@fabi-play/engine 0.0.0-stage → 0.1.0

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.
@@ -0,0 +1,105 @@
1
+ "use strict";(()=>{var As=Object.defineProperty;var Ra=(s,r,e)=>r in s?As(s,r,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[r]=e;var Fa=(s,r)=>{for(var e in r)As(s,e,{get:r[e],enumerable:!0})};var p=(s,r,e)=>Ra(s,typeof r!="symbol"?r+"":r,e);var ms={};Fa(ms,{AnimatedSprite:()=>Ce,Atlas:()=>at,AvatarPainter:()=>wt,AvatarsNode:()=>Mr,BitmapFont:()=>Yt,DEFAULT_FONT:()=>On,EASE:()=>st,Group:()=>vt,HALO:()=>At,MAX_LAYERS:()=>fr,NameTags:()=>ct,Node:()=>Fe,NodePool:()=>Tr,Particles:()=>Ot,STAGE_HEIGHT:()=>ae,Shape:()=>He,ShelfPacker:()=>br,Sound:()=>jt,Sprite:()=>Se,TIERS:()=>Ve,Text:()=>We,Timeline:()=>Qt,Tweens:()=>Zt,avatarPortrait:()=>Oo,blur:()=>da,brightness:()=>aa,colorMatrix:()=>pa,contrast:()=>ia,createAvatarRenderer:()=>Do,createEngine:()=>Jo,createRenderer:()=>Vt,dropShadow:()=>ma,grayscale:()=>ca,handsOf:()=>tn,hits:()=>Ar,hueRotate:()=>ha,invert:()=>fa,nodePool:()=>ka,packColor:()=>nt,parseBMFont:()=>Kt,parseColor:()=>he,pickTier:()=>sn,playerColor:()=>wr,rendererOrder:()=>Dn,rng:()=>Ys,saturate:()=>la,sepia:()=>ua,shader:()=>ba,shapeBounds:()=>Jr,tier:()=>et,tint:()=>oa,touching:()=>rn,wrists:()=>Hn});var K={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},Ss=["3-5","6-8","9-12"],Ca=s=>Ss.includes(s);var Pa=4,sr=["#EE6A43","#6FA0E0","#8CC9A0","#C49BE0"];var Ms={"3-5":["bunny","bear","panda","penguin"],"6-8":["fox","lion","dragon","unicorn"],"9-12":["robot","astronaut","ninja","skater"]},_a=Ms["6-8"],bn=(s,r)=>{let e=Ca(r)?Ms[r]:_a;return e[Number.isInteger(s)&&s>=0?s%e.length:0]};var Ts=(s,r)=>s?{x:s.x+r.x*s.w,y:s.y+r.y*s.h}:{x:r.x,y:r.y};var La=12,Na=132,Ba=s=>La+s*Na,ul=Ba(Pa);var Da=s=>s.startsWith("fabi-play.")?`fablee-play.${s.slice(10)}`:null;function Es(s,r,e=Da(r)){if(!(!s||!e))try{let t=s.getItem(e);if(t===null)return;s.getItem(r)===null&&s.setItem(r,t),s.removeItem(e)}catch{}}var ve="#4a382c",de="#2b2118",Re="#1c1f2b",Rs="#fbefe3",Ne="#f4897a",or="#3a2a22",yn=[{id:"fox",name:{en:"Fox",it:"Volpe"},band:"6-8",palette:{body:"#ee6a43",limbs:"#ee6a43",belly:Rs,accent:"#ffd9c2",outline:de,hands:"#5a3426",feet:"#5a3426"},head:"wide",ears:"pointy",face:{eyes:"dot",mouth:"cat",nose:or,muzzle:"cheeks"},tail:"fluffy",headExtras:[],bodyExtras:[]},{id:"mascot",name:{en:"Fabi",it:"Fabi"},band:"all",special:!0,palette:{body:"#ee6a43",limbs:"#ee6a43",belly:Rs,accent:"#5a3426",outline:de,hands:"#5a3426",feet:"#5a3426"},head:"wide",ears:"pointy",face:{eyes:"bead",mouth:"open",nose:or,muzzle:"band",cheeks:Ne},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:ve},head:"round",ears:"long",face:{eyes:"dot",mouth:"cat",nose:"#e0607e",muzzle:"none",cheeks:Ne},tail:"pom",headExtras:[],bodyExtras:[]},{id:"bear",name:{en:"Bear",it:"Orsetto"},band:"3-5",palette:{body:"#cf9f78",limbs:"#cf9f78",belly:"#f7e0bf",accent:"#f7e0bf",outline:ve},head:"round",ears:"round",face:{eyes:"dot",mouth:"smile",nose:or,muzzle:"oval",cheeks:Ne},tail:"none",headExtras:[],bodyExtras:[]},{id:"cat",name:{en:"Cat",it:"Gattino"},band:"3-5",palette:{body:"#c8b6ee",limbs:"#c8b6ee",belly:"#f4eeff",accent:"#f7b3c8",outline:ve,hands:"#f4eeff",feet:"#f4eeff"},head:"wide",ears:"pointy",face:{eyes:"big",eyeColor:"#3f9a5a",mouth:"cat",nose:"#f07a9a",muzzle:"none",cheeks:Ne},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:ve,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:ve,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:ve},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",palette:{body:"#f6c454",limbs:"#f6c454",belly:"#fde7b0",accent:"#fde7b0",outline:de},head:"round",ears:"round",face:{eyes:"dot",mouth:"cat",nose:"#8a4b2a",muzzle:"oval",cheeks:Ne},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:de,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:de},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:Re,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:Re,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:de},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:de,hands:"#f2c9a0",feet:"#f2c9a0"},head:"round",ears:"side",face:{eyes:"dot",mouth:"open",nose:"#5a3a26",muzzle:"monkey",cheeks:Ne},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:ve},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:de},head:"wide",ears:"round",face:{eyes:"dot",mouth:"cat",nose:"#e2607a",muzzle:"oval",cheeks:Ne},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:ve,feet:"#f9b95c",hands:"#639cc9"},head:"tall",ears:"tufts",face:{eyes:"big",eyeColor:ve,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:Re},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:de},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:de,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:ve,hands:"#ffc23d",feet:"#ffa04a"},head:"round",ears:"none",face:{eyes:"dot",mouth:"beak",muzzle:"none",cheeks:Ne},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:ve,ears:"#b58262",hands:"#e6caa6",feet:"#e6caa6"},head:"wide",ears:"floppy",face:{eyes:"dot",mouth:"open",nose:or,muzzle:"oval",cheeks:Ne},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:ve,skin:"#f7dccb",hands:"#a58c7e",feet:"#a58c7e"},head:"round",ears:"droopy",face:{eyes:"dot",mouth:"smile",nose:"#e591a0",muzzle:"none",cheeks:Ne},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:ve,feet:"#ff9f43"},head:"tall",ears:"none",face:{eyes:"dot",mouth:"bill",muzzle:"none",cheeks:Ne},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:de,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:de,hands:"#5a647a",feet:"#5a647a"},head:"round",ears:"pointy",face:{eyes:"dot",mouth:"open",nose:or,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:de,hands:"#3a9bdc",feet:"#8a7a70"},head:"round",ears:"none",face:{eyes:"big",eyeColor:de,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:Re,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:Re,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:Re,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:Re,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:Re,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:Re,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:Re,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:Re,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:Re,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"]}];var te={M:0,L:1,Q:2,C:3,Z:4},Fs=[2,2,4,6,0];function Ct(s,r){for(let e of r)Oa(s,e)}function Oa(s,r){if(r.k==="group"){s.save(),s.translate(r.x,r.y),r.rot&&s.rotate(r.rot),r.s!==void 0&&r.s!==1&&s.scale(r.s,r.s),r.alpha!==void 0&&(s.globalAlpha*=r.alpha),Ct(s,r.items),s.restore();return}switch(s.save(),r.alpha!==void 0&&(s.globalAlpha*=r.alpha),s.beginPath(),r.k){case"circle":s.arc(r.x,r.y,Math.max(r.r,0),0,Math.PI*2);break;case"ellipse":s.ellipse(r.x,r.y,Math.max(r.rx,0),Math.max(r.ry,0),r.rot??0,0,Math.PI*2);break;case"rect":Ia(s,r);break;case"path":typeof r.d=="string"?Ua(s,r.d):za(s,r.d);break;case"line":s.moveTo(r.pts[0]??0,r.pts[1]??0);for(let e=2;e+1<r.pts.length;e+=2)s.lineTo(r.pts[e],r.pts[e+1]);break}s.lineCap="round",s.lineJoin="round",r.fill&&r.k!=="line"&&(s.fillStyle=r.fill,s.fill()),r.stroke&&(r.lw??1)>0&&(s.strokeStyle=r.stroke,s.lineWidth=r.lw??1,s.stroke()),s.restore()}function Ia(s,r){let e=Math.max(0,Math.min(r.r,r.w/2,r.h/2));s.translate(r.x,r.y),r.rot&&s.rotate(r.rot);let t=-r.w/2,n=-r.h/2;s.moveTo(t+e,n),s.lineTo(t+r.w-e,n),s.quadraticCurveTo(t+r.w,n,t+r.w,n+e),s.lineTo(t+r.w,n+r.h-e),s.quadraticCurveTo(t+r.w,n+r.h,t+r.w-e,n+r.h),s.lineTo(t+e,n+r.h),s.quadraticCurveTo(t,n+r.h,t,n+r.h-e),s.lineTo(t,n+e),s.quadraticCurveTo(t,n,t+e,n),s.closePath()}function za(s,r){for(let e=0;e<r.length;){let t=r[e++];if(t===te.M)s.moveTo(r[e],r[e+1]);else if(t===te.L)s.lineTo(r[e],r[e+1]);else if(t===te.Q)s.quadraticCurveTo(r[e],r[e+1],r[e+2],r[e+3]);else if(t===te.C)s.bezierCurveTo(r[e],r[e+1],r[e+2],r[e+3],r[e+4],r[e+5]);else if(t===te.Z)s.closePath();else return;e+=Fs[t]}}function xn(s){if(typeof s=="string")return(s.match(/-?\d*\.?\d+(?:e-?\d+)?/gi)??[]).map(Number);let r=[];for(let e=0;e<s.length;){let t=Fs[s[e++]];if(t===void 0)break;for(let n=0;n<t;n++)r.push(s[e+n]);e+=t}return r}function Ua(s,r){let e=r.match(/[MLQCZ]|-?\d*\.?\d+(?:e-?\d+)?/gi)??[],t="",n=0,o=()=>Number(e[n++]);for(;n<e.length;){let a=e[n];if(/[MLQCZ]/i.test(a)&&(t=a.toUpperCase(),n++,t==="Z")){s.closePath();continue}t==="M"?(s.moveTo(o(),o()),t="L"):t==="L"?s.lineTo(o(),o()):t==="Q"?s.quadraticCurveTo(o(),o(),o(),o()):t==="C"?s.bezierCurveTo(o(),o(),o(),o(),o(),o()):n++}}var j=s=>{let r=Math.round(s*100)/100;return r===0?0:r};function J(s,r=.5){let e=s.length;if(e<3)return[];let t=(i,l,c)=>({x:i.x+(l.x-i.x)*c,y:i.y+(l.y-i.y)*c}),n=Math.min(Math.max(r,0),.5),o=t(s[0],s[1],n),a=[te.M,j(o.x),j(o.y)];for(let i=1;i<=e;i++){let l=s[(i-1)%e],c=s[i%e],u=s[(i+1)%e],f=t(l,c,1-n),h=t(c,u,n);a.push(te.L,j(f.x),j(f.y),te.Q,j(c.x),j(c.y),j(h.x),j(h.y))}return a.push(te.Z),a}function Z(s,r=1){let e=s.length;if(e<3)return[];let t=[te.M,j(s[0].x),j(s[0].y)],n=r/6;for(let o=0;o<e;o++){let a=s[(o-1+e)%e],i=s[o],l=s[(o+1)%e],c=s[(o+2)%e];t.push(te.C,j(i.x+(l.x-a.x)*n),j(i.y+(l.y-a.y)*n),j(l.x-(c.x-i.x)*n),j(l.y-(c.y-i.y)*n),j(l.x),j(l.y))}return t.push(te.Z),t}function Pt(s){let r=s.length;if(r<2)return[];let e=[te.M,j(s[0].x),j(s[0].y)];for(let t=0;t<r-1;t++){let n=s[Math.max(t-1,0)],o=s[t],a=s[t+1],i=s[Math.min(t+2,r-1)];e.push(te.C,j(o.x+(a.x-n.x)/6),j(o.y+(a.y-n.y)/6),j(a.x-(i.x-o.x)/6),j(a.y-(i.y-o.y)/6),j(a.x),j(a.y))}return e}var mt="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";var ce="#ffffff",V=[-1,1],Cs="#3a2420",Ha="#f2808f",gn="#26324a",Ga="#ffd84a",me=(...s)=>{let r=[];for(let e=0;e+1<s.length;e+=2)r.push({x:s[e],y:s[e+1]});return r};function Nr(s,r){let e=s.palette,t=[],n={stroke:e.outline,lw:r},o=u=>s.headExtras.includes(u),a=(u,f)=>s.extraColors?.[u]??f;if(o("mane")){for(let f=0;f<12;f++){let h=f/12*Math.PI*2;t.push({k:"circle",x:Math.cos(h)*1.02,y:Math.sin(h)*1+.04,r:.42,fill:a(0,e.accent),...n})}t.push({k:"circle",x:0,y:.04,r:1.08,fill:a(0,e.accent)})}if(o("rainbow-mane")){let u=s.extraColors??["#f59ac0","#fbd46a","#8fd3f4"];[[.98,.05,.3,.5,-.25],[.92,.58,.26,.42,-.1],[.62,.92,.22,.32,.4]].forEach(([h,b,y,m,d],x)=>t.push({k:"ellipse",x:h,y:b,rx:y,ry:m,rot:d,fill:u[x%u.length],...n}))}if(o("spikes"))for(let u of[-.55,0,.55]){let f=ar(u,1.48),h=ar(u-.32,.86),b=ar(u+.32,.86);t.push({k:"path",d:J([h,f,b],.22),fill:e.accent,...n})}if(o("curl")&&t.push({k:"path",d:Z([{x:-.2,y:-.9},{x:-.05,y:-1.3},{x:.32,y:-1.42},{x:.16,y:-1.18},{x:.2,y:-.9}]),fill:e.body,...n}),o("wool"))for(let u=0;u<=8;u++){let f=-1.75+u/8*3.5;t.push({k:"circle",x:Math.sin(f)*.98,y:-Math.cos(f)*.92-.04,r:.34,fill:e.body,...n})}if(o("crest")&&[-.38,0,.38].forEach((u,f)=>{let h=ar(u,1.12);t.push({k:"ellipse",x:h.x,y:h.y,rx:.15,ry:.42,rot:u,fill:a(f,e.accent),...n})}),o("plume")&&t.push({k:"path",d:Z(me(-.12,-.92,-.2,-1.42,.1,-1.78,.62,-1.74,.36,-1.46,.16,-.98)),fill:e.accent,...n}),o("locks")&&t.push({k:"path",d:Z(me(-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:e.hair??e.outline,...n}),o("ninja-hood"))for(let[u,f]of[[.35,.5],[.85,.42]])t.push({k:"ellipse",x:1+Math.cos(u)*f*.8,y:-.5+Math.sin(u)*f*.8,rx:f,ry:.11,rot:u,fill:e.accent,...n});if(o("bandana"))for(let[u,f]of[[Math.PI-.5,.42],[Math.PI-1,.36]])t.push({k:"ellipse",x:-.98+Math.cos(u)*f*.8,y:-.36+Math.sin(u)*f*.8,rx:f,ry:.12,rot:u,fill:e.accent,...n});if(o("ruff"))for(let u of V)t.push({k:"path",d:J(me(u*.7,-.3,u*1.32,0,u*1.02,.18,u*1.26,.46,u*.86,.56,u*.98,.84,u*.4,.7),.25),fill:e.body,...n});if(s.face.eyesOnTop)for(let u of V)t.push({k:"circle",x:u*.46,y:-.72,r:.38,fill:e.body,...n});t.push(...Xa(s,r)),t.push($a(s,n));let i=s.face.muzzle,l=e.belly;if(i==="oval"&&t.push({k:"ellipse",x:0,y:.4,rx:.46,ry:.32,fill:l}),i==="monkey"){for(let u of V)t.push({k:"circle",x:u*.32,y:-.04,r:.38,fill:l});t.push({k:"ellipse",x:0,y:.4,rx:.56,ry:.4,fill:l})}if(i==="heart"){for(let u of V)t.push({k:"circle",x:u*.36,y:.02,r:.5,fill:l});t.push({k:"ellipse",x:0,y:.38,rx:.66,ry:.48,fill:l})}if(i==="disc")for(let u of V)t.push({k:"circle",x:u*.4,y:.02,r:.44,fill:l});if(i==="cheeks")for(let u of V)t.push({k:"ellipse",x:u*.4,y:.44,rx:.44,ry:.32,fill:l});if(i==="band"&&t.push({k:"path",d:Va(s,r),fill:l}),o("stripes")){let u=a(0,e.outline);t.push({k:"line",pts:[0,-.97,0,-.66],stroke:u,lw:.13});for(let f of V)t.push({k:"line",pts:[f*.3,-.93,f*.24,-.7],stroke:u,lw:.1}),t.push({k:"line",pts:[f*.98,-.05,f*.74,0],stroke:u,lw:.1}),t.push({k:"line",pts:[f*.94,.22,f*.74,.22],stroke:u,lw:.09})}if(o("spots")){let u=a(1,e.belly);t.push({k:"circle",x:-.55,y:-.5,r:.15,fill:u}),t.push({k:"circle",x:.58,y:-.42,r:.11,fill:u}),t.push({k:"circle",x:.22,y:-.76,r:.09,fill:u})}if(o("forehead")&&t.push({k:"path",d:Z(me(-.62,-.66,0,-.86,.62,-.66,.26,-.36,0,-.1,-.26,-.36),.9),fill:a(0,e.accent)}),o("eye-spot")&&t.push({k:"ellipse",x:.42,y:-.06,rx:.3,ry:.33,rot:.3,fill:e.ears??e.accent}),o("gills"))for(let u of V)for(let f of[0,.12,.24])t.push({k:"path",d:`M${u*(.66+f)} 0.06 Q${u*(.6+f)} 0.22 ${u*(.66+f)} 0.38`,stroke:e.accent,lw:r*.9});let c=e.hair??e.outline;if(o("hair")&&t.push({k:"path",d:Z(me(-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:c,...n}),o("locks")&&t.push({k:"path",d:Z(me(-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:c,...n}),o("curls")){for(let u=0;u<7;u++){let f=ar(-1.3+u/6*2.6,.86);t.push({k:"circle",x:f.x,y:f.y,r:.3,fill:c,...n})}t.push({k:"ellipse",x:0,y:-.64,rx:.8,ry:.36,fill:c})}if(o("ninja-hood")&&(t.push({k:"rect",x:0,y:0,w:1.56,h:.6,r:.28,fill:e.skin??ce,stroke:e.outline,lw:r*.8}),t.push({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:e.accent,...n})),o("domino")){t.push({k:"path",d:Z(me(-.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:e.accent,...n});for(let u of V)t.push({k:"ellipse",x:u*.38,y:0,rx:.19,ry:.13,fill:ce})}if(t.push(...qa(s,r)),o("brows"))for(let u of V)t.push({k:"line",pts:[u*.72,-.5,u*.14,-.3],stroke:e.accent,lw:.16});if(s.face.brows)for(let u of V)t.push({k:"line",pts:[u*.2,-.2,u*.54,-.28],stroke:s.face.brows,lw:.09});if(t.push(...Ya(s,r)),s.face.cheeks)for(let u of V)t.push({k:"ellipse",x:u*.64,y:.3,rx:.15,ry:.1,fill:s.face.cheeks,alpha:.8});if(o("whiskers"))for(let u of V)for(let f of[-.1,.06])t.push({k:"line",pts:[u*.62,.38+f,u*1.06,.3+f*2.2],stroke:e.outline,lw:r*.7,alpha:.75});if(o("rainbow-mane")){let u=s.extraColors??["#f59ac0","#fbd46a","#8fd3f4"];t.push({k:"ellipse",x:.42,y:-.82,rx:.34,ry:.22,rot:.5,fill:u[0],...n}),t.push({k:"ellipse",x:.1,y:-.92,rx:.3,ry:.2,rot:.25,fill:u[1%u.length],...n})}if(s.ears==="unicorn"){let u=[{x:-.18,y:-.84},{x:.02,y:-1.72},{x:.18,y:-.84}];t.push({k:"path",d:J(u,.12),fill:e.accent,...n});for(let f of[-1,-1.2,-1.4]){let h=.16*((f+1.72)/.88);t.push({k:"line",pts:[-h,f+.04,h,f-.04],stroke:e.outline,lw:r*.7,alpha:.6})}}if(o("helmet")){for(let u of V)t.push({k:"rect",x:u*1,y:.05,w:.26,h:.56,r:.12,fill:e.accent,...n});t.push({k:"path",d:"M-0.62 -0.62 Q-0.3 -0.92 0.12 -0.9",stroke:ce,lw:.1,alpha:.9})}if(o("bolts"))for(let u of V)t.push({k:"rect",x:u*1.08,y:.08,w:.2,h:.44,r:.08,fill:e.accent,...n});if(o("tuft")&&t.push({k:"path",d:Z([{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:e.body,...n}),o("eggshell")&&t.push({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:a(0,ce),...n}),o("wool"))for(let[u,f]of[[-.36,-.84],[.02,-.94],[.4,-.82]])t.push({k:"circle",x:u,y:f,r:.27,fill:e.body,...n});if(o("stripe")&&t.push({k:"rect",x:0,y:-.64,w:.38,h:.62,r:.06,fill:e.accent}),o("eye-patch")&&(t.push({k:"line",pts:[-.97,-.5,.97,.13],stroke:e.outline,lw:.07}),t.push({k:"ellipse",x:.38,y:.02,rx:.21,ry:.19,fill:e.outline})),o("bandana")){t.push({k:"path",d:Z(me(-1.05,-.22,-.96,-.72,-.5,-1.08,.1,-1.14,.72,-.96,1.04,-.56,1.05,-.22,.5,-.46,-.5,-.46)),fill:e.accent,...n});for(let[u,f]of[[-.5,-.8],[.08,-.92],[.6,-.74],[-.12,-.62],[.36,-.6]])t.push({k:"circle",x:u,y:f,r:.06,fill:ce,alpha:.85});t.push({k:"circle",x:-.98,y:-.34,r:.15,fill:e.accent,...n})}if(o("cap")){for(let u of V)t.push({k:"line",pts:[u*.98,-.2,u*.5,.82,-u*.05,.98],stroke:e.outline,lw:.06});t.push({k:"path",d:Z(me(-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:e.accent,...n}),t.push({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:e.accent,...n}),t.push({k:"circle",x:.5,y:-.82,r:.15,fill:a(0,ce),...n});for(let u of[-.42,-.14])t.push({k:"line",pts:[u,-1.04,u+.02,-.78],stroke:e.outline,lw:.07,alpha:.7})}if(o("safari-hat")&&(t.push({k:"ellipse",x:0,y:-.56,rx:1.48,ry:.3,fill:e.accent,...n}),t.push({k:"path",d:Z(me(-.78,-.58,-.7,-1.1,-.3,-1.38,.3,-1.38,.7,-1.1,.78,-.58,0,-.5),.8),fill:e.accent,...n}),t.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:a(1,e.outline),stroke:e.outline,lw:r*.8})),o("wizard-hat")){t.push({k:"ellipse",x:0,y:-.62,rx:1.32,ry:.26,fill:e.accent,...n}),t.push({k:"path",d:J(me(-.8,-.66,-.36,-1.5,.5,-2.2,.3,-1.46,.8,-.66),.3),fill:e.accent,...n});let u=a(0,Ga);for(let[f,h,b]of[[.02,-1.08,.18],[-.38,-.84,.1],[.36,-1.5,.11]])t.push({k:"group",x:f,y:h,s:b,items:[{k:"path",d:mt,fill:u}]})}if(o("dive-mask")){for(let f of V)t.push({k:"line",pts:[f*.7,-.04,f*1,-.12],stroke:e.outline,lw:.2},{k:"line",pts:[f*.7,-.04,f*1,-.12],stroke:e.accent,lw:.11});t.push({k:"rect",x:0,y:0,w:1.42,h:.62,r:.28,fill:"#bfe9f5",alpha:.35}),t.push({k:"rect",x:0,y:0,w:1.42,h:.62,r:.28,stroke:e.outline,lw:.2}),t.push({k:"rect",x:0,y:0,w:1.42,h:.62,r:.28,stroke:e.accent,lw:.11}),t.push({k:"path",d:"M-0.5 -0.16 Q-0.4 -0.24 -0.22 -0.24",stroke:ce,lw:.06,alpha:.9});let u="M0.5 0.52 Q0.98 0.56 1.04 0.1 L1.12 -0.92";t.push({k:"path",d:u,stroke:e.outline,lw:.24},{k:"path",d:u,stroke:e.accent,lw:.13})}return t}function $a(s,r){let e=s.headExtras.includes("ninja-hood")?s.palette.body:s.palette.skin??s.palette.body;switch(s.head){case"round":return{k:"circle",x:0,y:0,r:1,fill:e,...r};case"wide":return{k:"ellipse",x:0,y:.03,rx:1.12,ry:.94,fill:e,...r};case"tall":return{k:"ellipse",x:0,y:-.02,rx:.94,ry:1.04,fill:e,...r};case"square":return{k:"rect",x:0,y:0,w:2,h:1.8,r:.46,fill:e,...r};case"bucket":return{k:"path",d:J(me(-.94,.96,-.98,-.36,-.62,-1.04,.62,-1.04,.98,-.36,.94,.96),.42),fill:e,...r};case"bulb":return{k:"path",d:Z([{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:e,...r}}}function Wa(s){return s.head==="round"?{cy:0,rx:1,ry:1}:s.head==="tall"?{cy:-.02,rx:.94,ry:1.04}:{cy:.03,rx:1.12,ry:.94}}function Va(s,r){let{cy:e,rx:t,ry:n}=Wa(s),o=t-r/2,a=n-r/2,i=.15,l=Math.asin(Math.min(1,(i-e)/a)),c=Math.cos(l)*o,u=y=>Math.round(y*100)/100||0,f=[te.M,u(-c),i],h=[[-.84*c,.02,-.53*c,.06,-.32*c,.24],[-.17*c,.11,.17*c,.11,.32*c,.24],[.53*c,.06,.84*c,.02,c,i]];for(let y of h)f.push(te.C,...y.map(u));let b=24;for(let y=1;y<=b;y++){let m=l+(Math.PI-2*l)*y/b;f.push(te.L,u(Math.cos(m)*o),u(e+Math.sin(m)*a))}return f.push(te.Z),f}function Xa(s,r){let e=s.palette,t={stroke:e.outline,lw:r},n=[];for(let o of V)switch(s.ears){case"pointy":case"unicorn":{let a=s.ears==="unicorn"?.8:1,i={x:o*.3,y:-.82},l={x:o*.86,y:-.82-.62*a},c={x:o*.94,y:-.36};n.push({k:"path",d:J([i,l,c],.2),fill:e.body,...t});let u={x:(i.x+l.x+c.x)/3,y:(i.y+l.y+c.y)/3},f=[i,l,c].map(h=>({x:u.x+(h.x-u.x)*.55,y:u.y+(h.y-u.y)*.55+.04}));n.push({k:"path",d:J(f,.25),fill:e.accent});break}case"round":n.push({k:"circle",x:o*.72,y:-.72,r:.36,fill:e.ears??e.body,...t}),e.ears||n.push({k:"circle",x:o*.74,y:-.74,r:.19,fill:e.accent});break;case"big-round":n.push({k:"circle",x:o*.96,y:-.46,r:.52,fill:e.body,...t}),n.push({k:"circle",x:o*1,y:-.44,r:.32,fill:e.accent});break;case"long":n.push({k:"ellipse",x:o*.38,y:-1.42,rx:.25,ry:.68,rot:o*.14,fill:e.body,...t}),n.push({k:"ellipse",x:o*.39,y:-1.36,rx:.12,ry:.48,rot:o*.14,fill:e.accent});break;case"side":n.push({k:"circle",x:o*1,y:.02,r:.34,fill:e.body,...t}),n.push({k:"circle",x:o*1.02,y:.02,r:.2,fill:e.belly});break;case"tufts":n.push({k:"path",d:J([{x:o*.3,y:-.84},{x:o*1.22,y:-1.12},{x:o*.92,y:-.42}],.16),fill:e.body,...t}),n.push({k:"line",pts:[o*.62,-.78,o*1,-.98],stroke:e.accent,lw:.08});break;case"antennae":{let a={x:o*.62,y:-1.42};n.push({k:"path",d:`M${o*.3} -0.8 Q${o*.36} -1.2 ${a.x} ${a.y}`,stroke:e.outline,lw:r*2.6}),n.push({k:"path",d:`M${o*.3} -0.8 Q${o*.36} -1.2 ${a.x} ${a.y}`,stroke:e.body,lw:r*1.2}),n.push({k:"circle",x:a.x,y:a.y,r:.17,fill:e.accent,...t});break}case"floppy":n.push({k:"ellipse",x:o*.96,y:.02,rx:.3,ry:.62,rot:-o*.36,fill:e.ears??e.body,...t});break;case"droopy":n.push({k:"ellipse",x:o*1.04,y:-.22,rx:.4,ry:.18,rot:o*.32,fill:e.skin??e.body,...t}),n.push({k:"ellipse",x:o*1.08,y:-.2,rx:.24,ry:.08,rot:o*.32,fill:e.accent});break;case"human":n.push({k:"ellipse",x:o*.98,y:.06,rx:.17,ry:.23,fill:e.skin??e.body,...t});break;case"horns":{let a=[{x:o*.3,y:-.84},{x:o*.6,y:-1.5},{x:o*.66,y:-.68}];n.push({k:"path",d:J(a,.18),fill:e.accent,...t});break}}return s.ears==="fin"&&n.push({k:"path",d:J(me(-.4,-.82,.2,-1.62,.46,-.78),.2),fill:e.body,...t}),s.ears==="antenna"&&(n.push({k:"line",pts:[0,-.85,0,-1.42],stroke:e.outline,lw:r*2.6}),n.push({k:"line",pts:[0,-.85,0,-1.42],stroke:e.limbs,lw:r*1.2}),n.push({k:"circle",x:0,y:-1.5,r:.18,fill:e.accent,...t})),n}function qa(s,r){let e=s.palette,t=s.face,n=[],o=e.outline,a=t.eyesOnTop?.46:.4,i=t.eyesOnTop?-.72:-.04,l=(c,u,f)=>({k:"circle",x:c,y:u,r:f,fill:ce});switch(t.eyes){case"dot":for(let c of V)n.push({k:"ellipse",x:c*a,y:i,rx:.12,ry:.155,fill:o}),n.push(l(c*a+.04,i-.06,.045));break;case"bead":for(let c of V)n.push({k:"ellipse",x:c*a,y:i,rx:.16,ry:.22,fill:o}),n.push(l(c*a+.05,i-.08,.065));break;case"big":for(let c of V)t.eyeRing&&n.push({k:"circle",x:c*a,y:i,r:.36,fill:t.eyeRing,stroke:o,lw:r*.8}),n.push({k:"circle",x:c*a,y:i,r:.25,fill:ce,stroke:o,lw:r*.8}),n.push({k:"circle",x:c*a+c*-.03,y:i+.03,r:.14,fill:t.eyeColor??o}),n.push(l(c*a+c*-.03+.05,i-.03,.05));break;case"mask":for(let c of V)n.push({k:"ellipse",x:c*.4,y:0,rx:.24,ry:.32,rot:c*-.55,fill:e.limbs}),n.push({k:"circle",x:c*.4,y:-.02,r:.11,fill:ce}),n.push({k:"circle",x:c*.39,y:-0,r:.065,fill:o});break;case"screen":n.push({k:"rect",x:0,y:0,w:1.5,h:.66,r:.26,fill:"#24323d",stroke:o,lw:r*.8});for(let c of V)n.push({k:"ellipse",x:c*.36,y:0,rx:.2,ry:.24,fill:t.eyeColor??"#7ff0ff",alpha:.3}),n.push({k:"ellipse",x:c*.36,y:0,rx:.12,ry:.16,fill:t.eyeColor??"#7ff0ff"});break;case"almond":for(let c of V)n.push({k:"ellipse",x:c*.42,y:-.02,rx:.3,ry:.2,rot:-c*.5,fill:t.eyeColor??o}),n.push(l(c*.42-c*.07,-.08,.07));break;case"calm":for(let c of V)n.push({k:"ellipse",x:c*.38,y:.02,rx:.085,ry:.12,fill:o}),n.push(l(c*.38+.03,-.02,.03));break;case"slit":n.push({k:"line",pts:[0,-.98,0,-.2],stroke:o,lw:r*.8,alpha:.5}),n.push({k:"rect",x:0,y:-.04,w:1.56,h:.26,r:.1,fill:gn,stroke:o,lw:r*.8}),n.push({k:"rect",x:0,y:.3,w:.22,h:.46,r:.08,fill:gn,stroke:o,lw:r*.8});for(let c of V){n.push({k:"ellipse",x:c*.4,y:-.04,rx:.12,ry:.07,fill:t.eyeColor??ce});for(let u of[.36,.56])n.push({k:"circle",x:c*.42,y:u,r:.05,fill:o,alpha:.6})}break;case"goggle":for(let c of V)n.push({k:"circle",x:c*.9,y:0,r:.13,fill:e.accent,stroke:o,lw:r*.8});n.push({k:"rect",x:0,y:0,w:1.66,h:.62,r:.3,fill:gn,stroke:o,lw:r*.8}),n.push({k:"path",d:"M-0.6 -0.16 Q-0.42 -0.24 -0.12 -0.24",stroke:ce,lw:.07,alpha:.8});for(let c of V)n.push({k:"path",d:`M${c*.5} 0.04 Q${c*.34} -0.08 ${c*.16} 0.02`,stroke:t.eyeColor??"#7fd6ff",lw:.08});for(let c of[-.18,0,.18])n.push({k:"line",pts:[c,.56,c,.72],stroke:o,lw:r*.8,alpha:.6});break;case"visor":n.push({k:"ellipse",x:0,y:.08,rx:.8,ry:.64,fill:"#2a3f6b",stroke:o,lw:r*.8}),n.push({k:"path",d:"M-0.56 -0.14 Q-0.46 -0.4 -0.16 -0.46",stroke:ce,lw:.08,alpha:.7});for(let c of V)n.push({k:"ellipse",x:c*.28,y:.04,rx:.1,ry:.14,fill:t.eyeColor??"#cfeeff"});break}return n}function Ya(s,r){let e=s.palette,t=s.face,n=[],o=t.eyes==="visor"?"#cfeeff":Cs,a=r*1.05;switch(t.nose&&t.mouth!=="beak"&&(t.mouth==="cat"?n.push({k:"path",d:J([{x:-.1,y:.22},{x:.1,y:.22},{x:0,y:.33}],.3),fill:t.nose,stroke:t.nose,lw:r*.6}):s.ears==="big-round"?n.push({k:"ellipse",x:0,y:.22,rx:.2,ry:.25,fill:t.nose}):n.push({k:"ellipse",x:0,y:.25,rx:.13,ry:.085,fill:t.nose})),t.mouth){case"smile":n.push({k:"path",d:t.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:o,lw:a});break;case"open":n.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:o,stroke:o,lw:r*.5}),n.push({k:"ellipse",x:0,y:.6,rx:.1,ry:.06,fill:Ha});break;case"cat":n.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:o,lw:a});break;case"beak":n.push({k:"path",d:J([{x:-.17,y:.2},{x:.17,y:.2},{x:0,y:.48}],.25),fill:e.accent,stroke:e.outline,lw:r*.8});break;case"teeth":n.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:o,stroke:o,lw:r*.5});for(let i of V)n.push({k:"rect",x:i*.12,y:.43,w:.1,h:.1,r:.03,fill:ce});break;case"grill":n.push({k:"rect",x:0,y:.56,w:.62,h:.2,r:.08,fill:"#24323d",stroke:e.outline,lw:r*.7});for(let i of[-.15,0,.15])n.push({k:"line",pts:[i,.51,i,.61],stroke:"#9fb0bd",lw:r*.6});break;case"tiny":n.push({k:"ellipse",x:0,y:.44,rx:.08,ry:.1,fill:o});break;case"smirk":n.push({k:"path",d:"M-0.16 0.46 Q0.06 0.54 0.22 0.38",stroke:o,lw:a});break;case"bill":n.push({k:"ellipse",x:0,y:.36,rx:.44,ry:.2,fill:e.accent,stroke:e.outline,lw:r*.8}),n.push({k:"path",d:"M-0.36 0.38 Q0 0.46 0.36 0.38",stroke:e.outline,lw:r*.7});for(let i of V)n.push({k:"circle",x:i*.1,y:.28,r:.03,fill:e.outline});break;case"hook":n.push({k:"ellipse",x:0,y:.48,rx:.16,ry:.11,fill:Cs}),n.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:e.accent,stroke:e.outline,lw:r*.8});break;case"jaws":{n.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:o,stroke:o,lw:r*.5});for(let i of[-.34,-.17,0,.17,.34]){let l=.3+.4*(i+.5)*(.5-i)-.01;n.push({k:"path",d:J(me(i-.075,l,i+.075,l,i,l+.13),.15),fill:ce})}break}}return n}var ar=(s,r)=>({x:Math.sin(s)*r,y:-Math.cos(s)*r});var Bs=.5,Ue={leftEye:2,rightEye:5,leftEar:7,rightEar:8},rt={"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}},Br="6-8",Dr=s=>s.band in rt?s.band:Br,Ka=rt[Br].head,Ds=.3,Os=.12,ja=.9,Ps=.5,_s=.65,Qa=.35,Za=.2,Ja=.25,Ke=(s,r)=>({x:s.x-r.x,y:s.y-r.y}),Be=(s,r)=>({x:s.x+r.x,y:s.y+r.y}),ue=(s,r)=>({x:s.x*r,y:s.y*r}),bt=s=>Math.hypot(s.x,s.y),Ls=(s,r)=>({x:(s.x+r.x)/2,y:(s.y+r.y)/2}),kn=s=>{let r=bt(s);return r>1e-9?{x:s.x/r,y:s.y/r}:{x:0,y:1}},ei=(...s)=>s.every(Number.isFinite),ti=s=>Math.atan2(Math.sin(s),Math.cos(s)),ri=(s,r,e)=>Math.min(Math.max(s,r),e);function Is(s,r,e=!1){return t=>{let n=s[t*3],o=s[t*3+1],a=s[t*3+2];return n===void 0||o===void 0||a===void 0||!ei(n,o,a)?{x:0,y:0,ok:!1}:{x:r.x+(e?1-n:n)*r.w,y:r.y+o*r.h,ok:a>=Bs}}}function _t(s,r,e={}){let t=Is(s,r,e.mirrored),n=t(K.leftShoulder),o=t(K.rightShoulder);if(!n.ok||!o.ok)return null;let a=t(K.leftHip),i=t(K.rightHip),l=Ls(n,o),c=bt(Ke(o,n)),u=a.ok&&i.ok,f=kn(Ke(o,n));c<1e-6&&(f={x:1,y:0});let h,b,y;if(u){let E=Ls(a,i);b=bt(Ke(E,l)),b>=c*Ja?h=kn(Ke(E,l)):(h={x:-f.y,y:f.x},h.y<0&&(h=ue(h,-1))),y=Math.max(b,c*1.15)}else h={x:-f.y,y:f.x},h.y<0&&(h=ue(h,-1)),y=c*1.15,b=y;y=Math.max(y,1e-6);let m={x:h.y,y:-h.x},d=Math.atan2(m.y,m.x),x=ue(h,-1),g=rt[e.band??Br]??rt[Br],M=g.head*y,v=Be(l,ue(x,M*g.neck)),A=t(K.nose);if(A.ok){let E=Be(A,ue(x,M*.15)),C=ue(Ke(E,v),Qa),_=Math.min(1,M*Za/Math.max(bt(C),1e-6));v=Be(v,ue(C,_))}return{S:l,r:m,d:h,U:y,L:b,hipsOk:u,head:v,headR:M,headRot:d+ni(s,t,d,y),angle:d}}function ni(s,r,e,t){let n=[[Ue.leftEar,Ue.rightEar],[Ue.leftEye,Ue.rightEye]];for(let[o,a]of n){let i=r(o),l=r(a);if(!i.ok||!l.ok||!(s[o*3+2]>=_s&&s[a*3+2]>=_s)||bt(Ke(l,i))<t*.05)continue;let c=ti(Math.atan2(l.y-i.y,l.x-i.x)-e),u=Math.max(Math.abs(c)-Os,0),f=ri((ja+Ps-Math.abs(c))/Ps,0,1);return Math.sign(c)*Math.min(u,Ds)*f}return 0}function ir(s,r,e,t={}){let n=Dr(r),o=rt[n],a=_t(s,e,{...t,band:n});if(!a)return[];let i=Is(s,e,t.mirrored),l=r.palette,{S:c,r:u,d:f,U:h,L:b}=a,y=w=>r.bodyExtras.includes(w),m=Math.max(1.2,h*.045),d={stroke:l.outline,lw:m},x=(w,N)=>({x:c.x+u.x*w+f.x*N,y:c.y+u.y*w+f.y*N}),g=w=>w.map(([N,D])=>x(N,D)),M=i(K.leftShoulder),v=i(K.rightShoulder),A=i(K.leftHip),E=i(K.rightHip),C=bt(Ke(v,M)),_=a.hipsOk?bt(Ke(E,A)):C*.7,L=Math.max(C/2+o.shoulderPad*h,o.shoulderMin*h),I=Math.max(_/2+o.hipPad*h,o.hipMin*h),U=-.1*h,X=b+o.bottom*h,G=[],fe=[],H=[],re=[],pe=[],Pe=(w,N,D,q)=>{let $=N.flatMap(se=>[se.x,se.y]);w.push({k:"line",pts:$,stroke:l.outline,lw:D+m*2}),w.push({k:"line",pts:$,stroke:q,lw:D})},cn=o.leg*h,xe=o.arm*h,_e=Math.max(o.arm/.22,.9);if(a.hipsOk)for(let[w,N,D,q]of[[A,K.leftKnee,K.leftAnkle,-1],[E,K.rightKnee,K.rightAnkle,1]]){let $=i(N),se=i(D);if(!$.ok)continue;let Mt=Be(w,ue(f,-.12*h)),qe=se.ok?[Mt,$,se]:[Mt,$];Pe(fe,qe,cn,l.limbs),y("joints")&&fe.push({k:"circle",x:$.x,y:$.y,r:.15*h*_e,fill:l.accent,...d}),se.ok&&fe.push(ai(r,se,a,q,m,o.foot))}for(let[w,N,D,q]of[[M,K.leftElbow,K.leftWrist,-1],[v,K.rightElbow,K.rightWrist,1]]){let $=i(N),se=i(D);if(y("pauldrons")){let ze=Be(w,ue(f,.02*h));re.push({k:"ellipse",x:ze.x,y:ze.y,rx:.25*h,ry:.17*h,rot:a.angle+q*.25,fill:l.body,...d});let Ye=Be(ze,ue(f,.05*h));re.push({k:"ellipse",x:Ye.x,y:Ye.y,rx:.17*h,ry:.07*h,rot:a.angle+q*.25,fill:l.belly})}if(!$.ok)continue;let qe=o.armsOverHead&&($.x-c.x)*f.x+($.y-c.y)*f.y<-.25*h?pe:re,Jt=Be(w,ue(f,.04*h));if(Pe(qe,se.ok?[Jt,$,se]:[Jt,$],xe,l.limbs),y("joints")&&qe.push({k:"circle",x:$.x,y:$.y,r:.13*h*_e,fill:l.accent,...d}),!se.ok)continue;let Ie=kn(Ke(se,$)),Tt=Be(se,ue(Ie,.05*h));if(y("feathers"))for(let ze of[-.55,0,.55]){let Ye=Math.cos(ze),Et=Math.sin(ze)*q,er={x:Ie.x*Ye-Ie.y*Et,y:Ie.x*Et+Ie.y*Ye},ht=Be(Tt,ue(er,.16*h));qe.push({k:"ellipse",x:ht.x,y:ht.y,rx:.2*h,ry:.09*h,rot:Math.atan2(er.y,er.x),fill:l.hands??l.accent,...d})}qe.push({k:"circle",x:Tt.x,y:Tt.y,r:o.hand*h,fill:l.hands??l.limbs,...d})}if(y("wings"))for(let w of[-1,1]){let N=g([[w*L*.5,.05*h],[w*(L+.85*h),-.6*h],[w*(L+.72*h),.05*h],[w*(L+.45*h),-.02*h],[w*(L+.3*h),.32*h],[w*L*.6,.55*h]]);G.push({k:"path",d:J(N,.18),fill:l.accent,...d})}if(y("cape")){let w=b+.8*h,N=I+.36*h,D=g([[-L*.92,U+.04*h],[L*.92,U+.04*h],[L+.16*h,b*.5],[N,w],[N*.5,w-.1*h],[0,w],[-N*.5,w-.1*h],[-N,w],[-L-.16*h,b*.5]]);G.push({k:"path",d:Z(D,.6),fill:l.accent,...d})}if(y("backpack")){let w=x(0,.35*h);G.push({k:"rect",x:w.x,y:w.y,w:L*2+.34*h,h:.8*h,r:.16*h,rot:a.angle,fill:r.extraColors?.[0]??l.limbs,...d})}if(y("tank")){let w=x(L*.95,.24*h),N=r.extraColors?.[0]??l.accent,D=x(L*.95,-.3*h);G.push({k:"rect",x:D.x,y:D.y,w:.14*h,h:.16*h,r:.04*h,rot:a.angle,fill:l.outline}),G.push({k:"rect",x:w.x,y:w.y,w:.34*h,h:1*h,r:.17*h,rot:a.angle,fill:N,...d})}if(a.hipsOk&&!t.portrait&&G.push(...ii(r,a,I,m)),y("tentacles")&&a.hipsOk)for(let w of[-1,1]){let N=g([[w*I*.7,b*.9],[w*(I+.22*h),b+.3*h],[w*(I+.48*h),b+.22*h],[w*(I+.5*h),b-.02*h],[w*(I+.34*h),b-.06*h]]);G.push({k:"path",d:Pt(N),stroke:l.outline,lw:.2*h+m*2}),G.push({k:"path",d:Pt(N),stroke:l.limbs,lw:.2*h})}let ge=Math.max(L,I)*o.bulge;if(y("wool")){for(let[N,D]of[[L*.7,U+.02*h],[ge,b*.3],[ge*1.02,b*.62],[(ge+I)/2,b*.92],[I*.55,X]])for(let q of[-1,1]){let $=x(q*N,D);H.push({k:"circle",x:$.x,y:$.y,r:.2*h,fill:l.body,...d})}let w=x(0,X+.02*h);H.push({k:"circle",x:w.x,y:w.y,r:.2*h,fill:l.body,...d})}if(y("robe")){let w=b+.58*h,N=I*1.4;H.push({k:"path",d:Z(g([[-L,U],[0,U-.04*h],[L,U],[ge,b*.55],[N,w],[0,w+.06*h],[-N,w],[-ge,b*.55]]),.7),fill:l.body,...d});let D=g([[-N*.94,w-.1*h],[0,w-.04*h],[N*.94,w-.1*h]]);H.push({k:"path",d:Pt(D),stroke:r.extraColors?.[0]??l.accent,lw:.07*h})}else if(y("sheet")){let w=b+.78*h,N=I*1.3;H.push({k:"path",d:Z(g([[-L,U],[L,U],[ge,b*.55],[N,w],[N*.5,w-.2*h],[0,w],[-N*.5,w-.2*h],[-N,w],[-ge,b*.55]]),.9),fill:l.body,...d})}else H.push({k:"path",d:Z(g([[-L,U],[0,U-.04*h],[L,U],[ge,b*.55],[I,X],[0,X+.03*h],[-I,X],[-ge,b*.55]]),.85),fill:l.body,...d});let ie=Math.min(L,I);if(y("pocket")){let w=x(0,b*.74);H.push({k:"rect",x:w.x,y:w.y,w:ie*1.3,h:.3*h,r:.1*h,rot:a.angle,fill:l.belly,stroke:l.outline,lw:m*.8})}else if(y("racing-stripe"))for(let w of[-.1,.1]){let N=x(w*h,U+.02*h),D=x(w*h,X-.04*h);H.push({k:"line",pts:[N.x,N.y,D.x,D.y],stroke:l.belly,lw:.1*h})}else if(l.belly&&l.belly!==l.body&&!y("panel")&&!y("sheet")&&!y("stripes")){let w=x(0,b*.58);H.push({k:"ellipse",x:w.x,y:w.y,rx:ie*.64,ry:Math.max(b*.36,.2*h),rot:a.angle,fill:l.belly})}if(y("spots")){let w=r.extraColors?.[1]??l.belly;for(let[N,D,q]of[[-.55,.35,.09],[.5,.62,.11],[-.35,.86,.07]]){let $=x(N*ie,D*b);H.push({k:"circle",x:$.x,y:$.y,r:q*h,fill:w})}}if(y("stripes")){let w=r.extraColors?.[1]??l.accent;for(let N of[.22,.44,.66]){let D=x(-ie*.98,b*N),q=x(ie*.98,b*N);H.push({k:"line",pts:[D.x,D.y,q.x,q.y],stroke:w,lw:.1*h})}}if(y("straps")){let w=r.extraColors?.[1]??l.outline;for(let N of[-1,1]){let D=x(N*L*.62,U+.02*h),q=x(N*ie*.62,b*.72);H.push({k:"line",pts:[D.x,D.y,q.x,q.y],stroke:l.outline,lw:.13*h+m*2}),H.push({k:"line",pts:[D.x,D.y,q.x,q.y],stroke:w,lw:.13*h})}}if(y("belt")){let w=x(0,b*.9);H.push({k:"rect",x:w.x,y:w.y,w:I*1.92,h:.17*h,r:.06*h,rot:a.angle,fill:r.extraColors?.[2]??"#4a3426",...d}),H.push({k:"rect",x:w.x,y:w.y,w:.2*h,h:.19*h,r:.04*h,rot:a.angle,fill:"#ffd84a",...d})}if(y("emblem")){let w=x(0,b*.4),N=r.extraColors?.[0]??l.accent,D=J([{x:-.22,y:-.2},{x:.22,y:-.2},{x:.22,y:.04},{x:0,y:.26},{x:-.22,y:.04}],.25);H.push({k:"group",x:w.x,y:w.y,rot:a.angle,s:h,items:[{k:"path",d:D,fill:N,stroke:l.outline,lw:m/h},{k:"group",x:0,y:.01,s:.12,items:[{k:"path",d:mt,fill:N===l.accent?"#ffffff":l.accent}]}]})}if(y("panel")){let w=x(0,b*.5);H.push({k:"rect",x:w.x,y:w.y,w:ie*1.2,h:.38*h,r:.1*h,rot:a.angle,fill:"#24323d",...d}),(r.extraColors??["#ff7a6b","#fbd46a","#7ff0ff"]).slice(0,3).forEach((D,q)=>{let $=x((q-1)*ie*.34,b*.5);H.push({k:"circle",x:$.x,y:$.y,r:.075*h,fill:D})})}if(y("badge")){let w=x(-ie*.42,b*.36);H.push({k:"circle",x:w.x,y:w.y,r:.15*h,fill:l.accent,...d}),H.push({k:"group",x:w.x,y:w.y,rot:a.angle,s:.09*h,items:[{k:"path",d:mt,fill:"#ffffff"}]})}if(y("star")){let w=x(-ie*.5,b*.3),N=.15*h;H.push({k:"group",x:w.x,y:w.y,rot:a.angle-.2,s:N,items:[{k:"path",d:mt,fill:r.extraColors?.[0]??"#ffd84a",stroke:l.outline,lw:m*.8/N}]})}if(y("scarf")){let w=Math.max(.04,o.head*(1-o.neck)-.06)*h,N=x(0,w),D=r.extraColors?.[0]??l.accent,q=x(L*.45,w+.28*h);H.push({k:"rect",x:q.x,y:q.y,w:.16*h,h:.42*h,r:.06*h,rot:a.angle+.15,fill:D,...d}),H.push({k:"rect",x:N.x,y:N.y,w:L*2.05,h:.2*h,r:.1*h,rot:a.angle,fill:D,...d})}let Le={k:"group",x:a.head.x,y:a.head.y,rot:a.headRot,s:a.headR,items:oi(r,m/a.headR)};return[...G,...fe,...H,...re,Le,...pe]}var Ns=new WeakMap,si=64;function oi(s,r){let e=Number(r.toPrecision(4)),t=Ns.get(s);t||Ns.set(s,t=new Map);let n=t.get(e);return n||(t.size>=si&&t.clear(),t.set(e,n=Nr(s,e))),n}function ai(s,r,e,t,n,o){let a=s.palette,{d:i,r:l}=e,c=e.U*o,u=Be(Be(r,ue(i,.07*c)),ue(l,t*.06*c)),f={stroke:a.outline,lw:n},h=a.feet??a.limbs;if(s.bodyExtras.includes("fins")){let b=J([{x:-.13,y:-.06},{x:.13,y:-.06},{x:.24,y:.46},{x:-.24,y:.46}],.22);return{k:"group",x:u.x,y:u.y,rot:e.angle,s:c,items:[{k:"path",d:b,fill:h,stroke:a.outline,lw:n/c},{k:"line",pts:[0,.06,0,.38],stroke:a.outline,lw:n/c,alpha:.5}]}}return s.bodyExtras.includes("flippers")?{k:"ellipse",x:u.x,y:u.y,rx:.27*c,ry:.11*c,rot:e.angle,fill:h,...f}:s.bodyExtras.includes("boots")?{k:"rect",x:u.x,y:u.y,w:.4*c,h:.24*c,r:.09*c,rot:e.angle,fill:h,...f}:{k:"ellipse",x:u.x,y:u.y,rx:.2*c,ry:.13*c,rot:e.angle,fill:h,...f}}function ii(s,r,e,t){let n=s.palette,{U:o,L:a,S:i,r:l,d:c}=r,u=(m,d)=>({x:i.x+l.x*m+c.x*d,y:i.y+l.y*m+c.y*d}),f=m=>m.map(([d,x])=>u(d,x)),h={stroke:n.outline,lw:t},b=(m,d,x)=>[{k:"path",d:Pt(m),stroke:n.outline,lw:d+t*2},{k:"path",d:Pt(m),stroke:x,lw:d}],y=[];switch(s.tail){case"none":break;case"fluffy":{let m=f([[e*.5,a*.95],[e+.28*o,a*1],[e+.72*o,a*.62],[e+.78*o,a*.12],[e+.52*o,a*.32],[e+.3*o,a*.6],[e*.6,a*.7]]);y.push({k:"path",d:Z(m),fill:n.body,...h});let d=u(e+.72*o,a*.2);y.push({k:"ellipse",x:d.x,y:d.y,rx:.13*o,ry:.2*o,rot:r.angle+.25,fill:n.belly,...h});break}case"brush":{let m=f([[e*.4,a*.98],[e+.42*o,a*1.06],[e+.98*o,a*.66],[e+1.06*o,a*.12],[e+.86*o,-.04*o],[e+.66*o,a*.36],[e+.3*o,a*.66],[e*.5,a*.68]]);y.push({k:"path",d:Z(m),fill:n.body,...h});let d=f([[e+1.03*o,a*.36],[e+1.06*o,a*.12],[e+.86*o,-.04*o],[e+.72*o,a*.24],[e+.86*o,a*.34]]);y.push({k:"path",d:Z(d),fill:n.belly,...h});break}case"pom":{let m=u(e+.06*o,a*.88);y.push({k:"circle",x:m.x,y:m.y,r:.2*o,fill:n.belly,...h});break}case"long":case"striped":case"tuft":{let m=f([[e*.6,a*.9],[e+.35*o,a*.85],[e+.58*o,a*.4],[e+.5*o,-.02*o]]);if(y.push(...b(m,.14*o,n.body)),s.tail==="tuft"){let d=m[m.length-1];y.push({k:"circle",x:d.x,y:d.y,r:.16*o,fill:s.extraColors?.[0]??n.accent,...h})}if(s.tail==="striped"){for(let x of[.35,.6,.85]){let g=u(e+.35*o+.22999999999999998*o*(x*1.4>1?1:x*1.4),a*(.85-.85*x));y.push({k:"line",pts:[g.x-l.x*.08*o,g.y-l.y*.08*o,g.x+l.x*.08*o,g.y+l.y*.08*o],stroke:s.extraColors?.[0]??n.outline,lw:.06*o})}let d=m[m.length-1];y.push({k:"circle",x:d.x,y:d.y,r:.07*o,fill:s.extraColors?.[0]??n.outline})}break}case"curl":{let m=f([[e*.6,a*.9],[e+.4*o,a*.88],[e+.62*o,a*.45],[e+.5*o,a*.12],[e+.3*o,a*.24],[e+.36*o,a*.42]]);y.push(...b(m,.12*o,n.limbs));break}case"fish":{let m=f([[e*.6,a*.9],[e+.36*o,a*.86],[e+.6*o,a*.5]]);y.push(...b(m,.17*o,n.body));let d=m[m.length-1],x=J([{x:0,y:.06},{x:-.26,y:-.34},{x:.02,y:-.12},{x:.32,y:-.3}],.2);y.push({k:"group",x:d.x,y:d.y,rot:r.angle+.35,s:o,items:[{k:"path",d:x,fill:n.body,stroke:n.outline,lw:t/o}]});break}case"plume":{let m=s.extraColors??[n.accent];[0,1,2].forEach(d=>{let x=u(e+(.12+d*.13)*o,a+(.32-d*.06)*o);y.push({k:"ellipse",x:x.x,y:x.y,rx:.11*o,ry:.44*o,rot:r.angle-.55+d*.28,fill:m[(d+1)%m.length],...h})});break}case"spiky":case"arrow":{let m=f([[e*.3,a*.55],[e+.35*o,a*.68],[e+.95*o,a*.86],[e+.35*o,a*1.08],[e*.3,a*1.08]]);if(s.tail==="spiky"){for(let d of[.15,.45,.72]){let x=e+(.2+d*.7)*o,g=a*(.66+d*.19);y.push({k:"path",d:J(f([[x-.12*o,g+.05*o],[x,g-.2*o],[x+.12*o,g+.07*o]]),.2),fill:n.accent,...h})}y.push({k:"path",d:Z(m,.7),fill:n.body,...h})}else{let d=f([[e*.6,a*.9],[e+.4*o,a*.92],[e+.62*o,a*.5],[e+.62*o,a*.18]]);y.push(...b(d,.13*o,n.body));let x=d[d.length-1];y.push({k:"group",x:x.x,y:x.y,rot:r.angle,s:o,items:[{k:"path",d:J([{x:-.15,y:.04},{x:0,y:-.22},{x:.15,y:.04}],.2),fill:n.accent,stroke:n.outline,lw:t/o}]})}break}}return y}var ci={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 ui(s,{cx:r=.5,cy:e=.36,T:t=.18}={}){let n={...ci,...s},o=new Array(99).fill(0),a=(c,[u,f],h=.99)=>{o[c*3]=r+u*t,o[c*3+1]=e+f*t,o[c*3+2]=h};for(let c of Object.keys(K))a(K[c],n[c]);let i=n.tilt??0,l=(c,u)=>[n.nose[0]+c*Math.cos(i)-u*Math.sin(i),n.nose[1]+c*Math.sin(i)+u*Math.cos(i)];return a(Ue.leftEye,l(-.1,-.08)),a(Ue.rightEye,l(.1,-.08)),a(Ue.leftEar,l(-.22,-.02)),a(Ue.rightEar,l(.22,-.02)),o}var zs=()=>ui({});var lr=class{constructor(r={}){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");this.lostMs=r.lostMs??250,this.maxExtrapolateMs=r.maxExtrapolateMs??25}get delayMs(){return this.interval}push(r,e,t,n=Us()){Number.isFinite(e)||(e=n),this.clock(e,n);let o=this.tracks.get(r);if(!o||e-o.tb>this.lostMs||e<o.tb-this.lostMs||t.length!==o.b.length){this.tracks.set(r,{a:null,ta:e,b:t,tb:e,out:null,outAt:NaN});return}if(t===o.b||e<=o.tb){e===o.tb&&t!==o.b&&(o.b=t,o.out=null);return}o.a=o.b,o.ta=o.tb,o.b=t,o.tb=e,o.out=null}at(r,e=Us()){let t=this.tracks.get(r);if(!t)return null;if(!t.a)return t.b;if(t.out&&t.outAt===e)return t.out;let n=e-this.offset-this.interval,o=t.tb-t.ta,a=Math.min(o*.5,this.maxExtrapolateMs),i=Math.min(Math.max((n-t.ta)/o,0),1+a/o);return t.out=Hs(t.a,t.b,i),t.outAt=e,t.out}forget(r){this.tracks.delete(r)}clear(){this.tracks.clear()}clock(r,e){let t=e-r;if(!Number.isFinite(this.offset)||t<this.offset||t>this.offset+1e3?this.offset=t:Number.isFinite(this.lastArrival)&&(this.offset+=Math.min(t-this.offset,(e-this.lastArrival)/1e3)),this.lastArrival=e,Number.isFinite(this.lastT)&&r>this.lastT){let n=r-this.lastT;n<this.interval*3+20&&(this.interval+=(Math.min(Math.max(n,8),100)-this.interval)*.1)}r<=this.lastT||(this.lastT=r)}},Us=()=>globalThis.performance?.now()??Date.now();function Hs(s,r,e){let t=r.slice(),n=e<.5?s:r;for(let o=0;o+2<r.length;o+=3){let a=s[o],i=s[o+1],l=r[o],c=r[o+1];s[o+2]>=.5&&r[o+2]>=.5&&Math.abs(l-a)+Math.abs(c-i)<.15?(t[o]=a+(l-a)*e,t[o+1]=i+(c-i)*e,t[o+2]=s[o+2]+(r[o+2]-s[o+2])*Math.min(e,1)):(t[o]=n[o],t[o+1]=n[o+1],t[o+2]=n[o+2])}return t}var _l=yn.map(s=>s.id);var Or=new Map(yn.map(s=>[s.id,s])),yt=Or.get("fox"),Gs=s=>typeof s=="string"&&Or.has(s),Lt=s=>Or.get(s);var fi=s=>typeof s=="string"?Or.get(s)??yt:s;function $s(s,r){let e=fi(s),t=zs(),n=Dr(e),o=_t(t,{x:0,y:0,w:1,h:1},{band:n}),a=-Vs(Nr(e,.05)).minY,l=Math.min(.27,.43/Math.max(a,1))*r/rt[n].head/o.U,c=.5*r+Math.min(0,(a-1.6)*.06*r),u={x:r/2-o.head.x*l,y:c-o.head.y*l,w:l,h:l};return ir(t,e,u,{portrait:!0})}function Ws(s,r,e=.5){if(!s||s.length!==r.length)return r.slice();let t=r.slice();for(let n=0;n+2<r.length;n+=3){let o=s[n+2],a=r[n+2],i=o>=.5,l=a>=.5;i&&a>=.3&&(t[n+2]=Math.max(a,.5)),i&&l&&Math.hypot(r[n]-s[n],r[n+1]-s[n+1])<.15?(t[n]=s[n]+(r[n]-s[n])*e,t[n+1]=s[n+1]+(r[n+1]-s[n+1])*e):i&&!l&&t[n+2]>=.5&&(t[n]=s[n],t[n+1]=s[n+1])}return mi(s,r,t,e*pi),t}var pi=.35,di=11;function mi(s,r,e,t){let n=K.leftShoulder*3,o=K.rightShoulder*3,a=(f,h)=>f[h+2]>=.5;if(!a(s,n)||!a(s,o)||!a(r,n)||!a(r,o))return;let i=(f,h)=>(f[n+h]+f[o+h])/2,l=[i(s,0),i(s,1)],c=[i(r,0),i(r,1)],u=[i(e,0),i(e,1)];for(let f=0;f<di&&f*3+2<r.length;f++){let h=f*3;if(!a(s,h)||!a(r,h))continue;let b=[s[h]-l[0],s[h+1]-l[1]],y=[r[h]-c[0],r[h+1]-c[1]];Math.hypot(y[0]-b[0],y[1]-b[1])>=.15||(e[h]=u[0]+b[0]+(y[0]-b[0])*t,e[h+1]=u[1]+b[1]+(y[1]-b[1])*t)}}function Vs(s){let r={minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0},e=(t,n)=>{r.minX=Math.min(r.minX,t),r.minY=Math.min(r.minY,n),r.maxX=Math.max(r.maxX,t),r.maxY=Math.max(r.maxY,n)};for(let t of s){let n="lw"in t&&t.stroke?(t.lw??1)/2:0;switch(t.k){case"circle":e(t.x-t.r-n,t.y-t.r-n),e(t.x+t.r+n,t.y+t.r+n);break;case"ellipse":case"rect":{let o=t.k==="ellipse"?t.rx:t.w/2,a=t.k==="ellipse"?t.ry:t.h/2,i=Math.max(o,a)+n;e(t.x-i,t.y-i),e(t.x+i,t.y+i);break}case"path":{let o=xn(t.d);for(let a=0;a+1<o.length;a+=2)e(o[a]-n,o[a+1]-n),e(o[a]+n,o[a+1]+n);break}case"line":for(let o=0;o+1<t.pts.length;o+=2)e(t.pts[o]-n,t.pts[o+1]-n),e(t.pts[o]+n,t.pts[o+1]+n);break;case"group":{let o=Vs(t.items);if(!Number.isFinite(o.minX))break;let a=t.s??1,i=Math.cos(t.rot??0),l=Math.sin(t.rot??0);for(let[c,u]of[[o.minX,o.minY],[o.maxX,o.minY],[o.minX,o.maxY],[o.maxX,o.maxY]])e(t.x+(c*i-u*l)*a,t.y+(c*l+u*i)*a);break}}}return r}var je=()=>Float64Array.of(1,0,0,1,0,0);function we(s,r,e,t,n,o,a){let i=n?Math.cos(n):1,l=n?Math.sin(n):0,c=i*o,u=l*o,f=-l*a,h=i*a;if(!r)return s[0]=c,s[1]=u,s[2]=f,s[3]=h,s[4]=e,s[5]=t,s;let b=r[0],y=r[1],m=r[2],d=r[3];return s[0]=b*c+m*u,s[1]=y*c+d*u,s[2]=b*f+m*h,s[3]=y*f+d*h,s[4]=b*e+m*t+r[4],s[5]=y*e+d*t+r[5],s}function qs(s,r,e){let t=s[0]*s[3]-s[1]*s[2];if(Math.abs(t)<1e-12)return null;let n=r-s[4],o=e-s[5];return[(s[3]*n-s[2]*o)/t,(-s[1]*n+s[0]*o)/t]}var Xs={white:16777215,black:0,red:16711680,transparent:0},cr=new Map;function he(s){if(typeof s=="number")return[s&16777215,1];let r=cr.get(s);if(r)return r;let e=[16777215,1],t=s.trim().toLowerCase();if(t[0]==="#"){let n=t.slice(1),o=n.length<=4?[...n].map(i=>i+i).join(""):n,a=parseInt(o.slice(0,6),16);Number.isFinite(a)&&(e=[a,o.length===8?parseInt(o.slice(6,8),16)/255:1])}else if(t.startsWith("rgb")){let n=t.match(/-?\d*\.?\d+%?/g)?.map(c=>c.endsWith("%")?parseFloat(c)/100*255:parseFloat(c))??[],[o=255,a=255,i=255]=n,l=n[3]===void 0?1:t.match(/,\s*[\d.]+%\s*\)$/)?n[3]/255:n[3];e=[(vn(o)<<16|vn(a)<<8|vn(i))>>>0,Math.min(Math.max(l,0),1)]}else if(t in Xs)e=[Xs[t],t==="transparent"?0:1];else if(typeof document<"u"){let n=document.createElement("canvas").getContext("2d");if(n){n.fillStyle="#ffffff",n.fillStyle=t;let o=n.fillStyle;if(o!==t)return cr.set(s,e=he(o)),e}}return cr.size>512&&cr.clear(),cr.set(s,e),e}var vn=s=>Math.min(Math.max(Math.round(s),0),255);function nt(s,r,e=!1){let t=Math.min(Math.max(r,0),1),n=(s>>16&255)*t,o=(s>>8&255)*t,a=(s&255)*t,i=e?0:t*255;return(Math.round(i)<<24|Math.round(a)<<16|Math.round(o)<<8|Math.round(n))>>>0}var xt=(s,r=1)=>`rgba(${s>>16&255},${s>>8&255},${s&255},${r})`;function wn(s,r){if(s===16777215)return r;if(r===16777215)return s;let e=t=>Math.round((s>>t&255)*(r>>t&255)/255);return(e(16)<<16|e(8)<<8|e(0))>>>0}var st={linear:s=>s,quadIn:s=>s*s,quadOut:s=>s*(2-s),quadInOut:s=>s<.5?2*s*s:-1+(4-2*s)*s,cubicOut:s=>1-(1-s)**3,sineInOut:s=>-(Math.cos(Math.PI*s)-1)/2,backOut:s=>1+(1.70158+1)*(s-1)**3+1.70158*(s-1)**2,elasticOut:s=>s===0||s===1?s:2**(-10*s)*Math.sin((s*10-.75)*(2*Math.PI/3))+1,bounceOut:s=>s<1/2.75?7.5625*s*s:s<2/2.75?7.5625*(s-=1.5/2.75)*s+.75:s<2.5/2.75?7.5625*(s-=2.25/2.75)*s+.9375:7.5625*(s-=2.625/2.75)*s+.984375};function Ys(s){let r=s>>>0;return()=>{r=r+1831565813>>>0;let e=r;return e=Math.imul(e^e>>>15,e|1),e^=e+Math.imul(e^e>>>7,e|61),((e^e>>>14)>>>0)/4294967296}}var T={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},ot=[],bi="x y rot sx sy alpha la lb lc ld world tint flags moved dirty gen parent first next prev stamp".split(" ");function Ks(s){let r=T;for(let t of bi){let n=r[t],o=new n.constructor(t==="world"?s*6:s);o.set(n),r[t]=o}let e=new Int32Array(s);for(let t=0;t<T.freeCount;t++)e[t]=T.free[(T.freeHead+t)%T.cap];for(T.free=e,T.freeHead=0,T.cap=s,T.epoch++;ot.length<s;)ot.push(null)}function Sn(s){T.x[s]=T.y[s]=T.rot[s]=0,T.sx[s]=T.sy[s]=T.alpha[s]=1,T.la[s]=T.ld[s]=1,T.lb[s]=T.lc[s]=0;let r=s*6,e=T.world;e[r]=e[r+3]=1,e[r+1]=e[r+2]=e[r+4]=e[r+5]=0,T.tint[s]=16777215,T.flags[s]=3,T.moved[s]=1,T.dirty[s]=0,T.parent[s]=T.first[s]=T.next[s]=T.prev[s]=-1}Ks(256);Sn(0);T.flags[0]=0;Sn(1);T.flags[1]=0;function js(){let s;if(T.freeCount){s=T.free[T.freeHead],T.freeHead=(T.freeHead+1)%T.cap,T.freeCount--;let r=ot[s];r&&(r._i=0,r._g=-1,ot[s]=null)}else T.top===T.cap&&Ks(T.cap*2),s=T.top++;return Sn(s),s}function Mn(s,r){Ir(s);for(let t=T.first[s];t>=0;){let n=T.next[t];T.parent[t]=T.next[t]=T.prev[t]=-1,t=n}T.first[s]=-1,T.flags[s]=T.flags[s]&-3,T.moved[s]=0;let e=T.gen[s]+1;T.gen[s]=e,e!==4294967295&&(r&&(ot[s]=r),T.free[(T.freeHead+T.freeCount)%T.cap]=s,T.freeCount++)}function Qs(s){for(let r=0;r<ot.length;r++){let e=ot[r];e&&s(e)&&(e._i=0,e._g=-1,ot[r]=null)}}function Zs(s,r){Ir(s);let e=T.first[r];T.parent[s]=r,T.next[s]=e,T.prev[s]=-1,e>=0&&(T.prev[e]=s),T.first[r]=s,T.moved[s]=1}function Ir(s){let r=T.parent[s];if(r<0)return;let e=T.next[s],t=T.prev[s];t>=0?T.next[t]=e:T.first[r]=e,e>=0&&(T.prev[e]=t),T.parent[s]=T.next[s]=T.prev[s]=-1}var ur={root:-1,gen:-1,world:new Float64Array(6)};function Js(s){let r=++T.pass,e=T.world,t=s*6,n=ur.world,o=ur.root!==s||ur.gen!==T.gen[s];for(let a=0;a<6;a++)n[a]!==e[t+a]&&(o=!0),n[a]=e[t+a];ur.root=s,ur.gen=T.gen[s],T.stamp[s]=o?r:r-1}function eo(s){T.stamp[s]=T.pass}function to(s){for(let r=T.first[s];r>=0;){let e=T.next[r];to(r),r=e}Mn(s)}var An=typeof FinalizationRegistry=="function"?new FinalizationRegistry(s=>T.gen[s.i]===s.g&&to(s.i)):null;function Tn(s){s._reg||!An||(s._reg=!0,An.register(s,{i:s._i,g:s._g},s))}function ro(s){s._reg&&An.unregister(s)}function hr(s){if(s){for(let r=0;r<s.length;r++)if(s[r].enabled)return!0}return!1}function no(s,r){let e=0;for(let t=0;t<s.length;t++){let n=s[t];n.enabled&&n.pad&&(e+=n.pad(r))}return e}var Ae={gl:null,c2d:null,live:null};var Y=new Float64Array(3),fr=4,yi=1,pr=()=>yi++;var ne=je(),P=T,Fe=class{constructor(r){p(this,"kernel",r);p(this,"_i",js());p(this,"_g",P.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 P.x[this._i]}set x(r){let e=this._i||1;P.x[e]=r,P.moved[e]=1}get y(){return P.y[this._i]}set y(r){let e=this._i||1;P.y[e]=r,P.moved[e]=1}get rotation(){return P.rot[this._i]}set rotation(r){let e=this._i||1;P.rot[e]=r,P.dirty[e]=P.moved[e]=1}get scaleX(){return P.sx[this._i]}set scaleX(r){let e=this._i||1;P.sx[e]=r,P.dirty[e]=P.moved[e]=1}get scaleY(){return P.sy[this._i]}set scaleY(r){let e=this._i||1;P.sy[e]=r,P.dirty[e]=P.moved[e]=1}get alpha(){return P.alpha[this._i]}set alpha(r){let e=this._i||1;P.alpha[e]=r,P.moved[e]=1}get visible(){return(P.flags[this._i]&1)!==0}set visible(r){let e=this._i||1;r?P.flags[e]=P.flags[e]|1:P.flags[e]=P.flags[e]&-2,P.moved[e]=1}get destroyed(){return P.gen[this._i]!==this._g}get world(){let r=this._i||1;return(this._wi!==r||this._we!==P.epoch)&&(this._wv=P.world.subarray(r*6,r*6+6),this._wi=r,this._we=P.epoch),this._wv}get data(){return this._data??(this._data={})}set data(r){this._data=r}get scale(){return this.scaleX}set scale(r){this.scaleX=this.scaleY=r}get z(){return this._z}set z(r){r!==this._z&&(this._z=r,this.parent&&(this.parent.sortDirty=!0))}get tint(){return P.tint[this._i]}set tint(r){P.tint[this._i||1]=typeof r=="number"?r&16777215:he(r)[0]}set anchor(r){typeof r=="number"?this.anchorX=this.anchorY=r:(this.anchorX=r.x,this.anchorY=r.y)}get width(){return 0}set width(r){}get height(){return 0}set height(r){}set(r){for(let e in r){let t=r[e];t!==void 0&&(this[e]=t)}return this}destroy(){this.destroyed||(this.visible=!1,this.parent&&(this.parent.dead=!0,this.parent=null),Mn(this._i,this),ro(this),this.kernel.tweens.stopAll(this),this._pool?.forget(this))}updateWorld(){let r=this.parent?this.parent.updateWorld():null;return we(this.world,r,this.x,this.y,this.rotation,this.scaleX,this.scaleY)}draw(r,e,t){}};function io(s){Qs(r=>r.kernel===s)}var En=!1,so=Object.freeze([]),vt=class s extends Fe{constructor(e){super(e);p(this,"children",so);p(this,"sortDirty",!1);p(this,"dead",!1);Tn(this)}add(e,...t){this.adopt(e);for(let n=0;n<t.length;n++)this.adopt(t[n]);return e}adopt(e){e.parent&&e.parent.detach(e),e.parent=this,!e.destroyed&&!this.destroyed&&Zs(e._i,this._i),this.children===so&&(this.children=[]),this.children.push(e),(e.z!==0||this.sortDirty)&&(this.sortDirty=!0)}remove(e){this.detach(e),e._pool||Tn(e)}detach(e){let t=this.children,n=t.indexOf(e);if(n>=0){for(let o=n+1;o<t.length;o++)t[o-1]=t[o];t.pop()}e.parent===this&&(e.parent=null,e.destroyed||Ir(e._i))}clear(){for(let e of this.children)e.destroy()}destroy(){for(let e of this.children)e.destroy();super.destroy()}sweep(){if(this.dead){this.dead=!1;let e=0;for(let t of this.children)t.destroyed?t.parent===this&&(t.parent=null):this.children[e++]=t;this.children.length=e}for(let e of this.children)e instanceof s&&e.sweep()}draw(e,t,n){if(En)return P.parent[this._i]<0&&!this.destroyed&&eo(this._i),this.drawChildren(e,t,n);En=!0;try{this.destroyed||Js(this._i),this.drawChildren(e,t,n)}finally{En=!1}}drawChildren(e,t,n){if(this.sortDirty){let l=new Map(this.children.map((c,u)=>[c,u]));this.children.sort((c,u)=>c.z-u.z||l.get(c)-l.get(u)),this.sortDirty=!1}let o=this.children,a=this._i,i=P.stamp[a]===P.pass;for(let l=0;l<o.length;l++){let c=o[l],u=c._i,f=P.alpha[u];if(P.gen[u]!==c._g||!(P.flags[u]&1)||f<=0)continue;if(i||P.moved[u]){P.moved[u]=0,P.stamp[u]=P.pass;let y,m,d,x;if(P.dirty[u]){P.dirty[u]=0;let U=P.rot[u],X=U?Math.cos(U):1,G=U?Math.sin(U):0,fe=P.sx[u],H=P.sy[u];P.la[u]=y=X*fe,P.lb[u]=m=G*fe,P.lc[u]=d=-G*H,P.ld[u]=x=X*H}else y=P.la[u],m=P.lb[u],d=P.lc[u],x=P.ld[u];let g=P.world,M=P.x[u],v=P.y[u],A=u*6,E=a*6,C=g[E],_=g[E+1],L=g[E+2],I=g[E+3];g[A]=C*y+L*m,g[A+1]=_*y+I*m,g[A+2]=C*d+L*x,g[A+3]=_*d+I*x,g[A+4]=C*M+L*v+g[E+4],g[A+5]=_*M+I*v+g[E+5]}let h=t*f,b=wn(n,P.tint[u]);c.clip||c.mask||c.filters?lo(e,c,h,b):c.draw(e,h,b)}}},be=new Float64Array(128),gt=0,Rn=new Float64Array(8);function Fn(s,r,e,t){r.clip||r.mask||r.filters?lo(s,r,e,t):r.draw(s,e,t)}function lo(s,r,e,t){let n=s.r,o=r.world,a=r.clip,i=!1,l=!1;if(a)if(Math.abs(o[1])<1e-9&&Math.abs(o[2])<1e-9&&gt<32){let f=o[0]*a.x+o[4],h=o[0]*(a.x+a.width)+o[4],b=o[3]*a.y+o[5],y=o[3]*(a.y+a.height)+o[5],m=Math.min(f,h),d=Math.max(f,h),x=Math.min(b,y),g=Math.max(b,y);if(gt){let v=(gt-1)*4;m=Math.max(m,be[v]),x=Math.max(x,be[v+1]),d=Math.min(d,be[v+2]),g=Math.min(g,be[v+3])}let M=gt++*4;be[M]=m,be[M+1]=x,be[M+2]=d,be[M+3]=g,n.clip(m,x,Math.max(d-m,0),Math.max(g-x,0)),l=!0}else i=!0;let c=r.mask&&r.mask.visible?r.mask:null,u=hr(r.filters)?r.filters:null;try{if(i&&n.beginLayer(),c&&n.beginLayer(),u?(r.draw(s,n.beginLayer()?1:e,t),n.endLayer(e,u)):r.draw(s,e,t),c&&(n.beginMask(),we(c.world,o,c.x,c.y,c.rotation,c.scaleX,c.scaleY),Fn(s,c,c.alpha,16777215),n.endLayer(1)),i&&a){n.beginMask();for(let f=0;f<4;f++){let h=f===1||f===2?a.x+a.width:a.x,b=f>1?a.y+a.height:a.y;Rn[f*2]=o[0]*h+o[2]*b+o[4],Rn[f*2+1]=o[1]*h+o[3]*b+o[5]}n.polygon(Rn,4,16777215,1),n.endLayer(1)}}finally{if(l)if(gt--,gt){let f=(gt-1)*4;n.clip(be[f],be[f+1],be[f+2]-be[f],be[f+3]-be[f+1])}else n.unclip()}}var Se=class extends Fe{constructor(e,t,n){super(e);p(this,"_frame",null);p(this,"_w",null);p(this,"_h",null);p(this,"slice",0);p(this,"autoAnchor",!0);p(this,"frameName",null);t&&(this.frame=t),n?.anchor===void 0&&this.useFrameAnchor(),n&&this.set(n)}get frame(){return this._frame}set frame(e){this.frameName=typeof e=="string"?e:null,this._frame=typeof e=="string"?this.kernel.frame(e):e,this.autoAnchor&&this.useFrameAnchor()}set anchor(e){this.autoAnchor=!1,super.anchor=e}get naturalWidth(){let e=this.frameNow();return e?(e.sw??e.w)/e.scale-e.margin*2:0}get naturalHeight(){let e=this.frameNow();return e?(e.sh??e.h)/e.scale-e.margin*2:0}get width(){return this._w??this.naturalWidth}set width(e){this._w=e}get height(){return this._h??this.naturalHeight}set height(e){this._h=e}sizeQ(e){Dt[0]=this._w??(e.sw??e.w)/e.scale-e.margin*2,Dt[1]=this._h??(e.sh??e.h)/e.scale-e.margin*2}frameNow(){return this.frameName&&!this.kernel.atlas.valid(this._frame)&&(this._frame=this.kernel.frame(this.frameName)),this._frame}useFrameAnchor(){let e=this._frame;if(!e)return;let t=(e.sw??e.w)/e.scale-e.margin*2,n=(e.sh??e.h)/e.scale-e.margin*2;this.anchorX=t>0?(e.ox-e.margin)/t:0,this.anchorY=n>0?(e.oy-e.margin)/n:0}draw(e,t,n){let o=this.frameNow();if(!o)return;let a=Dt;this.sizeQ(o),a[2]=this.anchorX,a[3]=this.anchorY,a[4]=t,xi(e,o,this.world,this.slice,n,this.blend)}},Nt=new Float64Array(12),Bt=new Float64Array(12),dr={x:0,y:0,w:0,h:0};function oo(s,r,e,t,n,o){r=Math.max(r,0),e=Math.max(e,0),t=Math.max(t,0);let a=e+t>n?e*n/(e+t):e,i=e+t>n?t*n/(e+t):t,l=a/o,c=i/o;if(l+c>r){let u=r/(l+c);l*=u,c*=u}s[0]=0,s[1]=l,s[2]=0,s[3]=a,s[4]=l,s[5]=r-l-c,s[6]=a,s[7]=n-a-i,s[8]=r-c,s[9]=c,s[10]=n-i,s[11]=i}var Dt=new Float64Array(5);function xi(s,r,e,t,n,o){let a=Dt,i=a[0],l=a[1],c=a[2],u=a[3],f=a[4],h=s.tex(r.surface),b=t===0?r.slice??0:t;if(b===0){let v=(r.sw??r.w)/r.scale-r.margin*2,A=(r.sh??r.h)/r.scale-r.margin*2,E=v>0?i/v:1,C=A>0?l/A:1,_=-c*i+((r.tx??0)/r.scale-r.margin)*E,L=-u*l+((r.ty??0)/r.scale-r.margin)*C;mr(e,_,L),Y[0]=r.w/r.scale*E,Y[1]=r.h/r.scale*C,Y[2]=f,s.r.quadQ(h,r,ne,n,o);return}let y=r.tx??0,m=r.ty??0,d=(r.sw??r.w)-r.w-y,x=(r.sh??r.h)-r.h-m,g=-c*i-r.margin+y/r.scale,M=-u*l-r.margin+m/r.scale;if(oo(Nt,i+r.margin*2-(y+d)/r.scale,(typeof b=="number"?b:b[3])-y,(typeof b=="number"?b:b[1])-d,r.w,r.scale),oo(Bt,l+r.margin*2-(m+x)/r.scale,(typeof b=="number"?b:b[0])-m,(typeof b=="number"?b:b[2])-x,r.h,r.scale),mr(e,g,M),Y[2]=f,!s.r.nineQ?.(h,r,Nt,Bt,ne,n,o))for(let v=0;v<12;v+=4){let A=Bt[v+1],E=Bt[v+3];if(!(A<=0||E<=0))for(let C=0;C<12;C+=4){let _=Nt[C+1],L=Nt[C+3];_<=0||L<=0||(dr.x=r.x+Nt[C+2],dr.y=r.y+Bt[v+2],dr.w=L,dr.h=E,mr(e,g+Nt[C],M+Bt[v]),Y[0]=_,Y[1]=A,Y[2]=f,s.r.quadQ(h,dr,ne,n,o))}}}function mr(s,r,e){ne[0]=s[0],ne[1]=s[1],ne[2]=s[2],ne[3]=s[3],ne[4]=s[0]*r+s[2]*e+s[4],ne[5]=s[1]*r+s[3]*e+s[5]}var He=class extends Se{constructor(e,t,n={}){super(e,null);p(this,"_spec");p(this,"baked",null);p(this,"bakedEffects",!0);this._spec=t,this.bake(),n.anchor===void 0&&this.useFrameAnchor(),this.set(n)}get spec(){return this._spec}set spec(e){this._spec=e,this.baked=null,this._w=this._h=null,this.bake()}bake(){let e=this.kernel;return this.baked&&e.atlas.valid(this.baked.frame)&&this.baked.frame.scale===e.pixelScale&&this.bakedEffects===e.effects?this.baked:(this.bakedEffects=e.effects,this.baked=e.shape(this._spec),this._frame=this.baked.frame,this.slice=this.baked.slice,this.baked)}frameNow(){return this.bake().frame}sizeQ(){let e=this.bake();Dt[0]=this._w??e.w,Dt[1]=this._h??e.h}get width(){return this._w??this.bake().w}set width(e){this._w=e}get height(){return this._h??this.bake().h}set height(e){this._h=e}},ao=(s,r,e)=>s===void 0?r:typeof s=="number"?s:s[0]+(s[1]-s[0])*e(),kt=class kt extends Fe{constructor(e,t,n={}){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=t,this.max=Math.max(1,Math.floor(n.max??200)),this.f=new Float32Array(this.max*kt.W),this.tints=new Uint32Array(this.max),this.blend=n.blend??"normal",this.gravity=n.gravity??0,this.drag=n.drag??1}get alive(){return this.count}burst(e,t,n,o={}){let a=kt.W,i=this.random,l=o.tint===void 0?16777215:he(o.tint)[0];for(let c=0;c<n;c++){let u=this.count;if(u>=this.max){let d=0,x=1/0;for(let g=0;g<this.max;g++){let M=this.f[g*a+5]-this.f[g*a+4];M<x&&(x=M,d=g)}u=d}else this.count++;let f=(o.angle??0)+(o.spread===void 0?i()*Math.PI*2:(i()-.5)*o.spread),h=ao(o.speed,200,i),b=Array.isArray(o.scale)?o.scale[0]:o.scale??1,y=Array.isArray(o.scale)?o.scale[1]:o.scale??1,m=u*a;this.f[m]=e,this.f[m+1]=t,this.f[m+2]=Math.cos(f)*h,this.f[m+3]=Math.sin(f)*h,this.f[m+4]=0,this.f[m+5]=Math.max(ao(o.life,.8,i),.01),this.f[m+6]=i()*Math.PI*2,this.f[m+7]=(i()-.5)*2*(o.spin??0),this.f[m+8]=b,this.f[m+9]=y,this.f[m+10]=o.alpha??1,this.tints[u]=l}}update(e){let t=kt.W,n=this.f,o=this.drag>=1?1:Math.pow(Math.max(this.drag,0),e);for(let a=0;a<this.count;){let i=a*t;if(n[i+4]=n[i+4]+e,n[i+4]>=n[i+5]){let l=--this.count;a!==l&&(n.copyWithin(i,l*t,l*t+t),this.tints[a]=this.tints[l]);continue}n[i+3]=(n[i+3]+this.gravity*e)*o,n[i+2]=n[i+2]*o,n[i]=n[i]+n[i+2]*e,n[i+1]=n[i+1]+n[i+3]*e,n[i+6]=n[i+6]+n[i+7]*e,a++}}clear(){this.count=0}draw(e,t,n){if(!this.count)return;let o=typeof this.frameRef=="string"?this.frameRef=this.kernel.frame(this.frameRef):this.frameRef,a=kt.W,i=this.f,l=this.world,c=o.w/o.scale,u=o.h/o.scale;for(let f=0;f<this.count;f++){let h=f*a,b=i[h+4]/i[h+5],y=i[h+8]+(i[h+9]-i[h+8])*b,m=t*i[h+10]*(1-b*b),d=i[h+6],x=Math.cos(d)*y,g=Math.sin(d)*y,M=i[h],v=i[h+1],A=l[0],E=l[1],C=l[2],_=l[3],L=A*x+C*g,I=E*x+_*g,U=C*x-A*g,X=_*x-E*g;ne[0]=L,ne[1]=I,ne[2]=U,ne[3]=X,ne[4]=A*M+C*v+l[4]-(L*c+U*u)/2,ne[5]=E*M+_*v+l[5]-(I*c+X*u)/2,Y[0]=c,Y[1]=u,Y[2]=m,e.r.quadQ(e.tex(o.surface),o,ne,wn(n,this.tints[f]),this.blend)}}};p(kt,"W",11);var Ot=kt;var Ce=class extends Se{constructor(e,t,n={}){let{fps:o,loop:a,playing:i,speed:l,onComplete:c,...u}=n;if(!t.frames.length)throw new Error("[engine] an animation needs at least one frame");super(e,t.frames[0],u);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=t.frames,this.durations=t.durations&&o===void 0?t.durations:null,this.fps=o??12,this.loop=a!==!1,this.speed=l??1,this.onComplete=c??null,this._playing=i!==!1,this.speed<0&&this.show(t.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(e){let t=this.frames.length;return this.show((Math.floor(e)%t+t)%t),this.t=0,this}gotoAndPlay(e){return this._playing=!0,this.gotoFrame(e)}gotoAndStop(e){return this._playing=!1,this.gotoFrame(e)}show(e){e===this.index&&this._frame||(this.index=e,this.frame=this.frames[e])}secondsOf(e){let t=this.durations?.[e];return t!==void 0&&t>0?t:1/Math.max(this.fps,.001)}update(e){if(!this._playing||this.destroyed||this.speed===0)return;let t=this.frames.length,n=this.speed<0;this.t+=e*Math.abs(this.speed);let o=this.index;for(let a=0;a<1e3;a++){let i=this.secondsOf(o);if(this.t<i)break;this.t-=i;let l=n?o-1:o+1;if(l<0||l>=t){if(!this.loop){this.t=0,this._playing=!1,this.show(o),this.onComplete?.();return}o=n?t-1:0}else o=l}this.show(o)}},co=(s,r)=>s.localeCompare(r,void 0,{numeric:!0});var br=class{constructor(r,e,t=2){p(this,"width",r);p(this,"height",e);p(this,"padding",t);p(this,"shelves",[]);p(this,"free",[]);p(this,"bottom",0)}alloc(r,e){let t=Math.ceil(r)+this.padding*2,n=Math.ceil(e)+this.padding*2;if(t>this.width||n>this.height)return null;for(let i=0;i<this.free.length;i++){let l=this.free[i];if(l.w>=t&&l.h>=n&&l.w*l.h<=t*n*2)return this.free.splice(i,1),this.inner(l.x,l.y,r,e)}let o=null;for(let i of this.shelves)i.h>=n&&i.h<=n*1.5+8&&this.width-i.x>=t&&(!o||i.h<o.h)&&(o=i);if(!o)if(this.bottom+n>this.height){for(let i of this.shelves)i.h>=n&&this.width-i.x>=t&&(o=i);if(!o)return null}else o={y:this.bottom,h:n,x:0},this.shelves.push(o),this.bottom+=n;let a=o.x;return o.x+=t,this.inner(a,o.y,r,e)}release(r){this.free.push({x:r.x-this.padding,y:r.y-this.padding,w:Math.ceil(r.w)+this.padding*2,h:Math.ceil(r.h)+this.padding*2})}get fill(){return this.bottom/this.height}reset(){this.shelves=[],this.free=[],this.bottom=0}inner(r,e,t,n){return{x:r+this.padding,y:e+this.padding,w:t,h:n}}},It=s=>({source:s,texture:null,pending:[]}),at=class{constructor(r=2048,e=4){p(this,"pageSize",r);p(this,"maxPages",e);p(this,"pages",[]);p(this,"gen",1);p(this,"onPage",()=>{});p(this,"onDrop",()=>{})}valid(r){return!!r&&(r.gen===this.gen||r.gen===0)}bake(r,e,t,n=1,o=0,a=0,i=0){let l=Math.max(1,Math.ceil(r)),c=Math.max(1,Math.ceil(e)),u=document.createElement("canvas");u.width=l,u.height=c;let f=u.getContext("2d");return t(f),this.put(u,l,c,n,o,a,i)}add(r,e=1,t=0,n=0){let o=document.createElement("canvas");return o.width=Math.max(1,r.width),o.height=Math.max(1,r.height),o.getContext("2d").drawImage(r,0,0),this.put(o,o.width,o.height,e,t,n,0)}release(r){if(r.gen!==this.gen)return;this.pages.find(t=>t.surface===r.surface)?.packer.release(r)}rebake(r,e,t,n,o=r.w,a=r.h){if(!this.valid(r)||e>o||t>a)return null;let i=Math.max(1,Math.ceil(e)),l=Math.max(1,Math.ceil(t)),c=this.pages.find(f=>f.surface===r.surface);if(!c)return null;let u=document.createElement("canvas");return u.width=Math.ceil(o),u.height=Math.ceil(a),n(u.getContext("2d")),c.ctx.clearRect(r.x,r.y,u.width,u.height),c.ctx.drawImage(u,r.x,r.y),r.surface.pending.push([u,r.x,r.y]),r.w=i,r.h=l,r}put(r,e,t,n,o,a,i){let l=null,c=this.pages.find(f=>(l=f.packer.alloc(e,t))!==null);if(c||(!(Math.max(e,t)+4>this.pageSize)&&this.pages.length>=this.maxPages&&(this.wipe(),c=this.pages[0],l=c?c.packer.alloc(e,t):null),(!c||!l)&&(c=this.newPage(Math.max(e,t)),l=c.packer.alloc(e,t))),!l)throw new Error(`[engine] ${e}\xD7${t} does not fit an atlas page`);let u=l;return c.ctx.drawImage(r,u.x,u.y),c.surface.pending.push([r,u.x,u.y]),{surface:c.surface,x:u.x,y:u.y,w:e,h:t,scale:n,gen:this.gen,ox:o,oy:a,margin:i}}newPage(r){let e=this.pageSize;for(;e<r+4;)e*=2;let t=document.createElement("canvas");t.width=t.height=e;let n=t.getContext("2d"),o=It(t),a={surface:o,packer:new br(e,e),ctx:n};return this.pages.push(a),this.onPage(o),a}wipe(){this.gen++;let r=0;for(let e=0;e<this.pages.length;e++){let t=this.pages[e];if(r<this.maxPages&&t.surface.source.width===this.pageSize){this.pages[r++]=t;continue}t.surface.pending=[],this.onDrop(t.surface)}this.pages.length=r;for(let 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])}};var gi=()=>{let s=typeof document<"u"?document.timeline?.currentTime:null;return typeof s=="number"&&Number.isFinite(s)?s:globalThis.performance?.now()??Date.now()},uo=()=>globalThis.performance?.now()??Date.now(),yr=class{constructor(r=gi){p(this,"now",r);p(this,"known",new Map);p(this,"smoothed",new Map);p(this,"times",new WeakMap);p(this,"lerp",new lr);p(this,"drawnAt",NaN);p(this,"drawn",0);p(this,"smoothedBody",(r,e={})=>{let t=e.interpolate!==!1;if(typeof r=="number"){let n=this.smoothed.get(r);return n?t?this.lerp.at(r,this.tick())??n.body:n.body:null}return typeof r!="object"||r===null||!Array.isArray(r.body)?null:this.posed(r.id,r.body,ki(e.smooth),t)})}note(r,e,t=uo()){for(let n of r)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:t})}of(r){return typeof r=="object"&&r!==null?r.avatar!==void 0?this.resolve(r.id,r.avatar):this.of(r.id):this.known.get(r)??bn(r-1)}posed(r,e,t,n=!0){let o=this.smooth(r,e,t);return n?this.lerp.at(r,this.tick())??o:o}smooth(r,e,t){let n=this.smoothed.get(r);if(n&&n.raw===e&&n.amount===t)return n.body;n&&n.amount!==t&&this.lerp.forget(r);let o=t<1?Ws(n?.body,e,t):e;this.smoothed.set(r,{raw:e,body:o,amount:t});let a=this.times.get(e),i=a?.arrival??uo();return this.lerp.push(r,a?.t??i,o,i),o}takeDrawn(){let r=this.drawn;return this.drawn=0,r}tick(){let r=this.now();return r!==this.drawnAt&&(this.drawnAt=r,this.drawn++),r}resolve(r,e){return Gs(e)?e:bn(r-1)}};var ki=s=>s===!1?1:typeof s=="number"?Math.min(Math.max(s,.05),1):.5;var po=new Float64Array(1),ho=new Int32Array(po.buffer),zt=(s,r)=>(s=Math.imul(s^r,1540483477),s^s>>>15);function Ze(s,r=2538058380){return s!==s?zt(r,2146959360):(po[0]=s===0?0:s,zt(zt(r,ho[0]),ho[1]))}function fo(s,r=2166136261){for(let e=0;e<s.length;e++)r=Math.imul(r^s.charCodeAt(e),16777619);return r}function De(s){switch(typeof s){case"number":return Ze(s);case"string":return fo(s);case"boolean":return s?1013904242:461845907;case"object":{if(s===null)return 625341585;if(Array.isArray(s)||s instanceof Float64Array){let t=1779033703^s.length;for(let n=0;n<s.length;n++){let o=s[n];t=zt(t,typeof o=="number"?Ze(o):De(o))}return t}let r=1359893119,e=s;for(let t in e){let n=e[t];n!==void 0&&(r=r+zt(fo(t),De(n))|0)}return zt(r,2600822924)}default:return 0}}function Ut(s,r){if(s===r)return!0;if(typeof s!="object"||typeof r!="object"||s===null||r===null)return typeof s=="number"&&typeof r=="number"&&s!==s&&r!==r;let e=Array.isArray(s)||s instanceof Float64Array;if(e!==(Array.isArray(r)||r instanceof Float64Array))return!1;if(e){let o=s,a=r;if(o.length!==a.length)return!1;for(let i=0;i<o.length;i++)if(o[i]!==a[i]&&!Ut(o[i],a[i]))return!1;return!0}let t=s,n=r;for(let o in t)if(t[o]!==void 0&&!Ut(t[o],n[o]))return!1;for(let o in n)if(n[o]!==void 0&&t[o]===void 0)return!1;return!0}function xr(s){if(typeof s!="object"||s===null)return s;if(Array.isArray(s))return s.map(xr);if(s instanceof Float64Array)return s.slice();let r={};for(let e in s)s[e]!==void 0&&(r[e]=xr(s[e]));return r}var Ht=class{constructor(r=1/0){p(this,"max",r);p(this,"buckets",new Map);p(this,"n",0)}get size(){return this.n}get(r,e=De(r)){let t=this.buckets.get(e);if(t){for(let n=0;n<t.length;n++)if(Ut(t[n].key,r))return t[n].value}}set(r,e,t=De(r)){let n=this.buckets.get(t);if(n){for(let o of n)if(Ut(o.key,r)){o.value=e;return}}this.n>=this.max&&this.clear(),(!n||!this.buckets.has(t))&&this.buckets.set(t,n=[]),n.push({key:xr(r),value:e}),this.n++}clear(){this.buckets.clear(),this.n=0}};var Cn=0,mo=1,Ur=2,Pn=3,Gt=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*(fr+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(r){this.scale=r,this.sp=this.real=this.mute=0,this.skipped=0,this.cOn=!1,this.clipVer++}growQ(){let r=this.gq;this.grow(r[0],r[1],r[2],r[3])}grow(r,e,t,n){if(!this.real)return;let o=this.bnd,a=(this.real-1)*4;r<o[a]&&(o[a]=r),e<o[a+1]&&(o[a+1]=e),t>o[a+2]&&(o[a+2]=t),n>o[a+3]&&(o[a+3]=n)}area(r,e){let t=this.bnd,n=r*4,o=this.scale;return this.rx0=Math.max(Math.floor((t[n]-e)*o)-1,0),this.ry0=Math.max(Math.floor((t[n+1]-e)*o)-1,0),this.rx1=Math.min(Math.ceil((t[n+2]+e)*o)+1,this.canvas.width),this.ry1=Math.min(Math.ceil((t[n+3]+e)*o)+1,this.canvas.height),this.rx1>this.rx0&&this.ry1>this.ry0}clip(r,e,t,n){let o=this.scale,a=this.canvas.width,i=this.canvas.height,l=Math.min(Math.max(Math.round(r*o),0),a),c=Math.min(Math.max(Math.round(e*o),0),i),u=Math.min(Math.max(Math.round((r+t)*o),l),a),f=Math.min(Math.max(Math.round((e+n)*o),c),i);this.cOn&&l===this.px0&&c===this.py0&&u===this.px1&&f===this.py1||(this.cOn=!0,this.px0=l,this.py0=c,this.px1=u,this.py1=f,this.clipVer++)}unclip(){this.cOn&&(this.cOn=!1,this.clipVer++)}push(r){if(r<Ur&&(this.mute||this.real>=fr||!this.pushLayer())&&(r+=2),r===Pn)this.mute++;else if(r!==Ur){let 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++]=r,r<Ur}beginLayer(){return this.push(Cn)}beginMask(){this.push(this.sp&&this.stack[this.sp-1]===Cn?mo:Pn)}endLayer(r,e){if(!this.sp)return;let t=this.stack[--this.sp];if(t===Pn){if(this.mute--,!this.sp)return;t=this.stack[--this.sp]}if(t===mo){let n=--this.real,o=this.popLayer();this.area(n-1,0)&&this.composite(o,!0,1,null);let a=this.bnd,i=(n-1)*4,l=n*4;a[i]=Math.max(a[i],a[l]),a[i+1]=Math.max(a[i+1],a[l+1]),a[i+2]=Math.min(a[i+2],a[l+2]),a[i+3]=Math.min(a[i+3],a[l+3]),t=this.stack[--this.sp]}if(t===Ur)hr(e)&&(this.skipped+=e.length);else if(t===Cn){let n=--this.real,o=hr(e)?e:null,a=this.popLayer();if(this.area(n,o?no(o,this.maxBlur):0)){this.composite(a,!1,r,o);let i=this.scale;this.grow(this.rx0/i,this.ry0/i,this.rx1/i,this.ry1/i)}}}closeLayers(){for(;this.sp;)this.endLayer(1)}};var vi=256,bo=8<<20,Me=new Float64Array(32),Te={x:0,y:0,w:0,h:0};function wi(s){if(typeof s.filter!="string")return!1;s.filter="blur(1px)";let r=s.filter==="blur(1px)";return s.filter="none",r}function $t(s){let r=s.getContext("2d",{alpha:!0});return r?new _n(s,r):null}var _n=class extends Gt{constructor(e,t){super();p(this,"canvas",e);p(this,"ctx",t);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:wi(t),shaders:!1},this.base=this.top={ctx:t,clipped:!1,ver:0},e.addEventListener("contextlost",()=>{this.lost=!0,this.lostListeners.forEach(n=>n())}),e.addEventListener("contextrestored",()=>{this.lost=!1,this.tinted.clear(),this.tintedN=0,this.dropNines(),this.restoredListeners.forEach(n=>n())})}resize(e,t){this.canvas.width!==e&&(this.canvas.width=e),this.canvas.height!==t&&(this.canvas.height=t)}createTexture(e){return{id:pr(),width:e.width,height:e.height,source:e}}updateTexture(e,t,n=0,o=0){let a=t?n+t.width:1/0,i=t?o+t.height:1/0;for(let l of this.nines.values()){let c=l.key;c[0]===e.id&&c[1]<a&&c[1]+c[3]>n&&c[2]<i&&c[2]+c[4]>o&&this.dropNine(l)}for(let[l,c]of this.tinted){let u=c.filter(f=>f.id!==e.id);this.tintedN-=c.length-u.length,u.length?this.tinted.set(l,u):this.tinted.delete(l)}}destroyTexture(e){this.updateTexture(e)}begin(e,t,n){this.resetLayers(n),this.fxr?.tick(),this.frame++,this.quads=0,this.top=this.base,this.ctx=this.base.ctx;let o=this.ctx;this.base.clipped&&o.restore(),this.base.clipped=!1,this.base.ver=this.clipVer,o.setTransform(1,0,0,1,0,0),o.globalAlpha=1,o.globalCompositeOperation="source-over",o.clearRect(0,0,this.canvas.width,this.canvas.height),t>0&&(o.fillStyle=xt(e,t),o.fillRect(0,0,this.canvas.width,this.canvas.height))}quad(e,t,n,o,a,i,l,c){Y[0]=o,Y[1]=a,Y[2]=l,this.quadQ(e,t,n,i,c)}quadQ(e,t,n,o,a){t.w<=0||t.h<=0||(o===16777215?this.blit(e.source,t.x,t.y,t.w,t.h,n,a):this.blit(this.tint(e,t,o),0,0,t.w,t.h,n,a))}blit(e,t,n,o,a,i,l){let c=Y[0],u=Y[1],f=Y[2];if(f<=0||this.mute)return;this.sync();let h=this.ctx,b=this.scale;if(this.real){let y=i[0]*c,m=i[1]*c,d=i[2]*u,x=i[3]*u;this.grow(i[4]+Math.min(0,y,d,y+d),i[5]+Math.min(0,m,x,m+x),i[4]+Math.max(0,y,d,y+d),i[5]+Math.max(0,m,x,m+x))}h.setTransform(i[0]*b,i[1]*b,i[2]*b,i[3]*b,i[4]*b,i[5]*b),h.globalAlpha=Math.min(f,1),l==="add"&&(h.globalCompositeOperation="lighter"),h.drawImage(e,t,n,o,a,0,0,c,u),l==="add"&&(h.globalCompositeOperation="source-over"),this.quads++}nineQ(e,t,n,o,a,i,l){var m,d;let c=n[8]+n[9],u=o[8]+o[9],f=Math.ceil(c*Math.hypot(a[0],a[1])*this.scale-1e-6),h=Math.ceil(u*Math.hypot(a[2],a[3])*this.scale-1e-6);if(a[1]===0&&a[2]===0||f>4096||h>4096)return!1;if(!(f>0&&h>0&&Y[2]>0)||this.mute)return!0;let b=this.kept(e,t,n,o,f,h,i),y=(b??(b=(m=this.scratch)[d=13*Math.ceil(Math.log2(f))+Math.ceil(Math.log2(h))]??(m[d]=document.createElement("canvas").getContext("2d")))).canvas;if(y.width<f&&(y.width=f),y.height<h&&(y.height=h),!this.hit){b.clearRect(0,0,f+2,h+2);for(let x=0;x<12;x+=4){let g=Math.round(o[x]*h/u),M=Math.round((o[x]+o[x+1])*h/u);for(let v=0;v<12;v+=4){let A=Math.round(n[v]*f/c),E=Math.round((n[v]+n[v+1])*f/c);Te.x=t.x+n[v+2],Te.y=t.y+o[x+2],Te.w=n[v+3],Te.h=o[x+3],!(E<=A||M<=g||Te.w<=0||Te.h<=0)&&(i===16777215?b.drawImage(e.source,Te.x,Te.y,Te.w,Te.h,A,g,E-A,M-g):b.drawImage(this.tint(e,Te,i),0,0,Te.w,Te.h,A,g,E-A,M-g))}}}return Y[0]=c,Y[1]=u,this.blit(y,0,0,f,h,a,l),!0}kept(e,t,n,o,a,i,l){Me[0]=e.id,Me[1]=t.x,Me[2]=t.y,Me[3]=t.w,Me[4]=t.h,Me[5]=a,Me[6]=i,Me[7]=l,Me.set(n,8),Me.set(o,20);let c=De(Me),u=this.nines.get(c);if(this.hit=!1,u)return Ut(u.key,Me)?(u.used=this.frame,this.hit=!0,u.ctx):null;let f=this.missed,h=f.get(c);f.size>4096&&f.clear(),f.set(c,this.frame);let b=a*i;if(h!==this.frame-1||b>bo)return null;let y;for(;this.ninePx+b>bo;){let x;for(let v of this.nines.values())v.used<this.frame-1&&!(x&&x.used<=v.used)&&(x=v);if(!x)return null;let g=x.ctx.canvas,M=!y&&g.width>=a&&g.height>=i&&g.width*g.height<=2*b;this.dropNine(x,M),M&&(y=x.ctx)}let m=y??document.createElement("canvas").getContext("2d"),d=m.canvas;return y||(d.width=a,d.height=i),this.ninePx+=d.width*d.height,this.nines.set(c,{key:xr(Me),ctx:m,used:this.frame}),m}dropNine(e,t=!1){this.nines.delete(De(e.key));let n=e.ctx.canvas;this.ninePx-=n.width*n.height,t||(n.width=0)}dropNines(){for(let e of this.nines.values())this.dropNine(e)}tint(e,t,n){let o=Ze(n,Ze(t.h,Ze(t.w,Ze(t.y,Ze(t.x,Ze(e.id)))))),a=this.tinted.get(o);if(a)for(let c=0;c<a.length;c++){let u=a[c];if(u.id===e.id&&u.x===t.x&&u.y===t.y&&u.w===t.w&&u.h===t.h&&u.color===n)return u.canvas}this.tintedN>=vi&&(this.tinted.clear(),this.tintedN=0,a=void 0);let i=document.createElement("canvas");i.width=Math.ceil(t.w),i.height=Math.ceil(t.h);let l=i.getContext("2d");return l.drawImage(e.source,t.x,t.y,t.w,t.h,0,0,t.w,t.h),l.globalCompositeOperation="multiply",l.fillStyle=xt(n),l.fillRect(0,0,t.w,t.h),l.globalCompositeOperation="destination-in",l.drawImage(e.source,t.x,t.y,t.w,t.h,0,0,t.w,t.h),a||this.tinted.set(o,a=[]),a.push({id:e.id,x:t.x,y:t.y,w:t.w,h:t.h,color:n,canvas:i}),this.tintedN++,i}paint(e,t){this.sync();let n=this.ctx,o=this.scale;return n.setTransform(o,0,0,o,0,0),n.globalAlpha=Math.min(t,1),xt(e)}ellipse(e,t,n,o,a,i,l){if(l<=0||n<=0||o<=0||this.mute)return;let c=Math.max(n,o);this.grow(e-c,t-c,e+c,t+c);let u=this.ctx;u.fillStyle=this.paint(i,l),u.beginPath(),u.ellipse(e,t,n,o,a,0,Math.PI*2),u.fill(),this.quads++}trace(e,t,n=0){if(this.real)for(let a=0;a<t;a++)this.grow(e[a*2]-n,e[a*2+1]-n,e[a*2]+n,e[a*2+1]+n);let o=this.ctx;o.beginPath(),o.moveTo(e[0],e[1]);for(let a=1;a<t;a++)o.lineTo(e[a*2],e[a*2+1])}polygon(e,t,n,o){if(o<=0||t<3||this.mute)return;let a=this.ctx;a.fillStyle=this.paint(n,o),this.trace(e,t),a.closePath(),a.fill(),this.quads++}stroke(e,t,n,o,a,i){if(a<=0||n<=0||t<1||this.mute)return;let l=this.ctx;l.strokeStyle=this.paint(o,a),l.lineWidth=n,l.lineCap="round",l.lineJoin="round",this.trace(e,t,n/2),t===1&&l.lineTo(e[0],e[1]),i&&l.closePath(),l.stroke(),this.quads++}sync(){let e=this.top;if(e.ver===this.clipVer)return;let t=e.ctx;e.clipped&&t.restore(),e.clipped=this.cOn,e.ver=this.clipVer,this.cOn&&(t.save(),t.setTransform(1,0,0,1,0,0),t.beginPath(),t.rect(this.px0,this.py0,this.px1-this.px0,this.py1-this.py0),t.clip())}pushLayer(){let e=this.canvas.width,t=this.canvas.height,n=this.layers[this.real];if(!n||n.ctx.canvas.width!==e||n.ctx.canvas.height!==t){let a=document.createElement("canvas");a.width=e,a.height=t;let i=a.getContext("2d");if(!i)return!1;n=this.layers[this.real]={ctx:i,clipped:!1,ver:-1}}let o=n.ctx;return n.clipped&&o.restore(),n.clipped=!1,n.ver=-1,o.setTransform(1,0,0,1,0,0),o.globalAlpha=1,o.globalCompositeOperation="source-over",o.clearRect(0,0,e,t),this.top=n,this.ctx=o,!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(e,t,n,o){let a=e,i="none",l=o&&Ae.c2d?this.fxr??(this.fxr=Ae.c2d(this)):null;l&&(a=l.chain(e,o),i=l.css),this.sync();let c=this.ctx,u=this.rx0,f=this.ry0,h=this.rx1-u,b=this.ry1-f;c.setTransform(1,0,0,1,0,0),c.globalAlpha=Math.min(n,1),c.globalCompositeOperation=t?"destination-in":"source-over",i!=="none"&&(c.filter=i),c.drawImage(a,u,f,h,b,u,f,h,b),i!=="none"&&(c.filter="none"),c.globalCompositeOperation="source-over",this.quads++}end(){this.closeLayers();let e=this.stats;return e.drawCalls=e.quads=this.quads,e.filtersSkipped=this.skipped,e}onLost(e){this.lostListeners.push(e)}onRestored(e){this.restoredListeners.push(e)}destroy(){this.tinted.clear(),this.dropNines(),this.layers=[],this.scratch=[],this.fxr?.destroy(),this.fxr=null}};var Hr=class{constructor(r,e,t=8192){p(this,"instanced",r);p(this,"slots",e);p(this,"capacity",t);p(this,"f32");p(this,"u32");p(this,"quads",0);p(this,"textures");p(this,"bound",0);this.textures=new Array(e).fill(null);let n=t*(r?14:24),o=new ArrayBuffer(n*4);this.f32=new Float32Array(o),this.u32=new Uint32Array(o)}slot(r){let e=this.textures;for(let t=0;t<this.bound;t++)if(e[t]===r)return t;return this.bound>=this.slots?-1:(e[this.bound]=r,this.bound++)}has(r){for(let e=0;e<this.bound;e++)if(this.textures[e]===r)return!0;return!1}get full(){return this.quads>=this.capacity}get words(){return this.quads*(this.instanced?14:24)}reset(){this.quads=0;for(let r=0;r<this.bound;r++)this.textures[r]=null;this.bound=0}push(r,e,t,n,o,a,i,l,c,u,f,h,b,y){let m=this.f32;if(this.instanced){let d=this.quads*14;m[d++]=r,m[d++]=e,m[d++]=t,m[d++]=n,m[d++]=o,m[d++]=a,m[d++]=i,m[d++]=l,m[d++]=c,m[d++]=u,m[d++]=f,m[d++]=h,this.u32[d++]=b,m[d]=y}else{let d=this.quads*6*4;this.vertex(d,r,e,c,u,b,y),this.vertex(d+6,t,n,f,u,b,y),this.vertex(d+12,o,a,f,h,b,y),this.vertex(d+18,i,l,c,h,b,y)}this.quads++}pushQ(r,e){let t=this.f32;if(this.instanced){let n=this.quads*14;for(let o=0;o<12;o++)t[n+o]=r[o];this.u32[n+12]=r[12],t[n+13]=e}else{let n=this.quads*6*4,o=r[12];for(let a=0;a<4;a++,n+=6)t[n]=r[a*2],t[n+1]=r[a*2+1],t[n+2]=a===1||a===2?r[10]:r[8],t[n+3]=a>=2?r[11]:r[9],this.u32[n+4]=o,t[n+5]=e}this.quads++}vertex(r,e,t,n,o,a,i){let l=this.f32;l[r]=e,l[r+1]=t,l[r+2]=n,l[r+3]=o,this.u32[r+4]=a,l[r+5]=i}};function yo(s){let r=new Uint16Array(s*6);for(let e=0,t=0,n=0;e<s;e++,t+=6,n+=4)r[t]=n,r[t+1]=n+1,r[t+2]=n+2,r[t+3]=n,r[t+4]=n+2,r[t+5]=n+3;return r}var ye={M:0,L:1,Q:2,C:3,Z:4},Mo=[2,2,4,6,0],Ai={M:0,L:1,Q:2,C:3,Z:4};function qr(s,r){if(s.length>=r)return s;let e=new Float64Array(Math.max(r,s.length*2,16));return e.set(s),e}var Gr=new Map;function Si(s){if(typeof s!="string")return s;let r=Gr.get(s);if(r)return r;r=[];let e=s.match(/[MLQCZ]|-?\d*\.?\d+(?:e-?\d+)?/gi)??[],t=-1;for(let n=0;n<e.length;){let o=e[n],a=Ai[o.toUpperCase()];if(a!==void 0){t=a,n++,a===ye.Z&&r.push(ye.Z);continue}if(t<0||t===ye.Z){n++;continue}let i=Mo[t];r.push(t);for(let l=0;l<i;l++)r.push(Number(e[n+l]??0));n+=i,t===ye.M&&(t=ye.L)}return Gr.size>256&&Gr.clear(),Gr.set(s,r),r}var lt={subs:[],count:0},Ln=null,it=null;function $r(s,r){let e=it;e||(e=lt.subs[lt.count]??null,e||lt.subs.push(e={pts:new Float64Array(64),n:0,closed:!1}),e.n=0,e.closed=!1,lt.count++,it=e);let t=e.n*2;t+2>e.pts.length&&(e.pts=qr(e.pts,t+2));let n=Ln;n?(e.pts[t]=n[0]*s+n[2]*r+n[4],e.pts[t+1]=n[1]*s+n[3]*r+n[5]):(e.pts[t]=s,e.pts[t+1]=r),e.n++}function Yr(s,r=null,e=1,t=6){let n=Si(s);lt.count=0,it=null,Ln=r;let o=0,a=0,i=0,l=0,c=e/t;for(let u=0;u<n.length;){let f=n[u++],h=n;if(f===ye.M)it=null,o=i=h[u],a=l=h[u+1],$r(o,a);else if(f===ye.L)o=h[u],a=h[u+1],$r(o,a);else if(f===ye.Q){let b=h[u],y=h[u+1],m=h[u+2],d=h[u+3],x=xo((Ge(b-o,y-a)+Ge(m-b,d-y))*c);for(let g=1;g<=x;g++){let M=g/x,v=1-M;$r(v*v*o+2*v*M*b+M*M*m,v*v*a+2*v*M*y+M*M*d)}o=m,a=d}else if(f===ye.C){let b=h[u],y=h[u+1],m=h[u+2],d=h[u+3],x=h[u+4],g=h[u+5],M=xo((Ge(b-o,y-a)+Ge(m-b,d-y)+Ge(x-m,g-d))*c);for(let v=1;v<=M;v++){let A=v/M,E=1-A,C=E*E*E,_=3*E*E*A,L=3*E*A*A,I=A*A*A;$r(C*o+_*b+L*m+I*x,C*a+_*y+L*d+I*g)}o=x,a=g}else if(f===ye.Z){it&&(it.closed=!0),it=null,o=i,a=l;continue}else break;u+=Mo[f]}it=null,Ln=null;for(let u=0;u<lt.count;u++){let f=lt.subs[u],h=f.n*2;f.closed&&f.n>=2&&Math.abs(f.pts[0]-f.pts[h-2])<1e-6&&Math.abs(f.pts[1]-f.pts[h-1])<1e-6&&f.n--}return lt}var Ge=(s,r)=>Math.sqrt(s*s+r*r),xo=s=>Math.min(Math.max(Math.ceil(s),2),24);function Mi(s,r){let e=0;for(let t=0,n=r-1;t<r;n=t++)e+=(s[n*2]-s[t*2])*(s[n*2+1]+s[t*2+1]);return e}var Wr=new Int32Array(64),Vr=(s,r,e,t,n)=>((s[t*2]-s[e*2])*(s[n*2+1]-s[e*2+1])-(s[t*2+1]-s[e*2+1])*(s[n*2]-s[e*2]))*r;function To(s,r,e){if(r<3)return 0;Wr.length<r&&(Wr=new Int32Array(Math.max(r,Wr.length*2)));let t=Wr,n=r,o=0;for(let c=0;c<r;c++)t[c]=c;let a=Mi(s,r)>0?1:-1,i=r*r+8,l=0;for(;n>3&&i-- >0;){let c=t[(l+n-1)%n],u=t[l%n],f=t[(l+1)%n],h=Vr(s,a,c,u,f)>0;if(h)for(let b=0;b<n;b++){let y=t[b];if(!(y===c||y===u||y===f)&&Vr(s,a,c,u,y)>=0&&Vr(s,a,u,f,y)>=0&&Vr(s,a,f,c,y)>=0){h=!1;break}}h?(e[o++]=c,e[o++]=u,e[o++]=f,t.copyWithin(l%n,l%n+1,n),n--,l=Math.max(l-1,0)):l=(l+1)%n}if(n===3)e[o++]=t[0],e[o++]=t[1],e[o++]=t[2];else if(n>3)for(let c=1;c+1<n;c++)e[o++]=t[0],e[o++]=t[c],e[o++]=t[c+1];return o}var Ti=.85,Xr=new Float64Array(64),go=new Float64Array(64),ko=new Float64Array(64),vo=new Float64Array(64),wo=new Float64Array(64),Ao=new Float64Array(64),So=new Uint8Array(64),gr=new Float64Array(8);function Eo(s,r,e,t,n,o){let a=gr;if(Xr.length<r){let d=Math.max(r,Xr.length*2);Xr=new Float64Array(d),go=new Float64Array(d),ko=new Float64Array(d),vo=new Float64Array(d),wo=new Float64Array(d),Ao=new Float64Array(d),So=new Uint8Array(d)}let i=Xr,l=go,c=0;for(let d=0;d<r;d++){let x=s[d*2],g=s[d*2+1];!Number.isFinite(x)||!Number.isFinite(g)||c&&Math.abs(i[c-1]-x)<.001&&Math.abs(l[c-1]-g)<.001||(i[c]=x,l[c]=g,c++)}if(t&&c>2&&Math.abs(i[0]-i[c-1])<.001&&Math.abs(l[0]-l[c-1])<.001&&c--,c===0)return;if(c===1)return a[0]=i[0],a[1]=l[0],o();let u=t?c:c-1,f=ko,h=vo;for(let d=0;d<u;d++){let x=(d+1)%c,g=i[x]-i[d],M=l[x]-l[d],v=Ge(g,M)||1;f[d]=-M/v,h[d]=g/v}let b=wo,y=Ao,m=So;for(let d=0;d<c;d++){let x=t?(d-1+u)%u:d-1,g=d<u?d:-1;if(m[d]=1,x<0||g<0||f[x]*f[g]+h[x]*h[g]<Ti)continue;let v=f[x]+f[g],A=h[x]+h[g],E=Ge(v,A)||1;v/=E,A/=E;let C=e/Math.max(v*f[g]+A*h[g],.5);b[d]=v*C,y[d]=A*C,m[d]=0}for(let d=0;d<u;d++){let x=(d+1)%c,g=m[d]?f[d]*e:b[d],M=m[d]?h[d]*e:y[d],v=m[x]?f[d]*e:b[x],A=m[x]?h[d]*e:y[x];a[0]=i[d]+g,a[1]=l[d]+M,a[2]=i[x]+v,a[3]=l[x]+A,a[4]=i[x]-v,a[5]=l[x]-A,a[6]=i[d]-g,a[7]=l[d]-M,n()}for(let d=0;d<c;d++)m[d]&&(a[0]=i[d],a[1]=l[d],o())}function Nn(s,r){let e=0,t=1/0;for(let n=0;n<r.length;n++){let o=Math.abs(Math.log(Math.max(s,.5)/r[n]));o<t&&(t=o,e=n)}return e}var Kr=[{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}],jr=[4,8,16,32,64,128].map((s,r)=>({x:r*4,y:128,w:4,h:s,r:s/2-1})),Je={x:248,y:248,w:8,h:8},Fo=Kr.map(s=>s.r*2),Co=jr.map(s=>s.r*2),Ro=(s,r)=>Math.min(Math.max(s+.5-r,0),1);function Ei(){let s=new Uint8ClampedArray(262144),r=(e,t,n)=>{let o=(t*256+e)*4;s[o]=s[o+1]=s[o+2]=255,s[o+3]=Math.round(n*255)};for(let e of Kr){let t=e.w/2;for(let n=0;n<e.h;n++)for(let o=0;o<e.w;o++)r(e.x+o,e.y+n,Ro(e.r,Math.hypot(o+.5-t,n+.5-t)))}for(let e of jr){let t=e.h/2;for(let n=0;n<e.h;n++)for(let o=0;o<e.w;o++)r(e.x+o,e.y+n,Ro(e.r,Math.abs(n+.5-t)))}for(let e=0;e<Je.h;e++)for(let t=0;t<Je.w;t++)r(Je.x+t,Je.y+e,1);return s}function Po(){let s=document.createElement("canvas");return s.width=s.height=256,s.getContext("2d").putImageData(new ImageData(Ei(),256,256),0,0),s}var _o=8,Qr=`
2
+ #ifdef GL_FRAGMENT_PRECISION_HIGH
3
+ precision highp float;
4
+ #else
5
+ precision mediump float;
6
+ #endif
7
+ `,Pi=s=>`${Qr}
8
+ uniform sampler2D uTex[${s}];
9
+ varying vec2 vUv;
10
+ varying vec4 vColor;
11
+ varying float vSlot;
12
+ void main() {
13
+ vec4 c;
14
+ ${Array.from({length:s},(r,e)=>e===s-1?`c = texture2D(uTex[${e}], vUv);`:`if (vSlot < ${e}.5) c = texture2D(uTex[${e}], vUv); else `).join(`
15
+ `)}
16
+ gl_FragColor = c * vColor;
17
+ }`,_i=`
18
+ attribute vec2 aPos;
19
+ attribute vec2 aUv;
20
+ attribute vec4 aColor;
21
+ attribute float aSlot;
22
+ uniform vec2 uScale;
23
+ varying vec2 vUv;
24
+ varying vec4 vColor;
25
+ varying float vSlot;
26
+ void main() {
27
+ vUv = aUv;
28
+ vColor = aColor;
29
+ vSlot = aSlot;
30
+ gl_Position = vec4(aPos * uScale + vec2(-1.0, 1.0), 0.0, 1.0);
31
+ }`,Li=`
32
+ attribute vec4 aCorner;
33
+ attribute vec4 aP01;
34
+ attribute vec4 aP23;
35
+ attribute vec4 aUvRect;
36
+ attribute vec4 aColor;
37
+ attribute float aSlot;
38
+ uniform vec2 uScale;
39
+ varying vec2 vUv;
40
+ varying vec4 vColor;
41
+ varying float vSlot;
42
+ void main() {
43
+ vec2 p = aP01.xy * aCorner.x + aP01.zw * aCorner.y + aP23.xy * aCorner.z + aP23.zw * aCorner.w;
44
+ vUv = vec2(mix(aUvRect.x, aUvRect.z, aCorner.y + aCorner.z), mix(aUvRect.y, aUvRect.w, aCorner.z + aCorner.w));
45
+ vColor = aColor;
46
+ vSlot = aSlot;
47
+ gl_Position = vec4(p * uScale + vec2(-1.0, 1.0), 0.0, 1.0);
48
+ }`,Ni={alpha:!0,premultipliedAlpha:!0,antialias:!1,depth:!1,stencil:!1,preserveDrawingBuffer:!1,powerPreference:"high-performance"},Bi=["aCorner","aP01","aP23","aUvRect","aColor","aSlot"],Di=["aPos","aUv","aColor","aSlot"];function No(s,r,e={}){let t={...Ni,failIfMajorPerformanceCaveat:e.failIfMajorPerformanceCaveat!==!1},n=r===2?s.getContext("webgl2",t):s.getContext("webgl",t)??s.getContext("experimental-webgl",t);if(!n||n.isContextLost())return null;try{return new Bn(s,n,r,e)}catch(o){return console.warn("[engine] WebGL setup failed:",o),n.getExtension("WEBGL_lose_context")?.loseContext(),null}}var Bn=class extends Gt{constructor(e,t,n,o){super();p(this,"canvas",e);p(this,"gl",t);p(this,"opts",o);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(_o).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",()=>{let e=this.q;e.set(gr),e[8]=e[10]=this.sU,e[9]=this.sV0,e[11]=this.sV1,e[12]=this.sPacked,this.put(this.kit)});p(this,"strokeDisc",()=>this.ellipse(gr[0],gr[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",e=>{e.preventDefault(),this.lost=!0;for(let t of this.lostListeners)t()});p(this,"onContextRestored",()=>{try{this.layers=[],this.layerTex.clear(),this.fxr=null,this.resetLayers(this.scale),this.setup();for(let e of this.textures.keys())this.textures.set(e,this.upload(e.source));this.lost=!1;for(let e of this.restoredListeners)e()}catch(e){console.warn("[engine] WebGL restore failed:",e)}});p(this,"views",new Map);this.kind=n===2?"webgl2":"webgl1",this.maxTextureSize=t.getParameter(t.MAX_TEXTURE_SIZE),this.setup(),this.kit=this.createTexture(Po()),Ae.live=this,e.addEventListener("webglcontextlost",this.onContextLost,!1),e.addEventListener("webglcontextrestored",this.onContextRestored,!1)}setup(){let e=this.gl,t=this.kind==="webgl2"?e:null;if(this.inst=null,this.opts.instancing!==!1)if(t)this.inst={divisor:(f,h)=>t.vertexAttribDivisor(f,h),draw:(f,h)=>t.drawElementsInstanced(e.TRIANGLES,f,e.UNSIGNED_SHORT,0,h)};else{let f=e.getExtension("ANGLE_instanced_arrays");f&&(this.inst={divisor:(h,b)=>f.vertexAttribDivisorANGLE(h,b),draw:(h,b)=>f.drawElementsInstancedANGLE(e.TRIANGLES,h,e.UNSIGNED_SHORT,0,b)})}if(this.vaoApi=null,this.opts.vao!==!1)if(t)this.vaoApi={create:()=>t.createVertexArray(),bind:f=>t.bindVertexArray(f),remove:f=>t.deleteVertexArray(f)};else{let f=e.getExtension("OES_vertex_array_object");f&&(this.vaoApi={create:()=>f.createVertexArrayOES(),bind:h=>f.bindVertexArrayOES(h),remove:h=>f.deleteVertexArrayOES(h)})}let n=e.getParameter(e.MAX_TEXTURE_IMAGE_UNITS),o=Math.max(1,Math.min(_o,n)),a=this.inst!==null;this.vsrc=a?Li:_i,this.attrs=a?Bi:Di,this.main=this.cur=this.build(Pi(o));let i=this.main.p;e.useProgram(i),this.calls.useProgram++,this.unit=-1,this.onUnit.fill(void 0),this.fbNow=void 0,this.uScale=this.main.uScale,e.uniform1iv(e.getUniformLocation(i,"uTex"),Int32Array.from({length:o},(f,h)=>h)),this.batch=new Hr(a,o),this.vaoApi&&(this.vao=this.vaoApi.create(),this.vaoApi.bind(this.vao)),this.dynamic=e.createBuffer(),e.bindBuffer(e.ARRAY_BUFFER,this.dynamic),e.bufferData(e.ARRAY_BUFFER,this.batch.f32.byteLength,e.DYNAMIC_DRAW),this.index=e.createBuffer(),e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,this.index),e.bufferData(e.ELEMENT_ARRAY_BUFFER,yo(a?1:8192),e.STATIC_DRAW);let l=f=>e.getAttribLocation(i,f),c=(f,h,b,y,m,d,x)=>{let g=l(f);g<0||(e.enableVertexAttribArray(g),e.vertexAttribPointer(g,h,b,y,m,d),this.inst&&this.inst.divisor(g,x))};if(a){let f=56;c("aP01",4,e.FLOAT,!1,f,0,1),c("aP23",4,e.FLOAT,!1,f,16,1),c("aUvRect",4,e.FLOAT,!1,f,32,1),c("aColor",4,e.UNSIGNED_BYTE,!0,f,48,1),c("aSlot",1,e.FLOAT,!1,f,52,1),this.staticBuf=e.createBuffer(),e.bindBuffer(e.ARRAY_BUFFER,this.staticBuf),e.bufferData(e.ARRAY_BUFFER,Float32Array.of(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1),e.STATIC_DRAW),c("aCorner",4,e.FLOAT,!1,16,0,0),e.bindBuffer(e.ARRAY_BUFFER,this.dynamic)}else{let f=24;c("aPos",2,e.FLOAT,!1,f,0,0),c("aUv",2,e.FLOAT,!1,f,8,0),c("aColor",4,e.UNSIGNED_BYTE,!0,f,16,0),c("aSlot",1,e.FLOAT,!1,f,20,0)}e.enable(e.BLEND),e.blendFunc(e.ONE,e.ONE_MINUS_SRC_ALPHA),e.disable(e.DEPTH_TEST),e.disable(e.CULL_FACE),e.pixelStorei(e.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!0);let u=e.getExtension("WEBGL_debug_renderer_info");this.info={version:e.getParameter(e.VERSION),renderer:u?e.getParameter(u.UNMASKED_RENDERER_WEBGL):e.getParameter(e.RENDERER),vendor:u?e.getParameter(u.UNMASKED_VENDOR_WEBGL):e.getParameter(e.VENDOR)},this.features={instancing:a,vao:this.vaoApi!==null,textureSlots:o,maxTextureSize:this.maxTextureSize}}upload(e){let t=this.gl,n=t.createTexture();return this.bindTex(n),t.texImage2D(t.TEXTURE_2D,0,t.RGBA,t.RGBA,t.UNSIGNED_BYTE,e),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.LINEAR),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.LINEAR),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE),n}resize(e,t){this.canvas.width!==e&&(this.canvas.width=e),this.canvas.height!==t&&(this.canvas.height=t)}createTexture(e){let t={id:pr(),width:e.width,height:e.height,source:e};return this.textures.set(t,this.lost?null:this.upload(e)),t}updateTexture(e,t,n=0,o=0){if(this.lost)return;this.batch.has(e)&&this.flush();let a=this.gl,i=this.textures.get(e);i&&(this.bindTex(i),!t||t===e.source&&n===0&&o===0?a.texImage2D(a.TEXTURE_2D,0,a.RGBA,a.RGBA,a.UNSIGNED_BYTE,e.source):a.texSubImage2D(a.TEXTURE_2D,0,n,o,a.RGBA,a.UNSIGNED_BYTE,t))}destroyTexture(e){this.batch.has(e)&&this.flush();let t=this.textures.get(e);t&&!this.lost&&this.deleteTex(t),this.textures.delete(e)}begin(e,t,n){if(this.stats.drawCalls=this.stats.quads=this.stats.filtersSkipped=0,this.batch.reset(),this.resetLayers(n),this.bScis=!1,this.lost)return;let o=this.gl;o.disable(o.SCISSOR_TEST),this.bindFb(null),o.viewport(0,0,this.canvas.width,this.canvas.height);let a=t;o.clearColor((e>>16&255)/255*a,(e>>8&255)/255*a,(e&255)/255*a,a),o.clear(o.COLOR_BUFFER_BIT),this.use(this.main),o.uniform2f(this.uScale,2*n/this.canvas.width,-2*n/this.canvas.height),this.mapped=!0}build(e){let t=this.gl,n=Lo(t,t.VERTEX_SHADER,this.vsrc),o;try{o=Lo(t,t.FRAGMENT_SHADER,e)}catch(i){throw t.deleteShader(n),i}let a=t.createProgram();if(t.attachShader(a,n),t.attachShader(a,o),this.attrs.forEach((i,l)=>t.bindAttribLocation(a,l,i)),t.linkProgram(a),t.deleteShader(n),t.deleteShader(o),!t.getProgramParameter(a,t.LINK_STATUS)){let i=t.getProgramInfoLog(a)??"?";throw t.deleteProgram(a),new Error(`link: ${i}`)}return{p:a,uScale:t.getUniformLocation(a,"uScale"),locs:new Map}}u(e,t){let n=e.locs.get(t);return n===void 0&&e.locs.set(t,n=this.gl.getUniformLocation(e.p,t)),n}use(e){this.cur!==e&&(this.cur=e,this.gl.useProgram(e.p),this.calls.useProgram++)}bindTex(e,t=this.unit<0?0:this.unit){let n=this.gl;this.onUnit[t]!==e&&(this.unit!==t&&(n.activeTexture(n.TEXTURE0+t),this.calls.activeTexture++,this.unit=t),n.bindTexture(n.TEXTURE_2D,e),this.calls.bindTexture++,this.onUnit[t]=e)}deleteTex(e){this.gl.deleteTexture(e);for(let t=0;t<this.onUnit.length;t++)this.onUnit[t]===e&&(this.onUnit[t]=null)}bindFb(e){if(e)for(let n=0;n<this.onUnit.length;n++)this.onUnit[n]===e.gl&&this.bindTex(null,n);let t=e?e.fb:null;this.fbNow!==t&&(this.gl.bindFramebuffer(this.gl.FRAMEBUFFER,t),this.calls.bindFramebuffer++,this.fbNow=t)}slotOf(e){this.batch.full&&this.flush();let t=this.batch.slot(e);return t<0&&(this.flush(),t=this.batch.slot(e)),t}quad(e,t,n,o,a,i,l,c){Y[0]=o,Y[1]=a,Y[2]=l,this.quadQ(e,t,n,i,c)}quadQ(e,t,n,o,a){let i=Y[2];if(this.lost||i<=0)return;let l=this.q,c=Y[0],u=Y[1],f=n[4],h=n[5],b=n[0]*c,y=n[1]*c,m=n[2]*u,d=n[3]*u;l[0]=f,l[1]=h,l[2]=b+f,l[3]=y+h,l[4]=b+m+f,l[5]=y+d+h,l[6]=m+f,l[7]=d+h;let x=1/e.width,g=1/e.height;l[8]=t.x*x,l[9]=t.y*g,l[10]=(t.x+t.w)*x,l[11]=(t.y+t.h)*g,l[12]=nt(o,i,a==="add"),this.put(e)}put(e){if(this.mute)return;let t=this.q,n=!1,o=Math.min(t[0],t[2],t[4],t[6]),a=Math.max(t[0],t[2],t[4],t[6]),i=Math.min(t[1],t[3],t[5],t[7]),l=Math.max(t[1],t[3],t[5],t[7]);if(this.cOn){if(this.px1<=this.px0||this.py1<=this.py0)return;let u=this.scale,f=this.px0/u,h=this.py0/u,b=this.px1/u,y=this.py1/u;if(a<=f||o>=b||l<=h||i>=y)return;if(o<f||a>b||i<h||l>y){let m=t[0],d=t[1],x=t[2],g=t[5];if(d===t[3]&&x===t[4]&&g===t[7]&&t[6]===m){if(m!==x){let M=Math.min(Math.max(m,f),b),v=Math.min(Math.max(x,f),b),A=t[8],E=(t[10]-A)/(x-m);t[10]=A+(v-m)*E,t[8]=A+(M-m)*E,t[0]=t[6]=M,t[2]=t[4]=v}if(d!==g){let M=Math.min(Math.max(d,h),y),v=Math.min(Math.max(g,h),y),A=t[9],E=(t[11]-A)/(g-d);t[11]=A+(v-d)*E,t[9]=A+(M-d)*E,t[1]=t[3]=M,t[5]=t[7]=v}}else n=!0}}let c=this.bx0===this.px0&&this.by0===this.py0&&this.bx1===this.px1&&this.by1===this.py1;if(n?(!this.bScis||!c)&&(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&&c)&&(this.flush(),this.bScis=!1),this.real){let u=this.gq;u[0]=o,u[1]=i,u[2]=a,u[3]=l,this.growQ()}this.batch.pushQ(t,this.slotOf(e))}ellipse(e,t,n,o,a,i,l){if(this.lost||l<=0||n<=0||o<=0)return;let c=Kr[Nn(Math.max(n,o)*2*this.scale,Fo)],u=c.w/2/c.r,f=n*u,h=o*u,b=Math.cos(a),y=Math.sin(a),m=b*f,d=y*f,x=-y*h,g=b*h,M=1/256,v=this.q;v[0]=e-m-x,v[1]=t-d-g,v[2]=e+m-x,v[3]=t+d-g,v[4]=e+m+x,v[5]=t+d+g,v[6]=e-m+x,v[7]=t-d+g,v[8]=c.x*M,v[9]=c.y*M,v[10]=(c.x+c.w)*M,v[11]=(c.y+c.h)*M,v[12]=nt(i,l),this.put(this.kit)}polygon(e,t,n,o){if(this.lost||o<=0||t<3)return;this.tris.length<t*3&&(this.tris=new Int32Array(Math.max(t*3,this.tris.length*2)));let a=this.tris,i=To(e,t,a),l=nt(n,o),c=(Je.x+Je.w/2)/256,u=(Je.y+Je.h/2)/256;for(let f=0;f<i;f+=3){let h=a[f]*2,b=a[f+1]*2,y=a[f+2]*2,m=this.q;m[0]=e[h],m[1]=e[h+1],m[2]=e[b],m[3]=e[b+1],m[4]=m[6]=e[y],m[5]=m[7]=e[y+1],m[8]=m[10]=c,m[9]=m[11]=u,m[12]=l,this.put(this.kit)}}stroke(e,t,n,o,a,i){if(this.lost||a<=0||n<=0||t<1)return;let l=jr[Nn(n*this.scale,Co)],c=n/2*(l.h/2/l.r);this.sPacked=nt(o,a),this.sColor=o,this.sAlpha=a,this.sU=(l.x+l.w/2)/256,this.sV0=l.y/256,this.sV1=(l.y+l.h)/256,this.sHw=n/2,Eo(e,t,c,i,this.strokeSeg,this.strokeDisc)}target(e,t,n,o){let a=this.gl,i=a.createTexture();this.bindTex(i),a.texImage2D(a.TEXTURE_2D,0,a.RGBA,e,t,0,a.RGBA,a.UNSIGNED_BYTE,null);let l=o?a.LINEAR:a.NEAREST;a.texParameteri(a.TEXTURE_2D,a.TEXTURE_MIN_FILTER,l),a.texParameteri(a.TEXTURE_2D,a.TEXTURE_MAG_FILTER,l),a.texParameteri(a.TEXTURE_2D,a.TEXTURE_WRAP_S,a.CLAMP_TO_EDGE),a.texParameteri(a.TEXTURE_2D,a.TEXTURE_WRAP_T,a.CLAMP_TO_EDGE),this.bindTex(null);let c=a.createFramebuffer();a.bindFramebuffer(a.FRAMEBUFFER,c),a.framebufferTexture2D(a.FRAMEBUFFER,a.COLOR_ATTACHMENT0,a.TEXTURE_2D,i,0);let u=a.checkFramebufferStatus(a.FRAMEBUFFER)===a.FRAMEBUFFER_COMPLETE;if(this.fbNow=c,this.bindFb(this.parent()),!u)return this.deleteTex(i),a.deleteFramebuffer(c),null;let f={tex:{id:pr(),width:e,height:t,source:this.canvas},gl:i,fb:c,w:e,h:t,f:n};return this.layerTex.set(f.tex,i),f}drop(e){this.batch.has(e.tex)&&this.flush(),this.deleteTex(e.gl),this.gl.deleteFramebuffer(e.fb),this.layerTex.delete(e.tex)}parent(){return this.real>0?this.layers[this.real-1]:null}layerAt(e){let t=this.canvas.width,n=this.canvas.height,o=this.layers[e]??null;return o&&(o.w!==t||o.h!==n)&&(this.drop(o),o=this.layers[e]=null),o??(this.layers[e]=this.target(t,n,1,!1))}pushLayer(){if(this.lost)return!1;this.flush();let e=this.layerAt(this.real);if(!e)return!1;let t=this.gl;return this.bindFb(e),t.disable(t.SCISSOR_TEST),t.clearColor(0,0,0,0),t.clear(t.COLOR_BUFFER_BIT),!0}popLayer(){return this.flush(),this.bindFb(this.parent()),this.layers[this.real].tex}filters(){return this.lost||!Ae.gl?null:this.fxr??(this.fxr=Ae.gl(this))}composite(e,t,n,o){if(o&&this.filters()?.chain(e,n,o))return;let a=this.gl;t&&a.blendFunc(a.ZERO,a.SRC_ALPHA),this.final(this.main,e,1,n),t&&(this.flush(),a.blendFunc(a.ONE,a.ONE_MINUS_SRC_ALPHA))}final(e,t,n,o){let a=this.gl,i=this.canvas.width,l=this.canvas.height,c=this.scale;(e!==this.main||!this.mapped)&&(this.bindFb(this.parent()),a.viewport(0,0,i,l),this.use(e),a.uniform2f(e.uScale,2*c/i,-2*c/l),this.mapped=e===this.main);let u=this.rx0/c,f=this.ry0/c,h=this.rx1/c,b=this.ry1/c,y=1/(n*t.width),m=1/(n*t.height),d=this.q;d[0]=d[6]=u,d[1]=d[3]=f,d[2]=d[4]=h,d[5]=d[7]=b,d[8]=this.rx0*y,d[9]=1-this.ry0*m,d[10]=this.rx1*y,d[11]=1-this.ry1*m,d[12]=nt(16777215,o),this.put(t),e!==this.main&&this.flush()}remap(){let e=this.gl;this.bindFb(this.parent()),e.viewport(0,0,this.canvas.width,this.canvas.height),this.use(this.main),e.uniform2f(this.uScale,2*this.scale/this.canvas.width,-2*this.scale/this.canvas.height),this.mapped=!0}upload2(e){let t=this.gl,n=e.words;if(this.kind==="webgl2")return t.bufferSubData(t.ARRAY_BUFFER,0,e.f32,0,n);let o=this.views.get(n);o||(this.views.size>=256&&this.views.clear(),this.views.set(n,o=e.f32.subarray(0,n))),t.bufferSubData(t.ARRAY_BUFFER,0,o)}flush(){let e=this.batch;if(!e.quads||this.lost)return e.reset();let t=this.gl;this.bScis?(t.enable(t.SCISSOR_TEST),t.scissor(this.bx0,this.canvas.height-this.by1,this.bx1-this.bx0,this.by1-this.by0)):t.disable(t.SCISSOR_TEST),this.upload2(e);for(let n=0;n<e.bound;n++){let o=e.textures[n];this.bindTex(this.textures.get(o)??this.layerTex.get(o)??null,n)}this.inst?this.inst.draw(6,e.quads):t.drawElements(t.TRIANGLES,e.quads*6,t.UNSIGNED_SHORT,0),this.stats.drawCalls++,this.stats.quads+=e.quads,e.reset()}end(){return this.closeLayers(),this.flush(),this.stats.filtersSkipped=this.skipped,this.stats}onLost(e){this.lostListeners.push(e)}onRestored(e){this.restoredListeners.push(e)}destroy(){let e=this.gl;Ae.live===this&&(Ae.live=null),this.canvas.removeEventListener("webglcontextlost",this.onContextLost),this.canvas.removeEventListener("webglcontextrestored",this.onContextRestored);try{for(let t of this.textures.values())t&&e.deleteTexture(t);for(let t of this.layers)t&&(e.deleteTexture(t.gl),e.deleteFramebuffer(t.fb));this.fxr?.destroy(),this.fxr=null,e.deleteBuffer(this.dynamic),e.deleteBuffer(this.index),this.staticBuf&&e.deleteBuffer(this.staticBuf),this.vao&&this.vaoApi&&this.vaoApi.remove(this.vao),e.deleteProgram(this.main.p),e.getExtension("WEBGL_lose_context")?.loseContext()}catch{}this.textures.clear()}};function Lo(s,r,e){let t=s.createShader(r);if(s.shaderSource(t,e),s.compileShader(t),!s.getShaderParameter(t,s.COMPILE_STATUS)){let n=s.getShaderInfoLog(t)??"?";throw s.deleteShader(t),new Error(n)}return t}function Dn(s="auto"){switch(s){case"canvas2d":return["canvas2d"];case"webgl1":return["webgl1","canvas2d"];default:return["webgl2","webgl1","canvas2d"]}}function Vt(s,r={}){let e=s;for(let t of Dn(r.renderer)){let n=t==="canvas2d"?$t(e):No(e,t==="webgl2"?2:1,r);if(n)return n;e=kr(e)}throw new Error("No renderer: this browser has neither WebGL nor Canvas 2D")}function kr(s){let r=s.cloneNode(!1);return s.parentNode?.replaceChild(r,s),r}function Bo(s=typeof location<"u"?location.search:""){let r=new URLSearchParams(s).get("renderer");return r==="canvas"?"canvas2d":r==="webgl2"||r==="webgl1"||r==="canvas2d"||r==="webgl"||r==="auto"?r:void 0}var ct=class{constructor(r,e={}){p(this,"atlas",r);p(this,"tags",new Map);p(this,"count",0);p(this,"m",je());p(this,"measure",null);p(this,"height");p(this,"font");this.height=e.tagHeight??34,this.font=e.tagFont??"Nunito, sans-serif"}drop(){for(let r of this.tags.values())for(let e of r.values())for(let t of e.values())this.atlas.release(t);this.tags.clear(),this.count=0}get(r,e,t){let n=this.tags.get(r);n||this.tags.set(r,n=new Map);let o=n.get(e);o||n.set(e,o=new Map);let a=o.get(t);return a&&this.atlas.valid(a)?a:this.bake(r,e,t)}bake(r,e,t){let n=this.height,o=`700 ${Math.round(n*.65)}px ${this.font}`,a=this.measure??(this.measure=document.createElement("canvas").getContext("2d"));a.font=o;let i=Math.round(n*.4),l=Math.ceil(a.measureText(r).width)+i*2,c=this.atlas.bake((l+2)*t,(n+2)*t,h=>{h.scale(t,t),h.translate(1,1);let b=n/2;h.beginPath(),h.moveTo(b,0),h.lineTo(l-b,0),h.arc(l-b,b,b,-Math.PI/2,Math.PI/2),h.lineTo(b,n),h.arc(b,b,b,Math.PI/2,Math.PI*3/2),h.closePath(),h.fillStyle=e,h.fill(),h.fillStyle="#fff",h.font=o,h.textAlign="center",h.textBaseline="middle",h.fillText(r,l/2,n/2+1)},t,1,1,1);++this.count>64&&(this.drop(),this.count=1);let u=this.tags.get(r);u||this.tags.set(r,u=new Map);let f=u.get(e);return f||u.set(e,f=new Map),f.set(t,c),c}draw(r,e,t,n,o,a,i,l,c,u,f){let h=_t(t,o,{band:Oi(n)});if(!h)return;let b=this.height,y=this.get(a,i,c),m=y.w/y.scale-2,d=Math.min(Math.max(h.head.x-m/2,4),u-m-4),x=Math.min(Math.max(h.head.y-h.headR*2.2-b,4),f-b-4);we(this.m,null,d-1,x-1,0,1,1),r.quad(e(y.surface),y,this.m,y.w/y.scale,y.h/y.scale,16777215,l,"normal")}},Oi=s=>s.band==="3-5"||s.band==="9-12"?s.band:"6-8";var Ii=(s,r=!1)=>r?Math.min(2**Math.round(Math.log2(Math.max(s,8))),256):Math.min(2**(Math.ceil(Math.log2(Math.max(s,8))*2)/2),512);function Jr(s,r=null){let e={minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0},t=(n,o,a)=>{let i=r?r[0]*n+r[2]*o+r[4]:n,l=r?r[1]*n+r[3]*o+r[5]:o,c=r?Math.hypot(r[0],r[1]):1;e.minX=Math.min(e.minX,i-a*c),e.minY=Math.min(e.minY,l-a*c),e.maxX=Math.max(e.maxX,i+a*c),e.maxY=Math.max(e.maxY,l+a*c)};for(let n of s){let o="lw"in n&&n.stroke?(n.lw??1)/2:0;switch(n.k){case"circle":t(n.x-n.r,n.y-n.r,o),t(n.x+n.r,n.y+n.r,o),t(n.x-n.r,n.y+n.r,o),t(n.x+n.r,n.y-n.r,o);break;case"ellipse":case"rect":{let a=n.k==="ellipse"?Math.max(n.rx,n.ry):Math.hypot(n.w,n.h)/2;t(n.x-a,n.y-a,o),t(n.x+a,n.y+a,o),t(n.x-a,n.y+a,o),t(n.x+a,n.y-a,o);break}case"path":{let a=Yr(n.d);for(let i=0;i<a.count;i++){let l=a.subs[i];for(let c=0;c<l.n;c++)t(l.pts[c*2],l.pts[c*2+1],o)}break}case"line":for(let a=0;a+1<n.pts.length;a+=2)t(n.pts[a],n.pts[a+1],o);break;case"group":{let a=we(je(),r,n.x,n.y,n.rot??0,n.s??1,n.s??1),i=Jr(n.items,a);Number.isFinite(i.minX)&&(e.minX=Math.min(e.minX,i.minX),e.minY=Math.min(e.minY,i.minY),e.maxX=Math.max(e.maxX,i.maxX),e.maxY=Math.max(e.maxY,i.maxY));break}}}return e}var wt=class{constructor(r){p(this,"atlas",r);p(this,"seen",new WeakSet);p(this,"baked",new WeakMap);p(this,"m",je());p(this,"stack",[]);p(this,"local",je());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(r){let e=r==="low";if(e!==this.coarse){this.coarse=e,this.gen++;for(let t of this.live)this.atlas.release(t.frame);this.live.clear()}}draw(r,e,t,n,o,a,i){let l=typeof n=="string"?Lt(n)??yt:n,c=ir(t,l,o);return c.length?(a<=0||(a<1?(this.paint(r,e,c,null,r.beginLayer()?1:a,i),r.endLayer(a)):this.paint(r,e,c,null,a,i)),!0):!1}paint(r,e,t,n,o,a,i=0){var l;for(let c=0;c<t.length;c++){let u=t[c];if(u.k==="group"){let g=we((l=this.stack)[i]??(l[i]=je()),n,u.x,u.y,u.rot??0,u.s??1,u.s??1),M=o*(u.alpha??1);if(this.bakeGroups&&this.seen.has(u.items)){let v=Ge(g[0],g[1])*a,A=this.bake(u.items,v);if(A){let E=A.frame,C=this.m;C.set(g),C[4]=g[0]*-A.ox+g[2]*-A.oy+g[4],C[5]=g[1]*-A.ox+g[3]*-A.oy+g[5],r.quad(e(E.surface),E,C,E.w/A.k,E.h/A.k,16777215,M,"normal"),this.stats.baked++;continue}}this.seen.add(u.items),this.stats.vector++,this.paint(r,e,u.items,g,M,a,i+1);continue}let f=o*(u.alpha??1),h=n?Ge(n[0],n[1]):1,b=n?Math.atan2(n[1],n[0]):0,y=(u.lw??1)*h,m=u.stroke&&(u.lw??1)>0?he(u.stroke):null,d=u.fill&&u.k!=="line"?he(u.fill):null;if(u.k==="circle"||u.k==="ellipse"){let g=n?n[0]*u.x+n[2]*u.y+n[4]:u.x,M=n?n[1]*u.x+n[3]*u.y+n[5]:u.y,v=(u.k==="circle"?u.r:u.rx)*h,A=(u.k==="circle"?u.r:u.ry)*h,E=(u.k==="ellipse"?u.rot??0:0)+b;if(d&&m)r.ellipse(g,M,v+y/2,A+y/2,E,m[0],f*m[1]),r.ellipse(g,M,Math.max(v-y/2,0),Math.max(A-y/2,0),E,d[0],f*d[1]);else if(d)r.ellipse(g,M,v,A,E,d[0],f*d[1]);else if(m){let C=Math.min(Math.max(Math.ceil(Math.max(v,A)*a*.6),12),64),_=this.pts=qr(this.pts,C*2),L=Math.cos(E),I=Math.sin(E);for(let U=0;U<C;U++){let X=U/C*Math.PI*2,G=Math.cos(X)*v,fe=Math.sin(X)*A;_[U*2]=g+G*L-fe*I,_[U*2+1]=M+G*I+fe*L}r.stroke(_,C,y,m[0],f*m[1],!0)}continue}if(u.k==="line"){if(!m)continue;let g=u.pts.length>>1,M=this.pts=qr(this.pts,g*2);for(let v=0;v<g;v++){let A=u.pts[v*2],E=u.pts[v*2+1];M[v*2]=n?n[0]*A+n[2]*E+n[4]:A,M[v*2+1]=n?n[1]*A+n[3]*E+n[5]:E}r.stroke(M,g,y,m[0],f*m[1],!1);continue}let x=u.k==="path"?Yr(u.d,n,h*a):zi(u,we(this.local,n,u.x,u.y,u.rot??0,1,1),a*h);for(let g=0;g<x.count;g++){let M=x.subs[g],v=M.n,A=u.k==="rect"||M.closed;d&&v>=3&&(r.polygon(M.pts,v,d[0],f*d[1]),m||r.stroke(M.pts,v,1/a,d[0],f*d[1],!0)),m&&r.stroke(M.pts,v,y,m[0],f*m[1],A)}}}bake(r,e){let t=Ii(e,this.coarse),n=this.baked.get(r),o=n?.get(t);if(o&&o.gen===this.gen&&this.atlas.valid(o.frame))return o;o&&this.live.delete(o);let a=Jr(r);if(!Number.isFinite(a.minX))return null;let i=2/t,l=(a.maxX-a.minX+i*2)*t,c=(a.maxY-a.minY+i*2)*t;if(l>1024||c>1024)return null;let u=-a.minX+i,f=-a.minY+i,b={frame:this.atlas.bake(l,c,y=>{y.scale(t,t),y.translate(u,f),Ct(y,r)}),k:t,ox:u,oy:f,gen:this.gen};return n||this.baked.set(r,n=new Map),n.set(t,b),this.live.add(b),b}},Xt=new Array(36).fill(0),qt=0,$e=(s,r=NaN,e=NaN,t=NaN,n=NaN)=>{Xt[qt++]=s,s!==ye.Z&&(Xt[qt++]=r,Xt[qt++]=e,s===ye.Q&&(Xt[qt++]=t,Xt[qt++]=n))};function zi(s,r,e){let t=Math.max(0,Math.min(s.r,s.w/2,s.h/2)),n=-s.w/2,o=-s.h/2,{M:a,L:i,Q:l,Z:c}=ye;return qt=0,$e(a,n+t,o),$e(i,n+s.w-t,o),$e(l,n+s.w,o,n+s.w,o+t),$e(i,n+s.w,o+s.h-t),$e(l,n+s.w,o+s.h,n+s.w-t,o+s.h),$e(i,n+t,o+s.h),$e(l,n,o+s.h,n,o+s.h-t),$e(i,n,o+t),$e(l,n,o,n+t,o),$e(c),Yr(Xt,r,e)}function Do(s,r={}){let e=Vt(s,r),t=new at(Math.min(1024,e.maxTextureSize),2);t.onDrop=A=>{A.texture&&e.destroyTexture(A.texture),A.texture=null};let n=new wt(t),o=new yr,a=new Map,i=1e6,l=r.smooth===!1?1:typeof r.smooth=="number"?Math.min(Math.max(r.smooth,.05),1):.5,c=vr(e),u=new ct(t,r),f={w:1,h:1},h=1,b=0,y=!1,m=()=>u.drop(),d=typeof document<"u"?document.fonts:void 0;d?.ready?.then(()=>{y||m()}),d?.addEventListener?.("loadingdone",m);let x=()=>{let A=kr(e.canvas),E=$t(A);if(E){console.warn("[engine] avatars: WebGL context lost for good, switching to Canvas 2D"),e.destroy(),e=E;for(let C of t.pages)C.surface.texture=null;c=vr(e),b=0}},g=()=>{if(!e.lost)return b=0,!0;let A=performance.now();return b||(b=A),A-b>3e3&&x(),!e.lost},M=()=>{let A=e.canvas;r.units?(h=r.pixelRatio??1,f.w=r.units.width,f.h=r.units.height):(h=r.pixelRatio??Math.min(globalThis.devicePixelRatio||1,2),f.w=A.clientWidth||A.width/h,f.h=A.clientHeight||A.height/h),e.resize(Math.max(1,Math.round(f.w*h)),Math.max(1,Math.round(f.h*h))),e.begin(0,0,h)},v=(A,E)=>{if(A.key===void 0)return A.id??E+1;let C=a.get(A.key);return C===void 0&&(a.size>256&&a.clear(),a.set(A.key,C=i++)),C};return{get renderer(){return e},get kind(){return e.kind},get lost(){return e.lost},get canvas(){return e.canvas},draw(A,E){if(g()){M();for(let C=0;C<A.length;C++){let _=A[C];if(!Array.isArray(_.body))continue;let L=v(_,C),I=l<1||r.interpolate!==!1?o.posed(L,_.body,l,r.interpolate!==!1):_.body,U=Lt(_.avatar??"")??yt,X=_.alpha??1;!n.draw(e,c,I,U,E,X,h)||!_.name||u.draw(e,c,I,U,E,_.name,_.color??"#6FA0E0",X,h,f.w,f.h)}e.end()}},clear(){g()&&(M(),e.end())},reset(){o=new yr,a.clear()},destroy(){y=!0,d?.removeEventListener?.("loadingdone",m),e.destroy()}}}var Zr=new Map;function Oo(s,r,e=Math.min(globalThis.devicePixelRatio||1,2)){let t=`${s}|${r}|${e}`,n=Zr.get(t);if(n)return n;n=document.createElement("canvas"),n.width=n.height=Math.round(r*e);let o=n.getContext("2d");return o.scale(e,e),o.beginPath(),o.rect(0,0,r,r),o.clip(),Ct(o,$s(Lt(s)??yt,r)),Zr.size>64&&Zr.clear(),Zr.set(t,n),n}function vr(s){return r=>{if(r.texture||(r.texture=s.createTexture(r.source),r.pending.length=0),r.pending.length){for(let[e,t,n]of r.pending)s.updateTexture(r.texture,e,t,n);r.pending.length=0}return r.texture}}var On='Fredoka, Nunito, "Varela Round", system-ui, sans-serif',At="rgba(10,16,30,0.75)";function In(s,r){let e=s.size??40,t=s.outline?s.outline===!0?At:s.outline:null,n=t?s.outlineWidth??Math.max(e*.12,3):0,o=s.shadow&&r?s.shadow===!0?At:s.shadow:null,a=o?s.shadowBlur??e*.25:0;return{size:e,font:s.font??On,weight:s.weight??700,color:s.color??"#FBEFE3",outline:t,ow:n,shadow:o,blur:a,pad:n/2+a*1.2+2,th:e*1.25}}var Io=(s,r)=>`${s.weight} ${s.size*r}px ${s.font}`;function zn(s,r,e,t,n,o){s.scale(t,t),s.font=Io(e,1),s.textBaseline="middle",s.textAlign="left",s.lineJoin="round",e.shadow&&(s.shadowColor=e.shadow,s.shadowBlur=e.blur*t),e.outline&&(s.strokeStyle=e.outline,s.lineWidth=e.ow,s.strokeText(r,n,o),s.shadowColor="transparent"),s.fillStyle=e.color,s.fillText(r,n,o)}var en=null;function Un(s,r,e){return en??(en=document.createElement("canvas").getContext("2d")),en.font=Io(r,e),en.measureText(s).width/e}var We=class extends Se{constructor(e,t,n={}){super(e,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=t;let{x:o,y:a,rotation:i,scale:l,scaleX:c,scaleY:u,alpha:f,visible:h,tint:b,blend:y,z:m,anchor:d,hitRadius:x,clip:g,mask:M,filters:v,...A}=n;this._style=A,this.bake(),this.set({x:o,y:a,rotation:i,scale:l,scaleX:c,scaleY:u,alpha:f,visible:h,tint:b,blend:y,z:m,hitRadius:x,clip:g,mask:M,filters:v}),d!==void 0&&(this.anchor=d)}get text(){return this._text}set text(e){let t=String(e);t!==this._text&&(this._text=t,this.dirty=!0)}get style(){return this._style}set style(e){this._style={...this._style,...e},this.dirty=!0}bitmap(){let e=this._style.bitmapFont;if(!e)return null;let t=typeof e=="string"?this.kernel.bitmapFont(e):e;if(this.autoAnchor){let n=this._style.align;this.anchorX=n==="left"?0:n==="right"?1:.5,this.anchorY=.5}return t}get naturalWidth(){let e=this.bitmap();return e?e.measure(this._text)*((this._style.size??e.size)/e.size):super.naturalWidth}get naturalHeight(){let e=this.bitmap();return e?e.lineHeight*((this._style.size??e.size)/e.size):super.naturalHeight}frameNow(){return this._style.bitmapFont?null:this.bake()}draw(e,t,n){let o=this.bitmap();if(!o)return super.draw(e,t,n);let a=(this._style.size??o.size)/o.size,i=o.measure(this._text)*a,l=o.lineHeight*a,c=this.width,u=this.height,f=i>0?c/i:1,h=l>0?u/l:1;o.run(this._text,e,this.world,-this.anchorX*c,-this.anchorY*u,a*f,a*h,n,t,this.blend)}destroy(){this._frame&&this.kernel.atlas.release(this._frame),super.destroy()}bake(){let e=this.kernel;if(this._style.bitmapFont)return null;let t=e.pixelScale,n=e.effects;return!this.dirty&&t===this.bakedScale&&e.fontGen===this.bakedFontGen&&n===this.bakedEffects&&e.atlas.valid(this._frame)?this._frame:this.rebake()}rebake(){let e=this.kernel,t=e.pixelScale,n=e.effects;this.dirty=!1,this.bakedScale=t,this.bakedFontGen=e.fontGen,this.bakedEffects=n;let o=In(this._style,n),{pad:a,th:i}=o,l=Un(this._text,o,t),c=(l+a*2)*t,u=(i+a*2)*t,f=this._style.align??"center",h=f==="left"?a:f==="right"?a+l:a+l/2,b=d=>zn(d,this._text,o,t,a,a+i/2),y=this._frame,m=null;return y&&e.atlas.valid(y)&&y.scale===t&&(m=e.atlas.rebake(y,c,u,b,this.capW,this.capH),m?Object.assign(m,{ox:h,oy:a+i/2,margin:a}):e.atlas.release(y)),m||(this.capW=Math.ceil(c*1.25+16),this.capH=Math.ceil(u),m=e.atlas.bake(this.capW,this.capH,b,t,h,a+i/2,a),m.w=Math.ceil(c),m.h=Math.ceil(u)),this._frame=m,this.autoAnchor&&this.useFrameAnchor(),this._w=this._h=null,m}};var oe=(s,r=0)=>{let e=Number(s);return Number.isFinite(e)?e:r};function Kt(s){typeof s=="string"&&/^\s*[{[]/.test(s)&&(s=JSON.parse(s));let r={size:0,lineHeight:0,base:0,pages:[],chars:[],kernings:[]},e=(t,n)=>{t==="info"?r.size=Math.abs(oe(n.size)):t==="common"?(r.lineHeight=oe(n.lineHeight),r.base=oe(n.base)):t==="page"?r.pages[oe(n.id)]=String(n.file??""):t==="char"?r.chars.push({id:oe(n.id),x:oe(n.x),y:oe(n.y),width:oe(n.width),height:oe(n.height),xoffset:oe(n.xoffset),yoffset:oe(n.yoffset),xadvance:oe(n.xadvance),page:oe(n.page)}):r.kernings.push({first:oe(n.first),second:oe(n.second),amount:oe(n.amount)})};if(typeof s=="object"){let t=s;e("info",t.info??{}),e("common",t.common??{});for(let[n,o]of(t.pages??[]).entries())e("page",{id:n,file:o});for(let n of t.chars??[])e("char",n);for(let n of t.kernings??[])e("kerning",n)}else{let t=/(?:^|<)\s*(info|common|page|char|kerning)\s([^\n<>]*)/gm,n=/(\w+)=(?:"([^"]*)"|([^\s/>]+))/g;for(let o=t.exec(s);o;o=t.exec(s)){let a={};for(let i=n.exec(o[2]);i;i=n.exec(o[2]))a[i[1]]=i[2]??i[3];e(o[1],a)}}return r.size||(r.size=r.lineHeight),r}var Yt=class{constructor(r,e,t,n=null,o=null){p(this,"baker",n);p(this,"host",o);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=r,this.lineHeight=e,this.base=t}set(r,e){r<128?this.ascii[r]=e:this.more.set(r,e)}setKerning(r,e,t){this.kern.set(r*1114112+e,t)}prepare(){let r=this.host;if(!(!r||r.pixelScale===this.bScale&&r.fontGen===this.bFontGen&&r.effects===this.bEffects&&r.atlas.gen===this.bGen)){this.bScale=r.pixelScale,this.bFontGen=r.fontGen,this.bEffects=r.effects,this.bGen=r.atlas.gen;for(let e of this.ascii)e&&r.atlas.release(e.frame);for(let e of this.more.values())e&&r.atlas.release(e.frame);this.ascii.fill(void 0),this.more.clear()}}glyph(r){let e=r<128?this.ascii[r]:this.more.get(r);return(e===void 0||e&&this.host&&!this.host.atlas.valid(e.frame))&&(e=this.baker?this.baker(r):null,this.set(r,e)),e}kerning(r,e){return this.kern.size?this.kern.get(r*1114112+e)??0:0}measure(r){return this.run(r)}run(r,e,t,n=0,o=0,a=1,i=1,l=0,c=1,u="normal"){this.prepare();let f=0,h=-1;for(let b=0;b<r.length;b++){let y=r.charCodeAt(b);y>=55296&&y<56320&&b+1<r.length&&(y=r.codePointAt(b),b++),h>=0&&(f+=this.kerning(h,y)),h=y;let m=this.glyph(y);m&&(e&&m.w>0&&m.h>0&&(mr(t,n+(f+m.x)*a,o+m.y*i),e.r.quad(e.tex(m.frame.surface),m.frame,ne,m.w*a,m.h*i,l,c,u)),f+=m.advance)}return f}};function zo(s,r){let e=new Yt(s.size,s.lineHeight,s.base);for(let t of s.chars){let n=r[t.page];if(!n)continue;let o={surface:n,x:t.x,y:t.y,w:t.width,h:t.height,scale:1,gen:0,ox:0,oy:0,margin:0};e.set(t.id,{frame:o,x:t.xoffset,y:t.yoffset,w:t.width,h:t.height,advance:t.xadvance})}for(let t of s.kernings)e.setKerning(t.first,t.second,t.amount);return e}function Uo(s,r){let e={...r},t=r.size??40,n=a=>{let i=String.fromCodePoint(a),l=s.pixelScale,c=In(e,s.effects),u=Un(i,c,l),f=s.atlas.bake((u+c.pad*2)*l,(c.th+c.pad*2)*l,h=>zn(h,i,c,l,c.pad,c.pad+c.th/2),l);return{frame:f,x:-c.pad,y:-c.pad,w:f.w/l,h:f.h/l,advance:u}},o=new Yt(t,t*1.25,t,n,s);o.prepare();for(let a of r.chars??"0123456789")o.glyph(a.codePointAt(0));return o}var Ui=.5;function Hn(s){let r=[];for(let[e,t]of[["left",K.leftWrist],["right",K.rightWrist]]){let n=s[t*3],o=s[t*3+1],a=s[t*3+2];n!==void 0&&o!==void 0&&Number.isFinite(n)&&Number.isFinite(o)&&(a??0)>=Ui&&r.push({side:e,x:n,y:o})}return r}var wr=s=>sr[((s-1)%sr.length+sr.length)%sr.length];function tn(s,r,e,t,n=()=>null){let o=[];for(let a of s){let i=n(a)??a.body;if(Array.isArray(i))for(let l of Hn(i)){let c=r(l);o.push({player:a.id,side:l.side,x:c.x*e,y:c.y*t,color:wr(a.id)})}}return o}function Ar(s,r,e,t=0){let n=s.world,o=qs(n,r,e);if(!o)return!1;let a=Math.hypot(n[0],n[1])||1,i=Math.hypot(n[2],n[3])||1,[l,c]=o;if(s.hitRadius!=null){let y=s.hitRadius+t/((a+i)/2);return l*l+c*c<=y*y}let u=-s.anchorX*s.width-t/a,f=-s.anchorY*s.height-t/i,h=(1-s.anchorX)*s.width+t/a,b=(1-s.anchorY)*s.height+t/i;return l>=u&&l<=h&&c>=f&&c<=b}function rn(s,r,e,t=0){for(let n of r)if((e===void 0||n.player===e)&&Ar(s,n.x,n.y,t))return n;return null}function Hi(s){switch(s.type){case"circle":case"ring":case"star":return[s.r*2,s.r*2];case"ellipse":return[s.rx*2,s.ry*2];case"roundRect":return[s.w,s.h];case"line":return[s.length,s.lw??4];case"path":return s.r?[s.r*2,s.r*2]:[s.size,s.size]}}function Gi(s){let r=s.type==="line"?0:s.stroke?(s.lw??2)/2:0,e=s.shadow?s.shadow.blur*1.5+Math.max(Math.abs(s.shadow.x??0),Math.abs(s.shadow.y??0)):0;return Math.ceil(r+e+1)}var Ho=(s,r)=>r||!s.shadow?s:{...s,shadow:void 0};function Gn(s,r,e){let t=Gi(r),n=r.type==="roundRect",[o,a]=n?[Math.min(r.w,r.r*2+4/e),Math.min(r.h,r.r*2+4/e)]:Hi(r),i=(o+t*2)*e,l=(a+t*2)*e;return{frame:s.bake(i,l,u=>{u.scale(e,e),u.translate(t+o/2,t+a/2),$i(u,r,o,a)},e,t+o/2,t+a/2,t),slice:n?Math.ceil((r.r+t)*e):0,w:n?r.w:o,h:n?r.h:a}}function $i(s,r,e,t){s.lineJoin="round",s.lineCap="round";let n=new Path2D;switch(r.type){case"circle":case"ring":n.arc(0,0,r.r,0,Math.PI*2);break;case"ellipse":n.ellipse(0,0,r.rx,r.ry,0,0,Math.PI*2);break;case"roundRect":n.roundRect(-e/2,-t/2,e,t,Math.min(r.r,e/2,t/2));break;case"star":{let c=r.points??5,u=r.r*(r.inner??.5);for(let f=0;f<c*2;f++){let h=f%2?u:r.r,b=-Math.PI/2+f*Math.PI/c;f?n.lineTo(Math.cos(b)*h,Math.sin(b)*h):n.moveTo(Math.cos(b)*h,Math.sin(b)*h)}n.closePath();break}case"line":n.moveTo(-e/2+t/2,0),n.lineTo(e/2-t/2,0);break;case"path":{let c=r.r?r.r*2/r.size:1,u=new DOMMatrix([c,0,0,c,-r.size/2*c,-r.size/2*c]);n.addPath(new Path2D(r.d),u);break}}let o=r.shadow,a=()=>{if(!o)return;let c=s.getTransform();s.shadowColor=o.color,s.shadowBlur=o.blur*c.a,s.shadowOffsetX=(o.x??0)*c.a,s.shadowOffsetY=(o.y??0)*c.a},i=()=>{s.shadowColor="transparent",s.shadowBlur=0};if(r.type==="line"){a(),s.strokeStyle=r.stroke??r.fill??"#fff",s.lineWidth=t,s.stroke(n);return}let l=r.type==="ring";if(r.outlineBelow&&r.fill&&r.stroke&&!l){a(),s.strokeStyle=r.stroke,s.lineWidth=r.lw??2,s.stroke(n),i(),s.fillStyle=r.fill,s.fill(n);return}r.fill&&!l&&(a(),s.fillStyle=r.fill,s.fill(n),i()),(r.stroke||l)&&((!r.fill||l)&&a(),l&&r.fill&&(s.fillStyle=r.fill,s.fill(n)),s.strokeStyle=r.stroke??"#fff",s.lineWidth=r.lw??2,s.stroke(n),i())}var jt=class{constructor(){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);if(typeof addEventListener=="function"){let r=()=>{this.context()?.resume().catch(()=>{})};for(let e of["pointerdown","keydown","touchstart"])addEventListener(e,r,{once:!0,capture:!0})}}context(){if(this.ctx)return this.ctx;let r=globalThis.AudioContext??globalThis.webkitAudioContext;if(!r)return null;try{this.ctx=new r,this.master=this.ctx.createGain(),this.master.connect(this.ctx.destination),this.held&&this.ctx.suspend()}catch{return null}return this.ctx}async load(r,e){let t=this.context();if(!t)return;let n=await(await fetch(e)).arrayBuffer();this.buffers.set(r,await t.decodeAudioData(n))}has(r){return this.buffers.has(r)}play(r,e={}){let t=this.context(),n=this.buffers.get(r);if(!t||!n||!this.audible)return()=>{};let o=t.createBufferSource();o.buffer=n,o.loop=e.loop??!1,o.playbackRate.value=e.rate??1;let a=t.createGain();return a.gain.value=(e.volume??1)*this.volume,o.connect(a).connect(this.master),o.start(),()=>{try{o.stop()}catch{}}}tone(r,e=.25,t={}){let n=this.context();if(!(!n||!this.audible))try{let o=n.createOscillator(),a=n.createGain();o.type=t.type??"sine",o.frequency.setValueAtTime(r,n.currentTime),t.to&&o.frequency.exponentialRampToValueAtTime(t.to,n.currentTime+e),a.gain.setValueAtTime((t.volume??.12)*this.volume,n.currentTime),a.gain.exponentialRampToValueAtTime(.001,n.currentTime+e),o.connect(a).connect(this.master),o.start(),o.stop(n.currentTime+e)}catch{}}get audible(){return!this.muted&&!this.held}hold(){this.held=!0,this.ctx?.suspend().catch(()=>{})}release(){this.held=!1,this.ctx?.resume().catch(()=>{})}destroy(){this.ctx?.close().catch(()=>{}),this.ctx=null}};var Wi={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}},Ve=["high","medium","low"];function et(s){let r=Wi[s];return{name:s,...r,scale:e=>e<=0?0:Math.max(1,Math.round(e*r.particles))}}var Go=s=>Ve[Math.min(Ve.indexOf(s)+1,Ve.length-1)],nn=(s,r)=>{if(!s.length)return NaN;let e=[...s].sort((t,n)=>t-n);return e[Math.min(e.length-1,Math.max(0,Math.floor(r*(e.length-1)+.5)))]},$o=12,Wo=s=>Sr(s,.5);function Sr(s,r=.1){let e=nn(s,r);if(!Number.isFinite(e))return 1e3/60;let t=[144,120,90,75,60,50,30],n=60;for(let o of t)Math.abs(1e3/o-e)<Math.abs(1e3/n-e)&&(n=o);return 1e3/n}function sn(s,r){let e=r.refresh!==void 0&&Number.isFinite(r.refresh)&&r.refresh>0?r.refresh:Sr(r.intervals),t=nn(r.intervals,.5),n=nn(r.intervals,.9),o=nn(r.cpu,.5);if(!Number.isFinite(t))return s==="canvas2d"?"low":"medium";let a=l=>l<=e*1.25,i=l=>!Number.isFinite(o)||o<e*l;return s==="canvas2d"?a(n)&&i(.25)?"medium":"low":a(n)&&i(.5)?"high":a(t)?"medium":"low"}function Vo(s,r){return s.length<30?!1:s.filter(t=>t>r*1.5).length/s.length>.5}var Xo="0.1.1",Vi=720*3600*1e3,qo=(s,r,e)=>`fabi-play.engine-tier:${Xo}:${s}:${r}:${e}`,Yo=(s,r,e)=>`fablee-engine-tier:${Xo}:${s}:${r}:${e}`;function Ko(s,r,e=Date.now()){try{let t=JSON.parse(s?.getItem(r)??"null");if(t&&Ve.includes(t.tier)&&typeof t.at=="number"&&e-t.at<Vi)return typeof t.refresh=="number"&&t.refresh>0?{name:t.tier,refresh:t.refresh}:{name:t.tier}}catch{}return null}function $n(s,r,e,t,n=Date.now()){try{s?.setItem(r,JSON.stringify(t!==void 0&&Number.isFinite(t)?{tier:e,at:n,refresh:t}:{tier:e,at:n}))}catch{}}function jo(s=typeof location<"u"?location.search:""){let r=new URLSearchParams(s).get("tier");return Ve.includes(r)?r:void 0}function Wn(s,r){let e=r?.tier;if(Ve.includes(e))return s==="canvas2d"&&e==="high"?"medium":e}var Vn=s=>typeof s?.hz=="number"&&s.hz>=20&&s.hz<=240?Sr([1e3/s.hz],.5):NaN,Xn=(s,r)=>Ve.indexOf(s)>=Ve.indexOf(r)?s:r;function Qo(s,r,e){return s?{name:s,from:"forced"}:r?{name:e?Xn(r,e):r,from:"hint"}:e?{name:e,from:"cache"}:null}var Xi=/^\s*(<|>|[^+\-<>=\s][^+=]*?)?\s*(?:([+-])=\s*(\d*\.?\d+))?\s*$/,Qt=class{constructor(r={}){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");this.repeat=Math.floor(r.repeat??0),this.yoyo=!!r.yoyo,this.delayLeft=r.delay??0,this._paused=!!r.paused,this.onComplete=r.onComplete,this.promise=new Promise(e=>this.resolve=e)}get duration(){return this.end}get time(){return this.last}get paused(){return this._paused}get finished(){return this.done}at(r){if(r===void 0)return this.end;if(typeof r=="number")return Math.max(r,0);let e=Xi.exec(r);if(!e)throw new Error(`[engine] timeline: bad position "${r}"`);let[,t,n,o]=e,a=o?(n==="-"?-1:1)*Number(o):0,i=this.end;if(t==="<")i=this.prevStart;else if(t&&t!==">"){let l=this.labels.get(t.trim());l===void 0?this.labels.set(t.trim(),this.end):i=l}return Math.max(i+a,0)}add(r){let e=this.steps.length;for(;e>0&&this.steps[e-1].start>r.start;)e--;return this.steps.splice(e,0,r),this.prevStart=r.start,this.end=Math.max(this.end,r.start+r.dur),this}to(r,e,t,n="quadOut"){let o=typeof n=="object"?n:{ease:n},a=typeof o.ease=="function"?o.ease:st[o.ease??"quadOut"];return this.add({target:r,to:e,from:null,fn:null,start:this.at(o.at)+(o.delay??0),dur:Math.max(t,0),ease:a,onUpdate:o.onUpdate,p:-1})}set(r,e,t){return this.add({target:r,to:e,from:null,fn:null,start:this.at(t),dur:0,ease:st.linear,p:-1})}call(r,e){return this.add({target:null,to:null,from:null,fn:r,start:this.at(e),dur:0,ease:st.linear,p:-1})}label(r,e){return this.labels.set(r,this.at(e)),this}wait(r){return this.end+=Math.max(r,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(r){let e=Math.min(typeof r=="string"&&this.labels.has(r)?this.labels.get(r):this.at(r),this.end),t=this.yoyo&&this.iter%2===1;return this.elapsed=this.iter*this.end+(t?this.end-e:e),this.render(e),this}then(r,e){return this.promise.then(r,e)}update(r){if(this._paused||this.done)return;if(this.delayLeft>0){if(this.delayLeft-=r,this.delayLeft>0)return;r=-this.delayLeft,this.delayLeft=0}let e=this.end;if(e<=0)return this.render(0),this.complete();this.elapsed+=r;let t=this.repeat<0?1/0:e*(this.repeat+1),n=Math.min(this.elapsed,t),o=n>=t?this.repeat:Math.floor(n/e);for(;this.iter<o;){let i=this.yoyo&&this.iter%2===1;this.render(i?0:e),this.iter++,this.yoyo||(this.rewinding=!0,this.render(0),this.rewinding=!1)}let a=n-o*e;this.render(this.yoyo&&o%2===1?e-a:a),n>=t&&this.complete()}complete(){this.done||(this.done=!0,this.onComplete?.(),this.resolve())}render(r){let e=this.steps;if(r>=this.last)for(let t=0;t<e.length;t++){let n=e[t];r>=n.start&&this.apply(n,r)}else for(let t=e.length-1;t>=0;t--){let n=e[t];n.p>=0&&this.apply(n,r)}this.last=r}apply(r,e){let t=r.dur>0?Math.min(Math.max((e-r.start)/r.dur,0),1):e>r.start||e===r.start&&!this.rewinding?1:0;if(t===r.p)return;if(r.p=t,r.fn){this.rewinding||r.fn();return}let n=r.target;if(n.destroyed||n._free)return;let o=r.to;if(!r.from){r.from={};for(let i in o)r.from[i]=Number(n[i]??0)}let a=r.ease(t);for(let i in o)n[i]=r.from[i]+(o[i]-r.from[i])*a;r.onUpdate?.(a)}};var Zt=class{constructor(){p(this,"list",[]);p(this,"timelines",[])}timeline(r){let e=new Qt(r);return this.timelines.push(e),e}tween(r,e,t,n="quadOut"){let o=typeof n=="object"?n:{ease:n},a=typeof o.ease=="function"?o.ease:st[o.ease??"quadOut"],i,l=new Promise(c=>{let u=Object.keys(e),f=new Float64Array(u.length);u.forEach((h,b)=>f[b]=Number(e[h])),i={target:r,keys:u,to:f,from:new Float64Array(u.length),started:!1,duration:Math.max(t,0),time:0,delay:o.delay??0,ease:a,onUpdate:o.onUpdate,done:c,dead:!1}});return this.list.push(i),Object.assign(l,{stop:()=>this.finish(i)})}stopAll(r){let e=this.list;for(let t=0;t<e.length;t++)e[t].target===r&&this.finish(e[t])}get size(){return this.list.length}update(r){if(this.timelines.length){let n=0,o=this.timelines;for(let a=0;a<o.length;a++){let i=o[a];i.update(r),i.finished||(o[n++]=i)}o.length=n}let e=this.list;if(!e.length)return;let t=0;for(let n=0;n<e.length;n++){let o=e[n];o.dead||this.step(o,r),o.dead||(e[t++]=o)}t!==e.length&&(e.length=t)}step(r,e){if(r.target.destroyed)return this.finish(r);let t=e;if(r.delay>0){if(r.delay-=e,r.delay>0)return;t=-r.delay}let n=r.keys;if(!r.started){r.started=!0;for(let i=0;i<n.length;i++)r.from[i]=Number(r.target[n[i]]??0)}r.time+=t;let o=r.duration>0?Math.min(r.time/r.duration,1):1,a=r.ease(o);for(let i=0;i<n.length;i++)r.target[n[i]]=r.from[i]+(r.to[i]-r.from[i])*a;r.onUpdate?.(a),o>=1&&this.finish(r)}finish(r){r.dead||(r.dead=!0,r.done())}clear(){for(let r of this.list)this.finish(r);this.list.length=0;for(let r of this.timelines)r.stop();this.timelines=[]}};var ae=720,Mr=class extends Fe{constructor(e,t){super(e);p(this,"paintAll",t)}draw(e,t){this.paintAll(e,t)}},Yn=class extends Fe{constructor(e,t){super(e);p(this,"paintAll",t)}draw(e,t){this.paintAll(e,t)}},ut=()=>performance.now();async function Jo(s={}){let r=s.play??null,e=s.canvas??null;e||(e=document.createElement("canvas"),e.style.cssText="position:fixed;inset:0;width:100%;height:100%;display:block;touch-action:none",document.body.appendChild(e));let t=Vt(e,{renderer:s.renderer??Bo(),failIfMajorPerformanceCaveat:s.failIfMajorPerformanceCaveat,instancing:s.instancing});e=t.canvas;let n=new Set,o=new at(Math.min(2048,t.maxTextureSize),4);o.onPage=k=>n.add(k),o.onDrop=k=>{n.delete(k),k.texture&&t.destroyTexture(k.texture),k.texture=null};let a=vr(t),i=new Zt,l=new jt,c=new wt(o),u=new Map,f=new Map,h=new Map,b=new Map,y=new Map,m=new Set,d=0,x=s.tier??jo(),g=String(t.info.renderer??""),M=(()=>{try{return globalThis.localStorage??null}catch{return null}})(),v=typeof screen<"u"?`${screen.width}x${screen.height}`:"",A=qo(t.kind,g,v);Es(M,A,Yo(t.kind,g,v));let E=Ko(M,A),C=Qo(x,Wn(t.kind,r?.device),E?.name),_=C?.name??"medium",L=et(_);c.setTier(_);let I=C?.from==="hint",U=E?.name,X=E?.refresh??Vn(r?.device),G=1,fe=1,H=1,re={atlas:o,get pixelScale(){return G},get fontGen(){return d},get effects(){return L.effects},tweens:i,frame:k=>Pr.frame(k),shape:k=>{let S=L.effects,F=S?G:-G,R=u.get(F);R||(u.size>=8&&u.clear(),u.set(F,R=new Ht(2e3)));let B=De(k),ee=R.get(k,B);return(!ee||!o.valid(ee.frame))&&R.set(k,ee=Gn(o,Ho(k,S),G),B),ee},bitmapFont:k=>Pr.bitmapFont(k)},pe=1280,Pe=null;class cn extends vt{get width(){return pe}set width(S){}get height(){return ae}set height(S){}get safe(){let S=Math.min(pe,ae*16/9);return{x:(pe-S)/2,y:0,w:S,h:ae}}}let xe=new cn(re),_e=()=>{let k=t.canvas,S=k.getBoundingClientRect();fe=Math.max(1,S.width||k.clientWidth||innerWidth),H=Math.max(1,S.height||k.clientHeight||innerHeight),pe=ae*fe/H;let F=Math.min(globalThis.devicePixelRatio||1,s.maxPixelRatio??2);if(H*F/ae<=L.resolution){let B=Math.max(1,Math.round(H*F));G=B/ae,t.resize(Math.max(1,Math.round(fe*F)),B)}else G=L.resolution,t.resize(Math.round(pe*G),Math.round(ae*G));Pe&&Pe.style.setProperty("--unit",`${H/ae}px`)};addEventListener("resize",_e);let ge=k=>{_=k,L=et(k),c.setTier(k),_e()},ie=typeof ResizeObserver<"u"?new ResizeObserver(_e):null;ie?.observe(e);let Le=r?.backdrop==="video"?"video":"none",w=r?.view??null,N=[],D=-1/0,q=!1,$=!1,se=new Set,Mt=()=>{let k=Le==="video"?"transparent":"";document.documentElement.style.background=k,document.body.style.background=k},qe=(k,S)=>{let F=k==="video"?"video":"none",R=S??null;if(!(F===Le&&(R===w||R&&w&&R.x===w.x&&R.y===w.y&&R.w===w.w&&R.h===w.h))){Le=F,w=R,Mt();for(let B of[...se])B(Le,w)}},Jt=[];if(r){let k=R=>{Array.isArray(R)&&(N=R,D=ut())},S=R=>{q=R,Ie()},F=R=>{if(x||I)return;Number.isFinite(X)||(X=Vn(R));let B=Wn(t.kind,R);B&&(I=!0,ge(U?Xn(B,U):B))};Jt.push(r.on("start",R=>F(R?.device)),r.on("frame",R=>k(R?.players)),r.on("players",R=>k(R?.players)),r.on("backdrop",R=>qe(R?.backdrop,R?.view)),r.on("start",R=>qe(R?.backdrop,R?.view??r.view)),r.on("pause",()=>S(!0)),r.on("resume",()=>S(!1)),r.on("break-start",()=>S(!0)),r.on("break-done",()=>S(!1)),r.on("break-end",()=>S(!1))),l.muted=r.muted===!0}Mt();let Ie=()=>q||$||document.hidden?l.hold():l.release(),Tt=-1,ze=[],Ye=0,Et=()=>ut()-D<1e3?N:[],er=k=>r?r.toScreen(k):Ts(w,k),ht=()=>{if(Tt===Ye)return ze;Tt=Ye;let k=Le==="video"||!r?.smoothedBody?()=>null:S=>r.smoothedBody(S);return ze=tn(Et(),er,pe,ae,k),ze},tr={x:0,y:0,w:1,h:1},va=()=>(tr.x=w?w.x*pe:0,tr.y=w?w.y*ae:0,tr.w=w?w.w*pe:pe,tr.h=w?w.h*ae:ae,tr),wa=k=>{let S=k.alpha??1,F=k.tags?new ct(o,k):null;F&&m.add(F);let R=typeof k.tags=="function"?k.tags:B=>String(B);return(B,ee)=>{if(Le==="video")return;let z=va();for(let W of Et()){let le=r?.smoothedBody?.(W)??W.body,Q=Lt(r?.avatarOf?.(W)??W.avatar??"")??yt;if(!c.draw(B.r,B.tex,le,Q,z,S*ee,G)||!F)continue;let Ee=R(W.id);Ee&&F.draw(B.r,B.tex,le,Q,z,Ee,wr(W.id),S*ee,G,pe,ae)}}},un=new Set,hn=new Set,rr=new Set,Er=!1,fn=0,Rt=0,Rr=0,ft={fps:0,cpuMs:0,drawCalls:0,quads:0,filtersSkipped:0},Fr=0,pn=0,dn=ut(),nr=[],Cr=0,bs=()=>({r:t,kernel:re,tex:a}),ys=bs(),Aa=()=>{if(t.lost)return;let[k,S]=Le==="video"||s.background===void 0?[0,0]:he(s.background);t.time=Rr,t.maxBlur=L.maxBlur,t.begin(k,S,G),we(xe.world,null,xe.x,xe.y,xe.rotation,xe.scaleX,xe.scaleY),Fn(ys,xe,xe.alpha,xe.tint);let F=t.end();ft.drawCalls=F.drawCalls,ft.quads=F.quads,ft.filtersSkipped=F.filtersSkipped},xs=k=>{if(!Er)return;fn=requestAnimationFrame(xs);let S=Math.min(Math.max((k-Rt)/1e3,0),.1);Rt&&nr.push(k-Rt),Rt=k,Ye++;let F=ut(),R=q||$;if(!R){Rr+=S,i.update(S);for(let B of rr)B.destroyed||B.update(S);for(let B of un)B(S,Rr)}for(let B of hn)B(S);xe.sweep();for(let B of rr)B.destroyed&&rr.delete(B);if(t.lost?(Cr||(Cr=k),k-Cr>3e3&&Sa()):(Cr=0,Aa()),Fr++,pn+=ut()-F,F-dn>=1e3&&(ft.fps=Math.round(Fr*1e3/(F-dn)),ft.cpuMs=Math.round(pn/Math.max(Fr,1)*100)/100,r?.reportStats?.({fps:ft.fps,renderer:t.kind,tier:_}),Fr=0,pn=0,dn=F),nr.length>=180){let B=Number.isFinite(X)?X:Sr(nr);!x&&!R&&Vo(nr,B)&&_!=="low"&&(ge(Go(_)),U=_,$n(M,A,_,Number.isFinite(X)?X:void 0),console.info(`[engine] slow frames: tier ${_}`)),nr.length=0}},Sa=()=>{let k=kr(t.canvas),S=$t(k);if(S){console.warn("[engine] WebGL context lost for good: switching to Canvas 2D"),t.destroy(),t=S;for(let F of n)F.texture=null;for(let F of o.pages)n.add(F.surface);a=vr(t),ys=bs(),ie?.disconnect(),ie?.observe(k),_e()}},gs=()=>{Ie(),document.hidden||(Rt=0)};document.addEventListener("visibilitychange",gs);let ks=()=>{d++;for(let k of m)k.drop()};if(document.fonts?.addEventListener?.("loadingdone",ks),_e(),!C&&s.probe!==!1&&(Number.isFinite(X)||(X=Wo(await qi($o))),!I)){L=et("high"),_e();let k=await Yi(t,o,()=>a,()=>G,pe,()=>I);if(k.refresh=X,!I){let S=sn(t.kind,k);$n(M,A,S,X),U=S,ge(S)}}let Pr={stage:xe,get tier(){return L},get renderer(){return t},get canvas(){return t.canvas},get pixelScale(){return G},get backdrop(){return Le},get view(){return w},get paused(){return q||$},sound:l,stats:ft,get time(){return Rr},get supports(){let k=t.support;return{filters:k.filters,blur:k.filters&&L.maxBlur>0,shaders:k.shaders,maxBlur:k.filters?L.maxBlur:0,tiers:{high:{maxBlur:et("high").maxBlur},medium:{maxBlur:et("medium").maxBlur},low:{maxBlur:et("low").maxBlur}}}},sprite:(k,S)=>new Se(re,k,S),shape:(k,S)=>new He(re,k,S),text:(k,S)=>new We(re,k,S),group:k=>new vt(re).set(k??{}),particles(k,S={}){let F=typeof k=="object"&&"type"in k?re.shape(k).frame:k,R=new Ot(re,F,S),{max:B,blend:ee,gravity:z,drag:W,...le}=S;return R.set(le),rr.add(R),R},tween:(k,S,F,R)=>i.tween(k,S,F,R),bake(k,S,F,R,B){return h.set(k,{w:S,h:F,draw:R,origin:B}),f.delete(k),Pr.frame(k)},frame(k){let S=f.get(k);if(S&&o.valid(S)&&(S.gen===0||S.scale===G))return S;let F=h.get(k);if(F){let R=G,B=o.bake(F.w*R,F.h*R,ee=>(ee.scale(R,R),F.draw(ee)),R,F.origin?.x??0,F.origin?.y??0);return f.set(k,B),B}if(S)return S;throw new Error(`[engine] no frame "${k}": load it or bake it first`)},async load(k){await Promise.all(Object.entries(k).map(([S,F])=>Ta(S,F)))},hands:k=>k===void 0?ht():ht().filter(S=>S.player===k),touched(k,S,F={}){return k.updateWorld(),rn(k,ht(),S,F.padding??0)},hits(k,S,F,R=0){return k.updateWorld(),Ar(k,S,F,R)},avatars:(k={})=>new Mr(re,wa(k)),handMarkers(k={}){let S=k.radius??36,F=k.look??"auto",R=new Float64Array(6),B=Math.max(S*.12,3),ee={type:"ring",r:S,lw:B,fill:"rgba(251,231,184,0.3)",stroke:"#ffffff"},z={type:"ring",r:S,lw:B*1.8,stroke:At,shadow:{color:At,blur:S*.2}},W=(pt,ke,Ft,mn,_r,dt)=>{let Lr=ke.w/ke.scale;we(R,null,Ft-Lr/2,mn-Lr/2,0,1,1),pt.r.quad(pt.tex(ke.surface),ke,R,Lr,Lr,_r,dt,"normal")},le=pt=>{let ke=null,Ft=!1;return()=>(ke&&o.valid(ke.frame)&&ke.frame.scale===G&&Ft===L.effects?ke:(Ft=L.effects,ke=re.shape(pt))).frame},Q=le(ee),Ee=le(z);return new Yn(re,(pt,ke)=>{let Ft=F==="video"||F==="auto"&&Le==="video",mn=Q(),_r=Ft?Ee():null;for(let dt of ht())_r&&W(pt,_r,dt.x,dt.y,16777215,ke),W(pt,mn,dt.x,dt.y,he(dt.color)[0],ke)})},timeline:k=>i.timeline(k),animation(k,S){let F=typeof k=="string"?Ma(k):{frames:k},R=new Ce(re,F,S);return rr.add(R),R},bitmapFont(k,S){if(!S){let R=b.get(k);if(!R)throw new Error(`[engine] no bitmap font "${k}": load or make it first`);return R}let F="data"in S?vs(Kt(S.data),S.pages):Uo(re,S);return b.set(k,F),F},players:()=>Et(),onFrame(k){return un.add(k),()=>{un.delete(k)}},onRender(k){return hn.add(k),()=>{hn.delete(k)}},onBackdrop(k){return se.add(k),()=>{se.delete(k)}},get hud(){return Pe||(Pe=document.createElement("div"),Pe.style.cssText="position:fixed;inset:0;pointer-events:none;overflow:hidden",document.body.appendChild(Pe),_e()),Pe},random:(k=0,S=1)=>k+Math.random()*(S-k),start(){Er||(Er=!0,Rt=0,fn=requestAnimationFrame(xs))},pause(){$=!0,Ie()},resume(){$=!1,Ie()},destroy(){Er=!1,cancelAnimationFrame(fn),Jt.forEach(k=>k()),removeEventListener("resize",_e),ie?.disconnect(),document.removeEventListener("visibilitychange",gs),document.fonts?.removeEventListener?.("loadingdone",ks),i.clear(),io(re),l.destroy(),t.destroy(),Pe?.remove()}};function Ma(k){let S=y.get(k);if(S)return S;let F=[...new Set([...f.keys(),...h.keys()])].filter(R=>R.startsWith(k)).sort(co);if(!F.length)throw new Error(`[engine] no animation or frames "${k}\u2026"`);return{frames:F}}async function Ta(k,S){let F=S.split("?")[0].split(".").pop().toLowerCase();if(["mp3","ogg","wav","m4a","aac","webm"].includes(F))return l.load(k,S);if(["woff","woff2","ttf","otf"].includes(F)){let z=new FontFace(k,`url(${S})`);document.fonts.add(await z.load()),d++;return}let R=new URL(S,location.href);if(F==="fnt")return ws(k,Kt(await(await fetch(S)).text()),R);if(F==="json"){let z=await(await fetch(S)).json();if(Array.isArray(z.chars)&&!z.frames)return ws(k,Kt(z),R);let W=await qn(new URL(z.meta?.image??S.replace(/\.json$/,".png"),R).href);Ea(k,z,It(W));return}let B=await qn(S),ee=It(B);n.add(ee),f.set(k,{surface:ee,x:0,y:0,w:B.width,h:B.height,scale:1,gen:0,ox:0,oy:0,margin:0})}function vs(k,S){return zo(k,S.map(F=>{let R=It(F);return n.add(R),R}))}async function ws(k,S,F){b.set(k,vs(S,await Promise.all(S.pages.map(R=>qn(new URL(R,F).href)))))}function Ea(k,S,F){n.add(F);let R=Array.isArray(S.frames)?S.frames:Object.entries(S.frames).map(([z,W])=>({...W,filename:z})),B=[],ee=[];for(let z of R){let W=z.frame,le=z.filename.replace(Zo,"");z.rotated&&console.warn(`[engine] ${k}/${le} is rotated: export without rotation`);let Q={surface:F,x:W.x,y:W.y,w:W.w,h:W.h,scale:1,gen:0,ox:0,oy:0,margin:0};z.trimmed&&z.sourceSize&&z.spriteSourceSize&&(Q.sw=z.sourceSize.w,Q.sh=z.sourceSize.h,Q.tx=z.spriteSourceSize.x,Q.ty=z.spriteSourceSize.y);let Ee=z.scale9Borders;Ee&&(Q.slice=[Ee.y,(Q.sw??W.w)-Ee.x-Ee.w,(Q.sh??W.h)-Ee.y-Ee.h,Ee.x]),f.set(`${k}/${le}`,Q),B.push(`${k}/${le}`),ee.push((z.duration??0)/1e3)}for(let[z,W]of Object.entries(S.animations??{}))y.set(`${k}/${z}`,{frames:W.map(le=>`${k}/${le.replace(Zo,"")}`)});for(let z of S.meta?.frameTags??[]){let W=[];for(let Q=z.from;Q<=z.to;Q++)W.push(Q);z.direction==="reverse"&&W.reverse(),z.direction==="pingpong"&&W.push(...W.slice(1,-1).reverse());let le=W.every(Q=>ee[Q]>0);y.set(`${k}/${z.name}`,{frames:W.map(Q=>B[Q]),...le?{durations:W.map(Q=>ee[Q])}:{}})}}return Pr}var Zo=/\.(png|webp|jpe?g|gif|bmp)$/i;function qn(s){return new Promise((r,e)=>{let t=new Image;t.onload=()=>r(t),t.onerror=()=>e(new Error(`[engine] image did not load: ${s}`)),t.src=s})}function qi(s){return new Promise(r=>{let e=[],t=0,n=o=>{t&&e.push(o-t),t=o,e.length<s?requestAnimationFrame(n):r(e)};requestAnimationFrame(n)})}async function Yi(s,r,e,t,n,o=()=>!1){let a=t(),i=Gn(r,{type:"star",r:30,fill:"#ffd23f",stroke:"#3a2a10",lw:3},a).frame,l=[],c=[],u=new Float64Array(6),f=.004,h=s.kind==="canvas2d"?s.canvas.getContext("2d"):null,b=ut(),y=0;return await new Promise(m=>{let d=x=>{y&&x-b>250&&l.push(x-y),y=x;let g=ut();s.begin(0,0,a);let M=e();for(let v=0;v<300;v++){let A=x/1e3+v;we(u,null,v*37%n,v*53%ae,A,1,1),s.quad(M(i.surface),i,u,i.w/a,i.h/a,16777215,f,"normal")}for(let v=0;v<40;v++)s.ellipse(100+v*20,300,20,14,v,16746496,f),s.stroke([100+v*20,400,120+v*20,460,100+v*20,520],3,18,3368703,f,!1);s.end(),h?.getImageData(0,0,1,1),x-b>250&&c.push(ut()-g),x-b<750&&!o()?requestAnimationFrame(d):(s.begin(0,0,a),s.end(),m())};requestAnimationFrame(d)}),{intervals:l,cpu:c}}var Ki=64,ea=32,ji=0,Qi=`fabi-cm-${Math.random().toString(36).slice(2,7)}-`,ta=new Set,ra=(s,r)=>{ta.has(s)||(ta.add(s),console.warn(r))},na=s=>new Kn(s),Kn=class{constructor(r){p(this,"r",r);p(this,"css","none");p(this,"plans",new Ht(Ki));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",r=>this.svg(r));p(this,"scr",[]);p(this,"flip",0)}chain(r,e){var y;let t=this.r,n=this.buf;n[0]=t.scale,n[1]=t.maxBlur;let o=2;for(let m=0;m<e.length;m++){let d=e[m];if(o+22>n.length){let g=new Float64Array(n.length*2);g.set(n),n=this.buf=g}let x=this.classes.get(d.constructor);x===void 0&&this.classes.set(d.constructor,x=this.classes.size),n[o++]=x,n[o++]=d.enabled?1:0,d.params&&(o=d.params(n,o))}let a=(y=this.keys)[o]??(y[o]=new Float64Array(o));for(let m=0;m<o;m++)a[m]=n[m];let i=De(a),l=this.plans.get(a,i);l||this.plans.set(a,l=this.plan(e),i);for(let m=0;m<l.svgs.length;m++){let d=l.svgs[m];d.used<0&&this.attach(d),d.used=this.t}t.skipped+=l.skip;let c=r,u=t.rx0,f=t.ry0,h=t.rx1-u,b=t.ry1-f;for(let m=0;m<l.paints.length;m++)l.parts[m]&&(c=this.bake(c,l.parts[m])),e[l.paints[m]].paint2d(c.getContext("2d"),u,f,h,b);return this.css=l.parts[l.paints.length]||"none",c}tick(){let r=++this.t;if(!(r%ea||!this.live.size))for(let e of this.live)r-e.used>ea&&this.detach(e)}destroy(){for(let r of this.live)this.detach(r);this.plans.clear()}svg(r){if(typeof document>"u"||!document.body)return null;let e=Array.from({length:20},(n,o)=>r[o]??0).join(" "),t=this.svgs.get(e);if(!t){let n="http://www.w3.org/2000/svg",o=document.createElementNS(n,"svg");o.setAttribute("width","0"),o.setAttribute("height","0"),o.setAttribute("aria-hidden","true"),o.style.position="absolute";let a=document.createElementNS(n,"filter"),i=Qi+ ++ji;a.setAttribute("id",i),a.setAttribute("color-interpolation-filters","sRGB");let l=document.createElementNS(n,"feColorMatrix");l.setAttribute("type","matrix"),l.setAttribute("values",e),a.append(l),o.append(a),this.attach(t={key:e,id:i,el:o,used:this.t})}return this.cur.svgs.push(t),`url(#${t.id})`}attach(r){document.body.append(r.el),this.live.add(r),this.svgs.has(r.key)||this.svgs.set(r.key,r)}detach(r){r.el.remove(),r.used=-1,this.live.delete(r),this.svgs.get(r.key)===r&&this.svgs.delete(r.key)}plan(r){let e=this.r,t=this.cur={parts:[],paints:[],skip:0,svgs:[]},n="";for(let o=0;o<r.length;o++){let a=r[o];if(!a.enabled)continue;if(a.kind===4){t.skip++,ra("shader","[engine] shader() filters are WebGL only: on Canvas 2D they are skipped (check engine.supports.shaders)");continue}let i=e.support.filters&&a.css?a.css(e.scale,e.maxBlur,this.svgFn):null;i!==null?n+=n?` ${i}`:i:a.paint2d?(t.parts.push(n),t.paints.push(o),n=""):(t.skip++,ra("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 t.parts.push(n),t}bake(r,e){let t=this.r,n=this.flip^=1,o=this.scr[n];(!o||o.width!==t.canvas.width||o.height!==t.canvas.height)&&(o=this.scr[n]=document.createElement("canvas"),o.width=t.canvas.width,o.height=t.canvas.height);let a=o.getContext("2d"),i=t.rx0,l=t.ry0,c=t.rx1-i,u=t.ry1-l;return a.clearRect(i,l,c,u),a.filter=e,a.drawImage(r,i,l,c,u,i,l,c,u),a.filter="none",o}};var Zi=64,on=17,Ji=s=>`${Qr}
49
+ uniform sampler2D uTexture;
50
+ uniform mat4 uM[${s}];
51
+ uniform vec4 uO[${s}];
52
+ uniform int uK;
53
+ varying vec2 vUv;
54
+ varying vec4 vColor;
55
+ void main() {
56
+ vec4 c = texture2D(uTexture, vUv);
57
+ if (c.a > 0.0) c.rgb /= c.a;
58
+ for (int i = 0; i < ${s}; i++) {
59
+ if (i >= uK) break;
60
+ c = clamp(uM[i] * c + uO[i], 0.0, 1.0);
61
+ }
62
+ c.rgb *= c.a;
63
+ gl_FragColor = c * vColor;
64
+ }`,el=()=>`${Qr}
65
+ uniform sampler2D uTexture;
66
+ uniform vec2 uDir;
67
+ uniform vec2 uOff;
68
+ uniform vec2 uTaps[${on}];
69
+ uniform int uN;
70
+ uniform float uMode;
71
+ uniform vec4 uShadow;
72
+ varying vec2 vUv;
73
+ varying vec4 vColor;
74
+ void main() {
75
+ vec2 p = vUv + uOff;
76
+ vec4 c = texture2D(uTexture, p) * uTaps[0].y;
77
+ for (int i = 1; i < ${on}; i++) {
78
+ if (i >= uN) break;
79
+ vec2 d = uDir * uTaps[i].x;
80
+ c += (texture2D(uTexture, p + d) + texture2D(uTexture, p - d)) * uTaps[i].y;
81
+ }
82
+ if (uMode > 0.5) c = uShadow * c.a;
83
+ gl_FragColor = c * vColor;
84
+ }`;function tl(s,r,e=new Float32Array(20)){for(let t=0;t<4;t++)for(let n=0;n<5;n++){let o=n===4?r[t*5+4]:0;for(let a=0;a<4;a++)o+=r[t*5+a]*s[a*5+n];e[t*5+n]=o}return s.set(e),s}var sa=s=>new Jn(s),Jn=class{constructor(r){p(this,"r",r);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(on*2));let e=r.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(r){return this.r.lost?null:(this.userProg(r,!1),this.userErr.get(r)??null)}destroy(){let r=this.r.gl;for(let e of this.scratchT.values())r.deleteTexture(e.gl),r.deleteFramebuffer(e.fb);this.scratchT.clear();for(let e of[this.colorProg,this.blurProg])e&&r.deleteProgram(e.p);for(let e of this.user.values())e.p&&r.deleteProgram(e.p.p);this.user.clear()}userProg(r,e){let t=this.user,n=t.get(r);if(n)return n.t=++this.uses,n.p;if(this.r.lost)return null;if(t.size>=Zi){let a="",i=1/0;for(let[c,u]of t)u.t<i&&(i=u.t,a=c);let l=t.get(a).p;l&&this.r.gl.deleteProgram(l.p),t.delete(a),this.userErr.delete(a)}let o;try{o=this.r.build(r)}catch(a){o=null;let i=a.message;this.userErr.set(r,i),e&&console.error(`[engine] a shader filter does not compile: it is skipped.
85
+ ${i}`)}return t.set(r,{p:o,t:++this.uses}),o}scratch(r,e){let t=this.r,n=Math.ceil(t.canvas.width/r),o=Math.ceil(t.canvas.height/r),a=r*8+e,i=this.scratchT.get(a)??null;return i&&(i.w!==n||i.h!==o)&&(t.drop(i),i=null),i||(i=t.target(n,o,r,!0),i?this.scratchT.set(a,i):this.scratchT.delete(a)),i}pass(r,e,t,n,o=!1){let a=this.r,i=a.gl;a.flush(),a.mapped=!1,a.bindFb(n),i.viewport(0,0,n.w,n.h),o||(i.disable(i.SCISSOR_TEST),i.clearColor(0,0,0,0),i.clear(i.COLOR_BUFFER_BIT)),a.use(r);let l=n.f;i.uniform2f(r.uScale,2/(l*n.w),-2/(l*n.h));let c=Math.floor(a.rx0/l)*l,u=Math.floor(a.ry0/l)*l,f=Math.min(Math.ceil(a.rx1/l),n.w)*l,h=Math.min(Math.ceil(a.ry1/l),n.h)*l,b=1/(t*e.width),y=1/(t*e.height);a.bScis=!1,a.batch.push(c,u,f,u,f,h,c,h,c*b,1-u*y,f*b,1-h*y,4294967295,a.slotOf(e)),a.flush()}post(r){return r==="color"?this.colorProg??(this.colorProg=this.r.build(Ji(this.colorN))):this.blurProg??(this.blurProg=this.r.build(el()))}linear(r,e){let t=this.r,n=t.gl;t.bindTex(t.layerTex.get(r)??null,0);let o=e?n.LINEAR:n.NEAREST;n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MIN_FILTER,o),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MAG_FILTER,o)}chain(r,e,t){let n=this.r,o=this.steps,a=n.scale,i=n.maxBlur,l=0;for(let h=0;h<t.length;h++){let b=t[h];if(b.enabled)if(b.kind===1&&b.toMatrix){(!l||o[l-1]!==null)&&(o[l]=null,(!this.mats[l]||this.mats[l].length<20*this.colorN)&&(this.mats[l]=new Float32Array(20*this.colorN)),this.counts[l]=0,l++);let y=this.mats[l-1],m=this.counts[l-1];if(m<this.colorN)b.toMatrix(this.fm),y.set(this.fm,m*20),this.counts[l-1]=m+1;else{let d=(m-1)*20;for(let x=0;x<20;x++)this.fm2[x]=y[d+x];b.toMatrix(this.fm),tl(this.fm2,this.fm,this.fm3),y.set(this.fm2,d)}}else b.kind===4?this.userProg(b.source,!0)?o[l++]=b:n.skipped++:b.kind===2?Math.min(b.radius,i)*a>=.25&&(o[l++]=b):b.kind===3?o[l++]=b:n.skipped++}if(!l)return!1;let c=n.gl,u=r,f=-1;for(let h=0;h<l;h++){let b=h===l-1,y=f===0?1:0,m=b?null:this.scratch(1,y);if(!b&&!m)break;let d=o[h];if(d===null){let x=this.post("color");n.use(x);let g=this.mats[h],M=this.counts[h],v=this.m16,A=this.o4;for(let E=0;E<M;E++)for(let C=0;C<4;C++){for(let _=0;_<4;_++)v[E*16+_*4+C]=g[E*20+C*5+_];A[E*4+C]=g[E*20+C*5+4]}c.uniformMatrix4fv(n.u(x,"uM"),!1,v),c.uniform4fv(n.u(x,"uO"),A),c.uniform1i(n.u(x,"uK"),M),m?this.pass(x,u,1,m):n.final(x,u,1,e)}else if(d.kind===2)this.blur(u,f<0,Math.min(d.radius,i)*a,m,e,null);else if(d.kind===3){let x=d,g=this.scratch(1,2);if(!g)break;this.blur(u,f<0,Math.max(Math.min(x.blur,i),0)*a,g,1,x);let M=m??(e<1?this.scratch(1,y):null);M?(this.pass(n.main,g.tex,1,M),this.pass(n.main,u,1,M,!0),m||n.final(n.main,M.tex,1,e)):(n.final(n.main,g.tex,1,1),n.final(n.main,u,1,1))}else{let x=d,g=this.userProg(x.source,!0);n.use(g);let M=n.canvas.width,v=n.canvas.height;c.uniform2f(n.u(g,"uResolution"),M,v),c.uniform1f(n.u(g,"uTime"),n.time),c.uniform4f(n.u(g,"uRect"),n.rx0/M,1-n.ry1/v,n.rx1/M,1-n.ry0/v);let A=x.uniforms;for(let E in A){let C=n.u(g,E);if(!C)continue;let _=A[E];typeof _=="number"?c.uniform1f(C,_):_.length===2?c.uniform2fv(C,_):_.length===3?c.uniform3fv(C,_):_.length===4?c.uniform4fv(C,_):_.length===1&&c.uniform1fv(C,_)}m?this.pass(g,u,1,m):n.final(g,u,1,e)}m&&(u=m.tex,f=y)}return n.remap(),!0}blur(r,e,t,n,o,a){let i=this.r,l=i.gl,c=this.post("blur"),u=1;for(;u<16&&t/u>8;)u*=2;e&&this.linear(r,!0);let f=r,h=1,b=Math.sqrt(Math.max(t*t-(u*u-1)/12,0))/u,y=t>=.25?this.tapsFor(b):this.tapsFor(0),m=!0;if(y>1){for(let x=2;x<=u&&m;x*=2){let g=this.scratch(x,0);g?(this.pass(i.main,f,h,g),f=g.tex,h=x):m=!1}let d=m?this.scratch(u,3):null;d&&(i.use(c),l.uniform2fv(i.u(c,"uTaps"),this.taps),l.uniform1i(i.u(c,"uN"),y),l.uniform2f(i.u(c,"uDir"),1/f.width,0),l.uniform2f(i.u(c,"uOff"),0,0),l.uniform1f(i.u(c,"uMode"),0),this.pass(c,f,h,d),f=d.tex)}if(i.use(c),l.uniform2fv(i.u(c,"uTaps"),this.taps),l.uniform1i(i.u(c,"uN"),y),l.uniform2f(i.u(c,"uDir"),0,1/f.height),a){let d=a.opacity,x=a.rgb;l.uniform4f(i.u(c,"uShadow"),(x>>16&255)/255*d,(x>>8&255)/255*d,(x&255)/255*d,d),l.uniform1f(i.u(c,"uMode"),1),l.uniform2f(i.u(c,"uOff"),-a.dx*i.scale/(h*f.width),a.dy*i.scale/(h*f.height))}else l.uniform1f(i.u(c,"uMode"),0),l.uniform2f(i.u(c,"uOff"),0,0);n?this.pass(c,f,h,n):i.final(c,f,h,o),e&&this.linear(r,!1)}tapsFor(r){let e=this.taps;if(e.fill(0),e[1]=1,r<.2)return 1;let t=Math.min(Math.ceil(3*r),(on-1)*2),n=-1/(2*r*r),o=1,a=1;for(let i=1;i<=t;i+=2){let l=Math.exp(i*i*n),c=i+1<=t?Math.exp((i+1)*(i+1)*n):0,u=l+c;e[a*2]=(i*l+(i+1)*c)/u,e[a*2+1]=u,o+=2*u,a++}for(let i=0;i<a;i++)e[i*2+1]=e[i*2+1]/o;return a}};var tt=s=>Math.min(Math.max(s,0),1),Oe=s=>Math.max(s,0),St=class{constructor(){p(this,"enabled",!0);Ae.gl=sa,Ae.c2d=na}},Xe=class extends St{constructor(e){super();p(this,"amount",e);p(this,"kind",1)}params(e,t){return e[t]=this.amount,t+1}};function an(s,r,e){s.fill(0),s[0]=s[6]=s[12]=r,s[4]=s[9]=s[14]=e,s[18]=1}function ln(s,r){s.fill(0);for(let e=0;e<3;e++)for(let t=0;t<3;t++)s[e*5+t]=r[e*3+t];s[18]=1}var O=new Float64Array(9),ts=class extends Xe{toMatrix(r){an(r,Oe(this.amount),0)}css(){return`brightness(${Oe(this.amount)})`}},rs=class extends Xe{toMatrix(r){let e=Oe(this.amount);an(r,e,.5-.5*e)}css(){return`contrast(${Oe(this.amount)})`}},ns=class extends Xe{toMatrix(r){let e=tt(this.amount);an(r,1-2*e,e)}css(){return`invert(${tt(this.amount)})`}},ss=class extends Xe{toMatrix(r){let e=Oe(this.amount);O[0]=.213+.787*e,O[1]=.715-.715*e,O[2]=.072-.072*e,O[3]=.213-.213*e,O[4]=.715+.285*e,O[5]=.072-.072*e,O[6]=.213-.213*e,O[7]=.715-.715*e,O[8]=.072+.928*e,ln(r,O)}css(){return`saturate(${Oe(this.amount)})`}},os=class extends Xe{toMatrix(r){let e=1-tt(this.amount);O[0]=.2126+.7874*e,O[1]=.7152-.7152*e,O[2]=.0722-.0722*e,O[3]=.2126-.2126*e,O[4]=.7152+.2848*e,O[5]=.0722-.0722*e,O[6]=.2126-.2126*e,O[7]=.7152-.7152*e,O[8]=.0722+.9278*e,ln(r,O)}css(){return`grayscale(${tt(this.amount)})`}},as=class extends Xe{toMatrix(r){let e=1-tt(this.amount);O[0]=.393+.607*e,O[1]=.769-.769*e,O[2]=.189-.189*e,O[3]=.349-.349*e,O[4]=.686+.314*e,O[5]=.168-.168*e,O[6]=.272-.272*e,O[7]=.534-.534*e,O[8]=.131+.869*e,ln(r,O)}css(){return`sepia(${tt(this.amount)})`}},is=class extends Xe{get angle(){return this.amount}set angle(r){this.amount=r}toMatrix(r){let e=this.amount*Math.PI/180,t=Math.cos(e),n=Math.sin(e);O[0]=.213+t*.787-n*.213,O[1]=.715-t*.715-n*.715,O[2]=.072-t*.072+n*.928,O[3]=.213-t*.213+n*.143,O[4]=.715+t*.285+n*.14,O[5]=.072-t*.072-n*.283,O[6]=.213-t*.213-n*.787,O[7]=.715-t*.715+n*.715,O[8]=.072+t*.928+n*.072,ln(r,O)}css(){return`hue-rotate(${this.amount}deg)`}},ls=class extends Xe{constructor(e,t){super(t);p(this,"c",16777215);p(this,"cs","");this.color=e}get color(){return this.c}set color(e){this.c=he(e)[0],this.cs=xt(this.c)}params(e,t){return e[t]=this.amount,e[t+1]=this.c,t+2}toMatrix(e){let t=tt(this.amount);an(e,1-t,0),e[4]=(this.c>>16&255)/255*t,e[9]=(this.c>>8&255)/255*t,e[14]=(this.c&255)/255*t}css(){return null}paint2d(e,t,n,o,a){let i=tt(this.amount);i<=0||(e.save(),e.setTransform(1,0,0,1,0,0),e.globalAlpha=i,e.globalCompositeOperation="source-atop",e.fillStyle=this.cs,e.fillRect(t,n,o,a),e.restore())}},cs=class extends St{constructor(e){super();p(this,"kind",1);p(this,"values");if(e.length!==20)throw new Error(`colorMatrix: 20 numbers expected (4 rows of 5), got ${e.length}`);this.values=Array.from(e)}toMatrix(e){for(let t=0;t<20;t++)e[t]=this.values[t]??0}params(e,t){for(let n=0;n<20;n++)e[t+n]=this.values[n]??0;return t+20}css(e,t,n){return n?n(this.values):null}},us=class extends St{constructor(e){super();p(this,"radius",e);p(this,"kind",2)}params(e,t){return e[t]=this.radius,t+1}pad(e){return 3*Math.min(Oe(this.radius),e)}css(e,t){return`blur(${Math.min(Oe(this.radius),t)*e}px)`}},hs=class extends St{constructor(e,t,n,o){super();p(this,"dx",e);p(this,"dy",t);p(this,"blur",n);p(this,"kind",3);p(this,"rgb",0);p(this,"a",1);this.color=o}get opacity(){return this.a}set opacity(e){this.a=tt(e)}get color(){return this.rgb}set color(e){let[t,n]=he(e);this.rgb=t,this.a=n}params(e,t){return e[t]=this.dx,e[t+1]=this.dy,e[t+2]=this.blur,e[t+3]=this.rgb,e[t+4]=this.a,t+5}pad(e){return 3*Math.min(Oe(this.blur),e)+Math.max(Math.abs(this.dx),Math.abs(this.dy))}css(e,t){return`drop-shadow(${this.dx*e}px ${this.dy*e}px ${2*Math.min(Oe(this.blur),t)*e}px ${xt(this.rgb,this.opacity)})`}},rl=`#ifdef GL_FRAGMENT_PRECISION_HIGH
86
+ precision highp float;
87
+ #else
88
+ precision mediump float;
89
+ #endif
90
+ uniform sampler2D uTexture;
91
+ uniform vec2 uResolution;
92
+ uniform float uTime;
93
+ uniform vec4 uRect;
94
+ varying vec2 vUv;
95
+ varying vec4 vColor;
96
+ #define main fabiUserMain
97
+ #line 1
98
+ `,nl=s=>`${rl}${s}
99
+ #undef main
100
+ void main() {
101
+ fabiUserMain();
102
+ gl_FragColor *= vColor.a;
103
+ }
104
+ `,fs=class extends St{constructor(e){super();p(this,"kind",4);p(this,"source");p(this,"uniforms",{});p(this,"padding");this.source=nl(e.fragment),this.padding=e.padding??0;for(let t in e.uniforms??{}){let n=e.uniforms[t];this.uniforms[t]=typeof n=="number"?n:Float32Array.from(n)}}pad(){return Oe(this.padding)}},oa=(s,r=1)=>new ls(s,r),aa=s=>new ts(s),ia=s=>new rs(s),la=s=>new ss(s),ca=(s=1)=>new os(s),ua=(s=1)=>new as(s),ha=s=>new is(s),fa=(s=1)=>new ns(s),pa=s=>new cs(s),da=s=>new us(s),ma=(s,r,e,t="rgba(0,0,0,0.5)")=>new hs(s,r,e,t);function ba(s){let r=new fs(s),e=Ae.live?.filters()?.check(r.source);if(e)throw new Error(`shader(): the fragment does not compile:
105
+ ${e}`);return r}var ps="x y rotation scaleX scaleY alpha visible blend tint z hitRadius clip mask filters".split(" "),xa="frameName _frame _w _h slice autoAnchor".split(" "),sl="fps loop speed onComplete durations".split(" "),ds=["anchorX","anchorY"],ol=[...ps,...xa,...sl,...ds],al=[...ps,...xa,...ds],il=[...ps,...ds],ga=s=>s instanceof Ce?ol:s instanceof Se?al:il;function ll(s){let r={},e=s;for(let t of ga(s))r[t]=e[t];return s instanceof He&&(r.spec=s.spec),s instanceof We&&(r.text=s.text,r.style=s.style),s instanceof Ce&&(r.playing=s.playing),r}function ya(s,r){let e=s;s instanceof He&&s.spec!==r.spec&&(s.spec=r.spec),s instanceof We&&(s.text=r.text,s.style!==r.style&&(e._style=r.style,e.dirty=!0)),s instanceof Ce&&s.gotoFrame(r.speed<0?s.frameCount-1:0);let t=s instanceof He||s instanceof We,n=ga(s);for(let o=0;o<n.length;o++){let a=n[o];(!t||a!=="_frame"&&a!=="frameName")&&(e[a]=r[a])}}var Tr=class{constructor(r,e={}){p(this,"factory",r);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(r){if(this.dead)throw new Error("[engine] nodePool.get() after destroy()");let e=this.free.pop();if(e){this.stats.free--,e._free=!1;let t=this.states.get(e);ya(e,t),e.visible=t.visible,e instanceof Ce&&t.playing&&e.play()}else{if(e=this.factory(),!(e instanceof Fe))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,ll(e)),e._pool=this,this.stats.created++}return this.stats.live++,r&&e.set(r),e}release(r){let e=this.states.get(r);if(!(!e||r.destroyed)&&!r._free){if(this.opts.max!==void 0&&this.free.length>=this.opts.max)return r.destroy();r.parent?.remove(r),r.kernel.tweens.stopAll(r),this.stats.live--,ya(r,e),r instanceof Ce&&r.stop(),r.visible=!1,r._free=!0,this.opts.reset?.(r),this.free.push(r),this.stats.free++}}forget(r){let e=r;if(this.states.delete(e))if(e._free){let t=this.free.indexOf(e);t>=0&&(this.free[t]=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(let r of[...this.states.keys()])r.destroy()}},ka=(s,r)=>new Tr(s,r);window.FabiEngine=ms;})();