@fabiplay/engine 0.9.0 → 0.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/fabi-play-engine.js +1 -105
- package/dist/fabi-play-engine.lite.js +1 -105
- package/dist/fabi-play-engine.lite.umd.js +1038 -972
- package/dist/fabi-play-engine.lite.umd.min.js +1 -105
- package/dist/fabi-play-engine.umd.js +1225 -1131
- package/dist/fabi-play-engine.umd.min.js +1 -105
- package/dist/index.development.js +2 -2
- package/dist/index.js +1 -1
- package/dist/integrity.json +7 -7
- package/package.json +5 -5
|
@@ -1,105 +1 @@
|
|
|
1
|
-
/*! @fabiplay/engine 0.9.0 (full) | Fabi Play Kit License | https://docs.fabiplay.app */(function(_i,re){var Ze=typeof document<"u"?document.currentScript:null;typeof define=="function"&&define.amd?define([],function(){return re(Ze)}):typeof module=="object"&&module&&module.exports?module.exports=re(Ze):_i.FabiEngine=re(Ze)})(typeof globalThis<"u"?globalThis:typeof self<"u"?self:this,function(_i){"use strict";var re={exports:{}},Ze=re.exports,Je=Object.defineProperty,kr=Object.getOwnPropertyDescriptor,wr=Object.getOwnPropertyNames,vr=Object.prototype.hasOwnProperty,Mr=(t,e,s)=>e in t?Je(t,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[e]=s,Er=(t,e)=>{for(var s in e)Je(t,s,{get:e[s],enumerable:!0})},Ar=(t,e,s,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of wr(e))!vr.call(t,n)&&n!==s&&Je(t,n,{get:()=>e[n],enumerable:!(i=kr(e,n))||i.enumerable});return t},_r=t=>Ar(Je({},"__esModule",{value:!0}),t),d=(t,e,s)=>Mr(t,typeof e!="symbol"?e+"":e,s),Si={};Er(Si,{AnimatedSprite:()=>fe,Atlas:()=>Ks,AvatarPainter:()=>ui,AvatarsNode:()=>sr,BitmapFont:()=>di,DEFAULT_FONT:()=>Dn,EASE:()=>ze,Group:()=>Qs,HALO:()=>$e,MAX_LAYERS:()=>Ws,NameTags:()=>ci,Node:()=>he,NodePool:()=>fr,Particles:()=>pn,STAGE_HEIGHT:()=>ft,Shape:()=>He,ShelfPacker:()=>yn,Sound:()=>Yn,Sprite:()=>we,TIERS:()=>qt,Text:()=>qe,Timeline:()=>tr,Tweens:()=>er,avatarPortrait:()=>Fo,blur:()=>Ol,brightness:()=>Tl,colorMatrix:()=>Il,contrast:()=>Cl,createAvatarRenderer:()=>Ro,createEngine:()=>Jo,createRenderer:()=>li,dropShadow:()=>zl,grayscale:()=>Fl,handsOf:()=>$n,hits:()=>pi,hueRotate:()=>Pl,invert:()=>Nl,nodePool:()=>$l,packColor:()=>ke,parseBMFont:()=>ks,parseColor:()=>Bt,pickTier:()=>jn,playerColor:()=>ws,rendererOrder:()=>zn,rng:()=>Ba,saturate:()=>Rl,sepia:()=>Ll,shader:()=>Dl,shapeBounds:()=>fi,tier:()=>ue,tint:()=>Sl,touching:()=>qn,wrists:()=>Xn}),re.exports=_r(Si);var Ti=33,H={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},Sr=["3-5","6-8","9-12"],Tr=t=>Sr.includes(t),Cr=4,ts=["#EE6A43","#6FA0E0","#8CC9A0","#C49BE0"],Ci={"3-5":["bunny","bear","panda","penguin"],"6-8":["fox","lion","dragon","unicorn"],"9-12":["robot","astronaut","ninja","skater"]},Rr=Ci["6-8"],Ri=(t,e)=>{const s=Tr(e)?Ci[e]:Rr;return s[Number.isInteger(t)&&t>=0?t%s.length:0]},Fi=(t,e)=>t?{x:t.x+e.x*t.w,y:t.y+e.y*t.h}:{x:e.x,y:e.y},Fr=.5,es={left:1.6,top:1.6,w:3.2,h:3},Lr=1.2;function Pr(t,e,s={}){const i=Array.isArray(t)?t:t.body;if(!Array.isArray(i))return null;const n=e==="left"?H.leftWrist:H.rightWrist,r=g=>Fe(i[g*3])&&Fe(i[g*3+1])&&(i[g*3+2]??0)>=Fr?g:-1;if(r(n)<0)return null;const a=i[n*3],l=i[n*3+1];if(s.orientation!=="portrait")return Fi(s.view,{x:a,y:l});if(r(H.leftShoulder)<0||r(H.rightShoulder)<0)return null;const h=H.leftShoulder*3,o=H.rightShoulder*3,c=(i[h]+i[o])/2,u=(i[h+1]+i[o+1])/2,f=H.leftHip*3,y=H.rightHip*3,p=(i[f]+i[y])/2,x=(i[f+1]+i[y+1])/2;let m=Fe(p)&&Fe(x)?Math.hypot(p-c,x-u):0;return(r(H.leftHip)<0||r(H.rightHip)<0)&&(m=Math.max(m,Lr*Math.hypot(i[h]-i[o],i[h+1]-i[o+1]))),m=Math.max(m,.01),{x:Pi((a-c+es.left*m)/(es.w*m)),y:Pi((l-u+es.top*m)/(es.h*m))}}var Nr=300,Li=class{constructor(t=Nr){d(this,"holdMs",t),d(this,"last",new Map)}static key(t,e){return t*2+(e==="right"?1:0)}at(t,e,s){const i=this.last.get(t);return e?(i?(i.x=e.x,i.y=e.y,i.t=s):this.last.set(t,{x:e.x,y:e.y,t:s}),e):i?s-i.t<=this.holdMs?{x:i.x,y:i.y}:(this.last.delete(t),null):null}clear(){this.last.clear()}},Ir=.25,Or=Object.freeze({top:0,bottom:0,left:0,right:0});function zr(t){if(!Dr(t))return;const e=s=>Fe(s)?Math.min(Math.max(s,0),Ir):0;return{top:e(t.top),bottom:e(t.bottom),left:e(t.left),right:e(t.right)}}var Zl=16/9,Dr=t=>typeof t=="object"&&t!==null&&!Array.isArray(t),Fe=t=>typeof t=="number"&&Number.isFinite(t),Pi=t=>Math.min(Math.max(t,0),1),Br=12,Ur=Ti*4,Hr=t=>Br+t*Ur,Jl=Hr(Cr),Gr=t=>t.startsWith("fabi-play.")?`fablee-play.${t.slice(10)}`:null;function Xr(t,e,s=Gr(e)){if(!(!t||!s))try{const i=t.getItem(s);if(i===null)return;t.getItem(e)===null&&t.setItem(e,i),t.removeItem(s)}catch{}}var xt="#4a382c",ht="#2b2118",Et="#1c1f2b",Ni="#fbefe3",Ft="#f4897a",Le="#3a2a22",Ii=[{id:"fox",name:{en:"Fox",it:"Volpe"},band:"6-8",palette:{body:"#ee6a43",limbs:"#ee6a43",belly:Ni,accent:"#ffd9c2",outline:ht,hands:"#5a3426",feet:"#5a3426"},head:"wide",ears:"pointy",face:{eyes:"dot",mouth:"cat",nose:Le,muzzle:"cheeks"},tail:"fluffy",headExtras:[],bodyExtras:[]},{id:"mascot",name:{en:"Fabi",it:"Fabi"},band:"all",special:!0,palette:{body:"#ee6a43",limbs:"#ee6a43",belly:Ni,accent:"#5a3426",outline:ht,hands:"#5a3426",feet:"#5a3426"},head:"wide",ears:"pointy",face:{eyes:"bead",mouth:"open",nose:Le,muzzle:"band",cheeks:Ft},tail:"brush",headExtras:[],bodyExtras:["star"],extraColors:["#ffd84a"]},{id:"bunny",name:{en:"Bunny",it:"Coniglietto"},band:"3-5",palette:{body:"#f9d0de",limbs:"#f9d0de",belly:"#fff6f8",accent:"#f4a0b9",outline:xt},head:"round",ears:"long",face:{eyes:"dot",mouth:"cat",nose:"#e0607e",muzzle:"none",cheeks:Ft},tail:"pom",headExtras:[],bodyExtras:[]},{id:"bear",name:{en:"Bear",it:"Orsetto"},band:"3-5",palette:{body:"#cf9f78",limbs:"#cf9f78",belly:"#f7e0bf",accent:"#f7e0bf",outline:xt},head:"round",ears:"round",face:{eyes:"dot",mouth:"smile",nose:Le,muzzle:"oval",cheeks:Ft},tail:"none",headExtras:[],bodyExtras:[]},{id:"cat",name:{en:"Cat",it:"Gattino"},band:"3-5",palette:{body:"#c8b6ee",limbs:"#c8b6ee",belly:"#f4eeff",accent:"#f7b3c8",outline:xt,hands:"#f4eeff",feet:"#f4eeff"},head:"wide",ears:"pointy",face:{eyes:"big",eyeColor:"#3f9a5a",mouth:"cat",nose:"#f07a9a",muzzle:"none",cheeks:Ft},tail:"long",headExtras:["whiskers"],bodyExtras:[]},{id:"panda",name:{en:"Panda",it:"Panda"},band:"3-5",palette:{body:"#ffffff",limbs:"#6e6674",belly:"#ffffff",accent:"#6e6674",outline:xt,ears:"#6e6674"},head:"wide",ears:"round",face:{eyes:"mask",mouth:"smile",nose:"#2f2a2c",muzzle:"none",cheeks:"#f6a3a3"},tail:"none",headExtras:[],bodyExtras:[]},{id:"penguin",name:{en:"Penguin",it:"Pinguino"},band:"3-5",palette:{body:"#6c8fca",limbs:"#6c8fca",belly:"#ffffff",accent:"#f9b95c",outline:xt,feet:"#f9b95c"},head:"tall",ears:"none",face:{eyes:"dot",mouth:"beak",muzzle:"heart",cheeks:"#f6a3a3"},tail:"none",headExtras:[],bodyExtras:["flippers","scarf"],extraColors:["#f6907a"]},{id:"frog",name:{en:"Frog",it:"Ranocchio"},band:"3-5",palette:{body:"#8fd487",limbs:"#8fd487",belly:"#e6f7cc",accent:"#62ad62",outline:xt},head:"wide",ears:"none",face:{eyes:"big",eyesOnTop:!0,mouth:"open",muzzle:"none",cheeks:"#f59b8f"},tail:"none",headExtras:[],bodyExtras:["flippers","spots"],extraColors:["#62ad62","#b0e6a4"]},{id:"lion",name:{en:"Lion",it:"Leoncino"},band:"6-8",alsoIn:["3-5"],palette:{body:"#f6c454",limbs:"#f6c454",belly:"#fde7b0",accent:"#fde7b0",outline:ht},head:"round",ears:"round",face:{eyes:"dot",mouth:"cat",nose:"#8a4b2a",muzzle:"oval",cheeks:Ft},tail:"tuft",headExtras:["mane"],bodyExtras:[],extraColors:["#c8692e"]},{id:"unicorn",name:{en:"Unicorn",it:"Unicorno"},band:"6-8",palette:{body:"#fbf5ff",limbs:"#fbf5ff",belly:"#efe0ff",accent:"#fbd46a",outline:ht,hands:"#c9a6f2",feet:"#c9a6f2"},head:"tall",ears:"unicorn",face:{eyes:"dot",mouth:"smile",muzzle:"none",cheeks:"#f7a6c8"},tail:"none",headExtras:["rainbow-mane"],bodyExtras:[],extraColors:["#f58cc0","#8fd3f4","#a98ff2"]},{id:"dragon",name:{en:"Little Dragon",it:"Draghetto"},band:"6-8",palette:{body:"#8a63d2",limbs:"#8a63d2",belly:"#fbd46a",accent:"#5fd0b5",outline:ht},head:"wide",ears:"horns",face:{eyes:"big",eyeColor:"#3a2a6a",mouth:"teeth",muzzle:"none",cheeks:"#f59bc0"},tail:"arrow",headExtras:[],bodyExtras:["wings"]},{id:"robot",name:{en:"Robot",it:"Robot"},band:"9-12",palette:{body:"#b9c7d2",limbs:"#8b9aa6",belly:"#b9c7d2",accent:"#ee6a43",outline:Et,hands:"#ee6a43",feet:"#6b7a86"},head:"square",ears:"antenna",face:{eyes:"screen",eyeColor:"#7ff0ff",mouth:"grill",muzzle:"none"},tail:"none",headExtras:["bolts"],bodyExtras:["panel","joints","boots"],extraColors:["#ff7a6b","#fbd46a","#7ff0ff"]},{id:"astronaut",name:{en:"Astronaut",it:"Astronauta"},band:"9-12",palette:{body:"#f4f1ec",limbs:"#f4f1ec",belly:"#f4f1ec",accent:"#ee6a43",outline:Et,hands:"#9fb0bd",feet:"#9fb0bd"},head:"round",ears:"none",face:{eyes:"visor",mouth:"smile",muzzle:"none"},tail:"none",headExtras:["helmet"],bodyExtras:["backpack","badge","boots"],extraColors:["#c9d3db"]},{id:"dinosaur",name:{en:"Dinosaur",it:"Dinosauro"},band:"6-8",palette:{body:"#3fb3a6",limbs:"#3fb3a6",belly:"#c9f0d6",accent:"#f79a3e",outline:ht},head:"wide",ears:"none",face:{eyes:"dot",mouth:"teeth",muzzle:"none",cheeks:"#f59b8f"},tail:"spiky",headExtras:["spikes","spots"],bodyExtras:[],extraColors:["#2b8f84","#7fd3c6"]},{id:"monkey",name:{en:"Monkey",it:"Scimmietta"},band:"6-8",palette:{body:"#7b5234",limbs:"#7b5234",belly:"#f2c9a0",accent:"#f2c9a0",outline:ht,hands:"#f2c9a0",feet:"#f2c9a0"},head:"round",ears:"side",face:{eyes:"dot",mouth:"open",nose:"#5a3a26",muzzle:"monkey",cheeks:Ft},tail:"curl",headExtras:["tuft"],bodyExtras:[]},{id:"koala",name:{en:"Koala",it:"Koala"},band:"3-5",palette:{body:"#b7bcc6",limbs:"#b7bcc6",belly:"#eef0f3",accent:"#f4dbe2",outline:xt},head:"wide",ears:"big-round",face:{eyes:"dot",mouth:"smile",nose:"#3b3438",muzzle:"none",cheeks:"#f4a3b0"},tail:"none",headExtras:[],bodyExtras:[]},{id:"tiger",name:{en:"Tiger",it:"Tigrotto"},band:"6-8",palette:{body:"#f9a33a",limbs:"#f9a33a",belly:"#fff1dc",accent:"#fff1dc",outline:ht},head:"wide",ears:"round",face:{eyes:"dot",mouth:"cat",nose:"#e2607a",muzzle:"oval",cheeks:Ft},tail:"striped",headExtras:["stripes","whiskers"],bodyExtras:[],extraColors:["#3a2a22"]},{id:"owl",name:{en:"Owl",it:"Gufetto"},band:"3-5",palette:{body:"#8ec0e6",limbs:"#8ec0e6",belly:"#e3f2fc",accent:"#639cc9",outline:xt,feet:"#f9b95c",hands:"#639cc9"},head:"tall",ears:"tufts",face:{eyes:"big",eyeColor:xt,eyeRing:"#fde08a",mouth:"beak",muzzle:"none",cheeks:"#f6a8b4"},tail:"none",headExtras:[],bodyExtras:["feathers"]},{id:"alien",name:{en:"Alien",it:"Alieno"},band:"9-12",palette:{body:"#9ee05a",limbs:"#9ee05a",belly:"#d8f5a8",accent:"#b07cf2",outline:Et},head:"bulb",ears:"antennae",face:{eyes:"almond",eyeColor:"#1e1838",mouth:"smirk",muzzle:"none"},tail:"none",headExtras:[],bodyExtras:["spots"],extraColors:["#7cc23e","#7cc23e"]},{id:"ghost",name:{en:"Friendly Ghost",it:"Fantasmino"},band:"6-8",palette:{body:"#e6f4ff",limbs:"#e6f4ff",belly:"#e6f4ff",accent:"#bcd9f2",outline:ht},head:"round",ears:"none",face:{eyes:"dot",mouth:"open",muzzle:"none",cheeks:"#f7a6c8"},tail:"none",headExtras:["curl"],bodyExtras:["sheet"]},{id:"octopus",name:{en:"Octopus",it:"Polpetto"},band:"6-8",palette:{body:"#e0578a",limbs:"#e0578a",belly:"#f7b3cc",accent:"#f7b3cc",outline:ht,hands:"#f7b3cc",feet:"#f7b3cc"},head:"tall",ears:"none",face:{eyes:"big",eyeColor:"#3a2140",mouth:"smile",muzzle:"none",cheeks:"#ffd0a0"},tail:"none",headExtras:["spots"],bodyExtras:["tentacles"],extraColors:["#f7b3cc","#f7b3cc"]},{id:"chick",name:{en:"Chick",it:"Pulcino"},band:"3-5",palette:{body:"#ffd45e",limbs:"#ffd45e",belly:"#fff2c2",accent:"#ffa04a",outline:xt,hands:"#ffc23d",feet:"#ffa04a"},head:"round",ears:"none",face:{eyes:"dot",mouth:"beak",muzzle:"none",cheeks:Ft},tail:"none",headExtras:["eggshell"],bodyExtras:[],extraColors:["#fffaf0"]},{id:"puppy",name:{en:"Puppy",it:"Cucciolo"},band:"3-5",palette:{body:"#f4e4cf",limbs:"#f4e4cf",belly:"#fffaf2",accent:"#f29aa4",outline:xt,ears:"#b58262",hands:"#e6caa6",feet:"#e6caa6"},head:"wide",ears:"floppy",face:{eyes:"dot",mouth:"open",nose:Le,muzzle:"oval",cheeks:Ft},tail:"curl",headExtras:["eye-spot"],bodyExtras:[]},{id:"lamb",name:{en:"Lamb",it:"Agnellino"},band:"3-5",palette:{body:"#fdf8ee",limbs:"#e3d1c2",belly:"#fffdf8",accent:"#f6bcc2",outline:xt,skin:"#f7dccb",hands:"#a58c7e",feet:"#a58c7e"},head:"round",ears:"droopy",face:{eyes:"dot",mouth:"smile",nose:"#e591a0",muzzle:"none",cheeks:Ft},tail:"pom",headExtras:["wool"],bodyExtras:["wool"]},{id:"duckling",name:{en:"Duckling",it:"Anatroccolo"},band:"3-5",palette:{body:"#fff1a6",limbs:"#fff1a6",belly:"#fffbe0",accent:"#ff9f43",outline:xt,feet:"#ff9f43"},head:"tall",ears:"none",face:{eyes:"dot",mouth:"bill",muzzle:"none",cheeks:Ft},tail:"none",headExtras:["curl"],bodyExtras:["flippers","scarf"],extraColors:["#86cfe0"]},{id:"shark",name:{en:"Shark",it:"Squalo"},band:"6-8",palette:{body:"#6c95c4",limbs:"#6c95c4",belly:"#eef5fb",accent:"#4c76a8",outline:ht,hands:"#eef5fb",feet:"#4c76a8"},head:"wide",ears:"fin",face:{eyes:"dot",mouth:"jaws",muzzle:"none",cheeks:"#f59bb0"},tail:"fish",headExtras:["gills"],bodyExtras:[]},{id:"wolf",name:{en:"Wolf",it:"Lupo"},band:"6-8",palette:{body:"#8f9bb3",limbs:"#8f9bb3",belly:"#eef1f6",accent:"#f3b8c4",outline:ht,hands:"#5a647a",feet:"#5a647a"},head:"round",ears:"pointy",face:{eyes:"dot",mouth:"open",nose:Le,muzzle:"oval",cheeks:"#f4a3b0"},tail:"fluffy",headExtras:["ruff","forehead"],bodyExtras:[],extraColors:["#636d84"]},{id:"parrot",name:{en:"Parrot",it:"Pappagallo"},band:"6-8",palette:{body:"#e8503f",limbs:"#e8503f",belly:"#ffd25a",accent:"#f6e6c4",outline:ht,hands:"#3a9bdc",feet:"#8a7a70"},head:"round",ears:"none",face:{eyes:"big",eyeColor:ht,eyeRing:"#ffffff",mouth:"hook",muzzle:"none",cheeks:"#ffb0a0"},tail:"plume",headExtras:["crest"],bodyExtras:["feathers"],extraColors:["#ffd25a","#3fae5a","#3a9bdc"]},{id:"ninja",name:{en:"Ninja",it:"Ninja"},band:"9-12",palette:{body:"#2f3a56",limbs:"#2f3a56",belly:"#2f3a56",accent:"#36c9bb",outline:Et,skin:"#b07a52",hands:"#222a40",feet:"#222a40"},head:"round",ears:"none",face:{eyes:"calm",mouth:"none",muzzle:"none",brows:"#2a1d16"},tail:"none",headExtras:["ninja-hood"],bodyExtras:["belt"],extraColors:["#36c9bb","#36c9bb","#36c9bb"]},{id:"skater",name:{en:"Skater",it:"Skater"},band:"9-12",palette:{body:"#3a8fc0",limbs:"#2c3e57",belly:"#2f7aa6",accent:"#ffcf3a",outline:Et,skin:"#f2c9a5",hair:"#7a4a2a",hands:"#f2c9a5",feet:"#eef1f5"},head:"round",ears:"human",face:{eyes:"calm",mouth:"smirk",muzzle:"none",brows:"#5a3520"},tail:"none",headExtras:["hair","cap"],bodyExtras:["pocket","joints"],extraColors:["#ff5d73"]},{id:"explorer",name:{en:"Explorer",it:"Giramondo"},band:"9-12",palette:{body:"#5f8f5b",limbs:"#5f8f5b",belly:"#5f8f5b",accent:"#d9bb7e",outline:Et,skin:"#7a4a30",hair:"#1d1410",hands:"#7a4a30",feet:"#6b4a2a"},head:"round",ears:"human",face:{eyes:"calm",mouth:"smile",muzzle:"none",brows:"#1d1410"},tail:"none",headExtras:["curls","safari-hat"],bodyExtras:["backpack","straps","boots"],extraColors:["#e07b39","#6b4a2a"]},{id:"wizard",name:{en:"Wizard",it:"Mago"},band:"9-12",palette:{body:"#5b3fa0",limbs:"#5b3fa0",belly:"#5b3fa0",accent:"#3d5fc8",outline:Et,skin:"#c98d62",hair:"#a8452a",hands:"#c98d62",feet:"#33255e"},head:"round",ears:"human",face:{eyes:"calm",mouth:"smile",muzzle:"none",brows:"#7a301c"},tail:"none",headExtras:["locks","wizard-hat"],bodyExtras:["robe","belt"],extraColors:["#ffd84a","#ffd84a","#ffd84a"]},{id:"knight",name:{en:"Knight",it:"Cavaliere"},band:"9-12",palette:{body:"#bcc7d3",limbs:"#8e9aa8",belly:"#dce3ea",accent:"#d8443a",outline:Et,hands:"#6c7786",feet:"#6c7786"},head:"bucket",ears:"none",face:{eyes:"slit",eyeColor:"#bfefff",mouth:"none",muzzle:"none"},tail:"none",headExtras:["plume"],bodyExtras:["pauldrons","emblem","boots"],extraColors:["#d8443a"]},{id:"racer",name:{en:"Racer",it:"Pilota"},band:"9-12",palette:{body:"#ff6a2b",limbs:"#ff6a2b",belly:"#ffffff",accent:"#ffffff",outline:Et,hands:"#232838",feet:"#232838"},head:"round",ears:"none",face:{eyes:"goggle",eyeColor:"#7fd6ff",mouth:"none",muzzle:"none"},tail:"none",headExtras:["stripe"],bodyExtras:["racing-stripe","boots"]},{id:"pirate",name:{en:"Pirate",it:"Pirata"},band:"9-12",palette:{body:"#f2efe6",limbs:"#2a3d6e",belly:"#f2efe6",accent:"#d94545",outline:Et,skin:"#d9a072",hair:"#2b1a12",hands:"#d9a072",feet:"#3a2a20"},head:"round",ears:"human",face:{eyes:"calm",mouth:"smirk",muzzle:"none",brows:"#2b1a12"},tail:"none",headExtras:["locks","bandana","eye-patch"],bodyExtras:["stripes","belt","boots"],extraColors:["#d94545","#2a3d6e","#4a3426"]},{id:"diver",name:{en:"Diver",it:"Sub"},band:"9-12",palette:{body:"#1f6582",limbs:"#1f6582",belly:"#1f6582",accent:"#ffb020",outline:Et,skin:"#e8b48a",hair:"#c98f2e",hands:"#1b4f66",feet:"#ffb020"},head:"round",ears:"human",face:{eyes:"calm",mouth:"smile",muzzle:"none",brows:"#8a5a1a"},tail:"none",headExtras:["curls","dive-mask"],bodyExtras:["tank","fins"],extraColors:["#c9d3db"]},{id:"hero",name:{en:"Hero",it:"Supereroe"},band:"9-12",palette:{body:"#3557c8",limbs:"#3557c8",belly:"#3557c8",accent:"#e0403a",outline:Et,skin:"#5a3825",hair:"#141010",hands:"#e0403a",feet:"#e0403a"},head:"round",ears:"human",face:{eyes:"calm",mouth:"smirk",muzzle:"none",brows:"#141010"},tail:"none",headExtras:["hair","domino"],bodyExtras:["cape","emblem","boots"],extraColors:["#ffd84a"]},{id:"trex",name:{en:"T-Rex",it:"T-Rex"},band:"6-8",alsoIn:["3-5"],palette:{body:"#6cb84e",limbs:"#6cb84e",belly:"#f4e8a8",accent:"#f4e8a8",outline:ht},head:"snout-long",ears:"none",face:{eyes:"dot",mouth:"toothy",muzzle:"none",cheeks:"#f59b8f"},tail:"thick",headExtras:["stripes"],bodyExtras:["tiny-arms","strong-legs"],extraColors:["#4a9235","#58a23f"]},{id:"fairy",name:{en:"Fairy",it:"Fatina"},band:"6-8",alsoIn:["3-5"],palette:{body:"#b99af0",limbs:"#a8693f",belly:"#b99af0",accent:"#ffd84a",outline:ht,skin:"#a8693f",hair:"#2e1d17",hands:"#a8693f",feet:"#f58cbc"},head:"round",ears:"pixie",face:{eyes:"dot",mouth:"smile",muzzle:"none",cheeks:"#f0857a"},tail:"none",headExtras:["bun","flower-crown"],bodyExtras:["wings-fairy","petals","wand"],extraColors:["#c4ecff","#f7a8cf","#fff3a0","#ffffff"]}],rt={M:0,L:1,Q:2,C:3,Z:4},Oi=[2,2,4,6,0];function Ns(t,e){for(const s of e)$r(t,s)}function $r(t,e){if(e.k==="group"){t.save(),t.translate(e.x,e.y),e.rot&&t.rotate(e.rot),e.s!==void 0&&e.s!==1&&t.scale(e.s,e.s),e.alpha!==void 0&&(t.globalAlpha*=e.alpha),Ns(t,e.items),t.restore();return}switch(t.save(),e.alpha!==void 0&&(t.globalAlpha*=e.alpha),t.beginPath(),e.k){case"circle":t.arc(e.x,e.y,Math.max(e.r,0),0,Math.PI*2);break;case"ellipse":t.ellipse(e.x,e.y,Math.max(e.rx,0),Math.max(e.ry,0),e.rot??0,0,Math.PI*2);break;case"rect":qr(t,e);break;case"path":typeof e.d=="string"?jr(t,e.d):Wr(t,e.d);break;case"line":t.moveTo(e.pts[0]??0,e.pts[1]??0);for(let s=2;s+1<e.pts.length;s+=2)t.lineTo(e.pts[s],e.pts[s+1]);break}t.lineCap="round",t.lineJoin="round",e.fill&&e.k!=="line"&&(t.fillStyle=e.fill,t.fill()),e.stroke&&(e.lw??1)>0&&(t.strokeStyle=e.stroke,t.lineWidth=e.lw??1,t.stroke()),t.restore()}function qr(t,e){const s=Math.max(0,Math.min(e.r,e.w/2,e.h/2));t.translate(e.x,e.y),e.rot&&t.rotate(e.rot);const i=-e.w/2,n=-e.h/2;t.moveTo(i+s,n),t.lineTo(i+e.w-s,n),t.quadraticCurveTo(i+e.w,n,i+e.w,n+s),t.lineTo(i+e.w,n+e.h-s),t.quadraticCurveTo(i+e.w,n+e.h,i+e.w-s,n+e.h),t.lineTo(i+s,n+e.h),t.quadraticCurveTo(i,n+e.h,i,n+e.h-s),t.lineTo(i,n+s),t.quadraticCurveTo(i,n,i+s,n),t.closePath()}function Wr(t,e){for(let s=0;s<e.length;){const i=e[s++];if(i===rt.M)t.moveTo(e[s],e[s+1]);else if(i===rt.L)t.lineTo(e[s],e[s+1]);else if(i===rt.Q)t.quadraticCurveTo(e[s],e[s+1],e[s+2],e[s+3]);else if(i===rt.C)t.bezierCurveTo(e[s],e[s+1],e[s+2],e[s+3],e[s+4],e[s+5]);else if(i===rt.Z)t.closePath();else return;s+=Oi[i]}}function Yr(t){if(typeof t=="string")return(t.match(/-?\d*\.?\d+(?:e-?\d+)?/gi)??[]).map(Number);const e=[];for(let s=0;s<t.length;){const i=Oi[t[s++]];if(i===void 0)break;for(let n=0;n<i;n++)e.push(t[s+n]);s+=i}return e}function jr(t,e){const s=e.match(/[MLQCZ]|-?\d*\.?\d+(?:e-?\d+)?/gi)??[];let i="",n=0;const r=()=>Number(s[n++]);for(;n<s.length;){const a=s[n];if(/[MLQCZ]/i.test(a)&&(i=a.toUpperCase(),n++,i==="Z")){t.closePath();continue}i==="M"?(t.moveTo(r(),r()),i="L"):i==="L"?t.lineTo(r(),r()):i==="Q"?t.quadraticCurveTo(r(),r(),r(),r()):i==="C"?t.bezierCurveTo(r(),r(),r(),r(),r(),r()):n++}}var K=t=>{const e=Math.round(t*100)/100;return e===0?0:e};function J(t,e=.5){const s=t.length;if(s<3)return[];const i=(l,h,o)=>({x:l.x+(h.x-l.x)*o,y:l.y+(h.y-l.y)*o}),n=Math.min(Math.max(e,0),.5),r=i(t[0],t[1],n),a=[rt.M,K(r.x),K(r.y)];for(let l=1;l<=s;l++){const h=t[(l-1)%s],o=t[l%s],c=t[(l+1)%s],u=i(h,o,1-n),f=i(o,c,n);a.push(rt.L,K(u.x),K(u.y),rt.Q,K(o.x),K(o.y),K(f.x),K(f.y))}return a.push(rt.Z),a}function Z(t,e=1){const s=t.length;if(s<3)return[];const i=[rt.M,K(t[0].x),K(t[0].y)],n=e/6;for(let r=0;r<s;r++){const a=t[(r-1+s)%s],l=t[r],h=t[(r+1)%s],o=t[(r+2)%s];i.push(rt.C,K(l.x+(h.x-a.x)*n),K(l.y+(h.y-a.y)*n),K(h.x-(o.x-l.x)*n),K(h.y-(o.y-l.y)*n),K(h.x),K(h.y))}return i.push(rt.Z),i}function Pe(t){const e=t.length;if(e<2)return[];const s=[rt.M,K(t[0].x),K(t[0].y)];for(let i=0;i<e-1;i++){const n=t[Math.max(i-1,0)],r=t[i],a=t[i+1],l=t[Math.min(i+2,e-1)];s.push(rt.C,K(r.x+(a.x-n.x)/6),K(r.y+(a.y-n.y)/6),K(a.x-(l.x-r.x)/6),K(a.y-(l.y-r.y)/6),K(a.x),K(a.y))}return s}var ge="M0 -1 L0.29 -0.4 L0.95 -0.31 L0.47 0.15 L0.59 0.81 L0 0.5 L-0.59 0.81 L-0.47 0.15 L-0.95 -0.31 L-0.29 -0.4 Z",at="#ffffff",$=[-1,1],zi="#3a2420",Di="#f2808f",Is="#26324a",Qr="#ffd84a",st=(...t)=>{const e=[];for(let s=0;s+1<t.length;s+=2)e.push({x:t[s],y:t[s+1]});return e};function Bi(t,e){const s=t.palette,i=[],n={stroke:s.outline,lw:e},r=c=>t.headExtras.includes(c),a=(c,u)=>t.extraColors?.[c]??u;if(r("mane")){for(let u=0;u<12;u++){const f=u/12*Math.PI*2;i.push({k:"circle",x:Math.cos(f)*1.02,y:Math.sin(f)*1+.04,r:.42,fill:a(0,s.accent),...n})}i.push({k:"circle",x:0,y:.04,r:1.08,fill:a(0,s.accent)})}if(r("rainbow-mane")){const c=t.extraColors??["#f59ac0","#fbd46a","#8fd3f4"];[[.98,.05,.3,.5,-.25],[.92,.58,.26,.42,-.1],[.62,.92,.22,.32,.4]].forEach(([f,y,p,x,m],g)=>i.push({k:"ellipse",x:f,y,rx:p,ry:x,rot:m,fill:c[g%c.length],...n}))}if(r("spikes"))for(const c of[-.55,0,.55]){const u=ae(c,1.48),f=ae(c-.32,.86),y=ae(c+.32,.86);i.push({k:"path",d:J([f,u,y],.22),fill:s.accent,...n})}if(r("curl")&&i.push({k:"path",d:Z([{x:-.2,y:-.9},{x:-.05,y:-1.3},{x:.32,y:-1.42},{x:.16,y:-1.18},{x:.2,y:-.9}]),fill:s.body,...n}),r("wool"))for(let c=0;c<=8;c++){const u=-1.75+c/8*3.5;i.push({k:"circle",x:Math.sin(u)*.98,y:-Math.cos(u)*.92-.04,r:.34,fill:s.body,...n})}if(r("crest")&&[-.38,0,.38].forEach((c,u)=>{const f=ae(c,1.12);i.push({k:"ellipse",x:f.x,y:f.y,rx:.15,ry:.42,rot:c,fill:a(u,s.accent),...n})}),r("plume")&&i.push({k:"path",d:Z(st(-.12,-.92,-.2,-1.42,.1,-1.78,.62,-1.74,.36,-1.46,.16,-.98)),fill:s.accent,...n}),r("locks")&&i.push({k:"path",d:Z(st(-1.14,.58,-1.24,-.2,-.86,-.98,0,-1.2,.86,-.98,1.24,-.2,1.14,.58,.8,.66,0,.2,-.8,.66)),fill:s.hair??s.outline,...n}),r("bun")&&i.push({k:"circle",x:.04,y:-1.14,r:.4,fill:s.hair??s.outline,...n}),r("ninja-hood"))for(const[c,u]of[[.35,.5],[.85,.42]])i.push({k:"ellipse",x:1+Math.cos(c)*u*.8,y:-.5+Math.sin(c)*u*.8,rx:u,ry:.11,rot:c,fill:s.accent,...n});if(r("bandana"))for(const[c,u]of[[Math.PI-.5,.42],[Math.PI-1,.36]])i.push({k:"ellipse",x:-.98+Math.cos(c)*u*.8,y:-.36+Math.sin(c)*u*.8,rx:u,ry:.12,rot:c,fill:s.accent,...n});if(r("ruff"))for(const c of $)i.push({k:"path",d:J(st(c*.7,-.3,c*1.32,0,c*1.02,.18,c*1.26,.46,c*.86,.56,c*.98,.84,c*.4,.7),.25),fill:s.body,...n});if(t.face.eyesOnTop)for(const c of $)i.push({k:"circle",x:c*.46,y:-.72,r:.38,fill:s.body,...n});i.push(...ea(t,e)),i.push(Vr(t,n));const l=t.face.muzzle,h=s.belly;if(l==="oval"&&i.push({k:"ellipse",x:0,y:.4,rx:.46,ry:.32,fill:h}),l==="monkey"){for(const c of $)i.push({k:"circle",x:c*.32,y:-.04,r:.38,fill:h});i.push({k:"ellipse",x:0,y:.4,rx:.56,ry:.4,fill:h})}if(l==="heart"){for(const c of $)i.push({k:"circle",x:c*.36,y:.02,r:.5,fill:h});i.push({k:"ellipse",x:0,y:.38,rx:.66,ry:.48,fill:h})}if(l==="disc")for(const c of $)i.push({k:"circle",x:c*.4,y:.02,r:.44,fill:h});if(l==="cheeks")for(const c of $)i.push({k:"ellipse",x:c*.4,y:.44,rx:.44,ry:.32,fill:h});if(l==="band"&&i.push({k:"path",d:ta(t,e),fill:h}),r("stripes")&&t.head==="snout-long"){const c=a(0,s.outline);for(const[u,f,y,p]of[[.46,-.94,.36,-.66],[.8,-.72,.62,-.5],[1,-.36,.78,-.24]])i.push({k:"line",pts:[u,f,y,p],stroke:c,lw:.11})}else if(r("stripes")){const c=a(0,s.outline);i.push({k:"line",pts:[0,-.97,0,-.66],stroke:c,lw:.13});for(const u of $)i.push({k:"line",pts:[u*.3,-.93,u*.24,-.7],stroke:c,lw:.1}),i.push({k:"line",pts:[u*.98,-.05,u*.74,0],stroke:c,lw:.1}),i.push({k:"line",pts:[u*.94,.22,u*.74,.22],stroke:c,lw:.09})}if(r("spots")){const c=a(1,s.belly);i.push({k:"circle",x:-.55,y:-.5,r:.15,fill:c}),i.push({k:"circle",x:.58,y:-.42,r:.11,fill:c}),i.push({k:"circle",x:.22,y:-.76,r:.09,fill:c})}if(t.head==="snout-long")for(const[c,u,f]of[[-1.38,-.14,.06],[-1.14,-.22,.055]])i.push({k:"ellipse",x:c,y:u,rx:f,ry:f*.8,rot:-.3,fill:s.outline,alpha:.85});if(r("forehead")&&i.push({k:"path",d:Z(st(-.62,-.66,0,-.86,.62,-.66,.26,-.36,0,-.1,-.26,-.36),.9),fill:a(0,s.accent)}),r("eye-spot")&&i.push({k:"ellipse",x:.42,y:-.06,rx:.3,ry:.33,rot:.3,fill:s.ears??s.accent}),r("gills"))for(const c of $)for(const u of[0,.12,.24])i.push({k:"path",d:`M${c*(.66+u)} 0.06 Q${c*(.6+u)} 0.22 ${c*(.66+u)} 0.38`,stroke:s.accent,lw:e*.9});const o=s.hair??s.outline;if(r("hair")&&i.push({k:"path",d:Z(st(-1.02,-.06,-1.02,-.58,-.62,-1.04,.08,-1.14,.76,-.92,1.05,-.42,1,-.06,.84,-.4,.42,-.5,.06,-.4,-.34,-.56,-.74,-.38)),fill:o,...n}),r("locks")&&i.push({k:"path",d:Z(st(-1,-.08,-.98,-.62,-.56,-1.02,0,-1.1,.56,-1.02,.98,-.62,1,-.08,.8,-.38,.36,-.44,0,-.4,-.36,-.44,-.8,-.38)),fill:o,...n}),r("bun")&&i.push({k:"path",d:Z(st(-1.02,-.1,-.98,-.62,-.56,-1.02,0,-1.1,.56,-1.02,.98,-.62,1.02,-.1,.84,-.36,.5,-.56,.12,-.48,-.22,-.6,-.6,-.5,-.86,-.36)),fill:o,...n}),r("curls")){for(let c=0;c<7;c++){const u=ae(-1.3+c/6*2.6,.86);i.push({k:"circle",x:u.x,y:u.y,r:.3,fill:o,...n})}i.push({k:"ellipse",x:0,y:-.64,rx:.8,ry:.36,fill:o})}if(r("ninja-hood")&&(i.push({k:"rect",x:0,y:0,w:1.56,h:.6,r:.28,fill:s.skin??at,stroke:s.outline,lw:e*.8}),i.push({k:"path",d:"M-0.98 -0.42 Q0 -0.74 0.98 -0.42 L1.0 -0.62 Q0 -0.94 -1.0 -0.62 Z",fill:s.accent,...n})),r("domino")){i.push({k:"path",d:Z(st(-.86,-.04,-.62,-.3,-.18,-.24,0,-.16,.18,-.24,.62,-.3,.86,-.04,.6,.22,.16,.16,0,.1,-.16,.16,-.6,.22),.9),fill:s.accent,...n});for(const c of $)i.push({k:"ellipse",x:c*.38,y:0,rx:.19,ry:.13,fill:at})}if(i.push(...sa(t,e)),r("brows"))for(const c of $)i.push({k:"line",pts:[c*.72,-.5,c*.14,-.3],stroke:s.accent,lw:.16});if(t.face.brows)for(const c of $)i.push({k:"line",pts:[c*.2,-.2,c*.54,-.28],stroke:t.face.brows,lw:.09});if(i.push(...ia(t,e)),t.face.cheeks)for(const c of Zr(t))i.push({k:"ellipse",x:c.x,y:c.y,rx:.15,ry:.1,fill:t.face.cheeks,alpha:.8});if(r("whiskers"))for(const c of $)for(const u of[-.1,.06])i.push({k:"line",pts:[c*.62,.38+u,c*1.06,.3+u*2.2],stroke:s.outline,lw:e*.7,alpha:.75});if(r("rainbow-mane")){const c=t.extraColors??["#f59ac0","#fbd46a","#8fd3f4"];i.push({k:"ellipse",x:.42,y:-.82,rx:.34,ry:.22,rot:.5,fill:c[0],...n}),i.push({k:"ellipse",x:.1,y:-.92,rx:.3,ry:.2,rot:.25,fill:c[1%c.length],...n})}if(t.ears==="unicorn"){const c=[{x:-.18,y:-.84},{x:.02,y:-1.72},{x:.18,y:-.84}];i.push({k:"path",d:J(c,.12),fill:s.accent,...n});for(const u of[-1,-1.2,-1.4]){const f=.16*((u+1.72)/.88);i.push({k:"line",pts:[-f,u+.04,f,u-.04],stroke:s.outline,lw:e*.7,alpha:.6})}}if(r("flower-crown")){const c=[a(1,"#f7a8cf"),a(2,"#fff3a0"),a(3,at)];for(const u of[-.84,-.28,.28,.84]){const f=ae(u,.9);i.push({k:"ellipse",x:f.x,y:f.y,rx:.14,ry:.07,rot:u+.5,fill:"#7cc76a",stroke:s.outline,lw:e*.7})}[-1.12,-.56,0,.56,1.12].forEach((u,f)=>{const y=ae(u,.9),p=f===2?.13:.11;for(let x=0;x<5;x++){const m=u+x/5*Math.PI*2;i.push({k:"circle",x:y.x+Math.sin(m)*p,y:y.y-Math.cos(m)*p,r:p*.82,fill:c[f%c.length],stroke:s.outline,lw:e*.7})}i.push({k:"circle",x:y.x,y:y.y,r:p*.62,fill:c[f%c.length]}),i.push({k:"circle",x:y.x,y:y.y,r:p*.42,fill:s.accent})})}if(r("helmet")){for(const c of $)i.push({k:"rect",x:c*1,y:.05,w:.26,h:.56,r:.12,fill:s.accent,...n});i.push({k:"path",d:"M-0.62 -0.62 Q-0.3 -0.92 0.12 -0.9",stroke:at,lw:.1,alpha:.9})}if(r("bolts"))for(const c of $)i.push({k:"rect",x:c*1.08,y:.08,w:.2,h:.44,r:.08,fill:s.accent,...n});if(r("tuft")&&i.push({k:"path",d:Z([{x:-.26,y:-.95},{x:-.12,y:-1.22},{x:.02,y:-1.04},{x:.16,y:-1.28},{x:.28,y:-.95},{x:0,y:-.86}]),fill:s.body,...n}),r("eggshell")&&i.push({k:"path",d:"M-0.88 -0.5 C-0.88 -1.12 -0.46 -1.42 0 -1.42 C0.46 -1.42 0.88 -1.12 0.88 -0.5 L0.66 -0.66 L0.44 -0.48 L0.22 -0.66 L0 -0.48 L-0.22 -0.66 L-0.44 -0.48 L-0.66 -0.66 Z",fill:a(0,at),...n}),r("wool"))for(const[c,u]of[[-.36,-.84],[.02,-.94],[.4,-.82]])i.push({k:"circle",x:c,y:u,r:.27,fill:s.body,...n});if(r("stripe")&&i.push({k:"rect",x:0,y:-.64,w:.38,h:.62,r:.06,fill:s.accent}),r("eye-patch")&&(i.push({k:"line",pts:[-.97,-.5,.97,.13],stroke:s.outline,lw:.07}),i.push({k:"ellipse",x:.38,y:.02,rx:.21,ry:.19,fill:s.outline})),r("bandana")){i.push({k:"path",d:Z(st(-1.05,-.22,-.96,-.72,-.5,-1.08,.1,-1.14,.72,-.96,1.04,-.56,1.05,-.22,.5,-.46,-.5,-.46)),fill:s.accent,...n});for(const[c,u]of[[-.5,-.8],[.08,-.92],[.6,-.74],[-.12,-.62],[.36,-.6]])i.push({k:"circle",x:c,y:u,r:.06,fill:at,alpha:.85});i.push({k:"circle",x:-.98,y:-.34,r:.15,fill:s.accent,...n})}if(r("cap")){for(const c of $)i.push({k:"line",pts:[c*.98,-.2,c*.5,.82,-c*.05,.98],stroke:s.outline,lw:.06});i.push({k:"path",d:Z(st(-1.1,-.16,-1.04,-.66,-.6,-1.12,0,-1.24,.6,-1.12,1.04,-.66,1.1,-.16,.5,-.4,-.5,-.4)),fill:s.accent,...n}),i.push({k:"path",d:"M-0.74 -0.4 Q0 -0.6 0.74 -0.4 Q0.8 -0.24 0.6 -0.22 Q0 -0.36 -0.6 -0.22 Q-0.8 -0.24 -0.74 -0.4 Z",fill:s.accent,...n}),i.push({k:"circle",x:.5,y:-.82,r:.15,fill:a(0,at),...n});for(const c of[-.42,-.14])i.push({k:"line",pts:[c,-1.04,c+.02,-.78],stroke:s.outline,lw:.07,alpha:.7})}if(r("safari-hat")&&(i.push({k:"ellipse",x:0,y:-.56,rx:1.48,ry:.3,fill:s.accent,...n}),i.push({k:"path",d:Z(st(-.78,-.58,-.7,-1.1,-.3,-1.38,.3,-1.38,.7,-1.1,.78,-.58,0,-.5),.8),fill:s.accent,...n}),i.push({k:"path",d:"M-0.77 -0.72 Q0 -0.62 0.77 -0.72 L0.74 -0.9 Q0 -0.8 -0.74 -0.9 Z",fill:a(1,s.outline),stroke:s.outline,lw:e*.8})),r("wizard-hat")){i.push({k:"ellipse",x:0,y:-.62,rx:1.32,ry:.26,fill:s.accent,...n}),i.push({k:"path",d:J(st(-.8,-.66,-.36,-1.5,.5,-2.2,.3,-1.46,.8,-.66),.3),fill:s.accent,...n});const c=a(0,Qr);for(const[u,f,y]of[[.02,-1.08,.18],[-.38,-.84,.1],[.36,-1.5,.11]])i.push({k:"group",x:u,y:f,s:y,items:[{k:"path",d:ge,fill:c}]})}if(r("dive-mask")){for(const u of $)i.push({k:"line",pts:[u*.7,-.04,u*1,-.12],stroke:s.outline,lw:.2},{k:"line",pts:[u*.7,-.04,u*1,-.12],stroke:s.accent,lw:.11});i.push({k:"rect",x:0,y:0,w:1.42,h:.62,r:.28,fill:"#bfe9f5",alpha:.35}),i.push({k:"rect",x:0,y:0,w:1.42,h:.62,r:.28,stroke:s.outline,lw:.2}),i.push({k:"rect",x:0,y:0,w:1.42,h:.62,r:.28,stroke:s.accent,lw:.11}),i.push({k:"path",d:"M-0.5 -0.16 Q-0.4 -0.24 -0.22 -0.24",stroke:at,lw:.06,alpha:.9});const c="M0.5 0.52 Q0.98 0.56 1.04 0.1 L1.12 -0.92";i.push({k:"path",d:c,stroke:s.outline,lw:.24},{k:"path",d:c,stroke:s.accent,lw:.13})}return i}function Vr(t,e){const s=t.headExtras.includes("ninja-hood")?t.palette.body:t.palette.skin??t.palette.body;switch(t.head){case"round":return{k:"circle",x:0,y:0,r:1,fill:s,...e};case"wide":return{k:"ellipse",x:0,y:.03,rx:1.12,ry:.94,fill:s,...e};case"tall":return{k:"ellipse",x:0,y:-.02,rx:.94,ry:1.04,fill:s,...e};case"square":return{k:"rect",x:0,y:0,w:2,h:1.8,r:.46,fill:s,...e};case"bucket":return{k:"path",d:J(st(-.94,.96,-.98,-.36,-.62,-1.04,.62,-1.04,.98,-.36,.94,.96),.42),fill:s,...e};case"snout-long":return{k:"path",d:Z(Kr,.95),fill:s,...e};case"bulb":return{k:"path",d:Z([{x:0,y:-1.02},{x:.86,y:-.74},{x:1.08,y:-.12},{x:.72,y:.62},{x:0,y:.92},{x:-.72,y:.62},{x:-1.08,y:-.12},{x:-.86,y:-.74}]),fill:s,...e}}}var Kr=st(.7,-.88,.12,-1.04,-.3,-.98,-.72,-.74,-1.2,-.56,-1.5,-.32,-1.6,.04,-1.44,.42,-.9,.72,-.2,.92,.5,.88,.96,.56,1.08,0,.98,-.5);function Ui(t,e,s){return t.head==="snout-long"?[{x:-.36,y:-.5,k:.95},{x:.26,y:-.48,k:1.1}]:$.map(i=>({x:i*e,y:s,k:1}))}function Zr(t){return t.head==="snout-long"?st(-.66,-.14,.66,.1):$.map(e=>({x:e*.64,y:.3}))}function Jr(t){return t.head==="round"?{cy:0,rx:1,ry:1}:t.head==="tall"?{cy:-.02,rx:.94,ry:1.04}:{cy:.03,rx:1.12,ry:.94}}function ta(t,e){const{cy:s,rx:i,ry:n}=Jr(t),r=i-e/2,a=n-e/2,l=.15,h=Math.asin(Math.min(1,(l-s)/a)),o=Math.cos(h)*r,c=p=>Math.round(p*100)/100||0,u=[rt.M,c(-o),l],f=[[-.84*o,.02,-.53*o,.06,-.32*o,.24],[-.17*o,.11,.17*o,.11,.32*o,.24],[.53*o,.06,.84*o,.02,o,l]];for(const p of f)u.push(rt.C,...p.map(c));const y=24;for(let p=1;p<=y;p++){const x=h+(Math.PI-2*h)*p/y;u.push(rt.L,c(Math.cos(x)*r),c(s+Math.sin(x)*a))}return u.push(rt.Z),u}function ea(t,e){const s=t.palette,i={stroke:s.outline,lw:e},n=[];for(const r of $)switch(t.ears){case"pointy":case"unicorn":{const a=t.ears==="unicorn"?.8:1,l={x:r*.3,y:-.82},h={x:r*.86,y:-.82-.62*a},o={x:r*.94,y:-.36};n.push({k:"path",d:J([l,h,o],.2),fill:s.body,...i});const c={x:(l.x+h.x+o.x)/3,y:(l.y+h.y+o.y)/3},u=[l,h,o].map(f=>({x:c.x+(f.x-c.x)*.55,y:c.y+(f.y-c.y)*.55+.04}));n.push({k:"path",d:J(u,.25),fill:s.accent});break}case"round":n.push({k:"circle",x:r*.72,y:-.72,r:.36,fill:s.ears??s.body,...i}),s.ears||n.push({k:"circle",x:r*.74,y:-.74,r:.19,fill:s.accent});break;case"big-round":n.push({k:"circle",x:r*.96,y:-.46,r:.52,fill:s.body,...i}),n.push({k:"circle",x:r*1,y:-.44,r:.32,fill:s.accent});break;case"long":n.push({k:"ellipse",x:r*.38,y:-1.42,rx:.25,ry:.68,rot:r*.14,fill:s.body,...i}),n.push({k:"ellipse",x:r*.39,y:-1.36,rx:.12,ry:.48,rot:r*.14,fill:s.accent});break;case"side":n.push({k:"circle",x:r*1,y:.02,r:.34,fill:s.body,...i}),n.push({k:"circle",x:r*1.02,y:.02,r:.2,fill:s.belly});break;case"tufts":n.push({k:"path",d:J([{x:r*.3,y:-.84},{x:r*1.22,y:-1.12},{x:r*.92,y:-.42}],.16),fill:s.body,...i}),n.push({k:"line",pts:[r*.62,-.78,r*1,-.98],stroke:s.accent,lw:.08});break;case"antennae":{const a={x:r*.62,y:-1.42};n.push({k:"path",d:`M${r*.3} -0.8 Q${r*.36} -1.2 ${a.x} ${a.y}`,stroke:s.outline,lw:e*2.6}),n.push({k:"path",d:`M${r*.3} -0.8 Q${r*.36} -1.2 ${a.x} ${a.y}`,stroke:s.body,lw:e*1.2}),n.push({k:"circle",x:a.x,y:a.y,r:.17,fill:s.accent,...i});break}case"floppy":n.push({k:"ellipse",x:r*.96,y:.02,rx:.3,ry:.62,rot:-r*.36,fill:s.ears??s.body,...i});break;case"droopy":n.push({k:"ellipse",x:r*1.04,y:-.22,rx:.4,ry:.18,rot:r*.32,fill:s.skin??s.body,...i}),n.push({k:"ellipse",x:r*1.08,y:-.2,rx:.24,ry:.08,rot:r*.32,fill:s.accent});break;case"pixie":n.push({k:"path",d:J(st(r*.86,-.22,r*1.36,-.5,r*1.02,.26),.28),fill:s.skin??s.body,...i}),n.push({k:"line",pts:[r*.98,-.12,r*1.16,-.3],stroke:s.accent,lw:e*.8,alpha:.5});break;case"human":n.push({k:"ellipse",x:r*.98,y:.06,rx:.17,ry:.23,fill:s.skin??s.body,...i});break;case"horns":{const a=[{x:r*.3,y:-.84},{x:r*.6,y:-1.5},{x:r*.66,y:-.68}];n.push({k:"path",d:J(a,.18),fill:s.accent,...i});break}}return t.ears==="fin"&&n.push({k:"path",d:J(st(-.4,-.82,.2,-1.62,.46,-.78),.2),fill:s.body,...i}),t.ears==="antenna"&&(n.push({k:"line",pts:[0,-.85,0,-1.42],stroke:s.outline,lw:e*2.6}),n.push({k:"line",pts:[0,-.85,0,-1.42],stroke:s.limbs,lw:e*1.2}),n.push({k:"circle",x:0,y:-1.5,r:.18,fill:s.accent,...i})),n}function sa(t,e){const s=t.palette,i=t.face,n=[],r=s.outline,a=i.eyesOnTop?.46:.4,l=i.eyesOnTop?-.72:-.04,h=(o,c,u)=>({k:"circle",x:o,y:c,r:u,fill:at});switch(i.eyes){case"dot":for(const o of Ui(t,a,l))n.push({k:"ellipse",x:o.x,y:o.y,rx:.12*o.k,ry:.155*o.k,fill:r}),n.push(h(o.x+.04*o.k,o.y-.06*o.k,.045*o.k));break;case"bead":for(const o of Ui(t,a,l))n.push({k:"ellipse",x:o.x,y:o.y,rx:.16*o.k,ry:.22*o.k,fill:r}),n.push(h(o.x+.05*o.k,o.y-.08*o.k,.065*o.k));break;case"big":for(const o of $)i.eyeRing&&n.push({k:"circle",x:o*a,y:l,r:.36,fill:i.eyeRing,stroke:r,lw:e*.8}),n.push({k:"circle",x:o*a,y:l,r:.25,fill:at,stroke:r,lw:e*.8}),n.push({k:"circle",x:o*a+o*-.03,y:l+.03,r:.14,fill:i.eyeColor??r}),n.push(h(o*a+o*-.03+.05,l-.03,.05));break;case"mask":for(const o of $)n.push({k:"ellipse",x:o*.4,y:0,rx:.24,ry:.32,rot:o*-.55,fill:s.limbs}),n.push({k:"circle",x:o*.4,y:-.02,r:.11,fill:at}),n.push({k:"circle",x:o*.39,y:-0,r:.065,fill:r});break;case"screen":n.push({k:"rect",x:0,y:0,w:1.5,h:.66,r:.26,fill:"#24323d",stroke:r,lw:e*.8});for(const o of $)n.push({k:"ellipse",x:o*.36,y:0,rx:.2,ry:.24,fill:i.eyeColor??"#7ff0ff",alpha:.3}),n.push({k:"ellipse",x:o*.36,y:0,rx:.12,ry:.16,fill:i.eyeColor??"#7ff0ff"});break;case"almond":for(const o of $)n.push({k:"ellipse",x:o*.42,y:-.02,rx:.3,ry:.2,rot:-o*.5,fill:i.eyeColor??r}),n.push(h(o*.42-o*.07,-.08,.07));break;case"calm":for(const o of $)n.push({k:"ellipse",x:o*.38,y:.02,rx:.085,ry:.12,fill:r}),n.push(h(o*.38+.03,-.02,.03));break;case"slit":n.push({k:"line",pts:[0,-.98,0,-.2],stroke:r,lw:e*.8,alpha:.5}),n.push({k:"rect",x:0,y:-.04,w:1.56,h:.26,r:.1,fill:Is,stroke:r,lw:e*.8}),n.push({k:"rect",x:0,y:.3,w:.22,h:.46,r:.08,fill:Is,stroke:r,lw:e*.8});for(const o of $){n.push({k:"ellipse",x:o*.4,y:-.04,rx:.12,ry:.07,fill:i.eyeColor??at});for(const c of[.36,.56])n.push({k:"circle",x:o*.42,y:c,r:.05,fill:r,alpha:.6})}break;case"goggle":for(const o of $)n.push({k:"circle",x:o*.9,y:0,r:.13,fill:s.accent,stroke:r,lw:e*.8});n.push({k:"rect",x:0,y:0,w:1.66,h:.62,r:.3,fill:Is,stroke:r,lw:e*.8}),n.push({k:"path",d:"M-0.6 -0.16 Q-0.42 -0.24 -0.12 -0.24",stroke:at,lw:.07,alpha:.8});for(const o of $)n.push({k:"path",d:`M${o*.5} 0.04 Q${o*.34} -0.08 ${o*.16} 0.02`,stroke:i.eyeColor??"#7fd6ff",lw:.08});for(const o of[-.18,0,.18])n.push({k:"line",pts:[o,.56,o,.72],stroke:r,lw:e*.8,alpha:.6});break;case"visor":n.push({k:"ellipse",x:0,y:.08,rx:.8,ry:.64,fill:"#2a3f6b",stroke:r,lw:e*.8}),n.push({k:"path",d:"M-0.56 -0.14 Q-0.46 -0.4 -0.16 -0.46",stroke:at,lw:.08,alpha:.7});for(const o of $)n.push({k:"ellipse",x:o*.28,y:.04,rx:.1,ry:.14,fill:i.eyeColor??"#cfeeff"});break}return n}function ia(t,e){const s=t.palette,i=t.face,n=[],r=i.eyes==="visor"?"#cfeeff":zi,a=e*1.05;switch(i.nose&&i.mouth!=="beak"&&(i.mouth==="cat"?n.push({k:"path",d:J([{x:-.1,y:.22},{x:.1,y:.22},{x:0,y:.33}],.3),fill:i.nose,stroke:i.nose,lw:e*.6}):t.ears==="big-round"?n.push({k:"ellipse",x:0,y:.22,rx:.2,ry:.25,fill:i.nose}):n.push({k:"ellipse",x:0,y:.25,rx:.13,ry:.085,fill:i.nose})),i.mouth){case"smile":n.push({k:"path",d:i.eyes==="visor"?"M-0.16 0.32 Q0 0.46 0.16 0.32":"M-0.17 0.42 Q0 0.58 0.17 0.42",stroke:r,lw:a});break;case"open":n.push({k:"path",d:"M-0.21 0.4 Q0 0.46 0.21 0.4 Q0.19 0.68 0 0.68 Q-0.19 0.68 -0.21 0.4 Z",fill:r,stroke:r,lw:e*.5}),n.push({k:"ellipse",x:0,y:.6,rx:.1,ry:.06,fill:Di});break;case"cat":n.push({k:"path",d:"M-0.19 0.4 Q-0.1 0.5 0 0.37 Q0.1 0.5 0.19 0.4",stroke:r,lw:a});break;case"beak":n.push({k:"path",d:J([{x:-.17,y:.2},{x:.17,y:.2},{x:0,y:.48}],.25),fill:s.accent,stroke:s.outline,lw:e*.8});break;case"teeth":n.push({k:"path",d:"M-0.36 0.34 Q0 0.44 0.36 0.34 Q0.28 0.66 0 0.66 Q-0.28 0.66 -0.36 0.34 Z",fill:r,stroke:r,lw:e*.5});for(const l of $)n.push({k:"rect",x:l*.12,y:.43,w:.1,h:.1,r:.03,fill:at});break;case"grill":n.push({k:"rect",x:0,y:.56,w:.62,h:.2,r:.08,fill:"#24323d",stroke:s.outline,lw:e*.7});for(const l of[-.15,0,.15])n.push({k:"line",pts:[l,.51,l,.61],stroke:"#9fb0bd",lw:e*.6});break;case"tiny":n.push({k:"ellipse",x:0,y:.44,rx:.08,ry:.1,fill:r});break;case"smirk":n.push({k:"path",d:"M-0.16 0.46 Q0.06 0.54 0.22 0.38",stroke:r,lw:a});break;case"bill":n.push({k:"ellipse",x:0,y:.36,rx:.44,ry:.2,fill:s.accent,stroke:s.outline,lw:e*.8}),n.push({k:"path",d:"M-0.36 0.38 Q0 0.46 0.36 0.38",stroke:s.outline,lw:e*.7});for(const l of $)n.push({k:"circle",x:l*.1,y:.28,r:.03,fill:s.outline});break;case"hook":n.push({k:"ellipse",x:0,y:.48,rx:.16,ry:.11,fill:zi}),n.push({k:"path",d:"M-0.3 0.12 Q0 -0.02 0.3 0.12 Q0.36 0.52 0.04 0.76 Q0.08 0.52 -0.08 0.46 Q-0.28 0.38 -0.3 0.12 Z",fill:s.accent,stroke:s.outline,lw:e*.8});break;case"toothy":{n.push({k:"path",d:"M-1.4 0.1 Q-0.5 0.36 0.5 0.2 Q0.64 0.16 0.68 0.02 Q0.78 0.28 0.52 0.38 Q-0.4 0.78 -1.3 0.26 Z",fill:r,stroke:r,lw:e*.6}),n.push({k:"ellipse",x:-.38,y:.5,rx:.24,ry:.08,fill:Di});for(const l of[.12,.27,.42,.57,.72,.86]){const h=(1-l)*(1-l)*-1.4+2*(1-l)*l*-.5+l*l*.5,o=(1-l)*(1-l)*.1+2*(1-l)*l*.36+l*l*.2-.01;n.push({k:"path",d:J(st(h-.08,o,h+.08,o,h,o+.14),.3),fill:at})}for(const l of[.3,.7]){const h=(1-l)*(1-l)*.52+2*(1-l)*l*-.4+l*l*-1.3,o=(1-l)*(1-l)*.38+2*(1-l)*l*.78+l*l*.26+.01;n.push({k:"path",d:J(st(h-.07,o,h+.07,o,h,o-.12),.3),fill:at})}break}case"jaws":{n.push({k:"path",d:"M-0.5 0.3 Q0 0.5 0.5 0.3 Q0.38 0.72 0 0.72 Q-0.38 0.72 -0.5 0.3 Z",fill:r,stroke:r,lw:e*.5});for(const l of[-.34,-.17,0,.17,.34]){const h=.3+.4*(l+.5)*(.5-l)-.01;n.push({k:"path",d:J(st(l-.075,h,l+.075,h,l,h+.13),.15),fill:at})}break}}return n}var ae=(t,e)=>({x:Math.sin(t)*e,y:-Math.cos(t)*e}),na=.5,Kt={leftEye:2,rightEye:5,leftEar:7,rightEar:8},oe={"3-5":{head:.75,neck:.74,arm:.3,leg:.36,hand:.19,foot:1.2,shoulderMin:.4,shoulderPad:.07,hipMin:.5,hipPad:.22,bottom:.26,bulge:1.12,armsOverHead:!0},"6-8":{head:.6,neck:.78,arm:.22,leg:.28,hand:.15,foot:1,shoulderMin:.34,shoulderPad:.04,hipMin:.4,hipPad:.16,bottom:.14,bulge:1.04,armsOverHead:!1},"9-12":{head:.5,neck:.92,arm:.17,leg:.21,hand:.125,foot:.9,shoulderMin:.36,shoulderPad:.07,hipMin:.32,hipPad:.08,bottom:.1,bulge:1,armsOverHead:!1}},ss="6-8",Hi=(t,e)=>e!==void 0&&t.band!=="all"&&t.alsoIn?.includes(e)&&e in oe?e:t.band in oe?t.band:ss,th=oe[ss].head,ra=.3,aa=.12,oa=.9,Gi=.5,Xi=.65,la=.35,ha=.2,ca=.25,Lt=(t,e)=>({x:t.x-e.x,y:t.y-e.y}),et=(t,e)=>({x:t.x+e.x,y:t.y+e.y}),Q=(t,e)=>({x:t.x*e,y:t.y*e}),le=t=>Math.hypot(t.x,t.y),$i=(t,e)=>({x:(t.x+e.x)/2,y:(t.y+e.y)/2}),is=t=>{const e=le(t);return e>1e-9?{x:t.x/e,y:t.y/e}:{x:0,y:1}},fa=(...t)=>t.every(Number.isFinite),ua=t=>Math.atan2(Math.sin(t),Math.cos(t)),da=(t,e,s)=>Math.min(Math.max(t,e),s);function qi(t,e,s=!1){return i=>{const n=t[i*3],r=t[i*3+1],a=t[i*3+2];return n===void 0||r===void 0||a===void 0||!fa(n,r,a)?{x:0,y:0,ok:!1}:{x:e.x+(s?1-n:n)*e.w,y:e.y+r*e.h,ok:a>=na}}}function Os(t,e,s={}){const i=qi(t,e,s.mirrored),n=i(H.leftShoulder),r=i(H.rightShoulder);if(!n.ok||!r.ok)return null;const a=i(H.leftHip),l=i(H.rightHip),h=$i(n,r),o=le(Lt(r,n)),c=a.ok&&l.ok;let u=is(Lt(r,n));o<1e-6&&(u={x:1,y:0});let f,y,p;if(c){const _=$i(a,l);y=le(Lt(_,h)),y>=o*ca?f=is(Lt(_,h)):(f={x:-u.y,y:u.x},f.y<0&&(f=Q(f,-1))),p=Math.max(y,o*1.15)}else f={x:-u.y,y:u.x},f.y<0&&(f=Q(f,-1)),p=o*1.15,y=p;p=Math.max(p,1e-6);const x={x:f.y,y:-f.x},m=Math.atan2(x.y,x.x),g=Q(f,-1),k=oe[s.band??ss]??oe[ss],E=k.head*p;let w=et(h,Q(g,E*k.neck));const T=i(H.nose);if(T.ok){const _=et(T,Q(g,E*.15)),L=Q(Lt(_,w),la),I=Math.min(1,E*ha/Math.max(le(L),1e-6));w=et(w,Q(L,I))}return{S:h,r:x,d:f,U:p,L:y,hipsOk:c,head:w,headR:E,headRot:m+pa(t,i,m,p),angle:m}}function pa(t,e,s,i){const n=[[Kt.leftEar,Kt.rightEar],[Kt.leftEye,Kt.rightEye]];for(const[r,a]of n){const l=e(r),h=e(a);if(!l.ok||!h.ok||!(t[r*3+2]>=Xi&&t[a*3+2]>=Xi)||le(Lt(h,l))<i*.05)continue;const o=ua(Math.atan2(h.y-l.y,h.x-l.x)-s),c=Math.max(Math.abs(o)-aa,0),u=da((oa+Gi-Math.abs(o))/Gi,0,1);return Math.sign(o)*Math.min(c,ra)*u}return 0}function Wi(t,e,s,i={}){const n=Hi(e,i.band),r=oe[n],a=Os(t,s,{...i,band:n});if(!a)return[];const l=qi(t,s,i.mirrored),h=e.palette,{S:o,r:c,d:u,U:f,L:y}=a,p=v=>e.bodyExtras.includes(v),x=Math.max(1.2,f*.045),m={stroke:h.outline,lw:x},g=(v,P)=>({x:o.x+c.x*v+u.x*P,y:o.y+c.y*v+u.y*P}),k=v=>v.map(([P,D])=>g(P,D)),E=l(H.leftShoulder),w=l(H.rightShoulder),T=l(H.leftHip),_=l(H.rightHip),L=le(Lt(w,E)),I=a.hipsOk?le(Lt(_,T)):L*.7,R=Math.max(L/2+r.shoulderPad*f,r.shoulderMin*f),O=Math.max(I/2+r.hipPad*f,r.hipMin*f),q=-.1*f,j=y+r.bottom*f,B=[],It=[],G=[],nt=[],yt=[],Ot=(v,P,D,Y)=>{const W=P.flatMap(ot=>[ot.x,ot.y]);v.push({k:"line",pts:W,stroke:h.outline,lw:D+x*2}),v.push({k:"line",pts:W,stroke:Y,lw:D})},gi=r.leg*f*(p("strong-legs")?1.3:1),wt=r.arm*f*(p("tiny-arms")?.6:1),zt=Math.max(r.arm/.22,.9);if(a.hipsOk)for(const[v,P,D,Y]of[[T,H.leftKnee,H.leftAnkle,-1],[_,H.rightKnee,H.rightAnkle,1]]){const W=l(P),ot=l(D);if(!W.ok)continue;const jt=et(v,Q(u,-.12*f)),_t=ot.ok?[jt,W,ot]:[jt,W];Ot(It,_t,gi,h.limbs),p("joints")&&It.push({k:"circle",x:W.x,y:W.y,r:.15*f*zt,fill:h.accent,...m}),ot.ok&&It.push(...xa(e,ot,a,Y,x,r.foot))}for(const[v,P,D,Y]of[[E,H.leftElbow,H.leftWrist,-1],[w,H.rightElbow,H.rightWrist,1]]){const W=l(P),ot=l(D);if(p("pauldrons")){const St=et(v,Q(u,.02*f));nt.push({k:"ellipse",x:St.x,y:St.y,rx:.25*f,ry:.17*f,rot:a.angle+Y*.25,fill:h.body,...m});const Tt=et(St,Q(u,.05*f));nt.push({k:"ellipse",x:Tt.x,y:Tt.y,rx:.17*f,ry:.07*f,rot:a.angle+Y*.25,fill:h.belly})}if(!W.ok)continue;const _t=r.armsOverHead&&(W.x-o.x)*u.x+(W.y-o.y)*u.y<-.25*f?yt:nt,Ye=et(v,Q(u,.04*f));if(Ot(_t,ot.ok?[Ye,W,ot]:[Ye,W],wt,h.limbs),p("joints")&&_t.push({k:"circle",x:W.x,y:W.y,r:.13*f*zt,fill:h.accent,...m}),!ot.ok)continue;const vt=is(Lt(ot,W)),Qt=et(ot,Q(vt,.05*f));if(p("feathers"))for(const St of[-.55,0,.55]){const Tt=Math.cos(St),Vt=Math.sin(St)*Y,Ct={x:vt.x*Tt-vt.y*Vt,y:vt.x*Vt+vt.y*Tt},de=et(Qt,Q(Ct,.16*f));_t.push({k:"ellipse",x:de.x,y:de.y,rx:.2*f,ry:.09*f,rot:Math.atan2(Ct.y,Ct.x),fill:h.hands??h.accent,...m})}p("wand")&&Y===1&&!i.portrait&&_t.push(...ka(e,Qt,is(et(Q(vt,.4),Lt(Q(c,.6),u))),f,x));const Gt=r.hand*f*(p("tiny-arms")?.72:1);if(p("tiny-arms"))for(const St of[-.45,.45]){const Tt=Math.cos(St),Vt=Math.sin(St),Ct={x:vt.x*Tt-vt.y*Vt,y:vt.x*Vt+vt.y*Tt},de=et(Qt,Q(Ct,Gt*.75)),bi=et(Qt,Q(Ct,Gt*1.6)),pe={x:-Ct.y*Gt*.32,y:Ct.x*Gt*.32};_t.push({k:"path",d:J([et(de,pe),bi,Lt(de,pe)],.2),fill:h.belly,...m})}_t.push({k:"circle",x:Qt.x,y:Qt.y,r:Gt,fill:h.hands??h.limbs,...m})}if(p("wings"))for(const v of[-1,1]){const P=k([[v*R*.5,.05*f],[v*(R+.85*f),-.6*f],[v*(R+.72*f),.05*f],[v*(R+.45*f),-.02*f],[v*(R+.3*f),.32*f],[v*R*.6,.55*f]]);B.push({k:"path",d:J(P,.18),fill:h.accent,...m})}if(p("wings-fairy")&&B.push(...wa(e,g,R,f,x)),p("cape")){const v=y+.8*f,P=O+.36*f,D=k([[-R*.92,q+.04*f],[R*.92,q+.04*f],[R+.16*f,y*.5],[P,v],[P*.5,v-.1*f],[0,v],[-P*.5,v-.1*f],[-P,v],[-R-.16*f,y*.5]]);B.push({k:"path",d:Z(D,.6),fill:h.accent,...m})}if(p("backpack")){const v=g(0,.35*f);B.push({k:"rect",x:v.x,y:v.y,w:R*2+.34*f,h:.8*f,r:.16*f,rot:a.angle,fill:e.extraColors?.[0]??h.limbs,...m})}if(p("tank")){const v=g(R*.95,.24*f),P=e.extraColors?.[0]??h.accent,D=g(R*.95,-.3*f);B.push({k:"rect",x:D.x,y:D.y,w:.14*f,h:.16*f,r:.04*f,rot:a.angle,fill:h.outline}),B.push({k:"rect",x:v.x,y:v.y,w:.34*f,h:1*f,r:.17*f,rot:a.angle,fill:P,...m})}if(a.hipsOk&&!i.portrait&&B.push(...ba(e,a,O,x)),p("tentacles")&&a.hipsOk)for(const v of[-1,1]){const P=k([[v*O*.7,y*.9],[v*(O+.22*f),y+.3*f],[v*(O+.48*f),y+.22*f],[v*(O+.5*f),y-.02*f],[v*(O+.34*f),y-.06*f]]);B.push({k:"path",d:Pe(P),stroke:h.outline,lw:.2*f+x*2}),B.push({k:"path",d:Pe(P),stroke:h.limbs,lw:.2*f})}const mt=Math.max(R,O)*r.bulge;if(p("wool")){for(const[P,D]of[[R*.7,q+.02*f],[mt,y*.3],[mt*1.02,y*.62],[(mt+O)/2,y*.92],[O*.55,j]])for(const Y of[-1,1]){const W=g(Y*P,D);G.push({k:"circle",x:W.x,y:W.y,r:.2*f,fill:h.body,...m})}const v=g(0,j+.02*f);G.push({k:"circle",x:v.x,y:v.y,r:.2*f,fill:h.body,...m})}if(p("robe")){const v=y+.58*f,P=O*1.4;G.push({k:"path",d:Z(k([[-R,q],[0,q-.04*f],[R,q],[mt,y*.55],[P,v],[0,v+.06*f],[-P,v],[-mt,y*.55]]),.7),fill:h.body,...m});const D=k([[-P*.94,v-.1*f],[0,v-.04*f],[P*.94,v-.1*f]]);G.push({k:"path",d:Pe(D),stroke:e.extraColors?.[0]??h.accent,lw:.07*f})}else if(p("sheet")){const v=y+.78*f,P=O*1.3;G.push({k:"path",d:Z(k([[-R,q],[R,q],[mt,y*.55],[P,v],[P*.5,v-.2*f],[0,v],[-P*.5,v-.2*f],[-P,v],[-mt,y*.55]]),.9),fill:h.body,...m})}else G.push({k:"path",d:Z(k([[-R,q],[0,q-.04*f],[R,q],[mt,y*.55],[O,j],[0,j+.03*f],[-O,j],[-mt,y*.55]]),.85),fill:h.body,...m});const ut=Math.min(R,O);if(p("pocket")){const v=g(0,y*.74);G.push({k:"rect",x:v.x,y:v.y,w:ut*1.3,h:.3*f,r:.1*f,rot:a.angle,fill:h.belly,stroke:h.outline,lw:x*.8})}else if(p("racing-stripe"))for(const v of[-.1,.1]){const P=g(v*f,q+.02*f),D=g(v*f,j-.04*f);G.push({k:"line",pts:[P.x,P.y,D.x,D.y],stroke:h.belly,lw:.1*f})}else if(h.belly&&h.belly!==h.body&&!p("panel")&&!p("sheet")&&!p("stripes")){const v=g(0,y*.58);G.push({k:"ellipse",x:v.x,y:v.y,rx:ut*.64,ry:Math.max(y*.36,.2*f),rot:a.angle,fill:h.belly})}if(p("spots")){const v=e.extraColors?.[1]??h.belly;for(const[P,D,Y]of[[-.55,.35,.09],[.5,.62,.11],[-.35,.86,.07]]){const W=g(P*ut,D*y);G.push({k:"circle",x:W.x,y:W.y,r:Y*f,fill:v})}}if(p("stripes")){const v=e.extraColors?.[1]??h.accent;for(const P of[.22,.44,.66]){const D=g(-ut*.98,y*P),Y=g(ut*.98,y*P);G.push({k:"line",pts:[D.x,D.y,Y.x,Y.y],stroke:v,lw:.1*f})}}if(p("straps")){const v=e.extraColors?.[1]??h.outline;for(const P of[-1,1]){const D=g(P*R*.62,q+.02*f),Y=g(P*ut*.62,y*.72);G.push({k:"line",pts:[D.x,D.y,Y.x,Y.y],stroke:h.outline,lw:.13*f+x*2}),G.push({k:"line",pts:[D.x,D.y,Y.x,Y.y],stroke:v,lw:.13*f})}}if(p("belt")){const v=g(0,y*.9);G.push({k:"rect",x:v.x,y:v.y,w:O*1.92,h:.17*f,r:.06*f,rot:a.angle,fill:e.extraColors?.[2]??"#4a3426",...m}),G.push({k:"rect",x:v.x,y:v.y,w:.2*f,h:.19*f,r:.04*f,rot:a.angle,fill:"#ffd84a",...m})}if(p("emblem")){const v=g(0,y*.4),P=e.extraColors?.[0]??h.accent,D=J([{x:-.22,y:-.2},{x:.22,y:-.2},{x:.22,y:.04},{x:0,y:.26},{x:-.22,y:.04}],.25);G.push({k:"group",x:v.x,y:v.y,rot:a.angle,s:f,items:[{k:"path",d:D,fill:P,stroke:h.outline,lw:x/f},{k:"group",x:0,y:.01,s:.12,items:[{k:"path",d:ge,fill:P===h.accent?"#ffffff":h.accent}]}]})}if(p("panel")){const v=g(0,y*.5);G.push({k:"rect",x:v.x,y:v.y,w:ut*1.2,h:.38*f,r:.1*f,rot:a.angle,fill:"#24323d",...m}),(e.extraColors??["#ff7a6b","#fbd46a","#7ff0ff"]).slice(0,3).forEach((D,Y)=>{const W=g((Y-1)*ut*.34,y*.5);G.push({k:"circle",x:W.x,y:W.y,r:.075*f,fill:D})})}if(p("badge")){const v=g(-ut*.42,y*.36);G.push({k:"circle",x:v.x,y:v.y,r:.15*f,fill:h.accent,...m}),G.push({k:"group",x:v.x,y:v.y,rot:a.angle,s:.09*f,items:[{k:"path",d:ge,fill:"#ffffff"}]})}if(p("star")){const v=g(-ut*.5,y*.3),P=.15*f;G.push({k:"group",x:v.x,y:v.y,rot:a.angle-.2,s:P,items:[{k:"path",d:ge,fill:e.extraColors?.[0]??"#ffd84a",stroke:h.outline,lw:x*.8/P}]})}if(p("petals")&&G.push(...va(e,g,R,O,mt,y,j,f,x,r)),p("scarf")){const v=Math.max(.04,r.head*(1-r.neck)-.06)*f,P=g(0,v),D=e.extraColors?.[0]??h.accent,Y=g(R*.45,v+.28*f);G.push({k:"rect",x:Y.x,y:Y.y,w:.16*f,h:.42*f,r:.06*f,rot:a.angle+.15,fill:D,...m}),G.push({k:"rect",x:P.x,y:P.y,w:R*2.05,h:.2*f,r:.1*f,rot:a.angle,fill:D,...m})}const Dt={k:"group",x:a.head.x,y:a.head.y,rot:a.headRot,s:a.headR,items:ma(e,x/a.headR)};return[...B,...It,...G,...nt,Dt,...yt]}var Yi=new WeakMap,ya=64;function ma(t,e){const s=Number(e.toPrecision(4));let i=Yi.get(t);i||Yi.set(t,i=new Map);let n=i.get(s);return n||(i.size>=ya&&i.clear(),i.set(s,n=Bi(t,s))),n}function xa(t,e,s,i,n,r){const a=ga(t,e,s,i,n,r);if(!t.bodyExtras.includes("strong-legs"))return[a];const l=s.U*r,h=et(et(e,Q(s.d,.07*l)),Q(s.r,i*.06*l)),o=[a];for(const c of[-1,0,1]){const u=et(et(h,Q(s.r,c*.12*l)),Q(s.d,.09*l));o.push({k:"ellipse",x:u.x,y:u.y,rx:.05*l,ry:.045*l,rot:s.angle,fill:t.palette.belly,stroke:t.palette.outline,lw:n*.8})}return o}function ga(t,e,s,i,n,r){const a=t.palette,{d:l,r:h}=s,o=s.U*r,c=et(et(e,Q(l,.07*o)),Q(h,i*.06*o)),u={stroke:a.outline,lw:n},f=a.feet??a.limbs;if(t.bodyExtras.includes("fins")){const y=J([{x:-.13,y:-.06},{x:.13,y:-.06},{x:.24,y:.46},{x:-.24,y:.46}],.22);return{k:"group",x:c.x,y:c.y,rot:s.angle,s:o,items:[{k:"path",d:y,fill:f,stroke:a.outline,lw:n/o},{k:"line",pts:[0,.06,0,.38],stroke:a.outline,lw:n/o,alpha:.5}]}}return t.bodyExtras.includes("flippers")?{k:"ellipse",x:c.x,y:c.y,rx:.27*o,ry:.11*o,rot:s.angle,fill:f,...u}:t.bodyExtras.includes("boots")?{k:"rect",x:c.x,y:c.y,w:.4*o,h:.24*o,r:.09*o,rot:s.angle,fill:f,...u}:{k:"ellipse",x:c.x,y:c.y,rx:.2*o,ry:.13*o,rot:s.angle,fill:f,...u}}function ba(t,e,s,i){const n=t.palette,{U:r,L:a,S:l,r:h,d:o}=e,c=(x,m)=>({x:l.x+h.x*x+o.x*m,y:l.y+h.y*x+o.y*m}),u=x=>x.map(([m,g])=>c(m,g)),f={stroke:n.outline,lw:i},y=(x,m,g)=>[{k:"path",d:Pe(x),stroke:n.outline,lw:m+i*2},{k:"path",d:Pe(x),stroke:g,lw:m}],p=[];switch(t.tail){case"none":break;case"fluffy":{const x=u([[s*.5,a*.95],[s+.28*r,a*1],[s+.72*r,a*.62],[s+.78*r,a*.12],[s+.52*r,a*.32],[s+.3*r,a*.6],[s*.6,a*.7]]);p.push({k:"path",d:Z(x),fill:n.body,...f});const m=c(s+.72*r,a*.2);p.push({k:"ellipse",x:m.x,y:m.y,rx:.13*r,ry:.2*r,rot:e.angle+.25,fill:n.belly,...f});break}case"brush":{const x=u([[s*.4,a*.98],[s+.42*r,a*1.06],[s+.98*r,a*.66],[s+1.06*r,a*.12],[s+.86*r,-.04*r],[s+.66*r,a*.36],[s+.3*r,a*.66],[s*.5,a*.68]]);p.push({k:"path",d:Z(x),fill:n.body,...f});const m=u([[s+1.03*r,a*.36],[s+1.06*r,a*.12],[s+.86*r,-.04*r],[s+.72*r,a*.24],[s+.86*r,a*.34]]);p.push({k:"path",d:Z(m),fill:n.belly,...f});break}case"pom":{const x=c(s+.06*r,a*.88);p.push({k:"circle",x:x.x,y:x.y,r:.2*r,fill:n.belly,...f});break}case"long":case"striped":case"tuft":{const x=u([[s*.6,a*.9],[s+.35*r,a*.85],[s+.58*r,a*.4],[s+.5*r,-.02*r]]);if(p.push(...y(x,.14*r,n.body)),t.tail==="tuft"){const m=x[x.length-1];p.push({k:"circle",x:m.x,y:m.y,r:.16*r,fill:t.extraColors?.[0]??n.accent,...f})}if(t.tail==="striped"){for(const g of[.35,.6,.85]){const k=c(s+.35*r+.22999999999999998*r*(g*1.4>1?1:g*1.4),a*(.85-.85*g));p.push({k:"line",pts:[k.x-h.x*.08*r,k.y-h.y*.08*r,k.x+h.x*.08*r,k.y+h.y*.08*r],stroke:t.extraColors?.[0]??n.outline,lw:.06*r})}const m=x[x.length-1];p.push({k:"circle",x:m.x,y:m.y,r:.07*r,fill:t.extraColors?.[0]??n.outline})}break}case"curl":{const x=u([[s*.6,a*.9],[s+.4*r,a*.88],[s+.62*r,a*.45],[s+.5*r,a*.12],[s+.3*r,a*.24],[s+.36*r,a*.42]]);p.push(...y(x,.12*r,n.limbs));break}case"fish":{const x=u([[s*.6,a*.9],[s+.36*r,a*.86],[s+.6*r,a*.5]]);p.push(...y(x,.17*r,n.body));const m=x[x.length-1],g=J([{x:0,y:.06},{x:-.26,y:-.34},{x:.02,y:-.12},{x:.32,y:-.3}],.2);p.push({k:"group",x:m.x,y:m.y,rot:e.angle+.35,s:r,items:[{k:"path",d:g,fill:n.body,stroke:n.outline,lw:i/r}]});break}case"plume":{const x=t.extraColors??[n.accent];[0,1,2].forEach(m=>{const g=c(s+(.12+m*.13)*r,a+(.32-m*.06)*r);p.push({k:"ellipse",x:g.x,y:g.y,rx:.11*r,ry:.44*r,rot:e.angle-.55+m*.28,fill:x[(m+1)%x.length],...f})});break}case"thick":{const x=u([[s*.3,a*.42],[s+.42*r,a*.62],[s+.92*r,a*.96],[s+1.32*r,a*1.08],[s+1.44*r,a*.98],[s+.98*r,a*1.2],[s+.4*r,a*1.22],[s*.3,a*1.12]]);p.push({k:"path",d:Z(x,.8),fill:n.body,...f});const m=t.extraColors?.[0]??n.accent;for(const[g,k,E]of[[.28,.58,.26],[.62,.8,.22],[.96,1,.16]]){const w=c(s+g*r,a*k+.03*r),T=c(s+(g-.1)*r,a*k+E*r);p.push({k:"line",pts:[w.x,w.y,T.x,T.y],stroke:m,lw:.09*r})}break}case"spiky":case"arrow":{const x=u([[s*.3,a*.55],[s+.35*r,a*.68],[s+.95*r,a*.86],[s+.35*r,a*1.08],[s*.3,a*1.08]]);if(t.tail==="spiky"){for(const m of[.15,.45,.72]){const g=s+(.2+m*.7)*r,k=a*(.66+m*.19);p.push({k:"path",d:J(u([[g-.12*r,k+.05*r],[g,k-.2*r],[g+.12*r,k+.07*r]]),.2),fill:n.accent,...f})}p.push({k:"path",d:Z(x,.7),fill:n.body,...f})}else{const m=u([[s*.6,a*.9],[s+.4*r,a*.92],[s+.62*r,a*.5],[s+.62*r,a*.18]]);p.push(...y(m,.13*r,n.body));const g=m[m.length-1];p.push({k:"group",x:g.x,y:g.y,rot:e.angle,s:r,items:[{k:"path",d:J([{x:-.15,y:.04},{x:0,y:-.22},{x:.15,y:.04}],.2),fill:n.accent,stroke:n.outline,lw:i/r}]})}break}}return p}function ka(t,e,s,i,n){const r=t.palette,a=et(e,Q(s,-.08*i)),l=et(e,Q(s,.52*i)),h=.2*i;return[{k:"line",pts:[a.x,a.y,l.x,l.y],stroke:r.outline,lw:.06*i+n*2},{k:"line",pts:[a.x,a.y,l.x,l.y],stroke:"#fff3d6",lw:.06*i},{k:"circle",x:l.x,y:l.y,r:.24*i,fill:r.accent,alpha:.28},{k:"group",x:l.x,y:l.y,rot:Math.atan2(s.y,s.x)+Math.PI/2,s:h,items:[{k:"path",d:ge,fill:r.accent,stroke:r.outline,lw:n*.9/h}]}]}function wa(t,e,s,i,n){const r=t.palette,a=t.extraColors?.[0]??"#cdeeff",l=[];for(const h of[-1,1]){const o=[[[h*s*.3,.12*i],[h*(s+.42*i),-.66*i],[h*(s+1*i),-.74*i],[h*(s+1.02*i),-.18*i],[h*(s+.5*i),.26*i]],[[h*s*.4,.3*i],[h*(s+.6*i),.36*i],[h*(s+.74*i),.78*i],[h*(s+.3*i),.9*i]]];for(const c of o){const u=Z(c.map(([x,m])=>e(x,m)),.9);l.push({k:"path",d:u,fill:a,alpha:.6}),l.push({k:"path",d:u,stroke:r.outline,lw:n*.9});const f=c[Math.floor(c.length/2)],y=e(c[0][0],c[0][1]),p=e(c[0][0]+(f[0]-c[0][0])*.75,c[0][1]+(f[1]-c[0][1])*.75);l.push({k:"line",pts:[y.x,y.y,p.x,p.y],stroke:"#ffffff",lw:n*.9,alpha:.85})}for(const[c,u,f]of[[s+.72*i,-.42*i,.075*i],[s+.44*i,-.16*i,.05*i],[s+.5*i,.6*i,.055*i]]){const y=e(h*c,u);l.push({k:"group",x:y.x,y:y.y,s:f,items:[{k:"path",d:ge,fill:"#ffffff"}]})}}return l}function va(t,e,s,i,n,r,a,l,h,o){const c=t.palette,u=t.extraColors?.[1]??c.belly,f=[],y=Math.atan2(e(1,0).y-e(0,0).y,e(1,0).x-e(0,0).x),p=5,x=Math.max(i,n*.92)*1.08,m=(r*.8+a)/2,g=[0,4,1,3,2];for(const E of g){const w=E/(p-1)-.5,T=e(w*2*x,m+(.5-Math.abs(w))*.1*l);f.push({k:"ellipse",x:T.x,y:T.y,rx:x*.3,ry:.34*l,rot:y-w*.6,fill:E%2?u:c.body,stroke:c.outline,lw:h})}const k=Math.max(.04,o.head*(1-o.neck)-.04)*l;for(const E of[-1,1,0]){const w=e(E*s*.32,k+(E?0:.05*l));f.push({k:"ellipse",x:w.x,y:w.y,rx:s*.26,ry:.12*l,rot:y+E*.5,fill:E?u:c.body,stroke:c.outline,lw:h*.9})}return f}var Ma={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 Ea(t,{cx:e=.5,cy:s=.36,T:i=.18}={}){const n={...Ma,...t},r=new Array(Ti*3).fill(0),a=(o,[c,u],f=.99)=>{r[o*3]=e+c*i,r[o*3+1]=s+u*i,r[o*3+2]=f};for(const o of Object.keys(H))a(H[o],n[o]);const l=n.tilt??0,h=(o,c)=>[n.nose[0]+o*Math.cos(l)-c*Math.sin(l),n.nose[1]+o*Math.sin(l)+c*Math.cos(l)];return a(Kt.leftEye,h(-.1,-.08)),a(Kt.rightEye,h(.1,-.08)),a(Kt.leftEar,h(-.22,-.02)),a(Kt.rightEar,h(.22,-.02)),r}var Aa=()=>Ea({}),ji=.5,_a=.15,Sa=Object.freeze({lag:.5,extrapolate:.75,maxExtrapolateMs:50}),Qi=class{constructor(t={}){d(this,"tracks",new Map),d(this,"offset",NaN),d(this,"lastArrival",NaN),d(this,"interval",33),d(this,"lastT",NaN),d(this,"lostMs"),d(this,"maxExtrapolateMs"),d(this,"lag"),d(this,"extrapolate"),this.lostMs=t.lostMs??250,this.maxExtrapolateMs=t.maxExtrapolateMs??25,this.lag=Ki(t.lag,1),this.extrapolate=Ki(t.extrapolate,.5)}get delayMs(){return this.interval*this.lag}push(t,e,s,i=Vi()){Number.isFinite(e)||(e=i),this.clock(e,i);const n=this.tracks.get(t);if(!n||e-n.tb>this.lostMs||e<n.tb-this.lostMs||s.length!==n.b.length){this.tracks.set(t,{a:null,ta:e,b:s,tb:e,out:null,outAt:NaN});return}if(s===n.b||e<=n.tb){e===n.tb&&s!==n.b&&(n.b=s,n.out=null);return}n.a=n.b,n.ta=n.tb,n.b=s,n.tb=e,n.out=null}at(t,e=Vi()){const s=this.tracks.get(t);if(!s)return null;if(!s.a)return s.b;if(s.out&&s.outAt===e)return s.out;const i=e-this.offset-this.interval*this.lag,n=s.tb-s.ta,r=Math.min(n*this.extrapolate,this.maxExtrapolateMs),a=Math.min(Math.max((i-s.ta)/n,0),1+r/n);return s.out=Ta(s.a,s.b,a),s.outAt=e,s.out}forget(t){this.tracks.delete(t)}clear(){this.tracks.clear()}clock(t,e){const s=e-t;if(!Number.isFinite(this.offset)||s<this.offset||s>this.offset+1e3?this.offset=s:Number.isFinite(this.lastArrival)&&(this.offset+=Math.min(s-this.offset,(e-this.lastArrival)/1e3)),this.lastArrival=e,Number.isFinite(this.lastT)&&t>this.lastT){const i=t-this.lastT;i<this.interval*3+20&&(this.interval+=(Math.min(Math.max(i,8),100)-this.interval)*.1)}t<=this.lastT||(this.lastT=t)}},Vi=()=>globalThis.performance?.now()??Date.now(),Ki=(t,e)=>typeof t=="number"&&Number.isFinite(t)?Math.min(Math.max(t,0),1):e;function Ta(t,e,s){const i=e.slice(),n=s<.5?t:e;for(let r=0;r+2<e.length;r+=3){const a=t[r],l=t[r+1],h=e[r],o=e[r+1];t[r+2]>=ji&&e[r+2]>=ji&&Math.abs(h-a)+Math.abs(o-l)<_a?(i[r]=a+(h-a)*s,i[r+1]=l+(o-l)*s,i[r+2]=t[r+2]+(e[r+2]-t[r+2])*Math.min(s,1)):(i[r]=n[r],i[r+1]=n[r+1],i[r+2]=n[r+2])}return i}var eh=Ii.map(t=>t.id),ns=new Map(Ii.map(t=>[t.id,t])),Ne=ns.get("fox"),Ca=t=>typeof t=="string"&&ns.has(t),rs=t=>ns.get(t),Ra=t=>typeof t=="string"?ns.get(t)??Ne:t;function Fa(t,e,s){const i=Ra(t),n=Aa(),r=Hi(i,s),a=Os(n,{x:0,y:0,w:1,h:1},{band:r}),l=Ji(Bi(i,.05)),h=-l.minY,o=Math.min(.27,.43/Math.max(h,1))*e,c=i.head==="snout-long"?(l.minX+l.maxX)/2*o:0,u=o/oe[r].head/a.U,f=.5*e+Math.min(0,(h-1.6)*.06*e),y={x:e/2-c-a.head.x*u,y:f-a.head.y*u,w:u,h:u};return Wi(n,i,y,{portrait:!0,band:r})}function La(t,e,s=.5){if(!t||t.length!==e.length)return e.slice();const i=e.slice();for(let n=0;n+2<e.length;n+=3){const r=t[n+2],a=e[n+2],l=r>=.5,h=a>=.5;l&&a>=.3&&(i[n+2]=Math.max(a,.5));const o=Math.hypot(e[n]-t[n],e[n+1]-t[n+1]);if(l&&h&&o<.15){const c=s*Math.min(1,Zi+(1-Zi)*o/Na);i[n]=t[n]+(e[n]-t[n])*c,i[n+1]=t[n+1]+(e[n+1]-t[n+1])*c}else l&&!h&&i[n+2]>=.5&&(i[n]=t[n],i[n+1]=t[n+1])}return za(t,e,i,s*Ia),i}var Pa=.8,Zi=.1,Na=.03,Ia=.35,Oa=11;function za(t,e,s,i){const n=H.leftShoulder*3,r=H.rightShoulder*3,a=(u,f)=>u[f+2]>=.5;if(!a(t,n)||!a(t,r)||!a(e,n)||!a(e,r))return;const l=(u,f)=>(u[n+f]+u[r+f])/2,h=[l(t,0),l(t,1)],o=[l(e,0),l(e,1)],c=[l(s,0),l(s,1)];for(let u=0;u<Oa&&u*3+2<e.length;u++){const f=u*3;if(!a(t,f)||!a(e,f))continue;const y=[t[f]-h[0],t[f+1]-h[1]],p=[e[f]-o[0],e[f+1]-o[1]];Math.hypot(p[0]-y[0],p[1]-y[1])>=.15||(s[f]=c[0]+y[0]+(p[0]-y[0])*i,s[f+1]=c[1]+y[1]+(p[1]-y[1])*i)}}function Ji(t){const e={minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0},s=(i,n)=>{e.minX=Math.min(e.minX,i),e.minY=Math.min(e.minY,n),e.maxX=Math.max(e.maxX,i),e.maxY=Math.max(e.maxY,n)};for(const i of t){const n="lw"in i&&i.stroke?(i.lw??1)/2:0;switch(i.k){case"circle":s(i.x-i.r-n,i.y-i.r-n),s(i.x+i.r+n,i.y+i.r+n);break;case"ellipse":case"rect":{const r=i.k==="ellipse"?i.rx:i.w/2,a=i.k==="ellipse"?i.ry:i.h/2,l=Math.max(r,a)+n;s(i.x-l,i.y-l),s(i.x+l,i.y+l);break}case"path":{const r=Yr(i.d);for(let a=0;a+1<r.length;a+=2)s(r[a]-n,r[a+1]-n),s(r[a]+n,r[a+1]+n);break}case"line":for(let r=0;r+1<i.pts.length;r+=2)s(i.pts[r]-n,i.pts[r+1]-n),s(i.pts[r]+n,i.pts[r+1]+n);break;case"group":{const r=Ji(i.items);if(!Number.isFinite(r.minX))break;const a=i.s??1,l=Math.cos(i.rot??0),h=Math.sin(i.rot??0);for(const[o,c]of[[r.minX,r.minY],[r.maxX,r.minY],[r.minX,r.maxY],[r.maxX,r.maxY]])s(i.x+(o*l-c*h)*a,i.y+(o*h+c*l)*a);break}}}return e}var be=()=>Float64Array.of(1,0,0,1,0,0);function Xt(t,e,s,i,n,r,a){const l=n?Math.cos(n):1,h=n?Math.sin(n):0,o=l*r,c=h*r,u=-h*a,f=l*a;if(!e)return t[0]=o,t[1]=c,t[2]=u,t[3]=f,t[4]=s,t[5]=i,t;const y=e[0],p=e[1],x=e[2],m=e[3];return t[0]=y*o+x*c,t[1]=p*o+m*c,t[2]=y*u+x*f,t[3]=p*u+m*f,t[4]=y*s+x*i+e[4],t[5]=p*s+m*i+e[5],t}function Da(t,e,s){const i=t[0]*t[3]-t[1]*t[2];if(Math.abs(i)<1e-12)return null;const n=e-t[4],r=s-t[5];return[(t[3]*n-t[2]*r)/i,(-t[1]*n+t[0]*r)/i]}var tn={white:16777215,black:0,red:16711680,transparent:0},Ie=new Map;function Bt(t){if(typeof t=="number")return[t&16777215,1];const e=Ie.get(t);if(e)return e;let s=[16777215,1];const i=t.trim().toLowerCase();if(i[0]==="#"){const n=i.slice(1),r=n.length<=4?[...n].map(l=>l+l).join(""):n,a=parseInt(r.slice(0,6),16);Number.isFinite(a)&&(s=[a,r.length===8?parseInt(r.slice(6,8),16)/255:1])}else if(i.startsWith("rgb")){const n=i.match(/-?\d*\.?\d+%?/g)?.map(o=>o.endsWith("%")?parseFloat(o)/100*255:parseFloat(o))??[],[r=255,a=255,l=255]=n,h=n[3]===void 0?1:i.match(/,\s*[\d.]+%\s*\)$/)?n[3]/255:n[3];s=[(zs(r)<<16|zs(a)<<8|zs(l))>>>0,Math.min(Math.max(h,0),1)]}else if(i in tn)s=[tn[i],i==="transparent"?0:1];else if(typeof document<"u"){const n=document.createElement("canvas").getContext("2d");if(n){n.fillStyle="#ffffff",n.fillStyle=i;const r=n.fillStyle;if(r!==i)return Ie.set(t,s=Bt(r)),s}}return Ie.size>512&&Ie.clear(),Ie.set(t,s),s}var zs=t=>Math.min(Math.max(Math.round(t),0),255);function ke(t,e,s=!1){const i=Math.min(Math.max(e,0),1),n=(t>>16&255)*i,r=(t>>8&255)*i,a=(t&255)*i,l=s?0:i*255;return(Math.round(l)<<24|Math.round(a)<<16|Math.round(r)<<8|Math.round(n))>>>0}var Oe=(t,e=1)=>`rgba(${t>>16&255},${t>>8&255},${t&255},${e})`;function en(t,e){if(t===16777215)return e;if(e===16777215)return t;const s=i=>Math.round((t>>i&255)*(e>>i&255)/255);return(s(16)<<16|s(8)<<8|s(0))>>>0}var ze={linear:t=>t,quadIn:t=>t*t,quadOut:t=>t*(2-t),quadInOut:t=>t<.5?2*t*t:-1+(4-2*t)*t,cubicOut:t=>1-(1-t)**3,sineInOut:t=>-(Math.cos(Math.PI*t)-1)/2,backOut:t=>1+(1.70158+1)*(t-1)**3+1.70158*(t-1)**2,elasticOut:t=>t===0||t===1?t:2**(-10*t)*Math.sin((t*10-.75)*(2*Math.PI/3))+1,bounceOut:t=>t<1/2.75?7.5625*t*t:t<2/2.75?7.5625*(t-=1.5/2.75)*t+.75:t<2.5/2.75?7.5625*(t-=2.25/2.75)*t+.9375:7.5625*(t-=2.625/2.75)*t+.984375};function Ba(t){let e=t>>>0;return()=>{e=e+1831565813>>>0;let s=e;return s=Math.imul(s^s>>>15,s|1),s^=s+Math.imul(s^s>>>7,s|61),((s^s>>>14)>>>0)/4294967296}}var De=1,sn=2,as=0,Pt=1,Ua=4294967295,A={cap:0,epoch:0,x:new Float64Array(0),y:new Float64Array(0),rot:new Float64Array(0),sx:new Float64Array(0),sy:new Float64Array(0),alpha:new Float64Array(0),la:new Float64Array(0),lb:new Float64Array(0),lc:new Float64Array(0),ld:new Float64Array(0),world:new Float64Array(0),tint:new Uint32Array(0),flags:new Uint8Array(0),moved:new Uint8Array(0),dirty:new Uint8Array(0),gen:new Uint32Array(0),parent:new Int32Array(0),first:new Int32Array(0),next:new Int32Array(0),prev:new Int32Array(0),stamp:new Uint32Array(0),pass:0,free:new Int32Array(0),freeHead:0,freeCount:0,top:2},Zt=[],Ha="x y rot sx sy alpha la lb lc ld world tint flags moved dirty gen parent first next prev stamp".split(" ");function nn(t){const e=A;for(const i of Ha){const n=e[i],r=new n.constructor(i==="world"?t*6:t);r.set(n),e[i]=r}const s=new Int32Array(t);for(let i=0;i<A.freeCount;i++)s[i]=A.free[(A.freeHead+i)%A.cap];for(A.free=s,A.freeHead=0,A.cap=t,A.epoch++;Zt.length<t;)Zt.push(null)}function Ds(t){A.x[t]=A.y[t]=A.rot[t]=0,A.sx[t]=A.sy[t]=A.alpha[t]=1,A.la[t]=A.ld[t]=1,A.lb[t]=A.lc[t]=0;const e=t*6,s=A.world;s[e]=s[e+3]=1,s[e+1]=s[e+2]=s[e+4]=s[e+5]=0,A.tint[t]=16777215,A.flags[t]=De|sn,A.moved[t]=1,A.dirty[t]=0,A.parent[t]=A.first[t]=A.next[t]=A.prev[t]=-1}nn(256),Ds(as),A.flags[as]=0,Ds(Pt),A.flags[Pt]=0;function Ga(){let t;if(A.freeCount){t=A.free[A.freeHead],A.freeHead=(A.freeHead+1)%A.cap,A.freeCount--;const e=Zt[t];e&&(e._i=as,e._g=-1,Zt[t]=null)}else A.top===A.cap&&nn(A.cap*2),t=A.top++;return Ds(t),t}function rn(t,e){Bs(t);for(let i=A.first[t];i>=0;){const n=A.next[i];A.parent[i]=A.next[i]=A.prev[i]=-1,i=n}A.first[t]=-1,A.flags[t]=A.flags[t]&~sn,A.moved[t]=0;const s=A.gen[t]+1;A.gen[t]=s,s!==Ua&&(e&&(Zt[t]=e),A.free[(A.freeHead+A.freeCount)%A.cap]=t,A.freeCount++)}function Xa(t){for(let e=0;e<Zt.length;e++){const s=Zt[e];s&&t(s)&&(s._i=as,s._g=-1,Zt[e]=null)}}function $a(t,e){Bs(t);const s=A.first[e];A.parent[t]=e,A.next[t]=s,A.prev[t]=-1,s>=0&&(A.prev[s]=t),A.first[e]=t,A.moved[t]=1}function Bs(t){const e=A.parent[t];if(e<0)return;const s=A.next[t],i=A.prev[t];i>=0?A.next[i]=s:A.first[e]=s,s>=0&&(A.prev[s]=i),A.parent[t]=A.next[t]=A.prev[t]=-1}var Be={root:-1,gen:-1,world:new Float64Array(6)};function qa(t){const e=++A.pass,s=A.world,i=t*6,n=Be.world;let r=Be.root!==t||Be.gen!==A.gen[t];for(let a=0;a<6;a++)n[a]!==s[i+a]&&(r=!0),n[a]=s[i+a];Be.root=t,Be.gen=A.gen[t],A.stamp[t]=r?e:e-1}function Wa(t){A.stamp[t]=A.pass}function an(t){for(let e=A.first[t];e>=0;){const s=A.next[e];an(e),e=s}rn(t)}var Us=typeof FinalizationRegistry=="function"?new FinalizationRegistry(t=>A.gen[t.i]===t.g&&an(t.i)):null;function on(t){t._reg||!Us||(t._reg=!0,Us.register(t,{i:t._i,g:t._g},t))}function Ya(t){t._reg&&Us.unregister(t)}var Hs=1,Gs=2,Xs=3,$s=4;function qs(t){if(t){for(let e=0;e<t.length;e++)if(t[e].enabled)return!0}return!1}function ja(t,e){let s=0;for(let i=0;i<t.length;i++){const n=t[i];n.enabled&&n.pad&&(s+=n.pad(e))}return s}var Ut={gl:null,c2d:null,live:null},V=new Float64Array(3),Ws=4,Qa=1,Ys=()=>Qa++,lt=be(),F=A,he=class{constructor(t){d(this,"kernel",t),d(this,"_i",Ga()),d(this,"_g",F.gen[this._i]),d(this,"_wv",null),d(this,"_wi",-1),d(this,"_we",-1),d(this,"blend","normal"),d(this,"_data",null),d(this,"parent",null),d(this,"hitRadius",null),d(this,"clip",null),d(this,"mask",null),d(this,"filters",null),d(this,"_z",0),d(this,"anchorX",0),d(this,"anchorY",0),d(this,"_pool",null),d(this,"_free",!1),d(this,"_reg",!1)}get x(){return F.x[this._i]}set x(t){const e=this._i||Pt;F.x[e]=t,F.moved[e]=1}get y(){return F.y[this._i]}set y(t){const e=this._i||Pt;F.y[e]=t,F.moved[e]=1}get rotation(){return F.rot[this._i]}set rotation(t){const e=this._i||Pt;F.rot[e]=t,F.dirty[e]=F.moved[e]=1}get scaleX(){return F.sx[this._i]}set scaleX(t){const e=this._i||Pt;F.sx[e]=t,F.dirty[e]=F.moved[e]=1}get scaleY(){return F.sy[this._i]}set scaleY(t){const e=this._i||Pt;F.sy[e]=t,F.dirty[e]=F.moved[e]=1}get alpha(){return F.alpha[this._i]}set alpha(t){const e=this._i||Pt;F.alpha[e]=t,F.moved[e]=1}get visible(){return(F.flags[this._i]&De)!==0}set visible(t){const e=this._i||Pt;t?F.flags[e]=F.flags[e]|De:F.flags[e]=F.flags[e]&~De,F.moved[e]=1}get destroyed(){return F.gen[this._i]!==this._g}get world(){const t=this._i||Pt;return(this._wi!==t||this._we!==F.epoch)&&(this._wv=F.world.subarray(t*6,t*6+6),this._wi=t,this._we=F.epoch),this._wv}get data(){return this._data??(this._data={})}set data(t){this._data=t}get scale(){return this.scaleX}set scale(t){this.scaleX=this.scaleY=t}get z(){return this._z}set z(t){t!==this._z&&(this._z=t,this.parent&&(this.parent.sortDirty=!0))}get tint(){return F.tint[this._i]}set tint(t){F.tint[this._i||Pt]=typeof t=="number"?t&16777215:Bt(t)[0]}set anchor(t){typeof t=="number"?this.anchorX=this.anchorY=t:(this.anchorX=t.x,this.anchorY=t.y)}get width(){return 0}set width(t){}get height(){return 0}set height(t){}set(t){for(const e in t){const s=t[e];s!==void 0&&(this[e]=s)}return this}destroy(){this.destroyed||(this.visible=!1,this.parent&&(this.parent.dead=!0,this.parent=null),rn(this._i,this),Ya(this),this.kernel.tweens.stopAll(this),this._pool?.forget(this))}updateWorld(){const t=this.parent?this.parent.updateWorld():null;return Xt(this.world,t,this.x,this.y,this.rotation,this.scaleX,this.scaleY)}draw(t,e,s){}};function Va(t){Xa(e=>e.kernel===t)}var js=!1,ln=Object.freeze([]),Qs=class br extends he{constructor(e){super(e),d(this,"children",ln),d(this,"sortDirty",!1),d(this,"dead",!1),on(this)}add(e,...s){this.adopt(e);for(let i=0;i<s.length;i++)this.adopt(s[i]);return e}adopt(e){e.parent&&e.parent.detach(e),e.parent=this,!e.destroyed&&!this.destroyed&&$a(e._i,this._i),this.children===ln&&(this.children=[]),this.children.push(e),(e.z!==0||this.sortDirty)&&(this.sortDirty=!0)}remove(e){this.detach(e),e._pool||on(e)}detach(e){const s=this.children,i=s.indexOf(e);if(i>=0){for(let n=i+1;n<s.length;n++)s[n-1]=s[n];s.pop()}e.parent===this&&(e.parent=null,e.destroyed||Bs(e._i))}clear(){for(const e of this.children)e.destroy()}destroy(){for(const e of this.children)e.destroy();super.destroy()}sweep(){if(this.dead){this.dead=!1;let e=0;for(const s of this.children)s.destroyed?s.parent===this&&(s.parent=null):this.children[e++]=s;this.children.length=e}for(const e of this.children)e instanceof br&&e.sweep()}draw(e,s,i){if(js)return F.parent[this._i]<0&&!this.destroyed&&Wa(this._i),this.drawChildren(e,s,i);js=!0;try{this.destroyed||qa(this._i),this.drawChildren(e,s,i)}finally{js=!1}}drawChildren(e,s,i){if(this.sortDirty){const l=new Map(this.children.map((h,o)=>[h,o]));this.children.sort((h,o)=>h.z-o.z||l.get(h)-l.get(o)),this.sortDirty=!1}const n=this.children,r=this._i,a=F.stamp[r]===F.pass;for(let l=0;l<n.length;l++){const h=n[l],o=h._i,c=F.alpha[o];if(F.gen[o]!==h._g||!(F.flags[o]&De)||c<=0)continue;if(a||F.moved[o]){F.moved[o]=0,F.stamp[o]=F.pass;let y,p,x,m;if(F.dirty[o]){F.dirty[o]=0;const O=F.rot[o],q=O?Math.cos(O):1,j=O?Math.sin(O):0,B=F.sx[o],It=F.sy[o];F.la[o]=y=q*B,F.lb[o]=p=j*B,F.lc[o]=x=-j*It,F.ld[o]=m=q*It}else y=F.la[o],p=F.lb[o],x=F.lc[o],m=F.ld[o];const g=F.world,k=F.x[o],E=F.y[o],w=o*6,T=r*6,_=g[T],L=g[T+1],I=g[T+2],R=g[T+3];g[w]=_*y+I*p,g[w+1]=L*y+R*p,g[w+2]=_*x+I*m,g[w+3]=L*x+R*m,g[w+4]=_*k+I*E+g[T+4],g[w+5]=L*k+R*E+g[T+5]}const u=s*c,f=en(i,F.tint[o]);h.clip||h.mask||h.filters?cn(e,h,u,f):h.draw(e,u,f)}}},pt=new Float64Array(128),ce=0,Vs=new Float64Array(8);function hn(t,e,s,i){e.clip||e.mask||e.filters?cn(t,e,s,i):e.draw(t,s,i)}function cn(t,e,s,i){const n=t.r,r=e.world,a=e.clip;let l=!1,h=!1;if(a)if(Math.abs(r[1])<1e-9&&Math.abs(r[2])<1e-9&&ce<32){const u=r[0]*a.x+r[4],f=r[0]*(a.x+a.width)+r[4],y=r[3]*a.y+r[5],p=r[3]*(a.y+a.height)+r[5];let x=Math.min(u,f),m=Math.max(u,f),g=Math.min(y,p),k=Math.max(y,p);if(ce){const w=(ce-1)*4;x=Math.max(x,pt[w]),g=Math.max(g,pt[w+1]),m=Math.min(m,pt[w+2]),k=Math.min(k,pt[w+3])}const E=ce++*4;pt[E]=x,pt[E+1]=g,pt[E+2]=m,pt[E+3]=k,n.clip(x,g,Math.max(m-x,0),Math.max(k-g,0)),h=!0}else l=!0;const o=e.mask&&e.mask.visible?e.mask:null,c=qs(e.filters)?e.filters:null;try{if(l&&n.beginLayer(),o&&n.beginLayer(),c?(e.draw(t,n.beginLayer()?1:s,i),n.endLayer(s,c)):e.draw(t,s,i),o&&(n.beginMask(),Xt(o.world,r,o.x,o.y,o.rotation,o.scaleX,o.scaleY),hn(t,o,o.alpha,16777215),n.endLayer(1)),l&&a){n.beginMask();for(let u=0;u<4;u++){const f=u===1||u===2?a.x+a.width:a.x,y=u>1?a.y+a.height:a.y;Vs[u*2]=r[0]*f+r[2]*y+r[4],Vs[u*2+1]=r[1]*f+r[3]*y+r[5]}n.polygon(Vs,4,16777215,1),n.endLayer(1)}}finally{if(h)if(ce--,ce){const u=(ce-1)*4;n.clip(pt[u],pt[u+1],pt[u+2]-pt[u],pt[u+3]-pt[u+1])}else n.unclip()}}var we=class extends he{constructor(t,e,s){super(t),d(this,"_frame",null),d(this,"_w",null),d(this,"_h",null),d(this,"slice",0),d(this,"autoAnchor",!0),d(this,"frameName",null),e&&(this.frame=e),s?.anchor===void 0&&this.useFrameAnchor(),s&&this.set(s)}get frame(){return this._frame}set frame(t){this.frameName=typeof t=="string"?t:null,this._frame=typeof t=="string"?this.kernel.frame(t):t,this.autoAnchor&&this.useFrameAnchor()}set anchor(t){this.autoAnchor=!1,super.anchor=t}get naturalWidth(){const t=this.frameNow();return t?(t.sw??t.w)/t.scale-t.margin*2:0}get naturalHeight(){const t=this.frameNow();return t?(t.sh??t.h)/t.scale-t.margin*2:0}get width(){return this._w??this.naturalWidth}set width(t){this._w=t}get height(){return this._h??this.naturalHeight}set height(t){this._h=t}sizeQ(t){Ee[0]=this._w??(t.sw??t.w)/t.scale-t.margin*2,Ee[1]=this._h??(t.sh??t.h)/t.scale-t.margin*2}frameNow(){return this.frameName&&!this.kernel.atlas.valid(this._frame)&&(this._frame=this.kernel.frame(this.frameName)),this._frame}useFrameAnchor(){const t=this._frame;if(!t)return;const e=(t.sw??t.w)/t.scale-t.margin*2,s=(t.sh??t.h)/t.scale-t.margin*2;this.anchorX=e>0?(t.ox-t.margin)/e:0,this.anchorY=s>0?(t.oy-t.margin)/s:0}draw(t,e,s){const i=this.frameNow();if(!i)return;const n=Ee;this.sizeQ(i),n[2]=this.anchorX,n[3]=this.anchorY,n[4]=e,Ka(t,i,this.world,this.slice,s,this.blend)}},ve=new Float64Array(12),Me=new Float64Array(12),Ue={x:0,y:0,w:0,h:0};function fn(t,e,s,i,n,r){e=Math.max(e,0),s=Math.max(s,0),i=Math.max(i,0);const a=s+i>n?s*n/(s+i):s,l=s+i>n?i*n/(s+i):i;let h=a/r,o=l/r;if(h+o>e){const c=e/(h+o);h*=c,o*=c}t[0]=0,t[1]=h,t[2]=0,t[3]=a,t[4]=h,t[5]=e-h-o,t[6]=a,t[7]=n-a-l,t[8]=e-o,t[9]=o,t[10]=n-l,t[11]=l}var Ee=new Float64Array(5);function Ka(t,e,s,i,n,r){const a=Ee,l=a[0],h=a[1],o=a[2],c=a[3],u=a[4],f=t.tex(e.surface),y=i===0?e.slice??0:i;if(y===0){const w=(e.sw??e.w)/e.scale-e.margin*2,T=(e.sh??e.h)/e.scale-e.margin*2,_=w>0?l/w:1,L=T>0?h/T:1,I=-o*l+((e.tx??0)/e.scale-e.margin)*_,R=-c*h+((e.ty??0)/e.scale-e.margin)*L;os(s,I,R),V[0]=e.w/e.scale*_,V[1]=e.h/e.scale*L,V[2]=u,t.r.quadQ(f,e,lt,n,r);return}const p=e.tx??0,x=e.ty??0,m=(e.sw??e.w)-e.w-p,g=(e.sh??e.h)-e.h-x,k=-o*l-e.margin+p/e.scale,E=-c*h-e.margin+x/e.scale;if(fn(ve,l+e.margin*2-(p+m)/e.scale,(typeof y=="number"?y:y[3])-p,(typeof y=="number"?y:y[1])-m,e.w,e.scale),fn(Me,h+e.margin*2-(x+g)/e.scale,(typeof y=="number"?y:y[0])-x,(typeof y=="number"?y:y[2])-g,e.h,e.scale),os(s,k,E),V[2]=u,!t.r.nineQ?.(f,e,ve,Me,lt,n,r))for(let w=0;w<12;w+=4){const T=Me[w+1],_=Me[w+3];if(!(T<=0||_<=0))for(let L=0;L<12;L+=4){const I=ve[L+1],R=ve[L+3];I<=0||R<=0||(Ue.x=e.x+ve[L+2],Ue.y=e.y+Me[w+2],Ue.w=R,Ue.h=_,os(s,k+ve[L],E+Me[w]),V[0]=I,V[1]=T,V[2]=u,t.r.quadQ(f,Ue,lt,n,r))}}}function os(t,e,s){lt[0]=t[0],lt[1]=t[1],lt[2]=t[2],lt[3]=t[3],lt[4]=t[0]*e+t[2]*s+t[4],lt[5]=t[1]*e+t[3]*s+t[5]}var He=class extends we{constructor(t,e,s={}){super(t,null),d(this,"_spec"),d(this,"baked",null),d(this,"bakedEffects",!0),this._spec=e,this.bake(),s.anchor===void 0&&this.useFrameAnchor(),this.set(s)}get spec(){return this._spec}set spec(t){this._spec=t,this.baked=null,this._w=this._h=null,this.bake()}bake(){const t=this.kernel;return this.baked&&t.atlas.valid(this.baked.frame)&&this.baked.frame.scale===t.pixelScale&&this.bakedEffects===t.effects?this.baked:(this.bakedEffects=t.effects,this.baked=t.shape(this._spec),this._frame=this.baked.frame,this.slice=this.baked.slice,this.autoAnchor&&this.useFrameAnchor(),this.baked)}frameNow(){return this.bake().frame}sizeQ(){const t=this.bake();Ee[0]=this._w??t.w,Ee[1]=this._h??t.h}get width(){return this._w??this.bake().w}set width(t){this._w=t}get height(){return this._h??this.bake().h}set height(t){this._h=t}},un=(t,e,s)=>t===void 0?e:typeof t=="number"?t:t[0]+(t[1]-t[0])*s(),dn=class Ke extends he{constructor(e,s,i={}){super(e),d(this,"max"),d(this,"f"),d(this,"tints"),d(this,"count",0),d(this,"gravity"),d(this,"drag"),d(this,"frameRef"),d(this,"random",Math.random),this.frameRef=s,this.max=Math.max(1,Math.floor(i.max??200)),this.f=new Float32Array(this.max*Ke.W),this.tints=new Uint32Array(this.max),this.blend=i.blend??"normal",this.gravity=i.gravity??0,this.drag=i.drag??1}get alive(){return this.count}burst(e,s,i,n={}){const r=Ke.W,a=this.random,l=n.tint===void 0?16777215:Bt(n.tint)[0];for(let h=0;h<i;h++){let o=this.count;if(o>=this.max){let x=0,m=1/0;for(let g=0;g<this.max;g++){const k=this.f[g*r+5]-this.f[g*r+4];k<m&&(m=k,x=g)}o=x}else this.count++;const c=(n.angle??0)+(n.spread===void 0?a()*Math.PI*2:(a()-.5)*n.spread),u=un(n.speed,200,a),f=Array.isArray(n.scale)?n.scale[0]:n.scale??1,y=Array.isArray(n.scale)?n.scale[1]:n.scale??1,p=o*r;this.f[p]=e,this.f[p+1]=s,this.f[p+2]=Math.cos(c)*u,this.f[p+3]=Math.sin(c)*u,this.f[p+4]=0,this.f[p+5]=Math.max(un(n.life,.8,a),.01),this.f[p+6]=a()*Math.PI*2,this.f[p+7]=(a()-.5)*2*(n.spin??0),this.f[p+8]=f,this.f[p+9]=y,this.f[p+10]=n.alpha??1,this.tints[o]=l}}update(e){const s=Ke.W,i=this.f,n=this.drag>=1?1:Math.pow(Math.max(this.drag,0),e);for(let r=0;r<this.count;){const a=r*s;if(i[a+4]=i[a+4]+e,i[a+4]>=i[a+5]){const l=--this.count;r!==l&&(i.copyWithin(a,l*s,l*s+s),this.tints[r]=this.tints[l]);continue}i[a+3]=(i[a+3]+this.gravity*e)*n,i[a+2]=i[a+2]*n,i[a]=i[a]+i[a+2]*e,i[a+1]=i[a+1]+i[a+3]*e,i[a+6]=i[a+6]+i[a+7]*e,r++}}clear(){this.count=0}draw(e,s,i){if(!this.count)return;const n=typeof this.frameRef=="string"?this.frameRef=this.kernel.frame(this.frameRef):this.frameRef,r=Ke.W,a=this.f,l=this.world,h=n.w/n.scale,o=n.h/n.scale;for(let c=0;c<this.count;c++){const u=c*r,f=a[u+4]/a[u+5],y=a[u+8]+(a[u+9]-a[u+8])*f,p=s*a[u+10]*(1-f*f),x=a[u+6],m=Math.cos(x)*y,g=Math.sin(x)*y,k=a[u],E=a[u+1],w=l[0],T=l[1],_=l[2],L=l[3],I=w*m+_*g,R=T*m+L*g,O=_*m-w*g,q=L*m-T*g;lt[0]=I,lt[1]=R,lt[2]=O,lt[3]=q,lt[4]=w*k+_*E+l[4]-(I*h+O*o)/2,lt[5]=T*k+L*E+l[5]-(R*h+q*o)/2,V[0]=h,V[1]=o,V[2]=p,e.r.quadQ(e.tex(n.surface),n,lt,en(i,this.tints[c]),this.blend)}}};d(dn,"W",11);var pn=dn,fe=class extends we{constructor(t,e,s={}){const{fps:i,loop:n,playing:r,speed:a,onComplete:l,...h}=s;if(!e.frames.length)throw new Error("[engine] an animation needs at least one frame");super(t,e.frames[0],h),d(this,"frames"),d(this,"durations"),d(this,"fps"),d(this,"loop"),d(this,"speed"),d(this,"onComplete"),d(this,"_playing"),d(this,"index",0),d(this,"t",0),this.frames=e.frames,this.durations=e.durations&&i===void 0?e.durations:null,this.fps=i??12,this.loop=n!==!1,this.speed=a??1,this.onComplete=l??null,this._playing=r!==!1,this.speed<0&&this.show(e.frames.length-1)}get frameIndex(){return this.index}get frameCount(){return this.frames.length}get playing(){return this._playing}play(){return!this.loop&&!this._playing&&this.index===(this.speed<0?0:this.frames.length-1)&&this.show(this.speed<0?this.frames.length-1:0),this._playing=!0,this}stop(){return this._playing=!1,this}gotoFrame(t){const e=this.frames.length;return this.show((Math.floor(t)%e+e)%e),this.t=0,this}gotoAndPlay(t){return this._playing=!0,this.gotoFrame(t)}gotoAndStop(t){return this._playing=!1,this.gotoFrame(t)}show(t){t===this.index&&this._frame||(this.index=t,this.frame=this.frames[t])}secondsOf(t){const e=this.durations?.[t];return e!==void 0&&e>0?e:1/Math.max(this.fps,.001)}update(t){if(!this._playing||this.destroyed||this.speed===0)return;const e=this.frames.length,s=this.speed<0;this.t+=t*Math.abs(this.speed);let i=this.index;for(let n=0;n<1e3;n++){const r=this.secondsOf(i);if(this.t<r)break;this.t-=r;const a=s?i-1:i+1;if(a<0||a>=e){if(!this.loop){this.t=0,this._playing=!1,this.show(i),this.onComplete?.();return}i=s?e-1:0}else i=a}this.show(i)}},Za=(t,e)=>t.localeCompare(e,void 0,{numeric:!0}),yn=class{constructor(t,e,s=2){d(this,"width",t),d(this,"height",e),d(this,"padding",s),d(this,"shelves",[]),d(this,"free",[]),d(this,"bottom",0)}alloc(t,e){const s=Math.ceil(t)+this.padding*2,i=Math.ceil(e)+this.padding*2;if(s>this.width||i>this.height)return null;for(let a=0;a<this.free.length;a++){const l=this.free[a];if(l.w>=s&&l.h>=i&&l.w*l.h<=s*i*2)return this.free.splice(a,1),{...this.inner(l.x,l.y,t,e),slot:l}}let n=null;for(const a of this.shelves)a.h>=i&&a.h<=i*1.5+8&&this.width-a.x>=s&&(!n||a.h<n.h)&&(n=a);if(!n)if(this.bottom+i>this.height){for(const a of this.shelves)a.h>=i&&this.width-a.x>=s&&(n=a);if(!n)return null}else n={y:this.bottom,h:i,x:0},this.shelves.push(n),this.bottom+=i;const r=n.x;return n.x+=s,this.inner(r,n.y,t,e)}release(t){this.free.push({x:t.x-this.padding,y:t.y-this.padding,w:Math.ceil(t.w)+this.padding*2,h:Math.ceil(t.h)+this.padding*2})}get fill(){return this.bottom/this.height}reset(){this.shelves=[],this.free=[],this.bottom=0}inner(t,e,s,i){return{x:t+this.padding,y:e+this.padding,w:s,h:i}}},ls=t=>({source:t,texture:null,pending:[]}),Ks=class{constructor(t=2048,e=4){d(this,"pageSize",t),d(this,"maxPages",e),d(this,"pages",[]),d(this,"gen",1),d(this,"onPage",()=>{}),d(this,"onDrop",()=>{})}valid(t){return!!t&&(t.gen===this.gen||t.gen===0)}bake(t,e,s,i=1,n=0,r=0,a=0){const l=Math.max(1,Math.ceil(t)),h=Math.max(1,Math.ceil(e)),o=document.createElement("canvas");o.width=l,o.height=h;const c=o.getContext("2d");return s(c),this.put(o,l,h,i,n,r,a)}add(t,e=1,s=0,i=0){const n=document.createElement("canvas");return n.width=Math.max(1,t.width),n.height=Math.max(1,t.height),n.getContext("2d").drawImage(t,0,0),this.put(n,n.width,n.height,e,s,i,0)}release(t){if(t.gen!==this.gen)return;this.pages.find(s=>s.surface===t.surface)?.packer.release(t)}rebake(t,e,s,i,n=t.w,r=t.h){if(!this.valid(t)||e>n||s>r)return null;const a=Math.max(1,Math.ceil(e)),l=Math.max(1,Math.ceil(s)),h=this.pages.find(c=>c.surface===t.surface);if(!h)return null;const o=document.createElement("canvas");return o.width=Math.ceil(n),o.height=Math.ceil(r),i(o.getContext("2d")),h.ctx.clearRect(t.x,t.y,o.width,o.height),h.ctx.drawImage(o,t.x,t.y),t.surface.pending.push([o,t.x,t.y]),t.w=a,t.h=l,t}put(t,e,s,i,n,r,a){let l=null,h=this.pages.find(c=>(l=c.packer.alloc(e,s))!==null);if(h||(!(Math.max(e,s)+4>this.pageSize)&&this.pages.length>=this.maxPages&&(this.wipe(),h=this.pages[0],l=h?h.packer.alloc(e,s):null),(!h||!l)&&(h=this.newPage(Math.max(e,s)),l=h.packer.alloc(e,s))),!l)throw new Error(`[engine] ${e}\xD7${s} does not fit an atlas page`);const o=l;if(o.slot){const c=o.slot;h.ctx.clearRect(c.x,c.y,c.w,c.h);const u=document.createElement("canvas");u.width=c.w,u.height=c.h,u.getContext("2d").drawImage(t,o.x-c.x,o.y-c.y),h.surface.pending.push([u,c.x,c.y])}else h.surface.pending.push([t,o.x,o.y]);return h.ctx.drawImage(t,o.x,o.y),{surface:h.surface,x:o.x,y:o.y,w:e,h:s,scale:i,gen:this.gen,ox:n,oy:r,margin:a}}newPage(t){let e=this.pageSize;for(;e<t+4;)e*=2;const s=document.createElement("canvas");s.width=s.height=e;const i=s.getContext("2d"),n=ls(s),r={surface:n,packer:new yn(e,e),ctx:i};return this.pages.push(r),this.onPage(n),r}wipe(){this.gen++;let t=0;for(let e=0;e<this.pages.length;e++){const s=this.pages[e];if(t<this.maxPages&&s.surface.source.width===this.pageSize){this.pages[t++]=s;continue}s.surface.pending=[],this.onDrop(s.surface)}this.pages.length=t;for(const e of this.pages)e.packer.reset(),e.ctx.clearRect(0,0,e.surface.source.width,e.surface.source.height),e.surface.pending=[],e.surface.pending.push([e.surface.source,0,0])}},Ja=()=>{const t=typeof document<"u"?document.timeline?.currentTime:null;return typeof t=="number"&&Number.isFinite(t)?t:globalThis.performance?.now()??Date.now()},mn=()=>globalThis.performance?.now()??Date.now(),to=class{constructor(t=Ja){d(this,"now",t),d(this,"known",new Map),d(this,"smoothed",new Map),d(this,"times",new WeakMap),d(this,"lerp",new Qi),d(this,"amount",Zs),d(this,"drawnAt",NaN),d(this,"drawn",0),d(this,"smoothedBody",(e,s={})=>{const i=s.interpolate!==!1;if(typeof e=="number"){const n=this.smoothed.get(e);return n?i?this.lerp.at(e,this.tick())??n.body:n.body:null}return typeof e!="object"||e===null||!Array.isArray(e.body)?null:this.posed(e.id,e.body,eo(s.smooth,this.defaultAmount),i)})}setLocal(t){this.amount=t?Pa:Zs,this.lerp=new Qi(t?Sa:{}),this.smoothed.clear()}get defaultAmount(){return this.amount}note(t,e,s=mn()){for(const i of t)this.known.set(i.id,this.resolve(i.id,i.avatar)),e!==void 0&&Number.isFinite(e)&&Array.isArray(i.body)&&this.times.set(i.body,{t:e,arrival:s})}of(t){return typeof t=="object"&&t!==null?t.avatar!==void 0?this.resolve(t.id,t.avatar):this.of(t.id):this.known.get(t)??Ri(t-1)}posed(t,e,s,i=!0){const n=this.smooth(t,e,s);return i?this.lerp.at(t,this.tick())??n:n}smooth(t,e,s){const i=this.smoothed.get(t);if(i&&i.raw===e&&i.amount===s)return i.body;i&&i.amount!==s&&this.lerp.forget(t);const n=s<1?La(i?.body,e,s):e;this.smoothed.set(t,{raw:e,body:n,amount:s});const r=this.times.get(e),a=r?.arrival??mn();return this.lerp.push(t,r?.t??a,n,a),n}takeDrawn(){const t=this.drawn;return this.drawn=0,t}tick(){const t=this.now();return t!==this.drawnAt&&(this.drawnAt=t,this.drawn++),t}resolve(t,e){return Ca(e)?e:Ri(t-1)}},Zs=.5,eo=(t,e=Zs)=>t===!1?1:typeof t=="number"?Math.min(Math.max(t,.05),1):e,xn=new Float64Array(1),gn=new Int32Array(xn.buffer),Ae=(t,e)=>(t=Math.imul(t^e,1540483477),t^t>>>15);function Jt(t,e=2538058380){return t!==t?Ae(e,2146959360):(xn[0]=t===0?0:t,Ae(Ae(e,gn[0]),gn[1]))}function bn(t,e=2166136261){for(let s=0;s<t.length;s++)e=Math.imul(e^t.charCodeAt(s),16777619);return e}function te(t){switch(typeof t){case"number":return Jt(t);case"string":return bn(t);case"boolean":return t?1013904242:461845907;case"object":{if(t===null)return 625341585;if(Array.isArray(t)||t instanceof Float64Array){let i=1779033703^t.length;for(let n=0;n<t.length;n++){const r=t[n];i=Ae(i,typeof r=="number"?Jt(r):te(r))}return i}let e=1359893119;const s=t;for(const i in s){const n=s[i];n!==void 0&&(e=e+Ae(bn(i),te(n))|0)}return Ae(e,2600822924)}default:return 0}}function Ge(t,e){if(t===e)return!0;if(typeof t!="object"||typeof e!="object"||t===null||e===null)return typeof t=="number"&&typeof e=="number"&&t!==t&&e!==e;const s=Array.isArray(t)||t instanceof Float64Array;if(s!==(Array.isArray(e)||e instanceof Float64Array))return!1;if(s){const r=t,a=e;if(r.length!==a.length)return!1;for(let l=0;l<r.length;l++)if(r[l]!==a[l]&&!Ge(r[l],a[l]))return!1;return!0}const i=t,n=e;for(const r in i)if(i[r]!==void 0&&!Ge(i[r],n[r]))return!1;for(const r in n)if(n[r]!==void 0&&i[r]===void 0)return!1;return!0}function hs(t){if(typeof t!="object"||t===null)return t;if(Array.isArray(t))return t.map(hs);if(t instanceof Float64Array)return t.slice();const e={};for(const s in t)t[s]!==void 0&&(e[s]=hs(t[s]));return e}var kn=class{constructor(t=1/0){d(this,"max",t),d(this,"buckets",new Map),d(this,"n",0)}get size(){return this.n}get(t,e=te(t)){const s=this.buckets.get(e);if(s){for(let i=0;i<s.length;i++)if(Ge(s[i].key,t))return s[i].value}}set(t,e,s=te(t)){let i=this.buckets.get(s);if(i){for(const n of i)if(Ge(n.key,t)){n.value=e;return}}this.n>=this.max&&this.clear(),(!i||!this.buckets.has(s))&&this.buckets.set(s,i=[]),i.push({key:hs(t),value:e}),this.n++}clear(){this.buckets.clear(),this.n=0}},Js=0,wn=1,cs=2,ti=3,vn=class{constructor(){d(this,"scale",1),d(this,"cOn",!1),d(this,"px0",0),d(this,"py0",0),d(this,"px1",0),d(this,"py1",0),d(this,"clipVer",0),d(this,"stack",[]),d(this,"sp",0),d(this,"real",0),d(this,"mute",0),d(this,"bnd",new Float64Array(4*(Ws+1))),d(this,"rx0",0),d(this,"ry0",0),d(this,"rx1",0),d(this,"ry1",0),d(this,"maxBlur",1/0),d(this,"time",0),d(this,"skipped",0),d(this,"gq",new Float64Array(4))}resetLayers(t){this.scale=t,this.sp=this.real=this.mute=0,this.skipped=0,this.cOn=!1,this.clipVer++}growQ(){const t=this.gq;this.grow(t[0],t[1],t[2],t[3])}grow(t,e,s,i){if(!this.real)return;const n=this.bnd,r=(this.real-1)*4;t<n[r]&&(n[r]=t),e<n[r+1]&&(n[r+1]=e),s>n[r+2]&&(n[r+2]=s),i>n[r+3]&&(n[r+3]=i)}area(t,e){const s=this.bnd,i=t*4,n=this.scale;return this.rx0=Math.max(Math.floor((s[i]-e)*n)-1,0),this.ry0=Math.max(Math.floor((s[i+1]-e)*n)-1,0),this.rx1=Math.min(Math.ceil((s[i+2]+e)*n)+1,this.canvas.width),this.ry1=Math.min(Math.ceil((s[i+3]+e)*n)+1,this.canvas.height),this.rx1>this.rx0&&this.ry1>this.ry0}clip(t,e,s,i){const n=this.scale,r=this.canvas.width,a=this.canvas.height,l=Math.min(Math.max(Math.round(t*n),0),r),h=Math.min(Math.max(Math.round(e*n),0),a),o=Math.min(Math.max(Math.round((t+s)*n),l),r),c=Math.min(Math.max(Math.round((e+i)*n),h),a);this.cOn&&l===this.px0&&h===this.py0&&o===this.px1&&c===this.py1||(this.cOn=!0,this.px0=l,this.py0=h,this.px1=o,this.py1=c,this.clipVer++)}unclip(){this.cOn&&(this.cOn=!1,this.clipVer++)}push(t){if(t<cs&&(this.mute||this.real>=Ws||!this.pushLayer())&&(t+=2),t===ti)this.mute++;else if(t!==cs){const e=this.real*4;this.bnd[e]=this.bnd[e+1]=1/0,this.bnd[e+2]=this.bnd[e+3]=-1/0,this.real++}return this.stack[this.sp++]=t,t<cs}beginLayer(){return this.push(Js)}beginMask(){this.push(this.sp&&this.stack[this.sp-1]===Js?wn:ti)}endLayer(t,e){if(!this.sp)return;let s=this.stack[--this.sp];if(s===ti){if(this.mute--,!this.sp)return;s=this.stack[--this.sp]}if(s===wn){const i=--this.real,n=this.popLayer();this.area(i-1,0)&&this.composite(n,!0,1,null);const r=this.bnd,a=(i-1)*4,l=i*4;r[a]=Math.max(r[a],r[l]),r[a+1]=Math.max(r[a+1],r[l+1]),r[a+2]=Math.min(r[a+2],r[l+2]),r[a+3]=Math.min(r[a+3],r[l+3]),s=this.stack[--this.sp]}if(s===cs)qs(e)&&(this.skipped+=e.length);else if(s===Js){const i=--this.real,n=qs(e)?e:null,r=this.popLayer();if(this.area(i,n?ja(n,this.maxBlur):0)){this.composite(r,!1,t,n);const a=this.scale;this.grow(this.rx0/a,this.ry0/a,this.rx1/a,this.ry1/a)}}}closeLayers(){for(;this.sp;)this.endLayer(1)}},so=256,Mn=8<<20,gt=new Float64Array(32),bt={x:0,y:0,w:0,h:0};function io(t){if(typeof t.filter!="string")return!1;t.filter="blur(1px)";const e=t.filter==="blur(1px)";return t.filter="none",e}function ei(t){const e=t.getContext("2d",{alpha:!0});return e?new no(t,e):null}var no=class extends vn{constructor(t,e){super(),d(this,"canvas",t),d(this,"ctx",e),d(this,"kind","canvas2d"),d(this,"maxTextureSize",4096),d(this,"features",{}),d(this,"info",{renderer:"canvas2d"}),d(this,"support"),d(this,"lost",!1),d(this,"fxr",null),d(this,"quads",0),d(this,"stats",{drawCalls:0,quads:0,filtersSkipped:0}),d(this,"tinted",new Map),d(this,"tintedN",0),d(this,"lostListeners",[]),d(this,"restoredListeners",[]),d(this,"base"),d(this,"top"),d(this,"layers",[]),d(this,"scratch",[]),d(this,"nines",new Map),d(this,"ninePx",0),d(this,"frame",0),d(this,"hit",!1),d(this,"missed",new Map),this.support={filters:io(e),shaders:!1},this.base=this.top={ctx:e,clipped:!1,ver:0},t.addEventListener("contextlost",()=>{this.lost=!0,this.lostListeners.forEach(s=>s())}),t.addEventListener("contextrestored",()=>{this.lost=!1,this.tinted.clear(),this.tintedN=0,this.dropNines(),this.restoredListeners.forEach(s=>s())})}resize(t,e){this.canvas.width!==t&&(this.canvas.width=t),this.canvas.height!==e&&(this.canvas.height=e)}createTexture(t){return{id:Ys(),width:t.width,height:t.height,source:t}}updateTexture(t,e,s=0,i=0){const n=e?s+e.width:1/0,r=e?i+e.height:1/0;for(const a of this.nines.values()){const l=a.key;l[0]===t.id&&l[1]<n&&l[1]+l[3]>s&&l[2]<r&&l[2]+l[4]>i&&this.dropNine(a)}for(const[a,l]of this.tinted){const h=l.filter(o=>o.id!==t.id);this.tintedN-=l.length-h.length,h.length?this.tinted.set(a,h):this.tinted.delete(a)}}destroyTexture(t){this.updateTexture(t)}begin(t,e,s){this.resetLayers(s),this.fxr?.tick(),this.frame++,this.quads=0,this.top=this.base,this.ctx=this.base.ctx;const i=this.ctx;this.base.clipped&&i.restore(),this.base.clipped=!1,this.base.ver=this.clipVer,i.setTransform(1,0,0,1,0,0),i.globalAlpha=1,i.globalCompositeOperation="source-over",i.clearRect(0,0,this.canvas.width,this.canvas.height),e>0&&(i.fillStyle=Oe(t,e),i.fillRect(0,0,this.canvas.width,this.canvas.height))}quad(t,e,s,i,n,r,a,l){V[0]=i,V[1]=n,V[2]=a,this.quadQ(t,e,s,r,l)}quadQ(t,e,s,i,n){e.w<=0||e.h<=0||(i===16777215?this.blit(t.source,e.x,e.y,e.w,e.h,s,n):this.blit(this.tint(t,e,i),0,0,e.w,e.h,s,n))}blit(t,e,s,i,n,r,a){const l=V[0],h=V[1],o=V[2];if(o<=0||this.mute)return;this.sync();const c=this.ctx,u=this.scale;if(this.real){const f=r[0]*l,y=r[1]*l,p=r[2]*h,x=r[3]*h;this.grow(r[4]+Math.min(0,f,p,f+p),r[5]+Math.min(0,y,x,y+x),r[4]+Math.max(0,f,p,f+p),r[5]+Math.max(0,y,x,y+x))}c.setTransform(r[0]*u,r[1]*u,r[2]*u,r[3]*u,r[4]*u,r[5]*u),c.globalAlpha=Math.min(o,1),a==="add"&&(c.globalCompositeOperation="lighter"),c.drawImage(t,e,s,i,n,0,0,l,h),a==="add"&&(c.globalCompositeOperation="source-over"),this.quads++}nineQ(t,e,s,i,n,r,a){var l,h;const o=s[8]+s[9],c=i[8]+i[9],u=Math.ceil(o*Math.hypot(n[0],n[1])*this.scale-1e-6),f=Math.ceil(c*Math.hypot(n[2],n[3])*this.scale-1e-6);if(n[1]===0&&n[2]===0||u>4096||f>4096)return!1;if(!(u>0&&f>0&&V[2]>0)||this.mute)return!0;let y=this.kept(t,e,s,i,u,f,r);const p=(y??(y=(l=this.scratch)[h=13*Math.ceil(Math.log2(u))+Math.ceil(Math.log2(f))]??(l[h]=document.createElement("canvas").getContext("2d")))).canvas;if(p.width<u&&(p.width=u),p.height<f&&(p.height=f),!this.hit){y.clearRect(0,0,u+2,f+2);for(let x=0;x<12;x+=4){const m=Math.round(i[x]*f/c),g=Math.round((i[x]+i[x+1])*f/c);for(let k=0;k<12;k+=4){const E=Math.round(s[k]*u/o),w=Math.round((s[k]+s[k+1])*u/o);bt.x=e.x+s[k+2],bt.y=e.y+i[x+2],bt.w=s[k+3],bt.h=i[x+3],!(w<=E||g<=m||bt.w<=0||bt.h<=0)&&(r===16777215?y.drawImage(t.source,bt.x,bt.y,bt.w,bt.h,E,m,w-E,g-m):y.drawImage(this.tint(t,bt,r),0,0,bt.w,bt.h,E,m,w-E,g-m))}}}return V[0]=o,V[1]=c,this.blit(p,0,0,u,f,n,a),!0}kept(t,e,s,i,n,r,a){gt[0]=t.id,gt[1]=e.x,gt[2]=e.y,gt[3]=e.w,gt[4]=e.h,gt[5]=n,gt[6]=r,gt[7]=a,gt.set(s,8),gt.set(i,20);const l=te(gt),h=this.nines.get(l);if(this.hit=!1,h)return Ge(h.key,gt)?(h.used=this.frame,this.hit=!0,h.ctx):null;const o=this.missed,c=o.get(l);o.size>4096&&o.clear(),o.set(l,this.frame);const u=n*r;if(c!==this.frame-1||u>Mn)return null;let f;for(;this.ninePx+u>Mn;){let x;for(const k of this.nines.values())k.used<this.frame-1&&!(x&&x.used<=k.used)&&(x=k);if(!x)return null;const m=x.ctx.canvas,g=!f&&m.width>=n&&m.height>=r&&m.width*m.height<=2*u;this.dropNine(x,g),g&&(f=x.ctx)}const y=f??document.createElement("canvas").getContext("2d"),p=y.canvas;return f||(p.width=n,p.height=r),this.ninePx+=p.width*p.height,this.nines.set(l,{key:hs(gt),ctx:y,used:this.frame}),y}dropNine(t,e=!1){this.nines.delete(te(t.key));const s=t.ctx.canvas;this.ninePx-=s.width*s.height,e||(s.width=0)}dropNines(){for(const t of this.nines.values())this.dropNine(t)}tint(t,e,s){const i=Jt(s,Jt(e.h,Jt(e.w,Jt(e.y,Jt(e.x,Jt(t.id))))));let n=this.tinted.get(i);if(n)for(let l=0;l<n.length;l++){const h=n[l];if(h.id===t.id&&h.x===e.x&&h.y===e.y&&h.w===e.w&&h.h===e.h&&h.color===s)return h.canvas}this.tintedN>=so&&(this.tinted.clear(),this.tintedN=0,n=void 0);const r=document.createElement("canvas");r.width=Math.ceil(e.w),r.height=Math.ceil(e.h);const a=r.getContext("2d");return a.drawImage(t.source,e.x,e.y,e.w,e.h,0,0,e.w,e.h),a.globalCompositeOperation="multiply",a.fillStyle=Oe(s),a.fillRect(0,0,e.w,e.h),a.globalCompositeOperation="destination-in",a.drawImage(t.source,e.x,e.y,e.w,e.h,0,0,e.w,e.h),n||this.tinted.set(i,n=[]),n.push({id:t.id,x:e.x,y:e.y,w:e.w,h:e.h,color:s,canvas:r}),this.tintedN++,r}paint(t,e){this.sync();const s=this.ctx,i=this.scale;return s.setTransform(i,0,0,i,0,0),s.globalAlpha=Math.min(e,1),Oe(t)}ellipse(t,e,s,i,n,r,a){if(a<=0||s<=0||i<=0||this.mute)return;const l=Math.max(s,i);this.grow(t-l,e-l,t+l,e+l);const h=this.ctx;h.fillStyle=this.paint(r,a),h.beginPath(),h.ellipse(t,e,s,i,n,0,Math.PI*2),h.fill(),this.quads++}trace(t,e,s=0){if(this.real)for(let n=0;n<e;n++)this.grow(t[n*2]-s,t[n*2+1]-s,t[n*2]+s,t[n*2+1]+s);const i=this.ctx;i.beginPath(),i.moveTo(t[0],t[1]);for(let n=1;n<e;n++)i.lineTo(t[n*2],t[n*2+1])}polygon(t,e,s,i){if(i<=0||e<3||this.mute)return;const n=this.ctx;n.fillStyle=this.paint(s,i),this.trace(t,e),n.closePath(),n.fill(),this.quads++}stroke(t,e,s,i,n,r){if(n<=0||s<=0||e<1||this.mute)return;const a=this.ctx;a.strokeStyle=this.paint(i,n),a.lineWidth=s,a.lineCap="round",a.lineJoin="round",this.trace(t,e,s/2),e===1&&a.lineTo(t[0],t[1]),r&&a.closePath(),a.stroke(),this.quads++}sync(){const t=this.top;if(t.ver===this.clipVer)return;const e=t.ctx;t.clipped&&e.restore(),t.clipped=this.cOn,t.ver=this.clipVer,this.cOn&&(e.save(),e.setTransform(1,0,0,1,0,0),e.beginPath(),e.rect(this.px0,this.py0,this.px1-this.px0,this.py1-this.py0),e.clip())}pushLayer(){const t=this.canvas.width,e=this.canvas.height;let s=this.layers[this.real];if(!s||s.ctx.canvas.width!==t||s.ctx.canvas.height!==e){const n=document.createElement("canvas");n.width=t,n.height=e;const r=n.getContext("2d");if(!r)return!1;s=this.layers[this.real]={ctx:r,clipped:!1,ver:-1}}const i=s.ctx;return s.clipped&&i.restore(),s.clipped=!1,s.ver=-1,i.setTransform(1,0,0,1,0,0),i.globalAlpha=1,i.globalCompositeOperation="source-over",i.clearRect(0,0,t,e),this.top=s,this.ctx=i,!0}popLayer(){return this.top=this.real>0?this.layers[this.real-1]:this.base,this.ctx=this.top.ctx,this.layers[this.real].ctx.canvas}composite(t,e,s,i){let n=t,r="none";const a=i&&Ut.c2d?this.fxr??(this.fxr=Ut.c2d(this)):null;a&&(n=a.chain(t,i),r=a.css),this.sync();const l=this.ctx,h=this.rx0,o=this.ry0,c=this.rx1-h,u=this.ry1-o;l.setTransform(1,0,0,1,0,0),l.globalAlpha=Math.min(s,1),l.globalCompositeOperation=e?"destination-in":"source-over",r!=="none"&&(l.filter=r),l.drawImage(n,h,o,c,u,h,o,c,u),r!=="none"&&(l.filter="none"),l.globalCompositeOperation="source-over",this.quads++}end(){this.closeLayers();const t=this.stats;return t.drawCalls=t.quads=this.quads,t.filtersSkipped=this.skipped,t}onLost(t){this.lostListeners.push(t)}onRestored(t){this.restoredListeners.push(t)}destroy(){this.tinted.clear(),this.dropNines(),this.layers=[],this.scratch=[],this.fxr?.destroy(),this.fxr=null}},Xe=14,_e=6,En=8192,ro=class{constructor(t,e,s=En){d(this,"instanced",t),d(this,"slots",e),d(this,"capacity",s),d(this,"f32"),d(this,"u32"),d(this,"quads",0),d(this,"textures"),d(this,"bound",0),this.textures=new Array(e).fill(null);const i=s*(t?Xe:_e*4),n=new ArrayBuffer(i*4);this.f32=new Float32Array(n),this.u32=new Uint32Array(n)}slot(t){const e=this.textures;for(let s=0;s<this.bound;s++)if(e[s]===t)return s;return this.bound>=this.slots?-1:(e[this.bound]=t,this.bound++)}has(t){for(let e=0;e<this.bound;e++)if(this.textures[e]===t)return!0;return!1}get full(){return this.quads>=this.capacity}get words(){return this.quads*(this.instanced?Xe:_e*4)}reset(){this.quads=0;for(let t=0;t<this.bound;t++)this.textures[t]=null;this.bound=0}push(t,e,s,i,n,r,a,l,h,o,c,u,f,y){const p=this.f32;if(this.instanced){let x=this.quads*Xe;p[x++]=t,p[x++]=e,p[x++]=s,p[x++]=i,p[x++]=n,p[x++]=r,p[x++]=a,p[x++]=l,p[x++]=h,p[x++]=o,p[x++]=c,p[x++]=u,this.u32[x++]=f,p[x]=y}else{const x=this.quads*_e*4;this.vertex(x,t,e,h,o,f,y),this.vertex(x+6,s,i,c,o,f,y),this.vertex(x+12,n,r,c,u,f,y),this.vertex(x+18,a,l,h,u,f,y)}this.quads++}pushQ(t,e){const s=this.f32;if(this.instanced){const i=this.quads*Xe;for(let n=0;n<12;n++)s[i+n]=t[n];this.u32[i+12]=t[12],s[i+13]=e}else{let i=this.quads*_e*4;const n=t[12];for(let r=0;r<4;r++,i+=_e)s[i]=t[r*2],s[i+1]=t[r*2+1],s[i+2]=r===1||r===2?t[10]:t[8],s[i+3]=r>=2?t[11]:t[9],this.u32[i+4]=n,s[i+5]=e}this.quads++}vertex(t,e,s,i,n,r,a){const l=this.f32;l[t]=e,l[t+1]=s,l[t+2]=i,l[t+3]=n,this.u32[t+4]=r,l[t+5]=a}};function ao(t){const e=new Uint16Array(t*6);for(let s=0,i=0,n=0;s<t;s++,i+=6,n+=4)e[i]=n,e[i+1]=n+1,e[i+2]=n+2,e[i+3]=n,e[i+4]=n+2,e[i+5]=n+3;return e}var kt={M:0,L:1,Q:2,C:3,Z:4},An=[2,2,4,6,0],oo={M:0,L:1,Q:2,C:3,Z:4};function si(t,e){if(t.length>=e)return t;const s=new Float64Array(Math.max(e,t.length*2,16));return s.set(t),s}var fs=new Map;function lo(t){if(typeof t!="string")return t;let e=fs.get(t);if(e)return e;e=[];const s=t.match(/[MLQCZ]|-?\d*\.?\d+(?:e-?\d+)?/gi)??[];let i=-1;for(let n=0;n<s.length;){const r=s[n],a=oo[r.toUpperCase()];if(a!==void 0){i=a,n++,a===kt.Z&&e.push(kt.Z);continue}if(i<0||i===kt.Z){n++;continue}const l=An[i];e.push(i);for(let h=0;h<l;h++)e.push(Number(s[n+h]??0));n+=l,i===kt.M&&(i=kt.L)}return fs.size>256&&fs.clear(),fs.set(t,e),e}var ee={subs:[],count:0},ii=null,se=null;function us(t,e){let s=se;s||(s=ee.subs[ee.count]??null,s||ee.subs.push(s={pts:new Float64Array(64),n:0,closed:!1}),s.n=0,s.closed=!1,ee.count++,se=s);const i=s.n*2;i+2>s.pts.length&&(s.pts=si(s.pts,i+2));const n=ii;n?(s.pts[i]=n[0]*t+n[2]*e+n[4],s.pts[i+1]=n[1]*t+n[3]*e+n[5]):(s.pts[i]=t,s.pts[i+1]=e),s.n++}function ni(t,e=null,s=1,i=6){const n=lo(t);ee.count=0,se=null,ii=e;let r=0,a=0,l=0,h=0;const o=s/i;for(let c=0;c<n.length;){const u=n[c++],f=n;if(u===kt.M)se=null,r=l=f[c],a=h=f[c+1],us(r,a);else if(u===kt.L)r=f[c],a=f[c+1],us(r,a);else if(u===kt.Q){const y=f[c],p=f[c+1],x=f[c+2],m=f[c+3],g=_n(($t(y-r,p-a)+$t(x-y,m-p))*o);for(let k=1;k<=g;k++){const E=k/g,w=1-E;us(w*w*r+2*w*E*y+E*E*x,w*w*a+2*w*E*p+E*E*m)}r=x,a=m}else if(u===kt.C){const y=f[c],p=f[c+1],x=f[c+2],m=f[c+3],g=f[c+4],k=f[c+5],E=_n(($t(y-r,p-a)+$t(x-y,m-p)+$t(g-x,k-m))*o);for(let w=1;w<=E;w++){const T=w/E,_=1-T,L=_*_*_,I=3*_*_*T,R=3*_*T*T,O=T*T*T;us(L*r+I*y+R*x+O*g,L*a+I*p+R*m+O*k)}r=g,a=k}else if(u===kt.Z){se&&(se.closed=!0),se=null,r=l,a=h;continue}else break;c+=An[u]}se=null,ii=null;for(let c=0;c<ee.count;c++){const u=ee.subs[c],f=u.n*2;u.closed&&u.n>=2&&Math.abs(u.pts[0]-u.pts[f-2])<1e-6&&Math.abs(u.pts[1]-u.pts[f-1])<1e-6&&u.n--}return ee}var $t=(t,e)=>Math.sqrt(t*t+e*e),_n=t=>Math.min(Math.max(Math.ceil(t),2),24);function ho(t,e){let s=0;for(let i=0,n=e-1;i<e;n=i++)s+=(t[n*2]-t[i*2])*(t[n*2+1]+t[i*2+1]);return s}var ds=new Int32Array(64),ps=(t,e,s,i,n)=>((t[i*2]-t[s*2])*(t[n*2+1]-t[s*2+1])-(t[i*2+1]-t[s*2+1])*(t[n*2]-t[s*2]))*e;function co(t,e,s){if(e<3)return 0;ds.length<e&&(ds=new Int32Array(Math.max(e,ds.length*2)));const i=ds;let n=e,r=0;for(let o=0;o<e;o++)i[o]=o;const a=ho(t,e)>0?1:-1;let l=e*e+8,h=0;for(;n>3&&l-- >0;){const o=i[(h+n-1)%n],c=i[h%n],u=i[(h+1)%n];let f=ps(t,a,o,c,u)>0;if(f)for(let y=0;y<n;y++){const p=i[y];if(!(p===o||p===c||p===u)&&ps(t,a,o,c,p)>=0&&ps(t,a,c,u,p)>=0&&ps(t,a,u,o,p)>=0){f=!1;break}}f?(s[r++]=o,s[r++]=c,s[r++]=u,i.copyWithin(h%n,h%n+1,n),n--,h=Math.max(h-1,0)):h=(h+1)%n}if(n===3)s[r++]=i[0],s[r++]=i[1],s[r++]=i[2];else if(n>3)for(let o=1;o+1<n;o++)s[r++]=i[0],s[r++]=i[o],s[r++]=i[o+1];return r}var fo=.85,ys=new Float64Array(64),Sn=new Float64Array(64),Tn=new Float64Array(64),Cn=new Float64Array(64),Rn=new Float64Array(64),Fn=new Float64Array(64),Ln=new Uint8Array(64),ms=new Float64Array(8);function uo(t,e,s,i,n,r){const a=ms;if(ys.length<e){const m=Math.max(e,ys.length*2);ys=new Float64Array(m),Sn=new Float64Array(m),Tn=new Float64Array(m),Cn=new Float64Array(m),Rn=new Float64Array(m),Fn=new Float64Array(m),Ln=new Uint8Array(m)}const l=ys,h=Sn;let o=0;for(let m=0;m<e;m++){const g=t[m*2],k=t[m*2+1];!Number.isFinite(g)||!Number.isFinite(k)||o&&Math.abs(l[o-1]-g)<.001&&Math.abs(h[o-1]-k)<.001||(l[o]=g,h[o]=k,o++)}if(i&&o>2&&Math.abs(l[0]-l[o-1])<.001&&Math.abs(h[0]-h[o-1])<.001&&o--,o===0)return;if(o===1)return a[0]=l[0],a[1]=h[0],r();const c=i?o:o-1,u=Tn,f=Cn;for(let m=0;m<c;m++){const g=(m+1)%o,k=l[g]-l[m],E=h[g]-h[m],w=$t(k,E)||1;u[m]=-E/w,f[m]=k/w}const y=Rn,p=Fn,x=Ln;for(let m=0;m<o;m++){const g=i?(m-1+c)%c:m-1,k=m<c?m:-1;if(x[m]=1,g<0||k<0||u[g]*u[k]+f[g]*f[k]<fo)continue;let w=u[g]+u[k],T=f[g]+f[k];const _=$t(w,T)||1;w/=_,T/=_;const L=s/Math.max(w*u[k]+T*f[k],.5);y[m]=w*L,p[m]=T*L,x[m]=0}for(let m=0;m<c;m++){const g=(m+1)%o,k=x[m]?u[m]*s:y[m],E=x[m]?f[m]*s:p[m],w=x[g]?u[m]*s:y[g],T=x[g]?f[m]*s:p[g];a[0]=l[m]+k,a[1]=h[m]+E,a[2]=l[g]+w,a[3]=h[g]+T,a[4]=l[g]-w,a[5]=h[g]-T,a[6]=l[m]-k,a[7]=h[m]-E,n()}for(let m=0;m<o;m++)x[m]&&(a[0]=l[m],a[1]=h[m],r())}function Pn(t,e){let s=0,i=1/0;for(let n=0;n<e.length;n++){const r=Math.abs(Math.log(Math.max(t,.5)/e[n]));r<i&&(i=r,s=n)}return s}var At=256,ri=[{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}],ai=[4,8,16,32,64,128].map((t,e)=>({x:e*4,y:128,w:4,h:t,r:t/2-1})),ie={x:248,y:248,w:8,h:8},po=ri.map(t=>t.r*2),yo=ai.map(t=>t.r*2),Nn=(t,e)=>Math.min(Math.max(t+.5-e,0),1);function mo(){const t=new Uint8ClampedArray(At*At*4),e=(s,i,n)=>{const r=(i*At+s)*4;t[r]=t[r+1]=t[r+2]=255,t[r+3]=Math.round(n*255)};for(const s of ri){const i=s.w/2;for(let n=0;n<s.h;n++)for(let r=0;r<s.w;r++)e(s.x+r,s.y+n,Nn(s.r,Math.hypot(r+.5-i,n+.5-i)))}for(const s of ai){const i=s.h/2;for(let n=0;n<s.h;n++)for(let r=0;r<s.w;r++)e(s.x+r,s.y+n,Nn(s.r,Math.abs(n+.5-i)))}for(let s=0;s<ie.h;s++)for(let i=0;i<ie.w;i++)e(ie.x+i,ie.y+s,1);return t}function xo(){const t=document.createElement("canvas");return t.width=t.height=At,t.getContext("2d").putImageData(new ImageData(mo(),At,At),0,0),t}var In=8,oi=`
|
|
2
|
-
#ifdef GL_FRAGMENT_PRECISION_HIGH
|
|
3
|
-
precision highp float;
|
|
4
|
-
#else
|
|
5
|
-
precision mediump float;
|
|
6
|
-
#endif
|
|
7
|
-
`,go=t=>`${oi}
|
|
8
|
-
uniform sampler2D uTex[${t}];
|
|
9
|
-
varying vec2 vUv;
|
|
10
|
-
varying vec4 vColor;
|
|
11
|
-
varying float vSlot;
|
|
12
|
-
void main() {
|
|
13
|
-
vec4 c;
|
|
14
|
-
${Array.from({length:t},(e,s)=>s===t-1?`c = texture2D(uTex[${s}], vUv);`:`if (vSlot < ${s}.5) c = texture2D(uTex[${s}], vUv); else `).join(`
|
|
15
|
-
`)}
|
|
16
|
-
gl_FragColor = c * vColor;
|
|
17
|
-
}`,bo=`
|
|
18
|
-
attribute vec2 aPos;
|
|
19
|
-
attribute vec2 aUv;
|
|
20
|
-
attribute vec4 aColor;
|
|
21
|
-
attribute float aSlot;
|
|
22
|
-
uniform vec2 uScale;
|
|
23
|
-
varying vec2 vUv;
|
|
24
|
-
varying vec4 vColor;
|
|
25
|
-
varying float vSlot;
|
|
26
|
-
void main() {
|
|
27
|
-
vUv = aUv;
|
|
28
|
-
vColor = aColor;
|
|
29
|
-
vSlot = aSlot;
|
|
30
|
-
gl_Position = vec4(aPos * uScale + vec2(-1.0, 1.0), 0.0, 1.0);
|
|
31
|
-
}`,ko=`
|
|
32
|
-
attribute vec4 aCorner;
|
|
33
|
-
attribute vec4 aP01;
|
|
34
|
-
attribute vec4 aP23;
|
|
35
|
-
attribute vec4 aUvRect;
|
|
36
|
-
attribute vec4 aColor;
|
|
37
|
-
attribute float aSlot;
|
|
38
|
-
uniform vec2 uScale;
|
|
39
|
-
varying vec2 vUv;
|
|
40
|
-
varying vec4 vColor;
|
|
41
|
-
varying float vSlot;
|
|
42
|
-
void main() {
|
|
43
|
-
vec2 p = aP01.xy * aCorner.x + aP01.zw * aCorner.y + aP23.xy * aCorner.z + aP23.zw * aCorner.w;
|
|
44
|
-
vUv = vec2(mix(aUvRect.x, aUvRect.z, aCorner.y + aCorner.z), mix(aUvRect.y, aUvRect.w, aCorner.z + aCorner.w));
|
|
45
|
-
vColor = aColor;
|
|
46
|
-
vSlot = aSlot;
|
|
47
|
-
gl_Position = vec4(p * uScale + vec2(-1.0, 1.0), 0.0, 1.0);
|
|
48
|
-
}`,wo={alpha:!0,premultipliedAlpha:!0,antialias:!1,depth:!1,stencil:!1,preserveDrawingBuffer:!1,powerPreference:"high-performance"},vo=["aCorner","aP01","aP23","aUvRect","aColor","aSlot"],Mo=["aPos","aUv","aColor","aSlot"];function Eo(t,e,s={}){const i={...wo,failIfMajorPerformanceCaveat:s.failIfMajorPerformanceCaveat!==!1},n=e===2?t.getContext("webgl2",i):t.getContext("webgl",i)??t.getContext("experimental-webgl",i);if(!n||n.isContextLost())return null;try{return new Ao(t,n,e,s)}catch(r){return console.warn("[engine] WebGL setup failed:",r),n.getExtension("WEBGL_lose_context")?.loseContext(),null}}var Ao=class extends vn{constructor(t,e,s,i){super(),d(this,"canvas",t),d(this,"gl",e),d(this,"opts",i),d(this,"kind"),d(this,"maxTextureSize"),d(this,"support",{filters:!0,shaders:!0}),d(this,"features",{}),d(this,"info",{}),d(this,"lost",!1),d(this,"main"),d(this,"cur"),d(this,"unit",-1),d(this,"onUnit",new Array(In).fill(void 0)),d(this,"fbNow"),d(this,"mapped",!0),d(this,"calls",{useProgram:0,bindTexture:0,activeTexture:0,bindFramebuffer:0}),d(this,"vsrc",""),d(this,"attrs",[]),d(this,"fxr",null),d(this,"batch"),d(this,"dynamic"),d(this,"staticBuf",null),d(this,"index"),d(this,"vao",null),d(this,"inst",null),d(this,"vaoApi",null),d(this,"uScale",null),d(this,"textures",new Map),d(this,"kit"),d(this,"stats",{drawCalls:0,quads:0,filtersSkipped:0}),d(this,"lostListeners",[]),d(this,"restoredListeners",[]),d(this,"tris",new Int32Array(192)),d(this,"sU",0),d(this,"sV0",0),d(this,"sV1",0),d(this,"sColor",0),d(this,"sPacked",0),d(this,"sAlpha",0),d(this,"sHw",0),d(this,"strokeSeg",()=>{const n=this.q;n.set(ms),n[8]=n[10]=this.sU,n[9]=this.sV0,n[11]=this.sV1,n[12]=this.sPacked,this.put(this.kit)}),d(this,"strokeDisc",()=>this.ellipse(ms[0],ms[1],this.sHw,this.sHw,0,this.sColor,this.sAlpha)),d(this,"q",new Float64Array(13)),d(this,"layers",[]),d(this,"layerTex",new Map),d(this,"bScis",!1),d(this,"bx0",0),d(this,"by0",0),d(this,"bx1",0),d(this,"by1",0),d(this,"onContextLost",n=>{n.preventDefault(),this.lost=!0;for(const r of this.lostListeners)r()}),d(this,"onContextRestored",()=>{try{this.layers=[],this.layerTex.clear(),this.fxr=null,this.resetLayers(this.scale),this.setup();for(const n of this.textures.keys())this.textures.set(n,this.upload(n.source));this.lost=!1;for(const n of this.restoredListeners)n()}catch(n){console.warn("[engine] WebGL restore failed:",n)}}),d(this,"views",new Map),this.kind=s===2?"webgl2":"webgl1",this.maxTextureSize=e.getParameter(e.MAX_TEXTURE_SIZE),this.setup(),this.kit=this.createTexture(xo()),Ut.live=this,t.addEventListener("webglcontextlost",this.onContextLost,!1),t.addEventListener("webglcontextrestored",this.onContextRestored,!1)}setup(){const t=this.gl,e=this.kind==="webgl2"?t:null;if(this.inst=null,this.opts.instancing!==!1)if(e)this.inst={divisor:(o,c)=>e.vertexAttribDivisor(o,c),draw:(o,c)=>e.drawElementsInstanced(t.TRIANGLES,o,t.UNSIGNED_SHORT,0,c)};else{const o=t.getExtension("ANGLE_instanced_arrays");o&&(this.inst={divisor:(c,u)=>o.vertexAttribDivisorANGLE(c,u),draw:(c,u)=>o.drawElementsInstancedANGLE(t.TRIANGLES,c,t.UNSIGNED_SHORT,0,u)})}if(this.vaoApi=null,this.opts.vao!==!1)if(e)this.vaoApi={create:()=>e.createVertexArray(),bind:o=>e.bindVertexArray(o),remove:o=>e.deleteVertexArray(o)};else{const o=t.getExtension("OES_vertex_array_object");o&&(this.vaoApi={create:()=>o.createVertexArrayOES(),bind:c=>o.bindVertexArrayOES(c),remove:c=>o.deleteVertexArrayOES(c)})}const s=t.getParameter(t.MAX_TEXTURE_IMAGE_UNITS),i=Math.max(1,Math.min(In,s)),n=this.inst!==null;this.vsrc=n?ko:bo,this.attrs=n?vo:Mo,this.main=this.cur=this.build(go(i));const r=this.main.p;t.useProgram(r),this.calls.useProgram++,this.unit=-1,this.onUnit.fill(void 0),this.fbNow=void 0,this.uScale=this.main.uScale,t.uniform1iv(t.getUniformLocation(r,"uTex"),Int32Array.from({length:i},(o,c)=>c)),this.batch=new ro(n,i),this.vaoApi&&(this.vao=this.vaoApi.create(),this.vaoApi.bind(this.vao)),this.dynamic=t.createBuffer(),t.bindBuffer(t.ARRAY_BUFFER,this.dynamic),t.bufferData(t.ARRAY_BUFFER,this.batch.f32.byteLength,t.DYNAMIC_DRAW),this.index=t.createBuffer(),t.bindBuffer(t.ELEMENT_ARRAY_BUFFER,this.index),t.bufferData(t.ELEMENT_ARRAY_BUFFER,ao(n?1:En),t.STATIC_DRAW);const a=o=>t.getAttribLocation(r,o),l=(o,c,u,f,y,p,x)=>{const m=a(o);m<0||(t.enableVertexAttribArray(m),t.vertexAttribPointer(m,c,u,f,y,p),this.inst&&this.inst.divisor(m,x))};if(n){const o=Xe*4;l("aP01",4,t.FLOAT,!1,o,0,1),l("aP23",4,t.FLOAT,!1,o,16,1),l("aUvRect",4,t.FLOAT,!1,o,32,1),l("aColor",4,t.UNSIGNED_BYTE,!0,o,48,1),l("aSlot",1,t.FLOAT,!1,o,52,1),this.staticBuf=t.createBuffer(),t.bindBuffer(t.ARRAY_BUFFER,this.staticBuf),t.bufferData(t.ARRAY_BUFFER,Float32Array.of(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1),t.STATIC_DRAW),l("aCorner",4,t.FLOAT,!1,16,0,0),t.bindBuffer(t.ARRAY_BUFFER,this.dynamic)}else{const o=_e*4;l("aPos",2,t.FLOAT,!1,o,0,0),l("aUv",2,t.FLOAT,!1,o,8,0),l("aColor",4,t.UNSIGNED_BYTE,!0,o,16,0),l("aSlot",1,t.FLOAT,!1,o,20,0)}t.enable(t.BLEND),t.blendFunc(t.ONE,t.ONE_MINUS_SRC_ALPHA),t.disable(t.DEPTH_TEST),t.disable(t.CULL_FACE),t.pixelStorei(t.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!0);const h=t.getExtension("WEBGL_debug_renderer_info");this.info={version:t.getParameter(t.VERSION),renderer:h?t.getParameter(h.UNMASKED_RENDERER_WEBGL):t.getParameter(t.RENDERER),vendor:h?t.getParameter(h.UNMASKED_VENDOR_WEBGL):t.getParameter(t.VENDOR)},this.features={instancing:n,vao:this.vaoApi!==null,textureSlots:i,maxTextureSize:this.maxTextureSize}}upload(t){const e=this.gl,s=e.createTexture();return this.bindTex(s),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,e.RGBA,e.UNSIGNED_BYTE,t),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),s}resize(t,e){this.canvas.width!==t&&(this.canvas.width=t),this.canvas.height!==e&&(this.canvas.height=e)}createTexture(t){const e={id:Ys(),width:t.width,height:t.height,source:t};return this.textures.set(e,this.lost?null:this.upload(t)),e}updateTexture(t,e,s=0,i=0){if(this.lost)return;this.batch.has(t)&&this.flush();const n=this.gl,r=this.textures.get(t);r&&(this.bindTex(r),!e||e===t.source&&s===0&&i===0?n.texImage2D(n.TEXTURE_2D,0,n.RGBA,n.RGBA,n.UNSIGNED_BYTE,t.source):n.texSubImage2D(n.TEXTURE_2D,0,s,i,n.RGBA,n.UNSIGNED_BYTE,e))}destroyTexture(t){this.batch.has(t)&&this.flush();const e=this.textures.get(t);e&&!this.lost&&this.deleteTex(e),this.textures.delete(t)}begin(t,e,s){if(this.stats.drawCalls=this.stats.quads=this.stats.filtersSkipped=0,this.batch.reset(),this.resetLayers(s),this.bScis=!1,this.lost)return;const i=this.gl;i.disable(i.SCISSOR_TEST),this.bindFb(null),i.viewport(0,0,this.canvas.width,this.canvas.height);const n=e;i.clearColor((t>>16&255)/255*n,(t>>8&255)/255*n,(t&255)/255*n,n),i.clear(i.COLOR_BUFFER_BIT),this.use(this.main),i.uniform2f(this.uScale,2*s/this.canvas.width,-2*s/this.canvas.height),this.mapped=!0}build(t){const e=this.gl,s=On(e,e.VERTEX_SHADER,this.vsrc);let i;try{i=On(e,e.FRAGMENT_SHADER,t)}catch(r){throw e.deleteShader(s),r}const n=e.createProgram();if(e.attachShader(n,s),e.attachShader(n,i),this.attrs.forEach((r,a)=>e.bindAttribLocation(n,a,r)),e.linkProgram(n),e.deleteShader(s),e.deleteShader(i),!e.getProgramParameter(n,e.LINK_STATUS)){const r=e.getProgramInfoLog(n)??"?";throw e.deleteProgram(n),new Error(`link: ${r}`)}return{p:n,uScale:e.getUniformLocation(n,"uScale"),locs:new Map}}u(t,e){let s=t.locs.get(e);return s===void 0&&t.locs.set(e,s=this.gl.getUniformLocation(t.p,e)),s}use(t){this.cur!==t&&(this.cur=t,this.gl.useProgram(t.p),this.calls.useProgram++)}bindTex(t,e=this.unit<0?0:this.unit){const s=this.gl;this.onUnit[e]!==t&&(this.unit!==e&&(s.activeTexture(s.TEXTURE0+e),this.calls.activeTexture++,this.unit=e),s.bindTexture(s.TEXTURE_2D,t),this.calls.bindTexture++,this.onUnit[e]=t)}deleteTex(t){this.gl.deleteTexture(t);for(let e=0;e<this.onUnit.length;e++)this.onUnit[e]===t&&(this.onUnit[e]=null)}bindFb(t){if(t)for(let s=0;s<this.onUnit.length;s++)this.onUnit[s]===t.gl&&this.bindTex(null,s);const e=t?t.fb:null;this.fbNow!==e&&(this.gl.bindFramebuffer(this.gl.FRAMEBUFFER,e),this.calls.bindFramebuffer++,this.fbNow=e)}slotOf(t){this.batch.full&&this.flush();let e=this.batch.slot(t);return e<0&&(this.flush(),e=this.batch.slot(t)),e}quad(t,e,s,i,n,r,a,l){V[0]=i,V[1]=n,V[2]=a,this.quadQ(t,e,s,r,l)}quadQ(t,e,s,i,n){const r=V[2];if(this.lost||r<=0)return;const a=this.q,l=V[0],h=V[1],o=s[4],c=s[5],u=s[0]*l,f=s[1]*l,y=s[2]*h,p=s[3]*h;a[0]=o,a[1]=c,a[2]=u+o,a[3]=f+c,a[4]=u+y+o,a[5]=f+p+c,a[6]=y+o,a[7]=p+c;const x=1/t.width,m=1/t.height;a[8]=e.x*x,a[9]=e.y*m,a[10]=(e.x+e.w)*x,a[11]=(e.y+e.h)*m,a[12]=ke(i,r,n==="add"),this.put(t)}put(t){if(this.mute)return;const e=this.q;let s=!1;const i=Math.min(e[0],e[2],e[4],e[6]),n=Math.max(e[0],e[2],e[4],e[6]),r=Math.min(e[1],e[3],e[5],e[7]),a=Math.max(e[1],e[3],e[5],e[7]);if(this.cOn){if(this.px1<=this.px0||this.py1<=this.py0)return;const h=this.scale,o=this.px0/h,c=this.py0/h,u=this.px1/h,f=this.py1/h;if(n<=o||i>=u||a<=c||r>=f)return;if(i<o||n>u||r<c||a>f){const y=e[0],p=e[1],x=e[2],m=e[5];if(p===e[3]&&x===e[4]&&m===e[7]&&e[6]===y){if(y!==x){const g=Math.min(Math.max(y,o),u),k=Math.min(Math.max(x,o),u),E=e[8],w=(e[10]-E)/(x-y);e[10]=E+(k-y)*w,e[8]=E+(g-y)*w,e[0]=e[6]=g,e[2]=e[4]=k}if(p!==m){const g=Math.min(Math.max(p,c),f),k=Math.min(Math.max(m,c),f),E=e[9],w=(e[11]-E)/(m-p);e[11]=E+(k-p)*w,e[9]=E+(g-p)*w,e[1]=e[3]=g,e[5]=e[7]=k}}else s=!0}}const l=this.bx0===this.px0&&this.by0===this.py0&&this.bx1===this.px1&&this.by1===this.py1;if(s?(!this.bScis||!l)&&(this.flush(),this.bScis=!0,this.bx0=this.px0,this.by0=this.py0,this.bx1=this.px1,this.by1=this.py1):this.bScis&&!(this.cOn&&l)&&(this.flush(),this.bScis=!1),this.real){const h=this.gq;h[0]=i,h[1]=r,h[2]=n,h[3]=a,this.growQ()}this.batch.pushQ(e,this.slotOf(t))}ellipse(t,e,s,i,n,r,a){if(this.lost||a<=0||s<=0||i<=0)return;const l=ri[Pn(Math.max(s,i)*2*this.scale,po)],h=l.w/2/l.r,o=s*h,c=i*h,u=Math.cos(n),f=Math.sin(n),y=u*o,p=f*o,x=-f*c,m=u*c,g=1/At,k=this.q;k[0]=t-y-x,k[1]=e-p-m,k[2]=t+y-x,k[3]=e+p-m,k[4]=t+y+x,k[5]=e+p+m,k[6]=t-y+x,k[7]=e-p+m,k[8]=l.x*g,k[9]=l.y*g,k[10]=(l.x+l.w)*g,k[11]=(l.y+l.h)*g,k[12]=ke(r,a),this.put(this.kit)}polygon(t,e,s,i){if(this.lost||i<=0||e<3)return;this.tris.length<e*3&&(this.tris=new Int32Array(Math.max(e*3,this.tris.length*2)));const n=this.tris,r=co(t,e,n),a=ke(s,i),l=(ie.x+ie.w/2)/At,h=(ie.y+ie.h/2)/At;for(let o=0;o<r;o+=3){const c=n[o]*2,u=n[o+1]*2,f=n[o+2]*2,y=this.q;y[0]=t[c],y[1]=t[c+1],y[2]=t[u],y[3]=t[u+1],y[4]=y[6]=t[f],y[5]=y[7]=t[f+1],y[8]=y[10]=l,y[9]=y[11]=h,y[12]=a,this.put(this.kit)}}stroke(t,e,s,i,n,r){if(this.lost||n<=0||s<=0||e<1)return;const a=ai[Pn(s*this.scale,yo)],l=s/2*(a.h/2/a.r);this.sPacked=ke(i,n),this.sColor=i,this.sAlpha=n,this.sU=(a.x+a.w/2)/At,this.sV0=a.y/At,this.sV1=(a.y+a.h)/At,this.sHw=s/2,uo(t,e,l,r,this.strokeSeg,this.strokeDisc)}target(t,e,s,i){const n=this.gl,r=n.createTexture();this.bindTex(r),n.texImage2D(n.TEXTURE_2D,0,n.RGBA,t,e,0,n.RGBA,n.UNSIGNED_BYTE,null);const a=i?n.LINEAR:n.NEAREST;n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MIN_FILTER,a),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MAG_FILTER,a),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_S,n.CLAMP_TO_EDGE),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_T,n.CLAMP_TO_EDGE),this.bindTex(null);const l=n.createFramebuffer();n.bindFramebuffer(n.FRAMEBUFFER,l),n.framebufferTexture2D(n.FRAMEBUFFER,n.COLOR_ATTACHMENT0,n.TEXTURE_2D,r,0);const h=n.checkFramebufferStatus(n.FRAMEBUFFER)===n.FRAMEBUFFER_COMPLETE;if(this.fbNow=l,this.bindFb(this.parent()),!h)return this.deleteTex(r),n.deleteFramebuffer(l),null;const o={tex:{id:Ys(),width:t,height:e,source:this.canvas},gl:r,fb:l,w:t,h:e,f:s};return this.layerTex.set(o.tex,r),o}drop(t){this.batch.has(t.tex)&&this.flush(),this.deleteTex(t.gl),this.gl.deleteFramebuffer(t.fb),this.layerTex.delete(t.tex)}parent(){return this.real>0?this.layers[this.real-1]:null}layerAt(t){const e=this.canvas.width,s=this.canvas.height;let i=this.layers[t]??null;return i&&(i.w!==e||i.h!==s)&&(this.drop(i),i=this.layers[t]=null),i??(this.layers[t]=this.target(e,s,1,!1))}pushLayer(){if(this.lost)return!1;this.flush();const t=this.layerAt(this.real);if(!t)return!1;const e=this.gl;return this.bindFb(t),e.disable(e.SCISSOR_TEST),e.clearColor(0,0,0,0),e.clear(e.COLOR_BUFFER_BIT),!0}popLayer(){return this.flush(),this.bindFb(this.parent()),this.layers[this.real].tex}filters(){return this.lost||!Ut.gl?null:this.fxr??(this.fxr=Ut.gl(this))}composite(t,e,s,i){if(i&&this.filters()?.chain(t,s,i))return;const n=this.gl;e&&n.blendFunc(n.ZERO,n.SRC_ALPHA),this.final(this.main,t,1,s),e&&(this.flush(),n.blendFunc(n.ONE,n.ONE_MINUS_SRC_ALPHA))}final(t,e,s,i){const n=this.gl,r=this.canvas.width,a=this.canvas.height,l=this.scale;(t!==this.main||!this.mapped)&&(this.bindFb(this.parent()),n.viewport(0,0,r,a),this.use(t),n.uniform2f(t.uScale,2*l/r,-2*l/a),this.mapped=t===this.main);const h=this.rx0/l,o=this.ry0/l,c=this.rx1/l,u=this.ry1/l,f=1/(s*e.width),y=1/(s*e.height),p=this.q;p[0]=p[6]=h,p[1]=p[3]=o,p[2]=p[4]=c,p[5]=p[7]=u,p[8]=this.rx0*f,p[9]=1-this.ry0*y,p[10]=this.rx1*f,p[11]=1-this.ry1*y,p[12]=ke(16777215,i),this.put(e),t!==this.main&&this.flush()}remap(){const t=this.gl;this.bindFb(this.parent()),t.viewport(0,0,this.canvas.width,this.canvas.height),this.use(this.main),t.uniform2f(this.uScale,2*this.scale/this.canvas.width,-2*this.scale/this.canvas.height),this.mapped=!0}upload2(t){const e=this.gl,s=t.words;if(this.kind==="webgl2")return e.bufferSubData(e.ARRAY_BUFFER,0,t.f32,0,s);let i=this.views.get(s);i||(this.views.size>=256&&this.views.clear(),this.views.set(s,i=t.f32.subarray(0,s))),e.bufferSubData(e.ARRAY_BUFFER,0,i)}flush(){const t=this.batch;if(!t.quads||this.lost)return t.reset();const e=this.gl;this.bScis?(e.enable(e.SCISSOR_TEST),e.scissor(this.bx0,this.canvas.height-this.by1,this.bx1-this.bx0,this.by1-this.by0)):e.disable(e.SCISSOR_TEST),this.upload2(t);for(let s=0;s<t.bound;s++){const i=t.textures[s];this.bindTex(this.textures.get(i)??this.layerTex.get(i)??null,s)}this.inst?this.inst.draw(6,t.quads):e.drawElements(e.TRIANGLES,t.quads*6,e.UNSIGNED_SHORT,0),this.stats.drawCalls++,this.stats.quads+=t.quads,t.reset()}end(){return this.closeLayers(),this.flush(),this.stats.filtersSkipped=this.skipped,this.stats}onLost(t){this.lostListeners.push(t)}onRestored(t){this.restoredListeners.push(t)}destroy(){const t=this.gl;Ut.live===this&&(Ut.live=null),this.canvas.removeEventListener("webglcontextlost",this.onContextLost),this.canvas.removeEventListener("webglcontextrestored",this.onContextRestored);try{for(const e of this.textures.values())e&&t.deleteTexture(e);for(const e of this.layers)e&&(t.deleteTexture(e.gl),t.deleteFramebuffer(e.fb));this.fxr?.destroy(),this.fxr=null,t.deleteBuffer(this.dynamic),t.deleteBuffer(this.index),this.staticBuf&&t.deleteBuffer(this.staticBuf),this.vao&&this.vaoApi&&this.vaoApi.remove(this.vao),t.deleteProgram(this.main.p),t.getExtension("WEBGL_lose_context")?.loseContext()}catch{}this.textures.clear()}};function On(t,e,s){const i=t.createShader(e);if(t.shaderSource(i,s),t.compileShader(i),!t.getShaderParameter(i,t.COMPILE_STATUS)){const n=t.getShaderInfoLog(i)??"?";throw t.deleteShader(i),new Error(n)}return i}function zn(t="auto"){switch(t){case"canvas2d":return["canvas2d"];case"webgl1":return["webgl1","canvas2d"];default:return["webgl2","webgl1","canvas2d"]}}function li(t,e={}){let s=t;for(const i of zn(e.renderer)){const n=i==="canvas2d"?ei(s):Eo(s,i==="webgl2"?2:1,e);if(n)return n;s=hi(s)}throw new Error("No renderer: this browser has neither WebGL nor Canvas 2D")}function hi(t){const e=t.cloneNode(!1);return t.parentNode?.replaceChild(e,t),e}function _o(t=typeof location<"u"?location.search:""){const e=new URLSearchParams(t).get("renderer");return e==="canvas"?"canvas2d":e==="webgl2"||e==="webgl1"||e==="canvas2d"||e==="webgl"||e==="auto"?e:void 0}var ci=class{constructor(t,e={}){d(this,"atlas",t),d(this,"tags",new Map),d(this,"count",0),d(this,"m",be()),d(this,"measure",null),d(this,"height"),d(this,"font"),this.height=e.tagHeight??34,this.font=e.tagFont??"Nunito, sans-serif"}drop(){for(const t of this.tags.values())for(const e of t.values())for(const s of e.values())this.atlas.release(s);this.tags.clear(),this.count=0}get(t,e,s){let i=this.tags.get(t);i||this.tags.set(t,i=new Map);let n=i.get(e);n||i.set(e,n=new Map);const r=n.get(s);return r&&this.atlas.valid(r)?r:this.bake(t,e,s)}bake(t,e,s){const i=this.height,n=`700 ${Math.round(i*.65)}px ${this.font}`,r=this.measure??(this.measure=document.createElement("canvas").getContext("2d"));r.font=n;const a=Math.round(i*.4),l=Math.ceil(r.measureText(t).width)+a*2,h=this.atlas.bake((l+2)*s,(i+2)*s,u=>{u.scale(s,s),u.translate(1,1);const f=i/2;u.beginPath(),u.moveTo(f,0),u.lineTo(l-f,0),u.arc(l-f,f,f,-Math.PI/2,Math.PI/2),u.lineTo(f,i),u.arc(f,f,f,Math.PI/2,Math.PI*3/2),u.closePath(),u.fillStyle=e,u.fill(),u.fillStyle="#fff",u.font=n,u.textAlign="center",u.textBaseline="middle",u.fillText(t,l/2,i/2+1)},s,1,1,1);++this.count>64&&(this.drop(),this.count=1);let o=this.tags.get(t);o||this.tags.set(t,o=new Map);let c=o.get(e);return c||o.set(e,c=new Map),c.set(s,h),h}draw(t,e,s,i,n,r,a,l,h,o,c){const u=Os(s,n,{band:So(i)});if(!u)return;const f=this.height,y=this.get(r,a,h),p=y.w/y.scale-2,x=Math.min(Math.max(u.head.x-p/2,4),o-p-4),m=Math.min(Math.max(u.head.y-u.headR*2.2-f,4),c-f-4);Xt(this.m,null,x-1,m-1,0,1,1),t.quad(e(y.surface),y,this.m,y.w/y.scale,y.h/y.scale,16777215,l,"normal")}},So=t=>t.band==="3-5"||t.band==="9-12"?t.band:"6-8",To=(t,e=!1)=>e?Math.min(2**Math.round(Math.log2(Math.max(t,8))),256):Math.min(2**(Math.ceil(Math.log2(Math.max(t,8))*2)/2),512);function fi(t,e=null){const s={minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0},i=(n,r,a)=>{const l=e?e[0]*n+e[2]*r+e[4]:n,h=e?e[1]*n+e[3]*r+e[5]:r,o=e?Math.hypot(e[0],e[1]):1;s.minX=Math.min(s.minX,l-a*o),s.minY=Math.min(s.minY,h-a*o),s.maxX=Math.max(s.maxX,l+a*o),s.maxY=Math.max(s.maxY,h+a*o)};for(const n of t){const r="lw"in n&&n.stroke?(n.lw??1)/2:0;switch(n.k){case"circle":i(n.x-n.r,n.y-n.r,r),i(n.x+n.r,n.y+n.r,r),i(n.x-n.r,n.y+n.r,r),i(n.x+n.r,n.y-n.r,r);break;case"ellipse":case"rect":{const a=n.k==="ellipse"?Math.max(n.rx,n.ry):Math.hypot(n.w,n.h)/2;i(n.x-a,n.y-a,r),i(n.x+a,n.y+a,r),i(n.x-a,n.y+a,r),i(n.x+a,n.y-a,r);break}case"path":{const a=ni(n.d);for(let l=0;l<a.count;l++){const h=a.subs[l];for(let o=0;o<h.n;o++)i(h.pts[o*2],h.pts[o*2+1],r)}break}case"line":for(let a=0;a+1<n.pts.length;a+=2)i(n.pts[a],n.pts[a+1],r);break;case"group":{const a=Xt(be(),e,n.x,n.y,n.rot??0,n.s??1,n.s??1),l=fi(n.items,a);Number.isFinite(l.minX)&&(s.minX=Math.min(s.minX,l.minX),s.minY=Math.min(s.minY,l.minY),s.maxX=Math.max(s.maxX,l.maxX),s.maxY=Math.max(s.maxY,l.maxY));break}}}return s}var ui=class{constructor(t){d(this,"atlas",t),d(this,"seen",new WeakSet),d(this,"baked",new WeakMap),d(this,"m",be()),d(this,"stack",[]),d(this,"local",be()),d(this,"pts",new Float64Array(128)),d(this,"stats",{baked:0,vector:0}),d(this,"bakeGroups",!0),d(this,"coarse",!1),d(this,"gen",0),d(this,"live",new Set)}setTier(t){const e=t==="low";if(e!==this.coarse){this.coarse=e,this.gen++;for(const s of this.live)this.atlas.release(s.frame);this.live.clear()}}draw(t,e,s,i,n,r,a){const l=typeof i=="string"?rs(i)??Ne:i,h=Wi(s,l,n);return h.length?(r<=0||(r<1?(this.paint(t,e,h,null,t.beginLayer()?1:r,a),t.endLayer(r)):this.paint(t,e,h,null,r,a)),!0):!1}paint(t,e,s,i,n,r,a=0){var l;for(let h=0;h<s.length;h++){const o=s[h];if(o.k==="group"){const g=Xt((l=this.stack)[a]??(l[a]=be()),i,o.x,o.y,o.rot??0,o.s??1,o.s??1),k=n*(o.alpha??1);if(this.bakeGroups&&this.seen.has(o.items)){const E=$t(g[0],g[1])*r,w=this.bake(o.items,E);if(w){const T=w.frame,_=this.m;_.set(g),_[4]=g[0]*-w.ox+g[2]*-w.oy+g[4],_[5]=g[1]*-w.ox+g[3]*-w.oy+g[5],t.quad(e(T.surface),T,_,T.w/w.k,T.h/w.k,16777215,k,"normal"),this.stats.baked++;continue}}this.seen.add(o.items),this.stats.vector++,this.paint(t,e,o.items,g,k,r,a+1);continue}const c=n*(o.alpha??1),u=i?$t(i[0],i[1]):1,f=i?Math.atan2(i[1],i[0]):0,y=(o.lw??1)*u,p=o.stroke&&(o.lw??1)>0?Bt(o.stroke):null,x=o.fill&&o.k!=="line"?Bt(o.fill):null;if(o.k==="circle"||o.k==="ellipse"){const g=i?i[0]*o.x+i[2]*o.y+i[4]:o.x,k=i?i[1]*o.x+i[3]*o.y+i[5]:o.y,E=(o.k==="circle"?o.r:o.rx)*u,w=(o.k==="circle"?o.r:o.ry)*u,T=(o.k==="ellipse"?o.rot??0:0)+f;if(x&&p)t.ellipse(g,k,E+y/2,w+y/2,T,p[0],c*p[1]),t.ellipse(g,k,Math.max(E-y/2,0),Math.max(w-y/2,0),T,x[0],c*x[1]);else if(x)t.ellipse(g,k,E,w,T,x[0],c*x[1]);else if(p){const _=Math.min(Math.max(Math.ceil(Math.max(E,w)*r*.6),12),64),L=this.pts=si(this.pts,_*2),I=Math.cos(T),R=Math.sin(T);for(let O=0;O<_;O++){const q=O/_*Math.PI*2,j=Math.cos(q)*E,B=Math.sin(q)*w;L[O*2]=g+j*I-B*R,L[O*2+1]=k+j*R+B*I}t.stroke(L,_,y,p[0],c*p[1],!0)}continue}if(o.k==="line"){if(!p)continue;const g=o.pts.length>>1,k=this.pts=si(this.pts,g*2);for(let E=0;E<g;E++){const w=o.pts[E*2],T=o.pts[E*2+1];k[E*2]=i?i[0]*w+i[2]*T+i[4]:w,k[E*2+1]=i?i[1]*w+i[3]*T+i[5]:T}t.stroke(k,g,y,p[0],c*p[1],!1);continue}const m=o.k==="path"?ni(o.d,i,u*r):Co(o,Xt(this.local,i,o.x,o.y,o.rot??0,1,1),r*u);for(let g=0;g<m.count;g++){const k=m.subs[g],E=k.n,w=o.k==="rect"||k.closed;x&&E>=3&&(t.polygon(k.pts,E,x[0],c*x[1]),p||t.stroke(k.pts,E,1/r,x[0],c*x[1],!0)),p&&t.stroke(k.pts,E,y,p[0],c*p[1],w)}}}bake(t,e){const s=To(e,this.coarse);let i=this.baked.get(t);const n=i?.get(s);if(n&&n.gen===this.gen&&this.atlas.valid(n.frame))return n;n&&this.live.delete(n);const r=fi(t);if(!Number.isFinite(r.minX))return null;const a=2/s,l=(r.maxX-r.minX+a*2)*s,h=(r.maxY-r.minY+a*2)*s;if(l>1024||h>1024)return null;const o=-r.minX+a,c=-r.minY+a,f={frame:this.atlas.bake(l,h,y=>{y.scale(s,s),y.translate(o,c),Ns(y,t)}),k:s,ox:o,oy:c,gen:this.gen};return i||this.baked.set(t,i=new Map),i.set(s,f),this.live.add(f),f}},Se=new Array(36).fill(0),Te=0,Ht=(t,e=NaN,s=NaN,i=NaN,n=NaN)=>{Se[Te++]=t,t!==kt.Z&&(Se[Te++]=e,Se[Te++]=s,t===kt.Q&&(Se[Te++]=i,Se[Te++]=n))};function Co(t,e,s){const i=Math.max(0,Math.min(t.r,t.w/2,t.h/2)),n=-t.w/2,r=-t.h/2,{M:a,L:l,Q:h,Z:o}=kt;return Te=0,Ht(a,n+i,r),Ht(l,n+t.w-i,r),Ht(h,n+t.w,r,n+t.w,r+i),Ht(l,n+t.w,r+t.h-i),Ht(h,n+t.w,r+t.h,n+t.w-i,r+t.h),Ht(l,n+i,r+t.h),Ht(h,n,r+t.h,n,r+t.h-i),Ht(l,n,r+i),Ht(h,n,r,n+i,r),Ht(o),ni(Se,e,s)}function Ro(t,e={}){let s=li(t,e);const i=new Ks(Math.min(1024,s.maxTextureSize),2);i.onDrop=_=>{_.texture&&s.destroyTexture(_.texture),_.texture=null};const n=new ui(i),r=()=>{const _=new to;return e.local&&_.setLocal(!0),_};let a=r();const l=new Map;let h=1e6;const o=e.smooth===!1?1:typeof e.smooth=="number"?Math.min(Math.max(e.smooth,.05),1):a.defaultAmount;let c=gs(s);const u=new ci(i,e),f={w:1,h:1};let y=1,p=0,x=!1;const m=()=>u.drop(),g=typeof document<"u"?document.fonts:void 0;g?.ready?.then(()=>{x||m()}),g?.addEventListener?.("loadingdone",m);const k=()=>{const _=hi(s.canvas),L=ei(_);if(L){console.warn("[engine] avatars: WebGL context lost for good, switching to Canvas 2D"),s.destroy(),s=L;for(const I of i.pages)I.surface.texture=null;c=gs(s),p=0}},E=()=>{if(!s.lost)return p=0,!0;const _=performance.now();return p||(p=_),_-p>3e3&&k(),!s.lost},w=()=>{const _=s.canvas;e.units?(y=e.pixelRatio??1,f.w=e.units.width,f.h=e.units.height):(y=e.pixelRatio??Math.min(globalThis.devicePixelRatio||1,2),f.w=_.clientWidth||_.width/y,f.h=_.clientHeight||_.height/y),s.resize(Math.max(1,Math.round(f.w*y)),Math.max(1,Math.round(f.h*y))),s.begin(0,0,y)},T=(_,L)=>{if(_.key===void 0)return _.id??L+1;let I=l.get(_.key);return I===void 0&&(l.size>256&&l.clear(),l.set(_.key,I=h++)),I};return{get renderer(){return s},get kind(){return s.kind},get lost(){return s.lost},get canvas(){return s.canvas},draw(_,L){if(E()){w();for(let I=0;I<_.length;I++){const R=_[I];if(!Array.isArray(R.body))continue;const O=T(R,I),q=o<1||e.interpolate!==!1?a.posed(O,R.body,o,e.interpolate!==!1):R.body,j=rs(R.avatar??"")??Ne,B=R.alpha??1;!n.draw(s,c,q,j,L,B,y)||!R.name||u.draw(s,c,q,j,L,R.name,R.color??"#6FA0E0",B,y,f.w,f.h)}s.end()}},clear(){E()&&(w(),s.end())},reset(){a=r(),l.clear()},destroy(){x=!0,g?.removeEventListener?.("loadingdone",m),s.destroy()}}}var xs=new Map;function Fo(t,e,s=Math.min(globalThis.devicePixelRatio||1,2)){const i=`${t}|${e}|${s}`;let n=xs.get(i);if(n)return n;n=document.createElement("canvas"),n.width=n.height=Math.round(e*s);const r=n.getContext("2d");return r.scale(s,s),r.beginPath(),r.rect(0,0,e,e),r.clip(),Ns(r,Fa(rs(t)??Ne,e)),xs.size>64&&xs.clear(),xs.set(i,n),n}function gs(t){return e=>{if(e.texture||(e.texture=t.createTexture(e.source),e.pending.length=0),e.pending.length){for(const[s,i,n]of e.pending)t.updateTexture(e.texture,s,i,n);e.pending.length=0}return e.texture}}var Dn='Fredoka, Nunito, "Varela Round", system-ui, sans-serif',$e="rgba(10,16,30,0.75)";function Bn(t,e){const s=t.size??40,i=t.outline?t.outline===!0?$e:t.outline:null,n=i?t.outlineWidth??Math.max(s*.12,3):0,r=t.shadow&&e?t.shadow===!0?$e:t.shadow:null,a=r?t.shadowBlur??s*.25:0;return{size:s,font:t.font??Dn,weight:t.weight??700,color:t.color??"#FBEFE3",outline:i,ow:n,shadow:r,blur:a,pad:n/2+a*1.2+2,th:s*1.25}}var Un=(t,e)=>`${t.weight} ${t.size*e}px ${t.font}`;function Hn(t,e,s,i,n,r){t.scale(i,i),t.font=Un(s,1),t.textBaseline="middle",t.textAlign="left",t.lineJoin="round",s.shadow&&(t.shadowColor=s.shadow,t.shadowBlur=s.blur*i),s.outline&&(t.strokeStyle=s.outline,t.lineWidth=s.ow,t.strokeText(e,n,r),t.shadowColor="transparent"),t.fillStyle=s.color,t.fillText(e,n,r)}var bs=null;function Gn(t,e,s){return bs??(bs=document.createElement("canvas").getContext("2d")),bs.font=Un(e,s),bs.measureText(t).width/s}var qe=class extends we{constructor(t,e,s={}){super(t,null),d(this,"_text"),d(this,"_style"),d(this,"dirty",!0),d(this,"bakedScale",0),d(this,"bakedFontGen",-1),d(this,"bakedEffects",!0),d(this,"capW",0),d(this,"capH",0),this._text=e;const{x:i,y:n,rotation:r,scale:a,scaleX:l,scaleY:h,alpha:o,visible:c,tint:u,blend:f,z:y,anchor:p,hitRadius:x,clip:m,mask:g,filters:k,...E}=s;this._style=E,this.bake(),this.set({x:i,y:n,rotation:r,scale:a,scaleX:l,scaleY:h,alpha:o,visible:c,tint:u,blend:f,z:y,hitRadius:x,clip:m,mask:g,filters:k}),p!==void 0&&(this.anchor=p)}get text(){return this._text}set text(t){const e=String(t);e!==this._text&&(this._text=e,this.dirty=!0)}get style(){return this._style}set style(t){this._style={...this._style,...t},this.dirty=!0}bitmap(){const t=this._style.bitmapFont;if(!t)return null;const e=typeof t=="string"?this.kernel.bitmapFont(t):t;if(this.autoAnchor){const s=this._style.align;this.anchorX=s==="left"?0:s==="right"?1:.5,this.anchorY=.5}return e}get naturalWidth(){const t=this.bitmap();return t?t.measure(this._text)*((this._style.size??t.size)/t.size):super.naturalWidth}get naturalHeight(){const t=this.bitmap();return t?t.lineHeight*((this._style.size??t.size)/t.size):super.naturalHeight}frameNow(){return this._style.bitmapFont?null:this.bake()}draw(t,e,s){const i=this.bitmap();if(!i)return super.draw(t,e,s);const n=(this._style.size??i.size)/i.size,r=i.measure(this._text)*n,a=i.lineHeight*n,l=this.width,h=this.height,o=r>0?l/r:1,c=a>0?h/a:1;i.run(this._text,t,this.world,-this.anchorX*l,-this.anchorY*h,n*o,n*c,s,e,this.blend)}destroy(){this._frame&&this.kernel.atlas.release(this._frame),super.destroy()}bake(){const t=this.kernel;if(this._style.bitmapFont)return null;const e=t.pixelScale,s=t.effects;return!this.dirty&&e===this.bakedScale&&t.fontGen===this.bakedFontGen&&s===this.bakedEffects&&t.atlas.valid(this._frame)?this._frame:this.rebake()}rebake(){const t=this.kernel,e=t.pixelScale,s=t.effects;this.dirty=!1,this.bakedScale=e,this.bakedFontGen=t.fontGen,this.bakedEffects=s;const i=Bn(this._style,s),{pad:n,th:r}=i,a=Gn(this._text,i,e),l=(a+n*2)*e,h=(r+n*2)*e,o=this._style.align??"center",c=o==="left"?n:o==="right"?n+a:n+a/2,u=p=>Hn(p,this._text,i,e,n,n+r/2),f=this._frame;let y=null;return f&&t.atlas.valid(f)&&f.scale===e&&(y=t.atlas.rebake(f,l,h,u,this.capW,this.capH),y?Object.assign(y,{ox:c,oy:n+r/2,margin:n}):t.atlas.release(f)),y||(this.capW=Math.ceil(l*1.25+16),this.capH=Math.ceil(h),y=t.atlas.bake(this.capW,this.capH,u,e,c,n+r/2,n),y.w=Math.ceil(l),y.h=Math.ceil(h)),this._frame=y,this.autoAnchor&&this.useFrameAnchor(),this._w=this._h=null,y}},ct=(t,e=0)=>{const s=Number(t);return Number.isFinite(s)?s:e};function ks(t){typeof t=="string"&&/^\s*[{[]/.test(t)&&(t=JSON.parse(t));const e={size:0,lineHeight:0,base:0,pages:[],chars:[],kernings:[]},s=(i,n)=>{i==="info"?e.size=Math.abs(ct(n.size)):i==="common"?(e.lineHeight=ct(n.lineHeight),e.base=ct(n.base)):i==="page"?e.pages[ct(n.id)]=String(n.file??""):i==="char"?e.chars.push({id:ct(n.id),x:ct(n.x),y:ct(n.y),width:ct(n.width),height:ct(n.height),xoffset:ct(n.xoffset),yoffset:ct(n.yoffset),xadvance:ct(n.xadvance),page:ct(n.page)}):e.kernings.push({first:ct(n.first),second:ct(n.second),amount:ct(n.amount)})};if(typeof t=="object"){const i=t;s("info",i.info??{}),s("common",i.common??{});for(const[n,r]of(i.pages??[]).entries())s("page",{id:n,file:r});for(const n of i.chars??[])s("char",n);for(const n of i.kernings??[])s("kerning",n)}else{const i=/(?:^|<)\s*(info|common|page|char|kerning)\s([^\n<>]*)/gm,n=/(\w+)=(?:"([^"]*)"|([^\s/>]+))/g;for(let r=i.exec(t);r;r=i.exec(t)){const a={};for(let l=n.exec(r[2]);l;l=n.exec(r[2]))a[l[1]]=l[2]??l[3];s(r[1],a)}}return e.size||(e.size=e.lineHeight),e}var di=class{constructor(t,e,s,i=null,n=null){d(this,"baker",i),d(this,"host",n),d(this,"size"),d(this,"lineHeight"),d(this,"base"),d(this,"ascii",new Array(128)),d(this,"more",new Map),d(this,"kern",new Map),d(this,"bScale",0),d(this,"bFontGen",-1),d(this,"bEffects",!1),d(this,"bGen",-1),this.size=t,this.lineHeight=e,this.base=s}set(t,e){t<128?this.ascii[t]=e:this.more.set(t,e)}setKerning(t,e,s){this.kern.set(t*1114112+e,s)}prepare(){const t=this.host;if(!(!t||t.pixelScale===this.bScale&&t.fontGen===this.bFontGen&&t.effects===this.bEffects&&t.atlas.gen===this.bGen)){this.bScale=t.pixelScale,this.bFontGen=t.fontGen,this.bEffects=t.effects,this.bGen=t.atlas.gen;for(const e of this.ascii)e&&t.atlas.release(e.frame);for(const e of this.more.values())e&&t.atlas.release(e.frame);this.ascii.fill(void 0),this.more.clear()}}glyph(t){let e=t<128?this.ascii[t]:this.more.get(t);return(e===void 0||e&&this.host&&!this.host.atlas.valid(e.frame))&&(e=this.baker?this.baker(t):null,this.set(t,e)),e}kerning(t,e){return this.kern.size?this.kern.get(t*1114112+e)??0:0}measure(t){return this.run(t)}run(t,e,s,i=0,n=0,r=1,a=1,l=0,h=1,o="normal"){this.prepare();let c=0,u=-1;for(let f=0;f<t.length;f++){let y=t.charCodeAt(f);y>=55296&&y<56320&&f+1<t.length&&(y=t.codePointAt(f),f++),u>=0&&(c+=this.kerning(u,y)),u=y;const p=this.glyph(y);p&&(e&&p.w>0&&p.h>0&&(os(s,i+(c+p.x)*r,n+p.y*a),e.r.quad(e.tex(p.frame.surface),p.frame,lt,p.w*r,p.h*a,l,h,o)),c+=p.advance)}return c}};function Lo(t,e){const s=new di(t.size,t.lineHeight,t.base);for(const i of t.chars){const n=e[i.page];if(!n)continue;const r={surface:n,x:i.x,y:i.y,w:i.width,h:i.height,scale:1,gen:0,ox:0,oy:0,margin:0};s.set(i.id,{frame:r,x:i.xoffset,y:i.yoffset,w:i.width,h:i.height,advance:i.xadvance})}for(const i of t.kernings)s.setKerning(i.first,i.second,i.amount);return s}function Po(t,e){const s={...e},i=e.size??40,n=a=>{const l=String.fromCodePoint(a),h=t.pixelScale,o=Bn(s,t.effects),c=Gn(l,o,h),u=t.atlas.bake((c+o.pad*2)*h,(o.th+o.pad*2)*h,f=>Hn(f,l,o,h,o.pad,o.pad+o.th/2),h);return{frame:u,x:-o.pad,y:-o.pad,w:u.w/h,h:u.h/h,advance:c}},r=new di(i,i*1.25,i,n,t);r.prepare();for(const a of e.chars??"0123456789")r.glyph(a.codePointAt(0));return r}var No=.5;function Xn(t){const e=[];for(const[s,i]of[["left",H.leftWrist],["right",H.rightWrist]]){const n=t[i*3],r=t[i*3+1],a=t[i*3+2];n!==void 0&&r!==void 0&&Number.isFinite(n)&&Number.isFinite(r)&&(a??0)>=No&&e.push({side:s,x:n,y:r})}return e}var ws=t=>ts[((t-1)%ts.length+ts.length)%ts.length],Io=["left","right"];function $n(t,e,s,i,n=()=>null,r={}){const a=[];for(const l of t){const h=n(l)??l.body;if(Array.isArray(h)){if(r.orientation==="portrait"){for(const o of Io){let c=Pr(h,o,{orientation:"portrait"});r.hold&&(c=r.hold.at(Li.key(l.id,o),c,r.t??0)),c&&a.push({player:l.id,side:o,x:c.x*s,y:c.y*i,color:ws(l.id)})}continue}for(const o of Xn(h)){const c=e(o);a.push({player:l.id,side:o.side,x:c.x*s,y:c.y*i,color:ws(l.id)})}}}return a}function pi(t,e,s,i=0){const n=t.world,r=Da(n,e,s);if(!r)return!1;const a=Math.hypot(n[0],n[1])||1,l=Math.hypot(n[2],n[3])||1,[h,o]=r;if(t.hitRadius!=null){const p=t.hitRadius+i/((a+l)/2);return h*h+o*o<=p*p}const c=-t.anchorX*t.width-i/a,u=-t.anchorY*t.height-i/l,f=(1-t.anchorX)*t.width+i/a,y=(1-t.anchorY)*t.height+i/l;return h>=c&&h<=f&&o>=u&&o<=y}function qn(t,e,s,i=0){for(const n of e)if((s===void 0||n.player===s)&&pi(t,n.x,n.y,i))return n;return null}function Oo(t){switch(t.type){case"circle":case"ring":case"star":return[t.r*2,t.r*2];case"ellipse":return[t.rx*2,t.ry*2];case"roundRect":return[t.w,t.h];case"line":return[t.length,t.lw??4];case"path":return t.r?[t.r*2,t.r*2]:[t.size,t.size]}}function zo(t){const e=t.type==="line"?0:t.stroke?(t.lw??2)/2:0,s=t.shadow?t.shadow.blur*1.5+Math.max(Math.abs(t.shadow.x??0),Math.abs(t.shadow.y??0)):0;return Math.ceil(e+s+1)}var Do=(t,e)=>e||!t.shadow?t:{...t,shadow:void 0};function Wn(t,e,s){const i=zo(e),n=e.type==="roundRect",[r,a]=n?[Math.min(e.w,e.r*2+4/s),Math.min(e.h,e.r*2+4/s)]:Oo(e),l=(r+i*2)*s,h=(a+i*2)*s;return{frame:t.bake(l,h,c=>{c.scale(s,s),c.translate(i+r/2,i+a/2),Bo(c,e,r,a)},s,i+r/2,i+a/2,i),slice:n?Math.ceil((e.r+i)*s):0,w:n?e.w:r,h:n?e.h:a}}function Bo(t,e,s,i){t.lineJoin="round",t.lineCap="round";const n=new Path2D;switch(e.type){case"circle":case"ring":n.arc(0,0,e.r,0,Math.PI*2);break;case"ellipse":n.ellipse(0,0,e.rx,e.ry,0,0,Math.PI*2);break;case"roundRect":n.roundRect(-s/2,-i/2,s,i,Math.min(e.r,s/2,i/2));break;case"star":{const o=e.points??5,c=e.r*(e.inner??.5);for(let u=0;u<o*2;u++){const f=u%2?c:e.r,y=-Math.PI/2+u*Math.PI/o;u?n.lineTo(Math.cos(y)*f,Math.sin(y)*f):n.moveTo(Math.cos(y)*f,Math.sin(y)*f)}n.closePath();break}case"line":n.moveTo(-s/2+i/2,0),n.lineTo(s/2-i/2,0);break;case"path":{const o=e.r?e.r*2/e.size:1,c=new DOMMatrix([o,0,0,o,-e.size/2*o,-e.size/2*o]);n.addPath(new Path2D(e.d),c);break}}const r=e.shadow,a=()=>{if(!r)return;const o=t.getTransform();t.shadowColor=r.color,t.shadowBlur=r.blur*o.a,t.shadowOffsetX=(r.x??0)*o.a,t.shadowOffsetY=(r.y??0)*o.a},l=()=>{t.shadowColor="transparent",t.shadowBlur=0};if(e.type==="line"){a(),t.strokeStyle=e.stroke??e.fill??"#fff",t.lineWidth=i,t.stroke(n);return}const h=e.type==="ring";if(e.outlineBelow&&e.fill&&e.stroke&&!h){a(),t.strokeStyle=e.stroke,t.lineWidth=e.lw??2,t.stroke(n),l(),t.fillStyle=e.fill,t.fill(n);return}e.fill&&!h&&(a(),t.fillStyle=e.fill,t.fill(n),l()),(e.stroke||h)&&((!e.fill||h)&&a(),h&&e.fill&&(t.fillStyle=e.fill,t.fill(n)),t.strokeStyle=e.stroke??"#fff",t.lineWidth=e.lw??2,t.stroke(n),l())}var Yn=class{constructor(){if(d(this,"ctx",null),d(this,"master",null),d(this,"buffers",new Map),d(this,"held",!1),d(this,"muted",!1),d(this,"volume",1),typeof addEventListener=="function"){const t=()=>{this.context()?.resume().catch(()=>{})};for(const e of["pointerdown","keydown","touchstart"])addEventListener(e,t,{once:!0,capture:!0})}}context(){if(this.ctx)return this.ctx;const t=globalThis.AudioContext??globalThis.webkitAudioContext;if(!t)return null;try{this.ctx=new t,this.master=this.ctx.createGain(),this.master.connect(this.ctx.destination),this.held&&this.ctx.suspend()}catch{return null}return this.ctx}async load(t,e){const s=this.context();if(!s)return;const i=await(await fetch(e)).arrayBuffer();this.buffers.set(t,await s.decodeAudioData(i))}has(t){return this.buffers.has(t)}play(t,e={}){const s=this.context(),i=this.buffers.get(t);if(!s||!i||!this.audible)return()=>{};const n=s.createBufferSource();n.buffer=i,n.loop=e.loop??!1,n.playbackRate.value=e.rate??1;const r=s.createGain();return r.gain.value=(e.volume??1)*this.volume,n.connect(r).connect(this.master),n.start(),()=>{try{n.stop()}catch{}}}tone(t,e=.25,s={}){const i=this.context();if(!(!i||!this.audible))try{const n=i.createOscillator(),r=i.createGain();n.type=s.type??"sine",n.frequency.setValueAtTime(t,i.currentTime),s.to&&n.frequency.exponentialRampToValueAtTime(s.to,i.currentTime+e),r.gain.setValueAtTime((s.volume??.12)*this.volume,i.currentTime),r.gain.exponentialRampToValueAtTime(.001,i.currentTime+e),n.connect(r).connect(this.master),n.start(),n.stop(i.currentTime+e)}catch{}}get audible(){return!this.muted&&!this.held}hold(){this.held=!0,this.ctx?.suspend().catch(()=>{})}release(){this.held=!1,this.ctx?.resume().catch(()=>{})}destroy(){this.ctx?.close().catch(()=>{}),this.ctx=null}},Uo={high:{resolution:1.5,particles:1,effects:!0,maxBlur:32},medium:{resolution:1,particles:.5,effects:!1,maxBlur:16},low:{resolution:.75,particles:.2,effects:!1,maxBlur:0}},qt=["high","medium","low"];function ue(t){const e=Uo[t];return{name:t,...e,scale:s=>s<=0?0:Math.max(1,Math.round(s*e.particles))}}var Ho=t=>qt[Math.min(qt.indexOf(t)+1,qt.length-1)],vs=(t,e)=>{if(!t.length)return NaN;const s=[...t].sort((i,n)=>i-n);return s[Math.min(s.length-1,Math.max(0,Math.floor(e*(s.length-1)+.5)))]},Go=12,Xo=t=>Ms(t,.5);function Ms(t,e=.1){const s=vs(t,e);if(!Number.isFinite(s))return 1e3/60;const i=[144,120,90,75,60,50,30];let n=60;for(const r of i)Math.abs(1e3/r-s)<Math.abs(1e3/n-s)&&(n=r);return 1e3/n}function jn(t,e){const s=e.refresh!==void 0&&Number.isFinite(e.refresh)&&e.refresh>0?e.refresh:Ms(e.intervals),i=vs(e.intervals,.5),n=vs(e.intervals,.9),r=vs(e.cpu,.5);if(!Number.isFinite(i))return t==="canvas2d"?"low":"medium";const a=h=>h<=s*1.25,l=h=>!Number.isFinite(r)||r<s*h;return t==="canvas2d"?a(n)&&l(.25)?"medium":"low":a(n)&&l(.5)?"high":a(i)?"medium":"low"}function $o(t,e){return t.length<30?!1:t.filter(i=>i>e*1.5).length/t.length>.5}var Qn="0.1.1",qo=720*3600*1e3,Wo=(t,e,s)=>`fabi-play.engine-tier:${Qn}:${t}:${e}:${s}`,Yo=(t,e,s)=>`fablee-engine-tier:${Qn}:${t}:${e}:${s}`;function jo(t,e,s=Date.now()){try{const i=JSON.parse(t?.getItem(e)??"null");if(i&&qt.includes(i.tier)&&typeof i.at=="number"&&s-i.at<qo)return typeof i.refresh=="number"&&i.refresh>0?{name:i.tier,refresh:i.refresh}:{name:i.tier}}catch{}return null}function Vn(t,e,s,i,n=Date.now()){try{t?.setItem(e,JSON.stringify(i!==void 0&&Number.isFinite(i)?{tier:s,at:n,refresh:i}:{tier:s,at:n}))}catch{}}function Qo(t=typeof location<"u"?location.search:""){const e=new URLSearchParams(t).get("tier");return qt.includes(e)?e:void 0}function Kn(t,e){const s=e?.tier;if(qt.includes(s))return t==="canvas2d"&&s==="high"?"medium":s}var Zn=t=>typeof t?.hz=="number"&&t.hz>=20&&t.hz<=240?Ms([1e3/t.hz],.5):NaN,Jn=(t,e)=>qt.indexOf(t)>=qt.indexOf(e)?t:e;function Vo(t,e,s){return t?{name:t,from:"forced"}:e?{name:s?Jn(e,s):e,from:"hint"}:s?{name:s,from:"cache"}:null}var Ko=/^\s*(<|>|[^+\-<>=\s][^+=]*?)?\s*(?:([+-])=\s*(\d*\.?\d+))?\s*$/,tr=class{constructor(t={}){d(this,"steps",[]),d(this,"labels",new Map),d(this,"end",0),d(this,"prevStart",0),d(this,"elapsed",0),d(this,"iter",0),d(this,"last",0),d(this,"delayLeft"),d(this,"_paused"),d(this,"done",!1),d(this,"rewinding",!1),d(this,"promise"),d(this,"resolve"),d(this,"repeat"),d(this,"yoyo"),d(this,"onComplete"),this.repeat=Math.floor(t.repeat??0),this.yoyo=!!t.yoyo,this.delayLeft=t.delay??0,this._paused=!!t.paused,this.onComplete=t.onComplete,this.promise=new Promise(e=>this.resolve=e)}get duration(){return this.end}get time(){return this.last}get paused(){return this._paused}get finished(){return this.done}at(t){if(t===void 0)return this.end;if(typeof t=="number")return Math.max(t,0);const e=Ko.exec(t);if(!e)throw new Error(`[engine] timeline: bad position "${t}"`);const[,s,i,n]=e,r=n?(i==="-"?-1:1)*Number(n):0;let a=this.end;if(s==="<")a=this.prevStart;else if(s&&s!==">"){const l=this.labels.get(s.trim());l===void 0?this.labels.set(s.trim(),this.end):a=l}return Math.max(a+r,0)}add(t){let e=this.steps.length;for(;e>0&&this.steps[e-1].start>t.start;)e--;return this.steps.splice(e,0,t),this.prevStart=t.start,this.end=Math.max(this.end,t.start+t.dur),this}to(t,e,s,i="quadOut"){const n=typeof i=="object"?i:{ease:i},r=typeof n.ease=="function"?n.ease:ze[n.ease??"quadOut"];return this.add({target:t,to:e,from:null,fn:null,start:this.at(n.at)+(n.delay??0),dur:Math.max(s,0),ease:r,onUpdate:n.onUpdate,p:-1})}set(t,e,s){return this.add({target:t,to:e,from:null,fn:null,start:this.at(s),dur:0,ease:ze.linear,p:-1})}call(t,e){return this.add({target:null,to:null,from:null,fn:t,start:this.at(e),dur:0,ease:ze.linear,p:-1})}label(t,e){return this.labels.set(t,this.at(e)),this}wait(t){return this.end+=Math.max(t,0),this.prevStart=this.end,this}pause(){return this._paused=!0,this}resume(){return this._paused=!1,this}stop(){this.done||(this.done=!0,this.resolve())}seek(t){const e=Math.min(typeof t=="string"&&this.labels.has(t)?this.labels.get(t):this.at(t),this.end),s=this.yoyo&&this.iter%2===1;return this.elapsed=this.iter*this.end+(s?this.end-e:e),this.render(e),this}then(t,e){return this.promise.then(t,e)}update(t){if(this._paused||this.done)return;if(this.delayLeft>0){if(this.delayLeft-=t,this.delayLeft>0)return;t=-this.delayLeft,this.delayLeft=0}const e=this.end;if(e<=0)return this.render(0),this.complete();this.elapsed+=t;const s=this.repeat<0?1/0:e*(this.repeat+1),i=Math.min(this.elapsed,s),n=i>=s?this.repeat:Math.floor(i/e);for(;this.iter<n;){const a=this.yoyo&&this.iter%2===1;this.render(a?0:e),this.iter++,this.yoyo||(this.rewinding=!0,this.render(0),this.rewinding=!1)}const r=i-n*e;this.render(this.yoyo&&n%2===1?e-r:r),i>=s&&this.complete()}complete(){this.done||(this.done=!0,this.onComplete?.(),this.resolve())}render(t){const e=this.steps;if(t>=this.last)for(let s=0;s<e.length;s++){const i=e[s];t>=i.start&&this.apply(i,t)}else for(let s=e.length-1;s>=0;s--){const i=e[s];i.p>=0&&this.apply(i,t)}this.last=t}apply(t,e){const s=t.dur>0?Math.min(Math.max((e-t.start)/t.dur,0),1):e>t.start||e===t.start&&!this.rewinding?1:0;if(s===t.p)return;if(t.p=s,t.fn){this.rewinding||t.fn();return}const i=t.target;if(i.destroyed||i._free)return;const n=t.to;if(!t.from){t.from={};for(const a in n)t.from[a]=Number(i[a]??0)}const r=t.ease(s);for(const a in n)i[a]=t.from[a]+(n[a]-t.from[a])*r;t.onUpdate?.(r)}},er=class{constructor(){d(this,"list",[]),d(this,"timelines",[])}timeline(t){const e=new tr(t);return this.timelines.push(e),e}tween(t,e,s,i="quadOut"){const n=typeof i=="object"?i:{ease:i},r=typeof n.ease=="function"?n.ease:ze[n.ease??"quadOut"];let a;const l=new Promise(h=>{const o=Object.keys(e),c=new Float64Array(o.length);o.forEach((u,f)=>c[f]=Number(e[u])),a={target:t,keys:o,to:c,from:new Float64Array(o.length),started:!1,duration:Math.max(s,0),time:0,delay:n.delay??0,ease:r,onUpdate:n.onUpdate,done:h,dead:!1}});return this.list.push(a),Object.assign(l,{stop:()=>this.finish(a)})}stopAll(t){const e=this.list;for(let s=0;s<e.length;s++)e[s].target===t&&this.finish(e[s])}get size(){return this.list.length}update(t){if(this.timelines.length){let i=0;const n=this.timelines;for(let r=0;r<n.length;r++){const a=n[r];a.update(t),a.finished||(n[i++]=a)}n.length=i}const e=this.list;if(!e.length)return;let s=0;for(let i=0;i<e.length;i++){const n=e[i];n.dead||this.step(n,t),n.dead||(e[s++]=n)}s!==e.length&&(e.length=s)}step(t,e){if(t.target.destroyed)return this.finish(t);let s=e;if(t.delay>0){if(t.delay-=e,t.delay>0)return;s=-t.delay}const i=t.keys;if(!t.started){t.started=!0;for(let a=0;a<i.length;a++)t.from[a]=Number(t.target[i[a]]??0)}t.time+=s;const n=t.duration>0?Math.min(t.time/t.duration,1):1,r=t.ease(n);for(let a=0;a<i.length;a++)t.target[i[a]]=t.from[a]+(t.to[a]-t.from[a])*r;t.onUpdate?.(r),n>=1&&this.finish(t)}finish(t){t.dead||(t.dead=!0,t.done())}clear(){for(const t of this.list)this.finish(t);this.list.length=0;for(const t of this.timelines)t.stop();this.timelines=[]}},ft=720,sr=class extends he{constructor(t,e){super(t),d(this,"paintAll",e)}draw(t,e){this.paintAll(t,e)}},Zo=class extends he{constructor(t,e){super(t),d(this,"paintAll",e)}draw(t,e){this.paintAll(t,e)}},Wt=()=>performance.now(),ir=t=>{const e=zr(t);return e&&Object.freeze(e)};async function Jo(t={}){const e=t.play??null;let s=t.canvas??null;s||(s=document.createElement("canvas"),s.style.cssText="position:fixed;inset:0;width:100%;height:100%;display:block;touch-action:none",document.body.appendChild(s));let i=li(s,{renderer:t.renderer??_o(),failIfMajorPerformanceCaveat:t.failIfMajorPerformanceCaveat,instancing:t.instancing});s=i.canvas;const n=new Set,r=new Ks(Math.min(2048,i.maxTextureSize),4);r.onPage=b=>n.add(b),r.onDrop=b=>{n.delete(b),b.texture&&i.destroyTexture(b.texture),b.texture=null};let a=gs(i);const l=new er,h=new Yn,o=new ui(r),c=new Map,u=new Map,f=new Map,y=new Map,p=new Map,x=new Set;let m=0;const g=t.tier??Qo(),k=String(i.info.renderer??""),E=(()=>{try{return globalThis.localStorage??null}catch{return null}})(),w=typeof screen<"u"?`${screen.width}x${screen.height}`:"",T=Wo(i.kind,k,w);Xr(E,T,Yo(i.kind,k,w));const _=jo(E,T),L=Vo(g,Kn(i.kind,e?.device),_?.name);let I=L?.name??"medium",R=ue(I);o.setTier(I);let O=L?.from==="hint",q=_?.name,j=_?.refresh??Zn(e?.device),B=1,It=1,G=1;const nt={atlas:r,get pixelScale(){return B},get fontGen(){return m},get effects(){return R.effects},tweens:l,frame:b=>Fs.frame(b),shape:b=>{const M=R.effects,C=M?B:-B;let S=c.get(C);S||(c.size>=8&&c.clear(),c.set(C,S=new kn(2e3)));const N=te(b);let it=S.get(b,N);return(!it||!r.valid(it.frame))&&S.set(b,it=Wn(r,Do(b,M),B),N),it},bitmapFont:b=>Fs.bitmapFont(b)};let yt=1280,Ot=null;class gi extends Qs{get width(){return yt}set width(M){}get height(){return ft}set height(M){}get safe(){const M=Math.min(yt,ft*16/9);return{x:(yt-M)/2,y:0,w:M,h:ft}}}const wt=new gi(nt),zt=()=>{const b=i.canvas,M=b.getBoundingClientRect();It=Math.max(1,M.width||b.clientWidth||innerWidth),G=Math.max(1,M.height||b.clientHeight||innerHeight),yt=ft*It/G;const C=Math.min(globalThis.devicePixelRatio||1,t.maxPixelRatio??2);if(G*C/ft<=R.resolution){const N=Math.max(1,Math.round(G*C));B=N/ft,i.resize(Math.max(1,Math.round(It*C)),N)}else B=R.resolution,i.resize(Math.round(yt*B),Math.round(ft*B));Ot&&Ot.style.setProperty("--unit",`${G/ft}px`)};addEventListener("resize",zt);const mt=b=>{I=b,R=ue(b),o.setTier(b),zt()},ut=typeof ResizeObserver<"u"?new ResizeObserver(zt):null;ut?.observe(s);let Dt=e?.backdrop==="video"?"video":"none",v=e?.view??null,P=e?.orientation==="portrait"?"portrait":"landscape",D=ir(e?.safeArea)??Or,Y=[],W=-1/0,ot=!1,jt=!1;const _t=new Set,Ye=()=>{const b=Dt==="video"?"transparent":"";document.documentElement.style.background=b,document.body.style.background=b},vt=(b,M)=>{const C=b==="video"?"video":"none",S=M??null;if(!(C===Dt&&(S===v||S&&v&&S.x===v.x&&S.y===v.y&&S.w===v.w&&S.h===v.h))){Dt=C,v=S,Ye();for(const N of[..._t])N(Dt,v)}},Qt=[];if(e){const b=S=>{Array.isArray(S)&&(Y=S,W=Wt())},M=S=>{ot=S,Gt()},C=S=>{if(g||O)return;Number.isFinite(j)||(j=Zn(S));const N=Kn(i.kind,S);N&&(O=!0,mt(q?Jn(N,q):N))};Qt.push(e.on("start",S=>C(S?.device)),e.on("start",S=>{(S?.orientation==="portrait"||S?.orientation==="landscape")&&(P=S.orientation);const N=ir(S?.safeArea);N&&(D=N)}),e.on("start",S=>{typeof S?.muted=="boolean"&&(h.muted=S.muted)}),e.on("frame",S=>b(S?.players)),e.on("players",S=>b(S?.players)),e.on("backdrop",S=>vt(S?.backdrop,S?.view)),e.on("start",S=>vt(S?.backdrop,S?.view??e.view)),e.on("pause",()=>M(!0)),e.on("resume",()=>M(!1)),e.on("break-start",()=>M(!0)),e.on("break-done",()=>M(!1)),e.on("break-end",()=>M(!1))),h.muted=e.muted===!0}Ye();const Gt=()=>ot||jt||document.hidden?h.hold():h.release();let St=-1,Tt=[],Vt=0;const Ct=()=>Wt()-W<1e3?Y:[],de=b=>e?e.toScreen(b):Fi(v,b),bi=new Li,pe=()=>{if(St===Vt)return Tt;St=Vt;const b=P==="portrait",M=Dt==="video"&&!b||!e?.smoothedBody?()=>null:C=>e.smoothedBody(C);return Tt=$n(Ct(),de,yt,ft,M,b?{orientation:P,hold:bi,t:Wt()}:void 0),Tt},je={x:0,y:0,w:1,h:1},ql=()=>(je.x=v?v.x*yt:0,je.y=v?v.y*ft:0,je.w=v?v.w*yt:yt,je.h=v?v.h*ft:ft,je),Wl=b=>{const M=b.alpha??1,C=b.tags?new ci(r,b):null;C&&x.add(C);const S=typeof b.tags=="function"?b.tags:N=>String(N);return(N,it)=>{if(Dt==="video")return;const U=ql();for(const X of Ct()){const dt=e?.smoothedBody?.(X)??X.body,tt=rs(e?.avatarOf?.(X)??X.avatar??"")??Ne;if(!o.draw(N.r,N.tex,dt,tt,U,M*it,B)||!C)continue;const Rt=S(X.id);Rt&&C.draw(N.r,N.tex,dt,tt,U,Rt,ws(X.id),M*it,B,yt,ft)}}},ki=new Set,wi=new Set,Qe=new Set;let Ss=!1,vi=0,Ce=0,Ts=0;const ye={fps:0,cpuMs:0,drawCalls:0,quads:0,filtersSkipped:0};let Cs=0,Mi=0,Ei=Wt();const Ve=[];let Rs=0;const ur=()=>({r:i,kernel:nt,tex:a});let dr=ur();const Yl=()=>{if(i.lost)return;const[b,M]=Dt==="video"||t.background===void 0?[0,0]:Bt(t.background);i.time=Ts,i.maxBlur=R.maxBlur,i.begin(b,M,B),Xt(wt.world,null,wt.x,wt.y,wt.rotation,wt.scaleX,wt.scaleY),hn(dr,wt,wt.alpha,wt.tint);const C=i.end();ye.drawCalls=C.drawCalls,ye.quads=C.quads,ye.filtersSkipped=C.filtersSkipped},pr=b=>{if(!Ss)return;vi=requestAnimationFrame(pr);const M=Math.min(Math.max((b-Ce)/1e3,0),.1);Ce&&Ve.push(b-Ce),Ce=b,Vt++;const C=Wt(),S=ot||jt;if(!S){Ts+=M,l.update(M);for(const N of Qe)N.destroyed||N.update(M);for(const N of ki)N(M,Ts)}for(const N of wi)N(M);wt.sweep();for(const N of Qe)N.destroyed&&Qe.delete(N);if(i.lost?(Rs||(Rs=b),b-Rs>3e3&&jl()):(Rs=0,Yl()),Cs++,Mi+=Wt()-C,C-Ei>=1e3&&(ye.fps=Math.round(Cs*1e3/(C-Ei)),ye.cpuMs=Math.round(Mi/Math.max(Cs,1)*100)/100,e?.reportStats?.({fps:ye.fps,renderer:i.kind,tier:I}),Cs=0,Mi=0,Ei=C),Ve.length>=180){const N=Number.isFinite(j)?j:Ms(Ve);!g&&!S&&$o(Ve,N)&&I!=="low"&&(mt(Ho(I)),q=I,Vn(E,T,I,Number.isFinite(j)?j:void 0),console.info(`[engine] slow frames: tier ${I}`)),Ve.length=0}},jl=()=>{const b=hi(i.canvas),M=ei(b);if(M){console.warn("[engine] WebGL context lost for good: switching to Canvas 2D"),i.destroy(),i=M;for(const C of n)C.texture=null;for(const C of r.pages)n.add(C.surface);a=gs(i),dr=ur(),ut?.disconnect(),ut?.observe(b),zt()}},yr=()=>{Gt(),document.hidden||(Ce=0)};document.addEventListener("visibilitychange",yr);const mr=()=>{m++;for(const b of x)b.drop()};if(document.fonts?.addEventListener?.("loadingdone",mr),zt(),!L&&t.probe!==!1&&(Number.isFinite(j)||(j=Xo(await tl(Go))),!O)){R=ue("high"),zt();const b=await el(i,r,()=>a,()=>B,yt,()=>O);if(b.refresh=j,!O){const M=jn(i.kind,b);Vn(E,T,M,j),q=M,mt(M)}}const Fs={stage:wt,get tier(){return R},get renderer(){return i},get canvas(){return i.canvas},get pixelScale(){return B},get backdrop(){return Dt},get view(){return v},get orientation(){return P},get safeArea(){return D},get paused(){return ot||jt},sound:h,stats:ye,get time(){return Ts},get supports(){const b=i.support;return{filters:b.filters,blur:b.filters&&R.maxBlur>0,shaders:b.shaders,maxBlur:b.filters?R.maxBlur:0,tiers:{high:{maxBlur:ue("high").maxBlur},medium:{maxBlur:ue("medium").maxBlur},low:{maxBlur:ue("low").maxBlur}}}},sprite:(b,M)=>new we(nt,b,M),shape:(b,M)=>new He(nt,b,M),text:(b,M)=>new qe(nt,b,M),group:b=>new Qs(nt).set(b??{}),particles(b,M={}){const C=typeof b=="object"&&"type"in b?nt.shape(b).frame:b,S=new pn(nt,C,M),{max:N,blend:it,gravity:U,drag:X,...dt}=M;return S.set(dt),Qe.add(S),S},tween:(b,M,C,S)=>l.tween(b,M,C,S),bake(b,M,C,S,N){return f.set(b,{w:M,h:C,draw:S,origin:N}),u.delete(b),Fs.frame(b)},frame(b){const M=u.get(b);if(M&&r.valid(M)&&(M.gen===0||M.scale===B))return M;const C=f.get(b);if(C){const S=B,N=r.bake(C.w*S,C.h*S,it=>(it.scale(S,S),C.draw(it)),S,C.origin?.x??0,C.origin?.y??0);return u.set(b,N),N}if(M)return M;throw new Error(`[engine] no frame "${b}": load it or bake it first`)},async load(b){await Promise.all(Object.entries(b).map(([M,C])=>Vl(M,C)))},hands:b=>b===void 0?pe():pe().filter(M=>M.player===b),touched(b,M,C={}){return b.updateWorld(),qn(b,pe(),M,C.padding??0)},hits(b,M,C,S=0){return b.updateWorld(),pi(b,M,C,S)},avatars:(b={})=>new sr(nt,Wl(b)),handMarkers(b={}){const M=b.radius??36,C=b.look??"auto",S=new Float64Array(6),N=Math.max(M*.12,3),it={type:"ring",r:M,lw:N,fill:"rgba(251,231,184,0.3)",stroke:"#ffffff"},U={type:"ring",r:M,lw:N*1.8,stroke:$e,shadow:{color:$e,blur:M*.2}},X=(me,Mt,Re,Ai,Ls,xe)=>{const Ps=Mt.w/Mt.scale;Xt(S,null,Re-Ps/2,Ai-Ps/2,0,1,1),me.r.quad(me.tex(Mt.surface),Mt,S,Ps,Ps,Ls,xe,"normal")},dt=me=>{let Mt=null,Re=!1;return()=>(Mt&&r.valid(Mt.frame)&&Mt.frame.scale===B&&Re===R.effects?Mt:(Re=R.effects,Mt=nt.shape(me))).frame},tt=dt(it),Rt=dt(U);return new Zo(nt,(me,Mt)=>{const Re=C==="video"||C==="auto"&&Dt==="video",Ai=tt(),Ls=Re?Rt():null;for(const xe of pe())Ls&&X(me,Ls,xe.x,xe.y,16777215,Mt),X(me,Ai,xe.x,xe.y,Bt(xe.color)[0],Mt)})},timeline:b=>l.timeline(b),animation(b,M){const C=typeof b=="string"?Ql(b):{frames:b},S=new fe(nt,C,M);return Qe.add(S),S},bitmapFont(b,M){if(!M){const S=y.get(b);if(!S)throw new Error(`[engine] no bitmap font "${b}": load or make it first`);return S}const C="data"in M?xr(ks(M.data),M.pages):Po(nt,M);return y.set(b,C),C},players:()=>Ct(),onFrame(b){return ki.add(b),()=>{ki.delete(b)}},onRender(b){return wi.add(b),()=>{wi.delete(b)}},onBackdrop(b){return _t.add(b),()=>{_t.delete(b)}},get hud(){return Ot||(Ot=document.createElement("div"),Ot.style.cssText="position:fixed;inset:0;pointer-events:none;overflow:hidden",document.body.appendChild(Ot),zt()),Ot},random:(b=0,M=1)=>b+Math.random()*(M-b),start(){Ss||(Ss=!0,Ce=0,vi=requestAnimationFrame(pr))},pause(){jt=!0,Gt()},resume(){jt=!1,Gt()},destroy(){Ss=!1,cancelAnimationFrame(vi),Qt.forEach(b=>b()),removeEventListener("resize",zt),ut?.disconnect(),document.removeEventListener("visibilitychange",yr),document.fonts?.removeEventListener?.("loadingdone",mr),l.clear(),Va(nt),h.destroy(),i.destroy(),Ot?.remove()}};function Ql(b){const M=p.get(b);if(M)return M;const C=[...new Set([...u.keys(),...f.keys()])].filter(S=>S.startsWith(b)).sort(Za);if(!C.length)throw new Error(`[engine] no animation or frames "${b}\u2026"`);return{frames:C}}async function Vl(b,M){const C=M.split("?")[0].split(".").pop().toLowerCase();if(["mp3","ogg","wav","m4a","aac","webm"].includes(C))return h.load(b,M);if(["woff","woff2","ttf","otf"].includes(C)){const U=new FontFace(b,`url(${M})`);document.fonts.add(await U.load()),m++;return}const S=new URL(M,location.href);if(C==="fnt")return gr(b,ks(await(await fetch(M)).text()),S);if(C==="json"){const U=await(await fetch(M)).json();if(Array.isArray(U.chars)&&!U.frames)return gr(b,ks(U),S);const X=await yi(new URL(U.meta?.image??M.replace(/\.json$/,".png"),S).href);Kl(b,U,ls(X));return}const N=await yi(M),it=ls(N);n.add(it),u.set(b,{surface:it,x:0,y:0,w:N.width,h:N.height,scale:1,gen:0,ox:0,oy:0,margin:0})}function xr(b,M){return Lo(b,M.map(C=>{const S=ls(C);return n.add(S),S}))}async function gr(b,M,C){y.set(b,xr(M,await Promise.all(M.pages.map(S=>yi(new URL(S,C).href)))))}function Kl(b,M,C){n.add(C);const S=Array.isArray(M.frames)?M.frames:Object.entries(M.frames).map(([U,X])=>({...X,filename:U})),N=[],it=[];for(const U of S){const X=U.frame,dt=U.filename.replace(nr,"");U.rotated&&console.warn(`[engine] ${b}/${dt} is rotated: export without rotation`);const tt={surface:C,x:X.x,y:X.y,w:X.w,h:X.h,scale:1,gen:0,ox:0,oy:0,margin:0};U.trimmed&&U.sourceSize&&U.spriteSourceSize&&(tt.sw=U.sourceSize.w,tt.sh=U.sourceSize.h,tt.tx=U.spriteSourceSize.x,tt.ty=U.spriteSourceSize.y);const Rt=U.scale9Borders;Rt&&(tt.slice=[Rt.y,(tt.sw??X.w)-Rt.x-Rt.w,(tt.sh??X.h)-Rt.y-Rt.h,Rt.x]),u.set(`${b}/${dt}`,tt),N.push(`${b}/${dt}`),it.push((U.duration??0)/1e3)}for(const[U,X]of Object.entries(M.animations??{}))p.set(`${b}/${U}`,{frames:X.map(dt=>`${b}/${dt.replace(nr,"")}`)});for(const U of M.meta?.frameTags??[]){const X=[];for(let tt=U.from;tt<=U.to;tt++)X.push(tt);U.direction==="reverse"&&X.reverse(),U.direction==="pingpong"&&X.push(...X.slice(1,-1).reverse());const dt=X.every(tt=>it[tt]>0);p.set(`${b}/${U.name}`,{frames:X.map(tt=>N[tt]),...dt?{durations:X.map(tt=>it[tt])}:{}})}}return Fs}var nr=/\.(png|webp|jpe?g|gif|bmp)$/i;function yi(t){return new Promise((e,s)=>{const i=new Image;i.onload=()=>e(i),i.onerror=()=>s(new Error(`[engine] image did not load: ${t}`)),i.src=t})}function tl(t){return new Promise(e=>{const s=[];let i=0;const n=r=>{i&&s.push(r-i),i=r,s.length<t?requestAnimationFrame(n):e(s)};requestAnimationFrame(n)})}async function el(t,e,s,i,n,r=()=>!1){const a=i(),l=Wn(e,{type:"star",r:30,fill:"#ffd23f",stroke:"#3a2a10",lw:3},a).frame,h=[],o=[],c=new Float64Array(6),u=.004,f=t.kind==="canvas2d"?t.canvas.getContext("2d"):null,y=Wt();let p=0;return await new Promise(x=>{const m=g=>{p&&g-y>250&&h.push(g-p),p=g;const k=Wt();t.begin(0,0,a);const E=s();for(let w=0;w<300;w++){const T=g/1e3+w;Xt(c,null,w*37%n,w*53%ft,T,1,1),t.quad(E(l.surface),l,c,l.w/a,l.h/a,16777215,u,"normal")}for(let w=0;w<40;w++)t.ellipse(100+w*20,300,20,14,w,16746496,u),t.stroke([100+w*20,400,120+w*20,460,100+w*20,520],3,18,3368703,u,!1);t.end(),f?.getImageData(0,0,1,1),g-y>250&&o.push(Wt()-k),g-y<750&&!r()?requestAnimationFrame(m):(t.begin(0,0,a),t.end(),x())};requestAnimationFrame(m)}),{intervals:h,cpu:o}}var sl=64,rr=32,il=0,nl=`fabi-cm-${Math.random().toString(36).slice(2,7)}-`,ar=new Set,or=(t,e)=>{ar.has(t)||(ar.add(t),console.warn(e))},rl=t=>new al(t),al=class{constructor(t){d(this,"r",t),d(this,"css","none"),d(this,"plans",new kn(sl)),d(this,"buf",new Float64Array(64)),d(this,"keys",[]),d(this,"classes",new Map),d(this,"live",new Set),d(this,"svgs",new Map),d(this,"t",0),d(this,"cur",null),d(this,"svgFn",e=>this.svg(e)),d(this,"scr",[]),d(this,"flip",0)}chain(t,e){var s;const i=this.r;let n=this.buf;n[0]=i.scale,n[1]=i.maxBlur;let r=2;for(let p=0;p<e.length;p++){const x=e[p];if(r+22>n.length){const g=new Float64Array(n.length*2);g.set(n),n=this.buf=g}let m=this.classes.get(x.constructor);m===void 0&&this.classes.set(x.constructor,m=this.classes.size),n[r++]=m,n[r++]=x.enabled?1:0,x.params&&(r=x.params(n,r))}const a=(s=this.keys)[r]??(s[r]=new Float64Array(r));for(let p=0;p<r;p++)a[p]=n[p];const l=te(a);let h=this.plans.get(a,l);h||this.plans.set(a,h=this.plan(e),l);for(let p=0;p<h.svgs.length;p++){const x=h.svgs[p];x.used<0&&this.attach(x),x.used=this.t}i.skipped+=h.skip;let o=t;const c=i.rx0,u=i.ry0,f=i.rx1-c,y=i.ry1-u;for(let p=0;p<h.paints.length;p++)h.parts[p]&&(o=this.bake(o,h.parts[p])),e[h.paints[p]].paint2d(o.getContext("2d"),c,u,f,y);return this.css=h.parts[h.paints.length]||"none",o}tick(){const t=++this.t;if(!(t%rr||!this.live.size))for(const e of this.live)t-e.used>rr&&this.detach(e)}destroy(){for(const t of this.live)this.detach(t);this.plans.clear()}svg(t){if(typeof document>"u"||!document.body)return null;const e=Array.from({length:20},(i,n)=>t[n]??0).join(" ");let s=this.svgs.get(e);if(!s){const i="http://www.w3.org/2000/svg",n=document.createElementNS(i,"svg");n.setAttribute("width","0"),n.setAttribute("height","0"),n.setAttribute("aria-hidden","true"),n.style.position="absolute";const r=document.createElementNS(i,"filter"),a=nl+ ++il;r.setAttribute("id",a),r.setAttribute("color-interpolation-filters","sRGB");const l=document.createElementNS(i,"feColorMatrix");l.setAttribute("type","matrix"),l.setAttribute("values",e),r.append(l),n.append(r),this.attach(s={key:e,id:a,el:n,used:this.t})}return this.cur.svgs.push(s),`url(#${s.id})`}attach(t){document.body.append(t.el),this.live.add(t),this.svgs.has(t.key)||this.svgs.set(t.key,t)}detach(t){t.el.remove(),t.used=-1,this.live.delete(t),this.svgs.get(t.key)===t&&this.svgs.delete(t.key)}plan(t){const e=this.r,s=this.cur={parts:[],paints:[],skip:0,svgs:[]};let i="";for(let n=0;n<t.length;n++){const r=t[n];if(!r.enabled)continue;if(r.kind===$s){s.skip++,or("shader","[engine] shader() filters are WebGL only: on Canvas 2D they are skipped (check engine.supports.shaders)");continue}const a=e.support.filters&&r.css?r.css(e.scale,e.maxBlur,this.svgFn):null;a!==null?i+=i?` ${a}`:a:r.paint2d?(s.parts.push(i),s.paints.push(n),i=""):(s.skip++,or("css","[engine] this browser's Canvas 2D has no ctx.filter: colour filters, blur and shadows are skipped (tint works; check engine.supports.filters)"))}return s.parts.push(i),s}bake(t,e){const s=this.r,i=this.flip^=1;let n=this.scr[i];(!n||n.width!==s.canvas.width||n.height!==s.canvas.height)&&(n=this.scr[i]=document.createElement("canvas"),n.width=s.canvas.width,n.height=s.canvas.height);const r=n.getContext("2d"),a=s.rx0,l=s.ry0,h=s.rx1-a,o=s.ry1-l;return r.clearRect(a,l,h,o),r.filter=e,r.drawImage(t,a,l,h,o,a,l,h,o),r.filter="none",n}},ol=64,Es=17,ll=t=>`${oi}
|
|
49
|
-
uniform sampler2D uTexture;
|
|
50
|
-
uniform mat4 uM[${t}];
|
|
51
|
-
uniform vec4 uO[${t}];
|
|
52
|
-
uniform int uK;
|
|
53
|
-
varying vec2 vUv;
|
|
54
|
-
varying vec4 vColor;
|
|
55
|
-
void main() {
|
|
56
|
-
vec4 c = texture2D(uTexture, vUv);
|
|
57
|
-
if (c.a > 0.0) c.rgb /= c.a;
|
|
58
|
-
for (int i = 0; i < ${t}; i++) {
|
|
59
|
-
if (i >= uK) break;
|
|
60
|
-
c = clamp(uM[i] * c + uO[i], 0.0, 1.0);
|
|
61
|
-
}
|
|
62
|
-
c.rgb *= c.a;
|
|
63
|
-
gl_FragColor = c * vColor;
|
|
64
|
-
}`,hl=()=>`${oi}
|
|
65
|
-
uniform sampler2D uTexture;
|
|
66
|
-
uniform vec2 uDir;
|
|
67
|
-
uniform vec2 uOff;
|
|
68
|
-
uniform vec2 uTaps[${Es}];
|
|
69
|
-
uniform int uN;
|
|
70
|
-
uniform float uMode;
|
|
71
|
-
uniform vec4 uShadow;
|
|
72
|
-
varying vec2 vUv;
|
|
73
|
-
varying vec4 vColor;
|
|
74
|
-
void main() {
|
|
75
|
-
vec2 p = vUv + uOff;
|
|
76
|
-
vec4 c = texture2D(uTexture, p) * uTaps[0].y;
|
|
77
|
-
for (int i = 1; i < ${Es}; i++) {
|
|
78
|
-
if (i >= uN) break;
|
|
79
|
-
vec2 d = uDir * uTaps[i].x;
|
|
80
|
-
c += (texture2D(uTexture, p + d) + texture2D(uTexture, p - d)) * uTaps[i].y;
|
|
81
|
-
}
|
|
82
|
-
if (uMode > 0.5) c = uShadow * c.a;
|
|
83
|
-
gl_FragColor = c * vColor;
|
|
84
|
-
}`;function cl(t,e,s=new Float32Array(20)){for(let i=0;i<4;i++)for(let n=0;n<5;n++){let r=n===4?e[i*5+4]:0;for(let a=0;a<4;a++)r+=e[i*5+a]*t[a*5+n];s[i*5+n]=r}return t.set(s),t}var fl=t=>new ul(t),ul=class{constructor(t){d(this,"r",t),d(this,"colorProg",null),d(this,"blurProg",null),d(this,"user",new Map),d(this,"uses",0),d(this,"userErr",new Map),d(this,"scratchT",new Map),d(this,"steps",[]),d(this,"mats",[]),d(this,"counts",[]),d(this,"colorN"),d(this,"fm",new Float32Array(20)),d(this,"fm2",new Float32Array(20)),d(this,"fm3",new Float32Array(20)),d(this,"m16"),d(this,"o4"),d(this,"taps",new Float32Array(Es*2));const e=t.gl;this.colorN=Math.max(1,Math.min(8,Math.floor((e.getParameter(e.MAX_FRAGMENT_UNIFORM_VECTORS)-4)/5))),this.m16=new Float32Array(16*this.colorN),this.o4=new Float32Array(4*this.colorN)}check(t){return this.r.lost?null:(this.userProg(t,!1),this.userErr.get(t)??null)}destroy(){const t=this.r.gl;for(const e of this.scratchT.values())t.deleteTexture(e.gl),t.deleteFramebuffer(e.fb);this.scratchT.clear();for(const e of[this.colorProg,this.blurProg])e&&t.deleteProgram(e.p);for(const e of this.user.values())e.p&&t.deleteProgram(e.p.p);this.user.clear()}userProg(t,e){const s=this.user,i=s.get(t);if(i)return i.t=++this.uses,i.p;if(this.r.lost)return null;if(s.size>=ol){let r="",a=1/0;for(const[h,o]of s)o.t<a&&(a=o.t,r=h);const l=s.get(r).p;l&&this.r.gl.deleteProgram(l.p),s.delete(r),this.userErr.delete(r)}let n;try{n=this.r.build(t)}catch(r){n=null;const a=r.message;this.userErr.set(t,a),e&&console.error(`[engine] a shader filter does not compile: it is skipped.
|
|
85
|
-
${a}`)}return s.set(t,{p:n,t:++this.uses}),n}scratch(t,e){const s=this.r,i=Math.ceil(s.canvas.width/t),n=Math.ceil(s.canvas.height/t),r=t*8+e;let a=this.scratchT.get(r)??null;return a&&(a.w!==i||a.h!==n)&&(s.drop(a),a=null),a||(a=s.target(i,n,t,!0),a?this.scratchT.set(r,a):this.scratchT.delete(r)),a}pass(t,e,s,i,n=!1){const r=this.r,a=r.gl;r.flush(),r.mapped=!1,r.bindFb(i),a.viewport(0,0,i.w,i.h),n||(a.disable(a.SCISSOR_TEST),a.clearColor(0,0,0,0),a.clear(a.COLOR_BUFFER_BIT)),r.use(t);const l=i.f;a.uniform2f(t.uScale,2/(l*i.w),-2/(l*i.h));const h=Math.floor(r.rx0/l)*l,o=Math.floor(r.ry0/l)*l,c=Math.min(Math.ceil(r.rx1/l),i.w)*l,u=Math.min(Math.ceil(r.ry1/l),i.h)*l,f=1/(s*e.width),y=1/(s*e.height);r.bScis=!1,r.batch.push(h,o,c,o,c,u,h,u,h*f,1-o*y,c*f,1-u*y,4294967295,r.slotOf(e)),r.flush()}post(t){return t==="color"?this.colorProg??(this.colorProg=this.r.build(ll(this.colorN))):this.blurProg??(this.blurProg=this.r.build(hl()))}linear(t,e){const s=this.r,i=s.gl;s.bindTex(s.layerTex.get(t)??null,0);const n=e?i.LINEAR:i.NEAREST;i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MIN_FILTER,n),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MAG_FILTER,n)}chain(t,e,s){const i=this.r,n=this.steps,r=i.scale,a=i.maxBlur;let l=0;for(let u=0;u<s.length;u++){const f=s[u];if(f.enabled)if(f.kind===Hs&&f.toMatrix){(!l||n[l-1]!==null)&&(n[l]=null,(!this.mats[l]||this.mats[l].length<20*this.colorN)&&(this.mats[l]=new Float32Array(20*this.colorN)),this.counts[l]=0,l++);const y=this.mats[l-1],p=this.counts[l-1];if(p<this.colorN)f.toMatrix(this.fm),y.set(this.fm,p*20),this.counts[l-1]=p+1;else{const x=(p-1)*20;for(let m=0;m<20;m++)this.fm2[m]=y[x+m];f.toMatrix(this.fm),cl(this.fm2,this.fm,this.fm3),y.set(this.fm2,x)}}else f.kind===$s?this.userProg(f.source,!0)?n[l++]=f:i.skipped++:f.kind===Gs?Math.min(f.radius,a)*r>=.25&&(n[l++]=f):f.kind===Xs?n[l++]=f:i.skipped++}if(!l)return!1;const h=i.gl;let o=t,c=-1;for(let u=0;u<l;u++){const f=u===l-1,y=c===0?1:0,p=f?null:this.scratch(1,y);if(!f&&!p)break;const x=n[u];if(x===null){const m=this.post("color");i.use(m);const g=this.mats[u],k=this.counts[u],E=this.m16,w=this.o4;for(let T=0;T<k;T++)for(let _=0;_<4;_++){for(let L=0;L<4;L++)E[T*16+L*4+_]=g[T*20+_*5+L];w[T*4+_]=g[T*20+_*5+4]}h.uniformMatrix4fv(i.u(m,"uM"),!1,E),h.uniform4fv(i.u(m,"uO"),w),h.uniform1i(i.u(m,"uK"),k),p?this.pass(m,o,1,p):i.final(m,o,1,e)}else if(x.kind===Gs)this.blur(o,c<0,Math.min(x.radius,a)*r,p,e,null);else if(x.kind===Xs){const m=x,g=this.scratch(1,2);if(!g)break;this.blur(o,c<0,Math.max(Math.min(m.blur,a),0)*r,g,1,m);const k=p??(e<1?this.scratch(1,y):null);k?(this.pass(i.main,g.tex,1,k),this.pass(i.main,o,1,k,!0),p||i.final(i.main,k.tex,1,e)):(i.final(i.main,g.tex,1,1),i.final(i.main,o,1,1))}else{const m=x,g=this.userProg(m.source,!0);i.use(g);const k=i.canvas.width,E=i.canvas.height;h.uniform2f(i.u(g,"uResolution"),k,E),h.uniform1f(i.u(g,"uTime"),i.time),h.uniform4f(i.u(g,"uRect"),i.rx0/k,1-i.ry1/E,i.rx1/k,1-i.ry0/E);const w=m.uniforms;for(const T in w){const _=i.u(g,T);if(!_)continue;const L=w[T];typeof L=="number"?h.uniform1f(_,L):L.length===2?h.uniform2fv(_,L):L.length===3?h.uniform3fv(_,L):L.length===4?h.uniform4fv(_,L):L.length===1&&h.uniform1fv(_,L)}p?this.pass(g,o,1,p):i.final(g,o,1,e)}p&&(o=p.tex,c=y)}return i.remap(),!0}blur(t,e,s,i,n,r){const a=this.r,l=a.gl,h=this.post("blur");let o=1;for(;o<16&&s/o>8;)o*=2;e&&this.linear(t,!0);let c=t,u=1;const f=Math.sqrt(Math.max(s*s-(o*o-1)/12,0))/o,y=s>=.25?this.tapsFor(f):this.tapsFor(0);let p=!0;if(y>1){for(let m=2;m<=o&&p;m*=2){const g=this.scratch(m,0);g?(this.pass(a.main,c,u,g),c=g.tex,u=m):p=!1}const x=p?this.scratch(o,3):null;x&&(a.use(h),l.uniform2fv(a.u(h,"uTaps"),this.taps),l.uniform1i(a.u(h,"uN"),y),l.uniform2f(a.u(h,"uDir"),1/c.width,0),l.uniform2f(a.u(h,"uOff"),0,0),l.uniform1f(a.u(h,"uMode"),0),this.pass(h,c,u,x),c=x.tex)}if(a.use(h),l.uniform2fv(a.u(h,"uTaps"),this.taps),l.uniform1i(a.u(h,"uN"),y),l.uniform2f(a.u(h,"uDir"),0,1/c.height),r){const x=r.opacity,m=r.rgb;l.uniform4f(a.u(h,"uShadow"),(m>>16&255)/255*x,(m>>8&255)/255*x,(m&255)/255*x,x),l.uniform1f(a.u(h,"uMode"),1),l.uniform2f(a.u(h,"uOff"),-r.dx*a.scale/(u*c.width),r.dy*a.scale/(u*c.height))}else l.uniform1f(a.u(h,"uMode"),0),l.uniform2f(a.u(h,"uOff"),0,0);i?this.pass(h,c,u,i):a.final(h,c,u,n),e&&this.linear(t,!1)}tapsFor(t){const e=this.taps;if(e.fill(0),e[1]=1,t<.2)return 1;const s=Math.min(Math.ceil(3*t),(Es-1)*2),i=-1/(2*t*t);let n=1,r=1;for(let a=1;a<=s;a+=2){const l=Math.exp(a*a*i),h=a+1<=s?Math.exp((a+1)*(a+1)*i):0,o=l+h;e[r*2]=(a*l+(a+1)*h)/o,e[r*2+1]=o,n+=2*o,r++}for(let a=0;a<r;a++)e[a*2+1]=e[a*2+1]/n;return r}},Yt=t=>Math.min(Math.max(t,0),1),Nt=t=>Math.max(t,0),We=class{constructor(){d(this,"enabled",!0),Ut.gl=fl,Ut.c2d=rl}},ne=class extends We{constructor(t){super(),d(this,"amount",t),d(this,"kind",Hs)}params(t,e){return t[e]=this.amount,e+1}};function As(t,e,s){t.fill(0),t[0]=t[6]=t[12]=e,t[4]=t[9]=t[14]=s,t[18]=1}function _s(t,e){t.fill(0);for(let s=0;s<3;s++)for(let i=0;i<3;i++)t[s*5+i]=e[s*3+i];t[18]=1}var z=new Float64Array(9),dl=class extends ne{toMatrix(t){As(t,Nt(this.amount),0)}css(){return`brightness(${Nt(this.amount)})`}},pl=class extends ne{toMatrix(t){const e=Nt(this.amount);As(t,e,.5-.5*e)}css(){return`contrast(${Nt(this.amount)})`}},yl=class extends ne{toMatrix(t){const e=Yt(this.amount);As(t,1-2*e,e)}css(){return`invert(${Yt(this.amount)})`}},ml=class extends ne{toMatrix(t){const e=Nt(this.amount);z[0]=.213+.787*e,z[1]=.715-.715*e,z[2]=.072-.072*e,z[3]=.213-.213*e,z[4]=.715+.285*e,z[5]=.072-.072*e,z[6]=.213-.213*e,z[7]=.715-.715*e,z[8]=.072+.928*e,_s(t,z)}css(){return`saturate(${Nt(this.amount)})`}},xl=class extends ne{toMatrix(t){const e=1-Yt(this.amount);z[0]=.2126+.7874*e,z[1]=.7152-.7152*e,z[2]=.0722-.0722*e,z[3]=.2126-.2126*e,z[4]=.7152+.2848*e,z[5]=.0722-.0722*e,z[6]=.2126-.2126*e,z[7]=.7152-.7152*e,z[8]=.0722+.9278*e,_s(t,z)}css(){return`grayscale(${Yt(this.amount)})`}},gl=class extends ne{toMatrix(t){const e=1-Yt(this.amount);z[0]=.393+.607*e,z[1]=.769-.769*e,z[2]=.189-.189*e,z[3]=.349-.349*e,z[4]=.686+.314*e,z[5]=.168-.168*e,z[6]=.272-.272*e,z[7]=.534-.534*e,z[8]=.131+.869*e,_s(t,z)}css(){return`sepia(${Yt(this.amount)})`}},bl=class extends ne{get angle(){return this.amount}set angle(t){this.amount=t}toMatrix(t){const e=this.amount*Math.PI/180,s=Math.cos(e),i=Math.sin(e);z[0]=.213+s*.787-i*.213,z[1]=.715-s*.715-i*.715,z[2]=.072-s*.072+i*.928,z[3]=.213-s*.213+i*.143,z[4]=.715+s*.285+i*.14,z[5]=.072-s*.072-i*.283,z[6]=.213-s*.213-i*.787,z[7]=.715-s*.715+i*.715,z[8]=.072+s*.928+i*.072,_s(t,z)}css(){return`hue-rotate(${this.amount}deg)`}},kl=class extends ne{constructor(t,e){super(e),d(this,"c",16777215),d(this,"cs",""),this.color=t}get color(){return this.c}set color(t){this.c=Bt(t)[0],this.cs=Oe(this.c)}params(t,e){return t[e]=this.amount,t[e+1]=this.c,e+2}toMatrix(t){const e=Yt(this.amount);As(t,1-e,0),t[4]=(this.c>>16&255)/255*e,t[9]=(this.c>>8&255)/255*e,t[14]=(this.c&255)/255*e}css(){return null}paint2d(t,e,s,i,n){const r=Yt(this.amount);r<=0||(t.save(),t.setTransform(1,0,0,1,0,0),t.globalAlpha=r,t.globalCompositeOperation="source-atop",t.fillStyle=this.cs,t.fillRect(e,s,i,n),t.restore())}},wl=class extends We{constructor(t){if(super(),d(this,"kind",Hs),d(this,"values"),t.length!==20)throw new Error(`colorMatrix: 20 numbers expected (4 rows of 5), got ${t.length}`);this.values=Array.from(t)}toMatrix(t){for(let e=0;e<20;e++)t[e]=this.values[e]??0}params(t,e){for(let s=0;s<20;s++)t[e+s]=this.values[s]??0;return e+20}css(t,e,s){return s?s(this.values):null}},vl=class extends We{constructor(t){super(),d(this,"radius",t),d(this,"kind",Gs)}params(t,e){return t[e]=this.radius,e+1}pad(t){return 3*Math.min(Nt(this.radius),t)}css(t,e){return`blur(${Math.min(Nt(this.radius),e)*t}px)`}},Ml=class extends We{constructor(t,e,s,i){super(),d(this,"dx",t),d(this,"dy",e),d(this,"blur",s),d(this,"kind",Xs),d(this,"rgb",0),d(this,"a",1),this.color=i}get opacity(){return this.a}set opacity(t){this.a=Yt(t)}get color(){return this.rgb}set color(t){const[e,s]=Bt(t);this.rgb=e,this.a=s}params(t,e){return t[e]=this.dx,t[e+1]=this.dy,t[e+2]=this.blur,t[e+3]=this.rgb,t[e+4]=this.a,e+5}pad(t){return 3*Math.min(Nt(this.blur),t)+Math.max(Math.abs(this.dx),Math.abs(this.dy))}css(t,e){return`drop-shadow(${this.dx*t}px ${this.dy*t}px ${2*Math.min(Nt(this.blur),e)*t}px ${Oe(this.rgb,this.opacity)})`}},El=`#ifdef GL_FRAGMENT_PRECISION_HIGH
|
|
86
|
-
precision highp float;
|
|
87
|
-
#else
|
|
88
|
-
precision mediump float;
|
|
89
|
-
#endif
|
|
90
|
-
uniform sampler2D uTexture;
|
|
91
|
-
uniform vec2 uResolution;
|
|
92
|
-
uniform float uTime;
|
|
93
|
-
uniform vec4 uRect;
|
|
94
|
-
varying vec2 vUv;
|
|
95
|
-
varying vec4 vColor;
|
|
96
|
-
#define main fabiUserMain
|
|
97
|
-
#line 1
|
|
98
|
-
`,Al=t=>`${El}${t}
|
|
99
|
-
#undef main
|
|
100
|
-
void main() {
|
|
101
|
-
fabiUserMain();
|
|
102
|
-
gl_FragColor *= vColor.a;
|
|
103
|
-
}
|
|
104
|
-
`,_l=class extends We{constructor(t){super(),d(this,"kind",$s),d(this,"source"),d(this,"uniforms",{}),d(this,"padding"),this.source=Al(t.fragment),this.padding=t.padding??0;for(const e in t.uniforms??{}){const s=t.uniforms[e];this.uniforms[e]=typeof s=="number"?s:Float32Array.from(s)}}pad(){return Nt(this.padding)}},Sl=(t,e=1)=>new kl(t,e),Tl=t=>new dl(t),Cl=t=>new pl(t),Rl=t=>new ml(t),Fl=(t=1)=>new xl(t),Ll=(t=1)=>new gl(t),Pl=t=>new bl(t),Nl=(t=1)=>new yl(t),Il=t=>new wl(t),Ol=t=>new vl(t),zl=(t,e,s,i="rgba(0,0,0,0.5)")=>new Ml(t,e,s,i);function Dl(t){const e=new _l(t),s=Ut.live?.filters()?.check(e.source);if(s)throw new Error(`shader(): the fragment does not compile:
|
|
105
|
-
${s}`);return e}var mi="x y rotation scaleX scaleY alpha visible blend tint z hitRadius clip mask filters".split(" "),lr="frameName _frame _w _h slice autoAnchor".split(" "),Bl="fps loop speed onComplete durations".split(" "),xi=["anchorX","anchorY"],Ul=[...mi,...lr,...Bl,...xi],Hl=[...mi,...lr,...xi],Gl=[...mi,...xi],hr=t=>t instanceof fe?Ul:t instanceof we?Hl:Gl;function Xl(t){const e={},s=t;for(const i of hr(t))e[i]=s[i];return t instanceof He&&(e.spec=t.spec),t instanceof qe&&(e.text=t.text,e.style=t.style),t instanceof fe&&(e.playing=t.playing),e}function cr(t,e){const s=t;t instanceof He&&t.spec!==e.spec&&(t.spec=e.spec),t instanceof qe&&(t.text=e.text,t.style!==e.style&&(s._style=e.style,s.dirty=!0)),t instanceof fe&&t.gotoFrame(e.speed<0?t.frameCount-1:0);const i=t instanceof He||t instanceof qe,n=hr(t);for(let r=0;r<n.length;r++){const a=n[r];(!i||a!=="_frame"&&a!=="frameName")&&(s[a]=e[a])}}var fr=class{constructor(t,e={}){d(this,"factory",t),d(this,"opts",e),d(this,"stats",{live:0,free:0,created:0}),d(this,"free",[]),d(this,"states",new Map),d(this,"dead",!1)}get(t){if(this.dead)throw new Error("[engine] nodePool.get() after destroy()");let e=this.free.pop();if(e){this.stats.free--,e._free=!1;const s=this.states.get(e);cr(e,s),e.visible=s.visible,e instanceof fe&&s.playing&&e.play()}else{if(e=this.factory(),!(e instanceof he))throw new Error("[engine] a nodePool factory must return a node (engine.sprite, engine.shape, \u2026)");if(e._pool)throw new Error("[engine] a nodePool factory returned a node of another pool: make a new node in it");this.states.set(e,Xl(e)),e._pool=this,this.stats.created++}return this.stats.live++,t&&e.set(t),e}release(t){const e=this.states.get(t);if(!(!e||t.destroyed)&&!t._free){if(this.opts.max!==void 0&&this.free.length>=this.opts.max)return t.destroy();t.parent?.remove(t),t.kernel.tweens.stopAll(t),this.stats.live--,cr(t,e),t instanceof fe&&t.stop(),t.visible=!1,t._free=!0,this.opts.reset?.(t),this.free.push(t),this.stats.free++}}forget(t){const e=t;if(this.states.delete(e))if(e._free){const s=this.free.indexOf(e);s>=0&&(this.free[s]=this.free[this.free.length-1],this.free.pop()),this.stats.free--}else this.stats.live--}clear(){for(;this.free.length;)this.free[this.free.length-1].destroy()}destroy(){this.dead=!0;for(const t of[...this.states.keys()])t.destroy()}},$l=(t,e)=>new fr(t,e);return re.exports});
|
|
1
|
+
/*! @fabiplay/engine 0.9.1 (full) | Fabi Play Kit License | https://docs.fabiplay.app */(function(Zn,Re){var Ss=typeof document!="undefined"?document.currentScript:null;typeof define=="function"&&define.amd?define([],function(){return Re(Ss)}):typeof module=="object"&&module&&module.exports?module.exports=Re(Ss):Zn.FabiEngine=Re(Ss)})(typeof globalThis!="undefined"?globalThis:typeof self!="undefined"?self:this,function(Zn){"use strict";var Re={exports:{}},Ss=Re.exports,Ts=Object.defineProperty,Wa=Object.defineProperties,ja=Object.getOwnPropertyDescriptor,Ya=Object.getOwnPropertyDescriptors,Qa=Object.getOwnPropertyNames,Cs=Object.getOwnPropertySymbols,ln=Object.prototype.hasOwnProperty,Jn=Object.prototype.propertyIsEnumerable,qe=Math.pow,cn=(t,e,s)=>e in t?Ts(t,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[e]=s,A=(t,e)=>{for(var s in e||(e={}))ln.call(e,s)&&cn(t,s,e[s]);if(Cs)for(var s of Cs(e))Jn.call(e,s)&&cn(t,s,e[s]);return t},We=(t,e)=>Wa(t,Ya(e)),hn=(t,e)=>{var s={};for(var n in t)ln.call(t,n)&&e.indexOf(n)<0&&(s[n]=t[n]);if(t!=null&&Cs)for(var n of Cs(t))e.indexOf(n)<0&&Jn.call(t,n)&&(s[n]=t[n]);return s},Va=(t,e)=>{for(var s in e)Ts(t,s,{get:e[s],enumerable:!0})},Ka=(t,e,s,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of Qa(e))!ln.call(t,i)&&i!==s&&Ts(t,i,{get:()=>e[i],enumerable:!(n=ja(e,i))||n.enumerable});return t},Za=t=>Ka(Ts({},"__esModule",{value:!0}),t),p=(t,e,s)=>cn(t,typeof e!="symbol"?e+"":e,s),je=(t,e,s)=>new Promise((n,i)=>{var a=h=>{try{r(s.next(h))}catch(l){i(l)}},o=h=>{try{r(s.throw(h))}catch(l){i(l)}},r=h=>h.done?n(h.value):Promise.resolve(h.value).then(a,o);r((s=s.apply(t,e)).next())}),$n={};Va($n,{AnimatedSprite:()=>Oe,Atlas:()=>Tn,AvatarPainter:()=>Xn,AvatarsNode:()=>Sa,BitmapFont:()=>qn,DEFAULT_FONT:()=>ca,EASE:()=>fs,Group:()=>An,HALO:()=>bs,MAX_LAYERS:()=>_n,NameTags:()=>Hn,Node:()=>Ne,NodePool:()=>Oa,Particles:()=>Bi,STAGE_HEIGHT:()=>Ft,Shape:()=>ys,ShelfPacker:()=>Ui,Sound:()=>ba,Sprite:()=>Ke,TIERS:()=>fe,Text:()=>vs,Timeline:()=>Ea,Tweens:()=>Aa,avatarPortrait:()=>sl,blur:()=>oc,brightness:()=>$l,colorMatrix:()=>rc,contrast:()=>tc,createAvatarRenderer:()=>el,createEngine:()=>Ml,createRenderer:()=>Bn,dropShadow:()=>lc,grayscale:()=>sc,handsOf:()=>ya,hits:()=>Wn,hueRotate:()=>ic,invert:()=>ac,nodePool:()=>yc,packColor:()=>Ve,parseBMFont:()=>Vs,parseColor:()=>ne,pickTier:()=>ga,playerColor:()=>Ks,rendererOrder:()=>la,rng:()=>ho,saturate:()=>ec,sepia:()=>nc,shader:()=>cc,shapeBounds:()=>Gn,tier:()=>ze,tint:()=>Jl,touching:()=>ma,wrists:()=>pa}),Re.exports=Za($n);var le=typeof self!="undefined"?self:typeof window!="undefined"?window:typeof global!="undefined"?global:{},ti=33,J={nose:0,leftShoulder:11,rightShoulder:12,leftElbow:13,rightElbow:14,leftWrist:15,rightWrist:16,leftHip:23,rightHip:24,leftKnee:25,rightKnee:26,leftAnkle:27,rightAnkle:28},Ja=["3-5","6-8","9-12"],$a=t=>Ja.includes(t),tr=4,Rs=["#EE6A43","#6FA0E0","#8CC9A0","#C49BE0"],ei={"3-5":["bunny","bear","panda","penguin"],"6-8":["fox","lion","dragon","unicorn"],"9-12":["robot","astronaut","ninja","skater"]},er=ei["6-8"],si=(t,e)=>{const s=$a(e)?ei[e]:er;return s[Number.isInteger(t)&&t>=0?t%s.length:0]},ni=(t,e)=>t?{x:t.x+e.x*t.w,y:t.y+e.y*t.h}:{x:e.x,y:e.y},sr=.5,Fs={left:1.6,top:1.6,w:3.2,h:3},nr=1.2;function ir(t,e,s={}){const n=Array.isArray(t)?t:t.body;if(!Array.isArray(n))return null;const i=e==="left"?J.leftWrist:J.rightWrist,a=x=>{var g;return as(n[x*3])&&as(n[x*3+1])&&((g=n[x*3+2])!=null?g:0)>=sr?x:-1};if(a(i)<0)return null;const o=n[i*3],r=n[i*3+1];if(s.orientation!=="portrait")return ni(s.view,{x:o,y:r});if(a(J.leftShoulder)<0||a(J.rightShoulder)<0)return null;const h=J.leftShoulder*3,l=J.rightShoulder*3,c=(n[h]+n[l])/2,f=(n[h+1]+n[l+1])/2,u=J.leftHip*3,y=J.rightHip*3,d=(n[u]+n[y])/2,b=(n[u+1]+n[y+1])/2;let m=as(d)&&as(b)?Math.hypot(d-c,b-f):0;return(a(J.leftHip)<0||a(J.rightHip)<0)&&(m=Math.max(m,nr*Math.hypot(n[h]-n[l],n[h+1]-n[l+1]))),m=Math.max(m,.01),{x:ai((o-c+Fs.left*m)/(Fs.w*m)),y:ai((r-f+Fs.top*m)/(Fs.h*m))}}var ar=300,ii=class{constructor(t=ar){p(this,"holdMs",t),p(this,"last",new Map)}static key(t,e){return t*2+(e==="right"?1:0)}at(t,e,s){const n=this.last.get(t);return e?(n?(n.x=e.x,n.y=e.y,n.t=s):this.last.set(t,{x:e.x,y:e.y,t:s}),e):n?s-n.t<=this.holdMs?{x:n.x,y:n.y}:(this.last.delete(t),null):null}clear(){this.last.clear()}},rr=.25,or=Object.freeze({top:0,bottom:0,left:0,right:0});function lr(t){if(!cr(t))return;const e=s=>as(s)?Math.min(Math.max(s,0),rr):0;return{top:e(t.top),bottom:e(t.bottom),left:e(t.left),right:e(t.right)}}var kc=16/9,cr=t=>typeof t=="object"&&t!==null&&!Array.isArray(t),as=t=>typeof t=="number"&&Number.isFinite(t),ai=t=>Math.min(Math.max(t,0),1),hr=12,fr=ti*4,ur=t=>hr+t*fr,wc=ur(tr),dr=t=>t.startsWith("fabi-play.")?"fablee-play.".concat(t.slice(10)):null;function pr(t,e,s=dr(e)){if(!(!t||!s))try{const n=t.getItem(s);if(n===null)return;t.getItem(e)===null&&t.setItem(e,n),t.removeItem(s)}catch(n){}}var Ut="#4a382c",Ct="#2b2118",Qt="#1c1f2b",ri="#fbefe3",Jt="#f4897a",rs="#3a2a22",oi=[{id:"fox",name:{en:"Fox",it:"Volpe"},band:"6-8",palette:{body:"#ee6a43",limbs:"#ee6a43",belly:ri,accent:"#ffd9c2",outline:Ct,hands:"#5a3426",feet:"#5a3426"},head:"wide",ears:"pointy",face:{eyes:"dot",mouth:"cat",nose:rs,muzzle:"cheeks"},tail:"fluffy",headExtras:[],bodyExtras:[]},{id:"mascot",name:{en:"Fabi",it:"Fabi"},band:"all",special:!0,palette:{body:"#ee6a43",limbs:"#ee6a43",belly:ri,accent:"#5a3426",outline:Ct,hands:"#5a3426",feet:"#5a3426"},head:"wide",ears:"pointy",face:{eyes:"bead",mouth:"open",nose:rs,muzzle:"band",cheeks:Jt},tail:"brush",headExtras:[],bodyExtras:["star"],extraColors:["#ffd84a"]},{id:"bunny",name:{en:"Bunny",it:"Coniglietto"},band:"3-5",palette:{body:"#f9d0de",limbs:"#f9d0de",belly:"#fff6f8",accent:"#f4a0b9",outline:Ut},head:"round",ears:"long",face:{eyes:"dot",mouth:"cat",nose:"#e0607e",muzzle:"none",cheeks:Jt},tail:"pom",headExtras:[],bodyExtras:[]},{id:"bear",name:{en:"Bear",it:"Orsetto"},band:"3-5",palette:{body:"#cf9f78",limbs:"#cf9f78",belly:"#f7e0bf",accent:"#f7e0bf",outline:Ut},head:"round",ears:"round",face:{eyes:"dot",mouth:"smile",nose:rs,muzzle:"oval",cheeks:Jt},tail:"none",headExtras:[],bodyExtras:[]},{id:"cat",name:{en:"Cat",it:"Gattino"},band:"3-5",palette:{body:"#c8b6ee",limbs:"#c8b6ee",belly:"#f4eeff",accent:"#f7b3c8",outline:Ut,hands:"#f4eeff",feet:"#f4eeff"},head:"wide",ears:"pointy",face:{eyes:"big",eyeColor:"#3f9a5a",mouth:"cat",nose:"#f07a9a",muzzle:"none",cheeks:Jt},tail:"long",headExtras:["whiskers"],bodyExtras:[]},{id:"panda",name:{en:"Panda",it:"Panda"},band:"3-5",palette:{body:"#ffffff",limbs:"#6e6674",belly:"#ffffff",accent:"#6e6674",outline:Ut,ears:"#6e6674"},head:"wide",ears:"round",face:{eyes:"mask",mouth:"smile",nose:"#2f2a2c",muzzle:"none",cheeks:"#f6a3a3"},tail:"none",headExtras:[],bodyExtras:[]},{id:"penguin",name:{en:"Penguin",it:"Pinguino"},band:"3-5",palette:{body:"#6c8fca",limbs:"#6c8fca",belly:"#ffffff",accent:"#f9b95c",outline:Ut,feet:"#f9b95c"},head:"tall",ears:"none",face:{eyes:"dot",mouth:"beak",muzzle:"heart",cheeks:"#f6a3a3"},tail:"none",headExtras:[],bodyExtras:["flippers","scarf"],extraColors:["#f6907a"]},{id:"frog",name:{en:"Frog",it:"Ranocchio"},band:"3-5",palette:{body:"#8fd487",limbs:"#8fd487",belly:"#e6f7cc",accent:"#62ad62",outline:Ut},head:"wide",ears:"none",face:{eyes:"big",eyesOnTop:!0,mouth:"open",muzzle:"none",cheeks:"#f59b8f"},tail:"none",headExtras:[],bodyExtras:["flippers","spots"],extraColors:["#62ad62","#b0e6a4"]},{id:"lion",name:{en:"Lion",it:"Leoncino"},band:"6-8",alsoIn:["3-5"],palette:{body:"#f6c454",limbs:"#f6c454",belly:"#fde7b0",accent:"#fde7b0",outline:Ct},head:"round",ears:"round",face:{eyes:"dot",mouth:"cat",nose:"#8a4b2a",muzzle:"oval",cheeks:Jt},tail:"tuft",headExtras:["mane"],bodyExtras:[],extraColors:["#c8692e"]},{id:"unicorn",name:{en:"Unicorn",it:"Unicorno"},band:"6-8",palette:{body:"#fbf5ff",limbs:"#fbf5ff",belly:"#efe0ff",accent:"#fbd46a",outline:Ct,hands:"#c9a6f2",feet:"#c9a6f2"},head:"tall",ears:"unicorn",face:{eyes:"dot",mouth:"smile",muzzle:"none",cheeks:"#f7a6c8"},tail:"none",headExtras:["rainbow-mane"],bodyExtras:[],extraColors:["#f58cc0","#8fd3f4","#a98ff2"]},{id:"dragon",name:{en:"Little Dragon",it:"Draghetto"},band:"6-8",palette:{body:"#8a63d2",limbs:"#8a63d2",belly:"#fbd46a",accent:"#5fd0b5",outline:Ct},head:"wide",ears:"horns",face:{eyes:"big",eyeColor:"#3a2a6a",mouth:"teeth",muzzle:"none",cheeks:"#f59bc0"},tail:"arrow",headExtras:[],bodyExtras:["wings"]},{id:"robot",name:{en:"Robot",it:"Robot"},band:"9-12",palette:{body:"#b9c7d2",limbs:"#8b9aa6",belly:"#b9c7d2",accent:"#ee6a43",outline:Qt,hands:"#ee6a43",feet:"#6b7a86"},head:"square",ears:"antenna",face:{eyes:"screen",eyeColor:"#7ff0ff",mouth:"grill",muzzle:"none"},tail:"none",headExtras:["bolts"],bodyExtras:["panel","joints","boots"],extraColors:["#ff7a6b","#fbd46a","#7ff0ff"]},{id:"astronaut",name:{en:"Astronaut",it:"Astronauta"},band:"9-12",palette:{body:"#f4f1ec",limbs:"#f4f1ec",belly:"#f4f1ec",accent:"#ee6a43",outline:Qt,hands:"#9fb0bd",feet:"#9fb0bd"},head:"round",ears:"none",face:{eyes:"visor",mouth:"smile",muzzle:"none"},tail:"none",headExtras:["helmet"],bodyExtras:["backpack","badge","boots"],extraColors:["#c9d3db"]},{id:"dinosaur",name:{en:"Dinosaur",it:"Dinosauro"},band:"6-8",palette:{body:"#3fb3a6",limbs:"#3fb3a6",belly:"#c9f0d6",accent:"#f79a3e",outline:Ct},head:"wide",ears:"none",face:{eyes:"dot",mouth:"teeth",muzzle:"none",cheeks:"#f59b8f"},tail:"spiky",headExtras:["spikes","spots"],bodyExtras:[],extraColors:["#2b8f84","#7fd3c6"]},{id:"monkey",name:{en:"Monkey",it:"Scimmietta"},band:"6-8",palette:{body:"#7b5234",limbs:"#7b5234",belly:"#f2c9a0",accent:"#f2c9a0",outline:Ct,hands:"#f2c9a0",feet:"#f2c9a0"},head:"round",ears:"side",face:{eyes:"dot",mouth:"open",nose:"#5a3a26",muzzle:"monkey",cheeks:Jt},tail:"curl",headExtras:["tuft"],bodyExtras:[]},{id:"koala",name:{en:"Koala",it:"Koala"},band:"3-5",palette:{body:"#b7bcc6",limbs:"#b7bcc6",belly:"#eef0f3",accent:"#f4dbe2",outline:Ut},head:"wide",ears:"big-round",face:{eyes:"dot",mouth:"smile",nose:"#3b3438",muzzle:"none",cheeks:"#f4a3b0"},tail:"none",headExtras:[],bodyExtras:[]},{id:"tiger",name:{en:"Tiger",it:"Tigrotto"},band:"6-8",palette:{body:"#f9a33a",limbs:"#f9a33a",belly:"#fff1dc",accent:"#fff1dc",outline:Ct},head:"wide",ears:"round",face:{eyes:"dot",mouth:"cat",nose:"#e2607a",muzzle:"oval",cheeks:Jt},tail:"striped",headExtras:["stripes","whiskers"],bodyExtras:[],extraColors:["#3a2a22"]},{id:"owl",name:{en:"Owl",it:"Gufetto"},band:"3-5",palette:{body:"#8ec0e6",limbs:"#8ec0e6",belly:"#e3f2fc",accent:"#639cc9",outline:Ut,feet:"#f9b95c",hands:"#639cc9"},head:"tall",ears:"tufts",face:{eyes:"big",eyeColor:Ut,eyeRing:"#fde08a",mouth:"beak",muzzle:"none",cheeks:"#f6a8b4"},tail:"none",headExtras:[],bodyExtras:["feathers"]},{id:"alien",name:{en:"Alien",it:"Alieno"},band:"9-12",palette:{body:"#9ee05a",limbs:"#9ee05a",belly:"#d8f5a8",accent:"#b07cf2",outline:Qt},head:"bulb",ears:"antennae",face:{eyes:"almond",eyeColor:"#1e1838",mouth:"smirk",muzzle:"none"},tail:"none",headExtras:[],bodyExtras:["spots"],extraColors:["#7cc23e","#7cc23e"]},{id:"ghost",name:{en:"Friendly Ghost",it:"Fantasmino"},band:"6-8",palette:{body:"#e6f4ff",limbs:"#e6f4ff",belly:"#e6f4ff",accent:"#bcd9f2",outline:Ct},head:"round",ears:"none",face:{eyes:"dot",mouth:"open",muzzle:"none",cheeks:"#f7a6c8"},tail:"none",headExtras:["curl"],bodyExtras:["sheet"]},{id:"octopus",name:{en:"Octopus",it:"Polpetto"},band:"6-8",palette:{body:"#e0578a",limbs:"#e0578a",belly:"#f7b3cc",accent:"#f7b3cc",outline:Ct,hands:"#f7b3cc",feet:"#f7b3cc"},head:"tall",ears:"none",face:{eyes:"big",eyeColor:"#3a2140",mouth:"smile",muzzle:"none",cheeks:"#ffd0a0"},tail:"none",headExtras:["spots"],bodyExtras:["tentacles"],extraColors:["#f7b3cc","#f7b3cc"]},{id:"chick",name:{en:"Chick",it:"Pulcino"},band:"3-5",palette:{body:"#ffd45e",limbs:"#ffd45e",belly:"#fff2c2",accent:"#ffa04a",outline:Ut,hands:"#ffc23d",feet:"#ffa04a"},head:"round",ears:"none",face:{eyes:"dot",mouth:"beak",muzzle:"none",cheeks:Jt},tail:"none",headExtras:["eggshell"],bodyExtras:[],extraColors:["#fffaf0"]},{id:"puppy",name:{en:"Puppy",it:"Cucciolo"},band:"3-5",palette:{body:"#f4e4cf",limbs:"#f4e4cf",belly:"#fffaf2",accent:"#f29aa4",outline:Ut,ears:"#b58262",hands:"#e6caa6",feet:"#e6caa6"},head:"wide",ears:"floppy",face:{eyes:"dot",mouth:"open",nose:rs,muzzle:"oval",cheeks:Jt},tail:"curl",headExtras:["eye-spot"],bodyExtras:[]},{id:"lamb",name:{en:"Lamb",it:"Agnellino"},band:"3-5",palette:{body:"#fdf8ee",limbs:"#e3d1c2",belly:"#fffdf8",accent:"#f6bcc2",outline:Ut,skin:"#f7dccb",hands:"#a58c7e",feet:"#a58c7e"},head:"round",ears:"droopy",face:{eyes:"dot",mouth:"smile",nose:"#e591a0",muzzle:"none",cheeks:Jt},tail:"pom",headExtras:["wool"],bodyExtras:["wool"]},{id:"duckling",name:{en:"Duckling",it:"Anatroccolo"},band:"3-5",palette:{body:"#fff1a6",limbs:"#fff1a6",belly:"#fffbe0",accent:"#ff9f43",outline:Ut,feet:"#ff9f43"},head:"tall",ears:"none",face:{eyes:"dot",mouth:"bill",muzzle:"none",cheeks:Jt},tail:"none",headExtras:["curl"],bodyExtras:["flippers","scarf"],extraColors:["#86cfe0"]},{id:"shark",name:{en:"Shark",it:"Squalo"},band:"6-8",palette:{body:"#6c95c4",limbs:"#6c95c4",belly:"#eef5fb",accent:"#4c76a8",outline:Ct,hands:"#eef5fb",feet:"#4c76a8"},head:"wide",ears:"fin",face:{eyes:"dot",mouth:"jaws",muzzle:"none",cheeks:"#f59bb0"},tail:"fish",headExtras:["gills"],bodyExtras:[]},{id:"wolf",name:{en:"Wolf",it:"Lupo"},band:"6-8",palette:{body:"#8f9bb3",limbs:"#8f9bb3",belly:"#eef1f6",accent:"#f3b8c4",outline:Ct,hands:"#5a647a",feet:"#5a647a"},head:"round",ears:"pointy",face:{eyes:"dot",mouth:"open",nose:rs,muzzle:"oval",cheeks:"#f4a3b0"},tail:"fluffy",headExtras:["ruff","forehead"],bodyExtras:[],extraColors:["#636d84"]},{id:"parrot",name:{en:"Parrot",it:"Pappagallo"},band:"6-8",palette:{body:"#e8503f",limbs:"#e8503f",belly:"#ffd25a",accent:"#f6e6c4",outline:Ct,hands:"#3a9bdc",feet:"#8a7a70"},head:"round",ears:"none",face:{eyes:"big",eyeColor:Ct,eyeRing:"#ffffff",mouth:"hook",muzzle:"none",cheeks:"#ffb0a0"},tail:"plume",headExtras:["crest"],bodyExtras:["feathers"],extraColors:["#ffd25a","#3fae5a","#3a9bdc"]},{id:"ninja",name:{en:"Ninja",it:"Ninja"},band:"9-12",palette:{body:"#2f3a56",limbs:"#2f3a56",belly:"#2f3a56",accent:"#36c9bb",outline:Qt,skin:"#b07a52",hands:"#222a40",feet:"#222a40"},head:"round",ears:"none",face:{eyes:"calm",mouth:"none",muzzle:"none",brows:"#2a1d16"},tail:"none",headExtras:["ninja-hood"],bodyExtras:["belt"],extraColors:["#36c9bb","#36c9bb","#36c9bb"]},{id:"skater",name:{en:"Skater",it:"Skater"},band:"9-12",palette:{body:"#3a8fc0",limbs:"#2c3e57",belly:"#2f7aa6",accent:"#ffcf3a",outline:Qt,skin:"#f2c9a5",hair:"#7a4a2a",hands:"#f2c9a5",feet:"#eef1f5"},head:"round",ears:"human",face:{eyes:"calm",mouth:"smirk",muzzle:"none",brows:"#5a3520"},tail:"none",headExtras:["hair","cap"],bodyExtras:["pocket","joints"],extraColors:["#ff5d73"]},{id:"explorer",name:{en:"Explorer",it:"Giramondo"},band:"9-12",palette:{body:"#5f8f5b",limbs:"#5f8f5b",belly:"#5f8f5b",accent:"#d9bb7e",outline:Qt,skin:"#7a4a30",hair:"#1d1410",hands:"#7a4a30",feet:"#6b4a2a"},head:"round",ears:"human",face:{eyes:"calm",mouth:"smile",muzzle:"none",brows:"#1d1410"},tail:"none",headExtras:["curls","safari-hat"],bodyExtras:["backpack","straps","boots"],extraColors:["#e07b39","#6b4a2a"]},{id:"wizard",name:{en:"Wizard",it:"Mago"},band:"9-12",palette:{body:"#5b3fa0",limbs:"#5b3fa0",belly:"#5b3fa0",accent:"#3d5fc8",outline:Qt,skin:"#c98d62",hair:"#a8452a",hands:"#c98d62",feet:"#33255e"},head:"round",ears:"human",face:{eyes:"calm",mouth:"smile",muzzle:"none",brows:"#7a301c"},tail:"none",headExtras:["locks","wizard-hat"],bodyExtras:["robe","belt"],extraColors:["#ffd84a","#ffd84a","#ffd84a"]},{id:"knight",name:{en:"Knight",it:"Cavaliere"},band:"9-12",palette:{body:"#bcc7d3",limbs:"#8e9aa8",belly:"#dce3ea",accent:"#d8443a",outline:Qt,hands:"#6c7786",feet:"#6c7786"},head:"bucket",ears:"none",face:{eyes:"slit",eyeColor:"#bfefff",mouth:"none",muzzle:"none"},tail:"none",headExtras:["plume"],bodyExtras:["pauldrons","emblem","boots"],extraColors:["#d8443a"]},{id:"racer",name:{en:"Racer",it:"Pilota"},band:"9-12",palette:{body:"#ff6a2b",limbs:"#ff6a2b",belly:"#ffffff",accent:"#ffffff",outline:Qt,hands:"#232838",feet:"#232838"},head:"round",ears:"none",face:{eyes:"goggle",eyeColor:"#7fd6ff",mouth:"none",muzzle:"none"},tail:"none",headExtras:["stripe"],bodyExtras:["racing-stripe","boots"]},{id:"pirate",name:{en:"Pirate",it:"Pirata"},band:"9-12",palette:{body:"#f2efe6",limbs:"#2a3d6e",belly:"#f2efe6",accent:"#d94545",outline:Qt,skin:"#d9a072",hair:"#2b1a12",hands:"#d9a072",feet:"#3a2a20"},head:"round",ears:"human",face:{eyes:"calm",mouth:"smirk",muzzle:"none",brows:"#2b1a12"},tail:"none",headExtras:["locks","bandana","eye-patch"],bodyExtras:["stripes","belt","boots"],extraColors:["#d94545","#2a3d6e","#4a3426"]},{id:"diver",name:{en:"Diver",it:"Sub"},band:"9-12",palette:{body:"#1f6582",limbs:"#1f6582",belly:"#1f6582",accent:"#ffb020",outline:Qt,skin:"#e8b48a",hair:"#c98f2e",hands:"#1b4f66",feet:"#ffb020"},head:"round",ears:"human",face:{eyes:"calm",mouth:"smile",muzzle:"none",brows:"#8a5a1a"},tail:"none",headExtras:["curls","dive-mask"],bodyExtras:["tank","fins"],extraColors:["#c9d3db"]},{id:"hero",name:{en:"Hero",it:"Supereroe"},band:"9-12",palette:{body:"#3557c8",limbs:"#3557c8",belly:"#3557c8",accent:"#e0403a",outline:Qt,skin:"#5a3825",hair:"#141010",hands:"#e0403a",feet:"#e0403a"},head:"round",ears:"human",face:{eyes:"calm",mouth:"smirk",muzzle:"none",brows:"#141010"},tail:"none",headExtras:["hair","domino"],bodyExtras:["cape","emblem","boots"],extraColors:["#ffd84a"]},{id:"trex",name:{en:"T-Rex",it:"T-Rex"},band:"6-8",alsoIn:["3-5"],palette:{body:"#6cb84e",limbs:"#6cb84e",belly:"#f4e8a8",accent:"#f4e8a8",outline:Ct},head:"snout-long",ears:"none",face:{eyes:"dot",mouth:"toothy",muzzle:"none",cheeks:"#f59b8f"},tail:"thick",headExtras:["stripes"],bodyExtras:["tiny-arms","strong-legs"],extraColors:["#4a9235","#58a23f"]},{id:"fairy",name:{en:"Fairy",it:"Fatina"},band:"6-8",alsoIn:["3-5"],palette:{body:"#b99af0",limbs:"#a8693f",belly:"#b99af0",accent:"#ffd84a",outline:Ct,skin:"#a8693f",hair:"#2e1d17",hands:"#a8693f",feet:"#f58cbc"},head:"round",ears:"pixie",face:{eyes:"dot",mouth:"smile",muzzle:"none",cheeks:"#f0857a"},tail:"none",headExtras:["bun","flower-crown"],bodyExtras:["wings-fairy","petals","wand"],extraColors:["#c4ecff","#f7a8cf","#fff3a0","#ffffff"]}],_t={M:0,L:1,Q:2,C:3,Z:4},li=[2,2,4,6,0];function fn(t,e){for(const s of e)yr(t,s)}function yr(t,e){var s,n,i,a,o;if(e.k==="group"){t.save(),t.translate(e.x,e.y),e.rot&&t.rotate(e.rot),e.s!==void 0&&e.s!==1&&t.scale(e.s,e.s),e.alpha!==void 0&&(t.globalAlpha*=e.alpha),fn(t,e.items),t.restore();return}switch(t.save(),e.alpha!==void 0&&(t.globalAlpha*=e.alpha),t.beginPath(),e.k){case"circle":t.arc(e.x,e.y,Math.max(e.r,0),0,Math.PI*2);break;case"ellipse":t.ellipse(e.x,e.y,Math.max(e.rx,0),Math.max(e.ry,0),(s=e.rot)!=null?s:0,0,Math.PI*2);break;case"rect":mr(t,e);break;case"path":typeof e.d=="string"?gr(t,e.d):xr(t,e.d);break;case"line":t.moveTo((n=e.pts[0])!=null?n:0,(i=e.pts[1])!=null?i:0);for(let r=2;r+1<e.pts.length;r+=2)t.lineTo(e.pts[r],e.pts[r+1]);break}t.lineCap="round",t.lineJoin="round",e.fill&&e.k!=="line"&&(t.fillStyle=e.fill,t.fill()),e.stroke&&((a=e.lw)!=null?a:1)>0&&(t.strokeStyle=e.stroke,t.lineWidth=(o=e.lw)!=null?o:1,t.stroke()),t.restore()}function mr(t,e){const s=Math.max(0,Math.min(e.r,e.w/2,e.h/2));t.translate(e.x,e.y),e.rot&&t.rotate(e.rot);const n=-e.w/2,i=-e.h/2;t.moveTo(n+s,i),t.lineTo(n+e.w-s,i),t.quadraticCurveTo(n+e.w,i,n+e.w,i+s),t.lineTo(n+e.w,i+e.h-s),t.quadraticCurveTo(n+e.w,i+e.h,n+e.w-s,i+e.h),t.lineTo(n+s,i+e.h),t.quadraticCurveTo(n,i+e.h,n,i+e.h-s),t.lineTo(n,i+s),t.quadraticCurveTo(n,i,n+s,i),t.closePath()}function xr(t,e){for(let s=0;s<e.length;){const n=e[s++];if(n===_t.M)t.moveTo(e[s],e[s+1]);else if(n===_t.L)t.lineTo(e[s],e[s+1]);else if(n===_t.Q)t.quadraticCurveTo(e[s],e[s+1],e[s+2],e[s+3]);else if(n===_t.C)t.bezierCurveTo(e[s],e[s+1],e[s+2],e[s+3],e[s+4],e[s+5]);else if(n===_t.Z)t.closePath();else return;s+=li[n]}}function br(t){var e;if(typeof t=="string")return((e=t.match(/-?\d*\.?\d+(?:e-?\d+)?/gi))!=null?e:[]).map(Number);const s=[];for(let n=0;n<t.length;){const i=li[t[n++]];if(i===void 0)break;for(let a=0;a<i;a++)s.push(t[n+a]);n+=i}return s}function gr(t,e){var s;const n=(s=e.match(/[MLQCZ]|-?\d*\.?\d+(?:e-?\d+)?/gi))!=null?s:[];let i="",a=0;const o=()=>Number(n[a++]);for(;a<n.length;){const r=n[a];if(/[MLQCZ]/i.test(r)&&(i=r.toUpperCase(),a++,i==="Z")){t.closePath();continue}i==="M"?(t.moveTo(o(),o()),i="L"):i==="L"?t.lineTo(o(),o()):i==="Q"?t.quadraticCurveTo(o(),o(),o(),o()):i==="C"?t.bezierCurveTo(o(),o(),o(),o(),o(),o()):a++}}var ut=t=>{const e=Math.round(t*100)/100;return e===0?0:e};function pt(t,e=.5){const s=t.length;if(s<3)return[];const n=(r,h,l)=>({x:r.x+(h.x-r.x)*l,y:r.y+(h.y-r.y)*l}),i=Math.min(Math.max(e,0),.5),a=n(t[0],t[1],i),o=[_t.M,ut(a.x),ut(a.y)];for(let r=1;r<=s;r++){const h=t[(r-1)%s],l=t[r%s],c=t[(r+1)%s],f=n(h,l,1-i),u=n(l,c,i);o.push(_t.L,ut(f.x),ut(f.y),_t.Q,ut(l.x),ut(l.y),ut(u.x),ut(u.y))}return o.push(_t.Z),o}function dt(t,e=1){const s=t.length;if(s<3)return[];const n=[_t.M,ut(t[0].x),ut(t[0].y)],i=e/6;for(let a=0;a<s;a++){const o=t[(a-1+s)%s],r=t[a],h=t[(a+1)%s],l=t[(a+2)%s];n.push(_t.C,ut(r.x+(h.x-o.x)*i),ut(r.y+(h.y-o.y)*i),ut(h.x-(l.x-r.x)*i),ut(h.y-(l.y-r.y)*i),ut(h.x),ut(h.y))}return n.push(_t.Z),n}function os(t){const e=t.length;if(e<2)return[];const s=[_t.M,ut(t[0].x),ut(t[0].y)];for(let n=0;n<e-1;n++){const i=t[Math.max(n-1,0)],a=t[n],o=t[n+1],r=t[Math.min(n+2,e-1)];s.push(_t.C,ut(a.x+(o.x-i.x)/6),ut(a.y+(o.y-i.y)/6),ut(o.x-(r.x-a.x)/6),ut(o.y-(r.y-a.y)/6),ut(o.x),ut(o.y))}return s}var Ye="M0 -1 L0.29 -0.4 L0.95 -0.31 L0.47 0.15 L0.59 0.81 L0 0.5 L-0.59 0.81 L-0.47 0.15 L-0.95 -0.31 L-0.29 -0.4 Z",Mt="#ffffff",tt=[-1,1],ci="#3a2420",hi="#f2808f",un="#26324a",vr="#ffd84a",vt=(...t)=>{const e=[];for(let s=0;s+1<t.length;s+=2)e.push({x:t[s],y:t[s+1]});return e};function fi(t,e){var s,n,i,a,o,r,h;const l=t.palette,c=[],f={stroke:l.outline,lw:e},u=x=>t.headExtras.includes(x),y=(x,g)=>{var v,_;return(_=(v=t.extraColors)==null?void 0:v[x])!=null?_:g};if(u("mane")){for(let g=0;g<12;g++){const v=g/12*Math.PI*2;c.push(A({k:"circle",x:Math.cos(v)*1.02,y:Math.sin(v)*1+.04,r:.42,fill:y(0,l.accent)},f))}c.push({k:"circle",x:0,y:.04,r:1.08,fill:y(0,l.accent)})}if(u("rainbow-mane")){const x=(s=t.extraColors)!=null?s:["#f59ac0","#fbd46a","#8fd3f4"];[[.98,.05,.3,.5,-.25],[.92,.58,.26,.42,-.1],[.62,.92,.22,.32,.4]].forEach(([v,_,T,N,R],M)=>c.push(A({k:"ellipse",x:v,y:_,rx:T,ry:N,rot:R,fill:x[M%x.length]},f)))}if(u("spikes"))for(const x of[-.55,0,.55]){const g=Fe(x,1.48),v=Fe(x-.32,.86),_=Fe(x+.32,.86);c.push(A({k:"path",d:pt([v,g,_],.22),fill:l.accent},f))}if(u("curl")&&c.push(A({k:"path",d:dt([{x:-.2,y:-.9},{x:-.05,y:-1.3},{x:.32,y:-1.42},{x:.16,y:-1.18},{x:.2,y:-.9}]),fill:l.body},f)),u("wool"))for(let x=0;x<=8;x++){const g=-1.75+x/8*3.5;c.push(A({k:"circle",x:Math.sin(g)*.98,y:-Math.cos(g)*.92-.04,r:.34,fill:l.body},f))}if(u("crest")&&[-.38,0,.38].forEach((x,g)=>{const v=Fe(x,1.12);c.push(A({k:"ellipse",x:v.x,y:v.y,rx:.15,ry:.42,rot:x,fill:y(g,l.accent)},f))}),u("plume")&&c.push(A({k:"path",d:dt(vt(-.12,-.92,-.2,-1.42,.1,-1.78,.62,-1.74,.36,-1.46,.16,-.98)),fill:l.accent},f)),u("locks")&&c.push(A({k:"path",d:dt(vt(-1.14,.58,-1.24,-.2,-.86,-.98,0,-1.2,.86,-.98,1.24,-.2,1.14,.58,.8,.66,0,.2,-.8,.66)),fill:(n=l.hair)!=null?n:l.outline},f)),u("bun")&&c.push(A({k:"circle",x:.04,y:-1.14,r:.4,fill:(i=l.hair)!=null?i:l.outline},f)),u("ninja-hood"))for(const[x,g]of[[.35,.5],[.85,.42]])c.push(A({k:"ellipse",x:1+Math.cos(x)*g*.8,y:-.5+Math.sin(x)*g*.8,rx:g,ry:.11,rot:x,fill:l.accent},f));if(u("bandana"))for(const[x,g]of[[Math.PI-.5,.42],[Math.PI-1,.36]])c.push(A({k:"ellipse",x:-.98+Math.cos(x)*g*.8,y:-.36+Math.sin(x)*g*.8,rx:g,ry:.12,rot:x,fill:l.accent},f));if(u("ruff"))for(const x of tt)c.push(A({k:"path",d:pt(vt(x*.7,-.3,x*1.32,0,x*1.02,.18,x*1.26,.46,x*.86,.56,x*.98,.84,x*.4,.7),.25),fill:l.body},f));if(t.face.eyesOnTop)for(const x of tt)c.push(A({k:"circle",x:x*.46,y:-.72,r:.38,fill:l.body},f));c.push(...Ar(t,e)),c.push(kr(t,f));const d=t.face.muzzle,b=l.belly;if(d==="oval"&&c.push({k:"ellipse",x:0,y:.4,rx:.46,ry:.32,fill:b}),d==="monkey"){for(const x of tt)c.push({k:"circle",x:x*.32,y:-.04,r:.38,fill:b});c.push({k:"ellipse",x:0,y:.4,rx:.56,ry:.4,fill:b})}if(d==="heart"){for(const x of tt)c.push({k:"circle",x:x*.36,y:.02,r:.5,fill:b});c.push({k:"ellipse",x:0,y:.38,rx:.66,ry:.48,fill:b})}if(d==="disc")for(const x of tt)c.push({k:"circle",x:x*.4,y:.02,r:.44,fill:b});if(d==="cheeks")for(const x of tt)c.push({k:"ellipse",x:x*.4,y:.44,rx:.44,ry:.32,fill:b});if(d==="band"&&c.push({k:"path",d:Er(t,e),fill:b}),u("stripes")&&t.head==="snout-long"){const x=y(0,l.outline);for(const[g,v,_,T]of[[.46,-.94,.36,-.66],[.8,-.72,.62,-.5],[1,-.36,.78,-.24]])c.push({k:"line",pts:[g,v,_,T],stroke:x,lw:.11})}else if(u("stripes")){const x=y(0,l.outline);c.push({k:"line",pts:[0,-.97,0,-.66],stroke:x,lw:.13});for(const g of tt)c.push({k:"line",pts:[g*.3,-.93,g*.24,-.7],stroke:x,lw:.1}),c.push({k:"line",pts:[g*.98,-.05,g*.74,0],stroke:x,lw:.1}),c.push({k:"line",pts:[g*.94,.22,g*.74,.22],stroke:x,lw:.09})}if(u("spots")){const x=y(1,l.belly);c.push({k:"circle",x:-.55,y:-.5,r:.15,fill:x}),c.push({k:"circle",x:.58,y:-.42,r:.11,fill:x}),c.push({k:"circle",x:.22,y:-.76,r:.09,fill:x})}if(t.head==="snout-long")for(const[x,g,v]of[[-1.38,-.14,.06],[-1.14,-.22,.055]])c.push({k:"ellipse",x,y:g,rx:v,ry:v*.8,rot:-.3,fill:l.outline,alpha:.85});if(u("forehead")&&c.push({k:"path",d:dt(vt(-.62,-.66,0,-.86,.62,-.66,.26,-.36,0,-.1,-.26,-.36),.9),fill:y(0,l.accent)}),u("eye-spot")&&c.push({k:"ellipse",x:.42,y:-.06,rx:.3,ry:.33,rot:.3,fill:(a=l.ears)!=null?a:l.accent}),u("gills"))for(const x of tt)for(const g of[0,.12,.24])c.push({k:"path",d:"M".concat(x*(.66+g)," 0.06 Q").concat(x*(.6+g)," 0.22 ").concat(x*(.66+g)," 0.38"),stroke:l.accent,lw:e*.9});const m=(o=l.hair)!=null?o:l.outline;if(u("hair")&&c.push(A({k:"path",d:dt(vt(-1.02,-.06,-1.02,-.58,-.62,-1.04,.08,-1.14,.76,-.92,1.05,-.42,1,-.06,.84,-.4,.42,-.5,.06,-.4,-.34,-.56,-.74,-.38)),fill:m},f)),u("locks")&&c.push(A({k:"path",d:dt(vt(-1,-.08,-.98,-.62,-.56,-1.02,0,-1.1,.56,-1.02,.98,-.62,1,-.08,.8,-.38,.36,-.44,0,-.4,-.36,-.44,-.8,-.38)),fill:m},f)),u("bun")&&c.push(A({k:"path",d:dt(vt(-1.02,-.1,-.98,-.62,-.56,-1.02,0,-1.1,.56,-1.02,.98,-.62,1.02,-.1,.84,-.36,.5,-.56,.12,-.48,-.22,-.6,-.6,-.5,-.86,-.36)),fill:m},f)),u("curls")){for(let x=0;x<7;x++){const g=Fe(-1.3+x/6*2.6,.86);c.push(A({k:"circle",x:g.x,y:g.y,r:.3,fill:m},f))}c.push({k:"ellipse",x:0,y:-.64,rx:.8,ry:.36,fill:m})}if(u("ninja-hood")&&(c.push({k:"rect",x:0,y:0,w:1.56,h:.6,r:.28,fill:(r=l.skin)!=null?r:Mt,stroke:l.outline,lw:e*.8}),c.push(A({k:"path",d:"M-0.98 -0.42 Q0 -0.74 0.98 -0.42 L1.0 -0.62 Q0 -0.94 -1.0 -0.62 Z",fill:l.accent},f))),u("domino")){c.push(A({k:"path",d:dt(vt(-.86,-.04,-.62,-.3,-.18,-.24,0,-.16,.18,-.24,.62,-.3,.86,-.04,.6,.22,.16,.16,0,.1,-.16,.16,-.6,.22),.9),fill:l.accent},f));for(const x of tt)c.push({k:"ellipse",x:x*.38,y:0,rx:.19,ry:.13,fill:Mt})}if(c.push(...Sr(t,e)),u("brows"))for(const x of tt)c.push({k:"line",pts:[x*.72,-.5,x*.14,-.3],stroke:l.accent,lw:.16});if(t.face.brows)for(const x of tt)c.push({k:"line",pts:[x*.2,-.2,x*.54,-.28],stroke:t.face.brows,lw:.09});if(c.push(...Tr(t,e)),t.face.cheeks)for(const x of _r(t))c.push({k:"ellipse",x:x.x,y:x.y,rx:.15,ry:.1,fill:t.face.cheeks,alpha:.8});if(u("whiskers"))for(const x of tt)for(const g of[-.1,.06])c.push({k:"line",pts:[x*.62,.38+g,x*1.06,.3+g*2.2],stroke:l.outline,lw:e*.7,alpha:.75});if(u("rainbow-mane")){const x=(h=t.extraColors)!=null?h:["#f59ac0","#fbd46a","#8fd3f4"];c.push(A({k:"ellipse",x:.42,y:-.82,rx:.34,ry:.22,rot:.5,fill:x[0]},f)),c.push(A({k:"ellipse",x:.1,y:-.92,rx:.3,ry:.2,rot:.25,fill:x[1%x.length]},f))}if(t.ears==="unicorn"){const x=[{x:-.18,y:-.84},{x:.02,y:-1.72},{x:.18,y:-.84}];c.push(A({k:"path",d:pt(x,.12),fill:l.accent},f));for(const g of[-1,-1.2,-1.4]){const v=.16*((g+1.72)/.88);c.push({k:"line",pts:[-v,g+.04,v,g-.04],stroke:l.outline,lw:e*.7,alpha:.6})}}if(u("flower-crown")){const x=[y(1,"#f7a8cf"),y(2,"#fff3a0"),y(3,Mt)];for(const g of[-.84,-.28,.28,.84]){const v=Fe(g,.9);c.push({k:"ellipse",x:v.x,y:v.y,rx:.14,ry:.07,rot:g+.5,fill:"#7cc76a",stroke:l.outline,lw:e*.7})}[-1.12,-.56,0,.56,1.12].forEach((g,v)=>{const _=Fe(g,.9),T=v===2?.13:.11;for(let N=0;N<5;N++){const R=g+N/5*Math.PI*2;c.push({k:"circle",x:_.x+Math.sin(R)*T,y:_.y-Math.cos(R)*T,r:T*.82,fill:x[v%x.length],stroke:l.outline,lw:e*.7})}c.push({k:"circle",x:_.x,y:_.y,r:T*.62,fill:x[v%x.length]}),c.push({k:"circle",x:_.x,y:_.y,r:T*.42,fill:l.accent})})}if(u("helmet")){for(const x of tt)c.push(A({k:"rect",x:x*1,y:.05,w:.26,h:.56,r:.12,fill:l.accent},f));c.push({k:"path",d:"M-0.62 -0.62 Q-0.3 -0.92 0.12 -0.9",stroke:Mt,lw:.1,alpha:.9})}if(u("bolts"))for(const x of tt)c.push(A({k:"rect",x:x*1.08,y:.08,w:.2,h:.44,r:.08,fill:l.accent},f));if(u("tuft")&&c.push(A({k:"path",d:dt([{x:-.26,y:-.95},{x:-.12,y:-1.22},{x:.02,y:-1.04},{x:.16,y:-1.28},{x:.28,y:-.95},{x:0,y:-.86}]),fill:l.body},f)),u("eggshell")&&c.push(A({k:"path",d:"M-0.88 -0.5 C-0.88 -1.12 -0.46 -1.42 0 -1.42 C0.46 -1.42 0.88 -1.12 0.88 -0.5 L0.66 -0.66 L0.44 -0.48 L0.22 -0.66 L0 -0.48 L-0.22 -0.66 L-0.44 -0.48 L-0.66 -0.66 Z",fill:y(0,Mt)},f)),u("wool"))for(const[x,g]of[[-.36,-.84],[.02,-.94],[.4,-.82]])c.push(A({k:"circle",x,y:g,r:.27,fill:l.body},f));if(u("stripe")&&c.push({k:"rect",x:0,y:-.64,w:.38,h:.62,r:.06,fill:l.accent}),u("eye-patch")&&(c.push({k:"line",pts:[-.97,-.5,.97,.13],stroke:l.outline,lw:.07}),c.push({k:"ellipse",x:.38,y:.02,rx:.21,ry:.19,fill:l.outline})),u("bandana")){c.push(A({k:"path",d:dt(vt(-1.05,-.22,-.96,-.72,-.5,-1.08,.1,-1.14,.72,-.96,1.04,-.56,1.05,-.22,.5,-.46,-.5,-.46)),fill:l.accent},f));for(const[x,g]of[[-.5,-.8],[.08,-.92],[.6,-.74],[-.12,-.62],[.36,-.6]])c.push({k:"circle",x,y:g,r:.06,fill:Mt,alpha:.85});c.push(A({k:"circle",x:-.98,y:-.34,r:.15,fill:l.accent},f))}if(u("cap")){for(const x of tt)c.push({k:"line",pts:[x*.98,-.2,x*.5,.82,-x*.05,.98],stroke:l.outline,lw:.06});c.push(A({k:"path",d:dt(vt(-1.1,-.16,-1.04,-.66,-.6,-1.12,0,-1.24,.6,-1.12,1.04,-.66,1.1,-.16,.5,-.4,-.5,-.4)),fill:l.accent},f)),c.push(A({k:"path",d:"M-0.74 -0.4 Q0 -0.6 0.74 -0.4 Q0.8 -0.24 0.6 -0.22 Q0 -0.36 -0.6 -0.22 Q-0.8 -0.24 -0.74 -0.4 Z",fill:l.accent},f)),c.push(A({k:"circle",x:.5,y:-.82,r:.15,fill:y(0,Mt)},f));for(const x of[-.42,-.14])c.push({k:"line",pts:[x,-1.04,x+.02,-.78],stroke:l.outline,lw:.07,alpha:.7})}if(u("safari-hat")&&(c.push(A({k:"ellipse",x:0,y:-.56,rx:1.48,ry:.3,fill:l.accent},f)),c.push(A({k:"path",d:dt(vt(-.78,-.58,-.7,-1.1,-.3,-1.38,.3,-1.38,.7,-1.1,.78,-.58,0,-.5),.8),fill:l.accent},f)),c.push({k:"path",d:"M-0.77 -0.72 Q0 -0.62 0.77 -0.72 L0.74 -0.9 Q0 -0.8 -0.74 -0.9 Z",fill:y(1,l.outline),stroke:l.outline,lw:e*.8})),u("wizard-hat")){c.push(A({k:"ellipse",x:0,y:-.62,rx:1.32,ry:.26,fill:l.accent},f)),c.push(A({k:"path",d:pt(vt(-.8,-.66,-.36,-1.5,.5,-2.2,.3,-1.46,.8,-.66),.3),fill:l.accent},f));const x=y(0,vr);for(const[g,v,_]of[[.02,-1.08,.18],[-.38,-.84,.1],[.36,-1.5,.11]])c.push({k:"group",x:g,y:v,s:_,items:[{k:"path",d:Ye,fill:x}]})}if(u("dive-mask")){for(const g of tt)c.push({k:"line",pts:[g*.7,-.04,g*1,-.12],stroke:l.outline,lw:.2},{k:"line",pts:[g*.7,-.04,g*1,-.12],stroke:l.accent,lw:.11});c.push({k:"rect",x:0,y:0,w:1.42,h:.62,r:.28,fill:"#bfe9f5",alpha:.35}),c.push({k:"rect",x:0,y:0,w:1.42,h:.62,r:.28,stroke:l.outline,lw:.2}),c.push({k:"rect",x:0,y:0,w:1.42,h:.62,r:.28,stroke:l.accent,lw:.11}),c.push({k:"path",d:"M-0.5 -0.16 Q-0.4 -0.24 -0.22 -0.24",stroke:Mt,lw:.06,alpha:.9});const x="M0.5 0.52 Q0.98 0.56 1.04 0.1 L1.12 -0.92";c.push({k:"path",d:x,stroke:l.outline,lw:.24},{k:"path",d:x,stroke:l.accent,lw:.13})}return c}function kr(t,e){var s;const n=t.headExtras.includes("ninja-hood")?t.palette.body:(s=t.palette.skin)!=null?s:t.palette.body;switch(t.head){case"round":return A({k:"circle",x:0,y:0,r:1,fill:n},e);case"wide":return A({k:"ellipse",x:0,y:.03,rx:1.12,ry:.94,fill:n},e);case"tall":return A({k:"ellipse",x:0,y:-.02,rx:.94,ry:1.04,fill:n},e);case"square":return A({k:"rect",x:0,y:0,w:2,h:1.8,r:.46,fill:n},e);case"bucket":return A({k:"path",d:pt(vt(-.94,.96,-.98,-.36,-.62,-1.04,.62,-1.04,.98,-.36,.94,.96),.42),fill:n},e);case"snout-long":return A({k:"path",d:dt(wr,.95),fill:n},e);case"bulb":return A({k:"path",d:dt([{x:0,y:-1.02},{x:.86,y:-.74},{x:1.08,y:-.12},{x:.72,y:.62},{x:0,y:.92},{x:-.72,y:.62},{x:-1.08,y:-.12},{x:-.86,y:-.74}]),fill:n},e)}}var wr=vt(.7,-.88,.12,-1.04,-.3,-.98,-.72,-.74,-1.2,-.56,-1.5,-.32,-1.6,.04,-1.44,.42,-.9,.72,-.2,.92,.5,.88,.96,.56,1.08,0,.98,-.5);function ui(t,e,s){return t.head==="snout-long"?[{x:-.36,y:-.5,k:.95},{x:.26,y:-.48,k:1.1}]:tt.map(n=>({x:n*e,y:s,k:1}))}function _r(t){return t.head==="snout-long"?vt(-.66,-.14,.66,.1):tt.map(e=>({x:e*.64,y:.3}))}function Mr(t){return t.head==="round"?{cy:0,rx:1,ry:1}:t.head==="tall"?{cy:-.02,rx:.94,ry:1.04}:{cy:.03,rx:1.12,ry:.94}}function Er(t,e){const{cy:s,rx:n,ry:i}=Mr(t),a=n-e/2,o=i-e/2,r=.15,h=Math.asin(Math.min(1,(r-s)/o)),l=Math.cos(h)*a,c=d=>Math.round(d*100)/100||0,f=[_t.M,c(-l),r],u=[[-.84*l,.02,-.53*l,.06,-.32*l,.24],[-.17*l,.11,.17*l,.11,.32*l,.24],[.53*l,.06,.84*l,.02,l,r]];for(const d of u)f.push(_t.C,...d.map(c));const y=24;for(let d=1;d<=y;d++){const b=h+(Math.PI-2*h)*d/y;f.push(_t.L,c(Math.cos(b)*a),c(s+Math.sin(b)*o))}return f.push(_t.Z),f}function Ar(t,e){var s,n,i,a,o;const r=t.palette,h={stroke:r.outline,lw:e},l=[];for(const c of tt)switch(t.ears){case"pointy":case"unicorn":{const f=t.ears==="unicorn"?.8:1,u={x:c*.3,y:-.82},y={x:c*.86,y:-.82-.62*f},d={x:c*.94,y:-.36};l.push(A({k:"path",d:pt([u,y,d],.2),fill:r.body},h));const b={x:(u.x+y.x+d.x)/3,y:(u.y+y.y+d.y)/3},m=[u,y,d].map(x=>({x:b.x+(x.x-b.x)*.55,y:b.y+(x.y-b.y)*.55+.04}));l.push({k:"path",d:pt(m,.25),fill:r.accent});break}case"round":l.push(A({k:"circle",x:c*.72,y:-.72,r:.36,fill:(s=r.ears)!=null?s:r.body},h)),r.ears||l.push({k:"circle",x:c*.74,y:-.74,r:.19,fill:r.accent});break;case"big-round":l.push(A({k:"circle",x:c*.96,y:-.46,r:.52,fill:r.body},h)),l.push({k:"circle",x:c*1,y:-.44,r:.32,fill:r.accent});break;case"long":l.push(A({k:"ellipse",x:c*.38,y:-1.42,rx:.25,ry:.68,rot:c*.14,fill:r.body},h)),l.push({k:"ellipse",x:c*.39,y:-1.36,rx:.12,ry:.48,rot:c*.14,fill:r.accent});break;case"side":l.push(A({k:"circle",x:c*1,y:.02,r:.34,fill:r.body},h)),l.push({k:"circle",x:c*1.02,y:.02,r:.2,fill:r.belly});break;case"tufts":l.push(A({k:"path",d:pt([{x:c*.3,y:-.84},{x:c*1.22,y:-1.12},{x:c*.92,y:-.42}],.16),fill:r.body},h)),l.push({k:"line",pts:[c*.62,-.78,c*1,-.98],stroke:r.accent,lw:.08});break;case"antennae":{const f={x:c*.62,y:-1.42};l.push({k:"path",d:"M".concat(c*.3," -0.8 Q").concat(c*.36," -1.2 ").concat(f.x," ").concat(f.y),stroke:r.outline,lw:e*2.6}),l.push({k:"path",d:"M".concat(c*.3," -0.8 Q").concat(c*.36," -1.2 ").concat(f.x," ").concat(f.y),stroke:r.body,lw:e*1.2}),l.push(A({k:"circle",x:f.x,y:f.y,r:.17,fill:r.accent},h));break}case"floppy":l.push(A({k:"ellipse",x:c*.96,y:.02,rx:.3,ry:.62,rot:-c*.36,fill:(n=r.ears)!=null?n:r.body},h));break;case"droopy":l.push(A({k:"ellipse",x:c*1.04,y:-.22,rx:.4,ry:.18,rot:c*.32,fill:(i=r.skin)!=null?i:r.body},h)),l.push({k:"ellipse",x:c*1.08,y:-.2,rx:.24,ry:.08,rot:c*.32,fill:r.accent});break;case"pixie":l.push(A({k:"path",d:pt(vt(c*.86,-.22,c*1.36,-.5,c*1.02,.26),.28),fill:(a=r.skin)!=null?a:r.body},h)),l.push({k:"line",pts:[c*.98,-.12,c*1.16,-.3],stroke:r.accent,lw:e*.8,alpha:.5});break;case"human":l.push(A({k:"ellipse",x:c*.98,y:.06,rx:.17,ry:.23,fill:(o=r.skin)!=null?o:r.body},h));break;case"horns":{const f=[{x:c*.3,y:-.84},{x:c*.6,y:-1.5},{x:c*.66,y:-.68}];l.push(A({k:"path",d:pt(f,.18),fill:r.accent},h));break}}return t.ears==="fin"&&l.push(A({k:"path",d:pt(vt(-.4,-.82,.2,-1.62,.46,-.78),.2),fill:r.body},h)),t.ears==="antenna"&&(l.push({k:"line",pts:[0,-.85,0,-1.42],stroke:r.outline,lw:e*2.6}),l.push({k:"line",pts:[0,-.85,0,-1.42],stroke:r.limbs,lw:e*1.2}),l.push(A({k:"circle",x:0,y:-1.5,r:.18,fill:r.accent},h))),l}function Sr(t,e){var s,n,i,a,o,r,h;const l=t.palette,c=t.face,f=[],u=l.outline,y=c.eyesOnTop?.46:.4,d=c.eyesOnTop?-.72:-.04,b=(m,x,g)=>({k:"circle",x:m,y:x,r:g,fill:Mt});switch(c.eyes){case"dot":for(const m of ui(t,y,d))f.push({k:"ellipse",x:m.x,y:m.y,rx:.12*m.k,ry:.155*m.k,fill:u}),f.push(b(m.x+.04*m.k,m.y-.06*m.k,.045*m.k));break;case"bead":for(const m of ui(t,y,d))f.push({k:"ellipse",x:m.x,y:m.y,rx:.16*m.k,ry:.22*m.k,fill:u}),f.push(b(m.x+.05*m.k,m.y-.08*m.k,.065*m.k));break;case"big":for(const m of tt)c.eyeRing&&f.push({k:"circle",x:m*y,y:d,r:.36,fill:c.eyeRing,stroke:u,lw:e*.8}),f.push({k:"circle",x:m*y,y:d,r:.25,fill:Mt,stroke:u,lw:e*.8}),f.push({k:"circle",x:m*y+m*-.03,y:d+.03,r:.14,fill:(s=c.eyeColor)!=null?s:u}),f.push(b(m*y+m*-.03+.05,d-.03,.05));break;case"mask":for(const m of tt)f.push({k:"ellipse",x:m*.4,y:0,rx:.24,ry:.32,rot:m*-.55,fill:l.limbs}),f.push({k:"circle",x:m*.4,y:-.02,r:.11,fill:Mt}),f.push({k:"circle",x:m*.39,y:-0,r:.065,fill:u});break;case"screen":f.push({k:"rect",x:0,y:0,w:1.5,h:.66,r:.26,fill:"#24323d",stroke:u,lw:e*.8});for(const m of tt)f.push({k:"ellipse",x:m*.36,y:0,rx:.2,ry:.24,fill:(n=c.eyeColor)!=null?n:"#7ff0ff",alpha:.3}),f.push({k:"ellipse",x:m*.36,y:0,rx:.12,ry:.16,fill:(i=c.eyeColor)!=null?i:"#7ff0ff"});break;case"almond":for(const m of tt)f.push({k:"ellipse",x:m*.42,y:-.02,rx:.3,ry:.2,rot:-m*.5,fill:(a=c.eyeColor)!=null?a:u}),f.push(b(m*.42-m*.07,-.08,.07));break;case"calm":for(const m of tt)f.push({k:"ellipse",x:m*.38,y:.02,rx:.085,ry:.12,fill:u}),f.push(b(m*.38+.03,-.02,.03));break;case"slit":f.push({k:"line",pts:[0,-.98,0,-.2],stroke:u,lw:e*.8,alpha:.5}),f.push({k:"rect",x:0,y:-.04,w:1.56,h:.26,r:.1,fill:un,stroke:u,lw:e*.8}),f.push({k:"rect",x:0,y:.3,w:.22,h:.46,r:.08,fill:un,stroke:u,lw:e*.8});for(const m of tt){f.push({k:"ellipse",x:m*.4,y:-.04,rx:.12,ry:.07,fill:(o=c.eyeColor)!=null?o:Mt});for(const x of[.36,.56])f.push({k:"circle",x:m*.42,y:x,r:.05,fill:u,alpha:.6})}break;case"goggle":for(const m of tt)f.push({k:"circle",x:m*.9,y:0,r:.13,fill:l.accent,stroke:u,lw:e*.8});f.push({k:"rect",x:0,y:0,w:1.66,h:.62,r:.3,fill:un,stroke:u,lw:e*.8}),f.push({k:"path",d:"M-0.6 -0.16 Q-0.42 -0.24 -0.12 -0.24",stroke:Mt,lw:.07,alpha:.8});for(const m of tt)f.push({k:"path",d:"M".concat(m*.5," 0.04 Q").concat(m*.34," -0.08 ").concat(m*.16," 0.02"),stroke:(r=c.eyeColor)!=null?r:"#7fd6ff",lw:.08});for(const m of[-.18,0,.18])f.push({k:"line",pts:[m,.56,m,.72],stroke:u,lw:e*.8,alpha:.6});break;case"visor":f.push({k:"ellipse",x:0,y:.08,rx:.8,ry:.64,fill:"#2a3f6b",stroke:u,lw:e*.8}),f.push({k:"path",d:"M-0.56 -0.14 Q-0.46 -0.4 -0.16 -0.46",stroke:Mt,lw:.08,alpha:.7});for(const m of tt)f.push({k:"ellipse",x:m*.28,y:.04,rx:.1,ry:.14,fill:(h=c.eyeColor)!=null?h:"#cfeeff"});break}return f}function Tr(t,e){const s=t.palette,n=t.face,i=[],a=n.eyes==="visor"?"#cfeeff":ci,o=e*1.05;switch(n.nose&&n.mouth!=="beak"&&(n.mouth==="cat"?i.push({k:"path",d:pt([{x:-.1,y:.22},{x:.1,y:.22},{x:0,y:.33}],.3),fill:n.nose,stroke:n.nose,lw:e*.6}):t.ears==="big-round"?i.push({k:"ellipse",x:0,y:.22,rx:.2,ry:.25,fill:n.nose}):i.push({k:"ellipse",x:0,y:.25,rx:.13,ry:.085,fill:n.nose})),n.mouth){case"smile":i.push({k:"path",d:n.eyes==="visor"?"M-0.16 0.32 Q0 0.46 0.16 0.32":"M-0.17 0.42 Q0 0.58 0.17 0.42",stroke:a,lw:o});break;case"open":i.push({k:"path",d:"M-0.21 0.4 Q0 0.46 0.21 0.4 Q0.19 0.68 0 0.68 Q-0.19 0.68 -0.21 0.4 Z",fill:a,stroke:a,lw:e*.5}),i.push({k:"ellipse",x:0,y:.6,rx:.1,ry:.06,fill:hi});break;case"cat":i.push({k:"path",d:"M-0.19 0.4 Q-0.1 0.5 0 0.37 Q0.1 0.5 0.19 0.4",stroke:a,lw:o});break;case"beak":i.push({k:"path",d:pt([{x:-.17,y:.2},{x:.17,y:.2},{x:0,y:.48}],.25),fill:s.accent,stroke:s.outline,lw:e*.8});break;case"teeth":i.push({k:"path",d:"M-0.36 0.34 Q0 0.44 0.36 0.34 Q0.28 0.66 0 0.66 Q-0.28 0.66 -0.36 0.34 Z",fill:a,stroke:a,lw:e*.5});for(const r of tt)i.push({k:"rect",x:r*.12,y:.43,w:.1,h:.1,r:.03,fill:Mt});break;case"grill":i.push({k:"rect",x:0,y:.56,w:.62,h:.2,r:.08,fill:"#24323d",stroke:s.outline,lw:e*.7});for(const r of[-.15,0,.15])i.push({k:"line",pts:[r,.51,r,.61],stroke:"#9fb0bd",lw:e*.6});break;case"tiny":i.push({k:"ellipse",x:0,y:.44,rx:.08,ry:.1,fill:a});break;case"smirk":i.push({k:"path",d:"M-0.16 0.46 Q0.06 0.54 0.22 0.38",stroke:a,lw:o});break;case"bill":i.push({k:"ellipse",x:0,y:.36,rx:.44,ry:.2,fill:s.accent,stroke:s.outline,lw:e*.8}),i.push({k:"path",d:"M-0.36 0.38 Q0 0.46 0.36 0.38",stroke:s.outline,lw:e*.7});for(const r of tt)i.push({k:"circle",x:r*.1,y:.28,r:.03,fill:s.outline});break;case"hook":i.push({k:"ellipse",x:0,y:.48,rx:.16,ry:.11,fill:ci}),i.push({k:"path",d:"M-0.3 0.12 Q0 -0.02 0.3 0.12 Q0.36 0.52 0.04 0.76 Q0.08 0.52 -0.08 0.46 Q-0.28 0.38 -0.3 0.12 Z",fill:s.accent,stroke:s.outline,lw:e*.8});break;case"toothy":{i.push({k:"path",d:"M-1.4 0.1 Q-0.5 0.36 0.5 0.2 Q0.64 0.16 0.68 0.02 Q0.78 0.28 0.52 0.38 Q-0.4 0.78 -1.3 0.26 Z",fill:a,stroke:a,lw:e*.6}),i.push({k:"ellipse",x:-.38,y:.5,rx:.24,ry:.08,fill:hi});for(const r of[.12,.27,.42,.57,.72,.86]){const h=(1-r)*(1-r)*-1.4+2*(1-r)*r*-.5+r*r*.5,l=(1-r)*(1-r)*.1+2*(1-r)*r*.36+r*r*.2-.01;i.push({k:"path",d:pt(vt(h-.08,l,h+.08,l,h,l+.14),.3),fill:Mt})}for(const r of[.3,.7]){const h=(1-r)*(1-r)*.52+2*(1-r)*r*-.4+r*r*-1.3,l=(1-r)*(1-r)*.38+2*(1-r)*r*.78+r*r*.26+.01;i.push({k:"path",d:pt(vt(h-.07,l,h+.07,l,h,l-.12),.3),fill:Mt})}break}case"jaws":{i.push({k:"path",d:"M-0.5 0.3 Q0 0.5 0.5 0.3 Q0.38 0.72 0 0.72 Q-0.38 0.72 -0.5 0.3 Z",fill:a,stroke:a,lw:e*.5});for(const r of[-.34,-.17,0,.17,.34]){const h=.3+.4*(r+.5)*(.5-r)-.01;i.push({k:"path",d:pt(vt(r-.075,h,r+.075,h,r,h+.13),.15),fill:Mt})}break}}return i}var Fe=(t,e)=>({x:Math.sin(t)*e,y:-Math.cos(t)*e}),Cr=.5,be={leftEye:2,rightEye:5,leftEar:7,rightEar:8},Pe={"3-5":{head:.75,neck:.74,arm:.3,leg:.36,hand:.19,foot:1.2,shoulderMin:.4,shoulderPad:.07,hipMin:.5,hipPad:.22,bottom:.26,bulge:1.12,armsOverHead:!0},"6-8":{head:.6,neck:.78,arm:.22,leg:.28,hand:.15,foot:1,shoulderMin:.34,shoulderPad:.04,hipMin:.4,hipPad:.16,bottom:.14,bulge:1.04,armsOverHead:!1},"9-12":{head:.5,neck:.92,arm:.17,leg:.21,hand:.125,foot:.9,shoulderMin:.36,shoulderPad:.07,hipMin:.32,hipPad:.08,bottom:.1,bulge:1,armsOverHead:!1}},Ps="6-8",di=(t,e)=>{var s;return e!==void 0&&t.band!=="all"&&((s=t.alsoIn)!=null&&s.includes(e))&&e in Pe?e:t.band in Pe?t.band:Ps},_c=Pe[Ps].head,Rr=.3,Fr=.12,Pr=.9,pi=.5,yi=.65,Lr=.35,Nr=.2,Ir=.25,$t=(t,e)=>({x:t.x-e.x,y:t.y-e.y}),xt=(t,e)=>({x:t.x+e.x,y:t.y+e.y}),ht=(t,e)=>({x:t.x*e,y:t.y*e}),Le=t=>Math.hypot(t.x,t.y),mi=(t,e)=>({x:(t.x+e.x)/2,y:(t.y+e.y)/2}),Ls=t=>{const e=Le(t);return e>1e-9?{x:t.x/e,y:t.y/e}:{x:0,y:1}},Or=(...t)=>t.every(Number.isFinite),zr=t=>Math.atan2(Math.sin(t),Math.cos(t)),Dr=(t,e,s)=>Math.min(Math.max(t,e),s);function xi(t,e,s=!1){return n=>{const i=t[n*3],a=t[n*3+1],o=t[n*3+2];return i===void 0||a===void 0||o===void 0||!Or(i,a,o)?{x:0,y:0,ok:!1}:{x:e.x+(s?1-i:i)*e.w,y:e.y+a*e.h,ok:o>=Cr}}}function dn(t,e,s={}){var n,i;const a=xi(t,e,s.mirrored),o=a(J.leftShoulder),r=a(J.rightShoulder);if(!o.ok||!r.ok)return null;const h=a(J.leftHip),l=a(J.rightHip),c=mi(o,r),f=Le($t(r,o)),u=h.ok&&l.ok;let y=Ls($t(r,o));f<1e-6&&(y={x:1,y:0});let d,b,m;if(u){const M=mi(h,l);b=Le($t(M,c)),b>=f*Ir?d=Ls($t(M,c)):(d={x:-y.y,y:y.x},d.y<0&&(d=ht(d,-1))),m=Math.max(b,f*1.15)}else d={x:-y.y,y:y.x},d.y<0&&(d=ht(d,-1)),m=f*1.15,b=m;m=Math.max(m,1e-6);const x={x:d.y,y:-d.x},g=Math.atan2(x.y,x.x),v=ht(d,-1),_=(i=Pe[(n=s.band)!=null?n:Ps])!=null?i:Pe[Ps],T=_.head*m;let N=xt(c,ht(v,T*_.neck));const R=a(J.nose);if(R.ok){const M=xt(R,ht(v,T*.15)),P=ht($t(M,N),Lr),z=Math.min(1,T*Nr/Math.max(Le(P),1e-6));N=xt(N,ht(P,z))}return{S:c,r:x,d,U:m,L:b,hipsOk:u,head:N,headR:T,headRot:g+Br(t,a,g,m),angle:g}}function Br(t,e,s,n){const i=[[be.leftEar,be.rightEar],[be.leftEye,be.rightEye]];for(const[a,o]of i){const r=e(a),h=e(o);if(!r.ok||!h.ok||!(t[a*3+2]>=yi&&t[o*3+2]>=yi)||Le($t(h,r))<n*.05)continue;const l=zr(Math.atan2(h.y-r.y,h.x-r.x)-s),c=Math.max(Math.abs(l)-Fr,0),f=Dr((Pr+pi-Math.abs(l))/pi,0,1);return Math.sign(l)*Math.min(c,Rr)*f}return 0}function bi(t,e,s,n={}){var i,a,o,r,h,l,c,f,u,y,d,b,m,x,g,v,_,T,N,R,M,P,z;const U=di(e,n.band),G=Pe[U],O=dn(t,s,We(A({},n),{band:U}));if(!O)return[];const X=xi(t,s,n.mirrored),L=e.palette,{S:lt,r:yt,d:$,U:w,L:H}=O,W=C=>e.bodyExtras.includes(C),bt=Math.max(1.2,w*.045),Z={stroke:L.outline,lw:bt},j=(C,B)=>({x:lt.x+yt.x*C+$.x*B,y:lt.y+yt.y*C+$.y*B}),se=C=>C.map(([B,Y])=>j(B,Y)),Ae=X(J.leftShoulder),At=X(J.rightShoulder),Ot=X(J.leftHip),Kt=X(J.rightHip),sn=Le($t(At,Ae)),qt=O.hipsOk?Le($t(Kt,Ot)):sn*.7,K=Math.max(sn/2+G.shoulderPad*w,G.shoulderMin*w),gt=Math.max(qt/2+G.hipPad*w,G.hipMin*w),mt=-.1*w,St=H+G.bottom*w,et=[],pe=[],it=[],De=[],ws=[],Be=(C,B,Y,st)=>{const at=B.flatMap(Pt=>[Pt.x,Pt.y]);C.push({k:"line",pts:at,stroke:L.outline,lw:Y+bt*2}),C.push({k:"line",pts:at,stroke:st,lw:Y})},Ue=G.leg*w*(W("strong-legs")?1.3:1),_s=G.arm*w*(W("tiny-arms")?.6:1),Ms=Math.max(G.arm/.22,.9);if(O.hipsOk)for(const[C,B,Y,st]of[[Ot,J.leftKnee,J.leftAnkle,-1],[Kt,J.rightKnee,J.rightAnkle,1]]){const at=X(B),Pt=X(Y);if(!at.ok)continue;const Se=xt(C,ht($,-.12*w)),zt=Pt.ok?[Se,at,Pt]:[Se,at];Be(pe,zt,Ue,L.limbs),W("joints")&&pe.push(A({k:"circle",x:at.x,y:at.y,r:.15*w*Ms,fill:L.accent},Z)),Pt.ok&&pe.push(...Gr(e,Pt,O,st,bt,G.foot))}for(const[C,B,Y,st]of[[Ae,J.leftElbow,J.leftWrist,-1],[At,J.rightElbow,J.rightWrist,1]]){const at=X(B),Pt=X(Y);if(W("pauldrons")){const Lt=xt(C,ht($,.02*w));De.push(A({k:"ellipse",x:Lt.x,y:Lt.y,rx:.25*w,ry:.17*w,rot:O.angle+st*.25,fill:L.body},Z));const Yt=xt(Lt,ht($,.05*w));De.push({k:"ellipse",x:Yt.x,y:Yt.y,rx:.17*w,ry:.07*w,rot:O.angle+st*.25,fill:L.belly})}if(!at.ok)continue;const zt=G.armsOverHead&&(at.x-lt.x)*$.x+(at.y-lt.y)*$.y<-.25*w?ws:De,nn=xt(C,ht($,.04*w));if(Be(zt,Pt.ok?[nn,at,Pt]:[nn,at],_s,L.limbs),W("joints")&&zt.push(A({k:"circle",x:at.x,y:at.y,r:.13*w*Ms,fill:L.accent},Z)),!Pt.ok)continue;const Zt=Ls($t(Pt,at)),re=xt(Pt,ht(Zt,.05*w));if(W("feathers"))for(const Lt of[-.55,0,.55]){const Yt=Math.cos(Lt),me=Math.sin(Lt)*st,Nt={x:Zt.x*Yt-Zt.y*me,y:Zt.x*me+Zt.y*Yt},oe=xt(re,ht(Nt,.16*w));zt.push(A({k:"ellipse",x:oe.x,y:oe.y,rx:.2*w,ry:.09*w,rot:Math.atan2(Nt.y,Nt.x),fill:(i=L.hands)!=null?i:L.accent},Z))}W("wand")&&st===1&&!n.portrait&&zt.push(...Wr(e,re,Ls(xt(ht(Zt,.4),$t(ht(yt,.6),$))),w,bt));const ye=G.hand*w*(W("tiny-arms")?.72:1);if(W("tiny-arms"))for(const Lt of[-.45,.45]){const Yt=Math.cos(Lt),me=Math.sin(Lt),Nt={x:Zt.x*Yt-Zt.y*me,y:Zt.x*me+Zt.y*Yt},oe=xt(re,ht(Nt,ye*.75)),xe=xt(re,ht(Nt,ye*1.6)),He={x:-Nt.y*ye*.32,y:Nt.x*ye*.32};zt.push(A({k:"path",d:pt([xt(oe,He),xe,$t(oe,He)],.2),fill:L.belly},Z))}zt.push(A({k:"circle",x:re.x,y:re.y,r:ye,fill:(a=L.hands)!=null?a:L.limbs},Z))}if(W("wings"))for(const C of[-1,1]){const B=se([[C*K*.5,.05*w],[C*(K+.85*w),-.6*w],[C*(K+.72*w),.05*w],[C*(K+.45*w),-.02*w],[C*(K+.3*w),.32*w],[C*K*.6,.55*w]]);et.push(A({k:"path",d:pt(B,.18),fill:L.accent},Z))}if(W("wings-fairy")&&et.push(...jr(e,j,K,w,bt)),W("cape")){const C=H+.8*w,B=gt+.36*w,Y=se([[-K*.92,mt+.04*w],[K*.92,mt+.04*w],[K+.16*w,H*.5],[B,C],[B*.5,C-.1*w],[0,C],[-B*.5,C-.1*w],[-B,C],[-K-.16*w,H*.5]]);et.push(A({k:"path",d:dt(Y,.6),fill:L.accent},Z))}if(W("backpack")){const C=j(0,.35*w);et.push(A({k:"rect",x:C.x,y:C.y,w:K*2+.34*w,h:.8*w,r:.16*w,rot:O.angle,fill:(r=(o=e.extraColors)==null?void 0:o[0])!=null?r:L.limbs},Z))}if(W("tank")){const C=j(K*.95,.24*w),B=(l=(h=e.extraColors)==null?void 0:h[0])!=null?l:L.accent,Y=j(K*.95,-.3*w);et.push({k:"rect",x:Y.x,y:Y.y,w:.14*w,h:.16*w,r:.04*w,rot:O.angle,fill:L.outline}),et.push(A({k:"rect",x:C.x,y:C.y,w:.34*w,h:1*w,r:.17*w,rot:O.angle,fill:B},Z))}if(O.hipsOk&&!n.portrait&&et.push(...qr(e,O,gt,bt)),W("tentacles")&&O.hipsOk)for(const C of[-1,1]){const B=se([[C*gt*.7,H*.9],[C*(gt+.22*w),H+.3*w],[C*(gt+.48*w),H+.22*w],[C*(gt+.5*w),H-.02*w],[C*(gt+.34*w),H-.06*w]]);et.push({k:"path",d:os(B),stroke:L.outline,lw:.2*w+bt*2}),et.push({k:"path",d:os(B),stroke:L.limbs,lw:.2*w})}const Wt=Math.max(K,gt)*G.bulge;if(W("wool")){for(const[B,Y]of[[K*.7,mt+.02*w],[Wt,H*.3],[Wt*1.02,H*.62],[(Wt+gt)/2,H*.92],[gt*.55,St]])for(const st of[-1,1]){const at=j(st*B,Y);it.push(A({k:"circle",x:at.x,y:at.y,r:.2*w,fill:L.body},Z))}const C=j(0,St+.02*w);it.push(A({k:"circle",x:C.x,y:C.y,r:.2*w,fill:L.body},Z))}if(W("robe")){const C=H+.58*w,B=gt*1.4;it.push(A({k:"path",d:dt(se([[-K,mt],[0,mt-.04*w],[K,mt],[Wt,H*.55],[B,C],[0,C+.06*w],[-B,C],[-Wt,H*.55]]),.7),fill:L.body},Z));const Y=se([[-B*.94,C-.1*w],[0,C-.04*w],[B*.94,C-.1*w]]);it.push({k:"path",d:os(Y),stroke:(f=(c=e.extraColors)==null?void 0:c[0])!=null?f:L.accent,lw:.07*w})}else if(W("sheet")){const C=H+.78*w,B=gt*1.3;it.push(A({k:"path",d:dt(se([[-K,mt],[K,mt],[Wt,H*.55],[B,C],[B*.5,C-.2*w],[0,C],[-B*.5,C-.2*w],[-B,C],[-Wt,H*.55]]),.9),fill:L.body},Z))}else it.push(A({k:"path",d:dt(se([[-K,mt],[0,mt-.04*w],[K,mt],[Wt,H*.55],[gt,St],[0,St+.03*w],[-gt,St],[-Wt,H*.55]]),.85),fill:L.body},Z));const jt=Math.min(K,gt);if(W("pocket")){const C=j(0,H*.74);it.push({k:"rect",x:C.x,y:C.y,w:jt*1.3,h:.3*w,r:.1*w,rot:O.angle,fill:L.belly,stroke:L.outline,lw:bt*.8})}else if(W("racing-stripe"))for(const C of[-.1,.1]){const B=j(C*w,mt+.02*w),Y=j(C*w,St-.04*w);it.push({k:"line",pts:[B.x,B.y,Y.x,Y.y],stroke:L.belly,lw:.1*w})}else if(L.belly&&L.belly!==L.body&&!W("panel")&&!W("sheet")&&!W("stripes")){const C=j(0,H*.58);it.push({k:"ellipse",x:C.x,y:C.y,rx:jt*.64,ry:Math.max(H*.36,.2*w),rot:O.angle,fill:L.belly})}if(W("spots")){const C=(y=(u=e.extraColors)==null?void 0:u[1])!=null?y:L.belly;for(const[B,Y,st]of[[-.55,.35,.09],[.5,.62,.11],[-.35,.86,.07]]){const at=j(B*jt,Y*H);it.push({k:"circle",x:at.x,y:at.y,r:st*w,fill:C})}}if(W("stripes")){const C=(b=(d=e.extraColors)==null?void 0:d[1])!=null?b:L.accent;for(const B of[.22,.44,.66]){const Y=j(-jt*.98,H*B),st=j(jt*.98,H*B);it.push({k:"line",pts:[Y.x,Y.y,st.x,st.y],stroke:C,lw:.1*w})}}if(W("straps")){const C=(x=(m=e.extraColors)==null?void 0:m[1])!=null?x:L.outline;for(const B of[-1,1]){const Y=j(B*K*.62,mt+.02*w),st=j(B*jt*.62,H*.72);it.push({k:"line",pts:[Y.x,Y.y,st.x,st.y],stroke:L.outline,lw:.13*w+bt*2}),it.push({k:"line",pts:[Y.x,Y.y,st.x,st.y],stroke:C,lw:.13*w})}}if(W("belt")){const C=j(0,H*.9);it.push(A({k:"rect",x:C.x,y:C.y,w:gt*1.92,h:.17*w,r:.06*w,rot:O.angle,fill:(v=(g=e.extraColors)==null?void 0:g[2])!=null?v:"#4a3426"},Z)),it.push(A({k:"rect",x:C.x,y:C.y,w:.2*w,h:.19*w,r:.04*w,rot:O.angle,fill:"#ffd84a"},Z))}if(W("emblem")){const C=j(0,H*.4),B=(T=(_=e.extraColors)==null?void 0:_[0])!=null?T:L.accent,Y=pt([{x:-.22,y:-.2},{x:.22,y:-.2},{x:.22,y:.04},{x:0,y:.26},{x:-.22,y:.04}],.25);it.push({k:"group",x:C.x,y:C.y,rot:O.angle,s:w,items:[{k:"path",d:Y,fill:B,stroke:L.outline,lw:bt/w},{k:"group",x:0,y:.01,s:.12,items:[{k:"path",d:Ye,fill:B===L.accent?"#ffffff":L.accent}]}]})}if(W("panel")){const C=j(0,H*.5);it.push(A({k:"rect",x:C.x,y:C.y,w:jt*1.2,h:.38*w,r:.1*w,rot:O.angle,fill:"#24323d"},Z)),((N=e.extraColors)!=null?N:["#ff7a6b","#fbd46a","#7ff0ff"]).slice(0,3).forEach((Y,st)=>{const at=j((st-1)*jt*.34,H*.5);it.push({k:"circle",x:at.x,y:at.y,r:.075*w,fill:Y})})}if(W("badge")){const C=j(-jt*.42,H*.36);it.push(A({k:"circle",x:C.x,y:C.y,r:.15*w,fill:L.accent},Z)),it.push({k:"group",x:C.x,y:C.y,rot:O.angle,s:.09*w,items:[{k:"path",d:Ye,fill:"#ffffff"}]})}if(W("star")){const C=j(-jt*.5,H*.3),B=.15*w;it.push({k:"group",x:C.x,y:C.y,rot:O.angle-.2,s:B,items:[{k:"path",d:Ye,fill:(M=(R=e.extraColors)==null?void 0:R[0])!=null?M:"#ffd84a",stroke:L.outline,lw:bt*.8/B}]})}if(W("petals")&&it.push(...Yr(e,j,K,gt,Wt,H,St,w,bt,G)),W("scarf")){const C=Math.max(.04,G.head*(1-G.neck)-.06)*w,B=j(0,C),Y=(z=(P=e.extraColors)==null?void 0:P[0])!=null?z:L.accent,st=j(K*.45,C+.28*w);it.push(A({k:"rect",x:st.x,y:st.y,w:.16*w,h:.42*w,r:.06*w,rot:O.angle+.15,fill:Y},Z)),it.push(A({k:"rect",x:B.x,y:B.y,w:K*2.05,h:.2*w,r:.1*w,rot:O.angle,fill:Y},Z))}const is={k:"group",x:O.head.x,y:O.head.y,rot:O.headRot,s:O.headR,items:Hr(e,bt/O.headR)};return[...et,...pe,...it,...De,is,...ws]}var gi=new WeakMap,Ur=64;function Hr(t,e){const s=Number(e.toPrecision(4));let n=gi.get(t);n||gi.set(t,n=new Map);let i=n.get(s);return i||(n.size>=Ur&&n.clear(),n.set(s,i=fi(t,s))),i}function Gr(t,e,s,n,i,a){const o=Xr(t,e,s,n,i,a);if(!t.bodyExtras.includes("strong-legs"))return[o];const r=s.U*a,h=xt(xt(e,ht(s.d,.07*r)),ht(s.r,n*.06*r)),l=[o];for(const c of[-1,0,1]){const f=xt(xt(h,ht(s.r,c*.12*r)),ht(s.d,.09*r));l.push({k:"ellipse",x:f.x,y:f.y,rx:.05*r,ry:.045*r,rot:s.angle,fill:t.palette.belly,stroke:t.palette.outline,lw:i*.8})}return l}function Xr(t,e,s,n,i,a){var o;const r=t.palette,{d:h,r:l}=s,c=s.U*a,f=xt(xt(e,ht(h,.07*c)),ht(l,n*.06*c)),u={stroke:r.outline,lw:i},y=(o=r.feet)!=null?o:r.limbs;if(t.bodyExtras.includes("fins")){const d=pt([{x:-.13,y:-.06},{x:.13,y:-.06},{x:.24,y:.46},{x:-.24,y:.46}],.22);return{k:"group",x:f.x,y:f.y,rot:s.angle,s:c,items:[{k:"path",d,fill:y,stroke:r.outline,lw:i/c},{k:"line",pts:[0,.06,0,.38],stroke:r.outline,lw:i/c,alpha:.5}]}}return t.bodyExtras.includes("flippers")?A({k:"ellipse",x:f.x,y:f.y,rx:.27*c,ry:.11*c,rot:s.angle,fill:y},u):t.bodyExtras.includes("boots")?A({k:"rect",x:f.x,y:f.y,w:.4*c,h:.24*c,r:.09*c,rot:s.angle,fill:y},u):A({k:"ellipse",x:f.x,y:f.y,rx:.2*c,ry:.13*c,rot:s.angle,fill:y},u)}function qr(t,e,s,n){var i,a,o,r,h,l,c,f,u;const y=t.palette,{U:d,L:b,S:m,r:x,d:g}=e,v=(M,P)=>({x:m.x+x.x*M+g.x*P,y:m.y+x.y*M+g.y*P}),_=M=>M.map(([P,z])=>v(P,z)),T={stroke:y.outline,lw:n},N=(M,P,z)=>[{k:"path",d:os(M),stroke:y.outline,lw:P+n*2},{k:"path",d:os(M),stroke:z,lw:P}],R=[];switch(t.tail){case"none":break;case"fluffy":{const M=_([[s*.5,b*.95],[s+.28*d,b*1],[s+.72*d,b*.62],[s+.78*d,b*.12],[s+.52*d,b*.32],[s+.3*d,b*.6],[s*.6,b*.7]]);R.push(A({k:"path",d:dt(M),fill:y.body},T));const P=v(s+.72*d,b*.2);R.push(A({k:"ellipse",x:P.x,y:P.y,rx:.13*d,ry:.2*d,rot:e.angle+.25,fill:y.belly},T));break}case"brush":{const M=_([[s*.4,b*.98],[s+.42*d,b*1.06],[s+.98*d,b*.66],[s+1.06*d,b*.12],[s+.86*d,-.04*d],[s+.66*d,b*.36],[s+.3*d,b*.66],[s*.5,b*.68]]);R.push(A({k:"path",d:dt(M),fill:y.body},T));const P=_([[s+1.03*d,b*.36],[s+1.06*d,b*.12],[s+.86*d,-.04*d],[s+.72*d,b*.24],[s+.86*d,b*.34]]);R.push(A({k:"path",d:dt(P),fill:y.belly},T));break}case"pom":{const M=v(s+.06*d,b*.88);R.push(A({k:"circle",x:M.x,y:M.y,r:.2*d,fill:y.belly},T));break}case"long":case"striped":case"tuft":{const M=_([[s*.6,b*.9],[s+.35*d,b*.85],[s+.58*d,b*.4],[s+.5*d,-.02*d]]);if(R.push(...N(M,.14*d,y.body)),t.tail==="tuft"){const P=M[M.length-1];R.push(A({k:"circle",x:P.x,y:P.y,r:.16*d,fill:(a=(i=t.extraColors)==null?void 0:i[0])!=null?a:y.accent},T))}if(t.tail==="striped"){for(const z of[.35,.6,.85]){const U=v(s+.35*d+.22999999999999998*d*(z*1.4>1?1:z*1.4),b*(.85-.85*z));R.push({k:"line",pts:[U.x-x.x*.08*d,U.y-x.y*.08*d,U.x+x.x*.08*d,U.y+x.y*.08*d],stroke:(r=(o=t.extraColors)==null?void 0:o[0])!=null?r:y.outline,lw:.06*d})}const P=M[M.length-1];R.push({k:"circle",x:P.x,y:P.y,r:.07*d,fill:(l=(h=t.extraColors)==null?void 0:h[0])!=null?l:y.outline})}break}case"curl":{const M=_([[s*.6,b*.9],[s+.4*d,b*.88],[s+.62*d,b*.45],[s+.5*d,b*.12],[s+.3*d,b*.24],[s+.36*d,b*.42]]);R.push(...N(M,.12*d,y.limbs));break}case"fish":{const M=_([[s*.6,b*.9],[s+.36*d,b*.86],[s+.6*d,b*.5]]);R.push(...N(M,.17*d,y.body));const P=M[M.length-1],z=pt([{x:0,y:.06},{x:-.26,y:-.34},{x:.02,y:-.12},{x:.32,y:-.3}],.2);R.push({k:"group",x:P.x,y:P.y,rot:e.angle+.35,s:d,items:[{k:"path",d:z,fill:y.body,stroke:y.outline,lw:n/d}]});break}case"plume":{const M=(c=t.extraColors)!=null?c:[y.accent];[0,1,2].forEach(P=>{const z=v(s+(.12+P*.13)*d,b+(.32-P*.06)*d);R.push(A({k:"ellipse",x:z.x,y:z.y,rx:.11*d,ry:.44*d,rot:e.angle-.55+P*.28,fill:M[(P+1)%M.length]},T))});break}case"thick":{const M=_([[s*.3,b*.42],[s+.42*d,b*.62],[s+.92*d,b*.96],[s+1.32*d,b*1.08],[s+1.44*d,b*.98],[s+.98*d,b*1.2],[s+.4*d,b*1.22],[s*.3,b*1.12]]);R.push(A({k:"path",d:dt(M,.8),fill:y.body},T));const P=(u=(f=t.extraColors)==null?void 0:f[0])!=null?u:y.accent;for(const[z,U,G]of[[.28,.58,.26],[.62,.8,.22],[.96,1,.16]]){const O=v(s+z*d,b*U+.03*d),X=v(s+(z-.1)*d,b*U+G*d);R.push({k:"line",pts:[O.x,O.y,X.x,X.y],stroke:P,lw:.09*d})}break}case"spiky":case"arrow":{const M=_([[s*.3,b*.55],[s+.35*d,b*.68],[s+.95*d,b*.86],[s+.35*d,b*1.08],[s*.3,b*1.08]]);if(t.tail==="spiky"){for(const P of[.15,.45,.72]){const z=s+(.2+P*.7)*d,U=b*(.66+P*.19);R.push(A({k:"path",d:pt(_([[z-.12*d,U+.05*d],[z,U-.2*d],[z+.12*d,U+.07*d]]),.2),fill:y.accent},T))}R.push(A({k:"path",d:dt(M,.7),fill:y.body},T))}else{const P=_([[s*.6,b*.9],[s+.4*d,b*.92],[s+.62*d,b*.5],[s+.62*d,b*.18]]);R.push(...N(P,.13*d,y.body));const z=P[P.length-1];R.push({k:"group",x:z.x,y:z.y,rot:e.angle,s:d,items:[{k:"path",d:pt([{x:-.15,y:.04},{x:0,y:-.22},{x:.15,y:.04}],.2),fill:y.accent,stroke:y.outline,lw:n/d}]})}break}}return R}function Wr(t,e,s,n,i){const a=t.palette,o=xt(e,ht(s,-.08*n)),r=xt(e,ht(s,.52*n)),h=.2*n;return[{k:"line",pts:[o.x,o.y,r.x,r.y],stroke:a.outline,lw:.06*n+i*2},{k:"line",pts:[o.x,o.y,r.x,r.y],stroke:"#fff3d6",lw:.06*n},{k:"circle",x:r.x,y:r.y,r:.24*n,fill:a.accent,alpha:.28},{k:"group",x:r.x,y:r.y,rot:Math.atan2(s.y,s.x)+Math.PI/2,s:h,items:[{k:"path",d:Ye,fill:a.accent,stroke:a.outline,lw:i*.9/h}]}]}function jr(t,e,s,n,i){var a,o;const r=t.palette,h=(o=(a=t.extraColors)==null?void 0:a[0])!=null?o:"#cdeeff",l=[];for(const c of[-1,1]){const f=[[[c*s*.3,.12*n],[c*(s+.42*n),-.66*n],[c*(s+1*n),-.74*n],[c*(s+1.02*n),-.18*n],[c*(s+.5*n),.26*n]],[[c*s*.4,.3*n],[c*(s+.6*n),.36*n],[c*(s+.74*n),.78*n],[c*(s+.3*n),.9*n]]];for(const u of f){const y=dt(u.map(([x,g])=>e(x,g)),.9);l.push({k:"path",d:y,fill:h,alpha:.6}),l.push({k:"path",d:y,stroke:r.outline,lw:i*.9});const d=u[Math.floor(u.length/2)],b=e(u[0][0],u[0][1]),m=e(u[0][0]+(d[0]-u[0][0])*.75,u[0][1]+(d[1]-u[0][1])*.75);l.push({k:"line",pts:[b.x,b.y,m.x,m.y],stroke:"#ffffff",lw:i*.9,alpha:.85})}for(const[u,y,d]of[[s+.72*n,-.42*n,.075*n],[s+.44*n,-.16*n,.05*n],[s+.5*n,.6*n,.055*n]]){const b=e(c*u,y);l.push({k:"group",x:b.x,y:b.y,s:d,items:[{k:"path",d:Ye,fill:"#ffffff"}]})}}return l}function Yr(t,e,s,n,i,a,o,r,h,l){var c,f;const u=t.palette,y=(f=(c=t.extraColors)==null?void 0:c[1])!=null?f:u.belly,d=[],b=Math.atan2(e(1,0).y-e(0,0).y,e(1,0).x-e(0,0).x),m=5,x=Math.max(n,i*.92)*1.08,g=(a*.8+o)/2,v=[0,4,1,3,2];for(const T of v){const N=T/(m-1)-.5,R=e(N*2*x,g+(.5-Math.abs(N))*.1*r);d.push({k:"ellipse",x:R.x,y:R.y,rx:x*.3,ry:.34*r,rot:b-N*.6,fill:T%2?y:u.body,stroke:u.outline,lw:h})}const _=Math.max(.04,l.head*(1-l.neck)-.04)*r;for(const T of[-1,1,0]){const N=e(T*s*.32,_+(T?0:.05*r));d.push({k:"ellipse",x:N.x,y:N.y,rx:s*.26,ry:.12*r,rot:b+T*.5,fill:T?y:u.body,stroke:u.outline,lw:h*.9})}return d}var Qr={nose:[0,-.62],leftShoulder:[-.42,0],rightShoulder:[.42,0],leftElbow:[-.58,.5],rightElbow:[.58,.5],leftWrist:[-.66,.98],rightWrist:[.66,.98],leftHip:[-.27,1],rightHip:[.27,1],leftKnee:[-.31,1.6],rightKnee:[.31,1.6],leftAnkle:[-.33,2.18],rightAnkle:[.33,2.18]};function Vr(t,{cx:e=.5,cy:s=.36,T:n=.18}={}){var i;const a=A(A({},Qr),t),o=new Array(ti*3).fill(0),r=(c,[f,u],y=.99)=>{o[c*3]=e+f*n,o[c*3+1]=s+u*n,o[c*3+2]=y};for(const c of Object.keys(J))r(J[c],a[c]);const h=(i=a.tilt)!=null?i:0,l=(c,f)=>[a.nose[0]+c*Math.cos(h)-f*Math.sin(h),a.nose[1]+c*Math.sin(h)+f*Math.cos(h)];return r(be.leftEye,l(-.1,-.08)),r(be.rightEye,l(.1,-.08)),r(be.leftEar,l(-.22,-.02)),r(be.rightEar,l(.22,-.02)),o}var Kr=()=>Vr({}),vi=.5,Zr=.15,Jr=Object.freeze({lag:.5,extrapolate:.75,maxExtrapolateMs:50}),ki=class{constructor(t={}){p(this,"tracks",new Map),p(this,"offset",NaN),p(this,"lastArrival",NaN),p(this,"interval",33),p(this,"lastT",NaN),p(this,"lostMs"),p(this,"maxExtrapolateMs"),p(this,"lag"),p(this,"extrapolate");var e,s;this.lostMs=(e=t.lostMs)!=null?e:250,this.maxExtrapolateMs=(s=t.maxExtrapolateMs)!=null?s:25,this.lag=_i(t.lag,1),this.extrapolate=_i(t.extrapolate,.5)}get delayMs(){return this.interval*this.lag}push(t,e,s,n=wi()){Number.isFinite(e)||(e=n),this.clock(e,n);const i=this.tracks.get(t);if(!i||e-i.tb>this.lostMs||e<i.tb-this.lostMs||s.length!==i.b.length){this.tracks.set(t,{a:null,ta:e,b:s,tb:e,out:null,outAt:NaN});return}if(s===i.b||e<=i.tb){e===i.tb&&s!==i.b&&(i.b=s,i.out=null);return}i.a=i.b,i.ta=i.tb,i.b=s,i.tb=e,i.out=null}at(t,e=wi()){const s=this.tracks.get(t);if(!s)return null;if(!s.a)return s.b;if(s.out&&s.outAt===e)return s.out;const n=e-this.offset-this.interval*this.lag,i=s.tb-s.ta,a=Math.min(i*this.extrapolate,this.maxExtrapolateMs),o=Math.min(Math.max((n-s.ta)/i,0),1+a/i);return s.out=$r(s.a,s.b,o),s.outAt=e,s.out}forget(t){this.tracks.delete(t)}clear(){this.tracks.clear()}clock(t,e){const s=e-t;if(!Number.isFinite(this.offset)||s<this.offset||s>this.offset+1e3?this.offset=s:Number.isFinite(this.lastArrival)&&(this.offset+=Math.min(s-this.offset,(e-this.lastArrival)/1e3)),this.lastArrival=e,Number.isFinite(this.lastT)&&t>this.lastT){const n=t-this.lastT;n<this.interval*3+20&&(this.interval+=(Math.min(Math.max(n,8),100)-this.interval)*.1)}t<=this.lastT||(this.lastT=t)}},wi=()=>{var t,e;return(e=(t=le.performance)==null?void 0:t.now())!=null?e:Date.now()},_i=(t,e)=>typeof t=="number"&&Number.isFinite(t)?Math.min(Math.max(t,0),1):e;function $r(t,e,s){const n=e.slice(),i=s<.5?t:e;for(let a=0;a+2<e.length;a+=3){const o=t[a],r=t[a+1],h=e[a],l=e[a+1];t[a+2]>=vi&&e[a+2]>=vi&&Math.abs(h-o)+Math.abs(l-r)<Zr?(n[a]=o+(h-o)*s,n[a+1]=r+(l-r)*s,n[a+2]=t[a+2]+(e[a+2]-t[a+2])*Math.min(s,1)):(n[a]=i[a],n[a+1]=i[a+1],n[a+2]=i[a+2])}return n}var Mc=oi.map(t=>t.id),Ns=new Map(oi.map(t=>[t.id,t])),ls=Ns.get("fox"),to=t=>typeof t=="string"&&Ns.has(t),Is=t=>Ns.get(t),eo=t=>{var e;return typeof t=="string"?(e=Ns.get(t))!=null?e:ls:t};function so(t,e,s){const n=eo(t),i=Kr(),a=di(n,s),o=dn(i,{x:0,y:0,w:1,h:1},{band:a}),r=Ei(fi(n,.05)),h=-r.minY,l=Math.min(.27,.43/Math.max(h,1))*e,c=n.head==="snout-long"?(r.minX+r.maxX)/2*l:0,f=l/Pe[a].head/o.U,u=.5*e+Math.min(0,(h-1.6)*.06*e),y={x:e/2-c-o.head.x*f,y:u-o.head.y*f,w:f,h:f};return bi(i,n,y,{portrait:!0,band:a})}function no(t,e,s=.5){if(!t||t.length!==e.length)return e.slice();const n=e.slice();for(let i=0;i+2<e.length;i+=3){const a=t[i+2],o=e[i+2],r=a>=.5,h=o>=.5;r&&o>=.3&&(n[i+2]=Math.max(o,.5));const l=Math.hypot(e[i]-t[i],e[i+1]-t[i+1]);if(r&&h&&l<.15){const c=s*Math.min(1,Mi+(1-Mi)*l/ao);n[i]=t[i]+(e[i]-t[i])*c,n[i+1]=t[i+1]+(e[i+1]-t[i+1])*c}else r&&!h&&n[i+2]>=.5&&(n[i]=t[i],n[i+1]=t[i+1])}return lo(t,e,n,s*ro),n}var io=.8,Mi=.1,ao=.03,ro=.35,oo=11;function lo(t,e,s,n){const i=J.leftShoulder*3,a=J.rightShoulder*3,o=(f,u)=>f[u+2]>=.5;if(!o(t,i)||!o(t,a)||!o(e,i)||!o(e,a))return;const r=(f,u)=>(f[i+u]+f[a+u])/2,h=[r(t,0),r(t,1)],l=[r(e,0),r(e,1)],c=[r(s,0),r(s,1)];for(let f=0;f<oo&&f*3+2<e.length;f++){const u=f*3;if(!o(t,u)||!o(e,u))continue;const y=[t[u]-h[0],t[u+1]-h[1]],d=[e[u]-l[0],e[u+1]-l[1]];Math.hypot(d[0]-y[0],d[1]-y[1])>=.15||(s[u]=c[0]+y[0]+(d[0]-y[0])*n,s[u+1]=c[1]+y[1]+(d[1]-y[1])*n)}}function Ei(t){var e,s,n,i;const a={minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0},o=(r,h)=>{a.minX=Math.min(a.minX,r),a.minY=Math.min(a.minY,h),a.maxX=Math.max(a.maxX,r),a.maxY=Math.max(a.maxY,h)};for(const r of t){const h="lw"in r&&r.stroke?((e=r.lw)!=null?e:1)/2:0;switch(r.k){case"circle":o(r.x-r.r-h,r.y-r.r-h),o(r.x+r.r+h,r.y+r.r+h);break;case"ellipse":case"rect":{const l=r.k==="ellipse"?r.rx:r.w/2,c=r.k==="ellipse"?r.ry:r.h/2,f=Math.max(l,c)+h;o(r.x-f,r.y-f),o(r.x+f,r.y+f);break}case"path":{const l=br(r.d);for(let c=0;c+1<l.length;c+=2)o(l[c]-h,l[c+1]-h),o(l[c]+h,l[c+1]+h);break}case"line":for(let l=0;l+1<r.pts.length;l+=2)o(r.pts[l]-h,r.pts[l+1]-h),o(r.pts[l]+h,r.pts[l+1]+h);break;case"group":{const l=Ei(r.items);if(!Number.isFinite(l.minX))break;const c=(s=r.s)!=null?s:1,f=Math.cos((n=r.rot)!=null?n:0),u=Math.sin((i=r.rot)!=null?i:0);for(const[y,d]of[[l.minX,l.minY],[l.maxX,l.minY],[l.minX,l.maxY],[l.maxX,l.maxY]])o(r.x+(y*f-d*u)*c,r.y+(y*u+d*f)*c);break}}}return a}var Qe=()=>Float64Array.of(1,0,0,1,0,0);function ce(t,e,s,n,i,a,o){const r=i?Math.cos(i):1,h=i?Math.sin(i):0,l=r*a,c=h*a,f=-h*o,u=r*o;if(!e)return t[0]=l,t[1]=c,t[2]=f,t[3]=u,t[4]=s,t[5]=n,t;const y=e[0],d=e[1],b=e[2],m=e[3];return t[0]=y*l+b*c,t[1]=d*l+m*c,t[2]=y*f+b*u,t[3]=d*f+m*u,t[4]=y*s+b*n+e[4],t[5]=d*s+m*n+e[5],t}function co(t,e,s){const n=t[0]*t[3]-t[1]*t[2];if(Math.abs(n)<1e-12)return null;const i=e-t[4],a=s-t[5];return[(t[3]*i-t[2]*a)/n,(-t[1]*i+t[0]*a)/n]}var Ai={white:16777215,black:0,red:16711680,transparent:0},cs=new Map;function ne(t){var e,s;if(typeof t=="number")return[t&16777215,1];const n=cs.get(t);if(n)return n;let i=[16777215,1];const a=t.trim().toLowerCase();if(a[0]==="#"){const o=a.slice(1),r=o.length<=4?[...o].map(l=>l+l).join(""):o,h=parseInt(r.slice(0,6),16);Number.isFinite(h)&&(i=[h,r.length===8?parseInt(r.slice(6,8),16)/255:1])}else if(a.startsWith("rgb")){const o=(s=(e=a.match(/-?\d*\.?\d+%?/g))==null?void 0:e.map(f=>f.endsWith("%")?parseFloat(f)/100*255:parseFloat(f)))!=null?s:[],[r=255,h=255,l=255]=o,c=o[3]===void 0?1:a.match(/,\s*[\d.]+%\s*\)$/)?o[3]/255:o[3];i=[(pn(r)<<16|pn(h)<<8|pn(l))>>>0,Math.min(Math.max(c,0),1)]}else if(a in Ai)i=[Ai[a],a==="transparent"?0:1];else if(typeof document!="undefined"){const o=document.createElement("canvas").getContext("2d");if(o){o.fillStyle="#ffffff",o.fillStyle=a;const r=o.fillStyle;if(r!==a)return cs.set(t,i=ne(r)),i}}return cs.size>512&&cs.clear(),cs.set(t,i),i}var pn=t=>Math.min(Math.max(Math.round(t),0),255);function Ve(t,e,s=!1){const n=Math.min(Math.max(e,0),1),i=(t>>16&255)*n,a=(t>>8&255)*n,o=(t&255)*n,r=s?0:n*255;return(Math.round(r)<<24|Math.round(o)<<16|Math.round(a)<<8|Math.round(i))>>>0}var hs=(t,e=1)=>"rgba(".concat(t>>16&255,",").concat(t>>8&255,",").concat(t&255,",").concat(e,")");function Si(t,e){if(t===16777215)return e;if(e===16777215)return t;const s=n=>Math.round((t>>n&255)*(e>>n&255)/255);return(s(16)<<16|s(8)<<8|s(0))>>>0}var fs={linear:t=>t,quadIn:t=>t*t,quadOut:t=>t*(2-t),quadInOut:t=>t<.5?2*t*t:-1+(4-2*t)*t,cubicOut:t=>1-qe(1-t,3),sineInOut:t=>-(Math.cos(Math.PI*t)-1)/2,backOut:t=>1+(1.70158+1)*qe(t-1,3)+1.70158*qe(t-1,2),elasticOut:t=>t===0||t===1?t:qe(2,-10*t)*Math.sin((t*10-.75)*(2*Math.PI/3))+1,bounceOut:t=>t<1/2.75?7.5625*t*t:t<2/2.75?7.5625*(t-=1.5/2.75)*t+.75:t<2.5/2.75?7.5625*(t-=2.25/2.75)*t+.9375:7.5625*(t-=2.625/2.75)*t+.984375};function ho(t){let e=t>>>0;return()=>{e=e+1831565813>>>0;let s=e;return s=Math.imul(s^s>>>15,s|1),s^=s+Math.imul(s^s>>>7,s|61),((s^s>>>14)>>>0)/4294967296}}var us=1,Ti=2,Os=0,te=1,fo=4294967295,F={cap:0,epoch:0,x:new Float64Array(0),y:new Float64Array(0),rot:new Float64Array(0),sx:new Float64Array(0),sy:new Float64Array(0),alpha:new Float64Array(0),la:new Float64Array(0),lb:new Float64Array(0),lc:new Float64Array(0),ld:new Float64Array(0),world:new Float64Array(0),tint:new Uint32Array(0),flags:new Uint8Array(0),moved:new Uint8Array(0),dirty:new Uint8Array(0),gen:new Uint32Array(0),parent:new Int32Array(0),first:new Int32Array(0),next:new Int32Array(0),prev:new Int32Array(0),stamp:new Uint32Array(0),pass:0,free:new Int32Array(0),freeHead:0,freeCount:0,top:2},ge=[],uo="x y rot sx sy alpha la lb lc ld world tint flags moved dirty gen parent first next prev stamp".split(" ");function Ci(t){const e=F;for(const n of uo){const i=e[n],a=new i.constructor(n==="world"?t*6:t);a.set(i),e[n]=a}const s=new Int32Array(t);for(let n=0;n<F.freeCount;n++)s[n]=F.free[(F.freeHead+n)%F.cap];for(F.free=s,F.freeHead=0,F.cap=t,F.epoch++;ge.length<t;)ge.push(null)}function yn(t){F.x[t]=F.y[t]=F.rot[t]=0,F.sx[t]=F.sy[t]=F.alpha[t]=1,F.la[t]=F.ld[t]=1,F.lb[t]=F.lc[t]=0;const e=t*6,s=F.world;s[e]=s[e+3]=1,s[e+1]=s[e+2]=s[e+4]=s[e+5]=0,F.tint[t]=16777215,F.flags[t]=us|Ti,F.moved[t]=1,F.dirty[t]=0,F.parent[t]=F.first[t]=F.next[t]=F.prev[t]=-1}Ci(256),yn(Os),F.flags[Os]=0,yn(te),F.flags[te]=0;function po(){let t;if(F.freeCount){t=F.free[F.freeHead],F.freeHead=(F.freeHead+1)%F.cap,F.freeCount--;const e=ge[t];e&&(e._i=Os,e._g=-1,ge[t]=null)}else F.top===F.cap&&Ci(F.cap*2),t=F.top++;return yn(t),t}function Ri(t,e){mn(t);for(let n=F.first[t];n>=0;){const i=F.next[n];F.parent[n]=F.next[n]=F.prev[n]=-1,n=i}F.first[t]=-1,F.flags[t]=F.flags[t]&~Ti,F.moved[t]=0;const s=F.gen[t]+1;F.gen[t]=s,s!==fo&&(e&&(ge[t]=e),F.free[(F.freeHead+F.freeCount)%F.cap]=t,F.freeCount++)}function yo(t){for(let e=0;e<ge.length;e++){const s=ge[e];s&&t(s)&&(s._i=Os,s._g=-1,ge[e]=null)}}function mo(t,e){mn(t);const s=F.first[e];F.parent[t]=e,F.next[t]=s,F.prev[t]=-1,s>=0&&(F.prev[s]=t),F.first[e]=t,F.moved[t]=1}function mn(t){const e=F.parent[t];if(e<0)return;const s=F.next[t],n=F.prev[t];n>=0?F.next[n]=s:F.first[e]=s,s>=0&&(F.prev[s]=n),F.parent[t]=F.next[t]=F.prev[t]=-1}var ds={root:-1,gen:-1,world:new Float64Array(6)};function xo(t){const e=++F.pass,s=F.world,n=t*6,i=ds.world;let a=ds.root!==t||ds.gen!==F.gen[t];for(let o=0;o<6;o++)i[o]!==s[n+o]&&(a=!0),i[o]=s[n+o];ds.root=t,ds.gen=F.gen[t],F.stamp[t]=a?e:e-1}function bo(t){F.stamp[t]=F.pass}function Fi(t){for(let e=F.first[t];e>=0;){const s=F.next[e];Fi(e),e=s}Ri(t)}var xn=typeof FinalizationRegistry=="function"?new FinalizationRegistry(t=>F.gen[t.i]===t.g&&Fi(t.i)):null;function Pi(t){t._reg||!xn||(t._reg=!0,xn.register(t,{i:t._i,g:t._g},t))}function go(t){t._reg&&xn.unregister(t)}var bn=1,gn=2,vn=3,kn=4;function wn(t){if(t){for(let e=0;e<t.length;e++)if(t[e].enabled)return!0}return!1}function vo(t,e){let s=0;for(let n=0;n<t.length;n++){const i=t[n];i.enabled&&i.pad&&(s+=i.pad(e))}return s}var ie={gl:null,c2d:null,live:null},ft=new Float64Array(3),_n=4,ko=1,Mn=()=>ko++,Et=Qe(),D=F,Ne=class{constructor(t){p(this,"kernel",t),p(this,"_i",po()),p(this,"_g",D.gen[this._i]),p(this,"_wv",null),p(this,"_wi",-1),p(this,"_we",-1),p(this,"blend","normal"),p(this,"_data",null),p(this,"parent",null),p(this,"hitRadius",null),p(this,"clip",null),p(this,"mask",null),p(this,"filters",null),p(this,"_z",0),p(this,"anchorX",0),p(this,"anchorY",0),p(this,"_pool",null),p(this,"_free",!1),p(this,"_reg",!1)}get x(){return D.x[this._i]}set x(t){const e=this._i||te;D.x[e]=t,D.moved[e]=1}get y(){return D.y[this._i]}set y(t){const e=this._i||te;D.y[e]=t,D.moved[e]=1}get rotation(){return D.rot[this._i]}set rotation(t){const e=this._i||te;D.rot[e]=t,D.dirty[e]=D.moved[e]=1}get scaleX(){return D.sx[this._i]}set scaleX(t){const e=this._i||te;D.sx[e]=t,D.dirty[e]=D.moved[e]=1}get scaleY(){return D.sy[this._i]}set scaleY(t){const e=this._i||te;D.sy[e]=t,D.dirty[e]=D.moved[e]=1}get alpha(){return D.alpha[this._i]}set alpha(t){const e=this._i||te;D.alpha[e]=t,D.moved[e]=1}get visible(){return(D.flags[this._i]&us)!==0}set visible(t){const e=this._i||te;t?D.flags[e]=D.flags[e]|us:D.flags[e]=D.flags[e]&~us,D.moved[e]=1}get destroyed(){return D.gen[this._i]!==this._g}get world(){const t=this._i||te;return(this._wi!==t||this._we!==D.epoch)&&(this._wv=D.world.subarray(t*6,t*6+6),this._wi=t,this._we=D.epoch),this._wv}get data(){var t;return(t=this._data)!=null?t:this._data={}}set data(t){this._data=t}get scale(){return this.scaleX}set scale(t){this.scaleX=this.scaleY=t}get z(){return this._z}set z(t){t!==this._z&&(this._z=t,this.parent&&(this.parent.sortDirty=!0))}get tint(){return D.tint[this._i]}set tint(t){D.tint[this._i||te]=typeof t=="number"?t&16777215:ne(t)[0]}set anchor(t){typeof t=="number"?this.anchorX=this.anchorY=t:(this.anchorX=t.x,this.anchorY=t.y)}get width(){return 0}set width(t){}get height(){return 0}set height(t){}set(t){for(const e in t){const s=t[e];s!==void 0&&(this[e]=s)}return this}destroy(){var t;this.destroyed||(this.visible=!1,this.parent&&(this.parent.dead=!0,this.parent=null),Ri(this._i,this),go(this),this.kernel.tweens.stopAll(this),(t=this._pool)==null||t.forget(this))}updateWorld(){const t=this.parent?this.parent.updateWorld():null;return ce(this.world,t,this.x,this.y,this.rotation,this.scaleX,this.scaleY)}draw(t,e,s){}};function wo(t){yo(e=>e.kernel===t)}var En=!1,Li=Object.freeze([]),An=class qa extends Ne{constructor(e){super(e),p(this,"children",Li),p(this,"sortDirty",!1),p(this,"dead",!1),Pi(this)}add(e,...s){this.adopt(e);for(let n=0;n<s.length;n++)this.adopt(s[n]);return e}adopt(e){e.parent&&e.parent.detach(e),e.parent=this,!e.destroyed&&!this.destroyed&&mo(e._i,this._i),this.children===Li&&(this.children=[]),this.children.push(e),(e.z!==0||this.sortDirty)&&(this.sortDirty=!0)}remove(e){this.detach(e),e._pool||Pi(e)}detach(e){const s=this.children,n=s.indexOf(e);if(n>=0){for(let i=n+1;i<s.length;i++)s[i-1]=s[i];s.pop()}e.parent===this&&(e.parent=null,e.destroyed||mn(e._i))}clear(){for(const e of this.children)e.destroy()}destroy(){for(const e of this.children)e.destroy();super.destroy()}sweep(){if(this.dead){this.dead=!1;let e=0;for(const s of this.children)s.destroyed?s.parent===this&&(s.parent=null):this.children[e++]=s;this.children.length=e}for(const e of this.children)e instanceof qa&&e.sweep()}draw(e,s,n){if(En)return D.parent[this._i]<0&&!this.destroyed&&bo(this._i),this.drawChildren(e,s,n);En=!0;try{this.destroyed||xo(this._i),this.drawChildren(e,s,n)}finally{En=!1}}drawChildren(e,s,n){if(this.sortDirty){const r=new Map(this.children.map((h,l)=>[h,l]));this.children.sort((h,l)=>h.z-l.z||r.get(h)-r.get(l)),this.sortDirty=!1}const i=this.children,a=this._i,o=D.stamp[a]===D.pass;for(let r=0;r<i.length;r++){const h=i[r],l=h._i,c=D.alpha[l];if(D.gen[l]!==h._g||!(D.flags[l]&us)||c<=0)continue;if(o||D.moved[l]){D.moved[l]=0,D.stamp[l]=D.pass;let y,d,b,m;if(D.dirty[l]){D.dirty[l]=0;const z=D.rot[l],U=z?Math.cos(z):1,G=z?Math.sin(z):0,O=D.sx[l],X=D.sy[l];D.la[l]=y=U*O,D.lb[l]=d=G*O,D.lc[l]=b=-G*X,D.ld[l]=m=U*X}else y=D.la[l],d=D.lb[l],b=D.lc[l],m=D.ld[l];const x=D.world,g=D.x[l],v=D.y[l],_=l*6,T=a*6,N=x[T],R=x[T+1],M=x[T+2],P=x[T+3];x[_]=N*y+M*d,x[_+1]=R*y+P*d,x[_+2]=N*b+M*m,x[_+3]=R*b+P*m,x[_+4]=N*g+M*v+x[T+4],x[_+5]=R*g+P*v+x[T+5]}const f=s*c,u=Si(n,D.tint[l]);h.clip||h.mask||h.filters?Ii(e,h,f,u):h.draw(e,f,u)}}},It=new Float64Array(128),Ie=0,Sn=new Float64Array(8);function Ni(t,e,s,n){e.clip||e.mask||e.filters?Ii(t,e,s,n):e.draw(t,s,n)}function Ii(t,e,s,n){const i=t.r,a=e.world,o=e.clip;let r=!1,h=!1;if(o)if(Math.abs(a[1])<1e-9&&Math.abs(a[2])<1e-9&&Ie<32){const f=a[0]*o.x+a[4],u=a[0]*(o.x+o.width)+a[4],y=a[3]*o.y+a[5],d=a[3]*(o.y+o.height)+a[5];let b=Math.min(f,u),m=Math.max(f,u),x=Math.min(y,d),g=Math.max(y,d);if(Ie){const _=(Ie-1)*4;b=Math.max(b,It[_]),x=Math.max(x,It[_+1]),m=Math.min(m,It[_+2]),g=Math.min(g,It[_+3])}const v=Ie++*4;It[v]=b,It[v+1]=x,It[v+2]=m,It[v+3]=g,i.clip(b,x,Math.max(m-b,0),Math.max(g-x,0)),h=!0}else r=!0;const l=e.mask&&e.mask.visible?e.mask:null,c=wn(e.filters)?e.filters:null;try{if(r&&i.beginLayer(),l&&i.beginLayer(),c?(e.draw(t,i.beginLayer()?1:s,n),i.endLayer(s,c)):e.draw(t,s,n),l&&(i.beginMask(),ce(l.world,a,l.x,l.y,l.rotation,l.scaleX,l.scaleY),Ni(t,l,l.alpha,16777215),i.endLayer(1)),r&&o){i.beginMask();for(let f=0;f<4;f++){const u=f===1||f===2?o.x+o.width:o.x,y=f>1?o.y+o.height:o.y;Sn[f*2]=a[0]*u+a[2]*y+a[4],Sn[f*2+1]=a[1]*u+a[3]*y+a[5]}i.polygon(Sn,4,16777215,1),i.endLayer(1)}}finally{if(h)if(Ie--,Ie){const f=(Ie-1)*4;i.clip(It[f],It[f+1],It[f+2]-It[f],It[f+3]-It[f+1])}else i.unclip()}}var Ke=class extends Ne{constructor(t,e,s){super(t),p(this,"_frame",null),p(this,"_w",null),p(this,"_h",null),p(this,"slice",0),p(this,"autoAnchor",!0),p(this,"frameName",null),e&&(this.frame=e),(s==null?void 0:s.anchor)===void 0&&this.useFrameAnchor(),s&&this.set(s)}get frame(){return this._frame}set frame(t){this.frameName=typeof t=="string"?t:null,this._frame=typeof t=="string"?this.kernel.frame(t):t,this.autoAnchor&&this.useFrameAnchor()}set anchor(t){this.autoAnchor=!1,super.anchor=t}get naturalWidth(){var t;const e=this.frameNow();return e?((t=e.sw)!=null?t:e.w)/e.scale-e.margin*2:0}get naturalHeight(){var t;const e=this.frameNow();return e?((t=e.sh)!=null?t:e.h)/e.scale-e.margin*2:0}get width(){var t;return(t=this._w)!=null?t:this.naturalWidth}set width(t){this._w=t}get height(){var t;return(t=this._h)!=null?t:this.naturalHeight}set height(t){this._h=t}sizeQ(t){var e,s,n,i;$e[0]=(s=this._w)!=null?s:((e=t.sw)!=null?e:t.w)/t.scale-t.margin*2,$e[1]=(i=this._h)!=null?i:((n=t.sh)!=null?n:t.h)/t.scale-t.margin*2}frameNow(){return this.frameName&&!this.kernel.atlas.valid(this._frame)&&(this._frame=this.kernel.frame(this.frameName)),this._frame}useFrameAnchor(){var t,e;const s=this._frame;if(!s)return;const n=((t=s.sw)!=null?t:s.w)/s.scale-s.margin*2,i=((e=s.sh)!=null?e:s.h)/s.scale-s.margin*2;this.anchorX=n>0?(s.ox-s.margin)/n:0,this.anchorY=i>0?(s.oy-s.margin)/i:0}draw(t,e,s){const n=this.frameNow();if(!n)return;const i=$e;this.sizeQ(n),i[2]=this.anchorX,i[3]=this.anchorY,i[4]=e,_o(t,n,this.world,this.slice,s,this.blend)}},Ze=new Float64Array(12),Je=new Float64Array(12),ps={x:0,y:0,w:0,h:0};function Oi(t,e,s,n,i,a){e=Math.max(e,0),s=Math.max(s,0),n=Math.max(n,0);const o=s+n>i?s*i/(s+n):s,r=s+n>i?n*i/(s+n):n;let h=o/a,l=r/a;if(h+l>e){const c=e/(h+l);h*=c,l*=c}t[0]=0,t[1]=h,t[2]=0,t[3]=o,t[4]=h,t[5]=e-h-l,t[6]=o,t[7]=i-o-r,t[8]=e-l,t[9]=l,t[10]=i-r,t[11]=r}var $e=new Float64Array(5);function _o(t,e,s,n,i,a){var o,r,h,l,c,f,u,y,d,b,m;const x=$e,g=x[0],v=x[1],_=x[2],T=x[3],N=x[4],R=t.tex(e.surface),M=n===0?(o=e.slice)!=null?o:0:n;if(M===0){const L=((r=e.sw)!=null?r:e.w)/e.scale-e.margin*2,lt=((h=e.sh)!=null?h:e.h)/e.scale-e.margin*2,yt=L>0?g/L:1,$=lt>0?v/lt:1,w=-_*g+(((l=e.tx)!=null?l:0)/e.scale-e.margin)*yt,H=-T*v+(((c=e.ty)!=null?c:0)/e.scale-e.margin)*$;zs(s,w,H),ft[0]=e.w/e.scale*yt,ft[1]=e.h/e.scale*$,ft[2]=N,t.r.quadQ(R,e,Et,i,a);return}const P=(f=e.tx)!=null?f:0,z=(u=e.ty)!=null?u:0,U=((y=e.sw)!=null?y:e.w)-e.w-P,G=((d=e.sh)!=null?d:e.h)-e.h-z,O=-_*g-e.margin+P/e.scale,X=-T*v-e.margin+z/e.scale;if(Oi(Ze,g+e.margin*2-(P+U)/e.scale,(typeof M=="number"?M:M[3])-P,(typeof M=="number"?M:M[1])-U,e.w,e.scale),Oi(Je,v+e.margin*2-(z+G)/e.scale,(typeof M=="number"?M:M[0])-z,(typeof M=="number"?M:M[2])-G,e.h,e.scale),zs(s,O,X),ft[2]=N,!((m=(b=t.r).nineQ)!=null&&m.call(b,R,e,Ze,Je,Et,i,a)))for(let L=0;L<12;L+=4){const lt=Je[L+1],yt=Je[L+3];if(!(lt<=0||yt<=0))for(let $=0;$<12;$+=4){const w=Ze[$+1],H=Ze[$+3];w<=0||H<=0||(ps.x=e.x+Ze[$+2],ps.y=e.y+Je[L+2],ps.w=H,ps.h=yt,zs(s,O+Ze[$],X+Je[L]),ft[0]=w,ft[1]=lt,ft[2]=N,t.r.quadQ(R,ps,Et,i,a))}}}function zs(t,e,s){Et[0]=t[0],Et[1]=t[1],Et[2]=t[2],Et[3]=t[3],Et[4]=t[0]*e+t[2]*s+t[4],Et[5]=t[1]*e+t[3]*s+t[5]}var ys=class extends Ke{constructor(t,e,s={}){super(t,null),p(this,"_spec"),p(this,"baked",null),p(this,"bakedEffects",!0),this._spec=e,this.bake(),s.anchor===void 0&&this.useFrameAnchor(),this.set(s)}get spec(){return this._spec}set spec(t){this._spec=t,this.baked=null,this._w=this._h=null,this.bake()}bake(){const t=this.kernel;return this.baked&&t.atlas.valid(this.baked.frame)&&this.baked.frame.scale===t.pixelScale&&this.bakedEffects===t.effects?this.baked:(this.bakedEffects=t.effects,this.baked=t.shape(this._spec),this._frame=this.baked.frame,this.slice=this.baked.slice,this.autoAnchor&&this.useFrameAnchor(),this.baked)}frameNow(){return this.bake().frame}sizeQ(){var t,e;const s=this.bake();$e[0]=(t=this._w)!=null?t:s.w,$e[1]=(e=this._h)!=null?e:s.h}get width(){var t;return(t=this._w)!=null?t:this.bake().w}set width(t){this._w=t}get height(){var t;return(t=this._h)!=null?t:this.bake().h}set height(t){this._h=t}},zi=(t,e,s)=>t===void 0?e:typeof t=="number"?t:t[0]+(t[1]-t[0])*s(),Di=class As extends Ne{constructor(e,s,n={}){var i,a,o,r;super(e),p(this,"max"),p(this,"f"),p(this,"tints"),p(this,"count",0),p(this,"gravity"),p(this,"drag"),p(this,"frameRef"),p(this,"random",Math.random),this.frameRef=s,this.max=Math.max(1,Math.floor((i=n.max)!=null?i:200)),this.f=new Float32Array(this.max*As.W),this.tints=new Uint32Array(this.max),this.blend=(a=n.blend)!=null?a:"normal",this.gravity=(o=n.gravity)!=null?o:0,this.drag=(r=n.drag)!=null?r:1}get alive(){return this.count}burst(e,s,n,i={}){var a,o,r,h,l;const c=As.W,f=this.random,u=i.tint===void 0?16777215:ne(i.tint)[0];for(let y=0;y<n;y++){let d=this.count;if(d>=this.max){let _=0,T=1/0;for(let N=0;N<this.max;N++){const R=this.f[N*c+5]-this.f[N*c+4];R<T&&(T=R,_=N)}d=_}else this.count++;const b=((a=i.angle)!=null?a:0)+(i.spread===void 0?f()*Math.PI*2:(f()-.5)*i.spread),m=zi(i.speed,200,f),x=Array.isArray(i.scale)?i.scale[0]:(o=i.scale)!=null?o:1,g=Array.isArray(i.scale)?i.scale[1]:(r=i.scale)!=null?r:1,v=d*c;this.f[v]=e,this.f[v+1]=s,this.f[v+2]=Math.cos(b)*m,this.f[v+3]=Math.sin(b)*m,this.f[v+4]=0,this.f[v+5]=Math.max(zi(i.life,.8,f),.01),this.f[v+6]=f()*Math.PI*2,this.f[v+7]=(f()-.5)*2*((h=i.spin)!=null?h:0),this.f[v+8]=x,this.f[v+9]=g,this.f[v+10]=(l=i.alpha)!=null?l:1,this.tints[d]=u}}update(e){const s=As.W,n=this.f,i=this.drag>=1?1:Math.pow(Math.max(this.drag,0),e);for(let a=0;a<this.count;){const o=a*s;if(n[o+4]=n[o+4]+e,n[o+4]>=n[o+5]){const r=--this.count;a!==r&&(n.copyWithin(o,r*s,r*s+s),this.tints[a]=this.tints[r]);continue}n[o+3]=(n[o+3]+this.gravity*e)*i,n[o+2]=n[o+2]*i,n[o]=n[o]+n[o+2]*e,n[o+1]=n[o+1]+n[o+3]*e,n[o+6]=n[o+6]+n[o+7]*e,a++}}clear(){this.count=0}draw(e,s,n){if(!this.count)return;const i=typeof this.frameRef=="string"?this.frameRef=this.kernel.frame(this.frameRef):this.frameRef,a=As.W,o=this.f,r=this.world,h=i.w/i.scale,l=i.h/i.scale;for(let c=0;c<this.count;c++){const f=c*a,u=o[f+4]/o[f+5],y=o[f+8]+(o[f+9]-o[f+8])*u,d=s*o[f+10]*(1-u*u),b=o[f+6],m=Math.cos(b)*y,x=Math.sin(b)*y,g=o[f],v=o[f+1],_=r[0],T=r[1],N=r[2],R=r[3],M=_*m+N*x,P=T*m+R*x,z=N*m-_*x,U=R*m-T*x;Et[0]=M,Et[1]=P,Et[2]=z,Et[3]=U,Et[4]=_*g+N*v+r[4]-(M*h+z*l)/2,Et[5]=T*g+R*v+r[5]-(P*h+U*l)/2,ft[0]=h,ft[1]=l,ft[2]=d,e.r.quadQ(e.tex(i.surface),i,Et,Si(n,this.tints[c]),this.blend)}}};p(Di,"W",11);var Bi=Di,Oe=class extends Ke{constructor(t,e,s={}){const n=s,{fps:i,loop:a,playing:o,speed:r,onComplete:h}=n,l=hn(n,["fps","loop","playing","speed","onComplete"]);if(!e.frames.length)throw new Error("[engine] an animation needs at least one frame");super(t,e.frames[0],l),p(this,"frames"),p(this,"durations"),p(this,"fps"),p(this,"loop"),p(this,"speed"),p(this,"onComplete"),p(this,"_playing"),p(this,"index",0),p(this,"t",0),this.frames=e.frames,this.durations=e.durations&&i===void 0?e.durations:null,this.fps=i!=null?i:12,this.loop=a!==!1,this.speed=r!=null?r:1,this.onComplete=h!=null?h:null,this._playing=o!==!1,this.speed<0&&this.show(e.frames.length-1)}get frameIndex(){return this.index}get frameCount(){return this.frames.length}get playing(){return this._playing}play(){return!this.loop&&!this._playing&&this.index===(this.speed<0?0:this.frames.length-1)&&this.show(this.speed<0?this.frames.length-1:0),this._playing=!0,this}stop(){return this._playing=!1,this}gotoFrame(t){const e=this.frames.length;return this.show((Math.floor(t)%e+e)%e),this.t=0,this}gotoAndPlay(t){return this._playing=!0,this.gotoFrame(t)}gotoAndStop(t){return this._playing=!1,this.gotoFrame(t)}show(t){t===this.index&&this._frame||(this.index=t,this.frame=this.frames[t])}secondsOf(t){var e;const s=(e=this.durations)==null?void 0:e[t];return s!==void 0&&s>0?s:1/Math.max(this.fps,.001)}update(t){var e;if(!this._playing||this.destroyed||this.speed===0)return;const s=this.frames.length,n=this.speed<0;this.t+=t*Math.abs(this.speed);let i=this.index;for(let a=0;a<1e3;a++){const o=this.secondsOf(i);if(this.t<o)break;this.t-=o;const r=n?i-1:i+1;if(r<0||r>=s){if(!this.loop){this.t=0,this._playing=!1,this.show(i),(e=this.onComplete)==null||e.call(this);return}i=n?s-1:0}else i=r}this.show(i)}},Mo=(t,e)=>t.localeCompare(e,void 0,{numeric:!0}),Ui=class{constructor(t,e,s=2){p(this,"width",t),p(this,"height",e),p(this,"padding",s),p(this,"shelves",[]),p(this,"free",[]),p(this,"bottom",0)}alloc(t,e){const s=Math.ceil(t)+this.padding*2,n=Math.ceil(e)+this.padding*2;if(s>this.width||n>this.height)return null;for(let o=0;o<this.free.length;o++){const r=this.free[o];if(r.w>=s&&r.h>=n&&r.w*r.h<=s*n*2)return this.free.splice(o,1),We(A({},this.inner(r.x,r.y,t,e)),{slot:r})}let i=null;for(const o of this.shelves)o.h>=n&&o.h<=n*1.5+8&&this.width-o.x>=s&&(!i||o.h<i.h)&&(i=o);if(!i)if(this.bottom+n>this.height){for(const o of this.shelves)o.h>=n&&this.width-o.x>=s&&(i=o);if(!i)return null}else i={y:this.bottom,h:n,x:0},this.shelves.push(i),this.bottom+=n;const a=i.x;return i.x+=s,this.inner(a,i.y,t,e)}release(t){this.free.push({x:t.x-this.padding,y:t.y-this.padding,w:Math.ceil(t.w)+this.padding*2,h:Math.ceil(t.h)+this.padding*2})}get fill(){return this.bottom/this.height}reset(){this.shelves=[],this.free=[],this.bottom=0}inner(t,e,s,n){return{x:t+this.padding,y:e+this.padding,w:s,h:n}}},Ds=t=>({source:t,texture:null,pending:[]}),Tn=class{constructor(t=2048,e=4){p(this,"pageSize",t),p(this,"maxPages",e),p(this,"pages",[]),p(this,"gen",1),p(this,"onPage",()=>{}),p(this,"onDrop",()=>{})}valid(t){return!!t&&(t.gen===this.gen||t.gen===0)}bake(t,e,s,n=1,i=0,a=0,o=0){const r=Math.max(1,Math.ceil(t)),h=Math.max(1,Math.ceil(e)),l=document.createElement("canvas");l.width=r,l.height=h;const c=l.getContext("2d");return s(c),this.put(l,r,h,n,i,a,o)}add(t,e=1,s=0,n=0){const i=document.createElement("canvas");return i.width=Math.max(1,t.width),i.height=Math.max(1,t.height),i.getContext("2d").drawImage(t,0,0),this.put(i,i.width,i.height,e,s,n,0)}release(t){if(t.gen!==this.gen)return;const e=this.pages.find(s=>s.surface===t.surface);e==null||e.packer.release(t)}rebake(t,e,s,n,i=t.w,a=t.h){if(!this.valid(t)||e>i||s>a)return null;const o=Math.max(1,Math.ceil(e)),r=Math.max(1,Math.ceil(s)),h=this.pages.find(c=>c.surface===t.surface);if(!h)return null;const l=document.createElement("canvas");return l.width=Math.ceil(i),l.height=Math.ceil(a),n(l.getContext("2d")),h.ctx.clearRect(t.x,t.y,l.width,l.height),h.ctx.drawImage(l,t.x,t.y),t.surface.pending.push([l,t.x,t.y]),t.w=o,t.h=r,t}put(t,e,s,n,i,a,o){let r=null,h=this.pages.find(c=>(r=c.packer.alloc(e,s))!==null);if(h||(!(Math.max(e,s)+4>this.pageSize)&&this.pages.length>=this.maxPages&&(this.wipe(),h=this.pages[0],r=h?h.packer.alloc(e,s):null),(!h||!r)&&(h=this.newPage(Math.max(e,s)),r=h.packer.alloc(e,s))),!r)throw new Error("[engine] ".concat(e,"\xD7").concat(s," does not fit an atlas page"));const l=r;if(l.slot){const c=l.slot;h.ctx.clearRect(c.x,c.y,c.w,c.h);const f=document.createElement("canvas");f.width=c.w,f.height=c.h,f.getContext("2d").drawImage(t,l.x-c.x,l.y-c.y),h.surface.pending.push([f,c.x,c.y])}else h.surface.pending.push([t,l.x,l.y]);return h.ctx.drawImage(t,l.x,l.y),{surface:h.surface,x:l.x,y:l.y,w:e,h:s,scale:n,gen:this.gen,ox:i,oy:a,margin:o}}newPage(t){let e=this.pageSize;for(;e<t+4;)e*=2;const s=document.createElement("canvas");s.width=s.height=e;const n=s.getContext("2d"),i=Ds(s),a={surface:i,packer:new Ui(e,e),ctx:n};return this.pages.push(a),this.onPage(i),a}wipe(){this.gen++;let t=0;for(let e=0;e<this.pages.length;e++){const s=this.pages[e];if(t<this.maxPages&&s.surface.source.width===this.pageSize){this.pages[t++]=s;continue}s.surface.pending=[],this.onDrop(s.surface)}this.pages.length=t;for(const e of this.pages)e.packer.reset(),e.ctx.clearRect(0,0,e.surface.source.width,e.surface.source.height),e.surface.pending=[],e.surface.pending.push([e.surface.source,0,0])}},Eo=()=>{var t,e,s;const n=typeof document!="undefined"?(t=document.timeline)==null?void 0:t.currentTime:null;return typeof n=="number"&&Number.isFinite(n)?n:(s=(e=le.performance)==null?void 0:e.now())!=null?s:Date.now()},Hi=()=>{var t,e;return(e=(t=le.performance)==null?void 0:t.now())!=null?e:Date.now()},Ao=class{constructor(t=Eo){p(this,"now",t),p(this,"known",new Map),p(this,"smoothed",new Map),p(this,"times",new WeakMap),p(this,"lerp",new ki),p(this,"amount",Cn),p(this,"drawnAt",NaN),p(this,"drawn",0),p(this,"smoothedBody",(e,s={})=>{var n;const i=s.interpolate!==!1;if(typeof e=="number"){const a=this.smoothed.get(e);return a?i&&(n=this.lerp.at(e,this.tick()))!=null?n:a.body:null}return typeof e!="object"||e===null||!Array.isArray(e.body)?null:this.posed(e.id,e.body,So(s.smooth,this.defaultAmount),i)})}setLocal(t){this.amount=t?io:Cn,this.lerp=new ki(t?Jr:{}),this.smoothed.clear()}get defaultAmount(){return this.amount}note(t,e,s=Hi()){for(const n of t)this.known.set(n.id,this.resolve(n.id,n.avatar)),e!==void 0&&Number.isFinite(e)&&Array.isArray(n.body)&&this.times.set(n.body,{t:e,arrival:s})}of(t){var e;return typeof t=="object"&&t!==null?t.avatar!==void 0?this.resolve(t.id,t.avatar):this.of(t.id):(e=this.known.get(t))!=null?e:si(t-1)}posed(t,e,s,n=!0){var i;const a=this.smooth(t,e,s);return n&&(i=this.lerp.at(t,this.tick()))!=null?i:a}smooth(t,e,s){var n,i;const a=this.smoothed.get(t);if(a&&a.raw===e&&a.amount===s)return a.body;a&&a.amount!==s&&this.lerp.forget(t);const o=s<1?no(a==null?void 0:a.body,e,s):e;this.smoothed.set(t,{raw:e,body:o,amount:s});const r=this.times.get(e),h=(n=r==null?void 0:r.arrival)!=null?n:Hi();return this.lerp.push(t,(i=r==null?void 0:r.t)!=null?i:h,o,h),o}takeDrawn(){const t=this.drawn;return this.drawn=0,t}tick(){const t=this.now();return t!==this.drawnAt&&(this.drawnAt=t,this.drawn++),t}resolve(t,e){return to(e)?e:si(t-1)}},Cn=.5,So=(t,e=Cn)=>t===!1?1:typeof t=="number"?Math.min(Math.max(t,.05),1):e,Gi=new Float64Array(1),Xi=new Int32Array(Gi.buffer),ts=(t,e)=>(t=Math.imul(t^e,1540483477),t^t>>>15);function ve(t,e=2538058380){return t!==t?ts(e,2146959360):(Gi[0]=t===0?0:t,ts(ts(e,Xi[0]),Xi[1]))}function qi(t,e=2166136261){for(let s=0;s<t.length;s++)e=Math.imul(e^t.charCodeAt(s),16777619);return e}function ke(t){switch(typeof t){case"number":return ve(t);case"string":return qi(t);case"boolean":return t?1013904242:461845907;case"object":{if(t===null)return 625341585;if(Array.isArray(t)||t instanceof Float64Array){let n=1779033703^t.length;for(let i=0;i<t.length;i++){const a=t[i];n=ts(n,typeof a=="number"?ve(a):ke(a))}return n}let e=1359893119;const s=t;for(const n in s){const i=s[n];i!==void 0&&(e=e+ts(qi(n),ke(i))|0)}return ts(e,2600822924)}default:return 0}}function ms(t,e){if(t===e)return!0;if(typeof t!="object"||typeof e!="object"||t===null||e===null)return typeof t=="number"&&typeof e=="number"&&t!==t&&e!==e;const s=Array.isArray(t)||t instanceof Float64Array;if(s!==(Array.isArray(e)||e instanceof Float64Array))return!1;if(s){const a=t,o=e;if(a.length!==o.length)return!1;for(let r=0;r<a.length;r++)if(a[r]!==o[r]&&!ms(a[r],o[r]))return!1;return!0}const n=t,i=e;for(const a in n)if(n[a]!==void 0&&!ms(n[a],i[a]))return!1;for(const a in i)if(i[a]!==void 0&&n[a]===void 0)return!1;return!0}function Bs(t){if(typeof t!="object"||t===null)return t;if(Array.isArray(t))return t.map(Bs);if(t instanceof Float64Array)return t.slice();const e={};for(const s in t)t[s]!==void 0&&(e[s]=Bs(t[s]));return e}var Wi=class{constructor(t=1/0){p(this,"max",t),p(this,"buckets",new Map),p(this,"n",0)}get size(){return this.n}get(t,e=ke(t)){const s=this.buckets.get(e);if(s){for(let n=0;n<s.length;n++)if(ms(s[n].key,t))return s[n].value}}set(t,e,s=ke(t)){let n=this.buckets.get(s);if(n){for(const i of n)if(ms(i.key,t)){i.value=e;return}}this.n>=this.max&&this.clear(),(!n||!this.buckets.has(s))&&this.buckets.set(s,n=[]),n.push({key:Bs(t),value:e}),this.n++}clear(){this.buckets.clear(),this.n=0}},Rn=0,ji=1,Us=2,Fn=3,Yi=class{constructor(){p(this,"scale",1),p(this,"cOn",!1),p(this,"px0",0),p(this,"py0",0),p(this,"px1",0),p(this,"py1",0),p(this,"clipVer",0),p(this,"stack",[]),p(this,"sp",0),p(this,"real",0),p(this,"mute",0),p(this,"bnd",new Float64Array(4*(_n+1))),p(this,"rx0",0),p(this,"ry0",0),p(this,"rx1",0),p(this,"ry1",0),p(this,"maxBlur",1/0),p(this,"time",0),p(this,"skipped",0),p(this,"gq",new Float64Array(4))}resetLayers(t){this.scale=t,this.sp=this.real=this.mute=0,this.skipped=0,this.cOn=!1,this.clipVer++}growQ(){const t=this.gq;this.grow(t[0],t[1],t[2],t[3])}grow(t,e,s,n){if(!this.real)return;const i=this.bnd,a=(this.real-1)*4;t<i[a]&&(i[a]=t),e<i[a+1]&&(i[a+1]=e),s>i[a+2]&&(i[a+2]=s),n>i[a+3]&&(i[a+3]=n)}area(t,e){const s=this.bnd,n=t*4,i=this.scale;return this.rx0=Math.max(Math.floor((s[n]-e)*i)-1,0),this.ry0=Math.max(Math.floor((s[n+1]-e)*i)-1,0),this.rx1=Math.min(Math.ceil((s[n+2]+e)*i)+1,this.canvas.width),this.ry1=Math.min(Math.ceil((s[n+3]+e)*i)+1,this.canvas.height),this.rx1>this.rx0&&this.ry1>this.ry0}clip(t,e,s,n){const i=this.scale,a=this.canvas.width,o=this.canvas.height,r=Math.min(Math.max(Math.round(t*i),0),a),h=Math.min(Math.max(Math.round(e*i),0),o),l=Math.min(Math.max(Math.round((t+s)*i),r),a),c=Math.min(Math.max(Math.round((e+n)*i),h),o);this.cOn&&r===this.px0&&h===this.py0&&l===this.px1&&c===this.py1||(this.cOn=!0,this.px0=r,this.py0=h,this.px1=l,this.py1=c,this.clipVer++)}unclip(){this.cOn&&(this.cOn=!1,this.clipVer++)}push(t){if(t<Us&&(this.mute||this.real>=_n||!this.pushLayer())&&(t+=2),t===Fn)this.mute++;else if(t!==Us){const e=this.real*4;this.bnd[e]=this.bnd[e+1]=1/0,this.bnd[e+2]=this.bnd[e+3]=-1/0,this.real++}return this.stack[this.sp++]=t,t<Us}beginLayer(){return this.push(Rn)}beginMask(){this.push(this.sp&&this.stack[this.sp-1]===Rn?ji:Fn)}endLayer(t,e){if(!this.sp)return;let s=this.stack[--this.sp];if(s===Fn){if(this.mute--,!this.sp)return;s=this.stack[--this.sp]}if(s===ji){const n=--this.real,i=this.popLayer();this.area(n-1,0)&&this.composite(i,!0,1,null);const a=this.bnd,o=(n-1)*4,r=n*4;a[o]=Math.max(a[o],a[r]),a[o+1]=Math.max(a[o+1],a[r+1]),a[o+2]=Math.min(a[o+2],a[r+2]),a[o+3]=Math.min(a[o+3],a[r+3]),s=this.stack[--this.sp]}if(s===Us)wn(e)&&(this.skipped+=e.length);else if(s===Rn){const n=--this.real,i=wn(e)?e:null,a=this.popLayer();if(this.area(n,i?vo(i,this.maxBlur):0)){this.composite(a,!1,t,i);const o=this.scale;this.grow(this.rx0/o,this.ry0/o,this.rx1/o,this.ry1/o)}}}closeLayers(){for(;this.sp;)this.endLayer(1)}},To=256,Qi=8<<20,Ht=new Float64Array(32),Gt={x:0,y:0,w:0,h:0};function Co(t){if(typeof t.filter!="string")return!1;t.filter="blur(1px)";const e=t.filter==="blur(1px)";return t.filter="none",e}function Pn(t){const e=t.getContext("2d",{alpha:!0});return e?new Ro(t,e):null}var Ro=class extends Yi{constructor(t,e){super(),p(this,"canvas",t),p(this,"ctx",e),p(this,"kind","canvas2d"),p(this,"maxTextureSize",4096),p(this,"features",{}),p(this,"info",{renderer:"canvas2d"}),p(this,"support"),p(this,"lost",!1),p(this,"fxr",null),p(this,"quads",0),p(this,"stats",{drawCalls:0,quads:0,filtersSkipped:0}),p(this,"tinted",new Map),p(this,"tintedN",0),p(this,"lostListeners",[]),p(this,"restoredListeners",[]),p(this,"base"),p(this,"top"),p(this,"layers",[]),p(this,"scratch",[]),p(this,"nines",new Map),p(this,"ninePx",0),p(this,"frame",0),p(this,"hit",!1),p(this,"missed",new Map),this.support={filters:Co(e),shaders:!1},this.base=this.top={ctx:e,clipped:!1,ver:0},t.addEventListener("contextlost",()=>{this.lost=!0,this.lostListeners.forEach(s=>s())}),t.addEventListener("contextrestored",()=>{this.lost=!1,this.tinted.clear(),this.tintedN=0,this.dropNines(),this.restoredListeners.forEach(s=>s())})}resize(t,e){this.canvas.width!==t&&(this.canvas.width=t),this.canvas.height!==e&&(this.canvas.height=e)}createTexture(t){return{id:Mn(),width:t.width,height:t.height,source:t}}updateTexture(t,e,s=0,n=0){const i=e?s+e.width:1/0,a=e?n+e.height:1/0;for(const o of this.nines.values()){const r=o.key;r[0]===t.id&&r[1]<i&&r[1]+r[3]>s&&r[2]<a&&r[2]+r[4]>n&&this.dropNine(o)}for(const[o,r]of this.tinted){const h=r.filter(l=>l.id!==t.id);this.tintedN-=r.length-h.length,h.length?this.tinted.set(o,h):this.tinted.delete(o)}}destroyTexture(t){this.updateTexture(t)}begin(t,e,s){var n;this.resetLayers(s),(n=this.fxr)==null||n.tick(),this.frame++,this.quads=0,this.top=this.base,this.ctx=this.base.ctx;const i=this.ctx;this.base.clipped&&i.restore(),this.base.clipped=!1,this.base.ver=this.clipVer,i.setTransform(1,0,0,1,0,0),i.globalAlpha=1,i.globalCompositeOperation="source-over",i.clearRect(0,0,this.canvas.width,this.canvas.height),e>0&&(i.fillStyle=hs(t,e),i.fillRect(0,0,this.canvas.width,this.canvas.height))}quad(t,e,s,n,i,a,o,r){ft[0]=n,ft[1]=i,ft[2]=o,this.quadQ(t,e,s,a,r)}quadQ(t,e,s,n,i){e.w<=0||e.h<=0||(n===16777215?this.blit(t.source,e.x,e.y,e.w,e.h,s,i):this.blit(this.tint(t,e,n),0,0,e.w,e.h,s,i))}blit(t,e,s,n,i,a,o){const r=ft[0],h=ft[1],l=ft[2];if(l<=0||this.mute)return;this.sync();const c=this.ctx,f=this.scale;if(this.real){const u=a[0]*r,y=a[1]*r,d=a[2]*h,b=a[3]*h;this.grow(a[4]+Math.min(0,u,d,u+d),a[5]+Math.min(0,y,b,y+b),a[4]+Math.max(0,u,d,u+d),a[5]+Math.max(0,y,b,y+b))}c.setTransform(a[0]*f,a[1]*f,a[2]*f,a[3]*f,a[4]*f,a[5]*f),c.globalAlpha=Math.min(l,1),o==="add"&&(c.globalCompositeOperation="lighter"),c.drawImage(t,e,s,n,i,0,0,r,h),o==="add"&&(c.globalCompositeOperation="source-over"),this.quads++}nineQ(t,e,s,n,i,a,o){var r,h,l;const c=s[8]+s[9],f=n[8]+n[9],u=Math.ceil(c*Math.hypot(i[0],i[1])*this.scale-1e-6),y=Math.ceil(f*Math.hypot(i[2],i[3])*this.scale-1e-6);if(i[1]===0&&i[2]===0||u>4096||y>4096)return!1;if(!(u>0&&y>0&&ft[2]>0)||this.mute)return!0;let d=this.kept(t,e,s,n,u,y,a);const b=(d!=null?d:d=(l=(r=this.scratch)[h=13*Math.ceil(Math.log2(u))+Math.ceil(Math.log2(y))])!=null?l:r[h]=document.createElement("canvas").getContext("2d")).canvas;if(b.width<u&&(b.width=u),b.height<y&&(b.height=y),!this.hit){d.clearRect(0,0,u+2,y+2);for(let m=0;m<12;m+=4){const x=Math.round(n[m]*y/f),g=Math.round((n[m]+n[m+1])*y/f);for(let v=0;v<12;v+=4){const _=Math.round(s[v]*u/c),T=Math.round((s[v]+s[v+1])*u/c);Gt.x=e.x+s[v+2],Gt.y=e.y+n[m+2],Gt.w=s[v+3],Gt.h=n[m+3],!(T<=_||g<=x||Gt.w<=0||Gt.h<=0)&&(a===16777215?d.drawImage(t.source,Gt.x,Gt.y,Gt.w,Gt.h,_,x,T-_,g-x):d.drawImage(this.tint(t,Gt,a),0,0,Gt.w,Gt.h,_,x,T-_,g-x))}}}return ft[0]=c,ft[1]=f,this.blit(b,0,0,u,y,i,o),!0}kept(t,e,s,n,i,a,o){Ht[0]=t.id,Ht[1]=e.x,Ht[2]=e.y,Ht[3]=e.w,Ht[4]=e.h,Ht[5]=i,Ht[6]=a,Ht[7]=o,Ht.set(s,8),Ht.set(n,20);const r=ke(Ht),h=this.nines.get(r);if(this.hit=!1,h)return ms(h.key,Ht)?(h.used=this.frame,this.hit=!0,h.ctx):null;const l=this.missed,c=l.get(r);l.size>4096&&l.clear(),l.set(r,this.frame);const f=i*a;if(c!==this.frame-1||f>Qi)return null;let u;for(;this.ninePx+f>Qi;){let b;for(const g of this.nines.values())g.used<this.frame-1&&!(b&&b.used<=g.used)&&(b=g);if(!b)return null;const m=b.ctx.canvas,x=!u&&m.width>=i&&m.height>=a&&m.width*m.height<=2*f;this.dropNine(b,x),x&&(u=b.ctx)}const y=u!=null?u:document.createElement("canvas").getContext("2d"),d=y.canvas;return u||(d.width=i,d.height=a),this.ninePx+=d.width*d.height,this.nines.set(r,{key:Bs(Ht),ctx:y,used:this.frame}),y}dropNine(t,e=!1){this.nines.delete(ke(t.key));const s=t.ctx.canvas;this.ninePx-=s.width*s.height,e||(s.width=0)}dropNines(){for(const t of this.nines.values())this.dropNine(t)}tint(t,e,s){const n=ve(s,ve(e.h,ve(e.w,ve(e.y,ve(e.x,ve(t.id))))));let i=this.tinted.get(n);if(i)for(let r=0;r<i.length;r++){const h=i[r];if(h.id===t.id&&h.x===e.x&&h.y===e.y&&h.w===e.w&&h.h===e.h&&h.color===s)return h.canvas}this.tintedN>=To&&(this.tinted.clear(),this.tintedN=0,i=void 0);const a=document.createElement("canvas");a.width=Math.ceil(e.w),a.height=Math.ceil(e.h);const o=a.getContext("2d");return o.drawImage(t.source,e.x,e.y,e.w,e.h,0,0,e.w,e.h),o.globalCompositeOperation="multiply",o.fillStyle=hs(s),o.fillRect(0,0,e.w,e.h),o.globalCompositeOperation="destination-in",o.drawImage(t.source,e.x,e.y,e.w,e.h,0,0,e.w,e.h),i||this.tinted.set(n,i=[]),i.push({id:t.id,x:e.x,y:e.y,w:e.w,h:e.h,color:s,canvas:a}),this.tintedN++,a}paint(t,e){this.sync();const s=this.ctx,n=this.scale;return s.setTransform(n,0,0,n,0,0),s.globalAlpha=Math.min(e,1),hs(t)}ellipse(t,e,s,n,i,a,o){if(o<=0||s<=0||n<=0||this.mute)return;const r=Math.max(s,n);this.grow(t-r,e-r,t+r,e+r);const h=this.ctx;h.fillStyle=this.paint(a,o),h.beginPath(),h.ellipse(t,e,s,n,i,0,Math.PI*2),h.fill(),this.quads++}trace(t,e,s=0){if(this.real)for(let i=0;i<e;i++)this.grow(t[i*2]-s,t[i*2+1]-s,t[i*2]+s,t[i*2+1]+s);const n=this.ctx;n.beginPath(),n.moveTo(t[0],t[1]);for(let i=1;i<e;i++)n.lineTo(t[i*2],t[i*2+1])}polygon(t,e,s,n){if(n<=0||e<3||this.mute)return;const i=this.ctx;i.fillStyle=this.paint(s,n),this.trace(t,e),i.closePath(),i.fill(),this.quads++}stroke(t,e,s,n,i,a){if(i<=0||s<=0||e<1||this.mute)return;const o=this.ctx;o.strokeStyle=this.paint(n,i),o.lineWidth=s,o.lineCap="round",o.lineJoin="round",this.trace(t,e,s/2),e===1&&o.lineTo(t[0],t[1]),a&&o.closePath(),o.stroke(),this.quads++}sync(){const t=this.top;if(t.ver===this.clipVer)return;const e=t.ctx;t.clipped&&e.restore(),t.clipped=this.cOn,t.ver=this.clipVer,this.cOn&&(e.save(),e.setTransform(1,0,0,1,0,0),e.beginPath(),e.rect(this.px0,this.py0,this.px1-this.px0,this.py1-this.py0),e.clip())}pushLayer(){const t=this.canvas.width,e=this.canvas.height;let s=this.layers[this.real];if(!s||s.ctx.canvas.width!==t||s.ctx.canvas.height!==e){const i=document.createElement("canvas");i.width=t,i.height=e;const a=i.getContext("2d");if(!a)return!1;s=this.layers[this.real]={ctx:a,clipped:!1,ver:-1}}const n=s.ctx;return s.clipped&&n.restore(),s.clipped=!1,s.ver=-1,n.setTransform(1,0,0,1,0,0),n.globalAlpha=1,n.globalCompositeOperation="source-over",n.clearRect(0,0,t,e),this.top=s,this.ctx=n,!0}popLayer(){return this.top=this.real>0?this.layers[this.real-1]:this.base,this.ctx=this.top.ctx,this.layers[this.real].ctx.canvas}composite(t,e,s,n){var i;let a=t,o="none";const r=n&&ie.c2d?(i=this.fxr)!=null?i:this.fxr=ie.c2d(this):null;r&&(a=r.chain(t,n),o=r.css),this.sync();const h=this.ctx,l=this.rx0,c=this.ry0,f=this.rx1-l,u=this.ry1-c;h.setTransform(1,0,0,1,0,0),h.globalAlpha=Math.min(s,1),h.globalCompositeOperation=e?"destination-in":"source-over",o!=="none"&&(h.filter=o),h.drawImage(a,l,c,f,u,l,c,f,u),o!=="none"&&(h.filter="none"),h.globalCompositeOperation="source-over",this.quads++}end(){this.closeLayers();const t=this.stats;return t.drawCalls=t.quads=this.quads,t.filtersSkipped=this.skipped,t}onLost(t){this.lostListeners.push(t)}onRestored(t){this.restoredListeners.push(t)}destroy(){var t;this.tinted.clear(),this.dropNines(),this.layers=[],this.scratch=[],(t=this.fxr)==null||t.destroy(),this.fxr=null}},xs=14,es=6,Vi=8192,Fo=class{constructor(t,e,s=Vi){p(this,"instanced",t),p(this,"slots",e),p(this,"capacity",s),p(this,"f32"),p(this,"u32"),p(this,"quads",0),p(this,"textures"),p(this,"bound",0),this.textures=new Array(e).fill(null);const n=s*(t?xs:es*4),i=new ArrayBuffer(n*4);this.f32=new Float32Array(i),this.u32=new Uint32Array(i)}slot(t){const e=this.textures;for(let s=0;s<this.bound;s++)if(e[s]===t)return s;return this.bound>=this.slots?-1:(e[this.bound]=t,this.bound++)}has(t){for(let e=0;e<this.bound;e++)if(this.textures[e]===t)return!0;return!1}get full(){return this.quads>=this.capacity}get words(){return this.quads*(this.instanced?xs:es*4)}reset(){this.quads=0;for(let t=0;t<this.bound;t++)this.textures[t]=null;this.bound=0}push(t,e,s,n,i,a,o,r,h,l,c,f,u,y){const d=this.f32;if(this.instanced){let b=this.quads*xs;d[b++]=t,d[b++]=e,d[b++]=s,d[b++]=n,d[b++]=i,d[b++]=a,d[b++]=o,d[b++]=r,d[b++]=h,d[b++]=l,d[b++]=c,d[b++]=f,this.u32[b++]=u,d[b]=y}else{const b=this.quads*es*4;this.vertex(b,t,e,h,l,u,y),this.vertex(b+6,s,n,c,l,u,y),this.vertex(b+12,i,a,c,f,u,y),this.vertex(b+18,o,r,h,f,u,y)}this.quads++}pushQ(t,e){const s=this.f32;if(this.instanced){const n=this.quads*xs;for(let i=0;i<12;i++)s[n+i]=t[i];this.u32[n+12]=t[12],s[n+13]=e}else{let n=this.quads*es*4;const i=t[12];for(let a=0;a<4;a++,n+=es)s[n]=t[a*2],s[n+1]=t[a*2+1],s[n+2]=a===1||a===2?t[10]:t[8],s[n+3]=a>=2?t[11]:t[9],this.u32[n+4]=i,s[n+5]=e}this.quads++}vertex(t,e,s,n,i,a,o){const r=this.f32;r[t]=e,r[t+1]=s,r[t+2]=n,r[t+3]=i,this.u32[t+4]=a,r[t+5]=o}};function Po(t){const e=new Uint16Array(t*6);for(let s=0,n=0,i=0;s<t;s++,n+=6,i+=4)e[n]=i,e[n+1]=i+1,e[n+2]=i+2,e[n+3]=i,e[n+4]=i+2,e[n+5]=i+3;return e}var Xt={M:0,L:1,Q:2,C:3,Z:4},Ki=[2,2,4,6,0],Lo={M:0,L:1,Q:2,C:3,Z:4};function Ln(t,e){if(t.length>=e)return t;const s=new Float64Array(Math.max(e,t.length*2,16));return s.set(t),s}var Hs=new Map;function No(t){var e,s;if(typeof t!="string")return t;let n=Hs.get(t);if(n)return n;n=[];const i=(e=t.match(/[MLQCZ]|-?\d*\.?\d+(?:e-?\d+)?/gi))!=null?e:[];let a=-1;for(let o=0;o<i.length;){const r=i[o],h=Lo[r.toUpperCase()];if(h!==void 0){a=h,o++,h===Xt.Z&&n.push(Xt.Z);continue}if(a<0||a===Xt.Z){o++;continue}const l=Ki[a];n.push(a);for(let c=0;c<l;c++)n.push(Number((s=i[o+c])!=null?s:0));o+=l,a===Xt.M&&(a=Xt.L)}return Hs.size>256&&Hs.clear(),Hs.set(t,n),n}var we={subs:[],count:0},Nn=null,_e=null;function Gs(t,e){var s;let n=_e;n||(n=(s=we.subs[we.count])!=null?s:null,n||we.subs.push(n={pts:new Float64Array(64),n:0,closed:!1}),n.n=0,n.closed=!1,we.count++,_e=n);const i=n.n*2;i+2>n.pts.length&&(n.pts=Ln(n.pts,i+2));const a=Nn;a?(n.pts[i]=a[0]*t+a[2]*e+a[4],n.pts[i+1]=a[1]*t+a[3]*e+a[5]):(n.pts[i]=t,n.pts[i+1]=e),n.n++}function In(t,e=null,s=1,n=6){const i=No(t);we.count=0,_e=null,Nn=e;let a=0,o=0,r=0,h=0;const l=s/n;for(let c=0;c<i.length;){const f=i[c++],u=i;if(f===Xt.M)_e=null,a=r=u[c],o=h=u[c+1],Gs(a,o);else if(f===Xt.L)a=u[c],o=u[c+1],Gs(a,o);else if(f===Xt.Q){const y=u[c],d=u[c+1],b=u[c+2],m=u[c+3],x=Zi((he(y-a,d-o)+he(b-y,m-d))*l);for(let g=1;g<=x;g++){const v=g/x,_=1-v;Gs(_*_*a+2*_*v*y+v*v*b,_*_*o+2*_*v*d+v*v*m)}a=b,o=m}else if(f===Xt.C){const y=u[c],d=u[c+1],b=u[c+2],m=u[c+3],x=u[c+4],g=u[c+5],v=Zi((he(y-a,d-o)+he(b-y,m-d)+he(x-b,g-m))*l);for(let _=1;_<=v;_++){const T=_/v,N=1-T,R=N*N*N,M=3*N*N*T,P=3*N*T*T,z=T*T*T;Gs(R*a+M*y+P*b+z*x,R*o+M*d+P*m+z*g)}a=x,o=g}else if(f===Xt.Z){_e&&(_e.closed=!0),_e=null,a=r,o=h;continue}else break;c+=Ki[f]}_e=null,Nn=null;for(let c=0;c<we.count;c++){const f=we.subs[c],u=f.n*2;f.closed&&f.n>=2&&Math.abs(f.pts[0]-f.pts[u-2])<1e-6&&Math.abs(f.pts[1]-f.pts[u-1])<1e-6&&f.n--}return we}var he=(t,e)=>Math.sqrt(t*t+e*e),Zi=t=>Math.min(Math.max(Math.ceil(t),2),24);function Io(t,e){let s=0;for(let n=0,i=e-1;n<e;i=n++)s+=(t[i*2]-t[n*2])*(t[i*2+1]+t[n*2+1]);return s}var Xs=new Int32Array(64),qs=(t,e,s,n,i)=>((t[n*2]-t[s*2])*(t[i*2+1]-t[s*2+1])-(t[n*2+1]-t[s*2+1])*(t[i*2]-t[s*2]))*e;function Oo(t,e,s){if(e<3)return 0;Xs.length<e&&(Xs=new Int32Array(Math.max(e,Xs.length*2)));const n=Xs;let i=e,a=0;for(let l=0;l<e;l++)n[l]=l;const o=Io(t,e)>0?1:-1;let r=e*e+8,h=0;for(;i>3&&r-- >0;){const l=n[(h+i-1)%i],c=n[h%i],f=n[(h+1)%i];let u=qs(t,o,l,c,f)>0;if(u)for(let y=0;y<i;y++){const d=n[y];if(!(d===l||d===c||d===f)&&qs(t,o,l,c,d)>=0&&qs(t,o,c,f,d)>=0&&qs(t,o,f,l,d)>=0){u=!1;break}}u?(s[a++]=l,s[a++]=c,s[a++]=f,n.copyWithin(h%i,h%i+1,i),i--,h=Math.max(h-1,0)):h=(h+1)%i}if(i===3)s[a++]=n[0],s[a++]=n[1],s[a++]=n[2];else if(i>3)for(let l=1;l+1<i;l++)s[a++]=n[0],s[a++]=n[l],s[a++]=n[l+1];return a}var zo=.85,Ws=new Float64Array(64),Ji=new Float64Array(64),$i=new Float64Array(64),ta=new Float64Array(64),ea=new Float64Array(64),sa=new Float64Array(64),na=new Uint8Array(64),js=new Float64Array(8);function Do(t,e,s,n,i,a){const o=js;if(Ws.length<e){const m=Math.max(e,Ws.length*2);Ws=new Float64Array(m),Ji=new Float64Array(m),$i=new Float64Array(m),ta=new Float64Array(m),ea=new Float64Array(m),sa=new Float64Array(m),na=new Uint8Array(m)}const r=Ws,h=Ji;let l=0;for(let m=0;m<e;m++){const x=t[m*2],g=t[m*2+1];!Number.isFinite(x)||!Number.isFinite(g)||l&&Math.abs(r[l-1]-x)<.001&&Math.abs(h[l-1]-g)<.001||(r[l]=x,h[l]=g,l++)}if(n&&l>2&&Math.abs(r[0]-r[l-1])<.001&&Math.abs(h[0]-h[l-1])<.001&&l--,l===0)return;if(l===1)return o[0]=r[0],o[1]=h[0],a();const c=n?l:l-1,f=$i,u=ta;for(let m=0;m<c;m++){const x=(m+1)%l,g=r[x]-r[m],v=h[x]-h[m],_=he(g,v)||1;f[m]=-v/_,u[m]=g/_}const y=ea,d=sa,b=na;for(let m=0;m<l;m++){const x=n?(m-1+c)%c:m-1,g=m<c?m:-1;if(b[m]=1,x<0||g<0||f[x]*f[g]+u[x]*u[g]<zo)continue;let _=f[x]+f[g],T=u[x]+u[g];const N=he(_,T)||1;_/=N,T/=N;const R=s/Math.max(_*f[g]+T*u[g],.5);y[m]=_*R,d[m]=T*R,b[m]=0}for(let m=0;m<c;m++){const x=(m+1)%l,g=b[m]?f[m]*s:y[m],v=b[m]?u[m]*s:d[m],_=b[x]?f[m]*s:y[x],T=b[x]?u[m]*s:d[x];o[0]=r[m]+g,o[1]=h[m]+v,o[2]=r[x]+_,o[3]=h[x]+T,o[4]=r[x]-_,o[5]=h[x]-T,o[6]=r[m]-g,o[7]=h[m]-v,i()}for(let m=0;m<l;m++)b[m]&&(o[0]=r[m],o[1]=h[m],a())}function ia(t,e){let s=0,n=1/0;for(let i=0;i<e.length;i++){const a=Math.abs(Math.log(Math.max(t,.5)/e[i]));a<n&&(n=a,s=i)}return s}var Vt=256,On=[{x:240,y:0,w:8,h:8,r:3},{x:224,y:0,w:16,h:16,r:7},{x:192,y:0,w:32,h:32,r:15},{x:128,y:0,w:64,h:64,r:31},{x:0,y:0,w:128,h:128,r:63}],zn=[4,8,16,32,64,128].map((t,e)=>({x:e*4,y:128,w:4,h:t,r:t/2-1})),Me={x:248,y:248,w:8,h:8},Bo=On.map(t=>t.r*2),Uo=zn.map(t=>t.r*2),aa=(t,e)=>Math.min(Math.max(t+.5-e,0),1);function Ho(){const t=new Uint8ClampedArray(Vt*Vt*4),e=(s,n,i)=>{const a=(n*Vt+s)*4;t[a]=t[a+1]=t[a+2]=255,t[a+3]=Math.round(i*255)};for(const s of On){const n=s.w/2;for(let i=0;i<s.h;i++)for(let a=0;a<s.w;a++)e(s.x+a,s.y+i,aa(s.r,Math.hypot(a+.5-n,i+.5-n)))}for(const s of zn){const n=s.h/2;for(let i=0;i<s.h;i++)for(let a=0;a<s.w;a++)e(s.x+a,s.y+i,aa(s.r,Math.abs(i+.5-n)))}for(let s=0;s<Me.h;s++)for(let n=0;n<Me.w;n++)e(Me.x+n,Me.y+s,1);return t}function Go(){const t=document.createElement("canvas");return t.width=t.height=Vt,t.getContext("2d").putImageData(new ImageData(Ho(),Vt,Vt),0,0),t}var ra=8,Dn="\n#ifdef GL_FRAGMENT_PRECISION_HIGH\nprecision highp float;\n#else\nprecision mediump float;\n#endif\n",Xo=t=>"".concat(Dn,"\nuniform sampler2D uTex[").concat(t,"];\nvarying vec2 vUv;\nvarying vec4 vColor;\nvarying float vSlot;\nvoid main() {\n vec4 c;\n ").concat(Array.from({length:t},(e,s)=>s===t-1?"c = texture2D(uTex[".concat(s,"], vUv);"):"if (vSlot < ".concat(s,".5) c = texture2D(uTex[").concat(s,"], vUv); else ")).join("\n "),"\n gl_FragColor = c * vColor;\n}"),qo="\nattribute vec2 aPos;\nattribute vec2 aUv;\nattribute vec4 aColor;\nattribute float aSlot;\nuniform vec2 uScale;\nvarying vec2 vUv;\nvarying vec4 vColor;\nvarying float vSlot;\nvoid main() {\n vUv = aUv;\n vColor = aColor;\n vSlot = aSlot;\n gl_Position = vec4(aPos * uScale + vec2(-1.0, 1.0), 0.0, 1.0);\n}",Wo="\nattribute vec4 aCorner;\nattribute vec4 aP01;\nattribute vec4 aP23;\nattribute vec4 aUvRect;\nattribute vec4 aColor;\nattribute float aSlot;\nuniform vec2 uScale;\nvarying vec2 vUv;\nvarying vec4 vColor;\nvarying float vSlot;\nvoid main() {\n vec2 p = aP01.xy * aCorner.x + aP01.zw * aCorner.y + aP23.xy * aCorner.z + aP23.zw * aCorner.w;\n vUv = vec2(mix(aUvRect.x, aUvRect.z, aCorner.y + aCorner.z), mix(aUvRect.y, aUvRect.w, aCorner.z + aCorner.w));\n vColor = aColor;\n vSlot = aSlot;\n gl_Position = vec4(p * uScale + vec2(-1.0, 1.0), 0.0, 1.0);\n}",jo={alpha:!0,premultipliedAlpha:!0,antialias:!1,depth:!1,stencil:!1,preserveDrawingBuffer:!1,powerPreference:"high-performance"},Yo=["aCorner","aP01","aP23","aUvRect","aColor","aSlot"],Qo=["aPos","aUv","aColor","aSlot"];function Vo(t,e,s={}){var n,i;const a=We(A({},jo),{failIfMajorPerformanceCaveat:s.failIfMajorPerformanceCaveat!==!1}),o=e===2?t.getContext("webgl2",a):(n=t.getContext("webgl",a))!=null?n:t.getContext("experimental-webgl",a);if(!o||o.isContextLost())return null;try{return new Ko(t,o,e,s)}catch(r){return console.warn("[engine] WebGL setup failed:",r),(i=o.getExtension("WEBGL_lose_context"))==null||i.loseContext(),null}}var Ko=class extends Yi{constructor(t,e,s,n){super(),p(this,"canvas",t),p(this,"gl",e),p(this,"opts",n),p(this,"kind"),p(this,"maxTextureSize"),p(this,"support",{filters:!0,shaders:!0}),p(this,"features",{}),p(this,"info",{}),p(this,"lost",!1),p(this,"main"),p(this,"cur"),p(this,"unit",-1),p(this,"onUnit",new Array(ra).fill(void 0)),p(this,"fbNow"),p(this,"mapped",!0),p(this,"calls",{useProgram:0,bindTexture:0,activeTexture:0,bindFramebuffer:0}),p(this,"vsrc",""),p(this,"attrs",[]),p(this,"fxr",null),p(this,"batch"),p(this,"dynamic"),p(this,"staticBuf",null),p(this,"index"),p(this,"vao",null),p(this,"inst",null),p(this,"vaoApi",null),p(this,"uScale",null),p(this,"textures",new Map),p(this,"kit"),p(this,"stats",{drawCalls:0,quads:0,filtersSkipped:0}),p(this,"lostListeners",[]),p(this,"restoredListeners",[]),p(this,"tris",new Int32Array(192)),p(this,"sU",0),p(this,"sV0",0),p(this,"sV1",0),p(this,"sColor",0),p(this,"sPacked",0),p(this,"sAlpha",0),p(this,"sHw",0),p(this,"strokeSeg",()=>{const i=this.q;i.set(js),i[8]=i[10]=this.sU,i[9]=this.sV0,i[11]=this.sV1,i[12]=this.sPacked,this.put(this.kit)}),p(this,"strokeDisc",()=>this.ellipse(js[0],js[1],this.sHw,this.sHw,0,this.sColor,this.sAlpha)),p(this,"q",new Float64Array(13)),p(this,"layers",[]),p(this,"layerTex",new Map),p(this,"bScis",!1),p(this,"bx0",0),p(this,"by0",0),p(this,"bx1",0),p(this,"by1",0),p(this,"onContextLost",i=>{i.preventDefault(),this.lost=!0;for(const a of this.lostListeners)a()}),p(this,"onContextRestored",()=>{try{this.layers=[],this.layerTex.clear(),this.fxr=null,this.resetLayers(this.scale),this.setup();for(const i of this.textures.keys())this.textures.set(i,this.upload(i.source));this.lost=!1;for(const i of this.restoredListeners)i()}catch(i){console.warn("[engine] WebGL restore failed:",i)}}),p(this,"views",new Map),this.kind=s===2?"webgl2":"webgl1",this.maxTextureSize=e.getParameter(e.MAX_TEXTURE_SIZE),this.setup(),this.kit=this.createTexture(Go()),ie.live=this,t.addEventListener("webglcontextlost",this.onContextLost,!1),t.addEventListener("webglcontextrestored",this.onContextRestored,!1)}setup(){const t=this.gl,e=this.kind==="webgl2"?t:null;if(this.inst=null,this.opts.instancing!==!1)if(e)this.inst={divisor:(l,c)=>e.vertexAttribDivisor(l,c),draw:(l,c)=>e.drawElementsInstanced(t.TRIANGLES,l,t.UNSIGNED_SHORT,0,c)};else{const l=t.getExtension("ANGLE_instanced_arrays");l&&(this.inst={divisor:(c,f)=>l.vertexAttribDivisorANGLE(c,f),draw:(c,f)=>l.drawElementsInstancedANGLE(t.TRIANGLES,c,t.UNSIGNED_SHORT,0,f)})}if(this.vaoApi=null,this.opts.vao!==!1)if(e)this.vaoApi={create:()=>e.createVertexArray(),bind:l=>e.bindVertexArray(l),remove:l=>e.deleteVertexArray(l)};else{const l=t.getExtension("OES_vertex_array_object");l&&(this.vaoApi={create:()=>l.createVertexArrayOES(),bind:c=>l.bindVertexArrayOES(c),remove:c=>l.deleteVertexArrayOES(c)})}const s=t.getParameter(t.MAX_TEXTURE_IMAGE_UNITS),n=Math.max(1,Math.min(ra,s)),i=this.inst!==null;this.vsrc=i?Wo:qo,this.attrs=i?Yo:Qo,this.main=this.cur=this.build(Xo(n));const a=this.main.p;t.useProgram(a),this.calls.useProgram++,this.unit=-1,this.onUnit.fill(void 0),this.fbNow=void 0,this.uScale=this.main.uScale,t.uniform1iv(t.getUniformLocation(a,"uTex"),Int32Array.from({length:n},(l,c)=>c)),this.batch=new Fo(i,n),this.vaoApi&&(this.vao=this.vaoApi.create(),this.vaoApi.bind(this.vao)),this.dynamic=t.createBuffer(),t.bindBuffer(t.ARRAY_BUFFER,this.dynamic),t.bufferData(t.ARRAY_BUFFER,this.batch.f32.byteLength,t.DYNAMIC_DRAW),this.index=t.createBuffer(),t.bindBuffer(t.ELEMENT_ARRAY_BUFFER,this.index),t.bufferData(t.ELEMENT_ARRAY_BUFFER,Po(i?1:Vi),t.STATIC_DRAW);const o=l=>t.getAttribLocation(a,l),r=(l,c,f,u,y,d,b)=>{const m=o(l);m<0||(t.enableVertexAttribArray(m),t.vertexAttribPointer(m,c,f,u,y,d),this.inst&&this.inst.divisor(m,b))};if(i){const l=xs*4;r("aP01",4,t.FLOAT,!1,l,0,1),r("aP23",4,t.FLOAT,!1,l,16,1),r("aUvRect",4,t.FLOAT,!1,l,32,1),r("aColor",4,t.UNSIGNED_BYTE,!0,l,48,1),r("aSlot",1,t.FLOAT,!1,l,52,1),this.staticBuf=t.createBuffer(),t.bindBuffer(t.ARRAY_BUFFER,this.staticBuf),t.bufferData(t.ARRAY_BUFFER,Float32Array.of(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1),t.STATIC_DRAW),r("aCorner",4,t.FLOAT,!1,16,0,0),t.bindBuffer(t.ARRAY_BUFFER,this.dynamic)}else{const l=es*4;r("aPos",2,t.FLOAT,!1,l,0,0),r("aUv",2,t.FLOAT,!1,l,8,0),r("aColor",4,t.UNSIGNED_BYTE,!0,l,16,0),r("aSlot",1,t.FLOAT,!1,l,20,0)}t.enable(t.BLEND),t.blendFunc(t.ONE,t.ONE_MINUS_SRC_ALPHA),t.disable(t.DEPTH_TEST),t.disable(t.CULL_FACE),t.pixelStorei(t.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!0);const h=t.getExtension("WEBGL_debug_renderer_info");this.info={version:t.getParameter(t.VERSION),renderer:h?t.getParameter(h.UNMASKED_RENDERER_WEBGL):t.getParameter(t.RENDERER),vendor:h?t.getParameter(h.UNMASKED_VENDOR_WEBGL):t.getParameter(t.VENDOR)},this.features={instancing:i,vao:this.vaoApi!==null,textureSlots:n,maxTextureSize:this.maxTextureSize}}upload(t){const e=this.gl,s=e.createTexture();return this.bindTex(s),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,e.RGBA,e.UNSIGNED_BYTE,t),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),s}resize(t,e){this.canvas.width!==t&&(this.canvas.width=t),this.canvas.height!==e&&(this.canvas.height=e)}createTexture(t){const e={id:Mn(),width:t.width,height:t.height,source:t};return this.textures.set(e,this.lost?null:this.upload(t)),e}updateTexture(t,e,s=0,n=0){if(this.lost)return;this.batch.has(t)&&this.flush();const i=this.gl,a=this.textures.get(t);a&&(this.bindTex(a),!e||e===t.source&&s===0&&n===0?i.texImage2D(i.TEXTURE_2D,0,i.RGBA,i.RGBA,i.UNSIGNED_BYTE,t.source):i.texSubImage2D(i.TEXTURE_2D,0,s,n,i.RGBA,i.UNSIGNED_BYTE,e))}destroyTexture(t){this.batch.has(t)&&this.flush();const e=this.textures.get(t);e&&!this.lost&&this.deleteTex(e),this.textures.delete(t)}begin(t,e,s){if(this.stats.drawCalls=this.stats.quads=this.stats.filtersSkipped=0,this.batch.reset(),this.resetLayers(s),this.bScis=!1,this.lost)return;const n=this.gl;n.disable(n.SCISSOR_TEST),this.bindFb(null),n.viewport(0,0,this.canvas.width,this.canvas.height);const i=e;n.clearColor((t>>16&255)/255*i,(t>>8&255)/255*i,(t&255)/255*i,i),n.clear(n.COLOR_BUFFER_BIT),this.use(this.main),n.uniform2f(this.uScale,2*s/this.canvas.width,-2*s/this.canvas.height),this.mapped=!0}build(t){var e;const s=this.gl,n=oa(s,s.VERTEX_SHADER,this.vsrc);let i;try{i=oa(s,s.FRAGMENT_SHADER,t)}catch(o){throw s.deleteShader(n),o}const a=s.createProgram();if(s.attachShader(a,n),s.attachShader(a,i),this.attrs.forEach((o,r)=>s.bindAttribLocation(a,r,o)),s.linkProgram(a),s.deleteShader(n),s.deleteShader(i),!s.getProgramParameter(a,s.LINK_STATUS)){const o=(e=s.getProgramInfoLog(a))!=null?e:"?";throw s.deleteProgram(a),new Error("link: ".concat(o))}return{p:a,uScale:s.getUniformLocation(a,"uScale"),locs:new Map}}u(t,e){let s=t.locs.get(e);return s===void 0&&t.locs.set(e,s=this.gl.getUniformLocation(t.p,e)),s}use(t){this.cur!==t&&(this.cur=t,this.gl.useProgram(t.p),this.calls.useProgram++)}bindTex(t,e=this.unit<0?0:this.unit){const s=this.gl;this.onUnit[e]!==t&&(this.unit!==e&&(s.activeTexture(s.TEXTURE0+e),this.calls.activeTexture++,this.unit=e),s.bindTexture(s.TEXTURE_2D,t),this.calls.bindTexture++,this.onUnit[e]=t)}deleteTex(t){this.gl.deleteTexture(t);for(let e=0;e<this.onUnit.length;e++)this.onUnit[e]===t&&(this.onUnit[e]=null)}bindFb(t){if(t)for(let s=0;s<this.onUnit.length;s++)this.onUnit[s]===t.gl&&this.bindTex(null,s);const e=t?t.fb:null;this.fbNow!==e&&(this.gl.bindFramebuffer(this.gl.FRAMEBUFFER,e),this.calls.bindFramebuffer++,this.fbNow=e)}slotOf(t){this.batch.full&&this.flush();let e=this.batch.slot(t);return e<0&&(this.flush(),e=this.batch.slot(t)),e}quad(t,e,s,n,i,a,o,r){ft[0]=n,ft[1]=i,ft[2]=o,this.quadQ(t,e,s,a,r)}quadQ(t,e,s,n,i){const a=ft[2];if(this.lost||a<=0)return;const o=this.q,r=ft[0],h=ft[1],l=s[4],c=s[5],f=s[0]*r,u=s[1]*r,y=s[2]*h,d=s[3]*h;o[0]=l,o[1]=c,o[2]=f+l,o[3]=u+c,o[4]=f+y+l,o[5]=u+d+c,o[6]=y+l,o[7]=d+c;const b=1/t.width,m=1/t.height;o[8]=e.x*b,o[9]=e.y*m,o[10]=(e.x+e.w)*b,o[11]=(e.y+e.h)*m,o[12]=Ve(n,a,i==="add"),this.put(t)}put(t){if(this.mute)return;const e=this.q;let s=!1;const n=Math.min(e[0],e[2],e[4],e[6]),i=Math.max(e[0],e[2],e[4],e[6]),a=Math.min(e[1],e[3],e[5],e[7]),o=Math.max(e[1],e[3],e[5],e[7]);if(this.cOn){if(this.px1<=this.px0||this.py1<=this.py0)return;const h=this.scale,l=this.px0/h,c=this.py0/h,f=this.px1/h,u=this.py1/h;if(i<=l||n>=f||o<=c||a>=u)return;if(n<l||i>f||a<c||o>u){const y=e[0],d=e[1],b=e[2],m=e[5];if(d===e[3]&&b===e[4]&&m===e[7]&&e[6]===y){if(y!==b){const x=Math.min(Math.max(y,l),f),g=Math.min(Math.max(b,l),f),v=e[8],_=(e[10]-v)/(b-y);e[10]=v+(g-y)*_,e[8]=v+(x-y)*_,e[0]=e[6]=x,e[2]=e[4]=g}if(d!==m){const x=Math.min(Math.max(d,c),u),g=Math.min(Math.max(m,c),u),v=e[9],_=(e[11]-v)/(m-d);e[11]=v+(g-d)*_,e[9]=v+(x-d)*_,e[1]=e[3]=x,e[5]=e[7]=g}}else s=!0}}const r=this.bx0===this.px0&&this.by0===this.py0&&this.bx1===this.px1&&this.by1===this.py1;if(s?(!this.bScis||!r)&&(this.flush(),this.bScis=!0,this.bx0=this.px0,this.by0=this.py0,this.bx1=this.px1,this.by1=this.py1):this.bScis&&!(this.cOn&&r)&&(this.flush(),this.bScis=!1),this.real){const h=this.gq;h[0]=n,h[1]=a,h[2]=i,h[3]=o,this.growQ()}this.batch.pushQ(e,this.slotOf(t))}ellipse(t,e,s,n,i,a,o){if(this.lost||o<=0||s<=0||n<=0)return;const r=On[ia(Math.max(s,n)*2*this.scale,Bo)],h=r.w/2/r.r,l=s*h,c=n*h,f=Math.cos(i),u=Math.sin(i),y=f*l,d=u*l,b=-u*c,m=f*c,x=1/Vt,g=this.q;g[0]=t-y-b,g[1]=e-d-m,g[2]=t+y-b,g[3]=e+d-m,g[4]=t+y+b,g[5]=e+d+m,g[6]=t-y+b,g[7]=e-d+m,g[8]=r.x*x,g[9]=r.y*x,g[10]=(r.x+r.w)*x,g[11]=(r.y+r.h)*x,g[12]=Ve(a,o),this.put(this.kit)}polygon(t,e,s,n){if(this.lost||n<=0||e<3)return;this.tris.length<e*3&&(this.tris=new Int32Array(Math.max(e*3,this.tris.length*2)));const i=this.tris,a=Oo(t,e,i),o=Ve(s,n),r=(Me.x+Me.w/2)/Vt,h=(Me.y+Me.h/2)/Vt;for(let l=0;l<a;l+=3){const c=i[l]*2,f=i[l+1]*2,u=i[l+2]*2,y=this.q;y[0]=t[c],y[1]=t[c+1],y[2]=t[f],y[3]=t[f+1],y[4]=y[6]=t[u],y[5]=y[7]=t[u+1],y[8]=y[10]=r,y[9]=y[11]=h,y[12]=o,this.put(this.kit)}}stroke(t,e,s,n,i,a){if(this.lost||i<=0||s<=0||e<1)return;const o=zn[ia(s*this.scale,Uo)],r=s/2*(o.h/2/o.r);this.sPacked=Ve(n,i),this.sColor=n,this.sAlpha=i,this.sU=(o.x+o.w/2)/Vt,this.sV0=o.y/Vt,this.sV1=(o.y+o.h)/Vt,this.sHw=s/2,Do(t,e,r,a,this.strokeSeg,this.strokeDisc)}target(t,e,s,n){const i=this.gl,a=i.createTexture();this.bindTex(a),i.texImage2D(i.TEXTURE_2D,0,i.RGBA,t,e,0,i.RGBA,i.UNSIGNED_BYTE,null);const o=n?i.LINEAR:i.NEAREST;i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MIN_FILTER,o),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MAG_FILTER,o),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_WRAP_S,i.CLAMP_TO_EDGE),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_WRAP_T,i.CLAMP_TO_EDGE),this.bindTex(null);const r=i.createFramebuffer();i.bindFramebuffer(i.FRAMEBUFFER,r),i.framebufferTexture2D(i.FRAMEBUFFER,i.COLOR_ATTACHMENT0,i.TEXTURE_2D,a,0);const h=i.checkFramebufferStatus(i.FRAMEBUFFER)===i.FRAMEBUFFER_COMPLETE;if(this.fbNow=r,this.bindFb(this.parent()),!h)return this.deleteTex(a),i.deleteFramebuffer(r),null;const l={tex:{id:Mn(),width:t,height:e,source:this.canvas},gl:a,fb:r,w:t,h:e,f:s};return this.layerTex.set(l.tex,a),l}drop(t){this.batch.has(t.tex)&&this.flush(),this.deleteTex(t.gl),this.gl.deleteFramebuffer(t.fb),this.layerTex.delete(t.tex)}parent(){return this.real>0?this.layers[this.real-1]:null}layerAt(t){var e;const s=this.canvas.width,n=this.canvas.height;let i=(e=this.layers[t])!=null?e:null;return i&&(i.w!==s||i.h!==n)&&(this.drop(i),i=this.layers[t]=null),i!=null?i:this.layers[t]=this.target(s,n,1,!1)}pushLayer(){if(this.lost)return!1;this.flush();const t=this.layerAt(this.real);if(!t)return!1;const e=this.gl;return this.bindFb(t),e.disable(e.SCISSOR_TEST),e.clearColor(0,0,0,0),e.clear(e.COLOR_BUFFER_BIT),!0}popLayer(){return this.flush(),this.bindFb(this.parent()),this.layers[this.real].tex}filters(){var t;return this.lost||!ie.gl?null:(t=this.fxr)!=null?t:this.fxr=ie.gl(this)}composite(t,e,s,n){var i;if(n&&((i=this.filters())!=null&&i.chain(t,s,n)))return;const a=this.gl;e&&a.blendFunc(a.ZERO,a.SRC_ALPHA),this.final(this.main,t,1,s),e&&(this.flush(),a.blendFunc(a.ONE,a.ONE_MINUS_SRC_ALPHA))}final(t,e,s,n){const i=this.gl,a=this.canvas.width,o=this.canvas.height,r=this.scale;(t!==this.main||!this.mapped)&&(this.bindFb(this.parent()),i.viewport(0,0,a,o),this.use(t),i.uniform2f(t.uScale,2*r/a,-2*r/o),this.mapped=t===this.main);const h=this.rx0/r,l=this.ry0/r,c=this.rx1/r,f=this.ry1/r,u=1/(s*e.width),y=1/(s*e.height),d=this.q;d[0]=d[6]=h,d[1]=d[3]=l,d[2]=d[4]=c,d[5]=d[7]=f,d[8]=this.rx0*u,d[9]=1-this.ry0*y,d[10]=this.rx1*u,d[11]=1-this.ry1*y,d[12]=Ve(16777215,n),this.put(e),t!==this.main&&this.flush()}remap(){const t=this.gl;this.bindFb(this.parent()),t.viewport(0,0,this.canvas.width,this.canvas.height),this.use(this.main),t.uniform2f(this.uScale,2*this.scale/this.canvas.width,-2*this.scale/this.canvas.height),this.mapped=!0}upload2(t){const e=this.gl,s=t.words;if(this.kind==="webgl2")return e.bufferSubData(e.ARRAY_BUFFER,0,t.f32,0,s);let n=this.views.get(s);n||(this.views.size>=256&&this.views.clear(),this.views.set(s,n=t.f32.subarray(0,s))),e.bufferSubData(e.ARRAY_BUFFER,0,n)}flush(){var t,e;const s=this.batch;if(!s.quads||this.lost)return s.reset();const n=this.gl;this.bScis?(n.enable(n.SCISSOR_TEST),n.scissor(this.bx0,this.canvas.height-this.by1,this.bx1-this.bx0,this.by1-this.by0)):n.disable(n.SCISSOR_TEST),this.upload2(s);for(let i=0;i<s.bound;i++){const a=s.textures[i];this.bindTex((e=(t=this.textures.get(a))!=null?t:this.layerTex.get(a))!=null?e:null,i)}this.inst?this.inst.draw(6,s.quads):n.drawElements(n.TRIANGLES,s.quads*6,n.UNSIGNED_SHORT,0),this.stats.drawCalls++,this.stats.quads+=s.quads,s.reset()}end(){return this.closeLayers(),this.flush(),this.stats.filtersSkipped=this.skipped,this.stats}onLost(t){this.lostListeners.push(t)}onRestored(t){this.restoredListeners.push(t)}destroy(){var t,e;const s=this.gl;ie.live===this&&(ie.live=null),this.canvas.removeEventListener("webglcontextlost",this.onContextLost),this.canvas.removeEventListener("webglcontextrestored",this.onContextRestored);try{for(const n of this.textures.values())n&&s.deleteTexture(n);for(const n of this.layers)n&&(s.deleteTexture(n.gl),s.deleteFramebuffer(n.fb));(t=this.fxr)==null||t.destroy(),this.fxr=null,s.deleteBuffer(this.dynamic),s.deleteBuffer(this.index),this.staticBuf&&s.deleteBuffer(this.staticBuf),this.vao&&this.vaoApi&&this.vaoApi.remove(this.vao),s.deleteProgram(this.main.p),(e=s.getExtension("WEBGL_lose_context"))==null||e.loseContext()}catch(n){}this.textures.clear()}};function oa(t,e,s){var n;const i=t.createShader(e);if(t.shaderSource(i,s),t.compileShader(i),!t.getShaderParameter(i,t.COMPILE_STATUS)){const a=(n=t.getShaderInfoLog(i))!=null?n:"?";throw t.deleteShader(i),new Error(a)}return i}function la(t="auto"){switch(t){case"canvas2d":return["canvas2d"];case"webgl1":return["webgl1","canvas2d"];default:return["webgl2","webgl1","canvas2d"]}}function Bn(t,e={}){let s=t;for(const n of la(e.renderer)){const i=n==="canvas2d"?Pn(s):Vo(s,n==="webgl2"?2:1,e);if(i)return i;s=Un(s)}throw new Error("No renderer: this browser has neither WebGL nor Canvas 2D")}function Un(t){var e;const s=t.cloneNode(!1);return(e=t.parentNode)==null||e.replaceChild(s,t),s}function Zo(t=typeof location!="undefined"?location.search:""){const e=new URLSearchParams(t).get("renderer");return e==="canvas"?"canvas2d":e==="webgl2"||e==="webgl1"||e==="canvas2d"||e==="webgl"||e==="auto"?e:void 0}var Hn=class{constructor(t,e={}){p(this,"atlas",t),p(this,"tags",new Map),p(this,"count",0),p(this,"m",Qe()),p(this,"measure",null),p(this,"height"),p(this,"font");var s,n;this.height=(s=e.tagHeight)!=null?s:34,this.font=(n=e.tagFont)!=null?n:"Nunito, sans-serif"}drop(){for(const t of this.tags.values())for(const e of t.values())for(const s of e.values())this.atlas.release(s);this.tags.clear(),this.count=0}get(t,e,s){let n=this.tags.get(t);n||this.tags.set(t,n=new Map);let i=n.get(e);i||n.set(e,i=new Map);const a=i.get(s);return a&&this.atlas.valid(a)?a:this.bake(t,e,s)}bake(t,e,s){var n;const i=this.height,a="700 ".concat(Math.round(i*.65),"px ").concat(this.font),o=(n=this.measure)!=null?n:this.measure=document.createElement("canvas").getContext("2d");o.font=a;const r=Math.round(i*.4),h=Math.ceil(o.measureText(t).width)+r*2,l=this.atlas.bake((h+2)*s,(i+2)*s,u=>{u.scale(s,s),u.translate(1,1);const y=i/2;u.beginPath(),u.moveTo(y,0),u.lineTo(h-y,0),u.arc(h-y,y,y,-Math.PI/2,Math.PI/2),u.lineTo(y,i),u.arc(y,y,y,Math.PI/2,Math.PI*3/2),u.closePath(),u.fillStyle=e,u.fill(),u.fillStyle="#fff",u.font=a,u.textAlign="center",u.textBaseline="middle",u.fillText(t,h/2,i/2+1)},s,1,1,1);++this.count>64&&(this.drop(),this.count=1);let c=this.tags.get(t);c||this.tags.set(t,c=new Map);let f=c.get(e);return f||c.set(e,f=new Map),f.set(s,l),l}draw(t,e,s,n,i,a,o,r,h,l,c){const f=dn(s,i,{band:Jo(n)});if(!f)return;const u=this.height,y=this.get(a,o,h),d=y.w/y.scale-2,b=Math.min(Math.max(f.head.x-d/2,4),l-d-4),m=Math.min(Math.max(f.head.y-f.headR*2.2-u,4),c-u-4);ce(this.m,null,b-1,m-1,0,1,1),t.quad(e(y.surface),y,this.m,y.w/y.scale,y.h/y.scale,16777215,r,"normal")}},Jo=t=>t.band==="3-5"||t.band==="9-12"?t.band:"6-8",$o=(t,e=!1)=>e?Math.min(qe(2,Math.round(Math.log2(Math.max(t,8)))),256):Math.min(qe(2,Math.ceil(Math.log2(Math.max(t,8))*2)/2),512);function Gn(t,e=null){var s,n,i,a;const o={minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0},r=(h,l,c)=>{const f=e?e[0]*h+e[2]*l+e[4]:h,u=e?e[1]*h+e[3]*l+e[5]:l,y=e?Math.hypot(e[0],e[1]):1;o.minX=Math.min(o.minX,f-c*y),o.minY=Math.min(o.minY,u-c*y),o.maxX=Math.max(o.maxX,f+c*y),o.maxY=Math.max(o.maxY,u+c*y)};for(const h of t){const l="lw"in h&&h.stroke?((s=h.lw)!=null?s:1)/2:0;switch(h.k){case"circle":r(h.x-h.r,h.y-h.r,l),r(h.x+h.r,h.y+h.r,l),r(h.x-h.r,h.y+h.r,l),r(h.x+h.r,h.y-h.r,l);break;case"ellipse":case"rect":{const c=h.k==="ellipse"?Math.max(h.rx,h.ry):Math.hypot(h.w,h.h)/2;r(h.x-c,h.y-c,l),r(h.x+c,h.y+c,l),r(h.x-c,h.y+c,l),r(h.x+c,h.y-c,l);break}case"path":{const c=In(h.d);for(let f=0;f<c.count;f++){const u=c.subs[f];for(let y=0;y<u.n;y++)r(u.pts[y*2],u.pts[y*2+1],l)}break}case"line":for(let c=0;c+1<h.pts.length;c+=2)r(h.pts[c],h.pts[c+1],l);break;case"group":{const c=ce(Qe(),e,h.x,h.y,(n=h.rot)!=null?n:0,(i=h.s)!=null?i:1,(a=h.s)!=null?a:1),f=Gn(h.items,c);Number.isFinite(f.minX)&&(o.minX=Math.min(o.minX,f.minX),o.minY=Math.min(o.minY,f.minY),o.maxX=Math.max(o.maxX,f.maxX),o.maxY=Math.max(o.maxY,f.maxY));break}}}return o}var Xn=class{constructor(t){p(this,"atlas",t),p(this,"seen",new WeakSet),p(this,"baked",new WeakMap),p(this,"m",Qe()),p(this,"stack",[]),p(this,"local",Qe()),p(this,"pts",new Float64Array(128)),p(this,"stats",{baked:0,vector:0}),p(this,"bakeGroups",!0),p(this,"coarse",!1),p(this,"gen",0),p(this,"live",new Set)}setTier(t){const e=t==="low";if(e!==this.coarse){this.coarse=e,this.gen++;for(const s of this.live)this.atlas.release(s.frame);this.live.clear()}}draw(t,e,s,n,i,a,o){var r;const h=typeof n=="string"?(r=Is(n))!=null?r:ls:n,l=bi(s,h,i);return l.length?(a<=0||(a<1?(this.paint(t,e,l,null,t.beginLayer()?1:a,o),t.endLayer(a)):this.paint(t,e,l,null,a,o)),!0):!1}paint(t,e,s,n,i,a,o=0){var r,h,l,c,f,u,y,d,b,m,x;for(let g=0;g<s.length;g++){const v=s[g];if(v.k==="group"){const U=ce((h=(r=this.stack)[o])!=null?h:r[o]=Qe(),n,v.x,v.y,(l=v.rot)!=null?l:0,(c=v.s)!=null?c:1,(f=v.s)!=null?f:1),G=i*((u=v.alpha)!=null?u:1);if(this.bakeGroups&&this.seen.has(v.items)){const O=he(U[0],U[1])*a,X=this.bake(v.items,O);if(X){const L=X.frame,lt=this.m;lt.set(U),lt[4]=U[0]*-X.ox+U[2]*-X.oy+U[4],lt[5]=U[1]*-X.ox+U[3]*-X.oy+U[5],t.quad(e(L.surface),L,lt,L.w/X.k,L.h/X.k,16777215,G,"normal"),this.stats.baked++;continue}}this.seen.add(v.items),this.stats.vector++,this.paint(t,e,v.items,U,G,a,o+1);continue}const _=i*((y=v.alpha)!=null?y:1),T=n?he(n[0],n[1]):1,N=n?Math.atan2(n[1],n[0]):0,R=((d=v.lw)!=null?d:1)*T,M=v.stroke&&((b=v.lw)!=null?b:1)>0?ne(v.stroke):null,P=v.fill&&v.k!=="line"?ne(v.fill):null;if(v.k==="circle"||v.k==="ellipse"){const U=n?n[0]*v.x+n[2]*v.y+n[4]:v.x,G=n?n[1]*v.x+n[3]*v.y+n[5]:v.y,O=(v.k==="circle"?v.r:v.rx)*T,X=(v.k==="circle"?v.r:v.ry)*T,L=(v.k==="ellipse"&&(m=v.rot)!=null?m:0)+N;if(P&&M)t.ellipse(U,G,O+R/2,X+R/2,L,M[0],_*M[1]),t.ellipse(U,G,Math.max(O-R/2,0),Math.max(X-R/2,0),L,P[0],_*P[1]);else if(P)t.ellipse(U,G,O,X,L,P[0],_*P[1]);else if(M){const lt=Math.min(Math.max(Math.ceil(Math.max(O,X)*a*.6),12),64),yt=this.pts=Ln(this.pts,lt*2),$=Math.cos(L),w=Math.sin(L);for(let H=0;H<lt;H++){const W=H/lt*Math.PI*2,bt=Math.cos(W)*O,Z=Math.sin(W)*X;yt[H*2]=U+bt*$-Z*w,yt[H*2+1]=G+bt*w+Z*$}t.stroke(yt,lt,R,M[0],_*M[1],!0)}continue}if(v.k==="line"){if(!M)continue;const U=v.pts.length>>1,G=this.pts=Ln(this.pts,U*2);for(let O=0;O<U;O++){const X=v.pts[O*2],L=v.pts[O*2+1];G[O*2]=n?n[0]*X+n[2]*L+n[4]:X,G[O*2+1]=n?n[1]*X+n[3]*L+n[5]:L}t.stroke(G,U,R,M[0],_*M[1],!1);continue}const z=v.k==="path"?In(v.d,n,T*a):tl(v,ce(this.local,n,v.x,v.y,(x=v.rot)!=null?x:0,1,1),a*T);for(let U=0;U<z.count;U++){const G=z.subs[U],O=G.n,X=v.k==="rect"||G.closed;P&&O>=3&&(t.polygon(G.pts,O,P[0],_*P[1]),M||t.stroke(G.pts,O,1/a,P[0],_*P[1],!0)),M&&t.stroke(G.pts,O,R,M[0],_*M[1],X)}}}bake(t,e){const s=$o(e,this.coarse);let n=this.baked.get(t);const i=n==null?void 0:n.get(s);if(i&&i.gen===this.gen&&this.atlas.valid(i.frame))return i;i&&this.live.delete(i);const a=Gn(t);if(!Number.isFinite(a.minX))return null;const o=2/s,r=(a.maxX-a.minX+o*2)*s,h=(a.maxY-a.minY+o*2)*s;if(r>1024||h>1024)return null;const l=-a.minX+o,c=-a.minY+o,u={frame:this.atlas.bake(r,h,y=>{y.scale(s,s),y.translate(l,c),fn(y,t)}),k:s,ox:l,oy:c,gen:this.gen};return n||this.baked.set(t,n=new Map),n.set(s,u),this.live.add(u),u}},ss=new Array(36).fill(0),ns=0,ae=(t,e=NaN,s=NaN,n=NaN,i=NaN)=>{ss[ns++]=t,t!==Xt.Z&&(ss[ns++]=e,ss[ns++]=s,t===Xt.Q&&(ss[ns++]=n,ss[ns++]=i))};function tl(t,e,s){const n=Math.max(0,Math.min(t.r,t.w/2,t.h/2)),i=-t.w/2,a=-t.h/2,{M:o,L:r,Q:h,Z:l}=Xt;return ns=0,ae(o,i+n,a),ae(r,i+t.w-n,a),ae(h,i+t.w,a,i+t.w,a+n),ae(r,i+t.w,a+t.h-n),ae(h,i+t.w,a+t.h,i+t.w-n,a+t.h),ae(r,i+n,a+t.h),ae(h,i,a+t.h,i,a+t.h-n),ae(r,i,a+n),ae(h,i,a,i+n,a),ae(l),In(ss,e,s)}function el(t,e={}){var s,n;let i=Bn(t,e);const a=new Tn(Math.min(1024,i.maxTextureSize),2);a.onDrop=M=>{M.texture&&i.destroyTexture(M.texture),M.texture=null};const o=new Xn(a),r=()=>{const M=new Ao;return e.local&&M.setLocal(!0),M};let h=r();const l=new Map;let c=1e6;const f=e.smooth===!1?1:typeof e.smooth=="number"?Math.min(Math.max(e.smooth,.05),1):h.defaultAmount;let u=Qs(i);const y=new Hn(a,e),d={w:1,h:1};let b=1,m=0,x=!1;const g=()=>y.drop(),v=typeof document!="undefined"?document.fonts:void 0;(s=v==null?void 0:v.ready)==null||s.then(()=>{x||g()}),(n=v==null?void 0:v.addEventListener)==null||n.call(v,"loadingdone",g);const _=()=>{const M=Un(i.canvas),P=Pn(M);if(P){console.warn("[engine] avatars: WebGL context lost for good, switching to Canvas 2D"),i.destroy(),i=P;for(const z of a.pages)z.surface.texture=null;u=Qs(i),m=0}},T=()=>{if(!i.lost)return m=0,!0;const M=performance.now();return m||(m=M),M-m>3e3&&_(),!i.lost},N=()=>{var M,P;const z=i.canvas;e.units?(b=(M=e.pixelRatio)!=null?M:1,d.w=e.units.width,d.h=e.units.height):(b=(P=e.pixelRatio)!=null?P:Math.min(le.devicePixelRatio||1,2),d.w=z.clientWidth||z.width/b,d.h=z.clientHeight||z.height/b),i.resize(Math.max(1,Math.round(d.w*b)),Math.max(1,Math.round(d.h*b))),i.begin(0,0,b)},R=(M,P)=>{var z;if(M.key===void 0)return(z=M.id)!=null?z:P+1;let U=l.get(M.key);return U===void 0&&(l.size>256&&l.clear(),l.set(M.key,U=c++)),U};return{get renderer(){return i},get kind(){return i.kind},get lost(){return i.lost},get canvas(){return i.canvas},draw(M,P){var z,U,G,O;if(T()){N();for(let X=0;X<M.length;X++){const L=M[X];if(!Array.isArray(L.body))continue;const lt=R(L,X),yt=f<1||e.interpolate!==!1?h.posed(lt,L.body,f,e.interpolate!==!1):L.body,$=(U=Is((z=L.avatar)!=null?z:""))!=null?U:ls,w=(G=L.alpha)!=null?G:1;!o.draw(i,u,yt,$,P,w,b)||!L.name||y.draw(i,u,yt,$,P,L.name,(O=L.color)!=null?O:"#6FA0E0",w,b,d.w,d.h)}i.end()}},clear(){T()&&(N(),i.end())},reset(){h=r(),l.clear()},destroy(){var M;x=!0,(M=v==null?void 0:v.removeEventListener)==null||M.call(v,"loadingdone",g),i.destroy()}}}var Ys=new Map;function sl(t,e,s=Math.min(le.devicePixelRatio||1,2)){var n;const i="".concat(t,"|").concat(e,"|").concat(s);let a=Ys.get(i);if(a)return a;a=document.createElement("canvas"),a.width=a.height=Math.round(e*s);const o=a.getContext("2d");return o.scale(s,s),o.beginPath(),o.rect(0,0,e,e),o.clip(),fn(o,so((n=Is(t))!=null?n:ls,e)),Ys.size>64&&Ys.clear(),Ys.set(i,a),a}function Qs(t){return e=>{if(e.texture||(e.texture=t.createTexture(e.source),e.pending.length=0),e.pending.length){for(const[s,n,i]of e.pending)t.updateTexture(e.texture,s,n,i);e.pending.length=0}return e.texture}}var ca='Fredoka, Nunito, "Varela Round", system-ui, sans-serif',bs="rgba(10,16,30,0.75)";function ha(t,e){var s,n,i,a,o,r;const h=(s=t.size)!=null?s:40,l=t.outline?t.outline===!0?bs:t.outline:null,c=l?(n=t.outlineWidth)!=null?n:Math.max(h*.12,3):0,f=t.shadow&&e?t.shadow===!0?bs:t.shadow:null,u=f?(i=t.shadowBlur)!=null?i:h*.25:0;return{size:h,font:(a=t.font)!=null?a:ca,weight:(o=t.weight)!=null?o:700,color:(r=t.color)!=null?r:"#FBEFE3",outline:l,ow:c,shadow:f,blur:u,pad:c/2+u*1.2+2,th:h*1.25}}var fa=(t,e)=>"".concat(t.weight," ").concat(t.size*e,"px ").concat(t.font);function ua(t,e,s,n,i,a){t.scale(n,n),t.font=fa(s,1),t.textBaseline="middle",t.textAlign="left",t.lineJoin="round",s.shadow&&(t.shadowColor=s.shadow,t.shadowBlur=s.blur*n),s.outline&&(t.strokeStyle=s.outline,t.lineWidth=s.ow,t.strokeText(e,i,a),t.shadowColor="transparent"),t.fillStyle=s.color,t.fillText(e,i,a)}var gs=null;function da(t,e,s){return gs!=null||(gs=document.createElement("canvas").getContext("2d")),gs.font=fa(e,s),gs.measureText(t).width/s}var vs=class extends Ke{constructor(t,e,s={}){super(t,null),p(this,"_text"),p(this,"_style"),p(this,"dirty",!0),p(this,"bakedScale",0),p(this,"bakedFontGen",-1),p(this,"bakedEffects",!0),p(this,"capW",0),p(this,"capH",0),this._text=e;const n=s,{x:i,y:a,rotation:o,scale:r,scaleX:h,scaleY:l,alpha:c,visible:f,tint:u,blend:y,z:d,anchor:b,hitRadius:m,clip:x,mask:g,filters:v}=n,_=hn(n,["x","y","rotation","scale","scaleX","scaleY","alpha","visible","tint","blend","z","anchor","hitRadius","clip","mask","filters"]);this._style=_,this.bake(),this.set({x:i,y:a,rotation:o,scale:r,scaleX:h,scaleY:l,alpha:c,visible:f,tint:u,blend:y,z:d,hitRadius:m,clip:x,mask:g,filters:v}),b!==void 0&&(this.anchor=b)}get text(){return this._text}set text(t){const e=String(t);e!==this._text&&(this._text=e,this.dirty=!0)}get style(){return this._style}set style(t){this._style=A(A({},this._style),t),this.dirty=!0}bitmap(){const t=this._style.bitmapFont;if(!t)return null;const e=typeof t=="string"?this.kernel.bitmapFont(t):t;if(this.autoAnchor){const s=this._style.align;this.anchorX=s==="left"?0:s==="right"?1:.5,this.anchorY=.5}return e}get naturalWidth(){var t;const e=this.bitmap();return e?e.measure(this._text)*(((t=this._style.size)!=null?t:e.size)/e.size):super.naturalWidth}get naturalHeight(){var t;const e=this.bitmap();return e?e.lineHeight*(((t=this._style.size)!=null?t:e.size)/e.size):super.naturalHeight}frameNow(){return this._style.bitmapFont?null:this.bake()}draw(t,e,s){var n;const i=this.bitmap();if(!i)return super.draw(t,e,s);const a=((n=this._style.size)!=null?n:i.size)/i.size,o=i.measure(this._text)*a,r=i.lineHeight*a,h=this.width,l=this.height,c=o>0?h/o:1,f=r>0?l/r:1;i.run(this._text,t,this.world,-this.anchorX*h,-this.anchorY*l,a*c,a*f,s,e,this.blend)}destroy(){this._frame&&this.kernel.atlas.release(this._frame),super.destroy()}bake(){const t=this.kernel;if(this._style.bitmapFont)return null;const e=t.pixelScale,s=t.effects;return!this.dirty&&e===this.bakedScale&&t.fontGen===this.bakedFontGen&&s===this.bakedEffects&&t.atlas.valid(this._frame)?this._frame:this.rebake()}rebake(){var t;const e=this.kernel,s=e.pixelScale,n=e.effects;this.dirty=!1,this.bakedScale=s,this.bakedFontGen=e.fontGen,this.bakedEffects=n;const i=ha(this._style,n),{pad:a,th:o}=i,r=da(this._text,i,s),h=(r+a*2)*s,l=(o+a*2)*s,c=(t=this._style.align)!=null?t:"center",f=c==="left"?a:c==="right"?a+r:a+r/2,u=b=>ua(b,this._text,i,s,a,a+o/2),y=this._frame;let d=null;return y&&e.atlas.valid(y)&&y.scale===s&&(d=e.atlas.rebake(y,h,l,u,this.capW,this.capH),d?Object.assign(d,{ox:f,oy:a+o/2,margin:a}):e.atlas.release(y)),d||(this.capW=Math.ceil(h*1.25+16),this.capH=Math.ceil(l),d=e.atlas.bake(this.capW,this.capH,u,s,f,a+o/2,a),d.w=Math.ceil(h),d.h=Math.ceil(l)),this._frame=d,this.autoAnchor&&this.useFrameAnchor(),this._w=this._h=null,d}},Rt=(t,e=0)=>{const s=Number(t);return Number.isFinite(s)?s:e};function Vs(t){var e,s,n,i,a,o;typeof t=="string"&&/^\s*[{[]/.test(t)&&(t=JSON.parse(t));const r={size:0,lineHeight:0,base:0,pages:[],chars:[],kernings:[]},h=(l,c)=>{var f;l==="info"?r.size=Math.abs(Rt(c.size)):l==="common"?(r.lineHeight=Rt(c.lineHeight),r.base=Rt(c.base)):l==="page"?r.pages[Rt(c.id)]=String((f=c.file)!=null?f:""):l==="char"?r.chars.push({id:Rt(c.id),x:Rt(c.x),y:Rt(c.y),width:Rt(c.width),height:Rt(c.height),xoffset:Rt(c.xoffset),yoffset:Rt(c.yoffset),xadvance:Rt(c.xadvance),page:Rt(c.page)}):r.kernings.push({first:Rt(c.first),second:Rt(c.second),amount:Rt(c.amount)})};if(typeof t=="object"){const l=t;h("info",(e=l.info)!=null?e:{}),h("common",(s=l.common)!=null?s:{});for(const[c,f]of((n=l.pages)!=null?n:[]).entries())h("page",{id:c,file:f});for(const c of(i=l.chars)!=null?i:[])h("char",c);for(const c of(a=l.kernings)!=null?a:[])h("kerning",c)}else{const l=/(?:^|<)\s*(info|common|page|char|kerning)\s([^\n<>]*)/gm,c=/(\w+)=(?:"([^"]*)"|([^\s/>]+))/g;for(let f=l.exec(t);f;f=l.exec(t)){const u={};for(let y=c.exec(f[2]);y;y=c.exec(f[2]))u[y[1]]=(o=y[2])!=null?o:y[3];h(f[1],u)}}return r.size||(r.size=r.lineHeight),r}var qn=class{constructor(t,e,s,n=null,i=null){p(this,"baker",n),p(this,"host",i),p(this,"size"),p(this,"lineHeight"),p(this,"base"),p(this,"ascii",new Array(128)),p(this,"more",new Map),p(this,"kern",new Map),p(this,"bScale",0),p(this,"bFontGen",-1),p(this,"bEffects",!1),p(this,"bGen",-1),this.size=t,this.lineHeight=e,this.base=s}set(t,e){t<128?this.ascii[t]=e:this.more.set(t,e)}setKerning(t,e,s){this.kern.set(t*1114112+e,s)}prepare(){const t=this.host;if(!(!t||t.pixelScale===this.bScale&&t.fontGen===this.bFontGen&&t.effects===this.bEffects&&t.atlas.gen===this.bGen)){this.bScale=t.pixelScale,this.bFontGen=t.fontGen,this.bEffects=t.effects,this.bGen=t.atlas.gen;for(const e of this.ascii)e&&t.atlas.release(e.frame);for(const e of this.more.values())e&&t.atlas.release(e.frame);this.ascii.fill(void 0),this.more.clear()}}glyph(t){let e=t<128?this.ascii[t]:this.more.get(t);return(e===void 0||e&&this.host&&!this.host.atlas.valid(e.frame))&&(e=this.baker?this.baker(t):null,this.set(t,e)),e}kerning(t,e){var s;return this.kern.size&&(s=this.kern.get(t*1114112+e))!=null?s:0}measure(t){return this.run(t)}run(t,e,s,n=0,i=0,a=1,o=1,r=0,h=1,l="normal"){this.prepare();let c=0,f=-1;for(let u=0;u<t.length;u++){let y=t.charCodeAt(u);y>=55296&&y<56320&&u+1<t.length&&(y=t.codePointAt(u),u++),f>=0&&(c+=this.kerning(f,y)),f=y;const d=this.glyph(y);d&&(e&&d.w>0&&d.h>0&&(zs(s,n+(c+d.x)*a,i+d.y*o),e.r.quad(e.tex(d.frame.surface),d.frame,Et,d.w*a,d.h*o,r,h,l)),c+=d.advance)}return c}};function nl(t,e){const s=new qn(t.size,t.lineHeight,t.base);for(const n of t.chars){const i=e[n.page];if(!i)continue;const a={surface:i,x:n.x,y:n.y,w:n.width,h:n.height,scale:1,gen:0,ox:0,oy:0,margin:0};s.set(n.id,{frame:a,x:n.xoffset,y:n.yoffset,w:n.width,h:n.height,advance:n.xadvance})}for(const n of t.kernings)s.setKerning(n.first,n.second,n.amount);return s}function il(t,e){var s,n;const i=A({},e),a=(s=e.size)!=null?s:40,o=h=>{const l=String.fromCodePoint(h),c=t.pixelScale,f=ha(i,t.effects),u=da(l,f,c),y=t.atlas.bake((u+f.pad*2)*c,(f.th+f.pad*2)*c,d=>ua(d,l,f,c,f.pad,f.pad+f.th/2),c);return{frame:y,x:-f.pad,y:-f.pad,w:y.w/c,h:y.h/c,advance:u}},r=new qn(a,a*1.25,a,o,t);r.prepare();for(const h of(n=e.chars)!=null?n:"0123456789")r.glyph(h.codePointAt(0));return r}var al=.5;function pa(t){const e=[];for(const[s,n]of[["left",J.leftWrist],["right",J.rightWrist]]){const i=t[n*3],a=t[n*3+1],o=t[n*3+2];i!==void 0&&a!==void 0&&Number.isFinite(i)&&Number.isFinite(a)&&(o!=null?o:0)>=al&&e.push({side:s,x:i,y:a})}return e}var Ks=t=>Rs[((t-1)%Rs.length+Rs.length)%Rs.length],rl=["left","right"];function ya(t,e,s,n,i=()=>null,a={}){var o,r;const h=[];for(const l of t){const c=(o=i(l))!=null?o:l.body;if(Array.isArray(c)){if(a.orientation==="portrait"){for(const f of rl){let u=ir(c,f,{orientation:"portrait"});a.hold&&(u=a.hold.at(ii.key(l.id,f),u,(r=a.t)!=null?r:0)),u&&h.push({player:l.id,side:f,x:u.x*s,y:u.y*n,color:Ks(l.id)})}continue}for(const f of pa(c)){const u=e(f);h.push({player:l.id,side:f.side,x:u.x*s,y:u.y*n,color:Ks(l.id)})}}}return h}function Wn(t,e,s,n=0){const i=t.world,a=co(i,e,s);if(!a)return!1;const o=Math.hypot(i[0],i[1])||1,r=Math.hypot(i[2],i[3])||1,[h,l]=a;if(t.hitRadius!=null){const d=t.hitRadius+n/((o+r)/2);return h*h+l*l<=d*d}const c=-t.anchorX*t.width-n/o,f=-t.anchorY*t.height-n/r,u=(1-t.anchorX)*t.width+n/o,y=(1-t.anchorY)*t.height+n/r;return h>=c&&h<=u&&l>=f&&l<=y}function ma(t,e,s,n=0){for(const i of e)if((s===void 0||i.player===s)&&Wn(t,i.x,i.y,n))return i;return null}function ol(t){var e;switch(t.type){case"circle":case"ring":case"star":return[t.r*2,t.r*2];case"ellipse":return[t.rx*2,t.ry*2];case"roundRect":return[t.w,t.h];case"line":return[t.length,(e=t.lw)!=null?e:4];case"path":return t.r?[t.r*2,t.r*2]:[t.size,t.size]}}function ll(t){var e,s,n;const i=t.type==="line"?0:t.stroke?((e=t.lw)!=null?e:2)/2:0,a=t.shadow?t.shadow.blur*1.5+Math.max(Math.abs((s=t.shadow.x)!=null?s:0),Math.abs((n=t.shadow.y)!=null?n:0)):0;return Math.ceil(i+a+1)}var cl=(t,e)=>e||!t.shadow?t:We(A({},t),{shadow:void 0});function xa(t,e,s){const n=ll(e),i=e.type==="roundRect",[a,o]=i?[Math.min(e.w,e.r*2+4/s),Math.min(e.h,e.r*2+4/s)]:ol(e),r=(a+n*2)*s,h=(o+n*2)*s;return{frame:t.bake(r,h,c=>{c.scale(s,s),c.translate(n+a/2,n+o/2),hl(c,e,a,o)},s,n+a/2,n+o/2,n),slice:i?Math.ceil((e.r+n)*s):0,w:i?e.w:a,h:i?e.h:o}}function hl(t,e,s,n){var i,a,o,r,h,l,c;t.lineJoin="round",t.lineCap="round";const f=new Path2D;switch(e.type){case"circle":case"ring":f.arc(0,0,e.r,0,Math.PI*2);break;case"ellipse":f.ellipse(0,0,e.rx,e.ry,0,0,Math.PI*2);break;case"roundRect":f.roundRect(-s/2,-n/2,s,n,Math.min(e.r,s/2,n/2));break;case"star":{const m=(i=e.points)!=null?i:5,x=e.r*((a=e.inner)!=null?a:.5);for(let g=0;g<m*2;g++){const v=g%2?x:e.r,_=-Math.PI/2+g*Math.PI/m;g?f.lineTo(Math.cos(_)*v,Math.sin(_)*v):f.moveTo(Math.cos(_)*v,Math.sin(_)*v)}f.closePath();break}case"line":f.moveTo(-s/2+n/2,0),f.lineTo(s/2-n/2,0);break;case"path":{const m=e.r?e.r*2/e.size:1,x=new DOMMatrix([m,0,0,m,-e.size/2*m,-e.size/2*m]);f.addPath(new Path2D(e.d),x);break}}const u=e.shadow,y=()=>{var m,x;if(!u)return;const g=t.getTransform();t.shadowColor=u.color,t.shadowBlur=u.blur*g.a,t.shadowOffsetX=((m=u.x)!=null?m:0)*g.a,t.shadowOffsetY=((x=u.y)!=null?x:0)*g.a},d=()=>{t.shadowColor="transparent",t.shadowBlur=0};if(e.type==="line"){y(),t.strokeStyle=(r=(o=e.stroke)!=null?o:e.fill)!=null?r:"#fff",t.lineWidth=n,t.stroke(f);return}const b=e.type==="ring";if(e.outlineBelow&&e.fill&&e.stroke&&!b){y(),t.strokeStyle=e.stroke,t.lineWidth=(h=e.lw)!=null?h:2,t.stroke(f),d(),t.fillStyle=e.fill,t.fill(f);return}e.fill&&!b&&(y(),t.fillStyle=e.fill,t.fill(f),d()),(e.stroke||b)&&((!e.fill||b)&&y(),b&&e.fill&&(t.fillStyle=e.fill,t.fill(f)),t.strokeStyle=(l=e.stroke)!=null?l:"#fff",t.lineWidth=(c=e.lw)!=null?c:2,t.stroke(f),d())}var ba=class{constructor(){if(p(this,"ctx",null),p(this,"master",null),p(this,"buffers",new Map),p(this,"held",!1),p(this,"muted",!1),p(this,"volume",1),typeof addEventListener=="function"){const t=()=>{var e;(e=this.context())==null?void 0:e.resume().catch(()=>{})};for(const e of["pointerdown","keydown","touchstart"])addEventListener(e,t,{once:!0,capture:!0})}}context(){var t;if(this.ctx)return this.ctx;const e=(t=le.AudioContext)!=null?t:le.webkitAudioContext;if(!e)return null;try{this.ctx=new e,this.master=this.ctx.createGain(),this.master.connect(this.ctx.destination),this.held&&this.ctx.suspend()}catch(s){return null}return this.ctx}load(t,e){return je(this,null,function*(){const s=this.context();if(!s)return;const n=yield(yield fetch(e)).arrayBuffer();this.buffers.set(t,yield s.decodeAudioData(n))})}has(t){return this.buffers.has(t)}play(t,e={}){var s,n,i;const a=this.context(),o=this.buffers.get(t);if(!a||!o||!this.audible)return()=>{};const r=a.createBufferSource();r.buffer=o,r.loop=(s=e.loop)!=null?s:!1,r.playbackRate.value=(n=e.rate)!=null?n:1;const h=a.createGain();return h.gain.value=((i=e.volume)!=null?i:1)*this.volume,r.connect(h).connect(this.master),r.start(),()=>{try{r.stop()}catch(l){}}}tone(t,e=.25,s={}){var n,i;const a=this.context();if(!(!a||!this.audible))try{const o=a.createOscillator(),r=a.createGain();o.type=(n=s.type)!=null?n:"sine",o.frequency.setValueAtTime(t,a.currentTime),s.to&&o.frequency.exponentialRampToValueAtTime(s.to,a.currentTime+e),r.gain.setValueAtTime(((i=s.volume)!=null?i:.12)*this.volume,a.currentTime),r.gain.exponentialRampToValueAtTime(.001,a.currentTime+e),o.connect(r).connect(this.master),o.start(),o.stop(a.currentTime+e)}catch(o){}}get audible(){return!this.muted&&!this.held}hold(){var t;this.held=!0,(t=this.ctx)==null||t.suspend().catch(()=>{})}release(){var t;this.held=!1,(t=this.ctx)==null||t.resume().catch(()=>{})}destroy(){var t;(t=this.ctx)==null||t.close().catch(()=>{}),this.ctx=null}},fl={high:{resolution:1.5,particles:1,effects:!0,maxBlur:32},medium:{resolution:1,particles:.5,effects:!1,maxBlur:16},low:{resolution:.75,particles:.2,effects:!1,maxBlur:0}},fe=["high","medium","low"];function ze(t){const e=fl[t];return We(A({name:t},e),{scale:s=>s<=0?0:Math.max(1,Math.round(s*e.particles))})}var ul=t=>fe[Math.min(fe.indexOf(t)+1,fe.length-1)],Zs=(t,e)=>{if(!t.length)return NaN;const s=[...t].sort((n,i)=>n-i);return s[Math.min(s.length-1,Math.max(0,Math.floor(e*(s.length-1)+.5)))]},dl=12,pl=t=>Js(t,.5);function Js(t,e=.1){const s=Zs(t,e);if(!Number.isFinite(s))return 1e3/60;const n=[144,120,90,75,60,50,30];let i=60;for(const a of n)Math.abs(1e3/a-s)<Math.abs(1e3/i-s)&&(i=a);return 1e3/i}function ga(t,e){const s=e.refresh!==void 0&&Number.isFinite(e.refresh)&&e.refresh>0?e.refresh:Js(e.intervals),n=Zs(e.intervals,.5),i=Zs(e.intervals,.9),a=Zs(e.cpu,.5);if(!Number.isFinite(n))return t==="canvas2d"?"low":"medium";const o=h=>h<=s*1.25,r=h=>!Number.isFinite(a)||a<s*h;return t==="canvas2d"?o(i)&&r(.25)?"medium":"low":o(i)&&r(.5)?"high":o(n)?"medium":"low"}function yl(t,e){return t.length<30?!1:t.filter(n=>n>e*1.5).length/t.length>.5}var va="0.1.1",ml=720*3600*1e3,xl=(t,e,s)=>"fabi-play.engine-tier:".concat(va,":").concat(t,":").concat(e,":").concat(s),bl=(t,e,s)=>"fablee-engine-tier:".concat(va,":").concat(t,":").concat(e,":").concat(s);function gl(t,e,s=Date.now()){var n;try{const i=JSON.parse((n=t==null?void 0:t.getItem(e))!=null?n:"null");if(i&&fe.includes(i.tier)&&typeof i.at=="number"&&s-i.at<ml)return typeof i.refresh=="number"&&i.refresh>0?{name:i.tier,refresh:i.refresh}:{name:i.tier}}catch(i){}return null}function ka(t,e,s,n,i=Date.now()){try{t==null||t.setItem(e,JSON.stringify(n!==void 0&&Number.isFinite(n)?{tier:s,at:i,refresh:n}:{tier:s,at:i}))}catch(a){}}function vl(t=typeof location!="undefined"?location.search:""){const e=new URLSearchParams(t).get("tier");return fe.includes(e)?e:void 0}function wa(t,e){const s=e==null?void 0:e.tier;if(fe.includes(s))return t==="canvas2d"&&s==="high"?"medium":s}var _a=t=>typeof(t==null?void 0:t.hz)=="number"&&t.hz>=20&&t.hz<=240?Js([1e3/t.hz],.5):NaN,Ma=(t,e)=>fe.indexOf(t)>=fe.indexOf(e)?t:e;function kl(t,e,s){return t?{name:t,from:"forced"}:e?{name:s?Ma(e,s):e,from:"hint"}:s?{name:s,from:"cache"}:null}var wl=/^\s*(<|>|[^+\-<>=\s][^+=]*?)?\s*(?:([+-])=\s*(\d*\.?\d+))?\s*$/,Ea=class{constructor(t={}){p(this,"steps",[]),p(this,"labels",new Map),p(this,"end",0),p(this,"prevStart",0),p(this,"elapsed",0),p(this,"iter",0),p(this,"last",0),p(this,"delayLeft"),p(this,"_paused"),p(this,"done",!1),p(this,"rewinding",!1),p(this,"promise"),p(this,"resolve"),p(this,"repeat"),p(this,"yoyo"),p(this,"onComplete");var e,s;this.repeat=Math.floor((e=t.repeat)!=null?e:0),this.yoyo=!!t.yoyo,this.delayLeft=(s=t.delay)!=null?s:0,this._paused=!!t.paused,this.onComplete=t.onComplete,this.promise=new Promise(n=>this.resolve=n)}get duration(){return this.end}get time(){return this.last}get paused(){return this._paused}get finished(){return this.done}at(t){if(t===void 0)return this.end;if(typeof t=="number")return Math.max(t,0);const e=wl.exec(t);if(!e)throw new Error('[engine] timeline: bad position "'.concat(t,'"'));const[,s,n,i]=e,a=i?(n==="-"?-1:1)*Number(i):0;let o=this.end;if(s==="<")o=this.prevStart;else if(s&&s!==">"){const r=this.labels.get(s.trim());r===void 0?this.labels.set(s.trim(),this.end):o=r}return Math.max(o+a,0)}add(t){let e=this.steps.length;for(;e>0&&this.steps[e-1].start>t.start;)e--;return this.steps.splice(e,0,t),this.prevStart=t.start,this.end=Math.max(this.end,t.start+t.dur),this}to(t,e,s,n="quadOut"){var i,a;const o=typeof n=="object"?n:{ease:n},r=typeof o.ease=="function"?o.ease:fs[(i=o.ease)!=null?i:"quadOut"];return this.add({target:t,to:e,from:null,fn:null,start:this.at(o.at)+((a=o.delay)!=null?a:0),dur:Math.max(s,0),ease:r,onUpdate:o.onUpdate,p:-1})}set(t,e,s){return this.add({target:t,to:e,from:null,fn:null,start:this.at(s),dur:0,ease:fs.linear,p:-1})}call(t,e){return this.add({target:null,to:null,from:null,fn:t,start:this.at(e),dur:0,ease:fs.linear,p:-1})}label(t,e){return this.labels.set(t,this.at(e)),this}wait(t){return this.end+=Math.max(t,0),this.prevStart=this.end,this}pause(){return this._paused=!0,this}resume(){return this._paused=!1,this}stop(){this.done||(this.done=!0,this.resolve())}seek(t){const e=Math.min(typeof t=="string"&&this.labels.has(t)?this.labels.get(t):this.at(t),this.end),s=this.yoyo&&this.iter%2===1;return this.elapsed=this.iter*this.end+(s?this.end-e:e),this.render(e),this}then(t,e){return this.promise.then(t,e)}update(t){if(this._paused||this.done)return;if(this.delayLeft>0){if(this.delayLeft-=t,this.delayLeft>0)return;t=-this.delayLeft,this.delayLeft=0}const e=this.end;if(e<=0)return this.render(0),this.complete();this.elapsed+=t;const s=this.repeat<0?1/0:e*(this.repeat+1),n=Math.min(this.elapsed,s),i=n>=s?this.repeat:Math.floor(n/e);for(;this.iter<i;){const o=this.yoyo&&this.iter%2===1;this.render(o?0:e),this.iter++,this.yoyo||(this.rewinding=!0,this.render(0),this.rewinding=!1)}const a=n-i*e;this.render(this.yoyo&&i%2===1?e-a:a),n>=s&&this.complete()}complete(){var t;this.done||(this.done=!0,(t=this.onComplete)==null||t.call(this),this.resolve())}render(t){const e=this.steps;if(t>=this.last)for(let s=0;s<e.length;s++){const n=e[s];t>=n.start&&this.apply(n,t)}else for(let s=e.length-1;s>=0;s--){const n=e[s];n.p>=0&&this.apply(n,t)}this.last=t}apply(t,e){var s,n;const i=t.dur>0?Math.min(Math.max((e-t.start)/t.dur,0),1):e>t.start||e===t.start&&!this.rewinding?1:0;if(i===t.p)return;if(t.p=i,t.fn){this.rewinding||t.fn();return}const a=t.target;if(a.destroyed||a._free)return;const o=t.to;if(!t.from){t.from={};for(const h in o)t.from[h]=Number((s=a[h])!=null?s:0)}const r=t.ease(i);for(const h in o)a[h]=t.from[h]+(o[h]-t.from[h])*r;(n=t.onUpdate)==null||n.call(t,r)}},Aa=class{constructor(){p(this,"list",[]),p(this,"timelines",[])}timeline(t){const e=new Ea(t);return this.timelines.push(e),e}tween(t,e,s,n="quadOut"){var i;const a=typeof n=="object"?n:{ease:n},o=typeof a.ease=="function"?a.ease:fs[(i=a.ease)!=null?i:"quadOut"];let r;const h=new Promise(l=>{var c;const f=Object.keys(e),u=new Float64Array(f.length);f.forEach((y,d)=>u[d]=Number(e[y])),r={target:t,keys:f,to:u,from:new Float64Array(f.length),started:!1,duration:Math.max(s,0),time:0,delay:(c=a.delay)!=null?c:0,ease:o,onUpdate:a.onUpdate,done:l,dead:!1}});return this.list.push(r),Object.assign(h,{stop:()=>this.finish(r)})}stopAll(t){const e=this.list;for(let s=0;s<e.length;s++)e[s].target===t&&this.finish(e[s])}get size(){return this.list.length}update(t){if(this.timelines.length){let n=0;const i=this.timelines;for(let a=0;a<i.length;a++){const o=i[a];o.update(t),o.finished||(i[n++]=o)}i.length=n}const e=this.list;if(!e.length)return;let s=0;for(let n=0;n<e.length;n++){const i=e[n];i.dead||this.step(i,t),i.dead||(e[s++]=i)}s!==e.length&&(e.length=s)}step(t,e){var s,n;if(t.target.destroyed)return this.finish(t);let i=e;if(t.delay>0){if(t.delay-=e,t.delay>0)return;i=-t.delay}const a=t.keys;if(!t.started){t.started=!0;for(let h=0;h<a.length;h++)t.from[h]=Number((s=t.target[a[h]])!=null?s:0)}t.time+=i;const o=t.duration>0?Math.min(t.time/t.duration,1):1,r=t.ease(o);for(let h=0;h<a.length;h++)t.target[a[h]]=t.from[h]+(t.to[h]-t.from[h])*r;(n=t.onUpdate)==null||n.call(t,r),o>=1&&this.finish(t)}finish(t){t.dead||(t.dead=!0,t.done())}clear(){for(const t of this.list)this.finish(t);this.list.length=0;for(const t of this.timelines)t.stop();this.timelines=[]}},Ft=720,Sa=class extends Ne{constructor(t,e){super(t),p(this,"paintAll",e)}draw(t,e){this.paintAll(t,e)}},_l=class extends Ne{constructor(t,e){super(t),p(this,"paintAll",e)}draw(t,e){this.paintAll(t,e)}},ue=()=>performance.now(),Ta=t=>{const e=lr(t);return e&&Object.freeze(e)};function Ml(){return je(this,arguments,function*(t={}){var e,s,n,i,a,o,r,h,l,c,f;const u=(e=t.play)!=null?e:null;let y=(s=t.canvas)!=null?s:null;y||(y=document.createElement("canvas"),y.style.cssText="position:fixed;top:0;left:0;width:100%;height:100%;display:block;touch-action:none",document.body.appendChild(y));let d=Bn(y,{renderer:(n=t.renderer)!=null?n:Zo(),failIfMajorPerformanceCaveat:t.failIfMajorPerformanceCaveat,instancing:t.instancing});y=d.canvas;const b=new Set,m=new Tn(Math.min(2048,d.maxTextureSize),4);m.onPage=k=>b.add(k),m.onDrop=k=>{b.delete(k),k.texture&&d.destroyTexture(k.texture),k.texture=null};let x=Qs(d);const g=new Aa,v=new ba,_=new Xn(m),T=new Map,N=new Map,R=new Map,M=new Map,P=new Map,z=new Set;let U=0;const G=(i=t.tier)!=null?i:vl(),O=String((a=d.info.renderer)!=null?a:""),X=(()=>{var k;try{return(k=le.localStorage)!=null?k:null}catch(S){return null}})(),L=typeof screen!="undefined"?"".concat(screen.width,"x").concat(screen.height):"",lt=xl(d.kind,O,L);pr(X,lt,bl(d.kind,O,L));const yt=gl(X,lt),$=kl(G,wa(d.kind,u==null?void 0:u.device),yt==null?void 0:yt.name);let w=(o=$==null?void 0:$.name)!=null?o:"medium",H=ze(w);_.setTier(w);let W=($==null?void 0:$.from)==="hint",bt=yt==null?void 0:yt.name,Z=(r=yt==null?void 0:yt.refresh)!=null?r:_a(u==null?void 0:u.device),j=1,se=1,Ae=1;const At={atlas:m,get pixelScale(){return j},get fontGen(){return U},get effects(){return H.effects},tweens:g,frame:k=>rn.frame(k),shape:k=>{const S=H.effects,I=S?j:-j;let E=T.get(I);E||(T.size>=8&&T.clear(),T.set(I,E=new Wi(2e3)));const V=ke(k);let q=E.get(k,V);return(!q||!m.valid(q.frame))&&E.set(k,q=xa(m,cl(k,S),j),V),q},bitmapFont:k=>rn.bitmapFont(k)};let Ot=1280,Kt=null;class sn extends An{get width(){return Ot}set width(S){}get height(){return Ft}set height(S){}get safe(){const S=Math.min(Ot,Ft*16/9);return{x:(Ot-S)/2,y:0,w:S,h:Ft}}}const qt=new sn(At),K=()=>{var k;const S=d.canvas,I=S.getBoundingClientRect();se=Math.max(1,I.width||S.clientWidth||innerWidth),Ae=Math.max(1,I.height||S.clientHeight||innerHeight),Ot=Ft*se/Ae;const E=Math.min(le.devicePixelRatio||1,(k=t.maxPixelRatio)!=null?k:2);if(Ae*E/Ft<=H.resolution){const q=Math.max(1,Math.round(Ae*E));j=q/Ft,d.resize(Math.max(1,Math.round(se*E)),q)}else j=H.resolution,d.resize(Math.round(Ot*j),Math.round(Ft*j));Kt&&Kt.style.setProperty("--unit","".concat(Ae/Ft,"px"))};addEventListener("resize",K);const gt=k=>{w=k,H=ze(k),_.setTier(k),K()},mt=typeof ResizeObserver!="undefined"?new ResizeObserver(K):null;mt==null||mt.observe(y);let St=(u==null?void 0:u.backdrop)==="video"?"video":"none",et=(h=u==null?void 0:u.view)!=null?h:null,pe=(u==null?void 0:u.orientation)==="portrait"?"portrait":"landscape",it=(l=Ta(u==null?void 0:u.safeArea))!=null?l:or,De=[],ws=-1/0,Be=!1,Ue=!1;const _s=new Set,Ms=()=>{const k=St==="video"?"transparent":"";document.documentElement.style.background=k,document.body.style.background=k},Wt=(k,S)=>{const I=k==="video"?"video":"none",E=S!=null?S:null;if(!(I===St&&(E===et||E&&et&&E.x===et.x&&E.y===et.y&&E.w===et.w&&E.h===et.h))){St=I,et=E,Ms();for(const V of[..._s])V(St,et)}},jt=[];if(u){const k=E=>{Array.isArray(E)&&(De=E,ws=ue())},S=E=>{Be=E,is()},I=E=>{if(G||W)return;Number.isFinite(Z)||(Z=_a(E));const V=wa(d.kind,E);V&&(W=!0,gt(bt?Ma(V,bt):V))};jt.push(u.on("start",E=>I(E==null?void 0:E.device)),u.on("start",E=>{((E==null?void 0:E.orientation)==="portrait"||(E==null?void 0:E.orientation)==="landscape")&&(pe=E.orientation);const V=Ta(E==null?void 0:E.safeArea);V&&(it=V)}),u.on("start",E=>{typeof(E==null?void 0:E.muted)=="boolean"&&(v.muted=E.muted)}),u.on("frame",E=>k(E==null?void 0:E.players)),u.on("players",E=>k(E==null?void 0:E.players)),u.on("backdrop",E=>Wt(E==null?void 0:E.backdrop,E==null?void 0:E.view)),u.on("start",E=>{var V;return Wt(E==null?void 0:E.backdrop,(V=E==null?void 0:E.view)!=null?V:u.view)}),u.on("pause",()=>S(!0)),u.on("resume",()=>S(!1)),u.on("break-start",()=>S(!0)),u.on("break-done",()=>S(!1)),u.on("break-end",()=>S(!1))),v.muted=u.muted===!0}Ms();const is=()=>Be||Ue||document.hidden?v.hold():v.release();let C=-1,B=[],Y=0;const st=()=>ue()-ws<1e3?De:[],at=k=>u?u.toScreen(k):ni(et,k),Pt=new ii,Se=()=>{if(C===Y)return B;C=Y;const k=pe==="portrait",S=St==="video"&&!k||!(u!=null&&u.smoothedBody)?()=>null:I=>u.smoothedBody(I);return B=ya(st(),at,Ot,Ft,S,k?{orientation:pe,hold:Pt,t:ue()}:void 0),B},zt={x:0,y:0,w:1,h:1},nn=()=>(zt.x=et?et.x*Ot:0,zt.y=et?et.y*Ft:0,zt.w=et?et.w*Ot:Ot,zt.h=et?et.h*Ft:Ft,zt),Zt=k=>{var S;const I=(S=k.alpha)!=null?S:1,E=k.tags?new Hn(m,k):null;E&&z.add(E);const V=typeof k.tags=="function"?k.tags:q=>String(q);return(q,kt)=>{var Tt,wt,Dt,Te,Ce,ct;if(St==="video")return;const nt=nn();for(const rt of st()){const ot=(wt=(Tt=u==null?void 0:u.smoothedBody)==null?void 0:Tt.call(u,rt))!=null?wt:rt.body,Bt=(ct=Is((Ce=(Te=(Dt=u==null?void 0:u.avatarOf)==null?void 0:Dt.call(u,rt))!=null?Te:rt.avatar)!=null?Ce:""))!=null?ct:ls;if(!_.draw(q.r,q.tex,ot,Bt,nt,I*kt,j)||!E)continue;const Ge=V(rt.id);Ge&&E.draw(q.r,q.tex,ot,Bt,nt,Ge,Ks(rt.id),I*kt,j,Ot,Ft)}}},re=new Set,ye=new Set,Lt=new Set;let Yt=!1,me=0,Nt=0,oe=0;const xe={fps:0,cpuMs:0,drawCalls:0,quads:0,filtersSkipped:0};let He=0,Vn=0,Kn=ue();const Es=[];let an=0;const za=()=>({r:d,kernel:At,tex:x});let Da=za();const mc=()=>{if(d.lost)return;const[k,S]=St==="video"||t.background===void 0?[0,0]:ne(t.background);d.time=oe,d.maxBlur=H.maxBlur,d.begin(k,S,j),ce(qt.world,null,qt.x,qt.y,qt.rotation,qt.scaleX,qt.scaleY),Ni(Da,qt,qt.alpha,qt.tint);const I=d.end();xe.drawCalls=I.drawCalls,xe.quads=I.quads,xe.filtersSkipped=I.filtersSkipped},Ba=k=>{var S;if(!Yt)return;me=requestAnimationFrame(Ba);const I=Math.min(Math.max((k-Nt)/1e3,0),.1);Nt&&Es.push(k-Nt),Nt=k,Y++;const E=ue(),V=Be||Ue;if(!V){oe+=I,g.update(I);for(const q of Lt)q.destroyed||q.update(I);for(const q of re)q(I,oe)}for(const q of ye)q(I);qt.sweep();for(const q of Lt)q.destroyed&&Lt.delete(q);if(d.lost?(an||(an=k),k-an>3e3&&xc()):(an=0,mc()),He++,Vn+=ue()-E,E-Kn>=1e3&&(xe.fps=Math.round(He*1e3/(E-Kn)),xe.cpuMs=Math.round(Vn/Math.max(He,1)*100)/100,(S=u==null?void 0:u.reportStats)==null||S.call(u,{fps:xe.fps,renderer:d.kind,tier:w}),He=0,Vn=0,Kn=E),Es.length>=180){const q=Number.isFinite(Z)?Z:Js(Es);!G&&!V&&yl(Es,q)&&w!=="low"&&(gt(ul(w)),bt=w,ka(X,lt,w,Number.isFinite(Z)?Z:void 0),console.info("[engine] slow frames: tier ".concat(w))),Es.length=0}},xc=()=>{const k=Un(d.canvas),S=Pn(k);if(S){console.warn("[engine] WebGL context lost for good: switching to Canvas 2D"),d.destroy(),d=S;for(const I of b)I.texture=null;for(const I of m.pages)b.add(I.surface);x=Qs(d),Da=za(),mt==null||mt.disconnect(),mt==null||mt.observe(k),K()}},Ua=()=>{is(),document.hidden||(Nt=0)};document.addEventListener("visibilitychange",Ua);const Ha=()=>{U++;for(const k of z)k.drop()};if((f=(c=document.fonts)==null?void 0:c.addEventListener)==null||f.call(c,"loadingdone",Ha),K(),!$&&t.probe!==!1&&(Number.isFinite(Z)||(Z=pl(yield El(dl))),!W)){H=ze("high"),K();const k=yield Al(d,m,()=>x,()=>j,Ot,()=>W);if(k.refresh=Z,!W){const S=ga(d.kind,k);ka(X,lt,S,Z),bt=S,gt(S)}}const rn={stage:qt,get tier(){return H},get renderer(){return d},get canvas(){return d.canvas},get pixelScale(){return j},get backdrop(){return St},get view(){return et},get orientation(){return pe},get safeArea(){return it},get paused(){return Be||Ue},sound:v,stats:xe,get time(){return oe},get supports(){const k=d.support;return{filters:k.filters,blur:k.filters&&H.maxBlur>0,shaders:k.shaders,maxBlur:k.filters?H.maxBlur:0,tiers:{high:{maxBlur:ze("high").maxBlur},medium:{maxBlur:ze("medium").maxBlur},low:{maxBlur:ze("low").maxBlur}}}},sprite:(k,S)=>new Ke(At,k,S),shape:(k,S)=>new ys(At,k,S),text:(k,S)=>new vs(At,k,S),group:k=>new An(At).set(k!=null?k:{}),particles(k,S={}){const I=typeof k=="object"&&"type"in k?At.shape(k).frame:k,E=new Bi(At,I,S),V=S,{max:q,blend:kt,gravity:Tt,drag:wt}=V,Dt=hn(V,["max","blend","gravity","drag"]);return E.set(Dt),Lt.add(E),E},tween:(k,S,I,E)=>g.tween(k,S,I,E),bake(k,S,I,E,V){return R.set(k,{w:S,h:I,draw:E,origin:V}),N.delete(k),rn.frame(k)},frame(k){var S,I,E,V;const q=N.get(k);if(q&&m.valid(q)&&(q.gen===0||q.scale===j))return q;const kt=R.get(k);if(kt){const Tt=j,wt=m.bake(kt.w*Tt,kt.h*Tt,Dt=>(Dt.scale(Tt,Tt),kt.draw(Dt)),Tt,(I=(S=kt.origin)==null?void 0:S.x)!=null?I:0,(V=(E=kt.origin)==null?void 0:E.y)!=null?V:0);return N.set(k,wt),wt}if(q)return q;throw new Error('[engine] no frame "'.concat(k,'": load it or bake it first'))},load(k){return je(this,null,function*(){yield Promise.all(Object.entries(k).map(([S,I])=>gc(S,I)))})},hands:k=>k===void 0?Se():Se().filter(S=>S.player===k),touched(k,S,I={}){var E;return k.updateWorld(),ma(k,Se(),S,(E=I.padding)!=null?E:0)},hits(k,S,I,E=0){return k.updateWorld(),Wn(k,S,I,E)},avatars:(k={})=>new Sa(At,Zt(k)),handMarkers(k={}){var S,I;const E=(S=k.radius)!=null?S:36,V=(I=k.look)!=null?I:"auto",q=new Float64Array(6),kt=Math.max(E*.12,3),Tt={type:"ring",r:E,lw:kt,fill:"rgba(251,231,184,0.3)",stroke:"#ffffff"},wt={type:"ring",r:E,lw:kt*1.8,stroke:bs,shadow:{color:bs,blur:E*.2}},Dt=(nt,rt,ot,Bt,Ge,Xe)=>{const on=rt.w/rt.scale;ce(q,null,ot-on/2,Bt-on/2,0,1,1),nt.r.quad(nt.tex(rt.surface),rt,q,on,on,Ge,Xe,"normal")},Te=nt=>{let rt=null,ot=!1;return()=>(rt&&m.valid(rt.frame)&&rt.frame.scale===j&&ot===H.effects?rt:(ot=H.effects,rt=At.shape(nt))).frame},Ce=Te(Tt),ct=Te(wt);return new _l(At,(nt,rt)=>{const ot=V==="video"||V==="auto"&&St==="video",Bt=Ce(),Ge=ot?ct():null;for(const Xe of Se())Ge&&Dt(nt,Ge,Xe.x,Xe.y,16777215,rt),Dt(nt,Bt,Xe.x,Xe.y,ne(Xe.color)[0],rt)})},timeline:k=>g.timeline(k),animation(k,S){const I=typeof k=="string"?bc(k):{frames:k},E=new Oe(At,I,S);return Lt.add(E),E},bitmapFont(k,S){if(!S){const E=M.get(k);if(!E)throw new Error('[engine] no bitmap font "'.concat(k,'": load or make it first'));return E}const I="data"in S?Ga(Vs(S.data),S.pages):il(At,S);return M.set(k,I),I},players:()=>st(),onFrame(k){return re.add(k),()=>{re.delete(k)}},onRender(k){return ye.add(k),()=>{ye.delete(k)}},onBackdrop(k){return _s.add(k),()=>{_s.delete(k)}},get hud(){return Kt||(Kt=document.createElement("div"),Kt.style.cssText="position:fixed;top:0;right:0;bottom:0;left:0;pointer-events:none;overflow:hidden",document.body.appendChild(Kt),K()),Kt},random:(k=0,S=1)=>k+Math.random()*(S-k),start(){Yt||(Yt=!0,Nt=0,me=requestAnimationFrame(Ba))},pause(){Ue=!0,is()},resume(){Ue=!1,is()},destroy(){var k,S;Yt=!1,cancelAnimationFrame(me),jt.forEach(I=>I()),removeEventListener("resize",K),mt==null||mt.disconnect(),document.removeEventListener("visibilitychange",Ua),(S=(k=document.fonts)==null?void 0:k.removeEventListener)==null||S.call(k,"loadingdone",Ha),g.clear(),wo(At),v.destroy(),d.destroy(),Kt==null||Kt.remove()}};function bc(k){const S=P.get(k);if(S)return S;const I=[...new Set([...N.keys(),...R.keys()])].filter(E=>E.startsWith(k)).sort(Mo);if(!I.length)throw new Error('[engine] no animation or frames "'.concat(k,'\u2026"'));return{frames:I}}function gc(k,S){return je(this,null,function*(){var I,E;const V=S.split("?")[0].split(".").pop().toLowerCase();if(["mp3","ogg","wav","m4a","aac","webm"].includes(V))return v.load(k,S);if(["woff","woff2","ttf","otf"].includes(V)){const wt=new FontFace(k,"url(".concat(S,")"));document.fonts.add(yield wt.load()),U++;return}const q=new URL(S,location.href);if(V==="fnt")return Xa(k,Vs(yield(yield fetch(S)).text()),q);if(V==="json"){const wt=yield(yield fetch(S)).json();if(Array.isArray(wt.chars)&&!wt.frames)return Xa(k,Vs(wt),q);const Dt=yield jn(new URL((E=(I=wt.meta)==null?void 0:I.image)!=null?E:S.replace(/\.json$/,".png"),q).href);vc(k,wt,Ds(Dt));return}const kt=yield jn(S),Tt=Ds(kt);b.add(Tt),N.set(k,{surface:Tt,x:0,y:0,w:kt.width,h:kt.height,scale:1,gen:0,ox:0,oy:0,margin:0})})}function Ga(k,S){return nl(k,S.map(I=>{const E=Ds(I);return b.add(E),E}))}function Xa(k,S,I){return je(this,null,function*(){M.set(k,Ga(S,yield Promise.all(S.pages.map(E=>jn(new URL(E,I).href)))))})}function vc(k,S,I){var E,V,q,kt,Tt,wt;b.add(I);const Dt=Array.isArray(S.frames)?S.frames:Object.entries(S.frames).map(([ct,nt])=>We(A({},nt),{filename:ct})),Te=[],Ce=[];for(const ct of Dt){const nt=ct.frame,rt=ct.filename.replace(Ca,"");ct.rotated&&console.warn("[engine] ".concat(k,"/").concat(rt," is rotated: export without rotation"));const ot={surface:I,x:nt.x,y:nt.y,w:nt.w,h:nt.h,scale:1,gen:0,ox:0,oy:0,margin:0};ct.trimmed&&ct.sourceSize&&ct.spriteSourceSize&&(ot.sw=ct.sourceSize.w,ot.sh=ct.sourceSize.h,ot.tx=ct.spriteSourceSize.x,ot.ty=ct.spriteSourceSize.y);const Bt=ct.scale9Borders;Bt&&(ot.slice=[Bt.y,((E=ot.sw)!=null?E:nt.w)-Bt.x-Bt.w,((V=ot.sh)!=null?V:nt.h)-Bt.y-Bt.h,Bt.x]),N.set("".concat(k,"/").concat(rt),ot),Te.push("".concat(k,"/").concat(rt)),Ce.push(((q=ct.duration)!=null?q:0)/1e3)}for(const[ct,nt]of Object.entries((kt=S.animations)!=null?kt:{}))P.set("".concat(k,"/").concat(ct),{frames:nt.map(rt=>"".concat(k,"/").concat(rt.replace(Ca,"")))});for(const ct of(wt=(Tt=S.meta)==null?void 0:Tt.frameTags)!=null?wt:[]){const nt=[];for(let ot=ct.from;ot<=ct.to;ot++)nt.push(ot);ct.direction==="reverse"&&nt.reverse(),ct.direction==="pingpong"&&nt.push(...nt.slice(1,-1).reverse());const rt=nt.every(ot=>Ce[ot]>0);P.set("".concat(k,"/").concat(ct.name),A({frames:nt.map(ot=>Te[ot])},rt?{durations:nt.map(ot=>Ce[ot])}:{}))}}return rn})}var Ca=/\.(png|webp|jpe?g|gif|bmp)$/i;function jn(t){return new Promise((e,s)=>{const n=new Image;n.onload=()=>e(n),n.onerror=()=>s(new Error("[engine] image did not load: ".concat(t))),n.src=t})}function El(t){return new Promise(e=>{const s=[];let n=0;const i=a=>{n&&s.push(a-n),n=a,s.length<t?requestAnimationFrame(i):e(s)};requestAnimationFrame(i)})}function Al(t,e,s,n,i,a=()=>!1){return je(this,null,function*(){const o=n(),r=xa(e,{type:"star",r:30,fill:"#ffd23f",stroke:"#3a2a10",lw:3},o).frame,h=[],l=[],c=new Float64Array(6),f=.004,u=t.kind==="canvas2d"?t.canvas.getContext("2d"):null,y=ue();let d=0;return yield new Promise(b=>{const m=x=>{d&&x-y>250&&h.push(x-d),d=x;const g=ue();t.begin(0,0,o);const v=s();for(let _=0;_<300;_++){const T=x/1e3+_;ce(c,null,_*37%i,_*53%Ft,T,1,1),t.quad(v(r.surface),r,c,r.w/o,r.h/o,16777215,f,"normal")}for(let _=0;_<40;_++)t.ellipse(100+_*20,300,20,14,_,16746496,f),t.stroke([100+_*20,400,120+_*20,460,100+_*20,520],3,18,3368703,f,!1);t.end(),u==null||u.getImageData(0,0,1,1),x-y>250&&l.push(ue()-g),x-y<750&&!a()?requestAnimationFrame(m):(t.begin(0,0,o),t.end(),b())};requestAnimationFrame(m)}),{intervals:h,cpu:l}})}var Sl=64,Ra=32,Tl=0,Cl="fabi-cm-".concat(Math.random().toString(36).slice(2,7),"-"),Fa=new Set,Pa=(t,e)=>{Fa.has(t)||(Fa.add(t),console.warn(e))},Rl=t=>new Fl(t),Fl=class{constructor(t){p(this,"r",t),p(this,"css","none"),p(this,"plans",new Wi(Sl)),p(this,"buf",new Float64Array(64)),p(this,"keys",[]),p(this,"classes",new Map),p(this,"live",new Set),p(this,"svgs",new Map),p(this,"t",0),p(this,"cur",null),p(this,"svgFn",e=>this.svg(e)),p(this,"scr",[]),p(this,"flip",0)}chain(t,e){var s,n;const i=this.r;let a=this.buf;a[0]=i.scale,a[1]=i.maxBlur;let o=2;for(let b=0;b<e.length;b++){const m=e[b];if(o+22>a.length){const g=new Float64Array(a.length*2);g.set(a),a=this.buf=g}let x=this.classes.get(m.constructor);x===void 0&&this.classes.set(m.constructor,x=this.classes.size),a[o++]=x,a[o++]=m.enabled?1:0,m.params&&(o=m.params(a,o))}const r=(n=(s=this.keys)[o])!=null?n:s[o]=new Float64Array(o);for(let b=0;b<o;b++)r[b]=a[b];const h=ke(r);let l=this.plans.get(r,h);l||this.plans.set(r,l=this.plan(e),h);for(let b=0;b<l.svgs.length;b++){const m=l.svgs[b];m.used<0&&this.attach(m),m.used=this.t}i.skipped+=l.skip;let c=t;const f=i.rx0,u=i.ry0,y=i.rx1-f,d=i.ry1-u;for(let b=0;b<l.paints.length;b++)l.parts[b]&&(c=this.bake(c,l.parts[b])),e[l.paints[b]].paint2d(c.getContext("2d"),f,u,y,d);return this.css=l.parts[l.paints.length]||"none",c}tick(){const t=++this.t;if(!(t%Ra||!this.live.size))for(const e of this.live)t-e.used>Ra&&this.detach(e)}destroy(){for(const t of this.live)this.detach(t);this.plans.clear()}svg(t){if(typeof document=="undefined"||!document.body)return null;const e=Array.from({length:20},(n,i)=>{var a;return(a=t[i])!=null?a:0}).join(" ");let s=this.svgs.get(e);if(!s){const n="http://www.w3.org/2000/svg",i=document.createElementNS(n,"svg");i.setAttribute("width","0"),i.setAttribute("height","0"),i.setAttribute("aria-hidden","true"),i.style.position="absolute";const a=document.createElementNS(n,"filter"),o=Cl+ ++Tl;a.setAttribute("id",o),a.setAttribute("color-interpolation-filters","sRGB");const r=document.createElementNS(n,"feColorMatrix");r.setAttribute("type","matrix"),r.setAttribute("values",e),a.append(r),i.append(a),this.attach(s={key:e,id:o,el:i,used:this.t})}return this.cur.svgs.push(s),"url(#".concat(s.id,")")}attach(t){document.body.append(t.el),this.live.add(t),this.svgs.has(t.key)||this.svgs.set(t.key,t)}detach(t){t.el.remove(),t.used=-1,this.live.delete(t),this.svgs.get(t.key)===t&&this.svgs.delete(t.key)}plan(t){const e=this.r,s=this.cur={parts:[],paints:[],skip:0,svgs:[]};let n="";for(let i=0;i<t.length;i++){const a=t[i];if(!a.enabled)continue;if(a.kind===kn){s.skip++,Pa("shader","[engine] shader() filters are WebGL only: on Canvas 2D they are skipped (check engine.supports.shaders)");continue}const o=e.support.filters&&a.css?a.css(e.scale,e.maxBlur,this.svgFn):null;o!==null?n+=n?" ".concat(o):o:a.paint2d?(s.parts.push(n),s.paints.push(i),n=""):(s.skip++,Pa("css","[engine] this browser's Canvas 2D has no ctx.filter: colour filters, blur and shadows are skipped (tint works; check engine.supports.filters)"))}return s.parts.push(n),s}bake(t,e){const s=this.r,n=this.flip^=1;let i=this.scr[n];(!i||i.width!==s.canvas.width||i.height!==s.canvas.height)&&(i=this.scr[n]=document.createElement("canvas"),i.width=s.canvas.width,i.height=s.canvas.height);const a=i.getContext("2d"),o=s.rx0,r=s.ry0,h=s.rx1-o,l=s.ry1-r;return a.clearRect(o,r,h,l),a.filter=e,a.drawImage(t,o,r,h,l,o,r,h,l),a.filter="none",i}},Pl=64,$s=17,Ll=t=>"".concat(Dn,"\nuniform sampler2D uTexture;\nuniform mat4 uM[").concat(t,"];\nuniform vec4 uO[").concat(t,"];\nuniform int uK;\nvarying vec2 vUv;\nvarying vec4 vColor;\nvoid main() {\n vec4 c = texture2D(uTexture, vUv);\n if (c.a > 0.0) c.rgb /= c.a;\n for (int i = 0; i < ").concat(t,"; i++) {\n if (i >= uK) break;\n c = clamp(uM[i] * c + uO[i], 0.0, 1.0);\n }\n c.rgb *= c.a;\n gl_FragColor = c * vColor;\n}"),Nl=()=>"".concat(Dn,"\nuniform sampler2D uTexture;\nuniform vec2 uDir;\nuniform vec2 uOff;\nuniform vec2 uTaps[").concat($s,"];\nuniform int uN;\nuniform float uMode;\nuniform vec4 uShadow;\nvarying vec2 vUv;\nvarying vec4 vColor;\nvoid main() {\n vec2 p = vUv + uOff;\n vec4 c = texture2D(uTexture, p) * uTaps[0].y;\n for (int i = 1; i < ").concat($s,"; i++) {\n if (i >= uN) break;\n vec2 d = uDir * uTaps[i].x;\n c += (texture2D(uTexture, p + d) + texture2D(uTexture, p - d)) * uTaps[i].y;\n }\n if (uMode > 0.5) c = uShadow * c.a;\n gl_FragColor = c * vColor;\n}");function Il(t,e,s=new Float32Array(20)){for(let n=0;n<4;n++)for(let i=0;i<5;i++){let a=i===4?e[n*5+4]:0;for(let o=0;o<4;o++)a+=e[n*5+o]*t[o*5+i];s[n*5+i]=a}return t.set(s),t}var Ol=t=>new zl(t),zl=class{constructor(t){p(this,"r",t),p(this,"colorProg",null),p(this,"blurProg",null),p(this,"user",new Map),p(this,"uses",0),p(this,"userErr",new Map),p(this,"scratchT",new Map),p(this,"steps",[]),p(this,"mats",[]),p(this,"counts",[]),p(this,"colorN"),p(this,"fm",new Float32Array(20)),p(this,"fm2",new Float32Array(20)),p(this,"fm3",new Float32Array(20)),p(this,"m16"),p(this,"o4"),p(this,"taps",new Float32Array($s*2));const e=t.gl;this.colorN=Math.max(1,Math.min(8,Math.floor((e.getParameter(e.MAX_FRAGMENT_UNIFORM_VECTORS)-4)/5))),this.m16=new Float32Array(16*this.colorN),this.o4=new Float32Array(4*this.colorN)}check(t){var e;return this.r.lost?null:(this.userProg(t,!1),(e=this.userErr.get(t))!=null?e:null)}destroy(){const t=this.r.gl;for(const e of this.scratchT.values())t.deleteTexture(e.gl),t.deleteFramebuffer(e.fb);this.scratchT.clear();for(const e of[this.colorProg,this.blurProg])e&&t.deleteProgram(e.p);for(const e of this.user.values())e.p&&t.deleteProgram(e.p.p);this.user.clear()}userProg(t,e){const s=this.user,n=s.get(t);if(n)return n.t=++this.uses,n.p;if(this.r.lost)return null;if(s.size>=Pl){let a="",o=1/0;for(const[h,l]of s)l.t<o&&(o=l.t,a=h);const r=s.get(a).p;r&&this.r.gl.deleteProgram(r.p),s.delete(a),this.userErr.delete(a)}let i;try{i=this.r.build(t)}catch(a){i=null;const o=a.message;this.userErr.set(t,o),e&&console.error("[engine] a shader filter does not compile: it is skipped.\n".concat(o))}return s.set(t,{p:i,t:++this.uses}),i}scratch(t,e){var s;const n=this.r,i=Math.ceil(n.canvas.width/t),a=Math.ceil(n.canvas.height/t),o=t*8+e;let r=(s=this.scratchT.get(o))!=null?s:null;return r&&(r.w!==i||r.h!==a)&&(n.drop(r),r=null),r||(r=n.target(i,a,t,!0),r?this.scratchT.set(o,r):this.scratchT.delete(o)),r}pass(t,e,s,n,i=!1){const a=this.r,o=a.gl;a.flush(),a.mapped=!1,a.bindFb(n),o.viewport(0,0,n.w,n.h),i||(o.disable(o.SCISSOR_TEST),o.clearColor(0,0,0,0),o.clear(o.COLOR_BUFFER_BIT)),a.use(t);const r=n.f;o.uniform2f(t.uScale,2/(r*n.w),-2/(r*n.h));const h=Math.floor(a.rx0/r)*r,l=Math.floor(a.ry0/r)*r,c=Math.min(Math.ceil(a.rx1/r),n.w)*r,f=Math.min(Math.ceil(a.ry1/r),n.h)*r,u=1/(s*e.width),y=1/(s*e.height);a.bScis=!1,a.batch.push(h,l,c,l,c,f,h,f,h*u,1-l*y,c*u,1-f*y,4294967295,a.slotOf(e)),a.flush()}post(t){var e,s;return t==="color"?(e=this.colorProg)!=null?e:this.colorProg=this.r.build(Ll(this.colorN)):(s=this.blurProg)!=null?s:this.blurProg=this.r.build(Nl())}linear(t,e){var s;const n=this.r,i=n.gl;n.bindTex((s=n.layerTex.get(t))!=null?s:null,0);const a=e?i.LINEAR:i.NEAREST;i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MIN_FILTER,a),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MAG_FILTER,a)}chain(t,e,s){const n=this.r,i=this.steps,a=n.scale,o=n.maxBlur;let r=0;for(let f=0;f<s.length;f++){const u=s[f];if(u.enabled)if(u.kind===bn&&u.toMatrix){(!r||i[r-1]!==null)&&(i[r]=null,(!this.mats[r]||this.mats[r].length<20*this.colorN)&&(this.mats[r]=new Float32Array(20*this.colorN)),this.counts[r]=0,r++);const y=this.mats[r-1],d=this.counts[r-1];if(d<this.colorN)u.toMatrix(this.fm),y.set(this.fm,d*20),this.counts[r-1]=d+1;else{const b=(d-1)*20;for(let m=0;m<20;m++)this.fm2[m]=y[b+m];u.toMatrix(this.fm),Il(this.fm2,this.fm,this.fm3),y.set(this.fm2,b)}}else u.kind===kn?this.userProg(u.source,!0)?i[r++]=u:n.skipped++:u.kind===gn?Math.min(u.radius,o)*a>=.25&&(i[r++]=u):u.kind===vn?i[r++]=u:n.skipped++}if(!r)return!1;const h=n.gl;let l=t,c=-1;for(let f=0;f<r;f++){const u=f===r-1,y=c===0?1:0,d=u?null:this.scratch(1,y);if(!u&&!d)break;const b=i[f];if(b===null){const m=this.post("color");n.use(m);const x=this.mats[f],g=this.counts[f],v=this.m16,_=this.o4;for(let T=0;T<g;T++)for(let N=0;N<4;N++){for(let R=0;R<4;R++)v[T*16+R*4+N]=x[T*20+N*5+R];_[T*4+N]=x[T*20+N*5+4]}h.uniformMatrix4fv(n.u(m,"uM"),!1,v),h.uniform4fv(n.u(m,"uO"),_),h.uniform1i(n.u(m,"uK"),g),d?this.pass(m,l,1,d):n.final(m,l,1,e)}else if(b.kind===gn)this.blur(l,c<0,Math.min(b.radius,o)*a,d,e,null);else if(b.kind===vn){const m=b,x=this.scratch(1,2);if(!x)break;this.blur(l,c<0,Math.max(Math.min(m.blur,o),0)*a,x,1,m);const g=d!=null?d:e<1?this.scratch(1,y):null;g?(this.pass(n.main,x.tex,1,g),this.pass(n.main,l,1,g,!0),d||n.final(n.main,g.tex,1,e)):(n.final(n.main,x.tex,1,1),n.final(n.main,l,1,1))}else{const m=b,x=this.userProg(m.source,!0);n.use(x);const g=n.canvas.width,v=n.canvas.height;h.uniform2f(n.u(x,"uResolution"),g,v),h.uniform1f(n.u(x,"uTime"),n.time),h.uniform4f(n.u(x,"uRect"),n.rx0/g,1-n.ry1/v,n.rx1/g,1-n.ry0/v);const _=m.uniforms;for(const T in _){const N=n.u(x,T);if(!N)continue;const R=_[T];typeof R=="number"?h.uniform1f(N,R):R.length===2?h.uniform2fv(N,R):R.length===3?h.uniform3fv(N,R):R.length===4?h.uniform4fv(N,R):R.length===1&&h.uniform1fv(N,R)}d?this.pass(x,l,1,d):n.final(x,l,1,e)}d&&(l=d.tex,c=y)}return n.remap(),!0}blur(t,e,s,n,i,a){const o=this.r,r=o.gl,h=this.post("blur");let l=1;for(;l<16&&s/l>8;)l*=2;e&&this.linear(t,!0);let c=t,f=1;const u=Math.sqrt(Math.max(s*s-(l*l-1)/12,0))/l,y=s>=.25?this.tapsFor(u):this.tapsFor(0);let d=!0;if(y>1){for(let m=2;m<=l&&d;m*=2){const x=this.scratch(m,0);x?(this.pass(o.main,c,f,x),c=x.tex,f=m):d=!1}const b=d?this.scratch(l,3):null;b&&(o.use(h),r.uniform2fv(o.u(h,"uTaps"),this.taps),r.uniform1i(o.u(h,"uN"),y),r.uniform2f(o.u(h,"uDir"),1/c.width,0),r.uniform2f(o.u(h,"uOff"),0,0),r.uniform1f(o.u(h,"uMode"),0),this.pass(h,c,f,b),c=b.tex)}if(o.use(h),r.uniform2fv(o.u(h,"uTaps"),this.taps),r.uniform1i(o.u(h,"uN"),y),r.uniform2f(o.u(h,"uDir"),0,1/c.height),a){const b=a.opacity,m=a.rgb;r.uniform4f(o.u(h,"uShadow"),(m>>16&255)/255*b,(m>>8&255)/255*b,(m&255)/255*b,b),r.uniform1f(o.u(h,"uMode"),1),r.uniform2f(o.u(h,"uOff"),-a.dx*o.scale/(f*c.width),a.dy*o.scale/(f*c.height))}else r.uniform1f(o.u(h,"uMode"),0),r.uniform2f(o.u(h,"uOff"),0,0);n?this.pass(h,c,f,n):o.final(h,c,f,i),e&&this.linear(t,!1)}tapsFor(t){const e=this.taps;if(e.fill(0),e[1]=1,t<.2)return 1;const s=Math.min(Math.ceil(3*t),($s-1)*2),n=-1/(2*t*t);let i=1,a=1;for(let o=1;o<=s;o+=2){const r=Math.exp(o*o*n),h=o+1<=s?Math.exp((o+1)*(o+1)*n):0,l=r+h;e[a*2]=(o*r+(o+1)*h)/l,e[a*2+1]=l,i+=2*l,a++}for(let o=0;o<a;o++)e[o*2+1]=e[o*2+1]/i;return a}},de=t=>Math.min(Math.max(t,0),1),ee=t=>Math.max(t,0),ks=class{constructor(){p(this,"enabled",!0),ie.gl=Ol,ie.c2d=Rl}},Ee=class extends ks{constructor(t){super(),p(this,"amount",t),p(this,"kind",bn)}params(t,e){return t[e]=this.amount,e+1}};function tn(t,e,s){t.fill(0),t[0]=t[6]=t[12]=e,t[4]=t[9]=t[14]=s,t[18]=1}function en(t,e){t.fill(0);for(let s=0;s<3;s++)for(let n=0;n<3;n++)t[s*5+n]=e[s*3+n];t[18]=1}var Q=new Float64Array(9),Dl=class extends Ee{toMatrix(t){tn(t,ee(this.amount),0)}css(){return"brightness(".concat(ee(this.amount),")")}},Bl=class extends Ee{toMatrix(t){const e=ee(this.amount);tn(t,e,.5-.5*e)}css(){return"contrast(".concat(ee(this.amount),")")}},Ul=class extends Ee{toMatrix(t){const e=de(this.amount);tn(t,1-2*e,e)}css(){return"invert(".concat(de(this.amount),")")}},Hl=class extends Ee{toMatrix(t){const e=ee(this.amount);Q[0]=.213+.787*e,Q[1]=.715-.715*e,Q[2]=.072-.072*e,Q[3]=.213-.213*e,Q[4]=.715+.285*e,Q[5]=.072-.072*e,Q[6]=.213-.213*e,Q[7]=.715-.715*e,Q[8]=.072+.928*e,en(t,Q)}css(){return"saturate(".concat(ee(this.amount),")")}},Gl=class extends Ee{toMatrix(t){const e=1-de(this.amount);Q[0]=.2126+.7874*e,Q[1]=.7152-.7152*e,Q[2]=.0722-.0722*e,Q[3]=.2126-.2126*e,Q[4]=.7152+.2848*e,Q[5]=.0722-.0722*e,Q[6]=.2126-.2126*e,Q[7]=.7152-.7152*e,Q[8]=.0722+.9278*e,en(t,Q)}css(){return"grayscale(".concat(de(this.amount),")")}},Xl=class extends Ee{toMatrix(t){const e=1-de(this.amount);Q[0]=.393+.607*e,Q[1]=.769-.769*e,Q[2]=.189-.189*e,Q[3]=.349-.349*e,Q[4]=.686+.314*e,Q[5]=.168-.168*e,Q[6]=.272-.272*e,Q[7]=.534-.534*e,Q[8]=.131+.869*e,en(t,Q)}css(){return"sepia(".concat(de(this.amount),")")}},ql=class extends Ee{get angle(){return this.amount}set angle(t){this.amount=t}toMatrix(t){const e=this.amount*Math.PI/180,s=Math.cos(e),n=Math.sin(e);Q[0]=.213+s*.787-n*.213,Q[1]=.715-s*.715-n*.715,Q[2]=.072-s*.072+n*.928,Q[3]=.213-s*.213+n*.143,Q[4]=.715+s*.285+n*.14,Q[5]=.072-s*.072-n*.283,Q[6]=.213-s*.213-n*.787,Q[7]=.715-s*.715+n*.715,Q[8]=.072+s*.928+n*.072,en(t,Q)}css(){return"hue-rotate(".concat(this.amount,"deg)")}},Wl=class extends Ee{constructor(t,e){super(e),p(this,"c",16777215),p(this,"cs",""),this.color=t}get color(){return this.c}set color(t){this.c=ne(t)[0],this.cs=hs(this.c)}params(t,e){return t[e]=this.amount,t[e+1]=this.c,e+2}toMatrix(t){const e=de(this.amount);tn(t,1-e,0),t[4]=(this.c>>16&255)/255*e,t[9]=(this.c>>8&255)/255*e,t[14]=(this.c&255)/255*e}css(){return null}paint2d(t,e,s,n,i){const a=de(this.amount);a<=0||(t.save(),t.setTransform(1,0,0,1,0,0),t.globalAlpha=a,t.globalCompositeOperation="source-atop",t.fillStyle=this.cs,t.fillRect(e,s,n,i),t.restore())}},jl=class extends ks{constructor(t){if(super(),p(this,"kind",bn),p(this,"values"),t.length!==20)throw new Error("colorMatrix: 20 numbers expected (4 rows of 5), got ".concat(t.length));this.values=Array.from(t)}toMatrix(t){var e;for(let s=0;s<20;s++)t[s]=(e=this.values[s])!=null?e:0}params(t,e){var s;for(let n=0;n<20;n++)t[e+n]=(s=this.values[n])!=null?s:0;return e+20}css(t,e,s){return s?s(this.values):null}},Yl=class extends ks{constructor(t){super(),p(this,"radius",t),p(this,"kind",gn)}params(t,e){return t[e]=this.radius,e+1}pad(t){return 3*Math.min(ee(this.radius),t)}css(t,e){return"blur(".concat(Math.min(ee(this.radius),e)*t,"px)")}},Ql=class extends ks{constructor(t,e,s,n){super(),p(this,"dx",t),p(this,"dy",e),p(this,"blur",s),p(this,"kind",vn),p(this,"rgb",0),p(this,"a",1),this.color=n}get opacity(){return this.a}set opacity(t){this.a=de(t)}get color(){return this.rgb}set color(t){const[e,s]=ne(t);this.rgb=e,this.a=s}params(t,e){return t[e]=this.dx,t[e+1]=this.dy,t[e+2]=this.blur,t[e+3]=this.rgb,t[e+4]=this.a,e+5}pad(t){return 3*Math.min(ee(this.blur),t)+Math.max(Math.abs(this.dx),Math.abs(this.dy))}css(t,e){return"drop-shadow(".concat(this.dx*t,"px ").concat(this.dy*t,"px ").concat(2*Math.min(ee(this.blur),e)*t,"px ").concat(hs(this.rgb,this.opacity),")")}},Vl="#ifdef GL_FRAGMENT_PRECISION_HIGH\nprecision highp float;\n#else\nprecision mediump float;\n#endif\nuniform sampler2D uTexture;\nuniform vec2 uResolution;\nuniform float uTime;\nuniform vec4 uRect;\nvarying vec2 vUv;\nvarying vec4 vColor;\n#define main fabiUserMain\n#line 1\n",Kl=t=>"".concat(Vl).concat(t,"\n#undef main\nvoid main() {\n fabiUserMain();\n gl_FragColor *= vColor.a;\n}\n"),Zl=class extends ks{constructor(t){var e,s;super(),p(this,"kind",kn),p(this,"source"),p(this,"uniforms",{}),p(this,"padding"),this.source=Kl(t.fragment),this.padding=(e=t.padding)!=null?e:0;for(const n in(s=t.uniforms)!=null?s:{}){const i=t.uniforms[n];this.uniforms[n]=typeof i=="number"?i:Float32Array.from(i)}}pad(){return ee(this.padding)}},Jl=(t,e=1)=>new Wl(t,e),$l=t=>new Dl(t),tc=t=>new Bl(t),ec=t=>new Hl(t),sc=(t=1)=>new Gl(t),nc=(t=1)=>new Xl(t),ic=t=>new ql(t),ac=(t=1)=>new Ul(t),rc=t=>new jl(t),oc=t=>new Yl(t),lc=(t,e,s,n="rgba(0,0,0,0.5)")=>new Ql(t,e,s,n);function cc(t){var e,s;const n=new Zl(t),i=(s=(e=ie.live)==null?void 0:e.filters())==null?void 0:s.check(n.source);if(i)throw new Error("shader(): the fragment does not compile:\n".concat(i));return n}var Yn="x y rotation scaleX scaleY alpha visible blend tint z hitRadius clip mask filters".split(" "),La="frameName _frame _w _h slice autoAnchor".split(" "),hc="fps loop speed onComplete durations".split(" "),Qn=["anchorX","anchorY"],fc=[...Yn,...La,...hc,...Qn],uc=[...Yn,...La,...Qn],dc=[...Yn,...Qn],Na=t=>t instanceof Oe?fc:t instanceof Ke?uc:dc;function pc(t){const e={},s=t;for(const n of Na(t))e[n]=s[n];return t instanceof ys&&(e.spec=t.spec),t instanceof vs&&(e.text=t.text,e.style=t.style),t instanceof Oe&&(e.playing=t.playing),e}function Ia(t,e){const s=t;t instanceof ys&&t.spec!==e.spec&&(t.spec=e.spec),t instanceof vs&&(t.text=e.text,t.style!==e.style&&(s._style=e.style,s.dirty=!0)),t instanceof Oe&&t.gotoFrame(e.speed<0?t.frameCount-1:0);const n=t instanceof ys||t instanceof vs,i=Na(t);for(let a=0;a<i.length;a++){const o=i[a];(!n||o!=="_frame"&&o!=="frameName")&&(s[o]=e[o])}}var Oa=class{constructor(t,e={}){p(this,"factory",t),p(this,"opts",e),p(this,"stats",{live:0,free:0,created:0}),p(this,"free",[]),p(this,"states",new Map),p(this,"dead",!1)}get(t){if(this.dead)throw new Error("[engine] nodePool.get() after destroy()");let e=this.free.pop();if(e){this.stats.free--,e._free=!1;const s=this.states.get(e);Ia(e,s),e.visible=s.visible,e instanceof Oe&&s.playing&&e.play()}else{if(e=this.factory(),!(e instanceof Ne))throw new Error("[engine] a nodePool factory must return a node (engine.sprite, engine.shape, \u2026)");if(e._pool)throw new Error("[engine] a nodePool factory returned a node of another pool: make a new node in it");this.states.set(e,pc(e)),e._pool=this,this.stats.created++}return this.stats.live++,t&&e.set(t),e}release(t){var e,s,n;const i=this.states.get(t);if(!(!i||t.destroyed)&&!t._free){if(this.opts.max!==void 0&&this.free.length>=this.opts.max)return t.destroy();(e=t.parent)==null||e.remove(t),t.kernel.tweens.stopAll(t),this.stats.live--,Ia(t,i),t instanceof Oe&&t.stop(),t.visible=!1,t._free=!0,(n=(s=this.opts).reset)==null||n.call(s,t),this.free.push(t),this.stats.free++}}forget(t){const e=t;if(this.states.delete(e))if(e._free){const s=this.free.indexOf(e);s>=0&&(this.free[s]=this.free[this.free.length-1],this.free.pop()),this.stats.free--}else this.stats.live--}clear(){for(;this.free.length;)this.free[this.free.length-1].destroy()}destroy(){this.dead=!0;for(const t of[...this.states.keys()])t.destroy()}},yc=(t,e)=>new Oa(t,e);return Re.exports});
|