@fabi-play/engine 0.5.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -0
- package/dist/fabi-play-engine.d.ts +65 -5
- package/dist/fabi-play-engine.js +13 -13
- package/dist/fabi-play-engine.lite.d.ts +65 -5
- package/dist/fabi-play-engine.lite.js +13 -13
- package/dist/fabi-play-engine.lite.umd.js +118 -20
- package/dist/fabi-play-engine.lite.umd.min.js +13 -13
- package/dist/fabi-play-engine.umd.js +118 -20
- package/dist/fabi-play-engine.umd.min.js +13 -13
- package/dist/index.d.ts +65 -5
- package/dist/index.development.js +117 -19
- package/dist/index.js +13 -13
- package/dist/integrity.json +9 -9
- package/package.json +5 -5
package/dist/fabi-play-engine.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
"use strict";(()=>{var Ts=Object.defineProperty;var _a=(s,n,e)=>n in s?Ts(s,n,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[n]=e;var La=(s,n)=>{for(var e in n)Ts(s,e,{get:n[e],enumerable:!0})};var p=(s,n,e)=>_a(s,typeof n!="symbol"?n+"":n,e);var xs={};La(xs,{AnimatedSprite:()=>Oe,Atlas:()=>ht,AvatarPainter:()=>Et,AvatarsNode:()=>Tn,BitmapFont:()=>Qt,DEFAULT_FONT:()=>Hr,EASE:()=>ct,Group:()=>Tt,HALO:()=>Rt,MAX_LAYERS:()=>pn,NameTags:()=>dt,Node:()=>Ie,NodePool:()=>En,Particles:()=>Ht,STAGE_HEIGHT:()=>he,Shape:()=>Xe,ShelfPacker:()=>yn,Sound:()=>Jt,Sprite:()=>Re,TIERS:()=>Ke,Text:()=>Ye,Timeline:()=>en,Tweens:()=>tn,avatarPortrait:()=>Uo,blur:()=>ka,brightness:()=>fa,colorMatrix:()=>ga,contrast:()=>pa,createAvatarRenderer:()=>Go,createEngine:()=>oa,createRenderer:()=>qt,dropShadow:()=>wa,grayscale:()=>ma,handsOf:()=>sr,hits:()=>Sn,hueRotate:()=>ya,invert:()=>xa,nodePool:()=>Ta,packColor:()=>lt,parseBMFont:()=>Zt,parseColor:()=>me,pickTier:()=>ir,playerColor:()=>An,rendererOrder:()=>zr,rng:()=>eo,saturate:()=>da,sepia:()=>ba,shader:()=>va,shapeBounds:()=>nr,tier:()=>at,tint:()=>ha,touching:()=>or,wrists:()=>Vr});var gr=33,Y={nose:0,leftShoulder:11,rightShoulder:12,leftElbow:13,rightElbow:14,leftWrist:15,rightWrist:16,leftHip:23,rightHip:24,leftKnee:25,rightKnee:26,leftAnkle:27,rightAnkle:28},Es=["3-5","6-8","9-12"],Ia=s=>Es.includes(s);var Oa=4,on=["#EE6A43","#6FA0E0","#8CC9A0","#C49BE0"];var Rs={"3-5":["bunny","bear","panda","penguin"],"6-8":["fox","lion","dragon","unicorn"],"9-12":["robot","astronaut","ninja","skater"]},Na=Rs["6-8"],kr=(s,n)=>{let e=Ia(n)?Rs[n]:Na;return e[Number.isInteger(s)&&s>=0?s%e.length:0]};var Cs=(s,n)=>s?{x:s.x+n.x*s.w,y:s.y+n.y*s.h}:{x:n.x,y:n.y};var gl=16/9;var Ba=12,Da=gr*4,za=s=>Ba+s*Da,kl=za(Oa);var Ha=s=>s.startsWith("fabi-play.")?`fablee-play.${s.slice(10)}`:null;function Fs(s,n,e=Ha(n)){if(!(!s||!e))try{let t=s.getItem(e);if(t===null)return;s.getItem(n)===null&&s.setItem(n,t),s.removeItem(e)}catch{}}var Me="#4a382c",ce="#2b2118",Le="#1c1f2b",Ps="#fbefe3",$e="#f4897a",an="#3a2a22",wr=[{id:"fox",name:{en:"Fox",it:"Volpe"},band:"6-8",palette:{body:"#ee6a43",limbs:"#ee6a43",belly:Ps,accent:"#ffd9c2",outline:ce,hands:"#5a3426",feet:"#5a3426"},head:"wide",ears:"pointy",face:{eyes:"dot",mouth:"cat",nose:an,muzzle:"cheeks"},tail:"fluffy",headExtras:[],bodyExtras:[]},{id:"mascot",name:{en:"Fabi",it:"Fabi"},band:"all",special:!0,palette:{body:"#ee6a43",limbs:"#ee6a43",belly:Ps,accent:"#5a3426",outline:ce,hands:"#5a3426",feet:"#5a3426"},head:"wide",ears:"pointy",face:{eyes:"bead",mouth:"open",nose:an,muzzle:"band",cheeks:$e},tail:"brush",headExtras:[],bodyExtras:["star"],extraColors:["#ffd84a"]},{id:"bunny",name:{en:"Bunny",it:"Coniglietto"},band:"3-5",palette:{body:"#f9d0de",limbs:"#f9d0de",belly:"#fff6f8",accent:"#f4a0b9",outline:Me},head:"round",ears:"long",face:{eyes:"dot",mouth:"cat",nose:"#e0607e",muzzle:"none",cheeks:$e},tail:"pom",headExtras:[],bodyExtras:[]},{id:"bear",name:{en:"Bear",it:"Orsetto"},band:"3-5",palette:{body:"#cf9f78",limbs:"#cf9f78",belly:"#f7e0bf",accent:"#f7e0bf",outline:Me},head:"round",ears:"round",face:{eyes:"dot",mouth:"smile",nose:an,muzzle:"oval",cheeks:$e},tail:"none",headExtras:[],bodyExtras:[]},{id:"cat",name:{en:"Cat",it:"Gattino"},band:"3-5",palette:{body:"#c8b6ee",limbs:"#c8b6ee",belly:"#f4eeff",accent:"#f7b3c8",outline:Me,hands:"#f4eeff",feet:"#f4eeff"},head:"wide",ears:"pointy",face:{eyes:"big",eyeColor:"#3f9a5a",mouth:"cat",nose:"#f07a9a",muzzle:"none",cheeks:$e},tail:"long",headExtras:["whiskers"],bodyExtras:[]},{id:"panda",name:{en:"Panda",it:"Panda"},band:"3-5",palette:{body:"#ffffff",limbs:"#6e6674",belly:"#ffffff",accent:"#6e6674",outline:Me,ears:"#6e6674"},head:"wide",ears:"round",face:{eyes:"mask",mouth:"smile",nose:"#2f2a2c",muzzle:"none",cheeks:"#f6a3a3"},tail:"none",headExtras:[],bodyExtras:[]},{id:"penguin",name:{en:"Penguin",it:"Pinguino"},band:"3-5",palette:{body:"#6c8fca",limbs:"#6c8fca",belly:"#ffffff",accent:"#f9b95c",outline:Me,feet:"#f9b95c"},head:"tall",ears:"none",face:{eyes:"dot",mouth:"beak",muzzle:"heart",cheeks:"#f6a3a3"},tail:"none",headExtras:[],bodyExtras:["flippers","scarf"],extraColors:["#f6907a"]},{id:"frog",name:{en:"Frog",it:"Ranocchio"},band:"3-5",palette:{body:"#8fd487",limbs:"#8fd487",belly:"#e6f7cc",accent:"#62ad62",outline:Me},head:"wide",ears:"none",face:{eyes:"big",eyesOnTop:!0,mouth:"open",muzzle:"none",cheeks:"#f59b8f"},tail:"none",headExtras:[],bodyExtras:["flippers","spots"],extraColors:["#62ad62","#b0e6a4"]},{id:"lion",name:{en:"Lion",it:"Leoncino"},band:"6-8",alsoIn:["3-5"],palette:{body:"#f6c454",limbs:"#f6c454",belly:"#fde7b0",accent:"#fde7b0",outline:ce},head:"round",ears:"round",face:{eyes:"dot",mouth:"cat",nose:"#8a4b2a",muzzle:"oval",cheeks:$e},tail:"tuft",headExtras:["mane"],bodyExtras:[],extraColors:["#c8692e"]},{id:"unicorn",name:{en:"Unicorn",it:"Unicorno"},band:"6-8",palette:{body:"#fbf5ff",limbs:"#fbf5ff",belly:"#efe0ff",accent:"#fbd46a",outline:ce,hands:"#c9a6f2",feet:"#c9a6f2"},head:"tall",ears:"unicorn",face:{eyes:"dot",mouth:"smile",muzzle:"none",cheeks:"#f7a6c8"},tail:"none",headExtras:["rainbow-mane"],bodyExtras:[],extraColors:["#f58cc0","#8fd3f4","#a98ff2"]},{id:"dragon",name:{en:"Little Dragon",it:"Draghetto"},band:"6-8",palette:{body:"#8a63d2",limbs:"#8a63d2",belly:"#fbd46a",accent:"#5fd0b5",outline:ce},head:"wide",ears:"horns",face:{eyes:"big",eyeColor:"#3a2a6a",mouth:"teeth",muzzle:"none",cheeks:"#f59bc0"},tail:"arrow",headExtras:[],bodyExtras:["wings"]},{id:"robot",name:{en:"Robot",it:"Robot"},band:"9-12",palette:{body:"#b9c7d2",limbs:"#8b9aa6",belly:"#b9c7d2",accent:"#ee6a43",outline:Le,hands:"#ee6a43",feet:"#6b7a86"},head:"square",ears:"antenna",face:{eyes:"screen",eyeColor:"#7ff0ff",mouth:"grill",muzzle:"none"},tail:"none",headExtras:["bolts"],bodyExtras:["panel","joints","boots"],extraColors:["#ff7a6b","#fbd46a","#7ff0ff"]},{id:"astronaut",name:{en:"Astronaut",it:"Astronauta"},band:"9-12",palette:{body:"#f4f1ec",limbs:"#f4f1ec",belly:"#f4f1ec",accent:"#ee6a43",outline:Le,hands:"#9fb0bd",feet:"#9fb0bd"},head:"round",ears:"none",face:{eyes:"visor",mouth:"smile",muzzle:"none"},tail:"none",headExtras:["helmet"],bodyExtras:["backpack","badge","boots"],extraColors:["#c9d3db"]},{id:"dinosaur",name:{en:"Dinosaur",it:"Dinosauro"},band:"6-8",palette:{body:"#3fb3a6",limbs:"#3fb3a6",belly:"#c9f0d6",accent:"#f79a3e",outline:ce},head:"wide",ears:"none",face:{eyes:"dot",mouth:"teeth",muzzle:"none",cheeks:"#f59b8f"},tail:"spiky",headExtras:["spikes","spots"],bodyExtras:[],extraColors:["#2b8f84","#7fd3c6"]},{id:"monkey",name:{en:"Monkey",it:"Scimmietta"},band:"6-8",palette:{body:"#7b5234",limbs:"#7b5234",belly:"#f2c9a0",accent:"#f2c9a0",outline:ce,hands:"#f2c9a0",feet:"#f2c9a0"},head:"round",ears:"side",face:{eyes:"dot",mouth:"open",nose:"#5a3a26",muzzle:"monkey",cheeks:$e},tail:"curl",headExtras:["tuft"],bodyExtras:[]},{id:"koala",name:{en:"Koala",it:"Koala"},band:"3-5",palette:{body:"#b7bcc6",limbs:"#b7bcc6",belly:"#eef0f3",accent:"#f4dbe2",outline:Me},head:"wide",ears:"big-round",face:{eyes:"dot",mouth:"smile",nose:"#3b3438",muzzle:"none",cheeks:"#f4a3b0"},tail:"none",headExtras:[],bodyExtras:[]},{id:"tiger",name:{en:"Tiger",it:"Tigrotto"},band:"6-8",palette:{body:"#f9a33a",limbs:"#f9a33a",belly:"#fff1dc",accent:"#fff1dc",outline:ce},head:"wide",ears:"round",face:{eyes:"dot",mouth:"cat",nose:"#e2607a",muzzle:"oval",cheeks:$e},tail:"striped",headExtras:["stripes","whiskers"],bodyExtras:[],extraColors:["#3a2a22"]},{id:"owl",name:{en:"Owl",it:"Gufetto"},band:"3-5",palette:{body:"#8ec0e6",limbs:"#8ec0e6",belly:"#e3f2fc",accent:"#639cc9",outline:Me,feet:"#f9b95c",hands:"#639cc9"},head:"tall",ears:"tufts",face:{eyes:"big",eyeColor:Me,eyeRing:"#fde08a",mouth:"beak",muzzle:"none",cheeks:"#f6a8b4"},tail:"none",headExtras:[],bodyExtras:["feathers"]},{id:"alien",name:{en:"Alien",it:"Alieno"},band:"9-12",palette:{body:"#9ee05a",limbs:"#9ee05a",belly:"#d8f5a8",accent:"#b07cf2",outline:Le},head:"bulb",ears:"antennae",face:{eyes:"almond",eyeColor:"#1e1838",mouth:"smirk",muzzle:"none"},tail:"none",headExtras:[],bodyExtras:["spots"],extraColors:["#7cc23e","#7cc23e"]},{id:"ghost",name:{en:"Friendly Ghost",it:"Fantasmino"},band:"6-8",palette:{body:"#e6f4ff",limbs:"#e6f4ff",belly:"#e6f4ff",accent:"#bcd9f2",outline:ce},head:"round",ears:"none",face:{eyes:"dot",mouth:"open",muzzle:"none",cheeks:"#f7a6c8"},tail:"none",headExtras:["curl"],bodyExtras:["sheet"]},{id:"octopus",name:{en:"Octopus",it:"Polpetto"},band:"6-8",palette:{body:"#e0578a",limbs:"#e0578a",belly:"#f7b3cc",accent:"#f7b3cc",outline:ce,hands:"#f7b3cc",feet:"#f7b3cc"},head:"tall",ears:"none",face:{eyes:"big",eyeColor:"#3a2140",mouth:"smile",muzzle:"none",cheeks:"#ffd0a0"},tail:"none",headExtras:["spots"],bodyExtras:["tentacles"],extraColors:["#f7b3cc","#f7b3cc"]},{id:"chick",name:{en:"Chick",it:"Pulcino"},band:"3-5",palette:{body:"#ffd45e",limbs:"#ffd45e",belly:"#fff2c2",accent:"#ffa04a",outline:Me,hands:"#ffc23d",feet:"#ffa04a"},head:"round",ears:"none",face:{eyes:"dot",mouth:"beak",muzzle:"none",cheeks:$e},tail:"none",headExtras:["eggshell"],bodyExtras:[],extraColors:["#fffaf0"]},{id:"puppy",name:{en:"Puppy",it:"Cucciolo"},band:"3-5",palette:{body:"#f4e4cf",limbs:"#f4e4cf",belly:"#fffaf2",accent:"#f29aa4",outline:Me,ears:"#b58262",hands:"#e6caa6",feet:"#e6caa6"},head:"wide",ears:"floppy",face:{eyes:"dot",mouth:"open",nose:an,muzzle:"oval",cheeks:$e},tail:"curl",headExtras:["eye-spot"],bodyExtras:[]},{id:"lamb",name:{en:"Lamb",it:"Agnellino"},band:"3-5",palette:{body:"#fdf8ee",limbs:"#e3d1c2",belly:"#fffdf8",accent:"#f6bcc2",outline:Me,skin:"#f7dccb",hands:"#a58c7e",feet:"#a58c7e"},head:"round",ears:"droopy",face:{eyes:"dot",mouth:"smile",nose:"#e591a0",muzzle:"none",cheeks:$e},tail:"pom",headExtras:["wool"],bodyExtras:["wool"]},{id:"duckling",name:{en:"Duckling",it:"Anatroccolo"},band:"3-5",palette:{body:"#fff1a6",limbs:"#fff1a6",belly:"#fffbe0",accent:"#ff9f43",outline:Me,feet:"#ff9f43"},head:"tall",ears:"none",face:{eyes:"dot",mouth:"bill",muzzle:"none",cheeks:$e},tail:"none",headExtras:["curl"],bodyExtras:["flippers","scarf"],extraColors:["#86cfe0"]},{id:"shark",name:{en:"Shark",it:"Squalo"},band:"6-8",palette:{body:"#6c95c4",limbs:"#6c95c4",belly:"#eef5fb",accent:"#4c76a8",outline:ce,hands:"#eef5fb",feet:"#4c76a8"},head:"wide",ears:"fin",face:{eyes:"dot",mouth:"jaws",muzzle:"none",cheeks:"#f59bb0"},tail:"fish",headExtras:["gills"],bodyExtras:[]},{id:"wolf",name:{en:"Wolf",it:"Lupo"},band:"6-8",palette:{body:"#8f9bb3",limbs:"#8f9bb3",belly:"#eef1f6",accent:"#f3b8c4",outline:ce,hands:"#5a647a",feet:"#5a647a"},head:"round",ears:"pointy",face:{eyes:"dot",mouth:"open",nose:an,muzzle:"oval",cheeks:"#f4a3b0"},tail:"fluffy",headExtras:["ruff","forehead"],bodyExtras:[],extraColors:["#636d84"]},{id:"parrot",name:{en:"Parrot",it:"Pappagallo"},band:"6-8",palette:{body:"#e8503f",limbs:"#e8503f",belly:"#ffd25a",accent:"#f6e6c4",outline:ce,hands:"#3a9bdc",feet:"#8a7a70"},head:"round",ears:"none",face:{eyes:"big",eyeColor:ce,eyeRing:"#ffffff",mouth:"hook",muzzle:"none",cheeks:"#ffb0a0"},tail:"plume",headExtras:["crest"],bodyExtras:["feathers"],extraColors:["#ffd25a","#3fae5a","#3a9bdc"]},{id:"ninja",name:{en:"Ninja",it:"Ninja"},band:"9-12",palette:{body:"#2f3a56",limbs:"#2f3a56",belly:"#2f3a56",accent:"#36c9bb",outline:Le,skin:"#b07a52",hands:"#222a40",feet:"#222a40"},head:"round",ears:"none",face:{eyes:"calm",mouth:"none",muzzle:"none",brows:"#2a1d16"},tail:"none",headExtras:["ninja-hood"],bodyExtras:["belt"],extraColors:["#36c9bb","#36c9bb","#36c9bb"]},{id:"skater",name:{en:"Skater",it:"Skater"},band:"9-12",palette:{body:"#3a8fc0",limbs:"#2c3e57",belly:"#2f7aa6",accent:"#ffcf3a",outline:Le,skin:"#f2c9a5",hair:"#7a4a2a",hands:"#f2c9a5",feet:"#eef1f5"},head:"round",ears:"human",face:{eyes:"calm",mouth:"smirk",muzzle:"none",brows:"#5a3520"},tail:"none",headExtras:["hair","cap"],bodyExtras:["pocket","joints"],extraColors:["#ff5d73"]},{id:"explorer",name:{en:"Explorer",it:"Giramondo"},band:"9-12",palette:{body:"#5f8f5b",limbs:"#5f8f5b",belly:"#5f8f5b",accent:"#d9bb7e",outline:Le,skin:"#7a4a30",hair:"#1d1410",hands:"#7a4a30",feet:"#6b4a2a"},head:"round",ears:"human",face:{eyes:"calm",mouth:"smile",muzzle:"none",brows:"#1d1410"},tail:"none",headExtras:["curls","safari-hat"],bodyExtras:["backpack","straps","boots"],extraColors:["#e07b39","#6b4a2a"]},{id:"wizard",name:{en:"Wizard",it:"Mago"},band:"9-12",palette:{body:"#5b3fa0",limbs:"#5b3fa0",belly:"#5b3fa0",accent:"#3d5fc8",outline:Le,skin:"#c98d62",hair:"#a8452a",hands:"#c98d62",feet:"#33255e"},head:"round",ears:"human",face:{eyes:"calm",mouth:"smile",muzzle:"none",brows:"#7a301c"},tail:"none",headExtras:["locks","wizard-hat"],bodyExtras:["robe","belt"],extraColors:["#ffd84a","#ffd84a","#ffd84a"]},{id:"knight",name:{en:"Knight",it:"Cavaliere"},band:"9-12",palette:{body:"#bcc7d3",limbs:"#8e9aa8",belly:"#dce3ea",accent:"#d8443a",outline:Le,hands:"#6c7786",feet:"#6c7786"},head:"bucket",ears:"none",face:{eyes:"slit",eyeColor:"#bfefff",mouth:"none",muzzle:"none"},tail:"none",headExtras:["plume"],bodyExtras:["pauldrons","emblem","boots"],extraColors:["#d8443a"]},{id:"racer",name:{en:"Racer",it:"Pilota"},band:"9-12",palette:{body:"#ff6a2b",limbs:"#ff6a2b",belly:"#ffffff",accent:"#ffffff",outline:Le,hands:"#232838",feet:"#232838"},head:"round",ears:"none",face:{eyes:"goggle",eyeColor:"#7fd6ff",mouth:"none",muzzle:"none"},tail:"none",headExtras:["stripe"],bodyExtras:["racing-stripe","boots"]},{id:"pirate",name:{en:"Pirate",it:"Pirata"},band:"9-12",palette:{body:"#f2efe6",limbs:"#2a3d6e",belly:"#f2efe6",accent:"#d94545",outline:Le,skin:"#d9a072",hair:"#2b1a12",hands:"#d9a072",feet:"#3a2a20"},head:"round",ears:"human",face:{eyes:"calm",mouth:"smirk",muzzle:"none",brows:"#2b1a12"},tail:"none",headExtras:["locks","bandana","eye-patch"],bodyExtras:["stripes","belt","boots"],extraColors:["#d94545","#2a3d6e","#4a3426"]},{id:"diver",name:{en:"Diver",it:"Sub"},band:"9-12",palette:{body:"#1f6582",limbs:"#1f6582",belly:"#1f6582",accent:"#ffb020",outline:Le,skin:"#e8b48a",hair:"#c98f2e",hands:"#1b4f66",feet:"#ffb020"},head:"round",ears:"human",face:{eyes:"calm",mouth:"smile",muzzle:"none",brows:"#8a5a1a"},tail:"none",headExtras:["curls","dive-mask"],bodyExtras:["tank","fins"],extraColors:["#c9d3db"]},{id:"hero",name:{en:"Hero",it:"Supereroe"},band:"9-12",palette:{body:"#3557c8",limbs:"#3557c8",belly:"#3557c8",accent:"#e0403a",outline:Le,skin:"#5a3825",hair:"#141010",hands:"#e0403a",feet:"#e0403a"},head:"round",ears:"human",face:{eyes:"calm",mouth:"smirk",muzzle:"none",brows:"#141010"},tail:"none",headExtras:["hair","domino"],bodyExtras:["cape","emblem","boots"],extraColors:["#ffd84a"]},{id:"trex",name:{en:"T-Rex",it:"T-Rex"},band:"6-8",alsoIn:["3-5"],palette:{body:"#6cb84e",limbs:"#6cb84e",belly:"#f4e8a8",accent:"#f4e8a8",outline:ce},head:"snout-long",ears:"none",face:{eyes:"dot",mouth:"toothy",muzzle:"none",cheeks:"#f59b8f"},tail:"thick",headExtras:["stripes"],bodyExtras:["tiny-arms","strong-legs"],extraColors:["#4a9235","#58a23f"]},{id:"fairy",name:{en:"Fairy",it:"Fatina"},band:"6-8",alsoIn:["3-5"],palette:{body:"#b99af0",limbs:"#a8693f",belly:"#b99af0",accent:"#ffd84a",outline:ce,skin:"#a8693f",hair:"#2e1d17",hands:"#a8693f",feet:"#f58cbc"},head:"round",ears:"pixie",face:{eyes:"dot",mouth:"smile",muzzle:"none",cheeks:"#f0857a"},tail:"none",headExtras:["bun","flower-crown"],bodyExtras:["wings-fairy","petals","wand"],extraColors:["#c4ecff","#f7a8cf","#fff3a0","#ffffff"]}];var re={M:0,L:1,Q:2,C:3,Z:4},_s=[2,2,4,6,0];function Lt(s,n){for(let e of n)$a(s,e)}function $a(s,n){if(n.k==="group"){s.save(),s.translate(n.x,n.y),n.rot&&s.rotate(n.rot),n.s!==void 0&&n.s!==1&&s.scale(n.s,n.s),n.alpha!==void 0&&(s.globalAlpha*=n.alpha),Lt(s,n.items),s.restore();return}switch(s.save(),n.alpha!==void 0&&(s.globalAlpha*=n.alpha),s.beginPath(),n.k){case"circle":s.arc(n.x,n.y,Math.max(n.r,0),0,Math.PI*2);break;case"ellipse":s.ellipse(n.x,n.y,Math.max(n.rx,0),Math.max(n.ry,0),n.rot??0,0,Math.PI*2);break;case"rect":Ga(s,n);break;case"path":typeof n.d=="string"?Va(s,n.d):Ua(s,n.d);break;case"line":s.moveTo(n.pts[0]??0,n.pts[1]??0);for(let e=2;e+1<n.pts.length;e+=2)s.lineTo(n.pts[e],n.pts[e+1]);break}s.lineCap="round",s.lineJoin="round",n.fill&&n.k!=="line"&&(s.fillStyle=n.fill,s.fill()),n.stroke&&(n.lw??1)>0&&(s.strokeStyle=n.stroke,s.lineWidth=n.lw??1,s.stroke()),s.restore()}function Ga(s,n){let e=Math.max(0,Math.min(n.r,n.w/2,n.h/2));s.translate(n.x,n.y),n.rot&&s.rotate(n.rot);let t=-n.w/2,r=-n.h/2;s.moveTo(t+e,r),s.lineTo(t+n.w-e,r),s.quadraticCurveTo(t+n.w,r,t+n.w,r+e),s.lineTo(t+n.w,r+n.h-e),s.quadraticCurveTo(t+n.w,r+n.h,t+n.w-e,r+n.h),s.lineTo(t+e,r+n.h),s.quadraticCurveTo(t,r+n.h,t,r+n.h-e),s.lineTo(t,r+e),s.quadraticCurveTo(t,r,t+e,r),s.closePath()}function Ua(s,n){for(let e=0;e<n.length;){let t=n[e++];if(t===re.M)s.moveTo(n[e],n[e+1]);else if(t===re.L)s.lineTo(n[e],n[e+1]);else if(t===re.Q)s.quadraticCurveTo(n[e],n[e+1],n[e+2],n[e+3]);else if(t===re.C)s.bezierCurveTo(n[e],n[e+1],n[e+2],n[e+3],n[e+4],n[e+5]);else if(t===re.Z)s.closePath();else return;e+=_s[t]}}function vr(s){if(typeof s=="string")return(s.match(/-?\d*\.?\d+(?:e-?\d+)?/gi)??[]).map(Number);let n=[];for(let e=0;e<s.length;){let t=_s[s[e++]];if(t===void 0)break;for(let r=0;r<t;r++)n.push(s[e+r]);e+=t}return n}function Va(s,n){let e=n.match(/[MLQCZ]|-?\d*\.?\d+(?:e-?\d+)?/gi)??[],t="",r=0,o=()=>Number(e[r++]);for(;r<e.length;){let a=e[r];if(/[MLQCZ]/i.test(a)&&(t=a.toUpperCase(),r++,t==="Z")){s.closePath();continue}t==="M"?(s.moveTo(o(),o()),t="L"):t==="L"?s.lineTo(o(),o()):t==="Q"?s.quadraticCurveTo(o(),o(),o(),o()):t==="C"?s.bezierCurveTo(o(),o(),o(),o(),o(),o()):r++}}var J=s=>{let n=Math.round(s*100)/100;return n===0?0:n};function Q(s,n=.5){let e=s.length;if(e<3)return[];let t=(i,l,c)=>({x:i.x+(l.x-i.x)*c,y:i.y+(l.y-i.y)*c}),r=Math.min(Math.max(n,0),.5),o=t(s[0],s[1],r),a=[re.M,J(o.x),J(o.y)];for(let i=1;i<=e;i++){let l=s[(i-1)%e],c=s[i%e],u=s[(i+1)%e],f=t(l,c,1-r),h=t(c,u,r);a.push(re.L,J(f.x),J(f.y),re.Q,J(c.x),J(c.y),J(h.x),J(h.y))}return a.push(re.Z),a}function K(s,n=1){let e=s.length;if(e<3)return[];let t=[re.M,J(s[0].x),J(s[0].y)],r=n/6;for(let o=0;o<e;o++){let a=s[(o-1+e)%e],i=s[o],l=s[(o+1)%e],c=s[(o+2)%e];t.push(re.C,J(i.x+(l.x-a.x)*r),J(i.y+(l.y-a.y)*r),J(l.x-(c.x-i.x)*r),J(l.y-(c.y-i.y)*r),J(l.x),J(l.y))}return t.push(re.Z),t}function It(s){let n=s.length;if(n<2)return[];let e=[re.M,J(s[0].x),J(s[0].y)];for(let t=0;t<n-1;t++){let r=s[Math.max(t-1,0)],o=s[t],a=s[t+1],i=s[Math.min(t+2,n-1)];e.push(re.C,J(o.x+(a.x-r.x)/6),J(o.y+(a.y-r.y)/6),J(a.x-(i.x-o.x)/6),J(a.y-(i.y-o.y)/6),J(a.x),J(a.y))}return e}var et="M0 -1 L0.29 -0.4 L0.95 -0.31 L0.47 0.15 L0.59 0.81 L0 0.5 L-0.59 0.81 L-0.47 0.15 L-0.95 -0.31 L-0.29 -0.4 Z";var ae="#ffffff",j=[-1,1],Ls="#3a2420",Is="#f2808f",Ar="#26324a",Wa="#ffd84a",se=(...s)=>{let n=[];for(let e=0;e+1<s.length;e+=2)n.push({x:s[e],y:s[e+1]});return n};function Nn(s,n){let e=s.palette,t=[],r={stroke:e.outline,lw:n},o=u=>s.headExtras.includes(u),a=(u,f)=>s.extraColors?.[u]??f;if(o("mane")){for(let f=0;f<12;f++){let h=f/12*Math.PI*2;t.push({k:"circle",x:Math.cos(h)*1.02,y:Math.sin(h)*1+.04,r:.42,fill:a(0,e.accent),...r})}t.push({k:"circle",x:0,y:.04,r:1.08,fill:a(0,e.accent)})}if(o("rainbow-mane")){let u=s.extraColors??["#f59ac0","#fbd46a","#8fd3f4"];[[.98,.05,.3,.5,-.25],[.92,.58,.26,.42,-.1],[.62,.92,.22,.32,.4]].forEach(([h,b,y,m,d],x)=>t.push({k:"ellipse",x:h,y:b,rx:y,ry:m,rot:d,fill:u[x%u.length],...r}))}if(o("spikes"))for(let u of[-.55,0,.55]){let f=kt(u,1.48),h=kt(u-.32,.86),b=kt(u+.32,.86);t.push({k:"path",d:Q([h,f,b],.22),fill:e.accent,...r})}if(o("curl")&&t.push({k:"path",d:K([{x:-.2,y:-.9},{x:-.05,y:-1.3},{x:.32,y:-1.42},{x:.16,y:-1.18},{x:.2,y:-.9}]),fill:e.body,...r}),o("wool"))for(let u=0;u<=8;u++){let f=-1.75+u/8*3.5;t.push({k:"circle",x:Math.sin(f)*.98,y:-Math.cos(f)*.92-.04,r:.34,fill:e.body,...r})}if(o("crest")&&[-.38,0,.38].forEach((u,f)=>{let h=kt(u,1.12);t.push({k:"ellipse",x:h.x,y:h.y,rx:.15,ry:.42,rot:u,fill:a(f,e.accent),...r})}),o("plume")&&t.push({k:"path",d:K(se(-.12,-.92,-.2,-1.42,.1,-1.78,.62,-1.74,.36,-1.46,.16,-.98)),fill:e.accent,...r}),o("locks")&&t.push({k:"path",d:K(se(-1.14,.58,-1.24,-.2,-.86,-.98,0,-1.2,.86,-.98,1.24,-.2,1.14,.58,.8,.66,0,.2,-.8,.66)),fill:e.hair??e.outline,...r}),o("bun")&&t.push({k:"circle",x:.04,y:-1.14,r:.4,fill:e.hair??e.outline,...r}),o("ninja-hood"))for(let[u,f]of[[.35,.5],[.85,.42]])t.push({k:"ellipse",x:1+Math.cos(u)*f*.8,y:-.5+Math.sin(u)*f*.8,rx:f,ry:.11,rot:u,fill:e.accent,...r});if(o("bandana"))for(let[u,f]of[[Math.PI-.5,.42],[Math.PI-1,.36]])t.push({k:"ellipse",x:-.98+Math.cos(u)*f*.8,y:-.36+Math.sin(u)*f*.8,rx:f,ry:.12,rot:u,fill:e.accent,...r});if(o("ruff"))for(let u of j)t.push({k:"path",d:Q(se(u*.7,-.3,u*1.32,0,u*1.02,.18,u*1.26,.46,u*.86,.56,u*.98,.84,u*.4,.7),.25),fill:e.body,...r});if(s.face.eyesOnTop)for(let u of j)t.push({k:"circle",x:u*.46,y:-.72,r:.38,fill:e.body,...r});t.push(...Qa(s,n)),t.push(Xa(s,r));let i=s.face.muzzle,l=e.belly;if(i==="oval"&&t.push({k:"ellipse",x:0,y:.4,rx:.46,ry:.32,fill:l}),i==="monkey"){for(let u of j)t.push({k:"circle",x:u*.32,y:-.04,r:.38,fill:l});t.push({k:"ellipse",x:0,y:.4,rx:.56,ry:.4,fill:l})}if(i==="heart"){for(let u of j)t.push({k:"circle",x:u*.36,y:.02,r:.5,fill:l});t.push({k:"ellipse",x:0,y:.38,rx:.66,ry:.48,fill:l})}if(i==="disc")for(let u of j)t.push({k:"circle",x:u*.4,y:.02,r:.44,fill:l});if(i==="cheeks")for(let u of j)t.push({k:"ellipse",x:u*.4,y:.44,rx:.44,ry:.32,fill:l});if(i==="band"&&t.push({k:"path",d:Ka(s,n),fill:l}),o("stripes")&&s.head==="snout-long"){let u=a(0,e.outline);for(let[f,h,b,y]of[[.46,-.94,.36,-.66],[.8,-.72,.62,-.5],[1,-.36,.78,-.24]])t.push({k:"line",pts:[f,h,b,y],stroke:u,lw:.11})}else if(o("stripes")){let u=a(0,e.outline);t.push({k:"line",pts:[0,-.97,0,-.66],stroke:u,lw:.13});for(let f of j)t.push({k:"line",pts:[f*.3,-.93,f*.24,-.7],stroke:u,lw:.1}),t.push({k:"line",pts:[f*.98,-.05,f*.74,0],stroke:u,lw:.1}),t.push({k:"line",pts:[f*.94,.22,f*.74,.22],stroke:u,lw:.09})}if(o("spots")){let u=a(1,e.belly);t.push({k:"circle",x:-.55,y:-.5,r:.15,fill:u}),t.push({k:"circle",x:.58,y:-.42,r:.11,fill:u}),t.push({k:"circle",x:.22,y:-.76,r:.09,fill:u})}if(s.head==="snout-long")for(let[u,f,h]of[[-1.38,-.14,.06],[-1.14,-.22,.055]])t.push({k:"ellipse",x:u,y:f,rx:h,ry:h*.8,rot:-.3,fill:e.outline,alpha:.85});if(o("forehead")&&t.push({k:"path",d:K(se(-.62,-.66,0,-.86,.62,-.66,.26,-.36,0,-.1,-.26,-.36),.9),fill:a(0,e.accent)}),o("eye-spot")&&t.push({k:"ellipse",x:.42,y:-.06,rx:.3,ry:.33,rot:.3,fill:e.ears??e.accent}),o("gills"))for(let u of j)for(let f of[0,.12,.24])t.push({k:"path",d:`M${u*(.66+f)} 0.06 Q${u*(.6+f)} 0.22 ${u*(.66+f)} 0.38`,stroke:e.accent,lw:n*.9});let c=e.hair??e.outline;if(o("hair")&&t.push({k:"path",d:K(se(-1.02,-.06,-1.02,-.58,-.62,-1.04,.08,-1.14,.76,-.92,1.05,-.42,1,-.06,.84,-.4,.42,-.5,.06,-.4,-.34,-.56,-.74,-.38)),fill:c,...r}),o("locks")&&t.push({k:"path",d:K(se(-1,-.08,-.98,-.62,-.56,-1.02,0,-1.1,.56,-1.02,.98,-.62,1,-.08,.8,-.38,.36,-.44,0,-.4,-.36,-.44,-.8,-.38)),fill:c,...r}),o("bun")&&t.push({k:"path",d:K(se(-1.02,-.1,-.98,-.62,-.56,-1.02,0,-1.1,.56,-1.02,.98,-.62,1.02,-.1,.84,-.36,.5,-.56,.12,-.48,-.22,-.6,-.6,-.5,-.86,-.36)),fill:c,...r}),o("curls")){for(let u=0;u<7;u++){let f=kt(-1.3+u/6*2.6,.86);t.push({k:"circle",x:f.x,y:f.y,r:.3,fill:c,...r})}t.push({k:"ellipse",x:0,y:-.64,rx:.8,ry:.36,fill:c})}if(o("ninja-hood")&&(t.push({k:"rect",x:0,y:0,w:1.56,h:.6,r:.28,fill:e.skin??ae,stroke:e.outline,lw:n*.8}),t.push({k:"path",d:"M-0.98 -0.42 Q0 -0.74 0.98 -0.42 L1.0 -0.62 Q0 -0.94 -1.0 -0.62 Z",fill:e.accent,...r})),o("domino")){t.push({k:"path",d:K(se(-.86,-.04,-.62,-.3,-.18,-.24,0,-.16,.18,-.24,.62,-.3,.86,-.04,.6,.22,.16,.16,0,.1,-.16,.16,-.6,.22),.9),fill:e.accent,...r});for(let u of j)t.push({k:"ellipse",x:u*.38,y:0,rx:.19,ry:.13,fill:ae})}if(t.push(...Za(s,n)),o("brows"))for(let u of j)t.push({k:"line",pts:[u*.72,-.5,u*.14,-.3],stroke:e.accent,lw:.16});if(s.face.brows)for(let u of j)t.push({k:"line",pts:[u*.2,-.2,u*.54,-.28],stroke:s.face.brows,lw:.09});if(t.push(...Ja(s,n)),s.face.cheeks)for(let u of qa(s))t.push({k:"ellipse",x:u.x,y:u.y,rx:.15,ry:.1,fill:s.face.cheeks,alpha:.8});if(o("whiskers"))for(let u of j)for(let f of[-.1,.06])t.push({k:"line",pts:[u*.62,.38+f,u*1.06,.3+f*2.2],stroke:e.outline,lw:n*.7,alpha:.75});if(o("rainbow-mane")){let u=s.extraColors??["#f59ac0","#fbd46a","#8fd3f4"];t.push({k:"ellipse",x:.42,y:-.82,rx:.34,ry:.22,rot:.5,fill:u[0],...r}),t.push({k:"ellipse",x:.1,y:-.92,rx:.3,ry:.2,rot:.25,fill:u[1%u.length],...r})}if(s.ears==="unicorn"){let u=[{x:-.18,y:-.84},{x:.02,y:-1.72},{x:.18,y:-.84}];t.push({k:"path",d:Q(u,.12),fill:e.accent,...r});for(let f of[-1,-1.2,-1.4]){let h=.16*((f+1.72)/.88);t.push({k:"line",pts:[-h,f+.04,h,f-.04],stroke:e.outline,lw:n*.7,alpha:.6})}}if(o("flower-crown")){let u=[a(1,"#f7a8cf"),a(2,"#fff3a0"),a(3,ae)];for(let f of[-.84,-.28,.28,.84]){let h=kt(f,.9);t.push({k:"ellipse",x:h.x,y:h.y,rx:.14,ry:.07,rot:f+.5,fill:"#7cc76a",stroke:e.outline,lw:n*.7})}[-1.12,-.56,0,.56,1.12].forEach((f,h)=>{let b=kt(f,.9),y=h===2?.13:.11;for(let m=0;m<5;m++){let d=f+m/5*Math.PI*2;t.push({k:"circle",x:b.x+Math.sin(d)*y,y:b.y-Math.cos(d)*y,r:y*.82,fill:u[h%u.length],stroke:e.outline,lw:n*.7})}t.push({k:"circle",x:b.x,y:b.y,r:y*.62,fill:u[h%u.length]}),t.push({k:"circle",x:b.x,y:b.y,r:y*.42,fill:e.accent})})}if(o("helmet")){for(let u of j)t.push({k:"rect",x:u*1,y:.05,w:.26,h:.56,r:.12,fill:e.accent,...r});t.push({k:"path",d:"M-0.62 -0.62 Q-0.3 -0.92 0.12 -0.9",stroke:ae,lw:.1,alpha:.9})}if(o("bolts"))for(let u of j)t.push({k:"rect",x:u*1.08,y:.08,w:.2,h:.44,r:.08,fill:e.accent,...r});if(o("tuft")&&t.push({k:"path",d:K([{x:-.26,y:-.95},{x:-.12,y:-1.22},{x:.02,y:-1.04},{x:.16,y:-1.28},{x:.28,y:-.95},{x:0,y:-.86}]),fill:e.body,...r}),o("eggshell")&&t.push({k:"path",d:"M-0.88 -0.5 C-0.88 -1.12 -0.46 -1.42 0 -1.42 C0.46 -1.42 0.88 -1.12 0.88 -0.5 L0.66 -0.66 L0.44 -0.48 L0.22 -0.66 L0 -0.48 L-0.22 -0.66 L-0.44 -0.48 L-0.66 -0.66 Z",fill:a(0,ae),...r}),o("wool"))for(let[u,f]of[[-.36,-.84],[.02,-.94],[.4,-.82]])t.push({k:"circle",x:u,y:f,r:.27,fill:e.body,...r});if(o("stripe")&&t.push({k:"rect",x:0,y:-.64,w:.38,h:.62,r:.06,fill:e.accent}),o("eye-patch")&&(t.push({k:"line",pts:[-.97,-.5,.97,.13],stroke:e.outline,lw:.07}),t.push({k:"ellipse",x:.38,y:.02,rx:.21,ry:.19,fill:e.outline})),o("bandana")){t.push({k:"path",d:K(se(-1.05,-.22,-.96,-.72,-.5,-1.08,.1,-1.14,.72,-.96,1.04,-.56,1.05,-.22,.5,-.46,-.5,-.46)),fill:e.accent,...r});for(let[u,f]of[[-.5,-.8],[.08,-.92],[.6,-.74],[-.12,-.62],[.36,-.6]])t.push({k:"circle",x:u,y:f,r:.06,fill:ae,alpha:.85});t.push({k:"circle",x:-.98,y:-.34,r:.15,fill:e.accent,...r})}if(o("cap")){for(let u of j)t.push({k:"line",pts:[u*.98,-.2,u*.5,.82,-u*.05,.98],stroke:e.outline,lw:.06});t.push({k:"path",d:K(se(-1.1,-.16,-1.04,-.66,-.6,-1.12,0,-1.24,.6,-1.12,1.04,-.66,1.1,-.16,.5,-.4,-.5,-.4)),fill:e.accent,...r}),t.push({k:"path",d:"M-0.74 -0.4 Q0 -0.6 0.74 -0.4 Q0.8 -0.24 0.6 -0.22 Q0 -0.36 -0.6 -0.22 Q-0.8 -0.24 -0.74 -0.4 Z",fill:e.accent,...r}),t.push({k:"circle",x:.5,y:-.82,r:.15,fill:a(0,ae),...r});for(let u of[-.42,-.14])t.push({k:"line",pts:[u,-1.04,u+.02,-.78],stroke:e.outline,lw:.07,alpha:.7})}if(o("safari-hat")&&(t.push({k:"ellipse",x:0,y:-.56,rx:1.48,ry:.3,fill:e.accent,...r}),t.push({k:"path",d:K(se(-.78,-.58,-.7,-1.1,-.3,-1.38,.3,-1.38,.7,-1.1,.78,-.58,0,-.5),.8),fill:e.accent,...r}),t.push({k:"path",d:"M-0.77 -0.72 Q0 -0.62 0.77 -0.72 L0.74 -0.9 Q0 -0.8 -0.74 -0.9 Z",fill:a(1,e.outline),stroke:e.outline,lw:n*.8})),o("wizard-hat")){t.push({k:"ellipse",x:0,y:-.62,rx:1.32,ry:.26,fill:e.accent,...r}),t.push({k:"path",d:Q(se(-.8,-.66,-.36,-1.5,.5,-2.2,.3,-1.46,.8,-.66),.3),fill:e.accent,...r});let u=a(0,Wa);for(let[f,h,b]of[[.02,-1.08,.18],[-.38,-.84,.1],[.36,-1.5,.11]])t.push({k:"group",x:f,y:h,s:b,items:[{k:"path",d:et,fill:u}]})}if(o("dive-mask")){for(let f of j)t.push({k:"line",pts:[f*.7,-.04,f*1,-.12],stroke:e.outline,lw:.2},{k:"line",pts:[f*.7,-.04,f*1,-.12],stroke:e.accent,lw:.11});t.push({k:"rect",x:0,y:0,w:1.42,h:.62,r:.28,fill:"#bfe9f5",alpha:.35}),t.push({k:"rect",x:0,y:0,w:1.42,h:.62,r:.28,stroke:e.outline,lw:.2}),t.push({k:"rect",x:0,y:0,w:1.42,h:.62,r:.28,stroke:e.accent,lw:.11}),t.push({k:"path",d:"M-0.5 -0.16 Q-0.4 -0.24 -0.22 -0.24",stroke:ae,lw:.06,alpha:.9});let u="M0.5 0.52 Q0.98 0.56 1.04 0.1 L1.12 -0.92";t.push({k:"path",d:u,stroke:e.outline,lw:.24},{k:"path",d:u,stroke:e.accent,lw:.13})}return t}function Xa(s,n){let e=s.headExtras.includes("ninja-hood")?s.palette.body:s.palette.skin??s.palette.body;switch(s.head){case"round":return{k:"circle",x:0,y:0,r:1,fill:e,...n};case"wide":return{k:"ellipse",x:0,y:.03,rx:1.12,ry:.94,fill:e,...n};case"tall":return{k:"ellipse",x:0,y:-.02,rx:.94,ry:1.04,fill:e,...n};case"square":return{k:"rect",x:0,y:0,w:2,h:1.8,r:.46,fill:e,...n};case"bucket":return{k:"path",d:Q(se(-.94,.96,-.98,-.36,-.62,-1.04,.62,-1.04,.98,-.36,.94,.96),.42),fill:e,...n};case"snout-long":return{k:"path",d:K(ja,.95),fill:e,...n};case"bulb":return{k:"path",d:K([{x:0,y:-1.02},{x:.86,y:-.74},{x:1.08,y:-.12},{x:.72,y:.62},{x:0,y:.92},{x:-.72,y:.62},{x:-1.08,y:-.12},{x:-.86,y:-.74}]),fill:e,...n}}}var ja=se(.7,-.88,.12,-1.04,-.3,-.98,-.72,-.74,-1.2,-.56,-1.5,-.32,-1.6,.04,-1.44,.42,-.9,.72,-.2,.92,.5,.88,.96,.56,1.08,0,.98,-.5);function Os(s,n,e){return s.head==="snout-long"?[{x:-.36,y:-.5,k:.95},{x:.26,y:-.48,k:1.1}]:j.map(t=>({x:t*n,y:e,k:1}))}function qa(s){return s.head==="snout-long"?se(-.66,-.14,.66,.1):j.map(n=>({x:n*.64,y:.3}))}function Ya(s){return s.head==="round"?{cy:0,rx:1,ry:1}:s.head==="tall"?{cy:-.02,rx:.94,ry:1.04}:{cy:.03,rx:1.12,ry:.94}}function Ka(s,n){let{cy:e,rx:t,ry:r}=Ya(s),o=t-n/2,a=r-n/2,i=.15,l=Math.asin(Math.min(1,(i-e)/a)),c=Math.cos(l)*o,u=y=>Math.round(y*100)/100||0,f=[re.M,u(-c),i],h=[[-.84*c,.02,-.53*c,.06,-.32*c,.24],[-.17*c,.11,.17*c,.11,.32*c,.24],[.53*c,.06,.84*c,.02,c,i]];for(let y of h)f.push(re.C,...y.map(u));let b=24;for(let y=1;y<=b;y++){let m=l+(Math.PI-2*l)*y/b;f.push(re.L,u(Math.cos(m)*o),u(e+Math.sin(m)*a))}return f.push(re.Z),f}function Qa(s,n){let e=s.palette,t={stroke:e.outline,lw:n},r=[];for(let o of j)switch(s.ears){case"pointy":case"unicorn":{let a=s.ears==="unicorn"?.8:1,i={x:o*.3,y:-.82},l={x:o*.86,y:-.82-.62*a},c={x:o*.94,y:-.36};r.push({k:"path",d:Q([i,l,c],.2),fill:e.body,...t});let u={x:(i.x+l.x+c.x)/3,y:(i.y+l.y+c.y)/3},f=[i,l,c].map(h=>({x:u.x+(h.x-u.x)*.55,y:u.y+(h.y-u.y)*.55+.04}));r.push({k:"path",d:Q(f,.25),fill:e.accent});break}case"round":r.push({k:"circle",x:o*.72,y:-.72,r:.36,fill:e.ears??e.body,...t}),e.ears||r.push({k:"circle",x:o*.74,y:-.74,r:.19,fill:e.accent});break;case"big-round":r.push({k:"circle",x:o*.96,y:-.46,r:.52,fill:e.body,...t}),r.push({k:"circle",x:o*1,y:-.44,r:.32,fill:e.accent});break;case"long":r.push({k:"ellipse",x:o*.38,y:-1.42,rx:.25,ry:.68,rot:o*.14,fill:e.body,...t}),r.push({k:"ellipse",x:o*.39,y:-1.36,rx:.12,ry:.48,rot:o*.14,fill:e.accent});break;case"side":r.push({k:"circle",x:o*1,y:.02,r:.34,fill:e.body,...t}),r.push({k:"circle",x:o*1.02,y:.02,r:.2,fill:e.belly});break;case"tufts":r.push({k:"path",d:Q([{x:o*.3,y:-.84},{x:o*1.22,y:-1.12},{x:o*.92,y:-.42}],.16),fill:e.body,...t}),r.push({k:"line",pts:[o*.62,-.78,o*1,-.98],stroke:e.accent,lw:.08});break;case"antennae":{let a={x:o*.62,y:-1.42};r.push({k:"path",d:`M${o*.3} -0.8 Q${o*.36} -1.2 ${a.x} ${a.y}`,stroke:e.outline,lw:n*2.6}),r.push({k:"path",d:`M${o*.3} -0.8 Q${o*.36} -1.2 ${a.x} ${a.y}`,stroke:e.body,lw:n*1.2}),r.push({k:"circle",x:a.x,y:a.y,r:.17,fill:e.accent,...t});break}case"floppy":r.push({k:"ellipse",x:o*.96,y:.02,rx:.3,ry:.62,rot:-o*.36,fill:e.ears??e.body,...t});break;case"droopy":r.push({k:"ellipse",x:o*1.04,y:-.22,rx:.4,ry:.18,rot:o*.32,fill:e.skin??e.body,...t}),r.push({k:"ellipse",x:o*1.08,y:-.2,rx:.24,ry:.08,rot:o*.32,fill:e.accent});break;case"pixie":r.push({k:"path",d:Q(se(o*.86,-.22,o*1.36,-.5,o*1.02,.26),.28),fill:e.skin??e.body,...t}),r.push({k:"line",pts:[o*.98,-.12,o*1.16,-.3],stroke:e.accent,lw:n*.8,alpha:.5});break;case"human":r.push({k:"ellipse",x:o*.98,y:.06,rx:.17,ry:.23,fill:e.skin??e.body,...t});break;case"horns":{let a=[{x:o*.3,y:-.84},{x:o*.6,y:-1.5},{x:o*.66,y:-.68}];r.push({k:"path",d:Q(a,.18),fill:e.accent,...t});break}}return s.ears==="fin"&&r.push({k:"path",d:Q(se(-.4,-.82,.2,-1.62,.46,-.78),.2),fill:e.body,...t}),s.ears==="antenna"&&(r.push({k:"line",pts:[0,-.85,0,-1.42],stroke:e.outline,lw:n*2.6}),r.push({k:"line",pts:[0,-.85,0,-1.42],stroke:e.limbs,lw:n*1.2}),r.push({k:"circle",x:0,y:-1.5,r:.18,fill:e.accent,...t})),r}function Za(s,n){let e=s.palette,t=s.face,r=[],o=e.outline,a=t.eyesOnTop?.46:.4,i=t.eyesOnTop?-.72:-.04,l=(c,u,f)=>({k:"circle",x:c,y:u,r:f,fill:ae});switch(t.eyes){case"dot":for(let c of Os(s,a,i))r.push({k:"ellipse",x:c.x,y:c.y,rx:.12*c.k,ry:.155*c.k,fill:o}),r.push(l(c.x+.04*c.k,c.y-.06*c.k,.045*c.k));break;case"bead":for(let c of Os(s,a,i))r.push({k:"ellipse",x:c.x,y:c.y,rx:.16*c.k,ry:.22*c.k,fill:o}),r.push(l(c.x+.05*c.k,c.y-.08*c.k,.065*c.k));break;case"big":for(let c of j)t.eyeRing&&r.push({k:"circle",x:c*a,y:i,r:.36,fill:t.eyeRing,stroke:o,lw:n*.8}),r.push({k:"circle",x:c*a,y:i,r:.25,fill:ae,stroke:o,lw:n*.8}),r.push({k:"circle",x:c*a+c*-.03,y:i+.03,r:.14,fill:t.eyeColor??o}),r.push(l(c*a+c*-.03+.05,i-.03,.05));break;case"mask":for(let c of j)r.push({k:"ellipse",x:c*.4,y:0,rx:.24,ry:.32,rot:c*-.55,fill:e.limbs}),r.push({k:"circle",x:c*.4,y:-.02,r:.11,fill:ae}),r.push({k:"circle",x:c*.39,y:-0,r:.065,fill:o});break;case"screen":r.push({k:"rect",x:0,y:0,w:1.5,h:.66,r:.26,fill:"#24323d",stroke:o,lw:n*.8});for(let c of j)r.push({k:"ellipse",x:c*.36,y:0,rx:.2,ry:.24,fill:t.eyeColor??"#7ff0ff",alpha:.3}),r.push({k:"ellipse",x:c*.36,y:0,rx:.12,ry:.16,fill:t.eyeColor??"#7ff0ff"});break;case"almond":for(let c of j)r.push({k:"ellipse",x:c*.42,y:-.02,rx:.3,ry:.2,rot:-c*.5,fill:t.eyeColor??o}),r.push(l(c*.42-c*.07,-.08,.07));break;case"calm":for(let c of j)r.push({k:"ellipse",x:c*.38,y:.02,rx:.085,ry:.12,fill:o}),r.push(l(c*.38+.03,-.02,.03));break;case"slit":r.push({k:"line",pts:[0,-.98,0,-.2],stroke:o,lw:n*.8,alpha:.5}),r.push({k:"rect",x:0,y:-.04,w:1.56,h:.26,r:.1,fill:Ar,stroke:o,lw:n*.8}),r.push({k:"rect",x:0,y:.3,w:.22,h:.46,r:.08,fill:Ar,stroke:o,lw:n*.8});for(let c of j){r.push({k:"ellipse",x:c*.4,y:-.04,rx:.12,ry:.07,fill:t.eyeColor??ae});for(let u of[.36,.56])r.push({k:"circle",x:c*.42,y:u,r:.05,fill:o,alpha:.6})}break;case"goggle":for(let c of j)r.push({k:"circle",x:c*.9,y:0,r:.13,fill:e.accent,stroke:o,lw:n*.8});r.push({k:"rect",x:0,y:0,w:1.66,h:.62,r:.3,fill:Ar,stroke:o,lw:n*.8}),r.push({k:"path",d:"M-0.6 -0.16 Q-0.42 -0.24 -0.12 -0.24",stroke:ae,lw:.07,alpha:.8});for(let c of j)r.push({k:"path",d:`M${c*.5} 0.04 Q${c*.34} -0.08 ${c*.16} 0.02`,stroke:t.eyeColor??"#7fd6ff",lw:.08});for(let c of[-.18,0,.18])r.push({k:"line",pts:[c,.56,c,.72],stroke:o,lw:n*.8,alpha:.6});break;case"visor":r.push({k:"ellipse",x:0,y:.08,rx:.8,ry:.64,fill:"#2a3f6b",stroke:o,lw:n*.8}),r.push({k:"path",d:"M-0.56 -0.14 Q-0.46 -0.4 -0.16 -0.46",stroke:ae,lw:.08,alpha:.7});for(let c of j)r.push({k:"ellipse",x:c*.28,y:.04,rx:.1,ry:.14,fill:t.eyeColor??"#cfeeff"});break}return r}function Ja(s,n){let e=s.palette,t=s.face,r=[],o=t.eyes==="visor"?"#cfeeff":Ls,a=n*1.05;switch(t.nose&&t.mouth!=="beak"&&(t.mouth==="cat"?r.push({k:"path",d:Q([{x:-.1,y:.22},{x:.1,y:.22},{x:0,y:.33}],.3),fill:t.nose,stroke:t.nose,lw:n*.6}):s.ears==="big-round"?r.push({k:"ellipse",x:0,y:.22,rx:.2,ry:.25,fill:t.nose}):r.push({k:"ellipse",x:0,y:.25,rx:.13,ry:.085,fill:t.nose})),t.mouth){case"smile":r.push({k:"path",d:t.eyes==="visor"?"M-0.16 0.32 Q0 0.46 0.16 0.32":"M-0.17 0.42 Q0 0.58 0.17 0.42",stroke:o,lw:a});break;case"open":r.push({k:"path",d:"M-0.21 0.4 Q0 0.46 0.21 0.4 Q0.19 0.68 0 0.68 Q-0.19 0.68 -0.21 0.4 Z",fill:o,stroke:o,lw:n*.5}),r.push({k:"ellipse",x:0,y:.6,rx:.1,ry:.06,fill:Is});break;case"cat":r.push({k:"path",d:"M-0.19 0.4 Q-0.1 0.5 0 0.37 Q0.1 0.5 0.19 0.4",stroke:o,lw:a});break;case"beak":r.push({k:"path",d:Q([{x:-.17,y:.2},{x:.17,y:.2},{x:0,y:.48}],.25),fill:e.accent,stroke:e.outline,lw:n*.8});break;case"teeth":r.push({k:"path",d:"M-0.36 0.34 Q0 0.44 0.36 0.34 Q0.28 0.66 0 0.66 Q-0.28 0.66 -0.36 0.34 Z",fill:o,stroke:o,lw:n*.5});for(let i of j)r.push({k:"rect",x:i*.12,y:.43,w:.1,h:.1,r:.03,fill:ae});break;case"grill":r.push({k:"rect",x:0,y:.56,w:.62,h:.2,r:.08,fill:"#24323d",stroke:e.outline,lw:n*.7});for(let i of[-.15,0,.15])r.push({k:"line",pts:[i,.51,i,.61],stroke:"#9fb0bd",lw:n*.6});break;case"tiny":r.push({k:"ellipse",x:0,y:.44,rx:.08,ry:.1,fill:o});break;case"smirk":r.push({k:"path",d:"M-0.16 0.46 Q0.06 0.54 0.22 0.38",stroke:o,lw:a});break;case"bill":r.push({k:"ellipse",x:0,y:.36,rx:.44,ry:.2,fill:e.accent,stroke:e.outline,lw:n*.8}),r.push({k:"path",d:"M-0.36 0.38 Q0 0.46 0.36 0.38",stroke:e.outline,lw:n*.7});for(let i of j)r.push({k:"circle",x:i*.1,y:.28,r:.03,fill:e.outline});break;case"hook":r.push({k:"ellipse",x:0,y:.48,rx:.16,ry:.11,fill:Ls}),r.push({k:"path",d:"M-0.3 0.12 Q0 -0.02 0.3 0.12 Q0.36 0.52 0.04 0.76 Q0.08 0.52 -0.08 0.46 Q-0.28 0.38 -0.3 0.12 Z",fill:e.accent,stroke:e.outline,lw:n*.8});break;case"toothy":{r.push({k:"path",d:"M-1.4 0.1 Q-0.5 0.36 0.5 0.2 Q0.64 0.16 0.68 0.02 Q0.78 0.28 0.52 0.38 Q-0.4 0.78 -1.3 0.26 Z",fill:o,stroke:o,lw:n*.6}),r.push({k:"ellipse",x:-.38,y:.5,rx:.24,ry:.08,fill:Is});for(let i of[.12,.27,.42,.57,.72,.86]){let l=(1-i)*(1-i)*-1.4+2*(1-i)*i*-.5+i*i*.5,c=(1-i)*(1-i)*.1+2*(1-i)*i*.36+i*i*.2-.01;r.push({k:"path",d:Q(se(l-.08,c,l+.08,c,l,c+.14),.3),fill:ae})}for(let i of[.3,.7]){let l=(1-i)*(1-i)*.52+2*(1-i)*i*-.4+i*i*-1.3,c=(1-i)*(1-i)*.38+2*(1-i)*i*.78+i*i*.26+.01;r.push({k:"path",d:Q(se(l-.07,c,l+.07,c,l,c-.12),.3),fill:ae})}break}case"jaws":{r.push({k:"path",d:"M-0.5 0.3 Q0 0.5 0.5 0.3 Q0.38 0.72 0 0.72 Q-0.38 0.72 -0.5 0.3 Z",fill:o,stroke:o,lw:n*.5});for(let i of[-.34,-.17,0,.17,.34]){let l=.3+.4*(i+.5)*(.5-i)-.01;r.push({k:"path",d:Q(se(i-.075,l,i+.075,l,i,l+.13),.15),fill:ae})}break}}return r}var kt=(s,n)=>({x:Math.sin(s)*n,y:-Math.cos(s)*n});var Hs=.5,We={leftEye:2,rightEye:5,leftEar:7,rightEar:8},tt={"3-5":{head:.75,neck:.74,arm:.3,leg:.36,hand:.19,foot:1.2,shoulderMin:.4,shoulderPad:.07,hipMin:.5,hipPad:.22,bottom:.26,bulge:1.12,armsOverHead:!0},"6-8":{head:.6,neck:.78,arm:.22,leg:.28,hand:.15,foot:1,shoulderMin:.34,shoulderPad:.04,hipMin:.4,hipPad:.16,bottom:.14,bulge:1.04,armsOverHead:!1},"9-12":{head:.5,neck:.92,arm:.17,leg:.21,hand:.125,foot:.9,shoulderMin:.36,shoulderPad:.07,hipMin:.32,hipPad:.08,bottom:.1,bulge:1,armsOverHead:!1}},Bn="6-8",zn=(s,n)=>n!==void 0&&s.band!=="all"&&s.alsoIn?.includes(n)&&n in tt?n:s.band in tt?s.band:Bn,ei=tt[Bn].head,$s=.3,Gs=.12,ti=.9,Ns=.5,Bs=.65,ni=.35,ri=.2,si=.25,Ge=(s,n)=>({x:s.x-n.x,y:s.y-n.y}),te=(s,n)=>({x:s.x+n.x,y:s.y+n.y}),Z=(s,n)=>({x:s.x*n,y:s.y*n}),wt=s=>Math.hypot(s.x,s.y),Ds=(s,n)=>({x:(s.x+n.x)/2,y:(s.y+n.y)/2}),Dn=s=>{let n=wt(s);return n>1e-9?{x:s.x/n,y:s.y/n}:{x:0,y:1}},oi=(...s)=>s.every(Number.isFinite),ai=s=>Math.atan2(Math.sin(s),Math.cos(s)),ii=(s,n,e)=>Math.min(Math.max(s,n),e);function Us(s,n,e=!1){return t=>{let r=s[t*3],o=s[t*3+1],a=s[t*3+2];return r===void 0||o===void 0||a===void 0||!oi(r,o,a)?{x:0,y:0,ok:!1}:{x:n.x+(e?1-r:r)*n.w,y:n.y+o*n.h,ok:a>=Hs}}}function Ot(s,n,e={}){let t=Us(s,n,e.mirrored),r=t(Y.leftShoulder),o=t(Y.rightShoulder);if(!r.ok||!o.ok)return null;let a=t(Y.leftHip),i=t(Y.rightHip),l=Ds(r,o),c=wt(Ge(o,r)),u=a.ok&&i.ok,f=Dn(Ge(o,r));c<1e-6&&(f={x:1,y:0});let h,b,y;if(u){let E=Ds(a,i);b=wt(Ge(E,l)),b>=c*si?h=Dn(Ge(E,l)):(h={x:-f.y,y:f.x},h.y<0&&(h=Z(h,-1))),y=Math.max(b,c*1.15)}else h={x:-f.y,y:f.x},h.y<0&&(h=Z(h,-1)),y=c*1.15,b=y;y=Math.max(y,1e-6);let m={x:h.y,y:-h.x},d=Math.atan2(m.y,m.x),x=Z(h,-1),g=tt[e.band??Bn]??tt[Bn],A=g.head*y,w=te(l,Z(x,A*g.neck)),v=t(Y.nose);if(v.ok){let E=te(v,Z(x,A*.15)),F=Z(Ge(E,w),ni),L=Math.min(1,A*ri/Math.max(wt(F),1e-6));w=te(w,Z(F,L))}return{S:l,r:m,d:h,U:y,L:b,hipsOk:u,head:w,headR:A,headRot:d+li(s,t,d,y),angle:d}}function li(s,n,e,t){let r=[[We.leftEar,We.rightEar],[We.leftEye,We.rightEye]];for(let[o,a]of r){let i=n(o),l=n(a);if(!i.ok||!l.ok||!(s[o*3+2]>=Bs&&s[a*3+2]>=Bs)||wt(Ge(l,i))<t*.05)continue;let c=ai(Math.atan2(l.y-i.y,l.x-i.x)-e),u=Math.max(Math.abs(c)-Gs,0),f=ii((ti+Ns-Math.abs(c))/Ns,0,1);return Math.sign(c)*Math.min(u,$s)*f}return 0}function ln(s,n,e,t={}){let r=zn(n,t.band),o=tt[r],a=Ot(s,e,{...t,band:r});if(!a)return[];let i=Us(s,e,t.mirrored),l=n.palette,{S:c,r:u,d:f,U:h,L:b}=a,y=S=>n.bodyExtras.includes(S),m=Math.max(1.2,h*.045),d={stroke:l.outline,lw:m},x=(S,I)=>({x:c.x+u.x*S+f.x*I,y:c.y+u.y*S+f.y*I}),g=S=>S.map(([I,N])=>x(I,N)),A=i(Y.leftShoulder),w=i(Y.rightShoulder),v=i(Y.leftHip),E=i(Y.rightHip),F=wt(Ge(w,A)),L=a.hipsOk?wt(Ge(E,v)):F*.7,_=Math.max(F/2+o.shoulderPad*h,o.shoulderMin*h),D=Math.max(L/2+o.hipPad*h,o.hipMin*h),H=-.1*h,W=b+o.bottom*h,G=[],be=[],$=[],oe=[],ye=[],Ne=(S,I,N,X)=>{let U=I.flatMap(le=>[le.x,le.y]);S.push({k:"line",pts:U,stroke:l.outline,lw:N+m*2}),S.push({k:"line",pts:U,stroke:X,lw:N})},hr=o.leg*h*(y("strong-legs")?1.3:1),we=o.arm*h*(y("tiny-arms")?.6:1),Be=Math.max(o.arm/.22,.9);if(a.hipsOk)for(let[S,I,N,X]of[[v,Y.leftKnee,Y.leftAnkle,-1],[E,Y.rightKnee,Y.rightAnkle,1]]){let U=i(I),le=i(N);if(!U.ok)continue;let Ft=te(S,Z(f,-.12*h)),ze=le.ok?[Ft,U,le]:[Ft,U];Ne(be,ze,hr,l.limbs),y("joints")&&be.push({k:"circle",x:U.x,y:U.y,r:.15*h*Be,fill:l.accent,...d}),le.ok&&be.push(...hi(n,le,a,X,m,o.foot))}for(let[S,I,N,X]of[[A,Y.leftElbow,Y.leftWrist,-1],[w,Y.rightElbow,Y.rightWrist,1]]){let U=i(I),le=i(N);if(y("pauldrons")){let ve=te(S,Z(f,.02*h));oe.push({k:"ellipse",x:ve.x,y:ve.y,rx:.25*h,ry:.17*h,rot:a.angle+X*.25,fill:l.body,...d});let Pe=te(ve,Z(f,.05*h));oe.push({k:"ellipse",x:Pe.x,y:Pe.y,rx:.17*h,ry:.07*h,rot:a.angle+X*.25,fill:l.belly})}if(!U.ok)continue;let ze=o.armsOverHead&&(U.x-c.x)*f.x+(U.y-c.y)*f.y<-.25*h?ye:oe,nn=te(S,Z(f,.04*h));if(Ne(ze,le.ok?[nn,U,le]:[nn,U],we,l.limbs),y("joints")&&ze.push({k:"circle",x:U.x,y:U.y,r:.13*h*Be,fill:l.accent,...d}),!le.ok)continue;let pe=Dn(Ge(le,U)),Ze=te(le,Z(pe,.05*h));if(y("feathers"))for(let ve of[-.55,0,.55]){let Pe=Math.cos(ve),bt=Math.sin(ve)*X,Ae={x:pe.x*Pe-pe.y*bt,y:pe.x*bt+pe.y*Pe},He=te(Ze,Z(Ae,.16*h));ze.push({k:"ellipse",x:He.x,y:He.y,rx:.2*h,ry:.09*h,rot:Math.atan2(Ae.y,Ae.x),fill:l.hands??l.accent,...d})}y("wand")&&X===1&&!t.portrait&&ze.push(...di(n,Ze,Dn(te(Z(pe,.4),Ge(Z(u,.6),f))),h,m));let Je=o.hand*h*(y("tiny-arms")?.72:1);if(y("tiny-arms"))for(let ve of[-.45,.45]){let Pe=Math.cos(ve),bt=Math.sin(ve),Ae={x:pe.x*Pe-pe.y*bt,y:pe.x*bt+pe.y*Pe},He=te(Ze,Z(Ae,Je*.75)),fr=te(Ze,Z(Ae,Je*1.6)),Rn={x:-Ae.y*Je*.32,y:Ae.x*Je*.32};ze.push({k:"path",d:Q([te(He,Rn),fr,Ge(He,Rn)],.2),fill:l.belly,...d})}ze.push({k:"circle",x:Ze.x,y:Ze.y,r:Je,fill:l.hands??l.limbs,...d})}if(y("wings"))for(let S of[-1,1]){let I=g([[S*_*.5,.05*h],[S*(_+.85*h),-.6*h],[S*(_+.72*h),.05*h],[S*(_+.45*h),-.02*h],[S*(_+.3*h),.32*h],[S*_*.6,.55*h]]);G.push({k:"path",d:Q(I,.18),fill:l.accent,...d})}if(y("wings-fairy")&&G.push(...mi(n,x,_,h,m)),y("cape")){let S=b+.8*h,I=D+.36*h,N=g([[-_*.92,H+.04*h],[_*.92,H+.04*h],[_+.16*h,b*.5],[I,S],[I*.5,S-.1*h],[0,S],[-I*.5,S-.1*h],[-I,S],[-_-.16*h,b*.5]]);G.push({k:"path",d:K(N,.6),fill:l.accent,...d})}if(y("backpack")){let S=x(0,.35*h);G.push({k:"rect",x:S.x,y:S.y,w:_*2+.34*h,h:.8*h,r:.16*h,rot:a.angle,fill:n.extraColors?.[0]??l.limbs,...d})}if(y("tank")){let S=x(_*.95,.24*h),I=n.extraColors?.[0]??l.accent,N=x(_*.95,-.3*h);G.push({k:"rect",x:N.x,y:N.y,w:.14*h,h:.16*h,r:.04*h,rot:a.angle,fill:l.outline}),G.push({k:"rect",x:S.x,y:S.y,w:.34*h,h:1*h,r:.17*h,rot:a.angle,fill:I,...d})}if(a.hipsOk&&!t.portrait&&G.push(...pi(n,a,D,m)),y("tentacles")&&a.hipsOk)for(let S of[-1,1]){let I=g([[S*D*.7,b*.9],[S*(D+.22*h),b+.3*h],[S*(D+.48*h),b+.22*h],[S*(D+.5*h),b-.02*h],[S*(D+.34*h),b-.06*h]]);G.push({k:"path",d:It(I),stroke:l.outline,lw:.2*h+m*2}),G.push({k:"path",d:It(I),stroke:l.limbs,lw:.2*h})}let xe=Math.max(_,D)*o.bulge;if(y("wool")){for(let[I,N]of[[_*.7,H+.02*h],[xe,b*.3],[xe*1.02,b*.62],[(xe+D)/2,b*.92],[D*.55,W]])for(let X of[-1,1]){let U=x(X*I,N);$.push({k:"circle",x:U.x,y:U.y,r:.2*h,fill:l.body,...d})}let S=x(0,W+.02*h);$.push({k:"circle",x:S.x,y:S.y,r:.2*h,fill:l.body,...d})}if(y("robe")){let S=b+.58*h,I=D*1.4;$.push({k:"path",d:K(g([[-_,H],[0,H-.04*h],[_,H],[xe,b*.55],[I,S],[0,S+.06*h],[-I,S],[-xe,b*.55]]),.7),fill:l.body,...d});let N=g([[-I*.94,S-.1*h],[0,S-.04*h],[I*.94,S-.1*h]]);$.push({k:"path",d:It(N),stroke:n.extraColors?.[0]??l.accent,lw:.07*h})}else if(y("sheet")){let S=b+.78*h,I=D*1.3;$.push({k:"path",d:K(g([[-_,H],[_,H],[xe,b*.55],[I,S],[I*.5,S-.2*h],[0,S],[-I*.5,S-.2*h],[-I,S],[-xe,b*.55]]),.9),fill:l.body,...d})}else $.push({k:"path",d:K(g([[-_,H],[0,H-.04*h],[_,H],[xe,b*.55],[D,W],[0,W+.03*h],[-D,W],[-xe,b*.55]]),.85),fill:l.body,...d});let fe=Math.min(_,D);if(y("pocket")){let S=x(0,b*.74);$.push({k:"rect",x:S.x,y:S.y,w:fe*1.3,h:.3*h,r:.1*h,rot:a.angle,fill:l.belly,stroke:l.outline,lw:m*.8})}else if(y("racing-stripe"))for(let S of[-.1,.1]){let I=x(S*h,H+.02*h),N=x(S*h,W-.04*h);$.push({k:"line",pts:[I.x,I.y,N.x,N.y],stroke:l.belly,lw:.1*h})}else if(l.belly&&l.belly!==l.body&&!y("panel")&&!y("sheet")&&!y("stripes")){let S=x(0,b*.58);$.push({k:"ellipse",x:S.x,y:S.y,rx:fe*.64,ry:Math.max(b*.36,.2*h),rot:a.angle,fill:l.belly})}if(y("spots")){let S=n.extraColors?.[1]??l.belly;for(let[I,N,X]of[[-.55,.35,.09],[.5,.62,.11],[-.35,.86,.07]]){let U=x(I*fe,N*b);$.push({k:"circle",x:U.x,y:U.y,r:X*h,fill:S})}}if(y("stripes")){let S=n.extraColors?.[1]??l.accent;for(let I of[.22,.44,.66]){let N=x(-fe*.98,b*I),X=x(fe*.98,b*I);$.push({k:"line",pts:[N.x,N.y,X.x,X.y],stroke:S,lw:.1*h})}}if(y("straps")){let S=n.extraColors?.[1]??l.outline;for(let I of[-1,1]){let N=x(I*_*.62,H+.02*h),X=x(I*fe*.62,b*.72);$.push({k:"line",pts:[N.x,N.y,X.x,X.y],stroke:l.outline,lw:.13*h+m*2}),$.push({k:"line",pts:[N.x,N.y,X.x,X.y],stroke:S,lw:.13*h})}}if(y("belt")){let S=x(0,b*.9);$.push({k:"rect",x:S.x,y:S.y,w:D*1.92,h:.17*h,r:.06*h,rot:a.angle,fill:n.extraColors?.[2]??"#4a3426",...d}),$.push({k:"rect",x:S.x,y:S.y,w:.2*h,h:.19*h,r:.04*h,rot:a.angle,fill:"#ffd84a",...d})}if(y("emblem")){let S=x(0,b*.4),I=n.extraColors?.[0]??l.accent,N=Q([{x:-.22,y:-.2},{x:.22,y:-.2},{x:.22,y:.04},{x:0,y:.26},{x:-.22,y:.04}],.25);$.push({k:"group",x:S.x,y:S.y,rot:a.angle,s:h,items:[{k:"path",d:N,fill:I,stroke:l.outline,lw:m/h},{k:"group",x:0,y:.01,s:.12,items:[{k:"path",d:et,fill:I===l.accent?"#ffffff":l.accent}]}]})}if(y("panel")){let S=x(0,b*.5);$.push({k:"rect",x:S.x,y:S.y,w:fe*1.2,h:.38*h,r:.1*h,rot:a.angle,fill:"#24323d",...d}),(n.extraColors??["#ff7a6b","#fbd46a","#7ff0ff"]).slice(0,3).forEach((N,X)=>{let U=x((X-1)*fe*.34,b*.5);$.push({k:"circle",x:U.x,y:U.y,r:.075*h,fill:N})})}if(y("badge")){let S=x(-fe*.42,b*.36);$.push({k:"circle",x:S.x,y:S.y,r:.15*h,fill:l.accent,...d}),$.push({k:"group",x:S.x,y:S.y,rot:a.angle,s:.09*h,items:[{k:"path",d:et,fill:"#ffffff"}]})}if(y("star")){let S=x(-fe*.5,b*.3),I=.15*h;$.push({k:"group",x:S.x,y:S.y,rot:a.angle-.2,s:I,items:[{k:"path",d:et,fill:n.extraColors?.[0]??"#ffd84a",stroke:l.outline,lw:m*.8/I}]})}if(y("petals")&&$.push(...bi(n,x,_,D,xe,b,W,h,m,o)),y("scarf")){let S=Math.max(.04,o.head*(1-o.neck)-.06)*h,I=x(0,S),N=n.extraColors?.[0]??l.accent,X=x(_*.45,S+.28*h);$.push({k:"rect",x:X.x,y:X.y,w:.16*h,h:.42*h,r:.06*h,rot:a.angle+.15,fill:N,...d}),$.push({k:"rect",x:I.x,y:I.y,w:_*2.05,h:.2*h,r:.1*h,rot:a.angle,fill:N,...d})}let De={k:"group",x:a.head.x,y:a.head.y,rot:a.headRot,s:a.headR,items:ui(n,m/a.headR)};return[...G,...be,...$,...oe,De,...ye]}var zs=new WeakMap,ci=64;function ui(s,n){let e=Number(n.toPrecision(4)),t=zs.get(s);t||zs.set(s,t=new Map);let r=t.get(e);return r||(t.size>=ci&&t.clear(),t.set(e,r=Nn(s,e))),r}function hi(s,n,e,t,r,o){let a=fi(s,n,e,t,r,o);if(!s.bodyExtras.includes("strong-legs"))return[a];let i=e.U*o,l=te(te(n,Z(e.d,.07*i)),Z(e.r,t*.06*i)),c=[a];for(let u of[-1,0,1]){let f=te(te(l,Z(e.r,u*.12*i)),Z(e.d,.09*i));c.push({k:"ellipse",x:f.x,y:f.y,rx:.05*i,ry:.045*i,rot:e.angle,fill:s.palette.belly,stroke:s.palette.outline,lw:r*.8})}return c}function fi(s,n,e,t,r,o){let a=s.palette,{d:i,r:l}=e,c=e.U*o,u=te(te(n,Z(i,.07*c)),Z(l,t*.06*c)),f={stroke:a.outline,lw:r},h=a.feet??a.limbs;if(s.bodyExtras.includes("fins")){let b=Q([{x:-.13,y:-.06},{x:.13,y:-.06},{x:.24,y:.46},{x:-.24,y:.46}],.22);return{k:"group",x:u.x,y:u.y,rot:e.angle,s:c,items:[{k:"path",d:b,fill:h,stroke:a.outline,lw:r/c},{k:"line",pts:[0,.06,0,.38],stroke:a.outline,lw:r/c,alpha:.5}]}}return s.bodyExtras.includes("flippers")?{k:"ellipse",x:u.x,y:u.y,rx:.27*c,ry:.11*c,rot:e.angle,fill:h,...f}:s.bodyExtras.includes("boots")?{k:"rect",x:u.x,y:u.y,w:.4*c,h:.24*c,r:.09*c,rot:e.angle,fill:h,...f}:{k:"ellipse",x:u.x,y:u.y,rx:.2*c,ry:.13*c,rot:e.angle,fill:h,...f}}function pi(s,n,e,t){let r=s.palette,{U:o,L:a,S:i,r:l,d:c}=n,u=(m,d)=>({x:i.x+l.x*m+c.x*d,y:i.y+l.y*m+c.y*d}),f=m=>m.map(([d,x])=>u(d,x)),h={stroke:r.outline,lw:t},b=(m,d,x)=>[{k:"path",d:It(m),stroke:r.outline,lw:d+t*2},{k:"path",d:It(m),stroke:x,lw:d}],y=[];switch(s.tail){case"none":break;case"fluffy":{let m=f([[e*.5,a*.95],[e+.28*o,a*1],[e+.72*o,a*.62],[e+.78*o,a*.12],[e+.52*o,a*.32],[e+.3*o,a*.6],[e*.6,a*.7]]);y.push({k:"path",d:K(m),fill:r.body,...h});let d=u(e+.72*o,a*.2);y.push({k:"ellipse",x:d.x,y:d.y,rx:.13*o,ry:.2*o,rot:n.angle+.25,fill:r.belly,...h});break}case"brush":{let m=f([[e*.4,a*.98],[e+.42*o,a*1.06],[e+.98*o,a*.66],[e+1.06*o,a*.12],[e+.86*o,-.04*o],[e+.66*o,a*.36],[e+.3*o,a*.66],[e*.5,a*.68]]);y.push({k:"path",d:K(m),fill:r.body,...h});let d=f([[e+1.03*o,a*.36],[e+1.06*o,a*.12],[e+.86*o,-.04*o],[e+.72*o,a*.24],[e+.86*o,a*.34]]);y.push({k:"path",d:K(d),fill:r.belly,...h});break}case"pom":{let m=u(e+.06*o,a*.88);y.push({k:"circle",x:m.x,y:m.y,r:.2*o,fill:r.belly,...h});break}case"long":case"striped":case"tuft":{let m=f([[e*.6,a*.9],[e+.35*o,a*.85],[e+.58*o,a*.4],[e+.5*o,-.02*o]]);if(y.push(...b(m,.14*o,r.body)),s.tail==="tuft"){let d=m[m.length-1];y.push({k:"circle",x:d.x,y:d.y,r:.16*o,fill:s.extraColors?.[0]??r.accent,...h})}if(s.tail==="striped"){for(let x of[.35,.6,.85]){let g=u(e+.35*o+.22999999999999998*o*(x*1.4>1?1:x*1.4),a*(.85-.85*x));y.push({k:"line",pts:[g.x-l.x*.08*o,g.y-l.y*.08*o,g.x+l.x*.08*o,g.y+l.y*.08*o],stroke:s.extraColors?.[0]??r.outline,lw:.06*o})}let d=m[m.length-1];y.push({k:"circle",x:d.x,y:d.y,r:.07*o,fill:s.extraColors?.[0]??r.outline})}break}case"curl":{let m=f([[e*.6,a*.9],[e+.4*o,a*.88],[e+.62*o,a*.45],[e+.5*o,a*.12],[e+.3*o,a*.24],[e+.36*o,a*.42]]);y.push(...b(m,.12*o,r.limbs));break}case"fish":{let m=f([[e*.6,a*.9],[e+.36*o,a*.86],[e+.6*o,a*.5]]);y.push(...b(m,.17*o,r.body));let d=m[m.length-1],x=Q([{x:0,y:.06},{x:-.26,y:-.34},{x:.02,y:-.12},{x:.32,y:-.3}],.2);y.push({k:"group",x:d.x,y:d.y,rot:n.angle+.35,s:o,items:[{k:"path",d:x,fill:r.body,stroke:r.outline,lw:t/o}]});break}case"plume":{let m=s.extraColors??[r.accent];[0,1,2].forEach(d=>{let x=u(e+(.12+d*.13)*o,a+(.32-d*.06)*o);y.push({k:"ellipse",x:x.x,y:x.y,rx:.11*o,ry:.44*o,rot:n.angle-.55+d*.28,fill:m[(d+1)%m.length],...h})});break}case"thick":{let m=f([[e*.3,a*.42],[e+.42*o,a*.62],[e+.92*o,a*.96],[e+1.32*o,a*1.08],[e+1.44*o,a*.98],[e+.98*o,a*1.2],[e+.4*o,a*1.22],[e*.3,a*1.12]]);y.push({k:"path",d:K(m,.8),fill:r.body,...h});let d=s.extraColors?.[0]??r.accent;for(let[x,g,A]of[[.28,.58,.26],[.62,.8,.22],[.96,1,.16]]){let w=u(e+x*o,a*g+.03*o),v=u(e+(x-.1)*o,a*g+A*o);y.push({k:"line",pts:[w.x,w.y,v.x,v.y],stroke:d,lw:.09*o})}break}case"spiky":case"arrow":{let m=f([[e*.3,a*.55],[e+.35*o,a*.68],[e+.95*o,a*.86],[e+.35*o,a*1.08],[e*.3,a*1.08]]);if(s.tail==="spiky"){for(let d of[.15,.45,.72]){let x=e+(.2+d*.7)*o,g=a*(.66+d*.19);y.push({k:"path",d:Q(f([[x-.12*o,g+.05*o],[x,g-.2*o],[x+.12*o,g+.07*o]]),.2),fill:r.accent,...h})}y.push({k:"path",d:K(m,.7),fill:r.body,...h})}else{let d=f([[e*.6,a*.9],[e+.4*o,a*.92],[e+.62*o,a*.5],[e+.62*o,a*.18]]);y.push(...b(d,.13*o,r.body));let x=d[d.length-1];y.push({k:"group",x:x.x,y:x.y,rot:n.angle,s:o,items:[{k:"path",d:Q([{x:-.15,y:.04},{x:0,y:-.22},{x:.15,y:.04}],.2),fill:r.accent,stroke:r.outline,lw:t/o}]})}break}}return y}function di(s,n,e,t,r){let o=s.palette,a=te(n,Z(e,-.08*t)),i=te(n,Z(e,.52*t)),l=.2*t;return[{k:"line",pts:[a.x,a.y,i.x,i.y],stroke:o.outline,lw:.06*t+r*2},{k:"line",pts:[a.x,a.y,i.x,i.y],stroke:"#fff3d6",lw:.06*t},{k:"circle",x:i.x,y:i.y,r:.24*t,fill:o.accent,alpha:.28},{k:"group",x:i.x,y:i.y,rot:Math.atan2(e.y,e.x)+Math.PI/2,s:l,items:[{k:"path",d:et,fill:o.accent,stroke:o.outline,lw:r*.9/l}]}]}function mi(s,n,e,t,r){let o=s.palette,a=s.extraColors?.[0]??"#cdeeff",i=[];for(let l of[-1,1]){let c=[[[l*e*.3,.12*t],[l*(e+.42*t),-.66*t],[l*(e+1*t),-.74*t],[l*(e+1.02*t),-.18*t],[l*(e+.5*t),.26*t]],[[l*e*.4,.3*t],[l*(e+.6*t),.36*t],[l*(e+.74*t),.78*t],[l*(e+.3*t),.9*t]]];for(let u of c){let f=K(u.map(([m,d])=>n(m,d)),.9);i.push({k:"path",d:f,fill:a,alpha:.6}),i.push({k:"path",d:f,stroke:o.outline,lw:r*.9});let h=u[Math.floor(u.length/2)],b=n(u[0][0],u[0][1]),y=n(u[0][0]+(h[0]-u[0][0])*.75,u[0][1]+(h[1]-u[0][1])*.75);i.push({k:"line",pts:[b.x,b.y,y.x,y.y],stroke:"#ffffff",lw:r*.9,alpha:.85})}for(let[u,f,h]of[[e+.72*t,-.42*t,.075*t],[e+.44*t,-.16*t,.05*t],[e+.5*t,.6*t,.055*t]]){let b=n(l*u,f);i.push({k:"group",x:b.x,y:b.y,s:h,items:[{k:"path",d:et,fill:"#ffffff"}]})}}return i}function bi(s,n,e,t,r,o,a,i,l,c){let u=s.palette,f=s.extraColors?.[1]??u.belly,h=[],b=Math.atan2(n(1,0).y-n(0,0).y,n(1,0).x-n(0,0).x),y=5,m=Math.max(t,r*.92)*1.08,d=(o*.8+a)/2,x=[0,4,1,3,2];for(let A of x){let w=A/(y-1)-.5,v=n(w*2*m,d+(.5-Math.abs(w))*.1*i);h.push({k:"ellipse",x:v.x,y:v.y,rx:m*.3,ry:.34*i,rot:b-w*.6,fill:A%2?f:u.body,stroke:u.outline,lw:l})}let g=Math.max(.04,c.head*(1-c.neck)-.04)*i;for(let A of[-1,1,0]){let w=n(A*e*.32,g+(A?0:.05*i));h.push({k:"ellipse",x:w.x,y:w.y,rx:e*.26,ry:.12*i,rot:b+A*.5,fill:A?f:u.body,stroke:u.outline,lw:l*.9})}return h}var yi={nose:[0,-.62],leftShoulder:[-.42,0],rightShoulder:[.42,0],leftElbow:[-.58,.5],rightElbow:[.58,.5],leftWrist:[-.66,.98],rightWrist:[.66,.98],leftHip:[-.27,1],rightHip:[.27,1],leftKnee:[-.31,1.6],rightKnee:[.31,1.6],leftAnkle:[-.33,2.18],rightAnkle:[.33,2.18]};function xi(s,{cx:n=.5,cy:e=.36,T:t=.18}={}){let r={...yi,...s},o=new Array(gr*3).fill(0),a=(c,[u,f],h=.99)=>{o[c*3]=n+u*t,o[c*3+1]=e+f*t,o[c*3+2]=h};for(let c of Object.keys(Y))a(Y[c],r[c]);let i=r.tilt??0,l=(c,u)=>[r.nose[0]+c*Math.cos(i)-u*Math.sin(i),r.nose[1]+c*Math.sin(i)+u*Math.cos(i)];return a(We.leftEye,l(-.1,-.08)),a(We.rightEye,l(.1,-.08)),a(We.leftEar,l(-.22,-.02)),a(We.rightEar,l(.22,-.02)),o}var Vs=()=>xi({});var cn=class{constructor(n={}){p(this,"tracks",new Map);p(this,"offset",NaN);p(this,"lastArrival",NaN);p(this,"interval",33);p(this,"lastT",NaN);p(this,"lostMs");p(this,"maxExtrapolateMs");this.lostMs=n.lostMs??250,this.maxExtrapolateMs=n.maxExtrapolateMs??25}get delayMs(){return this.interval}push(n,e,t,r=Ws()){Number.isFinite(e)||(e=r),this.clock(e,r);let o=this.tracks.get(n);if(!o||e-o.tb>this.lostMs||e<o.tb-this.lostMs||t.length!==o.b.length){this.tracks.set(n,{a:null,ta:e,b:t,tb:e,out:null,outAt:NaN});return}if(t===o.b||e<=o.tb){e===o.tb&&t!==o.b&&(o.b=t,o.out=null);return}o.a=o.b,o.ta=o.tb,o.b=t,o.tb=e,o.out=null}at(n,e=Ws()){let t=this.tracks.get(n);if(!t)return null;if(!t.a)return t.b;if(t.out&&t.outAt===e)return t.out;let r=e-this.offset-this.interval,o=t.tb-t.ta,a=Math.min(o*.5,this.maxExtrapolateMs),i=Math.min(Math.max((r-t.ta)/o,0),1+a/o);return t.out=Xs(t.a,t.b,i),t.outAt=e,t.out}forget(n){this.tracks.delete(n)}clear(){this.tracks.clear()}clock(n,e){let t=e-n;if(!Number.isFinite(this.offset)||t<this.offset||t>this.offset+1e3?this.offset=t:Number.isFinite(this.lastArrival)&&(this.offset+=Math.min(t-this.offset,(e-this.lastArrival)/1e3)),this.lastArrival=e,Number.isFinite(this.lastT)&&n>this.lastT){let r=n-this.lastT;r<this.interval*3+20&&(this.interval+=(Math.min(Math.max(r,8),100)-this.interval)*.1)}n<=this.lastT||(this.lastT=n)}},Ws=()=>globalThis.performance?.now()??Date.now();function Xs(s,n,e){let t=n.slice(),r=e<.5?s:n;for(let o=0;o+2<n.length;o+=3){let a=s[o],i=s[o+1],l=n[o],c=n[o+1];s[o+2]>=.5&&n[o+2]>=.5&&Math.abs(l-a)+Math.abs(c-i)<.15?(t[o]=a+(l-a)*e,t[o+1]=i+(c-i)*e,t[o+2]=s[o+2]+(n[o+2]-s[o+2])*Math.min(e,1)):(t[o]=r[o],t[o+1]=r[o+1],t[o+2]=r[o+2])}return t}var Vl=wr.map(s=>s.id);var Hn=new Map(wr.map(s=>[s.id,s])),vt=Hn.get("fox"),qs=s=>typeof s=="string"&&Hn.has(s),Nt=s=>Hn.get(s);var ki=s=>typeof s=="string"?Hn.get(s)??vt:s;function Ys(s,n,e){let t=ki(s),r=Vs(),o=zn(t,e),a=Ot(r,{x:0,y:0,w:1,h:1},{band:o}),i=Qs(Nn(t,.05)),l=-i.minY,c=Math.min(.27,.43/Math.max(l,1))*n,u=t.head==="snout-long"?(i.minX+i.maxX)/2*c:0,f=c/tt[o].head/a.U,h=.5*n+Math.min(0,(l-1.6)*.06*n),b={x:n/2-u-a.head.x*f,y:h-a.head.y*f,w:f,h:f};return ln(r,t,b,{portrait:!0,band:o})}function Ks(s,n,e=.5){if(!s||s.length!==n.length)return n.slice();let t=n.slice();for(let r=0;r+2<n.length;r+=3){let o=s[r+2],a=n[r+2],i=o>=.5,l=a>=.5;i&&a>=.3&&(t[r+2]=Math.max(a,.5));let c=Math.hypot(n[r]-s[r],n[r+1]-s[r+1]);if(i&&l&&c<.15){let u=e*Math.min(1,js+(1-js)*c/wi);t[r]=s[r]+(n[r]-s[r])*u,t[r+1]=s[r+1]+(n[r+1]-s[r+1])*u}else i&&!l&&t[r+2]>=.5&&(t[r]=s[r],t[r+1]=s[r+1])}return Si(s,n,t,e*vi),t}var js=.1,wi=.03,vi=.35,Ai=11;function Si(s,n,e,t){let r=Y.leftShoulder*3,o=Y.rightShoulder*3,a=(f,h)=>f[h+2]>=.5;if(!a(s,r)||!a(s,o)||!a(n,r)||!a(n,o))return;let i=(f,h)=>(f[r+h]+f[o+h])/2,l=[i(s,0),i(s,1)],c=[i(n,0),i(n,1)],u=[i(e,0),i(e,1)];for(let f=0;f<Ai&&f*3+2<n.length;f++){let h=f*3;if(!a(s,h)||!a(n,h))continue;let b=[s[h]-l[0],s[h+1]-l[1]],y=[n[h]-c[0],n[h+1]-c[1]];Math.hypot(y[0]-b[0],y[1]-b[1])>=.15||(e[h]=u[0]+b[0]+(y[0]-b[0])*t,e[h+1]=u[1]+b[1]+(y[1]-b[1])*t)}}function Qs(s){let n={minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0},e=(t,r)=>{n.minX=Math.min(n.minX,t),n.minY=Math.min(n.minY,r),n.maxX=Math.max(n.maxX,t),n.maxY=Math.max(n.maxY,r)};for(let t of s){let r="lw"in t&&t.stroke?(t.lw??1)/2:0;switch(t.k){case"circle":e(t.x-t.r-r,t.y-t.r-r),e(t.x+t.r+r,t.y+t.r+r);break;case"ellipse":case"rect":{let o=t.k==="ellipse"?t.rx:t.w/2,a=t.k==="ellipse"?t.ry:t.h/2,i=Math.max(o,a)+r;e(t.x-i,t.y-i),e(t.x+i,t.y+i);break}case"path":{let o=vr(t.d);for(let a=0;a+1<o.length;a+=2)e(o[a]-r,o[a+1]-r),e(o[a]+r,o[a+1]+r);break}case"line":for(let o=0;o+1<t.pts.length;o+=2)e(t.pts[o]-r,t.pts[o+1]-r),e(t.pts[o]+r,t.pts[o+1]+r);break;case"group":{let o=Qs(t.items);if(!Number.isFinite(o.minX))break;let a=t.s??1,i=Math.cos(t.rot??0),l=Math.sin(t.rot??0);for(let[c,u]of[[o.minX,o.minY],[o.maxX,o.minY],[o.minX,o.maxY],[o.maxX,o.maxY]])e(t.x+(c*i-u*l)*a,t.y+(c*l+u*i)*a);break}}}return n}var nt=()=>Float64Array.of(1,0,0,1,0,0);function Te(s,n,e,t,r,o,a){let i=r?Math.cos(r):1,l=r?Math.sin(r):0,c=i*o,u=l*o,f=-l*a,h=i*a;if(!n)return s[0]=c,s[1]=u,s[2]=f,s[3]=h,s[4]=e,s[5]=t,s;let b=n[0],y=n[1],m=n[2],d=n[3];return s[0]=b*c+m*u,s[1]=y*c+d*u,s[2]=b*f+m*h,s[3]=y*f+d*h,s[4]=b*e+m*t+n[4],s[5]=y*e+d*t+n[5],s}function Js(s,n,e){let t=s[0]*s[3]-s[1]*s[2];if(Math.abs(t)<1e-12)return null;let r=n-s[4],o=e-s[5];return[(s[3]*r-s[2]*o)/t,(-s[1]*r+s[0]*o)/t]}var Zs={white:16777215,black:0,red:16711680,transparent:0},un=new Map;function me(s){if(typeof s=="number")return[s&16777215,1];let n=un.get(s);if(n)return n;let e=[16777215,1],t=s.trim().toLowerCase();if(t[0]==="#"){let r=t.slice(1),o=r.length<=4?[...r].map(i=>i+i).join(""):r,a=parseInt(o.slice(0,6),16);Number.isFinite(a)&&(e=[a,o.length===8?parseInt(o.slice(6,8),16)/255:1])}else if(t.startsWith("rgb")){let r=t.match(/-?\d*\.?\d+%?/g)?.map(c=>c.endsWith("%")?parseFloat(c)/100*255:parseFloat(c))??[],[o=255,a=255,i=255]=r,l=r[3]===void 0?1:t.match(/,\s*[\d.]+%\s*\)$/)?r[3]/255:r[3];e=[(Sr(o)<<16|Sr(a)<<8|Sr(i))>>>0,Math.min(Math.max(l,0),1)]}else if(t in Zs)e=[Zs[t],t==="transparent"?0:1];else if(typeof document<"u"){let r=document.createElement("canvas").getContext("2d");if(r){r.fillStyle="#ffffff",r.fillStyle=t;let o=r.fillStyle;if(o!==t)return un.set(s,e=me(o)),e}}return un.size>512&&un.clear(),un.set(s,e),e}var Sr=s=>Math.min(Math.max(Math.round(s),0),255);function lt(s,n,e=!1){let t=Math.min(Math.max(n,0),1),r=(s>>16&255)*t,o=(s>>8&255)*t,a=(s&255)*t,i=e?0:t*255;return(Math.round(i)<<24|Math.round(a)<<16|Math.round(o)<<8|Math.round(r))>>>0}var At=(s,n=1)=>`rgba(${s>>16&255},${s>>8&255},${s&255},${n})`;function Mr(s,n){if(s===16777215)return n;if(n===16777215)return s;let e=t=>Math.round((s>>t&255)*(n>>t&255)/255);return(e(16)<<16|e(8)<<8|e(0))>>>0}var ct={linear:s=>s,quadIn:s=>s*s,quadOut:s=>s*(2-s),quadInOut:s=>s<.5?2*s*s:-1+(4-2*s)*s,cubicOut:s=>1-(1-s)**3,sineInOut:s=>-(Math.cos(Math.PI*s)-1)/2,backOut:s=>1+(1.70158+1)*(s-1)**3+1.70158*(s-1)**2,elasticOut:s=>s===0||s===1?s:2**(-10*s)*Math.sin((s*10-.75)*(2*Math.PI/3))+1,bounceOut:s=>s<1/2.75?7.5625*s*s:s<2/2.75?7.5625*(s-=1.5/2.75)*s+.75:s<2.5/2.75?7.5625*(s-=2.25/2.75)*s+.9375:7.5625*(s-=2.625/2.75)*s+.984375};function eo(s){let n=s>>>0;return()=>{n=n+1831565813>>>0;let e=n;return e=Math.imul(e^e>>>15,e|1),e^=e+Math.imul(e^e>>>7,e|61),((e^e>>>14)>>>0)/4294967296}}var T={cap:0,epoch:0,x:new Float64Array(0),y:new Float64Array(0),rot:new Float64Array(0),sx:new Float64Array(0),sy:new Float64Array(0),alpha:new Float64Array(0),la:new Float64Array(0),lb:new Float64Array(0),lc:new Float64Array(0),ld:new Float64Array(0),world:new Float64Array(0),tint:new Uint32Array(0),flags:new Uint8Array(0),moved:new Uint8Array(0),dirty:new Uint8Array(0),gen:new Uint32Array(0),parent:new Int32Array(0),first:new Int32Array(0),next:new Int32Array(0),prev:new Int32Array(0),stamp:new Uint32Array(0),pass:0,free:new Int32Array(0),freeHead:0,freeCount:0,top:2},ut=[],Mi="x y rot sx sy alpha la lb lc ld world tint flags moved dirty gen parent first next prev stamp".split(" ");function to(s){let n=T;for(let t of Mi){let r=n[t],o=new r.constructor(t==="world"?s*6:s);o.set(r),n[t]=o}let e=new Int32Array(s);for(let t=0;t<T.freeCount;t++)e[t]=T.free[(T.freeHead+t)%T.cap];for(T.free=e,T.freeHead=0,T.cap=s,T.epoch++;ut.length<s;)ut.push(null)}function Er(s){T.x[s]=T.y[s]=T.rot[s]=0,T.sx[s]=T.sy[s]=T.alpha[s]=1,T.la[s]=T.ld[s]=1,T.lb[s]=T.lc[s]=0;let n=s*6,e=T.world;e[n]=e[n+3]=1,e[n+1]=e[n+2]=e[n+4]=e[n+5]=0,T.tint[s]=16777215,T.flags[s]=3,T.moved[s]=1,T.dirty[s]=0,T.parent[s]=T.first[s]=T.next[s]=T.prev[s]=-1}to(256);Er(0);T.flags[0]=0;Er(1);T.flags[1]=0;function no(){let s;if(T.freeCount){s=T.free[T.freeHead],T.freeHead=(T.freeHead+1)%T.cap,T.freeCount--;let n=ut[s];n&&(n._i=0,n._g=-1,ut[s]=null)}else T.top===T.cap&&to(T.cap*2),s=T.top++;return Er(s),s}function Rr(s,n){$n(s);for(let t=T.first[s];t>=0;){let r=T.next[t];T.parent[t]=T.next[t]=T.prev[t]=-1,t=r}T.first[s]=-1,T.flags[s]=T.flags[s]&-3,T.moved[s]=0;let e=T.gen[s]+1;T.gen[s]=e,e!==4294967295&&(n&&(ut[s]=n),T.free[(T.freeHead+T.freeCount)%T.cap]=s,T.freeCount++)}function ro(s){for(let n=0;n<ut.length;n++){let e=ut[n];e&&s(e)&&(e._i=0,e._g=-1,ut[n]=null)}}function so(s,n){$n(s);let e=T.first[n];T.parent[s]=n,T.next[s]=e,T.prev[s]=-1,e>=0&&(T.prev[e]=s),T.first[n]=s,T.moved[s]=1}function $n(s){let n=T.parent[s];if(n<0)return;let e=T.next[s],t=T.prev[s];t>=0?T.next[t]=e:T.first[n]=e,e>=0&&(T.prev[e]=t),T.parent[s]=T.next[s]=T.prev[s]=-1}var hn={root:-1,gen:-1,world:new Float64Array(6)};function oo(s){let n=++T.pass,e=T.world,t=s*6,r=hn.world,o=hn.root!==s||hn.gen!==T.gen[s];for(let a=0;a<6;a++)r[a]!==e[t+a]&&(o=!0),r[a]=e[t+a];hn.root=s,hn.gen=T.gen[s],T.stamp[s]=o?n:n-1}function ao(s){T.stamp[s]=T.pass}function io(s){for(let n=T.first[s];n>=0;){let e=T.next[n];io(n),n=e}Rr(s)}var Tr=typeof FinalizationRegistry=="function"?new FinalizationRegistry(s=>T.gen[s.i]===s.g&&io(s.i)):null;function Cr(s){s._reg||!Tr||(s._reg=!0,Tr.register(s,{i:s._i,g:s._g},s))}function lo(s){s._reg&&Tr.unregister(s)}function fn(s){if(s){for(let n=0;n<s.length;n++)if(s[n].enabled)return!0}return!1}function co(s,n){let e=0;for(let t=0;t<s.length;t++){let r=s[t];r.enabled&&r.pad&&(e+=r.pad(n))}return e}var Ee={gl:null,c2d:null,live:null};var q=new Float64Array(3),pn=4,Ti=1,dn=()=>Ti++;var ie=nt(),P=T,Ie=class{constructor(n){p(this,"kernel",n);p(this,"_i",no());p(this,"_g",P.gen[this._i]);p(this,"_wv",null);p(this,"_wi",-1);p(this,"_we",-1);p(this,"blend","normal");p(this,"_data",null);p(this,"parent",null);p(this,"hitRadius",null);p(this,"clip",null);p(this,"mask",null);p(this,"filters",null);p(this,"_z",0);p(this,"anchorX",0);p(this,"anchorY",0);p(this,"_pool",null);p(this,"_free",!1);p(this,"_reg",!1)}get x(){return P.x[this._i]}set x(n){let e=this._i||1;P.x[e]=n,P.moved[e]=1}get y(){return P.y[this._i]}set y(n){let e=this._i||1;P.y[e]=n,P.moved[e]=1}get rotation(){return P.rot[this._i]}set rotation(n){let e=this._i||1;P.rot[e]=n,P.dirty[e]=P.moved[e]=1}get scaleX(){return P.sx[this._i]}set scaleX(n){let e=this._i||1;P.sx[e]=n,P.dirty[e]=P.moved[e]=1}get scaleY(){return P.sy[this._i]}set scaleY(n){let e=this._i||1;P.sy[e]=n,P.dirty[e]=P.moved[e]=1}get alpha(){return P.alpha[this._i]}set alpha(n){let e=this._i||1;P.alpha[e]=n,P.moved[e]=1}get visible(){return(P.flags[this._i]&1)!==0}set visible(n){let e=this._i||1;n?P.flags[e]=P.flags[e]|1:P.flags[e]=P.flags[e]&-2,P.moved[e]=1}get destroyed(){return P.gen[this._i]!==this._g}get world(){let n=this._i||1;return(this._wi!==n||this._we!==P.epoch)&&(this._wv=P.world.subarray(n*6,n*6+6),this._wi=n,this._we=P.epoch),this._wv}get data(){return this._data??(this._data={})}set data(n){this._data=n}get scale(){return this.scaleX}set scale(n){this.scaleX=this.scaleY=n}get z(){return this._z}set z(n){n!==this._z&&(this._z=n,this.parent&&(this.parent.sortDirty=!0))}get tint(){return P.tint[this._i]}set tint(n){P.tint[this._i||1]=typeof n=="number"?n&16777215:me(n)[0]}set anchor(n){typeof n=="number"?this.anchorX=this.anchorY=n:(this.anchorX=n.x,this.anchorY=n.y)}get width(){return 0}set width(n){}get height(){return 0}set height(n){}set(n){for(let e in n){let t=n[e];t!==void 0&&(this[e]=t)}return this}destroy(){this.destroyed||(this.visible=!1,this.parent&&(this.parent.dead=!0,this.parent=null),Rr(this._i,this),lo(this),this.kernel.tweens.stopAll(this),this._pool?.forget(this))}updateWorld(){let n=this.parent?this.parent.updateWorld():null;return Te(this.world,n,this.x,this.y,this.rotation,this.scaleX,this.scaleY)}draw(n,e,t){}};function po(s){ro(n=>n.kernel===s)}var Fr=!1,uo=Object.freeze([]),Tt=class s extends Ie{constructor(e){super(e);p(this,"children",uo);p(this,"sortDirty",!1);p(this,"dead",!1);Cr(this)}add(e,...t){this.adopt(e);for(let r=0;r<t.length;r++)this.adopt(t[r]);return e}adopt(e){e.parent&&e.parent.detach(e),e.parent=this,!e.destroyed&&!this.destroyed&&so(e._i,this._i),this.children===uo&&(this.children=[]),this.children.push(e),(e.z!==0||this.sortDirty)&&(this.sortDirty=!0)}remove(e){this.detach(e),e._pool||Cr(e)}detach(e){let t=this.children,r=t.indexOf(e);if(r>=0){for(let o=r+1;o<t.length;o++)t[o-1]=t[o];t.pop()}e.parent===this&&(e.parent=null,e.destroyed||$n(e._i))}clear(){for(let e of this.children)e.destroy()}destroy(){for(let e of this.children)e.destroy();super.destroy()}sweep(){if(this.dead){this.dead=!1;let e=0;for(let t of this.children)t.destroyed?t.parent===this&&(t.parent=null):this.children[e++]=t;this.children.length=e}for(let e of this.children)e instanceof s&&e.sweep()}draw(e,t,r){if(Fr)return P.parent[this._i]<0&&!this.destroyed&&ao(this._i),this.drawChildren(e,t,r);Fr=!0;try{this.destroyed||oo(this._i),this.drawChildren(e,t,r)}finally{Fr=!1}}drawChildren(e,t,r){if(this.sortDirty){let l=new Map(this.children.map((c,u)=>[c,u]));this.children.sort((c,u)=>c.z-u.z||l.get(c)-l.get(u)),this.sortDirty=!1}let o=this.children,a=this._i,i=P.stamp[a]===P.pass;for(let l=0;l<o.length;l++){let c=o[l],u=c._i,f=P.alpha[u];if(P.gen[u]!==c._g||!(P.flags[u]&1)||f<=0)continue;if(i||P.moved[u]){P.moved[u]=0,P.stamp[u]=P.pass;let y,m,d,x;if(P.dirty[u]){P.dirty[u]=0;let H=P.rot[u],W=H?Math.cos(H):1,G=H?Math.sin(H):0,be=P.sx[u],$=P.sy[u];P.la[u]=y=W*be,P.lb[u]=m=G*be,P.lc[u]=d=-G*$,P.ld[u]=x=W*$}else y=P.la[u],m=P.lb[u],d=P.lc[u],x=P.ld[u];let g=P.world,A=P.x[u],w=P.y[u],v=u*6,E=a*6,F=g[E],L=g[E+1],_=g[E+2],D=g[E+3];g[v]=F*y+_*m,g[v+1]=L*y+D*m,g[v+2]=F*d+_*x,g[v+3]=L*d+D*x,g[v+4]=F*A+_*w+g[E+4],g[v+5]=L*A+D*w+g[E+5]}let h=t*f,b=Mr(r,P.tint[u]);c.clip||c.mask||c.filters?mo(e,c,h,b):c.draw(e,h,b)}}},ge=new Float64Array(128),St=0,Pr=new Float64Array(8);function _r(s,n,e,t){n.clip||n.mask||n.filters?mo(s,n,e,t):n.draw(s,e,t)}function mo(s,n,e,t){let r=s.r,o=n.world,a=n.clip,i=!1,l=!1;if(a)if(Math.abs(o[1])<1e-9&&Math.abs(o[2])<1e-9&&St<32){let f=o[0]*a.x+o[4],h=o[0]*(a.x+a.width)+o[4],b=o[3]*a.y+o[5],y=o[3]*(a.y+a.height)+o[5],m=Math.min(f,h),d=Math.max(f,h),x=Math.min(b,y),g=Math.max(b,y);if(St){let w=(St-1)*4;m=Math.max(m,ge[w]),x=Math.max(x,ge[w+1]),d=Math.min(d,ge[w+2]),g=Math.min(g,ge[w+3])}let A=St++*4;ge[A]=m,ge[A+1]=x,ge[A+2]=d,ge[A+3]=g,r.clip(m,x,Math.max(d-m,0),Math.max(g-x,0)),l=!0}else i=!0;let c=n.mask&&n.mask.visible?n.mask:null,u=fn(n.filters)?n.filters:null;try{if(i&&r.beginLayer(),c&&r.beginLayer(),u?(n.draw(s,r.beginLayer()?1:e,t),r.endLayer(e,u)):n.draw(s,e,t),c&&(r.beginMask(),Te(c.world,o,c.x,c.y,c.rotation,c.scaleX,c.scaleY),_r(s,c,c.alpha,16777215),r.endLayer(1)),i&&a){r.beginMask();for(let f=0;f<4;f++){let h=f===1||f===2?a.x+a.width:a.x,b=f>1?a.y+a.height:a.y;Pr[f*2]=o[0]*h+o[2]*b+o[4],Pr[f*2+1]=o[1]*h+o[3]*b+o[5]}r.polygon(Pr,4,16777215,1),r.endLayer(1)}}finally{if(l)if(St--,St){let f=(St-1)*4;r.clip(ge[f],ge[f+1],ge[f+2]-ge[f],ge[f+3]-ge[f+1])}else r.unclip()}}var Re=class extends Ie{constructor(e,t,r){super(e);p(this,"_frame",null);p(this,"_w",null);p(this,"_h",null);p(this,"slice",0);p(this,"autoAnchor",!0);p(this,"frameName",null);t&&(this.frame=t),r?.anchor===void 0&&this.useFrameAnchor(),r&&this.set(r)}get frame(){return this._frame}set frame(e){this.frameName=typeof e=="string"?e:null,this._frame=typeof e=="string"?this.kernel.frame(e):e,this.autoAnchor&&this.useFrameAnchor()}set anchor(e){this.autoAnchor=!1,super.anchor=e}get naturalWidth(){let e=this.frameNow();return e?(e.sw??e.w)/e.scale-e.margin*2:0}get naturalHeight(){let e=this.frameNow();return e?(e.sh??e.h)/e.scale-e.margin*2:0}get width(){return this._w??this.naturalWidth}set width(e){this._w=e}get height(){return this._h??this.naturalHeight}set height(e){this._h=e}sizeQ(e){zt[0]=this._w??(e.sw??e.w)/e.scale-e.margin*2,zt[1]=this._h??(e.sh??e.h)/e.scale-e.margin*2}frameNow(){return this.frameName&&!this.kernel.atlas.valid(this._frame)&&(this._frame=this.kernel.frame(this.frameName)),this._frame}useFrameAnchor(){let e=this._frame;if(!e)return;let t=(e.sw??e.w)/e.scale-e.margin*2,r=(e.sh??e.h)/e.scale-e.margin*2;this.anchorX=t>0?(e.ox-e.margin)/t:0,this.anchorY=r>0?(e.oy-e.margin)/r:0}draw(e,t,r){let o=this.frameNow();if(!o)return;let a=zt;this.sizeQ(o),a[2]=this.anchorX,a[3]=this.anchorY,a[4]=t,Ei(e,o,this.world,this.slice,r,this.blend)}},Bt=new Float64Array(12),Dt=new Float64Array(12),mn={x:0,y:0,w:0,h:0};function ho(s,n,e,t,r,o){n=Math.max(n,0),e=Math.max(e,0),t=Math.max(t,0);let a=e+t>r?e*r/(e+t):e,i=e+t>r?t*r/(e+t):t,l=a/o,c=i/o;if(l+c>n){let u=n/(l+c);l*=u,c*=u}s[0]=0,s[1]=l,s[2]=0,s[3]=a,s[4]=l,s[5]=n-l-c,s[6]=a,s[7]=r-a-i,s[8]=n-c,s[9]=c,s[10]=r-i,s[11]=i}var zt=new Float64Array(5);function Ei(s,n,e,t,r,o){let a=zt,i=a[0],l=a[1],c=a[2],u=a[3],f=a[4],h=s.tex(n.surface),b=t===0?n.slice??0:t;if(b===0){let w=(n.sw??n.w)/n.scale-n.margin*2,v=(n.sh??n.h)/n.scale-n.margin*2,E=w>0?i/w:1,F=v>0?l/v:1,L=-c*i+((n.tx??0)/n.scale-n.margin)*E,_=-u*l+((n.ty??0)/n.scale-n.margin)*F;bn(e,L,_),q[0]=n.w/n.scale*E,q[1]=n.h/n.scale*F,q[2]=f,s.r.quadQ(h,n,ie,r,o);return}let y=n.tx??0,m=n.ty??0,d=(n.sw??n.w)-n.w-y,x=(n.sh??n.h)-n.h-m,g=-c*i-n.margin+y/n.scale,A=-u*l-n.margin+m/n.scale;if(ho(Bt,i+n.margin*2-(y+d)/n.scale,(typeof b=="number"?b:b[3])-y,(typeof b=="number"?b:b[1])-d,n.w,n.scale),ho(Dt,l+n.margin*2-(m+x)/n.scale,(typeof b=="number"?b:b[0])-m,(typeof b=="number"?b:b[2])-x,n.h,n.scale),bn(e,g,A),q[2]=f,!s.r.nineQ?.(h,n,Bt,Dt,ie,r,o))for(let w=0;w<12;w+=4){let v=Dt[w+1],E=Dt[w+3];if(!(v<=0||E<=0))for(let F=0;F<12;F+=4){let L=Bt[F+1],_=Bt[F+3];L<=0||_<=0||(mn.x=n.x+Bt[F+2],mn.y=n.y+Dt[w+2],mn.w=_,mn.h=E,bn(e,g+Bt[F],A+Dt[w]),q[0]=L,q[1]=v,q[2]=f,s.r.quadQ(h,mn,ie,r,o))}}}function bn(s,n,e){ie[0]=s[0],ie[1]=s[1],ie[2]=s[2],ie[3]=s[3],ie[4]=s[0]*n+s[2]*e+s[4],ie[5]=s[1]*n+s[3]*e+s[5]}var Xe=class extends Re{constructor(e,t,r={}){super(e,null);p(this,"_spec");p(this,"baked",null);p(this,"bakedEffects",!0);this._spec=t,this.bake(),r.anchor===void 0&&this.useFrameAnchor(),this.set(r)}get spec(){return this._spec}set spec(e){this._spec=e,this.baked=null,this._w=this._h=null,this.bake()}bake(){let e=this.kernel;return this.baked&&e.atlas.valid(this.baked.frame)&&this.baked.frame.scale===e.pixelScale&&this.bakedEffects===e.effects?this.baked:(this.bakedEffects=e.effects,this.baked=e.shape(this._spec),this._frame=this.baked.frame,this.slice=this.baked.slice,this.baked)}frameNow(){return this.bake().frame}sizeQ(){let e=this.bake();zt[0]=this._w??e.w,zt[1]=this._h??e.h}get width(){return this._w??this.bake().w}set width(e){this._w=e}get height(){return this._h??this.bake().h}set height(e){this._h=e}},fo=(s,n,e)=>s===void 0?n:typeof s=="number"?s:s[0]+(s[1]-s[0])*e(),Mt=class Mt extends Ie{constructor(e,t,r={}){super(e);p(this,"max");p(this,"f");p(this,"tints");p(this,"count",0);p(this,"gravity");p(this,"drag");p(this,"frameRef");p(this,"random",Math.random);this.frameRef=t,this.max=Math.max(1,Math.floor(r.max??200)),this.f=new Float32Array(this.max*Mt.W),this.tints=new Uint32Array(this.max),this.blend=r.blend??"normal",this.gravity=r.gravity??0,this.drag=r.drag??1}get alive(){return this.count}burst(e,t,r,o={}){let a=Mt.W,i=this.random,l=o.tint===void 0?16777215:me(o.tint)[0];for(let c=0;c<r;c++){let u=this.count;if(u>=this.max){let d=0,x=1/0;for(let g=0;g<this.max;g++){let A=this.f[g*a+5]-this.f[g*a+4];A<x&&(x=A,d=g)}u=d}else this.count++;let f=(o.angle??0)+(o.spread===void 0?i()*Math.PI*2:(i()-.5)*o.spread),h=fo(o.speed,200,i),b=Array.isArray(o.scale)?o.scale[0]:o.scale??1,y=Array.isArray(o.scale)?o.scale[1]:o.scale??1,m=u*a;this.f[m]=e,this.f[m+1]=t,this.f[m+2]=Math.cos(f)*h,this.f[m+3]=Math.sin(f)*h,this.f[m+4]=0,this.f[m+5]=Math.max(fo(o.life,.8,i),.01),this.f[m+6]=i()*Math.PI*2,this.f[m+7]=(i()-.5)*2*(o.spin??0),this.f[m+8]=b,this.f[m+9]=y,this.f[m+10]=o.alpha??1,this.tints[u]=l}}update(e){let t=Mt.W,r=this.f,o=this.drag>=1?1:Math.pow(Math.max(this.drag,0),e);for(let a=0;a<this.count;){let i=a*t;if(r[i+4]=r[i+4]+e,r[i+4]>=r[i+5]){let l=--this.count;a!==l&&(r.copyWithin(i,l*t,l*t+t),this.tints[a]=this.tints[l]);continue}r[i+3]=(r[i+3]+this.gravity*e)*o,r[i+2]=r[i+2]*o,r[i]=r[i]+r[i+2]*e,r[i+1]=r[i+1]+r[i+3]*e,r[i+6]=r[i+6]+r[i+7]*e,a++}}clear(){this.count=0}draw(e,t,r){if(!this.count)return;let o=typeof this.frameRef=="string"?this.frameRef=this.kernel.frame(this.frameRef):this.frameRef,a=Mt.W,i=this.f,l=this.world,c=o.w/o.scale,u=o.h/o.scale;for(let f=0;f<this.count;f++){let h=f*a,b=i[h+4]/i[h+5],y=i[h+8]+(i[h+9]-i[h+8])*b,m=t*i[h+10]*(1-b*b),d=i[h+6],x=Math.cos(d)*y,g=Math.sin(d)*y,A=i[h],w=i[h+1],v=l[0],E=l[1],F=l[2],L=l[3],_=v*x+F*g,D=E*x+L*g,H=F*x-v*g,W=L*x-E*g;ie[0]=_,ie[1]=D,ie[2]=H,ie[3]=W,ie[4]=v*A+F*w+l[4]-(_*c+H*u)/2,ie[5]=E*A+L*w+l[5]-(D*c+W*u)/2,q[0]=c,q[1]=u,q[2]=m,e.r.quadQ(e.tex(o.surface),o,ie,Mr(r,this.tints[f]),this.blend)}}};p(Mt,"W",11);var Ht=Mt;var Oe=class extends Re{constructor(e,t,r={}){let{fps:o,loop:a,playing:i,speed:l,onComplete:c,...u}=r;if(!t.frames.length)throw new Error("[engine] an animation needs at least one frame");super(e,t.frames[0],u);p(this,"frames");p(this,"durations");p(this,"fps");p(this,"loop");p(this,"speed");p(this,"onComplete");p(this,"_playing");p(this,"index",0);p(this,"t",0);this.frames=t.frames,this.durations=t.durations&&o===void 0?t.durations:null,this.fps=o??12,this.loop=a!==!1,this.speed=l??1,this.onComplete=c??null,this._playing=i!==!1,this.speed<0&&this.show(t.frames.length-1)}get frameIndex(){return this.index}get frameCount(){return this.frames.length}get playing(){return this._playing}play(){return!this.loop&&!this._playing&&this.index===(this.speed<0?0:this.frames.length-1)&&this.show(this.speed<0?this.frames.length-1:0),this._playing=!0,this}stop(){return this._playing=!1,this}gotoFrame(e){let t=this.frames.length;return this.show((Math.floor(e)%t+t)%t),this.t=0,this}gotoAndPlay(e){return this._playing=!0,this.gotoFrame(e)}gotoAndStop(e){return this._playing=!1,this.gotoFrame(e)}show(e){e===this.index&&this._frame||(this.index=e,this.frame=this.frames[e])}secondsOf(e){let t=this.durations?.[e];return t!==void 0&&t>0?t:1/Math.max(this.fps,.001)}update(e){if(!this._playing||this.destroyed||this.speed===0)return;let t=this.frames.length,r=this.speed<0;this.t+=e*Math.abs(this.speed);let o=this.index;for(let a=0;a<1e3;a++){let i=this.secondsOf(o);if(this.t<i)break;this.t-=i;let l=r?o-1:o+1;if(l<0||l>=t){if(!this.loop){this.t=0,this._playing=!1,this.show(o),this.onComplete?.();return}o=r?t-1:0}else o=l}this.show(o)}},bo=(s,n)=>s.localeCompare(n,void 0,{numeric:!0});var yn=class{constructor(n,e,t=2){p(this,"width",n);p(this,"height",e);p(this,"padding",t);p(this,"shelves",[]);p(this,"free",[]);p(this,"bottom",0)}alloc(n,e){let t=Math.ceil(n)+this.padding*2,r=Math.ceil(e)+this.padding*2;if(t>this.width||r>this.height)return null;for(let i=0;i<this.free.length;i++){let l=this.free[i];if(l.w>=t&&l.h>=r&&l.w*l.h<=t*r*2)return this.free.splice(i,1),this.inner(l.x,l.y,n,e)}let o=null;for(let i of this.shelves)i.h>=r&&i.h<=r*1.5+8&&this.width-i.x>=t&&(!o||i.h<o.h)&&(o=i);if(!o)if(this.bottom+r>this.height){for(let i of this.shelves)i.h>=r&&this.width-i.x>=t&&(o=i);if(!o)return null}else o={y:this.bottom,h:r,x:0},this.shelves.push(o),this.bottom+=r;let a=o.x;return o.x+=t,this.inner(a,o.y,n,e)}release(n){this.free.push({x:n.x-this.padding,y:n.y-this.padding,w:Math.ceil(n.w)+this.padding*2,h:Math.ceil(n.h)+this.padding*2})}get fill(){return this.bottom/this.height}reset(){this.shelves=[],this.free=[],this.bottom=0}inner(n,e,t,r){return{x:n+this.padding,y:e+this.padding,w:t,h:r}}},$t=s=>({source:s,texture:null,pending:[]}),ht=class{constructor(n=2048,e=4){p(this,"pageSize",n);p(this,"maxPages",e);p(this,"pages",[]);p(this,"gen",1);p(this,"onPage",()=>{});p(this,"onDrop",()=>{})}valid(n){return!!n&&(n.gen===this.gen||n.gen===0)}bake(n,e,t,r=1,o=0,a=0,i=0){let l=Math.max(1,Math.ceil(n)),c=Math.max(1,Math.ceil(e)),u=document.createElement("canvas");u.width=l,u.height=c;let f=u.getContext("2d");return t(f),this.put(u,l,c,r,o,a,i)}add(n,e=1,t=0,r=0){let o=document.createElement("canvas");return o.width=Math.max(1,n.width),o.height=Math.max(1,n.height),o.getContext("2d").drawImage(n,0,0),this.put(o,o.width,o.height,e,t,r,0)}release(n){if(n.gen!==this.gen)return;this.pages.find(t=>t.surface===n.surface)?.packer.release(n)}rebake(n,e,t,r,o=n.w,a=n.h){if(!this.valid(n)||e>o||t>a)return null;let i=Math.max(1,Math.ceil(e)),l=Math.max(1,Math.ceil(t)),c=this.pages.find(f=>f.surface===n.surface);if(!c)return null;let u=document.createElement("canvas");return u.width=Math.ceil(o),u.height=Math.ceil(a),r(u.getContext("2d")),c.ctx.clearRect(n.x,n.y,u.width,u.height),c.ctx.drawImage(u,n.x,n.y),n.surface.pending.push([u,n.x,n.y]),n.w=i,n.h=l,n}put(n,e,t,r,o,a,i){let l=null,c=this.pages.find(f=>(l=f.packer.alloc(e,t))!==null);if(c||(!(Math.max(e,t)+4>this.pageSize)&&this.pages.length>=this.maxPages&&(this.wipe(),c=this.pages[0],l=c?c.packer.alloc(e,t):null),(!c||!l)&&(c=this.newPage(Math.max(e,t)),l=c.packer.alloc(e,t))),!l)throw new Error(`[engine] ${e}\xD7${t} does not fit an atlas page`);let u=l;return c.ctx.drawImage(n,u.x,u.y),c.surface.pending.push([n,u.x,u.y]),{surface:c.surface,x:u.x,y:u.y,w:e,h:t,scale:r,gen:this.gen,ox:o,oy:a,margin:i}}newPage(n){let e=this.pageSize;for(;e<n+4;)e*=2;let t=document.createElement("canvas");t.width=t.height=e;let r=t.getContext("2d"),o=$t(t),a={surface:o,packer:new yn(e,e),ctx:r};return this.pages.push(a),this.onPage(o),a}wipe(){this.gen++;let n=0;for(let e=0;e<this.pages.length;e++){let t=this.pages[e];if(n<this.maxPages&&t.surface.source.width===this.pageSize){this.pages[n++]=t;continue}t.surface.pending=[],this.onDrop(t.surface)}this.pages.length=n;for(let e of this.pages)e.packer.reset(),e.ctx.clearRect(0,0,e.surface.source.width,e.surface.source.height),e.surface.pending=[],e.surface.pending.push([e.surface.source,0,0])}};var Ri=()=>{let s=typeof document<"u"?document.timeline?.currentTime:null;return typeof s=="number"&&Number.isFinite(s)?s:globalThis.performance?.now()??Date.now()},yo=()=>globalThis.performance?.now()??Date.now(),xn=class{constructor(n=Ri){p(this,"now",n);p(this,"known",new Map);p(this,"smoothed",new Map);p(this,"times",new WeakMap);p(this,"lerp",new cn);p(this,"drawnAt",NaN);p(this,"drawn",0);p(this,"smoothedBody",(n,e={})=>{let t=e.interpolate!==!1;if(typeof n=="number"){let r=this.smoothed.get(n);return r?t?this.lerp.at(n,this.tick())??r.body:r.body:null}return typeof n!="object"||n===null||!Array.isArray(n.body)?null:this.posed(n.id,n.body,Ci(e.smooth),t)})}note(n,e,t=yo()){for(let r of n)this.known.set(r.id,this.resolve(r.id,r.avatar)),e!==void 0&&Number.isFinite(e)&&Array.isArray(r.body)&&this.times.set(r.body,{t:e,arrival:t})}of(n){return typeof n=="object"&&n!==null?n.avatar!==void 0?this.resolve(n.id,n.avatar):this.of(n.id):this.known.get(n)??kr(n-1)}posed(n,e,t,r=!0){let o=this.smooth(n,e,t);return r?this.lerp.at(n,this.tick())??o:o}smooth(n,e,t){let r=this.smoothed.get(n);if(r&&r.raw===e&&r.amount===t)return r.body;r&&r.amount!==t&&this.lerp.forget(n);let o=t<1?Ks(r?.body,e,t):e;this.smoothed.set(n,{raw:e,body:o,amount:t});let a=this.times.get(e),i=a?.arrival??yo();return this.lerp.push(n,a?.t??i,o,i),o}takeDrawn(){let n=this.drawn;return this.drawn=0,n}tick(){let n=this.now();return n!==this.drawnAt&&(this.drawnAt=n,this.drawn++),n}resolve(n,e){return qs(e)?e:kr(n-1)}};var Ci=s=>s===!1?1:typeof s=="number"?Math.min(Math.max(s,.05),1):.5;var ko=new Float64Array(1),xo=new Int32Array(ko.buffer),Gt=(s,n)=>(s=Math.imul(s^n,1540483477),s^s>>>15);function st(s,n=2538058380){return s!==s?Gt(n,2146959360):(ko[0]=s===0?0:s,Gt(Gt(n,xo[0]),xo[1]))}function go(s,n=2166136261){for(let e=0;e<s.length;e++)n=Math.imul(n^s.charCodeAt(e),16777619);return n}function Ue(s){switch(typeof s){case"number":return st(s);case"string":return go(s);case"boolean":return s?1013904242:461845907;case"object":{if(s===null)return 625341585;if(Array.isArray(s)||s instanceof Float64Array){let t=1779033703^s.length;for(let r=0;r<s.length;r++){let o=s[r];t=Gt(t,typeof o=="number"?st(o):Ue(o))}return t}let n=1359893119,e=s;for(let t in e){let r=e[t];r!==void 0&&(n=n+Gt(go(t),Ue(r))|0)}return Gt(n,2600822924)}default:return 0}}function Ut(s,n){if(s===n)return!0;if(typeof s!="object"||typeof n!="object"||s===null||n===null)return typeof s=="number"&&typeof n=="number"&&s!==s&&n!==n;let e=Array.isArray(s)||s instanceof Float64Array;if(e!==(Array.isArray(n)||n instanceof Float64Array))return!1;if(e){let o=s,a=n;if(o.length!==a.length)return!1;for(let i=0;i<o.length;i++)if(o[i]!==a[i]&&!Ut(o[i],a[i]))return!1;return!0}let t=s,r=n;for(let o in t)if(t[o]!==void 0&&!Ut(t[o],r[o]))return!1;for(let o in r)if(r[o]!==void 0&&t[o]===void 0)return!1;return!0}function gn(s){if(typeof s!="object"||s===null)return s;if(Array.isArray(s))return s.map(gn);if(s instanceof Float64Array)return s.slice();let n={};for(let e in s)s[e]!==void 0&&(n[e]=gn(s[e]));return n}var Vt=class{constructor(n=1/0){p(this,"max",n);p(this,"buckets",new Map);p(this,"n",0)}get size(){return this.n}get(n,e=Ue(n)){let t=this.buckets.get(e);if(t){for(let r=0;r<t.length;r++)if(Ut(t[r].key,n))return t[r].value}}set(n,e,t=Ue(n)){let r=this.buckets.get(t);if(r){for(let o of r)if(Ut(o.key,n)){o.value=e;return}}this.n>=this.max&&this.clear(),(!r||!this.buckets.has(t))&&this.buckets.set(t,r=[]),r.push({key:gn(n),value:e}),this.n++}clear(){this.buckets.clear(),this.n=0}};var Lr=0,wo=1,Un=2,Ir=3,Wt=class{constructor(){p(this,"scale",1);p(this,"cOn",!1);p(this,"px0",0);p(this,"py0",0);p(this,"px1",0);p(this,"py1",0);p(this,"clipVer",0);p(this,"stack",[]);p(this,"sp",0);p(this,"real",0);p(this,"mute",0);p(this,"bnd",new Float64Array(4*(pn+1)));p(this,"rx0",0);p(this,"ry0",0);p(this,"rx1",0);p(this,"ry1",0);p(this,"maxBlur",1/0);p(this,"time",0);p(this,"skipped",0);p(this,"gq",new Float64Array(4))}resetLayers(n){this.scale=n,this.sp=this.real=this.mute=0,this.skipped=0,this.cOn=!1,this.clipVer++}growQ(){let n=this.gq;this.grow(n[0],n[1],n[2],n[3])}grow(n,e,t,r){if(!this.real)return;let o=this.bnd,a=(this.real-1)*4;n<o[a]&&(o[a]=n),e<o[a+1]&&(o[a+1]=e),t>o[a+2]&&(o[a+2]=t),r>o[a+3]&&(o[a+3]=r)}area(n,e){let t=this.bnd,r=n*4,o=this.scale;return this.rx0=Math.max(Math.floor((t[r]-e)*o)-1,0),this.ry0=Math.max(Math.floor((t[r+1]-e)*o)-1,0),this.rx1=Math.min(Math.ceil((t[r+2]+e)*o)+1,this.canvas.width),this.ry1=Math.min(Math.ceil((t[r+3]+e)*o)+1,this.canvas.height),this.rx1>this.rx0&&this.ry1>this.ry0}clip(n,e,t,r){let o=this.scale,a=this.canvas.width,i=this.canvas.height,l=Math.min(Math.max(Math.round(n*o),0),a),c=Math.min(Math.max(Math.round(e*o),0),i),u=Math.min(Math.max(Math.round((n+t)*o),l),a),f=Math.min(Math.max(Math.round((e+r)*o),c),i);this.cOn&&l===this.px0&&c===this.py0&&u===this.px1&&f===this.py1||(this.cOn=!0,this.px0=l,this.py0=c,this.px1=u,this.py1=f,this.clipVer++)}unclip(){this.cOn&&(this.cOn=!1,this.clipVer++)}push(n){if(n<Un&&(this.mute||this.real>=pn||!this.pushLayer())&&(n+=2),n===Ir)this.mute++;else if(n!==Un){let e=this.real*4;this.bnd[e]=this.bnd[e+1]=1/0,this.bnd[e+2]=this.bnd[e+3]=-1/0,this.real++}return this.stack[this.sp++]=n,n<Un}beginLayer(){return this.push(Lr)}beginMask(){this.push(this.sp&&this.stack[this.sp-1]===Lr?wo:Ir)}endLayer(n,e){if(!this.sp)return;let t=this.stack[--this.sp];if(t===Ir){if(this.mute--,!this.sp)return;t=this.stack[--this.sp]}if(t===wo){let r=--this.real,o=this.popLayer();this.area(r-1,0)&&this.composite(o,!0,1,null);let a=this.bnd,i=(r-1)*4,l=r*4;a[i]=Math.max(a[i],a[l]),a[i+1]=Math.max(a[i+1],a[l+1]),a[i+2]=Math.min(a[i+2],a[l+2]),a[i+3]=Math.min(a[i+3],a[l+3]),t=this.stack[--this.sp]}if(t===Un)fn(e)&&(this.skipped+=e.length);else if(t===Lr){let r=--this.real,o=fn(e)?e:null,a=this.popLayer();if(this.area(r,o?co(o,this.maxBlur):0)){this.composite(a,!1,n,o);let i=this.scale;this.grow(this.rx0/i,this.ry0/i,this.rx1/i,this.ry1/i)}}}closeLayers(){for(;this.sp;)this.endLayer(1)}};var Fi=256,vo=8<<20,Ce=new Float64Array(32),Fe={x:0,y:0,w:0,h:0};function Pi(s){if(typeof s.filter!="string")return!1;s.filter="blur(1px)";let n=s.filter==="blur(1px)";return s.filter="none",n}function Xt(s){let n=s.getContext("2d",{alpha:!0});return n?new Or(s,n):null}var Or=class extends Wt{constructor(e,t){super();p(this,"canvas",e);p(this,"ctx",t);p(this,"kind","canvas2d");p(this,"maxTextureSize",4096);p(this,"features",{});p(this,"info",{renderer:"canvas2d"});p(this,"support");p(this,"lost",!1);p(this,"fxr",null);p(this,"quads",0);p(this,"stats",{drawCalls:0,quads:0,filtersSkipped:0});p(this,"tinted",new Map);p(this,"tintedN",0);p(this,"lostListeners",[]);p(this,"restoredListeners",[]);p(this,"base");p(this,"top");p(this,"layers",[]);p(this,"scratch",[]);p(this,"nines",new Map);p(this,"ninePx",0);p(this,"frame",0);p(this,"hit",!1);p(this,"missed",new Map);this.support={filters:Pi(t),shaders:!1},this.base=this.top={ctx:t,clipped:!1,ver:0},e.addEventListener("contextlost",()=>{this.lost=!0,this.lostListeners.forEach(r=>r())}),e.addEventListener("contextrestored",()=>{this.lost=!1,this.tinted.clear(),this.tintedN=0,this.dropNines(),this.restoredListeners.forEach(r=>r())})}resize(e,t){this.canvas.width!==e&&(this.canvas.width=e),this.canvas.height!==t&&(this.canvas.height=t)}createTexture(e){return{id:dn(),width:e.width,height:e.height,source:e}}updateTexture(e,t,r=0,o=0){let a=t?r+t.width:1/0,i=t?o+t.height:1/0;for(let l of this.nines.values()){let c=l.key;c[0]===e.id&&c[1]<a&&c[1]+c[3]>r&&c[2]<i&&c[2]+c[4]>o&&this.dropNine(l)}for(let[l,c]of this.tinted){let u=c.filter(f=>f.id!==e.id);this.tintedN-=c.length-u.length,u.length?this.tinted.set(l,u):this.tinted.delete(l)}}destroyTexture(e){this.updateTexture(e)}begin(e,t,r){this.resetLayers(r),this.fxr?.tick(),this.frame++,this.quads=0,this.top=this.base,this.ctx=this.base.ctx;let o=this.ctx;this.base.clipped&&o.restore(),this.base.clipped=!1,this.base.ver=this.clipVer,o.setTransform(1,0,0,1,0,0),o.globalAlpha=1,o.globalCompositeOperation="source-over",o.clearRect(0,0,this.canvas.width,this.canvas.height),t>0&&(o.fillStyle=At(e,t),o.fillRect(0,0,this.canvas.width,this.canvas.height))}quad(e,t,r,o,a,i,l,c){q[0]=o,q[1]=a,q[2]=l,this.quadQ(e,t,r,i,c)}quadQ(e,t,r,o,a){t.w<=0||t.h<=0||(o===16777215?this.blit(e.source,t.x,t.y,t.w,t.h,r,a):this.blit(this.tint(e,t,o),0,0,t.w,t.h,r,a))}blit(e,t,r,o,a,i,l){let c=q[0],u=q[1],f=q[2];if(f<=0||this.mute)return;this.sync();let h=this.ctx,b=this.scale;if(this.real){let y=i[0]*c,m=i[1]*c,d=i[2]*u,x=i[3]*u;this.grow(i[4]+Math.min(0,y,d,y+d),i[5]+Math.min(0,m,x,m+x),i[4]+Math.max(0,y,d,y+d),i[5]+Math.max(0,m,x,m+x))}h.setTransform(i[0]*b,i[1]*b,i[2]*b,i[3]*b,i[4]*b,i[5]*b),h.globalAlpha=Math.min(f,1),l==="add"&&(h.globalCompositeOperation="lighter"),h.drawImage(e,t,r,o,a,0,0,c,u),l==="add"&&(h.globalCompositeOperation="source-over"),this.quads++}nineQ(e,t,r,o,a,i,l){var m,d;let c=r[8]+r[9],u=o[8]+o[9],f=Math.ceil(c*Math.hypot(a[0],a[1])*this.scale-1e-6),h=Math.ceil(u*Math.hypot(a[2],a[3])*this.scale-1e-6);if(a[1]===0&&a[2]===0||f>4096||h>4096)return!1;if(!(f>0&&h>0&&q[2]>0)||this.mute)return!0;let b=this.kept(e,t,r,o,f,h,i),y=(b??(b=(m=this.scratch)[d=13*Math.ceil(Math.log2(f))+Math.ceil(Math.log2(h))]??(m[d]=document.createElement("canvas").getContext("2d")))).canvas;if(y.width<f&&(y.width=f),y.height<h&&(y.height=h),!this.hit){b.clearRect(0,0,f+2,h+2);for(let x=0;x<12;x+=4){let g=Math.round(o[x]*h/u),A=Math.round((o[x]+o[x+1])*h/u);for(let w=0;w<12;w+=4){let v=Math.round(r[w]*f/c),E=Math.round((r[w]+r[w+1])*f/c);Fe.x=t.x+r[w+2],Fe.y=t.y+o[x+2],Fe.w=r[w+3],Fe.h=o[x+3],!(E<=v||A<=g||Fe.w<=0||Fe.h<=0)&&(i===16777215?b.drawImage(e.source,Fe.x,Fe.y,Fe.w,Fe.h,v,g,E-v,A-g):b.drawImage(this.tint(e,Fe,i),0,0,Fe.w,Fe.h,v,g,E-v,A-g))}}}return q[0]=c,q[1]=u,this.blit(y,0,0,f,h,a,l),!0}kept(e,t,r,o,a,i,l){Ce[0]=e.id,Ce[1]=t.x,Ce[2]=t.y,Ce[3]=t.w,Ce[4]=t.h,Ce[5]=a,Ce[6]=i,Ce[7]=l,Ce.set(r,8),Ce.set(o,20);let c=Ue(Ce),u=this.nines.get(c);if(this.hit=!1,u)return Ut(u.key,Ce)?(u.used=this.frame,this.hit=!0,u.ctx):null;let f=this.missed,h=f.get(c);f.size>4096&&f.clear(),f.set(c,this.frame);let b=a*i;if(h!==this.frame-1||b>vo)return null;let y;for(;this.ninePx+b>vo;){let x;for(let w of this.nines.values())w.used<this.frame-1&&!(x&&x.used<=w.used)&&(x=w);if(!x)return null;let g=x.ctx.canvas,A=!y&&g.width>=a&&g.height>=i&&g.width*g.height<=2*b;this.dropNine(x,A),A&&(y=x.ctx)}let m=y??document.createElement("canvas").getContext("2d"),d=m.canvas;return y||(d.width=a,d.height=i),this.ninePx+=d.width*d.height,this.nines.set(c,{key:gn(Ce),ctx:m,used:this.frame}),m}dropNine(e,t=!1){this.nines.delete(Ue(e.key));let r=e.ctx.canvas;this.ninePx-=r.width*r.height,t||(r.width=0)}dropNines(){for(let e of this.nines.values())this.dropNine(e)}tint(e,t,r){let o=st(r,st(t.h,st(t.w,st(t.y,st(t.x,st(e.id)))))),a=this.tinted.get(o);if(a)for(let c=0;c<a.length;c++){let u=a[c];if(u.id===e.id&&u.x===t.x&&u.y===t.y&&u.w===t.w&&u.h===t.h&&u.color===r)return u.canvas}this.tintedN>=Fi&&(this.tinted.clear(),this.tintedN=0,a=void 0);let i=document.createElement("canvas");i.width=Math.ceil(t.w),i.height=Math.ceil(t.h);let l=i.getContext("2d");return l.drawImage(e.source,t.x,t.y,t.w,t.h,0,0,t.w,t.h),l.globalCompositeOperation="multiply",l.fillStyle=At(r),l.fillRect(0,0,t.w,t.h),l.globalCompositeOperation="destination-in",l.drawImage(e.source,t.x,t.y,t.w,t.h,0,0,t.w,t.h),a||this.tinted.set(o,a=[]),a.push({id:e.id,x:t.x,y:t.y,w:t.w,h:t.h,color:r,canvas:i}),this.tintedN++,i}paint(e,t){this.sync();let r=this.ctx,o=this.scale;return r.setTransform(o,0,0,o,0,0),r.globalAlpha=Math.min(t,1),At(e)}ellipse(e,t,r,o,a,i,l){if(l<=0||r<=0||o<=0||this.mute)return;let c=Math.max(r,o);this.grow(e-c,t-c,e+c,t+c);let u=this.ctx;u.fillStyle=this.paint(i,l),u.beginPath(),u.ellipse(e,t,r,o,a,0,Math.PI*2),u.fill(),this.quads++}trace(e,t,r=0){if(this.real)for(let a=0;a<t;a++)this.grow(e[a*2]-r,e[a*2+1]-r,e[a*2]+r,e[a*2+1]+r);let o=this.ctx;o.beginPath(),o.moveTo(e[0],e[1]);for(let a=1;a<t;a++)o.lineTo(e[a*2],e[a*2+1])}polygon(e,t,r,o){if(o<=0||t<3||this.mute)return;let a=this.ctx;a.fillStyle=this.paint(r,o),this.trace(e,t),a.closePath(),a.fill(),this.quads++}stroke(e,t,r,o,a,i){if(a<=0||r<=0||t<1||this.mute)return;let l=this.ctx;l.strokeStyle=this.paint(o,a),l.lineWidth=r,l.lineCap="round",l.lineJoin="round",this.trace(e,t,r/2),t===1&&l.lineTo(e[0],e[1]),i&&l.closePath(),l.stroke(),this.quads++}sync(){let e=this.top;if(e.ver===this.clipVer)return;let t=e.ctx;e.clipped&&t.restore(),e.clipped=this.cOn,e.ver=this.clipVer,this.cOn&&(t.save(),t.setTransform(1,0,0,1,0,0),t.beginPath(),t.rect(this.px0,this.py0,this.px1-this.px0,this.py1-this.py0),t.clip())}pushLayer(){let e=this.canvas.width,t=this.canvas.height,r=this.layers[this.real];if(!r||r.ctx.canvas.width!==e||r.ctx.canvas.height!==t){let a=document.createElement("canvas");a.width=e,a.height=t;let i=a.getContext("2d");if(!i)return!1;r=this.layers[this.real]={ctx:i,clipped:!1,ver:-1}}let o=r.ctx;return r.clipped&&o.restore(),r.clipped=!1,r.ver=-1,o.setTransform(1,0,0,1,0,0),o.globalAlpha=1,o.globalCompositeOperation="source-over",o.clearRect(0,0,e,t),this.top=r,this.ctx=o,!0}popLayer(){return this.top=this.real>0?this.layers[this.real-1]:this.base,this.ctx=this.top.ctx,this.layers[this.real].ctx.canvas}composite(e,t,r,o){let a=e,i="none",l=o&&Ee.c2d?this.fxr??(this.fxr=Ee.c2d(this)):null;l&&(a=l.chain(e,o),i=l.css),this.sync();let c=this.ctx,u=this.rx0,f=this.ry0,h=this.rx1-u,b=this.ry1-f;c.setTransform(1,0,0,1,0,0),c.globalAlpha=Math.min(r,1),c.globalCompositeOperation=t?"destination-in":"source-over",i!=="none"&&(c.filter=i),c.drawImage(a,u,f,h,b,u,f,h,b),i!=="none"&&(c.filter="none"),c.globalCompositeOperation="source-over",this.quads++}end(){this.closeLayers();let e=this.stats;return e.drawCalls=e.quads=this.quads,e.filtersSkipped=this.skipped,e}onLost(e){this.lostListeners.push(e)}onRestored(e){this.restoredListeners.push(e)}destroy(){this.tinted.clear(),this.dropNines(),this.layers=[],this.scratch=[],this.fxr?.destroy(),this.fxr=null}};var Vn=class{constructor(n,e,t=8192){p(this,"instanced",n);p(this,"slots",e);p(this,"capacity",t);p(this,"f32");p(this,"u32");p(this,"quads",0);p(this,"textures");p(this,"bound",0);this.textures=new Array(e).fill(null);let r=t*(n?14:24),o=new ArrayBuffer(r*4);this.f32=new Float32Array(o),this.u32=new Uint32Array(o)}slot(n){let e=this.textures;for(let t=0;t<this.bound;t++)if(e[t]===n)return t;return this.bound>=this.slots?-1:(e[this.bound]=n,this.bound++)}has(n){for(let e=0;e<this.bound;e++)if(this.textures[e]===n)return!0;return!1}get full(){return this.quads>=this.capacity}get words(){return this.quads*(this.instanced?14:24)}reset(){this.quads=0;for(let n=0;n<this.bound;n++)this.textures[n]=null;this.bound=0}push(n,e,t,r,o,a,i,l,c,u,f,h,b,y){let m=this.f32;if(this.instanced){let d=this.quads*14;m[d++]=n,m[d++]=e,m[d++]=t,m[d++]=r,m[d++]=o,m[d++]=a,m[d++]=i,m[d++]=l,m[d++]=c,m[d++]=u,m[d++]=f,m[d++]=h,this.u32[d++]=b,m[d]=y}else{let d=this.quads*6*4;this.vertex(d,n,e,c,u,b,y),this.vertex(d+6,t,r,f,u,b,y),this.vertex(d+12,o,a,f,h,b,y),this.vertex(d+18,i,l,c,h,b,y)}this.quads++}pushQ(n,e){let t=this.f32;if(this.instanced){let r=this.quads*14;for(let o=0;o<12;o++)t[r+o]=n[o];this.u32[r+12]=n[12],t[r+13]=e}else{let r=this.quads*6*4,o=n[12];for(let a=0;a<4;a++,r+=6)t[r]=n[a*2],t[r+1]=n[a*2+1],t[r+2]=a===1||a===2?n[10]:n[8],t[r+3]=a>=2?n[11]:n[9],this.u32[r+4]=o,t[r+5]=e}this.quads++}vertex(n,e,t,r,o,a,i){let l=this.f32;l[n]=e,l[n+1]=t,l[n+2]=r,l[n+3]=o,this.u32[n+4]=a,l[n+5]=i}};function Ao(s){let n=new Uint16Array(s*6);for(let e=0,t=0,r=0;e<s;e++,t+=6,r+=4)n[t]=r,n[t+1]=r+1,n[t+2]=r+2,n[t+3]=r,n[t+4]=r+2,n[t+5]=r+3;return n}var ke={M:0,L:1,Q:2,C:3,Z:4},Po=[2,2,4,6,0],_i={M:0,L:1,Q:2,C:3,Z:4};function Kn(s,n){if(s.length>=n)return s;let e=new Float64Array(Math.max(n,s.length*2,16));return e.set(s),e}var Wn=new Map;function Li(s){if(typeof s!="string")return s;let n=Wn.get(s);if(n)return n;n=[];let e=s.match(/[MLQCZ]|-?\d*\.?\d+(?:e-?\d+)?/gi)??[],t=-1;for(let r=0;r<e.length;){let o=e[r],a=_i[o.toUpperCase()];if(a!==void 0){t=a,r++,a===ke.Z&&n.push(ke.Z);continue}if(t<0||t===ke.Z){r++;continue}let i=Po[t];n.push(t);for(let l=0;l<i;l++)n.push(Number(e[r+l]??0));r+=i,t===ke.M&&(t=ke.L)}return Wn.size>256&&Wn.clear(),Wn.set(s,n),n}var pt={subs:[],count:0},Nr=null,ft=null;function Xn(s,n){let e=ft;e||(e=pt.subs[pt.count]??null,e||pt.subs.push(e={pts:new Float64Array(64),n:0,closed:!1}),e.n=0,e.closed=!1,pt.count++,ft=e);let t=e.n*2;t+2>e.pts.length&&(e.pts=Kn(e.pts,t+2));let r=Nr;r?(e.pts[t]=r[0]*s+r[2]*n+r[4],e.pts[t+1]=r[1]*s+r[3]*n+r[5]):(e.pts[t]=s,e.pts[t+1]=n),e.n++}function Qn(s,n=null,e=1,t=6){let r=Li(s);pt.count=0,ft=null,Nr=n;let o=0,a=0,i=0,l=0,c=e/t;for(let u=0;u<r.length;){let f=r[u++],h=r;if(f===ke.M)ft=null,o=i=h[u],a=l=h[u+1],Xn(o,a);else if(f===ke.L)o=h[u],a=h[u+1],Xn(o,a);else if(f===ke.Q){let b=h[u],y=h[u+1],m=h[u+2],d=h[u+3],x=So((je(b-o,y-a)+je(m-b,d-y))*c);for(let g=1;g<=x;g++){let A=g/x,w=1-A;Xn(w*w*o+2*w*A*b+A*A*m,w*w*a+2*w*A*y+A*A*d)}o=m,a=d}else if(f===ke.C){let b=h[u],y=h[u+1],m=h[u+2],d=h[u+3],x=h[u+4],g=h[u+5],A=So((je(b-o,y-a)+je(m-b,d-y)+je(x-m,g-d))*c);for(let w=1;w<=A;w++){let v=w/A,E=1-v,F=E*E*E,L=3*E*E*v,_=3*E*v*v,D=v*v*v;Xn(F*o+L*b+_*m+D*x,F*a+L*y+_*d+D*g)}o=x,a=g}else if(f===ke.Z){ft&&(ft.closed=!0),ft=null,o=i,a=l;continue}else break;u+=Po[f]}ft=null,Nr=null;for(let u=0;u<pt.count;u++){let f=pt.subs[u],h=f.n*2;f.closed&&f.n>=2&&Math.abs(f.pts[0]-f.pts[h-2])<1e-6&&Math.abs(f.pts[1]-f.pts[h-1])<1e-6&&f.n--}return pt}var je=(s,n)=>Math.sqrt(s*s+n*n),So=s=>Math.min(Math.max(Math.ceil(s),2),24);function Ii(s,n){let e=0;for(let t=0,r=n-1;t<n;r=t++)e+=(s[r*2]-s[t*2])*(s[r*2+1]+s[t*2+1]);return e}var jn=new Int32Array(64),qn=(s,n,e,t,r)=>((s[t*2]-s[e*2])*(s[r*2+1]-s[e*2+1])-(s[t*2+1]-s[e*2+1])*(s[r*2]-s[e*2]))*n;function _o(s,n,e){if(n<3)return 0;jn.length<n&&(jn=new Int32Array(Math.max(n,jn.length*2)));let t=jn,r=n,o=0;for(let c=0;c<n;c++)t[c]=c;let a=Ii(s,n)>0?1:-1,i=n*n+8,l=0;for(;r>3&&i-- >0;){let c=t[(l+r-1)%r],u=t[l%r],f=t[(l+1)%r],h=qn(s,a,c,u,f)>0;if(h)for(let b=0;b<r;b++){let y=t[b];if(!(y===c||y===u||y===f)&&qn(s,a,c,u,y)>=0&&qn(s,a,u,f,y)>=0&&qn(s,a,f,c,y)>=0){h=!1;break}}h?(e[o++]=c,e[o++]=u,e[o++]=f,t.copyWithin(l%r,l%r+1,r),r--,l=Math.max(l-1,0)):l=(l+1)%r}if(r===3)e[o++]=t[0],e[o++]=t[1],e[o++]=t[2];else if(r>3)for(let c=1;c+1<r;c++)e[o++]=t[0],e[o++]=t[c],e[o++]=t[c+1];return o}var Oi=.85,Yn=new Float64Array(64),Mo=new Float64Array(64),To=new Float64Array(64),Eo=new Float64Array(64),Ro=new Float64Array(64),Co=new Float64Array(64),Fo=new Uint8Array(64),kn=new Float64Array(8);function Lo(s,n,e,t,r,o){let a=kn;if(Yn.length<n){let d=Math.max(n,Yn.length*2);Yn=new Float64Array(d),Mo=new Float64Array(d),To=new Float64Array(d),Eo=new Float64Array(d),Ro=new Float64Array(d),Co=new Float64Array(d),Fo=new Uint8Array(d)}let i=Yn,l=Mo,c=0;for(let d=0;d<n;d++){let x=s[d*2],g=s[d*2+1];!Number.isFinite(x)||!Number.isFinite(g)||c&&Math.abs(i[c-1]-x)<.001&&Math.abs(l[c-1]-g)<.001||(i[c]=x,l[c]=g,c++)}if(t&&c>2&&Math.abs(i[0]-i[c-1])<.001&&Math.abs(l[0]-l[c-1])<.001&&c--,c===0)return;if(c===1)return a[0]=i[0],a[1]=l[0],o();let u=t?c:c-1,f=To,h=Eo;for(let d=0;d<u;d++){let x=(d+1)%c,g=i[x]-i[d],A=l[x]-l[d],w=je(g,A)||1;f[d]=-A/w,h[d]=g/w}let b=Ro,y=Co,m=Fo;for(let d=0;d<c;d++){let x=t?(d-1+u)%u:d-1,g=d<u?d:-1;if(m[d]=1,x<0||g<0||f[x]*f[g]+h[x]*h[g]<Oi)continue;let w=f[x]+f[g],v=h[x]+h[g],E=je(w,v)||1;w/=E,v/=E;let F=e/Math.max(w*f[g]+v*h[g],.5);b[d]=w*F,y[d]=v*F,m[d]=0}for(let d=0;d<u;d++){let x=(d+1)%c,g=m[d]?f[d]*e:b[d],A=m[d]?h[d]*e:y[d],w=m[x]?f[d]*e:b[x],v=m[x]?h[d]*e:y[x];a[0]=i[d]+g,a[1]=l[d]+A,a[2]=i[x]+w,a[3]=l[x]+v,a[4]=i[x]-w,a[5]=l[x]-v,a[6]=i[d]-g,a[7]=l[d]-A,r()}for(let d=0;d<c;d++)m[d]&&(a[0]=i[d],a[1]=l[d],o())}function Br(s,n){let e=0,t=1/0;for(let r=0;r<n.length;r++){let o=Math.abs(Math.log(Math.max(s,.5)/n[r]));o<t&&(t=o,e=r)}return e}var Zn=[{x:240,y:0,w:8,h:8,r:3},{x:224,y:0,w:16,h:16,r:7},{x:192,y:0,w:32,h:32,r:15},{x:128,y:0,w:64,h:64,r:31},{x:0,y:0,w:128,h:128,r:63}],Jn=[4,8,16,32,64,128].map((s,n)=>({x:n*4,y:128,w:4,h:s,r:s/2-1})),ot={x:248,y:248,w:8,h:8},Oo=Zn.map(s=>s.r*2),No=Jn.map(s=>s.r*2),Io=(s,n)=>Math.min(Math.max(s+.5-n,0),1);function Ni(){let s=new Uint8ClampedArray(262144),n=(e,t,r)=>{let o=(t*256+e)*4;s[o]=s[o+1]=s[o+2]=255,s[o+3]=Math.round(r*255)};for(let e of Zn){let t=e.w/2;for(let r=0;r<e.h;r++)for(let o=0;o<e.w;o++)n(e.x+o,e.y+r,Io(e.r,Math.hypot(o+.5-t,r+.5-t)))}for(let e of Jn){let t=e.h/2;for(let r=0;r<e.h;r++)for(let o=0;o<e.w;o++)n(e.x+o,e.y+r,Io(e.r,Math.abs(r+.5-t)))}for(let e=0;e<ot.h;e++)for(let t=0;t<ot.w;t++)n(ot.x+t,ot.y+e,1);return s}function Bo(){let s=document.createElement("canvas");return s.width=s.height=256,s.getContext("2d").putImageData(new ImageData(Ni(),256,256),0,0),s}var Do=8,er=`
|
|
1
|
+
"use strict";(()=>{var Ps=Object.defineProperty;var Ua=(s,n,e)=>n in s?Ps(s,n,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[n]=e;var Va=(s,n)=>{for(var e in n)Ps(s,e,{get:n[e],enumerable:!0})};var p=(s,n,e)=>Ua(s,typeof n!="symbol"?n+"":n,e);var As={};Va(As,{AnimatedSprite:()=>Ne,Atlas:()=>pt,AvatarPainter:()=>Ct,AvatarsNode:()=>Fn,BitmapFont:()=>Jt,DEFAULT_FONT:()=>Wr,EASE:()=>ht,Group:()=>Rt,HALO:()=>Ft,MAX_LAYERS:()=>xn,NameTags:()=>yt,Node:()=>Ie,NodePool:()=>Pn,Particles:()=>Gt,STAGE_HEIGHT:()=>he,Shape:()=>Xe,ShelfPacker:()=>vn,Sound:()=>nn,Sprite:()=>Te,TIERS:()=>Ke,Text:()=>Ye,Timeline:()=>rn,Tweens:()=>sn,avatarPortrait:()=>Qo,blur:()=>Ca,brightness:()=>wa,colorMatrix:()=>Ra,contrast:()=>va,createAvatarRenderer:()=>Ko,createEngine:()=>da,createRenderer:()=>Kt,dropShadow:()=>Fa,grayscale:()=>Sa,handsOf:()=>lr,hits:()=>Rn,hueRotate:()=>Ta,invert:()=>Ea,nodePool:()=>Ia,packColor:()=>ut,parseBMFont:()=>en,parseColor:()=>de,pickTier:()=>hr,playerColor:()=>tn,rendererOrder:()=>Vr,rng:()=>lo,saturate:()=>Aa,sepia:()=>Ma,shader:()=>Pa,shapeBounds:()=>ar,tier:()=>it,tint:()=>ka,touching:()=>cr,wrists:()=>Yr});var Ar=33,z={nose:0,leftShoulder:11,rightShoulder:12,leftElbow:13,rightElbow:14,leftWrist:15,rightWrist:16,leftHip:23,rightHip:24,leftKnee:25,rightKnee:26,leftAnkle:27,rightAnkle:28},Ls=["3-5","6-8","9-12"],Wa=s=>Ls.includes(s);var Xa=4,hn=["#EE6A43","#6FA0E0","#8CC9A0","#C49BE0"];var Os={"3-5":["bunny","bear","panda","penguin"],"6-8":["fox","lion","dragon","unicorn"],"9-12":["robot","astronaut","ninja","skater"]},ja=Os["6-8"],Sr=(s,n)=>{let e=Wa(n)?Os[n]:ja;return e[Number.isInteger(s)&&s>=0?s%e.length:0]};var Mr=(s,n)=>s?{x:s.x+n.x*s.w,y:s.y+n.y*s.h}:{x:n.x,y:n.y},qa=.5,zn={left:1.6,top:1.6,w:3.2,h:3},Ya=1.2;function Is(s,n,e={}){let t=Array.isArray(s)?s:s.body;if(!Array.isArray(t))return null;let r=n==="left"?z.leftWrist:z.rightWrist,o=x=>un(t[x*3])&&un(t[x*3+1])&&(t[x*3+2]??0)>=qa?x:-1;if(o(r)<0)return null;let a=t[r*3],i=t[r*3+1];if(e.orientation!=="portrait")return Mr(e.view,{x:a,y:i});if(o(z.leftShoulder)<0||o(z.rightShoulder)<0)return null;let u=z.leftShoulder*3,c=z.rightShoulder*3,l=(t[u]+t[c])/2,f=(t[u+1]+t[c+1])/2,h=z.leftHip*3,y=z.rightHip*3,b=(t[h]+t[y])/2,m=(t[h+1]+t[y+1])/2,d=un(b)&&un(m)?Math.hypot(b-l,m-f):0;return(o(z.leftHip)<0||o(z.rightHip)<0)&&(d=Math.max(d,Ya*Math.hypot(t[u]-t[c],t[u+1]-t[c+1]))),d=Math.max(d,.01),{x:_s((a-l+zn.left*d)/(zn.w*d)),y:_s((i-f+zn.top*d)/(zn.h*d))}}var Ka=300,Ot=class{constructor(n=Ka){p(this,"holdMs",n);p(this,"last",new Map)}static key(n,e){return n*2+(e==="right"?1:0)}at(n,e,t){let r=this.last.get(n);return e?(r?(r.x=e.x,r.y=e.y,r.t=t):this.last.set(n,{x:e.x,y:e.y,t}),e):r?t-r.t<=this.holdMs?{x:r.x,y:r.y}:(this.last.delete(n),null):null}clear(){this.last.clear()}},Qa=.25,Ns=Object.freeze({top:0,bottom:0,left:0,right:0});function Ds(s){if(!Za(s))return;let n=e=>un(e)?Math.min(Math.max(e,0),Qa):0;return{top:n(s.top),bottom:n(s.bottom),left:n(s.left),right:n(s.right)}}var Nl=16/9;var Za=s=>typeof s=="object"&&s!==null&&!Array.isArray(s),un=s=>typeof s=="number"&&Number.isFinite(s),_s=s=>Math.min(Math.max(s,0),1);var Ja=12,ei=Ar*4,ti=s=>Ja+s*ei,Dl=ti(Xa);var ni=s=>s.startsWith("fabi-play.")?`fablee-play.${s.slice(10)}`:null;function Bs(s,n,e=ni(n)){if(!(!s||!e))try{let t=s.getItem(e);if(t===null)return;s.getItem(n)===null&&s.setItem(n,t),s.removeItem(e)}catch{}}var Ae="#4a382c",ce="#2b2118",Oe="#1c1f2b",zs="#fbefe3",He="#f4897a",fn="#3a2a22",Tr=[{id:"fox",name:{en:"Fox",it:"Volpe"},band:"6-8",palette:{body:"#ee6a43",limbs:"#ee6a43",belly:zs,accent:"#ffd9c2",outline:ce,hands:"#5a3426",feet:"#5a3426"},head:"wide",ears:"pointy",face:{eyes:"dot",mouth:"cat",nose:fn,muzzle:"cheeks"},tail:"fluffy",headExtras:[],bodyExtras:[]},{id:"mascot",name:{en:"Fabi",it:"Fabi"},band:"all",special:!0,palette:{body:"#ee6a43",limbs:"#ee6a43",belly:zs,accent:"#5a3426",outline:ce,hands:"#5a3426",feet:"#5a3426"},head:"wide",ears:"pointy",face:{eyes:"bead",mouth:"open",nose:fn,muzzle:"band",cheeks:He},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:Ae},head:"round",ears:"long",face:{eyes:"dot",mouth:"cat",nose:"#e0607e",muzzle:"none",cheeks:He},tail:"pom",headExtras:[],bodyExtras:[]},{id:"bear",name:{en:"Bear",it:"Orsetto"},band:"3-5",palette:{body:"#cf9f78",limbs:"#cf9f78",belly:"#f7e0bf",accent:"#f7e0bf",outline:Ae},head:"round",ears:"round",face:{eyes:"dot",mouth:"smile",nose:fn,muzzle:"oval",cheeks:He},tail:"none",headExtras:[],bodyExtras:[]},{id:"cat",name:{en:"Cat",it:"Gattino"},band:"3-5",palette:{body:"#c8b6ee",limbs:"#c8b6ee",belly:"#f4eeff",accent:"#f7b3c8",outline:Ae,hands:"#f4eeff",feet:"#f4eeff"},head:"wide",ears:"pointy",face:{eyes:"big",eyeColor:"#3f9a5a",mouth:"cat",nose:"#f07a9a",muzzle:"none",cheeks:He},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:Ae,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:Ae,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:Ae},head:"wide",ears:"none",face:{eyes:"big",eyesOnTop:!0,mouth:"open",muzzle:"none",cheeks:"#f59b8f"},tail:"none",headExtras:[],bodyExtras:["flippers","spots"],extraColors:["#62ad62","#b0e6a4"]},{id:"lion",name:{en:"Lion",it:"Leoncino"},band:"6-8",alsoIn:["3-5"],palette:{body:"#f6c454",limbs:"#f6c454",belly:"#fde7b0",accent:"#fde7b0",outline:ce},head:"round",ears:"round",face:{eyes:"dot",mouth:"cat",nose:"#8a4b2a",muzzle:"oval",cheeks:He},tail:"tuft",headExtras:["mane"],bodyExtras:[],extraColors:["#c8692e"]},{id:"unicorn",name:{en:"Unicorn",it:"Unicorno"},band:"6-8",palette:{body:"#fbf5ff",limbs:"#fbf5ff",belly:"#efe0ff",accent:"#fbd46a",outline:ce,hands:"#c9a6f2",feet:"#c9a6f2"},head:"tall",ears:"unicorn",face:{eyes:"dot",mouth:"smile",muzzle:"none",cheeks:"#f7a6c8"},tail:"none",headExtras:["rainbow-mane"],bodyExtras:[],extraColors:["#f58cc0","#8fd3f4","#a98ff2"]},{id:"dragon",name:{en:"Little Dragon",it:"Draghetto"},band:"6-8",palette:{body:"#8a63d2",limbs:"#8a63d2",belly:"#fbd46a",accent:"#5fd0b5",outline:ce},head:"wide",ears:"horns",face:{eyes:"big",eyeColor:"#3a2a6a",mouth:"teeth",muzzle:"none",cheeks:"#f59bc0"},tail:"arrow",headExtras:[],bodyExtras:["wings"]},{id:"robot",name:{en:"Robot",it:"Robot"},band:"9-12",palette:{body:"#b9c7d2",limbs:"#8b9aa6",belly:"#b9c7d2",accent:"#ee6a43",outline:Oe,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:Oe,hands:"#9fb0bd",feet:"#9fb0bd"},head:"round",ears:"none",face:{eyes:"visor",mouth:"smile",muzzle:"none"},tail:"none",headExtras:["helmet"],bodyExtras:["backpack","badge","boots"],extraColors:["#c9d3db"]},{id:"dinosaur",name:{en:"Dinosaur",it:"Dinosauro"},band:"6-8",palette:{body:"#3fb3a6",limbs:"#3fb3a6",belly:"#c9f0d6",accent:"#f79a3e",outline:ce},head:"wide",ears:"none",face:{eyes:"dot",mouth:"teeth",muzzle:"none",cheeks:"#f59b8f"},tail:"spiky",headExtras:["spikes","spots"],bodyExtras:[],extraColors:["#2b8f84","#7fd3c6"]},{id:"monkey",name:{en:"Monkey",it:"Scimmietta"},band:"6-8",palette:{body:"#7b5234",limbs:"#7b5234",belly:"#f2c9a0",accent:"#f2c9a0",outline:ce,hands:"#f2c9a0",feet:"#f2c9a0"},head:"round",ears:"side",face:{eyes:"dot",mouth:"open",nose:"#5a3a26",muzzle:"monkey",cheeks:He},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:Ae},head:"wide",ears:"big-round",face:{eyes:"dot",mouth:"smile",nose:"#3b3438",muzzle:"none",cheeks:"#f4a3b0"},tail:"none",headExtras:[],bodyExtras:[]},{id:"tiger",name:{en:"Tiger",it:"Tigrotto"},band:"6-8",palette:{body:"#f9a33a",limbs:"#f9a33a",belly:"#fff1dc",accent:"#fff1dc",outline:ce},head:"wide",ears:"round",face:{eyes:"dot",mouth:"cat",nose:"#e2607a",muzzle:"oval",cheeks:He},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:Ae,feet:"#f9b95c",hands:"#639cc9"},head:"tall",ears:"tufts",face:{eyes:"big",eyeColor:Ae,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:Oe},head:"bulb",ears:"antennae",face:{eyes:"almond",eyeColor:"#1e1838",mouth:"smirk",muzzle:"none"},tail:"none",headExtras:[],bodyExtras:["spots"],extraColors:["#7cc23e","#7cc23e"]},{id:"ghost",name:{en:"Friendly Ghost",it:"Fantasmino"},band:"6-8",palette:{body:"#e6f4ff",limbs:"#e6f4ff",belly:"#e6f4ff",accent:"#bcd9f2",outline:ce},head:"round",ears:"none",face:{eyes:"dot",mouth:"open",muzzle:"none",cheeks:"#f7a6c8"},tail:"none",headExtras:["curl"],bodyExtras:["sheet"]},{id:"octopus",name:{en:"Octopus",it:"Polpetto"},band:"6-8",palette:{body:"#e0578a",limbs:"#e0578a",belly:"#f7b3cc",accent:"#f7b3cc",outline:ce,hands:"#f7b3cc",feet:"#f7b3cc"},head:"tall",ears:"none",face:{eyes:"big",eyeColor:"#3a2140",mouth:"smile",muzzle:"none",cheeks:"#ffd0a0"},tail:"none",headExtras:["spots"],bodyExtras:["tentacles"],extraColors:["#f7b3cc","#f7b3cc"]},{id:"chick",name:{en:"Chick",it:"Pulcino"},band:"3-5",palette:{body:"#ffd45e",limbs:"#ffd45e",belly:"#fff2c2",accent:"#ffa04a",outline:Ae,hands:"#ffc23d",feet:"#ffa04a"},head:"round",ears:"none",face:{eyes:"dot",mouth:"beak",muzzle:"none",cheeks:He},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:Ae,ears:"#b58262",hands:"#e6caa6",feet:"#e6caa6"},head:"wide",ears:"floppy",face:{eyes:"dot",mouth:"open",nose:fn,muzzle:"oval",cheeks:He},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:Ae,skin:"#f7dccb",hands:"#a58c7e",feet:"#a58c7e"},head:"round",ears:"droopy",face:{eyes:"dot",mouth:"smile",nose:"#e591a0",muzzle:"none",cheeks:He},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:Ae,feet:"#ff9f43"},head:"tall",ears:"none",face:{eyes:"dot",mouth:"bill",muzzle:"none",cheeks:He},tail:"none",headExtras:["curl"],bodyExtras:["flippers","scarf"],extraColors:["#86cfe0"]},{id:"shark",name:{en:"Shark",it:"Squalo"},band:"6-8",palette:{body:"#6c95c4",limbs:"#6c95c4",belly:"#eef5fb",accent:"#4c76a8",outline:ce,hands:"#eef5fb",feet:"#4c76a8"},head:"wide",ears:"fin",face:{eyes:"dot",mouth:"jaws",muzzle:"none",cheeks:"#f59bb0"},tail:"fish",headExtras:["gills"],bodyExtras:[]},{id:"wolf",name:{en:"Wolf",it:"Lupo"},band:"6-8",palette:{body:"#8f9bb3",limbs:"#8f9bb3",belly:"#eef1f6",accent:"#f3b8c4",outline:ce,hands:"#5a647a",feet:"#5a647a"},head:"round",ears:"pointy",face:{eyes:"dot",mouth:"open",nose:fn,muzzle:"oval",cheeks:"#f4a3b0"},tail:"fluffy",headExtras:["ruff","forehead"],bodyExtras:[],extraColors:["#636d84"]},{id:"parrot",name:{en:"Parrot",it:"Pappagallo"},band:"6-8",palette:{body:"#e8503f",limbs:"#e8503f",belly:"#ffd25a",accent:"#f6e6c4",outline:ce,hands:"#3a9bdc",feet:"#8a7a70"},head:"round",ears:"none",face:{eyes:"big",eyeColor:ce,eyeRing:"#ffffff",mouth:"hook",muzzle:"none",cheeks:"#ffb0a0"},tail:"plume",headExtras:["crest"],bodyExtras:["feathers"],extraColors:["#ffd25a","#3fae5a","#3a9bdc"]},{id:"ninja",name:{en:"Ninja",it:"Ninja"},band:"9-12",palette:{body:"#2f3a56",limbs:"#2f3a56",belly:"#2f3a56",accent:"#36c9bb",outline:Oe,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:Oe,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:Oe,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:Oe,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:Oe,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:Oe,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:Oe,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:Oe,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:Oe,skin:"#5a3825",hair:"#141010",hands:"#e0403a",feet:"#e0403a"},head:"round",ears:"human",face:{eyes:"calm",mouth:"smirk",muzzle:"none",brows:"#141010"},tail:"none",headExtras:["hair","domino"],bodyExtras:["cape","emblem","boots"],extraColors:["#ffd84a"]},{id:"trex",name:{en:"T-Rex",it:"T-Rex"},band:"6-8",alsoIn:["3-5"],palette:{body:"#6cb84e",limbs:"#6cb84e",belly:"#f4e8a8",accent:"#f4e8a8",outline:ce},head:"snout-long",ears:"none",face:{eyes:"dot",mouth:"toothy",muzzle:"none",cheeks:"#f59b8f"},tail:"thick",headExtras:["stripes"],bodyExtras:["tiny-arms","strong-legs"],extraColors:["#4a9235","#58a23f"]},{id:"fairy",name:{en:"Fairy",it:"Fatina"},band:"6-8",alsoIn:["3-5"],palette:{body:"#b99af0",limbs:"#a8693f",belly:"#b99af0",accent:"#ffd84a",outline:ce,skin:"#a8693f",hair:"#2e1d17",hands:"#a8693f",feet:"#f58cbc"},head:"round",ears:"pixie",face:{eyes:"dot",mouth:"smile",muzzle:"none",cheeks:"#f0857a"},tail:"none",headExtras:["bun","flower-crown"],bodyExtras:["wings-fairy","petals","wand"],extraColors:["#c4ecff","#f7a8cf","#fff3a0","#ffffff"]}];var re={M:0,L:1,Q:2,C:3,Z:4},Hs=[2,2,4,6,0];function It(s,n){for(let e of n)ri(s,e)}function ri(s,n){if(n.k==="group"){s.save(),s.translate(n.x,n.y),n.rot&&s.rotate(n.rot),n.s!==void 0&&n.s!==1&&s.scale(n.s,n.s),n.alpha!==void 0&&(s.globalAlpha*=n.alpha),It(s,n.items),s.restore();return}switch(s.save(),n.alpha!==void 0&&(s.globalAlpha*=n.alpha),s.beginPath(),n.k){case"circle":s.arc(n.x,n.y,Math.max(n.r,0),0,Math.PI*2);break;case"ellipse":s.ellipse(n.x,n.y,Math.max(n.rx,0),Math.max(n.ry,0),n.rot??0,0,Math.PI*2);break;case"rect":si(s,n);break;case"path":typeof n.d=="string"?ai(s,n.d):oi(s,n.d);break;case"line":s.moveTo(n.pts[0]??0,n.pts[1]??0);for(let e=2;e+1<n.pts.length;e+=2)s.lineTo(n.pts[e],n.pts[e+1]);break}s.lineCap="round",s.lineJoin="round",n.fill&&n.k!=="line"&&(s.fillStyle=n.fill,s.fill()),n.stroke&&(n.lw??1)>0&&(s.strokeStyle=n.stroke,s.lineWidth=n.lw??1,s.stroke()),s.restore()}function si(s,n){let e=Math.max(0,Math.min(n.r,n.w/2,n.h/2));s.translate(n.x,n.y),n.rot&&s.rotate(n.rot);let t=-n.w/2,r=-n.h/2;s.moveTo(t+e,r),s.lineTo(t+n.w-e,r),s.quadraticCurveTo(t+n.w,r,t+n.w,r+e),s.lineTo(t+n.w,r+n.h-e),s.quadraticCurveTo(t+n.w,r+n.h,t+n.w-e,r+n.h),s.lineTo(t+e,r+n.h),s.quadraticCurveTo(t,r+n.h,t,r+n.h-e),s.lineTo(t,r+e),s.quadraticCurveTo(t,r,t+e,r),s.closePath()}function oi(s,n){for(let e=0;e<n.length;){let t=n[e++];if(t===re.M)s.moveTo(n[e],n[e+1]);else if(t===re.L)s.lineTo(n[e],n[e+1]);else if(t===re.Q)s.quadraticCurveTo(n[e],n[e+1],n[e+2],n[e+3]);else if(t===re.C)s.bezierCurveTo(n[e],n[e+1],n[e+2],n[e+3],n[e+4],n[e+5]);else if(t===re.Z)s.closePath();else return;e+=Hs[t]}}function Er(s){if(typeof s=="string")return(s.match(/-?\d*\.?\d+(?:e-?\d+)?/gi)??[]).map(Number);let n=[];for(let e=0;e<s.length;){let t=Hs[s[e++]];if(t===void 0)break;for(let r=0;r<t;r++)n.push(s[e+r]);e+=t}return n}function ai(s,n){let e=n.match(/[MLQCZ]|-?\d*\.?\d+(?:e-?\d+)?/gi)??[],t="",r=0,o=()=>Number(e[r++]);for(;r<e.length;){let a=e[r];if(/[MLQCZ]/i.test(a)&&(t=a.toUpperCase(),r++,t==="Z")){s.closePath();continue}t==="M"?(s.moveTo(o(),o()),t="L"):t==="L"?s.lineTo(o(),o()):t==="Q"?s.quadraticCurveTo(o(),o(),o(),o()):t==="C"?s.bezierCurveTo(o(),o(),o(),o(),o(),o()):r++}}var J=s=>{let n=Math.round(s*100)/100;return n===0?0:n};function Q(s,n=.5){let e=s.length;if(e<3)return[];let t=(i,u,c)=>({x:i.x+(u.x-i.x)*c,y:i.y+(u.y-i.y)*c}),r=Math.min(Math.max(n,0),.5),o=t(s[0],s[1],r),a=[re.M,J(o.x),J(o.y)];for(let i=1;i<=e;i++){let u=s[(i-1)%e],c=s[i%e],l=s[(i+1)%e],f=t(u,c,1-r),h=t(c,l,r);a.push(re.L,J(f.x),J(f.y),re.Q,J(c.x),J(c.y),J(h.x),J(h.y))}return a.push(re.Z),a}function K(s,n=1){let e=s.length;if(e<3)return[];let t=[re.M,J(s[0].x),J(s[0].y)],r=n/6;for(let o=0;o<e;o++){let a=s[(o-1+e)%e],i=s[o],u=s[(o+1)%e],c=s[(o+2)%e];t.push(re.C,J(i.x+(u.x-a.x)*r),J(i.y+(u.y-a.y)*r),J(u.x-(c.x-i.x)*r),J(u.y-(c.y-i.y)*r),J(u.x),J(u.y))}return t.push(re.Z),t}function Nt(s){let n=s.length;if(n<2)return[];let e=[re.M,J(s[0].x),J(s[0].y)];for(let t=0;t<n-1;t++){let r=s[Math.max(t-1,0)],o=s[t],a=s[t+1],i=s[Math.min(t+2,n-1)];e.push(re.C,J(o.x+(a.x-r.x)/6),J(o.y+(a.y-r.y)/6),J(a.x-(i.x-o.x)/6),J(a.y-(i.y-o.y)/6),J(a.x),J(a.y))}return e}var tt="M0 -1 L0.29 -0.4 L0.95 -0.31 L0.47 0.15 L0.59 0.81 L0 0.5 L-0.59 0.81 L-0.47 0.15 L-0.95 -0.31 L-0.29 -0.4 Z";var ie="#ffffff",X=[-1,1],$s="#3a2420",Gs="#f2808f",Rr="#26324a",ii="#ffd84a",se=(...s)=>{let n=[];for(let e=0;e+1<s.length;e+=2)n.push({x:s[e],y:s[e+1]});return n};function Hn(s,n){let e=s.palette,t=[],r={stroke:e.outline,lw:n},o=l=>s.headExtras.includes(l),a=(l,f)=>s.extraColors?.[l]??f;if(o("mane")){for(let f=0;f<12;f++){let h=f/12*Math.PI*2;t.push({k:"circle",x:Math.cos(h)*1.02,y:Math.sin(h)*1+.04,r:.42,fill:a(0,e.accent),...r})}t.push({k:"circle",x:0,y:.04,r:1.08,fill:a(0,e.accent)})}if(o("rainbow-mane")){let l=s.extraColors??["#f59ac0","#fbd46a","#8fd3f4"];[[.98,.05,.3,.5,-.25],[.92,.58,.26,.42,-.1],[.62,.92,.22,.32,.4]].forEach(([h,y,b,m,d],x)=>t.push({k:"ellipse",x:h,y,rx:b,ry:m,rot:d,fill:l[x%l.length],...r}))}if(o("spikes"))for(let l of[-.55,0,.55]){let f=vt(l,1.48),h=vt(l-.32,.86),y=vt(l+.32,.86);t.push({k:"path",d:Q([h,f,y],.22),fill:e.accent,...r})}if(o("curl")&&t.push({k:"path",d:K([{x:-.2,y:-.9},{x:-.05,y:-1.3},{x:.32,y:-1.42},{x:.16,y:-1.18},{x:.2,y:-.9}]),fill:e.body,...r}),o("wool"))for(let l=0;l<=8;l++){let f=-1.75+l/8*3.5;t.push({k:"circle",x:Math.sin(f)*.98,y:-Math.cos(f)*.92-.04,r:.34,fill:e.body,...r})}if(o("crest")&&[-.38,0,.38].forEach((l,f)=>{let h=vt(l,1.12);t.push({k:"ellipse",x:h.x,y:h.y,rx:.15,ry:.42,rot:l,fill:a(f,e.accent),...r})}),o("plume")&&t.push({k:"path",d:K(se(-.12,-.92,-.2,-1.42,.1,-1.78,.62,-1.74,.36,-1.46,.16,-.98)),fill:e.accent,...r}),o("locks")&&t.push({k:"path",d:K(se(-1.14,.58,-1.24,-.2,-.86,-.98,0,-1.2,.86,-.98,1.24,-.2,1.14,.58,.8,.66,0,.2,-.8,.66)),fill:e.hair??e.outline,...r}),o("bun")&&t.push({k:"circle",x:.04,y:-1.14,r:.4,fill:e.hair??e.outline,...r}),o("ninja-hood"))for(let[l,f]of[[.35,.5],[.85,.42]])t.push({k:"ellipse",x:1+Math.cos(l)*f*.8,y:-.5+Math.sin(l)*f*.8,rx:f,ry:.11,rot:l,fill:e.accent,...r});if(o("bandana"))for(let[l,f]of[[Math.PI-.5,.42],[Math.PI-1,.36]])t.push({k:"ellipse",x:-.98+Math.cos(l)*f*.8,y:-.36+Math.sin(l)*f*.8,rx:f,ry:.12,rot:l,fill:e.accent,...r});if(o("ruff"))for(let l of X)t.push({k:"path",d:Q(se(l*.7,-.3,l*1.32,0,l*1.02,.18,l*1.26,.46,l*.86,.56,l*.98,.84,l*.4,.7),.25),fill:e.body,...r});if(s.face.eyesOnTop)for(let l of X)t.push({k:"circle",x:l*.46,y:-.72,r:.38,fill:e.body,...r});t.push(...pi(s,n)),t.push(li(s,r));let i=s.face.muzzle,u=e.belly;if(i==="oval"&&t.push({k:"ellipse",x:0,y:.4,rx:.46,ry:.32,fill:u}),i==="monkey"){for(let l of X)t.push({k:"circle",x:l*.32,y:-.04,r:.38,fill:u});t.push({k:"ellipse",x:0,y:.4,rx:.56,ry:.4,fill:u})}if(i==="heart"){for(let l of X)t.push({k:"circle",x:l*.36,y:.02,r:.5,fill:u});t.push({k:"ellipse",x:0,y:.38,rx:.66,ry:.48,fill:u})}if(i==="disc")for(let l of X)t.push({k:"circle",x:l*.4,y:.02,r:.44,fill:u});if(i==="cheeks")for(let l of X)t.push({k:"ellipse",x:l*.4,y:.44,rx:.44,ry:.32,fill:u});if(i==="band"&&t.push({k:"path",d:fi(s,n),fill:u}),o("stripes")&&s.head==="snout-long"){let l=a(0,e.outline);for(let[f,h,y,b]of[[.46,-.94,.36,-.66],[.8,-.72,.62,-.5],[1,-.36,.78,-.24]])t.push({k:"line",pts:[f,h,y,b],stroke:l,lw:.11})}else if(o("stripes")){let l=a(0,e.outline);t.push({k:"line",pts:[0,-.97,0,-.66],stroke:l,lw:.13});for(let f of X)t.push({k:"line",pts:[f*.3,-.93,f*.24,-.7],stroke:l,lw:.1}),t.push({k:"line",pts:[f*.98,-.05,f*.74,0],stroke:l,lw:.1}),t.push({k:"line",pts:[f*.94,.22,f*.74,.22],stroke:l,lw:.09})}if(o("spots")){let l=a(1,e.belly);t.push({k:"circle",x:-.55,y:-.5,r:.15,fill:l}),t.push({k:"circle",x:.58,y:-.42,r:.11,fill:l}),t.push({k:"circle",x:.22,y:-.76,r:.09,fill:l})}if(s.head==="snout-long")for(let[l,f,h]of[[-1.38,-.14,.06],[-1.14,-.22,.055]])t.push({k:"ellipse",x:l,y:f,rx:h,ry:h*.8,rot:-.3,fill:e.outline,alpha:.85});if(o("forehead")&&t.push({k:"path",d:K(se(-.62,-.66,0,-.86,.62,-.66,.26,-.36,0,-.1,-.26,-.36),.9),fill:a(0,e.accent)}),o("eye-spot")&&t.push({k:"ellipse",x:.42,y:-.06,rx:.3,ry:.33,rot:.3,fill:e.ears??e.accent}),o("gills"))for(let l of X)for(let f of[0,.12,.24])t.push({k:"path",d:`M${l*(.66+f)} 0.06 Q${l*(.6+f)} 0.22 ${l*(.66+f)} 0.38`,stroke:e.accent,lw:n*.9});let c=e.hair??e.outline;if(o("hair")&&t.push({k:"path",d:K(se(-1.02,-.06,-1.02,-.58,-.62,-1.04,.08,-1.14,.76,-.92,1.05,-.42,1,-.06,.84,-.4,.42,-.5,.06,-.4,-.34,-.56,-.74,-.38)),fill:c,...r}),o("locks")&&t.push({k:"path",d:K(se(-1,-.08,-.98,-.62,-.56,-1.02,0,-1.1,.56,-1.02,.98,-.62,1,-.08,.8,-.38,.36,-.44,0,-.4,-.36,-.44,-.8,-.38)),fill:c,...r}),o("bun")&&t.push({k:"path",d:K(se(-1.02,-.1,-.98,-.62,-.56,-1.02,0,-1.1,.56,-1.02,.98,-.62,1.02,-.1,.84,-.36,.5,-.56,.12,-.48,-.22,-.6,-.6,-.5,-.86,-.36)),fill:c,...r}),o("curls")){for(let l=0;l<7;l++){let f=vt(-1.3+l/6*2.6,.86);t.push({k:"circle",x:f.x,y:f.y,r:.3,fill:c,...r})}t.push({k:"ellipse",x:0,y:-.64,rx:.8,ry:.36,fill:c})}if(o("ninja-hood")&&(t.push({k:"rect",x:0,y:0,w:1.56,h:.6,r:.28,fill:e.skin??ie,stroke:e.outline,lw:n*.8}),t.push({k:"path",d:"M-0.98 -0.42 Q0 -0.74 0.98 -0.42 L1.0 -0.62 Q0 -0.94 -1.0 -0.62 Z",fill:e.accent,...r})),o("domino")){t.push({k:"path",d:K(se(-.86,-.04,-.62,-.3,-.18,-.24,0,-.16,.18,-.24,.62,-.3,.86,-.04,.6,.22,.16,.16,0,.1,-.16,.16,-.6,.22),.9),fill:e.accent,...r});for(let l of X)t.push({k:"ellipse",x:l*.38,y:0,rx:.19,ry:.13,fill:ie})}if(t.push(...di(s,n)),o("brows"))for(let l of X)t.push({k:"line",pts:[l*.72,-.5,l*.14,-.3],stroke:e.accent,lw:.16});if(s.face.brows)for(let l of X)t.push({k:"line",pts:[l*.2,-.2,l*.54,-.28],stroke:s.face.brows,lw:.09});if(t.push(...mi(s,n)),s.face.cheeks)for(let l of ui(s))t.push({k:"ellipse",x:l.x,y:l.y,rx:.15,ry:.1,fill:s.face.cheeks,alpha:.8});if(o("whiskers"))for(let l of X)for(let f of[-.1,.06])t.push({k:"line",pts:[l*.62,.38+f,l*1.06,.3+f*2.2],stroke:e.outline,lw:n*.7,alpha:.75});if(o("rainbow-mane")){let l=s.extraColors??["#f59ac0","#fbd46a","#8fd3f4"];t.push({k:"ellipse",x:.42,y:-.82,rx:.34,ry:.22,rot:.5,fill:l[0],...r}),t.push({k:"ellipse",x:.1,y:-.92,rx:.3,ry:.2,rot:.25,fill:l[1%l.length],...r})}if(s.ears==="unicorn"){let l=[{x:-.18,y:-.84},{x:.02,y:-1.72},{x:.18,y:-.84}];t.push({k:"path",d:Q(l,.12),fill:e.accent,...r});for(let f of[-1,-1.2,-1.4]){let h=.16*((f+1.72)/.88);t.push({k:"line",pts:[-h,f+.04,h,f-.04],stroke:e.outline,lw:n*.7,alpha:.6})}}if(o("flower-crown")){let l=[a(1,"#f7a8cf"),a(2,"#fff3a0"),a(3,ie)];for(let f of[-.84,-.28,.28,.84]){let h=vt(f,.9);t.push({k:"ellipse",x:h.x,y:h.y,rx:.14,ry:.07,rot:f+.5,fill:"#7cc76a",stroke:e.outline,lw:n*.7})}[-1.12,-.56,0,.56,1.12].forEach((f,h)=>{let y=vt(f,.9),b=h===2?.13:.11;for(let m=0;m<5;m++){let d=f+m/5*Math.PI*2;t.push({k:"circle",x:y.x+Math.sin(d)*b,y:y.y-Math.cos(d)*b,r:b*.82,fill:l[h%l.length],stroke:e.outline,lw:n*.7})}t.push({k:"circle",x:y.x,y:y.y,r:b*.62,fill:l[h%l.length]}),t.push({k:"circle",x:y.x,y:y.y,r:b*.42,fill:e.accent})})}if(o("helmet")){for(let l of X)t.push({k:"rect",x:l*1,y:.05,w:.26,h:.56,r:.12,fill:e.accent,...r});t.push({k:"path",d:"M-0.62 -0.62 Q-0.3 -0.92 0.12 -0.9",stroke:ie,lw:.1,alpha:.9})}if(o("bolts"))for(let l of X)t.push({k:"rect",x:l*1.08,y:.08,w:.2,h:.44,r:.08,fill:e.accent,...r});if(o("tuft")&&t.push({k:"path",d:K([{x:-.26,y:-.95},{x:-.12,y:-1.22},{x:.02,y:-1.04},{x:.16,y:-1.28},{x:.28,y:-.95},{x:0,y:-.86}]),fill:e.body,...r}),o("eggshell")&&t.push({k:"path",d:"M-0.88 -0.5 C-0.88 -1.12 -0.46 -1.42 0 -1.42 C0.46 -1.42 0.88 -1.12 0.88 -0.5 L0.66 -0.66 L0.44 -0.48 L0.22 -0.66 L0 -0.48 L-0.22 -0.66 L-0.44 -0.48 L-0.66 -0.66 Z",fill:a(0,ie),...r}),o("wool"))for(let[l,f]of[[-.36,-.84],[.02,-.94],[.4,-.82]])t.push({k:"circle",x:l,y:f,r:.27,fill:e.body,...r});if(o("stripe")&&t.push({k:"rect",x:0,y:-.64,w:.38,h:.62,r:.06,fill:e.accent}),o("eye-patch")&&(t.push({k:"line",pts:[-.97,-.5,.97,.13],stroke:e.outline,lw:.07}),t.push({k:"ellipse",x:.38,y:.02,rx:.21,ry:.19,fill:e.outline})),o("bandana")){t.push({k:"path",d:K(se(-1.05,-.22,-.96,-.72,-.5,-1.08,.1,-1.14,.72,-.96,1.04,-.56,1.05,-.22,.5,-.46,-.5,-.46)),fill:e.accent,...r});for(let[l,f]of[[-.5,-.8],[.08,-.92],[.6,-.74],[-.12,-.62],[.36,-.6]])t.push({k:"circle",x:l,y:f,r:.06,fill:ie,alpha:.85});t.push({k:"circle",x:-.98,y:-.34,r:.15,fill:e.accent,...r})}if(o("cap")){for(let l of X)t.push({k:"line",pts:[l*.98,-.2,l*.5,.82,-l*.05,.98],stroke:e.outline,lw:.06});t.push({k:"path",d:K(se(-1.1,-.16,-1.04,-.66,-.6,-1.12,0,-1.24,.6,-1.12,1.04,-.66,1.1,-.16,.5,-.4,-.5,-.4)),fill:e.accent,...r}),t.push({k:"path",d:"M-0.74 -0.4 Q0 -0.6 0.74 -0.4 Q0.8 -0.24 0.6 -0.22 Q0 -0.36 -0.6 -0.22 Q-0.8 -0.24 -0.74 -0.4 Z",fill:e.accent,...r}),t.push({k:"circle",x:.5,y:-.82,r:.15,fill:a(0,ie),...r});for(let l of[-.42,-.14])t.push({k:"line",pts:[l,-1.04,l+.02,-.78],stroke:e.outline,lw:.07,alpha:.7})}if(o("safari-hat")&&(t.push({k:"ellipse",x:0,y:-.56,rx:1.48,ry:.3,fill:e.accent,...r}),t.push({k:"path",d:K(se(-.78,-.58,-.7,-1.1,-.3,-1.38,.3,-1.38,.7,-1.1,.78,-.58,0,-.5),.8),fill:e.accent,...r}),t.push({k:"path",d:"M-0.77 -0.72 Q0 -0.62 0.77 -0.72 L0.74 -0.9 Q0 -0.8 -0.74 -0.9 Z",fill:a(1,e.outline),stroke:e.outline,lw:n*.8})),o("wizard-hat")){t.push({k:"ellipse",x:0,y:-.62,rx:1.32,ry:.26,fill:e.accent,...r}),t.push({k:"path",d:Q(se(-.8,-.66,-.36,-1.5,.5,-2.2,.3,-1.46,.8,-.66),.3),fill:e.accent,...r});let l=a(0,ii);for(let[f,h,y]of[[.02,-1.08,.18],[-.38,-.84,.1],[.36,-1.5,.11]])t.push({k:"group",x:f,y:h,s:y,items:[{k:"path",d:tt,fill:l}]})}if(o("dive-mask")){for(let f of X)t.push({k:"line",pts:[f*.7,-.04,f*1,-.12],stroke:e.outline,lw:.2},{k:"line",pts:[f*.7,-.04,f*1,-.12],stroke:e.accent,lw:.11});t.push({k:"rect",x:0,y:0,w:1.42,h:.62,r:.28,fill:"#bfe9f5",alpha:.35}),t.push({k:"rect",x:0,y:0,w:1.42,h:.62,r:.28,stroke:e.outline,lw:.2}),t.push({k:"rect",x:0,y:0,w:1.42,h:.62,r:.28,stroke:e.accent,lw:.11}),t.push({k:"path",d:"M-0.5 -0.16 Q-0.4 -0.24 -0.22 -0.24",stroke:ie,lw:.06,alpha:.9});let l="M0.5 0.52 Q0.98 0.56 1.04 0.1 L1.12 -0.92";t.push({k:"path",d:l,stroke:e.outline,lw:.24},{k:"path",d:l,stroke:e.accent,lw:.13})}return t}function li(s,n){let e=s.headExtras.includes("ninja-hood")?s.palette.body:s.palette.skin??s.palette.body;switch(s.head){case"round":return{k:"circle",x:0,y:0,r:1,fill:e,...n};case"wide":return{k:"ellipse",x:0,y:.03,rx:1.12,ry:.94,fill:e,...n};case"tall":return{k:"ellipse",x:0,y:-.02,rx:.94,ry:1.04,fill:e,...n};case"square":return{k:"rect",x:0,y:0,w:2,h:1.8,r:.46,fill:e,...n};case"bucket":return{k:"path",d:Q(se(-.94,.96,-.98,-.36,-.62,-1.04,.62,-1.04,.98,-.36,.94,.96),.42),fill:e,...n};case"snout-long":return{k:"path",d:K(ci,.95),fill:e,...n};case"bulb":return{k:"path",d:K([{x:0,y:-1.02},{x:.86,y:-.74},{x:1.08,y:-.12},{x:.72,y:.62},{x:0,y:.92},{x:-.72,y:.62},{x:-1.08,y:-.12},{x:-.86,y:-.74}]),fill:e,...n}}}var ci=se(.7,-.88,.12,-1.04,-.3,-.98,-.72,-.74,-1.2,-.56,-1.5,-.32,-1.6,.04,-1.44,.42,-.9,.72,-.2,.92,.5,.88,.96,.56,1.08,0,.98,-.5);function Us(s,n,e){return s.head==="snout-long"?[{x:-.36,y:-.5,k:.95},{x:.26,y:-.48,k:1.1}]:X.map(t=>({x:t*n,y:e,k:1}))}function ui(s){return s.head==="snout-long"?se(-.66,-.14,.66,.1):X.map(n=>({x:n*.64,y:.3}))}function hi(s){return s.head==="round"?{cy:0,rx:1,ry:1}:s.head==="tall"?{cy:-.02,rx:.94,ry:1.04}:{cy:.03,rx:1.12,ry:.94}}function fi(s,n){let{cy:e,rx:t,ry:r}=hi(s),o=t-n/2,a=r-n/2,i=.15,u=Math.asin(Math.min(1,(i-e)/a)),c=Math.cos(u)*o,l=b=>Math.round(b*100)/100||0,f=[re.M,l(-c),i],h=[[-.84*c,.02,-.53*c,.06,-.32*c,.24],[-.17*c,.11,.17*c,.11,.32*c,.24],[.53*c,.06,.84*c,.02,c,i]];for(let b of h)f.push(re.C,...b.map(l));let y=24;for(let b=1;b<=y;b++){let m=u+(Math.PI-2*u)*b/y;f.push(re.L,l(Math.cos(m)*o),l(e+Math.sin(m)*a))}return f.push(re.Z),f}function pi(s,n){let e=s.palette,t={stroke:e.outline,lw:n},r=[];for(let o of X)switch(s.ears){case"pointy":case"unicorn":{let a=s.ears==="unicorn"?.8:1,i={x:o*.3,y:-.82},u={x:o*.86,y:-.82-.62*a},c={x:o*.94,y:-.36};r.push({k:"path",d:Q([i,u,c],.2),fill:e.body,...t});let l={x:(i.x+u.x+c.x)/3,y:(i.y+u.y+c.y)/3},f=[i,u,c].map(h=>({x:l.x+(h.x-l.x)*.55,y:l.y+(h.y-l.y)*.55+.04}));r.push({k:"path",d:Q(f,.25),fill:e.accent});break}case"round":r.push({k:"circle",x:o*.72,y:-.72,r:.36,fill:e.ears??e.body,...t}),e.ears||r.push({k:"circle",x:o*.74,y:-.74,r:.19,fill:e.accent});break;case"big-round":r.push({k:"circle",x:o*.96,y:-.46,r:.52,fill:e.body,...t}),r.push({k:"circle",x:o*1,y:-.44,r:.32,fill:e.accent});break;case"long":r.push({k:"ellipse",x:o*.38,y:-1.42,rx:.25,ry:.68,rot:o*.14,fill:e.body,...t}),r.push({k:"ellipse",x:o*.39,y:-1.36,rx:.12,ry:.48,rot:o*.14,fill:e.accent});break;case"side":r.push({k:"circle",x:o*1,y:.02,r:.34,fill:e.body,...t}),r.push({k:"circle",x:o*1.02,y:.02,r:.2,fill:e.belly});break;case"tufts":r.push({k:"path",d:Q([{x:o*.3,y:-.84},{x:o*1.22,y:-1.12},{x:o*.92,y:-.42}],.16),fill:e.body,...t}),r.push({k:"line",pts:[o*.62,-.78,o*1,-.98],stroke:e.accent,lw:.08});break;case"antennae":{let a={x:o*.62,y:-1.42};r.push({k:"path",d:`M${o*.3} -0.8 Q${o*.36} -1.2 ${a.x} ${a.y}`,stroke:e.outline,lw:n*2.6}),r.push({k:"path",d:`M${o*.3} -0.8 Q${o*.36} -1.2 ${a.x} ${a.y}`,stroke:e.body,lw:n*1.2}),r.push({k:"circle",x:a.x,y:a.y,r:.17,fill:e.accent,...t});break}case"floppy":r.push({k:"ellipse",x:o*.96,y:.02,rx:.3,ry:.62,rot:-o*.36,fill:e.ears??e.body,...t});break;case"droopy":r.push({k:"ellipse",x:o*1.04,y:-.22,rx:.4,ry:.18,rot:o*.32,fill:e.skin??e.body,...t}),r.push({k:"ellipse",x:o*1.08,y:-.2,rx:.24,ry:.08,rot:o*.32,fill:e.accent});break;case"pixie":r.push({k:"path",d:Q(se(o*.86,-.22,o*1.36,-.5,o*1.02,.26),.28),fill:e.skin??e.body,...t}),r.push({k:"line",pts:[o*.98,-.12,o*1.16,-.3],stroke:e.accent,lw:n*.8,alpha:.5});break;case"human":r.push({k:"ellipse",x:o*.98,y:.06,rx:.17,ry:.23,fill:e.skin??e.body,...t});break;case"horns":{let a=[{x:o*.3,y:-.84},{x:o*.6,y:-1.5},{x:o*.66,y:-.68}];r.push({k:"path",d:Q(a,.18),fill:e.accent,...t});break}}return s.ears==="fin"&&r.push({k:"path",d:Q(se(-.4,-.82,.2,-1.62,.46,-.78),.2),fill:e.body,...t}),s.ears==="antenna"&&(r.push({k:"line",pts:[0,-.85,0,-1.42],stroke:e.outline,lw:n*2.6}),r.push({k:"line",pts:[0,-.85,0,-1.42],stroke:e.limbs,lw:n*1.2}),r.push({k:"circle",x:0,y:-1.5,r:.18,fill:e.accent,...t})),r}function di(s,n){let e=s.palette,t=s.face,r=[],o=e.outline,a=t.eyesOnTop?.46:.4,i=t.eyesOnTop?-.72:-.04,u=(c,l,f)=>({k:"circle",x:c,y:l,r:f,fill:ie});switch(t.eyes){case"dot":for(let c of Us(s,a,i))r.push({k:"ellipse",x:c.x,y:c.y,rx:.12*c.k,ry:.155*c.k,fill:o}),r.push(u(c.x+.04*c.k,c.y-.06*c.k,.045*c.k));break;case"bead":for(let c of Us(s,a,i))r.push({k:"ellipse",x:c.x,y:c.y,rx:.16*c.k,ry:.22*c.k,fill:o}),r.push(u(c.x+.05*c.k,c.y-.08*c.k,.065*c.k));break;case"big":for(let c of X)t.eyeRing&&r.push({k:"circle",x:c*a,y:i,r:.36,fill:t.eyeRing,stroke:o,lw:n*.8}),r.push({k:"circle",x:c*a,y:i,r:.25,fill:ie,stroke:o,lw:n*.8}),r.push({k:"circle",x:c*a+c*-.03,y:i+.03,r:.14,fill:t.eyeColor??o}),r.push(u(c*a+c*-.03+.05,i-.03,.05));break;case"mask":for(let c of X)r.push({k:"ellipse",x:c*.4,y:0,rx:.24,ry:.32,rot:c*-.55,fill:e.limbs}),r.push({k:"circle",x:c*.4,y:-.02,r:.11,fill:ie}),r.push({k:"circle",x:c*.39,y:-0,r:.065,fill:o});break;case"screen":r.push({k:"rect",x:0,y:0,w:1.5,h:.66,r:.26,fill:"#24323d",stroke:o,lw:n*.8});for(let c of X)r.push({k:"ellipse",x:c*.36,y:0,rx:.2,ry:.24,fill:t.eyeColor??"#7ff0ff",alpha:.3}),r.push({k:"ellipse",x:c*.36,y:0,rx:.12,ry:.16,fill:t.eyeColor??"#7ff0ff"});break;case"almond":for(let c of X)r.push({k:"ellipse",x:c*.42,y:-.02,rx:.3,ry:.2,rot:-c*.5,fill:t.eyeColor??o}),r.push(u(c*.42-c*.07,-.08,.07));break;case"calm":for(let c of X)r.push({k:"ellipse",x:c*.38,y:.02,rx:.085,ry:.12,fill:o}),r.push(u(c*.38+.03,-.02,.03));break;case"slit":r.push({k:"line",pts:[0,-.98,0,-.2],stroke:o,lw:n*.8,alpha:.5}),r.push({k:"rect",x:0,y:-.04,w:1.56,h:.26,r:.1,fill:Rr,stroke:o,lw:n*.8}),r.push({k:"rect",x:0,y:.3,w:.22,h:.46,r:.08,fill:Rr,stroke:o,lw:n*.8});for(let c of X){r.push({k:"ellipse",x:c*.4,y:-.04,rx:.12,ry:.07,fill:t.eyeColor??ie});for(let l of[.36,.56])r.push({k:"circle",x:c*.42,y:l,r:.05,fill:o,alpha:.6})}break;case"goggle":for(let c of X)r.push({k:"circle",x:c*.9,y:0,r:.13,fill:e.accent,stroke:o,lw:n*.8});r.push({k:"rect",x:0,y:0,w:1.66,h:.62,r:.3,fill:Rr,stroke:o,lw:n*.8}),r.push({k:"path",d:"M-0.6 -0.16 Q-0.42 -0.24 -0.12 -0.24",stroke:ie,lw:.07,alpha:.8});for(let c of X)r.push({k:"path",d:`M${c*.5} 0.04 Q${c*.34} -0.08 ${c*.16} 0.02`,stroke:t.eyeColor??"#7fd6ff",lw:.08});for(let c of[-.18,0,.18])r.push({k:"line",pts:[c,.56,c,.72],stroke:o,lw:n*.8,alpha:.6});break;case"visor":r.push({k:"ellipse",x:0,y:.08,rx:.8,ry:.64,fill:"#2a3f6b",stroke:o,lw:n*.8}),r.push({k:"path",d:"M-0.56 -0.14 Q-0.46 -0.4 -0.16 -0.46",stroke:ie,lw:.08,alpha:.7});for(let c of X)r.push({k:"ellipse",x:c*.28,y:.04,rx:.1,ry:.14,fill:t.eyeColor??"#cfeeff"});break}return r}function mi(s,n){let e=s.palette,t=s.face,r=[],o=t.eyes==="visor"?"#cfeeff":$s,a=n*1.05;switch(t.nose&&t.mouth!=="beak"&&(t.mouth==="cat"?r.push({k:"path",d:Q([{x:-.1,y:.22},{x:.1,y:.22},{x:0,y:.33}],.3),fill:t.nose,stroke:t.nose,lw:n*.6}):s.ears==="big-round"?r.push({k:"ellipse",x:0,y:.22,rx:.2,ry:.25,fill:t.nose}):r.push({k:"ellipse",x:0,y:.25,rx:.13,ry:.085,fill:t.nose})),t.mouth){case"smile":r.push({k:"path",d:t.eyes==="visor"?"M-0.16 0.32 Q0 0.46 0.16 0.32":"M-0.17 0.42 Q0 0.58 0.17 0.42",stroke:o,lw:a});break;case"open":r.push({k:"path",d:"M-0.21 0.4 Q0 0.46 0.21 0.4 Q0.19 0.68 0 0.68 Q-0.19 0.68 -0.21 0.4 Z",fill:o,stroke:o,lw:n*.5}),r.push({k:"ellipse",x:0,y:.6,rx:.1,ry:.06,fill:Gs});break;case"cat":r.push({k:"path",d:"M-0.19 0.4 Q-0.1 0.5 0 0.37 Q0.1 0.5 0.19 0.4",stroke:o,lw:a});break;case"beak":r.push({k:"path",d:Q([{x:-.17,y:.2},{x:.17,y:.2},{x:0,y:.48}],.25),fill:e.accent,stroke:e.outline,lw:n*.8});break;case"teeth":r.push({k:"path",d:"M-0.36 0.34 Q0 0.44 0.36 0.34 Q0.28 0.66 0 0.66 Q-0.28 0.66 -0.36 0.34 Z",fill:o,stroke:o,lw:n*.5});for(let i of X)r.push({k:"rect",x:i*.12,y:.43,w:.1,h:.1,r:.03,fill:ie});break;case"grill":r.push({k:"rect",x:0,y:.56,w:.62,h:.2,r:.08,fill:"#24323d",stroke:e.outline,lw:n*.7});for(let i of[-.15,0,.15])r.push({k:"line",pts:[i,.51,i,.61],stroke:"#9fb0bd",lw:n*.6});break;case"tiny":r.push({k:"ellipse",x:0,y:.44,rx:.08,ry:.1,fill:o});break;case"smirk":r.push({k:"path",d:"M-0.16 0.46 Q0.06 0.54 0.22 0.38",stroke:o,lw:a});break;case"bill":r.push({k:"ellipse",x:0,y:.36,rx:.44,ry:.2,fill:e.accent,stroke:e.outline,lw:n*.8}),r.push({k:"path",d:"M-0.36 0.38 Q0 0.46 0.36 0.38",stroke:e.outline,lw:n*.7});for(let i of X)r.push({k:"circle",x:i*.1,y:.28,r:.03,fill:e.outline});break;case"hook":r.push({k:"ellipse",x:0,y:.48,rx:.16,ry:.11,fill:$s}),r.push({k:"path",d:"M-0.3 0.12 Q0 -0.02 0.3 0.12 Q0.36 0.52 0.04 0.76 Q0.08 0.52 -0.08 0.46 Q-0.28 0.38 -0.3 0.12 Z",fill:e.accent,stroke:e.outline,lw:n*.8});break;case"toothy":{r.push({k:"path",d:"M-1.4 0.1 Q-0.5 0.36 0.5 0.2 Q0.64 0.16 0.68 0.02 Q0.78 0.28 0.52 0.38 Q-0.4 0.78 -1.3 0.26 Z",fill:o,stroke:o,lw:n*.6}),r.push({k:"ellipse",x:-.38,y:.5,rx:.24,ry:.08,fill:Gs});for(let i of[.12,.27,.42,.57,.72,.86]){let u=(1-i)*(1-i)*-1.4+2*(1-i)*i*-.5+i*i*.5,c=(1-i)*(1-i)*.1+2*(1-i)*i*.36+i*i*.2-.01;r.push({k:"path",d:Q(se(u-.08,c,u+.08,c,u,c+.14),.3),fill:ie})}for(let i of[.3,.7]){let u=(1-i)*(1-i)*.52+2*(1-i)*i*-.4+i*i*-1.3,c=(1-i)*(1-i)*.38+2*(1-i)*i*.78+i*i*.26+.01;r.push({k:"path",d:Q(se(u-.07,c,u+.07,c,u,c-.12),.3),fill:ie})}break}case"jaws":{r.push({k:"path",d:"M-0.5 0.3 Q0 0.5 0.5 0.3 Q0.38 0.72 0 0.72 Q-0.38 0.72 -0.5 0.3 Z",fill:o,stroke:o,lw:n*.5});for(let i of[-.34,-.17,0,.17,.34]){let u=.3+.4*(i+.5)*(.5-i)-.01;r.push({k:"path",d:Q(se(i-.075,u,i+.075,u,i,u+.13),.15),fill:ie})}break}}return r}var vt=(s,n)=>({x:Math.sin(s)*n,y:-Math.cos(s)*n});var qs=.5,We={leftEye:2,rightEye:5,leftEar:7,rightEar:8},nt={"3-5":{head:.75,neck:.74,arm:.3,leg:.36,hand:.19,foot:1.2,shoulderMin:.4,shoulderPad:.07,hipMin:.5,hipPad:.22,bottom:.26,bulge:1.12,armsOverHead:!0},"6-8":{head:.6,neck:.78,arm:.22,leg:.28,hand:.15,foot:1,shoulderMin:.34,shoulderPad:.04,hipMin:.4,hipPad:.16,bottom:.14,bulge:1.04,armsOverHead:!1},"9-12":{head:.5,neck:.92,arm:.17,leg:.21,hand:.125,foot:.9,shoulderMin:.36,shoulderPad:.07,hipMin:.32,hipPad:.08,bottom:.1,bulge:1,armsOverHead:!1}},$n="6-8",Un=(s,n)=>n!==void 0&&s.band!=="all"&&s.alsoIn?.includes(n)&&n in nt?n:s.band in nt?s.band:$n,yi=nt[$n].head,Ys=.3,Ks=.12,bi=.9,Vs=.5,Ws=.65,xi=.35,gi=.2,ki=.25,$e=(s,n)=>({x:s.x-n.x,y:s.y-n.y}),te=(s,n)=>({x:s.x+n.x,y:s.y+n.y}),Z=(s,n)=>({x:s.x*n,y:s.y*n}),At=s=>Math.hypot(s.x,s.y),Xs=(s,n)=>({x:(s.x+n.x)/2,y:(s.y+n.y)/2}),Gn=s=>{let n=At(s);return n>1e-9?{x:s.x/n,y:s.y/n}:{x:0,y:1}},wi=(...s)=>s.every(Number.isFinite),vi=s=>Math.atan2(Math.sin(s),Math.cos(s)),Ai=(s,n,e)=>Math.min(Math.max(s,n),e);function Qs(s,n,e=!1){return t=>{let r=s[t*3],o=s[t*3+1],a=s[t*3+2];return r===void 0||o===void 0||a===void 0||!wi(r,o,a)?{x:0,y:0,ok:!1}:{x:n.x+(e?1-r:r)*n.w,y:n.y+o*n.h,ok:a>=qs}}}function Dt(s,n,e={}){let t=Qs(s,n,e.mirrored),r=t(z.leftShoulder),o=t(z.rightShoulder);if(!r.ok||!o.ok)return null;let a=t(z.leftHip),i=t(z.rightHip),u=Xs(r,o),c=At($e(o,r)),l=a.ok&&i.ok,f=Gn($e(o,r));c<1e-6&&(f={x:1,y:0});let h,y,b;if(l){let R=Xs(a,i);y=At($e(R,u)),y>=c*ki?h=Gn($e(R,u)):(h={x:-f.y,y:f.x},h.y<0&&(h=Z(h,-1))),b=Math.max(y,c*1.15)}else h={x:-f.y,y:f.x},h.y<0&&(h=Z(h,-1)),b=c*1.15,y=b;b=Math.max(b,1e-6);let m={x:h.y,y:-h.x},d=Math.atan2(m.y,m.x),x=Z(h,-1),g=nt[e.band??$n]??nt[$n],A=g.head*b,w=te(u,Z(x,A*g.neck)),v=t(z.nose);if(v.ok){let R=te(v,Z(x,A*.15)),F=Z($e(R,w),xi),O=Math.min(1,A*gi/Math.max(At(F),1e-6));w=te(w,Z(F,O))}return{S:u,r:m,d:h,U:b,L:y,hipsOk:l,head:w,headR:A,headRot:d+Si(s,t,d,b),angle:d}}function Si(s,n,e,t){let r=[[We.leftEar,We.rightEar],[We.leftEye,We.rightEye]];for(let[o,a]of r){let i=n(o),u=n(a);if(!i.ok||!u.ok||!(s[o*3+2]>=Ws&&s[a*3+2]>=Ws)||At($e(u,i))<t*.05)continue;let c=vi(Math.atan2(u.y-i.y,u.x-i.x)-e),l=Math.max(Math.abs(c)-Ks,0),f=Ai((bi+Vs-Math.abs(c))/Vs,0,1);return Math.sign(c)*Math.min(l,Ys)*f}return 0}function pn(s,n,e,t={}){let r=Un(n,t.band),o=nt[r],a=Dt(s,e,{...t,band:r});if(!a)return[];let i=Qs(s,e,t.mirrored),u=n.palette,{S:c,r:l,d:f,U:h,L:y}=a,b=S=>n.bodyExtras.includes(S),m=Math.max(1.2,h*.045),d={stroke:u.outline,lw:m},x=(S,L)=>({x:c.x+l.x*S+f.x*L,y:c.y+l.y*S+f.y*L}),g=S=>S.map(([L,N])=>x(L,N)),A=i(z.leftShoulder),w=i(z.rightShoulder),v=i(z.leftHip),R=i(z.rightHip),F=At($e(w,A)),O=a.hipsOk?At($e(R,v)):F*.7,_=Math.max(F/2+o.shoulderPad*h,o.shoulderMin*h),B=Math.max(O/2+o.hipPad*h,o.hipMin*h),$=-.1*h,W=y+o.bottom*h,U=[],me=[],G=[],oe=[],ye=[],De=(S,L,N,q)=>{let j=L.flatMap(ae=>[ae.x,ae.y]);S.push({k:"line",pts:j,stroke:u.outline,lw:N+m*2}),S.push({k:"line",pts:j,stroke:q,lw:N})},mr=o.leg*h*(b("strong-legs")?1.3:1),ke=o.arm*h*(b("tiny-arms")?.6:1),Be=Math.max(o.arm/.22,.9);if(a.hipsOk)for(let[S,L,N,q]of[[v,z.leftKnee,z.leftAnkle,-1],[R,z.rightKnee,z.rightAnkle,1]]){let j=i(L),ae=i(N);if(!j.ok)continue;let Ze=te(S,Z(f,-.12*h)),Ce=ae.ok?[Ze,j,ae]:[Ze,j];De(me,Ce,mr,u.limbs),b("joints")&&me.push({k:"circle",x:j.x,y:j.y,r:.15*h*Be,fill:u.accent,...d}),ae.ok&&me.push(...Ei(n,ae,a,q,m,o.foot))}for(let[S,L,N,q]of[[A,z.leftElbow,z.leftWrist,-1],[w,z.rightElbow,z.rightWrist,1]]){let j=i(L),ae=i(N);if(b("pauldrons")){let Fe=te(S,Z(f,.02*h));oe.push({k:"ellipse",x:Fe.x,y:Fe.y,rx:.25*h,ry:.17*h,rot:a.angle+q*.25,fill:u.body,...d});let Pe=te(Fe,Z(f,.05*h));oe.push({k:"ellipse",x:Pe.x,y:Pe.y,rx:.17*h,ry:.07*h,rot:a.angle+q*.25,fill:u.belly})}if(!j.ok)continue;let Ce=o.armsOverHead&&(j.x-c.x)*f.x+(j.y-c.y)*f.y<-.25*h?ye:oe,on=te(S,Z(f,.04*h));if(De(Ce,ae.ok?[on,j,ae]:[on,j],ke,u.limbs),b("joints")&&Ce.push({k:"circle",x:j.x,y:j.y,r:.13*h*Be,fill:u.accent,...d}),!ae.ok)continue;let we=Gn($e(ae,j)),Je=te(ae,Z(we,.05*h));if(b("feathers"))for(let Fe of[-.55,0,.55]){let Pe=Math.cos(Fe),et=Math.sin(Fe)*q,_e={x:we.x*Pe-we.y*et,y:we.x*et+we.y*Pe},bt=te(Je,Z(_e,.16*h));Ce.push({k:"ellipse",x:bt.x,y:bt.y,rx:.2*h,ry:.09*h,rot:Math.atan2(_e.y,_e.x),fill:u.hands??u.accent,...d})}b("wand")&&q===1&&!t.portrait&&Ce.push(...Fi(n,Je,Gn(te(Z(we,.4),$e(Z(l,.6),f))),h,m));let Ve=o.hand*h*(b("tiny-arms")?.72:1);if(b("tiny-arms"))for(let Fe of[-.45,.45]){let Pe=Math.cos(Fe),et=Math.sin(Fe),_e={x:we.x*Pe-we.y*et,y:we.x*et+we.y*Pe},bt=te(Je,Z(_e,Ve*.75)),yr=te(Je,Z(_e,Ve*1.6)),xt={x:-_e.y*Ve*.32,y:_e.x*Ve*.32};Ce.push({k:"path",d:Q([te(bt,xt),yr,$e(bt,xt)],.2),fill:u.belly,...d})}Ce.push({k:"circle",x:Je.x,y:Je.y,r:Ve,fill:u.hands??u.limbs,...d})}if(b("wings"))for(let S of[-1,1]){let L=g([[S*_*.5,.05*h],[S*(_+.85*h),-.6*h],[S*(_+.72*h),.05*h],[S*(_+.45*h),-.02*h],[S*(_+.3*h),.32*h],[S*_*.6,.55*h]]);U.push({k:"path",d:Q(L,.18),fill:u.accent,...d})}if(b("wings-fairy")&&U.push(...Pi(n,x,_,h,m)),b("cape")){let S=y+.8*h,L=B+.36*h,N=g([[-_*.92,$+.04*h],[_*.92,$+.04*h],[_+.16*h,y*.5],[L,S],[L*.5,S-.1*h],[0,S],[-L*.5,S-.1*h],[-L,S],[-_-.16*h,y*.5]]);U.push({k:"path",d:K(N,.6),fill:u.accent,...d})}if(b("backpack")){let S=x(0,.35*h);U.push({k:"rect",x:S.x,y:S.y,w:_*2+.34*h,h:.8*h,r:.16*h,rot:a.angle,fill:n.extraColors?.[0]??u.limbs,...d})}if(b("tank")){let S=x(_*.95,.24*h),L=n.extraColors?.[0]??u.accent,N=x(_*.95,-.3*h);U.push({k:"rect",x:N.x,y:N.y,w:.14*h,h:.16*h,r:.04*h,rot:a.angle,fill:u.outline}),U.push({k:"rect",x:S.x,y:S.y,w:.34*h,h:1*h,r:.17*h,rot:a.angle,fill:L,...d})}if(a.hipsOk&&!t.portrait&&U.push(...Ci(n,a,B,m)),b("tentacles")&&a.hipsOk)for(let S of[-1,1]){let L=g([[S*B*.7,y*.9],[S*(B+.22*h),y+.3*h],[S*(B+.48*h),y+.22*h],[S*(B+.5*h),y-.02*h],[S*(B+.34*h),y-.06*h]]);U.push({k:"path",d:Nt(L),stroke:u.outline,lw:.2*h+m*2}),U.push({k:"path",d:Nt(L),stroke:u.limbs,lw:.2*h})}let be=Math.max(_,B)*o.bulge;if(b("wool")){for(let[L,N]of[[_*.7,$+.02*h],[be,y*.3],[be*1.02,y*.62],[(be+B)/2,y*.92],[B*.55,W]])for(let q of[-1,1]){let j=x(q*L,N);G.push({k:"circle",x:j.x,y:j.y,r:.2*h,fill:u.body,...d})}let S=x(0,W+.02*h);G.push({k:"circle",x:S.x,y:S.y,r:.2*h,fill:u.body,...d})}if(b("robe")){let S=y+.58*h,L=B*1.4;G.push({k:"path",d:K(g([[-_,$],[0,$-.04*h],[_,$],[be,y*.55],[L,S],[0,S+.06*h],[-L,S],[-be,y*.55]]),.7),fill:u.body,...d});let N=g([[-L*.94,S-.1*h],[0,S-.04*h],[L*.94,S-.1*h]]);G.push({k:"path",d:Nt(N),stroke:n.extraColors?.[0]??u.accent,lw:.07*h})}else if(b("sheet")){let S=y+.78*h,L=B*1.3;G.push({k:"path",d:K(g([[-_,$],[_,$],[be,y*.55],[L,S],[L*.5,S-.2*h],[0,S],[-L*.5,S-.2*h],[-L,S],[-be,y*.55]]),.9),fill:u.body,...d})}else G.push({k:"path",d:K(g([[-_,$],[0,$-.04*h],[_,$],[be,y*.55],[B,W],[0,W+.03*h],[-B,W],[-be,y*.55]]),.85),fill:u.body,...d});let fe=Math.min(_,B);if(b("pocket")){let S=x(0,y*.74);G.push({k:"rect",x:S.x,y:S.y,w:fe*1.3,h:.3*h,r:.1*h,rot:a.angle,fill:u.belly,stroke:u.outline,lw:m*.8})}else if(b("racing-stripe"))for(let S of[-.1,.1]){let L=x(S*h,$+.02*h),N=x(S*h,W-.04*h);G.push({k:"line",pts:[L.x,L.y,N.x,N.y],stroke:u.belly,lw:.1*h})}else if(u.belly&&u.belly!==u.body&&!b("panel")&&!b("sheet")&&!b("stripes")){let S=x(0,y*.58);G.push({k:"ellipse",x:S.x,y:S.y,rx:fe*.64,ry:Math.max(y*.36,.2*h),rot:a.angle,fill:u.belly})}if(b("spots")){let S=n.extraColors?.[1]??u.belly;for(let[L,N,q]of[[-.55,.35,.09],[.5,.62,.11],[-.35,.86,.07]]){let j=x(L*fe,N*y);G.push({k:"circle",x:j.x,y:j.y,r:q*h,fill:S})}}if(b("stripes")){let S=n.extraColors?.[1]??u.accent;for(let L of[.22,.44,.66]){let N=x(-fe*.98,y*L),q=x(fe*.98,y*L);G.push({k:"line",pts:[N.x,N.y,q.x,q.y],stroke:S,lw:.1*h})}}if(b("straps")){let S=n.extraColors?.[1]??u.outline;for(let L of[-1,1]){let N=x(L*_*.62,$+.02*h),q=x(L*fe*.62,y*.72);G.push({k:"line",pts:[N.x,N.y,q.x,q.y],stroke:u.outline,lw:.13*h+m*2}),G.push({k:"line",pts:[N.x,N.y,q.x,q.y],stroke:S,lw:.13*h})}}if(b("belt")){let S=x(0,y*.9);G.push({k:"rect",x:S.x,y:S.y,w:B*1.92,h:.17*h,r:.06*h,rot:a.angle,fill:n.extraColors?.[2]??"#4a3426",...d}),G.push({k:"rect",x:S.x,y:S.y,w:.2*h,h:.19*h,r:.04*h,rot:a.angle,fill:"#ffd84a",...d})}if(b("emblem")){let S=x(0,y*.4),L=n.extraColors?.[0]??u.accent,N=Q([{x:-.22,y:-.2},{x:.22,y:-.2},{x:.22,y:.04},{x:0,y:.26},{x:-.22,y:.04}],.25);G.push({k:"group",x:S.x,y:S.y,rot:a.angle,s:h,items:[{k:"path",d:N,fill:L,stroke:u.outline,lw:m/h},{k:"group",x:0,y:.01,s:.12,items:[{k:"path",d:tt,fill:L===u.accent?"#ffffff":u.accent}]}]})}if(b("panel")){let S=x(0,y*.5);G.push({k:"rect",x:S.x,y:S.y,w:fe*1.2,h:.38*h,r:.1*h,rot:a.angle,fill:"#24323d",...d}),(n.extraColors??["#ff7a6b","#fbd46a","#7ff0ff"]).slice(0,3).forEach((N,q)=>{let j=x((q-1)*fe*.34,y*.5);G.push({k:"circle",x:j.x,y:j.y,r:.075*h,fill:N})})}if(b("badge")){let S=x(-fe*.42,y*.36);G.push({k:"circle",x:S.x,y:S.y,r:.15*h,fill:u.accent,...d}),G.push({k:"group",x:S.x,y:S.y,rot:a.angle,s:.09*h,items:[{k:"path",d:tt,fill:"#ffffff"}]})}if(b("star")){let S=x(-fe*.5,y*.3),L=.15*h;G.push({k:"group",x:S.x,y:S.y,rot:a.angle-.2,s:L,items:[{k:"path",d:tt,fill:n.extraColors?.[0]??"#ffd84a",stroke:u.outline,lw:m*.8/L}]})}if(b("petals")&&G.push(..._i(n,x,_,B,be,y,W,h,m,o)),b("scarf")){let S=Math.max(.04,o.head*(1-o.neck)-.06)*h,L=x(0,S),N=n.extraColors?.[0]??u.accent,q=x(_*.45,S+.28*h);G.push({k:"rect",x:q.x,y:q.y,w:.16*h,h:.42*h,r:.06*h,rot:a.angle+.15,fill:N,...d}),G.push({k:"rect",x:L.x,y:L.y,w:_*2.05,h:.2*h,r:.1*h,rot:a.angle,fill:N,...d})}let ze={k:"group",x:a.head.x,y:a.head.y,rot:a.headRot,s:a.headR,items:Ti(n,m/a.headR)};return[...U,...me,...G,...oe,ze,...ye]}var js=new WeakMap,Mi=64;function Ti(s,n){let e=Number(n.toPrecision(4)),t=js.get(s);t||js.set(s,t=new Map);let r=t.get(e);return r||(t.size>=Mi&&t.clear(),t.set(e,r=Hn(s,e))),r}function Ei(s,n,e,t,r,o){let a=Ri(s,n,e,t,r,o);if(!s.bodyExtras.includes("strong-legs"))return[a];let i=e.U*o,u=te(te(n,Z(e.d,.07*i)),Z(e.r,t*.06*i)),c=[a];for(let l of[-1,0,1]){let f=te(te(u,Z(e.r,l*.12*i)),Z(e.d,.09*i));c.push({k:"ellipse",x:f.x,y:f.y,rx:.05*i,ry:.045*i,rot:e.angle,fill:s.palette.belly,stroke:s.palette.outline,lw:r*.8})}return c}function Ri(s,n,e,t,r,o){let a=s.palette,{d:i,r:u}=e,c=e.U*o,l=te(te(n,Z(i,.07*c)),Z(u,t*.06*c)),f={stroke:a.outline,lw:r},h=a.feet??a.limbs;if(s.bodyExtras.includes("fins")){let y=Q([{x:-.13,y:-.06},{x:.13,y:-.06},{x:.24,y:.46},{x:-.24,y:.46}],.22);return{k:"group",x:l.x,y:l.y,rot:e.angle,s:c,items:[{k:"path",d:y,fill:h,stroke:a.outline,lw:r/c},{k:"line",pts:[0,.06,0,.38],stroke:a.outline,lw:r/c,alpha:.5}]}}return s.bodyExtras.includes("flippers")?{k:"ellipse",x:l.x,y:l.y,rx:.27*c,ry:.11*c,rot:e.angle,fill:h,...f}:s.bodyExtras.includes("boots")?{k:"rect",x:l.x,y:l.y,w:.4*c,h:.24*c,r:.09*c,rot:e.angle,fill:h,...f}:{k:"ellipse",x:l.x,y:l.y,rx:.2*c,ry:.13*c,rot:e.angle,fill:h,...f}}function Ci(s,n,e,t){let r=s.palette,{U:o,L:a,S:i,r:u,d:c}=n,l=(m,d)=>({x:i.x+u.x*m+c.x*d,y:i.y+u.y*m+c.y*d}),f=m=>m.map(([d,x])=>l(d,x)),h={stroke:r.outline,lw:t},y=(m,d,x)=>[{k:"path",d:Nt(m),stroke:r.outline,lw:d+t*2},{k:"path",d:Nt(m),stroke:x,lw:d}],b=[];switch(s.tail){case"none":break;case"fluffy":{let m=f([[e*.5,a*.95],[e+.28*o,a*1],[e+.72*o,a*.62],[e+.78*o,a*.12],[e+.52*o,a*.32],[e+.3*o,a*.6],[e*.6,a*.7]]);b.push({k:"path",d:K(m),fill:r.body,...h});let d=l(e+.72*o,a*.2);b.push({k:"ellipse",x:d.x,y:d.y,rx:.13*o,ry:.2*o,rot:n.angle+.25,fill:r.belly,...h});break}case"brush":{let m=f([[e*.4,a*.98],[e+.42*o,a*1.06],[e+.98*o,a*.66],[e+1.06*o,a*.12],[e+.86*o,-.04*o],[e+.66*o,a*.36],[e+.3*o,a*.66],[e*.5,a*.68]]);b.push({k:"path",d:K(m),fill:r.body,...h});let d=f([[e+1.03*o,a*.36],[e+1.06*o,a*.12],[e+.86*o,-.04*o],[e+.72*o,a*.24],[e+.86*o,a*.34]]);b.push({k:"path",d:K(d),fill:r.belly,...h});break}case"pom":{let m=l(e+.06*o,a*.88);b.push({k:"circle",x:m.x,y:m.y,r:.2*o,fill:r.belly,...h});break}case"long":case"striped":case"tuft":{let m=f([[e*.6,a*.9],[e+.35*o,a*.85],[e+.58*o,a*.4],[e+.5*o,-.02*o]]);if(b.push(...y(m,.14*o,r.body)),s.tail==="tuft"){let d=m[m.length-1];b.push({k:"circle",x:d.x,y:d.y,r:.16*o,fill:s.extraColors?.[0]??r.accent,...h})}if(s.tail==="striped"){for(let x of[.35,.6,.85]){let g=l(e+.35*o+.22999999999999998*o*(x*1.4>1?1:x*1.4),a*(.85-.85*x));b.push({k:"line",pts:[g.x-u.x*.08*o,g.y-u.y*.08*o,g.x+u.x*.08*o,g.y+u.y*.08*o],stroke:s.extraColors?.[0]??r.outline,lw:.06*o})}let d=m[m.length-1];b.push({k:"circle",x:d.x,y:d.y,r:.07*o,fill:s.extraColors?.[0]??r.outline})}break}case"curl":{let m=f([[e*.6,a*.9],[e+.4*o,a*.88],[e+.62*o,a*.45],[e+.5*o,a*.12],[e+.3*o,a*.24],[e+.36*o,a*.42]]);b.push(...y(m,.12*o,r.limbs));break}case"fish":{let m=f([[e*.6,a*.9],[e+.36*o,a*.86],[e+.6*o,a*.5]]);b.push(...y(m,.17*o,r.body));let d=m[m.length-1],x=Q([{x:0,y:.06},{x:-.26,y:-.34},{x:.02,y:-.12},{x:.32,y:-.3}],.2);b.push({k:"group",x:d.x,y:d.y,rot:n.angle+.35,s:o,items:[{k:"path",d:x,fill:r.body,stroke:r.outline,lw:t/o}]});break}case"plume":{let m=s.extraColors??[r.accent];[0,1,2].forEach(d=>{let x=l(e+(.12+d*.13)*o,a+(.32-d*.06)*o);b.push({k:"ellipse",x:x.x,y:x.y,rx:.11*o,ry:.44*o,rot:n.angle-.55+d*.28,fill:m[(d+1)%m.length],...h})});break}case"thick":{let m=f([[e*.3,a*.42],[e+.42*o,a*.62],[e+.92*o,a*.96],[e+1.32*o,a*1.08],[e+1.44*o,a*.98],[e+.98*o,a*1.2],[e+.4*o,a*1.22],[e*.3,a*1.12]]);b.push({k:"path",d:K(m,.8),fill:r.body,...h});let d=s.extraColors?.[0]??r.accent;for(let[x,g,A]of[[.28,.58,.26],[.62,.8,.22],[.96,1,.16]]){let w=l(e+x*o,a*g+.03*o),v=l(e+(x-.1)*o,a*g+A*o);b.push({k:"line",pts:[w.x,w.y,v.x,v.y],stroke:d,lw:.09*o})}break}case"spiky":case"arrow":{let m=f([[e*.3,a*.55],[e+.35*o,a*.68],[e+.95*o,a*.86],[e+.35*o,a*1.08],[e*.3,a*1.08]]);if(s.tail==="spiky"){for(let d of[.15,.45,.72]){let x=e+(.2+d*.7)*o,g=a*(.66+d*.19);b.push({k:"path",d:Q(f([[x-.12*o,g+.05*o],[x,g-.2*o],[x+.12*o,g+.07*o]]),.2),fill:r.accent,...h})}b.push({k:"path",d:K(m,.7),fill:r.body,...h})}else{let d=f([[e*.6,a*.9],[e+.4*o,a*.92],[e+.62*o,a*.5],[e+.62*o,a*.18]]);b.push(...y(d,.13*o,r.body));let x=d[d.length-1];b.push({k:"group",x:x.x,y:x.y,rot:n.angle,s:o,items:[{k:"path",d:Q([{x:-.15,y:.04},{x:0,y:-.22},{x:.15,y:.04}],.2),fill:r.accent,stroke:r.outline,lw:t/o}]})}break}}return b}function Fi(s,n,e,t,r){let o=s.palette,a=te(n,Z(e,-.08*t)),i=te(n,Z(e,.52*t)),u=.2*t;return[{k:"line",pts:[a.x,a.y,i.x,i.y],stroke:o.outline,lw:.06*t+r*2},{k:"line",pts:[a.x,a.y,i.x,i.y],stroke:"#fff3d6",lw:.06*t},{k:"circle",x:i.x,y:i.y,r:.24*t,fill:o.accent,alpha:.28},{k:"group",x:i.x,y:i.y,rot:Math.atan2(e.y,e.x)+Math.PI/2,s:u,items:[{k:"path",d:tt,fill:o.accent,stroke:o.outline,lw:r*.9/u}]}]}function Pi(s,n,e,t,r){let o=s.palette,a=s.extraColors?.[0]??"#cdeeff",i=[];for(let u of[-1,1]){let c=[[[u*e*.3,.12*t],[u*(e+.42*t),-.66*t],[u*(e+1*t),-.74*t],[u*(e+1.02*t),-.18*t],[u*(e+.5*t),.26*t]],[[u*e*.4,.3*t],[u*(e+.6*t),.36*t],[u*(e+.74*t),.78*t],[u*(e+.3*t),.9*t]]];for(let l of c){let f=K(l.map(([m,d])=>n(m,d)),.9);i.push({k:"path",d:f,fill:a,alpha:.6}),i.push({k:"path",d:f,stroke:o.outline,lw:r*.9});let h=l[Math.floor(l.length/2)],y=n(l[0][0],l[0][1]),b=n(l[0][0]+(h[0]-l[0][0])*.75,l[0][1]+(h[1]-l[0][1])*.75);i.push({k:"line",pts:[y.x,y.y,b.x,b.y],stroke:"#ffffff",lw:r*.9,alpha:.85})}for(let[l,f,h]of[[e+.72*t,-.42*t,.075*t],[e+.44*t,-.16*t,.05*t],[e+.5*t,.6*t,.055*t]]){let y=n(u*l,f);i.push({k:"group",x:y.x,y:y.y,s:h,items:[{k:"path",d:tt,fill:"#ffffff"}]})}}return i}function _i(s,n,e,t,r,o,a,i,u,c){let l=s.palette,f=s.extraColors?.[1]??l.belly,h=[],y=Math.atan2(n(1,0).y-n(0,0).y,n(1,0).x-n(0,0).x),b=5,m=Math.max(t,r*.92)*1.08,d=(o*.8+a)/2,x=[0,4,1,3,2];for(let A of x){let w=A/(b-1)-.5,v=n(w*2*m,d+(.5-Math.abs(w))*.1*i);h.push({k:"ellipse",x:v.x,y:v.y,rx:m*.3,ry:.34*i,rot:y-w*.6,fill:A%2?f:l.body,stroke:l.outline,lw:u})}let g=Math.max(.04,c.head*(1-c.neck)-.04)*i;for(let A of[-1,1,0]){let w=n(A*e*.32,g+(A?0:.05*i));h.push({k:"ellipse",x:w.x,y:w.y,rx:e*.26,ry:.12*i,rot:y+A*.5,fill:A?f:l.body,stroke:l.outline,lw:u*.9})}return h}var Li={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 Oi(s,{cx:n=.5,cy:e=.36,T:t=.18}={}){let r={...Li,...s},o=new Array(Ar*3).fill(0),a=(c,[l,f],h=.99)=>{o[c*3]=n+l*t,o[c*3+1]=e+f*t,o[c*3+2]=h};for(let c of Object.keys(z))a(z[c],r[c]);let i=r.tilt??0,u=(c,l)=>[r.nose[0]+c*Math.cos(i)-l*Math.sin(i),r.nose[1]+c*Math.sin(i)+l*Math.cos(i)];return a(We.leftEye,u(-.1,-.08)),a(We.rightEye,u(.1,-.08)),a(We.leftEar,u(-.22,-.02)),a(We.rightEar,u(.22,-.02)),o}var Zs=()=>Oi({});var dn=class{constructor(n={}){p(this,"tracks",new Map);p(this,"offset",NaN);p(this,"lastArrival",NaN);p(this,"interval",33);p(this,"lastT",NaN);p(this,"lostMs");p(this,"maxExtrapolateMs");this.lostMs=n.lostMs??250,this.maxExtrapolateMs=n.maxExtrapolateMs??25}get delayMs(){return this.interval}push(n,e,t,r=Js()){Number.isFinite(e)||(e=r),this.clock(e,r);let o=this.tracks.get(n);if(!o||e-o.tb>this.lostMs||e<o.tb-this.lostMs||t.length!==o.b.length){this.tracks.set(n,{a:null,ta:e,b:t,tb:e,out:null,outAt:NaN});return}if(t===o.b||e<=o.tb){e===o.tb&&t!==o.b&&(o.b=t,o.out=null);return}o.a=o.b,o.ta=o.tb,o.b=t,o.tb=e,o.out=null}at(n,e=Js()){let t=this.tracks.get(n);if(!t)return null;if(!t.a)return t.b;if(t.out&&t.outAt===e)return t.out;let r=e-this.offset-this.interval,o=t.tb-t.ta,a=Math.min(o*.5,this.maxExtrapolateMs),i=Math.min(Math.max((r-t.ta)/o,0),1+a/o);return t.out=eo(t.a,t.b,i),t.outAt=e,t.out}forget(n){this.tracks.delete(n)}clear(){this.tracks.clear()}clock(n,e){let t=e-n;if(!Number.isFinite(this.offset)||t<this.offset||t>this.offset+1e3?this.offset=t:Number.isFinite(this.lastArrival)&&(this.offset+=Math.min(t-this.offset,(e-this.lastArrival)/1e3)),this.lastArrival=e,Number.isFinite(this.lastT)&&n>this.lastT){let r=n-this.lastT;r<this.interval*3+20&&(this.interval+=(Math.min(Math.max(r,8),100)-this.interval)*.1)}n<=this.lastT||(this.lastT=n)}},Js=()=>globalThis.performance?.now()??Date.now();function eo(s,n,e){let t=n.slice(),r=e<.5?s:n;for(let o=0;o+2<n.length;o+=3){let a=s[o],i=s[o+1],u=n[o],c=n[o+1];s[o+2]>=.5&&n[o+2]>=.5&&Math.abs(u-a)+Math.abs(c-i)<.15?(t[o]=a+(u-a)*e,t[o+1]=i+(c-i)*e,t[o+2]=s[o+2]+(n[o+2]-s[o+2])*Math.min(e,1)):(t[o]=r[o],t[o+1]=r[o+1],t[o+2]=r[o+2])}return t}var lc=Tr.map(s=>s.id);var Vn=new Map(Tr.map(s=>[s.id,s])),St=Vn.get("fox"),no=s=>typeof s=="string"&&Vn.has(s),Bt=s=>Vn.get(s);var Ni=s=>typeof s=="string"?Vn.get(s)??St:s;function ro(s,n,e){let t=Ni(s),r=Zs(),o=Un(t,e),a=Dt(r,{x:0,y:0,w:1,h:1},{band:o}),i=oo(Hn(t,.05)),u=-i.minY,c=Math.min(.27,.43/Math.max(u,1))*n,l=t.head==="snout-long"?(i.minX+i.maxX)/2*c:0,f=c/nt[o].head/a.U,h=.5*n+Math.min(0,(u-1.6)*.06*n),y={x:n/2-l-a.head.x*f,y:h-a.head.y*f,w:f,h:f};return pn(r,t,y,{portrait:!0,band:o})}function so(s,n,e=.5){if(!s||s.length!==n.length)return n.slice();let t=n.slice();for(let r=0;r+2<n.length;r+=3){let o=s[r+2],a=n[r+2],i=o>=.5,u=a>=.5;i&&a>=.3&&(t[r+2]=Math.max(a,.5));let c=Math.hypot(n[r]-s[r],n[r+1]-s[r+1]);if(i&&u&&c<.15){let l=e*Math.min(1,to+(1-to)*c/Di);t[r]=s[r]+(n[r]-s[r])*l,t[r+1]=s[r+1]+(n[r+1]-s[r+1])*l}else i&&!u&&t[r+2]>=.5&&(t[r]=s[r],t[r+1]=s[r+1])}return Hi(s,n,t,e*Bi),t}var to=.1,Di=.03,Bi=.35,zi=11;function Hi(s,n,e,t){let r=z.leftShoulder*3,o=z.rightShoulder*3,a=(f,h)=>f[h+2]>=.5;if(!a(s,r)||!a(s,o)||!a(n,r)||!a(n,o))return;let i=(f,h)=>(f[r+h]+f[o+h])/2,u=[i(s,0),i(s,1)],c=[i(n,0),i(n,1)],l=[i(e,0),i(e,1)];for(let f=0;f<zi&&f*3+2<n.length;f++){let h=f*3;if(!a(s,h)||!a(n,h))continue;let y=[s[h]-u[0],s[h+1]-u[1]],b=[n[h]-c[0],n[h+1]-c[1]];Math.hypot(b[0]-y[0],b[1]-y[1])>=.15||(e[h]=l[0]+y[0]+(b[0]-y[0])*t,e[h+1]=l[1]+y[1]+(b[1]-y[1])*t)}}function oo(s){let n={minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0},e=(t,r)=>{n.minX=Math.min(n.minX,t),n.minY=Math.min(n.minY,r),n.maxX=Math.max(n.maxX,t),n.maxY=Math.max(n.maxY,r)};for(let t of s){let r="lw"in t&&t.stroke?(t.lw??1)/2:0;switch(t.k){case"circle":e(t.x-t.r-r,t.y-t.r-r),e(t.x+t.r+r,t.y+t.r+r);break;case"ellipse":case"rect":{let o=t.k==="ellipse"?t.rx:t.w/2,a=t.k==="ellipse"?t.ry:t.h/2,i=Math.max(o,a)+r;e(t.x-i,t.y-i),e(t.x+i,t.y+i);break}case"path":{let o=Er(t.d);for(let a=0;a+1<o.length;a+=2)e(o[a]-r,o[a+1]-r),e(o[a]+r,o[a+1]+r);break}case"line":for(let o=0;o+1<t.pts.length;o+=2)e(t.pts[o]-r,t.pts[o+1]-r),e(t.pts[o]+r,t.pts[o+1]+r);break;case"group":{let o=oo(t.items);if(!Number.isFinite(o.minX))break;let a=t.s??1,i=Math.cos(t.rot??0),u=Math.sin(t.rot??0);for(let[c,l]of[[o.minX,o.minY],[o.maxX,o.minY],[o.minX,o.maxY],[o.maxX,o.maxY]])e(t.x+(c*i-l*u)*a,t.y+(c*u+l*i)*a);break}}}return n}var rt=()=>Float64Array.of(1,0,0,1,0,0);function Se(s,n,e,t,r,o,a){let i=r?Math.cos(r):1,u=r?Math.sin(r):0,c=i*o,l=u*o,f=-u*a,h=i*a;if(!n)return s[0]=c,s[1]=l,s[2]=f,s[3]=h,s[4]=e,s[5]=t,s;let y=n[0],b=n[1],m=n[2],d=n[3];return s[0]=y*c+m*l,s[1]=b*c+d*l,s[2]=y*f+m*h,s[3]=b*f+d*h,s[4]=y*e+m*t+n[4],s[5]=b*e+d*t+n[5],s}function io(s,n,e){let t=s[0]*s[3]-s[1]*s[2];if(Math.abs(t)<1e-12)return null;let r=n-s[4],o=e-s[5];return[(s[3]*r-s[2]*o)/t,(-s[1]*r+s[0]*o)/t]}var ao={white:16777215,black:0,red:16711680,transparent:0},mn=new Map;function de(s){if(typeof s=="number")return[s&16777215,1];let n=mn.get(s);if(n)return n;let e=[16777215,1],t=s.trim().toLowerCase();if(t[0]==="#"){let r=t.slice(1),o=r.length<=4?[...r].map(i=>i+i).join(""):r,a=parseInt(o.slice(0,6),16);Number.isFinite(a)&&(e=[a,o.length===8?parseInt(o.slice(6,8),16)/255:1])}else if(t.startsWith("rgb")){let r=t.match(/-?\d*\.?\d+%?/g)?.map(c=>c.endsWith("%")?parseFloat(c)/100*255:parseFloat(c))??[],[o=255,a=255,i=255]=r,u=r[3]===void 0?1:t.match(/,\s*[\d.]+%\s*\)$/)?r[3]/255:r[3];e=[(Cr(o)<<16|Cr(a)<<8|Cr(i))>>>0,Math.min(Math.max(u,0),1)]}else if(t in ao)e=[ao[t],t==="transparent"?0:1];else if(typeof document<"u"){let r=document.createElement("canvas").getContext("2d");if(r){r.fillStyle="#ffffff",r.fillStyle=t;let o=r.fillStyle;if(o!==t)return mn.set(s,e=de(o)),e}}return mn.size>512&&mn.clear(),mn.set(s,e),e}var Cr=s=>Math.min(Math.max(Math.round(s),0),255);function ut(s,n,e=!1){let t=Math.min(Math.max(n,0),1),r=(s>>16&255)*t,o=(s>>8&255)*t,a=(s&255)*t,i=e?0:t*255;return(Math.round(i)<<24|Math.round(a)<<16|Math.round(o)<<8|Math.round(r))>>>0}var Mt=(s,n=1)=>`rgba(${s>>16&255},${s>>8&255},${s&255},${n})`;function Fr(s,n){if(s===16777215)return n;if(n===16777215)return s;let e=t=>Math.round((s>>t&255)*(n>>t&255)/255);return(e(16)<<16|e(8)<<8|e(0))>>>0}var ht={linear:s=>s,quadIn:s=>s*s,quadOut:s=>s*(2-s),quadInOut:s=>s<.5?2*s*s:-1+(4-2*s)*s,cubicOut:s=>1-(1-s)**3,sineInOut:s=>-(Math.cos(Math.PI*s)-1)/2,backOut:s=>1+(1.70158+1)*(s-1)**3+1.70158*(s-1)**2,elasticOut:s=>s===0||s===1?s:2**(-10*s)*Math.sin((s*10-.75)*(2*Math.PI/3))+1,bounceOut:s=>s<1/2.75?7.5625*s*s:s<2/2.75?7.5625*(s-=1.5/2.75)*s+.75:s<2.5/2.75?7.5625*(s-=2.25/2.75)*s+.9375:7.5625*(s-=2.625/2.75)*s+.984375};function lo(s){let n=s>>>0;return()=>{n=n+1831565813>>>0;let e=n;return e=Math.imul(e^e>>>15,e|1),e^=e+Math.imul(e^e>>>7,e|61),((e^e>>>14)>>>0)/4294967296}}var T={cap:0,epoch:0,x:new Float64Array(0),y:new Float64Array(0),rot:new Float64Array(0),sx:new Float64Array(0),sy:new Float64Array(0),alpha:new Float64Array(0),la:new Float64Array(0),lb:new Float64Array(0),lc:new Float64Array(0),ld:new Float64Array(0),world:new Float64Array(0),tint:new Uint32Array(0),flags:new Uint8Array(0),moved:new Uint8Array(0),dirty:new Uint8Array(0),gen:new Uint32Array(0),parent:new Int32Array(0),first:new Int32Array(0),next:new Int32Array(0),prev:new Int32Array(0),stamp:new Uint32Array(0),pass:0,free:new Int32Array(0),freeHead:0,freeCount:0,top:2},ft=[],$i="x y rot sx sy alpha la lb lc ld world tint flags moved dirty gen parent first next prev stamp".split(" ");function co(s){let n=T;for(let t of $i){let r=n[t],o=new r.constructor(t==="world"?s*6:s);o.set(r),n[t]=o}let e=new Int32Array(s);for(let t=0;t<T.freeCount;t++)e[t]=T.free[(T.freeHead+t)%T.cap];for(T.free=e,T.freeHead=0,T.cap=s,T.epoch++;ft.length<s;)ft.push(null)}function _r(s){T.x[s]=T.y[s]=T.rot[s]=0,T.sx[s]=T.sy[s]=T.alpha[s]=1,T.la[s]=T.ld[s]=1,T.lb[s]=T.lc[s]=0;let n=s*6,e=T.world;e[n]=e[n+3]=1,e[n+1]=e[n+2]=e[n+4]=e[n+5]=0,T.tint[s]=16777215,T.flags[s]=3,T.moved[s]=1,T.dirty[s]=0,T.parent[s]=T.first[s]=T.next[s]=T.prev[s]=-1}co(256);_r(0);T.flags[0]=0;_r(1);T.flags[1]=0;function uo(){let s;if(T.freeCount){s=T.free[T.freeHead],T.freeHead=(T.freeHead+1)%T.cap,T.freeCount--;let n=ft[s];n&&(n._i=0,n._g=-1,ft[s]=null)}else T.top===T.cap&&co(T.cap*2),s=T.top++;return _r(s),s}function Lr(s,n){Wn(s);for(let t=T.first[s];t>=0;){let r=T.next[t];T.parent[t]=T.next[t]=T.prev[t]=-1,t=r}T.first[s]=-1,T.flags[s]=T.flags[s]&-3,T.moved[s]=0;let e=T.gen[s]+1;T.gen[s]=e,e!==4294967295&&(n&&(ft[s]=n),T.free[(T.freeHead+T.freeCount)%T.cap]=s,T.freeCount++)}function ho(s){for(let n=0;n<ft.length;n++){let e=ft[n];e&&s(e)&&(e._i=0,e._g=-1,ft[n]=null)}}function fo(s,n){Wn(s);let e=T.first[n];T.parent[s]=n,T.next[s]=e,T.prev[s]=-1,e>=0&&(T.prev[e]=s),T.first[n]=s,T.moved[s]=1}function Wn(s){let n=T.parent[s];if(n<0)return;let e=T.next[s],t=T.prev[s];t>=0?T.next[t]=e:T.first[n]=e,e>=0&&(T.prev[e]=t),T.parent[s]=T.next[s]=T.prev[s]=-1}var yn={root:-1,gen:-1,world:new Float64Array(6)};function po(s){let n=++T.pass,e=T.world,t=s*6,r=yn.world,o=yn.root!==s||yn.gen!==T.gen[s];for(let a=0;a<6;a++)r[a]!==e[t+a]&&(o=!0),r[a]=e[t+a];yn.root=s,yn.gen=T.gen[s],T.stamp[s]=o?n:n-1}function mo(s){T.stamp[s]=T.pass}function yo(s){for(let n=T.first[s];n>=0;){let e=T.next[n];yo(n),n=e}Lr(s)}var Pr=typeof FinalizationRegistry=="function"?new FinalizationRegistry(s=>T.gen[s.i]===s.g&&yo(s.i)):null;function Or(s){s._reg||!Pr||(s._reg=!0,Pr.register(s,{i:s._i,g:s._g},s))}function bo(s){s._reg&&Pr.unregister(s)}function bn(s){if(s){for(let n=0;n<s.length;n++)if(s[n].enabled)return!0}return!1}function xo(s,n){let e=0;for(let t=0;t<s.length;t++){let r=s[t];r.enabled&&r.pad&&(e+=r.pad(n))}return e}var Me={gl:null,c2d:null,live:null};var Y=new Float64Array(3),xn=4,Gi=1,gn=()=>Gi++;var le=rt(),P=T,Ie=class{constructor(n){p(this,"kernel",n);p(this,"_i",uo());p(this,"_g",P.gen[this._i]);p(this,"_wv",null);p(this,"_wi",-1);p(this,"_we",-1);p(this,"blend","normal");p(this,"_data",null);p(this,"parent",null);p(this,"hitRadius",null);p(this,"clip",null);p(this,"mask",null);p(this,"filters",null);p(this,"_z",0);p(this,"anchorX",0);p(this,"anchorY",0);p(this,"_pool",null);p(this,"_free",!1);p(this,"_reg",!1)}get x(){return P.x[this._i]}set x(n){let e=this._i||1;P.x[e]=n,P.moved[e]=1}get y(){return P.y[this._i]}set y(n){let e=this._i||1;P.y[e]=n,P.moved[e]=1}get rotation(){return P.rot[this._i]}set rotation(n){let e=this._i||1;P.rot[e]=n,P.dirty[e]=P.moved[e]=1}get scaleX(){return P.sx[this._i]}set scaleX(n){let e=this._i||1;P.sx[e]=n,P.dirty[e]=P.moved[e]=1}get scaleY(){return P.sy[this._i]}set scaleY(n){let e=this._i||1;P.sy[e]=n,P.dirty[e]=P.moved[e]=1}get alpha(){return P.alpha[this._i]}set alpha(n){let e=this._i||1;P.alpha[e]=n,P.moved[e]=1}get visible(){return(P.flags[this._i]&1)!==0}set visible(n){let e=this._i||1;n?P.flags[e]=P.flags[e]|1:P.flags[e]=P.flags[e]&-2,P.moved[e]=1}get destroyed(){return P.gen[this._i]!==this._g}get world(){let n=this._i||1;return(this._wi!==n||this._we!==P.epoch)&&(this._wv=P.world.subarray(n*6,n*6+6),this._wi=n,this._we=P.epoch),this._wv}get data(){return this._data??(this._data={})}set data(n){this._data=n}get scale(){return this.scaleX}set scale(n){this.scaleX=this.scaleY=n}get z(){return this._z}set z(n){n!==this._z&&(this._z=n,this.parent&&(this.parent.sortDirty=!0))}get tint(){return P.tint[this._i]}set tint(n){P.tint[this._i||1]=typeof n=="number"?n&16777215:de(n)[0]}set anchor(n){typeof n=="number"?this.anchorX=this.anchorY=n:(this.anchorX=n.x,this.anchorY=n.y)}get width(){return 0}set width(n){}get height(){return 0}set height(n){}set(n){for(let e in n){let t=n[e];t!==void 0&&(this[e]=t)}return this}destroy(){this.destroyed||(this.visible=!1,this.parent&&(this.parent.dead=!0,this.parent=null),Lr(this._i,this),bo(this),this.kernel.tweens.stopAll(this),this._pool?.forget(this))}updateWorld(){let n=this.parent?this.parent.updateWorld():null;return Se(this.world,n,this.x,this.y,this.rotation,this.scaleX,this.scaleY)}draw(n,e,t){}};function vo(s){ho(n=>n.kernel===s)}var Ir=!1,go=Object.freeze([]),Rt=class s extends Ie{constructor(e){super(e);p(this,"children",go);p(this,"sortDirty",!1);p(this,"dead",!1);Or(this)}add(e,...t){this.adopt(e);for(let r=0;r<t.length;r++)this.adopt(t[r]);return e}adopt(e){e.parent&&e.parent.detach(e),e.parent=this,!e.destroyed&&!this.destroyed&&fo(e._i,this._i),this.children===go&&(this.children=[]),this.children.push(e),(e.z!==0||this.sortDirty)&&(this.sortDirty=!0)}remove(e){this.detach(e),e._pool||Or(e)}detach(e){let t=this.children,r=t.indexOf(e);if(r>=0){for(let o=r+1;o<t.length;o++)t[o-1]=t[o];t.pop()}e.parent===this&&(e.parent=null,e.destroyed||Wn(e._i))}clear(){for(let e of this.children)e.destroy()}destroy(){for(let e of this.children)e.destroy();super.destroy()}sweep(){if(this.dead){this.dead=!1;let e=0;for(let t of this.children)t.destroyed?t.parent===this&&(t.parent=null):this.children[e++]=t;this.children.length=e}for(let e of this.children)e instanceof s&&e.sweep()}draw(e,t,r){if(Ir)return P.parent[this._i]<0&&!this.destroyed&&mo(this._i),this.drawChildren(e,t,r);Ir=!0;try{this.destroyed||po(this._i),this.drawChildren(e,t,r)}finally{Ir=!1}}drawChildren(e,t,r){if(this.sortDirty){let u=new Map(this.children.map((c,l)=>[c,l]));this.children.sort((c,l)=>c.z-l.z||u.get(c)-u.get(l)),this.sortDirty=!1}let o=this.children,a=this._i,i=P.stamp[a]===P.pass;for(let u=0;u<o.length;u++){let c=o[u],l=c._i,f=P.alpha[l];if(P.gen[l]!==c._g||!(P.flags[l]&1)||f<=0)continue;if(i||P.moved[l]){P.moved[l]=0,P.stamp[l]=P.pass;let b,m,d,x;if(P.dirty[l]){P.dirty[l]=0;let $=P.rot[l],W=$?Math.cos($):1,U=$?Math.sin($):0,me=P.sx[l],G=P.sy[l];P.la[l]=b=W*me,P.lb[l]=m=U*me,P.lc[l]=d=-U*G,P.ld[l]=x=W*G}else b=P.la[l],m=P.lb[l],d=P.lc[l],x=P.ld[l];let g=P.world,A=P.x[l],w=P.y[l],v=l*6,R=a*6,F=g[R],O=g[R+1],_=g[R+2],B=g[R+3];g[v]=F*b+_*m,g[v+1]=O*b+B*m,g[v+2]=F*d+_*x,g[v+3]=O*d+B*x,g[v+4]=F*A+_*w+g[R+4],g[v+5]=O*A+B*w+g[R+5]}let h=t*f,y=Fr(r,P.tint[l]);c.clip||c.mask||c.filters?Ao(e,c,h,y):c.draw(e,h,y)}}},xe=new Float64Array(128),Tt=0,Nr=new Float64Array(8);function Dr(s,n,e,t){n.clip||n.mask||n.filters?Ao(s,n,e,t):n.draw(s,e,t)}function Ao(s,n,e,t){let r=s.r,o=n.world,a=n.clip,i=!1,u=!1;if(a)if(Math.abs(o[1])<1e-9&&Math.abs(o[2])<1e-9&&Tt<32){let f=o[0]*a.x+o[4],h=o[0]*(a.x+a.width)+o[4],y=o[3]*a.y+o[5],b=o[3]*(a.y+a.height)+o[5],m=Math.min(f,h),d=Math.max(f,h),x=Math.min(y,b),g=Math.max(y,b);if(Tt){let w=(Tt-1)*4;m=Math.max(m,xe[w]),x=Math.max(x,xe[w+1]),d=Math.min(d,xe[w+2]),g=Math.min(g,xe[w+3])}let A=Tt++*4;xe[A]=m,xe[A+1]=x,xe[A+2]=d,xe[A+3]=g,r.clip(m,x,Math.max(d-m,0),Math.max(g-x,0)),u=!0}else i=!0;let c=n.mask&&n.mask.visible?n.mask:null,l=bn(n.filters)?n.filters:null;try{if(i&&r.beginLayer(),c&&r.beginLayer(),l?(n.draw(s,r.beginLayer()?1:e,t),r.endLayer(e,l)):n.draw(s,e,t),c&&(r.beginMask(),Se(c.world,o,c.x,c.y,c.rotation,c.scaleX,c.scaleY),Dr(s,c,c.alpha,16777215),r.endLayer(1)),i&&a){r.beginMask();for(let f=0;f<4;f++){let h=f===1||f===2?a.x+a.width:a.x,y=f>1?a.y+a.height:a.y;Nr[f*2]=o[0]*h+o[2]*y+o[4],Nr[f*2+1]=o[1]*h+o[3]*y+o[5]}r.polygon(Nr,4,16777215,1),r.endLayer(1)}}finally{if(u)if(Tt--,Tt){let f=(Tt-1)*4;r.clip(xe[f],xe[f+1],xe[f+2]-xe[f],xe[f+3]-xe[f+1])}else r.unclip()}}var Te=class extends Ie{constructor(e,t,r){super(e);p(this,"_frame",null);p(this,"_w",null);p(this,"_h",null);p(this,"slice",0);p(this,"autoAnchor",!0);p(this,"frameName",null);t&&(this.frame=t),r?.anchor===void 0&&this.useFrameAnchor(),r&&this.set(r)}get frame(){return this._frame}set frame(e){this.frameName=typeof e=="string"?e:null,this._frame=typeof e=="string"?this.kernel.frame(e):e,this.autoAnchor&&this.useFrameAnchor()}set anchor(e){this.autoAnchor=!1,super.anchor=e}get naturalWidth(){let e=this.frameNow();return e?(e.sw??e.w)/e.scale-e.margin*2:0}get naturalHeight(){let e=this.frameNow();return e?(e.sh??e.h)/e.scale-e.margin*2:0}get width(){return this._w??this.naturalWidth}set width(e){this._w=e}get height(){return this._h??this.naturalHeight}set height(e){this._h=e}sizeQ(e){$t[0]=this._w??(e.sw??e.w)/e.scale-e.margin*2,$t[1]=this._h??(e.sh??e.h)/e.scale-e.margin*2}frameNow(){return this.frameName&&!this.kernel.atlas.valid(this._frame)&&(this._frame=this.kernel.frame(this.frameName)),this._frame}useFrameAnchor(){let e=this._frame;if(!e)return;let t=(e.sw??e.w)/e.scale-e.margin*2,r=(e.sh??e.h)/e.scale-e.margin*2;this.anchorX=t>0?(e.ox-e.margin)/t:0,this.anchorY=r>0?(e.oy-e.margin)/r:0}draw(e,t,r){let o=this.frameNow();if(!o)return;let a=$t;this.sizeQ(o),a[2]=this.anchorX,a[3]=this.anchorY,a[4]=t,Ui(e,o,this.world,this.slice,r,this.blend)}},zt=new Float64Array(12),Ht=new Float64Array(12),kn={x:0,y:0,w:0,h:0};function ko(s,n,e,t,r,o){n=Math.max(n,0),e=Math.max(e,0),t=Math.max(t,0);let a=e+t>r?e*r/(e+t):e,i=e+t>r?t*r/(e+t):t,u=a/o,c=i/o;if(u+c>n){let l=n/(u+c);u*=l,c*=l}s[0]=0,s[1]=u,s[2]=0,s[3]=a,s[4]=u,s[5]=n-u-c,s[6]=a,s[7]=r-a-i,s[8]=n-c,s[9]=c,s[10]=r-i,s[11]=i}var $t=new Float64Array(5);function Ui(s,n,e,t,r,o){let a=$t,i=a[0],u=a[1],c=a[2],l=a[3],f=a[4],h=s.tex(n.surface),y=t===0?n.slice??0:t;if(y===0){let w=(n.sw??n.w)/n.scale-n.margin*2,v=(n.sh??n.h)/n.scale-n.margin*2,R=w>0?i/w:1,F=v>0?u/v:1,O=-c*i+((n.tx??0)/n.scale-n.margin)*R,_=-l*u+((n.ty??0)/n.scale-n.margin)*F;wn(e,O,_),Y[0]=n.w/n.scale*R,Y[1]=n.h/n.scale*F,Y[2]=f,s.r.quadQ(h,n,le,r,o);return}let b=n.tx??0,m=n.ty??0,d=(n.sw??n.w)-n.w-b,x=(n.sh??n.h)-n.h-m,g=-c*i-n.margin+b/n.scale,A=-l*u-n.margin+m/n.scale;if(ko(zt,i+n.margin*2-(b+d)/n.scale,(typeof y=="number"?y:y[3])-b,(typeof y=="number"?y:y[1])-d,n.w,n.scale),ko(Ht,u+n.margin*2-(m+x)/n.scale,(typeof y=="number"?y:y[0])-m,(typeof y=="number"?y:y[2])-x,n.h,n.scale),wn(e,g,A),Y[2]=f,!s.r.nineQ?.(h,n,zt,Ht,le,r,o))for(let w=0;w<12;w+=4){let v=Ht[w+1],R=Ht[w+3];if(!(v<=0||R<=0))for(let F=0;F<12;F+=4){let O=zt[F+1],_=zt[F+3];O<=0||_<=0||(kn.x=n.x+zt[F+2],kn.y=n.y+Ht[w+2],kn.w=_,kn.h=R,wn(e,g+zt[F],A+Ht[w]),Y[0]=O,Y[1]=v,Y[2]=f,s.r.quadQ(h,kn,le,r,o))}}}function wn(s,n,e){le[0]=s[0],le[1]=s[1],le[2]=s[2],le[3]=s[3],le[4]=s[0]*n+s[2]*e+s[4],le[5]=s[1]*n+s[3]*e+s[5]}var Xe=class extends Te{constructor(e,t,r={}){super(e,null);p(this,"_spec");p(this,"baked",null);p(this,"bakedEffects",!0);this._spec=t,this.bake(),r.anchor===void 0&&this.useFrameAnchor(),this.set(r)}get spec(){return this._spec}set spec(e){this._spec=e,this.baked=null,this._w=this._h=null,this.bake()}bake(){let e=this.kernel;return this.baked&&e.atlas.valid(this.baked.frame)&&this.baked.frame.scale===e.pixelScale&&this.bakedEffects===e.effects?this.baked:(this.bakedEffects=e.effects,this.baked=e.shape(this._spec),this._frame=this.baked.frame,this.slice=this.baked.slice,this.baked)}frameNow(){return this.bake().frame}sizeQ(){let e=this.bake();$t[0]=this._w??e.w,$t[1]=this._h??e.h}get width(){return this._w??this.bake().w}set width(e){this._w=e}get height(){return this._h??this.bake().h}set height(e){this._h=e}},wo=(s,n,e)=>s===void 0?n:typeof s=="number"?s:s[0]+(s[1]-s[0])*e(),Et=class Et extends Ie{constructor(e,t,r={}){super(e);p(this,"max");p(this,"f");p(this,"tints");p(this,"count",0);p(this,"gravity");p(this,"drag");p(this,"frameRef");p(this,"random",Math.random);this.frameRef=t,this.max=Math.max(1,Math.floor(r.max??200)),this.f=new Float32Array(this.max*Et.W),this.tints=new Uint32Array(this.max),this.blend=r.blend??"normal",this.gravity=r.gravity??0,this.drag=r.drag??1}get alive(){return this.count}burst(e,t,r,o={}){let a=Et.W,i=this.random,u=o.tint===void 0?16777215:de(o.tint)[0];for(let c=0;c<r;c++){let l=this.count;if(l>=this.max){let d=0,x=1/0;for(let g=0;g<this.max;g++){let A=this.f[g*a+5]-this.f[g*a+4];A<x&&(x=A,d=g)}l=d}else this.count++;let f=(o.angle??0)+(o.spread===void 0?i()*Math.PI*2:(i()-.5)*o.spread),h=wo(o.speed,200,i),y=Array.isArray(o.scale)?o.scale[0]:o.scale??1,b=Array.isArray(o.scale)?o.scale[1]:o.scale??1,m=l*a;this.f[m]=e,this.f[m+1]=t,this.f[m+2]=Math.cos(f)*h,this.f[m+3]=Math.sin(f)*h,this.f[m+4]=0,this.f[m+5]=Math.max(wo(o.life,.8,i),.01),this.f[m+6]=i()*Math.PI*2,this.f[m+7]=(i()-.5)*2*(o.spin??0),this.f[m+8]=y,this.f[m+9]=b,this.f[m+10]=o.alpha??1,this.tints[l]=u}}update(e){let t=Et.W,r=this.f,o=this.drag>=1?1:Math.pow(Math.max(this.drag,0),e);for(let a=0;a<this.count;){let i=a*t;if(r[i+4]=r[i+4]+e,r[i+4]>=r[i+5]){let u=--this.count;a!==u&&(r.copyWithin(i,u*t,u*t+t),this.tints[a]=this.tints[u]);continue}r[i+3]=(r[i+3]+this.gravity*e)*o,r[i+2]=r[i+2]*o,r[i]=r[i]+r[i+2]*e,r[i+1]=r[i+1]+r[i+3]*e,r[i+6]=r[i+6]+r[i+7]*e,a++}}clear(){this.count=0}draw(e,t,r){if(!this.count)return;let o=typeof this.frameRef=="string"?this.frameRef=this.kernel.frame(this.frameRef):this.frameRef,a=Et.W,i=this.f,u=this.world,c=o.w/o.scale,l=o.h/o.scale;for(let f=0;f<this.count;f++){let h=f*a,y=i[h+4]/i[h+5],b=i[h+8]+(i[h+9]-i[h+8])*y,m=t*i[h+10]*(1-y*y),d=i[h+6],x=Math.cos(d)*b,g=Math.sin(d)*b,A=i[h],w=i[h+1],v=u[0],R=u[1],F=u[2],O=u[3],_=v*x+F*g,B=R*x+O*g,$=F*x-v*g,W=O*x-R*g;le[0]=_,le[1]=B,le[2]=$,le[3]=W,le[4]=v*A+F*w+u[4]-(_*c+$*l)/2,le[5]=R*A+O*w+u[5]-(B*c+W*l)/2,Y[0]=c,Y[1]=l,Y[2]=m,e.r.quadQ(e.tex(o.surface),o,le,Fr(r,this.tints[f]),this.blend)}}};p(Et,"W",11);var Gt=Et;var Ne=class extends Te{constructor(e,t,r={}){let{fps:o,loop:a,playing:i,speed:u,onComplete:c,...l}=r;if(!t.frames.length)throw new Error("[engine] an animation needs at least one frame");super(e,t.frames[0],l);p(this,"frames");p(this,"durations");p(this,"fps");p(this,"loop");p(this,"speed");p(this,"onComplete");p(this,"_playing");p(this,"index",0);p(this,"t",0);this.frames=t.frames,this.durations=t.durations&&o===void 0?t.durations:null,this.fps=o??12,this.loop=a!==!1,this.speed=u??1,this.onComplete=c??null,this._playing=i!==!1,this.speed<0&&this.show(t.frames.length-1)}get frameIndex(){return this.index}get frameCount(){return this.frames.length}get playing(){return this._playing}play(){return!this.loop&&!this._playing&&this.index===(this.speed<0?0:this.frames.length-1)&&this.show(this.speed<0?this.frames.length-1:0),this._playing=!0,this}stop(){return this._playing=!1,this}gotoFrame(e){let t=this.frames.length;return this.show((Math.floor(e)%t+t)%t),this.t=0,this}gotoAndPlay(e){return this._playing=!0,this.gotoFrame(e)}gotoAndStop(e){return this._playing=!1,this.gotoFrame(e)}show(e){e===this.index&&this._frame||(this.index=e,this.frame=this.frames[e])}secondsOf(e){let t=this.durations?.[e];return t!==void 0&&t>0?t:1/Math.max(this.fps,.001)}update(e){if(!this._playing||this.destroyed||this.speed===0)return;let t=this.frames.length,r=this.speed<0;this.t+=e*Math.abs(this.speed);let o=this.index;for(let a=0;a<1e3;a++){let i=this.secondsOf(o);if(this.t<i)break;this.t-=i;let u=r?o-1:o+1;if(u<0||u>=t){if(!this.loop){this.t=0,this._playing=!1,this.show(o),this.onComplete?.();return}o=r?t-1:0}else o=u}this.show(o)}},So=(s,n)=>s.localeCompare(n,void 0,{numeric:!0});var vn=class{constructor(n,e,t=2){p(this,"width",n);p(this,"height",e);p(this,"padding",t);p(this,"shelves",[]);p(this,"free",[]);p(this,"bottom",0)}alloc(n,e){let t=Math.ceil(n)+this.padding*2,r=Math.ceil(e)+this.padding*2;if(t>this.width||r>this.height)return null;for(let i=0;i<this.free.length;i++){let u=this.free[i];if(u.w>=t&&u.h>=r&&u.w*u.h<=t*r*2)return this.free.splice(i,1),this.inner(u.x,u.y,n,e)}let o=null;for(let i of this.shelves)i.h>=r&&i.h<=r*1.5+8&&this.width-i.x>=t&&(!o||i.h<o.h)&&(o=i);if(!o)if(this.bottom+r>this.height){for(let i of this.shelves)i.h>=r&&this.width-i.x>=t&&(o=i);if(!o)return null}else o={y:this.bottom,h:r,x:0},this.shelves.push(o),this.bottom+=r;let a=o.x;return o.x+=t,this.inner(a,o.y,n,e)}release(n){this.free.push({x:n.x-this.padding,y:n.y-this.padding,w:Math.ceil(n.w)+this.padding*2,h:Math.ceil(n.h)+this.padding*2})}get fill(){return this.bottom/this.height}reset(){this.shelves=[],this.free=[],this.bottom=0}inner(n,e,t,r){return{x:n+this.padding,y:e+this.padding,w:t,h:r}}},Ut=s=>({source:s,texture:null,pending:[]}),pt=class{constructor(n=2048,e=4){p(this,"pageSize",n);p(this,"maxPages",e);p(this,"pages",[]);p(this,"gen",1);p(this,"onPage",()=>{});p(this,"onDrop",()=>{})}valid(n){return!!n&&(n.gen===this.gen||n.gen===0)}bake(n,e,t,r=1,o=0,a=0,i=0){let u=Math.max(1,Math.ceil(n)),c=Math.max(1,Math.ceil(e)),l=document.createElement("canvas");l.width=u,l.height=c;let f=l.getContext("2d");return t(f),this.put(l,u,c,r,o,a,i)}add(n,e=1,t=0,r=0){let o=document.createElement("canvas");return o.width=Math.max(1,n.width),o.height=Math.max(1,n.height),o.getContext("2d").drawImage(n,0,0),this.put(o,o.width,o.height,e,t,r,0)}release(n){if(n.gen!==this.gen)return;this.pages.find(t=>t.surface===n.surface)?.packer.release(n)}rebake(n,e,t,r,o=n.w,a=n.h){if(!this.valid(n)||e>o||t>a)return null;let i=Math.max(1,Math.ceil(e)),u=Math.max(1,Math.ceil(t)),c=this.pages.find(f=>f.surface===n.surface);if(!c)return null;let l=document.createElement("canvas");return l.width=Math.ceil(o),l.height=Math.ceil(a),r(l.getContext("2d")),c.ctx.clearRect(n.x,n.y,l.width,l.height),c.ctx.drawImage(l,n.x,n.y),n.surface.pending.push([l,n.x,n.y]),n.w=i,n.h=u,n}put(n,e,t,r,o,a,i){let u=null,c=this.pages.find(f=>(u=f.packer.alloc(e,t))!==null);if(c||(!(Math.max(e,t)+4>this.pageSize)&&this.pages.length>=this.maxPages&&(this.wipe(),c=this.pages[0],u=c?c.packer.alloc(e,t):null),(!c||!u)&&(c=this.newPage(Math.max(e,t)),u=c.packer.alloc(e,t))),!u)throw new Error(`[engine] ${e}\xD7${t} does not fit an atlas page`);let l=u;return c.ctx.drawImage(n,l.x,l.y),c.surface.pending.push([n,l.x,l.y]),{surface:c.surface,x:l.x,y:l.y,w:e,h:t,scale:r,gen:this.gen,ox:o,oy:a,margin:i}}newPage(n){let e=this.pageSize;for(;e<n+4;)e*=2;let t=document.createElement("canvas");t.width=t.height=e;let r=t.getContext("2d"),o=Ut(t),a={surface:o,packer:new vn(e,e),ctx:r};return this.pages.push(a),this.onPage(o),a}wipe(){this.gen++;let n=0;for(let e=0;e<this.pages.length;e++){let t=this.pages[e];if(n<this.maxPages&&t.surface.source.width===this.pageSize){this.pages[n++]=t;continue}t.surface.pending=[],this.onDrop(t.surface)}this.pages.length=n;for(let e of this.pages)e.packer.reset(),e.ctx.clearRect(0,0,e.surface.source.width,e.surface.source.height),e.surface.pending=[],e.surface.pending.push([e.surface.source,0,0])}};var Vi=()=>{let s=typeof document<"u"?document.timeline?.currentTime:null;return typeof s=="number"&&Number.isFinite(s)?s:globalThis.performance?.now()??Date.now()},Mo=()=>globalThis.performance?.now()??Date.now(),An=class{constructor(n=Vi){p(this,"now",n);p(this,"known",new Map);p(this,"smoothed",new Map);p(this,"times",new WeakMap);p(this,"lerp",new dn);p(this,"drawnAt",NaN);p(this,"drawn",0);p(this,"smoothedBody",(n,e={})=>{let t=e.interpolate!==!1;if(typeof n=="number"){let r=this.smoothed.get(n);return r?t?this.lerp.at(n,this.tick())??r.body:r.body:null}return typeof n!="object"||n===null||!Array.isArray(n.body)?null:this.posed(n.id,n.body,Wi(e.smooth),t)})}note(n,e,t=Mo()){for(let r of n)this.known.set(r.id,this.resolve(r.id,r.avatar)),e!==void 0&&Number.isFinite(e)&&Array.isArray(r.body)&&this.times.set(r.body,{t:e,arrival:t})}of(n){return typeof n=="object"&&n!==null?n.avatar!==void 0?this.resolve(n.id,n.avatar):this.of(n.id):this.known.get(n)??Sr(n-1)}posed(n,e,t,r=!0){let o=this.smooth(n,e,t);return r?this.lerp.at(n,this.tick())??o:o}smooth(n,e,t){let r=this.smoothed.get(n);if(r&&r.raw===e&&r.amount===t)return r.body;r&&r.amount!==t&&this.lerp.forget(n);let o=t<1?so(r?.body,e,t):e;this.smoothed.set(n,{raw:e,body:o,amount:t});let a=this.times.get(e),i=a?.arrival??Mo();return this.lerp.push(n,a?.t??i,o,i),o}takeDrawn(){let n=this.drawn;return this.drawn=0,n}tick(){let n=this.now();return n!==this.drawnAt&&(this.drawnAt=n,this.drawn++),n}resolve(n,e){return no(e)?e:Sr(n-1)}};var Wi=s=>s===!1?1:typeof s=="number"?Math.min(Math.max(s,.05),1):.5;var Ro=new Float64Array(1),To=new Int32Array(Ro.buffer),Vt=(s,n)=>(s=Math.imul(s^n,1540483477),s^s>>>15);function ot(s,n=2538058380){return s!==s?Vt(n,2146959360):(Ro[0]=s===0?0:s,Vt(Vt(n,To[0]),To[1]))}function Eo(s,n=2166136261){for(let e=0;e<s.length;e++)n=Math.imul(n^s.charCodeAt(e),16777619);return n}function Ge(s){switch(typeof s){case"number":return ot(s);case"string":return Eo(s);case"boolean":return s?1013904242:461845907;case"object":{if(s===null)return 625341585;if(Array.isArray(s)||s instanceof Float64Array){let t=1779033703^s.length;for(let r=0;r<s.length;r++){let o=s[r];t=Vt(t,typeof o=="number"?ot(o):Ge(o))}return t}let n=1359893119,e=s;for(let t in e){let r=e[t];r!==void 0&&(n=n+Vt(Eo(t),Ge(r))|0)}return Vt(n,2600822924)}default:return 0}}function Wt(s,n){if(s===n)return!0;if(typeof s!="object"||typeof n!="object"||s===null||n===null)return typeof s=="number"&&typeof n=="number"&&s!==s&&n!==n;let e=Array.isArray(s)||s instanceof Float64Array;if(e!==(Array.isArray(n)||n instanceof Float64Array))return!1;if(e){let o=s,a=n;if(o.length!==a.length)return!1;for(let i=0;i<o.length;i++)if(o[i]!==a[i]&&!Wt(o[i],a[i]))return!1;return!0}let t=s,r=n;for(let o in t)if(t[o]!==void 0&&!Wt(t[o],r[o]))return!1;for(let o in r)if(r[o]!==void 0&&t[o]===void 0)return!1;return!0}function Sn(s){if(typeof s!="object"||s===null)return s;if(Array.isArray(s))return s.map(Sn);if(s instanceof Float64Array)return s.slice();let n={};for(let e in s)s[e]!==void 0&&(n[e]=Sn(s[e]));return n}var Xt=class{constructor(n=1/0){p(this,"max",n);p(this,"buckets",new Map);p(this,"n",0)}get size(){return this.n}get(n,e=Ge(n)){let t=this.buckets.get(e);if(t){for(let r=0;r<t.length;r++)if(Wt(t[r].key,n))return t[r].value}}set(n,e,t=Ge(n)){let r=this.buckets.get(t);if(r){for(let o of r)if(Wt(o.key,n)){o.value=e;return}}this.n>=this.max&&this.clear(),(!r||!this.buckets.has(t))&&this.buckets.set(t,r=[]),r.push({key:Sn(n),value:e}),this.n++}clear(){this.buckets.clear(),this.n=0}};var Br=0,Co=1,jn=2,zr=3,jt=class{constructor(){p(this,"scale",1);p(this,"cOn",!1);p(this,"px0",0);p(this,"py0",0);p(this,"px1",0);p(this,"py1",0);p(this,"clipVer",0);p(this,"stack",[]);p(this,"sp",0);p(this,"real",0);p(this,"mute",0);p(this,"bnd",new Float64Array(4*(xn+1)));p(this,"rx0",0);p(this,"ry0",0);p(this,"rx1",0);p(this,"ry1",0);p(this,"maxBlur",1/0);p(this,"time",0);p(this,"skipped",0);p(this,"gq",new Float64Array(4))}resetLayers(n){this.scale=n,this.sp=this.real=this.mute=0,this.skipped=0,this.cOn=!1,this.clipVer++}growQ(){let n=this.gq;this.grow(n[0],n[1],n[2],n[3])}grow(n,e,t,r){if(!this.real)return;let o=this.bnd,a=(this.real-1)*4;n<o[a]&&(o[a]=n),e<o[a+1]&&(o[a+1]=e),t>o[a+2]&&(o[a+2]=t),r>o[a+3]&&(o[a+3]=r)}area(n,e){let t=this.bnd,r=n*4,o=this.scale;return this.rx0=Math.max(Math.floor((t[r]-e)*o)-1,0),this.ry0=Math.max(Math.floor((t[r+1]-e)*o)-1,0),this.rx1=Math.min(Math.ceil((t[r+2]+e)*o)+1,this.canvas.width),this.ry1=Math.min(Math.ceil((t[r+3]+e)*o)+1,this.canvas.height),this.rx1>this.rx0&&this.ry1>this.ry0}clip(n,e,t,r){let o=this.scale,a=this.canvas.width,i=this.canvas.height,u=Math.min(Math.max(Math.round(n*o),0),a),c=Math.min(Math.max(Math.round(e*o),0),i),l=Math.min(Math.max(Math.round((n+t)*o),u),a),f=Math.min(Math.max(Math.round((e+r)*o),c),i);this.cOn&&u===this.px0&&c===this.py0&&l===this.px1&&f===this.py1||(this.cOn=!0,this.px0=u,this.py0=c,this.px1=l,this.py1=f,this.clipVer++)}unclip(){this.cOn&&(this.cOn=!1,this.clipVer++)}push(n){if(n<jn&&(this.mute||this.real>=xn||!this.pushLayer())&&(n+=2),n===zr)this.mute++;else if(n!==jn){let e=this.real*4;this.bnd[e]=this.bnd[e+1]=1/0,this.bnd[e+2]=this.bnd[e+3]=-1/0,this.real++}return this.stack[this.sp++]=n,n<jn}beginLayer(){return this.push(Br)}beginMask(){this.push(this.sp&&this.stack[this.sp-1]===Br?Co:zr)}endLayer(n,e){if(!this.sp)return;let t=this.stack[--this.sp];if(t===zr){if(this.mute--,!this.sp)return;t=this.stack[--this.sp]}if(t===Co){let r=--this.real,o=this.popLayer();this.area(r-1,0)&&this.composite(o,!0,1,null);let a=this.bnd,i=(r-1)*4,u=r*4;a[i]=Math.max(a[i],a[u]),a[i+1]=Math.max(a[i+1],a[u+1]),a[i+2]=Math.min(a[i+2],a[u+2]),a[i+3]=Math.min(a[i+3],a[u+3]),t=this.stack[--this.sp]}if(t===jn)bn(e)&&(this.skipped+=e.length);else if(t===Br){let r=--this.real,o=bn(e)?e:null,a=this.popLayer();if(this.area(r,o?xo(o,this.maxBlur):0)){this.composite(a,!1,n,o);let i=this.scale;this.grow(this.rx0/i,this.ry0/i,this.rx1/i,this.ry1/i)}}}closeLayers(){for(;this.sp;)this.endLayer(1)}};var Xi=256,Fo=8<<20,Ee=new Float64Array(32),Re={x:0,y:0,w:0,h:0};function ji(s){if(typeof s.filter!="string")return!1;s.filter="blur(1px)";let n=s.filter==="blur(1px)";return s.filter="none",n}function qt(s){let n=s.getContext("2d",{alpha:!0});return n?new Hr(s,n):null}var Hr=class extends jt{constructor(e,t){super();p(this,"canvas",e);p(this,"ctx",t);p(this,"kind","canvas2d");p(this,"maxTextureSize",4096);p(this,"features",{});p(this,"info",{renderer:"canvas2d"});p(this,"support");p(this,"lost",!1);p(this,"fxr",null);p(this,"quads",0);p(this,"stats",{drawCalls:0,quads:0,filtersSkipped:0});p(this,"tinted",new Map);p(this,"tintedN",0);p(this,"lostListeners",[]);p(this,"restoredListeners",[]);p(this,"base");p(this,"top");p(this,"layers",[]);p(this,"scratch",[]);p(this,"nines",new Map);p(this,"ninePx",0);p(this,"frame",0);p(this,"hit",!1);p(this,"missed",new Map);this.support={filters:ji(t),shaders:!1},this.base=this.top={ctx:t,clipped:!1,ver:0},e.addEventListener("contextlost",()=>{this.lost=!0,this.lostListeners.forEach(r=>r())}),e.addEventListener("contextrestored",()=>{this.lost=!1,this.tinted.clear(),this.tintedN=0,this.dropNines(),this.restoredListeners.forEach(r=>r())})}resize(e,t){this.canvas.width!==e&&(this.canvas.width=e),this.canvas.height!==t&&(this.canvas.height=t)}createTexture(e){return{id:gn(),width:e.width,height:e.height,source:e}}updateTexture(e,t,r=0,o=0){let a=t?r+t.width:1/0,i=t?o+t.height:1/0;for(let u of this.nines.values()){let c=u.key;c[0]===e.id&&c[1]<a&&c[1]+c[3]>r&&c[2]<i&&c[2]+c[4]>o&&this.dropNine(u)}for(let[u,c]of this.tinted){let l=c.filter(f=>f.id!==e.id);this.tintedN-=c.length-l.length,l.length?this.tinted.set(u,l):this.tinted.delete(u)}}destroyTexture(e){this.updateTexture(e)}begin(e,t,r){this.resetLayers(r),this.fxr?.tick(),this.frame++,this.quads=0,this.top=this.base,this.ctx=this.base.ctx;let o=this.ctx;this.base.clipped&&o.restore(),this.base.clipped=!1,this.base.ver=this.clipVer,o.setTransform(1,0,0,1,0,0),o.globalAlpha=1,o.globalCompositeOperation="source-over",o.clearRect(0,0,this.canvas.width,this.canvas.height),t>0&&(o.fillStyle=Mt(e,t),o.fillRect(0,0,this.canvas.width,this.canvas.height))}quad(e,t,r,o,a,i,u,c){Y[0]=o,Y[1]=a,Y[2]=u,this.quadQ(e,t,r,i,c)}quadQ(e,t,r,o,a){t.w<=0||t.h<=0||(o===16777215?this.blit(e.source,t.x,t.y,t.w,t.h,r,a):this.blit(this.tint(e,t,o),0,0,t.w,t.h,r,a))}blit(e,t,r,o,a,i,u){let c=Y[0],l=Y[1],f=Y[2];if(f<=0||this.mute)return;this.sync();let h=this.ctx,y=this.scale;if(this.real){let b=i[0]*c,m=i[1]*c,d=i[2]*l,x=i[3]*l;this.grow(i[4]+Math.min(0,b,d,b+d),i[5]+Math.min(0,m,x,m+x),i[4]+Math.max(0,b,d,b+d),i[5]+Math.max(0,m,x,m+x))}h.setTransform(i[0]*y,i[1]*y,i[2]*y,i[3]*y,i[4]*y,i[5]*y),h.globalAlpha=Math.min(f,1),u==="add"&&(h.globalCompositeOperation="lighter"),h.drawImage(e,t,r,o,a,0,0,c,l),u==="add"&&(h.globalCompositeOperation="source-over"),this.quads++}nineQ(e,t,r,o,a,i,u){var m,d;let c=r[8]+r[9],l=o[8]+o[9],f=Math.ceil(c*Math.hypot(a[0],a[1])*this.scale-1e-6),h=Math.ceil(l*Math.hypot(a[2],a[3])*this.scale-1e-6);if(a[1]===0&&a[2]===0||f>4096||h>4096)return!1;if(!(f>0&&h>0&&Y[2]>0)||this.mute)return!0;let y=this.kept(e,t,r,o,f,h,i),b=(y??(y=(m=this.scratch)[d=13*Math.ceil(Math.log2(f))+Math.ceil(Math.log2(h))]??(m[d]=document.createElement("canvas").getContext("2d")))).canvas;if(b.width<f&&(b.width=f),b.height<h&&(b.height=h),!this.hit){y.clearRect(0,0,f+2,h+2);for(let x=0;x<12;x+=4){let g=Math.round(o[x]*h/l),A=Math.round((o[x]+o[x+1])*h/l);for(let w=0;w<12;w+=4){let v=Math.round(r[w]*f/c),R=Math.round((r[w]+r[w+1])*f/c);Re.x=t.x+r[w+2],Re.y=t.y+o[x+2],Re.w=r[w+3],Re.h=o[x+3],!(R<=v||A<=g||Re.w<=0||Re.h<=0)&&(i===16777215?y.drawImage(e.source,Re.x,Re.y,Re.w,Re.h,v,g,R-v,A-g):y.drawImage(this.tint(e,Re,i),0,0,Re.w,Re.h,v,g,R-v,A-g))}}}return Y[0]=c,Y[1]=l,this.blit(b,0,0,f,h,a,u),!0}kept(e,t,r,o,a,i,u){Ee[0]=e.id,Ee[1]=t.x,Ee[2]=t.y,Ee[3]=t.w,Ee[4]=t.h,Ee[5]=a,Ee[6]=i,Ee[7]=u,Ee.set(r,8),Ee.set(o,20);let c=Ge(Ee),l=this.nines.get(c);if(this.hit=!1,l)return Wt(l.key,Ee)?(l.used=this.frame,this.hit=!0,l.ctx):null;let f=this.missed,h=f.get(c);f.size>4096&&f.clear(),f.set(c,this.frame);let y=a*i;if(h!==this.frame-1||y>Fo)return null;let b;for(;this.ninePx+y>Fo;){let x;for(let w of this.nines.values())w.used<this.frame-1&&!(x&&x.used<=w.used)&&(x=w);if(!x)return null;let g=x.ctx.canvas,A=!b&&g.width>=a&&g.height>=i&&g.width*g.height<=2*y;this.dropNine(x,A),A&&(b=x.ctx)}let m=b??document.createElement("canvas").getContext("2d"),d=m.canvas;return b||(d.width=a,d.height=i),this.ninePx+=d.width*d.height,this.nines.set(c,{key:Sn(Ee),ctx:m,used:this.frame}),m}dropNine(e,t=!1){this.nines.delete(Ge(e.key));let r=e.ctx.canvas;this.ninePx-=r.width*r.height,t||(r.width=0)}dropNines(){for(let e of this.nines.values())this.dropNine(e)}tint(e,t,r){let o=ot(r,ot(t.h,ot(t.w,ot(t.y,ot(t.x,ot(e.id)))))),a=this.tinted.get(o);if(a)for(let c=0;c<a.length;c++){let l=a[c];if(l.id===e.id&&l.x===t.x&&l.y===t.y&&l.w===t.w&&l.h===t.h&&l.color===r)return l.canvas}this.tintedN>=Xi&&(this.tinted.clear(),this.tintedN=0,a=void 0);let i=document.createElement("canvas");i.width=Math.ceil(t.w),i.height=Math.ceil(t.h);let u=i.getContext("2d");return u.drawImage(e.source,t.x,t.y,t.w,t.h,0,0,t.w,t.h),u.globalCompositeOperation="multiply",u.fillStyle=Mt(r),u.fillRect(0,0,t.w,t.h),u.globalCompositeOperation="destination-in",u.drawImage(e.source,t.x,t.y,t.w,t.h,0,0,t.w,t.h),a||this.tinted.set(o,a=[]),a.push({id:e.id,x:t.x,y:t.y,w:t.w,h:t.h,color:r,canvas:i}),this.tintedN++,i}paint(e,t){this.sync();let r=this.ctx,o=this.scale;return r.setTransform(o,0,0,o,0,0),r.globalAlpha=Math.min(t,1),Mt(e)}ellipse(e,t,r,o,a,i,u){if(u<=0||r<=0||o<=0||this.mute)return;let c=Math.max(r,o);this.grow(e-c,t-c,e+c,t+c);let l=this.ctx;l.fillStyle=this.paint(i,u),l.beginPath(),l.ellipse(e,t,r,o,a,0,Math.PI*2),l.fill(),this.quads++}trace(e,t,r=0){if(this.real)for(let a=0;a<t;a++)this.grow(e[a*2]-r,e[a*2+1]-r,e[a*2]+r,e[a*2+1]+r);let o=this.ctx;o.beginPath(),o.moveTo(e[0],e[1]);for(let a=1;a<t;a++)o.lineTo(e[a*2],e[a*2+1])}polygon(e,t,r,o){if(o<=0||t<3||this.mute)return;let a=this.ctx;a.fillStyle=this.paint(r,o),this.trace(e,t),a.closePath(),a.fill(),this.quads++}stroke(e,t,r,o,a,i){if(a<=0||r<=0||t<1||this.mute)return;let u=this.ctx;u.strokeStyle=this.paint(o,a),u.lineWidth=r,u.lineCap="round",u.lineJoin="round",this.trace(e,t,r/2),t===1&&u.lineTo(e[0],e[1]),i&&u.closePath(),u.stroke(),this.quads++}sync(){let e=this.top;if(e.ver===this.clipVer)return;let t=e.ctx;e.clipped&&t.restore(),e.clipped=this.cOn,e.ver=this.clipVer,this.cOn&&(t.save(),t.setTransform(1,0,0,1,0,0),t.beginPath(),t.rect(this.px0,this.py0,this.px1-this.px0,this.py1-this.py0),t.clip())}pushLayer(){let e=this.canvas.width,t=this.canvas.height,r=this.layers[this.real];if(!r||r.ctx.canvas.width!==e||r.ctx.canvas.height!==t){let a=document.createElement("canvas");a.width=e,a.height=t;let i=a.getContext("2d");if(!i)return!1;r=this.layers[this.real]={ctx:i,clipped:!1,ver:-1}}let o=r.ctx;return r.clipped&&o.restore(),r.clipped=!1,r.ver=-1,o.setTransform(1,0,0,1,0,0),o.globalAlpha=1,o.globalCompositeOperation="source-over",o.clearRect(0,0,e,t),this.top=r,this.ctx=o,!0}popLayer(){return this.top=this.real>0?this.layers[this.real-1]:this.base,this.ctx=this.top.ctx,this.layers[this.real].ctx.canvas}composite(e,t,r,o){let a=e,i="none",u=o&&Me.c2d?this.fxr??(this.fxr=Me.c2d(this)):null;u&&(a=u.chain(e,o),i=u.css),this.sync();let c=this.ctx,l=this.rx0,f=this.ry0,h=this.rx1-l,y=this.ry1-f;c.setTransform(1,0,0,1,0,0),c.globalAlpha=Math.min(r,1),c.globalCompositeOperation=t?"destination-in":"source-over",i!=="none"&&(c.filter=i),c.drawImage(a,l,f,h,y,l,f,h,y),i!=="none"&&(c.filter="none"),c.globalCompositeOperation="source-over",this.quads++}end(){this.closeLayers();let e=this.stats;return e.drawCalls=e.quads=this.quads,e.filtersSkipped=this.skipped,e}onLost(e){this.lostListeners.push(e)}onRestored(e){this.restoredListeners.push(e)}destroy(){this.tinted.clear(),this.dropNines(),this.layers=[],this.scratch=[],this.fxr?.destroy(),this.fxr=null}};var qn=class{constructor(n,e,t=8192){p(this,"instanced",n);p(this,"slots",e);p(this,"capacity",t);p(this,"f32");p(this,"u32");p(this,"quads",0);p(this,"textures");p(this,"bound",0);this.textures=new Array(e).fill(null);let r=t*(n?14:24),o=new ArrayBuffer(r*4);this.f32=new Float32Array(o),this.u32=new Uint32Array(o)}slot(n){let e=this.textures;for(let t=0;t<this.bound;t++)if(e[t]===n)return t;return this.bound>=this.slots?-1:(e[this.bound]=n,this.bound++)}has(n){for(let e=0;e<this.bound;e++)if(this.textures[e]===n)return!0;return!1}get full(){return this.quads>=this.capacity}get words(){return this.quads*(this.instanced?14:24)}reset(){this.quads=0;for(let n=0;n<this.bound;n++)this.textures[n]=null;this.bound=0}push(n,e,t,r,o,a,i,u,c,l,f,h,y,b){let m=this.f32;if(this.instanced){let d=this.quads*14;m[d++]=n,m[d++]=e,m[d++]=t,m[d++]=r,m[d++]=o,m[d++]=a,m[d++]=i,m[d++]=u,m[d++]=c,m[d++]=l,m[d++]=f,m[d++]=h,this.u32[d++]=y,m[d]=b}else{let d=this.quads*6*4;this.vertex(d,n,e,c,l,y,b),this.vertex(d+6,t,r,f,l,y,b),this.vertex(d+12,o,a,f,h,y,b),this.vertex(d+18,i,u,c,h,y,b)}this.quads++}pushQ(n,e){let t=this.f32;if(this.instanced){let r=this.quads*14;for(let o=0;o<12;o++)t[r+o]=n[o];this.u32[r+12]=n[12],t[r+13]=e}else{let r=this.quads*6*4,o=n[12];for(let a=0;a<4;a++,r+=6)t[r]=n[a*2],t[r+1]=n[a*2+1],t[r+2]=a===1||a===2?n[10]:n[8],t[r+3]=a>=2?n[11]:n[9],this.u32[r+4]=o,t[r+5]=e}this.quads++}vertex(n,e,t,r,o,a,i){let u=this.f32;u[n]=e,u[n+1]=t,u[n+2]=r,u[n+3]=o,this.u32[n+4]=a,u[n+5]=i}};function Po(s){let n=new Uint16Array(s*6);for(let e=0,t=0,r=0;e<s;e++,t+=6,r+=4)n[t]=r,n[t+1]=r+1,n[t+2]=r+2,n[t+3]=r,n[t+4]=r+2,n[t+5]=r+3;return n}var ge={M:0,L:1,Q:2,C:3,Z:4},zo=[2,2,4,6,0],qi={M:0,L:1,Q:2,C:3,Z:4};function er(s,n){if(s.length>=n)return s;let e=new Float64Array(Math.max(n,s.length*2,16));return e.set(s),e}var Yn=new Map;function Yi(s){if(typeof s!="string")return s;let n=Yn.get(s);if(n)return n;n=[];let e=s.match(/[MLQCZ]|-?\d*\.?\d+(?:e-?\d+)?/gi)??[],t=-1;for(let r=0;r<e.length;){let o=e[r],a=qi[o.toUpperCase()];if(a!==void 0){t=a,r++,a===ge.Z&&n.push(ge.Z);continue}if(t<0||t===ge.Z){r++;continue}let i=zo[t];n.push(t);for(let u=0;u<i;u++)n.push(Number(e[r+u]??0));r+=i,t===ge.M&&(t=ge.L)}return Yn.size>256&&Yn.clear(),Yn.set(s,n),n}var mt={subs:[],count:0},$r=null,dt=null;function Kn(s,n){let e=dt;e||(e=mt.subs[mt.count]??null,e||mt.subs.push(e={pts:new Float64Array(64),n:0,closed:!1}),e.n=0,e.closed=!1,mt.count++,dt=e);let t=e.n*2;t+2>e.pts.length&&(e.pts=er(e.pts,t+2));let r=$r;r?(e.pts[t]=r[0]*s+r[2]*n+r[4],e.pts[t+1]=r[1]*s+r[3]*n+r[5]):(e.pts[t]=s,e.pts[t+1]=n),e.n++}function tr(s,n=null,e=1,t=6){let r=Yi(s);mt.count=0,dt=null,$r=n;let o=0,a=0,i=0,u=0,c=e/t;for(let l=0;l<r.length;){let f=r[l++],h=r;if(f===ge.M)dt=null,o=i=h[l],a=u=h[l+1],Kn(o,a);else if(f===ge.L)o=h[l],a=h[l+1],Kn(o,a);else if(f===ge.Q){let y=h[l],b=h[l+1],m=h[l+2],d=h[l+3],x=_o((je(y-o,b-a)+je(m-y,d-b))*c);for(let g=1;g<=x;g++){let A=g/x,w=1-A;Kn(w*w*o+2*w*A*y+A*A*m,w*w*a+2*w*A*b+A*A*d)}o=m,a=d}else if(f===ge.C){let y=h[l],b=h[l+1],m=h[l+2],d=h[l+3],x=h[l+4],g=h[l+5],A=_o((je(y-o,b-a)+je(m-y,d-b)+je(x-m,g-d))*c);for(let w=1;w<=A;w++){let v=w/A,R=1-v,F=R*R*R,O=3*R*R*v,_=3*R*v*v,B=v*v*v;Kn(F*o+O*y+_*m+B*x,F*a+O*b+_*d+B*g)}o=x,a=g}else if(f===ge.Z){dt&&(dt.closed=!0),dt=null,o=i,a=u;continue}else break;l+=zo[f]}dt=null,$r=null;for(let l=0;l<mt.count;l++){let f=mt.subs[l],h=f.n*2;f.closed&&f.n>=2&&Math.abs(f.pts[0]-f.pts[h-2])<1e-6&&Math.abs(f.pts[1]-f.pts[h-1])<1e-6&&f.n--}return mt}var je=(s,n)=>Math.sqrt(s*s+n*n),_o=s=>Math.min(Math.max(Math.ceil(s),2),24);function Ki(s,n){let e=0;for(let t=0,r=n-1;t<n;r=t++)e+=(s[r*2]-s[t*2])*(s[r*2+1]+s[t*2+1]);return e}var Qn=new Int32Array(64),Zn=(s,n,e,t,r)=>((s[t*2]-s[e*2])*(s[r*2+1]-s[e*2+1])-(s[t*2+1]-s[e*2+1])*(s[r*2]-s[e*2]))*n;function Ho(s,n,e){if(n<3)return 0;Qn.length<n&&(Qn=new Int32Array(Math.max(n,Qn.length*2)));let t=Qn,r=n,o=0;for(let c=0;c<n;c++)t[c]=c;let a=Ki(s,n)>0?1:-1,i=n*n+8,u=0;for(;r>3&&i-- >0;){let c=t[(u+r-1)%r],l=t[u%r],f=t[(u+1)%r],h=Zn(s,a,c,l,f)>0;if(h)for(let y=0;y<r;y++){let b=t[y];if(!(b===c||b===l||b===f)&&Zn(s,a,c,l,b)>=0&&Zn(s,a,l,f,b)>=0&&Zn(s,a,f,c,b)>=0){h=!1;break}}h?(e[o++]=c,e[o++]=l,e[o++]=f,t.copyWithin(u%r,u%r+1,r),r--,u=Math.max(u-1,0)):u=(u+1)%r}if(r===3)e[o++]=t[0],e[o++]=t[1],e[o++]=t[2];else if(r>3)for(let c=1;c+1<r;c++)e[o++]=t[0],e[o++]=t[c],e[o++]=t[c+1];return o}var Qi=.85,Jn=new Float64Array(64),Lo=new Float64Array(64),Oo=new Float64Array(64),Io=new Float64Array(64),No=new Float64Array(64),Do=new Float64Array(64),Bo=new Uint8Array(64),Mn=new Float64Array(8);function $o(s,n,e,t,r,o){let a=Mn;if(Jn.length<n){let d=Math.max(n,Jn.length*2);Jn=new Float64Array(d),Lo=new Float64Array(d),Oo=new Float64Array(d),Io=new Float64Array(d),No=new Float64Array(d),Do=new Float64Array(d),Bo=new Uint8Array(d)}let i=Jn,u=Lo,c=0;for(let d=0;d<n;d++){let x=s[d*2],g=s[d*2+1];!Number.isFinite(x)||!Number.isFinite(g)||c&&Math.abs(i[c-1]-x)<.001&&Math.abs(u[c-1]-g)<.001||(i[c]=x,u[c]=g,c++)}if(t&&c>2&&Math.abs(i[0]-i[c-1])<.001&&Math.abs(u[0]-u[c-1])<.001&&c--,c===0)return;if(c===1)return a[0]=i[0],a[1]=u[0],o();let l=t?c:c-1,f=Oo,h=Io;for(let d=0;d<l;d++){let x=(d+1)%c,g=i[x]-i[d],A=u[x]-u[d],w=je(g,A)||1;f[d]=-A/w,h[d]=g/w}let y=No,b=Do,m=Bo;for(let d=0;d<c;d++){let x=t?(d-1+l)%l:d-1,g=d<l?d:-1;if(m[d]=1,x<0||g<0||f[x]*f[g]+h[x]*h[g]<Qi)continue;let w=f[x]+f[g],v=h[x]+h[g],R=je(w,v)||1;w/=R,v/=R;let F=e/Math.max(w*f[g]+v*h[g],.5);y[d]=w*F,b[d]=v*F,m[d]=0}for(let d=0;d<l;d++){let x=(d+1)%c,g=m[d]?f[d]*e:y[d],A=m[d]?h[d]*e:b[d],w=m[x]?f[d]*e:y[x],v=m[x]?h[d]*e:b[x];a[0]=i[d]+g,a[1]=u[d]+A,a[2]=i[x]+w,a[3]=u[x]+v,a[4]=i[x]-w,a[5]=u[x]-v,a[6]=i[d]-g,a[7]=u[d]-A,r()}for(let d=0;d<c;d++)m[d]&&(a[0]=i[d],a[1]=u[d],o())}function Gr(s,n){let e=0,t=1/0;for(let r=0;r<n.length;r++){let o=Math.abs(Math.log(Math.max(s,.5)/n[r]));o<t&&(t=o,e=r)}return e}var nr=[{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}],rr=[4,8,16,32,64,128].map((s,n)=>({x:n*4,y:128,w:4,h:s,r:s/2-1})),at={x:248,y:248,w:8,h:8},Uo=nr.map(s=>s.r*2),Vo=rr.map(s=>s.r*2),Go=(s,n)=>Math.min(Math.max(s+.5-n,0),1);function Zi(){let s=new Uint8ClampedArray(262144),n=(e,t,r)=>{let o=(t*256+e)*4;s[o]=s[o+1]=s[o+2]=255,s[o+3]=Math.round(r*255)};for(let e of nr){let t=e.w/2;for(let r=0;r<e.h;r++)for(let o=0;o<e.w;o++)n(e.x+o,e.y+r,Go(e.r,Math.hypot(o+.5-t,r+.5-t)))}for(let e of rr){let t=e.h/2;for(let r=0;r<e.h;r++)for(let o=0;o<e.w;o++)n(e.x+o,e.y+r,Go(e.r,Math.abs(r+.5-t)))}for(let e=0;e<at.h;e++)for(let t=0;t<at.w;t++)n(at.x+t,at.y+e,1);return s}function Wo(){let s=document.createElement("canvas");return s.width=s.height=256,s.getContext("2d").putImageData(new ImageData(Zi(),256,256),0,0),s}var Xo=8,sr=`
|
|
2
2
|
#ifdef GL_FRAGMENT_PRECISION_HIGH
|
|
3
3
|
precision highp float;
|
|
4
4
|
#else
|
|
5
5
|
precision mediump float;
|
|
6
6
|
#endif
|
|
7
|
-
`,
|
|
7
|
+
`,nl=s=>`${sr}
|
|
8
8
|
uniform sampler2D uTex[${s}];
|
|
9
9
|
varying vec2 vUv;
|
|
10
10
|
varying vec4 vColor;
|
|
@@ -14,7 +14,7 @@ void main() {
|
|
|
14
14
|
${Array.from({length:s},(n,e)=>e===s-1?`c = texture2D(uTex[${e}], vUv);`:`if (vSlot < ${e}.5) c = texture2D(uTex[${e}], vUv); else `).join(`
|
|
15
15
|
`)}
|
|
16
16
|
gl_FragColor = c * vColor;
|
|
17
|
-
}
|
|
17
|
+
}`,rl=`
|
|
18
18
|
attribute vec2 aPos;
|
|
19
19
|
attribute vec2 aUv;
|
|
20
20
|
attribute vec4 aColor;
|
|
@@ -28,7 +28,7 @@ void main() {
|
|
|
28
28
|
vColor = aColor;
|
|
29
29
|
vSlot = aSlot;
|
|
30
30
|
gl_Position = vec4(aPos * uScale + vec2(-1.0, 1.0), 0.0, 1.0);
|
|
31
|
-
}`,
|
|
31
|
+
}`,sl=`
|
|
32
32
|
attribute vec4 aCorner;
|
|
33
33
|
attribute vec4 aP01;
|
|
34
34
|
attribute vec4 aP23;
|
|
@@ -45,7 +45,7 @@ void main() {
|
|
|
45
45
|
vColor = aColor;
|
|
46
46
|
vSlot = aSlot;
|
|
47
47
|
gl_Position = vec4(p * uScale + vec2(-1.0, 1.0), 0.0, 1.0);
|
|
48
|
-
}`,Ui={alpha:!0,premultipliedAlpha:!0,antialias:!1,depth:!1,stencil:!1,preserveDrawingBuffer:!1,powerPreference:"high-performance"},Vi=["aCorner","aP01","aP23","aUvRect","aColor","aSlot"],Wi=["aPos","aUv","aColor","aSlot"];function Ho(s,n,e={}){let t={...Ui,failIfMajorPerformanceCaveat:e.failIfMajorPerformanceCaveat!==!1},r=n===2?s.getContext("webgl2",t):s.getContext("webgl",t)??s.getContext("experimental-webgl",t);if(!r||r.isContextLost())return null;try{return new Dr(s,r,n,e)}catch(o){return console.warn("[engine] WebGL setup failed:",o),r.getExtension("WEBGL_lose_context")?.loseContext(),null}}var Dr=class extends Wt{constructor(e,t,r,o){super();p(this,"canvas",e);p(this,"gl",t);p(this,"opts",o);p(this,"kind");p(this,"maxTextureSize");p(this,"support",{filters:!0,shaders:!0});p(this,"features",{});p(this,"info",{});p(this,"lost",!1);p(this,"main");p(this,"cur");p(this,"unit",-1);p(this,"onUnit",new Array(Do).fill(void 0));p(this,"fbNow");p(this,"mapped",!0);p(this,"calls",{useProgram:0,bindTexture:0,activeTexture:0,bindFramebuffer:0});p(this,"vsrc","");p(this,"attrs",[]);p(this,"fxr",null);p(this,"batch");p(this,"dynamic");p(this,"staticBuf",null);p(this,"index");p(this,"vao",null);p(this,"inst",null);p(this,"vaoApi",null);p(this,"uScale",null);p(this,"textures",new Map);p(this,"kit");p(this,"stats",{drawCalls:0,quads:0,filtersSkipped:0});p(this,"lostListeners",[]);p(this,"restoredListeners",[]);p(this,"tris",new Int32Array(192));p(this,"sU",0);p(this,"sV0",0);p(this,"sV1",0);p(this,"sColor",0);p(this,"sPacked",0);p(this,"sAlpha",0);p(this,"sHw",0);p(this,"strokeSeg",()=>{let e=this.q;e.set(kn),e[8]=e[10]=this.sU,e[9]=this.sV0,e[11]=this.sV1,e[12]=this.sPacked,this.put(this.kit)});p(this,"strokeDisc",()=>this.ellipse(kn[0],kn[1],this.sHw,this.sHw,0,this.sColor,this.sAlpha));p(this,"q",new Float64Array(13));p(this,"layers",[]);p(this,"layerTex",new Map);p(this,"bScis",!1);p(this,"bx0",0);p(this,"by0",0);p(this,"bx1",0);p(this,"by1",0);p(this,"onContextLost",e=>{e.preventDefault(),this.lost=!0;for(let t of this.lostListeners)t()});p(this,"onContextRestored",()=>{try{this.layers=[],this.layerTex.clear(),this.fxr=null,this.resetLayers(this.scale),this.setup();for(let e of this.textures.keys())this.textures.set(e,this.upload(e.source));this.lost=!1;for(let e of this.restoredListeners)e()}catch(e){console.warn("[engine] WebGL restore failed:",e)}});p(this,"views",new Map);this.kind=r===2?"webgl2":"webgl1",this.maxTextureSize=t.getParameter(t.MAX_TEXTURE_SIZE),this.setup(),this.kit=this.createTexture(Bo()),Ee.live=this,e.addEventListener("webglcontextlost",this.onContextLost,!1),e.addEventListener("webglcontextrestored",this.onContextRestored,!1)}setup(){let e=this.gl,t=this.kind==="webgl2"?e:null;if(this.inst=null,this.opts.instancing!==!1)if(t)this.inst={divisor:(f,h)=>t.vertexAttribDivisor(f,h),draw:(f,h)=>t.drawElementsInstanced(e.TRIANGLES,f,e.UNSIGNED_SHORT,0,h)};else{let f=e.getExtension("ANGLE_instanced_arrays");f&&(this.inst={divisor:(h,b)=>f.vertexAttribDivisorANGLE(h,b),draw:(h,b)=>f.drawElementsInstancedANGLE(e.TRIANGLES,h,e.UNSIGNED_SHORT,0,b)})}if(this.vaoApi=null,this.opts.vao!==!1)if(t)this.vaoApi={create:()=>t.createVertexArray(),bind:f=>t.bindVertexArray(f),remove:f=>t.deleteVertexArray(f)};else{let f=e.getExtension("OES_vertex_array_object");f&&(this.vaoApi={create:()=>f.createVertexArrayOES(),bind:h=>f.bindVertexArrayOES(h),remove:h=>f.deleteVertexArrayOES(h)})}let r=e.getParameter(e.MAX_TEXTURE_IMAGE_UNITS),o=Math.max(1,Math.min(Do,r)),a=this.inst!==null;this.vsrc=a?Gi:$i,this.attrs=a?Vi:Wi,this.main=this.cur=this.build(Hi(o));let i=this.main.p;e.useProgram(i),this.calls.useProgram++,this.unit=-1,this.onUnit.fill(void 0),this.fbNow=void 0,this.uScale=this.main.uScale,e.uniform1iv(e.getUniformLocation(i,"uTex"),Int32Array.from({length:o},(f,h)=>h)),this.batch=new Vn(a,o),this.vaoApi&&(this.vao=this.vaoApi.create(),this.vaoApi.bind(this.vao)),this.dynamic=e.createBuffer(),e.bindBuffer(e.ARRAY_BUFFER,this.dynamic),e.bufferData(e.ARRAY_BUFFER,this.batch.f32.byteLength,e.DYNAMIC_DRAW),this.index=e.createBuffer(),e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,this.index),e.bufferData(e.ELEMENT_ARRAY_BUFFER,Ao(a?1:8192),e.STATIC_DRAW);let l=f=>e.getAttribLocation(i,f),c=(f,h,b,y,m,d,x)=>{let g=l(f);g<0||(e.enableVertexAttribArray(g),e.vertexAttribPointer(g,h,b,y,m,d),this.inst&&this.inst.divisor(g,x))};if(a){let f=56;c("aP01",4,e.FLOAT,!1,f,0,1),c("aP23",4,e.FLOAT,!1,f,16,1),c("aUvRect",4,e.FLOAT,!1,f,32,1),c("aColor",4,e.UNSIGNED_BYTE,!0,f,48,1),c("aSlot",1,e.FLOAT,!1,f,52,1),this.staticBuf=e.createBuffer(),e.bindBuffer(e.ARRAY_BUFFER,this.staticBuf),e.bufferData(e.ARRAY_BUFFER,Float32Array.of(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1),e.STATIC_DRAW),c("aCorner",4,e.FLOAT,!1,16,0,0),e.bindBuffer(e.ARRAY_BUFFER,this.dynamic)}else{let f=24;c("aPos",2,e.FLOAT,!1,f,0,0),c("aUv",2,e.FLOAT,!1,f,8,0),c("aColor",4,e.UNSIGNED_BYTE,!0,f,16,0),c("aSlot",1,e.FLOAT,!1,f,20,0)}e.enable(e.BLEND),e.blendFunc(e.ONE,e.ONE_MINUS_SRC_ALPHA),e.disable(e.DEPTH_TEST),e.disable(e.CULL_FACE),e.pixelStorei(e.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!0);let u=e.getExtension("WEBGL_debug_renderer_info");this.info={version:e.getParameter(e.VERSION),renderer:u?e.getParameter(u.UNMASKED_RENDERER_WEBGL):e.getParameter(e.RENDERER),vendor:u?e.getParameter(u.UNMASKED_VENDOR_WEBGL):e.getParameter(e.VENDOR)},this.features={instancing:a,vao:this.vaoApi!==null,textureSlots:o,maxTextureSize:this.maxTextureSize}}upload(e){let t=this.gl,r=t.createTexture();return this.bindTex(r),t.texImage2D(t.TEXTURE_2D,0,t.RGBA,t.RGBA,t.UNSIGNED_BYTE,e),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.LINEAR),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.LINEAR),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE),r}resize(e,t){this.canvas.width!==e&&(this.canvas.width=e),this.canvas.height!==t&&(this.canvas.height=t)}createTexture(e){let t={id:dn(),width:e.width,height:e.height,source:e};return this.textures.set(t,this.lost?null:this.upload(e)),t}updateTexture(e,t,r=0,o=0){if(this.lost)return;this.batch.has(e)&&this.flush();let a=this.gl,i=this.textures.get(e);i&&(this.bindTex(i),!t||t===e.source&&r===0&&o===0?a.texImage2D(a.TEXTURE_2D,0,a.RGBA,a.RGBA,a.UNSIGNED_BYTE,e.source):a.texSubImage2D(a.TEXTURE_2D,0,r,o,a.RGBA,a.UNSIGNED_BYTE,t))}destroyTexture(e){this.batch.has(e)&&this.flush();let t=this.textures.get(e);t&&!this.lost&&this.deleteTex(t),this.textures.delete(e)}begin(e,t,r){if(this.stats.drawCalls=this.stats.quads=this.stats.filtersSkipped=0,this.batch.reset(),this.resetLayers(r),this.bScis=!1,this.lost)return;let o=this.gl;o.disable(o.SCISSOR_TEST),this.bindFb(null),o.viewport(0,0,this.canvas.width,this.canvas.height);let a=t;o.clearColor((e>>16&255)/255*a,(e>>8&255)/255*a,(e&255)/255*a,a),o.clear(o.COLOR_BUFFER_BIT),this.use(this.main),o.uniform2f(this.uScale,2*r/this.canvas.width,-2*r/this.canvas.height),this.mapped=!0}build(e){let t=this.gl,r=zo(t,t.VERTEX_SHADER,this.vsrc),o;try{o=zo(t,t.FRAGMENT_SHADER,e)}catch(i){throw t.deleteShader(r),i}let a=t.createProgram();if(t.attachShader(a,r),t.attachShader(a,o),this.attrs.forEach((i,l)=>t.bindAttribLocation(a,l,i)),t.linkProgram(a),t.deleteShader(r),t.deleteShader(o),!t.getProgramParameter(a,t.LINK_STATUS)){let i=t.getProgramInfoLog(a)??"?";throw t.deleteProgram(a),new Error(`link: ${i}`)}return{p:a,uScale:t.getUniformLocation(a,"uScale"),locs:new Map}}u(e,t){let r=e.locs.get(t);return r===void 0&&e.locs.set(t,r=this.gl.getUniformLocation(e.p,t)),r}use(e){this.cur!==e&&(this.cur=e,this.gl.useProgram(e.p),this.calls.useProgram++)}bindTex(e,t=this.unit<0?0:this.unit){let r=this.gl;this.onUnit[t]!==e&&(this.unit!==t&&(r.activeTexture(r.TEXTURE0+t),this.calls.activeTexture++,this.unit=t),r.bindTexture(r.TEXTURE_2D,e),this.calls.bindTexture++,this.onUnit[t]=e)}deleteTex(e){this.gl.deleteTexture(e);for(let t=0;t<this.onUnit.length;t++)this.onUnit[t]===e&&(this.onUnit[t]=null)}bindFb(e){if(e)for(let r=0;r<this.onUnit.length;r++)this.onUnit[r]===e.gl&&this.bindTex(null,r);let t=e?e.fb:null;this.fbNow!==t&&(this.gl.bindFramebuffer(this.gl.FRAMEBUFFER,t),this.calls.bindFramebuffer++,this.fbNow=t)}slotOf(e){this.batch.full&&this.flush();let t=this.batch.slot(e);return t<0&&(this.flush(),t=this.batch.slot(e)),t}quad(e,t,r,o,a,i,l,c){q[0]=o,q[1]=a,q[2]=l,this.quadQ(e,t,r,i,c)}quadQ(e,t,r,o,a){let i=q[2];if(this.lost||i<=0)return;let l=this.q,c=q[0],u=q[1],f=r[4],h=r[5],b=r[0]*c,y=r[1]*c,m=r[2]*u,d=r[3]*u;l[0]=f,l[1]=h,l[2]=b+f,l[3]=y+h,l[4]=b+m+f,l[5]=y+d+h,l[6]=m+f,l[7]=d+h;let x=1/e.width,g=1/e.height;l[8]=t.x*x,l[9]=t.y*g,l[10]=(t.x+t.w)*x,l[11]=(t.y+t.h)*g,l[12]=lt(o,i,a==="add"),this.put(e)}put(e){if(this.mute)return;let t=this.q,r=!1,o=Math.min(t[0],t[2],t[4],t[6]),a=Math.max(t[0],t[2],t[4],t[6]),i=Math.min(t[1],t[3],t[5],t[7]),l=Math.max(t[1],t[3],t[5],t[7]);if(this.cOn){if(this.px1<=this.px0||this.py1<=this.py0)return;let u=this.scale,f=this.px0/u,h=this.py0/u,b=this.px1/u,y=this.py1/u;if(a<=f||o>=b||l<=h||i>=y)return;if(o<f||a>b||i<h||l>y){let m=t[0],d=t[1],x=t[2],g=t[5];if(d===t[3]&&x===t[4]&&g===t[7]&&t[6]===m){if(m!==x){let A=Math.min(Math.max(m,f),b),w=Math.min(Math.max(x,f),b),v=t[8],E=(t[10]-v)/(x-m);t[10]=v+(w-m)*E,t[8]=v+(A-m)*E,t[0]=t[6]=A,t[2]=t[4]=w}if(d!==g){let A=Math.min(Math.max(d,h),y),w=Math.min(Math.max(g,h),y),v=t[9],E=(t[11]-v)/(g-d);t[11]=v+(w-d)*E,t[9]=v+(A-d)*E,t[1]=t[3]=A,t[5]=t[7]=w}}else r=!0}}let c=this.bx0===this.px0&&this.by0===this.py0&&this.bx1===this.px1&&this.by1===this.py1;if(r?(!this.bScis||!c)&&(this.flush(),this.bScis=!0,this.bx0=this.px0,this.by0=this.py0,this.bx1=this.px1,this.by1=this.py1):this.bScis&&!(this.cOn&&c)&&(this.flush(),this.bScis=!1),this.real){let u=this.gq;u[0]=o,u[1]=i,u[2]=a,u[3]=l,this.growQ()}this.batch.pushQ(t,this.slotOf(e))}ellipse(e,t,r,o,a,i,l){if(this.lost||l<=0||r<=0||o<=0)return;let c=Zn[Br(Math.max(r,o)*2*this.scale,Oo)],u=c.w/2/c.r,f=r*u,h=o*u,b=Math.cos(a),y=Math.sin(a),m=b*f,d=y*f,x=-y*h,g=b*h,A=1/256,w=this.q;w[0]=e-m-x,w[1]=t-d-g,w[2]=e+m-x,w[3]=t+d-g,w[4]=e+m+x,w[5]=t+d+g,w[6]=e-m+x,w[7]=t-d+g,w[8]=c.x*A,w[9]=c.y*A,w[10]=(c.x+c.w)*A,w[11]=(c.y+c.h)*A,w[12]=lt(i,l),this.put(this.kit)}polygon(e,t,r,o){if(this.lost||o<=0||t<3)return;this.tris.length<t*3&&(this.tris=new Int32Array(Math.max(t*3,this.tris.length*2)));let a=this.tris,i=_o(e,t,a),l=lt(r,o),c=(ot.x+ot.w/2)/256,u=(ot.y+ot.h/2)/256;for(let f=0;f<i;f+=3){let h=a[f]*2,b=a[f+1]*2,y=a[f+2]*2,m=this.q;m[0]=e[h],m[1]=e[h+1],m[2]=e[b],m[3]=e[b+1],m[4]=m[6]=e[y],m[5]=m[7]=e[y+1],m[8]=m[10]=c,m[9]=m[11]=u,m[12]=l,this.put(this.kit)}}stroke(e,t,r,o,a,i){if(this.lost||a<=0||r<=0||t<1)return;let l=Jn[Br(r*this.scale,No)],c=r/2*(l.h/2/l.r);this.sPacked=lt(o,a),this.sColor=o,this.sAlpha=a,this.sU=(l.x+l.w/2)/256,this.sV0=l.y/256,this.sV1=(l.y+l.h)/256,this.sHw=r/2,Lo(e,t,c,i,this.strokeSeg,this.strokeDisc)}target(e,t,r,o){let a=this.gl,i=a.createTexture();this.bindTex(i),a.texImage2D(a.TEXTURE_2D,0,a.RGBA,e,t,0,a.RGBA,a.UNSIGNED_BYTE,null);let l=o?a.LINEAR:a.NEAREST;a.texParameteri(a.TEXTURE_2D,a.TEXTURE_MIN_FILTER,l),a.texParameteri(a.TEXTURE_2D,a.TEXTURE_MAG_FILTER,l),a.texParameteri(a.TEXTURE_2D,a.TEXTURE_WRAP_S,a.CLAMP_TO_EDGE),a.texParameteri(a.TEXTURE_2D,a.TEXTURE_WRAP_T,a.CLAMP_TO_EDGE),this.bindTex(null);let c=a.createFramebuffer();a.bindFramebuffer(a.FRAMEBUFFER,c),a.framebufferTexture2D(a.FRAMEBUFFER,a.COLOR_ATTACHMENT0,a.TEXTURE_2D,i,0);let u=a.checkFramebufferStatus(a.FRAMEBUFFER)===a.FRAMEBUFFER_COMPLETE;if(this.fbNow=c,this.bindFb(this.parent()),!u)return this.deleteTex(i),a.deleteFramebuffer(c),null;let f={tex:{id:dn(),width:e,height:t,source:this.canvas},gl:i,fb:c,w:e,h:t,f:r};return this.layerTex.set(f.tex,i),f}drop(e){this.batch.has(e.tex)&&this.flush(),this.deleteTex(e.gl),this.gl.deleteFramebuffer(e.fb),this.layerTex.delete(e.tex)}parent(){return this.real>0?this.layers[this.real-1]:null}layerAt(e){let t=this.canvas.width,r=this.canvas.height,o=this.layers[e]??null;return o&&(o.w!==t||o.h!==r)&&(this.drop(o),o=this.layers[e]=null),o??(this.layers[e]=this.target(t,r,1,!1))}pushLayer(){if(this.lost)return!1;this.flush();let e=this.layerAt(this.real);if(!e)return!1;let t=this.gl;return this.bindFb(e),t.disable(t.SCISSOR_TEST),t.clearColor(0,0,0,0),t.clear(t.COLOR_BUFFER_BIT),!0}popLayer(){return this.flush(),this.bindFb(this.parent()),this.layers[this.real].tex}filters(){return this.lost||!Ee.gl?null:this.fxr??(this.fxr=Ee.gl(this))}composite(e,t,r,o){if(o&&this.filters()?.chain(e,r,o))return;let a=this.gl;t&&a.blendFunc(a.ZERO,a.SRC_ALPHA),this.final(this.main,e,1,r),t&&(this.flush(),a.blendFunc(a.ONE,a.ONE_MINUS_SRC_ALPHA))}final(e,t,r,o){let a=this.gl,i=this.canvas.width,l=this.canvas.height,c=this.scale;(e!==this.main||!this.mapped)&&(this.bindFb(this.parent()),a.viewport(0,0,i,l),this.use(e),a.uniform2f(e.uScale,2*c/i,-2*c/l),this.mapped=e===this.main);let u=this.rx0/c,f=this.ry0/c,h=this.rx1/c,b=this.ry1/c,y=1/(r*t.width),m=1/(r*t.height),d=this.q;d[0]=d[6]=u,d[1]=d[3]=f,d[2]=d[4]=h,d[5]=d[7]=b,d[8]=this.rx0*y,d[9]=1-this.ry0*m,d[10]=this.rx1*y,d[11]=1-this.ry1*m,d[12]=lt(16777215,o),this.put(t),e!==this.main&&this.flush()}remap(){let e=this.gl;this.bindFb(this.parent()),e.viewport(0,0,this.canvas.width,this.canvas.height),this.use(this.main),e.uniform2f(this.uScale,2*this.scale/this.canvas.width,-2*this.scale/this.canvas.height),this.mapped=!0}upload2(e){let t=this.gl,r=e.words;if(this.kind==="webgl2")return t.bufferSubData(t.ARRAY_BUFFER,0,e.f32,0,r);let o=this.views.get(r);o||(this.views.size>=256&&this.views.clear(),this.views.set(r,o=e.f32.subarray(0,r))),t.bufferSubData(t.ARRAY_BUFFER,0,o)}flush(){let e=this.batch;if(!e.quads||this.lost)return e.reset();let t=this.gl;this.bScis?(t.enable(t.SCISSOR_TEST),t.scissor(this.bx0,this.canvas.height-this.by1,this.bx1-this.bx0,this.by1-this.by0)):t.disable(t.SCISSOR_TEST),this.upload2(e);for(let r=0;r<e.bound;r++){let o=e.textures[r];this.bindTex(this.textures.get(o)??this.layerTex.get(o)??null,r)}this.inst?this.inst.draw(6,e.quads):t.drawElements(t.TRIANGLES,e.quads*6,t.UNSIGNED_SHORT,0),this.stats.drawCalls++,this.stats.quads+=e.quads,e.reset()}end(){return this.closeLayers(),this.flush(),this.stats.filtersSkipped=this.skipped,this.stats}onLost(e){this.lostListeners.push(e)}onRestored(e){this.restoredListeners.push(e)}destroy(){let e=this.gl;Ee.live===this&&(Ee.live=null),this.canvas.removeEventListener("webglcontextlost",this.onContextLost),this.canvas.removeEventListener("webglcontextrestored",this.onContextRestored);try{for(let t of this.textures.values())t&&e.deleteTexture(t);for(let t of this.layers)t&&(e.deleteTexture(t.gl),e.deleteFramebuffer(t.fb));this.fxr?.destroy(),this.fxr=null,e.deleteBuffer(this.dynamic),e.deleteBuffer(this.index),this.staticBuf&&e.deleteBuffer(this.staticBuf),this.vao&&this.vaoApi&&this.vaoApi.remove(this.vao),e.deleteProgram(this.main.p),e.getExtension("WEBGL_lose_context")?.loseContext()}catch{}this.textures.clear()}};function zo(s,n,e){let t=s.createShader(n);if(s.shaderSource(t,e),s.compileShader(t),!s.getShaderParameter(t,s.COMPILE_STATUS)){let r=s.getShaderInfoLog(t)??"?";throw s.deleteShader(t),new Error(r)}return t}function zr(s="auto"){switch(s){case"canvas2d":return["canvas2d"];case"webgl1":return["webgl1","canvas2d"];default:return["webgl2","webgl1","canvas2d"]}}function qt(s,n={}){let e=s;for(let t of zr(n.renderer)){let r=t==="canvas2d"?Xt(e):Ho(e,t==="webgl2"?2:1,n);if(r)return r;e=wn(e)}throw new Error("No renderer: this browser has neither WebGL nor Canvas 2D")}function wn(s){let n=s.cloneNode(!1);return s.parentNode?.replaceChild(n,s),n}function $o(s=typeof location<"u"?location.search:""){let n=new URLSearchParams(s).get("renderer");return n==="canvas"?"canvas2d":n==="webgl2"||n==="webgl1"||n==="canvas2d"||n==="webgl"||n==="auto"?n:void 0}var dt=class{constructor(n,e={}){p(this,"atlas",n);p(this,"tags",new Map);p(this,"count",0);p(this,"m",nt());p(this,"measure",null);p(this,"height");p(this,"font");this.height=e.tagHeight??34,this.font=e.tagFont??"Nunito, sans-serif"}drop(){for(let n of this.tags.values())for(let e of n.values())for(let t of e.values())this.atlas.release(t);this.tags.clear(),this.count=0}get(n,e,t){let r=this.tags.get(n);r||this.tags.set(n,r=new Map);let o=r.get(e);o||r.set(e,o=new Map);let a=o.get(t);return a&&this.atlas.valid(a)?a:this.bake(n,e,t)}bake(n,e,t){let r=this.height,o=`700 ${Math.round(r*.65)}px ${this.font}`,a=this.measure??(this.measure=document.createElement("canvas").getContext("2d"));a.font=o;let i=Math.round(r*.4),l=Math.ceil(a.measureText(n).width)+i*2,c=this.atlas.bake((l+2)*t,(r+2)*t,h=>{h.scale(t,t),h.translate(1,1);let b=r/2;h.beginPath(),h.moveTo(b,0),h.lineTo(l-b,0),h.arc(l-b,b,b,-Math.PI/2,Math.PI/2),h.lineTo(b,r),h.arc(b,b,b,Math.PI/2,Math.PI*3/2),h.closePath(),h.fillStyle=e,h.fill(),h.fillStyle="#fff",h.font=o,h.textAlign="center",h.textBaseline="middle",h.fillText(n,l/2,r/2+1)},t,1,1,1);++this.count>64&&(this.drop(),this.count=1);let u=this.tags.get(n);u||this.tags.set(n,u=new Map);let f=u.get(e);return f||u.set(e,f=new Map),f.set(t,c),c}draw(n,e,t,r,o,a,i,l,c,u,f){let h=Ot(t,o,{band:Xi(r)});if(!h)return;let b=this.height,y=this.get(a,i,c),m=y.w/y.scale-2,d=Math.min(Math.max(h.head.x-m/2,4),u-m-4),x=Math.min(Math.max(h.head.y-h.headR*2.2-b,4),f-b-4);Te(this.m,null,d-1,x-1,0,1,1),n.quad(e(y.surface),y,this.m,y.w/y.scale,y.h/y.scale,16777215,l,"normal")}},Xi=s=>s.band==="3-5"||s.band==="9-12"?s.band:"6-8";var ji=(s,n=!1)=>n?Math.min(2**Math.round(Math.log2(Math.max(s,8))),256):Math.min(2**(Math.ceil(Math.log2(Math.max(s,8))*2)/2),512);function nr(s,n=null){let e={minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0},t=(r,o,a)=>{let i=n?n[0]*r+n[2]*o+n[4]:r,l=n?n[1]*r+n[3]*o+n[5]:o,c=n?Math.hypot(n[0],n[1]):1;e.minX=Math.min(e.minX,i-a*c),e.minY=Math.min(e.minY,l-a*c),e.maxX=Math.max(e.maxX,i+a*c),e.maxY=Math.max(e.maxY,l+a*c)};for(let r of s){let o="lw"in r&&r.stroke?(r.lw??1)/2:0;switch(r.k){case"circle":t(r.x-r.r,r.y-r.r,o),t(r.x+r.r,r.y+r.r,o),t(r.x-r.r,r.y+r.r,o),t(r.x+r.r,r.y-r.r,o);break;case"ellipse":case"rect":{let a=r.k==="ellipse"?Math.max(r.rx,r.ry):Math.hypot(r.w,r.h)/2;t(r.x-a,r.y-a,o),t(r.x+a,r.y+a,o),t(r.x-a,r.y+a,o),t(r.x+a,r.y-a,o);break}case"path":{let a=Qn(r.d);for(let i=0;i<a.count;i++){let l=a.subs[i];for(let c=0;c<l.n;c++)t(l.pts[c*2],l.pts[c*2+1],o)}break}case"line":for(let a=0;a+1<r.pts.length;a+=2)t(r.pts[a],r.pts[a+1],o);break;case"group":{let a=Te(nt(),n,r.x,r.y,r.rot??0,r.s??1,r.s??1),i=nr(r.items,a);Number.isFinite(i.minX)&&(e.minX=Math.min(e.minX,i.minX),e.minY=Math.min(e.minY,i.minY),e.maxX=Math.max(e.maxX,i.maxX),e.maxY=Math.max(e.maxY,i.maxY));break}}}return e}var Et=class{constructor(n){p(this,"atlas",n);p(this,"seen",new WeakSet);p(this,"baked",new WeakMap);p(this,"m",nt());p(this,"stack",[]);p(this,"local",nt());p(this,"pts",new Float64Array(128));p(this,"stats",{baked:0,vector:0});p(this,"bakeGroups",!0);p(this,"coarse",!1);p(this,"gen",0);p(this,"live",new Set)}setTier(n){let e=n==="low";if(e!==this.coarse){this.coarse=e,this.gen++;for(let t of this.live)this.atlas.release(t.frame);this.live.clear()}}draw(n,e,t,r,o,a,i){let l=typeof r=="string"?Nt(r)??vt:r,c=ln(t,l,o);return c.length?(a<=0||(a<1?(this.paint(n,e,c,null,n.beginLayer()?1:a,i),n.endLayer(a)):this.paint(n,e,c,null,a,i)),!0):!1}paint(n,e,t,r,o,a,i=0){var l;for(let c=0;c<t.length;c++){let u=t[c];if(u.k==="group"){let g=Te((l=this.stack)[i]??(l[i]=nt()),r,u.x,u.y,u.rot??0,u.s??1,u.s??1),A=o*(u.alpha??1);if(this.bakeGroups&&this.seen.has(u.items)){let w=je(g[0],g[1])*a,v=this.bake(u.items,w);if(v){let E=v.frame,F=this.m;F.set(g),F[4]=g[0]*-v.ox+g[2]*-v.oy+g[4],F[5]=g[1]*-v.ox+g[3]*-v.oy+g[5],n.quad(e(E.surface),E,F,E.w/v.k,E.h/v.k,16777215,A,"normal"),this.stats.baked++;continue}}this.seen.add(u.items),this.stats.vector++,this.paint(n,e,u.items,g,A,a,i+1);continue}let f=o*(u.alpha??1),h=r?je(r[0],r[1]):1,b=r?Math.atan2(r[1],r[0]):0,y=(u.lw??1)*h,m=u.stroke&&(u.lw??1)>0?me(u.stroke):null,d=u.fill&&u.k!=="line"?me(u.fill):null;if(u.k==="circle"||u.k==="ellipse"){let g=r?r[0]*u.x+r[2]*u.y+r[4]:u.x,A=r?r[1]*u.x+r[3]*u.y+r[5]:u.y,w=(u.k==="circle"?u.r:u.rx)*h,v=(u.k==="circle"?u.r:u.ry)*h,E=(u.k==="ellipse"?u.rot??0:0)+b;if(d&&m)n.ellipse(g,A,w+y/2,v+y/2,E,m[0],f*m[1]),n.ellipse(g,A,Math.max(w-y/2,0),Math.max(v-y/2,0),E,d[0],f*d[1]);else if(d)n.ellipse(g,A,w,v,E,d[0],f*d[1]);else if(m){let F=Math.min(Math.max(Math.ceil(Math.max(w,v)*a*.6),12),64),L=this.pts=Kn(this.pts,F*2),_=Math.cos(E),D=Math.sin(E);for(let H=0;H<F;H++){let W=H/F*Math.PI*2,G=Math.cos(W)*w,be=Math.sin(W)*v;L[H*2]=g+G*_-be*D,L[H*2+1]=A+G*D+be*_}n.stroke(L,F,y,m[0],f*m[1],!0)}continue}if(u.k==="line"){if(!m)continue;let g=u.pts.length>>1,A=this.pts=Kn(this.pts,g*2);for(let w=0;w<g;w++){let v=u.pts[w*2],E=u.pts[w*2+1];A[w*2]=r?r[0]*v+r[2]*E+r[4]:v,A[w*2+1]=r?r[1]*v+r[3]*E+r[5]:E}n.stroke(A,g,y,m[0],f*m[1],!1);continue}let x=u.k==="path"?Qn(u.d,r,h*a):qi(u,Te(this.local,r,u.x,u.y,u.rot??0,1,1),a*h);for(let g=0;g<x.count;g++){let A=x.subs[g],w=A.n,v=u.k==="rect"||A.closed;d&&w>=3&&(n.polygon(A.pts,w,d[0],f*d[1]),m||n.stroke(A.pts,w,1/a,d[0],f*d[1],!0)),m&&n.stroke(A.pts,w,y,m[0],f*m[1],v)}}}bake(n,e){let t=ji(e,this.coarse),r=this.baked.get(n),o=r?.get(t);if(o&&o.gen===this.gen&&this.atlas.valid(o.frame))return o;o&&this.live.delete(o);let a=nr(n);if(!Number.isFinite(a.minX))return null;let i=2/t,l=(a.maxX-a.minX+i*2)*t,c=(a.maxY-a.minY+i*2)*t;if(l>1024||c>1024)return null;let u=-a.minX+i,f=-a.minY+i,b={frame:this.atlas.bake(l,c,y=>{y.scale(t,t),y.translate(u,f),Lt(y,n)}),k:t,ox:u,oy:f,gen:this.gen};return r||this.baked.set(n,r=new Map),r.set(t,b),this.live.add(b),b}},Yt=new Array(36).fill(0),Kt=0,qe=(s,n=NaN,e=NaN,t=NaN,r=NaN)=>{Yt[Kt++]=s,s!==ke.Z&&(Yt[Kt++]=n,Yt[Kt++]=e,s===ke.Q&&(Yt[Kt++]=t,Yt[Kt++]=r))};function qi(s,n,e){let t=Math.max(0,Math.min(s.r,s.w/2,s.h/2)),r=-s.w/2,o=-s.h/2,{M:a,L:i,Q:l,Z:c}=ke;return Kt=0,qe(a,r+t,o),qe(i,r+s.w-t,o),qe(l,r+s.w,o,r+s.w,o+t),qe(i,r+s.w,o+s.h-t),qe(l,r+s.w,o+s.h,r+s.w-t,o+s.h),qe(i,r+t,o+s.h),qe(l,r,o+s.h,r,o+s.h-t),qe(i,r,o+t),qe(l,r,o,r+t,o),qe(c),Qn(Yt,n,e)}function Go(s,n={}){let e=qt(s,n),t=new ht(Math.min(1024,e.maxTextureSize),2);t.onDrop=v=>{v.texture&&e.destroyTexture(v.texture),v.texture=null};let r=new Et(t),o=new xn,a=new Map,i=1e6,l=n.smooth===!1?1:typeof n.smooth=="number"?Math.min(Math.max(n.smooth,.05),1):.5,c=vn(e),u=new dt(t,n),f={w:1,h:1},h=1,b=0,y=!1,m=()=>u.drop(),d=typeof document<"u"?document.fonts:void 0;d?.ready?.then(()=>{y||m()}),d?.addEventListener?.("loadingdone",m);let x=()=>{let v=wn(e.canvas),E=Xt(v);if(E){console.warn("[engine] avatars: WebGL context lost for good, switching to Canvas 2D"),e.destroy(),e=E;for(let F of t.pages)F.surface.texture=null;c=vn(e),b=0}},g=()=>{if(!e.lost)return b=0,!0;let v=performance.now();return b||(b=v),v-b>3e3&&x(),!e.lost},A=()=>{let v=e.canvas;n.units?(h=n.pixelRatio??1,f.w=n.units.width,f.h=n.units.height):(h=n.pixelRatio??Math.min(globalThis.devicePixelRatio||1,2),f.w=v.clientWidth||v.width/h,f.h=v.clientHeight||v.height/h),e.resize(Math.max(1,Math.round(f.w*h)),Math.max(1,Math.round(f.h*h))),e.begin(0,0,h)},w=(v,E)=>{if(v.key===void 0)return v.id??E+1;let F=a.get(v.key);return F===void 0&&(a.size>256&&a.clear(),a.set(v.key,F=i++)),F};return{get renderer(){return e},get kind(){return e.kind},get lost(){return e.lost},get canvas(){return e.canvas},draw(v,E){if(g()){A();for(let F=0;F<v.length;F++){let L=v[F];if(!Array.isArray(L.body))continue;let _=w(L,F),D=l<1||n.interpolate!==!1?o.posed(_,L.body,l,n.interpolate!==!1):L.body,H=Nt(L.avatar??"")??vt,W=L.alpha??1;!r.draw(e,c,D,H,E,W,h)||!L.name||u.draw(e,c,D,H,E,L.name,L.color??"#6FA0E0",W,h,f.w,f.h)}e.end()}},clear(){g()&&(A(),e.end())},reset(){o=new xn,a.clear()},destroy(){y=!0,d?.removeEventListener?.("loadingdone",m),e.destroy()}}}var tr=new Map;function Uo(s,n,e=Math.min(globalThis.devicePixelRatio||1,2)){let t=`${s}|${n}|${e}`,r=tr.get(t);if(r)return r;r=document.createElement("canvas"),r.width=r.height=Math.round(n*e);let o=r.getContext("2d");return o.scale(e,e),o.beginPath(),o.rect(0,0,n,n),o.clip(),Lt(o,Ys(Nt(s)??vt,n)),tr.size>64&&tr.clear(),tr.set(t,r),r}function vn(s){return n=>{if(n.texture||(n.texture=s.createTexture(n.source),n.pending.length=0),n.pending.length){for(let[e,t,r]of n.pending)s.updateTexture(n.texture,e,t,r);n.pending.length=0}return n.texture}}var Hr='Fredoka, Nunito, "Varela Round", system-ui, sans-serif',Rt="rgba(10,16,30,0.75)";function $r(s,n){let e=s.size??40,t=s.outline?s.outline===!0?Rt:s.outline:null,r=t?s.outlineWidth??Math.max(e*.12,3):0,o=s.shadow&&n?s.shadow===!0?Rt:s.shadow:null,a=o?s.shadowBlur??e*.25:0;return{size:e,font:s.font??Hr,weight:s.weight??700,color:s.color??"#FBEFE3",outline:t,ow:r,shadow:o,blur:a,pad:r/2+a*1.2+2,th:e*1.25}}var Vo=(s,n)=>`${s.weight} ${s.size*n}px ${s.font}`;function Gr(s,n,e,t,r,o){s.scale(t,t),s.font=Vo(e,1),s.textBaseline="middle",s.textAlign="left",s.lineJoin="round",e.shadow&&(s.shadowColor=e.shadow,s.shadowBlur=e.blur*t),e.outline&&(s.strokeStyle=e.outline,s.lineWidth=e.ow,s.strokeText(n,r,o),s.shadowColor="transparent"),s.fillStyle=e.color,s.fillText(n,r,o)}var rr=null;function Ur(s,n,e){return rr??(rr=document.createElement("canvas").getContext("2d")),rr.font=Vo(n,e),rr.measureText(s).width/e}var Ye=class extends Re{constructor(e,t,r={}){super(e,null);p(this,"_text");p(this,"_style");p(this,"dirty",!0);p(this,"bakedScale",0);p(this,"bakedFontGen",-1);p(this,"bakedEffects",!0);p(this,"capW",0);p(this,"capH",0);this._text=t;let{x:o,y:a,rotation:i,scale:l,scaleX:c,scaleY:u,alpha:f,visible:h,tint:b,blend:y,z:m,anchor:d,hitRadius:x,clip:g,mask:A,filters:w,...v}=r;this._style=v,this.bake(),this.set({x:o,y:a,rotation:i,scale:l,scaleX:c,scaleY:u,alpha:f,visible:h,tint:b,blend:y,z:m,hitRadius:x,clip:g,mask:A,filters:w}),d!==void 0&&(this.anchor=d)}get text(){return this._text}set text(e){let t=String(e);t!==this._text&&(this._text=t,this.dirty=!0)}get style(){return this._style}set style(e){this._style={...this._style,...e},this.dirty=!0}bitmap(){let e=this._style.bitmapFont;if(!e)return null;let t=typeof e=="string"?this.kernel.bitmapFont(e):e;if(this.autoAnchor){let r=this._style.align;this.anchorX=r==="left"?0:r==="right"?1:.5,this.anchorY=.5}return t}get naturalWidth(){let e=this.bitmap();return e?e.measure(this._text)*((this._style.size??e.size)/e.size):super.naturalWidth}get naturalHeight(){let e=this.bitmap();return e?e.lineHeight*((this._style.size??e.size)/e.size):super.naturalHeight}frameNow(){return this._style.bitmapFont?null:this.bake()}draw(e,t,r){let o=this.bitmap();if(!o)return super.draw(e,t,r);let a=(this._style.size??o.size)/o.size,i=o.measure(this._text)*a,l=o.lineHeight*a,c=this.width,u=this.height,f=i>0?c/i:1,h=l>0?u/l:1;o.run(this._text,e,this.world,-this.anchorX*c,-this.anchorY*u,a*f,a*h,r,t,this.blend)}destroy(){this._frame&&this.kernel.atlas.release(this._frame),super.destroy()}bake(){let e=this.kernel;if(this._style.bitmapFont)return null;let t=e.pixelScale,r=e.effects;return!this.dirty&&t===this.bakedScale&&e.fontGen===this.bakedFontGen&&r===this.bakedEffects&&e.atlas.valid(this._frame)?this._frame:this.rebake()}rebake(){let e=this.kernel,t=e.pixelScale,r=e.effects;this.dirty=!1,this.bakedScale=t,this.bakedFontGen=e.fontGen,this.bakedEffects=r;let o=$r(this._style,r),{pad:a,th:i}=o,l=Ur(this._text,o,t),c=(l+a*2)*t,u=(i+a*2)*t,f=this._style.align??"center",h=f==="left"?a:f==="right"?a+l:a+l/2,b=d=>Gr(d,this._text,o,t,a,a+i/2),y=this._frame,m=null;return y&&e.atlas.valid(y)&&y.scale===t&&(m=e.atlas.rebake(y,c,u,b,this.capW,this.capH),m?Object.assign(m,{ox:h,oy:a+i/2,margin:a}):e.atlas.release(y)),m||(this.capW=Math.ceil(c*1.25+16),this.capH=Math.ceil(u),m=e.atlas.bake(this.capW,this.capH,b,t,h,a+i/2,a),m.w=Math.ceil(c),m.h=Math.ceil(u)),this._frame=m,this.autoAnchor&&this.useFrameAnchor(),this._w=this._h=null,m}};var ue=(s,n=0)=>{let e=Number(s);return Number.isFinite(e)?e:n};function Zt(s){typeof s=="string"&&/^\s*[{[]/.test(s)&&(s=JSON.parse(s));let n={size:0,lineHeight:0,base:0,pages:[],chars:[],kernings:[]},e=(t,r)=>{t==="info"?n.size=Math.abs(ue(r.size)):t==="common"?(n.lineHeight=ue(r.lineHeight),n.base=ue(r.base)):t==="page"?n.pages[ue(r.id)]=String(r.file??""):t==="char"?n.chars.push({id:ue(r.id),x:ue(r.x),y:ue(r.y),width:ue(r.width),height:ue(r.height),xoffset:ue(r.xoffset),yoffset:ue(r.yoffset),xadvance:ue(r.xadvance),page:ue(r.page)}):n.kernings.push({first:ue(r.first),second:ue(r.second),amount:ue(r.amount)})};if(typeof s=="object"){let t=s;e("info",t.info??{}),e("common",t.common??{});for(let[r,o]of(t.pages??[]).entries())e("page",{id:r,file:o});for(let r of t.chars??[])e("char",r);for(let r of t.kernings??[])e("kerning",r)}else{let t=/(?:^|<)\s*(info|common|page|char|kerning)\s([^\n<>]*)/gm,r=/(\w+)=(?:"([^"]*)"|([^\s/>]+))/g;for(let o=t.exec(s);o;o=t.exec(s)){let a={};for(let i=r.exec(o[2]);i;i=r.exec(o[2]))a[i[1]]=i[2]??i[3];e(o[1],a)}}return n.size||(n.size=n.lineHeight),n}var Qt=class{constructor(n,e,t,r=null,o=null){p(this,"baker",r);p(this,"host",o);p(this,"size");p(this,"lineHeight");p(this,"base");p(this,"ascii",new Array(128));p(this,"more",new Map);p(this,"kern",new Map);p(this,"bScale",0);p(this,"bFontGen",-1);p(this,"bEffects",!1);p(this,"bGen",-1);this.size=n,this.lineHeight=e,this.base=t}set(n,e){n<128?this.ascii[n]=e:this.more.set(n,e)}setKerning(n,e,t){this.kern.set(n*1114112+e,t)}prepare(){let n=this.host;if(!(!n||n.pixelScale===this.bScale&&n.fontGen===this.bFontGen&&n.effects===this.bEffects&&n.atlas.gen===this.bGen)){this.bScale=n.pixelScale,this.bFontGen=n.fontGen,this.bEffects=n.effects,this.bGen=n.atlas.gen;for(let e of this.ascii)e&&n.atlas.release(e.frame);for(let e of this.more.values())e&&n.atlas.release(e.frame);this.ascii.fill(void 0),this.more.clear()}}glyph(n){let e=n<128?this.ascii[n]:this.more.get(n);return(e===void 0||e&&this.host&&!this.host.atlas.valid(e.frame))&&(e=this.baker?this.baker(n):null,this.set(n,e)),e}kerning(n,e){return this.kern.size?this.kern.get(n*1114112+e)??0:0}measure(n){return this.run(n)}run(n,e,t,r=0,o=0,a=1,i=1,l=0,c=1,u="normal"){this.prepare();let f=0,h=-1;for(let b=0;b<n.length;b++){let y=n.charCodeAt(b);y>=55296&&y<56320&&b+1<n.length&&(y=n.codePointAt(b),b++),h>=0&&(f+=this.kerning(h,y)),h=y;let m=this.glyph(y);m&&(e&&m.w>0&&m.h>0&&(bn(t,r+(f+m.x)*a,o+m.y*i),e.r.quad(e.tex(m.frame.surface),m.frame,ie,m.w*a,m.h*i,l,c,u)),f+=m.advance)}return f}};function Wo(s,n){let e=new Qt(s.size,s.lineHeight,s.base);for(let t of s.chars){let r=n[t.page];if(!r)continue;let o={surface:r,x:t.x,y:t.y,w:t.width,h:t.height,scale:1,gen:0,ox:0,oy:0,margin:0};e.set(t.id,{frame:o,x:t.xoffset,y:t.yoffset,w:t.width,h:t.height,advance:t.xadvance})}for(let t of s.kernings)e.setKerning(t.first,t.second,t.amount);return e}function Xo(s,n){let e={...n},t=n.size??40,r=a=>{let i=String.fromCodePoint(a),l=s.pixelScale,c=$r(e,s.effects),u=Ur(i,c,l),f=s.atlas.bake((u+c.pad*2)*l,(c.th+c.pad*2)*l,h=>Gr(h,i,c,l,c.pad,c.pad+c.th/2),l);return{frame:f,x:-c.pad,y:-c.pad,w:f.w/l,h:f.h/l,advance:u}},o=new Qt(t,t*1.25,t,r,s);o.prepare();for(let a of n.chars??"0123456789")o.glyph(a.codePointAt(0));return o}var Yi=.5;function Vr(s){let n=[];for(let[e,t]of[["left",Y.leftWrist],["right",Y.rightWrist]]){let r=s[t*3],o=s[t*3+1],a=s[t*3+2];r!==void 0&&o!==void 0&&Number.isFinite(r)&&Number.isFinite(o)&&(a??0)>=Yi&&n.push({side:e,x:r,y:o})}return n}var An=s=>on[((s-1)%on.length+on.length)%on.length];function sr(s,n,e,t,r=()=>null){let o=[];for(let a of s){let i=r(a)??a.body;if(Array.isArray(i))for(let l of Vr(i)){let c=n(l);o.push({player:a.id,side:l.side,x:c.x*e,y:c.y*t,color:An(a.id)})}}return o}function Sn(s,n,e,t=0){let r=s.world,o=Js(r,n,e);if(!o)return!1;let a=Math.hypot(r[0],r[1])||1,i=Math.hypot(r[2],r[3])||1,[l,c]=o;if(s.hitRadius!=null){let y=s.hitRadius+t/((a+i)/2);return l*l+c*c<=y*y}let u=-s.anchorX*s.width-t/a,f=-s.anchorY*s.height-t/i,h=(1-s.anchorX)*s.width+t/a,b=(1-s.anchorY)*s.height+t/i;return l>=u&&l<=h&&c>=f&&c<=b}function or(s,n,e,t=0){for(let r of n)if((e===void 0||r.player===e)&&Sn(s,r.x,r.y,t))return r;return null}function Ki(s){switch(s.type){case"circle":case"ring":case"star":return[s.r*2,s.r*2];case"ellipse":return[s.rx*2,s.ry*2];case"roundRect":return[s.w,s.h];case"line":return[s.length,s.lw??4];case"path":return s.r?[s.r*2,s.r*2]:[s.size,s.size]}}function Qi(s){let n=s.type==="line"?0:s.stroke?(s.lw??2)/2:0,e=s.shadow?s.shadow.blur*1.5+Math.max(Math.abs(s.shadow.x??0),Math.abs(s.shadow.y??0)):0;return Math.ceil(n+e+1)}var jo=(s,n)=>n||!s.shadow?s:{...s,shadow:void 0};function Wr(s,n,e){let t=Qi(n),r=n.type==="roundRect",[o,a]=r?[Math.min(n.w,n.r*2+4/e),Math.min(n.h,n.r*2+4/e)]:Ki(n),i=(o+t*2)*e,l=(a+t*2)*e;return{frame:s.bake(i,l,u=>{u.scale(e,e),u.translate(t+o/2,t+a/2),Zi(u,n,o,a)},e,t+o/2,t+a/2,t),slice:r?Math.ceil((n.r+t)*e):0,w:r?n.w:o,h:r?n.h:a}}function Zi(s,n,e,t){s.lineJoin="round",s.lineCap="round";let r=new Path2D;switch(n.type){case"circle":case"ring":r.arc(0,0,n.r,0,Math.PI*2);break;case"ellipse":r.ellipse(0,0,n.rx,n.ry,0,0,Math.PI*2);break;case"roundRect":r.roundRect(-e/2,-t/2,e,t,Math.min(n.r,e/2,t/2));break;case"star":{let c=n.points??5,u=n.r*(n.inner??.5);for(let f=0;f<c*2;f++){let h=f%2?u:n.r,b=-Math.PI/2+f*Math.PI/c;f?r.lineTo(Math.cos(b)*h,Math.sin(b)*h):r.moveTo(Math.cos(b)*h,Math.sin(b)*h)}r.closePath();break}case"line":r.moveTo(-e/2+t/2,0),r.lineTo(e/2-t/2,0);break;case"path":{let c=n.r?n.r*2/n.size:1,u=new DOMMatrix([c,0,0,c,-n.size/2*c,-n.size/2*c]);r.addPath(new Path2D(n.d),u);break}}let o=n.shadow,a=()=>{if(!o)return;let c=s.getTransform();s.shadowColor=o.color,s.shadowBlur=o.blur*c.a,s.shadowOffsetX=(o.x??0)*c.a,s.shadowOffsetY=(o.y??0)*c.a},i=()=>{s.shadowColor="transparent",s.shadowBlur=0};if(n.type==="line"){a(),s.strokeStyle=n.stroke??n.fill??"#fff",s.lineWidth=t,s.stroke(r);return}let l=n.type==="ring";if(n.outlineBelow&&n.fill&&n.stroke&&!l){a(),s.strokeStyle=n.stroke,s.lineWidth=n.lw??2,s.stroke(r),i(),s.fillStyle=n.fill,s.fill(r);return}n.fill&&!l&&(a(),s.fillStyle=n.fill,s.fill(r),i()),(n.stroke||l)&&((!n.fill||l)&&a(),l&&n.fill&&(s.fillStyle=n.fill,s.fill(r)),s.strokeStyle=n.stroke??"#fff",s.lineWidth=n.lw??2,s.stroke(r),i())}var Jt=class{constructor(){p(this,"ctx",null);p(this,"master",null);p(this,"buffers",new Map);p(this,"held",!1);p(this,"muted",!1);p(this,"volume",1);if(typeof addEventListener=="function"){let n=()=>{this.context()?.resume().catch(()=>{})};for(let e of["pointerdown","keydown","touchstart"])addEventListener(e,n,{once:!0,capture:!0})}}context(){if(this.ctx)return this.ctx;let n=globalThis.AudioContext??globalThis.webkitAudioContext;if(!n)return null;try{this.ctx=new n,this.master=this.ctx.createGain(),this.master.connect(this.ctx.destination),this.held&&this.ctx.suspend()}catch{return null}return this.ctx}async load(n,e){let t=this.context();if(!t)return;let r=await(await fetch(e)).arrayBuffer();this.buffers.set(n,await t.decodeAudioData(r))}has(n){return this.buffers.has(n)}play(n,e={}){let t=this.context(),r=this.buffers.get(n);if(!t||!r||!this.audible)return()=>{};let o=t.createBufferSource();o.buffer=r,o.loop=e.loop??!1,o.playbackRate.value=e.rate??1;let a=t.createGain();return a.gain.value=(e.volume??1)*this.volume,o.connect(a).connect(this.master),o.start(),()=>{try{o.stop()}catch{}}}tone(n,e=.25,t={}){let r=this.context();if(!(!r||!this.audible))try{let o=r.createOscillator(),a=r.createGain();o.type=t.type??"sine",o.frequency.setValueAtTime(n,r.currentTime),t.to&&o.frequency.exponentialRampToValueAtTime(t.to,r.currentTime+e),a.gain.setValueAtTime((t.volume??.12)*this.volume,r.currentTime),a.gain.exponentialRampToValueAtTime(.001,r.currentTime+e),o.connect(a).connect(this.master),o.start(),o.stop(r.currentTime+e)}catch{}}get audible(){return!this.muted&&!this.held}hold(){this.held=!0,this.ctx?.suspend().catch(()=>{})}release(){this.held=!1,this.ctx?.resume().catch(()=>{})}destroy(){this.ctx?.close().catch(()=>{}),this.ctx=null}};var Ji={high:{resolution:1.5,particles:1,effects:!0,maxBlur:32},medium:{resolution:1,particles:.5,effects:!1,maxBlur:16},low:{resolution:.75,particles:.2,effects:!1,maxBlur:0}},Ke=["high","medium","low"];function at(s){let n=Ji[s];return{name:s,...n,scale:e=>e<=0?0:Math.max(1,Math.round(e*n.particles))}}var qo=s=>Ke[Math.min(Ke.indexOf(s)+1,Ke.length-1)],ar=(s,n)=>{if(!s.length)return NaN;let e=[...s].sort((t,r)=>t-r);return e[Math.min(e.length-1,Math.max(0,Math.floor(n*(e.length-1)+.5)))]},Yo=12,Ko=s=>Mn(s,.5);function Mn(s,n=.1){let e=ar(s,n);if(!Number.isFinite(e))return 1e3/60;let t=[144,120,90,75,60,50,30],r=60;for(let o of t)Math.abs(1e3/o-e)<Math.abs(1e3/r-e)&&(r=o);return 1e3/r}function ir(s,n){let e=n.refresh!==void 0&&Number.isFinite(n.refresh)&&n.refresh>0?n.refresh:Mn(n.intervals),t=ar(n.intervals,.5),r=ar(n.intervals,.9),o=ar(n.cpu,.5);if(!Number.isFinite(t))return s==="canvas2d"?"low":"medium";let a=l=>l<=e*1.25,i=l=>!Number.isFinite(o)||o<e*l;return s==="canvas2d"?a(r)&&i(.25)?"medium":"low":a(r)&&i(.5)?"high":a(t)?"medium":"low"}function Qo(s,n){return s.length<30?!1:s.filter(t=>t>n*1.5).length/s.length>.5}var Zo="0.1.1",el=720*3600*1e3,Jo=(s,n,e)=>`fabi-play.engine-tier:${Zo}:${s}:${n}:${e}`,ea=(s,n,e)=>`fablee-engine-tier:${Zo}:${s}:${n}:${e}`;function ta(s,n,e=Date.now()){try{let t=JSON.parse(s?.getItem(n)??"null");if(t&&Ke.includes(t.tier)&&typeof t.at=="number"&&e-t.at<el)return typeof t.refresh=="number"&&t.refresh>0?{name:t.tier,refresh:t.refresh}:{name:t.tier}}catch{}return null}function Xr(s,n,e,t,r=Date.now()){try{s?.setItem(n,JSON.stringify(t!==void 0&&Number.isFinite(t)?{tier:e,at:r,refresh:t}:{tier:e,at:r}))}catch{}}function na(s=typeof location<"u"?location.search:""){let n=new URLSearchParams(s).get("tier");return Ke.includes(n)?n:void 0}function jr(s,n){let e=n?.tier;if(Ke.includes(e))return s==="canvas2d"&&e==="high"?"medium":e}var qr=s=>typeof s?.hz=="number"&&s.hz>=20&&s.hz<=240?Mn([1e3/s.hz],.5):NaN,Yr=(s,n)=>Ke.indexOf(s)>=Ke.indexOf(n)?s:n;function ra(s,n,e){return s?{name:s,from:"forced"}:n?{name:e?Yr(n,e):n,from:"hint"}:e?{name:e,from:"cache"}:null}var tl=/^\s*(<|>|[^+\-<>=\s][^+=]*?)?\s*(?:([+-])=\s*(\d*\.?\d+))?\s*$/,en=class{constructor(n={}){p(this,"steps",[]);p(this,"labels",new Map);p(this,"end",0);p(this,"prevStart",0);p(this,"elapsed",0);p(this,"iter",0);p(this,"last",0);p(this,"delayLeft");p(this,"_paused");p(this,"done",!1);p(this,"rewinding",!1);p(this,"promise");p(this,"resolve");p(this,"repeat");p(this,"yoyo");p(this,"onComplete");this.repeat=Math.floor(n.repeat??0),this.yoyo=!!n.yoyo,this.delayLeft=n.delay??0,this._paused=!!n.paused,this.onComplete=n.onComplete,this.promise=new Promise(e=>this.resolve=e)}get duration(){return this.end}get time(){return this.last}get paused(){return this._paused}get finished(){return this.done}at(n){if(n===void 0)return this.end;if(typeof n=="number")return Math.max(n,0);let e=tl.exec(n);if(!e)throw new Error(`[engine] timeline: bad position "${n}"`);let[,t,r,o]=e,a=o?(r==="-"?-1:1)*Number(o):0,i=this.end;if(t==="<")i=this.prevStart;else if(t&&t!==">"){let l=this.labels.get(t.trim());l===void 0?this.labels.set(t.trim(),this.end):i=l}return Math.max(i+a,0)}add(n){let e=this.steps.length;for(;e>0&&this.steps[e-1].start>n.start;)e--;return this.steps.splice(e,0,n),this.prevStart=n.start,this.end=Math.max(this.end,n.start+n.dur),this}to(n,e,t,r="quadOut"){let o=typeof r=="object"?r:{ease:r},a=typeof o.ease=="function"?o.ease:ct[o.ease??"quadOut"];return this.add({target:n,to:e,from:null,fn:null,start:this.at(o.at)+(o.delay??0),dur:Math.max(t,0),ease:a,onUpdate:o.onUpdate,p:-1})}set(n,e,t){return this.add({target:n,to:e,from:null,fn:null,start:this.at(t),dur:0,ease:ct.linear,p:-1})}call(n,e){return this.add({target:null,to:null,from:null,fn:n,start:this.at(e),dur:0,ease:ct.linear,p:-1})}label(n,e){return this.labels.set(n,this.at(e)),this}wait(n){return this.end+=Math.max(n,0),this.prevStart=this.end,this}pause(){return this._paused=!0,this}resume(){return this._paused=!1,this}stop(){this.done||(this.done=!0,this.resolve())}seek(n){let e=Math.min(typeof n=="string"&&this.labels.has(n)?this.labels.get(n):this.at(n),this.end),t=this.yoyo&&this.iter%2===1;return this.elapsed=this.iter*this.end+(t?this.end-e:e),this.render(e),this}then(n,e){return this.promise.then(n,e)}update(n){if(this._paused||this.done)return;if(this.delayLeft>0){if(this.delayLeft-=n,this.delayLeft>0)return;n=-this.delayLeft,this.delayLeft=0}let e=this.end;if(e<=0)return this.render(0),this.complete();this.elapsed+=n;let t=this.repeat<0?1/0:e*(this.repeat+1),r=Math.min(this.elapsed,t),o=r>=t?this.repeat:Math.floor(r/e);for(;this.iter<o;){let i=this.yoyo&&this.iter%2===1;this.render(i?0:e),this.iter++,this.yoyo||(this.rewinding=!0,this.render(0),this.rewinding=!1)}let a=r-o*e;this.render(this.yoyo&&o%2===1?e-a:a),r>=t&&this.complete()}complete(){this.done||(this.done=!0,this.onComplete?.(),this.resolve())}render(n){let e=this.steps;if(n>=this.last)for(let t=0;t<e.length;t++){let r=e[t];n>=r.start&&this.apply(r,n)}else for(let t=e.length-1;t>=0;t--){let r=e[t];r.p>=0&&this.apply(r,n)}this.last=n}apply(n,e){let t=n.dur>0?Math.min(Math.max((e-n.start)/n.dur,0),1):e>n.start||e===n.start&&!this.rewinding?1:0;if(t===n.p)return;if(n.p=t,n.fn){this.rewinding||n.fn();return}let r=n.target;if(r.destroyed||r._free)return;let o=n.to;if(!n.from){n.from={};for(let i in o)n.from[i]=Number(r[i]??0)}let a=n.ease(t);for(let i in o)r[i]=n.from[i]+(o[i]-n.from[i])*a;n.onUpdate?.(a)}};var tn=class{constructor(){p(this,"list",[]);p(this,"timelines",[])}timeline(n){let e=new en(n);return this.timelines.push(e),e}tween(n,e,t,r="quadOut"){let o=typeof r=="object"?r:{ease:r},a=typeof o.ease=="function"?o.ease:ct[o.ease??"quadOut"],i,l=new Promise(c=>{let u=Object.keys(e),f=new Float64Array(u.length);u.forEach((h,b)=>f[b]=Number(e[h])),i={target:n,keys:u,to:f,from:new Float64Array(u.length),started:!1,duration:Math.max(t,0),time:0,delay:o.delay??0,ease:a,onUpdate:o.onUpdate,done:c,dead:!1}});return this.list.push(i),Object.assign(l,{stop:()=>this.finish(i)})}stopAll(n){let e=this.list;for(let t=0;t<e.length;t++)e[t].target===n&&this.finish(e[t])}get size(){return this.list.length}update(n){if(this.timelines.length){let r=0,o=this.timelines;for(let a=0;a<o.length;a++){let i=o[a];i.update(n),i.finished||(o[r++]=i)}o.length=r}let e=this.list;if(!e.length)return;let t=0;for(let r=0;r<e.length;r++){let o=e[r];o.dead||this.step(o,n),o.dead||(e[t++]=o)}t!==e.length&&(e.length=t)}step(n,e){if(n.target.destroyed)return this.finish(n);let t=e;if(n.delay>0){if(n.delay-=e,n.delay>0)return;t=-n.delay}let r=n.keys;if(!n.started){n.started=!0;for(let i=0;i<r.length;i++)n.from[i]=Number(n.target[r[i]]??0)}n.time+=t;let o=n.duration>0?Math.min(n.time/n.duration,1):1,a=n.ease(o);for(let i=0;i<r.length;i++)n.target[r[i]]=n.from[i]+(n.to[i]-n.from[i])*a;n.onUpdate?.(a),o>=1&&this.finish(n)}finish(n){n.dead||(n.dead=!0,n.done())}clear(){for(let n of this.list)this.finish(n);this.list.length=0;for(let n of this.timelines)n.stop();this.timelines=[]}};var he=720,Tn=class extends Ie{constructor(e,t){super(e);p(this,"paintAll",t)}draw(e,t){this.paintAll(e,t)}},Qr=class extends Ie{constructor(e,t){super(e);p(this,"paintAll",t)}draw(e,t){this.paintAll(e,t)}},mt=()=>performance.now();async function oa(s={}){let n=s.play??null,e=s.canvas??null;e||(e=document.createElement("canvas"),e.style.cssText="position:fixed;inset:0;width:100%;height:100%;display:block;touch-action:none",document.body.appendChild(e));let t=qt(e,{renderer:s.renderer??$o(),failIfMajorPerformanceCaveat:s.failIfMajorPerformanceCaveat,instancing:s.instancing});e=t.canvas;let r=new Set,o=new ht(Math.min(2048,t.maxTextureSize),4);o.onPage=k=>r.add(k),o.onDrop=k=>{r.delete(k),k.texture&&t.destroyTexture(k.texture),k.texture=null};let a=vn(t),i=new tn,l=new Jt,c=new Et(o),u=new Map,f=new Map,h=new Map,b=new Map,y=new Map,m=new Set,d=0,x=s.tier??na(),g=String(t.info.renderer??""),A=(()=>{try{return globalThis.localStorage??null}catch{return null}})(),w=typeof screen<"u"?`${screen.width}x${screen.height}`:"",v=Jo(t.kind,g,w);Fs(A,v,ea(t.kind,g,w));let E=ta(A,v),F=ra(x,jr(t.kind,n?.device),E?.name),L=F?.name??"medium",_=at(L);c.setTier(L);let D=F?.from==="hint",H=E?.name,W=E?.refresh??qr(n?.device),G=1,be=1,$=1,oe={atlas:o,get pixelScale(){return G},get fontGen(){return d},get effects(){return _.effects},tweens:i,frame:k=>Ln.frame(k),shape:k=>{let M=_.effects,C=M?G:-G,R=u.get(C);R||(u.size>=8&&u.clear(),u.set(C,R=new Vt(2e3)));let O=Ue(k),ne=R.get(k,O);return(!ne||!o.valid(ne.frame))&&R.set(k,ne=Wr(o,jo(k,M),G),O),ne},bitmapFont:k=>Ln.bitmapFont(k)},ye=1280,Ne=null;class hr extends Tt{get width(){return ye}set width(M){}get height(){return he}set height(M){}get safe(){let M=Math.min(ye,he*16/9);return{x:(ye-M)/2,y:0,w:M,h:he}}}let we=new hr(oe),Be=()=>{let k=t.canvas,M=k.getBoundingClientRect();be=Math.max(1,M.width||k.clientWidth||innerWidth),$=Math.max(1,M.height||k.clientHeight||innerHeight),ye=he*be/$;let C=Math.min(globalThis.devicePixelRatio||1,s.maxPixelRatio??2);if($*C/he<=_.resolution){let O=Math.max(1,Math.round($*C));G=O/he,t.resize(Math.max(1,Math.round(be*C)),O)}else G=_.resolution,t.resize(Math.round(ye*G),Math.round(he*G));Ne&&Ne.style.setProperty("--unit",`${$/he}px`)};addEventListener("resize",Be);let xe=k=>{L=k,_=at(k),c.setTier(k),Be()},fe=typeof ResizeObserver<"u"?new ResizeObserver(Be):null;fe?.observe(e);let De=n?.backdrop==="video"?"video":"none",S=n?.view??null,I=[],N=-1/0,X=!1,U=!1,le=new Set,Ft=()=>{let k=De==="video"?"transparent":"";document.documentElement.style.background=k,document.body.style.background=k},ze=(k,M)=>{let C=k==="video"?"video":"none",R=M??null;if(!(C===De&&(R===S||R&&S&&R.x===S.x&&R.y===S.y&&R.w===S.w&&R.h===S.h))){De=C,S=R,Ft();for(let O of[...le])O(De,S)}},nn=[];if(n){let k=R=>{Array.isArray(R)&&(I=R,N=mt())},M=R=>{X=R,pe()},C=R=>{if(x||D)return;Number.isFinite(W)||(W=qr(R));let O=jr(t.kind,R);O&&(D=!0,xe(H?Yr(O,H):O))};nn.push(n.on("start",R=>C(R?.device)),n.on("start",R=>{typeof R?.muted=="boolean"&&(l.muted=R.muted)}),n.on("frame",R=>k(R?.players)),n.on("players",R=>k(R?.players)),n.on("backdrop",R=>ze(R?.backdrop,R?.view)),n.on("start",R=>ze(R?.backdrop,R?.view??n.view)),n.on("pause",()=>M(!0)),n.on("resume",()=>M(!1)),n.on("break-start",()=>M(!0)),n.on("break-done",()=>M(!1)),n.on("break-end",()=>M(!1))),l.muted=n.muted===!0}Ft();let pe=()=>X||U||document.hidden?l.hold():l.release(),Ze=-1,Je=[],ve=0,Pe=()=>mt()-N<1e3?I:[],bt=k=>n?n.toScreen(k):Cs(S,k),Ae=()=>{if(Ze===ve)return Je;Ze=ve;let k=De==="video"||!n?.smoothedBody?()=>null:M=>n.smoothedBody(M);return Je=sr(Pe(),bt,ye,he,k),Je},He={x:0,y:0,w:1,h:1},fr=()=>(He.x=S?S.x*ye:0,He.y=S?S.y*he:0,He.w=S?S.w*ye:ye,He.h=S?S.h*he:he,He),Rn=k=>{let M=k.alpha??1,C=k.tags?new dt(o,k):null;C&&m.add(C);let R=typeof k.tags=="function"?k.tags:O=>String(O);return(O,ne)=>{if(De==="video")return;let z=fr();for(let V of Pe()){let de=n?.smoothedBody?.(V)??V.body,ee=Nt(n?.avatarOf?.(V)??V.avatar??"")??vt;if(!c.draw(O.r,O.tex,de,ee,z,M*ne,G)||!C)continue;let _e=R(V.id);_e&&C.draw(O.r,O.tex,de,ee,z,_e,An(V.id),M*ne,G,ye,he)}}},pr=new Set,dr=new Set,rn=new Set,Cn=!1,mr=0,Pt=0,Fn=0,yt={fps:0,cpuMs:0,drawCalls:0,quads:0,filtersSkipped:0},Pn=0,br=0,yr=mt(),sn=[],_n=0,gs=()=>({r:t,kernel:oe,tex:a}),ks=gs(),Ea=()=>{if(t.lost)return;let[k,M]=De==="video"||s.background===void 0?[0,0]:me(s.background);t.time=Fn,t.maxBlur=_.maxBlur,t.begin(k,M,G),Te(we.world,null,we.x,we.y,we.rotation,we.scaleX,we.scaleY),_r(ks,we,we.alpha,we.tint);let C=t.end();yt.drawCalls=C.drawCalls,yt.quads=C.quads,yt.filtersSkipped=C.filtersSkipped},ws=k=>{if(!Cn)return;mr=requestAnimationFrame(ws);let M=Math.min(Math.max((k-Pt)/1e3,0),.1);Pt&&sn.push(k-Pt),Pt=k,ve++;let C=mt(),R=X||U;if(!R){Fn+=M,i.update(M);for(let O of rn)O.destroyed||O.update(M);for(let O of pr)O(M,Fn)}for(let O of dr)O(M);we.sweep();for(let O of rn)O.destroyed&&rn.delete(O);if(t.lost?(_n||(_n=k),k-_n>3e3&&Ra()):(_n=0,Ea()),Pn++,br+=mt()-C,C-yr>=1e3&&(yt.fps=Math.round(Pn*1e3/(C-yr)),yt.cpuMs=Math.round(br/Math.max(Pn,1)*100)/100,n?.reportStats?.({fps:yt.fps,renderer:t.kind,tier:L}),Pn=0,br=0,yr=C),sn.length>=180){let O=Number.isFinite(W)?W:Mn(sn);!x&&!R&&Qo(sn,O)&&L!=="low"&&(xe(qo(L)),H=L,Xr(A,v,L,Number.isFinite(W)?W:void 0),console.info(`[engine] slow frames: tier ${L}`)),sn.length=0}},Ra=()=>{let k=wn(t.canvas),M=Xt(k);if(M){console.warn("[engine] WebGL context lost for good: switching to Canvas 2D"),t.destroy(),t=M;for(let C of r)C.texture=null;for(let C of o.pages)r.add(C.surface);a=vn(t),ks=gs(),fe?.disconnect(),fe?.observe(k),Be()}},vs=()=>{pe(),document.hidden||(Pt=0)};document.addEventListener("visibilitychange",vs);let As=()=>{d++;for(let k of m)k.drop()};if(document.fonts?.addEventListener?.("loadingdone",As),Be(),!F&&s.probe!==!1&&(Number.isFinite(W)||(W=Ko(await nl(Yo))),!D)){_=at("high"),Be();let k=await rl(t,o,()=>a,()=>G,ye,()=>D);if(k.refresh=W,!D){let M=ir(t.kind,k);Xr(A,v,M,W),H=M,xe(M)}}let Ln={stage:we,get tier(){return _},get renderer(){return t},get canvas(){return t.canvas},get pixelScale(){return G},get backdrop(){return De},get view(){return S},get paused(){return X||U},sound:l,stats:yt,get time(){return Fn},get supports(){let k=t.support;return{filters:k.filters,blur:k.filters&&_.maxBlur>0,shaders:k.shaders,maxBlur:k.filters?_.maxBlur:0,tiers:{high:{maxBlur:at("high").maxBlur},medium:{maxBlur:at("medium").maxBlur},low:{maxBlur:at("low").maxBlur}}}},sprite:(k,M)=>new Re(oe,k,M),shape:(k,M)=>new Xe(oe,k,M),text:(k,M)=>new Ye(oe,k,M),group:k=>new Tt(oe).set(k??{}),particles(k,M={}){let C=typeof k=="object"&&"type"in k?oe.shape(k).frame:k,R=new Ht(oe,C,M),{max:O,blend:ne,gravity:z,drag:V,...de}=M;return R.set(de),rn.add(R),R},tween:(k,M,C,R)=>i.tween(k,M,C,R),bake(k,M,C,R,O){return h.set(k,{w:M,h:C,draw:R,origin:O}),f.delete(k),Ln.frame(k)},frame(k){let M=f.get(k);if(M&&o.valid(M)&&(M.gen===0||M.scale===G))return M;let C=h.get(k);if(C){let R=G,O=o.bake(C.w*R,C.h*R,ne=>(ne.scale(R,R),C.draw(ne)),R,C.origin?.x??0,C.origin?.y??0);return f.set(k,O),O}if(M)return M;throw new Error(`[engine] no frame "${k}": load it or bake it first`)},async load(k){await Promise.all(Object.entries(k).map(([M,C])=>Fa(M,C)))},hands:k=>k===void 0?Ae():Ae().filter(M=>M.player===k),touched(k,M,C={}){return k.updateWorld(),or(k,Ae(),M,C.padding??0)},hits(k,M,C,R=0){return k.updateWorld(),Sn(k,M,C,R)},avatars:(k={})=>new Tn(oe,Rn(k)),handMarkers(k={}){let M=k.radius??36,C=k.look??"auto",R=new Float64Array(6),O=Math.max(M*.12,3),ne={type:"ring",r:M,lw:O,fill:"rgba(251,231,184,0.3)",stroke:"#ffffff"},z={type:"ring",r:M,lw:O*1.8,stroke:Rt,shadow:{color:Rt,blur:M*.2}},V=(xt,Se,_t,xr,In,gt)=>{let On=Se.w/Se.scale;Te(R,null,_t-On/2,xr-On/2,0,1,1),xt.r.quad(xt.tex(Se.surface),Se,R,On,On,In,gt,"normal")},de=xt=>{let Se=null,_t=!1;return()=>(Se&&o.valid(Se.frame)&&Se.frame.scale===G&&_t===_.effects?Se:(_t=_.effects,Se=oe.shape(xt))).frame},ee=de(ne),_e=de(z);return new Qr(oe,(xt,Se)=>{let _t=C==="video"||C==="auto"&&De==="video",xr=ee(),In=_t?_e():null;for(let gt of Ae())In&&V(xt,In,gt.x,gt.y,16777215,Se),V(xt,xr,gt.x,gt.y,me(gt.color)[0],Se)})},timeline:k=>i.timeline(k),animation(k,M){let C=typeof k=="string"?Ca(k):{frames:k},R=new Oe(oe,C,M);return rn.add(R),R},bitmapFont(k,M){if(!M){let R=b.get(k);if(!R)throw new Error(`[engine] no bitmap font "${k}": load or make it first`);return R}let C="data"in M?Ss(Zt(M.data),M.pages):Xo(oe,M);return b.set(k,C),C},players:()=>Pe(),onFrame(k){return pr.add(k),()=>{pr.delete(k)}},onRender(k){return dr.add(k),()=>{dr.delete(k)}},onBackdrop(k){return le.add(k),()=>{le.delete(k)}},get hud(){return Ne||(Ne=document.createElement("div"),Ne.style.cssText="position:fixed;inset:0;pointer-events:none;overflow:hidden",document.body.appendChild(Ne),Be()),Ne},random:(k=0,M=1)=>k+Math.random()*(M-k),start(){Cn||(Cn=!0,Pt=0,mr=requestAnimationFrame(ws))},pause(){U=!0,pe()},resume(){U=!1,pe()},destroy(){Cn=!1,cancelAnimationFrame(mr),nn.forEach(k=>k()),removeEventListener("resize",Be),fe?.disconnect(),document.removeEventListener("visibilitychange",vs),document.fonts?.removeEventListener?.("loadingdone",As),i.clear(),po(oe),l.destroy(),t.destroy(),Ne?.remove()}};function Ca(k){let M=y.get(k);if(M)return M;let C=[...new Set([...f.keys(),...h.keys()])].filter(R=>R.startsWith(k)).sort(bo);if(!C.length)throw new Error(`[engine] no animation or frames "${k}\u2026"`);return{frames:C}}async function Fa(k,M){let C=M.split("?")[0].split(".").pop().toLowerCase();if(["mp3","ogg","wav","m4a","aac","webm"].includes(C))return l.load(k,M);if(["woff","woff2","ttf","otf"].includes(C)){let z=new FontFace(k,`url(${M})`);document.fonts.add(await z.load()),d++;return}let R=new URL(M,location.href);if(C==="fnt")return Ms(k,Zt(await(await fetch(M)).text()),R);if(C==="json"){let z=await(await fetch(M)).json();if(Array.isArray(z.chars)&&!z.frames)return Ms(k,Zt(z),R);let V=await Kr(new URL(z.meta?.image??M.replace(/\.json$/,".png"),R).href);Pa(k,z,$t(V));return}let O=await Kr(M),ne=$t(O);r.add(ne),f.set(k,{surface:ne,x:0,y:0,w:O.width,h:O.height,scale:1,gen:0,ox:0,oy:0,margin:0})}function Ss(k,M){return Wo(k,M.map(C=>{let R=$t(C);return r.add(R),R}))}async function Ms(k,M,C){b.set(k,Ss(M,await Promise.all(M.pages.map(R=>Kr(new URL(R,C).href)))))}function Pa(k,M,C){r.add(C);let R=Array.isArray(M.frames)?M.frames:Object.entries(M.frames).map(([z,V])=>({...V,filename:z})),O=[],ne=[];for(let z of R){let V=z.frame,de=z.filename.replace(sa,"");z.rotated&&console.warn(`[engine] ${k}/${de} is rotated: export without rotation`);let ee={surface:C,x:V.x,y:V.y,w:V.w,h:V.h,scale:1,gen:0,ox:0,oy:0,margin:0};z.trimmed&&z.sourceSize&&z.spriteSourceSize&&(ee.sw=z.sourceSize.w,ee.sh=z.sourceSize.h,ee.tx=z.spriteSourceSize.x,ee.ty=z.spriteSourceSize.y);let _e=z.scale9Borders;_e&&(ee.slice=[_e.y,(ee.sw??V.w)-_e.x-_e.w,(ee.sh??V.h)-_e.y-_e.h,_e.x]),f.set(`${k}/${de}`,ee),O.push(`${k}/${de}`),ne.push((z.duration??0)/1e3)}for(let[z,V]of Object.entries(M.animations??{}))y.set(`${k}/${z}`,{frames:V.map(de=>`${k}/${de.replace(sa,"")}`)});for(let z of M.meta?.frameTags??[]){let V=[];for(let ee=z.from;ee<=z.to;ee++)V.push(ee);z.direction==="reverse"&&V.reverse(),z.direction==="pingpong"&&V.push(...V.slice(1,-1).reverse());let de=V.every(ee=>ne[ee]>0);y.set(`${k}/${z.name}`,{frames:V.map(ee=>O[ee]),...de?{durations:V.map(ee=>ne[ee])}:{}})}}return Ln}var sa=/\.(png|webp|jpe?g|gif|bmp)$/i;function Kr(s){return new Promise((n,e)=>{let t=new Image;t.onload=()=>n(t),t.onerror=()=>e(new Error(`[engine] image did not load: ${s}`)),t.src=s})}function nl(s){return new Promise(n=>{let e=[],t=0,r=o=>{t&&e.push(o-t),t=o,e.length<s?requestAnimationFrame(r):n(e)};requestAnimationFrame(r)})}async function rl(s,n,e,t,r,o=()=>!1){let a=t(),i=Wr(n,{type:"star",r:30,fill:"#ffd23f",stroke:"#3a2a10",lw:3},a).frame,l=[],c=[],u=new Float64Array(6),f=.004,h=s.kind==="canvas2d"?s.canvas.getContext("2d"):null,b=mt(),y=0;return await new Promise(m=>{let d=x=>{y&&x-b>250&&l.push(x-y),y=x;let g=mt();s.begin(0,0,a);let A=e();for(let w=0;w<300;w++){let v=x/1e3+w;Te(u,null,w*37%r,w*53%he,v,1,1),s.quad(A(i.surface),i,u,i.w/a,i.h/a,16777215,f,"normal")}for(let w=0;w<40;w++)s.ellipse(100+w*20,300,20,14,w,16746496,f),s.stroke([100+w*20,400,120+w*20,460,100+w*20,520],3,18,3368703,f,!1);s.end(),h?.getImageData(0,0,1,1),x-b>250&&c.push(mt()-g),x-b<750&&!o()?requestAnimationFrame(d):(s.begin(0,0,a),s.end(),m())};requestAnimationFrame(d)}),{intervals:l,cpu:c}}var sl=64,aa=32,ol=0,al=`fabi-cm-${Math.random().toString(36).slice(2,7)}-`,ia=new Set,la=(s,n)=>{ia.has(s)||(ia.add(s),console.warn(n))},ca=s=>new Zr(s),Zr=class{constructor(n){p(this,"r",n);p(this,"css","none");p(this,"plans",new Vt(sl));p(this,"buf",new Float64Array(64));p(this,"keys",[]);p(this,"classes",new Map);p(this,"live",new Set);p(this,"svgs",new Map);p(this,"t",0);p(this,"cur",null);p(this,"svgFn",n=>this.svg(n));p(this,"scr",[]);p(this,"flip",0)}chain(n,e){var y;let t=this.r,r=this.buf;r[0]=t.scale,r[1]=t.maxBlur;let o=2;for(let m=0;m<e.length;m++){let d=e[m];if(o+22>r.length){let g=new Float64Array(r.length*2);g.set(r),r=this.buf=g}let x=this.classes.get(d.constructor);x===void 0&&this.classes.set(d.constructor,x=this.classes.size),r[o++]=x,r[o++]=d.enabled?1:0,d.params&&(o=d.params(r,o))}let a=(y=this.keys)[o]??(y[o]=new Float64Array(o));for(let m=0;m<o;m++)a[m]=r[m];let i=Ue(a),l=this.plans.get(a,i);l||this.plans.set(a,l=this.plan(e),i);for(let m=0;m<l.svgs.length;m++){let d=l.svgs[m];d.used<0&&this.attach(d),d.used=this.t}t.skipped+=l.skip;let c=n,u=t.rx0,f=t.ry0,h=t.rx1-u,b=t.ry1-f;for(let m=0;m<l.paints.length;m++)l.parts[m]&&(c=this.bake(c,l.parts[m])),e[l.paints[m]].paint2d(c.getContext("2d"),u,f,h,b);return this.css=l.parts[l.paints.length]||"none",c}tick(){let n=++this.t;if(!(n%aa||!this.live.size))for(let e of this.live)n-e.used>aa&&this.detach(e)}destroy(){for(let n of this.live)this.detach(n);this.plans.clear()}svg(n){if(typeof document>"u"||!document.body)return null;let e=Array.from({length:20},(r,o)=>n[o]??0).join(" "),t=this.svgs.get(e);if(!t){let r="http://www.w3.org/2000/svg",o=document.createElementNS(r,"svg");o.setAttribute("width","0"),o.setAttribute("height","0"),o.setAttribute("aria-hidden","true"),o.style.position="absolute";let a=document.createElementNS(r,"filter"),i=al+ ++ol;a.setAttribute("id",i),a.setAttribute("color-interpolation-filters","sRGB");let l=document.createElementNS(r,"feColorMatrix");l.setAttribute("type","matrix"),l.setAttribute("values",e),a.append(l),o.append(a),this.attach(t={key:e,id:i,el:o,used:this.t})}return this.cur.svgs.push(t),`url(#${t.id})`}attach(n){document.body.append(n.el),this.live.add(n),this.svgs.has(n.key)||this.svgs.set(n.key,n)}detach(n){n.el.remove(),n.used=-1,this.live.delete(n),this.svgs.get(n.key)===n&&this.svgs.delete(n.key)}plan(n){let e=this.r,t=this.cur={parts:[],paints:[],skip:0,svgs:[]},r="";for(let o=0;o<n.length;o++){let a=n[o];if(!a.enabled)continue;if(a.kind===4){t.skip++,la("shader","[engine] shader() filters are WebGL only: on Canvas 2D they are skipped (check engine.supports.shaders)");continue}let i=e.support.filters&&a.css?a.css(e.scale,e.maxBlur,this.svgFn):null;i!==null?r+=r?` ${i}`:i:a.paint2d?(t.parts.push(r),t.paints.push(o),r=""):(t.skip++,la("css","[engine] this browser's Canvas 2D has no ctx.filter: colour filters, blur and shadows are skipped (tint works; check engine.supports.filters)"))}return t.parts.push(r),t}bake(n,e){let t=this.r,r=this.flip^=1,o=this.scr[r];(!o||o.width!==t.canvas.width||o.height!==t.canvas.height)&&(o=this.scr[r]=document.createElement("canvas"),o.width=t.canvas.width,o.height=t.canvas.height);let a=o.getContext("2d"),i=t.rx0,l=t.ry0,c=t.rx1-i,u=t.ry1-l;return a.clearRect(i,l,c,u),a.filter=e,a.drawImage(n,i,l,c,u,i,l,c,u),a.filter="none",o}};var il=64,lr=17,ll=s=>`${er}
|
|
48
|
+
}`,ol={alpha:!0,premultipliedAlpha:!0,antialias:!1,depth:!1,stencil:!1,preserveDrawingBuffer:!1,powerPreference:"high-performance"},al=["aCorner","aP01","aP23","aUvRect","aColor","aSlot"],il=["aPos","aUv","aColor","aSlot"];function qo(s,n,e={}){let t={...ol,failIfMajorPerformanceCaveat:e.failIfMajorPerformanceCaveat!==!1},r=n===2?s.getContext("webgl2",t):s.getContext("webgl",t)??s.getContext("experimental-webgl",t);if(!r||r.isContextLost())return null;try{return new Ur(s,r,n,e)}catch(o){return console.warn("[engine] WebGL setup failed:",o),r.getExtension("WEBGL_lose_context")?.loseContext(),null}}var Ur=class extends jt{constructor(e,t,r,o){super();p(this,"canvas",e);p(this,"gl",t);p(this,"opts",o);p(this,"kind");p(this,"maxTextureSize");p(this,"support",{filters:!0,shaders:!0});p(this,"features",{});p(this,"info",{});p(this,"lost",!1);p(this,"main");p(this,"cur");p(this,"unit",-1);p(this,"onUnit",new Array(Xo).fill(void 0));p(this,"fbNow");p(this,"mapped",!0);p(this,"calls",{useProgram:0,bindTexture:0,activeTexture:0,bindFramebuffer:0});p(this,"vsrc","");p(this,"attrs",[]);p(this,"fxr",null);p(this,"batch");p(this,"dynamic");p(this,"staticBuf",null);p(this,"index");p(this,"vao",null);p(this,"inst",null);p(this,"vaoApi",null);p(this,"uScale",null);p(this,"textures",new Map);p(this,"kit");p(this,"stats",{drawCalls:0,quads:0,filtersSkipped:0});p(this,"lostListeners",[]);p(this,"restoredListeners",[]);p(this,"tris",new Int32Array(192));p(this,"sU",0);p(this,"sV0",0);p(this,"sV1",0);p(this,"sColor",0);p(this,"sPacked",0);p(this,"sAlpha",0);p(this,"sHw",0);p(this,"strokeSeg",()=>{let e=this.q;e.set(Mn),e[8]=e[10]=this.sU,e[9]=this.sV0,e[11]=this.sV1,e[12]=this.sPacked,this.put(this.kit)});p(this,"strokeDisc",()=>this.ellipse(Mn[0],Mn[1],this.sHw,this.sHw,0,this.sColor,this.sAlpha));p(this,"q",new Float64Array(13));p(this,"layers",[]);p(this,"layerTex",new Map);p(this,"bScis",!1);p(this,"bx0",0);p(this,"by0",0);p(this,"bx1",0);p(this,"by1",0);p(this,"onContextLost",e=>{e.preventDefault(),this.lost=!0;for(let t of this.lostListeners)t()});p(this,"onContextRestored",()=>{try{this.layers=[],this.layerTex.clear(),this.fxr=null,this.resetLayers(this.scale),this.setup();for(let e of this.textures.keys())this.textures.set(e,this.upload(e.source));this.lost=!1;for(let e of this.restoredListeners)e()}catch(e){console.warn("[engine] WebGL restore failed:",e)}});p(this,"views",new Map);this.kind=r===2?"webgl2":"webgl1",this.maxTextureSize=t.getParameter(t.MAX_TEXTURE_SIZE),this.setup(),this.kit=this.createTexture(Wo()),Me.live=this,e.addEventListener("webglcontextlost",this.onContextLost,!1),e.addEventListener("webglcontextrestored",this.onContextRestored,!1)}setup(){let e=this.gl,t=this.kind==="webgl2"?e:null;if(this.inst=null,this.opts.instancing!==!1)if(t)this.inst={divisor:(f,h)=>t.vertexAttribDivisor(f,h),draw:(f,h)=>t.drawElementsInstanced(e.TRIANGLES,f,e.UNSIGNED_SHORT,0,h)};else{let f=e.getExtension("ANGLE_instanced_arrays");f&&(this.inst={divisor:(h,y)=>f.vertexAttribDivisorANGLE(h,y),draw:(h,y)=>f.drawElementsInstancedANGLE(e.TRIANGLES,h,e.UNSIGNED_SHORT,0,y)})}if(this.vaoApi=null,this.opts.vao!==!1)if(t)this.vaoApi={create:()=>t.createVertexArray(),bind:f=>t.bindVertexArray(f),remove:f=>t.deleteVertexArray(f)};else{let f=e.getExtension("OES_vertex_array_object");f&&(this.vaoApi={create:()=>f.createVertexArrayOES(),bind:h=>f.bindVertexArrayOES(h),remove:h=>f.deleteVertexArrayOES(h)})}let r=e.getParameter(e.MAX_TEXTURE_IMAGE_UNITS),o=Math.max(1,Math.min(Xo,r)),a=this.inst!==null;this.vsrc=a?sl:rl,this.attrs=a?al:il,this.main=this.cur=this.build(nl(o));let i=this.main.p;e.useProgram(i),this.calls.useProgram++,this.unit=-1,this.onUnit.fill(void 0),this.fbNow=void 0,this.uScale=this.main.uScale,e.uniform1iv(e.getUniformLocation(i,"uTex"),Int32Array.from({length:o},(f,h)=>h)),this.batch=new qn(a,o),this.vaoApi&&(this.vao=this.vaoApi.create(),this.vaoApi.bind(this.vao)),this.dynamic=e.createBuffer(),e.bindBuffer(e.ARRAY_BUFFER,this.dynamic),e.bufferData(e.ARRAY_BUFFER,this.batch.f32.byteLength,e.DYNAMIC_DRAW),this.index=e.createBuffer(),e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,this.index),e.bufferData(e.ELEMENT_ARRAY_BUFFER,Po(a?1:8192),e.STATIC_DRAW);let u=f=>e.getAttribLocation(i,f),c=(f,h,y,b,m,d,x)=>{let g=u(f);g<0||(e.enableVertexAttribArray(g),e.vertexAttribPointer(g,h,y,b,m,d),this.inst&&this.inst.divisor(g,x))};if(a){let f=56;c("aP01",4,e.FLOAT,!1,f,0,1),c("aP23",4,e.FLOAT,!1,f,16,1),c("aUvRect",4,e.FLOAT,!1,f,32,1),c("aColor",4,e.UNSIGNED_BYTE,!0,f,48,1),c("aSlot",1,e.FLOAT,!1,f,52,1),this.staticBuf=e.createBuffer(),e.bindBuffer(e.ARRAY_BUFFER,this.staticBuf),e.bufferData(e.ARRAY_BUFFER,Float32Array.of(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1),e.STATIC_DRAW),c("aCorner",4,e.FLOAT,!1,16,0,0),e.bindBuffer(e.ARRAY_BUFFER,this.dynamic)}else{let f=24;c("aPos",2,e.FLOAT,!1,f,0,0),c("aUv",2,e.FLOAT,!1,f,8,0),c("aColor",4,e.UNSIGNED_BYTE,!0,f,16,0),c("aSlot",1,e.FLOAT,!1,f,20,0)}e.enable(e.BLEND),e.blendFunc(e.ONE,e.ONE_MINUS_SRC_ALPHA),e.disable(e.DEPTH_TEST),e.disable(e.CULL_FACE),e.pixelStorei(e.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!0);let l=e.getExtension("WEBGL_debug_renderer_info");this.info={version:e.getParameter(e.VERSION),renderer:l?e.getParameter(l.UNMASKED_RENDERER_WEBGL):e.getParameter(e.RENDERER),vendor:l?e.getParameter(l.UNMASKED_VENDOR_WEBGL):e.getParameter(e.VENDOR)},this.features={instancing:a,vao:this.vaoApi!==null,textureSlots:o,maxTextureSize:this.maxTextureSize}}upload(e){let t=this.gl,r=t.createTexture();return this.bindTex(r),t.texImage2D(t.TEXTURE_2D,0,t.RGBA,t.RGBA,t.UNSIGNED_BYTE,e),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.LINEAR),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.LINEAR),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE),r}resize(e,t){this.canvas.width!==e&&(this.canvas.width=e),this.canvas.height!==t&&(this.canvas.height=t)}createTexture(e){let t={id:gn(),width:e.width,height:e.height,source:e};return this.textures.set(t,this.lost?null:this.upload(e)),t}updateTexture(e,t,r=0,o=0){if(this.lost)return;this.batch.has(e)&&this.flush();let a=this.gl,i=this.textures.get(e);i&&(this.bindTex(i),!t||t===e.source&&r===0&&o===0?a.texImage2D(a.TEXTURE_2D,0,a.RGBA,a.RGBA,a.UNSIGNED_BYTE,e.source):a.texSubImage2D(a.TEXTURE_2D,0,r,o,a.RGBA,a.UNSIGNED_BYTE,t))}destroyTexture(e){this.batch.has(e)&&this.flush();let t=this.textures.get(e);t&&!this.lost&&this.deleteTex(t),this.textures.delete(e)}begin(e,t,r){if(this.stats.drawCalls=this.stats.quads=this.stats.filtersSkipped=0,this.batch.reset(),this.resetLayers(r),this.bScis=!1,this.lost)return;let o=this.gl;o.disable(o.SCISSOR_TEST),this.bindFb(null),o.viewport(0,0,this.canvas.width,this.canvas.height);let a=t;o.clearColor((e>>16&255)/255*a,(e>>8&255)/255*a,(e&255)/255*a,a),o.clear(o.COLOR_BUFFER_BIT),this.use(this.main),o.uniform2f(this.uScale,2*r/this.canvas.width,-2*r/this.canvas.height),this.mapped=!0}build(e){let t=this.gl,r=jo(t,t.VERTEX_SHADER,this.vsrc),o;try{o=jo(t,t.FRAGMENT_SHADER,e)}catch(i){throw t.deleteShader(r),i}let a=t.createProgram();if(t.attachShader(a,r),t.attachShader(a,o),this.attrs.forEach((i,u)=>t.bindAttribLocation(a,u,i)),t.linkProgram(a),t.deleteShader(r),t.deleteShader(o),!t.getProgramParameter(a,t.LINK_STATUS)){let i=t.getProgramInfoLog(a)??"?";throw t.deleteProgram(a),new Error(`link: ${i}`)}return{p:a,uScale:t.getUniformLocation(a,"uScale"),locs:new Map}}u(e,t){let r=e.locs.get(t);return r===void 0&&e.locs.set(t,r=this.gl.getUniformLocation(e.p,t)),r}use(e){this.cur!==e&&(this.cur=e,this.gl.useProgram(e.p),this.calls.useProgram++)}bindTex(e,t=this.unit<0?0:this.unit){let r=this.gl;this.onUnit[t]!==e&&(this.unit!==t&&(r.activeTexture(r.TEXTURE0+t),this.calls.activeTexture++,this.unit=t),r.bindTexture(r.TEXTURE_2D,e),this.calls.bindTexture++,this.onUnit[t]=e)}deleteTex(e){this.gl.deleteTexture(e);for(let t=0;t<this.onUnit.length;t++)this.onUnit[t]===e&&(this.onUnit[t]=null)}bindFb(e){if(e)for(let r=0;r<this.onUnit.length;r++)this.onUnit[r]===e.gl&&this.bindTex(null,r);let t=e?e.fb:null;this.fbNow!==t&&(this.gl.bindFramebuffer(this.gl.FRAMEBUFFER,t),this.calls.bindFramebuffer++,this.fbNow=t)}slotOf(e){this.batch.full&&this.flush();let t=this.batch.slot(e);return t<0&&(this.flush(),t=this.batch.slot(e)),t}quad(e,t,r,o,a,i,u,c){Y[0]=o,Y[1]=a,Y[2]=u,this.quadQ(e,t,r,i,c)}quadQ(e,t,r,o,a){let i=Y[2];if(this.lost||i<=0)return;let u=this.q,c=Y[0],l=Y[1],f=r[4],h=r[5],y=r[0]*c,b=r[1]*c,m=r[2]*l,d=r[3]*l;u[0]=f,u[1]=h,u[2]=y+f,u[3]=b+h,u[4]=y+m+f,u[5]=b+d+h,u[6]=m+f,u[7]=d+h;let x=1/e.width,g=1/e.height;u[8]=t.x*x,u[9]=t.y*g,u[10]=(t.x+t.w)*x,u[11]=(t.y+t.h)*g,u[12]=ut(o,i,a==="add"),this.put(e)}put(e){if(this.mute)return;let t=this.q,r=!1,o=Math.min(t[0],t[2],t[4],t[6]),a=Math.max(t[0],t[2],t[4],t[6]),i=Math.min(t[1],t[3],t[5],t[7]),u=Math.max(t[1],t[3],t[5],t[7]);if(this.cOn){if(this.px1<=this.px0||this.py1<=this.py0)return;let l=this.scale,f=this.px0/l,h=this.py0/l,y=this.px1/l,b=this.py1/l;if(a<=f||o>=y||u<=h||i>=b)return;if(o<f||a>y||i<h||u>b){let m=t[0],d=t[1],x=t[2],g=t[5];if(d===t[3]&&x===t[4]&&g===t[7]&&t[6]===m){if(m!==x){let A=Math.min(Math.max(m,f),y),w=Math.min(Math.max(x,f),y),v=t[8],R=(t[10]-v)/(x-m);t[10]=v+(w-m)*R,t[8]=v+(A-m)*R,t[0]=t[6]=A,t[2]=t[4]=w}if(d!==g){let A=Math.min(Math.max(d,h),b),w=Math.min(Math.max(g,h),b),v=t[9],R=(t[11]-v)/(g-d);t[11]=v+(w-d)*R,t[9]=v+(A-d)*R,t[1]=t[3]=A,t[5]=t[7]=w}}else r=!0}}let c=this.bx0===this.px0&&this.by0===this.py0&&this.bx1===this.px1&&this.by1===this.py1;if(r?(!this.bScis||!c)&&(this.flush(),this.bScis=!0,this.bx0=this.px0,this.by0=this.py0,this.bx1=this.px1,this.by1=this.py1):this.bScis&&!(this.cOn&&c)&&(this.flush(),this.bScis=!1),this.real){let l=this.gq;l[0]=o,l[1]=i,l[2]=a,l[3]=u,this.growQ()}this.batch.pushQ(t,this.slotOf(e))}ellipse(e,t,r,o,a,i,u){if(this.lost||u<=0||r<=0||o<=0)return;let c=nr[Gr(Math.max(r,o)*2*this.scale,Uo)],l=c.w/2/c.r,f=r*l,h=o*l,y=Math.cos(a),b=Math.sin(a),m=y*f,d=b*f,x=-b*h,g=y*h,A=1/256,w=this.q;w[0]=e-m-x,w[1]=t-d-g,w[2]=e+m-x,w[3]=t+d-g,w[4]=e+m+x,w[5]=t+d+g,w[6]=e-m+x,w[7]=t-d+g,w[8]=c.x*A,w[9]=c.y*A,w[10]=(c.x+c.w)*A,w[11]=(c.y+c.h)*A,w[12]=ut(i,u),this.put(this.kit)}polygon(e,t,r,o){if(this.lost||o<=0||t<3)return;this.tris.length<t*3&&(this.tris=new Int32Array(Math.max(t*3,this.tris.length*2)));let a=this.tris,i=Ho(e,t,a),u=ut(r,o),c=(at.x+at.w/2)/256,l=(at.y+at.h/2)/256;for(let f=0;f<i;f+=3){let h=a[f]*2,y=a[f+1]*2,b=a[f+2]*2,m=this.q;m[0]=e[h],m[1]=e[h+1],m[2]=e[y],m[3]=e[y+1],m[4]=m[6]=e[b],m[5]=m[7]=e[b+1],m[8]=m[10]=c,m[9]=m[11]=l,m[12]=u,this.put(this.kit)}}stroke(e,t,r,o,a,i){if(this.lost||a<=0||r<=0||t<1)return;let u=rr[Gr(r*this.scale,Vo)],c=r/2*(u.h/2/u.r);this.sPacked=ut(o,a),this.sColor=o,this.sAlpha=a,this.sU=(u.x+u.w/2)/256,this.sV0=u.y/256,this.sV1=(u.y+u.h)/256,this.sHw=r/2,$o(e,t,c,i,this.strokeSeg,this.strokeDisc)}target(e,t,r,o){let a=this.gl,i=a.createTexture();this.bindTex(i),a.texImage2D(a.TEXTURE_2D,0,a.RGBA,e,t,0,a.RGBA,a.UNSIGNED_BYTE,null);let u=o?a.LINEAR:a.NEAREST;a.texParameteri(a.TEXTURE_2D,a.TEXTURE_MIN_FILTER,u),a.texParameteri(a.TEXTURE_2D,a.TEXTURE_MAG_FILTER,u),a.texParameteri(a.TEXTURE_2D,a.TEXTURE_WRAP_S,a.CLAMP_TO_EDGE),a.texParameteri(a.TEXTURE_2D,a.TEXTURE_WRAP_T,a.CLAMP_TO_EDGE),this.bindTex(null);let c=a.createFramebuffer();a.bindFramebuffer(a.FRAMEBUFFER,c),a.framebufferTexture2D(a.FRAMEBUFFER,a.COLOR_ATTACHMENT0,a.TEXTURE_2D,i,0);let l=a.checkFramebufferStatus(a.FRAMEBUFFER)===a.FRAMEBUFFER_COMPLETE;if(this.fbNow=c,this.bindFb(this.parent()),!l)return this.deleteTex(i),a.deleteFramebuffer(c),null;let f={tex:{id:gn(),width:e,height:t,source:this.canvas},gl:i,fb:c,w:e,h:t,f:r};return this.layerTex.set(f.tex,i),f}drop(e){this.batch.has(e.tex)&&this.flush(),this.deleteTex(e.gl),this.gl.deleteFramebuffer(e.fb),this.layerTex.delete(e.tex)}parent(){return this.real>0?this.layers[this.real-1]:null}layerAt(e){let t=this.canvas.width,r=this.canvas.height,o=this.layers[e]??null;return o&&(o.w!==t||o.h!==r)&&(this.drop(o),o=this.layers[e]=null),o??(this.layers[e]=this.target(t,r,1,!1))}pushLayer(){if(this.lost)return!1;this.flush();let e=this.layerAt(this.real);if(!e)return!1;let t=this.gl;return this.bindFb(e),t.disable(t.SCISSOR_TEST),t.clearColor(0,0,0,0),t.clear(t.COLOR_BUFFER_BIT),!0}popLayer(){return this.flush(),this.bindFb(this.parent()),this.layers[this.real].tex}filters(){return this.lost||!Me.gl?null:this.fxr??(this.fxr=Me.gl(this))}composite(e,t,r,o){if(o&&this.filters()?.chain(e,r,o))return;let a=this.gl;t&&a.blendFunc(a.ZERO,a.SRC_ALPHA),this.final(this.main,e,1,r),t&&(this.flush(),a.blendFunc(a.ONE,a.ONE_MINUS_SRC_ALPHA))}final(e,t,r,o){let a=this.gl,i=this.canvas.width,u=this.canvas.height,c=this.scale;(e!==this.main||!this.mapped)&&(this.bindFb(this.parent()),a.viewport(0,0,i,u),this.use(e),a.uniform2f(e.uScale,2*c/i,-2*c/u),this.mapped=e===this.main);let l=this.rx0/c,f=this.ry0/c,h=this.rx1/c,y=this.ry1/c,b=1/(r*t.width),m=1/(r*t.height),d=this.q;d[0]=d[6]=l,d[1]=d[3]=f,d[2]=d[4]=h,d[5]=d[7]=y,d[8]=this.rx0*b,d[9]=1-this.ry0*m,d[10]=this.rx1*b,d[11]=1-this.ry1*m,d[12]=ut(16777215,o),this.put(t),e!==this.main&&this.flush()}remap(){let e=this.gl;this.bindFb(this.parent()),e.viewport(0,0,this.canvas.width,this.canvas.height),this.use(this.main),e.uniform2f(this.uScale,2*this.scale/this.canvas.width,-2*this.scale/this.canvas.height),this.mapped=!0}upload2(e){let t=this.gl,r=e.words;if(this.kind==="webgl2")return t.bufferSubData(t.ARRAY_BUFFER,0,e.f32,0,r);let o=this.views.get(r);o||(this.views.size>=256&&this.views.clear(),this.views.set(r,o=e.f32.subarray(0,r))),t.bufferSubData(t.ARRAY_BUFFER,0,o)}flush(){let e=this.batch;if(!e.quads||this.lost)return e.reset();let t=this.gl;this.bScis?(t.enable(t.SCISSOR_TEST),t.scissor(this.bx0,this.canvas.height-this.by1,this.bx1-this.bx0,this.by1-this.by0)):t.disable(t.SCISSOR_TEST),this.upload2(e);for(let r=0;r<e.bound;r++){let o=e.textures[r];this.bindTex(this.textures.get(o)??this.layerTex.get(o)??null,r)}this.inst?this.inst.draw(6,e.quads):t.drawElements(t.TRIANGLES,e.quads*6,t.UNSIGNED_SHORT,0),this.stats.drawCalls++,this.stats.quads+=e.quads,e.reset()}end(){return this.closeLayers(),this.flush(),this.stats.filtersSkipped=this.skipped,this.stats}onLost(e){this.lostListeners.push(e)}onRestored(e){this.restoredListeners.push(e)}destroy(){let e=this.gl;Me.live===this&&(Me.live=null),this.canvas.removeEventListener("webglcontextlost",this.onContextLost),this.canvas.removeEventListener("webglcontextrestored",this.onContextRestored);try{for(let t of this.textures.values())t&&e.deleteTexture(t);for(let t of this.layers)t&&(e.deleteTexture(t.gl),e.deleteFramebuffer(t.fb));this.fxr?.destroy(),this.fxr=null,e.deleteBuffer(this.dynamic),e.deleteBuffer(this.index),this.staticBuf&&e.deleteBuffer(this.staticBuf),this.vao&&this.vaoApi&&this.vaoApi.remove(this.vao),e.deleteProgram(this.main.p),e.getExtension("WEBGL_lose_context")?.loseContext()}catch{}this.textures.clear()}};function jo(s,n,e){let t=s.createShader(n);if(s.shaderSource(t,e),s.compileShader(t),!s.getShaderParameter(t,s.COMPILE_STATUS)){let r=s.getShaderInfoLog(t)??"?";throw s.deleteShader(t),new Error(r)}return t}function Vr(s="auto"){switch(s){case"canvas2d":return["canvas2d"];case"webgl1":return["webgl1","canvas2d"];default:return["webgl2","webgl1","canvas2d"]}}function Kt(s,n={}){let e=s;for(let t of Vr(n.renderer)){let r=t==="canvas2d"?qt(e):qo(e,t==="webgl2"?2:1,n);if(r)return r;e=Tn(e)}throw new Error("No renderer: this browser has neither WebGL nor Canvas 2D")}function Tn(s){let n=s.cloneNode(!1);return s.parentNode?.replaceChild(n,s),n}function Yo(s=typeof location<"u"?location.search:""){let n=new URLSearchParams(s).get("renderer");return n==="canvas"?"canvas2d":n==="webgl2"||n==="webgl1"||n==="canvas2d"||n==="webgl"||n==="auto"?n:void 0}var yt=class{constructor(n,e={}){p(this,"atlas",n);p(this,"tags",new Map);p(this,"count",0);p(this,"m",rt());p(this,"measure",null);p(this,"height");p(this,"font");this.height=e.tagHeight??34,this.font=e.tagFont??"Nunito, sans-serif"}drop(){for(let n of this.tags.values())for(let e of n.values())for(let t of e.values())this.atlas.release(t);this.tags.clear(),this.count=0}get(n,e,t){let r=this.tags.get(n);r||this.tags.set(n,r=new Map);let o=r.get(e);o||r.set(e,o=new Map);let a=o.get(t);return a&&this.atlas.valid(a)?a:this.bake(n,e,t)}bake(n,e,t){let r=this.height,o=`700 ${Math.round(r*.65)}px ${this.font}`,a=this.measure??(this.measure=document.createElement("canvas").getContext("2d"));a.font=o;let i=Math.round(r*.4),u=Math.ceil(a.measureText(n).width)+i*2,c=this.atlas.bake((u+2)*t,(r+2)*t,h=>{h.scale(t,t),h.translate(1,1);let y=r/2;h.beginPath(),h.moveTo(y,0),h.lineTo(u-y,0),h.arc(u-y,y,y,-Math.PI/2,Math.PI/2),h.lineTo(y,r),h.arc(y,y,y,Math.PI/2,Math.PI*3/2),h.closePath(),h.fillStyle=e,h.fill(),h.fillStyle="#fff",h.font=o,h.textAlign="center",h.textBaseline="middle",h.fillText(n,u/2,r/2+1)},t,1,1,1);++this.count>64&&(this.drop(),this.count=1);let l=this.tags.get(n);l||this.tags.set(n,l=new Map);let f=l.get(e);return f||l.set(e,f=new Map),f.set(t,c),c}draw(n,e,t,r,o,a,i,u,c,l,f){let h=Dt(t,o,{band:ll(r)});if(!h)return;let y=this.height,b=this.get(a,i,c),m=b.w/b.scale-2,d=Math.min(Math.max(h.head.x-m/2,4),l-m-4),x=Math.min(Math.max(h.head.y-h.headR*2.2-y,4),f-y-4);Se(this.m,null,d-1,x-1,0,1,1),n.quad(e(b.surface),b,this.m,b.w/b.scale,b.h/b.scale,16777215,u,"normal")}},ll=s=>s.band==="3-5"||s.band==="9-12"?s.band:"6-8";var cl=(s,n=!1)=>n?Math.min(2**Math.round(Math.log2(Math.max(s,8))),256):Math.min(2**(Math.ceil(Math.log2(Math.max(s,8))*2)/2),512);function ar(s,n=null){let e={minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0},t=(r,o,a)=>{let i=n?n[0]*r+n[2]*o+n[4]:r,u=n?n[1]*r+n[3]*o+n[5]:o,c=n?Math.hypot(n[0],n[1]):1;e.minX=Math.min(e.minX,i-a*c),e.minY=Math.min(e.minY,u-a*c),e.maxX=Math.max(e.maxX,i+a*c),e.maxY=Math.max(e.maxY,u+a*c)};for(let r of s){let o="lw"in r&&r.stroke?(r.lw??1)/2:0;switch(r.k){case"circle":t(r.x-r.r,r.y-r.r,o),t(r.x+r.r,r.y+r.r,o),t(r.x-r.r,r.y+r.r,o),t(r.x+r.r,r.y-r.r,o);break;case"ellipse":case"rect":{let a=r.k==="ellipse"?Math.max(r.rx,r.ry):Math.hypot(r.w,r.h)/2;t(r.x-a,r.y-a,o),t(r.x+a,r.y+a,o),t(r.x-a,r.y+a,o),t(r.x+a,r.y-a,o);break}case"path":{let a=tr(r.d);for(let i=0;i<a.count;i++){let u=a.subs[i];for(let c=0;c<u.n;c++)t(u.pts[c*2],u.pts[c*2+1],o)}break}case"line":for(let a=0;a+1<r.pts.length;a+=2)t(r.pts[a],r.pts[a+1],o);break;case"group":{let a=Se(rt(),n,r.x,r.y,r.rot??0,r.s??1,r.s??1),i=ar(r.items,a);Number.isFinite(i.minX)&&(e.minX=Math.min(e.minX,i.minX),e.minY=Math.min(e.minY,i.minY),e.maxX=Math.max(e.maxX,i.maxX),e.maxY=Math.max(e.maxY,i.maxY));break}}}return e}var Ct=class{constructor(n){p(this,"atlas",n);p(this,"seen",new WeakSet);p(this,"baked",new WeakMap);p(this,"m",rt());p(this,"stack",[]);p(this,"local",rt());p(this,"pts",new Float64Array(128));p(this,"stats",{baked:0,vector:0});p(this,"bakeGroups",!0);p(this,"coarse",!1);p(this,"gen",0);p(this,"live",new Set)}setTier(n){let e=n==="low";if(e!==this.coarse){this.coarse=e,this.gen++;for(let t of this.live)this.atlas.release(t.frame);this.live.clear()}}draw(n,e,t,r,o,a,i){let u=typeof r=="string"?Bt(r)??St:r,c=pn(t,u,o);return c.length?(a<=0||(a<1?(this.paint(n,e,c,null,n.beginLayer()?1:a,i),n.endLayer(a)):this.paint(n,e,c,null,a,i)),!0):!1}paint(n,e,t,r,o,a,i=0){var u;for(let c=0;c<t.length;c++){let l=t[c];if(l.k==="group"){let g=Se((u=this.stack)[i]??(u[i]=rt()),r,l.x,l.y,l.rot??0,l.s??1,l.s??1),A=o*(l.alpha??1);if(this.bakeGroups&&this.seen.has(l.items)){let w=je(g[0],g[1])*a,v=this.bake(l.items,w);if(v){let R=v.frame,F=this.m;F.set(g),F[4]=g[0]*-v.ox+g[2]*-v.oy+g[4],F[5]=g[1]*-v.ox+g[3]*-v.oy+g[5],n.quad(e(R.surface),R,F,R.w/v.k,R.h/v.k,16777215,A,"normal"),this.stats.baked++;continue}}this.seen.add(l.items),this.stats.vector++,this.paint(n,e,l.items,g,A,a,i+1);continue}let f=o*(l.alpha??1),h=r?je(r[0],r[1]):1,y=r?Math.atan2(r[1],r[0]):0,b=(l.lw??1)*h,m=l.stroke&&(l.lw??1)>0?de(l.stroke):null,d=l.fill&&l.k!=="line"?de(l.fill):null;if(l.k==="circle"||l.k==="ellipse"){let g=r?r[0]*l.x+r[2]*l.y+r[4]:l.x,A=r?r[1]*l.x+r[3]*l.y+r[5]:l.y,w=(l.k==="circle"?l.r:l.rx)*h,v=(l.k==="circle"?l.r:l.ry)*h,R=(l.k==="ellipse"?l.rot??0:0)+y;if(d&&m)n.ellipse(g,A,w+b/2,v+b/2,R,m[0],f*m[1]),n.ellipse(g,A,Math.max(w-b/2,0),Math.max(v-b/2,0),R,d[0],f*d[1]);else if(d)n.ellipse(g,A,w,v,R,d[0],f*d[1]);else if(m){let F=Math.min(Math.max(Math.ceil(Math.max(w,v)*a*.6),12),64),O=this.pts=er(this.pts,F*2),_=Math.cos(R),B=Math.sin(R);for(let $=0;$<F;$++){let W=$/F*Math.PI*2,U=Math.cos(W)*w,me=Math.sin(W)*v;O[$*2]=g+U*_-me*B,O[$*2+1]=A+U*B+me*_}n.stroke(O,F,b,m[0],f*m[1],!0)}continue}if(l.k==="line"){if(!m)continue;let g=l.pts.length>>1,A=this.pts=er(this.pts,g*2);for(let w=0;w<g;w++){let v=l.pts[w*2],R=l.pts[w*2+1];A[w*2]=r?r[0]*v+r[2]*R+r[4]:v,A[w*2+1]=r?r[1]*v+r[3]*R+r[5]:R}n.stroke(A,g,b,m[0],f*m[1],!1);continue}let x=l.k==="path"?tr(l.d,r,h*a):ul(l,Se(this.local,r,l.x,l.y,l.rot??0,1,1),a*h);for(let g=0;g<x.count;g++){let A=x.subs[g],w=A.n,v=l.k==="rect"||A.closed;d&&w>=3&&(n.polygon(A.pts,w,d[0],f*d[1]),m||n.stroke(A.pts,w,1/a,d[0],f*d[1],!0)),m&&n.stroke(A.pts,w,b,m[0],f*m[1],v)}}}bake(n,e){let t=cl(e,this.coarse),r=this.baked.get(n),o=r?.get(t);if(o&&o.gen===this.gen&&this.atlas.valid(o.frame))return o;o&&this.live.delete(o);let a=ar(n);if(!Number.isFinite(a.minX))return null;let i=2/t,u=(a.maxX-a.minX+i*2)*t,c=(a.maxY-a.minY+i*2)*t;if(u>1024||c>1024)return null;let l=-a.minX+i,f=-a.minY+i,y={frame:this.atlas.bake(u,c,b=>{b.scale(t,t),b.translate(l,f),It(b,n)}),k:t,ox:l,oy:f,gen:this.gen};return r||this.baked.set(n,r=new Map),r.set(t,y),this.live.add(y),y}},Qt=new Array(36).fill(0),Zt=0,qe=(s,n=NaN,e=NaN,t=NaN,r=NaN)=>{Qt[Zt++]=s,s!==ge.Z&&(Qt[Zt++]=n,Qt[Zt++]=e,s===ge.Q&&(Qt[Zt++]=t,Qt[Zt++]=r))};function ul(s,n,e){let t=Math.max(0,Math.min(s.r,s.w/2,s.h/2)),r=-s.w/2,o=-s.h/2,{M:a,L:i,Q:u,Z:c}=ge;return Zt=0,qe(a,r+t,o),qe(i,r+s.w-t,o),qe(u,r+s.w,o,r+s.w,o+t),qe(i,r+s.w,o+s.h-t),qe(u,r+s.w,o+s.h,r+s.w-t,o+s.h),qe(i,r+t,o+s.h),qe(u,r,o+s.h,r,o+s.h-t),qe(i,r,o+t),qe(u,r,o,r+t,o),qe(c),tr(Qt,n,e)}function Ko(s,n={}){let e=Kt(s,n),t=new pt(Math.min(1024,e.maxTextureSize),2);t.onDrop=v=>{v.texture&&e.destroyTexture(v.texture),v.texture=null};let r=new Ct(t),o=new An,a=new Map,i=1e6,u=n.smooth===!1?1:typeof n.smooth=="number"?Math.min(Math.max(n.smooth,.05),1):.5,c=En(e),l=new yt(t,n),f={w:1,h:1},h=1,y=0,b=!1,m=()=>l.drop(),d=typeof document<"u"?document.fonts:void 0;d?.ready?.then(()=>{b||m()}),d?.addEventListener?.("loadingdone",m);let x=()=>{let v=Tn(e.canvas),R=qt(v);if(R){console.warn("[engine] avatars: WebGL context lost for good, switching to Canvas 2D"),e.destroy(),e=R;for(let F of t.pages)F.surface.texture=null;c=En(e),y=0}},g=()=>{if(!e.lost)return y=0,!0;let v=performance.now();return y||(y=v),v-y>3e3&&x(),!e.lost},A=()=>{let v=e.canvas;n.units?(h=n.pixelRatio??1,f.w=n.units.width,f.h=n.units.height):(h=n.pixelRatio??Math.min(globalThis.devicePixelRatio||1,2),f.w=v.clientWidth||v.width/h,f.h=v.clientHeight||v.height/h),e.resize(Math.max(1,Math.round(f.w*h)),Math.max(1,Math.round(f.h*h))),e.begin(0,0,h)},w=(v,R)=>{if(v.key===void 0)return v.id??R+1;let F=a.get(v.key);return F===void 0&&(a.size>256&&a.clear(),a.set(v.key,F=i++)),F};return{get renderer(){return e},get kind(){return e.kind},get lost(){return e.lost},get canvas(){return e.canvas},draw(v,R){if(g()){A();for(let F=0;F<v.length;F++){let O=v[F];if(!Array.isArray(O.body))continue;let _=w(O,F),B=u<1||n.interpolate!==!1?o.posed(_,O.body,u,n.interpolate!==!1):O.body,$=Bt(O.avatar??"")??St,W=O.alpha??1;!r.draw(e,c,B,$,R,W,h)||!O.name||l.draw(e,c,B,$,R,O.name,O.color??"#6FA0E0",W,h,f.w,f.h)}e.end()}},clear(){g()&&(A(),e.end())},reset(){o=new An,a.clear()},destroy(){b=!0,d?.removeEventListener?.("loadingdone",m),e.destroy()}}}var or=new Map;function Qo(s,n,e=Math.min(globalThis.devicePixelRatio||1,2)){let t=`${s}|${n}|${e}`,r=or.get(t);if(r)return r;r=document.createElement("canvas"),r.width=r.height=Math.round(n*e);let o=r.getContext("2d");return o.scale(e,e),o.beginPath(),o.rect(0,0,n,n),o.clip(),It(o,ro(Bt(s)??St,n)),or.size>64&&or.clear(),or.set(t,r),r}function En(s){return n=>{if(n.texture||(n.texture=s.createTexture(n.source),n.pending.length=0),n.pending.length){for(let[e,t,r]of n.pending)s.updateTexture(n.texture,e,t,r);n.pending.length=0}return n.texture}}var Wr='Fredoka, Nunito, "Varela Round", system-ui, sans-serif',Ft="rgba(10,16,30,0.75)";function Xr(s,n){let e=s.size??40,t=s.outline?s.outline===!0?Ft:s.outline:null,r=t?s.outlineWidth??Math.max(e*.12,3):0,o=s.shadow&&n?s.shadow===!0?Ft:s.shadow:null,a=o?s.shadowBlur??e*.25:0;return{size:e,font:s.font??Wr,weight:s.weight??700,color:s.color??"#FBEFE3",outline:t,ow:r,shadow:o,blur:a,pad:r/2+a*1.2+2,th:e*1.25}}var Zo=(s,n)=>`${s.weight} ${s.size*n}px ${s.font}`;function jr(s,n,e,t,r,o){s.scale(t,t),s.font=Zo(e,1),s.textBaseline="middle",s.textAlign="left",s.lineJoin="round",e.shadow&&(s.shadowColor=e.shadow,s.shadowBlur=e.blur*t),e.outline&&(s.strokeStyle=e.outline,s.lineWidth=e.ow,s.strokeText(n,r,o),s.shadowColor="transparent"),s.fillStyle=e.color,s.fillText(n,r,o)}var ir=null;function qr(s,n,e){return ir??(ir=document.createElement("canvas").getContext("2d")),ir.font=Zo(n,e),ir.measureText(s).width/e}var Ye=class extends Te{constructor(e,t,r={}){super(e,null);p(this,"_text");p(this,"_style");p(this,"dirty",!0);p(this,"bakedScale",0);p(this,"bakedFontGen",-1);p(this,"bakedEffects",!0);p(this,"capW",0);p(this,"capH",0);this._text=t;let{x:o,y:a,rotation:i,scale:u,scaleX:c,scaleY:l,alpha:f,visible:h,tint:y,blend:b,z:m,anchor:d,hitRadius:x,clip:g,mask:A,filters:w,...v}=r;this._style=v,this.bake(),this.set({x:o,y:a,rotation:i,scale:u,scaleX:c,scaleY:l,alpha:f,visible:h,tint:y,blend:b,z:m,hitRadius:x,clip:g,mask:A,filters:w}),d!==void 0&&(this.anchor=d)}get text(){return this._text}set text(e){let t=String(e);t!==this._text&&(this._text=t,this.dirty=!0)}get style(){return this._style}set style(e){this._style={...this._style,...e},this.dirty=!0}bitmap(){let e=this._style.bitmapFont;if(!e)return null;let t=typeof e=="string"?this.kernel.bitmapFont(e):e;if(this.autoAnchor){let r=this._style.align;this.anchorX=r==="left"?0:r==="right"?1:.5,this.anchorY=.5}return t}get naturalWidth(){let e=this.bitmap();return e?e.measure(this._text)*((this._style.size??e.size)/e.size):super.naturalWidth}get naturalHeight(){let e=this.bitmap();return e?e.lineHeight*((this._style.size??e.size)/e.size):super.naturalHeight}frameNow(){return this._style.bitmapFont?null:this.bake()}draw(e,t,r){let o=this.bitmap();if(!o)return super.draw(e,t,r);let a=(this._style.size??o.size)/o.size,i=o.measure(this._text)*a,u=o.lineHeight*a,c=this.width,l=this.height,f=i>0?c/i:1,h=u>0?l/u:1;o.run(this._text,e,this.world,-this.anchorX*c,-this.anchorY*l,a*f,a*h,r,t,this.blend)}destroy(){this._frame&&this.kernel.atlas.release(this._frame),super.destroy()}bake(){let e=this.kernel;if(this._style.bitmapFont)return null;let t=e.pixelScale,r=e.effects;return!this.dirty&&t===this.bakedScale&&e.fontGen===this.bakedFontGen&&r===this.bakedEffects&&e.atlas.valid(this._frame)?this._frame:this.rebake()}rebake(){let e=this.kernel,t=e.pixelScale,r=e.effects;this.dirty=!1,this.bakedScale=t,this.bakedFontGen=e.fontGen,this.bakedEffects=r;let o=Xr(this._style,r),{pad:a,th:i}=o,u=qr(this._text,o,t),c=(u+a*2)*t,l=(i+a*2)*t,f=this._style.align??"center",h=f==="left"?a:f==="right"?a+u:a+u/2,y=d=>jr(d,this._text,o,t,a,a+i/2),b=this._frame,m=null;return b&&e.atlas.valid(b)&&b.scale===t&&(m=e.atlas.rebake(b,c,l,y,this.capW,this.capH),m?Object.assign(m,{ox:h,oy:a+i/2,margin:a}):e.atlas.release(b)),m||(this.capW=Math.ceil(c*1.25+16),this.capH=Math.ceil(l),m=e.atlas.bake(this.capW,this.capH,y,t,h,a+i/2,a),m.w=Math.ceil(c),m.h=Math.ceil(l)),this._frame=m,this.autoAnchor&&this.useFrameAnchor(),this._w=this._h=null,m}};var ue=(s,n=0)=>{let e=Number(s);return Number.isFinite(e)?e:n};function en(s){typeof s=="string"&&/^\s*[{[]/.test(s)&&(s=JSON.parse(s));let n={size:0,lineHeight:0,base:0,pages:[],chars:[],kernings:[]},e=(t,r)=>{t==="info"?n.size=Math.abs(ue(r.size)):t==="common"?(n.lineHeight=ue(r.lineHeight),n.base=ue(r.base)):t==="page"?n.pages[ue(r.id)]=String(r.file??""):t==="char"?n.chars.push({id:ue(r.id),x:ue(r.x),y:ue(r.y),width:ue(r.width),height:ue(r.height),xoffset:ue(r.xoffset),yoffset:ue(r.yoffset),xadvance:ue(r.xadvance),page:ue(r.page)}):n.kernings.push({first:ue(r.first),second:ue(r.second),amount:ue(r.amount)})};if(typeof s=="object"){let t=s;e("info",t.info??{}),e("common",t.common??{});for(let[r,o]of(t.pages??[]).entries())e("page",{id:r,file:o});for(let r of t.chars??[])e("char",r);for(let r of t.kernings??[])e("kerning",r)}else{let t=/(?:^|<)\s*(info|common|page|char|kerning)\s([^\n<>]*)/gm,r=/(\w+)=(?:"([^"]*)"|([^\s/>]+))/g;for(let o=t.exec(s);o;o=t.exec(s)){let a={};for(let i=r.exec(o[2]);i;i=r.exec(o[2]))a[i[1]]=i[2]??i[3];e(o[1],a)}}return n.size||(n.size=n.lineHeight),n}var Jt=class{constructor(n,e,t,r=null,o=null){p(this,"baker",r);p(this,"host",o);p(this,"size");p(this,"lineHeight");p(this,"base");p(this,"ascii",new Array(128));p(this,"more",new Map);p(this,"kern",new Map);p(this,"bScale",0);p(this,"bFontGen",-1);p(this,"bEffects",!1);p(this,"bGen",-1);this.size=n,this.lineHeight=e,this.base=t}set(n,e){n<128?this.ascii[n]=e:this.more.set(n,e)}setKerning(n,e,t){this.kern.set(n*1114112+e,t)}prepare(){let n=this.host;if(!(!n||n.pixelScale===this.bScale&&n.fontGen===this.bFontGen&&n.effects===this.bEffects&&n.atlas.gen===this.bGen)){this.bScale=n.pixelScale,this.bFontGen=n.fontGen,this.bEffects=n.effects,this.bGen=n.atlas.gen;for(let e of this.ascii)e&&n.atlas.release(e.frame);for(let e of this.more.values())e&&n.atlas.release(e.frame);this.ascii.fill(void 0),this.more.clear()}}glyph(n){let e=n<128?this.ascii[n]:this.more.get(n);return(e===void 0||e&&this.host&&!this.host.atlas.valid(e.frame))&&(e=this.baker?this.baker(n):null,this.set(n,e)),e}kerning(n,e){return this.kern.size?this.kern.get(n*1114112+e)??0:0}measure(n){return this.run(n)}run(n,e,t,r=0,o=0,a=1,i=1,u=0,c=1,l="normal"){this.prepare();let f=0,h=-1;for(let y=0;y<n.length;y++){let b=n.charCodeAt(y);b>=55296&&b<56320&&y+1<n.length&&(b=n.codePointAt(y),y++),h>=0&&(f+=this.kerning(h,b)),h=b;let m=this.glyph(b);m&&(e&&m.w>0&&m.h>0&&(wn(t,r+(f+m.x)*a,o+m.y*i),e.r.quad(e.tex(m.frame.surface),m.frame,le,m.w*a,m.h*i,u,c,l)),f+=m.advance)}return f}};function Jo(s,n){let e=new Jt(s.size,s.lineHeight,s.base);for(let t of s.chars){let r=n[t.page];if(!r)continue;let o={surface:r,x:t.x,y:t.y,w:t.width,h:t.height,scale:1,gen:0,ox:0,oy:0,margin:0};e.set(t.id,{frame:o,x:t.xoffset,y:t.yoffset,w:t.width,h:t.height,advance:t.xadvance})}for(let t of s.kernings)e.setKerning(t.first,t.second,t.amount);return e}function ea(s,n){let e={...n},t=n.size??40,r=a=>{let i=String.fromCodePoint(a),u=s.pixelScale,c=Xr(e,s.effects),l=qr(i,c,u),f=s.atlas.bake((l+c.pad*2)*u,(c.th+c.pad*2)*u,h=>jr(h,i,c,u,c.pad,c.pad+c.th/2),u);return{frame:f,x:-c.pad,y:-c.pad,w:f.w/u,h:f.h/u,advance:l}},o=new Jt(t,t*1.25,t,r,s);o.prepare();for(let a of n.chars??"0123456789")o.glyph(a.codePointAt(0));return o}var hl=.5;function Yr(s){let n=[];for(let[e,t]of[["left",z.leftWrist],["right",z.rightWrist]]){let r=s[t*3],o=s[t*3+1],a=s[t*3+2];r!==void 0&&o!==void 0&&Number.isFinite(r)&&Number.isFinite(o)&&(a??0)>=hl&&n.push({side:e,x:r,y:o})}return n}var tn=s=>hn[((s-1)%hn.length+hn.length)%hn.length],fl=["left","right"];function lr(s,n,e,t,r=()=>null,o={}){let a=[];for(let i of s){let u=r(i)??i.body;if(Array.isArray(u)){if(o.orientation==="portrait"){for(let c of fl){let l=Is(u,c,{orientation:"portrait"});o.hold&&(l=o.hold.at(Ot.key(i.id,c),l,o.t??0)),l&&a.push({player:i.id,side:c,x:l.x*e,y:l.y*t,color:tn(i.id)})}continue}for(let c of Yr(u)){let l=n(c);a.push({player:i.id,side:c.side,x:l.x*e,y:l.y*t,color:tn(i.id)})}}}return a}function Rn(s,n,e,t=0){let r=s.world,o=io(r,n,e);if(!o)return!1;let a=Math.hypot(r[0],r[1])||1,i=Math.hypot(r[2],r[3])||1,[u,c]=o;if(s.hitRadius!=null){let b=s.hitRadius+t/((a+i)/2);return u*u+c*c<=b*b}let l=-s.anchorX*s.width-t/a,f=-s.anchorY*s.height-t/i,h=(1-s.anchorX)*s.width+t/a,y=(1-s.anchorY)*s.height+t/i;return u>=l&&u<=h&&c>=f&&c<=y}function cr(s,n,e,t=0){for(let r of n)if((e===void 0||r.player===e)&&Rn(s,r.x,r.y,t))return r;return null}function pl(s){switch(s.type){case"circle":case"ring":case"star":return[s.r*2,s.r*2];case"ellipse":return[s.rx*2,s.ry*2];case"roundRect":return[s.w,s.h];case"line":return[s.length,s.lw??4];case"path":return s.r?[s.r*2,s.r*2]:[s.size,s.size]}}function dl(s){let n=s.type==="line"?0:s.stroke?(s.lw??2)/2:0,e=s.shadow?s.shadow.blur*1.5+Math.max(Math.abs(s.shadow.x??0),Math.abs(s.shadow.y??0)):0;return Math.ceil(n+e+1)}var ta=(s,n)=>n||!s.shadow?s:{...s,shadow:void 0};function Kr(s,n,e){let t=dl(n),r=n.type==="roundRect",[o,a]=r?[Math.min(n.w,n.r*2+4/e),Math.min(n.h,n.r*2+4/e)]:pl(n),i=(o+t*2)*e,u=(a+t*2)*e;return{frame:s.bake(i,u,l=>{l.scale(e,e),l.translate(t+o/2,t+a/2),ml(l,n,o,a)},e,t+o/2,t+a/2,t),slice:r?Math.ceil((n.r+t)*e):0,w:r?n.w:o,h:r?n.h:a}}function ml(s,n,e,t){s.lineJoin="round",s.lineCap="round";let r=new Path2D;switch(n.type){case"circle":case"ring":r.arc(0,0,n.r,0,Math.PI*2);break;case"ellipse":r.ellipse(0,0,n.rx,n.ry,0,0,Math.PI*2);break;case"roundRect":r.roundRect(-e/2,-t/2,e,t,Math.min(n.r,e/2,t/2));break;case"star":{let c=n.points??5,l=n.r*(n.inner??.5);for(let f=0;f<c*2;f++){let h=f%2?l:n.r,y=-Math.PI/2+f*Math.PI/c;f?r.lineTo(Math.cos(y)*h,Math.sin(y)*h):r.moveTo(Math.cos(y)*h,Math.sin(y)*h)}r.closePath();break}case"line":r.moveTo(-e/2+t/2,0),r.lineTo(e/2-t/2,0);break;case"path":{let c=n.r?n.r*2/n.size:1,l=new DOMMatrix([c,0,0,c,-n.size/2*c,-n.size/2*c]);r.addPath(new Path2D(n.d),l);break}}let o=n.shadow,a=()=>{if(!o)return;let c=s.getTransform();s.shadowColor=o.color,s.shadowBlur=o.blur*c.a,s.shadowOffsetX=(o.x??0)*c.a,s.shadowOffsetY=(o.y??0)*c.a},i=()=>{s.shadowColor="transparent",s.shadowBlur=0};if(n.type==="line"){a(),s.strokeStyle=n.stroke??n.fill??"#fff",s.lineWidth=t,s.stroke(r);return}let u=n.type==="ring";if(n.outlineBelow&&n.fill&&n.stroke&&!u){a(),s.strokeStyle=n.stroke,s.lineWidth=n.lw??2,s.stroke(r),i(),s.fillStyle=n.fill,s.fill(r);return}n.fill&&!u&&(a(),s.fillStyle=n.fill,s.fill(r),i()),(n.stroke||u)&&((!n.fill||u)&&a(),u&&n.fill&&(s.fillStyle=n.fill,s.fill(r)),s.strokeStyle=n.stroke??"#fff",s.lineWidth=n.lw??2,s.stroke(r),i())}var nn=class{constructor(){p(this,"ctx",null);p(this,"master",null);p(this,"buffers",new Map);p(this,"held",!1);p(this,"muted",!1);p(this,"volume",1);if(typeof addEventListener=="function"){let n=()=>{this.context()?.resume().catch(()=>{})};for(let e of["pointerdown","keydown","touchstart"])addEventListener(e,n,{once:!0,capture:!0})}}context(){if(this.ctx)return this.ctx;let n=globalThis.AudioContext??globalThis.webkitAudioContext;if(!n)return null;try{this.ctx=new n,this.master=this.ctx.createGain(),this.master.connect(this.ctx.destination),this.held&&this.ctx.suspend()}catch{return null}return this.ctx}async load(n,e){let t=this.context();if(!t)return;let r=await(await fetch(e)).arrayBuffer();this.buffers.set(n,await t.decodeAudioData(r))}has(n){return this.buffers.has(n)}play(n,e={}){let t=this.context(),r=this.buffers.get(n);if(!t||!r||!this.audible)return()=>{};let o=t.createBufferSource();o.buffer=r,o.loop=e.loop??!1,o.playbackRate.value=e.rate??1;let a=t.createGain();return a.gain.value=(e.volume??1)*this.volume,o.connect(a).connect(this.master),o.start(),()=>{try{o.stop()}catch{}}}tone(n,e=.25,t={}){let r=this.context();if(!(!r||!this.audible))try{let o=r.createOscillator(),a=r.createGain();o.type=t.type??"sine",o.frequency.setValueAtTime(n,r.currentTime),t.to&&o.frequency.exponentialRampToValueAtTime(t.to,r.currentTime+e),a.gain.setValueAtTime((t.volume??.12)*this.volume,r.currentTime),a.gain.exponentialRampToValueAtTime(.001,r.currentTime+e),o.connect(a).connect(this.master),o.start(),o.stop(r.currentTime+e)}catch{}}get audible(){return!this.muted&&!this.held}hold(){this.held=!0,this.ctx?.suspend().catch(()=>{})}release(){this.held=!1,this.ctx?.resume().catch(()=>{})}destroy(){this.ctx?.close().catch(()=>{}),this.ctx=null}};var yl={high:{resolution:1.5,particles:1,effects:!0,maxBlur:32},medium:{resolution:1,particles:.5,effects:!1,maxBlur:16},low:{resolution:.75,particles:.2,effects:!1,maxBlur:0}},Ke=["high","medium","low"];function it(s){let n=yl[s];return{name:s,...n,scale:e=>e<=0?0:Math.max(1,Math.round(e*n.particles))}}var na=s=>Ke[Math.min(Ke.indexOf(s)+1,Ke.length-1)],ur=(s,n)=>{if(!s.length)return NaN;let e=[...s].sort((t,r)=>t-r);return e[Math.min(e.length-1,Math.max(0,Math.floor(n*(e.length-1)+.5)))]},ra=12,sa=s=>Cn(s,.5);function Cn(s,n=.1){let e=ur(s,n);if(!Number.isFinite(e))return 1e3/60;let t=[144,120,90,75,60,50,30],r=60;for(let o of t)Math.abs(1e3/o-e)<Math.abs(1e3/r-e)&&(r=o);return 1e3/r}function hr(s,n){let e=n.refresh!==void 0&&Number.isFinite(n.refresh)&&n.refresh>0?n.refresh:Cn(n.intervals),t=ur(n.intervals,.5),r=ur(n.intervals,.9),o=ur(n.cpu,.5);if(!Number.isFinite(t))return s==="canvas2d"?"low":"medium";let a=u=>u<=e*1.25,i=u=>!Number.isFinite(o)||o<e*u;return s==="canvas2d"?a(r)&&i(.25)?"medium":"low":a(r)&&i(.5)?"high":a(t)?"medium":"low"}function oa(s,n){return s.length<30?!1:s.filter(t=>t>n*1.5).length/s.length>.5}var aa="0.1.1",bl=720*3600*1e3,ia=(s,n,e)=>`fabi-play.engine-tier:${aa}:${s}:${n}:${e}`,la=(s,n,e)=>`fablee-engine-tier:${aa}:${s}:${n}:${e}`;function ca(s,n,e=Date.now()){try{let t=JSON.parse(s?.getItem(n)??"null");if(t&&Ke.includes(t.tier)&&typeof t.at=="number"&&e-t.at<bl)return typeof t.refresh=="number"&&t.refresh>0?{name:t.tier,refresh:t.refresh}:{name:t.tier}}catch{}return null}function Qr(s,n,e,t,r=Date.now()){try{s?.setItem(n,JSON.stringify(t!==void 0&&Number.isFinite(t)?{tier:e,at:r,refresh:t}:{tier:e,at:r}))}catch{}}function ua(s=typeof location<"u"?location.search:""){let n=new URLSearchParams(s).get("tier");return Ke.includes(n)?n:void 0}function Zr(s,n){let e=n?.tier;if(Ke.includes(e))return s==="canvas2d"&&e==="high"?"medium":e}var Jr=s=>typeof s?.hz=="number"&&s.hz>=20&&s.hz<=240?Cn([1e3/s.hz],.5):NaN,es=(s,n)=>Ke.indexOf(s)>=Ke.indexOf(n)?s:n;function ha(s,n,e){return s?{name:s,from:"forced"}:n?{name:e?es(n,e):n,from:"hint"}:e?{name:e,from:"cache"}:null}var xl=/^\s*(<|>|[^+\-<>=\s][^+=]*?)?\s*(?:([+-])=\s*(\d*\.?\d+))?\s*$/,rn=class{constructor(n={}){p(this,"steps",[]);p(this,"labels",new Map);p(this,"end",0);p(this,"prevStart",0);p(this,"elapsed",0);p(this,"iter",0);p(this,"last",0);p(this,"delayLeft");p(this,"_paused");p(this,"done",!1);p(this,"rewinding",!1);p(this,"promise");p(this,"resolve");p(this,"repeat");p(this,"yoyo");p(this,"onComplete");this.repeat=Math.floor(n.repeat??0),this.yoyo=!!n.yoyo,this.delayLeft=n.delay??0,this._paused=!!n.paused,this.onComplete=n.onComplete,this.promise=new Promise(e=>this.resolve=e)}get duration(){return this.end}get time(){return this.last}get paused(){return this._paused}get finished(){return this.done}at(n){if(n===void 0)return this.end;if(typeof n=="number")return Math.max(n,0);let e=xl.exec(n);if(!e)throw new Error(`[engine] timeline: bad position "${n}"`);let[,t,r,o]=e,a=o?(r==="-"?-1:1)*Number(o):0,i=this.end;if(t==="<")i=this.prevStart;else if(t&&t!==">"){let u=this.labels.get(t.trim());u===void 0?this.labels.set(t.trim(),this.end):i=u}return Math.max(i+a,0)}add(n){let e=this.steps.length;for(;e>0&&this.steps[e-1].start>n.start;)e--;return this.steps.splice(e,0,n),this.prevStart=n.start,this.end=Math.max(this.end,n.start+n.dur),this}to(n,e,t,r="quadOut"){let o=typeof r=="object"?r:{ease:r},a=typeof o.ease=="function"?o.ease:ht[o.ease??"quadOut"];return this.add({target:n,to:e,from:null,fn:null,start:this.at(o.at)+(o.delay??0),dur:Math.max(t,0),ease:a,onUpdate:o.onUpdate,p:-1})}set(n,e,t){return this.add({target:n,to:e,from:null,fn:null,start:this.at(t),dur:0,ease:ht.linear,p:-1})}call(n,e){return this.add({target:null,to:null,from:null,fn:n,start:this.at(e),dur:0,ease:ht.linear,p:-1})}label(n,e){return this.labels.set(n,this.at(e)),this}wait(n){return this.end+=Math.max(n,0),this.prevStart=this.end,this}pause(){return this._paused=!0,this}resume(){return this._paused=!1,this}stop(){this.done||(this.done=!0,this.resolve())}seek(n){let e=Math.min(typeof n=="string"&&this.labels.has(n)?this.labels.get(n):this.at(n),this.end),t=this.yoyo&&this.iter%2===1;return this.elapsed=this.iter*this.end+(t?this.end-e:e),this.render(e),this}then(n,e){return this.promise.then(n,e)}update(n){if(this._paused||this.done)return;if(this.delayLeft>0){if(this.delayLeft-=n,this.delayLeft>0)return;n=-this.delayLeft,this.delayLeft=0}let e=this.end;if(e<=0)return this.render(0),this.complete();this.elapsed+=n;let t=this.repeat<0?1/0:e*(this.repeat+1),r=Math.min(this.elapsed,t),o=r>=t?this.repeat:Math.floor(r/e);for(;this.iter<o;){let i=this.yoyo&&this.iter%2===1;this.render(i?0:e),this.iter++,this.yoyo||(this.rewinding=!0,this.render(0),this.rewinding=!1)}let a=r-o*e;this.render(this.yoyo&&o%2===1?e-a:a),r>=t&&this.complete()}complete(){this.done||(this.done=!0,this.onComplete?.(),this.resolve())}render(n){let e=this.steps;if(n>=this.last)for(let t=0;t<e.length;t++){let r=e[t];n>=r.start&&this.apply(r,n)}else for(let t=e.length-1;t>=0;t--){let r=e[t];r.p>=0&&this.apply(r,n)}this.last=n}apply(n,e){let t=n.dur>0?Math.min(Math.max((e-n.start)/n.dur,0),1):e>n.start||e===n.start&&!this.rewinding?1:0;if(t===n.p)return;if(n.p=t,n.fn){this.rewinding||n.fn();return}let r=n.target;if(r.destroyed||r._free)return;let o=n.to;if(!n.from){n.from={};for(let i in o)n.from[i]=Number(r[i]??0)}let a=n.ease(t);for(let i in o)r[i]=n.from[i]+(o[i]-n.from[i])*a;n.onUpdate?.(a)}};var sn=class{constructor(){p(this,"list",[]);p(this,"timelines",[])}timeline(n){let e=new rn(n);return this.timelines.push(e),e}tween(n,e,t,r="quadOut"){let o=typeof r=="object"?r:{ease:r},a=typeof o.ease=="function"?o.ease:ht[o.ease??"quadOut"],i,u=new Promise(c=>{let l=Object.keys(e),f=new Float64Array(l.length);l.forEach((h,y)=>f[y]=Number(e[h])),i={target:n,keys:l,to:f,from:new Float64Array(l.length),started:!1,duration:Math.max(t,0),time:0,delay:o.delay??0,ease:a,onUpdate:o.onUpdate,done:c,dead:!1}});return this.list.push(i),Object.assign(u,{stop:()=>this.finish(i)})}stopAll(n){let e=this.list;for(let t=0;t<e.length;t++)e[t].target===n&&this.finish(e[t])}get size(){return this.list.length}update(n){if(this.timelines.length){let r=0,o=this.timelines;for(let a=0;a<o.length;a++){let i=o[a];i.update(n),i.finished||(o[r++]=i)}o.length=r}let e=this.list;if(!e.length)return;let t=0;for(let r=0;r<e.length;r++){let o=e[r];o.dead||this.step(o,n),o.dead||(e[t++]=o)}t!==e.length&&(e.length=t)}step(n,e){if(n.target.destroyed)return this.finish(n);let t=e;if(n.delay>0){if(n.delay-=e,n.delay>0)return;t=-n.delay}let r=n.keys;if(!n.started){n.started=!0;for(let i=0;i<r.length;i++)n.from[i]=Number(n.target[r[i]]??0)}n.time+=t;let o=n.duration>0?Math.min(n.time/n.duration,1):1,a=n.ease(o);for(let i=0;i<r.length;i++)n.target[r[i]]=n.from[i]+(n.to[i]-n.from[i])*a;n.onUpdate?.(a),o>=1&&this.finish(n)}finish(n){n.dead||(n.dead=!0,n.done())}clear(){for(let n of this.list)this.finish(n);this.list.length=0;for(let n of this.timelines)n.stop();this.timelines=[]}};var he=720,Fn=class extends Ie{constructor(e,t){super(e);p(this,"paintAll",t)}draw(e,t){this.paintAll(e,t)}},ns=class extends Ie{constructor(e,t){super(e);p(this,"paintAll",t)}draw(e,t){this.paintAll(e,t)}},lt=()=>performance.now(),fa=s=>{let n=Ds(s);return n&&Object.freeze(n)};async function da(s={}){let n=s.play??null,e=s.canvas??null;e||(e=document.createElement("canvas"),e.style.cssText="position:fixed;inset:0;width:100%;height:100%;display:block;touch-action:none",document.body.appendChild(e));let t=Kt(e,{renderer:s.renderer??Yo(),failIfMajorPerformanceCaveat:s.failIfMajorPerformanceCaveat,instancing:s.instancing});e=t.canvas;let r=new Set,o=new pt(Math.min(2048,t.maxTextureSize),4);o.onPage=k=>r.add(k),o.onDrop=k=>{r.delete(k),k.texture&&t.destroyTexture(k.texture),k.texture=null};let a=En(t),i=new sn,u=new nn,c=new Ct(o),l=new Map,f=new Map,h=new Map,y=new Map,b=new Map,m=new Set,d=0,x=s.tier??ua(),g=String(t.info.renderer??""),A=(()=>{try{return globalThis.localStorage??null}catch{return null}})(),w=typeof screen<"u"?`${screen.width}x${screen.height}`:"",v=ia(t.kind,g,w);Bs(A,v,la(t.kind,g,w));let R=ca(A,v),F=ha(x,Zr(t.kind,n?.device),R?.name),O=F?.name??"medium",_=it(O);c.setTier(O);let B=F?.from==="hint",$=R?.name,W=R?.refresh??Jr(n?.device),U=1,me=1,G=1,oe={atlas:o,get pixelScale(){return U},get fontGen(){return d},get effects(){return _.effects},tweens:i,frame:k=>Nn.frame(k),shape:k=>{let M=_.effects,C=M?U:-U,E=l.get(C);E||(l.size>=8&&l.clear(),l.set(C,E=new Xt(2e3)));let I=Ge(k),ne=E.get(k,I);return(!ne||!o.valid(ne.frame))&&E.set(k,ne=Kr(o,ta(k,M),U),I),ne},bitmapFont:k=>Nn.bitmapFont(k)},ye=1280,De=null;class mr extends Rt{get width(){return ye}set width(M){}get height(){return he}set height(M){}get safe(){let M=Math.min(ye,he*16/9);return{x:(ye-M)/2,y:0,w:M,h:he}}}let ke=new mr(oe),Be=()=>{let k=t.canvas,M=k.getBoundingClientRect();me=Math.max(1,M.width||k.clientWidth||innerWidth),G=Math.max(1,M.height||k.clientHeight||innerHeight),ye=he*me/G;let C=Math.min(globalThis.devicePixelRatio||1,s.maxPixelRatio??2);if(G*C/he<=_.resolution){let I=Math.max(1,Math.round(G*C));U=I/he,t.resize(Math.max(1,Math.round(me*C)),I)}else U=_.resolution,t.resize(Math.round(ye*U),Math.round(he*U));De&&De.style.setProperty("--unit",`${G/he}px`)};addEventListener("resize",Be);let be=k=>{O=k,_=it(k),c.setTier(k),Be()},fe=typeof ResizeObserver<"u"?new ResizeObserver(Be):null;fe?.observe(e);let ze=n?.backdrop==="video"?"video":"none",S=n?.view??null,L=n?.orientation==="portrait"?"portrait":"landscape",N=fa(n?.safeArea)??Ns,q=[],j=-1/0,ae=!1,Ze=!1,Ce=new Set,on=()=>{let k=ze==="video"?"transparent":"";document.documentElement.style.background=k,document.body.style.background=k},we=(k,M)=>{let C=k==="video"?"video":"none",E=M??null;if(!(C===ze&&(E===S||E&&S&&E.x===S.x&&E.y===S.y&&E.w===S.w&&E.h===S.h))){ze=C,S=E,on();for(let I of[...Ce])I(ze,S)}},Je=[];if(n){let k=E=>{Array.isArray(E)&&(q=E,j=lt())},M=E=>{ae=E,Ve()},C=E=>{if(x||B)return;Number.isFinite(W)||(W=Jr(E));let I=Zr(t.kind,E);I&&(B=!0,be($?es(I,$):I))};Je.push(n.on("start",E=>C(E?.device)),n.on("start",E=>{(E?.orientation==="portrait"||E?.orientation==="landscape")&&(L=E.orientation);let I=fa(E?.safeArea);I&&(N=I)}),n.on("start",E=>{typeof E?.muted=="boolean"&&(u.muted=E.muted)}),n.on("frame",E=>k(E?.players)),n.on("players",E=>k(E?.players)),n.on("backdrop",E=>we(E?.backdrop,E?.view)),n.on("start",E=>we(E?.backdrop,E?.view??n.view)),n.on("pause",()=>M(!0)),n.on("resume",()=>M(!1)),n.on("break-start",()=>M(!0)),n.on("break-done",()=>M(!1)),n.on("break-end",()=>M(!1))),u.muted=n.muted===!0}on();let Ve=()=>ae||Ze||document.hidden?u.hold():u.release(),Fe=-1,Pe=[],et=0,_e=()=>lt()-j<1e3?q:[],bt=k=>n?n.toScreen(k):Mr(S,k),yr=new Ot,xt=()=>{if(Fe===et)return Pe;Fe=et;let k=L==="portrait",M=ze==="video"&&!k||!n?.smoothedBody?()=>null:C=>n.smoothedBody(C);return Pe=lr(_e(),bt,ye,he,M,k?{orientation:L,hold:yr,t:lt()}:void 0),Pe},an={x:0,y:0,w:1,h:1},Na=()=>(an.x=S?S.x*ye:0,an.y=S?S.y*he:0,an.w=S?S.w*ye:ye,an.h=S?S.h*he:he,an),Da=k=>{let M=k.alpha??1,C=k.tags?new yt(o,k):null;C&&m.add(C);let E=typeof k.tags=="function"?k.tags:I=>String(I);return(I,ne)=>{if(ze==="video")return;let H=Na();for(let V of _e()){let pe=n?.smoothedBody?.(V)??V.body,ee=Bt(n?.avatarOf?.(V)??V.avatar??"")??St;if(!c.draw(I.r,I.tex,pe,ee,H,M*ne,U)||!C)continue;let Le=E(V.id);Le&&C.draw(I.r,I.tex,pe,ee,H,Le,tn(V.id),M*ne,U,ye,he)}}},br=new Set,xr=new Set,ln=new Set,_n=!1,gr=0,_t=0,Ln=0,gt={fps:0,cpuMs:0,drawCalls:0,quads:0,filtersSkipped:0},On=0,kr=0,wr=lt(),cn=[],In=0,Ss=()=>({r:t,kernel:oe,tex:a}),Ms=Ss(),Ba=()=>{if(t.lost)return;let[k,M]=ze==="video"||s.background===void 0?[0,0]:de(s.background);t.time=Ln,t.maxBlur=_.maxBlur,t.begin(k,M,U),Se(ke.world,null,ke.x,ke.y,ke.rotation,ke.scaleX,ke.scaleY),Dr(Ms,ke,ke.alpha,ke.tint);let C=t.end();gt.drawCalls=C.drawCalls,gt.quads=C.quads,gt.filtersSkipped=C.filtersSkipped},Ts=k=>{if(!_n)return;gr=requestAnimationFrame(Ts);let M=Math.min(Math.max((k-_t)/1e3,0),.1);_t&&cn.push(k-_t),_t=k,et++;let C=lt(),E=ae||Ze;if(!E){Ln+=M,i.update(M);for(let I of ln)I.destroyed||I.update(M);for(let I of br)I(M,Ln)}for(let I of xr)I(M);ke.sweep();for(let I of ln)I.destroyed&&ln.delete(I);if(t.lost?(In||(In=k),k-In>3e3&&za()):(In=0,Ba()),On++,kr+=lt()-C,C-wr>=1e3&&(gt.fps=Math.round(On*1e3/(C-wr)),gt.cpuMs=Math.round(kr/Math.max(On,1)*100)/100,n?.reportStats?.({fps:gt.fps,renderer:t.kind,tier:O}),On=0,kr=0,wr=C),cn.length>=180){let I=Number.isFinite(W)?W:Cn(cn);!x&&!E&&oa(cn,I)&&O!=="low"&&(be(na(O)),$=O,Qr(A,v,O,Number.isFinite(W)?W:void 0),console.info(`[engine] slow frames: tier ${O}`)),cn.length=0}},za=()=>{let k=Tn(t.canvas),M=qt(k);if(M){console.warn("[engine] WebGL context lost for good: switching to Canvas 2D"),t.destroy(),t=M;for(let C of r)C.texture=null;for(let C of o.pages)r.add(C.surface);a=En(t),Ms=Ss(),fe?.disconnect(),fe?.observe(k),Be()}},Es=()=>{Ve(),document.hidden||(_t=0)};document.addEventListener("visibilitychange",Es);let Rs=()=>{d++;for(let k of m)k.drop()};if(document.fonts?.addEventListener?.("loadingdone",Rs),Be(),!F&&s.probe!==!1&&(Number.isFinite(W)||(W=sa(await gl(ra))),!B)){_=it("high"),Be();let k=await kl(t,o,()=>a,()=>U,ye,()=>B);if(k.refresh=W,!B){let M=hr(t.kind,k);Qr(A,v,M,W),$=M,be(M)}}let Nn={stage:ke,get tier(){return _},get renderer(){return t},get canvas(){return t.canvas},get pixelScale(){return U},get backdrop(){return ze},get view(){return S},get orientation(){return L},get safeArea(){return N},get paused(){return ae||Ze},sound:u,stats:gt,get time(){return Ln},get supports(){let k=t.support;return{filters:k.filters,blur:k.filters&&_.maxBlur>0,shaders:k.shaders,maxBlur:k.filters?_.maxBlur:0,tiers:{high:{maxBlur:it("high").maxBlur},medium:{maxBlur:it("medium").maxBlur},low:{maxBlur:it("low").maxBlur}}}},sprite:(k,M)=>new Te(oe,k,M),shape:(k,M)=>new Xe(oe,k,M),text:(k,M)=>new Ye(oe,k,M),group:k=>new Rt(oe).set(k??{}),particles(k,M={}){let C=typeof k=="object"&&"type"in k?oe.shape(k).frame:k,E=new Gt(oe,C,M),{max:I,blend:ne,gravity:H,drag:V,...pe}=M;return E.set(pe),ln.add(E),E},tween:(k,M,C,E)=>i.tween(k,M,C,E),bake(k,M,C,E,I){return h.set(k,{w:M,h:C,draw:E,origin:I}),f.delete(k),Nn.frame(k)},frame(k){let M=f.get(k);if(M&&o.valid(M)&&(M.gen===0||M.scale===U))return M;let C=h.get(k);if(C){let E=U,I=o.bake(C.w*E,C.h*E,ne=>(ne.scale(E,E),C.draw(ne)),E,C.origin?.x??0,C.origin?.y??0);return f.set(k,I),I}if(M)return M;throw new Error(`[engine] no frame "${k}": load it or bake it first`)},async load(k){await Promise.all(Object.entries(k).map(([M,C])=>$a(M,C)))},hands:k=>k===void 0?xt():xt().filter(M=>M.player===k),touched(k,M,C={}){return k.updateWorld(),cr(k,xt(),M,C.padding??0)},hits(k,M,C,E=0){return k.updateWorld(),Rn(k,M,C,E)},avatars:(k={})=>new Fn(oe,Da(k)),handMarkers(k={}){let M=k.radius??36,C=k.look??"auto",E=new Float64Array(6),I=Math.max(M*.12,3),ne={type:"ring",r:M,lw:I,fill:"rgba(251,231,184,0.3)",stroke:"#ffffff"},H={type:"ring",r:M,lw:I*1.8,stroke:Ft,shadow:{color:Ft,blur:M*.2}},V=(kt,ve,Lt,vr,Dn,wt)=>{let Bn=ve.w/ve.scale;Se(E,null,Lt-Bn/2,vr-Bn/2,0,1,1),kt.r.quad(kt.tex(ve.surface),ve,E,Bn,Bn,Dn,wt,"normal")},pe=kt=>{let ve=null,Lt=!1;return()=>(ve&&o.valid(ve.frame)&&ve.frame.scale===U&&Lt===_.effects?ve:(Lt=_.effects,ve=oe.shape(kt))).frame},ee=pe(ne),Le=pe(H);return new ns(oe,(kt,ve)=>{let Lt=C==="video"||C==="auto"&&ze==="video",vr=ee(),Dn=Lt?Le():null;for(let wt of xt())Dn&&V(kt,Dn,wt.x,wt.y,16777215,ve),V(kt,vr,wt.x,wt.y,de(wt.color)[0],ve)})},timeline:k=>i.timeline(k),animation(k,M){let C=typeof k=="string"?Ha(k):{frames:k},E=new Ne(oe,C,M);return ln.add(E),E},bitmapFont(k,M){if(!M){let E=y.get(k);if(!E)throw new Error(`[engine] no bitmap font "${k}": load or make it first`);return E}let C="data"in M?Cs(en(M.data),M.pages):ea(oe,M);return y.set(k,C),C},players:()=>_e(),onFrame(k){return br.add(k),()=>{br.delete(k)}},onRender(k){return xr.add(k),()=>{xr.delete(k)}},onBackdrop(k){return Ce.add(k),()=>{Ce.delete(k)}},get hud(){return De||(De=document.createElement("div"),De.style.cssText="position:fixed;inset:0;pointer-events:none;overflow:hidden",document.body.appendChild(De),Be()),De},random:(k=0,M=1)=>k+Math.random()*(M-k),start(){_n||(_n=!0,_t=0,gr=requestAnimationFrame(Ts))},pause(){Ze=!0,Ve()},resume(){Ze=!1,Ve()},destroy(){_n=!1,cancelAnimationFrame(gr),Je.forEach(k=>k()),removeEventListener("resize",Be),fe?.disconnect(),document.removeEventListener("visibilitychange",Es),document.fonts?.removeEventListener?.("loadingdone",Rs),i.clear(),vo(oe),u.destroy(),t.destroy(),De?.remove()}};function Ha(k){let M=b.get(k);if(M)return M;let C=[...new Set([...f.keys(),...h.keys()])].filter(E=>E.startsWith(k)).sort(So);if(!C.length)throw new Error(`[engine] no animation or frames "${k}\u2026"`);return{frames:C}}async function $a(k,M){let C=M.split("?")[0].split(".").pop().toLowerCase();if(["mp3","ogg","wav","m4a","aac","webm"].includes(C))return u.load(k,M);if(["woff","woff2","ttf","otf"].includes(C)){let H=new FontFace(k,`url(${M})`);document.fonts.add(await H.load()),d++;return}let E=new URL(M,location.href);if(C==="fnt")return Fs(k,en(await(await fetch(M)).text()),E);if(C==="json"){let H=await(await fetch(M)).json();if(Array.isArray(H.chars)&&!H.frames)return Fs(k,en(H),E);let V=await ts(new URL(H.meta?.image??M.replace(/\.json$/,".png"),E).href);Ga(k,H,Ut(V));return}let I=await ts(M),ne=Ut(I);r.add(ne),f.set(k,{surface:ne,x:0,y:0,w:I.width,h:I.height,scale:1,gen:0,ox:0,oy:0,margin:0})}function Cs(k,M){return Jo(k,M.map(C=>{let E=Ut(C);return r.add(E),E}))}async function Fs(k,M,C){y.set(k,Cs(M,await Promise.all(M.pages.map(E=>ts(new URL(E,C).href)))))}function Ga(k,M,C){r.add(C);let E=Array.isArray(M.frames)?M.frames:Object.entries(M.frames).map(([H,V])=>({...V,filename:H})),I=[],ne=[];for(let H of E){let V=H.frame,pe=H.filename.replace(pa,"");H.rotated&&console.warn(`[engine] ${k}/${pe} is rotated: export without rotation`);let ee={surface:C,x:V.x,y:V.y,w:V.w,h:V.h,scale:1,gen:0,ox:0,oy:0,margin:0};H.trimmed&&H.sourceSize&&H.spriteSourceSize&&(ee.sw=H.sourceSize.w,ee.sh=H.sourceSize.h,ee.tx=H.spriteSourceSize.x,ee.ty=H.spriteSourceSize.y);let Le=H.scale9Borders;Le&&(ee.slice=[Le.y,(ee.sw??V.w)-Le.x-Le.w,(ee.sh??V.h)-Le.y-Le.h,Le.x]),f.set(`${k}/${pe}`,ee),I.push(`${k}/${pe}`),ne.push((H.duration??0)/1e3)}for(let[H,V]of Object.entries(M.animations??{}))b.set(`${k}/${H}`,{frames:V.map(pe=>`${k}/${pe.replace(pa,"")}`)});for(let H of M.meta?.frameTags??[]){let V=[];for(let ee=H.from;ee<=H.to;ee++)V.push(ee);H.direction==="reverse"&&V.reverse(),H.direction==="pingpong"&&V.push(...V.slice(1,-1).reverse());let pe=V.every(ee=>ne[ee]>0);b.set(`${k}/${H.name}`,{frames:V.map(ee=>I[ee]),...pe?{durations:V.map(ee=>ne[ee])}:{}})}}return Nn}var pa=/\.(png|webp|jpe?g|gif|bmp)$/i;function ts(s){return new Promise((n,e)=>{let t=new Image;t.onload=()=>n(t),t.onerror=()=>e(new Error(`[engine] image did not load: ${s}`)),t.src=s})}function gl(s){return new Promise(n=>{let e=[],t=0,r=o=>{t&&e.push(o-t),t=o,e.length<s?requestAnimationFrame(r):n(e)};requestAnimationFrame(r)})}async function kl(s,n,e,t,r,o=()=>!1){let a=t(),i=Kr(n,{type:"star",r:30,fill:"#ffd23f",stroke:"#3a2a10",lw:3},a).frame,u=[],c=[],l=new Float64Array(6),f=.004,h=s.kind==="canvas2d"?s.canvas.getContext("2d"):null,y=lt(),b=0;return await new Promise(m=>{let d=x=>{b&&x-y>250&&u.push(x-b),b=x;let g=lt();s.begin(0,0,a);let A=e();for(let w=0;w<300;w++){let v=x/1e3+w;Se(l,null,w*37%r,w*53%he,v,1,1),s.quad(A(i.surface),i,l,i.w/a,i.h/a,16777215,f,"normal")}for(let w=0;w<40;w++)s.ellipse(100+w*20,300,20,14,w,16746496,f),s.stroke([100+w*20,400,120+w*20,460,100+w*20,520],3,18,3368703,f,!1);s.end(),h?.getImageData(0,0,1,1),x-y>250&&c.push(lt()-g),x-y<750&&!o()?requestAnimationFrame(d):(s.begin(0,0,a),s.end(),m())};requestAnimationFrame(d)}),{intervals:u,cpu:c}}var wl=64,ma=32,vl=0,Al=`fabi-cm-${Math.random().toString(36).slice(2,7)}-`,ya=new Set,ba=(s,n)=>{ya.has(s)||(ya.add(s),console.warn(n))},xa=s=>new rs(s),rs=class{constructor(n){p(this,"r",n);p(this,"css","none");p(this,"plans",new Xt(wl));p(this,"buf",new Float64Array(64));p(this,"keys",[]);p(this,"classes",new Map);p(this,"live",new Set);p(this,"svgs",new Map);p(this,"t",0);p(this,"cur",null);p(this,"svgFn",n=>this.svg(n));p(this,"scr",[]);p(this,"flip",0)}chain(n,e){var b;let t=this.r,r=this.buf;r[0]=t.scale,r[1]=t.maxBlur;let o=2;for(let m=0;m<e.length;m++){let d=e[m];if(o+22>r.length){let g=new Float64Array(r.length*2);g.set(r),r=this.buf=g}let x=this.classes.get(d.constructor);x===void 0&&this.classes.set(d.constructor,x=this.classes.size),r[o++]=x,r[o++]=d.enabled?1:0,d.params&&(o=d.params(r,o))}let a=(b=this.keys)[o]??(b[o]=new Float64Array(o));for(let m=0;m<o;m++)a[m]=r[m];let i=Ge(a),u=this.plans.get(a,i);u||this.plans.set(a,u=this.plan(e),i);for(let m=0;m<u.svgs.length;m++){let d=u.svgs[m];d.used<0&&this.attach(d),d.used=this.t}t.skipped+=u.skip;let c=n,l=t.rx0,f=t.ry0,h=t.rx1-l,y=t.ry1-f;for(let m=0;m<u.paints.length;m++)u.parts[m]&&(c=this.bake(c,u.parts[m])),e[u.paints[m]].paint2d(c.getContext("2d"),l,f,h,y);return this.css=u.parts[u.paints.length]||"none",c}tick(){let n=++this.t;if(!(n%ma||!this.live.size))for(let e of this.live)n-e.used>ma&&this.detach(e)}destroy(){for(let n of this.live)this.detach(n);this.plans.clear()}svg(n){if(typeof document>"u"||!document.body)return null;let e=Array.from({length:20},(r,o)=>n[o]??0).join(" "),t=this.svgs.get(e);if(!t){let r="http://www.w3.org/2000/svg",o=document.createElementNS(r,"svg");o.setAttribute("width","0"),o.setAttribute("height","0"),o.setAttribute("aria-hidden","true"),o.style.position="absolute";let a=document.createElementNS(r,"filter"),i=Al+ ++vl;a.setAttribute("id",i),a.setAttribute("color-interpolation-filters","sRGB");let u=document.createElementNS(r,"feColorMatrix");u.setAttribute("type","matrix"),u.setAttribute("values",e),a.append(u),o.append(a),this.attach(t={key:e,id:i,el:o,used:this.t})}return this.cur.svgs.push(t),`url(#${t.id})`}attach(n){document.body.append(n.el),this.live.add(n),this.svgs.has(n.key)||this.svgs.set(n.key,n)}detach(n){n.el.remove(),n.used=-1,this.live.delete(n),this.svgs.get(n.key)===n&&this.svgs.delete(n.key)}plan(n){let e=this.r,t=this.cur={parts:[],paints:[],skip:0,svgs:[]},r="";for(let o=0;o<n.length;o++){let a=n[o];if(!a.enabled)continue;if(a.kind===4){t.skip++,ba("shader","[engine] shader() filters are WebGL only: on Canvas 2D they are skipped (check engine.supports.shaders)");continue}let i=e.support.filters&&a.css?a.css(e.scale,e.maxBlur,this.svgFn):null;i!==null?r+=r?` ${i}`:i:a.paint2d?(t.parts.push(r),t.paints.push(o),r=""):(t.skip++,ba("css","[engine] this browser's Canvas 2D has no ctx.filter: colour filters, blur and shadows are skipped (tint works; check engine.supports.filters)"))}return t.parts.push(r),t}bake(n,e){let t=this.r,r=this.flip^=1,o=this.scr[r];(!o||o.width!==t.canvas.width||o.height!==t.canvas.height)&&(o=this.scr[r]=document.createElement("canvas"),o.width=t.canvas.width,o.height=t.canvas.height);let a=o.getContext("2d"),i=t.rx0,u=t.ry0,c=t.rx1-i,l=t.ry1-u;return a.clearRect(i,u,c,l),a.filter=e,a.drawImage(n,i,u,c,l,i,u,c,l),a.filter="none",o}};var Sl=64,fr=17,Ml=s=>`${sr}
|
|
49
49
|
uniform sampler2D uTexture;
|
|
50
50
|
uniform mat4 uM[${s}];
|
|
51
51
|
uniform vec4 uO[${s}];
|
|
@@ -61,11 +61,11 @@ void main() {
|
|
|
61
61
|
}
|
|
62
62
|
c.rgb *= c.a;
|
|
63
63
|
gl_FragColor = c * vColor;
|
|
64
|
-
}`,
|
|
64
|
+
}`,Tl=()=>`${sr}
|
|
65
65
|
uniform sampler2D uTexture;
|
|
66
66
|
uniform vec2 uDir;
|
|
67
67
|
uniform vec2 uOff;
|
|
68
|
-
uniform vec2 uTaps[${
|
|
68
|
+
uniform vec2 uTaps[${fr}];
|
|
69
69
|
uniform int uN;
|
|
70
70
|
uniform float uMode;
|
|
71
71
|
uniform vec4 uShadow;
|
|
@@ -74,15 +74,15 @@ varying vec4 vColor;
|
|
|
74
74
|
void main() {
|
|
75
75
|
vec2 p = vUv + uOff;
|
|
76
76
|
vec4 c = texture2D(uTexture, p) * uTaps[0].y;
|
|
77
|
-
for (int i = 1; i < ${
|
|
77
|
+
for (int i = 1; i < ${fr}; i++) {
|
|
78
78
|
if (i >= uN) break;
|
|
79
79
|
vec2 d = uDir * uTaps[i].x;
|
|
80
80
|
c += (texture2D(uTexture, p + d) + texture2D(uTexture, p - d)) * uTaps[i].y;
|
|
81
81
|
}
|
|
82
82
|
if (uMode > 0.5) c = uShadow * c.a;
|
|
83
83
|
gl_FragColor = c * vColor;
|
|
84
|
-
}`;function
|
|
85
|
-
${i}`)}return t.set(n,{p:o,t:++this.uses}),o}scratch(n,e){let t=this.r,r=Math.ceil(t.canvas.width/n),o=Math.ceil(t.canvas.height/n),a=n*8+e,i=this.scratchT.get(a)??null;return i&&(i.w!==r||i.h!==o)&&(t.drop(i),i=null),i||(i=t.target(r,o,n,!0),i?this.scratchT.set(a,i):this.scratchT.delete(a)),i}pass(n,e,t,r,o=!1){let a=this.r,i=a.gl;a.flush(),a.mapped=!1,a.bindFb(r),i.viewport(0,0,r.w,r.h),o||(i.disable(i.SCISSOR_TEST),i.clearColor(0,0,0,0),i.clear(i.COLOR_BUFFER_BIT)),a.use(n);let
|
|
84
|
+
}`;function El(s,n,e=new Float32Array(20)){for(let t=0;t<4;t++)for(let r=0;r<5;r++){let o=r===4?n[t*5+4]:0;for(let a=0;a<4;a++)o+=n[t*5+a]*s[a*5+r];e[t*5+r]=o}return s.set(e),s}var ga=s=>new is(s),is=class{constructor(n){p(this,"r",n);p(this,"colorProg",null);p(this,"blurProg",null);p(this,"user",new Map);p(this,"uses",0);p(this,"userErr",new Map);p(this,"scratchT",new Map);p(this,"steps",[]);p(this,"mats",[]);p(this,"counts",[]);p(this,"colorN");p(this,"fm",new Float32Array(20));p(this,"fm2",new Float32Array(20));p(this,"fm3",new Float32Array(20));p(this,"m16");p(this,"o4");p(this,"taps",new Float32Array(fr*2));let e=n.gl;this.colorN=Math.max(1,Math.min(8,Math.floor((e.getParameter(e.MAX_FRAGMENT_UNIFORM_VECTORS)-4)/5))),this.m16=new Float32Array(16*this.colorN),this.o4=new Float32Array(4*this.colorN)}check(n){return this.r.lost?null:(this.userProg(n,!1),this.userErr.get(n)??null)}destroy(){let n=this.r.gl;for(let e of this.scratchT.values())n.deleteTexture(e.gl),n.deleteFramebuffer(e.fb);this.scratchT.clear();for(let e of[this.colorProg,this.blurProg])e&&n.deleteProgram(e.p);for(let e of this.user.values())e.p&&n.deleteProgram(e.p.p);this.user.clear()}userProg(n,e){let t=this.user,r=t.get(n);if(r)return r.t=++this.uses,r.p;if(this.r.lost)return null;if(t.size>=Sl){let a="",i=1/0;for(let[c,l]of t)l.t<i&&(i=l.t,a=c);let u=t.get(a).p;u&&this.r.gl.deleteProgram(u.p),t.delete(a),this.userErr.delete(a)}let o;try{o=this.r.build(n)}catch(a){o=null;let i=a.message;this.userErr.set(n,i),e&&console.error(`[engine] a shader filter does not compile: it is skipped.
|
|
85
|
+
${i}`)}return t.set(n,{p:o,t:++this.uses}),o}scratch(n,e){let t=this.r,r=Math.ceil(t.canvas.width/n),o=Math.ceil(t.canvas.height/n),a=n*8+e,i=this.scratchT.get(a)??null;return i&&(i.w!==r||i.h!==o)&&(t.drop(i),i=null),i||(i=t.target(r,o,n,!0),i?this.scratchT.set(a,i):this.scratchT.delete(a)),i}pass(n,e,t,r,o=!1){let a=this.r,i=a.gl;a.flush(),a.mapped=!1,a.bindFb(r),i.viewport(0,0,r.w,r.h),o||(i.disable(i.SCISSOR_TEST),i.clearColor(0,0,0,0),i.clear(i.COLOR_BUFFER_BIT)),a.use(n);let u=r.f;i.uniform2f(n.uScale,2/(u*r.w),-2/(u*r.h));let c=Math.floor(a.rx0/u)*u,l=Math.floor(a.ry0/u)*u,f=Math.min(Math.ceil(a.rx1/u),r.w)*u,h=Math.min(Math.ceil(a.ry1/u),r.h)*u,y=1/(t*e.width),b=1/(t*e.height);a.bScis=!1,a.batch.push(c,l,f,l,f,h,c,h,c*y,1-l*b,f*y,1-h*b,4294967295,a.slotOf(e)),a.flush()}post(n){return n==="color"?this.colorProg??(this.colorProg=this.r.build(Ml(this.colorN))):this.blurProg??(this.blurProg=this.r.build(Tl()))}linear(n,e){let t=this.r,r=t.gl;t.bindTex(t.layerTex.get(n)??null,0);let o=e?r.LINEAR:r.NEAREST;r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MIN_FILTER,o),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MAG_FILTER,o)}chain(n,e,t){let r=this.r,o=this.steps,a=r.scale,i=r.maxBlur,u=0;for(let h=0;h<t.length;h++){let y=t[h];if(y.enabled)if(y.kind===1&&y.toMatrix){(!u||o[u-1]!==null)&&(o[u]=null,(!this.mats[u]||this.mats[u].length<20*this.colorN)&&(this.mats[u]=new Float32Array(20*this.colorN)),this.counts[u]=0,u++);let b=this.mats[u-1],m=this.counts[u-1];if(m<this.colorN)y.toMatrix(this.fm),b.set(this.fm,m*20),this.counts[u-1]=m+1;else{let d=(m-1)*20;for(let x=0;x<20;x++)this.fm2[x]=b[d+x];y.toMatrix(this.fm),El(this.fm2,this.fm,this.fm3),b.set(this.fm2,d)}}else y.kind===4?this.userProg(y.source,!0)?o[u++]=y:r.skipped++:y.kind===2?Math.min(y.radius,i)*a>=.25&&(o[u++]=y):y.kind===3?o[u++]=y:r.skipped++}if(!u)return!1;let c=r.gl,l=n,f=-1;for(let h=0;h<u;h++){let y=h===u-1,b=f===0?1:0,m=y?null:this.scratch(1,b);if(!y&&!m)break;let d=o[h];if(d===null){let x=this.post("color");r.use(x);let g=this.mats[h],A=this.counts[h],w=this.m16,v=this.o4;for(let R=0;R<A;R++)for(let F=0;F<4;F++){for(let O=0;O<4;O++)w[R*16+O*4+F]=g[R*20+F*5+O];v[R*4+F]=g[R*20+F*5+4]}c.uniformMatrix4fv(r.u(x,"uM"),!1,w),c.uniform4fv(r.u(x,"uO"),v),c.uniform1i(r.u(x,"uK"),A),m?this.pass(x,l,1,m):r.final(x,l,1,e)}else if(d.kind===2)this.blur(l,f<0,Math.min(d.radius,i)*a,m,e,null);else if(d.kind===3){let x=d,g=this.scratch(1,2);if(!g)break;this.blur(l,f<0,Math.max(Math.min(x.blur,i),0)*a,g,1,x);let A=m??(e<1?this.scratch(1,b):null);A?(this.pass(r.main,g.tex,1,A),this.pass(r.main,l,1,A,!0),m||r.final(r.main,A.tex,1,e)):(r.final(r.main,g.tex,1,1),r.final(r.main,l,1,1))}else{let x=d,g=this.userProg(x.source,!0);r.use(g);let A=r.canvas.width,w=r.canvas.height;c.uniform2f(r.u(g,"uResolution"),A,w),c.uniform1f(r.u(g,"uTime"),r.time),c.uniform4f(r.u(g,"uRect"),r.rx0/A,1-r.ry1/w,r.rx1/A,1-r.ry0/w);let v=x.uniforms;for(let R in v){let F=r.u(g,R);if(!F)continue;let O=v[R];typeof O=="number"?c.uniform1f(F,O):O.length===2?c.uniform2fv(F,O):O.length===3?c.uniform3fv(F,O):O.length===4?c.uniform4fv(F,O):O.length===1&&c.uniform1fv(F,O)}m?this.pass(g,l,1,m):r.final(g,l,1,e)}m&&(l=m.tex,f=b)}return r.remap(),!0}blur(n,e,t,r,o,a){let i=this.r,u=i.gl,c=this.post("blur"),l=1;for(;l<16&&t/l>8;)l*=2;e&&this.linear(n,!0);let f=n,h=1,y=Math.sqrt(Math.max(t*t-(l*l-1)/12,0))/l,b=t>=.25?this.tapsFor(y):this.tapsFor(0),m=!0;if(b>1){for(let x=2;x<=l&&m;x*=2){let g=this.scratch(x,0);g?(this.pass(i.main,f,h,g),f=g.tex,h=x):m=!1}let d=m?this.scratch(l,3):null;d&&(i.use(c),u.uniform2fv(i.u(c,"uTaps"),this.taps),u.uniform1i(i.u(c,"uN"),b),u.uniform2f(i.u(c,"uDir"),1/f.width,0),u.uniform2f(i.u(c,"uOff"),0,0),u.uniform1f(i.u(c,"uMode"),0),this.pass(c,f,h,d),f=d.tex)}if(i.use(c),u.uniform2fv(i.u(c,"uTaps"),this.taps),u.uniform1i(i.u(c,"uN"),b),u.uniform2f(i.u(c,"uDir"),0,1/f.height),a){let d=a.opacity,x=a.rgb;u.uniform4f(i.u(c,"uShadow"),(x>>16&255)/255*d,(x>>8&255)/255*d,(x&255)/255*d,d),u.uniform1f(i.u(c,"uMode"),1),u.uniform2f(i.u(c,"uOff"),-a.dx*i.scale/(h*f.width),a.dy*i.scale/(h*f.height))}else u.uniform1f(i.u(c,"uMode"),0),u.uniform2f(i.u(c,"uOff"),0,0);r?this.pass(c,f,h,r):i.final(c,f,h,o),e&&this.linear(n,!1)}tapsFor(n){let e=this.taps;if(e.fill(0),e[1]=1,n<.2)return 1;let t=Math.min(Math.ceil(3*n),(fr-1)*2),r=-1/(2*n*n),o=1,a=1;for(let i=1;i<=t;i+=2){let u=Math.exp(i*i*r),c=i+1<=t?Math.exp((i+1)*(i+1)*r):0,l=u+c;e[a*2]=(i*u+(i+1)*c)/l,e[a*2+1]=l,o+=2*l,a++}for(let i=0;i<a;i++)e[i*2+1]=e[i*2+1]/o;return a}};var ct=s=>Math.min(Math.max(s,0),1),Ue=s=>Math.max(s,0),Pt=class{constructor(){p(this,"enabled",!0);Me.gl=ga,Me.c2d=xa}},Qe=class extends Pt{constructor(e){super();p(this,"amount",e);p(this,"kind",1)}params(e,t){return e[t]=this.amount,t+1}};function pr(s,n,e){s.fill(0),s[0]=s[6]=s[12]=n,s[4]=s[9]=s[14]=e,s[18]=1}function dr(s,n){s.fill(0);for(let e=0;e<3;e++)for(let t=0;t<3;t++)s[e*5+t]=n[e*3+t];s[18]=1}var D=new Float64Array(9),cs=class extends Qe{toMatrix(n){pr(n,Ue(this.amount),0)}css(){return`brightness(${Ue(this.amount)})`}},us=class extends Qe{toMatrix(n){let e=Ue(this.amount);pr(n,e,.5-.5*e)}css(){return`contrast(${Ue(this.amount)})`}},hs=class extends Qe{toMatrix(n){let e=ct(this.amount);pr(n,1-2*e,e)}css(){return`invert(${ct(this.amount)})`}},fs=class extends Qe{toMatrix(n){let e=Ue(this.amount);D[0]=.213+.787*e,D[1]=.715-.715*e,D[2]=.072-.072*e,D[3]=.213-.213*e,D[4]=.715+.285*e,D[5]=.072-.072*e,D[6]=.213-.213*e,D[7]=.715-.715*e,D[8]=.072+.928*e,dr(n,D)}css(){return`saturate(${Ue(this.amount)})`}},ps=class extends Qe{toMatrix(n){let e=1-ct(this.amount);D[0]=.2126+.7874*e,D[1]=.7152-.7152*e,D[2]=.0722-.0722*e,D[3]=.2126-.2126*e,D[4]=.7152+.2848*e,D[5]=.0722-.0722*e,D[6]=.2126-.2126*e,D[7]=.7152-.7152*e,D[8]=.0722+.9278*e,dr(n,D)}css(){return`grayscale(${ct(this.amount)})`}},ds=class extends Qe{toMatrix(n){let e=1-ct(this.amount);D[0]=.393+.607*e,D[1]=.769-.769*e,D[2]=.189-.189*e,D[3]=.349-.349*e,D[4]=.686+.314*e,D[5]=.168-.168*e,D[6]=.272-.272*e,D[7]=.534-.534*e,D[8]=.131+.869*e,dr(n,D)}css(){return`sepia(${ct(this.amount)})`}},ms=class extends Qe{get angle(){return this.amount}set angle(n){this.amount=n}toMatrix(n){let e=this.amount*Math.PI/180,t=Math.cos(e),r=Math.sin(e);D[0]=.213+t*.787-r*.213,D[1]=.715-t*.715-r*.715,D[2]=.072-t*.072+r*.928,D[3]=.213-t*.213+r*.143,D[4]=.715+t*.285+r*.14,D[5]=.072-t*.072-r*.283,D[6]=.213-t*.213-r*.787,D[7]=.715-t*.715+r*.715,D[8]=.072+t*.928+r*.072,dr(n,D)}css(){return`hue-rotate(${this.amount}deg)`}},ys=class extends Qe{constructor(e,t){super(t);p(this,"c",16777215);p(this,"cs","");this.color=e}get color(){return this.c}set color(e){this.c=de(e)[0],this.cs=Mt(this.c)}params(e,t){return e[t]=this.amount,e[t+1]=this.c,t+2}toMatrix(e){let t=ct(this.amount);pr(e,1-t,0),e[4]=(this.c>>16&255)/255*t,e[9]=(this.c>>8&255)/255*t,e[14]=(this.c&255)/255*t}css(){return null}paint2d(e,t,r,o,a){let i=ct(this.amount);i<=0||(e.save(),e.setTransform(1,0,0,1,0,0),e.globalAlpha=i,e.globalCompositeOperation="source-atop",e.fillStyle=this.cs,e.fillRect(t,r,o,a),e.restore())}},bs=class extends Pt{constructor(e){super();p(this,"kind",1);p(this,"values");if(e.length!==20)throw new Error(`colorMatrix: 20 numbers expected (4 rows of 5), got ${e.length}`);this.values=Array.from(e)}toMatrix(e){for(let t=0;t<20;t++)e[t]=this.values[t]??0}params(e,t){for(let r=0;r<20;r++)e[t+r]=this.values[r]??0;return t+20}css(e,t,r){return r?r(this.values):null}},xs=class extends Pt{constructor(e){super();p(this,"radius",e);p(this,"kind",2)}params(e,t){return e[t]=this.radius,t+1}pad(e){return 3*Math.min(Ue(this.radius),e)}css(e,t){return`blur(${Math.min(Ue(this.radius),t)*e}px)`}},gs=class extends Pt{constructor(e,t,r,o){super();p(this,"dx",e);p(this,"dy",t);p(this,"blur",r);p(this,"kind",3);p(this,"rgb",0);p(this,"a",1);this.color=o}get opacity(){return this.a}set opacity(e){this.a=ct(e)}get color(){return this.rgb}set color(e){let[t,r]=de(e);this.rgb=t,this.a=r}params(e,t){return e[t]=this.dx,e[t+1]=this.dy,e[t+2]=this.blur,e[t+3]=this.rgb,e[t+4]=this.a,t+5}pad(e){return 3*Math.min(Ue(this.blur),e)+Math.max(Math.abs(this.dx),Math.abs(this.dy))}css(e,t){return`drop-shadow(${this.dx*e}px ${this.dy*e}px ${2*Math.min(Ue(this.blur),t)*e}px ${Mt(this.rgb,this.opacity)})`}},Rl=`#ifdef GL_FRAGMENT_PRECISION_HIGH
|
|
86
86
|
precision highp float;
|
|
87
87
|
#else
|
|
88
88
|
precision mediump float;
|
|
@@ -95,11 +95,11 @@ varying vec2 vUv;
|
|
|
95
95
|
varying vec4 vColor;
|
|
96
96
|
#define main fabiUserMain
|
|
97
97
|
#line 1
|
|
98
|
-
`,
|
|
98
|
+
`,Cl=s=>`${Rl}${s}
|
|
99
99
|
#undef main
|
|
100
100
|
void main() {
|
|
101
101
|
fabiUserMain();
|
|
102
102
|
gl_FragColor *= vColor.a;
|
|
103
103
|
}
|
|
104
|
-
`,
|
|
105
|
-
${e}`);return n}var
|
|
104
|
+
`,ks=class extends Pt{constructor(e){super();p(this,"kind",4);p(this,"source");p(this,"uniforms",{});p(this,"padding");this.source=Cl(e.fragment),this.padding=e.padding??0;for(let t in e.uniforms??{}){let r=e.uniforms[t];this.uniforms[t]=typeof r=="number"?r:Float32Array.from(r)}}pad(){return Ue(this.padding)}},ka=(s,n=1)=>new ys(s,n),wa=s=>new cs(s),va=s=>new us(s),Aa=s=>new fs(s),Sa=(s=1)=>new ps(s),Ma=(s=1)=>new ds(s),Ta=s=>new ms(s),Ea=(s=1)=>new hs(s),Ra=s=>new bs(s),Ca=s=>new xs(s),Fa=(s,n,e,t="rgba(0,0,0,0.5)")=>new gs(s,n,e,t);function Pa(s){let n=new ks(s),e=Me.live?.filters()?.check(n.source);if(e)throw new Error(`shader(): the fragment does not compile:
|
|
105
|
+
${e}`);return n}var ws="x y rotation scaleX scaleY alpha visible blend tint z hitRadius clip mask filters".split(" "),La="frameName _frame _w _h slice autoAnchor".split(" "),Fl="fps loop speed onComplete durations".split(" "),vs=["anchorX","anchorY"],Pl=[...ws,...La,...Fl,...vs],_l=[...ws,...La,...vs],Ll=[...ws,...vs],Oa=s=>s instanceof Ne?Pl:s instanceof Te?_l:Ll;function Ol(s){let n={},e=s;for(let t of Oa(s))n[t]=e[t];return s instanceof Xe&&(n.spec=s.spec),s instanceof Ye&&(n.text=s.text,n.style=s.style),s instanceof Ne&&(n.playing=s.playing),n}function _a(s,n){let e=s;s instanceof Xe&&s.spec!==n.spec&&(s.spec=n.spec),s instanceof Ye&&(s.text=n.text,s.style!==n.style&&(e._style=n.style,e.dirty=!0)),s instanceof Ne&&s.gotoFrame(n.speed<0?s.frameCount-1:0);let t=s instanceof Xe||s instanceof Ye,r=Oa(s);for(let o=0;o<r.length;o++){let a=r[o];(!t||a!=="_frame"&&a!=="frameName")&&(e[a]=n[a])}}var Pn=class{constructor(n,e={}){p(this,"factory",n);p(this,"opts",e);p(this,"stats",{live:0,free:0,created:0});p(this,"free",[]);p(this,"states",new Map);p(this,"dead",!1)}get(n){if(this.dead)throw new Error("[engine] nodePool.get() after destroy()");let e=this.free.pop();if(e){this.stats.free--,e._free=!1;let t=this.states.get(e);_a(e,t),e.visible=t.visible,e instanceof Ne&&t.playing&&e.play()}else{if(e=this.factory(),!(e instanceof Ie))throw new Error("[engine] a nodePool factory must return a node (engine.sprite, engine.shape, \u2026)");if(e._pool)throw new Error("[engine] a nodePool factory returned a node of another pool: make a new node in it");this.states.set(e,Ol(e)),e._pool=this,this.stats.created++}return this.stats.live++,n&&e.set(n),e}release(n){let e=this.states.get(n);if(!(!e||n.destroyed)&&!n._free){if(this.opts.max!==void 0&&this.free.length>=this.opts.max)return n.destroy();n.parent?.remove(n),n.kernel.tweens.stopAll(n),this.stats.live--,_a(n,e),n instanceof Ne&&n.stop(),n.visible=!1,n._free=!0,this.opts.reset?.(n),this.free.push(n),this.stats.free++}}forget(n){let e=n;if(this.states.delete(e))if(e._free){let t=this.free.indexOf(e);t>=0&&(this.free[t]=this.free[this.free.length-1],this.free.pop()),this.stats.free--}else this.stats.live--}clear(){for(;this.free.length;)this.free[this.free.length-1].destroy()}destroy(){this.dead=!0;for(let n of[...this.states.keys()])n.destroy()}},Ia=(s,n)=>new Pn(s,n);window.FabiEngine=As;})();
|