@fabi-play/engine 0.2.0 → 0.4.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.
- package/dist/fabi-play-engine.d.ts +17 -9
- package/dist/fabi-play-engine.js +13 -13
- package/dist/fabi-play-engine.lite.d.ts +17 -9
- package/dist/fabi-play-engine.lite.js +5 -5
- package/dist/fabi-play-engine.lite.umd.js +5 -1
- package/dist/fabi-play-engine.lite.umd.min.js +2 -2
- package/dist/fabi-play-engine.umd.js +267 -25
- package/dist/fabi-play-engine.umd.min.js +13 -13
- package/dist/index.d.ts +17 -9
- package/dist/index.development.js +4 -0
- package/dist/index.js +5 -5
- package/dist/integrity.json +9 -9
- package/package.json +5 -5
package/dist/fabi-play-engine.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
"use strict";(()=>{var Ss=Object.defineProperty;var Fa=(s,n,e)=>n in s?Ss(s,n,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[n]=e;var Ca=(s,n)=>{for(var e in n)Ss(s,e,{get:n[e],enumerable:!0})};var p=(s,n,e)=>Fa(s,typeof n!="symbol"?n+"":n,e);var bs={};Ca(bs,{AnimatedSprite:()=>Ce,Atlas:()=>at,AvatarPainter:()=>wt,AvatarsNode:()=>Tn,BitmapFont:()=>jt,DEFAULT_FONT:()=>Ir,EASE:()=>st,Group:()=>vt,HALO:()=>At,MAX_LAYERS:()=>pn,NameTags:()=>ct,Node:()=>Fe,NodePool:()=>En,Particles:()=>Ot,STAGE_HEIGHT:()=>ae,Shape:()=>$e,ShelfPacker:()=>yn,Sound:()=>Kt,Sprite:()=>Se,TIERS:()=>Ve,Text:()=>We,Timeline:()=>Qt,Tweens:()=>Zt,avatarPortrait:()=>Io,blur:()=>ma,brightness:()=>ia,colorMatrix:()=>da,contrast:()=>la,createAvatarRenderer:()=>Oo,createEngine:()=>ea,createRenderer:()=>Vt,dropShadow:()=>ba,grayscale:()=>ua,handsOf:()=>nr,hits:()=>Sn,hueRotate:()=>fa,invert:()=>pa,nodePool:()=>va,packColor:()=>rt,parseBMFont:()=>Yt,parseColor:()=>he,pickTier:()=>or,playerColor:()=>An,rendererOrder:()=>Or,rng:()=>Ys,saturate:()=>ca,sepia:()=>ha,shader:()=>ya,shapeBounds:()=>er,tier:()=>et,tint:()=>aa,touching:()=>rr,wrists:()=>Hr});var br=33,Y={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},Ms=["3-5","6-8","9-12"],_a=s=>Ms.includes(s);var Pa=4,sn=["#EE6A43","#6FA0E0","#8CC9A0","#C49BE0"];var Ts={"3-5":["bunny","bear","panda","penguin"],"6-8":["fox","lion","dragon","unicorn"],"9-12":["robot","astronaut","ninja","skater"]},La=Ts["6-8"],yr=(s,n)=>{let e=_a(n)?Ts[n]:La;return e[Number.isInteger(s)&&s>=0?s%e.length:0]};var Es=(s,n)=>s?{x:s.x+n.x*s.w,y:s.y+n.y*s.h}:{x:n.x,y:n.y};var Na=12,Ba=br*4,Da=s=>Na+s*Ba,ul=Da(Pa);var Oa=s=>s.startsWith("fabi-play.")?`fablee-play.${s.slice(10)}`:null;function Rs(s,n,e=Oa(n)){if(!(!s||!e))try{let t=s.getItem(e);if(t===null)return;s.getItem(n)===null&&s.setItem(n,t),s.removeItem(e)}catch{}}var ve="#4a382c",de="#2b2118",Re="#1c1f2b",Fs="#fbefe3",Ne="#f4897a",on="#3a2a22",xr=[{id:"fox",name:{en:"Fox",it:"Volpe"},band:"6-8",palette:{body:"#ee6a43",limbs:"#ee6a43",belly:Fs,accent:"#ffd9c2",outline:de,hands:"#5a3426",feet:"#5a3426"},head:"wide",ears:"pointy",face:{eyes:"dot",mouth:"cat",nose:on,muzzle:"cheeks"},tail:"fluffy",headExtras:[],bodyExtras:[]},{id:"mascot",name:{en:"Fabi",it:"Fabi"},band:"all",special:!0,palette:{body:"#ee6a43",limbs:"#ee6a43",belly:Fs,accent:"#5a3426",outline:de,hands:"#5a3426",feet:"#5a3426"},head:"wide",ears:"pointy",face:{eyes:"bead",mouth:"open",nose:on,muzzle:"band",cheeks:Ne},tail:"brush",headExtras:[],bodyExtras:["star"],extraColors:["#ffd84a"]},{id:"bunny",name:{en:"Bunny",it:"Coniglietto"},band:"3-5",palette:{body:"#f9d0de",limbs:"#f9d0de",belly:"#fff6f8",accent:"#f4a0b9",outline:ve},head:"round",ears:"long",face:{eyes:"dot",mouth:"cat",nose:"#e0607e",muzzle:"none",cheeks:Ne},tail:"pom",headExtras:[],bodyExtras:[]},{id:"bear",name:{en:"Bear",it:"Orsetto"},band:"3-5",palette:{body:"#cf9f78",limbs:"#cf9f78",belly:"#f7e0bf",accent:"#f7e0bf",outline:ve},head:"round",ears:"round",face:{eyes:"dot",mouth:"smile",nose:on,muzzle:"oval",cheeks:Ne},tail:"none",headExtras:[],bodyExtras:[]},{id:"cat",name:{en:"Cat",it:"Gattino"},band:"3-5",palette:{body:"#c8b6ee",limbs:"#c8b6ee",belly:"#f4eeff",accent:"#f7b3c8",outline:ve,hands:"#f4eeff",feet:"#f4eeff"},head:"wide",ears:"pointy",face:{eyes:"big",eyeColor:"#3f9a5a",mouth:"cat",nose:"#f07a9a",muzzle:"none",cheeks:Ne},tail:"long",headExtras:["whiskers"],bodyExtras:[]},{id:"panda",name:{en:"Panda",it:"Panda"},band:"3-5",palette:{body:"#ffffff",limbs:"#6e6674",belly:"#ffffff",accent:"#6e6674",outline:ve,ears:"#6e6674"},head:"wide",ears:"round",face:{eyes:"mask",mouth:"smile",nose:"#2f2a2c",muzzle:"none",cheeks:"#f6a3a3"},tail:"none",headExtras:[],bodyExtras:[]},{id:"penguin",name:{en:"Penguin",it:"Pinguino"},band:"3-5",palette:{body:"#6c8fca",limbs:"#6c8fca",belly:"#ffffff",accent:"#f9b95c",outline:ve,feet:"#f9b95c"},head:"tall",ears:"none",face:{eyes:"dot",mouth:"beak",muzzle:"heart",cheeks:"#f6a3a3"},tail:"none",headExtras:[],bodyExtras:["flippers","scarf"],extraColors:["#f6907a"]},{id:"frog",name:{en:"Frog",it:"Ranocchio"},band:"3-5",palette:{body:"#8fd487",limbs:"#8fd487",belly:"#e6f7cc",accent:"#62ad62",outline:ve},head:"wide",ears:"none",face:{eyes:"big",eyesOnTop:!0,mouth:"open",muzzle:"none",cheeks:"#f59b8f"},tail:"none",headExtras:[],bodyExtras:["flippers","spots"],extraColors:["#62ad62","#b0e6a4"]},{id:"lion",name:{en:"Lion",it:"Leoncino"},band:"6-8",palette:{body:"#f6c454",limbs:"#f6c454",belly:"#fde7b0",accent:"#fde7b0",outline:de},head:"round",ears:"round",face:{eyes:"dot",mouth:"cat",nose:"#8a4b2a",muzzle:"oval",cheeks:Ne},tail:"tuft",headExtras:["mane"],bodyExtras:[],extraColors:["#c8692e"]},{id:"unicorn",name:{en:"Unicorn",it:"Unicorno"},band:"6-8",palette:{body:"#fbf5ff",limbs:"#fbf5ff",belly:"#efe0ff",accent:"#fbd46a",outline:de,hands:"#c9a6f2",feet:"#c9a6f2"},head:"tall",ears:"unicorn",face:{eyes:"dot",mouth:"smile",muzzle:"none",cheeks:"#f7a6c8"},tail:"none",headExtras:["rainbow-mane"],bodyExtras:[],extraColors:["#f58cc0","#8fd3f4","#a98ff2"]},{id:"dragon",name:{en:"Little Dragon",it:"Draghetto"},band:"6-8",palette:{body:"#8a63d2",limbs:"#8a63d2",belly:"#fbd46a",accent:"#5fd0b5",outline:de},head:"wide",ears:"horns",face:{eyes:"big",eyeColor:"#3a2a6a",mouth:"teeth",muzzle:"none",cheeks:"#f59bc0"},tail:"arrow",headExtras:[],bodyExtras:["wings"]},{id:"robot",name:{en:"Robot",it:"Robot"},band:"9-12",palette:{body:"#b9c7d2",limbs:"#8b9aa6",belly:"#b9c7d2",accent:"#ee6a43",outline:Re,hands:"#ee6a43",feet:"#6b7a86"},head:"square",ears:"antenna",face:{eyes:"screen",eyeColor:"#7ff0ff",mouth:"grill",muzzle:"none"},tail:"none",headExtras:["bolts"],bodyExtras:["panel","joints","boots"],extraColors:["#ff7a6b","#fbd46a","#7ff0ff"]},{id:"astronaut",name:{en:"Astronaut",it:"Astronauta"},band:"9-12",palette:{body:"#f4f1ec",limbs:"#f4f1ec",belly:"#f4f1ec",accent:"#ee6a43",outline:Re,hands:"#9fb0bd",feet:"#9fb0bd"},head:"round",ears:"none",face:{eyes:"visor",mouth:"smile",muzzle:"none"},tail:"none",headExtras:["helmet"],bodyExtras:["backpack","badge","boots"],extraColors:["#c9d3db"]},{id:"dinosaur",name:{en:"Dinosaur",it:"Dinosauro"},band:"6-8",palette:{body:"#3fb3a6",limbs:"#3fb3a6",belly:"#c9f0d6",accent:"#f79a3e",outline:de},head:"wide",ears:"none",face:{eyes:"dot",mouth:"teeth",muzzle:"none",cheeks:"#f59b8f"},tail:"spiky",headExtras:["spikes","spots"],bodyExtras:[],extraColors:["#2b8f84","#7fd3c6"]},{id:"monkey",name:{en:"Monkey",it:"Scimmietta"},band:"6-8",palette:{body:"#7b5234",limbs:"#7b5234",belly:"#f2c9a0",accent:"#f2c9a0",outline:de,hands:"#f2c9a0",feet:"#f2c9a0"},head:"round",ears:"side",face:{eyes:"dot",mouth:"open",nose:"#5a3a26",muzzle:"monkey",cheeks:Ne},tail:"curl",headExtras:["tuft"],bodyExtras:[]},{id:"koala",name:{en:"Koala",it:"Koala"},band:"3-5",palette:{body:"#b7bcc6",limbs:"#b7bcc6",belly:"#eef0f3",accent:"#f4dbe2",outline:ve},head:"wide",ears:"big-round",face:{eyes:"dot",mouth:"smile",nose:"#3b3438",muzzle:"none",cheeks:"#f4a3b0"},tail:"none",headExtras:[],bodyExtras:[]},{id:"tiger",name:{en:"Tiger",it:"Tigrotto"},band:"6-8",palette:{body:"#f9a33a",limbs:"#f9a33a",belly:"#fff1dc",accent:"#fff1dc",outline:de},head:"wide",ears:"round",face:{eyes:"dot",mouth:"cat",nose:"#e2607a",muzzle:"oval",cheeks:Ne},tail:"striped",headExtras:["stripes","whiskers"],bodyExtras:[],extraColors:["#3a2a22"]},{id:"owl",name:{en:"Owl",it:"Gufetto"},band:"3-5",palette:{body:"#8ec0e6",limbs:"#8ec0e6",belly:"#e3f2fc",accent:"#639cc9",outline:ve,feet:"#f9b95c",hands:"#639cc9"},head:"tall",ears:"tufts",face:{eyes:"big",eyeColor:ve,eyeRing:"#fde08a",mouth:"beak",muzzle:"none",cheeks:"#f6a8b4"},tail:"none",headExtras:[],bodyExtras:["feathers"]},{id:"alien",name:{en:"Alien",it:"Alieno"},band:"9-12",palette:{body:"#9ee05a",limbs:"#9ee05a",belly:"#d8f5a8",accent:"#b07cf2",outline:Re},head:"bulb",ears:"antennae",face:{eyes:"almond",eyeColor:"#1e1838",mouth:"smirk",muzzle:"none"},tail:"none",headExtras:[],bodyExtras:["spots"],extraColors:["#7cc23e","#7cc23e"]},{id:"ghost",name:{en:"Friendly Ghost",it:"Fantasmino"},band:"6-8",palette:{body:"#e6f4ff",limbs:"#e6f4ff",belly:"#e6f4ff",accent:"#bcd9f2",outline:de},head:"round",ears:"none",face:{eyes:"dot",mouth:"open",muzzle:"none",cheeks:"#f7a6c8"},tail:"none",headExtras:["curl"],bodyExtras:["sheet"]},{id:"octopus",name:{en:"Octopus",it:"Polpetto"},band:"6-8",palette:{body:"#e0578a",limbs:"#e0578a",belly:"#f7b3cc",accent:"#f7b3cc",outline:de,hands:"#f7b3cc",feet:"#f7b3cc"},head:"tall",ears:"none",face:{eyes:"big",eyeColor:"#3a2140",mouth:"smile",muzzle:"none",cheeks:"#ffd0a0"},tail:"none",headExtras:["spots"],bodyExtras:["tentacles"],extraColors:["#f7b3cc","#f7b3cc"]},{id:"chick",name:{en:"Chick",it:"Pulcino"},band:"3-5",palette:{body:"#ffd45e",limbs:"#ffd45e",belly:"#fff2c2",accent:"#ffa04a",outline:ve,hands:"#ffc23d",feet:"#ffa04a"},head:"round",ears:"none",face:{eyes:"dot",mouth:"beak",muzzle:"none",cheeks:Ne},tail:"none",headExtras:["eggshell"],bodyExtras:[],extraColors:["#fffaf0"]},{id:"puppy",name:{en:"Puppy",it:"Cucciolo"},band:"3-5",palette:{body:"#f4e4cf",limbs:"#f4e4cf",belly:"#fffaf2",accent:"#f29aa4",outline:ve,ears:"#b58262",hands:"#e6caa6",feet:"#e6caa6"},head:"wide",ears:"floppy",face:{eyes:"dot",mouth:"open",nose:on,muzzle:"oval",cheeks:Ne},tail:"curl",headExtras:["eye-spot"],bodyExtras:[]},{id:"lamb",name:{en:"Lamb",it:"Agnellino"},band:"3-5",palette:{body:"#fdf8ee",limbs:"#e3d1c2",belly:"#fffdf8",accent:"#f6bcc2",outline:ve,skin:"#f7dccb",hands:"#a58c7e",feet:"#a58c7e"},head:"round",ears:"droopy",face:{eyes:"dot",mouth:"smile",nose:"#e591a0",muzzle:"none",cheeks:Ne},tail:"pom",headExtras:["wool"],bodyExtras:["wool"]},{id:"duckling",name:{en:"Duckling",it:"Anatroccolo"},band:"3-5",palette:{body:"#fff1a6",limbs:"#fff1a6",belly:"#fffbe0",accent:"#ff9f43",outline:ve,feet:"#ff9f43"},head:"tall",ears:"none",face:{eyes:"dot",mouth:"bill",muzzle:"none",cheeks:Ne},tail:"none",headExtras:["curl"],bodyExtras:["flippers","scarf"],extraColors:["#86cfe0"]},{id:"shark",name:{en:"Shark",it:"Squalo"},band:"6-8",palette:{body:"#6c95c4",limbs:"#6c95c4",belly:"#eef5fb",accent:"#4c76a8",outline:de,hands:"#eef5fb",feet:"#4c76a8"},head:"wide",ears:"fin",face:{eyes:"dot",mouth:"jaws",muzzle:"none",cheeks:"#f59bb0"},tail:"fish",headExtras:["gills"],bodyExtras:[]},{id:"wolf",name:{en:"Wolf",it:"Lupo"},band:"6-8",palette:{body:"#8f9bb3",limbs:"#8f9bb3",belly:"#eef1f6",accent:"#f3b8c4",outline:de,hands:"#5a647a",feet:"#5a647a"},head:"round",ears:"pointy",face:{eyes:"dot",mouth:"open",nose:on,muzzle:"oval",cheeks:"#f4a3b0"},tail:"fluffy",headExtras:["ruff","forehead"],bodyExtras:[],extraColors:["#636d84"]},{id:"parrot",name:{en:"Parrot",it:"Pappagallo"},band:"6-8",palette:{body:"#e8503f",limbs:"#e8503f",belly:"#ffd25a",accent:"#f6e6c4",outline:de,hands:"#3a9bdc",feet:"#8a7a70"},head:"round",ears:"none",face:{eyes:"big",eyeColor:de,eyeRing:"#ffffff",mouth:"hook",muzzle:"none",cheeks:"#ffb0a0"},tail:"plume",headExtras:["crest"],bodyExtras:["feathers"],extraColors:["#ffd25a","#3fae5a","#3a9bdc"]},{id:"ninja",name:{en:"Ninja",it:"Ninja"},band:"9-12",palette:{body:"#2f3a56",limbs:"#2f3a56",belly:"#2f3a56",accent:"#36c9bb",outline:Re,skin:"#b07a52",hands:"#222a40",feet:"#222a40"},head:"round",ears:"none",face:{eyes:"calm",mouth:"none",muzzle:"none",brows:"#2a1d16"},tail:"none",headExtras:["ninja-hood"],bodyExtras:["belt"],extraColors:["#36c9bb","#36c9bb","#36c9bb"]},{id:"skater",name:{en:"Skater",it:"Skater"},band:"9-12",palette:{body:"#3a8fc0",limbs:"#2c3e57",belly:"#2f7aa6",accent:"#ffcf3a",outline:Re,skin:"#f2c9a5",hair:"#7a4a2a",hands:"#f2c9a5",feet:"#eef1f5"},head:"round",ears:"human",face:{eyes:"calm",mouth:"smirk",muzzle:"none",brows:"#5a3520"},tail:"none",headExtras:["hair","cap"],bodyExtras:["pocket","joints"],extraColors:["#ff5d73"]},{id:"explorer",name:{en:"Explorer",it:"Giramondo"},band:"9-12",palette:{body:"#5f8f5b",limbs:"#5f8f5b",belly:"#5f8f5b",accent:"#d9bb7e",outline:Re,skin:"#7a4a30",hair:"#1d1410",hands:"#7a4a30",feet:"#6b4a2a"},head:"round",ears:"human",face:{eyes:"calm",mouth:"smile",muzzle:"none",brows:"#1d1410"},tail:"none",headExtras:["curls","safari-hat"],bodyExtras:["backpack","straps","boots"],extraColors:["#e07b39","#6b4a2a"]},{id:"wizard",name:{en:"Wizard",it:"Mago"},band:"9-12",palette:{body:"#5b3fa0",limbs:"#5b3fa0",belly:"#5b3fa0",accent:"#3d5fc8",outline:Re,skin:"#c98d62",hair:"#a8452a",hands:"#c98d62",feet:"#33255e"},head:"round",ears:"human",face:{eyes:"calm",mouth:"smile",muzzle:"none",brows:"#7a301c"},tail:"none",headExtras:["locks","wizard-hat"],bodyExtras:["robe","belt"],extraColors:["#ffd84a","#ffd84a","#ffd84a"]},{id:"knight",name:{en:"Knight",it:"Cavaliere"},band:"9-12",palette:{body:"#bcc7d3",limbs:"#8e9aa8",belly:"#dce3ea",accent:"#d8443a",outline:Re,hands:"#6c7786",feet:"#6c7786"},head:"bucket",ears:"none",face:{eyes:"slit",eyeColor:"#bfefff",mouth:"none",muzzle:"none"},tail:"none",headExtras:["plume"],bodyExtras:["pauldrons","emblem","boots"],extraColors:["#d8443a"]},{id:"racer",name:{en:"Racer",it:"Pilota"},band:"9-12",palette:{body:"#ff6a2b",limbs:"#ff6a2b",belly:"#ffffff",accent:"#ffffff",outline:Re,hands:"#232838",feet:"#232838"},head:"round",ears:"none",face:{eyes:"goggle",eyeColor:"#7fd6ff",mouth:"none",muzzle:"none"},tail:"none",headExtras:["stripe"],bodyExtras:["racing-stripe","boots"]},{id:"pirate",name:{en:"Pirate",it:"Pirata"},band:"9-12",palette:{body:"#f2efe6",limbs:"#2a3d6e",belly:"#f2efe6",accent:"#d94545",outline:Re,skin:"#d9a072",hair:"#2b1a12",hands:"#d9a072",feet:"#3a2a20"},head:"round",ears:"human",face:{eyes:"calm",mouth:"smirk",muzzle:"none",brows:"#2b1a12"},tail:"none",headExtras:["locks","bandana","eye-patch"],bodyExtras:["stripes","belt","boots"],extraColors:["#d94545","#2a3d6e","#4a3426"]},{id:"diver",name:{en:"Diver",it:"Sub"},band:"9-12",palette:{body:"#1f6582",limbs:"#1f6582",belly:"#1f6582",accent:"#ffb020",outline:Re,skin:"#e8b48a",hair:"#c98f2e",hands:"#1b4f66",feet:"#ffb020"},head:"round",ears:"human",face:{eyes:"calm",mouth:"smile",muzzle:"none",brows:"#8a5a1a"},tail:"none",headExtras:["curls","dive-mask"],bodyExtras:["tank","fins"],extraColors:["#c9d3db"]},{id:"hero",name:{en:"Hero",it:"Supereroe"},band:"9-12",palette:{body:"#3557c8",limbs:"#3557c8",belly:"#3557c8",accent:"#e0403a",outline:Re,skin:"#5a3825",hair:"#141010",hands:"#e0403a",feet:"#e0403a"},head:"round",ears:"human",face:{eyes:"calm",mouth:"smirk",muzzle:"none",brows:"#141010"},tail:"none",headExtras:["hair","domino"],bodyExtras:["cape","emblem","boots"],extraColors:["#ffd84a"]}];var te={M:0,L:1,Q:2,C:3,Z:4},Cs=[2,2,4,6,0];function Ct(s,n){for(let e of n)Ia(s,e)}function Ia(s,n){if(n.k==="group"){s.save(),s.translate(n.x,n.y),n.rot&&s.rotate(n.rot),n.s!==void 0&&n.s!==1&&s.scale(n.s,n.s),n.alpha!==void 0&&(s.globalAlpha*=n.alpha),Ct(s,n.items),s.restore();return}switch(s.save(),n.alpha!==void 0&&(s.globalAlpha*=n.alpha),s.beginPath(),n.k){case"circle":s.arc(n.x,n.y,Math.max(n.r,0),0,Math.PI*2);break;case"ellipse":s.ellipse(n.x,n.y,Math.max(n.rx,0),Math.max(n.ry,0),n.rot??0,0,Math.PI*2);break;case"rect":za(s,n);break;case"path":typeof n.d=="string"?$a(s,n.d):Ua(s,n.d);break;case"line":s.moveTo(n.pts[0]??0,n.pts[1]??0);for(let e=2;e+1<n.pts.length;e+=2)s.lineTo(n.pts[e],n.pts[e+1]);break}s.lineCap="round",s.lineJoin="round",n.fill&&n.k!=="line"&&(s.fillStyle=n.fill,s.fill()),n.stroke&&(n.lw??1)>0&&(s.strokeStyle=n.stroke,s.lineWidth=n.lw??1,s.stroke()),s.restore()}function za(s,n){let e=Math.max(0,Math.min(n.r,n.w/2,n.h/2));s.translate(n.x,n.y),n.rot&&s.rotate(n.rot);let t=-n.w/2,r=-n.h/2;s.moveTo(t+e,r),s.lineTo(t+n.w-e,r),s.quadraticCurveTo(t+n.w,r,t+n.w,r+e),s.lineTo(t+n.w,r+n.h-e),s.quadraticCurveTo(t+n.w,r+n.h,t+n.w-e,r+n.h),s.lineTo(t+e,r+n.h),s.quadraticCurveTo(t,r+n.h,t,r+n.h-e),s.lineTo(t,r+e),s.quadraticCurveTo(t,r,t+e,r),s.closePath()}function Ua(s,n){for(let e=0;e<n.length;){let t=n[e++];if(t===te.M)s.moveTo(n[e],n[e+1]);else if(t===te.L)s.lineTo(n[e],n[e+1]);else if(t===te.Q)s.quadraticCurveTo(n[e],n[e+1],n[e+2],n[e+3]);else if(t===te.C)s.bezierCurveTo(n[e],n[e+1],n[e+2],n[e+3],n[e+4],n[e+5]);else if(t===te.Z)s.closePath();else return;e+=Cs[t]}}function gr(s){if(typeof s=="string")return(s.match(/-?\d*\.?\d+(?:e-?\d+)?/gi)??[]).map(Number);let n=[];for(let e=0;e<s.length;){let t=Cs[s[e++]];if(t===void 0)break;for(let r=0;r<t;r++)n.push(s[e+r]);e+=t}return n}function $a(s,n){let e=n.match(/[MLQCZ]|-?\d*\.?\d+(?:e-?\d+)?/gi)??[],t="",r=0,o=()=>Number(e[r++]);for(;r<e.length;){let a=e[r];if(/[MLQCZ]/i.test(a)&&(t=a.toUpperCase(),r++,t==="Z")){s.closePath();continue}t==="M"?(s.moveTo(o(),o()),t="L"):t==="L"?s.lineTo(o(),o()):t==="Q"?s.quadraticCurveTo(o(),o(),o(),o()):t==="C"?s.bezierCurveTo(o(),o(),o(),o(),o(),o()):r++}}var K=s=>{let n=Math.round(s*100)/100;return n===0?0:n};function J(s,n=.5){let e=s.length;if(e<3)return[];let t=(i,l,c)=>({x:i.x+(l.x-i.x)*c,y:i.y+(l.y-i.y)*c}),r=Math.min(Math.max(n,0),.5),o=t(s[0],s[1],r),a=[te.M,K(o.x),K(o.y)];for(let i=1;i<=e;i++){let l=s[(i-1)%e],c=s[i%e],u=s[(i+1)%e],f=t(l,c,1-r),h=t(c,u,r);a.push(te.L,K(f.x),K(f.y),te.Q,K(c.x),K(c.y),K(h.x),K(h.y))}return a.push(te.Z),a}function Z(s,n=1){let e=s.length;if(e<3)return[];let t=[te.M,K(s[0].x),K(s[0].y)],r=n/6;for(let o=0;o<e;o++){let a=s[(o-1+e)%e],i=s[o],l=s[(o+1)%e],c=s[(o+2)%e];t.push(te.C,K(i.x+(l.x-a.x)*r),K(i.y+(l.y-a.y)*r),K(l.x-(c.x-i.x)*r),K(l.y-(c.y-i.y)*r),K(l.x),K(l.y))}return t.push(te.Z),t}function _t(s){let n=s.length;if(n<2)return[];let e=[te.M,K(s[0].x),K(s[0].y)];for(let t=0;t<n-1;t++){let r=s[Math.max(t-1,0)],o=s[t],a=s[t+1],i=s[Math.min(t+2,n-1)];e.push(te.C,K(o.x+(a.x-r.x)/6),K(o.y+(a.y-r.y)/6),K(a.x-(i.x-o.x)/6),K(a.y-(i.y-o.y)/6),K(a.x),K(a.y))}return e}var mt="M0 -1 L0.29 -0.4 L0.95 -0.31 L0.47 0.15 L0.59 0.81 L0 0.5 L-0.59 0.81 L-0.47 0.15 L-0.95 -0.31 L-0.29 -0.4 Z";var ce="#ffffff",V=[-1,1],_s="#3a2420",Ha="#f2808f",kr="#26324a",Ga="#ffd84a",me=(...s)=>{let n=[];for(let e=0;e+1<s.length;e+=2)n.push({x:s[e],y:s[e+1]});return n};function Bn(s,n){let e=s.palette,t=[],r={stroke:e.outline,lw:n},o=u=>s.headExtras.includes(u),a=(u,f)=>s.extraColors?.[u]??f;if(o("mane")){for(let f=0;f<12;f++){let h=f/12*Math.PI*2;t.push({k:"circle",x:Math.cos(h)*1.02,y:Math.sin(h)*1+.04,r:.42,fill:a(0,e.accent),...r})}t.push({k:"circle",x:0,y:.04,r:1.08,fill:a(0,e.accent)})}if(o("rainbow-mane")){let u=s.extraColors??["#f59ac0","#fbd46a","#8fd3f4"];[[.98,.05,.3,.5,-.25],[.92,.58,.26,.42,-.1],[.62,.92,.22,.32,.4]].forEach(([h,b,y,m,d],x)=>t.push({k:"ellipse",x:h,y:b,rx:y,ry:m,rot:d,fill:u[x%u.length],...r}))}if(o("spikes"))for(let u of[-.55,0,.55]){let f=an(u,1.48),h=an(u-.32,.86),b=an(u+.32,.86);t.push({k:"path",d:J([h,f,b],.22),fill:e.accent,...r})}if(o("curl")&&t.push({k:"path",d:Z([{x:-.2,y:-.9},{x:-.05,y:-1.3},{x:.32,y:-1.42},{x:.16,y:-1.18},{x:.2,y:-.9}]),fill:e.body,...r}),o("wool"))for(let u=0;u<=8;u++){let f=-1.75+u/8*3.5;t.push({k:"circle",x:Math.sin(f)*.98,y:-Math.cos(f)*.92-.04,r:.34,fill:e.body,...r})}if(o("crest")&&[-.38,0,.38].forEach((u,f)=>{let h=an(u,1.12);t.push({k:"ellipse",x:h.x,y:h.y,rx:.15,ry:.42,rot:u,fill:a(f,e.accent),...r})}),o("plume")&&t.push({k:"path",d:Z(me(-.12,-.92,-.2,-1.42,.1,-1.78,.62,-1.74,.36,-1.46,.16,-.98)),fill:e.accent,...r}),o("locks")&&t.push({k:"path",d:Z(me(-1.14,.58,-1.24,-.2,-.86,-.98,0,-1.2,.86,-.98,1.24,-.2,1.14,.58,.8,.66,0,.2,-.8,.66)),fill:e.hair??e.outline,...r}),o("ninja-hood"))for(let[u,f]of[[.35,.5],[.85,.42]])t.push({k:"ellipse",x:1+Math.cos(u)*f*.8,y:-.5+Math.sin(u)*f*.8,rx:f,ry:.11,rot:u,fill:e.accent,...r});if(o("bandana"))for(let[u,f]of[[Math.PI-.5,.42],[Math.PI-1,.36]])t.push({k:"ellipse",x:-.98+Math.cos(u)*f*.8,y:-.36+Math.sin(u)*f*.8,rx:f,ry:.12,rot:u,fill:e.accent,...r});if(o("ruff"))for(let u of V)t.push({k:"path",d:J(me(u*.7,-.3,u*1.32,0,u*1.02,.18,u*1.26,.46,u*.86,.56,u*.98,.84,u*.4,.7),.25),fill:e.body,...r});if(s.face.eyesOnTop)for(let u of V)t.push({k:"circle",x:u*.46,y:-.72,r:.38,fill:e.body,...r});t.push(...qa(s,n)),t.push(Wa(s,r));let i=s.face.muzzle,l=e.belly;if(i==="oval"&&t.push({k:"ellipse",x:0,y:.4,rx:.46,ry:.32,fill:l}),i==="monkey"){for(let u of V)t.push({k:"circle",x:u*.32,y:-.04,r:.38,fill:l});t.push({k:"ellipse",x:0,y:.4,rx:.56,ry:.4,fill:l})}if(i==="heart"){for(let u of V)t.push({k:"circle",x:u*.36,y:.02,r:.5,fill:l});t.push({k:"ellipse",x:0,y:.38,rx:.66,ry:.48,fill:l})}if(i==="disc")for(let u of V)t.push({k:"circle",x:u*.4,y:.02,r:.44,fill:l});if(i==="cheeks")for(let u of V)t.push({k:"ellipse",x:u*.4,y:.44,rx:.44,ry:.32,fill:l});if(i==="band"&&t.push({k:"path",d:Xa(s,n),fill:l}),o("stripes")){let u=a(0,e.outline);t.push({k:"line",pts:[0,-.97,0,-.66],stroke:u,lw:.13});for(let f of V)t.push({k:"line",pts:[f*.3,-.93,f*.24,-.7],stroke:u,lw:.1}),t.push({k:"line",pts:[f*.98,-.05,f*.74,0],stroke:u,lw:.1}),t.push({k:"line",pts:[f*.94,.22,f*.74,.22],stroke:u,lw:.09})}if(o("spots")){let u=a(1,e.belly);t.push({k:"circle",x:-.55,y:-.5,r:.15,fill:u}),t.push({k:"circle",x:.58,y:-.42,r:.11,fill:u}),t.push({k:"circle",x:.22,y:-.76,r:.09,fill:u})}if(o("forehead")&&t.push({k:"path",d:Z(me(-.62,-.66,0,-.86,.62,-.66,.26,-.36,0,-.1,-.26,-.36),.9),fill:a(0,e.accent)}),o("eye-spot")&&t.push({k:"ellipse",x:.42,y:-.06,rx:.3,ry:.33,rot:.3,fill:e.ears??e.accent}),o("gills"))for(let u of V)for(let f of[0,.12,.24])t.push({k:"path",d:`M${u*(.66+f)} 0.06 Q${u*(.6+f)} 0.22 ${u*(.66+f)} 0.38`,stroke:e.accent,lw:n*.9});let c=e.hair??e.outline;if(o("hair")&&t.push({k:"path",d:Z(me(-1.02,-.06,-1.02,-.58,-.62,-1.04,.08,-1.14,.76,-.92,1.05,-.42,1,-.06,.84,-.4,.42,-.5,.06,-.4,-.34,-.56,-.74,-.38)),fill:c,...r}),o("locks")&&t.push({k:"path",d:Z(me(-1,-.08,-.98,-.62,-.56,-1.02,0,-1.1,.56,-1.02,.98,-.62,1,-.08,.8,-.38,.36,-.44,0,-.4,-.36,-.44,-.8,-.38)),fill:c,...r}),o("curls")){for(let u=0;u<7;u++){let f=an(-1.3+u/6*2.6,.86);t.push({k:"circle",x:f.x,y:f.y,r:.3,fill:c,...r})}t.push({k:"ellipse",x:0,y:-.64,rx:.8,ry:.36,fill:c})}if(o("ninja-hood")&&(t.push({k:"rect",x:0,y:0,w:1.56,h:.6,r:.28,fill:e.skin??ce,stroke:e.outline,lw:n*.8}),t.push({k:"path",d:"M-0.98 -0.42 Q0 -0.74 0.98 -0.42 L1.0 -0.62 Q0 -0.94 -1.0 -0.62 Z",fill:e.accent,...r})),o("domino")){t.push({k:"path",d:Z(me(-.86,-.04,-.62,-.3,-.18,-.24,0,-.16,.18,-.24,.62,-.3,.86,-.04,.6,.22,.16,.16,0,.1,-.16,.16,-.6,.22),.9),fill:e.accent,...r});for(let u of V)t.push({k:"ellipse",x:u*.38,y:0,rx:.19,ry:.13,fill:ce})}if(t.push(...ja(s,n)),o("brows"))for(let u of V)t.push({k:"line",pts:[u*.72,-.5,u*.14,-.3],stroke:e.accent,lw:.16});if(s.face.brows)for(let u of V)t.push({k:"line",pts:[u*.2,-.2,u*.54,-.28],stroke:s.face.brows,lw:.09});if(t.push(...Ya(s,n)),s.face.cheeks)for(let u of V)t.push({k:"ellipse",x:u*.64,y:.3,rx:.15,ry:.1,fill:s.face.cheeks,alpha:.8});if(o("whiskers"))for(let u of V)for(let f of[-.1,.06])t.push({k:"line",pts:[u*.62,.38+f,u*1.06,.3+f*2.2],stroke:e.outline,lw:n*.7,alpha:.75});if(o("rainbow-mane")){let u=s.extraColors??["#f59ac0","#fbd46a","#8fd3f4"];t.push({k:"ellipse",x:.42,y:-.82,rx:.34,ry:.22,rot:.5,fill:u[0],...r}),t.push({k:"ellipse",x:.1,y:-.92,rx:.3,ry:.2,rot:.25,fill:u[1%u.length],...r})}if(s.ears==="unicorn"){let u=[{x:-.18,y:-.84},{x:.02,y:-1.72},{x:.18,y:-.84}];t.push({k:"path",d:J(u,.12),fill:e.accent,...r});for(let f of[-1,-1.2,-1.4]){let h=.16*((f+1.72)/.88);t.push({k:"line",pts:[-h,f+.04,h,f-.04],stroke:e.outline,lw:n*.7,alpha:.6})}}if(o("helmet")){for(let u of V)t.push({k:"rect",x:u*1,y:.05,w:.26,h:.56,r:.12,fill:e.accent,...r});t.push({k:"path",d:"M-0.62 -0.62 Q-0.3 -0.92 0.12 -0.9",stroke:ce,lw:.1,alpha:.9})}if(o("bolts"))for(let u of V)t.push({k:"rect",x:u*1.08,y:.08,w:.2,h:.44,r:.08,fill:e.accent,...r});if(o("tuft")&&t.push({k:"path",d:Z([{x:-.26,y:-.95},{x:-.12,y:-1.22},{x:.02,y:-1.04},{x:.16,y:-1.28},{x:.28,y:-.95},{x:0,y:-.86}]),fill:e.body,...r}),o("eggshell")&&t.push({k:"path",d:"M-0.88 -0.5 C-0.88 -1.12 -0.46 -1.42 0 -1.42 C0.46 -1.42 0.88 -1.12 0.88 -0.5 L0.66 -0.66 L0.44 -0.48 L0.22 -0.66 L0 -0.48 L-0.22 -0.66 L-0.44 -0.48 L-0.66 -0.66 Z",fill:a(0,ce),...r}),o("wool"))for(let[u,f]of[[-.36,-.84],[.02,-.94],[.4,-.82]])t.push({k:"circle",x:u,y:f,r:.27,fill:e.body,...r});if(o("stripe")&&t.push({k:"rect",x:0,y:-.64,w:.38,h:.62,r:.06,fill:e.accent}),o("eye-patch")&&(t.push({k:"line",pts:[-.97,-.5,.97,.13],stroke:e.outline,lw:.07}),t.push({k:"ellipse",x:.38,y:.02,rx:.21,ry:.19,fill:e.outline})),o("bandana")){t.push({k:"path",d:Z(me(-1.05,-.22,-.96,-.72,-.5,-1.08,.1,-1.14,.72,-.96,1.04,-.56,1.05,-.22,.5,-.46,-.5,-.46)),fill:e.accent,...r});for(let[u,f]of[[-.5,-.8],[.08,-.92],[.6,-.74],[-.12,-.62],[.36,-.6]])t.push({k:"circle",x:u,y:f,r:.06,fill:ce,alpha:.85});t.push({k:"circle",x:-.98,y:-.34,r:.15,fill:e.accent,...r})}if(o("cap")){for(let u of V)t.push({k:"line",pts:[u*.98,-.2,u*.5,.82,-u*.05,.98],stroke:e.outline,lw:.06});t.push({k:"path",d:Z(me(-1.1,-.16,-1.04,-.66,-.6,-1.12,0,-1.24,.6,-1.12,1.04,-.66,1.1,-.16,.5,-.4,-.5,-.4)),fill:e.accent,...r}),t.push({k:"path",d:"M-0.74 -0.4 Q0 -0.6 0.74 -0.4 Q0.8 -0.24 0.6 -0.22 Q0 -0.36 -0.6 -0.22 Q-0.8 -0.24 -0.74 -0.4 Z",fill:e.accent,...r}),t.push({k:"circle",x:.5,y:-.82,r:.15,fill:a(0,ce),...r});for(let u of[-.42,-.14])t.push({k:"line",pts:[u,-1.04,u+.02,-.78],stroke:e.outline,lw:.07,alpha:.7})}if(o("safari-hat")&&(t.push({k:"ellipse",x:0,y:-.56,rx:1.48,ry:.3,fill:e.accent,...r}),t.push({k:"path",d:Z(me(-.78,-.58,-.7,-1.1,-.3,-1.38,.3,-1.38,.7,-1.1,.78,-.58,0,-.5),.8),fill:e.accent,...r}),t.push({k:"path",d:"M-0.77 -0.72 Q0 -0.62 0.77 -0.72 L0.74 -0.9 Q0 -0.8 -0.74 -0.9 Z",fill:a(1,e.outline),stroke:e.outline,lw:n*.8})),o("wizard-hat")){t.push({k:"ellipse",x:0,y:-.62,rx:1.32,ry:.26,fill:e.accent,...r}),t.push({k:"path",d:J(me(-.8,-.66,-.36,-1.5,.5,-2.2,.3,-1.46,.8,-.66),.3),fill:e.accent,...r});let u=a(0,Ga);for(let[f,h,b]of[[.02,-1.08,.18],[-.38,-.84,.1],[.36,-1.5,.11]])t.push({k:"group",x:f,y:h,s:b,items:[{k:"path",d:mt,fill:u}]})}if(o("dive-mask")){for(let f of V)t.push({k:"line",pts:[f*.7,-.04,f*1,-.12],stroke:e.outline,lw:.2},{k:"line",pts:[f*.7,-.04,f*1,-.12],stroke:e.accent,lw:.11});t.push({k:"rect",x:0,y:0,w:1.42,h:.62,r:.28,fill:"#bfe9f5",alpha:.35}),t.push({k:"rect",x:0,y:0,w:1.42,h:.62,r:.28,stroke:e.outline,lw:.2}),t.push({k:"rect",x:0,y:0,w:1.42,h:.62,r:.28,stroke:e.accent,lw:.11}),t.push({k:"path",d:"M-0.5 -0.16 Q-0.4 -0.24 -0.22 -0.24",stroke:ce,lw:.06,alpha:.9});let u="M0.5 0.52 Q0.98 0.56 1.04 0.1 L1.12 -0.92";t.push({k:"path",d:u,stroke:e.outline,lw:.24},{k:"path",d:u,stroke:e.accent,lw:.13})}return t}function Wa(s,n){let e=s.headExtras.includes("ninja-hood")?s.palette.body:s.palette.skin??s.palette.body;switch(s.head){case"round":return{k:"circle",x:0,y:0,r:1,fill:e,...n};case"wide":return{k:"ellipse",x:0,y:.03,rx:1.12,ry:.94,fill:e,...n};case"tall":return{k:"ellipse",x:0,y:-.02,rx:.94,ry:1.04,fill:e,...n};case"square":return{k:"rect",x:0,y:0,w:2,h:1.8,r:.46,fill:e,...n};case"bucket":return{k:"path",d:J(me(-.94,.96,-.98,-.36,-.62,-1.04,.62,-1.04,.98,-.36,.94,.96),.42),fill:e,...n};case"bulb":return{k:"path",d:Z([{x:0,y:-1.02},{x:.86,y:-.74},{x:1.08,y:-.12},{x:.72,y:.62},{x:0,y:.92},{x:-.72,y:.62},{x:-1.08,y:-.12},{x:-.86,y:-.74}]),fill:e,...n}}}function Va(s){return s.head==="round"?{cy:0,rx:1,ry:1}:s.head==="tall"?{cy:-.02,rx:.94,ry:1.04}:{cy:.03,rx:1.12,ry:.94}}function Xa(s,n){let{cy:e,rx:t,ry:r}=Va(s),o=t-n/2,a=r-n/2,i=.15,l=Math.asin(Math.min(1,(i-e)/a)),c=Math.cos(l)*o,u=y=>Math.round(y*100)/100||0,f=[te.M,u(-c),i],h=[[-.84*c,.02,-.53*c,.06,-.32*c,.24],[-.17*c,.11,.17*c,.11,.32*c,.24],[.53*c,.06,.84*c,.02,c,i]];for(let y of h)f.push(te.C,...y.map(u));let b=24;for(let y=1;y<=b;y++){let m=l+(Math.PI-2*l)*y/b;f.push(te.L,u(Math.cos(m)*o),u(e+Math.sin(m)*a))}return f.push(te.Z),f}function qa(s,n){let e=s.palette,t={stroke:e.outline,lw:n},r=[];for(let o of V)switch(s.ears){case"pointy":case"unicorn":{let a=s.ears==="unicorn"?.8:1,i={x:o*.3,y:-.82},l={x:o*.86,y:-.82-.62*a},c={x:o*.94,y:-.36};r.push({k:"path",d:J([i,l,c],.2),fill:e.body,...t});let u={x:(i.x+l.x+c.x)/3,y:(i.y+l.y+c.y)/3},f=[i,l,c].map(h=>({x:u.x+(h.x-u.x)*.55,y:u.y+(h.y-u.y)*.55+.04}));r.push({k:"path",d:J(f,.25),fill:e.accent});break}case"round":r.push({k:"circle",x:o*.72,y:-.72,r:.36,fill:e.ears??e.body,...t}),e.ears||r.push({k:"circle",x:o*.74,y:-.74,r:.19,fill:e.accent});break;case"big-round":r.push({k:"circle",x:o*.96,y:-.46,r:.52,fill:e.body,...t}),r.push({k:"circle",x:o*1,y:-.44,r:.32,fill:e.accent});break;case"long":r.push({k:"ellipse",x:o*.38,y:-1.42,rx:.25,ry:.68,rot:o*.14,fill:e.body,...t}),r.push({k:"ellipse",x:o*.39,y:-1.36,rx:.12,ry:.48,rot:o*.14,fill:e.accent});break;case"side":r.push({k:"circle",x:o*1,y:.02,r:.34,fill:e.body,...t}),r.push({k:"circle",x:o*1.02,y:.02,r:.2,fill:e.belly});break;case"tufts":r.push({k:"path",d:J([{x:o*.3,y:-.84},{x:o*1.22,y:-1.12},{x:o*.92,y:-.42}],.16),fill:e.body,...t}),r.push({k:"line",pts:[o*.62,-.78,o*1,-.98],stroke:e.accent,lw:.08});break;case"antennae":{let a={x:o*.62,y:-1.42};r.push({k:"path",d:`M${o*.3} -0.8 Q${o*.36} -1.2 ${a.x} ${a.y}`,stroke:e.outline,lw:n*2.6}),r.push({k:"path",d:`M${o*.3} -0.8 Q${o*.36} -1.2 ${a.x} ${a.y}`,stroke:e.body,lw:n*1.2}),r.push({k:"circle",x:a.x,y:a.y,r:.17,fill:e.accent,...t});break}case"floppy":r.push({k:"ellipse",x:o*.96,y:.02,rx:.3,ry:.62,rot:-o*.36,fill:e.ears??e.body,...t});break;case"droopy":r.push({k:"ellipse",x:o*1.04,y:-.22,rx:.4,ry:.18,rot:o*.32,fill:e.skin??e.body,...t}),r.push({k:"ellipse",x:o*1.08,y:-.2,rx:.24,ry:.08,rot:o*.32,fill:e.accent});break;case"human":r.push({k:"ellipse",x:o*.98,y:.06,rx:.17,ry:.23,fill:e.skin??e.body,...t});break;case"horns":{let a=[{x:o*.3,y:-.84},{x:o*.6,y:-1.5},{x:o*.66,y:-.68}];r.push({k:"path",d:J(a,.18),fill:e.accent,...t});break}}return s.ears==="fin"&&r.push({k:"path",d:J(me(-.4,-.82,.2,-1.62,.46,-.78),.2),fill:e.body,...t}),s.ears==="antenna"&&(r.push({k:"line",pts:[0,-.85,0,-1.42],stroke:e.outline,lw:n*2.6}),r.push({k:"line",pts:[0,-.85,0,-1.42],stroke:e.limbs,lw:n*1.2}),r.push({k:"circle",x:0,y:-1.5,r:.18,fill:e.accent,...t})),r}function ja(s,n){let e=s.palette,t=s.face,r=[],o=e.outline,a=t.eyesOnTop?.46:.4,i=t.eyesOnTop?-.72:-.04,l=(c,u,f)=>({k:"circle",x:c,y:u,r:f,fill:ce});switch(t.eyes){case"dot":for(let c of V)r.push({k:"ellipse",x:c*a,y:i,rx:.12,ry:.155,fill:o}),r.push(l(c*a+.04,i-.06,.045));break;case"bead":for(let c of V)r.push({k:"ellipse",x:c*a,y:i,rx:.16,ry:.22,fill:o}),r.push(l(c*a+.05,i-.08,.065));break;case"big":for(let c of V)t.eyeRing&&r.push({k:"circle",x:c*a,y:i,r:.36,fill:t.eyeRing,stroke:o,lw:n*.8}),r.push({k:"circle",x:c*a,y:i,r:.25,fill:ce,stroke:o,lw:n*.8}),r.push({k:"circle",x:c*a+c*-.03,y:i+.03,r:.14,fill:t.eyeColor??o}),r.push(l(c*a+c*-.03+.05,i-.03,.05));break;case"mask":for(let c of V)r.push({k:"ellipse",x:c*.4,y:0,rx:.24,ry:.32,rot:c*-.55,fill:e.limbs}),r.push({k:"circle",x:c*.4,y:-.02,r:.11,fill:ce}),r.push({k:"circle",x:c*.39,y:-0,r:.065,fill:o});break;case"screen":r.push({k:"rect",x:0,y:0,w:1.5,h:.66,r:.26,fill:"#24323d",stroke:o,lw:n*.8});for(let c of V)r.push({k:"ellipse",x:c*.36,y:0,rx:.2,ry:.24,fill:t.eyeColor??"#7ff0ff",alpha:.3}),r.push({k:"ellipse",x:c*.36,y:0,rx:.12,ry:.16,fill:t.eyeColor??"#7ff0ff"});break;case"almond":for(let c of V)r.push({k:"ellipse",x:c*.42,y:-.02,rx:.3,ry:.2,rot:-c*.5,fill:t.eyeColor??o}),r.push(l(c*.42-c*.07,-.08,.07));break;case"calm":for(let c of V)r.push({k:"ellipse",x:c*.38,y:.02,rx:.085,ry:.12,fill:o}),r.push(l(c*.38+.03,-.02,.03));break;case"slit":r.push({k:"line",pts:[0,-.98,0,-.2],stroke:o,lw:n*.8,alpha:.5}),r.push({k:"rect",x:0,y:-.04,w:1.56,h:.26,r:.1,fill:kr,stroke:o,lw:n*.8}),r.push({k:"rect",x:0,y:.3,w:.22,h:.46,r:.08,fill:kr,stroke:o,lw:n*.8});for(let c of V){r.push({k:"ellipse",x:c*.4,y:-.04,rx:.12,ry:.07,fill:t.eyeColor??ce});for(let u of[.36,.56])r.push({k:"circle",x:c*.42,y:u,r:.05,fill:o,alpha:.6})}break;case"goggle":for(let c of V)r.push({k:"circle",x:c*.9,y:0,r:.13,fill:e.accent,stroke:o,lw:n*.8});r.push({k:"rect",x:0,y:0,w:1.66,h:.62,r:.3,fill:kr,stroke:o,lw:n*.8}),r.push({k:"path",d:"M-0.6 -0.16 Q-0.42 -0.24 -0.12 -0.24",stroke:ce,lw:.07,alpha:.8});for(let c of V)r.push({k:"path",d:`M${c*.5} 0.04 Q${c*.34} -0.08 ${c*.16} 0.02`,stroke:t.eyeColor??"#7fd6ff",lw:.08});for(let c of[-.18,0,.18])r.push({k:"line",pts:[c,.56,c,.72],stroke:o,lw:n*.8,alpha:.6});break;case"visor":r.push({k:"ellipse",x:0,y:.08,rx:.8,ry:.64,fill:"#2a3f6b",stroke:o,lw:n*.8}),r.push({k:"path",d:"M-0.56 -0.14 Q-0.46 -0.4 -0.16 -0.46",stroke:ce,lw:.08,alpha:.7});for(let c of V)r.push({k:"ellipse",x:c*.28,y:.04,rx:.1,ry:.14,fill:t.eyeColor??"#cfeeff"});break}return r}function Ya(s,n){let e=s.palette,t=s.face,r=[],o=t.eyes==="visor"?"#cfeeff":_s,a=n*1.05;switch(t.nose&&t.mouth!=="beak"&&(t.mouth==="cat"?r.push({k:"path",d:J([{x:-.1,y:.22},{x:.1,y:.22},{x:0,y:.33}],.3),fill:t.nose,stroke:t.nose,lw:n*.6}):s.ears==="big-round"?r.push({k:"ellipse",x:0,y:.22,rx:.2,ry:.25,fill:t.nose}):r.push({k:"ellipse",x:0,y:.25,rx:.13,ry:.085,fill:t.nose})),t.mouth){case"smile":r.push({k:"path",d:t.eyes==="visor"?"M-0.16 0.32 Q0 0.46 0.16 0.32":"M-0.17 0.42 Q0 0.58 0.17 0.42",stroke:o,lw:a});break;case"open":r.push({k:"path",d:"M-0.21 0.4 Q0 0.46 0.21 0.4 Q0.19 0.68 0 0.68 Q-0.19 0.68 -0.21 0.4 Z",fill:o,stroke:o,lw:n*.5}),r.push({k:"ellipse",x:0,y:.6,rx:.1,ry:.06,fill:Ha});break;case"cat":r.push({k:"path",d:"M-0.19 0.4 Q-0.1 0.5 0 0.37 Q0.1 0.5 0.19 0.4",stroke:o,lw:a});break;case"beak":r.push({k:"path",d:J([{x:-.17,y:.2},{x:.17,y:.2},{x:0,y:.48}],.25),fill:e.accent,stroke:e.outline,lw:n*.8});break;case"teeth":r.push({k:"path",d:"M-0.36 0.34 Q0 0.44 0.36 0.34 Q0.28 0.66 0 0.66 Q-0.28 0.66 -0.36 0.34 Z",fill:o,stroke:o,lw:n*.5});for(let i of V)r.push({k:"rect",x:i*.12,y:.43,w:.1,h:.1,r:.03,fill:ce});break;case"grill":r.push({k:"rect",x:0,y:.56,w:.62,h:.2,r:.08,fill:"#24323d",stroke:e.outline,lw:n*.7});for(let i of[-.15,0,.15])r.push({k:"line",pts:[i,.51,i,.61],stroke:"#9fb0bd",lw:n*.6});break;case"tiny":r.push({k:"ellipse",x:0,y:.44,rx:.08,ry:.1,fill:o});break;case"smirk":r.push({k:"path",d:"M-0.16 0.46 Q0.06 0.54 0.22 0.38",stroke:o,lw:a});break;case"bill":r.push({k:"ellipse",x:0,y:.36,rx:.44,ry:.2,fill:e.accent,stroke:e.outline,lw:n*.8}),r.push({k:"path",d:"M-0.36 0.38 Q0 0.46 0.36 0.38",stroke:e.outline,lw:n*.7});for(let i of V)r.push({k:"circle",x:i*.1,y:.28,r:.03,fill:e.outline});break;case"hook":r.push({k:"ellipse",x:0,y:.48,rx:.16,ry:.11,fill:_s}),r.push({k:"path",d:"M-0.3 0.12 Q0 -0.02 0.3 0.12 Q0.36 0.52 0.04 0.76 Q0.08 0.52 -0.08 0.46 Q-0.28 0.38 -0.3 0.12 Z",fill:e.accent,stroke:e.outline,lw:n*.8});break;case"jaws":{r.push({k:"path",d:"M-0.5 0.3 Q0 0.5 0.5 0.3 Q0.38 0.72 0 0.72 Q-0.38 0.72 -0.5 0.3 Z",fill:o,stroke:o,lw:n*.5});for(let i of[-.34,-.17,0,.17,.34]){let l=.3+.4*(i+.5)*(.5-i)-.01;r.push({k:"path",d:J(me(i-.075,l,i+.075,l,i,l+.13),.15),fill:ce})}break}}return r}var an=(s,n)=>({x:Math.sin(s)*n,y:-Math.cos(s)*n});var Ds=.5,Ue={leftEye:2,rightEye:5,leftEar:7,rightEar:8},nt={"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}},Dn="6-8",On=s=>s.band in nt?s.band:Dn,Ka=nt[Dn].head,Os=.3,Is=.12,Qa=.9,Ps=.5,Ls=.65,Za=.35,Ja=.2,ei=.25,Ye=(s,n)=>({x:s.x-n.x,y:s.y-n.y}),Be=(s,n)=>({x:s.x+n.x,y:s.y+n.y}),ue=(s,n)=>({x:s.x*n,y:s.y*n}),bt=s=>Math.hypot(s.x,s.y),Ns=(s,n)=>({x:(s.x+n.x)/2,y:(s.y+n.y)/2}),vr=s=>{let n=bt(s);return n>1e-9?{x:s.x/n,y:s.y/n}:{x:0,y:1}},ti=(...s)=>s.every(Number.isFinite),ni=s=>Math.atan2(Math.sin(s),Math.cos(s)),ri=(s,n,e)=>Math.min(Math.max(s,n),e);function zs(s,n,e=!1){return t=>{let r=s[t*3],o=s[t*3+1],a=s[t*3+2];return r===void 0||o===void 0||a===void 0||!ti(r,o,a)?{x:0,y:0,ok:!1}:{x:n.x+(e?1-r:r)*n.w,y:n.y+o*n.h,ok:a>=Ds}}}function Pt(s,n,e={}){let t=zs(s,n,e.mirrored),r=t(Y.leftShoulder),o=t(Y.rightShoulder);if(!r.ok||!o.ok)return null;let a=t(Y.leftHip),i=t(Y.rightHip),l=Ns(r,o),c=bt(Ye(o,r)),u=a.ok&&i.ok,f=vr(Ye(o,r));c<1e-6&&(f={x:1,y:0});let h,b,y;if(u){let E=Ns(a,i);b=bt(Ye(E,l)),b>=c*ei?h=vr(Ye(E,l)):(h={x:-f.y,y:f.x},h.y<0&&(h=ue(h,-1))),y=Math.max(b,c*1.15)}else h={x:-f.y,y:f.x},h.y<0&&(h=ue(h,-1)),y=c*1.15,b=y;y=Math.max(y,1e-6);let m={x:h.y,y:-h.x},d=Math.atan2(m.y,m.x),x=ue(h,-1),g=nt[e.band??Dn]??nt[Dn],M=g.head*y,v=Be(l,ue(x,M*g.neck)),A=t(Y.nose);if(A.ok){let E=Be(A,ue(x,M*.15)),C=ue(Ye(E,v),Za),P=Math.min(1,M*Ja/Math.max(bt(C),1e-6));v=Be(v,ue(C,P))}return{S:l,r:m,d:h,U:y,L:b,hipsOk:u,head:v,headR:M,headRot:d+si(s,t,d,y),angle:d}}function si(s,n,e,t){let r=[[Ue.leftEar,Ue.rightEar],[Ue.leftEye,Ue.rightEye]];for(let[o,a]of r){let i=n(o),l=n(a);if(!i.ok||!l.ok||!(s[o*3+2]>=Ls&&s[a*3+2]>=Ls)||bt(Ye(l,i))<t*.05)continue;let c=ni(Math.atan2(l.y-i.y,l.x-i.x)-e),u=Math.max(Math.abs(c)-Is,0),f=ri((Qa+Ps-Math.abs(c))/Ps,0,1);return Math.sign(c)*Math.min(u,Os)*f}return 0}function ln(s,n,e,t={}){let r=On(n),o=nt[r],a=Pt(s,e,{...t,band:r});if(!a)return[];let i=zs(s,e,t.mirrored),l=n.palette,{S:c,r:u,d:f,U:h,L:b}=a,y=w=>n.bodyExtras.includes(w),m=Math.max(1.2,h*.045),d={stroke:l.outline,lw:m},x=(w,N)=>({x:c.x+u.x*w+f.x*N,y:c.y+u.y*w+f.y*N}),g=w=>w.map(([N,D])=>x(N,D)),M=i(Y.leftShoulder),v=i(Y.rightShoulder),A=i(Y.leftHip),E=i(Y.rightHip),C=bt(Ye(v,M)),P=a.hipsOk?bt(Ye(E,A)):C*.7,L=Math.max(C/2+o.shoulderPad*h,o.shoulderMin*h),I=Math.max(P/2+o.hipPad*h,o.hipMin*h),U=-.1*h,X=b+o.bottom*h,H=[],fe=[],$=[],ne=[],pe=[],_e=(w,N,D,q)=>{let G=N.flatMap(se=>[se.x,se.y]);w.push({k:"line",pts:G,stroke:l.outline,lw:D+m*2}),w.push({k:"line",pts:G,stroke:q,lw:D})},cr=o.leg*h,xe=o.arm*h,Pe=Math.max(o.arm/.22,.9);if(a.hipsOk)for(let[w,N,D,q]of[[A,Y.leftKnee,Y.leftAnkle,-1],[E,Y.rightKnee,Y.rightAnkle,1]]){let G=i(N),se=i(D);if(!G.ok)continue;let Mt=Be(w,ue(f,-.12*h)),qe=se.ok?[Mt,G,se]:[Mt,G];_e(fe,qe,cr,l.limbs),y("joints")&&fe.push({k:"circle",x:G.x,y:G.y,r:.15*h*Pe,fill:l.accent,...d}),se.ok&&fe.push(ii(n,se,a,q,m,o.foot))}for(let[w,N,D,q]of[[M,Y.leftElbow,Y.leftWrist,-1],[v,Y.rightElbow,Y.rightWrist,1]]){let G=i(N),se=i(D);if(y("pauldrons")){let ze=Be(w,ue(f,.02*h));ne.push({k:"ellipse",x:ze.x,y:ze.y,rx:.25*h,ry:.17*h,rot:a.angle+q*.25,fill:l.body,...d});let je=Be(ze,ue(f,.05*h));ne.push({k:"ellipse",x:je.x,y:je.y,rx:.17*h,ry:.07*h,rot:a.angle+q*.25,fill:l.belly})}if(!G.ok)continue;let qe=o.armsOverHead&&(G.x-c.x)*f.x+(G.y-c.y)*f.y<-.25*h?pe:ne,Jt=Be(w,ue(f,.04*h));if(_e(qe,se.ok?[Jt,G,se]:[Jt,G],xe,l.limbs),y("joints")&&qe.push({k:"circle",x:G.x,y:G.y,r:.13*h*Pe,fill:l.accent,...d}),!se.ok)continue;let Ie=vr(Ye(se,G)),Tt=Be(se,ue(Ie,.05*h));if(y("feathers"))for(let ze of[-.55,0,.55]){let je=Math.cos(ze),Et=Math.sin(ze)*q,en={x:Ie.x*je-Ie.y*Et,y:Ie.x*Et+Ie.y*je},ht=Be(Tt,ue(en,.16*h));qe.push({k:"ellipse",x:ht.x,y:ht.y,rx:.2*h,ry:.09*h,rot:Math.atan2(en.y,en.x),fill:l.hands??l.accent,...d})}qe.push({k:"circle",x:Tt.x,y:Tt.y,r:o.hand*h,fill:l.hands??l.limbs,...d})}if(y("wings"))for(let w of[-1,1]){let N=g([[w*L*.5,.05*h],[w*(L+.85*h),-.6*h],[w*(L+.72*h),.05*h],[w*(L+.45*h),-.02*h],[w*(L+.3*h),.32*h],[w*L*.6,.55*h]]);H.push({k:"path",d:J(N,.18),fill:l.accent,...d})}if(y("cape")){let w=b+.8*h,N=I+.36*h,D=g([[-L*.92,U+.04*h],[L*.92,U+.04*h],[L+.16*h,b*.5],[N,w],[N*.5,w-.1*h],[0,w],[-N*.5,w-.1*h],[-N,w],[-L-.16*h,b*.5]]);H.push({k:"path",d:Z(D,.6),fill:l.accent,...d})}if(y("backpack")){let w=x(0,.35*h);H.push({k:"rect",x:w.x,y:w.y,w:L*2+.34*h,h:.8*h,r:.16*h,rot:a.angle,fill:n.extraColors?.[0]??l.limbs,...d})}if(y("tank")){let w=x(L*.95,.24*h),N=n.extraColors?.[0]??l.accent,D=x(L*.95,-.3*h);H.push({k:"rect",x:D.x,y:D.y,w:.14*h,h:.16*h,r:.04*h,rot:a.angle,fill:l.outline}),H.push({k:"rect",x:w.x,y:w.y,w:.34*h,h:1*h,r:.17*h,rot:a.angle,fill:N,...d})}if(a.hipsOk&&!t.portrait&&H.push(...li(n,a,I,m)),y("tentacles")&&a.hipsOk)for(let w of[-1,1]){let N=g([[w*I*.7,b*.9],[w*(I+.22*h),b+.3*h],[w*(I+.48*h),b+.22*h],[w*(I+.5*h),b-.02*h],[w*(I+.34*h),b-.06*h]]);H.push({k:"path",d:_t(N),stroke:l.outline,lw:.2*h+m*2}),H.push({k:"path",d:_t(N),stroke:l.limbs,lw:.2*h})}let ge=Math.max(L,I)*o.bulge;if(y("wool")){for(let[N,D]of[[L*.7,U+.02*h],[ge,b*.3],[ge*1.02,b*.62],[(ge+I)/2,b*.92],[I*.55,X]])for(let q of[-1,1]){let G=x(q*N,D);$.push({k:"circle",x:G.x,y:G.y,r:.2*h,fill:l.body,...d})}let w=x(0,X+.02*h);$.push({k:"circle",x:w.x,y:w.y,r:.2*h,fill:l.body,...d})}if(y("robe")){let w=b+.58*h,N=I*1.4;$.push({k:"path",d:Z(g([[-L,U],[0,U-.04*h],[L,U],[ge,b*.55],[N,w],[0,w+.06*h],[-N,w],[-ge,b*.55]]),.7),fill:l.body,...d});let D=g([[-N*.94,w-.1*h],[0,w-.04*h],[N*.94,w-.1*h]]);$.push({k:"path",d:_t(D),stroke:n.extraColors?.[0]??l.accent,lw:.07*h})}else if(y("sheet")){let w=b+.78*h,N=I*1.3;$.push({k:"path",d:Z(g([[-L,U],[L,U],[ge,b*.55],[N,w],[N*.5,w-.2*h],[0,w],[-N*.5,w-.2*h],[-N,w],[-ge,b*.55]]),.9),fill:l.body,...d})}else $.push({k:"path",d:Z(g([[-L,U],[0,U-.04*h],[L,U],[ge,b*.55],[I,X],[0,X+.03*h],[-I,X],[-ge,b*.55]]),.85),fill:l.body,...d});let ie=Math.min(L,I);if(y("pocket")){let w=x(0,b*.74);$.push({k:"rect",x:w.x,y:w.y,w:ie*1.3,h:.3*h,r:.1*h,rot:a.angle,fill:l.belly,stroke:l.outline,lw:m*.8})}else if(y("racing-stripe"))for(let w of[-.1,.1]){let N=x(w*h,U+.02*h),D=x(w*h,X-.04*h);$.push({k:"line",pts:[N.x,N.y,D.x,D.y],stroke:l.belly,lw:.1*h})}else if(l.belly&&l.belly!==l.body&&!y("panel")&&!y("sheet")&&!y("stripes")){let w=x(0,b*.58);$.push({k:"ellipse",x:w.x,y:w.y,rx:ie*.64,ry:Math.max(b*.36,.2*h),rot:a.angle,fill:l.belly})}if(y("spots")){let w=n.extraColors?.[1]??l.belly;for(let[N,D,q]of[[-.55,.35,.09],[.5,.62,.11],[-.35,.86,.07]]){let G=x(N*ie,D*b);$.push({k:"circle",x:G.x,y:G.y,r:q*h,fill:w})}}if(y("stripes")){let w=n.extraColors?.[1]??l.accent;for(let N of[.22,.44,.66]){let D=x(-ie*.98,b*N),q=x(ie*.98,b*N);$.push({k:"line",pts:[D.x,D.y,q.x,q.y],stroke:w,lw:.1*h})}}if(y("straps")){let w=n.extraColors?.[1]??l.outline;for(let N of[-1,1]){let D=x(N*L*.62,U+.02*h),q=x(N*ie*.62,b*.72);$.push({k:"line",pts:[D.x,D.y,q.x,q.y],stroke:l.outline,lw:.13*h+m*2}),$.push({k:"line",pts:[D.x,D.y,q.x,q.y],stroke:w,lw:.13*h})}}if(y("belt")){let w=x(0,b*.9);$.push({k:"rect",x:w.x,y:w.y,w:I*1.92,h:.17*h,r:.06*h,rot:a.angle,fill:n.extraColors?.[2]??"#4a3426",...d}),$.push({k:"rect",x:w.x,y:w.y,w:.2*h,h:.19*h,r:.04*h,rot:a.angle,fill:"#ffd84a",...d})}if(y("emblem")){let w=x(0,b*.4),N=n.extraColors?.[0]??l.accent,D=J([{x:-.22,y:-.2},{x:.22,y:-.2},{x:.22,y:.04},{x:0,y:.26},{x:-.22,y:.04}],.25);$.push({k:"group",x:w.x,y:w.y,rot:a.angle,s:h,items:[{k:"path",d:D,fill:N,stroke:l.outline,lw:m/h},{k:"group",x:0,y:.01,s:.12,items:[{k:"path",d:mt,fill:N===l.accent?"#ffffff":l.accent}]}]})}if(y("panel")){let w=x(0,b*.5);$.push({k:"rect",x:w.x,y:w.y,w:ie*1.2,h:.38*h,r:.1*h,rot:a.angle,fill:"#24323d",...d}),(n.extraColors??["#ff7a6b","#fbd46a","#7ff0ff"]).slice(0,3).forEach((D,q)=>{let G=x((q-1)*ie*.34,b*.5);$.push({k:"circle",x:G.x,y:G.y,r:.075*h,fill:D})})}if(y("badge")){let w=x(-ie*.42,b*.36);$.push({k:"circle",x:w.x,y:w.y,r:.15*h,fill:l.accent,...d}),$.push({k:"group",x:w.x,y:w.y,rot:a.angle,s:.09*h,items:[{k:"path",d:mt,fill:"#ffffff"}]})}if(y("star")){let w=x(-ie*.5,b*.3),N=.15*h;$.push({k:"group",x:w.x,y:w.y,rot:a.angle-.2,s:N,items:[{k:"path",d:mt,fill:n.extraColors?.[0]??"#ffd84a",stroke:l.outline,lw:m*.8/N}]})}if(y("scarf")){let w=Math.max(.04,o.head*(1-o.neck)-.06)*h,N=x(0,w),D=n.extraColors?.[0]??l.accent,q=x(L*.45,w+.28*h);$.push({k:"rect",x:q.x,y:q.y,w:.16*h,h:.42*h,r:.06*h,rot:a.angle+.15,fill:D,...d}),$.push({k:"rect",x:N.x,y:N.y,w:L*2.05,h:.2*h,r:.1*h,rot:a.angle,fill:D,...d})}let Le={k:"group",x:a.head.x,y:a.head.y,rot:a.headRot,s:a.headR,items:ai(n,m/a.headR)};return[...H,...fe,...$,...ne,Le,...pe]}var Bs=new WeakMap,oi=64;function ai(s,n){let e=Number(n.toPrecision(4)),t=Bs.get(s);t||Bs.set(s,t=new Map);let r=t.get(e);return r||(t.size>=oi&&t.clear(),t.set(e,r=Bn(s,e))),r}function ii(s,n,e,t,r,o){let a=s.palette,{d:i,r:l}=e,c=e.U*o,u=Be(Be(n,ue(i,.07*c)),ue(l,t*.06*c)),f={stroke:a.outline,lw:r},h=a.feet??a.limbs;if(s.bodyExtras.includes("fins")){let b=J([{x:-.13,y:-.06},{x:.13,y:-.06},{x:.24,y:.46},{x:-.24,y:.46}],.22);return{k:"group",x:u.x,y:u.y,rot:e.angle,s:c,items:[{k:"path",d:b,fill:h,stroke:a.outline,lw:r/c},{k:"line",pts:[0,.06,0,.38],stroke:a.outline,lw:r/c,alpha:.5}]}}return s.bodyExtras.includes("flippers")?{k:"ellipse",x:u.x,y:u.y,rx:.27*c,ry:.11*c,rot:e.angle,fill:h,...f}:s.bodyExtras.includes("boots")?{k:"rect",x:u.x,y:u.y,w:.4*c,h:.24*c,r:.09*c,rot:e.angle,fill:h,...f}:{k:"ellipse",x:u.x,y:u.y,rx:.2*c,ry:.13*c,rot:e.angle,fill:h,...f}}function li(s,n,e,t){let r=s.palette,{U:o,L:a,S:i,r:l,d:c}=n,u=(m,d)=>({x:i.x+l.x*m+c.x*d,y:i.y+l.y*m+c.y*d}),f=m=>m.map(([d,x])=>u(d,x)),h={stroke:r.outline,lw:t},b=(m,d,x)=>[{k:"path",d:_t(m),stroke:r.outline,lw:d+t*2},{k:"path",d:_t(m),stroke:x,lw:d}],y=[];switch(s.tail){case"none":break;case"fluffy":{let m=f([[e*.5,a*.95],[e+.28*o,a*1],[e+.72*o,a*.62],[e+.78*o,a*.12],[e+.52*o,a*.32],[e+.3*o,a*.6],[e*.6,a*.7]]);y.push({k:"path",d:Z(m),fill:r.body,...h});let d=u(e+.72*o,a*.2);y.push({k:"ellipse",x:d.x,y:d.y,rx:.13*o,ry:.2*o,rot:n.angle+.25,fill:r.belly,...h});break}case"brush":{let m=f([[e*.4,a*.98],[e+.42*o,a*1.06],[e+.98*o,a*.66],[e+1.06*o,a*.12],[e+.86*o,-.04*o],[e+.66*o,a*.36],[e+.3*o,a*.66],[e*.5,a*.68]]);y.push({k:"path",d:Z(m),fill:r.body,...h});let d=f([[e+1.03*o,a*.36],[e+1.06*o,a*.12],[e+.86*o,-.04*o],[e+.72*o,a*.24],[e+.86*o,a*.34]]);y.push({k:"path",d:Z(d),fill:r.belly,...h});break}case"pom":{let m=u(e+.06*o,a*.88);y.push({k:"circle",x:m.x,y:m.y,r:.2*o,fill:r.belly,...h});break}case"long":case"striped":case"tuft":{let m=f([[e*.6,a*.9],[e+.35*o,a*.85],[e+.58*o,a*.4],[e+.5*o,-.02*o]]);if(y.push(...b(m,.14*o,r.body)),s.tail==="tuft"){let d=m[m.length-1];y.push({k:"circle",x:d.x,y:d.y,r:.16*o,fill:s.extraColors?.[0]??r.accent,...h})}if(s.tail==="striped"){for(let x of[.35,.6,.85]){let g=u(e+.35*o+.22999999999999998*o*(x*1.4>1?1:x*1.4),a*(.85-.85*x));y.push({k:"line",pts:[g.x-l.x*.08*o,g.y-l.y*.08*o,g.x+l.x*.08*o,g.y+l.y*.08*o],stroke:s.extraColors?.[0]??r.outline,lw:.06*o})}let d=m[m.length-1];y.push({k:"circle",x:d.x,y:d.y,r:.07*o,fill:s.extraColors?.[0]??r.outline})}break}case"curl":{let m=f([[e*.6,a*.9],[e+.4*o,a*.88],[e+.62*o,a*.45],[e+.5*o,a*.12],[e+.3*o,a*.24],[e+.36*o,a*.42]]);y.push(...b(m,.12*o,r.limbs));break}case"fish":{let m=f([[e*.6,a*.9],[e+.36*o,a*.86],[e+.6*o,a*.5]]);y.push(...b(m,.17*o,r.body));let d=m[m.length-1],x=J([{x:0,y:.06},{x:-.26,y:-.34},{x:.02,y:-.12},{x:.32,y:-.3}],.2);y.push({k:"group",x:d.x,y:d.y,rot:n.angle+.35,s:o,items:[{k:"path",d:x,fill:r.body,stroke:r.outline,lw:t/o}]});break}case"plume":{let m=s.extraColors??[r.accent];[0,1,2].forEach(d=>{let x=u(e+(.12+d*.13)*o,a+(.32-d*.06)*o);y.push({k:"ellipse",x:x.x,y:x.y,rx:.11*o,ry:.44*o,rot:n.angle-.55+d*.28,fill:m[(d+1)%m.length],...h})});break}case"spiky":case"arrow":{let m=f([[e*.3,a*.55],[e+.35*o,a*.68],[e+.95*o,a*.86],[e+.35*o,a*1.08],[e*.3,a*1.08]]);if(s.tail==="spiky"){for(let d of[.15,.45,.72]){let x=e+(.2+d*.7)*o,g=a*(.66+d*.19);y.push({k:"path",d:J(f([[x-.12*o,g+.05*o],[x,g-.2*o],[x+.12*o,g+.07*o]]),.2),fill:r.accent,...h})}y.push({k:"path",d:Z(m,.7),fill:r.body,...h})}else{let d=f([[e*.6,a*.9],[e+.4*o,a*.92],[e+.62*o,a*.5],[e+.62*o,a*.18]]);y.push(...b(d,.13*o,r.body));let x=d[d.length-1];y.push({k:"group",x:x.x,y:x.y,rot:n.angle,s:o,items:[{k:"path",d:J([{x:-.15,y:.04},{x:0,y:-.22},{x:.15,y:.04}],.2),fill:r.accent,stroke:r.outline,lw:t/o}]})}break}}return y}var ci={nose:[0,-.62],leftShoulder:[-.42,0],rightShoulder:[.42,0],leftElbow:[-.58,.5],rightElbow:[.58,.5],leftWrist:[-.66,.98],rightWrist:[.66,.98],leftHip:[-.27,1],rightHip:[.27,1],leftKnee:[-.31,1.6],rightKnee:[.31,1.6],leftAnkle:[-.33,2.18],rightAnkle:[.33,2.18]};function ui(s,{cx:n=.5,cy:e=.36,T:t=.18}={}){let r={...ci,...s},o=new Array(br*3).fill(0),a=(c,[u,f],h=.99)=>{o[c*3]=n+u*t,o[c*3+1]=e+f*t,o[c*3+2]=h};for(let c of Object.keys(Y))a(Y[c],r[c]);let i=r.tilt??0,l=(c,u)=>[r.nose[0]+c*Math.cos(i)-u*Math.sin(i),r.nose[1]+c*Math.sin(i)+u*Math.cos(i)];return a(Ue.leftEye,l(-.1,-.08)),a(Ue.rightEye,l(.1,-.08)),a(Ue.leftEar,l(-.22,-.02)),a(Ue.rightEar,l(.22,-.02)),o}var Us=()=>ui({});var cn=class{constructor(n={}){p(this,"tracks",new Map);p(this,"offset",NaN);p(this,"lastArrival",NaN);p(this,"interval",33);p(this,"lastT",NaN);p(this,"lostMs");p(this,"maxExtrapolateMs");this.lostMs=n.lostMs??250,this.maxExtrapolateMs=n.maxExtrapolateMs??25}get delayMs(){return this.interval}push(n,e,t,r=$s()){Number.isFinite(e)||(e=r),this.clock(e,r);let o=this.tracks.get(n);if(!o||e-o.tb>this.lostMs||e<o.tb-this.lostMs||t.length!==o.b.length){this.tracks.set(n,{a:null,ta:e,b:t,tb:e,out:null,outAt:NaN});return}if(t===o.b||e<=o.tb){e===o.tb&&t!==o.b&&(o.b=t,o.out=null);return}o.a=o.b,o.ta=o.tb,o.b=t,o.tb=e,o.out=null}at(n,e=$s()){let t=this.tracks.get(n);if(!t)return null;if(!t.a)return t.b;if(t.out&&t.outAt===e)return t.out;let r=e-this.offset-this.interval,o=t.tb-t.ta,a=Math.min(o*.5,this.maxExtrapolateMs),i=Math.min(Math.max((r-t.ta)/o,0),1+a/o);return t.out=Hs(t.a,t.b,i),t.outAt=e,t.out}forget(n){this.tracks.delete(n)}clear(){this.tracks.clear()}clock(n,e){let t=e-n;if(!Number.isFinite(this.offset)||t<this.offset||t>this.offset+1e3?this.offset=t:Number.isFinite(this.lastArrival)&&(this.offset+=Math.min(t-this.offset,(e-this.lastArrival)/1e3)),this.lastArrival=e,Number.isFinite(this.lastT)&&n>this.lastT){let r=n-this.lastT;r<this.interval*3+20&&(this.interval+=(Math.min(Math.max(r,8),100)-this.interval)*.1)}n<=this.lastT||(this.lastT=n)}},$s=()=>globalThis.performance?.now()??Date.now();function Hs(s,n,e){let t=n.slice(),r=e<.5?s:n;for(let o=0;o+2<n.length;o+=3){let a=s[o],i=s[o+1],l=n[o],c=n[o+1];s[o+2]>=.5&&n[o+2]>=.5&&Math.abs(l-a)+Math.abs(c-i)<.15?(t[o]=a+(l-a)*e,t[o+1]=i+(c-i)*e,t[o+2]=s[o+2]+(n[o+2]-s[o+2])*Math.min(e,1)):(t[o]=r[o],t[o+1]=r[o+1],t[o+2]=r[o+2])}return t}var Pl=xr.map(s=>s.id);var In=new Map(xr.map(s=>[s.id,s])),yt=In.get("fox"),Gs=s=>typeof s=="string"&&In.has(s),Lt=s=>In.get(s);var fi=s=>typeof s=="string"?In.get(s)??yt:s;function Ws(s,n){let e=fi(s),t=Us(),r=On(e),o=Pt(t,{x:0,y:0,w:1,h:1},{band:r}),a=-Xs(Bn(e,.05)).minY,l=Math.min(.27,.43/Math.max(a,1))*n/nt[r].head/o.U,c=.5*n+Math.min(0,(a-1.6)*.06*n),u={x:n/2-o.head.x*l,y:c-o.head.y*l,w:l,h:l};return ln(t,e,u,{portrait:!0})}function Vs(s,n,e=.5){if(!s||s.length!==n.length)return n.slice();let t=n.slice();for(let r=0;r+2<n.length;r+=3){let o=s[r+2],a=n[r+2],i=o>=.5,l=a>=.5;i&&a>=.3&&(t[r+2]=Math.max(a,.5)),i&&l&&Math.hypot(n[r]-s[r],n[r+1]-s[r+1])<.15?(t[r]=s[r]+(n[r]-s[r])*e,t[r+1]=s[r+1]+(n[r+1]-s[r+1])*e):i&&!l&&t[r+2]>=.5&&(t[r]=s[r],t[r+1]=s[r+1])}return mi(s,n,t,e*pi),t}var pi=.35,di=11;function mi(s,n,e,t){let r=Y.leftShoulder*3,o=Y.rightShoulder*3,a=(f,h)=>f[h+2]>=.5;if(!a(s,r)||!a(s,o)||!a(n,r)||!a(n,o))return;let i=(f,h)=>(f[r+h]+f[o+h])/2,l=[i(s,0),i(s,1)],c=[i(n,0),i(n,1)],u=[i(e,0),i(e,1)];for(let f=0;f<di&&f*3+2<n.length;f++){let h=f*3;if(!a(s,h)||!a(n,h))continue;let b=[s[h]-l[0],s[h+1]-l[1]],y=[n[h]-c[0],n[h+1]-c[1]];Math.hypot(y[0]-b[0],y[1]-b[1])>=.15||(e[h]=u[0]+b[0]+(y[0]-b[0])*t,e[h+1]=u[1]+b[1]+(y[1]-b[1])*t)}}function Xs(s){let n={minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0},e=(t,r)=>{n.minX=Math.min(n.minX,t),n.minY=Math.min(n.minY,r),n.maxX=Math.max(n.maxX,t),n.maxY=Math.max(n.maxY,r)};for(let t of s){let r="lw"in t&&t.stroke?(t.lw??1)/2:0;switch(t.k){case"circle":e(t.x-t.r-r,t.y-t.r-r),e(t.x+t.r+r,t.y+t.r+r);break;case"ellipse":case"rect":{let o=t.k==="ellipse"?t.rx:t.w/2,a=t.k==="ellipse"?t.ry:t.h/2,i=Math.max(o,a)+r;e(t.x-i,t.y-i),e(t.x+i,t.y+i);break}case"path":{let o=gr(t.d);for(let a=0;a+1<o.length;a+=2)e(o[a]-r,o[a+1]-r),e(o[a]+r,o[a+1]+r);break}case"line":for(let o=0;o+1<t.pts.length;o+=2)e(t.pts[o]-r,t.pts[o+1]-r),e(t.pts[o]+r,t.pts[o+1]+r);break;case"group":{let o=Xs(t.items);if(!Number.isFinite(o.minX))break;let a=t.s??1,i=Math.cos(t.rot??0),l=Math.sin(t.rot??0);for(let[c,u]of[[o.minX,o.minY],[o.maxX,o.minY],[o.minX,o.maxY],[o.maxX,o.maxY]])e(t.x+(c*i-u*l)*a,t.y+(c*l+u*i)*a);break}}}return n}var Ke=()=>Float64Array.of(1,0,0,1,0,0);function we(s,n,e,t,r,o,a){let i=r?Math.cos(r):1,l=r?Math.sin(r):0,c=i*o,u=l*o,f=-l*a,h=i*a;if(!n)return s[0]=c,s[1]=u,s[2]=f,s[3]=h,s[4]=e,s[5]=t,s;let b=n[0],y=n[1],m=n[2],d=n[3];return s[0]=b*c+m*u,s[1]=y*c+d*u,s[2]=b*f+m*h,s[3]=y*f+d*h,s[4]=b*e+m*t+n[4],s[5]=y*e+d*t+n[5],s}function js(s,n,e){let t=s[0]*s[3]-s[1]*s[2];if(Math.abs(t)<1e-12)return null;let r=n-s[4],o=e-s[5];return[(s[3]*r-s[2]*o)/t,(-s[1]*r+s[0]*o)/t]}var qs={white:16777215,black:0,red:16711680,transparent:0},un=new Map;function he(s){if(typeof s=="number")return[s&16777215,1];let n=un.get(s);if(n)return n;let e=[16777215,1],t=s.trim().toLowerCase();if(t[0]==="#"){let r=t.slice(1),o=r.length<=4?[...r].map(i=>i+i).join(""):r,a=parseInt(o.slice(0,6),16);Number.isFinite(a)&&(e=[a,o.length===8?parseInt(o.slice(6,8),16)/255:1])}else if(t.startsWith("rgb")){let r=t.match(/-?\d*\.?\d+%?/g)?.map(c=>c.endsWith("%")?parseFloat(c)/100*255:parseFloat(c))??[],[o=255,a=255,i=255]=r,l=r[3]===void 0?1:t.match(/,\s*[\d.]+%\s*\)$/)?r[3]/255:r[3];e=[(wr(o)<<16|wr(a)<<8|wr(i))>>>0,Math.min(Math.max(l,0),1)]}else if(t in qs)e=[qs[t],t==="transparent"?0:1];else if(typeof document<"u"){let r=document.createElement("canvas").getContext("2d");if(r){r.fillStyle="#ffffff",r.fillStyle=t;let o=r.fillStyle;if(o!==t)return un.set(s,e=he(o)),e}}return un.size>512&&un.clear(),un.set(s,e),e}var wr=s=>Math.min(Math.max(Math.round(s),0),255);function rt(s,n,e=!1){let t=Math.min(Math.max(n,0),1),r=(s>>16&255)*t,o=(s>>8&255)*t,a=(s&255)*t,i=e?0:t*255;return(Math.round(i)<<24|Math.round(a)<<16|Math.round(o)<<8|Math.round(r))>>>0}var xt=(s,n=1)=>`rgba(${s>>16&255},${s>>8&255},${s&255},${n})`;function Ar(s,n){if(s===16777215)return n;if(n===16777215)return s;let e=t=>Math.round((s>>t&255)*(n>>t&255)/255);return(e(16)<<16|e(8)<<8|e(0))>>>0}var st={linear:s=>s,quadIn:s=>s*s,quadOut:s=>s*(2-s),quadInOut:s=>s<.5?2*s*s:-1+(4-2*s)*s,cubicOut:s=>1-(1-s)**3,sineInOut:s=>-(Math.cos(Math.PI*s)-1)/2,backOut:s=>1+(1.70158+1)*(s-1)**3+1.70158*(s-1)**2,elasticOut:s=>s===0||s===1?s:2**(-10*s)*Math.sin((s*10-.75)*(2*Math.PI/3))+1,bounceOut:s=>s<1/2.75?7.5625*s*s:s<2/2.75?7.5625*(s-=1.5/2.75)*s+.75:s<2.5/2.75?7.5625*(s-=2.25/2.75)*s+.9375:7.5625*(s-=2.625/2.75)*s+.984375};function Ys(s){let n=s>>>0;return()=>{n=n+1831565813>>>0;let e=n;return e=Math.imul(e^e>>>15,e|1),e^=e+Math.imul(e^e>>>7,e|61),((e^e>>>14)>>>0)/4294967296}}var T={cap:0,epoch:0,x:new Float64Array(0),y:new Float64Array(0),rot:new Float64Array(0),sx:new Float64Array(0),sy:new Float64Array(0),alpha:new Float64Array(0),la:new Float64Array(0),lb:new Float64Array(0),lc:new Float64Array(0),ld:new Float64Array(0),world:new Float64Array(0),tint:new Uint32Array(0),flags:new Uint8Array(0),moved:new Uint8Array(0),dirty:new Uint8Array(0),gen:new Uint32Array(0),parent:new Int32Array(0),first:new Int32Array(0),next:new Int32Array(0),prev:new Int32Array(0),stamp:new Uint32Array(0),pass:0,free:new Int32Array(0),freeHead:0,freeCount:0,top:2},ot=[],bi="x y rot sx sy alpha la lb lc ld world tint flags moved dirty gen parent first next prev stamp".split(" ");function Ks(s){let n=T;for(let t of bi){let r=n[t],o=new r.constructor(t==="world"?s*6:s);o.set(r),n[t]=o}let e=new Int32Array(s);for(let t=0;t<T.freeCount;t++)e[t]=T.free[(T.freeHead+t)%T.cap];for(T.free=e,T.freeHead=0,T.cap=s,T.epoch++;ot.length<s;)ot.push(null)}function Mr(s){T.x[s]=T.y[s]=T.rot[s]=0,T.sx[s]=T.sy[s]=T.alpha[s]=1,T.la[s]=T.ld[s]=1,T.lb[s]=T.lc[s]=0;let n=s*6,e=T.world;e[n]=e[n+3]=1,e[n+1]=e[n+2]=e[n+4]=e[n+5]=0,T.tint[s]=16777215,T.flags[s]=3,T.moved[s]=1,T.dirty[s]=0,T.parent[s]=T.first[s]=T.next[s]=T.prev[s]=-1}Ks(256);Mr(0);T.flags[0]=0;Mr(1);T.flags[1]=0;function Qs(){let s;if(T.freeCount){s=T.free[T.freeHead],T.freeHead=(T.freeHead+1)%T.cap,T.freeCount--;let n=ot[s];n&&(n._i=0,n._g=-1,ot[s]=null)}else T.top===T.cap&&Ks(T.cap*2),s=T.top++;return Mr(s),s}function Tr(s,n){zn(s);for(let t=T.first[s];t>=0;){let r=T.next[t];T.parent[t]=T.next[t]=T.prev[t]=-1,t=r}T.first[s]=-1,T.flags[s]=T.flags[s]&-3,T.moved[s]=0;let e=T.gen[s]+1;T.gen[s]=e,e!==4294967295&&(n&&(ot[s]=n),T.free[(T.freeHead+T.freeCount)%T.cap]=s,T.freeCount++)}function Zs(s){for(let n=0;n<ot.length;n++){let e=ot[n];e&&s(e)&&(e._i=0,e._g=-1,ot[n]=null)}}function Js(s,n){zn(s);let e=T.first[n];T.parent[s]=n,T.next[s]=e,T.prev[s]=-1,e>=0&&(T.prev[e]=s),T.first[n]=s,T.moved[s]=1}function zn(s){let n=T.parent[s];if(n<0)return;let e=T.next[s],t=T.prev[s];t>=0?T.next[t]=e:T.first[n]=e,e>=0&&(T.prev[e]=t),T.parent[s]=T.next[s]=T.prev[s]=-1}var hn={root:-1,gen:-1,world:new Float64Array(6)};function eo(s){let n=++T.pass,e=T.world,t=s*6,r=hn.world,o=hn.root!==s||hn.gen!==T.gen[s];for(let a=0;a<6;a++)r[a]!==e[t+a]&&(o=!0),r[a]=e[t+a];hn.root=s,hn.gen=T.gen[s],T.stamp[s]=o?n:n-1}function to(s){T.stamp[s]=T.pass}function no(s){for(let n=T.first[s];n>=0;){let e=T.next[n];no(n),n=e}Tr(s)}var Sr=typeof FinalizationRegistry=="function"?new FinalizationRegistry(s=>T.gen[s.i]===s.g&&no(s.i)):null;function Er(s){s._reg||!Sr||(s._reg=!0,Sr.register(s,{i:s._i,g:s._g},s))}function ro(s){s._reg&&Sr.unregister(s)}function fn(s){if(s){for(let n=0;n<s.length;n++)if(s[n].enabled)return!0}return!1}function so(s,n){let e=0;for(let t=0;t<s.length;t++){let r=s[t];r.enabled&&r.pad&&(e+=r.pad(n))}return e}var Ae={gl:null,c2d:null,live:null};var j=new Float64Array(3),pn=4,yi=1,dn=()=>yi++;var re=Ke(),_=T,Fe=class{constructor(n){p(this,"kernel",n);p(this,"_i",Qs());p(this,"_g",_.gen[this._i]);p(this,"_wv",null);p(this,"_wi",-1);p(this,"_we",-1);p(this,"blend","normal");p(this,"_data",null);p(this,"parent",null);p(this,"hitRadius",null);p(this,"clip",null);p(this,"mask",null);p(this,"filters",null);p(this,"_z",0);p(this,"anchorX",0);p(this,"anchorY",0);p(this,"_pool",null);p(this,"_free",!1);p(this,"_reg",!1)}get x(){return _.x[this._i]}set x(n){let e=this._i||1;_.x[e]=n,_.moved[e]=1}get y(){return _.y[this._i]}set y(n){let e=this._i||1;_.y[e]=n,_.moved[e]=1}get rotation(){return _.rot[this._i]}set rotation(n){let e=this._i||1;_.rot[e]=n,_.dirty[e]=_.moved[e]=1}get scaleX(){return _.sx[this._i]}set scaleX(n){let e=this._i||1;_.sx[e]=n,_.dirty[e]=_.moved[e]=1}get scaleY(){return _.sy[this._i]}set scaleY(n){let e=this._i||1;_.sy[e]=n,_.dirty[e]=_.moved[e]=1}get alpha(){return _.alpha[this._i]}set alpha(n){let e=this._i||1;_.alpha[e]=n,_.moved[e]=1}get visible(){return(_.flags[this._i]&1)!==0}set visible(n){let e=this._i||1;n?_.flags[e]=_.flags[e]|1:_.flags[e]=_.flags[e]&-2,_.moved[e]=1}get destroyed(){return _.gen[this._i]!==this._g}get world(){let n=this._i||1;return(this._wi!==n||this._we!==_.epoch)&&(this._wv=_.world.subarray(n*6,n*6+6),this._wi=n,this._we=_.epoch),this._wv}get data(){return this._data??(this._data={})}set data(n){this._data=n}get scale(){return this.scaleX}set scale(n){this.scaleX=this.scaleY=n}get z(){return this._z}set z(n){n!==this._z&&(this._z=n,this.parent&&(this.parent.sortDirty=!0))}get tint(){return _.tint[this._i]}set tint(n){_.tint[this._i||1]=typeof n=="number"?n&16777215:he(n)[0]}set anchor(n){typeof n=="number"?this.anchorX=this.anchorY=n:(this.anchorX=n.x,this.anchorY=n.y)}get width(){return 0}set width(n){}get height(){return 0}set height(n){}set(n){for(let e in n){let t=n[e];t!==void 0&&(this[e]=t)}return this}destroy(){this.destroyed||(this.visible=!1,this.parent&&(this.parent.dead=!0,this.parent=null),Tr(this._i,this),ro(this),this.kernel.tweens.stopAll(this),this._pool?.forget(this))}updateWorld(){let n=this.parent?this.parent.updateWorld():null;return we(this.world,n,this.x,this.y,this.rotation,this.scaleX,this.scaleY)}draw(n,e,t){}};function lo(s){Zs(n=>n.kernel===s)}var Rr=!1,oo=Object.freeze([]),vt=class s extends Fe{constructor(e){super(e);p(this,"children",oo);p(this,"sortDirty",!1);p(this,"dead",!1);Er(this)}add(e,...t){this.adopt(e);for(let r=0;r<t.length;r++)this.adopt(t[r]);return e}adopt(e){e.parent&&e.parent.detach(e),e.parent=this,!e.destroyed&&!this.destroyed&&Js(e._i,this._i),this.children===oo&&(this.children=[]),this.children.push(e),(e.z!==0||this.sortDirty)&&(this.sortDirty=!0)}remove(e){this.detach(e),e._pool||Er(e)}detach(e){let t=this.children,r=t.indexOf(e);if(r>=0){for(let o=r+1;o<t.length;o++)t[o-1]=t[o];t.pop()}e.parent===this&&(e.parent=null,e.destroyed||zn(e._i))}clear(){for(let e of this.children)e.destroy()}destroy(){for(let e of this.children)e.destroy();super.destroy()}sweep(){if(this.dead){this.dead=!1;let e=0;for(let t of this.children)t.destroyed?t.parent===this&&(t.parent=null):this.children[e++]=t;this.children.length=e}for(let e of this.children)e instanceof s&&e.sweep()}draw(e,t,r){if(Rr)return _.parent[this._i]<0&&!this.destroyed&&to(this._i),this.drawChildren(e,t,r);Rr=!0;try{this.destroyed||eo(this._i),this.drawChildren(e,t,r)}finally{Rr=!1}}drawChildren(e,t,r){if(this.sortDirty){let l=new Map(this.children.map((c,u)=>[c,u]));this.children.sort((c,u)=>c.z-u.z||l.get(c)-l.get(u)),this.sortDirty=!1}let o=this.children,a=this._i,i=_.stamp[a]===_.pass;for(let l=0;l<o.length;l++){let c=o[l],u=c._i,f=_.alpha[u];if(_.gen[u]!==c._g||!(_.flags[u]&1)||f<=0)continue;if(i||_.moved[u]){_.moved[u]=0,_.stamp[u]=_.pass;let y,m,d,x;if(_.dirty[u]){_.dirty[u]=0;let U=_.rot[u],X=U?Math.cos(U):1,H=U?Math.sin(U):0,fe=_.sx[u],$=_.sy[u];_.la[u]=y=X*fe,_.lb[u]=m=H*fe,_.lc[u]=d=-H*$,_.ld[u]=x=X*$}else y=_.la[u],m=_.lb[u],d=_.lc[u],x=_.ld[u];let g=_.world,M=_.x[u],v=_.y[u],A=u*6,E=a*6,C=g[E],P=g[E+1],L=g[E+2],I=g[E+3];g[A]=C*y+L*m,g[A+1]=P*y+I*m,g[A+2]=C*d+L*x,g[A+3]=P*d+I*x,g[A+4]=C*M+L*v+g[E+4],g[A+5]=P*M+I*v+g[E+5]}let h=t*f,b=Ar(r,_.tint[u]);c.clip||c.mask||c.filters?co(e,c,h,b):c.draw(e,h,b)}}},be=new Float64Array(128),gt=0,Fr=new Float64Array(8);function Cr(s,n,e,t){n.clip||n.mask||n.filters?co(s,n,e,t):n.draw(s,e,t)}function co(s,n,e,t){let r=s.r,o=n.world,a=n.clip,i=!1,l=!1;if(a)if(Math.abs(o[1])<1e-9&&Math.abs(o[2])<1e-9&><32){let f=o[0]*a.x+o[4],h=o[0]*(a.x+a.width)+o[4],b=o[3]*a.y+o[5],y=o[3]*(a.y+a.height)+o[5],m=Math.min(f,h),d=Math.max(f,h),x=Math.min(b,y),g=Math.max(b,y);if(gt){let v=(gt-1)*4;m=Math.max(m,be[v]),x=Math.max(x,be[v+1]),d=Math.min(d,be[v+2]),g=Math.min(g,be[v+3])}let M=gt++*4;be[M]=m,be[M+1]=x,be[M+2]=d,be[M+3]=g,r.clip(m,x,Math.max(d-m,0),Math.max(g-x,0)),l=!0}else i=!0;let c=n.mask&&n.mask.visible?n.mask:null,u=fn(n.filters)?n.filters:null;try{if(i&&r.beginLayer(),c&&r.beginLayer(),u?(n.draw(s,r.beginLayer()?1:e,t),r.endLayer(e,u)):n.draw(s,e,t),c&&(r.beginMask(),we(c.world,o,c.x,c.y,c.rotation,c.scaleX,c.scaleY),Cr(s,c,c.alpha,16777215),r.endLayer(1)),i&&a){r.beginMask();for(let f=0;f<4;f++){let h=f===1||f===2?a.x+a.width:a.x,b=f>1?a.y+a.height:a.y;Fr[f*2]=o[0]*h+o[2]*b+o[4],Fr[f*2+1]=o[1]*h+o[3]*b+o[5]}r.polygon(Fr,4,16777215,1),r.endLayer(1)}}finally{if(l)if(gt--,gt){let f=(gt-1)*4;r.clip(be[f],be[f+1],be[f+2]-be[f],be[f+3]-be[f+1])}else r.unclip()}}var Se=class extends Fe{constructor(e,t,r){super(e);p(this,"_frame",null);p(this,"_w",null);p(this,"_h",null);p(this,"slice",0);p(this,"autoAnchor",!0);p(this,"frameName",null);t&&(this.frame=t),r?.anchor===void 0&&this.useFrameAnchor(),r&&this.set(r)}get frame(){return this._frame}set frame(e){this.frameName=typeof e=="string"?e:null,this._frame=typeof e=="string"?this.kernel.frame(e):e,this.autoAnchor&&this.useFrameAnchor()}set anchor(e){this.autoAnchor=!1,super.anchor=e}get naturalWidth(){let e=this.frameNow();return e?(e.sw??e.w)/e.scale-e.margin*2:0}get naturalHeight(){let e=this.frameNow();return e?(e.sh??e.h)/e.scale-e.margin*2:0}get width(){return this._w??this.naturalWidth}set width(e){this._w=e}get height(){return this._h??this.naturalHeight}set height(e){this._h=e}sizeQ(e){Dt[0]=this._w??(e.sw??e.w)/e.scale-e.margin*2,Dt[1]=this._h??(e.sh??e.h)/e.scale-e.margin*2}frameNow(){return this.frameName&&!this.kernel.atlas.valid(this._frame)&&(this._frame=this.kernel.frame(this.frameName)),this._frame}useFrameAnchor(){let e=this._frame;if(!e)return;let t=(e.sw??e.w)/e.scale-e.margin*2,r=(e.sh??e.h)/e.scale-e.margin*2;this.anchorX=t>0?(e.ox-e.margin)/t:0,this.anchorY=r>0?(e.oy-e.margin)/r:0}draw(e,t,r){let o=this.frameNow();if(!o)return;let a=Dt;this.sizeQ(o),a[2]=this.anchorX,a[3]=this.anchorY,a[4]=t,xi(e,o,this.world,this.slice,r,this.blend)}},Nt=new Float64Array(12),Bt=new Float64Array(12),mn={x:0,y:0,w:0,h:0};function ao(s,n,e,t,r,o){n=Math.max(n,0),e=Math.max(e,0),t=Math.max(t,0);let a=e+t>r?e*r/(e+t):e,i=e+t>r?t*r/(e+t):t,l=a/o,c=i/o;if(l+c>n){let u=n/(l+c);l*=u,c*=u}s[0]=0,s[1]=l,s[2]=0,s[3]=a,s[4]=l,s[5]=n-l-c,s[6]=a,s[7]=r-a-i,s[8]=n-c,s[9]=c,s[10]=r-i,s[11]=i}var Dt=new Float64Array(5);function xi(s,n,e,t,r,o){let a=Dt,i=a[0],l=a[1],c=a[2],u=a[3],f=a[4],h=s.tex(n.surface),b=t===0?n.slice??0:t;if(b===0){let v=(n.sw??n.w)/n.scale-n.margin*2,A=(n.sh??n.h)/n.scale-n.margin*2,E=v>0?i/v:1,C=A>0?l/A:1,P=-c*i+((n.tx??0)/n.scale-n.margin)*E,L=-u*l+((n.ty??0)/n.scale-n.margin)*C;bn(e,P,L),j[0]=n.w/n.scale*E,j[1]=n.h/n.scale*C,j[2]=f,s.r.quadQ(h,n,re,r,o);return}let y=n.tx??0,m=n.ty??0,d=(n.sw??n.w)-n.w-y,x=(n.sh??n.h)-n.h-m,g=-c*i-n.margin+y/n.scale,M=-u*l-n.margin+m/n.scale;if(ao(Nt,i+n.margin*2-(y+d)/n.scale,(typeof b=="number"?b:b[3])-y,(typeof b=="number"?b:b[1])-d,n.w,n.scale),ao(Bt,l+n.margin*2-(m+x)/n.scale,(typeof b=="number"?b:b[0])-m,(typeof b=="number"?b:b[2])-x,n.h,n.scale),bn(e,g,M),j[2]=f,!s.r.nineQ?.(h,n,Nt,Bt,re,r,o))for(let v=0;v<12;v+=4){let A=Bt[v+1],E=Bt[v+3];if(!(A<=0||E<=0))for(let C=0;C<12;C+=4){let P=Nt[C+1],L=Nt[C+3];P<=0||L<=0||(mn.x=n.x+Nt[C+2],mn.y=n.y+Bt[v+2],mn.w=L,mn.h=E,bn(e,g+Nt[C],M+Bt[v]),j[0]=P,j[1]=A,j[2]=f,s.r.quadQ(h,mn,re,r,o))}}}function bn(s,n,e){re[0]=s[0],re[1]=s[1],re[2]=s[2],re[3]=s[3],re[4]=s[0]*n+s[2]*e+s[4],re[5]=s[1]*n+s[3]*e+s[5]}var $e=class extends Se{constructor(e,t,r={}){super(e,null);p(this,"_spec");p(this,"baked",null);p(this,"bakedEffects",!0);this._spec=t,this.bake(),r.anchor===void 0&&this.useFrameAnchor(),this.set(r)}get spec(){return this._spec}set spec(e){this._spec=e,this.baked=null,this._w=this._h=null,this.bake()}bake(){let e=this.kernel;return this.baked&&e.atlas.valid(this.baked.frame)&&this.baked.frame.scale===e.pixelScale&&this.bakedEffects===e.effects?this.baked:(this.bakedEffects=e.effects,this.baked=e.shape(this._spec),this._frame=this.baked.frame,this.slice=this.baked.slice,this.baked)}frameNow(){return this.bake().frame}sizeQ(){let e=this.bake();Dt[0]=this._w??e.w,Dt[1]=this._h??e.h}get width(){return this._w??this.bake().w}set width(e){this._w=e}get height(){return this._h??this.bake().h}set height(e){this._h=e}},io=(s,n,e)=>s===void 0?n:typeof s=="number"?s:s[0]+(s[1]-s[0])*e(),kt=class kt extends Fe{constructor(e,t,r={}){super(e);p(this,"max");p(this,"f");p(this,"tints");p(this,"count",0);p(this,"gravity");p(this,"drag");p(this,"frameRef");p(this,"random",Math.random);this.frameRef=t,this.max=Math.max(1,Math.floor(r.max??200)),this.f=new Float32Array(this.max*kt.W),this.tints=new Uint32Array(this.max),this.blend=r.blend??"normal",this.gravity=r.gravity??0,this.drag=r.drag??1}get alive(){return this.count}burst(e,t,r,o={}){let a=kt.W,i=this.random,l=o.tint===void 0?16777215:he(o.tint)[0];for(let c=0;c<r;c++){let u=this.count;if(u>=this.max){let d=0,x=1/0;for(let g=0;g<this.max;g++){let M=this.f[g*a+5]-this.f[g*a+4];M<x&&(x=M,d=g)}u=d}else this.count++;let f=(o.angle??0)+(o.spread===void 0?i()*Math.PI*2:(i()-.5)*o.spread),h=io(o.speed,200,i),b=Array.isArray(o.scale)?o.scale[0]:o.scale??1,y=Array.isArray(o.scale)?o.scale[1]:o.scale??1,m=u*a;this.f[m]=e,this.f[m+1]=t,this.f[m+2]=Math.cos(f)*h,this.f[m+3]=Math.sin(f)*h,this.f[m+4]=0,this.f[m+5]=Math.max(io(o.life,.8,i),.01),this.f[m+6]=i()*Math.PI*2,this.f[m+7]=(i()-.5)*2*(o.spin??0),this.f[m+8]=b,this.f[m+9]=y,this.f[m+10]=o.alpha??1,this.tints[u]=l}}update(e){let t=kt.W,r=this.f,o=this.drag>=1?1:Math.pow(Math.max(this.drag,0),e);for(let a=0;a<this.count;){let i=a*t;if(r[i+4]=r[i+4]+e,r[i+4]>=r[i+5]){let l=--this.count;a!==l&&(r.copyWithin(i,l*t,l*t+t),this.tints[a]=this.tints[l]);continue}r[i+3]=(r[i+3]+this.gravity*e)*o,r[i+2]=r[i+2]*o,r[i]=r[i]+r[i+2]*e,r[i+1]=r[i+1]+r[i+3]*e,r[i+6]=r[i+6]+r[i+7]*e,a++}}clear(){this.count=0}draw(e,t,r){if(!this.count)return;let o=typeof this.frameRef=="string"?this.frameRef=this.kernel.frame(this.frameRef):this.frameRef,a=kt.W,i=this.f,l=this.world,c=o.w/o.scale,u=o.h/o.scale;for(let f=0;f<this.count;f++){let h=f*a,b=i[h+4]/i[h+5],y=i[h+8]+(i[h+9]-i[h+8])*b,m=t*i[h+10]*(1-b*b),d=i[h+6],x=Math.cos(d)*y,g=Math.sin(d)*y,M=i[h],v=i[h+1],A=l[0],E=l[1],C=l[2],P=l[3],L=A*x+C*g,I=E*x+P*g,U=C*x-A*g,X=P*x-E*g;re[0]=L,re[1]=I,re[2]=U,re[3]=X,re[4]=A*M+C*v+l[4]-(L*c+U*u)/2,re[5]=E*M+P*v+l[5]-(I*c+X*u)/2,j[0]=c,j[1]=u,j[2]=m,e.r.quadQ(e.tex(o.surface),o,re,Ar(r,this.tints[f]),this.blend)}}};p(kt,"W",11);var Ot=kt;var Ce=class extends Se{constructor(e,t,r={}){let{fps:o,loop:a,playing:i,speed:l,onComplete:c,...u}=r;if(!t.frames.length)throw new Error("[engine] an animation needs at least one frame");super(e,t.frames[0],u);p(this,"frames");p(this,"durations");p(this,"fps");p(this,"loop");p(this,"speed");p(this,"onComplete");p(this,"_playing");p(this,"index",0);p(this,"t",0);this.frames=t.frames,this.durations=t.durations&&o===void 0?t.durations:null,this.fps=o??12,this.loop=a!==!1,this.speed=l??1,this.onComplete=c??null,this._playing=i!==!1,this.speed<0&&this.show(t.frames.length-1)}get frameIndex(){return this.index}get frameCount(){return this.frames.length}get playing(){return this._playing}play(){return!this.loop&&!this._playing&&this.index===(this.speed<0?0:this.frames.length-1)&&this.show(this.speed<0?this.frames.length-1:0),this._playing=!0,this}stop(){return this._playing=!1,this}gotoFrame(e){let t=this.frames.length;return this.show((Math.floor(e)%t+t)%t),this.t=0,this}gotoAndPlay(e){return this._playing=!0,this.gotoFrame(e)}gotoAndStop(e){return this._playing=!1,this.gotoFrame(e)}show(e){e===this.index&&this._frame||(this.index=e,this.frame=this.frames[e])}secondsOf(e){let t=this.durations?.[e];return t!==void 0&&t>0?t:1/Math.max(this.fps,.001)}update(e){if(!this._playing||this.destroyed||this.speed===0)return;let t=this.frames.length,r=this.speed<0;this.t+=e*Math.abs(this.speed);let o=this.index;for(let a=0;a<1e3;a++){let i=this.secondsOf(o);if(this.t<i)break;this.t-=i;let l=r?o-1:o+1;if(l<0||l>=t){if(!this.loop){this.t=0,this._playing=!1,this.show(o),this.onComplete?.();return}o=r?t-1:0}else o=l}this.show(o)}},uo=(s,n)=>s.localeCompare(n,void 0,{numeric:!0});var yn=class{constructor(n,e,t=2){p(this,"width",n);p(this,"height",e);p(this,"padding",t);p(this,"shelves",[]);p(this,"free",[]);p(this,"bottom",0)}alloc(n,e){let t=Math.ceil(n)+this.padding*2,r=Math.ceil(e)+this.padding*2;if(t>this.width||r>this.height)return null;for(let i=0;i<this.free.length;i++){let l=this.free[i];if(l.w>=t&&l.h>=r&&l.w*l.h<=t*r*2)return this.free.splice(i,1),this.inner(l.x,l.y,n,e)}let o=null;for(let i of this.shelves)i.h>=r&&i.h<=r*1.5+8&&this.width-i.x>=t&&(!o||i.h<o.h)&&(o=i);if(!o)if(this.bottom+r>this.height){for(let i of this.shelves)i.h>=r&&this.width-i.x>=t&&(o=i);if(!o)return null}else o={y:this.bottom,h:r,x:0},this.shelves.push(o),this.bottom+=r;let a=o.x;return o.x+=t,this.inner(a,o.y,n,e)}release(n){this.free.push({x:n.x-this.padding,y:n.y-this.padding,w:Math.ceil(n.w)+this.padding*2,h:Math.ceil(n.h)+this.padding*2})}get fill(){return this.bottom/this.height}reset(){this.shelves=[],this.free=[],this.bottom=0}inner(n,e,t,r){return{x:n+this.padding,y:e+this.padding,w:t,h:r}}},It=s=>({source:s,texture:null,pending:[]}),at=class{constructor(n=2048,e=4){p(this,"pageSize",n);p(this,"maxPages",e);p(this,"pages",[]);p(this,"gen",1);p(this,"onPage",()=>{});p(this,"onDrop",()=>{})}valid(n){return!!n&&(n.gen===this.gen||n.gen===0)}bake(n,e,t,r=1,o=0,a=0,i=0){let l=Math.max(1,Math.ceil(n)),c=Math.max(1,Math.ceil(e)),u=document.createElement("canvas");u.width=l,u.height=c;let f=u.getContext("2d");return t(f),this.put(u,l,c,r,o,a,i)}add(n,e=1,t=0,r=0){let o=document.createElement("canvas");return o.width=Math.max(1,n.width),o.height=Math.max(1,n.height),o.getContext("2d").drawImage(n,0,0),this.put(o,o.width,o.height,e,t,r,0)}release(n){if(n.gen!==this.gen)return;this.pages.find(t=>t.surface===n.surface)?.packer.release(n)}rebake(n,e,t,r,o=n.w,a=n.h){if(!this.valid(n)||e>o||t>a)return null;let i=Math.max(1,Math.ceil(e)),l=Math.max(1,Math.ceil(t)),c=this.pages.find(f=>f.surface===n.surface);if(!c)return null;let u=document.createElement("canvas");return u.width=Math.ceil(o),u.height=Math.ceil(a),r(u.getContext("2d")),c.ctx.clearRect(n.x,n.y,u.width,u.height),c.ctx.drawImage(u,n.x,n.y),n.surface.pending.push([u,n.x,n.y]),n.w=i,n.h=l,n}put(n,e,t,r,o,a,i){let l=null,c=this.pages.find(f=>(l=f.packer.alloc(e,t))!==null);if(c||(!(Math.max(e,t)+4>this.pageSize)&&this.pages.length>=this.maxPages&&(this.wipe(),c=this.pages[0],l=c?c.packer.alloc(e,t):null),(!c||!l)&&(c=this.newPage(Math.max(e,t)),l=c.packer.alloc(e,t))),!l)throw new Error(`[engine] ${e}\xD7${t} does not fit an atlas page`);let u=l;return c.ctx.drawImage(n,u.x,u.y),c.surface.pending.push([n,u.x,u.y]),{surface:c.surface,x:u.x,y:u.y,w:e,h:t,scale:r,gen:this.gen,ox:o,oy:a,margin:i}}newPage(n){let e=this.pageSize;for(;e<n+4;)e*=2;let t=document.createElement("canvas");t.width=t.height=e;let r=t.getContext("2d"),o=It(t),a={surface:o,packer:new yn(e,e),ctx:r};return this.pages.push(a),this.onPage(o),a}wipe(){this.gen++;let n=0;for(let e=0;e<this.pages.length;e++){let t=this.pages[e];if(n<this.maxPages&&t.surface.source.width===this.pageSize){this.pages[n++]=t;continue}t.surface.pending=[],this.onDrop(t.surface)}this.pages.length=n;for(let e of this.pages)e.packer.reset(),e.ctx.clearRect(0,0,e.surface.source.width,e.surface.source.height),e.surface.pending=[],e.surface.pending.push([e.surface.source,0,0])}};var gi=()=>{let s=typeof document<"u"?document.timeline?.currentTime:null;return typeof s=="number"&&Number.isFinite(s)?s:globalThis.performance?.now()??Date.now()},ho=()=>globalThis.performance?.now()??Date.now(),xn=class{constructor(n=gi){p(this,"now",n);p(this,"known",new Map);p(this,"smoothed",new Map);p(this,"times",new WeakMap);p(this,"lerp",new cn);p(this,"drawnAt",NaN);p(this,"drawn",0);p(this,"smoothedBody",(n,e={})=>{let t=e.interpolate!==!1;if(typeof n=="number"){let r=this.smoothed.get(n);return r?t?this.lerp.at(n,this.tick())??r.body:r.body:null}return typeof n!="object"||n===null||!Array.isArray(n.body)?null:this.posed(n.id,n.body,ki(e.smooth),t)})}note(n,e,t=ho()){for(let r of n)this.known.set(r.id,this.resolve(r.id,r.avatar)),e!==void 0&&Number.isFinite(e)&&Array.isArray(r.body)&&this.times.set(r.body,{t:e,arrival:t})}of(n){return typeof n=="object"&&n!==null?n.avatar!==void 0?this.resolve(n.id,n.avatar):this.of(n.id):this.known.get(n)??yr(n-1)}posed(n,e,t,r=!0){let o=this.smooth(n,e,t);return r?this.lerp.at(n,this.tick())??o:o}smooth(n,e,t){let r=this.smoothed.get(n);if(r&&r.raw===e&&r.amount===t)return r.body;r&&r.amount!==t&&this.lerp.forget(n);let o=t<1?Vs(r?.body,e,t):e;this.smoothed.set(n,{raw:e,body:o,amount:t});let a=this.times.get(e),i=a?.arrival??ho();return this.lerp.push(n,a?.t??i,o,i),o}takeDrawn(){let n=this.drawn;return this.drawn=0,n}tick(){let n=this.now();return n!==this.drawnAt&&(this.drawnAt=n,this.drawn++),n}resolve(n,e){return Gs(e)?e:yr(n-1)}};var ki=s=>s===!1?1:typeof s=="number"?Math.min(Math.max(s,.05),1):.5;var mo=new Float64Array(1),fo=new Int32Array(mo.buffer),zt=(s,n)=>(s=Math.imul(s^n,1540483477),s^s>>>15);function Ze(s,n=2538058380){return s!==s?zt(n,2146959360):(mo[0]=s===0?0:s,zt(zt(n,fo[0]),fo[1]))}function po(s,n=2166136261){for(let e=0;e<s.length;e++)n=Math.imul(n^s.charCodeAt(e),16777619);return n}function De(s){switch(typeof s){case"number":return Ze(s);case"string":return po(s);case"boolean":return s?1013904242:461845907;case"object":{if(s===null)return 625341585;if(Array.isArray(s)||s instanceof Float64Array){let t=1779033703^s.length;for(let r=0;r<s.length;r++){let o=s[r];t=zt(t,typeof o=="number"?Ze(o):De(o))}return t}let n=1359893119,e=s;for(let t in e){let r=e[t];r!==void 0&&(n=n+zt(po(t),De(r))|0)}return zt(n,2600822924)}default:return 0}}function Ut(s,n){if(s===n)return!0;if(typeof s!="object"||typeof n!="object"||s===null||n===null)return typeof s=="number"&&typeof n=="number"&&s!==s&&n!==n;let e=Array.isArray(s)||s instanceof Float64Array;if(e!==(Array.isArray(n)||n instanceof Float64Array))return!1;if(e){let o=s,a=n;if(o.length!==a.length)return!1;for(let i=0;i<o.length;i++)if(o[i]!==a[i]&&!Ut(o[i],a[i]))return!1;return!0}let t=s,r=n;for(let o in t)if(t[o]!==void 0&&!Ut(t[o],r[o]))return!1;for(let o in r)if(r[o]!==void 0&&t[o]===void 0)return!1;return!0}function gn(s){if(typeof s!="object"||s===null)return s;if(Array.isArray(s))return s.map(gn);if(s instanceof Float64Array)return s.slice();let n={};for(let e in s)s[e]!==void 0&&(n[e]=gn(s[e]));return n}var $t=class{constructor(n=1/0){p(this,"max",n);p(this,"buckets",new Map);p(this,"n",0)}get size(){return this.n}get(n,e=De(n)){let t=this.buckets.get(e);if(t){for(let r=0;r<t.length;r++)if(Ut(t[r].key,n))return t[r].value}}set(n,e,t=De(n)){let r=this.buckets.get(t);if(r){for(let o of r)if(Ut(o.key,n)){o.value=e;return}}this.n>=this.max&&this.clear(),(!r||!this.buckets.has(t))&&this.buckets.set(t,r=[]),r.push({key:gn(n),value:e}),this.n++}clear(){this.buckets.clear(),this.n=0}};var _r=0,bo=1,$n=2,Pr=3,Ht=class{constructor(){p(this,"scale",1);p(this,"cOn",!1);p(this,"px0",0);p(this,"py0",0);p(this,"px1",0);p(this,"py1",0);p(this,"clipVer",0);p(this,"stack",[]);p(this,"sp",0);p(this,"real",0);p(this,"mute",0);p(this,"bnd",new Float64Array(4*(pn+1)));p(this,"rx0",0);p(this,"ry0",0);p(this,"rx1",0);p(this,"ry1",0);p(this,"maxBlur",1/0);p(this,"time",0);p(this,"skipped",0);p(this,"gq",new Float64Array(4))}resetLayers(n){this.scale=n,this.sp=this.real=this.mute=0,this.skipped=0,this.cOn=!1,this.clipVer++}growQ(){let n=this.gq;this.grow(n[0],n[1],n[2],n[3])}grow(n,e,t,r){if(!this.real)return;let o=this.bnd,a=(this.real-1)*4;n<o[a]&&(o[a]=n),e<o[a+1]&&(o[a+1]=e),t>o[a+2]&&(o[a+2]=t),r>o[a+3]&&(o[a+3]=r)}area(n,e){let t=this.bnd,r=n*4,o=this.scale;return this.rx0=Math.max(Math.floor((t[r]-e)*o)-1,0),this.ry0=Math.max(Math.floor((t[r+1]-e)*o)-1,0),this.rx1=Math.min(Math.ceil((t[r+2]+e)*o)+1,this.canvas.width),this.ry1=Math.min(Math.ceil((t[r+3]+e)*o)+1,this.canvas.height),this.rx1>this.rx0&&this.ry1>this.ry0}clip(n,e,t,r){let o=this.scale,a=this.canvas.width,i=this.canvas.height,l=Math.min(Math.max(Math.round(n*o),0),a),c=Math.min(Math.max(Math.round(e*o),0),i),u=Math.min(Math.max(Math.round((n+t)*o),l),a),f=Math.min(Math.max(Math.round((e+r)*o),c),i);this.cOn&&l===this.px0&&c===this.py0&&u===this.px1&&f===this.py1||(this.cOn=!0,this.px0=l,this.py0=c,this.px1=u,this.py1=f,this.clipVer++)}unclip(){this.cOn&&(this.cOn=!1,this.clipVer++)}push(n){if(n<$n&&(this.mute||this.real>=pn||!this.pushLayer())&&(n+=2),n===Pr)this.mute++;else if(n!==$n){let e=this.real*4;this.bnd[e]=this.bnd[e+1]=1/0,this.bnd[e+2]=this.bnd[e+3]=-1/0,this.real++}return this.stack[this.sp++]=n,n<$n}beginLayer(){return this.push(_r)}beginMask(){this.push(this.sp&&this.stack[this.sp-1]===_r?bo:Pr)}endLayer(n,e){if(!this.sp)return;let t=this.stack[--this.sp];if(t===Pr){if(this.mute--,!this.sp)return;t=this.stack[--this.sp]}if(t===bo){let r=--this.real,o=this.popLayer();this.area(r-1,0)&&this.composite(o,!0,1,null);let a=this.bnd,i=(r-1)*4,l=r*4;a[i]=Math.max(a[i],a[l]),a[i+1]=Math.max(a[i+1],a[l+1]),a[i+2]=Math.min(a[i+2],a[l+2]),a[i+3]=Math.min(a[i+3],a[l+3]),t=this.stack[--this.sp]}if(t===$n)fn(e)&&(this.skipped+=e.length);else if(t===_r){let r=--this.real,o=fn(e)?e:null,a=this.popLayer();if(this.area(r,o?so(o,this.maxBlur):0)){this.composite(a,!1,n,o);let i=this.scale;this.grow(this.rx0/i,this.ry0/i,this.rx1/i,this.ry1/i)}}}closeLayers(){for(;this.sp;)this.endLayer(1)}};var vi=256,yo=8<<20,Me=new Float64Array(32),Te={x:0,y:0,w:0,h:0};function wi(s){if(typeof s.filter!="string")return!1;s.filter="blur(1px)";let n=s.filter==="blur(1px)";return s.filter="none",n}function Gt(s){let n=s.getContext("2d",{alpha:!0});return n?new Lr(s,n):null}var Lr=class extends Ht{constructor(e,t){super();p(this,"canvas",e);p(this,"ctx",t);p(this,"kind","canvas2d");p(this,"maxTextureSize",4096);p(this,"features",{});p(this,"info",{renderer:"canvas2d"});p(this,"support");p(this,"lost",!1);p(this,"fxr",null);p(this,"quads",0);p(this,"stats",{drawCalls:0,quads:0,filtersSkipped:0});p(this,"tinted",new Map);p(this,"tintedN",0);p(this,"lostListeners",[]);p(this,"restoredListeners",[]);p(this,"base");p(this,"top");p(this,"layers",[]);p(this,"scratch",[]);p(this,"nines",new Map);p(this,"ninePx",0);p(this,"frame",0);p(this,"hit",!1);p(this,"missed",new Map);this.support={filters:wi(t),shaders:!1},this.base=this.top={ctx:t,clipped:!1,ver:0},e.addEventListener("contextlost",()=>{this.lost=!0,this.lostListeners.forEach(r=>r())}),e.addEventListener("contextrestored",()=>{this.lost=!1,this.tinted.clear(),this.tintedN=0,this.dropNines(),this.restoredListeners.forEach(r=>r())})}resize(e,t){this.canvas.width!==e&&(this.canvas.width=e),this.canvas.height!==t&&(this.canvas.height=t)}createTexture(e){return{id:dn(),width:e.width,height:e.height,source:e}}updateTexture(e,t,r=0,o=0){let a=t?r+t.width:1/0,i=t?o+t.height:1/0;for(let l of this.nines.values()){let c=l.key;c[0]===e.id&&c[1]<a&&c[1]+c[3]>r&&c[2]<i&&c[2]+c[4]>o&&this.dropNine(l)}for(let[l,c]of this.tinted){let u=c.filter(f=>f.id!==e.id);this.tintedN-=c.length-u.length,u.length?this.tinted.set(l,u):this.tinted.delete(l)}}destroyTexture(e){this.updateTexture(e)}begin(e,t,r){this.resetLayers(r),this.fxr?.tick(),this.frame++,this.quads=0,this.top=this.base,this.ctx=this.base.ctx;let o=this.ctx;this.base.clipped&&o.restore(),this.base.clipped=!1,this.base.ver=this.clipVer,o.setTransform(1,0,0,1,0,0),o.globalAlpha=1,o.globalCompositeOperation="source-over",o.clearRect(0,0,this.canvas.width,this.canvas.height),t>0&&(o.fillStyle=xt(e,t),o.fillRect(0,0,this.canvas.width,this.canvas.height))}quad(e,t,r,o,a,i,l,c){j[0]=o,j[1]=a,j[2]=l,this.quadQ(e,t,r,i,c)}quadQ(e,t,r,o,a){t.w<=0||t.h<=0||(o===16777215?this.blit(e.source,t.x,t.y,t.w,t.h,r,a):this.blit(this.tint(e,t,o),0,0,t.w,t.h,r,a))}blit(e,t,r,o,a,i,l){let c=j[0],u=j[1],f=j[2];if(f<=0||this.mute)return;this.sync();let h=this.ctx,b=this.scale;if(this.real){let y=i[0]*c,m=i[1]*c,d=i[2]*u,x=i[3]*u;this.grow(i[4]+Math.min(0,y,d,y+d),i[5]+Math.min(0,m,x,m+x),i[4]+Math.max(0,y,d,y+d),i[5]+Math.max(0,m,x,m+x))}h.setTransform(i[0]*b,i[1]*b,i[2]*b,i[3]*b,i[4]*b,i[5]*b),h.globalAlpha=Math.min(f,1),l==="add"&&(h.globalCompositeOperation="lighter"),h.drawImage(e,t,r,o,a,0,0,c,u),l==="add"&&(h.globalCompositeOperation="source-over"),this.quads++}nineQ(e,t,r,o,a,i,l){var m,d;let c=r[8]+r[9],u=o[8]+o[9],f=Math.ceil(c*Math.hypot(a[0],a[1])*this.scale-1e-6),h=Math.ceil(u*Math.hypot(a[2],a[3])*this.scale-1e-6);if(a[1]===0&&a[2]===0||f>4096||h>4096)return!1;if(!(f>0&&h>0&&j[2]>0)||this.mute)return!0;let b=this.kept(e,t,r,o,f,h,i),y=(b??(b=(m=this.scratch)[d=13*Math.ceil(Math.log2(f))+Math.ceil(Math.log2(h))]??(m[d]=document.createElement("canvas").getContext("2d")))).canvas;if(y.width<f&&(y.width=f),y.height<h&&(y.height=h),!this.hit){b.clearRect(0,0,f+2,h+2);for(let x=0;x<12;x+=4){let g=Math.round(o[x]*h/u),M=Math.round((o[x]+o[x+1])*h/u);for(let v=0;v<12;v+=4){let A=Math.round(r[v]*f/c),E=Math.round((r[v]+r[v+1])*f/c);Te.x=t.x+r[v+2],Te.y=t.y+o[x+2],Te.w=r[v+3],Te.h=o[x+3],!(E<=A||M<=g||Te.w<=0||Te.h<=0)&&(i===16777215?b.drawImage(e.source,Te.x,Te.y,Te.w,Te.h,A,g,E-A,M-g):b.drawImage(this.tint(e,Te,i),0,0,Te.w,Te.h,A,g,E-A,M-g))}}}return j[0]=c,j[1]=u,this.blit(y,0,0,f,h,a,l),!0}kept(e,t,r,o,a,i,l){Me[0]=e.id,Me[1]=t.x,Me[2]=t.y,Me[3]=t.w,Me[4]=t.h,Me[5]=a,Me[6]=i,Me[7]=l,Me.set(r,8),Me.set(o,20);let c=De(Me),u=this.nines.get(c);if(this.hit=!1,u)return Ut(u.key,Me)?(u.used=this.frame,this.hit=!0,u.ctx):null;let f=this.missed,h=f.get(c);f.size>4096&&f.clear(),f.set(c,this.frame);let b=a*i;if(h!==this.frame-1||b>yo)return null;let y;for(;this.ninePx+b>yo;){let x;for(let v of this.nines.values())v.used<this.frame-1&&!(x&&x.used<=v.used)&&(x=v);if(!x)return null;let g=x.ctx.canvas,M=!y&&g.width>=a&&g.height>=i&&g.width*g.height<=2*b;this.dropNine(x,M),M&&(y=x.ctx)}let m=y??document.createElement("canvas").getContext("2d"),d=m.canvas;return y||(d.width=a,d.height=i),this.ninePx+=d.width*d.height,this.nines.set(c,{key:gn(Me),ctx:m,used:this.frame}),m}dropNine(e,t=!1){this.nines.delete(De(e.key));let r=e.ctx.canvas;this.ninePx-=r.width*r.height,t||(r.width=0)}dropNines(){for(let e of this.nines.values())this.dropNine(e)}tint(e,t,r){let o=Ze(r,Ze(t.h,Ze(t.w,Ze(t.y,Ze(t.x,Ze(e.id)))))),a=this.tinted.get(o);if(a)for(let c=0;c<a.length;c++){let u=a[c];if(u.id===e.id&&u.x===t.x&&u.y===t.y&&u.w===t.w&&u.h===t.h&&u.color===r)return u.canvas}this.tintedN>=vi&&(this.tinted.clear(),this.tintedN=0,a=void 0);let i=document.createElement("canvas");i.width=Math.ceil(t.w),i.height=Math.ceil(t.h);let l=i.getContext("2d");return l.drawImage(e.source,t.x,t.y,t.w,t.h,0,0,t.w,t.h),l.globalCompositeOperation="multiply",l.fillStyle=xt(r),l.fillRect(0,0,t.w,t.h),l.globalCompositeOperation="destination-in",l.drawImage(e.source,t.x,t.y,t.w,t.h,0,0,t.w,t.h),a||this.tinted.set(o,a=[]),a.push({id:e.id,x:t.x,y:t.y,w:t.w,h:t.h,color:r,canvas:i}),this.tintedN++,i}paint(e,t){this.sync();let r=this.ctx,o=this.scale;return r.setTransform(o,0,0,o,0,0),r.globalAlpha=Math.min(t,1),xt(e)}ellipse(e,t,r,o,a,i,l){if(l<=0||r<=0||o<=0||this.mute)return;let c=Math.max(r,o);this.grow(e-c,t-c,e+c,t+c);let u=this.ctx;u.fillStyle=this.paint(i,l),u.beginPath(),u.ellipse(e,t,r,o,a,0,Math.PI*2),u.fill(),this.quads++}trace(e,t,r=0){if(this.real)for(let a=0;a<t;a++)this.grow(e[a*2]-r,e[a*2+1]-r,e[a*2]+r,e[a*2+1]+r);let o=this.ctx;o.beginPath(),o.moveTo(e[0],e[1]);for(let a=1;a<t;a++)o.lineTo(e[a*2],e[a*2+1])}polygon(e,t,r,o){if(o<=0||t<3||this.mute)return;let a=this.ctx;a.fillStyle=this.paint(r,o),this.trace(e,t),a.closePath(),a.fill(),this.quads++}stroke(e,t,r,o,a,i){if(a<=0||r<=0||t<1||this.mute)return;let l=this.ctx;l.strokeStyle=this.paint(o,a),l.lineWidth=r,l.lineCap="round",l.lineJoin="round",this.trace(e,t,r/2),t===1&&l.lineTo(e[0],e[1]),i&&l.closePath(),l.stroke(),this.quads++}sync(){let e=this.top;if(e.ver===this.clipVer)return;let t=e.ctx;e.clipped&&t.restore(),e.clipped=this.cOn,e.ver=this.clipVer,this.cOn&&(t.save(),t.setTransform(1,0,0,1,0,0),t.beginPath(),t.rect(this.px0,this.py0,this.px1-this.px0,this.py1-this.py0),t.clip())}pushLayer(){let e=this.canvas.width,t=this.canvas.height,r=this.layers[this.real];if(!r||r.ctx.canvas.width!==e||r.ctx.canvas.height!==t){let a=document.createElement("canvas");a.width=e,a.height=t;let i=a.getContext("2d");if(!i)return!1;r=this.layers[this.real]={ctx:i,clipped:!1,ver:-1}}let o=r.ctx;return r.clipped&&o.restore(),r.clipped=!1,r.ver=-1,o.setTransform(1,0,0,1,0,0),o.globalAlpha=1,o.globalCompositeOperation="source-over",o.clearRect(0,0,e,t),this.top=r,this.ctx=o,!0}popLayer(){return this.top=this.real>0?this.layers[this.real-1]:this.base,this.ctx=this.top.ctx,this.layers[this.real].ctx.canvas}composite(e,t,r,o){let a=e,i="none",l=o&&Ae.c2d?this.fxr??(this.fxr=Ae.c2d(this)):null;l&&(a=l.chain(e,o),i=l.css),this.sync();let c=this.ctx,u=this.rx0,f=this.ry0,h=this.rx1-u,b=this.ry1-f;c.setTransform(1,0,0,1,0,0),c.globalAlpha=Math.min(r,1),c.globalCompositeOperation=t?"destination-in":"source-over",i!=="none"&&(c.filter=i),c.drawImage(a,u,f,h,b,u,f,h,b),i!=="none"&&(c.filter="none"),c.globalCompositeOperation="source-over",this.quads++}end(){this.closeLayers();let e=this.stats;return e.drawCalls=e.quads=this.quads,e.filtersSkipped=this.skipped,e}onLost(e){this.lostListeners.push(e)}onRestored(e){this.restoredListeners.push(e)}destroy(){this.tinted.clear(),this.dropNines(),this.layers=[],this.scratch=[],this.fxr?.destroy(),this.fxr=null}};var Hn=class{constructor(n,e,t=8192){p(this,"instanced",n);p(this,"slots",e);p(this,"capacity",t);p(this,"f32");p(this,"u32");p(this,"quads",0);p(this,"textures");p(this,"bound",0);this.textures=new Array(e).fill(null);let r=t*(n?14:24),o=new ArrayBuffer(r*4);this.f32=new Float32Array(o),this.u32=new Uint32Array(o)}slot(n){let e=this.textures;for(let t=0;t<this.bound;t++)if(e[t]===n)return t;return this.bound>=this.slots?-1:(e[this.bound]=n,this.bound++)}has(n){for(let e=0;e<this.bound;e++)if(this.textures[e]===n)return!0;return!1}get full(){return this.quads>=this.capacity}get words(){return this.quads*(this.instanced?14:24)}reset(){this.quads=0;for(let n=0;n<this.bound;n++)this.textures[n]=null;this.bound=0}push(n,e,t,r,o,a,i,l,c,u,f,h,b,y){let m=this.f32;if(this.instanced){let d=this.quads*14;m[d++]=n,m[d++]=e,m[d++]=t,m[d++]=r,m[d++]=o,m[d++]=a,m[d++]=i,m[d++]=l,m[d++]=c,m[d++]=u,m[d++]=f,m[d++]=h,this.u32[d++]=b,m[d]=y}else{let d=this.quads*6*4;this.vertex(d,n,e,c,u,b,y),this.vertex(d+6,t,r,f,u,b,y),this.vertex(d+12,o,a,f,h,b,y),this.vertex(d+18,i,l,c,h,b,y)}this.quads++}pushQ(n,e){let t=this.f32;if(this.instanced){let r=this.quads*14;for(let o=0;o<12;o++)t[r+o]=n[o];this.u32[r+12]=n[12],t[r+13]=e}else{let r=this.quads*6*4,o=n[12];for(let a=0;a<4;a++,r+=6)t[r]=n[a*2],t[r+1]=n[a*2+1],t[r+2]=a===1||a===2?n[10]:n[8],t[r+3]=a>=2?n[11]:n[9],this.u32[r+4]=o,t[r+5]=e}this.quads++}vertex(n,e,t,r,o,a,i){let l=this.f32;l[n]=e,l[n+1]=t,l[n+2]=r,l[n+3]=o,this.u32[n+4]=a,l[n+5]=i}};function xo(s){let n=new Uint16Array(s*6);for(let e=0,t=0,r=0;e<s;e++,t+=6,r+=4)n[t]=r,n[t+1]=r+1,n[t+2]=r+2,n[t+3]=r,n[t+4]=r+2,n[t+5]=r+3;return n}var ye={M:0,L:1,Q:2,C:3,Z:4},To=[2,2,4,6,0],Ai={M:0,L:1,Q:2,C:3,Z:4};function jn(s,n){if(s.length>=n)return s;let e=new Float64Array(Math.max(n,s.length*2,16));return e.set(s),e}var Gn=new Map;function Si(s){if(typeof s!="string")return s;let n=Gn.get(s);if(n)return n;n=[];let e=s.match(/[MLQCZ]|-?\d*\.?\d+(?:e-?\d+)?/gi)??[],t=-1;for(let r=0;r<e.length;){let o=e[r],a=Ai[o.toUpperCase()];if(a!==void 0){t=a,r++,a===ye.Z&&n.push(ye.Z);continue}if(t<0||t===ye.Z){r++;continue}let i=To[t];n.push(t);for(let l=0;l<i;l++)n.push(Number(e[r+l]??0));r+=i,t===ye.M&&(t=ye.L)}return Gn.size>256&&Gn.clear(),Gn.set(s,n),n}var lt={subs:[],count:0},Nr=null,it=null;function Wn(s,n){let e=it;e||(e=lt.subs[lt.count]??null,e||lt.subs.push(e={pts:new Float64Array(64),n:0,closed:!1}),e.n=0,e.closed=!1,lt.count++,it=e);let t=e.n*2;t+2>e.pts.length&&(e.pts=jn(e.pts,t+2));let r=Nr;r?(e.pts[t]=r[0]*s+r[2]*n+r[4],e.pts[t+1]=r[1]*s+r[3]*n+r[5]):(e.pts[t]=s,e.pts[t+1]=n),e.n++}function Yn(s,n=null,e=1,t=6){let r=Si(s);lt.count=0,it=null,Nr=n;let o=0,a=0,i=0,l=0,c=e/t;for(let u=0;u<r.length;){let f=r[u++],h=r;if(f===ye.M)it=null,o=i=h[u],a=l=h[u+1],Wn(o,a);else if(f===ye.L)o=h[u],a=h[u+1],Wn(o,a);else if(f===ye.Q){let b=h[u],y=h[u+1],m=h[u+2],d=h[u+3],x=go((He(b-o,y-a)+He(m-b,d-y))*c);for(let g=1;g<=x;g++){let M=g/x,v=1-M;Wn(v*v*o+2*v*M*b+M*M*m,v*v*a+2*v*M*y+M*M*d)}o=m,a=d}else if(f===ye.C){let b=h[u],y=h[u+1],m=h[u+2],d=h[u+3],x=h[u+4],g=h[u+5],M=go((He(b-o,y-a)+He(m-b,d-y)+He(x-m,g-d))*c);for(let v=1;v<=M;v++){let A=v/M,E=1-A,C=E*E*E,P=3*E*E*A,L=3*E*A*A,I=A*A*A;Wn(C*o+P*b+L*m+I*x,C*a+P*y+L*d+I*g)}o=x,a=g}else if(f===ye.Z){it&&(it.closed=!0),it=null,o=i,a=l;continue}else break;u+=To[f]}it=null,Nr=null;for(let u=0;u<lt.count;u++){let f=lt.subs[u],h=f.n*2;f.closed&&f.n>=2&&Math.abs(f.pts[0]-f.pts[h-2])<1e-6&&Math.abs(f.pts[1]-f.pts[h-1])<1e-6&&f.n--}return lt}var He=(s,n)=>Math.sqrt(s*s+n*n),go=s=>Math.min(Math.max(Math.ceil(s),2),24);function Mi(s,n){let e=0;for(let t=0,r=n-1;t<n;r=t++)e+=(s[r*2]-s[t*2])*(s[r*2+1]+s[t*2+1]);return e}var Vn=new Int32Array(64),Xn=(s,n,e,t,r)=>((s[t*2]-s[e*2])*(s[r*2+1]-s[e*2+1])-(s[t*2+1]-s[e*2+1])*(s[r*2]-s[e*2]))*n;function Eo(s,n,e){if(n<3)return 0;Vn.length<n&&(Vn=new Int32Array(Math.max(n,Vn.length*2)));let t=Vn,r=n,o=0;for(let c=0;c<n;c++)t[c]=c;let a=Mi(s,n)>0?1:-1,i=n*n+8,l=0;for(;r>3&&i-- >0;){let c=t[(l+r-1)%r],u=t[l%r],f=t[(l+1)%r],h=Xn(s,a,c,u,f)>0;if(h)for(let b=0;b<r;b++){let y=t[b];if(!(y===c||y===u||y===f)&&Xn(s,a,c,u,y)>=0&&Xn(s,a,u,f,y)>=0&&Xn(s,a,f,c,y)>=0){h=!1;break}}h?(e[o++]=c,e[o++]=u,e[o++]=f,t.copyWithin(l%r,l%r+1,r),r--,l=Math.max(l-1,0)):l=(l+1)%r}if(r===3)e[o++]=t[0],e[o++]=t[1],e[o++]=t[2];else if(r>3)for(let c=1;c+1<r;c++)e[o++]=t[0],e[o++]=t[c],e[o++]=t[c+1];return o}var Ti=.85,qn=new Float64Array(64),ko=new Float64Array(64),vo=new Float64Array(64),wo=new Float64Array(64),Ao=new Float64Array(64),So=new Float64Array(64),Mo=new Uint8Array(64),kn=new Float64Array(8);function Ro(s,n,e,t,r,o){let a=kn;if(qn.length<n){let d=Math.max(n,qn.length*2);qn=new Float64Array(d),ko=new Float64Array(d),vo=new Float64Array(d),wo=new Float64Array(d),Ao=new Float64Array(d),So=new Float64Array(d),Mo=new Uint8Array(d)}let i=qn,l=ko,c=0;for(let d=0;d<n;d++){let x=s[d*2],g=s[d*2+1];!Number.isFinite(x)||!Number.isFinite(g)||c&&Math.abs(i[c-1]-x)<.001&&Math.abs(l[c-1]-g)<.001||(i[c]=x,l[c]=g,c++)}if(t&&c>2&&Math.abs(i[0]-i[c-1])<.001&&Math.abs(l[0]-l[c-1])<.001&&c--,c===0)return;if(c===1)return a[0]=i[0],a[1]=l[0],o();let u=t?c:c-1,f=vo,h=wo;for(let d=0;d<u;d++){let x=(d+1)%c,g=i[x]-i[d],M=l[x]-l[d],v=He(g,M)||1;f[d]=-M/v,h[d]=g/v}let b=Ao,y=So,m=Mo;for(let d=0;d<c;d++){let x=t?(d-1+u)%u:d-1,g=d<u?d:-1;if(m[d]=1,x<0||g<0||f[x]*f[g]+h[x]*h[g]<Ti)continue;let v=f[x]+f[g],A=h[x]+h[g],E=He(v,A)||1;v/=E,A/=E;let C=e/Math.max(v*f[g]+A*h[g],.5);b[d]=v*C,y[d]=A*C,m[d]=0}for(let d=0;d<u;d++){let x=(d+1)%c,g=m[d]?f[d]*e:b[d],M=m[d]?h[d]*e:y[d],v=m[x]?f[d]*e:b[x],A=m[x]?h[d]*e:y[x];a[0]=i[d]+g,a[1]=l[d]+M,a[2]=i[x]+v,a[3]=l[x]+A,a[4]=i[x]-v,a[5]=l[x]-A,a[6]=i[d]-g,a[7]=l[d]-M,r()}for(let d=0;d<c;d++)m[d]&&(a[0]=i[d],a[1]=l[d],o())}function Br(s,n){let e=0,t=1/0;for(let r=0;r<n.length;r++){let o=Math.abs(Math.log(Math.max(s,.5)/n[r]));o<t&&(t=o,e=r)}return e}var Kn=[{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}],Qn=[4,8,16,32,64,128].map((s,n)=>({x:n*4,y:128,w:4,h:s,r:s/2-1})),Je={x:248,y:248,w:8,h:8},Co=Kn.map(s=>s.r*2),_o=Qn.map(s=>s.r*2),Fo=(s,n)=>Math.min(Math.max(s+.5-n,0),1);function Ei(){let s=new Uint8ClampedArray(262144),n=(e,t,r)=>{let o=(t*256+e)*4;s[o]=s[o+1]=s[o+2]=255,s[o+3]=Math.round(r*255)};for(let e of Kn){let t=e.w/2;for(let r=0;r<e.h;r++)for(let o=0;o<e.w;o++)n(e.x+o,e.y+r,Fo(e.r,Math.hypot(o+.5-t,r+.5-t)))}for(let e of Qn){let t=e.h/2;for(let r=0;r<e.h;r++)for(let o=0;o<e.w;o++)n(e.x+o,e.y+r,Fo(e.r,Math.abs(r+.5-t)))}for(let e=0;e<Je.h;e++)for(let t=0;t<Je.w;t++)n(Je.x+t,Je.y+e,1);return s}function Po(){let s=document.createElement("canvas");return s.width=s.height=256,s.getContext("2d").putImageData(new ImageData(Ei(),256,256),0,0),s}var Lo=8,Zn=`
|
|
1
|
+
"use strict";(()=>{var Ts=Object.defineProperty;var _a=(s,n,e)=>n in s?Ts(s,n,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[n]=e;var La=(s,n)=>{for(var e in n)Ts(s,e,{get:n[e],enumerable:!0})};var p=(s,n,e)=>_a(s,typeof n!="symbol"?n+"":n,e);var xs={};La(xs,{AnimatedSprite:()=>Ne,Atlas:()=>ht,AvatarPainter:()=>Et,AvatarsNode:()=>Tn,BitmapFont:()=>Qt,DEFAULT_FONT:()=>Hr,EASE:()=>ct,Group:()=>Tt,HALO:()=>Rt,MAX_LAYERS:()=>pn,NameTags:()=>dt,Node:()=>Ie,NodePool:()=>En,Particles:()=>Ht,STAGE_HEIGHT:()=>he,Shape:()=>Xe,ShelfPacker:()=>yn,Sound:()=>Jt,Sprite:()=>Re,TIERS:()=>Ke,Text:()=>Ye,Timeline:()=>en,Tweens:()=>tn,avatarPortrait:()=>Uo,blur:()=>ka,brightness:()=>fa,colorMatrix:()=>ga,contrast:()=>pa,createAvatarRenderer:()=>Go,createEngine:()=>oa,createRenderer:()=>jt,dropShadow:()=>wa,grayscale:()=>ma,handsOf:()=>sr,hits:()=>Sn,hueRotate:()=>ya,invert:()=>xa,nodePool:()=>Ta,packColor:()=>lt,parseBMFont:()=>Zt,parseColor:()=>me,pickTier:()=>ir,playerColor:()=>An,rendererOrder:()=>zr,rng:()=>eo,saturate:()=>da,sepia:()=>ba,shader:()=>va,shapeBounds:()=>nr,tier:()=>at,tint:()=>ha,touching:()=>or,wrists:()=>Wr});var gr=33,Y={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},Es=["3-5","6-8","9-12"],Ia=s=>Es.includes(s);var Na=4,on=["#EE6A43","#6FA0E0","#8CC9A0","#C49BE0"];var Rs={"3-5":["bunny","bear","panda","penguin"],"6-8":["fox","lion","dragon","unicorn"],"9-12":["robot","astronaut","ninja","skater"]},Ba=Rs["6-8"],kr=(s,n)=>{let e=Ia(n)?Rs[n]:Ba;return e[Number.isInteger(s)&&s>=0?s%e.length:0]};var Cs=(s,n)=>s?{x:s.x+n.x*s.w,y:s.y+n.y*s.h}:{x:n.x,y:n.y};var Da=12,Oa=gr*4,za=s=>Da+s*Oa,gl=za(Na);var Ha=s=>s.startsWith("fabi-play.")?`fablee-play.${s.slice(10)}`:null;function Fs(s,n,e=Ha(n)){if(!(!s||!e))try{let t=s.getItem(e);if(t===null)return;s.getItem(n)===null&&s.setItem(n,t),s.removeItem(e)}catch{}}var Me="#4a382c",ce="#2b2118",Le="#1c1f2b",Ps="#fbefe3",$e="#f4897a",an="#3a2a22",wr=[{id:"fox",name:{en:"Fox",it:"Volpe"},band:"6-8",palette:{body:"#ee6a43",limbs:"#ee6a43",belly:Ps,accent:"#ffd9c2",outline:ce,hands:"#5a3426",feet:"#5a3426"},head:"wide",ears:"pointy",face:{eyes:"dot",mouth:"cat",nose:an,muzzle:"cheeks"},tail:"fluffy",headExtras:[],bodyExtras:[]},{id:"mascot",name:{en:"Fabi",it:"Fabi"},band:"all",special:!0,palette:{body:"#ee6a43",limbs:"#ee6a43",belly:Ps,accent:"#5a3426",outline:ce,hands:"#5a3426",feet:"#5a3426"},head:"wide",ears:"pointy",face:{eyes:"bead",mouth:"open",nose:an,muzzle:"band",cheeks:$e},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:Me},head:"round",ears:"long",face:{eyes:"dot",mouth:"cat",nose:"#e0607e",muzzle:"none",cheeks:$e},tail:"pom",headExtras:[],bodyExtras:[]},{id:"bear",name:{en:"Bear",it:"Orsetto"},band:"3-5",palette:{body:"#cf9f78",limbs:"#cf9f78",belly:"#f7e0bf",accent:"#f7e0bf",outline:Me},head:"round",ears:"round",face:{eyes:"dot",mouth:"smile",nose:an,muzzle:"oval",cheeks:$e},tail:"none",headExtras:[],bodyExtras:[]},{id:"cat",name:{en:"Cat",it:"Gattino"},band:"3-5",palette:{body:"#c8b6ee",limbs:"#c8b6ee",belly:"#f4eeff",accent:"#f7b3c8",outline:Me,hands:"#f4eeff",feet:"#f4eeff"},head:"wide",ears:"pointy",face:{eyes:"big",eyeColor:"#3f9a5a",mouth:"cat",nose:"#f07a9a",muzzle:"none",cheeks:$e},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:Me,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:Me,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:Me},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:ce},head:"round",ears:"round",face:{eyes:"dot",mouth:"cat",nose:"#8a4b2a",muzzle:"oval",cheeks:$e},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:ce,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:ce},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:Le,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:Le,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:ce},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:ce,hands:"#f2c9a0",feet:"#f2c9a0"},head:"round",ears:"side",face:{eyes:"dot",mouth:"open",nose:"#5a3a26",muzzle:"monkey",cheeks:$e},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:Me},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:ce},head:"wide",ears:"round",face:{eyes:"dot",mouth:"cat",nose:"#e2607a",muzzle:"oval",cheeks:$e},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:Me,feet:"#f9b95c",hands:"#639cc9"},head:"tall",ears:"tufts",face:{eyes:"big",eyeColor:Me,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:Le},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:ce},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:ce,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:Me,hands:"#ffc23d",feet:"#ffa04a"},head:"round",ears:"none",face:{eyes:"dot",mouth:"beak",muzzle:"none",cheeks:$e},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:Me,ears:"#b58262",hands:"#e6caa6",feet:"#e6caa6"},head:"wide",ears:"floppy",face:{eyes:"dot",mouth:"open",nose:an,muzzle:"oval",cheeks:$e},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:Me,skin:"#f7dccb",hands:"#a58c7e",feet:"#a58c7e"},head:"round",ears:"droopy",face:{eyes:"dot",mouth:"smile",nose:"#e591a0",muzzle:"none",cheeks:$e},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:Me,feet:"#ff9f43"},head:"tall",ears:"none",face:{eyes:"dot",mouth:"bill",muzzle:"none",cheeks:$e},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:ce,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:ce,hands:"#5a647a",feet:"#5a647a"},head:"round",ears:"pointy",face:{eyes:"dot",mouth:"open",nose:an,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:ce,hands:"#3a9bdc",feet:"#8a7a70"},head:"round",ears:"none",face:{eyes:"big",eyeColor:ce,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:Le,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:Le,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:Le,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:Le,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:Le,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:Le,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:Le,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:Le,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:Le,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:ce},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:ce,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"]}];var re={M:0,L:1,Q:2,C:3,Z:4},_s=[2,2,4,6,0];function Lt(s,n){for(let e of n)$a(s,e)}function $a(s,n){if(n.k==="group"){s.save(),s.translate(n.x,n.y),n.rot&&s.rotate(n.rot),n.s!==void 0&&n.s!==1&&s.scale(n.s,n.s),n.alpha!==void 0&&(s.globalAlpha*=n.alpha),Lt(s,n.items),s.restore();return}switch(s.save(),n.alpha!==void 0&&(s.globalAlpha*=n.alpha),s.beginPath(),n.k){case"circle":s.arc(n.x,n.y,Math.max(n.r,0),0,Math.PI*2);break;case"ellipse":s.ellipse(n.x,n.y,Math.max(n.rx,0),Math.max(n.ry,0),n.rot??0,0,Math.PI*2);break;case"rect":Ga(s,n);break;case"path":typeof n.d=="string"?Wa(s,n.d):Ua(s,n.d);break;case"line":s.moveTo(n.pts[0]??0,n.pts[1]??0);for(let e=2;e+1<n.pts.length;e+=2)s.lineTo(n.pts[e],n.pts[e+1]);break}s.lineCap="round",s.lineJoin="round",n.fill&&n.k!=="line"&&(s.fillStyle=n.fill,s.fill()),n.stroke&&(n.lw??1)>0&&(s.strokeStyle=n.stroke,s.lineWidth=n.lw??1,s.stroke()),s.restore()}function Ga(s,n){let e=Math.max(0,Math.min(n.r,n.w/2,n.h/2));s.translate(n.x,n.y),n.rot&&s.rotate(n.rot);let t=-n.w/2,r=-n.h/2;s.moveTo(t+e,r),s.lineTo(t+n.w-e,r),s.quadraticCurveTo(t+n.w,r,t+n.w,r+e),s.lineTo(t+n.w,r+n.h-e),s.quadraticCurveTo(t+n.w,r+n.h,t+n.w-e,r+n.h),s.lineTo(t+e,r+n.h),s.quadraticCurveTo(t,r+n.h,t,r+n.h-e),s.lineTo(t,r+e),s.quadraticCurveTo(t,r,t+e,r),s.closePath()}function Ua(s,n){for(let e=0;e<n.length;){let t=n[e++];if(t===re.M)s.moveTo(n[e],n[e+1]);else if(t===re.L)s.lineTo(n[e],n[e+1]);else if(t===re.Q)s.quadraticCurveTo(n[e],n[e+1],n[e+2],n[e+3]);else if(t===re.C)s.bezierCurveTo(n[e],n[e+1],n[e+2],n[e+3],n[e+4],n[e+5]);else if(t===re.Z)s.closePath();else return;e+=_s[t]}}function vr(s){if(typeof s=="string")return(s.match(/-?\d*\.?\d+(?:e-?\d+)?/gi)??[]).map(Number);let n=[];for(let e=0;e<s.length;){let t=_s[s[e++]];if(t===void 0)break;for(let r=0;r<t;r++)n.push(s[e+r]);e+=t}return n}function Wa(s,n){let e=n.match(/[MLQCZ]|-?\d*\.?\d+(?:e-?\d+)?/gi)??[],t="",r=0,o=()=>Number(e[r++]);for(;r<e.length;){let a=e[r];if(/[MLQCZ]/i.test(a)&&(t=a.toUpperCase(),r++,t==="Z")){s.closePath();continue}t==="M"?(s.moveTo(o(),o()),t="L"):t==="L"?s.lineTo(o(),o()):t==="Q"?s.quadraticCurveTo(o(),o(),o(),o()):t==="C"?s.bezierCurveTo(o(),o(),o(),o(),o(),o()):r++}}var J=s=>{let n=Math.round(s*100)/100;return n===0?0:n};function Q(s,n=.5){let e=s.length;if(e<3)return[];let t=(i,l,c)=>({x:i.x+(l.x-i.x)*c,y:i.y+(l.y-i.y)*c}),r=Math.min(Math.max(n,0),.5),o=t(s[0],s[1],r),a=[re.M,J(o.x),J(o.y)];for(let i=1;i<=e;i++){let l=s[(i-1)%e],c=s[i%e],u=s[(i+1)%e],f=t(l,c,1-r),h=t(c,u,r);a.push(re.L,J(f.x),J(f.y),re.Q,J(c.x),J(c.y),J(h.x),J(h.y))}return a.push(re.Z),a}function K(s,n=1){let e=s.length;if(e<3)return[];let t=[re.M,J(s[0].x),J(s[0].y)],r=n/6;for(let o=0;o<e;o++){let a=s[(o-1+e)%e],i=s[o],l=s[(o+1)%e],c=s[(o+2)%e];t.push(re.C,J(i.x+(l.x-a.x)*r),J(i.y+(l.y-a.y)*r),J(l.x-(c.x-i.x)*r),J(l.y-(c.y-i.y)*r),J(l.x),J(l.y))}return t.push(re.Z),t}function It(s){let n=s.length;if(n<2)return[];let e=[re.M,J(s[0].x),J(s[0].y)];for(let t=0;t<n-1;t++){let r=s[Math.max(t-1,0)],o=s[t],a=s[t+1],i=s[Math.min(t+2,n-1)];e.push(re.C,J(o.x+(a.x-r.x)/6),J(o.y+(a.y-r.y)/6),J(a.x-(i.x-o.x)/6),J(a.y-(i.y-o.y)/6),J(a.x),J(a.y))}return e}var et="M0 -1 L0.29 -0.4 L0.95 -0.31 L0.47 0.15 L0.59 0.81 L0 0.5 L-0.59 0.81 L-0.47 0.15 L-0.95 -0.31 L-0.29 -0.4 Z";var ae="#ffffff",q=[-1,1],Ls="#3a2420",Is="#f2808f",Ar="#26324a",Va="#ffd84a",se=(...s)=>{let n=[];for(let e=0;e+1<s.length;e+=2)n.push({x:s[e],y:s[e+1]});return n};function Bn(s,n){let e=s.palette,t=[],r={stroke:e.outline,lw:n},o=u=>s.headExtras.includes(u),a=(u,f)=>s.extraColors?.[u]??f;if(o("mane")){for(let f=0;f<12;f++){let h=f/12*Math.PI*2;t.push({k:"circle",x:Math.cos(h)*1.02,y:Math.sin(h)*1+.04,r:.42,fill:a(0,e.accent),...r})}t.push({k:"circle",x:0,y:.04,r:1.08,fill:a(0,e.accent)})}if(o("rainbow-mane")){let u=s.extraColors??["#f59ac0","#fbd46a","#8fd3f4"];[[.98,.05,.3,.5,-.25],[.92,.58,.26,.42,-.1],[.62,.92,.22,.32,.4]].forEach(([h,b,y,m,d],x)=>t.push({k:"ellipse",x:h,y:b,rx:y,ry:m,rot:d,fill:u[x%u.length],...r}))}if(o("spikes"))for(let u of[-.55,0,.55]){let f=kt(u,1.48),h=kt(u-.32,.86),b=kt(u+.32,.86);t.push({k:"path",d:Q([h,f,b],.22),fill:e.accent,...r})}if(o("curl")&&t.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:e.body,...r}),o("wool"))for(let u=0;u<=8;u++){let f=-1.75+u/8*3.5;t.push({k:"circle",x:Math.sin(f)*.98,y:-Math.cos(f)*.92-.04,r:.34,fill:e.body,...r})}if(o("crest")&&[-.38,0,.38].forEach((u,f)=>{let h=kt(u,1.12);t.push({k:"ellipse",x:h.x,y:h.y,rx:.15,ry:.42,rot:u,fill:a(f,e.accent),...r})}),o("plume")&&t.push({k:"path",d:K(se(-.12,-.92,-.2,-1.42,.1,-1.78,.62,-1.74,.36,-1.46,.16,-.98)),fill:e.accent,...r}),o("locks")&&t.push({k:"path",d:K(se(-1.14,.58,-1.24,-.2,-.86,-.98,0,-1.2,.86,-.98,1.24,-.2,1.14,.58,.8,.66,0,.2,-.8,.66)),fill:e.hair??e.outline,...r}),o("bun")&&t.push({k:"circle",x:.04,y:-1.14,r:.4,fill:e.hair??e.outline,...r}),o("ninja-hood"))for(let[u,f]of[[.35,.5],[.85,.42]])t.push({k:"ellipse",x:1+Math.cos(u)*f*.8,y:-.5+Math.sin(u)*f*.8,rx:f,ry:.11,rot:u,fill:e.accent,...r});if(o("bandana"))for(let[u,f]of[[Math.PI-.5,.42],[Math.PI-1,.36]])t.push({k:"ellipse",x:-.98+Math.cos(u)*f*.8,y:-.36+Math.sin(u)*f*.8,rx:f,ry:.12,rot:u,fill:e.accent,...r});if(o("ruff"))for(let u of q)t.push({k:"path",d:Q(se(u*.7,-.3,u*1.32,0,u*1.02,.18,u*1.26,.46,u*.86,.56,u*.98,.84,u*.4,.7),.25),fill:e.body,...r});if(s.face.eyesOnTop)for(let u of q)t.push({k:"circle",x:u*.46,y:-.72,r:.38,fill:e.body,...r});t.push(...Qa(s,n)),t.push(Xa(s,r));let i=s.face.muzzle,l=e.belly;if(i==="oval"&&t.push({k:"ellipse",x:0,y:.4,rx:.46,ry:.32,fill:l}),i==="monkey"){for(let u of q)t.push({k:"circle",x:u*.32,y:-.04,r:.38,fill:l});t.push({k:"ellipse",x:0,y:.4,rx:.56,ry:.4,fill:l})}if(i==="heart"){for(let u of q)t.push({k:"circle",x:u*.36,y:.02,r:.5,fill:l});t.push({k:"ellipse",x:0,y:.38,rx:.66,ry:.48,fill:l})}if(i==="disc")for(let u of q)t.push({k:"circle",x:u*.4,y:.02,r:.44,fill:l});if(i==="cheeks")for(let u of q)t.push({k:"ellipse",x:u*.4,y:.44,rx:.44,ry:.32,fill:l});if(i==="band"&&t.push({k:"path",d:Ka(s,n),fill:l}),o("stripes")&&s.head==="snout-long"){let u=a(0,e.outline);for(let[f,h,b,y]of[[.46,-.94,.36,-.66],[.8,-.72,.62,-.5],[1,-.36,.78,-.24]])t.push({k:"line",pts:[f,h,b,y],stroke:u,lw:.11})}else if(o("stripes")){let u=a(0,e.outline);t.push({k:"line",pts:[0,-.97,0,-.66],stroke:u,lw:.13});for(let f of q)t.push({k:"line",pts:[f*.3,-.93,f*.24,-.7],stroke:u,lw:.1}),t.push({k:"line",pts:[f*.98,-.05,f*.74,0],stroke:u,lw:.1}),t.push({k:"line",pts:[f*.94,.22,f*.74,.22],stroke:u,lw:.09})}if(o("spots")){let u=a(1,e.belly);t.push({k:"circle",x:-.55,y:-.5,r:.15,fill:u}),t.push({k:"circle",x:.58,y:-.42,r:.11,fill:u}),t.push({k:"circle",x:.22,y:-.76,r:.09,fill:u})}if(s.head==="snout-long")for(let[u,f,h]of[[-1.38,-.14,.06],[-1.14,-.22,.055]])t.push({k:"ellipse",x:u,y:f,rx:h,ry:h*.8,rot:-.3,fill:e.outline,alpha:.85});if(o("forehead")&&t.push({k:"path",d:K(se(-.62,-.66,0,-.86,.62,-.66,.26,-.36,0,-.1,-.26,-.36),.9),fill:a(0,e.accent)}),o("eye-spot")&&t.push({k:"ellipse",x:.42,y:-.06,rx:.3,ry:.33,rot:.3,fill:e.ears??e.accent}),o("gills"))for(let u of q)for(let f of[0,.12,.24])t.push({k:"path",d:`M${u*(.66+f)} 0.06 Q${u*(.6+f)} 0.22 ${u*(.66+f)} 0.38`,stroke:e.accent,lw:n*.9});let c=e.hair??e.outline;if(o("hair")&&t.push({k:"path",d:K(se(-1.02,-.06,-1.02,-.58,-.62,-1.04,.08,-1.14,.76,-.92,1.05,-.42,1,-.06,.84,-.4,.42,-.5,.06,-.4,-.34,-.56,-.74,-.38)),fill:c,...r}),o("locks")&&t.push({k:"path",d:K(se(-1,-.08,-.98,-.62,-.56,-1.02,0,-1.1,.56,-1.02,.98,-.62,1,-.08,.8,-.38,.36,-.44,0,-.4,-.36,-.44,-.8,-.38)),fill:c,...r}),o("bun")&&t.push({k:"path",d:K(se(-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:c,...r}),o("curls")){for(let u=0;u<7;u++){let f=kt(-1.3+u/6*2.6,.86);t.push({k:"circle",x:f.x,y:f.y,r:.3,fill:c,...r})}t.push({k:"ellipse",x:0,y:-.64,rx:.8,ry:.36,fill:c})}if(o("ninja-hood")&&(t.push({k:"rect",x:0,y:0,w:1.56,h:.6,r:.28,fill:e.skin??ae,stroke:e.outline,lw:n*.8}),t.push({k:"path",d:"M-0.98 -0.42 Q0 -0.74 0.98 -0.42 L1.0 -0.62 Q0 -0.94 -1.0 -0.62 Z",fill:e.accent,...r})),o("domino")){t.push({k:"path",d:K(se(-.86,-.04,-.62,-.3,-.18,-.24,0,-.16,.18,-.24,.62,-.3,.86,-.04,.6,.22,.16,.16,0,.1,-.16,.16,-.6,.22),.9),fill:e.accent,...r});for(let u of q)t.push({k:"ellipse",x:u*.38,y:0,rx:.19,ry:.13,fill:ae})}if(t.push(...Za(s,n)),o("brows"))for(let u of q)t.push({k:"line",pts:[u*.72,-.5,u*.14,-.3],stroke:e.accent,lw:.16});if(s.face.brows)for(let u of q)t.push({k:"line",pts:[u*.2,-.2,u*.54,-.28],stroke:s.face.brows,lw:.09});if(t.push(...Ja(s,n)),s.face.cheeks)for(let u of ja(s))t.push({k:"ellipse",x:u.x,y:u.y,rx:.15,ry:.1,fill:s.face.cheeks,alpha:.8});if(o("whiskers"))for(let u of q)for(let f of[-.1,.06])t.push({k:"line",pts:[u*.62,.38+f,u*1.06,.3+f*2.2],stroke:e.outline,lw:n*.7,alpha:.75});if(o("rainbow-mane")){let u=s.extraColors??["#f59ac0","#fbd46a","#8fd3f4"];t.push({k:"ellipse",x:.42,y:-.82,rx:.34,ry:.22,rot:.5,fill:u[0],...r}),t.push({k:"ellipse",x:.1,y:-.92,rx:.3,ry:.2,rot:.25,fill:u[1%u.length],...r})}if(s.ears==="unicorn"){let u=[{x:-.18,y:-.84},{x:.02,y:-1.72},{x:.18,y:-.84}];t.push({k:"path",d:Q(u,.12),fill:e.accent,...r});for(let f of[-1,-1.2,-1.4]){let h=.16*((f+1.72)/.88);t.push({k:"line",pts:[-h,f+.04,h,f-.04],stroke:e.outline,lw:n*.7,alpha:.6})}}if(o("flower-crown")){let u=[a(1,"#f7a8cf"),a(2,"#fff3a0"),a(3,ae)];for(let f of[-.84,-.28,.28,.84]){let h=kt(f,.9);t.push({k:"ellipse",x:h.x,y:h.y,rx:.14,ry:.07,rot:f+.5,fill:"#7cc76a",stroke:e.outline,lw:n*.7})}[-1.12,-.56,0,.56,1.12].forEach((f,h)=>{let b=kt(f,.9),y=h===2?.13:.11;for(let m=0;m<5;m++){let d=f+m/5*Math.PI*2;t.push({k:"circle",x:b.x+Math.sin(d)*y,y:b.y-Math.cos(d)*y,r:y*.82,fill:u[h%u.length],stroke:e.outline,lw:n*.7})}t.push({k:"circle",x:b.x,y:b.y,r:y*.62,fill:u[h%u.length]}),t.push({k:"circle",x:b.x,y:b.y,r:y*.42,fill:e.accent})})}if(o("helmet")){for(let u of q)t.push({k:"rect",x:u*1,y:.05,w:.26,h:.56,r:.12,fill:e.accent,...r});t.push({k:"path",d:"M-0.62 -0.62 Q-0.3 -0.92 0.12 -0.9",stroke:ae,lw:.1,alpha:.9})}if(o("bolts"))for(let u of q)t.push({k:"rect",x:u*1.08,y:.08,w:.2,h:.44,r:.08,fill:e.accent,...r});if(o("tuft")&&t.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:e.body,...r}),o("eggshell")&&t.push({k:"path",d:"M-0.88 -0.5 C-0.88 -1.12 -0.46 -1.42 0 -1.42 C0.46 -1.42 0.88 -1.12 0.88 -0.5 L0.66 -0.66 L0.44 -0.48 L0.22 -0.66 L0 -0.48 L-0.22 -0.66 L-0.44 -0.48 L-0.66 -0.66 Z",fill:a(0,ae),...r}),o("wool"))for(let[u,f]of[[-.36,-.84],[.02,-.94],[.4,-.82]])t.push({k:"circle",x:u,y:f,r:.27,fill:e.body,...r});if(o("stripe")&&t.push({k:"rect",x:0,y:-.64,w:.38,h:.62,r:.06,fill:e.accent}),o("eye-patch")&&(t.push({k:"line",pts:[-.97,-.5,.97,.13],stroke:e.outline,lw:.07}),t.push({k:"ellipse",x:.38,y:.02,rx:.21,ry:.19,fill:e.outline})),o("bandana")){t.push({k:"path",d:K(se(-1.05,-.22,-.96,-.72,-.5,-1.08,.1,-1.14,.72,-.96,1.04,-.56,1.05,-.22,.5,-.46,-.5,-.46)),fill:e.accent,...r});for(let[u,f]of[[-.5,-.8],[.08,-.92],[.6,-.74],[-.12,-.62],[.36,-.6]])t.push({k:"circle",x:u,y:f,r:.06,fill:ae,alpha:.85});t.push({k:"circle",x:-.98,y:-.34,r:.15,fill:e.accent,...r})}if(o("cap")){for(let u of q)t.push({k:"line",pts:[u*.98,-.2,u*.5,.82,-u*.05,.98],stroke:e.outline,lw:.06});t.push({k:"path",d:K(se(-1.1,-.16,-1.04,-.66,-.6,-1.12,0,-1.24,.6,-1.12,1.04,-.66,1.1,-.16,.5,-.4,-.5,-.4)),fill:e.accent,...r}),t.push({k:"path",d:"M-0.74 -0.4 Q0 -0.6 0.74 -0.4 Q0.8 -0.24 0.6 -0.22 Q0 -0.36 -0.6 -0.22 Q-0.8 -0.24 -0.74 -0.4 Z",fill:e.accent,...r}),t.push({k:"circle",x:.5,y:-.82,r:.15,fill:a(0,ae),...r});for(let u of[-.42,-.14])t.push({k:"line",pts:[u,-1.04,u+.02,-.78],stroke:e.outline,lw:.07,alpha:.7})}if(o("safari-hat")&&(t.push({k:"ellipse",x:0,y:-.56,rx:1.48,ry:.3,fill:e.accent,...r}),t.push({k:"path",d:K(se(-.78,-.58,-.7,-1.1,-.3,-1.38,.3,-1.38,.7,-1.1,.78,-.58,0,-.5),.8),fill:e.accent,...r}),t.push({k:"path",d:"M-0.77 -0.72 Q0 -0.62 0.77 -0.72 L0.74 -0.9 Q0 -0.8 -0.74 -0.9 Z",fill:a(1,e.outline),stroke:e.outline,lw:n*.8})),o("wizard-hat")){t.push({k:"ellipse",x:0,y:-.62,rx:1.32,ry:.26,fill:e.accent,...r}),t.push({k:"path",d:Q(se(-.8,-.66,-.36,-1.5,.5,-2.2,.3,-1.46,.8,-.66),.3),fill:e.accent,...r});let u=a(0,Va);for(let[f,h,b]of[[.02,-1.08,.18],[-.38,-.84,.1],[.36,-1.5,.11]])t.push({k:"group",x:f,y:h,s:b,items:[{k:"path",d:et,fill:u}]})}if(o("dive-mask")){for(let f of q)t.push({k:"line",pts:[f*.7,-.04,f*1,-.12],stroke:e.outline,lw:.2},{k:"line",pts:[f*.7,-.04,f*1,-.12],stroke:e.accent,lw:.11});t.push({k:"rect",x:0,y:0,w:1.42,h:.62,r:.28,fill:"#bfe9f5",alpha:.35}),t.push({k:"rect",x:0,y:0,w:1.42,h:.62,r:.28,stroke:e.outline,lw:.2}),t.push({k:"rect",x:0,y:0,w:1.42,h:.62,r:.28,stroke:e.accent,lw:.11}),t.push({k:"path",d:"M-0.5 -0.16 Q-0.4 -0.24 -0.22 -0.24",stroke:ae,lw:.06,alpha:.9});let u="M0.5 0.52 Q0.98 0.56 1.04 0.1 L1.12 -0.92";t.push({k:"path",d:u,stroke:e.outline,lw:.24},{k:"path",d:u,stroke:e.accent,lw:.13})}return t}function Xa(s,n){let e=s.headExtras.includes("ninja-hood")?s.palette.body:s.palette.skin??s.palette.body;switch(s.head){case"round":return{k:"circle",x:0,y:0,r:1,fill:e,...n};case"wide":return{k:"ellipse",x:0,y:.03,rx:1.12,ry:.94,fill:e,...n};case"tall":return{k:"ellipse",x:0,y:-.02,rx:.94,ry:1.04,fill:e,...n};case"square":return{k:"rect",x:0,y:0,w:2,h:1.8,r:.46,fill:e,...n};case"bucket":return{k:"path",d:Q(se(-.94,.96,-.98,-.36,-.62,-1.04,.62,-1.04,.98,-.36,.94,.96),.42),fill:e,...n};case"snout-long":return{k:"path",d:K(qa,.95),fill:e,...n};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:e,...n}}}var qa=se(.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 Ns(s,n,e){return s.head==="snout-long"?[{x:-.36,y:-.5,k:.95},{x:.26,y:-.48,k:1.1}]:q.map(t=>({x:t*n,y:e,k:1}))}function ja(s){return s.head==="snout-long"?se(-.66,-.14,.66,.1):q.map(n=>({x:n*.64,y:.3}))}function Ya(s){return s.head==="round"?{cy:0,rx:1,ry:1}:s.head==="tall"?{cy:-.02,rx:.94,ry:1.04}:{cy:.03,rx:1.12,ry:.94}}function Ka(s,n){let{cy:e,rx:t,ry:r}=Ya(s),o=t-n/2,a=r-n/2,i=.15,l=Math.asin(Math.min(1,(i-e)/a)),c=Math.cos(l)*o,u=y=>Math.round(y*100)/100||0,f=[re.M,u(-c),i],h=[[-.84*c,.02,-.53*c,.06,-.32*c,.24],[-.17*c,.11,.17*c,.11,.32*c,.24],[.53*c,.06,.84*c,.02,c,i]];for(let y of h)f.push(re.C,...y.map(u));let b=24;for(let y=1;y<=b;y++){let m=l+(Math.PI-2*l)*y/b;f.push(re.L,u(Math.cos(m)*o),u(e+Math.sin(m)*a))}return f.push(re.Z),f}function Qa(s,n){let e=s.palette,t={stroke:e.outline,lw:n},r=[];for(let o of q)switch(s.ears){case"pointy":case"unicorn":{let a=s.ears==="unicorn"?.8:1,i={x:o*.3,y:-.82},l={x:o*.86,y:-.82-.62*a},c={x:o*.94,y:-.36};r.push({k:"path",d:Q([i,l,c],.2),fill:e.body,...t});let u={x:(i.x+l.x+c.x)/3,y:(i.y+l.y+c.y)/3},f=[i,l,c].map(h=>({x:u.x+(h.x-u.x)*.55,y:u.y+(h.y-u.y)*.55+.04}));r.push({k:"path",d:Q(f,.25),fill:e.accent});break}case"round":r.push({k:"circle",x:o*.72,y:-.72,r:.36,fill:e.ears??e.body,...t}),e.ears||r.push({k:"circle",x:o*.74,y:-.74,r:.19,fill:e.accent});break;case"big-round":r.push({k:"circle",x:o*.96,y:-.46,r:.52,fill:e.body,...t}),r.push({k:"circle",x:o*1,y:-.44,r:.32,fill:e.accent});break;case"long":r.push({k:"ellipse",x:o*.38,y:-1.42,rx:.25,ry:.68,rot:o*.14,fill:e.body,...t}),r.push({k:"ellipse",x:o*.39,y:-1.36,rx:.12,ry:.48,rot:o*.14,fill:e.accent});break;case"side":r.push({k:"circle",x:o*1,y:.02,r:.34,fill:e.body,...t}),r.push({k:"circle",x:o*1.02,y:.02,r:.2,fill:e.belly});break;case"tufts":r.push({k:"path",d:Q([{x:o*.3,y:-.84},{x:o*1.22,y:-1.12},{x:o*.92,y:-.42}],.16),fill:e.body,...t}),r.push({k:"line",pts:[o*.62,-.78,o*1,-.98],stroke:e.accent,lw:.08});break;case"antennae":{let a={x:o*.62,y:-1.42};r.push({k:"path",d:`M${o*.3} -0.8 Q${o*.36} -1.2 ${a.x} ${a.y}`,stroke:e.outline,lw:n*2.6}),r.push({k:"path",d:`M${o*.3} -0.8 Q${o*.36} -1.2 ${a.x} ${a.y}`,stroke:e.body,lw:n*1.2}),r.push({k:"circle",x:a.x,y:a.y,r:.17,fill:e.accent,...t});break}case"floppy":r.push({k:"ellipse",x:o*.96,y:.02,rx:.3,ry:.62,rot:-o*.36,fill:e.ears??e.body,...t});break;case"droopy":r.push({k:"ellipse",x:o*1.04,y:-.22,rx:.4,ry:.18,rot:o*.32,fill:e.skin??e.body,...t}),r.push({k:"ellipse",x:o*1.08,y:-.2,rx:.24,ry:.08,rot:o*.32,fill:e.accent});break;case"pixie":r.push({k:"path",d:Q(se(o*.86,-.22,o*1.36,-.5,o*1.02,.26),.28),fill:e.skin??e.body,...t}),r.push({k:"line",pts:[o*.98,-.12,o*1.16,-.3],stroke:e.accent,lw:n*.8,alpha:.5});break;case"human":r.push({k:"ellipse",x:o*.98,y:.06,rx:.17,ry:.23,fill:e.skin??e.body,...t});break;case"horns":{let a=[{x:o*.3,y:-.84},{x:o*.6,y:-1.5},{x:o*.66,y:-.68}];r.push({k:"path",d:Q(a,.18),fill:e.accent,...t});break}}return s.ears==="fin"&&r.push({k:"path",d:Q(se(-.4,-.82,.2,-1.62,.46,-.78),.2),fill:e.body,...t}),s.ears==="antenna"&&(r.push({k:"line",pts:[0,-.85,0,-1.42],stroke:e.outline,lw:n*2.6}),r.push({k:"line",pts:[0,-.85,0,-1.42],stroke:e.limbs,lw:n*1.2}),r.push({k:"circle",x:0,y:-1.5,r:.18,fill:e.accent,...t})),r}function Za(s,n){let e=s.palette,t=s.face,r=[],o=e.outline,a=t.eyesOnTop?.46:.4,i=t.eyesOnTop?-.72:-.04,l=(c,u,f)=>({k:"circle",x:c,y:u,r:f,fill:ae});switch(t.eyes){case"dot":for(let c of Ns(s,a,i))r.push({k:"ellipse",x:c.x,y:c.y,rx:.12*c.k,ry:.155*c.k,fill:o}),r.push(l(c.x+.04*c.k,c.y-.06*c.k,.045*c.k));break;case"bead":for(let c of Ns(s,a,i))r.push({k:"ellipse",x:c.x,y:c.y,rx:.16*c.k,ry:.22*c.k,fill:o}),r.push(l(c.x+.05*c.k,c.y-.08*c.k,.065*c.k));break;case"big":for(let c of q)t.eyeRing&&r.push({k:"circle",x:c*a,y:i,r:.36,fill:t.eyeRing,stroke:o,lw:n*.8}),r.push({k:"circle",x:c*a,y:i,r:.25,fill:ae,stroke:o,lw:n*.8}),r.push({k:"circle",x:c*a+c*-.03,y:i+.03,r:.14,fill:t.eyeColor??o}),r.push(l(c*a+c*-.03+.05,i-.03,.05));break;case"mask":for(let c of q)r.push({k:"ellipse",x:c*.4,y:0,rx:.24,ry:.32,rot:c*-.55,fill:e.limbs}),r.push({k:"circle",x:c*.4,y:-.02,r:.11,fill:ae}),r.push({k:"circle",x:c*.39,y:-0,r:.065,fill:o});break;case"screen":r.push({k:"rect",x:0,y:0,w:1.5,h:.66,r:.26,fill:"#24323d",stroke:o,lw:n*.8});for(let c of q)r.push({k:"ellipse",x:c*.36,y:0,rx:.2,ry:.24,fill:t.eyeColor??"#7ff0ff",alpha:.3}),r.push({k:"ellipse",x:c*.36,y:0,rx:.12,ry:.16,fill:t.eyeColor??"#7ff0ff"});break;case"almond":for(let c of q)r.push({k:"ellipse",x:c*.42,y:-.02,rx:.3,ry:.2,rot:-c*.5,fill:t.eyeColor??o}),r.push(l(c*.42-c*.07,-.08,.07));break;case"calm":for(let c of q)r.push({k:"ellipse",x:c*.38,y:.02,rx:.085,ry:.12,fill:o}),r.push(l(c*.38+.03,-.02,.03));break;case"slit":r.push({k:"line",pts:[0,-.98,0,-.2],stroke:o,lw:n*.8,alpha:.5}),r.push({k:"rect",x:0,y:-.04,w:1.56,h:.26,r:.1,fill:Ar,stroke:o,lw:n*.8}),r.push({k:"rect",x:0,y:.3,w:.22,h:.46,r:.08,fill:Ar,stroke:o,lw:n*.8});for(let c of q){r.push({k:"ellipse",x:c*.4,y:-.04,rx:.12,ry:.07,fill:t.eyeColor??ae});for(let u of[.36,.56])r.push({k:"circle",x:c*.42,y:u,r:.05,fill:o,alpha:.6})}break;case"goggle":for(let c of q)r.push({k:"circle",x:c*.9,y:0,r:.13,fill:e.accent,stroke:o,lw:n*.8});r.push({k:"rect",x:0,y:0,w:1.66,h:.62,r:.3,fill:Ar,stroke:o,lw:n*.8}),r.push({k:"path",d:"M-0.6 -0.16 Q-0.42 -0.24 -0.12 -0.24",stroke:ae,lw:.07,alpha:.8});for(let c of q)r.push({k:"path",d:`M${c*.5} 0.04 Q${c*.34} -0.08 ${c*.16} 0.02`,stroke:t.eyeColor??"#7fd6ff",lw:.08});for(let c of[-.18,0,.18])r.push({k:"line",pts:[c,.56,c,.72],stroke:o,lw:n*.8,alpha:.6});break;case"visor":r.push({k:"ellipse",x:0,y:.08,rx:.8,ry:.64,fill:"#2a3f6b",stroke:o,lw:n*.8}),r.push({k:"path",d:"M-0.56 -0.14 Q-0.46 -0.4 -0.16 -0.46",stroke:ae,lw:.08,alpha:.7});for(let c of q)r.push({k:"ellipse",x:c*.28,y:.04,rx:.1,ry:.14,fill:t.eyeColor??"#cfeeff"});break}return r}function Ja(s,n){let e=s.palette,t=s.face,r=[],o=t.eyes==="visor"?"#cfeeff":Ls,a=n*1.05;switch(t.nose&&t.mouth!=="beak"&&(t.mouth==="cat"?r.push({k:"path",d:Q([{x:-.1,y:.22},{x:.1,y:.22},{x:0,y:.33}],.3),fill:t.nose,stroke:t.nose,lw:n*.6}):s.ears==="big-round"?r.push({k:"ellipse",x:0,y:.22,rx:.2,ry:.25,fill:t.nose}):r.push({k:"ellipse",x:0,y:.25,rx:.13,ry:.085,fill:t.nose})),t.mouth){case"smile":r.push({k:"path",d:t.eyes==="visor"?"M-0.16 0.32 Q0 0.46 0.16 0.32":"M-0.17 0.42 Q0 0.58 0.17 0.42",stroke:o,lw:a});break;case"open":r.push({k:"path",d:"M-0.21 0.4 Q0 0.46 0.21 0.4 Q0.19 0.68 0 0.68 Q-0.19 0.68 -0.21 0.4 Z",fill:o,stroke:o,lw:n*.5}),r.push({k:"ellipse",x:0,y:.6,rx:.1,ry:.06,fill:Is});break;case"cat":r.push({k:"path",d:"M-0.19 0.4 Q-0.1 0.5 0 0.37 Q0.1 0.5 0.19 0.4",stroke:o,lw:a});break;case"beak":r.push({k:"path",d:Q([{x:-.17,y:.2},{x:.17,y:.2},{x:0,y:.48}],.25),fill:e.accent,stroke:e.outline,lw:n*.8});break;case"teeth":r.push({k:"path",d:"M-0.36 0.34 Q0 0.44 0.36 0.34 Q0.28 0.66 0 0.66 Q-0.28 0.66 -0.36 0.34 Z",fill:o,stroke:o,lw:n*.5});for(let i of q)r.push({k:"rect",x:i*.12,y:.43,w:.1,h:.1,r:.03,fill:ae});break;case"grill":r.push({k:"rect",x:0,y:.56,w:.62,h:.2,r:.08,fill:"#24323d",stroke:e.outline,lw:n*.7});for(let i of[-.15,0,.15])r.push({k:"line",pts:[i,.51,i,.61],stroke:"#9fb0bd",lw:n*.6});break;case"tiny":r.push({k:"ellipse",x:0,y:.44,rx:.08,ry:.1,fill:o});break;case"smirk":r.push({k:"path",d:"M-0.16 0.46 Q0.06 0.54 0.22 0.38",stroke:o,lw:a});break;case"bill":r.push({k:"ellipse",x:0,y:.36,rx:.44,ry:.2,fill:e.accent,stroke:e.outline,lw:n*.8}),r.push({k:"path",d:"M-0.36 0.38 Q0 0.46 0.36 0.38",stroke:e.outline,lw:n*.7});for(let i of q)r.push({k:"circle",x:i*.1,y:.28,r:.03,fill:e.outline});break;case"hook":r.push({k:"ellipse",x:0,y:.48,rx:.16,ry:.11,fill:Ls}),r.push({k:"path",d:"M-0.3 0.12 Q0 -0.02 0.3 0.12 Q0.36 0.52 0.04 0.76 Q0.08 0.52 -0.08 0.46 Q-0.28 0.38 -0.3 0.12 Z",fill:e.accent,stroke:e.outline,lw:n*.8});break;case"toothy":{r.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:o,stroke:o,lw:n*.6}),r.push({k:"ellipse",x:-.38,y:.5,rx:.24,ry:.08,fill:Is});for(let i of[.12,.27,.42,.57,.72,.86]){let l=(1-i)*(1-i)*-1.4+2*(1-i)*i*-.5+i*i*.5,c=(1-i)*(1-i)*.1+2*(1-i)*i*.36+i*i*.2-.01;r.push({k:"path",d:Q(se(l-.08,c,l+.08,c,l,c+.14),.3),fill:ae})}for(let i of[.3,.7]){let l=(1-i)*(1-i)*.52+2*(1-i)*i*-.4+i*i*-1.3,c=(1-i)*(1-i)*.38+2*(1-i)*i*.78+i*i*.26+.01;r.push({k:"path",d:Q(se(l-.07,c,l+.07,c,l,c-.12),.3),fill:ae})}break}case"jaws":{r.push({k:"path",d:"M-0.5 0.3 Q0 0.5 0.5 0.3 Q0.38 0.72 0 0.72 Q-0.38 0.72 -0.5 0.3 Z",fill:o,stroke:o,lw:n*.5});for(let i of[-.34,-.17,0,.17,.34]){let l=.3+.4*(i+.5)*(.5-i)-.01;r.push({k:"path",d:Q(se(i-.075,l,i+.075,l,i,l+.13),.15),fill:ae})}break}}return r}var kt=(s,n)=>({x:Math.sin(s)*n,y:-Math.cos(s)*n});var Hs=.5,Ve={leftEye:2,rightEye:5,leftEar:7,rightEar:8},tt={"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}},Dn="6-8",zn=(s,n)=>n!==void 0&&s.band!=="all"&&s.alsoIn?.includes(n)&&n in tt?n:s.band in tt?s.band:Dn,ei=tt[Dn].head,$s=.3,Gs=.12,ti=.9,Bs=.5,Ds=.65,ni=.35,ri=.2,si=.25,Ge=(s,n)=>({x:s.x-n.x,y:s.y-n.y}),te=(s,n)=>({x:s.x+n.x,y:s.y+n.y}),Z=(s,n)=>({x:s.x*n,y:s.y*n}),wt=s=>Math.hypot(s.x,s.y),Os=(s,n)=>({x:(s.x+n.x)/2,y:(s.y+n.y)/2}),On=s=>{let n=wt(s);return n>1e-9?{x:s.x/n,y:s.y/n}:{x:0,y:1}},oi=(...s)=>s.every(Number.isFinite),ai=s=>Math.atan2(Math.sin(s),Math.cos(s)),ii=(s,n,e)=>Math.min(Math.max(s,n),e);function Us(s,n,e=!1){return t=>{let r=s[t*3],o=s[t*3+1],a=s[t*3+2];return r===void 0||o===void 0||a===void 0||!oi(r,o,a)?{x:0,y:0,ok:!1}:{x:n.x+(e?1-r:r)*n.w,y:n.y+o*n.h,ok:a>=Hs}}}function Nt(s,n,e={}){let t=Us(s,n,e.mirrored),r=t(Y.leftShoulder),o=t(Y.rightShoulder);if(!r.ok||!o.ok)return null;let a=t(Y.leftHip),i=t(Y.rightHip),l=Os(r,o),c=wt(Ge(o,r)),u=a.ok&&i.ok,f=On(Ge(o,r));c<1e-6&&(f={x:1,y:0});let h,b,y;if(u){let E=Os(a,i);b=wt(Ge(E,l)),b>=c*si?h=On(Ge(E,l)):(h={x:-f.y,y:f.x},h.y<0&&(h=Z(h,-1))),y=Math.max(b,c*1.15)}else h={x:-f.y,y:f.x},h.y<0&&(h=Z(h,-1)),y=c*1.15,b=y;y=Math.max(y,1e-6);let m={x:h.y,y:-h.x},d=Math.atan2(m.y,m.x),x=Z(h,-1),g=tt[e.band??Dn]??tt[Dn],A=g.head*y,w=te(l,Z(x,A*g.neck)),v=t(Y.nose);if(v.ok){let E=te(v,Z(x,A*.15)),F=Z(Ge(E,w),ni),L=Math.min(1,A*ri/Math.max(wt(F),1e-6));w=te(w,Z(F,L))}return{S:l,r:m,d:h,U:y,L:b,hipsOk:u,head:w,headR:A,headRot:d+li(s,t,d,y),angle:d}}function li(s,n,e,t){let r=[[Ve.leftEar,Ve.rightEar],[Ve.leftEye,Ve.rightEye]];for(let[o,a]of r){let i=n(o),l=n(a);if(!i.ok||!l.ok||!(s[o*3+2]>=Ds&&s[a*3+2]>=Ds)||wt(Ge(l,i))<t*.05)continue;let c=ai(Math.atan2(l.y-i.y,l.x-i.x)-e),u=Math.max(Math.abs(c)-Gs,0),f=ii((ti+Bs-Math.abs(c))/Bs,0,1);return Math.sign(c)*Math.min(u,$s)*f}return 0}function ln(s,n,e,t={}){let r=zn(n,t.band),o=tt[r],a=Nt(s,e,{...t,band:r});if(!a)return[];let i=Us(s,e,t.mirrored),l=n.palette,{S:c,r:u,d:f,U:h,L:b}=a,y=S=>n.bodyExtras.includes(S),m=Math.max(1.2,h*.045),d={stroke:l.outline,lw:m},x=(S,I)=>({x:c.x+u.x*S+f.x*I,y:c.y+u.y*S+f.y*I}),g=S=>S.map(([I,B])=>x(I,B)),A=i(Y.leftShoulder),w=i(Y.rightShoulder),v=i(Y.leftHip),E=i(Y.rightHip),F=wt(Ge(w,A)),L=a.hipsOk?wt(Ge(E,v)):F*.7,_=Math.max(F/2+o.shoulderPad*h,o.shoulderMin*h),O=Math.max(L/2+o.hipPad*h,o.hipMin*h),H=-.1*h,V=b+o.bottom*h,G=[],be=[],$=[],oe=[],ye=[],Be=(S,I,B,X)=>{let U=I.flatMap(le=>[le.x,le.y]);S.push({k:"line",pts:U,stroke:l.outline,lw:B+m*2}),S.push({k:"line",pts:U,stroke:X,lw:B})},hr=o.leg*h*(y("strong-legs")?1.3:1),we=o.arm*h*(y("tiny-arms")?.6:1),De=Math.max(o.arm/.22,.9);if(a.hipsOk)for(let[S,I,B,X]of[[v,Y.leftKnee,Y.leftAnkle,-1],[E,Y.rightKnee,Y.rightAnkle,1]]){let U=i(I),le=i(B);if(!U.ok)continue;let Ft=te(S,Z(f,-.12*h)),ze=le.ok?[Ft,U,le]:[Ft,U];Be(be,ze,hr,l.limbs),y("joints")&&be.push({k:"circle",x:U.x,y:U.y,r:.15*h*De,fill:l.accent,...d}),le.ok&&be.push(...hi(n,le,a,X,m,o.foot))}for(let[S,I,B,X]of[[A,Y.leftElbow,Y.leftWrist,-1],[w,Y.rightElbow,Y.rightWrist,1]]){let U=i(I),le=i(B);if(y("pauldrons")){let ve=te(S,Z(f,.02*h));oe.push({k:"ellipse",x:ve.x,y:ve.y,rx:.25*h,ry:.17*h,rot:a.angle+X*.25,fill:l.body,...d});let Pe=te(ve,Z(f,.05*h));oe.push({k:"ellipse",x:Pe.x,y:Pe.y,rx:.17*h,ry:.07*h,rot:a.angle+X*.25,fill:l.belly})}if(!U.ok)continue;let ze=o.armsOverHead&&(U.x-c.x)*f.x+(U.y-c.y)*f.y<-.25*h?ye:oe,nn=te(S,Z(f,.04*h));if(Be(ze,le.ok?[nn,U,le]:[nn,U],we,l.limbs),y("joints")&&ze.push({k:"circle",x:U.x,y:U.y,r:.13*h*De,fill:l.accent,...d}),!le.ok)continue;let pe=On(Ge(le,U)),Ze=te(le,Z(pe,.05*h));if(y("feathers"))for(let ve of[-.55,0,.55]){let Pe=Math.cos(ve),bt=Math.sin(ve)*X,Ae={x:pe.x*Pe-pe.y*bt,y:pe.x*bt+pe.y*Pe},He=te(Ze,Z(Ae,.16*h));ze.push({k:"ellipse",x:He.x,y:He.y,rx:.2*h,ry:.09*h,rot:Math.atan2(Ae.y,Ae.x),fill:l.hands??l.accent,...d})}y("wand")&&X===1&&!t.portrait&&ze.push(...di(n,Ze,On(te(Z(pe,.4),Ge(Z(u,.6),f))),h,m));let Je=o.hand*h*(y("tiny-arms")?.72:1);if(y("tiny-arms"))for(let ve of[-.45,.45]){let Pe=Math.cos(ve),bt=Math.sin(ve),Ae={x:pe.x*Pe-pe.y*bt,y:pe.x*bt+pe.y*Pe},He=te(Ze,Z(Ae,Je*.75)),fr=te(Ze,Z(Ae,Je*1.6)),Rn={x:-Ae.y*Je*.32,y:Ae.x*Je*.32};ze.push({k:"path",d:Q([te(He,Rn),fr,Ge(He,Rn)],.2),fill:l.belly,...d})}ze.push({k:"circle",x:Ze.x,y:Ze.y,r:Je,fill:l.hands??l.limbs,...d})}if(y("wings"))for(let S of[-1,1]){let I=g([[S*_*.5,.05*h],[S*(_+.85*h),-.6*h],[S*(_+.72*h),.05*h],[S*(_+.45*h),-.02*h],[S*(_+.3*h),.32*h],[S*_*.6,.55*h]]);G.push({k:"path",d:Q(I,.18),fill:l.accent,...d})}if(y("wings-fairy")&&G.push(...mi(n,x,_,h,m)),y("cape")){let S=b+.8*h,I=O+.36*h,B=g([[-_*.92,H+.04*h],[_*.92,H+.04*h],[_+.16*h,b*.5],[I,S],[I*.5,S-.1*h],[0,S],[-I*.5,S-.1*h],[-I,S],[-_-.16*h,b*.5]]);G.push({k:"path",d:K(B,.6),fill:l.accent,...d})}if(y("backpack")){let S=x(0,.35*h);G.push({k:"rect",x:S.x,y:S.y,w:_*2+.34*h,h:.8*h,r:.16*h,rot:a.angle,fill:n.extraColors?.[0]??l.limbs,...d})}if(y("tank")){let S=x(_*.95,.24*h),I=n.extraColors?.[0]??l.accent,B=x(_*.95,-.3*h);G.push({k:"rect",x:B.x,y:B.y,w:.14*h,h:.16*h,r:.04*h,rot:a.angle,fill:l.outline}),G.push({k:"rect",x:S.x,y:S.y,w:.34*h,h:1*h,r:.17*h,rot:a.angle,fill:I,...d})}if(a.hipsOk&&!t.portrait&&G.push(...pi(n,a,O,m)),y("tentacles")&&a.hipsOk)for(let S of[-1,1]){let I=g([[S*O*.7,b*.9],[S*(O+.22*h),b+.3*h],[S*(O+.48*h),b+.22*h],[S*(O+.5*h),b-.02*h],[S*(O+.34*h),b-.06*h]]);G.push({k:"path",d:It(I),stroke:l.outline,lw:.2*h+m*2}),G.push({k:"path",d:It(I),stroke:l.limbs,lw:.2*h})}let xe=Math.max(_,O)*o.bulge;if(y("wool")){for(let[I,B]of[[_*.7,H+.02*h],[xe,b*.3],[xe*1.02,b*.62],[(xe+O)/2,b*.92],[O*.55,V]])for(let X of[-1,1]){let U=x(X*I,B);$.push({k:"circle",x:U.x,y:U.y,r:.2*h,fill:l.body,...d})}let S=x(0,V+.02*h);$.push({k:"circle",x:S.x,y:S.y,r:.2*h,fill:l.body,...d})}if(y("robe")){let S=b+.58*h,I=O*1.4;$.push({k:"path",d:K(g([[-_,H],[0,H-.04*h],[_,H],[xe,b*.55],[I,S],[0,S+.06*h],[-I,S],[-xe,b*.55]]),.7),fill:l.body,...d});let B=g([[-I*.94,S-.1*h],[0,S-.04*h],[I*.94,S-.1*h]]);$.push({k:"path",d:It(B),stroke:n.extraColors?.[0]??l.accent,lw:.07*h})}else if(y("sheet")){let S=b+.78*h,I=O*1.3;$.push({k:"path",d:K(g([[-_,H],[_,H],[xe,b*.55],[I,S],[I*.5,S-.2*h],[0,S],[-I*.5,S-.2*h],[-I,S],[-xe,b*.55]]),.9),fill:l.body,...d})}else $.push({k:"path",d:K(g([[-_,H],[0,H-.04*h],[_,H],[xe,b*.55],[O,V],[0,V+.03*h],[-O,V],[-xe,b*.55]]),.85),fill:l.body,...d});let fe=Math.min(_,O);if(y("pocket")){let S=x(0,b*.74);$.push({k:"rect",x:S.x,y:S.y,w:fe*1.3,h:.3*h,r:.1*h,rot:a.angle,fill:l.belly,stroke:l.outline,lw:m*.8})}else if(y("racing-stripe"))for(let S of[-.1,.1]){let I=x(S*h,H+.02*h),B=x(S*h,V-.04*h);$.push({k:"line",pts:[I.x,I.y,B.x,B.y],stroke:l.belly,lw:.1*h})}else if(l.belly&&l.belly!==l.body&&!y("panel")&&!y("sheet")&&!y("stripes")){let S=x(0,b*.58);$.push({k:"ellipse",x:S.x,y:S.y,rx:fe*.64,ry:Math.max(b*.36,.2*h),rot:a.angle,fill:l.belly})}if(y("spots")){let S=n.extraColors?.[1]??l.belly;for(let[I,B,X]of[[-.55,.35,.09],[.5,.62,.11],[-.35,.86,.07]]){let U=x(I*fe,B*b);$.push({k:"circle",x:U.x,y:U.y,r:X*h,fill:S})}}if(y("stripes")){let S=n.extraColors?.[1]??l.accent;for(let I of[.22,.44,.66]){let B=x(-fe*.98,b*I),X=x(fe*.98,b*I);$.push({k:"line",pts:[B.x,B.y,X.x,X.y],stroke:S,lw:.1*h})}}if(y("straps")){let S=n.extraColors?.[1]??l.outline;for(let I of[-1,1]){let B=x(I*_*.62,H+.02*h),X=x(I*fe*.62,b*.72);$.push({k:"line",pts:[B.x,B.y,X.x,X.y],stroke:l.outline,lw:.13*h+m*2}),$.push({k:"line",pts:[B.x,B.y,X.x,X.y],stroke:S,lw:.13*h})}}if(y("belt")){let S=x(0,b*.9);$.push({k:"rect",x:S.x,y:S.y,w:O*1.92,h:.17*h,r:.06*h,rot:a.angle,fill:n.extraColors?.[2]??"#4a3426",...d}),$.push({k:"rect",x:S.x,y:S.y,w:.2*h,h:.19*h,r:.04*h,rot:a.angle,fill:"#ffd84a",...d})}if(y("emblem")){let S=x(0,b*.4),I=n.extraColors?.[0]??l.accent,B=Q([{x:-.22,y:-.2},{x:.22,y:-.2},{x:.22,y:.04},{x:0,y:.26},{x:-.22,y:.04}],.25);$.push({k:"group",x:S.x,y:S.y,rot:a.angle,s:h,items:[{k:"path",d:B,fill:I,stroke:l.outline,lw:m/h},{k:"group",x:0,y:.01,s:.12,items:[{k:"path",d:et,fill:I===l.accent?"#ffffff":l.accent}]}]})}if(y("panel")){let S=x(0,b*.5);$.push({k:"rect",x:S.x,y:S.y,w:fe*1.2,h:.38*h,r:.1*h,rot:a.angle,fill:"#24323d",...d}),(n.extraColors??["#ff7a6b","#fbd46a","#7ff0ff"]).slice(0,3).forEach((B,X)=>{let U=x((X-1)*fe*.34,b*.5);$.push({k:"circle",x:U.x,y:U.y,r:.075*h,fill:B})})}if(y("badge")){let S=x(-fe*.42,b*.36);$.push({k:"circle",x:S.x,y:S.y,r:.15*h,fill:l.accent,...d}),$.push({k:"group",x:S.x,y:S.y,rot:a.angle,s:.09*h,items:[{k:"path",d:et,fill:"#ffffff"}]})}if(y("star")){let S=x(-fe*.5,b*.3),I=.15*h;$.push({k:"group",x:S.x,y:S.y,rot:a.angle-.2,s:I,items:[{k:"path",d:et,fill:n.extraColors?.[0]??"#ffd84a",stroke:l.outline,lw:m*.8/I}]})}if(y("petals")&&$.push(...bi(n,x,_,O,xe,b,V,h,m,o)),y("scarf")){let S=Math.max(.04,o.head*(1-o.neck)-.06)*h,I=x(0,S),B=n.extraColors?.[0]??l.accent,X=x(_*.45,S+.28*h);$.push({k:"rect",x:X.x,y:X.y,w:.16*h,h:.42*h,r:.06*h,rot:a.angle+.15,fill:B,...d}),$.push({k:"rect",x:I.x,y:I.y,w:_*2.05,h:.2*h,r:.1*h,rot:a.angle,fill:B,...d})}let Oe={k:"group",x:a.head.x,y:a.head.y,rot:a.headRot,s:a.headR,items:ui(n,m/a.headR)};return[...G,...be,...$,...oe,Oe,...ye]}var zs=new WeakMap,ci=64;function ui(s,n){let e=Number(n.toPrecision(4)),t=zs.get(s);t||zs.set(s,t=new Map);let r=t.get(e);return r||(t.size>=ci&&t.clear(),t.set(e,r=Bn(s,e))),r}function hi(s,n,e,t,r,o){let a=fi(s,n,e,t,r,o);if(!s.bodyExtras.includes("strong-legs"))return[a];let i=e.U*o,l=te(te(n,Z(e.d,.07*i)),Z(e.r,t*.06*i)),c=[a];for(let u of[-1,0,1]){let f=te(te(l,Z(e.r,u*.12*i)),Z(e.d,.09*i));c.push({k:"ellipse",x:f.x,y:f.y,rx:.05*i,ry:.045*i,rot:e.angle,fill:s.palette.belly,stroke:s.palette.outline,lw:r*.8})}return c}function fi(s,n,e,t,r,o){let a=s.palette,{d:i,r:l}=e,c=e.U*o,u=te(te(n,Z(i,.07*c)),Z(l,t*.06*c)),f={stroke:a.outline,lw:r},h=a.feet??a.limbs;if(s.bodyExtras.includes("fins")){let b=Q([{x:-.13,y:-.06},{x:.13,y:-.06},{x:.24,y:.46},{x:-.24,y:.46}],.22);return{k:"group",x:u.x,y:u.y,rot:e.angle,s:c,items:[{k:"path",d:b,fill:h,stroke:a.outline,lw:r/c},{k:"line",pts:[0,.06,0,.38],stroke:a.outline,lw:r/c,alpha:.5}]}}return s.bodyExtras.includes("flippers")?{k:"ellipse",x:u.x,y:u.y,rx:.27*c,ry:.11*c,rot:e.angle,fill:h,...f}:s.bodyExtras.includes("boots")?{k:"rect",x:u.x,y:u.y,w:.4*c,h:.24*c,r:.09*c,rot:e.angle,fill:h,...f}:{k:"ellipse",x:u.x,y:u.y,rx:.2*c,ry:.13*c,rot:e.angle,fill:h,...f}}function pi(s,n,e,t){let r=s.palette,{U:o,L:a,S:i,r:l,d:c}=n,u=(m,d)=>({x:i.x+l.x*m+c.x*d,y:i.y+l.y*m+c.y*d}),f=m=>m.map(([d,x])=>u(d,x)),h={stroke:r.outline,lw:t},b=(m,d,x)=>[{k:"path",d:It(m),stroke:r.outline,lw:d+t*2},{k:"path",d:It(m),stroke:x,lw:d}],y=[];switch(s.tail){case"none":break;case"fluffy":{let m=f([[e*.5,a*.95],[e+.28*o,a*1],[e+.72*o,a*.62],[e+.78*o,a*.12],[e+.52*o,a*.32],[e+.3*o,a*.6],[e*.6,a*.7]]);y.push({k:"path",d:K(m),fill:r.body,...h});let d=u(e+.72*o,a*.2);y.push({k:"ellipse",x:d.x,y:d.y,rx:.13*o,ry:.2*o,rot:n.angle+.25,fill:r.belly,...h});break}case"brush":{let m=f([[e*.4,a*.98],[e+.42*o,a*1.06],[e+.98*o,a*.66],[e+1.06*o,a*.12],[e+.86*o,-.04*o],[e+.66*o,a*.36],[e+.3*o,a*.66],[e*.5,a*.68]]);y.push({k:"path",d:K(m),fill:r.body,...h});let d=f([[e+1.03*o,a*.36],[e+1.06*o,a*.12],[e+.86*o,-.04*o],[e+.72*o,a*.24],[e+.86*o,a*.34]]);y.push({k:"path",d:K(d),fill:r.belly,...h});break}case"pom":{let m=u(e+.06*o,a*.88);y.push({k:"circle",x:m.x,y:m.y,r:.2*o,fill:r.belly,...h});break}case"long":case"striped":case"tuft":{let m=f([[e*.6,a*.9],[e+.35*o,a*.85],[e+.58*o,a*.4],[e+.5*o,-.02*o]]);if(y.push(...b(m,.14*o,r.body)),s.tail==="tuft"){let d=m[m.length-1];y.push({k:"circle",x:d.x,y:d.y,r:.16*o,fill:s.extraColors?.[0]??r.accent,...h})}if(s.tail==="striped"){for(let x of[.35,.6,.85]){let g=u(e+.35*o+.22999999999999998*o*(x*1.4>1?1:x*1.4),a*(.85-.85*x));y.push({k:"line",pts:[g.x-l.x*.08*o,g.y-l.y*.08*o,g.x+l.x*.08*o,g.y+l.y*.08*o],stroke:s.extraColors?.[0]??r.outline,lw:.06*o})}let d=m[m.length-1];y.push({k:"circle",x:d.x,y:d.y,r:.07*o,fill:s.extraColors?.[0]??r.outline})}break}case"curl":{let m=f([[e*.6,a*.9],[e+.4*o,a*.88],[e+.62*o,a*.45],[e+.5*o,a*.12],[e+.3*o,a*.24],[e+.36*o,a*.42]]);y.push(...b(m,.12*o,r.limbs));break}case"fish":{let m=f([[e*.6,a*.9],[e+.36*o,a*.86],[e+.6*o,a*.5]]);y.push(...b(m,.17*o,r.body));let d=m[m.length-1],x=Q([{x:0,y:.06},{x:-.26,y:-.34},{x:.02,y:-.12},{x:.32,y:-.3}],.2);y.push({k:"group",x:d.x,y:d.y,rot:n.angle+.35,s:o,items:[{k:"path",d:x,fill:r.body,stroke:r.outline,lw:t/o}]});break}case"plume":{let m=s.extraColors??[r.accent];[0,1,2].forEach(d=>{let x=u(e+(.12+d*.13)*o,a+(.32-d*.06)*o);y.push({k:"ellipse",x:x.x,y:x.y,rx:.11*o,ry:.44*o,rot:n.angle-.55+d*.28,fill:m[(d+1)%m.length],...h})});break}case"thick":{let m=f([[e*.3,a*.42],[e+.42*o,a*.62],[e+.92*o,a*.96],[e+1.32*o,a*1.08],[e+1.44*o,a*.98],[e+.98*o,a*1.2],[e+.4*o,a*1.22],[e*.3,a*1.12]]);y.push({k:"path",d:K(m,.8),fill:r.body,...h});let d=s.extraColors?.[0]??r.accent;for(let[x,g,A]of[[.28,.58,.26],[.62,.8,.22],[.96,1,.16]]){let w=u(e+x*o,a*g+.03*o),v=u(e+(x-.1)*o,a*g+A*o);y.push({k:"line",pts:[w.x,w.y,v.x,v.y],stroke:d,lw:.09*o})}break}case"spiky":case"arrow":{let m=f([[e*.3,a*.55],[e+.35*o,a*.68],[e+.95*o,a*.86],[e+.35*o,a*1.08],[e*.3,a*1.08]]);if(s.tail==="spiky"){for(let d of[.15,.45,.72]){let x=e+(.2+d*.7)*o,g=a*(.66+d*.19);y.push({k:"path",d:Q(f([[x-.12*o,g+.05*o],[x,g-.2*o],[x+.12*o,g+.07*o]]),.2),fill:r.accent,...h})}y.push({k:"path",d:K(m,.7),fill:r.body,...h})}else{let d=f([[e*.6,a*.9],[e+.4*o,a*.92],[e+.62*o,a*.5],[e+.62*o,a*.18]]);y.push(...b(d,.13*o,r.body));let x=d[d.length-1];y.push({k:"group",x:x.x,y:x.y,rot:n.angle,s:o,items:[{k:"path",d:Q([{x:-.15,y:.04},{x:0,y:-.22},{x:.15,y:.04}],.2),fill:r.accent,stroke:r.outline,lw:t/o}]})}break}}return y}function di(s,n,e,t,r){let o=s.palette,a=te(n,Z(e,-.08*t)),i=te(n,Z(e,.52*t)),l=.2*t;return[{k:"line",pts:[a.x,a.y,i.x,i.y],stroke:o.outline,lw:.06*t+r*2},{k:"line",pts:[a.x,a.y,i.x,i.y],stroke:"#fff3d6",lw:.06*t},{k:"circle",x:i.x,y:i.y,r:.24*t,fill:o.accent,alpha:.28},{k:"group",x:i.x,y:i.y,rot:Math.atan2(e.y,e.x)+Math.PI/2,s:l,items:[{k:"path",d:et,fill:o.accent,stroke:o.outline,lw:r*.9/l}]}]}function mi(s,n,e,t,r){let o=s.palette,a=s.extraColors?.[0]??"#cdeeff",i=[];for(let l of[-1,1]){let c=[[[l*e*.3,.12*t],[l*(e+.42*t),-.66*t],[l*(e+1*t),-.74*t],[l*(e+1.02*t),-.18*t],[l*(e+.5*t),.26*t]],[[l*e*.4,.3*t],[l*(e+.6*t),.36*t],[l*(e+.74*t),.78*t],[l*(e+.3*t),.9*t]]];for(let u of c){let f=K(u.map(([m,d])=>n(m,d)),.9);i.push({k:"path",d:f,fill:a,alpha:.6}),i.push({k:"path",d:f,stroke:o.outline,lw:r*.9});let h=u[Math.floor(u.length/2)],b=n(u[0][0],u[0][1]),y=n(u[0][0]+(h[0]-u[0][0])*.75,u[0][1]+(h[1]-u[0][1])*.75);i.push({k:"line",pts:[b.x,b.y,y.x,y.y],stroke:"#ffffff",lw:r*.9,alpha:.85})}for(let[u,f,h]of[[e+.72*t,-.42*t,.075*t],[e+.44*t,-.16*t,.05*t],[e+.5*t,.6*t,.055*t]]){let b=n(l*u,f);i.push({k:"group",x:b.x,y:b.y,s:h,items:[{k:"path",d:et,fill:"#ffffff"}]})}}return i}function bi(s,n,e,t,r,o,a,i,l,c){let u=s.palette,f=s.extraColors?.[1]??u.belly,h=[],b=Math.atan2(n(1,0).y-n(0,0).y,n(1,0).x-n(0,0).x),y=5,m=Math.max(t,r*.92)*1.08,d=(o*.8+a)/2,x=[0,4,1,3,2];for(let A of x){let w=A/(y-1)-.5,v=n(w*2*m,d+(.5-Math.abs(w))*.1*i);h.push({k:"ellipse",x:v.x,y:v.y,rx:m*.3,ry:.34*i,rot:b-w*.6,fill:A%2?f:u.body,stroke:u.outline,lw:l})}let g=Math.max(.04,c.head*(1-c.neck)-.04)*i;for(let A of[-1,1,0]){let w=n(A*e*.32,g+(A?0:.05*i));h.push({k:"ellipse",x:w.x,y:w.y,rx:e*.26,ry:.12*i,rot:b+A*.5,fill:A?f:u.body,stroke:u.outline,lw:l*.9})}return h}var yi={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 xi(s,{cx:n=.5,cy:e=.36,T:t=.18}={}){let r={...yi,...s},o=new Array(gr*3).fill(0),a=(c,[u,f],h=.99)=>{o[c*3]=n+u*t,o[c*3+1]=e+f*t,o[c*3+2]=h};for(let c of Object.keys(Y))a(Y[c],r[c]);let i=r.tilt??0,l=(c,u)=>[r.nose[0]+c*Math.cos(i)-u*Math.sin(i),r.nose[1]+c*Math.sin(i)+u*Math.cos(i)];return a(Ve.leftEye,l(-.1,-.08)),a(Ve.rightEye,l(.1,-.08)),a(Ve.leftEar,l(-.22,-.02)),a(Ve.rightEar,l(.22,-.02)),o}var Ws=()=>xi({});var cn=class{constructor(n={}){p(this,"tracks",new Map);p(this,"offset",NaN);p(this,"lastArrival",NaN);p(this,"interval",33);p(this,"lastT",NaN);p(this,"lostMs");p(this,"maxExtrapolateMs");this.lostMs=n.lostMs??250,this.maxExtrapolateMs=n.maxExtrapolateMs??25}get delayMs(){return this.interval}push(n,e,t,r=Vs()){Number.isFinite(e)||(e=r),this.clock(e,r);let o=this.tracks.get(n);if(!o||e-o.tb>this.lostMs||e<o.tb-this.lostMs||t.length!==o.b.length){this.tracks.set(n,{a:null,ta:e,b:t,tb:e,out:null,outAt:NaN});return}if(t===o.b||e<=o.tb){e===o.tb&&t!==o.b&&(o.b=t,o.out=null);return}o.a=o.b,o.ta=o.tb,o.b=t,o.tb=e,o.out=null}at(n,e=Vs()){let t=this.tracks.get(n);if(!t)return null;if(!t.a)return t.b;if(t.out&&t.outAt===e)return t.out;let r=e-this.offset-this.interval,o=t.tb-t.ta,a=Math.min(o*.5,this.maxExtrapolateMs),i=Math.min(Math.max((r-t.ta)/o,0),1+a/o);return t.out=Xs(t.a,t.b,i),t.outAt=e,t.out}forget(n){this.tracks.delete(n)}clear(){this.tracks.clear()}clock(n,e){let t=e-n;if(!Number.isFinite(this.offset)||t<this.offset||t>this.offset+1e3?this.offset=t:Number.isFinite(this.lastArrival)&&(this.offset+=Math.min(t-this.offset,(e-this.lastArrival)/1e3)),this.lastArrival=e,Number.isFinite(this.lastT)&&n>this.lastT){let r=n-this.lastT;r<this.interval*3+20&&(this.interval+=(Math.min(Math.max(r,8),100)-this.interval)*.1)}n<=this.lastT||(this.lastT=n)}},Vs=()=>globalThis.performance?.now()??Date.now();function Xs(s,n,e){let t=n.slice(),r=e<.5?s:n;for(let o=0;o+2<n.length;o+=3){let a=s[o],i=s[o+1],l=n[o],c=n[o+1];s[o+2]>=.5&&n[o+2]>=.5&&Math.abs(l-a)+Math.abs(c-i)<.15?(t[o]=a+(l-a)*e,t[o+1]=i+(c-i)*e,t[o+2]=s[o+2]+(n[o+2]-s[o+2])*Math.min(e,1)):(t[o]=r[o],t[o+1]=r[o+1],t[o+2]=r[o+2])}return t}var Ul=wr.map(s=>s.id);var Hn=new Map(wr.map(s=>[s.id,s])),vt=Hn.get("fox"),js=s=>typeof s=="string"&&Hn.has(s),Bt=s=>Hn.get(s);var ki=s=>typeof s=="string"?Hn.get(s)??vt:s;function Ys(s,n,e){let t=ki(s),r=Ws(),o=zn(t,e),a=Nt(r,{x:0,y:0,w:1,h:1},{band:o}),i=Qs(Bn(t,.05)),l=-i.minY,c=Math.min(.27,.43/Math.max(l,1))*n,u=t.head==="snout-long"?(i.minX+i.maxX)/2*c:0,f=c/tt[o].head/a.U,h=.5*n+Math.min(0,(l-1.6)*.06*n),b={x:n/2-u-a.head.x*f,y:h-a.head.y*f,w:f,h:f};return ln(r,t,b,{portrait:!0,band:o})}function Ks(s,n,e=.5){if(!s||s.length!==n.length)return n.slice();let t=n.slice();for(let r=0;r+2<n.length;r+=3){let o=s[r+2],a=n[r+2],i=o>=.5,l=a>=.5;i&&a>=.3&&(t[r+2]=Math.max(a,.5));let c=Math.hypot(n[r]-s[r],n[r+1]-s[r+1]);if(i&&l&&c<.15){let u=e*Math.min(1,qs+(1-qs)*c/wi);t[r]=s[r]+(n[r]-s[r])*u,t[r+1]=s[r+1]+(n[r+1]-s[r+1])*u}else i&&!l&&t[r+2]>=.5&&(t[r]=s[r],t[r+1]=s[r+1])}return Si(s,n,t,e*vi),t}var qs=.1,wi=.03,vi=.35,Ai=11;function Si(s,n,e,t){let r=Y.leftShoulder*3,o=Y.rightShoulder*3,a=(f,h)=>f[h+2]>=.5;if(!a(s,r)||!a(s,o)||!a(n,r)||!a(n,o))return;let i=(f,h)=>(f[r+h]+f[o+h])/2,l=[i(s,0),i(s,1)],c=[i(n,0),i(n,1)],u=[i(e,0),i(e,1)];for(let f=0;f<Ai&&f*3+2<n.length;f++){let h=f*3;if(!a(s,h)||!a(n,h))continue;let b=[s[h]-l[0],s[h+1]-l[1]],y=[n[h]-c[0],n[h+1]-c[1]];Math.hypot(y[0]-b[0],y[1]-b[1])>=.15||(e[h]=u[0]+b[0]+(y[0]-b[0])*t,e[h+1]=u[1]+b[1]+(y[1]-b[1])*t)}}function Qs(s){let n={minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0},e=(t,r)=>{n.minX=Math.min(n.minX,t),n.minY=Math.min(n.minY,r),n.maxX=Math.max(n.maxX,t),n.maxY=Math.max(n.maxY,r)};for(let t of s){let r="lw"in t&&t.stroke?(t.lw??1)/2:0;switch(t.k){case"circle":e(t.x-t.r-r,t.y-t.r-r),e(t.x+t.r+r,t.y+t.r+r);break;case"ellipse":case"rect":{let o=t.k==="ellipse"?t.rx:t.w/2,a=t.k==="ellipse"?t.ry:t.h/2,i=Math.max(o,a)+r;e(t.x-i,t.y-i),e(t.x+i,t.y+i);break}case"path":{let o=vr(t.d);for(let a=0;a+1<o.length;a+=2)e(o[a]-r,o[a+1]-r),e(o[a]+r,o[a+1]+r);break}case"line":for(let o=0;o+1<t.pts.length;o+=2)e(t.pts[o]-r,t.pts[o+1]-r),e(t.pts[o]+r,t.pts[o+1]+r);break;case"group":{let o=Qs(t.items);if(!Number.isFinite(o.minX))break;let a=t.s??1,i=Math.cos(t.rot??0),l=Math.sin(t.rot??0);for(let[c,u]of[[o.minX,o.minY],[o.maxX,o.minY],[o.minX,o.maxY],[o.maxX,o.maxY]])e(t.x+(c*i-u*l)*a,t.y+(c*l+u*i)*a);break}}}return n}var nt=()=>Float64Array.of(1,0,0,1,0,0);function Te(s,n,e,t,r,o,a){let i=r?Math.cos(r):1,l=r?Math.sin(r):0,c=i*o,u=l*o,f=-l*a,h=i*a;if(!n)return s[0]=c,s[1]=u,s[2]=f,s[3]=h,s[4]=e,s[5]=t,s;let b=n[0],y=n[1],m=n[2],d=n[3];return s[0]=b*c+m*u,s[1]=y*c+d*u,s[2]=b*f+m*h,s[3]=y*f+d*h,s[4]=b*e+m*t+n[4],s[5]=y*e+d*t+n[5],s}function Js(s,n,e){let t=s[0]*s[3]-s[1]*s[2];if(Math.abs(t)<1e-12)return null;let r=n-s[4],o=e-s[5];return[(s[3]*r-s[2]*o)/t,(-s[1]*r+s[0]*o)/t]}var Zs={white:16777215,black:0,red:16711680,transparent:0},un=new Map;function me(s){if(typeof s=="number")return[s&16777215,1];let n=un.get(s);if(n)return n;let e=[16777215,1],t=s.trim().toLowerCase();if(t[0]==="#"){let r=t.slice(1),o=r.length<=4?[...r].map(i=>i+i).join(""):r,a=parseInt(o.slice(0,6),16);Number.isFinite(a)&&(e=[a,o.length===8?parseInt(o.slice(6,8),16)/255:1])}else if(t.startsWith("rgb")){let r=t.match(/-?\d*\.?\d+%?/g)?.map(c=>c.endsWith("%")?parseFloat(c)/100*255:parseFloat(c))??[],[o=255,a=255,i=255]=r,l=r[3]===void 0?1:t.match(/,\s*[\d.]+%\s*\)$/)?r[3]/255:r[3];e=[(Sr(o)<<16|Sr(a)<<8|Sr(i))>>>0,Math.min(Math.max(l,0),1)]}else if(t in Zs)e=[Zs[t],t==="transparent"?0:1];else if(typeof document<"u"){let r=document.createElement("canvas").getContext("2d");if(r){r.fillStyle="#ffffff",r.fillStyle=t;let o=r.fillStyle;if(o!==t)return un.set(s,e=me(o)),e}}return un.size>512&&un.clear(),un.set(s,e),e}var Sr=s=>Math.min(Math.max(Math.round(s),0),255);function lt(s,n,e=!1){let t=Math.min(Math.max(n,0),1),r=(s>>16&255)*t,o=(s>>8&255)*t,a=(s&255)*t,i=e?0:t*255;return(Math.round(i)<<24|Math.round(a)<<16|Math.round(o)<<8|Math.round(r))>>>0}var At=(s,n=1)=>`rgba(${s>>16&255},${s>>8&255},${s&255},${n})`;function Mr(s,n){if(s===16777215)return n;if(n===16777215)return s;let e=t=>Math.round((s>>t&255)*(n>>t&255)/255);return(e(16)<<16|e(8)<<8|e(0))>>>0}var ct={linear:s=>s,quadIn:s=>s*s,quadOut:s=>s*(2-s),quadInOut:s=>s<.5?2*s*s:-1+(4-2*s)*s,cubicOut:s=>1-(1-s)**3,sineInOut:s=>-(Math.cos(Math.PI*s)-1)/2,backOut:s=>1+(1.70158+1)*(s-1)**3+1.70158*(s-1)**2,elasticOut:s=>s===0||s===1?s:2**(-10*s)*Math.sin((s*10-.75)*(2*Math.PI/3))+1,bounceOut:s=>s<1/2.75?7.5625*s*s:s<2/2.75?7.5625*(s-=1.5/2.75)*s+.75:s<2.5/2.75?7.5625*(s-=2.25/2.75)*s+.9375:7.5625*(s-=2.625/2.75)*s+.984375};function eo(s){let n=s>>>0;return()=>{n=n+1831565813>>>0;let e=n;return e=Math.imul(e^e>>>15,e|1),e^=e+Math.imul(e^e>>>7,e|61),((e^e>>>14)>>>0)/4294967296}}var T={cap:0,epoch:0,x:new Float64Array(0),y:new Float64Array(0),rot:new Float64Array(0),sx:new Float64Array(0),sy:new Float64Array(0),alpha:new Float64Array(0),la:new Float64Array(0),lb:new Float64Array(0),lc:new Float64Array(0),ld:new Float64Array(0),world:new Float64Array(0),tint:new Uint32Array(0),flags:new Uint8Array(0),moved:new Uint8Array(0),dirty:new Uint8Array(0),gen:new Uint32Array(0),parent:new Int32Array(0),first:new Int32Array(0),next:new Int32Array(0),prev:new Int32Array(0),stamp:new Uint32Array(0),pass:0,free:new Int32Array(0),freeHead:0,freeCount:0,top:2},ut=[],Mi="x y rot sx sy alpha la lb lc ld world tint flags moved dirty gen parent first next prev stamp".split(" ");function to(s){let n=T;for(let t of Mi){let r=n[t],o=new r.constructor(t==="world"?s*6:s);o.set(r),n[t]=o}let e=new Int32Array(s);for(let t=0;t<T.freeCount;t++)e[t]=T.free[(T.freeHead+t)%T.cap];for(T.free=e,T.freeHead=0,T.cap=s,T.epoch++;ut.length<s;)ut.push(null)}function Er(s){T.x[s]=T.y[s]=T.rot[s]=0,T.sx[s]=T.sy[s]=T.alpha[s]=1,T.la[s]=T.ld[s]=1,T.lb[s]=T.lc[s]=0;let n=s*6,e=T.world;e[n]=e[n+3]=1,e[n+1]=e[n+2]=e[n+4]=e[n+5]=0,T.tint[s]=16777215,T.flags[s]=3,T.moved[s]=1,T.dirty[s]=0,T.parent[s]=T.first[s]=T.next[s]=T.prev[s]=-1}to(256);Er(0);T.flags[0]=0;Er(1);T.flags[1]=0;function no(){let s;if(T.freeCount){s=T.free[T.freeHead],T.freeHead=(T.freeHead+1)%T.cap,T.freeCount--;let n=ut[s];n&&(n._i=0,n._g=-1,ut[s]=null)}else T.top===T.cap&&to(T.cap*2),s=T.top++;return Er(s),s}function Rr(s,n){$n(s);for(let t=T.first[s];t>=0;){let r=T.next[t];T.parent[t]=T.next[t]=T.prev[t]=-1,t=r}T.first[s]=-1,T.flags[s]=T.flags[s]&-3,T.moved[s]=0;let e=T.gen[s]+1;T.gen[s]=e,e!==4294967295&&(n&&(ut[s]=n),T.free[(T.freeHead+T.freeCount)%T.cap]=s,T.freeCount++)}function ro(s){for(let n=0;n<ut.length;n++){let e=ut[n];e&&s(e)&&(e._i=0,e._g=-1,ut[n]=null)}}function so(s,n){$n(s);let e=T.first[n];T.parent[s]=n,T.next[s]=e,T.prev[s]=-1,e>=0&&(T.prev[e]=s),T.first[n]=s,T.moved[s]=1}function $n(s){let n=T.parent[s];if(n<0)return;let e=T.next[s],t=T.prev[s];t>=0?T.next[t]=e:T.first[n]=e,e>=0&&(T.prev[e]=t),T.parent[s]=T.next[s]=T.prev[s]=-1}var hn={root:-1,gen:-1,world:new Float64Array(6)};function oo(s){let n=++T.pass,e=T.world,t=s*6,r=hn.world,o=hn.root!==s||hn.gen!==T.gen[s];for(let a=0;a<6;a++)r[a]!==e[t+a]&&(o=!0),r[a]=e[t+a];hn.root=s,hn.gen=T.gen[s],T.stamp[s]=o?n:n-1}function ao(s){T.stamp[s]=T.pass}function io(s){for(let n=T.first[s];n>=0;){let e=T.next[n];io(n),n=e}Rr(s)}var Tr=typeof FinalizationRegistry=="function"?new FinalizationRegistry(s=>T.gen[s.i]===s.g&&io(s.i)):null;function Cr(s){s._reg||!Tr||(s._reg=!0,Tr.register(s,{i:s._i,g:s._g},s))}function lo(s){s._reg&&Tr.unregister(s)}function fn(s){if(s){for(let n=0;n<s.length;n++)if(s[n].enabled)return!0}return!1}function co(s,n){let e=0;for(let t=0;t<s.length;t++){let r=s[t];r.enabled&&r.pad&&(e+=r.pad(n))}return e}var Ee={gl:null,c2d:null,live:null};var j=new Float64Array(3),pn=4,Ti=1,dn=()=>Ti++;var ie=nt(),P=T,Ie=class{constructor(n){p(this,"kernel",n);p(this,"_i",no());p(this,"_g",P.gen[this._i]);p(this,"_wv",null);p(this,"_wi",-1);p(this,"_we",-1);p(this,"blend","normal");p(this,"_data",null);p(this,"parent",null);p(this,"hitRadius",null);p(this,"clip",null);p(this,"mask",null);p(this,"filters",null);p(this,"_z",0);p(this,"anchorX",0);p(this,"anchorY",0);p(this,"_pool",null);p(this,"_free",!1);p(this,"_reg",!1)}get x(){return P.x[this._i]}set x(n){let e=this._i||1;P.x[e]=n,P.moved[e]=1}get y(){return P.y[this._i]}set y(n){let e=this._i||1;P.y[e]=n,P.moved[e]=1}get rotation(){return P.rot[this._i]}set rotation(n){let e=this._i||1;P.rot[e]=n,P.dirty[e]=P.moved[e]=1}get scaleX(){return P.sx[this._i]}set scaleX(n){let e=this._i||1;P.sx[e]=n,P.dirty[e]=P.moved[e]=1}get scaleY(){return P.sy[this._i]}set scaleY(n){let e=this._i||1;P.sy[e]=n,P.dirty[e]=P.moved[e]=1}get alpha(){return P.alpha[this._i]}set alpha(n){let e=this._i||1;P.alpha[e]=n,P.moved[e]=1}get visible(){return(P.flags[this._i]&1)!==0}set visible(n){let e=this._i||1;n?P.flags[e]=P.flags[e]|1:P.flags[e]=P.flags[e]&-2,P.moved[e]=1}get destroyed(){return P.gen[this._i]!==this._g}get world(){let n=this._i||1;return(this._wi!==n||this._we!==P.epoch)&&(this._wv=P.world.subarray(n*6,n*6+6),this._wi=n,this._we=P.epoch),this._wv}get data(){return this._data??(this._data={})}set data(n){this._data=n}get scale(){return this.scaleX}set scale(n){this.scaleX=this.scaleY=n}get z(){return this._z}set z(n){n!==this._z&&(this._z=n,this.parent&&(this.parent.sortDirty=!0))}get tint(){return P.tint[this._i]}set tint(n){P.tint[this._i||1]=typeof n=="number"?n&16777215:me(n)[0]}set anchor(n){typeof n=="number"?this.anchorX=this.anchorY=n:(this.anchorX=n.x,this.anchorY=n.y)}get width(){return 0}set width(n){}get height(){return 0}set height(n){}set(n){for(let e in n){let t=n[e];t!==void 0&&(this[e]=t)}return this}destroy(){this.destroyed||(this.visible=!1,this.parent&&(this.parent.dead=!0,this.parent=null),Rr(this._i,this),lo(this),this.kernel.tweens.stopAll(this),this._pool?.forget(this))}updateWorld(){let n=this.parent?this.parent.updateWorld():null;return Te(this.world,n,this.x,this.y,this.rotation,this.scaleX,this.scaleY)}draw(n,e,t){}};function po(s){ro(n=>n.kernel===s)}var Fr=!1,uo=Object.freeze([]),Tt=class s extends Ie{constructor(e){super(e);p(this,"children",uo);p(this,"sortDirty",!1);p(this,"dead",!1);Cr(this)}add(e,...t){this.adopt(e);for(let r=0;r<t.length;r++)this.adopt(t[r]);return e}adopt(e){e.parent&&e.parent.detach(e),e.parent=this,!e.destroyed&&!this.destroyed&&so(e._i,this._i),this.children===uo&&(this.children=[]),this.children.push(e),(e.z!==0||this.sortDirty)&&(this.sortDirty=!0)}remove(e){this.detach(e),e._pool||Cr(e)}detach(e){let t=this.children,r=t.indexOf(e);if(r>=0){for(let o=r+1;o<t.length;o++)t[o-1]=t[o];t.pop()}e.parent===this&&(e.parent=null,e.destroyed||$n(e._i))}clear(){for(let e of this.children)e.destroy()}destroy(){for(let e of this.children)e.destroy();super.destroy()}sweep(){if(this.dead){this.dead=!1;let e=0;for(let t of this.children)t.destroyed?t.parent===this&&(t.parent=null):this.children[e++]=t;this.children.length=e}for(let e of this.children)e instanceof s&&e.sweep()}draw(e,t,r){if(Fr)return P.parent[this._i]<0&&!this.destroyed&&ao(this._i),this.drawChildren(e,t,r);Fr=!0;try{this.destroyed||oo(this._i),this.drawChildren(e,t,r)}finally{Fr=!1}}drawChildren(e,t,r){if(this.sortDirty){let l=new Map(this.children.map((c,u)=>[c,u]));this.children.sort((c,u)=>c.z-u.z||l.get(c)-l.get(u)),this.sortDirty=!1}let o=this.children,a=this._i,i=P.stamp[a]===P.pass;for(let l=0;l<o.length;l++){let c=o[l],u=c._i,f=P.alpha[u];if(P.gen[u]!==c._g||!(P.flags[u]&1)||f<=0)continue;if(i||P.moved[u]){P.moved[u]=0,P.stamp[u]=P.pass;let y,m,d,x;if(P.dirty[u]){P.dirty[u]=0;let H=P.rot[u],V=H?Math.cos(H):1,G=H?Math.sin(H):0,be=P.sx[u],$=P.sy[u];P.la[u]=y=V*be,P.lb[u]=m=G*be,P.lc[u]=d=-G*$,P.ld[u]=x=V*$}else y=P.la[u],m=P.lb[u],d=P.lc[u],x=P.ld[u];let g=P.world,A=P.x[u],w=P.y[u],v=u*6,E=a*6,F=g[E],L=g[E+1],_=g[E+2],O=g[E+3];g[v]=F*y+_*m,g[v+1]=L*y+O*m,g[v+2]=F*d+_*x,g[v+3]=L*d+O*x,g[v+4]=F*A+_*w+g[E+4],g[v+5]=L*A+O*w+g[E+5]}let h=t*f,b=Mr(r,P.tint[u]);c.clip||c.mask||c.filters?mo(e,c,h,b):c.draw(e,h,b)}}},ge=new Float64Array(128),St=0,Pr=new Float64Array(8);function _r(s,n,e,t){n.clip||n.mask||n.filters?mo(s,n,e,t):n.draw(s,e,t)}function mo(s,n,e,t){let r=s.r,o=n.world,a=n.clip,i=!1,l=!1;if(a)if(Math.abs(o[1])<1e-9&&Math.abs(o[2])<1e-9&&St<32){let f=o[0]*a.x+o[4],h=o[0]*(a.x+a.width)+o[4],b=o[3]*a.y+o[5],y=o[3]*(a.y+a.height)+o[5],m=Math.min(f,h),d=Math.max(f,h),x=Math.min(b,y),g=Math.max(b,y);if(St){let w=(St-1)*4;m=Math.max(m,ge[w]),x=Math.max(x,ge[w+1]),d=Math.min(d,ge[w+2]),g=Math.min(g,ge[w+3])}let A=St++*4;ge[A]=m,ge[A+1]=x,ge[A+2]=d,ge[A+3]=g,r.clip(m,x,Math.max(d-m,0),Math.max(g-x,0)),l=!0}else i=!0;let c=n.mask&&n.mask.visible?n.mask:null,u=fn(n.filters)?n.filters:null;try{if(i&&r.beginLayer(),c&&r.beginLayer(),u?(n.draw(s,r.beginLayer()?1:e,t),r.endLayer(e,u)):n.draw(s,e,t),c&&(r.beginMask(),Te(c.world,o,c.x,c.y,c.rotation,c.scaleX,c.scaleY),_r(s,c,c.alpha,16777215),r.endLayer(1)),i&&a){r.beginMask();for(let f=0;f<4;f++){let h=f===1||f===2?a.x+a.width:a.x,b=f>1?a.y+a.height:a.y;Pr[f*2]=o[0]*h+o[2]*b+o[4],Pr[f*2+1]=o[1]*h+o[3]*b+o[5]}r.polygon(Pr,4,16777215,1),r.endLayer(1)}}finally{if(l)if(St--,St){let f=(St-1)*4;r.clip(ge[f],ge[f+1],ge[f+2]-ge[f],ge[f+3]-ge[f+1])}else r.unclip()}}var Re=class extends Ie{constructor(e,t,r){super(e);p(this,"_frame",null);p(this,"_w",null);p(this,"_h",null);p(this,"slice",0);p(this,"autoAnchor",!0);p(this,"frameName",null);t&&(this.frame=t),r?.anchor===void 0&&this.useFrameAnchor(),r&&this.set(r)}get frame(){return this._frame}set frame(e){this.frameName=typeof e=="string"?e:null,this._frame=typeof e=="string"?this.kernel.frame(e):e,this.autoAnchor&&this.useFrameAnchor()}set anchor(e){this.autoAnchor=!1,super.anchor=e}get naturalWidth(){let e=this.frameNow();return e?(e.sw??e.w)/e.scale-e.margin*2:0}get naturalHeight(){let e=this.frameNow();return e?(e.sh??e.h)/e.scale-e.margin*2:0}get width(){return this._w??this.naturalWidth}set width(e){this._w=e}get height(){return this._h??this.naturalHeight}set height(e){this._h=e}sizeQ(e){zt[0]=this._w??(e.sw??e.w)/e.scale-e.margin*2,zt[1]=this._h??(e.sh??e.h)/e.scale-e.margin*2}frameNow(){return this.frameName&&!this.kernel.atlas.valid(this._frame)&&(this._frame=this.kernel.frame(this.frameName)),this._frame}useFrameAnchor(){let e=this._frame;if(!e)return;let t=(e.sw??e.w)/e.scale-e.margin*2,r=(e.sh??e.h)/e.scale-e.margin*2;this.anchorX=t>0?(e.ox-e.margin)/t:0,this.anchorY=r>0?(e.oy-e.margin)/r:0}draw(e,t,r){let o=this.frameNow();if(!o)return;let a=zt;this.sizeQ(o),a[2]=this.anchorX,a[3]=this.anchorY,a[4]=t,Ei(e,o,this.world,this.slice,r,this.blend)}},Dt=new Float64Array(12),Ot=new Float64Array(12),mn={x:0,y:0,w:0,h:0};function ho(s,n,e,t,r,o){n=Math.max(n,0),e=Math.max(e,0),t=Math.max(t,0);let a=e+t>r?e*r/(e+t):e,i=e+t>r?t*r/(e+t):t,l=a/o,c=i/o;if(l+c>n){let u=n/(l+c);l*=u,c*=u}s[0]=0,s[1]=l,s[2]=0,s[3]=a,s[4]=l,s[5]=n-l-c,s[6]=a,s[7]=r-a-i,s[8]=n-c,s[9]=c,s[10]=r-i,s[11]=i}var zt=new Float64Array(5);function Ei(s,n,e,t,r,o){let a=zt,i=a[0],l=a[1],c=a[2],u=a[3],f=a[4],h=s.tex(n.surface),b=t===0?n.slice??0:t;if(b===0){let w=(n.sw??n.w)/n.scale-n.margin*2,v=(n.sh??n.h)/n.scale-n.margin*2,E=w>0?i/w:1,F=v>0?l/v:1,L=-c*i+((n.tx??0)/n.scale-n.margin)*E,_=-u*l+((n.ty??0)/n.scale-n.margin)*F;bn(e,L,_),j[0]=n.w/n.scale*E,j[1]=n.h/n.scale*F,j[2]=f,s.r.quadQ(h,n,ie,r,o);return}let y=n.tx??0,m=n.ty??0,d=(n.sw??n.w)-n.w-y,x=(n.sh??n.h)-n.h-m,g=-c*i-n.margin+y/n.scale,A=-u*l-n.margin+m/n.scale;if(ho(Dt,i+n.margin*2-(y+d)/n.scale,(typeof b=="number"?b:b[3])-y,(typeof b=="number"?b:b[1])-d,n.w,n.scale),ho(Ot,l+n.margin*2-(m+x)/n.scale,(typeof b=="number"?b:b[0])-m,(typeof b=="number"?b:b[2])-x,n.h,n.scale),bn(e,g,A),j[2]=f,!s.r.nineQ?.(h,n,Dt,Ot,ie,r,o))for(let w=0;w<12;w+=4){let v=Ot[w+1],E=Ot[w+3];if(!(v<=0||E<=0))for(let F=0;F<12;F+=4){let L=Dt[F+1],_=Dt[F+3];L<=0||_<=0||(mn.x=n.x+Dt[F+2],mn.y=n.y+Ot[w+2],mn.w=_,mn.h=E,bn(e,g+Dt[F],A+Ot[w]),j[0]=L,j[1]=v,j[2]=f,s.r.quadQ(h,mn,ie,r,o))}}}function bn(s,n,e){ie[0]=s[0],ie[1]=s[1],ie[2]=s[2],ie[3]=s[3],ie[4]=s[0]*n+s[2]*e+s[4],ie[5]=s[1]*n+s[3]*e+s[5]}var Xe=class extends Re{constructor(e,t,r={}){super(e,null);p(this,"_spec");p(this,"baked",null);p(this,"bakedEffects",!0);this._spec=t,this.bake(),r.anchor===void 0&&this.useFrameAnchor(),this.set(r)}get spec(){return this._spec}set spec(e){this._spec=e,this.baked=null,this._w=this._h=null,this.bake()}bake(){let e=this.kernel;return this.baked&&e.atlas.valid(this.baked.frame)&&this.baked.frame.scale===e.pixelScale&&this.bakedEffects===e.effects?this.baked:(this.bakedEffects=e.effects,this.baked=e.shape(this._spec),this._frame=this.baked.frame,this.slice=this.baked.slice,this.baked)}frameNow(){return this.bake().frame}sizeQ(){let e=this.bake();zt[0]=this._w??e.w,zt[1]=this._h??e.h}get width(){return this._w??this.bake().w}set width(e){this._w=e}get height(){return this._h??this.bake().h}set height(e){this._h=e}},fo=(s,n,e)=>s===void 0?n:typeof s=="number"?s:s[0]+(s[1]-s[0])*e(),Mt=class Mt extends Ie{constructor(e,t,r={}){super(e);p(this,"max");p(this,"f");p(this,"tints");p(this,"count",0);p(this,"gravity");p(this,"drag");p(this,"frameRef");p(this,"random",Math.random);this.frameRef=t,this.max=Math.max(1,Math.floor(r.max??200)),this.f=new Float32Array(this.max*Mt.W),this.tints=new Uint32Array(this.max),this.blend=r.blend??"normal",this.gravity=r.gravity??0,this.drag=r.drag??1}get alive(){return this.count}burst(e,t,r,o={}){let a=Mt.W,i=this.random,l=o.tint===void 0?16777215:me(o.tint)[0];for(let c=0;c<r;c++){let u=this.count;if(u>=this.max){let d=0,x=1/0;for(let g=0;g<this.max;g++){let A=this.f[g*a+5]-this.f[g*a+4];A<x&&(x=A,d=g)}u=d}else this.count++;let f=(o.angle??0)+(o.spread===void 0?i()*Math.PI*2:(i()-.5)*o.spread),h=fo(o.speed,200,i),b=Array.isArray(o.scale)?o.scale[0]:o.scale??1,y=Array.isArray(o.scale)?o.scale[1]:o.scale??1,m=u*a;this.f[m]=e,this.f[m+1]=t,this.f[m+2]=Math.cos(f)*h,this.f[m+3]=Math.sin(f)*h,this.f[m+4]=0,this.f[m+5]=Math.max(fo(o.life,.8,i),.01),this.f[m+6]=i()*Math.PI*2,this.f[m+7]=(i()-.5)*2*(o.spin??0),this.f[m+8]=b,this.f[m+9]=y,this.f[m+10]=o.alpha??1,this.tints[u]=l}}update(e){let t=Mt.W,r=this.f,o=this.drag>=1?1:Math.pow(Math.max(this.drag,0),e);for(let a=0;a<this.count;){let i=a*t;if(r[i+4]=r[i+4]+e,r[i+4]>=r[i+5]){let l=--this.count;a!==l&&(r.copyWithin(i,l*t,l*t+t),this.tints[a]=this.tints[l]);continue}r[i+3]=(r[i+3]+this.gravity*e)*o,r[i+2]=r[i+2]*o,r[i]=r[i]+r[i+2]*e,r[i+1]=r[i+1]+r[i+3]*e,r[i+6]=r[i+6]+r[i+7]*e,a++}}clear(){this.count=0}draw(e,t,r){if(!this.count)return;let o=typeof this.frameRef=="string"?this.frameRef=this.kernel.frame(this.frameRef):this.frameRef,a=Mt.W,i=this.f,l=this.world,c=o.w/o.scale,u=o.h/o.scale;for(let f=0;f<this.count;f++){let h=f*a,b=i[h+4]/i[h+5],y=i[h+8]+(i[h+9]-i[h+8])*b,m=t*i[h+10]*(1-b*b),d=i[h+6],x=Math.cos(d)*y,g=Math.sin(d)*y,A=i[h],w=i[h+1],v=l[0],E=l[1],F=l[2],L=l[3],_=v*x+F*g,O=E*x+L*g,H=F*x-v*g,V=L*x-E*g;ie[0]=_,ie[1]=O,ie[2]=H,ie[3]=V,ie[4]=v*A+F*w+l[4]-(_*c+H*u)/2,ie[5]=E*A+L*w+l[5]-(O*c+V*u)/2,j[0]=c,j[1]=u,j[2]=m,e.r.quadQ(e.tex(o.surface),o,ie,Mr(r,this.tints[f]),this.blend)}}};p(Mt,"W",11);var Ht=Mt;var Ne=class extends Re{constructor(e,t,r={}){let{fps:o,loop:a,playing:i,speed:l,onComplete:c,...u}=r;if(!t.frames.length)throw new Error("[engine] an animation needs at least one frame");super(e,t.frames[0],u);p(this,"frames");p(this,"durations");p(this,"fps");p(this,"loop");p(this,"speed");p(this,"onComplete");p(this,"_playing");p(this,"index",0);p(this,"t",0);this.frames=t.frames,this.durations=t.durations&&o===void 0?t.durations:null,this.fps=o??12,this.loop=a!==!1,this.speed=l??1,this.onComplete=c??null,this._playing=i!==!1,this.speed<0&&this.show(t.frames.length-1)}get frameIndex(){return this.index}get frameCount(){return this.frames.length}get playing(){return this._playing}play(){return!this.loop&&!this._playing&&this.index===(this.speed<0?0:this.frames.length-1)&&this.show(this.speed<0?this.frames.length-1:0),this._playing=!0,this}stop(){return this._playing=!1,this}gotoFrame(e){let t=this.frames.length;return this.show((Math.floor(e)%t+t)%t),this.t=0,this}gotoAndPlay(e){return this._playing=!0,this.gotoFrame(e)}gotoAndStop(e){return this._playing=!1,this.gotoFrame(e)}show(e){e===this.index&&this._frame||(this.index=e,this.frame=this.frames[e])}secondsOf(e){let t=this.durations?.[e];return t!==void 0&&t>0?t:1/Math.max(this.fps,.001)}update(e){if(!this._playing||this.destroyed||this.speed===0)return;let t=this.frames.length,r=this.speed<0;this.t+=e*Math.abs(this.speed);let o=this.index;for(let a=0;a<1e3;a++){let i=this.secondsOf(o);if(this.t<i)break;this.t-=i;let l=r?o-1:o+1;if(l<0||l>=t){if(!this.loop){this.t=0,this._playing=!1,this.show(o),this.onComplete?.();return}o=r?t-1:0}else o=l}this.show(o)}},bo=(s,n)=>s.localeCompare(n,void 0,{numeric:!0});var yn=class{constructor(n,e,t=2){p(this,"width",n);p(this,"height",e);p(this,"padding",t);p(this,"shelves",[]);p(this,"free",[]);p(this,"bottom",0)}alloc(n,e){let t=Math.ceil(n)+this.padding*2,r=Math.ceil(e)+this.padding*2;if(t>this.width||r>this.height)return null;for(let i=0;i<this.free.length;i++){let l=this.free[i];if(l.w>=t&&l.h>=r&&l.w*l.h<=t*r*2)return this.free.splice(i,1),this.inner(l.x,l.y,n,e)}let o=null;for(let i of this.shelves)i.h>=r&&i.h<=r*1.5+8&&this.width-i.x>=t&&(!o||i.h<o.h)&&(o=i);if(!o)if(this.bottom+r>this.height){for(let i of this.shelves)i.h>=r&&this.width-i.x>=t&&(o=i);if(!o)return null}else o={y:this.bottom,h:r,x:0},this.shelves.push(o),this.bottom+=r;let a=o.x;return o.x+=t,this.inner(a,o.y,n,e)}release(n){this.free.push({x:n.x-this.padding,y:n.y-this.padding,w:Math.ceil(n.w)+this.padding*2,h:Math.ceil(n.h)+this.padding*2})}get fill(){return this.bottom/this.height}reset(){this.shelves=[],this.free=[],this.bottom=0}inner(n,e,t,r){return{x:n+this.padding,y:e+this.padding,w:t,h:r}}},$t=s=>({source:s,texture:null,pending:[]}),ht=class{constructor(n=2048,e=4){p(this,"pageSize",n);p(this,"maxPages",e);p(this,"pages",[]);p(this,"gen",1);p(this,"onPage",()=>{});p(this,"onDrop",()=>{})}valid(n){return!!n&&(n.gen===this.gen||n.gen===0)}bake(n,e,t,r=1,o=0,a=0,i=0){let l=Math.max(1,Math.ceil(n)),c=Math.max(1,Math.ceil(e)),u=document.createElement("canvas");u.width=l,u.height=c;let f=u.getContext("2d");return t(f),this.put(u,l,c,r,o,a,i)}add(n,e=1,t=0,r=0){let o=document.createElement("canvas");return o.width=Math.max(1,n.width),o.height=Math.max(1,n.height),o.getContext("2d").drawImage(n,0,0),this.put(o,o.width,o.height,e,t,r,0)}release(n){if(n.gen!==this.gen)return;this.pages.find(t=>t.surface===n.surface)?.packer.release(n)}rebake(n,e,t,r,o=n.w,a=n.h){if(!this.valid(n)||e>o||t>a)return null;let i=Math.max(1,Math.ceil(e)),l=Math.max(1,Math.ceil(t)),c=this.pages.find(f=>f.surface===n.surface);if(!c)return null;let u=document.createElement("canvas");return u.width=Math.ceil(o),u.height=Math.ceil(a),r(u.getContext("2d")),c.ctx.clearRect(n.x,n.y,u.width,u.height),c.ctx.drawImage(u,n.x,n.y),n.surface.pending.push([u,n.x,n.y]),n.w=i,n.h=l,n}put(n,e,t,r,o,a,i){let l=null,c=this.pages.find(f=>(l=f.packer.alloc(e,t))!==null);if(c||(!(Math.max(e,t)+4>this.pageSize)&&this.pages.length>=this.maxPages&&(this.wipe(),c=this.pages[0],l=c?c.packer.alloc(e,t):null),(!c||!l)&&(c=this.newPage(Math.max(e,t)),l=c.packer.alloc(e,t))),!l)throw new Error(`[engine] ${e}\xD7${t} does not fit an atlas page`);let u=l;return c.ctx.drawImage(n,u.x,u.y),c.surface.pending.push([n,u.x,u.y]),{surface:c.surface,x:u.x,y:u.y,w:e,h:t,scale:r,gen:this.gen,ox:o,oy:a,margin:i}}newPage(n){let e=this.pageSize;for(;e<n+4;)e*=2;let t=document.createElement("canvas");t.width=t.height=e;let r=t.getContext("2d"),o=$t(t),a={surface:o,packer:new yn(e,e),ctx:r};return this.pages.push(a),this.onPage(o),a}wipe(){this.gen++;let n=0;for(let e=0;e<this.pages.length;e++){let t=this.pages[e];if(n<this.maxPages&&t.surface.source.width===this.pageSize){this.pages[n++]=t;continue}t.surface.pending=[],this.onDrop(t.surface)}this.pages.length=n;for(let e of this.pages)e.packer.reset(),e.ctx.clearRect(0,0,e.surface.source.width,e.surface.source.height),e.surface.pending=[],e.surface.pending.push([e.surface.source,0,0])}};var Ri=()=>{let s=typeof document<"u"?document.timeline?.currentTime:null;return typeof s=="number"&&Number.isFinite(s)?s:globalThis.performance?.now()??Date.now()},yo=()=>globalThis.performance?.now()??Date.now(),xn=class{constructor(n=Ri){p(this,"now",n);p(this,"known",new Map);p(this,"smoothed",new Map);p(this,"times",new WeakMap);p(this,"lerp",new cn);p(this,"drawnAt",NaN);p(this,"drawn",0);p(this,"smoothedBody",(n,e={})=>{let t=e.interpolate!==!1;if(typeof n=="number"){let r=this.smoothed.get(n);return r?t?this.lerp.at(n,this.tick())??r.body:r.body:null}return typeof n!="object"||n===null||!Array.isArray(n.body)?null:this.posed(n.id,n.body,Ci(e.smooth),t)})}note(n,e,t=yo()){for(let r of n)this.known.set(r.id,this.resolve(r.id,r.avatar)),e!==void 0&&Number.isFinite(e)&&Array.isArray(r.body)&&this.times.set(r.body,{t:e,arrival:t})}of(n){return typeof n=="object"&&n!==null?n.avatar!==void 0?this.resolve(n.id,n.avatar):this.of(n.id):this.known.get(n)??kr(n-1)}posed(n,e,t,r=!0){let o=this.smooth(n,e,t);return r?this.lerp.at(n,this.tick())??o:o}smooth(n,e,t){let r=this.smoothed.get(n);if(r&&r.raw===e&&r.amount===t)return r.body;r&&r.amount!==t&&this.lerp.forget(n);let o=t<1?Ks(r?.body,e,t):e;this.smoothed.set(n,{raw:e,body:o,amount:t});let a=this.times.get(e),i=a?.arrival??yo();return this.lerp.push(n,a?.t??i,o,i),o}takeDrawn(){let n=this.drawn;return this.drawn=0,n}tick(){let n=this.now();return n!==this.drawnAt&&(this.drawnAt=n,this.drawn++),n}resolve(n,e){return js(e)?e:kr(n-1)}};var Ci=s=>s===!1?1:typeof s=="number"?Math.min(Math.max(s,.05),1):.5;var ko=new Float64Array(1),xo=new Int32Array(ko.buffer),Gt=(s,n)=>(s=Math.imul(s^n,1540483477),s^s>>>15);function st(s,n=2538058380){return s!==s?Gt(n,2146959360):(ko[0]=s===0?0:s,Gt(Gt(n,xo[0]),xo[1]))}function go(s,n=2166136261){for(let e=0;e<s.length;e++)n=Math.imul(n^s.charCodeAt(e),16777619);return n}function Ue(s){switch(typeof s){case"number":return st(s);case"string":return go(s);case"boolean":return s?1013904242:461845907;case"object":{if(s===null)return 625341585;if(Array.isArray(s)||s instanceof Float64Array){let t=1779033703^s.length;for(let r=0;r<s.length;r++){let o=s[r];t=Gt(t,typeof o=="number"?st(o):Ue(o))}return t}let n=1359893119,e=s;for(let t in e){let r=e[t];r!==void 0&&(n=n+Gt(go(t),Ue(r))|0)}return Gt(n,2600822924)}default:return 0}}function Ut(s,n){if(s===n)return!0;if(typeof s!="object"||typeof n!="object"||s===null||n===null)return typeof s=="number"&&typeof n=="number"&&s!==s&&n!==n;let e=Array.isArray(s)||s instanceof Float64Array;if(e!==(Array.isArray(n)||n instanceof Float64Array))return!1;if(e){let o=s,a=n;if(o.length!==a.length)return!1;for(let i=0;i<o.length;i++)if(o[i]!==a[i]&&!Ut(o[i],a[i]))return!1;return!0}let t=s,r=n;for(let o in t)if(t[o]!==void 0&&!Ut(t[o],r[o]))return!1;for(let o in r)if(r[o]!==void 0&&t[o]===void 0)return!1;return!0}function gn(s){if(typeof s!="object"||s===null)return s;if(Array.isArray(s))return s.map(gn);if(s instanceof Float64Array)return s.slice();let n={};for(let e in s)s[e]!==void 0&&(n[e]=gn(s[e]));return n}var Wt=class{constructor(n=1/0){p(this,"max",n);p(this,"buckets",new Map);p(this,"n",0)}get size(){return this.n}get(n,e=Ue(n)){let t=this.buckets.get(e);if(t){for(let r=0;r<t.length;r++)if(Ut(t[r].key,n))return t[r].value}}set(n,e,t=Ue(n)){let r=this.buckets.get(t);if(r){for(let o of r)if(Ut(o.key,n)){o.value=e;return}}this.n>=this.max&&this.clear(),(!r||!this.buckets.has(t))&&this.buckets.set(t,r=[]),r.push({key:gn(n),value:e}),this.n++}clear(){this.buckets.clear(),this.n=0}};var Lr=0,wo=1,Un=2,Ir=3,Vt=class{constructor(){p(this,"scale",1);p(this,"cOn",!1);p(this,"px0",0);p(this,"py0",0);p(this,"px1",0);p(this,"py1",0);p(this,"clipVer",0);p(this,"stack",[]);p(this,"sp",0);p(this,"real",0);p(this,"mute",0);p(this,"bnd",new Float64Array(4*(pn+1)));p(this,"rx0",0);p(this,"ry0",0);p(this,"rx1",0);p(this,"ry1",0);p(this,"maxBlur",1/0);p(this,"time",0);p(this,"skipped",0);p(this,"gq",new Float64Array(4))}resetLayers(n){this.scale=n,this.sp=this.real=this.mute=0,this.skipped=0,this.cOn=!1,this.clipVer++}growQ(){let n=this.gq;this.grow(n[0],n[1],n[2],n[3])}grow(n,e,t,r){if(!this.real)return;let o=this.bnd,a=(this.real-1)*4;n<o[a]&&(o[a]=n),e<o[a+1]&&(o[a+1]=e),t>o[a+2]&&(o[a+2]=t),r>o[a+3]&&(o[a+3]=r)}area(n,e){let t=this.bnd,r=n*4,o=this.scale;return this.rx0=Math.max(Math.floor((t[r]-e)*o)-1,0),this.ry0=Math.max(Math.floor((t[r+1]-e)*o)-1,0),this.rx1=Math.min(Math.ceil((t[r+2]+e)*o)+1,this.canvas.width),this.ry1=Math.min(Math.ceil((t[r+3]+e)*o)+1,this.canvas.height),this.rx1>this.rx0&&this.ry1>this.ry0}clip(n,e,t,r){let o=this.scale,a=this.canvas.width,i=this.canvas.height,l=Math.min(Math.max(Math.round(n*o),0),a),c=Math.min(Math.max(Math.round(e*o),0),i),u=Math.min(Math.max(Math.round((n+t)*o),l),a),f=Math.min(Math.max(Math.round((e+r)*o),c),i);this.cOn&&l===this.px0&&c===this.py0&&u===this.px1&&f===this.py1||(this.cOn=!0,this.px0=l,this.py0=c,this.px1=u,this.py1=f,this.clipVer++)}unclip(){this.cOn&&(this.cOn=!1,this.clipVer++)}push(n){if(n<Un&&(this.mute||this.real>=pn||!this.pushLayer())&&(n+=2),n===Ir)this.mute++;else if(n!==Un){let e=this.real*4;this.bnd[e]=this.bnd[e+1]=1/0,this.bnd[e+2]=this.bnd[e+3]=-1/0,this.real++}return this.stack[this.sp++]=n,n<Un}beginLayer(){return this.push(Lr)}beginMask(){this.push(this.sp&&this.stack[this.sp-1]===Lr?wo:Ir)}endLayer(n,e){if(!this.sp)return;let t=this.stack[--this.sp];if(t===Ir){if(this.mute--,!this.sp)return;t=this.stack[--this.sp]}if(t===wo){let r=--this.real,o=this.popLayer();this.area(r-1,0)&&this.composite(o,!0,1,null);let a=this.bnd,i=(r-1)*4,l=r*4;a[i]=Math.max(a[i],a[l]),a[i+1]=Math.max(a[i+1],a[l+1]),a[i+2]=Math.min(a[i+2],a[l+2]),a[i+3]=Math.min(a[i+3],a[l+3]),t=this.stack[--this.sp]}if(t===Un)fn(e)&&(this.skipped+=e.length);else if(t===Lr){let r=--this.real,o=fn(e)?e:null,a=this.popLayer();if(this.area(r,o?co(o,this.maxBlur):0)){this.composite(a,!1,n,o);let i=this.scale;this.grow(this.rx0/i,this.ry0/i,this.rx1/i,this.ry1/i)}}}closeLayers(){for(;this.sp;)this.endLayer(1)}};var Fi=256,vo=8<<20,Ce=new Float64Array(32),Fe={x:0,y:0,w:0,h:0};function Pi(s){if(typeof s.filter!="string")return!1;s.filter="blur(1px)";let n=s.filter==="blur(1px)";return s.filter="none",n}function Xt(s){let n=s.getContext("2d",{alpha:!0});return n?new Nr(s,n):null}var Nr=class extends Vt{constructor(e,t){super();p(this,"canvas",e);p(this,"ctx",t);p(this,"kind","canvas2d");p(this,"maxTextureSize",4096);p(this,"features",{});p(this,"info",{renderer:"canvas2d"});p(this,"support");p(this,"lost",!1);p(this,"fxr",null);p(this,"quads",0);p(this,"stats",{drawCalls:0,quads:0,filtersSkipped:0});p(this,"tinted",new Map);p(this,"tintedN",0);p(this,"lostListeners",[]);p(this,"restoredListeners",[]);p(this,"base");p(this,"top");p(this,"layers",[]);p(this,"scratch",[]);p(this,"nines",new Map);p(this,"ninePx",0);p(this,"frame",0);p(this,"hit",!1);p(this,"missed",new Map);this.support={filters:Pi(t),shaders:!1},this.base=this.top={ctx:t,clipped:!1,ver:0},e.addEventListener("contextlost",()=>{this.lost=!0,this.lostListeners.forEach(r=>r())}),e.addEventListener("contextrestored",()=>{this.lost=!1,this.tinted.clear(),this.tintedN=0,this.dropNines(),this.restoredListeners.forEach(r=>r())})}resize(e,t){this.canvas.width!==e&&(this.canvas.width=e),this.canvas.height!==t&&(this.canvas.height=t)}createTexture(e){return{id:dn(),width:e.width,height:e.height,source:e}}updateTexture(e,t,r=0,o=0){let a=t?r+t.width:1/0,i=t?o+t.height:1/0;for(let l of this.nines.values()){let c=l.key;c[0]===e.id&&c[1]<a&&c[1]+c[3]>r&&c[2]<i&&c[2]+c[4]>o&&this.dropNine(l)}for(let[l,c]of this.tinted){let u=c.filter(f=>f.id!==e.id);this.tintedN-=c.length-u.length,u.length?this.tinted.set(l,u):this.tinted.delete(l)}}destroyTexture(e){this.updateTexture(e)}begin(e,t,r){this.resetLayers(r),this.fxr?.tick(),this.frame++,this.quads=0,this.top=this.base,this.ctx=this.base.ctx;let o=this.ctx;this.base.clipped&&o.restore(),this.base.clipped=!1,this.base.ver=this.clipVer,o.setTransform(1,0,0,1,0,0),o.globalAlpha=1,o.globalCompositeOperation="source-over",o.clearRect(0,0,this.canvas.width,this.canvas.height),t>0&&(o.fillStyle=At(e,t),o.fillRect(0,0,this.canvas.width,this.canvas.height))}quad(e,t,r,o,a,i,l,c){j[0]=o,j[1]=a,j[2]=l,this.quadQ(e,t,r,i,c)}quadQ(e,t,r,o,a){t.w<=0||t.h<=0||(o===16777215?this.blit(e.source,t.x,t.y,t.w,t.h,r,a):this.blit(this.tint(e,t,o),0,0,t.w,t.h,r,a))}blit(e,t,r,o,a,i,l){let c=j[0],u=j[1],f=j[2];if(f<=0||this.mute)return;this.sync();let h=this.ctx,b=this.scale;if(this.real){let y=i[0]*c,m=i[1]*c,d=i[2]*u,x=i[3]*u;this.grow(i[4]+Math.min(0,y,d,y+d),i[5]+Math.min(0,m,x,m+x),i[4]+Math.max(0,y,d,y+d),i[5]+Math.max(0,m,x,m+x))}h.setTransform(i[0]*b,i[1]*b,i[2]*b,i[3]*b,i[4]*b,i[5]*b),h.globalAlpha=Math.min(f,1),l==="add"&&(h.globalCompositeOperation="lighter"),h.drawImage(e,t,r,o,a,0,0,c,u),l==="add"&&(h.globalCompositeOperation="source-over"),this.quads++}nineQ(e,t,r,o,a,i,l){var m,d;let c=r[8]+r[9],u=o[8]+o[9],f=Math.ceil(c*Math.hypot(a[0],a[1])*this.scale-1e-6),h=Math.ceil(u*Math.hypot(a[2],a[3])*this.scale-1e-6);if(a[1]===0&&a[2]===0||f>4096||h>4096)return!1;if(!(f>0&&h>0&&j[2]>0)||this.mute)return!0;let b=this.kept(e,t,r,o,f,h,i),y=(b??(b=(m=this.scratch)[d=13*Math.ceil(Math.log2(f))+Math.ceil(Math.log2(h))]??(m[d]=document.createElement("canvas").getContext("2d")))).canvas;if(y.width<f&&(y.width=f),y.height<h&&(y.height=h),!this.hit){b.clearRect(0,0,f+2,h+2);for(let x=0;x<12;x+=4){let g=Math.round(o[x]*h/u),A=Math.round((o[x]+o[x+1])*h/u);for(let w=0;w<12;w+=4){let v=Math.round(r[w]*f/c),E=Math.round((r[w]+r[w+1])*f/c);Fe.x=t.x+r[w+2],Fe.y=t.y+o[x+2],Fe.w=r[w+3],Fe.h=o[x+3],!(E<=v||A<=g||Fe.w<=0||Fe.h<=0)&&(i===16777215?b.drawImage(e.source,Fe.x,Fe.y,Fe.w,Fe.h,v,g,E-v,A-g):b.drawImage(this.tint(e,Fe,i),0,0,Fe.w,Fe.h,v,g,E-v,A-g))}}}return j[0]=c,j[1]=u,this.blit(y,0,0,f,h,a,l),!0}kept(e,t,r,o,a,i,l){Ce[0]=e.id,Ce[1]=t.x,Ce[2]=t.y,Ce[3]=t.w,Ce[4]=t.h,Ce[5]=a,Ce[6]=i,Ce[7]=l,Ce.set(r,8),Ce.set(o,20);let c=Ue(Ce),u=this.nines.get(c);if(this.hit=!1,u)return Ut(u.key,Ce)?(u.used=this.frame,this.hit=!0,u.ctx):null;let f=this.missed,h=f.get(c);f.size>4096&&f.clear(),f.set(c,this.frame);let b=a*i;if(h!==this.frame-1||b>vo)return null;let y;for(;this.ninePx+b>vo;){let x;for(let w of this.nines.values())w.used<this.frame-1&&!(x&&x.used<=w.used)&&(x=w);if(!x)return null;let g=x.ctx.canvas,A=!y&&g.width>=a&&g.height>=i&&g.width*g.height<=2*b;this.dropNine(x,A),A&&(y=x.ctx)}let m=y??document.createElement("canvas").getContext("2d"),d=m.canvas;return y||(d.width=a,d.height=i),this.ninePx+=d.width*d.height,this.nines.set(c,{key:gn(Ce),ctx:m,used:this.frame}),m}dropNine(e,t=!1){this.nines.delete(Ue(e.key));let r=e.ctx.canvas;this.ninePx-=r.width*r.height,t||(r.width=0)}dropNines(){for(let e of this.nines.values())this.dropNine(e)}tint(e,t,r){let o=st(r,st(t.h,st(t.w,st(t.y,st(t.x,st(e.id)))))),a=this.tinted.get(o);if(a)for(let c=0;c<a.length;c++){let u=a[c];if(u.id===e.id&&u.x===t.x&&u.y===t.y&&u.w===t.w&&u.h===t.h&&u.color===r)return u.canvas}this.tintedN>=Fi&&(this.tinted.clear(),this.tintedN=0,a=void 0);let i=document.createElement("canvas");i.width=Math.ceil(t.w),i.height=Math.ceil(t.h);let l=i.getContext("2d");return l.drawImage(e.source,t.x,t.y,t.w,t.h,0,0,t.w,t.h),l.globalCompositeOperation="multiply",l.fillStyle=At(r),l.fillRect(0,0,t.w,t.h),l.globalCompositeOperation="destination-in",l.drawImage(e.source,t.x,t.y,t.w,t.h,0,0,t.w,t.h),a||this.tinted.set(o,a=[]),a.push({id:e.id,x:t.x,y:t.y,w:t.w,h:t.h,color:r,canvas:i}),this.tintedN++,i}paint(e,t){this.sync();let r=this.ctx,o=this.scale;return r.setTransform(o,0,0,o,0,0),r.globalAlpha=Math.min(t,1),At(e)}ellipse(e,t,r,o,a,i,l){if(l<=0||r<=0||o<=0||this.mute)return;let c=Math.max(r,o);this.grow(e-c,t-c,e+c,t+c);let u=this.ctx;u.fillStyle=this.paint(i,l),u.beginPath(),u.ellipse(e,t,r,o,a,0,Math.PI*2),u.fill(),this.quads++}trace(e,t,r=0){if(this.real)for(let a=0;a<t;a++)this.grow(e[a*2]-r,e[a*2+1]-r,e[a*2]+r,e[a*2+1]+r);let o=this.ctx;o.beginPath(),o.moveTo(e[0],e[1]);for(let a=1;a<t;a++)o.lineTo(e[a*2],e[a*2+1])}polygon(e,t,r,o){if(o<=0||t<3||this.mute)return;let a=this.ctx;a.fillStyle=this.paint(r,o),this.trace(e,t),a.closePath(),a.fill(),this.quads++}stroke(e,t,r,o,a,i){if(a<=0||r<=0||t<1||this.mute)return;let l=this.ctx;l.strokeStyle=this.paint(o,a),l.lineWidth=r,l.lineCap="round",l.lineJoin="round",this.trace(e,t,r/2),t===1&&l.lineTo(e[0],e[1]),i&&l.closePath(),l.stroke(),this.quads++}sync(){let e=this.top;if(e.ver===this.clipVer)return;let t=e.ctx;e.clipped&&t.restore(),e.clipped=this.cOn,e.ver=this.clipVer,this.cOn&&(t.save(),t.setTransform(1,0,0,1,0,0),t.beginPath(),t.rect(this.px0,this.py0,this.px1-this.px0,this.py1-this.py0),t.clip())}pushLayer(){let e=this.canvas.width,t=this.canvas.height,r=this.layers[this.real];if(!r||r.ctx.canvas.width!==e||r.ctx.canvas.height!==t){let a=document.createElement("canvas");a.width=e,a.height=t;let i=a.getContext("2d");if(!i)return!1;r=this.layers[this.real]={ctx:i,clipped:!1,ver:-1}}let o=r.ctx;return r.clipped&&o.restore(),r.clipped=!1,r.ver=-1,o.setTransform(1,0,0,1,0,0),o.globalAlpha=1,o.globalCompositeOperation="source-over",o.clearRect(0,0,e,t),this.top=r,this.ctx=o,!0}popLayer(){return this.top=this.real>0?this.layers[this.real-1]:this.base,this.ctx=this.top.ctx,this.layers[this.real].ctx.canvas}composite(e,t,r,o){let a=e,i="none",l=o&&Ee.c2d?this.fxr??(this.fxr=Ee.c2d(this)):null;l&&(a=l.chain(e,o),i=l.css),this.sync();let c=this.ctx,u=this.rx0,f=this.ry0,h=this.rx1-u,b=this.ry1-f;c.setTransform(1,0,0,1,0,0),c.globalAlpha=Math.min(r,1),c.globalCompositeOperation=t?"destination-in":"source-over",i!=="none"&&(c.filter=i),c.drawImage(a,u,f,h,b,u,f,h,b),i!=="none"&&(c.filter="none"),c.globalCompositeOperation="source-over",this.quads++}end(){this.closeLayers();let e=this.stats;return e.drawCalls=e.quads=this.quads,e.filtersSkipped=this.skipped,e}onLost(e){this.lostListeners.push(e)}onRestored(e){this.restoredListeners.push(e)}destroy(){this.tinted.clear(),this.dropNines(),this.layers=[],this.scratch=[],this.fxr?.destroy(),this.fxr=null}};var Wn=class{constructor(n,e,t=8192){p(this,"instanced",n);p(this,"slots",e);p(this,"capacity",t);p(this,"f32");p(this,"u32");p(this,"quads",0);p(this,"textures");p(this,"bound",0);this.textures=new Array(e).fill(null);let r=t*(n?14:24),o=new ArrayBuffer(r*4);this.f32=new Float32Array(o),this.u32=new Uint32Array(o)}slot(n){let e=this.textures;for(let t=0;t<this.bound;t++)if(e[t]===n)return t;return this.bound>=this.slots?-1:(e[this.bound]=n,this.bound++)}has(n){for(let e=0;e<this.bound;e++)if(this.textures[e]===n)return!0;return!1}get full(){return this.quads>=this.capacity}get words(){return this.quads*(this.instanced?14:24)}reset(){this.quads=0;for(let n=0;n<this.bound;n++)this.textures[n]=null;this.bound=0}push(n,e,t,r,o,a,i,l,c,u,f,h,b,y){let m=this.f32;if(this.instanced){let d=this.quads*14;m[d++]=n,m[d++]=e,m[d++]=t,m[d++]=r,m[d++]=o,m[d++]=a,m[d++]=i,m[d++]=l,m[d++]=c,m[d++]=u,m[d++]=f,m[d++]=h,this.u32[d++]=b,m[d]=y}else{let d=this.quads*6*4;this.vertex(d,n,e,c,u,b,y),this.vertex(d+6,t,r,f,u,b,y),this.vertex(d+12,o,a,f,h,b,y),this.vertex(d+18,i,l,c,h,b,y)}this.quads++}pushQ(n,e){let t=this.f32;if(this.instanced){let r=this.quads*14;for(let o=0;o<12;o++)t[r+o]=n[o];this.u32[r+12]=n[12],t[r+13]=e}else{let r=this.quads*6*4,o=n[12];for(let a=0;a<4;a++,r+=6)t[r]=n[a*2],t[r+1]=n[a*2+1],t[r+2]=a===1||a===2?n[10]:n[8],t[r+3]=a>=2?n[11]:n[9],this.u32[r+4]=o,t[r+5]=e}this.quads++}vertex(n,e,t,r,o,a,i){let l=this.f32;l[n]=e,l[n+1]=t,l[n+2]=r,l[n+3]=o,this.u32[n+4]=a,l[n+5]=i}};function Ao(s){let n=new Uint16Array(s*6);for(let e=0,t=0,r=0;e<s;e++,t+=6,r+=4)n[t]=r,n[t+1]=r+1,n[t+2]=r+2,n[t+3]=r,n[t+4]=r+2,n[t+5]=r+3;return n}var ke={M:0,L:1,Q:2,C:3,Z:4},Po=[2,2,4,6,0],_i={M:0,L:1,Q:2,C:3,Z:4};function Kn(s,n){if(s.length>=n)return s;let e=new Float64Array(Math.max(n,s.length*2,16));return e.set(s),e}var Vn=new Map;function Li(s){if(typeof s!="string")return s;let n=Vn.get(s);if(n)return n;n=[];let e=s.match(/[MLQCZ]|-?\d*\.?\d+(?:e-?\d+)?/gi)??[],t=-1;for(let r=0;r<e.length;){let o=e[r],a=_i[o.toUpperCase()];if(a!==void 0){t=a,r++,a===ke.Z&&n.push(ke.Z);continue}if(t<0||t===ke.Z){r++;continue}let i=Po[t];n.push(t);for(let l=0;l<i;l++)n.push(Number(e[r+l]??0));r+=i,t===ke.M&&(t=ke.L)}return Vn.size>256&&Vn.clear(),Vn.set(s,n),n}var pt={subs:[],count:0},Br=null,ft=null;function Xn(s,n){let e=ft;e||(e=pt.subs[pt.count]??null,e||pt.subs.push(e={pts:new Float64Array(64),n:0,closed:!1}),e.n=0,e.closed=!1,pt.count++,ft=e);let t=e.n*2;t+2>e.pts.length&&(e.pts=Kn(e.pts,t+2));let r=Br;r?(e.pts[t]=r[0]*s+r[2]*n+r[4],e.pts[t+1]=r[1]*s+r[3]*n+r[5]):(e.pts[t]=s,e.pts[t+1]=n),e.n++}function Qn(s,n=null,e=1,t=6){let r=Li(s);pt.count=0,ft=null,Br=n;let o=0,a=0,i=0,l=0,c=e/t;for(let u=0;u<r.length;){let f=r[u++],h=r;if(f===ke.M)ft=null,o=i=h[u],a=l=h[u+1],Xn(o,a);else if(f===ke.L)o=h[u],a=h[u+1],Xn(o,a);else if(f===ke.Q){let b=h[u],y=h[u+1],m=h[u+2],d=h[u+3],x=So((qe(b-o,y-a)+qe(m-b,d-y))*c);for(let g=1;g<=x;g++){let A=g/x,w=1-A;Xn(w*w*o+2*w*A*b+A*A*m,w*w*a+2*w*A*y+A*A*d)}o=m,a=d}else if(f===ke.C){let b=h[u],y=h[u+1],m=h[u+2],d=h[u+3],x=h[u+4],g=h[u+5],A=So((qe(b-o,y-a)+qe(m-b,d-y)+qe(x-m,g-d))*c);for(let w=1;w<=A;w++){let v=w/A,E=1-v,F=E*E*E,L=3*E*E*v,_=3*E*v*v,O=v*v*v;Xn(F*o+L*b+_*m+O*x,F*a+L*y+_*d+O*g)}o=x,a=g}else if(f===ke.Z){ft&&(ft.closed=!0),ft=null,o=i,a=l;continue}else break;u+=Po[f]}ft=null,Br=null;for(let u=0;u<pt.count;u++){let f=pt.subs[u],h=f.n*2;f.closed&&f.n>=2&&Math.abs(f.pts[0]-f.pts[h-2])<1e-6&&Math.abs(f.pts[1]-f.pts[h-1])<1e-6&&f.n--}return pt}var qe=(s,n)=>Math.sqrt(s*s+n*n),So=s=>Math.min(Math.max(Math.ceil(s),2),24);function Ii(s,n){let e=0;for(let t=0,r=n-1;t<n;r=t++)e+=(s[r*2]-s[t*2])*(s[r*2+1]+s[t*2+1]);return e}var qn=new Int32Array(64),jn=(s,n,e,t,r)=>((s[t*2]-s[e*2])*(s[r*2+1]-s[e*2+1])-(s[t*2+1]-s[e*2+1])*(s[r*2]-s[e*2]))*n;function _o(s,n,e){if(n<3)return 0;qn.length<n&&(qn=new Int32Array(Math.max(n,qn.length*2)));let t=qn,r=n,o=0;for(let c=0;c<n;c++)t[c]=c;let a=Ii(s,n)>0?1:-1,i=n*n+8,l=0;for(;r>3&&i-- >0;){let c=t[(l+r-1)%r],u=t[l%r],f=t[(l+1)%r],h=jn(s,a,c,u,f)>0;if(h)for(let b=0;b<r;b++){let y=t[b];if(!(y===c||y===u||y===f)&&jn(s,a,c,u,y)>=0&&jn(s,a,u,f,y)>=0&&jn(s,a,f,c,y)>=0){h=!1;break}}h?(e[o++]=c,e[o++]=u,e[o++]=f,t.copyWithin(l%r,l%r+1,r),r--,l=Math.max(l-1,0)):l=(l+1)%r}if(r===3)e[o++]=t[0],e[o++]=t[1],e[o++]=t[2];else if(r>3)for(let c=1;c+1<r;c++)e[o++]=t[0],e[o++]=t[c],e[o++]=t[c+1];return o}var Ni=.85,Yn=new Float64Array(64),Mo=new Float64Array(64),To=new Float64Array(64),Eo=new Float64Array(64),Ro=new Float64Array(64),Co=new Float64Array(64),Fo=new Uint8Array(64),kn=new Float64Array(8);function Lo(s,n,e,t,r,o){let a=kn;if(Yn.length<n){let d=Math.max(n,Yn.length*2);Yn=new Float64Array(d),Mo=new Float64Array(d),To=new Float64Array(d),Eo=new Float64Array(d),Ro=new Float64Array(d),Co=new Float64Array(d),Fo=new Uint8Array(d)}let i=Yn,l=Mo,c=0;for(let d=0;d<n;d++){let x=s[d*2],g=s[d*2+1];!Number.isFinite(x)||!Number.isFinite(g)||c&&Math.abs(i[c-1]-x)<.001&&Math.abs(l[c-1]-g)<.001||(i[c]=x,l[c]=g,c++)}if(t&&c>2&&Math.abs(i[0]-i[c-1])<.001&&Math.abs(l[0]-l[c-1])<.001&&c--,c===0)return;if(c===1)return a[0]=i[0],a[1]=l[0],o();let u=t?c:c-1,f=To,h=Eo;for(let d=0;d<u;d++){let x=(d+1)%c,g=i[x]-i[d],A=l[x]-l[d],w=qe(g,A)||1;f[d]=-A/w,h[d]=g/w}let b=Ro,y=Co,m=Fo;for(let d=0;d<c;d++){let x=t?(d-1+u)%u:d-1,g=d<u?d:-1;if(m[d]=1,x<0||g<0||f[x]*f[g]+h[x]*h[g]<Ni)continue;let w=f[x]+f[g],v=h[x]+h[g],E=qe(w,v)||1;w/=E,v/=E;let F=e/Math.max(w*f[g]+v*h[g],.5);b[d]=w*F,y[d]=v*F,m[d]=0}for(let d=0;d<u;d++){let x=(d+1)%c,g=m[d]?f[d]*e:b[d],A=m[d]?h[d]*e:y[d],w=m[x]?f[d]*e:b[x],v=m[x]?h[d]*e:y[x];a[0]=i[d]+g,a[1]=l[d]+A,a[2]=i[x]+w,a[3]=l[x]+v,a[4]=i[x]-w,a[5]=l[x]-v,a[6]=i[d]-g,a[7]=l[d]-A,r()}for(let d=0;d<c;d++)m[d]&&(a[0]=i[d],a[1]=l[d],o())}function Dr(s,n){let e=0,t=1/0;for(let r=0;r<n.length;r++){let o=Math.abs(Math.log(Math.max(s,.5)/n[r]));o<t&&(t=o,e=r)}return e}var Zn=[{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}],Jn=[4,8,16,32,64,128].map((s,n)=>({x:n*4,y:128,w:4,h:s,r:s/2-1})),ot={x:248,y:248,w:8,h:8},No=Zn.map(s=>s.r*2),Bo=Jn.map(s=>s.r*2),Io=(s,n)=>Math.min(Math.max(s+.5-n,0),1);function Bi(){let s=new Uint8ClampedArray(262144),n=(e,t,r)=>{let o=(t*256+e)*4;s[o]=s[o+1]=s[o+2]=255,s[o+3]=Math.round(r*255)};for(let e of Zn){let t=e.w/2;for(let r=0;r<e.h;r++)for(let o=0;o<e.w;o++)n(e.x+o,e.y+r,Io(e.r,Math.hypot(o+.5-t,r+.5-t)))}for(let e of Jn){let t=e.h/2;for(let r=0;r<e.h;r++)for(let o=0;o<e.w;o++)n(e.x+o,e.y+r,Io(e.r,Math.abs(r+.5-t)))}for(let e=0;e<ot.h;e++)for(let t=0;t<ot.w;t++)n(ot.x+t,ot.y+e,1);return s}function Do(){let s=document.createElement("canvas");return s.width=s.height=256,s.getContext("2d").putImageData(new ImageData(Bi(),256,256),0,0),s}var Oo=8,er=`
|
|
2
2
|
#ifdef GL_FRAGMENT_PRECISION_HIGH
|
|
3
3
|
precision highp float;
|
|
4
4
|
#else
|
|
5
5
|
precision mediump float;
|
|
6
6
|
#endif
|
|
7
|
-
`,
|
|
7
|
+
`,Hi=s=>`${er}
|
|
8
8
|
uniform sampler2D uTex[${s}];
|
|
9
9
|
varying vec2 vUv;
|
|
10
10
|
varying vec4 vColor;
|
|
@@ -14,7 +14,7 @@ void main() {
|
|
|
14
14
|
${Array.from({length:s},(n,e)=>e===s-1?`c = texture2D(uTex[${e}], vUv);`:`if (vSlot < ${e}.5) c = texture2D(uTex[${e}], vUv); else `).join(`
|
|
15
15
|
`)}
|
|
16
16
|
gl_FragColor = c * vColor;
|
|
17
|
-
}
|
|
17
|
+
}`,$i=`
|
|
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
|
-
}`,
|
|
31
|
+
}`,Gi=`
|
|
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
|
-
}`,Ni={alpha:!0,premultipliedAlpha:!0,antialias:!1,depth:!1,stencil:!1,preserveDrawingBuffer:!1,powerPreference:"high-performance"},Bi=["aCorner","aP01","aP23","aUvRect","aColor","aSlot"],Di=["aPos","aUv","aColor","aSlot"];function Bo(s,n,e={}){let t={...Ni,failIfMajorPerformanceCaveat:e.failIfMajorPerformanceCaveat!==!1},r=n===2?s.getContext("webgl2",t):s.getContext("webgl",t)??s.getContext("experimental-webgl",t);if(!r||r.isContextLost())return null;try{return new Dr(s,r,n,e)}catch(o){return console.warn("[engine] WebGL setup failed:",o),r.getExtension("WEBGL_lose_context")?.loseContext(),null}}var Dr=class extends Ht{constructor(e,t,r,o){super();p(this,"canvas",e);p(this,"gl",t);p(this,"opts",o);p(this,"kind");p(this,"maxTextureSize");p(this,"support",{filters:!0,shaders:!0});p(this,"features",{});p(this,"info",{});p(this,"lost",!1);p(this,"main");p(this,"cur");p(this,"unit",-1);p(this,"onUnit",new Array(Lo).fill(void 0));p(this,"fbNow");p(this,"mapped",!0);p(this,"calls",{useProgram:0,bindTexture:0,activeTexture:0,bindFramebuffer:0});p(this,"vsrc","");p(this,"attrs",[]);p(this,"fxr",null);p(this,"batch");p(this,"dynamic");p(this,"staticBuf",null);p(this,"index");p(this,"vao",null);p(this,"inst",null);p(this,"vaoApi",null);p(this,"uScale",null);p(this,"textures",new Map);p(this,"kit");p(this,"stats",{drawCalls:0,quads:0,filtersSkipped:0});p(this,"lostListeners",[]);p(this,"restoredListeners",[]);p(this,"tris",new Int32Array(192));p(this,"sU",0);p(this,"sV0",0);p(this,"sV1",0);p(this,"sColor",0);p(this,"sPacked",0);p(this,"sAlpha",0);p(this,"sHw",0);p(this,"strokeSeg",()=>{let e=this.q;e.set(kn),e[8]=e[10]=this.sU,e[9]=this.sV0,e[11]=this.sV1,e[12]=this.sPacked,this.put(this.kit)});p(this,"strokeDisc",()=>this.ellipse(kn[0],kn[1],this.sHw,this.sHw,0,this.sColor,this.sAlpha));p(this,"q",new Float64Array(13));p(this,"layers",[]);p(this,"layerTex",new Map);p(this,"bScis",!1);p(this,"bx0",0);p(this,"by0",0);p(this,"bx1",0);p(this,"by1",0);p(this,"onContextLost",e=>{e.preventDefault(),this.lost=!0;for(let t of this.lostListeners)t()});p(this,"onContextRestored",()=>{try{this.layers=[],this.layerTex.clear(),this.fxr=null,this.resetLayers(this.scale),this.setup();for(let e of this.textures.keys())this.textures.set(e,this.upload(e.source));this.lost=!1;for(let e of this.restoredListeners)e()}catch(e){console.warn("[engine] WebGL restore failed:",e)}});p(this,"views",new Map);this.kind=r===2?"webgl2":"webgl1",this.maxTextureSize=t.getParameter(t.MAX_TEXTURE_SIZE),this.setup(),this.kit=this.createTexture(Po()),Ae.live=this,e.addEventListener("webglcontextlost",this.onContextLost,!1),e.addEventListener("webglcontextrestored",this.onContextRestored,!1)}setup(){let e=this.gl,t=this.kind==="webgl2"?e:null;if(this.inst=null,this.opts.instancing!==!1)if(t)this.inst={divisor:(f,h)=>t.vertexAttribDivisor(f,h),draw:(f,h)=>t.drawElementsInstanced(e.TRIANGLES,f,e.UNSIGNED_SHORT,0,h)};else{let f=e.getExtension("ANGLE_instanced_arrays");f&&(this.inst={divisor:(h,b)=>f.vertexAttribDivisorANGLE(h,b),draw:(h,b)=>f.drawElementsInstancedANGLE(e.TRIANGLES,h,e.UNSIGNED_SHORT,0,b)})}if(this.vaoApi=null,this.opts.vao!==!1)if(t)this.vaoApi={create:()=>t.createVertexArray(),bind:f=>t.bindVertexArray(f),remove:f=>t.deleteVertexArray(f)};else{let f=e.getExtension("OES_vertex_array_object");f&&(this.vaoApi={create:()=>f.createVertexArrayOES(),bind:h=>f.bindVertexArrayOES(h),remove:h=>f.deleteVertexArrayOES(h)})}let r=e.getParameter(e.MAX_TEXTURE_IMAGE_UNITS),o=Math.max(1,Math.min(Lo,r)),a=this.inst!==null;this.vsrc=a?Li:Pi,this.attrs=a?Bi:Di,this.main=this.cur=this.build(_i(o));let i=this.main.p;e.useProgram(i),this.calls.useProgram++,this.unit=-1,this.onUnit.fill(void 0),this.fbNow=void 0,this.uScale=this.main.uScale,e.uniform1iv(e.getUniformLocation(i,"uTex"),Int32Array.from({length:o},(f,h)=>h)),this.batch=new Hn(a,o),this.vaoApi&&(this.vao=this.vaoApi.create(),this.vaoApi.bind(this.vao)),this.dynamic=e.createBuffer(),e.bindBuffer(e.ARRAY_BUFFER,this.dynamic),e.bufferData(e.ARRAY_BUFFER,this.batch.f32.byteLength,e.DYNAMIC_DRAW),this.index=e.createBuffer(),e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,this.index),e.bufferData(e.ELEMENT_ARRAY_BUFFER,xo(a?1:8192),e.STATIC_DRAW);let l=f=>e.getAttribLocation(i,f),c=(f,h,b,y,m,d,x)=>{let g=l(f);g<0||(e.enableVertexAttribArray(g),e.vertexAttribPointer(g,h,b,y,m,d),this.inst&&this.inst.divisor(g,x))};if(a){let f=56;c("aP01",4,e.FLOAT,!1,f,0,1),c("aP23",4,e.FLOAT,!1,f,16,1),c("aUvRect",4,e.FLOAT,!1,f,32,1),c("aColor",4,e.UNSIGNED_BYTE,!0,f,48,1),c("aSlot",1,e.FLOAT,!1,f,52,1),this.staticBuf=e.createBuffer(),e.bindBuffer(e.ARRAY_BUFFER,this.staticBuf),e.bufferData(e.ARRAY_BUFFER,Float32Array.of(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1),e.STATIC_DRAW),c("aCorner",4,e.FLOAT,!1,16,0,0),e.bindBuffer(e.ARRAY_BUFFER,this.dynamic)}else{let f=24;c("aPos",2,e.FLOAT,!1,f,0,0),c("aUv",2,e.FLOAT,!1,f,8,0),c("aColor",4,e.UNSIGNED_BYTE,!0,f,16,0),c("aSlot",1,e.FLOAT,!1,f,20,0)}e.enable(e.BLEND),e.blendFunc(e.ONE,e.ONE_MINUS_SRC_ALPHA),e.disable(e.DEPTH_TEST),e.disable(e.CULL_FACE),e.pixelStorei(e.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!0);let u=e.getExtension("WEBGL_debug_renderer_info");this.info={version:e.getParameter(e.VERSION),renderer:u?e.getParameter(u.UNMASKED_RENDERER_WEBGL):e.getParameter(e.RENDERER),vendor:u?e.getParameter(u.UNMASKED_VENDOR_WEBGL):e.getParameter(e.VENDOR)},this.features={instancing:a,vao:this.vaoApi!==null,textureSlots:o,maxTextureSize:this.maxTextureSize}}upload(e){let t=this.gl,r=t.createTexture();return this.bindTex(r),t.texImage2D(t.TEXTURE_2D,0,t.RGBA,t.RGBA,t.UNSIGNED_BYTE,e),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.LINEAR),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.LINEAR),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE),r}resize(e,t){this.canvas.width!==e&&(this.canvas.width=e),this.canvas.height!==t&&(this.canvas.height=t)}createTexture(e){let t={id:dn(),width:e.width,height:e.height,source:e};return this.textures.set(t,this.lost?null:this.upload(e)),t}updateTexture(e,t,r=0,o=0){if(this.lost)return;this.batch.has(e)&&this.flush();let a=this.gl,i=this.textures.get(e);i&&(this.bindTex(i),!t||t===e.source&&r===0&&o===0?a.texImage2D(a.TEXTURE_2D,0,a.RGBA,a.RGBA,a.UNSIGNED_BYTE,e.source):a.texSubImage2D(a.TEXTURE_2D,0,r,o,a.RGBA,a.UNSIGNED_BYTE,t))}destroyTexture(e){this.batch.has(e)&&this.flush();let t=this.textures.get(e);t&&!this.lost&&this.deleteTex(t),this.textures.delete(e)}begin(e,t,r){if(this.stats.drawCalls=this.stats.quads=this.stats.filtersSkipped=0,this.batch.reset(),this.resetLayers(r),this.bScis=!1,this.lost)return;let o=this.gl;o.disable(o.SCISSOR_TEST),this.bindFb(null),o.viewport(0,0,this.canvas.width,this.canvas.height);let a=t;o.clearColor((e>>16&255)/255*a,(e>>8&255)/255*a,(e&255)/255*a,a),o.clear(o.COLOR_BUFFER_BIT),this.use(this.main),o.uniform2f(this.uScale,2*r/this.canvas.width,-2*r/this.canvas.height),this.mapped=!0}build(e){let t=this.gl,r=No(t,t.VERTEX_SHADER,this.vsrc),o;try{o=No(t,t.FRAGMENT_SHADER,e)}catch(i){throw t.deleteShader(r),i}let a=t.createProgram();if(t.attachShader(a,r),t.attachShader(a,o),this.attrs.forEach((i,l)=>t.bindAttribLocation(a,l,i)),t.linkProgram(a),t.deleteShader(r),t.deleteShader(o),!t.getProgramParameter(a,t.LINK_STATUS)){let i=t.getProgramInfoLog(a)??"?";throw t.deleteProgram(a),new Error(`link: ${i}`)}return{p:a,uScale:t.getUniformLocation(a,"uScale"),locs:new Map}}u(e,t){let r=e.locs.get(t);return r===void 0&&e.locs.set(t,r=this.gl.getUniformLocation(e.p,t)),r}use(e){this.cur!==e&&(this.cur=e,this.gl.useProgram(e.p),this.calls.useProgram++)}bindTex(e,t=this.unit<0?0:this.unit){let r=this.gl;this.onUnit[t]!==e&&(this.unit!==t&&(r.activeTexture(r.TEXTURE0+t),this.calls.activeTexture++,this.unit=t),r.bindTexture(r.TEXTURE_2D,e),this.calls.bindTexture++,this.onUnit[t]=e)}deleteTex(e){this.gl.deleteTexture(e);for(let t=0;t<this.onUnit.length;t++)this.onUnit[t]===e&&(this.onUnit[t]=null)}bindFb(e){if(e)for(let r=0;r<this.onUnit.length;r++)this.onUnit[r]===e.gl&&this.bindTex(null,r);let t=e?e.fb:null;this.fbNow!==t&&(this.gl.bindFramebuffer(this.gl.FRAMEBUFFER,t),this.calls.bindFramebuffer++,this.fbNow=t)}slotOf(e){this.batch.full&&this.flush();let t=this.batch.slot(e);return t<0&&(this.flush(),t=this.batch.slot(e)),t}quad(e,t,r,o,a,i,l,c){j[0]=o,j[1]=a,j[2]=l,this.quadQ(e,t,r,i,c)}quadQ(e,t,r,o,a){let i=j[2];if(this.lost||i<=0)return;let l=this.q,c=j[0],u=j[1],f=r[4],h=r[5],b=r[0]*c,y=r[1]*c,m=r[2]*u,d=r[3]*u;l[0]=f,l[1]=h,l[2]=b+f,l[3]=y+h,l[4]=b+m+f,l[5]=y+d+h,l[6]=m+f,l[7]=d+h;let x=1/e.width,g=1/e.height;l[8]=t.x*x,l[9]=t.y*g,l[10]=(t.x+t.w)*x,l[11]=(t.y+t.h)*g,l[12]=rt(o,i,a==="add"),this.put(e)}put(e){if(this.mute)return;let t=this.q,r=!1,o=Math.min(t[0],t[2],t[4],t[6]),a=Math.max(t[0],t[2],t[4],t[6]),i=Math.min(t[1],t[3],t[5],t[7]),l=Math.max(t[1],t[3],t[5],t[7]);if(this.cOn){if(this.px1<=this.px0||this.py1<=this.py0)return;let u=this.scale,f=this.px0/u,h=this.py0/u,b=this.px1/u,y=this.py1/u;if(a<=f||o>=b||l<=h||i>=y)return;if(o<f||a>b||i<h||l>y){let m=t[0],d=t[1],x=t[2],g=t[5];if(d===t[3]&&x===t[4]&&g===t[7]&&t[6]===m){if(m!==x){let M=Math.min(Math.max(m,f),b),v=Math.min(Math.max(x,f),b),A=t[8],E=(t[10]-A)/(x-m);t[10]=A+(v-m)*E,t[8]=A+(M-m)*E,t[0]=t[6]=M,t[2]=t[4]=v}if(d!==g){let M=Math.min(Math.max(d,h),y),v=Math.min(Math.max(g,h),y),A=t[9],E=(t[11]-A)/(g-d);t[11]=A+(v-d)*E,t[9]=A+(M-d)*E,t[1]=t[3]=M,t[5]=t[7]=v}}else r=!0}}let c=this.bx0===this.px0&&this.by0===this.py0&&this.bx1===this.px1&&this.by1===this.py1;if(r?(!this.bScis||!c)&&(this.flush(),this.bScis=!0,this.bx0=this.px0,this.by0=this.py0,this.bx1=this.px1,this.by1=this.py1):this.bScis&&!(this.cOn&&c)&&(this.flush(),this.bScis=!1),this.real){let u=this.gq;u[0]=o,u[1]=i,u[2]=a,u[3]=l,this.growQ()}this.batch.pushQ(t,this.slotOf(e))}ellipse(e,t,r,o,a,i,l){if(this.lost||l<=0||r<=0||o<=0)return;let c=Kn[Br(Math.max(r,o)*2*this.scale,Co)],u=c.w/2/c.r,f=r*u,h=o*u,b=Math.cos(a),y=Math.sin(a),m=b*f,d=y*f,x=-y*h,g=b*h,M=1/256,v=this.q;v[0]=e-m-x,v[1]=t-d-g,v[2]=e+m-x,v[3]=t+d-g,v[4]=e+m+x,v[5]=t+d+g,v[6]=e-m+x,v[7]=t-d+g,v[8]=c.x*M,v[9]=c.y*M,v[10]=(c.x+c.w)*M,v[11]=(c.y+c.h)*M,v[12]=rt(i,l),this.put(this.kit)}polygon(e,t,r,o){if(this.lost||o<=0||t<3)return;this.tris.length<t*3&&(this.tris=new Int32Array(Math.max(t*3,this.tris.length*2)));let a=this.tris,i=Eo(e,t,a),l=rt(r,o),c=(Je.x+Je.w/2)/256,u=(Je.y+Je.h/2)/256;for(let f=0;f<i;f+=3){let h=a[f]*2,b=a[f+1]*2,y=a[f+2]*2,m=this.q;m[0]=e[h],m[1]=e[h+1],m[2]=e[b],m[3]=e[b+1],m[4]=m[6]=e[y],m[5]=m[7]=e[y+1],m[8]=m[10]=c,m[9]=m[11]=u,m[12]=l,this.put(this.kit)}}stroke(e,t,r,o,a,i){if(this.lost||a<=0||r<=0||t<1)return;let l=Qn[Br(r*this.scale,_o)],c=r/2*(l.h/2/l.r);this.sPacked=rt(o,a),this.sColor=o,this.sAlpha=a,this.sU=(l.x+l.w/2)/256,this.sV0=l.y/256,this.sV1=(l.y+l.h)/256,this.sHw=r/2,Ro(e,t,c,i,this.strokeSeg,this.strokeDisc)}target(e,t,r,o){let a=this.gl,i=a.createTexture();this.bindTex(i),a.texImage2D(a.TEXTURE_2D,0,a.RGBA,e,t,0,a.RGBA,a.UNSIGNED_BYTE,null);let l=o?a.LINEAR:a.NEAREST;a.texParameteri(a.TEXTURE_2D,a.TEXTURE_MIN_FILTER,l),a.texParameteri(a.TEXTURE_2D,a.TEXTURE_MAG_FILTER,l),a.texParameteri(a.TEXTURE_2D,a.TEXTURE_WRAP_S,a.CLAMP_TO_EDGE),a.texParameteri(a.TEXTURE_2D,a.TEXTURE_WRAP_T,a.CLAMP_TO_EDGE),this.bindTex(null);let c=a.createFramebuffer();a.bindFramebuffer(a.FRAMEBUFFER,c),a.framebufferTexture2D(a.FRAMEBUFFER,a.COLOR_ATTACHMENT0,a.TEXTURE_2D,i,0);let u=a.checkFramebufferStatus(a.FRAMEBUFFER)===a.FRAMEBUFFER_COMPLETE;if(this.fbNow=c,this.bindFb(this.parent()),!u)return this.deleteTex(i),a.deleteFramebuffer(c),null;let f={tex:{id:dn(),width:e,height:t,source:this.canvas},gl:i,fb:c,w:e,h:t,f:r};return this.layerTex.set(f.tex,i),f}drop(e){this.batch.has(e.tex)&&this.flush(),this.deleteTex(e.gl),this.gl.deleteFramebuffer(e.fb),this.layerTex.delete(e.tex)}parent(){return this.real>0?this.layers[this.real-1]:null}layerAt(e){let t=this.canvas.width,r=this.canvas.height,o=this.layers[e]??null;return o&&(o.w!==t||o.h!==r)&&(this.drop(o),o=this.layers[e]=null),o??(this.layers[e]=this.target(t,r,1,!1))}pushLayer(){if(this.lost)return!1;this.flush();let e=this.layerAt(this.real);if(!e)return!1;let t=this.gl;return this.bindFb(e),t.disable(t.SCISSOR_TEST),t.clearColor(0,0,0,0),t.clear(t.COLOR_BUFFER_BIT),!0}popLayer(){return this.flush(),this.bindFb(this.parent()),this.layers[this.real].tex}filters(){return this.lost||!Ae.gl?null:this.fxr??(this.fxr=Ae.gl(this))}composite(e,t,r,o){if(o&&this.filters()?.chain(e,r,o))return;let a=this.gl;t&&a.blendFunc(a.ZERO,a.SRC_ALPHA),this.final(this.main,e,1,r),t&&(this.flush(),a.blendFunc(a.ONE,a.ONE_MINUS_SRC_ALPHA))}final(e,t,r,o){let a=this.gl,i=this.canvas.width,l=this.canvas.height,c=this.scale;(e!==this.main||!this.mapped)&&(this.bindFb(this.parent()),a.viewport(0,0,i,l),this.use(e),a.uniform2f(e.uScale,2*c/i,-2*c/l),this.mapped=e===this.main);let u=this.rx0/c,f=this.ry0/c,h=this.rx1/c,b=this.ry1/c,y=1/(r*t.width),m=1/(r*t.height),d=this.q;d[0]=d[6]=u,d[1]=d[3]=f,d[2]=d[4]=h,d[5]=d[7]=b,d[8]=this.rx0*y,d[9]=1-this.ry0*m,d[10]=this.rx1*y,d[11]=1-this.ry1*m,d[12]=rt(16777215,o),this.put(t),e!==this.main&&this.flush()}remap(){let e=this.gl;this.bindFb(this.parent()),e.viewport(0,0,this.canvas.width,this.canvas.height),this.use(this.main),e.uniform2f(this.uScale,2*this.scale/this.canvas.width,-2*this.scale/this.canvas.height),this.mapped=!0}upload2(e){let t=this.gl,r=e.words;if(this.kind==="webgl2")return t.bufferSubData(t.ARRAY_BUFFER,0,e.f32,0,r);let o=this.views.get(r);o||(this.views.size>=256&&this.views.clear(),this.views.set(r,o=e.f32.subarray(0,r))),t.bufferSubData(t.ARRAY_BUFFER,0,o)}flush(){let e=this.batch;if(!e.quads||this.lost)return e.reset();let t=this.gl;this.bScis?(t.enable(t.SCISSOR_TEST),t.scissor(this.bx0,this.canvas.height-this.by1,this.bx1-this.bx0,this.by1-this.by0)):t.disable(t.SCISSOR_TEST),this.upload2(e);for(let r=0;r<e.bound;r++){let o=e.textures[r];this.bindTex(this.textures.get(o)??this.layerTex.get(o)??null,r)}this.inst?this.inst.draw(6,e.quads):t.drawElements(t.TRIANGLES,e.quads*6,t.UNSIGNED_SHORT,0),this.stats.drawCalls++,this.stats.quads+=e.quads,e.reset()}end(){return this.closeLayers(),this.flush(),this.stats.filtersSkipped=this.skipped,this.stats}onLost(e){this.lostListeners.push(e)}onRestored(e){this.restoredListeners.push(e)}destroy(){let e=this.gl;Ae.live===this&&(Ae.live=null),this.canvas.removeEventListener("webglcontextlost",this.onContextLost),this.canvas.removeEventListener("webglcontextrestored",this.onContextRestored);try{for(let t of this.textures.values())t&&e.deleteTexture(t);for(let t of this.layers)t&&(e.deleteTexture(t.gl),e.deleteFramebuffer(t.fb));this.fxr?.destroy(),this.fxr=null,e.deleteBuffer(this.dynamic),e.deleteBuffer(this.index),this.staticBuf&&e.deleteBuffer(this.staticBuf),this.vao&&this.vaoApi&&this.vaoApi.remove(this.vao),e.deleteProgram(this.main.p),e.getExtension("WEBGL_lose_context")?.loseContext()}catch{}this.textures.clear()}};function No(s,n,e){let t=s.createShader(n);if(s.shaderSource(t,e),s.compileShader(t),!s.getShaderParameter(t,s.COMPILE_STATUS)){let r=s.getShaderInfoLog(t)??"?";throw s.deleteShader(t),new Error(r)}return t}function Or(s="auto"){switch(s){case"canvas2d":return["canvas2d"];case"webgl1":return["webgl1","canvas2d"];default:return["webgl2","webgl1","canvas2d"]}}function Vt(s,n={}){let e=s;for(let t of Or(n.renderer)){let r=t==="canvas2d"?Gt(e):Bo(e,t==="webgl2"?2:1,n);if(r)return r;e=vn(e)}throw new Error("No renderer: this browser has neither WebGL nor Canvas 2D")}function vn(s){let n=s.cloneNode(!1);return s.parentNode?.replaceChild(n,s),n}function Do(s=typeof location<"u"?location.search:""){let n=new URLSearchParams(s).get("renderer");return n==="canvas"?"canvas2d":n==="webgl2"||n==="webgl1"||n==="canvas2d"||n==="webgl"||n==="auto"?n:void 0}var ct=class{constructor(n,e={}){p(this,"atlas",n);p(this,"tags",new Map);p(this,"count",0);p(this,"m",Ke());p(this,"measure",null);p(this,"height");p(this,"font");this.height=e.tagHeight??34,this.font=e.tagFont??"Nunito, sans-serif"}drop(){for(let n of this.tags.values())for(let e of n.values())for(let t of e.values())this.atlas.release(t);this.tags.clear(),this.count=0}get(n,e,t){let r=this.tags.get(n);r||this.tags.set(n,r=new Map);let o=r.get(e);o||r.set(e,o=new Map);let a=o.get(t);return a&&this.atlas.valid(a)?a:this.bake(n,e,t)}bake(n,e,t){let r=this.height,o=`700 ${Math.round(r*.65)}px ${this.font}`,a=this.measure??(this.measure=document.createElement("canvas").getContext("2d"));a.font=o;let i=Math.round(r*.4),l=Math.ceil(a.measureText(n).width)+i*2,c=this.atlas.bake((l+2)*t,(r+2)*t,h=>{h.scale(t,t),h.translate(1,1);let b=r/2;h.beginPath(),h.moveTo(b,0),h.lineTo(l-b,0),h.arc(l-b,b,b,-Math.PI/2,Math.PI/2),h.lineTo(b,r),h.arc(b,b,b,Math.PI/2,Math.PI*3/2),h.closePath(),h.fillStyle=e,h.fill(),h.fillStyle="#fff",h.font=o,h.textAlign="center",h.textBaseline="middle",h.fillText(n,l/2,r/2+1)},t,1,1,1);++this.count>64&&(this.drop(),this.count=1);let u=this.tags.get(n);u||this.tags.set(n,u=new Map);let f=u.get(e);return f||u.set(e,f=new Map),f.set(t,c),c}draw(n,e,t,r,o,a,i,l,c,u,f){let h=Pt(t,o,{band:Oi(r)});if(!h)return;let b=this.height,y=this.get(a,i,c),m=y.w/y.scale-2,d=Math.min(Math.max(h.head.x-m/2,4),u-m-4),x=Math.min(Math.max(h.head.y-h.headR*2.2-b,4),f-b-4);we(this.m,null,d-1,x-1,0,1,1),n.quad(e(y.surface),y,this.m,y.w/y.scale,y.h/y.scale,16777215,l,"normal")}},Oi=s=>s.band==="3-5"||s.band==="9-12"?s.band:"6-8";var Ii=(s,n=!1)=>n?Math.min(2**Math.round(Math.log2(Math.max(s,8))),256):Math.min(2**(Math.ceil(Math.log2(Math.max(s,8))*2)/2),512);function er(s,n=null){let e={minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0},t=(r,o,a)=>{let i=n?n[0]*r+n[2]*o+n[4]:r,l=n?n[1]*r+n[3]*o+n[5]:o,c=n?Math.hypot(n[0],n[1]):1;e.minX=Math.min(e.minX,i-a*c),e.minY=Math.min(e.minY,l-a*c),e.maxX=Math.max(e.maxX,i+a*c),e.maxY=Math.max(e.maxY,l+a*c)};for(let r of s){let o="lw"in r&&r.stroke?(r.lw??1)/2:0;switch(r.k){case"circle":t(r.x-r.r,r.y-r.r,o),t(r.x+r.r,r.y+r.r,o),t(r.x-r.r,r.y+r.r,o),t(r.x+r.r,r.y-r.r,o);break;case"ellipse":case"rect":{let a=r.k==="ellipse"?Math.max(r.rx,r.ry):Math.hypot(r.w,r.h)/2;t(r.x-a,r.y-a,o),t(r.x+a,r.y+a,o),t(r.x-a,r.y+a,o),t(r.x+a,r.y-a,o);break}case"path":{let a=Yn(r.d);for(let i=0;i<a.count;i++){let l=a.subs[i];for(let c=0;c<l.n;c++)t(l.pts[c*2],l.pts[c*2+1],o)}break}case"line":for(let a=0;a+1<r.pts.length;a+=2)t(r.pts[a],r.pts[a+1],o);break;case"group":{let a=we(Ke(),n,r.x,r.y,r.rot??0,r.s??1,r.s??1),i=er(r.items,a);Number.isFinite(i.minX)&&(e.minX=Math.min(e.minX,i.minX),e.minY=Math.min(e.minY,i.minY),e.maxX=Math.max(e.maxX,i.maxX),e.maxY=Math.max(e.maxY,i.maxY));break}}}return e}var wt=class{constructor(n){p(this,"atlas",n);p(this,"seen",new WeakSet);p(this,"baked",new WeakMap);p(this,"m",Ke());p(this,"stack",[]);p(this,"local",Ke());p(this,"pts",new Float64Array(128));p(this,"stats",{baked:0,vector:0});p(this,"bakeGroups",!0);p(this,"coarse",!1);p(this,"gen",0);p(this,"live",new Set)}setTier(n){let e=n==="low";if(e!==this.coarse){this.coarse=e,this.gen++;for(let t of this.live)this.atlas.release(t.frame);this.live.clear()}}draw(n,e,t,r,o,a,i){let l=typeof r=="string"?Lt(r)??yt:r,c=ln(t,l,o);return c.length?(a<=0||(a<1?(this.paint(n,e,c,null,n.beginLayer()?1:a,i),n.endLayer(a)):this.paint(n,e,c,null,a,i)),!0):!1}paint(n,e,t,r,o,a,i=0){var l;for(let c=0;c<t.length;c++){let u=t[c];if(u.k==="group"){let g=we((l=this.stack)[i]??(l[i]=Ke()),r,u.x,u.y,u.rot??0,u.s??1,u.s??1),M=o*(u.alpha??1);if(this.bakeGroups&&this.seen.has(u.items)){let v=He(g[0],g[1])*a,A=this.bake(u.items,v);if(A){let E=A.frame,C=this.m;C.set(g),C[4]=g[0]*-A.ox+g[2]*-A.oy+g[4],C[5]=g[1]*-A.ox+g[3]*-A.oy+g[5],n.quad(e(E.surface),E,C,E.w/A.k,E.h/A.k,16777215,M,"normal"),this.stats.baked++;continue}}this.seen.add(u.items),this.stats.vector++,this.paint(n,e,u.items,g,M,a,i+1);continue}let f=o*(u.alpha??1),h=r?He(r[0],r[1]):1,b=r?Math.atan2(r[1],r[0]):0,y=(u.lw??1)*h,m=u.stroke&&(u.lw??1)>0?he(u.stroke):null,d=u.fill&&u.k!=="line"?he(u.fill):null;if(u.k==="circle"||u.k==="ellipse"){let g=r?r[0]*u.x+r[2]*u.y+r[4]:u.x,M=r?r[1]*u.x+r[3]*u.y+r[5]:u.y,v=(u.k==="circle"?u.r:u.rx)*h,A=(u.k==="circle"?u.r:u.ry)*h,E=(u.k==="ellipse"?u.rot??0:0)+b;if(d&&m)n.ellipse(g,M,v+y/2,A+y/2,E,m[0],f*m[1]),n.ellipse(g,M,Math.max(v-y/2,0),Math.max(A-y/2,0),E,d[0],f*d[1]);else if(d)n.ellipse(g,M,v,A,E,d[0],f*d[1]);else if(m){let C=Math.min(Math.max(Math.ceil(Math.max(v,A)*a*.6),12),64),P=this.pts=jn(this.pts,C*2),L=Math.cos(E),I=Math.sin(E);for(let U=0;U<C;U++){let X=U/C*Math.PI*2,H=Math.cos(X)*v,fe=Math.sin(X)*A;P[U*2]=g+H*L-fe*I,P[U*2+1]=M+H*I+fe*L}n.stroke(P,C,y,m[0],f*m[1],!0)}continue}if(u.k==="line"){if(!m)continue;let g=u.pts.length>>1,M=this.pts=jn(this.pts,g*2);for(let v=0;v<g;v++){let A=u.pts[v*2],E=u.pts[v*2+1];M[v*2]=r?r[0]*A+r[2]*E+r[4]:A,M[v*2+1]=r?r[1]*A+r[3]*E+r[5]:E}n.stroke(M,g,y,m[0],f*m[1],!1);continue}let x=u.k==="path"?Yn(u.d,r,h*a):zi(u,we(this.local,r,u.x,u.y,u.rot??0,1,1),a*h);for(let g=0;g<x.count;g++){let M=x.subs[g],v=M.n,A=u.k==="rect"||M.closed;d&&v>=3&&(n.polygon(M.pts,v,d[0],f*d[1]),m||n.stroke(M.pts,v,1/a,d[0],f*d[1],!0)),m&&n.stroke(M.pts,v,y,m[0],f*m[1],A)}}}bake(n,e){let t=Ii(e,this.coarse),r=this.baked.get(n),o=r?.get(t);if(o&&o.gen===this.gen&&this.atlas.valid(o.frame))return o;o&&this.live.delete(o);let a=er(n);if(!Number.isFinite(a.minX))return null;let i=2/t,l=(a.maxX-a.minX+i*2)*t,c=(a.maxY-a.minY+i*2)*t;if(l>1024||c>1024)return null;let u=-a.minX+i,f=-a.minY+i,b={frame:this.atlas.bake(l,c,y=>{y.scale(t,t),y.translate(u,f),Ct(y,n)}),k:t,ox:u,oy:f,gen:this.gen};return r||this.baked.set(n,r=new Map),r.set(t,b),this.live.add(b),b}},Xt=new Array(36).fill(0),qt=0,Ge=(s,n=NaN,e=NaN,t=NaN,r=NaN)=>{Xt[qt++]=s,s!==ye.Z&&(Xt[qt++]=n,Xt[qt++]=e,s===ye.Q&&(Xt[qt++]=t,Xt[qt++]=r))};function zi(s,n,e){let t=Math.max(0,Math.min(s.r,s.w/2,s.h/2)),r=-s.w/2,o=-s.h/2,{M:a,L:i,Q:l,Z:c}=ye;return qt=0,Ge(a,r+t,o),Ge(i,r+s.w-t,o),Ge(l,r+s.w,o,r+s.w,o+t),Ge(i,r+s.w,o+s.h-t),Ge(l,r+s.w,o+s.h,r+s.w-t,o+s.h),Ge(i,r+t,o+s.h),Ge(l,r,o+s.h,r,o+s.h-t),Ge(i,r,o+t),Ge(l,r,o,r+t,o),Ge(c),Yn(Xt,n,e)}function Oo(s,n={}){let e=Vt(s,n),t=new at(Math.min(1024,e.maxTextureSize),2);t.onDrop=A=>{A.texture&&e.destroyTexture(A.texture),A.texture=null};let r=new wt(t),o=new xn,a=new Map,i=1e6,l=n.smooth===!1?1:typeof n.smooth=="number"?Math.min(Math.max(n.smooth,.05),1):.5,c=wn(e),u=new ct(t,n),f={w:1,h:1},h=1,b=0,y=!1,m=()=>u.drop(),d=typeof document<"u"?document.fonts:void 0;d?.ready?.then(()=>{y||m()}),d?.addEventListener?.("loadingdone",m);let x=()=>{let A=vn(e.canvas),E=Gt(A);if(E){console.warn("[engine] avatars: WebGL context lost for good, switching to Canvas 2D"),e.destroy(),e=E;for(let C of t.pages)C.surface.texture=null;c=wn(e),b=0}},g=()=>{if(!e.lost)return b=0,!0;let A=performance.now();return b||(b=A),A-b>3e3&&x(),!e.lost},M=()=>{let A=e.canvas;n.units?(h=n.pixelRatio??1,f.w=n.units.width,f.h=n.units.height):(h=n.pixelRatio??Math.min(globalThis.devicePixelRatio||1,2),f.w=A.clientWidth||A.width/h,f.h=A.clientHeight||A.height/h),e.resize(Math.max(1,Math.round(f.w*h)),Math.max(1,Math.round(f.h*h))),e.begin(0,0,h)},v=(A,E)=>{if(A.key===void 0)return A.id??E+1;let C=a.get(A.key);return C===void 0&&(a.size>256&&a.clear(),a.set(A.key,C=i++)),C};return{get renderer(){return e},get kind(){return e.kind},get lost(){return e.lost},get canvas(){return e.canvas},draw(A,E){if(g()){M();for(let C=0;C<A.length;C++){let P=A[C];if(!Array.isArray(P.body))continue;let L=v(P,C),I=l<1||n.interpolate!==!1?o.posed(L,P.body,l,n.interpolate!==!1):P.body,U=Lt(P.avatar??"")??yt,X=P.alpha??1;!r.draw(e,c,I,U,E,X,h)||!P.name||u.draw(e,c,I,U,E,P.name,P.color??"#6FA0E0",X,h,f.w,f.h)}e.end()}},clear(){g()&&(M(),e.end())},reset(){o=new xn,a.clear()},destroy(){y=!0,d?.removeEventListener?.("loadingdone",m),e.destroy()}}}var Jn=new Map;function Io(s,n,e=Math.min(globalThis.devicePixelRatio||1,2)){let t=`${s}|${n}|${e}`,r=Jn.get(t);if(r)return r;r=document.createElement("canvas"),r.width=r.height=Math.round(n*e);let o=r.getContext("2d");return o.scale(e,e),o.beginPath(),o.rect(0,0,n,n),o.clip(),Ct(o,Ws(Lt(s)??yt,n)),Jn.size>64&&Jn.clear(),Jn.set(t,r),r}function wn(s){return n=>{if(n.texture||(n.texture=s.createTexture(n.source),n.pending.length=0),n.pending.length){for(let[e,t,r]of n.pending)s.updateTexture(n.texture,e,t,r);n.pending.length=0}return n.texture}}var Ir='Fredoka, Nunito, "Varela Round", system-ui, sans-serif',At="rgba(10,16,30,0.75)";function zr(s,n){let e=s.size??40,t=s.outline?s.outline===!0?At:s.outline:null,r=t?s.outlineWidth??Math.max(e*.12,3):0,o=s.shadow&&n?s.shadow===!0?At:s.shadow:null,a=o?s.shadowBlur??e*.25:0;return{size:e,font:s.font??Ir,weight:s.weight??700,color:s.color??"#FBEFE3",outline:t,ow:r,shadow:o,blur:a,pad:r/2+a*1.2+2,th:e*1.25}}var zo=(s,n)=>`${s.weight} ${s.size*n}px ${s.font}`;function Ur(s,n,e,t,r,o){s.scale(t,t),s.font=zo(e,1),s.textBaseline="middle",s.textAlign="left",s.lineJoin="round",e.shadow&&(s.shadowColor=e.shadow,s.shadowBlur=e.blur*t),e.outline&&(s.strokeStyle=e.outline,s.lineWidth=e.ow,s.strokeText(n,r,o),s.shadowColor="transparent"),s.fillStyle=e.color,s.fillText(n,r,o)}var tr=null;function $r(s,n,e){return tr??(tr=document.createElement("canvas").getContext("2d")),tr.font=zo(n,e),tr.measureText(s).width/e}var We=class extends Se{constructor(e,t,r={}){super(e,null);p(this,"_text");p(this,"_style");p(this,"dirty",!0);p(this,"bakedScale",0);p(this,"bakedFontGen",-1);p(this,"bakedEffects",!0);p(this,"capW",0);p(this,"capH",0);this._text=t;let{x:o,y:a,rotation:i,scale:l,scaleX:c,scaleY:u,alpha:f,visible:h,tint:b,blend:y,z:m,anchor:d,hitRadius:x,clip:g,mask:M,filters:v,...A}=r;this._style=A,this.bake(),this.set({x:o,y:a,rotation:i,scale:l,scaleX:c,scaleY:u,alpha:f,visible:h,tint:b,blend:y,z:m,hitRadius:x,clip:g,mask:M,filters:v}),d!==void 0&&(this.anchor=d)}get text(){return this._text}set text(e){let t=String(e);t!==this._text&&(this._text=t,this.dirty=!0)}get style(){return this._style}set style(e){this._style={...this._style,...e},this.dirty=!0}bitmap(){let e=this._style.bitmapFont;if(!e)return null;let t=typeof e=="string"?this.kernel.bitmapFont(e):e;if(this.autoAnchor){let r=this._style.align;this.anchorX=r==="left"?0:r==="right"?1:.5,this.anchorY=.5}return t}get naturalWidth(){let e=this.bitmap();return e?e.measure(this._text)*((this._style.size??e.size)/e.size):super.naturalWidth}get naturalHeight(){let e=this.bitmap();return e?e.lineHeight*((this._style.size??e.size)/e.size):super.naturalHeight}frameNow(){return this._style.bitmapFont?null:this.bake()}draw(e,t,r){let o=this.bitmap();if(!o)return super.draw(e,t,r);let a=(this._style.size??o.size)/o.size,i=o.measure(this._text)*a,l=o.lineHeight*a,c=this.width,u=this.height,f=i>0?c/i:1,h=l>0?u/l:1;o.run(this._text,e,this.world,-this.anchorX*c,-this.anchorY*u,a*f,a*h,r,t,this.blend)}destroy(){this._frame&&this.kernel.atlas.release(this._frame),super.destroy()}bake(){let e=this.kernel;if(this._style.bitmapFont)return null;let t=e.pixelScale,r=e.effects;return!this.dirty&&t===this.bakedScale&&e.fontGen===this.bakedFontGen&&r===this.bakedEffects&&e.atlas.valid(this._frame)?this._frame:this.rebake()}rebake(){let e=this.kernel,t=e.pixelScale,r=e.effects;this.dirty=!1,this.bakedScale=t,this.bakedFontGen=e.fontGen,this.bakedEffects=r;let o=zr(this._style,r),{pad:a,th:i}=o,l=$r(this._text,o,t),c=(l+a*2)*t,u=(i+a*2)*t,f=this._style.align??"center",h=f==="left"?a:f==="right"?a+l:a+l/2,b=d=>Ur(d,this._text,o,t,a,a+i/2),y=this._frame,m=null;return y&&e.atlas.valid(y)&&y.scale===t&&(m=e.atlas.rebake(y,c,u,b,this.capW,this.capH),m?Object.assign(m,{ox:h,oy:a+i/2,margin:a}):e.atlas.release(y)),m||(this.capW=Math.ceil(c*1.25+16),this.capH=Math.ceil(u),m=e.atlas.bake(this.capW,this.capH,b,t,h,a+i/2,a),m.w=Math.ceil(c),m.h=Math.ceil(u)),this._frame=m,this.autoAnchor&&this.useFrameAnchor(),this._w=this._h=null,m}};var oe=(s,n=0)=>{let e=Number(s);return Number.isFinite(e)?e:n};function Yt(s){typeof s=="string"&&/^\s*[{[]/.test(s)&&(s=JSON.parse(s));let n={size:0,lineHeight:0,base:0,pages:[],chars:[],kernings:[]},e=(t,r)=>{t==="info"?n.size=Math.abs(oe(r.size)):t==="common"?(n.lineHeight=oe(r.lineHeight),n.base=oe(r.base)):t==="page"?n.pages[oe(r.id)]=String(r.file??""):t==="char"?n.chars.push({id:oe(r.id),x:oe(r.x),y:oe(r.y),width:oe(r.width),height:oe(r.height),xoffset:oe(r.xoffset),yoffset:oe(r.yoffset),xadvance:oe(r.xadvance),page:oe(r.page)}):n.kernings.push({first:oe(r.first),second:oe(r.second),amount:oe(r.amount)})};if(typeof s=="object"){let t=s;e("info",t.info??{}),e("common",t.common??{});for(let[r,o]of(t.pages??[]).entries())e("page",{id:r,file:o});for(let r of t.chars??[])e("char",r);for(let r of t.kernings??[])e("kerning",r)}else{let t=/(?:^|<)\s*(info|common|page|char|kerning)\s([^\n<>]*)/gm,r=/(\w+)=(?:"([^"]*)"|([^\s/>]+))/g;for(let o=t.exec(s);o;o=t.exec(s)){let a={};for(let i=r.exec(o[2]);i;i=r.exec(o[2]))a[i[1]]=i[2]??i[3];e(o[1],a)}}return n.size||(n.size=n.lineHeight),n}var jt=class{constructor(n,e,t,r=null,o=null){p(this,"baker",r);p(this,"host",o);p(this,"size");p(this,"lineHeight");p(this,"base");p(this,"ascii",new Array(128));p(this,"more",new Map);p(this,"kern",new Map);p(this,"bScale",0);p(this,"bFontGen",-1);p(this,"bEffects",!1);p(this,"bGen",-1);this.size=n,this.lineHeight=e,this.base=t}set(n,e){n<128?this.ascii[n]=e:this.more.set(n,e)}setKerning(n,e,t){this.kern.set(n*1114112+e,t)}prepare(){let n=this.host;if(!(!n||n.pixelScale===this.bScale&&n.fontGen===this.bFontGen&&n.effects===this.bEffects&&n.atlas.gen===this.bGen)){this.bScale=n.pixelScale,this.bFontGen=n.fontGen,this.bEffects=n.effects,this.bGen=n.atlas.gen;for(let e of this.ascii)e&&n.atlas.release(e.frame);for(let e of this.more.values())e&&n.atlas.release(e.frame);this.ascii.fill(void 0),this.more.clear()}}glyph(n){let e=n<128?this.ascii[n]:this.more.get(n);return(e===void 0||e&&this.host&&!this.host.atlas.valid(e.frame))&&(e=this.baker?this.baker(n):null,this.set(n,e)),e}kerning(n,e){return this.kern.size?this.kern.get(n*1114112+e)??0:0}measure(n){return this.run(n)}run(n,e,t,r=0,o=0,a=1,i=1,l=0,c=1,u="normal"){this.prepare();let f=0,h=-1;for(let b=0;b<n.length;b++){let y=n.charCodeAt(b);y>=55296&&y<56320&&b+1<n.length&&(y=n.codePointAt(b),b++),h>=0&&(f+=this.kerning(h,y)),h=y;let m=this.glyph(y);m&&(e&&m.w>0&&m.h>0&&(bn(t,r+(f+m.x)*a,o+m.y*i),e.r.quad(e.tex(m.frame.surface),m.frame,re,m.w*a,m.h*i,l,c,u)),f+=m.advance)}return f}};function Uo(s,n){let e=new jt(s.size,s.lineHeight,s.base);for(let t of s.chars){let r=n[t.page];if(!r)continue;let o={surface:r,x:t.x,y:t.y,w:t.width,h:t.height,scale:1,gen:0,ox:0,oy:0,margin:0};e.set(t.id,{frame:o,x:t.xoffset,y:t.yoffset,w:t.width,h:t.height,advance:t.xadvance})}for(let t of s.kernings)e.setKerning(t.first,t.second,t.amount);return e}function $o(s,n){let e={...n},t=n.size??40,r=a=>{let i=String.fromCodePoint(a),l=s.pixelScale,c=zr(e,s.effects),u=$r(i,c,l),f=s.atlas.bake((u+c.pad*2)*l,(c.th+c.pad*2)*l,h=>Ur(h,i,c,l,c.pad,c.pad+c.th/2),l);return{frame:f,x:-c.pad,y:-c.pad,w:f.w/l,h:f.h/l,advance:u}},o=new jt(t,t*1.25,t,r,s);o.prepare();for(let a of n.chars??"0123456789")o.glyph(a.codePointAt(0));return o}var Ui=.5;function Hr(s){let n=[];for(let[e,t]of[["left",Y.leftWrist],["right",Y.rightWrist]]){let r=s[t*3],o=s[t*3+1],a=s[t*3+2];r!==void 0&&o!==void 0&&Number.isFinite(r)&&Number.isFinite(o)&&(a??0)>=Ui&&n.push({side:e,x:r,y:o})}return n}var An=s=>sn[((s-1)%sn.length+sn.length)%sn.length];function nr(s,n,e,t,r=()=>null){let o=[];for(let a of s){let i=r(a)??a.body;if(Array.isArray(i))for(let l of Hr(i)){let c=n(l);o.push({player:a.id,side:l.side,x:c.x*e,y:c.y*t,color:An(a.id)})}}return o}function Sn(s,n,e,t=0){let r=s.world,o=js(r,n,e);if(!o)return!1;let a=Math.hypot(r[0],r[1])||1,i=Math.hypot(r[2],r[3])||1,[l,c]=o;if(s.hitRadius!=null){let y=s.hitRadius+t/((a+i)/2);return l*l+c*c<=y*y}let u=-s.anchorX*s.width-t/a,f=-s.anchorY*s.height-t/i,h=(1-s.anchorX)*s.width+t/a,b=(1-s.anchorY)*s.height+t/i;return l>=u&&l<=h&&c>=f&&c<=b}function rr(s,n,e,t=0){for(let r of n)if((e===void 0||r.player===e)&&Sn(s,r.x,r.y,t))return r;return null}function $i(s){switch(s.type){case"circle":case"ring":case"star":return[s.r*2,s.r*2];case"ellipse":return[s.rx*2,s.ry*2];case"roundRect":return[s.w,s.h];case"line":return[s.length,s.lw??4];case"path":return s.r?[s.r*2,s.r*2]:[s.size,s.size]}}function Hi(s){let n=s.type==="line"?0:s.stroke?(s.lw??2)/2:0,e=s.shadow?s.shadow.blur*1.5+Math.max(Math.abs(s.shadow.x??0),Math.abs(s.shadow.y??0)):0;return Math.ceil(n+e+1)}var Ho=(s,n)=>n||!s.shadow?s:{...s,shadow:void 0};function Gr(s,n,e){let t=Hi(n),r=n.type==="roundRect",[o,a]=r?[Math.min(n.w,n.r*2+4/e),Math.min(n.h,n.r*2+4/e)]:$i(n),i=(o+t*2)*e,l=(a+t*2)*e;return{frame:s.bake(i,l,u=>{u.scale(e,e),u.translate(t+o/2,t+a/2),Gi(u,n,o,a)},e,t+o/2,t+a/2,t),slice:r?Math.ceil((n.r+t)*e):0,w:r?n.w:o,h:r?n.h:a}}function Gi(s,n,e,t){s.lineJoin="round",s.lineCap="round";let r=new Path2D;switch(n.type){case"circle":case"ring":r.arc(0,0,n.r,0,Math.PI*2);break;case"ellipse":r.ellipse(0,0,n.rx,n.ry,0,0,Math.PI*2);break;case"roundRect":r.roundRect(-e/2,-t/2,e,t,Math.min(n.r,e/2,t/2));break;case"star":{let c=n.points??5,u=n.r*(n.inner??.5);for(let f=0;f<c*2;f++){let h=f%2?u:n.r,b=-Math.PI/2+f*Math.PI/c;f?r.lineTo(Math.cos(b)*h,Math.sin(b)*h):r.moveTo(Math.cos(b)*h,Math.sin(b)*h)}r.closePath();break}case"line":r.moveTo(-e/2+t/2,0),r.lineTo(e/2-t/2,0);break;case"path":{let c=n.r?n.r*2/n.size:1,u=new DOMMatrix([c,0,0,c,-n.size/2*c,-n.size/2*c]);r.addPath(new Path2D(n.d),u);break}}let o=n.shadow,a=()=>{if(!o)return;let c=s.getTransform();s.shadowColor=o.color,s.shadowBlur=o.blur*c.a,s.shadowOffsetX=(o.x??0)*c.a,s.shadowOffsetY=(o.y??0)*c.a},i=()=>{s.shadowColor="transparent",s.shadowBlur=0};if(n.type==="line"){a(),s.strokeStyle=n.stroke??n.fill??"#fff",s.lineWidth=t,s.stroke(r);return}let l=n.type==="ring";if(n.outlineBelow&&n.fill&&n.stroke&&!l){a(),s.strokeStyle=n.stroke,s.lineWidth=n.lw??2,s.stroke(r),i(),s.fillStyle=n.fill,s.fill(r);return}n.fill&&!l&&(a(),s.fillStyle=n.fill,s.fill(r),i()),(n.stroke||l)&&((!n.fill||l)&&a(),l&&n.fill&&(s.fillStyle=n.fill,s.fill(r)),s.strokeStyle=n.stroke??"#fff",s.lineWidth=n.lw??2,s.stroke(r),i())}var Kt=class{constructor(){p(this,"ctx",null);p(this,"master",null);p(this,"buffers",new Map);p(this,"held",!1);p(this,"muted",!1);p(this,"volume",1);if(typeof addEventListener=="function"){let n=()=>{this.context()?.resume().catch(()=>{})};for(let e of["pointerdown","keydown","touchstart"])addEventListener(e,n,{once:!0,capture:!0})}}context(){if(this.ctx)return this.ctx;let n=globalThis.AudioContext??globalThis.webkitAudioContext;if(!n)return null;try{this.ctx=new n,this.master=this.ctx.createGain(),this.master.connect(this.ctx.destination),this.held&&this.ctx.suspend()}catch{return null}return this.ctx}async load(n,e){let t=this.context();if(!t)return;let r=await(await fetch(e)).arrayBuffer();this.buffers.set(n,await t.decodeAudioData(r))}has(n){return this.buffers.has(n)}play(n,e={}){let t=this.context(),r=this.buffers.get(n);if(!t||!r||!this.audible)return()=>{};let o=t.createBufferSource();o.buffer=r,o.loop=e.loop??!1,o.playbackRate.value=e.rate??1;let a=t.createGain();return a.gain.value=(e.volume??1)*this.volume,o.connect(a).connect(this.master),o.start(),()=>{try{o.stop()}catch{}}}tone(n,e=.25,t={}){let r=this.context();if(!(!r||!this.audible))try{let o=r.createOscillator(),a=r.createGain();o.type=t.type??"sine",o.frequency.setValueAtTime(n,r.currentTime),t.to&&o.frequency.exponentialRampToValueAtTime(t.to,r.currentTime+e),a.gain.setValueAtTime((t.volume??.12)*this.volume,r.currentTime),a.gain.exponentialRampToValueAtTime(.001,r.currentTime+e),o.connect(a).connect(this.master),o.start(),o.stop(r.currentTime+e)}catch{}}get audible(){return!this.muted&&!this.held}hold(){this.held=!0,this.ctx?.suspend().catch(()=>{})}release(){this.held=!1,this.ctx?.resume().catch(()=>{})}destroy(){this.ctx?.close().catch(()=>{}),this.ctx=null}};var Wi={high:{resolution:1.5,particles:1,effects:!0,maxBlur:32},medium:{resolution:1,particles:.5,effects:!1,maxBlur:16},low:{resolution:.75,particles:.2,effects:!1,maxBlur:0}},Ve=["high","medium","low"];function et(s){let n=Wi[s];return{name:s,...n,scale:e=>e<=0?0:Math.max(1,Math.round(e*n.particles))}}var Go=s=>Ve[Math.min(Ve.indexOf(s)+1,Ve.length-1)],sr=(s,n)=>{if(!s.length)return NaN;let e=[...s].sort((t,r)=>t-r);return e[Math.min(e.length-1,Math.max(0,Math.floor(n*(e.length-1)+.5)))]},Wo=12,Vo=s=>Mn(s,.5);function Mn(s,n=.1){let e=sr(s,n);if(!Number.isFinite(e))return 1e3/60;let t=[144,120,90,75,60,50,30],r=60;for(let o of t)Math.abs(1e3/o-e)<Math.abs(1e3/r-e)&&(r=o);return 1e3/r}function or(s,n){let e=n.refresh!==void 0&&Number.isFinite(n.refresh)&&n.refresh>0?n.refresh:Mn(n.intervals),t=sr(n.intervals,.5),r=sr(n.intervals,.9),o=sr(n.cpu,.5);if(!Number.isFinite(t))return s==="canvas2d"?"low":"medium";let a=l=>l<=e*1.25,i=l=>!Number.isFinite(o)||o<e*l;return s==="canvas2d"?a(r)&&i(.25)?"medium":"low":a(r)&&i(.5)?"high":a(t)?"medium":"low"}function Xo(s,n){return s.length<30?!1:s.filter(t=>t>n*1.5).length/s.length>.5}var qo="0.1.1",Vi=720*3600*1e3,jo=(s,n,e)=>`fabi-play.engine-tier:${qo}:${s}:${n}:${e}`,Yo=(s,n,e)=>`fablee-engine-tier:${qo}:${s}:${n}:${e}`;function Ko(s,n,e=Date.now()){try{let t=JSON.parse(s?.getItem(n)??"null");if(t&&Ve.includes(t.tier)&&typeof t.at=="number"&&e-t.at<Vi)return typeof t.refresh=="number"&&t.refresh>0?{name:t.tier,refresh:t.refresh}:{name:t.tier}}catch{}return null}function Wr(s,n,e,t,r=Date.now()){try{s?.setItem(n,JSON.stringify(t!==void 0&&Number.isFinite(t)?{tier:e,at:r,refresh:t}:{tier:e,at:r}))}catch{}}function Qo(s=typeof location<"u"?location.search:""){let n=new URLSearchParams(s).get("tier");return Ve.includes(n)?n:void 0}function Vr(s,n){let e=n?.tier;if(Ve.includes(e))return s==="canvas2d"&&e==="high"?"medium":e}var Xr=s=>typeof s?.hz=="number"&&s.hz>=20&&s.hz<=240?Mn([1e3/s.hz],.5):NaN,qr=(s,n)=>Ve.indexOf(s)>=Ve.indexOf(n)?s:n;function Zo(s,n,e){return s?{name:s,from:"forced"}:n?{name:e?qr(n,e):n,from:"hint"}:e?{name:e,from:"cache"}:null}var Xi=/^\s*(<|>|[^+\-<>=\s][^+=]*?)?\s*(?:([+-])=\s*(\d*\.?\d+))?\s*$/,Qt=class{constructor(n={}){p(this,"steps",[]);p(this,"labels",new Map);p(this,"end",0);p(this,"prevStart",0);p(this,"elapsed",0);p(this,"iter",0);p(this,"last",0);p(this,"delayLeft");p(this,"_paused");p(this,"done",!1);p(this,"rewinding",!1);p(this,"promise");p(this,"resolve");p(this,"repeat");p(this,"yoyo");p(this,"onComplete");this.repeat=Math.floor(n.repeat??0),this.yoyo=!!n.yoyo,this.delayLeft=n.delay??0,this._paused=!!n.paused,this.onComplete=n.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(n){if(n===void 0)return this.end;if(typeof n=="number")return Math.max(n,0);let e=Xi.exec(n);if(!e)throw new Error(`[engine] timeline: bad position "${n}"`);let[,t,r,o]=e,a=o?(r==="-"?-1:1)*Number(o):0,i=this.end;if(t==="<")i=this.prevStart;else if(t&&t!==">"){let l=this.labels.get(t.trim());l===void 0?this.labels.set(t.trim(),this.end):i=l}return Math.max(i+a,0)}add(n){let e=this.steps.length;for(;e>0&&this.steps[e-1].start>n.start;)e--;return this.steps.splice(e,0,n),this.prevStart=n.start,this.end=Math.max(this.end,n.start+n.dur),this}to(n,e,t,r="quadOut"){let o=typeof r=="object"?r:{ease:r},a=typeof o.ease=="function"?o.ease:st[o.ease??"quadOut"];return this.add({target:n,to:e,from:null,fn:null,start:this.at(o.at)+(o.delay??0),dur:Math.max(t,0),ease:a,onUpdate:o.onUpdate,p:-1})}set(n,e,t){return this.add({target:n,to:e,from:null,fn:null,start:this.at(t),dur:0,ease:st.linear,p:-1})}call(n,e){return this.add({target:null,to:null,from:null,fn:n,start:this.at(e),dur:0,ease:st.linear,p:-1})}label(n,e){return this.labels.set(n,this.at(e)),this}wait(n){return this.end+=Math.max(n,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(n){let e=Math.min(typeof n=="string"&&this.labels.has(n)?this.labels.get(n):this.at(n),this.end),t=this.yoyo&&this.iter%2===1;return this.elapsed=this.iter*this.end+(t?this.end-e:e),this.render(e),this}then(n,e){return this.promise.then(n,e)}update(n){if(this._paused||this.done)return;if(this.delayLeft>0){if(this.delayLeft-=n,this.delayLeft>0)return;n=-this.delayLeft,this.delayLeft=0}let e=this.end;if(e<=0)return this.render(0),this.complete();this.elapsed+=n;let t=this.repeat<0?1/0:e*(this.repeat+1),r=Math.min(this.elapsed,t),o=r>=t?this.repeat:Math.floor(r/e);for(;this.iter<o;){let i=this.yoyo&&this.iter%2===1;this.render(i?0:e),this.iter++,this.yoyo||(this.rewinding=!0,this.render(0),this.rewinding=!1)}let a=r-o*e;this.render(this.yoyo&&o%2===1?e-a:a),r>=t&&this.complete()}complete(){this.done||(this.done=!0,this.onComplete?.(),this.resolve())}render(n){let e=this.steps;if(n>=this.last)for(let t=0;t<e.length;t++){let r=e[t];n>=r.start&&this.apply(r,n)}else for(let t=e.length-1;t>=0;t--){let r=e[t];r.p>=0&&this.apply(r,n)}this.last=n}apply(n,e){let t=n.dur>0?Math.min(Math.max((e-n.start)/n.dur,0),1):e>n.start||e===n.start&&!this.rewinding?1:0;if(t===n.p)return;if(n.p=t,n.fn){this.rewinding||n.fn();return}let r=n.target;if(r.destroyed||r._free)return;let o=n.to;if(!n.from){n.from={};for(let i in o)n.from[i]=Number(r[i]??0)}let a=n.ease(t);for(let i in o)r[i]=n.from[i]+(o[i]-n.from[i])*a;n.onUpdate?.(a)}};var Zt=class{constructor(){p(this,"list",[]);p(this,"timelines",[])}timeline(n){let e=new Qt(n);return this.timelines.push(e),e}tween(n,e,t,r="quadOut"){let o=typeof r=="object"?r:{ease:r},a=typeof o.ease=="function"?o.ease:st[o.ease??"quadOut"],i,l=new Promise(c=>{let u=Object.keys(e),f=new Float64Array(u.length);u.forEach((h,b)=>f[b]=Number(e[h])),i={target:n,keys:u,to:f,from:new Float64Array(u.length),started:!1,duration:Math.max(t,0),time:0,delay:o.delay??0,ease:a,onUpdate:o.onUpdate,done:c,dead:!1}});return this.list.push(i),Object.assign(l,{stop:()=>this.finish(i)})}stopAll(n){let e=this.list;for(let t=0;t<e.length;t++)e[t].target===n&&this.finish(e[t])}get size(){return this.list.length}update(n){if(this.timelines.length){let r=0,o=this.timelines;for(let a=0;a<o.length;a++){let i=o[a];i.update(n),i.finished||(o[r++]=i)}o.length=r}let e=this.list;if(!e.length)return;let t=0;for(let r=0;r<e.length;r++){let o=e[r];o.dead||this.step(o,n),o.dead||(e[t++]=o)}t!==e.length&&(e.length=t)}step(n,e){if(n.target.destroyed)return this.finish(n);let t=e;if(n.delay>0){if(n.delay-=e,n.delay>0)return;t=-n.delay}let r=n.keys;if(!n.started){n.started=!0;for(let i=0;i<r.length;i++)n.from[i]=Number(n.target[r[i]]??0)}n.time+=t;let o=n.duration>0?Math.min(n.time/n.duration,1):1,a=n.ease(o);for(let i=0;i<r.length;i++)n.target[r[i]]=n.from[i]+(n.to[i]-n.from[i])*a;n.onUpdate?.(a),o>=1&&this.finish(n)}finish(n){n.dead||(n.dead=!0,n.done())}clear(){for(let n of this.list)this.finish(n);this.list.length=0;for(let n of this.timelines)n.stop();this.timelines=[]}};var ae=720,Tn=class extends Fe{constructor(e,t){super(e);p(this,"paintAll",t)}draw(e,t){this.paintAll(e,t)}},Yr=class extends Fe{constructor(e,t){super(e);p(this,"paintAll",t)}draw(e,t){this.paintAll(e,t)}},ut=()=>performance.now();async function ea(s={}){let n=s.play??null,e=s.canvas??null;e||(e=document.createElement("canvas"),e.style.cssText="position:fixed;inset:0;width:100%;height:100%;display:block;touch-action:none",document.body.appendChild(e));let t=Vt(e,{renderer:s.renderer??Do(),failIfMajorPerformanceCaveat:s.failIfMajorPerformanceCaveat,instancing:s.instancing});e=t.canvas;let r=new Set,o=new at(Math.min(2048,t.maxTextureSize),4);o.onPage=k=>r.add(k),o.onDrop=k=>{r.delete(k),k.texture&&t.destroyTexture(k.texture),k.texture=null};let a=wn(t),i=new Zt,l=new Kt,c=new wt(o),u=new Map,f=new Map,h=new Map,b=new Map,y=new Map,m=new Set,d=0,x=s.tier??Qo(),g=String(t.info.renderer??""),M=(()=>{try{return globalThis.localStorage??null}catch{return null}})(),v=typeof screen<"u"?`${screen.width}x${screen.height}`:"",A=jo(t.kind,g,v);Rs(M,A,Yo(t.kind,g,v));let E=Ko(M,A),C=Zo(x,Vr(t.kind,n?.device),E?.name),P=C?.name??"medium",L=et(P);c.setTier(P);let I=C?.from==="hint",U=E?.name,X=E?.refresh??Xr(n?.device),H=1,fe=1,$=1,ne={atlas:o,get pixelScale(){return H},get fontGen(){return d},get effects(){return L.effects},tweens:i,frame:k=>Pn.frame(k),shape:k=>{let S=L.effects,F=S?H:-H,R=u.get(F);R||(u.size>=8&&u.clear(),u.set(F,R=new $t(2e3)));let B=De(k),ee=R.get(k,B);return(!ee||!o.valid(ee.frame))&&R.set(k,ee=Gr(o,Ho(k,S),H),B),ee},bitmapFont:k=>Pn.bitmapFont(k)},pe=1280,_e=null;class cr extends vt{get width(){return pe}set width(S){}get height(){return ae}set height(S){}get safe(){let S=Math.min(pe,ae*16/9);return{x:(pe-S)/2,y:0,w:S,h:ae}}}let xe=new cr(ne),Pe=()=>{let k=t.canvas,S=k.getBoundingClientRect();fe=Math.max(1,S.width||k.clientWidth||innerWidth),$=Math.max(1,S.height||k.clientHeight||innerHeight),pe=ae*fe/$;let F=Math.min(globalThis.devicePixelRatio||1,s.maxPixelRatio??2);if($*F/ae<=L.resolution){let B=Math.max(1,Math.round($*F));H=B/ae,t.resize(Math.max(1,Math.round(fe*F)),B)}else H=L.resolution,t.resize(Math.round(pe*H),Math.round(ae*H));_e&&_e.style.setProperty("--unit",`${$/ae}px`)};addEventListener("resize",Pe);let ge=k=>{P=k,L=et(k),c.setTier(k),Pe()},ie=typeof ResizeObserver<"u"?new ResizeObserver(Pe):null;ie?.observe(e);let Le=n?.backdrop==="video"?"video":"none",w=n?.view??null,N=[],D=-1/0,q=!1,G=!1,se=new Set,Mt=()=>{let k=Le==="video"?"transparent":"";document.documentElement.style.background=k,document.body.style.background=k},qe=(k,S)=>{let F=k==="video"?"video":"none",R=S??null;if(!(F===Le&&(R===w||R&&w&&R.x===w.x&&R.y===w.y&&R.w===w.w&&R.h===w.h))){Le=F,w=R,Mt();for(let B of[...se])B(Le,w)}},Jt=[];if(n){let k=R=>{Array.isArray(R)&&(N=R,D=ut())},S=R=>{q=R,Ie()},F=R=>{if(x||I)return;Number.isFinite(X)||(X=Xr(R));let B=Vr(t.kind,R);B&&(I=!0,ge(U?qr(B,U):B))};Jt.push(n.on("start",R=>F(R?.device)),n.on("frame",R=>k(R?.players)),n.on("players",R=>k(R?.players)),n.on("backdrop",R=>qe(R?.backdrop,R?.view)),n.on("start",R=>qe(R?.backdrop,R?.view??n.view)),n.on("pause",()=>S(!0)),n.on("resume",()=>S(!1)),n.on("break-start",()=>S(!0)),n.on("break-done",()=>S(!1)),n.on("break-end",()=>S(!1))),l.muted=n.muted===!0}Mt();let Ie=()=>q||G||document.hidden?l.hold():l.release(),Tt=-1,ze=[],je=0,Et=()=>ut()-D<1e3?N:[],en=k=>n?n.toScreen(k):Es(w,k),ht=()=>{if(Tt===je)return ze;Tt=je;let k=Le==="video"||!n?.smoothedBody?()=>null:S=>n.smoothedBody(S);return ze=nr(Et(),en,pe,ae,k),ze},tn={x:0,y:0,w:1,h:1},wa=()=>(tn.x=w?w.x*pe:0,tn.y=w?w.y*ae:0,tn.w=w?w.w*pe:pe,tn.h=w?w.h*ae:ae,tn),Aa=k=>{let S=k.alpha??1,F=k.tags?new ct(o,k):null;F&&m.add(F);let R=typeof k.tags=="function"?k.tags:B=>String(B);return(B,ee)=>{if(Le==="video")return;let z=wa();for(let W of Et()){let le=n?.smoothedBody?.(W)??W.body,Q=Lt(n?.avatarOf?.(W)??W.avatar??"")??yt;if(!c.draw(B.r,B.tex,le,Q,z,S*ee,H)||!F)continue;let Ee=R(W.id);Ee&&F.draw(B.r,B.tex,le,Q,z,Ee,An(W.id),S*ee,H,pe,ae)}}},ur=new Set,hr=new Set,nn=new Set,Rn=!1,fr=0,Rt=0,Fn=0,ft={fps:0,cpuMs:0,drawCalls:0,quads:0,filtersSkipped:0},Cn=0,pr=0,dr=ut(),rn=[],_n=0,ys=()=>({r:t,kernel:ne,tex:a}),xs=ys(),Sa=()=>{if(t.lost)return;let[k,S]=Le==="video"||s.background===void 0?[0,0]:he(s.background);t.time=Fn,t.maxBlur=L.maxBlur,t.begin(k,S,H),we(xe.world,null,xe.x,xe.y,xe.rotation,xe.scaleX,xe.scaleY),Cr(xs,xe,xe.alpha,xe.tint);let F=t.end();ft.drawCalls=F.drawCalls,ft.quads=F.quads,ft.filtersSkipped=F.filtersSkipped},gs=k=>{if(!Rn)return;fr=requestAnimationFrame(gs);let S=Math.min(Math.max((k-Rt)/1e3,0),.1);Rt&&rn.push(k-Rt),Rt=k,je++;let F=ut(),R=q||G;if(!R){Fn+=S,i.update(S);for(let B of nn)B.destroyed||B.update(S);for(let B of ur)B(S,Fn)}for(let B of hr)B(S);xe.sweep();for(let B of nn)B.destroyed&&nn.delete(B);if(t.lost?(_n||(_n=k),k-_n>3e3&&Ma()):(_n=0,Sa()),Cn++,pr+=ut()-F,F-dr>=1e3&&(ft.fps=Math.round(Cn*1e3/(F-dr)),ft.cpuMs=Math.round(pr/Math.max(Cn,1)*100)/100,n?.reportStats?.({fps:ft.fps,renderer:t.kind,tier:P}),Cn=0,pr=0,dr=F),rn.length>=180){let B=Number.isFinite(X)?X:Mn(rn);!x&&!R&&Xo(rn,B)&&P!=="low"&&(ge(Go(P)),U=P,Wr(M,A,P,Number.isFinite(X)?X:void 0),console.info(`[engine] slow frames: tier ${P}`)),rn.length=0}},Ma=()=>{let k=vn(t.canvas),S=Gt(k);if(S){console.warn("[engine] WebGL context lost for good: switching to Canvas 2D"),t.destroy(),t=S;for(let F of r)F.texture=null;for(let F of o.pages)r.add(F.surface);a=wn(t),xs=ys(),ie?.disconnect(),ie?.observe(k),Pe()}},ks=()=>{Ie(),document.hidden||(Rt=0)};document.addEventListener("visibilitychange",ks);let vs=()=>{d++;for(let k of m)k.drop()};if(document.fonts?.addEventListener?.("loadingdone",vs),Pe(),!C&&s.probe!==!1&&(Number.isFinite(X)||(X=Vo(await qi(Wo))),!I)){L=et("high"),Pe();let k=await ji(t,o,()=>a,()=>H,pe,()=>I);if(k.refresh=X,!I){let S=or(t.kind,k);Wr(M,A,S,X),U=S,ge(S)}}let Pn={stage:xe,get tier(){return L},get renderer(){return t},get canvas(){return t.canvas},get pixelScale(){return H},get backdrop(){return Le},get view(){return w},get paused(){return q||G},sound:l,stats:ft,get time(){return Fn},get supports(){let k=t.support;return{filters:k.filters,blur:k.filters&&L.maxBlur>0,shaders:k.shaders,maxBlur:k.filters?L.maxBlur:0,tiers:{high:{maxBlur:et("high").maxBlur},medium:{maxBlur:et("medium").maxBlur},low:{maxBlur:et("low").maxBlur}}}},sprite:(k,S)=>new Se(ne,k,S),shape:(k,S)=>new $e(ne,k,S),text:(k,S)=>new We(ne,k,S),group:k=>new vt(ne).set(k??{}),particles(k,S={}){let F=typeof k=="object"&&"type"in k?ne.shape(k).frame:k,R=new Ot(ne,F,S),{max:B,blend:ee,gravity:z,drag:W,...le}=S;return R.set(le),nn.add(R),R},tween:(k,S,F,R)=>i.tween(k,S,F,R),bake(k,S,F,R,B){return h.set(k,{w:S,h:F,draw:R,origin:B}),f.delete(k),Pn.frame(k)},frame(k){let S=f.get(k);if(S&&o.valid(S)&&(S.gen===0||S.scale===H))return S;let F=h.get(k);if(F){let R=H,B=o.bake(F.w*R,F.h*R,ee=>(ee.scale(R,R),F.draw(ee)),R,F.origin?.x??0,F.origin?.y??0);return f.set(k,B),B}if(S)return S;throw new Error(`[engine] no frame "${k}": load it or bake it first`)},async load(k){await Promise.all(Object.entries(k).map(([S,F])=>Ea(S,F)))},hands:k=>k===void 0?ht():ht().filter(S=>S.player===k),touched(k,S,F={}){return k.updateWorld(),rr(k,ht(),S,F.padding??0)},hits(k,S,F,R=0){return k.updateWorld(),Sn(k,S,F,R)},avatars:(k={})=>new Tn(ne,Aa(k)),handMarkers(k={}){let S=k.radius??36,F=k.look??"auto",R=new Float64Array(6),B=Math.max(S*.12,3),ee={type:"ring",r:S,lw:B,fill:"rgba(251,231,184,0.3)",stroke:"#ffffff"},z={type:"ring",r:S,lw:B*1.8,stroke:At,shadow:{color:At,blur:S*.2}},W=(pt,ke,Ft,mr,Ln,dt)=>{let Nn=ke.w/ke.scale;we(R,null,Ft-Nn/2,mr-Nn/2,0,1,1),pt.r.quad(pt.tex(ke.surface),ke,R,Nn,Nn,Ln,dt,"normal")},le=pt=>{let ke=null,Ft=!1;return()=>(ke&&o.valid(ke.frame)&&ke.frame.scale===H&&Ft===L.effects?ke:(Ft=L.effects,ke=ne.shape(pt))).frame},Q=le(ee),Ee=le(z);return new Yr(ne,(pt,ke)=>{let Ft=F==="video"||F==="auto"&&Le==="video",mr=Q(),Ln=Ft?Ee():null;for(let dt of ht())Ln&&W(pt,Ln,dt.x,dt.y,16777215,ke),W(pt,mr,dt.x,dt.y,he(dt.color)[0],ke)})},timeline:k=>i.timeline(k),animation(k,S){let F=typeof k=="string"?Ta(k):{frames:k},R=new Ce(ne,F,S);return nn.add(R),R},bitmapFont(k,S){if(!S){let R=b.get(k);if(!R)throw new Error(`[engine] no bitmap font "${k}": load or make it first`);return R}let F="data"in S?ws(Yt(S.data),S.pages):$o(ne,S);return b.set(k,F),F},players:()=>Et(),onFrame(k){return ur.add(k),()=>{ur.delete(k)}},onRender(k){return hr.add(k),()=>{hr.delete(k)}},onBackdrop(k){return se.add(k),()=>{se.delete(k)}},get hud(){return _e||(_e=document.createElement("div"),_e.style.cssText="position:fixed;inset:0;pointer-events:none;overflow:hidden",document.body.appendChild(_e),Pe()),_e},random:(k=0,S=1)=>k+Math.random()*(S-k),start(){Rn||(Rn=!0,Rt=0,fr=requestAnimationFrame(gs))},pause(){G=!0,Ie()},resume(){G=!1,Ie()},destroy(){Rn=!1,cancelAnimationFrame(fr),Jt.forEach(k=>k()),removeEventListener("resize",Pe),ie?.disconnect(),document.removeEventListener("visibilitychange",ks),document.fonts?.removeEventListener?.("loadingdone",vs),i.clear(),lo(ne),l.destroy(),t.destroy(),_e?.remove()}};function Ta(k){let S=y.get(k);if(S)return S;let F=[...new Set([...f.keys(),...h.keys()])].filter(R=>R.startsWith(k)).sort(uo);if(!F.length)throw new Error(`[engine] no animation or frames "${k}\u2026"`);return{frames:F}}async function Ea(k,S){let F=S.split("?")[0].split(".").pop().toLowerCase();if(["mp3","ogg","wav","m4a","aac","webm"].includes(F))return l.load(k,S);if(["woff","woff2","ttf","otf"].includes(F)){let z=new FontFace(k,`url(${S})`);document.fonts.add(await z.load()),d++;return}let R=new URL(S,location.href);if(F==="fnt")return As(k,Yt(await(await fetch(S)).text()),R);if(F==="json"){let z=await(await fetch(S)).json();if(Array.isArray(z.chars)&&!z.frames)return As(k,Yt(z),R);let W=await jr(new URL(z.meta?.image??S.replace(/\.json$/,".png"),R).href);Ra(k,z,It(W));return}let B=await jr(S),ee=It(B);r.add(ee),f.set(k,{surface:ee,x:0,y:0,w:B.width,h:B.height,scale:1,gen:0,ox:0,oy:0,margin:0})}function ws(k,S){return Uo(k,S.map(F=>{let R=It(F);return r.add(R),R}))}async function As(k,S,F){b.set(k,ws(S,await Promise.all(S.pages.map(R=>jr(new URL(R,F).href)))))}function Ra(k,S,F){r.add(F);let R=Array.isArray(S.frames)?S.frames:Object.entries(S.frames).map(([z,W])=>({...W,filename:z})),B=[],ee=[];for(let z of R){let W=z.frame,le=z.filename.replace(Jo,"");z.rotated&&console.warn(`[engine] ${k}/${le} is rotated: export without rotation`);let Q={surface:F,x:W.x,y:W.y,w:W.w,h:W.h,scale:1,gen:0,ox:0,oy:0,margin:0};z.trimmed&&z.sourceSize&&z.spriteSourceSize&&(Q.sw=z.sourceSize.w,Q.sh=z.sourceSize.h,Q.tx=z.spriteSourceSize.x,Q.ty=z.spriteSourceSize.y);let Ee=z.scale9Borders;Ee&&(Q.slice=[Ee.y,(Q.sw??W.w)-Ee.x-Ee.w,(Q.sh??W.h)-Ee.y-Ee.h,Ee.x]),f.set(`${k}/${le}`,Q),B.push(`${k}/${le}`),ee.push((z.duration??0)/1e3)}for(let[z,W]of Object.entries(S.animations??{}))y.set(`${k}/${z}`,{frames:W.map(le=>`${k}/${le.replace(Jo,"")}`)});for(let z of S.meta?.frameTags??[]){let W=[];for(let Q=z.from;Q<=z.to;Q++)W.push(Q);z.direction==="reverse"&&W.reverse(),z.direction==="pingpong"&&W.push(...W.slice(1,-1).reverse());let le=W.every(Q=>ee[Q]>0);y.set(`${k}/${z.name}`,{frames:W.map(Q=>B[Q]),...le?{durations:W.map(Q=>ee[Q])}:{}})}}return Pn}var Jo=/\.(png|webp|jpe?g|gif|bmp)$/i;function jr(s){return new Promise((n,e)=>{let t=new Image;t.onload=()=>n(t),t.onerror=()=>e(new Error(`[engine] image did not load: ${s}`)),t.src=s})}function qi(s){return new Promise(n=>{let e=[],t=0,r=o=>{t&&e.push(o-t),t=o,e.length<s?requestAnimationFrame(r):n(e)};requestAnimationFrame(r)})}async function ji(s,n,e,t,r,o=()=>!1){let a=t(),i=Gr(n,{type:"star",r:30,fill:"#ffd23f",stroke:"#3a2a10",lw:3},a).frame,l=[],c=[],u=new Float64Array(6),f=.004,h=s.kind==="canvas2d"?s.canvas.getContext("2d"):null,b=ut(),y=0;return await new Promise(m=>{let d=x=>{y&&x-b>250&&l.push(x-y),y=x;let g=ut();s.begin(0,0,a);let M=e();for(let v=0;v<300;v++){let A=x/1e3+v;we(u,null,v*37%r,v*53%ae,A,1,1),s.quad(M(i.surface),i,u,i.w/a,i.h/a,16777215,f,"normal")}for(let v=0;v<40;v++)s.ellipse(100+v*20,300,20,14,v,16746496,f),s.stroke([100+v*20,400,120+v*20,460,100+v*20,520],3,18,3368703,f,!1);s.end(),h?.getImageData(0,0,1,1),x-b>250&&c.push(ut()-g),x-b<750&&!o()?requestAnimationFrame(d):(s.begin(0,0,a),s.end(),m())};requestAnimationFrame(d)}),{intervals:l,cpu:c}}var Yi=64,ta=32,Ki=0,Qi=`fabi-cm-${Math.random().toString(36).slice(2,7)}-`,na=new Set,ra=(s,n)=>{na.has(s)||(na.add(s),console.warn(n))},sa=s=>new Kr(s),Kr=class{constructor(n){p(this,"r",n);p(this,"css","none");p(this,"plans",new $t(Yi));p(this,"buf",new Float64Array(64));p(this,"keys",[]);p(this,"classes",new Map);p(this,"live",new Set);p(this,"svgs",new Map);p(this,"t",0);p(this,"cur",null);p(this,"svgFn",n=>this.svg(n));p(this,"scr",[]);p(this,"flip",0)}chain(n,e){var y;let t=this.r,r=this.buf;r[0]=t.scale,r[1]=t.maxBlur;let o=2;for(let m=0;m<e.length;m++){let d=e[m];if(o+22>r.length){let g=new Float64Array(r.length*2);g.set(r),r=this.buf=g}let x=this.classes.get(d.constructor);x===void 0&&this.classes.set(d.constructor,x=this.classes.size),r[o++]=x,r[o++]=d.enabled?1:0,d.params&&(o=d.params(r,o))}let a=(y=this.keys)[o]??(y[o]=new Float64Array(o));for(let m=0;m<o;m++)a[m]=r[m];let i=De(a),l=this.plans.get(a,i);l||this.plans.set(a,l=this.plan(e),i);for(let m=0;m<l.svgs.length;m++){let d=l.svgs[m];d.used<0&&this.attach(d),d.used=this.t}t.skipped+=l.skip;let c=n,u=t.rx0,f=t.ry0,h=t.rx1-u,b=t.ry1-f;for(let m=0;m<l.paints.length;m++)l.parts[m]&&(c=this.bake(c,l.parts[m])),e[l.paints[m]].paint2d(c.getContext("2d"),u,f,h,b);return this.css=l.parts[l.paints.length]||"none",c}tick(){let n=++this.t;if(!(n%ta||!this.live.size))for(let e of this.live)n-e.used>ta&&this.detach(e)}destroy(){for(let n of this.live)this.detach(n);this.plans.clear()}svg(n){if(typeof document>"u"||!document.body)return null;let e=Array.from({length:20},(r,o)=>n[o]??0).join(" "),t=this.svgs.get(e);if(!t){let r="http://www.w3.org/2000/svg",o=document.createElementNS(r,"svg");o.setAttribute("width","0"),o.setAttribute("height","0"),o.setAttribute("aria-hidden","true"),o.style.position="absolute";let a=document.createElementNS(r,"filter"),i=Qi+ ++Ki;a.setAttribute("id",i),a.setAttribute("color-interpolation-filters","sRGB");let l=document.createElementNS(r,"feColorMatrix");l.setAttribute("type","matrix"),l.setAttribute("values",e),a.append(l),o.append(a),this.attach(t={key:e,id:i,el:o,used:this.t})}return this.cur.svgs.push(t),`url(#${t.id})`}attach(n){document.body.append(n.el),this.live.add(n),this.svgs.has(n.key)||this.svgs.set(n.key,n)}detach(n){n.el.remove(),n.used=-1,this.live.delete(n),this.svgs.get(n.key)===n&&this.svgs.delete(n.key)}plan(n){let e=this.r,t=this.cur={parts:[],paints:[],skip:0,svgs:[]},r="";for(let o=0;o<n.length;o++){let a=n[o];if(!a.enabled)continue;if(a.kind===4){t.skip++,ra("shader","[engine] shader() filters are WebGL only: on Canvas 2D they are skipped (check engine.supports.shaders)");continue}let i=e.support.filters&&a.css?a.css(e.scale,e.maxBlur,this.svgFn):null;i!==null?r+=r?` ${i}`:i:a.paint2d?(t.parts.push(r),t.paints.push(o),r=""):(t.skip++,ra("css","[engine] this browser's Canvas 2D has no ctx.filter: colour filters, blur and shadows are skipped (tint works; check engine.supports.filters)"))}return t.parts.push(r),t}bake(n,e){let t=this.r,r=this.flip^=1,o=this.scr[r];(!o||o.width!==t.canvas.width||o.height!==t.canvas.height)&&(o=this.scr[r]=document.createElement("canvas"),o.width=t.canvas.width,o.height=t.canvas.height);let a=o.getContext("2d"),i=t.rx0,l=t.ry0,c=t.rx1-i,u=t.ry1-l;return a.clearRect(i,l,c,u),a.filter=e,a.drawImage(n,i,l,c,u,i,l,c,u),a.filter="none",o}};var Zi=64,ar=17,Ji=s=>`${Zn}
|
|
48
|
+
}`,Ui={alpha:!0,premultipliedAlpha:!0,antialias:!1,depth:!1,stencil:!1,preserveDrawingBuffer:!1,powerPreference:"high-performance"},Wi=["aCorner","aP01","aP23","aUvRect","aColor","aSlot"],Vi=["aPos","aUv","aColor","aSlot"];function Ho(s,n,e={}){let t={...Ui,failIfMajorPerformanceCaveat:e.failIfMajorPerformanceCaveat!==!1},r=n===2?s.getContext("webgl2",t):s.getContext("webgl",t)??s.getContext("experimental-webgl",t);if(!r||r.isContextLost())return null;try{return new Or(s,r,n,e)}catch(o){return console.warn("[engine] WebGL setup failed:",o),r.getExtension("WEBGL_lose_context")?.loseContext(),null}}var Or=class extends Vt{constructor(e,t,r,o){super();p(this,"canvas",e);p(this,"gl",t);p(this,"opts",o);p(this,"kind");p(this,"maxTextureSize");p(this,"support",{filters:!0,shaders:!0});p(this,"features",{});p(this,"info",{});p(this,"lost",!1);p(this,"main");p(this,"cur");p(this,"unit",-1);p(this,"onUnit",new Array(Oo).fill(void 0));p(this,"fbNow");p(this,"mapped",!0);p(this,"calls",{useProgram:0,bindTexture:0,activeTexture:0,bindFramebuffer:0});p(this,"vsrc","");p(this,"attrs",[]);p(this,"fxr",null);p(this,"batch");p(this,"dynamic");p(this,"staticBuf",null);p(this,"index");p(this,"vao",null);p(this,"inst",null);p(this,"vaoApi",null);p(this,"uScale",null);p(this,"textures",new Map);p(this,"kit");p(this,"stats",{drawCalls:0,quads:0,filtersSkipped:0});p(this,"lostListeners",[]);p(this,"restoredListeners",[]);p(this,"tris",new Int32Array(192));p(this,"sU",0);p(this,"sV0",0);p(this,"sV1",0);p(this,"sColor",0);p(this,"sPacked",0);p(this,"sAlpha",0);p(this,"sHw",0);p(this,"strokeSeg",()=>{let e=this.q;e.set(kn),e[8]=e[10]=this.sU,e[9]=this.sV0,e[11]=this.sV1,e[12]=this.sPacked,this.put(this.kit)});p(this,"strokeDisc",()=>this.ellipse(kn[0],kn[1],this.sHw,this.sHw,0,this.sColor,this.sAlpha));p(this,"q",new Float64Array(13));p(this,"layers",[]);p(this,"layerTex",new Map);p(this,"bScis",!1);p(this,"bx0",0);p(this,"by0",0);p(this,"bx1",0);p(this,"by1",0);p(this,"onContextLost",e=>{e.preventDefault(),this.lost=!0;for(let t of this.lostListeners)t()});p(this,"onContextRestored",()=>{try{this.layers=[],this.layerTex.clear(),this.fxr=null,this.resetLayers(this.scale),this.setup();for(let e of this.textures.keys())this.textures.set(e,this.upload(e.source));this.lost=!1;for(let e of this.restoredListeners)e()}catch(e){console.warn("[engine] WebGL restore failed:",e)}});p(this,"views",new Map);this.kind=r===2?"webgl2":"webgl1",this.maxTextureSize=t.getParameter(t.MAX_TEXTURE_SIZE),this.setup(),this.kit=this.createTexture(Do()),Ee.live=this,e.addEventListener("webglcontextlost",this.onContextLost,!1),e.addEventListener("webglcontextrestored",this.onContextRestored,!1)}setup(){let e=this.gl,t=this.kind==="webgl2"?e:null;if(this.inst=null,this.opts.instancing!==!1)if(t)this.inst={divisor:(f,h)=>t.vertexAttribDivisor(f,h),draw:(f,h)=>t.drawElementsInstanced(e.TRIANGLES,f,e.UNSIGNED_SHORT,0,h)};else{let f=e.getExtension("ANGLE_instanced_arrays");f&&(this.inst={divisor:(h,b)=>f.vertexAttribDivisorANGLE(h,b),draw:(h,b)=>f.drawElementsInstancedANGLE(e.TRIANGLES,h,e.UNSIGNED_SHORT,0,b)})}if(this.vaoApi=null,this.opts.vao!==!1)if(t)this.vaoApi={create:()=>t.createVertexArray(),bind:f=>t.bindVertexArray(f),remove:f=>t.deleteVertexArray(f)};else{let f=e.getExtension("OES_vertex_array_object");f&&(this.vaoApi={create:()=>f.createVertexArrayOES(),bind:h=>f.bindVertexArrayOES(h),remove:h=>f.deleteVertexArrayOES(h)})}let r=e.getParameter(e.MAX_TEXTURE_IMAGE_UNITS),o=Math.max(1,Math.min(Oo,r)),a=this.inst!==null;this.vsrc=a?Gi:$i,this.attrs=a?Wi:Vi,this.main=this.cur=this.build(Hi(o));let i=this.main.p;e.useProgram(i),this.calls.useProgram++,this.unit=-1,this.onUnit.fill(void 0),this.fbNow=void 0,this.uScale=this.main.uScale,e.uniform1iv(e.getUniformLocation(i,"uTex"),Int32Array.from({length:o},(f,h)=>h)),this.batch=new Wn(a,o),this.vaoApi&&(this.vao=this.vaoApi.create(),this.vaoApi.bind(this.vao)),this.dynamic=e.createBuffer(),e.bindBuffer(e.ARRAY_BUFFER,this.dynamic),e.bufferData(e.ARRAY_BUFFER,this.batch.f32.byteLength,e.DYNAMIC_DRAW),this.index=e.createBuffer(),e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,this.index),e.bufferData(e.ELEMENT_ARRAY_BUFFER,Ao(a?1:8192),e.STATIC_DRAW);let l=f=>e.getAttribLocation(i,f),c=(f,h,b,y,m,d,x)=>{let g=l(f);g<0||(e.enableVertexAttribArray(g),e.vertexAttribPointer(g,h,b,y,m,d),this.inst&&this.inst.divisor(g,x))};if(a){let f=56;c("aP01",4,e.FLOAT,!1,f,0,1),c("aP23",4,e.FLOAT,!1,f,16,1),c("aUvRect",4,e.FLOAT,!1,f,32,1),c("aColor",4,e.UNSIGNED_BYTE,!0,f,48,1),c("aSlot",1,e.FLOAT,!1,f,52,1),this.staticBuf=e.createBuffer(),e.bindBuffer(e.ARRAY_BUFFER,this.staticBuf),e.bufferData(e.ARRAY_BUFFER,Float32Array.of(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1),e.STATIC_DRAW),c("aCorner",4,e.FLOAT,!1,16,0,0),e.bindBuffer(e.ARRAY_BUFFER,this.dynamic)}else{let f=24;c("aPos",2,e.FLOAT,!1,f,0,0),c("aUv",2,e.FLOAT,!1,f,8,0),c("aColor",4,e.UNSIGNED_BYTE,!0,f,16,0),c("aSlot",1,e.FLOAT,!1,f,20,0)}e.enable(e.BLEND),e.blendFunc(e.ONE,e.ONE_MINUS_SRC_ALPHA),e.disable(e.DEPTH_TEST),e.disable(e.CULL_FACE),e.pixelStorei(e.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!0);let u=e.getExtension("WEBGL_debug_renderer_info");this.info={version:e.getParameter(e.VERSION),renderer:u?e.getParameter(u.UNMASKED_RENDERER_WEBGL):e.getParameter(e.RENDERER),vendor:u?e.getParameter(u.UNMASKED_VENDOR_WEBGL):e.getParameter(e.VENDOR)},this.features={instancing:a,vao:this.vaoApi!==null,textureSlots:o,maxTextureSize:this.maxTextureSize}}upload(e){let t=this.gl,r=t.createTexture();return this.bindTex(r),t.texImage2D(t.TEXTURE_2D,0,t.RGBA,t.RGBA,t.UNSIGNED_BYTE,e),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.LINEAR),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.LINEAR),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE),r}resize(e,t){this.canvas.width!==e&&(this.canvas.width=e),this.canvas.height!==t&&(this.canvas.height=t)}createTexture(e){let t={id:dn(),width:e.width,height:e.height,source:e};return this.textures.set(t,this.lost?null:this.upload(e)),t}updateTexture(e,t,r=0,o=0){if(this.lost)return;this.batch.has(e)&&this.flush();let a=this.gl,i=this.textures.get(e);i&&(this.bindTex(i),!t||t===e.source&&r===0&&o===0?a.texImage2D(a.TEXTURE_2D,0,a.RGBA,a.RGBA,a.UNSIGNED_BYTE,e.source):a.texSubImage2D(a.TEXTURE_2D,0,r,o,a.RGBA,a.UNSIGNED_BYTE,t))}destroyTexture(e){this.batch.has(e)&&this.flush();let t=this.textures.get(e);t&&!this.lost&&this.deleteTex(t),this.textures.delete(e)}begin(e,t,r){if(this.stats.drawCalls=this.stats.quads=this.stats.filtersSkipped=0,this.batch.reset(),this.resetLayers(r),this.bScis=!1,this.lost)return;let o=this.gl;o.disable(o.SCISSOR_TEST),this.bindFb(null),o.viewport(0,0,this.canvas.width,this.canvas.height);let a=t;o.clearColor((e>>16&255)/255*a,(e>>8&255)/255*a,(e&255)/255*a,a),o.clear(o.COLOR_BUFFER_BIT),this.use(this.main),o.uniform2f(this.uScale,2*r/this.canvas.width,-2*r/this.canvas.height),this.mapped=!0}build(e){let t=this.gl,r=zo(t,t.VERTEX_SHADER,this.vsrc),o;try{o=zo(t,t.FRAGMENT_SHADER,e)}catch(i){throw t.deleteShader(r),i}let a=t.createProgram();if(t.attachShader(a,r),t.attachShader(a,o),this.attrs.forEach((i,l)=>t.bindAttribLocation(a,l,i)),t.linkProgram(a),t.deleteShader(r),t.deleteShader(o),!t.getProgramParameter(a,t.LINK_STATUS)){let i=t.getProgramInfoLog(a)??"?";throw t.deleteProgram(a),new Error(`link: ${i}`)}return{p:a,uScale:t.getUniformLocation(a,"uScale"),locs:new Map}}u(e,t){let r=e.locs.get(t);return r===void 0&&e.locs.set(t,r=this.gl.getUniformLocation(e.p,t)),r}use(e){this.cur!==e&&(this.cur=e,this.gl.useProgram(e.p),this.calls.useProgram++)}bindTex(e,t=this.unit<0?0:this.unit){let r=this.gl;this.onUnit[t]!==e&&(this.unit!==t&&(r.activeTexture(r.TEXTURE0+t),this.calls.activeTexture++,this.unit=t),r.bindTexture(r.TEXTURE_2D,e),this.calls.bindTexture++,this.onUnit[t]=e)}deleteTex(e){this.gl.deleteTexture(e);for(let t=0;t<this.onUnit.length;t++)this.onUnit[t]===e&&(this.onUnit[t]=null)}bindFb(e){if(e)for(let r=0;r<this.onUnit.length;r++)this.onUnit[r]===e.gl&&this.bindTex(null,r);let t=e?e.fb:null;this.fbNow!==t&&(this.gl.bindFramebuffer(this.gl.FRAMEBUFFER,t),this.calls.bindFramebuffer++,this.fbNow=t)}slotOf(e){this.batch.full&&this.flush();let t=this.batch.slot(e);return t<0&&(this.flush(),t=this.batch.slot(e)),t}quad(e,t,r,o,a,i,l,c){j[0]=o,j[1]=a,j[2]=l,this.quadQ(e,t,r,i,c)}quadQ(e,t,r,o,a){let i=j[2];if(this.lost||i<=0)return;let l=this.q,c=j[0],u=j[1],f=r[4],h=r[5],b=r[0]*c,y=r[1]*c,m=r[2]*u,d=r[3]*u;l[0]=f,l[1]=h,l[2]=b+f,l[3]=y+h,l[4]=b+m+f,l[5]=y+d+h,l[6]=m+f,l[7]=d+h;let x=1/e.width,g=1/e.height;l[8]=t.x*x,l[9]=t.y*g,l[10]=(t.x+t.w)*x,l[11]=(t.y+t.h)*g,l[12]=lt(o,i,a==="add"),this.put(e)}put(e){if(this.mute)return;let t=this.q,r=!1,o=Math.min(t[0],t[2],t[4],t[6]),a=Math.max(t[0],t[2],t[4],t[6]),i=Math.min(t[1],t[3],t[5],t[7]),l=Math.max(t[1],t[3],t[5],t[7]);if(this.cOn){if(this.px1<=this.px0||this.py1<=this.py0)return;let u=this.scale,f=this.px0/u,h=this.py0/u,b=this.px1/u,y=this.py1/u;if(a<=f||o>=b||l<=h||i>=y)return;if(o<f||a>b||i<h||l>y){let m=t[0],d=t[1],x=t[2],g=t[5];if(d===t[3]&&x===t[4]&&g===t[7]&&t[6]===m){if(m!==x){let A=Math.min(Math.max(m,f),b),w=Math.min(Math.max(x,f),b),v=t[8],E=(t[10]-v)/(x-m);t[10]=v+(w-m)*E,t[8]=v+(A-m)*E,t[0]=t[6]=A,t[2]=t[4]=w}if(d!==g){let A=Math.min(Math.max(d,h),y),w=Math.min(Math.max(g,h),y),v=t[9],E=(t[11]-v)/(g-d);t[11]=v+(w-d)*E,t[9]=v+(A-d)*E,t[1]=t[3]=A,t[5]=t[7]=w}}else r=!0}}let c=this.bx0===this.px0&&this.by0===this.py0&&this.bx1===this.px1&&this.by1===this.py1;if(r?(!this.bScis||!c)&&(this.flush(),this.bScis=!0,this.bx0=this.px0,this.by0=this.py0,this.bx1=this.px1,this.by1=this.py1):this.bScis&&!(this.cOn&&c)&&(this.flush(),this.bScis=!1),this.real){let u=this.gq;u[0]=o,u[1]=i,u[2]=a,u[3]=l,this.growQ()}this.batch.pushQ(t,this.slotOf(e))}ellipse(e,t,r,o,a,i,l){if(this.lost||l<=0||r<=0||o<=0)return;let c=Zn[Dr(Math.max(r,o)*2*this.scale,No)],u=c.w/2/c.r,f=r*u,h=o*u,b=Math.cos(a),y=Math.sin(a),m=b*f,d=y*f,x=-y*h,g=b*h,A=1/256,w=this.q;w[0]=e-m-x,w[1]=t-d-g,w[2]=e+m-x,w[3]=t+d-g,w[4]=e+m+x,w[5]=t+d+g,w[6]=e-m+x,w[7]=t-d+g,w[8]=c.x*A,w[9]=c.y*A,w[10]=(c.x+c.w)*A,w[11]=(c.y+c.h)*A,w[12]=lt(i,l),this.put(this.kit)}polygon(e,t,r,o){if(this.lost||o<=0||t<3)return;this.tris.length<t*3&&(this.tris=new Int32Array(Math.max(t*3,this.tris.length*2)));let a=this.tris,i=_o(e,t,a),l=lt(r,o),c=(ot.x+ot.w/2)/256,u=(ot.y+ot.h/2)/256;for(let f=0;f<i;f+=3){let h=a[f]*2,b=a[f+1]*2,y=a[f+2]*2,m=this.q;m[0]=e[h],m[1]=e[h+1],m[2]=e[b],m[3]=e[b+1],m[4]=m[6]=e[y],m[5]=m[7]=e[y+1],m[8]=m[10]=c,m[9]=m[11]=u,m[12]=l,this.put(this.kit)}}stroke(e,t,r,o,a,i){if(this.lost||a<=0||r<=0||t<1)return;let l=Jn[Dr(r*this.scale,Bo)],c=r/2*(l.h/2/l.r);this.sPacked=lt(o,a),this.sColor=o,this.sAlpha=a,this.sU=(l.x+l.w/2)/256,this.sV0=l.y/256,this.sV1=(l.y+l.h)/256,this.sHw=r/2,Lo(e,t,c,i,this.strokeSeg,this.strokeDisc)}target(e,t,r,o){let a=this.gl,i=a.createTexture();this.bindTex(i),a.texImage2D(a.TEXTURE_2D,0,a.RGBA,e,t,0,a.RGBA,a.UNSIGNED_BYTE,null);let l=o?a.LINEAR:a.NEAREST;a.texParameteri(a.TEXTURE_2D,a.TEXTURE_MIN_FILTER,l),a.texParameteri(a.TEXTURE_2D,a.TEXTURE_MAG_FILTER,l),a.texParameteri(a.TEXTURE_2D,a.TEXTURE_WRAP_S,a.CLAMP_TO_EDGE),a.texParameteri(a.TEXTURE_2D,a.TEXTURE_WRAP_T,a.CLAMP_TO_EDGE),this.bindTex(null);let c=a.createFramebuffer();a.bindFramebuffer(a.FRAMEBUFFER,c),a.framebufferTexture2D(a.FRAMEBUFFER,a.COLOR_ATTACHMENT0,a.TEXTURE_2D,i,0);let u=a.checkFramebufferStatus(a.FRAMEBUFFER)===a.FRAMEBUFFER_COMPLETE;if(this.fbNow=c,this.bindFb(this.parent()),!u)return this.deleteTex(i),a.deleteFramebuffer(c),null;let f={tex:{id:dn(),width:e,height:t,source:this.canvas},gl:i,fb:c,w:e,h:t,f:r};return this.layerTex.set(f.tex,i),f}drop(e){this.batch.has(e.tex)&&this.flush(),this.deleteTex(e.gl),this.gl.deleteFramebuffer(e.fb),this.layerTex.delete(e.tex)}parent(){return this.real>0?this.layers[this.real-1]:null}layerAt(e){let t=this.canvas.width,r=this.canvas.height,o=this.layers[e]??null;return o&&(o.w!==t||o.h!==r)&&(this.drop(o),o=this.layers[e]=null),o??(this.layers[e]=this.target(t,r,1,!1))}pushLayer(){if(this.lost)return!1;this.flush();let e=this.layerAt(this.real);if(!e)return!1;let t=this.gl;return this.bindFb(e),t.disable(t.SCISSOR_TEST),t.clearColor(0,0,0,0),t.clear(t.COLOR_BUFFER_BIT),!0}popLayer(){return this.flush(),this.bindFb(this.parent()),this.layers[this.real].tex}filters(){return this.lost||!Ee.gl?null:this.fxr??(this.fxr=Ee.gl(this))}composite(e,t,r,o){if(o&&this.filters()?.chain(e,r,o))return;let a=this.gl;t&&a.blendFunc(a.ZERO,a.SRC_ALPHA),this.final(this.main,e,1,r),t&&(this.flush(),a.blendFunc(a.ONE,a.ONE_MINUS_SRC_ALPHA))}final(e,t,r,o){let a=this.gl,i=this.canvas.width,l=this.canvas.height,c=this.scale;(e!==this.main||!this.mapped)&&(this.bindFb(this.parent()),a.viewport(0,0,i,l),this.use(e),a.uniform2f(e.uScale,2*c/i,-2*c/l),this.mapped=e===this.main);let u=this.rx0/c,f=this.ry0/c,h=this.rx1/c,b=this.ry1/c,y=1/(r*t.width),m=1/(r*t.height),d=this.q;d[0]=d[6]=u,d[1]=d[3]=f,d[2]=d[4]=h,d[5]=d[7]=b,d[8]=this.rx0*y,d[9]=1-this.ry0*m,d[10]=this.rx1*y,d[11]=1-this.ry1*m,d[12]=lt(16777215,o),this.put(t),e!==this.main&&this.flush()}remap(){let e=this.gl;this.bindFb(this.parent()),e.viewport(0,0,this.canvas.width,this.canvas.height),this.use(this.main),e.uniform2f(this.uScale,2*this.scale/this.canvas.width,-2*this.scale/this.canvas.height),this.mapped=!0}upload2(e){let t=this.gl,r=e.words;if(this.kind==="webgl2")return t.bufferSubData(t.ARRAY_BUFFER,0,e.f32,0,r);let o=this.views.get(r);o||(this.views.size>=256&&this.views.clear(),this.views.set(r,o=e.f32.subarray(0,r))),t.bufferSubData(t.ARRAY_BUFFER,0,o)}flush(){let e=this.batch;if(!e.quads||this.lost)return e.reset();let t=this.gl;this.bScis?(t.enable(t.SCISSOR_TEST),t.scissor(this.bx0,this.canvas.height-this.by1,this.bx1-this.bx0,this.by1-this.by0)):t.disable(t.SCISSOR_TEST),this.upload2(e);for(let r=0;r<e.bound;r++){let o=e.textures[r];this.bindTex(this.textures.get(o)??this.layerTex.get(o)??null,r)}this.inst?this.inst.draw(6,e.quads):t.drawElements(t.TRIANGLES,e.quads*6,t.UNSIGNED_SHORT,0),this.stats.drawCalls++,this.stats.quads+=e.quads,e.reset()}end(){return this.closeLayers(),this.flush(),this.stats.filtersSkipped=this.skipped,this.stats}onLost(e){this.lostListeners.push(e)}onRestored(e){this.restoredListeners.push(e)}destroy(){let e=this.gl;Ee.live===this&&(Ee.live=null),this.canvas.removeEventListener("webglcontextlost",this.onContextLost),this.canvas.removeEventListener("webglcontextrestored",this.onContextRestored);try{for(let t of this.textures.values())t&&e.deleteTexture(t);for(let t of this.layers)t&&(e.deleteTexture(t.gl),e.deleteFramebuffer(t.fb));this.fxr?.destroy(),this.fxr=null,e.deleteBuffer(this.dynamic),e.deleteBuffer(this.index),this.staticBuf&&e.deleteBuffer(this.staticBuf),this.vao&&this.vaoApi&&this.vaoApi.remove(this.vao),e.deleteProgram(this.main.p),e.getExtension("WEBGL_lose_context")?.loseContext()}catch{}this.textures.clear()}};function zo(s,n,e){let t=s.createShader(n);if(s.shaderSource(t,e),s.compileShader(t),!s.getShaderParameter(t,s.COMPILE_STATUS)){let r=s.getShaderInfoLog(t)??"?";throw s.deleteShader(t),new Error(r)}return t}function zr(s="auto"){switch(s){case"canvas2d":return["canvas2d"];case"webgl1":return["webgl1","canvas2d"];default:return["webgl2","webgl1","canvas2d"]}}function jt(s,n={}){let e=s;for(let t of zr(n.renderer)){let r=t==="canvas2d"?Xt(e):Ho(e,t==="webgl2"?2:1,n);if(r)return r;e=wn(e)}throw new Error("No renderer: this browser has neither WebGL nor Canvas 2D")}function wn(s){let n=s.cloneNode(!1);return s.parentNode?.replaceChild(n,s),n}function $o(s=typeof location<"u"?location.search:""){let n=new URLSearchParams(s).get("renderer");return n==="canvas"?"canvas2d":n==="webgl2"||n==="webgl1"||n==="canvas2d"||n==="webgl"||n==="auto"?n:void 0}var dt=class{constructor(n,e={}){p(this,"atlas",n);p(this,"tags",new Map);p(this,"count",0);p(this,"m",nt());p(this,"measure",null);p(this,"height");p(this,"font");this.height=e.tagHeight??34,this.font=e.tagFont??"Nunito, sans-serif"}drop(){for(let n of this.tags.values())for(let e of n.values())for(let t of e.values())this.atlas.release(t);this.tags.clear(),this.count=0}get(n,e,t){let r=this.tags.get(n);r||this.tags.set(n,r=new Map);let o=r.get(e);o||r.set(e,o=new Map);let a=o.get(t);return a&&this.atlas.valid(a)?a:this.bake(n,e,t)}bake(n,e,t){let r=this.height,o=`700 ${Math.round(r*.65)}px ${this.font}`,a=this.measure??(this.measure=document.createElement("canvas").getContext("2d"));a.font=o;let i=Math.round(r*.4),l=Math.ceil(a.measureText(n).width)+i*2,c=this.atlas.bake((l+2)*t,(r+2)*t,h=>{h.scale(t,t),h.translate(1,1);let b=r/2;h.beginPath(),h.moveTo(b,0),h.lineTo(l-b,0),h.arc(l-b,b,b,-Math.PI/2,Math.PI/2),h.lineTo(b,r),h.arc(b,b,b,Math.PI/2,Math.PI*3/2),h.closePath(),h.fillStyle=e,h.fill(),h.fillStyle="#fff",h.font=o,h.textAlign="center",h.textBaseline="middle",h.fillText(n,l/2,r/2+1)},t,1,1,1);++this.count>64&&(this.drop(),this.count=1);let u=this.tags.get(n);u||this.tags.set(n,u=new Map);let f=u.get(e);return f||u.set(e,f=new Map),f.set(t,c),c}draw(n,e,t,r,o,a,i,l,c,u,f){let h=Nt(t,o,{band:Xi(r)});if(!h)return;let b=this.height,y=this.get(a,i,c),m=y.w/y.scale-2,d=Math.min(Math.max(h.head.x-m/2,4),u-m-4),x=Math.min(Math.max(h.head.y-h.headR*2.2-b,4),f-b-4);Te(this.m,null,d-1,x-1,0,1,1),n.quad(e(y.surface),y,this.m,y.w/y.scale,y.h/y.scale,16777215,l,"normal")}},Xi=s=>s.band==="3-5"||s.band==="9-12"?s.band:"6-8";var qi=(s,n=!1)=>n?Math.min(2**Math.round(Math.log2(Math.max(s,8))),256):Math.min(2**(Math.ceil(Math.log2(Math.max(s,8))*2)/2),512);function nr(s,n=null){let e={minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0},t=(r,o,a)=>{let i=n?n[0]*r+n[2]*o+n[4]:r,l=n?n[1]*r+n[3]*o+n[5]:o,c=n?Math.hypot(n[0],n[1]):1;e.minX=Math.min(e.minX,i-a*c),e.minY=Math.min(e.minY,l-a*c),e.maxX=Math.max(e.maxX,i+a*c),e.maxY=Math.max(e.maxY,l+a*c)};for(let r of s){let o="lw"in r&&r.stroke?(r.lw??1)/2:0;switch(r.k){case"circle":t(r.x-r.r,r.y-r.r,o),t(r.x+r.r,r.y+r.r,o),t(r.x-r.r,r.y+r.r,o),t(r.x+r.r,r.y-r.r,o);break;case"ellipse":case"rect":{let a=r.k==="ellipse"?Math.max(r.rx,r.ry):Math.hypot(r.w,r.h)/2;t(r.x-a,r.y-a,o),t(r.x+a,r.y+a,o),t(r.x-a,r.y+a,o),t(r.x+a,r.y-a,o);break}case"path":{let a=Qn(r.d);for(let i=0;i<a.count;i++){let l=a.subs[i];for(let c=0;c<l.n;c++)t(l.pts[c*2],l.pts[c*2+1],o)}break}case"line":for(let a=0;a+1<r.pts.length;a+=2)t(r.pts[a],r.pts[a+1],o);break;case"group":{let a=Te(nt(),n,r.x,r.y,r.rot??0,r.s??1,r.s??1),i=nr(r.items,a);Number.isFinite(i.minX)&&(e.minX=Math.min(e.minX,i.minX),e.minY=Math.min(e.minY,i.minY),e.maxX=Math.max(e.maxX,i.maxX),e.maxY=Math.max(e.maxY,i.maxY));break}}}return e}var Et=class{constructor(n){p(this,"atlas",n);p(this,"seen",new WeakSet);p(this,"baked",new WeakMap);p(this,"m",nt());p(this,"stack",[]);p(this,"local",nt());p(this,"pts",new Float64Array(128));p(this,"stats",{baked:0,vector:0});p(this,"bakeGroups",!0);p(this,"coarse",!1);p(this,"gen",0);p(this,"live",new Set)}setTier(n){let e=n==="low";if(e!==this.coarse){this.coarse=e,this.gen++;for(let t of this.live)this.atlas.release(t.frame);this.live.clear()}}draw(n,e,t,r,o,a,i){let l=typeof r=="string"?Bt(r)??vt:r,c=ln(t,l,o);return c.length?(a<=0||(a<1?(this.paint(n,e,c,null,n.beginLayer()?1:a,i),n.endLayer(a)):this.paint(n,e,c,null,a,i)),!0):!1}paint(n,e,t,r,o,a,i=0){var l;for(let c=0;c<t.length;c++){let u=t[c];if(u.k==="group"){let g=Te((l=this.stack)[i]??(l[i]=nt()),r,u.x,u.y,u.rot??0,u.s??1,u.s??1),A=o*(u.alpha??1);if(this.bakeGroups&&this.seen.has(u.items)){let w=qe(g[0],g[1])*a,v=this.bake(u.items,w);if(v){let E=v.frame,F=this.m;F.set(g),F[4]=g[0]*-v.ox+g[2]*-v.oy+g[4],F[5]=g[1]*-v.ox+g[3]*-v.oy+g[5],n.quad(e(E.surface),E,F,E.w/v.k,E.h/v.k,16777215,A,"normal"),this.stats.baked++;continue}}this.seen.add(u.items),this.stats.vector++,this.paint(n,e,u.items,g,A,a,i+1);continue}let f=o*(u.alpha??1),h=r?qe(r[0],r[1]):1,b=r?Math.atan2(r[1],r[0]):0,y=(u.lw??1)*h,m=u.stroke&&(u.lw??1)>0?me(u.stroke):null,d=u.fill&&u.k!=="line"?me(u.fill):null;if(u.k==="circle"||u.k==="ellipse"){let g=r?r[0]*u.x+r[2]*u.y+r[4]:u.x,A=r?r[1]*u.x+r[3]*u.y+r[5]:u.y,w=(u.k==="circle"?u.r:u.rx)*h,v=(u.k==="circle"?u.r:u.ry)*h,E=(u.k==="ellipse"?u.rot??0:0)+b;if(d&&m)n.ellipse(g,A,w+y/2,v+y/2,E,m[0],f*m[1]),n.ellipse(g,A,Math.max(w-y/2,0),Math.max(v-y/2,0),E,d[0],f*d[1]);else if(d)n.ellipse(g,A,w,v,E,d[0],f*d[1]);else if(m){let F=Math.min(Math.max(Math.ceil(Math.max(w,v)*a*.6),12),64),L=this.pts=Kn(this.pts,F*2),_=Math.cos(E),O=Math.sin(E);for(let H=0;H<F;H++){let V=H/F*Math.PI*2,G=Math.cos(V)*w,be=Math.sin(V)*v;L[H*2]=g+G*_-be*O,L[H*2+1]=A+G*O+be*_}n.stroke(L,F,y,m[0],f*m[1],!0)}continue}if(u.k==="line"){if(!m)continue;let g=u.pts.length>>1,A=this.pts=Kn(this.pts,g*2);for(let w=0;w<g;w++){let v=u.pts[w*2],E=u.pts[w*2+1];A[w*2]=r?r[0]*v+r[2]*E+r[4]:v,A[w*2+1]=r?r[1]*v+r[3]*E+r[5]:E}n.stroke(A,g,y,m[0],f*m[1],!1);continue}let x=u.k==="path"?Qn(u.d,r,h*a):ji(u,Te(this.local,r,u.x,u.y,u.rot??0,1,1),a*h);for(let g=0;g<x.count;g++){let A=x.subs[g],w=A.n,v=u.k==="rect"||A.closed;d&&w>=3&&(n.polygon(A.pts,w,d[0],f*d[1]),m||n.stroke(A.pts,w,1/a,d[0],f*d[1],!0)),m&&n.stroke(A.pts,w,y,m[0],f*m[1],v)}}}bake(n,e){let t=qi(e,this.coarse),r=this.baked.get(n),o=r?.get(t);if(o&&o.gen===this.gen&&this.atlas.valid(o.frame))return o;o&&this.live.delete(o);let a=nr(n);if(!Number.isFinite(a.minX))return null;let i=2/t,l=(a.maxX-a.minX+i*2)*t,c=(a.maxY-a.minY+i*2)*t;if(l>1024||c>1024)return null;let u=-a.minX+i,f=-a.minY+i,b={frame:this.atlas.bake(l,c,y=>{y.scale(t,t),y.translate(u,f),Lt(y,n)}),k:t,ox:u,oy:f,gen:this.gen};return r||this.baked.set(n,r=new Map),r.set(t,b),this.live.add(b),b}},Yt=new Array(36).fill(0),Kt=0,je=(s,n=NaN,e=NaN,t=NaN,r=NaN)=>{Yt[Kt++]=s,s!==ke.Z&&(Yt[Kt++]=n,Yt[Kt++]=e,s===ke.Q&&(Yt[Kt++]=t,Yt[Kt++]=r))};function ji(s,n,e){let t=Math.max(0,Math.min(s.r,s.w/2,s.h/2)),r=-s.w/2,o=-s.h/2,{M:a,L:i,Q:l,Z:c}=ke;return Kt=0,je(a,r+t,o),je(i,r+s.w-t,o),je(l,r+s.w,o,r+s.w,o+t),je(i,r+s.w,o+s.h-t),je(l,r+s.w,o+s.h,r+s.w-t,o+s.h),je(i,r+t,o+s.h),je(l,r,o+s.h,r,o+s.h-t),je(i,r,o+t),je(l,r,o,r+t,o),je(c),Qn(Yt,n,e)}function Go(s,n={}){let e=jt(s,n),t=new ht(Math.min(1024,e.maxTextureSize),2);t.onDrop=v=>{v.texture&&e.destroyTexture(v.texture),v.texture=null};let r=new Et(t),o=new xn,a=new Map,i=1e6,l=n.smooth===!1?1:typeof n.smooth=="number"?Math.min(Math.max(n.smooth,.05),1):.5,c=vn(e),u=new dt(t,n),f={w:1,h:1},h=1,b=0,y=!1,m=()=>u.drop(),d=typeof document<"u"?document.fonts:void 0;d?.ready?.then(()=>{y||m()}),d?.addEventListener?.("loadingdone",m);let x=()=>{let v=wn(e.canvas),E=Xt(v);if(E){console.warn("[engine] avatars: WebGL context lost for good, switching to Canvas 2D"),e.destroy(),e=E;for(let F of t.pages)F.surface.texture=null;c=vn(e),b=0}},g=()=>{if(!e.lost)return b=0,!0;let v=performance.now();return b||(b=v),v-b>3e3&&x(),!e.lost},A=()=>{let v=e.canvas;n.units?(h=n.pixelRatio??1,f.w=n.units.width,f.h=n.units.height):(h=n.pixelRatio??Math.min(globalThis.devicePixelRatio||1,2),f.w=v.clientWidth||v.width/h,f.h=v.clientHeight||v.height/h),e.resize(Math.max(1,Math.round(f.w*h)),Math.max(1,Math.round(f.h*h))),e.begin(0,0,h)},w=(v,E)=>{if(v.key===void 0)return v.id??E+1;let F=a.get(v.key);return F===void 0&&(a.size>256&&a.clear(),a.set(v.key,F=i++)),F};return{get renderer(){return e},get kind(){return e.kind},get lost(){return e.lost},get canvas(){return e.canvas},draw(v,E){if(g()){A();for(let F=0;F<v.length;F++){let L=v[F];if(!Array.isArray(L.body))continue;let _=w(L,F),O=l<1||n.interpolate!==!1?o.posed(_,L.body,l,n.interpolate!==!1):L.body,H=Bt(L.avatar??"")??vt,V=L.alpha??1;!r.draw(e,c,O,H,E,V,h)||!L.name||u.draw(e,c,O,H,E,L.name,L.color??"#6FA0E0",V,h,f.w,f.h)}e.end()}},clear(){g()&&(A(),e.end())},reset(){o=new xn,a.clear()},destroy(){y=!0,d?.removeEventListener?.("loadingdone",m),e.destroy()}}}var tr=new Map;function Uo(s,n,e=Math.min(globalThis.devicePixelRatio||1,2)){let t=`${s}|${n}|${e}`,r=tr.get(t);if(r)return r;r=document.createElement("canvas"),r.width=r.height=Math.round(n*e);let o=r.getContext("2d");return o.scale(e,e),o.beginPath(),o.rect(0,0,n,n),o.clip(),Lt(o,Ys(Bt(s)??vt,n)),tr.size>64&&tr.clear(),tr.set(t,r),r}function vn(s){return n=>{if(n.texture||(n.texture=s.createTexture(n.source),n.pending.length=0),n.pending.length){for(let[e,t,r]of n.pending)s.updateTexture(n.texture,e,t,r);n.pending.length=0}return n.texture}}var Hr='Fredoka, Nunito, "Varela Round", system-ui, sans-serif',Rt="rgba(10,16,30,0.75)";function $r(s,n){let e=s.size??40,t=s.outline?s.outline===!0?Rt:s.outline:null,r=t?s.outlineWidth??Math.max(e*.12,3):0,o=s.shadow&&n?s.shadow===!0?Rt:s.shadow:null,a=o?s.shadowBlur??e*.25:0;return{size:e,font:s.font??Hr,weight:s.weight??700,color:s.color??"#FBEFE3",outline:t,ow:r,shadow:o,blur:a,pad:r/2+a*1.2+2,th:e*1.25}}var Wo=(s,n)=>`${s.weight} ${s.size*n}px ${s.font}`;function Gr(s,n,e,t,r,o){s.scale(t,t),s.font=Wo(e,1),s.textBaseline="middle",s.textAlign="left",s.lineJoin="round",e.shadow&&(s.shadowColor=e.shadow,s.shadowBlur=e.blur*t),e.outline&&(s.strokeStyle=e.outline,s.lineWidth=e.ow,s.strokeText(n,r,o),s.shadowColor="transparent"),s.fillStyle=e.color,s.fillText(n,r,o)}var rr=null;function Ur(s,n,e){return rr??(rr=document.createElement("canvas").getContext("2d")),rr.font=Wo(n,e),rr.measureText(s).width/e}var Ye=class extends Re{constructor(e,t,r={}){super(e,null);p(this,"_text");p(this,"_style");p(this,"dirty",!0);p(this,"bakedScale",0);p(this,"bakedFontGen",-1);p(this,"bakedEffects",!0);p(this,"capW",0);p(this,"capH",0);this._text=t;let{x:o,y:a,rotation:i,scale:l,scaleX:c,scaleY:u,alpha:f,visible:h,tint:b,blend:y,z:m,anchor:d,hitRadius:x,clip:g,mask:A,filters:w,...v}=r;this._style=v,this.bake(),this.set({x:o,y:a,rotation:i,scale:l,scaleX:c,scaleY:u,alpha:f,visible:h,tint:b,blend:y,z:m,hitRadius:x,clip:g,mask:A,filters:w}),d!==void 0&&(this.anchor=d)}get text(){return this._text}set text(e){let t=String(e);t!==this._text&&(this._text=t,this.dirty=!0)}get style(){return this._style}set style(e){this._style={...this._style,...e},this.dirty=!0}bitmap(){let e=this._style.bitmapFont;if(!e)return null;let t=typeof e=="string"?this.kernel.bitmapFont(e):e;if(this.autoAnchor){let r=this._style.align;this.anchorX=r==="left"?0:r==="right"?1:.5,this.anchorY=.5}return t}get naturalWidth(){let e=this.bitmap();return e?e.measure(this._text)*((this._style.size??e.size)/e.size):super.naturalWidth}get naturalHeight(){let e=this.bitmap();return e?e.lineHeight*((this._style.size??e.size)/e.size):super.naturalHeight}frameNow(){return this._style.bitmapFont?null:this.bake()}draw(e,t,r){let o=this.bitmap();if(!o)return super.draw(e,t,r);let a=(this._style.size??o.size)/o.size,i=o.measure(this._text)*a,l=o.lineHeight*a,c=this.width,u=this.height,f=i>0?c/i:1,h=l>0?u/l:1;o.run(this._text,e,this.world,-this.anchorX*c,-this.anchorY*u,a*f,a*h,r,t,this.blend)}destroy(){this._frame&&this.kernel.atlas.release(this._frame),super.destroy()}bake(){let e=this.kernel;if(this._style.bitmapFont)return null;let t=e.pixelScale,r=e.effects;return!this.dirty&&t===this.bakedScale&&e.fontGen===this.bakedFontGen&&r===this.bakedEffects&&e.atlas.valid(this._frame)?this._frame:this.rebake()}rebake(){let e=this.kernel,t=e.pixelScale,r=e.effects;this.dirty=!1,this.bakedScale=t,this.bakedFontGen=e.fontGen,this.bakedEffects=r;let o=$r(this._style,r),{pad:a,th:i}=o,l=Ur(this._text,o,t),c=(l+a*2)*t,u=(i+a*2)*t,f=this._style.align??"center",h=f==="left"?a:f==="right"?a+l:a+l/2,b=d=>Gr(d,this._text,o,t,a,a+i/2),y=this._frame,m=null;return y&&e.atlas.valid(y)&&y.scale===t&&(m=e.atlas.rebake(y,c,u,b,this.capW,this.capH),m?Object.assign(m,{ox:h,oy:a+i/2,margin:a}):e.atlas.release(y)),m||(this.capW=Math.ceil(c*1.25+16),this.capH=Math.ceil(u),m=e.atlas.bake(this.capW,this.capH,b,t,h,a+i/2,a),m.w=Math.ceil(c),m.h=Math.ceil(u)),this._frame=m,this.autoAnchor&&this.useFrameAnchor(),this._w=this._h=null,m}};var ue=(s,n=0)=>{let e=Number(s);return Number.isFinite(e)?e:n};function Zt(s){typeof s=="string"&&/^\s*[{[]/.test(s)&&(s=JSON.parse(s));let n={size:0,lineHeight:0,base:0,pages:[],chars:[],kernings:[]},e=(t,r)=>{t==="info"?n.size=Math.abs(ue(r.size)):t==="common"?(n.lineHeight=ue(r.lineHeight),n.base=ue(r.base)):t==="page"?n.pages[ue(r.id)]=String(r.file??""):t==="char"?n.chars.push({id:ue(r.id),x:ue(r.x),y:ue(r.y),width:ue(r.width),height:ue(r.height),xoffset:ue(r.xoffset),yoffset:ue(r.yoffset),xadvance:ue(r.xadvance),page:ue(r.page)}):n.kernings.push({first:ue(r.first),second:ue(r.second),amount:ue(r.amount)})};if(typeof s=="object"){let t=s;e("info",t.info??{}),e("common",t.common??{});for(let[r,o]of(t.pages??[]).entries())e("page",{id:r,file:o});for(let r of t.chars??[])e("char",r);for(let r of t.kernings??[])e("kerning",r)}else{let t=/(?:^|<)\s*(info|common|page|char|kerning)\s([^\n<>]*)/gm,r=/(\w+)=(?:"([^"]*)"|([^\s/>]+))/g;for(let o=t.exec(s);o;o=t.exec(s)){let a={};for(let i=r.exec(o[2]);i;i=r.exec(o[2]))a[i[1]]=i[2]??i[3];e(o[1],a)}}return n.size||(n.size=n.lineHeight),n}var Qt=class{constructor(n,e,t,r=null,o=null){p(this,"baker",r);p(this,"host",o);p(this,"size");p(this,"lineHeight");p(this,"base");p(this,"ascii",new Array(128));p(this,"more",new Map);p(this,"kern",new Map);p(this,"bScale",0);p(this,"bFontGen",-1);p(this,"bEffects",!1);p(this,"bGen",-1);this.size=n,this.lineHeight=e,this.base=t}set(n,e){n<128?this.ascii[n]=e:this.more.set(n,e)}setKerning(n,e,t){this.kern.set(n*1114112+e,t)}prepare(){let n=this.host;if(!(!n||n.pixelScale===this.bScale&&n.fontGen===this.bFontGen&&n.effects===this.bEffects&&n.atlas.gen===this.bGen)){this.bScale=n.pixelScale,this.bFontGen=n.fontGen,this.bEffects=n.effects,this.bGen=n.atlas.gen;for(let e of this.ascii)e&&n.atlas.release(e.frame);for(let e of this.more.values())e&&n.atlas.release(e.frame);this.ascii.fill(void 0),this.more.clear()}}glyph(n){let e=n<128?this.ascii[n]:this.more.get(n);return(e===void 0||e&&this.host&&!this.host.atlas.valid(e.frame))&&(e=this.baker?this.baker(n):null,this.set(n,e)),e}kerning(n,e){return this.kern.size?this.kern.get(n*1114112+e)??0:0}measure(n){return this.run(n)}run(n,e,t,r=0,o=0,a=1,i=1,l=0,c=1,u="normal"){this.prepare();let f=0,h=-1;for(let b=0;b<n.length;b++){let y=n.charCodeAt(b);y>=55296&&y<56320&&b+1<n.length&&(y=n.codePointAt(b),b++),h>=0&&(f+=this.kerning(h,y)),h=y;let m=this.glyph(y);m&&(e&&m.w>0&&m.h>0&&(bn(t,r+(f+m.x)*a,o+m.y*i),e.r.quad(e.tex(m.frame.surface),m.frame,ie,m.w*a,m.h*i,l,c,u)),f+=m.advance)}return f}};function Vo(s,n){let e=new Qt(s.size,s.lineHeight,s.base);for(let t of s.chars){let r=n[t.page];if(!r)continue;let o={surface:r,x:t.x,y:t.y,w:t.width,h:t.height,scale:1,gen:0,ox:0,oy:0,margin:0};e.set(t.id,{frame:o,x:t.xoffset,y:t.yoffset,w:t.width,h:t.height,advance:t.xadvance})}for(let t of s.kernings)e.setKerning(t.first,t.second,t.amount);return e}function Xo(s,n){let e={...n},t=n.size??40,r=a=>{let i=String.fromCodePoint(a),l=s.pixelScale,c=$r(e,s.effects),u=Ur(i,c,l),f=s.atlas.bake((u+c.pad*2)*l,(c.th+c.pad*2)*l,h=>Gr(h,i,c,l,c.pad,c.pad+c.th/2),l);return{frame:f,x:-c.pad,y:-c.pad,w:f.w/l,h:f.h/l,advance:u}},o=new Qt(t,t*1.25,t,r,s);o.prepare();for(let a of n.chars??"0123456789")o.glyph(a.codePointAt(0));return o}var Yi=.5;function Wr(s){let n=[];for(let[e,t]of[["left",Y.leftWrist],["right",Y.rightWrist]]){let r=s[t*3],o=s[t*3+1],a=s[t*3+2];r!==void 0&&o!==void 0&&Number.isFinite(r)&&Number.isFinite(o)&&(a??0)>=Yi&&n.push({side:e,x:r,y:o})}return n}var An=s=>on[((s-1)%on.length+on.length)%on.length];function sr(s,n,e,t,r=()=>null){let o=[];for(let a of s){let i=r(a)??a.body;if(Array.isArray(i))for(let l of Wr(i)){let c=n(l);o.push({player:a.id,side:l.side,x:c.x*e,y:c.y*t,color:An(a.id)})}}return o}function Sn(s,n,e,t=0){let r=s.world,o=Js(r,n,e);if(!o)return!1;let a=Math.hypot(r[0],r[1])||1,i=Math.hypot(r[2],r[3])||1,[l,c]=o;if(s.hitRadius!=null){let y=s.hitRadius+t/((a+i)/2);return l*l+c*c<=y*y}let u=-s.anchorX*s.width-t/a,f=-s.anchorY*s.height-t/i,h=(1-s.anchorX)*s.width+t/a,b=(1-s.anchorY)*s.height+t/i;return l>=u&&l<=h&&c>=f&&c<=b}function or(s,n,e,t=0){for(let r of n)if((e===void 0||r.player===e)&&Sn(s,r.x,r.y,t))return r;return null}function Ki(s){switch(s.type){case"circle":case"ring":case"star":return[s.r*2,s.r*2];case"ellipse":return[s.rx*2,s.ry*2];case"roundRect":return[s.w,s.h];case"line":return[s.length,s.lw??4];case"path":return s.r?[s.r*2,s.r*2]:[s.size,s.size]}}function Qi(s){let n=s.type==="line"?0:s.stroke?(s.lw??2)/2:0,e=s.shadow?s.shadow.blur*1.5+Math.max(Math.abs(s.shadow.x??0),Math.abs(s.shadow.y??0)):0;return Math.ceil(n+e+1)}var qo=(s,n)=>n||!s.shadow?s:{...s,shadow:void 0};function Vr(s,n,e){let t=Qi(n),r=n.type==="roundRect",[o,a]=r?[Math.min(n.w,n.r*2+4/e),Math.min(n.h,n.r*2+4/e)]:Ki(n),i=(o+t*2)*e,l=(a+t*2)*e;return{frame:s.bake(i,l,u=>{u.scale(e,e),u.translate(t+o/2,t+a/2),Zi(u,n,o,a)},e,t+o/2,t+a/2,t),slice:r?Math.ceil((n.r+t)*e):0,w:r?n.w:o,h:r?n.h:a}}function Zi(s,n,e,t){s.lineJoin="round",s.lineCap="round";let r=new Path2D;switch(n.type){case"circle":case"ring":r.arc(0,0,n.r,0,Math.PI*2);break;case"ellipse":r.ellipse(0,0,n.rx,n.ry,0,0,Math.PI*2);break;case"roundRect":r.roundRect(-e/2,-t/2,e,t,Math.min(n.r,e/2,t/2));break;case"star":{let c=n.points??5,u=n.r*(n.inner??.5);for(let f=0;f<c*2;f++){let h=f%2?u:n.r,b=-Math.PI/2+f*Math.PI/c;f?r.lineTo(Math.cos(b)*h,Math.sin(b)*h):r.moveTo(Math.cos(b)*h,Math.sin(b)*h)}r.closePath();break}case"line":r.moveTo(-e/2+t/2,0),r.lineTo(e/2-t/2,0);break;case"path":{let c=n.r?n.r*2/n.size:1,u=new DOMMatrix([c,0,0,c,-n.size/2*c,-n.size/2*c]);r.addPath(new Path2D(n.d),u);break}}let o=n.shadow,a=()=>{if(!o)return;let c=s.getTransform();s.shadowColor=o.color,s.shadowBlur=o.blur*c.a,s.shadowOffsetX=(o.x??0)*c.a,s.shadowOffsetY=(o.y??0)*c.a},i=()=>{s.shadowColor="transparent",s.shadowBlur=0};if(n.type==="line"){a(),s.strokeStyle=n.stroke??n.fill??"#fff",s.lineWidth=t,s.stroke(r);return}let l=n.type==="ring";if(n.outlineBelow&&n.fill&&n.stroke&&!l){a(),s.strokeStyle=n.stroke,s.lineWidth=n.lw??2,s.stroke(r),i(),s.fillStyle=n.fill,s.fill(r);return}n.fill&&!l&&(a(),s.fillStyle=n.fill,s.fill(r),i()),(n.stroke||l)&&((!n.fill||l)&&a(),l&&n.fill&&(s.fillStyle=n.fill,s.fill(r)),s.strokeStyle=n.stroke??"#fff",s.lineWidth=n.lw??2,s.stroke(r),i())}var Jt=class{constructor(){p(this,"ctx",null);p(this,"master",null);p(this,"buffers",new Map);p(this,"held",!1);p(this,"muted",!1);p(this,"volume",1);if(typeof addEventListener=="function"){let n=()=>{this.context()?.resume().catch(()=>{})};for(let e of["pointerdown","keydown","touchstart"])addEventListener(e,n,{once:!0,capture:!0})}}context(){if(this.ctx)return this.ctx;let n=globalThis.AudioContext??globalThis.webkitAudioContext;if(!n)return null;try{this.ctx=new n,this.master=this.ctx.createGain(),this.master.connect(this.ctx.destination),this.held&&this.ctx.suspend()}catch{return null}return this.ctx}async load(n,e){let t=this.context();if(!t)return;let r=await(await fetch(e)).arrayBuffer();this.buffers.set(n,await t.decodeAudioData(r))}has(n){return this.buffers.has(n)}play(n,e={}){let t=this.context(),r=this.buffers.get(n);if(!t||!r||!this.audible)return()=>{};let o=t.createBufferSource();o.buffer=r,o.loop=e.loop??!1,o.playbackRate.value=e.rate??1;let a=t.createGain();return a.gain.value=(e.volume??1)*this.volume,o.connect(a).connect(this.master),o.start(),()=>{try{o.stop()}catch{}}}tone(n,e=.25,t={}){let r=this.context();if(!(!r||!this.audible))try{let o=r.createOscillator(),a=r.createGain();o.type=t.type??"sine",o.frequency.setValueAtTime(n,r.currentTime),t.to&&o.frequency.exponentialRampToValueAtTime(t.to,r.currentTime+e),a.gain.setValueAtTime((t.volume??.12)*this.volume,r.currentTime),a.gain.exponentialRampToValueAtTime(.001,r.currentTime+e),o.connect(a).connect(this.master),o.start(),o.stop(r.currentTime+e)}catch{}}get audible(){return!this.muted&&!this.held}hold(){this.held=!0,this.ctx?.suspend().catch(()=>{})}release(){this.held=!1,this.ctx?.resume().catch(()=>{})}destroy(){this.ctx?.close().catch(()=>{}),this.ctx=null}};var Ji={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}},Ke=["high","medium","low"];function at(s){let n=Ji[s];return{name:s,...n,scale:e=>e<=0?0:Math.max(1,Math.round(e*n.particles))}}var jo=s=>Ke[Math.min(Ke.indexOf(s)+1,Ke.length-1)],ar=(s,n)=>{if(!s.length)return NaN;let e=[...s].sort((t,r)=>t-r);return e[Math.min(e.length-1,Math.max(0,Math.floor(n*(e.length-1)+.5)))]},Yo=12,Ko=s=>Mn(s,.5);function Mn(s,n=.1){let e=ar(s,n);if(!Number.isFinite(e))return 1e3/60;let t=[144,120,90,75,60,50,30],r=60;for(let o of t)Math.abs(1e3/o-e)<Math.abs(1e3/r-e)&&(r=o);return 1e3/r}function ir(s,n){let e=n.refresh!==void 0&&Number.isFinite(n.refresh)&&n.refresh>0?n.refresh:Mn(n.intervals),t=ar(n.intervals,.5),r=ar(n.intervals,.9),o=ar(n.cpu,.5);if(!Number.isFinite(t))return s==="canvas2d"?"low":"medium";let a=l=>l<=e*1.25,i=l=>!Number.isFinite(o)||o<e*l;return s==="canvas2d"?a(r)&&i(.25)?"medium":"low":a(r)&&i(.5)?"high":a(t)?"medium":"low"}function Qo(s,n){return s.length<30?!1:s.filter(t=>t>n*1.5).length/s.length>.5}var Zo="0.1.1",el=720*3600*1e3,Jo=(s,n,e)=>`fabi-play.engine-tier:${Zo}:${s}:${n}:${e}`,ea=(s,n,e)=>`fablee-engine-tier:${Zo}:${s}:${n}:${e}`;function ta(s,n,e=Date.now()){try{let t=JSON.parse(s?.getItem(n)??"null");if(t&&Ke.includes(t.tier)&&typeof t.at=="number"&&e-t.at<el)return typeof t.refresh=="number"&&t.refresh>0?{name:t.tier,refresh:t.refresh}:{name:t.tier}}catch{}return null}function Xr(s,n,e,t,r=Date.now()){try{s?.setItem(n,JSON.stringify(t!==void 0&&Number.isFinite(t)?{tier:e,at:r,refresh:t}:{tier:e,at:r}))}catch{}}function na(s=typeof location<"u"?location.search:""){let n=new URLSearchParams(s).get("tier");return Ke.includes(n)?n:void 0}function qr(s,n){let e=n?.tier;if(Ke.includes(e))return s==="canvas2d"&&e==="high"?"medium":e}var jr=s=>typeof s?.hz=="number"&&s.hz>=20&&s.hz<=240?Mn([1e3/s.hz],.5):NaN,Yr=(s,n)=>Ke.indexOf(s)>=Ke.indexOf(n)?s:n;function ra(s,n,e){return s?{name:s,from:"forced"}:n?{name:e?Yr(n,e):n,from:"hint"}:e?{name:e,from:"cache"}:null}var tl=/^\s*(<|>|[^+\-<>=\s][^+=]*?)?\s*(?:([+-])=\s*(\d*\.?\d+))?\s*$/,en=class{constructor(n={}){p(this,"steps",[]);p(this,"labels",new Map);p(this,"end",0);p(this,"prevStart",0);p(this,"elapsed",0);p(this,"iter",0);p(this,"last",0);p(this,"delayLeft");p(this,"_paused");p(this,"done",!1);p(this,"rewinding",!1);p(this,"promise");p(this,"resolve");p(this,"repeat");p(this,"yoyo");p(this,"onComplete");this.repeat=Math.floor(n.repeat??0),this.yoyo=!!n.yoyo,this.delayLeft=n.delay??0,this._paused=!!n.paused,this.onComplete=n.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(n){if(n===void 0)return this.end;if(typeof n=="number")return Math.max(n,0);let e=tl.exec(n);if(!e)throw new Error(`[engine] timeline: bad position "${n}"`);let[,t,r,o]=e,a=o?(r==="-"?-1:1)*Number(o):0,i=this.end;if(t==="<")i=this.prevStart;else if(t&&t!==">"){let l=this.labels.get(t.trim());l===void 0?this.labels.set(t.trim(),this.end):i=l}return Math.max(i+a,0)}add(n){let e=this.steps.length;for(;e>0&&this.steps[e-1].start>n.start;)e--;return this.steps.splice(e,0,n),this.prevStart=n.start,this.end=Math.max(this.end,n.start+n.dur),this}to(n,e,t,r="quadOut"){let o=typeof r=="object"?r:{ease:r},a=typeof o.ease=="function"?o.ease:ct[o.ease??"quadOut"];return this.add({target:n,to:e,from:null,fn:null,start:this.at(o.at)+(o.delay??0),dur:Math.max(t,0),ease:a,onUpdate:o.onUpdate,p:-1})}set(n,e,t){return this.add({target:n,to:e,from:null,fn:null,start:this.at(t),dur:0,ease:ct.linear,p:-1})}call(n,e){return this.add({target:null,to:null,from:null,fn:n,start:this.at(e),dur:0,ease:ct.linear,p:-1})}label(n,e){return this.labels.set(n,this.at(e)),this}wait(n){return this.end+=Math.max(n,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(n){let e=Math.min(typeof n=="string"&&this.labels.has(n)?this.labels.get(n):this.at(n),this.end),t=this.yoyo&&this.iter%2===1;return this.elapsed=this.iter*this.end+(t?this.end-e:e),this.render(e),this}then(n,e){return this.promise.then(n,e)}update(n){if(this._paused||this.done)return;if(this.delayLeft>0){if(this.delayLeft-=n,this.delayLeft>0)return;n=-this.delayLeft,this.delayLeft=0}let e=this.end;if(e<=0)return this.render(0),this.complete();this.elapsed+=n;let t=this.repeat<0?1/0:e*(this.repeat+1),r=Math.min(this.elapsed,t),o=r>=t?this.repeat:Math.floor(r/e);for(;this.iter<o;){let i=this.yoyo&&this.iter%2===1;this.render(i?0:e),this.iter++,this.yoyo||(this.rewinding=!0,this.render(0),this.rewinding=!1)}let a=r-o*e;this.render(this.yoyo&&o%2===1?e-a:a),r>=t&&this.complete()}complete(){this.done||(this.done=!0,this.onComplete?.(),this.resolve())}render(n){let e=this.steps;if(n>=this.last)for(let t=0;t<e.length;t++){let r=e[t];n>=r.start&&this.apply(r,n)}else for(let t=e.length-1;t>=0;t--){let r=e[t];r.p>=0&&this.apply(r,n)}this.last=n}apply(n,e){let t=n.dur>0?Math.min(Math.max((e-n.start)/n.dur,0),1):e>n.start||e===n.start&&!this.rewinding?1:0;if(t===n.p)return;if(n.p=t,n.fn){this.rewinding||n.fn();return}let r=n.target;if(r.destroyed||r._free)return;let o=n.to;if(!n.from){n.from={};for(let i in o)n.from[i]=Number(r[i]??0)}let a=n.ease(t);for(let i in o)r[i]=n.from[i]+(o[i]-n.from[i])*a;n.onUpdate?.(a)}};var tn=class{constructor(){p(this,"list",[]);p(this,"timelines",[])}timeline(n){let e=new en(n);return this.timelines.push(e),e}tween(n,e,t,r="quadOut"){let o=typeof r=="object"?r:{ease:r},a=typeof o.ease=="function"?o.ease:ct[o.ease??"quadOut"],i,l=new Promise(c=>{let u=Object.keys(e),f=new Float64Array(u.length);u.forEach((h,b)=>f[b]=Number(e[h])),i={target:n,keys:u,to:f,from:new Float64Array(u.length),started:!1,duration:Math.max(t,0),time:0,delay:o.delay??0,ease:a,onUpdate:o.onUpdate,done:c,dead:!1}});return this.list.push(i),Object.assign(l,{stop:()=>this.finish(i)})}stopAll(n){let e=this.list;for(let t=0;t<e.length;t++)e[t].target===n&&this.finish(e[t])}get size(){return this.list.length}update(n){if(this.timelines.length){let r=0,o=this.timelines;for(let a=0;a<o.length;a++){let i=o[a];i.update(n),i.finished||(o[r++]=i)}o.length=r}let e=this.list;if(!e.length)return;let t=0;for(let r=0;r<e.length;r++){let o=e[r];o.dead||this.step(o,n),o.dead||(e[t++]=o)}t!==e.length&&(e.length=t)}step(n,e){if(n.target.destroyed)return this.finish(n);let t=e;if(n.delay>0){if(n.delay-=e,n.delay>0)return;t=-n.delay}let r=n.keys;if(!n.started){n.started=!0;for(let i=0;i<r.length;i++)n.from[i]=Number(n.target[r[i]]??0)}n.time+=t;let o=n.duration>0?Math.min(n.time/n.duration,1):1,a=n.ease(o);for(let i=0;i<r.length;i++)n.target[r[i]]=n.from[i]+(n.to[i]-n.from[i])*a;n.onUpdate?.(a),o>=1&&this.finish(n)}finish(n){n.dead||(n.dead=!0,n.done())}clear(){for(let n of this.list)this.finish(n);this.list.length=0;for(let n of this.timelines)n.stop();this.timelines=[]}};var he=720,Tn=class extends Ie{constructor(e,t){super(e);p(this,"paintAll",t)}draw(e,t){this.paintAll(e,t)}},Qr=class extends Ie{constructor(e,t){super(e);p(this,"paintAll",t)}draw(e,t){this.paintAll(e,t)}},mt=()=>performance.now();async function oa(s={}){let n=s.play??null,e=s.canvas??null;e||(e=document.createElement("canvas"),e.style.cssText="position:fixed;inset:0;width:100%;height:100%;display:block;touch-action:none",document.body.appendChild(e));let t=jt(e,{renderer:s.renderer??$o(),failIfMajorPerformanceCaveat:s.failIfMajorPerformanceCaveat,instancing:s.instancing});e=t.canvas;let r=new Set,o=new ht(Math.min(2048,t.maxTextureSize),4);o.onPage=k=>r.add(k),o.onDrop=k=>{r.delete(k),k.texture&&t.destroyTexture(k.texture),k.texture=null};let a=vn(t),i=new tn,l=new Jt,c=new Et(o),u=new Map,f=new Map,h=new Map,b=new Map,y=new Map,m=new Set,d=0,x=s.tier??na(),g=String(t.info.renderer??""),A=(()=>{try{return globalThis.localStorage??null}catch{return null}})(),w=typeof screen<"u"?`${screen.width}x${screen.height}`:"",v=Jo(t.kind,g,w);Fs(A,v,ea(t.kind,g,w));let E=ta(A,v),F=ra(x,qr(t.kind,n?.device),E?.name),L=F?.name??"medium",_=at(L);c.setTier(L);let O=F?.from==="hint",H=E?.name,V=E?.refresh??jr(n?.device),G=1,be=1,$=1,oe={atlas:o,get pixelScale(){return G},get fontGen(){return d},get effects(){return _.effects},tweens:i,frame:k=>Ln.frame(k),shape:k=>{let M=_.effects,C=M?G:-G,R=u.get(C);R||(u.size>=8&&u.clear(),u.set(C,R=new Wt(2e3)));let N=Ue(k),ne=R.get(k,N);return(!ne||!o.valid(ne.frame))&&R.set(k,ne=Vr(o,qo(k,M),G),N),ne},bitmapFont:k=>Ln.bitmapFont(k)},ye=1280,Be=null;class hr extends Tt{get width(){return ye}set width(M){}get height(){return he}set height(M){}get safe(){let M=Math.min(ye,he*16/9);return{x:(ye-M)/2,y:0,w:M,h:he}}}let we=new hr(oe),De=()=>{let k=t.canvas,M=k.getBoundingClientRect();be=Math.max(1,M.width||k.clientWidth||innerWidth),$=Math.max(1,M.height||k.clientHeight||innerHeight),ye=he*be/$;let C=Math.min(globalThis.devicePixelRatio||1,s.maxPixelRatio??2);if($*C/he<=_.resolution){let N=Math.max(1,Math.round($*C));G=N/he,t.resize(Math.max(1,Math.round(be*C)),N)}else G=_.resolution,t.resize(Math.round(ye*G),Math.round(he*G));Be&&Be.style.setProperty("--unit",`${$/he}px`)};addEventListener("resize",De);let xe=k=>{L=k,_=at(k),c.setTier(k),De()},fe=typeof ResizeObserver<"u"?new ResizeObserver(De):null;fe?.observe(e);let Oe=n?.backdrop==="video"?"video":"none",S=n?.view??null,I=[],B=-1/0,X=!1,U=!1,le=new Set,Ft=()=>{let k=Oe==="video"?"transparent":"";document.documentElement.style.background=k,document.body.style.background=k},ze=(k,M)=>{let C=k==="video"?"video":"none",R=M??null;if(!(C===Oe&&(R===S||R&&S&&R.x===S.x&&R.y===S.y&&R.w===S.w&&R.h===S.h))){Oe=C,S=R,Ft();for(let N of[...le])N(Oe,S)}},nn=[];if(n){let k=R=>{Array.isArray(R)&&(I=R,B=mt())},M=R=>{X=R,pe()},C=R=>{if(x||O)return;Number.isFinite(V)||(V=jr(R));let N=qr(t.kind,R);N&&(O=!0,xe(H?Yr(N,H):N))};nn.push(n.on("start",R=>C(R?.device)),n.on("start",R=>{typeof R?.muted=="boolean"&&(l.muted=R.muted)}),n.on("frame",R=>k(R?.players)),n.on("players",R=>k(R?.players)),n.on("backdrop",R=>ze(R?.backdrop,R?.view)),n.on("start",R=>ze(R?.backdrop,R?.view??n.view)),n.on("pause",()=>M(!0)),n.on("resume",()=>M(!1)),n.on("break-start",()=>M(!0)),n.on("break-done",()=>M(!1)),n.on("break-end",()=>M(!1))),l.muted=n.muted===!0}Ft();let pe=()=>X||U||document.hidden?l.hold():l.release(),Ze=-1,Je=[],ve=0,Pe=()=>mt()-B<1e3?I:[],bt=k=>n?n.toScreen(k):Cs(S,k),Ae=()=>{if(Ze===ve)return Je;Ze=ve;let k=Oe==="video"||!n?.smoothedBody?()=>null:M=>n.smoothedBody(M);return Je=sr(Pe(),bt,ye,he,k),Je},He={x:0,y:0,w:1,h:1},fr=()=>(He.x=S?S.x*ye:0,He.y=S?S.y*he:0,He.w=S?S.w*ye:ye,He.h=S?S.h*he:he,He),Rn=k=>{let M=k.alpha??1,C=k.tags?new dt(o,k):null;C&&m.add(C);let R=typeof k.tags=="function"?k.tags:N=>String(N);return(N,ne)=>{if(Oe==="video")return;let z=fr();for(let W of Pe()){let de=n?.smoothedBody?.(W)??W.body,ee=Bt(n?.avatarOf?.(W)??W.avatar??"")??vt;if(!c.draw(N.r,N.tex,de,ee,z,M*ne,G)||!C)continue;let _e=R(W.id);_e&&C.draw(N.r,N.tex,de,ee,z,_e,An(W.id),M*ne,G,ye,he)}}},pr=new Set,dr=new Set,rn=new Set,Cn=!1,mr=0,Pt=0,Fn=0,yt={fps:0,cpuMs:0,drawCalls:0,quads:0,filtersSkipped:0},Pn=0,br=0,yr=mt(),sn=[],_n=0,gs=()=>({r:t,kernel:oe,tex:a}),ks=gs(),Ea=()=>{if(t.lost)return;let[k,M]=Oe==="video"||s.background===void 0?[0,0]:me(s.background);t.time=Fn,t.maxBlur=_.maxBlur,t.begin(k,M,G),Te(we.world,null,we.x,we.y,we.rotation,we.scaleX,we.scaleY),_r(ks,we,we.alpha,we.tint);let C=t.end();yt.drawCalls=C.drawCalls,yt.quads=C.quads,yt.filtersSkipped=C.filtersSkipped},ws=k=>{if(!Cn)return;mr=requestAnimationFrame(ws);let M=Math.min(Math.max((k-Pt)/1e3,0),.1);Pt&&sn.push(k-Pt),Pt=k,ve++;let C=mt(),R=X||U;if(!R){Fn+=M,i.update(M);for(let N of rn)N.destroyed||N.update(M);for(let N of pr)N(M,Fn)}for(let N of dr)N(M);we.sweep();for(let N of rn)N.destroyed&&rn.delete(N);if(t.lost?(_n||(_n=k),k-_n>3e3&&Ra()):(_n=0,Ea()),Pn++,br+=mt()-C,C-yr>=1e3&&(yt.fps=Math.round(Pn*1e3/(C-yr)),yt.cpuMs=Math.round(br/Math.max(Pn,1)*100)/100,n?.reportStats?.({fps:yt.fps,renderer:t.kind,tier:L}),Pn=0,br=0,yr=C),sn.length>=180){let N=Number.isFinite(V)?V:Mn(sn);!x&&!R&&Qo(sn,N)&&L!=="low"&&(xe(jo(L)),H=L,Xr(A,v,L,Number.isFinite(V)?V:void 0),console.info(`[engine] slow frames: tier ${L}`)),sn.length=0}},Ra=()=>{let k=wn(t.canvas),M=Xt(k);if(M){console.warn("[engine] WebGL context lost for good: switching to Canvas 2D"),t.destroy(),t=M;for(let C of r)C.texture=null;for(let C of o.pages)r.add(C.surface);a=vn(t),ks=gs(),fe?.disconnect(),fe?.observe(k),De()}},vs=()=>{pe(),document.hidden||(Pt=0)};document.addEventListener("visibilitychange",vs);let As=()=>{d++;for(let k of m)k.drop()};if(document.fonts?.addEventListener?.("loadingdone",As),De(),!F&&s.probe!==!1&&(Number.isFinite(V)||(V=Ko(await nl(Yo))),!O)){_=at("high"),De();let k=await rl(t,o,()=>a,()=>G,ye,()=>O);if(k.refresh=V,!O){let M=ir(t.kind,k);Xr(A,v,M,V),H=M,xe(M)}}let Ln={stage:we,get tier(){return _},get renderer(){return t},get canvas(){return t.canvas},get pixelScale(){return G},get backdrop(){return Oe},get view(){return S},get paused(){return X||U},sound:l,stats:yt,get time(){return Fn},get supports(){let k=t.support;return{filters:k.filters,blur:k.filters&&_.maxBlur>0,shaders:k.shaders,maxBlur:k.filters?_.maxBlur:0,tiers:{high:{maxBlur:at("high").maxBlur},medium:{maxBlur:at("medium").maxBlur},low:{maxBlur:at("low").maxBlur}}}},sprite:(k,M)=>new Re(oe,k,M),shape:(k,M)=>new Xe(oe,k,M),text:(k,M)=>new Ye(oe,k,M),group:k=>new Tt(oe).set(k??{}),particles(k,M={}){let C=typeof k=="object"&&"type"in k?oe.shape(k).frame:k,R=new Ht(oe,C,M),{max:N,blend:ne,gravity:z,drag:W,...de}=M;return R.set(de),rn.add(R),R},tween:(k,M,C,R)=>i.tween(k,M,C,R),bake(k,M,C,R,N){return h.set(k,{w:M,h:C,draw:R,origin:N}),f.delete(k),Ln.frame(k)},frame(k){let M=f.get(k);if(M&&o.valid(M)&&(M.gen===0||M.scale===G))return M;let C=h.get(k);if(C){let R=G,N=o.bake(C.w*R,C.h*R,ne=>(ne.scale(R,R),C.draw(ne)),R,C.origin?.x??0,C.origin?.y??0);return f.set(k,N),N}if(M)return M;throw new Error(`[engine] no frame "${k}": load it or bake it first`)},async load(k){await Promise.all(Object.entries(k).map(([M,C])=>Fa(M,C)))},hands:k=>k===void 0?Ae():Ae().filter(M=>M.player===k),touched(k,M,C={}){return k.updateWorld(),or(k,Ae(),M,C.padding??0)},hits(k,M,C,R=0){return k.updateWorld(),Sn(k,M,C,R)},avatars:(k={})=>new Tn(oe,Rn(k)),handMarkers(k={}){let M=k.radius??36,C=k.look??"auto",R=new Float64Array(6),N=Math.max(M*.12,3),ne={type:"ring",r:M,lw:N,fill:"rgba(251,231,184,0.3)",stroke:"#ffffff"},z={type:"ring",r:M,lw:N*1.8,stroke:Rt,shadow:{color:Rt,blur:M*.2}},W=(xt,Se,_t,xr,In,gt)=>{let Nn=Se.w/Se.scale;Te(R,null,_t-Nn/2,xr-Nn/2,0,1,1),xt.r.quad(xt.tex(Se.surface),Se,R,Nn,Nn,In,gt,"normal")},de=xt=>{let Se=null,_t=!1;return()=>(Se&&o.valid(Se.frame)&&Se.frame.scale===G&&_t===_.effects?Se:(_t=_.effects,Se=oe.shape(xt))).frame},ee=de(ne),_e=de(z);return new Qr(oe,(xt,Se)=>{let _t=C==="video"||C==="auto"&&Oe==="video",xr=ee(),In=_t?_e():null;for(let gt of Ae())In&&W(xt,In,gt.x,gt.y,16777215,Se),W(xt,xr,gt.x,gt.y,me(gt.color)[0],Se)})},timeline:k=>i.timeline(k),animation(k,M){let C=typeof k=="string"?Ca(k):{frames:k},R=new Ne(oe,C,M);return rn.add(R),R},bitmapFont(k,M){if(!M){let R=b.get(k);if(!R)throw new Error(`[engine] no bitmap font "${k}": load or make it first`);return R}let C="data"in M?Ss(Zt(M.data),M.pages):Xo(oe,M);return b.set(k,C),C},players:()=>Pe(),onFrame(k){return pr.add(k),()=>{pr.delete(k)}},onRender(k){return dr.add(k),()=>{dr.delete(k)}},onBackdrop(k){return le.add(k),()=>{le.delete(k)}},get hud(){return Be||(Be=document.createElement("div"),Be.style.cssText="position:fixed;inset:0;pointer-events:none;overflow:hidden",document.body.appendChild(Be),De()),Be},random:(k=0,M=1)=>k+Math.random()*(M-k),start(){Cn||(Cn=!0,Pt=0,mr=requestAnimationFrame(ws))},pause(){U=!0,pe()},resume(){U=!1,pe()},destroy(){Cn=!1,cancelAnimationFrame(mr),nn.forEach(k=>k()),removeEventListener("resize",De),fe?.disconnect(),document.removeEventListener("visibilitychange",vs),document.fonts?.removeEventListener?.("loadingdone",As),i.clear(),po(oe),l.destroy(),t.destroy(),Be?.remove()}};function Ca(k){let M=y.get(k);if(M)return M;let C=[...new Set([...f.keys(),...h.keys()])].filter(R=>R.startsWith(k)).sort(bo);if(!C.length)throw new Error(`[engine] no animation or frames "${k}\u2026"`);return{frames:C}}async function Fa(k,M){let C=M.split("?")[0].split(".").pop().toLowerCase();if(["mp3","ogg","wav","m4a","aac","webm"].includes(C))return l.load(k,M);if(["woff","woff2","ttf","otf"].includes(C)){let z=new FontFace(k,`url(${M})`);document.fonts.add(await z.load()),d++;return}let R=new URL(M,location.href);if(C==="fnt")return Ms(k,Zt(await(await fetch(M)).text()),R);if(C==="json"){let z=await(await fetch(M)).json();if(Array.isArray(z.chars)&&!z.frames)return Ms(k,Zt(z),R);let W=await Kr(new URL(z.meta?.image??M.replace(/\.json$/,".png"),R).href);Pa(k,z,$t(W));return}let N=await Kr(M),ne=$t(N);r.add(ne),f.set(k,{surface:ne,x:0,y:0,w:N.width,h:N.height,scale:1,gen:0,ox:0,oy:0,margin:0})}function Ss(k,M){return Vo(k,M.map(C=>{let R=$t(C);return r.add(R),R}))}async function Ms(k,M,C){b.set(k,Ss(M,await Promise.all(M.pages.map(R=>Kr(new URL(R,C).href)))))}function Pa(k,M,C){r.add(C);let R=Array.isArray(M.frames)?M.frames:Object.entries(M.frames).map(([z,W])=>({...W,filename:z})),N=[],ne=[];for(let z of R){let W=z.frame,de=z.filename.replace(sa,"");z.rotated&&console.warn(`[engine] ${k}/${de} is rotated: export without rotation`);let ee={surface:C,x:W.x,y:W.y,w:W.w,h:W.h,scale:1,gen:0,ox:0,oy:0,margin:0};z.trimmed&&z.sourceSize&&z.spriteSourceSize&&(ee.sw=z.sourceSize.w,ee.sh=z.sourceSize.h,ee.tx=z.spriteSourceSize.x,ee.ty=z.spriteSourceSize.y);let _e=z.scale9Borders;_e&&(ee.slice=[_e.y,(ee.sw??W.w)-_e.x-_e.w,(ee.sh??W.h)-_e.y-_e.h,_e.x]),f.set(`${k}/${de}`,ee),N.push(`${k}/${de}`),ne.push((z.duration??0)/1e3)}for(let[z,W]of Object.entries(M.animations??{}))y.set(`${k}/${z}`,{frames:W.map(de=>`${k}/${de.replace(sa,"")}`)});for(let z of M.meta?.frameTags??[]){let W=[];for(let ee=z.from;ee<=z.to;ee++)W.push(ee);z.direction==="reverse"&&W.reverse(),z.direction==="pingpong"&&W.push(...W.slice(1,-1).reverse());let de=W.every(ee=>ne[ee]>0);y.set(`${k}/${z.name}`,{frames:W.map(ee=>N[ee]),...de?{durations:W.map(ee=>ne[ee])}:{}})}}return Ln}var sa=/\.(png|webp|jpe?g|gif|bmp)$/i;function Kr(s){return new Promise((n,e)=>{let t=new Image;t.onload=()=>n(t),t.onerror=()=>e(new Error(`[engine] image did not load: ${s}`)),t.src=s})}function nl(s){return new Promise(n=>{let e=[],t=0,r=o=>{t&&e.push(o-t),t=o,e.length<s?requestAnimationFrame(r):n(e)};requestAnimationFrame(r)})}async function rl(s,n,e,t,r,o=()=>!1){let a=t(),i=Vr(n,{type:"star",r:30,fill:"#ffd23f",stroke:"#3a2a10",lw:3},a).frame,l=[],c=[],u=new Float64Array(6),f=.004,h=s.kind==="canvas2d"?s.canvas.getContext("2d"):null,b=mt(),y=0;return await new Promise(m=>{let d=x=>{y&&x-b>250&&l.push(x-y),y=x;let g=mt();s.begin(0,0,a);let A=e();for(let w=0;w<300;w++){let v=x/1e3+w;Te(u,null,w*37%r,w*53%he,v,1,1),s.quad(A(i.surface),i,u,i.w/a,i.h/a,16777215,f,"normal")}for(let w=0;w<40;w++)s.ellipse(100+w*20,300,20,14,w,16746496,f),s.stroke([100+w*20,400,120+w*20,460,100+w*20,520],3,18,3368703,f,!1);s.end(),h?.getImageData(0,0,1,1),x-b>250&&c.push(mt()-g),x-b<750&&!o()?requestAnimationFrame(d):(s.begin(0,0,a),s.end(),m())};requestAnimationFrame(d)}),{intervals:l,cpu:c}}var sl=64,aa=32,ol=0,al=`fabi-cm-${Math.random().toString(36).slice(2,7)}-`,ia=new Set,la=(s,n)=>{ia.has(s)||(ia.add(s),console.warn(n))},ca=s=>new Zr(s),Zr=class{constructor(n){p(this,"r",n);p(this,"css","none");p(this,"plans",new Wt(sl));p(this,"buf",new Float64Array(64));p(this,"keys",[]);p(this,"classes",new Map);p(this,"live",new Set);p(this,"svgs",new Map);p(this,"t",0);p(this,"cur",null);p(this,"svgFn",n=>this.svg(n));p(this,"scr",[]);p(this,"flip",0)}chain(n,e){var y;let t=this.r,r=this.buf;r[0]=t.scale,r[1]=t.maxBlur;let o=2;for(let m=0;m<e.length;m++){let d=e[m];if(o+22>r.length){let g=new Float64Array(r.length*2);g.set(r),r=this.buf=g}let x=this.classes.get(d.constructor);x===void 0&&this.classes.set(d.constructor,x=this.classes.size),r[o++]=x,r[o++]=d.enabled?1:0,d.params&&(o=d.params(r,o))}let a=(y=this.keys)[o]??(y[o]=new Float64Array(o));for(let m=0;m<o;m++)a[m]=r[m];let i=Ue(a),l=this.plans.get(a,i);l||this.plans.set(a,l=this.plan(e),i);for(let m=0;m<l.svgs.length;m++){let d=l.svgs[m];d.used<0&&this.attach(d),d.used=this.t}t.skipped+=l.skip;let c=n,u=t.rx0,f=t.ry0,h=t.rx1-u,b=t.ry1-f;for(let m=0;m<l.paints.length;m++)l.parts[m]&&(c=this.bake(c,l.parts[m])),e[l.paints[m]].paint2d(c.getContext("2d"),u,f,h,b);return this.css=l.parts[l.paints.length]||"none",c}tick(){let n=++this.t;if(!(n%aa||!this.live.size))for(let e of this.live)n-e.used>aa&&this.detach(e)}destroy(){for(let n of this.live)this.detach(n);this.plans.clear()}svg(n){if(typeof document>"u"||!document.body)return null;let e=Array.from({length:20},(r,o)=>n[o]??0).join(" "),t=this.svgs.get(e);if(!t){let r="http://www.w3.org/2000/svg",o=document.createElementNS(r,"svg");o.setAttribute("width","0"),o.setAttribute("height","0"),o.setAttribute("aria-hidden","true"),o.style.position="absolute";let a=document.createElementNS(r,"filter"),i=al+ ++ol;a.setAttribute("id",i),a.setAttribute("color-interpolation-filters","sRGB");let l=document.createElementNS(r,"feColorMatrix");l.setAttribute("type","matrix"),l.setAttribute("values",e),a.append(l),o.append(a),this.attach(t={key:e,id:i,el:o,used:this.t})}return this.cur.svgs.push(t),`url(#${t.id})`}attach(n){document.body.append(n.el),this.live.add(n),this.svgs.has(n.key)||this.svgs.set(n.key,n)}detach(n){n.el.remove(),n.used=-1,this.live.delete(n),this.svgs.get(n.key)===n&&this.svgs.delete(n.key)}plan(n){let e=this.r,t=this.cur={parts:[],paints:[],skip:0,svgs:[]},r="";for(let o=0;o<n.length;o++){let a=n[o];if(!a.enabled)continue;if(a.kind===4){t.skip++,la("shader","[engine] shader() filters are WebGL only: on Canvas 2D they are skipped (check engine.supports.shaders)");continue}let i=e.support.filters&&a.css?a.css(e.scale,e.maxBlur,this.svgFn):null;i!==null?r+=r?` ${i}`:i:a.paint2d?(t.parts.push(r),t.paints.push(o),r=""):(t.skip++,la("css","[engine] this browser's Canvas 2D has no ctx.filter: colour filters, blur and shadows are skipped (tint works; check engine.supports.filters)"))}return t.parts.push(r),t}bake(n,e){let t=this.r,r=this.flip^=1,o=this.scr[r];(!o||o.width!==t.canvas.width||o.height!==t.canvas.height)&&(o=this.scr[r]=document.createElement("canvas"),o.width=t.canvas.width,o.height=t.canvas.height);let a=o.getContext("2d"),i=t.rx0,l=t.ry0,c=t.rx1-i,u=t.ry1-l;return a.clearRect(i,l,c,u),a.filter=e,a.drawImage(n,i,l,c,u,i,l,c,u),a.filter="none",o}};var il=64,lr=17,ll=s=>`${er}
|
|
49
49
|
uniform sampler2D uTexture;
|
|
50
50
|
uniform mat4 uM[${s}];
|
|
51
51
|
uniform vec4 uO[${s}];
|
|
@@ -61,11 +61,11 @@ void main() {
|
|
|
61
61
|
}
|
|
62
62
|
c.rgb *= c.a;
|
|
63
63
|
gl_FragColor = c * vColor;
|
|
64
|
-
}`,
|
|
64
|
+
}`,cl=()=>`${er}
|
|
65
65
|
uniform sampler2D uTexture;
|
|
66
66
|
uniform vec2 uDir;
|
|
67
67
|
uniform vec2 uOff;
|
|
68
|
-
uniform vec2 uTaps[${
|
|
68
|
+
uniform vec2 uTaps[${lr}];
|
|
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 < ${
|
|
77
|
+
for (int i = 1; i < ${lr}; 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
|
|
85
|
-
${i}`)}return t.set(n,{p:o,t:++this.uses}),o}scratch(n,e){let t=this.r,r=Math.ceil(t.canvas.width/n),o=Math.ceil(t.canvas.height/n),a=n*8+e,i=this.scratchT.get(a)??null;return i&&(i.w!==r||i.h!==o)&&(t.drop(i),i=null),i||(i=t.target(r,o,n,!0),i?this.scratchT.set(a,i):this.scratchT.delete(a)),i}pass(n,e,t,r,o=!1){let a=this.r,i=a.gl;a.flush(),a.mapped=!1,a.bindFb(r),i.viewport(0,0,r.w,r.h),o||(i.disable(i.SCISSOR_TEST),i.clearColor(0,0,0,0),i.clear(i.COLOR_BUFFER_BIT)),a.use(n);let l=r.f;i.uniform2f(n.uScale,2/(l*r.w),-2/(l*r.h));let c=Math.floor(a.rx0/l)*l,u=Math.floor(a.ry0/l)*l,f=Math.min(Math.ceil(a.rx1/l),r.w)*l,h=Math.min(Math.ceil(a.ry1/l),r.h)*l,b=1/(t*e.width),y=1/(t*e.height);a.bScis=!1,a.batch.push(c,u,f,u,f,h,c,h,c*b,1-u*y,f*b,1-h*y,4294967295,a.slotOf(e)),a.flush()}post(n){return n==="color"?this.colorProg??(this.colorProg=this.r.build(
|
|
84
|
+
}`;function ul(s,n,e=new Float32Array(20)){for(let t=0;t<4;t++)for(let r=0;r<5;r++){let o=r===4?n[t*5+4]:0;for(let a=0;a<4;a++)o+=n[t*5+a]*s[a*5+r];e[t*5+r]=o}return s.set(e),s}var ua=s=>new ns(s),ns=class{constructor(n){p(this,"r",n);p(this,"colorProg",null);p(this,"blurProg",null);p(this,"user",new Map);p(this,"uses",0);p(this,"userErr",new Map);p(this,"scratchT",new Map);p(this,"steps",[]);p(this,"mats",[]);p(this,"counts",[]);p(this,"colorN");p(this,"fm",new Float32Array(20));p(this,"fm2",new Float32Array(20));p(this,"fm3",new Float32Array(20));p(this,"m16");p(this,"o4");p(this,"taps",new Float32Array(lr*2));let e=n.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(n){return this.r.lost?null:(this.userProg(n,!1),this.userErr.get(n)??null)}destroy(){let n=this.r.gl;for(let e of this.scratchT.values())n.deleteTexture(e.gl),n.deleteFramebuffer(e.fb);this.scratchT.clear();for(let e of[this.colorProg,this.blurProg])e&&n.deleteProgram(e.p);for(let e of this.user.values())e.p&&n.deleteProgram(e.p.p);this.user.clear()}userProg(n,e){let t=this.user,r=t.get(n);if(r)return r.t=++this.uses,r.p;if(this.r.lost)return null;if(t.size>=il){let a="",i=1/0;for(let[c,u]of t)u.t<i&&(i=u.t,a=c);let l=t.get(a).p;l&&this.r.gl.deleteProgram(l.p),t.delete(a),this.userErr.delete(a)}let o;try{o=this.r.build(n)}catch(a){o=null;let i=a.message;this.userErr.set(n,i),e&&console.error(`[engine] a shader filter does not compile: it is skipped.
|
|
85
|
+
${i}`)}return t.set(n,{p:o,t:++this.uses}),o}scratch(n,e){let t=this.r,r=Math.ceil(t.canvas.width/n),o=Math.ceil(t.canvas.height/n),a=n*8+e,i=this.scratchT.get(a)??null;return i&&(i.w!==r||i.h!==o)&&(t.drop(i),i=null),i||(i=t.target(r,o,n,!0),i?this.scratchT.set(a,i):this.scratchT.delete(a)),i}pass(n,e,t,r,o=!1){let a=this.r,i=a.gl;a.flush(),a.mapped=!1,a.bindFb(r),i.viewport(0,0,r.w,r.h),o||(i.disable(i.SCISSOR_TEST),i.clearColor(0,0,0,0),i.clear(i.COLOR_BUFFER_BIT)),a.use(n);let l=r.f;i.uniform2f(n.uScale,2/(l*r.w),-2/(l*r.h));let c=Math.floor(a.rx0/l)*l,u=Math.floor(a.ry0/l)*l,f=Math.min(Math.ceil(a.rx1/l),r.w)*l,h=Math.min(Math.ceil(a.ry1/l),r.h)*l,b=1/(t*e.width),y=1/(t*e.height);a.bScis=!1,a.batch.push(c,u,f,u,f,h,c,h,c*b,1-u*y,f*b,1-h*y,4294967295,a.slotOf(e)),a.flush()}post(n){return n==="color"?this.colorProg??(this.colorProg=this.r.build(ll(this.colorN))):this.blurProg??(this.blurProg=this.r.build(cl()))}linear(n,e){let t=this.r,r=t.gl;t.bindTex(t.layerTex.get(n)??null,0);let o=e?r.LINEAR:r.NEAREST;r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MIN_FILTER,o),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MAG_FILTER,o)}chain(n,e,t){let r=this.r,o=this.steps,a=r.scale,i=r.maxBlur,l=0;for(let h=0;h<t.length;h++){let b=t[h];if(b.enabled)if(b.kind===1&&b.toMatrix){(!l||o[l-1]!==null)&&(o[l]=null,(!this.mats[l]||this.mats[l].length<20*this.colorN)&&(this.mats[l]=new Float32Array(20*this.colorN)),this.counts[l]=0,l++);let y=this.mats[l-1],m=this.counts[l-1];if(m<this.colorN)b.toMatrix(this.fm),y.set(this.fm,m*20),this.counts[l-1]=m+1;else{let d=(m-1)*20;for(let x=0;x<20;x++)this.fm2[x]=y[d+x];b.toMatrix(this.fm),ul(this.fm2,this.fm,this.fm3),y.set(this.fm2,d)}}else b.kind===4?this.userProg(b.source,!0)?o[l++]=b:r.skipped++:b.kind===2?Math.min(b.radius,i)*a>=.25&&(o[l++]=b):b.kind===3?o[l++]=b:r.skipped++}if(!l)return!1;let c=r.gl,u=n,f=-1;for(let h=0;h<l;h++){let b=h===l-1,y=f===0?1:0,m=b?null:this.scratch(1,y);if(!b&&!m)break;let d=o[h];if(d===null){let x=this.post("color");r.use(x);let g=this.mats[h],A=this.counts[h],w=this.m16,v=this.o4;for(let E=0;E<A;E++)for(let F=0;F<4;F++){for(let L=0;L<4;L++)w[E*16+L*4+F]=g[E*20+F*5+L];v[E*4+F]=g[E*20+F*5+4]}c.uniformMatrix4fv(r.u(x,"uM"),!1,w),c.uniform4fv(r.u(x,"uO"),v),c.uniform1i(r.u(x,"uK"),A),m?this.pass(x,u,1,m):r.final(x,u,1,e)}else if(d.kind===2)this.blur(u,f<0,Math.min(d.radius,i)*a,m,e,null);else if(d.kind===3){let x=d,g=this.scratch(1,2);if(!g)break;this.blur(u,f<0,Math.max(Math.min(x.blur,i),0)*a,g,1,x);let A=m??(e<1?this.scratch(1,y):null);A?(this.pass(r.main,g.tex,1,A),this.pass(r.main,u,1,A,!0),m||r.final(r.main,A.tex,1,e)):(r.final(r.main,g.tex,1,1),r.final(r.main,u,1,1))}else{let x=d,g=this.userProg(x.source,!0);r.use(g);let A=r.canvas.width,w=r.canvas.height;c.uniform2f(r.u(g,"uResolution"),A,w),c.uniform1f(r.u(g,"uTime"),r.time),c.uniform4f(r.u(g,"uRect"),r.rx0/A,1-r.ry1/w,r.rx1/A,1-r.ry0/w);let v=x.uniforms;for(let E in v){let F=r.u(g,E);if(!F)continue;let L=v[E];typeof L=="number"?c.uniform1f(F,L):L.length===2?c.uniform2fv(F,L):L.length===3?c.uniform3fv(F,L):L.length===4?c.uniform4fv(F,L):L.length===1&&c.uniform1fv(F,L)}m?this.pass(g,u,1,m):r.final(g,u,1,e)}m&&(u=m.tex,f=y)}return r.remap(),!0}blur(n,e,t,r,o,a){let i=this.r,l=i.gl,c=this.post("blur"),u=1;for(;u<16&&t/u>8;)u*=2;e&&this.linear(n,!0);let f=n,h=1,b=Math.sqrt(Math.max(t*t-(u*u-1)/12,0))/u,y=t>=.25?this.tapsFor(b):this.tapsFor(0),m=!0;if(y>1){for(let x=2;x<=u&&m;x*=2){let g=this.scratch(x,0);g?(this.pass(i.main,f,h,g),f=g.tex,h=x):m=!1}let d=m?this.scratch(u,3):null;d&&(i.use(c),l.uniform2fv(i.u(c,"uTaps"),this.taps),l.uniform1i(i.u(c,"uN"),y),l.uniform2f(i.u(c,"uDir"),1/f.width,0),l.uniform2f(i.u(c,"uOff"),0,0),l.uniform1f(i.u(c,"uMode"),0),this.pass(c,f,h,d),f=d.tex)}if(i.use(c),l.uniform2fv(i.u(c,"uTaps"),this.taps),l.uniform1i(i.u(c,"uN"),y),l.uniform2f(i.u(c,"uDir"),0,1/f.height),a){let d=a.opacity,x=a.rgb;l.uniform4f(i.u(c,"uShadow"),(x>>16&255)/255*d,(x>>8&255)/255*d,(x&255)/255*d,d),l.uniform1f(i.u(c,"uMode"),1),l.uniform2f(i.u(c,"uOff"),-a.dx*i.scale/(h*f.width),a.dy*i.scale/(h*f.height))}else l.uniform1f(i.u(c,"uMode"),0),l.uniform2f(i.u(c,"uOff"),0,0);r?this.pass(c,f,h,r):i.final(c,f,h,o),e&&this.linear(n,!1)}tapsFor(n){let e=this.taps;if(e.fill(0),e[1]=1,n<.2)return 1;let t=Math.min(Math.ceil(3*n),(lr-1)*2),r=-1/(2*n*n),o=1,a=1;for(let i=1;i<=t;i+=2){let l=Math.exp(i*i*r),c=i+1<=t?Math.exp((i+1)*(i+1)*r):0,u=l+c;e[a*2]=(i*l+(i+1)*c)/u,e[a*2+1]=u,o+=2*u,a++}for(let i=0;i<a;i++)e[i*2+1]=e[i*2+1]/o;return a}};var it=s=>Math.min(Math.max(s,0),1),We=s=>Math.max(s,0),Ct=class{constructor(){p(this,"enabled",!0);Ee.gl=ua,Ee.c2d=ca}},Qe=class extends Ct{constructor(e){super();p(this,"amount",e);p(this,"kind",1)}params(e,t){return e[t]=this.amount,t+1}};function cr(s,n,e){s.fill(0),s[0]=s[6]=s[12]=n,s[4]=s[9]=s[14]=e,s[18]=1}function ur(s,n){s.fill(0);for(let e=0;e<3;e++)for(let t=0;t<3;t++)s[e*5+t]=n[e*3+t];s[18]=1}var D=new Float64Array(9),ss=class extends Qe{toMatrix(n){cr(n,We(this.amount),0)}css(){return`brightness(${We(this.amount)})`}},os=class extends Qe{toMatrix(n){let e=We(this.amount);cr(n,e,.5-.5*e)}css(){return`contrast(${We(this.amount)})`}},as=class extends Qe{toMatrix(n){let e=it(this.amount);cr(n,1-2*e,e)}css(){return`invert(${it(this.amount)})`}},is=class extends Qe{toMatrix(n){let e=We(this.amount);D[0]=.213+.787*e,D[1]=.715-.715*e,D[2]=.072-.072*e,D[3]=.213-.213*e,D[4]=.715+.285*e,D[5]=.072-.072*e,D[6]=.213-.213*e,D[7]=.715-.715*e,D[8]=.072+.928*e,ur(n,D)}css(){return`saturate(${We(this.amount)})`}},ls=class extends Qe{toMatrix(n){let e=1-it(this.amount);D[0]=.2126+.7874*e,D[1]=.7152-.7152*e,D[2]=.0722-.0722*e,D[3]=.2126-.2126*e,D[4]=.7152+.2848*e,D[5]=.0722-.0722*e,D[6]=.2126-.2126*e,D[7]=.7152-.7152*e,D[8]=.0722+.9278*e,ur(n,D)}css(){return`grayscale(${it(this.amount)})`}},cs=class extends Qe{toMatrix(n){let e=1-it(this.amount);D[0]=.393+.607*e,D[1]=.769-.769*e,D[2]=.189-.189*e,D[3]=.349-.349*e,D[4]=.686+.314*e,D[5]=.168-.168*e,D[6]=.272-.272*e,D[7]=.534-.534*e,D[8]=.131+.869*e,ur(n,D)}css(){return`sepia(${it(this.amount)})`}},us=class extends Qe{get angle(){return this.amount}set angle(n){this.amount=n}toMatrix(n){let e=this.amount*Math.PI/180,t=Math.cos(e),r=Math.sin(e);D[0]=.213+t*.787-r*.213,D[1]=.715-t*.715-r*.715,D[2]=.072-t*.072+r*.928,D[3]=.213-t*.213+r*.143,D[4]=.715+t*.285+r*.14,D[5]=.072-t*.072-r*.283,D[6]=.213-t*.213-r*.787,D[7]=.715-t*.715+r*.715,D[8]=.072+t*.928+r*.072,ur(n,D)}css(){return`hue-rotate(${this.amount}deg)`}},hs=class extends Qe{constructor(e,t){super(t);p(this,"c",16777215);p(this,"cs","");this.color=e}get color(){return this.c}set color(e){this.c=me(e)[0],this.cs=At(this.c)}params(e,t){return e[t]=this.amount,e[t+1]=this.c,t+2}toMatrix(e){let t=it(this.amount);cr(e,1-t,0),e[4]=(this.c>>16&255)/255*t,e[9]=(this.c>>8&255)/255*t,e[14]=(this.c&255)/255*t}css(){return null}paint2d(e,t,r,o,a){let i=it(this.amount);i<=0||(e.save(),e.setTransform(1,0,0,1,0,0),e.globalAlpha=i,e.globalCompositeOperation="source-atop",e.fillStyle=this.cs,e.fillRect(t,r,o,a),e.restore())}},fs=class extends Ct{constructor(e){super();p(this,"kind",1);p(this,"values");if(e.length!==20)throw new Error(`colorMatrix: 20 numbers expected (4 rows of 5), got ${e.length}`);this.values=Array.from(e)}toMatrix(e){for(let t=0;t<20;t++)e[t]=this.values[t]??0}params(e,t){for(let r=0;r<20;r++)e[t+r]=this.values[r]??0;return t+20}css(e,t,r){return r?r(this.values):null}},ps=class extends Ct{constructor(e){super();p(this,"radius",e);p(this,"kind",2)}params(e,t){return e[t]=this.radius,t+1}pad(e){return 3*Math.min(We(this.radius),e)}css(e,t){return`blur(${Math.min(We(this.radius),t)*e}px)`}},ds=class extends Ct{constructor(e,t,r,o){super();p(this,"dx",e);p(this,"dy",t);p(this,"blur",r);p(this,"kind",3);p(this,"rgb",0);p(this,"a",1);this.color=o}get opacity(){return this.a}set opacity(e){this.a=it(e)}get color(){return this.rgb}set color(e){let[t,r]=me(e);this.rgb=t,this.a=r}params(e,t){return e[t]=this.dx,e[t+1]=this.dy,e[t+2]=this.blur,e[t+3]=this.rgb,e[t+4]=this.a,t+5}pad(e){return 3*Math.min(We(this.blur),e)+Math.max(Math.abs(this.dx),Math.abs(this.dy))}css(e,t){return`drop-shadow(${this.dx*e}px ${this.dy*e}px ${2*Math.min(We(this.blur),t)*e}px ${At(this.rgb,this.opacity)})`}},hl=`#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
|
-
`,
|
|
98
|
+
`,fl=s=>`${hl}${s}
|
|
99
99
|
#undef main
|
|
100
100
|
void main() {
|
|
101
101
|
fabiUserMain();
|
|
102
102
|
gl_FragColor *= vColor.a;
|
|
103
103
|
}
|
|
104
|
-
`,
|
|
105
|
-
${e}`);return n}var
|
|
104
|
+
`,ms=class extends Ct{constructor(e){super();p(this,"kind",4);p(this,"source");p(this,"uniforms",{});p(this,"padding");this.source=fl(e.fragment),this.padding=e.padding??0;for(let t in e.uniforms??{}){let r=e.uniforms[t];this.uniforms[t]=typeof r=="number"?r:Float32Array.from(r)}}pad(){return We(this.padding)}},ha=(s,n=1)=>new hs(s,n),fa=s=>new ss(s),pa=s=>new os(s),da=s=>new is(s),ma=(s=1)=>new ls(s),ba=(s=1)=>new cs(s),ya=s=>new us(s),xa=(s=1)=>new as(s),ga=s=>new fs(s),ka=s=>new ps(s),wa=(s,n,e,t="rgba(0,0,0,0.5)")=>new ds(s,n,e,t);function va(s){let n=new ms(s),e=Ee.live?.filters()?.check(n.source);if(e)throw new Error(`shader(): the fragment does not compile:
|
|
105
|
+
${e}`);return n}var bs="x y rotation scaleX scaleY alpha visible blend tint z hitRadius clip mask filters".split(" "),Sa="frameName _frame _w _h slice autoAnchor".split(" "),pl="fps loop speed onComplete durations".split(" "),ys=["anchorX","anchorY"],dl=[...bs,...Sa,...pl,...ys],ml=[...bs,...Sa,...ys],bl=[...bs,...ys],Ma=s=>s instanceof Ne?dl:s instanceof Re?ml:bl;function yl(s){let n={},e=s;for(let t of Ma(s))n[t]=e[t];return s instanceof Xe&&(n.spec=s.spec),s instanceof Ye&&(n.text=s.text,n.style=s.style),s instanceof Ne&&(n.playing=s.playing),n}function Aa(s,n){let e=s;s instanceof Xe&&s.spec!==n.spec&&(s.spec=n.spec),s instanceof Ye&&(s.text=n.text,s.style!==n.style&&(e._style=n.style,e.dirty=!0)),s instanceof Ne&&s.gotoFrame(n.speed<0?s.frameCount-1:0);let t=s instanceof Xe||s instanceof Ye,r=Ma(s);for(let o=0;o<r.length;o++){let a=r[o];(!t||a!=="_frame"&&a!=="frameName")&&(e[a]=n[a])}}var En=class{constructor(n,e={}){p(this,"factory",n);p(this,"opts",e);p(this,"stats",{live:0,free:0,created:0});p(this,"free",[]);p(this,"states",new Map);p(this,"dead",!1)}get(n){if(this.dead)throw new Error("[engine] nodePool.get() after destroy()");let e=this.free.pop();if(e){this.stats.free--,e._free=!1;let t=this.states.get(e);Aa(e,t),e.visible=t.visible,e instanceof Ne&&t.playing&&e.play()}else{if(e=this.factory(),!(e instanceof Ie))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,yl(e)),e._pool=this,this.stats.created++}return this.stats.live++,n&&e.set(n),e}release(n){let e=this.states.get(n);if(!(!e||n.destroyed)&&!n._free){if(this.opts.max!==void 0&&this.free.length>=this.opts.max)return n.destroy();n.parent?.remove(n),n.kernel.tweens.stopAll(n),this.stats.live--,Aa(n,e),n instanceof Ne&&n.stop(),n.visible=!1,n._free=!0,this.opts.reset?.(n),this.free.push(n),this.stats.free++}}forget(n){let e=n;if(this.states.delete(e))if(e._free){let t=this.free.indexOf(e);t>=0&&(this.free[t]=this.free[this.free.length-1],this.free.pop()),this.stats.free--}else this.stats.live--}clear(){for(;this.free.length;)this.free[this.free.length-1].destroy()}destroy(){this.dead=!0;for(let n of[...this.states.keys()])n.destroy()}},Ta=(s,n)=>new En(s,n);window.FabiEngine=xs;})();
|