@fabi-play/engine 0.4.0 → 0.7.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.
@@ -1,10 +1,10 @@
1
- /*! @fabi-play/engine 0.4.0 (full) | Fabi Play Kit License | https://docs.fabiplay.app */(function(vi,ne){var je=typeof document<"u"?document.currentScript:null;typeof define=="function"&&define.amd?define([],function(){return ne(je)}):typeof module=="object"&&module&&module.exports?module.exports=ne(je):vi.FabiEngine=ne(je)})(typeof globalThis<"u"?globalThis:typeof self<"u"?self:this,function(vi){"use strict";var ne={exports:{}},je=ne.exports,Ve=Object.defineProperty,fr=Object.getOwnPropertyDescriptor,ur=Object.getOwnPropertyNames,dr=Object.prototype.hasOwnProperty,pr=(t,e,s)=>e in t?Ve(t,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[e]=s,yr=(t,e)=>{for(var s in e)Ve(t,s,{get:e[s],enumerable:!0})},mr=(t,e,s,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of ur(e))!dr.call(t,n)&&n!==s&&Ve(t,n,{get:()=>e[n],enumerable:!(i=fr(e,n))||i.enumerable});return t},xr=t=>mr(Ve({},"__esModule",{value:!0}),t),d=(t,e,s)=>pr(t,typeof e!="symbol"?e+"":e,s),Mi={};yr(Mi,{AnimatedSprite:()=>ce,Atlas:()=>Ys,AvatarPainter:()=>oi,AvatarsNode:()=>Qn,BitmapFont:()=>li,DEFAULT_FONT:()=>Rn,EASE:()=>Ie,Group:()=>qs,HALO:()=>He,MAX_LAYERS:()=>Hs,NameTags:()=>ri,Node:()=>le,NodePool:()=>sr,Particles:()=>rn,STAGE_HEIGHT:()=>ft,Shape:()=>Be,ShelfPacker:()=>an,Sound:()=>Bn,Sprite:()=>be,TIERS:()=>qt,Text:()=>Xe,Timeline:()=>Wn,Tweens:()=>Yn,avatarPortrait:()=>uo,blur:()=>xl,brightness:()=>hl,colorMatrix:()=>ml,contrast:()=>cl,createAvatarRenderer:()=>fo,createEngine:()=>No,createRenderer:()=>ii,dropShadow:()=>gl,grayscale:()=>ul,handsOf:()=>On,hits:()=>ci,hueRotate:()=>pl,invert:()=>yl,nodePool:()=>Al,packColor:()=>ge,parseBMFont:()=>ms,parseColor:()=>Ut,pickTier:()=>Un,playerColor:()=>hi,rendererOrder:()=>Cn,rng:()=>va,saturate:()=>fl,sepia:()=>dl,shader:()=>bl,shapeBounds:()=>ai,tier:()=>fe,tint:()=>ll,touching:()=>zn,wrists:()=>In}),ne.exports=xr(Mi);var Ei=33,Z={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},gr=["3-5","6-8","9-12"],br=t=>gr.includes(t),kr=4,Ke=["#EE6A43","#6FA0E0","#8CC9A0","#C49BE0"],Ai={"3-5":["bunny","bear","panda","penguin"],"6-8":["fox","lion","dragon","unicorn"],"9-12":["robot","astronaut","ninja","skater"]},wr=Ai["6-8"],_i=(t,e)=>{const s=br(e)?Ai[e]:wr;return s[Number.isInteger(t)&&t>=0?t%s.length:0]},vr=(t,e)=>t?{x:t.x+e.x*t.w,y:t.y+e.y*t.h}:{x:e.x,y:e.y},Mr=12,Er=Ei*4,Ar=t=>Mr+t*Er,Fl=Ar(kr),_r=t=>t.startsWith("fabi-play.")?`fablee-play.${t.slice(10)}`:null;function Tr(t,e,s=_r(e)){if(!(!t||!s))try{const i=t.getItem(s);if(i===null)return;t.getItem(e)===null&&t.setItem(e,i),t.removeItem(s)}catch{}}var gt="#4a382c",ht="#2b2118",_t="#1c1f2b",Ti="#fbefe3",Rt="#f4897a",Re="#3a2a22",Si=[{id:"fox",name:{en:"Fox",it:"Volpe"},band:"6-8",palette:{body:"#ee6a43",limbs:"#ee6a43",belly:Ti,accent:"#ffd9c2",outline:ht,hands:"#5a3426",feet:"#5a3426"},head:"wide",ears:"pointy",face:{eyes:"dot",mouth:"cat",nose:Re,muzzle:"cheeks"},tail:"fluffy",headExtras:[],bodyExtras:[]},{id:"mascot",name:{en:"Fabi",it:"Fabi"},band:"all",special:!0,palette:{body:"#ee6a43",limbs:"#ee6a43",belly:Ti,accent:"#5a3426",outline:ht,hands:"#5a3426",feet:"#5a3426"},head:"wide",ears:"pointy",face:{eyes:"bead",mouth:"open",nose:Re,muzzle:"band",cheeks:Rt},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:gt},head:"round",ears:"long",face:{eyes:"dot",mouth:"cat",nose:"#e0607e",muzzle:"none",cheeks:Rt},tail:"pom",headExtras:[],bodyExtras:[]},{id:"bear",name:{en:"Bear",it:"Orsetto"},band:"3-5",palette:{body:"#cf9f78",limbs:"#cf9f78",belly:"#f7e0bf",accent:"#f7e0bf",outline:gt},head:"round",ears:"round",face:{eyes:"dot",mouth:"smile",nose:Re,muzzle:"oval",cheeks:Rt},tail:"none",headExtras:[],bodyExtras:[]},{id:"cat",name:{en:"Cat",it:"Gattino"},band:"3-5",palette:{body:"#c8b6ee",limbs:"#c8b6ee",belly:"#f4eeff",accent:"#f7b3c8",outline:gt,hands:"#f4eeff",feet:"#f4eeff"},head:"wide",ears:"pointy",face:{eyes:"big",eyeColor:"#3f9a5a",mouth:"cat",nose:"#f07a9a",muzzle:"none",cheeks:Rt},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:gt,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:gt,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:gt},head:"wide",ears:"none",face:{eyes:"big",eyesOnTop:!0,mouth:"open",muzzle:"none",cheeks:"#f59b8f"},tail:"none",headExtras:[],bodyExtras:["flippers","spots"],extraColors:["#62ad62","#b0e6a4"]},{id:"lion",name:{en:"Lion",it:"Leoncino"},band:"6-8",alsoIn:["3-5"],palette:{body:"#f6c454",limbs:"#f6c454",belly:"#fde7b0",accent:"#fde7b0",outline:ht},head:"round",ears:"round",face:{eyes:"dot",mouth:"cat",nose:"#8a4b2a",muzzle:"oval",cheeks:Rt},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:ht,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:ht},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:_t,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:_t,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:ht},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:ht,hands:"#f2c9a0",feet:"#f2c9a0"},head:"round",ears:"side",face:{eyes:"dot",mouth:"open",nose:"#5a3a26",muzzle:"monkey",cheeks:Rt},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:gt},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:ht},head:"wide",ears:"round",face:{eyes:"dot",mouth:"cat",nose:"#e2607a",muzzle:"oval",cheeks:Rt},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:gt,feet:"#f9b95c",hands:"#639cc9"},head:"tall",ears:"tufts",face:{eyes:"big",eyeColor:gt,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:_t},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:ht},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:ht,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:gt,hands:"#ffc23d",feet:"#ffa04a"},head:"round",ears:"none",face:{eyes:"dot",mouth:"beak",muzzle:"none",cheeks:Rt},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:gt,ears:"#b58262",hands:"#e6caa6",feet:"#e6caa6"},head:"wide",ears:"floppy",face:{eyes:"dot",mouth:"open",nose:Re,muzzle:"oval",cheeks:Rt},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:gt,skin:"#f7dccb",hands:"#a58c7e",feet:"#a58c7e"},head:"round",ears:"droopy",face:{eyes:"dot",mouth:"smile",nose:"#e591a0",muzzle:"none",cheeks:Rt},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:gt,feet:"#ff9f43"},head:"tall",ears:"none",face:{eyes:"dot",mouth:"bill",muzzle:"none",cheeks:Rt},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:ht,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:ht,hands:"#5a647a",feet:"#5a647a"},head:"round",ears:"pointy",face:{eyes:"dot",mouth:"open",nose:Re,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:ht,hands:"#3a9bdc",feet:"#8a7a70"},head:"round",ears:"none",face:{eyes:"big",eyeColor:ht,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:_t,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:_t,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:_t,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:_t,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:_t,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:_t,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:_t,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:_t,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:_t,skin:"#5a3825",hair:"#141010",hands:"#e0403a",feet:"#e0403a"},head:"round",ears:"human",face:{eyes:"calm",mouth:"smirk",muzzle:"none",brows:"#141010"},tail:"none",headExtras:["hair","domino"],bodyExtras:["cape","emblem","boots"],extraColors:["#ffd84a"]},{id:"trex",name:{en:"T-Rex",it:"T-Rex"},band:"6-8",alsoIn:["3-5"],palette:{body:"#6cb84e",limbs:"#6cb84e",belly:"#f4e8a8",accent:"#f4e8a8",outline:ht},head:"snout-long",ears:"none",face:{eyes:"dot",mouth:"toothy",muzzle:"none",cheeks:"#f59b8f"},tail:"thick",headExtras:["stripes"],bodyExtras:["tiny-arms","strong-legs"],extraColors:["#4a9235","#58a23f"]},{id:"fairy",name:{en:"Fairy",it:"Fatina"},band:"6-8",alsoIn:["3-5"],palette:{body:"#b99af0",limbs:"#a8693f",belly:"#b99af0",accent:"#ffd84a",outline:ht,skin:"#a8693f",hair:"#2e1d17",hands:"#a8693f",feet:"#f58cbc"},head:"round",ears:"pixie",face:{eyes:"dot",mouth:"smile",muzzle:"none",cheeks:"#f0857a"},tail:"none",headExtras:["bun","flower-crown"],bodyExtras:["wings-fairy","petals","wand"],extraColors:["#c4ecff","#f7a8cf","#fff3a0","#ffffff"]}],rt={M:0,L:1,Q:2,C:3,Z:4},Ci=[2,2,4,6,0];function Rs(t,e){for(const s of e)Sr(t,s)}function Sr(t,e){if(e.k==="group"){t.save(),t.translate(e.x,e.y),e.rot&&t.rotate(e.rot),e.s!==void 0&&e.s!==1&&t.scale(e.s,e.s),e.alpha!==void 0&&(t.globalAlpha*=e.alpha),Rs(t,e.items),t.restore();return}switch(t.save(),e.alpha!==void 0&&(t.globalAlpha*=e.alpha),t.beginPath(),e.k){case"circle":t.arc(e.x,e.y,Math.max(e.r,0),0,Math.PI*2);break;case"ellipse":t.ellipse(e.x,e.y,Math.max(e.rx,0),Math.max(e.ry,0),e.rot??0,0,Math.PI*2);break;case"rect":Cr(t,e);break;case"path":typeof e.d=="string"?Pr(t,e.d):Rr(t,e.d);break;case"line":t.moveTo(e.pts[0]??0,e.pts[1]??0);for(let s=2;s+1<e.pts.length;s+=2)t.lineTo(e.pts[s],e.pts[s+1]);break}t.lineCap="round",t.lineJoin="round",e.fill&&e.k!=="line"&&(t.fillStyle=e.fill,t.fill()),e.stroke&&(e.lw??1)>0&&(t.strokeStyle=e.stroke,t.lineWidth=e.lw??1,t.stroke()),t.restore()}function Cr(t,e){const s=Math.max(0,Math.min(e.r,e.w/2,e.h/2));t.translate(e.x,e.y),e.rot&&t.rotate(e.rot);const i=-e.w/2,n=-e.h/2;t.moveTo(i+s,n),t.lineTo(i+e.w-s,n),t.quadraticCurveTo(i+e.w,n,i+e.w,n+s),t.lineTo(i+e.w,n+e.h-s),t.quadraticCurveTo(i+e.w,n+e.h,i+e.w-s,n+e.h),t.lineTo(i+s,n+e.h),t.quadraticCurveTo(i,n+e.h,i,n+e.h-s),t.lineTo(i,n+s),t.quadraticCurveTo(i,n,i+s,n),t.closePath()}function Rr(t,e){for(let s=0;s<e.length;){const i=e[s++];if(i===rt.M)t.moveTo(e[s],e[s+1]);else if(i===rt.L)t.lineTo(e[s],e[s+1]);else if(i===rt.Q)t.quadraticCurveTo(e[s],e[s+1],e[s+2],e[s+3]);else if(i===rt.C)t.bezierCurveTo(e[s],e[s+1],e[s+2],e[s+3],e[s+4],e[s+5]);else if(i===rt.Z)t.closePath();else return;s+=Ci[i]}}function Fr(t){if(typeof t=="string")return(t.match(/-?\d*\.?\d+(?:e-?\d+)?/gi)??[]).map(Number);const e=[];for(let s=0;s<t.length;){const i=Ci[t[s++]];if(i===void 0)break;for(let n=0;n<i;n++)e.push(t[s+n]);s+=i}return e}function Pr(t,e){const s=e.match(/[MLQCZ]|-?\d*\.?\d+(?:e-?\d+)?/gi)??[];let i="",n=0;const r=()=>Number(s[n++]);for(;n<s.length;){const a=s[n];if(/[MLQCZ]/i.test(a)&&(i=a.toUpperCase(),n++,i==="Z")){t.closePath();continue}i==="M"?(t.moveTo(r(),r()),i="L"):i==="L"?t.lineTo(r(),r()):i==="Q"?t.quadraticCurveTo(r(),r(),r(),r()):i==="C"?t.bezierCurveTo(r(),r(),r(),r(),r(),r()):n++}}var V=t=>{const e=Math.round(t*100)/100;return e===0?0:e};function J(t,e=.5){const s=t.length;if(s<3)return[];const i=(l,h,o)=>({x:l.x+(h.x-l.x)*o,y:l.y+(h.y-l.y)*o}),n=Math.min(Math.max(e,0),.5),r=i(t[0],t[1],n),a=[rt.M,V(r.x),V(r.y)];for(let l=1;l<=s;l++){const h=t[(l-1)%s],o=t[l%s],f=t[(l+1)%s],u=i(h,o,1-n),c=i(o,f,n);a.push(rt.L,V(u.x),V(u.y),rt.Q,V(o.x),V(o.y),V(c.x),V(c.y))}return a.push(rt.Z),a}function K(t,e=1){const s=t.length;if(s<3)return[];const i=[rt.M,V(t[0].x),V(t[0].y)],n=e/6;for(let r=0;r<s;r++){const a=t[(r-1+s)%s],l=t[r],h=t[(r+1)%s],o=t[(r+2)%s];i.push(rt.C,V(l.x+(h.x-a.x)*n),V(l.y+(h.y-a.y)*n),V(h.x-(o.x-l.x)*n),V(h.y-(o.y-l.y)*n),V(h.x),V(h.y))}return i.push(rt.Z),i}function Fe(t){const e=t.length;if(e<2)return[];const s=[rt.M,V(t[0].x),V(t[0].y)];for(let i=0;i<e-1;i++){const n=t[Math.max(i-1,0)],r=t[i],a=t[i+1],l=t[Math.min(i+2,e-1)];s.push(rt.C,V(r.x+(a.x-n.x)/6),V(r.y+(a.y-n.y)/6),V(a.x-(l.x-r.x)/6),V(a.y-(l.y-r.y)/6),V(a.x),V(a.y))}return s}var me="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",at="#ffffff",$=[-1,1],Ri="#3a2420",Fi="#f2808f",Fs="#26324a",Lr="#ffd84a",st=(...t)=>{const e=[];for(let s=0;s+1<t.length;s+=2)e.push({x:t[s],y:t[s+1]});return e};function Pi(t,e){const s=t.palette,i=[],n={stroke:s.outline,lw:e},r=f=>t.headExtras.includes(f),a=(f,u)=>t.extraColors?.[f]??u;if(r("mane")){for(let u=0;u<12;u++){const c=u/12*Math.PI*2;i.push({k:"circle",x:Math.cos(c)*1.02,y:Math.sin(c)*1+.04,r:.42,fill:a(0,s.accent),...n})}i.push({k:"circle",x:0,y:.04,r:1.08,fill:a(0,s.accent)})}if(r("rainbow-mane")){const f=t.extraColors??["#f59ac0","#fbd46a","#8fd3f4"];[[.98,.05,.3,.5,-.25],[.92,.58,.26,.42,-.1],[.62,.92,.22,.32,.4]].forEach(([c,y,p,x,m],g)=>i.push({k:"ellipse",x:c,y,rx:p,ry:x,rot:m,fill:f[g%f.length],...n}))}if(r("spikes"))for(const f of[-.55,0,.55]){const u=re(f,1.48),c=re(f-.32,.86),y=re(f+.32,.86);i.push({k:"path",d:J([c,u,y],.22),fill:s.accent,...n})}if(r("curl")&&i.push({k:"path",d:K([{x:-.2,y:-.9},{x:-.05,y:-1.3},{x:.32,y:-1.42},{x:.16,y:-1.18},{x:.2,y:-.9}]),fill:s.body,...n}),r("wool"))for(let f=0;f<=8;f++){const u=-1.75+f/8*3.5;i.push({k:"circle",x:Math.sin(u)*.98,y:-Math.cos(u)*.92-.04,r:.34,fill:s.body,...n})}if(r("crest")&&[-.38,0,.38].forEach((f,u)=>{const c=re(f,1.12);i.push({k:"ellipse",x:c.x,y:c.y,rx:.15,ry:.42,rot:f,fill:a(u,s.accent),...n})}),r("plume")&&i.push({k:"path",d:K(st(-.12,-.92,-.2,-1.42,.1,-1.78,.62,-1.74,.36,-1.46,.16,-.98)),fill:s.accent,...n}),r("locks")&&i.push({k:"path",d:K(st(-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:s.hair??s.outline,...n}),r("bun")&&i.push({k:"circle",x:.04,y:-1.14,r:.4,fill:s.hair??s.outline,...n}),r("ninja-hood"))for(const[f,u]of[[.35,.5],[.85,.42]])i.push({k:"ellipse",x:1+Math.cos(f)*u*.8,y:-.5+Math.sin(f)*u*.8,rx:u,ry:.11,rot:f,fill:s.accent,...n});if(r("bandana"))for(const[f,u]of[[Math.PI-.5,.42],[Math.PI-1,.36]])i.push({k:"ellipse",x:-.98+Math.cos(f)*u*.8,y:-.36+Math.sin(f)*u*.8,rx:u,ry:.12,rot:f,fill:s.accent,...n});if(r("ruff"))for(const f of $)i.push({k:"path",d:J(st(f*.7,-.3,f*1.32,0,f*1.02,.18,f*1.26,.46,f*.86,.56,f*.98,.84,f*.4,.7),.25),fill:s.body,...n});if(t.face.eyesOnTop)for(const f of $)i.push({k:"circle",x:f*.46,y:-.72,r:.38,fill:s.body,...n});i.push(...Br(t,e)),i.push(Nr(t,n));const l=t.face.muzzle,h=s.belly;if(l==="oval"&&i.push({k:"ellipse",x:0,y:.4,rx:.46,ry:.32,fill:h}),l==="monkey"){for(const f of $)i.push({k:"circle",x:f*.32,y:-.04,r:.38,fill:h});i.push({k:"ellipse",x:0,y:.4,rx:.56,ry:.4,fill:h})}if(l==="heart"){for(const f of $)i.push({k:"circle",x:f*.36,y:.02,r:.5,fill:h});i.push({k:"ellipse",x:0,y:.38,rx:.66,ry:.48,fill:h})}if(l==="disc")for(const f of $)i.push({k:"circle",x:f*.4,y:.02,r:.44,fill:h});if(l==="cheeks")for(const f of $)i.push({k:"ellipse",x:f*.4,y:.44,rx:.44,ry:.32,fill:h});if(l==="band"&&i.push({k:"path",d:Dr(t,e),fill:h}),r("stripes")&&t.head==="snout-long"){const f=a(0,s.outline);for(const[u,c,y,p]of[[.46,-.94,.36,-.66],[.8,-.72,.62,-.5],[1,-.36,.78,-.24]])i.push({k:"line",pts:[u,c,y,p],stroke:f,lw:.11})}else if(r("stripes")){const f=a(0,s.outline);i.push({k:"line",pts:[0,-.97,0,-.66],stroke:f,lw:.13});for(const u of $)i.push({k:"line",pts:[u*.3,-.93,u*.24,-.7],stroke:f,lw:.1}),i.push({k:"line",pts:[u*.98,-.05,u*.74,0],stroke:f,lw:.1}),i.push({k:"line",pts:[u*.94,.22,u*.74,.22],stroke:f,lw:.09})}if(r("spots")){const f=a(1,s.belly);i.push({k:"circle",x:-.55,y:-.5,r:.15,fill:f}),i.push({k:"circle",x:.58,y:-.42,r:.11,fill:f}),i.push({k:"circle",x:.22,y:-.76,r:.09,fill:f})}if(t.head==="snout-long")for(const[f,u,c]of[[-1.38,-.14,.06],[-1.14,-.22,.055]])i.push({k:"ellipse",x:f,y:u,rx:c,ry:c*.8,rot:-.3,fill:s.outline,alpha:.85});if(r("forehead")&&i.push({k:"path",d:K(st(-.62,-.66,0,-.86,.62,-.66,.26,-.36,0,-.1,-.26,-.36),.9),fill:a(0,s.accent)}),r("eye-spot")&&i.push({k:"ellipse",x:.42,y:-.06,rx:.3,ry:.33,rot:.3,fill:s.ears??s.accent}),r("gills"))for(const f of $)for(const u of[0,.12,.24])i.push({k:"path",d:`M${f*(.66+u)} 0.06 Q${f*(.6+u)} 0.22 ${f*(.66+u)} 0.38`,stroke:s.accent,lw:e*.9});const o=s.hair??s.outline;if(r("hair")&&i.push({k:"path",d:K(st(-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:o,...n}),r("locks")&&i.push({k:"path",d:K(st(-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:o,...n}),r("bun")&&i.push({k:"path",d:K(st(-1.02,-.1,-.98,-.62,-.56,-1.02,0,-1.1,.56,-1.02,.98,-.62,1.02,-.1,.84,-.36,.5,-.56,.12,-.48,-.22,-.6,-.6,-.5,-.86,-.36)),fill:o,...n}),r("curls")){for(let f=0;f<7;f++){const u=re(-1.3+f/6*2.6,.86);i.push({k:"circle",x:u.x,y:u.y,r:.3,fill:o,...n})}i.push({k:"ellipse",x:0,y:-.64,rx:.8,ry:.36,fill:o})}if(r("ninja-hood")&&(i.push({k:"rect",x:0,y:0,w:1.56,h:.6,r:.28,fill:s.skin??at,stroke:s.outline,lw:e*.8}),i.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:s.accent,...n})),r("domino")){i.push({k:"path",d:K(st(-.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:s.accent,...n});for(const f of $)i.push({k:"ellipse",x:f*.38,y:0,rx:.19,ry:.13,fill:at})}if(i.push(...Ur(t,e)),r("brows"))for(const f of $)i.push({k:"line",pts:[f*.72,-.5,f*.14,-.3],stroke:s.accent,lw:.16});if(t.face.brows)for(const f of $)i.push({k:"line",pts:[f*.2,-.2,f*.54,-.28],stroke:t.face.brows,lw:.09});if(i.push(...Gr(t,e)),t.face.cheeks)for(const f of Or(t))i.push({k:"ellipse",x:f.x,y:f.y,rx:.15,ry:.1,fill:t.face.cheeks,alpha:.8});if(r("whiskers"))for(const f of $)for(const u of[-.1,.06])i.push({k:"line",pts:[f*.62,.38+u,f*1.06,.3+u*2.2],stroke:s.outline,lw:e*.7,alpha:.75});if(r("rainbow-mane")){const f=t.extraColors??["#f59ac0","#fbd46a","#8fd3f4"];i.push({k:"ellipse",x:.42,y:-.82,rx:.34,ry:.22,rot:.5,fill:f[0],...n}),i.push({k:"ellipse",x:.1,y:-.92,rx:.3,ry:.2,rot:.25,fill:f[1%f.length],...n})}if(t.ears==="unicorn"){const f=[{x:-.18,y:-.84},{x:.02,y:-1.72},{x:.18,y:-.84}];i.push({k:"path",d:J(f,.12),fill:s.accent,...n});for(const u of[-1,-1.2,-1.4]){const c=.16*((u+1.72)/.88);i.push({k:"line",pts:[-c,u+.04,c,u-.04],stroke:s.outline,lw:e*.7,alpha:.6})}}if(r("flower-crown")){const f=[a(1,"#f7a8cf"),a(2,"#fff3a0"),a(3,at)];for(const u of[-.84,-.28,.28,.84]){const c=re(u,.9);i.push({k:"ellipse",x:c.x,y:c.y,rx:.14,ry:.07,rot:u+.5,fill:"#7cc76a",stroke:s.outline,lw:e*.7})}[-1.12,-.56,0,.56,1.12].forEach((u,c)=>{const y=re(u,.9),p=c===2?.13:.11;for(let x=0;x<5;x++){const m=u+x/5*Math.PI*2;i.push({k:"circle",x:y.x+Math.sin(m)*p,y:y.y-Math.cos(m)*p,r:p*.82,fill:f[c%f.length],stroke:s.outline,lw:e*.7})}i.push({k:"circle",x:y.x,y:y.y,r:p*.62,fill:f[c%f.length]}),i.push({k:"circle",x:y.x,y:y.y,r:p*.42,fill:s.accent})})}if(r("helmet")){for(const f of $)i.push({k:"rect",x:f*1,y:.05,w:.26,h:.56,r:.12,fill:s.accent,...n});i.push({k:"path",d:"M-0.62 -0.62 Q-0.3 -0.92 0.12 -0.9",stroke:at,lw:.1,alpha:.9})}if(r("bolts"))for(const f of $)i.push({k:"rect",x:f*1.08,y:.08,w:.2,h:.44,r:.08,fill:s.accent,...n});if(r("tuft")&&i.push({k:"path",d:K([{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:s.body,...n}),r("eggshell")&&i.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,at),...n}),r("wool"))for(const[f,u]of[[-.36,-.84],[.02,-.94],[.4,-.82]])i.push({k:"circle",x:f,y:u,r:.27,fill:s.body,...n});if(r("stripe")&&i.push({k:"rect",x:0,y:-.64,w:.38,h:.62,r:.06,fill:s.accent}),r("eye-patch")&&(i.push({k:"line",pts:[-.97,-.5,.97,.13],stroke:s.outline,lw:.07}),i.push({k:"ellipse",x:.38,y:.02,rx:.21,ry:.19,fill:s.outline})),r("bandana")){i.push({k:"path",d:K(st(-1.05,-.22,-.96,-.72,-.5,-1.08,.1,-1.14,.72,-.96,1.04,-.56,1.05,-.22,.5,-.46,-.5,-.46)),fill:s.accent,...n});for(const[f,u]of[[-.5,-.8],[.08,-.92],[.6,-.74],[-.12,-.62],[.36,-.6]])i.push({k:"circle",x:f,y:u,r:.06,fill:at,alpha:.85});i.push({k:"circle",x:-.98,y:-.34,r:.15,fill:s.accent,...n})}if(r("cap")){for(const f of $)i.push({k:"line",pts:[f*.98,-.2,f*.5,.82,-f*.05,.98],stroke:s.outline,lw:.06});i.push({k:"path",d:K(st(-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:s.accent,...n}),i.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:s.accent,...n}),i.push({k:"circle",x:.5,y:-.82,r:.15,fill:a(0,at),...n});for(const f of[-.42,-.14])i.push({k:"line",pts:[f,-1.04,f+.02,-.78],stroke:s.outline,lw:.07,alpha:.7})}if(r("safari-hat")&&(i.push({k:"ellipse",x:0,y:-.56,rx:1.48,ry:.3,fill:s.accent,...n}),i.push({k:"path",d:K(st(-.78,-.58,-.7,-1.1,-.3,-1.38,.3,-1.38,.7,-1.1,.78,-.58,0,-.5),.8),fill:s.accent,...n}),i.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,s.outline),stroke:s.outline,lw:e*.8})),r("wizard-hat")){i.push({k:"ellipse",x:0,y:-.62,rx:1.32,ry:.26,fill:s.accent,...n}),i.push({k:"path",d:J(st(-.8,-.66,-.36,-1.5,.5,-2.2,.3,-1.46,.8,-.66),.3),fill:s.accent,...n});const f=a(0,Lr);for(const[u,c,y]of[[.02,-1.08,.18],[-.38,-.84,.1],[.36,-1.5,.11]])i.push({k:"group",x:u,y:c,s:y,items:[{k:"path",d:me,fill:f}]})}if(r("dive-mask")){for(const u of $)i.push({k:"line",pts:[u*.7,-.04,u*1,-.12],stroke:s.outline,lw:.2},{k:"line",pts:[u*.7,-.04,u*1,-.12],stroke:s.accent,lw:.11});i.push({k:"rect",x:0,y:0,w:1.42,h:.62,r:.28,fill:"#bfe9f5",alpha:.35}),i.push({k:"rect",x:0,y:0,w:1.42,h:.62,r:.28,stroke:s.outline,lw:.2}),i.push({k:"rect",x:0,y:0,w:1.42,h:.62,r:.28,stroke:s.accent,lw:.11}),i.push({k:"path",d:"M-0.5 -0.16 Q-0.4 -0.24 -0.22 -0.24",stroke:at,lw:.06,alpha:.9});const f="M0.5 0.52 Q0.98 0.56 1.04 0.1 L1.12 -0.92";i.push({k:"path",d:f,stroke:s.outline,lw:.24},{k:"path",d:f,stroke:s.accent,lw:.13})}return i}function Nr(t,e){const s=t.headExtras.includes("ninja-hood")?t.palette.body:t.palette.skin??t.palette.body;switch(t.head){case"round":return{k:"circle",x:0,y:0,r:1,fill:s,...e};case"wide":return{k:"ellipse",x:0,y:.03,rx:1.12,ry:.94,fill:s,...e};case"tall":return{k:"ellipse",x:0,y:-.02,rx:.94,ry:1.04,fill:s,...e};case"square":return{k:"rect",x:0,y:0,w:2,h:1.8,r:.46,fill:s,...e};case"bucket":return{k:"path",d:J(st(-.94,.96,-.98,-.36,-.62,-1.04,.62,-1.04,.98,-.36,.94,.96),.42),fill:s,...e};case"snout-long":return{k:"path",d:K(Ir,.95),fill:s,...e};case"bulb":return{k:"path",d:K([{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:s,...e}}}var Ir=st(.7,-.88,.12,-1.04,-.3,-.98,-.72,-.74,-1.2,-.56,-1.5,-.32,-1.6,.04,-1.44,.42,-.9,.72,-.2,.92,.5,.88,.96,.56,1.08,0,.98,-.5);function Li(t,e,s){return t.head==="snout-long"?[{x:-.36,y:-.5,k:.95},{x:.26,y:-.48,k:1.1}]:$.map(i=>({x:i*e,y:s,k:1}))}function Or(t){return t.head==="snout-long"?st(-.66,-.14,.66,.1):$.map(e=>({x:e*.64,y:.3}))}function zr(t){return t.head==="round"?{cy:0,rx:1,ry:1}:t.head==="tall"?{cy:-.02,rx:.94,ry:1.04}:{cy:.03,rx:1.12,ry:.94}}function Dr(t,e){const{cy:s,rx:i,ry:n}=zr(t),r=i-e/2,a=n-e/2,l=.15,h=Math.asin(Math.min(1,(l-s)/a)),o=Math.cos(h)*r,f=p=>Math.round(p*100)/100||0,u=[rt.M,f(-o),l],c=[[-.84*o,.02,-.53*o,.06,-.32*o,.24],[-.17*o,.11,.17*o,.11,.32*o,.24],[.53*o,.06,.84*o,.02,o,l]];for(const p of c)u.push(rt.C,...p.map(f));const y=24;for(let p=1;p<=y;p++){const x=h+(Math.PI-2*h)*p/y;u.push(rt.L,f(Math.cos(x)*r),f(s+Math.sin(x)*a))}return u.push(rt.Z),u}function Br(t,e){const s=t.palette,i={stroke:s.outline,lw:e},n=[];for(const r of $)switch(t.ears){case"pointy":case"unicorn":{const a=t.ears==="unicorn"?.8:1,l={x:r*.3,y:-.82},h={x:r*.86,y:-.82-.62*a},o={x:r*.94,y:-.36};n.push({k:"path",d:J([l,h,o],.2),fill:s.body,...i});const f={x:(l.x+h.x+o.x)/3,y:(l.y+h.y+o.y)/3},u=[l,h,o].map(c=>({x:f.x+(c.x-f.x)*.55,y:f.y+(c.y-f.y)*.55+.04}));n.push({k:"path",d:J(u,.25),fill:s.accent});break}case"round":n.push({k:"circle",x:r*.72,y:-.72,r:.36,fill:s.ears??s.body,...i}),s.ears||n.push({k:"circle",x:r*.74,y:-.74,r:.19,fill:s.accent});break;case"big-round":n.push({k:"circle",x:r*.96,y:-.46,r:.52,fill:s.body,...i}),n.push({k:"circle",x:r*1,y:-.44,r:.32,fill:s.accent});break;case"long":n.push({k:"ellipse",x:r*.38,y:-1.42,rx:.25,ry:.68,rot:r*.14,fill:s.body,...i}),n.push({k:"ellipse",x:r*.39,y:-1.36,rx:.12,ry:.48,rot:r*.14,fill:s.accent});break;case"side":n.push({k:"circle",x:r*1,y:.02,r:.34,fill:s.body,...i}),n.push({k:"circle",x:r*1.02,y:.02,r:.2,fill:s.belly});break;case"tufts":n.push({k:"path",d:J([{x:r*.3,y:-.84},{x:r*1.22,y:-1.12},{x:r*.92,y:-.42}],.16),fill:s.body,...i}),n.push({k:"line",pts:[r*.62,-.78,r*1,-.98],stroke:s.accent,lw:.08});break;case"antennae":{const a={x:r*.62,y:-1.42};n.push({k:"path",d:`M${r*.3} -0.8 Q${r*.36} -1.2 ${a.x} ${a.y}`,stroke:s.outline,lw:e*2.6}),n.push({k:"path",d:`M${r*.3} -0.8 Q${r*.36} -1.2 ${a.x} ${a.y}`,stroke:s.body,lw:e*1.2}),n.push({k:"circle",x:a.x,y:a.y,r:.17,fill:s.accent,...i});break}case"floppy":n.push({k:"ellipse",x:r*.96,y:.02,rx:.3,ry:.62,rot:-r*.36,fill:s.ears??s.body,...i});break;case"droopy":n.push({k:"ellipse",x:r*1.04,y:-.22,rx:.4,ry:.18,rot:r*.32,fill:s.skin??s.body,...i}),n.push({k:"ellipse",x:r*1.08,y:-.2,rx:.24,ry:.08,rot:r*.32,fill:s.accent});break;case"pixie":n.push({k:"path",d:J(st(r*.86,-.22,r*1.36,-.5,r*1.02,.26),.28),fill:s.skin??s.body,...i}),n.push({k:"line",pts:[r*.98,-.12,r*1.16,-.3],stroke:s.accent,lw:e*.8,alpha:.5});break;case"human":n.push({k:"ellipse",x:r*.98,y:.06,rx:.17,ry:.23,fill:s.skin??s.body,...i});break;case"horns":{const a=[{x:r*.3,y:-.84},{x:r*.6,y:-1.5},{x:r*.66,y:-.68}];n.push({k:"path",d:J(a,.18),fill:s.accent,...i});break}}return t.ears==="fin"&&n.push({k:"path",d:J(st(-.4,-.82,.2,-1.62,.46,-.78),.2),fill:s.body,...i}),t.ears==="antenna"&&(n.push({k:"line",pts:[0,-.85,0,-1.42],stroke:s.outline,lw:e*2.6}),n.push({k:"line",pts:[0,-.85,0,-1.42],stroke:s.limbs,lw:e*1.2}),n.push({k:"circle",x:0,y:-1.5,r:.18,fill:s.accent,...i})),n}function Ur(t,e){const s=t.palette,i=t.face,n=[],r=s.outline,a=i.eyesOnTop?.46:.4,l=i.eyesOnTop?-.72:-.04,h=(o,f,u)=>({k:"circle",x:o,y:f,r:u,fill:at});switch(i.eyes){case"dot":for(const o of Li(t,a,l))n.push({k:"ellipse",x:o.x,y:o.y,rx:.12*o.k,ry:.155*o.k,fill:r}),n.push(h(o.x+.04*o.k,o.y-.06*o.k,.045*o.k));break;case"bead":for(const o of Li(t,a,l))n.push({k:"ellipse",x:o.x,y:o.y,rx:.16*o.k,ry:.22*o.k,fill:r}),n.push(h(o.x+.05*o.k,o.y-.08*o.k,.065*o.k));break;case"big":for(const o of $)i.eyeRing&&n.push({k:"circle",x:o*a,y:l,r:.36,fill:i.eyeRing,stroke:r,lw:e*.8}),n.push({k:"circle",x:o*a,y:l,r:.25,fill:at,stroke:r,lw:e*.8}),n.push({k:"circle",x:o*a+o*-.03,y:l+.03,r:.14,fill:i.eyeColor??r}),n.push(h(o*a+o*-.03+.05,l-.03,.05));break;case"mask":for(const o of $)n.push({k:"ellipse",x:o*.4,y:0,rx:.24,ry:.32,rot:o*-.55,fill:s.limbs}),n.push({k:"circle",x:o*.4,y:-.02,r:.11,fill:at}),n.push({k:"circle",x:o*.39,y:-0,r:.065,fill:r});break;case"screen":n.push({k:"rect",x:0,y:0,w:1.5,h:.66,r:.26,fill:"#24323d",stroke:r,lw:e*.8});for(const o of $)n.push({k:"ellipse",x:o*.36,y:0,rx:.2,ry:.24,fill:i.eyeColor??"#7ff0ff",alpha:.3}),n.push({k:"ellipse",x:o*.36,y:0,rx:.12,ry:.16,fill:i.eyeColor??"#7ff0ff"});break;case"almond":for(const o of $)n.push({k:"ellipse",x:o*.42,y:-.02,rx:.3,ry:.2,rot:-o*.5,fill:i.eyeColor??r}),n.push(h(o*.42-o*.07,-.08,.07));break;case"calm":for(const o of $)n.push({k:"ellipse",x:o*.38,y:.02,rx:.085,ry:.12,fill:r}),n.push(h(o*.38+.03,-.02,.03));break;case"slit":n.push({k:"line",pts:[0,-.98,0,-.2],stroke:r,lw:e*.8,alpha:.5}),n.push({k:"rect",x:0,y:-.04,w:1.56,h:.26,r:.1,fill:Fs,stroke:r,lw:e*.8}),n.push({k:"rect",x:0,y:.3,w:.22,h:.46,r:.08,fill:Fs,stroke:r,lw:e*.8});for(const o of $){n.push({k:"ellipse",x:o*.4,y:-.04,rx:.12,ry:.07,fill:i.eyeColor??at});for(const f of[.36,.56])n.push({k:"circle",x:o*.42,y:f,r:.05,fill:r,alpha:.6})}break;case"goggle":for(const o of $)n.push({k:"circle",x:o*.9,y:0,r:.13,fill:s.accent,stroke:r,lw:e*.8});n.push({k:"rect",x:0,y:0,w:1.66,h:.62,r:.3,fill:Fs,stroke:r,lw:e*.8}),n.push({k:"path",d:"M-0.6 -0.16 Q-0.42 -0.24 -0.12 -0.24",stroke:at,lw:.07,alpha:.8});for(const o of $)n.push({k:"path",d:`M${o*.5} 0.04 Q${o*.34} -0.08 ${o*.16} 0.02`,stroke:i.eyeColor??"#7fd6ff",lw:.08});for(const o of[-.18,0,.18])n.push({k:"line",pts:[o,.56,o,.72],stroke:r,lw:e*.8,alpha:.6});break;case"visor":n.push({k:"ellipse",x:0,y:.08,rx:.8,ry:.64,fill:"#2a3f6b",stroke:r,lw:e*.8}),n.push({k:"path",d:"M-0.56 -0.14 Q-0.46 -0.4 -0.16 -0.46",stroke:at,lw:.08,alpha:.7});for(const o of $)n.push({k:"ellipse",x:o*.28,y:.04,rx:.1,ry:.14,fill:i.eyeColor??"#cfeeff"});break}return n}function Gr(t,e){const s=t.palette,i=t.face,n=[],r=i.eyes==="visor"?"#cfeeff":Ri,a=e*1.05;switch(i.nose&&i.mouth!=="beak"&&(i.mouth==="cat"?n.push({k:"path",d:J([{x:-.1,y:.22},{x:.1,y:.22},{x:0,y:.33}],.3),fill:i.nose,stroke:i.nose,lw:e*.6}):t.ears==="big-round"?n.push({k:"ellipse",x:0,y:.22,rx:.2,ry:.25,fill:i.nose}):n.push({k:"ellipse",x:0,y:.25,rx:.13,ry:.085,fill:i.nose})),i.mouth){case"smile":n.push({k:"path",d:i.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:r,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:r,stroke:r,lw:e*.5}),n.push({k:"ellipse",x:0,y:.6,rx:.1,ry:.06,fill:Fi});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:r,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:s.accent,stroke:s.outline,lw:e*.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:r,stroke:r,lw:e*.5});for(const l of $)n.push({k:"rect",x:l*.12,y:.43,w:.1,h:.1,r:.03,fill:at});break;case"grill":n.push({k:"rect",x:0,y:.56,w:.62,h:.2,r:.08,fill:"#24323d",stroke:s.outline,lw:e*.7});for(const l of[-.15,0,.15])n.push({k:"line",pts:[l,.51,l,.61],stroke:"#9fb0bd",lw:e*.6});break;case"tiny":n.push({k:"ellipse",x:0,y:.44,rx:.08,ry:.1,fill:r});break;case"smirk":n.push({k:"path",d:"M-0.16 0.46 Q0.06 0.54 0.22 0.38",stroke:r,lw:a});break;case"bill":n.push({k:"ellipse",x:0,y:.36,rx:.44,ry:.2,fill:s.accent,stroke:s.outline,lw:e*.8}),n.push({k:"path",d:"M-0.36 0.38 Q0 0.46 0.36 0.38",stroke:s.outline,lw:e*.7});for(const l of $)n.push({k:"circle",x:l*.1,y:.28,r:.03,fill:s.outline});break;case"hook":n.push({k:"ellipse",x:0,y:.48,rx:.16,ry:.11,fill:Ri}),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:s.accent,stroke:s.outline,lw:e*.8});break;case"toothy":{n.push({k:"path",d:"M-1.4 0.1 Q-0.5 0.36 0.5 0.2 Q0.64 0.16 0.68 0.02 Q0.78 0.28 0.52 0.38 Q-0.4 0.78 -1.3 0.26 Z",fill:r,stroke:r,lw:e*.6}),n.push({k:"ellipse",x:-.38,y:.5,rx:.24,ry:.08,fill:Fi});for(const l of[.12,.27,.42,.57,.72,.86]){const h=(1-l)*(1-l)*-1.4+2*(1-l)*l*-.5+l*l*.5,o=(1-l)*(1-l)*.1+2*(1-l)*l*.36+l*l*.2-.01;n.push({k:"path",d:J(st(h-.08,o,h+.08,o,h,o+.14),.3),fill:at})}for(const l of[.3,.7]){const h=(1-l)*(1-l)*.52+2*(1-l)*l*-.4+l*l*-1.3,o=(1-l)*(1-l)*.38+2*(1-l)*l*.78+l*l*.26+.01;n.push({k:"path",d:J(st(h-.07,o,h+.07,o,h,o-.12),.3),fill:at})}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:r,stroke:r,lw:e*.5});for(const l of[-.34,-.17,0,.17,.34]){const h=.3+.4*(l+.5)*(.5-l)-.01;n.push({k:"path",d:J(st(l-.075,h,l+.075,h,l,h+.13),.15),fill:at})}break}}return n}var re=(t,e)=>({x:Math.sin(t)*e,y:-Math.cos(t)*e}),Hr=.5,jt={leftEye:2,rightEye:5,leftEar:7,rightEar:8},ae={"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}},Ze="6-8",Ni=(t,e)=>e!==void 0&&t.band!=="all"&&t.alsoIn?.includes(e)&&e in ae?e:t.band in ae?t.band:Ze,Pl=ae[Ze].head,Xr=.3,$r=.12,qr=.9,Ii=.5,Oi=.65,Wr=.35,Yr=.2,Qr=.25,Ft=(t,e)=>({x:t.x-e.x,y:t.y-e.y}),et=(t,e)=>({x:t.x+e.x,y:t.y+e.y}),Q=(t,e)=>({x:t.x*e,y:t.y*e}),oe=t=>Math.hypot(t.x,t.y),zi=(t,e)=>({x:(t.x+e.x)/2,y:(t.y+e.y)/2}),Je=t=>{const e=oe(t);return e>1e-9?{x:t.x/e,y:t.y/e}:{x:0,y:1}},jr=(...t)=>t.every(Number.isFinite),Vr=t=>Math.atan2(Math.sin(t),Math.cos(t)),Kr=(t,e,s)=>Math.min(Math.max(t,e),s);function Di(t,e,s=!1){return i=>{const n=t[i*3],r=t[i*3+1],a=t[i*3+2];return n===void 0||r===void 0||a===void 0||!jr(n,r,a)?{x:0,y:0,ok:!1}:{x:e.x+(s?1-n:n)*e.w,y:e.y+r*e.h,ok:a>=Hr}}}function Ps(t,e,s={}){const i=Di(t,e,s.mirrored),n=i(Z.leftShoulder),r=i(Z.rightShoulder);if(!n.ok||!r.ok)return null;const a=i(Z.leftHip),l=i(Z.rightHip),h=zi(n,r),o=oe(Ft(r,n)),f=a.ok&&l.ok;let u=Je(Ft(r,n));o<1e-6&&(u={x:1,y:0});let c,y,p;if(f){const C=zi(a,l);y=oe(Ft(C,h)),y>=o*Qr?c=Je(Ft(C,h)):(c={x:-u.y,y:u.x},c.y<0&&(c=Q(c,-1))),p=Math.max(y,o*1.15)}else c={x:-u.y,y:u.x},c.y<0&&(c=Q(c,-1)),p=o*1.15,y=p;p=Math.max(p,1e-6);const x={x:c.y,y:-c.x},m=Math.atan2(x.y,x.x),g=Q(c,-1),k=ae[s.band??Ze]??ae[Ze],E=k.head*p;let w=et(h,Q(g,E*k.neck));const A=i(Z.nose);if(A.ok){const C=et(A,Q(g,E*.15)),R=Q(Ft(C,w),Wr),O=Math.min(1,E*Yr/Math.max(oe(R),1e-6));w=et(w,Q(R,O))}return{S:h,r:x,d:c,U:p,L:y,hipsOk:f,head:w,headR:E,headRot:m+Zr(t,i,m,p),angle:m}}function Zr(t,e,s,i){const n=[[jt.leftEar,jt.rightEar],[jt.leftEye,jt.rightEye]];for(const[r,a]of n){const l=e(r),h=e(a);if(!l.ok||!h.ok||!(t[r*3+2]>=Oi&&t[a*3+2]>=Oi)||oe(Ft(h,l))<i*.05)continue;const o=Vr(Math.atan2(h.y-l.y,h.x-l.x)-s),f=Math.max(Math.abs(o)-$r,0),u=Kr((qr+Ii-Math.abs(o))/Ii,0,1);return Math.sign(o)*Math.min(f,Xr)*u}return 0}function Bi(t,e,s,i={}){const n=Ni(e,i.band),r=ae[n],a=Ps(t,s,{...i,band:n});if(!a)return[];const l=Di(t,s,i.mirrored),h=e.palette,{S:o,r:f,d:u,U:c,L:y}=a,p=v=>e.bodyExtras.includes(v),x=Math.max(1.2,c*.045),m={stroke:h.outline,lw:x},g=(v,L)=>({x:o.x+f.x*v+u.x*L,y:o.y+f.y*v+u.y*L}),k=v=>v.map(([L,D])=>g(L,D)),E=l(Z.leftShoulder),w=l(Z.rightShoulder),A=l(Z.leftHip),C=l(Z.rightHip),R=oe(Ft(w,E)),O=a.hipsOk?oe(Ft(C,A)):R*.7,P=Math.max(R/2+r.shoulderPad*c,r.shoulderMin*c),I=Math.max(O/2+r.hipPad*c,r.hipMin*c),q=-.1*c,Y=y+r.bottom*c,U=[],Nt=[],H=[],nt=[],mt=[],It=(v,L,D,W)=>{const G=L.flatMap(lt=>[lt.x,lt.y]);v.push({k:"line",pts:G,stroke:h.outline,lw:D+x*2}),v.push({k:"line",pts:G,stroke:W,lw:D})},pi=r.leg*c*(p("strong-legs")?1.3:1),vt=r.arm*c*(p("tiny-arms")?.6:1),Ot=Math.max(r.arm/.22,.9);if(a.hipsOk)for(const[v,L,D,W]of[[A,Z.leftKnee,Z.leftAnkle,-1],[C,Z.rightKnee,Z.rightAnkle,1]]){const G=l(L),lt=l(D);if(!G.ok)continue;const Te=et(v,Q(u,-.12*c)),Dt=lt.ok?[Te,G,lt]:[Te,G];It(Nt,Dt,pi,h.limbs),p("joints")&&Nt.push({k:"circle",x:G.x,y:G.y,r:.15*c*Ot,fill:h.accent,...m}),lt.ok&&Nt.push(...ea(e,lt,a,W,x,r.foot))}for(const[v,L,D,W]of[[E,Z.leftElbow,Z.leftWrist,-1],[w,Z.rightElbow,Z.rightWrist,1]]){const G=l(L),lt=l(D);if(p("pauldrons")){const Mt=et(v,Q(u,.02*c));nt.push({k:"ellipse",x:Mt.x,y:Mt.y,rx:.25*c,ry:.17*c,rot:a.angle+W*.25,fill:h.body,...m});const St=et(Mt,Q(u,.05*c));nt.push({k:"ellipse",x:St.x,y:St.y,rx:.17*c,ry:.07*c,rot:a.angle+W*.25,fill:h.belly})}if(!G.ok)continue;const Dt=r.armsOverHead&&(G.x-o.x)*u.x+(G.y-o.y)*u.y<-.25*c?mt:nt,qe=et(v,Q(u,.04*c));if(It(Dt,lt.ok?[qe,G,lt]:[qe,G],vt,h.limbs),p("joints")&&Dt.push({k:"circle",x:G.x,y:G.y,r:.13*c*Ot,fill:h.accent,...m}),!lt.ok)continue;const dt=Je(Ft(lt,G)),Yt=et(lt,Q(dt,.05*c));if(p("feathers"))for(const Mt of[-.55,0,.55]){const St=Math.cos(Mt),ue=Math.sin(Mt)*W,Et={x:dt.x*St-dt.y*ue,y:dt.x*ue+dt.y*St},Bt=et(Yt,Q(Et,.16*c));Dt.push({k:"ellipse",x:Bt.x,y:Bt.y,rx:.2*c,ry:.09*c,rot:Math.atan2(Et.y,Et.x),fill:h.hands??h.accent,...m})}p("wand")&&W===1&&!i.portrait&&Dt.push(...na(e,Yt,Je(et(Q(dt,.4),Ft(Q(f,.6),u))),c,x));const Qt=r.hand*c*(p("tiny-arms")?.72:1);if(p("tiny-arms"))for(const Mt of[-.45,.45]){const St=Math.cos(Mt),ue=Math.sin(Mt),Et={x:dt.x*St-dt.y*ue,y:dt.x*ue+dt.y*St},Bt=et(Yt,Q(Et,Qt*.75)),yi=et(Yt,Q(Et,Qt*1.6)),vs={x:-Et.y*Qt*.32,y:Et.x*Qt*.32};Dt.push({k:"path",d:J([et(Bt,vs),yi,Ft(Bt,vs)],.2),fill:h.belly,...m})}Dt.push({k:"circle",x:Yt.x,y:Yt.y,r:Qt,fill:h.hands??h.limbs,...m})}if(p("wings"))for(const v of[-1,1]){const L=k([[v*P*.5,.05*c],[v*(P+.85*c),-.6*c],[v*(P+.72*c),.05*c],[v*(P+.45*c),-.02*c],[v*(P+.3*c),.32*c],[v*P*.6,.55*c]]);U.push({k:"path",d:J(L,.18),fill:h.accent,...m})}if(p("wings-fairy")&&U.push(...ra(e,g,P,c,x)),p("cape")){const v=y+.8*c,L=I+.36*c,D=k([[-P*.92,q+.04*c],[P*.92,q+.04*c],[P+.16*c,y*.5],[L,v],[L*.5,v-.1*c],[0,v],[-L*.5,v-.1*c],[-L,v],[-P-.16*c,y*.5]]);U.push({k:"path",d:K(D,.6),fill:h.accent,...m})}if(p("backpack")){const v=g(0,.35*c);U.push({k:"rect",x:v.x,y:v.y,w:P*2+.34*c,h:.8*c,r:.16*c,rot:a.angle,fill:e.extraColors?.[0]??h.limbs,...m})}if(p("tank")){const v=g(P*.95,.24*c),L=e.extraColors?.[0]??h.accent,D=g(P*.95,-.3*c);U.push({k:"rect",x:D.x,y:D.y,w:.14*c,h:.16*c,r:.04*c,rot:a.angle,fill:h.outline}),U.push({k:"rect",x:v.x,y:v.y,w:.34*c,h:1*c,r:.17*c,rot:a.angle,fill:L,...m})}if(a.hipsOk&&!i.portrait&&U.push(...ia(e,a,I,x)),p("tentacles")&&a.hipsOk)for(const v of[-1,1]){const L=k([[v*I*.7,y*.9],[v*(I+.22*c),y+.3*c],[v*(I+.48*c),y+.22*c],[v*(I+.5*c),y-.02*c],[v*(I+.34*c),y-.06*c]]);U.push({k:"path",d:Fe(L),stroke:h.outline,lw:.2*c+x*2}),U.push({k:"path",d:Fe(L),stroke:h.limbs,lw:.2*c})}const xt=Math.max(P,I)*r.bulge;if(p("wool")){for(const[L,D]of[[P*.7,q+.02*c],[xt,y*.3],[xt*1.02,y*.62],[(xt+I)/2,y*.92],[I*.55,Y]])for(const W of[-1,1]){const G=g(W*L,D);H.push({k:"circle",x:G.x,y:G.y,r:.2*c,fill:h.body,...m})}const v=g(0,Y+.02*c);H.push({k:"circle",x:v.x,y:v.y,r:.2*c,fill:h.body,...m})}if(p("robe")){const v=y+.58*c,L=I*1.4;H.push({k:"path",d:K(k([[-P,q],[0,q-.04*c],[P,q],[xt,y*.55],[L,v],[0,v+.06*c],[-L,v],[-xt,y*.55]]),.7),fill:h.body,...m});const D=k([[-L*.94,v-.1*c],[0,v-.04*c],[L*.94,v-.1*c]]);H.push({k:"path",d:Fe(D),stroke:e.extraColors?.[0]??h.accent,lw:.07*c})}else if(p("sheet")){const v=y+.78*c,L=I*1.3;H.push({k:"path",d:K(k([[-P,q],[P,q],[xt,y*.55],[L,v],[L*.5,v-.2*c],[0,v],[-L*.5,v-.2*c],[-L,v],[-xt,y*.55]]),.9),fill:h.body,...m})}else H.push({k:"path",d:K(k([[-P,q],[0,q-.04*c],[P,q],[xt,y*.55],[I,Y],[0,Y+.03*c],[-I,Y],[-xt,y*.55]]),.85),fill:h.body,...m});const ut=Math.min(P,I);if(p("pocket")){const v=g(0,y*.74);H.push({k:"rect",x:v.x,y:v.y,w:ut*1.3,h:.3*c,r:.1*c,rot:a.angle,fill:h.belly,stroke:h.outline,lw:x*.8})}else if(p("racing-stripe"))for(const v of[-.1,.1]){const L=g(v*c,q+.02*c),D=g(v*c,Y-.04*c);H.push({k:"line",pts:[L.x,L.y,D.x,D.y],stroke:h.belly,lw:.1*c})}else if(h.belly&&h.belly!==h.body&&!p("panel")&&!p("sheet")&&!p("stripes")){const v=g(0,y*.58);H.push({k:"ellipse",x:v.x,y:v.y,rx:ut*.64,ry:Math.max(y*.36,.2*c),rot:a.angle,fill:h.belly})}if(p("spots")){const v=e.extraColors?.[1]??h.belly;for(const[L,D,W]of[[-.55,.35,.09],[.5,.62,.11],[-.35,.86,.07]]){const G=g(L*ut,D*y);H.push({k:"circle",x:G.x,y:G.y,r:W*c,fill:v})}}if(p("stripes")){const v=e.extraColors?.[1]??h.accent;for(const L of[.22,.44,.66]){const D=g(-ut*.98,y*L),W=g(ut*.98,y*L);H.push({k:"line",pts:[D.x,D.y,W.x,W.y],stroke:v,lw:.1*c})}}if(p("straps")){const v=e.extraColors?.[1]??h.outline;for(const L of[-1,1]){const D=g(L*P*.62,q+.02*c),W=g(L*ut*.62,y*.72);H.push({k:"line",pts:[D.x,D.y,W.x,W.y],stroke:h.outline,lw:.13*c+x*2}),H.push({k:"line",pts:[D.x,D.y,W.x,W.y],stroke:v,lw:.13*c})}}if(p("belt")){const v=g(0,y*.9);H.push({k:"rect",x:v.x,y:v.y,w:I*1.92,h:.17*c,r:.06*c,rot:a.angle,fill:e.extraColors?.[2]??"#4a3426",...m}),H.push({k:"rect",x:v.x,y:v.y,w:.2*c,h:.19*c,r:.04*c,rot:a.angle,fill:"#ffd84a",...m})}if(p("emblem")){const v=g(0,y*.4),L=e.extraColors?.[0]??h.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:v.x,y:v.y,rot:a.angle,s:c,items:[{k:"path",d:D,fill:L,stroke:h.outline,lw:x/c},{k:"group",x:0,y:.01,s:.12,items:[{k:"path",d:me,fill:L===h.accent?"#ffffff":h.accent}]}]})}if(p("panel")){const v=g(0,y*.5);H.push({k:"rect",x:v.x,y:v.y,w:ut*1.2,h:.38*c,r:.1*c,rot:a.angle,fill:"#24323d",...m}),(e.extraColors??["#ff7a6b","#fbd46a","#7ff0ff"]).slice(0,3).forEach((D,W)=>{const G=g((W-1)*ut*.34,y*.5);H.push({k:"circle",x:G.x,y:G.y,r:.075*c,fill:D})})}if(p("badge")){const v=g(-ut*.42,y*.36);H.push({k:"circle",x:v.x,y:v.y,r:.15*c,fill:h.accent,...m}),H.push({k:"group",x:v.x,y:v.y,rot:a.angle,s:.09*c,items:[{k:"path",d:me,fill:"#ffffff"}]})}if(p("star")){const v=g(-ut*.5,y*.3),L=.15*c;H.push({k:"group",x:v.x,y:v.y,rot:a.angle-.2,s:L,items:[{k:"path",d:me,fill:e.extraColors?.[0]??"#ffd84a",stroke:h.outline,lw:x*.8/L}]})}if(p("petals")&&H.push(...aa(e,g,P,I,xt,y,Y,c,x,r)),p("scarf")){const v=Math.max(.04,r.head*(1-r.neck)-.06)*c,L=g(0,v),D=e.extraColors?.[0]??h.accent,W=g(P*.45,v+.28*c);H.push({k:"rect",x:W.x,y:W.y,w:.16*c,h:.42*c,r:.06*c,rot:a.angle+.15,fill:D,...m}),H.push({k:"rect",x:L.x,y:L.y,w:P*2.05,h:.2*c,r:.1*c,rot:a.angle,fill:D,...m})}const zt={k:"group",x:a.head.x,y:a.head.y,rot:a.headRot,s:a.headR,items:ta(e,x/a.headR)};return[...U,...Nt,...H,...nt,zt,...mt]}var Ui=new WeakMap,Jr=64;function ta(t,e){const s=Number(e.toPrecision(4));let i=Ui.get(t);i||Ui.set(t,i=new Map);let n=i.get(s);return n||(i.size>=Jr&&i.clear(),i.set(s,n=Pi(t,s))),n}function ea(t,e,s,i,n,r){const a=sa(t,e,s,i,n,r);if(!t.bodyExtras.includes("strong-legs"))return[a];const l=s.U*r,h=et(et(e,Q(s.d,.07*l)),Q(s.r,i*.06*l)),o=[a];for(const f of[-1,0,1]){const u=et(et(h,Q(s.r,f*.12*l)),Q(s.d,.09*l));o.push({k:"ellipse",x:u.x,y:u.y,rx:.05*l,ry:.045*l,rot:s.angle,fill:t.palette.belly,stroke:t.palette.outline,lw:n*.8})}return o}function sa(t,e,s,i,n,r){const a=t.palette,{d:l,r:h}=s,o=s.U*r,f=et(et(e,Q(l,.07*o)),Q(h,i*.06*o)),u={stroke:a.outline,lw:n},c=a.feet??a.limbs;if(t.bodyExtras.includes("fins")){const y=J([{x:-.13,y:-.06},{x:.13,y:-.06},{x:.24,y:.46},{x:-.24,y:.46}],.22);return{k:"group",x:f.x,y:f.y,rot:s.angle,s:o,items:[{k:"path",d:y,fill:c,stroke:a.outline,lw:n/o},{k:"line",pts:[0,.06,0,.38],stroke:a.outline,lw:n/o,alpha:.5}]}}return t.bodyExtras.includes("flippers")?{k:"ellipse",x:f.x,y:f.y,rx:.27*o,ry:.11*o,rot:s.angle,fill:c,...u}:t.bodyExtras.includes("boots")?{k:"rect",x:f.x,y:f.y,w:.4*o,h:.24*o,r:.09*o,rot:s.angle,fill:c,...u}:{k:"ellipse",x:f.x,y:f.y,rx:.2*o,ry:.13*o,rot:s.angle,fill:c,...u}}function ia(t,e,s,i){const n=t.palette,{U:r,L:a,S:l,r:h,d:o}=e,f=(x,m)=>({x:l.x+h.x*x+o.x*m,y:l.y+h.y*x+o.y*m}),u=x=>x.map(([m,g])=>f(m,g)),c={stroke:n.outline,lw:i},y=(x,m,g)=>[{k:"path",d:Fe(x),stroke:n.outline,lw:m+i*2},{k:"path",d:Fe(x),stroke:g,lw:m}],p=[];switch(t.tail){case"none":break;case"fluffy":{const x=u([[s*.5,a*.95],[s+.28*r,a*1],[s+.72*r,a*.62],[s+.78*r,a*.12],[s+.52*r,a*.32],[s+.3*r,a*.6],[s*.6,a*.7]]);p.push({k:"path",d:K(x),fill:n.body,...c});const m=f(s+.72*r,a*.2);p.push({k:"ellipse",x:m.x,y:m.y,rx:.13*r,ry:.2*r,rot:e.angle+.25,fill:n.belly,...c});break}case"brush":{const x=u([[s*.4,a*.98],[s+.42*r,a*1.06],[s+.98*r,a*.66],[s+1.06*r,a*.12],[s+.86*r,-.04*r],[s+.66*r,a*.36],[s+.3*r,a*.66],[s*.5,a*.68]]);p.push({k:"path",d:K(x),fill:n.body,...c});const m=u([[s+1.03*r,a*.36],[s+1.06*r,a*.12],[s+.86*r,-.04*r],[s+.72*r,a*.24],[s+.86*r,a*.34]]);p.push({k:"path",d:K(m),fill:n.belly,...c});break}case"pom":{const x=f(s+.06*r,a*.88);p.push({k:"circle",x:x.x,y:x.y,r:.2*r,fill:n.belly,...c});break}case"long":case"striped":case"tuft":{const x=u([[s*.6,a*.9],[s+.35*r,a*.85],[s+.58*r,a*.4],[s+.5*r,-.02*r]]);if(p.push(...y(x,.14*r,n.body)),t.tail==="tuft"){const m=x[x.length-1];p.push({k:"circle",x:m.x,y:m.y,r:.16*r,fill:t.extraColors?.[0]??n.accent,...c})}if(t.tail==="striped"){for(const g of[.35,.6,.85]){const k=f(s+.35*r+.22999999999999998*r*(g*1.4>1?1:g*1.4),a*(.85-.85*g));p.push({k:"line",pts:[k.x-h.x*.08*r,k.y-h.y*.08*r,k.x+h.x*.08*r,k.y+h.y*.08*r],stroke:t.extraColors?.[0]??n.outline,lw:.06*r})}const m=x[x.length-1];p.push({k:"circle",x:m.x,y:m.y,r:.07*r,fill:t.extraColors?.[0]??n.outline})}break}case"curl":{const x=u([[s*.6,a*.9],[s+.4*r,a*.88],[s+.62*r,a*.45],[s+.5*r,a*.12],[s+.3*r,a*.24],[s+.36*r,a*.42]]);p.push(...y(x,.12*r,n.limbs));break}case"fish":{const x=u([[s*.6,a*.9],[s+.36*r,a*.86],[s+.6*r,a*.5]]);p.push(...y(x,.17*r,n.body));const m=x[x.length-1],g=J([{x:0,y:.06},{x:-.26,y:-.34},{x:.02,y:-.12},{x:.32,y:-.3}],.2);p.push({k:"group",x:m.x,y:m.y,rot:e.angle+.35,s:r,items:[{k:"path",d:g,fill:n.body,stroke:n.outline,lw:i/r}]});break}case"plume":{const x=t.extraColors??[n.accent];[0,1,2].forEach(m=>{const g=f(s+(.12+m*.13)*r,a+(.32-m*.06)*r);p.push({k:"ellipse",x:g.x,y:g.y,rx:.11*r,ry:.44*r,rot:e.angle-.55+m*.28,fill:x[(m+1)%x.length],...c})});break}case"thick":{const x=u([[s*.3,a*.42],[s+.42*r,a*.62],[s+.92*r,a*.96],[s+1.32*r,a*1.08],[s+1.44*r,a*.98],[s+.98*r,a*1.2],[s+.4*r,a*1.22],[s*.3,a*1.12]]);p.push({k:"path",d:K(x,.8),fill:n.body,...c});const m=t.extraColors?.[0]??n.accent;for(const[g,k,E]of[[.28,.58,.26],[.62,.8,.22],[.96,1,.16]]){const w=f(s+g*r,a*k+.03*r),A=f(s+(g-.1)*r,a*k+E*r);p.push({k:"line",pts:[w.x,w.y,A.x,A.y],stroke:m,lw:.09*r})}break}case"spiky":case"arrow":{const x=u([[s*.3,a*.55],[s+.35*r,a*.68],[s+.95*r,a*.86],[s+.35*r,a*1.08],[s*.3,a*1.08]]);if(t.tail==="spiky"){for(const m of[.15,.45,.72]){const g=s+(.2+m*.7)*r,k=a*(.66+m*.19);p.push({k:"path",d:J(u([[g-.12*r,k+.05*r],[g,k-.2*r],[g+.12*r,k+.07*r]]),.2),fill:n.accent,...c})}p.push({k:"path",d:K(x,.7),fill:n.body,...c})}else{const m=u([[s*.6,a*.9],[s+.4*r,a*.92],[s+.62*r,a*.5],[s+.62*r,a*.18]]);p.push(...y(m,.13*r,n.body));const g=m[m.length-1];p.push({k:"group",x:g.x,y:g.y,rot:e.angle,s:r,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:i/r}]})}break}}return p}function na(t,e,s,i,n){const r=t.palette,a=et(e,Q(s,-.08*i)),l=et(e,Q(s,.52*i)),h=.2*i;return[{k:"line",pts:[a.x,a.y,l.x,l.y],stroke:r.outline,lw:.06*i+n*2},{k:"line",pts:[a.x,a.y,l.x,l.y],stroke:"#fff3d6",lw:.06*i},{k:"circle",x:l.x,y:l.y,r:.24*i,fill:r.accent,alpha:.28},{k:"group",x:l.x,y:l.y,rot:Math.atan2(s.y,s.x)+Math.PI/2,s:h,items:[{k:"path",d:me,fill:r.accent,stroke:r.outline,lw:n*.9/h}]}]}function ra(t,e,s,i,n){const r=t.palette,a=t.extraColors?.[0]??"#cdeeff",l=[];for(const h of[-1,1]){const o=[[[h*s*.3,.12*i],[h*(s+.42*i),-.66*i],[h*(s+1*i),-.74*i],[h*(s+1.02*i),-.18*i],[h*(s+.5*i),.26*i]],[[h*s*.4,.3*i],[h*(s+.6*i),.36*i],[h*(s+.74*i),.78*i],[h*(s+.3*i),.9*i]]];for(const f of o){const u=K(f.map(([x,m])=>e(x,m)),.9);l.push({k:"path",d:u,fill:a,alpha:.6}),l.push({k:"path",d:u,stroke:r.outline,lw:n*.9});const c=f[Math.floor(f.length/2)],y=e(f[0][0],f[0][1]),p=e(f[0][0]+(c[0]-f[0][0])*.75,f[0][1]+(c[1]-f[0][1])*.75);l.push({k:"line",pts:[y.x,y.y,p.x,p.y],stroke:"#ffffff",lw:n*.9,alpha:.85})}for(const[f,u,c]of[[s+.72*i,-.42*i,.075*i],[s+.44*i,-.16*i,.05*i],[s+.5*i,.6*i,.055*i]]){const y=e(h*f,u);l.push({k:"group",x:y.x,y:y.y,s:c,items:[{k:"path",d:me,fill:"#ffffff"}]})}}return l}function aa(t,e,s,i,n,r,a,l,h,o){const f=t.palette,u=t.extraColors?.[1]??f.belly,c=[],y=Math.atan2(e(1,0).y-e(0,0).y,e(1,0).x-e(0,0).x),p=5,x=Math.max(i,n*.92)*1.08,m=(r*.8+a)/2,g=[0,4,1,3,2];for(const E of g){const w=E/(p-1)-.5,A=e(w*2*x,m+(.5-Math.abs(w))*.1*l);c.push({k:"ellipse",x:A.x,y:A.y,rx:x*.3,ry:.34*l,rot:y-w*.6,fill:E%2?u:f.body,stroke:f.outline,lw:h})}const k=Math.max(.04,o.head*(1-o.neck)-.04)*l;for(const E of[-1,1,0]){const w=e(E*s*.32,k+(E?0:.05*l));c.push({k:"ellipse",x:w.x,y:w.y,rx:s*.26,ry:.12*l,rot:y+E*.5,fill:E?u:f.body,stroke:f.outline,lw:h*.9})}return c}var oa={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 la(t,{cx:e=.5,cy:s=.36,T:i=.18}={}){const n={...oa,...t},r=new Array(Ei*3).fill(0),a=(o,[f,u],c=.99)=>{r[o*3]=e+f*i,r[o*3+1]=s+u*i,r[o*3+2]=c};for(const o of Object.keys(Z))a(Z[o],n[o]);const l=n.tilt??0,h=(o,f)=>[n.nose[0]+o*Math.cos(l)-f*Math.sin(l),n.nose[1]+o*Math.sin(l)+f*Math.cos(l)];return a(jt.leftEye,h(-.1,-.08)),a(jt.rightEye,h(.1,-.08)),a(jt.leftEar,h(-.22,-.02)),a(jt.rightEar,h(.22,-.02)),r}var ha=()=>la({}),Gi=.5,ca=.15,fa=class{constructor(t={}){d(this,"tracks",new Map),d(this,"offset",NaN),d(this,"lastArrival",NaN),d(this,"interval",33),d(this,"lastT",NaN),d(this,"lostMs"),d(this,"maxExtrapolateMs"),this.lostMs=t.lostMs??250,this.maxExtrapolateMs=t.maxExtrapolateMs??25}get delayMs(){return this.interval}push(t,e,s,i=Hi()){Number.isFinite(e)||(e=i),this.clock(e,i);const n=this.tracks.get(t);if(!n||e-n.tb>this.lostMs||e<n.tb-this.lostMs||s.length!==n.b.length){this.tracks.set(t,{a:null,ta:e,b:s,tb:e,out:null,outAt:NaN});return}if(s===n.b||e<=n.tb){e===n.tb&&s!==n.b&&(n.b=s,n.out=null);return}n.a=n.b,n.ta=n.tb,n.b=s,n.tb=e,n.out=null}at(t,e=Hi()){const s=this.tracks.get(t);if(!s)return null;if(!s.a)return s.b;if(s.out&&s.outAt===e)return s.out;const i=e-this.offset-this.interval,n=s.tb-s.ta,r=Math.min(n*.5,this.maxExtrapolateMs),a=Math.min(Math.max((i-s.ta)/n,0),1+r/n);return s.out=ua(s.a,s.b,a),s.outAt=e,s.out}forget(t){this.tracks.delete(t)}clear(){this.tracks.clear()}clock(t,e){const s=e-t;if(!Number.isFinite(this.offset)||s<this.offset||s>this.offset+1e3?this.offset=s:Number.isFinite(this.lastArrival)&&(this.offset+=Math.min(s-this.offset,(e-this.lastArrival)/1e3)),this.lastArrival=e,Number.isFinite(this.lastT)&&t>this.lastT){const i=t-this.lastT;i<this.interval*3+20&&(this.interval+=(Math.min(Math.max(i,8),100)-this.interval)*.1)}t<=this.lastT||(this.lastT=t)}},Hi=()=>globalThis.performance?.now()??Date.now();function ua(t,e,s){const i=e.slice(),n=s<.5?t:e;for(let r=0;r+2<e.length;r+=3){const a=t[r],l=t[r+1],h=e[r],o=e[r+1];t[r+2]>=Gi&&e[r+2]>=Gi&&Math.abs(h-a)+Math.abs(o-l)<ca?(i[r]=a+(h-a)*s,i[r+1]=l+(o-l)*s,i[r+2]=t[r+2]+(e[r+2]-t[r+2])*Math.min(s,1)):(i[r]=n[r],i[r+1]=n[r+1],i[r+2]=n[r+2])}return i}var Ll=Si.map(t=>t.id),ts=new Map(Si.map(t=>[t.id,t])),Pe=ts.get("fox"),da=t=>typeof t=="string"&&ts.has(t),es=t=>ts.get(t),pa=t=>typeof t=="string"?ts.get(t)??Pe:t;function ya(t,e,s){const i=pa(t),n=ha(),r=Ni(i,s),a=Ps(n,{x:0,y:0,w:1,h:1},{band:r}),l=$i(Pi(i,.05)),h=-l.minY,o=Math.min(.27,.43/Math.max(h,1))*e,f=i.head==="snout-long"?(l.minX+l.maxX)/2*o:0,u=o/ae[r].head/a.U,c=.5*e+Math.min(0,(h-1.6)*.06*e),y={x:e/2-f-a.head.x*u,y:c-a.head.y*u,w:u,h:u};return Bi(n,i,y,{portrait:!0,band:r})}function ma(t,e,s=.5){if(!t||t.length!==e.length)return e.slice();const i=e.slice();for(let n=0;n+2<e.length;n+=3){const r=t[n+2],a=e[n+2],l=r>=.5,h=a>=.5;l&&a>=.3&&(i[n+2]=Math.max(a,.5));const o=Math.hypot(e[n]-t[n],e[n+1]-t[n+1]);if(l&&h&&o<.15){const f=s*Math.min(1,Xi+(1-Xi)*o/xa);i[n]=t[n]+(e[n]-t[n])*f,i[n+1]=t[n+1]+(e[n+1]-t[n+1])*f}else l&&!h&&i[n+2]>=.5&&(i[n]=t[n],i[n+1]=t[n+1])}return ka(t,e,i,s*ga),i}var Xi=.1,xa=.03,ga=.35,ba=11;function ka(t,e,s,i){const n=Z.leftShoulder*3,r=Z.rightShoulder*3,a=(u,c)=>u[c+2]>=.5;if(!a(t,n)||!a(t,r)||!a(e,n)||!a(e,r))return;const l=(u,c)=>(u[n+c]+u[r+c])/2,h=[l(t,0),l(t,1)],o=[l(e,0),l(e,1)],f=[l(s,0),l(s,1)];for(let u=0;u<ba&&u*3+2<e.length;u++){const c=u*3;if(!a(t,c)||!a(e,c))continue;const y=[t[c]-h[0],t[c+1]-h[1]],p=[e[c]-o[0],e[c+1]-o[1]];Math.hypot(p[0]-y[0],p[1]-y[1])>=.15||(s[c]=f[0]+y[0]+(p[0]-y[0])*i,s[c+1]=f[1]+y[1]+(p[1]-y[1])*i)}}function $i(t){const e={minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0},s=(i,n)=>{e.minX=Math.min(e.minX,i),e.minY=Math.min(e.minY,n),e.maxX=Math.max(e.maxX,i),e.maxY=Math.max(e.maxY,n)};for(const i of t){const n="lw"in i&&i.stroke?(i.lw??1)/2:0;switch(i.k){case"circle":s(i.x-i.r-n,i.y-i.r-n),s(i.x+i.r+n,i.y+i.r+n);break;case"ellipse":case"rect":{const r=i.k==="ellipse"?i.rx:i.w/2,a=i.k==="ellipse"?i.ry:i.h/2,l=Math.max(r,a)+n;s(i.x-l,i.y-l),s(i.x+l,i.y+l);break}case"path":{const r=Fr(i.d);for(let a=0;a+1<r.length;a+=2)s(r[a]-n,r[a+1]-n),s(r[a]+n,r[a+1]+n);break}case"line":for(let r=0;r+1<i.pts.length;r+=2)s(i.pts[r]-n,i.pts[r+1]-n),s(i.pts[r]+n,i.pts[r+1]+n);break;case"group":{const r=$i(i.items);if(!Number.isFinite(r.minX))break;const a=i.s??1,l=Math.cos(i.rot??0),h=Math.sin(i.rot??0);for(const[o,f]of[[r.minX,r.minY],[r.maxX,r.minY],[r.minX,r.maxY],[r.maxX,r.maxY]])s(i.x+(o*l-f*h)*a,i.y+(o*h+f*l)*a);break}}}return e}var xe=()=>Float64Array.of(1,0,0,1,0,0);function Xt(t,e,s,i,n,r,a){const l=n?Math.cos(n):1,h=n?Math.sin(n):0,o=l*r,f=h*r,u=-h*a,c=l*a;if(!e)return t[0]=o,t[1]=f,t[2]=u,t[3]=c,t[4]=s,t[5]=i,t;const y=e[0],p=e[1],x=e[2],m=e[3];return t[0]=y*o+x*f,t[1]=p*o+m*f,t[2]=y*u+x*c,t[3]=p*u+m*c,t[4]=y*s+x*i+e[4],t[5]=p*s+m*i+e[5],t}function wa(t,e,s){const i=t[0]*t[3]-t[1]*t[2];if(Math.abs(i)<1e-12)return null;const n=e-t[4],r=s-t[5];return[(t[3]*n-t[2]*r)/i,(-t[1]*n+t[0]*r)/i]}var qi={white:16777215,black:0,red:16711680,transparent:0},Le=new Map;function Ut(t){if(typeof t=="number")return[t&16777215,1];const e=Le.get(t);if(e)return e;let s=[16777215,1];const i=t.trim().toLowerCase();if(i[0]==="#"){const n=i.slice(1),r=n.length<=4?[...n].map(l=>l+l).join(""):n,a=parseInt(r.slice(0,6),16);Number.isFinite(a)&&(s=[a,r.length===8?parseInt(r.slice(6,8),16)/255:1])}else if(i.startsWith("rgb")){const n=i.match(/-?\d*\.?\d+%?/g)?.map(o=>o.endsWith("%")?parseFloat(o)/100*255:parseFloat(o))??[],[r=255,a=255,l=255]=n,h=n[3]===void 0?1:i.match(/,\s*[\d.]+%\s*\)$/)?n[3]/255:n[3];s=[(Ls(r)<<16|Ls(a)<<8|Ls(l))>>>0,Math.min(Math.max(h,0),1)]}else if(i in qi)s=[qi[i],i==="transparent"?0:1];else if(typeof document<"u"){const n=document.createElement("canvas").getContext("2d");if(n){n.fillStyle="#ffffff",n.fillStyle=i;const r=n.fillStyle;if(r!==i)return Le.set(t,s=Ut(r)),s}}return Le.size>512&&Le.clear(),Le.set(t,s),s}var Ls=t=>Math.min(Math.max(Math.round(t),0),255);function ge(t,e,s=!1){const i=Math.min(Math.max(e,0),1),n=(t>>16&255)*i,r=(t>>8&255)*i,a=(t&255)*i,l=s?0:i*255;return(Math.round(l)<<24|Math.round(a)<<16|Math.round(r)<<8|Math.round(n))>>>0}var Ne=(t,e=1)=>`rgba(${t>>16&255},${t>>8&255},${t&255},${e})`;function Wi(t,e){if(t===16777215)return e;if(e===16777215)return t;const s=i=>Math.round((t>>i&255)*(e>>i&255)/255);return(s(16)<<16|s(8)<<8|s(0))>>>0}var Ie={linear:t=>t,quadIn:t=>t*t,quadOut:t=>t*(2-t),quadInOut:t=>t<.5?2*t*t:-1+(4-2*t)*t,cubicOut:t=>1-(1-t)**3,sineInOut:t=>-(Math.cos(Math.PI*t)-1)/2,backOut:t=>1+(1.70158+1)*(t-1)**3+1.70158*(t-1)**2,elasticOut:t=>t===0||t===1?t:2**(-10*t)*Math.sin((t*10-.75)*(2*Math.PI/3))+1,bounceOut:t=>t<1/2.75?7.5625*t*t:t<2/2.75?7.5625*(t-=1.5/2.75)*t+.75:t<2.5/2.75?7.5625*(t-=2.25/2.75)*t+.9375:7.5625*(t-=2.625/2.75)*t+.984375};function va(t){let e=t>>>0;return()=>{e=e+1831565813>>>0;let s=e;return s=Math.imul(s^s>>>15,s|1),s^=s+Math.imul(s^s>>>7,s|61),((s^s>>>14)>>>0)/4294967296}}var Oe=1,Yi=2,ss=0,Pt=1,Ma=4294967295,_={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},Vt=[],Ea="x y rot sx sy alpha la lb lc ld world tint flags moved dirty gen parent first next prev stamp".split(" ");function Qi(t){const e=_;for(const i of Ea){const n=e[i],r=new n.constructor(i==="world"?t*6:t);r.set(n),e[i]=r}const s=new Int32Array(t);for(let i=0;i<_.freeCount;i++)s[i]=_.free[(_.freeHead+i)%_.cap];for(_.free=s,_.freeHead=0,_.cap=t,_.epoch++;Vt.length<t;)Vt.push(null)}function Ns(t){_.x[t]=_.y[t]=_.rot[t]=0,_.sx[t]=_.sy[t]=_.alpha[t]=1,_.la[t]=_.ld[t]=1,_.lb[t]=_.lc[t]=0;const e=t*6,s=_.world;s[e]=s[e+3]=1,s[e+1]=s[e+2]=s[e+4]=s[e+5]=0,_.tint[t]=16777215,_.flags[t]=Oe|Yi,_.moved[t]=1,_.dirty[t]=0,_.parent[t]=_.first[t]=_.next[t]=_.prev[t]=-1}Qi(256),Ns(ss),_.flags[ss]=0,Ns(Pt),_.flags[Pt]=0;function Aa(){let t;if(_.freeCount){t=_.free[_.freeHead],_.freeHead=(_.freeHead+1)%_.cap,_.freeCount--;const e=Vt[t];e&&(e._i=ss,e._g=-1,Vt[t]=null)}else _.top===_.cap&&Qi(_.cap*2),t=_.top++;return Ns(t),t}function ji(t,e){Is(t);for(let i=_.first[t];i>=0;){const n=_.next[i];_.parent[i]=_.next[i]=_.prev[i]=-1,i=n}_.first[t]=-1,_.flags[t]=_.flags[t]&~Yi,_.moved[t]=0;const s=_.gen[t]+1;_.gen[t]=s,s!==Ma&&(e&&(Vt[t]=e),_.free[(_.freeHead+_.freeCount)%_.cap]=t,_.freeCount++)}function _a(t){for(let e=0;e<Vt.length;e++){const s=Vt[e];s&&t(s)&&(s._i=ss,s._g=-1,Vt[e]=null)}}function Ta(t,e){Is(t);const s=_.first[e];_.parent[t]=e,_.next[t]=s,_.prev[t]=-1,s>=0&&(_.prev[s]=t),_.first[e]=t,_.moved[t]=1}function Is(t){const e=_.parent[t];if(e<0)return;const s=_.next[t],i=_.prev[t];i>=0?_.next[i]=s:_.first[e]=s,s>=0&&(_.prev[s]=i),_.parent[t]=_.next[t]=_.prev[t]=-1}var ze={root:-1,gen:-1,world:new Float64Array(6)};function Sa(t){const e=++_.pass,s=_.world,i=t*6,n=ze.world;let r=ze.root!==t||ze.gen!==_.gen[t];for(let a=0;a<6;a++)n[a]!==s[i+a]&&(r=!0),n[a]=s[i+a];ze.root=t,ze.gen=_.gen[t],_.stamp[t]=r?e:e-1}function Ca(t){_.stamp[t]=_.pass}function Vi(t){for(let e=_.first[t];e>=0;){const s=_.next[e];Vi(e),e=s}ji(t)}var Os=typeof FinalizationRegistry=="function"?new FinalizationRegistry(t=>_.gen[t.i]===t.g&&Vi(t.i)):null;function Ki(t){t._reg||!Os||(t._reg=!0,Os.register(t,{i:t._i,g:t._g},t))}function Ra(t){t._reg&&Os.unregister(t)}var zs=1,Ds=2,Bs=3,Us=4;function Gs(t){if(t){for(let e=0;e<t.length;e++)if(t[e].enabled)return!0}return!1}function Fa(t,e){let s=0;for(let i=0;i<t.length;i++){const n=t[i];n.enabled&&n.pad&&(s+=n.pad(e))}return s}var Gt={gl:null,c2d:null,live:null},j=new Float64Array(3),Hs=4,Pa=1,Xs=()=>Pa++,ot=xe(),F=_,le=class{constructor(t){d(this,"kernel",t),d(this,"_i",Aa()),d(this,"_g",F.gen[this._i]),d(this,"_wv",null),d(this,"_wi",-1),d(this,"_we",-1),d(this,"blend","normal"),d(this,"_data",null),d(this,"parent",null),d(this,"hitRadius",null),d(this,"clip",null),d(this,"mask",null),d(this,"filters",null),d(this,"_z",0),d(this,"anchorX",0),d(this,"anchorY",0),d(this,"_pool",null),d(this,"_free",!1),d(this,"_reg",!1)}get x(){return F.x[this._i]}set x(t){const e=this._i||Pt;F.x[e]=t,F.moved[e]=1}get y(){return F.y[this._i]}set y(t){const e=this._i||Pt;F.y[e]=t,F.moved[e]=1}get rotation(){return F.rot[this._i]}set rotation(t){const e=this._i||Pt;F.rot[e]=t,F.dirty[e]=F.moved[e]=1}get scaleX(){return F.sx[this._i]}set scaleX(t){const e=this._i||Pt;F.sx[e]=t,F.dirty[e]=F.moved[e]=1}get scaleY(){return F.sy[this._i]}set scaleY(t){const e=this._i||Pt;F.sy[e]=t,F.dirty[e]=F.moved[e]=1}get alpha(){return F.alpha[this._i]}set alpha(t){const e=this._i||Pt;F.alpha[e]=t,F.moved[e]=1}get visible(){return(F.flags[this._i]&Oe)!==0}set visible(t){const e=this._i||Pt;t?F.flags[e]=F.flags[e]|Oe:F.flags[e]=F.flags[e]&~Oe,F.moved[e]=1}get destroyed(){return F.gen[this._i]!==this._g}get world(){const t=this._i||Pt;return(this._wi!==t||this._we!==F.epoch)&&(this._wv=F.world.subarray(t*6,t*6+6),this._wi=t,this._we=F.epoch),this._wv}get data(){return this._data??(this._data={})}set data(t){this._data=t}get scale(){return this.scaleX}set scale(t){this.scaleX=this.scaleY=t}get z(){return this._z}set z(t){t!==this._z&&(this._z=t,this.parent&&(this.parent.sortDirty=!0))}get tint(){return F.tint[this._i]}set tint(t){F.tint[this._i||Pt]=typeof t=="number"?t&16777215:Ut(t)[0]}set anchor(t){typeof t=="number"?this.anchorX=this.anchorY=t:(this.anchorX=t.x,this.anchorY=t.y)}get width(){return 0}set width(t){}get height(){return 0}set height(t){}set(t){for(const e in t){const s=t[e];s!==void 0&&(this[e]=s)}return this}destroy(){this.destroyed||(this.visible=!1,this.parent&&(this.parent.dead=!0,this.parent=null),ji(this._i,this),Ra(this),this.kernel.tweens.stopAll(this),this._pool?.forget(this))}updateWorld(){const t=this.parent?this.parent.updateWorld():null;return Xt(this.world,t,this.x,this.y,this.rotation,this.scaleX,this.scaleY)}draw(t,e,s){}};function La(t){_a(e=>e.kernel===t)}var $s=!1,Zi=Object.freeze([]),qs=class cr extends le{constructor(e){super(e),d(this,"children",Zi),d(this,"sortDirty",!1),d(this,"dead",!1),Ki(this)}add(e,...s){this.adopt(e);for(let i=0;i<s.length;i++)this.adopt(s[i]);return e}adopt(e){e.parent&&e.parent.detach(e),e.parent=this,!e.destroyed&&!this.destroyed&&Ta(e._i,this._i),this.children===Zi&&(this.children=[]),this.children.push(e),(e.z!==0||this.sortDirty)&&(this.sortDirty=!0)}remove(e){this.detach(e),e._pool||Ki(e)}detach(e){const s=this.children,i=s.indexOf(e);if(i>=0){for(let n=i+1;n<s.length;n++)s[n-1]=s[n];s.pop()}e.parent===this&&(e.parent=null,e.destroyed||Is(e._i))}clear(){for(const e of this.children)e.destroy()}destroy(){for(const e of this.children)e.destroy();super.destroy()}sweep(){if(this.dead){this.dead=!1;let e=0;for(const s of this.children)s.destroyed?s.parent===this&&(s.parent=null):this.children[e++]=s;this.children.length=e}for(const e of this.children)e instanceof cr&&e.sweep()}draw(e,s,i){if($s)return F.parent[this._i]<0&&!this.destroyed&&Ca(this._i),this.drawChildren(e,s,i);$s=!0;try{this.destroyed||Sa(this._i),this.drawChildren(e,s,i)}finally{$s=!1}}drawChildren(e,s,i){if(this.sortDirty){const l=new Map(this.children.map((h,o)=>[h,o]));this.children.sort((h,o)=>h.z-o.z||l.get(h)-l.get(o)),this.sortDirty=!1}const n=this.children,r=this._i,a=F.stamp[r]===F.pass;for(let l=0;l<n.length;l++){const h=n[l],o=h._i,f=F.alpha[o];if(F.gen[o]!==h._g||!(F.flags[o]&Oe)||f<=0)continue;if(a||F.moved[o]){F.moved[o]=0,F.stamp[o]=F.pass;let y,p,x,m;if(F.dirty[o]){F.dirty[o]=0;const I=F.rot[o],q=I?Math.cos(I):1,Y=I?Math.sin(I):0,U=F.sx[o],Nt=F.sy[o];F.la[o]=y=q*U,F.lb[o]=p=Y*U,F.lc[o]=x=-Y*Nt,F.ld[o]=m=q*Nt}else y=F.la[o],p=F.lb[o],x=F.lc[o],m=F.ld[o];const g=F.world,k=F.x[o],E=F.y[o],w=o*6,A=r*6,C=g[A],R=g[A+1],O=g[A+2],P=g[A+3];g[w]=C*y+O*p,g[w+1]=R*y+P*p,g[w+2]=C*x+O*m,g[w+3]=R*x+P*m,g[w+4]=C*k+O*E+g[A+4],g[w+5]=R*k+P*E+g[A+5]}const u=s*f,c=Wi(i,F.tint[o]);h.clip||h.mask||h.filters?tn(e,h,u,c):h.draw(e,u,c)}}},yt=new Float64Array(128),he=0,Ws=new Float64Array(8);function Ji(t,e,s,i){e.clip||e.mask||e.filters?tn(t,e,s,i):e.draw(t,s,i)}function tn(t,e,s,i){const n=t.r,r=e.world,a=e.clip;let l=!1,h=!1;if(a)if(Math.abs(r[1])<1e-9&&Math.abs(r[2])<1e-9&&he<32){const u=r[0]*a.x+r[4],c=r[0]*(a.x+a.width)+r[4],y=r[3]*a.y+r[5],p=r[3]*(a.y+a.height)+r[5];let x=Math.min(u,c),m=Math.max(u,c),g=Math.min(y,p),k=Math.max(y,p);if(he){const w=(he-1)*4;x=Math.max(x,yt[w]),g=Math.max(g,yt[w+1]),m=Math.min(m,yt[w+2]),k=Math.min(k,yt[w+3])}const E=he++*4;yt[E]=x,yt[E+1]=g,yt[E+2]=m,yt[E+3]=k,n.clip(x,g,Math.max(m-x,0),Math.max(k-g,0)),h=!0}else l=!0;const o=e.mask&&e.mask.visible?e.mask:null,f=Gs(e.filters)?e.filters:null;try{if(l&&n.beginLayer(),o&&n.beginLayer(),f?(e.draw(t,n.beginLayer()?1:s,i),n.endLayer(s,f)):e.draw(t,s,i),o&&(n.beginMask(),Xt(o.world,r,o.x,o.y,o.rotation,o.scaleX,o.scaleY),Ji(t,o,o.alpha,16777215),n.endLayer(1)),l&&a){n.beginMask();for(let u=0;u<4;u++){const c=u===1||u===2?a.x+a.width:a.x,y=u>1?a.y+a.height:a.y;Ws[u*2]=r[0]*c+r[2]*y+r[4],Ws[u*2+1]=r[1]*c+r[3]*y+r[5]}n.polygon(Ws,4,16777215,1),n.endLayer(1)}}finally{if(h)if(he--,he){const u=(he-1)*4;n.clip(yt[u],yt[u+1],yt[u+2]-yt[u],yt[u+3]-yt[u+1])}else n.unclip()}}var be=class extends le{constructor(t,e,s){super(t),d(this,"_frame",null),d(this,"_w",null),d(this,"_h",null),d(this,"slice",0),d(this,"autoAnchor",!0),d(this,"frameName",null),e&&(this.frame=e),s?.anchor===void 0&&this.useFrameAnchor(),s&&this.set(s)}get frame(){return this._frame}set frame(t){this.frameName=typeof t=="string"?t:null,this._frame=typeof t=="string"?this.kernel.frame(t):t,this.autoAnchor&&this.useFrameAnchor()}set anchor(t){this.autoAnchor=!1,super.anchor=t}get naturalWidth(){const t=this.frameNow();return t?(t.sw??t.w)/t.scale-t.margin*2:0}get naturalHeight(){const t=this.frameNow();return t?(t.sh??t.h)/t.scale-t.margin*2:0}get width(){return this._w??this.naturalWidth}set width(t){this._w=t}get height(){return this._h??this.naturalHeight}set height(t){this._h=t}sizeQ(t){ve[0]=this._w??(t.sw??t.w)/t.scale-t.margin*2,ve[1]=this._h??(t.sh??t.h)/t.scale-t.margin*2}frameNow(){return this.frameName&&!this.kernel.atlas.valid(this._frame)&&(this._frame=this.kernel.frame(this.frameName)),this._frame}useFrameAnchor(){const t=this._frame;if(!t)return;const e=(t.sw??t.w)/t.scale-t.margin*2,s=(t.sh??t.h)/t.scale-t.margin*2;this.anchorX=e>0?(t.ox-t.margin)/e:0,this.anchorY=s>0?(t.oy-t.margin)/s:0}draw(t,e,s){const i=this.frameNow();if(!i)return;const n=ve;this.sizeQ(i),n[2]=this.anchorX,n[3]=this.anchorY,n[4]=e,Na(t,i,this.world,this.slice,s,this.blend)}},ke=new Float64Array(12),we=new Float64Array(12),De={x:0,y:0,w:0,h:0};function en(t,e,s,i,n,r){e=Math.max(e,0),s=Math.max(s,0),i=Math.max(i,0);const a=s+i>n?s*n/(s+i):s,l=s+i>n?i*n/(s+i):i;let h=a/r,o=l/r;if(h+o>e){const f=e/(h+o);h*=f,o*=f}t[0]=0,t[1]=h,t[2]=0,t[3]=a,t[4]=h,t[5]=e-h-o,t[6]=a,t[7]=n-a-l,t[8]=e-o,t[9]=o,t[10]=n-l,t[11]=l}var ve=new Float64Array(5);function Na(t,e,s,i,n,r){const a=ve,l=a[0],h=a[1],o=a[2],f=a[3],u=a[4],c=t.tex(e.surface),y=i===0?e.slice??0:i;if(y===0){const w=(e.sw??e.w)/e.scale-e.margin*2,A=(e.sh??e.h)/e.scale-e.margin*2,C=w>0?l/w:1,R=A>0?h/A:1,O=-o*l+((e.tx??0)/e.scale-e.margin)*C,P=-f*h+((e.ty??0)/e.scale-e.margin)*R;is(s,O,P),j[0]=e.w/e.scale*C,j[1]=e.h/e.scale*R,j[2]=u,t.r.quadQ(c,e,ot,n,r);return}const p=e.tx??0,x=e.ty??0,m=(e.sw??e.w)-e.w-p,g=(e.sh??e.h)-e.h-x,k=-o*l-e.margin+p/e.scale,E=-f*h-e.margin+x/e.scale;if(en(ke,l+e.margin*2-(p+m)/e.scale,(typeof y=="number"?y:y[3])-p,(typeof y=="number"?y:y[1])-m,e.w,e.scale),en(we,h+e.margin*2-(x+g)/e.scale,(typeof y=="number"?y:y[0])-x,(typeof y=="number"?y:y[2])-g,e.h,e.scale),is(s,k,E),j[2]=u,!t.r.nineQ?.(c,e,ke,we,ot,n,r))for(let w=0;w<12;w+=4){const A=we[w+1],C=we[w+3];if(!(A<=0||C<=0))for(let R=0;R<12;R+=4){const O=ke[R+1],P=ke[R+3];O<=0||P<=0||(De.x=e.x+ke[R+2],De.y=e.y+we[w+2],De.w=P,De.h=C,is(s,k+ke[R],E+we[w]),j[0]=O,j[1]=A,j[2]=u,t.r.quadQ(c,De,ot,n,r))}}}function is(t,e,s){ot[0]=t[0],ot[1]=t[1],ot[2]=t[2],ot[3]=t[3],ot[4]=t[0]*e+t[2]*s+t[4],ot[5]=t[1]*e+t[3]*s+t[5]}var Be=class extends be{constructor(t,e,s={}){super(t,null),d(this,"_spec"),d(this,"baked",null),d(this,"bakedEffects",!0),this._spec=e,this.bake(),s.anchor===void 0&&this.useFrameAnchor(),this.set(s)}get spec(){return this._spec}set spec(t){this._spec=t,this.baked=null,this._w=this._h=null,this.bake()}bake(){const t=this.kernel;return this.baked&&t.atlas.valid(this.baked.frame)&&this.baked.frame.scale===t.pixelScale&&this.bakedEffects===t.effects?this.baked:(this.bakedEffects=t.effects,this.baked=t.shape(this._spec),this._frame=this.baked.frame,this.slice=this.baked.slice,this.baked)}frameNow(){return this.bake().frame}sizeQ(){const t=this.bake();ve[0]=this._w??t.w,ve[1]=this._h??t.h}get width(){return this._w??this.bake().w}set width(t){this._w=t}get height(){return this._h??this.bake().h}set height(t){this._h=t}},sn=(t,e,s)=>t===void 0?e:typeof t=="number"?t:t[0]+(t[1]-t[0])*s(),nn=class Qe extends le{constructor(e,s,i={}){super(e),d(this,"max"),d(this,"f"),d(this,"tints"),d(this,"count",0),d(this,"gravity"),d(this,"drag"),d(this,"frameRef"),d(this,"random",Math.random),this.frameRef=s,this.max=Math.max(1,Math.floor(i.max??200)),this.f=new Float32Array(this.max*Qe.W),this.tints=new Uint32Array(this.max),this.blend=i.blend??"normal",this.gravity=i.gravity??0,this.drag=i.drag??1}get alive(){return this.count}burst(e,s,i,n={}){const r=Qe.W,a=this.random,l=n.tint===void 0?16777215:Ut(n.tint)[0];for(let h=0;h<i;h++){let o=this.count;if(o>=this.max){let x=0,m=1/0;for(let g=0;g<this.max;g++){const k=this.f[g*r+5]-this.f[g*r+4];k<m&&(m=k,x=g)}o=x}else this.count++;const f=(n.angle??0)+(n.spread===void 0?a()*Math.PI*2:(a()-.5)*n.spread),u=sn(n.speed,200,a),c=Array.isArray(n.scale)?n.scale[0]:n.scale??1,y=Array.isArray(n.scale)?n.scale[1]:n.scale??1,p=o*r;this.f[p]=e,this.f[p+1]=s,this.f[p+2]=Math.cos(f)*u,this.f[p+3]=Math.sin(f)*u,this.f[p+4]=0,this.f[p+5]=Math.max(sn(n.life,.8,a),.01),this.f[p+6]=a()*Math.PI*2,this.f[p+7]=(a()-.5)*2*(n.spin??0),this.f[p+8]=c,this.f[p+9]=y,this.f[p+10]=n.alpha??1,this.tints[o]=l}}update(e){const s=Qe.W,i=this.f,n=this.drag>=1?1:Math.pow(Math.max(this.drag,0),e);for(let r=0;r<this.count;){const a=r*s;if(i[a+4]=i[a+4]+e,i[a+4]>=i[a+5]){const l=--this.count;r!==l&&(i.copyWithin(a,l*s,l*s+s),this.tints[r]=this.tints[l]);continue}i[a+3]=(i[a+3]+this.gravity*e)*n,i[a+2]=i[a+2]*n,i[a]=i[a]+i[a+2]*e,i[a+1]=i[a+1]+i[a+3]*e,i[a+6]=i[a+6]+i[a+7]*e,r++}}clear(){this.count=0}draw(e,s,i){if(!this.count)return;const n=typeof this.frameRef=="string"?this.frameRef=this.kernel.frame(this.frameRef):this.frameRef,r=Qe.W,a=this.f,l=this.world,h=n.w/n.scale,o=n.h/n.scale;for(let f=0;f<this.count;f++){const u=f*r,c=a[u+4]/a[u+5],y=a[u+8]+(a[u+9]-a[u+8])*c,p=s*a[u+10]*(1-c*c),x=a[u+6],m=Math.cos(x)*y,g=Math.sin(x)*y,k=a[u],E=a[u+1],w=l[0],A=l[1],C=l[2],R=l[3],O=w*m+C*g,P=A*m+R*g,I=C*m-w*g,q=R*m-A*g;ot[0]=O,ot[1]=P,ot[2]=I,ot[3]=q,ot[4]=w*k+C*E+l[4]-(O*h+I*o)/2,ot[5]=A*k+R*E+l[5]-(P*h+q*o)/2,j[0]=h,j[1]=o,j[2]=p,e.r.quadQ(e.tex(n.surface),n,ot,Wi(i,this.tints[f]),this.blend)}}};d(nn,"W",11);var rn=nn,ce=class extends be{constructor(t,e,s={}){const{fps:i,loop:n,playing:r,speed:a,onComplete:l,...h}=s;if(!e.frames.length)throw new Error("[engine] an animation needs at least one frame");super(t,e.frames[0],h),d(this,"frames"),d(this,"durations"),d(this,"fps"),d(this,"loop"),d(this,"speed"),d(this,"onComplete"),d(this,"_playing"),d(this,"index",0),d(this,"t",0),this.frames=e.frames,this.durations=e.durations&&i===void 0?e.durations:null,this.fps=i??12,this.loop=n!==!1,this.speed=a??1,this.onComplete=l??null,this._playing=r!==!1,this.speed<0&&this.show(e.frames.length-1)}get frameIndex(){return this.index}get frameCount(){return this.frames.length}get playing(){return this._playing}play(){return!this.loop&&!this._playing&&this.index===(this.speed<0?0:this.frames.length-1)&&this.show(this.speed<0?this.frames.length-1:0),this._playing=!0,this}stop(){return this._playing=!1,this}gotoFrame(t){const e=this.frames.length;return this.show((Math.floor(t)%e+e)%e),this.t=0,this}gotoAndPlay(t){return this._playing=!0,this.gotoFrame(t)}gotoAndStop(t){return this._playing=!1,this.gotoFrame(t)}show(t){t===this.index&&this._frame||(this.index=t,this.frame=this.frames[t])}secondsOf(t){const e=this.durations?.[t];return e!==void 0&&e>0?e:1/Math.max(this.fps,.001)}update(t){if(!this._playing||this.destroyed||this.speed===0)return;const e=this.frames.length,s=this.speed<0;this.t+=t*Math.abs(this.speed);let i=this.index;for(let n=0;n<1e3;n++){const r=this.secondsOf(i);if(this.t<r)break;this.t-=r;const a=s?i-1:i+1;if(a<0||a>=e){if(!this.loop){this.t=0,this._playing=!1,this.show(i),this.onComplete?.();return}i=s?e-1:0}else i=a}this.show(i)}},Ia=(t,e)=>t.localeCompare(e,void 0,{numeric:!0}),an=class{constructor(t,e,s=2){d(this,"width",t),d(this,"height",e),d(this,"padding",s),d(this,"shelves",[]),d(this,"free",[]),d(this,"bottom",0)}alloc(t,e){const s=Math.ceil(t)+this.padding*2,i=Math.ceil(e)+this.padding*2;if(s>this.width||i>this.height)return null;for(let a=0;a<this.free.length;a++){const l=this.free[a];if(l.w>=s&&l.h>=i&&l.w*l.h<=s*i*2)return this.free.splice(a,1),this.inner(l.x,l.y,t,e)}let n=null;for(const a of this.shelves)a.h>=i&&a.h<=i*1.5+8&&this.width-a.x>=s&&(!n||a.h<n.h)&&(n=a);if(!n)if(this.bottom+i>this.height){for(const a of this.shelves)a.h>=i&&this.width-a.x>=s&&(n=a);if(!n)return null}else n={y:this.bottom,h:i,x:0},this.shelves.push(n),this.bottom+=i;const r=n.x;return n.x+=s,this.inner(r,n.y,t,e)}release(t){this.free.push({x:t.x-this.padding,y:t.y-this.padding,w:Math.ceil(t.w)+this.padding*2,h:Math.ceil(t.h)+this.padding*2})}get fill(){return this.bottom/this.height}reset(){this.shelves=[],this.free=[],this.bottom=0}inner(t,e,s,i){return{x:t+this.padding,y:e+this.padding,w:s,h:i}}},ns=t=>({source:t,texture:null,pending:[]}),Ys=class{constructor(t=2048,e=4){d(this,"pageSize",t),d(this,"maxPages",e),d(this,"pages",[]),d(this,"gen",1),d(this,"onPage",()=>{}),d(this,"onDrop",()=>{})}valid(t){return!!t&&(t.gen===this.gen||t.gen===0)}bake(t,e,s,i=1,n=0,r=0,a=0){const l=Math.max(1,Math.ceil(t)),h=Math.max(1,Math.ceil(e)),o=document.createElement("canvas");o.width=l,o.height=h;const f=o.getContext("2d");return s(f),this.put(o,l,h,i,n,r,a)}add(t,e=1,s=0,i=0){const n=document.createElement("canvas");return n.width=Math.max(1,t.width),n.height=Math.max(1,t.height),n.getContext("2d").drawImage(t,0,0),this.put(n,n.width,n.height,e,s,i,0)}release(t){if(t.gen!==this.gen)return;this.pages.find(s=>s.surface===t.surface)?.packer.release(t)}rebake(t,e,s,i,n=t.w,r=t.h){if(!this.valid(t)||e>n||s>r)return null;const a=Math.max(1,Math.ceil(e)),l=Math.max(1,Math.ceil(s)),h=this.pages.find(f=>f.surface===t.surface);if(!h)return null;const o=document.createElement("canvas");return o.width=Math.ceil(n),o.height=Math.ceil(r),i(o.getContext("2d")),h.ctx.clearRect(t.x,t.y,o.width,o.height),h.ctx.drawImage(o,t.x,t.y),t.surface.pending.push([o,t.x,t.y]),t.w=a,t.h=l,t}put(t,e,s,i,n,r,a){let l=null,h=this.pages.find(f=>(l=f.packer.alloc(e,s))!==null);if(h||(!(Math.max(e,s)+4>this.pageSize)&&this.pages.length>=this.maxPages&&(this.wipe(),h=this.pages[0],l=h?h.packer.alloc(e,s):null),(!h||!l)&&(h=this.newPage(Math.max(e,s)),l=h.packer.alloc(e,s))),!l)throw new Error(`[engine] ${e}\xD7${s} does not fit an atlas page`);const o=l;return h.ctx.drawImage(t,o.x,o.y),h.surface.pending.push([t,o.x,o.y]),{surface:h.surface,x:o.x,y:o.y,w:e,h:s,scale:i,gen:this.gen,ox:n,oy:r,margin:a}}newPage(t){let e=this.pageSize;for(;e<t+4;)e*=2;const s=document.createElement("canvas");s.width=s.height=e;const i=s.getContext("2d"),n=ns(s),r={surface:n,packer:new an(e,e),ctx:i};return this.pages.push(r),this.onPage(n),r}wipe(){this.gen++;let t=0;for(let e=0;e<this.pages.length;e++){const s=this.pages[e];if(t<this.maxPages&&s.surface.source.width===this.pageSize){this.pages[t++]=s;continue}s.surface.pending=[],this.onDrop(s.surface)}this.pages.length=t;for(const e of this.pages)e.packer.reset(),e.ctx.clearRect(0,0,e.surface.source.width,e.surface.source.height),e.surface.pending=[],e.surface.pending.push([e.surface.source,0,0])}},Oa=()=>{const t=typeof document<"u"?document.timeline?.currentTime:null;return typeof t=="number"&&Number.isFinite(t)?t:globalThis.performance?.now()??Date.now()},on=()=>globalThis.performance?.now()??Date.now(),ln=class{constructor(t=Oa){d(this,"now",t),d(this,"known",new Map),d(this,"smoothed",new Map),d(this,"times",new WeakMap),d(this,"lerp",new fa),d(this,"drawnAt",NaN),d(this,"drawn",0),d(this,"smoothedBody",(e,s={})=>{const i=s.interpolate!==!1;if(typeof e=="number"){const n=this.smoothed.get(e);return n?i?this.lerp.at(e,this.tick())??n.body:n.body:null}return typeof e!="object"||e===null||!Array.isArray(e.body)?null:this.posed(e.id,e.body,za(s.smooth),i)})}note(t,e,s=on()){for(const i of t)this.known.set(i.id,this.resolve(i.id,i.avatar)),e!==void 0&&Number.isFinite(e)&&Array.isArray(i.body)&&this.times.set(i.body,{t:e,arrival:s})}of(t){return typeof t=="object"&&t!==null?t.avatar!==void 0?this.resolve(t.id,t.avatar):this.of(t.id):this.known.get(t)??_i(t-1)}posed(t,e,s,i=!0){const n=this.smooth(t,e,s);return i?this.lerp.at(t,this.tick())??n:n}smooth(t,e,s){const i=this.smoothed.get(t);if(i&&i.raw===e&&i.amount===s)return i.body;i&&i.amount!==s&&this.lerp.forget(t);const n=s<1?ma(i?.body,e,s):e;this.smoothed.set(t,{raw:e,body:n,amount:s});const r=this.times.get(e),a=r?.arrival??on();return this.lerp.push(t,r?.t??a,n,a),n}takeDrawn(){const t=this.drawn;return this.drawn=0,t}tick(){const t=this.now();return t!==this.drawnAt&&(this.drawnAt=t,this.drawn++),t}resolve(t,e){return da(e)?e:_i(t-1)}},za=t=>t===!1?1:typeof t=="number"?Math.min(Math.max(t,.05),1):.5,hn=new Float64Array(1),cn=new Int32Array(hn.buffer),Me=(t,e)=>(t=Math.imul(t^e,1540483477),t^t>>>15);function Kt(t,e=2538058380){return t!==t?Me(e,2146959360):(hn[0]=t===0?0:t,Me(Me(e,cn[0]),cn[1]))}function fn(t,e=2166136261){for(let s=0;s<t.length;s++)e=Math.imul(e^t.charCodeAt(s),16777619);return e}function Zt(t){switch(typeof t){case"number":return Kt(t);case"string":return fn(t);case"boolean":return t?1013904242:461845907;case"object":{if(t===null)return 625341585;if(Array.isArray(t)||t instanceof Float64Array){let i=1779033703^t.length;for(let n=0;n<t.length;n++){const r=t[n];i=Me(i,typeof r=="number"?Kt(r):Zt(r))}return i}let e=1359893119;const s=t;for(const i in s){const n=s[i];n!==void 0&&(e=e+Me(fn(i),Zt(n))|0)}return Me(e,2600822924)}default:return 0}}function Ue(t,e){if(t===e)return!0;if(typeof t!="object"||typeof e!="object"||t===null||e===null)return typeof t=="number"&&typeof e=="number"&&t!==t&&e!==e;const s=Array.isArray(t)||t instanceof Float64Array;if(s!==(Array.isArray(e)||e instanceof Float64Array))return!1;if(s){const r=t,a=e;if(r.length!==a.length)return!1;for(let l=0;l<r.length;l++)if(r[l]!==a[l]&&!Ue(r[l],a[l]))return!1;return!0}const i=t,n=e;for(const r in i)if(i[r]!==void 0&&!Ue(i[r],n[r]))return!1;for(const r in n)if(n[r]!==void 0&&i[r]===void 0)return!1;return!0}function rs(t){if(typeof t!="object"||t===null)return t;if(Array.isArray(t))return t.map(rs);if(t instanceof Float64Array)return t.slice();const e={};for(const s in t)t[s]!==void 0&&(e[s]=rs(t[s]));return e}var un=class{constructor(t=1/0){d(this,"max",t),d(this,"buckets",new Map),d(this,"n",0)}get size(){return this.n}get(t,e=Zt(t)){const s=this.buckets.get(e);if(s){for(let i=0;i<s.length;i++)if(Ue(s[i].key,t))return s[i].value}}set(t,e,s=Zt(t)){let i=this.buckets.get(s);if(i){for(const n of i)if(Ue(n.key,t)){n.value=e;return}}this.n>=this.max&&this.clear(),(!i||!this.buckets.has(s))&&this.buckets.set(s,i=[]),i.push({key:rs(t),value:e}),this.n++}clear(){this.buckets.clear(),this.n=0}},Qs=0,dn=1,as=2,js=3,pn=class{constructor(){d(this,"scale",1),d(this,"cOn",!1),d(this,"px0",0),d(this,"py0",0),d(this,"px1",0),d(this,"py1",0),d(this,"clipVer",0),d(this,"stack",[]),d(this,"sp",0),d(this,"real",0),d(this,"mute",0),d(this,"bnd",new Float64Array(4*(Hs+1))),d(this,"rx0",0),d(this,"ry0",0),d(this,"rx1",0),d(this,"ry1",0),d(this,"maxBlur",1/0),d(this,"time",0),d(this,"skipped",0),d(this,"gq",new Float64Array(4))}resetLayers(t){this.scale=t,this.sp=this.real=this.mute=0,this.skipped=0,this.cOn=!1,this.clipVer++}growQ(){const t=this.gq;this.grow(t[0],t[1],t[2],t[3])}grow(t,e,s,i){if(!this.real)return;const n=this.bnd,r=(this.real-1)*4;t<n[r]&&(n[r]=t),e<n[r+1]&&(n[r+1]=e),s>n[r+2]&&(n[r+2]=s),i>n[r+3]&&(n[r+3]=i)}area(t,e){const s=this.bnd,i=t*4,n=this.scale;return this.rx0=Math.max(Math.floor((s[i]-e)*n)-1,0),this.ry0=Math.max(Math.floor((s[i+1]-e)*n)-1,0),this.rx1=Math.min(Math.ceil((s[i+2]+e)*n)+1,this.canvas.width),this.ry1=Math.min(Math.ceil((s[i+3]+e)*n)+1,this.canvas.height),this.rx1>this.rx0&&this.ry1>this.ry0}clip(t,e,s,i){const n=this.scale,r=this.canvas.width,a=this.canvas.height,l=Math.min(Math.max(Math.round(t*n),0),r),h=Math.min(Math.max(Math.round(e*n),0),a),o=Math.min(Math.max(Math.round((t+s)*n),l),r),f=Math.min(Math.max(Math.round((e+i)*n),h),a);this.cOn&&l===this.px0&&h===this.py0&&o===this.px1&&f===this.py1||(this.cOn=!0,this.px0=l,this.py0=h,this.px1=o,this.py1=f,this.clipVer++)}unclip(){this.cOn&&(this.cOn=!1,this.clipVer++)}push(t){if(t<as&&(this.mute||this.real>=Hs||!this.pushLayer())&&(t+=2),t===js)this.mute++;else if(t!==as){const e=this.real*4;this.bnd[e]=this.bnd[e+1]=1/0,this.bnd[e+2]=this.bnd[e+3]=-1/0,this.real++}return this.stack[this.sp++]=t,t<as}beginLayer(){return this.push(Qs)}beginMask(){this.push(this.sp&&this.stack[this.sp-1]===Qs?dn:js)}endLayer(t,e){if(!this.sp)return;let s=this.stack[--this.sp];if(s===js){if(this.mute--,!this.sp)return;s=this.stack[--this.sp]}if(s===dn){const i=--this.real,n=this.popLayer();this.area(i-1,0)&&this.composite(n,!0,1,null);const r=this.bnd,a=(i-1)*4,l=i*4;r[a]=Math.max(r[a],r[l]),r[a+1]=Math.max(r[a+1],r[l+1]),r[a+2]=Math.min(r[a+2],r[l+2]),r[a+3]=Math.min(r[a+3],r[l+3]),s=this.stack[--this.sp]}if(s===as)Gs(e)&&(this.skipped+=e.length);else if(s===Qs){const i=--this.real,n=Gs(e)?e:null,r=this.popLayer();if(this.area(i,n?Fa(n,this.maxBlur):0)){this.composite(r,!1,t,n);const a=this.scale;this.grow(this.rx0/a,this.ry0/a,this.rx1/a,this.ry1/a)}}}closeLayers(){for(;this.sp;)this.endLayer(1)}},Da=256,yn=8<<20,bt=new Float64Array(32),kt={x:0,y:0,w:0,h:0};function Ba(t){if(typeof t.filter!="string")return!1;t.filter="blur(1px)";const e=t.filter==="blur(1px)";return t.filter="none",e}function Vs(t){const e=t.getContext("2d",{alpha:!0});return e?new Ua(t,e):null}var Ua=class extends pn{constructor(t,e){super(),d(this,"canvas",t),d(this,"ctx",e),d(this,"kind","canvas2d"),d(this,"maxTextureSize",4096),d(this,"features",{}),d(this,"info",{renderer:"canvas2d"}),d(this,"support"),d(this,"lost",!1),d(this,"fxr",null),d(this,"quads",0),d(this,"stats",{drawCalls:0,quads:0,filtersSkipped:0}),d(this,"tinted",new Map),d(this,"tintedN",0),d(this,"lostListeners",[]),d(this,"restoredListeners",[]),d(this,"base"),d(this,"top"),d(this,"layers",[]),d(this,"scratch",[]),d(this,"nines",new Map),d(this,"ninePx",0),d(this,"frame",0),d(this,"hit",!1),d(this,"missed",new Map),this.support={filters:Ba(e),shaders:!1},this.base=this.top={ctx:e,clipped:!1,ver:0},t.addEventListener("contextlost",()=>{this.lost=!0,this.lostListeners.forEach(s=>s())}),t.addEventListener("contextrestored",()=>{this.lost=!1,this.tinted.clear(),this.tintedN=0,this.dropNines(),this.restoredListeners.forEach(s=>s())})}resize(t,e){this.canvas.width!==t&&(this.canvas.width=t),this.canvas.height!==e&&(this.canvas.height=e)}createTexture(t){return{id:Xs(),width:t.width,height:t.height,source:t}}updateTexture(t,e,s=0,i=0){const n=e?s+e.width:1/0,r=e?i+e.height:1/0;for(const a of this.nines.values()){const l=a.key;l[0]===t.id&&l[1]<n&&l[1]+l[3]>s&&l[2]<r&&l[2]+l[4]>i&&this.dropNine(a)}for(const[a,l]of this.tinted){const h=l.filter(o=>o.id!==t.id);this.tintedN-=l.length-h.length,h.length?this.tinted.set(a,h):this.tinted.delete(a)}}destroyTexture(t){this.updateTexture(t)}begin(t,e,s){this.resetLayers(s),this.fxr?.tick(),this.frame++,this.quads=0,this.top=this.base,this.ctx=this.base.ctx;const i=this.ctx;this.base.clipped&&i.restore(),this.base.clipped=!1,this.base.ver=this.clipVer,i.setTransform(1,0,0,1,0,0),i.globalAlpha=1,i.globalCompositeOperation="source-over",i.clearRect(0,0,this.canvas.width,this.canvas.height),e>0&&(i.fillStyle=Ne(t,e),i.fillRect(0,0,this.canvas.width,this.canvas.height))}quad(t,e,s,i,n,r,a,l){j[0]=i,j[1]=n,j[2]=a,this.quadQ(t,e,s,r,l)}quadQ(t,e,s,i,n){e.w<=0||e.h<=0||(i===16777215?this.blit(t.source,e.x,e.y,e.w,e.h,s,n):this.blit(this.tint(t,e,i),0,0,e.w,e.h,s,n))}blit(t,e,s,i,n,r,a){const l=j[0],h=j[1],o=j[2];if(o<=0||this.mute)return;this.sync();const f=this.ctx,u=this.scale;if(this.real){const c=r[0]*l,y=r[1]*l,p=r[2]*h,x=r[3]*h;this.grow(r[4]+Math.min(0,c,p,c+p),r[5]+Math.min(0,y,x,y+x),r[4]+Math.max(0,c,p,c+p),r[5]+Math.max(0,y,x,y+x))}f.setTransform(r[0]*u,r[1]*u,r[2]*u,r[3]*u,r[4]*u,r[5]*u),f.globalAlpha=Math.min(o,1),a==="add"&&(f.globalCompositeOperation="lighter"),f.drawImage(t,e,s,i,n,0,0,l,h),a==="add"&&(f.globalCompositeOperation="source-over"),this.quads++}nineQ(t,e,s,i,n,r,a){var l,h;const o=s[8]+s[9],f=i[8]+i[9],u=Math.ceil(o*Math.hypot(n[0],n[1])*this.scale-1e-6),c=Math.ceil(f*Math.hypot(n[2],n[3])*this.scale-1e-6);if(n[1]===0&&n[2]===0||u>4096||c>4096)return!1;if(!(u>0&&c>0&&j[2]>0)||this.mute)return!0;let y=this.kept(t,e,s,i,u,c,r);const p=(y??(y=(l=this.scratch)[h=13*Math.ceil(Math.log2(u))+Math.ceil(Math.log2(c))]??(l[h]=document.createElement("canvas").getContext("2d")))).canvas;if(p.width<u&&(p.width=u),p.height<c&&(p.height=c),!this.hit){y.clearRect(0,0,u+2,c+2);for(let x=0;x<12;x+=4){const m=Math.round(i[x]*c/f),g=Math.round((i[x]+i[x+1])*c/f);for(let k=0;k<12;k+=4){const E=Math.round(s[k]*u/o),w=Math.round((s[k]+s[k+1])*u/o);kt.x=e.x+s[k+2],kt.y=e.y+i[x+2],kt.w=s[k+3],kt.h=i[x+3],!(w<=E||g<=m||kt.w<=0||kt.h<=0)&&(r===16777215?y.drawImage(t.source,kt.x,kt.y,kt.w,kt.h,E,m,w-E,g-m):y.drawImage(this.tint(t,kt,r),0,0,kt.w,kt.h,E,m,w-E,g-m))}}}return j[0]=o,j[1]=f,this.blit(p,0,0,u,c,n,a),!0}kept(t,e,s,i,n,r,a){bt[0]=t.id,bt[1]=e.x,bt[2]=e.y,bt[3]=e.w,bt[4]=e.h,bt[5]=n,bt[6]=r,bt[7]=a,bt.set(s,8),bt.set(i,20);const l=Zt(bt),h=this.nines.get(l);if(this.hit=!1,h)return Ue(h.key,bt)?(h.used=this.frame,this.hit=!0,h.ctx):null;const o=this.missed,f=o.get(l);o.size>4096&&o.clear(),o.set(l,this.frame);const u=n*r;if(f!==this.frame-1||u>yn)return null;let c;for(;this.ninePx+u>yn;){let x;for(const k of this.nines.values())k.used<this.frame-1&&!(x&&x.used<=k.used)&&(x=k);if(!x)return null;const m=x.ctx.canvas,g=!c&&m.width>=n&&m.height>=r&&m.width*m.height<=2*u;this.dropNine(x,g),g&&(c=x.ctx)}const y=c??document.createElement("canvas").getContext("2d"),p=y.canvas;return c||(p.width=n,p.height=r),this.ninePx+=p.width*p.height,this.nines.set(l,{key:rs(bt),ctx:y,used:this.frame}),y}dropNine(t,e=!1){this.nines.delete(Zt(t.key));const s=t.ctx.canvas;this.ninePx-=s.width*s.height,e||(s.width=0)}dropNines(){for(const t of this.nines.values())this.dropNine(t)}tint(t,e,s){const i=Kt(s,Kt(e.h,Kt(e.w,Kt(e.y,Kt(e.x,Kt(t.id))))));let n=this.tinted.get(i);if(n)for(let l=0;l<n.length;l++){const h=n[l];if(h.id===t.id&&h.x===e.x&&h.y===e.y&&h.w===e.w&&h.h===e.h&&h.color===s)return h.canvas}this.tintedN>=Da&&(this.tinted.clear(),this.tintedN=0,n=void 0);const r=document.createElement("canvas");r.width=Math.ceil(e.w),r.height=Math.ceil(e.h);const a=r.getContext("2d");return a.drawImage(t.source,e.x,e.y,e.w,e.h,0,0,e.w,e.h),a.globalCompositeOperation="multiply",a.fillStyle=Ne(s),a.fillRect(0,0,e.w,e.h),a.globalCompositeOperation="destination-in",a.drawImage(t.source,e.x,e.y,e.w,e.h,0,0,e.w,e.h),n||this.tinted.set(i,n=[]),n.push({id:t.id,x:e.x,y:e.y,w:e.w,h:e.h,color:s,canvas:r}),this.tintedN++,r}paint(t,e){this.sync();const s=this.ctx,i=this.scale;return s.setTransform(i,0,0,i,0,0),s.globalAlpha=Math.min(e,1),Ne(t)}ellipse(t,e,s,i,n,r,a){if(a<=0||s<=0||i<=0||this.mute)return;const l=Math.max(s,i);this.grow(t-l,e-l,t+l,e+l);const h=this.ctx;h.fillStyle=this.paint(r,a),h.beginPath(),h.ellipse(t,e,s,i,n,0,Math.PI*2),h.fill(),this.quads++}trace(t,e,s=0){if(this.real)for(let n=0;n<e;n++)this.grow(t[n*2]-s,t[n*2+1]-s,t[n*2]+s,t[n*2+1]+s);const i=this.ctx;i.beginPath(),i.moveTo(t[0],t[1]);for(let n=1;n<e;n++)i.lineTo(t[n*2],t[n*2+1])}polygon(t,e,s,i){if(i<=0||e<3||this.mute)return;const n=this.ctx;n.fillStyle=this.paint(s,i),this.trace(t,e),n.closePath(),n.fill(),this.quads++}stroke(t,e,s,i,n,r){if(n<=0||s<=0||e<1||this.mute)return;const a=this.ctx;a.strokeStyle=this.paint(i,n),a.lineWidth=s,a.lineCap="round",a.lineJoin="round",this.trace(t,e,s/2),e===1&&a.lineTo(t[0],t[1]),r&&a.closePath(),a.stroke(),this.quads++}sync(){const t=this.top;if(t.ver===this.clipVer)return;const e=t.ctx;t.clipped&&e.restore(),t.clipped=this.cOn,t.ver=this.clipVer,this.cOn&&(e.save(),e.setTransform(1,0,0,1,0,0),e.beginPath(),e.rect(this.px0,this.py0,this.px1-this.px0,this.py1-this.py0),e.clip())}pushLayer(){const t=this.canvas.width,e=this.canvas.height;let s=this.layers[this.real];if(!s||s.ctx.canvas.width!==t||s.ctx.canvas.height!==e){const n=document.createElement("canvas");n.width=t,n.height=e;const r=n.getContext("2d");if(!r)return!1;s=this.layers[this.real]={ctx:r,clipped:!1,ver:-1}}const i=s.ctx;return s.clipped&&i.restore(),s.clipped=!1,s.ver=-1,i.setTransform(1,0,0,1,0,0),i.globalAlpha=1,i.globalCompositeOperation="source-over",i.clearRect(0,0,t,e),this.top=s,this.ctx=i,!0}popLayer(){return this.top=this.real>0?this.layers[this.real-1]:this.base,this.ctx=this.top.ctx,this.layers[this.real].ctx.canvas}composite(t,e,s,i){let n=t,r="none";const a=i&&Gt.c2d?this.fxr??(this.fxr=Gt.c2d(this)):null;a&&(n=a.chain(t,i),r=a.css),this.sync();const l=this.ctx,h=this.rx0,o=this.ry0,f=this.rx1-h,u=this.ry1-o;l.setTransform(1,0,0,1,0,0),l.globalAlpha=Math.min(s,1),l.globalCompositeOperation=e?"destination-in":"source-over",r!=="none"&&(l.filter=r),l.drawImage(n,h,o,f,u,h,o,f,u),r!=="none"&&(l.filter="none"),l.globalCompositeOperation="source-over",this.quads++}end(){this.closeLayers();const t=this.stats;return t.drawCalls=t.quads=this.quads,t.filtersSkipped=this.skipped,t}onLost(t){this.lostListeners.push(t)}onRestored(t){this.restoredListeners.push(t)}destroy(){this.tinted.clear(),this.dropNines(),this.layers=[],this.scratch=[],this.fxr?.destroy(),this.fxr=null}},Ge=14,Ee=6,mn=8192,Ga=class{constructor(t,e,s=mn){d(this,"instanced",t),d(this,"slots",e),d(this,"capacity",s),d(this,"f32"),d(this,"u32"),d(this,"quads",0),d(this,"textures"),d(this,"bound",0),this.textures=new Array(e).fill(null);const i=s*(t?Ge:Ee*4),n=new ArrayBuffer(i*4);this.f32=new Float32Array(n),this.u32=new Uint32Array(n)}slot(t){const e=this.textures;for(let s=0;s<this.bound;s++)if(e[s]===t)return s;return this.bound>=this.slots?-1:(e[this.bound]=t,this.bound++)}has(t){for(let e=0;e<this.bound;e++)if(this.textures[e]===t)return!0;return!1}get full(){return this.quads>=this.capacity}get words(){return this.quads*(this.instanced?Ge:Ee*4)}reset(){this.quads=0;for(let t=0;t<this.bound;t++)this.textures[t]=null;this.bound=0}push(t,e,s,i,n,r,a,l,h,o,f,u,c,y){const p=this.f32;if(this.instanced){let x=this.quads*Ge;p[x++]=t,p[x++]=e,p[x++]=s,p[x++]=i,p[x++]=n,p[x++]=r,p[x++]=a,p[x++]=l,p[x++]=h,p[x++]=o,p[x++]=f,p[x++]=u,this.u32[x++]=c,p[x]=y}else{const x=this.quads*Ee*4;this.vertex(x,t,e,h,o,c,y),this.vertex(x+6,s,i,f,o,c,y),this.vertex(x+12,n,r,f,u,c,y),this.vertex(x+18,a,l,h,u,c,y)}this.quads++}pushQ(t,e){const s=this.f32;if(this.instanced){const i=this.quads*Ge;for(let n=0;n<12;n++)s[i+n]=t[n];this.u32[i+12]=t[12],s[i+13]=e}else{let i=this.quads*Ee*4;const n=t[12];for(let r=0;r<4;r++,i+=Ee)s[i]=t[r*2],s[i+1]=t[r*2+1],s[i+2]=r===1||r===2?t[10]:t[8],s[i+3]=r>=2?t[11]:t[9],this.u32[i+4]=n,s[i+5]=e}this.quads++}vertex(t,e,s,i,n,r,a){const l=this.f32;l[t]=e,l[t+1]=s,l[t+2]=i,l[t+3]=n,this.u32[t+4]=r,l[t+5]=a}};function Ha(t){const e=new Uint16Array(t*6);for(let s=0,i=0,n=0;s<t;s++,i+=6,n+=4)e[i]=n,e[i+1]=n+1,e[i+2]=n+2,e[i+3]=n,e[i+4]=n+2,e[i+5]=n+3;return e}var wt={M:0,L:1,Q:2,C:3,Z:4},xn=[2,2,4,6,0],Xa={M:0,L:1,Q:2,C:3,Z:4};function Ks(t,e){if(t.length>=e)return t;const s=new Float64Array(Math.max(e,t.length*2,16));return s.set(t),s}var os=new Map;function $a(t){if(typeof t!="string")return t;let e=os.get(t);if(e)return e;e=[];const s=t.match(/[MLQCZ]|-?\d*\.?\d+(?:e-?\d+)?/gi)??[];let i=-1;for(let n=0;n<s.length;){const r=s[n],a=Xa[r.toUpperCase()];if(a!==void 0){i=a,n++,a===wt.Z&&e.push(wt.Z);continue}if(i<0||i===wt.Z){n++;continue}const l=xn[i];e.push(i);for(let h=0;h<l;h++)e.push(Number(s[n+h]??0));n+=l,i===wt.M&&(i=wt.L)}return os.size>256&&os.clear(),os.set(t,e),e}var Jt={subs:[],count:0},Zs=null,te=null;function ls(t,e){let s=te;s||(s=Jt.subs[Jt.count]??null,s||Jt.subs.push(s={pts:new Float64Array(64),n:0,closed:!1}),s.n=0,s.closed=!1,Jt.count++,te=s);const i=s.n*2;i+2>s.pts.length&&(s.pts=Ks(s.pts,i+2));const n=Zs;n?(s.pts[i]=n[0]*t+n[2]*e+n[4],s.pts[i+1]=n[1]*t+n[3]*e+n[5]):(s.pts[i]=t,s.pts[i+1]=e),s.n++}function Js(t,e=null,s=1,i=6){const n=$a(t);Jt.count=0,te=null,Zs=e;let r=0,a=0,l=0,h=0;const o=s/i;for(let f=0;f<n.length;){const u=n[f++],c=n;if(u===wt.M)te=null,r=l=c[f],a=h=c[f+1],ls(r,a);else if(u===wt.L)r=c[f],a=c[f+1],ls(r,a);else if(u===wt.Q){const y=c[f],p=c[f+1],x=c[f+2],m=c[f+3],g=gn(($t(y-r,p-a)+$t(x-y,m-p))*o);for(let k=1;k<=g;k++){const E=k/g,w=1-E;ls(w*w*r+2*w*E*y+E*E*x,w*w*a+2*w*E*p+E*E*m)}r=x,a=m}else if(u===wt.C){const y=c[f],p=c[f+1],x=c[f+2],m=c[f+3],g=c[f+4],k=c[f+5],E=gn(($t(y-r,p-a)+$t(x-y,m-p)+$t(g-x,k-m))*o);for(let w=1;w<=E;w++){const A=w/E,C=1-A,R=C*C*C,O=3*C*C*A,P=3*C*A*A,I=A*A*A;ls(R*r+O*y+P*x+I*g,R*a+O*p+P*m+I*k)}r=g,a=k}else if(u===wt.Z){te&&(te.closed=!0),te=null,r=l,a=h;continue}else break;f+=xn[u]}te=null,Zs=null;for(let f=0;f<Jt.count;f++){const u=Jt.subs[f],c=u.n*2;u.closed&&u.n>=2&&Math.abs(u.pts[0]-u.pts[c-2])<1e-6&&Math.abs(u.pts[1]-u.pts[c-1])<1e-6&&u.n--}return Jt}var $t=(t,e)=>Math.sqrt(t*t+e*e),gn=t=>Math.min(Math.max(Math.ceil(t),2),24);function qa(t,e){let s=0;for(let i=0,n=e-1;i<e;n=i++)s+=(t[n*2]-t[i*2])*(t[n*2+1]+t[i*2+1]);return s}var hs=new Int32Array(64),cs=(t,e,s,i,n)=>((t[i*2]-t[s*2])*(t[n*2+1]-t[s*2+1])-(t[i*2+1]-t[s*2+1])*(t[n*2]-t[s*2]))*e;function Wa(t,e,s){if(e<3)return 0;hs.length<e&&(hs=new Int32Array(Math.max(e,hs.length*2)));const i=hs;let n=e,r=0;for(let o=0;o<e;o++)i[o]=o;const a=qa(t,e)>0?1:-1;let l=e*e+8,h=0;for(;n>3&&l-- >0;){const o=i[(h+n-1)%n],f=i[h%n],u=i[(h+1)%n];let c=cs(t,a,o,f,u)>0;if(c)for(let y=0;y<n;y++){const p=i[y];if(!(p===o||p===f||p===u)&&cs(t,a,o,f,p)>=0&&cs(t,a,f,u,p)>=0&&cs(t,a,u,o,p)>=0){c=!1;break}}c?(s[r++]=o,s[r++]=f,s[r++]=u,i.copyWithin(h%n,h%n+1,n),n--,h=Math.max(h-1,0)):h=(h+1)%n}if(n===3)s[r++]=i[0],s[r++]=i[1],s[r++]=i[2];else if(n>3)for(let o=1;o+1<n;o++)s[r++]=i[0],s[r++]=i[o],s[r++]=i[o+1];return r}var Ya=.85,fs=new Float64Array(64),bn=new Float64Array(64),kn=new Float64Array(64),wn=new Float64Array(64),vn=new Float64Array(64),Mn=new Float64Array(64),En=new Uint8Array(64),us=new Float64Array(8);function Qa(t,e,s,i,n,r){const a=us;if(fs.length<e){const m=Math.max(e,fs.length*2);fs=new Float64Array(m),bn=new Float64Array(m),kn=new Float64Array(m),wn=new Float64Array(m),vn=new Float64Array(m),Mn=new Float64Array(m),En=new Uint8Array(m)}const l=fs,h=bn;let o=0;for(let m=0;m<e;m++){const g=t[m*2],k=t[m*2+1];!Number.isFinite(g)||!Number.isFinite(k)||o&&Math.abs(l[o-1]-g)<.001&&Math.abs(h[o-1]-k)<.001||(l[o]=g,h[o]=k,o++)}if(i&&o>2&&Math.abs(l[0]-l[o-1])<.001&&Math.abs(h[0]-h[o-1])<.001&&o--,o===0)return;if(o===1)return a[0]=l[0],a[1]=h[0],r();const f=i?o:o-1,u=kn,c=wn;for(let m=0;m<f;m++){const g=(m+1)%o,k=l[g]-l[m],E=h[g]-h[m],w=$t(k,E)||1;u[m]=-E/w,c[m]=k/w}const y=vn,p=Mn,x=En;for(let m=0;m<o;m++){const g=i?(m-1+f)%f:m-1,k=m<f?m:-1;if(x[m]=1,g<0||k<0||u[g]*u[k]+c[g]*c[k]<Ya)continue;let w=u[g]+u[k],A=c[g]+c[k];const C=$t(w,A)||1;w/=C,A/=C;const R=s/Math.max(w*u[k]+A*c[k],.5);y[m]=w*R,p[m]=A*R,x[m]=0}for(let m=0;m<f;m++){const g=(m+1)%o,k=x[m]?u[m]*s:y[m],E=x[m]?c[m]*s:p[m],w=x[g]?u[m]*s:y[g],A=x[g]?c[m]*s:p[g];a[0]=l[m]+k,a[1]=h[m]+E,a[2]=l[g]+w,a[3]=h[g]+A,a[4]=l[g]-w,a[5]=h[g]-A,a[6]=l[m]-k,a[7]=h[m]-E,n()}for(let m=0;m<o;m++)x[m]&&(a[0]=l[m],a[1]=h[m],r())}function An(t,e){let s=0,i=1/0;for(let n=0;n<e.length;n++){const r=Math.abs(Math.log(Math.max(t,.5)/e[n]));r<i&&(i=r,s=n)}return s}var Tt=256,ti=[{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}],ei=[4,8,16,32,64,128].map((t,e)=>({x:e*4,y:128,w:4,h:t,r:t/2-1})),ee={x:248,y:248,w:8,h:8},ja=ti.map(t=>t.r*2),Va=ei.map(t=>t.r*2),_n=(t,e)=>Math.min(Math.max(t+.5-e,0),1);function Ka(){const t=new Uint8ClampedArray(Tt*Tt*4),e=(s,i,n)=>{const r=(i*Tt+s)*4;t[r]=t[r+1]=t[r+2]=255,t[r+3]=Math.round(n*255)};for(const s of ti){const i=s.w/2;for(let n=0;n<s.h;n++)for(let r=0;r<s.w;r++)e(s.x+r,s.y+n,_n(s.r,Math.hypot(r+.5-i,n+.5-i)))}for(const s of ei){const i=s.h/2;for(let n=0;n<s.h;n++)for(let r=0;r<s.w;r++)e(s.x+r,s.y+n,_n(s.r,Math.abs(n+.5-i)))}for(let s=0;s<ee.h;s++)for(let i=0;i<ee.w;i++)e(ee.x+i,ee.y+s,1);return t}function Za(){const t=document.createElement("canvas");return t.width=t.height=Tt,t.getContext("2d").putImageData(new ImageData(Ka(),Tt,Tt),0,0),t}var Tn=8,si=`
1
+ /*! @fabi-play/engine 0.7.0 (full) | Fabi Play Kit License | https://docs.fabiplay.app */(function(Ai,re){var Ze=typeof document<"u"?document.currentScript:null;typeof define=="function"&&define.amd?define([],function(){return re(Ze)}):typeof module=="object"&&module&&module.exports?module.exports=re(Ze):Ai.FabiEngine=re(Ze)})(typeof globalThis<"u"?globalThis:typeof self<"u"?self:this,function(Ai){"use strict";var re={exports:{}},Ze=re.exports,Je=Object.defineProperty,gr=Object.getOwnPropertyDescriptor,br=Object.getOwnPropertyNames,kr=Object.prototype.hasOwnProperty,wr=(t,e,s)=>e in t?Je(t,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[e]=s,vr=(t,e)=>{for(var s in e)Je(t,s,{get:e[s],enumerable:!0})},Mr=(t,e,s,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of br(e))!kr.call(t,n)&&n!==s&&Je(t,n,{get:()=>e[n],enumerable:!(i=gr(e,n))||i.enumerable});return t},Er=t=>Mr(Je({},"__esModule",{value:!0}),t),d=(t,e,s)=>wr(t,typeof e!="symbol"?e+"":e,s),_i={};vr(_i,{AnimatedSprite:()=>fe,Atlas:()=>Ks,AvatarPainter:()=>fi,AvatarsNode:()=>tr,BitmapFont:()=>ui,DEFAULT_FONT:()=>On,EASE:()=>ze,Group:()=>js,HALO:()=>$e,MAX_LAYERS:()=>Ws,NameTags:()=>hi,Node:()=>he,NodePool:()=>hr,Particles:()=>fn,STAGE_HEIGHT:()=>ft,Shape:()=>He,ShelfPacker:()=>un,Sound:()=>qn,Sprite:()=>we,TIERS:()=>qt,Text:()=>qe,Timeline:()=>Zn,Tweens:()=>Jn,avatarPortrait:()=>So,blur:()=>Pl,brightness:()=>El,colorMatrix:()=>Fl,contrast:()=>Al,createAvatarRenderer:()=>_o,createEngine:()=>jo,createRenderer:()=>oi,dropShadow:()=>Ll,grayscale:()=>Sl,handsOf:()=>Gn,hits:()=>di,hueRotate:()=>Cl,invert:()=>Rl,nodePool:()=>Ul,packColor:()=>ke,parseBMFont:()=>ks,parseColor:()=>Bt,pickTier:()=>Wn,playerColor:()=>ws,rendererOrder:()=>In,rng:()=>Oa,saturate:()=>_l,sepia:()=>Tl,shader:()=>Nl,shapeBounds:()=>ci,tier:()=>ue,tint:()=>Ml,touching:()=>Xn,wrists:()=>Hn}),re.exports=Er(_i);var Si=33,U={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},Ar=["3-5","6-8","9-12"],_r=t=>Ar.includes(t),Sr=4,ts=["#EE6A43","#6FA0E0","#8CC9A0","#C49BE0"],Ti={"3-5":["bunny","bear","panda","penguin"],"6-8":["fox","lion","dragon","unicorn"],"9-12":["robot","astronaut","ninja","skater"]},Tr=Ti["6-8"],Ci=(t,e)=>{const s=_r(e)?Ti[e]:Tr;return s[Number.isInteger(t)&&t>=0?t%s.length:0]},Ri=(t,e)=>t?{x:t.x+e.x*t.w,y:t.y+e.y*t.h}:{x:e.x,y:e.y},Cr=.5,es={left:1.6,top:1.6,w:3.2,h:3},Rr=1.2;function Fr(t,e,s={}){const i=Array.isArray(t)?t:t.body;if(!Array.isArray(i))return null;const n=e==="left"?U.leftWrist:U.rightWrist,r=g=>Fe(i[g*3])&&Fe(i[g*3+1])&&(i[g*3+2]??0)>=Cr?g:-1;if(r(n)<0)return null;const a=i[n*3],l=i[n*3+1];if(s.orientation!=="portrait")return Ri(s.view,{x:a,y:l});if(r(U.leftShoulder)<0||r(U.rightShoulder)<0)return null;const h=U.leftShoulder*3,o=U.rightShoulder*3,c=(i[h]+i[o])/2,u=(i[h+1]+i[o+1])/2,f=U.leftHip*3,y=U.rightHip*3,p=(i[f]+i[y])/2,x=(i[f+1]+i[y+1])/2;let m=Fe(p)&&Fe(x)?Math.hypot(p-c,x-u):0;return(r(U.leftHip)<0||r(U.rightHip)<0)&&(m=Math.max(m,Rr*Math.hypot(i[h]-i[o],i[h+1]-i[o+1]))),m=Math.max(m,.01),{x:Pi((a-c+es.left*m)/(es.w*m)),y:Pi((l-u+es.top*m)/(es.h*m))}}var Pr=300,Fi=class{constructor(t=Pr){d(this,"holdMs",t),d(this,"last",new Map)}static key(t,e){return t*2+(e==="right"?1:0)}at(t,e,s){const i=this.last.get(t);return e?(i?(i.x=e.x,i.y=e.y,i.t=s):this.last.set(t,{x:e.x,y:e.y,t:s}),e):i?s-i.t<=this.holdMs?{x:i.x,y:i.y}:(this.last.delete(t),null):null}clear(){this.last.clear()}},Lr=.25,Nr=Object.freeze({top:0,bottom:0,left:0,right:0});function Ir(t){if(!Or(t))return;const e=s=>Fe(s)?Math.min(Math.max(s,0),Lr):0;return{top:e(t.top),bottom:e(t.bottom),left:e(t.left),right:e(t.right)}}var Ql=16/9,Or=t=>typeof t=="object"&&t!==null&&!Array.isArray(t),Fe=t=>typeof t=="number"&&Number.isFinite(t),Pi=t=>Math.min(Math.max(t,0),1),zr=12,Dr=Si*4,Br=t=>zr+t*Dr,jl=Br(Sr),Ur=t=>t.startsWith("fabi-play.")?`fablee-play.${t.slice(10)}`:null;function Hr(t,e,s=Ur(e)){if(!(!t||!s))try{const i=t.getItem(s);if(i===null)return;t.getItem(e)===null&&t.setItem(e,i),t.removeItem(s)}catch{}}var xt="#4a382c",ht="#2b2118",Et="#1c1f2b",Li="#fbefe3",Ft="#f4897a",Pe="#3a2a22",Ni=[{id:"fox",name:{en:"Fox",it:"Volpe"},band:"6-8",palette:{body:"#ee6a43",limbs:"#ee6a43",belly:Li,accent:"#ffd9c2",outline:ht,hands:"#5a3426",feet:"#5a3426"},head:"wide",ears:"pointy",face:{eyes:"dot",mouth:"cat",nose:Pe,muzzle:"cheeks"},tail:"fluffy",headExtras:[],bodyExtras:[]},{id:"mascot",name:{en:"Fabi",it:"Fabi"},band:"all",special:!0,palette:{body:"#ee6a43",limbs:"#ee6a43",belly:Li,accent:"#5a3426",outline:ht,hands:"#5a3426",feet:"#5a3426"},head:"wide",ears:"pointy",face:{eyes:"bead",mouth:"open",nose:Pe,muzzle:"band",cheeks:Ft},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:xt},head:"round",ears:"long",face:{eyes:"dot",mouth:"cat",nose:"#e0607e",muzzle:"none",cheeks:Ft},tail:"pom",headExtras:[],bodyExtras:[]},{id:"bear",name:{en:"Bear",it:"Orsetto"},band:"3-5",palette:{body:"#cf9f78",limbs:"#cf9f78",belly:"#f7e0bf",accent:"#f7e0bf",outline:xt},head:"round",ears:"round",face:{eyes:"dot",mouth:"smile",nose:Pe,muzzle:"oval",cheeks:Ft},tail:"none",headExtras:[],bodyExtras:[]},{id:"cat",name:{en:"Cat",it:"Gattino"},band:"3-5",palette:{body:"#c8b6ee",limbs:"#c8b6ee",belly:"#f4eeff",accent:"#f7b3c8",outline:xt,hands:"#f4eeff",feet:"#f4eeff"},head:"wide",ears:"pointy",face:{eyes:"big",eyeColor:"#3f9a5a",mouth:"cat",nose:"#f07a9a",muzzle:"none",cheeks:Ft},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:xt,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:xt,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:xt},head:"wide",ears:"none",face:{eyes:"big",eyesOnTop:!0,mouth:"open",muzzle:"none",cheeks:"#f59b8f"},tail:"none",headExtras:[],bodyExtras:["flippers","spots"],extraColors:["#62ad62","#b0e6a4"]},{id:"lion",name:{en:"Lion",it:"Leoncino"},band:"6-8",alsoIn:["3-5"],palette:{body:"#f6c454",limbs:"#f6c454",belly:"#fde7b0",accent:"#fde7b0",outline:ht},head:"round",ears:"round",face:{eyes:"dot",mouth:"cat",nose:"#8a4b2a",muzzle:"oval",cheeks:Ft},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:ht,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:ht},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:Et,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:Et,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:ht},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:ht,hands:"#f2c9a0",feet:"#f2c9a0"},head:"round",ears:"side",face:{eyes:"dot",mouth:"open",nose:"#5a3a26",muzzle:"monkey",cheeks:Ft},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:xt},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:ht},head:"wide",ears:"round",face:{eyes:"dot",mouth:"cat",nose:"#e2607a",muzzle:"oval",cheeks:Ft},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:xt,feet:"#f9b95c",hands:"#639cc9"},head:"tall",ears:"tufts",face:{eyes:"big",eyeColor:xt,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:Et},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:ht},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:ht,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:xt,hands:"#ffc23d",feet:"#ffa04a"},head:"round",ears:"none",face:{eyes:"dot",mouth:"beak",muzzle:"none",cheeks:Ft},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:xt,ears:"#b58262",hands:"#e6caa6",feet:"#e6caa6"},head:"wide",ears:"floppy",face:{eyes:"dot",mouth:"open",nose:Pe,muzzle:"oval",cheeks:Ft},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:xt,skin:"#f7dccb",hands:"#a58c7e",feet:"#a58c7e"},head:"round",ears:"droopy",face:{eyes:"dot",mouth:"smile",nose:"#e591a0",muzzle:"none",cheeks:Ft},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:xt,feet:"#ff9f43"},head:"tall",ears:"none",face:{eyes:"dot",mouth:"bill",muzzle:"none",cheeks:Ft},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:ht,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:ht,hands:"#5a647a",feet:"#5a647a"},head:"round",ears:"pointy",face:{eyes:"dot",mouth:"open",nose:Pe,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:ht,hands:"#3a9bdc",feet:"#8a7a70"},head:"round",ears:"none",face:{eyes:"big",eyeColor:ht,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:Et,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:Et,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:Et,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:Et,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:Et,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:Et,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:Et,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:Et,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:Et,skin:"#5a3825",hair:"#141010",hands:"#e0403a",feet:"#e0403a"},head:"round",ears:"human",face:{eyes:"calm",mouth:"smirk",muzzle:"none",brows:"#141010"},tail:"none",headExtras:["hair","domino"],bodyExtras:["cape","emblem","boots"],extraColors:["#ffd84a"]},{id:"trex",name:{en:"T-Rex",it:"T-Rex"},band:"6-8",alsoIn:["3-5"],palette:{body:"#6cb84e",limbs:"#6cb84e",belly:"#f4e8a8",accent:"#f4e8a8",outline:ht},head:"snout-long",ears:"none",face:{eyes:"dot",mouth:"toothy",muzzle:"none",cheeks:"#f59b8f"},tail:"thick",headExtras:["stripes"],bodyExtras:["tiny-arms","strong-legs"],extraColors:["#4a9235","#58a23f"]},{id:"fairy",name:{en:"Fairy",it:"Fatina"},band:"6-8",alsoIn:["3-5"],palette:{body:"#b99af0",limbs:"#a8693f",belly:"#b99af0",accent:"#ffd84a",outline:ht,skin:"#a8693f",hair:"#2e1d17",hands:"#a8693f",feet:"#f58cbc"},head:"round",ears:"pixie",face:{eyes:"dot",mouth:"smile",muzzle:"none",cheeks:"#f0857a"},tail:"none",headExtras:["bun","flower-crown"],bodyExtras:["wings-fairy","petals","wand"],extraColors:["#c4ecff","#f7a8cf","#fff3a0","#ffffff"]}],rt={M:0,L:1,Q:2,C:3,Z:4},Ii=[2,2,4,6,0];function Ns(t,e){for(const s of e)Gr(t,s)}function Gr(t,e){if(e.k==="group"){t.save(),t.translate(e.x,e.y),e.rot&&t.rotate(e.rot),e.s!==void 0&&e.s!==1&&t.scale(e.s,e.s),e.alpha!==void 0&&(t.globalAlpha*=e.alpha),Ns(t,e.items),t.restore();return}switch(t.save(),e.alpha!==void 0&&(t.globalAlpha*=e.alpha),t.beginPath(),e.k){case"circle":t.arc(e.x,e.y,Math.max(e.r,0),0,Math.PI*2);break;case"ellipse":t.ellipse(e.x,e.y,Math.max(e.rx,0),Math.max(e.ry,0),e.rot??0,0,Math.PI*2);break;case"rect":Xr(t,e);break;case"path":typeof e.d=="string"?Wr(t,e.d):$r(t,e.d);break;case"line":t.moveTo(e.pts[0]??0,e.pts[1]??0);for(let s=2;s+1<e.pts.length;s+=2)t.lineTo(e.pts[s],e.pts[s+1]);break}t.lineCap="round",t.lineJoin="round",e.fill&&e.k!=="line"&&(t.fillStyle=e.fill,t.fill()),e.stroke&&(e.lw??1)>0&&(t.strokeStyle=e.stroke,t.lineWidth=e.lw??1,t.stroke()),t.restore()}function Xr(t,e){const s=Math.max(0,Math.min(e.r,e.w/2,e.h/2));t.translate(e.x,e.y),e.rot&&t.rotate(e.rot);const i=-e.w/2,n=-e.h/2;t.moveTo(i+s,n),t.lineTo(i+e.w-s,n),t.quadraticCurveTo(i+e.w,n,i+e.w,n+s),t.lineTo(i+e.w,n+e.h-s),t.quadraticCurveTo(i+e.w,n+e.h,i+e.w-s,n+e.h),t.lineTo(i+s,n+e.h),t.quadraticCurveTo(i,n+e.h,i,n+e.h-s),t.lineTo(i,n+s),t.quadraticCurveTo(i,n,i+s,n),t.closePath()}function $r(t,e){for(let s=0;s<e.length;){const i=e[s++];if(i===rt.M)t.moveTo(e[s],e[s+1]);else if(i===rt.L)t.lineTo(e[s],e[s+1]);else if(i===rt.Q)t.quadraticCurveTo(e[s],e[s+1],e[s+2],e[s+3]);else if(i===rt.C)t.bezierCurveTo(e[s],e[s+1],e[s+2],e[s+3],e[s+4],e[s+5]);else if(i===rt.Z)t.closePath();else return;s+=Ii[i]}}function qr(t){if(typeof t=="string")return(t.match(/-?\d*\.?\d+(?:e-?\d+)?/gi)??[]).map(Number);const e=[];for(let s=0;s<t.length;){const i=Ii[t[s++]];if(i===void 0)break;for(let n=0;n<i;n++)e.push(t[s+n]);s+=i}return e}function Wr(t,e){const s=e.match(/[MLQCZ]|-?\d*\.?\d+(?:e-?\d+)?/gi)??[];let i="",n=0;const r=()=>Number(s[n++]);for(;n<s.length;){const a=s[n];if(/[MLQCZ]/i.test(a)&&(i=a.toUpperCase(),n++,i==="Z")){t.closePath();continue}i==="M"?(t.moveTo(r(),r()),i="L"):i==="L"?t.lineTo(r(),r()):i==="Q"?t.quadraticCurveTo(r(),r(),r(),r()):i==="C"?t.bezierCurveTo(r(),r(),r(),r(),r(),r()):n++}}var K=t=>{const e=Math.round(t*100)/100;return e===0?0:e};function J(t,e=.5){const s=t.length;if(s<3)return[];const i=(l,h,o)=>({x:l.x+(h.x-l.x)*o,y:l.y+(h.y-l.y)*o}),n=Math.min(Math.max(e,0),.5),r=i(t[0],t[1],n),a=[rt.M,K(r.x),K(r.y)];for(let l=1;l<=s;l++){const h=t[(l-1)%s],o=t[l%s],c=t[(l+1)%s],u=i(h,o,1-n),f=i(o,c,n);a.push(rt.L,K(u.x),K(u.y),rt.Q,K(o.x),K(o.y),K(f.x),K(f.y))}return a.push(rt.Z),a}function Z(t,e=1){const s=t.length;if(s<3)return[];const i=[rt.M,K(t[0].x),K(t[0].y)],n=e/6;for(let r=0;r<s;r++){const a=t[(r-1+s)%s],l=t[r],h=t[(r+1)%s],o=t[(r+2)%s];i.push(rt.C,K(l.x+(h.x-a.x)*n),K(l.y+(h.y-a.y)*n),K(h.x-(o.x-l.x)*n),K(h.y-(o.y-l.y)*n),K(h.x),K(h.y))}return i.push(rt.Z),i}function Le(t){const e=t.length;if(e<2)return[];const s=[rt.M,K(t[0].x),K(t[0].y)];for(let i=0;i<e-1;i++){const n=t[Math.max(i-1,0)],r=t[i],a=t[i+1],l=t[Math.min(i+2,e-1)];s.push(rt.C,K(r.x+(a.x-n.x)/6),K(r.y+(a.y-n.y)/6),K(a.x-(l.x-r.x)/6),K(a.y-(l.y-r.y)/6),K(a.x),K(a.y))}return s}var ge="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",at="#ffffff",$=[-1,1],Oi="#3a2420",zi="#f2808f",Is="#26324a",Yr="#ffd84a",st=(...t)=>{const e=[];for(let s=0;s+1<t.length;s+=2)e.push({x:t[s],y:t[s+1]});return e};function Di(t,e){const s=t.palette,i=[],n={stroke:s.outline,lw:e},r=c=>t.headExtras.includes(c),a=(c,u)=>t.extraColors?.[c]??u;if(r("mane")){for(let u=0;u<12;u++){const f=u/12*Math.PI*2;i.push({k:"circle",x:Math.cos(f)*1.02,y:Math.sin(f)*1+.04,r:.42,fill:a(0,s.accent),...n})}i.push({k:"circle",x:0,y:.04,r:1.08,fill:a(0,s.accent)})}if(r("rainbow-mane")){const c=t.extraColors??["#f59ac0","#fbd46a","#8fd3f4"];[[.98,.05,.3,.5,-.25],[.92,.58,.26,.42,-.1],[.62,.92,.22,.32,.4]].forEach(([f,y,p,x,m],g)=>i.push({k:"ellipse",x:f,y,rx:p,ry:x,rot:m,fill:c[g%c.length],...n}))}if(r("spikes"))for(const c of[-.55,0,.55]){const u=ae(c,1.48),f=ae(c-.32,.86),y=ae(c+.32,.86);i.push({k:"path",d:J([f,u,y],.22),fill:s.accent,...n})}if(r("curl")&&i.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:s.body,...n}),r("wool"))for(let c=0;c<=8;c++){const u=-1.75+c/8*3.5;i.push({k:"circle",x:Math.sin(u)*.98,y:-Math.cos(u)*.92-.04,r:.34,fill:s.body,...n})}if(r("crest")&&[-.38,0,.38].forEach((c,u)=>{const f=ae(c,1.12);i.push({k:"ellipse",x:f.x,y:f.y,rx:.15,ry:.42,rot:c,fill:a(u,s.accent),...n})}),r("plume")&&i.push({k:"path",d:Z(st(-.12,-.92,-.2,-1.42,.1,-1.78,.62,-1.74,.36,-1.46,.16,-.98)),fill:s.accent,...n}),r("locks")&&i.push({k:"path",d:Z(st(-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:s.hair??s.outline,...n}),r("bun")&&i.push({k:"circle",x:.04,y:-1.14,r:.4,fill:s.hair??s.outline,...n}),r("ninja-hood"))for(const[c,u]of[[.35,.5],[.85,.42]])i.push({k:"ellipse",x:1+Math.cos(c)*u*.8,y:-.5+Math.sin(c)*u*.8,rx:u,ry:.11,rot:c,fill:s.accent,...n});if(r("bandana"))for(const[c,u]of[[Math.PI-.5,.42],[Math.PI-1,.36]])i.push({k:"ellipse",x:-.98+Math.cos(c)*u*.8,y:-.36+Math.sin(c)*u*.8,rx:u,ry:.12,rot:c,fill:s.accent,...n});if(r("ruff"))for(const c of $)i.push({k:"path",d:J(st(c*.7,-.3,c*1.32,0,c*1.02,.18,c*1.26,.46,c*.86,.56,c*.98,.84,c*.4,.7),.25),fill:s.body,...n});if(t.face.eyesOnTop)for(const c of $)i.push({k:"circle",x:c*.46,y:-.72,r:.38,fill:s.body,...n});i.push(...Jr(t,e)),i.push(Qr(t,n));const l=t.face.muzzle,h=s.belly;if(l==="oval"&&i.push({k:"ellipse",x:0,y:.4,rx:.46,ry:.32,fill:h}),l==="monkey"){for(const c of $)i.push({k:"circle",x:c*.32,y:-.04,r:.38,fill:h});i.push({k:"ellipse",x:0,y:.4,rx:.56,ry:.4,fill:h})}if(l==="heart"){for(const c of $)i.push({k:"circle",x:c*.36,y:.02,r:.5,fill:h});i.push({k:"ellipse",x:0,y:.38,rx:.66,ry:.48,fill:h})}if(l==="disc")for(const c of $)i.push({k:"circle",x:c*.4,y:.02,r:.44,fill:h});if(l==="cheeks")for(const c of $)i.push({k:"ellipse",x:c*.4,y:.44,rx:.44,ry:.32,fill:h});if(l==="band"&&i.push({k:"path",d:Zr(t,e),fill:h}),r("stripes")&&t.head==="snout-long"){const c=a(0,s.outline);for(const[u,f,y,p]of[[.46,-.94,.36,-.66],[.8,-.72,.62,-.5],[1,-.36,.78,-.24]])i.push({k:"line",pts:[u,f,y,p],stroke:c,lw:.11})}else if(r("stripes")){const c=a(0,s.outline);i.push({k:"line",pts:[0,-.97,0,-.66],stroke:c,lw:.13});for(const u of $)i.push({k:"line",pts:[u*.3,-.93,u*.24,-.7],stroke:c,lw:.1}),i.push({k:"line",pts:[u*.98,-.05,u*.74,0],stroke:c,lw:.1}),i.push({k:"line",pts:[u*.94,.22,u*.74,.22],stroke:c,lw:.09})}if(r("spots")){const c=a(1,s.belly);i.push({k:"circle",x:-.55,y:-.5,r:.15,fill:c}),i.push({k:"circle",x:.58,y:-.42,r:.11,fill:c}),i.push({k:"circle",x:.22,y:-.76,r:.09,fill:c})}if(t.head==="snout-long")for(const[c,u,f]of[[-1.38,-.14,.06],[-1.14,-.22,.055]])i.push({k:"ellipse",x:c,y:u,rx:f,ry:f*.8,rot:-.3,fill:s.outline,alpha:.85});if(r("forehead")&&i.push({k:"path",d:Z(st(-.62,-.66,0,-.86,.62,-.66,.26,-.36,0,-.1,-.26,-.36),.9),fill:a(0,s.accent)}),r("eye-spot")&&i.push({k:"ellipse",x:.42,y:-.06,rx:.3,ry:.33,rot:.3,fill:s.ears??s.accent}),r("gills"))for(const c of $)for(const u of[0,.12,.24])i.push({k:"path",d:`M${c*(.66+u)} 0.06 Q${c*(.6+u)} 0.22 ${c*(.66+u)} 0.38`,stroke:s.accent,lw:e*.9});const o=s.hair??s.outline;if(r("hair")&&i.push({k:"path",d:Z(st(-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:o,...n}),r("locks")&&i.push({k:"path",d:Z(st(-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:o,...n}),r("bun")&&i.push({k:"path",d:Z(st(-1.02,-.1,-.98,-.62,-.56,-1.02,0,-1.1,.56,-1.02,.98,-.62,1.02,-.1,.84,-.36,.5,-.56,.12,-.48,-.22,-.6,-.6,-.5,-.86,-.36)),fill:o,...n}),r("curls")){for(let c=0;c<7;c++){const u=ae(-1.3+c/6*2.6,.86);i.push({k:"circle",x:u.x,y:u.y,r:.3,fill:o,...n})}i.push({k:"ellipse",x:0,y:-.64,rx:.8,ry:.36,fill:o})}if(r("ninja-hood")&&(i.push({k:"rect",x:0,y:0,w:1.56,h:.6,r:.28,fill:s.skin??at,stroke:s.outline,lw:e*.8}),i.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:s.accent,...n})),r("domino")){i.push({k:"path",d:Z(st(-.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:s.accent,...n});for(const c of $)i.push({k:"ellipse",x:c*.38,y:0,rx:.19,ry:.13,fill:at})}if(i.push(...ta(t,e)),r("brows"))for(const c of $)i.push({k:"line",pts:[c*.72,-.5,c*.14,-.3],stroke:s.accent,lw:.16});if(t.face.brows)for(const c of $)i.push({k:"line",pts:[c*.2,-.2,c*.54,-.28],stroke:t.face.brows,lw:.09});if(i.push(...ea(t,e)),t.face.cheeks)for(const c of Vr(t))i.push({k:"ellipse",x:c.x,y:c.y,rx:.15,ry:.1,fill:t.face.cheeks,alpha:.8});if(r("whiskers"))for(const c of $)for(const u of[-.1,.06])i.push({k:"line",pts:[c*.62,.38+u,c*1.06,.3+u*2.2],stroke:s.outline,lw:e*.7,alpha:.75});if(r("rainbow-mane")){const c=t.extraColors??["#f59ac0","#fbd46a","#8fd3f4"];i.push({k:"ellipse",x:.42,y:-.82,rx:.34,ry:.22,rot:.5,fill:c[0],...n}),i.push({k:"ellipse",x:.1,y:-.92,rx:.3,ry:.2,rot:.25,fill:c[1%c.length],...n})}if(t.ears==="unicorn"){const c=[{x:-.18,y:-.84},{x:.02,y:-1.72},{x:.18,y:-.84}];i.push({k:"path",d:J(c,.12),fill:s.accent,...n});for(const u of[-1,-1.2,-1.4]){const f=.16*((u+1.72)/.88);i.push({k:"line",pts:[-f,u+.04,f,u-.04],stroke:s.outline,lw:e*.7,alpha:.6})}}if(r("flower-crown")){const c=[a(1,"#f7a8cf"),a(2,"#fff3a0"),a(3,at)];for(const u of[-.84,-.28,.28,.84]){const f=ae(u,.9);i.push({k:"ellipse",x:f.x,y:f.y,rx:.14,ry:.07,rot:u+.5,fill:"#7cc76a",stroke:s.outline,lw:e*.7})}[-1.12,-.56,0,.56,1.12].forEach((u,f)=>{const y=ae(u,.9),p=f===2?.13:.11;for(let x=0;x<5;x++){const m=u+x/5*Math.PI*2;i.push({k:"circle",x:y.x+Math.sin(m)*p,y:y.y-Math.cos(m)*p,r:p*.82,fill:c[f%c.length],stroke:s.outline,lw:e*.7})}i.push({k:"circle",x:y.x,y:y.y,r:p*.62,fill:c[f%c.length]}),i.push({k:"circle",x:y.x,y:y.y,r:p*.42,fill:s.accent})})}if(r("helmet")){for(const c of $)i.push({k:"rect",x:c*1,y:.05,w:.26,h:.56,r:.12,fill:s.accent,...n});i.push({k:"path",d:"M-0.62 -0.62 Q-0.3 -0.92 0.12 -0.9",stroke:at,lw:.1,alpha:.9})}if(r("bolts"))for(const c of $)i.push({k:"rect",x:c*1.08,y:.08,w:.2,h:.44,r:.08,fill:s.accent,...n});if(r("tuft")&&i.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:s.body,...n}),r("eggshell")&&i.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,at),...n}),r("wool"))for(const[c,u]of[[-.36,-.84],[.02,-.94],[.4,-.82]])i.push({k:"circle",x:c,y:u,r:.27,fill:s.body,...n});if(r("stripe")&&i.push({k:"rect",x:0,y:-.64,w:.38,h:.62,r:.06,fill:s.accent}),r("eye-patch")&&(i.push({k:"line",pts:[-.97,-.5,.97,.13],stroke:s.outline,lw:.07}),i.push({k:"ellipse",x:.38,y:.02,rx:.21,ry:.19,fill:s.outline})),r("bandana")){i.push({k:"path",d:Z(st(-1.05,-.22,-.96,-.72,-.5,-1.08,.1,-1.14,.72,-.96,1.04,-.56,1.05,-.22,.5,-.46,-.5,-.46)),fill:s.accent,...n});for(const[c,u]of[[-.5,-.8],[.08,-.92],[.6,-.74],[-.12,-.62],[.36,-.6]])i.push({k:"circle",x:c,y:u,r:.06,fill:at,alpha:.85});i.push({k:"circle",x:-.98,y:-.34,r:.15,fill:s.accent,...n})}if(r("cap")){for(const c of $)i.push({k:"line",pts:[c*.98,-.2,c*.5,.82,-c*.05,.98],stroke:s.outline,lw:.06});i.push({k:"path",d:Z(st(-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:s.accent,...n}),i.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:s.accent,...n}),i.push({k:"circle",x:.5,y:-.82,r:.15,fill:a(0,at),...n});for(const c of[-.42,-.14])i.push({k:"line",pts:[c,-1.04,c+.02,-.78],stroke:s.outline,lw:.07,alpha:.7})}if(r("safari-hat")&&(i.push({k:"ellipse",x:0,y:-.56,rx:1.48,ry:.3,fill:s.accent,...n}),i.push({k:"path",d:Z(st(-.78,-.58,-.7,-1.1,-.3,-1.38,.3,-1.38,.7,-1.1,.78,-.58,0,-.5),.8),fill:s.accent,...n}),i.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,s.outline),stroke:s.outline,lw:e*.8})),r("wizard-hat")){i.push({k:"ellipse",x:0,y:-.62,rx:1.32,ry:.26,fill:s.accent,...n}),i.push({k:"path",d:J(st(-.8,-.66,-.36,-1.5,.5,-2.2,.3,-1.46,.8,-.66),.3),fill:s.accent,...n});const c=a(0,Yr);for(const[u,f,y]of[[.02,-1.08,.18],[-.38,-.84,.1],[.36,-1.5,.11]])i.push({k:"group",x:u,y:f,s:y,items:[{k:"path",d:ge,fill:c}]})}if(r("dive-mask")){for(const u of $)i.push({k:"line",pts:[u*.7,-.04,u*1,-.12],stroke:s.outline,lw:.2},{k:"line",pts:[u*.7,-.04,u*1,-.12],stroke:s.accent,lw:.11});i.push({k:"rect",x:0,y:0,w:1.42,h:.62,r:.28,fill:"#bfe9f5",alpha:.35}),i.push({k:"rect",x:0,y:0,w:1.42,h:.62,r:.28,stroke:s.outline,lw:.2}),i.push({k:"rect",x:0,y:0,w:1.42,h:.62,r:.28,stroke:s.accent,lw:.11}),i.push({k:"path",d:"M-0.5 -0.16 Q-0.4 -0.24 -0.22 -0.24",stroke:at,lw:.06,alpha:.9});const c="M0.5 0.52 Q0.98 0.56 1.04 0.1 L1.12 -0.92";i.push({k:"path",d:c,stroke:s.outline,lw:.24},{k:"path",d:c,stroke:s.accent,lw:.13})}return i}function Qr(t,e){const s=t.headExtras.includes("ninja-hood")?t.palette.body:t.palette.skin??t.palette.body;switch(t.head){case"round":return{k:"circle",x:0,y:0,r:1,fill:s,...e};case"wide":return{k:"ellipse",x:0,y:.03,rx:1.12,ry:.94,fill:s,...e};case"tall":return{k:"ellipse",x:0,y:-.02,rx:.94,ry:1.04,fill:s,...e};case"square":return{k:"rect",x:0,y:0,w:2,h:1.8,r:.46,fill:s,...e};case"bucket":return{k:"path",d:J(st(-.94,.96,-.98,-.36,-.62,-1.04,.62,-1.04,.98,-.36,.94,.96),.42),fill:s,...e};case"snout-long":return{k:"path",d:Z(jr,.95),fill:s,...e};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:s,...e}}}var jr=st(.7,-.88,.12,-1.04,-.3,-.98,-.72,-.74,-1.2,-.56,-1.5,-.32,-1.6,.04,-1.44,.42,-.9,.72,-.2,.92,.5,.88,.96,.56,1.08,0,.98,-.5);function Bi(t,e,s){return t.head==="snout-long"?[{x:-.36,y:-.5,k:.95},{x:.26,y:-.48,k:1.1}]:$.map(i=>({x:i*e,y:s,k:1}))}function Vr(t){return t.head==="snout-long"?st(-.66,-.14,.66,.1):$.map(e=>({x:e*.64,y:.3}))}function Kr(t){return t.head==="round"?{cy:0,rx:1,ry:1}:t.head==="tall"?{cy:-.02,rx:.94,ry:1.04}:{cy:.03,rx:1.12,ry:.94}}function Zr(t,e){const{cy:s,rx:i,ry:n}=Kr(t),r=i-e/2,a=n-e/2,l=.15,h=Math.asin(Math.min(1,(l-s)/a)),o=Math.cos(h)*r,c=p=>Math.round(p*100)/100||0,u=[rt.M,c(-o),l],f=[[-.84*o,.02,-.53*o,.06,-.32*o,.24],[-.17*o,.11,.17*o,.11,.32*o,.24],[.53*o,.06,.84*o,.02,o,l]];for(const p of f)u.push(rt.C,...p.map(c));const y=24;for(let p=1;p<=y;p++){const x=h+(Math.PI-2*h)*p/y;u.push(rt.L,c(Math.cos(x)*r),c(s+Math.sin(x)*a))}return u.push(rt.Z),u}function Jr(t,e){const s=t.palette,i={stroke:s.outline,lw:e},n=[];for(const r of $)switch(t.ears){case"pointy":case"unicorn":{const a=t.ears==="unicorn"?.8:1,l={x:r*.3,y:-.82},h={x:r*.86,y:-.82-.62*a},o={x:r*.94,y:-.36};n.push({k:"path",d:J([l,h,o],.2),fill:s.body,...i});const c={x:(l.x+h.x+o.x)/3,y:(l.y+h.y+o.y)/3},u=[l,h,o].map(f=>({x:c.x+(f.x-c.x)*.55,y:c.y+(f.y-c.y)*.55+.04}));n.push({k:"path",d:J(u,.25),fill:s.accent});break}case"round":n.push({k:"circle",x:r*.72,y:-.72,r:.36,fill:s.ears??s.body,...i}),s.ears||n.push({k:"circle",x:r*.74,y:-.74,r:.19,fill:s.accent});break;case"big-round":n.push({k:"circle",x:r*.96,y:-.46,r:.52,fill:s.body,...i}),n.push({k:"circle",x:r*1,y:-.44,r:.32,fill:s.accent});break;case"long":n.push({k:"ellipse",x:r*.38,y:-1.42,rx:.25,ry:.68,rot:r*.14,fill:s.body,...i}),n.push({k:"ellipse",x:r*.39,y:-1.36,rx:.12,ry:.48,rot:r*.14,fill:s.accent});break;case"side":n.push({k:"circle",x:r*1,y:.02,r:.34,fill:s.body,...i}),n.push({k:"circle",x:r*1.02,y:.02,r:.2,fill:s.belly});break;case"tufts":n.push({k:"path",d:J([{x:r*.3,y:-.84},{x:r*1.22,y:-1.12},{x:r*.92,y:-.42}],.16),fill:s.body,...i}),n.push({k:"line",pts:[r*.62,-.78,r*1,-.98],stroke:s.accent,lw:.08});break;case"antennae":{const a={x:r*.62,y:-1.42};n.push({k:"path",d:`M${r*.3} -0.8 Q${r*.36} -1.2 ${a.x} ${a.y}`,stroke:s.outline,lw:e*2.6}),n.push({k:"path",d:`M${r*.3} -0.8 Q${r*.36} -1.2 ${a.x} ${a.y}`,stroke:s.body,lw:e*1.2}),n.push({k:"circle",x:a.x,y:a.y,r:.17,fill:s.accent,...i});break}case"floppy":n.push({k:"ellipse",x:r*.96,y:.02,rx:.3,ry:.62,rot:-r*.36,fill:s.ears??s.body,...i});break;case"droopy":n.push({k:"ellipse",x:r*1.04,y:-.22,rx:.4,ry:.18,rot:r*.32,fill:s.skin??s.body,...i}),n.push({k:"ellipse",x:r*1.08,y:-.2,rx:.24,ry:.08,rot:r*.32,fill:s.accent});break;case"pixie":n.push({k:"path",d:J(st(r*.86,-.22,r*1.36,-.5,r*1.02,.26),.28),fill:s.skin??s.body,...i}),n.push({k:"line",pts:[r*.98,-.12,r*1.16,-.3],stroke:s.accent,lw:e*.8,alpha:.5});break;case"human":n.push({k:"ellipse",x:r*.98,y:.06,rx:.17,ry:.23,fill:s.skin??s.body,...i});break;case"horns":{const a=[{x:r*.3,y:-.84},{x:r*.6,y:-1.5},{x:r*.66,y:-.68}];n.push({k:"path",d:J(a,.18),fill:s.accent,...i});break}}return t.ears==="fin"&&n.push({k:"path",d:J(st(-.4,-.82,.2,-1.62,.46,-.78),.2),fill:s.body,...i}),t.ears==="antenna"&&(n.push({k:"line",pts:[0,-.85,0,-1.42],stroke:s.outline,lw:e*2.6}),n.push({k:"line",pts:[0,-.85,0,-1.42],stroke:s.limbs,lw:e*1.2}),n.push({k:"circle",x:0,y:-1.5,r:.18,fill:s.accent,...i})),n}function ta(t,e){const s=t.palette,i=t.face,n=[],r=s.outline,a=i.eyesOnTop?.46:.4,l=i.eyesOnTop?-.72:-.04,h=(o,c,u)=>({k:"circle",x:o,y:c,r:u,fill:at});switch(i.eyes){case"dot":for(const o of Bi(t,a,l))n.push({k:"ellipse",x:o.x,y:o.y,rx:.12*o.k,ry:.155*o.k,fill:r}),n.push(h(o.x+.04*o.k,o.y-.06*o.k,.045*o.k));break;case"bead":for(const o of Bi(t,a,l))n.push({k:"ellipse",x:o.x,y:o.y,rx:.16*o.k,ry:.22*o.k,fill:r}),n.push(h(o.x+.05*o.k,o.y-.08*o.k,.065*o.k));break;case"big":for(const o of $)i.eyeRing&&n.push({k:"circle",x:o*a,y:l,r:.36,fill:i.eyeRing,stroke:r,lw:e*.8}),n.push({k:"circle",x:o*a,y:l,r:.25,fill:at,stroke:r,lw:e*.8}),n.push({k:"circle",x:o*a+o*-.03,y:l+.03,r:.14,fill:i.eyeColor??r}),n.push(h(o*a+o*-.03+.05,l-.03,.05));break;case"mask":for(const o of $)n.push({k:"ellipse",x:o*.4,y:0,rx:.24,ry:.32,rot:o*-.55,fill:s.limbs}),n.push({k:"circle",x:o*.4,y:-.02,r:.11,fill:at}),n.push({k:"circle",x:o*.39,y:-0,r:.065,fill:r});break;case"screen":n.push({k:"rect",x:0,y:0,w:1.5,h:.66,r:.26,fill:"#24323d",stroke:r,lw:e*.8});for(const o of $)n.push({k:"ellipse",x:o*.36,y:0,rx:.2,ry:.24,fill:i.eyeColor??"#7ff0ff",alpha:.3}),n.push({k:"ellipse",x:o*.36,y:0,rx:.12,ry:.16,fill:i.eyeColor??"#7ff0ff"});break;case"almond":for(const o of $)n.push({k:"ellipse",x:o*.42,y:-.02,rx:.3,ry:.2,rot:-o*.5,fill:i.eyeColor??r}),n.push(h(o*.42-o*.07,-.08,.07));break;case"calm":for(const o of $)n.push({k:"ellipse",x:o*.38,y:.02,rx:.085,ry:.12,fill:r}),n.push(h(o*.38+.03,-.02,.03));break;case"slit":n.push({k:"line",pts:[0,-.98,0,-.2],stroke:r,lw:e*.8,alpha:.5}),n.push({k:"rect",x:0,y:-.04,w:1.56,h:.26,r:.1,fill:Is,stroke:r,lw:e*.8}),n.push({k:"rect",x:0,y:.3,w:.22,h:.46,r:.08,fill:Is,stroke:r,lw:e*.8});for(const o of $){n.push({k:"ellipse",x:o*.4,y:-.04,rx:.12,ry:.07,fill:i.eyeColor??at});for(const c of[.36,.56])n.push({k:"circle",x:o*.42,y:c,r:.05,fill:r,alpha:.6})}break;case"goggle":for(const o of $)n.push({k:"circle",x:o*.9,y:0,r:.13,fill:s.accent,stroke:r,lw:e*.8});n.push({k:"rect",x:0,y:0,w:1.66,h:.62,r:.3,fill:Is,stroke:r,lw:e*.8}),n.push({k:"path",d:"M-0.6 -0.16 Q-0.42 -0.24 -0.12 -0.24",stroke:at,lw:.07,alpha:.8});for(const o of $)n.push({k:"path",d:`M${o*.5} 0.04 Q${o*.34} -0.08 ${o*.16} 0.02`,stroke:i.eyeColor??"#7fd6ff",lw:.08});for(const o of[-.18,0,.18])n.push({k:"line",pts:[o,.56,o,.72],stroke:r,lw:e*.8,alpha:.6});break;case"visor":n.push({k:"ellipse",x:0,y:.08,rx:.8,ry:.64,fill:"#2a3f6b",stroke:r,lw:e*.8}),n.push({k:"path",d:"M-0.56 -0.14 Q-0.46 -0.4 -0.16 -0.46",stroke:at,lw:.08,alpha:.7});for(const o of $)n.push({k:"ellipse",x:o*.28,y:.04,rx:.1,ry:.14,fill:i.eyeColor??"#cfeeff"});break}return n}function ea(t,e){const s=t.palette,i=t.face,n=[],r=i.eyes==="visor"?"#cfeeff":Oi,a=e*1.05;switch(i.nose&&i.mouth!=="beak"&&(i.mouth==="cat"?n.push({k:"path",d:J([{x:-.1,y:.22},{x:.1,y:.22},{x:0,y:.33}],.3),fill:i.nose,stroke:i.nose,lw:e*.6}):t.ears==="big-round"?n.push({k:"ellipse",x:0,y:.22,rx:.2,ry:.25,fill:i.nose}):n.push({k:"ellipse",x:0,y:.25,rx:.13,ry:.085,fill:i.nose})),i.mouth){case"smile":n.push({k:"path",d:i.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:r,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:r,stroke:r,lw:e*.5}),n.push({k:"ellipse",x:0,y:.6,rx:.1,ry:.06,fill:zi});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:r,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:s.accent,stroke:s.outline,lw:e*.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:r,stroke:r,lw:e*.5});for(const l of $)n.push({k:"rect",x:l*.12,y:.43,w:.1,h:.1,r:.03,fill:at});break;case"grill":n.push({k:"rect",x:0,y:.56,w:.62,h:.2,r:.08,fill:"#24323d",stroke:s.outline,lw:e*.7});for(const l of[-.15,0,.15])n.push({k:"line",pts:[l,.51,l,.61],stroke:"#9fb0bd",lw:e*.6});break;case"tiny":n.push({k:"ellipse",x:0,y:.44,rx:.08,ry:.1,fill:r});break;case"smirk":n.push({k:"path",d:"M-0.16 0.46 Q0.06 0.54 0.22 0.38",stroke:r,lw:a});break;case"bill":n.push({k:"ellipse",x:0,y:.36,rx:.44,ry:.2,fill:s.accent,stroke:s.outline,lw:e*.8}),n.push({k:"path",d:"M-0.36 0.38 Q0 0.46 0.36 0.38",stroke:s.outline,lw:e*.7});for(const l of $)n.push({k:"circle",x:l*.1,y:.28,r:.03,fill:s.outline});break;case"hook":n.push({k:"ellipse",x:0,y:.48,rx:.16,ry:.11,fill:Oi}),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:s.accent,stroke:s.outline,lw:e*.8});break;case"toothy":{n.push({k:"path",d:"M-1.4 0.1 Q-0.5 0.36 0.5 0.2 Q0.64 0.16 0.68 0.02 Q0.78 0.28 0.52 0.38 Q-0.4 0.78 -1.3 0.26 Z",fill:r,stroke:r,lw:e*.6}),n.push({k:"ellipse",x:-.38,y:.5,rx:.24,ry:.08,fill:zi});for(const l of[.12,.27,.42,.57,.72,.86]){const h=(1-l)*(1-l)*-1.4+2*(1-l)*l*-.5+l*l*.5,o=(1-l)*(1-l)*.1+2*(1-l)*l*.36+l*l*.2-.01;n.push({k:"path",d:J(st(h-.08,o,h+.08,o,h,o+.14),.3),fill:at})}for(const l of[.3,.7]){const h=(1-l)*(1-l)*.52+2*(1-l)*l*-.4+l*l*-1.3,o=(1-l)*(1-l)*.38+2*(1-l)*l*.78+l*l*.26+.01;n.push({k:"path",d:J(st(h-.07,o,h+.07,o,h,o-.12),.3),fill:at})}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:r,stroke:r,lw:e*.5});for(const l of[-.34,-.17,0,.17,.34]){const h=.3+.4*(l+.5)*(.5-l)-.01;n.push({k:"path",d:J(st(l-.075,h,l+.075,h,l,h+.13),.15),fill:at})}break}}return n}var ae=(t,e)=>({x:Math.sin(t)*e,y:-Math.cos(t)*e}),sa=.5,Kt={leftEye:2,rightEye:5,leftEar:7,rightEar:8},oe={"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}},ss="6-8",Ui=(t,e)=>e!==void 0&&t.band!=="all"&&t.alsoIn?.includes(e)&&e in oe?e:t.band in oe?t.band:ss,Vl=oe[ss].head,ia=.3,na=.12,ra=.9,Hi=.5,Gi=.65,aa=.35,oa=.2,la=.25,Pt=(t,e)=>({x:t.x-e.x,y:t.y-e.y}),et=(t,e)=>({x:t.x+e.x,y:t.y+e.y}),j=(t,e)=>({x:t.x*e,y:t.y*e}),le=t=>Math.hypot(t.x,t.y),Xi=(t,e)=>({x:(t.x+e.x)/2,y:(t.y+e.y)/2}),is=t=>{const e=le(t);return e>1e-9?{x:t.x/e,y:t.y/e}:{x:0,y:1}},ha=(...t)=>t.every(Number.isFinite),ca=t=>Math.atan2(Math.sin(t),Math.cos(t)),fa=(t,e,s)=>Math.min(Math.max(t,e),s);function $i(t,e,s=!1){return i=>{const n=t[i*3],r=t[i*3+1],a=t[i*3+2];return n===void 0||r===void 0||a===void 0||!ha(n,r,a)?{x:0,y:0,ok:!1}:{x:e.x+(s?1-n:n)*e.w,y:e.y+r*e.h,ok:a>=sa}}}function Os(t,e,s={}){const i=$i(t,e,s.mirrored),n=i(U.leftShoulder),r=i(U.rightShoulder);if(!n.ok||!r.ok)return null;const a=i(U.leftHip),l=i(U.rightHip),h=Xi(n,r),o=le(Pt(r,n)),c=a.ok&&l.ok;let u=is(Pt(r,n));o<1e-6&&(u={x:1,y:0});let f,y,p;if(c){const C=Xi(a,l);y=le(Pt(C,h)),y>=o*la?f=is(Pt(C,h)):(f={x:-u.y,y:u.x},f.y<0&&(f=j(f,-1))),p=Math.max(y,o*1.15)}else f={x:-u.y,y:u.x},f.y<0&&(f=j(f,-1)),p=o*1.15,y=p;p=Math.max(p,1e-6);const x={x:f.y,y:-f.x},m=Math.atan2(x.y,x.x),g=j(f,-1),k=oe[s.band??ss]??oe[ss],E=k.head*p;let w=et(h,j(g,E*k.neck));const A=i(U.nose);if(A.ok){const C=et(A,j(g,E*.15)),R=j(Pt(C,w),aa),O=Math.min(1,E*oa/Math.max(le(R),1e-6));w=et(w,j(R,O))}return{S:h,r:x,d:f,U:p,L:y,hipsOk:c,head:w,headR:E,headRot:m+ua(t,i,m,p),angle:m}}function ua(t,e,s,i){const n=[[Kt.leftEar,Kt.rightEar],[Kt.leftEye,Kt.rightEye]];for(const[r,a]of n){const l=e(r),h=e(a);if(!l.ok||!h.ok||!(t[r*3+2]>=Gi&&t[a*3+2]>=Gi)||le(Pt(h,l))<i*.05)continue;const o=ca(Math.atan2(h.y-l.y,h.x-l.x)-s),c=Math.max(Math.abs(o)-na,0),u=fa((ra+Hi-Math.abs(o))/Hi,0,1);return Math.sign(o)*Math.min(c,ia)*u}return 0}function qi(t,e,s,i={}){const n=Ui(e,i.band),r=oe[n],a=Os(t,s,{...i,band:n});if(!a)return[];const l=$i(t,s,i.mirrored),h=e.palette,{S:o,r:c,d:u,U:f,L:y}=a,p=v=>e.bodyExtras.includes(v),x=Math.max(1.2,f*.045),m={stroke:h.outline,lw:x},g=(v,L)=>({x:o.x+c.x*v+u.x*L,y:o.y+c.y*v+u.y*L}),k=v=>v.map(([L,D])=>g(L,D)),E=l(U.leftShoulder),w=l(U.rightShoulder),A=l(U.leftHip),C=l(U.rightHip),R=le(Pt(w,E)),O=a.hipsOk?le(Pt(C,A)):R*.7,P=Math.max(R/2+r.shoulderPad*f,r.shoulderMin*f),I=Math.max(O/2+r.hipPad*f,r.hipMin*f),q=-.1*f,Q=y+r.bottom*f,H=[],It=[],G=[],nt=[],yt=[],Ot=(v,L,D,Y)=>{const W=L.flatMap(ot=>[ot.x,ot.y]);v.push({k:"line",pts:W,stroke:h.outline,lw:D+x*2}),v.push({k:"line",pts:W,stroke:Y,lw:D})},xi=r.leg*f*(p("strong-legs")?1.3:1),wt=r.arm*f*(p("tiny-arms")?.6:1),zt=Math.max(r.arm/.22,.9);if(a.hipsOk)for(const[v,L,D,Y]of[[A,U.leftKnee,U.leftAnkle,-1],[C,U.rightKnee,U.rightAnkle,1]]){const W=l(L),ot=l(D);if(!W.ok)continue;const Qt=et(v,j(u,-.12*f)),_t=ot.ok?[Qt,W,ot]:[Qt,W];Ot(It,_t,xi,h.limbs),p("joints")&&It.push({k:"circle",x:W.x,y:W.y,r:.15*f*zt,fill:h.accent,...m}),ot.ok&&It.push(...ya(e,ot,a,Y,x,r.foot))}for(const[v,L,D,Y]of[[E,U.leftElbow,U.leftWrist,-1],[w,U.rightElbow,U.rightWrist,1]]){const W=l(L),ot=l(D);if(p("pauldrons")){const St=et(v,j(u,.02*f));nt.push({k:"ellipse",x:St.x,y:St.y,rx:.25*f,ry:.17*f,rot:a.angle+Y*.25,fill:h.body,...m});const Tt=et(St,j(u,.05*f));nt.push({k:"ellipse",x:Tt.x,y:Tt.y,rx:.17*f,ry:.07*f,rot:a.angle+Y*.25,fill:h.belly})}if(!W.ok)continue;const _t=r.armsOverHead&&(W.x-o.x)*u.x+(W.y-o.y)*u.y<-.25*f?yt:nt,Ye=et(v,j(u,.04*f));if(Ot(_t,ot.ok?[Ye,W,ot]:[Ye,W],wt,h.limbs),p("joints")&&_t.push({k:"circle",x:W.x,y:W.y,r:.13*f*zt,fill:h.accent,...m}),!ot.ok)continue;const vt=is(Pt(ot,W)),jt=et(ot,j(vt,.05*f));if(p("feathers"))for(const St of[-.55,0,.55]){const Tt=Math.cos(St),Vt=Math.sin(St)*Y,Ct={x:vt.x*Tt-vt.y*Vt,y:vt.x*Vt+vt.y*Tt},de=et(jt,j(Ct,.16*f));_t.push({k:"ellipse",x:de.x,y:de.y,rx:.2*f,ry:.09*f,rot:Math.atan2(Ct.y,Ct.x),fill:h.hands??h.accent,...m})}p("wand")&&Y===1&&!i.portrait&&_t.push(...ga(e,jt,is(et(j(vt,.4),Pt(j(c,.6),u))),f,x));const Gt=r.hand*f*(p("tiny-arms")?.72:1);if(p("tiny-arms"))for(const St of[-.45,.45]){const Tt=Math.cos(St),Vt=Math.sin(St),Ct={x:vt.x*Tt-vt.y*Vt,y:vt.x*Vt+vt.y*Tt},de=et(jt,j(Ct,Gt*.75)),gi=et(jt,j(Ct,Gt*1.6)),pe={x:-Ct.y*Gt*.32,y:Ct.x*Gt*.32};_t.push({k:"path",d:J([et(de,pe),gi,Pt(de,pe)],.2),fill:h.belly,...m})}_t.push({k:"circle",x:jt.x,y:jt.y,r:Gt,fill:h.hands??h.limbs,...m})}if(p("wings"))for(const v of[-1,1]){const L=k([[v*P*.5,.05*f],[v*(P+.85*f),-.6*f],[v*(P+.72*f),.05*f],[v*(P+.45*f),-.02*f],[v*(P+.3*f),.32*f],[v*P*.6,.55*f]]);H.push({k:"path",d:J(L,.18),fill:h.accent,...m})}if(p("wings-fairy")&&H.push(...ba(e,g,P,f,x)),p("cape")){const v=y+.8*f,L=I+.36*f,D=k([[-P*.92,q+.04*f],[P*.92,q+.04*f],[P+.16*f,y*.5],[L,v],[L*.5,v-.1*f],[0,v],[-L*.5,v-.1*f],[-L,v],[-P-.16*f,y*.5]]);H.push({k:"path",d:Z(D,.6),fill:h.accent,...m})}if(p("backpack")){const v=g(0,.35*f);H.push({k:"rect",x:v.x,y:v.y,w:P*2+.34*f,h:.8*f,r:.16*f,rot:a.angle,fill:e.extraColors?.[0]??h.limbs,...m})}if(p("tank")){const v=g(P*.95,.24*f),L=e.extraColors?.[0]??h.accent,D=g(P*.95,-.3*f);H.push({k:"rect",x:D.x,y:D.y,w:.14*f,h:.16*f,r:.04*f,rot:a.angle,fill:h.outline}),H.push({k:"rect",x:v.x,y:v.y,w:.34*f,h:1*f,r:.17*f,rot:a.angle,fill:L,...m})}if(a.hipsOk&&!i.portrait&&H.push(...xa(e,a,I,x)),p("tentacles")&&a.hipsOk)for(const v of[-1,1]){const L=k([[v*I*.7,y*.9],[v*(I+.22*f),y+.3*f],[v*(I+.48*f),y+.22*f],[v*(I+.5*f),y-.02*f],[v*(I+.34*f),y-.06*f]]);H.push({k:"path",d:Le(L),stroke:h.outline,lw:.2*f+x*2}),H.push({k:"path",d:Le(L),stroke:h.limbs,lw:.2*f})}const mt=Math.max(P,I)*r.bulge;if(p("wool")){for(const[L,D]of[[P*.7,q+.02*f],[mt,y*.3],[mt*1.02,y*.62],[(mt+I)/2,y*.92],[I*.55,Q]])for(const Y of[-1,1]){const W=g(Y*L,D);G.push({k:"circle",x:W.x,y:W.y,r:.2*f,fill:h.body,...m})}const v=g(0,Q+.02*f);G.push({k:"circle",x:v.x,y:v.y,r:.2*f,fill:h.body,...m})}if(p("robe")){const v=y+.58*f,L=I*1.4;G.push({k:"path",d:Z(k([[-P,q],[0,q-.04*f],[P,q],[mt,y*.55],[L,v],[0,v+.06*f],[-L,v],[-mt,y*.55]]),.7),fill:h.body,...m});const D=k([[-L*.94,v-.1*f],[0,v-.04*f],[L*.94,v-.1*f]]);G.push({k:"path",d:Le(D),stroke:e.extraColors?.[0]??h.accent,lw:.07*f})}else if(p("sheet")){const v=y+.78*f,L=I*1.3;G.push({k:"path",d:Z(k([[-P,q],[P,q],[mt,y*.55],[L,v],[L*.5,v-.2*f],[0,v],[-L*.5,v-.2*f],[-L,v],[-mt,y*.55]]),.9),fill:h.body,...m})}else G.push({k:"path",d:Z(k([[-P,q],[0,q-.04*f],[P,q],[mt,y*.55],[I,Q],[0,Q+.03*f],[-I,Q],[-mt,y*.55]]),.85),fill:h.body,...m});const ut=Math.min(P,I);if(p("pocket")){const v=g(0,y*.74);G.push({k:"rect",x:v.x,y:v.y,w:ut*1.3,h:.3*f,r:.1*f,rot:a.angle,fill:h.belly,stroke:h.outline,lw:x*.8})}else if(p("racing-stripe"))for(const v of[-.1,.1]){const L=g(v*f,q+.02*f),D=g(v*f,Q-.04*f);G.push({k:"line",pts:[L.x,L.y,D.x,D.y],stroke:h.belly,lw:.1*f})}else if(h.belly&&h.belly!==h.body&&!p("panel")&&!p("sheet")&&!p("stripes")){const v=g(0,y*.58);G.push({k:"ellipse",x:v.x,y:v.y,rx:ut*.64,ry:Math.max(y*.36,.2*f),rot:a.angle,fill:h.belly})}if(p("spots")){const v=e.extraColors?.[1]??h.belly;for(const[L,D,Y]of[[-.55,.35,.09],[.5,.62,.11],[-.35,.86,.07]]){const W=g(L*ut,D*y);G.push({k:"circle",x:W.x,y:W.y,r:Y*f,fill:v})}}if(p("stripes")){const v=e.extraColors?.[1]??h.accent;for(const L of[.22,.44,.66]){const D=g(-ut*.98,y*L),Y=g(ut*.98,y*L);G.push({k:"line",pts:[D.x,D.y,Y.x,Y.y],stroke:v,lw:.1*f})}}if(p("straps")){const v=e.extraColors?.[1]??h.outline;for(const L of[-1,1]){const D=g(L*P*.62,q+.02*f),Y=g(L*ut*.62,y*.72);G.push({k:"line",pts:[D.x,D.y,Y.x,Y.y],stroke:h.outline,lw:.13*f+x*2}),G.push({k:"line",pts:[D.x,D.y,Y.x,Y.y],stroke:v,lw:.13*f})}}if(p("belt")){const v=g(0,y*.9);G.push({k:"rect",x:v.x,y:v.y,w:I*1.92,h:.17*f,r:.06*f,rot:a.angle,fill:e.extraColors?.[2]??"#4a3426",...m}),G.push({k:"rect",x:v.x,y:v.y,w:.2*f,h:.19*f,r:.04*f,rot:a.angle,fill:"#ffd84a",...m})}if(p("emblem")){const v=g(0,y*.4),L=e.extraColors?.[0]??h.accent,D=J([{x:-.22,y:-.2},{x:.22,y:-.2},{x:.22,y:.04},{x:0,y:.26},{x:-.22,y:.04}],.25);G.push({k:"group",x:v.x,y:v.y,rot:a.angle,s:f,items:[{k:"path",d:D,fill:L,stroke:h.outline,lw:x/f},{k:"group",x:0,y:.01,s:.12,items:[{k:"path",d:ge,fill:L===h.accent?"#ffffff":h.accent}]}]})}if(p("panel")){const v=g(0,y*.5);G.push({k:"rect",x:v.x,y:v.y,w:ut*1.2,h:.38*f,r:.1*f,rot:a.angle,fill:"#24323d",...m}),(e.extraColors??["#ff7a6b","#fbd46a","#7ff0ff"]).slice(0,3).forEach((D,Y)=>{const W=g((Y-1)*ut*.34,y*.5);G.push({k:"circle",x:W.x,y:W.y,r:.075*f,fill:D})})}if(p("badge")){const v=g(-ut*.42,y*.36);G.push({k:"circle",x:v.x,y:v.y,r:.15*f,fill:h.accent,...m}),G.push({k:"group",x:v.x,y:v.y,rot:a.angle,s:.09*f,items:[{k:"path",d:ge,fill:"#ffffff"}]})}if(p("star")){const v=g(-ut*.5,y*.3),L=.15*f;G.push({k:"group",x:v.x,y:v.y,rot:a.angle-.2,s:L,items:[{k:"path",d:ge,fill:e.extraColors?.[0]??"#ffd84a",stroke:h.outline,lw:x*.8/L}]})}if(p("petals")&&G.push(...ka(e,g,P,I,mt,y,Q,f,x,r)),p("scarf")){const v=Math.max(.04,r.head*(1-r.neck)-.06)*f,L=g(0,v),D=e.extraColors?.[0]??h.accent,Y=g(P*.45,v+.28*f);G.push({k:"rect",x:Y.x,y:Y.y,w:.16*f,h:.42*f,r:.06*f,rot:a.angle+.15,fill:D,...m}),G.push({k:"rect",x:L.x,y:L.y,w:P*2.05,h:.2*f,r:.1*f,rot:a.angle,fill:D,...m})}const Dt={k:"group",x:a.head.x,y:a.head.y,rot:a.headRot,s:a.headR,items:pa(e,x/a.headR)};return[...H,...It,...G,...nt,Dt,...yt]}var Wi=new WeakMap,da=64;function pa(t,e){const s=Number(e.toPrecision(4));let i=Wi.get(t);i||Wi.set(t,i=new Map);let n=i.get(s);return n||(i.size>=da&&i.clear(),i.set(s,n=Di(t,s))),n}function ya(t,e,s,i,n,r){const a=ma(t,e,s,i,n,r);if(!t.bodyExtras.includes("strong-legs"))return[a];const l=s.U*r,h=et(et(e,j(s.d,.07*l)),j(s.r,i*.06*l)),o=[a];for(const c of[-1,0,1]){const u=et(et(h,j(s.r,c*.12*l)),j(s.d,.09*l));o.push({k:"ellipse",x:u.x,y:u.y,rx:.05*l,ry:.045*l,rot:s.angle,fill:t.palette.belly,stroke:t.palette.outline,lw:n*.8})}return o}function ma(t,e,s,i,n,r){const a=t.palette,{d:l,r:h}=s,o=s.U*r,c=et(et(e,j(l,.07*o)),j(h,i*.06*o)),u={stroke:a.outline,lw:n},f=a.feet??a.limbs;if(t.bodyExtras.includes("fins")){const y=J([{x:-.13,y:-.06},{x:.13,y:-.06},{x:.24,y:.46},{x:-.24,y:.46}],.22);return{k:"group",x:c.x,y:c.y,rot:s.angle,s:o,items:[{k:"path",d:y,fill:f,stroke:a.outline,lw:n/o},{k:"line",pts:[0,.06,0,.38],stroke:a.outline,lw:n/o,alpha:.5}]}}return t.bodyExtras.includes("flippers")?{k:"ellipse",x:c.x,y:c.y,rx:.27*o,ry:.11*o,rot:s.angle,fill:f,...u}:t.bodyExtras.includes("boots")?{k:"rect",x:c.x,y:c.y,w:.4*o,h:.24*o,r:.09*o,rot:s.angle,fill:f,...u}:{k:"ellipse",x:c.x,y:c.y,rx:.2*o,ry:.13*o,rot:s.angle,fill:f,...u}}function xa(t,e,s,i){const n=t.palette,{U:r,L:a,S:l,r:h,d:o}=e,c=(x,m)=>({x:l.x+h.x*x+o.x*m,y:l.y+h.y*x+o.y*m}),u=x=>x.map(([m,g])=>c(m,g)),f={stroke:n.outline,lw:i},y=(x,m,g)=>[{k:"path",d:Le(x),stroke:n.outline,lw:m+i*2},{k:"path",d:Le(x),stroke:g,lw:m}],p=[];switch(t.tail){case"none":break;case"fluffy":{const x=u([[s*.5,a*.95],[s+.28*r,a*1],[s+.72*r,a*.62],[s+.78*r,a*.12],[s+.52*r,a*.32],[s+.3*r,a*.6],[s*.6,a*.7]]);p.push({k:"path",d:Z(x),fill:n.body,...f});const m=c(s+.72*r,a*.2);p.push({k:"ellipse",x:m.x,y:m.y,rx:.13*r,ry:.2*r,rot:e.angle+.25,fill:n.belly,...f});break}case"brush":{const x=u([[s*.4,a*.98],[s+.42*r,a*1.06],[s+.98*r,a*.66],[s+1.06*r,a*.12],[s+.86*r,-.04*r],[s+.66*r,a*.36],[s+.3*r,a*.66],[s*.5,a*.68]]);p.push({k:"path",d:Z(x),fill:n.body,...f});const m=u([[s+1.03*r,a*.36],[s+1.06*r,a*.12],[s+.86*r,-.04*r],[s+.72*r,a*.24],[s+.86*r,a*.34]]);p.push({k:"path",d:Z(m),fill:n.belly,...f});break}case"pom":{const x=c(s+.06*r,a*.88);p.push({k:"circle",x:x.x,y:x.y,r:.2*r,fill:n.belly,...f});break}case"long":case"striped":case"tuft":{const x=u([[s*.6,a*.9],[s+.35*r,a*.85],[s+.58*r,a*.4],[s+.5*r,-.02*r]]);if(p.push(...y(x,.14*r,n.body)),t.tail==="tuft"){const m=x[x.length-1];p.push({k:"circle",x:m.x,y:m.y,r:.16*r,fill:t.extraColors?.[0]??n.accent,...f})}if(t.tail==="striped"){for(const g of[.35,.6,.85]){const k=c(s+.35*r+.22999999999999998*r*(g*1.4>1?1:g*1.4),a*(.85-.85*g));p.push({k:"line",pts:[k.x-h.x*.08*r,k.y-h.y*.08*r,k.x+h.x*.08*r,k.y+h.y*.08*r],stroke:t.extraColors?.[0]??n.outline,lw:.06*r})}const m=x[x.length-1];p.push({k:"circle",x:m.x,y:m.y,r:.07*r,fill:t.extraColors?.[0]??n.outline})}break}case"curl":{const x=u([[s*.6,a*.9],[s+.4*r,a*.88],[s+.62*r,a*.45],[s+.5*r,a*.12],[s+.3*r,a*.24],[s+.36*r,a*.42]]);p.push(...y(x,.12*r,n.limbs));break}case"fish":{const x=u([[s*.6,a*.9],[s+.36*r,a*.86],[s+.6*r,a*.5]]);p.push(...y(x,.17*r,n.body));const m=x[x.length-1],g=J([{x:0,y:.06},{x:-.26,y:-.34},{x:.02,y:-.12},{x:.32,y:-.3}],.2);p.push({k:"group",x:m.x,y:m.y,rot:e.angle+.35,s:r,items:[{k:"path",d:g,fill:n.body,stroke:n.outline,lw:i/r}]});break}case"plume":{const x=t.extraColors??[n.accent];[0,1,2].forEach(m=>{const g=c(s+(.12+m*.13)*r,a+(.32-m*.06)*r);p.push({k:"ellipse",x:g.x,y:g.y,rx:.11*r,ry:.44*r,rot:e.angle-.55+m*.28,fill:x[(m+1)%x.length],...f})});break}case"thick":{const x=u([[s*.3,a*.42],[s+.42*r,a*.62],[s+.92*r,a*.96],[s+1.32*r,a*1.08],[s+1.44*r,a*.98],[s+.98*r,a*1.2],[s+.4*r,a*1.22],[s*.3,a*1.12]]);p.push({k:"path",d:Z(x,.8),fill:n.body,...f});const m=t.extraColors?.[0]??n.accent;for(const[g,k,E]of[[.28,.58,.26],[.62,.8,.22],[.96,1,.16]]){const w=c(s+g*r,a*k+.03*r),A=c(s+(g-.1)*r,a*k+E*r);p.push({k:"line",pts:[w.x,w.y,A.x,A.y],stroke:m,lw:.09*r})}break}case"spiky":case"arrow":{const x=u([[s*.3,a*.55],[s+.35*r,a*.68],[s+.95*r,a*.86],[s+.35*r,a*1.08],[s*.3,a*1.08]]);if(t.tail==="spiky"){for(const m of[.15,.45,.72]){const g=s+(.2+m*.7)*r,k=a*(.66+m*.19);p.push({k:"path",d:J(u([[g-.12*r,k+.05*r],[g,k-.2*r],[g+.12*r,k+.07*r]]),.2),fill:n.accent,...f})}p.push({k:"path",d:Z(x,.7),fill:n.body,...f})}else{const m=u([[s*.6,a*.9],[s+.4*r,a*.92],[s+.62*r,a*.5],[s+.62*r,a*.18]]);p.push(...y(m,.13*r,n.body));const g=m[m.length-1];p.push({k:"group",x:g.x,y:g.y,rot:e.angle,s:r,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:i/r}]})}break}}return p}function ga(t,e,s,i,n){const r=t.palette,a=et(e,j(s,-.08*i)),l=et(e,j(s,.52*i)),h=.2*i;return[{k:"line",pts:[a.x,a.y,l.x,l.y],stroke:r.outline,lw:.06*i+n*2},{k:"line",pts:[a.x,a.y,l.x,l.y],stroke:"#fff3d6",lw:.06*i},{k:"circle",x:l.x,y:l.y,r:.24*i,fill:r.accent,alpha:.28},{k:"group",x:l.x,y:l.y,rot:Math.atan2(s.y,s.x)+Math.PI/2,s:h,items:[{k:"path",d:ge,fill:r.accent,stroke:r.outline,lw:n*.9/h}]}]}function ba(t,e,s,i,n){const r=t.palette,a=t.extraColors?.[0]??"#cdeeff",l=[];for(const h of[-1,1]){const o=[[[h*s*.3,.12*i],[h*(s+.42*i),-.66*i],[h*(s+1*i),-.74*i],[h*(s+1.02*i),-.18*i],[h*(s+.5*i),.26*i]],[[h*s*.4,.3*i],[h*(s+.6*i),.36*i],[h*(s+.74*i),.78*i],[h*(s+.3*i),.9*i]]];for(const c of o){const u=Z(c.map(([x,m])=>e(x,m)),.9);l.push({k:"path",d:u,fill:a,alpha:.6}),l.push({k:"path",d:u,stroke:r.outline,lw:n*.9});const f=c[Math.floor(c.length/2)],y=e(c[0][0],c[0][1]),p=e(c[0][0]+(f[0]-c[0][0])*.75,c[0][1]+(f[1]-c[0][1])*.75);l.push({k:"line",pts:[y.x,y.y,p.x,p.y],stroke:"#ffffff",lw:n*.9,alpha:.85})}for(const[c,u,f]of[[s+.72*i,-.42*i,.075*i],[s+.44*i,-.16*i,.05*i],[s+.5*i,.6*i,.055*i]]){const y=e(h*c,u);l.push({k:"group",x:y.x,y:y.y,s:f,items:[{k:"path",d:ge,fill:"#ffffff"}]})}}return l}function ka(t,e,s,i,n,r,a,l,h,o){const c=t.palette,u=t.extraColors?.[1]??c.belly,f=[],y=Math.atan2(e(1,0).y-e(0,0).y,e(1,0).x-e(0,0).x),p=5,x=Math.max(i,n*.92)*1.08,m=(r*.8+a)/2,g=[0,4,1,3,2];for(const E of g){const w=E/(p-1)-.5,A=e(w*2*x,m+(.5-Math.abs(w))*.1*l);f.push({k:"ellipse",x:A.x,y:A.y,rx:x*.3,ry:.34*l,rot:y-w*.6,fill:E%2?u:c.body,stroke:c.outline,lw:h})}const k=Math.max(.04,o.head*(1-o.neck)-.04)*l;for(const E of[-1,1,0]){const w=e(E*s*.32,k+(E?0:.05*l));f.push({k:"ellipse",x:w.x,y:w.y,rx:s*.26,ry:.12*l,rot:y+E*.5,fill:E?u:c.body,stroke:c.outline,lw:h*.9})}return f}var wa={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 va(t,{cx:e=.5,cy:s=.36,T:i=.18}={}){const n={...wa,...t},r=new Array(Si*3).fill(0),a=(o,[c,u],f=.99)=>{r[o*3]=e+c*i,r[o*3+1]=s+u*i,r[o*3+2]=f};for(const o of Object.keys(U))a(U[o],n[o]);const l=n.tilt??0,h=(o,c)=>[n.nose[0]+o*Math.cos(l)-c*Math.sin(l),n.nose[1]+o*Math.sin(l)+c*Math.cos(l)];return a(Kt.leftEye,h(-.1,-.08)),a(Kt.rightEye,h(.1,-.08)),a(Kt.leftEar,h(-.22,-.02)),a(Kt.rightEar,h(.22,-.02)),r}var Ma=()=>va({}),Yi=.5,Ea=.15,Aa=class{constructor(t={}){d(this,"tracks",new Map),d(this,"offset",NaN),d(this,"lastArrival",NaN),d(this,"interval",33),d(this,"lastT",NaN),d(this,"lostMs"),d(this,"maxExtrapolateMs"),this.lostMs=t.lostMs??250,this.maxExtrapolateMs=t.maxExtrapolateMs??25}get delayMs(){return this.interval}push(t,e,s,i=Qi()){Number.isFinite(e)||(e=i),this.clock(e,i);const n=this.tracks.get(t);if(!n||e-n.tb>this.lostMs||e<n.tb-this.lostMs||s.length!==n.b.length){this.tracks.set(t,{a:null,ta:e,b:s,tb:e,out:null,outAt:NaN});return}if(s===n.b||e<=n.tb){e===n.tb&&s!==n.b&&(n.b=s,n.out=null);return}n.a=n.b,n.ta=n.tb,n.b=s,n.tb=e,n.out=null}at(t,e=Qi()){const s=this.tracks.get(t);if(!s)return null;if(!s.a)return s.b;if(s.out&&s.outAt===e)return s.out;const i=e-this.offset-this.interval,n=s.tb-s.ta,r=Math.min(n*.5,this.maxExtrapolateMs),a=Math.min(Math.max((i-s.ta)/n,0),1+r/n);return s.out=_a(s.a,s.b,a),s.outAt=e,s.out}forget(t){this.tracks.delete(t)}clear(){this.tracks.clear()}clock(t,e){const s=e-t;if(!Number.isFinite(this.offset)||s<this.offset||s>this.offset+1e3?this.offset=s:Number.isFinite(this.lastArrival)&&(this.offset+=Math.min(s-this.offset,(e-this.lastArrival)/1e3)),this.lastArrival=e,Number.isFinite(this.lastT)&&t>this.lastT){const i=t-this.lastT;i<this.interval*3+20&&(this.interval+=(Math.min(Math.max(i,8),100)-this.interval)*.1)}t<=this.lastT||(this.lastT=t)}},Qi=()=>globalThis.performance?.now()??Date.now();function _a(t,e,s){const i=e.slice(),n=s<.5?t:e;for(let r=0;r+2<e.length;r+=3){const a=t[r],l=t[r+1],h=e[r],o=e[r+1];t[r+2]>=Yi&&e[r+2]>=Yi&&Math.abs(h-a)+Math.abs(o-l)<Ea?(i[r]=a+(h-a)*s,i[r+1]=l+(o-l)*s,i[r+2]=t[r+2]+(e[r+2]-t[r+2])*Math.min(s,1)):(i[r]=n[r],i[r+1]=n[r+1],i[r+2]=n[r+2])}return i}var Kl=Ni.map(t=>t.id),ns=new Map(Ni.map(t=>[t.id,t])),Ne=ns.get("fox"),Sa=t=>typeof t=="string"&&ns.has(t),rs=t=>ns.get(t),Ta=t=>typeof t=="string"?ns.get(t)??Ne:t;function Ca(t,e,s){const i=Ta(t),n=Ma(),r=Ui(i,s),a=Os(n,{x:0,y:0,w:1,h:1},{band:r}),l=Vi(Di(i,.05)),h=-l.minY,o=Math.min(.27,.43/Math.max(h,1))*e,c=i.head==="snout-long"?(l.minX+l.maxX)/2*o:0,u=o/oe[r].head/a.U,f=.5*e+Math.min(0,(h-1.6)*.06*e),y={x:e/2-c-a.head.x*u,y:f-a.head.y*u,w:u,h:u};return qi(n,i,y,{portrait:!0,band:r})}function Ra(t,e,s=.5){if(!t||t.length!==e.length)return e.slice();const i=e.slice();for(let n=0;n+2<e.length;n+=3){const r=t[n+2],a=e[n+2],l=r>=.5,h=a>=.5;l&&a>=.3&&(i[n+2]=Math.max(a,.5));const o=Math.hypot(e[n]-t[n],e[n+1]-t[n+1]);if(l&&h&&o<.15){const c=s*Math.min(1,ji+(1-ji)*o/Fa);i[n]=t[n]+(e[n]-t[n])*c,i[n+1]=t[n+1]+(e[n+1]-t[n+1])*c}else l&&!h&&i[n+2]>=.5&&(i[n]=t[n],i[n+1]=t[n+1])}return Na(t,e,i,s*Pa),i}var ji=.1,Fa=.03,Pa=.35,La=11;function Na(t,e,s,i){const n=U.leftShoulder*3,r=U.rightShoulder*3,a=(u,f)=>u[f+2]>=.5;if(!a(t,n)||!a(t,r)||!a(e,n)||!a(e,r))return;const l=(u,f)=>(u[n+f]+u[r+f])/2,h=[l(t,0),l(t,1)],o=[l(e,0),l(e,1)],c=[l(s,0),l(s,1)];for(let u=0;u<La&&u*3+2<e.length;u++){const f=u*3;if(!a(t,f)||!a(e,f))continue;const y=[t[f]-h[0],t[f+1]-h[1]],p=[e[f]-o[0],e[f+1]-o[1]];Math.hypot(p[0]-y[0],p[1]-y[1])>=.15||(s[f]=c[0]+y[0]+(p[0]-y[0])*i,s[f+1]=c[1]+y[1]+(p[1]-y[1])*i)}}function Vi(t){const e={minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0},s=(i,n)=>{e.minX=Math.min(e.minX,i),e.minY=Math.min(e.minY,n),e.maxX=Math.max(e.maxX,i),e.maxY=Math.max(e.maxY,n)};for(const i of t){const n="lw"in i&&i.stroke?(i.lw??1)/2:0;switch(i.k){case"circle":s(i.x-i.r-n,i.y-i.r-n),s(i.x+i.r+n,i.y+i.r+n);break;case"ellipse":case"rect":{const r=i.k==="ellipse"?i.rx:i.w/2,a=i.k==="ellipse"?i.ry:i.h/2,l=Math.max(r,a)+n;s(i.x-l,i.y-l),s(i.x+l,i.y+l);break}case"path":{const r=qr(i.d);for(let a=0;a+1<r.length;a+=2)s(r[a]-n,r[a+1]-n),s(r[a]+n,r[a+1]+n);break}case"line":for(let r=0;r+1<i.pts.length;r+=2)s(i.pts[r]-n,i.pts[r+1]-n),s(i.pts[r]+n,i.pts[r+1]+n);break;case"group":{const r=Vi(i.items);if(!Number.isFinite(r.minX))break;const a=i.s??1,l=Math.cos(i.rot??0),h=Math.sin(i.rot??0);for(const[o,c]of[[r.minX,r.minY],[r.maxX,r.minY],[r.minX,r.maxY],[r.maxX,r.maxY]])s(i.x+(o*l-c*h)*a,i.y+(o*h+c*l)*a);break}}}return e}var be=()=>Float64Array.of(1,0,0,1,0,0);function Xt(t,e,s,i,n,r,a){const l=n?Math.cos(n):1,h=n?Math.sin(n):0,o=l*r,c=h*r,u=-h*a,f=l*a;if(!e)return t[0]=o,t[1]=c,t[2]=u,t[3]=f,t[4]=s,t[5]=i,t;const y=e[0],p=e[1],x=e[2],m=e[3];return t[0]=y*o+x*c,t[1]=p*o+m*c,t[2]=y*u+x*f,t[3]=p*u+m*f,t[4]=y*s+x*i+e[4],t[5]=p*s+m*i+e[5],t}function Ia(t,e,s){const i=t[0]*t[3]-t[1]*t[2];if(Math.abs(i)<1e-12)return null;const n=e-t[4],r=s-t[5];return[(t[3]*n-t[2]*r)/i,(-t[1]*n+t[0]*r)/i]}var Ki={white:16777215,black:0,red:16711680,transparent:0},Ie=new Map;function Bt(t){if(typeof t=="number")return[t&16777215,1];const e=Ie.get(t);if(e)return e;let s=[16777215,1];const i=t.trim().toLowerCase();if(i[0]==="#"){const n=i.slice(1),r=n.length<=4?[...n].map(l=>l+l).join(""):n,a=parseInt(r.slice(0,6),16);Number.isFinite(a)&&(s=[a,r.length===8?parseInt(r.slice(6,8),16)/255:1])}else if(i.startsWith("rgb")){const n=i.match(/-?\d*\.?\d+%?/g)?.map(o=>o.endsWith("%")?parseFloat(o)/100*255:parseFloat(o))??[],[r=255,a=255,l=255]=n,h=n[3]===void 0?1:i.match(/,\s*[\d.]+%\s*\)$/)?n[3]/255:n[3];s=[(zs(r)<<16|zs(a)<<8|zs(l))>>>0,Math.min(Math.max(h,0),1)]}else if(i in Ki)s=[Ki[i],i==="transparent"?0:1];else if(typeof document<"u"){const n=document.createElement("canvas").getContext("2d");if(n){n.fillStyle="#ffffff",n.fillStyle=i;const r=n.fillStyle;if(r!==i)return Ie.set(t,s=Bt(r)),s}}return Ie.size>512&&Ie.clear(),Ie.set(t,s),s}var zs=t=>Math.min(Math.max(Math.round(t),0),255);function ke(t,e,s=!1){const i=Math.min(Math.max(e,0),1),n=(t>>16&255)*i,r=(t>>8&255)*i,a=(t&255)*i,l=s?0:i*255;return(Math.round(l)<<24|Math.round(a)<<16|Math.round(r)<<8|Math.round(n))>>>0}var Oe=(t,e=1)=>`rgba(${t>>16&255},${t>>8&255},${t&255},${e})`;function Zi(t,e){if(t===16777215)return e;if(e===16777215)return t;const s=i=>Math.round((t>>i&255)*(e>>i&255)/255);return(s(16)<<16|s(8)<<8|s(0))>>>0}var ze={linear:t=>t,quadIn:t=>t*t,quadOut:t=>t*(2-t),quadInOut:t=>t<.5?2*t*t:-1+(4-2*t)*t,cubicOut:t=>1-(1-t)**3,sineInOut:t=>-(Math.cos(Math.PI*t)-1)/2,backOut:t=>1+(1.70158+1)*(t-1)**3+1.70158*(t-1)**2,elasticOut:t=>t===0||t===1?t:2**(-10*t)*Math.sin((t*10-.75)*(2*Math.PI/3))+1,bounceOut:t=>t<1/2.75?7.5625*t*t:t<2/2.75?7.5625*(t-=1.5/2.75)*t+.75:t<2.5/2.75?7.5625*(t-=2.25/2.75)*t+.9375:7.5625*(t-=2.625/2.75)*t+.984375};function Oa(t){let e=t>>>0;return()=>{e=e+1831565813>>>0;let s=e;return s=Math.imul(s^s>>>15,s|1),s^=s+Math.imul(s^s>>>7,s|61),((s^s>>>14)>>>0)/4294967296}}var De=1,Ji=2,as=0,Lt=1,za=4294967295,_={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},Zt=[],Da="x y rot sx sy alpha la lb lc ld world tint flags moved dirty gen parent first next prev stamp".split(" ");function tn(t){const e=_;for(const i of Da){const n=e[i],r=new n.constructor(i==="world"?t*6:t);r.set(n),e[i]=r}const s=new Int32Array(t);for(let i=0;i<_.freeCount;i++)s[i]=_.free[(_.freeHead+i)%_.cap];for(_.free=s,_.freeHead=0,_.cap=t,_.epoch++;Zt.length<t;)Zt.push(null)}function Ds(t){_.x[t]=_.y[t]=_.rot[t]=0,_.sx[t]=_.sy[t]=_.alpha[t]=1,_.la[t]=_.ld[t]=1,_.lb[t]=_.lc[t]=0;const e=t*6,s=_.world;s[e]=s[e+3]=1,s[e+1]=s[e+2]=s[e+4]=s[e+5]=0,_.tint[t]=16777215,_.flags[t]=De|Ji,_.moved[t]=1,_.dirty[t]=0,_.parent[t]=_.first[t]=_.next[t]=_.prev[t]=-1}tn(256),Ds(as),_.flags[as]=0,Ds(Lt),_.flags[Lt]=0;function Ba(){let t;if(_.freeCount){t=_.free[_.freeHead],_.freeHead=(_.freeHead+1)%_.cap,_.freeCount--;const e=Zt[t];e&&(e._i=as,e._g=-1,Zt[t]=null)}else _.top===_.cap&&tn(_.cap*2),t=_.top++;return Ds(t),t}function en(t,e){Bs(t);for(let i=_.first[t];i>=0;){const n=_.next[i];_.parent[i]=_.next[i]=_.prev[i]=-1,i=n}_.first[t]=-1,_.flags[t]=_.flags[t]&~Ji,_.moved[t]=0;const s=_.gen[t]+1;_.gen[t]=s,s!==za&&(e&&(Zt[t]=e),_.free[(_.freeHead+_.freeCount)%_.cap]=t,_.freeCount++)}function Ua(t){for(let e=0;e<Zt.length;e++){const s=Zt[e];s&&t(s)&&(s._i=as,s._g=-1,Zt[e]=null)}}function Ha(t,e){Bs(t);const s=_.first[e];_.parent[t]=e,_.next[t]=s,_.prev[t]=-1,s>=0&&(_.prev[s]=t),_.first[e]=t,_.moved[t]=1}function Bs(t){const e=_.parent[t];if(e<0)return;const s=_.next[t],i=_.prev[t];i>=0?_.next[i]=s:_.first[e]=s,s>=0&&(_.prev[s]=i),_.parent[t]=_.next[t]=_.prev[t]=-1}var Be={root:-1,gen:-1,world:new Float64Array(6)};function Ga(t){const e=++_.pass,s=_.world,i=t*6,n=Be.world;let r=Be.root!==t||Be.gen!==_.gen[t];for(let a=0;a<6;a++)n[a]!==s[i+a]&&(r=!0),n[a]=s[i+a];Be.root=t,Be.gen=_.gen[t],_.stamp[t]=r?e:e-1}function Xa(t){_.stamp[t]=_.pass}function sn(t){for(let e=_.first[t];e>=0;){const s=_.next[e];sn(e),e=s}en(t)}var Us=typeof FinalizationRegistry=="function"?new FinalizationRegistry(t=>_.gen[t.i]===t.g&&sn(t.i)):null;function nn(t){t._reg||!Us||(t._reg=!0,Us.register(t,{i:t._i,g:t._g},t))}function $a(t){t._reg&&Us.unregister(t)}var Hs=1,Gs=2,Xs=3,$s=4;function qs(t){if(t){for(let e=0;e<t.length;e++)if(t[e].enabled)return!0}return!1}function qa(t,e){let s=0;for(let i=0;i<t.length;i++){const n=t[i];n.enabled&&n.pad&&(s+=n.pad(e))}return s}var Ut={gl:null,c2d:null,live:null},V=new Float64Array(3),Ws=4,Wa=1,Ys=()=>Wa++,lt=be(),F=_,he=class{constructor(t){d(this,"kernel",t),d(this,"_i",Ba()),d(this,"_g",F.gen[this._i]),d(this,"_wv",null),d(this,"_wi",-1),d(this,"_we",-1),d(this,"blend","normal"),d(this,"_data",null),d(this,"parent",null),d(this,"hitRadius",null),d(this,"clip",null),d(this,"mask",null),d(this,"filters",null),d(this,"_z",0),d(this,"anchorX",0),d(this,"anchorY",0),d(this,"_pool",null),d(this,"_free",!1),d(this,"_reg",!1)}get x(){return F.x[this._i]}set x(t){const e=this._i||Lt;F.x[e]=t,F.moved[e]=1}get y(){return F.y[this._i]}set y(t){const e=this._i||Lt;F.y[e]=t,F.moved[e]=1}get rotation(){return F.rot[this._i]}set rotation(t){const e=this._i||Lt;F.rot[e]=t,F.dirty[e]=F.moved[e]=1}get scaleX(){return F.sx[this._i]}set scaleX(t){const e=this._i||Lt;F.sx[e]=t,F.dirty[e]=F.moved[e]=1}get scaleY(){return F.sy[this._i]}set scaleY(t){const e=this._i||Lt;F.sy[e]=t,F.dirty[e]=F.moved[e]=1}get alpha(){return F.alpha[this._i]}set alpha(t){const e=this._i||Lt;F.alpha[e]=t,F.moved[e]=1}get visible(){return(F.flags[this._i]&De)!==0}set visible(t){const e=this._i||Lt;t?F.flags[e]=F.flags[e]|De:F.flags[e]=F.flags[e]&~De,F.moved[e]=1}get destroyed(){return F.gen[this._i]!==this._g}get world(){const t=this._i||Lt;return(this._wi!==t||this._we!==F.epoch)&&(this._wv=F.world.subarray(t*6,t*6+6),this._wi=t,this._we=F.epoch),this._wv}get data(){return this._data??(this._data={})}set data(t){this._data=t}get scale(){return this.scaleX}set scale(t){this.scaleX=this.scaleY=t}get z(){return this._z}set z(t){t!==this._z&&(this._z=t,this.parent&&(this.parent.sortDirty=!0))}get tint(){return F.tint[this._i]}set tint(t){F.tint[this._i||Lt]=typeof t=="number"?t&16777215:Bt(t)[0]}set anchor(t){typeof t=="number"?this.anchorX=this.anchorY=t:(this.anchorX=t.x,this.anchorY=t.y)}get width(){return 0}set width(t){}get height(){return 0}set height(t){}set(t){for(const e in t){const s=t[e];s!==void 0&&(this[e]=s)}return this}destroy(){this.destroyed||(this.visible=!1,this.parent&&(this.parent.dead=!0,this.parent=null),en(this._i,this),$a(this),this.kernel.tweens.stopAll(this),this._pool?.forget(this))}updateWorld(){const t=this.parent?this.parent.updateWorld():null;return Xt(this.world,t,this.x,this.y,this.rotation,this.scaleX,this.scaleY)}draw(t,e,s){}};function Ya(t){Ua(e=>e.kernel===t)}var Qs=!1,rn=Object.freeze([]),js=class xr extends he{constructor(e){super(e),d(this,"children",rn),d(this,"sortDirty",!1),d(this,"dead",!1),nn(this)}add(e,...s){this.adopt(e);for(let i=0;i<s.length;i++)this.adopt(s[i]);return e}adopt(e){e.parent&&e.parent.detach(e),e.parent=this,!e.destroyed&&!this.destroyed&&Ha(e._i,this._i),this.children===rn&&(this.children=[]),this.children.push(e),(e.z!==0||this.sortDirty)&&(this.sortDirty=!0)}remove(e){this.detach(e),e._pool||nn(e)}detach(e){const s=this.children,i=s.indexOf(e);if(i>=0){for(let n=i+1;n<s.length;n++)s[n-1]=s[n];s.pop()}e.parent===this&&(e.parent=null,e.destroyed||Bs(e._i))}clear(){for(const e of this.children)e.destroy()}destroy(){for(const e of this.children)e.destroy();super.destroy()}sweep(){if(this.dead){this.dead=!1;let e=0;for(const s of this.children)s.destroyed?s.parent===this&&(s.parent=null):this.children[e++]=s;this.children.length=e}for(const e of this.children)e instanceof xr&&e.sweep()}draw(e,s,i){if(Qs)return F.parent[this._i]<0&&!this.destroyed&&Xa(this._i),this.drawChildren(e,s,i);Qs=!0;try{this.destroyed||Ga(this._i),this.drawChildren(e,s,i)}finally{Qs=!1}}drawChildren(e,s,i){if(this.sortDirty){const l=new Map(this.children.map((h,o)=>[h,o]));this.children.sort((h,o)=>h.z-o.z||l.get(h)-l.get(o)),this.sortDirty=!1}const n=this.children,r=this._i,a=F.stamp[r]===F.pass;for(let l=0;l<n.length;l++){const h=n[l],o=h._i,c=F.alpha[o];if(F.gen[o]!==h._g||!(F.flags[o]&De)||c<=0)continue;if(a||F.moved[o]){F.moved[o]=0,F.stamp[o]=F.pass;let y,p,x,m;if(F.dirty[o]){F.dirty[o]=0;const I=F.rot[o],q=I?Math.cos(I):1,Q=I?Math.sin(I):0,H=F.sx[o],It=F.sy[o];F.la[o]=y=q*H,F.lb[o]=p=Q*H,F.lc[o]=x=-Q*It,F.ld[o]=m=q*It}else y=F.la[o],p=F.lb[o],x=F.lc[o],m=F.ld[o];const g=F.world,k=F.x[o],E=F.y[o],w=o*6,A=r*6,C=g[A],R=g[A+1],O=g[A+2],P=g[A+3];g[w]=C*y+O*p,g[w+1]=R*y+P*p,g[w+2]=C*x+O*m,g[w+3]=R*x+P*m,g[w+4]=C*k+O*E+g[A+4],g[w+5]=R*k+P*E+g[A+5]}const u=s*c,f=Zi(i,F.tint[o]);h.clip||h.mask||h.filters?on(e,h,u,f):h.draw(e,u,f)}}},pt=new Float64Array(128),ce=0,Vs=new Float64Array(8);function an(t,e,s,i){e.clip||e.mask||e.filters?on(t,e,s,i):e.draw(t,s,i)}function on(t,e,s,i){const n=t.r,r=e.world,a=e.clip;let l=!1,h=!1;if(a)if(Math.abs(r[1])<1e-9&&Math.abs(r[2])<1e-9&&ce<32){const u=r[0]*a.x+r[4],f=r[0]*(a.x+a.width)+r[4],y=r[3]*a.y+r[5],p=r[3]*(a.y+a.height)+r[5];let x=Math.min(u,f),m=Math.max(u,f),g=Math.min(y,p),k=Math.max(y,p);if(ce){const w=(ce-1)*4;x=Math.max(x,pt[w]),g=Math.max(g,pt[w+1]),m=Math.min(m,pt[w+2]),k=Math.min(k,pt[w+3])}const E=ce++*4;pt[E]=x,pt[E+1]=g,pt[E+2]=m,pt[E+3]=k,n.clip(x,g,Math.max(m-x,0),Math.max(k-g,0)),h=!0}else l=!0;const o=e.mask&&e.mask.visible?e.mask:null,c=qs(e.filters)?e.filters:null;try{if(l&&n.beginLayer(),o&&n.beginLayer(),c?(e.draw(t,n.beginLayer()?1:s,i),n.endLayer(s,c)):e.draw(t,s,i),o&&(n.beginMask(),Xt(o.world,r,o.x,o.y,o.rotation,o.scaleX,o.scaleY),an(t,o,o.alpha,16777215),n.endLayer(1)),l&&a){n.beginMask();for(let u=0;u<4;u++){const f=u===1||u===2?a.x+a.width:a.x,y=u>1?a.y+a.height:a.y;Vs[u*2]=r[0]*f+r[2]*y+r[4],Vs[u*2+1]=r[1]*f+r[3]*y+r[5]}n.polygon(Vs,4,16777215,1),n.endLayer(1)}}finally{if(h)if(ce--,ce){const u=(ce-1)*4;n.clip(pt[u],pt[u+1],pt[u+2]-pt[u],pt[u+3]-pt[u+1])}else n.unclip()}}var we=class extends he{constructor(t,e,s){super(t),d(this,"_frame",null),d(this,"_w",null),d(this,"_h",null),d(this,"slice",0),d(this,"autoAnchor",!0),d(this,"frameName",null),e&&(this.frame=e),s?.anchor===void 0&&this.useFrameAnchor(),s&&this.set(s)}get frame(){return this._frame}set frame(t){this.frameName=typeof t=="string"?t:null,this._frame=typeof t=="string"?this.kernel.frame(t):t,this.autoAnchor&&this.useFrameAnchor()}set anchor(t){this.autoAnchor=!1,super.anchor=t}get naturalWidth(){const t=this.frameNow();return t?(t.sw??t.w)/t.scale-t.margin*2:0}get naturalHeight(){const t=this.frameNow();return t?(t.sh??t.h)/t.scale-t.margin*2:0}get width(){return this._w??this.naturalWidth}set width(t){this._w=t}get height(){return this._h??this.naturalHeight}set height(t){this._h=t}sizeQ(t){Ee[0]=this._w??(t.sw??t.w)/t.scale-t.margin*2,Ee[1]=this._h??(t.sh??t.h)/t.scale-t.margin*2}frameNow(){return this.frameName&&!this.kernel.atlas.valid(this._frame)&&(this._frame=this.kernel.frame(this.frameName)),this._frame}useFrameAnchor(){const t=this._frame;if(!t)return;const e=(t.sw??t.w)/t.scale-t.margin*2,s=(t.sh??t.h)/t.scale-t.margin*2;this.anchorX=e>0?(t.ox-t.margin)/e:0,this.anchorY=s>0?(t.oy-t.margin)/s:0}draw(t,e,s){const i=this.frameNow();if(!i)return;const n=Ee;this.sizeQ(i),n[2]=this.anchorX,n[3]=this.anchorY,n[4]=e,Qa(t,i,this.world,this.slice,s,this.blend)}},ve=new Float64Array(12),Me=new Float64Array(12),Ue={x:0,y:0,w:0,h:0};function ln(t,e,s,i,n,r){e=Math.max(e,0),s=Math.max(s,0),i=Math.max(i,0);const a=s+i>n?s*n/(s+i):s,l=s+i>n?i*n/(s+i):i;let h=a/r,o=l/r;if(h+o>e){const c=e/(h+o);h*=c,o*=c}t[0]=0,t[1]=h,t[2]=0,t[3]=a,t[4]=h,t[5]=e-h-o,t[6]=a,t[7]=n-a-l,t[8]=e-o,t[9]=o,t[10]=n-l,t[11]=l}var Ee=new Float64Array(5);function Qa(t,e,s,i,n,r){const a=Ee,l=a[0],h=a[1],o=a[2],c=a[3],u=a[4],f=t.tex(e.surface),y=i===0?e.slice??0:i;if(y===0){const w=(e.sw??e.w)/e.scale-e.margin*2,A=(e.sh??e.h)/e.scale-e.margin*2,C=w>0?l/w:1,R=A>0?h/A:1,O=-o*l+((e.tx??0)/e.scale-e.margin)*C,P=-c*h+((e.ty??0)/e.scale-e.margin)*R;os(s,O,P),V[0]=e.w/e.scale*C,V[1]=e.h/e.scale*R,V[2]=u,t.r.quadQ(f,e,lt,n,r);return}const p=e.tx??0,x=e.ty??0,m=(e.sw??e.w)-e.w-p,g=(e.sh??e.h)-e.h-x,k=-o*l-e.margin+p/e.scale,E=-c*h-e.margin+x/e.scale;if(ln(ve,l+e.margin*2-(p+m)/e.scale,(typeof y=="number"?y:y[3])-p,(typeof y=="number"?y:y[1])-m,e.w,e.scale),ln(Me,h+e.margin*2-(x+g)/e.scale,(typeof y=="number"?y:y[0])-x,(typeof y=="number"?y:y[2])-g,e.h,e.scale),os(s,k,E),V[2]=u,!t.r.nineQ?.(f,e,ve,Me,lt,n,r))for(let w=0;w<12;w+=4){const A=Me[w+1],C=Me[w+3];if(!(A<=0||C<=0))for(let R=0;R<12;R+=4){const O=ve[R+1],P=ve[R+3];O<=0||P<=0||(Ue.x=e.x+ve[R+2],Ue.y=e.y+Me[w+2],Ue.w=P,Ue.h=C,os(s,k+ve[R],E+Me[w]),V[0]=O,V[1]=A,V[2]=u,t.r.quadQ(f,Ue,lt,n,r))}}}function os(t,e,s){lt[0]=t[0],lt[1]=t[1],lt[2]=t[2],lt[3]=t[3],lt[4]=t[0]*e+t[2]*s+t[4],lt[5]=t[1]*e+t[3]*s+t[5]}var He=class extends we{constructor(t,e,s={}){super(t,null),d(this,"_spec"),d(this,"baked",null),d(this,"bakedEffects",!0),this._spec=e,this.bake(),s.anchor===void 0&&this.useFrameAnchor(),this.set(s)}get spec(){return this._spec}set spec(t){this._spec=t,this.baked=null,this._w=this._h=null,this.bake()}bake(){const t=this.kernel;return this.baked&&t.atlas.valid(this.baked.frame)&&this.baked.frame.scale===t.pixelScale&&this.bakedEffects===t.effects?this.baked:(this.bakedEffects=t.effects,this.baked=t.shape(this._spec),this._frame=this.baked.frame,this.slice=this.baked.slice,this.baked)}frameNow(){return this.bake().frame}sizeQ(){const t=this.bake();Ee[0]=this._w??t.w,Ee[1]=this._h??t.h}get width(){return this._w??this.bake().w}set width(t){this._w=t}get height(){return this._h??this.bake().h}set height(t){this._h=t}},hn=(t,e,s)=>t===void 0?e:typeof t=="number"?t:t[0]+(t[1]-t[0])*s(),cn=class Ke extends he{constructor(e,s,i={}){super(e),d(this,"max"),d(this,"f"),d(this,"tints"),d(this,"count",0),d(this,"gravity"),d(this,"drag"),d(this,"frameRef"),d(this,"random",Math.random),this.frameRef=s,this.max=Math.max(1,Math.floor(i.max??200)),this.f=new Float32Array(this.max*Ke.W),this.tints=new Uint32Array(this.max),this.blend=i.blend??"normal",this.gravity=i.gravity??0,this.drag=i.drag??1}get alive(){return this.count}burst(e,s,i,n={}){const r=Ke.W,a=this.random,l=n.tint===void 0?16777215:Bt(n.tint)[0];for(let h=0;h<i;h++){let o=this.count;if(o>=this.max){let x=0,m=1/0;for(let g=0;g<this.max;g++){const k=this.f[g*r+5]-this.f[g*r+4];k<m&&(m=k,x=g)}o=x}else this.count++;const c=(n.angle??0)+(n.spread===void 0?a()*Math.PI*2:(a()-.5)*n.spread),u=hn(n.speed,200,a),f=Array.isArray(n.scale)?n.scale[0]:n.scale??1,y=Array.isArray(n.scale)?n.scale[1]:n.scale??1,p=o*r;this.f[p]=e,this.f[p+1]=s,this.f[p+2]=Math.cos(c)*u,this.f[p+3]=Math.sin(c)*u,this.f[p+4]=0,this.f[p+5]=Math.max(hn(n.life,.8,a),.01),this.f[p+6]=a()*Math.PI*2,this.f[p+7]=(a()-.5)*2*(n.spin??0),this.f[p+8]=f,this.f[p+9]=y,this.f[p+10]=n.alpha??1,this.tints[o]=l}}update(e){const s=Ke.W,i=this.f,n=this.drag>=1?1:Math.pow(Math.max(this.drag,0),e);for(let r=0;r<this.count;){const a=r*s;if(i[a+4]=i[a+4]+e,i[a+4]>=i[a+5]){const l=--this.count;r!==l&&(i.copyWithin(a,l*s,l*s+s),this.tints[r]=this.tints[l]);continue}i[a+3]=(i[a+3]+this.gravity*e)*n,i[a+2]=i[a+2]*n,i[a]=i[a]+i[a+2]*e,i[a+1]=i[a+1]+i[a+3]*e,i[a+6]=i[a+6]+i[a+7]*e,r++}}clear(){this.count=0}draw(e,s,i){if(!this.count)return;const n=typeof this.frameRef=="string"?this.frameRef=this.kernel.frame(this.frameRef):this.frameRef,r=Ke.W,a=this.f,l=this.world,h=n.w/n.scale,o=n.h/n.scale;for(let c=0;c<this.count;c++){const u=c*r,f=a[u+4]/a[u+5],y=a[u+8]+(a[u+9]-a[u+8])*f,p=s*a[u+10]*(1-f*f),x=a[u+6],m=Math.cos(x)*y,g=Math.sin(x)*y,k=a[u],E=a[u+1],w=l[0],A=l[1],C=l[2],R=l[3],O=w*m+C*g,P=A*m+R*g,I=C*m-w*g,q=R*m-A*g;lt[0]=O,lt[1]=P,lt[2]=I,lt[3]=q,lt[4]=w*k+C*E+l[4]-(O*h+I*o)/2,lt[5]=A*k+R*E+l[5]-(P*h+q*o)/2,V[0]=h,V[1]=o,V[2]=p,e.r.quadQ(e.tex(n.surface),n,lt,Zi(i,this.tints[c]),this.blend)}}};d(cn,"W",11);var fn=cn,fe=class extends we{constructor(t,e,s={}){const{fps:i,loop:n,playing:r,speed:a,onComplete:l,...h}=s;if(!e.frames.length)throw new Error("[engine] an animation needs at least one frame");super(t,e.frames[0],h),d(this,"frames"),d(this,"durations"),d(this,"fps"),d(this,"loop"),d(this,"speed"),d(this,"onComplete"),d(this,"_playing"),d(this,"index",0),d(this,"t",0),this.frames=e.frames,this.durations=e.durations&&i===void 0?e.durations:null,this.fps=i??12,this.loop=n!==!1,this.speed=a??1,this.onComplete=l??null,this._playing=r!==!1,this.speed<0&&this.show(e.frames.length-1)}get frameIndex(){return this.index}get frameCount(){return this.frames.length}get playing(){return this._playing}play(){return!this.loop&&!this._playing&&this.index===(this.speed<0?0:this.frames.length-1)&&this.show(this.speed<0?this.frames.length-1:0),this._playing=!0,this}stop(){return this._playing=!1,this}gotoFrame(t){const e=this.frames.length;return this.show((Math.floor(t)%e+e)%e),this.t=0,this}gotoAndPlay(t){return this._playing=!0,this.gotoFrame(t)}gotoAndStop(t){return this._playing=!1,this.gotoFrame(t)}show(t){t===this.index&&this._frame||(this.index=t,this.frame=this.frames[t])}secondsOf(t){const e=this.durations?.[t];return e!==void 0&&e>0?e:1/Math.max(this.fps,.001)}update(t){if(!this._playing||this.destroyed||this.speed===0)return;const e=this.frames.length,s=this.speed<0;this.t+=t*Math.abs(this.speed);let i=this.index;for(let n=0;n<1e3;n++){const r=this.secondsOf(i);if(this.t<r)break;this.t-=r;const a=s?i-1:i+1;if(a<0||a>=e){if(!this.loop){this.t=0,this._playing=!1,this.show(i),this.onComplete?.();return}i=s?e-1:0}else i=a}this.show(i)}},ja=(t,e)=>t.localeCompare(e,void 0,{numeric:!0}),un=class{constructor(t,e,s=2){d(this,"width",t),d(this,"height",e),d(this,"padding",s),d(this,"shelves",[]),d(this,"free",[]),d(this,"bottom",0)}alloc(t,e){const s=Math.ceil(t)+this.padding*2,i=Math.ceil(e)+this.padding*2;if(s>this.width||i>this.height)return null;for(let a=0;a<this.free.length;a++){const l=this.free[a];if(l.w>=s&&l.h>=i&&l.w*l.h<=s*i*2)return this.free.splice(a,1),this.inner(l.x,l.y,t,e)}let n=null;for(const a of this.shelves)a.h>=i&&a.h<=i*1.5+8&&this.width-a.x>=s&&(!n||a.h<n.h)&&(n=a);if(!n)if(this.bottom+i>this.height){for(const a of this.shelves)a.h>=i&&this.width-a.x>=s&&(n=a);if(!n)return null}else n={y:this.bottom,h:i,x:0},this.shelves.push(n),this.bottom+=i;const r=n.x;return n.x+=s,this.inner(r,n.y,t,e)}release(t){this.free.push({x:t.x-this.padding,y:t.y-this.padding,w:Math.ceil(t.w)+this.padding*2,h:Math.ceil(t.h)+this.padding*2})}get fill(){return this.bottom/this.height}reset(){this.shelves=[],this.free=[],this.bottom=0}inner(t,e,s,i){return{x:t+this.padding,y:e+this.padding,w:s,h:i}}},ls=t=>({source:t,texture:null,pending:[]}),Ks=class{constructor(t=2048,e=4){d(this,"pageSize",t),d(this,"maxPages",e),d(this,"pages",[]),d(this,"gen",1),d(this,"onPage",()=>{}),d(this,"onDrop",()=>{})}valid(t){return!!t&&(t.gen===this.gen||t.gen===0)}bake(t,e,s,i=1,n=0,r=0,a=0){const l=Math.max(1,Math.ceil(t)),h=Math.max(1,Math.ceil(e)),o=document.createElement("canvas");o.width=l,o.height=h;const c=o.getContext("2d");return s(c),this.put(o,l,h,i,n,r,a)}add(t,e=1,s=0,i=0){const n=document.createElement("canvas");return n.width=Math.max(1,t.width),n.height=Math.max(1,t.height),n.getContext("2d").drawImage(t,0,0),this.put(n,n.width,n.height,e,s,i,0)}release(t){if(t.gen!==this.gen)return;this.pages.find(s=>s.surface===t.surface)?.packer.release(t)}rebake(t,e,s,i,n=t.w,r=t.h){if(!this.valid(t)||e>n||s>r)return null;const a=Math.max(1,Math.ceil(e)),l=Math.max(1,Math.ceil(s)),h=this.pages.find(c=>c.surface===t.surface);if(!h)return null;const o=document.createElement("canvas");return o.width=Math.ceil(n),o.height=Math.ceil(r),i(o.getContext("2d")),h.ctx.clearRect(t.x,t.y,o.width,o.height),h.ctx.drawImage(o,t.x,t.y),t.surface.pending.push([o,t.x,t.y]),t.w=a,t.h=l,t}put(t,e,s,i,n,r,a){let l=null,h=this.pages.find(c=>(l=c.packer.alloc(e,s))!==null);if(h||(!(Math.max(e,s)+4>this.pageSize)&&this.pages.length>=this.maxPages&&(this.wipe(),h=this.pages[0],l=h?h.packer.alloc(e,s):null),(!h||!l)&&(h=this.newPage(Math.max(e,s)),l=h.packer.alloc(e,s))),!l)throw new Error(`[engine] ${e}\xD7${s} does not fit an atlas page`);const o=l;return h.ctx.drawImage(t,o.x,o.y),h.surface.pending.push([t,o.x,o.y]),{surface:h.surface,x:o.x,y:o.y,w:e,h:s,scale:i,gen:this.gen,ox:n,oy:r,margin:a}}newPage(t){let e=this.pageSize;for(;e<t+4;)e*=2;const s=document.createElement("canvas");s.width=s.height=e;const i=s.getContext("2d"),n=ls(s),r={surface:n,packer:new un(e,e),ctx:i};return this.pages.push(r),this.onPage(n),r}wipe(){this.gen++;let t=0;for(let e=0;e<this.pages.length;e++){const s=this.pages[e];if(t<this.maxPages&&s.surface.source.width===this.pageSize){this.pages[t++]=s;continue}s.surface.pending=[],this.onDrop(s.surface)}this.pages.length=t;for(const e of this.pages)e.packer.reset(),e.ctx.clearRect(0,0,e.surface.source.width,e.surface.source.height),e.surface.pending=[],e.surface.pending.push([e.surface.source,0,0])}},Va=()=>{const t=typeof document<"u"?document.timeline?.currentTime:null;return typeof t=="number"&&Number.isFinite(t)?t:globalThis.performance?.now()??Date.now()},dn=()=>globalThis.performance?.now()??Date.now(),pn=class{constructor(t=Va){d(this,"now",t),d(this,"known",new Map),d(this,"smoothed",new Map),d(this,"times",new WeakMap),d(this,"lerp",new Aa),d(this,"drawnAt",NaN),d(this,"drawn",0),d(this,"smoothedBody",(e,s={})=>{const i=s.interpolate!==!1;if(typeof e=="number"){const n=this.smoothed.get(e);return n?i?this.lerp.at(e,this.tick())??n.body:n.body:null}return typeof e!="object"||e===null||!Array.isArray(e.body)?null:this.posed(e.id,e.body,Ka(s.smooth),i)})}note(t,e,s=dn()){for(const i of t)this.known.set(i.id,this.resolve(i.id,i.avatar)),e!==void 0&&Number.isFinite(e)&&Array.isArray(i.body)&&this.times.set(i.body,{t:e,arrival:s})}of(t){return typeof t=="object"&&t!==null?t.avatar!==void 0?this.resolve(t.id,t.avatar):this.of(t.id):this.known.get(t)??Ci(t-1)}posed(t,e,s,i=!0){const n=this.smooth(t,e,s);return i?this.lerp.at(t,this.tick())??n:n}smooth(t,e,s){const i=this.smoothed.get(t);if(i&&i.raw===e&&i.amount===s)return i.body;i&&i.amount!==s&&this.lerp.forget(t);const n=s<1?Ra(i?.body,e,s):e;this.smoothed.set(t,{raw:e,body:n,amount:s});const r=this.times.get(e),a=r?.arrival??dn();return this.lerp.push(t,r?.t??a,n,a),n}takeDrawn(){const t=this.drawn;return this.drawn=0,t}tick(){const t=this.now();return t!==this.drawnAt&&(this.drawnAt=t,this.drawn++),t}resolve(t,e){return Sa(e)?e:Ci(t-1)}},Ka=t=>t===!1?1:typeof t=="number"?Math.min(Math.max(t,.05),1):.5,yn=new Float64Array(1),mn=new Int32Array(yn.buffer),Ae=(t,e)=>(t=Math.imul(t^e,1540483477),t^t>>>15);function Jt(t,e=2538058380){return t!==t?Ae(e,2146959360):(yn[0]=t===0?0:t,Ae(Ae(e,mn[0]),mn[1]))}function xn(t,e=2166136261){for(let s=0;s<t.length;s++)e=Math.imul(e^t.charCodeAt(s),16777619);return e}function te(t){switch(typeof t){case"number":return Jt(t);case"string":return xn(t);case"boolean":return t?1013904242:461845907;case"object":{if(t===null)return 625341585;if(Array.isArray(t)||t instanceof Float64Array){let i=1779033703^t.length;for(let n=0;n<t.length;n++){const r=t[n];i=Ae(i,typeof r=="number"?Jt(r):te(r))}return i}let e=1359893119;const s=t;for(const i in s){const n=s[i];n!==void 0&&(e=e+Ae(xn(i),te(n))|0)}return Ae(e,2600822924)}default:return 0}}function Ge(t,e){if(t===e)return!0;if(typeof t!="object"||typeof e!="object"||t===null||e===null)return typeof t=="number"&&typeof e=="number"&&t!==t&&e!==e;const s=Array.isArray(t)||t instanceof Float64Array;if(s!==(Array.isArray(e)||e instanceof Float64Array))return!1;if(s){const r=t,a=e;if(r.length!==a.length)return!1;for(let l=0;l<r.length;l++)if(r[l]!==a[l]&&!Ge(r[l],a[l]))return!1;return!0}const i=t,n=e;for(const r in i)if(i[r]!==void 0&&!Ge(i[r],n[r]))return!1;for(const r in n)if(n[r]!==void 0&&i[r]===void 0)return!1;return!0}function hs(t){if(typeof t!="object"||t===null)return t;if(Array.isArray(t))return t.map(hs);if(t instanceof Float64Array)return t.slice();const e={};for(const s in t)t[s]!==void 0&&(e[s]=hs(t[s]));return e}var gn=class{constructor(t=1/0){d(this,"max",t),d(this,"buckets",new Map),d(this,"n",0)}get size(){return this.n}get(t,e=te(t)){const s=this.buckets.get(e);if(s){for(let i=0;i<s.length;i++)if(Ge(s[i].key,t))return s[i].value}}set(t,e,s=te(t)){let i=this.buckets.get(s);if(i){for(const n of i)if(Ge(n.key,t)){n.value=e;return}}this.n>=this.max&&this.clear(),(!i||!this.buckets.has(s))&&this.buckets.set(s,i=[]),i.push({key:hs(t),value:e}),this.n++}clear(){this.buckets.clear(),this.n=0}},Zs=0,bn=1,cs=2,Js=3,kn=class{constructor(){d(this,"scale",1),d(this,"cOn",!1),d(this,"px0",0),d(this,"py0",0),d(this,"px1",0),d(this,"py1",0),d(this,"clipVer",0),d(this,"stack",[]),d(this,"sp",0),d(this,"real",0),d(this,"mute",0),d(this,"bnd",new Float64Array(4*(Ws+1))),d(this,"rx0",0),d(this,"ry0",0),d(this,"rx1",0),d(this,"ry1",0),d(this,"maxBlur",1/0),d(this,"time",0),d(this,"skipped",0),d(this,"gq",new Float64Array(4))}resetLayers(t){this.scale=t,this.sp=this.real=this.mute=0,this.skipped=0,this.cOn=!1,this.clipVer++}growQ(){const t=this.gq;this.grow(t[0],t[1],t[2],t[3])}grow(t,e,s,i){if(!this.real)return;const n=this.bnd,r=(this.real-1)*4;t<n[r]&&(n[r]=t),e<n[r+1]&&(n[r+1]=e),s>n[r+2]&&(n[r+2]=s),i>n[r+3]&&(n[r+3]=i)}area(t,e){const s=this.bnd,i=t*4,n=this.scale;return this.rx0=Math.max(Math.floor((s[i]-e)*n)-1,0),this.ry0=Math.max(Math.floor((s[i+1]-e)*n)-1,0),this.rx1=Math.min(Math.ceil((s[i+2]+e)*n)+1,this.canvas.width),this.ry1=Math.min(Math.ceil((s[i+3]+e)*n)+1,this.canvas.height),this.rx1>this.rx0&&this.ry1>this.ry0}clip(t,e,s,i){const n=this.scale,r=this.canvas.width,a=this.canvas.height,l=Math.min(Math.max(Math.round(t*n),0),r),h=Math.min(Math.max(Math.round(e*n),0),a),o=Math.min(Math.max(Math.round((t+s)*n),l),r),c=Math.min(Math.max(Math.round((e+i)*n),h),a);this.cOn&&l===this.px0&&h===this.py0&&o===this.px1&&c===this.py1||(this.cOn=!0,this.px0=l,this.py0=h,this.px1=o,this.py1=c,this.clipVer++)}unclip(){this.cOn&&(this.cOn=!1,this.clipVer++)}push(t){if(t<cs&&(this.mute||this.real>=Ws||!this.pushLayer())&&(t+=2),t===Js)this.mute++;else if(t!==cs){const e=this.real*4;this.bnd[e]=this.bnd[e+1]=1/0,this.bnd[e+2]=this.bnd[e+3]=-1/0,this.real++}return this.stack[this.sp++]=t,t<cs}beginLayer(){return this.push(Zs)}beginMask(){this.push(this.sp&&this.stack[this.sp-1]===Zs?bn:Js)}endLayer(t,e){if(!this.sp)return;let s=this.stack[--this.sp];if(s===Js){if(this.mute--,!this.sp)return;s=this.stack[--this.sp]}if(s===bn){const i=--this.real,n=this.popLayer();this.area(i-1,0)&&this.composite(n,!0,1,null);const r=this.bnd,a=(i-1)*4,l=i*4;r[a]=Math.max(r[a],r[l]),r[a+1]=Math.max(r[a+1],r[l+1]),r[a+2]=Math.min(r[a+2],r[l+2]),r[a+3]=Math.min(r[a+3],r[l+3]),s=this.stack[--this.sp]}if(s===cs)qs(e)&&(this.skipped+=e.length);else if(s===Zs){const i=--this.real,n=qs(e)?e:null,r=this.popLayer();if(this.area(i,n?qa(n,this.maxBlur):0)){this.composite(r,!1,t,n);const a=this.scale;this.grow(this.rx0/a,this.ry0/a,this.rx1/a,this.ry1/a)}}}closeLayers(){for(;this.sp;)this.endLayer(1)}},Za=256,wn=8<<20,gt=new Float64Array(32),bt={x:0,y:0,w:0,h:0};function Ja(t){if(typeof t.filter!="string")return!1;t.filter="blur(1px)";const e=t.filter==="blur(1px)";return t.filter="none",e}function ti(t){const e=t.getContext("2d",{alpha:!0});return e?new to(t,e):null}var to=class extends kn{constructor(t,e){super(),d(this,"canvas",t),d(this,"ctx",e),d(this,"kind","canvas2d"),d(this,"maxTextureSize",4096),d(this,"features",{}),d(this,"info",{renderer:"canvas2d"}),d(this,"support"),d(this,"lost",!1),d(this,"fxr",null),d(this,"quads",0),d(this,"stats",{drawCalls:0,quads:0,filtersSkipped:0}),d(this,"tinted",new Map),d(this,"tintedN",0),d(this,"lostListeners",[]),d(this,"restoredListeners",[]),d(this,"base"),d(this,"top"),d(this,"layers",[]),d(this,"scratch",[]),d(this,"nines",new Map),d(this,"ninePx",0),d(this,"frame",0),d(this,"hit",!1),d(this,"missed",new Map),this.support={filters:Ja(e),shaders:!1},this.base=this.top={ctx:e,clipped:!1,ver:0},t.addEventListener("contextlost",()=>{this.lost=!0,this.lostListeners.forEach(s=>s())}),t.addEventListener("contextrestored",()=>{this.lost=!1,this.tinted.clear(),this.tintedN=0,this.dropNines(),this.restoredListeners.forEach(s=>s())})}resize(t,e){this.canvas.width!==t&&(this.canvas.width=t),this.canvas.height!==e&&(this.canvas.height=e)}createTexture(t){return{id:Ys(),width:t.width,height:t.height,source:t}}updateTexture(t,e,s=0,i=0){const n=e?s+e.width:1/0,r=e?i+e.height:1/0;for(const a of this.nines.values()){const l=a.key;l[0]===t.id&&l[1]<n&&l[1]+l[3]>s&&l[2]<r&&l[2]+l[4]>i&&this.dropNine(a)}for(const[a,l]of this.tinted){const h=l.filter(o=>o.id!==t.id);this.tintedN-=l.length-h.length,h.length?this.tinted.set(a,h):this.tinted.delete(a)}}destroyTexture(t){this.updateTexture(t)}begin(t,e,s){this.resetLayers(s),this.fxr?.tick(),this.frame++,this.quads=0,this.top=this.base,this.ctx=this.base.ctx;const i=this.ctx;this.base.clipped&&i.restore(),this.base.clipped=!1,this.base.ver=this.clipVer,i.setTransform(1,0,0,1,0,0),i.globalAlpha=1,i.globalCompositeOperation="source-over",i.clearRect(0,0,this.canvas.width,this.canvas.height),e>0&&(i.fillStyle=Oe(t,e),i.fillRect(0,0,this.canvas.width,this.canvas.height))}quad(t,e,s,i,n,r,a,l){V[0]=i,V[1]=n,V[2]=a,this.quadQ(t,e,s,r,l)}quadQ(t,e,s,i,n){e.w<=0||e.h<=0||(i===16777215?this.blit(t.source,e.x,e.y,e.w,e.h,s,n):this.blit(this.tint(t,e,i),0,0,e.w,e.h,s,n))}blit(t,e,s,i,n,r,a){const l=V[0],h=V[1],o=V[2];if(o<=0||this.mute)return;this.sync();const c=this.ctx,u=this.scale;if(this.real){const f=r[0]*l,y=r[1]*l,p=r[2]*h,x=r[3]*h;this.grow(r[4]+Math.min(0,f,p,f+p),r[5]+Math.min(0,y,x,y+x),r[4]+Math.max(0,f,p,f+p),r[5]+Math.max(0,y,x,y+x))}c.setTransform(r[0]*u,r[1]*u,r[2]*u,r[3]*u,r[4]*u,r[5]*u),c.globalAlpha=Math.min(o,1),a==="add"&&(c.globalCompositeOperation="lighter"),c.drawImage(t,e,s,i,n,0,0,l,h),a==="add"&&(c.globalCompositeOperation="source-over"),this.quads++}nineQ(t,e,s,i,n,r,a){var l,h;const o=s[8]+s[9],c=i[8]+i[9],u=Math.ceil(o*Math.hypot(n[0],n[1])*this.scale-1e-6),f=Math.ceil(c*Math.hypot(n[2],n[3])*this.scale-1e-6);if(n[1]===0&&n[2]===0||u>4096||f>4096)return!1;if(!(u>0&&f>0&&V[2]>0)||this.mute)return!0;let y=this.kept(t,e,s,i,u,f,r);const p=(y??(y=(l=this.scratch)[h=13*Math.ceil(Math.log2(u))+Math.ceil(Math.log2(f))]??(l[h]=document.createElement("canvas").getContext("2d")))).canvas;if(p.width<u&&(p.width=u),p.height<f&&(p.height=f),!this.hit){y.clearRect(0,0,u+2,f+2);for(let x=0;x<12;x+=4){const m=Math.round(i[x]*f/c),g=Math.round((i[x]+i[x+1])*f/c);for(let k=0;k<12;k+=4){const E=Math.round(s[k]*u/o),w=Math.round((s[k]+s[k+1])*u/o);bt.x=e.x+s[k+2],bt.y=e.y+i[x+2],bt.w=s[k+3],bt.h=i[x+3],!(w<=E||g<=m||bt.w<=0||bt.h<=0)&&(r===16777215?y.drawImage(t.source,bt.x,bt.y,bt.w,bt.h,E,m,w-E,g-m):y.drawImage(this.tint(t,bt,r),0,0,bt.w,bt.h,E,m,w-E,g-m))}}}return V[0]=o,V[1]=c,this.blit(p,0,0,u,f,n,a),!0}kept(t,e,s,i,n,r,a){gt[0]=t.id,gt[1]=e.x,gt[2]=e.y,gt[3]=e.w,gt[4]=e.h,gt[5]=n,gt[6]=r,gt[7]=a,gt.set(s,8),gt.set(i,20);const l=te(gt),h=this.nines.get(l);if(this.hit=!1,h)return Ge(h.key,gt)?(h.used=this.frame,this.hit=!0,h.ctx):null;const o=this.missed,c=o.get(l);o.size>4096&&o.clear(),o.set(l,this.frame);const u=n*r;if(c!==this.frame-1||u>wn)return null;let f;for(;this.ninePx+u>wn;){let x;for(const k of this.nines.values())k.used<this.frame-1&&!(x&&x.used<=k.used)&&(x=k);if(!x)return null;const m=x.ctx.canvas,g=!f&&m.width>=n&&m.height>=r&&m.width*m.height<=2*u;this.dropNine(x,g),g&&(f=x.ctx)}const y=f??document.createElement("canvas").getContext("2d"),p=y.canvas;return f||(p.width=n,p.height=r),this.ninePx+=p.width*p.height,this.nines.set(l,{key:hs(gt),ctx:y,used:this.frame}),y}dropNine(t,e=!1){this.nines.delete(te(t.key));const s=t.ctx.canvas;this.ninePx-=s.width*s.height,e||(s.width=0)}dropNines(){for(const t of this.nines.values())this.dropNine(t)}tint(t,e,s){const i=Jt(s,Jt(e.h,Jt(e.w,Jt(e.y,Jt(e.x,Jt(t.id))))));let n=this.tinted.get(i);if(n)for(let l=0;l<n.length;l++){const h=n[l];if(h.id===t.id&&h.x===e.x&&h.y===e.y&&h.w===e.w&&h.h===e.h&&h.color===s)return h.canvas}this.tintedN>=Za&&(this.tinted.clear(),this.tintedN=0,n=void 0);const r=document.createElement("canvas");r.width=Math.ceil(e.w),r.height=Math.ceil(e.h);const a=r.getContext("2d");return a.drawImage(t.source,e.x,e.y,e.w,e.h,0,0,e.w,e.h),a.globalCompositeOperation="multiply",a.fillStyle=Oe(s),a.fillRect(0,0,e.w,e.h),a.globalCompositeOperation="destination-in",a.drawImage(t.source,e.x,e.y,e.w,e.h,0,0,e.w,e.h),n||this.tinted.set(i,n=[]),n.push({id:t.id,x:e.x,y:e.y,w:e.w,h:e.h,color:s,canvas:r}),this.tintedN++,r}paint(t,e){this.sync();const s=this.ctx,i=this.scale;return s.setTransform(i,0,0,i,0,0),s.globalAlpha=Math.min(e,1),Oe(t)}ellipse(t,e,s,i,n,r,a){if(a<=0||s<=0||i<=0||this.mute)return;const l=Math.max(s,i);this.grow(t-l,e-l,t+l,e+l);const h=this.ctx;h.fillStyle=this.paint(r,a),h.beginPath(),h.ellipse(t,e,s,i,n,0,Math.PI*2),h.fill(),this.quads++}trace(t,e,s=0){if(this.real)for(let n=0;n<e;n++)this.grow(t[n*2]-s,t[n*2+1]-s,t[n*2]+s,t[n*2+1]+s);const i=this.ctx;i.beginPath(),i.moveTo(t[0],t[1]);for(let n=1;n<e;n++)i.lineTo(t[n*2],t[n*2+1])}polygon(t,e,s,i){if(i<=0||e<3||this.mute)return;const n=this.ctx;n.fillStyle=this.paint(s,i),this.trace(t,e),n.closePath(),n.fill(),this.quads++}stroke(t,e,s,i,n,r){if(n<=0||s<=0||e<1||this.mute)return;const a=this.ctx;a.strokeStyle=this.paint(i,n),a.lineWidth=s,a.lineCap="round",a.lineJoin="round",this.trace(t,e,s/2),e===1&&a.lineTo(t[0],t[1]),r&&a.closePath(),a.stroke(),this.quads++}sync(){const t=this.top;if(t.ver===this.clipVer)return;const e=t.ctx;t.clipped&&e.restore(),t.clipped=this.cOn,t.ver=this.clipVer,this.cOn&&(e.save(),e.setTransform(1,0,0,1,0,0),e.beginPath(),e.rect(this.px0,this.py0,this.px1-this.px0,this.py1-this.py0),e.clip())}pushLayer(){const t=this.canvas.width,e=this.canvas.height;let s=this.layers[this.real];if(!s||s.ctx.canvas.width!==t||s.ctx.canvas.height!==e){const n=document.createElement("canvas");n.width=t,n.height=e;const r=n.getContext("2d");if(!r)return!1;s=this.layers[this.real]={ctx:r,clipped:!1,ver:-1}}const i=s.ctx;return s.clipped&&i.restore(),s.clipped=!1,s.ver=-1,i.setTransform(1,0,0,1,0,0),i.globalAlpha=1,i.globalCompositeOperation="source-over",i.clearRect(0,0,t,e),this.top=s,this.ctx=i,!0}popLayer(){return this.top=this.real>0?this.layers[this.real-1]:this.base,this.ctx=this.top.ctx,this.layers[this.real].ctx.canvas}composite(t,e,s,i){let n=t,r="none";const a=i&&Ut.c2d?this.fxr??(this.fxr=Ut.c2d(this)):null;a&&(n=a.chain(t,i),r=a.css),this.sync();const l=this.ctx,h=this.rx0,o=this.ry0,c=this.rx1-h,u=this.ry1-o;l.setTransform(1,0,0,1,0,0),l.globalAlpha=Math.min(s,1),l.globalCompositeOperation=e?"destination-in":"source-over",r!=="none"&&(l.filter=r),l.drawImage(n,h,o,c,u,h,o,c,u),r!=="none"&&(l.filter="none"),l.globalCompositeOperation="source-over",this.quads++}end(){this.closeLayers();const t=this.stats;return t.drawCalls=t.quads=this.quads,t.filtersSkipped=this.skipped,t}onLost(t){this.lostListeners.push(t)}onRestored(t){this.restoredListeners.push(t)}destroy(){this.tinted.clear(),this.dropNines(),this.layers=[],this.scratch=[],this.fxr?.destroy(),this.fxr=null}},Xe=14,_e=6,vn=8192,eo=class{constructor(t,e,s=vn){d(this,"instanced",t),d(this,"slots",e),d(this,"capacity",s),d(this,"f32"),d(this,"u32"),d(this,"quads",0),d(this,"textures"),d(this,"bound",0),this.textures=new Array(e).fill(null);const i=s*(t?Xe:_e*4),n=new ArrayBuffer(i*4);this.f32=new Float32Array(n),this.u32=new Uint32Array(n)}slot(t){const e=this.textures;for(let s=0;s<this.bound;s++)if(e[s]===t)return s;return this.bound>=this.slots?-1:(e[this.bound]=t,this.bound++)}has(t){for(let e=0;e<this.bound;e++)if(this.textures[e]===t)return!0;return!1}get full(){return this.quads>=this.capacity}get words(){return this.quads*(this.instanced?Xe:_e*4)}reset(){this.quads=0;for(let t=0;t<this.bound;t++)this.textures[t]=null;this.bound=0}push(t,e,s,i,n,r,a,l,h,o,c,u,f,y){const p=this.f32;if(this.instanced){let x=this.quads*Xe;p[x++]=t,p[x++]=e,p[x++]=s,p[x++]=i,p[x++]=n,p[x++]=r,p[x++]=a,p[x++]=l,p[x++]=h,p[x++]=o,p[x++]=c,p[x++]=u,this.u32[x++]=f,p[x]=y}else{const x=this.quads*_e*4;this.vertex(x,t,e,h,o,f,y),this.vertex(x+6,s,i,c,o,f,y),this.vertex(x+12,n,r,c,u,f,y),this.vertex(x+18,a,l,h,u,f,y)}this.quads++}pushQ(t,e){const s=this.f32;if(this.instanced){const i=this.quads*Xe;for(let n=0;n<12;n++)s[i+n]=t[n];this.u32[i+12]=t[12],s[i+13]=e}else{let i=this.quads*_e*4;const n=t[12];for(let r=0;r<4;r++,i+=_e)s[i]=t[r*2],s[i+1]=t[r*2+1],s[i+2]=r===1||r===2?t[10]:t[8],s[i+3]=r>=2?t[11]:t[9],this.u32[i+4]=n,s[i+5]=e}this.quads++}vertex(t,e,s,i,n,r,a){const l=this.f32;l[t]=e,l[t+1]=s,l[t+2]=i,l[t+3]=n,this.u32[t+4]=r,l[t+5]=a}};function so(t){const e=new Uint16Array(t*6);for(let s=0,i=0,n=0;s<t;s++,i+=6,n+=4)e[i]=n,e[i+1]=n+1,e[i+2]=n+2,e[i+3]=n,e[i+4]=n+2,e[i+5]=n+3;return e}var kt={M:0,L:1,Q:2,C:3,Z:4},Mn=[2,2,4,6,0],io={M:0,L:1,Q:2,C:3,Z:4};function ei(t,e){if(t.length>=e)return t;const s=new Float64Array(Math.max(e,t.length*2,16));return s.set(t),s}var fs=new Map;function no(t){if(typeof t!="string")return t;let e=fs.get(t);if(e)return e;e=[];const s=t.match(/[MLQCZ]|-?\d*\.?\d+(?:e-?\d+)?/gi)??[];let i=-1;for(let n=0;n<s.length;){const r=s[n],a=io[r.toUpperCase()];if(a!==void 0){i=a,n++,a===kt.Z&&e.push(kt.Z);continue}if(i<0||i===kt.Z){n++;continue}const l=Mn[i];e.push(i);for(let h=0;h<l;h++)e.push(Number(s[n+h]??0));n+=l,i===kt.M&&(i=kt.L)}return fs.size>256&&fs.clear(),fs.set(t,e),e}var ee={subs:[],count:0},si=null,se=null;function us(t,e){let s=se;s||(s=ee.subs[ee.count]??null,s||ee.subs.push(s={pts:new Float64Array(64),n:0,closed:!1}),s.n=0,s.closed=!1,ee.count++,se=s);const i=s.n*2;i+2>s.pts.length&&(s.pts=ei(s.pts,i+2));const n=si;n?(s.pts[i]=n[0]*t+n[2]*e+n[4],s.pts[i+1]=n[1]*t+n[3]*e+n[5]):(s.pts[i]=t,s.pts[i+1]=e),s.n++}function ii(t,e=null,s=1,i=6){const n=no(t);ee.count=0,se=null,si=e;let r=0,a=0,l=0,h=0;const o=s/i;for(let c=0;c<n.length;){const u=n[c++],f=n;if(u===kt.M)se=null,r=l=f[c],a=h=f[c+1],us(r,a);else if(u===kt.L)r=f[c],a=f[c+1],us(r,a);else if(u===kt.Q){const y=f[c],p=f[c+1],x=f[c+2],m=f[c+3],g=En(($t(y-r,p-a)+$t(x-y,m-p))*o);for(let k=1;k<=g;k++){const E=k/g,w=1-E;us(w*w*r+2*w*E*y+E*E*x,w*w*a+2*w*E*p+E*E*m)}r=x,a=m}else if(u===kt.C){const y=f[c],p=f[c+1],x=f[c+2],m=f[c+3],g=f[c+4],k=f[c+5],E=En(($t(y-r,p-a)+$t(x-y,m-p)+$t(g-x,k-m))*o);for(let w=1;w<=E;w++){const A=w/E,C=1-A,R=C*C*C,O=3*C*C*A,P=3*C*A*A,I=A*A*A;us(R*r+O*y+P*x+I*g,R*a+O*p+P*m+I*k)}r=g,a=k}else if(u===kt.Z){se&&(se.closed=!0),se=null,r=l,a=h;continue}else break;c+=Mn[u]}se=null,si=null;for(let c=0;c<ee.count;c++){const u=ee.subs[c],f=u.n*2;u.closed&&u.n>=2&&Math.abs(u.pts[0]-u.pts[f-2])<1e-6&&Math.abs(u.pts[1]-u.pts[f-1])<1e-6&&u.n--}return ee}var $t=(t,e)=>Math.sqrt(t*t+e*e),En=t=>Math.min(Math.max(Math.ceil(t),2),24);function ro(t,e){let s=0;for(let i=0,n=e-1;i<e;n=i++)s+=(t[n*2]-t[i*2])*(t[n*2+1]+t[i*2+1]);return s}var ds=new Int32Array(64),ps=(t,e,s,i,n)=>((t[i*2]-t[s*2])*(t[n*2+1]-t[s*2+1])-(t[i*2+1]-t[s*2+1])*(t[n*2]-t[s*2]))*e;function ao(t,e,s){if(e<3)return 0;ds.length<e&&(ds=new Int32Array(Math.max(e,ds.length*2)));const i=ds;let n=e,r=0;for(let o=0;o<e;o++)i[o]=o;const a=ro(t,e)>0?1:-1;let l=e*e+8,h=0;for(;n>3&&l-- >0;){const o=i[(h+n-1)%n],c=i[h%n],u=i[(h+1)%n];let f=ps(t,a,o,c,u)>0;if(f)for(let y=0;y<n;y++){const p=i[y];if(!(p===o||p===c||p===u)&&ps(t,a,o,c,p)>=0&&ps(t,a,c,u,p)>=0&&ps(t,a,u,o,p)>=0){f=!1;break}}f?(s[r++]=o,s[r++]=c,s[r++]=u,i.copyWithin(h%n,h%n+1,n),n--,h=Math.max(h-1,0)):h=(h+1)%n}if(n===3)s[r++]=i[0],s[r++]=i[1],s[r++]=i[2];else if(n>3)for(let o=1;o+1<n;o++)s[r++]=i[0],s[r++]=i[o],s[r++]=i[o+1];return r}var oo=.85,ys=new Float64Array(64),An=new Float64Array(64),_n=new Float64Array(64),Sn=new Float64Array(64),Tn=new Float64Array(64),Cn=new Float64Array(64),Rn=new Uint8Array(64),ms=new Float64Array(8);function lo(t,e,s,i,n,r){const a=ms;if(ys.length<e){const m=Math.max(e,ys.length*2);ys=new Float64Array(m),An=new Float64Array(m),_n=new Float64Array(m),Sn=new Float64Array(m),Tn=new Float64Array(m),Cn=new Float64Array(m),Rn=new Uint8Array(m)}const l=ys,h=An;let o=0;for(let m=0;m<e;m++){const g=t[m*2],k=t[m*2+1];!Number.isFinite(g)||!Number.isFinite(k)||o&&Math.abs(l[o-1]-g)<.001&&Math.abs(h[o-1]-k)<.001||(l[o]=g,h[o]=k,o++)}if(i&&o>2&&Math.abs(l[0]-l[o-1])<.001&&Math.abs(h[0]-h[o-1])<.001&&o--,o===0)return;if(o===1)return a[0]=l[0],a[1]=h[0],r();const c=i?o:o-1,u=_n,f=Sn;for(let m=0;m<c;m++){const g=(m+1)%o,k=l[g]-l[m],E=h[g]-h[m],w=$t(k,E)||1;u[m]=-E/w,f[m]=k/w}const y=Tn,p=Cn,x=Rn;for(let m=0;m<o;m++){const g=i?(m-1+c)%c:m-1,k=m<c?m:-1;if(x[m]=1,g<0||k<0||u[g]*u[k]+f[g]*f[k]<oo)continue;let w=u[g]+u[k],A=f[g]+f[k];const C=$t(w,A)||1;w/=C,A/=C;const R=s/Math.max(w*u[k]+A*f[k],.5);y[m]=w*R,p[m]=A*R,x[m]=0}for(let m=0;m<c;m++){const g=(m+1)%o,k=x[m]?u[m]*s:y[m],E=x[m]?f[m]*s:p[m],w=x[g]?u[m]*s:y[g],A=x[g]?f[m]*s:p[g];a[0]=l[m]+k,a[1]=h[m]+E,a[2]=l[g]+w,a[3]=h[g]+A,a[4]=l[g]-w,a[5]=h[g]-A,a[6]=l[m]-k,a[7]=h[m]-E,n()}for(let m=0;m<o;m++)x[m]&&(a[0]=l[m],a[1]=h[m],r())}function Fn(t,e){let s=0,i=1/0;for(let n=0;n<e.length;n++){const r=Math.abs(Math.log(Math.max(t,.5)/e[n]));r<i&&(i=r,s=n)}return s}var At=256,ni=[{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}],ri=[4,8,16,32,64,128].map((t,e)=>({x:e*4,y:128,w:4,h:t,r:t/2-1})),ie={x:248,y:248,w:8,h:8},ho=ni.map(t=>t.r*2),co=ri.map(t=>t.r*2),Pn=(t,e)=>Math.min(Math.max(t+.5-e,0),1);function fo(){const t=new Uint8ClampedArray(At*At*4),e=(s,i,n)=>{const r=(i*At+s)*4;t[r]=t[r+1]=t[r+2]=255,t[r+3]=Math.round(n*255)};for(const s of ni){const i=s.w/2;for(let n=0;n<s.h;n++)for(let r=0;r<s.w;r++)e(s.x+r,s.y+n,Pn(s.r,Math.hypot(r+.5-i,n+.5-i)))}for(const s of ri){const i=s.h/2;for(let n=0;n<s.h;n++)for(let r=0;r<s.w;r++)e(s.x+r,s.y+n,Pn(s.r,Math.abs(n+.5-i)))}for(let s=0;s<ie.h;s++)for(let i=0;i<ie.w;i++)e(ie.x+i,ie.y+s,1);return t}function uo(){const t=document.createElement("canvas");return t.width=t.height=At,t.getContext("2d").putImageData(new ImageData(fo(),At,At),0,0),t}var Ln=8,ai=`
2
2
  #ifdef GL_FRAGMENT_PRECISION_HIGH
3
3
  precision highp float;
4
4
  #else
5
5
  precision mediump float;
6
6
  #endif
7
- `,Ja=t=>`${si}
7
+ `,po=t=>`${ai}
8
8
  uniform sampler2D uTex[${t}];
9
9
  varying vec2 vUv;
10
10
  varying vec4 vColor;
@@ -14,7 +14,7 @@ void main() {
14
14
  ${Array.from({length:t},(e,s)=>s===t-1?`c = texture2D(uTex[${s}], vUv);`:`if (vSlot < ${s}.5) c = texture2D(uTex[${s}], vUv); else `).join(`
15
15
  `)}
16
16
  gl_FragColor = c * vColor;
17
- }`,to=`
17
+ }`,yo=`
18
18
  attribute vec2 aPos;
19
19
  attribute vec2 aUv;
20
20
  attribute vec4 aColor;
@@ -28,7 +28,7 @@ void main() {
28
28
  vColor = aColor;
29
29
  vSlot = aSlot;
30
30
  gl_Position = vec4(aPos * uScale + vec2(-1.0, 1.0), 0.0, 1.0);
31
- }`,eo=`
31
+ }`,mo=`
32
32
  attribute vec4 aCorner;
33
33
  attribute vec4 aP01;
34
34
  attribute vec4 aP23;
@@ -45,7 +45,7 @@ void main() {
45
45
  vColor = aColor;
46
46
  vSlot = aSlot;
47
47
  gl_Position = vec4(p * uScale + vec2(-1.0, 1.0), 0.0, 1.0);
48
- }`,so={alpha:!0,premultipliedAlpha:!0,antialias:!1,depth:!1,stencil:!1,preserveDrawingBuffer:!1,powerPreference:"high-performance"},io=["aCorner","aP01","aP23","aUvRect","aColor","aSlot"],no=["aPos","aUv","aColor","aSlot"];function ro(t,e,s={}){const i={...so,failIfMajorPerformanceCaveat:s.failIfMajorPerformanceCaveat!==!1},n=e===2?t.getContext("webgl2",i):t.getContext("webgl",i)??t.getContext("experimental-webgl",i);if(!n||n.isContextLost())return null;try{return new ao(t,n,e,s)}catch(r){return console.warn("[engine] WebGL setup failed:",r),n.getExtension("WEBGL_lose_context")?.loseContext(),null}}var ao=class extends pn{constructor(t,e,s,i){super(),d(this,"canvas",t),d(this,"gl",e),d(this,"opts",i),d(this,"kind"),d(this,"maxTextureSize"),d(this,"support",{filters:!0,shaders:!0}),d(this,"features",{}),d(this,"info",{}),d(this,"lost",!1),d(this,"main"),d(this,"cur"),d(this,"unit",-1),d(this,"onUnit",new Array(Tn).fill(void 0)),d(this,"fbNow"),d(this,"mapped",!0),d(this,"calls",{useProgram:0,bindTexture:0,activeTexture:0,bindFramebuffer:0}),d(this,"vsrc",""),d(this,"attrs",[]),d(this,"fxr",null),d(this,"batch"),d(this,"dynamic"),d(this,"staticBuf",null),d(this,"index"),d(this,"vao",null),d(this,"inst",null),d(this,"vaoApi",null),d(this,"uScale",null),d(this,"textures",new Map),d(this,"kit"),d(this,"stats",{drawCalls:0,quads:0,filtersSkipped:0}),d(this,"lostListeners",[]),d(this,"restoredListeners",[]),d(this,"tris",new Int32Array(192)),d(this,"sU",0),d(this,"sV0",0),d(this,"sV1",0),d(this,"sColor",0),d(this,"sPacked",0),d(this,"sAlpha",0),d(this,"sHw",0),d(this,"strokeSeg",()=>{const n=this.q;n.set(us),n[8]=n[10]=this.sU,n[9]=this.sV0,n[11]=this.sV1,n[12]=this.sPacked,this.put(this.kit)}),d(this,"strokeDisc",()=>this.ellipse(us[0],us[1],this.sHw,this.sHw,0,this.sColor,this.sAlpha)),d(this,"q",new Float64Array(13)),d(this,"layers",[]),d(this,"layerTex",new Map),d(this,"bScis",!1),d(this,"bx0",0),d(this,"by0",0),d(this,"bx1",0),d(this,"by1",0),d(this,"onContextLost",n=>{n.preventDefault(),this.lost=!0;for(const r of this.lostListeners)r()}),d(this,"onContextRestored",()=>{try{this.layers=[],this.layerTex.clear(),this.fxr=null,this.resetLayers(this.scale),this.setup();for(const n of this.textures.keys())this.textures.set(n,this.upload(n.source));this.lost=!1;for(const n of this.restoredListeners)n()}catch(n){console.warn("[engine] WebGL restore failed:",n)}}),d(this,"views",new Map),this.kind=s===2?"webgl2":"webgl1",this.maxTextureSize=e.getParameter(e.MAX_TEXTURE_SIZE),this.setup(),this.kit=this.createTexture(Za()),Gt.live=this,t.addEventListener("webglcontextlost",this.onContextLost,!1),t.addEventListener("webglcontextrestored",this.onContextRestored,!1)}setup(){const t=this.gl,e=this.kind==="webgl2"?t:null;if(this.inst=null,this.opts.instancing!==!1)if(e)this.inst={divisor:(o,f)=>e.vertexAttribDivisor(o,f),draw:(o,f)=>e.drawElementsInstanced(t.TRIANGLES,o,t.UNSIGNED_SHORT,0,f)};else{const o=t.getExtension("ANGLE_instanced_arrays");o&&(this.inst={divisor:(f,u)=>o.vertexAttribDivisorANGLE(f,u),draw:(f,u)=>o.drawElementsInstancedANGLE(t.TRIANGLES,f,t.UNSIGNED_SHORT,0,u)})}if(this.vaoApi=null,this.opts.vao!==!1)if(e)this.vaoApi={create:()=>e.createVertexArray(),bind:o=>e.bindVertexArray(o),remove:o=>e.deleteVertexArray(o)};else{const o=t.getExtension("OES_vertex_array_object");o&&(this.vaoApi={create:()=>o.createVertexArrayOES(),bind:f=>o.bindVertexArrayOES(f),remove:f=>o.deleteVertexArrayOES(f)})}const s=t.getParameter(t.MAX_TEXTURE_IMAGE_UNITS),i=Math.max(1,Math.min(Tn,s)),n=this.inst!==null;this.vsrc=n?eo:to,this.attrs=n?io:no,this.main=this.cur=this.build(Ja(i));const r=this.main.p;t.useProgram(r),this.calls.useProgram++,this.unit=-1,this.onUnit.fill(void 0),this.fbNow=void 0,this.uScale=this.main.uScale,t.uniform1iv(t.getUniformLocation(r,"uTex"),Int32Array.from({length:i},(o,f)=>f)),this.batch=new Ga(n,i),this.vaoApi&&(this.vao=this.vaoApi.create(),this.vaoApi.bind(this.vao)),this.dynamic=t.createBuffer(),t.bindBuffer(t.ARRAY_BUFFER,this.dynamic),t.bufferData(t.ARRAY_BUFFER,this.batch.f32.byteLength,t.DYNAMIC_DRAW),this.index=t.createBuffer(),t.bindBuffer(t.ELEMENT_ARRAY_BUFFER,this.index),t.bufferData(t.ELEMENT_ARRAY_BUFFER,Ha(n?1:mn),t.STATIC_DRAW);const a=o=>t.getAttribLocation(r,o),l=(o,f,u,c,y,p,x)=>{const m=a(o);m<0||(t.enableVertexAttribArray(m),t.vertexAttribPointer(m,f,u,c,y,p),this.inst&&this.inst.divisor(m,x))};if(n){const o=Ge*4;l("aP01",4,t.FLOAT,!1,o,0,1),l("aP23",4,t.FLOAT,!1,o,16,1),l("aUvRect",4,t.FLOAT,!1,o,32,1),l("aColor",4,t.UNSIGNED_BYTE,!0,o,48,1),l("aSlot",1,t.FLOAT,!1,o,52,1),this.staticBuf=t.createBuffer(),t.bindBuffer(t.ARRAY_BUFFER,this.staticBuf),t.bufferData(t.ARRAY_BUFFER,Float32Array.of(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1),t.STATIC_DRAW),l("aCorner",4,t.FLOAT,!1,16,0,0),t.bindBuffer(t.ARRAY_BUFFER,this.dynamic)}else{const o=Ee*4;l("aPos",2,t.FLOAT,!1,o,0,0),l("aUv",2,t.FLOAT,!1,o,8,0),l("aColor",4,t.UNSIGNED_BYTE,!0,o,16,0),l("aSlot",1,t.FLOAT,!1,o,20,0)}t.enable(t.BLEND),t.blendFunc(t.ONE,t.ONE_MINUS_SRC_ALPHA),t.disable(t.DEPTH_TEST),t.disable(t.CULL_FACE),t.pixelStorei(t.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!0);const h=t.getExtension("WEBGL_debug_renderer_info");this.info={version:t.getParameter(t.VERSION),renderer:h?t.getParameter(h.UNMASKED_RENDERER_WEBGL):t.getParameter(t.RENDERER),vendor:h?t.getParameter(h.UNMASKED_VENDOR_WEBGL):t.getParameter(t.VENDOR)},this.features={instancing:n,vao:this.vaoApi!==null,textureSlots:i,maxTextureSize:this.maxTextureSize}}upload(t){const e=this.gl,s=e.createTexture();return this.bindTex(s),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,e.RGBA,e.UNSIGNED_BYTE,t),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),s}resize(t,e){this.canvas.width!==t&&(this.canvas.width=t),this.canvas.height!==e&&(this.canvas.height=e)}createTexture(t){const e={id:Xs(),width:t.width,height:t.height,source:t};return this.textures.set(e,this.lost?null:this.upload(t)),e}updateTexture(t,e,s=0,i=0){if(this.lost)return;this.batch.has(t)&&this.flush();const n=this.gl,r=this.textures.get(t);r&&(this.bindTex(r),!e||e===t.source&&s===0&&i===0?n.texImage2D(n.TEXTURE_2D,0,n.RGBA,n.RGBA,n.UNSIGNED_BYTE,t.source):n.texSubImage2D(n.TEXTURE_2D,0,s,i,n.RGBA,n.UNSIGNED_BYTE,e))}destroyTexture(t){this.batch.has(t)&&this.flush();const e=this.textures.get(t);e&&!this.lost&&this.deleteTex(e),this.textures.delete(t)}begin(t,e,s){if(this.stats.drawCalls=this.stats.quads=this.stats.filtersSkipped=0,this.batch.reset(),this.resetLayers(s),this.bScis=!1,this.lost)return;const i=this.gl;i.disable(i.SCISSOR_TEST),this.bindFb(null),i.viewport(0,0,this.canvas.width,this.canvas.height);const n=e;i.clearColor((t>>16&255)/255*n,(t>>8&255)/255*n,(t&255)/255*n,n),i.clear(i.COLOR_BUFFER_BIT),this.use(this.main),i.uniform2f(this.uScale,2*s/this.canvas.width,-2*s/this.canvas.height),this.mapped=!0}build(t){const e=this.gl,s=Sn(e,e.VERTEX_SHADER,this.vsrc);let i;try{i=Sn(e,e.FRAGMENT_SHADER,t)}catch(r){throw e.deleteShader(s),r}const n=e.createProgram();if(e.attachShader(n,s),e.attachShader(n,i),this.attrs.forEach((r,a)=>e.bindAttribLocation(n,a,r)),e.linkProgram(n),e.deleteShader(s),e.deleteShader(i),!e.getProgramParameter(n,e.LINK_STATUS)){const r=e.getProgramInfoLog(n)??"?";throw e.deleteProgram(n),new Error(`link: ${r}`)}return{p:n,uScale:e.getUniformLocation(n,"uScale"),locs:new Map}}u(t,e){let s=t.locs.get(e);return s===void 0&&t.locs.set(e,s=this.gl.getUniformLocation(t.p,e)),s}use(t){this.cur!==t&&(this.cur=t,this.gl.useProgram(t.p),this.calls.useProgram++)}bindTex(t,e=this.unit<0?0:this.unit){const s=this.gl;this.onUnit[e]!==t&&(this.unit!==e&&(s.activeTexture(s.TEXTURE0+e),this.calls.activeTexture++,this.unit=e),s.bindTexture(s.TEXTURE_2D,t),this.calls.bindTexture++,this.onUnit[e]=t)}deleteTex(t){this.gl.deleteTexture(t);for(let e=0;e<this.onUnit.length;e++)this.onUnit[e]===t&&(this.onUnit[e]=null)}bindFb(t){if(t)for(let s=0;s<this.onUnit.length;s++)this.onUnit[s]===t.gl&&this.bindTex(null,s);const e=t?t.fb:null;this.fbNow!==e&&(this.gl.bindFramebuffer(this.gl.FRAMEBUFFER,e),this.calls.bindFramebuffer++,this.fbNow=e)}slotOf(t){this.batch.full&&this.flush();let e=this.batch.slot(t);return e<0&&(this.flush(),e=this.batch.slot(t)),e}quad(t,e,s,i,n,r,a,l){j[0]=i,j[1]=n,j[2]=a,this.quadQ(t,e,s,r,l)}quadQ(t,e,s,i,n){const r=j[2];if(this.lost||r<=0)return;const a=this.q,l=j[0],h=j[1],o=s[4],f=s[5],u=s[0]*l,c=s[1]*l,y=s[2]*h,p=s[3]*h;a[0]=o,a[1]=f,a[2]=u+o,a[3]=c+f,a[4]=u+y+o,a[5]=c+p+f,a[6]=y+o,a[7]=p+f;const x=1/t.width,m=1/t.height;a[8]=e.x*x,a[9]=e.y*m,a[10]=(e.x+e.w)*x,a[11]=(e.y+e.h)*m,a[12]=ge(i,r,n==="add"),this.put(t)}put(t){if(this.mute)return;const e=this.q;let s=!1;const i=Math.min(e[0],e[2],e[4],e[6]),n=Math.max(e[0],e[2],e[4],e[6]),r=Math.min(e[1],e[3],e[5],e[7]),a=Math.max(e[1],e[3],e[5],e[7]);if(this.cOn){if(this.px1<=this.px0||this.py1<=this.py0)return;const h=this.scale,o=this.px0/h,f=this.py0/h,u=this.px1/h,c=this.py1/h;if(n<=o||i>=u||a<=f||r>=c)return;if(i<o||n>u||r<f||a>c){const y=e[0],p=e[1],x=e[2],m=e[5];if(p===e[3]&&x===e[4]&&m===e[7]&&e[6]===y){if(y!==x){const g=Math.min(Math.max(y,o),u),k=Math.min(Math.max(x,o),u),E=e[8],w=(e[10]-E)/(x-y);e[10]=E+(k-y)*w,e[8]=E+(g-y)*w,e[0]=e[6]=g,e[2]=e[4]=k}if(p!==m){const g=Math.min(Math.max(p,f),c),k=Math.min(Math.max(m,f),c),E=e[9],w=(e[11]-E)/(m-p);e[11]=E+(k-p)*w,e[9]=E+(g-p)*w,e[1]=e[3]=g,e[5]=e[7]=k}}else s=!0}}const l=this.bx0===this.px0&&this.by0===this.py0&&this.bx1===this.px1&&this.by1===this.py1;if(s?(!this.bScis||!l)&&(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&&l)&&(this.flush(),this.bScis=!1),this.real){const h=this.gq;h[0]=i,h[1]=r,h[2]=n,h[3]=a,this.growQ()}this.batch.pushQ(e,this.slotOf(t))}ellipse(t,e,s,i,n,r,a){if(this.lost||a<=0||s<=0||i<=0)return;const l=ti[An(Math.max(s,i)*2*this.scale,ja)],h=l.w/2/l.r,o=s*h,f=i*h,u=Math.cos(n),c=Math.sin(n),y=u*o,p=c*o,x=-c*f,m=u*f,g=1/Tt,k=this.q;k[0]=t-y-x,k[1]=e-p-m,k[2]=t+y-x,k[3]=e+p-m,k[4]=t+y+x,k[5]=e+p+m,k[6]=t-y+x,k[7]=e-p+m,k[8]=l.x*g,k[9]=l.y*g,k[10]=(l.x+l.w)*g,k[11]=(l.y+l.h)*g,k[12]=ge(r,a),this.put(this.kit)}polygon(t,e,s,i){if(this.lost||i<=0||e<3)return;this.tris.length<e*3&&(this.tris=new Int32Array(Math.max(e*3,this.tris.length*2)));const n=this.tris,r=Wa(t,e,n),a=ge(s,i),l=(ee.x+ee.w/2)/Tt,h=(ee.y+ee.h/2)/Tt;for(let o=0;o<r;o+=3){const f=n[o]*2,u=n[o+1]*2,c=n[o+2]*2,y=this.q;y[0]=t[f],y[1]=t[f+1],y[2]=t[u],y[3]=t[u+1],y[4]=y[6]=t[c],y[5]=y[7]=t[c+1],y[8]=y[10]=l,y[9]=y[11]=h,y[12]=a,this.put(this.kit)}}stroke(t,e,s,i,n,r){if(this.lost||n<=0||s<=0||e<1)return;const a=ei[An(s*this.scale,Va)],l=s/2*(a.h/2/a.r);this.sPacked=ge(i,n),this.sColor=i,this.sAlpha=n,this.sU=(a.x+a.w/2)/Tt,this.sV0=a.y/Tt,this.sV1=(a.y+a.h)/Tt,this.sHw=s/2,Qa(t,e,l,r,this.strokeSeg,this.strokeDisc)}target(t,e,s,i){const n=this.gl,r=n.createTexture();this.bindTex(r),n.texImage2D(n.TEXTURE_2D,0,n.RGBA,t,e,0,n.RGBA,n.UNSIGNED_BYTE,null);const a=i?n.LINEAR:n.NEAREST;n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MIN_FILTER,a),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MAG_FILTER,a),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_S,n.CLAMP_TO_EDGE),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_T,n.CLAMP_TO_EDGE),this.bindTex(null);const l=n.createFramebuffer();n.bindFramebuffer(n.FRAMEBUFFER,l),n.framebufferTexture2D(n.FRAMEBUFFER,n.COLOR_ATTACHMENT0,n.TEXTURE_2D,r,0);const h=n.checkFramebufferStatus(n.FRAMEBUFFER)===n.FRAMEBUFFER_COMPLETE;if(this.fbNow=l,this.bindFb(this.parent()),!h)return this.deleteTex(r),n.deleteFramebuffer(l),null;const o={tex:{id:Xs(),width:t,height:e,source:this.canvas},gl:r,fb:l,w:t,h:e,f:s};return this.layerTex.set(o.tex,r),o}drop(t){this.batch.has(t.tex)&&this.flush(),this.deleteTex(t.gl),this.gl.deleteFramebuffer(t.fb),this.layerTex.delete(t.tex)}parent(){return this.real>0?this.layers[this.real-1]:null}layerAt(t){const e=this.canvas.width,s=this.canvas.height;let i=this.layers[t]??null;return i&&(i.w!==e||i.h!==s)&&(this.drop(i),i=this.layers[t]=null),i??(this.layers[t]=this.target(e,s,1,!1))}pushLayer(){if(this.lost)return!1;this.flush();const t=this.layerAt(this.real);if(!t)return!1;const e=this.gl;return this.bindFb(t),e.disable(e.SCISSOR_TEST),e.clearColor(0,0,0,0),e.clear(e.COLOR_BUFFER_BIT),!0}popLayer(){return this.flush(),this.bindFb(this.parent()),this.layers[this.real].tex}filters(){return this.lost||!Gt.gl?null:this.fxr??(this.fxr=Gt.gl(this))}composite(t,e,s,i){if(i&&this.filters()?.chain(t,s,i))return;const n=this.gl;e&&n.blendFunc(n.ZERO,n.SRC_ALPHA),this.final(this.main,t,1,s),e&&(this.flush(),n.blendFunc(n.ONE,n.ONE_MINUS_SRC_ALPHA))}final(t,e,s,i){const n=this.gl,r=this.canvas.width,a=this.canvas.height,l=this.scale;(t!==this.main||!this.mapped)&&(this.bindFb(this.parent()),n.viewport(0,0,r,a),this.use(t),n.uniform2f(t.uScale,2*l/r,-2*l/a),this.mapped=t===this.main);const h=this.rx0/l,o=this.ry0/l,f=this.rx1/l,u=this.ry1/l,c=1/(s*e.width),y=1/(s*e.height),p=this.q;p[0]=p[6]=h,p[1]=p[3]=o,p[2]=p[4]=f,p[5]=p[7]=u,p[8]=this.rx0*c,p[9]=1-this.ry0*y,p[10]=this.rx1*c,p[11]=1-this.ry1*y,p[12]=ge(16777215,i),this.put(e),t!==this.main&&this.flush()}remap(){const t=this.gl;this.bindFb(this.parent()),t.viewport(0,0,this.canvas.width,this.canvas.height),this.use(this.main),t.uniform2f(this.uScale,2*this.scale/this.canvas.width,-2*this.scale/this.canvas.height),this.mapped=!0}upload2(t){const e=this.gl,s=t.words;if(this.kind==="webgl2")return e.bufferSubData(e.ARRAY_BUFFER,0,t.f32,0,s);let i=this.views.get(s);i||(this.views.size>=256&&this.views.clear(),this.views.set(s,i=t.f32.subarray(0,s))),e.bufferSubData(e.ARRAY_BUFFER,0,i)}flush(){const t=this.batch;if(!t.quads||this.lost)return t.reset();const e=this.gl;this.bScis?(e.enable(e.SCISSOR_TEST),e.scissor(this.bx0,this.canvas.height-this.by1,this.bx1-this.bx0,this.by1-this.by0)):e.disable(e.SCISSOR_TEST),this.upload2(t);for(let s=0;s<t.bound;s++){const i=t.textures[s];this.bindTex(this.textures.get(i)??this.layerTex.get(i)??null,s)}this.inst?this.inst.draw(6,t.quads):e.drawElements(e.TRIANGLES,t.quads*6,e.UNSIGNED_SHORT,0),this.stats.drawCalls++,this.stats.quads+=t.quads,t.reset()}end(){return this.closeLayers(),this.flush(),this.stats.filtersSkipped=this.skipped,this.stats}onLost(t){this.lostListeners.push(t)}onRestored(t){this.restoredListeners.push(t)}destroy(){const t=this.gl;Gt.live===this&&(Gt.live=null),this.canvas.removeEventListener("webglcontextlost",this.onContextLost),this.canvas.removeEventListener("webglcontextrestored",this.onContextRestored);try{for(const e of this.textures.values())e&&t.deleteTexture(e);for(const e of this.layers)e&&(t.deleteTexture(e.gl),t.deleteFramebuffer(e.fb));this.fxr?.destroy(),this.fxr=null,t.deleteBuffer(this.dynamic),t.deleteBuffer(this.index),this.staticBuf&&t.deleteBuffer(this.staticBuf),this.vao&&this.vaoApi&&this.vaoApi.remove(this.vao),t.deleteProgram(this.main.p),t.getExtension("WEBGL_lose_context")?.loseContext()}catch{}this.textures.clear()}};function Sn(t,e,s){const i=t.createShader(e);if(t.shaderSource(i,s),t.compileShader(i),!t.getShaderParameter(i,t.COMPILE_STATUS)){const n=t.getShaderInfoLog(i)??"?";throw t.deleteShader(i),new Error(n)}return i}function Cn(t="auto"){switch(t){case"canvas2d":return["canvas2d"];case"webgl1":return["webgl1","canvas2d"];default:return["webgl2","webgl1","canvas2d"]}}function ii(t,e={}){let s=t;for(const i of Cn(e.renderer)){const n=i==="canvas2d"?Vs(s):ro(s,i==="webgl2"?2:1,e);if(n)return n;s=ni(s)}throw new Error("No renderer: this browser has neither WebGL nor Canvas 2D")}function ni(t){const e=t.cloneNode(!1);return t.parentNode?.replaceChild(e,t),e}function oo(t=typeof location<"u"?location.search:""){const e=new URLSearchParams(t).get("renderer");return e==="canvas"?"canvas2d":e==="webgl2"||e==="webgl1"||e==="canvas2d"||e==="webgl"||e==="auto"?e:void 0}var ri=class{constructor(t,e={}){d(this,"atlas",t),d(this,"tags",new Map),d(this,"count",0),d(this,"m",xe()),d(this,"measure",null),d(this,"height"),d(this,"font"),this.height=e.tagHeight??34,this.font=e.tagFont??"Nunito, sans-serif"}drop(){for(const t of this.tags.values())for(const e of t.values())for(const s of e.values())this.atlas.release(s);this.tags.clear(),this.count=0}get(t,e,s){let i=this.tags.get(t);i||this.tags.set(t,i=new Map);let n=i.get(e);n||i.set(e,n=new Map);const r=n.get(s);return r&&this.atlas.valid(r)?r:this.bake(t,e,s)}bake(t,e,s){const i=this.height,n=`700 ${Math.round(i*.65)}px ${this.font}`,r=this.measure??(this.measure=document.createElement("canvas").getContext("2d"));r.font=n;const a=Math.round(i*.4),l=Math.ceil(r.measureText(t).width)+a*2,h=this.atlas.bake((l+2)*s,(i+2)*s,u=>{u.scale(s,s),u.translate(1,1);const c=i/2;u.beginPath(),u.moveTo(c,0),u.lineTo(l-c,0),u.arc(l-c,c,c,-Math.PI/2,Math.PI/2),u.lineTo(c,i),u.arc(c,c,c,Math.PI/2,Math.PI*3/2),u.closePath(),u.fillStyle=e,u.fill(),u.fillStyle="#fff",u.font=n,u.textAlign="center",u.textBaseline="middle",u.fillText(t,l/2,i/2+1)},s,1,1,1);++this.count>64&&(this.drop(),this.count=1);let o=this.tags.get(t);o||this.tags.set(t,o=new Map);let f=o.get(e);return f||o.set(e,f=new Map),f.set(s,h),h}draw(t,e,s,i,n,r,a,l,h,o,f){const u=Ps(s,n,{band:lo(i)});if(!u)return;const c=this.height,y=this.get(r,a,h),p=y.w/y.scale-2,x=Math.min(Math.max(u.head.x-p/2,4),o-p-4),m=Math.min(Math.max(u.head.y-u.headR*2.2-c,4),f-c-4);Xt(this.m,null,x-1,m-1,0,1,1),t.quad(e(y.surface),y,this.m,y.w/y.scale,y.h/y.scale,16777215,l,"normal")}},lo=t=>t.band==="3-5"||t.band==="9-12"?t.band:"6-8",ho=(t,e=!1)=>e?Math.min(2**Math.round(Math.log2(Math.max(t,8))),256):Math.min(2**(Math.ceil(Math.log2(Math.max(t,8))*2)/2),512);function ai(t,e=null){const s={minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0},i=(n,r,a)=>{const l=e?e[0]*n+e[2]*r+e[4]:n,h=e?e[1]*n+e[3]*r+e[5]:r,o=e?Math.hypot(e[0],e[1]):1;s.minX=Math.min(s.minX,l-a*o),s.minY=Math.min(s.minY,h-a*o),s.maxX=Math.max(s.maxX,l+a*o),s.maxY=Math.max(s.maxY,h+a*o)};for(const n of t){const r="lw"in n&&n.stroke?(n.lw??1)/2:0;switch(n.k){case"circle":i(n.x-n.r,n.y-n.r,r),i(n.x+n.r,n.y+n.r,r),i(n.x-n.r,n.y+n.r,r),i(n.x+n.r,n.y-n.r,r);break;case"ellipse":case"rect":{const a=n.k==="ellipse"?Math.max(n.rx,n.ry):Math.hypot(n.w,n.h)/2;i(n.x-a,n.y-a,r),i(n.x+a,n.y+a,r),i(n.x-a,n.y+a,r),i(n.x+a,n.y-a,r);break}case"path":{const a=Js(n.d);for(let l=0;l<a.count;l++){const h=a.subs[l];for(let o=0;o<h.n;o++)i(h.pts[o*2],h.pts[o*2+1],r)}break}case"line":for(let a=0;a+1<n.pts.length;a+=2)i(n.pts[a],n.pts[a+1],r);break;case"group":{const a=Xt(xe(),e,n.x,n.y,n.rot??0,n.s??1,n.s??1),l=ai(n.items,a);Number.isFinite(l.minX)&&(s.minX=Math.min(s.minX,l.minX),s.minY=Math.min(s.minY,l.minY),s.maxX=Math.max(s.maxX,l.maxX),s.maxY=Math.max(s.maxY,l.maxY));break}}}return s}var oi=class{constructor(t){d(this,"atlas",t),d(this,"seen",new WeakSet),d(this,"baked",new WeakMap),d(this,"m",xe()),d(this,"stack",[]),d(this,"local",xe()),d(this,"pts",new Float64Array(128)),d(this,"stats",{baked:0,vector:0}),d(this,"bakeGroups",!0),d(this,"coarse",!1),d(this,"gen",0),d(this,"live",new Set)}setTier(t){const e=t==="low";if(e!==this.coarse){this.coarse=e,this.gen++;for(const s of this.live)this.atlas.release(s.frame);this.live.clear()}}draw(t,e,s,i,n,r,a){const l=typeof i=="string"?es(i)??Pe:i,h=Bi(s,l,n);return h.length?(r<=0||(r<1?(this.paint(t,e,h,null,t.beginLayer()?1:r,a),t.endLayer(r)):this.paint(t,e,h,null,r,a)),!0):!1}paint(t,e,s,i,n,r,a=0){var l;for(let h=0;h<s.length;h++){const o=s[h];if(o.k==="group"){const g=Xt((l=this.stack)[a]??(l[a]=xe()),i,o.x,o.y,o.rot??0,o.s??1,o.s??1),k=n*(o.alpha??1);if(this.bakeGroups&&this.seen.has(o.items)){const E=$t(g[0],g[1])*r,w=this.bake(o.items,E);if(w){const A=w.frame,C=this.m;C.set(g),C[4]=g[0]*-w.ox+g[2]*-w.oy+g[4],C[5]=g[1]*-w.ox+g[3]*-w.oy+g[5],t.quad(e(A.surface),A,C,A.w/w.k,A.h/w.k,16777215,k,"normal"),this.stats.baked++;continue}}this.seen.add(o.items),this.stats.vector++,this.paint(t,e,o.items,g,k,r,a+1);continue}const f=n*(o.alpha??1),u=i?$t(i[0],i[1]):1,c=i?Math.atan2(i[1],i[0]):0,y=(o.lw??1)*u,p=o.stroke&&(o.lw??1)>0?Ut(o.stroke):null,x=o.fill&&o.k!=="line"?Ut(o.fill):null;if(o.k==="circle"||o.k==="ellipse"){const g=i?i[0]*o.x+i[2]*o.y+i[4]:o.x,k=i?i[1]*o.x+i[3]*o.y+i[5]:o.y,E=(o.k==="circle"?o.r:o.rx)*u,w=(o.k==="circle"?o.r:o.ry)*u,A=(o.k==="ellipse"?o.rot??0:0)+c;if(x&&p)t.ellipse(g,k,E+y/2,w+y/2,A,p[0],f*p[1]),t.ellipse(g,k,Math.max(E-y/2,0),Math.max(w-y/2,0),A,x[0],f*x[1]);else if(x)t.ellipse(g,k,E,w,A,x[0],f*x[1]);else if(p){const C=Math.min(Math.max(Math.ceil(Math.max(E,w)*r*.6),12),64),R=this.pts=Ks(this.pts,C*2),O=Math.cos(A),P=Math.sin(A);for(let I=0;I<C;I++){const q=I/C*Math.PI*2,Y=Math.cos(q)*E,U=Math.sin(q)*w;R[I*2]=g+Y*O-U*P,R[I*2+1]=k+Y*P+U*O}t.stroke(R,C,y,p[0],f*p[1],!0)}continue}if(o.k==="line"){if(!p)continue;const g=o.pts.length>>1,k=this.pts=Ks(this.pts,g*2);for(let E=0;E<g;E++){const w=o.pts[E*2],A=o.pts[E*2+1];k[E*2]=i?i[0]*w+i[2]*A+i[4]:w,k[E*2+1]=i?i[1]*w+i[3]*A+i[5]:A}t.stroke(k,g,y,p[0],f*p[1],!1);continue}const m=o.k==="path"?Js(o.d,i,u*r):co(o,Xt(this.local,i,o.x,o.y,o.rot??0,1,1),r*u);for(let g=0;g<m.count;g++){const k=m.subs[g],E=k.n,w=o.k==="rect"||k.closed;x&&E>=3&&(t.polygon(k.pts,E,x[0],f*x[1]),p||t.stroke(k.pts,E,1/r,x[0],f*x[1],!0)),p&&t.stroke(k.pts,E,y,p[0],f*p[1],w)}}}bake(t,e){const s=ho(e,this.coarse);let i=this.baked.get(t);const n=i?.get(s);if(n&&n.gen===this.gen&&this.atlas.valid(n.frame))return n;n&&this.live.delete(n);const r=ai(t);if(!Number.isFinite(r.minX))return null;const a=2/s,l=(r.maxX-r.minX+a*2)*s,h=(r.maxY-r.minY+a*2)*s;if(l>1024||h>1024)return null;const o=-r.minX+a,f=-r.minY+a,c={frame:this.atlas.bake(l,h,y=>{y.scale(s,s),y.translate(o,f),Rs(y,t)}),k:s,ox:o,oy:f,gen:this.gen};return i||this.baked.set(t,i=new Map),i.set(s,c),this.live.add(c),c}},Ae=new Array(36).fill(0),_e=0,Ht=(t,e=NaN,s=NaN,i=NaN,n=NaN)=>{Ae[_e++]=t,t!==wt.Z&&(Ae[_e++]=e,Ae[_e++]=s,t===wt.Q&&(Ae[_e++]=i,Ae[_e++]=n))};function co(t,e,s){const i=Math.max(0,Math.min(t.r,t.w/2,t.h/2)),n=-t.w/2,r=-t.h/2,{M:a,L:l,Q:h,Z:o}=wt;return _e=0,Ht(a,n+i,r),Ht(l,n+t.w-i,r),Ht(h,n+t.w,r,n+t.w,r+i),Ht(l,n+t.w,r+t.h-i),Ht(h,n+t.w,r+t.h,n+t.w-i,r+t.h),Ht(l,n+i,r+t.h),Ht(h,n,r+t.h,n,r+t.h-i),Ht(l,n,r+i),Ht(h,n,r,n+i,r),Ht(o),Js(Ae,e,s)}function fo(t,e={}){let s=ii(t,e);const i=new Ys(Math.min(1024,s.maxTextureSize),2);i.onDrop=A=>{A.texture&&s.destroyTexture(A.texture),A.texture=null};const n=new oi(i);let r=new ln;const a=new Map;let l=1e6;const h=e.smooth===!1?1:typeof e.smooth=="number"?Math.min(Math.max(e.smooth,.05),1):.5;let o=ps(s);const f=new ri(i,e),u={w:1,h:1};let c=1,y=0,p=!1;const x=()=>f.drop(),m=typeof document<"u"?document.fonts:void 0;m?.ready?.then(()=>{p||x()}),m?.addEventListener?.("loadingdone",x);const g=()=>{const A=ni(s.canvas),C=Vs(A);if(C){console.warn("[engine] avatars: WebGL context lost for good, switching to Canvas 2D"),s.destroy(),s=C;for(const R of i.pages)R.surface.texture=null;o=ps(s),y=0}},k=()=>{if(!s.lost)return y=0,!0;const A=performance.now();return y||(y=A),A-y>3e3&&g(),!s.lost},E=()=>{const A=s.canvas;e.units?(c=e.pixelRatio??1,u.w=e.units.width,u.h=e.units.height):(c=e.pixelRatio??Math.min(globalThis.devicePixelRatio||1,2),u.w=A.clientWidth||A.width/c,u.h=A.clientHeight||A.height/c),s.resize(Math.max(1,Math.round(u.w*c)),Math.max(1,Math.round(u.h*c))),s.begin(0,0,c)},w=(A,C)=>{if(A.key===void 0)return A.id??C+1;let R=a.get(A.key);return R===void 0&&(a.size>256&&a.clear(),a.set(A.key,R=l++)),R};return{get renderer(){return s},get kind(){return s.kind},get lost(){return s.lost},get canvas(){return s.canvas},draw(A,C){if(k()){E();for(let R=0;R<A.length;R++){const O=A[R];if(!Array.isArray(O.body))continue;const P=w(O,R),I=h<1||e.interpolate!==!1?r.posed(P,O.body,h,e.interpolate!==!1):O.body,q=es(O.avatar??"")??Pe,Y=O.alpha??1;!n.draw(s,o,I,q,C,Y,c)||!O.name||f.draw(s,o,I,q,C,O.name,O.color??"#6FA0E0",Y,c,u.w,u.h)}s.end()}},clear(){k()&&(E(),s.end())},reset(){r=new ln,a.clear()},destroy(){p=!0,m?.removeEventListener?.("loadingdone",x),s.destroy()}}}var ds=new Map;function uo(t,e,s=Math.min(globalThis.devicePixelRatio||1,2)){const i=`${t}|${e}|${s}`;let n=ds.get(i);if(n)return n;n=document.createElement("canvas"),n.width=n.height=Math.round(e*s);const r=n.getContext("2d");return r.scale(s,s),r.beginPath(),r.rect(0,0,e,e),r.clip(),Rs(r,ya(es(t)??Pe,e)),ds.size>64&&ds.clear(),ds.set(i,n),n}function ps(t){return e=>{if(e.texture||(e.texture=t.createTexture(e.source),e.pending.length=0),e.pending.length){for(const[s,i,n]of e.pending)t.updateTexture(e.texture,s,i,n);e.pending.length=0}return e.texture}}var Rn='Fredoka, Nunito, "Varela Round", system-ui, sans-serif',He="rgba(10,16,30,0.75)";function Fn(t,e){const s=t.size??40,i=t.outline?t.outline===!0?He:t.outline:null,n=i?t.outlineWidth??Math.max(s*.12,3):0,r=t.shadow&&e?t.shadow===!0?He:t.shadow:null,a=r?t.shadowBlur??s*.25:0;return{size:s,font:t.font??Rn,weight:t.weight??700,color:t.color??"#FBEFE3",outline:i,ow:n,shadow:r,blur:a,pad:n/2+a*1.2+2,th:s*1.25}}var Pn=(t,e)=>`${t.weight} ${t.size*e}px ${t.font}`;function Ln(t,e,s,i,n,r){t.scale(i,i),t.font=Pn(s,1),t.textBaseline="middle",t.textAlign="left",t.lineJoin="round",s.shadow&&(t.shadowColor=s.shadow,t.shadowBlur=s.blur*i),s.outline&&(t.strokeStyle=s.outline,t.lineWidth=s.ow,t.strokeText(e,n,r),t.shadowColor="transparent"),t.fillStyle=s.color,t.fillText(e,n,r)}var ys=null;function Nn(t,e,s){return ys??(ys=document.createElement("canvas").getContext("2d")),ys.font=Pn(e,s),ys.measureText(t).width/s}var Xe=class extends be{constructor(t,e,s={}){super(t,null),d(this,"_text"),d(this,"_style"),d(this,"dirty",!0),d(this,"bakedScale",0),d(this,"bakedFontGen",-1),d(this,"bakedEffects",!0),d(this,"capW",0),d(this,"capH",0),this._text=e;const{x:i,y:n,rotation:r,scale:a,scaleX:l,scaleY:h,alpha:o,visible:f,tint:u,blend:c,z:y,anchor:p,hitRadius:x,clip:m,mask:g,filters:k,...E}=s;this._style=E,this.bake(),this.set({x:i,y:n,rotation:r,scale:a,scaleX:l,scaleY:h,alpha:o,visible:f,tint:u,blend:c,z:y,hitRadius:x,clip:m,mask:g,filters:k}),p!==void 0&&(this.anchor=p)}get text(){return this._text}set text(t){const e=String(t);e!==this._text&&(this._text=e,this.dirty=!0)}get style(){return this._style}set style(t){this._style={...this._style,...t},this.dirty=!0}bitmap(){const t=this._style.bitmapFont;if(!t)return null;const e=typeof t=="string"?this.kernel.bitmapFont(t):t;if(this.autoAnchor){const s=this._style.align;this.anchorX=s==="left"?0:s==="right"?1:.5,this.anchorY=.5}return e}get naturalWidth(){const t=this.bitmap();return t?t.measure(this._text)*((this._style.size??t.size)/t.size):super.naturalWidth}get naturalHeight(){const t=this.bitmap();return t?t.lineHeight*((this._style.size??t.size)/t.size):super.naturalHeight}frameNow(){return this._style.bitmapFont?null:this.bake()}draw(t,e,s){const i=this.bitmap();if(!i)return super.draw(t,e,s);const n=(this._style.size??i.size)/i.size,r=i.measure(this._text)*n,a=i.lineHeight*n,l=this.width,h=this.height,o=r>0?l/r:1,f=a>0?h/a:1;i.run(this._text,t,this.world,-this.anchorX*l,-this.anchorY*h,n*o,n*f,s,e,this.blend)}destroy(){this._frame&&this.kernel.atlas.release(this._frame),super.destroy()}bake(){const t=this.kernel;if(this._style.bitmapFont)return null;const e=t.pixelScale,s=t.effects;return!this.dirty&&e===this.bakedScale&&t.fontGen===this.bakedFontGen&&s===this.bakedEffects&&t.atlas.valid(this._frame)?this._frame:this.rebake()}rebake(){const t=this.kernel,e=t.pixelScale,s=t.effects;this.dirty=!1,this.bakedScale=e,this.bakedFontGen=t.fontGen,this.bakedEffects=s;const i=Fn(this._style,s),{pad:n,th:r}=i,a=Nn(this._text,i,e),l=(a+n*2)*e,h=(r+n*2)*e,o=this._style.align??"center",f=o==="left"?n:o==="right"?n+a:n+a/2,u=p=>Ln(p,this._text,i,e,n,n+r/2),c=this._frame;let y=null;return c&&t.atlas.valid(c)&&c.scale===e&&(y=t.atlas.rebake(c,l,h,u,this.capW,this.capH),y?Object.assign(y,{ox:f,oy:n+r/2,margin:n}):t.atlas.release(c)),y||(this.capW=Math.ceil(l*1.25+16),this.capH=Math.ceil(h),y=t.atlas.bake(this.capW,this.capH,u,e,f,n+r/2,n),y.w=Math.ceil(l),y.h=Math.ceil(h)),this._frame=y,this.autoAnchor&&this.useFrameAnchor(),this._w=this._h=null,y}},ct=(t,e=0)=>{const s=Number(t);return Number.isFinite(s)?s:e};function ms(t){typeof t=="string"&&/^\s*[{[]/.test(t)&&(t=JSON.parse(t));const e={size:0,lineHeight:0,base:0,pages:[],chars:[],kernings:[]},s=(i,n)=>{i==="info"?e.size=Math.abs(ct(n.size)):i==="common"?(e.lineHeight=ct(n.lineHeight),e.base=ct(n.base)):i==="page"?e.pages[ct(n.id)]=String(n.file??""):i==="char"?e.chars.push({id:ct(n.id),x:ct(n.x),y:ct(n.y),width:ct(n.width),height:ct(n.height),xoffset:ct(n.xoffset),yoffset:ct(n.yoffset),xadvance:ct(n.xadvance),page:ct(n.page)}):e.kernings.push({first:ct(n.first),second:ct(n.second),amount:ct(n.amount)})};if(typeof t=="object"){const i=t;s("info",i.info??{}),s("common",i.common??{});for(const[n,r]of(i.pages??[]).entries())s("page",{id:n,file:r});for(const n of i.chars??[])s("char",n);for(const n of i.kernings??[])s("kerning",n)}else{const i=/(?:^|<)\s*(info|common|page|char|kerning)\s([^\n<>]*)/gm,n=/(\w+)=(?:"([^"]*)"|([^\s/>]+))/g;for(let r=i.exec(t);r;r=i.exec(t)){const a={};for(let l=n.exec(r[2]);l;l=n.exec(r[2]))a[l[1]]=l[2]??l[3];s(r[1],a)}}return e.size||(e.size=e.lineHeight),e}var li=class{constructor(t,e,s,i=null,n=null){d(this,"baker",i),d(this,"host",n),d(this,"size"),d(this,"lineHeight"),d(this,"base"),d(this,"ascii",new Array(128)),d(this,"more",new Map),d(this,"kern",new Map),d(this,"bScale",0),d(this,"bFontGen",-1),d(this,"bEffects",!1),d(this,"bGen",-1),this.size=t,this.lineHeight=e,this.base=s}set(t,e){t<128?this.ascii[t]=e:this.more.set(t,e)}setKerning(t,e,s){this.kern.set(t*1114112+e,s)}prepare(){const t=this.host;if(!(!t||t.pixelScale===this.bScale&&t.fontGen===this.bFontGen&&t.effects===this.bEffects&&t.atlas.gen===this.bGen)){this.bScale=t.pixelScale,this.bFontGen=t.fontGen,this.bEffects=t.effects,this.bGen=t.atlas.gen;for(const e of this.ascii)e&&t.atlas.release(e.frame);for(const e of this.more.values())e&&t.atlas.release(e.frame);this.ascii.fill(void 0),this.more.clear()}}glyph(t){let e=t<128?this.ascii[t]:this.more.get(t);return(e===void 0||e&&this.host&&!this.host.atlas.valid(e.frame))&&(e=this.baker?this.baker(t):null,this.set(t,e)),e}kerning(t,e){return this.kern.size?this.kern.get(t*1114112+e)??0:0}measure(t){return this.run(t)}run(t,e,s,i=0,n=0,r=1,a=1,l=0,h=1,o="normal"){this.prepare();let f=0,u=-1;for(let c=0;c<t.length;c++){let y=t.charCodeAt(c);y>=55296&&y<56320&&c+1<t.length&&(y=t.codePointAt(c),c++),u>=0&&(f+=this.kerning(u,y)),u=y;const p=this.glyph(y);p&&(e&&p.w>0&&p.h>0&&(is(s,i+(f+p.x)*r,n+p.y*a),e.r.quad(e.tex(p.frame.surface),p.frame,ot,p.w*r,p.h*a,l,h,o)),f+=p.advance)}return f}};function po(t,e){const s=new li(t.size,t.lineHeight,t.base);for(const i of t.chars){const n=e[i.page];if(!n)continue;const r={surface:n,x:i.x,y:i.y,w:i.width,h:i.height,scale:1,gen:0,ox:0,oy:0,margin:0};s.set(i.id,{frame:r,x:i.xoffset,y:i.yoffset,w:i.width,h:i.height,advance:i.xadvance})}for(const i of t.kernings)s.setKerning(i.first,i.second,i.amount);return s}function yo(t,e){const s={...e},i=e.size??40,n=a=>{const l=String.fromCodePoint(a),h=t.pixelScale,o=Fn(s,t.effects),f=Nn(l,o,h),u=t.atlas.bake((f+o.pad*2)*h,(o.th+o.pad*2)*h,c=>Ln(c,l,o,h,o.pad,o.pad+o.th/2),h);return{frame:u,x:-o.pad,y:-o.pad,w:u.w/h,h:u.h/h,advance:f}},r=new li(i,i*1.25,i,n,t);r.prepare();for(const a of e.chars??"0123456789")r.glyph(a.codePointAt(0));return r}var mo=.5;function In(t){const e=[];for(const[s,i]of[["left",Z.leftWrist],["right",Z.rightWrist]]){const n=t[i*3],r=t[i*3+1],a=t[i*3+2];n!==void 0&&r!==void 0&&Number.isFinite(n)&&Number.isFinite(r)&&(a??0)>=mo&&e.push({side:s,x:n,y:r})}return e}var hi=t=>Ke[((t-1)%Ke.length+Ke.length)%Ke.length];function On(t,e,s,i,n=()=>null){const r=[];for(const a of t){const l=n(a)??a.body;if(Array.isArray(l))for(const h of In(l)){const o=e(h);r.push({player:a.id,side:h.side,x:o.x*s,y:o.y*i,color:hi(a.id)})}}return r}function ci(t,e,s,i=0){const n=t.world,r=wa(n,e,s);if(!r)return!1;const a=Math.hypot(n[0],n[1])||1,l=Math.hypot(n[2],n[3])||1,[h,o]=r;if(t.hitRadius!=null){const p=t.hitRadius+i/((a+l)/2);return h*h+o*o<=p*p}const f=-t.anchorX*t.width-i/a,u=-t.anchorY*t.height-i/l,c=(1-t.anchorX)*t.width+i/a,y=(1-t.anchorY)*t.height+i/l;return h>=f&&h<=c&&o>=u&&o<=y}function zn(t,e,s,i=0){for(const n of e)if((s===void 0||n.player===s)&&ci(t,n.x,n.y,i))return n;return null}function xo(t){switch(t.type){case"circle":case"ring":case"star":return[t.r*2,t.r*2];case"ellipse":return[t.rx*2,t.ry*2];case"roundRect":return[t.w,t.h];case"line":return[t.length,t.lw??4];case"path":return t.r?[t.r*2,t.r*2]:[t.size,t.size]}}function go(t){const e=t.type==="line"?0:t.stroke?(t.lw??2)/2:0,s=t.shadow?t.shadow.blur*1.5+Math.max(Math.abs(t.shadow.x??0),Math.abs(t.shadow.y??0)):0;return Math.ceil(e+s+1)}var bo=(t,e)=>e||!t.shadow?t:{...t,shadow:void 0};function Dn(t,e,s){const i=go(e),n=e.type==="roundRect",[r,a]=n?[Math.min(e.w,e.r*2+4/s),Math.min(e.h,e.r*2+4/s)]:xo(e),l=(r+i*2)*s,h=(a+i*2)*s;return{frame:t.bake(l,h,f=>{f.scale(s,s),f.translate(i+r/2,i+a/2),ko(f,e,r,a)},s,i+r/2,i+a/2,i),slice:n?Math.ceil((e.r+i)*s):0,w:n?e.w:r,h:n?e.h:a}}function ko(t,e,s,i){t.lineJoin="round",t.lineCap="round";const n=new Path2D;switch(e.type){case"circle":case"ring":n.arc(0,0,e.r,0,Math.PI*2);break;case"ellipse":n.ellipse(0,0,e.rx,e.ry,0,0,Math.PI*2);break;case"roundRect":n.roundRect(-s/2,-i/2,s,i,Math.min(e.r,s/2,i/2));break;case"star":{const o=e.points??5,f=e.r*(e.inner??.5);for(let u=0;u<o*2;u++){const c=u%2?f:e.r,y=-Math.PI/2+u*Math.PI/o;u?n.lineTo(Math.cos(y)*c,Math.sin(y)*c):n.moveTo(Math.cos(y)*c,Math.sin(y)*c)}n.closePath();break}case"line":n.moveTo(-s/2+i/2,0),n.lineTo(s/2-i/2,0);break;case"path":{const o=e.r?e.r*2/e.size:1,f=new DOMMatrix([o,0,0,o,-e.size/2*o,-e.size/2*o]);n.addPath(new Path2D(e.d),f);break}}const r=e.shadow,a=()=>{if(!r)return;const o=t.getTransform();t.shadowColor=r.color,t.shadowBlur=r.blur*o.a,t.shadowOffsetX=(r.x??0)*o.a,t.shadowOffsetY=(r.y??0)*o.a},l=()=>{t.shadowColor="transparent",t.shadowBlur=0};if(e.type==="line"){a(),t.strokeStyle=e.stroke??e.fill??"#fff",t.lineWidth=i,t.stroke(n);return}const h=e.type==="ring";if(e.outlineBelow&&e.fill&&e.stroke&&!h){a(),t.strokeStyle=e.stroke,t.lineWidth=e.lw??2,t.stroke(n),l(),t.fillStyle=e.fill,t.fill(n);return}e.fill&&!h&&(a(),t.fillStyle=e.fill,t.fill(n),l()),(e.stroke||h)&&((!e.fill||h)&&a(),h&&e.fill&&(t.fillStyle=e.fill,t.fill(n)),t.strokeStyle=e.stroke??"#fff",t.lineWidth=e.lw??2,t.stroke(n),l())}var Bn=class{constructor(){if(d(this,"ctx",null),d(this,"master",null),d(this,"buffers",new Map),d(this,"held",!1),d(this,"muted",!1),d(this,"volume",1),typeof addEventListener=="function"){const t=()=>{this.context()?.resume().catch(()=>{})};for(const e of["pointerdown","keydown","touchstart"])addEventListener(e,t,{once:!0,capture:!0})}}context(){if(this.ctx)return this.ctx;const t=globalThis.AudioContext??globalThis.webkitAudioContext;if(!t)return null;try{this.ctx=new t,this.master=this.ctx.createGain(),this.master.connect(this.ctx.destination),this.held&&this.ctx.suspend()}catch{return null}return this.ctx}async load(t,e){const s=this.context();if(!s)return;const i=await(await fetch(e)).arrayBuffer();this.buffers.set(t,await s.decodeAudioData(i))}has(t){return this.buffers.has(t)}play(t,e={}){const s=this.context(),i=this.buffers.get(t);if(!s||!i||!this.audible)return()=>{};const n=s.createBufferSource();n.buffer=i,n.loop=e.loop??!1,n.playbackRate.value=e.rate??1;const r=s.createGain();return r.gain.value=(e.volume??1)*this.volume,n.connect(r).connect(this.master),n.start(),()=>{try{n.stop()}catch{}}}tone(t,e=.25,s={}){const i=this.context();if(!(!i||!this.audible))try{const n=i.createOscillator(),r=i.createGain();n.type=s.type??"sine",n.frequency.setValueAtTime(t,i.currentTime),s.to&&n.frequency.exponentialRampToValueAtTime(s.to,i.currentTime+e),r.gain.setValueAtTime((s.volume??.12)*this.volume,i.currentTime),r.gain.exponentialRampToValueAtTime(.001,i.currentTime+e),n.connect(r).connect(this.master),n.start(),n.stop(i.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}},wo={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}},qt=["high","medium","low"];function fe(t){const e=wo[t];return{name:t,...e,scale:s=>s<=0?0:Math.max(1,Math.round(s*e.particles))}}var vo=t=>qt[Math.min(qt.indexOf(t)+1,qt.length-1)],xs=(t,e)=>{if(!t.length)return NaN;const s=[...t].sort((i,n)=>i-n);return s[Math.min(s.length-1,Math.max(0,Math.floor(e*(s.length-1)+.5)))]},Mo=12,Eo=t=>gs(t,.5);function gs(t,e=.1){const s=xs(t,e);if(!Number.isFinite(s))return 1e3/60;const i=[144,120,90,75,60,50,30];let n=60;for(const r of i)Math.abs(1e3/r-s)<Math.abs(1e3/n-s)&&(n=r);return 1e3/n}function Un(t,e){const s=e.refresh!==void 0&&Number.isFinite(e.refresh)&&e.refresh>0?e.refresh:gs(e.intervals),i=xs(e.intervals,.5),n=xs(e.intervals,.9),r=xs(e.cpu,.5);if(!Number.isFinite(i))return t==="canvas2d"?"low":"medium";const a=h=>h<=s*1.25,l=h=>!Number.isFinite(r)||r<s*h;return t==="canvas2d"?a(n)&&l(.25)?"medium":"low":a(n)&&l(.5)?"high":a(i)?"medium":"low"}function Ao(t,e){return t.length<30?!1:t.filter(i=>i>e*1.5).length/t.length>.5}var Gn="0.1.1",_o=720*3600*1e3,To=(t,e,s)=>`fabi-play.engine-tier:${Gn}:${t}:${e}:${s}`,So=(t,e,s)=>`fablee-engine-tier:${Gn}:${t}:${e}:${s}`;function Co(t,e,s=Date.now()){try{const i=JSON.parse(t?.getItem(e)??"null");if(i&&qt.includes(i.tier)&&typeof i.at=="number"&&s-i.at<_o)return typeof i.refresh=="number"&&i.refresh>0?{name:i.tier,refresh:i.refresh}:{name:i.tier}}catch{}return null}function Hn(t,e,s,i,n=Date.now()){try{t?.setItem(e,JSON.stringify(i!==void 0&&Number.isFinite(i)?{tier:s,at:n,refresh:i}:{tier:s,at:n}))}catch{}}function Ro(t=typeof location<"u"?location.search:""){const e=new URLSearchParams(t).get("tier");return qt.includes(e)?e:void 0}function Xn(t,e){const s=e?.tier;if(qt.includes(s))return t==="canvas2d"&&s==="high"?"medium":s}var $n=t=>typeof t?.hz=="number"&&t.hz>=20&&t.hz<=240?gs([1e3/t.hz],.5):NaN,qn=(t,e)=>qt.indexOf(t)>=qt.indexOf(e)?t:e;function Fo(t,e,s){return t?{name:t,from:"forced"}:e?{name:s?qn(e,s):e,from:"hint"}:s?{name:s,from:"cache"}:null}var Po=/^\s*(<|>|[^+\-<>=\s][^+=]*?)?\s*(?:([+-])=\s*(\d*\.?\d+))?\s*$/,Wn=class{constructor(t={}){d(this,"steps",[]),d(this,"labels",new Map),d(this,"end",0),d(this,"prevStart",0),d(this,"elapsed",0),d(this,"iter",0),d(this,"last",0),d(this,"delayLeft"),d(this,"_paused"),d(this,"done",!1),d(this,"rewinding",!1),d(this,"promise"),d(this,"resolve"),d(this,"repeat"),d(this,"yoyo"),d(this,"onComplete"),this.repeat=Math.floor(t.repeat??0),this.yoyo=!!t.yoyo,this.delayLeft=t.delay??0,this._paused=!!t.paused,this.onComplete=t.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(t){if(t===void 0)return this.end;if(typeof t=="number")return Math.max(t,0);const e=Po.exec(t);if(!e)throw new Error(`[engine] timeline: bad position "${t}"`);const[,s,i,n]=e,r=n?(i==="-"?-1:1)*Number(n):0;let a=this.end;if(s==="<")a=this.prevStart;else if(s&&s!==">"){const l=this.labels.get(s.trim());l===void 0?this.labels.set(s.trim(),this.end):a=l}return Math.max(a+r,0)}add(t){let e=this.steps.length;for(;e>0&&this.steps[e-1].start>t.start;)e--;return this.steps.splice(e,0,t),this.prevStart=t.start,this.end=Math.max(this.end,t.start+t.dur),this}to(t,e,s,i="quadOut"){const n=typeof i=="object"?i:{ease:i},r=typeof n.ease=="function"?n.ease:Ie[n.ease??"quadOut"];return this.add({target:t,to:e,from:null,fn:null,start:this.at(n.at)+(n.delay??0),dur:Math.max(s,0),ease:r,onUpdate:n.onUpdate,p:-1})}set(t,e,s){return this.add({target:t,to:e,from:null,fn:null,start:this.at(s),dur:0,ease:Ie.linear,p:-1})}call(t,e){return this.add({target:null,to:null,from:null,fn:t,start:this.at(e),dur:0,ease:Ie.linear,p:-1})}label(t,e){return this.labels.set(t,this.at(e)),this}wait(t){return this.end+=Math.max(t,0),this.prevStart=this.end,this}pause(){return this._paused=!0,this}resume(){return this._paused=!1,this}stop(){this.done||(this.done=!0,this.resolve())}seek(t){const e=Math.min(typeof t=="string"&&this.labels.has(t)?this.labels.get(t):this.at(t),this.end),s=this.yoyo&&this.iter%2===1;return this.elapsed=this.iter*this.end+(s?this.end-e:e),this.render(e),this}then(t,e){return this.promise.then(t,e)}update(t){if(this._paused||this.done)return;if(this.delayLeft>0){if(this.delayLeft-=t,this.delayLeft>0)return;t=-this.delayLeft,this.delayLeft=0}const e=this.end;if(e<=0)return this.render(0),this.complete();this.elapsed+=t;const s=this.repeat<0?1/0:e*(this.repeat+1),i=Math.min(this.elapsed,s),n=i>=s?this.repeat:Math.floor(i/e);for(;this.iter<n;){const a=this.yoyo&&this.iter%2===1;this.render(a?0:e),this.iter++,this.yoyo||(this.rewinding=!0,this.render(0),this.rewinding=!1)}const r=i-n*e;this.render(this.yoyo&&n%2===1?e-r:r),i>=s&&this.complete()}complete(){this.done||(this.done=!0,this.onComplete?.(),this.resolve())}render(t){const e=this.steps;if(t>=this.last)for(let s=0;s<e.length;s++){const i=e[s];t>=i.start&&this.apply(i,t)}else for(let s=e.length-1;s>=0;s--){const i=e[s];i.p>=0&&this.apply(i,t)}this.last=t}apply(t,e){const s=t.dur>0?Math.min(Math.max((e-t.start)/t.dur,0),1):e>t.start||e===t.start&&!this.rewinding?1:0;if(s===t.p)return;if(t.p=s,t.fn){this.rewinding||t.fn();return}const i=t.target;if(i.destroyed||i._free)return;const n=t.to;if(!t.from){t.from={};for(const a in n)t.from[a]=Number(i[a]??0)}const r=t.ease(s);for(const a in n)i[a]=t.from[a]+(n[a]-t.from[a])*r;t.onUpdate?.(r)}},Yn=class{constructor(){d(this,"list",[]),d(this,"timelines",[])}timeline(t){const e=new Wn(t);return this.timelines.push(e),e}tween(t,e,s,i="quadOut"){const n=typeof i=="object"?i:{ease:i},r=typeof n.ease=="function"?n.ease:Ie[n.ease??"quadOut"];let a;const l=new Promise(h=>{const o=Object.keys(e),f=new Float64Array(o.length);o.forEach((u,c)=>f[c]=Number(e[u])),a={target:t,keys:o,to:f,from:new Float64Array(o.length),started:!1,duration:Math.max(s,0),time:0,delay:n.delay??0,ease:r,onUpdate:n.onUpdate,done:h,dead:!1}});return this.list.push(a),Object.assign(l,{stop:()=>this.finish(a)})}stopAll(t){const e=this.list;for(let s=0;s<e.length;s++)e[s].target===t&&this.finish(e[s])}get size(){return this.list.length}update(t){if(this.timelines.length){let i=0;const n=this.timelines;for(let r=0;r<n.length;r++){const a=n[r];a.update(t),a.finished||(n[i++]=a)}n.length=i}const e=this.list;if(!e.length)return;let s=0;for(let i=0;i<e.length;i++){const n=e[i];n.dead||this.step(n,t),n.dead||(e[s++]=n)}s!==e.length&&(e.length=s)}step(t,e){if(t.target.destroyed)return this.finish(t);let s=e;if(t.delay>0){if(t.delay-=e,t.delay>0)return;s=-t.delay}const i=t.keys;if(!t.started){t.started=!0;for(let a=0;a<i.length;a++)t.from[a]=Number(t.target[i[a]]??0)}t.time+=s;const n=t.duration>0?Math.min(t.time/t.duration,1):1,r=t.ease(n);for(let a=0;a<i.length;a++)t.target[i[a]]=t.from[a]+(t.to[a]-t.from[a])*r;t.onUpdate?.(r),n>=1&&this.finish(t)}finish(t){t.dead||(t.dead=!0,t.done())}clear(){for(const t of this.list)this.finish(t);this.list.length=0;for(const t of this.timelines)t.stop();this.timelines=[]}},ft=720,Qn=class extends le{constructor(t,e){super(t),d(this,"paintAll",e)}draw(t,e){this.paintAll(t,e)}},Lo=class extends le{constructor(t,e){super(t),d(this,"paintAll",e)}draw(t,e){this.paintAll(t,e)}},se=()=>performance.now();async function No(t={}){const e=t.play??null;let s=t.canvas??null;s||(s=document.createElement("canvas"),s.style.cssText="position:fixed;inset:0;width:100%;height:100%;display:block;touch-action:none",document.body.appendChild(s));let i=ii(s,{renderer:t.renderer??oo(),failIfMajorPerformanceCaveat:t.failIfMajorPerformanceCaveat,instancing:t.instancing});s=i.canvas;const n=new Set,r=new Ys(Math.min(2048,i.maxTextureSize),4);r.onPage=b=>n.add(b),r.onDrop=b=>{n.delete(b),b.texture&&i.destroyTexture(b.texture),b.texture=null};let a=ps(i);const l=new Yn,h=new Bn,o=new oi(r),f=new Map,u=new Map,c=new Map,y=new Map,p=new Map,x=new Set;let m=0;const g=t.tier??Ro(),k=String(i.info.renderer??""),E=(()=>{try{return globalThis.localStorage??null}catch{return null}})(),w=typeof screen<"u"?`${screen.width}x${screen.height}`:"",A=To(i.kind,k,w);Tr(E,A,So(i.kind,k,w));const C=Co(E,A),R=Fo(g,Xn(i.kind,e?.device),C?.name);let O=R?.name??"medium",P=fe(O);o.setTier(O);let I=R?.from==="hint",q=C?.name,Y=C?.refresh??$n(e?.device),U=1,Nt=1,H=1;const nt={atlas:r,get pixelScale(){return U},get fontGen(){return m},get effects(){return P.effects},tweens:l,frame:b=>Ts.frame(b),shape:b=>{const M=P.effects,S=M?U:-U;let T=f.get(S);T||(f.size>=8&&f.clear(),f.set(S,T=new un(2e3)));const N=Zt(b);let it=T.get(b,N);return(!it||!r.valid(it.frame))&&T.set(b,it=Dn(r,bo(b,M),U),N),it},bitmapFont:b=>Ts.bitmapFont(b)};let mt=1280,It=null;class pi extends qs{get width(){return mt}set width(M){}get height(){return ft}set height(M){}get safe(){const M=Math.min(mt,ft*16/9);return{x:(mt-M)/2,y:0,w:M,h:ft}}}const vt=new pi(nt),Ot=()=>{const b=i.canvas,M=b.getBoundingClientRect();Nt=Math.max(1,M.width||b.clientWidth||innerWidth),H=Math.max(1,M.height||b.clientHeight||innerHeight),mt=ft*Nt/H;const S=Math.min(globalThis.devicePixelRatio||1,t.maxPixelRatio??2);if(H*S/ft<=P.resolution){const N=Math.max(1,Math.round(H*S));U=N/ft,i.resize(Math.max(1,Math.round(Nt*S)),N)}else U=P.resolution,i.resize(Math.round(mt*U),Math.round(ft*U));It&&It.style.setProperty("--unit",`${H/ft}px`)};addEventListener("resize",Ot);const xt=b=>{O=b,P=fe(b),o.setTier(b),Ot()},ut=typeof ResizeObserver<"u"?new ResizeObserver(Ot):null;ut?.observe(s);let zt=e?.backdrop==="video"?"video":"none",v=e?.view??null,L=[],D=-1/0,W=!1,G=!1;const lt=new Set,Te=()=>{const b=zt==="video"?"transparent":"";document.documentElement.style.background=b,document.body.style.background=b},Dt=(b,M)=>{const S=b==="video"?"video":"none",T=M??null;if(!(S===zt&&(T===v||T&&v&&T.x===v.x&&T.y===v.y&&T.w===v.w&&T.h===v.h))){zt=S,v=T,Te();for(const N of[...lt])N(zt,v)}},qe=[];if(e){const b=T=>{Array.isArray(T)&&(L=T,D=se())},M=T=>{W=T,dt()},S=T=>{if(g||I)return;Number.isFinite(Y)||(Y=$n(T));const N=Xn(i.kind,T);N&&(I=!0,xt(q?qn(N,q):N))};qe.push(e.on("start",T=>S(T?.device)),e.on("start",T=>{typeof T?.muted=="boolean"&&(h.muted=T.muted)}),e.on("frame",T=>b(T?.players)),e.on("players",T=>b(T?.players)),e.on("backdrop",T=>Dt(T?.backdrop,T?.view)),e.on("start",T=>Dt(T?.backdrop,T?.view??e.view)),e.on("pause",()=>M(!0)),e.on("resume",()=>M(!1)),e.on("break-start",()=>M(!0)),e.on("break-done",()=>M(!1)),e.on("break-end",()=>M(!1))),h.muted=e.muted===!0}Te();const dt=()=>W||G||document.hidden?h.hold():h.release();let Yt=-1,Qt=[],Mt=0;const St=()=>se()-D<1e3?L:[],ue=b=>e?e.toScreen(b):vr(v,b),Et=()=>{if(Yt===Mt)return Qt;Yt=Mt;const b=zt==="video"||!e?.smoothedBody?()=>null:M=>e.smoothedBody(M);return Qt=On(St(),ue,mt,ft,b),Qt},Bt={x:0,y:0,w:1,h:1},yi=()=>(Bt.x=v?v.x*mt:0,Bt.y=v?v.y*ft:0,Bt.w=v?v.w*mt:mt,Bt.h=v?v.h*ft:ft,Bt),vs=b=>{const M=b.alpha??1,S=b.tags?new ri(r,b):null;S&&x.add(S);const T=typeof b.tags=="function"?b.tags:N=>String(N);return(N,it)=>{if(zt==="video")return;const B=yi();for(const X of St()){const pt=e?.smoothedBody?.(X)??X.body,tt=es(e?.avatarOf?.(X)??X.avatar??"")??Pe;if(!o.draw(N.r,N.tex,pt,tt,B,M*it,U)||!S)continue;const Ct=T(X.id);Ct&&S.draw(N.r,N.tex,pt,tt,B,Ct,hi(X.id),M*it,U,mt,ft)}}},mi=new Set,xi=new Set,We=new Set;let Ms=!1,gi=0,Se=0,Es=0;const de={fps:0,cpuMs:0,drawCalls:0,quads:0,filtersSkipped:0};let As=0,bi=0,ki=se();const Ye=[];let _s=0;const ir=()=>({r:i,kernel:nt,tex:a});let nr=ir();const _l=()=>{if(i.lost)return;const[b,M]=zt==="video"||t.background===void 0?[0,0]:Ut(t.background);i.time=Es,i.maxBlur=P.maxBlur,i.begin(b,M,U),Xt(vt.world,null,vt.x,vt.y,vt.rotation,vt.scaleX,vt.scaleY),Ji(nr,vt,vt.alpha,vt.tint);const S=i.end();de.drawCalls=S.drawCalls,de.quads=S.quads,de.filtersSkipped=S.filtersSkipped},rr=b=>{if(!Ms)return;gi=requestAnimationFrame(rr);const M=Math.min(Math.max((b-Se)/1e3,0),.1);Se&&Ye.push(b-Se),Se=b,Mt++;const S=se(),T=W||G;if(!T){Es+=M,l.update(M);for(const N of We)N.destroyed||N.update(M);for(const N of mi)N(M,Es)}for(const N of xi)N(M);vt.sweep();for(const N of We)N.destroyed&&We.delete(N);if(i.lost?(_s||(_s=b),b-_s>3e3&&Tl()):(_s=0,_l()),As++,bi+=se()-S,S-ki>=1e3&&(de.fps=Math.round(As*1e3/(S-ki)),de.cpuMs=Math.round(bi/Math.max(As,1)*100)/100,e?.reportStats?.({fps:de.fps,renderer:i.kind,tier:O}),As=0,bi=0,ki=S),Ye.length>=180){const N=Number.isFinite(Y)?Y:gs(Ye);!g&&!T&&Ao(Ye,N)&&O!=="low"&&(xt(vo(O)),q=O,Hn(E,A,O,Number.isFinite(Y)?Y:void 0),console.info(`[engine] slow frames: tier ${O}`)),Ye.length=0}},Tl=()=>{const b=ni(i.canvas),M=Vs(b);if(M){console.warn("[engine] WebGL context lost for good: switching to Canvas 2D"),i.destroy(),i=M;for(const S of n)S.texture=null;for(const S of r.pages)n.add(S.surface);a=ps(i),nr=ir(),ut?.disconnect(),ut?.observe(b),Ot()}},ar=()=>{dt(),document.hidden||(Se=0)};document.addEventListener("visibilitychange",ar);const or=()=>{m++;for(const b of x)b.drop()};if(document.fonts?.addEventListener?.("loadingdone",or),Ot(),!R&&t.probe!==!1&&(Number.isFinite(Y)||(Y=Eo(await Io(Mo))),!I)){P=fe("high"),Ot();const b=await Oo(i,r,()=>a,()=>U,mt,()=>I);if(b.refresh=Y,!I){const M=Un(i.kind,b);Hn(E,A,M,Y),q=M,xt(M)}}const Ts={stage:vt,get tier(){return P},get renderer(){return i},get canvas(){return i.canvas},get pixelScale(){return U},get backdrop(){return zt},get view(){return v},get paused(){return W||G},sound:h,stats:de,get time(){return Es},get supports(){const b=i.support;return{filters:b.filters,blur:b.filters&&P.maxBlur>0,shaders:b.shaders,maxBlur:b.filters?P.maxBlur:0,tiers:{high:{maxBlur:fe("high").maxBlur},medium:{maxBlur:fe("medium").maxBlur},low:{maxBlur:fe("low").maxBlur}}}},sprite:(b,M)=>new be(nt,b,M),shape:(b,M)=>new Be(nt,b,M),text:(b,M)=>new Xe(nt,b,M),group:b=>new qs(nt).set(b??{}),particles(b,M={}){const S=typeof b=="object"&&"type"in b?nt.shape(b).frame:b,T=new rn(nt,S,M),{max:N,blend:it,gravity:B,drag:X,...pt}=M;return T.set(pt),We.add(T),T},tween:(b,M,S,T)=>l.tween(b,M,S,T),bake(b,M,S,T,N){return c.set(b,{w:M,h:S,draw:T,origin:N}),u.delete(b),Ts.frame(b)},frame(b){const M=u.get(b);if(M&&r.valid(M)&&(M.gen===0||M.scale===U))return M;const S=c.get(b);if(S){const T=U,N=r.bake(S.w*T,S.h*T,it=>(it.scale(T,T),S.draw(it)),T,S.origin?.x??0,S.origin?.y??0);return u.set(b,N),N}if(M)return M;throw new Error(`[engine] no frame "${b}": load it or bake it first`)},async load(b){await Promise.all(Object.entries(b).map(([M,S])=>Cl(M,S)))},hands:b=>b===void 0?Et():Et().filter(M=>M.player===b),touched(b,M,S={}){return b.updateWorld(),zn(b,Et(),M,S.padding??0)},hits(b,M,S,T=0){return b.updateWorld(),ci(b,M,S,T)},avatars:(b={})=>new Qn(nt,vs(b)),handMarkers(b={}){const M=b.radius??36,S=b.look??"auto",T=new Float64Array(6),N=Math.max(M*.12,3),it={type:"ring",r:M,lw:N,fill:"rgba(251,231,184,0.3)",stroke:"#ffffff"},B={type:"ring",r:M,lw:N*1.8,stroke:He,shadow:{color:He,blur:M*.2}},X=(pe,At,Ce,wi,Ss,ye)=>{const Cs=At.w/At.scale;Xt(T,null,Ce-Cs/2,wi-Cs/2,0,1,1),pe.r.quad(pe.tex(At.surface),At,T,Cs,Cs,Ss,ye,"normal")},pt=pe=>{let At=null,Ce=!1;return()=>(At&&r.valid(At.frame)&&At.frame.scale===U&&Ce===P.effects?At:(Ce=P.effects,At=nt.shape(pe))).frame},tt=pt(it),Ct=pt(B);return new Lo(nt,(pe,At)=>{const Ce=S==="video"||S==="auto"&&zt==="video",wi=tt(),Ss=Ce?Ct():null;for(const ye of Et())Ss&&X(pe,Ss,ye.x,ye.y,16777215,At),X(pe,wi,ye.x,ye.y,Ut(ye.color)[0],At)})},timeline:b=>l.timeline(b),animation(b,M){const S=typeof b=="string"?Sl(b):{frames:b},T=new ce(nt,S,M);return We.add(T),T},bitmapFont(b,M){if(!M){const T=y.get(b);if(!T)throw new Error(`[engine] no bitmap font "${b}": load or make it first`);return T}const S="data"in M?lr(ms(M.data),M.pages):yo(nt,M);return y.set(b,S),S},players:()=>St(),onFrame(b){return mi.add(b),()=>{mi.delete(b)}},onRender(b){return xi.add(b),()=>{xi.delete(b)}},onBackdrop(b){return lt.add(b),()=>{lt.delete(b)}},get hud(){return It||(It=document.createElement("div"),It.style.cssText="position:fixed;inset:0;pointer-events:none;overflow:hidden",document.body.appendChild(It),Ot()),It},random:(b=0,M=1)=>b+Math.random()*(M-b),start(){Ms||(Ms=!0,Se=0,gi=requestAnimationFrame(rr))},pause(){G=!0,dt()},resume(){G=!1,dt()},destroy(){Ms=!1,cancelAnimationFrame(gi),qe.forEach(b=>b()),removeEventListener("resize",Ot),ut?.disconnect(),document.removeEventListener("visibilitychange",ar),document.fonts?.removeEventListener?.("loadingdone",or),l.clear(),La(nt),h.destroy(),i.destroy(),It?.remove()}};function Sl(b){const M=p.get(b);if(M)return M;const S=[...new Set([...u.keys(),...c.keys()])].filter(T=>T.startsWith(b)).sort(Ia);if(!S.length)throw new Error(`[engine] no animation or frames "${b}\u2026"`);return{frames:S}}async function Cl(b,M){const S=M.split("?")[0].split(".").pop().toLowerCase();if(["mp3","ogg","wav","m4a","aac","webm"].includes(S))return h.load(b,M);if(["woff","woff2","ttf","otf"].includes(S)){const B=new FontFace(b,`url(${M})`);document.fonts.add(await B.load()),m++;return}const T=new URL(M,location.href);if(S==="fnt")return hr(b,ms(await(await fetch(M)).text()),T);if(S==="json"){const B=await(await fetch(M)).json();if(Array.isArray(B.chars)&&!B.frames)return hr(b,ms(B),T);const X=await fi(new URL(B.meta?.image??M.replace(/\.json$/,".png"),T).href);Rl(b,B,ns(X));return}const N=await fi(M),it=ns(N);n.add(it),u.set(b,{surface:it,x:0,y:0,w:N.width,h:N.height,scale:1,gen:0,ox:0,oy:0,margin:0})}function lr(b,M){return po(b,M.map(S=>{const T=ns(S);return n.add(T),T}))}async function hr(b,M,S){y.set(b,lr(M,await Promise.all(M.pages.map(T=>fi(new URL(T,S).href)))))}function Rl(b,M,S){n.add(S);const T=Array.isArray(M.frames)?M.frames:Object.entries(M.frames).map(([B,X])=>({...X,filename:B})),N=[],it=[];for(const B of T){const X=B.frame,pt=B.filename.replace(jn,"");B.rotated&&console.warn(`[engine] ${b}/${pt} is rotated: export without rotation`);const tt={surface:S,x:X.x,y:X.y,w:X.w,h:X.h,scale:1,gen:0,ox:0,oy:0,margin:0};B.trimmed&&B.sourceSize&&B.spriteSourceSize&&(tt.sw=B.sourceSize.w,tt.sh=B.sourceSize.h,tt.tx=B.spriteSourceSize.x,tt.ty=B.spriteSourceSize.y);const Ct=B.scale9Borders;Ct&&(tt.slice=[Ct.y,(tt.sw??X.w)-Ct.x-Ct.w,(tt.sh??X.h)-Ct.y-Ct.h,Ct.x]),u.set(`${b}/${pt}`,tt),N.push(`${b}/${pt}`),it.push((B.duration??0)/1e3)}for(const[B,X]of Object.entries(M.animations??{}))p.set(`${b}/${B}`,{frames:X.map(pt=>`${b}/${pt.replace(jn,"")}`)});for(const B of M.meta?.frameTags??[]){const X=[];for(let tt=B.from;tt<=B.to;tt++)X.push(tt);B.direction==="reverse"&&X.reverse(),B.direction==="pingpong"&&X.push(...X.slice(1,-1).reverse());const pt=X.every(tt=>it[tt]>0);p.set(`${b}/${B.name}`,{frames:X.map(tt=>N[tt]),...pt?{durations:X.map(tt=>it[tt])}:{}})}}return Ts}var jn=/\.(png|webp|jpe?g|gif|bmp)$/i;function fi(t){return new Promise((e,s)=>{const i=new Image;i.onload=()=>e(i),i.onerror=()=>s(new Error(`[engine] image did not load: ${t}`)),i.src=t})}function Io(t){return new Promise(e=>{const s=[];let i=0;const n=r=>{i&&s.push(r-i),i=r,s.length<t?requestAnimationFrame(n):e(s)};requestAnimationFrame(n)})}async function Oo(t,e,s,i,n,r=()=>!1){const a=i(),l=Dn(e,{type:"star",r:30,fill:"#ffd23f",stroke:"#3a2a10",lw:3},a).frame,h=[],o=[],f=new Float64Array(6),u=.004,c=t.kind==="canvas2d"?t.canvas.getContext("2d"):null,y=se();let p=0;return await new Promise(x=>{const m=g=>{p&&g-y>250&&h.push(g-p),p=g;const k=se();t.begin(0,0,a);const E=s();for(let w=0;w<300;w++){const A=g/1e3+w;Xt(f,null,w*37%n,w*53%ft,A,1,1),t.quad(E(l.surface),l,f,l.w/a,l.h/a,16777215,u,"normal")}for(let w=0;w<40;w++)t.ellipse(100+w*20,300,20,14,w,16746496,u),t.stroke([100+w*20,400,120+w*20,460,100+w*20,520],3,18,3368703,u,!1);t.end(),c?.getImageData(0,0,1,1),g-y>250&&o.push(se()-k),g-y<750&&!r()?requestAnimationFrame(m):(t.begin(0,0,a),t.end(),x())};requestAnimationFrame(m)}),{intervals:h,cpu:o}}var zo=64,Vn=32,Do=0,Bo=`fabi-cm-${Math.random().toString(36).slice(2,7)}-`,Kn=new Set,Zn=(t,e)=>{Kn.has(t)||(Kn.add(t),console.warn(e))},Uo=t=>new Go(t),Go=class{constructor(t){d(this,"r",t),d(this,"css","none"),d(this,"plans",new un(zo)),d(this,"buf",new Float64Array(64)),d(this,"keys",[]),d(this,"classes",new Map),d(this,"live",new Set),d(this,"svgs",new Map),d(this,"t",0),d(this,"cur",null),d(this,"svgFn",e=>this.svg(e)),d(this,"scr",[]),d(this,"flip",0)}chain(t,e){var s;const i=this.r;let n=this.buf;n[0]=i.scale,n[1]=i.maxBlur;let r=2;for(let p=0;p<e.length;p++){const x=e[p];if(r+22>n.length){const g=new Float64Array(n.length*2);g.set(n),n=this.buf=g}let m=this.classes.get(x.constructor);m===void 0&&this.classes.set(x.constructor,m=this.classes.size),n[r++]=m,n[r++]=x.enabled?1:0,x.params&&(r=x.params(n,r))}const a=(s=this.keys)[r]??(s[r]=new Float64Array(r));for(let p=0;p<r;p++)a[p]=n[p];const l=Zt(a);let h=this.plans.get(a,l);h||this.plans.set(a,h=this.plan(e),l);for(let p=0;p<h.svgs.length;p++){const x=h.svgs[p];x.used<0&&this.attach(x),x.used=this.t}i.skipped+=h.skip;let o=t;const f=i.rx0,u=i.ry0,c=i.rx1-f,y=i.ry1-u;for(let p=0;p<h.paints.length;p++)h.parts[p]&&(o=this.bake(o,h.parts[p])),e[h.paints[p]].paint2d(o.getContext("2d"),f,u,c,y);return this.css=h.parts[h.paints.length]||"none",o}tick(){const t=++this.t;if(!(t%Vn||!this.live.size))for(const e of this.live)t-e.used>Vn&&this.detach(e)}destroy(){for(const t of this.live)this.detach(t);this.plans.clear()}svg(t){if(typeof document>"u"||!document.body)return null;const e=Array.from({length:20},(i,n)=>t[n]??0).join(" ");let s=this.svgs.get(e);if(!s){const i="http://www.w3.org/2000/svg",n=document.createElementNS(i,"svg");n.setAttribute("width","0"),n.setAttribute("height","0"),n.setAttribute("aria-hidden","true"),n.style.position="absolute";const r=document.createElementNS(i,"filter"),a=Bo+ ++Do;r.setAttribute("id",a),r.setAttribute("color-interpolation-filters","sRGB");const l=document.createElementNS(i,"feColorMatrix");l.setAttribute("type","matrix"),l.setAttribute("values",e),r.append(l),n.append(r),this.attach(s={key:e,id:a,el:n,used:this.t})}return this.cur.svgs.push(s),`url(#${s.id})`}attach(t){document.body.append(t.el),this.live.add(t),this.svgs.has(t.key)||this.svgs.set(t.key,t)}detach(t){t.el.remove(),t.used=-1,this.live.delete(t),this.svgs.get(t.key)===t&&this.svgs.delete(t.key)}plan(t){const e=this.r,s=this.cur={parts:[],paints:[],skip:0,svgs:[]};let i="";for(let n=0;n<t.length;n++){const r=t[n];if(!r.enabled)continue;if(r.kind===Us){s.skip++,Zn("shader","[engine] shader() filters are WebGL only: on Canvas 2D they are skipped (check engine.supports.shaders)");continue}const a=e.support.filters&&r.css?r.css(e.scale,e.maxBlur,this.svgFn):null;a!==null?i+=i?` ${a}`:a:r.paint2d?(s.parts.push(i),s.paints.push(n),i=""):(s.skip++,Zn("css","[engine] this browser's Canvas 2D has no ctx.filter: colour filters, blur and shadows are skipped (tint works; check engine.supports.filters)"))}return s.parts.push(i),s}bake(t,e){const s=this.r,i=this.flip^=1;let n=this.scr[i];(!n||n.width!==s.canvas.width||n.height!==s.canvas.height)&&(n=this.scr[i]=document.createElement("canvas"),n.width=s.canvas.width,n.height=s.canvas.height);const r=n.getContext("2d"),a=s.rx0,l=s.ry0,h=s.rx1-a,o=s.ry1-l;return r.clearRect(a,l,h,o),r.filter=e,r.drawImage(t,a,l,h,o,a,l,h,o),r.filter="none",n}},Ho=64,bs=17,Xo=t=>`${si}
48
+ }`,xo={alpha:!0,premultipliedAlpha:!0,antialias:!1,depth:!1,stencil:!1,preserveDrawingBuffer:!1,powerPreference:"high-performance"},go=["aCorner","aP01","aP23","aUvRect","aColor","aSlot"],bo=["aPos","aUv","aColor","aSlot"];function ko(t,e,s={}){const i={...xo,failIfMajorPerformanceCaveat:s.failIfMajorPerformanceCaveat!==!1},n=e===2?t.getContext("webgl2",i):t.getContext("webgl",i)??t.getContext("experimental-webgl",i);if(!n||n.isContextLost())return null;try{return new wo(t,n,e,s)}catch(r){return console.warn("[engine] WebGL setup failed:",r),n.getExtension("WEBGL_lose_context")?.loseContext(),null}}var wo=class extends kn{constructor(t,e,s,i){super(),d(this,"canvas",t),d(this,"gl",e),d(this,"opts",i),d(this,"kind"),d(this,"maxTextureSize"),d(this,"support",{filters:!0,shaders:!0}),d(this,"features",{}),d(this,"info",{}),d(this,"lost",!1),d(this,"main"),d(this,"cur"),d(this,"unit",-1),d(this,"onUnit",new Array(Ln).fill(void 0)),d(this,"fbNow"),d(this,"mapped",!0),d(this,"calls",{useProgram:0,bindTexture:0,activeTexture:0,bindFramebuffer:0}),d(this,"vsrc",""),d(this,"attrs",[]),d(this,"fxr",null),d(this,"batch"),d(this,"dynamic"),d(this,"staticBuf",null),d(this,"index"),d(this,"vao",null),d(this,"inst",null),d(this,"vaoApi",null),d(this,"uScale",null),d(this,"textures",new Map),d(this,"kit"),d(this,"stats",{drawCalls:0,quads:0,filtersSkipped:0}),d(this,"lostListeners",[]),d(this,"restoredListeners",[]),d(this,"tris",new Int32Array(192)),d(this,"sU",0),d(this,"sV0",0),d(this,"sV1",0),d(this,"sColor",0),d(this,"sPacked",0),d(this,"sAlpha",0),d(this,"sHw",0),d(this,"strokeSeg",()=>{const n=this.q;n.set(ms),n[8]=n[10]=this.sU,n[9]=this.sV0,n[11]=this.sV1,n[12]=this.sPacked,this.put(this.kit)}),d(this,"strokeDisc",()=>this.ellipse(ms[0],ms[1],this.sHw,this.sHw,0,this.sColor,this.sAlpha)),d(this,"q",new Float64Array(13)),d(this,"layers",[]),d(this,"layerTex",new Map),d(this,"bScis",!1),d(this,"bx0",0),d(this,"by0",0),d(this,"bx1",0),d(this,"by1",0),d(this,"onContextLost",n=>{n.preventDefault(),this.lost=!0;for(const r of this.lostListeners)r()}),d(this,"onContextRestored",()=>{try{this.layers=[],this.layerTex.clear(),this.fxr=null,this.resetLayers(this.scale),this.setup();for(const n of this.textures.keys())this.textures.set(n,this.upload(n.source));this.lost=!1;for(const n of this.restoredListeners)n()}catch(n){console.warn("[engine] WebGL restore failed:",n)}}),d(this,"views",new Map),this.kind=s===2?"webgl2":"webgl1",this.maxTextureSize=e.getParameter(e.MAX_TEXTURE_SIZE),this.setup(),this.kit=this.createTexture(uo()),Ut.live=this,t.addEventListener("webglcontextlost",this.onContextLost,!1),t.addEventListener("webglcontextrestored",this.onContextRestored,!1)}setup(){const t=this.gl,e=this.kind==="webgl2"?t:null;if(this.inst=null,this.opts.instancing!==!1)if(e)this.inst={divisor:(o,c)=>e.vertexAttribDivisor(o,c),draw:(o,c)=>e.drawElementsInstanced(t.TRIANGLES,o,t.UNSIGNED_SHORT,0,c)};else{const o=t.getExtension("ANGLE_instanced_arrays");o&&(this.inst={divisor:(c,u)=>o.vertexAttribDivisorANGLE(c,u),draw:(c,u)=>o.drawElementsInstancedANGLE(t.TRIANGLES,c,t.UNSIGNED_SHORT,0,u)})}if(this.vaoApi=null,this.opts.vao!==!1)if(e)this.vaoApi={create:()=>e.createVertexArray(),bind:o=>e.bindVertexArray(o),remove:o=>e.deleteVertexArray(o)};else{const o=t.getExtension("OES_vertex_array_object");o&&(this.vaoApi={create:()=>o.createVertexArrayOES(),bind:c=>o.bindVertexArrayOES(c),remove:c=>o.deleteVertexArrayOES(c)})}const s=t.getParameter(t.MAX_TEXTURE_IMAGE_UNITS),i=Math.max(1,Math.min(Ln,s)),n=this.inst!==null;this.vsrc=n?mo:yo,this.attrs=n?go:bo,this.main=this.cur=this.build(po(i));const r=this.main.p;t.useProgram(r),this.calls.useProgram++,this.unit=-1,this.onUnit.fill(void 0),this.fbNow=void 0,this.uScale=this.main.uScale,t.uniform1iv(t.getUniformLocation(r,"uTex"),Int32Array.from({length:i},(o,c)=>c)),this.batch=new eo(n,i),this.vaoApi&&(this.vao=this.vaoApi.create(),this.vaoApi.bind(this.vao)),this.dynamic=t.createBuffer(),t.bindBuffer(t.ARRAY_BUFFER,this.dynamic),t.bufferData(t.ARRAY_BUFFER,this.batch.f32.byteLength,t.DYNAMIC_DRAW),this.index=t.createBuffer(),t.bindBuffer(t.ELEMENT_ARRAY_BUFFER,this.index),t.bufferData(t.ELEMENT_ARRAY_BUFFER,so(n?1:vn),t.STATIC_DRAW);const a=o=>t.getAttribLocation(r,o),l=(o,c,u,f,y,p,x)=>{const m=a(o);m<0||(t.enableVertexAttribArray(m),t.vertexAttribPointer(m,c,u,f,y,p),this.inst&&this.inst.divisor(m,x))};if(n){const o=Xe*4;l("aP01",4,t.FLOAT,!1,o,0,1),l("aP23",4,t.FLOAT,!1,o,16,1),l("aUvRect",4,t.FLOAT,!1,o,32,1),l("aColor",4,t.UNSIGNED_BYTE,!0,o,48,1),l("aSlot",1,t.FLOAT,!1,o,52,1),this.staticBuf=t.createBuffer(),t.bindBuffer(t.ARRAY_BUFFER,this.staticBuf),t.bufferData(t.ARRAY_BUFFER,Float32Array.of(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1),t.STATIC_DRAW),l("aCorner",4,t.FLOAT,!1,16,0,0),t.bindBuffer(t.ARRAY_BUFFER,this.dynamic)}else{const o=_e*4;l("aPos",2,t.FLOAT,!1,o,0,0),l("aUv",2,t.FLOAT,!1,o,8,0),l("aColor",4,t.UNSIGNED_BYTE,!0,o,16,0),l("aSlot",1,t.FLOAT,!1,o,20,0)}t.enable(t.BLEND),t.blendFunc(t.ONE,t.ONE_MINUS_SRC_ALPHA),t.disable(t.DEPTH_TEST),t.disable(t.CULL_FACE),t.pixelStorei(t.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!0);const h=t.getExtension("WEBGL_debug_renderer_info");this.info={version:t.getParameter(t.VERSION),renderer:h?t.getParameter(h.UNMASKED_RENDERER_WEBGL):t.getParameter(t.RENDERER),vendor:h?t.getParameter(h.UNMASKED_VENDOR_WEBGL):t.getParameter(t.VENDOR)},this.features={instancing:n,vao:this.vaoApi!==null,textureSlots:i,maxTextureSize:this.maxTextureSize}}upload(t){const e=this.gl,s=e.createTexture();return this.bindTex(s),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,e.RGBA,e.UNSIGNED_BYTE,t),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),s}resize(t,e){this.canvas.width!==t&&(this.canvas.width=t),this.canvas.height!==e&&(this.canvas.height=e)}createTexture(t){const e={id:Ys(),width:t.width,height:t.height,source:t};return this.textures.set(e,this.lost?null:this.upload(t)),e}updateTexture(t,e,s=0,i=0){if(this.lost)return;this.batch.has(t)&&this.flush();const n=this.gl,r=this.textures.get(t);r&&(this.bindTex(r),!e||e===t.source&&s===0&&i===0?n.texImage2D(n.TEXTURE_2D,0,n.RGBA,n.RGBA,n.UNSIGNED_BYTE,t.source):n.texSubImage2D(n.TEXTURE_2D,0,s,i,n.RGBA,n.UNSIGNED_BYTE,e))}destroyTexture(t){this.batch.has(t)&&this.flush();const e=this.textures.get(t);e&&!this.lost&&this.deleteTex(e),this.textures.delete(t)}begin(t,e,s){if(this.stats.drawCalls=this.stats.quads=this.stats.filtersSkipped=0,this.batch.reset(),this.resetLayers(s),this.bScis=!1,this.lost)return;const i=this.gl;i.disable(i.SCISSOR_TEST),this.bindFb(null),i.viewport(0,0,this.canvas.width,this.canvas.height);const n=e;i.clearColor((t>>16&255)/255*n,(t>>8&255)/255*n,(t&255)/255*n,n),i.clear(i.COLOR_BUFFER_BIT),this.use(this.main),i.uniform2f(this.uScale,2*s/this.canvas.width,-2*s/this.canvas.height),this.mapped=!0}build(t){const e=this.gl,s=Nn(e,e.VERTEX_SHADER,this.vsrc);let i;try{i=Nn(e,e.FRAGMENT_SHADER,t)}catch(r){throw e.deleteShader(s),r}const n=e.createProgram();if(e.attachShader(n,s),e.attachShader(n,i),this.attrs.forEach((r,a)=>e.bindAttribLocation(n,a,r)),e.linkProgram(n),e.deleteShader(s),e.deleteShader(i),!e.getProgramParameter(n,e.LINK_STATUS)){const r=e.getProgramInfoLog(n)??"?";throw e.deleteProgram(n),new Error(`link: ${r}`)}return{p:n,uScale:e.getUniformLocation(n,"uScale"),locs:new Map}}u(t,e){let s=t.locs.get(e);return s===void 0&&t.locs.set(e,s=this.gl.getUniformLocation(t.p,e)),s}use(t){this.cur!==t&&(this.cur=t,this.gl.useProgram(t.p),this.calls.useProgram++)}bindTex(t,e=this.unit<0?0:this.unit){const s=this.gl;this.onUnit[e]!==t&&(this.unit!==e&&(s.activeTexture(s.TEXTURE0+e),this.calls.activeTexture++,this.unit=e),s.bindTexture(s.TEXTURE_2D,t),this.calls.bindTexture++,this.onUnit[e]=t)}deleteTex(t){this.gl.deleteTexture(t);for(let e=0;e<this.onUnit.length;e++)this.onUnit[e]===t&&(this.onUnit[e]=null)}bindFb(t){if(t)for(let s=0;s<this.onUnit.length;s++)this.onUnit[s]===t.gl&&this.bindTex(null,s);const e=t?t.fb:null;this.fbNow!==e&&(this.gl.bindFramebuffer(this.gl.FRAMEBUFFER,e),this.calls.bindFramebuffer++,this.fbNow=e)}slotOf(t){this.batch.full&&this.flush();let e=this.batch.slot(t);return e<0&&(this.flush(),e=this.batch.slot(t)),e}quad(t,e,s,i,n,r,a,l){V[0]=i,V[1]=n,V[2]=a,this.quadQ(t,e,s,r,l)}quadQ(t,e,s,i,n){const r=V[2];if(this.lost||r<=0)return;const a=this.q,l=V[0],h=V[1],o=s[4],c=s[5],u=s[0]*l,f=s[1]*l,y=s[2]*h,p=s[3]*h;a[0]=o,a[1]=c,a[2]=u+o,a[3]=f+c,a[4]=u+y+o,a[5]=f+p+c,a[6]=y+o,a[7]=p+c;const x=1/t.width,m=1/t.height;a[8]=e.x*x,a[9]=e.y*m,a[10]=(e.x+e.w)*x,a[11]=(e.y+e.h)*m,a[12]=ke(i,r,n==="add"),this.put(t)}put(t){if(this.mute)return;const e=this.q;let s=!1;const i=Math.min(e[0],e[2],e[4],e[6]),n=Math.max(e[0],e[2],e[4],e[6]),r=Math.min(e[1],e[3],e[5],e[7]),a=Math.max(e[1],e[3],e[5],e[7]);if(this.cOn){if(this.px1<=this.px0||this.py1<=this.py0)return;const h=this.scale,o=this.px0/h,c=this.py0/h,u=this.px1/h,f=this.py1/h;if(n<=o||i>=u||a<=c||r>=f)return;if(i<o||n>u||r<c||a>f){const y=e[0],p=e[1],x=e[2],m=e[5];if(p===e[3]&&x===e[4]&&m===e[7]&&e[6]===y){if(y!==x){const g=Math.min(Math.max(y,o),u),k=Math.min(Math.max(x,o),u),E=e[8],w=(e[10]-E)/(x-y);e[10]=E+(k-y)*w,e[8]=E+(g-y)*w,e[0]=e[6]=g,e[2]=e[4]=k}if(p!==m){const g=Math.min(Math.max(p,c),f),k=Math.min(Math.max(m,c),f),E=e[9],w=(e[11]-E)/(m-p);e[11]=E+(k-p)*w,e[9]=E+(g-p)*w,e[1]=e[3]=g,e[5]=e[7]=k}}else s=!0}}const l=this.bx0===this.px0&&this.by0===this.py0&&this.bx1===this.px1&&this.by1===this.py1;if(s?(!this.bScis||!l)&&(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&&l)&&(this.flush(),this.bScis=!1),this.real){const h=this.gq;h[0]=i,h[1]=r,h[2]=n,h[3]=a,this.growQ()}this.batch.pushQ(e,this.slotOf(t))}ellipse(t,e,s,i,n,r,a){if(this.lost||a<=0||s<=0||i<=0)return;const l=ni[Fn(Math.max(s,i)*2*this.scale,ho)],h=l.w/2/l.r,o=s*h,c=i*h,u=Math.cos(n),f=Math.sin(n),y=u*o,p=f*o,x=-f*c,m=u*c,g=1/At,k=this.q;k[0]=t-y-x,k[1]=e-p-m,k[2]=t+y-x,k[3]=e+p-m,k[4]=t+y+x,k[5]=e+p+m,k[6]=t-y+x,k[7]=e-p+m,k[8]=l.x*g,k[9]=l.y*g,k[10]=(l.x+l.w)*g,k[11]=(l.y+l.h)*g,k[12]=ke(r,a),this.put(this.kit)}polygon(t,e,s,i){if(this.lost||i<=0||e<3)return;this.tris.length<e*3&&(this.tris=new Int32Array(Math.max(e*3,this.tris.length*2)));const n=this.tris,r=ao(t,e,n),a=ke(s,i),l=(ie.x+ie.w/2)/At,h=(ie.y+ie.h/2)/At;for(let o=0;o<r;o+=3){const c=n[o]*2,u=n[o+1]*2,f=n[o+2]*2,y=this.q;y[0]=t[c],y[1]=t[c+1],y[2]=t[u],y[3]=t[u+1],y[4]=y[6]=t[f],y[5]=y[7]=t[f+1],y[8]=y[10]=l,y[9]=y[11]=h,y[12]=a,this.put(this.kit)}}stroke(t,e,s,i,n,r){if(this.lost||n<=0||s<=0||e<1)return;const a=ri[Fn(s*this.scale,co)],l=s/2*(a.h/2/a.r);this.sPacked=ke(i,n),this.sColor=i,this.sAlpha=n,this.sU=(a.x+a.w/2)/At,this.sV0=a.y/At,this.sV1=(a.y+a.h)/At,this.sHw=s/2,lo(t,e,l,r,this.strokeSeg,this.strokeDisc)}target(t,e,s,i){const n=this.gl,r=n.createTexture();this.bindTex(r),n.texImage2D(n.TEXTURE_2D,0,n.RGBA,t,e,0,n.RGBA,n.UNSIGNED_BYTE,null);const a=i?n.LINEAR:n.NEAREST;n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MIN_FILTER,a),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MAG_FILTER,a),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_S,n.CLAMP_TO_EDGE),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_T,n.CLAMP_TO_EDGE),this.bindTex(null);const l=n.createFramebuffer();n.bindFramebuffer(n.FRAMEBUFFER,l),n.framebufferTexture2D(n.FRAMEBUFFER,n.COLOR_ATTACHMENT0,n.TEXTURE_2D,r,0);const h=n.checkFramebufferStatus(n.FRAMEBUFFER)===n.FRAMEBUFFER_COMPLETE;if(this.fbNow=l,this.bindFb(this.parent()),!h)return this.deleteTex(r),n.deleteFramebuffer(l),null;const o={tex:{id:Ys(),width:t,height:e,source:this.canvas},gl:r,fb:l,w:t,h:e,f:s};return this.layerTex.set(o.tex,r),o}drop(t){this.batch.has(t.tex)&&this.flush(),this.deleteTex(t.gl),this.gl.deleteFramebuffer(t.fb),this.layerTex.delete(t.tex)}parent(){return this.real>0?this.layers[this.real-1]:null}layerAt(t){const e=this.canvas.width,s=this.canvas.height;let i=this.layers[t]??null;return i&&(i.w!==e||i.h!==s)&&(this.drop(i),i=this.layers[t]=null),i??(this.layers[t]=this.target(e,s,1,!1))}pushLayer(){if(this.lost)return!1;this.flush();const t=this.layerAt(this.real);if(!t)return!1;const e=this.gl;return this.bindFb(t),e.disable(e.SCISSOR_TEST),e.clearColor(0,0,0,0),e.clear(e.COLOR_BUFFER_BIT),!0}popLayer(){return this.flush(),this.bindFb(this.parent()),this.layers[this.real].tex}filters(){return this.lost||!Ut.gl?null:this.fxr??(this.fxr=Ut.gl(this))}composite(t,e,s,i){if(i&&this.filters()?.chain(t,s,i))return;const n=this.gl;e&&n.blendFunc(n.ZERO,n.SRC_ALPHA),this.final(this.main,t,1,s),e&&(this.flush(),n.blendFunc(n.ONE,n.ONE_MINUS_SRC_ALPHA))}final(t,e,s,i){const n=this.gl,r=this.canvas.width,a=this.canvas.height,l=this.scale;(t!==this.main||!this.mapped)&&(this.bindFb(this.parent()),n.viewport(0,0,r,a),this.use(t),n.uniform2f(t.uScale,2*l/r,-2*l/a),this.mapped=t===this.main);const h=this.rx0/l,o=this.ry0/l,c=this.rx1/l,u=this.ry1/l,f=1/(s*e.width),y=1/(s*e.height),p=this.q;p[0]=p[6]=h,p[1]=p[3]=o,p[2]=p[4]=c,p[5]=p[7]=u,p[8]=this.rx0*f,p[9]=1-this.ry0*y,p[10]=this.rx1*f,p[11]=1-this.ry1*y,p[12]=ke(16777215,i),this.put(e),t!==this.main&&this.flush()}remap(){const t=this.gl;this.bindFb(this.parent()),t.viewport(0,0,this.canvas.width,this.canvas.height),this.use(this.main),t.uniform2f(this.uScale,2*this.scale/this.canvas.width,-2*this.scale/this.canvas.height),this.mapped=!0}upload2(t){const e=this.gl,s=t.words;if(this.kind==="webgl2")return e.bufferSubData(e.ARRAY_BUFFER,0,t.f32,0,s);let i=this.views.get(s);i||(this.views.size>=256&&this.views.clear(),this.views.set(s,i=t.f32.subarray(0,s))),e.bufferSubData(e.ARRAY_BUFFER,0,i)}flush(){const t=this.batch;if(!t.quads||this.lost)return t.reset();const e=this.gl;this.bScis?(e.enable(e.SCISSOR_TEST),e.scissor(this.bx0,this.canvas.height-this.by1,this.bx1-this.bx0,this.by1-this.by0)):e.disable(e.SCISSOR_TEST),this.upload2(t);for(let s=0;s<t.bound;s++){const i=t.textures[s];this.bindTex(this.textures.get(i)??this.layerTex.get(i)??null,s)}this.inst?this.inst.draw(6,t.quads):e.drawElements(e.TRIANGLES,t.quads*6,e.UNSIGNED_SHORT,0),this.stats.drawCalls++,this.stats.quads+=t.quads,t.reset()}end(){return this.closeLayers(),this.flush(),this.stats.filtersSkipped=this.skipped,this.stats}onLost(t){this.lostListeners.push(t)}onRestored(t){this.restoredListeners.push(t)}destroy(){const t=this.gl;Ut.live===this&&(Ut.live=null),this.canvas.removeEventListener("webglcontextlost",this.onContextLost),this.canvas.removeEventListener("webglcontextrestored",this.onContextRestored);try{for(const e of this.textures.values())e&&t.deleteTexture(e);for(const e of this.layers)e&&(t.deleteTexture(e.gl),t.deleteFramebuffer(e.fb));this.fxr?.destroy(),this.fxr=null,t.deleteBuffer(this.dynamic),t.deleteBuffer(this.index),this.staticBuf&&t.deleteBuffer(this.staticBuf),this.vao&&this.vaoApi&&this.vaoApi.remove(this.vao),t.deleteProgram(this.main.p),t.getExtension("WEBGL_lose_context")?.loseContext()}catch{}this.textures.clear()}};function Nn(t,e,s){const i=t.createShader(e);if(t.shaderSource(i,s),t.compileShader(i),!t.getShaderParameter(i,t.COMPILE_STATUS)){const n=t.getShaderInfoLog(i)??"?";throw t.deleteShader(i),new Error(n)}return i}function In(t="auto"){switch(t){case"canvas2d":return["canvas2d"];case"webgl1":return["webgl1","canvas2d"];default:return["webgl2","webgl1","canvas2d"]}}function oi(t,e={}){let s=t;for(const i of In(e.renderer)){const n=i==="canvas2d"?ti(s):ko(s,i==="webgl2"?2:1,e);if(n)return n;s=li(s)}throw new Error("No renderer: this browser has neither WebGL nor Canvas 2D")}function li(t){const e=t.cloneNode(!1);return t.parentNode?.replaceChild(e,t),e}function vo(t=typeof location<"u"?location.search:""){const e=new URLSearchParams(t).get("renderer");return e==="canvas"?"canvas2d":e==="webgl2"||e==="webgl1"||e==="canvas2d"||e==="webgl"||e==="auto"?e:void 0}var hi=class{constructor(t,e={}){d(this,"atlas",t),d(this,"tags",new Map),d(this,"count",0),d(this,"m",be()),d(this,"measure",null),d(this,"height"),d(this,"font"),this.height=e.tagHeight??34,this.font=e.tagFont??"Nunito, sans-serif"}drop(){for(const t of this.tags.values())for(const e of t.values())for(const s of e.values())this.atlas.release(s);this.tags.clear(),this.count=0}get(t,e,s){let i=this.tags.get(t);i||this.tags.set(t,i=new Map);let n=i.get(e);n||i.set(e,n=new Map);const r=n.get(s);return r&&this.atlas.valid(r)?r:this.bake(t,e,s)}bake(t,e,s){const i=this.height,n=`700 ${Math.round(i*.65)}px ${this.font}`,r=this.measure??(this.measure=document.createElement("canvas").getContext("2d"));r.font=n;const a=Math.round(i*.4),l=Math.ceil(r.measureText(t).width)+a*2,h=this.atlas.bake((l+2)*s,(i+2)*s,u=>{u.scale(s,s),u.translate(1,1);const f=i/2;u.beginPath(),u.moveTo(f,0),u.lineTo(l-f,0),u.arc(l-f,f,f,-Math.PI/2,Math.PI/2),u.lineTo(f,i),u.arc(f,f,f,Math.PI/2,Math.PI*3/2),u.closePath(),u.fillStyle=e,u.fill(),u.fillStyle="#fff",u.font=n,u.textAlign="center",u.textBaseline="middle",u.fillText(t,l/2,i/2+1)},s,1,1,1);++this.count>64&&(this.drop(),this.count=1);let o=this.tags.get(t);o||this.tags.set(t,o=new Map);let c=o.get(e);return c||o.set(e,c=new Map),c.set(s,h),h}draw(t,e,s,i,n,r,a,l,h,o,c){const u=Os(s,n,{band:Mo(i)});if(!u)return;const f=this.height,y=this.get(r,a,h),p=y.w/y.scale-2,x=Math.min(Math.max(u.head.x-p/2,4),o-p-4),m=Math.min(Math.max(u.head.y-u.headR*2.2-f,4),c-f-4);Xt(this.m,null,x-1,m-1,0,1,1),t.quad(e(y.surface),y,this.m,y.w/y.scale,y.h/y.scale,16777215,l,"normal")}},Mo=t=>t.band==="3-5"||t.band==="9-12"?t.band:"6-8",Eo=(t,e=!1)=>e?Math.min(2**Math.round(Math.log2(Math.max(t,8))),256):Math.min(2**(Math.ceil(Math.log2(Math.max(t,8))*2)/2),512);function ci(t,e=null){const s={minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0},i=(n,r,a)=>{const l=e?e[0]*n+e[2]*r+e[4]:n,h=e?e[1]*n+e[3]*r+e[5]:r,o=e?Math.hypot(e[0],e[1]):1;s.minX=Math.min(s.minX,l-a*o),s.minY=Math.min(s.minY,h-a*o),s.maxX=Math.max(s.maxX,l+a*o),s.maxY=Math.max(s.maxY,h+a*o)};for(const n of t){const r="lw"in n&&n.stroke?(n.lw??1)/2:0;switch(n.k){case"circle":i(n.x-n.r,n.y-n.r,r),i(n.x+n.r,n.y+n.r,r),i(n.x-n.r,n.y+n.r,r),i(n.x+n.r,n.y-n.r,r);break;case"ellipse":case"rect":{const a=n.k==="ellipse"?Math.max(n.rx,n.ry):Math.hypot(n.w,n.h)/2;i(n.x-a,n.y-a,r),i(n.x+a,n.y+a,r),i(n.x-a,n.y+a,r),i(n.x+a,n.y-a,r);break}case"path":{const a=ii(n.d);for(let l=0;l<a.count;l++){const h=a.subs[l];for(let o=0;o<h.n;o++)i(h.pts[o*2],h.pts[o*2+1],r)}break}case"line":for(let a=0;a+1<n.pts.length;a+=2)i(n.pts[a],n.pts[a+1],r);break;case"group":{const a=Xt(be(),e,n.x,n.y,n.rot??0,n.s??1,n.s??1),l=ci(n.items,a);Number.isFinite(l.minX)&&(s.minX=Math.min(s.minX,l.minX),s.minY=Math.min(s.minY,l.minY),s.maxX=Math.max(s.maxX,l.maxX),s.maxY=Math.max(s.maxY,l.maxY));break}}}return s}var fi=class{constructor(t){d(this,"atlas",t),d(this,"seen",new WeakSet),d(this,"baked",new WeakMap),d(this,"m",be()),d(this,"stack",[]),d(this,"local",be()),d(this,"pts",new Float64Array(128)),d(this,"stats",{baked:0,vector:0}),d(this,"bakeGroups",!0),d(this,"coarse",!1),d(this,"gen",0),d(this,"live",new Set)}setTier(t){const e=t==="low";if(e!==this.coarse){this.coarse=e,this.gen++;for(const s of this.live)this.atlas.release(s.frame);this.live.clear()}}draw(t,e,s,i,n,r,a){const l=typeof i=="string"?rs(i)??Ne:i,h=qi(s,l,n);return h.length?(r<=0||(r<1?(this.paint(t,e,h,null,t.beginLayer()?1:r,a),t.endLayer(r)):this.paint(t,e,h,null,r,a)),!0):!1}paint(t,e,s,i,n,r,a=0){var l;for(let h=0;h<s.length;h++){const o=s[h];if(o.k==="group"){const g=Xt((l=this.stack)[a]??(l[a]=be()),i,o.x,o.y,o.rot??0,o.s??1,o.s??1),k=n*(o.alpha??1);if(this.bakeGroups&&this.seen.has(o.items)){const E=$t(g[0],g[1])*r,w=this.bake(o.items,E);if(w){const A=w.frame,C=this.m;C.set(g),C[4]=g[0]*-w.ox+g[2]*-w.oy+g[4],C[5]=g[1]*-w.ox+g[3]*-w.oy+g[5],t.quad(e(A.surface),A,C,A.w/w.k,A.h/w.k,16777215,k,"normal"),this.stats.baked++;continue}}this.seen.add(o.items),this.stats.vector++,this.paint(t,e,o.items,g,k,r,a+1);continue}const c=n*(o.alpha??1),u=i?$t(i[0],i[1]):1,f=i?Math.atan2(i[1],i[0]):0,y=(o.lw??1)*u,p=o.stroke&&(o.lw??1)>0?Bt(o.stroke):null,x=o.fill&&o.k!=="line"?Bt(o.fill):null;if(o.k==="circle"||o.k==="ellipse"){const g=i?i[0]*o.x+i[2]*o.y+i[4]:o.x,k=i?i[1]*o.x+i[3]*o.y+i[5]:o.y,E=(o.k==="circle"?o.r:o.rx)*u,w=(o.k==="circle"?o.r:o.ry)*u,A=(o.k==="ellipse"?o.rot??0:0)+f;if(x&&p)t.ellipse(g,k,E+y/2,w+y/2,A,p[0],c*p[1]),t.ellipse(g,k,Math.max(E-y/2,0),Math.max(w-y/2,0),A,x[0],c*x[1]);else if(x)t.ellipse(g,k,E,w,A,x[0],c*x[1]);else if(p){const C=Math.min(Math.max(Math.ceil(Math.max(E,w)*r*.6),12),64),R=this.pts=ei(this.pts,C*2),O=Math.cos(A),P=Math.sin(A);for(let I=0;I<C;I++){const q=I/C*Math.PI*2,Q=Math.cos(q)*E,H=Math.sin(q)*w;R[I*2]=g+Q*O-H*P,R[I*2+1]=k+Q*P+H*O}t.stroke(R,C,y,p[0],c*p[1],!0)}continue}if(o.k==="line"){if(!p)continue;const g=o.pts.length>>1,k=this.pts=ei(this.pts,g*2);for(let E=0;E<g;E++){const w=o.pts[E*2],A=o.pts[E*2+1];k[E*2]=i?i[0]*w+i[2]*A+i[4]:w,k[E*2+1]=i?i[1]*w+i[3]*A+i[5]:A}t.stroke(k,g,y,p[0],c*p[1],!1);continue}const m=o.k==="path"?ii(o.d,i,u*r):Ao(o,Xt(this.local,i,o.x,o.y,o.rot??0,1,1),r*u);for(let g=0;g<m.count;g++){const k=m.subs[g],E=k.n,w=o.k==="rect"||k.closed;x&&E>=3&&(t.polygon(k.pts,E,x[0],c*x[1]),p||t.stroke(k.pts,E,1/r,x[0],c*x[1],!0)),p&&t.stroke(k.pts,E,y,p[0],c*p[1],w)}}}bake(t,e){const s=Eo(e,this.coarse);let i=this.baked.get(t);const n=i?.get(s);if(n&&n.gen===this.gen&&this.atlas.valid(n.frame))return n;n&&this.live.delete(n);const r=ci(t);if(!Number.isFinite(r.minX))return null;const a=2/s,l=(r.maxX-r.minX+a*2)*s,h=(r.maxY-r.minY+a*2)*s;if(l>1024||h>1024)return null;const o=-r.minX+a,c=-r.minY+a,f={frame:this.atlas.bake(l,h,y=>{y.scale(s,s),y.translate(o,c),Ns(y,t)}),k:s,ox:o,oy:c,gen:this.gen};return i||this.baked.set(t,i=new Map),i.set(s,f),this.live.add(f),f}},Se=new Array(36).fill(0),Te=0,Ht=(t,e=NaN,s=NaN,i=NaN,n=NaN)=>{Se[Te++]=t,t!==kt.Z&&(Se[Te++]=e,Se[Te++]=s,t===kt.Q&&(Se[Te++]=i,Se[Te++]=n))};function Ao(t,e,s){const i=Math.max(0,Math.min(t.r,t.w/2,t.h/2)),n=-t.w/2,r=-t.h/2,{M:a,L:l,Q:h,Z:o}=kt;return Te=0,Ht(a,n+i,r),Ht(l,n+t.w-i,r),Ht(h,n+t.w,r,n+t.w,r+i),Ht(l,n+t.w,r+t.h-i),Ht(h,n+t.w,r+t.h,n+t.w-i,r+t.h),Ht(l,n+i,r+t.h),Ht(h,n,r+t.h,n,r+t.h-i),Ht(l,n,r+i),Ht(h,n,r,n+i,r),Ht(o),ii(Se,e,s)}function _o(t,e={}){let s=oi(t,e);const i=new Ks(Math.min(1024,s.maxTextureSize),2);i.onDrop=A=>{A.texture&&s.destroyTexture(A.texture),A.texture=null};const n=new fi(i);let r=new pn;const a=new Map;let l=1e6;const h=e.smooth===!1?1:typeof e.smooth=="number"?Math.min(Math.max(e.smooth,.05),1):.5;let o=gs(s);const c=new hi(i,e),u={w:1,h:1};let f=1,y=0,p=!1;const x=()=>c.drop(),m=typeof document<"u"?document.fonts:void 0;m?.ready?.then(()=>{p||x()}),m?.addEventListener?.("loadingdone",x);const g=()=>{const A=li(s.canvas),C=ti(A);if(C){console.warn("[engine] avatars: WebGL context lost for good, switching to Canvas 2D"),s.destroy(),s=C;for(const R of i.pages)R.surface.texture=null;o=gs(s),y=0}},k=()=>{if(!s.lost)return y=0,!0;const A=performance.now();return y||(y=A),A-y>3e3&&g(),!s.lost},E=()=>{const A=s.canvas;e.units?(f=e.pixelRatio??1,u.w=e.units.width,u.h=e.units.height):(f=e.pixelRatio??Math.min(globalThis.devicePixelRatio||1,2),u.w=A.clientWidth||A.width/f,u.h=A.clientHeight||A.height/f),s.resize(Math.max(1,Math.round(u.w*f)),Math.max(1,Math.round(u.h*f))),s.begin(0,0,f)},w=(A,C)=>{if(A.key===void 0)return A.id??C+1;let R=a.get(A.key);return R===void 0&&(a.size>256&&a.clear(),a.set(A.key,R=l++)),R};return{get renderer(){return s},get kind(){return s.kind},get lost(){return s.lost},get canvas(){return s.canvas},draw(A,C){if(k()){E();for(let R=0;R<A.length;R++){const O=A[R];if(!Array.isArray(O.body))continue;const P=w(O,R),I=h<1||e.interpolate!==!1?r.posed(P,O.body,h,e.interpolate!==!1):O.body,q=rs(O.avatar??"")??Ne,Q=O.alpha??1;!n.draw(s,o,I,q,C,Q,f)||!O.name||c.draw(s,o,I,q,C,O.name,O.color??"#6FA0E0",Q,f,u.w,u.h)}s.end()}},clear(){k()&&(E(),s.end())},reset(){r=new pn,a.clear()},destroy(){p=!0,m?.removeEventListener?.("loadingdone",x),s.destroy()}}}var xs=new Map;function So(t,e,s=Math.min(globalThis.devicePixelRatio||1,2)){const i=`${t}|${e}|${s}`;let n=xs.get(i);if(n)return n;n=document.createElement("canvas"),n.width=n.height=Math.round(e*s);const r=n.getContext("2d");return r.scale(s,s),r.beginPath(),r.rect(0,0,e,e),r.clip(),Ns(r,Ca(rs(t)??Ne,e)),xs.size>64&&xs.clear(),xs.set(i,n),n}function gs(t){return e=>{if(e.texture||(e.texture=t.createTexture(e.source),e.pending.length=0),e.pending.length){for(const[s,i,n]of e.pending)t.updateTexture(e.texture,s,i,n);e.pending.length=0}return e.texture}}var On='Fredoka, Nunito, "Varela Round", system-ui, sans-serif',$e="rgba(10,16,30,0.75)";function zn(t,e){const s=t.size??40,i=t.outline?t.outline===!0?$e:t.outline:null,n=i?t.outlineWidth??Math.max(s*.12,3):0,r=t.shadow&&e?t.shadow===!0?$e:t.shadow:null,a=r?t.shadowBlur??s*.25:0;return{size:s,font:t.font??On,weight:t.weight??700,color:t.color??"#FBEFE3",outline:i,ow:n,shadow:r,blur:a,pad:n/2+a*1.2+2,th:s*1.25}}var Dn=(t,e)=>`${t.weight} ${t.size*e}px ${t.font}`;function Bn(t,e,s,i,n,r){t.scale(i,i),t.font=Dn(s,1),t.textBaseline="middle",t.textAlign="left",t.lineJoin="round",s.shadow&&(t.shadowColor=s.shadow,t.shadowBlur=s.blur*i),s.outline&&(t.strokeStyle=s.outline,t.lineWidth=s.ow,t.strokeText(e,n,r),t.shadowColor="transparent"),t.fillStyle=s.color,t.fillText(e,n,r)}var bs=null;function Un(t,e,s){return bs??(bs=document.createElement("canvas").getContext("2d")),bs.font=Dn(e,s),bs.measureText(t).width/s}var qe=class extends we{constructor(t,e,s={}){super(t,null),d(this,"_text"),d(this,"_style"),d(this,"dirty",!0),d(this,"bakedScale",0),d(this,"bakedFontGen",-1),d(this,"bakedEffects",!0),d(this,"capW",0),d(this,"capH",0),this._text=e;const{x:i,y:n,rotation:r,scale:a,scaleX:l,scaleY:h,alpha:o,visible:c,tint:u,blend:f,z:y,anchor:p,hitRadius:x,clip:m,mask:g,filters:k,...E}=s;this._style=E,this.bake(),this.set({x:i,y:n,rotation:r,scale:a,scaleX:l,scaleY:h,alpha:o,visible:c,tint:u,blend:f,z:y,hitRadius:x,clip:m,mask:g,filters:k}),p!==void 0&&(this.anchor=p)}get text(){return this._text}set text(t){const e=String(t);e!==this._text&&(this._text=e,this.dirty=!0)}get style(){return this._style}set style(t){this._style={...this._style,...t},this.dirty=!0}bitmap(){const t=this._style.bitmapFont;if(!t)return null;const e=typeof t=="string"?this.kernel.bitmapFont(t):t;if(this.autoAnchor){const s=this._style.align;this.anchorX=s==="left"?0:s==="right"?1:.5,this.anchorY=.5}return e}get naturalWidth(){const t=this.bitmap();return t?t.measure(this._text)*((this._style.size??t.size)/t.size):super.naturalWidth}get naturalHeight(){const t=this.bitmap();return t?t.lineHeight*((this._style.size??t.size)/t.size):super.naturalHeight}frameNow(){return this._style.bitmapFont?null:this.bake()}draw(t,e,s){const i=this.bitmap();if(!i)return super.draw(t,e,s);const n=(this._style.size??i.size)/i.size,r=i.measure(this._text)*n,a=i.lineHeight*n,l=this.width,h=this.height,o=r>0?l/r:1,c=a>0?h/a:1;i.run(this._text,t,this.world,-this.anchorX*l,-this.anchorY*h,n*o,n*c,s,e,this.blend)}destroy(){this._frame&&this.kernel.atlas.release(this._frame),super.destroy()}bake(){const t=this.kernel;if(this._style.bitmapFont)return null;const e=t.pixelScale,s=t.effects;return!this.dirty&&e===this.bakedScale&&t.fontGen===this.bakedFontGen&&s===this.bakedEffects&&t.atlas.valid(this._frame)?this._frame:this.rebake()}rebake(){const t=this.kernel,e=t.pixelScale,s=t.effects;this.dirty=!1,this.bakedScale=e,this.bakedFontGen=t.fontGen,this.bakedEffects=s;const i=zn(this._style,s),{pad:n,th:r}=i,a=Un(this._text,i,e),l=(a+n*2)*e,h=(r+n*2)*e,o=this._style.align??"center",c=o==="left"?n:o==="right"?n+a:n+a/2,u=p=>Bn(p,this._text,i,e,n,n+r/2),f=this._frame;let y=null;return f&&t.atlas.valid(f)&&f.scale===e&&(y=t.atlas.rebake(f,l,h,u,this.capW,this.capH),y?Object.assign(y,{ox:c,oy:n+r/2,margin:n}):t.atlas.release(f)),y||(this.capW=Math.ceil(l*1.25+16),this.capH=Math.ceil(h),y=t.atlas.bake(this.capW,this.capH,u,e,c,n+r/2,n),y.w=Math.ceil(l),y.h=Math.ceil(h)),this._frame=y,this.autoAnchor&&this.useFrameAnchor(),this._w=this._h=null,y}},ct=(t,e=0)=>{const s=Number(t);return Number.isFinite(s)?s:e};function ks(t){typeof t=="string"&&/^\s*[{[]/.test(t)&&(t=JSON.parse(t));const e={size:0,lineHeight:0,base:0,pages:[],chars:[],kernings:[]},s=(i,n)=>{i==="info"?e.size=Math.abs(ct(n.size)):i==="common"?(e.lineHeight=ct(n.lineHeight),e.base=ct(n.base)):i==="page"?e.pages[ct(n.id)]=String(n.file??""):i==="char"?e.chars.push({id:ct(n.id),x:ct(n.x),y:ct(n.y),width:ct(n.width),height:ct(n.height),xoffset:ct(n.xoffset),yoffset:ct(n.yoffset),xadvance:ct(n.xadvance),page:ct(n.page)}):e.kernings.push({first:ct(n.first),second:ct(n.second),amount:ct(n.amount)})};if(typeof t=="object"){const i=t;s("info",i.info??{}),s("common",i.common??{});for(const[n,r]of(i.pages??[]).entries())s("page",{id:n,file:r});for(const n of i.chars??[])s("char",n);for(const n of i.kernings??[])s("kerning",n)}else{const i=/(?:^|<)\s*(info|common|page|char|kerning)\s([^\n<>]*)/gm,n=/(\w+)=(?:"([^"]*)"|([^\s/>]+))/g;for(let r=i.exec(t);r;r=i.exec(t)){const a={};for(let l=n.exec(r[2]);l;l=n.exec(r[2]))a[l[1]]=l[2]??l[3];s(r[1],a)}}return e.size||(e.size=e.lineHeight),e}var ui=class{constructor(t,e,s,i=null,n=null){d(this,"baker",i),d(this,"host",n),d(this,"size"),d(this,"lineHeight"),d(this,"base"),d(this,"ascii",new Array(128)),d(this,"more",new Map),d(this,"kern",new Map),d(this,"bScale",0),d(this,"bFontGen",-1),d(this,"bEffects",!1),d(this,"bGen",-1),this.size=t,this.lineHeight=e,this.base=s}set(t,e){t<128?this.ascii[t]=e:this.more.set(t,e)}setKerning(t,e,s){this.kern.set(t*1114112+e,s)}prepare(){const t=this.host;if(!(!t||t.pixelScale===this.bScale&&t.fontGen===this.bFontGen&&t.effects===this.bEffects&&t.atlas.gen===this.bGen)){this.bScale=t.pixelScale,this.bFontGen=t.fontGen,this.bEffects=t.effects,this.bGen=t.atlas.gen;for(const e of this.ascii)e&&t.atlas.release(e.frame);for(const e of this.more.values())e&&t.atlas.release(e.frame);this.ascii.fill(void 0),this.more.clear()}}glyph(t){let e=t<128?this.ascii[t]:this.more.get(t);return(e===void 0||e&&this.host&&!this.host.atlas.valid(e.frame))&&(e=this.baker?this.baker(t):null,this.set(t,e)),e}kerning(t,e){return this.kern.size?this.kern.get(t*1114112+e)??0:0}measure(t){return this.run(t)}run(t,e,s,i=0,n=0,r=1,a=1,l=0,h=1,o="normal"){this.prepare();let c=0,u=-1;for(let f=0;f<t.length;f++){let y=t.charCodeAt(f);y>=55296&&y<56320&&f+1<t.length&&(y=t.codePointAt(f),f++),u>=0&&(c+=this.kerning(u,y)),u=y;const p=this.glyph(y);p&&(e&&p.w>0&&p.h>0&&(os(s,i+(c+p.x)*r,n+p.y*a),e.r.quad(e.tex(p.frame.surface),p.frame,lt,p.w*r,p.h*a,l,h,o)),c+=p.advance)}return c}};function To(t,e){const s=new ui(t.size,t.lineHeight,t.base);for(const i of t.chars){const n=e[i.page];if(!n)continue;const r={surface:n,x:i.x,y:i.y,w:i.width,h:i.height,scale:1,gen:0,ox:0,oy:0,margin:0};s.set(i.id,{frame:r,x:i.xoffset,y:i.yoffset,w:i.width,h:i.height,advance:i.xadvance})}for(const i of t.kernings)s.setKerning(i.first,i.second,i.amount);return s}function Co(t,e){const s={...e},i=e.size??40,n=a=>{const l=String.fromCodePoint(a),h=t.pixelScale,o=zn(s,t.effects),c=Un(l,o,h),u=t.atlas.bake((c+o.pad*2)*h,(o.th+o.pad*2)*h,f=>Bn(f,l,o,h,o.pad,o.pad+o.th/2),h);return{frame:u,x:-o.pad,y:-o.pad,w:u.w/h,h:u.h/h,advance:c}},r=new ui(i,i*1.25,i,n,t);r.prepare();for(const a of e.chars??"0123456789")r.glyph(a.codePointAt(0));return r}var Ro=.5;function Hn(t){const e=[];for(const[s,i]of[["left",U.leftWrist],["right",U.rightWrist]]){const n=t[i*3],r=t[i*3+1],a=t[i*3+2];n!==void 0&&r!==void 0&&Number.isFinite(n)&&Number.isFinite(r)&&(a??0)>=Ro&&e.push({side:s,x:n,y:r})}return e}var ws=t=>ts[((t-1)%ts.length+ts.length)%ts.length],Fo=["left","right"];function Gn(t,e,s,i,n=()=>null,r={}){const a=[];for(const l of t){const h=n(l)??l.body;if(Array.isArray(h)){if(r.orientation==="portrait"){for(const o of Fo){let c=Fr(h,o,{orientation:"portrait"});r.hold&&(c=r.hold.at(Fi.key(l.id,o),c,r.t??0)),c&&a.push({player:l.id,side:o,x:c.x*s,y:c.y*i,color:ws(l.id)})}continue}for(const o of Hn(h)){const c=e(o);a.push({player:l.id,side:o.side,x:c.x*s,y:c.y*i,color:ws(l.id)})}}}return a}function di(t,e,s,i=0){const n=t.world,r=Ia(n,e,s);if(!r)return!1;const a=Math.hypot(n[0],n[1])||1,l=Math.hypot(n[2],n[3])||1,[h,o]=r;if(t.hitRadius!=null){const p=t.hitRadius+i/((a+l)/2);return h*h+o*o<=p*p}const c=-t.anchorX*t.width-i/a,u=-t.anchorY*t.height-i/l,f=(1-t.anchorX)*t.width+i/a,y=(1-t.anchorY)*t.height+i/l;return h>=c&&h<=f&&o>=u&&o<=y}function Xn(t,e,s,i=0){for(const n of e)if((s===void 0||n.player===s)&&di(t,n.x,n.y,i))return n;return null}function Po(t){switch(t.type){case"circle":case"ring":case"star":return[t.r*2,t.r*2];case"ellipse":return[t.rx*2,t.ry*2];case"roundRect":return[t.w,t.h];case"line":return[t.length,t.lw??4];case"path":return t.r?[t.r*2,t.r*2]:[t.size,t.size]}}function Lo(t){const e=t.type==="line"?0:t.stroke?(t.lw??2)/2:0,s=t.shadow?t.shadow.blur*1.5+Math.max(Math.abs(t.shadow.x??0),Math.abs(t.shadow.y??0)):0;return Math.ceil(e+s+1)}var No=(t,e)=>e||!t.shadow?t:{...t,shadow:void 0};function $n(t,e,s){const i=Lo(e),n=e.type==="roundRect",[r,a]=n?[Math.min(e.w,e.r*2+4/s),Math.min(e.h,e.r*2+4/s)]:Po(e),l=(r+i*2)*s,h=(a+i*2)*s;return{frame:t.bake(l,h,c=>{c.scale(s,s),c.translate(i+r/2,i+a/2),Io(c,e,r,a)},s,i+r/2,i+a/2,i),slice:n?Math.ceil((e.r+i)*s):0,w:n?e.w:r,h:n?e.h:a}}function Io(t,e,s,i){t.lineJoin="round",t.lineCap="round";const n=new Path2D;switch(e.type){case"circle":case"ring":n.arc(0,0,e.r,0,Math.PI*2);break;case"ellipse":n.ellipse(0,0,e.rx,e.ry,0,0,Math.PI*2);break;case"roundRect":n.roundRect(-s/2,-i/2,s,i,Math.min(e.r,s/2,i/2));break;case"star":{const o=e.points??5,c=e.r*(e.inner??.5);for(let u=0;u<o*2;u++){const f=u%2?c:e.r,y=-Math.PI/2+u*Math.PI/o;u?n.lineTo(Math.cos(y)*f,Math.sin(y)*f):n.moveTo(Math.cos(y)*f,Math.sin(y)*f)}n.closePath();break}case"line":n.moveTo(-s/2+i/2,0),n.lineTo(s/2-i/2,0);break;case"path":{const o=e.r?e.r*2/e.size:1,c=new DOMMatrix([o,0,0,o,-e.size/2*o,-e.size/2*o]);n.addPath(new Path2D(e.d),c);break}}const r=e.shadow,a=()=>{if(!r)return;const o=t.getTransform();t.shadowColor=r.color,t.shadowBlur=r.blur*o.a,t.shadowOffsetX=(r.x??0)*o.a,t.shadowOffsetY=(r.y??0)*o.a},l=()=>{t.shadowColor="transparent",t.shadowBlur=0};if(e.type==="line"){a(),t.strokeStyle=e.stroke??e.fill??"#fff",t.lineWidth=i,t.stroke(n);return}const h=e.type==="ring";if(e.outlineBelow&&e.fill&&e.stroke&&!h){a(),t.strokeStyle=e.stroke,t.lineWidth=e.lw??2,t.stroke(n),l(),t.fillStyle=e.fill,t.fill(n);return}e.fill&&!h&&(a(),t.fillStyle=e.fill,t.fill(n),l()),(e.stroke||h)&&((!e.fill||h)&&a(),h&&e.fill&&(t.fillStyle=e.fill,t.fill(n)),t.strokeStyle=e.stroke??"#fff",t.lineWidth=e.lw??2,t.stroke(n),l())}var qn=class{constructor(){if(d(this,"ctx",null),d(this,"master",null),d(this,"buffers",new Map),d(this,"held",!1),d(this,"muted",!1),d(this,"volume",1),typeof addEventListener=="function"){const t=()=>{this.context()?.resume().catch(()=>{})};for(const e of["pointerdown","keydown","touchstart"])addEventListener(e,t,{once:!0,capture:!0})}}context(){if(this.ctx)return this.ctx;const t=globalThis.AudioContext??globalThis.webkitAudioContext;if(!t)return null;try{this.ctx=new t,this.master=this.ctx.createGain(),this.master.connect(this.ctx.destination),this.held&&this.ctx.suspend()}catch{return null}return this.ctx}async load(t,e){const s=this.context();if(!s)return;const i=await(await fetch(e)).arrayBuffer();this.buffers.set(t,await s.decodeAudioData(i))}has(t){return this.buffers.has(t)}play(t,e={}){const s=this.context(),i=this.buffers.get(t);if(!s||!i||!this.audible)return()=>{};const n=s.createBufferSource();n.buffer=i,n.loop=e.loop??!1,n.playbackRate.value=e.rate??1;const r=s.createGain();return r.gain.value=(e.volume??1)*this.volume,n.connect(r).connect(this.master),n.start(),()=>{try{n.stop()}catch{}}}tone(t,e=.25,s={}){const i=this.context();if(!(!i||!this.audible))try{const n=i.createOscillator(),r=i.createGain();n.type=s.type??"sine",n.frequency.setValueAtTime(t,i.currentTime),s.to&&n.frequency.exponentialRampToValueAtTime(s.to,i.currentTime+e),r.gain.setValueAtTime((s.volume??.12)*this.volume,i.currentTime),r.gain.exponentialRampToValueAtTime(.001,i.currentTime+e),n.connect(r).connect(this.master),n.start(),n.stop(i.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}},Oo={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}},qt=["high","medium","low"];function ue(t){const e=Oo[t];return{name:t,...e,scale:s=>s<=0?0:Math.max(1,Math.round(s*e.particles))}}var zo=t=>qt[Math.min(qt.indexOf(t)+1,qt.length-1)],vs=(t,e)=>{if(!t.length)return NaN;const s=[...t].sort((i,n)=>i-n);return s[Math.min(s.length-1,Math.max(0,Math.floor(e*(s.length-1)+.5)))]},Do=12,Bo=t=>Ms(t,.5);function Ms(t,e=.1){const s=vs(t,e);if(!Number.isFinite(s))return 1e3/60;const i=[144,120,90,75,60,50,30];let n=60;for(const r of i)Math.abs(1e3/r-s)<Math.abs(1e3/n-s)&&(n=r);return 1e3/n}function Wn(t,e){const s=e.refresh!==void 0&&Number.isFinite(e.refresh)&&e.refresh>0?e.refresh:Ms(e.intervals),i=vs(e.intervals,.5),n=vs(e.intervals,.9),r=vs(e.cpu,.5);if(!Number.isFinite(i))return t==="canvas2d"?"low":"medium";const a=h=>h<=s*1.25,l=h=>!Number.isFinite(r)||r<s*h;return t==="canvas2d"?a(n)&&l(.25)?"medium":"low":a(n)&&l(.5)?"high":a(i)?"medium":"low"}function Uo(t,e){return t.length<30?!1:t.filter(i=>i>e*1.5).length/t.length>.5}var Yn="0.1.1",Ho=720*3600*1e3,Go=(t,e,s)=>`fabi-play.engine-tier:${Yn}:${t}:${e}:${s}`,Xo=(t,e,s)=>`fablee-engine-tier:${Yn}:${t}:${e}:${s}`;function $o(t,e,s=Date.now()){try{const i=JSON.parse(t?.getItem(e)??"null");if(i&&qt.includes(i.tier)&&typeof i.at=="number"&&s-i.at<Ho)return typeof i.refresh=="number"&&i.refresh>0?{name:i.tier,refresh:i.refresh}:{name:i.tier}}catch{}return null}function Qn(t,e,s,i,n=Date.now()){try{t?.setItem(e,JSON.stringify(i!==void 0&&Number.isFinite(i)?{tier:s,at:n,refresh:i}:{tier:s,at:n}))}catch{}}function qo(t=typeof location<"u"?location.search:""){const e=new URLSearchParams(t).get("tier");return qt.includes(e)?e:void 0}function jn(t,e){const s=e?.tier;if(qt.includes(s))return t==="canvas2d"&&s==="high"?"medium":s}var Vn=t=>typeof t?.hz=="number"&&t.hz>=20&&t.hz<=240?Ms([1e3/t.hz],.5):NaN,Kn=(t,e)=>qt.indexOf(t)>=qt.indexOf(e)?t:e;function Wo(t,e,s){return t?{name:t,from:"forced"}:e?{name:s?Kn(e,s):e,from:"hint"}:s?{name:s,from:"cache"}:null}var Yo=/^\s*(<|>|[^+\-<>=\s][^+=]*?)?\s*(?:([+-])=\s*(\d*\.?\d+))?\s*$/,Zn=class{constructor(t={}){d(this,"steps",[]),d(this,"labels",new Map),d(this,"end",0),d(this,"prevStart",0),d(this,"elapsed",0),d(this,"iter",0),d(this,"last",0),d(this,"delayLeft"),d(this,"_paused"),d(this,"done",!1),d(this,"rewinding",!1),d(this,"promise"),d(this,"resolve"),d(this,"repeat"),d(this,"yoyo"),d(this,"onComplete"),this.repeat=Math.floor(t.repeat??0),this.yoyo=!!t.yoyo,this.delayLeft=t.delay??0,this._paused=!!t.paused,this.onComplete=t.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(t){if(t===void 0)return this.end;if(typeof t=="number")return Math.max(t,0);const e=Yo.exec(t);if(!e)throw new Error(`[engine] timeline: bad position "${t}"`);const[,s,i,n]=e,r=n?(i==="-"?-1:1)*Number(n):0;let a=this.end;if(s==="<")a=this.prevStart;else if(s&&s!==">"){const l=this.labels.get(s.trim());l===void 0?this.labels.set(s.trim(),this.end):a=l}return Math.max(a+r,0)}add(t){let e=this.steps.length;for(;e>0&&this.steps[e-1].start>t.start;)e--;return this.steps.splice(e,0,t),this.prevStart=t.start,this.end=Math.max(this.end,t.start+t.dur),this}to(t,e,s,i="quadOut"){const n=typeof i=="object"?i:{ease:i},r=typeof n.ease=="function"?n.ease:ze[n.ease??"quadOut"];return this.add({target:t,to:e,from:null,fn:null,start:this.at(n.at)+(n.delay??0),dur:Math.max(s,0),ease:r,onUpdate:n.onUpdate,p:-1})}set(t,e,s){return this.add({target:t,to:e,from:null,fn:null,start:this.at(s),dur:0,ease:ze.linear,p:-1})}call(t,e){return this.add({target:null,to:null,from:null,fn:t,start:this.at(e),dur:0,ease:ze.linear,p:-1})}label(t,e){return this.labels.set(t,this.at(e)),this}wait(t){return this.end+=Math.max(t,0),this.prevStart=this.end,this}pause(){return this._paused=!0,this}resume(){return this._paused=!1,this}stop(){this.done||(this.done=!0,this.resolve())}seek(t){const e=Math.min(typeof t=="string"&&this.labels.has(t)?this.labels.get(t):this.at(t),this.end),s=this.yoyo&&this.iter%2===1;return this.elapsed=this.iter*this.end+(s?this.end-e:e),this.render(e),this}then(t,e){return this.promise.then(t,e)}update(t){if(this._paused||this.done)return;if(this.delayLeft>0){if(this.delayLeft-=t,this.delayLeft>0)return;t=-this.delayLeft,this.delayLeft=0}const e=this.end;if(e<=0)return this.render(0),this.complete();this.elapsed+=t;const s=this.repeat<0?1/0:e*(this.repeat+1),i=Math.min(this.elapsed,s),n=i>=s?this.repeat:Math.floor(i/e);for(;this.iter<n;){const a=this.yoyo&&this.iter%2===1;this.render(a?0:e),this.iter++,this.yoyo||(this.rewinding=!0,this.render(0),this.rewinding=!1)}const r=i-n*e;this.render(this.yoyo&&n%2===1?e-r:r),i>=s&&this.complete()}complete(){this.done||(this.done=!0,this.onComplete?.(),this.resolve())}render(t){const e=this.steps;if(t>=this.last)for(let s=0;s<e.length;s++){const i=e[s];t>=i.start&&this.apply(i,t)}else for(let s=e.length-1;s>=0;s--){const i=e[s];i.p>=0&&this.apply(i,t)}this.last=t}apply(t,e){const s=t.dur>0?Math.min(Math.max((e-t.start)/t.dur,0),1):e>t.start||e===t.start&&!this.rewinding?1:0;if(s===t.p)return;if(t.p=s,t.fn){this.rewinding||t.fn();return}const i=t.target;if(i.destroyed||i._free)return;const n=t.to;if(!t.from){t.from={};for(const a in n)t.from[a]=Number(i[a]??0)}const r=t.ease(s);for(const a in n)i[a]=t.from[a]+(n[a]-t.from[a])*r;t.onUpdate?.(r)}},Jn=class{constructor(){d(this,"list",[]),d(this,"timelines",[])}timeline(t){const e=new Zn(t);return this.timelines.push(e),e}tween(t,e,s,i="quadOut"){const n=typeof i=="object"?i:{ease:i},r=typeof n.ease=="function"?n.ease:ze[n.ease??"quadOut"];let a;const l=new Promise(h=>{const o=Object.keys(e),c=new Float64Array(o.length);o.forEach((u,f)=>c[f]=Number(e[u])),a={target:t,keys:o,to:c,from:new Float64Array(o.length),started:!1,duration:Math.max(s,0),time:0,delay:n.delay??0,ease:r,onUpdate:n.onUpdate,done:h,dead:!1}});return this.list.push(a),Object.assign(l,{stop:()=>this.finish(a)})}stopAll(t){const e=this.list;for(let s=0;s<e.length;s++)e[s].target===t&&this.finish(e[s])}get size(){return this.list.length}update(t){if(this.timelines.length){let i=0;const n=this.timelines;for(let r=0;r<n.length;r++){const a=n[r];a.update(t),a.finished||(n[i++]=a)}n.length=i}const e=this.list;if(!e.length)return;let s=0;for(let i=0;i<e.length;i++){const n=e[i];n.dead||this.step(n,t),n.dead||(e[s++]=n)}s!==e.length&&(e.length=s)}step(t,e){if(t.target.destroyed)return this.finish(t);let s=e;if(t.delay>0){if(t.delay-=e,t.delay>0)return;s=-t.delay}const i=t.keys;if(!t.started){t.started=!0;for(let a=0;a<i.length;a++)t.from[a]=Number(t.target[i[a]]??0)}t.time+=s;const n=t.duration>0?Math.min(t.time/t.duration,1):1,r=t.ease(n);for(let a=0;a<i.length;a++)t.target[i[a]]=t.from[a]+(t.to[a]-t.from[a])*r;t.onUpdate?.(r),n>=1&&this.finish(t)}finish(t){t.dead||(t.dead=!0,t.done())}clear(){for(const t of this.list)this.finish(t);this.list.length=0;for(const t of this.timelines)t.stop();this.timelines=[]}},ft=720,tr=class extends he{constructor(t,e){super(t),d(this,"paintAll",e)}draw(t,e){this.paintAll(t,e)}},Qo=class extends he{constructor(t,e){super(t),d(this,"paintAll",e)}draw(t,e){this.paintAll(t,e)}},Wt=()=>performance.now(),er=t=>{const e=Ir(t);return e&&Object.freeze(e)};async function jo(t={}){const e=t.play??null;let s=t.canvas??null;s||(s=document.createElement("canvas"),s.style.cssText="position:fixed;inset:0;width:100%;height:100%;display:block;touch-action:none",document.body.appendChild(s));let i=oi(s,{renderer:t.renderer??vo(),failIfMajorPerformanceCaveat:t.failIfMajorPerformanceCaveat,instancing:t.instancing});s=i.canvas;const n=new Set,r=new Ks(Math.min(2048,i.maxTextureSize),4);r.onPage=b=>n.add(b),r.onDrop=b=>{n.delete(b),b.texture&&i.destroyTexture(b.texture),b.texture=null};let a=gs(i);const l=new Jn,h=new qn,o=new fi(r),c=new Map,u=new Map,f=new Map,y=new Map,p=new Map,x=new Set;let m=0;const g=t.tier??qo(),k=String(i.info.renderer??""),E=(()=>{try{return globalThis.localStorage??null}catch{return null}})(),w=typeof screen<"u"?`${screen.width}x${screen.height}`:"",A=Go(i.kind,k,w);Hr(E,A,Xo(i.kind,k,w));const C=$o(E,A),R=Wo(g,jn(i.kind,e?.device),C?.name);let O=R?.name??"medium",P=ue(O);o.setTier(O);let I=R?.from==="hint",q=C?.name,Q=C?.refresh??Vn(e?.device),H=1,It=1,G=1;const nt={atlas:r,get pixelScale(){return H},get fontGen(){return m},get effects(){return P.effects},tweens:l,frame:b=>Fs.frame(b),shape:b=>{const M=P.effects,T=M?H:-H;let S=c.get(T);S||(c.size>=8&&c.clear(),c.set(T,S=new gn(2e3)));const N=te(b);let it=S.get(b,N);return(!it||!r.valid(it.frame))&&S.set(b,it=$n(r,No(b,M),H),N),it},bitmapFont:b=>Fs.bitmapFont(b)};let yt=1280,Ot=null;class xi extends js{get width(){return yt}set width(M){}get height(){return ft}set height(M){}get safe(){const M=Math.min(yt,ft*16/9);return{x:(yt-M)/2,y:0,w:M,h:ft}}}const wt=new xi(nt),zt=()=>{const b=i.canvas,M=b.getBoundingClientRect();It=Math.max(1,M.width||b.clientWidth||innerWidth),G=Math.max(1,M.height||b.clientHeight||innerHeight),yt=ft*It/G;const T=Math.min(globalThis.devicePixelRatio||1,t.maxPixelRatio??2);if(G*T/ft<=P.resolution){const N=Math.max(1,Math.round(G*T));H=N/ft,i.resize(Math.max(1,Math.round(It*T)),N)}else H=P.resolution,i.resize(Math.round(yt*H),Math.round(ft*H));Ot&&Ot.style.setProperty("--unit",`${G/ft}px`)};addEventListener("resize",zt);const mt=b=>{O=b,P=ue(b),o.setTier(b),zt()},ut=typeof ResizeObserver<"u"?new ResizeObserver(zt):null;ut?.observe(s);let Dt=e?.backdrop==="video"?"video":"none",v=e?.view??null,L=e?.orientation==="portrait"?"portrait":"landscape",D=er(e?.safeArea)??Nr,Y=[],W=-1/0,ot=!1,Qt=!1;const _t=new Set,Ye=()=>{const b=Dt==="video"?"transparent":"";document.documentElement.style.background=b,document.body.style.background=b},vt=(b,M)=>{const T=b==="video"?"video":"none",S=M??null;if(!(T===Dt&&(S===v||S&&v&&S.x===v.x&&S.y===v.y&&S.w===v.w&&S.h===v.h))){Dt=T,v=S,Ye();for(const N of[..._t])N(Dt,v)}},jt=[];if(e){const b=S=>{Array.isArray(S)&&(Y=S,W=Wt())},M=S=>{ot=S,Gt()},T=S=>{if(g||I)return;Number.isFinite(Q)||(Q=Vn(S));const N=jn(i.kind,S);N&&(I=!0,mt(q?Kn(N,q):N))};jt.push(e.on("start",S=>T(S?.device)),e.on("start",S=>{(S?.orientation==="portrait"||S?.orientation==="landscape")&&(L=S.orientation);const N=er(S?.safeArea);N&&(D=N)}),e.on("start",S=>{typeof S?.muted=="boolean"&&(h.muted=S.muted)}),e.on("frame",S=>b(S?.players)),e.on("players",S=>b(S?.players)),e.on("backdrop",S=>vt(S?.backdrop,S?.view)),e.on("start",S=>vt(S?.backdrop,S?.view??e.view)),e.on("pause",()=>M(!0)),e.on("resume",()=>M(!1)),e.on("break-start",()=>M(!0)),e.on("break-done",()=>M(!1)),e.on("break-end",()=>M(!1))),h.muted=e.muted===!0}Ye();const Gt=()=>ot||Qt||document.hidden?h.hold():h.release();let St=-1,Tt=[],Vt=0;const Ct=()=>Wt()-W<1e3?Y:[],de=b=>e?e.toScreen(b):Ri(v,b),gi=new Fi,pe=()=>{if(St===Vt)return Tt;St=Vt;const b=L==="portrait",M=Dt==="video"&&!b||!e?.smoothedBody?()=>null:T=>e.smoothedBody(T);return Tt=Gn(Ct(),de,yt,ft,M,b?{orientation:L,hold:gi,t:Wt()}:void 0),Tt},Qe={x:0,y:0,w:1,h:1},Hl=()=>(Qe.x=v?v.x*yt:0,Qe.y=v?v.y*ft:0,Qe.w=v?v.w*yt:yt,Qe.h=v?v.h*ft:ft,Qe),Gl=b=>{const M=b.alpha??1,T=b.tags?new hi(r,b):null;T&&x.add(T);const S=typeof b.tags=="function"?b.tags:N=>String(N);return(N,it)=>{if(Dt==="video")return;const B=Hl();for(const X of Ct()){const dt=e?.smoothedBody?.(X)??X.body,tt=rs(e?.avatarOf?.(X)??X.avatar??"")??Ne;if(!o.draw(N.r,N.tex,dt,tt,B,M*it,H)||!T)continue;const Rt=S(X.id);Rt&&T.draw(N.r,N.tex,dt,tt,B,Rt,ws(X.id),M*it,H,yt,ft)}}},bi=new Set,ki=new Set,je=new Set;let Ss=!1,wi=0,Ce=0,Ts=0;const ye={fps:0,cpuMs:0,drawCalls:0,quads:0,filtersSkipped:0};let Cs=0,vi=0,Mi=Wt();const Ve=[];let Rs=0;const cr=()=>({r:i,kernel:nt,tex:a});let fr=cr();const Xl=()=>{if(i.lost)return;const[b,M]=Dt==="video"||t.background===void 0?[0,0]:Bt(t.background);i.time=Ts,i.maxBlur=P.maxBlur,i.begin(b,M,H),Xt(wt.world,null,wt.x,wt.y,wt.rotation,wt.scaleX,wt.scaleY),an(fr,wt,wt.alpha,wt.tint);const T=i.end();ye.drawCalls=T.drawCalls,ye.quads=T.quads,ye.filtersSkipped=T.filtersSkipped},ur=b=>{if(!Ss)return;wi=requestAnimationFrame(ur);const M=Math.min(Math.max((b-Ce)/1e3,0),.1);Ce&&Ve.push(b-Ce),Ce=b,Vt++;const T=Wt(),S=ot||Qt;if(!S){Ts+=M,l.update(M);for(const N of je)N.destroyed||N.update(M);for(const N of bi)N(M,Ts)}for(const N of ki)N(M);wt.sweep();for(const N of je)N.destroyed&&je.delete(N);if(i.lost?(Rs||(Rs=b),b-Rs>3e3&&$l()):(Rs=0,Xl()),Cs++,vi+=Wt()-T,T-Mi>=1e3&&(ye.fps=Math.round(Cs*1e3/(T-Mi)),ye.cpuMs=Math.round(vi/Math.max(Cs,1)*100)/100,e?.reportStats?.({fps:ye.fps,renderer:i.kind,tier:O}),Cs=0,vi=0,Mi=T),Ve.length>=180){const N=Number.isFinite(Q)?Q:Ms(Ve);!g&&!S&&Uo(Ve,N)&&O!=="low"&&(mt(zo(O)),q=O,Qn(E,A,O,Number.isFinite(Q)?Q:void 0),console.info(`[engine] slow frames: tier ${O}`)),Ve.length=0}},$l=()=>{const b=li(i.canvas),M=ti(b);if(M){console.warn("[engine] WebGL context lost for good: switching to Canvas 2D"),i.destroy(),i=M;for(const T of n)T.texture=null;for(const T of r.pages)n.add(T.surface);a=gs(i),fr=cr(),ut?.disconnect(),ut?.observe(b),zt()}},dr=()=>{Gt(),document.hidden||(Ce=0)};document.addEventListener("visibilitychange",dr);const pr=()=>{m++;for(const b of x)b.drop()};if(document.fonts?.addEventListener?.("loadingdone",pr),zt(),!R&&t.probe!==!1&&(Number.isFinite(Q)||(Q=Bo(await Vo(Do))),!I)){P=ue("high"),zt();const b=await Ko(i,r,()=>a,()=>H,yt,()=>I);if(b.refresh=Q,!I){const M=Wn(i.kind,b);Qn(E,A,M,Q),q=M,mt(M)}}const Fs={stage:wt,get tier(){return P},get renderer(){return i},get canvas(){return i.canvas},get pixelScale(){return H},get backdrop(){return Dt},get view(){return v},get orientation(){return L},get safeArea(){return D},get paused(){return ot||Qt},sound:h,stats:ye,get time(){return Ts},get supports(){const b=i.support;return{filters:b.filters,blur:b.filters&&P.maxBlur>0,shaders:b.shaders,maxBlur:b.filters?P.maxBlur:0,tiers:{high:{maxBlur:ue("high").maxBlur},medium:{maxBlur:ue("medium").maxBlur},low:{maxBlur:ue("low").maxBlur}}}},sprite:(b,M)=>new we(nt,b,M),shape:(b,M)=>new He(nt,b,M),text:(b,M)=>new qe(nt,b,M),group:b=>new js(nt).set(b??{}),particles(b,M={}){const T=typeof b=="object"&&"type"in b?nt.shape(b).frame:b,S=new fn(nt,T,M),{max:N,blend:it,gravity:B,drag:X,...dt}=M;return S.set(dt),je.add(S),S},tween:(b,M,T,S)=>l.tween(b,M,T,S),bake(b,M,T,S,N){return f.set(b,{w:M,h:T,draw:S,origin:N}),u.delete(b),Fs.frame(b)},frame(b){const M=u.get(b);if(M&&r.valid(M)&&(M.gen===0||M.scale===H))return M;const T=f.get(b);if(T){const S=H,N=r.bake(T.w*S,T.h*S,it=>(it.scale(S,S),T.draw(it)),S,T.origin?.x??0,T.origin?.y??0);return u.set(b,N),N}if(M)return M;throw new Error(`[engine] no frame "${b}": load it or bake it first`)},async load(b){await Promise.all(Object.entries(b).map(([M,T])=>Wl(M,T)))},hands:b=>b===void 0?pe():pe().filter(M=>M.player===b),touched(b,M,T={}){return b.updateWorld(),Xn(b,pe(),M,T.padding??0)},hits(b,M,T,S=0){return b.updateWorld(),di(b,M,T,S)},avatars:(b={})=>new tr(nt,Gl(b)),handMarkers(b={}){const M=b.radius??36,T=b.look??"auto",S=new Float64Array(6),N=Math.max(M*.12,3),it={type:"ring",r:M,lw:N,fill:"rgba(251,231,184,0.3)",stroke:"#ffffff"},B={type:"ring",r:M,lw:N*1.8,stroke:$e,shadow:{color:$e,blur:M*.2}},X=(me,Mt,Re,Ei,Ps,xe)=>{const Ls=Mt.w/Mt.scale;Xt(S,null,Re-Ls/2,Ei-Ls/2,0,1,1),me.r.quad(me.tex(Mt.surface),Mt,S,Ls,Ls,Ps,xe,"normal")},dt=me=>{let Mt=null,Re=!1;return()=>(Mt&&r.valid(Mt.frame)&&Mt.frame.scale===H&&Re===P.effects?Mt:(Re=P.effects,Mt=nt.shape(me))).frame},tt=dt(it),Rt=dt(B);return new Qo(nt,(me,Mt)=>{const Re=T==="video"||T==="auto"&&Dt==="video",Ei=tt(),Ps=Re?Rt():null;for(const xe of pe())Ps&&X(me,Ps,xe.x,xe.y,16777215,Mt),X(me,Ei,xe.x,xe.y,Bt(xe.color)[0],Mt)})},timeline:b=>l.timeline(b),animation(b,M){const T=typeof b=="string"?ql(b):{frames:b},S=new fe(nt,T,M);return je.add(S),S},bitmapFont(b,M){if(!M){const S=y.get(b);if(!S)throw new Error(`[engine] no bitmap font "${b}": load or make it first`);return S}const T="data"in M?yr(ks(M.data),M.pages):Co(nt,M);return y.set(b,T),T},players:()=>Ct(),onFrame(b){return bi.add(b),()=>{bi.delete(b)}},onRender(b){return ki.add(b),()=>{ki.delete(b)}},onBackdrop(b){return _t.add(b),()=>{_t.delete(b)}},get hud(){return Ot||(Ot=document.createElement("div"),Ot.style.cssText="position:fixed;inset:0;pointer-events:none;overflow:hidden",document.body.appendChild(Ot),zt()),Ot},random:(b=0,M=1)=>b+Math.random()*(M-b),start(){Ss||(Ss=!0,Ce=0,wi=requestAnimationFrame(ur))},pause(){Qt=!0,Gt()},resume(){Qt=!1,Gt()},destroy(){Ss=!1,cancelAnimationFrame(wi),jt.forEach(b=>b()),removeEventListener("resize",zt),ut?.disconnect(),document.removeEventListener("visibilitychange",dr),document.fonts?.removeEventListener?.("loadingdone",pr),l.clear(),Ya(nt),h.destroy(),i.destroy(),Ot?.remove()}};function ql(b){const M=p.get(b);if(M)return M;const T=[...new Set([...u.keys(),...f.keys()])].filter(S=>S.startsWith(b)).sort(ja);if(!T.length)throw new Error(`[engine] no animation or frames "${b}\u2026"`);return{frames:T}}async function Wl(b,M){const T=M.split("?")[0].split(".").pop().toLowerCase();if(["mp3","ogg","wav","m4a","aac","webm"].includes(T))return h.load(b,M);if(["woff","woff2","ttf","otf"].includes(T)){const B=new FontFace(b,`url(${M})`);document.fonts.add(await B.load()),m++;return}const S=new URL(M,location.href);if(T==="fnt")return mr(b,ks(await(await fetch(M)).text()),S);if(T==="json"){const B=await(await fetch(M)).json();if(Array.isArray(B.chars)&&!B.frames)return mr(b,ks(B),S);const X=await pi(new URL(B.meta?.image??M.replace(/\.json$/,".png"),S).href);Yl(b,B,ls(X));return}const N=await pi(M),it=ls(N);n.add(it),u.set(b,{surface:it,x:0,y:0,w:N.width,h:N.height,scale:1,gen:0,ox:0,oy:0,margin:0})}function yr(b,M){return To(b,M.map(T=>{const S=ls(T);return n.add(S),S}))}async function mr(b,M,T){y.set(b,yr(M,await Promise.all(M.pages.map(S=>pi(new URL(S,T).href)))))}function Yl(b,M,T){n.add(T);const S=Array.isArray(M.frames)?M.frames:Object.entries(M.frames).map(([B,X])=>({...X,filename:B})),N=[],it=[];for(const B of S){const X=B.frame,dt=B.filename.replace(sr,"");B.rotated&&console.warn(`[engine] ${b}/${dt} is rotated: export without rotation`);const tt={surface:T,x:X.x,y:X.y,w:X.w,h:X.h,scale:1,gen:0,ox:0,oy:0,margin:0};B.trimmed&&B.sourceSize&&B.spriteSourceSize&&(tt.sw=B.sourceSize.w,tt.sh=B.sourceSize.h,tt.tx=B.spriteSourceSize.x,tt.ty=B.spriteSourceSize.y);const Rt=B.scale9Borders;Rt&&(tt.slice=[Rt.y,(tt.sw??X.w)-Rt.x-Rt.w,(tt.sh??X.h)-Rt.y-Rt.h,Rt.x]),u.set(`${b}/${dt}`,tt),N.push(`${b}/${dt}`),it.push((B.duration??0)/1e3)}for(const[B,X]of Object.entries(M.animations??{}))p.set(`${b}/${B}`,{frames:X.map(dt=>`${b}/${dt.replace(sr,"")}`)});for(const B of M.meta?.frameTags??[]){const X=[];for(let tt=B.from;tt<=B.to;tt++)X.push(tt);B.direction==="reverse"&&X.reverse(),B.direction==="pingpong"&&X.push(...X.slice(1,-1).reverse());const dt=X.every(tt=>it[tt]>0);p.set(`${b}/${B.name}`,{frames:X.map(tt=>N[tt]),...dt?{durations:X.map(tt=>it[tt])}:{}})}}return Fs}var sr=/\.(png|webp|jpe?g|gif|bmp)$/i;function pi(t){return new Promise((e,s)=>{const i=new Image;i.onload=()=>e(i),i.onerror=()=>s(new Error(`[engine] image did not load: ${t}`)),i.src=t})}function Vo(t){return new Promise(e=>{const s=[];let i=0;const n=r=>{i&&s.push(r-i),i=r,s.length<t?requestAnimationFrame(n):e(s)};requestAnimationFrame(n)})}async function Ko(t,e,s,i,n,r=()=>!1){const a=i(),l=$n(e,{type:"star",r:30,fill:"#ffd23f",stroke:"#3a2a10",lw:3},a).frame,h=[],o=[],c=new Float64Array(6),u=.004,f=t.kind==="canvas2d"?t.canvas.getContext("2d"):null,y=Wt();let p=0;return await new Promise(x=>{const m=g=>{p&&g-y>250&&h.push(g-p),p=g;const k=Wt();t.begin(0,0,a);const E=s();for(let w=0;w<300;w++){const A=g/1e3+w;Xt(c,null,w*37%n,w*53%ft,A,1,1),t.quad(E(l.surface),l,c,l.w/a,l.h/a,16777215,u,"normal")}for(let w=0;w<40;w++)t.ellipse(100+w*20,300,20,14,w,16746496,u),t.stroke([100+w*20,400,120+w*20,460,100+w*20,520],3,18,3368703,u,!1);t.end(),f?.getImageData(0,0,1,1),g-y>250&&o.push(Wt()-k),g-y<750&&!r()?requestAnimationFrame(m):(t.begin(0,0,a),t.end(),x())};requestAnimationFrame(m)}),{intervals:h,cpu:o}}var Zo=64,ir=32,Jo=0,tl=`fabi-cm-${Math.random().toString(36).slice(2,7)}-`,nr=new Set,rr=(t,e)=>{nr.has(t)||(nr.add(t),console.warn(e))},el=t=>new sl(t),sl=class{constructor(t){d(this,"r",t),d(this,"css","none"),d(this,"plans",new gn(Zo)),d(this,"buf",new Float64Array(64)),d(this,"keys",[]),d(this,"classes",new Map),d(this,"live",new Set),d(this,"svgs",new Map),d(this,"t",0),d(this,"cur",null),d(this,"svgFn",e=>this.svg(e)),d(this,"scr",[]),d(this,"flip",0)}chain(t,e){var s;const i=this.r;let n=this.buf;n[0]=i.scale,n[1]=i.maxBlur;let r=2;for(let p=0;p<e.length;p++){const x=e[p];if(r+22>n.length){const g=new Float64Array(n.length*2);g.set(n),n=this.buf=g}let m=this.classes.get(x.constructor);m===void 0&&this.classes.set(x.constructor,m=this.classes.size),n[r++]=m,n[r++]=x.enabled?1:0,x.params&&(r=x.params(n,r))}const a=(s=this.keys)[r]??(s[r]=new Float64Array(r));for(let p=0;p<r;p++)a[p]=n[p];const l=te(a);let h=this.plans.get(a,l);h||this.plans.set(a,h=this.plan(e),l);for(let p=0;p<h.svgs.length;p++){const x=h.svgs[p];x.used<0&&this.attach(x),x.used=this.t}i.skipped+=h.skip;let o=t;const c=i.rx0,u=i.ry0,f=i.rx1-c,y=i.ry1-u;for(let p=0;p<h.paints.length;p++)h.parts[p]&&(o=this.bake(o,h.parts[p])),e[h.paints[p]].paint2d(o.getContext("2d"),c,u,f,y);return this.css=h.parts[h.paints.length]||"none",o}tick(){const t=++this.t;if(!(t%ir||!this.live.size))for(const e of this.live)t-e.used>ir&&this.detach(e)}destroy(){for(const t of this.live)this.detach(t);this.plans.clear()}svg(t){if(typeof document>"u"||!document.body)return null;const e=Array.from({length:20},(i,n)=>t[n]??0).join(" ");let s=this.svgs.get(e);if(!s){const i="http://www.w3.org/2000/svg",n=document.createElementNS(i,"svg");n.setAttribute("width","0"),n.setAttribute("height","0"),n.setAttribute("aria-hidden","true"),n.style.position="absolute";const r=document.createElementNS(i,"filter"),a=tl+ ++Jo;r.setAttribute("id",a),r.setAttribute("color-interpolation-filters","sRGB");const l=document.createElementNS(i,"feColorMatrix");l.setAttribute("type","matrix"),l.setAttribute("values",e),r.append(l),n.append(r),this.attach(s={key:e,id:a,el:n,used:this.t})}return this.cur.svgs.push(s),`url(#${s.id})`}attach(t){document.body.append(t.el),this.live.add(t),this.svgs.has(t.key)||this.svgs.set(t.key,t)}detach(t){t.el.remove(),t.used=-1,this.live.delete(t),this.svgs.get(t.key)===t&&this.svgs.delete(t.key)}plan(t){const e=this.r,s=this.cur={parts:[],paints:[],skip:0,svgs:[]};let i="";for(let n=0;n<t.length;n++){const r=t[n];if(!r.enabled)continue;if(r.kind===$s){s.skip++,rr("shader","[engine] shader() filters are WebGL only: on Canvas 2D they are skipped (check engine.supports.shaders)");continue}const a=e.support.filters&&r.css?r.css(e.scale,e.maxBlur,this.svgFn):null;a!==null?i+=i?` ${a}`:a:r.paint2d?(s.parts.push(i),s.paints.push(n),i=""):(s.skip++,rr("css","[engine] this browser's Canvas 2D has no ctx.filter: colour filters, blur and shadows are skipped (tint works; check engine.supports.filters)"))}return s.parts.push(i),s}bake(t,e){const s=this.r,i=this.flip^=1;let n=this.scr[i];(!n||n.width!==s.canvas.width||n.height!==s.canvas.height)&&(n=this.scr[i]=document.createElement("canvas"),n.width=s.canvas.width,n.height=s.canvas.height);const r=n.getContext("2d"),a=s.rx0,l=s.ry0,h=s.rx1-a,o=s.ry1-l;return r.clearRect(a,l,h,o),r.filter=e,r.drawImage(t,a,l,h,o,a,l,h,o),r.filter="none",n}},il=64,Es=17,nl=t=>`${ai}
49
49
  uniform sampler2D uTexture;
50
50
  uniform mat4 uM[${t}];
51
51
  uniform vec4 uO[${t}];
@@ -61,11 +61,11 @@ void main() {
61
61
  }
62
62
  c.rgb *= c.a;
63
63
  gl_FragColor = c * vColor;
64
- }`,$o=()=>`${si}
64
+ }`,rl=()=>`${ai}
65
65
  uniform sampler2D uTexture;
66
66
  uniform vec2 uDir;
67
67
  uniform vec2 uOff;
68
- uniform vec2 uTaps[${bs}];
68
+ uniform vec2 uTaps[${Es}];
69
69
  uniform int uN;
70
70
  uniform float uMode;
71
71
  uniform vec4 uShadow;
@@ -74,15 +74,15 @@ varying vec4 vColor;
74
74
  void main() {
75
75
  vec2 p = vUv + uOff;
76
76
  vec4 c = texture2D(uTexture, p) * uTaps[0].y;
77
- for (int i = 1; i < ${bs}; i++) {
77
+ for (int i = 1; i < ${Es}; i++) {
78
78
  if (i >= uN) break;
79
79
  vec2 d = uDir * uTaps[i].x;
80
80
  c += (texture2D(uTexture, p + d) + texture2D(uTexture, p - d)) * uTaps[i].y;
81
81
  }
82
82
  if (uMode > 0.5) c = uShadow * c.a;
83
83
  gl_FragColor = c * vColor;
84
- }`;function qo(t,e,s=new Float32Array(20)){for(let i=0;i<4;i++)for(let n=0;n<5;n++){let r=n===4?e[i*5+4]:0;for(let a=0;a<4;a++)r+=e[i*5+a]*t[a*5+n];s[i*5+n]=r}return t.set(s),t}var Wo=t=>new Yo(t),Yo=class{constructor(t){d(this,"r",t),d(this,"colorProg",null),d(this,"blurProg",null),d(this,"user",new Map),d(this,"uses",0),d(this,"userErr",new Map),d(this,"scratchT",new Map),d(this,"steps",[]),d(this,"mats",[]),d(this,"counts",[]),d(this,"colorN"),d(this,"fm",new Float32Array(20)),d(this,"fm2",new Float32Array(20)),d(this,"fm3",new Float32Array(20)),d(this,"m16"),d(this,"o4"),d(this,"taps",new Float32Array(bs*2));const e=t.gl;this.colorN=Math.max(1,Math.min(8,Math.floor((e.getParameter(e.MAX_FRAGMENT_UNIFORM_VECTORS)-4)/5))),this.m16=new Float32Array(16*this.colorN),this.o4=new Float32Array(4*this.colorN)}check(t){return this.r.lost?null:(this.userProg(t,!1),this.userErr.get(t)??null)}destroy(){const t=this.r.gl;for(const e of this.scratchT.values())t.deleteTexture(e.gl),t.deleteFramebuffer(e.fb);this.scratchT.clear();for(const e of[this.colorProg,this.blurProg])e&&t.deleteProgram(e.p);for(const e of this.user.values())e.p&&t.deleteProgram(e.p.p);this.user.clear()}userProg(t,e){const s=this.user,i=s.get(t);if(i)return i.t=++this.uses,i.p;if(this.r.lost)return null;if(s.size>=Ho){let r="",a=1/0;for(const[h,o]of s)o.t<a&&(a=o.t,r=h);const l=s.get(r).p;l&&this.r.gl.deleteProgram(l.p),s.delete(r),this.userErr.delete(r)}let n;try{n=this.r.build(t)}catch(r){n=null;const a=r.message;this.userErr.set(t,a),e&&console.error(`[engine] a shader filter does not compile: it is skipped.
85
- ${a}`)}return s.set(t,{p:n,t:++this.uses}),n}scratch(t,e){const s=this.r,i=Math.ceil(s.canvas.width/t),n=Math.ceil(s.canvas.height/t),r=t*8+e;let a=this.scratchT.get(r)??null;return a&&(a.w!==i||a.h!==n)&&(s.drop(a),a=null),a||(a=s.target(i,n,t,!0),a?this.scratchT.set(r,a):this.scratchT.delete(r)),a}pass(t,e,s,i,n=!1){const r=this.r,a=r.gl;r.flush(),r.mapped=!1,r.bindFb(i),a.viewport(0,0,i.w,i.h),n||(a.disable(a.SCISSOR_TEST),a.clearColor(0,0,0,0),a.clear(a.COLOR_BUFFER_BIT)),r.use(t);const l=i.f;a.uniform2f(t.uScale,2/(l*i.w),-2/(l*i.h));const h=Math.floor(r.rx0/l)*l,o=Math.floor(r.ry0/l)*l,f=Math.min(Math.ceil(r.rx1/l),i.w)*l,u=Math.min(Math.ceil(r.ry1/l),i.h)*l,c=1/(s*e.width),y=1/(s*e.height);r.bScis=!1,r.batch.push(h,o,f,o,f,u,h,u,h*c,1-o*y,f*c,1-u*y,4294967295,r.slotOf(e)),r.flush()}post(t){return t==="color"?this.colorProg??(this.colorProg=this.r.build(Xo(this.colorN))):this.blurProg??(this.blurProg=this.r.build($o()))}linear(t,e){const s=this.r,i=s.gl;s.bindTex(s.layerTex.get(t)??null,0);const n=e?i.LINEAR:i.NEAREST;i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MIN_FILTER,n),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MAG_FILTER,n)}chain(t,e,s){const i=this.r,n=this.steps,r=i.scale,a=i.maxBlur;let l=0;for(let u=0;u<s.length;u++){const c=s[u];if(c.enabled)if(c.kind===zs&&c.toMatrix){(!l||n[l-1]!==null)&&(n[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++);const y=this.mats[l-1],p=this.counts[l-1];if(p<this.colorN)c.toMatrix(this.fm),y.set(this.fm,p*20),this.counts[l-1]=p+1;else{const x=(p-1)*20;for(let m=0;m<20;m++)this.fm2[m]=y[x+m];c.toMatrix(this.fm),qo(this.fm2,this.fm,this.fm3),y.set(this.fm2,x)}}else c.kind===Us?this.userProg(c.source,!0)?n[l++]=c:i.skipped++:c.kind===Ds?Math.min(c.radius,a)*r>=.25&&(n[l++]=c):c.kind===Bs?n[l++]=c:i.skipped++}if(!l)return!1;const h=i.gl;let o=t,f=-1;for(let u=0;u<l;u++){const c=u===l-1,y=f===0?1:0,p=c?null:this.scratch(1,y);if(!c&&!p)break;const x=n[u];if(x===null){const m=this.post("color");i.use(m);const g=this.mats[u],k=this.counts[u],E=this.m16,w=this.o4;for(let A=0;A<k;A++)for(let C=0;C<4;C++){for(let R=0;R<4;R++)E[A*16+R*4+C]=g[A*20+C*5+R];w[A*4+C]=g[A*20+C*5+4]}h.uniformMatrix4fv(i.u(m,"uM"),!1,E),h.uniform4fv(i.u(m,"uO"),w),h.uniform1i(i.u(m,"uK"),k),p?this.pass(m,o,1,p):i.final(m,o,1,e)}else if(x.kind===Ds)this.blur(o,f<0,Math.min(x.radius,a)*r,p,e,null);else if(x.kind===Bs){const m=x,g=this.scratch(1,2);if(!g)break;this.blur(o,f<0,Math.max(Math.min(m.blur,a),0)*r,g,1,m);const k=p??(e<1?this.scratch(1,y):null);k?(this.pass(i.main,g.tex,1,k),this.pass(i.main,o,1,k,!0),p||i.final(i.main,k.tex,1,e)):(i.final(i.main,g.tex,1,1),i.final(i.main,o,1,1))}else{const m=x,g=this.userProg(m.source,!0);i.use(g);const k=i.canvas.width,E=i.canvas.height;h.uniform2f(i.u(g,"uResolution"),k,E),h.uniform1f(i.u(g,"uTime"),i.time),h.uniform4f(i.u(g,"uRect"),i.rx0/k,1-i.ry1/E,i.rx1/k,1-i.ry0/E);const w=m.uniforms;for(const A in w){const C=i.u(g,A);if(!C)continue;const R=w[A];typeof R=="number"?h.uniform1f(C,R):R.length===2?h.uniform2fv(C,R):R.length===3?h.uniform3fv(C,R):R.length===4?h.uniform4fv(C,R):R.length===1&&h.uniform1fv(C,R)}p?this.pass(g,o,1,p):i.final(g,o,1,e)}p&&(o=p.tex,f=y)}return i.remap(),!0}blur(t,e,s,i,n,r){const a=this.r,l=a.gl,h=this.post("blur");let o=1;for(;o<16&&s/o>8;)o*=2;e&&this.linear(t,!0);let f=t,u=1;const c=Math.sqrt(Math.max(s*s-(o*o-1)/12,0))/o,y=s>=.25?this.tapsFor(c):this.tapsFor(0);let p=!0;if(y>1){for(let m=2;m<=o&&p;m*=2){const g=this.scratch(m,0);g?(this.pass(a.main,f,u,g),f=g.tex,u=m):p=!1}const x=p?this.scratch(o,3):null;x&&(a.use(h),l.uniform2fv(a.u(h,"uTaps"),this.taps),l.uniform1i(a.u(h,"uN"),y),l.uniform2f(a.u(h,"uDir"),1/f.width,0),l.uniform2f(a.u(h,"uOff"),0,0),l.uniform1f(a.u(h,"uMode"),0),this.pass(h,f,u,x),f=x.tex)}if(a.use(h),l.uniform2fv(a.u(h,"uTaps"),this.taps),l.uniform1i(a.u(h,"uN"),y),l.uniform2f(a.u(h,"uDir"),0,1/f.height),r){const x=r.opacity,m=r.rgb;l.uniform4f(a.u(h,"uShadow"),(m>>16&255)/255*x,(m>>8&255)/255*x,(m&255)/255*x,x),l.uniform1f(a.u(h,"uMode"),1),l.uniform2f(a.u(h,"uOff"),-r.dx*a.scale/(u*f.width),r.dy*a.scale/(u*f.height))}else l.uniform1f(a.u(h,"uMode"),0),l.uniform2f(a.u(h,"uOff"),0,0);i?this.pass(h,f,u,i):a.final(h,f,u,n),e&&this.linear(t,!1)}tapsFor(t){const e=this.taps;if(e.fill(0),e[1]=1,t<.2)return 1;const s=Math.min(Math.ceil(3*t),(bs-1)*2),i=-1/(2*t*t);let n=1,r=1;for(let a=1;a<=s;a+=2){const l=Math.exp(a*a*i),h=a+1<=s?Math.exp((a+1)*(a+1)*i):0,o=l+h;e[r*2]=(a*l+(a+1)*h)/o,e[r*2+1]=o,n+=2*o,r++}for(let a=0;a<r;a++)e[a*2+1]=e[a*2+1]/n;return r}},Wt=t=>Math.min(Math.max(t,0),1),Lt=t=>Math.max(t,0),$e=class{constructor(){d(this,"enabled",!0),Gt.gl=Wo,Gt.c2d=Uo}},ie=class extends $e{constructor(t){super(),d(this,"amount",t),d(this,"kind",zs)}params(t,e){return t[e]=this.amount,e+1}};function ks(t,e,s){t.fill(0),t[0]=t[6]=t[12]=e,t[4]=t[9]=t[14]=s,t[18]=1}function ws(t,e){t.fill(0);for(let s=0;s<3;s++)for(let i=0;i<3;i++)t[s*5+i]=e[s*3+i];t[18]=1}var z=new Float64Array(9),Qo=class extends ie{toMatrix(t){ks(t,Lt(this.amount),0)}css(){return`brightness(${Lt(this.amount)})`}},jo=class extends ie{toMatrix(t){const e=Lt(this.amount);ks(t,e,.5-.5*e)}css(){return`contrast(${Lt(this.amount)})`}},Vo=class extends ie{toMatrix(t){const e=Wt(this.amount);ks(t,1-2*e,e)}css(){return`invert(${Wt(this.amount)})`}},Ko=class extends ie{toMatrix(t){const e=Lt(this.amount);z[0]=.213+.787*e,z[1]=.715-.715*e,z[2]=.072-.072*e,z[3]=.213-.213*e,z[4]=.715+.285*e,z[5]=.072-.072*e,z[6]=.213-.213*e,z[7]=.715-.715*e,z[8]=.072+.928*e,ws(t,z)}css(){return`saturate(${Lt(this.amount)})`}},Zo=class extends ie{toMatrix(t){const e=1-Wt(this.amount);z[0]=.2126+.7874*e,z[1]=.7152-.7152*e,z[2]=.0722-.0722*e,z[3]=.2126-.2126*e,z[4]=.7152+.2848*e,z[5]=.0722-.0722*e,z[6]=.2126-.2126*e,z[7]=.7152-.7152*e,z[8]=.0722+.9278*e,ws(t,z)}css(){return`grayscale(${Wt(this.amount)})`}},Jo=class extends ie{toMatrix(t){const e=1-Wt(this.amount);z[0]=.393+.607*e,z[1]=.769-.769*e,z[2]=.189-.189*e,z[3]=.349-.349*e,z[4]=.686+.314*e,z[5]=.168-.168*e,z[6]=.272-.272*e,z[7]=.534-.534*e,z[8]=.131+.869*e,ws(t,z)}css(){return`sepia(${Wt(this.amount)})`}},tl=class extends ie{get angle(){return this.amount}set angle(t){this.amount=t}toMatrix(t){const e=this.amount*Math.PI/180,s=Math.cos(e),i=Math.sin(e);z[0]=.213+s*.787-i*.213,z[1]=.715-s*.715-i*.715,z[2]=.072-s*.072+i*.928,z[3]=.213-s*.213+i*.143,z[4]=.715+s*.285+i*.14,z[5]=.072-s*.072-i*.283,z[6]=.213-s*.213-i*.787,z[7]=.715-s*.715+i*.715,z[8]=.072+s*.928+i*.072,ws(t,z)}css(){return`hue-rotate(${this.amount}deg)`}},el=class extends ie{constructor(t,e){super(e),d(this,"c",16777215),d(this,"cs",""),this.color=t}get color(){return this.c}set color(t){this.c=Ut(t)[0],this.cs=Ne(this.c)}params(t,e){return t[e]=this.amount,t[e+1]=this.c,e+2}toMatrix(t){const e=Wt(this.amount);ks(t,1-e,0),t[4]=(this.c>>16&255)/255*e,t[9]=(this.c>>8&255)/255*e,t[14]=(this.c&255)/255*e}css(){return null}paint2d(t,e,s,i,n){const r=Wt(this.amount);r<=0||(t.save(),t.setTransform(1,0,0,1,0,0),t.globalAlpha=r,t.globalCompositeOperation="source-atop",t.fillStyle=this.cs,t.fillRect(e,s,i,n),t.restore())}},sl=class extends $e{constructor(t){if(super(),d(this,"kind",zs),d(this,"values"),t.length!==20)throw new Error(`colorMatrix: 20 numbers expected (4 rows of 5), got ${t.length}`);this.values=Array.from(t)}toMatrix(t){for(let e=0;e<20;e++)t[e]=this.values[e]??0}params(t,e){for(let s=0;s<20;s++)t[e+s]=this.values[s]??0;return e+20}css(t,e,s){return s?s(this.values):null}},il=class extends $e{constructor(t){super(),d(this,"radius",t),d(this,"kind",Ds)}params(t,e){return t[e]=this.radius,e+1}pad(t){return 3*Math.min(Lt(this.radius),t)}css(t,e){return`blur(${Math.min(Lt(this.radius),e)*t}px)`}},nl=class extends $e{constructor(t,e,s,i){super(),d(this,"dx",t),d(this,"dy",e),d(this,"blur",s),d(this,"kind",Bs),d(this,"rgb",0),d(this,"a",1),this.color=i}get opacity(){return this.a}set opacity(t){this.a=Wt(t)}get color(){return this.rgb}set color(t){const[e,s]=Ut(t);this.rgb=e,this.a=s}params(t,e){return t[e]=this.dx,t[e+1]=this.dy,t[e+2]=this.blur,t[e+3]=this.rgb,t[e+4]=this.a,e+5}pad(t){return 3*Math.min(Lt(this.blur),t)+Math.max(Math.abs(this.dx),Math.abs(this.dy))}css(t,e){return`drop-shadow(${this.dx*t}px ${this.dy*t}px ${2*Math.min(Lt(this.blur),e)*t}px ${Ne(this.rgb,this.opacity)})`}},rl=`#ifdef GL_FRAGMENT_PRECISION_HIGH
84
+ }`;function al(t,e,s=new Float32Array(20)){for(let i=0;i<4;i++)for(let n=0;n<5;n++){let r=n===4?e[i*5+4]:0;for(let a=0;a<4;a++)r+=e[i*5+a]*t[a*5+n];s[i*5+n]=r}return t.set(s),t}var ol=t=>new ll(t),ll=class{constructor(t){d(this,"r",t),d(this,"colorProg",null),d(this,"blurProg",null),d(this,"user",new Map),d(this,"uses",0),d(this,"userErr",new Map),d(this,"scratchT",new Map),d(this,"steps",[]),d(this,"mats",[]),d(this,"counts",[]),d(this,"colorN"),d(this,"fm",new Float32Array(20)),d(this,"fm2",new Float32Array(20)),d(this,"fm3",new Float32Array(20)),d(this,"m16"),d(this,"o4"),d(this,"taps",new Float32Array(Es*2));const e=t.gl;this.colorN=Math.max(1,Math.min(8,Math.floor((e.getParameter(e.MAX_FRAGMENT_UNIFORM_VECTORS)-4)/5))),this.m16=new Float32Array(16*this.colorN),this.o4=new Float32Array(4*this.colorN)}check(t){return this.r.lost?null:(this.userProg(t,!1),this.userErr.get(t)??null)}destroy(){const t=this.r.gl;for(const e of this.scratchT.values())t.deleteTexture(e.gl),t.deleteFramebuffer(e.fb);this.scratchT.clear();for(const e of[this.colorProg,this.blurProg])e&&t.deleteProgram(e.p);for(const e of this.user.values())e.p&&t.deleteProgram(e.p.p);this.user.clear()}userProg(t,e){const s=this.user,i=s.get(t);if(i)return i.t=++this.uses,i.p;if(this.r.lost)return null;if(s.size>=il){let r="",a=1/0;for(const[h,o]of s)o.t<a&&(a=o.t,r=h);const l=s.get(r).p;l&&this.r.gl.deleteProgram(l.p),s.delete(r),this.userErr.delete(r)}let n;try{n=this.r.build(t)}catch(r){n=null;const a=r.message;this.userErr.set(t,a),e&&console.error(`[engine] a shader filter does not compile: it is skipped.
85
+ ${a}`)}return s.set(t,{p:n,t:++this.uses}),n}scratch(t,e){const s=this.r,i=Math.ceil(s.canvas.width/t),n=Math.ceil(s.canvas.height/t),r=t*8+e;let a=this.scratchT.get(r)??null;return a&&(a.w!==i||a.h!==n)&&(s.drop(a),a=null),a||(a=s.target(i,n,t,!0),a?this.scratchT.set(r,a):this.scratchT.delete(r)),a}pass(t,e,s,i,n=!1){const r=this.r,a=r.gl;r.flush(),r.mapped=!1,r.bindFb(i),a.viewport(0,0,i.w,i.h),n||(a.disable(a.SCISSOR_TEST),a.clearColor(0,0,0,0),a.clear(a.COLOR_BUFFER_BIT)),r.use(t);const l=i.f;a.uniform2f(t.uScale,2/(l*i.w),-2/(l*i.h));const h=Math.floor(r.rx0/l)*l,o=Math.floor(r.ry0/l)*l,c=Math.min(Math.ceil(r.rx1/l),i.w)*l,u=Math.min(Math.ceil(r.ry1/l),i.h)*l,f=1/(s*e.width),y=1/(s*e.height);r.bScis=!1,r.batch.push(h,o,c,o,c,u,h,u,h*f,1-o*y,c*f,1-u*y,4294967295,r.slotOf(e)),r.flush()}post(t){return t==="color"?this.colorProg??(this.colorProg=this.r.build(nl(this.colorN))):this.blurProg??(this.blurProg=this.r.build(rl()))}linear(t,e){const s=this.r,i=s.gl;s.bindTex(s.layerTex.get(t)??null,0);const n=e?i.LINEAR:i.NEAREST;i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MIN_FILTER,n),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MAG_FILTER,n)}chain(t,e,s){const i=this.r,n=this.steps,r=i.scale,a=i.maxBlur;let l=0;for(let u=0;u<s.length;u++){const f=s[u];if(f.enabled)if(f.kind===Hs&&f.toMatrix){(!l||n[l-1]!==null)&&(n[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++);const y=this.mats[l-1],p=this.counts[l-1];if(p<this.colorN)f.toMatrix(this.fm),y.set(this.fm,p*20),this.counts[l-1]=p+1;else{const x=(p-1)*20;for(let m=0;m<20;m++)this.fm2[m]=y[x+m];f.toMatrix(this.fm),al(this.fm2,this.fm,this.fm3),y.set(this.fm2,x)}}else f.kind===$s?this.userProg(f.source,!0)?n[l++]=f:i.skipped++:f.kind===Gs?Math.min(f.radius,a)*r>=.25&&(n[l++]=f):f.kind===Xs?n[l++]=f:i.skipped++}if(!l)return!1;const h=i.gl;let o=t,c=-1;for(let u=0;u<l;u++){const f=u===l-1,y=c===0?1:0,p=f?null:this.scratch(1,y);if(!f&&!p)break;const x=n[u];if(x===null){const m=this.post("color");i.use(m);const g=this.mats[u],k=this.counts[u],E=this.m16,w=this.o4;for(let A=0;A<k;A++)for(let C=0;C<4;C++){for(let R=0;R<4;R++)E[A*16+R*4+C]=g[A*20+C*5+R];w[A*4+C]=g[A*20+C*5+4]}h.uniformMatrix4fv(i.u(m,"uM"),!1,E),h.uniform4fv(i.u(m,"uO"),w),h.uniform1i(i.u(m,"uK"),k),p?this.pass(m,o,1,p):i.final(m,o,1,e)}else if(x.kind===Gs)this.blur(o,c<0,Math.min(x.radius,a)*r,p,e,null);else if(x.kind===Xs){const m=x,g=this.scratch(1,2);if(!g)break;this.blur(o,c<0,Math.max(Math.min(m.blur,a),0)*r,g,1,m);const k=p??(e<1?this.scratch(1,y):null);k?(this.pass(i.main,g.tex,1,k),this.pass(i.main,o,1,k,!0),p||i.final(i.main,k.tex,1,e)):(i.final(i.main,g.tex,1,1),i.final(i.main,o,1,1))}else{const m=x,g=this.userProg(m.source,!0);i.use(g);const k=i.canvas.width,E=i.canvas.height;h.uniform2f(i.u(g,"uResolution"),k,E),h.uniform1f(i.u(g,"uTime"),i.time),h.uniform4f(i.u(g,"uRect"),i.rx0/k,1-i.ry1/E,i.rx1/k,1-i.ry0/E);const w=m.uniforms;for(const A in w){const C=i.u(g,A);if(!C)continue;const R=w[A];typeof R=="number"?h.uniform1f(C,R):R.length===2?h.uniform2fv(C,R):R.length===3?h.uniform3fv(C,R):R.length===4?h.uniform4fv(C,R):R.length===1&&h.uniform1fv(C,R)}p?this.pass(g,o,1,p):i.final(g,o,1,e)}p&&(o=p.tex,c=y)}return i.remap(),!0}blur(t,e,s,i,n,r){const a=this.r,l=a.gl,h=this.post("blur");let o=1;for(;o<16&&s/o>8;)o*=2;e&&this.linear(t,!0);let c=t,u=1;const f=Math.sqrt(Math.max(s*s-(o*o-1)/12,0))/o,y=s>=.25?this.tapsFor(f):this.tapsFor(0);let p=!0;if(y>1){for(let m=2;m<=o&&p;m*=2){const g=this.scratch(m,0);g?(this.pass(a.main,c,u,g),c=g.tex,u=m):p=!1}const x=p?this.scratch(o,3):null;x&&(a.use(h),l.uniform2fv(a.u(h,"uTaps"),this.taps),l.uniform1i(a.u(h,"uN"),y),l.uniform2f(a.u(h,"uDir"),1/c.width,0),l.uniform2f(a.u(h,"uOff"),0,0),l.uniform1f(a.u(h,"uMode"),0),this.pass(h,c,u,x),c=x.tex)}if(a.use(h),l.uniform2fv(a.u(h,"uTaps"),this.taps),l.uniform1i(a.u(h,"uN"),y),l.uniform2f(a.u(h,"uDir"),0,1/c.height),r){const x=r.opacity,m=r.rgb;l.uniform4f(a.u(h,"uShadow"),(m>>16&255)/255*x,(m>>8&255)/255*x,(m&255)/255*x,x),l.uniform1f(a.u(h,"uMode"),1),l.uniform2f(a.u(h,"uOff"),-r.dx*a.scale/(u*c.width),r.dy*a.scale/(u*c.height))}else l.uniform1f(a.u(h,"uMode"),0),l.uniform2f(a.u(h,"uOff"),0,0);i?this.pass(h,c,u,i):a.final(h,c,u,n),e&&this.linear(t,!1)}tapsFor(t){const e=this.taps;if(e.fill(0),e[1]=1,t<.2)return 1;const s=Math.min(Math.ceil(3*t),(Es-1)*2),i=-1/(2*t*t);let n=1,r=1;for(let a=1;a<=s;a+=2){const l=Math.exp(a*a*i),h=a+1<=s?Math.exp((a+1)*(a+1)*i):0,o=l+h;e[r*2]=(a*l+(a+1)*h)/o,e[r*2+1]=o,n+=2*o,r++}for(let a=0;a<r;a++)e[a*2+1]=e[a*2+1]/n;return r}},Yt=t=>Math.min(Math.max(t,0),1),Nt=t=>Math.max(t,0),We=class{constructor(){d(this,"enabled",!0),Ut.gl=ol,Ut.c2d=el}},ne=class extends We{constructor(t){super(),d(this,"amount",t),d(this,"kind",Hs)}params(t,e){return t[e]=this.amount,e+1}};function As(t,e,s){t.fill(0),t[0]=t[6]=t[12]=e,t[4]=t[9]=t[14]=s,t[18]=1}function _s(t,e){t.fill(0);for(let s=0;s<3;s++)for(let i=0;i<3;i++)t[s*5+i]=e[s*3+i];t[18]=1}var z=new Float64Array(9),hl=class extends ne{toMatrix(t){As(t,Nt(this.amount),0)}css(){return`brightness(${Nt(this.amount)})`}},cl=class extends ne{toMatrix(t){const e=Nt(this.amount);As(t,e,.5-.5*e)}css(){return`contrast(${Nt(this.amount)})`}},fl=class extends ne{toMatrix(t){const e=Yt(this.amount);As(t,1-2*e,e)}css(){return`invert(${Yt(this.amount)})`}},ul=class extends ne{toMatrix(t){const e=Nt(this.amount);z[0]=.213+.787*e,z[1]=.715-.715*e,z[2]=.072-.072*e,z[3]=.213-.213*e,z[4]=.715+.285*e,z[5]=.072-.072*e,z[6]=.213-.213*e,z[7]=.715-.715*e,z[8]=.072+.928*e,_s(t,z)}css(){return`saturate(${Nt(this.amount)})`}},dl=class extends ne{toMatrix(t){const e=1-Yt(this.amount);z[0]=.2126+.7874*e,z[1]=.7152-.7152*e,z[2]=.0722-.0722*e,z[3]=.2126-.2126*e,z[4]=.7152+.2848*e,z[5]=.0722-.0722*e,z[6]=.2126-.2126*e,z[7]=.7152-.7152*e,z[8]=.0722+.9278*e,_s(t,z)}css(){return`grayscale(${Yt(this.amount)})`}},pl=class extends ne{toMatrix(t){const e=1-Yt(this.amount);z[0]=.393+.607*e,z[1]=.769-.769*e,z[2]=.189-.189*e,z[3]=.349-.349*e,z[4]=.686+.314*e,z[5]=.168-.168*e,z[6]=.272-.272*e,z[7]=.534-.534*e,z[8]=.131+.869*e,_s(t,z)}css(){return`sepia(${Yt(this.amount)})`}},yl=class extends ne{get angle(){return this.amount}set angle(t){this.amount=t}toMatrix(t){const e=this.amount*Math.PI/180,s=Math.cos(e),i=Math.sin(e);z[0]=.213+s*.787-i*.213,z[1]=.715-s*.715-i*.715,z[2]=.072-s*.072+i*.928,z[3]=.213-s*.213+i*.143,z[4]=.715+s*.285+i*.14,z[5]=.072-s*.072-i*.283,z[6]=.213-s*.213-i*.787,z[7]=.715-s*.715+i*.715,z[8]=.072+s*.928+i*.072,_s(t,z)}css(){return`hue-rotate(${this.amount}deg)`}},ml=class extends ne{constructor(t,e){super(e),d(this,"c",16777215),d(this,"cs",""),this.color=t}get color(){return this.c}set color(t){this.c=Bt(t)[0],this.cs=Oe(this.c)}params(t,e){return t[e]=this.amount,t[e+1]=this.c,e+2}toMatrix(t){const e=Yt(this.amount);As(t,1-e,0),t[4]=(this.c>>16&255)/255*e,t[9]=(this.c>>8&255)/255*e,t[14]=(this.c&255)/255*e}css(){return null}paint2d(t,e,s,i,n){const r=Yt(this.amount);r<=0||(t.save(),t.setTransform(1,0,0,1,0,0),t.globalAlpha=r,t.globalCompositeOperation="source-atop",t.fillStyle=this.cs,t.fillRect(e,s,i,n),t.restore())}},xl=class extends We{constructor(t){if(super(),d(this,"kind",Hs),d(this,"values"),t.length!==20)throw new Error(`colorMatrix: 20 numbers expected (4 rows of 5), got ${t.length}`);this.values=Array.from(t)}toMatrix(t){for(let e=0;e<20;e++)t[e]=this.values[e]??0}params(t,e){for(let s=0;s<20;s++)t[e+s]=this.values[s]??0;return e+20}css(t,e,s){return s?s(this.values):null}},gl=class extends We{constructor(t){super(),d(this,"radius",t),d(this,"kind",Gs)}params(t,e){return t[e]=this.radius,e+1}pad(t){return 3*Math.min(Nt(this.radius),t)}css(t,e){return`blur(${Math.min(Nt(this.radius),e)*t}px)`}},bl=class extends We{constructor(t,e,s,i){super(),d(this,"dx",t),d(this,"dy",e),d(this,"blur",s),d(this,"kind",Xs),d(this,"rgb",0),d(this,"a",1),this.color=i}get opacity(){return this.a}set opacity(t){this.a=Yt(t)}get color(){return this.rgb}set color(t){const[e,s]=Bt(t);this.rgb=e,this.a=s}params(t,e){return t[e]=this.dx,t[e+1]=this.dy,t[e+2]=this.blur,t[e+3]=this.rgb,t[e+4]=this.a,e+5}pad(t){return 3*Math.min(Nt(this.blur),t)+Math.max(Math.abs(this.dx),Math.abs(this.dy))}css(t,e){return`drop-shadow(${this.dx*t}px ${this.dy*t}px ${2*Math.min(Nt(this.blur),e)*t}px ${Oe(this.rgb,this.opacity)})`}},kl=`#ifdef GL_FRAGMENT_PRECISION_HIGH
86
86
  precision highp float;
87
87
  #else
88
88
  precision mediump float;
@@ -95,11 +95,11 @@ varying vec2 vUv;
95
95
  varying vec4 vColor;
96
96
  #define main fabiUserMain
97
97
  #line 1
98
- `,al=t=>`${rl}${t}
98
+ `,wl=t=>`${kl}${t}
99
99
  #undef main
100
100
  void main() {
101
101
  fabiUserMain();
102
102
  gl_FragColor *= vColor.a;
103
103
  }
104
- `,ol=class extends $e{constructor(t){super(),d(this,"kind",Us),d(this,"source"),d(this,"uniforms",{}),d(this,"padding"),this.source=al(t.fragment),this.padding=t.padding??0;for(const e in t.uniforms??{}){const s=t.uniforms[e];this.uniforms[e]=typeof s=="number"?s:Float32Array.from(s)}}pad(){return Lt(this.padding)}},ll=(t,e=1)=>new el(t,e),hl=t=>new Qo(t),cl=t=>new jo(t),fl=t=>new Ko(t),ul=(t=1)=>new Zo(t),dl=(t=1)=>new Jo(t),pl=t=>new tl(t),yl=(t=1)=>new Vo(t),ml=t=>new sl(t),xl=t=>new il(t),gl=(t,e,s,i="rgba(0,0,0,0.5)")=>new nl(t,e,s,i);function bl(t){const e=new ol(t),s=Gt.live?.filters()?.check(e.source);if(s)throw new Error(`shader(): the fragment does not compile:
105
- ${s}`);return e}var ui="x y rotation scaleX scaleY alpha visible blend tint z hitRadius clip mask filters".split(" "),Jn="frameName _frame _w _h slice autoAnchor".split(" "),kl="fps loop speed onComplete durations".split(" "),di=["anchorX","anchorY"],wl=[...ui,...Jn,...kl,...di],vl=[...ui,...Jn,...di],Ml=[...ui,...di],tr=t=>t instanceof ce?wl:t instanceof be?vl:Ml;function El(t){const e={},s=t;for(const i of tr(t))e[i]=s[i];return t instanceof Be&&(e.spec=t.spec),t instanceof Xe&&(e.text=t.text,e.style=t.style),t instanceof ce&&(e.playing=t.playing),e}function er(t,e){const s=t;t instanceof Be&&t.spec!==e.spec&&(t.spec=e.spec),t instanceof Xe&&(t.text=e.text,t.style!==e.style&&(s._style=e.style,s.dirty=!0)),t instanceof ce&&t.gotoFrame(e.speed<0?t.frameCount-1:0);const i=t instanceof Be||t instanceof Xe,n=tr(t);for(let r=0;r<n.length;r++){const a=n[r];(!i||a!=="_frame"&&a!=="frameName")&&(s[a]=e[a])}}var sr=class{constructor(t,e={}){d(this,"factory",t),d(this,"opts",e),d(this,"stats",{live:0,free:0,created:0}),d(this,"free",[]),d(this,"states",new Map),d(this,"dead",!1)}get(t){if(this.dead)throw new Error("[engine] nodePool.get() after destroy()");let e=this.free.pop();if(e){this.stats.free--,e._free=!1;const s=this.states.get(e);er(e,s),e.visible=s.visible,e instanceof ce&&s.playing&&e.play()}else{if(e=this.factory(),!(e instanceof le))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,El(e)),e._pool=this,this.stats.created++}return this.stats.live++,t&&e.set(t),e}release(t){const e=this.states.get(t);if(!(!e||t.destroyed)&&!t._free){if(this.opts.max!==void 0&&this.free.length>=this.opts.max)return t.destroy();t.parent?.remove(t),t.kernel.tweens.stopAll(t),this.stats.live--,er(t,e),t instanceof ce&&t.stop(),t.visible=!1,t._free=!0,this.opts.reset?.(t),this.free.push(t),this.stats.free++}}forget(t){const e=t;if(this.states.delete(e))if(e._free){const s=this.free.indexOf(e);s>=0&&(this.free[s]=this.free[this.free.length-1],this.free.pop()),this.stats.free--}else this.stats.live--}clear(){for(;this.free.length;)this.free[this.free.length-1].destroy()}destroy(){this.dead=!0;for(const t of[...this.states.keys()])t.destroy()}},Al=(t,e)=>new sr(t,e);return ne.exports});
104
+ `,vl=class extends We{constructor(t){super(),d(this,"kind",$s),d(this,"source"),d(this,"uniforms",{}),d(this,"padding"),this.source=wl(t.fragment),this.padding=t.padding??0;for(const e in t.uniforms??{}){const s=t.uniforms[e];this.uniforms[e]=typeof s=="number"?s:Float32Array.from(s)}}pad(){return Nt(this.padding)}},Ml=(t,e=1)=>new ml(t,e),El=t=>new hl(t),Al=t=>new cl(t),_l=t=>new ul(t),Sl=(t=1)=>new dl(t),Tl=(t=1)=>new pl(t),Cl=t=>new yl(t),Rl=(t=1)=>new fl(t),Fl=t=>new xl(t),Pl=t=>new gl(t),Ll=(t,e,s,i="rgba(0,0,0,0.5)")=>new bl(t,e,s,i);function Nl(t){const e=new vl(t),s=Ut.live?.filters()?.check(e.source);if(s)throw new Error(`shader(): the fragment does not compile:
105
+ ${s}`);return e}var yi="x y rotation scaleX scaleY alpha visible blend tint z hitRadius clip mask filters".split(" "),ar="frameName _frame _w _h slice autoAnchor".split(" "),Il="fps loop speed onComplete durations".split(" "),mi=["anchorX","anchorY"],Ol=[...yi,...ar,...Il,...mi],zl=[...yi,...ar,...mi],Dl=[...yi,...mi],or=t=>t instanceof fe?Ol:t instanceof we?zl:Dl;function Bl(t){const e={},s=t;for(const i of or(t))e[i]=s[i];return t instanceof He&&(e.spec=t.spec),t instanceof qe&&(e.text=t.text,e.style=t.style),t instanceof fe&&(e.playing=t.playing),e}function lr(t,e){const s=t;t instanceof He&&t.spec!==e.spec&&(t.spec=e.spec),t instanceof qe&&(t.text=e.text,t.style!==e.style&&(s._style=e.style,s.dirty=!0)),t instanceof fe&&t.gotoFrame(e.speed<0?t.frameCount-1:0);const i=t instanceof He||t instanceof qe,n=or(t);for(let r=0;r<n.length;r++){const a=n[r];(!i||a!=="_frame"&&a!=="frameName")&&(s[a]=e[a])}}var hr=class{constructor(t,e={}){d(this,"factory",t),d(this,"opts",e),d(this,"stats",{live:0,free:0,created:0}),d(this,"free",[]),d(this,"states",new Map),d(this,"dead",!1)}get(t){if(this.dead)throw new Error("[engine] nodePool.get() after destroy()");let e=this.free.pop();if(e){this.stats.free--,e._free=!1;const s=this.states.get(e);lr(e,s),e.visible=s.visible,e instanceof fe&&s.playing&&e.play()}else{if(e=this.factory(),!(e instanceof he))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,Bl(e)),e._pool=this,this.stats.created++}return this.stats.live++,t&&e.set(t),e}release(t){const e=this.states.get(t);if(!(!e||t.destroyed)&&!t._free){if(this.opts.max!==void 0&&this.free.length>=this.opts.max)return t.destroy();t.parent?.remove(t),t.kernel.tweens.stopAll(t),this.stats.live--,lr(t,e),t instanceof fe&&t.stop(),t.visible=!1,t._free=!0,this.opts.reset?.(t),this.free.push(t),this.stats.free++}}forget(t){const e=t;if(this.states.delete(e))if(e._free){const s=this.free.indexOf(e);s>=0&&(this.free[s]=this.free[this.free.length-1],this.free.pop()),this.stats.free--}else this.stats.live--}clear(){for(;this.free.length;)this.free[this.free.length-1].destroy()}destroy(){this.dead=!0;for(const t of[...this.states.keys()])t.destroy()}},Ul=(t,e)=>new hr(t,e);return re.exports});