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