@cimplify/sdk 0.108.0 → 0.110.2

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.
Files changed (608) hide show
  1. package/LICENSE +21 -0
  2. package/dist/advanced.d.mts +4 -3
  3. package/dist/advanced.d.ts +4 -3
  4. package/dist/advanced.js +24 -24
  5. package/dist/advanced.mjs +5 -5
  6. package/dist/animation-4EXBXRVX.js +27 -0
  7. package/dist/animation-6DICNWUP.mjs +6 -0
  8. package/dist/audio-DhvyjqdA.d.mts +249 -0
  9. package/dist/audio-m0w8cnxq.d.ts +249 -0
  10. package/dist/avatars.d.mts +110 -0
  11. package/dist/avatars.d.ts +110 -0
  12. package/dist/avatars.js +82 -0
  13. package/dist/avatars.mjs +5 -0
  14. package/dist/backend-gUCzs5Kg.d.mts +3866 -0
  15. package/dist/backend-gUCzs5Kg.d.ts +3866 -0
  16. package/dist/{catalogue-B4eLL8Mi.d.ts → catalogue-CPTMyBUz.d.mts} +109 -221
  17. package/dist/catalogue-DzrTXP3v.d.mts +541 -0
  18. package/dist/catalogue-DzrTXP3v.d.ts +541 -0
  19. package/dist/{catalogue-OT89_Ifs.d.mts → catalogue-OTuS5zp-.d.ts} +109 -221
  20. package/dist/chunk-22BD3RHN.mjs +1809 -0
  21. package/dist/chunk-25T4JHEA.mjs +21 -0
  22. package/dist/chunk-2AQ237Y4.js +508 -0
  23. package/dist/chunk-2IC4H6OV.mjs +48 -0
  24. package/dist/chunk-2LHLG4OB.mjs +71 -0
  25. package/dist/chunk-2O2CG465.js +1709 -0
  26. package/dist/chunk-2Q4DTHXK.js +316 -0
  27. package/dist/chunk-2QTQ6BUH.mjs +46 -0
  28. package/dist/chunk-2UN4SFLR.mjs +100 -0
  29. package/dist/chunk-2V75I7K3.js +454 -0
  30. package/dist/chunk-2V7IL4HC.js +10 -0
  31. package/dist/chunk-34XBXUMW.js +296 -0
  32. package/dist/chunk-3C4C654I.js +71 -0
  33. package/dist/chunk-3DAD2LDF.mjs +72 -0
  34. package/dist/chunk-3GXH2NFD.mjs +4 -0
  35. package/dist/chunk-3O47ZFW3.js +961 -0
  36. package/dist/chunk-3OY3VYNF.mjs +11 -0
  37. package/dist/chunk-3S6WPBZL.js +2936 -0
  38. package/dist/chunk-3TUOUP5T.js +399 -0
  39. package/dist/chunk-3VEH23I5.mjs +1380 -0
  40. package/dist/chunk-3ZYSAW2T.mjs +263 -0
  41. package/dist/chunk-4ANVF274.js +103 -0
  42. package/dist/chunk-4C7I3ELN.js +388 -0
  43. package/dist/chunk-4DYKAYFO.mjs +8 -0
  44. package/dist/chunk-4ZDR72SG.js +329 -0
  45. package/dist/chunk-52YS45RR.js +1066 -0
  46. package/dist/chunk-5325XSCH.js +107 -0
  47. package/dist/chunk-5AD5X6AV.js +13 -0
  48. package/dist/chunk-5BYDGGWO.mjs +197 -0
  49. package/dist/chunk-5C3C7VDM.mjs +55 -0
  50. package/dist/chunk-5HFMY3D7.js +660 -0
  51. package/dist/chunk-5LH2QN3T.js +1862 -0
  52. package/dist/chunk-5PJEXSOW.js +44 -0
  53. package/dist/chunk-5SXDH3Y7.js +90 -0
  54. package/dist/chunk-5YFBGGCK.mjs +502 -0
  55. package/dist/chunk-5YWN6H5Q.mjs +133 -0
  56. package/dist/chunk-66QP3SMN.js +402 -0
  57. package/dist/chunk-6DAEZKIG.mjs +385 -0
  58. package/dist/chunk-6DATW7TB.mjs +420 -0
  59. package/dist/{chunk-JRGK3NXR.mjs → chunk-6ETDAU62.mjs} +72 -212
  60. package/dist/chunk-6H254EVP.mjs +178 -0
  61. package/dist/chunk-6PFNJPBJ.mjs +820 -0
  62. package/dist/chunk-6PJWXIFX.mjs +357 -0
  63. package/dist/chunk-6SWKWCMS.js +80 -0
  64. package/dist/chunk-6VVXXX7S.js +808 -0
  65. package/dist/chunk-6WUBSMTX.js +1403 -0
  66. package/dist/chunk-73SGZLAQ.mjs +35 -0
  67. package/dist/chunk-76L2V6KD.mjs +4 -0
  68. package/dist/chunk-7AAIAVAA.js +1531 -0
  69. package/dist/chunk-7ARSJPV3.mjs +93 -0
  70. package/dist/chunk-7BHW5GTC.mjs +1234 -0
  71. package/dist/chunk-7DQSDKDU.js +6 -0
  72. package/dist/chunk-7IQQQENP.mjs +401 -0
  73. package/dist/chunk-7KFTYENS.js +11357 -0
  74. package/dist/chunk-7SM6XSPZ.js +3171 -0
  75. package/dist/chunk-7SXOHAIR.mjs +28 -0
  76. package/dist/chunk-A2MAX6S4.js +90 -0
  77. package/dist/chunk-A33OORT7.mjs +1530 -0
  78. package/dist/{chunk-U6ACF76H.mjs → chunk-A36JRXXH.mjs} +1075 -1845
  79. package/dist/chunk-A7BU3BK4.js +52 -0
  80. package/dist/chunk-A7MQSN2V.mjs +77 -0
  81. package/dist/chunk-A7V4L2IT.mjs +416 -0
  82. package/dist/chunk-AABEK6XU.js +226 -0
  83. package/dist/chunk-AGV33FWC.mjs +5005 -0
  84. package/dist/chunk-AHNR3BXI.js +108 -0
  85. package/dist/chunk-AQ5RLBU2.mjs +286 -0
  86. package/dist/chunk-AQOE6WCG.js +1270 -0
  87. package/dist/chunk-ATAWRACV.mjs +62 -0
  88. package/dist/chunk-ATCURNUV.js +14 -0
  89. package/dist/chunk-AWPV33OO.js +6 -0
  90. package/dist/chunk-AYJPHKYV.js +337 -0
  91. package/dist/chunk-AZ5BGWHB.js +162 -0
  92. package/dist/chunk-AZAXD44P.js +1373 -0
  93. package/dist/chunk-BBGKQIJJ.mjs +406 -0
  94. package/dist/chunk-BP4JLSUA.js +1453 -0
  95. package/dist/{chunk-SUCE7FWA.mjs → chunk-BTUSVHIE.mjs} +539 -978
  96. package/dist/chunk-BU6OK542.mjs +818 -0
  97. package/dist/chunk-CVSRWM6W.js +418 -0
  98. package/dist/chunk-CYBMFMJD.mjs +247 -0
  99. package/dist/chunk-DDJLDOUX.mjs +217 -0
  100. package/dist/{chunk-V32BCG7M.js → chunk-DFZWHNRG.js} +75 -215
  101. package/dist/chunk-DJ2C7AVG.js +644 -0
  102. package/dist/chunk-DS2VU4WW.mjs +102 -0
  103. package/dist/chunk-DSAG7T5P.js +7290 -0
  104. package/dist/chunk-E2QPPH7I.js +327 -0
  105. package/dist/chunk-E65WCTIG.mjs +1187 -0
  106. package/dist/{chunk-33VCYWVL.mjs → chunk-E6QQKDNE.mjs} +30 -42
  107. package/dist/chunk-ECDK6QBF.mjs +981 -0
  108. package/dist/chunk-EIB4OWVQ.mjs +620 -0
  109. package/dist/chunk-EQUZYCGO.js +250 -0
  110. package/dist/chunk-F3UJ6ZRM.mjs +313 -0
  111. package/dist/chunk-F63N2ZTQ.js +7023 -0
  112. package/dist/chunk-F6XRYEM3.mjs +26 -0
  113. package/dist/chunk-FE6VCE4K.js +5030 -0
  114. package/dist/chunk-FLWD6GRR.js +1372 -0
  115. package/dist/chunk-FQBFWJBS.mjs +110 -0
  116. package/dist/chunk-FXVJ2HFU.js +26 -0
  117. package/dist/chunk-FZMQMQBW.js +312 -0
  118. package/dist/chunk-G3EEC44R.js +53 -0
  119. package/dist/{chunk-KG3WT4PR.mjs → chunk-GCKWKLZF.mjs} +73 -104
  120. package/dist/chunk-GCX7TY4D.mjs +6826 -0
  121. package/dist/chunk-GDB6TCSD.js +450 -0
  122. package/dist/chunk-GDCV4IWO.mjs +21 -0
  123. package/dist/chunk-GDZT5LZ5.js +170 -0
  124. package/dist/chunk-GHPUYD4I.mjs +213 -0
  125. package/dist/chunk-GHS6MIL6.mjs +1432 -0
  126. package/dist/chunk-GPS2THCL.mjs +11 -0
  127. package/dist/{chunk-EV2EVOYS.js → chunk-GTJWQAGU.js} +31 -42
  128. package/dist/chunk-GVTI6UJQ.mjs +130 -0
  129. package/dist/chunk-GXKI64OT.mjs +1138 -0
  130. package/dist/chunk-GYDYF2WX.js +275 -0
  131. package/dist/chunk-GYLP6UG4.mjs +705 -0
  132. package/dist/chunk-H3OQKK6X.js +1158 -0
  133. package/dist/chunk-H5DFSCJ6.js +40 -0
  134. package/dist/chunk-HAGEIC2L.mjs +186 -0
  135. package/dist/chunk-HAJ4JRFO.js +293 -0
  136. package/dist/chunk-HDR72GB6.js +188 -0
  137. package/dist/chunk-HF5HPS4T.mjs +40 -0
  138. package/dist/chunk-HK6LOFDS.js +218 -0
  139. package/dist/chunk-HMWYTXCY.mjs +143 -0
  140. package/dist/chunk-HPCSRCMA.js +89 -0
  141. package/dist/chunk-HSEO6TPU.js +247 -0
  142. package/dist/chunk-I5FOHCLH.js +132 -0
  143. package/dist/chunk-IDLW4NWA.mjs +85 -0
  144. package/dist/chunk-IIDZ5WUX.js +61 -0
  145. package/dist/chunk-IR74FJHU.js +2332 -0
  146. package/dist/chunk-IRVFYAKP.mjs +100 -0
  147. package/dist/{chunk-XBL3TMPC.mjs → chunk-IZDWAL53.mjs} +1795 -3287
  148. package/dist/chunk-J2KZXIU3.js +51 -0
  149. package/dist/chunk-J2U6PJSO.js +91 -0
  150. package/dist/chunk-J5AJNY2N.js +283 -0
  151. package/dist/chunk-J6KQZ4FO.mjs +821 -0
  152. package/dist/{chunk-OWW5GUSB.js → chunk-JGBCIKJV.js} +7 -6
  153. package/dist/chunk-JKGTBMU7.mjs +25 -0
  154. package/dist/chunk-JR3TNEQC.js +422 -0
  155. package/dist/chunk-JURRXY2J.mjs +29 -0
  156. package/dist/chunk-K3HW5I2A.mjs +317 -0
  157. package/dist/chunk-K46SMZ66.mjs +103 -0
  158. package/dist/chunk-K4UDGE3Z.mjs +6 -0
  159. package/dist/chunk-KDQOR4QQ.mjs +350 -0
  160. package/dist/chunk-KDTVOLHI.mjs +288 -0
  161. package/dist/chunk-KGHJH5KJ.mjs +35 -0
  162. package/dist/chunk-KIZOA5LX.mjs +140 -0
  163. package/dist/chunk-KK6HYVBI.mjs +242 -0
  164. package/dist/chunk-KMKWGXMK.js +856 -0
  165. package/dist/chunk-KPA6K5IB.js +80 -0
  166. package/dist/chunk-KU7O4IXU.mjs +260 -0
  167. package/dist/chunk-KVFNRJOR.mjs +11142 -0
  168. package/dist/chunk-KZJRSXHK.js +2432 -0
  169. package/dist/chunk-LHWPRUJL.js +79 -0
  170. package/dist/chunk-LIV3KXJG.mjs +369 -0
  171. package/dist/chunk-LKV4LACG.js +21 -0
  172. package/dist/chunk-LUY45X3U.mjs +263 -0
  173. package/dist/chunk-LYEZZEEF.mjs +17 -0
  174. package/dist/chunk-M5EXQZYY.mjs +1519 -0
  175. package/dist/chunk-ME6HGG4I.mjs +1338 -0
  176. package/dist/chunk-MEXP6DA6.js +31 -0
  177. package/dist/chunk-MG52AW3H.js +902 -0
  178. package/dist/chunk-MIPO6F72.js +334 -0
  179. package/dist/{chunk-5QW7CQBA.js → chunk-MKIJQL5Q.js} +211 -321
  180. package/dist/chunk-MN3YETVN.mjs +17 -0
  181. package/dist/chunk-MOBSBXVE.mjs +2391 -0
  182. package/dist/chunk-MOMOZEUM.mjs +88 -0
  183. package/dist/chunk-MRFUNRAP.js +62 -0
  184. package/dist/chunk-MTIHEW2M.js +433 -0
  185. package/dist/chunk-N4RGGDEL.mjs +73 -0
  186. package/dist/chunk-NH654HAT.js +10 -0
  187. package/dist/chunk-NHJUGZUR.mjs +253 -0
  188. package/dist/chunk-NMQT4HG3.mjs +757 -0
  189. package/dist/chunk-NPSYB6DC.mjs +906 -0
  190. package/dist/chunk-NW2GPMSO.js +857 -0
  191. package/dist/chunk-NXKQOQ6L.js +76 -0
  192. package/dist/chunk-NXLAZIJZ.js +309 -0
  193. package/dist/chunk-NYWNA5CF.js +148 -0
  194. package/dist/chunk-NZTKLY2W.js +1442 -0
  195. package/dist/chunk-O2ICABUD.js +36 -0
  196. package/dist/chunk-OIVVQQ22.js +862 -0
  197. package/dist/chunk-OKC2B4O3.mjs +312 -0
  198. package/dist/chunk-OLWFPDBK.js +2220 -0
  199. package/dist/chunk-OMTVH334.js +3779 -0
  200. package/dist/chunk-OQRVEM56.mjs +362 -0
  201. package/dist/chunk-OXMIBOD4.js +337 -0
  202. package/dist/chunk-PBL6YL5L.mjs +288 -0
  203. package/dist/chunk-PDOELNNQ.js +97 -0
  204. package/dist/chunk-PDQJY2GZ.js +136 -0
  205. package/dist/chunk-PKOZXD2Q.js +1274 -0
  206. package/dist/chunk-PPF2BYFL.mjs +2191 -0
  207. package/dist/chunk-PQTQKNKD.js +539 -0
  208. package/dist/chunk-PRSR4FAV.mjs +81 -0
  209. package/dist/chunk-PTRNO5UD.js +95 -0
  210. package/dist/chunk-Q2Y3VMKH.js +2000 -0
  211. package/dist/chunk-QCZOE65N.js +96 -0
  212. package/dist/chunk-QDYFLATW.mjs +52 -0
  213. package/dist/chunk-QQABGCMM.js +22 -0
  214. package/dist/chunk-QS6TRHMR.js +345 -0
  215. package/dist/chunk-R56P64LB.mjs +208 -0
  216. package/dist/chunk-RCQ2MPBV.js +428 -0
  217. package/dist/chunk-RFVRPYR2.mjs +856 -0
  218. package/dist/chunk-RKBLPGPV.js +11521 -0
  219. package/dist/chunk-RM2V4IND.mjs +327 -0
  220. package/dist/chunk-RQXN5A34.mjs +613 -0
  221. package/dist/chunk-RUVGVNOF.mjs +2687 -0
  222. package/dist/chunk-SAFJIGYB.mjs +165 -0
  223. package/dist/chunk-SKQFLBDD.js +263 -0
  224. package/dist/chunk-SMK6JU2F.mjs +2092 -0
  225. package/dist/{chunk-UVRPC2P7.js → chunk-SNNEOS5Z.js} +1984 -3476
  226. package/dist/chunk-SPCRQ6NO.mjs +1246 -0
  227. package/dist/chunk-SWX4SALA.mjs +19 -0
  228. package/dist/{chunk-JVODCGFP.mjs → chunk-SYEO2WV4.mjs} +128 -238
  229. package/dist/chunk-T2QQMX2N.js +10 -0
  230. package/dist/chunk-T3AFF3L7.mjs +57 -0
  231. package/dist/chunk-T6Z2EXYL.js +712 -0
  232. package/dist/chunk-T7LOXGYX.js +118 -0
  233. package/dist/chunk-TJCAE7RC.mjs +1315 -0
  234. package/dist/chunk-TJI3K6RP.js +137 -0
  235. package/dist/chunk-TL2SVO4P.mjs +55 -0
  236. package/dist/chunk-TM63CYGN.mjs +399 -0
  237. package/dist/chunk-TU5RYTYU.mjs +13 -0
  238. package/dist/chunk-TVJZ4GPS.js +1553 -0
  239. package/dist/chunk-TWM6DLYF.js +371 -0
  240. package/dist/chunk-U63OC4TQ.js +30 -0
  241. package/dist/{chunk-L5GKVQVJ.js → chunk-U6BVSJZ6.js} +25 -57
  242. package/dist/chunk-U6UVWEAK.mjs +792 -0
  243. package/dist/chunk-UCEPNO6N.mjs +11048 -0
  244. package/dist/{chunk-ANT574FD.js → chunk-UCR5HRYM.js} +74 -105
  245. package/dist/chunk-UG5BTOTF.mjs +334 -0
  246. package/dist/chunk-UGH37BQW.mjs +157 -0
  247. package/dist/chunk-V7ZRH3PY.mjs +271 -0
  248. package/dist/chunk-VBGHBL3E.mjs +1394 -0
  249. package/dist/chunk-VRBDAS5I.js +920 -0
  250. package/dist/chunk-VVE3Y76O.js +230 -0
  251. package/dist/chunk-W65JIRI4.mjs +1182 -0
  252. package/dist/chunk-WHYKAT7G.js +62 -0
  253. package/dist/{chunk-YOIVZ6OA.mjs → chunk-WIZRUIZB.mjs} +25 -57
  254. package/dist/chunk-WKWTDZS7.js +385 -0
  255. package/dist/chunk-WLMINRC4.mjs +78 -0
  256. package/dist/chunk-WOF3AD3J.js +22 -0
  257. package/dist/chunk-WWKMOA76.js +1262 -0
  258. package/dist/chunk-X5A5FOWW.js +615 -0
  259. package/dist/chunk-X6CN6KQF.mjs +192 -0
  260. package/dist/chunk-XD2PMH46.mjs +517 -0
  261. package/dist/chunk-XJA2NGTI.mjs +88 -0
  262. package/dist/chunk-XJIHN3BY.mjs +8 -0
  263. package/dist/chunk-XK6UDWJS.js +203 -0
  264. package/dist/chunk-XPG3N5CF.mjs +415 -0
  265. package/dist/chunk-XVZ2NKSU.mjs +74 -0
  266. package/dist/chunk-XYP45OLE.js +117 -0
  267. package/dist/chunk-XZSDGZX6.mjs +301 -0
  268. package/dist/chunk-Y2EMGN4T.mjs +120 -0
  269. package/dist/chunk-Y3XWP5XW.mjs +298 -0
  270. package/dist/chunk-Y4K22JL6.js +228 -0
  271. package/dist/chunk-Y65LXQGA.mjs +3164 -0
  272. package/dist/chunk-Y66WVMO5.mjs +87 -0
  273. package/dist/chunk-Y7JWLB25.mjs +7280 -0
  274. package/dist/chunk-YCDXAJKU.js +175 -0
  275. package/dist/chunk-YRDQCCIS.js +152 -0
  276. package/dist/chunk-YV52DGSA.js +111 -0
  277. package/dist/chunk-YXGZQPUD.js +94 -0
  278. package/dist/chunk-Z3A3AFVU.mjs +102 -0
  279. package/dist/chunk-ZCY6YKKP.mjs +475 -0
  280. package/dist/chunk-ZEQHXVU5.js +215 -0
  281. package/dist/chunk-ZF7JCXCI.js +284 -0
  282. package/dist/chunk-ZJBRUH6V.js +29 -0
  283. package/dist/chunk-ZMIL4ZOA.js +365 -0
  284. package/dist/chunk-ZR5ULMN2.mjs +337 -0
  285. package/dist/chunk-ZXREOYOW.js +87 -0
  286. package/dist/{client-BSP9U1O1.d.mts → client-CX_WR0-J.d.mts} +2 -2
  287. package/dist/client-Dytx_ZTC.d.ts +230 -0
  288. package/dist/{client-B878xeAP.d.ts → client-dqOhP9Nc.d.ts} +2 -2
  289. package/dist/client-hTKbCuhG.d.mts +230 -0
  290. package/dist/clock-B-UAjkKa.d.mts +5 -0
  291. package/dist/clock-B-UAjkKa.d.ts +5 -0
  292. package/dist/config-BlXQluJR.d.mts +36 -0
  293. package/dist/config-BlXQluJR.d.ts +36 -0
  294. package/dist/courier-Cnn-edJ4.d.ts +95 -0
  295. package/dist/courier-FmGfkvIN.d.mts +95 -0
  296. package/dist/crowd-DdHFbqKK.d.ts +186 -0
  297. package/dist/crowd-hOVSAmA3.d.mts +186 -0
  298. package/dist/danfo-BEBapFlX.d.mts +146 -0
  299. package/dist/danfo-UQ_PTIIx.d.ts +146 -0
  300. package/dist/{elements-Bty6Qs_N.d.mts → elements-DdsRig-2.d.mts} +1548 -257
  301. package/dist/{elements-Bty6Qs_N.d.ts → elements-DdsRig-2.d.ts} +1548 -257
  302. package/dist/engines/godot.d.mts +56 -0
  303. package/dist/engines/godot.d.ts +56 -0
  304. package/dist/engines/godot.js +28 -0
  305. package/dist/engines/godot.mjs +3 -0
  306. package/dist/engines/wasm.d.mts +11 -0
  307. package/dist/engines/wasm.d.ts +11 -0
  308. package/dist/engines/wasm.js +178 -0
  309. package/dist/engines/wasm.mjs +176 -0
  310. package/dist/fallback-CrG_lTFk.d.mts +270 -0
  311. package/dist/fallback-CrG_lTFk.d.ts +270 -0
  312. package/dist/fallback-KDB4Y2CE.mjs +6 -0
  313. package/dist/fallback-Y26TQENE.js +19 -0
  314. package/dist/features-CZB4rmcD.d.mts +118 -0
  315. package/dist/features-CZB4rmcD.d.ts +118 -0
  316. package/dist/fit-BWiE7rgA.d.mts +44 -0
  317. package/dist/fit-DK0oT7zO.d.ts +44 -0
  318. package/dist/five-a-side-Bv1AOUy3.d.mts +115 -0
  319. package/dist/five-a-side-EC51SJY1.d.ts +115 -0
  320. package/dist/fluid-ARr0qUIL.d.ts +939 -0
  321. package/dist/fluid-DLlEj2cs.d.mts +939 -0
  322. package/dist/game/conformance.d.mts +84 -0
  323. package/dist/game/conformance.d.ts +84 -0
  324. package/dist/game/conformance.js +1025 -0
  325. package/dist/game/conformance.mjs +994 -0
  326. package/dist/game/heap.d.mts +40 -0
  327. package/dist/game/heap.d.ts +40 -0
  328. package/dist/game/heap.js +48 -0
  329. package/dist/game/heap.mjs +7 -0
  330. package/dist/game/kit/canvas.d.mts +240 -0
  331. package/dist/game/kit/canvas.d.ts +240 -0
  332. package/dist/game/kit/canvas.js +3566 -0
  333. package/dist/game/kit/canvas.mjs +1039 -0
  334. package/dist/game/kit/courier.d.mts +17 -0
  335. package/dist/game/kit/courier.d.ts +17 -0
  336. package/dist/game/kit/courier.js +66 -0
  337. package/dist/game/kit/courier.mjs +49 -0
  338. package/dist/game/kit/danfo.d.mts +11 -0
  339. package/dist/game/kit/danfo.d.ts +11 -0
  340. package/dist/game/kit/danfo.js +109 -0
  341. package/dist/game/kit/danfo.mjs +44 -0
  342. package/dist/game/kit/engine.d.mts +29 -0
  343. package/dist/game/kit/engine.d.ts +29 -0
  344. package/dist/game/kit/engine.js +183 -0
  345. package/dist/game/kit/engine.mjs +30 -0
  346. package/dist/game/kit/five-a-side.d.mts +11 -0
  347. package/dist/game/kit/five-a-side.d.ts +11 -0
  348. package/dist/game/kit/five-a-side.js +86 -0
  349. package/dist/game/kit/five-a-side.mjs +41 -0
  350. package/dist/game/kit/frontier.d.mts +344 -0
  351. package/dist/game/kit/frontier.d.ts +344 -0
  352. package/dist/game/kit/frontier.js +435 -0
  353. package/dist/game/kit/frontier.mjs +14 -0
  354. package/dist/game/kit/genesis.d.mts +752 -0
  355. package/dist/game/kit/genesis.d.ts +752 -0
  356. package/dist/game/kit/genesis.js +380 -0
  357. package/dist/game/kit/genesis.mjs +15 -0
  358. package/dist/game/kit/ludo.d.mts +15 -0
  359. package/dist/game/kit/ludo.d.ts +15 -0
  360. package/dist/game/kit/ludo.js +87 -0
  361. package/dist/game/kit/ludo.mjs +42 -0
  362. package/dist/game/kit/runner.d.mts +12 -0
  363. package/dist/game/kit/runner.d.ts +12 -0
  364. package/dist/game/kit/runner.js +83 -0
  365. package/dist/game/kit/runner.mjs +46 -0
  366. package/dist/game/kit/shootout.d.mts +13 -0
  367. package/dist/game/kit/shootout.d.ts +13 -0
  368. package/dist/game/kit/shootout.js +122 -0
  369. package/dist/game/kit/shootout.mjs +57 -0
  370. package/dist/game/kit/slots.d.mts +392 -0
  371. package/dist/game/kit/slots.d.ts +392 -0
  372. package/dist/game/kit/slots.js +215 -0
  373. package/dist/game/kit/slots.mjs +6 -0
  374. package/dist/game/kit/tycoon.d.mts +16 -0
  375. package/dist/game/kit/tycoon.d.ts +16 -0
  376. package/dist/game/kit/tycoon.js +145 -0
  377. package/dist/game/kit/tycoon.mjs +44 -0
  378. package/dist/game/kit/word.d.mts +11 -0
  379. package/dist/game/kit/word.d.ts +11 -0
  380. package/dist/game/kit/word.js +78 -0
  381. package/dist/game/kit/word.mjs +41 -0
  382. package/dist/game/kit/worlds.d.mts +18 -0
  383. package/dist/game/kit/worlds.d.ts +18 -0
  384. package/dist/game/kit/worlds.js +74 -0
  385. package/dist/game/kit/worlds.mjs +49 -0
  386. package/dist/game/kit.d.mts +53 -0
  387. package/dist/game/kit.d.ts +53 -0
  388. package/dist/game/kit.js +2610 -0
  389. package/dist/game/kit.mjs +101 -0
  390. package/dist/game/prepared.d.mts +14 -0
  391. package/dist/game/prepared.d.ts +14 -0
  392. package/dist/game/prepared.js +81 -0
  393. package/dist/game/prepared.mjs +32 -0
  394. package/dist/game-Bx8onkhX.d.mts +1451 -0
  395. package/dist/game-fgQy2YIm.d.ts +1451 -0
  396. package/dist/game-theme-CBTw1b_d.d.mts +35 -0
  397. package/dist/game-theme-Dg-ict5A.d.ts +35 -0
  398. package/dist/game.d.mts +3546 -0
  399. package/dist/game.d.ts +3546 -0
  400. package/dist/game.js +4455 -0
  401. package/dist/game.mjs +50 -0
  402. package/dist/graphics-C6YjWYvP.d.ts +5 -0
  403. package/dist/graphics-Dk2yQnYN.d.mts +5 -0
  404. package/dist/guest-DrsA00XD.d.mts +732 -0
  405. package/dist/guest-wIdfoT05.d.ts +732 -0
  406. package/dist/hit-stop-BKkVwTq7.d.mts +43 -0
  407. package/dist/hit-stop-D-8pPYnM.d.ts +43 -0
  408. package/dist/hot-Crn9XpHJ.d.ts +29 -0
  409. package/dist/hot-DH3nOhQD.d.mts +29 -0
  410. package/dist/{index-CQStGb3B.d.mts → index-6gkHMGAq.d.mts} +2 -2
  411. package/dist/index-B8ybCKJI.d.ts +41 -0
  412. package/dist/{index-DJwXmoaP.d.ts → index-B98Xac8e.d.ts} +2 -2
  413. package/dist/{index-B7oA_1XI.d.ts → index-B_ByTtIT.d.ts} +2 -2
  414. package/dist/index-DHjNHb1c.d.mts +41 -0
  415. package/dist/{index-DhUSTAhT.d.mts → index-DbAN_VQE.d.mts} +2 -2
  416. package/dist/index.d.mts +134 -24
  417. package/dist/index.d.ts +134 -24
  418. package/dist/index.js +407 -248
  419. package/dist/index.mjs +184 -58
  420. package/dist/interactives-authoring.d.mts +231 -0
  421. package/dist/interactives-authoring.d.ts +231 -0
  422. package/dist/interactives-authoring.js +1743 -0
  423. package/dist/interactives-authoring.mjs +1704 -0
  424. package/dist/interactives-canvas.global.js +148 -0
  425. package/dist/interactives-guest.d.mts +20 -0
  426. package/dist/interactives-guest.d.ts +20 -0
  427. package/dist/interactives-guest.js +63 -0
  428. package/dist/interactives-guest.json +1 -0
  429. package/dist/interactives-guest.mjs +61 -0
  430. package/dist/interactives-jsc.global.js +9357 -0
  431. package/dist/interactives-meters.d.mts +93 -0
  432. package/dist/interactives-meters.d.ts +93 -0
  433. package/dist/interactives-meters.js +252 -0
  434. package/dist/interactives-meters.mjs +68 -0
  435. package/dist/interactives-production.d.mts +430 -0
  436. package/dist/interactives-production.d.ts +430 -0
  437. package/dist/interactives-production.js +1231 -0
  438. package/dist/interactives-production.mjs +1170 -0
  439. package/dist/interactives-record.d.mts +112 -0
  440. package/dist/interactives-record.d.ts +112 -0
  441. package/dist/interactives-record.js +302 -0
  442. package/dist/interactives-record.mjs +295 -0
  443. package/dist/interactives-runtime.d.mts +61 -0
  444. package/dist/interactives-runtime.d.ts +61 -0
  445. package/dist/interactives-runtime.js +442 -0
  446. package/dist/interactives-runtime.mjs +25 -0
  447. package/dist/interactives-studio-kernel.global.js +1 -0
  448. package/dist/interactives-studio.d.mts +806 -0
  449. package/dist/interactives-studio.d.ts +806 -0
  450. package/dist/interactives-studio.js +5741 -0
  451. package/dist/interactives-studio.mjs +5651 -0
  452. package/dist/interactives-tick.d.mts +90 -0
  453. package/dist/interactives-tick.d.ts +90 -0
  454. package/dist/interactives-tick.js +203 -0
  455. package/dist/interactives-tick.mjs +6 -0
  456. package/dist/interactives-web.d.mts +762 -0
  457. package/dist/interactives-web.d.ts +762 -0
  458. package/dist/interactives-web.js +5000 -0
  459. package/dist/interactives-web.mjs +4628 -0
  460. package/dist/interactives.d.mts +2430 -0
  461. package/dist/interactives.d.ts +2430 -0
  462. package/dist/interactives.js +5723 -0
  463. package/dist/interactives.mjs +4333 -0
  464. package/dist/juice-CoHxlpKA.d.ts +42 -0
  465. package/dist/juice-DQztFS43.d.mts +42 -0
  466. package/dist/launch-T2f4_Di4.d.mts +151 -0
  467. package/dist/launch-d6oreMzR.d.ts +151 -0
  468. package/dist/library-DXYaMFhi.d.mts +69 -0
  469. package/dist/library-DXYaMFhi.d.ts +69 -0
  470. package/dist/link-BUTqGmyi.d.mts +38 -0
  471. package/dist/link-BUTqGmyi.d.ts +38 -0
  472. package/dist/lint.js +104 -204
  473. package/dist/lint.mjs +103 -203
  474. package/dist/local-D8_I6UeL.d.mts +6967 -0
  475. package/dist/local-VZkqsCzR.d.ts +6967 -0
  476. package/dist/lockstep-BLf6dglI.d.mts +321 -0
  477. package/dist/lockstep-D50Ia0JW.d.ts +321 -0
  478. package/dist/ludo-B8ClkDqr.d.ts +205 -0
  479. package/dist/ludo-BOuohQ-M.d.mts +205 -0
  480. package/dist/mock/cli.mjs +200 -56
  481. package/dist/mock/library.js +200 -56
  482. package/dist/mock/library.mjs +200 -56
  483. package/dist/mock/msw.js +200 -56
  484. package/dist/mock/msw.mjs +200 -56
  485. package/dist/native-BodxSh03.d.mts +16 -0
  486. package/dist/native-DUHMT8gA.d.ts +16 -0
  487. package/dist/network-ZXLD7l1b.d.mts +19 -0
  488. package/dist/network-ZXLD7l1b.d.ts +19 -0
  489. package/dist/online-XeymeM9s.d.ts +381 -0
  490. package/dist/online-d7W_Al9a.d.mts +381 -0
  491. package/dist/params-DxFb5G_U.d.mts +155 -0
  492. package/dist/params-DxFb5G_U.d.ts +155 -0
  493. package/dist/play-BRRlfLhX.d.ts +940 -0
  494. package/dist/play-ClrMd_e8.d.mts +940 -0
  495. package/dist/policy-CCw8tXLm.d.mts +3078 -0
  496. package/dist/policy-CMqOSQIu.d.ts +3078 -0
  497. package/dist/ports-B_0v_P3A.d.mts +13 -0
  498. package/dist/ports-CGU_3e_0.d.ts +13 -0
  499. package/dist/prefetch-BHnicOQj.d.ts +117 -0
  500. package/dist/prefetch-CBXgYacv.d.mts +117 -0
  501. package/dist/{price-CSztR02F.d.mts → price-BOzexBww.d.mts} +1 -1
  502. package/dist/{price-C_vasx9A.d.ts → price-C1h9sPxE.d.ts} +1 -1
  503. package/dist/protocol-C8qbpUbT.d.mts +242 -0
  504. package/dist/protocol-C8qbpUbT.d.ts +242 -0
  505. package/dist/rapier-AZHT4YI7.js +7886 -0
  506. package/dist/rapier-ODEPCQA6.mjs +7792 -0
  507. package/dist/react.d.mts +157 -15
  508. package/dist/react.d.ts +157 -15
  509. package/dist/react.js +5564 -5904
  510. package/dist/react.mjs +5451 -5808
  511. package/dist/runner-CQcLL7By.d.ts +189 -0
  512. package/dist/runner-D46Yj-wE.d.mts +189 -0
  513. package/dist/runtime-BRWfkf_q.d.mts +51 -0
  514. package/dist/runtime-DyuBMkKM.d.ts +51 -0
  515. package/dist/scheduling-D2ajXpMC.d.ts +224 -0
  516. package/dist/scheduling-DSRbbaZb.d.mts +224 -0
  517. package/dist/schema-BrWxzKp6.d.mts +63 -0
  518. package/dist/schema-BrWxzKp6.d.ts +63 -0
  519. package/dist/server/evict.js +34 -37
  520. package/dist/server/evict.mjs +34 -37
  521. package/dist/server/tanstack.d.mts +49 -3
  522. package/dist/server/tanstack.d.ts +49 -3
  523. package/dist/server/tanstack.js +169 -117
  524. package/dist/server/tanstack.mjs +166 -118
  525. package/dist/{server-Dckg4Vdr.d.ts → server-D29IIuDV.d.ts} +136 -130
  526. package/dist/{server-B6dW7-Lj.d.mts → server-DQMWPnc8.d.mts} +136 -130
  527. package/dist/server.d.mts +45 -5
  528. package/dist/server.d.ts +45 -5
  529. package/dist/server.js +171 -227
  530. package/dist/server.mjs +165 -225
  531. package/dist/session-grant-CJ27DwrT.d.mts +19 -0
  532. package/dist/session-grant-CJ27DwrT.d.ts +19 -0
  533. package/dist/shootout-BJZeX6FG.d.ts +140 -0
  534. package/dist/shootout-tcZd1Rxt.d.mts +140 -0
  535. package/dist/state-replica-stMtdkVD.d.mts +42 -0
  536. package/dist/state-replica-stMtdkVD.d.ts +42 -0
  537. package/dist/studio-CowqWqez.d.mts +14 -0
  538. package/dist/studio-CowqWqez.d.ts +14 -0
  539. package/dist/styles.css +1 -1
  540. package/dist/template-AhCdB1kW.d.mts +190 -0
  541. package/dist/template-BkEGVTQj.d.ts +190 -0
  542. package/dist/terrain-BMxEc6Oc.d.ts +429 -0
  543. package/dist/terrain-C-XC1Oui.d.mts +429 -0
  544. package/dist/testing/msw.d.mts +28 -4
  545. package/dist/testing/msw.d.ts +28 -4
  546. package/dist/testing/msw.js +15 -21
  547. package/dist/testing/msw.mjs +15 -21
  548. package/dist/testing/suite.d.mts +6 -5
  549. package/dist/testing/suite.d.ts +6 -5
  550. package/dist/testing/suite.js +89 -124
  551. package/dist/testing/suite.mjs +81 -116
  552. package/dist/testing.d.mts +27 -1227
  553. package/dist/testing.d.ts +27 -1227
  554. package/dist/testing.js +127 -131
  555. package/dist/testing.mjs +19 -23
  556. package/dist/tick-transport-C8QEh8Uw.d.mts +50 -0
  557. package/dist/tick-transport-UjHY3xK1.d.ts +50 -0
  558. package/dist/timeline-protocol-hp6e8zFB.d.mts +47 -0
  559. package/dist/timeline-protocol-hp6e8zFB.d.ts +47 -0
  560. package/dist/tokens-DhanQRQS.d.mts +21 -0
  561. package/dist/tokens-K8yxwd6G.d.ts +21 -0
  562. package/dist/tree-C-Io2Hbx.d.mts +35 -0
  563. package/dist/tree-CP_qSW4H.d.ts +35 -0
  564. package/dist/tycoon-B5KHk2Xx.d.mts +255 -0
  565. package/dist/tycoon-hmHo-3HX.d.ts +255 -0
  566. package/dist/types-BQkxPwZP.d.mts +219 -0
  567. package/dist/types-D_f6UUxM.d.ts +219 -0
  568. package/dist/ui-DwHicuFv.d.mts +563 -0
  569. package/dist/ui-hi7S2YcH.d.ts +563 -0
  570. package/dist/{sign-in-DQlIdqsi.d.mts → url-52ndUruG.d.mts} +15 -1
  571. package/dist/{sign-in-DQlIdqsi.d.ts → url-52ndUruG.d.ts} +15 -1
  572. package/dist/utils.d.mts +3 -3
  573. package/dist/utils.d.ts +3 -3
  574. package/dist/utils.js +37 -37
  575. package/dist/utils.mjs +4 -4
  576. package/dist/vars-Dc_PrhBK.d.mts +511 -0
  577. package/dist/vars-Dc_PrhBK.d.ts +511 -0
  578. package/dist/vm-IUARFFAI.mjs +63 -0
  579. package/dist/vm-N7L6MGGH.js +65 -0
  580. package/dist/weave-delivery-CW-Kstut.d.mts +360 -0
  581. package/dist/weave-delivery-CW-Kstut.d.ts +360 -0
  582. package/dist/web-Dss74a7v.d.ts +883 -0
  583. package/dist/web-f9ZQPoyw.d.mts +883 -0
  584. package/dist/web-transport-C7MkBL0a.d.ts +19 -0
  585. package/dist/web-transport-aYEqXMd9.d.mts +19 -0
  586. package/dist/weight-CPGjsgjV.d.ts +92 -0
  587. package/dist/weight-tF1ODR1p.d.mts +92 -0
  588. package/dist/word-BcX9Jcmv.d.mts +70 -0
  589. package/dist/word-C7sVPLHm.d.ts +70 -0
  590. package/dist/world-PvILHDR1.d.ts +2285 -0
  591. package/dist/world-qekkXjJv.d.mts +2285 -0
  592. package/dist/worlds-Br2Pb0Cs.d.ts +109 -0
  593. package/dist/worlds-D5ydYr7d.d.mts +109 -0
  594. package/engines/c/cimplify.h +108 -0
  595. package/engines/c/cimplify.lib.js +11 -0
  596. package/engines/godot/addons/cimplify/cimplify.gd +97 -0
  597. package/engines/rust/interactives-ctx/Cargo.toml +9 -0
  598. package/engines/rust/interactives-ctx/src/lib.rs +189 -0
  599. package/package.json +189 -3
  600. package/vendor/rapier3d-compat/LICENSE +201 -0
  601. package/vendor/rapier3d-compat/PATCHES.md +61 -0
  602. package/dist/chunk-2P4KXFB6.js +0 -274
  603. package/dist/chunk-3G6RQLXK.mjs +0 -21
  604. package/dist/chunk-3V4DVXV3.mjs +0 -254
  605. package/dist/chunk-EDK3LNM6.js +0 -2436
  606. package/dist/chunk-F7J3HK27.js +0 -4549
  607. package/dist/chunk-U4MW6PYU.mjs +0 -23
  608. package/dist/chunk-XREIZ56K.js +0 -26
@@ -0,0 +1,148 @@
1
+ (function(){'use strict';var Pp=(i,e)=>()=>(i&&(e=i(i=0)),e);function s6(i){return {clock_time_get(e,t,n){return new DataView(i().buffer).setBigUint64(n,0n,true),0},fd_close:()=>8,fd_seek:()=>8,fd_write:()=>8}}function a6(i){return WebAssembly.Module.imports(i).some(e=>e.module===mI)}function l6(i){let e=i[vfe];typeof e=="function"&&e();}var mI,vfe,c6=Pp(()=>{mI="wasi_snapshot_preview1",vfe="_initialize";});function N6(i,e){let t=new DataView(i.buffer,i.byteOffset,UA);i[0]=ee.session_complete,i[Zfe]=Jfe[e.outcome],i[e_e]=e.score===null?n_e:t_e;let n=e.score===null?0:Math.trunc(e.score),r=Math.floor(n/x6);return t.setUint32(E6,n-r*x6,true),t.setInt32(E6+r_e,r,true),UA}function Ti(i){return JSON.parse(s_e.decode(i.subarray(Ae)))}function wi(i){let e="";for(let t=0;t<i.length;t++)e+=(i[t]<16?"0":"")+i[t].toString(16);return e}function w6(i){return i>=v6&&i<=a_e?i-v6:i>=R6&&i<=l_e?i-R6+T6:i>=S6&&i<=c_e?i-S6+T6:-1}function L6(i,e,t,n){if(i.length!==n*2||t+n>e.length)return false;for(let r=0;r<n;r++){let o=w6(i.charCodeAt(r*2)),s=w6(i.charCodeAt(r*2+1));if(o<0||s<0)return false;e[t+r]=o<<u_e|s;}return true}function bI(i,e,t){let n="";for(let r=e;r<e+t;r++)n+=(i[r]<16?"0":"")+i[r].toString(16);return n}function F6(i){return i.length<h_e||i[0]!==ee.chunk_failed?null:{digest:bI(i,Ae,Ft),reason:d_e[i[Ae+Ft]]??"unknown"}}function U6(i,e){if(i.length!==e.length*2)return false;for(let t=0;t<e.length;t++){let n=Number.parseInt(i.slice(t*2,t*2+2),16);if(Number.isNaN(n))return false;e[t]=n;}return true}var GA,VA,I6,ee,O6,C6,yI,Jfe,UA,Zfe,e_e,E6,t_e,n_e,x6,r_e,Ft,AI,k6,Ae,i_e,fs,o_e,s_e,BA,v6,a_e,R6,l_e,S6,c_e,T6,u_e,M6,Je,d_e,_I,D6,P6,h_e,p_e,m_e,f_e,Yp,yn=Pp(()=>{GA="@cimplify/engine-core",VA="@cimplify/engine-core-threads",I6="/wasm",ee={hello:1,close:2,consent:3,confirm:4,ai_local:5,ai_local_result:6,request:16,response:17,event:18,frames:19,boot:32,chunk:33,start:34,lifecycle:35,ui_event:36,ui_reply:37,ping:38,room_dialed:39,room_frames:40,room_closed:41,stage:42,warm:43,chunk_ref:44,stage_ref:45,room_batch:46,room_backpressure:47,ready:48,render:49,ui_command:50,pong:51,fault:52,started:53,disposed:54,room_dial:55,room_send:56,room_close:57,milestone:58,warmed:59,chunk_request:60,game_ui:61,game_ui_event:62,session_complete:63,chunk_release:64,chunk_failed:65,network:66,camera_open:67,camera_opened:68,camera_close:69,camera_track:70,camera_untrack:71,camera_face:72,camera_colours:73,camera_coloured:74,inspector:75,frame_mark:76,frame_step:77,font_request:78,font_reply:79,hot:80,hot_done:81,meters:82,meter_report:83,studio:84,studio_report:85,clip_arm:86,clip_pause:87,clip_save:88,clip_saved:89,replay:90,camera_place:91,camera_identify:92,camera_identified:93},new TextEncoder,new TextDecoder,O6=[null,"visible","hidden","suspend","resume","revision_update","dispose"],C6={linked:1,main_entered:2,attach_requested:3,attach_resolved:4,first_frame_scheduled:5,ready_for_input:6},yI=2,Jfe={won:1,lost:2,draw:3,finished:4},UA=11,Zfe=1,e_e=2,E6=3,t_e=1,n_e=0,x6=4294967296,r_e=4;Ft=32,AI=13,k6=1,Ae=1,i_e=3,fs={max_message_bytes:4*1024*1024,max_render_bytes:512*1024,max_tree_nodes:2048,max_tree_depth:64,frame_outbox_bytes:16*1024},o_e=new TextEncoder,s_e=new TextDecoder,BA=class{constructor(e=4096){this.buffer=new Uint8Array(e);}get bytes(){return this.buffer}json(e,t){return this.text(e,JSON.stringify(t))}text(e,t){for(;;){let n=o_e.encodeInto(t,this.buffer.subarray(Ae));if(n.read===t.length)return this.buffer[0]=e,Ae+n.written;this.buffer=new Uint8Array(Math.max(this.buffer.length*2,Ae+t.length*i_e));}}tag(e){return this.buffer[0]=e,Ae}};v6=48,a_e=57,R6=97,l_e=102,S6=65,c_e=70,T6=10,u_e=4;M6=1,Je={now:0,soon:1,prefetch:2},d_e=["unknown","budget","network","verify"],_I=2,D6=Ft+1,P6=Ft,h_e=Ae+Ft+1,p_e=256,m_e=8,f_e=255,Yp=class{constructor(e,t,n=p_e){this.tag=e;this.entryBytes=t;this.capacity=n;this.count=0;this.bytes=new Uint8Array(Ae+_I+n*t);}get size(){return this.count}get full(){return this.count>=this.capacity}add(e,t=Je.now){if(this.full)return false;let n=Ae+_I+this.count*this.entryBytes;return L6(e,this.bytes,n,Ft)?(this.entryBytes>Ft&&(this.bytes[n+Ft]=t),this.count++,true):false}seal(){let e=this.count;return this.bytes[0]=this.tag,this.bytes[Ae]=e&f_e,this.bytes[Ae+1]=e>>m_e,this.count=0,Ae+_I+e*this.entryBytes}};});function tX(){return cd!==null&&!dC}async function hC(i){if(cd===null||dC)throw new Im("compile");let e=await cd.compile(i);return eX.add(e),e}async function Om(i){if(cd===null||dC)throw new Im("compile");let e=await i;if(!(e instanceof cd.Module))throw new Im("compile");return eX.add(e),e}async function pC(i,e){let t=await hC(i);return cd.instantiate(t,e)}var cd,eX,Im,dC,Cm=Pp(()=>{cd=typeof WebAssembly>"u"?null:WebAssembly,eX=new WeakSet,Im=class extends Error{constructor(e){super(`WebAssembly.${e} is not available to Interactives; only the platform's runtime modules instantiate`),this.name="GuardError";}},dC=false;});function DU(i){if(i.length<CU)throw new vt("a chunk is shorter than its header");let e=new DataView(i.buffer,i.byteOffset,CU);if(e.getUint32(xJe,true)!==pJe)throw new vt("not a Cimplify chunk");if(e.getUint16(vJe,true)!==mJe)throw new vt("unsupported chunk format");let t=e.getUint32(rhe+4,true)*TJe+e.getUint32(rhe,true),n=e.getUint32(SJe,true);if(n<CU||t>i.length-n)throw new vt("a chunk payload is truncated");return {kind:e.getUint8(RJe),payload:i.subarray(n,n+t)}}function wJe(i){let e=i.names;if(!Array.isArray(e))throw new vt("the module index has no name table");let t=o=>{if(o===yJe)return null;let s=o===void 0?void 0:e[o];if(typeof s!="string")throw new vt("the module index names an import it does not list");return s},n=o=>o.map(s=>{if(s.length===AJe){let u=t(s[1]);if(u===null)throw new vt("the module index holds a malformed import");return {at:s[0],end:s[0]+u.length,module:null,library:u,export:u,specifier:u}}if(s.length!==bJe&&s.length!==the&&s.length!==nhe)throw new vt("the module index holds a malformed import");let a=t(s[3]),l=s.length===the||s[4]===gJe?a:t(s[4]),c=s.length===nhe?t(s[5]):null;return {at:s[0],end:s[1],module:t(s[2]),library:a,export:l,...c===null?{}:{specifier:c}}}),r=i.assets?.map(o=>{let s=new Set(o.lazy_parts??[]),a={path:o.path,chunk:o.chunk,...o.lazy===true?{lazy:true}:{},...o.progressive===true?{progressive:true}:{}};return o.parts===void 0?a:{...a,parts:o.parts.map((l,c)=>s.has(c)?{chunk:l,lazy:true}:{chunk:l})}});return {format:i.format,entries:i.entries,modules:i.modules.map(o=>({...o,imports:n(o.imports)})),runtimes:i.runtimes.map(o=>({...o,imports:n(o.imports)})),...r===void 0?{}:{assets:r},...i.alternatives===void 0?{}:{alternatives:i.alternatives},...i.late===void 0?{}:{late:i.late},...i.more===void 0?{}:{more:i.more}}}function NU(i){if(i.kind!==Jr.index)throw new vt("the package's first chunk is not its module index");let e=JSON.parse(kU.decode(i.payload));if(e.format===fJe)return wJe(e);if(e.format===_Je)return e;throw new vt(`module index format ${e.format} is not supported`)}function CJe(i,e){return e.map(t=>{if(t.specifier===void 0)throw new vt(`module ${i} has no source and its index does not name its imports`);return {specifier:t.specifier,module:t.module,library:t.library,export:t.export}})}function she(i,e,t){return t.map(n=>{if(n.at<0||n.end>e.length||n.end<n.at)throw new vt(`${i} has an import outside its code`);let r=e.slice(n.at,n.end);if(n.specifier!==void 0&&n.specifier!==r)throw new vt(`${i} names an import its code does not hold`);return {specifier:r,module:n.module,library:n.library,export:n.export}})}function ahe(i){return i.runtimes.map(e=>`${e.unit}=${e.chunk}`).join(",")}function NJe(i,e,t){let n=new Map;for(let a of i)n.set(a.path,a);let r=new Map,o=[],s=(a,l)=>{let c=r.get(a);if(c===2)return;if(c===1)throw new vt(`modules import each other in a cycle through ${a}`);let u=n.get(a);if(u===void 0)throw new vt(`${l??"the entry"} imports ${a}, which is not in the package`);r.set(a,1);for(let d of u.imports)if(d.module!==null)s(d.module,a);else if(d.library===null||d.export===null||!t.has(d.library))throw new vt(`${a} imports library ${d.library??d.specifier}, which this host does not provide`);r.set(a,2),o.push(u);};return s(e,null),o}function lhe(i,e=null){let t=null,n=async(r,o,s,a,l)=>{let c=NJe(s,a,r.names),u=o(),d=new Map;for(let f of c)d.set(f.path,f);let h=new Map;if(i.ahead){let f=await Promise.all(c.map(y=>i.compile(y.path,y.code)));for(let y=0;y<c.length;y++)h.set(c[y].path,f[y]);}await u;let p=new Map,m=f=>{let y=p.get(f);if(y!==void 0)return y.exports;let b=d.get(f),A=h.get(f);A===void 0&&(A=i.compile(f,b.code),h.set(f,A));let E=new Map;for(let v of b.imports)E.set(v.specifier,v);let R=v=>{let x=E.get(v);if(x===void 0)throw new vt(`${f} may not require ${v}`);return x.module!==null?m(x.module):r.resolve(x)},g={exports:{}};return p.set(f,g),A(R,g.exports,g,l),g.exports};return m(a)};return {link(r,o,s,a=[]){let l=new MU(i,s,a,e);return t=l,n(l,()=>l.prepare(),r,o,s)},relink(r,o,s){return t===null?Promise.reject(new vt("nothing has been linked to swap")):n(t,()=>Promise.resolve(),r,o,s)}}}function kJe(i){return `export default function (${EJe.join(", ")}) {
2
+ ${i}
3
+ }
4
+ `}function uhe(i){let e=new Map;return {ahead:i.ahead,prepare(t){if(e.has(t))return;let n=Promise.resolve(i.compile(LU,t));n.catch(()=>e.delete(t)),e.set(t,n);},compile(t,n){return e.get(n)??i.compile(t,n)}}}function dhe(i,e){return {ahead:true,async compile(t,n){let r=i.create(kJe(n));try{return (await e(r)).default}finally{i.revoke(r);}}}}var pJe,mJe,CU,fJe,_Je,yJe,AJe,the,bJe,nhe,gJe,EJe,Jr,xJe,vJe,RJe,rhe,SJe,TJe,vt,dA,ihe,ohe,kU,IJe,OJe,Tw,LU,MU,che,PU=Pp(()=>{Cm();yn();pJe=1262701891,mJe=1,CU=64,fJe=4,_Je=3,yJe=-1,AJe=2,the=4,bJe=5,nhe=6,gJe=-2,EJe=["require","exports","module","__cimplify_tick"],Jr={code:0,texture:1,mesh:2,audio:3,font:4,data:5,wasm:6,index:7,bytecode:8},xJe=0,vJe=4,RJe=6,rhe=8,SJe=16,TJe=4294967296,vt=class extends Error{constructor(e){super(e),this.name="PackageError";}};dA=[],ihe=[],ohe=[],kU=new TextDecoder;IJe=new Set,OJe="";Tw=class{constructor(e=null,t=null,n=null){this.onWasm=e;this.native=t;this.assets=n;this.index=null;this.moreCatalogued=false;this.nextIndexes=new Map;this.code=new Map;this.wasm=new Map;}accept(e,t){let n=DU(t);if(this.index===null){this.index=NU(n),this.assets?.catalog(this.index.assets??dA),this.index.more!==void 0&&this.assets?.awaitCatalog?.();for(let[r,o]of this.wasm)this.announce(r,o);return}if(n.kind===Jr.index){let r=wi(e);if(this.index.more===void 0||r!==this.index.more){this.nextIndexes.set(r,{kind:n.kind,payload:n.payload.slice()});return}if(this.moreCatalogued)return;this.moreCatalogued=true,this.assets?.catalog(NU(n).assets??dA),this.assets?.catalogued?.();return}switch(n.kind){case Jr.code:this.code.set(wi(e),kU.decode(n.payload));return;case Jr.wasm:this.acceptWasm(wi(e),n.payload.slice());return;case Jr.texture:case Jr.mesh:case Jr.audio:case Jr.font:case Jr.data:this.assets?.accept(wi(e),n.payload);return}}swapIndex(e){for(let t of e){let n=this.nextIndexes.get(t);if(n===void 0)continue;let r=NU(n),o=this.index;if(o===null||r.entries.client!==o.entries.client||ahe(r)!==ahe(o))return null;let s=new Map;for(let l of o.assets??dA)s.set(l.path,l.chunk);let a=[];for(let l of r.assets??dA)s.get(l.path)!==l.chunk&&a.push(l.path);return this.index=r,this.nextIndexes.clear(),a.length>0&&this.assets?.catalog(r.assets??dA),a}return null}stageCode(e,t){let n=kU.decode(t);return this.code.set(e,n),n}stage(e,t){let n=t.slice();return this.wasm.set(e,n),n}lateRuntime(e){for(let t of this.index?.late??ohe)if(t.unit===e)return t.chunk;return null}holdsWasm(e){return this.wasm.has(e)}acceptWasmPayload(e,t){this.acceptWasm(e,t);}acceptWasm(e,t){this.wasm.set(e,t),this.announce(e,t);}announce(e,t){if(this.onWasm===null||this.index===null)return;let n=this.index.runtimes;for(let s=0;s<n.length;s++)n[s].chunk===e&&this.onWasm(n[s].unit,t,e);let r=this.index.alternatives??ihe;for(let s=0;s<r.length;s++)r[s].chunk===e&&this.onWasm(r[s].unit,t,e);let o=this.index.late??ohe;for(let s=0;s<o.length;s++)o[s].chunk===e&&this.onWasm(o[s].unit,t,e);}standIn(e){for(let t of this.index?.alternatives??ihe){if(t.replaces!==e)continue;let n=this.wasm.get(t.chunk);if(n!==void 0)return n}}modules(e=IJe){let t=this.index;if(t===null)throw new vt("the package has no module index");let n=[];for(let o of t.modules){let s=this.code.get(o.chunk);if(s!==void 0){n.push({path:o.path,code:s,imports:she(o.path,s,o.imports)});continue}if(!e.has(o.path))throw new vt(`module ${o.path} did not arrive`);n.push({path:o.path,code:OJe,imports:CJe(o.path,o.imports)});}let r=[];for(let o of t.runtimes)r.push(this.runtime(o));return {entry:t.entries.client,modules:n,runtimes:r}}runtime(e){if(e.kind==="wasm"){let n=this.native?.(e.unit);if(n!==void 0)return {unit:e.unit,kind:"native",value:n};let r=this.wasm.get(e.chunk)??this.standIn(e.unit);if(r===void 0)throw new vt(`runtime ${e.unit} did not arrive`);return {unit:e.unit,kind:"wasm",bytes:r}}let t=this.code.get(e.chunk);if(t===void 0)throw new vt(`runtime ${e.unit} did not arrive`);return {unit:e.unit,kind:"code",code:t,imports:she(e.unit,t,e.imports)}}};LU="runtime:",MU=class{constructor(e,t,n,r){this.compiler=e;this.tick=t;this.compiled=r;this.sources=new Map;this.factories=new Map;this.wasm=new Map;this.evaluated=new Map;for(let o of n)this.sources.set(o.unit,o);}get names(){return new Set(this.sources.keys())}async prepare(){let e=[];for(let t of this.sources.values())if(t.kind==="native")this.wasm.set(t.unit,t.value);else if(t.kind==="wasm"){if(!tX())throw new vt(`runtime ${t.unit} needs WebAssembly, which this host does not provide`);let n=this.compiled?.(t.unit,t.bytes)??null,r=n===null?hC(t.bytes):Om(n);e.push(r.then(o=>{this.wasm.set(t.unit,o);}));}else if(this.compiler.ahead){let n=LU+t.unit;e.push(Promise.resolve(this.compiler.compile(n,t.code)).then(r=>{this.factories.set(t.unit,r);}));}await Promise.all(e);}resolve(e){let t=e.library,n=this.wasm.get(t);return n!==void 0?n:this.load(t)[e.export]}load(e){let t=this.evaluated.get(e);if(t!==void 0)return t;let n=this.sources.get(e);if(n===void 0||n.kind!=="code")throw new vt(`runtime ${e} is not in the package`);let r=this.factories.get(e);r===void 0&&(r=this.compiler.compile(LU+e,n.code),this.factories.set(e,r));let o=new Map;for(let c of n.imports)o.set(c.specifier,c);let s=c=>{let u=o.get(c);if(u===void 0)throw new vt(`runtime ${e} may not require ${c}`);return this.resolve(u)},a={exports:{}};r(s,a.exports,a,this.tick);let l=a.exports.default;return this.evaluated.set(e,l),l}};che={create(i){return URL.createObjectURL(new Blob([i],{type:"text/javascript"}))},revoke(i){URL.revokeObjectURL(i);}};});var ghe=Pp(()=>{});var Hw={engine_abi_compatible:1,engine_abi_digest:0,engine_abi_version:0,engine_ai_agent_target:2,engine_ai_aim:3,engine_ai_archetype:3,engine_ai_cover_add:1,engine_ai_cover_remove:2,engine_ai_create:1,engine_ai_despawn:2,engine_ai_destroy:1,engine_ai_digest:2,engine_ai_doing:5,engine_ai_events:3,engine_ai_focus:4,engine_ai_goal:3,engine_ai_join:3,engine_ai_leave:2,engine_ai_need:4,engine_ai_noise:3,engine_ai_object_add:1,engine_ai_object_remove:2,engine_ai_place:2,engine_ai_registers:1,engine_ai_skill:3,engine_ai_slots:1,engine_ai_spawn:2,engine_ai_speed:3,engine_ai_squad:3,engine_ai_step:1,engine_ai_step_world:2,engine_ai_target_add:1,engine_ai_target_move:2,engine_ai_target_remove:2,engine_ai_target_threat:3,engine_ai_view:1,engine_alloc:2,engine_apply_commands:2,engine_arena_ceiling:0,engine_arena_committed:0,engine_arena_release:0,engine_arena_set_ceiling:1,engine_audio_bound:0,engine_audio_capture:4,engine_audio_clock:2,engine_audio_create_bus:2,engine_audio_create_convolver:3,engine_audio_create_emitters:5,engine_audio_create_reverb:5,engine_audio_feed_emitters:4,engine_audio_is_playing:2,engine_audio_load_pcm:5,engine_audio_load_wav:3,engine_audio_lockstep:3,engine_audio_meter:3,engine_audio_music_layer:4,engine_audio_music_play:7,engine_audio_music_position:2,engine_audio_music_stinger:5,engine_audio_music_stop:3,engine_audio_music_tempo:4,engine_audio_now:2,engine_audio_occlude:2,engine_audio_place:6,engine_audio_play:6,engine_audio_play_at:7,engine_audio_registers:1,engine_audio_relay_create:3,engine_audio_relay_pump:3,engine_audio_relay_receive:3,engine_audio_release:2,engine_audio_release_emitters:2,engine_audio_replace:4,engine_audio_reset:1,engine_audio_resume:1,engine_audio_set_bus_filter:6,engine_audio_set_bus_gain:4,engine_audio_set_bus_send:5,engine_audio_set_duck:7,engine_audio_set_limiter:4,engine_audio_set_listener:2,engine_audio_set_sound_limit:4,engine_audio_set_voice_binaural:3,engine_audio_set_voice_budget:2,engine_audio_set_voice_filter:6,engine_audio_set_voice_gain:4,engine_audio_set_voice_loop:5,engine_audio_set_voice_occlusion:3,engine_audio_set_voice_rate:3,engine_audio_set_voice_spatial:3,engine_audio_stop:3,engine_audio_stop_at:4,engine_audio_stream_close:2,engine_audio_stream_duration:3,engine_audio_stream_feed:5,engine_audio_stream_flush:2,engine_audio_stream_gain:4,engine_audio_stream_loop:3,engine_audio_stream_open:5,engine_audio_stream_open_opus:5,engine_audio_stream_play:4,engine_audio_stream_seek:3,engine_audio_stream_space:2,engine_audio_stream_time:3,engine_audio_suspend:1,engine_audio_update:1,engine_avatar_close:1,engine_avatar_edit_json:3,engine_avatar_error:3,engine_avatar_express:3,engine_avatar_feel:3,engine_avatar_hear:3,engine_avatar_identity:3,engine_avatar_json:3,engine_avatar_open:2,engine_avatar_perform:2,engine_avatar_performer_create:2,engine_avatar_performer_destroy:1,engine_avatar_performer_outputs:1,engine_avatar_redo:1,engine_avatar_registers:1,engine_avatar_say:3,engine_avatar_schema:2,engine_avatar_track:2,engine_avatar_undo:1,engine_avatar_write:3,engine_bench_close:0,engine_bench_frame:0,engine_bench_host:3,engine_bench_open:6,engine_bench_report:2,engine_bind_transforms:1,engine_body_angular_velocity:2,engine_body_create:2,engine_body_destroy:2,engine_body_linear_velocity:2,engine_body_sleeping:2,engine_body_velocity_at_point:2,engine_character_move:3,engine_chemistry_catalog:3,engine_chemistry_close:1,engine_chemistry_counts:1,engine_chemistry_define:4,engine_chemistry_find:4,engine_chemistry_grid_clear_events:1,engine_chemistry_grid_close:1,engine_chemistry_grid_colours:2,engine_chemistry_grid_columns:1,engine_chemistry_grid_events:1,engine_chemistry_grid_fired:1,engine_chemistry_grid_heat:4,engine_chemistry_grid_load:5,engine_chemistry_grid_open:6,engine_chemistry_grid_paint:5,engine_chemistry_grid_power:3,engine_chemistry_grid_probe:6,engine_chemistry_grid_save:2,engine_chemistry_grid_saved:1,engine_chemistry_grid_set:7,engine_chemistry_grid_stats:3,engine_chemistry_grid_step:3,engine_chemistry_grid_threshold:3,engine_chemistry_grid_unthreshold:2,engine_chemistry_grid_watch:4,engine_chemistry_open:1,engine_chemistry_particles_close:1,engine_chemistry_particles_columns:1,engine_chemistry_particles_events:1,engine_chemistry_particles_open:2,engine_chemistry_particles_spawn:5,engine_chemistry_particles_step:5,engine_chemistry_reaction_info:3,engine_chemistry_species_info:3,engine_chemistry_text:1,engine_chemistry_vessel_add:5,engine_chemistry_vessel_close:1,engine_chemistry_vessel_heat:3,engine_chemistry_vessel_open:2,engine_chemistry_vessel_power:2,engine_chemistry_vessel_state:3,engine_chemistry_vessel_step:3,engine_chemistry_vessel_take:4,engine_chemistry_vessel_vent:3,engine_cloth_add_grid:3,engine_cloth_add_mesh:7,engine_cloth_anchors:4,engine_cloth_colliders:3,engine_cloth_couple:3,engine_cloth_create:2,engine_cloth_create_in:3,engine_cloth_destroy:1,engine_cloth_digest:1,engine_cloth_params:2,engine_cloth_positions:2,engine_cloth_present:4,engine_cloth_registers:1,engine_cloth_remove:2,engine_cloth_rigid_mesh:5,engine_cloth_rigid_pose:2,engine_cloth_step:2,engine_cloth_step_coupled:3,engine_cloth_uncouple:2,engine_collider_create:2,engine_collider_destroy:2,engine_collider_enable:3,engine_compute_clear:0,engine_compute_frame:2,engine_compute_priority:3,engine_compute_registers:0,engine_compute_render:2,engine_contact_count:1,engine_contacts_a:1,engine_contacts_b:1,engine_contacts_started:1,engine_controller_create:1,engine_controller_destroy:2,engine_craft_advance_water:1,engine_craft_cascades:4,engine_craft_controls:1,engine_craft_create:1,engine_craft_crumple:5,engine_craft_crumple_present:4,engine_craft_custom:5,engine_craft_damage:2,engine_craft_destroy:1,engine_craft_impact:3,engine_craft_ocean:1,engine_craft_preset:5,engine_craft_puddles:7,engine_craft_puddles_bed:3,engine_craft_puddles_pour:1,engine_craft_puddles_weather:3,engine_craft_registers:1,engine_craft_remove:2,engine_craft_render_water:2,engine_craft_ripples:4,engine_craft_ripples_follow:1,engine_craft_ripples_push:1,engine_craft_sea:4,engine_craft_set_flow:1,engine_craft_set_water:1,engine_craft_spin_up:2,engine_craft_step:2,engine_craft_telemetry:1,engine_destructible_attached:2,engine_destructible_configure:4,engine_destructible_create:8,engine_destructible_damage:3,engine_destructible_destroy:3,engine_destruction_close:1,engine_destruction_dropped:1,engine_destruction_events:1,engine_destruction_open:1,engine_destruction_update:3,engine_determinism_digest:3,engine_export_arity:2,engine_export_prototype_of:2,engine_feature_count:0,engine_feature_name:3,engine_flow_build:1,engine_flow_costs:1,engine_flow_create:1,engine_flow_destroy:1,engine_flow_rasterize:2,engine_flow_registers:1,engine_fluid_caps:0,engine_fluid_clear:2,engine_fluid_colliders:4,engine_fluid_count:2,engine_fluid_create:3,engine_fluid_destroy:2,engine_fluid_emitter:4,engine_fluid_forces:3,engine_fluid_parameters:3,engine_fluid_pause:3,engine_fluid_step:3,engine_fluid_surface:3,engine_fluid_volume:8,engine_fluid_volume_info:4,engine_fluid_volumes_clear:2,engine_fracturer_asset:3,engine_fracturer_close:1,engine_fracturer_fragment:4,engine_fracturer_model:3,engine_fracturer_open:0,engine_fracturer_run:6,engine_free:3,engine_genesis_active:3,engine_genesis_advance:2,engine_genesis_close:1,engine_genesis_decree:3,engine_genesis_indicators:2,engine_genesis_interest:3,engine_genesis_load:2,engine_genesis_open:1,engine_genesis_save:1,engine_genesis_saved:1,engine_genesis_settlements:4,engine_genesis_step_months:2,engine_gpu_prewarm:0,engine_heap_live:0,engine_heap_peak:0,engine_inspector_enable:1,engine_inspector_label:4,engine_inspector_registers:0,engine_inspector_watch:2,engine_joint_break_count:1,engine_joint_breakable:2,engine_joint_breaks:1,engine_joint_broken:2,engine_joint_contacts:3,engine_joint_create:3,engine_joint_destroy:2,engine_joint_drive:3,engine_joint_drive_clear:3,engine_joint_enable:3,engine_joint_load:2,engine_joint_motor:2,engine_joint_motor_position:2,engine_joint_target:2,engine_kernel_attach:5,engine_kernel_attach_handle:3,engine_kernel_backend:1,engine_kernel_bind:4,engine_kernel_bind_pool:4,engine_kernel_bind_table:3,engine_kernel_clear_events:1,engine_kernel_data:1,engine_kernel_events:1,engine_kernel_gpu_bind:5,engine_kernel_gpu_class:0,engine_kernel_gpu_clear_events:1,engine_kernel_gpu_events:1,engine_kernel_gpu_frame:0,engine_kernel_gpu_mirror:3,engine_kernel_gpu_ready:0,engine_kernel_gpu_run:4,engine_kernel_gpu_sync:0,engine_kernel_gpu_touch:2,engine_kernel_gpu_unbind:1,engine_kernel_isa:0,engine_kernel_isa_max:0,engine_kernel_load:2,engine_kernel_run:4,engine_kernel_run_region:6,engine_kernel_spawns:1,engine_kernel_stage_begin:3,engine_kernel_stage_call:2,engine_kernel_stage_column:2,engine_kernel_stage_data:4,engine_kernel_stage_end:1,engine_kernel_stage_finish:2,engine_kernel_stage_records:2,engine_kernel_stage_storage:2,engine_kernel_stage_uniforms:1,engine_kernel_unbind:1,engine_kernel_unload:1,engine_memory_base:0,engine_memory_bytes:0,engine_memory_used:0,engine_native_abi_version:0,engine_nav_add_link:1,engine_nav_add_tile:3,engine_nav_agent_add:1,engine_nav_agent_remove:2,engine_nav_agent_stop:2,engine_nav_agent_target:2,engine_nav_agents:1,engine_nav_costs:1,engine_nav_create:1,engine_nav_destroy:1,engine_nav_find_path:3,engine_nav_include:1,engine_nav_nearest:1,engine_nav_registers:1,engine_nav_remove_link:2,engine_nav_remove_tile:3,engine_nav_roads:3,engine_nav_signal:2,engine_nav_step:1,engine_nav_vehicle_add:2,engine_nav_vehicle_external:3,engine_nav_vehicle_remove:2,engine_nav_vehicles:1,engine_noise:5,engine_noise_fbm:5,engine_overlap_sphere:1,engine_physics_radial_gravity:2,engine_pipeline_archive_path:2,engine_pipeline_cache_path:2,engine_ragdoll_act:5,engine_ragdoll_bodies:2,engine_ragdoll_bone_count:2,engine_ragdoll_create:3,engine_ragdoll_destroy:2,engine_ragdoll_drive:4,engine_ragdoll_mjcf:5,engine_ragdoll_observe:6,engine_ragdoll_place:4,engine_ragdoll_policy_control:3,engine_ragdoll_policy_create:6,engine_ragdoll_policy_destroy:1,engine_ragdoll_read:4,engine_ragdoll_root:2,engine_raycast:1,engine_reactive_create:3,engine_reactive_destroy:1,engine_reactive_digest:1,engine_reactive_emitter:3,engine_reactive_hob:2,engine_reactive_lit:2,engine_reactive_media:3,engine_reactive_positions:1,engine_reactive_preheat:3,engine_reactive_registers:1,engine_reactive_step:2,engine_reactive_texels:1,engine_render_animate:1,engine_render_animation:5,engine_render_attach_layer:6,engine_render_attach_layer_with:8,engine_render_attach_window:6,engine_render_attach_window_with:8,engine_render_backend:1,engine_render_buffer:4,engine_render_camera_view_projection:2,engine_render_capabilities:1,engine_render_capture_done:1,engine_render_capture_into:4,engine_render_commands:1,engine_render_commit_geometry:2,engine_render_create:1,engine_render_create_chain:1,engine_render_create_emitter:1,engine_render_create_geometry:1,engine_render_create_material:5,engine_render_create_node:1,engine_render_create_pass:1,engine_render_create_target:1,engine_render_create_texture:1,engine_render_decode_texture:4,engine_render_desc:1,engine_render_destroy:1,engine_render_detach_layer:1,engine_render_display_link_start:7,engine_render_display_link_stop:1,engine_render_encode_texture:3,engine_render_fade_clip_from:4,engine_render_find_node:4,engine_render_flush:2,engine_render_font_face:4,engine_render_force_tier:2,engine_render_frame:1,engine_render_frame_cap:1,engine_render_install_shaders:3,engine_render_install_texture:5,engine_render_instantiate:2,engine_render_load_clips:5,engine_render_load_font:4,engine_render_load_installed:3,engine_render_load_model:3,engine_render_node_matrix:3,engine_render_node_poses:4,engine_render_pipelines:3,engine_render_play_clip:6,engine_render_push_video_frame:3,engine_render_quality_tier:1,engine_render_raw_bindings:1,engine_render_raw_buffer:1,engine_render_raw_pipeline:3,engine_render_raw_poll:2,engine_render_raw_read:4,engine_render_raw_read_texture:6,engine_render_raw_sampler:1,engine_render_raw_texture:1,engine_render_raycast:4,engine_render_read_target:7,engine_render_record_pipelines:2,engine_render_registers:1,engine_render_reload_model:4,engine_render_reload_texture:5,engine_render_resize:4,engine_render_set_blend_parameter_from:4,engine_render_set_chain_shader:5,engine_render_set_environment:1,engine_render_set_frame_budget:2,engine_render_set_ik_target_from:4,engine_render_set_main_budget:2,engine_render_set_perspective_from:4,engine_render_set_pipelining:2,engine_render_set_text:4,engine_render_set_text_style:2,engine_render_set_thermal_state:2,engine_render_stats:1,engine_render_sync:4,engine_render_text_bounds:3,engine_render_upscaler_kind:1,engine_render_upscaling:1,engine_render_vector_event_count:1,engine_render_vector_events:1,engine_render_vector_frame:2,engine_render_vector_load:3,engine_render_vector_surface:5,engine_render_vector_surface_data_index:4,engine_render_vector_surface_data_set:6,engine_render_vector_surface_destroy:2,engine_render_vector_surface_input:4,engine_render_vector_surface_input_index:4,engine_render_vector_surface_node:3,engine_render_vector_surface_pick:3,engine_render_vector_surface_play:4,engine_render_vector_surface_pointer:5,engine_render_vector_surface_seek:5,engine_render_vector_surface_stats:1,engine_render_vector_surface_tier:2,engine_render_vector_unload:2,engine_reserve:1,engine_session_enforced:0,engine_session_present:6,engine_session_status:0,engine_shape_cast:1,engine_smoke_create:3,engine_smoke_destroy:2,engine_smoke_emitters:4,engine_smoke_emitters_tinted:4,engine_smoke_follow:3,engine_smoke_step:3,engine_snapshot:2,engine_soa_create:1,engine_soa_destroy:1,engine_soa_effect:5,engine_soa_flow:3,engine_soa_generations:0,engine_soa_grid:5,engine_soa_header:1,engine_soa_inventory:6,engine_soa_map:6,engine_soa_near:2,engine_soa_nearest:3,engine_soa_paths:4,engine_soa_pick:4,engine_soa_raycast:4,engine_soa_reduce:4,engine_soa_remove:2,engine_soa_select:5,engine_soa_sort:5,engine_soa_turn:2,engine_soa_vec:7,engine_soft_activate:3,engine_soft_add:3,engine_soft_add_lattice:3,engine_soft_add_rope:3,engine_soft_anchors:4,engine_soft_colliders:3,engine_soft_couple:3,engine_soft_create:2,engine_soft_create_in:3,engine_soft_destroy:1,engine_soft_digest:1,engine_soft_move:2,engine_soft_params:2,engine_soft_positions:2,engine_soft_present:4,engine_soft_registers:1,engine_soft_remove:2,engine_soft_rigid_mesh:5,engine_soft_rigid_pose:2,engine_soft_step:2,engine_soft_step_coupled:3,engine_soft_uncouple:2,engine_splat_bench:5,engine_splat_bind:3,engine_splat_close:2,engine_splat_drape:6,engine_splat_edit:3,engine_splat_fail:2,engine_splat_hero_budget:2,engine_splat_motion:5,engine_splat_motion_rows:1,engine_splat_open:3,engine_splat_provide:4,engine_splat_registers:1,engine_splat_requests:1,engine_splat_set_transform:2,engine_splat_update:3,engine_step:2,engine_story_available:2,engine_story_create:2,engine_story_destroy:1,engine_story_events:1,engine_story_get:2,engine_story_id_of:3,engine_story_program_text:4,engine_story_registers:1,engine_story_samples:1,engine_story_seek:2,engine_story_set:3,engine_story_set_text:4,engine_story_start:1,engine_story_step:3,engine_story_text_index:3,engine_story_text_of:4,engine_story_variable:2,engine_story_variable_text:4,engine_stream_close:2,engine_stream_collider:3,engine_stream_open:6,engine_stream_open_logic:4,engine_stream_provide:3,engine_stream_registers:1,engine_stream_step_logic:5,engine_stream_update:3,engine_terrain_close:2,engine_terrain_colliders:4,engine_terrain_grass:2,engine_terrain_height:3,engine_terrain_interactors:3,engine_terrain_look:3,engine_terrain_normal:4,engine_terrain_open:6,engine_terrain_registers:1,engine_terrain_scatter:4,engine_terrain_sculpt:3,engine_terrain_update:3,engine_terrain_wind:5,engine_transform_convolve:5,engine_transform_convolver_close:1,engine_transform_convolver_open:3,engine_transform_distance_close:1,engine_transform_distance_mask:4,engine_transform_distance_open:3,engine_transform_distance_signed:5,engine_transform_fft_close:1,engine_transform_fft_open:2,engine_transform_fft_run:4,engine_transform_jump_flood:6,engine_transform_multigrid_close:1,engine_transform_multigrid_open:5,engine_transform_multigrid_solve:5,engine_transform_sat_build:3,engine_transform_sat_close:1,engine_transform_sat_open:2,engine_ui_accessibility:2,engine_ui_accessibility_export:1,engine_ui_apply:2,engine_ui_apply_bytes:3,engine_ui_clear_events:1,engine_ui_create:2,engine_ui_destroy:1,engine_ui_event_count:1,engine_ui_events:1,engine_ui_focus_move:2,engine_ui_focus_press:2,engine_ui_frame:2,engine_ui_occluded:3,engine_ui_patch_buffer:2,engine_ui_perform_action:3,engine_ui_pointer:6,engine_ui_register_font:4,engine_ui_render:2,engine_ui_set_anchor:5,engine_ui_set_language:3,engine_ui_set_slot:3,engine_ui_text:2,engine_ui_text_length:2,engine_ui_vector_attach:4,engine_ui_vector_audio:4,engine_ui_vector_data_index:4,engine_ui_vector_data_set:6,engine_ui_vector_detach:2,engine_ui_vector_fallback_font:3,engine_ui_vector_fallback_request:0,engine_ui_vector_fetch_next:4,engine_ui_vector_fetch_origins:4,engine_ui_vector_fetch_pending:2,engine_ui_vector_fetch_settle:6,engine_ui_vector_input:4,engine_ui_vector_input_index:4,engine_ui_vector_load:3,engine_ui_vector_play:4,engine_ui_vector_seek:5,engine_ui_vector_system_fonts:1,engine_ui_vector_unload:2,engine_ui_view:2,engine_ui_view_from_camera:2,engine_ui_viewport:8,engine_ui_wheel:5,engine_vector_author_add:4,engine_vector_author_add_artboard:1,engine_vector_author_add_asset:4,engine_vector_author_add_view_model:1,engine_vector_author_add_view_model_instance:2,engine_vector_author_add_view_model_property:3,engine_vector_author_bake:3,engine_vector_author_bind:3,engine_vector_author_checkpoint:1,engine_vector_author_close:1,engine_vector_author_edit_json:3,engine_vector_author_hit:4,engine_vector_author_insert:4,engine_vector_author_item:3,engine_vector_author_json:3,engine_vector_author_open:2,engine_vector_author_prop:4,engine_vector_author_prop_bytes:5,engine_vector_author_redo:1,engine_vector_author_registers:1,engine_vector_author_remove:2,engine_vector_author_result:3,engine_vector_author_schema:2,engine_vector_author_set:6,engine_vector_author_set_bytes:6,engine_vector_author_undo:1,engine_vector_author_unset:3,engine_vector_author_write:3,engine_vehicle_capacity:1,engine_vehicle_create:4,engine_vehicle_destroy:2,engine_vehicle_inputs:1,engine_vehicle_reserve:2,engine_vehicle_states:1,engine_voxel_branch:3,engine_voxel_close:2,engine_voxel_colliders:4,engine_voxel_edit:3,engine_voxel_export:3,engine_voxel_import:4,engine_voxel_load:3,engine_voxel_open:2,engine_voxel_release:2,engine_voxel_report:1,engine_voxel_root:2,engine_voxel_save:2,engine_voxel_saved:1,engine_voxel_snapshot:2,engine_voxel_update:3,engine_voxel_write:4,engine_water_params:1,engine_water_sample:4,engine_world_commands:1,engine_world_create:1,engine_world_desc:1,engine_world_destroy:1,engine_world_keyframe_nearest:2,engine_world_keyframe_registers:1,engine_world_keyframe_save:2,engine_world_keyframe_seek:2,engine_world_keyframe_truncate:2,engine_world_keyframes_enable:3,engine_world_registers:1,engine_world_rollback_create:2,engine_world_snapshot_clear:1,engine_world_snapshot_digest:2,engine_world_snapshot_mark:3,engine_world_snapshot_registers:1,engine_world_snapshot_restore:2,engine_world_snapshot_save:2,engine_world_snapshot_track:4,engine_world_snapshot_track_table:3,engine_world_snapshot_untrack:2},rB={engine_abi_compatible:1846252708,engine_abi_digest:1224336668,engine_abi_version:1675243454,engine_ai_agent_target:2107167374,engine_ai_aim:2034210499,engine_ai_archetype:1520945441,engine_ai_cover_add:1448600402,engine_ai_cover_remove:2133248489,engine_ai_create:1574567097,engine_ai_despawn:1822199027,engine_ai_destroy:1721721088,engine_ai_digest:1091215838,engine_ai_doing:1281157573,engine_ai_events:1782937551,engine_ai_focus:2040872025,engine_ai_goal:1708635894,engine_ai_join:1716574151,engine_ai_leave:1387843766,engine_ai_need:1350704501,engine_ai_noise:1294477849,engine_ai_object_add:2033349042,engine_ai_object_remove:1906593417,engine_ai_place:1269361018,engine_ai_registers:1480712669,engine_ai_skill:2044541598,engine_ai_slots:1256680524,engine_ai_spawn:1375893878,engine_ai_speed:1680574080,engine_ai_squad:1704274808,engine_ai_step:1249145061,engine_ai_step_world:2081469074,engine_ai_target_add:1474545708,engine_ai_target_move:1284585270,engine_ai_target_remove:1795203199,engine_ai_target_threat:1995908465,engine_ai_view:1698823528,engine_alloc:1555248155,engine_apply_commands:1865579443,engine_arena_ceiling:1596868752,engine_arena_committed:1486596929,engine_arena_release:1087108878,engine_arena_set_ceiling:1442993236,engine_audio_bound:1853296552,engine_audio_capture:1290046997,engine_audio_clock:1900590478,engine_audio_create_bus:1629907003,engine_audio_create_convolver:1097209438,engine_audio_create_emitters:1800244752,engine_audio_create_reverb:1457717399,engine_audio_feed_emitters:1153015803,engine_audio_is_playing:1426885707,engine_audio_load_pcm:1477313691,engine_audio_load_wav:2044530205,engine_audio_lockstep:1153252282,engine_audio_meter:2083291106,engine_audio_music_layer:2014414926,engine_audio_music_play:2144567260,engine_audio_music_position:1376527525,engine_audio_music_stinger:2062713103,engine_audio_music_stop:1076198009,engine_audio_music_tempo:1336531405,engine_audio_now:1434907440,engine_audio_occlude:1509951094,engine_audio_place:2084834059,engine_audio_play:2036562985,engine_audio_play_at:1897341954,engine_audio_registers:2121963491,engine_audio_relay_create:1830637471,engine_audio_relay_pump:1497798268,engine_audio_relay_receive:1346338323,engine_audio_release:2116747619,engine_audio_release_emitters:1396716091,engine_audio_replace:1813878871,engine_audio_reset:1294495960,engine_audio_resume:1275093668,engine_audio_set_bus_filter:1947262895,engine_audio_set_bus_gain:1756941455,engine_audio_set_bus_send:2079515313,engine_audio_set_duck:1406557853,engine_audio_set_limiter:1170352609,engine_audio_set_listener:1573290151,engine_audio_set_sound_limit:1216338395,engine_audio_set_voice_binaural:1224259557,engine_audio_set_voice_budget:1215413069,engine_audio_set_voice_filter:2030275023,engine_audio_set_voice_gain:1662766703,engine_audio_set_voice_loop:1338296033,engine_audio_set_voice_occlusion:1737051008,engine_audio_set_voice_rate:1933008042,engine_audio_set_voice_spatial:2142478307,engine_audio_stop:2061283418,engine_audio_stop_at:1553156159,engine_audio_stream_close:2112622765,engine_audio_stream_duration:1603193414,engine_audio_stream_feed:1284485086,engine_audio_stream_flush:1445829723,engine_audio_stream_gain:1277378498,engine_audio_stream_loop:2073581640,engine_audio_stream_open:1283261425,engine_audio_stream_open_opus:1315090258,engine_audio_stream_play:1878558742,engine_audio_stream_seek:1986093724,engine_audio_stream_space:1723229379,engine_audio_stream_time:1476351173,engine_audio_suspend:1885569405,engine_audio_update:1137801918,engine_avatar_close:1733444455,engine_avatar_edit_json:1283349266,engine_avatar_error:1517132383,engine_avatar_express:2007651672,engine_avatar_feel:1662976746,engine_avatar_hear:1373995023,engine_avatar_identity:1811547593,engine_avatar_json:1694329925,engine_avatar_open:1369610718,engine_avatar_perform:1635708823,engine_avatar_performer_create:1439046090,engine_avatar_performer_destroy:1392925774,engine_avatar_performer_outputs:2077934071,engine_avatar_redo:1622798444,engine_avatar_registers:1898753196,engine_avatar_say:1922080270,engine_avatar_schema:1239650526,engine_avatar_track:1074282758,engine_avatar_undo:1769420614,engine_avatar_write:1537261342,engine_bench_close:2142786287,engine_bench_frame:1195743242,engine_bench_host:1618561164,engine_bench_open:1798778190,engine_bench_report:1251400932,engine_bind_transforms:1527439525,engine_body_angular_velocity:1439908879,engine_body_create:1140291927,engine_body_destroy:1838747325,engine_body_linear_velocity:2076612566,engine_body_sleeping:1511049386,engine_body_velocity_at_point:1717127559,engine_character_move:1114261275,engine_chemistry_catalog:1802999348,engine_chemistry_close:1248724170,engine_chemistry_counts:1488691312,engine_chemistry_define:1130426681,engine_chemistry_find:1428886783,engine_chemistry_grid_clear_events:1185079123,engine_chemistry_grid_close:1456900481,engine_chemistry_grid_colours:1616209285,engine_chemistry_grid_columns:1806887249,engine_chemistry_grid_events:1737148225,engine_chemistry_grid_fired:1448231924,engine_chemistry_grid_heat:1860483926,engine_chemistry_grid_load:2036923002,engine_chemistry_grid_open:1342761229,engine_chemistry_grid_paint:1912940715,engine_chemistry_grid_power:1509593718,engine_chemistry_grid_probe:1519698377,engine_chemistry_grid_save:2114205687,engine_chemistry_grid_saved:1970010873,engine_chemistry_grid_set:1803345521,engine_chemistry_grid_stats:1513594414,engine_chemistry_grid_step:1760334930,engine_chemistry_grid_threshold:1662025764,engine_chemistry_grid_unthreshold:2067167290,engine_chemistry_grid_watch:1201285123,engine_chemistry_open:1401577229,engine_chemistry_particles_close:1090293374,engine_chemistry_particles_columns:1661499484,engine_chemistry_particles_events:2071923246,engine_chemistry_particles_open:2114612428,engine_chemistry_particles_spawn:1226656926,engine_chemistry_particles_step:1909650030,engine_chemistry_reaction_info:1633390078,engine_chemistry_species_info:2050201441,engine_chemistry_text:1451120980,engine_chemistry_vessel_add:1649080899,engine_chemistry_vessel_close:1416926307,engine_chemistry_vessel_heat:2075269881,engine_chemistry_vessel_open:1568050079,engine_chemistry_vessel_power:1648102155,engine_chemistry_vessel_state:1377408994,engine_chemistry_vessel_step:1880898712,engine_chemistry_vessel_take:1268143443,engine_chemistry_vessel_vent:1988041641,engine_cloth_add_grid:1796564298,engine_cloth_add_mesh:1248644749,engine_cloth_anchors:1123629570,engine_cloth_colliders:1671756723,engine_cloth_couple:1375622615,engine_cloth_create:1748209930,engine_cloth_create_in:1499462700,engine_cloth_destroy:1339636626,engine_cloth_digest:1373556171,engine_cloth_params:1535440643,engine_cloth_positions:2022331317,engine_cloth_present:1649616932,engine_cloth_registers:1958055301,engine_cloth_remove:1076757465,engine_cloth_rigid_mesh:1823748970,engine_cloth_rigid_pose:1244231236,engine_cloth_step:1094390651,engine_cloth_step_coupled:1152028678,engine_cloth_uncouple:1860801542,engine_collider_create:1604634531,engine_collider_destroy:1618176729,engine_collider_enable:1561312744,engine_compute_clear:1153773761,engine_compute_frame:1135610005,engine_compute_priority:1923188512,engine_compute_registers:1383352914,engine_compute_render:1164282706,engine_contact_count:1470453693,engine_contacts_a:1631213727,engine_contacts_b:2013685168,engine_contacts_started:1331533549,engine_controller_create:1446873509,engine_controller_destroy:2025633481,engine_craft_advance_water:1379144859,engine_craft_cascades:1834855393,engine_craft_controls:1441049703,engine_craft_create:2011641072,engine_craft_crumple:1872756079,engine_craft_crumple_present:2124694477,engine_craft_custom:1266982655,engine_craft_damage:1928729562,engine_craft_destroy:1986517804,engine_craft_impact:1896927736,engine_craft_ocean:1640023363,engine_craft_preset:1243933952,engine_craft_puddles:1182984090,engine_craft_puddles_bed:1750790885,engine_craft_puddles_pour:2106007501,engine_craft_puddles_weather:1412842535,engine_craft_registers:1910030299,engine_craft_remove:1708317071,engine_craft_render_water:2111274171,engine_craft_ripples:1341990656,engine_craft_ripples_follow:1659119518,engine_craft_ripples_push:1701428505,engine_craft_sea:2125973658,engine_craft_set_flow:1575962474,engine_craft_set_water:1267961609,engine_craft_spin_up:1310860071,engine_craft_step:1495541841,engine_craft_telemetry:1630709848,engine_destructible_attached:1930088993,engine_destructible_configure:1920047578,engine_destructible_create:1446400832,engine_destructible_damage:1508814597,engine_destructible_destroy:1300613865,engine_destruction_close:1178950395,engine_destruction_dropped:1162184010,engine_destruction_events:1523682024,engine_destruction_open:1542689700,engine_destruction_update:1519082250,engine_determinism_digest:1303927949,engine_export_arity:1232958473,engine_export_prototype_of:1367039039,engine_feature_count:1447928505,engine_feature_name:1883688201,engine_flow_build:1165373833,engine_flow_costs:1411437727,engine_flow_create:1768449351,engine_flow_destroy:1136744238,engine_flow_rasterize:1418434492,engine_flow_registers:1349819651,engine_fluid_caps:2098470111,engine_fluid_clear:1810766532,engine_fluid_colliders:1085271039,engine_fluid_count:1206525066,engine_fluid_create:1733154431,engine_fluid_destroy:1174530443,engine_fluid_emitter:1314149528,engine_fluid_forces:1092859660,engine_fluid_parameters:1344274736,engine_fluid_pause:1131961589,engine_fluid_step:1119669769,engine_fluid_surface:1534494851,engine_fluid_volume:1976334949,engine_fluid_volume_info:1895059831,engine_fluid_volumes_clear:1988279944,engine_fracturer_asset:1472971562,engine_fracturer_close:1122524291,engine_fracturer_fragment:1167760840,engine_fracturer_model:1648753123,engine_fracturer_open:1383483276,engine_fracturer_run:1132931983,engine_free:1274831988,engine_genesis_active:1335772138,engine_genesis_advance:1939131317,engine_genesis_close:1654407402,engine_genesis_decree:1206569388,engine_genesis_indicators:1805893666,engine_genesis_interest:1839690843,engine_genesis_load:1252862347,engine_genesis_open:1561303361,engine_genesis_save:1975572054,engine_genesis_saved:1629409384,engine_genesis_settlements:2087603946,engine_genesis_step_months:1269136539,engine_gpu_prewarm:1473114259,engine_heap_live:1780032314,engine_heap_peak:1508105667,engine_inspector_enable:1999465419,engine_inspector_label:1671079775,engine_inspector_registers:1947043826,engine_inspector_watch:2062073631,engine_joint_break_count:1317586309,engine_joint_breakable:1129230870,engine_joint_breaks:1958523807,engine_joint_broken:1827504544,engine_joint_contacts:1723083024,engine_joint_create:1503051311,engine_joint_destroy:1232130111,engine_joint_drive:1851235367,engine_joint_drive_clear:2075882945,engine_joint_enable:1602136850,engine_joint_load:1571810461,engine_joint_motor:1089642104,engine_joint_motor_position:1642711468,engine_joint_target:1327673688,engine_kernel_attach:1303923099,engine_kernel_attach_handle:1653962430,engine_kernel_backend:1633511535,engine_kernel_bind:1591759542,engine_kernel_bind_pool:2062715277,engine_kernel_bind_table:1185330026,engine_kernel_clear_events:1352927829,engine_kernel_data:1863712474,engine_kernel_events:2145789035,engine_kernel_gpu_bind:1264975134,engine_kernel_gpu_class:1080327804,engine_kernel_gpu_clear_events:1185050334,engine_kernel_gpu_events:1510489900,engine_kernel_gpu_frame:1921483946,engine_kernel_gpu_mirror:1987709134,engine_kernel_gpu_ready:1489565748,engine_kernel_gpu_run:1433688195,engine_kernel_gpu_sync:1957182440,engine_kernel_gpu_touch:1788049286,engine_kernel_gpu_unbind:2073494541,engine_kernel_isa:1712856914,engine_kernel_isa_max:1937070907,engine_kernel_load:1539570777,engine_kernel_run:1497522102,engine_kernel_run_region:2035016316,engine_kernel_spawns:1805264870,engine_kernel_stage_begin:1915812615,engine_kernel_stage_call:1787130355,engine_kernel_stage_column:1125094545,engine_kernel_stage_data:1968970908,engine_kernel_stage_end:1245053580,engine_kernel_stage_finish:1341324610,engine_kernel_stage_records:2088439585,engine_kernel_stage_storage:1240197317,engine_kernel_stage_uniforms:1359213328,engine_kernel_unbind:1262607058,engine_kernel_unload:1733457269,engine_memory_base:1539000465,engine_memory_bytes:2113038832,engine_memory_used:1802176122,engine_native_abi_version:1110110282,engine_nav_add_link:1902961790,engine_nav_add_tile:1112771993,engine_nav_agent_add:1805407239,engine_nav_agent_remove:1335168644,engine_nav_agent_stop:1632652728,engine_nav_agent_target:1827738553,engine_nav_agents:1118361740,engine_nav_costs:2083043082,engine_nav_create:2126325214,engine_nav_destroy:1281730805,engine_nav_find_path:1330478452,engine_nav_include:1742954860,engine_nav_nearest:1758940906,engine_nav_registers:1491564498,engine_nav_remove_link:1507101369,engine_nav_remove_tile:1221061503,engine_nav_roads:1773003864,engine_nav_signal:1277876790,engine_nav_step:1758915108,engine_nav_vehicle_add:1874610640,engine_nav_vehicle_external:1431319996,engine_nav_vehicle_remove:1794850891,engine_nav_vehicles:1134223897,engine_noise:2000666837,engine_noise_fbm:1376647009,engine_overlap_sphere:1611761859,engine_physics_radial_gravity:1224952577,engine_pipeline_archive_path:2133909928,engine_pipeline_cache_path:1110088632,engine_ragdoll_act:1670274578,engine_ragdoll_bodies:1918311900,engine_ragdoll_bone_count:2063872050,engine_ragdoll_create:1440090499,engine_ragdoll_destroy:1516821748,engine_ragdoll_drive:1124215581,engine_ragdoll_mjcf:1813034118,engine_ragdoll_observe:1839488917,engine_ragdoll_place:1663601028,engine_ragdoll_policy_control:1797995647,engine_ragdoll_policy_create:1613658894,engine_ragdoll_policy_destroy:1700600968,engine_ragdoll_read:1230784551,engine_ragdoll_root:1777323e3,engine_raycast:1142498307,engine_reactive_create:1541787835,engine_reactive_destroy:1681177887,engine_reactive_digest:1364713894,engine_reactive_emitter:1573210107,engine_reactive_hob:1178961770,engine_reactive_lit:1828366841,engine_reactive_media:1228346102,engine_reactive_positions:1529799232,engine_reactive_preheat:1606230045,engine_reactive_registers:1204931034,engine_reactive_step:1577303972,engine_reactive_texels:1386647849,engine_render_animate:1477512360,engine_render_animation:1714748162,engine_render_attach_layer:1818320442,engine_render_attach_layer_with:1347049181,engine_render_attach_window:1181315959,engine_render_attach_window_with:1302456590,engine_render_backend:1866715492,engine_render_buffer:1130915177,engine_render_camera_view_projection:2070663557,engine_render_capabilities:1263833084,engine_render_capture_done:1476087091,engine_render_capture_into:1598116126,engine_render_commands:2108356251,engine_render_commit_geometry:1376001905,engine_render_create:1839751775,engine_render_create_chain:1552560063,engine_render_create_emitter:1795309054,engine_render_create_geometry:1215188314,engine_render_create_material:1589276495,engine_render_create_node:1109572862,engine_render_create_pass:1148000749,engine_render_create_target:1259065197,engine_render_create_texture:1897134081,engine_render_decode_texture:1281261110,engine_render_desc:1560880190,engine_render_destroy:1310521894,engine_render_detach_layer:1104900122,engine_render_display_link_start:1501053742,engine_render_display_link_stop:2061705681,engine_render_encode_texture:1957335299,engine_render_fade_clip_from:1800962648,engine_render_find_node:2042017478,engine_render_flush:1416905629,engine_render_font_face:1368964391,engine_render_force_tier:2061042228,engine_render_frame:1439031162,engine_render_frame_cap:1114803282,engine_render_install_shaders:1152659574,engine_render_install_texture:1979703838,engine_render_instantiate:1210756983,engine_render_load_clips:1206109320,engine_render_load_font:1558449408,engine_render_load_installed:1957920845,engine_render_load_model:2145307010,engine_render_node_matrix:1724778818,engine_render_node_poses:1429220528,engine_render_pipelines:1317536411,engine_render_play_clip:2071132070,engine_render_push_video_frame:1102379277,engine_render_quality_tier:1820242399,engine_render_raw_bindings:1445986338,engine_render_raw_buffer:2089260534,engine_render_raw_pipeline:1989041653,engine_render_raw_poll:1477840777,engine_render_raw_read:1278153760,engine_render_raw_read_texture:1511714364,engine_render_raw_sampler:1327165870,engine_render_raw_texture:1297375143,engine_render_raycast:1508873866,engine_render_read_target:1811570957,engine_render_record_pipelines:2007519786,engine_render_registers:1511975003,engine_render_reload_model:1676917483,engine_render_reload_texture:1474198443,engine_render_resize:1644855707,engine_render_set_blend_parameter_from:1616069641,engine_render_set_chain_shader:1124644370,engine_render_set_environment:1880855983,engine_render_set_frame_budget:1710584709,engine_render_set_ik_target_from:1143071694,engine_render_set_main_budget:1701671639,engine_render_set_perspective_from:1800116136,engine_render_set_pipelining:1580292659,engine_render_set_text:1702104448,engine_render_set_text_style:1937588787,engine_render_set_thermal_state:1786514877,engine_render_stats:1187825100,engine_render_sync:1908929479,engine_render_text_bounds:1547325043,engine_render_upscaler_kind:1521295429,engine_render_upscaling:1687081143,engine_render_vector_event_count:1306623398,engine_render_vector_events:1816008222,engine_render_vector_frame:1902539302,engine_render_vector_load:2119772188,engine_render_vector_surface:1956986980,engine_render_vector_surface_data_index:1997708795,engine_render_vector_surface_data_set:1082148450,engine_render_vector_surface_destroy:2132815669,engine_render_vector_surface_input:2009512003,engine_render_vector_surface_input_index:1775499951,engine_render_vector_surface_node:1631986633,engine_render_vector_surface_pick:1465208959,engine_render_vector_surface_play:2119324589,engine_render_vector_surface_pointer:1827703182,engine_render_vector_surface_seek:1606108253,engine_render_vector_surface_stats:1561356240,engine_render_vector_surface_tier:1318687031,engine_render_vector_unload:1228385460,engine_reserve:2040035124,engine_session_enforced:2014663060,engine_session_present:1980207345,engine_session_status:1491866571,engine_shape_cast:1765473167,engine_smoke_create:1782597833,engine_smoke_destroy:1413387770,engine_smoke_emitters:1521842964,engine_smoke_emitters_tinted:1576818539,engine_smoke_follow:1517028342,engine_smoke_step:1462956396,engine_snapshot:1080126076,engine_soa_create:1572131785,engine_soa_destroy:1077944964,engine_soa_effect:1586597881,engine_soa_flow:1695891306,engine_soa_generations:1156634387,engine_soa_grid:1409991024,engine_soa_header:1788973877,engine_soa_inventory:1378778346,engine_soa_map:1525460288,engine_soa_near:1212131394,engine_soa_nearest:1412397248,engine_soa_paths:1719800736,engine_soa_pick:1947039927,engine_soa_raycast:1686772303,engine_soa_reduce:1508091786,engine_soa_remove:1909308484,engine_soa_select:2124848596,engine_soa_sort:1608226048,engine_soa_turn:1362783833,engine_soa_vec:1279061860,engine_soft_activate:1084710920,engine_soft_add:1289099839,engine_soft_add_lattice:1655973098,engine_soft_add_rope:1783448024,engine_soft_anchors:1623683836,engine_soft_colliders:1301347837,engine_soft_couple:1269355913,engine_soft_create:1136914214,engine_soft_create_in:1292635640,engine_soft_destroy:1379860710,engine_soft_digest:1512569553,engine_soft_move:2144849294,engine_soft_params:1505071189,engine_soft_positions:1350466423,engine_soft_present:1184189058,engine_soft_registers:1079495091,engine_soft_remove:2012670519,engine_soft_rigid_mesh:1622813168,engine_soft_rigid_pose:1845073506,engine_soft_step:1924157745,engine_soft_step_coupled:1304151184,engine_soft_uncouple:1840822644,engine_splat_bench:1928482274,engine_splat_bind:1550081272,engine_splat_close:1949153226,engine_splat_drape:2137022990,engine_splat_edit:1974094180,engine_splat_fail:1298791785,engine_splat_hero_budget:2097821698,engine_splat_motion:1372351450,engine_splat_motion_rows:1335114137,engine_splat_open:1407655239,engine_splat_provide:1885686159,engine_splat_registers:1467436081,engine_splat_requests:1778943637,engine_splat_set_transform:1489529999,engine_splat_update:1308548591,engine_step:1520429634,engine_story_available:1196203783,engine_story_create:1256201342,engine_story_destroy:1952798789,engine_story_events:1264546045,engine_story_get:1762137908,engine_story_id_of:1905231321,engine_story_program_text:1608455107,engine_story_registers:1211264686,engine_story_samples:2067330933,engine_story_seek:1714280459,engine_story_set:2029839685,engine_story_set_text:1131927787,engine_story_start:1317462088,engine_story_step:2061211227,engine_story_text_index:1771601345,engine_story_text_of:2083773493,engine_story_variable:1376041686,engine_story_variable_text:1730618057,engine_stream_close:1258822514,engine_stream_collider:2021475266,engine_stream_open:1915696754,engine_stream_open_logic:1487748416,engine_stream_provide:1894217993,engine_stream_registers:1934628271,engine_stream_step_logic:1461987858,engine_stream_update:1131772209,engine_terrain_close:1777822273,engine_terrain_colliders:1194363850,engine_terrain_grass:1754682495,engine_terrain_height:1742970492,engine_terrain_interactors:1143832703,engine_terrain_look:1586498494,engine_terrain_normal:2037706298,engine_terrain_open:1701147280,engine_terrain_registers:1356745298,engine_terrain_scatter:1291365178,engine_terrain_sculpt:1888667744,engine_terrain_update:1584018334,engine_terrain_wind:1812668444,engine_transform_convolve:1397491463,engine_transform_convolver_close:2105441011,engine_transform_convolver_open:1266742714,engine_transform_distance_close:1751823738,engine_transform_distance_mask:1236545058,engine_transform_distance_open:1558400648,engine_transform_distance_signed:1455903607,engine_transform_fft_close:1678503649,engine_transform_fft_open:1609552145,engine_transform_fft_run:1412696659,engine_transform_jump_flood:1593104924,engine_transform_multigrid_close:1412227490,engine_transform_multigrid_open:1178277696,engine_transform_multigrid_solve:1217025809,engine_transform_sat_build:1784427278,engine_transform_sat_close:1959658469,engine_transform_sat_open:2106942409,engine_ui_accessibility:1532832209,engine_ui_accessibility_export:1396830578,engine_ui_apply:1407349713,engine_ui_apply_bytes:2141865918,engine_ui_clear_events:1983925241,engine_ui_create:1640130406,engine_ui_destroy:1335019932,engine_ui_event_count:2146698422,engine_ui_events:1617272544,engine_ui_focus_move:1399860729,engine_ui_focus_press:1299935209,engine_ui_frame:1096392964,engine_ui_occluded:1464023580,engine_ui_patch_buffer:2067580500,engine_ui_perform_action:1924104659,engine_ui_pointer:1718592928,engine_ui_register_font:2050096706,engine_ui_render:1526214245,engine_ui_set_anchor:2120930603,engine_ui_set_language:2086640105,engine_ui_set_slot:1645814756,engine_ui_text:1744778394,engine_ui_text_length:1361726365,engine_ui_vector_attach:1147653020,engine_ui_vector_audio:2087064555,engine_ui_vector_data_index:1213343073,engine_ui_vector_data_set:1401306508,engine_ui_vector_detach:2059660046,engine_ui_vector_fallback_font:2078651584,engine_ui_vector_fallback_request:2083807242,engine_ui_vector_fetch_next:1777430152,engine_ui_vector_fetch_origins:1689285416,engine_ui_vector_fetch_pending:1994505057,engine_ui_vector_fetch_settle:1402475682,engine_ui_vector_input:1662579533,engine_ui_vector_input_index:1691943421,engine_ui_vector_load:1870818974,engine_ui_vector_play:2138426995,engine_ui_vector_seek:1572101459,engine_ui_vector_system_fonts:1383044023,engine_ui_vector_unload:1745155254,engine_ui_view:1173959305,engine_ui_view_from_camera:1780373657,engine_ui_viewport:1424574171,engine_ui_wheel:1790169254,engine_vector_author_add:1622629877,engine_vector_author_add_artboard:1794442649,engine_vector_author_add_asset:1926564713,engine_vector_author_add_view_model:1592106681,engine_vector_author_add_view_model_instance:1596526649,engine_vector_author_add_view_model_property:1385194457,engine_vector_author_bake:1510944034,engine_vector_author_bind:2080046557,engine_vector_author_checkpoint:1650782958,engine_vector_author_close:1181969333,engine_vector_author_edit_json:1376707662,engine_vector_author_hit:1562455407,engine_vector_author_insert:1505083201,engine_vector_author_item:1782915470,engine_vector_author_json:2146737929,engine_vector_author_open:2099753616,engine_vector_author_prop:1146154646,engine_vector_author_prop_bytes:1329221122,engine_vector_author_redo:1625832400,engine_vector_author_registers:1750130480,engine_vector_author_remove:2132017544,engine_vector_author_result:1314478934,engine_vector_author_schema:1356926698,engine_vector_author_set:1602944178,engine_vector_author_set_bytes:1350804141,engine_vector_author_undo:1946819506,engine_vector_author_unset:2069765981,engine_vector_author_write:1313888498,engine_vehicle_capacity:1333951202,engine_vehicle_create:1876392144,engine_vehicle_destroy:1993918659,engine_vehicle_inputs:2144900200,engine_vehicle_reserve:1769245765,engine_vehicle_states:1214534685,engine_voxel_branch:1843883615,engine_voxel_close:1189820990,engine_voxel_colliders:1991771189,engine_voxel_edit:1091152716,engine_voxel_export:1837980470,engine_voxel_import:1291455493,engine_voxel_load:1674530654,engine_voxel_open:2079927157,engine_voxel_release:1406848868,engine_voxel_report:1630520289,engine_voxel_root:1663218006,engine_voxel_save:1188456608,engine_voxel_saved:1817540798,engine_voxel_snapshot:1429701021,engine_voxel_update:1146796223,engine_voxel_write:1689618100,engine_water_params:1417424562,engine_water_sample:1838496316,engine_world_commands:1253502833,engine_world_create:2119516479,engine_world_desc:1977715292,engine_world_destroy:1310935058,engine_world_keyframe_nearest:1753922116,engine_world_keyframe_registers:1225674524,engine_world_keyframe_save:1253737481,engine_world_keyframe_seek:1643050676,engine_world_keyframe_truncate:1606463142,engine_world_keyframes_enable:1684132572,engine_world_registers:1746990265,engine_world_rollback_create:2143032395,engine_world_snapshot_clear:1756211773,engine_world_snapshot_digest:1845126921,engine_world_snapshot_mark:1587420898,engine_world_snapshot_registers:1852029232,engine_world_snapshot_restore:1505099436,engine_world_snapshot_save:1902952349,engine_world_snapshot_track:2039665506,engine_world_snapshot_track_table:2029856278,engine_world_snapshot_untrack:1383225857};var Xl=65536,ku=64,vA=2048;var iB=1<<20,ce=64,Rt=4;var Fp=32,Ww=32,oB=24,sB=25,aB=26,lB=27,cB=28,uB=4294967296,Up=9,Lu=1024,RA=0,dB=3,hB=4,pB=5,mB=6,Kw=7,fB=8,_B=9,yB=0,AB=1,bB=2,gB=3,EB=4,xB=5,vB=6,RB=7,SB=8,TB=9,wB=10,IB=11,OB=0,CB=1,NB=2,kB=3,LB=4,MB=5,DB=1,PB=2,FB=2,UB=5,BB=0,GB=1,VB=2,HB=0,WB=1,KB=2,YB=3,XB=4,qB=5,zB=6,QB=7,$B=8,jB=9,JB=10,ZB=11,e4=12,t4=0,n4=1,r4=4,i4=5,o4=8,Yw=12,s4=0,Bp=1,a4=4,l4=7,c4=11,u4=12,d4=13,h4=14,p4=15,m4=16,f4=17,Mu=18,Du=19,_4=20,y4=21,A4=22,b4=23,Xw=24,g4=1,E4=2,x4=4,qw=65535,v4=0,R4=1,S4=2,T4=3,w4=4,I4=5,ga=0,O4=1,C4=4,zw=7,N4=10,Gp=11,SA=13,k4=14,L4=15,M4=6,D4=7,P4=SA,Qw=7,F4=19,U4=23,B4=27,G4=28,V4=0,H4=1,W4=2,K4=2,Y4=0,X4=1,q4=2,z4=3,Q4=4,$4=5,j4=6,J4=7,Z4=10,eG=2,yo=0,ql=3,TA=6,tG=7,wA=8,$w=9,IA=10,jw=11,zl=12,Ql=15,wr=0,nG=3,Jw=4294967295,rG=1,iG=2,oG=3,sG=4,aG=5,lG=6,cG=7,uG=8,dG=9,hG=10,pG=11,mG=15,fG=20,_G=21,yG=22,AG=18,OA=19,bG=27,gG=27,EG=28,xG=29,vG=12,RG=13,SG=14,TG=0,wG=1,IG=2,Ea=-1,xa=-2,va=-3,Vp=-4,Ao=-5,Zw=1;var CA=1024*1024,OG={low:128*CA,mid:256*CA,high:512*CA};function eI(i){return i===void 0||!Number.isFinite(i)||i<=0?vA:Math.max(ku+1,Math.ceil(i/Xl))}var _=class extends Error{constructor(e,t){super(t),this.name="GameError",this.code=e;}};var $he="__stack_pointer",jhe="__wasm_init_tls",Jhe="__tls_size",Zhe="__tls_align";var CG=1<<20,NG=16,LG=2,epe=15,tpe=1,npe=5e3,rpe=1,MG="env",DG="memory",ipe="function",ope=new Uint8Array([0,97,115,109,1,0,0,0,2,9,1,1,101,1,109,2,3,1,1]);function spe(){if(typeof WebAssembly!="object"||typeof WebAssembly.validate!="function")return false;try{return WebAssembly.validate(ope)}catch{return false}}function PG(i=globalThis){return i.crossOriginIsolated===true&&typeof SharedArrayBuffer=="function"&&typeof Worker=="function"&&typeof Atomics=="object"&&typeof URL.createObjectURL=="function"&&spe()}function FG(i=globalThis){let e=i.navigator?.hardwareConcurrency??0,t=Math.min(epe,e-tpe);return t+1>=LG?t:0}var ape=`"use strict";
5
+ self.onmessage = (event) => {
6
+ const boot = event.data;
7
+ const imports = { ${JSON.stringify(MG)}: { ${JSON.stringify(DG)}: boot.memory } };
8
+ for (const [module, name] of boot.stubs) {
9
+ imports[module] = imports[module] || {};
10
+ imports[module][name] = () => { throw new Error("engine lane " + boot.index + " called the host import " + module + "." + name); };
11
+ }
12
+ WebAssembly.instantiate(boot.module, imports).then((instance) => {
13
+ const exports = instance.exports;
14
+ exports[${JSON.stringify($he)}].value = boot.stack;
15
+ exports[${JSON.stringify(jhe)}](boot.tls);
16
+ self.postMessage(boot.index);
17
+ exports.engine_jobs_worker(boot.index);
18
+ }, (error) => self.postMessage(String(error)));
19
+ };
20
+ `;function lpe(i){let e=[];for(let t of WebAssembly.Module.imports(i))t.kind===ipe&&!(t.module===MG&&t.name===DG)&&e.push([t.module,t.name]);return e}function cpe(i,e){return Math.ceil(i/e)*e}function kG(i){return Number(i.value)}function upe(i){return new Promise(e=>setTimeout(e,i))}var dpe={create:i=>new Worker(i)};async function UG(i,e,t,n,r=dpe){if(n<=0||t.engine_jobs_init(n)<0)return null;let o=Math.max(NG,kG(t[Zhe])),s=cpe(Math.max(kG(t[Jhe]),1),o),a=lpe(i),l=URL.createObjectURL(new Blob([ape],{type:"text/javascript"})),c=[],u=[];try{for(let m=0;m<n;m++){let f=t.engine_alloc(CG,NG),y=t.engine_alloc(s,o);if(f===0||y===0)break;let b=r.create(l);c.push(b),u.push(new Promise(E=>{b.onmessage=R=>E(R.data===m),b.onerror=()=>E(!1);}));let A={module:i,memory:e,index:m,stack:f+CG,tls:y,stubs:a};b.postMessage(A);}let d=(await Promise.all(u)).every(Boolean),h=c.length+1,p=Date.now()+npe;for(;d&&t.engine_jobs_lanes()<h&&Date.now()<p;)await upe(rpe);if(!d||t.engine_jobs_lanes()<LG){t.engine_jobs_shutdown();for(let m of c)m.terminate();return null}}finally{URL.revokeObjectURL(l);}return {lanes:t.engine_jobs_lanes(),terminate(){t.engine_jobs_shutdown();for(let d of c)d.terminate();}}}var hpe={player:1,ios:2,android:3,cli:4};var ppe=["missing","malformed","unknown_key","forged","expired","not_yet_valid","lifetime","audience","origin"],mpe={missing:"no engine session token was given before the engine started",malformed:"the engine session token is malformed",unknown_key:"the engine session token was signed by a key this engine does not trust",forged:"the engine session token signature does not verify",expired:"the engine session token has expired",not_yet_valid:"the engine session token is not valid yet",lifetime:"the engine session token lives longer than its audience allows",audience:"the engine session token was issued for a different host",origin:"the engine session token was issued for a different origin",unknown:"the engine refused to start without a valid session"},fpe=0,_pe=1,NA=1,ype="engine_session_present",Ape="engine_session_status",bpe="engine_session_enforced";function gpe(i){return ppe[-i-1]??"unknown"}var tI=class extends _{constructor(e){let t=gpe(e);super("not_initialized",`the engine did not start: ${mpe[t]}`),this.name="EngineSessionError",this.refusal=t;}};function nI(i,e){let t=i[e];return typeof t=="function"?t:null}function BG(i,e,t=Date.now()){let n=nI(i.symbols,ype);if(n===null)return null;let r=new TextEncoder,o=r.encode(e.token),s=r.encode(e.origin),a=o.length===0?0:i.exports.engine_alloc(o.length,NA),l=s.length===0?0:i.exports.engine_alloc(s.length,NA);try{return a!==0&&new Uint8Array(i.memory.buffer,a,o.length).set(o),l!==0&&new Uint8Array(i.memory.buffer,l,s.length).set(s),n(a,o.length,hpe[e.audience],l,s.length,t)}finally{a!==0&&i.exports.engine_free(a,o.length,NA),l!==0&&i.exports.engine_free(l,s.length,NA);}}function Pu(i){let e=nI(i,bpe),t=nI(i,Ape);if(e===null||t===null||e()!==_pe)return null;let n=t();return n===fpe?null:new tI(n)}function ms(i,e){}var Vn=0,Sa=4294967295,Epe=1,xpe=2,vpe=3,Rpe=8,Spe=64,rI=8,iI=1,oI=1,Tpe=1,wpe=1,Ipe=2,GG=32,VG=1,HG=2,WG=3,Ope=4,Cpe=5,Npe=6,kpe=7,Lpe=8,Mpe=9,Dpe=10,Ppe=11,Fpe=12,Upe=13,Bpe=14,Gpe=15,Vpe=20,Hpe=21,Wpe=22,Kpe=23,Ype=24,Xpe=25,qpe=26,zpe=27,Qpe=28,$pe=1,jpe=2,Jpe=3,Zpe=4,eme=1,tme=2,nme=3,bo=[void 0,"r8unorm","r8snorm","r8uint","r8sint","r16uint","r16sint","r16float","rg8unorm","rg8snorm","rg8uint","rg8sint","r32uint","r32sint","r32float","rg16uint","rg16sint","rg16float","rgba8unorm","rgba8unorm-srgb","rgba8snorm","rgba8uint","rgba8sint","bgra8unorm","bgra8unorm-srgb","rgb9e5ufloat","rgb10a2uint","rgb10a2unorm","rg11b10ufloat","rg32uint","rg32sint","rg32float","rgba16uint","rgba16sint","rgba16float","rgba32uint","rgba32sint","rgba32float","stencil8","depth16unorm","depth24plus","depth24plus-stencil8","depth32float","depth32float-stencil8","bc7-rgba-unorm","bc7-rgba-unorm-srgb","etc2-rgba8unorm","etc2-rgba8unorm-srgb","astc-4x4-unorm","astc-4x4-unorm-srgb","bc1-rgba-unorm","bc1-rgba-unorm-srgb","bc3-rgba-unorm","bc3-rgba-unorm-srgb","bc4-r-unorm","bc5-rg-unorm","bc6h-rgb-ufloat","etc2-rgb8unorm","etc2-rgb8unorm-srgb"],rme=[void 0,"uint8x2","uint8x4","sint8x2","sint8x4","unorm8x2","unorm8x4","snorm8x2","snorm8x4","uint16x2","uint16x4","sint16x2","sint16x4","unorm16x2","unorm16x4","snorm16x2","snorm16x4","float16x2","float16x4","float32","float32x2","float32x3","float32x4","uint32","uint32x2","uint32x3","uint32x4","sint32","sint32x2","sint32x3","sint32x4","unorm10-10-10-2","uint8","sint8","unorm8","snorm8","uint16","sint16","unorm16","snorm16","float16","unorm8x4-bgra"],sI=[void 0,"never","less","equal","less-equal","greater","not-equal","greater-equal","always"],aI=["keep","keep","zero","replace","invert","increment-clamp","decrement-clamp","increment-wrap","decrement-wrap"],LA=["zero","zero","one","src","one-minus-src","src-alpha","one-minus-src-alpha","dst","one-minus-dst","dst-alpha","one-minus-dst-alpha","src-alpha-saturated","constant","one-minus-constant","src1","one-minus-src1","src1-alpha","one-minus-src1-alpha"],KG=["add","add","subtract","reverse-subtract","min","max"],lI=["clamp-to-edge","clamp-to-edge","repeat","mirror-repeat"],YG=["nearest","nearest","linear"],ime=["nearest","nearest","linear"],ome=["triangle-list","point-list","line-list","line-strip","triangle-list","triangle-strip"],XG=[void 0,"uint16","uint32"],sme=["ccw","ccw","cw"],ame=["none","none","front","back"],lme=["vertex","vertex","instance"],cI=[void 0,"1d","2d","2d-array","cube","cube-array","3d"],cme=["2d","1d","2d","3d"],uI=["all","all","stencil-only","depth-only"],ume=["float","float","unfilterable-float","depth","sint","uint"],dme=["write-only","write-only","read-only","read-write"],hme=["uniform","uniform","storage","read-only-storage"],pme=["filtering","filtering","non-filtering","comparison"],$G=1,mme=2,fme=3,_me=["validation","validation","out-of-memory","internal"];function qG(i){let e=i.constructor.name;return e==="GPUOutOfMemoryError"?mme:e==="GPUInternalError"?fme:$G}function zG(){return {view:null,resolveTarget:void 0,loadOp:"clear",storeOp:"store",clearValue:{r:0,g:0,b:0,a:0},depthSlice:void 0}}function QG(){return {querySet:null,beginningOfPassWriteIndex:void 0,endOfPassWriteIndex:void 0}}function Ra(i){return i===Sa?void 0:i}var MA=class{constructor(){this.shaderErrors=[];this.memory=null;this.words=new Uint32Array(0);this.floats=new Float32Array(0);this.signed=new Int32Array(0);this.bytes=new Uint8Array(0);this.target=null;this.callbacks=null;this.objects=[null,null,null];this.free=[];this.released=[];this.pipelines=[];this.submits=[];this.renderPasses=[];this.depth={view:null,depthLoadOp:void 0,depthStoreOp:void 0,depthClearValue:0,depthReadOnly:false,stencilLoadOp:void 0,stencilStoreOp:void 0,stencilClearValue:0,stencilReadOnly:false};this.renderTimestamps=QG();this.computeTimestamps=QG();this.computePass={timestampWrites:void 0};this.origin={x:0,y:0,z:0};this.origin2={x:0,y:0,z:0};this.extent={width:0,height:0,depthOrArrayLayers:0};this.textureCopy={texture:null,mipLevel:0,origin:this.origin,aspect:"all"};this.textureCopy2={texture:null,mipLevel:0,origin:this.origin2,aspect:"all"};this.bufferCopy={buffer:null,offset:0,bytesPerRow:void 0,rowsPerImage:void 0};this.pending=0;this.releasedCount=0;this.cursor=0;this.submissions=0;this.transient=true;this.decoder=new TextDecoder;this.encoder=new TextEncoder;this.scopes=0;this.onUncaptured=e=>{let t=e.error;this.report(qG(t),t.message);};this.externalSource={source:null,flipY:false};this.externalTarget={texture:null,mipLevel:0,origin:this.origin,colorSpace:"srgb",premultipliedAlpha:false};this.externalSize={width:0,height:0,depthOrArrayLayers:1};this.blend={r:0,g:0,b:0,a:0};this.pendingBuffers=new Array(rI).fill(null);for(let e=0;e<=Rpe;e++){let t=[];for(let n=0;n<e;n++)t.push(zG());this.renderPasses.push({colorAttachments:t,depthStencilAttachment:void 0,timestampWrites:void 0});}for(let e=0;e<=rI;e++){let t=[];for(let n=0;n<e;n++)t.push(null);this.submits.push(t);}this.imports={gpu_shader:(e,t)=>this.shader(e,t),gpu_bind_group_layout:(e,t)=>(this.bindGroupLayout(e,t)),gpu_pipeline_layout:(e,t)=>(this.pipelineLayout(e,t)),gpu_bind_group:(e,t)=>(this.bindGroup(e,t)),gpu_render_pipeline:(e,t)=>(this.renderPipeline(e,t)),gpu_compute_pipeline:(e,t)=>(this.computePipeline(e,t)),gpu_pipeline_group_layout:(e,t)=>this.groupLayout(e,t),gpu_buffer:(e,t,n)=>this.buffer(e,t,n),gpu_texture:(e,t)=>(this.texture(e,t)),gpu_view:(e,t,n)=>(this.view(e,t,n)),gpu_sampler:(e,t)=>(this.sampler(e,t)),gpu_query_set:(e,t)=>this.querySet(e,t),gpu_release:e=>this.release(e),gpu_destroy:e=>this.destroy(e),gpu_write_buffer:(e,t,n,r)=>this.writeBuffer(e,t,n,r),gpu_write_texture:(e,t,n,r)=>(this.writeTexture(e,t,n,r)),gpu_execute:(e,t)=>(this.execute(e,t)),gpu_submit:()=>this.submit(),gpu_configure:(e,t)=>(this.configure(e,t)),gpu_current_texture:()=>this.currentTexture(),gpu_map:(e,t,n,r,o)=>this.map(e,t,n,r,o),gpu_read_mapped:(e,t,n,r)=>this.readMapped(e,t,n,r),gpu_write_mapped:(e,t,n,r)=>(this.writeMapped(e,t,n,r)),gpu_unmap:e=>this.unmap(e),gpu_push_error_scope:e=>this.pushErrorScope(e),gpu_pop_error_scope:()=>this.popErrorScope()};}report(e,t){let n=this.callbacks;if(n===null)return;let r=this.encoder.encode(t),o=n.errorBuffer(r.byteLength);this.refresh(),this.bytes.set(r,o),n.error(e,r.byteLength);}pushErrorScope(e){return this.device.pushErrorScope(_me[e]??"validation"),this.scopes++}popErrorScope(){this.scopes--,this.device.popErrorScope().then(e=>{e!==null&&this.report(qG(e),e.message);},()=>{});}bindMemory(e,t){this.memory=e,this.callbacks=t,this.refresh();}bindTarget(e){this.target?.device!==e.device&&(this.target?.device.removeEventListener("uncapturederror",this.onUncaptured),e.device.addEventListener("uncapturederror",this.onUncaptured)),this.target=e;let t=globalThis.GPUTextureUsage;this.transient=t?.TRANSIENT_ATTACHMENT===GG;}unbind(){this.target?.device.removeEventListener("uncapturederror",this.onUncaptured),this.target=null;}refresh(){let e=this.memory.buffer;this.words.buffer!==e&&(this.words=new Uint32Array(e),this.floats=new Float32Array(e),this.signed=new Int32Array(e),this.bytes=new Uint8Array(e));}get device(){if(this.target===null)throw new Error("the engine drew before its WebGPU surface was attached");return this.target.device}copyExternalImage(e,t,n,r){let o=this.objects[e];if(this.target===null||o===null||o===void 0||!("createView"in o))return false;let s=o;return this.origin.x=0,this.origin.y=0,this.origin.z=0,this.externalSource.source=t,this.externalTarget.texture=s,this.externalSize.width=Math.min(n,s.width),this.externalSize.height=Math.min(r,s.height),this.device.queue.copyExternalImageToTexture(this.externalSource,this.externalTarget,this.externalSize),this.externalSource.source=null,true}store(e){let t=this.free.pop();return t!==void 0?(this.objects[t]=e,t):(this.objects.push(e),this.objects.length-1)}text(e,t){return this.decoder.decode(this.bytes.subarray(e,e+t))}entry(e){let t=this.words[e];return t===Vn?void 0:this.text(t,this.words[e+1])}constants(e,t){let n=this.words,r=n[e++];if(r===0)return e;let o={};for(let s=0;s<r;s++)o[this.text(n[e],n[e+1])]=this.floats[e+2],e+=3;return t.constants=o,e}shader(e,t){this.refresh();let n=this.device.createShaderModule({code:this.text(e,t)});return typeof n.getCompilationInfo=="function"&&n.getCompilationInfo().then(r=>{for(let o of r.messages)o.type!=="error"||this.shaderErrors.length>=Spe||this.shaderErrors.push(`${o.lineNum}:${o.linePos} ${o.message}`);}),this.store(n)}bindGroupLayout(e,t){this.refresh();let n=this.words,r=e>>>2,o=n[r++],s=[];for(let a=0;a<o;a++){let l=n[r],c=n[r+1],u=n[r+2],d=n[r+3],h=n[r+4],p=n[r+5];r+=6,u===$pe?s.push({binding:l,visibility:c,buffer:{type:hme[d],hasDynamicOffset:h!==0,minBindingSize:p}}):u===jpe?s.push({binding:l,visibility:c,sampler:{type:pme[d]}}):u===Jpe?s.push({binding:l,visibility:c,texture:{sampleType:ume[d],viewDimension:cI[h],multisampled:p!==0}}):u===Zpe&&s.push({binding:l,visibility:c,storageTexture:{access:dme[d],format:bo[h],viewDimension:cI[p]}});}return this.store(this.device.createBindGroupLayout({entries:s}))}pipelineLayout(e,t){this.refresh();let n=this.words,r=e>>>2,o=n[r++],s=[];for(let a=0;a<o;a++)s.push(this.objects[n[r+a]]);return this.store(this.device.createPipelineLayout({bindGroupLayouts:s}))}bindGroup(e,t){this.refresh();let n=this.words,r=e>>>2,o=this.objects[n[r++]],s=n[r++],a=[];for(let l=0;l<s;l++){let c=n[r],u=n[r+1],d=n[r+2],h=n[r+3],p=n[r+4];r+=5,u===eme?a.push({binding:c,resource:{buffer:this.objects[d],offset:h,size:Ra(p)}}):u===tme?a.push({binding:c,resource:this.objects[d]}):u===nme&&a.push({binding:c,resource:this.objects[d]});}return this.store(this.device.createBindGroup({layout:o,entries:a}))}layout(e){return e===Vn?"auto":this.objects[e]}renderDescriptor(e){let t=this.words,n=this.floats,r=this.entry(e>>>2),o=(e>>>2)+2,s=this.layout(t[o++]),l={module:this.objects[t[o++]],entryPoint:this.entry(o),buffers:[]};o=this.constants(o+2,l);let c=t[o++],u=[];for(let y=0;y<c;y++){let b=t[o];if(b===Sa){u.push(null),o+=1;continue}let A=lme[t[o+1]],E=t[o+2];o+=3;let R=[];for(let g=0;g<E;g++)R.push({format:rme[t[o]],offset:t[o+1],shaderLocation:t[o+2]}),o+=3;u.push({arrayStride:b,stepMode:A,attributes:R});}l.buffers=u;let d=XG[t[o+1]],h={topology:ome[t[o]],frontFace:sme[t[o+2]],cullMode:ame[t[o+3]],unclippedDepth:t[o+4]!==0};d!==void 0&&(h.stripIndexFormat=d),o+=5;let p={layout:s,vertex:l,primitive:h};r!==void 0&&(p.label=r);let m=t[o++];if(m!==Vn){let y=t[o],b=sI[t[o+1]];o+=2;let A=()=>{let v={compare:sI[t[o]],failOp:aI[t[o+1]],depthFailOp:aI[t[o+2]],passOp:aI[t[o+3]]};return o+=4,v},E=A(),R=A(),g={format:bo[m],stencilFront:E,stencilBack:R,stencilReadMask:t[o],stencilWriteMask:t[o+1],depthBias:this.signed[o+2],depthBiasSlopeScale:n[o+3],depthBiasClamp:n[o+4]};y!==Vn&&(g.depthWriteEnabled=y===2),b!==void 0&&(g.depthCompare=b),o+=5,p.depthStencil=g;}p.multisample={count:t[o],mask:t[o+1],alphaToCoverageEnabled:t[o+2]!==0},o+=3;let f=t[o++];if(f!==Vn){let y={module:this.objects[f],entryPoint:this.entry(o),targets:[]};o=this.constants(o+2,y);let b=t[o++],A=[];for(let E=0;E<b;E++){let R=t[o++];if(R===Vn){A.push(null);continue}let g={format:bo[R]};t[o++]!==Vn&&(g.blend={color:{srcFactor:LA[t[o]],dstFactor:LA[t[o+1]],operation:KG[t[o+2]]},alpha:{srcFactor:LA[t[o+3]],dstFactor:LA[t[o+4]],operation:KG[t[o+5]]}},o+=6),g.writeMask=t[o++],A.push(g);}y.targets=A,p.fragment=y;}return p}track(e,t,n){n.then(r=>{this.objects[e]!==null||this.pipelines[e]!==t||(this.objects[e]=r,this.pipelines[e]=void 0);},r=>this.report($G,`${t.label??"pipeline"}: ${r.message}`));}renderPipeline(e,t){this.refresh();let n=this.renderDescriptor(e),r=this.store(null);return this.pipelines[r]=n,this.track(r,n,this.device.createRenderPipelineAsync(n)),r}computePipeline(e,t){this.refresh();let n=this.words,r=this.entry(e>>>2),o=(e>>>2)+2,s={module:this.objects[n[o+1]],entryPoint:this.entry(o+2)};this.constants(o+4,s);let a={layout:this.layout(n[o]),compute:s};r!==void 0&&(a.label=r);let l=this.store(null);return this.pipelines[l]=a,this.track(l,a,this.device.createComputePipelineAsync(a)),l}force(e){let t=this.pipelines[e];if(t===void 0)throw new Error(`engine pipeline ${e} does not exist`);this.pipelines[e]=void 0;let n="vertex"in t?this.device.createRenderPipeline(t):this.device.createComputePipeline(t);return this.objects[e]=n,n}pipeline(e){let t=this.objects[e];return t===null?this.force(e):t}groupLayout(e,t){return this.store(this.pipeline(e).getBindGroupLayout(t))}buffer(e,t,n){return this.store(this.device.createBuffer({size:e,usage:t,mappedAtCreation:n!==0}))}texture(e,t){this.refresh();let n=this.words,r=e>>>2,o=[];for(let a=0;a<n[r+8];a++)o.push(bo[n[r+9+a]]);let s=this.transient?n[r+7]:n[r+7]&~GG;return this.store(this.device.createTexture({size:{width:n[r],height:n[r+1],depthOrArrayLayers:n[r+2]},mipLevelCount:n[r+3],sampleCount:n[r+4],dimension:cme[n[r+5]],format:bo[n[r+6]],usage:s,viewFormats:o}))}view(e,t,n){this.refresh();let r=this.words,o=t>>>2,s={aspect:uI[r[o+2]],baseMipLevel:r[o+3],baseArrayLayer:r[o+5]},a=bo[r[o]],l=cI[r[o+1]];return a!==void 0&&(s.format=a),l!==void 0&&(s.dimension=l),r[o+4]!==Sa&&(s.mipLevelCount=r[o+4]),r[o+6]!==Sa&&(s.arrayLayerCount=r[o+6]),this.store(this.objects[e].createView(s))}sampler(e,t){this.refresh();let n=this.words,r=e>>>2,o={addressModeU:lI[n[r]],addressModeV:lI[n[r+1]],addressModeW:lI[n[r+2]],magFilter:YG[n[r+3]],minFilter:YG[n[r+4]],mipmapFilter:ime[n[r+5]],lodMinClamp:this.floats[r+6],lodMaxClamp:this.floats[r+7],maxAnisotropy:Math.max(1,n[r+9])},s=sI[n[r+8]];return s!==void 0&&(o.compare=s),this.store(this.device.createSampler(o))}querySet(e,t){return this.store(this.device.createQuerySet({type:e===1?"occlusion":"timestamp",count:t}))}release(e){e<vpe||(this.releasedCount===this.released.length?this.released.push(e):this.released[this.releasedCount]=e,this.releasedCount++);}destroy(e){this.objects[e]?.destroy?.();}writeBuffer(e,t,n,r){this.refresh(),this.device.queue.writeBuffer(this.objects[e],t,this.words.buffer,n,r);}writeTexture(e,t,n,r){this.refresh();let o=this.words,s=e>>>2,a=Ra(o[s+7]),l=Ra(o[s+8]);this.device.queue.writeTexture({texture:this.objects[o[s]],mipLevel:o[s+1],origin:{x:o[s+2],y:o[s+3],z:o[s+4]},aspect:uI[o[s+5]]},this.bytes.subarray(n,n+r),{offset:o[s+6],bytesPerRow:a,rowsPerImage:l},{width:o[s+9],height:o[s+10],depthOrArrayLayers:o[s+11]});}configure(e,t){this.refresh();let n=this.target;if(n===null)return;let r=this.words,o=e>>>2,s=[];for(let a=0;a<r[o+5];a++)s.push(bo[r[o+6+a]]);n.canvas.width=r[o+2],n.canvas.height=r[o+3],n.context.configure({device:n.device,format:bo[r[o]],usage:r[o+1],alphaMode:r[o+4]!==0?"premultiplied":"opaque",viewFormats:s});}currentTexture(){let e=this.target;if(e===null)return 0;let t=e.context.getCurrentTexture();return this.objects[Epe]=t,this.objects[xpe]=t,1}map(e,t,n,r,o){let s=this.callbacks;this.objects[e].mapAsync(t===Tpe?wpe:Ipe,n,r).then(()=>s.mapped(o,1),()=>s.mapped(o,0));}readMapped(e,t,n,r){this.refresh(),this.bytes.set(new Uint8Array(this.objects[e].getMappedRange(t,n)),r);}writeMapped(e,t,n,r){this.refresh(),new Uint8Array(this.objects[e].getMappedRange(t,n)).set(this.bytes.subarray(r,r+n));}unmap(e){let t=this.objects[e];t.mapState!=="unmapped"&&t.unmap();}timestamps(e,t){let n=this.words;if(n[t]!==Vn)return e.querySet=this.objects[n[t]],e.beginningOfPassWriteIndex=Ra(n[t+1]),e.endOfPassWriteIndex=Ra(n[t+2]),e}beginRender(e,t){let n=this.words,r=this.floats,o=this.objects,s=n[t++],a=this.renderPasses[s],l=a.colorAttachments;for(let u=0;u<s;u++){let d=n[t];if(d===Vn){l[u]=null,t+=1;continue}let h=l[u]??=zG();h.view=o[d];let p=n[t+1];h.resolveTarget=p===Vn?void 0:o[p],h.loadOp=n[t+2]===iI?"clear":"load",h.storeOp=n[t+3]===oI?"store":"discard";let m=h.clearValue;m.r=r[t+4],m.g=r[t+5],m.b=r[t+6],m.a=r[t+7],h.depthSlice=Ra(n[t+8]),t+=9;}let c=n[t++];if(c===Vn)a.depthStencilAttachment=void 0;else {let u=this.depth;u.view=o[c];let d=n[t];u.depthLoadOp=d===Vn?void 0:d===iI?"clear":"load",u.depthStoreOp=d===Vn?void 0:n[t+1]===oI?"store":"discard",u.depthReadOnly=d===Vn,u.depthClearValue=r[t+2];let h=n[t+3];u.stencilLoadOp=h===Vn?void 0:h===iI?"clear":"load",u.stencilStoreOp=h===Vn?void 0:n[t+4]===oI?"store":"discard",u.stencilClearValue=n[t+5],t+=6,a.depthStencilAttachment=u;}return a.timestampWrites=this.timestamps(this.renderTimestamps,t),this.cursor=t+3,e.beginRenderPass(a)}runRender(e,t){let n=this.words,r=this.floats,o=this.objects;for(;;){let s=n[t++];switch(s){case VG:return e.end(),t;case HG:e.setPipeline(this.pipeline(n[t])),t+=1;break;case WG:{let a=n[t+2];a===0?e.setBindGroup(n[t],o[n[t+1]]):e.setBindGroup(n[t],o[n[t+1]],n,t+3,a),t+=3+a;break}case Ope:{let a=n[t+3];a===Sa?e.setVertexBuffer(n[t],o[n[t+1]],n[t+2]):e.setVertexBuffer(n[t],o[n[t+1]],n[t+2],a),t+=4;break}case Cpe:{let a=n[t+3],l=XG[n[t+1]];a===Sa?e.setIndexBuffer(o[n[t]],l,n[t+2]):e.setIndexBuffer(o[n[t]],l,n[t+2],a),t+=4;break}case Npe:e.draw(n[t],n[t+1],n[t+2],n[t+3]),t+=4;break;case kpe:e.drawIndexed(n[t],n[t+1],n[t+2],this.signed[t+3],n[t+4]),t+=5;break;case Lpe:e.drawIndirect(o[n[t]],n[t+1]),t+=2;break;case Mpe:e.drawIndexedIndirect(o[n[t]],n[t+1]),t+=2;break;case Dpe:e.setViewport(r[t],r[t+1],r[t+2],r[t+3],r[t+4],r[t+5]),t+=6;break;case Ppe:e.setScissorRect(n[t],n[t+1],n[t+2],n[t+3]),t+=4;break;case Fpe:this.blend.r=r[t],this.blend.g=r[t+1],this.blend.b=r[t+2],this.blend.a=r[t+3],e.setBlendConstant(this.blend),t+=4;break;case Upe:e.setStencilReference(n[t]),t+=1;break;default:throw new Error(`engine render pass op ${s} is unknown`)}}}runCompute(e,t){let n=this.words,r=this.objects;for(;;){let o=n[t++];switch(o){case VG:return e.end(),t;case HG:e.setPipeline(this.pipeline(n[t])),t+=1;break;case WG:{let s=n[t+2];s===0?e.setBindGroup(n[t],r[n[t+1]]):e.setBindGroup(n[t],r[n[t+1]],n,t+3,s),t+=3+s;break}case Bpe:e.dispatchWorkgroups(n[t],n[t+1],n[t+2]),t+=3;break;case Gpe:e.dispatchWorkgroupsIndirect(r[n[t]],n[t+1]),t+=2;break;default:throw new Error(`engine compute pass op ${o} is unknown`)}}}texelTexture(e,t){let n=this.words;return e.texture=this.objects[n[t]],e.mipLevel=n[t+1],e.origin.x=n[t+2],e.origin.y=n[t+3],e.origin.z=n[t+4],e.aspect=uI[n[t+5]],t+6}texelBuffer(e){let t=this.words,n=this.bufferCopy;return n.buffer=this.objects[t[e]],n.offset=t[e+1],n.bytesPerRow=Ra(t[e+2]),n.rowsPerImage=Ra(t[e+3]),e+4}texelExtent(e){let t=this.words;return this.extent.width=t[e],this.extent.height=t[e+1],this.extent.depthOrArrayLayers=t[e+2],e+3}execute(e,t){this.refresh();let n=this.words,r=this.objects,o=this.device.createCommandEncoder(),s=e>>>2,a=s+t;for(;s<a;){let l=n[s++];switch(l){case Vpe:{let c=this.beginRender(o,s);s=this.runRender(c,this.cursor);break}case Hpe:{this.computePass.timestampWrites=this.timestamps(this.computeTimestamps,s),s=this.runCompute(o.beginComputePass(this.computePass),s+3);break}case Wpe:{let c=n[s+4],u=r[n[s]],d=r[n[s+2]];c===Sa?o.copyBufferToBuffer(u,n[s+1],d,n[s+3]):o.copyBufferToBuffer(u,n[s+1],d,n[s+3],c),s+=5;break}case Kpe:s=this.texelExtent(this.texelTexture(this.textureCopy,this.texelBuffer(s))),o.copyBufferToTexture(this.bufferCopy,this.textureCopy,this.extent);break;case Ype:s=this.texelExtent(this.texelBuffer(this.texelTexture(this.textureCopy,s))),o.copyTextureToBuffer(this.textureCopy,this.bufferCopy,this.extent);break;case Xpe:s=this.texelExtent(this.texelTexture(this.textureCopy2,this.texelTexture(this.textureCopy,s))),o.copyTextureToTexture(this.textureCopy,this.textureCopy2,this.extent);break;case qpe:{let c=n[s+2];c===Sa?o.clearBuffer(r[n[s]],n[s+1]):o.clearBuffer(r[n[s]],n[s+1],c),s+=3;break}case zpe:o.resolveQuerySet(r[n[s]],n[s+1],n[s+2],r[n[s+3]],n[s+4]),s+=5;break;case Qpe:s+=2;break;default:throw new Error(`engine command op ${l} is unknown`)}}if(this.pending===rI)throw new Error("the engine submitted too many command buffers in one batch");this.pendingBuffers[this.pending++]=o.finish();}submit(){let e=this.pending;if(e>0){let n=this.submits[e],r=this.pendingBuffers;for(let o=0;o<e;o++)n[o]=r[o],r[o]=null;this.device.queue.submit(n);for(let o=0;o<e;o++)n[o]=null;this.pending=0;}let t=this.released;for(let n=0;n<this.releasedCount;n++){let r=t[n];this.objects[r]=null,this.pipelines[r]=void 0,this.free.push(r);}return this.releasedCount=0,++this.submissions}};var yme=1,Ame=2,bme=3,gme=4,Eme=5,xme=6,vme=7,Rme=8,Sme=9,Tme=10,wme=11,Ime=12,Ome=13,Cme=14,Nme=15,kme=16,Lme=17,Mme=18,Dme=19,Pme=20,Fme=21,Ume=22,Bme=23,Gme=24,Vme=25,Hme=26,Wme=27,Kme=28,Yme=29,Xme=30,qme=31,zme=32;var Qme=1,$me=2,jme=2,Jme=3,Zme=4,dI=0,efe=1,jG=16,tfe=8,nfe=27,rfe=9,JG=6,ife=6,ofe=1,sfe=0,afe=1,hI=0,ZG=1,lfe=2,cfe=1,ufe=2,dfe=4,hfe=8,pfe=0,e6=2,mfe=1,t6=0,ffe=1,n6=1,pI=0,r6=15,Hp=16,cr=4,Wp=2,Ta=4,_fe=16,yfe="naga_vs_first_instance",Afe="EXT_color_buffer_float",bfe="EXT_color_buffer_half_float",gfe="KHR_parallel_shader_compile",Efe=16,o6="cimplify_gl",PA="engine_render_attach_webgl",xfe=`
21
+ `;function i6(i,e){if(e.length===0)return i;let t=i.indexOf(xfe);return i.slice(0,t+1)+e+i.slice(t+1)}var DA=class{constructor(){this.errors=[];this.gl=null;this.memory=null;this.buffer=null;this.words=new Uint32Array(0);this.floats=new Float32Array(0);this.bytes=new Uint8Array(0);this.halves=new Uint16Array(0);this.singles=new Float32Array(0);this.programs=[];this.textures=[];this.blocks=[];this.blockSizes=[];this.formats=[];this.current=null;this.targetHeight=0;this.readsCanvas=true;this.lastOp=0;this.checked=false;this.salt=null;this.compileMs=[];this.fallback=null;this.sampler=null;this.row=new Uint8Array(0);this.decoder=new TextDecoder;this.signed=new Int8Array(0);this.blendFactors=[];this.blendOps=[];this.compares=[];this.stencilOps=[];this.attributeTypes=[];this.vertexArray=null;this.buffers=[];this.samplers=[];this.passes=[];this.drawBuffers=[];this.clearColor=new Float32Array(4);this.clearDepth=new Float32Array(1);this.clearStencil=new Int32Array(1);this.indexType=0;this.stencilFront=[0,0,255];this.stencilBack=[0,0,255];this.stencilReference=0;this.enabledAttributes=0;this.imports={gl_execute:(e,t)=>this.execute(e,t)};}bindMemory(e){this.memory=e,this.buffer=null;}bindContext(e){if(e.getExtension(gfe),!(e.getExtension(Afe)!==null||e.getExtension(bfe)!==null))return false;this.gl=e,this.formats=[{internal:0,format:0,type:0,bytes:0},{internal:e.RGBA8,format:e.RGBA,type:e.UNSIGNED_BYTE,bytes:Ta},{internal:e.SRGB8_ALPHA8,format:e.RGBA,type:e.UNSIGNED_BYTE,bytes:Ta},{internal:e.RGBA16F,format:e.RGBA,type:e.HALF_FLOAT,bytes:Ta*Wp},{internal:e.RGBA32UI,format:e.RGBA_INTEGER,type:e.UNSIGNED_INT,bytes:Ta*cr},{internal:e.R8,format:e.RED,type:e.UNSIGNED_BYTE,bytes:1},{internal:e.RG8,format:e.RG,type:e.UNSIGNED_BYTE,bytes:2},{internal:e.R16F,format:e.RED,type:e.HALF_FLOAT,bytes:Wp},{internal:e.RGBA32F,format:e.RGBA,type:e.FLOAT,bytes:Ta*cr},{internal:e.RG16F,format:e.RG,type:e.HALF_FLOAT,bytes:2*Wp},{internal:e.RG32F,format:e.RG,type:e.FLOAT,bytes:2*cr},{internal:e.R32F,format:e.RED,type:e.FLOAT,bytes:cr},{internal:e.RGB10_A2,format:e.RGBA,type:e.UNSIGNED_INT_2_10_10_10_REV,bytes:cr},{internal:e.R11F_G11F_B10F,format:e.RGB,type:e.UNSIGNED_INT_10F_11F_11F_REV,bytes:cr},{internal:e.DEPTH_COMPONENT16,format:e.DEPTH_COMPONENT,type:e.UNSIGNED_SHORT,bytes:Wp},{internal:e.DEPTH24_STENCIL8,format:e.DEPTH_STENCIL,type:e.UNSIGNED_INT_24_8,bytes:cr},{internal:e.DEPTH_COMPONENT32F,format:e.DEPTH_COMPONENT,type:e.FLOAT,bytes:cr},{internal:e.DEPTH32F_STENCIL8,format:e.DEPTH_STENCIL,type:e.FLOAT_32_UNSIGNED_INT_24_8_REV,bytes:2*cr},{internal:e.RGBA8_SNORM,format:e.RGBA,type:e.BYTE,bytes:Ta}],this.blendFactors=[e.ZERO,e.ONE,e.SRC_COLOR,e.ONE_MINUS_SRC_COLOR,e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA,e.DST_COLOR,e.ONE_MINUS_DST_COLOR,e.DST_ALPHA,e.ONE_MINUS_DST_ALPHA,e.SRC_ALPHA_SATURATE,e.CONSTANT_COLOR,e.ONE_MINUS_CONSTANT_COLOR],this.blendOps=[e.FUNC_ADD,e.FUNC_SUBTRACT,e.FUNC_REVERSE_SUBTRACT,e.MIN,e.MAX],this.compares=[e.NEVER,e.LESS,e.EQUAL,e.LEQUAL,e.GREATER,e.NOTEQUAL,e.GEQUAL,e.ALWAYS],this.stencilOps=[e.KEEP,e.ZERO,e.REPLACE,e.INCR,e.DECR,e.INVERT,e.INCR_WRAP,e.DECR_WRAP],this.attributeTypes=[e.FLOAT,e.UNSIGNED_BYTE,e.BYTE,e.UNSIGNED_SHORT,e.SHORT,e.HALF_FLOAT,e.UNSIGNED_INT],this.vertexArray=e.createVertexArray(),e.bindVertexArray(this.vertexArray);let n=e.createTexture();e.activeTexture(e.TEXTURE0+Hp),e.bindTexture(e.TEXTURE_2D,n),e.texStorage2D(e.TEXTURE_2D,1,e.RGBA8,1,1),e.texSubImage2D(e.TEXTURE_2D,0,0,0,1,1,e.RGBA,e.UNSIGNED_BYTE,new Uint8Array(Ta)),this.fallback=n;let r=e.createSampler();e.samplerParameteri(r,e.TEXTURE_MIN_FILTER,e.LINEAR_MIPMAP_LINEAR),e.samplerParameteri(r,e.TEXTURE_MAG_FILTER,e.LINEAR),e.samplerParameteri(r,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.samplerParameteri(r,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE);for(let o=0;o<r6;o++)e.bindSampler(o,r);return this.sampler=r,e.pixelStorei(e.UNPACK_ALIGNMENT,1),e.pixelStorei(e.PACK_ALIGNMENT,1),true}unbind(){let e=this.gl;if(e!==null){for(let t of this.textures)t!==void 0&&(e.deleteTexture(t.texture),t.framebuffer!==null&&e.deleteFramebuffer(t.framebuffer));for(let t of this.programs)t!==void 0&&e.deleteProgram(t.program);for(let t of this.blocks)t!==void 0&&e.deleteBuffer(t);this.fallback!==null&&e.deleteTexture(this.fallback),this.sampler!==null&&e.deleteSampler(this.sampler);}this.textures.length=0,this.programs.length=0,this.blocks.length=0,this.blockSizes.length=0,this.current=null,this.gl=null;}views(){let e=this.memory;if(e===null||e.buffer===this.buffer)return;let t=e.buffer;this.buffer=t,this.words=new Uint32Array(t),this.floats=new Float32Array(t),this.bytes=new Uint8Array(t),this.halves=new Uint16Array(t),this.singles=new Float32Array(t),this.signed=new Int8Array(t);}fail(e){this.errors.length<Efe&&this.errors.push(e);}text(e,t){let n=this.bytes.subarray(e,e+t);return this.decoder.decode(n.buffer instanceof ArrayBuffer?n:n.slice())}shader(e,t,n){let r=e.createShader(t);return r===null?null:(e.shaderSource(r,n),e.compileShader(r),e.getShaderParameter(r,e.COMPILE_STATUS)?r:(this.fail(`shader: ${e.getShaderInfoLog(r)??""}`),e.deleteShader(r),null))}program(e,t){let n=this.words,r=n[t+1],o=this.text(n[t+2],n[t+3]),s=this.text(n[t+4],n[t+5]),a=t+6,l=n[a++],c=[];for(let b=0;b<l;b++,a+=3)c.push([this.text(n[a],n[a+1]),n[a+2]]);let u=n[a++],d=[];for(let b=0;b<u;b++,a+=3)d.push([this.text(n[a],n[a+1]),n[a+2]]);let h=performance.now(),p=this.salt===null?"":`
22
+ const uint SALT_${this.salt} = 0u;
23
+ `,m=this.shader(e,e.VERTEX_SHADER,i6(o,p)),f=this.shader(e,e.FRAGMENT_SHADER,i6(s,p)),y=e.createProgram();if(m!==null&&f!==null&&y!==null){e.attachShader(y,m),e.attachShader(y,f),e.linkProgram(y),e.deleteShader(m),e.deleteShader(f);let b={id:r,program:y,firstInstance:null,pending:{blocks:c,samplers:d,started:h}};this.programs[r]=b;}return a}ready(e,t){let n=t.pending;if(n===null)return true;t.pending=null;let r=t.program;if(!e.getProgramParameter(r,e.LINK_STATUS))return this.fail(`program ${t.id}: ${e.getProgramInfoLog(r)??""}`),this.programs[t.id]=void 0,false;for(let[o,s]of n.blocks){let a=e.getUniformBlockIndex(r,o);a!==e.INVALID_INDEX&&e.uniformBlockBinding(r,a,s);}e.useProgram(r);for(let[o,s]of n.samplers){let a=e.getUniformLocation(r,o);a!==null&&e.uniform1i(a,s);}return t.firstInstance=e.getUniformLocation(r,yfe),this.compileMs.push(performance.now()-n.started),this.current!==null&&this.current!==t&&e.useProgram(this.current.program),true}texture(e,t){let n=this.words,r=n[t+1],o=n[t+2],s=n[t+3],a=this.formats[n[t+4]],l=n[t+5];if(this.deleteTexture(e,r),a===void 0||a.internal===0)return;let c=e.createTexture();if(c===null)return;let u=l===e6?Math.floor(Math.log2(Math.max(o,s)))+1:Math.max(1,n[t+6]);e.activeTexture(e.TEXTURE0+Hp),e.bindTexture(e.TEXTURE_2D,c),e.texStorage2D(e.TEXTURE_2D,u,a.internal,o,s);let d=l===pfe;e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,d?e.NEAREST:l===e6?e.LINEAR_MIPMAP_LINEAR:e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,d?e.NEAREST:e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),this.textures[r]={texture:c,format:a,framebuffer:null};}deleteTexture(e,t){let n=this.textures[t];if(n!==void 0){e.deleteTexture(n.texture),n.framebuffer!==null&&e.deleteFramebuffer(n.framebuffer),this.textures[t]=void 0;for(let r=this.passes.length-1;r>=0;r--){let o=this.passes[r];o.depth!==t&&!o.colors.includes(t)||(e.deleteFramebuffer(o.framebuffer),this.passes.splice(r,1));}}}upload(e,t){let n=this.words,r=this.textures[n[t+1]];if(r===void 0)return;let o=r.format,s=n[t+6];e.activeTexture(e.TEXTURE0+Hp),e.bindTexture(e.TEXTURE_2D,r.texture),e.pixelStorei(e.UNPACK_ROW_LENGTH,n[t+8]);let a=(n[t+9]&mfe)!==0;e.pixelStorei(e.UNPACK_FLIP_Y_WEBGL,a);let l=n[t+2],c=n[t+3],u=n[t+4],d=n[t+5],h=o.type;ms(s,Math.max(n[t+8],u)*d*_fe),h===e.UNSIGNED_INT||h===e.UNSIGNED_INT_2_10_10_10_REV||h===e.UNSIGNED_INT_10F_11F_11F_REV||h===e.UNSIGNED_INT_24_8?e.texSubImage2D(e.TEXTURE_2D,0,l,c,u,d,o.format,h,this.words,s/cr):h===e.HALF_FLOAT||h===e.UNSIGNED_SHORT?e.texSubImage2D(e.TEXTURE_2D,0,l,c,u,d,o.format,h,this.halves,s/Wp):h===e.FLOAT?e.texSubImage2D(e.TEXTURE_2D,0,l,c,u,d,o.format,h,this.singles,s/cr):h===e.BYTE?e.texSubImage2D(e.TEXTURE_2D,0,l,c,u,d,o.format,h,this.signed,s):h===e.UNSIGNED_BYTE&&e.texSubImage2D(e.TEXTURE_2D,0,l,c,u,d,o.format,h,this.bytes,s),a&&e.pixelStorei(e.UNPACK_FLIP_Y_WEBGL,false),e.pixelStorei(e.UNPACK_ROW_LENGTH,0);}target(e,t){let n=this.words,r=n[t+1],o=n[t+2],s=n[t+3];if(r===t6){e.bindFramebuffer(e.FRAMEBUFFER,null);let a=e.canvas;a.width!==o&&(a.width=o),a.height!==s&&(a.height=s);}else {let a=this.textures[r];if(a===void 0)return;a.framebuffer===null?(a.framebuffer=e.createFramebuffer(),e.bindFramebuffer(e.FRAMEBUFFER,a.framebuffer),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,a.texture,0),e.checkFramebufferStatus(e.FRAMEBUFFER)!==e.FRAMEBUFFER_COMPLETE&&this.fail(`target ${r} is not renderable`)):e.bindFramebuffer(e.FRAMEBUFFER,a.framebuffer);}this.targetHeight=s,this.readsCanvas=r===t6,e.viewport(0,0,o,s);}uniforms(e,t){let n=this.words,r=n[t+1],o=n[t+2],s=o*cr,a=this.blocks[r];return a===void 0&&(a=e.createBuffer(),this.blocks[r]=a,this.blockSizes[r]=0),e.bindBuffer(e.UNIFORM_BUFFER,a),this.blockSizes[r]<s&&(e.bufferData(e.UNIFORM_BUFFER,s,e.DYNAMIC_DRAW),this.blockSizes[r]=s),e.bufferSubData(e.UNIFORM_BUFFER,0,n,t+3,o),e.bindBufferBase(e.UNIFORM_BUFFER,r,a),t+3+o}read(e,t){let n=this.words,r=n[t+1],o=n[t+2],s=n[t+3],a=n[t+4],l=n[t+5],c=s*Ta;if(n[t+6]<c*a)return;if(!this.readsCanvas){e.readPixels(r,o,s,a,e.RGBA,e.UNSIGNED_BYTE,this.bytes,l);return}e.readPixels(r,this.targetHeight-o-a,s,a,e.RGBA,e.UNSIGNED_BYTE,this.bytes,l),this.row.length<c&&(this.row=new Uint8Array(c));let u=this.bytes;for(let d=0,h=a-1;d<h;d++,h--){let p=l+d*c,m=l+h*c;this.row.set(u.subarray(p,p+c)),u.copyWithin(p,m,m+c),u.set(this.row.subarray(0,c),m);}}makeBuffer(e,t){let n=this.words,r=n[t+1],o=this.buffers[r];o!==void 0&&e.deleteBuffer(o);let s=e.createBuffer(),a=n[t+2]===Qme?e.ELEMENT_ARRAY_BUFFER:n[t+2]===$me?e.UNIFORM_BUFFER:e.ARRAY_BUFFER;e.bindBuffer(a,s),e.bufferData(a,n[t+3],e.DYNAMIC_DRAW),this.buffers[r]=s;}makeSampler(e,t){let n=this.words,r=n[t+1],o=this.samplers[r];o!==void 0&&e.deleteSampler(o);let s=e.createSampler(),a=h=>h===ofe,l=a(n[t+4]),c=a(n[t+2])?l?e.LINEAR_MIPMAP_LINEAR:e.LINEAR_MIPMAP_NEAREST:l?e.NEAREST_MIPMAP_LINEAR:e.NEAREST_MIPMAP_NEAREST,u=h=>h===sfe?e.REPEAT:h===afe?e.MIRRORED_REPEAT:e.CLAMP_TO_EDGE;e.samplerParameteri(s,e.TEXTURE_MIN_FILTER,c),e.samplerParameteri(s,e.TEXTURE_MAG_FILTER,a(n[t+3])?e.LINEAR:e.NEAREST),e.samplerParameteri(s,e.TEXTURE_WRAP_S,u(n[t+5])),e.samplerParameteri(s,e.TEXTURE_WRAP_T,u(n[t+6])),n[t+7]!==hI&&(e.samplerParameteri(s,e.TEXTURE_COMPARE_MODE,e.COMPARE_REF_TO_TEXTURE),e.samplerParameteri(s,e.TEXTURE_COMPARE_FUNC,this.compares[n[t+7]-1]??e.ALWAYS));let d=this.floats;e.samplerParameterf(s,e.TEXTURE_MIN_LOD,d[t+8]),e.samplerParameterf(s,e.TEXTURE_MAX_LOD,d[t+9]),this.samplers[r]=s;}framebuffer(e,t,n,r){for(let a of this.passes){if(a.depth!==n||a.colors.length!==t.length)continue;let l=true;for(let c=0;c<t.length;c++)l&&=a.colors[c]===t[c];if(l)return a.framebuffer}let o=e.createFramebuffer();if(o===null)return null;e.bindFramebuffer(e.FRAMEBUFFER,o);for(let a=0;a<t.length;a++){let l=this.textures[t[a]];l!==void 0&&e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0+a,e.TEXTURE_2D,l.texture,0);}let s=n===pI?void 0:this.textures[n];return s!==void 0&&e.framebufferTexture2D(e.FRAMEBUFFER,r?e.DEPTH_STENCIL_ATTACHMENT:e.DEPTH_ATTACHMENT,e.TEXTURE_2D,s.texture,0),e.checkFramebufferStatus(e.FRAMEBUFFER)!==e.FRAMEBUFFER_COMPLETE&&this.fail("script pass is not renderable"),this.passes.push({colors:[...t],depth:n,framebuffer:o}),o}pass(e,t){let n=this.words,r=Math.min(n[t+1],tfe),o=t+2,s=[],a=o;for(let m=0;m<r;m++,o+=JG)s.push(n[o]);let l=n[o],c=n[o+1]!==0,u=o;o+=ife;let d=n[o],h=n[o+1];for(o+=2,e.bindFramebuffer(e.FRAMEBUFFER,this.framebuffer(e,s,l,c));this.drawBuffers.length<=r;){let m=[];for(let f=0;f<this.drawBuffers.length;f++)m.push(e.COLOR_ATTACHMENT0+f);this.drawBuffers.push(m);}e.drawBuffers(this.drawBuffers[r]),e.viewport(0,0,d,h),e.depthRange(0,1),e.disable(e.SCISSOR_TEST),e.colorMask(true,true,true,true),e.depthMask(true),e.stencilMask(255),this.targetHeight=h,this.readsCanvas=false;let p=this.floats;for(let m=0;m<r;m++){let f=a+m*JG;n[f+1]===dI&&(this.clearColor[0]=p[f+2],this.clearColor[1]=p[f+3],this.clearColor[2]=p[f+4],this.clearColor[3]=p[f+5],e.clearBufferfv(e.COLOR,m,this.clearColor));}return l!==pI&&(n[u+2]===dI&&(this.clearDepth[0]=p[u+3],e.clearBufferfv(e.DEPTH,0,this.clearDepth)),c&&n[u+4]===dI&&(this.clearStencil[0]=n[u+5],e.clearBufferiv(e.STENCIL,0,this.clearStencil))),o}stencil(e){let t=this.stencilFront,n=this.stencilBack;e.stencilFuncSeparate(e.BACK,t[0],this.stencilReference,t[2]),e.stencilFuncSeparate(e.FRONT,n[0],this.stencilReference,n[2]);}state(e,t){let n=this.words,r=t+1;n[r]!==0?(e.enable(e.BLEND),e.blendFuncSeparate(this.blendFactors[n[r+1]],this.blendFactors[n[r+2]],this.blendFactors[n[r+4]],this.blendFactors[n[r+5]]),e.blendEquationSeparate(this.blendOps[n[r+3]],this.blendOps[n[r+6]])):e.disable(e.BLEND);let o=n[r+7];e.colorMask((o&cfe)!==0,(o&ufe)!==0,(o&dfe)!==0,(o&hfe)!==0),n[r+26]!==0?(e.enable(e.DEPTH_TEST),e.depthFunc(n[r+8]===hI?e.ALWAYS:this.compares[n[r+8]-1]),e.depthMask(n[r+9]!==0)):e.disable(e.DEPTH_TEST);let a=n[r+10];if(a===ZG||a===lfe?(e.enable(e.CULL_FACE),e.cullFace(a===ZG?e.FRONT:e.BACK)):e.disable(e.CULL_FACE),e.frontFace(n[r+11]!==0?e.CW:e.CCW),n[r+12]!==0){e.enable(e.STENCIL_TEST);let u=d=>d===hI?e.ALWAYS:this.compares[d-1];this.stencilFront=[u(n[r+13]),0,n[r+21]],this.stencilBack=[u(n[r+17]),0,n[r+21]],this.stencil(e),e.stencilOpSeparate(e.BACK,this.stencilOps[n[r+14]],this.stencilOps[n[r+15]],this.stencilOps[n[r+16]]),e.stencilOpSeparate(e.FRONT,this.stencilOps[n[r+18]],this.stencilOps[n[r+19]],this.stencilOps[n[r+20]]),e.stencilMask(n[r+22]);}else e.disable(e.STENCIL_TEST);let l=this.signedWord(n[r+23]),c=this.floats[r+24];l!==0||c!==0?(e.enable(e.POLYGON_OFFSET_FILL),e.polygonOffset(c,l)):e.disable(e.POLYGON_OFFSET_FILL);}signedWord(e){return e|0}attribute(e,t){let n=this.words,r=n[t+1],o=this.buffers[n[t+2]];if(o===void 0||r>=jG)return;e.bindBuffer(e.ARRAY_BUFFER,o),e.enableVertexAttribArray(r),this.enabledAttributes|=1<<r;let s=this.attributeTypes[n[t+4]];n[t+6]!==0?e.vertexAttribIPointer(r,n[t+3],s,n[t+7],n[t+8]):e.vertexAttribPointer(r,n[t+3],s,n[t+5]!==0,n[t+7],n[t+8]),e.vertexAttribDivisor(r,n[t+9]);}mode(e,t){switch(t){case n6:return e.TRIANGLE_STRIP;case jme:return e.POINTS;case Jme:return e.LINES;case Zme:return e.LINE_STRIP;default:return e.TRIANGLES}}endPass(e){for(let t=0;t<jG;t++)(this.enabledAttributes&1<<t)!==0&&(e.vertexAttribDivisor(t,0),e.disableVertexAttribArray(t));this.enabledAttributes=0,e.disable(e.SCISSOR_TEST),e.disable(e.BLEND),e.disable(e.DEPTH_TEST),e.disable(e.STENCIL_TEST),e.disable(e.CULL_FACE),e.disable(e.POLYGON_OFFSET_FILL),e.colorMask(true,true,true,true),e.depthRange(0,1),e.frontFace(e.CCW);for(let t=0;t<r6;t++)e.bindSampler(t,this.sampler);}execute(e,t){let n=this.gl;if(n===null)return;this.views();let r=this.words,o=e/cr+t,s=e/cr;for(;s<o;){if(this.checked){let a=n.getError();a!==n.NO_ERROR&&this.fail(`GL error ${a} before op ${r[this.lastOp]} at ${this.lastOp}`),this.lastOp=s;}switch(r[s]){case yme:s=this.program(n,s);break;case Ame:this.texture(n,s),s+=7;break;case bme:this.upload(n,s),s+=10;break;case gme:this.deleteTexture(n,r[s+1]),s+=2;break;case Eme:this.target(n,s),s+=4;break;case xme:{let a=this.floats;n.clearColor(a[s+1],a[s+2],a[s+3],a[s+4]),n.clear(n.COLOR_BUFFER_BIT),s+=5;break}case vme:r[s+1]===ffe?(n.enable(n.BLEND),n.blendFunc(n.ONE,n.ONE_MINUS_SRC_ALPHA)):n.disable(n.BLEND),s+=2;break;case Rme:{let a=this.programs[r[s+1]],l=a!==void 0&&this.ready(n,a);this.current=l?a:null,n.useProgram(l?a.program:null),s+=2;break}case Sme:{let a=r[s+2]===pI?void 0:this.textures[r[s+2]];n.activeTexture(n.TEXTURE0+r[s+1]),n.bindTexture(n.TEXTURE_2D,a===void 0?this.fallback:a.texture),s+=3;break}case Tme:s=this.uniforms(n,s);break;case wme:{let a=this.current;a!==null&&(a.firstInstance!==null&&n.uniform1ui(a.firstInstance,r[s+5]),n.drawArraysInstanced(r[s+1]===n6?n.TRIANGLE_STRIP:n.TRIANGLES,r[s+2],r[s+3],r[s+4])),s+=6;break}case Ime:{let a=this.textures[r[s+1]];a!==void 0&&(n.activeTexture(n.TEXTURE0+Hp),n.bindTexture(n.TEXTURE_2D,a.texture),n.copyTexSubImage2D(n.TEXTURE_2D,0,r[s+2],r[s+3],r[s+2],r[s+3],r[s+4],r[s+5])),s+=6;break}case Ome:this.read(n,s),s+=7;break;case Cme:{let a=this.textures[r[s+1]];a!==void 0&&(n.activeTexture(n.TEXTURE0+Hp),n.bindTexture(n.TEXTURE_2D,a.texture),n.generateMipmap(n.TEXTURE_2D)),s+=2;break}case Nme:this.makeBuffer(n,s),s+=4;break;case kme:{let a=this.buffers[r[s+1]];a!==void 0&&(n.bindBuffer(n.COPY_WRITE_BUFFER,a),ms(r[s+3],r[s+4]),n.bufferSubData(n.COPY_WRITE_BUFFER,r[s+2],this.bytes,r[s+3],r[s+4])),s+=5;break}case Lme:{let a=this.buffers[r[s+1]];a!==void 0&&n.deleteBuffer(a),this.buffers[r[s+1]]=void 0,s+=2;break}case Mme:this.makeSampler(n,s),s+=10;break;case Dme:{let a=this.samplers[r[s+1]];a!==void 0&&n.deleteSampler(a),this.samplers[r[s+1]]=void 0,s+=2;break}case Pme:{let a=this.programs[r[s+1]];a!==void 0&&n.deleteProgram(a.program),this.programs[r[s+1]]=void 0,s+=2;break}case Fme:s=this.pass(n,s);break;case Ume:this.state(n,s),s+=1+nfe;break;case Bme:this.attribute(n,s),s+=1+rfe;break;case Gme:{let a=this.buffers[r[s+1]];a!==void 0&&n.bindBuffer(n.ELEMENT_ARRAY_BUFFER,a),s+=2;break}case Vme:{let a=this.current;if(a!==null){a.firstInstance!==null&&n.uniform1ui(a.firstInstance,r[s+6]);let l=r[s+3]===efe?n.UNSIGNED_SHORT:n.UNSIGNED_INT;n.drawElementsInstanced(this.mode(n,r[s+1]),r[s+2],l,r[s+4],r[s+5]);}s+=7;break}case Hme:{let a=this.floats;n.viewport(Math.round(a[s+1]),Math.round(a[s+2]),Math.round(a[s+3]),Math.round(a[s+4])),n.depthRange(a[s+5],a[s+6]),s+=7;break}case Wme:n.enable(n.SCISSOR_TEST),n.scissor(r[s+1],r[s+2],r[s+3],r[s+4]),s+=5;break;case Kme:this.stencilReference=r[s+1],this.stencil(n),s+=2;break;case Yme:{let a=this.floats;n.blendColor(a[s+1],a[s+2],a[s+3],a[s+4]),s+=5;break}case Xme:{let a=this.buffers[r[s+2]];a!==void 0&&n.bindBufferRange(n.UNIFORM_BUFFER,r[s+1],a,r[s+3],r[s+4]),s+=5;break}case qme:{let a=this.samplers[r[s+2]];n.bindSampler(r[s+1],a??null),s+=3;break}case zme:this.endPass(n),s+=1;break;default:this.fail(`unknown op ${r[s]} at ${s}`);return}}if(this.checked){let a=n.getError();a!==n.NO_ERROR&&this.fail(`GL error ${a} after op ${r[this.lastOp]} at ${this.lastOp}`);}}};c6();var FA=new WeakMap;function u6(i){return typeof SharedArrayBuffer=="function"&&i instanceof SharedArrayBuffer}function Rfe(){throw new _("capacity_exceeded","engine memory is reserved in full at boot and never grows; reserve more with memoryPages")}function d6(i,e){let t=e*Xl,n=i.buffer;if(n.byteLength!==t)throw new _("capacity_exceeded",`engine memory holds ${n.byteLength} bytes after boot, not the ${t} it reserves`);Object.defineProperty(i,"grow",{value:Rfe,configurable:false,enumerable:false,writable:false}),FA.set(i,{buffer:n,bytes:t,shared:u6(n)});}function h6(i){if(FA.has(i))return;let e=i.buffer;FA.set(i,{buffer:e,bytes:e.byteLength,shared:u6(e)});}function Sfe(i){let e=FA.get(i);if(e===void 0)return true;let t=i.buffer;return t===e.buffer?true:e.shared&&t.byteLength===e.bytes}function p6(i){if(!Sfe(i))throw new _("engine_mismatch","engine memory moved after boot, so views into it would read stale data; the frame stops instead")}var Tfe=["engine_abi_version","engine_alloc","engine_free","engine_reserve","engine_world_create","engine_world_destroy","engine_world_registers","engine_world_desc","engine_world_commands","engine_contacts_a","engine_contacts_b","engine_contacts_started","engine_contact_count","engine_bind_transforms","engine_snapshot","engine_compute_render","engine_apply_commands","engine_step","engine_body_create","engine_body_destroy","engine_body_linear_velocity","engine_body_angular_velocity","engine_body_sleeping","engine_collider_create","engine_collider_destroy","engine_collider_enable","engine_joint_create","engine_joint_motor","engine_joint_destroy","engine_controller_create","engine_controller_destroy","engine_character_move","engine_raycast","engine_determinism_digest"],wfe="engine_abi_compatible",Ife=1,Ofe="cimplify_gpu",Cfe="engine_gpu_mapped",Nfe="engine_gpu_error_buffer",kfe="engine_gpu_error",Lfe="engine_step",Mfe=0,Dfe=0,m6=0,Pfe=new Set(["engine_contacts_a","engine_contacts_b","engine_contacts_started","engine_contact_count","engine_apply_commands","engine_step","engine_body_create","engine_body_destroy","engine_body_linear_velocity","engine_body_angular_velocity","engine_body_sleeping","engine_collider_create","engine_collider_destroy","engine_collider_enable","engine_joint_create","engine_joint_motor","engine_joint_destroy","engine_controller_create","engine_controller_destroy","engine_character_move","engine_raycast","engine_determinism_digest"]);function f6(i){throw new _("unsupported_feature",`${i} needs the physics engine feature, which this game's engine build does not include`)}function Ffe(i){switch(i){case "engine_contacts_a":case "engine_contacts_b":case "engine_contacts_started":return ()=>Mfe;case "engine_contact_count":return ()=>Dfe;case "engine_apply_commands":case "engine_step":return (e,t)=>t===m6?m6:f6(i);default:return ()=>f6(i)}}function Kp(i){return typeof i[Lfe]=="function"}function _6(i){let e={},t=Kp(i);for(let n of Tfe){let r=i[n];if(typeof r=="function")e[n]=r;else if(!t&&Pfe.has(n))e[n]=Ffe(n);else throw new _("not_initialized",`engine module is missing ${n}`)}return e}function Ufe(i){let e=i.engine_abi_version;if(typeof e=="function"&&e()===1882262861)return true;let t=i[wfe];return typeof t=="function"&&t(1882262861)===Ife}function y6(i,e){if(!Ufe(e))throw new _("engine_mismatch",`engine ABI ${i.engine_abi_version()} does not cover ${1882262861}; the engine retired exports this SDK calls`)}function A6(i){let e=_6(i.exports);return y6(e,i.exports),h6(i.memory),{exports:e,memory:i.memory,symbols:i.exports,gpu:i.gpu??null,gl:i.gl??null,decodeAudio:i.decode_audio??null,audioContext:i.audio_context??null,audioWorklet:i.audio_worklet??null}}async function Bfe(i,e={}){let t=e.memoryPages??vA;if(t<=ku)throw new _("invalid_argument",`engine memory needs more than ${ku} pages`);let n=e.scope??globalThis,r=e.threaded!==void 0&&PG(n),o=r?e.threaded:i,s=o instanceof WebAssembly.Module?o:await WebAssembly.compile(o),a=new WebAssembly.Memory({initial:ku,maximum:t,shared:r}),l=new MA,c=new DA,u={env:{memory:a},[Ofe]:l.imports,[o6]:c.imports};a6(s)&&(u[mI]=s6(()=>a));let d=await WebAssembly.instantiate(s,u);l6(d.exports);let h=_6(d.exports);y6(h,d.exports);let p=t*Xl-a.buffer.byteLength-iB;if(h.engine_reserve(p)<0)throw new _("capacity_exceeded","engine memory could not be reserved");let m=t-a.buffer.byteLength/Xl;m>0&&a.grow(m),d6(a,t),e.session&&BG({symbols:d.exports,memory:a,exports:h},e.session);let f=d.exports[Cfe],y=d.exports[Nfe],b=d.exports[kfe],A=typeof f=="function"&&typeof y=="function"&&typeof b=="function";A&&l.bindMemory(a,{mapped:f,errorBuffer:y,error:b});let E=typeof d.exports[PA]=="function";E&&c.bindMemory(a);let R=e.workers??FG(n),g=r?await UG(s,a,d.exports,R,e.workerFactory):null;return {exports:h,memory:a,symbols:d.exports,gpu:A?l:null,gl:E?c:null,threads:g,lanes:g?.lanes??1}}async function b6(i,e={}){return Gfe(await Bfe(i,e))}function Gfe(i){return {kind:"engine",runtime:{exports:i.symbols,memory:i.memory,gpu:i.gpu,gl:i.gl}}}var fI="runtime/text-dictionaries.bin";var g6="@cimplify/engine-core-gl";var Vfe=/\.wasm$/,Hfe={name:"base",features:[],file:"engine_wasm.base.wasm"},Wfe={name:"physics",features:["physics"],file:"engine_wasm.physics.wasm"},Kfe={name:"content",features:["models","images"],file:"engine_wasm.content.wasm"},Yfe={name:"full",features:["physics","models","images"],file:"engine_wasm.wasm"};var Xfe=[Hfe,Wfe,Kfe,Yfe];var qfe={name:"scripts",features:["physics","models","images"],file:"engine_wasm.scripts.wasm",scripts:true},zfe=[{name:"base-scripts",features:[],file:"engine_wasm.base.scripts.wasm",scripts:true},{name:"physics-scripts",features:["physics"],file:"engine_wasm.physics.scripts.wasm",scripts:true},{name:"content-scripts",features:["models","images"],file:"engine_wasm.content.scripts.wasm",scripts:true},qfe],Qfe={name:"scripts-shaders",features:["physics","models","images"],file:"engine_wasm.scripts.shaders.wasm",scripts:true,shaders:true},$fe=[{name:"base-scripts-shaders",features:[],file:"engine_wasm.base.scripts.shaders.wasm",scripts:true,shaders:true},{name:"physics-scripts-shaders",features:["physics"],file:"engine_wasm.physics.scripts.shaders.wasm",scripts:true,shaders:true},{name:"content-scripts-shaders",features:["models","images"],file:"engine_wasm.content.scripts.shaders.wasm",scripts:true,shaders:true},Qfe];function jfe(i){return {...i,name:`${i.name}-gl`,file:i.file.replace(Vfe,".gl.wasm"),gl:true}}[...Xfe,...zfe,...$fe].map(jfe);yn();var ri={WebTransport:"web_transport",WebSocket:"web_socket"};var Fu=3,EI=4,gI=6,HA=64,__e=2048,y_e=1,A_e=1,B6=4,b_e=8,g_e=3,WA=4,E_e=true,x_e=[ri.WebTransport,ri.WebSocket];function v_e(i){return x_e.indexOf(i)}function KA(i){return i[1]|i[2]<<8}function vI(i,e,t,n){i[e]=t,i[e+1]=n&255,i[e+2]=n>>>8;}function R_e(i,e,t,n,r){let o=i.reserve(EI+r.length),s=i.out;vI(s,o,e,t),s[o+Fu]=n,s.set(r,o+EI),i.commitFrame();}function S_e(i,e,t){vI(i.out,i.reserve(Fu),e,t),i.commitTask();}var T_e=new TextEncoder,xI=class{constructor(e,t,n){this.transport=e;this.rooms=t;this.link=n;}send(e,t){this.rooms.send(this.link,e,t);}close(){this.rooms.close(this.link);}},YA=class{constructor(e){this.port=e;this.links=Array.from({length:HA},()=>null);this.next=0;}dialer(e,t){return {transport:e,dial:(n,r)=>this.dial(e,t,n,r)}}allocate(){for(let e=0;e<HA;e++){let t=(this.next+e)%HA;if(this.links[t]===null)return this.next=(t+1)%HA,t}return -1}dial(e,t,n,r){let o=T_e.encode(t),s=this.allocate();return s<0||o.length>__e?Promise.resolve(null):new Promise(a=>{this.links[s]={transport:e,handler:r,settle:a};let l=this.port.reserve(gI+o.length+n.length),c=this.port.out;vI(c,l,ee.room_dial,s),c[l+Fu]=v_e(e),new DataView(c.buffer,c.byteOffset).setUint16(l+4,o.length,E_e),c.set(o,l+gI),c.set(n,l+gI+o.length),this.port.commitTask();})}send(e,t,n){this.links[e]?.settle===null&&R_e(this.port,ee.room_send,e,t,n);}close(e){this.links[e]!==null&&(this.links[e]=null,S_e(this.port,ee.room_close,e));}receive(e){switch(e[0]){case ee.room_batch:{let t=A_e;for(;t+B6<=e.length;){let n=(e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24)>>>0,r=t+B6,o=r+n;if(o>e.length)break;n>0&&e[r]!==ee.room_batch&&this.receive(e.subarray(r,o)),t=o;}return true}case ee.room_backpressure:{if(e.length<b_e)return true;let t=this.links[KA(e)];if(t===null||t.settle!==null)return true;let n=(e[WA]|e[WA+1]<<8|e[WA+2]<<16|e[WA+3]<<24)>>>0;return t.handler.backpressure?.(n,e[g_e]),true}case ee.room_frames:{let t=this.links[KA(e)];return t!==null&&t.settle===null&&t.handler.frame(e[Fu],e.subarray(EI)),true}case ee.room_dialed:return this.dialed(KA(e),e),true;case ee.room_closed:{let t=KA(e),n=this.links[t];return this.links[t]=null,n===null||(n.settle!==null?n.settle(null):n.handler.closed()),true}}return false}dialed(e,t){let n=this.links[e];if(n===null||n.settle===null)return;let r=n.settle;if(n.settle=null,t[Fu]!==y_e){this.links[e]=null,r(null);return}r({link:new xI(n.transport,this,e),reply:t.slice(Fu+1)});}};var Uu="@cimplify/godot/",RI={alpha:false,depth:true,stencil:false,antialias:false,premultipliedAlpha:true,preserveDrawingBuffer:false,powerPreference:"default",failIfMajorPerformanceCaveat:false},G6={api:"webgl2",transparent:false,pixel_ratio_cap:3,offscreen:false};var w_e="canvas",I_e="data-cimplify-engine";function V6(i){i.id=w_e,i.setAttribute(I_e,"");}var O_e="text/javascript";function H6(i,e,t){let n=new Blob([e],{type:O_e}),r=URL.createObjectURL(n),o=globalThis;return new Promise((s,a)=>{let l=i.createElement("script");l.src=r,l.onload=()=>{let c=o[t];Reflect.deleteProperty(o,t),l.remove(),URL.revokeObjectURL(r),typeof c!="function"?a(new Error(`the engine glue did not define ${t}`)):s({factory:c,script:n});},l.onerror=()=>{l.remove(),URL.revokeObjectURL(r),a(new Error("the engine glue did not load"));},i.head.appendChild(l);})}new TextDecoder;function W6(...i){for(let e of i)if(e!==void 0)for(let t of Object.values(e)){if(t instanceof WebAssembly.Memory)return t;if(typeof t=="object"&&t!==null&&!(t instanceof WebAssembly.Global)&&!(t instanceof WebAssembly.Table)){for(let n of Object.values(t))if(n instanceof WebAssembly.Memory)return n}}return null}async function C_e(i,e){let t=new Uint8Array(e.bytes),n=0;for(let r of e.parts){let o=await i.take(r);if(n+o.length>t.length)throw new Error("a binary is larger than its declared size");t.set(o,n),n+=o.length;}if(n!==t.length)throw new Error("a binary is smaller than its declared size");return t}function K6(i,e){let t=i.module(e.parts);if(t!==null)return t;let n=e.sha256===void 0?null:i.joined?.(e.sha256,e.parts)??null;return n===null?XA(i,e):n.catch(()=>XA(i,e))}function XA(i,e){return Xp(i,e).then(t=>WebAssembly.compile(t))}async function Xp(i,e){return e.parts.length===1?i.take(e.parts[0]):C_e(i,e)}new TextEncoder;var N_e="Godot";var k_e=".audio.worklet.js",L_e=".audio.position.worklet.js",M_e=2,q6=4,D_e=2,P_e=q6+D_e,F_e="text/javascript";var U_e="webgl2",B_e="godot",G_e=",",Y6="/wasm",V_e="/glue",H_e="worklet/audio",W_e="worklet/position",K_e="/project.godot",Y_e="/.godot/global_script_class_cache.cfg",X_e=`list=[]
24
+ `,q_e=`config_version=5
25
+
26
+ [application]
27
+
28
+ run/main_scene="res://cimplify_boot.tscn"
29
+ boot_splash/show_image=false
30
+ `,z_e="godot_web_set_boot_only";var Q_e="number";function $_e(i){return i.getContext(U_e,RI),typeof AudioContext=="function"?new AudioContext:null}async function X6(i,e){let t=await Xp(i,e);return URL.createObjectURL(new Blob([t],{type:F_e}))}function j_e(i){return i.parts.join(G_e)}async function J_e(i,e,t){let n=Xp(i,t.glue).then(d=>H6(document,d,N_e)),r=K6(i,t.wasm),o=$_e(e),[s,a,l]=await Promise.all([n,X6(i,t.audio),X6(i,t.position)]),c={drawn:()=>{}},u=await s.factory({print:d=>console.debug(d),printErr:d=>console.warn(d),thisProgram:B_e,noExitRuntime:false,dynamicLibraries:[],emscriptenPoolSize:P_e,mainScriptUrlOrBlob:s.script,postMainLoop:()=>c.drawn(),locateFile:d=>d.endsWith(L_e)?l:d.endsWith(k_e)?a:d,instantiateWasm(d,h){return r.then(async p=>{let m=await WebAssembly.instantiate(p,d);if(W6(m.exports,...Object.values(d))===null)throw new Error("the Godot runtime has no linear memory");h(m,p);}),{}}});return await u.initFS([]),Object.assign(c,{runtime:u,audioContext:o,worklets:[a,l]})}function Z_e(i,e,t,n){i.runtime.initConfig({canvas:e,canvasResizePolicy:M_e,locale:t.replace("-","_"),persistentDrops:false,virtualKeyboard:false,godotPoolSize:q6,focusCanvas:true,onExecute:null,onExit:n,audioContext:i.audioContext});}function eye(i,e){for(let t of Object.keys(e)){if(!t.startsWith(Uu)||!t.endsWith(Y6))continue;let n=t.slice(Uu.length,t.length-Y6.length),r=c=>{let u=e[c];return u===void 0?null:i.binary(u)},o=r(`${Uu}${n}${V_e}`),s=r(t),a=r(`${Uu}${H_e}`),l=r(`${Uu}${W_e}`);return o===null||s===null||a===null||l===null?null:{glue:o,wasm:s,audio:a,position:l}}return null}function z6(i,e){let t=eye(i,e);if(t===null)return null;let n=i.prepare(G6,RI);return n===null?null:(async()=>{V6(n);let r=await J_e(i.assets,n,t);Z_e(r,n,navigator.language,()=>{}),r.runtime.copyToFS(K_e,new TextEncoder().encode(q_e)),r.runtime.copyToFS(Y_e,new TextEncoder().encode(X_e)),r.runtime.cwrap(z_e,null,[Q_e])(1),r.runtime.callMain([]),i.hold(j_e(t.wasm),r);})()}yn();var tye=1414680643,nye=1,Q6=8,rye=1296126019,iye=1,SI=24,$6=Ft+8,j6=16;var qA=512*1024*1024,oye={data:0,scene:1,mesh_index:2,mesh_vertex:3,skeleton:4,clip:5,texture:6,image:7,material:8,audio:9,shader:10,kernel:11,cell:12,font:13},sye=Object.keys(oye);function J6(i){let e=sye[i];if(e===void 0)throw new qe(`unknown part kind ${i}`);return e}var $n={literal:0,part:1,delta:2},qe=class extends Error{constructor(e){super(e),this.name="PartFormatError";}};function TI(i){return new DataView(i.buffer,i.byteOffset,i.byteLength)}function wI(i){if(i.length<Q6)throw new qe("a part is shorter than its header");let e=TI(i);if(e.getUint32(0,true)!==tye)throw new qe("not an asset part");if(e.getUint8(4)!==nye)throw new qe("unsupported asset part version");let t=e.getUint8(5);return J6(t),{kind:t,body:i.subarray(Q6)}}function aye(i){return i.length>=SI&&TI(i).getUint32(0,true)===rye}function II(i){if(!aye(i))throw new qe("not an asset manifest");let e=TI(i);if(e.getUint8(4)!==iye)throw new qe("unsupported asset manifest version");let t=e.getUint8(5),n=e.getUint16(6,true),r=e.getUint32(8,true),o=e.getUint32(12,true),s=e.getUint32(16,true),a=SI+n*$6+o*j6;if(a+s!==i.length)throw new qe("the asset manifest's tables do not match its length");let l=[],c=SI;for(let h=0;h<n;h++){let p=e.getUint8(c+Ft);J6(p),l.push({digest:bI(i,c,Ft),kind:p,length:e.getUint32(c+Ft+4,true)}),c+=$6;}let u=[];for(let h=0;h<o;h++){let p=e.getUint8(c),m=e.getUint16(c+2,true),f=e.getUint32(c+4,true),y=e.getUint32(c+8,true),b=e.getUint32(c+12,true);if(p===$n.literal)u.push({op:p,offset:f,length:y});else if(p===$n.part)u.push({op:p,part:m,offset:f,length:y});else if(p===$n.delta)u.push({op:p,part:m,offset:f,length:y,output:b});else throw new qe(`unknown segment op ${p}`);c+=j6;}let d={kind:t,length:r,parts:l,segments:u,literal:i.subarray(a)};return lye(d),d}function zA(i){return i.op===$n.delta?i.output:i.length}function lye(i){if(i.length>qA)throw new qe(`an asset of ${i.length} bytes is larger than the ${qA} byte limit`);let e=0;for(let t of i.segments){if(t.op===$n.literal){if(t.offset+t.length>i.literal.length)throw new qe("a literal segment runs past the manifest's literal bytes")}else {let n=i.parts[t.part];if(n===void 0)throw new qe(`a segment names part ${t.part} of ${i.parts.length}`);if(t.op===$n.part&&t.offset+t.length>n.length)throw new qe("a part segment runs past its part");if(t.op===$n.delta&&t.offset+t.length>i.literal.length)throw new qe("a delta segment runs past the manifest's literal bytes")}e+=zA(t);}if(e!==i.length)throw new qe(`the asset manifest's segments make ${e} bytes, not ${i.length}`)}var cye=1196576835,uye=1,_s=32,Bu=8,$l=12,wa=12,Qp=16,qp=1e6,dye=2147483647,hye=qA,go={magic:0,version:4,kind:5,levels:6,output:8,units:12,segments:16,patches:20,table:24,staging:28},Z6={opaque:0,texture:1,mesh:2,splat:3,audio:4,cells:5},pye=Object.keys(Z6);var OI=1,oi={write:0,staged:1,merge:2,unlift:3,length:4,fill:5},mye=255,fye=12,_ye=12,QA=2,gt=class extends Error{constructor(e){super(e),this.name="ProgressiveFormatError";}};function yye(i,e,t,n,r){return _s+i*Bu+e*$l+t*wa+n*Qp+r}var zp=class{constructor(){this.kind=Z6.opaque;this.output=0;this.levels=0;this.units=0;this.segments=0;this.patches=0;this.table=0;this.staging=0;this.levelsAt=0;this.unitsAt=0;this.segmentsAt=0;this.patchesAt=0;this.tableAt=0;this.head=0;}};function CI(i,e=new zp){if(i.byteLength<_s)throw new gt("a progressive container is shorter than its header");if(i.getUint32(go.magic,true)!==cye)throw new gt("not a progressive container");if(i.getUint8(go.version)!==uye)throw new gt("unsupported progressive container version");let t=i.getUint8(go.kind);if(t>=pye.length)throw new gt("unknown progressive kind");let n=i.getUint16(go.levels,true),r=i.getUint32(go.units,true),o=i.getUint32(go.segments,true),s=i.getUint32(go.patches,true),a=i.getUint32(go.table,true),l=yye(n,r,o,s,a);if(n===0||r<n||l>dye)throw new gt("the progressive container's tables are malformed");let c=i.getUint32(go.output,true),u=i.getUint32(go.staging,true);if(l+c+u>hye)throw new gt("a progressive container decodes to more than the format allows");return e.kind=t,e.output=c,e.levels=n,e.units=r,e.segments=o,e.patches=s,e.table=a,e.staging=u,e.levelsAt=_s,e.unitsAt=e.levelsAt+n*Bu,e.segmentsAt=e.unitsAt+r*$l,e.patchesAt=e.segmentsAt+o*wa,e.tableAt=e.patchesAt+s*Qp,e.head=l,e}function ii(i,e,t){return i>=0&&e>=0&&i+e<=t}function e8(i,e){let t=0,n=0;for(let s=0;s<e.levels;s++){let a=e.levelsAt+s*Bu,l=i.getUint32(a,true),c=i.getUint32(a+4,true);if(l<=t||l>e.units||c<n||c>qp)throw new gt(`progressive level ${s} is malformed`);t=l,n=c;}if(t!==e.units||n!==qp)throw new gt("the progressive levels do not end at full quality");let r=0,o=0;n=0;for(let s=0;s<e.units;s++){let a=e.unitsAt+s*$l,l=i.getUint32(a,true),c=i.getUint32(a+4,true),u=i.getUint32(a+8,true);if(l<r||l>e.segments||c<o||c>e.patches||u<n||u>qp)throw new gt(`progressive unit ${s} is malformed`);r=l,o=c,n=u;}if(r!==e.segments||o!==e.patches)throw new gt("the progressive units do not cover every segment and patch");for(let s=0;s<e.segments;s++){let a=e.segmentsAt+s*wa,l=i.getUint32(a,true),c=i.getUint32(a+4,true),u=(i.getUint32(a+8,true)&OI)!==0;if(!ii(l,c,u?e.staging:e.output))throw new gt(`progressive segment ${s} writes outside its target`)}for(let s=0;s<e.patches;s++){let a=e.patchesAt+s*Qp,l=i.getUint8(a),c=i.getUint32(a+4,true),u=i.getUint32(a+8,true),d=i.getUint32(a+12,true);if(l===oi.write){if(!ii(c,d,e.output)||!ii(u,d,e.table))throw new gt(`progressive patch ${s} is out of range`)}else if(l===oi.staged){if(!ii(c,d,e.output)||!ii(u,d,e.staging))throw new gt(`progressive patch ${s} is out of range`)}else if(l===oi.merge){if(!ii(d,fye,e.table))throw new gt(`progressive patch ${s} is out of range`);let h=i.getUint32(e.tableAt+d,true),p=i.getUint32(e.tableAt+d+4,true),m=i.getUint32(e.tableAt+d+8,true);if(m<2||p===0||!ii(c,h*p,e.output)||!ii(u,(h-NI(h,m))*p,e.staging))throw new gt(`progressive patch ${s} merges outside its target`)}else if(l===oi.unlift){if(!ii(d,_ye,e.table))throw new gt(`progressive patch ${s} is out of range`);let h=i.getUint32(e.tableAt+d,true),p=i.getUint32(e.tableAt+d+4,true),m=i.getUint32(e.tableAt+d+8,true);if(m===0||h!==Math.ceil(p/2)||!ii(c,p*m*QA,e.output)||!ii(u,(p-h)*m*QA,e.staging))throw new gt(`progressive patch ${s} lifts outside its target`)}else if(l===oi.length){if(c===0||c>e.output)throw new gt(`progressive patch ${s} sets a length outside the output`)}else if(l===oi.fill){if(u>mye||!ii(c,d,e.output))throw new gt(`progressive patch ${s} fills outside the output`)}else throw new gt(`unknown progressive patch op ${l}`)}}function NI(i,e){if(i===0)return 0;let t=i-1;return Math.floor(t/e)+1+(t%e===0?0:1)}function t8(i,e,t){return i%t===0||i===e-1}function n8(i){return i<<16>>16}function r8(i,e,t,n,r,o,s,a){let l=o-r,c=s*a;for(let u=0;u<s;u++){let d=e+u*a,h=n+u*a,p=0;for(let m=r-1;m>=0;m--){let f=i.getInt16(d+m*c,true);if(l>0){let y=t.getInt16(h+Math.max(0,m-1)*c,true),b=t.getInt16(h+Math.min(l-1,m)*c,true);f=n8(f-(y+b+2>>2));}if(m<l){let y=m+1<r?p:f,b=n8(t.getInt16(h+m*c,true)+(f+y>>1));i.setInt16(d+(2*m+1)*c,b,true);}i.setInt16(d+2*m*c,f,true),p=f;}}}var Gu=-1,kI=8,i8=new Uint8Array(0);function $p(i,e,t,n,r){if(n===0&&r===t.length){i.set(t,e);return}for(let o=0;o<r;o++)i[e+o]=t[n+o];}var jp=class{constructor(){this.head=new Uint8Array(_s);this.headView=new DataView(this.head.buffer);this.headLength=0;this.headNeeded=_s;this.shape=new zp;this.layout=null;this.out=i8;this.outView=new DataView(this.out.buffer);this.view=null;this.views=Array.from({length:kI},()=>null);this.nextView=0;this.staging=i8;this.stagingView=new DataView(this.staging.buffer);this.segment=0;this.segmentDone=0;this.unit=0;this.levelIndex=0;this.consumed=0;this.first=Gu;this.full=Gu;this.ppm=0;}get ready(){return this.layout!==null}get usable(){return this.levelIndex>0}get done(){return this.layout!==null&&this.unit===this.layout.units}get kind(){return this.layout?.kind??null}get output(){return this.levelIndex>0?this.view:null}get quality(){return this.ppm}get level(){return this.levelIndex}get levels(){return this.layout?.levels??0}get units(){return this.unit}get received(){return this.consumed}get firstBytes(){return this.first}get fullBytes(){return this.full}get outputBytes(){return this.layout?.output??Gu}levelEndBytes(e){let t=this.layout;if(t===null||e<0||e>=t.levels)return Gu;let n=this.headView.getUint32(t.levelsAt+e*Bu,true),r=this.headView.getUint32(t.unitsAt+(n-1)*$l,true),o=t.head;for(let s=0;s<r;s++)o+=this.headView.getUint32(t.segmentsAt+s*wa+4,true);return o}reset(){this.headLength=0,this.headNeeded=_s,this.layout=null,this.segment=0,this.segmentDone=0,this.unit=0,this.levelIndex=0,this.consumed=0,this.first=Gu,this.full=Gu,this.ppm=0;}push(e,t=0,n=e.length){let r=t,o=0;for(;r<n;){let s=this.layout;if(s===null){let h=Math.min(n-r,this.headNeeded-this.headLength);$p(this.head,this.headLength,e,r,h),this.headLength+=h,r+=h,this.consumed+=h,this.headLength===this.headNeeded&&(o+=this.openHead());continue}if(this.segment>=s.segments)break;let a=s.segmentsAt+this.segment*wa,l=this.headView.getUint32(a,true),c=this.headView.getUint32(a+4,true),u=(this.headView.getUint32(a+8,true)&OI)!==0,d=Math.min(n-r,c-this.segmentDone);$p(u?this.staging:this.out,l+this.segmentDone,e,r,d),this.segmentDone+=d,r+=d,this.consumed+=d,this.segmentDone===c&&(this.segment++,this.segmentDone=0,o+=this.settle());}return o}viewOf(e){for(let n=0;n<kI;n++){let r=this.views[n];if(r!==null&&r.length===e)return r}let t=this.out.subarray(0,e);return this.views[this.nextView]=t,this.nextView=(this.nextView+1)%kI,t}ensureHead(e){if(this.head.length>=e)return;let t=new Uint8Array(e);t.set(this.head.subarray(0,this.headLength)),this.head=t,this.headView=new DataView(t.buffer);}openHead(){if(this.headNeeded===_s){let n=CI(this.headView,this.shape).head;if(n>_s)return this.ensureHead(n),this.headNeeded=n,0}let e=CI(this.headView,this.shape);e8(this.headView,e),this.out.length<e.output?(this.out=new Uint8Array(e.output),this.outView=new DataView(this.out.buffer),this.views.fill(null)):this.out.fill(0,0,e.output),this.view=this.viewOf(e.output),this.staging.length<e.staging&&(this.staging=new Uint8Array(e.staging),this.stagingView=new DataView(this.staging.buffer)),this.layout=e;let t=0;for(let n=0;n<e.segments;n++)t+=this.headView.getUint32(e.segmentsAt+n*wa+4,true);return this.full=e.head+t,this.first=this.levelEndBytes(0),this.settle()}settle(){let e=this.layout;if(e===null)return 0;for(;this.segment<e.segments&&this.headView.getUint32(e.segmentsAt+this.segment*wa+4,true)===0;)this.segment++;let t=0;for(;this.unit<e.units;){let n=e.unitsAt+this.unit*$l;if(this.segment<this.headView.getUint32(n,true))break;let r=this.unit===0?0:this.headView.getUint32(n-$l+4,true),o=this.headView.getUint32(n+4,true);for(let s=r;s<o;s++)this.apply(e,e.patchesAt+s*Qp);for(this.ppm=this.headView.getUint32(n+8,true),this.unit++,t++;this.levelIndex<e.levels&&this.unit>=this.headView.getUint32(e.levelsAt+this.levelIndex*Bu,true);)this.levelIndex++;}return t}apply(e,t){let n=this.headView,r=n.getUint8(t),o=n.getUint32(t+4,true),s=n.getUint32(t+8,true),a=n.getUint32(t+12,true);if(r===oi.write)$p(this.out,o,this.head,e.tableAt+s,a);else if(r===oi.staged)$p(this.out,o,this.staging,s,a);else if(r===oi.merge){let l=n.getUint32(e.tableAt+a,true),c=n.getUint32(e.tableAt+a+4,true),u=n.getUint32(e.tableAt+a+8,true),d=NI(l,u)-1,h=l-d-2;for(let p=l-1;p>=0;p--){let m=o+p*c;if(t8(p,l,u)){let f=o+d*c;f!==m&&this.out.copyWithin(m,f,f+c),d--;}else $p(this.out,m,this.staging,s+h*c,c),h--;}}else if(r===oi.length)this.view=this.viewOf(o);else if(r===oi.fill)this.out.fill(s,o,o+a);else {let l=n.getUint32(e.tableAt+a,true),c=n.getUint32(e.tableAt+a+4,true),u=n.getUint32(e.tableAt+a+8,true);r8(this.outView,o,this.stagingView,s,l,c,u,QA);}}};function o8(i){let e=new jp;e.push(i);let t=e.output;if(!e.done||t===null)throw new gt("the progressive container is truncated");return t}var LI=class extends Error{constructor(t){super(`the progressive load of ${t} was cancelled`);this.asset=t;this.name="ProgressiveCancelled";}};function s8(){let i=()=>{},e=()=>{},t=new Promise((n,r)=>{i=n,e=r;});return t.catch(()=>{}),{promise:t,resolve:i,reject:e}}var $A=class{constructor(e,t){this.asset=e;this.listener=t;this.decoder=new jp;this.firstReady=s8();this.doneReady=s8();this.stopped=false;this.finished=false;this.first=this.firstReady.promise;this.done=this.doneReady.promise;}get cancelled(){return this.stopped}get firstBytes(){return this.decoder.firstBytes}cancel(){this.finished||(this.stopped=true,this.fail(new LI(this.asset)));}push(e){if(this.stopped||this.finished)return;let t;try{t=this.decoder.push(e);}catch(o){this.fail(o instanceof Error?o:new gt(String(o)));return}let n=this.decoder.output;if(t===0||n===null)return;let r=this.decoder.done;this.listener?.(n,this.decoder.quality,this.decoder.level,r),this.firstReady.resolve(n),r&&(this.finished=true,this.doneReady.resolve(n));}whole(e){this.push(e),!this.finished&&!this.stopped&&this.fail(new gt(`the progressive container for ${this.asset} is truncated`));}complete(e){this.stopped||this.finished||(this.finished=true,this.listener?.(e,qp,0,true),this.firstReady.resolve(e),this.doneReady.resolve(e));}fail(e){this.finished=true,this.firstReady.reject(e),this.doneReady.reject(e);}};var Jp={copy:0,insert:1,table:2,map:3,fill:4};var bye=4,a8=256;var MI=class{constructor(e){this.bytes=e;this.at=0;}get done(){return this.at>=this.bytes.length}byte(){if(this.at>=this.bytes.length)throw new qe("a delta ends inside an operation");return this.bytes[this.at++]}varint(){let e=0,t=0;for(;;){let n=this.byte();if(e+=(n&127)*2**t,(n&128)===0)return e;if(t+=7,t>28)throw new qe("a delta varint is too long")}}take(e){if(this.at+e>this.bytes.length)throw new qe("a delta literal runs past its end");let t=this.bytes.subarray(this.at,this.at+e);return this.at+=e,t}};function jA(i,e,t,n,r){let o=new MI(e),s=n+r;if(s>t.length)throw new qe("a delta writes past its target");let a=0,l=null,c=n;for(;!o.done;){let u=o.byte();if(u===Jp.copy){let d=o.varint(),h=o.varint();if(d+h>i.length||c+h>s)throw new qe("a delta copy runs out of bounds");t.set(i.subarray(d,d+h),c),c+=h;}else if(u===Jp.insert){let d=o.varint();if(c+d>s)throw new qe("a delta insert runs past its target");t.set(o.take(d),c),c+=d;}else if(u===Jp.table){if(a=o.byte(),a<1||a>bye)throw new qe(`a delta table has stride ${a}`);l=o.take(a*a8);}else if(u===Jp.map){let d=o.varint(),h=o.varint();if(l===null)throw new qe("a delta maps before it declares a table");if(d+h>i.length||c+h>s)throw new qe("a delta map runs out of bounds");for(let p=0;p<h;p++){let m=d+p;t[c+p]=l[m%a*a8+i[m]];}c+=h;}else if(u===Jp.fill){let d=o.varint(),h=o.byte();if(c+d>s)throw new qe("a delta fill runs past its target");t.fill(h,c,c+d),c+=d;}else throw new qe(`unknown delta op ${u}`)}if(c!==s)throw new qe(`a delta made ${c-n} bytes, not ${r}`)}function l8(i,e,t,n=0){if(n+i.length>t.length)throw new qe("the assembly target is smaller than the asset");let r=n;for(let o of i.segments){if(o.op===$n.literal){t.set(i.literal.subarray(o.offset,o.offset+o.length),r),r+=o.length;continue}let s=e(o.part);if(s.length!==i.parts[o.part].length)throw new qe(`part ${i.parts[o.part].digest} is ${s.length} bytes, not ${i.parts[o.part].length}`);o.op===$n.part?(t.set(s.subarray(o.offset,o.offset+o.length),r),r+=o.length):(jA(s,i.literal.subarray(o.offset,o.offset+o.length),t,r,o.output),r+=o.output);}}function c8(i){if(i.segments.length!==1)return null;let e=i.segments[0];return e.op===$n.part?{part:e.part,offset:e.offset}:null}var JA=class{constructor(){this.users=new Map;this.held=new Map;this.loading=new Map;this.lazy=new Set;}use(e,t){t?this.lazy.add(e):this.users.set(e,(this.users.get(e)??0)+1);}register(e,t){this.use(e.chunk,e.lazy===true);for(let n of t)this.use(n.chunk,n.lazy===true);}holds(e){return this.held.has(e)}fetch(e,t,n){let r=this.held.get(e);if(r!==void 0)return Promise.resolve(r);let o=this.loading.get(e);if(o!==void 0)return o;let s=n.take(e,t).then(a=>(this.loading.delete(e),!this.lazy.has(e)&&(this.users.get(e)??0)>1&&this.held.set(e,a),a));return s.catch(()=>this.loading.delete(e)),this.loading.set(e,s),s}shared(e){return this.lazy.has(e)||(this.users.get(e)??0)>1}done(e,t){if(this.lazy.has(e)){t.release(e);return}let n=(this.users.get(e)??0)-1;if(n>0){this.users.set(e,n);return}this.users.delete(e),this.held.delete(e);}async stream(e,t,n,r,o){let s=II(await this.fetch(e,t,r)),a=new Map,l=(d,h)=>{let p=a.get(d);if(p!==void 0)return p;let m=this.fetch(s.parts[d].digest,h,r).then(f=>wI(f).body);return m.catch(()=>{}),a.set(d,m),m},c=false,u=new Uint8Array(0);try{let d=0;for(let h=0;h<s.segments.length;h++){let p=s.segments[h];if(o.cancelled)return;if(!c&&o.firstBytes>=0){c=!0;let m=d;for(let f=h;f<s.segments.length;f++){let y=s.segments[f];y.op!==$n.literal&&l(y.part,m<o.firstBytes?t:n),m+=zA(y);}}if(p.op===$n.literal)o.push(s.literal.subarray(p.offset,p.offset+p.length));else if(p.op===$n.part){let m=await l(p.part,t);if(m.length!==s.parts[p.part].length)throw new qe(`part ${s.parts[p.part].digest} is ${m.length} bytes, not ${s.parts[p.part].length}`);o.push(m.subarray(p.offset,p.offset+p.length));}else {let m=await l(p.part,t);u.length<p.output&&(u=new Uint8Array(p.output)),jA(m,s.literal.subarray(p.offset,p.offset+p.length),u,0,p.output),o.push(u.subarray(0,p.output));}d+=zA(p);}}finally{for(let d of s.parts)this.done(d.digest,r);this.done(e,r);}}async assemble(e,t,n){let r=II(await this.fetch(e,t,n)),s=(await Promise.all(r.parts.map(c=>this.fetch(c.digest,t,n)))).map(c=>wI(c).body),a=c8(r),l;if(a!==null){let c=s[a.part].subarray(a.offset,a.offset+r.length);l=this.shared(r.parts[a.part].digest)?c.slice():c;}else l=new Uint8Array(r.length),l8(r,c=>s[c],l,0);for(let c of r.parts)this.done(c.digest,n);return this.done(e,n),l}};yn();var xye="__cimplify_readiness_probe",ZA=0;function DI(){let i=globalThis[xye];return i===void 0?null:i}function eb(){ZA++;}function Zp(){ZA>0&&ZA--;}function u8(i=false){DI()?.frame(i||ZA>0);}var PI=",",vye="content/",Rye=/^content@(low|mid|high)\/(.+)$/,Sye=/^[0-9a-f]{64}$/,em=class{constructor(e=null,t=null){this.joinedSource=e;this.compiler=t;this.arrived=new Map;this.tiered=new Map;this.waiting=new Map;this.paths=new Map;this.modules=new Map;this.lazyDigests=new Set;this.prefetching=new Map;this.prefetched=new Set;this.cancelled=new Set;this.networkListeners=[];this.parted=new Map;this.assetParts=new JA;this.progressiveAssets=new Set;this.channel=null;this.hint=null;this.catalogPending=null;this.catalogDone=()=>{};}joined(e,t){if(this.joinedSource===null)return null;let n=t.join(PI),r=this.modules.get(n);if(r!==void 0)return r;let o=this.joinedSource(e,t);return o.catch(()=>this.modules.delete(n)),this.modules.set(n,o),o}warm(e,t){let n=e.join(PI),r=this.modules.get(n);if(r!==void 0)return r;let o=this.binary(e);if(o===null)return null;let s=t(o);return s.catch(()=>{}),this.modules.set(n,s),s}binary(e){let t=0;for(let n of e){let r=this.arrived.get(n);if(r===void 0)return null;t+=r.length;}return {parts:e,bytes:t}}module(e){let t=e.join(PI),n=this.modules.get(t);if(n!==void 0)return n;let r=this.compiler;if(r===null)return null;let o=this.joinTaken(e).then(r);return o.catch(()=>this.modules.delete(t)),this.modules.set(t,o),o}async joinTaken(e){let t=[],n=0;for(let s of e){let a=await this.take(s);t.push(a),n+=a.length;}if(t.length===1)return t[0];let r=new Uint8Array(n),o=0;for(let s of t)r.set(s,o),o+=s.length;return r}catalog(e){for(let t of e){if(this.paths.set(t.path,t.chunk),t.lazy===true&&this.lazyDigests.add(t.chunk),t.progressive===true&&this.progressiveAssets.add(t.path),t.parts!==void 0){this.parted.set(t.path,t.parts),this.assetParts.register(t,t.parts);for(let s of t.parts)s.lazy===true&&this.lazyDigests.add(s.chunk);}let n=Rye.exec(t.path);if(n===null)continue;let r=`${vye}${n[2]}`,o=this.tiered.get(r)??[];o.push(t.chunk),this.tiered.set(r,o);}}awaitCatalog(){this.catalogPending===null&&(this.catalogPending=new Promise(e=>{this.catalogDone=e;}));}catalogued(){this.catalogPending=null,this.catalogDone();}uncatalogued(e){return this.catalogPending===null||this.has(e)||Sye.test(e)?null:this.catalogPending}has(e){return this.paths.has(e)||this.tiered.has(e)}resolve(e){let t=this.tiered.get(e);if(t!==void 0){for(let n of t)if(this.arrived.has(n))return n}return this.paths.get(e)??e}accept(e,t){let n=this.waiting.get(e);if(n!==void 0){this.waiting.delete(e),n.needed&&Zp(),n.resolve(t.slice());return}if(this.cancelled.delete(e)){this.channel?.release(e);return}this.prefetching.delete(e)&&this.prefetched.add(e),this.arrived.has(e)||this.arrived.set(e,t.slice());}connect(e){this.channel=e;}network(e){this.hint=e;for(let t=0;t<this.networkListeners.length;t++)this.networkListeners[t](e);}networkHint(){return this.hint}onNetwork(e){return this.networkListeners.push(e),()=>{let t=this.networkListeners.indexOf(e);t>=0&&this.networkListeners.splice(t,1);}}fail(e,t){this.prefetching.delete(e),this.cancelled.delete(e);let n=this.waiting.get(e);n!==void 0&&(this.waiting.delete(e),n.needed&&Zp(),n.reject(new FI(e,t)));}prefetch(e,t=Je.prefetch){let n=this.uncatalogued(e);if(n!==null)return n.then(()=>this.prefetch(e,t)),true;let r=this.parted.get(e);if(r!==void 0)for(let l of r)l.lazy===true&&!this.assetParts.holds(l.chunk)&&this.prefetch(l.chunk,t);let o=this.resolve(e),s=this.channel;if(s===null||!this.lazyDigests.has(o))return false;if(this.arrived.has(o)||this.waiting.has(o))return true;let a=this.prefetching.get(o);return a!==void 0&&a<=t||(this.cancelled.delete(o),this.prefetching.set(o,t),s.request(o,t)),true}cancelPrefetch(e){let t=this.parted.get(e);if(t!==void 0)for(let o of t)o.lazy===true&&this.cancelPrefetch(o.chunk);let n=this.resolve(e),r=this.channel;return r===null?false:this.prefetching.delete(n)?(this.cancelled.add(n),r.release(n),true):this.prefetched.delete(n)?(this.arrived.delete(n),r.release(n),true):false}resident(e){let t=this.parted.get(e);if(t!==void 0&&!t.every(r=>this.arrived.has(r.chunk)||this.assetParts.holds(r.chunk)))return false;let n=this.resolve(e);return this.arrived.has(n)||this.assetParts.holds(n)}pending(e){let t=this.parted.get(e);if(t!==void 0&&t.some(r=>this.pending(r.chunk)))return true;let n=this.resolve(e);return this.prefetching.has(n)||this.waiting.has(n)}lazy(e){return this.lazyDigests.has(this.resolve(e))}requests(){return this.channel!==null}isProgressive(e){return this.progressiveAssets.has(e)}progressive(e,t=null,n=Je.now,r=Je.soon){let o=new $A(e,t),s=this.uncatalogued(e);return s!==null?(n===Je.now&&eb(),s.then(()=>{n===Je.now&&Zp(),this.feedProgressive(o,e,n,r);}),o):(this.feedProgressive(o,e,n,r),o)}feedProgressive(e,t,n,r){if(!this.progressiveAssets.has(t)){this.takeStored(t,n,n===Je.now).then(a=>e.complete(a),a=>e.fail(a));return}if(!this.parted.has(t)){this.takeStored(t,n,n===Je.now).then(a=>e.whole(a),a=>e.fail(a));return}let o=n===Je.now,s={take:(a,l)=>this.takeStored(a,l,o&&l===n),release:a=>this.release(a)};this.assetParts.stream(this.resolve(t),n,r,s,e).catch(a=>e.fail(a));}take(e,t=Je.now,n=t===Je.now){let r=this.uncatalogued(e);if(r!==null)return n&&eb(),r.then(()=>(n&&Zp(),this.take(e,t,n)));let o=this.takeStored(e,t,n);return this.progressiveAssets.has(e)?o.then(o8):o}takeStored(e,t,n){if(this.parted.has(e)){let c={take:(u,d)=>this.takeStored(u,d,n),release:u=>this.release(u)};return this.assetParts.assemble(this.resolve(e),t,c)}let r=this.resolve(e),o=this.arrived.get(r);if(o!==void 0)return this.arrived.delete(r),this.prefetched.delete(r),Promise.resolve(o);if(this.waiting.has(r))return Promise.reject(new Error(`chunk ${r} is already being awaited`));let s=this.prefetching.get(r);this.prefetching.delete(r);let a=this.channel!==null&&this.lazyDigests.has(r),l=a&&n;return new Promise((c,u)=>{this.waiting.set(r,{resolve:c,reject:u,needed:l}),l&&eb(),a&&(s===void 0||t<s)&&this.channel?.request(r,t);})}release(e){let t=this.resolve(e);this.prefetched.delete(t)&&this.arrived.delete(t),this.channel!==null&&this.lazyDigests.has(t)&&this.channel.release(t);}},FI=class extends Error{constructor(t,n){super(`the host could not deliver chunk ${t} (${n})`);this.digest=t;this.reason=n;this.name="ChunkUnavailable";}};var Ii="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";var Tye=[9,10,12,13,32],wye=Iye();function Iye(){let i=new Uint8Array(128).fill(255);for(let e=0;e<Ii.length;e++)i[Ii.charCodeAt(e)]=e;i[45]=i[43],i[95]=i[47];for(let e of Tye)i[e]=254;return i}function UI(i){return i<128?wye[i]:255}function tb(i){let e=i.length;for(;e>0&&(i.charCodeAt(e-1)===61||UI(i.charCodeAt(e-1))===254);)e--;let t=0;for(let a=0;a<e;a++){let l=UI(i.charCodeAt(a));if(l===255)throw new Error("the text is not valid base64");l!==254&&t++;}if(t%4===1)throw new Error("the text is not valid base64");let n=new Uint8Array(Math.floor(t*6/8)),r=0,o=0,s=0;for(let a=0;a<e;a++){let l=UI(i.charCodeAt(a));l!==254&&(r=(r<<6|l)&16777215,o+=6,o>=8&&(o-=8,n[s++]=r>>o&255));}return n}function Vu(i){let e="",t=0;for(;t+3<=i.length;t+=3){let r=i[t]<<16|i[t+1]<<8|i[t+2];e+=Ii[r>>18&63]+Ii[r>>12&63]+Ii[r>>6&63]+Ii[r&63];}let n=i.length-t;if(n===1){let r=i[t]<<16;e+=`${Ii[r>>18&63]}${Ii[r>>12&63]}==`;}else if(n===2){let r=i[t]<<16|i[t+1]<<8;e+=`${Ii[r>>18&63]}${Ii[r>>12&63]}${Ii[r>>6&63]}=`;}return e}var nb={max_ai_content_retries:2,max_ai_content_timeout_ms:2e4,min_ai_content_timeout_ms:100},d8={program:{confirmation:"never",consent:null,fan_out:null,frames:[],locations:["client","local_worker","room","remote_job"],minimum_tier:"builder",minors:"unrestricted",records:["host"]},clock:{confirmation:"never",consent:null,fan_out:null,frames:[],locations:["client","local_worker","room","remote_job"],minimum_tier:"builder",minors:"unrestricted",records:["host"]},random:{confirmation:"never",consent:null,fan_out:null,frames:[],locations:["client","local_worker","room","remote_job"],minimum_tier:"builder",minors:"unrestricted",records:["host"]},locale:{confirmation:"never",consent:null,fan_out:null,frames:[],locations:["client","local_worker"],minimum_tier:"builder",minors:"unrestricted",records:["host"]},identity:{confirmation:"never",consent:null,fan_out:null,frames:[],locations:["client","local_worker","room","remote_job"],minimum_tier:"builder",minors:"unrestricted",records:["domain"]},social:{confirmation:"always",consent:"friends",fan_out:null,frames:[],locations:["client"],minimum_tier:"builder",minors:"limited",records:["domain"]},store:{confirmation:"never",consent:null,fan_out:null,frames:[],locations:["client","local_worker","room","remote_job"],minimum_tier:"builder",minors:"unrestricted",records:["sift"]},schedule:{confirmation:"never",consent:null,fan_out:null,frames:[],locations:["client","room","remote_job"],minimum_tier:"builder",minors:"unrestricted",records:["sift"]},compute:{confirmation:"never",consent:null,fan_out:null,frames:[],locations:["client","local_worker","room","remote_job"],minimum_tier:"builder",minors:"unrestricted",records:["sift"]},worker:{confirmation:"never",consent:null,fan_out:null,frames:[],locations:["client","room","remote_job"],minimum_tier:"builder",minors:"unrestricted",records:["sift"]},room:{confirmation:"never",consent:null,fan_out:"spatial",frames:["room_input","ack"],locations:["client","room","remote_job"],minimum_tier:"builder",minors:"unrestricted",records:["spatial","sift"]},channel:{confirmation:"never",consent:null,fan_out:"spatial",frames:["channel","ack"],locations:["client","room"],minimum_tier:"builder",minors:"unrestricted",records:["spatial"]},world:{confirmation:"never",consent:null,fan_out:"spatial",frames:["move_input","presence_tick"],locations:["client","room"],minimum_tier:"builder",minors:"unrestricted",records:["spatial"]},"game.leaderboards":{confirmation:"never",consent:null,fan_out:null,frames:[],locations:["client","room","remote_job"],minimum_tier:"builder",minors:"unrestricted",records:["sift"]},"game.achievements":{confirmation:"never",consent:null,fan_out:null,frames:[],locations:["client","room","remote_job"],minimum_tier:"builder",minors:"unrestricted",records:["sift"]},"game.economy":{confirmation:"never",consent:null,fan_out:null,frames:[],locations:["client","room","remote_job"],minimum_tier:"builder",minors:"unrestricted",records:["sift","postgres"]},"services.catalogue":{confirmation:"never",consent:null,fan_out:null,frames:[],locations:["client","remote_job"],minimum_tier:"builder",minors:"unrestricted",records:["domain"]},"services.cart":{confirmation:"never",consent:null,fan_out:null,frames:[],locations:["client"],minimum_tier:"builder",minors:"unrestricted",records:["domain"]},"services.delivery":{confirmation:"never",consent:null,fan_out:null,frames:[],locations:["client"],minimum_tier:"builder",minors:"unrestricted",records:["domain"]},"services.purchase_intents":{confirmation:"always",consent:null,fan_out:null,frames:[],locations:["client"],minimum_tier:"builder",minors:"unrestricted",records:["domain"]},"services.orders":{confirmation:"never",consent:null,fan_out:null,frames:[],locations:["client"],minimum_tier:"builder",minors:"unrestricted",records:["domain"]},"services.scheduling":{confirmation:"always",consent:null,fan_out:null,frames:[],locations:["client"],minimum_tier:"builder",minors:"unrestricted",records:["domain"]},"services.places":{confirmation:"never",consent:null,fan_out:null,frames:[],locations:["client"],minimum_tier:"builder",minors:"unrestricted",records:["domain"]},"services.arcs":{confirmation:"never",consent:null,fan_out:null,frames:[],locations:["client","remote_job"],minimum_tier:"builder",minors:"unrestricted",records:["domain"]},gifts:{confirmation:"always",consent:null,fan_out:null,frames:[],locations:["client"],minimum_tier:"verified_developer",minors:"limited",records:["postgres"]},wallet:{confirmation:"always",consent:null,fan_out:null,frames:[],locations:["client"],minimum_tier:"verified_developer",minors:"limited",records:["postgres"]},ads:{confirmation:"always",consent:null,fan_out:null,frames:[],locations:["client"],minimum_tier:"verified_developer",minors:"limited",records:["postgres"]},notify:{confirmation:"never",consent:"notifications",fan_out:null,frames:[],locations:["client","room","remote_job"],minimum_tier:"builder",minors:"unrestricted",records:["domain"]},moderate:{confirmation:"never",consent:null,fan_out:null,frames:[],locations:["client","room","remote_job"],minimum_tier:"builder",minors:"unrestricted",records:["domain"]},report:{confirmation:"always",consent:null,fan_out:null,frames:[],locations:["client"],minimum_tier:"builder",minors:"unrestricted",records:["domain"]},actions:{confirmation:"always",consent:null,fan_out:null,frames:[],locations:["client"],minimum_tier:"builder",minors:"unrestricted",records:["domain"]},provider:{confirmation:"when_consequential",consent:null,fan_out:null,frames:[],locations:["client","remote_job"],minimum_tier:"builder",minors:"unrestricted",records:["domain"]},flow:{confirmation:"never",consent:null,fan_out:null,frames:[],locations:["client","remote_job"],minimum_tier:"builder",minors:"unrestricted",records:["domain"]},agent:{confirmation:"never",consent:null,fan_out:null,frames:[],locations:["client"],minimum_tier:"builder",minors:"unrestricted",records:["domain"]},share:{confirmation:"always",consent:null,fan_out:null,frames:[],locations:["client"],minimum_tier:"builder",minors:"unrestricted",records:["domain"]},camera:{confirmation:"always",consent:"camera",fan_out:null,frames:[],locations:["client"],minimum_tier:"builder",minors:"unrestricted",records:["host"]},db:{confirmation:"never",consent:null,fan_out:null,frames:[],locations:["client","room","remote_job"],minimum_tier:"builder",minors:"unrestricted",records:["sift"]},tx:{confirmation:"never",consent:null,fan_out:null,frames:[],locations:["client","room","remote_job"],minimum_tier:"builder",minors:"unrestricted",records:["sift"]},kv:{confirmation:"never",consent:null,fan_out:null,frames:["fast_read","fast_value"],locations:["client","room","remote_job"],minimum_tier:"builder",minors:"unrestricted",records:["sift"]},cache:{confirmation:"never",consent:null,fan_out:null,frames:["fast_read","fast_value"],locations:["client","room","remote_job"],minimum_tier:"builder",minors:"unrestricted",records:["sift"]},blob:{confirmation:"never",consent:null,fan_out:null,frames:[],locations:["client","room","remote_job"],minimum_tier:"builder",minors:"unrestricted",records:["sift"]},counter:{confirmation:"never",consent:null,fan_out:null,frames:["counter_add","counter_value"],locations:["client","room","remote_job"],minimum_tier:"builder",minors:"unrestricted",records:["sift"]},queue:{confirmation:"never",consent:null,fan_out:null,frames:[],locations:["client","room","remote_job"],minimum_tier:"builder",minors:"unrestricted",records:["sift"]},search:{confirmation:"never",consent:null,fan_out:null,frames:[],locations:["client","room","remote_job"],minimum_tier:"builder",minors:"unrestricted",records:["sift"]},ai:{confirmation:"never",consent:"ai",fan_out:null,frames:[],locations:["client","room","remote_job"],minimum_tier:"builder",minors:"limited",records:["domain"]},pubsub:{confirmation:"never",consent:null,fan_out:"sift",frames:[],locations:["client","room","remote_job"],minimum_tier:"builder",minors:"unrestricted",records:["sift"]},analytics:{confirmation:"never",consent:null,fan_out:null,frames:[],locations:["client","local_worker","room","remote_job"],minimum_tier:"builder",minors:"unrestricted",records:["sift"]},secrets:{confirmation:"never",consent:null,fan_out:null,frames:[],locations:["room","remote_job"],minimum_tier:"builder",minors:"unrestricted",records:["domain"]},events:{confirmation:"never",consent:null,fan_out:null,frames:[],locations:["client","local_worker","room","remote_job"],minimum_tier:"builder",minors:"unrestricted",records:["host"]}};var jl={arkit:["eye_blink_left","eye_look_down_left","eye_look_in_left","eye_look_out_left","eye_look_up_left","eye_squint_left","eye_wide_left","eye_blink_right","eye_look_down_right","eye_look_in_right","eye_look_out_right","eye_look_up_right","eye_squint_right","eye_wide_right","jaw_forward","jaw_left","jaw_right","jaw_open","mouth_close","mouth_funnel","mouth_pucker","mouth_left","mouth_right","mouth_smile_left","mouth_smile_right","mouth_frown_left","mouth_frown_right","mouth_dimple_left","mouth_dimple_right","mouth_stretch_left","mouth_stretch_right","mouth_roll_lower","mouth_roll_upper","mouth_shrug_lower","mouth_shrug_upper","mouth_press_left","mouth_press_right","mouth_lower_down_left","mouth_lower_down_right","mouth_upper_up_left","mouth_upper_up_right","brow_down_left","brow_down_right","brow_inner_up","brow_outer_up_left","brow_outer_up_right","cheek_puff","cheek_squint_left","cheek_squint_right","nose_sneer_left","nose_sneer_right","tongue_out"],expressions:["smile","jaw_open","blink_left","blink_right","brow_raise","pucker"],head_pose:["yaw","pitch","roll","x","y","z"]},rb={identity_codes:["unavailable","cancelled","refused","consent"],view_default_layer:"over",view_default_mirror:true},BI=1,ib=1200,an={game_channel_reliable_base:32,game_channel_slots:64,max_channel_payload_bytes:1188,max_fast_key_bytes:256,max_fast_value_bytes:1180,max_presence_entries:98,max_room_input_payload_bytes:1184},Ir={axis_scale:32767,position_units_per_metre:256,yaw_units_per_turn:65536},et={channel:{code:1,header_bytes:12,fields:{tag:0,flags:1,slot:2,sequence:4,sender:8,payload_length:10,payload:12}},room_input:{code:2,header_bytes:16,fields:{tag:0,flags:1,action:2,sequence:4,client_tick:8,sender:12,payload_length:14,payload:16}},move_input:{code:3,header_bytes:16,fields:{tag:0,buttons:1,sequence:2,client_tick:4,axis_x:8,axis_z:10,yaw:12,layer:14,subtick:15}},presence_tick:{code:4,header_bytes:16,entry_bytes:12,fields:{flags:1,count:2,server_tick:4,cell_index:8,acked_input:12,layer:14,baseline_age:15},entry_fields:{slot:0,x:2,y:4,z:6,yaw:8,animation:10,flags:11}},ack:{code:5,header_bytes:12,fields:{tag:0,reserved:1,slot:2,sequence:4,received_mask:8}},fast_read:{code:6,header_bytes:12,fields:{tag:0,target:1,slot:2,correlation:4,key_length:8,reserved:10}},fast_value:{code:7,header_bytes:20,fields:{status:1,slot:2,correlation:4,stamp_low:8,stamp_high:12,value_length:16,reserved:18,value:20}},counter_add:{code:8,header_bytes:16,fields:{tag:0,status:1,slot:2,correlation:4,low:8,high:12}},counter_value:{code:9},presence_delta:{code:10,header_bytes:16,fields:{flags:1,count:2,server_tick:4,cell_index:8,acked_input:12,layer:14,baseline_age:15}}},Oi={room_input:{command:1},move_input:{sprint:2},presence_tick:{keyframe:1},presence_delta:{entry_x:1,entry_y:2,entry_z:4,entry_yaw:8,entry_animation:16,entry_flags:32,entry_full:128}},tm={fast_status:{denied:2,miss:1,not_found:6,ok:0,quota_exceeded:4,rate_limited:5,unavailable:3},fast_target:{cache:1,kv:0}};var h8=1,ur=4,Ci=h8,sb=Ci+ur,si=h8+ur,ab=si+ur,p8=si+ur*3,GI=si,VI=GI+1,m8=0,HI=rb.identity_codes;function f8(i){return HI[i-1]??"unavailable"}var Ia=0,Jl=-1,WI={track:0,view:1},_8=si,KI=si+1,lb={shown:1,mirror:2,over:4},Hu=si,YI=Hu+ur*4,y8=YI+1,Or={sequence:0,faces:1,header_words:3,expression_floats:jl.expressions.length,arkit_floats:jl.arkit.length,pose_floats:jl.head_pose.length},Oye=Or.expression_floats+Or.arkit_floats+Or.pose_floats,XI=(Or.header_words+Oye)*ur,qI=Or.faces*ur,zI=XI-qI,A8=si+zI,QI={notOpen:"stream_not_open",badPlacement:"camera_bad_placement"},$I={mirror:rb.view_default_mirror,layer:rb.view_default_layer};function nm(i,e){return i[e]|i[e+1]<<8|i[e+2]<<16|i[e+3]<<24}function Oa(i,e){return nm(i,e)>>>0}function Eo(i,e,t){i[e]=t&255,i[e+1]=t>>>8&255,i[e+2]=t>>>16&255,i[e+3]=t>>>24&255;}var b8=new Float32Array(1),ob=new Uint8Array(b8.buffer);function rm(i,e,t){b8[0]=t,i[e]=ob[0],i[e+1]=ob[1],i[e+2]=ob[2],i[e+3]=ob[3];}yn();var Nye="cancelled",g8=new TextEncoder,kye=new TextDecoder,v8=sb,R8=v8+ur,Lye=R8+ur,E8="over",Mye="under";function cb(i){return typeof i=="number"&&Number.isFinite(i)}function x8(i){let e;try{e=JSON.parse(i);}catch{return null}if(e===null||typeof e!="object")return null;let{x:t,y:n,width:r,height:o}=e;if(!cb(t)||!cb(n)||!cb(r)||!cb(o)||r<0||o<0)return null;let s=e.mirror===void 0?$I.mirror:e.mirror,a=e.layer===void 0?$I.layer:e.layer;return typeof s!="boolean"||a!==E8&&a!==Mye?null:{x:t,y:n,width:r,height:o,mirror:s,over:a===E8}}var ub=class{constructor(e){this.port=e;this.opening=new Map;this.painting=new Map;this.trackers=new Map;this.tracked=new Map;this.views=new Map;this.identifying=new Map;this.next=0;}track(e,t){let n=this.trackers.get(e);if(n!==void 0)return t(this.attach(n),"");this.open(e,WI.track,(r,o)=>{if(r===Ia)return t(null,o);this.trackers.set(e,r),t(this.attach(r),"");});}untrack(e){let t=this.trackers.get(e);t!==void 0&&(this.trackers.delete(e),this.tracked.delete(t),this.signal(ee.camera_untrack,t),this.signal(ee.camera_close,t));}colours(e,t){let n=this.trackers.get(e);if(n===void 0)return t(Jl,Jl,Jl);let r=this.request();this.painting.set(r,t);let o=this.port.reserve(ab),s=this.port.out;s[o]=ee.camera_colours,Eo(s,o+Ci,n),Eo(s,o+sb,r),this.port.commitTask();}view(e,t,n){let r=x8(t);if(r===null)return n(Ia,QI.badPlacement);this.open(e,WI.view,(o,s)=>{if(o===Ia)return n(Ia,s);let a={placement:r,shown:true};this.views.set(o,a),this.sendPlace(o,a),n(o,"");});}place(e,t){let n=this.views.get(e),r=x8(t);return n===void 0||r===null?false:(n.placement=r,this.sendPlace(e,n),true)}hide(e){this.setShown(e,false);}show(e){this.setShown(e,true);}close_view(e){this.views.delete(e)&&this.signal(ee.camera_close,e);}capture_identity(e,t){let n=this.request();this.identifying.set(n,t);let r=g8.encode(e),o=this.port.reserve(si+r.length),s=this.port.out;s[o]=ee.camera_identify,Eo(s,o+Ci,n),s.set(r,o+si),this.port.commitTask();}receive(e){switch(e[0]){case ee.camera_face:return this.face(e),true;case ee.camera_opened:return this.opened(e),true;case ee.camera_coloured:return this.coloured(e),true;case ee.camera_identified:return this.identified(e),true}return false}dispose(){let e=[...this.opening.values()],t=[...this.painting.values()],n=[...this.identifying.values()];this.opening.clear(),this.painting.clear(),this.identifying.clear();for(let r of n)r(null,Nye);this.trackers.clear(),this.tracked.clear(),this.views.clear();for(let r of e)r(Ia,QI.notOpen);for(let r of t)r(Jl,Jl,Jl);}setShown(e,t){let n=this.views.get(e);n===void 0||n.shown===t||(n.shown=t,this.sendPlace(e,n));}sendPlace(e,t){let n=this.port.reserve(y8),r=this.port.out,o=t.placement;r[n]=ee.camera_place,Eo(r,n+Ci,e),rm(r,n+Hu,o.x),rm(r,n+Hu+ur,o.y),rm(r,n+Hu+ur*2,o.width),rm(r,n+Hu+ur*3,o.height),r[n+YI]=(t.shown?lb.shown:0)|(o.mirror?lb.mirror:0)|(o.over?lb.over:0),this.port.commitTask();}face(e){if(e.length<A8)return;let t=this.tracked.get(Oa(e,Ci));if(t===void 0)return;let n=t.bytes;for(let r=0;r<zI;r++)n[qI+r]=e[si+r];t.header[Or.sequence]=t.header[Or.sequence]+1>>>0;}opened(e){if(e.length<ab)return;let t=Oa(e,Ci),n=this.opening.get(t);if(n===void 0)return;this.opening.delete(t);let r=Oa(e,sb);n(r,r===Ia?kye.decode(e.subarray(ab)):"");}coloured(e){if(e.length<p8)return;let t=Oa(e,Ci),n=this.painting.get(t);n!==void 0&&(this.painting.delete(t),n(nm(e,v8),nm(e,R8),nm(e,Lye)));}identified(e){if(e.length<VI)return;let t=Oa(e,Ci),n=this.identifying.get(t);if(n===void 0)return;this.identifying.delete(t);let r=e[GI],o=e.subarray(VI);r===m8&&o.length>0?n(Vu(o),""):n(null,f8(r));}open(e,t,n){let r=this.request();this.opening.set(r,n);let o=g8.encode(e),s=this.port.reserve(KI+o.length),a=this.port.out;a[s]=ee.camera_open,Eo(a,s+Ci,r),a[s+_8]=t,a.set(o,s+KI),this.port.commitTask();}attach(e){let t=new ArrayBuffer(XI);return this.tracked.set(e,{bytes:new Uint8Array(t),header:new Uint32Array(t,0,Or.header_words)}),this.signal(ee.camera_track,e),t}request(){return this.next=this.next+1>>>0,this.next===Ia&&(this.next=1),this.next}signal(e,t){let n=this.port.reserve(si),r=this.port.out;r[n]=e,Eo(r,n+Ci,t),this.port.commitTask();}};var ZI="video/mp4";var S8=[65536,0,0,0,65536,0,0,0,1073741824],Dye=["isom","iso6","avc1","mp41"],Pye="VideoHandler",Fye="SoundHandler";function eO(i){let{ring:e,from:t,to:n}=i.video.range;return n<=t?0:Math.round((e.time(n-1)+e.duration(n-1)-e.time(t))/1e3)}var JI=class{constructor(){this.at=0;this.view=null;this.bytes=null;this.base=0;}target(e,t){this.bytes=e,this.view=e===null?null:new DataView(e.buffer,e.byteOffset,e.byteLength),this.base=t,this.at=0;}u8(e){this.view?.setUint8(this.base+this.at,e),this.at+=1;}u16(e){this.view?.setUint16(this.base+this.at,e,false),this.at+=2;}i16(e){this.view?.setInt16(this.base+this.at,e,false),this.at+=2;}u24(e){this.u8(e>>>16&255),this.u16(e&65535);}u32(e){this.view?.setUint32(this.base+this.at,e>>>0,false),this.at+=4;}i32(e){this.view?.setInt32(this.base+this.at,e,false),this.at+=4;}u64(e){this.u32(Math.floor(e/4294967296)),this.u32(e>>>0);}zeros(e){this.bytes!==null&&this.bytes.fill(0,this.base+this.at,this.base+this.at+e),this.at+=e;}ascii(e){for(let t=0;t<e.length;t++)this.u8(e.charCodeAt(t));}bytesFrom(e,t,n){this.bytes!==null&&this.bytes.set(e.subarray(t,t+n),this.base+this.at),this.at+=n;}box(e,t){let n=this.at;this.u32(0),this.ascii(e),t(),this.view?.setUint32(this.base+n,this.at-n,false);}full(e,t,n,r){this.box(e,()=>{this.u8(t),this.u24(n),r();});}patch32(e,t){this.view?.setInt32(this.base+e,t,false);}};function db(i,e){return Math.round(i*e/1e6)}function T8(i){return i.codec==="opus"?48e3:i.sample_rate}function jI(i,e){if(e<=127){i.u8(e);return}i.u8(128|e>>>21&127),i.u8(128|e>>>14&127),i.u8(128|e>>>7&127),i.u8(e&127);}function w8(i){return i<=127?1:4}var hb=class{constructor(e){this.plan=e;this.w=new JI;}size(){return this.w.target(null,0),this.write(),this.w.at}into(e,t){return this.w.target(e,t),this.write(),this.w.at}write(){let e=this.w;e.box("ftyp",()=>{e.ascii("isom"),e.u32(512);for(let o of Dye)e.ascii(o);}),this.moov();let t=e.at,n=this.moof(),r=e.at+8-t;e.patch32(n.video,r),n.audio>=0&&e.patch32(n.audio,r+this.rangeBytes(this.plan.video.range)),this.mdat();}durationMs(){return eO(this.plan)}moov(){let e=this.w,t=this.plan;e.box("moov",()=>{e.full("mvhd",0,0,()=>{e.u32(0),e.u32(0),e.u32(1e3),e.u32(0),e.u32(65536),e.u16(256),e.zeros(10);for(let n of S8)e.u32(n);e.zeros(24),e.u32(t.audio===null?2:3);}),this.videoTrak(),t.audio!==null&&this.audioTrak(t.audio.track),e.box("mvex",()=>{e.full("mehd",0,0,()=>e.u32(this.durationMs())),this.trex(1),t.audio!==null&&this.trex(2);});});}trex(e){let t=this.w;t.full("trex",0,0,()=>{t.u32(e),t.u32(1),t.u32(0),t.u32(0),t.u32(0);});}tkhd(e,t,n,r){let o=this.w;o.full("tkhd",0,3,()=>{o.u32(0),o.u32(0),o.u32(e),o.u32(0),o.u32(0),o.zeros(8),o.u16(0),o.u16(t?1:0),o.u16(t?256:0),o.u16(0);for(let s of S8)o.u32(s);o.u32(n*65536),o.u32(r*65536);});}mdhd(e){let t=this.w;t.full("mdhd",0,0,()=>{t.u32(0),t.u32(0),t.u32(e),t.u32(0),t.u16(21956),t.u16(0);});}hdlr(e,t){let n=this.w;n.full("hdlr",0,0,()=>{n.u32(0),n.ascii(e),n.zeros(12),n.ascii(t),n.u8(0);});}dinf(){let e=this.w;e.box("dinf",()=>{e.full("dref",0,0,()=>{e.u32(1),e.full("url ",0,1,()=>{});});});}emptyTables(){let e=this.w;e.full("stts",0,0,()=>e.u32(0)),e.full("stsc",0,0,()=>e.u32(0)),e.full("stsz",0,0,()=>{e.u32(0),e.u32(0);}),e.full("stco",0,0,()=>e.u32(0));}videoTrak(){let e=this.w,t=this.plan.video.track;e.box("trak",()=>{this.tkhd(1,false,t.width,t.height),e.box("mdia",()=>{this.mdhd(9e4),this.hdlr("vide",Pye),e.box("minf",()=>{e.full("vmhd",0,1,()=>e.zeros(8)),this.dinf(),e.box("stbl",()=>{e.full("stsd",0,0,()=>{e.u32(1),e.box("avc1",()=>{e.zeros(6),e.u16(1),e.zeros(16),e.u16(t.width),e.u16(t.height),e.u32(4718592),e.u32(4718592),e.u32(0),e.u16(1),e.zeros(32),e.u16(24),e.u16(65535),e.box("avcC",()=>e.bytesFrom(t.description,0,t.description.length));});}),this.emptyTables();});});});});}audioTrak(e){let t=this.w;t.box("trak",()=>{this.tkhd(2,true,0,0),t.box("mdia",()=>{this.mdhd(T8(e)),this.hdlr("soun",Fye),t.box("minf",()=>{t.full("smhd",0,0,()=>t.zeros(4)),this.dinf(),t.box("stbl",()=>{t.full("stsd",0,0,()=>{t.u32(1),t.box(e.codec==="opus"?"Opus":"mp4a",()=>{t.zeros(6),t.u16(1),t.zeros(8),t.u16(e.channels),t.u16(16),t.u32(0),t.u32((e.codec==="opus"?48e3:e.sample_rate)*65536),e.codec==="opus"?this.dops(e):this.esds(e);});}),this.emptyTables();});});});});}esds(e){let t=this.w,n=e.description??new Uint8Array(0),o=13+(1+w8(n.length)+n.length),a=4+w8(o)+o+3;t.full("esds",0,0,()=>{t.u8(3),jI(t,a),t.u16(2),t.u8(0),t.u8(4),jI(t,o),t.u8(64),t.u8(21),t.u24(0),t.u32(0),t.u32(0),t.u8(5),jI(t,n.length),t.bytesFrom(n,0,n.length),t.u8(6),t.u8(1),t.u8(2);});}dops(e){let t=this.w,n=e.description,r=n!==null&&n.length>=19?new DataView(n.buffer,n.byteOffset,n.byteLength):null;t.box("dOps",()=>{t.u8(0),t.u8(r===null?e.channels:r.getUint8(9)),t.u16(r===null?312:r.getUint16(10,true)),t.u32(r===null?e.sample_rate:r.getUint32(12,true)),t.i16(r===null?0:r.getInt16(16,true)),t.u8(r===null?0:r.getUint8(18));});}rangeBytes(e){let t=0;for(let n=e.from;n<e.to;n++)t+=e.ring.length(n);return t}moof(){let e=this.w,t=this.plan,n=t.video.range.ring.time(t.video.range.from),r=0,o=-1;return e.box("moof",()=>{e.full("mfhd",0,0,()=>e.u32(1)),r=this.traf(1,t.video.range,9e4,n,true),t.audio!==null&&(o=this.traf(2,t.audio.range,T8(t.audio.track),n,false));}),{video:r,audio:o}}traf(e,t,n,r,o){let s=this.w,a=t.ring,l=0;return s.box("traf",()=>{s.full("tfhd",0,131072,()=>s.u32(e));let c=t.to>t.from?a.time(t.from):r;s.full("tfdt",1,0,()=>s.u64(Math.max(0,db(c-r,n)))),s.full("trun",0,o?1793:769,()=>{s.u32(t.to-t.from),l=s.at,s.i32(0);for(let u=t.from;u<t.to;u++){let d=db(a.time(u)-c,n),h=u+1<t.to?db(a.time(u+1)-c,n):db(a.time(u)+a.duration(u)-c,n);s.u32(Math.max(1,h-d)),s.u32(a.length(u)),o&&s.u32(a.key(u)?33554432:16842752);}});}),l}mdat(){let e=this.w,t=this.plan;e.box("mdat",()=>{this.samples(t.video.range),t.audio!==null&&this.samples(t.audio.range);});}samples(e){let t=e.ring;for(let n=e.from;n<e.to;n++)this.w.bytesFrom(t.arena,t.offset(n),t.length(n));}};function I8(i){return new hb(i).size()}function O8(i,e,t){return new hb(i).into(e,t)}function C8(i,e,t,n){let r=e.startFor(t);if(r<0)return null;let o=e.time(r),s={ring:e,from:r,to:e.count};if(n===null)return {video:{track:i,range:s},audio:null};let a=n.ring.firstAtOrAfter(o);return a<0?{video:{track:i,range:s},audio:null}:{video:{track:i,range:s},audio:{track:n.track,range:{ring:n.ring,from:a,to:n.ring.count}}}}var im=class{constructor(e){this.head=0;this.size=0;this.writePage=0;this.dropped=0;let t=e.page_bytes??1024,n=Math.max(1,Math.ceil(e.capacity_bytes/t));this.pageBytes=t,this.arena=new Uint8Array(n*t),this.pages=[];for(let r=0;r<n;r++)this.pages.push(this.arena.subarray(r*t));this.maxSamples=e.max_samples,this.starts=new Uint32Array(e.max_samples),this.lengths=new Uint32Array(e.max_samples),this.times=new Float64Array(e.max_samples),this.durations=new Float64Array(e.max_samples),this.keys=new Uint8Array(e.max_samples);}get count(){return this.size}get pageCount(){return this.pages.length}slot(e){return (this.head+e)%this.maxSamples}push(e,t,n,r){let o=e.byteLength,s=this.pages.length,a=Math.ceil(o/this.pageBytes)||1;if(a>s)return this.dropped++,false;this.size===0&&(this.writePage=0);let l=this.writePage,c=l+a>s,u=c?s-l+a:a;for(;this.size>0&&(this.size===this.maxSamples||(this.starts[this.head]-l+s)%s<u);)this.evict();let d=c?0:l;e.copyTo(this.pages[d]);let h=this.slot(this.size);this.starts[h]=d,this.lengths[h]=o,this.times[h]=t,this.durations[h]=n,this.keys[h]=r?1:0,this.size++;let p=d+a;return this.writePage=p===s?0:p,true}evict(){this.head=(this.head+1)%this.maxSamples,this.size--;}retain(e){if(this.size===0)return;let t=this.endUs()-e;for(;;){let n=this.nextKey(1);if(n===-1||this.times[this.slot(n)]>t)return;for(let r=0;r<n;r++)this.evict();}}nextKey(e){for(let t=e;t<this.size;t++)if(this.keys[this.slot(t)]===1)return t;return -1}endUs(){if(this.size===0)return 0;let e=this.slot(this.size-1);return this.times[e]+this.durations[e]}startFor(e){if(this.size===0)return -1;let t=this.endUs()-e,n=this.nextKey(0);if(n===-1)return -1;for(let r=n+1;r<this.size;r++){let o=this.slot(r);if(this.times[o]>t)break;this.keys[o]===1&&(n=r);}return n}firstAtOrAfter(e){for(let t=0;t<this.size;t++)if(this.times[this.slot(t)]>=e)return t;return -1}offset(e){return this.starts[this.slot(e)]*this.pageBytes}length(e){return this.lengths[this.slot(e)]}time(e){return this.times[this.slot(e)]}duration(e){return this.durations[this.slot(e)]}key(e){return this.keys[this.slot(e)]===1}clear(){this.head=0,this.size=0,this.writePage=0;}};yn();var Uye=15e3,Bye=30,Gye=4e6,Vye=1280,k8={window_ms:Uye,fps:Bye,video_bits_per_second:Gye,audio:true,max_long_edge:Vye},Ca={saved:0,empty:1,unavailable:2},Hye=Ae+8,L8=Ae,M8=L8+4,D8=M8+1,P8=D8+4,F8=P8+2,U8=F8+2,pb=U8+1,B8=255,Wu=true,N8=Ae+1;var Wye=1;function G8(i){return i.length<N8||i[0]!==ee.replay?null:{replay:i.slice(N8),mode:i[Ae]===Wye?"play":"watch"}}function V8(i){if(i.length<Hye)return null;let e=new DataView(i.buffer,i.byteOffset,i.byteLength);return {id:e.getUint32(Ae,Wu),keep_ms:e.getUint32(Ae+4,Wu)}}function mb(i){return pb+Math.min(i.length,B8)}function fb(i,e,t){let n=new DataView(i.buffer,i.byteOffset+e,pb);i[e]=ee.clip_saved,n.setUint32(L8,t.id>>>0,Wu),n.setUint8(M8,t.status),n.setUint32(D8,Math.max(0,t.duration_ms)>>>0,Wu),n.setUint16(P8,t.width,Wu),n.setUint16(F8,t.height,Wu);let r=Math.min(t.type.length,B8);n.setUint8(U8,r);for(let o=0;o<r;o++)i[e+pb+o]=t.type.charCodeAt(o)&127;return pb+r}yn();var om=1e3,X8=1e3,Kye=2*X8,_b=1.5,Yye=8,H8=1e3,Xye=24e3,qye=60,zye=128e3,Qye=2,$ye=.9,jye=1e3,Jye=1e3,Zye="mp4a.40.2",eAe="opus",tAe="avc1.64001f",nAe="avc1.640028",rAe="avc1.42e01f",iAe="avc1.42e028",oAe=3600,W8=16,sAe=["video/mp4;codecs=avc1,mp4a","video/mp4","video/webm;codecs=vp9,opus","video/webm"];function K8(i){return Math.max(2,i-i%2)}function aAe(i,e,t){let n=Math.min(1,t/Math.max(i,e,1));return {width:K8(Math.round(i*n)),height:K8(Math.round(e*n))}}function lAe(i,e){return Math.ceil(i/W8)*Math.ceil(e/W8)<=oAe?[tAe,rAe]:[nAe,iAe]}function Y8(i){return (ArrayBuffer.isView(i)?new Uint8Array(i.buffer,i.byteOffset,i.byteLength):new Uint8Array(i)).slice()}function q8(i){let e=i.body?.getElementsByTagName("canvas");if(e===void 0)return null;let t=null,n=0;for(let r=0;r<e.length;r++){let o=e[r],s=o.clientWidth*o.clientHeight;s>=n&&s>0&&(t=o,n=s);}return t}function sm(i,e,t){let n=mb(""),r=i.reserve(n);fb(i.out,r,{id:e,status:t,duration_ms:0,width:0,height:0,type:""}),i.commitTask();}var tO=class{constructor(e,t,n,r,o){this.scope=e;this.port=t;this.sources=n;this.arm=r;this.fallback=o;this.encoder=null;this.audioEncoder=null;this.reader=null;this.description=null;this.audioTrack=null;this.width=0;this.height=0;this.configuring=false;this.paused=false;this.running=true;this.lastFrame=-1/0;this.lastKey=-1/0;this.audioOffset=Number.NaN;this.tick=e=>{if(!this.running||(this.scope.requestAnimationFrame(this.tick),this.paused||e-this.lastFrame<this.frameMs*$ye))return;let t=this.sources.canvas();if(t===null||t.width===0||t.height===0)return;let n=aAe(t.width,t.height,this.arm.max_long_edge);if(n.width!==this.width||n.height!==this.height){this.configure(n.width,n.height);return}let r=this.encoder;if(r===null||r.state!=="configured"||r.encodeQueueSize>Qye)return;let o=Math.round(e*om),s=e-this.lastKey>=X8,a=this.scope.VideoFrame,l;try{l=new a(t,{timestamp:o});}catch{return}try{r.encode(l,{keyFrame:s});}finally{l.close();}this.lastFrame=e,s&&(this.lastKey=e);};let s=(r.window_ms+Kye)/H8;this.video=new im({capacity_bytes:Math.ceil(r.video_bits_per_second/Yye*s*_b),max_samples:Math.ceil(r.fps*s*_b)}),this.audio=new im({capacity_bytes:Math.ceil(Xye*s*_b),max_samples:Math.ceil(qye*s*_b)}),this.frameMs=H8/r.fps,this.windowUs=r.window_ms*om,e.requestAnimationFrame(this.tick),r.audio&&this.startAudio();}async configure(e,t){if(!this.configuring){this.configuring=true;try{let n=this.scope.VideoEncoder;for(let r of lAe(e,t)){let o={codec:r,width:e,height:t,bitrate:this.arm.video_bits_per_second,framerate:this.arm.fps,hardwareAcceleration:"prefer-hardware",latencyMode:"realtime",avc:{format:"avc"}};if(!(!(await n.isConfigSupported(o).catch(()=>({supported:!1}))).supported||!this.running)){this.encoder?.close(),this.video.clear(),this.description=null,this.lastKey=-1/0,this.encoder=new n({output:(a,l)=>this.videoOut(a,l),error:()=>this.dropEncoder()}),this.encoder.configure(o),this.width=e,this.height=t;return}}this.running&&this.fallback();}finally{this.configuring=false;}}}dropEncoder(){this.encoder=null,this.width=0,this.height=0;}videoOut(e,t){let n=t?.decoderConfig?.description;n!==void 0&&(this.description=Y8(n)),this.video.push(e,e.timestamp,e.duration??this.frameMs*om,e.type==="key"),this.video.retain(this.windowUs);}async startAudio(){let e=this.scope.MediaStreamTrackProcessor,t=this.scope.AudioEncoder,n=this.sources.audio()?.getAudioTracks()[0];if(e===void 0||t===void 0||n===void 0)return;let r=new e({track:n}).readable.getReader();for(this.reader=r;this.running;){let o=await r.read().catch(()=>({done:true}));if(o.done||o.value===void 0)return;let s=o.value;try{if(this.audioEncoder===null&&!await this.configureAudio(t,s))return;Number.isNaN(this.audioOffset)&&(this.audioOffset=Math.round(this.scope.performance.now()*om)-s.timestamp);let a=this.audioEncoder;a!==null&&a.state==="configured"&&a.encode(s);}finally{s.close();}}}async configureAudio(e,t){let n=[{codec:Zye,track:"mp4a"},{codec:eAe,track:"opus"}];for(let r of n){let o={codec:r.codec,sampleRate:t.sampleRate,numberOfChannels:t.numberOfChannels,bitrate:zye,...r.track==="mp4a"?{aac:{format:"aac"}}:{}};if(!(await e.isConfigSupported(o).catch(()=>({supported:false}))).supported)continue;let a=new e({output:(l,c)=>this.audioOut(l,c),error:()=>this.audioEncoder=null});return a.configure(o),this.audioEncoder=a,this.audioTrack={codec:r.track,sample_rate:t.sampleRate,channels:t.numberOfChannels,description:null},true}return false}audioOut(e,t){let n=this.audioTrack;if(n===null)return;let r=t?.decoderConfig?.description;r!==void 0&&(this.audioTrack={...n,description:Y8(r)}),this.audio.push(e,e.timestamp+this.audioOffset,e.duration??0,true),this.audio.retain(this.windowUs);}pause(e){this.paused=e;}save(e,t){let n=this.description;if(n===null){sm(this.port,e,Ca.empty);return}let r={width:this.width,height:this.height,description:n},o=this.audioTrack,s=o===null||o.codec==="mp4a"&&o.description===null?null:{track:o,ring:this.audio},a=C8(r,this.video,Math.min(t,this.arm.window_ms)*om,s);if(a===null){sm(this.port,e,Ca.empty);return}let l=mb(ZI),c=I8(a),u=this.port.reserve(l+c);fb(this.port.out,u,{id:e,status:Ca.saved,duration_ms:eO(a),width:r.width,height:r.height,type:ZI}),O8(a,this.port.out,u+l),this.port.commitTask();}stop(){this.running=false,this.reader?.cancel().catch(()=>{}),this.reader=null,this.encoder?.state!=="closed"&&this.encoder?.close(),this.audioEncoder?.state!=="closed"&&this.audioEncoder?.close(),this.encoder=null,this.audioEncoder=null,this.video.clear(),this.audio.clear();}},nO=class{constructor(e,t,n,r,o){this.scope=e;this.port=t;this.sources=n;this.arm=r;this.Recorder=o;this.slots=[null,null];this.canvas=null;this.stream=null;this.paused=false;this.running=true;this.type=sAe.find(s=>o.isTypeSupported(s))??"",this.timer=e.setInterval(()=>this.check(),Jye),this.check();}now(){return this.scope.performance.now()}check(){if(!this.running)return;let e=this.sources.canvas();e!==this.canvas&&this.rebuild(e);let t=this.now();for(let n=0;n<this.slots.length;n++){let r=this.slots[n];if(r===null){this.stream!==null&&(n===0||t-(this.slots[0]?.started??t)>=this.arm.window_ms)&&(this.slots[n]=this.open());continue}t-r.started>=2*this.arm.window_ms&&(this.discard(r),this.slots[n]=this.open());}}rebuild(e){for(let r=0;r<this.slots.length;r++){let o=this.slots[r];o!==null&&this.discard(o),this.slots[r]=null;}if(this.canvas=e,this.stream=null,e===null||typeof e.captureStream!="function")return;let t=e.captureStream(this.arm.fps),n=this.arm.audio?this.sources.audio():null;if(n!==null)for(let r of n.getAudioTracks())t.addTrack(r);this.stream=t;}open(){let e=this.stream;if(e===null||this.type==="")return null;let t=new this.Recorder(e,{mimeType:this.type,videoBitsPerSecond:this.arm.video_bits_per_second}),n={recorder:t,started:this.now(),chunks:[]};return t.ondataavailable=r=>{r.data.size>0&&n.chunks.push(r.data);},t.start(),this.paused&&t.pause(),n}discard(e){e.recorder.ondataavailable=null,e.recorder.onstop=null,e.recorder.state!=="inactive"&&e.recorder.stop(),e.chunks.length=0;}pause(e){this.paused=e;for(let t of this.slots)t!==null&&(e&&t.recorder.state==="recording"?t.recorder.pause():!e&&t.recorder.state==="paused"&&t.recorder.resume());}save(e,t){let n=-1;for(let a=0;a<this.slots.length;a++){let l=this.slots[a];l!==null&&(n<0||l.started<this.slots[n].started)&&(n=a);}if(n<0){sm(this.port,e,Ca.empty);return}let r=this.slots[n],o=Math.round(this.now()-r.started),s=this.canvas;this.slots[n]=this.open(),r.recorder.onstop=()=>{let a=new Blob(r.chunks,{type:this.type});r.chunks.length=0,a.arrayBuffer().then(l=>{let c=this.type.split(";")[0],u=mb(c),d=this.port.reserve(u+l.byteLength);fb(this.port.out,d,{id:e,status:Ca.saved,duration_ms:o,width:s?.width??0,height:s?.height??0,type:c}),this.port.out.set(new Uint8Array(l),d+u),this.port.commitTask();},()=>sm(this.port,e,Ca.empty));},r.recorder.stop();}stop(){this.running=false,this.scope.clearInterval(this.timer);for(let e=0;e<this.slots.length;e++){let t=this.slots[e];t!==null&&this.discard(t),this.slots[e]=null;}this.stream=null;}},rO=class{constructor(e,t){this.scope=e;this.find=t;this.canvas=null;this.checked=-1/0;}get(){let e=this.scope.performance.now();return (e-this.checked>=jye||this.canvas!==null&&!this.canvas.isConnected)&&(this.canvas=this.find(),this.checked=e),this.canvas}};function cAe(i){let e=i.performance,t=e.now.bind(e);return Object.freeze({document:i.document,performance:{now:t},requestAnimationFrame:i.requestAnimationFrame.bind(i),setInterval:i.setInterval.bind(i),clearInterval:i.clearInterval.bind(i),VideoEncoder:i.VideoEncoder,VideoFrame:i.VideoFrame,AudioEncoder:i.AudioEncoder,MediaStreamTrackProcessor:i.MediaStreamTrackProcessor,MediaRecorder:i.MediaRecorder,MediaStream:i.MediaStream})}var yb=class{constructor(e,t,n){this.port=t;this.pipeline=null;this.paused=false;this.scope=cAe(e);let r=new rO(this.scope,()=>n.canvas());this.sources={canvas:()=>r.get(),audio:()=>n.audio()};}get armed(){return this.pipeline!==null}receive(e){switch(e[0]){case ee.clip_arm:return this.arm(e.length>Ae?{...k8,...Ti(e)}:null),true;case ee.clip_pause:return this.paused=e[Ae]===1,this.pipeline?.pause(this.paused),true;case ee.clip_save:{let t=V8(e);return t===null||(this.pipeline===null?sm(this.port,t.id,Ca.unavailable):this.pipeline.save(t.id,t.keep_ms)),true}}return false}arm(e){this.pipeline?.stop(),this.pipeline=e===null?null:this.open(e),this.pipeline?.pause(this.paused);}open(e){let t=this.scope;if(typeof t.VideoEncoder=="function"&&typeof t.VideoFrame=="function"){let n=new tO(t,this.port,this.sources,e,()=>{this.pipeline===n&&(n.stop(),this.pipeline=this.recorder(e),this.pipeline?.pause(this.paused));});return n}return this.recorder(e)}recorder(e){let t=this.scope;return typeof t.MediaRecorder=="function"?new nO(t,this.port,this.sources,e,t.MediaRecorder):null}dispose(){this.pipeline?.stop(),this.pipeline=null;}};yn();var uAe=1,oO=4,Ab=uAe,Q8=Ab+oO,dAe=Q8+oO,iO=Ab+oO,z8=0,bb=class{constructor(e){this.port=e;this.waiting=new Map;this.next=z8;this.source=e=>new Promise(t=>{let n=this.request();this.waiting.set(n,t);let r=this.port.reserve(dAe),o=this.port.out;o[r]=ee.font_request,Eo(o,r+Ab,n),Eo(o,r+Q8,e),this.port.commitTask();});}receive(e){if(e[0]!==ee.font_reply)return false;if(e.length<iO)return true;let t=Oa(e,Ab),n=this.waiting.get(t);return n===void 0||(this.waiting.delete(t),n(e.length>iO?e.slice(iO):null)),true}dispose(){let e=[...this.waiting.values()];this.waiting.clear();for(let t of e)t(null);}request(){return this.next=this.next+1>>>0,this.next===z8&&(this.next=1),this.next}};var Ku={down:0,move:1,up:2,cancel:3};var hAe=1,pAe=2,mAe=16,fAe=800;function xb(i,e,t){return e===hAe?i*mAe:e===pAe?i*(t>0?t:fAe):i}var _Ae=0,yAe=1,AAe=2,bAe=3,gAe=4,EAe=5,xAe=6,iV=7,oV=24,sO=iV+oV,vAe=4,RAe=1,SAe=2048,TAe=2,am=0,$8=0,j8=0,J8=1,Z8=2,eV=3,wAe=4,IAe="visibility:hidden",Ib="position:fixed;inset:0;width:100%;height:100%;display:block;touch-action:none;outline:none",OAe="data-cimplify-engine",tV="data-cimplify-frame",CAe="canvas",NAe=[["texture-compression-bc",1],["texture-compression-etc2",2],["texture-compression-astc",4],["shader-f16",8],["indirect-first-instance",16],["rg11b10ufloat-renderable",32],["timestamp-query",64],["float32-filterable",128],["depth32float-stencil8",256]],aO=["maxTextureDimension1D","maxTextureDimension2D","maxTextureDimension3D","maxTextureArrayLayers","maxBindGroups","maxBindingsPerBindGroup","maxDynamicUniformBuffersPerPipelineLayout","maxDynamicStorageBuffersPerPipelineLayout","maxSampledTexturesPerShaderStage","maxSamplersPerShaderStage","maxStorageBuffersPerShaderStage","maxStorageTexturesPerShaderStage","maxUniformBuffersPerShaderStage","maxUniformBufferBindingSize","maxStorageBufferBindingSize","maxVertexBuffers","maxBufferSize","maxVertexAttributes","maxVertexBufferArrayStride","maxColorAttachments","maxComputeWorkgroupStorageSize","maxComputeInvocationsPerWorkgroup","maxComputeWorkgroupSizeX","maxComputeWorkgroupsPerDimension"],kAe=4294967295,nV={passive:false},rV=["pointerdown","pointermove","pointerup","pointercancel"],vb=0,Rb=1,Sb=2,Tb=3,LAe=4,lO=class{constructor(){this.top=0;this.right=0;this.bottom=0;this.left=0;}};async function sV(i){if(i===void 0)return null;let e=await i.requestAdapter({powerPreference:"high-performance"});if(e===null)return null;let t=0,n=[];for(let[a,l]of NAe)e.features.has(a)&&(n.push(a),t|=l);let r={},o=new Uint32Array(oV);for(let a=0;a<aO.length;a++){let l=e.limits[aO[a]];r[aO[a]]=l,o[a]=Math.min(l,kAe);}return {device:await e.requestDevice({requiredFeatures:n,requiredLimits:r}),features:t,limits:o,format:i.getPreferredCanvasFormat()}}function Ni(i,e){let t=i.exports[e];if(typeof t!="function")throw new _("unsupported_feature",`the engine module does not export ${e}`);return t}var wb=class{constructor(e,t,n,r,o=null){this.scope=e;this.canvas=t;this.detach=r;this.overlay=o;this.frames=[];this.resized=[];this.pointers=[];this.wheels=[];this.handle=am;this.first=true;this.released=false;this.frameTime=0;this.box=new Float64Array(wAe);this.insets=new Float64Array(LAe);this.safeListeners=[];this.safe_area=new lO;this.before_render=()=>{this.overlay!==null&&this.overlay.frame(this.frameTime);};this.tick=e=>{if(this.released)return;this.frameTime=e;let t=this.frames;for(let n=0;n<t.length;n++)t[n](e);this.first&&(this.first=false,this.canvas.hasAttribute(tV)||this.canvas.setAttribute(tV,"")),this.handle=t.length>0?this.scope.requestAnimationFrame(this.tick):am;};this.onResize=()=>{let e=this.canvas.clientWidth,t=this.canvas.clientHeight;if(!(e===this.width&&t===this.height)){this.width=e,this.height=t,this.measure(),this.overlay?.resize(e,t,this.pixel_ratio),this.readSafeArea();for(let n=0;n<this.resized.length;n++)this.resized[n](e,t,this.pixel_ratio);}};this.onWheel=e=>{let t=e.deltaMode,n=xb(e.deltaX,t,this.height),r=xb(e.deltaY,t,this.height);if(this.overlay!==null&&this.overlay.wheel(e.clientX,e.clientY,n,r)){e.preventDefault();return}let o=xb(e.deltaZ,t,this.height);for(let s=0;s<this.wheels.length;s++)this.wheels[s](n,r,o,e.clientX,e.clientY,e.timeStamp);};this.onPointer=e=>{let t=e.type==="pointerdown"?Ku.down:e.type==="pointermove"?Ku.move:e.type==="pointerup"?Ku.up:Ku.cancel;if(t===Ku.down&&(this.canvas.setPointerCapture(e.pointerId),this.measure()),this.overlay!==null&&this.overlay.pointer(t,e.pointerId,e.clientX,e.clientY,e.timeStamp))return;let n=this.box,r=(e.clientX-n[j8])/n[Z8],o=(e.clientY-n[J8])/n[eV];for(let s=0;s<this.pointers.length;s++)this.pointers[s](t,e.pointerId,r,o,e.timeStamp);};this.pixel_ratio=n,this.width=t.clientWidth,this.height=t.clientHeight,this.measure();let s=e.ResizeObserver;this.observer=s===void 0?null:new s(this.onResize),this.observer?.observe(t);for(let a of rV)t.addEventListener(a,this.onPointer);t.addEventListener("wheel",this.onWheel,nV),o?.resize(this.width,this.height,n),this.readSafeArea();}on_safe_area(e){return this.safeListeners.push(e),()=>{let t=this.safeListeners.indexOf(e);t>=0&&this.safeListeners.splice(t,1);}}readSafeArea(){let e=this.overlay;if(e===null||e.safeArea===void 0)return;let t=this.insets;e.safeArea(t);let n=this.safe_area;if(!(n.top===t[vb]&&n.right===t[Rb]&&n.bottom===t[Sb]&&n.left===t[Tb])){n.top=t[vb],n.right=t[Rb],n.bottom=t[Sb],n.left=t[Tb];for(let r=0;r<this.safeListeners.length;r++)this.safeListeners[r](n.top,n.right,n.bottom,n.left);}}measure(){let e=this.canvas.getBoundingClientRect(),t=this.box;t[j8]=e.left,t[J8]=e.top,t[Z8]=e.width>0?e.width:1,t[eV]=e.height>0?e.height:1;}on_frame(e){return this.frames.push(e),this.handle===am&&!this.released&&(this.handle=this.scope.requestAnimationFrame(this.tick)),()=>{let t=this.frames.indexOf(e);t>=0&&this.frames.splice(t,1);}}on_resize(e){return this.resized.push(e),()=>{let t=this.resized.indexOf(e);t>=0&&this.resized.splice(t,1);}}on_pointer(e){return this.pointers.push(e),()=>{let t=this.pointers.indexOf(e);t>=0&&this.pointers.splice(t,1);}}on_wheel(e){return this.wheels.push(e),()=>{let t=this.wheels.indexOf(e);t>=0&&this.wheels.splice(t,1);}}release(){if(!this.released){this.released=true,this.handle!==am&&this.scope.cancelAnimationFrame(this.handle),this.handle=am,this.observer?.disconnect();for(let e of rV)this.canvas.removeEventListener(e,this.onPointer);this.canvas.removeEventListener("wheel",this.onWheel,nV),this.overlay?.release(),this.detach(),this.canvas.remove();}}};function cO(i,e){return Math.min(i.devicePixelRatio||1,e??TAe)}function uO(i,e){let t=i.document.createElement("canvas");return t.setAttribute("style",e),t.tabIndex=0,t.id=CAe,t.setAttribute(OAe,""),i.document.body.appendChild(t),t}function aV(i,e,t,n){let{runtime:r,executor:o,device:s}=i,a=t.getContext("webgpu");if(a===null)throw new _("unsupported_feature","the canvas has no WebGPU context");let l=Ni(r,"engine_render_attach_web"),c=Ni(r,"engine_alloc"),u=Ni(r,"engine_free"),d=Math.max(1,Math.round(t.clientWidth*n)),h=Math.max(1,Math.round(t.clientHeight*n));t.width=d,t.height=h,o.bindTarget({device:s.device,context:a,canvas:t});let p=sO*Rt,m=c(p,ce);if(m===0)throw new _("capacity_exceeded","engine memory cannot hold the surface description");let f=new Uint32Array(r.memory.buffer,m,sO);f[_Ae]=d,f[yAe]=h,f[AAe]=s.features,f[bAe]=bo.indexOf(s.format),f[gAe]=vAe,new Float32Array(r.memory.buffer,m,sO)[EAe]=RAe,f[xAe]=SAe,f.set(s.limits,iV);let y=l(e,m);if(u(m,p,ce),y<0)throw o.unbind(),new _("unsupported_feature",`the engine could not attach its WebGPU presenter (${y})`)}function lV(i,e){let t=Ni(i.runtime,"engine_render_create")($8);if(t===$8)throw Pu(i.runtime.exports)??new _("capacity_exceeded","the engine could not create a renderer to warm");let n=uO(i.scope,`${Ib};${IAe}`),r=cO(i.scope,e);try{aV(i,t,n,r);}catch(o){throw Ni(i.runtime,"engine_render_destroy")(t),n.remove(),o}return {canvas:n,world:t,pixelRatio:r}}function MAe(i,e){Ni(i.runtime,"engine_render_destroy")(e.world),i.executor.unbind(),e.canvas.remove();}function DAe(i,e){let t=Ni(i.runtime,"engine_render_adopt")(i.render,e.world);return Ni(i.runtime,"engine_render_destroy")(e.world),t<0?(i.executor.unbind(),e.canvas.remove(),null):(e.canvas.setAttribute("style",Ib),e.canvas)}function cV(i){let{scope:e,runtime:t,executor:n,render:r,options:o,prepared:s}=i,a=cO(e,o.pixel_ratio_cap),l=s!==null&&s.pixelRatio===a?DAe(i,s):null;if(s!==null&&l===null&&s.pixelRatio!==a&&MAe(i,s),l===null){l=uO(e,Ib);try{aV(i,r,l,a);}catch(d){throw l.remove(),d}}let c=Ni(t,"engine_render_detach"),u=i.overlay?.(l,r,a)??null;return new wb(e,l,a,()=>{c(r),n.unbind();},u)}var PAe={alpha:false,antialias:false,depth:false,stencil:false,premultipliedAlpha:true,preserveDrawingBuffer:false};function uV(i){let{scope:e,runtime:t,executor:n,render:r,options:o}=i,s=cO(e,o.pixel_ratio_cap),a=uO(e,Ib),l=Math.max(1,Math.round(a.clientWidth*s)),c=Math.max(1,Math.round(a.clientHeight*s));a.width=l,a.height=c;let u=a.getContext("webgl2",PAe);if(u===null||!n.bindContext(u))throw a.remove(),new _("unsupported_feature","the canvas has no WebGL2 context that renders to half-float targets");let d=Ni(t,PA)(r,l,c);if(d<0)throw n.unbind(),a.remove(),new _("unsupported_feature",`the engine could not attach its WebGL2 presenter (${d})`);let h=Ni(t,"engine_render_detach"),p=i.overlay?.(a,r,s)??null;return new wb(e,a,s,()=>{h(r),n.unbind();},p)}var dV=new WeakMap;function hV(i,e){dV.set(i,e);}function lm(i){let e=dV.get(i);return e===void 0?i.destination:e}var pV="render_kernel_instances_1";var Ob="media_volume_1";var mV="render_feed_pose_1";var fV=["never","less","equal","lessEqual","greater","notEqual","greaterEqual","always"],dO=["add","subtract","reverseSubtract","min","max"],kn=["zero","one","srcColor","oneMinusSrcColor","srcAlpha","oneMinusSrcAlpha","dstColor","oneMinusDstColor","dstAlpha","oneMinusDstAlpha","srcAlphaSaturate"],Cb=["keep","zero","replace","increment","decrement","invert","incrementWrap","decrementWrap"];var _V=["point","sphere","cone","box","disc"],yV=["none","plane","depth"];var AV=["linear","exp2","height"];var bV={12:4194304,13:8388608,14:-2147483648},gV=17,EV=18,xV=19,vV=20,RV=21;var Nb=23,SV=24,TV=25,wV=26,IV=27,OV=28,CV=29,NV=32;var kV=33,LV=31,MV=32,kb=33,DV=34,PV=35,FV=36,UV=37,hO=38,BV=39,GV=40,VV=41,HV=42,pO=43,WV=44,KV=45,YV=46,XV=50,qV=51,zV=52,QV=54,$V=55,jV=60,JV=61,ZV=3,eH=4,tH=5,nH=6,rH=7,iH=8,oH=9,sH=10,aH=11,lH=12,cH=13,uH=14,dH=15,hH=16,pH=17,mH=3,fH=4,_H=5;var yH=1,AH=2,bH=3,gH=7,EH=5,xH=6,vH=8,mO=16,RH=4,SH=0,TH=1,wH=2,IH=11,OH=12,CH=13,NH=1,kH=2,LH=4,MH=29,DH=30,PH=31,FH=32,UH=33,BH=["off","field","full"],GH=20;var fO=64,_O=4,VH=47,HH=48,WH=53,KH=1,YH=2,XH=3,qH=4,zH=5,QH=6,$H=7,jH=8,yO=9,AO=10,JH=11;var bO=13,Yu=14,ZH=15,eW=16,tW=32,nW=33,rW=34,iW=35,gO=36,oW=37,sW=38,aW=39,lW=45,cW=46;var uW=47,EO=7,dW=1,hW=2,pW=4,xO=8,mW=0,fW=1,_W=2,yW=3,AW=4,bW=4,gW=256,EW=4,xW=1,vW=2,RW=4,SW=0,TW=1,wW=2,IW=["none","linear","reinhard","aces","agx","neutral","cineon","custom"],Lb=["map","normalMap","roughnessMap","metalnessMap","emissiveMap","aoMap","clearcoatMap","clearcoatRoughnessMap","clearcoatNormalMap","sheenColorMap","sheenRoughnessMap","specularIntensityMap","specularColorMap","transmissionMap"],vO=6,RO=["engine_render_create","engine_render_destroy","engine_render_registers","engine_render_desc","engine_render_commands","engine_render_capabilities","engine_render_flush","engine_render_create_geometry","engine_render_commit_geometry","engine_render_create_texture","engine_render_decode_texture","engine_render_create_material","engine_render_create_node","engine_render_create_target","engine_render_create_chain","engine_render_create_pass","engine_render_set_environment","engine_render_load_model","engine_render_install_shaders","engine_render_instantiate","engine_render_find_node","engine_render_play_clip","engine_render_buffer","engine_render_sync","engine_render_animate","engine_render_frame","engine_render_stats","engine_render_node_matrix"],Xu={engine_render_create_emitter:1024,engine_render_raw_buffer:8192,engine_render_raw_pipeline:8192,engine_render_raw_bindings:8192,engine_render_raw_read:8192,engine_render_raw_poll:8192,engine_render_raw_texture:131072,engine_render_raw_sampler:131072,engine_render_raw_read_texture:131072,engine_render_load_font:1048576,engine_render_set_text:1048576,engine_render_set_text_style:1048576,engine_render_text_bounds:1048576,engine_render_raycast:2097152,engine_render_set_chain_shader:256,engine_render_animation:-2147483648,engine_render_load_clips:-2147483648,engine_render_node_poses:-2147483648,engine_render_read_target:32,engine_render_texture_object:32,engine_render_reload_model:128,engine_render_reload_texture:1,engine_render_encode_texture:1};[...RO,...Object.keys(Xu)];var um=4,cm=1,kW=52*um,LW=4,Lbe=16,Mbe=0,Dbe=0,Pbe={storage:1,uniform:2,vertex:4,index:8,indirect:16,copy_src:32,copy_dst:64,map_read:128},Fbe={sampled:1,storage:2,target:4},MW={rgba8:0,rgba16f:2,rgba32f:1},DW={rgba8:4,rgba16f:8,rgba32f:16},Mb={zero:kn.indexOf("zero"),one:kn.indexOf("one"),src:kn.indexOf("srcColor"),"one-minus-src":kn.indexOf("oneMinusSrcColor"),"src-alpha":kn.indexOf("srcAlpha"),"one-minus-src-alpha":kn.indexOf("oneMinusSrcAlpha"),dst:kn.indexOf("dstColor"),"one-minus-dst":kn.indexOf("oneMinusDstColor"),"dst-alpha":kn.indexOf("dstAlpha"),"one-minus-dst-alpha":kn.indexOf("oneMinusDstAlpha"),"src-alpha-saturated":kn.indexOf("srcAlphaSaturate")},Ube={"triangle-list":0,"triangle-strip":1,"line-list":2,"point-list":3},PW="rgba16f",OO=["beforeScene","afterOpaque","afterTransparent","post","afterPost"],Bbe={depth:4294967280,motion:4294967281,color:4294967282,instances:4294967283,particles:4294967284},Gbe={depth:4294967280,motion:4294967281,color:4294967282};function Vbe(i,e){switch(i){case Ea:return new _("capacity_exceeded",`${e}: capacity exceeded`);case xa:case va:return new _("unknown_resource",`${e}: unknown resource`);case Ao:return new _("unsupported_feature",`${e}: unsupported`);default:return new _("invalid_argument",`${e}: invalid argument`)}}function Hbe(i){return i?(Mb[i.color.src]<<0|Mb[i.color.dst]<<5|Mb[i.alpha.src]<<10|Mb[i.alpha.dst]<<15)>>>0:0}function CO(i){return (i[0]|i[1]<<Lbe)>>>0}var NO=class{constructor(e){this.api="wgsl";this.shaders=[null];this.sizes=new Map;this.textures=new Map;this.targetFormats=new Map;this.encoder=new TextEncoder;this.reads=[];this.host=e;}createBuffer(e){if(e.size<=0||e.size%um!==0)throw new _("invalid_argument",`gpu buffer size ${e.size} must be a positive multiple of ${um}`);let t=this.host.clearDesc();t[0]=e.size;let n=0;for(let o of e.usage)n|=Pbe[o];t[1]=n;let r=this.check(this.host.call("engine_render_raw_buffer"),"create gpu buffer");return this.sizes.set(r,e.size),r}writeBuffer(e,t,n){let r=this.size(e);if(t<0||t%um!==0||t+n.byteLength>r)throw new _("invalid_argument",`write of ${n.byteLength} bytes at ${t} overflows gpu buffer ${e}`);this.host.flush(),this.host.bytes(10,e,0).set(new Uint8Array(n.buffer,n.byteOffset,n.byteLength),t),this.host.command(BV,e);}createTexture(e){let t=this.host.clearDesc();t[0]=e.width,t[1]=e.height,t[2]=MW[e.format];let n=0;for(let o of e.usage)n|=Fbe[o];t[3]=n,t[4]=e.mipLevels??1;let r=this.check(this.host.call("engine_render_raw_texture"),"create gpu texture");return this.textures.set(r,{width:e.width,height:e.height,format:e.format}),r}writeTexture(e,t){let n=this.texture(e),r=n.width*n.height*DW[n.format];if(t.byteLength!==r)throw new _("invalid_argument",`texture ${e} takes exactly ${r} bytes`);this.host.flush(),this.host.bytes(11,e,0).set(new Uint8Array(t.buffer,t.byteOffset,t.byteLength)),this.host.command(WV,e);}readTexture(e,t,n){let r=this.texture(e),o=t.width*t.height*DW[r.format];if(n.byteLength<o)throw new _("invalid_argument",`readTexture needs ${o} bytes`);this.host.flush();let s=this.check(this.host.call("engine_render_raw_read_texture",e,t.x,t.y,t.width,t.height),"read gpu texture");return new Promise((a,l)=>{this.reads.push({request:s,buffer:null,texture:e,offset:0,out:n.subarray(0,o),resolve:a,reject:l});})}copyTexture(e,t,n){let r=this.texture(e),o=this.host.command(KV,e),s=this.host.commandWords;s[o]=t,s[o+1]=CO(n?.from??[0,0]),s[o+2]=CO(n?.to??[0,0]),s[o+3]=CO(n?.size??[r.width,r.height]),s[o+4]=OO.indexOf(n?.hook??"beforeScene");}destroyTexture(e){this.host.command(pO,e),this.textures.delete(e),this.reject(t=>t.texture===e,`gpu texture ${e} was destroyed`);}createSampler(e){let t=this.host.clearDesc();return t[0]=e?.filter==="nearest"?1:0,t[1]=e?.wrap==="clamp"?1:e?.wrap==="mirror"?2:0,this.check(this.host.call("engine_render_raw_sampler"),"create gpu sampler")}createShader(e){return this.shaders.push(e),this.shaders.length-1}createComputePipeline(e){let t=e.workgroupSize??[cm,cm,cm];return this.pipeline(e.shader,this.encoder.encode(e.entryPoint),n=>{n[4]=0,n[1]=t[0],n[2]=t[1],n[3]=t[2];})}createRenderPipeline(e){if(e.targets.length===0||e.targets.length>LW)throw new _("invalid_argument",`render pipelines take 1 to ${LW} targets`);let t=this.encoder.encode(e.vertexEntry),n=this.encoder.encode(e.fragmentEntry),r=new Uint8Array(t.byteLength+1+n.byteLength);r.set(t),r[t.byteLength]=Mbe,r.set(n,t.byteLength+1);let o=this.pipeline(e.shader,r,s=>{s[4]=1,e.targets.forEach((a,l)=>{s[5+l]=MW[a]+1;}),s[9]=Hbe(e.blend),s[10]=Dbe,s[11]=Ube[e.topology??"triangle-list"];});return this.targetFormats.set(o,e.targets[0]),o}createBindGroup(e,t,n){if(n.length>11)throw new _("capacity_exceeded",`bind groups take at most ${11} bindings`);this.host.flush();let r=this.host.clearDesc();return r[0]=e,r[1]=t,r[2]=n.length,n.forEach((o,s)=>{let a=3+s*5;if(r[a+0]=o.binding,"texture"in o){r[a+4]=1,r[a+1]=typeof o.texture=="string"?Gbe[o.texture]:o.texture;return}if("sampler"in o){r[a+4]=2,r[a+1]=o.sampler;return}let l=typeof o.buffer=="string";r[a+4]=0,r[a+1]=l?Bbe[o.buffer]:o.buffer,r[a+2]=o.offset??0,r[a+3]=o.size??(l?0:this.size(o.buffer)-(o.offset??0));}),this.check(this.host.call("engine_render_raw_bindings"),"create bind group")}dispatch(e,t,n,r=cm,o=cm,s){let a=this.host.command(FV,e),l=this.host.commandWords;l[a+0]=t,l[a+1]=n,l[a+1+1]=r,l[a+1+2]=o,l[a+4]=OO.indexOf(s?.hook??"beforeScene"),l[a+5]=s?.indirect??0;}draw(e,t,n,r){let o=r?.target??"color",s=r?.hook??(o==="color"?"post":"afterTransparent");if(o==="color"){if(s!=="post")throw new _("invalid_argument","draws into scene colour run on the post hook");if(this.targetFormats.get(e)!==PW)throw new _("invalid_argument",`scene colour draws need a ${PW} target`)}let a=this.host.command(HV,e),l=this.host.commandWords;l[a+0]=t,l[a+1]=n,l[a+2]=r?.instances??1,l[a+3]=o==="color"?4294967282:o,l[a+4]=OO.indexOf(s),l[a+5]=0;}copyBuffer(e,t,n,r,o){let s=this.host.command(UV,e),a=this.host.commandWords;a[s]=t,a[s+1]=n,a[s+2]=r,a[s+3]=o;}submit(){this.host.flush(),this.poll();}readBuffer(e,t,n){this.host.flush();let r=this.check(this.host.call("engine_render_raw_read",e,t,n.byteLength),"read gpu buffer");return new Promise((o,s)=>{this.reads.push({request:r,buffer:e,texture:null,offset:t,out:n,resolve:o,reject:s});})}destroyBuffer(e){this.host.command(hO,e),this.sizes.delete(e),this.reject(t=>t.buffer===e,`gpu buffer ${e} was destroyed`);}dispose(){for(let e of this.sizes.keys())this.host.command(hO,e);for(let e of this.textures.keys())this.host.command(pO,e);this.host.flush(),this.sizes.clear(),this.textures.clear(),this.reject(()=>true,"gpu was disposed");}pipeline(e,t,n){let r=this.shaders[e];if(!r)throw new _("unknown_resource",`shader ${e} does not exist`);if(t.byteLength===0||t.byteLength>kW)throw new _("invalid_argument",`entry point names must fit ${kW} bytes`);this.host.flush();let o=this.encoder.encode(r),s=this.host.stage(o),a=this.host.clearDesc();return a[0]=t.byteLength,n(a),new Uint8Array(a.buffer,a.byteOffset+12*um,t.byteLength).set(t),this.check(this.host.call("engine_render_raw_pipeline",s,o.byteLength),"create gpu pipeline")}reject(e,t){let n=[];for(let r of this.reads)e(r)?r.reject(new _("unknown_resource",t)):n.push(r);this.reads=n;}poll(){if(this.reads.length===0)return;let e=[];for(let t of this.reads){let n=this.host.call("engine_render_raw_poll",t.request);if(n===0){e.push(t);continue}if(t.buffer!==null){let r=this.host.bytes(10,t.buffer,0);t.out.set(r.subarray(t.offset,t.offset+t.out.byteLength));}else t.out.set(this.host.view(n,t.out.byteLength));t.resolve();}this.reads=e;}size(e){let t=this.sizes.get(e);if(t===void 0)throw new _("unknown_resource",`gpu buffer ${e} does not exist`);return t}texture(e){let t=this.textures.get(e);if(!t)throw new _("unknown_resource",`gpu texture ${e} does not exist`);return t}check(e,t){if(e<0)throw Vbe(e,t);return e}};function GW(i){return (i.capabilities&8192)===0?null:new NO(i)}var ai=0,Hn=1,ys=2,Db=3,hm=4,Pb=5,Fb=6,pm=7,ki=8,zu=pm,Xbe=9,HW=-1,WW=2147483647,YO=class{constructor(){this.values=new Float64Array(Xbe);}get stepSeconds(){return this.values[ai]}get frameSeconds(){return this.values[Hn]}get alpha(){return this.values[ys]}get tick(){return this.values[zu]}},Ub=class{constructor(e={}){this.time=new YO;this.views=[this.time.values.subarray(zu,zu+1)];let t=e.fixedHz??60;if(!(t>0))throw new _("invalid_argument","fixedHz must be positive");this.stepMs=1e3/t,this.maxSubsteps=e.maxSubsteps??5,this.maxFrameDeltaMs=e.maxFrameDeltaMs??250;let n=this.time.values;n[ai]=1/t,n[Fb]=1,n[hm]=HW;}rollbackViews(){return this.views}get stepSeconds(){return this.time.values[ai]}get alpha(){return this.time.values[ys]}get tick(){return this.time.values[zu]}get frameDeltaSeconds(){return this.time.values[Hn]}get droppedTimeMs(){return this.time.values[Pb]}get timeScale(){return this.time.values[Fb]}set timeScale(e){this.time.values[Fb]=e;}begin(e){return this.time.values[ki]=e,this.beginAtClock()}beginAtClock(){let e=this.time.values,t=e[hm],n=e[ki]-t;e[hm]=e[ki],(t<0||n<0)&&(n=0),n>this.maxFrameDeltaMs&&(e[Pb]+=n-this.maxFrameDeltaMs,n=this.maxFrameDeltaMs),n*=e[Fb],e[Hn]=n/1e3;let r=e[Db]+n,o=r/this.stepMs,s=o<WW?o|0:WW;if(s>this.maxSubsteps){let a=(s-this.maxSubsteps)*this.stepMs;e[Pb]+=a,r-=a,s=this.maxSubsteps;}return r-=s*this.stepMs,e[Db]=r,e[ys]=r/this.stepMs,s}hold(){let e=this.time.values;e[hm]=e[ki],e[Db]=0,e[Hn]=0;}completeStep(){this.time.values[zu]++;}settle(e){let t=this.time.values;t[ys]=1,t[Hn]=e*t[ai];}reset(){let e=this.time.values;e[Db]=0,e[hm]=HW,e[ys]=0,e[zu]=0,e[Pb]=0;}};var XO=128,xo=65535,qO=4,qW=0,zW=1,QW=2,$W=3,zO=2,qbe=1414415939,zbe=2,KW=64,YW=16,XW=4;function Qbe(i){return Math.ceil(i/YW)*YW}var Bb=class{constructor(e){let t=new DataView(e);if(e.byteLength<KW||t.getUint32(0,true)!==qbe||t.getUint32(4,true)!==zbe)throw new _("asset_load_failed","font table is not a Cimplify font");let n=N=>t.getUint32(4+N*XW,true),r=N=>t.getFloat32(4+N*XW,true),o=n(1),s=n(2),a=n(3),l=n(12),c=n(13);this.glyphCount=o,this.fallback=n(11),this.metrics={atlas:[n(4),n(5)],emPx:r(6),rangePx:r(7),ascender:r(8),descender:r(9),lineGap:r(10)};let u=KW,d=N=>{let I=u;return u=Qbe(u+N),I},h=d(XO*2),p=d(s*4),m=d(s*2),f=d(o*4),y=d(o*16),b=d(o*16),A=d(a*4),E=d(a*4),R=d((o+1)*4),g=d(l*4),v=d(l*qO*2),x=d(c*8),O=d(c*zO*2);if(u!==e.byteLength||o===0||this.fallback>=o)throw new _("asset_load_failed","font table sections do not match its header");this.ascii=new Uint16Array(e,h,XO),this.codepoints=new Uint32Array(e,p,s),this.cmapGlyphs=new Uint16Array(e,m,s),this.advances=new Float32Array(e,f,o),this.planes=new Float32Array(e,y,o*4),this.uvs=new Float32Array(e,b,o*4),this.kernKeys=new Uint32Array(e,A,a),this.kernValues=new Float32Array(e,E,a),this.kernRows=new Uint32Array(e,R,o+1),this.formCodepoints=new Uint32Array(e,g,l),this.formGlyphs=new Uint16Array(e,v,l*qO),this.ligatureKeys=new Uint32Array(e,x,c*2),this.ligatureGlyphs=new Uint16Array(e,O,c*zO);}lookup(e){if(e<XO)return this.ascii[e];let t=QO(this.codepoints,0,this.codepoints.length,e);return t<0?xo:this.cmapGlyphs[t]}glyph(e){let t=this.lookup(e);return t===xo?this.fallback:t}advance(e){return this.advances[e]}plane(e,t){return this.planes[e*4+t]}uv(e,t){return this.uvs[e*4+t]}kerning(e,t){let n=this.kernRows[e],r=this.kernRows[e+1];if(n===r)return 0;let o=QO(this.kernKeys,n,r,(e<<16|t)>>>0);return o<0?0:this.kernValues[o]}get hasForms(){return this.formCodepoints.length>0}form(e,t){let n=QO(this.formCodepoints,0,this.formCodepoints.length,e);return n<0?xo:this.formGlyphs[n*qO+t]}ligature(e,t,n){let r=0,o=this.ligatureKeys.length/2;for(;r<o;){let s=r+o>>>1,a=this.ligatureKeys[s*2],l=this.ligatureKeys[s*2+1];a<e||a===e&&l<t?r=s+1:o=s;}return r<this.ligatureKeys.length/2&&this.ligatureKeys[r*2]===e&&this.ligatureKeys[r*2+1]===t?this.ligatureGlyphs[r*zO+n]:xo}};function QO(i,e,t,n){let r=e,o=t;for(;r<o;){let s=r+o>>>1;i[s]<n?r=s+1:o=s;}return r<t&&i[r]===n?r:-1}var jW=new Map;function JW(i,e){jW.set(i,e);}function ZW(i){return jW.get(i)}var ec=["hips","spine","chest","upperChest","neck","head","leftEye","rightEye","jaw","leftUpperLeg","leftLowerLeg","leftFoot","leftToes","rightUpperLeg","rightLowerLeg","rightFoot","rightToes","leftShoulder","leftUpperArm","leftLowerArm","leftHand","rightShoulder","rightUpperArm","rightLowerArm","rightHand","leftThumbMetacarpal","leftThumbProximal","leftThumbDistal","leftIndexProximal","leftIndexIntermediate","leftIndexDistal","leftMiddleProximal","leftMiddleIntermediate","leftMiddleDistal","leftRingProximal","leftRingIntermediate","leftRingDistal","leftLittleProximal","leftLittleIntermediate","leftLittleDistal","rightThumbMetacarpal","rightThumbProximal","rightThumbDistal","rightIndexProximal","rightIndexIntermediate","rightIndexDistal","rightMiddleProximal","rightMiddleIntermediate","rightMiddleDistal","rightRingProximal","rightRingIntermediate","rightRingDistal","rightLittleProximal","rightLittleIntermediate","rightLittleDistal"];function n5(i){if(!Number.isFinite(i)||i<1||i>16)throw new RangeError("animation LOD interval must be 1 to 16 frames");return i|0}var r5={once:0,repeat:1,pingpong:2},i5={"1d":1,cartesian:2,directional:3},o5={twoBone:0,lookAt:1,fabrik:2,ccd:3},s5=["event","loop","finished"],a5={linear:0,step:1,cubic:2},e5=4,l5={phase:0,markers:1},t5=32,$be=60;function c5(i,e){if(i.length>t5)throw new RangeError(`clips hold at most ${t5} sync markers`);for(let t of i)if(!Number.isFinite(t.time)||t.time<0||t.time>e)throw new RangeError(`sync marker time ${t.time} is outside the clip`)}function Gb(i){let e=i?.rate??$be;if(!Number.isFinite(e)||e<0)throw new RangeError(`bake rate ${e} must be zero (source keys only) or a positive rate`);return e}function u5(i){let e=i.size??i.rest.length;if(e<1||e>e5||i.rest.length!==e)throw new RangeError(`property tracks hold 1 to ${e5} values with a matching rest value`);let t=i.interpolation==="cubic"?3:1;if(i.times.length===0||i.values.length!==i.times.length*e*t)throw new RangeError("property track values must hold one entry per key (three for cubic: in tangent, value, out tangent)");return e}var d5=16,h5=.001,$O=4;function p5(){return {action:0,kind:"event",id:0,time:0}}var jO=4294967295,m5=8,f5=3,jbe=4,_5=1,y5=2,A5=4,Jbe=Math.PI*2,Zbe=40,ege=41,tge=42,nge=43,JO=0,rge=1,e1=8,b5=6,ZO=e1+b5,Vb=class{constructor(e){this.host=e;this.bits=new Float32Array(1);this.bitWords=new Uint32Array(this.bits.buffer);}floatBits(e){return this.bits[0]=e,this.bitWords[0]}op(e,t){let n=this.host.command(WH,e);return this.host.commandWords[n]=t,n+1}joint(e,t){let n=this.host.model(e).nodeNames.indexOf(t);if(n<0)throw new _("unknown_resource",`model has no bone ${t}`);return n}clipIndex(e,t){let n=this.host.model(e).clipNames.indexOf(t);if(n<0)throw new _("unknown_resource",`model has no clip ${t}`);return n}createPropertyClip(e){let t=e.tracks.map(u5),n=2;e.tracks.forEach((s,a)=>{n+=ZO+t[a]+s.times.length+s.values.length;});let r=new Uint32Array(n);r[0]=this.floatBits(e.duration),r[1]=e.tracks.length;let o=2;return e.tracks.forEach((s,a)=>{let l=t[a],c=r.subarray(o,o+ZO);this.bindTarget(s.target,l,c),c[4]=l,c[5]=a5[s.interpolation??"linear"],c[6]=s.times.length,o+=ZO;for(let u=0;u<l;u++)r[o++]=this.floatBits(s.rest[u]);for(let u=0;u<s.times.length;u++)r[o++]=this.floatBits(s.times[u]);for(let u=0;u<s.values.length;u++)r[o++]=this.floatBits(s.values[u]);}),this.host.animation(Zbe,0,r)}bindTarget(e,t,n){let r=n.subarray(e1,e1+b5);switch(e.kind){case "uniform":{let o=this.host.uniformSlot(e.material,e.name);if(t>o.words)throw new _("invalid_argument",`uniform ${e.name} holds ${o.words} values`);n[0]=rge,n[1]=0,n[2]=e.material,n[3]=o.offset;return}case "light":n[0]=JO,n[1]=12,n[2]=e.node,n[3]=1,r[0]=e.color>>>0;return;case "post":n[0]=JO,n[1]=24,n[2]=e.chain,n[3]=2,r[0]=e.effect,r[1]=this.host.postParam(e.chain,e.effect,e.name);return;case "emitterRate":n[0]=JO,n[1]=kb,n[2]=e.emitter,n[3]=0;return}}playPropertyClip(e,t,n,r){let o=Uint32Array.of(e,t?1:0,this.floatBits(n),this.floatBits(r));return this.host.animation(ege,0,o)}setPropertyClipEvents(e,t){let n=new Uint32Array(1+t.length*2);n[0]=e,t.forEach((r,o)=>{n[1+o*2]=this.floatBits(r.time),n[2+o*2]=r.id>>>0;}),this.host.animation(nge,0,n);}destroyPropertyClip(e){this.host.animation(tge,0,Uint32Array.of(e));}setClipTime(e,t){this.host.commandFloats[this.op(e,KH)]=t;}setClipSpeed(e,t){this.host.commandFloats[this.op(e,YH)]=t;}setClipLoop(e,t,n,r){let o=this.op(e,XH),s=this.host.commandWords;s[o]=r5[t],s[o+1]=Number.isFinite(n)?Math.max(0,n|0):0,s[o+2]=r?1:0;}setClipPaused(e,t){this.host.commandWords[this.op(e,qH)]=t?1:0;}setClipRange(e,t,n){let r=this.op(e,$H);this.host.commandFloats[r]=t,this.host.commandFloats[r+1]=n;}setClipSync(e,t){this.host.commandWords[this.op(e,QH)]=t===null?0:(t&2147483647)+1;}setClipSyncMode(e,t){this.host.commandWords[this.op(e,eW)]=l5[t];}setClipSyncMarkers(e,t,n){c5(n,Number.POSITIVE_INFINITY);let r=new Uint32Array(1+n.length*2);r[0]=this.clipIndex(e,t),n.forEach((o,s)=>{r[1+s*2]=this.floatBits(o.time),r[2+s*2]=o.id>>>0;}),this.host.animation(cW,e,r);}inertialize(e,t,n){let r=this.op(e,ZH);this.host.commandWords[r]=t,this.host.commandFloats[r+1]=n;}bakeRetarget(e,t,n,r){let o=r?.maps,s=new Uint32Array(A5+(o===void 0?0:ec.length*2)).fill(jO);s[0]=t,s[1]=this.clipIndex(t,n),s[2]=this.floatBits(Gb(r)),s[3]=o===void 0?0:_5,o!==void 0&&this.writeMaps(s,A5,e,t,o);let a=this.host.animation(lW,e,s),l=this.host.refreshModel(e).clipNames[a];if(l===void 0)throw new _("unknown_resource",`baked clip ${a} is missing on the target model`);return l}writeMaps(e,t,n,r,o){ec.forEach((s,a)=>{let l=o.source[s],c=o.target[s];l!==void 0&&(e[t+a]=this.joint(r,l)),c!==void 0&&(e[t+ec.length+a]=this.joint(n,c));});}setClipEventsEnabled(e,t){this.host.commandWords[this.op(e,jH)]=t?1:0;}setClipAdditive(e,t){this.host.commandFloats[this.host.command(VH,e)]=t??Number.POSITIVE_INFINITY;}crossFade(e,t,n,r){let o=this.op(e,zH);this.host.commandWords[o]=t,this.host.commandFloats[o+1]=n,this.host.commandWords[o+2]=r?1:0;}fadeClip(e,t,n){let r=this.op(e,bO);this.host.commandFloats[r]=t,this.host.commandFloats[r+1]=n;}fadeClipFrom(e,t,n){let r=this.op(e,bO),o=this.host.commandFloats;o[r]=t[n],o[r+1]=t[n+1];}createClipMask(e,t){let n=this.host.model(e).nodeNames,r=new Uint32Array(n.length);for(let[o,s]of Object.entries(t))r[this.joint(e,o)]=this.floatBits(s);return this.host.animation(tW,e,r)}setClipMask(e,t){this.host.commandWords[this.host.command(HH,e)]=t??0;}destroyClipMask(e,t){this.host.animation(Yu,e,Uint32Array.of(mW,t));}setClipEvents(e,t,n){let r=new Uint32Array(1+n.length*2);r[0]=this.clipIndex(e,t),n.forEach((o,s)=>{r[1+s*2]=this.floatBits(o.time),r[2+s*2]=o.id>>>0;}),this.host.animation(nW,e,r);}clipInfo(e,t){let n=new Uint32Array(jbe);return n[0]=this.clipIndex(e,t),this.host.animation(sW,e,n),this.bitWords[0]=n[0],{duration:this.bits[0],tracks:n[1],morphWeights:n[2],events:n[3]}}createBlendSpace(e,t){let n=new Uint32Array(2+t.members.length*f5);return n[0]=i5[t.kind],n[1]=t.members.length,t.members.forEach((r,o)=>{let s=2+o*f5;n[s]=r.action,n[s+1]=this.floatBits(r.x),n[s+2]=this.floatBits(r.y??0);}),this.host.animation(rW,e,n)}setBlendParameter(e,t,n,r){let o=this.op(e,yO);this.host.commandFloats[o]=t,this.host.commandFloats[o+1]=n,this.host.commandFloats[o+2]=r;}setBlendParameterFrom(e,t,n){let r=this.op(e,yO),o=this.host.commandFloats;o[r]=t[n],o[r+1]=t[n+1],o[r+2]=t[n+2];}destroyBlendSpace(e,t){this.host.animation(Yu,e,Uint32Array.of(fW,t));}createIk(e,t){let n=new Uint32Array(m5+t.bones.length),r=t.forward??[0,0,1];return n[0]=o5[t.solver],n[1]=t.iterations??d5,n[2]=this.floatBits(t.tolerance??h5),n[3]=this.floatBits(t.maxAngle??Jbe),n[4]=this.floatBits(r[0]),n[5]=this.floatBits(r[1]),n[6]=this.floatBits(r[2]),n[7]=t.bones.length,t.bones.forEach((o,s)=>{n[m5+s]=this.joint(e,o);}),this.host.animation(iW,e,n)}setIkTarget(e,t,n,r,o){let s=this.op(e,AO),a=this.host.commandFloats;a[s]=t,a[s+1]=n,a[s+2]=r,a[s+3]=o;}setIkTargetFrom(e,t,n){let r=this.op(e,AO),o=this.host.commandFloats;o[r]=t[n],o[r+1]=t[n+1],o[r+2]=t[n+2],o[r+3]=t[n+3];}setIkPole(e,t,n,r){let o=this.op(e,JH),s=this.host.commandFloats;s[o]=t,s[o+1]=n,s[o+2]=r;}destroyIk(e,t){this.host.animation(Yu,e,Uint32Array.of(_W,t));}humanoid(e){let t=new Uint32Array(ec.length);this.host.animation(oW,e,t);let n=this.host.model(e).nodeNames,r={};return ec.forEach((o,s)=>{t[s]!==jO&&(r[o]=n[t[s]]);}),r}retarget(e,t,n){if(n===void 0){this.host.animation(gO,e,Uint32Array.of(t,0));return}let r=new Uint32Array(y5+ec.length*2).fill(jO);r[0]=t,r[1]=_5,this.writeMaps(r,y5,e,t,n),this.host.animation(gO,e,r);}stopRetarget(e){this.host.animation(Yu,e,Uint32Array.of(yW,0));}createBoneSet(e,t){let n=new Uint32Array(t.length);return t.forEach((r,o)=>{let s=this.host.findNode(e,r);if(s===null)throw new _("unknown_resource",`model has no bone ${r}`);n[o]=s;}),this.host.createPoseReader(n)}readBonePoses(e,t,n){this.host.readPoses(e,t,n);}destroyBoneSet(e){this.host.destroyPoseReader(e);}setAnimationLod(e,t){this.host.animation(uW,e,Uint32Array.of(n5(t)));}enableRootMotion(e,t){let n=(t.horizontal??true?dW:0)|(t.vertical?hW:0)|(t.yaw?pW:0)|(t.apply?xO:0);if(n===0||n===xO)throw new _("invalid_argument","root motion needs at least one extracted axis");return this.host.animation(aW,e,Uint32Array.of(n,this.joint(e,t.bone)))}disableRootMotion(e){this.host.animation(Yu,e,Uint32Array.of(AW,0));}readRootMotion(e,t,n){let r=this.host.floats(wW);t.set(r.subarray(e*$O,(e+1)*$O),n);}readClipState(e,t){let n=this.host.floats(TW),r=e*EW;this.bits[0]=n[r+3];let o=this.bitWords[0];t.time=n[r],t.weight=n[r+1],t.speed=n[r+2],t.running=(o&xW)!==0,t.paused=(o&vW)!==0,t.finished=(o&RW)!==0;}readClipEvents(e){let t=this.host.words(SW),n=Math.min(t[0],gW);for(let r=0;r<n;r++){let o=1+r*bW,s=e[r]??p5();s.action=t[o],s.kind=s5[t[o+1]]??"event",s.id=t[o+2],this.bitWords[0]=t[o+3],s.time=this.bits[0],e[r]=s;}return n}};var g5={low:0,mid:1,high:2},E5={low:4,mid:8,high:16};function x5(){return {cap:0,live:0,encoded:0,unchanged:0,offscreen:0,occluded:0,overCap:0,droppedEvents:0}}var ige=["engine_render_vector_load","engine_render_vector_unload","engine_render_vector_surface","engine_render_vector_surface_destroy","engine_render_vector_surface_node","engine_render_vector_surface_play","engine_render_vector_surface_input_index","engine_render_vector_surface_input","engine_render_vector_surface_data_index","engine_render_vector_surface_data_set","engine_render_vector_surface_pointer","engine_render_vector_surface_pick","engine_render_vector_frame","engine_render_vector_events","engine_render_vector_event_count","engine_render_vector_surface_tier","engine_render_vector_surface_stats"],oge="engine_render_vector_surface_seek";function w5(i){for(let e of ige)if(typeof i[e]!="function")return null;return i}var v5={down:0,move:1,up:2,cancel:3},sge={machine:0,animation:1,stop:2},age={machine:0,animation:1},lge={number:0,bool:1,color:2,id:3,fire:4},R5=32,cge=14,uge=8,dge=7,hge=0,pge=4,mge=24,fge=0,_ge=1,yge=2,Age=3,bge=4,gge=5,Ege=6,xge=7,S5=0,vge=0,Rge=1,Sge=1e6,Tge=6,T5=new TextEncoder;function wge(i,e){switch(i){case Ea:return new _("capacity_exceeded",`${e}: capacity exceeded`);case xa:case va:return new _("unknown_resource",`${e}: unknown resource`);case Ao:return new _("unsupported_feature",`${e}: unsupported`);default:return new _("invalid_argument",`${e}: invalid argument`)}}function jn(i,e){if(i<0)throw wge(i,e);return i}var Hb=class{constructor(e,t){this.exports=e;this.host=t;this.surfaces=0;this.tier="mid";this.ray=new Float32Array(dge);this.rayBytes=new Uint8Array(this.ray.buffer);}get cap(){return E5[this.tier]}get handle(){return this.host.handle}load(e){if(e.byteLength===0)throw new _("invalid_argument","a vector asset needs its bytes");let t=this.host.stage(e);return jn(this.exports.engine_render_vector_load(this.handle,t,e.byteLength),"load vector")}unload(e){jn(this.exports.engine_render_vector_unload(this.handle,e),"unload vector");}create(e){this.host.flush();let t=jn(this.exports.engine_render_vector_surface(this.handle,e.asset,e.artboard??0,e.target,e.node??S5),"create vector surface");return this.surfaces++,t}destroy(e){jn(this.exports.engine_render_vector_surface_destroy(this.handle,e),"destroy vector surface"),this.surfaces--;}setNode(e,t){this.host.flush(),jn(this.exports.engine_render_vector_surface_node(this.handle,e,t??S5),"vector surface node");}play(e,t,n){jn(this.exports.engine_render_vector_surface_play(this.handle,e,sge[t],n),"play vector surface");}seek(e,t,n,r){let o=this.exports[oge];if(o===void 0)throw new _("unsupported_feature","this engine cannot seek vector surfaces");jn(o(this.handle,e,age[t],n,r),"seek vector surface");}inputIndex(e,t){let n=T5.encode(t);if(n.byteLength===0)throw new _("invalid_argument","a vector input needs a name");let r=this.host.stage(n);return jn(this.exports.engine_render_vector_surface_input_index(this.handle,e,r,n.byteLength),`vector input ${t}`)}setInput(e,t,n){jn(this.exports.engine_render_vector_surface_input(this.handle,e,t,n),"vector input");}dataIndex(e,t){let n=T5.encode(t);if(n.byteLength===0)throw new _("invalid_argument","vector data needs a path");let r=this.host.stage(n);return jn(this.exports.engine_render_vector_surface_data_index(this.handle,e,r,n.byteLength),`vector data ${t}`)}setData(e,t,n,r){let o=n==="color"||n==="id"?r>>>0:0;jn(this.exports.engine_render_vector_surface_data_set(this.handle,e,t,lge[n],r,o),"vector data");}pointer(e,t,n,r){return jn(this.exports.engine_render_vector_surface_pointer(this.handle,e,v5[t],n,r),"vector pointer")===Rge}pick(e,t,n,r){this.host.flush();let o=this.ray;o[0]=e[0],o[1]=e[1],o[2]=e[2],o[3]=t[0],o[4]=t[1],o[5]=t[2],o[Tge]=n;let s=this.host.stage(this.rayBytes),a=jn(this.exports.engine_render_vector_surface_pick(this.handle,v5[r],s),"pick vector surface");return a===vge?null:a}events(e){let t=this.exports.engine_render_vector_event_count(this.handle);if(t===0)return e.length=0,0;let n=new DataView(this.host.buffer(),this.exports.engine_render_vector_events(this.handle),t*R5),r=0;for(let o=0;o<t;o++){let s=o*R5;if(n.getUint8(s+hge)!==cge)continue;let a=n.getUint32(s+pge,true),l=n.getFloat32(s+mge,true),c=e[r];c===void 0?e.push({surface:a,event:l}):(c.surface=a,c.event=l),r++;}return e.length=r,r}stats(e){let t=this.exports.engine_render_vector_surface_stats(this.handle);if(t===0)throw new _("unknown_resource","vector surface stats are unavailable");let n=new Uint32Array(this.host.buffer(),t,uge);e.cap=n[fge],e.live=n[_ge],e.encoded=n[yge],e.unchanged=n[Age],e.offscreen=n[bge],e.occluded=n[gge],e.overCap=n[Ege],e.droppedEvents=n[xge];}setTier(e){jn(this.exports.engine_render_vector_surface_tier(this.handle,g5[e]),"vector surface tier"),this.tier=e;}frame(e){this.surfaces!==0&&jn(this.exports.engine_render_vector_frame(this.handle,Math.round(e*Sge)),"vector surface frame");}};var I5=4,sEe=1,aEe=1,lEe=.1,O5=16777215;function r1(i,e,t,n){i[e]=t?.[0]??n,i[e+1]=t?.[1]??n;}function N5(i,e,t){i[0]=t.capacity,e[1]=t.rate??0,i[2]=t.burst??0,r1(e,3,t.lifetime,sEe),r1(e,5,t.speed,aEe),r1(e,7,t.size,lEe),i[9]=t.color?.[0]??O5,i[10]=t.color?.[1]??t.color?.[0]??O5,e[11]=t.alpha?.[0]??1,e[12]=t.alpha?.[1]??1,e.set(t.gravity??[0,0,0],13),e[16]=t.drag??0,e[17]=t.noise?.strength??0,e[18]=t.noise?.scale??1;let n=t.shape??{kind:"point"};switch(i[19]=_V.indexOf(n.kind),n.kind){case "sphere":case "disc":e[20]=n.radius;break;case "cone":e[20]=n.angle,e[21]=n.radius??0;break;case "box":e.set(n.size,20);break;}let r=t.collision??{kind:"none"};i[24]=yV.indexOf(r.kind),r.kind==="plane"&&e.set(r.plane,25),r.kind!=="none"&&(e[29]=r.bounce??0),i[30]=t.material??0,i[31]=(t.soft?1:0)|(t.sorted?2:0)|(t.localSpace?4:0)|(t.deterministic?8:0)|(t.additive?16:0)|(t.stretch?32:0)|(t.oit?64:0)|(t.velocityAligned?128:0),i[32]=t.seed??0,e[33]=t.spread??0,e[34]=t.spin??0,i[36]=t.sizeCurve||t.colorCurve?32:0;}function C5(i,e){return typeof i.value=="number"?i.value:i.value[e]}function o1(i,e){if(i.length===0)return;let t=0;for(let n=0;n<32;n++){let r=n/31;for(;t<i.length-1&&i[t+1].t<r;)t++;let o=i[t],s=i[Math.min(t+1,i.length-1)],a=s.t-o.t,l=a>0?Math.min(1,Math.max(0,(r-o.t)/a)):0;for(let c=0;c<I5;c++){let u=C5(o,c);e[n*I5+c]=u+(C5(s,c)-u)*l;}}}function Kb(i,e,t,n,r,o,s,a){let l=s[a],c=t[n],u=t[n+1],d=t[n+2],h=t[n+3],p=r[o],m=r[o+1],f=r[o+2],y=r[o+3],b=c*p+u*m+d*f+h*y;b<0&&(b=-b,p=-p,m=-m,f=-f,y=-y);let A,E;if(b>.9995)A=1-l,E=l;else {let N=Math.acos(b),I=Math.sin(N);A=Math.sin((1-l)*N)/I,E=Math.sin(l*N)/I;}let R=c*A+p*E,g=u*A+m*E,v=d*A+f*E,x=h*A+y*E,O=Math.sqrt(R*R+g*g+v*v+x*x);if(O>1e-6){let N=1/O;R*=N,g*=N,v*=N,x*=N;}i[e]=R,i[e+1]=g,i[e+2]=v,i[e+3]=x;}function a1(i,e,t,n,r,o,s,a,l,c,u){let d=t+s+u,h,p,m,f;if(d>0){let y=.5/Math.sqrt(d+1);f=.25/y,h=(a-c)*y,p=(l-r)*y,m=(n-o)*y;}else if(t>s&&t>u){let y=2*Math.sqrt(1+t-s-u);f=(a-c)/y,h=.25*y,p=(o+n)/y,m=(l+r)/y;}else if(s>u){let y=2*Math.sqrt(1+s-t-u);f=(l-r)/y,h=(o+n)/y,p=.25*y,m=(c+a)/y;}else {let y=2*Math.sqrt(1+u-t-s);f=(n-o)/y,h=(l+r)/y,p=(c+a)/y,m=.25*y;}i[e]=h,i[e+1]=p,i[e+2]=m,i[e+3]=f;}function k5(i,e,t,n,r,o,s,a){for(let l=0;l<16;l++)i[e+l]=0;i[e]=2*s/(n-t),i[e+5]=2*s/(o-r),i[e+8]=(n+t)/(n-t),i[e+9]=(o+r)/(o-r),i[e+10]=-(a+s)/(a-s),i[e+11]=-1,i[e+14]=-2*a*s/(a-s);}function L5(i,e,t,n,r,o,s,a){for(let l=0;l<16;l++)i[e+l]=0;i[e]=2/(n-t),i[e+5]=2/(o-r),i[e+10]=-2/(a-s),i[e+12]=-(n+t)/(n-t),i[e+13]=-(o+r)/(o-r),i[e+14]=-(a+s)/(a-s),i[e+15]=1;}var cEe=[3.67,1.37,.68],uEe=1.5,dEe=.18,hEe=.04,pEe=.02,mEe=.35,fEe=.5,_Ee=.2,yEe=.3,AEe=1,l1=50,c1=.5,bEe=8,gEe=60,EEe=61,xEe=62,vEe=49,D5={skin:12,eye:13,hair:14};function li(i,e,t){return Math.min(Math.max(i,e),t)}function REe(i){switch(i.kind){case "skin":{let e=i.scatter??cEe;return [li(e[0],0,l1),li(e[1],0,l1),li(e[2],0,l1),Math.max(i.thickness??uEe,0)]}case "eye":return [li(i.irisRadius??dEe,0,c1),li(i.irisDepth??hEe,0,c1),li(i.limbus??pEe,0,c1),li(i.pupil??mEe,0,1)];case "hair":return [li(i.melanin??fEe,0,1),li(i.redness??_Ee,0,1),li(i.azimuthalRoughness??yEe,0,1),li(i.density??AEe,0,bEe)]}}var P5=new Float32Array(1),SEe=new Uint32Array(P5.buffer);function M5(i){return P5[0]=i===0?-0:i,SEe[0]}function F5(i,e){if(REe(i).forEach((n,r)=>e(40+r,M5(n))),i.kind!=="skin")return;let t=[[gEe,i.sheen],[EEe,i.sheenRoughness],[xEe,i.warmth],[vEe,i.rim]];for(let[n,r]of t)r!==void 0&&e(n,M5(li(r,0,1)));}function Yb(){return {node:0,instance:0,triangle:0,distance:0,point:new Float32Array(3),barycentric:new Float32Array(2),uv:new Float32Array(2)}}var U5={tintable:false,mask:void 0};function B5(i){if(!("tintable"in i||"tintMask"in i))return U5;let e=i.tintMask;if(e===void 0&&i.tintable!==true)return U5;if(e!==void 0&&i.kind==="physical"&&((i.transmission??0)>0||i.transmissionMap!==void 0))throw new _("invalid_argument","a tint mask shares the transmission texture slot; drop transmission or the tint mask");return {tintable:true,mask:e}}var mm=27,Qu=["cull","particles","shadow","main","overlay","post","targets","gi","rt","volumetrics"];function G5(){return {gpuLastNs:0,gpuP50Ns:0,gpuP95Ns:0,gpuBytes:0,thermalTier:0,particlesAlive:0,rawDispatches:0,rawGpuNs:0,rawDisabled:0,transparentSorted:0,textGlyphs:0,drawCalls:0,triangles:0,passNs:new Float64Array(Qu.length)}}var g0e=7,E0e=8,X5=13,x0e=4,v0e=16,R0e=0,S0e=1,T0e=49,w0e=58,I0e=59,O0e=22,u1=27,W5=61,C0e=63,A1=15;var N0e=1<<27,zb=1<<28,q5=1<<30,k0e=16,d1=65535,Xb=Math.PI*2,L0e=Math.PI/180,K5=.5,M0e=1,D0e=1,qb={turbidity:10,rayleigh:2,mie:.005,mieDirectionalG:.8},fm={coverage:.4,density:.6,scale:1,speed:1,elevation:.5},P0e=4,Y5=16,b1={directional:0,point:1,spot:2,ambient:3,hemisphere:4,probe:5,rectArea:6,reflectionProbe:7},z5={standard:0,physical:1,toon:g0e,matcap:E0e,unlit:2,sprite:3,points:4,lines:5,shader:6,...D5},F0e=16777215;function h1(i,e,t,n){return i[e]=t===void 0?0:(t&F0e)>>>0,t===void 0?0:n}function Q5(i,e,t){let n=h1(e,t,i?.primary,1)|h1(e,t+1,i?.secondary,2)|h1(e,t+2,i?.tertiary,4);e[t+3]=n;}function $5(i,e){let t=B5(i);return t.tintable?(t.mask!==void 0&&(e[51+(13-vO)]=t.mask),512):0}var g1={pcf:R0e,pcss:S0e};function rg(i){return i==="gradientMap"||i==="matcap"?X5:Lb.indexOf(i)}function tc(i){return rc(i===0?-0:i)}function U0e(i,e){let t=Math.round(Math.min(Math.max(i,0),1)*d1),n=(e%Xb+Xb)%Xb;return ((Math.round(n/Xb*d1)&d1)<<16|t)>>>0}function j5(i){switch(i.kind){case "toon":return 64;case "matcap":return i.flatShading?32:0;case "lines":return i.worldUnits?256:0;case "sprite":return i.sizeAttenuation===false?0:128;default:return 0}}function p1(i){return i<=.04045?i/12.92:((i+.055)/1.055)**2.4}function B0e(i,e,t){i[e]=p1((t>>16&255)/255),i[e+1]=p1((t>>8&255)/255),i[e+2]=p1((t&255)/255);}function J5(i,e,t){let n=51+(X5-vO);switch(i.kind){case "toon":e[15]=i.map??0,e[16]=i.normalMap??0,e[19]=i.emissiveMap??0,e[20]=i.aoMap??0,B0e(t,7,i.emissive??0),t[10]=i.emissiveIntensity??1,e[n]=i.gradientMap??0;break;case "matcap":e[15]=i.map??0,e[16]=i.normalMap??0,e[n]=i.matcap??0;break;case "lines":t[21]=i.width??M0e,i.dashSize!==void 0&&(e[60]=tc(i.dashSize)),i.gapSize!==void 0&&(e[61]=tc(i.gapSize)),i.dashScale!==void 0&&(e[62]=tc(i.dashScale));break;case "physical":i.anisotropy!==void 0&&i.anisotropy>0&&(e[63]=U0e(i.anisotropy,i.anisotropyRotation??0));break;}}function Z5(i,e,t){let n=i.sky;if(i.background!==void 0&&"sky"in i.background&&(e[0]=3),!n){e[19]=0;return}e[19]=1,t[20]=n.turbidity??qb.turbidity,t[21]=n.rayleigh??qb.rayleigh,t[22]=n.mie??qb.mie,t[23]=n.mieDirectionalG??qb.mieDirectionalG;let r=n.clouds;if(!r){t[24]=0;return}t[24]=r.coverage??fm.coverage,t[25]=r.density??fm.density,t[26]=r.scale??fm.scale,t[27]=r.speed??fm.speed,t[28]=r.elevation??fm.elevation;}function eK(i,e,t,n){let r=i.lod;switch(r&&(t[34]=r.near??0,t[35]=r.far??0,t[36]=r.hysteresis??0),i.kind){case "sprite":e[W5]=tc(i.center?.[0]??K5),e[W5+1]=tc(i.center?.[1]??K5),e[C0e]=tc(n);break;case "decal":e[0]=10,e[2]=i.material,i.angleFade!==void 0&&(t[32]=i.angleFade),i.fade!==void 0&&(t[33]=i.fade);break;case "light":if(e[5]=b1[i.light],i.shadow?.type!==void 0&&(e[50]=g1[i.shadow.type]),i.light==="rectArea")t[51]=i.width??1,t[52]=i.height??1;else if(i.light==="probe")i.fromEnvironment&&(e[3]|=v0e);else if(i.light==="reflectionProbe"){if(i.texture===void 0)throw new _("invalid_argument","reflection probes need a cube or equirect texture");e[53]=i.texture;let o=i.boxMin??[-1,-1,-1],s=i.boxMax??[1,1,1];for(let a=0;a<3;a++)t[54+a]=o[a],t[57+a]=s[a];e[60]=tc(i.intensity??D0e);}break;}}function G0e(i,e,t=0){for(let n=0;n<4;n++){let r=n*4;e[t+r]=i[r],e[t+r+1]=i[r+1],e[t+r+2]=.5*i[r+3]-.5*i[r+2],e[t+r+3]=i[r+3];}}function V0e(i,e,t,n){if(i.perspective){let h=i.near*Math.tan(L0e*.5*i.fov),p=2*h,m=e*p,f=-0.5*m;f+=t.x*m/t.fullWidth,h-=t.y*p/t.fullHeight,m*=t.width/t.fullWidth,p*=t.height/t.fullHeight,k5(n,0,f,f+m,h-p,h,i.near,i.far);return}let r=i.height/2,o=r*e,s=2*o/t.fullWidth,a=2*r/t.fullHeight,l=-o+s*t.x,c=l+s*t.width,u=r-a*t.y,d=u-a*t.height;L5(n,0,l,c,d,u,i.near,i.far);}var Qb=class{constructor(e){this.spriteRotations=new Map;this.cameras=new Map;this.glScratch=new Float64Array(k0e);this.staging=null;this.aspect=1;this.host=e;}has(e){return (this.host.caps()&e)!==0}require(e,t){if(!this.has(e))throw new _("unsupported_feature",`this engine build has no ${t}; update the app to use it`)}material(e,t){t.kind==="sprite"&&this.spriteRotations.set(e,t.rotation??0);}spriteRotation(e){return this.spriteRotations.get(e)??0}forgetMaterial(e){this.spriteRotations.delete(e);}node(e,t){if(t.kind==="camera"){let n=t.projection!=="orthographic";this.cameras.set(e,{perspective:n,fov:t.projection==="perspective"?t.fov??0:0,height:t.projection==="orthographic"?t.height:0,near:t.near??0,far:t.far??0,offset:null,custom:false}),t.projection==="custom"&&this.setProjectionMatrix(e,t.matrix,t.near,t.far);return}t.kind==="light"&&t.light==="probe"&&t.sh&&this.setProbeCoefficients(e,t.sh);}forgetNode(e){this.cameras.delete(e);}perspective(e,t,n,r){let o=this.cameras.get(e);o&&(o.perspective=true,o.fov=t,o.near=n,o.far=r,o.custom=false,o.offset&&this.sendOffset(e,o));}perspectiveFrom(e,t,n){let r=this.cameras.get(e);r&&(r.perspective=true,r.fov=t[n],r.near=t[n+1],r.far=t[n+2],r.custom=false,r.offset&&this.sendOffset(e,r));}orthographic(e,t,n,r){let o=this.cameras.get(e);o&&(o.perspective=false,o.height=t,o.near=n,o.far=r,o.custom=false,o.offset&&this.sendOffset(e,o));}resize(e,t){this.aspect=e/Math.max(1,t);for(let[n,r]of this.cameras)r.offset&&this.sendOffset(n,r);}setLod(e,t,n,r){let o=this.host.command(YV,e);this.host.floats[o]=t,this.host.floats[o+1]=n,this.host.floats[o+2]=r;}setSprite(e,t,n,r){this.require(N0e,"sprite rotation and center");let o=this.host.command(w0e,e);this.host.floats[o]=t,this.host.floats[o+1]=n,this.host.floats[o+2]=r;}setProbeCoefficients(e,t){if(t.length<u1)throw new _("invalid_argument",`light probes take ${u1} coefficients (9 RGB)`);this.host.buffer(4,e,x0e).set(t.subarray(0,u1)),this.host.command(T0e,e);}setProjectionMatrix(e,t,n,r){this.require(zb,"custom camera projections");let o=this.cameras.get(e);o&&(o.custom=t!==null,t!==null&&(o.offset=null)),this.sendProjection(e,t,n,r);}setViewOffset(e,t){this.require(zb,"camera view offsets");let n=this.cameras.get(e);if(!n)throw new _("unknown_resource",`node ${e} is not a camera`);if(n.offset=t,t===null){this.sendProjection(e,null,n.near,n.far);return}this.sendOffset(e,n);}readGpuStats(e){let t=this.host.registers;e.gpuLastNs=t[gV],e.gpuP50Ns=t[EV],e.gpuP95Ns=t[xV],e.gpuBytes=t[vV]+t[RV]*4294967296,e.thermalTier=t[Nb],e.particlesAlive=t[SV],e.rawDispatches=t[TV],e.rawGpuNs=t[wV],e.rawDisabled=t[IV],e.transparentSorted=t[OV],e.textGlyphs=t[CV],e.drawCalls=t[NV],e.triangles=t[kV];}sendOffset(e,t){let n=t.offset;n&&(V0e(t,this.aspect,n,this.glScratch),this.sendProjection(e,this.glScratch,t.near,t.far));}sendProjection(e,t,n,r){if(t===null){this.sendBase(e);return}this.host.flush(),G0e(t,this.stagingView());let o=this.host.command(I0e,e);this.host.floats[o]=n,this.host.floats[o+1]=r,this.host.flush();}sendBase(e){let t=this.cameras.get(e),n=t?.perspective??true,r=this.host.command(n?9:10,e);this.host.floats[r]=n?t?.fov||60:t?.height??1,this.host.floats[r+1]=t?.near||.1,this.host.floats[r+2]=t?.far||1e3;}stagingView(){return (this.staging===null||this.staging.length===0)&&(this.staging=this.host.buffer(A1,0,0)),this.staging}};function tK(i,e,t){let n=64*P0e;if(typeof i.exports.engine_alloc!="function")return t(0);let r=i.exports.engine_alloc(n,Y5);if(r===0)return t(0);try{let o=new Uint32Array(i.memory.buffer,r,64);return o.fill(0),o[O0e]=e.pointShadows===!1?0:1,t(r)}finally{i.exports.engine_free(r,n,Y5);}}var uK=new Float32Array(1),Ixe=new Uint32Array(uK.buffer),sK=255,aK=3,Oxe=8,lK=255,Cxe=.04045,Nxe=12.92,cK=.055,kxe=2.4;function rc(i){return uK[0]=i,Ixe[0]}function dK(i){return i===void 0?0:1+fV.indexOf(i)}function Lxe(i){let e=i.blend?.equation??"add",t=dK(i.depthFunc)<<0;return t|=dO.indexOf(e)<<4,t|=dO.indexOf(i.blend?.alphaEquation??e)<<7,i.alphaToCoverage&&(t|=1024),i.transparency==="oit"&&(t|=2048),i.stencil&&(t|=8192),t>>>0}function Mxe(i){if(!i)return 0;let e=i.src??"srcAlpha",t=i.dst??"oneMinusSrcAlpha";return (kn.indexOf(e)<<0|kn.indexOf(t)<<5|kn.indexOf(i.srcAlpha??e)<<10|kn.indexOf(i.dstAlpha??t)<<15)>>>0}function Dxe(i){return i?(dK(i.func??"always")<<0|((i.ref??0)&255)<<4|((i.readMask??sK)&255)<<12|((i.writeMask??sK)&255)<<20)>>>0:0}function Pxe(i){return i?Cb.indexOf(i.fail??"keep")<<0|Cb.indexOf(i.depthFail??"keep")<<3|Cb.indexOf(i.pass??"keep")<<6:0}function R1(i,e){let t=i.clippingPlanes?.length??0;if(t>4)throw new RangeError(`materials clip against at most ${4} planes`);e(32,Lxe(i)),e(33,Mxe(i.blend)),e(34,Dxe(i.stencil)),e(35,Pxe(i.stencil)),e(36,rc(i.polygonOffset?.factor??0)),e(37,rc(i.polygonOffset?.units??0)),e(38,t),e(39,Mi(i.envMapIntensity));}function Mi(i){return i===void 0?0:rc(i===0?-0:i)}function Fxe(i){return i<=Cxe?i/Nxe:((i+cK)/(1+cK))**kxe}function x1(i,e,t,n){if(t!==void 0)for(let r=0;r<aK;r++){let o=(t>>(aK-1-r)*Oxe&lK)/lK;i(e+r,Mi(Fxe(o)*n));}}function hK(i,e){if(R1(i,e),i.kind!=="physical")return;x1(e,40,i.sheenColor,i.sheen??0),e(43,Mi(i.sheenRoughness)),x1(e,44,i.specularColor,1),e(47,Mi(i.specularIntensity)),e(48,Mi(i.thickness)),e(49,Mi(i.iridescence)),e(59,Mi(i.clearcoatNormalScale)),x1(e,28,i.attenuationColor,1),e(31,Mi(i.attenuationDistance)),e(60,Mi(i.iridescenceIOR));let t=i.iridescenceThicknessRange;t!==void 0&&(e(61,Mi(t[0])),e(62,Mi(t[1])));}var Uxe=["iridescenceMap","iridescenceThicknessMap","anisotropyMap"];function pK(i){if(i.kind==="physical"){for(let e of Uxe)if(i[e]!==void 0)throw new _("unsupported_feature",`the engine renderer does not draw ${e} on physical materials; remove it, or bake it into the base maps`);if((i.dispersion??0)>0)throw new _("unsupported_feature","the engine renderer does not draw dispersion on physical materials; remove it or set it to 0")}}function mK(i){return i.kind!=="physical"?[]:[i.clearcoatMap,i.clearcoatRoughnessMap,i.clearcoatNormalMap,i.sheenColorMap,i.sheenRoughnessMap,i.specularIntensityMap,i.specularColorMap,i.transmissionMap]}function S1(i,e){let t=i.clippingPlanes;return !t||t.length===0?false:(t.forEach((n,r)=>e.set(n,r*4)),true)}function fK(i,e,t){if(!i.textureTransforms)return false;let n=0;for(let[r,o]of Object.entries(i.textureTransforms)){if(!o)continue;let s=rg(r),a=s*8;e[a+0]=o.offset?.[0]??0,e[a+0+1]=o.offset?.[1]??0,e[a+2]=o.repeat?.[0]??1,e[a+2+1]=o.repeat?.[1]??1,e[a+4]=o.rotation??0,e[a+5]=o.center?.[0]??0,e[a+5+1]=o.center?.[1]??0,e[a+7]=o.channel??0,n|=1<<s;}return t(50,n),n!==0}var T1=(i,e)=>(i>>e&255)/255;function _K(i){let e=[];for(let t=0;t<i.length;t+=5)e.push([t,i.subarray(t,Math.min(t+5,i.length))]);return e}function yK(i){let e=new Float32Array(24).fill(Number.NaN),t=i.enabled===false?1:0,n=i.fog;if(n){t|=2;let s=n.albedo??15132390;e.set([n.density??Ht,n.height??Ht,n.falloff??Ht,n.anisotropy??Ht,T1(s,16),T1(s,8),T1(s,0),n.noise??Ht,n.range??Ht,n.ambient??Ht],1);}let r=i.clouds;r&&(t|=4,e.set([r.coverage??Ht,r.density??Ht,r.altitude??Ht,r.thickness??Ht,r.type??Ht,r.shadow??Ht,r.detail??Ht],11));let o=i.atmosphere;return o&&(t|=8,e.set([o.rayleigh??Ht,o.mie??Ht,o.mieAnisotropy??Ht,o.ozone??Ht,o.groundAlbedo??Ht,o.sunDiscDegrees??Ht],18)),e[0]=t,e}var Bxe=-1,Ht=Number.NaN,ig=i=>Math.min(Math.max(i??0,0),1);function AK(i){return {cloudCover:ig(i.cloudCover),haze:ig(i.haze),precipitation:ig(i.precipitation),snow:i.snow??false,wetness:i.wetness===void 0?Bxe:ig(i.wetness),windX:i.wind?.[0]??0,windZ:i.wind?.[1]??0}}function og(i,e){let t=i.symbols.engine_feature_count,n=i.symbols.engine_feature_name;if(typeof t!="function"||typeof n!="function")return false;let r=i.exports.engine_alloc(64,1);if(r===0)return false;let o=false;for(let s=0;s<t()&&!o;s++){let a=n(s,r,64);if(a!==e.length)continue;let l=new Uint8Array(i.memory.buffer,r,a);o=true;for(let c=0;c<a&&o;c++)o=l[c]===e.charCodeAt(c);}return i.exports.engine_free(r,64,1),o}var w1={emission:1,extinction:1,albedo:[.5,.5,.5]};var I1=3;function Xxe(i,e,t,n){return e>=0&&e<i[0]&&t>=0&&t<i[1]&&n>=0&&n<i[2]?(n*i[1]+t)*i[0]+e:-1}function bm(i){throw new _("invalid_argument",`a media volume ${i}`)}function C1(i){return Number.isFinite(i)&&Number.isFinite(Math.fround(i))}function O1(i){return C1(i)&&Math.fround(i)>0&&C1(1/Math.fround(i))}function gK(i,e){let t=[e.origin.x,e.origin.y,e.origin.z],n=[e.extent.x,e.extent.y,e.extent.z],r=e.albedo??w1.albedo,o=e.emission??w1.emission,s=e.extinction??w1.extinction;t.every(C1)||bm("needs a finite origin"),n.every(O1)||bm("needs a positive, finite extent on every axis"),(e.size.length!==I1||!e.size.every(a=>Number.isInteger(a)&&a>=1&&a<=64))&&bm(`holds 1 to ${64} whole texels per axis`),(!O1(o)||!O1(s))&&bm("needs a positive, finite emission and extinction"),(r.length!==I1||!r.every(a=>a>=0&&a<=1))&&bm("albedo runs from 0 to 1 per channel"),i.fill(0,0,14);for(let a=0;a<I1;a++)i[0+a]=t[a],i[3+a]=n[a],i[6+a]=e.size[a],i[11+a]=r[a];i[9]=o,i[10]=s;}var sg=class{constructor(e,t,n){this.port=e;this.id=t;this.disposed=false;this.desc=n;}get size(){return this.desc.size}get texels(){if(this.disposed)throw new _("unknown_resource","this media volume was disposed");return this.port.mediumTexels(this.id)}index(e,t,n){return Xxe(this.desc.size,e,t,n)}set(e){if(this.disposed)throw new _("unknown_resource","this media volume was disposed");this.port.setMedium(this.id,e),this.desc=e;}mark(){this.disposed||this.port.markMedium(this.id);}dispose(){this.disposed||(this.disposed=true,this.port.destroyMedium(this.id));}};var fIe="cimplify-render",$K=0,_Ie=255,yIe=-1,AIe=0,bIe=28,gIe=15,EIe=1,U1=100,xIe=64,vIe=1e3,RIe=50,SIe=-1,jK=0,dg=1,TIe=0,wIe=.04045,IIe=12.92,OIe=.055,CIe=1.055,NIe=2.4,Zu=255,kIe=4473924,LIe=Math.PI/3,MIe=2,JK=1.5,B1=1,ZK=1,DIe=10,PIe=4,ed=new TextEncoder,FIe=3,UIe=128,BIe=1,GIe=16,VIe=16777215,HIe=0,G1=1,WIe={start:0,end:1,left:2,center:3,right:4},KIe={auto:0,ltr:1,rtl:2},YIe=1,XIe=new TextDecoder,qIe=0,zIe={position:0,normal:1,uv:2,uv1:3,uv2:3,color:4,tangent:5,skinIndex:6,skinWeight:7},eY={bloom:["strength","radius","threshold","physical"],fxaa:[],vignette:["offset","darkness"],color_grade:["exposure","contrast","saturation"],shader:[],ao:["radius","intensity","thickness","quality"],smaa:["threshold","temporal"],taa:["feedback","sharpness"],outline:["thickness","depthThreshold","normalThreshold","color"],ssr:["intensity","maxDistance","thickness","fade"],dof:["focus","aperture","maxBlur"],motion_blur:["intensity","samples"],lut:["texture","intensity","size"],grain:["intensity"],god_rays:["intensity","decay","density","weight"],lens_dirt:["texture","intensity"],sharpen:["sharpness"],chromatic:["amount"],mask:["texture","outline","bloom","hidden"],weather:["rain","snow","wetness","night"],lens_flare:["intensity","ghosts","halo","dispersal"]},QIe={rgba8:[0,4],rgba16f:[2,8],rgba32f:[1,16],r8:[ZV,1],rg8:[eH,2],r16f:[tH,2],rg16f:[nH,4],r32f:[rH,4],rg32f:[iH,8],r8ui:[oH,1],r16ui:[sH,2],r32ui:[aH,4],rg32ui:[lH,8],rgba8ui:[cH,4],rgba16ui:[uH,8],rgba32ui:[dH,16],r32i:[hH,4],rgba32i:[pH,16]},tY={bloom:0,fxaa:1,vignette:2,color_grade:3,shader:4,ao:5,smaa:6,taa:7,outline:8,ssr:9,dof:10,motion_blur:11,lut:12,grain:13,god_rays:14,lens_dirt:15,sharpen:16,chromatic:17,mask:18,weather:19,lens_flare:GH},$Ie={opacity:3,emissiveIntensity:7,metalness:8,roughness:9,alphaTest:10,size:11,clearcoat:12,clearcoatRoughness:13,transmission:14,ior:15},nY=4,jIe=["x","y","z","w"],JIe={f32:1,vec2:2,vec3:3,vec4:4},ZIe={f32:1,i32:1,vec2:2,vec3:3,vec4:4,mat4:16,texture:1},rY={cascades:23,split:24,maxFar:25,fade:26,bias:27,normalBias:28,radius:29,blurSamples:30,type:50},eOe=new Set(["cascades","blurSamples"]);function iY(i,e){return typeof e=="string"?g1[e]:eOe.has(i)?e>>>0:rc(e)}function V1(i){return i<=wIe?i/IIe:((i+OIe)/CIe)**NIe}function tOe(i){return i instanceof Float32Array?0:i instanceof Uint32Array?1:i instanceof Uint16Array?2:i instanceof Uint8Array?3:i instanceof Int16Array?4:5}function hg(i,e){switch(i){case Ea:return new _("capacity_exceeded",`${e}: capacity exceeded`);case xa:case va:return new _("unknown_resource",`${e}: unknown resource`);case Ao:return new _("unsupported_feature",`${e}: unsupported`);default:return new _("invalid_argument",`${e}: invalid argument`)}}function nOe(i){let e={};for(let t of RO){let n=i[t];if(typeof n!="function")throw new _("not_initialized",`engine module is missing ${t}`);e[t]=n;}for(let t of Object.keys(Xu)){let n=i[t];typeof n=="function"&&(e[t]=n);}return e}function pg(i,e,t){return i[t]!==void 0&&(e&Xu[t])!==0}function oY(i,e){return {backend:fIe,dimensions:"3d",rendering:(e&1)!==0,webgpu:false,compute:false,shaderLanguages:["wgsl"],instancing:(e&4)!==0,skinning:(e&8)!==0,morphTargets:(e&16)!==0,renderTargets:(e&32)!==0,postProcessing:(e&64)!==0,models:(e&128)!==0,particles:td(i,e,1024),orderIndependentTransparency:(e&2048)!==0,imageBasedLighting:(e&4096)!==0,cascadedShadows:(e&16384)!==0,renderState:(e&32768)!==0,rawRender:td(i,e,131072),decals:(e&65536)!==0,lod:(e&262144)!==0,fatLines:(e&524288)!==0,text:td(i,e,1048576),picking:td(i,e,2097152),pointShadows:(e&q5)!==0,sky:(e&4096)!==0,customProjection:(e&zb)!==0,gpuTiming:(e&8388608)!==0,globalIllumination:(e&33554432)!==0,rayTracing:(e&67108864)!==0}}function td(i,e,t){return (e&t)===0?false:Object.keys(Xu).filter(n=>Xu[n]===t).every(n=>i[n]!==void 0)}function rOe(i,e){let t=new Uint8Array(i.byteLength+e.byteLength);return t.set(i,0),t.set(e,i.byteLength),t}function iOe(i){let e=[],t=[],n="";for(let[r,o]of Object.entries(i.uniforms??{})){let s=JIe[o.type];if(s===void 0)throw new _("invalid_argument",`post shader uniform ${r} must be f32, vec2, vec3 or vec4`);if(e.length+s>nY)throw new _("invalid_argument",`post shader uniforms hold ${nY} floats`);let a=e.length,l=[];for(let d=0;d<s;d++){e.push(s===1?r:`${r}.${jIe[d]}`);let h=o.value;t.push(typeof h=="number"?h:h instanceof Float32Array?h[d]??0:0),l.push(`pass_info.params[${a+d}]`);}let c=s===1?"f32":`vec${s}f`,u=s===1?l[0]:`${c}(${l.join(", ")})`;n+=`fn ${r}() -> ${c} { return ${u}; }
31
+ `;}return {source:ed.encode(n+i.shader.wgsl.fragment),params:e,values:t}}var dr=class{constructor(e,t=nOe(e.symbols),n=null,r={}){this.attacher=n;this.nativeSurface=null;this.stopResize=null;this.raw=null;this.refresh=Float64Array.of(SIe,U1);this.observed=0;this.budgetMicros=0;this.pending=0;this.scratch=0;this.scratchBytes=0;this.attributes=new Map;this.textures=new Map;this.targetDepths=new Map;this.targetFormats=new Map;this.targetAttachments=new Map;this.targetReads=[];this.uniforms=new Map;this.chains=new Map;this.models=new Map;this.roots=new Map;this.clipPort=null;this.nodeViews=new Map;this.targetTextures=new Map;this.matrixScratch=null;this.poseReaders=[];this.fontFamilies=new Map;this.textNodes=new Map;this.defaultFont=null;this.textPointer=0;this.textBytes=0;this.pickPointer=0;this.disposed=false;this.feedSupport=null;this.poseSupport=null;this.mediaSupport=null;this.mediaLive=new Array(17).fill(false);this.mediaViews=new Array(17).fill(null);this.mediumWords=new Float32Array(14);this.passScratch=new Uint32Array(10);this.batchViews=new Map;this.runtime=e,this.abi=t;let o=e.symbols.engine_render_set_frame_budget;this.frameBudget=typeof o=="function"?o:null;let s=e.symbols.engine_render_force_tier;this.forceTierCall=typeof s=="function"?s:null;let a=e.symbols.engine_render_quality_tier;if(this.qualityTierCall=typeof a=="function"?a:null,this.handle=tK(e,r,m=>t.engine_render_create(m===0?$K:m)),this.handle===$K)throw Pu(e.symbols)??new _("capacity_exceeded","engine renderer could not be created");let l=this.buffer,c=t.engine_render_desc(this.handle);this.desc=new Uint32Array(l,c,64),this.descFloats=new Float32Array(l,c,64);let u=t.engine_render_registers(this.handle);this.registers=new Uint32Array(l,u,34),this.registerFloats=new Float32Array(l,u,34);let d=t.engine_render_commands(this.handle);this.commandWords=new Uint32Array(l,d,1024*8),this.commandFloats=new Float32Array(l,d,1024*8),this.sync=this.u32(5,0,0),this.params=this.f32(3,0,0);let h=t.engine_render_capabilities(this.handle),p=w5(e.symbols);this.vectorSurfaces=p===null?null:new Hb(p,{handle:this.handle,buffer:()=>this.buffer,stage:m=>this.stage(m),flush:()=>this.flush()}),this.capabilities={...oY(t,h),vectorSurfaces:this.vectorSurfaces?.cap??0},this.caps=h,this.features=new Qb({caps:()=>this.caps,command:(m,f)=>this.command(m,f),words:this.commandWords,floats:this.commandFloats,flush:()=>this.flush(),buffer:(m,f,y)=>this.f32(m,f,y),registers:this.registers});}get gpu(){return this.raw===null&&(this.raw=GW(this.rawHost())),this.raw}rawCapabilities(){let e=this.caps,t=td(this.abi,e,8192),n=td(this.abi,e,131072);return e&-139265|(t?8192:0)|(n?131072:0)}get clips(){if(pg(this.abi,this.caps,"engine_render_animation"))return this.clipPort??=new Vb(this.clipHost()),this.clipPort}clipHost(){let e={words:[],floats:[]},t=n=>n!==void 0&&n.buffer===this.buffer;return {command:(n,r)=>this.command(n,r),commandWords:this.commandWords,commandFloats:this.commandFloats,animation:(n,r,o)=>{this.flush();let s=o.length===0?0:this.stage(new Uint8Array(o.buffer,o.byteOffset,o.byteLength)),a=this.check(this.feature("engine_render_animation")(this.handle,n,r,s,o.length),"animation");return s!==0&&o.set(new Uint32Array(this.buffer,s,o.length)),a},words:n=>{let r=e.words[n];if(t(r))return r;let o=this.u32(14,0,n);return e.words[n]=o,o},floats:n=>{let r=e.floats[n];if(t(r))return r;let o=this.f32(14,0,n);return e.floats[n]=o,o},model:n=>{let r=this.roots.get(n),o=r===void 0?void 0:this.models.get(r);if(o===void 0)throw new _("invalid_argument",`node ${n} is not a model instance`);return o},refreshModel:n=>this.refreshModel(n),findNode:(n,r)=>this.findNode(n,r),createPoseReader:n=>this.createPoseReader(n),readPoses:(n,r,o)=>this.readPoses(n,r,o),destroyPoseReader:n=>this.destroyPoseReader(n),uniformSlot:(n,r)=>{let o=this.uniform(n,r);if(o===null)throw new _("invalid_argument",`material ${n} has no shader uniform ${r}`);return o},postParam:(n,r,o)=>{let a=this.chains.get(n)?.params[r]?.indexOf(o)??-1;if(a<0)throw new _("invalid_argument",`post chain ${n} effect ${r} has no parameter ${o}`);return a}}}rawHost(){let e=this;return {get capabilities(){return e.rawCapabilities()},clearDesc:()=>this.clearDesc(),command:(t,n)=>this.command(t,n),commandWords:this.commandWords,stage:t=>this.stage(t),call:(t,...n)=>this.feature(t)(this.handle,...n),bytes:(t,n,r)=>{let[o,s]=this.view(t,n,r);return new Uint8Array(this.buffer,o,s)},flush:()=>this.flush(),view:(t,n)=>new Uint8Array(this.buffer,t,n)}}get buffer(){return this.runtime.memory.buffer}feature(e){let t=this.abi[e];if(t===void 0||!pg(this.abi,this.caps,e))throw new _("unsupported_feature",`this engine build does not provide ${e}; update the app to use this feature`);return t}check(e,t){if(e<0)throw hg(e,t);return e}owns(e){let t=bV[e];return t===void 0||(this.caps&t)!==0}view(e,t,n){if(!this.owns(e))throw new _("unsupported_feature",`this engine build has no buffer owner ${e}`);let r=this.abi.engine_render_buffer(this.handle,e,t,n);if(r===0)throw new _("unknown_resource",`engine buffer ${e}:${t}:${n} does not exist`);return [r,this.registers[31]]}f32(e,t,n){let[r,o]=this.view(e,t,n);return new Float32Array(this.buffer,r,o)}u32(e,t,n){let[r,o]=this.view(e,t,n);return new Uint32Array(this.buffer,r,o)}clearDesc(){return this.desc.fill(0),this.desc}stage(e){if(e.byteLength>this.scratchBytes&&(this.scratch!==0&&this.runtime.exports.engine_free(this.scratch,this.scratchBytes,ce),this.scratchBytes=Math.max(e.byteLength,ce),this.scratch=this.runtime.exports.engine_alloc(this.scratchBytes,ce),this.scratch===0))throw new _("capacity_exceeded","engine memory cannot stage asset bytes");return new Uint8Array(this.buffer,this.scratch,e.byteLength).set(e),this.scratch}command(e,t){this.pending===1024&&this.flush();let n=this.pending*8;return this.commandWords[n+0]=e,this.commandWords[n+1]=t,this.pending++,n+2}flush(){if(this.pending===0)return;let e=this.pending;this.pending=0,this.check(this.abi.engine_render_flush(this.handle,e),"graphics command");}get renderHandle(){return this.handle}passTimings(e){if(!this.owns(13))return false;let t=this.abi.engine_render_buffer(this.handle,13,0,0);return t===0?false:(e.set(new Uint32Array(this.buffer,t,Math.min(10,e.length))),true)}get native(){return this.nativeSurface}async attach(e){if(e!==null||this.attacher===null||this.nativeSurface!==null)return;let t=await this.attacher(this.handle,{});this.nativeSurface=t,this.caps=this.abi.engine_render_capabilities(this.handle),this.capabilities={...oY(this.abi,this.caps),vectorSurfaces:this.vectorSurfaces?.cap??0},this.resize(t.width,t.height,t.pixel_ratio),this.stopResize=t.on_resize((n,r,o)=>this.resize(n,r,o));}resize(e,t,n){let r=this.command(30,0);this.commandWords[r]=Math.max(1,Math.round(e*n)),this.commandWords[r+1]=Math.max(1,Math.round(t*n)),this.commandFloats[r+2]=n,this.features.resize(e,t);}createGeometry(e){let t=Object.keys(e.attributes);if(t.length>8)throw new _("invalid_argument",`geometry has more than ${8} attributes`);let n=e.attributes.position;if(!n)throw new _("invalid_argument","geometry needs a position attribute");let r=n.data.length/n.itemSize,o=e.morphTargets??[],s=this.clearDesc();s[0]=t.length,s[1]=r,s[2]=e.index?.length??0,s[3]=e.index instanceof Uint32Array?1:0,s[4]=o.length,s[5]=o.length>0&&o.every(c=>c.normal!==void 0)?1:0,s[6]=e.morphRelative===false?0:1,t.forEach((c,u)=>{let d=e.attributes[c],h=8+u*4;s[h+0]=zIe[c]??8+u,s[h+1]=tOe(d.data),s[h+2]=d.itemSize,s[h+3]=(d.normalized?1:0)|(d.dynamic?2:0);});let a=this.check(this.abi.engine_render_create_geometry(this.handle),"create geometry"),l=new Map;if(t.forEach((c,u)=>{let d=e.attributes[c].data,[h]=this.view(0,a,u),p=d.constructor,m=new p(this.buffer,h,d.length);m.set(d),l.set(c,{source:d,target:m,slot:u});}),this.attributes.set(a,l),e.index){let[c]=this.view(0,a,65535);(e.index instanceof Uint32Array?new Uint32Array(this.buffer,c,e.index.length):new Uint16Array(this.buffer,c,e.index.length)).set(e.index);}if(o.length>0){let c=this.f32(0,a,65534),u=r*3;if(o.forEach((d,h)=>c.set(d.position,h*u)),s[5]===1){let d=this.f32(0,a,65533);o.forEach((h,p)=>{h.normal&&d.set(h.normal,p*u);});}}return this.check(this.abi.engine_render_commit_geometry(this.handle,a),"commit geometry"),a}geometryAttribute(e,t){let n=this.attributes.get(e)?.get(t);if(!n)throw new _("unknown_resource",`geometry ${e} has no attribute ${t}`);return n.source}markGeometryDirty(e,t,n,r){let o=this.attributes.get(e),s=o?.get(t);if(!o||!s)throw new _("unknown_resource",`geometry ${e} has no attribute ${t}`);let a=r<0?s.source.length:Math.min(s.source.length,n+r);for(let l=n;l<a;l++)s.target[l]=s.source[l];this.commandWords[this.command(16,e)]=s.slot;}setDrawRange(e,t,n){let r=this.command(17,e);this.commandWords[r]=t,this.commandWords[r+1]=n;}destroyGeometry(e){this.command(18,e),this.attributes.delete(e);}createTexture(e){if(e.source.kind==="video"){let h=this.clearDesc();return h[0]=e.source.width,h[1]=e.source.height,h[8]=_H,this.check(this.abi.engine_render_create_texture(this.handle),"create video texture")}if(e.source.kind!=="pixels")throw new _("unsupported_feature","the Cimplify renderer takes pixel or encoded textures; decode images with loadTexture");let{width:t,height:n,data:r}=e.source,o=e.source.format??(r instanceof Float32Array?"rgba32f":r instanceof Uint16Array?"rgba16f":"rgba8"),[s,a]=QIe[o],l=e.kind==="2d-array"||e.kind==="3d",c=e.kind==="cube"?6:l?e.source.depth??1:1;if(e.kind==="cube"&&(t!==n||r.byteLength!==t*n*6*a))throw new _("invalid_argument","cube textures take six square faces packed +X, -X, +Y, -Y, +Z, -Z");if(r.byteLength!==t*n*c*a)throw new _("invalid_argument",`a ${o} texture of ${t}x${n}x${c} takes ${t*n*c*a} bytes`);let u=this.clearDesc();u[0]=t,u[1]=n,u[2]=s,u[8]=e.kind==="cube"?1:e.kind==="equirect"?2:e.kind==="2d-array"?mH:e.kind==="3d"?fH:0,u[9]=c,u[3]=e.colorSpace==="linear"?1:0,u[4]=e.wrap==="clamp"?1:e.wrap==="mirror"?2:0,u[5]=e.filter==="nearest"?1:0,u[6]=e.mipmaps===false?0:1,u[7]=e.flipY?1:0;let d=this.check(this.abi.engine_render_create_texture(this.handle),"create texture");return this.textures.set(d,{data:r,width:t,height:n,depth:c,texelBytes:a}),this.copyTexture(d,r),this.requestEncode(d,e.encode),d}requestEncode(e,t){if(t===void 0||t==="none"||!pg(this.abi,this.caps,"engine_render_encode_texture"))return;let n=this.abi.engine_render_encode_texture;if(!n)return;let r=t==="astc"?AH:t==="bc7"?bH:yH;n(this.handle,e,r);}copyTexture(e,t){let[n]=this.view(1,e,0);new Uint8Array(this.buffer,n,t.byteLength).set(new Uint8Array(t.buffer,t.byteOffset,t.byteLength));}copyRegion(e,t,n){let[r]=this.view(1,e,0),o=new Uint8Array(t.data.buffer,t.data.byteOffset,t.data.byteLength),s=new Uint8Array(this.buffer,r,t.data.byteLength),a=t.width*t.texelBytes,l=n.width*t.texelBytes,c=n.z??0;for(let u=c;u<c+(n.depth??1);u++)for(let d=n.y;d<n.y+n.height;d++){let h=(u*t.height+d)*a+n.x*t.texelBytes;s.set(o.subarray(h,h+l),h);}}async loadTexture(e){let t=await this.bytes(e,"texture"),n=this.stage(t);return this.check(this.abi.engine_render_decode_texture(this.handle,n,t.byteLength,G1),"decode texture")}async upgradeTexture(e,t){let n=await this.bytes(t,"texture"),r=this.reloadExport("engine_render_reload_texture");if(r!==null){this.flush();let a=r(this.handle,e,this.stage(n),n.byteLength,G1);if(a>=0)return {texture:e,inPlace:true};if(a!==Vp)throw hg(a,"reload texture")}let o=this.stage(n);return {texture:this.check(this.abi.engine_render_decode_texture(this.handle,o,n.byteLength,G1),"decode texture"),inPlace:false}}reloadExport(e){return pg(this.abi,this.caps,e)?this.abi[e]??null:null}markTextureDirty(e,t){let n=this.textures.get(e);if(t===void 0){n&&this.copyTexture(e,n.data),this.command(19,e);return}n&&this.copyRegion(e,n,t);let r=this.command(QV,e),o=this.commandWords;o[r]=t.x,o[r+1]=t.y,o[r+2]=t.z??0,o[r+3]=t.width,o[r+4]=t.height,o[r+5]=t.depth??1;}destroyTexture(e){this.command(20,e),this.textures.delete(e);}createMaterial(e){pK(e);let t=this.clearDesc(),n=this.descFloats;t[0]=z5[e.kind];let r="color"in e&&e.color!==void 0?e.color:16777215;this.writeHex(n,1,r),n[4]=e.opacity??1,n[11]=e.alphaTest??0,n[25]=JK,n[6]=B1,n[21]=ZK;let o=0;e.transparent&&(o|=1),e.depthTest!==false&&(o|=2),(e.depthWrite??!e.transparent)&&(o|=4),e.vertexColors&&(o|=8),e.wireframe&&(o|=16),t[13]=e.side==="back"?1:e.side==="double"?2:0,t[14]=e.blending==="additive"?1:e.blending==="multiply"?2:e.blending==="none"?3:e.blending==="custom"?4:0;let s=(A,E)=>{t[A]=E;};hK(e,s);let a=mK(e);for(let A=0;A<8;A++)t[51+A]=a[A]??0;J5(e,t,n),o|=j5(e),o|=$5(e,t);let l=null,c=null;switch(e.kind){case "standard":case "physical":{o|=64,e.flatShading&&(o|=32),n[5]=e.metalness??0,n[6]=e.roughness??B1,this.writeHex(n,7,e.emissive??0),n[10]=e.emissiveIntensity??1,[e.map,e.normalMap,e.roughnessMap,e.metalnessMap,e.emissiveMap,e.aoMap].forEach((E,R)=>{t[15+R]=E??0;}),e.kind==="physical"&&(n[22]=e.clearcoat??0,n[23]=e.clearcoatRoughness??0,n[24]=e.transmission??0,n[25]=e.ior??JK,n[26]=e.sheen??0);break}case "skin":case "eye":case "hair":{o|=64,e.flatShading&&(o|=32),n[6]=e.roughness??B1,this.writeHex(n,7,e.emissive??0),n[10]=e.emissiveIntensity??1,[e.map,e.normalMap,e.roughnessMap,void 0,e.emissiveMap,e.aoMap].forEach((E,R)=>{t[15+R]=E??0;}),F5(e,s);break}case "unlit":case "sprite":t[15]=e.map??0,e.kind==="sprite"&&e.sizeAttenuation!==false&&(o|=128);break;case "points":t[15]=e.map??0,n[21]=e.size??ZK,e.sizeAttenuation!==false&&(o|=128);break;case "lines":break;case "shader":{e.lights&&(o|=64),l=ed.encode(e.shader.wgsl.fragment),c=new Map;let A=0;for(let[E,R]of Object.entries(e.uniforms??{})){let g=ZIe[R.type];c.set(E,{offset:A,words:g}),A+=g;}t[27]=A;break}}t[12]=o;let u=e.textureTransforms?new Float32Array(Lb.length*8):null,d=u!==null&&fK(e,u,s),h=e.kind==="shader"&&e.shader.wgsl.vertex?ed.encode(e.shader.wgsl.vertex):null,p=l&&h?rOe(l,h):l,m=p?this.stage(p):0,f=l?.byteLength??0,y=this.check(this.abi.engine_render_create_material(this.handle,m,f,h?m+f:0,h?.byteLength??0),"create material"),b=(e.clippingPlanes?.length??0)>0&&S1(e,this.f32(7,y,0));if(u&&d&&this.f32(8,y,0).set(u),(b||d)&&this.command(13,y),c&&e.kind==="shader"){this.uniforms.set(y,c);for(let[A,E]of Object.entries(e.uniforms??{}))typeof E.value=="number"?this.setMaterialScalar(y,A,E.value):E.value instanceof Float32Array&&this.setMaterialVector(y,A,E.value);}return this.features.material(y,e),y}writeHex(e,t,n){e[t]=V1((n>>16&Zu)/Zu),e[t+1]=V1((n>>8&Zu)/Zu),e[t+2]=V1((n&Zu)/Zu);}setMaterialColor(e,t,n,r){let o=e*20+0;this.params[o]=t,this.params[o+1]=n,this.params[o+2]=r,this.command(13,e);}setMaterialOpacity(e,t){this.params[e*20+3]=t,this.command(13,e);}setMaterialTexture(e,t,n){let r=this.command(14,e);this.commandWords[r]=rg(t),this.commandWords[r+1]=n??0;}uniform(e,t){let n=this.uniforms.get(e);if(!n)return null;let r=n.get(t);if(!r)throw new _("invalid_argument",`material ${e} has no uniform ${t}`);return r}setMaterialScalar(e,t,n){let r=this.uniform(e,t);if(r)this.f32(2,e,0)[r.offset]=n;else {let o=$Ie[t];if(o===void 0)throw new _("invalid_argument",`material ${e} has no scalar ${t}`);this.params[e*20+o]=n;}this.command(13,e);}setMaterialVector(e,t,n){let r=this.uniform(e,t);if(!r)throw new _("invalid_argument","vector uniforms belong to shader materials");if(n.length>r.words)throw new _("invalid_argument",`uniform ${t} holds ${r.words} values`);this.f32(2,e,0).set(n,r.offset),this.command(13,e);}setMaterialUniformTexture(e,t,n){let r=this.uniform(e,t);if(!r)throw new _("invalid_argument","texture uniforms belong to shader materials");this.u32(2,e,0)[r.offset]=n,this.command(13,e);}setMaterialState(e,t){R1(t,(n,r)=>{let o=this.command(VV,e);this.commandWords[o]=n,this.commandWords[o+1]=r;}),(t.clippingPlanes?.length??0)>0&&S1(t,this.f32(7,e,0))&&this.command(13,e);}destroyMaterial(e){this.command(15,e),this.uniforms.delete(e),this.features.forgetMaterial(e);}createEmitter(e){if(!this.capabilities.particles)throw new _("unsupported_feature","this engine build has no particles");this.flush(),N5(this.clearDesc(),this.descFloats,e);let t=this.check(this.feature("engine_render_create_emitter")(this.handle),"create emitter");return e.sizeCurve&&o1(e.sizeCurve,this.f32(9,t,0)),e.colorCurve&&o1(e.colorCurve,this.f32(9,t,1)),(e.sizeCurve||e.colorCurve)&&this.command(DV,t),t}emit(e,t){this.commandWords[this.command(MV,e)]=t;}setEmitterRate(e,t){this.commandFloats[this.command(kb,e)]=t;}clearEmitter(e){this.command(XV,e);}destroyEmitter(e){this.command(PV,e);}setRenderOrder(e,t){this.commandWords[this.command(LV,e)]=t|0;}setShadow(e,t){let n=6,r=0,o=n;for(let s of Object.keys(t)){let a=t[s];a!==void 0&&(o===n&&(r=this.command(GV,e),o=0),this.commandWords[r+o]=rY[s],this.commandWords[r+o+1]=iY(s,a),o+=2);}o<n&&(this.commandWords[r+o]=0);}writeShadow(e,t){if(t)for(let n of Object.keys(t)){let r=t[n];r!==void 0&&(e[rY[n]]=iY(n,r));}}createNode(e){let t=this.clearDesc(),n=this.descFloats;switch(t[22]=e.renderOrder??0,e.kind){case "mesh":t[0]=0,t[1]=e.geometry,t[2]=Array.isArray(e.material)?e.material[0]??0:e.material,t[3]=this.shadowFlags(e.castShadow,e.receiveShadow,e.giExclude);break;case "instanced":t[0]=1,t[1]=e.geometry,t[2]=e.material,t[4]=e.capacity,t[3]=this.shadowFlags(e.castShadow,e.receiveShadow,e.giExclude)|(e.colors?4:0)|(e.batchSlots?64:0),t[18]=e.batchSlots??0;break;case "skinned":{t[0]=2,t[1]=e.geometry,t[2]=e.material,t[3]=this.shadowFlags(e.castShadow,e.receiveShadow,e.giExclude);let{parents:o,bindPose:s,inverseBindMatrices:a}=e.skeleton;if(s.length!==o.length*DIe)throw new _("invalid_argument","bind pose needs ten floats per bone");let l=Math.ceil(o.byteLength/ce)*ce,c=Math.ceil(s.byteLength/ce)*ce,u=new Uint8Array(l+c+(a?.byteLength??0));u.set(new Uint8Array(o.buffer,o.byteOffset,o.byteLength),0),u.set(new Uint8Array(s.buffer,s.byteOffset,s.byteLength),l),a&&u.set(new Uint8Array(a.buffer,a.byteOffset,a.byteLength),l+c);let d=this.stage(u);t[18]=o.length,t[19]=d,t[20]=d+l,t[21]=a?d+l+c:0;break}case "points":t[0]=3,t[1]=e.geometry,t[2]=e.material;break;case "lines":t[0]=4,t[1]=e.geometry,t[2]=e.material,t[3]=e.segments?8:0;break;case "sprite":t[0]=5,t[2]=e.material;break;case "camera":t[0]=6,t[14]=e.projection==="orthographic"?1:0,n[15]=e.projection==="orthographic"?e.height:e.projection==="perspective"?e.fov??60:60,n[16]=e.near??.1,n[17]=e.far??1e3;break;case "decal":break;case "light":{t[0]=7,t[5]=b1[e.light],t[6]=e.color??16777215,t[12]=e.groundColor??kIe,t[3]=e.castShadow?1:0,t[13]=e.shadowMapSize??0,n[7]=e.intensity??1,n[8]=e.distance??0,n[9]=e.decay??MIe,n[10]=e.angle??LIe,n[11]=e.penumbra??0,this.writeShadow(t,e.shadow);break}case "particles":t[0]=9,t[31]=e.emitter;break;case "group":t[0]=8;break;case "shape2d":throw new _("unsupported_feature","shape2d nodes need the 2D renderer");case "text2d":case "text3d":{let o=e.kind==="text2d"?2:e.billboard?1:0,s=e.kind==="text3d"?e.font:this.resolveFont(e.font,e.fontFamily);this.writeText(t,n,s,e,o);let a=this.check(this.abi.engine_render_create_node(this.handle),`create ${e.kind} node`);return this.textNodes.set(a,{font:s,mode:o}),e.text&&this.setNodeText(a,e.text),a}}eK(e,t,n,e.kind==="sprite"?this.features.spriteRotation(e.material):0);let r=this.check(this.abi.engine_render_create_node(this.handle),`create ${e.kind} node`);return this.features.node(r,e),r}setLod(e,t,n,r){this.features.setLod(e,t,n,r);}setSprite(e,t,n,r){this.features.setSprite(e,t,n,r);}setProbeCoefficients(e,t){this.features.setProbeCoefficients(e,t);}setProjectionMatrix(e,t,n,r){this.features.setProjectionMatrix(e,t,n,r);}setViewOffset(e,t){this.features.setViewOffset(e,t);}batchBuffers(e){let t=this.batchViews.get(e);if(t)return t;this.flush();let n=this.abi.engine_render_buffer(this.handle,4,e,5);if(n===0)return null;let r=this.registers[31],o=this.abi.engine_render_buffer(this.handle,4,e,6);if(o===0)return null;let s={slots:new Uint32Array(this.buffer,n,r),ranges:new Uint32Array(this.buffer,o,this.registers[31])};return this.batchViews.set(e,s),s}markBatch(e){this.command(62,e);}gpuStats(e){this.flush(),this.check(this.abi.engine_render_stats(this.handle),"stats"),this.features.readGpuStats(e);let t=this.passTimings(this.passScratch);for(let n=0;n<e.passNs.length;n++)e.passNs[n]=t?this.passScratch[n]??0:0;return t||e.gpuLastNs>0}resolveFont(e,t){let n=e??(t!==void 0?this.fontFamilies.get(t):void 0)??this.defaultFont;if(n==null)throw new _("asset_load_failed","load a font with loadFont before creating text");return n}writeText(e,t,n,r,o){e[0]=11,e[4]=r.capacity??UIe,e[6]=r.color??VIe,e[37]=n,e[46]=o,e[42]=WIe[r.align??"start"],e[43]=KIe[r.direction??"auto"],e[48]=r.outlineColor??0,t[38]=r.size??(o===2?GIe:BIe),t[39]=r.lineHeight??0,t[40]=r.letterSpacing??0,t[41]=r.maxWidth??0,t[44]=r.anchor?.[0]??0,t[45]=r.anchor?.[1]??0,t[47]=r.outlineWidth??0,t[49]=r.opacity??1;}async loadFont(e,t){let[n,r]=await Promise.all([this.bytes(e.atlas,"font atlas"),this.bytes(e.table,"font table")]),o=this.check(this.abi.engine_render_decode_texture(this.handle,this.stage(n),n.byteLength,HIe),"decode font atlas"),s=this.createMaterial({kind:"unlit",transparent:true,depthWrite:false});this.setMaterialTexture(s,"map",o);let a=this.check(this.feature("engine_render_load_font")(this.handle,this.stage(r),r.byteLength,s),"load font");return e.face!==void 0&&await this.loadFontFace(a,e.face),t!==void 0&&this.fontFamilies.set(t,a),this.defaultFont??=a,JW(a,new Bb(r.slice().buffer)),a}async loadFontFace(e,t){let n=this.abi.engine_render_font_face;if(n===void 0)return;let r=await this.bytes(t,"font face");this.check(n(this.handle,e,this.stage(r),r.byteLength),"load font face");}setTextStyle(e,t){let n=this.textNodes.get(e);if(n===void 0)throw new _("unknown_resource","setTextStyle needs a text node");this.writeText(this.clearDesc(),this.descFloats,n.font,t,n.mode),this.check(this.feature("engine_render_set_text_style")(this.handle,e),"set text style");}textBounds(e,t){let n=this.pickScratch();this.check(this.feature("engine_render_text_bounds")(this.handle,e,n),"text bounds"),t.set(new Float32Array(this.buffer,n,4));}batchHandle(){return this.handle}forceQualityTier(e){return this.forceTierCall===null?false:(this.check(this.forceTierCall(this.handle,e===null?yIe:e),"force quality tier"),true)}qualityTier(){return this.qualityTierCall===null?AIe:this.check(this.qualityTierCall(this.handle),"quality tier")}governorPressure(){this.check(this.abi.engine_render_stats(this.handle),"stats");let e=this.registers[Nb];return Math.max(e&_Ie,e>>>bIe&gIe)}raycast(e,t,n,r,o){let s=this.pickScratch(),a=new Float32Array(this.buffer,s,7);a[0]=e[0],a[1]=e[1],a[2]=e[2],a[3]=t[0],a[4]=t[1],a[5]=t[2],a[6]=n;let l=s+7*Rt;if(this.check(this.feature("engine_render_raycast")(this.handle,s,r>>>0,l),"raycast")!==YIe)return false;let u=new Uint32Array(this.buffer,l,11),d=new Float32Array(this.buffer,l,11);return o.node=u[0],o.instance=u[1],o.triangle=u[2],o.distance=d[3],o.point.set(d.subarray(4,7)),o.barycentric.set(d.subarray(7,9)),o.uv.set(d.subarray(9,11)),true}pickScratch(){if(this.pickPointer===0&&(this.pickPointer=this.runtime.exports.engine_alloc(18*Rt,ce),this.pickPointer===0))throw new _("capacity_exceeded","engine memory cannot hold the pick scratch");return this.pickPointer}shadowFlags(e,t,n){return (e?1:0)|(t?2:0)|(n?32:0)}destroyNode(e){this.command(1,e),this.roots.delete(e),this.nodeViews.delete(e),this.textNodes.delete(e),this.batchViews.delete(e),this.features.forgetNode(e);}setNodeVisible(e,t){this.commandWords[this.command(2,e)]=t?1:0;}setNodeLayers(e,t){this.commandWords[this.command(3,e)]=t>>>0;}setNodeMaterial(e,t){this.commandWords[this.command(4,e)]=t;}setNodeText(e,t){let n=Math.max(t.length*FIe,ce);if(n>this.textBytes&&(this.textPointer!==0&&this.runtime.exports.engine_free(this.textPointer,this.textBytes,ce),this.textBytes=n,this.textPointer=this.runtime.exports.engine_alloc(n,ce),this.textPointer===0))throw new _("capacity_exceeded","engine memory cannot stage text");let r=ed.encodeInto(t,new Uint8Array(this.buffer,this.textPointer,this.textBytes)).written;this.check(this.feature("engine_render_set_text")(this.handle,e,this.textPointer,r),"set text");}writeNodeMatrices(e,t,n,r){if(t.buffer!==this.buffer)throw new _("invalid_argument","the Cimplify renderer reads render matrices from engine memory");let o=this.sync;for(let s=0;s<r;s++)o[2*s]=e[s],o[2*s+1]=n[s];this.flush(),this.check(this.abi.engine_render_sync(this.handle,r,t.byteOffset,t.length/16),"sync matrices");}readNodeMatrix(e,t,n){this.flush();let r=this.nodeMatrixScratch();this.check(this.abi.engine_render_node_matrix(this.handle,e,r.byteOffset),"read node matrix");for(let o=0;o<16;o++)t[n+o]=r[o];}createPoseReader(e){let t=e.length,n=t*Rt*(1+EO),r=t===0?0:this.runtime.exports.engine_alloc(n,ce);if(t>0&&r===0)throw new _("capacity_exceeded","engine memory cannot hold a bone set");t>0&&new Uint32Array(this.buffer,r,t).set(e);let o={pointer:r,bytes:n,count:t,out:r+t*Rt,view:null},s=this.poseReaders.indexOf(null,1);return s>0?(this.poseReaders[s]=o,s):(this.poseReaders.length===0&&this.poseReaders.push(null),this.poseReaders.push(o),this.poseReaders.length-1)}poseReader(e){let t=this.poseReaders[e];if(!t)throw new _("unknown_resource",`bone set ${e} does not exist`);return t}readPoses(e,t,n){let r=this.poseReader(e);if(r.count===0)return;this.flush(),this.check(this.feature("engine_render_node_poses")(this.handle,r.pointer,r.count,r.out),"read bone poses");let o=r.view;(o===null||o.buffer!==this.buffer)&&(o=new Float32Array(this.buffer,r.out,r.count*EO),r.view=o);for(let s=0;s<o.length;s++)t[n+s]=o[s];}destroyPoseReader(e){let t=this.poseReader(e);t.pointer!==0&&this.runtime.exports.engine_free(t.pointer,t.bytes,ce),this.poseReaders[e]=null;}nodeMatrixScratch(){if(!this.matrixScratch){let e=this.runtime.exports.engine_alloc(16*Rt,ce);if(e===0)throw new _("capacity_exceeded","engine memory cannot hold a matrix");this.matrixScratch=new Float32Array(this.buffer,e,16);}return this.matrixScratch}nodeBuffer(e,t){let n=e*PIe+t,r=this.nodeViews.get(n);if(r)return r;let o=this.f32(4,e,t);return this.nodeViews.set(n,o),o}instanceMatrices(e){return this.nodeBuffer(e,0)}instanceColors(e){try{return this.nodeBuffer(e,1)}catch{return null}}setInstanceCount(e,t){this.commandWords[this.command(5,e)]=t;}markInstancesDirty(e){this.command(6,e);}setInstanceFeed(e,t,n,r,o){if(this.feedSupport===null&&(this.feedSupport=og(this.runtime,pV)),!this.feedSupport||n.length!==4||o!==void 0&&(o.length!==2||!this.posesSupported()))return false;let s=this.command(64,e);this.commandWords[s]=t;for(let a=0;a<4;a++)this.commandWords[s+1+a]=n[a];if(this.commandWords[s+1+4]=r?1:0,o!==void 0){let a=this.command(66,e);for(let l=0;l<2;l++)this.commandWords[a+l]=o[l];}return true}setInstancePalette(e,t,n,r,o,s){if(!this.posesSupported())return false;let a=this.command(67,e);return this.commandWords[a]=t,this.commandWords[a+1]=n,this.commandWords[a+2]=r,this.commandWords[a+3]=o,this.commandWords[a+4]=s,true}posesSupported(){return this.poseSupport===null&&(this.poseSupport=og(this.runtime,mV)),this.poseSupport}requireMedia(){if(this.mediaSupport===null&&(this.mediaSupport=og(this.runtime,Ob)),!this.mediaSupport)throw new _("unsupported_feature",`this engine build has no media volumes (feature ${Ob}); update the app to use them`)}liveMedium(e){let t=e;if(!(Number.isInteger(t)&&t>=1&&t<=16&&this.mediaLive[t]))throw new _("unknown_resource",`media volume ${t} does not exist`);return t}sendMedium(e,t,n){gK(this.mediumWords,n),this.flush(),this.f32(A1,0,0).set(this.mediumWords),this.command(e,t),this.flush(),this.mediaViews[t]=null;}createMedium(e){this.requireMedia();let t=this.mediaLive.indexOf(false,1);if(t<0)throw new _("capacity_exceeded",`a scene holds at most ${16} media volumes`);return this.sendMedium(68,t,e),this.mediaLive[t]=true,t}setMedium(e,t){this.sendMedium(69,this.liveMedium(e),t);}mediumTexels(e){let t=this.liveMedium(e),n=this.mediaViews[t];if(n!==null&&n.buffer===this.buffer)return n;let r=this.u32(16,t,0);return this.mediaViews[t]=r,r}markMedium(e){this.command(71,this.liveMedium(e));}destroyMedium(e){let t=this.liveMedium(e);this.command(70,t),this.flush(),this.mediaLive[t]=false,this.mediaViews[t]=null;}clearInstanceFeed(e){this.feedSupport===true&&this.command(65,e);}morphWeights(e){return this.nodeBuffer(e,2)}markMorphWeightsDirty(e){this.command(7,e);}skeletonPose(e){return this.nodeBuffer(e,3)}markSkeletonDirty(e){this.command(8,e);}setCameraPerspective(e,t,n,r){let o=this.command(9,e);this.commandFloats[o]=t,this.commandFloats[o+1]=n,this.commandFloats[o+2]=r,this.features.perspective(e,t,n,r);}setCameraPerspectiveFrom(e,t,n){let r=this.command(9,e),o=this.commandFloats;o[r]=t[n],o[r+1]=t[n+1],o[r+2]=t[n+2],this.features.perspectiveFrom(e,t,n);}setCameraOrthographic(e,t,n,r){let o=this.command(10,e);this.commandFloats[o]=t,this.commandFloats[o+1]=n,this.commandFloats[o+2]=r,this.features.orthographic(e,t,n,r);}setActiveCamera(e){this.command(11,e);}setLight(e,t,n){let r=this.command(12,e);this.commandWords[r]=t,this.commandFloats[r+1]=n;}setEnvironment(e){this.flush();let t=this.clearDesc(),n=this.descFloats,r=e.background;t[2]=0,r&&"color"in r?(t[0]=1,t[1]=r.color):r&&"texture"in r?(t[0]=2,t[2]=r.texture):r?t[0]=3:t[0]=1,t[3]=e.environment??0,n[15]=e.environmentIntensity??1,n[16]=e.environmentRotation??0,n[17]=e.backgroundBlurriness??0,n[18]=e.backgroundIntensity??1;let o=e.fog;o&&(t[4]=1,t[5]=o.color,t[11]=AV.indexOf(o.mode??"linear"),o.mode==="exp2"||o.mode==="height"?n[12]=o.density:(n[6]=o.near,n[7]=o.far),o.mode==="height"&&(n[13]=o.height,n[14]=o.falloff)),t[8]=Math.max(0,IW.indexOf(e.toneMapping??"aces")),t[MH]=e.toneCurve??0,n[9]=e.exposure??1,t[10]=e.shadows===false?0:1;let s=e.gi;if(s&&(t[DH]=Math.max(0,BH.indexOf(s.mode??"field")),n[PH]=s.intensity??1,n[FH]=s.spacing??1,n[UH]=s.sunAngle??.53),Z5(e,t,n),this.check(this.abi.engine_render_set_environment(this.handle),"set environment"),e.volumetrics)for(let[a,l]of _K(yK(e.volumetrics))){let c=this.command(JV,0);this.commandWords[c]=a,l.forEach((u,d)=>{this.commandFloats[c+1+d]=u;});}}createRenderTarget(e){let t=this.clearDesc();t[0]=e.width,t[1]=e.height,t[2]=e.format==="rgba16f"?1:e.format==="rgba32f"?2:0,t[3]=e.depth===false?0:1,t[4]=e.samples??1,t[EH]=e.kind==="cube"?TH:e.kind==="2d-array"?wH:SH,t[xH]=e.layers??1,t[vH]=e.sampleDepth?1:0,t[gH]=e.colors??1;let n=this.check(this.abi.engine_render_create_target(this.handle),"create render target");this.targetTextures.set(n,this.registers[30]);let r=t[mO+RH-1];e.sampleDepth&&r!==0&&this.targetDepths.set(n,r),this.targetFormats.set(n,e.format??"rgba8");let o=[];for(let s=1;s<(e.colors??1);s++)o.push(t[mO+s-1]);return this.targetAttachments.set(n,o),n}renderTargetAttachment(e,t){if(t===0)return this.renderTargetTexture(e);let n=this.targetAttachments.get(e)?.[t-1];if(n===void 0||n===0)throw new _("invalid_argument",`render target ${e} has no colour attachment ${t}`);return n}renderTargetTexture(e){let t=this.targetTextures.get(e);if(t===void 0)throw new _("unknown_resource",`render target ${e} does not exist`);return t}renderTargetDepthTexture(e){let t=this.targetDepths.get(e);if(t===void 0)throw new _("unsupported_feature",`render target ${e} was not created with sampleDepth`);return t}resizeRenderTarget(e,t,n){let r=this.command(26,e);this.commandWords[r]=t,this.commandWords[r+1]=n;}destroyRenderTarget(e){this.command(27,e),this.targetTextures.delete(e),this.targetDepths.delete(e),this.targetFormats.delete(e),this.targetAttachments.delete(e);}createPostChain(e){if(e.effects.length>fO)throw new _("invalid_argument",`post chains hold ${fO} effects`);let t=e.effects.map(c=>c.kind==="shader"?iOe(c):null),n=e.effects.map((c,u)=>{let d=t[u];if(d)return d.values;let h=c;return eY[c.kind].map(p=>Number(h[p]??0))}),r=Math.min(e.effects.length,12),o=this.clearDesc(),s=this.descFloats;o[0]=r;for(let c=0;c<r;c++){let u=1+c*5;o[u+0]=tY[e.effects[c].kind],n[c].forEach((d,h)=>{s[u+1+h]=d;});}let a=t.some(c=>c!==null)?this.feature("engine_render_set_chain_shader"):null,l=this.check(this.abi.engine_render_create_chain(this.handle),"create post chain");for(let c=r;c<e.effects.length;c++){let u=this.command($V,l);this.commandWords[u]=c,this.commandWords[u+1]=tY[e.effects[c].kind],n[c].forEach((d,h)=>{this.commandFloats[u+2+h]=d;});}return r<e.effects.length&&this.flush(),t.forEach((c,u)=>{if(!c||!a)return;let d=this.stage(c.source);this.check(a(this.handle,l,u,d,c.source.byteLength),"set post shader");}),e.effects.forEach((c,u)=>{if(!(c.kind!=="shader"||c.textures===void 0)){if(c.textures.length>_O)throw new _("invalid_argument",`post shaders take ${_O} textures`);c.textures.forEach((d,h)=>{let p=this.command(jV,l);this.commandWords[p]=u,this.commandWords[p+1]=h,this.commandWords[p+2]=d;});}}),this.chains.set(l,{kinds:e.effects.map(c=>c.kind),params:e.effects.map((c,u)=>t[u]?.params??eY[c.kind])}),l}setPostScalar(e,t,n,r){let o=this.chains.get(e),s=o?.kinds[t];if(o===void 0||s===void 0)throw new _("unknown_resource",`post chain ${e} has no effect ${t}`);let a=o.params[t].indexOf(n);if(a<0)throw new _("invalid_argument",`${s} has no parameter ${n}`);let l=this.command(24,e);this.commandWords[l]=t,this.commandWords[l+1]=a,this.commandFloats[l+2]=r;}setPostChain(e){this.command(23,e??0);}setWeather(e){let t=AK(e),n=this.command(qV,t.snow?1:0),r=this.commandFloats;r[n]=t.cloudCover,r[n+1]=t.haze,r[n+2]=t.precipitation,r[n+3]=t.wetness,r[n+4]=t.windX,r[n+5]=t.windZ;}setTimeOfDay(e,t,n){let r=this.command(zV,0),o=this.commandFloats;o[r]=e,o[r+1]=t??Ht,o[r+2]=n??Ht;}destroyPostChain(e){this.command(25,e),this.chains.delete(e);}createRenderPass(e){this.flush();let t=this.clearDesc(),n=this.descFloats;return t[0]=e.camera,t[1]=e.target??0,t[2]=(e.layers??4294967295)>>>0,t[3]=e.clearColor??0,n[4]=e.clearAlpha??1,t[5]=(e.order??0)>>>0,t[IH]=e.slice??0,t[OH]=(e.cubeFace?NH:0)|(e.reflect?kH:0)|(e.once?LH:0),e.reflect?.forEach((r,o)=>{n[CH+o]=r;}),e.viewport&&(t[6]=1,e.viewport.forEach((r,o)=>{n[7+o]=r;})),this.check(this.abi.engine_render_create_pass(this.handle),"create render pass")}setRenderPassEnabled(e,t){this.commandWords[this.command(21,e)]=t?1:0;}destroyRenderPass(e){this.command(22,e);}async bytes(e,t){if("bytes"in e)return new Uint8Array(e.bytes);if("text"in e)return ed.encode(e.text);let n=await fetch(e.url);if(!n.ok)throw new _("asset_load_failed",`${t} ${e.url} failed with ${n.status}`);return new Uint8Array(await n.arrayBuffer())}installShaders(e){let t=this.stage(e);return this.check(this.abi.engine_render_install_shaders(this.handle,t,e.byteLength),"install shaders")}async loadModel(e){let t=await this.bytes(e,"model"),n=this.stage(t),r=this.check(this.abi.engine_render_load_model(this.handle,n,t.byteLength),"load model");return this.readModel(r,null)}async upgradeModel(e,t){let n=this.models.get(e);if(n===void 0)throw new _("unknown_resource",`model ${e} is not loaded`);let r=await this.bytes(t,"model"),o=this.reloadExport("engine_render_reload_model");if(o!==null){this.flush();let a=o(this.handle,e,this.stage(r),r.byteLength);if(a>=0)return {model:this.readModel(e,n),inPlace:true};if(a!==Vp)throw hg(a,"reload model")}let s=this.check(this.abi.engine_render_load_model(this.handle,this.stage(r),r.byteLength),"load model");return {model:this.readModel(s,null),inPlace:false}}readModel(e,t){let n=this.registers[12],r=n+this.registers[13],[o,s]=this.view(6,e,0),a=XIe.decode(new Uint8Array(this.buffer,o,s).slice()).split(String.fromCharCode(qIe)),l=a.slice(n,r);if(t!==null){let p={...t,nodeNames:a.slice(0,n),clipNames:l};return this.models.set(e,p),p}let c=this.owns(12),u=c?a.slice(r,a.length-1):[],d=c?this.modelMaterials(e,u.length):[],h={id:e,nodeNames:a.slice(0,n),clipNames:l,materialNames:u,materials:d};return this.models.set(e,h),h}refreshModel(e){let t=this.roots.get(e),n=t===void 0?void 0:this.models.get(t);if(t===void 0||n===void 0)throw new _("invalid_argument",`node ${e} is not a model instance`);return this.readModel(t,n)}async loadClips(e,t,n){let r=Gb(n),o=this.feature("engine_render_load_clips");if(!this.roots.has(e))throw new _("invalid_argument",`node ${e} is not a model instance`);let s=await this.bytes(t,"clips");this.flush();let a=this.stage(s),l=this.check(o(this.handle,e,a,s.byteLength,r),"load clips");return this.refreshModel(e).clipNames.slice(l)}setTint(e,t){let n=this.command(63,e);Q5(t,this.commandWords,n);}modelMaterials(e,t){let[n]=this.view(12,e,0);return Array.from(new Uint32Array(this.buffer,n,t),r=>r)}instantiateModel(e){if(!this.models.get(e))throw new _("unknown_resource",`model ${e} is not loaded`);let n=this.check(this.abi.engine_render_instantiate(this.handle,e),"instantiate model");return this.roots.set(n,e),n}findNode(e,t){let n=ed.encode(t),r=this.check(this.abi.engine_render_find_node(this.handle,e,this.stage(n),n.byteLength),"find node");return r===TIe?null:r}playClip(e,t,n,r,o){let s=this.clipIndex(e,t);if(s<0)throw new _("unknown_resource",`node ${e} has no clip ${t}`);return this.playClipIndex(e,s,n,r,o)}clipIndex(e,t){let n=this.roots.get(e);return n===void 0?-1:this.models.get(n)?.clipNames.indexOf(t)??-1}playClipIndex(e,t,n,r,o){return this.flush(),this.check(this.abi.engine_render_play_clip(this.handle,e,t,n?1:0,r,o),"play clip")}setClipWeight(e,t){this.commandFloats[this.command(28,e)]=t;}stopClip(e,t){this.commandFloats[this.command(29,e)]=t;}advanceAnimations(e){this.flush(),this.registerFloats[16]=e.values[Hn],this.check(this.abi.engine_render_animate(this.handle),"advance animations");}render(e){this.frameBudget!==null&&this.followRefresh(e.values),this.flush();let t=this.nativeSurface;t!==null&&t.before_render!==void 0&&t.before_render(),this.vectorSurfaces?.frame(e.values[Hn]),this.check(this.abi.engine_render_frame(this.handle),"render frame"),this.targetReads.length>0&&this.pollTargetReads();}followRefresh(e){let t=this.refresh,n=e[ki]-t[jK];if(t[jK]=e[ki],n>=EIe&&n<U1&&(n<t[dg]&&(t[dg]=n),this.observed++),this.observed<xIe||this.frameBudget===null)return;let r=Math.round(t[dg]*vIe);t[dg]=U1,this.observed=0,!(Math.abs(r-this.budgetMicros)*RIe<=this.budgetMicros)&&(this.budgetMicros=r,this.frameBudget(this.handle,r));}pushVideoFrame(e,t,n,r){let o=this.runtime.gpu;if(o===null||this.abi.engine_render_texture_object===void 0)return false;this.flush();let s=this.abi.engine_render_texture_object(this.handle,e);return s<=0?false:o.copyExternalImage(s,t,n,r)}readRenderTarget(e,t,n=0){let r=this.feature("engine_render_read_target");if(this.abi.engine_render_raw_poll===void 0)throw new _("unsupported_feature","this engine build cannot poll readbacks");this.flush();let[o,s,a,l]=t,c=this.check(r(this.handle,e,n,o,s,a,l),"read render target"),u=a*l*(this.targetFormats.get(e)==="rgba8"?4:8);return new Promise((d,h)=>{this.targetReads.push({request:c,bytes:u,resolve:d,reject:h});})}pollTargetReads(){let e=this.abi.engine_render_raw_poll;if(e===void 0)return;let t=[];for(let n of this.targetReads){let r=e(this.handle,n.request);if(r===0){t.push(n);continue}if(r<0){n.reject(hg(r,"read render target"));continue}n.resolve(new Uint8Array(this.buffer,r,n.bytes).slice());}this.targetReads=t;}stats(e){this.flush(),this.check(this.abi.engine_render_stats(this.handle),"stats");let t=this.registers;e.nodes=t[0],e.geometries=t[1],e.materials=t[2],e.textures=t[3],e.renderTargets=t[4],e.postChains=t[5],e.renderPasses=t[6],e.frames=t[7];}dispose(){this.disposed||(this.disposed=true,this.stopResize?.(),this.nativeSurface?.release(),this.nativeSurface=null,this.abi.engine_render_destroy(this.handle),this.scratch!==0&&this.runtime.exports.engine_free(this.scratch,this.scratchBytes,ce),this.matrixScratch&&this.runtime.exports.engine_free(this.matrixScratch.byteOffset,16*Rt,ce),this.textPointer!==0&&this.runtime.exports.engine_free(this.textPointer,this.textBytes,ce),this.pickPointer!==0&&this.runtime.exports.engine_free(this.pickPointer,18*Rt,ce),this.textPointer=0,this.pickPointer=0,this.scratch=0,this.matrixScratch=null);}};var xm={radius:.5,occludedGain:.35,occludedCutoff:900,smoothingSeconds:.08},nd=4,aY=0,lY=1,H1=2,ci=8,cY=16,vm=3,uY=-1,dY=.1,W1=-128,K1=127,rd=0,Y1=8,X1=255,q1=-1,hY=["oldest","quietest","refuse"],z1=".preview.m4a",id=8,pY=0,mY=3,fY=6,_Y=7,yY=4294967295,AY=1024;var bY={spatial:true,filters:true,meters:true,analyser:true,reverb:true,sends:true,loopPoints:true,streaming:true,detune:true,procedural:true},fg=["lowpass","highpass","bandpass","notch","allpass","peaking","lowshelf","highshelf"],Rm=-1,_g=["linear","inverse","exponential"],ui=8,yg=0,Ag=1,bg=2,gg=3,Eg=4,xg=5,vg=6,gY=7,As={distanceModel:"inverse",refDistance:1,maxDistance:1e4,rolloff:1,coneInnerAngle:360,coneOuterAngle:360,coneOuterGain:0,doppler:0},od=0,sd=1;var bs=0,EY=1,xY=2048,Q1=32,$1=32768,vY=.8,RY=-100,SY=-30,j1=0,J1=1,TY=2,oOe=1200;function wY(i,e){return e===0?i:i*2**(e/oOe)}var sOe=.42,aOe=.5,lOe=.08,cOe=20,Z1=255,uOe=128,IY=1e-12;function NY(i={}){let e=i.fftSize??xY;if(!Number.isInteger(e)||e<Q1||e>$1||(e&e-1)!==0)throw new _("invalid_argument",`fftSize must be a power of two from ${Q1} to ${$1}`);let t=i.smoothing??vY;if(!(t>=0&&t<=1))throw new _("invalid_argument","smoothing must be between 0 and 1");let n=i.minDecibels??RY,r=i.maxDecibels??SY;if(!(n<r))throw new _("invalid_argument","minDecibels must be below maxDecibels");return {fftSize:e,smoothing:t,minDecibels:n,maxDecibels:r}}var ad=class{constructor(e){this.head=0;let t=e.fftSize;this.fftSize=t,this.binCount=t/2,this.smoothing=e.smoothing,this.minDecibels=e.minDecibels,this.maxDecibels=e.maxDecibels,this.ring=new Float32Array(t),this.real=new Float64Array(t),this.imag=new Float64Array(t),this.window=new Float64Array(t),this.smoothed=new Float64Array(t/2),this.bitReverse=new Uint32Array(t),this.cos=new Float64Array(t/2),this.sin=new Float64Array(t/2);for(let r=0;r<t;r++){let o=2*Math.PI*r/t;this.window[r]=sOe-aOe*Math.cos(o)+lOe*Math.cos(2*o);}let n=Math.log2(t);for(let r=0;r<t;r++){let o=0;for(let s=0;s<n;s++)o|=(r>>>s&1)<<n-1-s;this.bitReverse[r]=o;}for(let r=0;r<t/2;r++)this.cos[r]=Math.cos(-2*Math.PI*r/t),this.sin[r]=Math.sin(-2*Math.PI*r/t);}push(e,t,n){let r=this.ring,o=this.fftSize,s=this.head;for(let a=0;a<n;a++)r[s]=e[t+a],s=s+1===o?0:s+1;this.head=s;}reset(){this.ring.fill(0),this.smoothed.fill(0),this.head=0;}timeDomain(e){let t=this.ring,n=Math.min(e.length,this.fftSize),r=this.head+this.fftSize-n,o=e instanceof Uint8Array;for(let s=0;s<n;s++){let a=t[(r+s)%this.fftSize];o?e[s]=CY(uOe*(1+a)):e[s]=a;}}frequency(e){this.transform();let t=Math.min(e.length,this.binCount),n=this.smoothed;if(e instanceof Uint8Array){let r=Z1/(this.maxDecibels-this.minDecibels);for(let o=0;o<t;o++)e[o]=CY((OY(n[o])-this.minDecibels)*r);}else for(let r=0;r<t;r++)e[r]=OY(n[r]);}transform(){let e=this.fftSize,t=this.real,n=this.imag,r=this.ring,o=this.head;for(let c=0;c<e;c++){let u=this.bitReverse[c];t[u]=r[(o+c)%e]*this.window[c],n[u]=0;}for(let c=2;c<=e;c<<=1){let u=c>>>1,d=e/c;for(let h=0;h<e;h+=c)for(let p=0;p<u;p++){let m=this.cos[p*d],f=this.sin[p*d],y=h+p,b=y+u,A=t[b]*m-n[b]*f,E=t[b]*f+n[b]*m;t[b]=t[y]-A,n[b]=n[y]-E,t[y]+=A,n[y]+=E;}}let s=this.smoothing,a=1/e,l=this.smoothed;for(let c=0;c<this.binCount;c++){let u=Math.sqrt(t[c]*t[c]+n[c]*n[c])*a;l[c]=s*l[c]+(1-s)*u;}}};function OY(i){return cOe*Math.log10(i>IY?i:IY)}function CY(i){return i<=0?0:i>=Z1?Z1:Math.floor(i)}var dOe=["engine_audio_music_tempo","engine_audio_music_play","engine_audio_music_layer","engine_audio_music_stinger","engine_audio_music_stop","engine_audio_music_position"],VY=4,hOe=8,HY=2*ci*VY,WY=HY+vm*hOe,kY=WY+nd*VY,pOe=48e3,rC=["engine_audio_bound","engine_audio_load_pcm","engine_audio_load_wav","engine_audio_release","engine_audio_create_bus","engine_audio_set_bus_gain","engine_audio_set_bus_filter","engine_audio_set_duck","engine_audio_play","engine_audio_stop","engine_audio_set_voice_gain","engine_audio_set_voice_rate","engine_audio_is_playing","engine_audio_set_listener","engine_audio_place","engine_audio_set_voice_spatial","engine_audio_registers","engine_audio_update","engine_audio_meter","engine_audio_suspend","engine_audio_resume","engine_audio_reset"];var LY=["engine_audio_lockstep","engine_audio_clock","engine_audio_create_emitters","engine_audio_feed_emitters","engine_audio_release_emitters"],KY=["engine_audio_relay_create","engine_audio_relay_pump","engine_audio_relay_receive"],mOe=["engine_audio_stream_open","engine_audio_stream_feed","engine_audio_stream_space","engine_audio_stream_play","engine_audio_stream_gain","engine_audio_stream_flush","engine_audio_stream_time","engine_audio_stream_close"],MY=["engine_audio_stream_open_opus","engine_audio_stream_seek","engine_audio_stream_loop","engine_audio_stream_duration","engine_audio_stream_time"],DY=2,eC=4096,PY=.02,fOe=8,tC=48e3,_Oe=1399285583;function yOe(i){return i.byteLength>=Nr&&new DataView(i.buffer,i.byteOffset).getUint32(0,true)===_Oe}var AOe=1,bOe=.03,gOe=1e3;function FY(i,e){return new Promise((t,n)=>{i(e,(r,o,s)=>{if(r===null||o<1||s<=0||r.length%o!==0){n(new _("asset_load_failed","the host could not decode the sound"));return}t({samples:r,channels:o,sampleRate:s});});})}var nC=0,Zn=-1,UY=-1,EOe=0,xOe=-1,BY=1,GY=2,Nr=4,vOe=1179011410,ROe=4,SOe=0,ld=class{constructor(e,t=64){this.name="cimplify-audio";this.pending=0;this.unlockedValue=false;this.busCount=0;this.sampleRate=pOe;this.analysers=[];this.analyserBus=[];this.capture=0;this.captureBytes=0;this.captureFloats=null;this.streams=new Map;this.refined=new Map;this.streamList=[];this.streamPointer=0;this.streamBytes=0;this.streamFloats=null;this.emitterColumns=0;this.musicStaging=0;this.occlusionWorld=null;if(this.host=e,this.handle=e.handle??e.exports.engine_audio_bound(),this.handle===nC)throw new _("unsupported_feature","the host has no native audio engine bound");this.maxVoices=t;let n=16*(t+1);this.stagingBytes=(n+2*t)*Nr,this.staging=e.allocate(this.stagingBytes);let r=e.memory.buffer;this.listener=new Float32Array(r,this.staging,16),this.column=new Float32Array(r,this.staging+16*Nr,16*t),this.voices=new Int32Array(r,this.staging+n*Nr,t),this.offsets=new Uint32Array(r,this.staging+(n+t)*Nr,t);for(let s=0;s<t;s++)this.offsets[s]=s*16;this.registers=new Float32Array(r,e.exports.engine_audio_registers(this.handle),ROe);let o=s=>typeof e.exports[s]=="function";this.caps={spatial:true,filters:true,meters:true,analyser:o("engine_audio_capture"),reverb:o("engine_audio_create_convolver"),sends:o("engine_audio_set_bus_send"),loopPoints:o("engine_audio_set_voice_loop"),streaming:mOe.every(o)&&(e.decode!==void 0&&e.decode!==null||MY.every(o)),detune:true,procedural:true,emitters:LY.every(o),lockstep:LY.every(o),voiceLimits:o("engine_audio_set_sound_limit")&&o("engine_audio_set_voice_budget"),voiceFilters:o("engine_audio_set_voice_filter"),limiter:o("engine_audio_set_limiter"),scheduling:o("engine_audio_now")&&o("engine_audio_play_at")&&o("engine_audio_stop_at"),music:dOe.every(o),binaural:o("engine_audio_set_voice_binaural"),occlusion:o("engine_audio_set_voice_occlusion")&&o("engine_audio_occlude")};}bindOcclusionWorld(e){this.occlusionWorld=e;}musicView(){this.musicStaging===0&&(this.musicStaging=this.host.allocate(kY));let e=this.host.memory.buffer,t=this.musicStaging;return {sounds:new Int32Array(e,t,ci),gains:new Float32Array(e,t+ci*Nr,ci),position:new Float64Array(e,t+HY,vm),occlusion:new Float32Array(e,t+WY,nd)}}nowFrame(){let e=this.host.exports.engine_audio_now;if(!e)throw Wn("sample-accurate scheduling");let t=this.musicView().position;if(e(this.handle,t.byteOffset)<0)throw new _("invalid_argument","the audio clock could not be read");return t[0]}playOn(e,t,n,r,o,s,a,l){let c=this.host.exports.engine_audio_play_at;if(!c)throw Wn("sample-accurate scheduling");let u=this.refined.get(e)??e;if(u===UY)return Zn;let d=(o?BY:0)|(s?GY:0)|(a&X1)<<Y1,h=c(this.handle,u,t,n,r,d,l);return h<0?Zn:h}stopOn(e,t,n){e!==Zn&&this.host.exports.engine_audio_stop_at?.(this.handle,e,t,n);}setVoiceBinaural(e,t){let n=this.host.exports.engine_audio_set_voice_binaural;if(!n)throw Wn("binaural rendering");if(e!==Zn&&n(this.handle,e,t?1:0)<0)throw new _("unsupported_feature","this engine build has no HRTF set")}setVoiceOcclusion(e,t){let n=this.host.exports.engine_audio_set_voice_occlusion;if(!n)throw Wn("occlusion");if(e===Zn)return;if(t===null){n(this.handle,e,0);return}let r=this.musicView().occlusion;r.set(t.subarray(0,nd)),n(this.handle,e,r.byteOffset);}musicTempo(e,t,n){return this.host.exports.engine_audio_music_tempo?.(this.handle,e,t,n)??-1}musicPlay(e,t,n,r,o,s){let a=this.host.exports.engine_audio_music_play;if(!a)return -1;let l=this.musicView();for(let u=0;u<e.length;u++)l.sounds[u]=this.refined.get(e[u])??e[u];l.gains.set(t);let c=n|o<<cY;return a(this.handle,l.sounds.byteOffset,l.gains.byteOffset,e.length,c,r,s)}musicLayer(e,t,n){this.host.exports.engine_audio_music_layer?.(this.handle,e,t,n);}musicStinger(e,t,n,r){let o=this.refined.get(e)??e;return this.host.exports.engine_audio_music_stinger?.(this.handle,o,t,n,r)??-1}musicStop(e,t){return this.host.exports.engine_audio_music_stop?.(this.handle,e,t)??-1}musicPosition(e){let t=this.host.exports.engine_audio_music_position;if(!t)return false;let n=this.musicView().position;return t(this.handle,n.byteOffset)<0?false:(e.set(n),true)}setVoiceFilter(e,t,n,r,o){let s=this.host.exports.engine_audio_set_voice_filter;if(!s)throw Wn("voice filters");if(e!==Zn&&s(this.handle,e,t,n,r,o)<0)throw new _("invalid_argument",`voice ${e} filter was rejected`)}setLimiter(e,t,n){let r=this.host.exports.engine_audio_set_limiter;if(!r)throw Wn("a master limiter");if(r(this.handle,e?1:0,t,n)<0)throw new _("invalid_argument","the master limiter settings were rejected")}setSoundLimit(e,t,n){let r=this.host.exports.engine_audio_set_sound_limit;if(!r)throw Wn("sound voice limits");if(r(this.handle,e,t,n)<0)throw new _("invalid_argument",`sound ${e} cannot take that voice limit`)}setVoiceBudget(e){let t=this.host.exports.engine_audio_set_voice_budget;if(!t)throw Wn("a voice budget");if(t(this.handle,e)<0)throw new _("invalid_argument",`the mixer cannot take a budget of ${e} voices`)}lockstep(e,t){this.host.exports.engine_audio_lockstep?.(this.handle,e>>>0,t);}flush(){this.host.relay?.pump();}createEmitters(e,t,n,r){let o=this.host.exports.engine_audio_create_emitters;if(!o)throw Wn("emitter tables");let s=0;if(r!==null){for(let a=0;a<ui;a++)this.listener[a]=r[a];s=this.listener.byteOffset;}return o(this.handle,e,t,n,s)}feedEmitters(e,t,n){let r=this.host.exports.engine_audio_feed_emitters;return r?(this.emitterColumns===0&&(this.emitterColumns=this.host.allocate(id*Nr)),new Uint32Array(this.host.memory.buffer,this.emitterColumns,id).set(n),r(this.handle,e,t,this.emitterColumns)):0}releaseEmitters(e){this.host.exports.engine_audio_release_emitters?.(this.handle,e);}meter(e,t){let n=this.listener.byteOffset;this.host.exports.engine_audio_meter(this.handle,e,n),t[od]=this.listener[0],t[sd]=this.listener[1];}get capabilities(){return this.caps}createSound(e,t,n){if(t<1||n<=0||e.length%t!==0)throw new _("invalid_argument","sound PCM must be interleaved whole frames");let r=this.host.allocate(e.byteLength);try{return new Float32Array(this.host.memory.buffer,r,e.length).set(e),this.check(this.host.exports.engine_audio_load_pcm(this.handle,r,e.length/t,t,n),"load sound")}finally{this.host.release(r,e.byteLength);}}setVoiceGain(e,t,n){e!==Zn&&this.host.exports.engine_audio_set_voice_gain(this.handle,e,t,n);}setVoiceRate(e,t,n){e!==Zn&&this.host.exports.engine_audio_set_voice_rate(this.handle,e,wY(t,n));}setVoiceSpatial(e,t){if(e!==Zn){for(let n=0;n<ui;n++)this.listener[n]=t[n];this.host.exports.engine_audio_set_voice_spatial(this.handle,e,this.listener.byteOffset);}}setVoiceLoop(e,t,n,r){let o=this.host.exports.engine_audio_set_voice_loop;if(!o)throw Wn("loop points");e!==Zn&&o(this.handle,e,t?1:0,n,r);}setBusFilter(e,t,n,r,o){if(this.host.exports.engine_audio_set_bus_filter(this.handle,e,t,n,r,o)<0)throw new _("invalid_argument",`bus ${e} filter was rejected`)}createAnalyser(e,t){if(!this.host.exports.engine_audio_capture)throw Wn("the analyser");let n=t.fftSize*Nr;return n>this.captureBytes&&(this.capture!==0&&this.host.release(this.capture,this.captureBytes),this.capture=this.host.allocate(n),this.captureBytes=n),this.analysers.push(new ad(t)),this.analyserBus.push(e),this.analysers.length-1}readAnalyser(e,t,n){let r=this.host.exports.engine_audio_capture,o=this.analysers[e];if(!r||!o)throw new _("unknown_resource",`analyser ${e} does not exist`);let s=r(this.handle,this.analyserBus[e],this.capture,o.fftSize);s>0&&o.push(this.captureView(),0,Math.min(s,o.fftSize)),t===bs?o.frequency(n):o.timeDomain(n);}captureView(){let e=this.host.memory.buffer,t=this.captureFloats;return (t===null||t.buffer!==e||t.byteOffset!==this.capture)&&(t=new Float32Array(e,this.capture,this.captureBytes/Nr),this.captureFloats=t),t}createReverb(e,t){let n=this.host.exports.engine_audio_create_convolver;if(!n)throw Wn("convolution reverb");let r=n(this.handle,e,t);if(r<0)throw new _("capacity_exceeded","the audio mixer has no free reverb bus");return this.busCount++,r}setBusSend(e,t,n){let r=this.host.exports.engine_audio_set_bus_send;if(!r)throw Wn("bus sends");if(r(this.handle,e,t,n,0)<0)throw new _("invalid_argument",`bus ${e} cannot send to ${t}`)}async openStream(e,t){let n=this.host.exports,r=n.engine_audio_stream_open;if(!this.caps.streaming||!r)throw Wn("streaming music");let o=await this.bytes(e);if(yOe(o)&&MY.every(c=>typeof n[c]=="function"))return this.openCompressed(o,t);if(!this.host.decode)throw Wn("streaming music");let s=await FY(this.host.decode,o),a=r(this.handle,t,s.channels,s.sampleRate,Math.ceil(s.sampleRate*DY));if(a<0)throw new _("capacity_exceeded","the audio mixer has no free stream");let l={id:a,pcm:s,frames:s.samples.length/s.channels,sampleRate:s.sampleRate,cursor:0,loop:false,playing:false,fed:0,baseSeconds:0,baseFed:0};return this.streams.set(a,l),this.streamList.push(l),this.streamStaging(eC*s.channels),this.feedStream(this.stream(a)),a}openCompressed(e,t){let n=this.host.exports,r=n.engine_audio_stream_open_opus,o=n.engine_audio_stream_duration;if(!r||!o)throw Wn("compressed streaming");let s=this.host.allocate(e.byteLength),a;try{new Uint8Array(this.host.memory.buffer,s,e.byteLength).set(e),a=r(this.handle,t,s,e.byteLength,Math.ceil(tC*DY));}finally{this.host.release(s,e.byteLength);}if(a<0)throw new _("asset_load_failed",`the stream could not open (${a})`);this.streamStaging(eC),o(this.handle,a,this.streamPointer);let l=new DataView(this.host.memory.buffer).getFloat64(this.streamPointer,true),c={id:a,pcm:null,frames:Math.round(l*tC),sampleRate:tC,cursor:0,loop:false,playing:false,fed:0,baseSeconds:0,baseFed:0};return this.streams.set(a,c),this.streamList.push(c),a}stream(e){let t=this.streams.get(e);if(!t)throw new _("unknown_resource",`stream ${e} is not open`);return t}streamStaging(e){let t=Math.max(e*Nr,fOe);t<=this.streamBytes||(this.streamPointer!==0&&this.host.release(this.streamPointer,this.streamBytes),this.streamPointer=this.host.allocate(t),this.streamBytes=t);}streamView(){let e=this.host.memory.buffer,t=this.streamFloats;return (t===null||t.buffer!==e||t.byteOffset!==this.streamPointer||t.byteLength!==this.streamBytes)&&(t=new Float32Array(e,this.streamPointer,this.streamBytes/Nr),this.streamFloats=t),t}feedStream(e){let t=this.host.exports,n=t.engine_audio_stream_feed,r=t.engine_audio_stream_space,o=e.pcm;if(!n||!r||o===null)return;let s=o.channels,a=r(this.handle,e.id);for(;a>0;){if(e.cursor>=e.frames){if(!e.loop)return;e.cursor=0;}let l=Math.min(a,eC,e.frames-e.cursor),c=this.streamView(),u=o.samples,d=e.cursor*s;for(let p=0;p<l*s;p++)c[p]=u[d+p];let h=n(this.handle,e.id,this.streamPointer,l,s);if(h<=0)return;e.cursor+=h,e.fed+=h,a-=h;}}playStream(e,t,n){let r=this.stream(e);r.loop=n,r.playing=true,r.pcm===null&&this.host.exports.engine_audio_stream_loop?.(this.handle,e,n?1:0),this.feedStream(r),this.host.exports.engine_audio_stream_gain?.(this.handle,e,t,0),this.host.exports.engine_audio_stream_play?.(this.handle,e,1,PY);}pauseStream(e){this.stream(e).playing=false,this.host.exports.engine_audio_stream_play?.(this.handle,e,0,PY);}seekStream(e,t){let n=this.stream(e),r=Math.min(Math.max(t,0),n.frames/n.sampleRate);if(n.pcm===null){this.host.exports.engine_audio_stream_seek?.(this.handle,e,r);return}this.host.exports.engine_audio_stream_flush?.(this.handle,e),n.cursor=Math.floor(r*n.sampleRate),n.baseSeconds=r,n.baseFed=n.fed,this.feedStream(n);}streamTime(e){let t=this.stream(e),n=this.host.exports.engine_audio_stream_time;if(!n)return t.baseSeconds;n(this.handle,e,this.streamPointer);let r=new DataView(this.host.memory.buffer).getFloat64(this.streamPointer,true),o=t.frames/t.sampleRate;if(t.pcm===null)return Math.min(r,o);let s=t.baseSeconds+Math.max(0,r-t.baseFed/t.sampleRate);return t.loop&&o>0?s%o:Math.min(s,o)}streamDuration(e){let t=this.stream(e);return t.frames/t.sampleRate}closeStream(e){let t=this.stream(e);this.host.exports.engine_audio_stream_close?.(this.handle,e),this.streams.delete(e),this.streamList.splice(this.streamList.indexOf(t),1);}get unlocked(){return this.unlockedValue}unlock(){this.unlockedValue=true;}async decode(e){let t=this.host.assets;if("url"in e&&t?.has?.(e.url+z1)===true){let n=await this.decodeBytes(await t.take(e.url+z1));return this.refine(n,t,e.url),n}return this.decodeBytes(await this.bytes(e))}async refine(e,t,n){let r;try{r=await this.decodeBytes(await t.take(n,AOe,!1));}catch{return}this.refined.set(e,r);let o=this.host.exports.engine_audio_replace;o===void 0||o(this.handle,e,r,bOe)<0||setTimeout(()=>this.host.exports.engine_audio_release(this.handle,e),gOe);}async decodeBytes(e){if(e.byteLength>=Nr&&new DataView(e.buffer,e.byteOffset).getUint32(0,true)===vOe)return this.loadWave(e);if(!this.host.decode)throw new _("asset_load_failed","compressed audio needs the host decoder");let n=await FY(this.host.decode,e),r=n.samples.length/n.channels,o=this.host.allocate(n.samples.byteLength);try{return new Float32Array(this.host.memory.buffer,o,n.samples.length).set(n.samples),this.check(this.host.exports.engine_audio_load_pcm(this.handle,o,r,n.channels,n.sampleRate),"load sound")}finally{this.host.release(o,n.samples.byteLength);}}loadWave(e){let t=this.host.allocate(e.byteLength);try{return new Uint8Array(this.host.memory.buffer,t,e.byteLength).set(e),this.check(this.host.exports.engine_audio_load_wav(this.handle,t,e.byteLength),"load sound")}finally{this.host.release(t,e.byteLength);}}async bytes(e){if("bytes"in e)return new Uint8Array(e.bytes);if(!("url"in e))throw new _("asset_load_failed","sounds load from bytes or a url");if(this.host.assets)return this.host.assets.take(e.url);let t=await fetch(e.url);if(!t.ok)throw new _("asset_load_failed",`sound ${e.url} failed with ${t.status}`);return new Uint8Array(await t.arrayBuffer())}check(e,t){if(e<0)throw new _("asset_load_failed",`${t} failed with ${e}`);return e}createBus(e,t){if(t===xOe)return this.busCount=Math.max(this.busCount,1),EOe;let n=this.host.exports.engine_audio_create_bus(this.handle,t);if(n<0)throw new _("capacity_exceeded","the audio mixer has no free bus");return this.busCount++,n}setBusGain(e,t,n){this.host.exports.engine_audio_set_bus_gain(this.handle,e,t,n);}play(e,t,n,r,o,s,a=rd){let l=this.refined.get(e)??e;if(l===UY)return Zn;let c=(o?BY:0)|(s?GY:0)|(a&X1)<<Y1,u=this.host.exports.engine_audio_play(this.handle,l,t,n,r,c);return u<0?Zn:u}stop(e,t){e!==Zn&&this.host.exports.engine_audio_stop(this.handle,e,t);}isPlaying(e){return e!==Zn&&this.host.exports.engine_audio_is_playing(this.handle,e)===1}setVoicePosition(e,t,n){if(e===Zn||this.pending===this.maxVoices)return;let r=this.pending++;this.voices[r]=e;for(let o=0;o<16;o++)this.column[r*16+o]=t[n+o];}setListener(e,t){for(let n=0;n<16;n++)this.listener[n]=e[t+n];this.host.exports.engine_audio_set_listener(this.handle,this.listener.byteOffset);}commit(e,t){let n=this.host.exports;this.pending>0&&(n.engine_audio_place(this.handle,this.voices.byteOffset,this.offsets.byteOffset,this.pending,this.column.byteOffset,this.pending*16),this.pending=0),this.registers[SOe]=e[t];let r=this.occlusionWorld?.()??nC;r!==nC&&n.engine_audio_occlude?.(this.handle,r),n.engine_audio_update(this.handle);let o=this.streamList;for(let s=0;s<o.length;s++)o[s].playing&&this.feedStream(o[s]);}suspend(){this.host.exports.engine_audio_suspend(this.handle),this.host.relay?.pump(),this.host.relay?.suspend?.();}resume(){this.host.exports.engine_audio_resume(this.handle),this.host.relay?.resume?.(),this.host.relay?.pump();}dispose(){this.host.exports.engine_audio_reset(this.handle),this.host.release(this.staging,this.stagingBytes),this.capture!==0&&this.host.release(this.capture,this.captureBytes),this.streamPointer!==0&&this.host.release(this.streamPointer,this.streamBytes),this.emitterColumns!==0&&this.host.release(this.emitterColumns,id*Nr),this.musicStaging!==0&&this.host.release(this.musicStaging,kY),this.musicStaging=0,this.emitterColumns=0,this.capture=0,this.captureBytes=0,this.streamPointer=0,this.streamBytes=0,this.streams.clear(),this.streamList.length=0;}};function Wn(i){return new _("unsupported_feature",`this engine build has no ${i}; update the app to use it`)}var iC="cimplify-audio";var YY=`
32
+ const RING_HEADER_WORDS = 2;
33
+ const RING_WRITE = 0;
34
+ const RING_READ = 1;
35
+
36
+ class CimplifyAudioProcessor extends AudioWorkletProcessor {
37
+ constructor(options) {
38
+ super();
39
+ const o = options.processorOptions;
40
+ const instance = new WebAssembly.Instance(o.module, {});
41
+ this.x = instance.exports;
42
+ const sizes = new Uint32Array(this.x.memory.buffer, this.x.worklet_sizes(), o.sizes.length);
43
+ for (let k = 0; k < o.sizes.length; k++) sizes[k] = o.sizes[k];
44
+ this.host = this.x.worklet_create(sampleRate, o.voices, o.inputWords);
45
+ this.capacity = this.x.worklet_input_words(this.host);
46
+ this.pending = 0;
47
+ this.queue = [];
48
+ this.queued = 0;
49
+ this.reportQuanta = o.reportQuanta;
50
+ this.quanta = 0;
51
+ this.buffer = null;
52
+ this.inbound = o.inbound === null ? null : new Int32Array(o.inbound);
53
+ this.outbound = o.outbound === null ? null : new Int32Array(o.outbound);
54
+ if (this.inbound === null) {
55
+ this.port.onmessage = (event) => {
56
+ this.queue.push(event.data);
57
+ };
58
+ }
59
+ }
60
+
61
+ views() {
62
+ const buffer = this.x.memory.buffer;
63
+ if (this.buffer === buffer) return;
64
+ this.buffer = buffer;
65
+ this.input = new Uint32Array(buffer, this.x.worklet_input(this.host), this.capacity);
66
+ this.left = new Float32Array(buffer, this.x.worklet_output(this.host, 0), 4096);
67
+ this.right = new Float32Array(buffer, this.x.worklet_output(this.host, 1), 4096);
68
+ }
69
+
70
+ fromRing() {
71
+ const ring = this.inbound;
72
+ const capacity = ring.length - RING_HEADER_WORDS;
73
+ const write = Atomics.load(ring, RING_WRITE);
74
+ let read = Atomics.load(ring, RING_READ);
75
+ let available = (write - read) | 0;
76
+ const room = this.capacity - this.pending;
77
+ if (available > room) available = room;
78
+ for (let k = 0; k < available; k++) {
79
+ this.input[this.pending + k] = ring[RING_HEADER_WORDS + ((read + k) & (capacity - 1))];
80
+ }
81
+ this.pending += available;
82
+ Atomics.store(ring, RING_READ, (read + available) | 0);
83
+ }
84
+
85
+ fromQueue() {
86
+ while (this.queue.length > 0 && this.pending < this.capacity) {
87
+ const head = this.queue[0];
88
+ const take = Math.min(head.length - this.queued, this.capacity - this.pending);
89
+ this.input.set(head.subarray(this.queued, this.queued + take), this.pending);
90
+ this.pending += take;
91
+ this.queued += take;
92
+ if (this.queued === head.length) {
93
+ this.queue.shift();
94
+ this.queued = 0;
95
+ }
96
+ }
97
+ }
98
+
99
+ ingest() {
100
+ this.views();
101
+ if (this.inbound !== null) this.fromRing();
102
+ else this.fromQueue();
103
+ if (this.pending === 0) return;
104
+ const used = this.x.worklet_ingest(this.host, this.pending);
105
+ if (used > 0) {
106
+ this.input.copyWithin(0, used, this.pending);
107
+ this.pending -= used;
108
+ }
109
+ }
110
+
111
+ report() {
112
+ const words = this.x.worklet_report(this.host);
113
+ this.views();
114
+ const report = new Uint32Array(this.x.memory.buffer, this.x.worklet_report_buffer(this.host), words);
115
+ if (this.outbound === null) {
116
+ this.port.postMessage(report.slice());
117
+ return;
118
+ }
119
+ const ring = this.outbound;
120
+ const capacity = ring.length - RING_HEADER_WORDS;
121
+ const write = Atomics.load(ring, RING_WRITE);
122
+ const read = Atomics.load(ring, RING_READ);
123
+ if (capacity - ((write - read) | 0) < words) return;
124
+ for (let k = 0; k < words; k++) ring[RING_HEADER_WORDS + ((write + k) & (capacity - 1))] = report[k];
125
+ Atomics.store(ring, RING_WRITE, (write + words) | 0);
126
+ }
127
+
128
+ process(inputs, outputs) {
129
+ this.ingest();
130
+ const out = outputs[0];
131
+ const frames = out[0].length;
132
+ this.x.worklet_render(this.host, frames);
133
+ this.views();
134
+ out[0].set(this.left.subarray(0, frames));
135
+ if (out.length > 1) out[1].set(this.right.subarray(0, frames));
136
+ this.ingest();
137
+ this.quanta += 1;
138
+ if (this.quanta >= this.reportQuanta) {
139
+ this.quanta = 0;
140
+ this.report();
141
+ }
142
+ return true;
143
+ }
144
+ }
145
+
146
+ registerProcessor("${iC}", CimplifyAudioProcessor);
147
+ `;var wOe=48e3,IOe=65536,OOe=1<<20,COe=120,Tm=4,NOe=2,kOe=0,LOe=2,MOe=0,DOe="running",POe={arenaFloats:1<<23,streamFrames:65536,reverbs:2,reverbPartitions:1024,banks:4,emitters:2048};function FOe(i){return [i.arenaFloats,i.streamFrames,i.reverbs,i.reverbPartitions,i.banks,i.emitters]}function XY(i){return new SharedArrayBuffer((2+i)*Tm)}function UOe(i){return URL.createObjectURL(new Blob([i],{type:"application/javascript"}))}function BOe(i,e,t){let n=globalThis.AudioWorkletNode;return new n(i,e,{numberOfInputs:0,numberOfOutputs:1,outputChannelCount:[NOe],processorOptions:t})}function GOe(){return typeof SharedArrayBuffer=="function"&&globalThis.crossOriginIsolated===true}var Rg=class i{constructor(e,t,n,r,o,s,a){this.backlog=[];this.reports=[];this.node=null;this.failed=null;this.meterView=null;this.quiet=0;this.idled=false;this.hidden=false;this.engine=e,this.handle=t,this.shared=n,this.stagingWords=r,this.staging=e.allocate(r*Tm),this.inbound=n?new Int32Array(XY(o)):null,this.outbound=n?new Int32Array(XY(o)):null,this.context=s,this.idlePumps=a;}static create(e,t){let n=e.exports.engine_audio_relay_create;if(!n)throw new _("unsupported_feature","this engine build has no web audio relay");let r=t.sizes??POe,o=FOe(r),s=e.allocate(6*Tm);new Uint32Array(e.memory.buffer,s,6).set(o);let a=t.voices??64,l=n(wOe,a,s);if(e.release(s,6*Tm),l===0)throw new _("invalid_argument","the engine refused the web audio relay sizes");let c=t.shared??GOe(),u=t.pumpWords??IOe,d=t.ringWords??OOe;if(d&d-1||d<u)throw new _("invalid_argument","the ring holds a power of two words, at least one pump");let h=t.idlePumps??COe,p=new i(e,l,c,u,d,t.context,h),m=(t.moduleUrl??UOe)(YY);return Promise.all([t.context.audioWorklet.addModule(m),t.module]).then(([,f])=>{let y={module:f,voices:a,sizes:o,inputWords:u*2,reportQuanta:t.reportQuanta??8,inbound:p.inbound===null?null:p.inbound.buffer,outbound:p.outbound===null?null:p.outbound.buffer};p.attach((t.createNode??BOe)(t.context,iC,y),t.context);}).catch(f=>{p.failed=f;}),p}get idle(){return this.idled}suspend(){this.hidden=true,this.context.suspend?.();}resume(){this.hidden=false,this.idled=false,this.quiet=0,this.context.resume?.();}silent(){let e=this.engine.memory.buffer,t=this.meterView;return (t===null||t.buffer!==e)&&(t=new Float32Array(e,this.staging,LOe),this.meterView=t),this.engine.exports.engine_audio_meter(this.handle,kOe,this.staging),t[MOe]===0}settle(e){if(e>0||!this.silent()){this.quiet=0,this.idled&&!this.hidden&&(this.idled=false,this.context.resume?.());return}this.idled||this.hidden||this.node===null||this.context.state!==DOe||(this.quiet+=1,!(this.quiet<this.idlePumps)&&(this.idled=true,this.context.suspend?.()));}get ready(){return this.node!==null}get error(){return this.failed}attach(e,t){this.node=e,this.shared||(e.port.onmessage=n=>{this.reports.push(n.data);}),e.connect(lm(t)),this.drainBacklog();}send(e){let t=this.node;if(t===null)return false;let n=this.inbound;if(n===null)return t.port.postMessage(e,[e.buffer]),true;let r=n.length-2,o=Atomics.load(n,0),s=Atomics.load(n,1);if(r-(o-s|0)<e.length)return false;for(let a=0;a<e.length;a++)n[2+(o+a&r-1)]=e[a];return Atomics.store(n,0,o+e.length|0),true}drainBacklog(){for(;this.backlog.length>0&&this.send(this.backlog[0]);)this.backlog.shift();}receive(e){let t=this.engine.exports.engine_audio_relay_receive;if(!t||e.length===0)return;let n=e.length*Tm,r=e.length<=this.stagingWords?this.staging:this.engine.allocate(n);new Uint32Array(this.engine.memory.buffer,r,e.length).set(e),t(this.handle,r,e.length),r!==this.staging&&this.engine.release(r,n);}collect(){if(this.outbound===null){for(let a of this.reports)this.receive(a);this.reports.length=0;return}let e=this.outbound,t=e.length-2,n=Atomics.load(e,0),r=Atomics.load(e,1),o=n-r|0;if(o<=0)return;let s=new Uint32Array(o);for(let a=0;a<o;a++)s[a]=e[2+(r+a&t-1)];Atomics.store(e,1,r+o|0),this.receive(s);}pump(){let t=this.engine.exports.engine_audio_relay_pump;if(!t)return;this.collect(),this.drainBacklog();let n=this.backlog.length;for(;;){let r=t(this.handle,this.staging,this.stagingWords);if(r<=0)break;n+=r;let o=new Uint32Array(this.engine.memory.buffer,this.staging,r).slice();(this.backlog.length>0||!this.send(o))&&this.backlog.push(o);}this.settle(n);}};var wm=-1,VOe=-1,lC=12,Sg=4,sc=3,ac=2,HOe=48e3,WOe=180,qY=1024,Tg=class{constructor(e=64){this.name="headless";this.capabilities=bY;this.sampleRate=HOe;this.unlockedValue=false;this.soundCount=0;this.busCount=0;this.busGains=[];this.busFilters=[];this.busMeters=[];this.sends=new Map;this.reverbs=new Map;this.analysers=[];this.analyserBus=[];this.streams=[];this.listener=new Float32Array(16);this.nextVoice=0;this.voiceSound=new Int32Array(e).fill(wm),this.voiceLoop=new Uint8Array(e),this.voicePosition=new Float32Array(e*3),this.voiceGain=new Float32Array(e),this.voiceRate=new Float32Array(e*ac),this.voiceLoopPoints=new Float32Array(e*sc),this.voiceSpatial=new Float32Array(e*ui);}get unlocked(){return this.unlockedValue}unlock(){this.unlockedValue=true;}decode(e){return Promise.resolve(this.soundCount++)}createSound(e,t,n){if(t<1||n<=0||e.length%t!==0)throw new _("invalid_argument","sound PCM must be interleaved whole frames");return this.soundCount++}createBus(e,t){this.busGains.push(1);for(let n=0;n<Sg;n++)this.busFilters.push(n===0?Rm:0);return this.busMeters.push(0,0),this.busCount++}setBusGain(e,t,n){this.busGains[e]=t;}busGain(e){return this.busGains[e]}setBusFilter(e,t,n,r,o){let s=e*Sg;this.busFilters[s]=t,this.busFilters[s+1]=n,this.busFilters[s+2]=r,this.busFilters[s+3]=o;}busFilter(e,t){for(let n=0;n<Sg;n++)t[n]=this.busFilters[e*Sg+n];}meter(e,t){t[od]=this.busMeters[e*2]??0,t[sd]=this.busMeters[e*2+1]??0;}inject(e,t){let n=0,r=0;for(let o=0;o<t.length;o++){let s=t[o],a=s<0?-s:s;a>n&&(n=a),r+=s*s;}this.busMeters[e*2]=n,this.busMeters[e*2+1]=t.length>0?Math.sqrt(r/t.length):0;for(let o=0;o<this.analysers.length;o++)this.analyserBus[o]===e&&this.analysers[o].push(t,0,t.length);}createAnalyser(e,t){return this.analysers.push(new ad(t)),this.analyserBus.push(e),this.analysers.length-1}readAnalyser(e,t,n){let r=this.analysers[e];if(!r)throw new _("unknown_resource",`analyser ${e} does not exist`);t===bs?r.frequency(n):r.timeDomain(n);}createReverb(e,t){let n=this.createBus("reverb",e);return this.reverbs.set(n,t),n}reverbImpulse(e){return this.reverbs.get(e)??wm}setBusSend(e,t,n){this.sends.set(e*qY+t,n);}busSend(e,t){return this.sends.get(e*qY+t)??0}play(e,t,n,r,o,s){let a=this.nextVoice;return this.nextVoice=(this.nextVoice+1)%this.voiceSound.length,this.voiceSound[a]=e,this.voiceLoop[a]=o?1:0,this.voiceGain[a]=n,this.voiceRate[a*ac]=r,this.voiceRate[a*ac+1]=0,this.voiceLoopPoints[a*sc]=o?1:0,this.voiceLoopPoints[a*sc+1]=0,this.voiceLoopPoints[a*sc+2]=0,a}stop(e,t){this.voiceSound[e]=wm;}isPlaying(e){return this.voiceSound[e]!==wm}setVoiceGain(e,t,n){this.voiceGain[e]=t;}voiceGainOf(e){return this.voiceGain[e]}setVoiceRate(e,t,n){this.voiceRate[e*ac]=t,this.voiceRate[e*ac+1]=n;}voiceRateOf(e,t){t[0]=this.voiceRate[e*ac],t[1]=this.voiceRate[e*ac+1];}setVoiceSpatial(e,t){this.voiceSpatial.set(t.subarray(0,ui),e*ui);}voiceSpatialOf(e,t){for(let n=0;n<ui;n++)t[n]=this.voiceSpatial[e*ui+n];}setVoiceLoop(e,t,n,r){let o=e*sc;this.voiceLoop[e]=t?1:0,this.voiceLoopPoints[o]=t?1:0,this.voiceLoopPoints[o+1]=n,this.voiceLoopPoints[o+2]=r;}voiceLoopOf(e,t){for(let n=0;n<sc;n++)t[n]=this.voiceLoopPoints[e*sc+n];}setVoicePosition(e,t,n){let r=e*3;this.voicePosition[r]=t[n+lC],this.voicePosition[r+1]=t[n+lC+1],this.voicePosition[r+2]=t[n+lC+2];}voiceX(e){return this.voicePosition[e*3]}setListener(e,t){for(let n=0;n<16;n++)this.listener[n]=e[t+n];}async openStream(e,t){return this.streams.push({bus:t,state:j1,loop:false,gain:1,time:0,duration:WOe}),this.streams.length-1}stream(e){let t=this.streams[e];if(!t)throw new _("unknown_resource",`stream ${e} is not open`);return t}playStream(e,t,n){let r=this.stream(e);r.state=J1,r.gain=t,r.loop=n;}pauseStream(e){this.stream(e).state=TY;}seekStream(e,t){let n=this.stream(e);n.time=Math.max(0,Math.min(n.duration,t));}streamTime(e){return this.stream(e).time}streamDuration(e){return this.stream(e).duration}streamState(e){return this.stream(e).state}closeStream(e){this.streams[e]=null;}commit(e,t){let n=e[t];for(let r=0;r<this.streams.length;r++){let o=this.streams[r];o===null||o.state!==J1||(o.time+=n,o.time>=o.duration&&(o.loop?o.time-=o.duration:(o.time=o.duration,o.state=j1)));}}suspend(){}resume(){}dispose(){this.voiceSound.fill(wm),this.streams.length=0,this.analyserBus.fill(VOe);}};var zY=-1,cC=12,KOe=1,YOe=100,QY=3,$Y=1024,XOe=1024,wg=class{constructor(e,t=64,n={}){this.name="web-audio";this.buffers=[];this.buses=[];this.analysers=[];this.sends=new Map;this.streams=[];this.meterScratch=new Float32Array($Y);this.nextVoice=0;this.context=e,this.voices=Array.from({length:t},()=>({source:null,gain:null,panner:null})),this.onEnded=Array.from({length:t},(o,s)=>()=>this.release(s)),this.createMediaElement=n.createMediaElement??(typeof document>"u"?null:()=>document.createElement("audio"));let r=this.createMediaElement!==null&&typeof e.createMediaElementSource=="function";this.capabilities={spatial:true,filters:true,meters:true,analyser:true,reverb:true,sends:true,loopPoints:true,streaming:r,detune:true,procedural:true};}get sampleRate(){return this.context.sampleRate}get unlocked(){return this.context.state==="running"}unlock(){this.context.state!=="running"&&this.context.resume();}async decode(e){let t;if("bytes"in e)t=e.bytes.slice(0);else if("url"in e)t=await(await fetch(e.url)).arrayBuffer();else throw new _("invalid_argument","audio sources are bytes or a url");return this.buffers.push(await this.context.decodeAudioData(t)),this.buffers.length-1}createSound(e,t,n){if(t<1||n<=0||e.length%t!==0)throw new _("invalid_argument","sound PCM must be interleaved whole frames");let r=e.length/t,o=this.context.createBuffer(t,r,n);for(let s=0;s<t;s++){let a=o.getChannelData(s);for(let l=0;l<r;l++)a[l]=e[l*t+s];}return this.buffers.push(o),this.buffers.length-1}createBus(e,t){let n=this.context.createGain(),r=t===zY?lm(this.context):this.buses[t].input;return n.connect(r),this.buses.push({input:n,parent:r,tail:n,body:n,filter:null,meter:null}),this.buses.length-1}createReverb(e,t){let n=this.buffers[t];if(!n)throw new _("unknown_resource",`impulse sound ${t} is not loaded`);let r=this.context.createGain(),o=this.context.createConvolver();o.normalize=true,o.buffer=n;let s=e===zY?lm(this.context):this.buses[e].input;return r.connect(o),o.connect(s),this.buses.push({input:r,parent:s,tail:o,body:o,filter:null,meter:null}),this.buses.length-1}setBusGain(e,t,n){this.ramp(this.buses[e].input.gain,t,n);}setBusFilter(e,t,n,r,o){let s=this.buses[e];if(t<0){if(s.filter===null)return;s.body.disconnect(s.filter),s.filter.disconnect(),s.body.connect(s.parent),s.meter&&s.body.connect(s.meter),s.filter=null,s.tail=s.body;return}let a=fg[t];if(a===void 0)throw new _("invalid_argument",`filter kind ${t} is unknown`);let l=s.filter;l===null&&(l=this.context.createBiquadFilter(),s.body.disconnect(s.parent),s.meter&&s.body.disconnect(s.meter),s.body.connect(l),l.connect(s.parent),s.meter&&l.connect(s.meter),s.filter=l,s.tail=l),l.type=a,l.frequency.setValueAtTime(n,this.context.currentTime),l.Q.setValueAtTime(r,this.context.currentTime),l.gain.setValueAtTime(o,this.context.currentTime);}meter(e,t){let n=this.buses[e];n.meter===null&&(n.meter=this.context.createAnalyser(),n.meter.fftSize=$Y,n.tail.connect(n.meter));let r=this.meterScratch;n.meter.getFloatTimeDomainData(r);let o=0,s=0;for(let a=0;a<r.length;a++){let l=r[a],c=l<0?-l:l;c>o&&(o=c),s+=l*l;}t[od]=o,t[sd]=Math.sqrt(s/r.length);}createAnalyser(e,t){let n=this.context.createAnalyser();return n.fftSize=t.fftSize,n.smoothingTimeConstant=t.smoothing,n.minDecibels=t.minDecibels,n.maxDecibels=t.maxDecibels,this.buses[e].tail.connect(n),this.analysers.push(n),this.analysers.length-1}readAnalyser(e,t,n){let r=this.analysers[e];if(!r)throw new _("unknown_resource",`analyser ${e} does not exist`);n instanceof Uint8Array?t===bs?r.getByteFrequencyData(n):r.getByteTimeDomainData(n):t===bs?r.getFloatFrequencyData(n):r.getFloatTimeDomainData(n);}setBusSend(e,t,n){let r=e*XOe+t,o=this.sends.get(r);o===void 0&&(o=this.context.createGain(),this.buses[e].input.connect(o),o.connect(this.buses[t].input),this.sends.set(r,o)),o.gain.setValueAtTime(n,this.context.currentTime);}play(e,t,n,r,o,s){let a=this.nextVoice;this.nextVoice=(this.nextVoice+1)%this.voices.length,this.release(a);let l=this.voices[a],c=this.context.createBufferSource();c.buffer=this.buffers[e],c.loop=o,c.playbackRate.value=r;let u=this.context.createGain();if(u.gain.value=n,c.connect(u),s){let d=this.context.createPanner();d.panningModel="HRTF",d.refDistance=KOe,d.maxDistance=YOe,u.connect(d),d.connect(this.buses[t].input),l.panner=d;}else u.connect(this.buses[t].input);return c.addEventListener("ended",this.onEnded[a]),c.start(),l.source=c,l.gain=u,a}stop(e,t){let n=this.voices[e];if(!n.source||!n.gain)return;if(t<=0){n.source.stop();return}let r=this.context.currentTime;n.gain.gain.setTargetAtTime(0,r,t/QY),n.source.stop(r+t);}isPlaying(e){return this.voices[e].source!==null}setVoiceGain(e,t,n){let r=this.voices[e]?.gain;r&&this.ramp(r.gain,t,n);}setVoiceRate(e,t,n){let r=this.voices[e]?.source;if(!r)return;let o=this.context.currentTime;r.playbackRate.setValueAtTime(t,o),r.detune.setValueAtTime(n,o);}setVoiceSpatial(e,t){let n=this.voices[e]?.panner;n&&(n.distanceModel=_g[t[yg]]??"inverse",n.refDistance=t[Ag],n.maxDistance=t[bg],n.rolloffFactor=t[gg],n.coneInnerAngle=t[Eg],n.coneOuterAngle=t[xg],n.coneOuterGain=t[vg]);}setVoiceLoop(e,t,n,r){let o=this.voices[e]?.source;o&&(o.loop=t,o.loopStart=n,o.loopEnd=r);}setVoicePosition(e,t,n){let r=this.voices[e].panner;r&&(r.positionX.value=t[n+cC],r.positionY.value=t[n+cC+1],r.positionZ.value=t[n+cC+2],r.orientationX.value=-t[n+8],r.orientationY.value=-t[n+9],r.orientationZ.value=-t[n+10]);}setListener(e,t){let n=this.context.listener;n.positionX.value=e[t+12],n.positionY.value=e[t+13],n.positionZ.value=e[t+14],n.forwardX.value=-e[t+8],n.forwardY.value=-e[t+9],n.forwardZ.value=-e[t+10],n.upX.value=e[t+4],n.upY.value=e[t+5],n.upZ.value=e[t+6];}async openStream(e,t){let n=this.createMediaElement;if(n===null||!this.capabilities.streaming)throw new _("unsupported_feature","this audio context cannot stream media");let r=n(),o=null;if("url"in e)r.src=e.url;else if("bytes"in e)o=URL.createObjectURL(new Blob([e.bytes])),r.src=o;else throw new _("invalid_argument","streams play from bytes or a url");r.crossOrigin="anonymous",r.preload="auto";let s=this.context.createMediaElementSource(r),a=this.context.createGain();return s.connect(a),a.connect(this.buses[t].input),this.streams.push({element:r,source:s,gain:a,objectUrl:o}),this.streams.length-1}stream(e){let t=this.streams[e];if(!t)throw new _("unknown_resource",`stream ${e} is not open`);return t}playStream(e,t,n){let r=this.stream(e);r.gain.gain.setValueAtTime(t,this.context.currentTime),r.element.loop=n;let o=r.element.play();o&&o.catch(()=>{});}pauseStream(e){this.stream(e).element.pause();}seekStream(e,t){this.stream(e).element.currentTime=Math.max(0,t);}streamTime(e){return this.stream(e).element.currentTime}streamDuration(e){let t=this.stream(e).element.duration;return Number.isFinite(t)?t:0}closeStream(e){let t=this.streams[e];t&&(t.element.pause(),t.source.disconnect(),t.gain.disconnect(),t.objectUrl!==null&&URL.revokeObjectURL(t.objectUrl),this.streams[e]=null);}suspend(){this.context.suspend();}resume(){this.context.resume();}dispose(){for(let e=0;e<this.voices.length;e++)this.release(e);for(let e=0;e<this.streams.length;e++)this.closeStream(e);this.context.close();}ramp(e,t,n){n<=0?e.setValueAtTime(t,this.context.currentTime):e.setTargetAtTime(t,this.context.currentTime,n/QY);}release(e){let t=this.voices[e],n=t.source;n&&(n.removeEventListener("ended",this.onEnded[e]),n.stop(),n.disconnect()),t.gain?.disconnect(),t.panner?.disconnect(),t.source=null,t.gain=null,t.panner=null;}};var qOe=0;function zOe(i,e,t,n){switch(e){case "f32":return new Float32Array(i,t,n);case "f64":return new Float64Array(i,t,n);case "i8":return new Int8Array(i,t,n);case "i16":return new Int16Array(i,t,n);case "i32":return new Int32Array(i,t,n);case "u8":return new Uint8Array(i,t,n);case "u16":return new Uint16Array(i,t,n);case "u32":return new Uint32Array(i,t,n)}}var QOe={f32:4,f64:8,i8:1,i16:2,i32:4,u8:1,u16:2,u32:4};var $Oe=0;function Ig(i,e){let t=i[e];return typeof t=="function"?t:null}function jOe(i){let e=Ig(i,"engine_memory_used"),t=Ig(i,"engine_arena_committed"),n=Ig(i,"engine_arena_ceiling");return e===null||t===null||n===null?null:{used:e(),committed:t(),ceiling:n()}}function jY(i){return Ig(i,"engine_arena_release")?.()??$Oe}function JOe(i){let e=jOe(i);return e===null?"":` (using ${e.used} of a ${e.ceiling} byte ceiling, ${e.committed} committed)`}var Og=class{constructor(e){this.pointers=[];this.sizes=[];this.runtime=e;}owns(e){return e.buffer===this.runtime.memory.buffer}allocate(e,t){let n=Math.max(t*QOe[e],ce),r=this.runtime.exports.engine_alloc(n,ce);if(r===qOe)throw new _("capacity_exceeded",`engine memory cannot hold ${n} more bytes${JOe(this.runtime.symbols)}`);return this.pointers.push(r),this.sizes.push(n),zOe(this.runtime.memory.buffer,e,r,t)}release(){for(let e=0;e<this.pointers.length;e++)this.runtime.exports.engine_free(this.pointers[e],this.sizes[e],ce);this.pointers.length=0,this.sizes.length=0;}};function uC(i){return i===3?1:4}function JY(i){return Math.ceil(i/16)*16}function ZY(i,e){return Math.ceil(e*uC(i)/64)*64}var ZOe=["engine_soa_create","engine_soa_destroy","engine_soa_generations","engine_soa_header","engine_soa_turn","engine_soa_remove","engine_soa_map","engine_soa_vec","engine_soa_select","engine_soa_reduce","engine_soa_sort","engine_soa_grid","engine_soa_near","engine_soa_nearest"],e1e=["engine_soa_inventory","engine_soa_effect","engine_soa_raycast","engine_soa_paths","engine_soa_pick","engine_soa_flow","engine_flow_create","engine_flow_destroy","engine_flow_registers","engine_flow_costs","engine_flow_rasterize","engine_flow_build"];function Cg(i,e){for(let n of ZOe)if(typeof i[n]!="function")return null;if(typeof i.engine_alloc!="function"||typeof i.engine_free!="function")return null;let t={};for(let n of e1e){let r=i[n];typeof r=="function"&&(t[n]=r);}return {exports:i,memory:e,bulk:t}}Cm();function km(i){return i&255}function nX(i){return i>>>8}function fC(i){return i===22||i===23}var mC={args:[2,0,0,0],results:[]},_C={1:{args:[0,0,0,0,0,0,0],results:[0,0,0,0,2,3]},2:{args:[0,0,0,0,0,0],results:[3]},3:{args:[0,0],results:[0]},4:{args:[0,0,0,0,0,0],results:[0,0,0,2]},5:{args:[0,0,0],results:[0,0,0,0,2]},6:mC,7:mC,8:mC,9:{args:[0,0,0,0],results:[2,2]},10:{args:[0,0,0,0,0,0,0,0,2],results:[0,0,0,0,2,3]},11:{args:[2,0],results:[]},12:{args:[2,2,3,0,0],results:[2]},13:{args:[2,0,0,0,0],results:[]},14:{args:[2,2,0,0,0,0,0,0,0,0,0,0],results:[]},15:{args:[2,2,0,0,0,0],results:[]},16:{args:[2,0,0,0],results:[]},17:{args:[2,2,0,0,0,0],results:[]},18:{args:[0,0,0,0,0,0,0],results:[0,2,2,3]},19:{args:[0,0,0],results:[2,3]},20:{args:[0,0,0,2],results:[]},21:{args:[2,2,2],results:[2,0,2]},23:{args:[],results:[]}},rX=4,iX=5,oX=6,sX=7,aX=9,lX=3,cX=1,Ng=1,nt={NOP:0,MOV:1,LOAD:2,STORE:3,ROW:4,SEL:5,JNONE:6,LOOP_INIT:8,LOOP_NEXT:9,NEIGHBOURS:11,NLOAD:12,OUTER:13,NROW:14,ACC_FADD:15,ACC_FMIN:16,ACC_FMAX:17,ACC_IADD:18,EXT:19,FADD:20,FSUB:21,FMUL:22,FDIV:23,FMIN:24,FMAX:25,FMOD:26,FPOW:27,FATAN2:28,FMULADD:29,FMULSUB:30,FSUBMUL:31,FADDMUL:32,FCLAMP:33,FLERP:34,FLOG2:39,FNEG:40,FABS:41,FSQRT:42,FFLOOR:43,FCEIL:44,FROUND:45,FTRUNC:46,FSIGN:47,FSIN:48,FCOS:49,FTAN:50,FASIN:51,FACOS:52,FATAN:53,FEXP:54,FLOG:55,FLEN2:56,FLEN3:57,FDOT2:58,FDOT3:59,FLT:60,FLE:61,FEQ:62,FNE:63,IADD:70,ISUB:71,IMUL:72,IREM:73,UREM:74,IAND:75,IOR:76,IXOR:77,ISHL:78,ISHR:79,IUSHR:80,IMIN:81,IMAX:82,UMIN:83,UMAX:84,INEG:85,IABS:86,INOT:87,ILT:90,ILE:91,IEQ:92,INE:93,ULT:94,ULE:95,ITOF:100,UTOF:101,FTOI:102,BTOF:103,BTOI:104,FTOB:105,ITOB:106,MAND:110,MOR:111,MANDN:112,MNOT:113,NOISE2:120,NOISE3:121,HASH:122,RAND:123,EMIT:124,CALL:125,UADDC:126,USUBB:127,UMULHI:128},lc=0,gs=1,yC=2,uX=["engine_kernel_isa","engine_kernel_load","engine_kernel_unload","engine_kernel_bind","engine_kernel_unbind","engine_kernel_run","engine_kernel_events","engine_kernel_clear_events"];var dX=["engine_kernel_bind_table","engine_kernel_bind_pool","engine_kernel_data"],kg=70,er=2,vo=0,Es=1,Ro=4096,Ln={REDUCE:160,ARG:161,HIST:162,SCATTER:163,SCAN:164,COMPACT:165},AC=65536,Lm=256,hX=0,pX=1,mX=2,fX=3,_X=4,yX=5,AX=6;var bX=0,bC=1,gX=2,EX=3,xX=4;var vX=0;var RX=0,SX=1,TX=2;function So(i){return i>=Ln.REDUCE&&i<=Ln.COMPACT}var Nm={CURVE:176,LUT1:177,LUT2:178,SAMPLE:179,CELL:180},Lg=1<<18,wX=0,IX=1,OX=2;var CX=4;var NX=4;var kX=8,Mg=1,Mm=2,LX=8,gC=0,EC=1,xC=2,vC=3;var MX=1<<24;function DX(i){return i>=Nm.CURVE&&i<=Nm.CELL}var ka=4096,RC=4097,SC=4098,cc=4099,PX=4100;var La=0,Dg=1,Pg=2,ud=3,Fg=3,Ug=4,Bg=1,Gg=2,Vg=3;var Ve=175;var t1e=12,An={CROSS:0,SAMPLING:1,NARROW:2,DATA:3,SYSTEMS:5,NEURAL:6,SIMD:7},FX=24576;var UX=24578,BX=24579;var Ma=128,dd=32,Hg=28672,GX=256,hd=28928,pd=28929,md=28930,Dm=28931,Pm=28944,Fm=28945,Um=28946,Bm=28947,Gm=28948;var TC=7,VX=8,HX=16,WX=32,wC=3,KX=(1<<wC)-1,Wg=0;function Di(i){return i>>>t1e}var IC=19,OC=15,YX=1<<23,xs=16,fd=12288,_d=12289,Vm=12290,yd=12291,Hm=12304,Wm=12305,Ad=12306,Km=12307,Ym=12320,bd=12336;var uc=64,kr={FADD:1,FMUL:2,FMIN:3,FMAX:4,IADD:5,IMIN:6,IMAX:7,UMIN:8,UMAX:9,OR:10,AND:11,PUSH:12},XX=0;var CC=1,NC=2,qX=3,n1e=4,Da=16,Pa=17;var r1e=32,kC=33;var at={LINEAR_F32:0,LINEAR_U32:1,FEEDBACK_F32:2,PHASE_F64:3,ADD_F32:4,MUL_F32:5,MIN_F32:6,MAX_F32:7,ADD_INT:8,MUL_INT:9,MIN_I32:10,MAX_I32:11,MIN_U32:12,MAX_U32:13,AND:14,OR:15};var zX=31,QX=32,Kg=64;function gd(i){return i===r1e||i===kC}function $X(i){return i===at.FEEDBACK_F32||i===at.PHASE_F64?2:1}var LC=20480,jX=20481;var Ed=20483,Yg=4294967295;var i1e=1,MC=2,JX=3,ZX=4,Xg=8;function qg(i,e){return i===i1e?(e^2147483648)>>>0:i===MC?(e&2147483648)!==0?~e>>>0:(e|2147483648)>>>0:e>>>0}function DC(i){switch(Di(i)){case An.CROSS:return i>=CC&&i<=n1e||gd(i);case An.SYSTEMS:return i>=LC&&i<=Ed;default:return false}}function dc(i,e){return i===Ve&&DC(e)}var o1e=4294967295,zg=new Map,eq=-1;function $g(i){eq=i;}var Qg=class{constructor(e,t,n){this.name=e;this.fields=t;this.capacity=n;this.count=0;this.lost=0;this.at=0;if(this.names=Object.keys(t),this.kinds=this.names.map(s=>t[s]),this.names.length>8)throw new _("invalid_argument",`events carry at most ${8} fields`);this.ring=new Uint32Array(n*10),this.floats=new Float32Array(this.ring.buffer),this.ints=new Int32Array(this.ring.buffer);let r={},o=this;Object.defineProperty(r,"row",{get:()=>o.ring[o.at+1],enumerable:true}),this.names.forEach((s,a)=>{let l=2+a,c=this.kinds[a];Object.defineProperty(r,s,{get:()=>c==="f32"?o.floats[o.at+l]:c==="i32"?o.ints[o.at+l]:c==="bool"?o.ring[o.at+l]!==0:o.ring[o.at+l],enumerable:true});}),this.event=Object.freeze(r);}get pending(){return this.count}get dropped(){return this.lost}emit(e){let t=e;if(this.count>=this.capacity){this.lost++;return}let n=this.count*10;this.ring[n+1]=eq>>>0;for(let r=0;r<this.names.length;r++){let o=t[this.names[r]],s=n+2+r,a=this.kinds[r];a==="f32"?this.floats[s]=o:a==="bool"?this.ring[s]=o?o1e:0:this.ring[s]=o>>>0;}this.count++;}accept(e,t){if(this.count>=this.capacity){this.lost++;return}this.ring.set(e.subarray(t,t+10),this.count*10),this.count++;}addLost(e){this.lost+=e;}drain(e){let t=this.count;for(let n=0;n<t;n++)this.at=n*10,e(this.event);return this.count=0,this.lost=0,t}};function tq(i,e,t=Ro){if(zg.has(i))throw new _("invalid_argument",`an event channel named ${i} already exists`);let n=new Qg(i,e,t);return zg.set(i,n),n}function hc(i,e){let t=i[vo],n=i[Es];if(!(e===void 0||t===0&&n===0)){for(let r=0;r<t;r++){let o=er+r*10,s=e[i[o]];(s===void 0?void 0:zg.get(s.name))?.accept(i,o);}if(n>0)for(let r of e)zg.get(r.name)?.addLost(n);}}var s1e=["engine_compute_frame","engine_compute_priority","engine_compute_registers","engine_compute_clear"];var a1e={simulation:0,presentation:1,optional:2};function nq(i){return i===void 0?0:a1e[i]}var qm=0,Zg=1,eE=-7,rq=-8,iq=16,oq=8,sq=32,l1e=iq+sq*oq,c1e=1,u1e=2,d1e=5,h1e=6,aq=8,p1e=0,m1e=1,f1e=2,_1e=4,y1e=5,A1e=6,b1e=7,PC=1e6,g1e=2,E1e=2**32,x1e=1023;function jg(i,e){return i*E1e+(i===qm?e&x1e:e)}var v1e=[null,"frame_over","kernel_heavy","kernel_deferred","kernel_stopped","gpu_deferred","gpu_stall"],R1e=["interpreter","jit","prebuilt","native","gpu"],S1e={frame_over:"Kernels used more time this frame than some phones can spare.",kernel_heavy:"This kernel is too heavy for some phones.",kernel_deferred:"This kernel waited for the next frame so the game stays smooth.",kernel_stopped:"This kernel ran too long and was stopped so the game stays responsive.",gpu_deferred:"This GPU kernel waited for the next frame so the game stays smooth.",gpu_stall:"GPU work took longer than a frame."};function lq(i){let e=i.kernel===null?"":` kernel ${i.kernel}`,t=i.rows>0?` on ${i.rows} rows`:"";return `[compute ${i.code}]${e} ${i.ms.toFixed(2)} ms${t} via ${i.route}: ${i.message}`}function T1e(i,e){let t=[],n=Math.min(i[aq],sq);for(let r=0;r<n;r++){let o=iq+r*oq,s=v1e[i[o+p1e]]??null;s!==null&&t.push({code:s,kernel:e(i[o+m1e],i[o+f1e]),route:R1e[i[o+_1e]]??"interpreter",ms:i[o+y1e]/PC,rows:i[o+A1e],frame:i[o+b1e],message:S1e[s]});}return t}var Jg=class i{constructor(e,t){this.exports=e;this.memory=t;this.names=new Map;this.kernels=new Map;this.levels=new Map;this.view=new Uint32Array(0);this.readout={budgetMs:0,spentMs:0,deferred:0,stopped:0};this.nameOf=(e,t)=>this.names.get(jg(e,t))??null;this.onBound=null;}get last(){return this.readout}static bind(e,t){for(let n of s1e)if(typeof e[n]!="function")return null;return new i(e,t)}bound(e,t,n,r){let o=jg(e,t);this.names.set(o,n),this.kernels.set(o,[e,t,n]),this.levels.set(o,0),this.prioritise(e,t,r),this.onBound?.(e,t,n);}unbound(e,t){let n=jg(e,t);this.names.delete(n),this.kernels.delete(n),this.levels.delete(n);}boundKernels(){return this.kernels.values()}prioritise(e,t,n){let r=jg(e,t);(this.levels.get(r)??0)!==n&&this.exports.engine_compute_priority(e,t,n)>=0&&this.levels.set(r,n);}frame(e,t,n){this.exports.engine_compute_frame(Math.min(Math.max(Math.trunc(e),0),g1e),Math.max(Math.trunc(t),0));let r=this.exports.engine_compute_registers();if(r===0)return;let o=this.memory.buffer;(this.view.buffer!==o||this.view.byteOffset!==r)&&(this.view=new Uint32Array(o,r,l1e));let s=this.view,a=this.readout;if(a.budgetMs=s[c1e]/PC,a.spentMs=s[u1e]/PC,a.deferred=s[d1e],a.stopped=s[h1e],s[aq]===0)return;let l=T1e(s,this.nameOf);this.exports.engine_compute_clear();for(let c of l)n(c);}};var UC=new Float64Array(1),FC=new Uint32Array(UC.buffer),BC=new Float32Array(1),hq=new Uint32Array(BC.buffer),It=Math.fround;function mt(i){return BC[0]=i,hq[0]}function Ye(i){return hq[0]=i>>>0,BC[0]}function pq(i,e){return FC[0]=e>>>0,FC[1]=i>>>0,UC[0]}function w1e(i){return UC[0]=i,FC[0]}function pt(i){return pq(Number.parseInt(i.slice(0,8),16),Number.parseInt(i.slice(8),16))}var mq=["3ff0000000000000","3fefd9b0d3158574","3fefb5586cf9890f","3fef9301d0125b51","3fef72b83c7d517b","3fef54873168b9aa","3fef387a6e756238","3fef1e9df51fdee1","3fef06fe0a31b715","3feef1a7373aa9cb","3feedea64c123422","3feece086061892d","3feebfdad5362a27","3feeb42b569d4f82","3feeab07dd485429","3feea47eb03a5585","3feea09e667f3bcd","3fee9f75e8ec5f74","3feea11473eb0187","3feea589994cce13","3feeace5422aa0db","3feeb737b0cdc5e5","3feec49182a3f090","3feed503b23e255d","3feee89f995ad3ad","3feeff76f2fb5e47","3fef199bdd85529c","3fef3720dcef9069","3fef5818dcfba487","3fef7c97337b9b5f","3fefa4afa2a490da","3fefd0765b6e4540"],fq=mq.map(i=>Number.parseInt(i.slice(0,8),16)),_q=mq.map(i=>Number.parseInt(i.slice(8),16)),yq=[pt("3fac6af84b912394"),pt("3fcebfce50fac4f3"),pt("3fe62e42ff0c52d6")],Aq=[pt("3ebc6af84b912394"),pt("3f2ebfce50fac4f3"),pt("3f962e42ff0c52d6")],bq=pt("40471547652b82fe"),gq=pt("4338000000000000"),Eq=pt("42e8000000000000"),xq=-104,vq=89,Rq=-151,Sq=129,Tq=["3ff661ec79f8f3be","3ff571ed4aaf883d","3ff49539f0f010b0","3ff3c995b0b80385","3ff30d190c8864a5","3ff25e227b0b8ea0","3ff1bb4a4a1a343f","3ff12358f08ae5ba","3ff0953f419900a7","3ff0000000000000","3fee608cfd9a47ac","3feca4b31f026aa0","3feb2036576afce6","3fe9c2d163a1aa2d","3fe886e6037841ed","3fe767dcf5534862"].map(pt),wq=["bfd57bf7808caade","bfd2bef0a7c06ddb","bfd01eae7f513a67","bfcb31d8a68224e9","bfc6574f0ac07758","bfc1aa2bc79c8100","bfba4e76ce8c0e5e","bfb1973c5a611ccc","bfa252f438e10c1e","0000000000000000","3faaa5aa5df25984","3fbc5e53aa362eb4","3fc526e57720db08","3fcbc2860d224770","3fd1058bc8a07ee1","3fd4043057b6ee09"].map(pt),GC=["bfdefec65b963019","bfdb0b6832d4fca4","bfd7418b0a1fb77b","bfd39de91a6dcf7b","bfd01d9bf3f2b631","bfc97c1d1b3b7af0","bfc2f9e393af3c9f","bfb960cbbf788d5c","bfaa6f9db6475fce","0000000000000000","3fb338ca9f24f53d","3fc476a9543891ba","3fce840b4ac4e4d2","3fd40645f0c6651c","3fd88e9c2c1b9ff8","3fdce0a44eb17bcc"].map(pt),Iq=pt("3fe62e42fefa39ef"),nE=["bfd00ea348b88334","3fd5575b0be00b6a","bfdffffef20a4123"].map(pt),zm=["bfd712b6f70a7e4d","3fdecabf496832e0","bfe715479ffae3de","3ff715475f35c8b8"].map(pt),vd=["3fd27616c9496e0b","bfd71969a075c67a","3fdec70a6ca7badd","bfe7154748bef6c8","3ff71547652ab82b"].map(pt),Oq=65536,Cq=pt("405fffffffd1d571"),Nq=pt("405fffffffa3aae2"),kq=-150,Lq=1060306944,Mq=8388608,Dq=23<<23,Pq=8388608,Rd=2139095040,rE=1065353216,iE=2147483648,I1e=2147483647,O1e=4286578688,Fq=Ye(2139095039),Uq=pt("41645f306dc9c883"),Bq=pt("3ff921fb54442d18"),Gq=pt("3c1921fb54442d18"),Vq=pt("bfdffffffd0c621c"),Hq=pt("3fa55553e1068f19"),Wq=pt("bf56c087e89a359d"),Kq=pt("3ef99343027bf8c3"),Yq=pt("bfc555545995a603"),Xq=pt("3f81107605230bc4"),qq=pt("bf2994eb3774cf24"),cq=[1,-1,-1,1],zq=1071,Qq=8388608,oE=[162,41721,10680707,2734261102,4186140238,2205044292,1850622997,1313084713,1142237692,355073063,704390999,4230436817,660066805,1473377588,3522507997,4113882560,886948059,3720403810,3235603093,3680671129,1653971260,2509847619,2570863504,1011060801],$q=Math.PI/4,jq=Math.PI/2,Jq=pt("3fda827999fcef34"),Zq=14,e7=Array.from({length:Zq},(i,e)=>(e%2===0?1:-1)*(1/(2*e+1))),tE=(1n<<64n)-1n,C1e=(1n<<32n)-1n;function t7(i,e,t){return Number.isNaN(i)?e:Math.min(Math.max(i,e),t)}function n7(i,e,t,n){let r=i+e,o=w1e(r),s=r-e,a=i-s,l=o&31,c=fq[l]+(o+n>>>0<<15)>>>0,u=pq(c,_q[l]),d=t[0]*a+t[1],h=a*a,p=t[2]*a+1;return (d*h+p)*u}function r7(i){return Number.isNaN(i)?Number.NaN:It(n7(bq*t7(i,xq,vq),gq,Aq,0))}function VC(i){let e=(i&I1e)>>>0;return e>=Pq?e:mt(It(Ye(e)*Mq))-Dq>>>0}function HC(i){let e=i-Lq>>>0,t=e>>>19&15,n=(e&O1e)>>>0,r=(n|0)>>23,o=Ye(i-n>>>0);return [t,r,o*Tq[t]-1]}function i7(i,e){let t=mt(i);return t<<1>>>0?t===Rd?i:(t&iE)!==0||t<<1>>>0>=Rd<<1>>>0?Number.NaN:e:Number.NEGATIVE_INFINITY}function o7(i){let[e,t,n]=HC(VC(mt(i))),r=wq[e]+t*Iq,o=n*n,s=nE[1]*n+nE[2];return s=nE[0]*o+s,s=s*o+(r+n),i7(It(i),It(s))}function s7(i){let[e,t,n]=HC(VC(mt(i))),r=GC[e]+t,o=n*n,s=zm[1]*n+zm[2];s=zm[0]*o+s;let a=zm[3]*n+r;return s=s*o+a,i7(It(i),It(s))}function N1e(i){let[e,t,n]=HC(i),r=GC[e]+t,o=n*n,s=vd[0]*n+vd[1],a=vd[2]*n+vd[3],l=o*o,c=vd[4]*n+r;return c=a*o+c,s*l+c}function k1e(i){let e=i>>>23&255;if(e<127)return 0;if(e>150)return 2;let t=150-e;return (t===0?0:(i&(1<<t>>>0)-1)>>>0)!==0?0:(i&1<<t>>>0)!==0?1:2}function uq(i){return (i<<1>>>0)-1>>>0>=(Rd<<1>>>0)-1>>>0}function a7(i,e){let t=It(i),n=It(e),r=mt(t),o=mt(n),s=r<<1>>>0>>>1;if(uq(o))return !(o<<1>>>0)||r===rE?1:r<<1>>>0>Rd<<1>>>0||o<<1>>>0>Rd<<1>>>0?Number.NaN:s===rE?1:s<rE==((o&iE)===0)?0:It(n*n);let a=k1e(o),l=(r&iE)!==0,c=l&&a===1;if(uq(r)){if(Number.isNaN(t))return Number.NaN;let h=It(t*t),p=c?-h:h;return (o&iE)!==0?It(1/p):p}if(l&&a===0)return Number.NaN;let u=n*N1e(VC(r)),d=h=>c?-h:h;return u>Cq?d(Number.POSITIVE_INFINITY):u>Nq?d(Fq):u<=kq?d(0):It(n7(t7(u,Rq,Sq),Eq,yq,c?Oq:0))}function dq(i,e,t,n){let r=i*n,o=i*i,s=o*r,a=o*o,l=s*o,c=a*o,u=Wq*t+o*(Kq*t),d=Xq+o*qq,h=t+o*(Vq*t),p=r+s*Yq,m=h+a*(Hq*t),f=p+l*d,y=m+c*u;return (e&1)!==0?[y,f]:[f,y]}function WC(i){let e=It(i),t=mt(e);if((t>>>20&2047)<zq){let y=(e*Uq|0)+Qq>>24;return dq(e-y*Bq,y,(y&2)!==0?-1:1,cq[y&3])}if(!Number.isFinite(e))return [Number.NaN,Number.NaN];let n=t>>>31,r=t>>>26&15,o=t>>>23&7,s=BigInt((t&16777215|8388608)<<o>>>0),a=s*BigInt(oE[r])&C1e,l=s*BigInt(oE[r+4]),u=(s*BigInt(oE[r+8])>>32n|a<<32n)&tE;u=u+l&tE;let d=(u+(1n<<61n)&tE)>>62n;u=u-(d<<62n)&tE;let h=u>=1n<<63n?u-(1n<<64n):u,p=Number(h)*Gq,m=Number(d)+n|0;return dq(p,Number(d),(m&2)!==0?-1:1,cq[m&3])}function sE(i){return It(WC(i)[0])}function aE(i){return It(WC(i)[1])}function l7(i){let[e,t]=WC(i);return It(e/t)}function L1e(i){let e=i>Jq,t=e?(i-1)/(i+1):i,n=t*t,r=0;for(let o=Zq-1;o>=0;o--)r=e7[o]+n*r;return (e?$q:0)+t*r}function lE(i,e){if(Number.isNaN(e)||Number.isNaN(i))return Number.NaN;let t=Math.abs(e),n=Math.abs(i),r=Math.max(t,n),o=Math.min(t,n),s=r===0?0:o===Number.POSITIVE_INFINITY?1:o/r,a=L1e(s);return n>t&&(a=jq-a),(e<0||Object.is(e,-0))&&(a=Math.PI-a),i<0||Object.is(i,-0)?-a:a}function c7(i,e){return It(lE(It(i),It(e)))}function u7(i){return It(lE(It(i),1))}function d7(i){let e=It(i);return Math.abs(e)>1?Number.NaN:It(lE(e,Math.sqrt((1-e)*(1+e))))}function h7(i){let e=It(i);return Math.abs(e)>1?Number.NaN:It(lE(Math.sqrt((1-e)*(1+e)),e))}var re={EXP2_HI:fq,EXP2_LO:_q,EXP2_POLY:yq,EXP_POLY:Aq,INV_LN2_N:bq,SHIFT:gq,SHIFT_SCALED:Eq,EXP_LOW:xq,EXP_HIGH:vq,EXP2_LOW:Rq,EXP2_HIGH:Sq,INV_C:Tq,LOG_C:wq,LOG2_C:GC,LN2:Iq,LOG_POLY:nE,LOG2_POLY:zm,POW_POLY:vd,POW_SIGN_BIAS:Oq,POW_OVERFLOW:Cq,POW_SATURATE:Nq,POW_UNDERFLOW:kq,LOG_OFF:Lq,SUBNORMAL_SCALE:Mq,SUBNORMAL_BIAS:Dq,MIN_NORMAL:Pq,INFINITY_BITS:Rd,ONE_BITS:rE,HPI_INV:Uq,HPI:Bq,PI63:Gq,COS_C1:Vq,COS_C2:Hq,COS_C3:Wq,COS_C4:Kq,SIN_S1:Yq,SIN_S2:Xq,SIN_S3:qq,LARGE_TOP:zq,QUADRANT_ROUND:Qq,INV_PIO4:oE,QUARTER_PI:$q,HALF_PI:jq,TAN_PI_8:Jq,ATAN_COEFFS:e7};var vn=Math.fround;function tr(i,e){return Math.floor(vn(i*e))}var M1e=-2147483648,D1e=2147483647;function KC(i){return Number.isNaN(i)?0:Math.min(Math.max(i,M1e),D1e)}var Fa=class{constructor(e){this.inverse=1;this.radiusSquared=0;this.radius=0;this.flat=true;this.len=0;let t=1024;for(;t<e*2;)t*=2;this.mask=t-1,this.starts=new Uint32Array(t+1),this.bucket=new Uint32Array(e),this.rows=new Uint32Array(e),this.cells=new Int32Array(e*3),this.xs=new Float32Array(e),this.ys=new Float32Array(e),this.zs=new Float32Array(e);}hash(e,t,n){return (t+Math.imul(e,1021)+Math.imul(n,65539)&this.mask)>>>0}rebuild(e,t,n,r,o){let s=vn(e);if(this.len=0,this.radius=s,!(s>0)||!Number.isFinite(s))return false;let a=Math.min(o,this.rows.length);this.inverse=vn(1/s),this.radiusSquared=vn(s*s),this.flat=r===null;let l=this.inverse;this.starts.fill(0);for(let c=0;c<a;c++){let u=r===null?0:r[c],d=this.hash(tr(t[c],l),tr(n[c],l),tr(u,l));this.bucket[c]=d,this.starts[d+1]++;}for(let c=1;c<this.starts.length;c++)this.starts[c]+=this.starts[c-1];for(let c=0;c<a;c++){let u=this.bucket[c],d=this.starts[u]++,h=r===null?0:r[c];this.rows[d]=c,this.xs[d]=t[c],this.ys[d]=n[c],this.zs[d]=h,this.cells[3*d]=tr(t[c],l),this.cells[3*d+1]=tr(n[c],l),this.cells[3*d+2]=tr(h,l);}for(let c=this.starts.length-1;c>0;c--)this.starts[c]=this.starts[c-1];return this.starts[0]=0,this.len=a,true}get size(){return this.len}get isFlat(){return this.flat}cellOf(e,t,n,r){r[0]=KC(tr(e,this.inverse)),r[1]=KC(tr(t,this.inverse)),r[2]=this.flat?0:KC(tr(n,this.inverse));}bucketOf(e,t,n){return this.hash(e,t,n)}bucketStart(e){return this.starts[e]}bucketEnd(e){return this.starts[e+1]}inCell(e,t,n,r){return this.cells[3*e]===t&&this.cells[3*e+1]===n&&this.cells[3*e+2]===r}rowAt(e){return this.rows[e]}xAt(e){return this.xs[e]}yAt(e){return this.ys[e]}zAt(e){return this.zs[e]}order(){return this.rows.subarray(0,this.len)}walk(e,t,n,r,o){if(o.length=0,this.len===0)return 0;let s=this.radius,a=this.inverse,l=tr(vn(e-s),a),c=tr(vn(t-s),a),u=this.flat?0:tr(vn(n-s),a),d=tr(vn(e+s),a),h=tr(vn(t+s),a),p=this.flat?0:tr(vn(n+s),a),m=this.radiusSquared;for(let f=l;f<=d;f++)for(let y=c;y<=h;y++)for(let b=u;b<=p;b++){let A=this.hash(f,y,b),E=this.starts[A+1];for(let R=this.starts[A];R<E;R++){if(this.cells[3*R]!==f||this.cells[3*R+1]!==y||this.cells[3*R+2]!==b)continue;let g=vn(this.xs[R]-e),v=vn(this.ys[R]-t),x=vn(this.zs[R]-n),O=vn(vn(vn(g*g)+vn(v*v))+vn(x*x)),N=this.rows[R];O<=m&&N!==r&&o.push(N);}}return o.length}};var Ba=new Float64Array(1),Td=new Uint32Array(Ba.buffer);function Qt(i){return Ba[0]=i,Td[1]}function vs(i){return Ba[0]=i,Td[0]}function Ga(i,e){return Td[1]=i>>>0,Td[0]=e>>>0,Ba[0]}function Fi(i,e){return Ba[0]=i,Td[0]=e>>>0,Ba[0]}function qC(i,e){return Ba[0]=i,Td[1]=e>>>0,Ba[0]}function Qm(i){return Ga(1023+i<<20,0)}function Sd(i,e){if(e>1023)i*=Qm(1023),e-=1023,e>1023&&(i*=Qm(1023),e-=1023,e>1023&&(e=1023));else if(e<-1022){let r=Qm(-1022)*Qm(53),o=969;i*=r,e+=o,e<-1022&&(i*=r,e+=o,e<-1022&&(e=-1022));}return i*Qm(e)}var p7=-0.16666666666666632,P1e=.00833333333332249,F1e=-1984126982985795e-19,U1e=27557313707070068e-22,B1e=-2.5050760253406863e-8,G1e=158969099521155e-24;function jm(i,e,t){let n=i*i,r=n*n,o=P1e+n*(F1e+n*U1e)+n*r*(B1e+n*G1e),s=n*i;return t===0?i+s*(p7+n*o):i-(n*(.5*e-s*o)-e-s*p7)}var V1e=.0416666666666666,H1e=-0.001388888888887411,W1e=2480158728947673e-20,K1e=-2.7557314351390663e-7,Y1e=2087572321298175e-24,X1e=-11359647557788195e-27;function Jm(i,e){let t=i*i,n=t*t,r=t*(V1e+t*(H1e+t*W1e))+n*n*(K1e+t*(Y1e+t*X1e)),o=.5*t,s=1-o;return s+(1-s-o+(t*r-i*e))}var Lr=[.3333333333333341,.13333333333320124,.05396825397622605,.021869488294859542,.0088632398235993,.0035920791075913124,.0014562094543252903,.0005880412408202641,.0002464631348184699,7817944429395571e-20,7140724913826082e-20,-18558637485527546e-21,2590730518636337e-20],q1e=.7853981633974483,z1e=3061616997868383e-32;function m7(i){return Fi(i,0)}function f7(i,e,t){let n=Qt(i),r=(n&2147483647)>>>0>=1072010280;r&&(n>>>31&&(i=-i,e=-e),i=q1e-i+(z1e-e),e=0);let o=i*i,s=o*o,a=Lr[1]+s*(Lr[3]+s*(Lr[5]+s*(Lr[7]+s*(Lr[9]+s*Lr[11])))),l=o*(Lr[2]+s*(Lr[4]+s*(Lr[6]+s*(Lr[8]+s*(Lr[10]+s*Lr[12]))))),c=o*i;a=e+o*(c*(a+l)+e)+c*Lr[0];let u=i+a;if(r){let f=n>>>31,y=1-2*t,b=y-2*(i+(a-u*u/(u+y)));return f!==0?-b:b}if(t===0)return u;let d=m7(u),h=a-(d-i),p=-1/u,m=m7(p);return m+p*(1+m*d+m*h)}var _7=[10680707,7228996,1387004,2578385,16069853,12639074,9804092,4427841,16666979,11263675,12935607,2387514,4345298,14681673,3074569,13734428,16653803,1880361,10960616,8533493,3062596,8710556,7349940,6258241,3772886,3769171,3798172,8675211,12450088,3874808,9961438,366607,15675153,9132554,7151469,3571407,2607881,12013382,4155038,6285869,7677882,13102053,15825725,473591,9065106,15363067,6271263,9264392,5636912,4652155,7056368,13614112,10155062,1944035,9527646,15080200,6658437,6231200,6832269,16767104,5075751,3212806,1398474,7579849,6349435,12618859],Q1e=[1.570796251296997,7549789415861596e-23,5390302529957765e-30,3282003415807913e-37,1270655753080676e-44,12293330898111133e-52,27337005381646456e-60,21674168387780482e-67],hE=16777216,YC=1/16777216;function $1e(i,e,t){let o=i.length,s=new Array(20).fill(0),a=new Array(20).fill(0),l=new Array(20).fill(0),c=new Array(20).fill(0),u=o-1,d=Math.trunc((t-3)/24);d<0&&(d=0);let h=t-24*(d+1),p=d-u,m=u+4;for(let g=0;g<=m;g++)s[g]=p<0?0:_7[p],p++;for(let g=0;g<=4;g++){let v=0;for(let x=0;x<=u;x++)v+=i[x]*s[u+g-x];l[g]=v;}let f=4,y=0,b=0,A=0;for(;;){let g=0;y=l[f];for(let v=f;v>=1;v--){let x=YC*y|0;c[g]=y-hE*x|0,y=l[v-1]+x,g++;}if(y=Sd(y,h),y-=8*Math.floor(y*.125),b=y|0,y-=b,A=0,h>0?(g=c[f-1]>>24-h,b+=g,c[f-1]-=g<<24-h,A=c[f-1]>>23-h):h===0?A=c[f-1]>>23:y>=.5&&(A=2),A>0){b+=1;let v=0;for(let x=0;x<f;x++){let O=c[x];v===0?O!==0&&(v=1,c[x]=16777216-O):c[x]=16777215-O;}h>0&&(h===1?c[f-1]&=8388607:h===2&&(c[f-1]&=4194303)),A===2&&(y=1-y,v!==0&&(y-=Sd(1,h)));}if(y===0){let v=0;for(let x=f-1;x>=4;x--)v|=c[x];if(v===0){let x=1;for(;c[4-x]===0;)x++;for(let O=f+1;O<=f+x;O++){s[u+O]=_7[d+O];let N=0;for(let I=0;I<=u;I++)N+=i[I]*s[u+O-I];l[O]=N;}f+=x;continue}}break}if(y===0)for(f-=1,h-=24;c[f]===0;)f-=1,h-=24;else if(y=Sd(y,-h),y>=hE){let g=YC*y|0;c[f]=y-hE*g|0,f+=1,h+=24,c[f]=g;}else c[f]=y|0;let E=Sd(1,h);for(let g=f;g>=0;g--)l[g]=E*c[g],E*=YC;for(let g=f;g>=0;g--){let v=0;for(let x=0;x<=4&&x<=f-g;x++)v+=Q1e[x]*l[g+x];a[f-g]=v;}let R=0;for(let g=f;g>=0;g--)R+=a[g];e[0]=A===0?R:-R,R=a[0]-R;for(let g=1;g<=f;g++)R+=a[g];return e[1]=A===0?R:-R,b&7}var y7=1.5/2220446049250313e-31,j1e=.6366197723675814,zC=1.5707963267341256,$m=6077100506506192e-26,J1e=6077100506303966e-26,Z1e=20222662487959506e-37,eCe=20222662487111665e-37,tCe=84784276603689e-45,Mn=[0,0];function uE(i,e){let t=i*j1e+y7-y7,n=t|0,r=i-t*zC,o=t*$m,s=r-o,a=e>>>20,l=Qt(s)>>>20&2047;if(a-l>16){let c=r;o=t*J1e,r=c-o,o=t*Z1e-(c-r-o),s=r-o,l=Qt(s)>>>20&2047,a-l>49&&(c=r,o=t*eCe,r=c-o,o=t*tCe-(c-r-o),s=r-o);}return Mn[0]=s,Mn[1]=r-s-o,n}function dE(i,e,t){if(e===0){let o=i-t*zC,s=o-t*$m;return Mn[0]=s,Mn[1]=o-s-t*$m,t}let n=i+t*zC,r=n+t*$m;return Mn[0]=r,Mn[1]=n-r+t*$m,-t}function QC(i){let e=Qt(i)>>>31,t=(Qt(i)&2147483647)>>>0;if(t<=1074752122)return (t&1048575)===598523?uE(i,t):t<=1073928572?dE(i,e,1):dE(i,e,2);if(t<=1075594811)return t<=1075183036?t===1074977148?uE(i,t):dE(i,e,3):t===1075388923?uE(i,t):dE(i,e,4);if(t<1094263291)return uE(i,t);if(t>=2146435072)return Mn[0]=i-i,Mn[1]=Mn[0],0;let n=Ga((Qt(i)&1048575|1046<<20)>>>0,vs(i)),r=[0,0,0];for(let l=0;l<2;l++)r[l]=n|0,n=(n-r[l])*hE;r[2]=n;let o=2;for(;o!==0&&r[o]===0;)o--;let s=[0,0,0],a=$1e(r.slice(0,o+1),s,(t>>20)-1046);return e!==0?(Mn[0]=-s[0],Mn[1]=-s[1],-a):(Mn[0]=s[0],Mn[1]=s[1],a)}function x7(i){let e=(Qt(i)&2147483647)>>>0;if(e<=1072243195)return e<1045430272?i:jm(i,0,0);if(e>=2146435072)return i-i;let t=QC(i),[n,r]=Mn;switch(t&3){case 0:return jm(n,r,1);case 1:return Jm(n,r);case 2:return -jm(n,r,1);default:return -Jm(n,r)}}function v7(i){let e=(Qt(i)&2147483647)>>>0;if(e<=1072243195)return e<1044816030&&(i|0)===0?1:Jm(i,0);if(e>=2146435072)return i-i;let t=QC(i),[n,r]=Mn;switch(t&3){case 0:return Jm(n,r);case 1:return -jm(n,r,1);case 2:return -Jm(n,r);default:return jm(n,r,1)}}function R7(i){let e=(Qt(i)&2147483647)>>>0;if(e<=1072243195)return e<1044381696?i:f7(i,0,0);if(e>=2146435072)return i-i;let t=QC(i);return f7(Mn[0],Mn[1],t&1)}var A7=[.4636476090008061,.7853981633974483,.982793723247329,1.5707963267948966],nCe=[22698777452961687e-33,3061616997868383e-32,13903311031230998e-33,6123233995736766e-32],Pi=[.3333333333333293,-0.19999999999876483,.14285714272503466,-0.11111110405462356,.09090887133436507,-0.0769187620504483,.06661073137387531,-0.058335701337905735,.049768779946159324,-0.036531572744216916,.016285820115365782];function pE(i){let e=Qt(i),t=e>>>31;if(e=(e&2147483647)>>>0,e>=1141899264){if(Number.isNaN(i))return i;let c=A7[3]+Ga(0,58720256);return t!==0?-c:c}let n;if(e<1071382528){if(e<1044381696)return i;n=-1;}else i=Math.abs(i),e<1072889856?e<1072037888?(i=(2*i-1)/(2+i),n=0):(i=(i-1)/(i+1),n=1):e<1073971200?(i=(i-1.5)/(1+1.5*i),n=2):(i=-1/i,n=3);let r=i*i,o=r*r,s=r*(Pi[0]+o*(Pi[2]+o*(Pi[4]+o*(Pi[6]+o*(Pi[8]+o*Pi[10]))))),a=o*(Pi[1]+o*(Pi[3]+o*(Pi[5]+o*(Pi[7]+o*Pi[9]))));if(n<0)return i-i*(s+a);let l=A7[n]-(i*(s+a)-nCe[n]-i);return t!==0?-l:l}var hr=3.141592653589793,b7=12246467991473532e-32;function S7(i,e){if(Number.isNaN(e)||Number.isNaN(i))return e+i;let t=Qt(e),n=vs(e),r=Qt(i),o=vs(i);if((t-1072693248>>>0|n)===0)return pE(i);let s=r>>>31&1|t>>>30&2;if(t=(t&2147483647)>>>0,r=(r&2147483647)>>>0,(r|o)===0)return s===0||s===1?i:s===2?hr:-hr;if((t|n)===0)return s&1?-hr/2:hr/2;if(t===2146435072)return r===2146435072?s===0?hr/4:s===1?-hr/4:s===2?3*hr/4:-3*hr/4:s===0?0:s===1?-0:s===2?hr:-hr;if(t+(64<<20)>>>0<r||r===2146435072)return s&1?-hr/2:hr/2;let a=s&2&&r+(64<<20)>>>0<t?0:pE(Math.abs(i/e));return s===0?a:s===1?-a:s===2?hr-(a-b7):a-b7-hr}var Ua=1.5707963267948966,mE=6123233995736766e-32,rCe=.16666666666666666,iCe=-0.3255658186224009,oCe=.20121253213486293,sCe=-0.04005553450067941,aCe=.0007915349942898145,lCe=3479331075960212e-20,cCe=-2.403394911734414,uCe=2.0209457602335057,dCe=-0.6882839716054533,hCe=.07703815055590194;function Zm(i){let e=i*(rCe+i*(iCe+i*(oCe+i*(sCe+i*(aCe+i*lCe))))),t=1+i*(cCe+i*(uCe+i*(dCe+i*hCe)));return e/t}function T7(i){let e=Qt(i),t=(e&2147483647)>>>0;if(t>=1072693248){let a=vs(i);return (t-1072693248>>>0|a)===0?i*Ua+Ga(946864128,0):0/(i-i)}if(t<1071644672)return t>=1048576&&t<1045430272?i:i+i*Zm(i*i);let n=(1-Math.abs(i))*.5,r=Math.sqrt(n),o=Zm(n),s;if(t>=1072640819)s=Ua-(2*(r+r*o)-mE);else {let a=Fi(r,0),l=(n-a*a)/(r+a);s=.5*Ua-(2*r*o-(mE-2*l)-(.5*Ua-2*a));}return e>>>31?-s:s}function w7(i){let e=Ga(946864128,0),t=Qt(i),n=(t&2147483647)>>>0;if(n>=1072693248){let c=vs(i);return (n-1072693248>>>0|c)===0?t>>>31?2*Ua+e:0:0/(i-i)}if(n<1071644672)return n<=1012924416?Ua+e:Ua-(i-(mE-i*Zm(i*i)));if(t>>>31){let c=(1+i)*.5,u=Math.sqrt(c),d=Zm(c)*u-mE;return 2*(Ua-(u+d))}let r=(1-i)*.5,o=Math.sqrt(r),s=Fi(o,0),a=(r-s*s)/(o+s),l=Zm(r)*o+a;return 2*(s+l)}var I7=.6931471803691238,O7=19082149292705877e-26,pCe=1.4426950408889634,C7=.16666666666666602,N7=-0.0027777777777015593,k7=6613756321437934e-20,L7=-16533902205465252e-22,M7=41381367970572385e-24;function D7(i){let e=Ga(2145386496,0),t=Qt(i),n=t>>>31;if(t=(t&2147483647)>>>0,t>=1082532651){if(Number.isNaN(i))return i;if(i>709.782712893384)return i*e;if(i<-708.3964185322641&&i<-745.1332191019411)return 0}let r,o,s;if(t>1071001154)t>=1072734898?r=pCe*i+(n===0?.5:-0.5)|0:r=1-n-n,o=i-r*I7,s=r*O7,i=o-s;else if(t>1043333120)r=0,o=i,s=0;else return 1+i;let a=i*i,l=i-a*(C7+a*(N7+a*(k7+a*(L7+a*M7)))),c=1+(i*l/(2-l)-s+o);return r===0?c:Sd(c,r)}var P7=.6666666666666735,F7=.3999999999940942,U7=.2857142874366239,B7=.22222198432149784,G7=.1818357216161805,V7=.15313837699209373,H7=.14798198605116586,mCe=0x40000000000000;function W7(i){let e=Qt(i),t=0;if(e<1048576||e>>>31){if(i===0)return -1/(i*i);if(e>>>31)return (i-i)/0;t-=54,i*=mCe,e=Qt(i);}else {if(e>=2146435072)return i;if(e===1072693248&&vs(i)===0)return 0}return e=e+614242>>>0,t+=(e>>>20)-1023,e=(e&1048575)+1072079006>>>0,{f:qC(i,e)-1,k:t}}function K7(i){let e=W7(i);if(typeof e=="number")return e;let{f:t,k:n}=e,r=.5*t*t,o=t/(2+t),s=o*o,a=s*s,l=a*(F7+a*(B7+a*V7)),u=s*(P7+a*(U7+a*(G7+a*H7)))+l,d=n;return o*(r+u)+d*O7-r+t+d*I7}var g7=1.4426950407214463,fCe=16751713164886512e-26;function Y7(i){let e=W7(i);if(typeof e=="number")return e;let{f:t,k:n}=e,r=.5*t*t,o=t/(2+t),s=o*o,a=s*s,l=a*(F7+a*(B7+a*V7)),u=s*(P7+a*(U7+a*(G7+a*H7)))+l,d=Fi(t-r,0),h=t-d-r+o*(r+u),p=d*g7,m=(h+d)*fCe+h*g7,f=n;return a=f+p,m+=f-a+p,p=a,m+p}var XC=[1,1.5],E7=[0,.5849624872207642],_Ce=[0,1350039202129749e-23],yCe=9007199254740992,hi=1e300,pi=1e-300,ACe=.5999999999999946,bCe=.4285714285785502,gCe=.33333332981837743,ECe=.272728123808534,xCe=.23066074577556175,vCe=.20697501780033842,RCe=.6931471805599453,SCe=.6931471824645996,TCe=-1.904654299957768e-9,wCe=8008566259537294e-32,ICe=.9617966939259756,OCe=.9617967009544373,CCe=-7.028461650952758e-9,NCe=1.4426950408889634,kCe=1.4426950216293335,LCe=19259629911266175e-24;function X7(i,e){let t=Qt(i)|0,n=vs(i),r=Qt(e)|0,o=vs(e),s=t&2147483647,a=r&2147483647;if((a|o)===0||t===1072693248&&n===0)return 1;if(s>2146435072||s===2146435072&&n!==0||a>2146435072||a===2146435072&&o!==0)return i+e;let l=0,c,u;if(t<0&&(a>=1128267776?l=2:a>=1072693248&&(c=(a>>20)-1023,c>20?(u=o>>>52-c|0,u<<52-c===(o|0)&&(l=2-(u&1))):o===0&&(u=a>>20-c,u<<20-c===a&&(l=2-(u&1))))),o===0){if(a===2146435072)return (s-1072693248|n)===0?1:s>=1072693248?r>=0?e:0:r>=0?0:-e;if(a===1072693248)return r>=0?i:1/i;if(r===1073741824)return i*i;if(r===1071644672&&t>=0)return Math.sqrt(i)}let d=Math.abs(i);if(n===0&&(s===2146435072||s===0||s===1072693248)){let L=d;return r<0&&(L=1/L),t<0&&((s-1072693248|l)===0?L=(L-L)/(L-L):l===1&&(L=-L)),L}let h=1;if(t<0){if(l===0)return (i-i)/(i-i);l===1&&(h=-1);}let p,m;if(a>1105199104){if(a>1139802112){if(s<=1072693247)return r<0?hi*hi:pi*pi;if(s>=1072693248)return r>0?hi*hi:pi*pi}if(s<1072693247)return r<0?h*hi*hi:h*pi*pi;if(s>1072693248)return r>0?h*hi*hi:h*pi*pi;let L=d-1,k=L*L*(.5-L*(.3333333333333333-L*.25)),M=kCe*L,K=L*LCe-k*NCe;p=Fi(M+K,0),m=K-(p-M);}else {let L=0;s<1048576&&(d*=yCe,L-=53,s=Qt(d)|0),L+=(s>>20)-1023,u=s&1048575;let k;s=u|1072693248,u<=235662?k=0:u<767610?k=1:(k=0,L+=1,s-=1048576),d=qC(d,s>>>0);let M=d-XC[k],K=1/(d+XC[k]),Y=M*K,te=Fi(Y,0),Z=Ga((s>>>1|536870912)+524288+(k<<18)>>>0,0),de=d-(Z-XC[k]),Oe=K*(M-te*Z-te*de),be=Y*Y,ke=be*be*(ACe+be*(bCe+be*(gCe+be*(ECe+be*(xCe+be*vCe)))));ke+=Oe*(te+Y),be=te*te,Z=Fi(3+be+ke,0),de=ke-(Z-3-be);let De=te*Z,Fe=Oe*Z+de*Y,Ze=Fi(De+Fe,0),wt=Fe-(Ze-De),q=OCe*Ze,he=CCe*Ze+wt*ICe+_Ce[k],ot=L;p=Fi(q+he+E7[k]+ot,0),m=he-(p-ot-E7[k]-q);}let f=Fi(e,0),y=(e-f)*p+e*m,b=f*p,A=y+b,E=Qt(A)|0,R=vs(A)|0;if(E>=1083179008){if((E-1083179008|R)!==0||y+wCe>A-b)return h*hi*hi}else if((E&2147483647)>=1083231232&&(((E>>>0)-3230714880|R)!==0||y<=A-b))return h*pi*pi;let g=E&2147483647;c=(g>>20)-1023;let v=0;if(g>1071644672){v=E+(1048576>>c+1)|0,c=((v&2147483647)>>20)-1023;let L=Ga((v&~(1048575>>c))>>>0,0);v=(v&1048575|1048576)>>20-c,E<0&&(v=-v),b-=L;}let x=Fi(y+b,0),O=x*SCe,N=(y-(x-b))*RCe+x*TCe;A=O+N;let I=N-(A-O),S=A*A,w=A-S*(C7+S*(N7+S*(k7+S*(L7+S*M7))));return A=1-(A*w/(w-2)-(I+A*I)-A),E=Qt(A)|0,E=E+(v<<20)|0,E>>20<=0?A=Sd(A,v):A=qC(A,E>>>0),h*A}var DCe={F64_ADD:8192,F64_SUB:8193,F64_MUL:8194,F64_DIV:8195,F64_MIN:8196,F64_MAX:8197,F64_MOD:8198,F64_POW:8199,F64_ATAN2:8200,F64_NEG:8208,F64_ABS:8209,F64_SQRT:8210,F64_FLOOR:8211,F64_CEIL:8212,F64_ROUND:8213,F64_TRUNC:8214,F64_SIGN:8215,F64_SIN:8216,F64_COS:8217,F64_TAN:8218,F64_ASIN:8219,F64_ACOS:8220,F64_ATAN:8221,F64_EXP:8222,F64_LOG:8223,F64_LOG2:8224,F64_LT:8240,F64_LE:8241,F64_EQ:8242,F64_NE:8243,F64_FROM_F32:8256,F64_FROM_I32:8257,F64_FROM_U32:8258,F64_TO_F32:8259,F64_TO_I32:8260,F64_TO_U32:8261,F64_FROM_U64:8262,F64_TO_U64:8263,BIT_POPCNT:8448,BIT_CLZ:8449,BIT_CTZ:8450,BIT_ROTL:8451,BIT_ROTR:8452,BIT_EXTRACT:8453,BIT_INSERT:8454,BIT_MORTON2:8455,BIT_MORTON3:8456,BIT_UNMORTON2:8457,BIT_UNMORTON3:8458,BIT64_POPCNT:8464,BIT64_CLZ:8465,BIT64_CTZ:8466,BIT64_ROTL:8467,BIT64_ROTR:8468,BIT64_EXTRACT:8469,BIT64_INSERT:8470,BIT64_MORTON2:8471,BIT64_MORTON3:8472,BIT64_UNMORTON2:8473,BIT64_UNMORTON3:8474,U64_SHL:8480,U64_SHR:8481,U64_MUL:8482,U64_DIV:8483,U64_REM:8484},PCe=8,JC=2143289344,W=DCe,Ss=1,tf=2,ef=4,n9=8,FCe=16,pc=Ss|tf,fE=Ss|tf|ef|n9,$C=4294967296,UCe=18446744073709552e3,yE=(1n<<64n)-1n;function gE(i){if(i>=W.F64_ADD&&i<=W.F64_ATAN2||i>=W.U64_MUL&&i<=W.U64_REM)return [fE,2];if(i===W.U64_SHL||i===W.U64_SHR)return [pc|ef,2];if(i>=W.F64_NEG&&i<=W.F64_LOG2||i===W.F64_FROM_U64||i===W.F64_TO_U64)return [pc,2];if(i>=W.F64_LT&&i<=W.F64_NE)return [fE,1];if(i>=W.F64_FROM_F32&&i<=W.F64_FROM_U32)return [Ss,2];if(i>=W.F64_TO_F32&&i<=W.F64_TO_U32)return [pc,1];switch(i){case W.BIT_POPCNT:case W.BIT_CLZ:case W.BIT_CTZ:return [Ss,1];case W.BIT_ROTL:case W.BIT_ROTR:case W.BIT_MORTON2:return [Ss|tf,1];case W.BIT_EXTRACT:case W.BIT_MORTON3:return [Ss|tf|ef,1];case W.BIT_INSERT:return [Ss|tf|ef|n9,1];case W.BIT_UNMORTON2:return [Ss,2];case W.BIT_UNMORTON3:return [Ss,3];case W.BIT64_POPCNT:case W.BIT64_CLZ:case W.BIT64_CTZ:return [pc,1];case W.BIT64_ROTL:case W.BIT64_ROTR:case W.BIT64_MORTON3:return [pc|ef,2];case W.BIT64_EXTRACT:return [fE,2];case W.BIT64_INSERT:return [fE|FCe,2];case W.BIT64_MORTON2:case W.BIT64_UNMORTON2:return [pc,2];case W.BIT64_UNMORTON3:return [pc,3];default:return null}}var ZC=new Float64Array(1),AE=new Uint32Array(ZC.buffer),jC=new Float32Array(1),q7=new Uint32Array(jC.buffer);function Io(i,e){return AE[0]=i>>>0,AE[1]=e>>>0,ZC[0]}function wd(i,e){if(Number.isNaN(i)){e[0]=0,e[1]=2146959360;return}ZC[0]=i,e[0]=AE[0],e[1]=AE[1];}function mc(i,e){return BigInt(e>>>0)<<32n|BigInt(i>>>0)}function Rs(i,e){let t=i&yE;e[0]=Number(t&0xffffffffn),e[1]=Number(t>>32n);}function BCe(i,e){return Number.isNaN(i)||Number.isNaN(e)?Number.NaN:i===e?Object.is(i,-0)||Object.is(e,-0)?-0:i:i<e?i:e}function GCe(i,e){return Number.isNaN(i)||Number.isNaN(e)?Number.NaN:i===e?Object.is(i,0)||Object.is(e,0)?0:i:i>e?i:e}function VCe(i,e){return Number.isNaN(e)||Math.abs(i)===1&&!Number.isFinite(e)?Number.NaN:X7(i,e)}function HCe(i){if(!Number.isFinite(i)||i===0)return i;let e=Math.floor(i),t=i-e>=.5?e+1:e;return t===0&&i<0?-0:t}function WCe(i){return i>0?1:i<0?-1:i}function r9(i){if(!Number.isFinite(i))return 0;let e=Math.trunc(i)%$C;return (e<0?e+$C:e)>>>0}function e2(i){if(!Number.isFinite(i))return 0n;let e=Math.trunc(i),t=BigInt(Math.abs(e)%UCe);return e<0?-t&yE:t}function KCe(i,e,t){switch(i){case W.F64_ADD:return e+t;case W.F64_SUB:return e-t;case W.F64_MUL:return e*t;case W.F64_DIV:return e/t;case W.F64_MIN:return BCe(e,t);case W.F64_MAX:return GCe(e,t);case W.F64_MOD:return e%t;case W.F64_POW:return VCe(e,t);default:return S7(e,t)}}function YCe(i,e){switch(i){case W.F64_NEG:return -e;case W.F64_ABS:return Math.abs(e);case W.F64_SQRT:return Math.sqrt(e);case W.F64_FLOOR:return Math.floor(e);case W.F64_CEIL:return Math.ceil(e);case W.F64_ROUND:return HCe(e);case W.F64_TRUNC:return Math.trunc(e);case W.F64_SIGN:return WCe(e);case W.F64_SIN:return x7(e);case W.F64_COS:return v7(e);case W.F64_TAN:return R7(e);case W.F64_ASIN:return T7(e);case W.F64_ACOS:return w7(e);case W.F64_ATAN:return pE(e);case W.F64_EXP:return D7(e);case W.F64_LOG:return K7(e);default:return Y7(e)}}function bE(i,e){return i>=e?(1n<<BigInt(e))-1n:(1n<<BigInt(i))-1n}function z7(i,e,t,n){return i>>BigInt(e&n-1)&bE(t>>>0,n)}function Q7(i,e,t,n,r){let o=BigInt(t&r-1),s=bE(n>>>0,r)<<o;return (i&~s|e<<o&s)&bE(r,r)}function To(i,e,t){let n=0n;for(let r=0;r<e;r++)n|=(i>>BigInt(r)&1n)<<BigInt(r*t);return n}function wo(i,e,t,n){let r=0n;for(let o=0;o<e;o++)r|=(i>>BigInt(o*t+n)&1n)<<BigInt(o);return r}function $7(i){let e=0;for(;i>0n;)e+=Number(i&1n),i>>=1n;return e}function j7(i,e){let t=0;for(let n=e-1;n>=0&&(i>>BigInt(n)&1n)===0n;n--)t++;return t}function J7(i,e){let t=0;for(let n=0;n<e&&(i>>BigInt(n)&1n)===0n;n++)t++;return t}function _E(i,e,t){let n=BigInt(e&t-1),r=bE(t,t);return (i<<n|i>>BigInt(t)-n)&r}function Z7(i,e,t){switch(i){case W.U64_SHL:return e<<(t&63n)&yE;case W.U64_SHR:return e>>(t&63n);case W.U64_MUL:return e*t&yE;case W.U64_DIV:return t===0n?0n:e/t;default:return t===0n?0n:e%t}}var e9=new Uint32Array(5),t9=new Uint32Array(3);function i9(i,e,t,n,r,o){let s=gE(i);if(s===null)return;let[a,l]=s;for(let c=0;c<n;c++){for(let u=0;u<5;u++)e9[u]=a&1<<u?r(e[u],c):0;t2(i,e9,t9);for(let u=0;u<l;u++)o(t[u],c,t9[u]);}}function t2(i,e,t){t[0]=0,t[1]=0,t[2]=0;let n=c=>{t[0]=Number(c)>>>0;};if(i>=W.F64_ADD&&i<=W.F64_ATAN2)return wd(KCe(i,Io(e[0],e[1]),Io(e[2],e[3])),t);if(i>=W.U64_MUL&&i<=W.U64_REM)return Rs(Z7(i,mc(e[0],e[1]),mc(e[2],e[3])),t);if(i===W.U64_SHL||i===W.U64_SHR)return Rs(Z7(i,mc(e[0],e[1]),BigInt(e[2])),t);if(i>=W.F64_NEG&&i<=W.F64_LOG2)return wd(YCe(i,Io(e[0],e[1])),t);if(i===W.F64_FROM_U64)return wd(e[1]*$C+e[0],t);if(i===W.F64_TO_U64)return Rs(e2(Io(e[0],e[1])),t);if(i>=W.F64_LT&&i<=W.F64_NE){let c=Io(e[0],e[1]),u=Io(e[2],e[3]),d=i===W.F64_LT?c<u:i===W.F64_LE?c<=u:i===W.F64_EQ?c===u:c!==u;t[0]=d?4294967295:0;return}if(i===W.F64_FROM_F32)return q7[0]=e[0],wd(jC[0],t);if(i===W.F64_FROM_I32)return wd(e[0]|0,t);if(i===W.F64_FROM_U32)return wd(e[0]>>>0,t);if(i===W.F64_TO_F32){let c=Math.fround(Io(e[0],e[1]));Number.isNaN(c)?t[0]=JC:(jC[0]=c,t[0]=q7[0]);return}if(i===W.F64_TO_I32||i===W.F64_TO_U32)return n(r9(Io(e[0],e[1])));let r=BigInt(e[0]),o=BigInt(e[1]),s=BigInt(e[2]),a=mc(e[0],e[1]),l=mc(e[2],e[3]);switch(i){case W.BIT_POPCNT:return n($7(r));case W.BIT_CLZ:return n(j7(r,32));case W.BIT_CTZ:return n(J7(r,32));case W.BIT_ROTL:return n(_E(r,e[1],32));case W.BIT_ROTR:return n(_E(r,32-(e[1]&31)&31,32));case W.BIT_EXTRACT:return n(z7(r,e[1],e[2],32));case W.BIT_INSERT:return n(Q7(r,o,e[2],e[3],32));case W.BIT_MORTON2:return n(To(r,16,2)|To(o,16,2)<<1n);case W.BIT_MORTON3:return n(To(r,10,3)|To(o,10,3)<<1n|To(s,10,3)<<2n);case W.BIT_UNMORTON2:t[0]=Number(wo(r,16,2,0)),t[1]=Number(wo(r,16,2,1));return;case W.BIT_UNMORTON3:t[0]=Number(wo(r,10,3,0)),t[2]=Number(wo(r,10,3,1)),t[1]=Number(wo(r,10,3,2));return;case W.BIT64_POPCNT:return n($7(a));case W.BIT64_CLZ:return n(j7(a,64));case W.BIT64_CTZ:return n(J7(a,64));case W.BIT64_ROTL:return Rs(_E(a,e[2],64),t);case W.BIT64_ROTR:return Rs(_E(a,64-(e[2]&63)&63,64),t);case W.BIT64_EXTRACT:return Rs(z7(a,e[2],e[3],64),t);case W.BIT64_INSERT:return Rs(Q7(a,l,e[4]&255,e[4]>>>PCe,64),t);case W.BIT64_MORTON2:return Rs(To(r,32,2)|To(o,32,2)<<1n,t);case W.BIT64_MORTON3:return Rs(To(r,21,3)|To(o,21,3)<<1n|To(s,21,3)<<2n,t);case W.BIT64_UNMORTON2:t[0]=Number(wo(a,32,2,0)),t[1]=Number(wo(a,32,2,1));return;case W.BIT64_UNMORTON3:t[0]=Number(wo(a,21,3,0)),t[2]=Number(wo(a,21,3,1)),t[1]=Number(wo(a,21,3,2));return}}var XCe=4294967295,qCe=16;var fc=4,zCe=8192,QCe=256,EE=0,a9=1,$Ce=2;function o9(i){let e=i>>>0;return e^=e>>>16,e=Math.imul(e,2146121005),e^=e>>>15,e=Math.imul(e,2221713035),(e^e>>>16)>>>0}function Id(i){return i>>>IC&OC}function s9(i){return (i&YX)!==0}function Ts(i,e,t){return i===0?e===EE?mt(t):mt(Math.fround(e===a9?t|0:t>>>0)):i===3?t!==0&&!Number.isNaN(t)?XCe:0:e===EE?(t|0)>>>0:t>>>0}function nf(i,e,t){return e===EE?i===0?Ye(t):i===3?t!==0?1:0:Math.fround(i===1?t|0:t>>>0):i===0?Ye(t)|0:i===3?t!==0?1:0:t}function jCe(i,e){return i.values===e.values||i.values.buffer===e.values.buffer&&i.values.byteOffset===e.values.byteOffset&&i.values.length>0}function JCe(i,e){return i===0?e===EE:i===1||i===2?e===a9||e===$Ce:false}function ZCe(i,e){return i<e?i:e<i?e:Number.isNaN(i)?i:e}function e2e(i,e){return i>e?i:e>i?e:Number.isNaN(i)?i:e}function t2e(i,e,t){let n=Ye,r=mt;switch(i){case kr.FADD:return r(Math.fround(n(e)+n(t)));case kr.FMUL:return r(Math.fround(n(e)*n(t)));case kr.FMIN:return r(ZCe(n(e),n(t)));case kr.FMAX:return r(e2e(n(e),n(t)));case kr.IADD:return e+t>>>0;case kr.IMIN:return Math.min(e|0,t|0)>>>0;case kr.IMAX:return Math.max(e|0,t|0)>>>0;case kr.UMIN:return Math.min(e>>>0,t>>>0);case kr.UMAX:return Math.max(e>>>0,t>>>0);case kr.OR:return (e|t)>>>0;case kr.AND:return (e&t)>>>0;default:return t>>>0}}function n2e(i,e){return i===XX?e>>>0:Number.isNaN(Ye(e))?4294967295:qg(MC,e)}var xE=class{constructor(e){this.capacity=e;this.epoch=0;let t=qCe;for(;t<e*2;)t*=2;this.keys=new Uint32Array(t),this.rows=new Uint32Array(t),this.stamps=new Uint32Array(t),this.mask=t-1;}build(e,t){this.epoch=this.epoch+1>>>0,this.epoch===0&&(this.stamps.fill(0),this.epoch=1);let n=Math.min(e,this.capacity);for(let r=0;r<n;r++){let o=t(r)>>>0;if(o===4294967295)continue;let s=o9(o)&this.mask;for(;;){if(this.stamps[s]!==this.epoch){this.stamps[s]=this.epoch,this.keys[s]=o,this.rows[s]=r;break}if(this.keys[s]===o)break;s=s+1&this.mask;}}}find(e){let t=e>>>0;if(t===4294967295)return 4294967295;let n=o9(t)&this.mask;for(;;){if(this.stamps[n]!==this.epoch)return 4294967295;if(this.keys[n]===t)return this.rows[n];n=n+1&this.mask;}}},rf=class{constructor(e,t){this.capacity=e;this.words=t;this.len=0;this.dropped=0;this.heaped=false;this.a=new Float64Array(e),this.b=new Float64Array(e),this.c=new Float64Array(e),this.data=new Uint32Array(e*t),this.heap=new Uint32Array(e);}clear(){this.len=0,this.dropped=0,this.heaped=false;}compare(e,t){return this.a[e]-this.a[t]||this.b[e]-this.b[t]||this.c[e]-this.c[t]}below(e,t,n,r){return e!==this.a[r]?e<this.a[r]:t!==this.b[r]?t<this.b[r]:n<this.c[r]}siftDown(e){let t=this.heap.length,n=e;for(;;){let r=2*n+1,o=r+1,s=n;if(r<t&&this.compare(this.heap[r],this.heap[s])>0&&(s=r),o<t&&this.compare(this.heap[o],this.heap[s])>0&&(s=o),s===n)return;let a=this.heap[n];this.heap[n]=this.heap[s],this.heap[s]=a,n=s;}}insert(e,t,n,r){let o;if(this.len<this.capacity)o=this.len++;else {if(this.dropped++,this.capacity===0)return;if(!this.heaped){for(let a=0;a<this.capacity;a++)this.heap[a]=a;for(let a=(this.capacity>>1)-1;a>=0;a--)this.siftDown(a);this.heaped=true;}let s=this.heap[0];if(!this.below(e,t,n,s))return;o=s;}if(this.a[o]=e,this.b[o]=t,this.c[o]=n,r!==null)for(let s=0;s<this.words;s++)this.data[o*this.words+s]=r[s];this.heaped&&this.siftDown(0);}},vE=class{constructor(e,t,n,r){this.at=e;this.len=t;this.table=n;this.k=r;this.used=new Uint8Array(0);this.blocks=0;this.unplaced=0;}bind(e){this.blocks=e,this.used=new Uint8Array(e);}run(e,t,n,r){this.used.fill(0),this.unplaced=0;let o=(c,u)=>Ts(2,c.storage,c.values[u]),s=(c,u,d,h)=>{c.values[d]=nf(u,c.storage,h);},a=false;for(let c=0;c<r;c++){let u=o(e,c);if(u===0){a=true;continue}let d=u-1,h=Math.floor(d/this.k);if(d%this.k===0&&h<this.blocks&&this.used[h]===0){this.used[h]=1,o(t,c)>this.k&&s(t,n,c,this.k);continue}s(e,2,c,0),s(t,n,c,0),a=true;}if(!a)return;let l=0;for(let c=0;c<r;c++)if(o(e,c)===0){for(;l<this.blocks&&this.used[l]!==0;)l++;if(s(t,n,c,0),l===this.blocks){this.unplaced++;continue}this.used[l]=1,s(e,2,c,l*this.k+1),l++;}}};function l9(i){let e=[],t=0;for(;t+1<i.length;){let n=i[t];if(n.op===Ve){Di(n.dst)===An.DATA&&e.push({pc:t,i:n,ext:i[t+1]}),t+=2;continue}t++;}return e}function r2e(i){return l9(i).filter(e=>e.i.dst===Hm).map(e=>({at:e.i.a,len:e.i.b,pool:e.i.c,k:e.ext.a}))}var RE=class{constructor(e,t,n){this.slots=e;this.code=t;this.tableCapacity=new Array(xs).fill(0);this.tableCount=new Array(xs).fill(0);this.bound=new Array(xs).fill(false);this.used=1;this.snaps=new Map;this.indexes=new Map;this.pools=new Map;this.sweeps=[];this.sites=[];this.commandCapacity=zCe;this.pickCapacity=QCe;this.counter=0;this.tallies=new Uint32Array(uc);this.stats={sent:0,applied:0,dropped:0,overflow:0};this.payload=new Uint32Array(fc);let r=l9(t);this.active=r.length>0,e.forEach((o,s)=>{let a=o.word??0,l=Id(a);this.used|=1<<l,l!==0&&!s9(a)&&(a&256)!==0&&this.snaps.set(s,{table:l,values:new Float64Array(0),active:false});});for(let o of r2e(t)){if(this.pools.has(o.pool))continue;let s=Id(e[o.pool].word??0),a=this.sweeps.findIndex(l=>l.at===o.at&&l.len===o.len);a<0&&(this.sweeps.push(new vE(o.at,o.len,s,o.k)),a=this.sweeps.length-1),this.pools.set(o.pool,{decl:o,words:0,bound:false,sweep:a});}for(let{pc:o,i:s}of r)s.dst===fd?(this.used|=1<<s.b,this.indexes.has(s.c)||this.indexes.set(s.c,{table:s.b,index:new xE(0)})):s.dst===_d?this.used|=1<<s.b:s.dst===yd?this.used|=1<<s.a:s.dst===bd&&this.sites.push({pc:o,n:s.a,rows:new Uint32Array(0),len:0});this.commands=new rf(this.commandCapacity,fc),this.picks=[],this.bindPicks(this.pickCapacity),this.bindStorage(0,n),this.tableCapacity[0]=n,this.bound[0]=true;}bindStorage(e,t){for(let n of this.snaps.values())n.table===e&&(n.values=new Float64Array(t));for(let n of this.indexes.values())n.table===e&&(n.index=new xE(t));}get tablesUsed(){return this.used}get poolDecls(){return [...this.pools.values()].map(e=>e.decl)}get unplaced(){return this.sweeps.reduce((e,t)=>e+t.unplaced,0)}bindTable(e,t){if(e<1||e>=xs)throw new _("invalid_argument",`kernel tables are numbered 1..${xs-1}`);this.tableCapacity[e]=t,this.bound[e]=true,this.bindStorage(e,t);}bindPool(e,t){let n=this.pools.get(e);if(n===void 0)throw new _("invalid_argument",`slot ${e} is not a list pool`);n.words=t,n.bound=true;let r=this.sweeps[n.sweep],o=1/0;for(let s of this.pools.values())s.sweep===n.sweep&&(o=Math.min(o,s.bound?Math.floor(s.words/r.k):1/0));o!==1/0&&r.bind(o);}bindCommands(e){this.commandCapacity=e,this.commands=new rf(e,fc);}bindPicks(e){this.pickCapacity=e,this.picks=this.sites.map(()=>new rf(e,0));for(let t of this.sites)t.rows=new Uint32Array(e);}setCount(e,t){if(t>this.tableCapacity[e])throw new _("capacity_exceeded",`table ${e} holds ${t} rows but was bound with capacity ${this.tableCapacity[e]}`);this.tableCount[e]=t;}count(e){return this.tableCount[e]}pickRows(e){let t=this.sites[e];return t===void 0?new Uint32Array(0):t.rows.subarray(0,t.len)}prepare(e,t){if(this.active){this.tableCount[0]=t;for(let n=1;n<xs;n++)if((this.used&1<<n)!==0&&!this.bound[n])throw new _("invalid_argument",`this kernel reads table ${n}, which is not bound; pass the table as its Rows argument`);for(let[n,r]of this.pools)if(!r.bound)throw new _("invalid_argument",`list pool slot ${n} is not bound`);for(let[n,r]of this.snaps){let o=e[n];if(r.active=this.slots.some((s,a)=>Id(s.word??0)===0&&!s9(s.word??0)&&((s.word??0)&512)!==0&&jCe(e[a],o)),r.active){let s=this.tableCount[r.table];for(let a=0;a<s;a++)r.values[a]=o.values[a];}}for(let n of this.sweeps)n.run(e[n.at],e[n.len],this.slots[n.len].kind,this.tableCount[n.table]);for(let[n,r]of this.indexes){let o=e[n],s=this.slots[n].kind;r.index.build(this.tableCount[r.table],a=>Ts(s,o.storage,o.values[a]));}this.commands.clear();for(let n of this.picks)n.clear();this.tallies.fill(0),this.counter=0,this.stats={sent:0,applied:0,dropped:0,overflow:0};}}exec(e,t,n,r,o,s){let a=(l,c)=>l===4294967295||s.lane(l,c)!==0;switch(t.dst){case fd:{let l=this.indexes.get(t.c).index;for(let c=0;c<r;c++)s.set(n.dst,c,l.find(s.lane(t.a,c)));return}case _d:{let l=this.tableCount[t.b];for(let c=0;c<r;c++){let u=s.lane(t.a,c)>>>0;s.set(n.dst,c,u<l?u:4294967295);}return}case Vm:{let l=this.slots[t.a],c=o[t.a],u=this.tableCount[Id(l.word??0)],d=this.snaps.get(t.a),h=d!==void 0&&d.active?d.values:c.values;for(let p=0;p<r;p++){let m=s.lane(t.b,p)>>>0;s.set(n.dst,p,m<u?Ts(l.kind,c.storage,h[m]):0);}return}case yd:{let l=this.tableCount[t.a];for(let c=0;c<r;c++)s.set(n.dst,c,l);return}case Wm:case Ad:{let l=this.pools.get(t.a),c=o[l.decl.at],u=o[t.a],d=this.slots[t.a].kind,h=t.dst===Ad,p=h?n.a:t.c;for(let m=0;m<r;m++){let f=0;if(a(p,m)){let y=Ts(2,c.storage,c.values[s.row(m)]),b=s.lane(t.b,m)>>>0,A=y-1+b;y!==0&&b<l.decl.k&&A<l.words&&(h?u.values[A]=nf(d,u.storage,s.lane(t.c,m)):f=Ts(d,u.storage,u.values[A]));}h||s.set(n.dst,m,f);}return}case Km:{let l=0;for(let c=0;c<r;c++)a(t.b,c)&&l++;this.tallies[t.a]=this.tallies[t.a]+l>>>0;return}case Ym:{let l=this.tableCount[Id(this.slots[t.a].word??0)];for(let c=0;c<r;c++){let u=s.lane(t.b,c)>>>0;!a(n.a,c)||u>=l||(this.payload[0]=t.a,this.payload[1]=n.b,this.payload[2]=u,this.payload[3]=s.lane(t.c,c),this.commands.insert(s.row(c),this.counter++,0,this.payload));}return}case bd:{let l=this.sites.findIndex(u=>u.pc===e),c=this.picks[l];for(let u=0;u<r;u++)a(t.c,u)&&c.insert(n2e(n.a,s.lane(t.b,u)),s.row(u),0,null);return}default:return}}finish(e,t){this.active&&(this.finishCommands(e),this.sites.forEach((n,r)=>{let o=this.picks[r],s=Array.from({length:o.len},(c,u)=>u).sort((c,u)=>o.compare(c,u)),a=Math.max(t[n.n&2147483647]|0,0),l=Math.min(a,s.length,n.rows.length);for(let c=0;c<l;c++)n.rows[c]=o.b[s[c]];n.len=l;}));}finishCommands(e){let t=this.commands,n=t.len+t.dropped;if(t.len===0)return;let r=a=>Id(this.slots[t.data[a*fc]].word??0),o=Array.from({length:t.len},(a,l)=>l);o.sort((a,l)=>r(a)-r(l)||t.data[a*fc+2]-t.data[l*fc+2]||t.compare(a,l));let s=0;for(let a of o){let l=a*fc,c=t.data[l],u=t.data[l+1],d=t.data[l+2],h=t.data[l+3],p=this.slots[c].kind,m=e[c];if(u===kr.PUSH){let b=this.pools.get(c),A=e[b.decl.at],E=e[b.decl.len],R=Ts(2,A.storage,A.values[d]),g=Ts(2,E.storage,E.values[d]),v=R-1+g;if(R===0||g>=b.decl.k||v>=b.words){s++;continue}m.values[v]=nf(p,m.storage,h),E.values[d]=nf(this.slots[b.decl.len].kind,E.storage,g+1);continue}let f=Ts(p,m.storage,m.values[d]),y=t2e(u,f,h);(JCe(p,m.storage)||f!==y)&&(m.values[d]=nf(p,m.storage,y));}this.stats={sent:n,applied:t.len-s,dropped:n-t.len,overflow:s};}};var sf=4294967295,Ui=4294967295;function i2e(i,e){return i-e}function r2(i){return i.width*i.height*i.depth}var c9=new Uint32Array(6),o2e=new Uint32Array(7);function n2(i,e,t){let n=i.width,r=i.height,o=e%n,s=Math.floor(e/n)%r,a=Math.floor(e/(n*r)),l=0;return o>0&&(t[l++]=e-1),o+1<n&&(t[l++]=e+1),s>0&&(t[l++]=e-n),s+1<r&&(t[l++]=e+n),a>0&&(t[l++]=e-n*r),a+1<i.depth&&(t[l++]=e+n*r),l}function wE(i,e){let t=e;for(;i[t]!==t;){let n=i[i[t]];i[t]=n,t=n;}return t}function TE(i,e,t){let n=wE(i,e),r=wE(i,t);n<r?i[r]=n:r<n&&(i[n]=r);}function s2e(i,e,t,n){let r=0;for(let o=0;o<t;o++){if(!n(o)){e[o]=Ui;continue}let s=wE(i,o);s===o&&r++,e[o]=s;}return r}function u9(i,e,t,n,r){let o=r2(i);if(e.length<o||n.length<o||r.length<o)throw new _("capacity_exceeded","grid buffers are too small");for(let l=0;l<o;l++)n[l]=l;let s=i.width,a=s*i.height;for(let l=0;l<o;l++){let c=e[l];if(c===t)continue;let u=l%s,d=Math.floor(l/s)%i.height;u+1<s&&e[l+1]===c&&TE(n,l,l+1),d+1<i.height&&e[l+s]===c&&TE(n,l,l+s),l+a<o&&e[l+a]===c&&TE(n,l,l+a);}return s2e(n,r,o,l=>e[l]!==t)}function a2e(i){i.sort(i2e);let e=Ui,t=0,n=0;for(;n<i.length;){let r=i[n],o=n+1;for(;o<i.length&&i[o]===r;)o++;r!==Ui&&o-n>t&&(e=r,t=o-n),n=o;}return e}function d9(i,e,t,n){let r=r2(i),o=c9,s=o2e;for(let a=0;a<n;a++){let l=false;for(let c=0;c<r;c++){if(e[c]===Ui){t[c]=Ui;continue}let u=n2(i,c,o);s[0]=e[c];for(let h=0;h<u;h++)s[h+1]=e[o[h]];let d=a2e(s.subarray(0,u+1));l||=d!==e[c],t[c]=d;}if(e.set(t.subarray(0,r)),!l)return a}return n}var IE=4294967295;function h9(i,e,t,n,r,o){let s=r2(i),a=r,l=c9;for(let c=0;c<a;c++){let u=n[c],d=t[u]+1,h=n2(i,u,l);for(let p=0;p<h;p++){let m=l[p];m<s&&e[m]!==IE&&t[m]===sf&&(t[m]=d,n[a++]=m);}}if(o!==null)for(let c=r;c<a;c++){let u=n[c],d=n2(i,u,l),h=Ui;for(let p=0;p<d;p++)t[l[p]]===t[u]-1&&(h=Math.min(h,o[l[p]]));o[u]=h;}return a}function p9(i,e,t){TE(i,e,t);}function m9(i,e){return wE(i,e)}var _c=4;function f9(i,e,t,n,r,o){let s=i.dst===Ed?i.c:4294967295;for(let a=0;a<n;a++){let l=(t+a)*_c;e[l]=r(i.a,a)>>>0,e[l+1]=s===4294967295?0:r(s,a)>>>0,e[l+2]=i.b===4294967295||r(i.b,a)!==0?1:0,e[l+3]=o(a);}}function l2e(i,e){let t=e&2147483647,n={width:i.uniform(2147483648|t),height:i.uniform(2147483648|t+1),depth:i.uniform(2147483648|t+2)},r=n.width*n.height*n.depth;return r>0&&r<=i.capacity?n:null}function _9(i,e,t,n,r){let o=i.capacity,s=i.buffers.subarray(0,o),a=i.buffers.subarray(o,2*o),l=i.buffers.subarray(2*o,3*o),c=i.buffers.subarray(3*o,4*o),u=f=>n[f*_c+3],d=0;if(e.dst===Ed){let f=i.uniform(t.b);if(f>o)d=4294967295;else {for(let b=0;b<f;b++)s[b]=b;for(let b=0;b<r;b++){let A=b*_c;n[A+2]!==0&&n[A]<f&&n[A+1]<f&&p9(s,n[A],n[A+1]);}let y=i.array(t.dst);for(let b=0;b<f;b++){let A=m9(s,b);A===b&&d++,y[b]=A;}}i.setUniform(t.a,d>>>0);return}let h=l2e(i,e.c),p=h===null?0:h.width*h.height*h.depth,m=f=>f<p;if(e.dst===LC){if(h!==null){a.fill(Yg,0,p);for(let f=0;f<r;f++){let y=f*_c;n[y+2]!==0&&m(n[y+3])&&(a[n[y+3]]=n[y]);}d=u9(h,a.subarray(0,p),Yg,s,l);}for(let f=0;f<r;f++)i.writeRow(t.dst,u(f),m(u(f))?l[u(f)]:Yg);}else if(e.dst===jX){if(h!==null){s.fill(IE,0,p),a.fill(sf,0,p),c.fill(Ui,0,p);for(let y=0;y<r;y++)m(u(y))&&(s[u(y)]=n[y*_c]);let f=0;for(let y=0;y<r;y++){let b=y*_c,A=n[b+3];n[b+2]===0||!m(A)||s[A]===IE||(a[A]===sf&&(a[A]=0,l[f++]=A),c[A]=Math.min(c[A],n[b]));}d=h9(h,s.subarray(0,p),a,l,f,t.b===4294967295?null:c);}for(let f=0;f<r;f++){let y=u(f);i.writeRow(t.dst,y,m(y)?a[y]:sf),t.b!==4294967295&&i.writeRow(t.b,y,m(y)?c[y]:Ui);}}else {if(h!==null){s.fill(Ui,0,p);for(let f=0;f<r;f++){let y=f*_c;n[y+2]!==0&&m(n[y+3])&&(s[n[y+3]]=n[y]);}d=d9(h,s.subarray(0,p),a.subarray(0,p),i.uniform(t.b));}for(let f=0;f<r;f++)i.writeRow(t.dst,u(f),m(u(f))?s[u(f)]:Ui);}i.setUniform(t.a,d>>>0);}var ie=Math.fround,y9=16777216;function Is(i){return Number.isNaN(i)?0:Math.min(Math.max(i,-y9),y9)}function Os(i,e,t){return t?(i%e+e)%e:Math.min(Math.max(i,0),e-1)}function af(i,e,t){return ie(i+ie(ie(e-i)*t))}function Ot(i){return Ye(i>>>0)}function s2(i,e,t,n){let r=i[e],o=i[e+1],s=i[e+2],a=e+CX,l=a+o,c=O=>Ot(i[l+O*s+t]);if(o===1||!(n>Ot(i[a])))return c(0);if(!(n<Ot(i[a+o-1])))return c(o-1);let u=0;for(;u+2<o&&Ot(i[a+u+1])<=n;)u++;let d=Ot(i[a+u]),h=Ot(i[a+u+1]),p=c(u),m=c(u+1),f=ie(ie(n-d)/ie(h-d));if(r===wX)return p;if(r===IX)return af(p,m,f);if(r===OX){let O=l+o*s,N=Ot(i[O+u*s+t]),I=Ot(i[O+(u+1)*s+t]),S=ie(h-d),w=ie(f*f),U=ie(w*f),L=ie(U+U),k=ie(w*3),M=ie(ie(L-k)+1),K=ie(ie(U-ie(w+w))+f),Y=ie(k-L),te=ie(U-w),Z=ie(M*p);return Z=ie(Z+ie(ie(K*S)*N)),Z=ie(Z+ie(Y*m)),ie(Z+ie(ie(te*S)*I))}let y=l+o*s,b=y+o*s,A=ie(p+Ot(i[y+u*s+t])),E=ie(m-Ot(i[b+(u+1)*s+t])),R=ie(1-f),g=ie(R*R),v=ie(f*f),x=ie(ie(g*R)*p);return x=ie(x+ie(ie(ie(g*3)*f)*A)),x=ie(x+ie(ie(ie(R*3)*v)*E)),ie(x+ie(ie(v*f)*m))}function a2(i,e,t){let n=i[e],r=i[e+1],o=(r&Mm)!==0,s=e+NX,a=Is(ie(ie(t-Ot(i[e+2]))*Ot(i[e+3])));if((r&Mg)===0){let u=Math.floor(ie(a+.5));return Ot(i[s+Os(u,n,o)])}let l=Math.floor(a),c=ie(a-l);return af(Ot(i[s+Os(l,n,o)]),Ot(i[s+Os(l+1,n,o)]),c)}function Od(i,e,t,n,r,o){let s=Math.floor(n),a=Math.floor(r),l=ie(n-s),c=ie(r-a),u=Os(s,i,t),d=Os(s+1,i,t),h=Os(a,e,t),p=Os(a+1,e,t),m=af(o(u,h),o(d,h),l),f=af(o(u,p),o(d,p),l);return af(m,f,c)}function A9(i,e,t,n,r,o){return o(Os(Math.floor(ie(n+.5)),i,t),Os(Math.floor(ie(r+.5)),e,t))}function l2(i,e,t,n){let r=i[e],o=i[e+1],s=i[e+2],a=(s&Mm)!==0,l=e+kX,c=Is(ie(ie(t-Ot(i[e+4]))*Ot(i[e+6]))),u=Is(ie(ie(n-Ot(i[e+5]))*Ot(i[e+7]))),d=(h,p)=>Ot(i[l+p*r+h]);return (s&Mg)===0?A9(r,o,a,c,u,d):Od(r,o,a,c,u,d)}function c2(i,e,t,n,r,o,s){let a=i[e],l=i[e+1],c=i[e+2],u=(i[e+3]&Mm)!==0,d=Is(ie(ie(r-Ot(i[e+4]))*Ot(i[e+6]))),h=Is(ie(ie(o-Ot(i[e+5]))*Ot(i[e+6]))),p=(O,N)=>s((N*a+O)*c+n);if(t===gC)return A9(a,l,u,d,h,p);if(t===EC)return Od(a,l,u,d,h,p);let m=Od(a,l,u,Is(ie(d-1)),h,p),f=Od(a,l,u,Is(ie(d+1)),h,p),y=Od(a,l,u,d,Is(ie(h-1)),p),b=Od(a,l,u,d,Is(ie(h+1)),p),A=Ot(i[e+LX-1]),E=ie(m-f),R=ie(A+A),g=ie(y-b),v=ie(Math.sqrt(ie(ie(ie(E*E)+ie(R*R))+ie(g*g)))),x=t===xC?E:t===vC?R:g;return v>0?ie(x/v):0}function i2(i,e,t){return t?(i%e+e)%e:Math.min(Math.max(i,0),e-1)}function o2(i,e){let t=i>>>e&255;return t>=128?t-256:t}function b9(i,e,t,n,r,o){if(t===0||n===0||r===0)return -1;let s=(e&MX)!==0,a=t*n,l=i%t,c=Math.floor(i/t)%n,u=Math.floor(i/a),d=i2(l+o2(e,0),t,s)+i2(c+o2(e,8),n,s)*t+i2(u+o2(e,16),r,s)*a;return d<o?d:-1}var c2e=1347177795,u2e=8,u2=5,E9=6,d2e=1<<23,h2e=47,x9=(1<<24)-1;var OE=1,v9=256,p2=-128,m2=127,p2e=4,f2=new Float32Array(1),T9=new Uint32Array(f2.buffer);function h2(i){return T9[0]=i,f2[0]}function m2e(i){return f2[0]=i,T9[0]}function R9(i){return i>=p2&&i<=m2}function _2(i,e,t,n){let r=u=>i[u]>>>0;if(e<u2||r(0)!==c2e)return null;let o=r(1),s=r(4)|0;if(o===0||o>u2e||r(2)!==t||t===0||t>Ma||!R9(s))return null;let a=u2+o*E9;if(e<a)return null;let l=[],c=t;for(let u=0;u<o;u++){let d=u2+u*E9,h=r(d),p=u+1===o,m=r(d+4)|0;if(h===0||h>(p?dd:Ma)||r(d+1)>OE||r(d+2)>=d2e||r(d+3)>h2e||!R9(m))return null;let f=Math.ceil(c/p2e),y=a,b=y+h;if(a=b+h*f,a>e)return null;l.push({inputs:c,outputs:h,activation:r(d+1),multiplier:r(d+2),shift:r(d+3),zero:m,scale:h2(r(d+5)),bias:y,weights:b,stride:f}),c=h;}return c!==n?null:{words:i,inputs:t,outputs:n,scale:h2(r(3)),zero:s,layers:l}}function f2e(i){let e=Math.floor(i),t=i-e;return t>.5?e+1:t<.5||e%2===0?e:e+1}function w9(i,e,t){let n=Math.fround(h2(i)*e);return n=Number.isNaN(n)?0:Math.min(Math.max(n,-v9),v9),Math.min(Math.max(f2e(n)+t,p2),m2)}function y2(i){return Math.min(Math.max(i,-x9),x9)}function I9(i,e){let t=y2(i),n=Math.abs(t)*e.multiplier,r=e.shift===0?n:Math.floor((n+2**(e.shift-1))/2**e.shift),o=t<0?-r:r,s=e.activation===OE?e.zero:p2;return Math.min(Math.max(o+e.zero,s),m2)}function _2e(i,e){let t=y2(i);return e.activation===OE&&(t=Math.max(t,0)),m2e(Math.fround(t*e.scale))}function O9(i,e){return i>>>8*e<<24>>24}var C9=new Int32Array(Ma),N9=new Int32Array(Ma);function A2(i,e,t,n,r){let o=C9,s=N9;for(let l=0;l<i.inputs;l++)o[l]=w9(e[l*n+t]>>>0,i.scale,i.zero);let a=i.words;for(let l=0;l<i.layers.length;l++){let c=i.layers[l],u=l+1===i.layers.length;for(let h=0;h<c.outputs;h++){let p=a[c.bias+h]|0,m=c.weights+h*c.stride;for(let f=0;f<c.inputs;f++)p=p+O9(a[m+(f>>2)]>>>0,f&3)*o[f]|0;u?r[h]=_2e(p,c):s[h]=I9(p,c);}let d=o;o=s,s=d;}}function y2e(i,e){let t=y2(i);return e.activation===OE?Math.max(t,0):t}function A2e(i,e,t,n){let r=C9,o=N9;for(let l=0;l<i.inputs;l++)r[l]=w9(e[l*n+t]>>>0,i.scale,i.zero);let s=i.words,a=0;for(let l=0;l<i.layers.length;l++){let c=i.layers[l],u=l+1===i.layers.length,d=0;for(let p=0;p<c.outputs;p++){let m=s[c.bias+p]|0,f=c.weights+p*c.stride;for(let y=0;y<c.inputs;y++)m=m+O9(s[f+(y>>2)]>>>0,y&3)*r[y]|0;if(u){let y=y2e(m,c);(p===0||y>d)&&(d=y,a=p);}else o[p]=I9(m,c);}let h=r;r=o,o=h;}return a}var b2e=1162825027,g2e=1,E2e=2,x2e=16,d2=5,S9=2;function v2e(i,e,t){return i instanceof Uint32Array?i.subarray(e,e+t):Array.prototype.slice.call(i,e,e+t)}function k9(i,e,t,n){let r=l=>i[l]>>>0;if(e<d2||r(0)!==b2e||r(1)!==g2e)return null;let o=r(2);if(o<E2e||o>x2e||r(3)!==t||r(4)!==n)return null;let s=d2+(o+1)*S9;if(e<s)return null;let a=[];for(let l=0;l<=o;l++){let c=d2+l*S9,u=r(c),d=r(c+1);if(u<s||u+d>e)return null;let h=_2(v2e(i,u,d),d,t,l===0?o:n);if(h===null)return null;a.push(h);}return {inputs:t,outputs:n,router:a[0],experts:a.slice(1)}}function L9(i,e,t,n,r){let o=A2e(i.router,e,t,n);return A2(i.experts[o],e,t,n,r),o}var me=Math.fround,R2e=-2147483648,S2e=2147483647,D9=4294967295,b2=11;var Cd=new Float64Array(3),g2=new Float32Array(1);function T2e(i,e){let t=Cd[0],n=Cd[1],r=Cd[2];if(i.kind===ud){let s=me(me(me(t*i.vx)+me(n*i.vy))+me(r*i.vz)),a=s>0?s<i.reach?s:i.reach:0,l=me(t-me(i.vx*a)),c=me(n-me(i.vy*a)),u=me(r-me(i.vz*a));return me(me(me(l*l)+me(c*c))+me(u*u))<=me(i.p0*i.p0)?(g2[0]=a+0,true):false}let o=me(me(me(t*t)+me(n*n))+me(r*r));if(!(o<=me(i.reach*i.reach)))return false;if(i.kind===Dg){if(!(me(me(me(t*i.vx)+me(n*i.vy))+me(r*i.vz))>=me(i.p0*me(Math.sqrt(o)))))return false}else if(i.kind===Pg){let s=me(me(me(t*i.vx)+me(n*i.vy))+me(r*i.vz)),a=me(e?me(n*i.vx)-me(t*i.vy):me(t*i.vz)-me(r*i.vx)),l=e?0:n;if(!(Math.abs(s)<=i.p0&&Math.abs(a)<=i.p1&&Math.abs(l)<=i.p2))return false}return g2[0]=o,true}var w2e=new Float32Array(1);new Uint32Array(w2e.buffer);function M9(i,e){return Math.min(Math.max(i+e,R2e),S2e)}var yc=class{constructor(e){this.lo=new Int32Array(3);this.hi=new Int32Array(3);this.center=new Int32Array(3);this.len=0;this.grid=null;this.shape={kind:0,vx:0,vy:0,vz:0,p0:0,p1:0,p2:0,reach:0};this.mode=0;this.mask=0;this.value=0;this.filterColumn=null;this.cx=0;this.cy=0;this.cz=0;this.self=0;this.limit=0;this.keys=new Uint32Array(e),this.rows=new Uint32Array(e),this.floats=new Float32Array(this.keys.buffer);}accepts(e){let t=(this.filterColumn[e]&this.mask)>>>0,n=this.mode;return n===Bg?t===this.value>>>0:n===Gg?t!==0:n===Vg?t===0:true}test(e){let t=this.grid,n=t.rowAt(e);n!==this.self&&(this.mode!==0&&!this.accepts(n)||(Cd[0]=me(t.xAt(e)-this.cx),Cd[1]=me(t.yAt(e)-this.cy),Cd[2]=me(t.zAt(e)-this.cz),T2e(this.shape,t.isFlat)&&(this.floats[this.len]=g2[0],this.rows[this.len]=n,this.len++)));}scanCell(e,t,n){let r=this.grid,o=r.bucketOf(e,t,n),s=r.bucketEnd(o);for(let a=r.bucketStart(o);a<s;a++)r.inCell(a,e,t,n)&&this.test(a);}full(){this.len=0;let e=this.grid.size;for(let t=0;t<e;t++)this.test(t);}window(){let e=this.grid,t=this.shape,n,r,o,s,a,l;if(t.kind===ud){let c=me(this.cx+me(t.vx*t.reach)),u=me(this.cy+me(t.vy*t.reach)),d=me(this.cz+me(t.vz*t.reach)),h=t.p0;n=me(Math.min(this.cx,c)-h),r=me(Math.min(this.cy,u)-h),o=me(Math.min(this.cz,d)-h),s=me(Math.max(this.cx,c)+h),a=me(Math.max(this.cy,u)+h),l=me(Math.max(this.cz,d)+h);}else {let c=t.reach;n=me(this.cx-c),r=me(this.cy-c),o=me(this.cz-c),s=me(this.cx+c),a=me(this.cy+c),l=me(this.cz+c);}e.cellOf(n,r,o,this.lo),e.cellOf(s,a,l,this.hi);for(let c=0;c<3;c++)this.lo[c]=M9(this.lo[c],-1),this.hi[c]=M9(this.hi[c],1);e.isFlat&&(this.lo[2]=0,this.hi[2]=0);}cells(){let e=1;for(let t=0;t<3;t++)e*=Math.max(this.hi[t]-this.lo[t]+1,0);return e}ring(e){let{lo:t,hi:n,center:r}=this,o=Math.max(r[2]-e,t[2]),s=Math.min(r[2]+e,n[2]),a=Math.max(r[0]-e,t[0]),l=Math.min(r[0]+e,n[0]),c=Math.max(r[1]-e,t[1]),u=Math.min(r[1]+e,n[1]),d=0;for(let h=o;h<=s;h++){if(Math.abs(h-r[2])===e){for(let p=a;p<=l;p++)for(let m=c;m<=u;m++)this.scanCell(p,m,h),d++;continue}for(let p=a;p<=l;p++)if(Math.abs(p-r[0])===e)for(let m=c;m<=u;m++)this.scanCell(p,m,h),d++;else {let m=r[1]-e,f=r[1]+e;m>=c&&m<=u&&(this.scanCell(p,m,h),d++),f!==m&&f>=c&&f<=u&&(this.scanCell(p,f,h),d++);}}return d}covers(e){for(let t=0;t<3;t++)if(this.center[t]-e>this.lo[t]||this.center[t]+e<this.hi[t])return false;return true}rings(){let e=this.limit,t=this.grid;t.cellOf(this.cx,this.cy,this.cz,this.center);let n=t.size,r=0;for(let o=0;;o++){if(r+=this.ring(o),r>n)return false;if(this.covers(o))return true;if(this.len>=e&&o>=1){let s=me((o-1)*t.radius),a=me(s*s),l=0;for(let c=0;c<this.len&&l<e;c++)this.floats[c]<a&&l++;if(l>=e)return true}}}less(e,t){let n=this.keys[e],r=this.keys[t];return n!==r?n<r:this.rows[e]<this.rows[t]}swap(e,t){let n=this.keys[e];this.keys[e]=this.keys[t],this.keys[t]=n;let r=this.rows[e];this.rows[e]=this.rows[t],this.rows[t]=r;}sift(e,t){let n=e;for(;;){let r=2*n+1;if(r>=t||(r+1<t&&this.less(r,r+1)&&r++,!this.less(n,r)))return;this.swap(n,r),n=r;}}sort(){let e=this.len;for(let t=(e>>1)-1;t>=0;t--)this.sift(t,e);for(let t=e-1;t>0;t--)this.swap(0,t),this.sift(0,t);}run(e,t,n,r,o,s,a,l,c,u,d){return this.len=0,e.size===0||d===0||!(t.reach>=0)?0:(this.mask=r,this.value=o,this.cx=a,this.cy=l,this.cz=c,this.limit=d,this.search(e,t,n,s,u))}runFrom(e,t,n,r,o,s,a,l,c,u,d,h){this.len=0;let p=r[a];return e.size===0||p===0||!(t.reach>=0)?0:(this.mask=r[o],this.value=r[s],this.cx=c[h],this.cy=u[h],this.cz=d===null?0:d[h],this.limit=p,this.search(e,t,n,l,h))}search(e,t,n,r,o){let s=this.limit;if(this.grid=e,this.shape=t,this.mode=n,this.filterColumn=r,this.self=o,this.window(),s!==D9&&t.kind!==ud)this.rings()||this.full();else if(this.cells()<=e.size)for(let a=this.lo[0];a<=this.hi[0];a++)for(let l=this.lo[1];l<=this.hi[1];l++)for(let c=this.lo[2];c<=this.hi[2];c++)this.scanCell(a,l,c);else this.full();return this.sort(),this.grid=null,this.filterColumn=null,Math.min(this.len,s)}},CE=class{constructor(e,t,n){this.shape={kind:0,vx:0,vy:0,vz:0,p0:0,p1:0,p2:0,reach:0};this.f32=new Float32Array(1);this.u32=new Uint32Array(this.f32.buffer);this.dry=false;this.search=new yc(e),this.params=new Uint32Array(b2*t),this.stopped=new Uint8Array(t),this.stop=new Uint8Array(t),this.saved=new Uint32Array(n*t),this.accs=new Uint32Array(n),this.ranks=new Uint32Array(t);}float(e){return this.u32[0]=e,this.f32[0]}op(e,t,n,r){if(!(t!==cc||!this.dry))for(let o=0;o<r;o++)e.lane(n,o)!==0&&(this.stop[o]=1);}run(e,t,n){let r=e.code,o=r[t],s=r[t+1],a=t+2,l=s.a,c=s.c,u=(c&Ug)!==0,d=c&Fg,h=u?t-2:-1,p=d===La?-1:u?t-4:t-2,m=false;for(let S=a;S<l;S++)r[S].op===Ve&&r[S].dst===cc&&(m=true);let f=(S,w,U)=>S===4294967295?U:e.lane(S,w)>>>0,y=this.params;for(let S=0;S<n;S++){let w=S*b2;y[w]=f(s.b,S,1),y[w+1]=e.lane(o.b,S),y[w+2]=f(o.c,S,D9);for(let U=3;U<11;U++)y[w+U]=0;if(p>=0){let U=r[p],L=r[p+1];[U.a,U.b,U.c,L.a,L.b,L.c].forEach((k,M)=>{y[w+3+M]=f(k,S,0);});}h>=0&&(y[w+9]=e.lane(r[h].b,S),y[w+10]=e.lane(r[h].c,S));}let[b,A,E]=e.position,R=new Float32Array(e.snapshot[b].buffer),g=new Float32Array(e.snapshot[A].buffer),v=E===4294967295?null:new Float32Array(e.snapshot[E].buffer),x=h>=0?r[h+1].a:0,O=h>=0?e.snapshot[r[h].a]:null;this.stopped.fill(0,0,n);let N=this.shape;N.kind=d;let I=0;for(let S=0;S<n;S++){let w=S*b2;if(y[w]===0)continue;let U=e.row(S);N.reach=this.float(y[w+1]),N.vx=this.float(y[w+3]),N.vy=this.float(y[w+4]),N.vz=this.float(y[w+5]),N.p0=this.float(y[w+6]),N.p1=this.float(y[w+7]),N.p2=this.float(y[w+8]);let L=this.search.run(e.grid,N,x,y[w+9],y[w+10],O,R[U],g[U],v===null?0:v[U],U,y[w+2]);for(let k=0;k<L&&this.stopped[S]===0;k++)e.pairLane[I]=S,e.pairRow[I]=this.search.rows[k],this.ranks[I]=k,I++,I===e.tile&&(this.flush(e,a,l,I,m),I=0);}I>0&&this.flush(e,a,l,I,m);}flush(e,t,n,r,o){if(!o){e.exec(t,n,r);return}let s=e.code,a=e.tile,l=0;for(let u=t;u<n;u++){let d=s[u].op;if(d!==nt.ACC_FADD&&d!==nt.ACC_FMIN&&d!==nt.ACC_FMAX&&d!==nt.ACC_IADD)continue;let h=false;for(let p=0;p<l;p++)this.accs[p]===s[u].a&&(h=true);h||(this.accs[l++]=s[u].a);}for(let u=0;u<l;u++)this.saved.set(e.bits.subarray(this.accs[u]*a,this.accs[u]*a+a),u*a);this.stop.fill(0,0,r),this.dry=true,e.exec(t,n,r),this.dry=false;for(let u=0;u<l;u++)e.bits.set(this.saved.subarray(u*a,u*a+a),this.accs[u]*a);let c=0;for(let u=0;u<r;u++){let d=e.pairLane[u];this.stopped[d]===0&&(e.pairLane[c]=d,e.pairRow[c]=e.pairRow[u],this.ranks[c]=this.ranks[u],this.stop[u]!==0&&(this.stopped[d]=1),c++);}c>0&&e.exec(t,n,c);}};var se=nt,I2e=new Set([se.MOV,se.INEG,se.IABS,se.INOT,se.MNOT,se.ITOF,se.UTOF,se.FTOI,se.BTOF,se.BTOI,se.FTOB,se.ITOB]),O2e=new Set([se.FLEN2,se.NOISE2,se.HASH,se.RAND,se.UMULHI,se.MAND,se.MOR,se.MANDN]),C2e=new Set([se.SEL,se.FMULADD,se.FMULSUB,se.FSUBMUL,se.FADDMUL,se.FCLAMP,se.FLERP,se.FLEN3,se.NOISE3,se.UADDC,se.USUBB]);function N2e(i){return I2e.has(i)||i>=se.FLOG2&&i<=se.FLOG?1:O2e.has(i)||i>=se.FADD&&i<=se.FATAN2||i>=se.FLT&&i<=se.FNE||i>=se.IADD&&i<=se.UMAX||i>=se.ILT&&i<=se.ULE?2:C2e.has(i)?3:0}function NE(i){return i>=Hg&&i<Hg+GX?i-Hg:null}function kE(i){return i.op===Ve&&Di(i.dst)===An.SIMD}function x2(i,e){let t=e.a,n=t&TC,r=s=>s===4294967295?"unused":"vector",o=NE(i.dst);if(o!==null){let s=N2e(o);if(s===0)return null;let a=(l,c)=>l<s?(t&c)!==0?"scalar":"vector":"unused";return {width:n,roles:[a(0,VX),a(1,HX),a(2,WX),"unused"],vectorDst:true}}switch(i.dst){case hd:return {width:n,roles:["vector",r(i.b),"unused","immediate"],vectorDst:true};case pd:return {width:n,roles:["vector","immediate","unused","unused"],vectorDst:false};case md:return {width:n,roles:["vector","scalar","immediate","unused"],vectorDst:true};case Dm:{let s=a=>a<n?"scalar":"unused";return {width:n,roles:[s(0),s(1),s(2),s(3)],vectorDst:true}}case Pm:return {width:n,roles:["vector","vector","immediate","unused"],vectorDst:false};case Fm:return {width:n,roles:["vector","immediate","unused","unused"],vectorDst:false};case Um:return {width:n,roles:["vector","unused","unused","unused"],vectorDst:false};case Bm:return {width:n,roles:["vector","unused","unused","unused"],vectorDst:true};case Gm:return {width:n,roles:["vector","vector","unused","unused"],vectorDst:true};default:return null}}function P9(i,e){return [i.a,i.b,i.c,e.b]}function E2(i,e,t){return e==="vector"?i+t>>>0:i}function k2e(i,e){return i>>>wC*e&KX}function lf(i,e,t){let n=e.a&TC;switch(i.dst){case hd:{let r=k2e(e.b,t);return r<n?i.a+r>>>0:i.b+r-n>>>0}case md:return t===i.c?i.b:i.a+t>>>0;case pd:return i.a+i.b>>>0;default:return P9(i,e)[t]}}var v2=[[1,2,2,1],[2,0,0,2],[0,1,1,0]],F9=4;function U9(i,e,t){let n=x2(i,e);if(n===null)return null;let r=n.width,o=[],s=4294967295,a=(f,y,b,A=s,E=s)=>{o.push({op:f,dst:y,a:b,b:A,c:E});},[l,c,u,d]=[t,t+1,t+2,t+3],h=(f,y)=>f+y>>>0,p=(f,y,b)=>{a(b?se.FMUL:se.IMUL,l,f,y);for(let A=1;A<r;A++)a(b?se.FMUL:se.IMUL,c,h(f,A),h(y,A)),a(b?se.FADD:se.IADD,l,l,c);},m=NE(i.dst);if(m!==null){for(let f=0;f<r;f++)o.push(R2(m,i,e,n,f));return o}switch(i.dst){case hd:case md:case Dm:for(let f=0;f<r;f++)a(se.MOV,e.dst+f,lf(i,e,f));return o;case pd:return a(se.MOV,e.dst,lf(i,e,0)),o;case Pm:return p(i.a,i.b,i.c===Wg),a(se.MOV,e.dst,l),o;case Um:return p(i.a,i.a,true),a(se.FSQRT,e.dst,l),o;case Bm:p(i.a,i.a,true),a(se.FSQRT,l,l),a(se.IXOR,u,l,l),a(se.FLT,d,u,l);for(let f=0;f<r;f++)a(se.FDIV,c,h(i.a,f),l),a(se.SEL,e.dst+f,d,c,u);return o;case Gm:return v2.forEach(([f,y,b,A],E)=>{a(se.FMUL,l,h(i.a,b),h(i.b,A)),a(se.FMULSUB,e.dst+E,h(i.a,f),h(i.b,y),l);}),o;case Fm:a(i.b,e.dst,i.a,h(i.a,1));for(let f=2;f<r;f++)a(i.b,e.dst,e.dst,h(i.a,f));return o;default:return null}}function R2(i,e,t,n,r){let o=P9(e,t);return {op:i,dst:t.dst+r,a:E2(o[0],n.roles[0],r),b:E2(o[1],n.roles[1],r),c:E2(o[2],n.roles[2],r)}}var Cs=Math.fround,S2=new Float64Array(1),LE=new Uint32Array(S2.buffer),L2e=2143289344,M2e=2146959360,D2e=1065353216,P2e=2139095040,F2e=4286578688,U2e=2147483647,B2e=2147483648,G2e=4294967295;function B9(i,e){return LE[0]=i>>>0,LE[1]=e>>>0,S2[0]}function V2e(i,e){return Number.isNaN(i)?(e[0]=0,e[1]=M2e,e):(S2[0]=i,e[0]=LE[0],e[1]=LE[1],e)}function G9(i){switch(i){case at.MUL_F32:return D2e;case at.MIN_F32:return P2e;case at.MAX_F32:return F2e;case at.MUL_INT:return 1;case at.MIN_I32:return U2e;case at.MAX_I32:return B2e;case at.MIN_U32:case at.AND:return G2e;default:return 0}}function H2e(i,e){let t=Ye(i),n=Ye(e);return t<n?i:n<t?e:Number.isNaN(t)?i:e}function W2e(i,e){let t=Ye(i),n=Ye(e);return t>n?i:n>t?e:Number.isNaN(t)?i:e}function V9(i,e,t,n,r){let o=e[0];switch(i){case at.LINEAR_F32:e[0]=mt(Cs(Cs(Ye(t)*Ye(o))+Ye(n)));return;case at.LINEAR_U32:e[0]=Math.imul(t,o)+n>>>0;return;case at.FEEDBACK_F32:e[0]=mt(Cs(Cs(Ye(n)-Cs(Ye(t)*Ye(o)))-Cs(Ye(r)*Ye(e[1])))),e[1]=o;return;case at.PHASE_F64:{let s=B9(e[0],e[1])+Ye(n),a=Ye(t);V2e(s>=a?s-a:s,e);return}case at.ADD_F32:e[0]=mt(Cs(Ye(o)+Ye(n)));return;case at.MUL_F32:e[0]=mt(Cs(Ye(o)*Ye(n)));return;case at.MIN_F32:e[0]=H2e(o,n)>>>0;return;case at.MAX_F32:e[0]=W2e(o,n)>>>0;return;case at.ADD_INT:e[0]=o+n>>>0;return;case at.MUL_INT:e[0]=Math.imul(o,n)>>>0;return;case at.MIN_I32:e[0]=((o|0)<(n|0)?o:n)>>>0;return;case at.MAX_I32:e[0]=((o|0)>(n|0)?o:n)>>>0;return;case at.MIN_U32:e[0]=Math.min(o>>>0,n>>>0);return;case at.MAX_U32:e[0]=Math.max(o>>>0,n>>>0);return;case at.AND:e[0]=(o&n)>>>0;return;case at.OR:e[0]=(o|n)>>>0;return;default:e[0]=(o^n)>>>0;}}function H9(i,e,t,n){if(i!==at.PHASE_F64||(e&Kg)!==0)return n[0]=t[0],n[1]=t[1],n;let r=Cs(B9(t[0],t[1]));return n[0]=Number.isNaN(r)?L2e:mt(r),n[1]=0,n}var H=nt,we=256,pr=4,j2e=4,J2e=2,cf=4294967295,Ie=Math.fround,Kn=Ye,Nd=mt,Yn=0,Bi=1,Dr=2,kd=3;function gc(i){if(i.byteLength%4!==0)throw new _("invalid_argument","a kernel program is a whole number of words");let e=new DataView(i.buffer,i.byteOffset,i.byteLength),t=new Uint32Array(i.byteLength/4);for(let R=0;R<t.length;R++)t[R]=e.getUint32(R*4,true);if(t[0]!==827345731)throw new _("invalid_argument","this is not a kernel program");if(t[1]<1||t[1]>4)throw new _("unsupported_feature",`kernel instruction set ${t[1]} is not supported`);let n=t[4],r=t[5],o=t[6],s=t[7],a=t[8],l=t[9],c=16,u=Array.from({length:n},(R,g)=>({kind:t[c+g]&255,neighbour:(t[c+g]&1024)!==0,scratch:(t[c+g]&2048)!==0,spawn:(t[c+g]&8192)!==0,indexed:(t[c+g]&Lg)!==0,write:(t[c+g]&512)!==0,word:t[c+g]}));c+=n+r;let d=new Uint32Array(r+o+s);d.set(t.subarray(c,c+o),r),c+=o;let h=[];for(let R=0;R<l;R++,c+=4)h.push({isDefault:(t[c]&cX)!==0,value:t[c+1],start:t[c+2],end:t[c+3]});let p=t[14];if(p>64)throw new _("invalid_argument","the kernel program is malformed");let m=[];for(let R=0;R<p;R++,c+=4)m.push(t[c]);let f=[];for(let R=0;R<a;R++,c+=4)f.push({op:t[c]&255,dst:t[c]>>>8,a:t[c+1],b:t[c+2],c:t[c+3]});if(c!==t.length)throw new _("invalid_argument","the kernel program is malformed");let y=t[2],b=-1;for(let R of f)(R.op===H.NEIGHBOURS||R.op===Ve&&R.dst===ka)&&(b=R.a);let A=[],E=[];return f.forEach((R,g)=>{R.op===H.CALL&&A.push(g),(So(R.op)||dc(R.op,R.dst))&&E.push(g);}),{registers:t[3],slots:u,calls:A,cross:E,args:r,loops:s,uniforms:d,code:f,groups:h,state:(y&2)!==0?t[10]:-1,position:(y&1)!==0?[t[11],t[12],t[13]]:null,radius:b,channels:m}}function P2(i){return i|0}var Z2e=65536,eNe=4294967296,ME=65535;function tNe(i,e){let t=i&ME,n=i>>>16,r=e&ME,o=e>>>16,s=t*o,a=n*r,l=(t*r>>>16)+(s&ME)+(a&ME);return n*o+(s>>>16)+(a>>>16)+Math.floor(l/Z2e)>>>0}var nNe=[[4,3],[5,4]];function rNe(i,e,t){let n=i.calls.some(r=>{let o=i.code[r];return nNe.some(([s,a])=>s===km(o.dst)&&o.c+a===e)});switch(i.slots[e].kind){case 0:return {values:new Float32Array(t),storage:Yn};case 1:return {values:new Int32Array(t),storage:Bi};case 2:return n?{values:new Uint8Array(t),storage:kd}:{values:new Uint32Array(t),storage:Dr};default:return {values:new Uint8Array(t),storage:kd}}}function DE(i,e){return i<e?i:e<i?e:Number.isNaN(i)?i:e}function PE(i,e){return i>e?i:e>i?e:Number.isNaN(i)?i:e}function iNe(i){let e=Math.floor(i);return i-e>=.5?e+1:e}function oNe(i){return i>0?1:i<0?-1:i}var sNe=2146121005,aNe=2221713035;function T2(i){let e=i>>>0;return e^=e>>>16,e=Math.imul(e,sNe),e^=e>>>15,e=Math.imul(e,aNe),e^=e>>>16,e>>>0}function K9(i,e){return T2((i^T2(e+2654435769>>>0))>>>0)}function lNe(i,e){return Ie((K9(i,e)>>>8)*(1/16777216))}function fi(i,e,t){return Ie((T2(Math.imul(i,2376512323)^Math.imul(e,3625334849)^Math.imul(t,3407524639))>>>8)*(1/16777216))}function df(i){return Ie(Ie(i*i)*Ie(3-Ie(2*i)))}function Oo(i,e,t){return Ie(i+Ie(Ie(e-i)*t))}function hf(i){let e=Math.floor(i);return [e|0,Ie(i-e)]}function F2(i,e){if(!Number.isFinite(i)||!Number.isFinite(e))return 0;let[t,n]=hf(i),[r,o]=hf(e),s=df(n),a=df(o),l=Oo(fi(t,r,0),fi(t+1,r,0),s),c=Oo(fi(t,r+1,0),fi(t+1,r+1,0),s);return Ie(Ie(Oo(l,c,a)*2)-1)}function U2(i,e,t){if(!Number.isFinite(i)||!Number.isFinite(e)||!Number.isFinite(t))return 0;let[n,r]=hf(i),[o,s]=hf(e),[a,l]=hf(t),c=df(r),u=df(s),d=df(l),h=Oo(fi(n,o,a),fi(n+1,o,a),c),p=Oo(fi(n,o+1,a),fi(n+1,o+1,a),c),m=Oo(fi(n,o,a+1),fi(n+1,o,a+1),c),f=Oo(fi(n,o+1,a+1),fi(n+1,o+1,a+1),c);return Ie(Ie(Oo(Oo(h,p,u),Oo(m,f,u),d)*2)-1)}function Ns(i,e,t){return i===0?Nd(e===Yn?t:Ie(e===Bi?t|0:t>>>0)):i===3?t!==0&&!Number.isNaN(t)?cf:0:e===Yn?P2(t)>>>0:t>>>0}function Va(i,e,t){return e===Yn?i===0?Kn(t):i===3?t!==0?1:0:Ie(i===1?t|0:t>>>0):i===0?P2(Kn(t)):i===3?t!==0?1:0:t}var Ld=class{constructor(e,t){this.program=e;this.capacity=t;this.rows=new Uint32Array(we);this.pairLane=new Uint32Array(we);this.pairRow=new Uint32Array(we);this.columns=[];this.scratch=new Uint32Array(we);this.fscratch=new Float32Array(this.scratch.buffer);this.found=[];this.callArgs=new Float64Array(8);this.mlpRow=new Uint32Array(dd);this.callOut=new Float64Array(8);this.services=null;this.dataHost={lane:(e,t)=>this.lane(e,t),row:e=>this.row(e),set:(e,t,n)=>{this.bits[e*we+t]=n;}};this.pending=[];this.marked=0;this.spawnStats={spawned:0,dropped:0,killed:0};this.base=0;this.listMode=false;this.visit=0;this.runCount=0;this.sortCounts=new Uint32Array(1<<Xg);this.graphCache=null;this.recurState=[0,0];this.recurBefore=[0,0];this.recurOut=[0,0];this.splats=[new Uint32Array(we),new Uint32Array(we),new Uint32Array(we)];let n=new ArrayBuffer(Math.max(e.registers,1)*we*4);this.bits=new Uint32Array(n),this.floats=new Float32Array(n),this.uniforms=new Uint32Array(e.uniforms.length),this.grid=new Fa(e.position===null?0:t),this.snapshot=e.slots.map(s=>s.neighbour?new Uint32Array(t):new Uint32Array(0)),this.own=e.slots.map((s,a)=>s.scratch?rNe(e,a,t):null),this.deferred=e.calls.map(s=>e.code[s]).filter(s=>fC(km(s.dst))),this.marks=new Uint32Array(this.deferred.length>0?t:0),this.records=e.cross.map(()=>new Uint32Array(t*pr)),this.sorting=e.cross.some(s=>e.code[s].op===Ve)?new Uint32Array(j2e*t):new Uint32Array(0),this.indexed=e.slots.map(s=>s.indexed===true&&s.write===true?new Float64Array(t):null),this.events=new Uint32Array(er+(e.channels.length>0?Ro*10:0)),this.data=new RE(e.slots,e.code,t);let r=e.code.some(s=>s.op===Ve&&Di(s.dst)===An.NEURAL);this.mlpIn=new Uint32Array(r?Ma*we:0),this.mlpOut=new Uint32Array(r?dd*we:0);let o=e.code.filter(s=>s.op===H.ACC_FADD||s.op===H.ACC_FMIN||s.op===H.ACC_FMAX||s.op===H.ACC_IADD).length;this.queries=e.code.some(s=>s.op===Ve&&s.dst===ka)?new CE(t,we,o):null,this.queryHost={code:e.code,bits:this.bits,pairLane:this.pairLane,pairRow:this.pairRow,snapshot:this.snapshot,grid:this.grid,position:e.position??[4294967295,4294967295,4294967295],tile:we,lane:(s,a)=>this.lane(s,a),row:s=>this.row(s),exec:(s,a,l)=>{let c=this.listMode,u=this.base;this.exec(s,a,l),this.listMode=c,this.base=u;}};}clearEvents(){this.events[vo]=0,this.events[Es]=0;}u(e){return this.uniforms[e&2147483647]}isUniform(e){return (e&2147483648)!==0&&e!==4294967295}lane(e,t){return this.isUniform(e)?this.u(e):this.bits[e*we+t]}flane(e,t){return this.isUniform(e)?Kn(this.u(e)):this.floats[e*we+t]}run(e,t,n,r){let o=this.program;if(e.length!==o.slots.length||t>this.capacity)throw new _("invalid_argument","the kernel binding does not match its table");if(o.calls.length>this.deferred.length&&this.services===null)throw new _("unsupported_feature","this kernel calls engine services; attach them with world.kernelServices({ physics, nav, flow, terrain, graphics })");this.columns=o.calls.length>0||o.cross.length>0?e.map((d,h)=>this.own[h]??d):e,this.runCount=t,this.indexed.forEach((d,h)=>{if(d!==null)for(let p=0;p<t;p++)d[p]=this.columns[h].values[p];}),this.marked>0&&(this.marks.fill(0,0,Math.min(this.marked,this.marks.length)),this.marked=0),this.uniforms.set(o.uniforms),this.uniforms.set(r.subarray(0,o.args)),this.data.prepare(this.columns,t);let s=null;if(n!==null){let d=[];for(let h of n)h<t&&d.push(h);s=Uint32Array.from(d);}if(o.position!==null){this.prepareNeighbours(t);let d=this.grid.order();s===null&&o.state<0&&d.length===t&&(s=d.slice());}if(o.state>=0){let d=s??Uint32Array.from({length:t},(b,A)=>A),h=o.slots[o.state],p=e[o.state],m=o.groups.map(()=>[]),f=o.groups.findIndex(b=>b.isDefault);for(let b of d){let A=Ns(h.kind,p.storage,p.values[b]),E=o.groups.findIndex(R=>!R.isDefault&&(h.kind===0?Kn(A)===Kn(R.value):A===R.value));E<0&&(E=f),E>=0&&m[E].push(b);}let y=0;return o.groups.forEach((b,A)=>{this.tiles(Uint32Array.from(m[A]),m[A].length,b.start,b.end),y+=m[A].length;}),this.data.finish(this.columns,this.uniforms),this.orderEvents(s),y}let a=s===null?t:s.length,l=0,c=0,u=0;for(;c<o.calls.length||u<o.cross.length;){let d=c<o.calls.length?o.calls[c]:1/0,h=u<o.cross.length?o.cross[u]:1/0;if(h<d){let p=y=>o.code[y].op===Ln.SCATTER||o.code[y].op===Ve?2:1,m=u,f=h+p(h);for(u++;u<o.cross.length&&o.cross[u]===f;)f+=p(f),u++;this.tiles(s,a,l,f);for(let y=m;y<u;y++)this.finishCross(o.cross[y],y,a);l=f;continue}this.tiles(s,a,l,d),this.call(o.code[d],s,a,t),c++,l=d+1;}return this.tiles(s,a,l,o.code.length),this.data.finish(this.columns,this.uniforms),this.orderEvents(s),a}orderEvents(e){let t=this.events,n=this.pending;if(this.pending=[],t.length<=er||n.length===0)return;let r=new Map;e!==null&&e.forEach((a,l)=>r.set(a,l));let o=n.map((a,l)=>({entry:a,ordinal:e===null?a[1]:r.get(a[1]),k:l}));o.sort((a,l)=>a.ordinal-l.ordinal||a.k-l.k);let s=(t.length-er)/10;for(let{entry:a}of o){let l=t[vo];if(l>=s){t[Es]++;continue}t.set(a,er+l*10),t[vo]=l+1;}}call(e,t,n,r){let o=km(e.dst),s=this.columns,a=e.b===4294967295?null:s[e.b].values;if(fC(o)){let h=1<<this.deferred.findIndex(p=>p.a===e.a&&p.b===e.b&&p.c===e.c&&p.dst===e.dst);for(let p=0;p<n;p++){let m=t===null?p:t[p];m>=r||a!==null&&a[m]===0||(this.marks[m]|=h);}this.marked=Math.max(this.marked,r);return}let l=_C[o],c=this.services,u=this.callArgs,d=this.callOut;c.begin?.(o);for(let h=0;h<n;h++){let p=t===null?h:t[h];if(!(p>=r||a!==null&&a[p]===0)){for(let m=0;m<l.args.length;m++)u[m]=s[e.a+m].values[p];if(!c.call(o,u,d))throw new _("unsupported_feature","the attached kernel services cannot answer this engine call");for(let m=0;m<l.results.length;m++)s[e.c+m].values[p]=l.results[m]===3?d[m]!==0?1:0:d[m];}}c.end?.(o);}get defers(){return this.deferred.length>0}finish(e,t){let n=this.spawnStats;if(n.spawned=0,n.dropped=0,n.killed=0,this.deferred.length===0)return n;let r=this.marks,o=Math.min(this.marked,e.count,r.length),s=0;this.deferred.forEach((c,u)=>{km(c.dst)===23&&(s|=1<<u);});let a=false;for(let c=0;c<o&&!a;c++)a=(r[c]&s)!==0;if(a){let c=e.count,u=e.columns,d=0;for(let h=0;h<c;h++)if(!(h<o&&(r[h]&s)!==0)){if(d!==h)for(let p of u)p[d]=p[h];d++;}n.killed=c-d,e.count=d;}let l=~s&(this.deferred.length>=32?4294967295:(1<<this.deferred.length)-1);if(l!==0){let c=t??e,u=this.program.slots;for(let d=0;d<o;d++){let h=r[d]&l;if(h!==0)for(let p=0;p<this.deferred.length;p++){if((h&1<<p)===0)continue;let m=this.deferred[p],f=c.count;if(f>=c.capacity){n.dropped++;continue}for(let b of c.columns)b[f]=0;let y=nX(m.dst);for(let b=0;b<y;b++){let A=this.columns[m.a+b],E=u[m.a+b].kind,R=c.column(m.c+b);R.values[f]=Va(E,R.storage,Ns(E,A.storage,A.values[d]));}c.count=f+1,n.spawned++;}}}return r.fill(0,0,Math.min(this.marked,r.length)),this.marked=0,n}prepareNeighbours(e){let t=this.program;t.slots.forEach((a,l)=>{if(!a.neighbour)return;let c=this.columns[l],u=this.snapshot[l];for(let d=0;d<e;d++)u[d]=Ns(a.kind,c.storage,c.values[d]);});let[n,r,o]=t.position,s=a=>new Float32Array(this.snapshot[a].buffer,0,e);this.grid.rebuild(Kn(this.u(t.radius)),s(n),s(r),o===4294967295?null:s(o),e);}tiles(e,t,n,r){for(let o=0;o<t;o+=we){let s=Math.min(we,t-o);this.visit=o,e===null?(this.listMode=false,this.base=o):(this.listMode=true,this.rows.set(e.subarray(o,o+s))),this.exec(n,r,s);}}row(e){return this.listMode?this.rows[e]:this.base+e}exec(e,t,n){let r=this.program.code,o=this.bits,s=this.floats,a=e;for(;a<t;){let l=r[a],c=l.dst*we;if(DX(l.op)){this.lookup(a,l,n),a+=l.op===Nm.SAMPLE?2:1;continue}if(l.op===Ve){if(l.dst===ka&&this.queries!==null){this.queries.run(this.queryHost,a,n),a=r[a+1].a;continue}this.extended(a,l,r[a+1],n),a+=2;continue}if(So(l.op)){this.record(a,l,n),a+=l.op===Ln.SCATTER?2:1;continue}switch(l.op){case H.NOP:break;case H.LOAD:{let u=this.program.slots[l.a],d=this.columns[l.a];for(let h=0;h<n;h++)o[c+h]=Ns(u.kind,d.storage,d.values[this.row(h)]);break}case H.STORE:{let u=this.program.slots[l.a],d=this.columns[l.a],h=u.kind===0&&d.storage===Yn||(u.kind===1||u.kind===2)&&(d.storage===Bi||d.storage===Dr);for(let p=0;p<n;p++){let m=this.lane(l.b,p),f=this.row(p);!h&&Ns(u.kind,d.storage,d.values[f])===m||(d.values[f]=Va(u.kind,d.storage,m));}break}case H.ROW:for(let u=0;u<n;u++)o[c+u]=this.row(u);break;case H.JNONE:{let u=false;for(let d=0;d<n&&!u;d++)u=this.lane(l.a,d)!==0;if(!u){a=l.b;continue}break}case H.LOOP_INIT:{if(this.uniforms[l.a]=0,this.trips(l.b,l.dst)===0){a=l.c;continue}break}case H.LOOP_NEXT:{if(this.uniforms[l.a]++,this.uniforms[l.a]<this.trips(l.b,l.dst)){a=l.c;continue}break}case H.NEIGHBOURS:this.neighbours(a+1,l.b,l.c,n),a=l.b;continue;case H.NLOAD:{let u=this.snapshot[l.a];for(let d=0;d<n;d++)o[c+d]=u[this.pairRow[d]];break}case H.OUTER:{let u=l.a*we;for(let d=0;d<n;d++)o[c+d]=o[u+this.pairLane[d]];break}case H.NROW:for(let u=0;u<n;u++)o[c+u]=this.pairRow[u];break;case H.ACC_FADD:case H.ACC_FMIN:case H.ACC_FMAX:case H.ACC_IADD:{let u=l.a*we;for(let d=0;d<n;d++){if(l.c!==4294967295&&o[l.c*we+d]===0)continue;let h=u+this.pairLane[d];if(l.op===H.ACC_IADD)o[h]=o[h]+this.lane(l.b,d)>>>0;else {let p=this.flane(l.b,d);s[h]=l.op===H.ACC_FADD?s[h]+p:l.op===H.ACC_FMIN?DE(s[h],p):PE(s[h],p);}}break}case H.EMIT:{let u=this.program.channels[l.dst],d=Math.ceil(u/3);for(let h=0;h<n;h++){if(l.a!==4294967295&&this.lane(l.a,h)===0)continue;let p=new Uint32Array(10);p[0]=l.dst,p[1]=this.row(h);for(let m=0;m<8;m++){let f=r[a+1+Math.floor(m/3)];p[2+m]=m<u?this.lane([f.a,f.b,f.c][m%3],h):0;}this.pending.push(p);}a+=1+d;continue}case H.FDOT2:case H.FDOT3:{let u=r[a+1];for(let d=0;d<n;d++){let h=Ie(Ie(this.flane(l.a,d)*this.flane(l.b,d))+Ie(this.flane(l.c,d)*this.flane(u.a,d)));l.op===H.FDOT3&&(h=Ie(h+Ie(this.flane(u.b,d)*this.flane(u.c,d)))),s[c+d]=h;}a+=2;continue}default:this.arith(l,n);}a++;}}extended(e,t,n,r){switch(Di(t.dst)){case An.DATA:this.data.exec(e,t,n,r,this.columns,this.dataHost);return;case An.NARROW:{let s=this.bits;i9(t.dst,[t.a,t.b,t.c,n.a,n.b],[n.dst,n.c,n.b],r,(a,l)=>this.lane(a,l),(a,l,c)=>{s[a*we+l]=c;});return}case An.SAMPLING:if(t.dst===PX&&this.queries!==null){let s=this.bits,a=this.queries.ranks;for(let l=0;l<r;l++)s[n.dst*we+l]=a[l];return}this.queries?.op(this.queryHost,t.dst,t.a,r);return;case An.CROSS:t.dst===Da||t.dst===Pa?this.gather(t,n,r):this.record(e,t,r);return;case An.NEURAL:this.neural(t,n,r);return;case An.SIMD:this.simd(t,n,r);return;case An.SYSTEMS:f9(t,this.records[this.program.cross.indexOf(e)],this.visit,r,(s,a)=>this.lane(s,a),s=>this.row(s));return;default:throw new _("unsupported_feature",`extended kernel op 0x${t.dst.toString(16)} (pc ${e}, ext ${n.op}, ${r} rows) is not supported by this SDK; update @cimplify/sdk`)}}lookup(e,t,n){let r=Nm,o=this.uniforms,s=this.floats,a=this.bits,l=t.dst*we;switch(t.op){case r.CURVE:{let c=t.b&2147483647;for(let u=0;u<n;u++)s[l+u]=s2(o,c,t.c,this.flane(t.a,u));return}case r.LUT1:{let c=t.b&2147483647;for(let u=0;u<n;u++)s[l+u]=a2(o,c,this.flane(t.a,u));return}case r.LUT2:{let c=t.c&2147483647;for(let u=0;u<n;u++)s[l+u]=l2(o,c,this.flane(t.a,u),this.flane(t.b,u));return}case r.SAMPLE:{let c=this.program.code[e+1],u=c.a&2147483647,d=this.columns[t.a],p=this.indexed[t.a]??d.values,m=f=>Kn(Ns(0,d.storage,p[f]));for(let f=0;f<n;f++)s[l+f]=c2(o,u,c.b,c.c,this.flane(t.b,f),this.flane(t.c,f),m);return}default:{let c=this.columns[t.a],u=this.program.slots[t.a].kind,h=this.indexed[t.a]??c.values,p=t.c&2147483647,m=o[p],f=o[p+1],y=o[p+2];for(let b=0;b<n;b++){let A=b9(this.row(b),t.b,m,f,y,this.runCount);a[l+b]=A<0?0:Ns(u,c.storage,h[A]);}}}}dotRow(e,t,n,r){let o=Ie(this.flane(e,r)*this.flane(t,r));for(let s=1;s<n;s++)o=Ie(o+Ie(this.flane(e+s>>>0,r)*this.flane(t+s>>>0,r)));return o}simd(e,t,n){let r=x2(e,t);if(r===null)throw new _("invalid_argument",`vector kernel op 0x${e.dst.toString(16)} is malformed`);let o=r.width,s=NE(e.dst);if(s!==null){for(let u=0;u<o;u++)this.arith(R2(s,e,t,r,u),n);return}let a=this.bits,l=this.floats,c=(u,d)=>this.arith({op:H.MOV,dst:u,a:d,b:4294967295,c:4294967295},n);switch(e.dst){case hd:case md:case Dm:for(let u=0;u<o;u++)c(t.dst+u,lf(e,t,u));return;case pd:c(t.dst,lf(e,t,0));return;case Pm:{let u=t.dst*we;if(e.c===Wg){for(let d=0;d<n;d++)l[u+d]=this.dotRow(e.a,e.b,o,d);return}for(let d=0;d<n;d++){let h=Math.imul(this.lane(e.a,d),this.lane(e.b,d));for(let p=1;p<o;p++)h=h+Math.imul(this.lane(e.a+p>>>0,d),this.lane(e.b+p>>>0,d))|0;a[u+d]=h>>>0;}return}case Um:{let u=t.dst*we;for(let d=0;d<n;d++)l[u+d]=Math.sqrt(this.dotRow(e.a,e.a,o,d));return}case Bm:{for(let u=0;u<n;u++){let d=Ie(Math.sqrt(this.dotRow(e.a,e.a,o,u)));for(let h=0;h<o;h++){let p=(t.dst+h)*we+u;0<d?l[p]=this.flane(e.a+h>>>0,u)/d:a[p]=0;}}return}case Gm:for(let u=0;u<n;u++)v2.forEach(([d,h,p,m],f)=>{let y=Ie(this.flane(e.a+d>>>0,u)*this.flane(e.b+h>>>0,u)),b=Ie(this.flane(e.a+p>>>0,u)*this.flane(e.b+m>>>0,u));l[(t.dst+f)*we+u]=y-b;});return;case Fm:this.arith({op:e.b,dst:t.dst,a:e.a,b:e.a+1>>>0,c:4294967295},n);for(let u=2;u<o;u++)this.arith({op:e.b,dst:t.dst,a:t.dst,b:e.a+u>>>0,c:4294967295},n);return;default:throw new _("invalid_argument",`vector kernel op 0x${e.dst.toString(16)} is not supported by this SDK; update @cimplify/sdk`)}}neural(e,t,n){if(e.dst===FX){let c=e.b*we;for(let u=0;u<n;u++)this.mlpIn[c+u]=this.lane(e.a,u)>>>0;return}if(e.dst===UX){let c=e.a*we,u=t.dst*we;for(let d=0;d<n;d++)this.bits[u+d]=this.mlpOut[c+d];return}let r=this.columns[e.a],o=r.storage===Dr||r.storage===Bi?r.values:new Uint32Array(0),s=Math.min(this.lane(t.a,0)>>>0,o.length,this.capacity),a=this.mlpRow;if(e.dst===BX){let c=k9(o,s,e.b,e.c);for(let u=0;u<n;u++){c===null?a.fill(0):L9(c,this.mlpIn,u,we,a);for(let d=0;d<e.c;d++)this.mlpOut[d*we+u]=a[d];}return}let l=_2(o,s,e.b,e.c);for(let c=0;c<n;c++){l===null?a.fill(0):A2(l,this.mlpIn,c,we,a);for(let u=0;u<e.c;u++)this.mlpOut[u*we+c]=a[u];}}gather(e,t,n){let r=this.bits,o=t.dst*we,s=e.dst===Pa,a=this.program.slots;for(let l=0;l<n;l++){if(t.a!==4294967295&&this.lane(t.a,l)===0){r[o+l]=0;continue}let c=this.lane(e.b,l)>>>0;if(s)if(c<e.c){let u=this.columns[e.a+c];r[o+l]=Ns(a[e.a+c].kind,u.storage,u.values[this.row(l)]);}else r[o+l]=0;else {let u=this.columns[e.a],d=this.lane(e.c,l)>>>0;r[o+l]=c<d&&c<u.values.length?Ns(a[e.a].kind,u.storage,u.values[c]):0;}}}record(e,t,n){let r=this.records[this.program.cross.indexOf(e)],o=t.op===Ln.SCATTER,s=t.op===Ve&&gd(t.dst),a=t.op===Ln.COMPACT?4294967295:t.a,l=o||s?t.b:4294967295,c=o?this.program.code[e+1].b:t.op===Ln.COMPACT?t.a:s?t.c:t.b;for(let u=0;u<n;u++){let d=(this.visit+u)*pr;r[d]=a===4294967295?0:this.lane(a,u),r[d+1]=l===4294967295?0:this.lane(l,u),r[d+2]=c===4294967295||this.lane(c,u)!==0?1:0,r[d+3]=this.row(u);}}finishExtended(e,t,n){switch(Di(this.program.code[e].dst)){case An.CROSS:gd(this.program.code[e].dst)?this.finishRecurrence(e,t,n):this.finishSort(e,t,n);return;case An.SYSTEMS:_9(this.graphHost(),this.program.code[e],this.program.code[e+1],this.records[t],n);return;default:throw new _("invalid_argument",`extended kernel op 0x${this.program.code[e].dst.toString(16)} does not end a stage`)}}graphHost(){return this.graphCache!==null?this.graphCache:(this.graphCache={capacity:this.capacity,buffers:this.sorting,lane:(e,t)=>this.lane(e,t),uniform:e=>this.u(e),setUniform:(e,t)=>{this.uniforms[e]=t;},writeRow:(e,t,n)=>{let r=this.columns[e];r.values[t]=Va(this.program.slots[e].kind,r.storage,n);},array:e=>this.columns[e].values},this.graphCache)}finishRecurrence(e,t,n){if(this.program.code[e].dst===kC)return;let o=this.program.code[e+1],s=o.c,a=s&zX,l=$X(a)===J2e,c=(s&Kg)!==0,u=(s&QX)!==0,d=this.uniforms,h=this.recurState,p=this.recurBefore,m=this.recurOut;h[0]=o.a===4294967295?G9(a):this.u(o.a),h[1]=o.a!==4294967295&&l?this.u(o.a+1):0;let f=this.columns[o.dst],y=this.program.slots[o.dst].kind,b=c?this.columns[o.dst+1]:f,A=c?this.program.slots[o.dst+1].kind:y,E=this.records[t],R=a===at.FEEDBACK_F32?this.records[t-1]:null;for(let g=0;g<n;g++){let v=g*pr;if(E[v+2]===0)continue;p[0]=h[0],p[1]=h[1],V9(a,h,E[v],E[v+1],R===null?0:R[v]),H9(a,s,u?p:h,m);let x=E[v+3];f.values[x]=Va(y,f.storage,m[0]),c&&(b.values[x]=Va(A,b.storage,m[1]));}o.b!==4294967295&&(d[o.b]=h[0],l&&(d[o.b+1]=h[1]));}finishSort(e,t,n){let r=this.program.code[e],o=this.program.code[e+1],s=this.records[t],a=this.capacity,l=r.c&JX,c=(r.c&ZX)!==0?4294967295:0,u=this.sorting.subarray(0,a),d=this.sorting.subarray(a,2*a),h=this.sorting.subarray(2*a,3*a),p=this.sorting.subarray(3*a,4*a),m=0;for(let A=0;A<n;A++){let E=A*pr;s[E+2]!==0&&(u[m]=(qg(l,s[E])^c)>>>0,d[m]=s[E+3],m++);}let f=1<<Xg,y=this.sortCounts;for(let A=0;A<32;A+=Xg){y.fill(0);for(let v=0;v<m;v++)y[u[v]>>>A&f-1]++;let E=0;for(let v=0;v<f;v++){let x=y[v];y[v]=E,E+=x;}for(let v=0;v<m;v++){let x=u[v]>>>A&f-1;h[y[x]]=u[v],p[y[x]]=d[v],y[x]++;}let R=u;u=h,h=R;let g=d;d=p,p=g;}let b;if(r.dst===CC||r.dst===NC){let A=r.dst===NC?Math.min(this.u(o.b),m):m,E=this.columns[o.dst].values;for(let R=0;R<A;R++)E[R]=d[R];b=A;}else {let A=this.program.slots[o.dst],E=this.columns[o.dst],R=0;for(let g=0;g<m;g++){let v=g===0||u[g]!==u[g-1];v&&R++,E.values[d[g]]=Va(A.kind,E.storage,r.dst===qX?R-1:v?1:0);}b=R;}this.uniforms[o.a]=b;}finishCross(e,t,n){let r=this.program.code[e];if(r.op===Ve){this.finishExtended(e,t,n);return}let o=this.records[t],s=Ln,a=(l,c)=>{let u=l;for(let d=0;d<n;d+=Lm){let h=l;for(let p=d;p<Math.min(n,d+Lm);p++)o[p*pr+2]!==0&&(h=c(h,Kn(o[p*pr])));u=c(u,h);}return u};switch(r.op){case s.REDUCE:{let l;if(r.c===hX)l=Nd(a(0,(c,u)=>Ie(c+u)));else if(r.c===mX)l=Nd(a(1/0,DE));else if(r.c===fX)l=Nd(a(-1/0,PE));else {let c=[0,0,0,0,2147483647,2147483648,4294967295,0][r.c],u=(d,h)=>{switch(r.c){case pX:return d+h>>>0;case _X:return ((d|0)<(h|0)?d:h)>>>0;case yX:return ((d|0)>(h|0)?d:h)>>>0;case AX:return Math.min(d>>>0,h>>>0);default:return Math.max(d>>>0,h>>>0)}};l=c;for(let d=0;d<n;d++)o[d*pr+2]!==0&&(l=u(l,o[d*pr]));}this.uniforms[r.dst]=l>>>0;return}case s.ARG:{let l=(h,p)=>{switch(r.c){case bX:return Kn(h)<Kn(p);case bC:return Kn(h)>Kn(p);case gX:return (h|0)<(p|0);case EX:return (h|0)>(p|0);case xX:return h>>>0<p>>>0;default:return h>>>0>p>>>0}},c=r.c<=bC,u=0,d=4294967295;for(let h=0;h<n;h++){let p=h*pr;o[p+2]===0||c&&Number.isNaN(Kn(o[p]))||(d===4294967295||l(o[p],u))&&(u=o[p],d=o[p+3]);}this.uniforms[r.dst]=d;return}case s.HIST:{let l=this.u(r.c),c=this.columns[r.dst].values;for(let u=0;u<n;u++){let d=u*pr;o[d+2]!==0&&o[d]<l&&(c[o[d]]=c[o[d]]+1>>>0);}return}case s.SCATTER:{let l=this.u(this.program.code[e+1].a),c=this.columns[r.dst].values;for(let u=0;u<n;u++){let d=u*pr;if(o[d+2]===0||o[d]>=l)continue;let h=o[d];c[h]=r.c===vX?Ie(c[h]+Kn(o[d+1])):c[h]+o[d+1]>>>0;}return}case s.SCAN:{let l=this.program.slots[r.dst],c=this.columns[r.dst],u=r.c===RX||r.c===TX;if(r.c<=SX){let d=0;for(let h=0;h<n;h+=Lm){let p=0;for(let m=h;m<Math.min(n,h+Lm);m++){let f=m*pr;if(o[f+2]===0)continue;let y=p;p=Ie(p+Kn(o[f])),c.values[o[f+3]]=Va(l.kind,c.storage,Nd(Ie(d+(u?p:y))));}d=Ie(d+p);}}else {let d=0;for(let h=0;h<n;h++){let p=h*pr;if(o[p+2]===0)continue;let m=d;d=d+o[p]>>>0,c.values[o[p+3]]=Va(l.kind,c.storage,u?d:m);}}return}case s.COMPACT:{let l=this.columns[r.dst].values,c=0;for(let u=0;u<n;u++){let d=u*pr;o[d+2]!==0&&(l[c++]=o[d+3]);}this.uniforms[r.b]=c;return}}}trips(e,t){let n=this.u(e),r;if((t&Ng)!==0){let o=Kn(n);r=o>0?Math.min(Math.ceil(o),65536):0;}else r=Math.max(n|0,0);return Math.min(r,65536)}neighbours(e,t,n,r){let[o,s,a]=this.program.position,l=new Float32Array(this.snapshot[o].buffer),c=new Float32Array(this.snapshot[s].buffer),u=a===4294967295?null:new Float32Array(this.snapshot[a].buffer),d=0;for(let h=0;h<r;h++){if(n!==4294967295&&this.lane(n,h)===0)continue;let p=this.row(h);this.grid.walk(l[p],c[p],u===null?0:u[p],p,this.found);for(let m of this.found)if(this.pairLane[d]=h,this.pairRow[d]=m,d++,d===we){let f=this.listMode,y=this.base;this.exec(e,t,we),this.listMode=f,this.base=y,d=0;}}d>0&&this.exec(e,t,d);}source(e,t,n){return e===4294967295?this.splats[t]:this.isUniform(e)?this.splats[t].fill(this.u(e),0,n):this.bits.subarray(e*we,e*we+we)}arith(e,t){let n=this.bits;this.floats;let o=e.dst*we,s=this.source(e.a,0,t),a=this.source(e.b,1,t),l=this.source(e.c,2,t),c=new Float32Array(s.buffer,s.byteOffset,we),u=new Float32Array(a.buffer,a.byteOffset,we),d=new Float32Array(l.buffer,l.byteOffset,we),h=S=>c[S],p=S=>u[S],m=S=>d[S],f=S=>s[S],y=S=>a[S],b=S=>l[S],A=this.scratch,E=this.fscratch,R=S=>{for(let w=0;w<t;w++)E[w]=S(h(w));},g=S=>{for(let w=0;w<t;w++)E[w]=S(h(w),p(w));},v=S=>{for(let w=0;w<t;w++)E[w]=S(h(w),p(w),m(w));},x=S=>{for(let w=0;w<t;w++)A[w]=S(f(w));},O=S=>{for(let w=0;w<t;w++)A[w]=S(f(w),y(w));},N=S=>{for(let w=0;w<t;w++)A[w]=S(h(w),p(w))?cf:0;},I=S=>{for(let w=0;w<t;w++)A[w]=S(f(w),y(w))?cf:0;};switch(e.op){case H.MOV:x(S=>S);break;case H.SEL:for(let S=0;S<t;S++)A[S]=f(S)!==0?y(S):b(S);break;case H.FADD:g((S,w)=>S+w);break;case H.FSUB:g((S,w)=>S-w);break;case H.FMUL:g((S,w)=>S*w);break;case H.FDIV:g((S,w)=>S/w);break;case H.FMIN:g(DE);break;case H.FMAX:g(PE);break;case H.FMOD:for(let S=0;S<t;S++){let w=h(S)%p(S);Number.isNaN(w)?A[S]=JC:E[S]=w;}break;case H.FPOW:g(a7);break;case H.FATAN2:g(c7);break;case H.FLEN2:g((S,w)=>Math.sqrt(Ie(Ie(S*S)+Ie(w*w))));break;case H.FMULADD:v((S,w,U)=>Ie(S*w)+U);break;case H.FMULSUB:v((S,w,U)=>Ie(S*w)-U);break;case H.FSUBMUL:v((S,w,U)=>Ie(S-w)*U);break;case H.FADDMUL:v((S,w,U)=>Ie(S+w)*U);break;case H.FCLAMP:v((S,w,U)=>DE(PE(S,w),U));break;case H.FLERP:v((S,w,U)=>S+Ie(Ie(w-S)*U));break;case H.FLEN3:v((S,w,U)=>Math.sqrt(Ie(Ie(Ie(S*S)+Ie(w*w))+Ie(U*U))));break;case H.NOISE3:v(U2);break;case H.FNEG:x(S=>(S^2147483648)>>>0);break;case H.FABS:x(S=>(S&2147483647)>>>0);break;case H.FSQRT:R(Math.sqrt);break;case H.FFLOOR:R(Math.floor);break;case H.FCEIL:R(Math.ceil);break;case H.FROUND:R(iNe);break;case H.FTRUNC:R(Math.trunc);break;case H.FSIGN:R(oNe);break;case H.FSIN:R(sE);break;case H.FCOS:R(aE);break;case H.FTAN:R(l7);break;case H.FASIN:R(d7);break;case H.FACOS:R(h7);break;case H.FATAN:R(u7);break;case H.FEXP:R(r7);break;case H.FLOG:R(o7);break;case H.FLOG2:R(s7);break;case H.FLT:N((S,w)=>S<w);break;case H.FLE:N((S,w)=>S<=w);break;case H.FEQ:N((S,w)=>S===w);break;case H.FNE:N((S,w)=>S!==w);break;case H.IADD:O((S,w)=>S+w>>>0);break;case H.ISUB:O((S,w)=>S-w>>>0);break;case H.IMUL:O((S,w)=>Math.imul(S,w)>>>0);break;case H.IREM:O((S,w)=>w===0?0:((S|0)%(w|0)|0)>>>0);break;case H.UREM:O((S,w)=>w===0?0:S%w);break;case H.IAND:O((S,w)=>(S&w)>>>0);break;case H.IOR:O((S,w)=>(S|w)>>>0);break;case H.IXOR:O((S,w)=>(S^w)>>>0);break;case H.ISHL:O((S,w)=>S<<(w&31)>>>0);break;case H.ISHR:O((S,w)=>(S|0)>>(w&31)>>>0);break;case H.IUSHR:O((S,w)=>S>>>(w&31));break;case H.IMIN:O((S,w)=>Math.min(S|0,w|0)>>>0);break;case H.IMAX:O((S,w)=>Math.max(S|0,w|0)>>>0);break;case H.UMIN:O(Math.min);break;case H.UMAX:O(Math.max);break;case H.INEG:x(S=>-S>>>0);break;case H.IABS:x(S=>Math.abs(S|0)>>>0);break;case H.INOT:x(S=>~S>>>0);break;case H.ILT:I((S,w)=>(S|0)<(w|0));break;case H.ILE:I((S,w)=>(S|0)<=(w|0));break;case H.IEQ:I((S,w)=>S===w);break;case H.INE:I((S,w)=>S!==w);break;case H.ULT:I((S,w)=>S<w);break;case H.ULE:I((S,w)=>S<=w);break;case H.ITOF:for(let S=0;S<t;S++)E[S]=f(S)|0;break;case H.UTOF:for(let S=0;S<t;S++)E[S]=f(S);break;case H.FTOI:for(let S=0;S<t;S++)A[S]=P2(h(S))>>>0;break;case H.BTOF:for(let S=0;S<t;S++)E[S]=f(S)!==0?1:0;break;case H.BTOI:x(S=>S!==0?1:0);break;case H.FTOB:for(let S=0;S<t;S++)A[S]=h(S)!==0&&!Number.isNaN(h(S))?cf:0;break;case H.ITOB:x(S=>S!==0?cf:0);break;case H.MAND:O((S,w)=>(S&w)>>>0);break;case H.MOR:O((S,w)=>(S|w)>>>0);break;case H.MANDN:O((S,w)=>(S&~w)>>>0);break;case H.MNOT:x(S=>~S>>>0);break;case H.NOISE2:g(F2);break;case H.HASH:O(K9);break;case H.RAND:for(let S=0;S<t;S++)E[S]=lNe(f(S),y(S));break;case H.UADDC:for(let S=0;S<t;S++)A[S]=f(S)+y(S)+(b(S)&1)>=eNe?1:0;break;case H.USUBB:for(let S=0;S<t;S++)A[S]=f(S)<y(S)+(b(S)&1)?1:0;break;case H.UMULHI:for(let S=0;S<t;S++)A[S]=tNe(f(S),y(S));break;default:throw new _("invalid_argument",`kernel opcode ${e.op} is not part of instruction set ${4}`)}n.set(t===we?A:A.subarray(0,t),o);}};var cNe={vec2:2,vec3:3,vec4:4},uNe=["x","y","z","w"],dNe=4294967295,hNe=tq("kernel.spawnOverflow",{dropped:"u32",capacity:"u32",table:"u32"});function pNe(i){return i instanceof Float32Array?Yn:i instanceof Int32Array?Bi:i instanceof Uint32Array?Dr:kd}function B2(i){let e=[];for(let t of Object.keys(i.schema)){let n=cNe[i.schema[t]]??1;for(let r=0;r<n;r++)e.push(i.values(t,r));}return e}var gf=class{constructor(e,t){this.table=e;this.bySlot=new Map;this.columns=B2(e),t!==null&&t.slots.forEach((n,r)=>{if(n.spawn!==true)return;if(!(n.field in e.schema))throw new _("invalid_argument",`kernel ${t.name} spawns ${n.field}, which the spawn table does not have`);let o=e.values(n.field,n.component);this.bySlot.set(r,{values:o,storage:pNe(o)});});}get capacity(){return this.table.capacity}get count(){return this.table.count}set count(e){this.table.count=e;}column(e){let t=this.bySlot.get(e);if(t===void 0)throw new _("invalid_argument","the spawn table has no column for this kernel field");return t}};function Ef(i,e,t){return t.spawned=i.spawned,t.dropped=i.dropped,t.killed=i.killed,i.dropped>0&&($g(dNe),hNe.emit({dropped:i.dropped,capacity:e.capacity,table:e.id>>>0})),t}function G2(i,e,t){if(typeof e=="number")t.push([i,0,e]);else if(typeof e=="boolean")t.push([i,0,e?1:0]);else if(e!==null&&typeof e=="object"){let n=e,r=Object.keys(n);if(r.length>=2&&r.length<=4&&r.every((o,s)=>o===uNe[s])&&r.every(o=>typeof n[o]=="number")){r.forEach((o,s)=>t.push([i,s,n[o]]));return}if(Array.isArray(e)){e.forEach((o,s)=>G2(`${i}.${s}`,o,t));return}for(let o of r)G2(i.length===0?o:`${i}.${o}`,n[o],t);}}var GE=class{constructor(){this.pending=[];this.kills=new Set;this.sequence=0;}spawn(e,t){let n=[];G2("",t,n),this.pending.push({row:e,order:this.sequence++,fields:n});}kill(e){this.kills.add(e);}get used(){return this.pending.length>0||this.kills.size>0}finish(e,t,n){if(n.spawned=0,n.dropped=0,n.killed=0,this.kills.size>0){let a=B2(e),l=e.count,c=0;for(let u=0;u<l;u++)if(!this.kills.has(u)){if(c!==u)for(let d of a)d[c]=d[u];c++;}n.killed=l-c,e.count=c;}let r=t??e,o=this.pending.sort((a,l)=>a.row-l.row||a.order-l.order),s=B2(r);for(let a of o){let l=r.count;if(l>=r.capacity){n.dropped++;continue}for(let c of s)c[l]=0;for(let[c,u,d]of a.fields){if(!(c in r.schema))throw new _("invalid_argument",`spawn() sets ${c}, which the spawn table does not have`);let h=r.values(c,u);h[l]=h instanceof Float32Array?d:Math.trunc(d);}r.count=l+1,n.spawned++;}return this.pending=[],this.kills.clear(),this.sequence=0,n}};var mNe=0xffffffffn;function X9(i,e){return Io(i,e)}function q9(i,e){return mc(i,e)}var V2=new Float64Array(1),Y9=new Uint32Array(V2.buffer);function Wa(i,e,t,n){if(t==="u64"){let o=typeof n=="bigint"?BigInt.asUintN(64,n):e2(Number(n));return i[e]=Number(o&mNe),i[e+1]=Number(o>>32n),e+2}V2[0]=typeof n=="bigint"?Number(n):n;let r=Number.isNaN(V2[0]);return i[e]=r?0:Y9[0],i[e+1]=r?2146959360:Y9[1],e+2}var z9=new WeakMap,H2=null,fNe=4;function Q9(i){H2=i;}function $9(i,e,t,n,r){let o=z9.get(i);o===void 0&&(o=new Map,z9.set(i,o));let s=`${e}#${r}`,a=i.capacity*t,l=o.get(s);if(l===void 0||l.words!==a||l.kind!==n){let c=i.native?H2:null,u=c===null?0:c.alloc(a*fNe);if(c!==null&&u===0)throw new _("capacity_exceeded",`engine memory cannot hold the ${e} list pool`);u!==0&&c!==null&&new Uint32Array(c.memory.buffer,u,a).fill(0),l={at:u,words:a,kind:n,array:null},o.set(s,l);}return l}function _Ne(i){if(i.at===0)return i.array??=i.kind==="f32"?new Float32Array(i.words):i.kind==="i32"?new Int32Array(i.words):new Uint32Array(i.words),i.array;let e=H2.memory.buffer;return (i.array===null||i.array.buffer!==e)&&(i.array=i.kind==="f32"?new Float32Array(e,i.at,i.words):i.kind==="i32"?new Int32Array(e,i.at,i.words):new Uint32Array(e,i.at,i.words)),i.array}function yNe(i,e,t,n="u32",r=0){return _Ne($9(i,e,t,n==="bool"?"u32":n,r))}function j9(i,e,t,n="u32",r=0){let o=$9(i,e,t,n==="bool"?"u32":n,r);return {at:o.at,words:o.words}}function J9(i,e){let t={};(i.data?.tallies??[]).forEach((a,l)=>{t[a]=e[l];});let n=e[uc+5],r=[],o=uc+6+n;for(let a=0;a<n;a++){let l=e[uc+6+a];r.push(e.slice(o,o+l)),o+=l;}let s=uc;return {picks:r,tallies:t,commands:{sent:e[s],applied:e[s+1],dropped:e[s+2],overflow:e[s+3]},unplaced:e[s+4]}}var ANe={f32:0,i32:1,u32:2,u8:3,vec2:0,vec3:0,vec4:0};function bNe(i,e,t,n){if(!(e in i.schema))throw new _("invalid_argument",`kernel ${n} reads ${e}, which its table does not have`);return {values:i.values(e,t),storage:ANe[i.schema[e]]}}function gNe(i){return typeof i=="object"&&i!==null&&"schema"in i&&"capacity"in i&&"values"in i}function ks(i){if(i.data!==void 0)return true;let e=i.slots;for(let t=0;t<e.length;t++)if(e[t].table!==void 0)return true;return false}function Ka(i,e,t){let n=[e];for(let r of i.data?.tables??[]){let o=t[r.position];if(!gNe(o))throw new _("invalid_argument",`kernel ${i.name} takes the table for ${r.name} as argument ${r.position+1}; pass an entity table`);n[r.table]=o;}return n}function Z9(i,e){let t=new Set((i.data?.tables??[]).map(n=>n.position));return e.filter((n,r)=>!t.has(r))}function ez(i,e,t){if(t.table===void 0)return null;let n=e[t.table];return t.pool!==void 0?{values:yNe(n,t.field,t.pool,t.kind,t.component),storage:t.kind==="f32"?0:t.kind==="i32"?1:2}:bNe(n,t.field,t.component,i.name)}function tz(i,e,t,n,r){for(let o of e.data?.tables??[]){let s=t[o.table];r.get(o.table)!==s.capacity&&(i.bindTable(o.table,s.capacity),r.set(o.table,s.capacity)),i.setCount(o.table,s.count);}e.slots.forEach((o,s)=>{o.pool!==void 0&&r.get(-1-s)!==n[s].values.length&&(i.bindPool(s,n[s].values.length),r.set(-1-s,n[s].values.length));});}function nz(i,e){let t={};return (e.data?.tallies??[]).forEach((n,r)=>{t[n]=i.tallies[r];}),{picks:Array.from({length:e.data?.picks??0},(n,r)=>i.pickRows(r).slice()),tallies:t,commands:{...i.stats},unplaced:i.unplaced}}var ENe=new Uint32Array(1);new Float32Array(ENe.buffer);var Xa=["sin","cos","tan","asin","acos","atan","exp","log","log2","pow","atan2"],pz=new Set(["pow","atan2"]),Jt=127,xf=126,Vd=125,Le=124,ft=64,rz=2,xNe=4,vNe=5,VE=11,RNe=12,SNe=14,ko=15,Bd=27,TNe=32,wNe=33,INe=34,ONe=65,CNe=66,NNe=67,kNe=68,vf=69,Pd=70,HE=71,WE=73,W2=75,mz=79,LNe=83,J2=92,iz=97,oz=98;var Rf=100,MNe=101,Fd=106,Hd=107,jt=113,Sf=114,Lo=116,fz=117,Ud=118,z2=124,DNe=125,K2=126,PNe=131,FNe=132,Q2=134,sz=136,$2=153,_z=154,UNe=159,rt=160,Ya=161,Re=162,KE=163,yz=164,Az=165,bz=167,BNe=170,gz=173,Mo=182,YE=183,GNe=185,mr=187,Wd=188,Ez=189,xz=190,VNe=191,vz=2143289344,Dd=2147483648,Rz=2147483647,HNe=4286578688,j2=4278190080,WNe=4278190079,KNe=4294967295,YNe=32,XNe=16,qNe=re.ATAN_COEFFS.length;function No(i,e){let t=e>>>0;do{let n=t&127;t>>>=7,t!==0&&(n|=128),i.push(n);}while(t!==0)}function az(i,e){let t=e;for(;;){let n=Number(t&0x7fn);t>>=7n;let r=t===0n&&(n&64)===0||t===-1n&&(n&64)!==0;if(i.push(r?n:n|128),r)return}}var Gi=class{constructor(e){this.params=e;this.code=[];this.kinds=[];}local(e){return this.kinds.push(e),this.params+this.kinds.length-1}op(...e){for(let t of e)this.code.push(t);return this}get(e){return this.code.push(TNe),No(this.code,e),this}set(e){return this.code.push(wNe),No(this.code,e),this}tee(e){return this.code.push(INe),No(this.code,e),this}i32(e){return this.code.push(ONe),az(this.code,BigInt(e|0)),this}i64(e){return this.code.push(CNe),az(this.code,BigInt.asIntN(64,e)),this}f32bits(e){this.code.push(NNe);let t=e>>>0;return this.code.push(t&255,t>>>8&255,t>>>16&255,t>>>24),this}f64(e){this.code.push(kNe);for(let t of new Uint8Array(new Float64Array([e]).buffer))this.code.push(t);return this}when(e,t,n){return this.code.push(xNe,e),t(),n!==void 0&&(this.code.push(vNe),n()),this.code.push(VE),this}returnNan(){return this.f32bits(vz).op(ko)}table(e,t,n){let r=n.length;this.code.push(rz,t);for(let o=0;o<r;o++)this.code.push(rz,ft);this.get(e).op(SNe),No(this.code,r-1);for(let o=0;o<r;o++)No(this.code,o);this.code.push(VE);for(let o=0;o<r;o++)n[o](),o<r-1&&(this.code.push(RNe),No(this.code,r-1-o)),this.code.push(VE);return this}f64Table(e,t){return this.table(e,Le,t.map(n=>()=>this.f64(n)))}i64Table(e,t){return this.table(e,xf,t.map(n=>()=>this.i64(n)))}finish(){let e=[],t=[];for(let n of this.kinds){let r=t[t.length-1];r!==void 0&&r[1]===n?r[0]++:t.push([1,n]);}No(e,t.length);for(let[n,r]of t)No(e,n),e.push(r);for(let n of this.code)e.push(n);return e.push(VE),e}},zNe=re.EXP2_HI.map((i,e)=>BigInt(i>>>0)<<32n|BigInt(re.EXP2_LO[e]>>>0)),Y2=re.INV_PIO4.map(i=>BigInt(i>>>0));function Tf(i,e){i.f32bits(vz).get(e).get(e).get(e).op(J2).op(Bd);}function Sz(i,e,t,n){e(),i.f64(t).op(Az).f64(n).op(yz);}function Tz(i,e,t,n,r){let o=i.local(Le),s=i.local(Jt),a=i.local(Le),l=i.local(Le),c=i.local(Jt);i.get(e).f64(t).op(rt).set(o),i.get(o).op(Ez,bz).set(s),i.get(e).get(o).f64(t).op(Ya).op(Ya).set(a),i.get(s).i32(YNe-1).op(jt).set(c),i.i64Table(c,zNe),i.get(s),r(),i.op(Fd).i32(15).op(Lo).op(gz).i64(32n).op(Q2).op(z2).op(VNe).set(l),i.f64(n[0]).get(a).op(Re).f64(n[1]).op(rt),i.get(a).get(a).op(Re).op(Re),i.f64(n[2]).get(a).op(Re).f64(1).op(rt),i.op(rt).get(l).op(Re);}function wz(i,e,t){i.get(e).i32(Rz).op(jt).set(t),i.get(t).i32(re.MIN_NORMAL).op(WE),i.when(ft,()=>{i.get(t).op(xz,mr).f64(re.SUBNORMAL_SCALE).op(Re).op(Mo,Wd),i.i32(re.SUBNORMAL_BIAS).op(Hd).set(t);});}function Iz(i,e){let t=i.local(Jt),n=i.local(Jt),r=i.local(Jt),o=i.local(Jt),s=i.local(Le);return i.get(e).i32(re.LOG_OFF).op(Hd).set(t),i.get(t).i32(19).op(Ud).i32(XNe-1).op(jt).set(n),i.get(t).i32(HNe).op(jt).set(r),i.get(r).i32(23).op(fz).set(o),i.get(e).get(r).op(Hd).op(xz,mr),i.f64Table(n,re.INV_C).op(Re).f64(1).op(Ya).set(s),{i:n,k:o,r:s}}function QNe(i,e){let t=i.local(Jt);i.get(0).op(Wd).set(t),i.get(t).i32(1).op(Lo).op(vf).when(ft,()=>i.f32bits(4286578688).op(ko)),i.get(t).i32(re.INFINITY_BITS).op(Pd).when(ft,()=>i.get(0).op(ko)),i.get(t).i32(Dd).op(jt).i32(0).op(HE),i.get(t).i32(1).op(Lo).i32(j2).op(mz).op(Sf),i.when(ft,()=>i.returnNan()),i.get(e);}function lz(i){let e=new Gi(1),t=e.local(Jt),n=e.local(Le),r=e.local(Le),o=e.local(Vd);e.get(0).op(Wd).set(t),wz(e,t,t);let{i:s,k:a,r:l}=Iz(e,t),c=e.local(Le);if(i){e.f64Table(s,re.LOG2_C).get(a).op(YE).op(rt).set(c),e.get(l).get(l).op(Re).set(r),e.f64(re.LOG2_POLY[1]).get(l).op(Re).f64(re.LOG2_POLY[2]).op(rt).set(n),e.f64(re.LOG2_POLY[0]).get(r).op(Re).get(n).op(rt).set(n);let u=e.local(Le);e.f64(re.LOG2_POLY[3]).get(l).op(Re).get(c).op(rt).set(u),e.get(n).get(r).op(Re).get(u).op(rt).set(n);}else e.f64Table(s,re.LOG_C).get(a).op(YE).f64(re.LN2).op(Re).op(rt).set(c),e.get(l).get(l).op(Re).set(r),e.f64(re.LOG_POLY[1]).get(l).op(Re).f64(re.LOG_POLY[2]).op(rt).set(n),e.f64(re.LOG_POLY[0]).get(r).op(Re).get(n).op(rt).set(n),e.get(n).get(r).op(Re).get(c).get(l).op(rt).op(rt).set(n);return e.get(n).op(Mo).set(o),QNe(e,o),e.set(o),Tf(e,o),e.finish()}function $Ne(){let i=new Gi(1),e=i.local(Le),t=i.local(Vd);return i.get(0).get(0).op(J2).when(ft,()=>i.returnNan()),i.f64(re.INV_LN2_N),Sz(i,()=>i.get(0).op(mr),re.EXP_LOW,re.EXP_HIGH),i.op(Re).set(e),Tz(i,e,re.SHIFT,re.EXP_POLY,()=>i.i32(0)),i.op(Mo).set(t),Tf(i,t),i.finish()}function cz(i,e){i.get(e).i32(1).op(Lo).i32(1).op(Hd).i32(WNe).op(mz);}function jNe(){let i=new Gi(2),e=i.local(Jt),t=i.local(Jt),n=i.local(Jt),r=i.local(Jt),o=i.local(Jt),s=i.local(Jt),a=i.local(Jt),l=i.local(Le),c=i.local(Le),u=i.local(Jt),d=i.local(Vd),h=()=>i.get(0).op(mr),p=()=>i.get(1).op(mr);i.get(0).op(Wd).set(e),i.get(1).op(Wd).set(t),i.get(e).i32(Rz).op(jt).set(n),cz(i,t),i.when(ft,()=>{i.get(t).i32(1).op(Lo).op(vf).get(e).i32(re.ONE_BITS).op(Pd).op(Sf),i.when(ft,()=>i.f32bits(re.ONE_BITS).op(ko)),i.get(e).i32(1).op(Lo).i32(j2).op(W2),i.get(t).i32(1).op(Lo).i32(j2).op(W2).op(Sf),i.when(ft,()=>i.returnNan()),i.get(n).i32(re.ONE_BITS).op(Pd).when(ft,()=>i.f32bits(re.ONE_BITS).op(ko)),i.get(n).i32(re.ONE_BITS).op(WE).get(t).i32(Dd).op(jt).op(vf).op(Pd),i.when(ft,()=>i.f32bits(0).op(ko)),p().get(1).op(mr).op(Re).op(Mo).op(ko);}),i.get(t).i32(23).op(Ud).i32(255).op(jt).set(s),i.get(s).i32(127).op(WE),i.when(ft,()=>i.i32(0).set(r),()=>{i.get(s).i32(150).op(W2),i.when(ft,()=>i.i32(2).set(r),()=>{i.i32(150).get(s).op(Hd).set(a),i.get(t).i32(1).get(a).op(Lo).i32(1).op(Hd).op(jt).i32(0).op(HE),i.when(ft,()=>i.i32(0).set(r),()=>{i.i32(1).i32(2).get(t).i32(1).get(a).op(Lo).op(jt).op(Bd).set(r);});});}),i.get(e).i32(Dd).op(jt).i32(0).op(HE).get(r).i32(1).op(Pd).op(jt).set(o),cz(i,e),i.when(ft,()=>{i.get(0).get(0).op(J2).when(ft,()=>i.returnNan()),h().get(0).op(mr).op(Re).op(Mo,mr).set(l),i.get(o).when(ft,()=>i.get(l).op(_z).set(l)),i.get(t).i32(Dd).op(jt),i.when(Vd,()=>i.f64(1).get(l).op(KE).op(Mo),()=>i.get(l).op(Mo)),i.op(ko);}),i.get(e).i32(Dd).op(jt).i32(0).op(HE).get(r).op(vf).op(jt).when(ft,()=>i.returnNan()),wz(i,e,u);let{i:m,k:f,r:y}=Iz(i,u),b=i.local(Le),A=i.local(Le),E=i.local(Le);i.f64Table(m,re.LOG2_C).get(f).op(YE).op(rt).set(b),i.get(y).get(y).op(Re).set(A),p(),i.f64(re.POW_POLY[0]).get(y).op(Re).f64(re.POW_POLY[1]).op(rt),i.get(A).get(A).op(Re).op(Re),i.f64(re.POW_POLY[4]).get(y).op(Re).get(b).op(rt).set(E),i.f64(re.POW_POLY[2]).get(y).op(Re).f64(re.POW_POLY[3]).op(rt).get(A).op(Re).get(E).op(rt),i.op(rt).op(Re).set(c);let R=v=>{i.f32bits(v|Dd).f32bits(v).get(o).op(Bd).op(ko);};i.get(c).f64(re.POW_OVERFLOW).op(Rf).when(ft,()=>R(re.INFINITY_BITS)),i.get(c).f64(re.POW_SATURATE).op(Rf).when(ft,()=>R(2139095039)),i.get(c).f64(re.POW_UNDERFLOW).op(MNe).when(ft,()=>R(0));let g=i.local(Le);return Sz(i,()=>i.get(c),re.EXP2_LOW,re.EXP2_HIGH),i.set(g),Tz(i,g,re.SHIFT_SCALED,re.EXP2_POLY,()=>i.i32(re.POW_SIGN_BIAS).i32(0).get(o).op(Bd)),i.op(Mo).set(d),Tf(i,d),i.finish()}function uz(i,e,t){i.f64(-1).f64(1).get(e),t===1&&i.i32(1).op(Fd),i.i32(2).op(jt).op(Bd);}function JNe(i,e,t,n){let r=i.local(Jt),o=i.local(Le),s=i.local(Jt),a=i.local(Jt),l=i.local(Le),c=i.local(Le);i.get(0).op(Wd).set(r),i.get(r).i32(20).op(Ud).i32(2047).op(jt).i32(re.LARGE_TOP).op(WE),i.when(ft,()=>{i.get(0).op(mr).f64(re.HPI_INV).op(Re).op(BNe).i32(re.QUADRANT_ROUND).op(Fd).i32(24).op(fz).tee(s).set(a),i.get(0).op(mr).get(s).op(YE).f64(re.HPI).op(Re).op(Ya).set(o);},()=>{i.get(r).i32(re.INFINITY_BITS).op(jt).i32(re.INFINITY_BITS).op(Pd).when(ft,()=>i.returnNan());let b=i.local(Jt),A=i.local(xf),E=i.local(xf),R=i.local(xf),g=i.local(Jt),v=i.local(xf);i.get(r).i32(26).op(Ud).i32(15).op(jt).set(b),i.get(r).i32(16777215).op(jt).i32(8388608).op(Sf).get(r).i32(23).op(Ud).i32(7).op(jt).op(Lo).op(gz).set(A),i.get(A).get(b).set(g).i64Table(g,Y2).op(K2).i64(BigInt(KNe)).op(PNe).set(E),i.get(b).i32(8).op(Fd).set(g),i.get(A).i64Table(g,Y2).op(K2).i64(32n).op(sz).get(E).i64(32n).op(Q2).op(FNe).set(R),i.get(b).i32(4).op(Fd).set(g),i.get(R).get(A).i64Table(g,Y2).op(K2).op(z2).set(R),i.get(R).i64(1n<<61n).op(z2).i64(62n).op(sz).set(v),i.get(R).get(v).i64(62n).op(Q2).op(DNe).set(R),i.get(R).op(GNe).f64(re.PI63).op(Re).set(o),i.get(v).op(bz).tee(s).get(r).i32(31).op(Ud).op(Fd).set(a);}),uz(i,a,2),i.set(l),uz(i,a,1),i.set(c);let u=i.local(Le),d=i.local(Le),h=i.local(Le),p=i.local(Le);i.get(o).get(c).op(Re).set(u),i.get(o).get(o).op(Re).set(d),i.get(d).get(u).op(Re).set(h),i.get(d).get(d).op(Re).set(p);let m=()=>{i.get(u).get(h).f64(re.SIN_S1).op(Re).op(rt),i.get(h).get(d).op(Re),i.f64(re.SIN_S2).get(d).f64(re.SIN_S3).op(Re).op(rt),i.op(Re).op(rt);},f=()=>{i.get(l).get(d).f64(re.COS_C1).get(l).op(Re).op(Re).op(rt),i.get(p).f64(re.COS_C2).get(l).op(Re).op(Re).op(rt),i.get(p).get(d).op(Re),i.f64(re.COS_C3).get(l).op(Re).get(d).f64(re.COS_C4).get(l).op(Re).op(Re).op(rt),i.op(Re).op(rt);},y=()=>i.get(s).i32(1).op(jt);n!=="cos"&&(y().when(Le,f,m),i.set(e)),n!=="sin"&&(y().when(Le,m,f),i.set(t));}function ZNe(i){let e=new Gi(1),t=e.local(Le),n=e.local(Le),r=e.local(Vd);return JNe(e,t,n,i),i==="sin"?e.get(t):i==="cos"?e.get(n):e.get(t).get(n).op(KE),e.op(Mo).set(r),Tf(e,r),e.finish()}function dz(i,e){i.get(e).op(Ez).i64(0n).op(LNe);}function eke(i,e,t,n){i.get(t).get(t).op(oz).get(e).get(e).op(oz).op(Sf).when(ft,()=>i.returnNan());let r=i.local(Le),o=i.local(Le),s=i.local(Le),a=i.local(Le),l=i.local(Le),c=i.local(Le),u=i.local(Le),d=i.local(Le),h=i.local(Jt);i.get(t).op($2).set(r),i.get(e).op($2).set(o),i.get(r).get(o).op(Az).set(s),i.get(r).get(o).op(yz).set(a),i.get(s).f64(0).op(iz),i.when(Le,()=>i.f64(0),()=>{i.get(a).f64(Number.POSITIVE_INFINITY).op(iz),i.when(Le,()=>i.f64(1),()=>i.get(a).get(s).op(KE));}),i.set(l),i.get(l).f64(re.TAN_PI_8).op(Rf).set(h),i.get(h),i.when(Le,()=>i.get(l).f64(1).op(Ya).get(l).f64(1).op(rt).op(KE),()=>i.get(l)),i.set(c),i.get(c).get(c).op(Re).set(u),i.f64(0).set(d);for(let p=qNe-1;p>=0;p--)i.f64(re.ATAN_COEFFS[p]).get(u).get(d).op(Re).op(rt).set(d);i.f64(re.QUARTER_PI).f64(0).get(h).op(Bd).get(c).get(d).op(Re).op(rt).set(n),i.get(o).get(r).op(Rf).when(ft,()=>i.f64(re.HALF_PI).get(n).op(Ya).set(n)),dz(i,t),i.when(ft,()=>i.f64(Math.PI).get(n).op(Ya).set(n)),dz(i,e),i.when(ft,()=>i.get(n).op(_z).set(n));}function tke(i){let e=new Gi(i==="atan2"?2:1),t=e.local(Le),n=e.local(Le),r=e.local(Le),o=e.local(Vd);if(i==="atan2")e.get(0).op(mr).set(t),e.get(1).op(mr).set(n);else if(i==="atan")e.get(0).op(mr).set(t),e.f64(1).set(n);else {let s=e.local(Le);e.get(0).op(mr).set(s),e.get(s).op($2).f64(1).op(Rf).when(ft,()=>e.returnNan()),e.f64(1).get(s).op(Ya).f64(1).get(s).op(rt).op(Re).op(UNe),i==="asin"?e.set(n).get(s).set(t):e.set(t).get(s).set(n);}return eke(e,t,n,r),e.get(r).op(Mo).set(o),Tf(e,o),e.finish()}function nke(i){switch(i){case "sin":case "cos":case "tan":return ZNe(i);case "exp":return $Ne();case "log":return lz(false);case "log2":return lz(true);case "pow":return jNe();default:return tke(i)}}var Fr=123,rke=253,ike=16,oke=4,At={shuffle:13,i32splat:17,f64splat:20,f32extract:31,f32replace:32,i32ne:56,i32ltU:58,and:78,bitselect:82,demoteZero:94,promoteLow:95,i32allTrue:163,i32shrS:172,i32shrU:173,i32add:174,i64extendLowS:199,f64add:240,f64sub:241,f64mul:242,truncSatZero:252,convertLow:254},ske=[8,9,10,11,12,13,14,15,8,9,10,11,12,13,14,15],ake=[0,1,2,3,4,5,6,7,16,17,18,19,20,21,22,23];function bt(i,e){return i.code.push(rke),No(i.code,e),i}function Pr(i,e){return bt(i.f64(e),At.f64splat)}function Gd(i,e){return bt(i.i32(e),At.i32splat)}function X2(i,e,t,n){i.get(e),t!==0&&bt(Gd(i,t),At.i32add),bt(Gd(i,n),At.and),bt(Gd(i,0),At.i32ne),bt(i,At.i64extendLowS);}function hz(i,e,t,n){let r=i.local(Fr),o=i.local(Fr),s=i.local(Fr),a=i.local(Fr),l=i.local(Fr),c=i.local(Fr),u=i.local(Fr),d=i.local(Fr),h=()=>bt(i,At.f64mul),p=()=>bt(i,At.f64add);i.get(e),bt(Pr(i,re.HPI_INV),At.f64mul),bt(i,At.truncSatZero),bt(Gd(i,re.QUADRANT_ROUND),At.i32add),i.i32(24),bt(i,At.i32shrS).set(r),i.get(e).get(r),bt(i,At.convertLow),Pr(i,re.HPI),h(),bt(i,At.f64sub).set(o),Pr(i,-1),Pr(i,1),X2(i,r,0,2),bt(i,At.bitselect).set(s),Pr(i,-1),Pr(i,1),X2(i,r,1,2),bt(i,At.bitselect).set(a),i.get(o).get(a),h().set(l),i.get(o).get(o),h().set(c),i.get(c).get(l),h().set(u),i.get(c).get(c),h().set(d);let m=()=>{i.get(l).get(u),Pr(i,re.SIN_S1),h(),p(),i.get(u).get(c),h(),Pr(i,re.SIN_S2).get(c),Pr(i,re.SIN_S3),h(),p(),h(),p();},f=()=>{i.get(s).get(c),Pr(i,re.COS_C1).get(s),h(),h(),p(),i.get(d),Pr(i,re.COS_C2).get(s),h(),h(),p(),i.get(d).get(c),h(),Pr(i,re.COS_C3).get(s),h(),i.get(c),Pr(i,re.COS_C4).get(s),h(),h(),p(),h(),p();};t==="sin"?(f(),m()):(m(),f()),X2(i,r,0,1),bt(i,At.bitselect),bt(i,At.demoteZero).set(n);}function lke(i,e){let t=new Gi(1),n=t.local(Fr),r=t.local(Fr),o=t.local(Fr),s=t.local(Fr),a=t.local(Fr);t.get(0).i32(20),bt(t,At.i32shrU),bt(Gd(t,2047),At.and),bt(Gd(t,re.LARGE_TOP),At.i32ltU),bt(t,At.i32allTrue).op(vf),t.when(ft,()=>{t.get(0).set(a);for(let l=0;l<oke;l++)t.get(a).get(0),bt(t,At.f32extract).op(l),t.op(ike),No(t.code,e),bt(t,At.f32replace).op(l).set(a);t.get(a).op(ko);}),t.get(0),bt(t,At.promoteLow).set(n),t.get(0).get(0),bt(t,At.shuffle);for(let l of ske)t.code.push(l);bt(t,At.promoteLow).set(r),hz(t,n,i,o),hz(t,r,i,s),t.get(o).get(s),bt(t,At.shuffle);for(let l of ake)t.code.push(l);return t.finish()}var XE=["sin","cos"];function Oz(i){return XE.map(e=>lke(e,i+Xa.indexOf(e)))}var q2=null;function Cz(){return q2===null&&(q2=Xa.map(nke)),q2}var lN=["fmod","noise2","noise3"],Cf=127,Ur=125,qE=124,Ls=64,Nz=3,cke=4,uke=5,sN=11,kz=12,QE=15,dke=69,wf=115,Z2=114,Lz=113,hke=106,If=108,zE=118,eN=91,Mz=92,pke=93,mke=96,fke=99,_ke=101,Dz=102,Kd=139,yke=142,Ake=146,$E=147,Yd=148,bke=161,tN=162,gke=166,Eke=167,xke=179,vke=182,nN=187,Rke=252,Ske=4,Tke=2143289344,aN=2139095040,Gz=0,wke=1065353216,Vz=1073741824,Ike=1077936128,Oke=1593835520,Cke=864026624,Pz=2,Nke=.5,kke=2376512323,Lke=3625334849,Mke=3407524639,Dke=2146121005,Pke=2221713035,Fz=16,Fke=15,Uke=8;function Bke(){let i=new Gi(2),e=0,t=1,n=i.local(qE),r=i.local(qE),o=i.local(qE),s=i.local(qE);return i.get(e).get(e).op(Mz),i.get(t).get(t).op(Mz).op(Z2),i.get(e).op(Kd).f32bits(aN).op(eN).op(Z2),i.get(t).f32bits(Gz).op(eN).op(Z2),i.when(Ls,()=>i.f32bits(Tke).op(QE)),i.get(t).op(Kd).f32bits(aN).op(eN),i.when(Ls,()=>i.get(e).op(QE)),i.get(e).op(Kd,nN).set(n),i.get(t).op(Kd,nN).set(r),i.get(n).get(r).op(fke),i.when(Ls,()=>i.get(e).op(QE)),i.get(r).set(s),i.op(Nz,Ls),i.get(s).f64(Pz).op(tN).get(n).op(_ke),i.when(Ls,()=>{i.get(s).f64(Pz).op(tN).set(s),i.op(kz,1);}),i.op(sN),i.get(n).set(o),i.op(Nz,Ls),i.get(s).get(r).op(Dz),i.when(Ls,()=>{i.get(o).get(s).op(Dz),i.when(Ls,()=>i.get(o).get(s).op(bke).set(o)),i.get(s).f64(Nke).op(tN).set(s),i.op(kz,1);}),i.op(sN),i.get(o).get(e).op(nN,gke,vke),i.finish()}function Gke(i,e,t){i.get(e).op(Kd).f32bits(Oke).op(mke),i.op(cke,Cf),i.i32(0),i.op(uke),i.get(e).op(Rke,Ske,Eke),i.op(sN),i.set(t);}function rN(i,e,t,n,r){i.get(e).op(yke).set(r),i.get(e).get(r).op($E).set(n),Gke(i,r,t);}function iN(i,e,t){i.get(e).get(e).op(Yd),i.f32bits(Ike).f32bits(Vz).get(e).op(Yd).op($E),i.op(Yd).set(t);}function Uz(i,e,t,n,r){t(),i.i32(kke).op(If),n(),i.i32(Lke).op(If).op(wf),r(),i.i32(Mke).op(If).op(wf).set(e),i.get(e).get(e).i32(Fz).op(zE).op(wf).set(e),i.get(e).i32(Dke).op(If).set(e),i.get(e).get(e).i32(Fke).op(zE).op(wf).set(e),i.get(e).i32(Pke).op(If).set(e),i.get(e).get(e).i32(Fz).op(zE).op(wf).set(e),i.get(e).i32(Uke).op(zE).op(xke).f32bits(Cke).op(Yd);}function Of(i,e,t,n,r){i.get(e).get(t).get(e).op($E).get(n).op(Yd).op(Ake).set(r);}function Bz(i){let e=new Gi(i),t=v=>{e.get(v).op(Kd).f32bits(aN).op(pke);};t(0),t(1),e.op(Lz),i===3&&(t(2),e.op(Lz)),e.op(dke),e.when(Ls,()=>e.f32bits(Gz).op(QE));let n=e.local(Ur),r=e.local(Cf),o=e.local(Cf),s=e.local(Cf),a=e.local(Cf),l=e.local(Ur),c=e.local(Ur),u=e.local(Ur),d=e.local(Ur),h=e.local(Ur),p=e.local(Ur),m=e.local(Ur),f=e.local(Ur),y=e.local(Ur),b=e.local(Ur),A=e.local(Ur),E=e.local(Ur);rN(e,0,r,l,n),rN(e,1,o,c,n),i===3?rN(e,2,s,u,n):e.i32(0).set(s),iN(e,l,d),iN(e,c,h),i===3&&iN(e,u,p);let R=(v,x)=>()=>{e.get(v),x!==0&&e.i32(x).op(hke);},g=(v,x,O)=>{Uz(e,a,R(r,0),R(o,v),R(s,x)),e.set(m),Uz(e,a,R(r,1),R(o,v),R(s,x)),e.set(f),Of(e,m,f,d,O);};return g(0,0,y),g(1,0,b),i===2?Of(e,y,b,h,y):(g(0,1,A),g(1,1,E),Of(e,y,b,h,y),Of(e,A,E,h,A),Of(e,y,A,p,y)),e.get(y).f32bits(Vz).op(Yd).f32bits(wke).op($E),e.finish()}var oN=null;function Hz(){return oN===null&&(oN=[Bke(),Bz(2),Bz(3)]),oN}var P=nt,Wt=127,Hi=125,mN=123,He=64,_i=2,Do=3,Xn=4,cN=5,Ue=11,Ms=12,fr=13,Vke=16,$a=27,Hke=32,Wke=33,Kke=34,bn=40,uN=42,Yke=45,Xd=54,Xke=58,Pf=190,qke=65,zke=67,qa=69,Vi=70,Nf=71,fN=72,za=73,Wz=75,dN=79,Qke=92,Kz=93,_N=94,$ke=95,ve=106,jke=107,qd=108,Jke=111,Zke=112,yi=113,Yz=114,Ct=116,eLe=117,tLe=118,Xz=66,nLe=84,hN=124,rLe=126,qz=136,zz=167,iLe=173,Qz=32,oLe=141,sLe=142,jE=146,$z=147,JE=148,uQ=252,aLe=0,lLe=1,cLe=253,C={load:0,store:11,const:12,i32splat:17,i32extract:27,i32replace:28,f32extract:31,f32replace:32,i32eq:55,i32ne:56,i32lt_s:57,i32lt_u:58,i32le_s:61,i32le_u:62,f32eq:65,f32ne:66,f32lt:67,f32le:69,f32ge:70,not:77,and:78,andnot:79,or:80,xor:81,bitselect:82,anyTrue:83,load32lane:86,store32lane:90,f32ceil:103,f32floor:104,f32trunc:105,i32abs:160,i32neg:161,i32shl:171,i32shr_s:172,i32shr_u:173,i32add:174,i32sub:177,i32mul:181,i32min_s:182,i32min_u:183,i32max_s:184,i32max_u:185,f32abs:224,f32neg:225,f32sqrt:227,f32add:228,f32sub:229,f32mul:230,f32div:231,truncSatS:248,convertS:250,convertU:251},Br=2147483648,uLe=2146121005,dLe=2221713035,ZE=2654435769,hLe=1/16777216,Me=4,dQ=1021,hQ=65539,pLe=1024,mLe=2,Po=8,fLe=3,Qa=2+Po+10,_Le=2,ge=4,rr=255,jz=31,Jz=-2147483648,Qd=0,t0=4,r0=8,i0=12,o0=16,s0=20,a0=24,Ff=28,yN=32,AN=36,bN=40,gN=44,EN=48,yLe=52,n0=56,xN=60,vN=64,pQ=68,Uf=72,Ds=76,Zz=80,eQ=96,tQ=112,nQ=128,rQ=144,zd=160,mQ=192,e0=208;var Df=["toInt32","fmod","noise2","noise3","lanes","data","query","queryKeep"],kf=Object.fromEntries(Df.map((i,e)=>[i,e])),ALe=2,iQ=3,bLe=4,gLe=8,fQ={[P.FLOG2]:"log2",[P.FSIN]:"sin",[P.FCOS]:"cos",[P.FTAN]:"tan",[P.FASIN]:"asin",[P.FACOS]:"acos",[P.FATAN]:"atan",[P.FEXP]:"exp",[P.FLOG]:"log"},ELe=new Set([...Object.keys(fQ).map(Number),P.FPOW,P.FATAN2]),xLe=new Set([P.FMOD,P.NOISE2,P.NOISE3]),vLe={toInt32:0,fmod:3,noise2:3,noise3:4,lanes:5,data:5,query:6,queryKeep:7},RN=new Map,l0=new Map;function IN(i,e){e===null?RN.delete(i):RN.set(i,e);}function ON(i){let e=new Uint32Array(Bf),t=new Uint32Array(SN),n=new Uint32Array(i.buffer);return {env:{memory:i,toInt32:r=>r|0,fmod:(r,o)=>r%o,noise2:F2,noise3:U2,lanes:(r,o,s)=>{n.buffer!==i.buffer&&(n=new Uint32Array(i.buffer));for(let a=0;a<Me;a++){for(let l=0;l<Bf;l++)e[l]=n[(o>>>2)+l*Me+a];t2(r,e,t);for(let l=0;l<SN;l++)n[(s>>>2)+l*Me+a]=t[l];}},data:(r,o,s)=>{let a=RN.get(r>>>0);if(a===void 0)throw new Error("a compiled kernel ran a data op without an engine data binding");a(o,s);},query:(r,o,s,a,l,c)=>l0.get(r>>>0).query(o,s,a,l|0,c),queryKeep:(r,o,s,a)=>l0.get(r>>>0).keep(o,s,a)}}}var Ec=11,oQ=(Ec+3)*16,Bf=5,SN=3;function CN(i){return Math.ceil(Math.max(i.cross.length,1)*ge/sQ)*sQ}var c0=(Bf+SN)*16,sQ=16;function Et(i,e){let t=e>>>0;do{let n=t&127;t>>>=7,t!==0&&(n|=128),i.push(n);}while(t!==0)}function RLe(i,e){let t=e|0;for(;;){let n=t&127;if(t>>=7,t===0&&(n&64)===0||t===-1&&(n&64)!==0){i.push(n);return}i.push(n|128);}}function Lf(i,e,t){i.push(e),Et(i,t.length);for(let n of t)i.push(n);}function Mf(i,e){Et(i,e.length);for(let t=0;t<e.length;t++)i.push(e.charCodeAt(t));}var SLe=new Set(Object.values(P)),aQ=2,TLe=4;function wLe(i){return SLe.has(i)&&i!==P.CALL}function NN(i){return `stage${i}`}function TN(i,e){return i===0?e===0:(i===1||i===2)&&(e===1||e===2)}function kN(i,e){return i===Ve&&Di(e)===An.NARROW&&gE(e)!==null}var ILe=new Set([Hm,fd,_d,Vm,yd,Wm,Ad,Km,Ym,bd]);function d0(i,e){return i===Ve&&ILe.has(e)}function _Q(i,e){return i===Ve&&(e===Da||e===Pa)}function OLe(i,e,t){return e===Ve&&i.position!==null&&(t===ka||t===RC||t===SC||t===cc)}function LN(i){return i.code.some(e=>kN(e.op,e.dst)||d0(e.op,e.dst))}function CLe(i){return i.position!==null||i.channels.length>0||i.state>=0}function ja(i){return i.calls.length>0||i.cross.length>0||LN(i)&&!CLe(i)}function MN(i){return ja(i)}function yQ(i){return i.position!==null||i.channels.length>0||!ja(i)&&LN(i)}function DN(i){return i.code.some(e=>d0(e.op,e.dst))}function NLe(i){return i.code.some(e=>e.op===Ve&&e.dst===ka)}function kLe(i){let e=[],t=s=>i.code[s].op===Ln.SCATTER||i.code[s].op===Ve?2:1,n=0,r=0,o=0;for(;r<i.calls.length||o<i.cross.length;){let s=r<i.calls.length?i.calls[r]:1/0,a=o<i.cross.length?i.cross[o]:1/0;if(a<s){let l=[],c=a;for(;o<i.cross.length&&i.cross[o]===c;)l.push(c),c+=t(c),o++;e.push({start:n,end:c,stage:{barrier:"cross",pcs:l}}),n=c;}else e.push({start:n,end:s,stage:{barrier:"call",pcs:[s]}}),n=s+1,r++;}return e.push({start:n,end:i.code.length,stage:{barrier:"end",pcs:[]}}),e}function LLe(i,e){if(!(!ja(i)||i.position===null&&i.channels.length===0&&i.state<0)||!ja(i)&&i.slots.some(n=>n.scratch)||e.length!==i.slots.length||e.some(n=>n>3))return false;if(i.state>=0){let n=i.slots[i.state];if(n===void 0||!TN(n.kind,e[i.state]))return false}return i.code.every((n,r)=>wLe(n.op)||kE(n)||So(n.op)||dc(n.op,n.dst)||kN(n.op,n.dst)||d0(n.op,n.dst)||_Q(n.op,n.dst)||!ja(i)&&OLe(i,n.op,n.dst)||n.op===P.CALL&&i.calls.includes(r))}var wN=class{constructor(){this.code=[];this.mapper=e=>e;}reg(e){return this.get(this.mapper(e))}op(...e){for(let t of e)this.code.push(t);return this}simd(e){return this.code.push(cLe),Et(this.code,e),this}get(e){return this.code.push(Hke),Et(this.code,e),this}set(e){return this.code.push(Wke),Et(this.code,e),this}tee(e){return this.code.push(Kke),Et(this.code,e),this}i32(e){return this.code.push(qke),RLe(this.code,e),this}f32(e){this.code.push(zke);let t=new Uint8Array(new Float32Array([e]).buffer);for(let n of t)this.code.push(n);return this}v128i(e){this.simd(C.const);let t=new Uint8Array(new Uint32Array(e.map(n=>n>>>0)).buffer);for(let n of t)this.code.push(n);return this}v128f(e){this.simd(C.const);let t=new Uint8Array(new Float32Array([e,e,e,e]).buffer);for(let n of t)this.code.push(n);return this}mem(e,t){return Et(this.code,e),Et(this.code,t),this}call(e){return this.code.push(Vke),Et(this.code,e),this}load(e,t){return this.get(e).op(bn).mem(2,t)}};function MLe(i,e,t,n,r,o){let s=F=>o+lN.indexOf(F),a=F=>r+Xa.indexOf(F),l=F=>r+Xa.length+XE.indexOf(F),c=i.slots.length,u=i.uniforms.length,d=i.args,h=i.uniforms.length-i.loops,p=0,m=1,f=2,y=3,b=4,A=5,E=A++,R=A++,g=A;A+=u;let v=A;A+=u;let x=A;A+=c;let O=A++,N=A++,I=A++,S=A++,w=A++,U=A++,L=A++,k=A++,M=A++,K=A++,Y=A++,te=A++,Z=A++,de=A++,Oe=A++,be=A++,ke=A++,De=A++,Fe=A++,Ze=A++,wt=A++,q=[Qd,t0,r0,i0,o0,s0,a0,Ff,yN,AN,bN,gN],he=A;A+=q.length;let ot=A-5,Vt=A++,_t=A++,dt=A++,_n=A++,Bn=A++,Zr=A++,zn=A++,Gn=A++,ei=A-Vt,ti=A,mA=Math.max(i.registers,1);A+=mA+(i.code.some(kE)?F9:0);let Cu=A;A+=u;let Che=A;A+=8;let Qn=A++,ba=A++,fA=A++,_A=A++,yA=A++,zU=A++,Nhe=A-ti,Lw=[],khe=0;for(let F of i.slots)Lw.push(F.neighbour?khe++:-1);let T=new wN;for(let F=0;F<c;F++)T.get(p).op(bn).mem(2,F*4).set(x+F);for(let F=0;F<u;F++)F<d||F>=h?T.get(y).op(bn).mem(2,F*4):T.i32(i.uniforms[F]|0),T.tee(v+F).simd(C.i32splat).set(Cu+F);i.position!==null&&q.forEach((F,V)=>T.load(b,F).set(he+V));let ni=F=>T.get(he+q.indexOf(F)),AA=F=>(F&2147483648)!==0?Cu+(F&2147483647):ti+F;T.mapper=AA;let le=F=>T.reg(F),oe=F=>Che+F,bA="list",gA=F=>{if(bA=F,T.get(E).simd(C.i32splat).v128i([0,1,2,3]).simd(C.i32add).set(Qn),F==="full"?T.v128i([-1,-1,-1,-1]).set(ba):T.get(Qn).get(m).simd(C.i32splat).simd(C.i32lt_u).set(ba),F==="list")for(let V=0;V<Me;V++)T.get(Qn),T.get(E).i32(V).op(ve).get(m).op(za).op(Xn,Wt),T.get(f).get(E).i32(V).op(ve).i32(2).op(Ct).op(ve).op(bn).mem(2,0),T.op(cN).get(f).get(E).i32(2).op(Ct).op(ve).op(bn).mem(2,0).op(Ue),T.simd(C.i32replace).op(V).set(Qn);},Mw=()=>{T.get(E).i32(Me).op(ve).set(E);},Dw=F=>{T.get(E).i32(F).op(ve).get(m).op(za);},Pw=F=>e[F]===3,QU=F=>{if(Pw(F)){T.v128i([0,0,0,0]);for(let V=0;V<Me;V++)T.set(oe(7)),T.get(oe(7)),T.get(x+F).get(Qn).simd(C.i32extract).op(V).op(ve).op(Yke).mem(0,0),T.simd(C.i32replace).op(V);return}if(bA!=="list"){T.get(x+F).get(E).i32(2).op(Ct).op(ve).simd(C.load).mem(2,0);return}T.v128i([0,0,0,0]);for(let V=0;V<Me;V++)T.set(oe(7)),T.get(x+F).get(Qn).simd(C.i32extract).op(V).i32(2).op(Ct).op(ve),T.get(oe(7)).simd(C.load32lane).mem(2,0).op(V);},Fw=(F,V)=>{T.get(F).simd(C.truncSatS).set(V),T.get(F).simd(C.f32abs).v128f(Br).simd(C.f32ge).simd(C.anyTrue).op(Xn,He);for(let $=0;$<Me;$++)T.get(V).get(F).simd(C.f32extract).op($).call(kf.toInt32).simd(C.i32replace).op($).set(V);T.op(Ue);},$U=(F,V,$,Q)=>{if(F===0){V===0?T.get($).set(Q):V===1?T.get($).simd(C.convertS).set(Q):V===2?T.get($).simd(C.convertU).set(Q):T.get($).v128i([rr,rr,rr,rr]).simd(C.and).simd(C.convertU).set(Q);return}if(F===3){V===0?(T.get($).v128f(0).simd(C.f32ne),T.get($).get($).simd(C.f32eq).simd(C.and).set(Q)):V===3?T.get($).v128i([rr,rr,rr,rr]).simd(C.and).v128i([0,0,0,0]).simd(C.i32ne).set(Q):T.get($).v128i([0,0,0,0]).simd(C.i32ne).set(Q);return}V===0?Fw($,Q):V===3?T.get($).v128i([rr,rr,rr,rr]).simd(C.and).set(Q):T.get($).set(Q);},Lhe=(F,V,$,Q)=>{if(F===0){V===0?T.get($).set(Q):Fw($,Q);return}if(F===3){V===0?T.v128f(1).v128f(0):T.v128i([1,1,1,1]).v128i([0,0,0,0]),T.get($).v128i([0,0,0,0]).simd(C.i32ne).simd(C.bitselect).set(Q);return}V===0?T.get($).simd(F===1?C.convertS:C.convertU).set(Q):T.get($).set(Q);},Mhe=(F,V)=>{QU(F),T.set(oe(6)),$U(i.slots[F].kind,e[F],oe(6),V);},jU=(F,V)=>{for(let $=0;$<Me;$++)Dw($),T.op(Xn,He),Pw(F)?(T.get(x+F).get(Qn).simd(C.i32extract).op($).op(ve),T.get(V).simd(C.i32extract).op($).op(Xke).mem(0,0)):(T.get(x+F).get(Qn).simd(C.i32extract).op($).i32(2).op(Ct).op(ve),T.get(V).simd(C.store32lane).mem(2,0).op($)),T.op(Ue);},Dhe=(F,V)=>{let $=i.slots[F].kind,Q=e[F],Pe=oe(5);if(TN($,Q)?le(V).set(Pe):(QU(F),T.set(oe(6)),$U($,Q,oe(6),oe(4)),le(V).set(oe(3)),Lhe($,Q,oe(3),oe(2)),T.get(oe(6)).get(oe(2)).get(oe(4)).get(oe(3)).simd(C.i32eq).simd(C.bitselect).set(Pe)),Pw(F)){jU(F,Pe);return}if(bA==="list"){jU(F,Pe);return}T.get(x+F).get(E).i32(2).op(Ct).op(ve),bA==="full"?T.get(Pe):T.get(Pe).get(x+F).get(E).i32(2).op(Ct).op(ve).simd(C.load).mem(2,0).get(ba).simd(C.bitselect),T.simd(C.store).mem(2,0);},Uw=(F,V,$,Q)=>{F(),T.set(oe(0)),V(),T.set(oe(1)),T.get(oe(0)).get(oe(1)).get(oe(0)).get(oe(0)).simd(C.f32ne).simd(C.bitselect).set(oe(2)),T.get(oe(1)).get(oe(2)),Q?T.get(oe(0)).get(oe(1)).simd(C.f32lt):T.get(oe(1)).get(oe(0)).simd(C.f32lt),T.simd(C.bitselect).set(oe(2)),T.get(oe(0)).get(oe(2)),Q?T.get(oe(1)).get(oe(0)).simd(C.f32lt):T.get(oe(0)).get(oe(1)).simd(C.f32lt),T.simd(C.bitselect).set($);},Phe=F=>{T.set(Gn).set(zn),T.get(zn),T.get(Gn),T.get(zn).get(Gn).get(zn).get(zn).op(Qke).op($a),F?T.get(Gn).get(zn).op(_N):T.get(Gn).get(zn).op(Kz),T.op($a),F?T.get(zn).get(Gn).op(_N):T.get(zn).get(Gn).op(Kz),T.op($a);},Nu=(F,V,$)=>{for(let Q=0;Q<V.length;Q++)le(V[Q]).set(oe(Q));T.v128f(0).set(oe(4));for(let Q=0;Q<Me;Q++){T.get(oe(4));for(let Pe=0;Pe<V.length;Pe++)T.get(oe(Pe)).simd(C.f32extract).op(Q);T.call(F).simd(C.f32replace).op(Q).set(oe(4));}T.get(oe(4)).set($);},JU=(F,V,$,Q)=>{le(F).set(oe(0)),le(V).set(oe(1)),T.v128i([0,0,0,0]).set(oe(2));for(let Pe=0;Pe<Me;Pe++)T.get(oe(2)),T.get(oe(0)).simd(C.i32extract).op(Pe).set(De),T.get(oe(1)).simd(C.i32extract).op(Pe).set(Fe),Q(),T.simd(C.i32replace).op(Pe).set(oe(2));T.get(oe(2)).set($);},ZU=()=>{for(let[F,V]of [[16,uLe],[15,dLe],[16,0]])T.tee(oe(5)).get(oe(5)).i32(F).simd(C.i32shr_u).simd(C.xor),V!==0&&T.v128i([V,V,V,V]).simd(C.i32mul);},eB=F=>{le(F.b).v128i([ZE,ZE,ZE,ZE]).simd(C.i32add),ZU(),le(F.a).simd(C.xor),ZU();},st=i.code,Fhe=new Set(st.filter(F=>F.op===P.LOOP_INIT).map(F=>F.a)),Bw=F=>{let V=F&2147483647;return Fhe.has(V)?g+(V-d):v+V},Uhe=F=>F.filter(V=>V.kind==="loop"),Bhe=(F,V)=>{let $=st[F],Q=i.channels[$.dst],Pe=Uhe(V);if(Pe.length>fLe)return false;let Ee=[];for(let ye of Pe)Ee.push(()=>T.i32(ye.pc)),Ee.push(()=>T.get(g+(ye.counter-d)));for(Ee.push(()=>T.i32(F));Ee.length<Po;)Ee.push(()=>T.i32(0));for(let ye=0;ye<Me;ye++){Dw(ye),$.a!==4294967295&&le($.a).simd(C.i32extract).op(ye).i32(0).op(Nf).op(yi),T.op(Xn,He),T.load(b,Uf).tee(be),T.get(b).get(be).i32(1).op(ve).op(Xd).mem(2,Uf),T.load(b,pQ).op(za).op(Xn,He),T.load(b,vN).get(be).i32(Qa*ge).op(qd).op(ve).set(ke);let Ge=(ze,ht)=>{T.get(ke),ht(),T.op(Xd).mem(2,ze*ge);};Ge(0,()=>T.get(E).i32(ye).op(ve)),Ee.forEach((ze,ht)=>Ge(1+ht,ze)),Ge(1+Po,()=>T.i32(0)),Ge(2+Po,()=>T.i32($.dst)),Ge(3+Po,()=>T.get(Qn).simd(C.i32extract).op(ye));for(let ze=0;ze<8;ze++)if(ze<Q){let ht=st[F+1+Math.floor(ze/3)],xn=[ht.a,ht.b,ht.c][ze%3];Ge(4+Po+ze,()=>le(xn).simd(C.i32extract).op(ye));}else Ge(4+Po+ze,()=>T.i32(0));T.op(Ue).op(Ue);}return true},EA=false,Gw=false,Ghe=F=>{if(!EA){T.get(b).get(AA(F.a)).simd(C.store).mem(2,zd);for(let V=0;V<Me;V++)T.i32(V).get(de).op(za),F.c!==4294967295&&le(F.c).simd(C.i32extract).op(V).i32(0).op(Nf).op(yi),Gw&&T.get(zU).simd(C.i32extract).op(V).i32(0).op(Nf).op(yi),T.op(Xn,He),T.get(b).get(fA).simd(C.i32extract).op(V).i32(2).op(Ct).op(ve).set(be),F.op===P.ACC_IADD?(T.get(be),T.get(be).op(bn).mem(2,zd),le(F.b).simd(C.i32extract).op(V).op(ve),T.op(Xd).mem(2,zd)):(T.get(be),T.get(be).op(uN).mem(2,zd),le(F.b).simd(C.f32extract).op(V),F.op===P.ACC_FADD?T.op(jE):Phe(F.op===P.ACC_FMAX),T.op(56).mem(2,zd)),T.op(Ue);T.get(b).simd(C.load).mem(2,zd).set(AA(F.a));}},Vhe=F=>{let V=($,Q,Pe)=>{le($).simd(C.i32extract).op(Q),Pe&&T.i32(1).op(yi),T.op(iLe);};for(let $=0;$<Me;$++)T.get(ti+F.dst),V(F.a,$,false),V(F.b,$,false),F.op===P.UMULHI?T.op(rLe).op(Xz,Qz).op(qz).op(zz):F.op===P.UADDC?(T.op(hN),V(F.c,$,true),T.op(hN).op(Xz,Qz).op(qz).op(zz)):(V(F.c,$,true),T.op(hN).op(nLe)),T.simd(C.i32replace).op($).set(ti+F.dst);},Hhe=ja(i),hs=()=>Hhe?T.get(b).i32(CN(i)).op(ve):T.load(b,mQ),Whe=F=>{let V=st[F],$=st[F+1],[Q,Pe]=gE(V.dst);[V.a,V.b,V.c,$.a,$.b].forEach((Ge,ze)=>{hs(),(Q&1<<ze)!==0?le(Ge):T.v128i([0,0,0,0]),T.simd(C.store).mem(0,ze*16);}),T.i32(V.dst),hs(),hs().i32(Bf*16).op(ve).call(kf.lanes);let ye=[$.dst,$.c,$.b];for(let Ge=0;Ge<Pe;Ge++)hs().simd(C.load).mem(0,(Bf+Ge)*16).set(ti+ye[Ge]);},Khe=F=>{let V=st[F],$=st[F+1];if(V.dst===Hm)return;let Q=4294967295,Pe={[fd]:[[V.a,Q,Q,Q],[false,false,false,false],true],[_d]:[[V.a,Q,Q,Q],[false,false,false,false],true],[Vm]:[[Q,V.b,Q,Q],[false,false,false,false],true],[yd]:[[Q,Q,Q,Q],[false,false,false,false],true],[Wm]:[[Q,V.b,V.c,Q],[false,false,true,false],true],[bd]:[[Q,V.b,V.c,Q],[false,false,true,false],false],[Ad]:[[Q,V.b,V.c,$.a],[false,false,false,true],false],[Ym]:[[Q,V.b,V.c,$.a],[false,false,false,true],false],[Km]:[[Q,V.b,Q,Q],[false,true,false,false],false]},[Ee,ye,Ge]=Pe[V.dst];hs().get(Qn).simd(C.store).mem(0,0),hs().get(ba).simd(C.store).mem(0,16),Ee.forEach((ze,ht)=>{hs(),ze!==Q?le(ze):T.v128i(ye[ht]?[-1,-1,-1,-1]:[0,0,0,0]),T.simd(C.store).mem(0,(2+ht)*16);}),T.get(b).i32(F),hs().call(kf.data),Ge&&hs().simd(C.load).mem(0,96).set(ti+$.dst);},Yhe=F=>{let V=st[F],$=st[F+1],Q=F+2,Pe=$.a,Ee=($.c&Ug)!==0,ye=$.c&Fg,Ge=Ee?F-2:-1,ze=ye===La?-1:Ee?F-4:F-2,ht=(yt,_o)=>{yt===4294967295?T.v128i([_o,_o,_o,_o]):le(yt);},xn=[()=>$.b===4294967295?T.get(ba):le($.b).get(ba).simd(C.and),()=>le(V.b),()=>ht(V.c,-1)],B=ze<0?null:[st[ze].a,st[ze].b,st[ze].c,st[ze+1].a,st[ze+1].b,st[ze+1].c];for(let yt=0;yt<6;yt++)xn.push(()=>ht(B===null?4294967295:B[yt],0));xn.push(()=>ht(Ge<0?4294967295:st[Ge].b,0)),xn.push(()=>ht(Ge<0?4294967295:st[Ge].c,0)),xn.forEach((yt,_o)=>{T.load(b,Ds),yt(),T.simd(C.store).mem(0,_o*16);}),T.load(b,Ds).get(Qn).simd(C.store).mem(0,Ec*16),T.get(b).load(b,Ds).load(b,Ds).i32(Ec*16).op(ve),T.i32(ye).i32(Ge<0?-1:st[Ge].a).i32(Ge<0?0:st[Ge+1].a).call(kf.query).set(wt);let pe=false;for(let yt=Q;yt<Pe;yt++)st[yt].op===Ve&&st[yt].dst===cc&&(pe=true);if(T.i32(0).set(Ze),T.op(_i,He).op(Do,He),T.get(Ze).get(wt).op(dN).op(fr,1),T.get(wt).get(Ze).op(jke).tee(de).i32(Me).get(de).i32(Me).op(za).op($a).set(de),T.load(b,n0).get(Ze).i32(2).op(Ct).op(ve).simd(C.load).mem(2,0).set(fA),T.load(b,xN).get(Ze).i32(2).op(Ct).op(ve).simd(C.load).mem(2,0).set(_A),pe){T.v128i([0,0,0,0]).set(yA),EA=true;let yt=Yl(Q,Pe,true);if(EA=false,!yt)return false;T.load(b,Ds).get(yA).simd(C.store).mem(0,(Ec+1)*16),T.get(b).load(b,Ds).i32((Ec+1)*16).op(ve).get(Ze).load(b,Ds).i32((Ec+2)*16).op(ve).call(kf.queryKeep),T.load(b,Ds).simd(C.load).mem(0,(Ec+2)*16).set(zU),Gw=true;}let Ce=Yl(Q,Pe,true);return Gw=false,Ce?(T.get(Ze).i32(Me).op(ve).set(Ze).op(Ms,0).op(Ue).op(Ue),true):false},Xhe=F=>{let V=st[F],$=i.cross.indexOf(F);if($<0)return false;let Pe=V.op===Ln.SCATTER||V.op===Ve?st[F+1]:V,Ee=V.op===Ve&&gd(V.dst),ye=V.op===Ln.COMPACT?4294967295:V.a,Ge=V.op===Ln.SCATTER||Ee?V.b:V.op===Ve&&V.dst===Ed?V.c:4294967295,ze=V.op===Ln.SCATTER?Pe.b:V.op===Ln.COMPACT?V.a:Ee?V.c:V.b;T.get(b).op(bn).mem(2,$*ge).set(ke);for(let ht=0;ht<Me;ht++){Dw(ht),T.op(Xn,He),T.get(ke).get(E).i32(ht).op(ve).i32(TLe).op(Ct).op(ve).set(be);let xn=(B,pe)=>{T.get(be),pe(),T.op(Xd).mem(2,B*ge);};xn(0,()=>ye===4294967295?T.i32(0):le(ye).simd(C.i32extract).op(ht)),xn(1,()=>Ge===4294967295?T.i32(0):le(Ge).simd(C.i32extract).op(ht)),xn(2,()=>ze===4294967295?T.i32(1):le(ze).simd(C.i32extract).op(ht).i32(0).op(Nf)),xn(3,()=>T.get(Qn).simd(C.i32extract).op(ht)),T.op(Ue);}return true},Yl=(F,V,$)=>{let Q=[],Pe=Ee=>Q.length-1-Ee;for(let Ee=F;Ee<=V;Ee++){for(;Q.length>0&&Q[Q.length-1].end===Ee;)Q.pop(),T.op(Ue);if(Ee===V)break;let ye=st[Ee];ti+ye.dst;if(kN(ye.op,ye.dst)){if($)return false;Whe(Ee),Ee++;continue}if(d0(ye.op,ye.dst)){if($)return false;Khe(Ee),Ee++;continue}if(_Q(ye.op,ye.dst)){let xn=st[Ee+1],B=ye.dst===Pa,pe=B?ye.c:1;if(B&&$||pe<1||ye.a+pe>c)return false;for(let Ce=ye.a;Ce<ye.a+pe;Ce++)if(!TN(i.slots[Ce].kind,e[Ce]))return false;T.v128i([0,0,0,0]).set(oe(7));for(let Ce=0;Ce<Me;Ce++)le(ye.b).simd(C.i32extract).op(Ce).set(De),T.get(De),B?T.i32(ye.c):le(ye.c).simd(C.i32extract).op(Ce),T.op(za).op(Xn,He),T.get(oe(7)),B?(T.get(p).get(De).i32(ye.a).op(ve).i32(2).op(Ct).op(ve).op(bn).mem(2,0),T.get(Qn).simd(C.i32extract).op(Ce).i32(2).op(Ct).op(ve)):T.get(x+ye.a).get(De).i32(2).op(Ct).op(ve),T.op(bn).mem(2,0).simd(C.i32replace).op(Ce).set(oe(7)),T.op(Ue);xn.a!==4294967295?T.get(oe(7)).reg(xn.a).simd(C.and).set(ti+xn.dst):T.get(oe(7)).set(ti+xn.dst),Ee++;continue}if(ye.op===Ve&&ye.dst===ka){if($||!Yhe(Ee))return false;Ee=st[Ee+1].a-1;continue}if(ye.op===Ve&&(ye.dst===RC||ye.dst===SC)){Ee++;continue}if(ye.op===Ve&&ye.dst===cc){if(!$)return false;EA&&le(ye.a).get(yA).simd(C.or).set(yA),Ee++;continue}if(So(ye.op)||dc(ye.op,ye.dst)){if($||!Xhe(Ee))return false;(ye.op===Ln.SCATTER||ye.op===Ve)&&Ee++;continue}let ze=kE(ye),ht=ze?U9(ye,st[Ee+1],mA):[ye];if(ht===null)return false;ze&&Ee++;for(let xn of ht){let B=xn,pe=ti+B.dst;switch(B.op){case P.NOP:case P.EXT:break;case P.MOV:le(B.a).set(pe);break;case P.LOAD:Mhe(B.a,pe);break;case P.STORE:Dhe(B.a,B.b);break;case P.ROW:T.get(Qn).set(pe);break;case P.SEL:le(B.b).reg(B.c).reg(B.a).simd(C.bitselect).set(pe);break;case P.JNONE:{let Ce=Q.findIndex(yt=>yt.kind==="block"&&yt.end===B.b);if(Ce>=0)le(B.a).simd(C.anyTrue).op(qa).op(fr),Et(T.code,Pe(Ce));else {if(Q.length>0&&Q[Q.length-1].end<B.b||B.b>V)return false;T.op(_i,He),Q.push({kind:"block",end:B.b,pc:Ee,counter:-1}),le(B.a).simd(C.anyTrue).op(qa).op(fr,0);}break}case P.LOOP_INIT:{let Ce=g+(B.a-d),yt=st.findIndex((_o,Qhe)=>Qhe>Ee&&_o.op===P.LOOP_NEXT&&_o.a===B.a&&_o.c===Ee+1);if(yt<0||B.c>V||Q.length>0&&Q[Q.length-1].end<B.c)return false;T.i32(0).set(Ce),T.op(_i,He),Q.push({kind:"block",end:B.c,pc:Ee,counter:B.a}),cQ(T,Bw(B.b),B.dst,R),T.op(qa).op(fr,0),T.op(Do,He),Q.push({kind:"loop",end:yt+1,pc:Ee,counter:B.a}),T.get(Ce).simd(C.i32splat).set(Cu+B.a);break}case P.LOOP_NEXT:{let Ce=g+(B.a-d);T.get(Ce).i32(1).op(ve).tee(Ce),T.simd(C.i32splat).set(Cu+B.a),T.get(Ce),cQ(T,Bw(B.b),B.dst,R),T.op(fN).op(fr,0);break}case P.NEIGHBOURS:{if($||!qhe(Ee+1,B.b,B.c))return false;Ee=B.b-1;break}case P.NLOAD:{let Ce=Lw[B.a];T.v128i([0,0,0,0]).set(pe);for(let yt=0;yt<Me;yt++)T.get(pe),ni(Qd),ni(t0).i32(Ce).op(qd).get(_A).simd(C.i32extract).op(yt).op(ve).i32(2).op(Ct).op(ve),T.op(bn).mem(2,0).simd(C.i32replace).op(yt).set(pe);break}case P.OUTER:{T.get(b).get(AA(B.a)).simd(C.store).mem(2,tQ),T.v128i([0,0,0,0]).set(oe(7));for(let Ce=0;Ce<Me;Ce++)T.get(oe(7)),T.get(b).get(fA).simd(C.i32extract).op(Ce).i32(2).op(Ct).op(ve).op(bn).mem(2,tQ),T.simd(C.i32replace).op(Ce).set(oe(7));T.get(oe(7)).set(pe);break}case P.NROW:T.get(_A).set(pe);break;case P.ACC_FADD:case P.ACC_FMIN:case P.ACC_FMAX:case P.ACC_IADD:Ghe(B);break;case P.EMIT:{if($||!Bhe(Ee,Q))return false;Ee+=Math.ceil(i.channels[B.dst]/3);break}case P.FADD:case P.FSUB:case P.FMUL:case P.FDIV:le(B.a).reg(B.b).simd(B.op===P.FADD?C.f32add:B.op===P.FSUB?C.f32sub:B.op===P.FMUL?C.f32mul:C.f32div).set(pe);break;case P.FMIN:case P.FMAX:Uw(()=>le(B.a),()=>le(B.b),pe,B.op===P.FMAX);break;case P.FMOD:Nu(s("fmod"),[B.a,B.b],pe);break;case P.FPOW:Nu(a("pow"),[B.a,B.b],pe);break;case P.FATAN2:Nu(a("atan2"),[B.a,B.b],pe);break;case P.NOISE2:Nu(s("noise2"),[B.a,B.b],pe);break;case P.NOISE3:Nu(s("noise3"),[B.a,B.b,B.c],pe);break;case P.FLOG2:case P.FSIN:case P.FCOS:case P.FTAN:case P.FASIN:case P.FACOS:case P.FATAN:case P.FEXP:case P.FLOG:{B.op===P.FSIN||B.op===P.FCOS?le(B.a).call(l(B.op===P.FSIN?"sin":"cos")).set(pe):Nu(a(fQ[B.op]),[B.a],pe);break}case P.FMULADD:le(B.a).reg(B.b).simd(C.f32mul).reg(B.c).simd(C.f32add).set(pe);break;case P.FMULSUB:le(B.a).reg(B.b).simd(C.f32mul).reg(B.c).simd(C.f32sub).set(pe);break;case P.FSUBMUL:le(B.a).reg(B.b).simd(C.f32sub).reg(B.c).simd(C.f32mul).set(pe);break;case P.FADDMUL:le(B.a).reg(B.b).simd(C.f32add).reg(B.c).simd(C.f32mul).set(pe);break;case P.FCLAMP:Uw(()=>le(B.a),()=>le(B.b),oe(3),true),Uw(()=>T.get(oe(3)),()=>le(B.c),pe,false);break;case P.FLERP:le(B.a).reg(B.b).reg(B.a).simd(C.f32sub).reg(B.c).simd(C.f32mul).simd(C.f32add).set(pe);break;case P.FNEG:le(B.a).simd(C.f32neg).set(pe);break;case P.FABS:le(B.a).simd(C.f32abs).set(pe);break;case P.FSQRT:le(B.a).simd(C.f32sqrt).set(pe);break;case P.FFLOOR:le(B.a).simd(C.f32floor).set(pe);break;case P.FCEIL:le(B.a).simd(C.f32ceil).set(pe);break;case P.FTRUNC:le(B.a).simd(C.f32trunc).set(pe);break;case P.FROUND:le(B.a).simd(C.f32floor).set(oe(0)),T.get(oe(0)).v128f(1).simd(C.f32add).get(oe(0)),le(B.a).get(oe(0)).simd(C.f32sub).v128f(.5).simd(C.f32ge).simd(C.bitselect).set(pe);break;case P.FSIGN:le(B.a).set(oe(0)),T.v128f(1).v128f(-1).get(oe(0)).get(oe(0)).v128f(0).simd(C.f32lt).simd(C.bitselect),T.v128f(0).get(oe(0)).simd(C.f32lt).simd(C.bitselect).set(pe);break;case P.FLEN2:le(B.a).reg(B.a).simd(C.f32mul).reg(B.b).reg(B.b).simd(C.f32mul).simd(C.f32add).simd(C.f32sqrt).set(pe);break;case P.FLEN3:le(B.a).reg(B.a).simd(C.f32mul).reg(B.b).reg(B.b).simd(C.f32mul).simd(C.f32add).reg(B.c).reg(B.c).simd(C.f32mul).simd(C.f32add).simd(C.f32sqrt).set(pe);break;case P.FDOT2:{let Ce=st[Ee+1];le(B.a).reg(B.b).simd(C.f32mul).reg(B.c).reg(Ce.a).simd(C.f32mul).simd(C.f32add).set(pe),Ee++;break}case P.FDOT3:{let Ce=st[Ee+1];le(B.a).reg(B.b).simd(C.f32mul).reg(B.c).reg(Ce.a).simd(C.f32mul).simd(C.f32add).reg(Ce.b).reg(Ce.c).simd(C.f32mul).simd(C.f32add).set(pe),Ee++;break}case P.FLT:le(B.a).reg(B.b).simd(C.f32lt).set(pe);break;case P.FLE:le(B.a).reg(B.b).simd(C.f32le).set(pe);break;case P.FEQ:le(B.a).reg(B.b).simd(C.f32eq).set(pe);break;case P.FNE:le(B.a).reg(B.b).simd(C.f32ne).set(pe);break;case P.IADD:case P.ISUB:case P.IMUL:case P.IAND:case P.IOR:case P.IXOR:case P.IMIN:case P.IMAX:case P.UMIN:case P.UMAX:case P.ILT:case P.ILE:case P.IEQ:case P.INE:case P.ULT:case P.ULE:case P.MAND:case P.MOR:case P.MANDN:{let Ce={[P.IADD]:C.i32add,[P.ISUB]:C.i32sub,[P.IMUL]:C.i32mul,[P.IAND]:C.and,[P.IOR]:C.or,[P.IXOR]:C.xor,[P.IMIN]:C.i32min_s,[P.IMAX]:C.i32max_s,[P.UMIN]:C.i32min_u,[P.UMAX]:C.i32max_u,[P.ILT]:C.i32lt_s,[P.ILE]:C.i32le_s,[P.IEQ]:C.i32eq,[P.INE]:C.i32ne,[P.ULT]:C.i32lt_u,[P.ULE]:C.i32le_u,[P.MAND]:C.and,[P.MOR]:C.or,[P.MANDN]:C.andnot};le(B.a).reg(B.b).simd(Ce[B.op]).set(pe);break}case P.IREM:case P.UREM:{let Ce=B.op===P.IREM;JU(B.a,B.b,pe,()=>{T.i32(0),T.get(De),T.get(Fe).op(qa),Ce&&T.get(De).i32(Jz).op(Vi).get(Fe).i32(-1).op(Vi).op(yi).op(Yz),T.op(Xn,Wt).i32(1).op(cN).get(Fe).op(Ue),T.op(Ce?Jke:Zke),T.get(Fe).op(qa),Ce&&T.get(De).i32(Jz).op(Vi).get(Fe).i32(-1).op(Vi).op(yi).op(Yz),T.op($a);});break}case P.ISHL:case P.ISHR:case P.IUSHR:{let Ce=B.op===P.ISHL?C.i32shl:B.op===P.ISHR?C.i32shr_s:C.i32shr_u;if((B.b&2147483648)!==0&&B.b!==4294967295)le(B.a).get(Bw(B.b)).i32(jz).op(yi).simd(Ce).set(pe);else {let yt=B.op===P.ISHL?Ct:B.op===P.ISHR?eLe:tLe;JU(B.a,B.b,pe,()=>{T.get(De).get(Fe).i32(jz).op(yi).op(yt);});}break}case P.INEG:le(B.a).simd(C.i32neg).set(pe);break;case P.IABS:le(B.a).simd(C.i32abs).set(pe);break;case P.INOT:case P.MNOT:le(B.a).simd(C.not).set(pe);break;case P.ITOF:le(B.a).simd(C.convertS).set(pe);break;case P.UTOF:le(B.a).simd(C.convertU).set(pe);break;case P.FTOI:le(B.a).set(oe(0)),Fw(oe(0),pe);break;case P.BTOF:T.v128f(1).v128f(0),le(B.a).v128i([0,0,0,0]).simd(C.i32ne).simd(C.bitselect).set(pe);break;case P.BTOI:T.v128i([1,1,1,1]).v128i([0,0,0,0]),le(B.a).v128i([0,0,0,0]).simd(C.i32ne).simd(C.bitselect).set(pe);break;case P.FTOB:le(B.a).v128f(0).simd(C.f32ne),le(B.a).reg(B.a).simd(C.f32eq).simd(C.and).set(pe);break;case P.ITOB:le(B.a).v128i([0,0,0,0]).simd(C.i32ne).set(pe);break;case P.UADDC:case P.USUBB:case P.UMULHI:Vhe(B);break;case P.HASH:eB(B),T.set(pe);break;case P.RAND:eB(B),T.i32(8).simd(C.i32shr_u).simd(C.convertU).v128f(hLe).simd(C.f32mul).set(pe);break;default:return false}}}return Q.length===0},tB=F=>{F(),ni(AN).op(Pf).op(JE).op(sLe).op(uQ),Et(T.code,aLe);},nB=(F,V,$)=>($(),T.set(de),T.get(b).simd(C.load).mem(2,nQ).set(fA),T.get(b).simd(C.load).mem(2,rQ).set(_A),Yl(F,V,true)),Vw=(F,V)=>{ni(Qd),ni(t0).i32(Lw[F]).op(qd).get(V).op(ve).i32(2).op(Ct).op(ve).op(uN).mem(2,0);},qhe=(F,V,$)=>{let Q=i.position;if(Q===null)return false;let[Pe,Ee,ye]=Q;return T.get(b).get(Qn).simd(C.store).mem(2,Zz),T.get(b),$===4294967295?T.get(ba):le($).get(ba).simd(C.and),T.simd(C.store).mem(2,eQ),T.i32(0).set(Z),T.op(_i,He),T.load(b,EN).op(qa).op(fr,0),T.i32(0).set(O),T.op(_i,He).op(Do,He),T.get(O).i32(Me).op(dN).op(fr,1),T.get(b).get(O).i32(2).op(Ct).op(ve).op(bn).mem(2,eQ).op(Xn,He),T.get(b).get(O).i32(2).op(Ct).op(ve).op(bn).mem(2,Zz).set(N),Vw(Pe,N),T.set(Vt),Vw(Ee,N),T.set(_t),ye===4294967295?T.f32(0).set(dt):(Vw(ye,N),T.set(dt)),zhe(F,V,()=>ni(bN).op(Pf),ye)},zhe=(F,V,$,Q)=>{let Pe=Ge=>tB(()=>{T.get(Ge),$(),T.op($z);}),Ee=Ge=>tB(()=>{T.get(Ge),$(),T.op(jE);});Pe(Vt),T.set(I),Ee(Vt),T.set(k),Pe(_t),T.set(U),Ee(_t),T.set(M),Q===4294967295?(T.i32(0).set(L),T.i32(0).set(K)):(Pe(dt),T.set(L),Ee(dt),T.set(K)),T.op(_i,He).op(Do,He),T.get(U).set(S),T.op(_i,He).op(Do,He),T.get(L).set(w),T.op(_i,He).op(Do,He),T.get(S).get(I).i32(dQ).op(qd).op(ve).get(w).i32(hQ).op(qd).op(ve),ni(yN).op(yi).set(be),ni(r0).get(be).i32(2).op(Ct).op(ve).tee(ke).op(bn).mem(2,0).set(Y),T.get(ke).op(bn).mem(2,4).set(te),T.op(_i,He).op(Do,He),T.get(Y).get(te).op(dN).op(fr,1),ni(i0).get(Y).i32(12).op(qd).op(ve).set(ke),T.get(ke).op(bn).mem(2,0).get(I).op(Vi),T.get(ke).op(bn).mem(2,4).get(S).op(Vi).op(yi),T.get(ke).op(bn).mem(2,8).get(w).op(Vi).op(yi),T.op(Xn,He);let ye=(Ge,ze,ht)=>{ni(Ge).get(Y).i32(2).op(Ct).op(ve).op(uN).mem(2,0).get(ze).op($z).set(ht);};return ye(o0,Vt,_n),ye(s0,_t,Bn),ye(a0,dt,Zr),ni(Ff).get(Y).i32(2).op(Ct).op(ve).op(bn).mem(2,0).set(Oe),T.get(_n).get(_n).op(JE).get(Bn).get(Bn).op(JE).op(jE).get(Zr).get(Zr).op(JE).op(jE),ni(gN).op(Pf).op($ke),T.get(Oe).get(N).op(Nf).op(yi),T.op(Xn,He),T.get(b).get(Z).i32(2).op(Ct).op(ve).get(O).op(Xd).mem(2,nQ),T.get(b).get(Z).i32(2).op(Ct).op(ve).get(Oe).op(Xd).mem(2,rQ),T.get(Z).i32(1).op(ve).tee(Z).i32(Me).op(Vi).op(Xn,He),!nB(F,V,()=>T.i32(Me))||(T.i32(0).set(Z),T.op(Ue),T.op(Ue),T.op(Ue),T.get(Y).i32(1).op(ve).set(Y).op(Ms,0).op(Ue).op(Ue),T.get(w).get(K).op(Vi).op(fr,1),T.get(w).i32(1).op(ve).set(w).op(Ms,0).op(Ue).op(Ue),T.get(S).get(M).op(Vi).op(fr,1),T.get(S).i32(1).op(ve).set(S).op(Ms,0).op(Ue).op(Ue),T.get(I).get(k).op(Vi).op(fr,1),T.get(I).i32(1).op(ve).set(I).op(Ms,0).op(Ue).op(Ue),T.op(Ue),T.get(O).i32(1).op(ve).set(O).op(Ms,0).op(Ue).op(Ue),T.get(Z).op(Xn,He),!nB(F,V,()=>T.get(Z)))?false:(T.op(Ue),T.op(Ue),true)};T.get(f).op(qa).op(Xn,He),T.op(_i,He).op(Do,He),T.get(E).i32(Me*aQ).op(ve).get(m).op(Wz).op(fr,1);for(let F=0;F<aQ;F++){if(gA("full"),!Yl(t,n,false))return null;Mw();}if(T.op(Ms,0).op(Ue).op(Ue),T.op(_i,He).op(Do,He),T.get(E).i32(Me).op(ve).get(m).op(Wz).op(fr,1),gA("full"),!Yl(t,n,false)||(Mw(),T.op(Ms,0).op(Ue).op(Ue),T.get(E).get(m).op(za).op(Xn,He),gA("tail"),!Yl(t,n,false))||(T.op(Ue),T.op(cN),T.op(_i,He).op(Do,He),T.get(E).get(m).op(za).op(qa).op(fr,1),gA("list"),!Yl(t,n,false)))return null;Mw(),T.op(Ms,0).op(Ue).op(Ue),T.op(Ue).op(Ue);let ps=[];Et(ps,3),Et(ps,ot),ps.push(Wt),Et(ps,ei),ps.push(Hi),Et(ps,Nhe),ps.push(mN);for(let F of T.code)ps.push(F);return ps}var AQ=new Float32Array(1),DLe=new Uint32Array(AQ.buffer),pN=new Uint32Array(0);function lQ(i,e,t,n){for(let r=0;r<i.length;r++)if(!i[r].isDefault){if(e){if(DLe[0]=i[r].value,n===AQ[0])return r}else if(n>>>0===i[r].value>>>0)return r}return t}function bQ(i,e,t,n,r){let o=i.groups,s=i.slots[i.state].kind===0,a=-1;for(let c=0;c<o.length;c++)if(o[c].isDefault){a=c;break}r.fill(0);for(let c=0;c<t;c++){let u=lQ(o,s,a,e[c]);u>=0&&r[u+1]++;}for(let c=1;c<=o.length;c++)r[c]+=r[c-1];pN.length<o.length&&(pN=new Uint32Array(o.length));let l=pN;for(let c=0;c<o.length;c++)l[c]=r[c];for(let c=0;c<t;c++){let u=lQ(o,s,a,e[c]);u>=0&&(n[l[u]++]=c);}}function h0(i){return i<0?"run":`g${i}`}function PN(i,e,t=null){if(!LLe(i,e))return null;let n=ja(i)?kLe(i):null,r=n!==null?n.map(E=>[E.start,E.end]):i.state>=0?i.groups.map(E=>[E.start,E.end]):[[0,i.code.length]],o=[],s=Df.length+r.length,a=i.code.some(E=>ELe.has(E.op)),l=i.code.some(E=>xLe.has(E.op)),c=a?Xa.length+XE.length:0,u=s+c;for(let[E,R]of r){let g=MLe(i,e,E,R,s,u);if(g===null)return null;o.push(g);}let d=[...a?[...Cz(),...Oz(s)]:[],...l?Hz():[]],h=E=>E>=c?lN[E-c]==="noise3"?bLe:iQ:E>=Xa.length?gLe:pz.has(Xa[E])?iQ:ALe,p=[0,97,115,109,1,0,0,0],m=[];Et(m,9),m.push(96,1,Hi,1,Wt),m.push(96,5,Wt,Wt,Wt,Wt,Wt,0),m.push(96,1,Hi,1,Hi),m.push(96,2,Hi,Hi,1,Hi),m.push(96,3,Hi,Hi,Hi,1,Hi),m.push(96,3,Wt,Wt,Wt,0),m.push(96,6,Wt,Wt,Wt,Wt,Wt,Wt,1,Wt),m.push(96,4,Wt,Wt,Wt,Wt,0),m.push(96,1,mN,1,mN),Lf(p,1,m);let f=[];Et(f,Df.length+1);for(let E of Df)Mf(f,"env"),Mf(f,E),f.push(0),Et(f,vLe[E]);Mf(f,"env"),Mf(f,"memory"),t===null?f.push(2,0,1):(f.push(2,3,1),Et(f,t)),Lf(p,2,f);let y=[];Et(y,o.length+d.length);for(let E=0;E<o.length;E++)Et(y,1);for(let E=0;E<d.length;E++)Et(y,h(E));Lf(p,3,y);let b=[];Et(b,o.length),o.forEach((E,R)=>{Mf(b,n!==null?NN(R):h0(i.state>=0?R:-1)),b.push(0),Et(b,R+Df.length);}),Lf(p,7,b);let A=[];Et(A,o.length+d.length);for(let E of [...o,...d]){Et(A,E.length);for(let R of E)A.push(R);}return Lf(p,10,A),{bytes:new Uint8Array(p),slots:i.slots.length,groups:n===null&&i.state>=0?o.length:0,stages:n===null?[]:n.map(E=>E.stage)}}function cQ(i,e,t,n){let r=()=>i.get(e);(t&Ng)!==0?(r().op(Pf).op(oLe).op(uQ),Et(i.code,lLe),i.i32(0),r().op(Pf).f32(0).op(_N),i.op($a)):i.i32(0).get(e).get(e).i32(0).op(fN).op($a),i.tee(n).i32(65536).get(n).i32(65536).op(fN).op($a);}function PLe(i,e,t){if(i===0)return e===0?t>>>0:e===1?mt(Math.fround(t|0)):e===2?mt(Math.fround(t>>>0)):mt(t&rr);if(i===3){if(e===0){let n=Ye(t);return n!==0&&!Number.isNaN(n)?4294967295:0}return (e===3?t&rr:t)!==0?4294967295:0}return e===0?Ye(t)|0:(e===3?t&rr:t)>>>0}var u0=class{constructor(e,t,n,r,o=Ro){this.program=e;this.capacity=t;this.memory=n;this.shape={kind:0,vx:0,vy:0,vz:0,p0:0,p1:0,p2:0,reach:0};this.stopped=new Uint8Array(Me);this.pairs=0;this.heapBuffer=null;this.u32=new Uint32Array(0);this.f32=new Float32Array(0);this.i32=new Int32Array(0);this.u8=new Uint8Array(0);this.ctxWords=new Uint32Array(0);this.stageView=new Uint32Array(0);this.snapshotColumns=[];this.snapshotAxes=[];this.neighbourIndex=null;this.rowCells=new Int32Array(0);this.eventOrder=new Uint32Array(0);this.eventScratch=new Uint32Array(0);let s=pLe;for(;s<t*mLe;)s*=2;this.table=s,this.snapshots=e.slots.filter(f=>f.neighbour).length,this.stageCapacity=e.channels.length>0?o*_Le:0,this.bucket=new Uint32Array(e.position===null?0:t),this.ring=new Uint32Array(er+(e.channels.length>0?o*10:0));let a=e.position===null?0:(s+1+t*3+t*4)*ge,l=e.position!==null&&NLe(e);this.pairCapacity=l?Me*t+Me:0,this.grid=l?new Fa(t):null,this.search=l?new yc(t):null;let c=l?oQ+2*this.pairCapacity*ge:0,u=!ja(e)&&LN(e),d=e0+this.snapshots*t*ge+a+this.stageCapacity*Qa*ge+c+(u?c0:0);this.ctx=r(d);let h=new Uint32Array(n.buffer,this.ctx,e0/ge);h.fill(0);let p=this.ctx+e0,m=f=>{let y=p;return p+=f*ge,y};h[Qd/ge]=m(this.snapshots*t),h[t0/ge]=t,e.position!==null&&(h[r0/ge]=m(s+1),h[i0/ge]=m(t*3),h[o0/ge]=m(t),h[s0/ge]=m(t),h[a0/ge]=m(t),h[Ff/ge]=m(t),h[yN/ge]=s-1,h[yLe/ge]=e.position[2]===4294967295?1:0),h[vN/ge]=m(this.stageCapacity*Qa),h[pQ/ge]=this.stageCapacity,u&&(h[mQ/ge]=m(c0/ge)),l&&(h[Ds/ge]=m(oQ/ge),h[n0/ge]=m(this.pairCapacity),h[xN/ge]=m(this.pairCapacity),l0.set(this.ctx>>>0,this));}dispose(){l0.delete(this.ctx>>>0);}heap(){let e=this.memory.buffer;if(e===this.heapBuffer)return;this.heapBuffer=e,this.u32=new Uint32Array(e),this.f32=new Float32Array(e),this.i32=new Int32Array(e),this.u8=new Uint8Array(e);let t=new Uint32Array(e,this.ctx,e0/ge);this.ctxWords=t;let n=t[Qd/ge],r=[],o=[];for(let s=0;s<this.snapshots;s++){let a=n+s*this.capacity*ge;r.push(new Uint32Array(e,a,this.capacity)),o.push(new Float32Array(e,a,this.capacity));}this.snapshotColumns=r,this.snapshotAxes=o,this.stageView=this.stageCapacity===0?new Uint32Array(0):new Uint32Array(e,t[vN/ge],this.stageCapacity*Qa);}neighbourOf(e){let t=this.neighbourIndex;if(t===null){let n=this.program.slots;t=new Int32Array(n.length+1);let r=0;for(let o=0;o<=n.length;o++)t[o]=r,o<n.length&&n[o].neighbour&&r++;this.neighbourIndex=t;}return t[e]}snapshotColumn(e){return this.heap(),this.snapshotColumns[this.neighbourOf(e)]}axis(e){return this.heap(),this.snapshotAxes[this.neighbourOf(e)]}query(e,t,n,r,o){let s=this.grid,a=this.search,l=this.program.position;this.heap();let c=this.u32,u=this.f32,d=e>>>2,h=this.axis(l[0]),p=this.axis(l[1]),m=l[2]===4294967295?null:this.axis(l[2]),f=r>>>0===4294967295?null:this.snapshotColumn(r>>>0),y=this.words(),b=y[n0/ge]>>>2,A=y[xN/ge]>>>2,E=this.shape;E.kind=n,this.stopped.fill(0);let R=0;for(let g=0;g<Me;g++){if(c[d+g]===0)continue;let v=c[(t>>>2)+g];E.reach=u[d+Me+g],E.vx=u[d+3*Me+g],E.vy=u[d+4*Me+g],E.vz=u[d+5*Me+g],E.p0=u[d+6*Me+g],E.p1=u[d+7*Me+g],E.p2=u[d+8*Me+g];let x=a.runFrom(s,E,o,c,d+9*Me+g,d+10*Me+g,d+2*Me+g,f,h,p,m,v);for(let O=0;O<x;O++)c[b+R]=g,c[A+R]=a.rows[O],R++;}if(this.pairs=R,R>0)for(let g=R;g%Me!==0;g++)c[b+g]=c[b+R-1],c[A+g]=c[A+R-1];return R}keep(e,t,n){this.heap();let r=this.u32,o=this.words()[n0/ge]>>>2;for(let s=0;s<Me;s++){let a=t+s,l=0;if(a<this.pairs){let c=r[o+a];this.stopped[c]===0&&(l=4294967295,r[(e>>>2)+s]!==0&&(this.stopped[c]=1));}r[(n>>>2)+s]=l;}}words(){return this.heap(),this.ctxWords}prepare(e,t,n){let r=this.program,o=this.words();if(o[Uf/ge]=0,r.position===null)return 0;let s=this.u32,a=this.u8,l=o[Qd/ge]/ge,c=0,u=r.slots;for(let L=0;L<u.length;L++){let k=u[L];if(!k.neighbour)continue;let M=e[L],K=l+c*this.capacity;for(let Y=0;Y<t;Y++){let te=M.storage===3?a[M.at+Y]:s[M.at/ge+Y];s[K+Y]=PLe(k.kind,M.storage,te);}c++;}let d=this.f32,h=Ye(n[r.radius&2147483647]),p=r.position,m=p[0],f=p[1],y=p[2];if(this.grid!==null&&this.grid.rebuild(h,this.axis(m),this.axis(f),y===4294967295?null:this.axis(y),t),o[EN/ge]=0,o[bN/ge]=mt(h),!(h>0)||!Number.isFinite(h))return 0;let b=Math.fround(1/h);o[AN/ge]=mt(b),o[gN/ge]=mt(Math.fround(h*h));let A=l+this.neighbourOf(m)*this.capacity,E=l+this.neighbourOf(f)*this.capacity,R=y===4294967295?-1:l+this.neighbourOf(y)*this.capacity,g=this.table-1,v=o[r0/ge]/ge,x=o[i0/ge]/ge,O=o[o0/ge]/ge,N=o[s0/ge]/ge,I=o[a0/ge]/ge,S=o[Ff/ge]/ge,w=this.i32;s.fill(0,v,v+this.table+1),this.rowCells.length<t*3&&(this.rowCells=new Int32Array(this.capacity*3));let U=this.rowCells;for(let L=0;L<t;L++){let k=Math.floor(Math.fround(d[A+L]*b)),M=Math.floor(Math.fround(d[E+L]*b)),K=Math.floor(Math.fround((R<0?0:d[R+L])*b)),Y=k!==k?0:k>=Br?Br-1:k<-Br?-Br:k|0,te=M!==M?0:M>=Br?Br-1:M<-Br?-Br:M|0,Z=K!==K?0:K>=Br?Br-1:K<-Br?-Br:K|0;U[3*L]=Y,U[3*L+1]=te,U[3*L+2]=Z;let de=te+Math.imul(Y,dQ)+Math.imul(Z,hQ)&g;this.bucket[L]=de>>>0,s[v+de+1]++;}for(let L=1;L<=this.table;L++)s[v+L]+=s[v+L-1];for(let L=0;L<t;L++){let k=this.bucket[L],M=s[v+k]++,K=R<0?0:d[R+L];s[S+M]=L,d[O+M]=d[A+L],d[N+M]=d[E+L],d[I+M]=K,w[x+3*M]=U[3*L],w[x+3*M+1]=U[3*L+1],w[x+3*M+2]=U[3*L+2];}for(let L=this.table;L>0;L--)s[v+L]=s[v+L-1];return s[v]=0,o[EN/ge]=t,o[Ff/ge]}flush(){if(this.stageCapacity===0)return;let e=this.words(),t=e[Uf/ge],n=Math.min(t,this.stageCapacity),r=this.stageView,o=this.sortedEvents(r,n),s=this.ring,a=(s.length-er)/10,l=s[vo],c=s[Es]+(t-n),u=Qa-2-Po;for(let d=0;d<n;d++){if(l>=a){c++;continue}let h=o[d]*Qa+2+Po,p=er+l*10;for(let m=0;m<u;m++)s[p+m]=r[h+m];l++;}s[vo]=l,s[Es]=c,e[Uf/ge]=0;}eventBefore(e,t,n){let r=t*Qa,o=n*Qa;for(let s=0;s<2+Po;s++){let a=e[r+s]-e[o+s];if(a!==0)return a<0}return false}sortedEvents(e,t){this.eventOrder.length<t&&(this.eventOrder=new Uint32Array(this.stageCapacity),this.eventScratch=new Uint32Array(this.stageCapacity));let n=this.eventOrder,r=this.eventScratch;for(let o=0;o<t;o++)n[o]=o;for(let o=1;o<t;o*=2){for(let a=0;a<t;a+=2*o){let l=Math.min(a+o,t),c=Math.min(a+2*o,t),u=a,d=l,h=a;for(;u<l&&d<c;)r[h++]=this.eventBefore(e,n[d],n[u])?n[d++]:n[u++];for(;u<l;)r[h++]=n[u++];for(;d<c;)r[h++]=n[d++];}let s=n;n=r,r=s;}return n}clearEvents(){this.ring[vo]=0,this.ring[Es]=0;}};var FLe=255,Zt=4,$d=64,ULe=4294967295,BLe=["x","y","z","w"];function TQ(i,e){for(let c of uX)if(typeof i[c]!="function")return null;if(typeof i.engine_alloc!="function"||typeof i.engine_free!="function")return null;let t=i,n=typeof i.engine_kernel_isa_max=="function"?i.engine_kernel_isa_max():t.engine_kernel_isa();if(n<1)return null;let r=typeof i.engine_kernel_attach=="function"?i.engine_kernel_attach:null,o=typeof i.engine_kernel_attach_handle=="function"?i.engine_kernel_attach_handle:null,s=typeof i.engine_kernel_spawns=="function"?i.engine_kernel_spawns:null,a=dX.every(c=>typeof i[c]=="function")?{bindTable:i.engine_kernel_bind_table,bindPool:i.engine_kernel_bind_pool,report:i.engine_kernel_data}:null,l=typeof i.engine_kernel_run_region=="function"?i.engine_kernel_run_region:null;return {exports:t,memory:e,isa:n,attach:r,attachHandle:o,spawns:s,data:a,runRegion:l}}function _r(i,e){if(i>=0)return i;throw i===-1?new _("capacity_exceeded",`${e}: the engine is out of kernel slots`):i===-3?new _("unknown_resource",`${e}: the kernel or table is gone`):i===-5?new _("unsupported_feature",`${e}: the engine does not run this kernel instruction set`):i===rq?new _("capacity_exceeded",`${e}: the kernel ran too long and was stopped so the game stays responsive; split the work across frames or lower its row count`):new _("invalid_argument",`${e}: the engine refused the kernel (${i})`)}var EQ=32,FN=256,xQ=65536,vQ=16;function RQ(i){return Object.prototype.toString.call(i)==="[object SharedArrayBuffer]"}function GLe(i,e){if(i===null||e===null)return i===e;if(i.length!==e.length)return false;for(let t=0;t<i.length;t++)if(i[t]!==e[t]||!i[t].valid)return false;return true}function VLe(i){return typeof i=="object"&&i!==null&&"schema"in i&&"capacity"in i&&"values"in i}function HLe(i){for(let e=0;e<i.length;e++)if(!i[e].native)return false;return true}function WLe(i){let e=i.slots;for(let t=0;t<e.length;t++)if(e[t].spawn||e[t].scratch)return true;return false}function SQ(i,e){if(i.length!==e.length)return false;for(let t=0;t<e.length;t++)if(i[t]!==e[t])return false;return true}var m0=class{constructor(e){this.engine=e;this.programs=new Map;this.bindings=new Map;this.argsAt=0;this.argsBuffer=null;this.words=new Uint32Array(0);this.floats=new Float32Array(0);this.world=null;this.into=null;this.priority=0;this.compute=null;this.report={spawned:0,dropped:0,killed:0};this.spawnStats=new Uint32Array(0);this.spawnCounts={spawned:0,dropped:0,killed:0};this.columnsView=new Uint32Array(0);this.recordsView=new Uint32Array(0);this.hookBinding=0;this.hookDispatched=0;this.hookStage=null;this.hookCtxs=new Set;this.dataHook=(e,t)=>{let n=this.hookData(this.hookBinding,e,this.hookDispatched,t);n<0&&_r(n,"running a data op from a kernel");};this.hookData=null;this.reportCopies=new Map;this.heapView=new Uint32Array(0);this.joinedTables=new Map;this.scalarMaps=new Map;this.staged=new Map;this.stagedRuns=0;this.compiledRuns=0;this.recordsAt=0;this.recordsCapacity=0;this.compiled=new Map;this.columnsAt=0;this.compiling=new Set;this.groupRowsAt=0;this.groupRowsCapacity=0;this.groupRowsView=new Uint32Array(0);this.rings=new Map;e.data!==null&&e.data!==void 0&&Q9({alloc:t=>e.exports.engine_alloc(t,Zt),memory:e.memory});}acceptsData(){return this.engine.data!==null&&this.engine.data!==void 0}accepts(e){let t=e.byteLength>=8?e[4]:0;return t<2?true:t>=3&&(typeof this.engine.attachHandle!="function"||typeof this.engine.spawns!="function")?false:(this.engine.isa??1)>=t&&typeof this.engine.attach=="function"}attach(e){this.world=e;}copyIn(e){let n=this.engine.exports.engine_alloc(Math.max(e.byteLength,Zt),Zt);if(n===0)throw new _("capacity_exceeded","engine memory cannot hold a kernel program");return new Uint8Array(this.engine.memory.buffer,n,e.byteLength).set(e),n}program(e,t){let n=this.programs.get(t);if(n!==void 0)return n;let r=this.engine.exports,o=this.copyIn(t),s=r.engine_kernel_load(o,t.byteLength);return r.engine_free(o,Math.max(t.byteLength,Zt),Zt),_r(s,`loading kernel ${e.name}`),this.programs.set(t,s),s}binding(e,t,n,r,o){let s=this.bindings.get(t);s===void 0&&(s=[],this.bindings.set(t,s));let a=this.into!==null&&this.into!==r?this.into:null;for(let l=0;l<s.length;l++){let c=s[l];if(c.table===r&&c.into===a&&GLe(c.joined,o)&&r.valid&&(a===null||a.valid))return c.binding}return this.bindNew(e,n,r,o,a,s)}bindNew(e,t,n,r,o,s){let a=this.engine.exports;for(let h=s.length-1;h>=0;h--)s[h].table.valid&&(s[h].into===null||s[h].into.valid)||(a.engine_kernel_unbind(s[h].binding),this.compute?.unbound(qm,s[h].binding),s.splice(h,1));let l=o??n,c=new Uint32Array(e.slots.length);for(let h=0;h<e.slots.length;h++){let p=e.slots[h];if(p.scratch===true||p.pool!==void 0){c[h]=4294967295;continue}let m=p.spawn===true?l:p.table!==void 0&&p.table>0&&r!==null?r[p.table]:n;if(!(p.field in m.schema))throw new _("invalid_argument",`kernel ${e.name} ${p.spawn===true?"spawns":"reads"} ${p.field}, which the ${p.spawn===true?"spawn ":""}table does not have`);c[h]=m.column(p.field,p.component);}let u=this.copyIn(new Uint8Array(c.buffer)),d=a.engine_kernel_bind(t,n.id,u,c.length);if(a.engine_free(u,Math.max(c.byteLength,Zt),Zt),_r(d,`binding kernel ${e.name}`),this.compute?.bound(qm,d,e.name,this.priority),o!==null){let h=this.engine.attachHandle;if(h==null)throw new _("unsupported_feature",`kernel ${e.name} spawns into another table; this engine predates kernel_isa_3`);_r(h(d,aX,o.id),`attaching the spawn table to kernel ${e.name}`);}if(r!==null){let h=this.engine.data;for(let p of e.data?.tables??[])_r(h.bindTable(d,p.table,r[p.table].id),`binding table ${p.name} to kernel ${e.name}`);e.slots.forEach((p,m)=>{if(p.pool===void 0)return;let f=r[p.table??0],y=j9(f,p.field,p.pool,p.kind,p.component);if(y.at===0)throw new _("unsupported_feature",`kernel ${e.name} keeps the ${p.field} list outside engine memory`);_r(h.bindPool(d,m,y.at,y.words),`binding the ${p.field} list to kernel ${e.name}`);});}return s.push({table:n,into:o,joined:r===null?null:r.slice(),binding:d}),d}spawned(e,t){let n=this.engine.spawns;if(n==null)return;let r=n(e);if(r===0)return;let o=this.engine.memory.buffer,s=this.spawnStats;(s.length===0||s.byteOffset!==r||s.buffer!==o)&&(s=new Uint32Array(o,r,lX),this.spawnStats=s);let a=this.spawnCounts;a.spawned=s[0],a.dropped=s[1],a.killed=s[2];let l=this.into!==null&&this.into!==t?this.into:t;Ef(a,l,this.report);}columnPointers(){let e=this.engine.memory.buffer,t=this.columnsView;return (t.length===0||t.byteOffset!==this.columnsAt||t.buffer!==e)&&(t=new Uint32Array(e,this.columnsAt,FN),this.columnsView=t),t}recordWords(){let e=this.engine.memory.buffer,t=this.recordsView;return (t.length===0||t.byteOffset!==this.recordsAt||t.buffer!==e)&&(t=new Uint32Array(e,this.recordsAt,this.recordsCapacity/Zt),this.recordsView=t),t}armDataHook(e,t,n){this.hookStage=t,this.hookData=t.engine_kernel_stage_data??null,this.hookBinding=n,this.hookDispatched=0,!this.hookCtxs.has(e)&&(this.hookCtxs.add(e),IN(e,this.dataHook));}disarmDataHook(e){this.hookCtxs.delete(e)&&IN(e,null);}argViews(){let e=this.engine.memory.buffer;if(this.argsAt===0&&(this.argsAt=this.engine.exports.engine_alloc($d*Zt,Zt),this.argsAt===0))throw new _("capacity_exceeded","engine memory cannot hold kernel arguments");this.argsBuffer!==e&&(this.words=new Uint32Array(e,this.argsAt,$d),this.floats=new Float32Array(e,this.argsAt,$d),this.argsBuffer=e);}writeArg(e,t,n){if(t.kind==="f64"||t.kind==="u64")return Wa(this.words,e,t.kind,n);if(t.width>1&&(Array.isArray(n)||ArrayBuffer.isView(n))){let r=n;for(let o=0;o<t.width;o++)t.kind==="f32"?this.floats[e+o]=r[o]:this.words[e+o]=r[o]>>>0;return e+t.width}if(t.width>1){let r=n;for(let o=0;o<t.width;o++)this.floats[e+o]=r[BLe[o]];return e+t.width}switch(t.kind){case "f32":this.floats[e]=n;break;case "bool":this.words[e]=n?ULe:0;break;default:this.words[e]=n>>>0;}return e+1}run(e,t,n,r,o){if(!n.native)throw new _("unsupported_feature","native kernels run on engine tables");if(e.argWords>$d)throw new _("invalid_argument",`kernel ${e.name} takes more than ${$d} argument words`);let s=ks(e)?this.joinedOf(e,n,o):null;if(s!==null&&(!this.acceptsData()||!HLe(s)))throw new _("unsupported_feature",`kernel ${e.name} joins tables; this engine predates native data ops or a joined table is not an engine table`);let a=s===null?null:this.scalarMap(e),l=this.program(e,t),c=this.binding(e,t,l,n,s);this.argViews();let u=0,d=e.args;for(let y=0;y<d.length;y++){let b=d[y],A=a===null?y:a[y];b.width===1&&b.kind==="f32"?this.floats[u++]=o[A]:b.width===1&&(b.kind==="u32"||b.kind==="i32")?this.words[u++]=o[A]>>>0:u=this.writeArg(u,b,o[A]);}let h=t.byteLength>=8&&t[4]>=2,p=t.byteLength>=8&&t[4]>=3;if(h){let y=this.world?.handles()??null;if(y===null&&!p)throw new _("unsupported_feature",`kernel ${e.name} calls engine services; attach them with world.kernelServices({ physics, nav, flow, terrain, graphics })`);let b=this.engine.attach(c,y?.physics??0,y?.nav??0,y?.flow??0,y?.render??0);if(b<0&&_r(b,`attaching services to kernel ${e.name}`),p){let A=this.engine.attachHandle;A(c,rX,y?.ui??0),A(c,iX,y?.audio??0),A(c,oX,y?.voxels??0),A(c,sX,y?.chemistry??0);}}if(this.runStaged(t,n,c,u,r))return s!==null&&this.readReport(e,t,c),p&&this.spawned(c,n),r===null?n.count:r.length;if(r===null&&this.runCompiled(e,t,n,c,u))return s!==null&&this.readReport(e,t,c),n.count;let m=r?r.index:FLe;this.compute?.prioritise(qm,c,this.priority);let f=this.engine.exports.engine_kernel_run(c,m,this.argsAt,u);return f===eE&&this.priority!==0?0:(f>=0||_r(f,`running kernel ${e.name}`),s!==null&&this.readReport(e,t,c),e.channels!==void 0&&e.channels.length>0&&(hc(this.ring(c),e.channels),this.engine.exports.engine_kernel_clear_events(c)),p&&this.spawned(c,n),f)}readReport(e,t,n){let r=this.engine.data.report(n);if(r===0)return;let o=this.heapWords(),s=r>>>2,a=o[s+kg-1],l=kg+a;for(let d=0;d<a;d++)l+=o[s+kg+d];let c=this.reportCopies.get(t);c===void 0&&(c={meta:e,words:new Uint32Array(l),length:0,report:null},this.reportCopies.set(t,c)),c.words.length<l&&(c.words=new Uint32Array(Math.max(l,c.words.length*2)));let u=c.words;for(let d=0;d<l;d++)u[d]=o[s+d];c.meta=e,c.length=l,c.report=null;}dataReport(e){let t=this.reportCopies.get(e);return t===void 0?null:(t.report===null&&(t.report=J9(t.meta,t.words.slice(0,t.length))),t.report)}heapWords(){let e=this.engine.memory.buffer;return (this.heapView.buffer!==e||this.heapView.length===0)&&(this.heapView=new Uint32Array(e)),this.heapView}joinedOf(e,t,n){let r=this.joinedTables.get(e),o=e.data?.tables;if(r===void 0){let s=Ka(e,t,n);return this.joinedTables.set(e,s),s}if(r[0]=t,o===void 0)return r;for(let s=0;s<o.length;s++){let a=o[s],l=n[a.position];if(!VLe(l))return Ka(e,t,n);r[a.table]=l;}return r}scalarMap(e){let t=this.scalarMaps.get(e);if(t===void 0){let n=e.data?.tables,r=[];for(let o=0;r.length<e.args.length;o++){let s=false;if(n!==void 0)for(let a=0;a<n.length;a++)n[a].position===o&&(s=true);s||r.push(o);}t=Int32Array.from(r),this.scalarMaps.set(e,t);}return t}runStaged(e,t,n,r,o){let s=this.engine.memory,a=this.engine.exports;if(typeof WebAssembly>"u"||!(s instanceof WebAssembly.Memory)||typeof a.engine_kernel_stage_begin!="function")return false;let l=a,c=this.staged.get(e);if(c===void 0){let x=gc(e);c=MN(x)?{program:x,data:DN(x),storages:"",planned:false,storageWords:new Float64Array(x.slots.length),probe:new Array(x.slots.length).fill(0),runs:null,stages:[]}:null,this.staged.set(e,c);}if(c===null)return false;let u=t.count,d=0,h=u;if(o!==null){if(c.program.calls.length>0||c.program.cross.length>0||o.rows.buffer!==s.buffer)return false;h=o.length;for(let x=0;x<h;x++)if(o.rows[x]>=u)return false;d=o.rows.byteOffset;}let p=l.engine_kernel_stage_data;if(c.data&&typeof p!="function")return false;let m=c.program;_r(l.engine_kernel_stage_begin(n,this.argsAt,r),"starting a staged kernel");let f=c.probe;for(let x=0;x<f.length;x++)f[x]=l.engine_kernel_stage_storage(n,x);if(!c.planned||!SQ(c.storageWords,f)){let x=f.slice(),O=x.join(",");c.planned=true,c.storages=O,c.storageWords.set(x),c.runs=null;let N=PN(m,x,RQ(s.buffer)?xQ:null);if(N!==null){let I=c;this.track(pC(N.bytes,ON(s)).then(S=>{I.storages===O&&(I.stages=N.stages,I.runs=N.stages.map((w,U)=>S.exports[NN(U)]));}).catch(()=>{}));}}if(c.runs===null||this.columnsAt===0&&(this.columnsAt=this.engine.exports.engine_alloc(FN*Zt,Zt),this.columnsAt===0))return false;let y=CN(m)+c0;if(this.recordsCapacity<y&&(this.recordsAt!==0&&(this.disarmDataHook(this.recordsAt),this.engine.exports.engine_free(this.recordsAt,this.recordsCapacity,vQ)),this.recordsAt=this.engine.exports.engine_alloc(y,vQ),this.recordsCapacity=this.recordsAt===0?0:y,this.recordsAt===0))return false;let b=this.columnPointers();for(let x=0;x<m.slots.length;x++)b[x]=l.engine_kernel_stage_column(n,x);let A=this.recordWords(),E=m.cross;for(let x=0;x<E.length;x++)A[x]=l.engine_kernel_stage_records(n,E[x]);let R=l.engine_kernel_stage_uniforms(n);c.data&&p!==void 0&&this.armDataHook(this.recordsAt,l,n);let g=c.runs,v=c.stages;for(let x=0;x<v.length;x++){let O=v[x];if(g[x](this.columnsAt,h,d,R,this.recordsAt),h>0&&this.hookDispatched++,O.barrier==="call")_r(l.engine_kernel_stage_call(n,O.pcs[0]),"calling the engine from a kernel");else if(O.barrier==="cross")for(let N=0;N<O.pcs.length;N++)_r(l.engine_kernel_stage_finish(n,O.pcs[N]),"finishing a cross-row stage");}return _r(l.engine_kernel_stage_end(n),"ending a staged kernel"),this.stagedRuns++,true}compiledEntry(e,t,n){let r=this.compiled.get(t);if(r!==void 0)return r;let o=gc(t),s=DN(o),a=!MN(o)&&!WLe(o)&&(!s||typeof n.engine_kernel_stage_data=="function"&&typeof n.engine_kernel_stage_begin=="function"),l=e.slots.length,c=a?{runs:null,storages:"",planned:false,program:o,data:s,needsHost:yQ(o),offsets:new Uint32Array(o.groups.length+1),columns:new Int32Array(l),probe:new Array(l).fill(0),storageWords:new Float64Array(l),hostColumns:Array.from({length:l},()=>({at:0,storage:0})),uniforms:null,host:null,state:null}:null;return this.compiled.set(t,c),c}planCompiled(e,t){e.planned=true;let n=e.probe.slice();e.storageWords.set(n),e.storages=n.join(",");let r=PN(e.program,n,RQ(t.buffer)?xQ:null);r!==null&&this.track(pC(r.bytes,ON(t)).then(o=>{let s=r.groups>0?Array.from({length:r.groups},(a,l)=>h0(l)):[h0(-1)];e.runs=s.map(a=>o.exports[a]);}).catch(()=>{}));}track(e){this.compiling.add(e),e.finally(()=>this.compiling.delete(e));}async settled(){for(;this.compiling.size>0;)await Promise.all([...this.compiling]);}finishCompiled(e,t,n,r){let o=e.host;return e.data&&_r(n.engine_kernel_stage_end(r),"ending a data kernel"),o!==null&&t.channels!==void 0&&t.channels.length>0&&(o.flush(),hc(o.ring,t.channels),o.clearEvents()),true}stateView(e,t,n,r){let o=this.engine.memory.buffer,s=e.state,a=n===0;if(s!==null&&s.buffer===o&&s.byteOffset===t&&s.length===r&&s instanceof Float32Array===a)return s;let l=a?new Float32Array(o,t,r):new Uint32Array(o,t,r);return e.state=l,l}groupRows(e){let t=this.engine.memory.buffer,n=this.groupRowsView;return (n.length!==e||n.byteOffset!==this.groupRowsAt||n.buffer!==t)&&(n=new Uint32Array(t,this.groupRowsAt,e),this.groupRowsView=n),n}runCompiled(e,t,n,r,o){let s=this.engine.memory;if(typeof WebAssembly>"u"||!(s instanceof WebAssembly.Memory))return false;let a=this.engine.exports,l=this.compiledEntry(e,t,a);if(l===null)return false;let c=a,u=l.data;u&&_r(c.engine_kernel_stage_begin(r,this.argsAt,o),"starting a data kernel");let d=e.slots,h=l.columns,p=l.probe;if(u)for(let x=0;x<d.length;x++)p[x]=c.engine_kernel_stage_storage(r,x);else for(let x=0;x<d.length;x++){let O=n.column(d[x].field,d[x].component);h[x]=O,p[x]=n.header[EQ+2*O+1];}if(l.planned||this.planCompiled(l,s),l.runs===null||!SQ(l.storageWords,p)||this.columnsAt===0&&(this.columnsAt=this.engine.exports.engine_alloc(FN*Zt,Zt),this.columnsAt===0))return false;let m=this.columnPointers();for(let x=0;x<d.length;x++)m[x]=u?c.engine_kernel_stage_column(r,x):n.header[EQ+2*h[x]];let f=n.count,y=l.program,b=0,A=0;if(l.needsHost){if(l.host===null||l.host.capacity!==n.capacity){l.host!==null&&(this.disarmDataHook(l.host.ctx),l.host.dispose());let I=this.engine.exports;l.host=new u0(y,n.capacity,this.engine.memory,S=>I.engine_alloc(S,Zt));}b=l.host.ctx;let x=l.uniforms;x===null&&(x=y.uniforms.slice(),l.uniforms=x);let O=this.words;for(let I=0;I<y.args;I++)x[I]=O[I];let N=l.hostColumns;for(let I=0;I<d.length;I++)N[I].at=m[I],N[I].storage=p[I];A=l.host.prepare(N,f,x);}this.compiledRuns++,u&&this.armDataHook(b,c,r);let E=l.runs;if(y.state<0)return E[0](this.columnsAt,f,A,this.argsAt,b),this.finishCompiled(l,e,c,r);if(this.groupRowsCapacity<n.capacity&&(this.groupRowsAt!==0&&this.engine.exports.engine_free(this.groupRowsAt,this.groupRowsCapacity*Zt,Zt),this.groupRowsAt=this.engine.exports.engine_alloc(n.capacity*Zt,Zt),this.groupRowsCapacity=this.groupRowsAt===0?0:n.capacity,this.groupRowsAt===0))return false;let R=this.stateView(l,m[y.state],p[y.state],n.capacity);bQ(y,R,f,this.groupRows(n.capacity),l.offsets);let g=l.offsets,v=l.host!==null&&e.channels!==void 0&&e.channels.length>0;for(let x=0;x<E.length;x++){let O=g[x+1]-g[x];O>0&&(E[x](this.columnsAt,O,this.groupRowsAt+g[x]*Zt,this.argsAt,b),this.hookDispatched++,v&&l.host.flush());}return this.finishCompiled(l,e,c,r)}ring(e){let t=this.rings.get(e);if(t!==void 0&&t.buffer===this.engine.memory.buffer)return t;let n=this.engine.exports.engine_kernel_events(e),r=new Uint32Array(this.engine.memory.buffer,n,er+Ro*10);return this.rings.set(e,r),r}dispose(){let e=this.engine.exports;for(let t of this.bindings.values())for(let n of t)e.engine_kernel_unbind(n.binding);for(let t of this.programs.values())e.engine_kernel_unload(t);this.argsAt!==0&&e.engine_free(this.argsAt,$d*Zt,Zt),this.bindings.clear(),this.programs.clear(),this.argsAt=0;}};var KLe=["engine_chemistry_open","engine_chemistry_close","engine_chemistry_define","engine_chemistry_find","engine_chemistry_catalog","engine_chemistry_text","engine_chemistry_counts","engine_chemistry_species_info","engine_chemistry_reaction_info","engine_chemistry_grid_open","engine_chemistry_grid_close","engine_chemistry_grid_step","engine_chemistry_grid_paint","engine_chemistry_grid_set","engine_chemistry_grid_heat","engine_chemistry_grid_power","engine_chemistry_grid_columns","engine_chemistry_grid_colours","engine_chemistry_grid_events","engine_chemistry_grid_clear_events","engine_chemistry_grid_watch","engine_chemistry_grid_threshold","engine_chemistry_grid_unthreshold","engine_chemistry_grid_fired","engine_chemistry_grid_stats","engine_chemistry_grid_probe","engine_chemistry_grid_save","engine_chemistry_grid_saved","engine_chemistry_grid_load","engine_chemistry_vessel_open","engine_chemistry_vessel_close","engine_chemistry_vessel_add","engine_chemistry_vessel_take","engine_chemistry_vessel_heat","engine_chemistry_vessel_power","engine_chemistry_vessel_step","engine_chemistry_vessel_vent","engine_chemistry_vessel_state","engine_chemistry_particles_open","engine_chemistry_particles_close","engine_chemistry_particles_spawn","engine_chemistry_particles_step","engine_chemistry_particles_columns","engine_chemistry_particles_events"];function wQ(i,e){for(let t of KLe)if(typeof i[t]!="function")return null;return typeof i.engine_alloc!="function"||typeof i.engine_free!="function"?null:{exports:i,memory:e}}var YLe=["engine_transform_fft_open","engine_transform_fft_close","engine_transform_fft_run","engine_transform_convolver_open","engine_transform_convolver_close","engine_transform_convolve","engine_transform_sat_open","engine_transform_sat_close","engine_transform_sat_build","engine_transform_distance_open","engine_transform_distance_close","engine_transform_distance_mask","engine_transform_distance_signed","engine_transform_jump_flood","engine_transform_multigrid_open","engine_transform_multigrid_close","engine_transform_multigrid_solve"];function IQ(i,e){for(let t of YLe)if(typeof i[t]!="function")return null;return typeof i.engine_alloc!="function"||typeof i.engine_free!="function"?null:{exports:i,memory:e}}function OQ(i){}var CQ=["focus_distance","focus_visible","focus_since_seen","focus_confidence","focus_threat","hostiles_known","allies_near","attack_token_free","action_seconds","goal_distance","lateness","best_object"];var NQ=["engine_ai_create","engine_ai_destroy","engine_ai_registers","engine_ai_view","engine_ai_slots","engine_ai_archetype","engine_ai_spawn","engine_ai_despawn","engine_ai_target_add","engine_ai_target_remove","engine_ai_target_move","engine_ai_target_threat","engine_ai_agent_target","engine_ai_noise","engine_ai_goal","engine_ai_focus","engine_ai_skill","engine_ai_need","engine_ai_speed","engine_ai_place","engine_ai_step","engine_ai_events","engine_ai_doing","engine_ai_aim","engine_ai_digest","engine_ai_squad","engine_ai_join","engine_ai_leave","engine_ai_object_add","engine_ai_object_remove","engine_ai_cover_add","engine_ai_cover_remove"],kQ="engine_ai_step_world";var LQ=0;function qLe(i){for(let e of NQ)if(typeof i[e]!="function")return null;return i}var UN=class{constructor(e,t,n){this.name="cimplify-engine-ai";this.runtime=e,this.exports=t,this.physicsWorld=n;let r=e.symbols[kQ];this.stepWorld=typeof r=="function"?r:null;}buffer(){return this.runtime.memory.buffer}alloc(e,t){return this.runtime.exports.engine_alloc(e,t)}free(e,t,n){this.runtime.exports.engine_free(e,t,n);}step(e){let t=this.physicsWorld();return this.stepWorld!==null&&t!==LQ?this.stepWorld(e,t):this.exports.engine_ai_step(e)}};function MQ(i,e=()=>LQ){let t=qLe(i.symbols);return t?new UN(i,t,e):null}var Gf=[2,4,2],Ut=16;var yMe=["engine_nav_create","engine_nav_destroy","engine_nav_registers","engine_nav_costs","engine_nav_include","engine_nav_add_tile","engine_nav_remove_tile","engine_nav_nearest","engine_nav_find_path","engine_nav_agents","engine_nav_agent_add","engine_nav_agent_remove","engine_nav_agent_target","engine_nav_agent_stop","engine_nav_step","engine_nav_roads","engine_nav_vehicles","engine_nav_vehicle_add","engine_nav_vehicle_remove","engine_nav_vehicle_external","engine_nav_signal","engine_nav_add_link","engine_nav_remove_link"],Uo=0,BQ=new Float32Array(0),AMe=["","capacity exceeded","dead entity","unknown resource","invalid argument","unsupported"],bMe=6;function GQ(i){for(let e of yMe)if(typeof i[e]!="function")return null;return i}var f0=class{constructor(e,t){this.name="cimplify-engine-nav";this.handle=Uo;this.words=new Uint32Array(0);this.floats=new Float32Array(0);this.costs=new Float32Array(0);this.agentView=BQ;this.vehicleView=BQ;this.maxAgents=0;this.maxVehicles=0;this.scratch=Uo;this.scratchBytes=0;this.complete=false;this.runtime=e,this.exports=t;}get pathComplete(){return this.complete}batchHandle(){return this.handle}check(e,t){if(e<0){let n=-e===1?"capacity_exceeded":-e===3?"unknown_resource":-e===5?"unsupported_feature":"invalid_argument";throw new _(n,`${t}: ${AMe[-e]??"failed"}`)}return e}require(){if(this.handle===Uo)throw new _("not_initialized","navigation is not initialised");return this.handle}alloc(e){if(e<=this.scratchBytes)return this.scratch;if(this.scratch!==Uo&&this.runtime.exports.engine_free(this.scratch,this.scratchBytes,Rt),this.scratch=this.runtime.exports.engine_alloc(e,Rt),this.scratch===Uo)throw new _("capacity_exceeded","engine memory is full");return this.scratchBytes=e,this.scratch}init(e){let t=this.alloc(16*Rt),n=this.runtime.memory.buffer,r=new Uint32Array(n,t,16),o=new Float32Array(n,t,16);r.fill(0);let s=e.origin??[0,0],a=e.extents??Gf;o[0]=s[0],o[1]=s[1],o[2]=e.tileWorld,r[3]=e.maxTiles??256,r[4]=e.queryNodes??2048,this.maxAgents=e.maxAgents??512,r[5]=this.maxAgents,o[6]=e.neighbourDistance??4,o[7]=e.timeHorizon??2,r[8]=e.pathBudget??16,r[9]=e.maxPathPolys??256;for(let c=0;c<3;c++)o[10+c]=a[c];if(this.handle=this.exports.engine_nav_create(t),this.handle===Uo)throw new _("invalid_argument","navigation could not be created");let l=this.exports.engine_nav_registers(this.handle);this.words=new Uint32Array(n,l,32),this.floats=new Float32Array(n,l,32);for(let c=0;c<3;c++)this.floats[6+c]=a[c];this.costs=new Float32Array(n,this.exports.engine_nav_costs(this.handle),64),this.agentView=new Float32Array(n,this.exports.engine_nav_agents(this.handle),this.maxAgents*8);}addTile(e){let t=this.require(),n=this.alloc(e.byteLength);return new Uint8Array(this.runtime.memory.buffer,n,e.byteLength).set(e),this.check(this.exports.engine_nav_add_tile(t,n,e.byteLength),"add tile")}removeTile(e,t){this.check(this.exports.engine_nav_remove_tile(this.require(),e,t),"remove tile");}addLink(e,t,n,r,o,s){let a=this.require(),l=this.floats;for(let c=0;c<3;c++)l[0+c]=e[c],l[3+c]=t[c];return l[29]=n,this.words[30]=(r?1:0)|o<<8,this.words[31]=s>>>0,this.check(this.exports.engine_nav_add_link(a),"add link")}removeLink(e){this.check(this.exports.engine_nav_remove_link(this.require(),e),"remove link");}setAreaCost(e,t){this.require(),this.costs[e]=t;}setIncludeMask(e,t){let n=this.require();this.words[27]=e,this.words[28]=t,this.check(this.exports.engine_nav_include(n),"include mask");}nearest(e,t,n,r){let o=this.require(),s=this.floats;return s[0]=e,s[1]=t,s[2]=n,this.check(this.exports.engine_nav_nearest(o),"nearest")===0?false:(r[0]=s[10],r[1]=s[11],r[2]=s[12],true)}findPath(e,t,n,r,o,s,a){let l=this.require(),c=this.floats;c[0]=e,c[1]=t,c[2]=n,c[3]=r,c[4]=o,c[5]=s;let u=Math.max(Math.floor(a.length/3),1),d=this.alloc(u*3*Rt),h=this.exports.engine_nav_find_path(l,d,u);return h<0?(this.complete=false,0):(a.set(new Float32Array(this.runtime.memory.buffer,d,h*3)),this.complete=this.words[13]===1,h)}addAgent(e,t,n,r,o,s){let a=this.require(),l=this.floats;return l[0]=e,l[1]=t,l[2]=n,l[15]=r,l[16]=o,l[17]=s,this.check(this.exports.engine_nav_agent_add(a),"add agent")}removeAgent(e){this.check(this.exports.engine_nav_agent_remove(this.require(),e),"remove agent");}setAgentTarget(e,t,n,r){let o=this.require(),s=this.floats;s[3]=t,s[4]=n,s[5]=r,this.check(this.exports.engine_nav_agent_target(o,e),"agent target");}stopAgent(e){this.check(this.exports.engine_nav_agent_stop(this.require(),e),"stop agent");}agents(){return this.agentView}loadRoads(e){let t=this.require(),n=this.alloc(e.byteLength);new Uint32Array(this.runtime.memory.buffer,n,e.length).set(e),this.check(this.exports.engine_nav_roads(t,n,e.length),"load roads"),this.maxVehicles=e[5];let r=Math.ceil(this.maxVehicles/4)*4;this.vehicleView=new Float32Array(this.runtime.memory.buffer,this.exports.engine_nav_vehicles(t),r*8);}addVehicle(e,t,n,r){let o=this.require(),s=this.floats;s[18]=t,s[19]=n;for(let a=0;a<bMe;a++)s[20+a]=r[a];return this.check(this.exports.engine_nav_vehicle_add(o,e),"add vehicle")}removeVehicle(e){this.check(this.exports.engine_nav_vehicle_remove(this.require(),e),"remove vehicle");}setExternalVehicle(e,t,n,r){let o=this.require();this.floats[18]=n,this.floats[19]=r,this.check(this.exports.engine_nav_vehicle_external(o,e,t),"external vehicle");}vehicles(){return this.vehicleView}signal(e){return this.check(this.exports.engine_nav_signal(this.require(),e),"signal")}step(e){let t=this.require();this.floats[14]=e,this.check(this.exports.engine_nav_step(t),"nav step");}dispose(){this.handle!==Uo&&this.exports.engine_nav_destroy(this.handle),this.scratch!==Uo&&this.runtime.exports.engine_free(this.scratch,this.scratchBytes,Rt),this.handle=Uo,this.scratch=Uo,this.scratchBytes=0;}};function nn(i,e){for(let t=0;t<e.length;t++){let n=e[t],r=i[n];Reflect.set(i,n,.5),Reflect.set(i,n,r);}}var XN=class{constructor(e=0,t=0){this.x=e,this.y=t;}set(e,t){return this.x=e,this.y=t,this}copy(e){return this.x=e.x,this.y=e.y,this}length(){return Math.sqrt(this.x*this.x+this.y*this.y)}add(e){return this.x+=e.x,this.y+=e.y,this}sub(e){return this.x-=e.x,this.y-=e.y,this}scale(e){return this.x*=e,this.y*=e,this}dot(e){return this.x*e.x+this.y*e.y}cross(e){return this.x*e.y-this.y*e.x}normalize(){let e=this.length();return e>1e-6&&this.scale(1/e),this}distanceTo(e){return Math.hypot(this.x-e.x,this.y-e.y)}lerp(e,t,n){return this.x=e.x+(t.x-e.x)*n,this.y=e.y+(t.y-e.y)*n,this}angle(){return Math.atan2(-this.y,-this.x)+Math.PI}rotateAround(e,t){let n=Math.cos(t),r=Math.sin(t),o=this.x-e.x,s=this.y-e.y;return this.x=o*n-s*r+e.x,this.y=o*r+s*n+e.y,this}},qN=class{constructor(e=0,t=0,n=0,r=1){this.x=e,this.y=t,this.z=n,this.w=r;}set(e,t,n,r){return this.x=e,this.y=t,this.z=n,this.w=r,this}copy(e){return this.set(e.x,e.y,e.z,e.w)}dot(e){return this.x*e.x+this.y*e.y+this.z*e.z+this.w*e.w}length(){return Math.sqrt(this.dot(this))}scale(e){return this.set(this.x*e,this.y*e,this.z*e,this.w*e)}lerp(e,t,n){return this.set(e.x+(t.x-e.x)*n,e.y+(t.y-e.y)*n,e.z+(t.z-e.z)*n,e.w+(t.w-e.w)*n)}applyMat4(e,t){let{x:n,y:r,z:o,w:s}=this;return this.set(e[t]*n+e[t+4]*r+e[t+8]*o+e[t+12]*s,e[t+1]*n+e[t+5]*r+e[t+9]*o+e[t+13]*s,e[t+2]*n+e[t+6]*r+e[t+10]*o+e[t+14]*s,e[t+3]*n+e[t+7]*r+e[t+11]*o+e[t+15]*s)}readFrom(e,t){return this.set(e[t],e[t+1],e[t+2],e[t+3])}writeTo(e,t){e[t]=this.x,e[t+1]=this.y,e[t+2]=this.z,e[t+3]=this.w;}},Kt=class{constructor(e=0,t=0,n=0){this.x=e,this.y=t,this.z=n;}set(e,t,n){return this.x=e,this.y=t,this.z=n,this}copy(e){return this.x=e.x,this.y=e.y,this.z=e.z,this}add(e){return this.x+=e.x,this.y+=e.y,this.z+=e.z,this}sub(e){return this.x-=e.x,this.y-=e.y,this.z-=e.z,this}scale(e){return this.x*=e,this.y*=e,this.z*=e,this}addScaled(e,t){return this.x+=e.x*t,this.y+=e.y*t,this.z+=e.z*t,this}dot(e){return this.x*e.x+this.y*e.y+this.z*e.z}cross(e,t){let n=e.y*t.z-e.z*t.y,r=e.z*t.x-e.x*t.z,o=e.x*t.y-e.y*t.x;return this.x=n,this.y=r,this.z=o,this}lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z}length(){return Math.sqrt(this.lengthSq())}normalize(){let e=this.length();return e>1e-6&&this.scale(1/e),this}lerp(e,t,n){return this.x=e.x+(t.x-e.x)*n,this.y=e.y+(t.y-e.y)*n,this.z=e.z+(t.z-e.z)*n,this}distanceTo(e){return Math.sqrt(this.distanceToSquared(e))}distanceToSquared(e){let t=this.x-e.x,n=this.y-e.y,r=this.z-e.z;return t*t+n*n+r*r}negate(){return this.set(-this.x,-this.y,-this.z)}min(e){return this.set(Math.min(this.x,e.x),Math.min(this.y,e.y),Math.min(this.z,e.z))}max(e){return this.set(Math.max(this.x,e.x),Math.max(this.y,e.y),Math.max(this.z,e.z))}clamp(e,t){return this.set(Math.max(e.x,Math.min(t.x,this.x)),Math.max(e.y,Math.min(t.y,this.y)),Math.max(e.z,Math.min(t.z,this.z)))}clampLength(e,t){let n=this.length();return n<1e-6?this:this.scale(Math.max(e,Math.min(t,n))/n)}subVectors(e,t){return this.set(e.x-t.x,e.y-t.y,e.z-t.z)}addVectors(e,t){return this.set(e.x+t.x,e.y+t.y,e.z+t.z)}applyQuat(e){return e.rotate(this),this}applyMat4(e,t){let n=this.x,r=this.y,o=this.z,s=e[t+3]*n+e[t+7]*r+e[t+11]*o+e[t+15],a=Math.abs(s)>1e-6?1/s:1;return this.set((e[t]*n+e[t+4]*r+e[t+8]*o+e[t+12])*a,(e[t+1]*n+e[t+5]*r+e[t+9]*o+e[t+13])*a,(e[t+2]*n+e[t+6]*r+e[t+10]*o+e[t+14])*a)}transformDirection(e,t){let n=this.x,r=this.y,o=this.z;return this.set(e[t]*n+e[t+4]*r+e[t+8]*o,e[t+1]*n+e[t+5]*r+e[t+9]*o,e[t+2]*n+e[t+6]*r+e[t+10]*o),this.normalize()}projectOnVector(e){let t=e.x*e.x+e.y*e.y+e.z*e.z;if(t<1e-6)return this.set(0,0,0);let n=this.dot(e)/t;return this.set(e.x*n,e.y*n,e.z*n)}projectOnPlane(e){let t=this.dot(e);return this.set(this.x-e.x*t,this.y-e.y*t,this.z-e.z*t)}reflect(e){let t=2*this.dot(e);return this.set(this.x-e.x*t,this.y-e.y*t,this.z-e.z*t)}angleTo(e){let t=Math.sqrt(this.lengthSq()*(e.x*e.x+e.y*e.y+e.z*e.z));return t<1e-6?Math.PI/2:Math.acos(Math.max(-1,Math.min(1,this.dot(e)/t)))}setFromSpherical(e,t,n){let r=Math.sin(t)*e;return this.set(r*Math.sin(n),Math.cos(t)*e,r*Math.cos(n))}setFromMatrixColumn(e,t,n){return this.readFrom(e,t+n*4)}equals(e,t=0){return Math.abs(this.x-e.x)<=t&&Math.abs(this.y-e.y)<=t&&Math.abs(this.z-e.z)<=t}readFrom(e,t){return this.x=e[t],this.y=e[t+1],this.z=e[t+2],this}writeTo(e,t){e[t]=this.x,e[t+1]=this.y,e[t+2]=this.z;}},vc=class{constructor(e=0,t=0,n=0,r=1){this.x=e,this.y=t,this.z=n,this.w=r;}set(e,t,n,r){return this.x=e,this.y=t,this.z=n,this.w=r,this}identity(){return this.set(0,0,0,1)}copy(e){return this.set(e.x,e.y,e.z,e.w)}setAxisAngle(e,t){let n=t*.5,r=Math.sin(n);return this.set(e.x*r,e.y*r,e.z*r,Math.cos(n))}setEuler(e,t,n){let r=Math.cos(e*.5),o=Math.sin(e*.5),s=Math.cos(t*.5),a=Math.sin(t*.5),l=Math.cos(n*.5),c=Math.sin(n*.5);return this.set(o*s*l+r*a*c,r*a*l-o*s*c,r*s*c+o*a*l,r*s*l-o*a*c)}multiply(e,t){return this.set(e.w*t.x+e.x*t.w+e.y*t.z-e.z*t.y,e.w*t.y-e.x*t.z+e.y*t.w+e.z*t.x,e.w*t.z+e.x*t.y-e.y*t.x+e.z*t.w,e.w*t.w-e.x*t.x-e.y*t.y-e.z*t.z)}normalize(){let e=Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w);if(e<1e-6)return this.identity();let t=1/e;return this.set(this.x*t,this.y*t,this.z*t,this.w*t)}rotate(e){let{x:t,y:n,z:r,w:o}=this,s=o*e.x+n*e.z-r*e.y,a=o*e.y+r*e.x-t*e.z,l=o*e.z+t*e.y-n*e.x,c=-t*e.x-n*e.y-r*e.z;return e.set(s*o+c*-t+a*-r-l*-n,a*o+c*-n+l*-t-s*-r,l*o+c*-r+s*-n-a*-t)}dot(e){return this.x*e.x+this.y*e.y+this.z*e.z+this.w*e.w}conjugate(){return this.set(-this.x,-this.y,-this.z,this.w)}invert(){let e=this.dot(this);if(e<1e-6)return this.identity();let t=1/e;return this.set(-this.x*t,-this.y*t,-this.z*t,this.w*t)}premultiply(e){return this.multiply(e,this)}slerp(e,t,n){let r=t.x,o=t.y,s=t.z,a=t.w,l=e.x*r+e.y*o+e.z*s+e.w*a;l<0&&(l=-l,r=-r,o=-o,s=-s,a=-a);let c=1-n,u=n;if(l<=.9995){let d=Math.acos(l),h=Math.sin(d);c=Math.sin((1-n)*d)/h,u=Math.sin(n*d)/h;}return this.set(e.x*c+r*u,e.y*c+o*u,e.z*c+s*u,e.w*c+a*u),this.normalize()}rotateTowards(e,t){let n=this.angleTo(e);return n<1e-6?this:this.slerp(this,e,Math.min(1,t/n))}angleTo(e){return 2*Math.acos(Math.min(1,Math.abs(this.dot(e))))}setFromUnitVectors(e,t){let n=e.x*t.x+e.y*t.y+e.z*t.z+1;return n<1e-6?(n=0,Math.abs(e.x)>Math.abs(e.z)?this.set(-e.y,e.x,0,n).normalize():this.set(0,-e.z,e.y,n).normalize()):this.set(e.y*t.z-e.z*t.y,e.z*t.x-e.x*t.z,e.x*t.y-e.y*t.x,n).normalize()}setFromRotationMatrix(e,t){return a1(Bo,0,e[t],e[t+1],e[t+2],e[t+4],e[t+5],e[t+6],e[t+8],e[t+9],e[t+10]),this.set(Bo[0],Bo[1],Bo[2],Bo[3])}lookRotation(e,t,n,r=0,o=1,s=0){let a=-e,l=-t,c=-n,u=Math.sqrt(a*a+l*l+c*c);if(u<1e-6)return this.identity();a/=u,l/=u,c/=u;let d=o*c-s*l,h=s*a-r*c,p=r*l-o*a;u=Math.sqrt(d*d+h*h+p*p),u<1e-6&&(d=1,h=0,p=0,u=1),d/=u,h/=u,p/=u;let m=l*p-c*h,f=c*d-a*p,y=a*h-l*d;return a1(Bo,0,d,h,p,m,f,y,a,l,c),this.set(Bo[0],Bo[1],Bo[2],Bo[3])}toEuler(e){let{x:t,y:n,z:r,w:o}=this,s=1-2*(n*n+r*r),a=2*(t*n-o*r),l=2*(t*r+o*n),c=1-2*(t*t+r*r),u=2*(n*r-o*t),d=2*(n*r+o*t),h=1-2*(t*t+n*n),p=Math.asin(Math.max(-1,Math.min(1,l)));return Math.abs(l)<1-1e-6?e.set(Math.atan2(-u,h),p,Math.atan2(-a,s)):e.set(Math.atan2(d,c),p,0)}readFrom(e,t){return this.set(e[t],e[t+1],e[t+2],e[t+3])}writeTo(e,t){e[t]=this.x,e[t+1]=this.y,e[t+2]=this.z,e[t+3]=this.w;}},Bo=new Float64Array(4);nn(new XN,["x","y"]);nn(new qN,["x","y","z","w"]);nn(new Kt,["x","y","z"]);nn(new vc,["x","y","z","w"]);var gMe=0,EMe=1,xMe=2,vMe=3,Vf=class{constructor(){this.kind="ball";this.params=new Kt(.5,0,0);this.origin=new Kt;this.rotation=new Float32Array([0,0,0,1]);this.direction=new Kt(0,-1,0);this.maxDistance=Number.MAX_VALUE;this.includeSensors=false;this.excludeBody=-1;}ball(e){return this.kind="ball",this.params.set(e,0,0),this}cuboid(e,t,n){return this.kind="cuboid",this.params.set(e,t,n),this}capsule(e,t){return this.kind="capsule",this.params.set(e,t,0),this}cylinder(e,t){return this.kind="cylinder",this.params.set(e,t,0),this}};function VQ(i){return i==="ball"?gMe:i==="cuboid"?EMe:i==="capsule"?xMe:vMe}nn(new Vf,["maxDistance"]);var A0=16;var RMe=1,SMe=2,TMe=4,wMe=8,IMe=8,OMe=16,CMe=0,NMe=1,Jd=2,HQ={};function Za(i){if(!Number.isInteger(i)||i<0||i>=A0)throw new _("invalid_argument",`collider classes are integers from 0 to ${A0-1}`);return i}function kMe(i){return (i.ignore?RMe:0)|(i.friction!==void 0?SMe:0)|(i.restitution!==void 0?TMe:0)|(i.oneWay!==void 0?wMe:0)}function WQ(i,e,t){return (Za(i)|Za(e)<<IMe|kMe(t)<<OMe)>>>0}function KQ(i,e,t){e[t+CMe]=i.friction??0,e[t+NMe]=i.restitution??0;let n=i.oneWay;if(n===void 0){e[t+Jd]=0,e[t+Jd+1]=0,e[t+Jd+2]=0;return}let r=Math.hypot(n[0],n[1],n[2]);if(!(r>0))throw new _("invalid_argument","a one-way normal must be a non-zero vector");e[t+Jd]=n[0]/r,e[t+Jd+1]=n[1]/r,e[t+Jd+2]=n[2]/r;}function Yt(i,e,t=0){let n=Array.from({length:16},(r,o)=>o===i?e:0);return {bias:t,gains:n}}function el(i,e,t){let n=Array.from({length:16},(r,o)=>i.gains?.[o]??0);return n[e]=t,{bias:i.bias??0,gains:n}}var z=Math.fround,Zd=z(Math.PI),Go=z(Math.PI*2),LMe=z(Math.PI/2),MMe=z(1/Go),DMe=z(2/Math.PI),YQ=12582912,PMe=4194304,FMe=z(1.5703125),UMe=z(.0004837513),BMe=z(754979e-13),GMe=z(-0.16666655),VMe=z(.008332161),HMe=z(-19515296e-11),WMe=z(.041666646),KMe=z(-0.0013887316),YMe=z(24433157e-12),XMe=.25,zN=.125,QN=.375,qMe=z(.99997726),zMe=z(-0.33262347),QMe=z(.19354346),$Me=z(-0.11643287),jMe=z(.05265332),JMe=z(-0.0117212),ZMe=z(Math.LOG2E),e3e=z(.69314575),t3e=z(14286068e-13),n3e=.5,r3e=z(.16666667),i3e=z(.041666668),o3e=z(.008333334),s3e=z(.0013888889),XQ=87,qQ=9;function Hf(i,e,t){let n=i>e?i:e;return n<t?n:t}function b0(i){return Math.abs(i)<PMe?z(z(i+YQ)-YQ):i}function tl(i){return z(i-z(b0(z(i*MMe))*Go))}function yr(i,e){let t=b0(z(i*DMe)),n=z(z(z(i-z(t*FMe))-z(t*UMe))-z(t*BMe)),r=z(n*n),o=z(z(z(z(z(z(z(HMe*r)+VMe)*r)+GMe)*r)*n)+n),s=z(z(1-z(.5*r))+z(z(r*r)*z(z(z(z(YMe*r)+KMe)*r)+WMe))),a=z(t*XMe),l=z(a-b0(a)),c=Math.abs(l),u=c>zN&&c<QN,d=l<-zN||l>QN,h=l>zN||l<-QN,p=u?s:o,m=u?o:s;return e.sin=d?-p:p,e.cos=h?-m:m,e}var a3e={sin:0,cos:0};function QQ(i){return yr(i,a3e).sin}function eh(i,e){let t=Math.abs(e),n=Math.abs(i),r=t>n?t:n,o=t<n?t:n,s=r>0?z(o/r):0,a=z(s*s),l=z(z(z(z(z(z(z(z(z(z(z(JMe*a)+jMe)*a)+$Me)*a)+QMe)*a)+zMe)*a)+qMe)*s);return n>t&&(l=z(LMe-l)),e<0&&(l=z(Zd-l)),i<0?-l:l}var zQ=new DataView(new ArrayBuffer(4));function l3e(i){let e=Hf(z(i),-XQ,XQ),t=b0(z(e*ZMe)),n=z(z(e-z(t*e3e))-z(t*t3e)),r=z(z(z(z(z(z(z(z(z(z(z(z(s3e*n)+o3e)*n)+i3e)*n)+r3e)*n)+n3e)*n)*n)+n)+1);return zQ.setUint32(0,t+127<<23>>>0),z(r*zQ.getFloat32(0))}function $Q(i){if(i>qQ)return 1;if(i<-qQ)return -1;let e=l3e(z(i+i));return z(z(e-1)/z(e+1))}var g0=class{constructor(){this.rx=1;this.ry=0;this.rz=0;this.ux=0;this.uy=1;this.uz=0;this.bx=0;this.by=0;this.bz=1;}fromQuaternion(e,t,n,r){let o=e+e,s=t+t,a=n+n,l=e*o,c=e*s,u=e*a,d=t*s,h=t*a,p=n*a,m=r*o,f=r*s,y=r*a;return this.rx=1-(d+p),this.ry=c+y,this.rz=u-f,this.ux=c-y,this.uy=1-(l+p),this.uz=h+m,this.bx=u+f,this.by=h-m,this.bz=1-(l+d),this}toWorld(e,t,n,r,o=0){return r[o]=this.rx*e+this.ux*t+this.bx*n,r[o+1]=this.ry*e+this.uy*t+this.by*n,r[o+2]=this.rz*e+this.uz*t+this.bz*n,r}toLocal(e,t,n,r,o=0){return r[o]=this.rx*e+this.ry*t+this.rz*n,r[o+1]=this.ux*e+this.uy*t+this.uz*n,r[o+2]=this.bx*e+this.by*t+this.bz*n,r}};var D=Math.fround,Rn=16,$N=1025,c3e=1e3,ZN=D(1.225),jN=D(9.81),jQ=2,u3e=8,Vo=7,d3e=D(.05),h3e=D(1e-6),p3e=D(.877),m3e=D(.21),f3e=8,JQ=D(.7),ZQ=D(.35),_3e=D(1.6),y3e=6,A3e=8,b3e=40n,g3e=16777216,E0=(1n<<64n)-1n,E3e=0x9e3779b97f4a7c15n,x3e=0xbf58476d1ce4e5b9n,v3e=0x94d049bb133111ebn,e$=["mirror","lake","calm","moderate","rough","storm"],R3e={mirror:0,lake:4,calm:5,moderate:9,rough:14,storm:22},S3e={mirror:0,lake:D(.25),calm:D(.3),moderate:D(.45),rough:D(.6),storm:D(.75)},Rc=class{constructor(){this.height=0;this.normalX=0;this.normalY=1;this.normalZ=0;this.velocityX=0;this.velocityY=0;this.velocityZ=0;}},JN=class{constructor(e){this.state=BigInt(e)&E0;}next(){this.state=this.state+E3e&E0;let e=this.state;return e=(e^e>>30n)*x3e&E0,e=(e^e>>27n)*v3e&E0,e^e>>31n}unit(){return D(Number(this.next()>>b3e)/g3e)}range(e,t){return D(e+D(D(t-e)*this.unit()))}};function v0(i,e,t){let n=R3e[i],r=D(e),o={sin:0,cos:0};yr(r,o);let s=[D(o.cos*n),D(o.sin*n)];if(i==="mirror")return {wind:s};let a=jN,l=D(D(p3e*a)/n),c=D(D(Go*a)/D(l*l)),u=Number.POSITIVE_INFINITY,d=$N;i==="lake"&&(u=A3e,d=c3e,c=Hf(c,0,y3e));let h=D(D(D(m3e*n)*n)/a),p=new JN(t),m=Math.min(f3e,Rn),f=D(1/D(Math.sqrt(m))),y=[];for(let b=0;b<m;b++){let A=D(D(b+p.unit())/m),E=D(c*D(ZQ+D(D(_3e-ZQ)*A))),R=D(r+p.range(-JQ,JQ));yr(R,o);let g=D(D(D(D(.5*h)*f))*D(E/c));y.push({direction:[o.cos,o.sin],wavelength:E,amplitude:g,steepness:D(D(D(S3e[i]/m))*2),phase:p.range(0,Go)});}return {wind:s,depth:u,density:d,waves:y}}var x0=class{constructor(e={}){this.kx=new Float32Array(Rn);this.kz=new Float32Array(Rn);this.phase=new Float32Array(Rn);this.amplitude=new Float32Array(Rn);this.qax=new Float32Array(Rn);this.qaz=new Float32Array(Rn);this.kax=new Float32Array(Rn);this.kaz=new Float32Array(Rn);this.kqa=new Float32Array(Rn);this.wqax=new Float32Array(Rn);this.wqaz=new Float32Array(Rn);this.wa=new Float32Array(Rn);this.omega=new Float32Array(Rn);this.sc={sin:0,cos:0};this.seconds=new Float64Array(1);this.count=0;this.iterations=jQ;this.currentX=0;this.currentZ=0;this.windX=0;this.windZ=0;this.gust=0;this.gustOmega=0;this.gustPhase=0;this.time=0;this.level=0;this.density=$N;this.gravity=jN;this.batchSample=new Rc;this.px=0;this.pz=0;this.configure(e);}configure(e){let t=e.waves??[],n=D(e.gravity??jN),r=D(e.density??$N),o=e.depth??Number.POSITIVE_INFINITY,s=e.iterations??jQ;if(t.length>Rn||s>u3e||!(n>0)||!(r>0)||Number.isNaN(o)||o<=0)throw new _("invalid_argument","water description is out of range");let a=0;for(let c of t){let u=D(Math.sqrt(D(D(D(c.direction[0])*D(c.direction[0]))+D(D(c.direction[1])*D(c.direction[1])))));if(!(D(c.wavelength)>=d3e)||!(c.amplitude>=0)||!(u>h3e))throw new _("invalid_argument","wave description is out of range");a=D(a+Hf(D(c.steepness),0,1));}let l=a>1?D(1/a):1;for(let c=0;c<Rn;c++){let u=t[c];if(!u){this.kx[c]=this.kz[c]=this.phase[c]=this.amplitude[c]=0,this.qax[c]=this.qaz[c]=this.kax[c]=this.kaz[c]=this.kqa[c]=0,this.wqax[c]=this.wqaz[c]=this.wa[c]=this.omega[c]=0;continue}let d=D(u.direction[0]),h=D(u.direction[1]),p=D(Math.sqrt(D(D(d*d)+D(h*h)))),m=D(d/p),f=D(h/p),y=D(Go/D(u.wavelength)),b=D(n*y),A=Number.isFinite(o)?D(Math.sqrt(D(b*$Q(D(y*D(o)))))):D(Math.sqrt(b)),E=D(u.amplitude),R=D(y*E),g=R>0?D(D(Hf(D(u.steepness),0,1)*l)/R):0,v=D(g*E);this.kx[c]=D(y*m),this.kz[c]=D(y*f),this.phase[c]=tl(D(u.phase)),this.amplitude[c]=E,this.qax[c]=D(m*v),this.qaz[c]=D(f*v),this.kax[c]=D(m*R),this.kaz[c]=D(f*R),this.kqa[c]=D(y*v),this.wqax[c]=D(A*D(m*v)),this.wqaz[c]=D(A*D(f*v)),this.wa[c]=D(A*E),this.omega[c]=A;}this.count=t.length,this.iterations=s,this.level=D(e.level??0),this.density=r,this.gravity=n,this.currentX=D(e.current?.[0]??0),this.currentZ=D(e.current?.[1]??0),this.setWind(e.wind?.[0]??0,e.wind?.[1]??0,e.gust??0,e.gustPeriod??0),this.gustPhase=0,this.time=0;}setWind(e,t,n=0,r=0){this.windX=D(e),this.windZ=D(t),this.gust=D(n),this.gustOmega=r>0?D(Go/D(r)):0;}setCurrent(e,t){this.currentX=D(e),this.currentZ=D(t);}crest(){let e=0;for(let t=0;t<this.count;t++)e+=this.amplitude[t];return this.level+e}get elapsed(){return this.time}advance(e){this.seconds[0]=e,this.advanceFrom(this.seconds,0);}advanceFrom(e,t){let n=D(e[t]);for(let r=0;r<this.count;r++)this.phase[r]=tl(D(this.phase[r]-D(this.omega[r]*n)));this.gustPhase=tl(D(this.gustPhase+D(this.gustOmega*n))),this.time+=n;}windInto(e,t=0){let n=D(1+D(this.gust*QQ(this.gustPhase)));return e[t]=D(this.windX*n),e[t+1]=0,e[t+2]=D(this.windZ*n),e}height(e,t){this.undisplace(D(e),D(t));let n=0;for(let r=0;r<this.count;r++)yr(this.theta(r),this.sc),n=D(n+D(this.amplitude[r]*this.sc.sin));return D(this.level+n)}sample(e,t,n){this.undisplace(D(e),D(t));let r=0,o=0,s=0,a=0,l=0,c=0,u=0;for(let f=0;f<this.count;f++){yr(this.theta(f),this.sc);let y=this.sc.sin,b=this.sc.cos;r=D(r+D(this.amplitude[f]*y)),o=D(o+D(this.kax[f]*b)),s=D(s+D(this.kqa[f]*y)),a=D(a+D(this.kaz[f]*b)),l=D(l+D(this.wqax[f]*y)),c=D(c+D(this.wa[f]*b)),u=D(u+D(this.wqaz[f]*y));}let d=-o,h=D(1-s),p=-a,m=D(1/D(Math.sqrt(D(D(D(d*d)+D(h*h))+D(p*p)))));return n.height=D(this.level+r),n.normalX=D(d*m),n.normalY=D(h*m),n.normalZ=D(p*m),n.velocityX=D(l+this.currentX),n.velocityY=-c,n.velocityZ=D(u+this.currentZ),n}sampleBatch(e,t,n){let r=this.batchSample;for(let o=0;o<t;o++){this.sample(e[o*2],e[o*2+1],r);let s=o*Vo;n[s]=r.height,n[s+1]=r.normalX,n[s+2]=r.normalY,n[s+3]=r.normalZ,n[s+4]=r.velocityX,n[s+5]=r.velocityY,n[s+6]=r.velocityZ;}}theta(e){return D(D(D(this.kx[e]*this.px)+D(this.kz[e]*this.pz))+this.phase[e])}undisplace(e,t){this.px=e,this.pz=t;for(let n=0;n<this.iterations;n++){let r=0,o=0;for(let s=0;s<this.count;s++)yr(this.theta(s),this.sc),r=D(r+D(this.qax[s]*this.sc.cos)),o=D(o+D(this.qaz[s]*this.sc.cos));this.px=D(e-r),this.pz=D(t-o);}}};var t$=64,i$=0,o$=1,s$=2,a$=3,l$=4,T0=5,c$=8,u$=9,d$=10,h$=16,p$=17,m$=18,f$=19,_$=22,y$=25,A$=28,T3e=32,w3e=33,I3e=34;var O3e=36;var C3e=40,N3e=41,b$=0,g$=1,E$=2,th=8,x$=0,v$=1,Tc=32,k3e=4,L3e=32,M3e=65536,D3e=["engine_cloth_create","engine_cloth_create_in","engine_cloth_destroy","engine_cloth_registers","engine_cloth_add_grid","engine_cloth_add_mesh","engine_cloth_remove","engine_cloth_params","engine_cloth_colliders","engine_cloth_anchors","engine_cloth_step","engine_cloth_positions","engine_cloth_digest","engine_cloth_present"];function Sc(i,e){let t=i.symbols[e];if(typeof t!="function")throw new _("unsupported_feature",`${e} needs an engine with feature rigid_coupling_1`);return t}var cn=0,R0=4,P3e=1e6,F3e=32n,n$=3,U3e=3,r$=th*Tc;function R$(i){let e=i.symbols;return D3e.every(t=>typeof e[t]=="function")?e:null}var S0=class{constructor(e,t,n,r=()=>cn,o=L3e,s=M3e){this.runtime=e;this.exports=t;this.render=n;this.world=r;this.maxCloths=o;this.maxParticles=s;this.handle=cn;this.scratch=cn;this.buffer=null;this.bytes=new Uint8Array(0);this.words=new Uint32Array(0);this.views=new Float32Array(0);this.registers=new Uint32Array(0);this.floats=new Float32Array(0);this.rows=new Map;this.coupled=0;}memory(){let e=this.runtime.memory.buffer;e!==this.buffer&&(this.buffer=e,this.bytes=new Uint8Array(e),this.words=new Uint32Array(e),this.views=new Float32Array(e));}get engineHost(){return this.open()}open(){if(this.handle===cn){let e=this.world();if(this.handle=e===cn?this.exports.engine_cloth_create(this.maxCloths,this.maxParticles):this.exports.engine_cloth_create_in(e,this.maxCloths,this.maxParticles),this.handle===cn)throw new _("invalid_argument","the engine refused the cloth world");if(this.scratch=this.runtime.exports.engine_alloc(r$*R0,ce),this.scratch===cn)throw new _("capacity_exceeded","engine memory cannot hold cloth colliders")}return this.view(),this.handle}view(){this.memory();let e=this.exports.engine_cloth_registers(this.handle);(this.registers.buffer!==this.words.buffer||this.registers.byteOffset!==e)&&(this.registers=new Uint32Array(this.words.buffer,e,t$),this.floats=new Float32Array(this.words.buffer,e,t$));}check(e,t){if(e===-1)throw new _("capacity_exceeded",`the cloth world has no room for the ${t}`);if(e===-3)throw new _("unknown_resource",`the cloth ${t} names a missing cloth`);if(!(e>=0))throw new _("invalid_argument",`the engine refused the cloth ${t} (${e})`);return e}stage(e,t){let n=this.runtime.exports.engine_alloc(Math.max(e,R0),ce);if(n===cn)throw new _("capacity_exceeded",`engine memory cannot hold the cloth ${t}`);return this.memory(),n}release(e,t){e!==cn&&this.runtime.exports.engine_free(e,Math.max(t,R0),ce);}staged(e,t){if(e===null||e.length===0)return cn;let n=this.stage(e.byteLength,t);return this.bytes.set(new Uint8Array(e.buffer,e.byteOffset,e.byteLength),n),n}info(e){this.view();let t=this.registers;return {id:e,particles:t[T3e],triangles:t[w3e],pins:t[O3e],colours:t[I3e]}}prepare(){return this.open(),this.floats}grid(e){let t=this.open(),n=this.staged(e,"pins"),r=this.exports.engine_cloth_add_grid(t,n,e?.length??0);return this.release(n,e?.byteLength??0),this.info(this.check(r,"grid"))}mesh(e,t,n){let r=this.open(),o=this.staged(e,"vertices"),s=this.staged(t,"triangles"),a=this.staged(n,"pins"),l=this.exports.engine_cloth_add_mesh(r,o,e.length/n$,s,t.length/U3e,a,n?.length??0);return this.release(o,e.byteLength),this.release(s,t.byteLength),this.release(a,n?.byteLength??0),this.info(this.check(l,"mesh"))}remove(e){this.rows.delete(e),this.handle!==cn&&this.exports.engine_cloth_remove(this.handle,e);}params(e){this.check(this.exports.engine_cloth_params(this.open(),e),"parameters");}colliders(e,t){let n=this.open();if(t>Tc)throw new _("capacity_exceeded",`cloth collides with at most ${Tc} shapes`);this.memory(),this.views.set(e.subarray(0,t*th),this.scratch>>>2),this.check(this.exports.engine_cloth_colliders(n,this.scratch,t),"colliders");}anchors(e,t){let n=this.open(),r=this.staged(t,"anchors"),o=this.exports.engine_cloth_anchors(n,e,r,t.length/n$);this.release(r,t.byteLength),this.check(o,"anchors");}step(e){if(this.handle===cn)return;let t=Math.max(0,Math.round(e*P3e)),n=this.world();if(this.coupled>0&&n!==cn){this.check(Sc(this.runtime,"engine_cloth_step_coupled")(this.handle,n,t),"coupled step");return}this.exports.engine_cloth_step(this.handle,t);}couple(e){let t=this.open(),n=this.world();if(n===cn)throw new _("not_initialized","cloth couples to rigid bodies only inside a physics world");let r=this.check(Sc(this.runtime,"engine_cloth_couple")(t,n,e),"coupling");return this.coupled++,r}uncouple(e){this.check(Sc(this.runtime,"engine_cloth_uncouple")(this.open(),e),"uncoupling"),this.coupled=Math.max(0,this.coupled-1);}positions(e,t){let n=this.exports.engine_cloth_positions(this.open(),e);if(n===cn)throw new _("unknown_resource",`cloth ${e} is gone`);this.memory();let r=this.rows.get(e);if(r!==void 0&&r.buffer===this.views.buffer&&r.byteOffset===n)return r;let o=new Float32Array(this.views.buffer,n,t*k3e);return this.rows.set(e,o),o}digest(){let e=this.open();return this.exports.engine_cloth_digest(e),this.view(),BigInt(this.registers[N3e])<<F3e|BigInt(this.registers[C3e])}present(e,t){let n=this.render();return this.handle===cn||n===cn?0:this.check(this.exports.engine_cloth_present(this.handle,e,n,t),"presentation")}dispose(){this.handle!==cn&&(this.release(this.scratch,r$*R0),this.exports.engine_cloth_destroy(this.handle),this.handle=cn,this.scratch=cn,this.rows.clear());}};var O$="soft_body_1",S$=64,C$=0,N$=1,k$=2,L$=3,O0=4,M$=7,D$=8,P$=9,F$=10,U$=11,B$=12,G$=13,B3e=16,T$=19,w$=22,G3e=25,V3e=26,H3e=27,C0=28,W3e=32,K3e=33;var Y3e=40,X3e=41,q3e=42,z3e=43,nh=12,wc=32,Q3e=4,V$=0,H$=1,W$=2,K$=3,Y$=14,X$=6,$3e=64,j3e=65536,J3e=["engine_soft_create","engine_soft_destroy","engine_soft_registers","engine_soft_add","engine_soft_add_lattice","engine_soft_add_rope","engine_soft_remove","engine_soft_params","engine_soft_colliders","engine_soft_anchors","engine_soft_activate","engine_soft_move","engine_soft_step","engine_soft_positions","engine_soft_digest","engine_soft_present","engine_soft_create_in"];var Sn=0,w0=4,Z3e=1e6,I$=nh*wc;function q$(i){let e=i.symbols;return J3e.every(t=>typeof e[t]=="function")?e:null}var ek=class{constructor(e){this.runtime=e;this.buffer=null;this.bytes=new Uint8Array(0);this.floats=new Float32Array(0);this.words=new Uint32Array(0);}views(){let e=this.runtime.memory.buffer;e!==this.buffer&&(this.buffer=e,this.bytes=new Uint8Array(e),this.floats=new Float32Array(e),this.words=new Uint32Array(e));}allocate(e,t){let n=this.runtime.exports.engine_alloc(Math.max(e,w0),ce);if(n===Sn)throw new _("capacity_exceeded",`engine memory cannot hold the ${t}`);return this.views(),n}release(e,t){this.runtime.exports.engine_free(e,Math.max(t,w0),ce);}floatsAt(e,t){let n=this.allocate(e.byteLength,t);return this.floats.set(e,n>>>2),n}},I0=class{constructor(e,t,n,r=()=>Sn,o=$3e,s=j3e){this.runtime=e;this.exports=t;this.render=n;this.world=r;this.maxBodies=o;this.maxParticles=s;this.handle=Sn;this.scratch=Sn;this.registers=new Uint32Array(0);this.floats=new Float32Array(0);this.coupled=0;this.memory=new ek(e);}open(){if(this.handle===Sn){let e=this.world();if(this.handle=e===Sn?this.exports.engine_soft_create(this.maxBodies,this.maxParticles):this.exports.engine_soft_create_in(e,this.maxBodies,this.maxParticles),this.handle===Sn)throw new _("invalid_argument","the engine refused the soft body world");this.scratch=this.memory.allocate(I$*w0,"soft body colliders");}return this.view(),this.handle}view(){this.memory.views();let e=this.exports.engine_soft_registers(this.handle);(this.registers.buffer!==this.memory.words.buffer||this.registers.byteOffset!==e)&&(this.registers=new Uint32Array(this.memory.words.buffer,e,S$),this.floats=new Float32Array(this.memory.words.buffer,e,S$));}check(e,t){if(!(e>=0))throw new _("invalid_argument",`the engine refused the soft body ${t} (${e})`);return e}info(e){this.view();let t=this.registers;return {id:e,particles:t[W3e],skinned:t[K3e],tets:t[q3e],colours:t[z3e]}}prepare(){return this.open(),this.floats}lattice(e,t){let n=this.open(),r=this.registers,o=this.floats;for(let c=0;c<3;c++)r[B3e+c]=e.cells[c],o[T$+c]=e.size[c],o[w$+c]=e.origin[c];o[G3e]=e.density;let s=t===null?0:t.length/3,a=t===null?Sn:this.memory.floatsAt(t,"soft body surface"),l=this.exports.engine_soft_add_lattice(n,a,s);return a!==Sn&&t!==null&&this.memory.release(a,t.byteLength),this.info(this.check(l,"lattice"))}rope(e,t,n){let r=this.open();this.floats[V3e]=t,this.registers[H3e]=n?1:0;let o=this.memory.floatsAt(e,"rope points"),s=this.exports.engine_soft_add_rope(r,o,e.length/3);return this.memory.release(o,e.byteLength),this.info(this.check(s,"rope"))}asset(e){let t=this.open(),n=this.memory.allocate(e.byteLength,"soft body asset");this.memory.bytes.set(e,n);let r=this.exports.engine_soft_add(t,n,e.byteLength);return this.memory.release(n,e.byteLength),this.info(this.check(r,"asset (CSBT)"))}remove(e){this.handle!==Sn&&this.exports.engine_soft_remove(this.handle,e);}params(e){this.check(this.exports.engine_soft_params(this.open(),e),"parameters");}colliders(e,t){let n=this.open();if(t>wc)throw new _("capacity_exceeded",`soft bodies collide with at most ${wc} shapes`);this.memory.views(),this.memory.floats.set(e.subarray(0,t*nh),this.scratch>>>2),this.check(this.exports.engine_soft_colliders(n,this.scratch,t),"colliders");}anchors(e,t){let n=this.open(),r=this.memory.floatsAt(t,"anchors"),o=this.exports.engine_soft_anchors(n,e,r,t.length/3);this.memory.release(r,t.byteLength),this.check(o,"anchors");}activate(e,t){this.check(this.exports.engine_soft_activate(this.open(),e,t),"activation");}move(e,t,n){let r=this.open();for(let o=0;o<3;o++)this.floats[w$+o]=t[o],this.floats[T$+o]=n[o];this.check(this.exports.engine_soft_move(r,e),"move");}step(e){if(this.handle===Sn)return;let t=Math.max(0,Math.round(e*Z3e)),n=this.world();if(this.coupled>0&&n!==Sn){this.check(Sc(this.runtime,"engine_soft_step_coupled")(this.handle,n,t),"coupled step");return}this.exports.engine_soft_step(this.handle,t);}couple(e){let t=this.open(),n=this.world();if(n===Sn)throw new _("not_initialized","soft bodies couple to rigid bodies only inside a physics world");let r=this.check(Sc(this.runtime,"engine_soft_couple")(t,n,e),"coupling");return this.coupled++,r}uncouple(e){this.check(Sc(this.runtime,"engine_soft_uncouple")(this.open(),e),"uncoupling"),this.coupled=Math.max(0,this.coupled-1);}positions(e,t){let n=this.exports.engine_soft_positions(this.open(),e);if(n===Sn)throw new _("unknown_resource",`soft body ${e} is gone`);return this.memory.views(),new Float32Array(this.memory.floats.buffer,n,t*Q3e)}digest(){let e=this.open();return this.exports.engine_soft_digest(e),this.view(),BigInt(this.registers[X3e])<<32n|BigInt(this.registers[Y3e])}present(e,t){let n=this.render();return this.handle===Sn||n===Sn?0:this.check(this.exports.engine_soft_present(this.handle,e,n,t),"presentation")}dispose(){this.handle!==Sn&&(this.memory.release(this.scratch,I$*w0),this.exports.engine_soft_destroy(this.handle),this.handle=Sn);}};var eDe="engine-craft",tDe=["engine_craft_create","engine_craft_destroy","engine_craft_registers","engine_craft_controls","engine_craft_telemetry","engine_craft_set_water","engine_craft_set_flow","engine_craft_sea","engine_craft_custom","engine_craft_spin_up","engine_craft_remove","engine_craft_step","engine_water_sample","engine_alloc","engine_free"],nDe=1e3,rDe=113,iDe=114,z$=115,oDe=117,sDe=118,aDe=119,lDe=120,cDe=121,uDe=122,dDe=123,hDe=124,pDe=64,mDe=64,fDe=2e-4,_De=1.2,yDe=.05,N0=0,ADe=128,bDe=.25,gDe=1.5,EDe=0,xDe=0,vDe=.5,Q$=128,$$=0,RDe=1,SDe=2,TDe=3,k0=4,rh=6,j$=8,J$=9,wDe=10,IDe=11,ODe=12,CDe=6,NDe=9.81,kDe=1025,LDe=2,Gr=0,Bt=4,nl=1024,ej=21,MDe=19,DDe=20,Z$=2**32,PDe=64,FDe={size:256,count:4,patches:[256,64,16,4],windSpeed:10,windDirection:0,fetch:1e5,peakEnhancement:3.3,swell:0,depth:Number.POSITIVE_INFINITY,shortWaves:.01,scale:1,choppiness:1,gravity:9.81,seed:1},UDe={threshold:.7,gain:4,decaySeconds:2.5};function BDe(i){let e=new Float32Array(ej),t=new Uint32Array(e.buffer);if(i===null)return e;let n={...FDe,...i},r={...UDe,...i.foam};e.set([n.size,n.count,...n.patches,n.windSpeed,n.windDirection,n.fetch,n.peakEnhancement,n.swell,n.depth,n.shortWaves,n.scale,n.choppiness,r.threshold,r.gain,r.decaySeconds,n.gravity]);let o=Math.max(0,Math.floor(n.seed));return t[MDe]=o%Z$,t[DDe]=Math.floor(o/Z$),e}function tj(i){return tDe.every(e=>typeof i[e]=="function")}function nj(i){return tj(i.symbols)?new tk(i,i.symbols):null}var tk=class{constructor(e,t,n=64){this.name=eDe;this.handle=Gr;this.words=new Uint32Array(0);this.floats=new Float32Array(0);this.controlTable=new Float32Array(0);this.telemetryTable=new Float32Array(0);this.points=0;this.samples=0;this.render=()=>N0;this.pointView=new Float32Array(0);this.sampleView=new Float32Array(0);if(!tj(t))throw new _("unsupported_feature","this engine build has no craft simulation");this.session=e,this.exports=t,this.capacity=n;}configureWater(e){this.open();let t=this.words,n=this.floats,r=e.waves??[];if(r.length>Rn)throw new _("invalid_argument","too many waves");n[$$]=e.level??0,n[RDe]=e.depth??Number.POSITIVE_INFINITY,n[SDe]=e.gravity??NDe,n[TDe]=e.density??kDe,n[k0]=e.current?.[0]??0,n[k0+1]=e.current?.[1]??0,n[rh]=e.wind?.[0]??0,n[rh+1]=e.wind?.[1]??0,n[j$]=e.gust??0,n[J$]=e.gustPeriod??0,t[wDe]=e.iterations??LDe,t[IDe]=r.length,r.forEach((o,s)=>{let a=ODe+s*CDe;n[a]=o.direction[0],n[a+1]=o.direction[1],n[a+2]=o.wavelength,n[a+3]=o.amplitude,n[a+4]=o.steepness,n[a+5]=o.phase;}),this.session.check(this.exports.engine_craft_set_water(this.handle),"configure water");}sea(e,t,n){this.open(),this.session.check(this.exports.engine_craft_sea(this.handle,e$.indexOf(e),t,n>>>0),"sea state");}setFlow(e){this.open();let t=this.floats;t[$$]=e.level,t[k0]=e.current[0],t[k0+1]=e.current[1],t[rh]=e.wind[0],t[rh+1]=e.wind[1],t[j$]=e.gust,t[J$]=e.gustPeriod,this.session.check(this.exports.engine_craft_set_flow(this.handle),"water flow");}createCraft(e,t,n,r,o){this.open();let s=r.length*Bt,a=this.exports.engine_alloc(s,Bt);if(a===0)throw new _("capacity_exceeded","craft description could not be staged");try{new Float32Array(this.session.buffer,a,r.length).set(r);let l=this.session.check(this.exports.engine_craft_custom(this.handle,t,n>>>0,a,r.length),"create craft");return o&&this.session.check(this.exports.engine_craft_spin_up(this.handle,l),"spin up craft"),l}finally{this.exports.engine_free(a,s,Bt);}}removeCraft(e){this.open(),this.session.check(this.exports.engine_craft_remove(this.handle,e),"remove craft");}controls(){return this.open(),this.controlTable}telemetry(){return this.open(),this.telemetryTable}setOcean(e){let t=this.exports.engine_craft_ocean;if(!t)throw new _("unsupported_feature","this engine build has no ocean simulation");this.open();let n=this.words,r=this.floats;n[rDe]=e?e.size??pDe:0,r[iDe]=e?.patch??mDe,r[z$]=e?.wind?.[0]??r[rh],r[z$+1]=e?.wind?.[1]??r[rh+1],r[oDe]=e?.amplitude??fDe,r[sDe]=e?.choppiness??_De,r[aDe]=e?.smallWave??yDe,n[lDe]=(e?.seed??1)>>>0,n[cDe]=Math.max(1,e?.updateEvery??1),this.session.check(t(this.handle),"configure ocean");}setRipples(e){let t=this.exports.engine_craft_ripples;if(!t)throw new _("unsupported_feature","this engine build has no ripples");this.open();let n=e?e.size??ADe:EDe,r=e?.cell??bDe,o=e?.speed??gDe;this.session.check(t(this.handle,n,r,o),"configure ripples");}setCascades(e){let t=this.exports.engine_craft_cascades;if(!t)throw new _("unsupported_feature","this engine build has no FFT ocean");let n=this.render();if(n===N0)throw new _("invalid_argument","the FFT ocean needs a render world to draw it");this.open();let r=BDe(e),o=this.exports.engine_alloc(r.byteLength,Bt);if(o===0)throw new _("capacity_exceeded","engine memory cannot hold the ocean desc");try{new Float32Array(this.session.buffer,o,ej).set(r);let s=e?.physicsSize??PDe;this.session.check(t(this.handle,n,o,s),"FFT ocean");}finally{this.exports.engine_free(o,r.byteLength,Bt);}}setPuddles(e){let t=this.exports.engine_craft_puddles;if(!t)throw new _("unsupported_feature","this engine build has no puddles");this.open();let n=e?e.width:xDe;this.session.check(t(this.handle,e?.origin[0]??0,e?.origin[1]??0,e?.cell??0,n,e?.height??0,e?.maxDepth??vDe),"configure puddles");}setPuddleBed(e){let t=this.exports.engine_craft_puddles_bed;if(!t||this.handle===Gr)return;let n=Math.max(e.byteLength,Bt),r=this.exports.engine_alloc(n,Bt);if(r===0)throw new _("capacity_exceeded","engine memory cannot hold the puddle bed");try{new Float32Array(this.session.buffer,r,e.length).set(e),this.session.check(t(this.handle,r,e.length),"puddle bed");}finally{this.exports.engine_free(r,n,Bt);}}pourPuddles(e,t,n){let r=this.exports.engine_craft_puddles_pour;r&&this.handle!==Gr&&(this.point(e,t,n),this.session.check(r(this.handle),"pour"));}point(e,t,n){let r=this.floats;r[uDe]=e,r[dDe]=t,r[hDe]=n;}puddleWeather(e,t){let n=this.exports.engine_craft_puddles_weather;n&&this.handle!==Gr&&this.session.check(n(this.handle,e,t),"puddle weather");}followRipples(e,t){let n=this.exports.engine_craft_ripples_follow;n&&this.handle!==Gr&&(this.point(e,t,0),this.session.check(n(this.handle),"follow ripples"));}pushRipples(e,t,n){let r=this.exports.engine_craft_ripples_push;r&&this.handle!==Gr&&(this.point(e,t,n),this.session.check(r(this.handle),"push ripples"));}bindRender(e){this.render=e;}step(){if(this.handle===Gr||this.session.world===0)return;this.session.check(this.exports.engine_craft_step(this.handle,this.session.world),"craft step");let e=this.exports.engine_craft_render_water,t=this.render();e&&t!==N0&&this.session.check(e(this.handle,t),"render water");}sampleWater(e,t,n){this.open();let r=this.session.buffer;this.pointView.buffer!==r&&(this.pointView=new Float32Array(r,this.points,nl*2),this.sampleView=new Float32Array(r,this.samples,nl*Vo));for(let o=0;o<t;o+=nl){let s=Math.min(nl,t-o);for(let l=0;l<s*2;l++)this.pointView[l]=e[o*2+l];this.session.check(this.exports.engine_water_sample(this.handle,this.points,s,this.samples),"water sample");let a=o*Vo;for(let l=0;l<s*Vo;l++)n[a+l]=this.sampleView[l];}}floatsIn(e){let t=this.exports.engine_alloc(Math.max(e.byteLength,Bt),Bt);if(t===0)throw new _("capacity_exceeded","engine memory cannot hold the crumple data");return new Float32Array(this.session.buffer,t,e.length).set(e),t}crumpleExport(e){let t=this.exports[e];if(!t)throw new _("unsupported_feature",`this engine build has no vehicle crumple (feature ${O$})`);return t}crumple(e,t,n){let r=this.crumpleExport("engine_craft_crumple");this.open();let o=this.floatsIn(t),s=n===null?0:this.floatsIn(n);try{this.session.check(r(this.handle,e,s,o,t.length/3),"crumple cage");}finally{this.exports.engine_free(o,Math.max(t.byteLength,Bt),Bt),n!==null&&this.exports.engine_free(s,Math.max(n.byteLength,Bt),Bt);}}impact(e,t,n){let r=this.crumpleExport("engine_craft_impact");this.open();let o=this.floatsIn(new Float32Array([...t,...n]));try{return this.session.check(r(this.handle,e,o),"impact")===1}finally{this.exports.engine_free(o,X$*Bt,Bt);}}damage(e){if(this.handle===Gr)return 0;let t=this.crumpleExport("engine_craft_damage")(this.handle,e);return t>=0?t/nDe:0}presentCrumple(e,t){let n=this.render();if(this.handle===Gr||n===N0)return 0;let r=this.crumpleExport("engine_craft_crumple_present")(this.handle,e,n,t);return r>=0?r:0}dispose(){this.handle!==Gr&&(this.exports.engine_craft_destroy(this.handle),this.exports.engine_free(this.points,nl*2*Bt,Bt),this.exports.engine_free(this.samples,nl*Vo*Bt,Bt),this.handle=Gr);}open(){if(this.handle!==Gr)return;let e=this.exports.engine_craft_create(this.capacity);if(e===Gr)throw new _("capacity_exceeded","craft world could not be created");this.handle=e;let t=this.session.buffer,n=this.exports.engine_craft_registers(e);if(this.words=new Uint32Array(t,n,Q$),this.floats=new Float32Array(t,n,Q$),this.controlTable=new Float32Array(t,this.exports.engine_craft_controls(e),this.capacity*16),this.telemetryTable=new Float32Array(t,this.exports.engine_craft_telemetry(e),this.capacity*16),this.points=this.exports.engine_alloc(nl*2*Bt,Bt),this.samples=this.exports.engine_alloc(nl*Vo*Bt,Bt),this.points===0||this.samples===0)throw new _("capacity_exceeded","water sample buffers could not be allocated")}};function ih(i,e,t){let n=i.x.length;if(n<1||n>e||i.y.length!==n)throw new _("invalid_argument",`${t} needs 1 to ${e} matching x and y points`);for(let r=0;r<n;r++){if(!Number.isFinite(i.x[r])||!Number.isFinite(i.y[r]))throw new _("invalid_argument",`${t} has a non-finite point`);if(r>0&&!(i.x[r]>i.x[r-1]))throw new _("invalid_argument",`${t} x values must increase`)}}function rk(i,e){let t=i.x.length;if(e<=i.x[0])return i.y[0];for(let n=1;n<t;n++)if(e<i.x[n]){let r=(e-i.x[n-1])/(i.x[n]-i.x[n-1]);return i.y[n-1]+(i.y[n]-i.y[n-1])*r}return i.y[t-1]}function ik(i,e,t,n){return {x:[0,i,t],y:[0,e,n]}}var L0=16,dk=8,hk=8,pk=8,GDe=100;var VDe=-1,HDe=0;var ok=0,sk=1,ak=2,lk=3,ck=4,mk=8,WDe=0,KDe=1,YDe=2,XDe=3,qDe=4,zDe=5,oj=8;var sj=16;var fk=oj+L0*sj,QDe=0,$De=1,jDe=2,JDe=3,ZDe=4,ePe=5,tPe=6,nPe=7,rPe=8,iPe=9,oPe=10,sPe=11,aj=12,lj=aj+hk,rl=lj+hk,aPe=rl+1,lPe=rl+2,cPe=rl+3,uPe=rl+4,dPe=rl+5,hPe=rl+6,cj=rl+7,Wo=cj+dk,pPe=Wo+1,mPe=Wo+2,fPe=Wo+3,_Pe=Wo+4,yPe=Wo+5,APe=Wo+6,bPe=Wo+7,gPe=Wo+8,EPe=Wo+9,uj=56,uk=0,xPe=3,vPe=4,RPe=5,SPe=6,TPe=7,wPe=8,IPe=9,OPe=10,CPe=11,NPe=12,kPe=13,LPe=14,MPe=15,DPe=16,PPe=17,FPe=0,dj=1,hj=dj+pk,pj=hj+pk,mj=18,fj=mj+pj,UPe=fj+pj,_j=56,il=uj+L0*_j,BPe=ik(.12,1.1,.8,.85),GPe=ik(.2,1.05,.9,.8),VPe=1.2,HPe=.35,WPe=.15,KPe=35e3,rj=3500,YPe=4e4,XPe=1500,qPe=60,zPe=.2,QPe=.9,$Pe=.18,jPe=3,JPe=.4,ZPe=.02,eFe=.5,tFe=8;function ij(i,e,t,n){ih(t,pk,n),i[e+FPe]=t.x.length;for(let r=0;r<t.x.length;r++)i[e+dj+r]=t.x[r],i[e+hj+r]=t.y[r];}function yj(i,e=new Float32Array(il)){let t=i.wheels.length;if(t<1||t>L0)throw new _("invalid_argument",`vehicles take 1 to ${L0} wheels`);ih(i.engine.torque,hk,"engine torque curve");let n=i.forceHeight??0;if(!(n>=0&&n<=1))throw new _("invalid_argument","forceHeight must be between 0 and 1");let r=i.ackermann??0;if(!(r>=0&&r<=1))throw new _("invalid_argument","ackermann must be between 0 and 1");let o=i.gearbox.ratios.length;if(o<1||o>dk)throw new _("invalid_argument",`gearboxes take 1 to ${dk} ratios`);e.fill(0),e[QDe]=t,e[$De]=i.maxSteerRadians,e[jDe]=i.steerRate??jPe,e[JDe]=i.antiRoll??0,e[ZDe]=i.downforce??0,e[ePe]=i.drag??JPe,e[tPe]=i.rollingResistance??ZPe,e[nPe]=i.handbrakeGrip??eFe,e[rPe]=i.engine.idleRpm,e[iPe]=i.engine.maxRpm,e[oPe]=i.engine.engineBraking??qPe,e[Wo]=i.engine.inertia??zPe;let s=i.engine.torque;e[sPe]=s.x.length;for(let a=0;a<s.x.length;a++)e[aj+a]=s.x[a],e[lj+a]=s.y[a];e[rl]=o,e[aPe]=i.gearbox.reverse,e[lPe]=i.gearbox.finalDrive,e[cPe]=i.gearbox.efficiency??QPe,e[uPe]=i.gearbox.shiftUpRpm,e[dPe]=i.gearbox.shiftDownRpm,e[hPe]=i.gearbox.shiftSeconds??$Pe;for(let a=0;a<o;a++)e[cj+a]=i.gearbox.ratios[a];e[pPe]=i.differentialLock??0,e[mPe]=i.centerLock??0,e[fPe]=i.skidTorque??0,e[gPe]=i.forceHeight??0,e[EPe]=i.ackermann??0,e[_Pe]=i.lean?.maxAngle??0,e[yPe]=i.lean?.stiffness??0,e[APe]=i.lean?.damping??0,e[bPe]=i.lean?.fullSpeed??tFe;for(let a=0;a<t;a++){let l=i.wheels[a],c=uj+a*_j;e[c+uk]=l.position[0],e[c+uk+1]=l.position[1],e[c+uk+2]=l.position[2],e[c+xPe]=l.radius,e[c+vPe]=l.inertia??VPe,e[c+RPe]=l.restLength??HPe,e[c+SPe]=l.travel??WPe,e[c+TPe]=l.stiffness??KPe,e[c+wPe]=l.compressionDamping??rj,e[c+IPe]=l.relaxationDamping??l.compressionDamping??rj,e[c+OPe]=l.maxSuspensionForce??YPe,e[c+CPe]=l.steer??0,e[c+NPe]=l.drive??0,e[c+kPe]=l.brakeTorque??XPe,e[c+LPe]=l.handbrakeTorque??0,e[c+MPe]=l.grip??1,e[c+DPe]=l.axle??VDe,e[c+PPe]=l.side??0,e[c+UPe]=l.width??HDe,ij(e,c+mj,l.longitudinal??BPe,"longitudinal tyre curve"),ij(e,c+fj,l.lateral??GPe,"lateral tyre curve");}return e}var M0=class{constructor(e,t,n,r){this.port=e,this.id=t,this.entity=n,this.wheelCount=r,this.inputs=e.vehicleInputs(),this.states=e.vehicleStates(),this.input=t*mk,this.state=t*fk;}refresh(){this.inputs=this.port.vehicleInputs(),this.states=this.port.vehicleStates();}drive(e,t,n,r=0,o=GDe){let s=this.inputs,a=this.input;s[a+ok]=e,s[a+sk]=t,s[a+ak]=n,s[a+lk]=r,s[a+ck]=o;}driveFrom(e,t){let n=this.inputs,r=this.input;n[r+ok]=e[t+ok],n[r+sk]=e[t+sk],n[r+ak]=e[t+ak],n[r+lk]=e[t+lk],n[r+ck]=e[t+ck];}get speed(){return this.states[this.state+WDe]}get rpm(){return this.states[this.state+KDe]}get gear(){return this.states[this.state+YDe]}get steer(){return this.states[this.state+XDe]}get groundedWheels(){return this.states[this.state+qDe]}get shifting(){return this.states[this.state+zDe]!==0}wheel(e,t){return this.states[this.state+oj+e*sj+t]}get stateView(){return this.states}get stateOffset(){return this.state}};var nFe=["engine_vehicle_reserve","engine_vehicle_create","engine_vehicle_destroy","engine_vehicle_capacity","engine_vehicle_inputs","engine_vehicle_states"],Wf=0,Aj=new Float32Array(0);function bj(i){for(let e of nFe)if(typeof i[e]!="function")return null;return i}var D0=class{constructor(e,t){this.desc=Wf;this.inputs=Aj;this.states=Aj;this.session=e,this.exports=t;}createVehicle(e,t){let n=this.session;n.flush();let r=n.require();if(this.desc===Wf&&(this.desc=n.exports.engine_alloc(il*Rt,Rt),this.desc===Wf))throw new _("capacity_exceeded","engine memory cannot hold a vehicle descriptor");new Float32Array(n.buffer,this.desc,il).set(t.subarray(0,il));let o=n.check(this.exports.engine_vehicle_create(r,e,this.desc,il),"create vehicle");return this.bindViews(r),o}destroyVehicle(e){let t=this.session;t.flush(),t.check(this.exports.engine_vehicle_destroy(t.require(),e),"destroy vehicle");}vehicleInputs(){return this.inputs}vehicleStates(){return this.states}bindViews(e){let t=this.exports.engine_vehicle_capacity(e),n=this.exports.engine_vehicle_inputs(e),r=this.exports.engine_vehicle_states(e);if(n===Wf||r===Wf)throw new _("not_initialized","engine vehicles are not reserved");let o=this.session.buffer;(this.inputs.byteOffset!==n||this.inputs.buffer!==o)&&(this.inputs=new Float32Array(o,n,t*mk),this.states=new Float32Array(o,r,t*fk));}};var _k={linX:0,linY:1,linZ:2,angX:3,angY:4,angZ:5},ol=10,gj=-1;var rFe=["engine_joint_drive","engine_joint_drive_clear","engine_joint_target","engine_joint_breakable","engine_joint_enable","engine_joint_contacts","engine_joint_broken","engine_joint_load","engine_joint_break_count","engine_joint_breaks"],iFe=["engine_ragdoll_create","engine_ragdoll_destroy","engine_ragdoll_drive","engine_ragdoll_place","engine_ragdoll_read","engine_ragdoll_root","engine_ragdoll_bodies","engine_ragdoll_bone_count"],oFe=0,sFe=1,aFe=2,lFe=3,cFe=4,uFe=0,dFe=4,hFe=5,pFe=6,mFe=0,fFe=1,_Fe=0,yFe=1,AFe=0,bFe=1,gFe=2;var EFe=12,xFe=13,vFe=14,RFe=15,yk=16,SFe=1,Ej=4294967295,TFe=0,wFe=1,IFe=4,OFe=5,CFe=6,NFe=7,xj=8,kFe=10,vj=11,LFe=0,MFe=1,DFe=2,PFe=0,FFe=0,UFe=Number.MAX_VALUE,BFe=1e3,GFe=Math.PI/4,VFe=[-Math.PI/8,Math.PI/8],HFe=[0,1,0],WFe=[0,0,0],KFe=[0,0,0,1],YFe=[1,1,1],Kf=3,Ak=4,Rj=new Uint32Array(0);function XFe(i){for(let e of [...rFe,...iFe])if(typeof i[e]!="function")return null;return i}function Sj(i){let e=XFe(i.symbols);return e?new gk(i,e):null}function Tj(i,e,t){let n=t.position??WFe,r=t.rotation??KFe,o=t.scale??YFe;for(let s=0;s<Kf;s++)i[e+s]=n[s];for(let s=0;s<Ak;s++)i[e+Kf+s]=r[s];for(let s=0;s<Kf;s++)i[e+Kf+Ak+s]=o[s];}var bk=class{constructor(e,t,n,r,o){this.live=true;this.session=e,this.exports=t,this.id=n,this.pose=r;let s=t.engine_ragdoll_bodies(e.require(),n);if(s===FFe)throw new _("unknown_resource",`ragdoll ${n} has no bodies`);this.bodies=new Uint32Array(e.buffer,s,o);}world(){if(!this.live)throw new _("unknown_resource",`ragdoll ${this.id} was destroyed`);let e=this.session;return e.flush(),e.require()}drive(e){let t=this.world(),n=this.session.registerFloats;n[LFe]=e.stiffness,n[MFe]=e.damping,n[DFe]=e.maxTorque,this.session.check(this.exports.engine_ragdoll_drive(t,this.id,this.pose.byteOffset,this.pose.length),"drive ragdoll");}place(){let e=this.world();this.session.check(this.exports.engine_ragdoll_place(e,this.id,this.pose.byteOffset,this.pose.length),"place ragdoll");}read(){let e=this.world();return this.session.check(this.exports.engine_ragdoll_read(e,this.id,this.pose.byteOffset,this.pose.length),"read ragdoll"),this.pose}setRoot(e){let t=this.world();Tj(this.session.registerFloats,PFe,e),this.session.check(this.exports.engine_ragdoll_root(t,this.id),"ragdoll root");}destroy(){let e=this.world();this.session.check(this.exports.engine_ragdoll_destroy(e,this.id),"destroy ragdoll"),this.live=false;}},gk=class{constructor(e,t){this.breakView=Rj;this.session=e,this.exports=t;}world(){let e=this.session;return e.flush(),e.require()}setDrive(e,t,n){let r=this.world(),o=this.session.registerFloats;o[oFe]=n.targetPosition??0,o[sFe]=n.targetVelocity??0,o[aFe]=n.stiffness,o[lFe]=n.damping,o[cFe]=n.maxForce??UFe,this.session.check(this.exports.engine_joint_drive(r,e,_k[t]),"joint drive");}clearDrive(e,t){this.session.check(this.exports.engine_joint_drive_clear(this.world(),e,_k[t]),"clear joint drive");}setTarget(e,t,n){let r=this.world(),o=this.session.registerFloats;for(let s=0;s<Ak;s++)o[uFe+s]=t[s];o[dFe]=n.stiffness,o[hFe]=n.damping,o[pFe]=n.maxTorque,this.session.check(this.exports.engine_joint_target(r,e),"joint target");}setBreakable(e,t,n){let r=this.world(),o=this.session.registerFloats;o[mFe]=t,o[fFe]=n,this.session.check(this.exports.engine_joint_breakable(r,e),"breakable joint");}setEnabled(e,t){this.session.check(this.exports.engine_joint_enable(this.world(),e,t?1:0),"enable joint");}setContacts(e,t){this.session.check(this.exports.engine_joint_contacts(this.world(),e,t?1:0),"joint contacts");}broken(e){return this.session.check(this.exports.engine_joint_broken(this.world(),e),"joint broken")!==0}load(e,t){this.session.check(this.exports.engine_joint_load(this.world(),e),"joint load");let n=this.session.registerFloats;t.force=n[_Fe],t.torque=n[yFe];}breaks(){let e=this.world(),t=this.exports.engine_joint_break_count(e);if(t===0)return Rj;let n=this.exports.engine_joint_breaks(e),r=this.session.buffer;return (this.breakView.byteOffset!==n||this.breakView.buffer!==r||this.breakView.length!==t)&&(this.breakView=new Uint32Array(r,n,t)),this.breakView}createRagdoll(e){let t=e.parents.length;if(e.pose.length<t*ol)throw new _("invalid_argument",`a ragdoll pose needs ${ol} floats per joint`);let n=e.bones.length,r=yk+t+t*ol+n*vj,o=this.session,s=o.memory.allocate("u32",r),a=new Float32Array(s.buffer,s.byteOffset,r);s[AFe]=n,s[bFe]=t,Tj(a,gFe,e.root??{}),a[EFe]=e.linearDamping??0,a[xFe]=e.angularDamping??0,a[vFe]=e.friction??Number.NaN;let l=e.bones.some(m=>m.entity!==void 0);s[RFe]=l?SFe:0;for(let m=0;m<t;m++){let f=e.parents[m];s[yk+m]=f===gj?Ej:f;}let c=yk+t;a.set(e.pose.subarray(0,t*ol),c);let u=c+t*ol;for(let m=0;m<n;m++){let f=e.bones[m],y=u+m*vj,b=f.axis??HFe,A=f.twist??VFe;s[y+TFe]=f.joint;for(let E=0;E<Kf;E++)a[y+wFe+E]=b[E];a[y+IFe]=f.length,a[y+OFe]=f.radius,a[y+CFe]=f.density??BFe,a[y+NFe]=f.swing??GFe,a[y+xj]=A[0],a[y+xj+1]=A[1],s[y+kFe]=f.entity??Ej;}let d=this.world(),h=o.check(this.exports.engine_ragdoll_create(d,s.byteOffset,r),"create ragdoll"),p=o.memory.allocate("f32",t*ol);return p.set(e.pose.subarray(0,t*ol)),new bk(o,this.exports,h,p,n)}};var qFe="cimplify-engine",wj=65535,Ij=Math.PI/180,zFe=.01,Dj=[0,0,0],P0=[0,0,0,1],Oj=[true,true,true],Cj=[false,false,false],QFe=[true,true,false],$Fe=[false,false,true],jFe=0,Ko=Number.NaN;function Nj(i,e){return ((i[0]?1:0)|(i[1]?2:0)|(i[2]?4:0))<<e}function Pj(i){switch(i.kind){case "ball":return HB;case "cuboid":return WB;case "capsule":return KB;case "cylinder":return YB;case "cone":return XB;case "trimesh":return qB;case "convex_hull":return zB;case "heightfield":return QB;case "round_cuboid":return $B;case "round_cylinder":return jB;case "round_cone":return JB;case "round_convex_hull":return ZB;case "compound":return e4}}function Fj(i,e,t,n){switch(i.kind){case "ball":e[t]=i.radius;break;case "cuboid":case "round_cuboid":e[t]=i.halfExtents[0],e[t+1]=i.halfExtents[1],e[t+2]=i.halfExtents[2];break;case "capsule":case "cylinder":case "cone":case "round_cylinder":case "round_cone":e[t]=i.halfHeight,e[t+1]=i.radius;break}(i.kind==="round_cuboid"||i.kind==="round_cylinder"||i.kind==="round_cone")&&(e[n]=i.border);}function JFe(i){let e=new Float32Array(i.length*Yw);for(let t=0;t<i.length;t++){let n=i[t],r=t*Yw;e[r+t4]=Pj(n.shape),Fj(n.shape,e,r+n4,r+r4);let o=n.offset??Dj,s=n.rotation??P0;for(let a=0;a<3;a++)e[r+i4+a]=o[a];for(let a=0;a<4;a++)e[r+o4+a]=s[a];}return e}var kj=["locked","locked","locked"],Lj=2,Mj=6,ZFe=4;function eUe(i,e,t){let n=i.frameA??P0,r=i.frameB??P0;for(let a=0;a<ZFe;a++)t[F4+a]=n[a],t[U4+a]=r[a];let o=[...i.linear??kj,...i.angular??kj];if(o.length!==Mj)throw new _("invalid_argument","a six_dof joint has three linear and three angular axes");let s=0;for(let a=0;a<Mj;a++){let l=o[a],c=V4;l==="free"?c=H4:l!=="locked"&&(c=W4,t[Qw+a*Lj]=l[0],t[Qw+a*Lj+1]=l[1]),s|=c<<a*K4;}e[B4]=s>>>0,t[G4]=i.swingCone??Ko;}var F0=class{constructor(e){this.name=qFe;this.session=e;let t=bj(e.symbols);this.vehicles=t?new D0(e,t):null,this.craft=nj(e),this.jointPort=Sj(e);}bindTransforms(e){this.session.bind(e);}init(e){return this.session.open(e),Promise.resolve()}get rollback(){return this.session.snapshots}setGravity(e){this.vectorCommand(dG,0,e);}createBody(e,t){let n=this.session;n.flush();let r=n.descWords,o=n.descFloats;r[OB]=t.kind==="dynamic"?BB:t.kind==="kinematic"?GB:VB,o[CB]=t.linearDamping??0,o[NB]=t.angularDamping??0,o[kB]=t.gravityScale??1;let s=t.planar?QFe:t.lockTranslations?Cj:t.enabledTranslations??Oj,a=t.planar?$Fe:t.lockRotations?Cj:t.enabledRotations??Oj;return r[LB]=(t.ccd?DB:0)|(t.canSleep===false?0:PB)|Nj(s,FB)|Nj(a,UB),r[MB]=t.dominance??0,n.check(n.exports.engine_body_create(n.require(),e),"create body")}destroyBody(e){let t=this.session;t.flush(),t.check(t.exports.engine_body_destroy(t.require(),e),"destroy body");}createCollider(e,t){let n=this.session;n.flush();let r=n.descWords,o=n.descFloats;r.fill(0);let s=t.shape;r[s4]=Pj(s);let a=[];switch(s.kind){case "ball":case "cuboid":case "capsule":case "cylinder":case "cone":case "round_cuboid":case "round_cylinder":case "round_cone":Fj(s,o,Bp,Xw);break;case "round_convex_hull":this.stage(a,s.points,Mu,Du),o[Xw]=s.border;break;case "compound":this.stage(a,JFe(s.parts),Mu,Du);break;case "trimesh":this.stage(a,s.vertices,Mu,Du),this.stage(a,s.indices,_4,y4);break;case "convex_hull":this.stage(a,s.points,Mu,Du);break;case "heightfield":this.stage(a,s.heights,Mu,Du),r[A4]=s.rows,r[b4]=s.columns,o[Bp]=s.scale[0],o[Bp+1]=s.scale[1],o[Bp+2]=s.scale[2];break}let l=t.offset??Dj,c=t.rotation??P0;for(let d=0;d<3;d++)o[a4+d]=l[d];for(let d=0;d<4;d++)o[l4+d]=c[d];o[c4]=t.density??Ko,o[u4]=t.mass??Ko,o[d4]=t.friction??Ko,o[h4]=t.restitution??Ko;let u=t.membership!==void 0||t.filter!==void 0;r[p4]=(t.sensor?g4:0)|(t.events?E4:0)|(u?x4:0),r[m4]=t.membership??qw,r[f4]=t.filter??qw;try{return n.check(n.exports.engine_collider_create(n.require(),e),"create collider")}finally{for(let d of a)n.exports.engine_free(d.pointer,d.bytes,Rt);}}destroyCollider(e){let t=this.session;t.flush(),t.check(t.exports.engine_collider_destroy(t.require(),e),"destroy collider");}setColliderEnabled(e,t){let n=this.session;n.flush(),n.check(n.exports.engine_collider_enable(n.require(),e,t?1:0),"enable collider");}createJoint(e,t,n){let r=this.session;r.flush();let o=r.descWords,s=r.descFloats;o.fill(0);for(let a=0;a<3;a++)s[O4+a]=n.anchorA[a],s[C4+a]=n.anchorB[a];switch(n.kind){case "fixed":o[ga]=v4;break;case "spherical":o[ga]=R4;break;case "revolute":case "prismatic":o[ga]=n.kind==="revolute"?S4:T4;for(let a=0;a<3;a++)s[zw+a]=n.axis[a];n.limits&&(o[N4]=1,s[Gp]=n.limits[0],s[Gp+1]=n.limits[1]);break;case "rope":o[ga]=w4,s[SA]=n.length;break;case "spring":o[ga]=I4,s[SA]=n.restLength,s[k4]=n.stiffness,s[L4]=n.damping;break;case "cone":o[ga]=M4;for(let a=0;a<3;a++)s[zw+a]=n.axis[a];s[P4]=n.swing,s[Gp]=n.twist[0],s[Gp+1]=n.twist[1];break;case "six_dof":o[ga]=D4,eUe(n,o,s);break}return r.check(r.exports.engine_joint_create(r.require(),e,t),"create joint")}setJointMotor(e,t,n){let r=this.session;r.flush();let o=r.require();r.registerFloats[lB]=t,r.registerFloats[cB]=n,r.check(r.exports.engine_joint_motor(o,e),"joint motor");}destroyJoint(e){let t=this.session;t.flush(),t.check(t.exports.engine_joint_destroy(t.require(),e),"destroy joint");}step(){this.session.step();}setBodyPose(e,t,n,r,o){let s=this.session,a=s.command(uG,e),l=s.commandPayload;l[a]=t[n],l[a+1]=t[n+1],l[a+2]=t[n+2],l[a+3]=r[o],l[a+4]=r[o+1],l[a+5]=r[o+2],l[a+6]=r[o+3];}linearVelocity(e,t){let n=this.session;n.flush(),n.check(n.exports.engine_body_linear_velocity(n.require(),e),"linear velocity"),this.readVector(t);}angularVelocity(e,t){let n=this.session;n.flush(),n.check(n.exports.engine_body_angular_velocity(n.require(),e),"angular velocity"),this.readVector(t);}setLinearVelocity(e,t){this.vectorCommand(aG,e,t);}setAngularVelocity(e,t){this.vectorCommand(lG,e,t);}applyImpulse(e,t){this.vectorCommand(rG,e,t);}applyTorqueImpulse(e,t){this.vectorCommand(iG,e,t);}addForce(e,t){this.vectorCommand(oG,e,t);}applyImpulseAtPoint(e,t,n){this.pointCommand(vG,e,t,n);}addForceAtPoint(e,t,n){this.pointCommand(RG,e,t,n);}addTorque(e,t){this.vectorCommand(SG,e,t);}extra(e){let t=this.session.symbols[e];if(typeof t!="function")throw new _("unsupported_feature",`${e} is not in this engine build`);return t}velocityAtPoint(e,t,n){let r=this.session;r.flush();let o=r.registerFloats;o[wr]=t.x,o[wr+1]=t.y,o[wr+2]=t.z,r.check(this.extra("engine_body_velocity_at_point")(r.require(),e),"velocity at point"),this.readVector(n);}setJointMotorPosition(e,t,n,r){let o=this.session;o.flush();let s=o.registerFloats;s[gG]=t,s[EG]=n,s[xG]=r,o.check(this.extra("engine_joint_motor_position")(o.require(),e),"joint motor position");}castShape(e,t){let n=this.session;n.flush();let r=n.registerWords,o=n.registerFloats;r[AG]=VQ(e.kind),o[OA]=e.params.x,o[OA+1]=e.params.y,o[OA+2]=e.params.z;for(let a=0;a<4;a++)o[bG+a]=e.rotation[a];o[yo]=e.origin.x,o[yo+1]=e.origin.y,o[yo+2]=e.origin.z,o[ql]=e.direction.x,o[ql+1]=e.direction.y,o[ql+2]=e.direction.z,o[TA]=e.maxDistance,r[wA]=e.includeSensors?1:0,r[$w]=e.excludeBody<0?Jw:e.excludeBody;let s=n.check(this.extra("engine_shape_cast")(n.require()),"shape cast")===Zw;return t.hit=s,s?(t.collider=r[IA],t.distance=o[jw],t.pointX=o[zl],t.pointY=o[zl+1],t.pointZ=o[zl+2],t.normalX=o[Ql],t.normalY=o[Ql+1],t.normalZ=o[Ql+2],true):(t.collider=-1,false)}overlapSphere(e,t,n,r,o,s){let a=this.session;a.flush();let l=a.registerWords,c=a.registerFloats;c[yo]=e,c[yo+1]=t,c[yo+2]=n,c[TA]=r,l[wA]=o?1:0,s.count=a.check(this.extra("engine_overlap_sphere")(a.require()),"sphere overlap"),s.collider=s.count>0?l[IA]:-1;}pointCommand(e,t,n,r){let o=this.session,s=o.command(e,t),a=o.commandPayload;a[s]=n.x,a[s+1]=n.y,a[s+2]=n.z,a[s+3]=r.x,a[s+4]=r.y,a[s+5]=r.z;}resetForces(e){this.session.command(sG,e);}isSleeping(e){let t=this.session;return t.flush(),t.check(t.exports.engine_body_sleeping(t.require(),e),"sleeping")===1}wake(e){this.session.command(cG,e);}batchHandle(){let e=this.session;return e.flush(),e.require()}raycast(e,t){let n=this.session;n.flush();let r=n.registerWords,o=n.registerFloats;o[yo]=e.origin.x,o[yo+1]=e.origin.y,o[yo+2]=e.origin.z,o[ql]=e.direction.x,o[ql+1]=e.direction.y,o[ql+2]=e.direction.z,o[TA]=e.maxDistance,r[tG]=e.solid?1:0,r[wA]=e.includeSensors?1:0,r[$w]=e.excludeCollider<0?Jw:e.excludeCollider;let s=n.check(n.exports.engine_raycast(n.require()),"raycast")===Zw;return t.hit=s,s?(t.collider=r[IA],t.distance=o[jw],t.pointX=o[zl],t.pointY=o[zl+1],t.pointZ=o[zl+2],t.normalX=o[Ql],t.normalY=o[Ql+1],t.normalZ=o[Ql+2],true):(t.collider=-1,false)}contactCount(){return this.session.contacts}contactColliderA(e){return this.session.contactA[e]}contactColliderB(e){return this.session.contactB[e]}contactStarted(e){return this.session.contactBegan[e]===1}createCharacterController(e){let t=this.session;t.flush();let n=t.descWords,r=t.descFloats;if(n.fill(0),r[Y4]=e.offset??zFe,r[X4]=e.maxSlopeClimbDegrees===void 0?Ko:e.maxSlopeClimbDegrees*Ij,r[q4]=e.minSlopeSlideDegrees===void 0?Ko:e.minSlopeSlideDegrees*Ij,r[z4]=e.autostepMaxHeight??Ko,r[Q4]=e.autostepMinWidth??Ko,r[$4]=e.snapToGround??Ko,n[j4]=e.slide===void 0?eG:e.slide?1:0,e.up){n[Z4]=1;for(let o=0;o<3;o++)r[J4+o]=e.up[o];}return t.check(t.exports.engine_controller_create(t.require()),"create controller")}moveCharacter(e,t,n,r){let o=this.session;o.flush();let s=o.registerFloats;s[wr]=n.x,s[wr+1]=n.y,s[wr+2]=n.z,o.check(o.exports.engine_character_move(o.require(),e,t),"move character"),r.x=s[wr],r.y=s[wr+1],r.z=s[wr+2],r.grounded=o.registerWords[nG]===1;}destroyCharacterController(e){let t=this.session;t.flush(),t.check(t.exports.engine_controller_destroy(t.require(),e),"destroy controller");}dispose(){this.craft?.dispose(),this.session.close();}setColliderClass(e,t){let n=this.session,r=n.command(hG,e);n.commandPayloadWords[r]=Za(t);}setContactRule(e,t,n){let r=this.session,o=r.command(pG,WQ(e,t,n));KQ(n,r.commandPayload,o);}setCollisionGroups(e,t,n){let r=this.session,o=r.command(mG,e);r.commandPayloadWords[o]=t&wj,r.commandPayloadWords[o+1]=n&wj;}setSolver(e,t,n){let r=this.session,o=r.command(fG,0);r.commandPayloadWords[o]=e,r.commandPayloadWords[o+1]=t,r.commandPayloadWords[o+2]=n;}setSoftCcd(e,t){let n=this.session,r=n.command(_G,e);n.commandPayload[r]=t;}setSleepThresholds(e,t,n,r){let o=this.session,s=o.command(yG,e),a=o.commandPayload;a[s]=t,a[s+1]=n,a[s+2]=r;}vectorCommand(e,t,n){let r=this.session,o=r.command(e,t),s=r.commandPayload;s[o]=n.x,s[o+1]=n.y,s[o+2]=n.z;}readVector(e){let t=this.session.registerFloats;e.x=t[wr],e.y=t[wr+1],e.z=t[wr+2];}stage(e,t,n,r){let o=this.session,s=t.length*Rt,a=o.exports.engine_alloc(s,Rt);if(a===jFe)throw new _("capacity_exceeded","engine memory cannot hold collider data");e.push({pointer:a,bytes:s}),new Uint8Array(o.buffer,a,s).set(new Uint8Array(t.buffer,t.byteOffset,s)),o.descWords[n]=a,o.descWords[r]=t.length;}};var tUe=["engine_inspector_enable","engine_inspector_watch","engine_inspector_label","engine_inspector_registers"];var Uj="__cimplify_dev";function Bj(i,e){return {live:i[e],highWater:i[e+1],capacity:i[e+2]}}function nUe(i){return {shown:i[0]!==0,refreshes:i[1],error:i[2],arena:{highWaterBytes:i[3]*1024,committedBytes:i[4]*1024,ceilingBytes:i[5]*1024},stream:{missing:i[10],urgent:i[13],starvedFrames:i[14]},bodies:Bj(i,19),colliders:Bj(i,22),kernels:{budgetMs:i[28]/1e6,spentMs:i[29]/1e6},frameMs:i[34]/1e6}}var Gj=null;function oh(){let i=globalThis,e=i[Uj]??Gj;if(e!=null)return e;let t={wanted:false,supported:false,world:0,stream:0,listeners:new Set};return Object.isExtensible(i)?i[Uj]=t:Gj=t,t}function Ek(){let i=oh();for(let e of [...i.listeners])e(i.wanted);}function Vj(i){let e=oh();e.wanted!==i&&(e.wanted=i,Ek());}function xk(i){let e=oh();e.world!==i&&(e.world=i,Ek());}function vk(i){let e=oh();e.stream!==i&&(e.stream=i,Ek());}var U0=class i{constructor(e,t,n){this.exports=e;this.memory=t;this.names=n;this.view=new Uint32Array(0);this.encoder=new TextEncoder;this.shown=false;let r=oh();r.supported=true;let o=s=>this.apply(s);r.listeners.add(o),this.unsubscribe=()=>r.listeners.delete(o),r.wanted&&this.apply(true);}static bind(e,t,n){for(let o of [...tUe,"engine_alloc","engine_free"])if(typeof e[o]!="function")return null;let r=e;return r.engine_inspector_watch(0,0)<0?null:new i(r,t,n)}apply(e){let t=oh();if(!(this.exports.engine_inspector_enable(e?1:0)<0)&&(this.shown=e,this.exports.engine_inspector_watch(t.world,t.stream),e))for(let[n,r,o]of this.names())this.label(n,r,o);}label(e,t,n){if(!this.shown)return;let r=this.encoder.encode(n).subarray(0,24);if(r.byteLength===0)return;let o=this.exports.engine_alloc(r.byteLength,1);o!==0&&(new Uint8Array(this.memory.buffer,o,r.byteLength).set(r),this.exports.engine_inspector_label(e,t,o,r.byteLength),this.exports.engine_free(o,r.byteLength,1));}readout(){let e=this.exports.engine_inspector_registers();if(e===0)return null;let t=this.memory.buffer;return (this.view.buffer!==t||this.view.byteOffset!==e)&&(this.view=new Uint32Array(t,e,40)),nUe(this.view)}release(){this.unsubscribe(),this.shown&&this.exports.engine_inspector_enable(0),this.shown=false;}};function rUe(i){return new Uint8Array(i.buffer,i.byteOffset,i.byteLength)}var Yf=class{constructor(e,t=null){this.states=[];this.known=[];this.copies=[];this.stride=0;this.slots=new Uint8Array(0);this.slices=[];this.stale=true;this.breaks=0;this.frames=e,this.engine=t,this.ticks=new Float64Array(e).fill(-1);}attach(e){this.states.includes(e)||(this.states.push(e),this.stale=true);}save(e){this.changed()&&this.relayout();let t=this.slot(e),n=this.copies,r=this.slices,o=t*n.length;for(let s=0;s<n.length;s++)r[o+s].set(n[s]);this.ticks[t]=e;}has(e){return !this.changed()&&this.ticks[this.slot(e)]===e}restore(e){if(!this.has(e))return false;let t=this.copies,n=this.slices,r=this.slot(e)*t.length;for(let o=0;o<t.length;o++)t[o].set(n[r+o]);for(let o=0;o<this.frames;o++)this.ticks[o]>e&&(this.ticks[o]=-1);return true}clear(){this.ticks.fill(-1);}dropAfter(e){for(let t=0;t<this.frames;t++)this.ticks[t]>e&&(this.ticks[t]=-1);}slot(e){return (e%this.frames+this.frames)%this.frames}changed(){if(this.stale)return true;let e=0,t=this.known,n=this.states;for(let r=0;r<n.length;r++){let o=n[r].rollbackViews();for(let s=0;s<o.length;s++){if(t[e]!==o[s])return true;e++;}}return e!==t.length}relayout(){let e=[],t=[],n=0;for(let o of this.states)for(let s of o.rollbackViews()){if(e.push(s),this.engine!==null&&this.engine.owns(s)){this.engine.adopt(s);continue}let a=rUe(s);t.push(a),n+=a.byteLength;}this.known=e,this.copies=t,(n!==this.stride||this.slots.byteLength!==n*this.frames)&&(this.stride=n,this.slots=new Uint8Array(n*this.frames));let r=[];for(let o=0,s=0;o<this.frames;o++)for(let a of t)r.push(this.slots.subarray(s,s+a.byteLength)),s+=a.byteLength;this.slices=r,(!this.stale||this.ticks.some(o=>o!==-1))&&this.breaks++,this.ticks.fill(-1),this.stale=false;}};var iUe=["engine_world_rollback_create","engine_world_snapshot_save","engine_world_snapshot_restore","engine_world_snapshot_clear","engine_world_snapshot_track","engine_world_snapshot_track_table","engine_world_snapshot_untrack","engine_world_snapshot_mark","engine_world_snapshot_registers","engine_world_snapshot_digest"],qj=4,oUe=0,sUe=1,aUe=2,lUe=3,zj=0,cUe=1,uUe=16,dUe=4294967295,hUe=16*1024*1024,pUe=4*1024*1024,mUe=8*1024*1024,H0=8,Hj=64,fUe=0,_Ue=1,yUe=2,AUe=3,bUe=4,gUe=5,EUe=6,xUe=7,vUe=8,RUe=9,SUe=10,TUe=11,wUe=12,IUe=13,OUe=14,CUe=15,B0=-3,NUe=-1,Wj=1e6,Kj=8,kUe=8;function Rk(i){return iUe.every(e=>typeof i[e]=="function")}function Qj(i,e){let t=e.frames??H0;if(!Number.isInteger(t)||t<2||t>Hj)throw new _("invalid_argument",`rollback frames must be 2..${Hj}`);i[oUe]=e.regionBytes??hUe,i[sUe]=e.trackedBytes??pUe,i[aUe]=e.journalBytes??mUe,i[lUe]=t;}function Yj(i){return i==="marked"?cUe:zj}function G0(i){return i===dUe?null:i}var LUe=["engine_world_keyframes_enable","engine_world_keyframe_save","engine_world_keyframe_seek","engine_world_keyframe_nearest","engine_world_keyframe_truncate","engine_world_keyframe_registers"],MUe=8,Xj=60,DUe=64,PUe=16384,FUe=0,UUe=1,BUe=2,GUe=3,VUe=4,HUe=5,WUe=6,KUe=7;function YUe(i){let e=i;return LUe.every(t=>typeof e[t]=="function")?i:null}var V0=class i{constructor(e,t,n,r,o){this.exports=e;this.memory=t;this.world=n;this.beforeRestore=r;this.view=new Uint32Array(0);this.digestAt=0;this.keyRing=null;this.keyframes=null;this.every=Xj;this.states=[];this.ring=new Yf(o,{owns:s=>s.buffer===this.memory.buffer,adopt:s=>this.adopt(s)});}static bind(e,t,n,r=()=>{},o=H0){if(!Rk(e)||typeof e.engine_alloc!="function")return null;let s=e;return s.engine_world_snapshot_registers(n)===0?null:new i(s,t,n,r,o)}attach(e){this.ring.attach(e),this.keyRing?.attach(e),this.states.push(e);}enableKeyframes(e){let t=YUe(this.exports);if(t===null)return false;let n=e.every??Xj,r=e.slots??DUe;if(!Number.isInteger(n)||n<1)throw new _("invalid_argument","keyframes come every whole number of ticks");this.check(t.engine_world_keyframes_enable(this.world,e.leaves??PUe,r),"keyframes enable"),this.keyframes=t,this.every=n,this.keyRing=new Yf(r,{owns:o=>o.buffer===this.memory.buffer,adopt:o=>this.adopt(o)});for(let o of this.states)this.keyRing.attach(o);return true}get keyframeEvery(){return this.every}keyframe(e){let t=this.keyframes,n=this.keyRing;return t===null||n===null||e%this.every!==0?false:(this.check(t.engine_world_keyframe_save(this.world,e>>>0),"keyframe save"),n.save(e/this.every),true)}nearestKeyframe(e){let t=this.keyframes;if(t===null)return null;let n=t.engine_world_keyframe_nearest(this.world,e>>>0);return n===B0?null:this.check(n,"keyframe nearest")}seekKeyframe(e){let t=this.keyframes,n=this.keyRing;if(t===null||n===null||e%this.every!==0||(this.beforeRestore(),!n.has(e/this.every)))return false;let r=t.engine_world_keyframe_seek(this.world,e>>>0);return r===B0?false:(this.check(r,"keyframe seek"),n.restore(e/this.every),this.ring.clear(),this.truncateKeyframes(e),true)}truncateKeyframes(e){this.keyframes!==null&&(this.check(this.keyframes.engine_world_keyframe_truncate(this.world,e>>>0),"keyframe truncate"),this.keyRing?.dropAfter(Math.floor(e/this.every)));}clearKeyframes(){this.keyframes!==null&&(this.clear(),this.keyRing?.clear());}keyframeStats(){if(this.keyframes===null)return null;let e=this.keyframes.engine_world_keyframe_registers(this.world),t=new Uint32Array(this.memory.buffer,e,MUe);return {frames:t[FUe],oldest:G0(t[UUe]),newest:G0(t[BUe]),leavesUsed:t[GUe],leavesShared:t[VUe],captures:t[HUe],evicted:t[WUe],installs:t[KUe]}}get stateBreaks(){return this.ring.breaks}save(e){let t=this.check(this.exports.engine_world_snapshot_save(this.world,e>>>0),"snapshot save");return this.ring.save(e>>>0),t}restore(e){if(this.beforeRestore(),!this.ring.has(e>>>0))return false;let t=this.exports.engine_world_snapshot_restore(this.world,e>>>0);return t===B0?false:(this.check(t,"snapshot restore"),this.ring.restore(e>>>0))}clear(){this.check(this.exports.engine_world_snapshot_clear(this.world),"snapshot clear"),this.ring.clear();}adopt(e){if(this.exports.engine_world_snapshot_track(this.world,e.byteOffset,e.byteLength,zj)===NUe)throw new _("capacity_exceeded","rollback trackedBytes is too small for the game's engine-memory state")}track(e,t="scan"){this.owned(e),this.check(this.exports.engine_world_snapshot_track(this.world,e.byteOffset,e.byteLength,Yj(t)),"snapshot track");}trackTable(e,t="scan"){this.check(this.exports.engine_world_snapshot_track_table(this.world,e,Yj(t)),"snapshot track table");}untrack(e){this.owned(e),this.check(this.exports.engine_world_snapshot_untrack(this.world,e.byteOffset),"snapshot untrack");}mark(e,t=0,n){let r=e.BYTES_PER_ELEMENT,o=Math.min(n??e.byteLength/r,e.byteLength/r);return o<=t?false:this.exports.engine_world_snapshot_mark(this.world,e.byteOffset+t*r,(o-t)*r)===1}digest(){return this.digestAt===0&&(this.digestAt=this.exports.engine_alloc(Kj,kUe)),this.check(this.exports.engine_world_snapshot_digest(this.world,this.digestAt),"snapshot digest"),new DataView(this.memory.buffer,this.digestAt,Kj).getBigUint64(0,true)}stats(){let e=this.registers();return {depth:e[fUe],newest:G0(e[_Ue]),oldest:G0(e[yUe]),dirtyPages:e[AUe],scannedPages:e[bUe],restoredPages:e[gUe],saveMs:e[EUe]/Wj,restoreMs:e[xUe]/Wj,evicted:e[vUe],heapBytes:e[RUe],trackedPages:e[SUe],spilled:e[TUe]!==0,breaks:e[wUe]+this.ring.breaks,residents:e[IUe],quietPages:e[OUe],missedPages:e[CUe]}}registers(){let e=this.exports.engine_world_snapshot_registers(this.world),t=this.memory.buffer;return (this.view.buffer!==t||this.view.byteOffset!==e)&&(this.view=new Uint32Array(t,e,uUe)),this.view}owned(e){if(e.buffer!==this.memory.buffer)throw new _("invalid_argument","rolled-back views must live in engine memory")}check(e,t){if(e>=0)return e;throw new _(e===B0?"unknown_resource":"invalid_argument",`${t} failed (${e})`)}};var sl=0,Xf=new Uint32Array(0),Sk=new Float32Array(0),$Ue=new Uint8Array(0);function jUe(i,e){switch(i){case Ea:return new _("capacity_exceeded",`${e}: capacity exceeded`);case xa:return new _("dead_entity",`${e}: entity has no transform`);case va:return new _("unknown_resource",`${e}: unknown resource`);case Ao:return new _("unsupported_feature",`${e}: unsupported`);case Vp:default:return new _("invalid_argument",`${e}: invalid argument`)}}var W0=class{constructor(e,t){this.world=sl;this.registerWords=Xf;this.registerFloats=Sk;this.descWords=Xf;this.descFloats=Sk;this.contactA=Xf;this.contactB=Xf;this.contactBegan=$Ue;this.contacts=0;this.snapshots=null;this.commandWords=Xf;this.commandFloats=Sk;this.commandCapacity=0;this.pending=0;this.columns=null;this.runtime=e,this.exports=e.exports,this.memory=t;}bind(e){for(let t of [e.position,e.rotation,e.render,e.parent,e.entities,e.sparse])if(!this.memory.owns(t))throw new _("invalid_argument","engine transforms must live in engine memory");this.columns=e,this.world!==sl&&this.bindLayout(e);}open(e){if(this.world!==sl)throw new _("invalid_argument","engine world is already open");let t=this.memory.allocate("u32",Fp),n=new Float32Array(t.buffer,t.byteOffset,Fp),r=e.gravity??[0,-9.81,0];n[RA]=r[0],n[RA+1]=r[1],n[RA+2]=r[2],n[dB]=e.stepSeconds,t[hB]=e.maxBodies??2048,t[pB]=e.maxColliders??4096,t[mB]=e.maxJoints??1024,t[Kw]=e.maxContactEvents??1024,t[fB]=e.maxCharacterControllers??64,t[_B]=Lu;let o=e.rollback===void 0?this.exports.engine_world_create(t.byteOffset):this.createRollback(t,e.rollback);if(o===sl)throw Pu(this.runtime.symbols)??new _("capacity_exceeded","engine world could not be created");this.world=o,this.snapshots=e.rollback===void 0?null:V0.bind(this.runtime.symbols,this.runtime.memory,o,()=>this.discard(),e.rollback.frames??H0),xk(o);let s=this.runtime.memory.buffer,a=this.exports.engine_world_registers(o);this.registerWords=new Uint32Array(s,a,Ww),this.registerFloats=new Float32Array(s,a,Ww);let l=this.exports.engine_world_desc(o);this.descWords=new Uint32Array(s,l,Fp),this.descFloats=new Float32Array(s,l,Fp),this.commandCapacity=Lu;let c=Kp(this.runtime.symbols)?s:new ArrayBuffer(Lu*Up*Rt),u=c===s?this.exports.engine_world_commands(o):0;this.commandWords=new Uint32Array(c,u,Lu*Up),this.commandFloats=new Float32Array(c,u,Lu*Up);let d=t[Kw];this.contactA=new Uint32Array(s,this.exports.engine_contacts_a(o),d),this.contactB=new Uint32Array(s,this.exports.engine_contacts_b(o),d),this.contactBegan=new Uint8Array(s,this.exports.engine_contacts_started(o),d),this.columns&&this.bindLayout(this.columns);}createRollback(e,t){let n=this.runtime.symbols;if(!Rk(n))throw new _("unsupported_feature","this engine has no client rollback (feature rollback_1)");let r=this.memory.allocate("u32",qj);Qj(r,t);let o=n.engine_world_rollback_create;return o(e.byteOffset,r.byteOffset)}require(){if(this.world===sl)throw new _("not_initialized","engine physics is not initialised");return this.world}check(e,t){if(!(e>=0))throw jUe(e,t);return e}command(e,t){this.pending===this.commandCapacity&&this.flush();let n=this.pending*Up;return this.commandWords[n+TG]=e,this.commandWords[n+wG]=t,this.pending++,n+IG}get commandPayload(){return this.commandFloats}get commandPayloadWords(){return this.commandWords}get symbols(){return this.runtime.symbols}get buffer(){return this.runtime.memory.buffer}discard(){this.pending=0;}flush(){if(this.pending===0)return;let e=this.pending;this.pending=0,this.check(this.exports.engine_apply_commands(this.require(),e),"command");}step(){p6(this.runtime.memory);let e=this.pending;this.pending=0,this.check(this.exports.engine_step(this.require(),e),"step"),this.contacts=this.exports.engine_contact_count(this.world);}close(){this.world!==sl&&(xk(sl),this.exports.engine_world_destroy(this.world)),this.world=sl,this.snapshots=null,this.pending=0,this.columns=null,this.memory.release(),jY(this.runtime.symbols);}bindLayout(e){let t=this.descWords;t[yB]=e.position.byteOffset,t[AB]=e.rotation.byteOffset,t[bB]=e.scale.byteOffset,t[gB]=e.previousPosition.byteOffset,t[EB]=e.previousRotation.byteOffset,t[xB]=e.previousScale.byteOffset,t[vB]=e.parent.byteOffset,t[RB]=e.render.byteOffset,t[SB]=e.entities.byteOffset,t[TB]=e.sparse.byteOffset,t[wB]=e.capacity,t[IB]=e.sparse.byteLength/Rt,this.check(this.exports.engine_bind_transforms(this.world),"bind transforms");}};var K0=class{constructor(e){this.session=e;}bind(e){this.session.bind(e);}snapshot(e){let t=this.session;t.check(t.exports.engine_snapshot(t.require(),e),"snapshot");}computeRender(e,t,n){let r=this.session,o=r.require();r.registerFloats[oB]=t.values[ys],r.registerWords[sB]=n>>>0,r.registerWords[aB]=Math.floor(n/uB),r.check(r.exports.engine_compute_render(o,e),"compute render");}};var Ar={live:0,loading:1,waiting:2,failed:3,inflight:4,installed:5,installedBytes:6,evicted:8,residentKib:9,poolKib:10,proxyKib:11,sourceKib:12,totalInstalls:15},$j=16,jj=17,Ik=16,Ok=16,Ck=18,Nk=Ck+Ik,Jj=Nk+Ok,Zj=256,kk=24,eJ=0,tJ=1,nJ=0;var rJ=(1<<kk)-1,qf=6,Fs=2,sh=8,iJ=1,oJ={low:0,mid:1,high:2},Ic=-6;var JUe=["engine_stream_open","engine_stream_close","engine_stream_provide","engine_stream_update","engine_stream_registers","engine_stream_open_logic","engine_stream_step_logic","engine_stream_collider"],Vr=0,Lk=64,sJ="world_lazy_packs_1",Y0=4,Mk=4;function aJ(i){let e=i.symbols;return JUe.every(t=>typeof e[t]=="function")?e:null}var X0=class{constructor(e,t,n){this.runtime=e;this.exports=t;this.render=n;this.eye={pointer:Vr,bytes:0};this.actors={pointer:Vr,bytes:0};this.ops={pointer:Vr,bytes:0};this.scratch={pointer:Vr,bytes:0};this.buffer=null;this.floats=new Float32Array(0);this.words=new Uint32Array(0);this.bytes=new Uint8Array(0);this.lazySupport=null;}views(){let e=this.runtime.memory.buffer;e!==this.buffer&&(this.buffer=e,this.floats=new Float32Array(e),this.words=new Uint32Array(e),this.bytes=new Uint8Array(e));}ensure(e,t){if(e.bytes>=t)return e.pointer;if(e.pointer!==Vr&&this.runtime.exports.engine_free(e.pointer,e.bytes,ce),e.bytes=Math.max(t,ce),e.pointer=this.runtime.exports.engine_alloc(e.bytes,ce),e.pointer===Vr)throw e.bytes=0,new _("capacity_exceeded","engine memory cannot hold world streaming buffers");return e.pointer}stage(e){let t=this.runtime.exports.engine_alloc(Math.max(e.byteLength,1),ce);if(t===Vr)throw new _("capacity_exceeded","engine memory cannot hold world data");return this.views(),this.bytes.set(e,t),t}lazyPacks(){if(this.lazySupport!==null)return this.lazySupport;this.lazySupport=false;let e=this.runtime.symbols,t=e.engine_feature_count,n=e.engine_feature_name;if(t===void 0||n===void 0)return false;let r=this.runtime.exports.engine_alloc(Lk,1);if(r===Vr)return false;for(let o=0;o<t()&&!this.lazySupport;o++){let s=n(o,r,Lk);if(s!==sJ.length)continue;this.views();let a=true;for(let l=0;l<s&&a;l++)a=this.bytes[r+l]===sJ.charCodeAt(l);this.lazySupport=a;}return this.runtime.exports.engine_free(r,Lk,1),this.lazySupport}open(e,t,n){let r=this.ensure(this.scratch,Math.max(t.length,sh)*Mk),o=this.stage(e);this.views();for(let a=0;a<t.length;a++)this.words[(r>>>2)+a]=t[a];let s=this.exports.engine_stream_open(this.render(),o,e.byteLength,r,t.length,n);if(s===Vr)throw new _("invalid_argument","the engine refused the world file");return vk(s),s}provide(e,t){let n=this.exports.engine_stream_provide(e,this.stage(t),t.byteLength);if(n===Ic)return n;if(n<0)throw new _("invalid_argument",`the engine refused a world pack (${n})`);return n}update(e,t){let n=this.ensure(this.eye,qf*Y0);this.views();let r=n>>>2;for(let o=0;o<qf;o++)this.floats[r+o]=t[o];this.exports.engine_stream_update(e,this.render(),n);}registers(e){let t=this.exports.engine_stream_registers(e);if(t===Vr)throw new _("unknown_resource","world stream is closed");return this.views(),this.words.subarray(t>>>2,(t>>>2)+Jj)}openLogic(e,t,n,r){this.ensure(this.actors,Math.max(r,1)*Fs*Y0),this.ensure(this.ops,Math.max(n,1)*Mk);let o=this.exports.engine_stream_open_logic(e,t,n,r);if(o<0)throw new _("invalid_argument",`the engine refused world colliders (${o})`);return o}stepLogic(e,t,n,r){let o=this.ensure(this.actors,Math.max(n,1)*Fs*Y0),s=this.ensure(this.ops,Math.max(r.length,1)*Mk);this.views();let a=o>>>2,l=n*Fs;for(let d=0;d<l;d++)this.floats[a+d]=t[d];let c=this.exports.engine_stream_step_logic(e,o,n,s,r.length);if(c===Ic)return c;if(c<0)throw new _("capacity_exceeded",`world collider step failed (${c})`);this.views();let u=s>>>2;for(let d=0;d<c;d++)r[d]=this.words[u+d];return c}collider(e,t,n){let r=this.ensure(this.scratch,sh*Y0);if(this.exports.engine_stream_collider(e,t,r)<0)throw new _("unknown_resource",`world collider ${t} does not exist`);this.views();let s=r>>>2;for(let a=0;a<sh;a++)n[a]=this.floats[s+a];}close(e){vk(Vr),this.exports.engine_stream_close(e,this.render());for(let t of [this.eye,this.actors,this.ops,this.scratch])t.pointer!==Vr&&this.runtime.exports.engine_free(t.pointer,t.bytes,ce),t.pointer=Vr,t.bytes=0;}};var Xt={chunks:0,resident:1,requested:2,installed:3,evicted:4,deferred:5,failed:6,installedKib:7,residentSplats:8,drawnSplats:9,listedPages:10,poolCapacity:11,poolFreePages:12,tier:13,updates:14,heroSplats:15,heroShed:16,standIn:17,deformedSplats:18};var ZUe=["engine_splat_edit","engine_splat_bind","engine_splat_hero_budget","engine_splat_drape","engine_splat_motion_rows","engine_splat_motion"],eBe=["engine_splat_open","engine_splat_close","engine_splat_provide","engine_splat_fail","engine_splat_update","engine_splat_requests","engine_splat_set_transform","engine_splat_registers"],Wi=0,lJ=4,tBe=0,cJ=16,uJ=cJ+8*lJ,nBe=Math.max(3,3,14),rBe=uJ+nBe*lJ;function zf(i,e){if(e<0)throw new _("invalid_argument",`the engine refused the ${i} (${e})`)}var Dk=class{constructor(e,t,n,r){this.exports=e;this.render=t;this.stage=n;this.stageOwned=r;}edit(e,t,n){zf("splat edit",this.exports.engine_splat_edit(e,t,this.stage(n)));}bind(e,t){zf("splat rig",this.exports.engine_splat_bind(e,this.render(),t));}heroBudget(e,t){zf("hero budget",this.exports.engine_splat_hero_budget(e,t===null?Wi:this.stage(t)));}drape(e,t,n,r,o){let s=o===null?Wi:this.stageOwned(new Uint8Array(o.buffer,o.byteOffset,o.byteLength));zf("splat drape",this.exports.engine_splat_drape(e,t,n,r,s,o?.length??0));}motionRows(e){return this.exports.engine_splat_motion_rows(e)}motion(e,t,n,r,o){zf("splat motion",this.exports.engine_splat_motion(e,t,n===null?Wi:this.stage(n),r,o));}};function dJ(i){let e=i.symbols;return eBe.every(t=>typeof e[t]=="function")?e:null}var q0=class{constructor(e,t,n){this.runtime=e;this.exports=t;this.render=n;this.scratch=Wi;this.scratchBytes=0;this.live=0;this.buffer=null;this.floats=new Float32Array(0);this.words=new Uint32Array(0);this.bytes=new Uint8Array(0);let r=e.symbols;this.bodies=ZUe.every(o=>typeof r[o]=="function")?new Dk(r,n,o=>this.stageBody(o),o=>this.stage(o)):null;}stageBody(e){let t=this.ensureScratch()+uJ;this.views();let n=t>>>2;return e instanceof Float32Array?this.floats.set(e,n):this.words.set(e,n),t}views(){let e=this.runtime.memory.buffer;e!==this.buffer&&(this.buffer=e,this.floats=new Float32Array(e),this.words=new Uint32Array(e),this.bytes=new Uint8Array(e));}ensureScratch(){if(this.scratch!==Wi)return this.scratch;let e=Math.max(rBe,ce),t=this.runtime.exports.engine_alloc(e,ce);if(t===Wi)throw new _("capacity_exceeded","engine memory cannot hold scenery buffers");return this.scratch=t,this.scratchBytes=e,t}stage(e){let t=this.runtime.exports.engine_alloc(Math.max(e.byteLength,1),ce);if(t===Wi)throw new _("capacity_exceeded","engine memory cannot hold scenery data");return this.views(),this.bytes.set(e,t),t}open(e){this.ensureScratch();let t=this.exports.engine_splat_open(this.render(),this.stage(e),e.byteLength);if(t===Wi)throw new _("invalid_argument","the engine refused the scenery manifest");return this.live++,t}provide(e,t,n){return this.exports.engine_splat_provide(e,t,this.stage(n),n.byteLength)}fail(e,t){return this.exports.engine_splat_fail(e,t)}update(e,t,n){let r=this.ensureScratch()+tBe;this.views();let o=r>>>2;for(let c=0;c<3;c++)this.floats[o+c]=t[c];let s=this.exports.engine_splat_update(e,this.render(),r);if(s<=0)return s;let a=Math.min(s,n.length),l=this.exports.engine_splat_requests(e)>>>2;this.views();for(let c=0;c<a;c++)n[c]=this.words[l+c];return a}setTransform(e,t){let n=this.ensureScratch()+cJ;this.views();let r=n>>>2;for(let s=0;s<8;s++)this.floats[r+s]=t[s];let o=this.exports.engine_splat_set_transform(e,n);if(o<0)throw new _("invalid_argument",`the engine refused the scenery transform (${o})`)}registers(e){let t=this.exports.engine_splat_registers(e);if(t===Wi)throw new _("unknown_resource","scenery is closed");return this.views(),this.words.subarray(t>>>2,(t>>>2)+20)}close(e){this.exports.engine_splat_close(e,this.render()),this.live--,!(this.live>0||this.scratch===Wi)&&(this.runtime.exports.engine_free(this.scratch,this.scratchBytes,ce),this.scratch=Wi,this.scratchBytes=0);}};var aBe=["engine_terrain_open","engine_terrain_close","engine_terrain_update","engine_terrain_registers","engine_terrain_height","engine_terrain_normal","engine_terrain_sculpt","engine_terrain_colliders","engine_physics_radial_gravity","engine_terrain_grass","engine_terrain_wind","engine_terrain_interactors","engine_terrain_look","engine_terrain_scatter","engine_noise","engine_noise_fbm"],Us=0,Qf=4,lBe=3,cBe=3,uBe=4,Q0=Math.max(8,12,7,6,14,16,32,64)*2;function EJ(i){let e=i.symbols;return aBe.every(t=>typeof e[t]=="function")?e:null}var $0=class{constructor(e,t,n,r){this.runtime=e;this.exports=t;this.render=n;this.world=r;this.scratch={pointer:Us,bytes:0};this.second={pointer:Us,bytes:0};this.columns={pointer:Us,bytes:0};this.buffer=null;this.floats=new Float32Array(0);this.words=new Uint32Array(0);this.bytes=new Uint8Array(0);}views(){let e=this.runtime.memory.buffer;e!==this.buffer&&(this.buffer=e,this.floats=new Float32Array(e),this.words=new Uint32Array(e),this.bytes=new Uint8Array(e));}ensure(e,t){if(e.bytes>=t)return e.pointer;if(e.pointer!==Us&&this.runtime.exports.engine_free(e.pointer,e.bytes,ce),e.bytes=Math.max(t,ce),e.pointer=this.runtime.exports.engine_alloc(e.bytes,ce),e.pointer===Us)throw e.bytes=0,new _("capacity_exceeded","engine memory cannot hold terrain buffers");return e.pointer}put(e,t,n=t.length){let r=this.ensure(e,Math.max(Q0,n)*Qf);this.views();let o=r>>>2;for(let s=0;s<n;s++)this.floats[o+s]=t[s];return r}open(e,t,n,r){let o=this.put(this.scratch,e),s=this.put(this.second,n),a=Us;if(r!==null){if(a=this.runtime.exports.engine_alloc(Math.max(r.byteLength,1),ce),a===Us)throw new _("capacity_exceeded","engine memory cannot hold the terrain pack");this.views(),this.bytes.set(r,a);}let l=this.exports.engine_terrain_open(this.render(),o,t,s,a,r?.byteLength??0);if(l===Us)throw new _("invalid_argument","the engine refused the terrain description");return l}close(e){this.exports.engine_terrain_close(e,this.render());}update(e,t){return this.exports.engine_terrain_update(e,this.render(),this.put(this.scratch,t,6))}registers(e){let t=this.exports.engine_terrain_registers(e);if(t===Us)throw new _("unknown_resource","terrain is closed");return this.views(),this.words.subarray(t>>>2,(t>>>2)+8)}height(e,t){return this.exports.engine_terrain_height(this.render(),e,t)}normal(e,t,n){let r=this.ensure(this.second,Q0*Qf);if(this.exports.engine_terrain_normal(this.render(),e,t,r)<0)return false;this.views();let o=r>>>2;for(let s=0;s<lBe;s++)n[s]=this.floats[o+s];return true}sculpt(e,t){return this.exports.engine_terrain_sculpt(e,this.render(),this.put(this.scratch,t,7))}colliders(e,t,n,r){let o=this.ensure(this.second,Q0*Qf);this.views();let s=this.floats,a=o>>>2;return s[a]=t,s[a+1]=n,s[a+2]=r,this.exports.engine_terrain_colliders(e,this.render(),this.world(),o)}gravity(e,t,n,r,o){let s=this.ensure(this.second,Q0*Qf);this.views();let a=this.floats,l=s>>>2;return a[l]=e,a[l+1]=t,a[l+2]=n,a[l+cBe]=r,a[l+uBe]=o,this.exports.engine_physics_radial_gravity(this.world(),s)}grass(e){return this.exports.engine_terrain_grass(this.render(),this.put(this.scratch,e,14))}wind(e,t,n,r){this.exports.engine_terrain_wind(this.render(),e,t,n,r);}interactors(e,t){let n=Math.min(t,8);this.exports.engine_terrain_interactors(this.render(),this.put(this.scratch,e,n*4),n);}look(e,t){let n=Math.min(t,8);this.exports.engine_terrain_look(this.render(),this.put(this.scratch,e,n*8),n);}scatter(e,t,n){let r=this.put(this.scratch,e,16),o=this.ensure(this.columns,n*6*Qf),s=this.exports.engine_terrain_scatter(this.render(),r,o,n);if(s<0)throw new _("invalid_argument",`the engine refused the scatter rules (${s})`);return this.views(),t.set(this.floats.subarray(o>>>2,(o>>>2)+n*6)),s}noise(e,t,n,r,o){return this.exports.engine_noise(e,t,n,r,o)}fbm(e,t,n,r,o){return this.exports.engine_noise_fbm(e,t,n,r,o)}};var Bs=18,xJ=17,Oc=12,ah=19,vJ=18,al=64;var $f=8,Vk=6,ex=al*Vk,RJ=1;var dBe=["engine_fluid_caps","engine_fluid_create","engine_fluid_destroy","engine_fluid_parameters","engine_fluid_surface","engine_fluid_emitter","engine_fluid_colliders","engine_fluid_step","engine_fluid_pause","engine_fluid_clear","engine_fluid_count","engine_fluid_forces","engine_fluid_volume","engine_fluid_volume_info","engine_fluid_volumes_clear"],j0=0,J0=4,hBe=4,pBe=1e6,mBe=ah*al+ex;function SJ(i){let e=i.symbols;return dBe.every(t=>typeof e[t]=="function")?e:null}var Z0=class{constructor(e,t,n){this.runtime=e;this.exports=t;this.render=n;this.pointer=j0;this.buffer=null;this.floats=new Float32Array(0);this.caps=t.engine_fluid_caps();}scratch(){if(this.pointer===j0&&(this.pointer=this.runtime.exports.engine_alloc(mBe*J0,ce),this.pointer===j0))throw new _("capacity_exceeded","engine memory cannot hold fluid parameters");let e=this.runtime.memory.buffer;return e!==this.buffer&&(this.buffer=e,this.floats=new Float32Array(e)),this.pointer}put(e,t=e.length){let n=this.scratch();return this.floats.set(e.subarray(0,t),n>>>2),n}check(e,t){if(!(e>=0))throw new _("invalid_argument",`the engine refused the fluid ${t} (${e})`);return e}create(e,t){let n=this.put(e),r=n+Bs*J0;return this.floats.set(t,r>>>2),this.check(this.exports.engine_fluid_create(this.render(),n,r),"description")}destroy(e){this.exports.engine_fluid_destroy(this.render(),e);}parameters(e,t){this.check(this.exports.engine_fluid_parameters(this.render(),e,this.put(t)),"parameters");}surface(e,t){this.check(this.exports.engine_fluid_surface(this.render(),e,this.put(t)),"surface");}emitter(e,t,n){this.check(this.exports.engine_fluid_emitter(this.render(),e,t,this.put(n)),"emitter");}colliders(e,t,n){this.check(this.exports.engine_fluid_colliders(this.render(),e,this.put(t,n*ah),n),"colliders");}step(e,t){this.exports.engine_fluid_step(this.render(),e,Math.max(0,Math.round(t*pBe)));}pause(e,t){this.exports.engine_fluid_pause(this.render(),e,t?1:0);}clear(e){this.exports.engine_fluid_clear(this.render(),e);}count(e){return Math.max(0,this.exports.engine_fluid_count(this.render(),e))}forces(e,t){let n=this.scratch()+ah*al*J0;if(!(this.exports.engine_fluid_forces(this.render(),e,n)>=0))return;let r=n>>>2;for(let o=0;o<ex;o++)t[o]=this.floats[r+o];}volume(e,t,n,r,o){let s=Math.floor(t.length/3),a=Math.floor(n.length/3),l=s*3*J0,c=a*3*hBe,u=l+c,d=this.runtime.exports.engine_alloc(u,ce);if(d===j0)throw new _("capacity_exceeded","engine memory cannot hold the collider mesh");try{let h=this.runtime.memory.buffer;new Float32Array(h,d,s*3).set(t.subarray(0,s*3)),new Uint32Array(h,d+l,a*3).set(n.subarray(0,a*3));let p=this.check(this.exports.engine_fluid_volume(this.render(),e,d,s,d+l,a,r,o),"collider mesh"),m=this.scratch();this.check(this.exports.engine_fluid_volume_info(this.render(),e,p,m),"volume");let f=m>>>2,y=this.floats;return {index:p,half:[y[f+3],y[f+4],y[f+5]],centre:[y[f+6],y[f+7],y[f+8]]}}finally{this.runtime.exports.engine_free(d,u,ce);}}clearVolumes(e){this.exports.engine_fluid_volumes_clear(this.render(),e);}};var tx=8,fBe=9,Hk=5,TJ=4096,_Be=["engine_fracturer_open","engine_fracturer_close","engine_fracturer_run","engine_fracturer_asset","engine_fracturer_model","engine_fracturer_fragment"],ll=0,yBe=4,wJ=4,Yo=3,jf=2,IJ=3,ABe=.02,Wk=3,nx=6;function OJ(i){let e=i.symbols;return _Be.every(t=>typeof e[t]=="function")?e:null}var rx=class{constructor(e,t){this.runtime=e;this.exports=t;this.handle=ll;}allocate(e){let t=this.runtime.exports.engine_alloc(Math.max(e,wJ),ce);if(t===ll)throw new _("capacity_exceeded","engine memory cannot hold the mesh to break");return t}free(e,t){this.runtime.exports.engine_free(e,Math.max(t,wJ),ce);}fracture(e,t){let n=e.positions.length/Yo;if(!Number.isInteger(n)||e.indices.length%IJ!==0)throw new _("invalid_argument","fracture needs whole vertices and triangles");if(!(t.pieces>=1&&t.pieces<=TJ))throw new _("invalid_argument",`pieces must be between 1 and ${TJ}`);if(this.handle===ll&&(this.handle=this.exports.engine_fracturer_open(),this.handle===ll))throw new _("not_initialized","the engine could not open a fracturer");let r=new Float32Array(n*tx);for(let h=0;h<n;h++){let p=h*tx;for(let m=0;m<Yo;m++)r[p+m]=e.positions[h*Yo+m],r[p+Wk+m]=e.normals?.[h*Yo+m]??0;r[p+nx]=e.uvs?.[h*jf]??0,r[p+nx+1]=e.uvs?.[h*jf+1]??0;}let o=new Float32Array(fBe);o.set([t.pieces,t.seed??1,t.impact?1:0,t.impact?.[0]??0,t.impact?.[1]??0,t.impact?.[2]??0,t.focus??0,t.interiorUvScale??1,t.anchorHeight??ABe]);let s=r.byteLength,a=e.indices.byteLength,l=o.byteLength,c=this.allocate(s),u=this.allocate(a),d=this.allocate(l);try{new Float32Array(this.runtime.memory.buffer).set(r,c>>>2),new Uint32Array(this.runtime.memory.buffer).set(e.indices,u>>>2),new Float32Array(this.runtime.memory.buffer).set(o,d>>>2);let h=this.exports.engine_fracturer_run(this.handle,c,n,u,e.indices.length,d);if(!(h>=0))throw new _("invalid_argument",`the engine refused to break the mesh (${h}); it must be closed and finite`);return {asset:this.bytes(this.exports.engine_fracturer_asset,"fracture asset"),model:this.bytes(this.exports.engine_fracturer_model,"fracture model"),pieces:Array.from({length:h},(p,m)=>this.piece(m))}}finally{this.free(c,s),this.free(u,a),this.free(d,l);}}bytes(e,t){let n=e(this.handle,ll,0);if(!(n>=0))throw new _("invalid_argument",`${t} refused (${n})`);let r=this.allocate(n);try{return e(this.handle,r,n),new Uint8Array(this.runtime.memory.buffer,r,n).slice()}finally{this.free(r,n);}}piece(e){let t=this.exports.engine_fracturer_fragment(this.handle,e,ll,0);if(!(t>=Hk))throw new _("invalid_argument",`fracture piece refused (${t})`);let n=t*yBe,r=this.allocate(n);try{this.exports.engine_fracturer_fragment(this.handle,e,r,t);let o=new Float32Array(this.runtime.memory.buffer,r,t).slice(),s=o[0],a=(t-Hk)/tx,l=new Float32Array(a*Yo),c=new Float32Array(a*Yo),u=new Float32Array(a*jf),d=new Uint32Array(a);for(let h=0;h<a;h++){let p=Hk+h*tx;l.set(o.subarray(p,p+Yo),h*Yo),c.set(o.subarray(p+Wk,p+Wk+Yo),h*Yo),u.set(o.subarray(p+nx,p+nx+jf),h*jf),d[h]=h;}return {centroid:[o[2],o[3],o[4]],positions:l,normals:c,uvs:u,indices:d,interiorStart:s*IJ}}finally{this.free(r,n);}}dispose(){this.handle!==ll&&(this.exports.engine_fracturer_close(this.handle),this.handle=ll);}};var Kk=24,bBe=5,CJ=8,NJ=1,kJ=2,LJ=3,MJ=4,gBe=["engine_destruction_open","engine_destruction_close","engine_destructible_create","engine_destructible_destroy","engine_destructible_damage","engine_destructible_attached","engine_destruction_update","engine_destruction_events","engine_destruction_dropped"];var EBe=8,xBe=0,vBe=1,RBe=2,SBe=3,TBe=4,wBe=5,DJ=5;var Ki=0,IBe=4,OBe=1e6;function PJ(i){let e=i.symbols;return gBe.every(t=>typeof e[t]=="function")?e:null}var ix=class{constructor(e,t,n){this.runtime=e;this.exports=t;this.world=n;this.handle=Ki;this.scratch=Ki;this.fracturer=null;this.buffer=null;this.words=new Uint32Array(0);this.floats=new Float32Array(0);this.bytes=new Uint8Array(0);this.events={words:this.words,floats:this.floats,offset:0,count:0};}views(){let e=this.runtime.memory.buffer;e!==this.buffer&&(this.buffer=e,this.words=new Uint32Array(e),this.floats=new Float32Array(e),this.bytes=new Uint8Array(e),this.events.words=this.words,this.events.floats=this.floats);}open(){if(this.handle===Ki){if(this.handle=this.exports.engine_destruction_open(this.world()),this.handle===Ki)throw new _("not_initialized","destruction needs an engine physics world");if(this.scratch=this.runtime.exports.engine_alloc(Math.max(Kk,bBe)*IBe,ce),this.scratch===Ki)throw new _("capacity_exceeded","engine memory cannot hold destruction parameters")}return this.handle}allocate(e){let t=this.runtime.exports.engine_alloc(Math.max(e,4),ce);if(t===Ki)throw new _("capacity_exceeded","engine memory cannot hold the fracture asset");return t}create(e,t,n,r){let o=this.open(),s=this.allocate(e.byteLength),a=this.allocate(t.byteLength);this.views(),this.bytes.set(e,s),this.words.set(t,a>>>2),this.floats.set(r,this.scratch>>>2);let l=this.exports.engine_destructible_create(o,this.world(),s,e.byteLength,a,t.length,n,this.scratch);if(this.runtime.exports.engine_free(s,Math.max(e.byteLength,4),ce),this.runtime.exports.engine_free(a,Math.max(t.byteLength,4),ce),!(l>=0))throw new _("invalid_argument",`the engine refused the destructible (${l}); check the fracture asset and that every entity has a transform`);return l}destroy(e){this.handle!==Ki&&this.exports.engine_destructible_destroy(this.handle,this.world(),e);}configure(e,t){let n=this.open(),r=this.runtime.symbols.engine_destructible_configure;if(typeof r!="function")throw new _("unsupported_feature","structural destruction needs an engine with feature destruction_2");this.views();let o=this.scratch>>>2;this.floats.fill(0,o,o+EBe),this.floats[o+xBe]=t.propagation??0,this.floats[o+vBe]=t.bondStrength,this.floats[o+RBe]=t.stress?1:0,this.floats[o+SBe]=t.clusters?1:0,this.floats[o+TBe]=t.levels??0,this.floats[o+wBe]=t.levelStrength??1;let s=r(n,this.world(),e,this.scratch);if(!(s>=0))throw new _("invalid_argument",`the engine refused the structure (${s}); configure before any damage, with bondStrength above 0 for stress or clusters`)}damage(e,t,n,r,o,s){let a=this.open();this.views();let l=this.scratch>>>2;this.floats[l]=t,this.floats[l+1]=n,this.floats[l+2]=r,this.floats[l+3]=o,this.floats[l+4]=s;let c=this.exports.engine_destructible_damage(a,e,this.scratch);if(!(c>=0))throw new _("invalid_argument",`damage refused (${c})`);return c}attached(e){if(this.handle===Ki)return 0;let t=this.exports.engine_destructible_attached(this.handle,e);if(!(t>=0))throw new _("invalid_argument",`attached refused (${t})`);return t}update(e){if(this.events.count=0,this.handle===Ki)return this.events;let t=this.exports.engine_destruction_update(this.handle,this.world(),Math.max(0,Math.round(e*OBe)));if(!(t>=0))throw new _("invalid_argument",`destruction update refused (${t})`);return t===0?this.events:(this.views(),this.events.offset=this.exports.engine_destruction_events(this.handle)>>>2,this.events.count=t,this.events)}fracture(e,t){if(this.fracturer===null){let n=OJ(this.runtime);if(n===null)throw new _("unsupported_feature","breaking a made thing needs an engine with live fracture");this.fracturer=new rx(this.runtime,n);}return this.fracturer.fracture(e,t)}dispose(){this.fracturer?.dispose(),this.fracturer=null,this.handle!==Ki&&(this.exports.engine_destruction_close(this.handle),this.handle=Ki);}};var lh=32,GJ=0,sx=3,VJ=6,HJ=7,WJ=8,KJ=9,YJ=10,XJ=11,qJ=12,zJ=13,QJ=14,$J=16,Xk=4,jJ=20,JJ=21,ZJ=22,eZ=23,tZ=24,qk=12,zk=0,Qk=2,nZ=4,rZ=5,iZ=6,oZ=7,sZ=8,aZ=9,lZ=10,cZ=11,CBe=96,uZ=0,dZ=1;var hZ=3,pZ=4;var mZ=7,fZ=8,$k=9,_Z=10,yZ=11,AZ=12,bZ=13,gZ=14,ax=15,NBe=16,kBe=17;var EZ=21,xZ=22,LBe=23,vZ=32,RZ=8,SZ=8,TZ=0,wZ=3,IZ=4,lx=5,OZ=4096,jk=.1,Jf=64,MBe=["engine_reactive_create","engine_reactive_destroy","engine_reactive_registers","engine_reactive_hob","engine_reactive_lit","engine_reactive_emitter","engine_reactive_preheat","engine_reactive_step","engine_reactive_media","engine_reactive_texels","engine_reactive_positions","engine_reactive_digest"],Gs=0,Yk=4,FJ=0,DBe=3,CZ=new Float32Array(1),PBe=new Uint32Array(CZ.buffer),FBe=32n,UBe=lh+Bs+Oc,UJ=lh,BJ=lh+Bs;function NZ(i){let e=i.symbols;return MBe.every(t=>typeof e[t]=="function")?e:null}function BBe(i,e){throw i===-1?new _("capacity_exceeded",`the engine has no room for the reactive fluid ${e}`):i===-3?new _("unknown_resource",`the reactive fluid ${e} names an unknown material or a missing hob`):new _("invalid_argument",`the engine refused the reactive fluid ${e} (${i})`)}function Cc(i,e){return i>=0?i:BBe(i,e)}var ox=class{constructor(e,t,n){this.runtime=e;this.exports=t;this.render=n;this.scratch=Gs;this.buffer=null;this.words=new Uint32Array(0);this.floats=new Float32Array(0);this.registerViews=new Map;this.texelViews=new Map;this.positionViews=new Map;}views(){let e=this.runtime.memory.buffer;e!==this.buffer&&(this.buffer=e,this.words=new Uint32Array(e),this.floats=new Float32Array(e));}at(){if(this.scratch===Gs&&(this.scratch=this.runtime.exports.engine_alloc(UBe*Yk,ce),this.scratch===Gs))throw new _("capacity_exceeded","engine memory cannot hold reactive fluid parameters");return this.views(),this.scratch>>>2}open(e,t,n){let r=this.at();this.words.set(n.subarray(0,lh),r),this.floats.set(t.subarray(0,Bs),r+UJ);let o=this.exports.engine_reactive_create(e,this.scratch+UJ*Yk,this.scratch);if(o===Gs)throw new _("invalid_argument","the engine refused this reactive fluid (check the liquid, the grids and the contact radius)");return o}registers(e){this.views();let t=this.registerViews.get(e);if(t!==void 0&&t.buffer===this.buffer)return t;let n=this.exports.engine_reactive_registers(e);if(n===Gs)throw new _("unknown_resource","this reactive fluid was disposed");let r=new Uint32Array(this.words.buffer,n,CBe);return this.registerViews.set(e,r),r}hob(e,t){let n=this.at();this.words.set(t.subarray(0,qk),n),Cc(this.exports.engine_reactive_hob(e,this.scratch),"hob");}lit(e,t){Cc(this.exports.engine_reactive_lit(e,t?1:0),"burner");}emitter(e,t,n){let r=this.at();this.floats.set(n.subarray(0,Oc),r+BJ),Cc(this.exports.engine_reactive_emitter(e,t,this.scratch+BJ*Yk),"pour");}preheat(e,t,n){return Cc(this.exports.engine_reactive_preheat(e,t,n),"preheat")}step(e,t,n){CZ[0]=t,this.registers(e)[LBe]=PBe[0],Cc(this.exports.engine_reactive_step(e,n?1:0),"step");}media(e,t){let n=t===FJ?Gs:this.render();if(t!==FJ&&n===Gs)throw new _("unsupported_feature","writing a media volume needs the engine renderer");return Cc(this.exports.engine_reactive_media(e,n,t),"media volume")}texels(e,t){this.views();let n=this.texelViews.get(e);if(n!==void 0&&n.buffer===this.buffer)return n;let r=this.exports.engine_reactive_texels(e);if(r===Gs)throw new _("unknown_resource","this reactive fluid was disposed");let o=new Uint32Array(this.words.buffer,r,t);return this.texelViews.set(e,o),o}positions(e,t){let n=this.exports.engine_reactive_positions(e);if(n===Gs)throw new _("unknown_resource","this reactive fluid was disposed");this.views();let r=this.positionViews.get(e);if(r!==void 0&&r.buffer===this.buffer&&r.byteOffset===n)return r;let o=new Float32Array(this.floats.buffer,n,t*DBe);return this.positionViews.set(e,o),o}digest(e){Cc(this.exports.engine_reactive_digest(e),"digest");let t=this.registers(e);return BigInt(t[kBe])<<FBe|BigInt(t[NBe])}close(e){this.registerViews.delete(e),this.texelViews.delete(e),this.positionViews.delete(e),this.exports.engine_reactive_destroy(e);}};var ch=24,kZ=11,cl=14,e_=11,t_=8,GBe=3,VBe="engine_smoke_emitters_tinted",HBe="engine_smoke_follow",WBe=1e6,KBe=1e5,YBe=["engine_smoke_create","engine_smoke_destroy","engine_smoke_emitters","engine_smoke_step"],cx=0,LZ=4,XBe=-1,qBe=-3,zBe=1,QBe=ch+t_*cl,MZ=ch;function $Be(i,e){for(let t=0;t<e;t++)for(let n=0;n<GBe;n++)if(i[t*cl+e_+n]!==zBe)return true;return false}function DZ(i){let e=i.symbols;return YBe.every(t=>typeof e[t]=="function")?e:null}function Zf(i,e){if(i>=0)return i;throw i===XBe?new _("capacity_exceeded",`the engine has no room for the smoke ${e}`):i===qBe?new _("unknown_resource",`the smoke ${e} names a disposed smoke volume or a missing medium`):new _("invalid_argument",`the engine refused the smoke ${e} (${i})`)}var ux=class{constructor(e,t,n){this.runtime=e;this.exports=t;this.render=n;this.scratch=cx;this.buffer=null;this.floats=new Float32Array(0);}at(){if(this.scratch===cx&&(this.scratch=this.runtime.exports.engine_alloc(QBe*LZ,ce),this.scratch===cx))throw new _("capacity_exceeded","engine memory cannot hold smoke parameters");let e=this.runtime.memory.buffer;return e!==this.buffer&&(this.buffer=e,this.floats=new Float32Array(e)),this.scratch>>>2}renderHandle(){let e=this.render();if(e===cx)throw new _("unsupported_feature","smoke volumes need the engine renderer");return e}create(e,t){let n=this.at();return this.floats.set(e.subarray(0,ch),n),Zf(this.exports.engine_smoke_create(this.renderHandle(),this.scratch,t),"description")}emitters(e,t,n){let r=this.at()+MZ,o=this.scratch+MZ*LZ,s=this.runtime.symbols[VBe];if(typeof s=="function"){this.floats.set(t.subarray(0,n*cl),r),Zf(s(this.renderHandle(),e,o,n),"emitters");return}if($Be(t,n))throw new _("unsupported_feature","tinted flames need an engine with smoke emitter tints");for(let a=0;a<n;a++)this.floats.set(t.subarray(a*cl,a*cl+kZ),r+a*kZ);Zf(this.exports.engine_smoke_emitters(this.renderHandle(),e,o,n),"emitters");}follow(e,t,n,r){let o=this.runtime.symbols[HBe];if(typeof o!="function")throw new _("unsupported_feature","a smoke volume that follows a moving thing needs an engine with smoke follow");let s=this.at();this.floats[s]=t,this.floats[s+1]=n,this.floats[s+2]=r,Zf(o(this.renderHandle(),e,this.scratch),"follow");}step(e,t){let n=Math.min(Math.max(Math.round(t*WBe),0),KBe);return Zf(this.exports.engine_smoke_step(this.renderHandle(),e,n),"step")}destroy(e){this.exports.engine_smoke_destroy(this.renderHandle(),e);}};var PZ=20,BZ=0,GZ=1,VZ=2,HZ=4,WZ=6,Jk=8,KZ=9,Zk=10;var eL=12,YZ=14,XZ=15,jBe=16,JBe=1024,qZ=1,zZ=2,tL=4,uh=3,nL=8,kc=64,QZ=8,rL=255,n_=4294967295,$Z=1,jZ=2,JZ=3,ZZ=4,eee=5,tee=6,nee=7,ree=8,iee=1,oee=2,see=3,ZBe=["engine_story_create","engine_story_destroy","engine_story_registers","engine_story_events","engine_story_samples","engine_story_start","engine_story_step","engine_story_seek","engine_story_available","engine_story_variable","engine_story_get","engine_story_set","engine_story_set_text","engine_story_variable_text","engine_story_program_text","engine_story_text_index","engine_story_text_of","engine_story_id_of"],FZ=17,aee=4,iL=0,oL=1,sL=2,aL=3,lee=4,lL=5,cL=6,uL=7,Nc=0,dx=1,e4e=-1,hx=-3,t4e=-4,n4e=8,cee=4,r4e=kc*uh*cee,UZ=4096,i4e=32n;function uee(i){let e=i.symbols;return ZBe.every(t=>typeof e[t]=="function")?e:null}function Ai(i,e){if(i>=0)return i;throw i===e4e?new _("capacity_exceeded",`the story ${e} is too large`):i===hx?new _("unknown_resource",`the story ${e} names nothing in this story`):i===t4e?new _("invalid_argument",`the engine refused the story ${e}`):new _("invalid_argument",`the engine refused the story ${e} (${i})`)}var px=class{constructor(e,t){this.runtime=e;this.exports=t;this.inputs=Nc;this.text=Nc;this.textBytes=0;this.encoder=new TextEncoder;this.decoder=new TextDecoder;}alloc(e,t){let n=this.runtime.exports.engine_alloc(e,t);if(n===Nc)throw new _("capacity_exceeded","engine memory cannot hold the story's working space");return n}textScratch(e){return e>this.textBytes&&(this.text!==Nc&&this.runtime.exports.engine_free(this.text,this.textBytes,dx),this.textBytes=Math.max(e,UZ),this.text=this.alloc(this.textBytes,dx)),this.text}bytes(){return new Uint8Array(this.runtime.memory.buffer)}create(e){let t=this.alloc(Math.max(e.length,1),dx);try{this.bytes().set(e,t);let n=this.exports.engine_story_create(t,e.length);if(n===Nc)throw new _("invalid_argument","the engine refused the story program");return n}finally{this.runtime.exports.engine_free(t,Math.max(e.length,1),dx);}}destroy(e){this.exports.engine_story_destroy(e);}start(e){Ai(this.exports.engine_story_start(e),"start");}step(e,t,n){if(n>kc)throw new _("capacity_exceeded",`a story step takes at most ${kc} inputs`);this.inputs===Nc&&(this.inputs=this.alloc(r4e,cee)),n>0&&new Uint32Array(this.runtime.memory.buffer,this.inputs,n*uh).set(t.subarray(0,n*uh)),Ai(this.exports.engine_story_step(e,this.inputs,n),"step");}seek(e,t){Ai(this.exports.engine_story_seek(e,Math.round(t)),"seek");}available(e,t){return Ai(this.exports.engine_story_available(e,t),"choice")===1}variable(e,t){return Ai(this.exports.engine_story_variable(e,t),"variable")}get(e,t){return this.exports.engine_story_get(e,t)}set(e,t,n){Ai(this.exports.engine_story_set(e,t,n),"variable value");}setText(e,t,n){let r=this.encoder.encode(n),o=this.textScratch(r.length);this.bytes().set(r,o),Ai(this.exports.engine_story_set_text(e,t,o,r.length),"variable text");}readText(e,t){let n=Ai(e(this.textScratch(UZ),this.textBytes),t);return n>this.textBytes&&(n=Ai(e(this.textScratch(n),this.textBytes),t)),this.decoder.decode(this.bytes().subarray(this.text,this.text+n))}variableText(e,t){return this.readText((n,r)=>this.exports.engine_story_variable_text(e,t,n,r),"variable text")}programText(e,t){return this.readText((n,r)=>this.exports.engine_story_program_text(e,t,n,r),"text")}textIndex(e,t){let n=this.encoder.encode(t),r=this.textScratch(n.length);this.bytes().set(n,r);let o=this.exports.engine_story_text_index(e,r,n.length);return o===hx?n_:Ai(o,"text")}textOf(e,t,n,r){let o=this.exports.engine_story_text_of(e,t,n,r);return o===hx?n_:Ai(o,"text")}idOf(e,t,n){let r=this.exports.engine_story_id_of(e,t,n);if(r===hx)return null;Ai(r,"id");let o=new Uint32Array(this.runtime.memory.buffer,this.exports.engine_story_registers(e),PZ);return (BigInt(o[FZ+1])<<i4e|BigInt(o[FZ])).toString()}buffer(){return this.runtime.memory.buffer}views(e){let t=this.runtime.memory.buffer,n=new Uint32Array(t,this.exports.engine_story_registers(e),PZ),r=this.exports.engine_story_samples(e);if(r%n4e!==0)throw new _("invalid_argument","the engine's story samples are misaligned");return {registers:n,events:new Uint32Array(t,this.exports.engine_story_events(e),JBe*tL),samples:r===Nc?new Float64Array(0):new Float64Array(t,r,n[jBe]*nL)}}};var o4e="engine_export_arity",s4e="engine_export_prototype_of",a4e=8,dee=64,l4e=0,hee=0;function pee(i,e){let t=i.exports.engine_alloc(dee,a4e);if(t===l4e)throw new _("capacity_exceeded","engine memory cannot hold an export name");return n=>{let r=new Uint8Array(i.memory.buffer,t,dee);for(let o=0;o<n.length;o++)r[o]=n.charCodeAt(o);return e(t,n.length)}}function c4e(i){let e=i.symbols,t=e[o4e];return typeof t=="function"?pee(i,t):n=>{let r=e[n];return typeof r=="function"?r.length:-1}}function u4e(i){let e=i.symbols[s4e];return typeof e=="function"?pee(i,e):null}function d4e(i,e,t=null){let n=[];for(let r in Hw){if(typeof i[r]!="function")continue;let o=Hw[r],s=e(r);if(s!==o){n.push(`${r} takes ${s<0?"an unknown number of":s} arguments, this package expects ${o}`);continue}let a=t?.(r)??hee;a!==hee&&a!==rB[r]&&n.push(`${r} has another prototype than this package expects`);}return n}function mee(i){let e=d4e(i.symbols,c4e(i),u4e(i));if(e.length>0)throw new _("engine_mismatch",`this package was built for a different engine; rebuild it or update the app (${e.length} exports differ: ${e.slice(0,3).join("; ")})`)}var h4e="cimplify-engine",p4e="engine_core@0.1.0+rapier3d@0.36.0+three@0.186.1";function _ee(i,e){let t=e?_4e(e,i.assets??null):null;if(t)return t;let n=i.assets??null,r=e&&i.audioWorklet?fee(e,i.audioWorklet,n):null;if(r)return r;if(i.audio)return i.audio;let o=i.audioContext??e?.audioContext?.()??null,s=i.audioWorklet===null?null:m4e(e,o),a=e&&s?fee(e,s,n):null;return a||(o?new wg(o):new Tg)}function m4e(i,e){e?.audioWorklet;return null}function f4e(i){return {exports:i.symbols,memory:i.memory,allocate:e=>i.exports.engine_alloc(e,ce),release:(e,t)=>i.exports.engine_free(e,t,ce)}}function fee(i,e,t){let n=i.symbols;if([...rC.filter(a=>a!=="engine_audio_bound"),...KY].some(a=>typeof n[a]!="function"))return null;let o=f4e(i),s=Rg.create(o,e);return new ld({...o,decode:i.decodeAudio??null,assets:t,handle:s.handle,relay:s})}function _4e(i,e){let t=i.symbols;if(rC.some(r=>typeof t[r]!="function"))return null;let n=t;return n.engine_audio_bound()===0?null:new ld({exports:n,memory:i.memory,allocate:r=>i.exports.engine_alloc(r,ce),release:(r,o)=>i.exports.engine_free(r,o,ce),decode:i.decodeAudio??null,assets:e})}function yee(i,e,t){mee(i);let n=new Og(i),r=new W0(i,n),o=e(i),s=new F0(r);return o instanceof dr&&s.craft?.bindRender?.(()=>o.renderHandle),t instanceof ld&&t.bindOcclusionWorld(()=>r.world),OQ(IQ(i.symbols,i.memory)),{name:h4e,version:p4e,memory:n,transforms:new K0(r),physics:s,graphics:o,audio:t,nav:w4e(i),ai:MQ(i,()=>r.world),streaming:S4e(i,o),scenery:T4e(i,o),terrain:R4e(i,o,()=>r.world),soa:Cg(i.symbols,i.memory),kernels:TQ(i.symbols,i.memory),chemistry:wQ(i.symbols,i.memory),fluids:x4e(i,o),destruction:v4e(i,()=>r.world),softBodies:E4e(i,o,()=>r.world),reactive:g4e(i,o),cloths:b4e(i,o,()=>r.world),smoke:A4e(i,o),story:y4e(i)}}function y4e(i){let e=uee(i);return e!==null?new px(i,e):null}function A4e(i,e){let t=DZ(i);return t!==null&&e instanceof dr?new ux(i,t,()=>e.renderHandle):null}function b4e(i,e,t){let n=R$(i);if(n===null)return null;let r=e instanceof dr?()=>e.renderHandle:()=>0;return new S0(i,n,r,t)}function g4e(i,e){let t=NZ(i);if(t===null)return null;let n=e instanceof dr?()=>e.renderHandle:()=>0;return new ox(i,t,n)}function E4e(i,e,t){let n=q$(i);if(n===null)return null;let r=e instanceof dr?()=>e.renderHandle:()=>0;return new I0(i,n,r,t)}function x4e(i,e){let t=SJ(i);return t!==null&&e instanceof dr?new Z0(i,t,()=>e.renderHandle):null}function v4e(i,e){let t=PJ(i);return t!==null?new ix(i,t,e):null}function R4e(i,e,t){let n=EJ(i);return n!==null&&e instanceof dr?new $0(i,n,()=>e.renderHandle,t):null}function S4e(i,e){let t=aJ(i);return t!==null&&e instanceof dr?new X0(i,t,()=>e.renderHandle):null}function T4e(i,e){let t=dJ(i);return t!==null&&e instanceof dr?new q0(i,t,()=>e.renderHandle):null}function w4e(i){let e=GQ(i.symbols);return e?new f0(i,e):null}var Hr={InQuad:1,OutQuad:2,InOutQuad:3,InCubic:4,OutCubic:5,InOutCubic:6,OutBack:7,OutElastic:8,OutBounce:9,InSine:10,OutSine:11,InOutSine:12,OutExpo:13},Aee=1.70158,I4e=2*Math.PI/3,dL=10,O4e=.75,mx=7.5625,dh=2.75,bee=2;function gee(i,e,t){let n=e[t];if(n<=0){e[t]=0;return}if(n>=1){e[t]=1;return}let r;switch(i){case Hr.InQuad:e[t]=n*n;return;case Hr.OutQuad:e[t]=n*(2-n);return;case Hr.InOutQuad:e[t]=n<.5?2*n*n:-1+(4-2*n)*n;return;case Hr.InCubic:e[t]=n*n*n;return;case Hr.OutCubic:r=n-1,e[t]=r*r*r+1;return;case Hr.InOutCubic:e[t]=n<.5?4*n*n*n:(n-1)*(2*n-2)*(2*n-2)+1;return;case Hr.OutBack:r=n-1,e[t]=1+(Aee+1)*r*r*r+Aee*r*r;return;case Hr.OutElastic:e[t]=Math.pow(bee,-dL*n)*Math.sin((n*dL-O4e)*I4e)+1;return;case Hr.OutBounce:n<1/dh?e[t]=mx*n*n:n<2/dh?(r=n-1.5/dh,e[t]=mx*r*r+.75):n<2.5/dh?(r=n-2.25/dh,e[t]=mx*r*r+.9375):(r=n-2.625/dh,e[t]=mx*r*r+.984375);return;case Hr.InSine:e[t]=1-Math.cos(n*Math.PI/2);return;case Hr.OutSine:e[t]=Math.sin(n*Math.PI/2);return;case Hr.InOutSine:e[t]=-(Math.cos(Math.PI*n)-1)/2;return;case Hr.OutExpo:e[t]=1-Math.pow(bee,-dL*n);return;default:return}}var hL=0,Lc=1,Yi=2,Eee=3,L4e=4,en={PositionX:0,PositionY:1,PositionZ:2,ScaleX:3,ScaleY:4,ScaleZ:5,ScaleUniform:6,Rotation:7,Value:8},ul={Once:0,Loop:1,PingPong:2},mL=16,pL=(1<<mL)-1,M4e=32767,D4e=-1;var fx=class{constructor(e,t,n={}){this.tweenHigh=0;this.valueCount=0;this.registers=new Float64Array(L4e);this.transforms=t;let r=n.maxTweens??1024;if(r>pL)throw new _("invalid_argument","too many tweens");this.tweenCapacity=r,this.tweenActive=new Uint8Array(r),this.tweenGeneration=new Uint16Array(r),this.tweenTarget=new Uint8Array(r),this.tweenEase=new Uint8Array(r),this.tweenRepeat=new Uint8Array(r),this.tweenEntity=new Uint32Array(r),this.tweenSlot=new Int32Array(r),this.tweenFrom=new Float32Array(r*4),this.tweenTo=new Float32Array(r*4),this.tweenDuration=new Float32Array(r),this.tweenElapsed=new Float32Array(r),this.tweenDelay=new Float32Array(r),this.tweenFree=new Uint16Array(r),this.tweenFreeCount=0,this.values=new Float32Array(n.maxValueSlots??256);let o=n.maxClipPlayers??256;this.clips=Array.from({length:o},()=>null),this.clipEntity=new Uint32Array(o).fill(4294967295),this.clipTime=new Float32Array(o),this.clipSpeed=new Float32Array(o),this.clipRepeat=new Uint8Array(o),e.onDespawn(this);}createValue(e=0){if(this.valueCount>=this.values.length)throw new _("capacity_exceeded","animation value slots exhausted");let t=this.valueCount++;return this.values[t]=e,t}value(e){return this.values[e]}setValue(e,t){this.values[e]=t;}tween(e,t,n,r,o,s=0,a=ul.Once){let l=this.allocTween(t,o,r,s,a);return this.tweenEntity[l]=e,this.loadScalar(e,t),this.tweenFrom[l*4]=this.registers[Yi],this.tweenTo[l*4]=n,this.handle(l)}tweenValue(e,t,n,r,o=0,s=ul.Once){let a=this.allocTween(en.Value,r,n,o,s);return this.tweenSlot[a]=e,this.tweenFrom[a*4]=this.values[e],this.tweenTo[a*4]=t,this.handle(a)}tweenRotation(e,t,n,r,o=0,s=ul.Once){let a=this.allocTween(en.Rotation,r,n,o,s);this.tweenEntity[a]=e;let l=this.transforms.row(e),c=this.transforms.store.fields.rotation,u=a*4;for(let d=0;d<4;d++)this.tweenFrom[u+d]=c[l*4+d];return t.writeTo(this.tweenTo,u),this.handle(a)}isActive(e){let t=e&pL;return this.tweenActive[t]===1&&this.tweenGeneration[t]===e>>>mL}cancel(e){this.isActive(e)&&this.releaseTween(e&pL);}playClip(e,t,n=ul.Once,r=1){for(let o=0;o<this.clips.length;o++)if(this.clips[o]===null)return this.clips[o]=t,this.clipEntity[o]=e,this.clipTime[o]=0,this.clipSpeed[o]=r,this.clipRepeat[o]=n,o;throw new _("capacity_exceeded","clip players exhausted")}stopClip(e){this.clips[e]=null,this.clipEntity[e]=4294967295;}isClipPlaying(e){return this.clips[e]!==null}onDespawn(e){for(let t=0;t<this.tweenHigh;t++)this.tweenActive[t]===1&&this.tweenEntity[t]===e&&this.tweenTarget[t]!==en.Value&&this.releaseTween(t);for(let t=0;t<this.clips.length;t++)this.clipEntity[t]===e&&this.stopClip(t);}update(e){this.registers[hL]=e.values[ai];for(let t=0;t<this.tweenHigh;t++)this.tweenActive[t]===1&&this.advanceTween(t);for(let t=0;t<this.clips.length;t++){let n=this.clips[t];n!==null&&this.advanceClip(t,n);}}handle(e){return this.tweenGeneration[e]<<mL|e}allocTween(e,t,n,r,o){let s;if(this.tweenFreeCount>0)s=this.tweenFree[--this.tweenFreeCount];else if(this.tweenHigh<this.tweenCapacity)s=this.tweenHigh++;else throw new _("capacity_exceeded","tween pool exhausted");return this.tweenActive[s]=1,this.tweenTarget[s]=e,this.tweenEase[s]=t,this.tweenRepeat[s]=o,this.tweenDuration[s]=n>0?n:Number.MIN_VALUE,this.tweenElapsed[s]=0,this.tweenDelay[s]=r,this.tweenSlot[s]=D4e,this.tweenEntity[s]=4294967295,s}releaseTween(e){this.tweenActive[e]=0,this.tweenGeneration[e]=this.tweenGeneration[e]+1&M4e,this.tweenFree[this.tweenFreeCount++]=e;}advanceTween(e){let t=this.registers,n=t[hL];if(this.tweenDelay[e]>0){if(this.tweenDelay[e]-=n,this.tweenDelay[e]>0)return;n=-this.tweenDelay[e],this.tweenDelay[e]=0,this.tweenTarget[e]!==en.Value&&this.tweenTarget[e]!==en.Rotation&&(this.loadScalar(this.tweenEntity[e],this.tweenTarget[e]),this.tweenFrom[e*4]=t[Yi]);}let r=this.tweenDuration[e],o=this.tweenElapsed[e]+n,s=false,a=this.tweenRepeat[e];o>=r&&(a===ul.Once?(o=r,s=true):a===ul.Loop?o%=r:o%=r*2),this.tweenElapsed[e]=o;let l=o/r;a===ul.PingPong&&l>1&&(l=2-l),t[Lc]=l,gee(this.tweenEase[e],t,Lc);let c=this.applyTween(e);(s||!c)&&this.releaseTween(e);}applyTween(e){let t=this.registers,n=t[Lc],r=e*4,o=this.tweenTarget[e];if(o===en.Value)return this.values[this.tweenSlot[e]]=this.tweenFrom[r]+(this.tweenTo[r]-this.tweenFrom[r])*n,true;let s=this.tweenEntity[e],a=this.transforms.store.row(s);return a===-1?false:o===en.Rotation?(Kb(this.transforms.store.fields.rotation,a*4,this.tweenFrom,r,this.tweenTo,r,t,Lc),true):(t[Yi]=this.tweenFrom[r]+(this.tweenTo[r]-this.tweenFrom[r])*n,this.writeScalar(a,o),true)}advanceClip(e,t){let n=this.registers,r=this.clipTime[e]+n[hL]*this.clipSpeed[e],o=false;r>=t.duration&&(this.clipRepeat[e]===ul.Once?(r=t.duration,o=true):r%=t.duration),this.clipTime[e]=r,n[Eee]=r;let s=this.transforms.store.row(this.clipEntity[e]);if(s===-1){this.stopClip(e);return}for(let a=0;a<t.tracks.length;a++)this.sampleTrack(t.tracks[a],s);o&&this.stopClip(e);}sampleTrack(e,t){let n=this.registers,r=n[Eee],o=e.times,s=e.values,a=o.length-1,l=0,c=a;if(r<=o[0])c=0;else if(r>=o[a])l=a;else for(;c-l>1;){let p=l+c>>>1;o[p]<=r?l=p:c=p;}let u=Math.min(l,c),d=Math.max(l,c),h=o[d]-o[u];if(n[Lc]=h>0?(r-o[u])/h:0,e.target===en.Rotation){Kb(this.transforms.store.fields.rotation,t*4,s,u*4,s,d*4,n,Lc);return}n[Yi]=s[u]+(s[d]-s[u])*n[Lc],this.writeScalar(t,e.target);}loadScalar(e,t){let n=this.transforms.row(e),r=this.transforms.store.fields,o=n*3,s=this.registers;switch(t){case en.PositionX:s[Yi]=r.position[o];return;case en.PositionY:s[Yi]=r.position[o+1];return;case en.PositionZ:s[Yi]=r.position[o+2];return;case en.ScaleX:case en.ScaleUniform:s[Yi]=r.scale[o];return;case en.ScaleY:s[Yi]=r.scale[o+1];return;case en.ScaleZ:s[Yi]=r.scale[o+2];return;default:throw new _("invalid_argument",`tween target ${t} is not a transform scalar`)}}writeScalar(e,t){let n=this.registers[Yi],r=this.transforms.store.fields,o=e*3;switch(t){case en.PositionX:r.position[o]=n;break;case en.PositionY:r.position[o+1]=n;break;case en.PositionZ:r.position[o+2]=n;break;case en.ScaleX:r.scale[o]=n;break;case en.ScaleY:r.scale[o+1]=n;break;case en.ScaleZ:r.scale[o+2]=n;break;case en.ScaleUniform:r.scale[o]=n,r.scale[o+1]=n,r.scale[o+2]=n;break}}};var P4e=4,F4e=1,U4e=0,B4e=1,G4e=2;function _x(i){if(i==="now")return aY;if(i==="beat")return lY;if(i==="bar")return H1;if(!Number.isInteger(i.bars)||i.bars<1)throw new _("invalid_argument","a phrase is a whole number of bars, at least one");return H1+i.bars}var yx=class{constructor(e,t){this.sounds=new Int32Array(ci);this.gains=new Float32Array(ci);this.where=new Float64Array(vm);this.port=e,this.defaultBus=t;}get available(){return this.port.capabilities.music===true}require(){if(!this.available)throw new _("unsupported_feature",`${this.port.name} has no interactive music`)}checked(e,t){if(e===void 0||e<0)throw new _("invalid_argument",`${t} was refused`);return e}setTempo(e,t="bar"){this.require();let n=e.beatsPerBar??P4e;if(!(e.bpm>0)||!Number.isFinite(e.bpm)||!Number.isInteger(n)||n<1)throw new _("invalid_argument","a tempo is a positive bpm and a whole number of beats per bar");return this.checked(this.port.musicTempo?.(e.bpm,n,_x(t)),"the tempo")}play(e,t={}){if(this.require(),e.length===0||e.length>ci)throw new _("invalid_argument",`a segment has 1 to ${ci} stems`);let n=t.bars??F4e;if(!Number.isInteger(n)||n<1)throw new _("invalid_argument","a segment loops over a whole number of bars");for(let s=0;s<e.length;s++)this.sounds[s]=e[s].sound,this.gains[s]=e[s].gain??1;let r=t.fadeSeconds??0,o=this.port.musicPlay?.(this.sounds.subarray(0,e.length),this.gains.subarray(0,e.length),n,t.bus??this.defaultBus,_x(t.quantize??"bar"),r);return this.checked(o,"the segment")}setLayer(e,t,n=0){if(this.require(),!Number.isInteger(e)||e<0||e>=ci||!(t>=0))throw new _("invalid_argument",`layers are 0 to ${ci-1} with a non-negative gain`);this.port.musicLayer?.(e,t,n);}stinger(e,t={}){this.require();let n=this.port.musicStinger?.(e,t.bus??this.defaultBus,t.gain??1,_x(t.quantize??"beat"));return this.checked(n,"the stinger")}stop(e="bar",t=0){return this.require(),this.checked(this.port.musicStop?.(_x(e),t),"stopping the music")}position(){return !this.available||this.port.musicPosition?.(this.where)!==true?null:{bar:this.where[U4e],beat:this.where[B4e],fraction:this.where[G4e]}}};var V4e=64,H4e=3,hh=4,W4e=12;function xee(i,e,t){let n=i.fields,r=e*4,o=e*3,s=n.rotation[r],a=n.rotation[r+1],l=n.rotation[r+2],c=n.rotation[r+3],u=n.scale[o],d=n.scale[o+1],h=n.scale[o+2];t[0]=(1-2*(a*a+l*l))*u,t[1]=2*(s*a+c*l)*u,t[2]=2*(s*l-c*a)*u,t[3]=0,t[4]=2*(s*a-c*l)*d,t[5]=(1-2*(s*s+l*l))*d,t[6]=2*(a*l+c*s)*d,t[7]=0,t[8]=2*(s*l+c*a)*h,t[9]=2*(a*l-c*s)*h,t[10]=(1-2*(s*s+a*a))*h,t[11]=0;for(let p=0;p<H4e;p++)t[W4e+p]=n.position[o+p];t[15]=1;}function K4e(i,e,t){for(let n=0;n<hh;n++)for(let r=0;r<hh;r++){let o=0;for(let s=0;s<hh;s++)o+=i[s*hh+r]*e[n*hh+s];t[n*hh+r]=o;}}var Ax=class{constructor(){this.matrix=new Float32Array(16);this.parent=new Float32Array(16);this.product=new Float32Array(16);}of(e,t){let n=e.row(t);if(n===-1)return false;xee(e,n,this.matrix);for(let r=0;r<V4e;r++){let o=e.fields.parent[n];if(o===4294967295||(n=e.row(o),n===-1))break;xee(e,n,this.parent),K4e(this.parent,this.matrix,this.product),this.matrix.set(this.product);}return true}};var Y4e=new Uint8Array(Uint16Array.of(1).buffer)[0]===1,bx=Y4e?Int32Array.of(0,1,2,3):Int32Array.of(3,2,1,0);function r_(i,e){let t=(i&65535)+(e&65535);return (i>>>16)+(e>>>16)+(t>>>16)<<16|t&65535}var mh=class{constructor(e){this.state=new Uint32Array(4);this.output=new Uint32Array(2);this.words=new Int32Array(this.state.buffer);this.drawn=new Int32Array(this.output.buffer);this.limbs=new Int32Array(7);this.cell=new Float64Array(1);this.halves=new Uint16Array(this.cell.buffer);this.views=[this.state,this.output];this.reseed(e);}rollbackViews(){return this.views}get seed(){return this.output[1]}reseed(e){this.output[1]=e;let t=this.output[1];for(let n=0;n<4;n++){t=t+2654435769>>>0;let r=t;r=Math.imul(r^r>>>16,2246822507),r=Math.imul(r^r>>>13,3266489909),this.state[n]=(r^r>>>16)>>>0;}for(let n=0;n<12;n++)this.advance();}nextUint32(){return this.advance(),this.output[0]}float(){return this.advance(),this.output[0]/4294967296}range(e,t){return this.advance(),e+(t-e)*(this.output[0]/4294967296)}rangeInto(e,t,n,r){this.advance(),e[t]=n+(r-n)*(this.output[0]/4294967296);}int(e,t){return this.advance(),e+(this.output[0]/4294967296*(t-e+1)|0)}chance(e){return this.advance(),this.output[0]/4294967296<e}centeredInto(e,t,n,r,o){this.advance();let s=this.drawn[0]^-2147483648,a=s>>>31,l=a===1?~s:s,c=(l&65535)+a,u=l>>>16;c>65535&&(c=0,u++);let d=n*c,h=n*u;h+=d>>>16,d&=65535;let p=h>>>7;if(r[o]=(p^-a)+a,h===0&&d===0){e[t]=0;return}let m=h!==0?47-Math.clz32(h):31-Math.clz32(d),f=this.limbs;f[0]=d,f[1]=h&65535,f[2]=h>>>16,f[m>>4]&=~(1<<(m&15)),f[3]=0,f[4]=0,f[5]=0,f[6]=0;let y=52-m;for(let E=0;E<3;E++){let R=f[E];if(R===0)continue;let g=E*16+y,v=g>>4,x=g&15;f[3+v]|=(R&65535>>>x)<<x,x>0&&v+1<4&&(f[3+v+1]|=R>>>16-x);}let b=this.halves,A=a<<15|m+992<<4|f[6]&15;b[bx[0]]=f[3],b[bx[1]]=f[4],b[bx[2]]=f[5],b[bx[3]]=A,e.set(this.cell,t);}advance(){let e=this.words,t=e[0],n=e[1],r=e[2],o=e[3],s=r_(r_(t,n),o);e[3]=r_(o,1),e[0]=n^n>>>9,e[1]=r_(r,r<<3);let a=r<<21|r>>>11;e[2]=r_(a,s),this.drawn[0]=s;}saveState(e){e.set(this.state);}restoreState(e){this.state.set(e);}};var X4e={room:{seconds:.8,decay:3,preDelay:.005,damping:.5,width:1},hall:{seconds:2.4,decay:2.2,preDelay:.02,damping:.35,width:1},cathedral:{seconds:5,decay:1.6,preDelay:.04,damping:.25,width:1},plate:{seconds:1.6,decay:2.8,preDelay:0,damping:.1,width:.8},cave:{seconds:3.5,decay:1.8,preDelay:.03,damping:.6,width:1},tunnel:{seconds:2.8,decay:2,preDelay:.06,damping:.45,width:.6}},q4e=1.5,z4e=2.5,vee=10,fL=2;function Ree(i,e){let t=i.seconds??q4e,n=i.preDelay??0;if(!(t>0&&t<=vee))throw new _("invalid_argument",`reverb length must be in (0, ${vee}] seconds`);if(!(n>=0&&n<t))throw new _("invalid_argument","preDelay must be non-negative and shorter than the reverb");if(!(e>0))throw new _("invalid_argument","sampleRate must be positive");return Math.max(1,Math.round(t*e))}function Q4e(i,e,t){let n=Ree(i,e),r=i.channels??fL;if(t.length<n*r)throw new _("invalid_argument","impulse buffer is too small");let o=i.decay??z4e,s=Math.min(1,Math.max(0,i.damping??0)),a=Math.min(1,Math.max(0,i.width??1)),l=Math.round((i.preDelay??0)*e),c=new mh(i.seed??0),u=0,d=0;for(let h=0;h<n;h++){let p=h*r;if(h<l){for(let R=0;R<r;R++)t[p+R]=0;continue}let m=(h-l)/(n-l),f=(1-m)**o,y=1-s*m,b=c.range(-1,1),A=c.range(-1,1),E=(b+A)*.5;u+=y*(E+(b-E)*a-u),t[p]=u*f,r===fL&&(d+=y*(E+(A-E)*a-d),t[p+1]=d*f);}return n}function See(i,e,t){let n=typeof i=="string"?{...X4e[i],seed:t}:i,r=n.channels??fL,o=Ree(n,e),s=new Float32Array(o*r);return Q4e(n,e,s),{samples:s,channels:r,sampleRate:e,frames:o}}var Tee=3;function wee(i){let e=fg.indexOf(i.kind);if(e<0)throw new _("invalid_argument",`filter kind ${i.kind} is unknown`);if(!(i.frequency>0))throw new _("invalid_argument","filter frequency must be positive");return e}function Iee(i){let e=i.q??J4e;if(!(e>0))throw new _("invalid_argument","filter Q must be positive");return e}function _L(i){if(!Number.isInteger(i)||i<W1||i>K1)throw new _("invalid_argument",`a voice priority is a whole number from ${W1} to ${K1}`);return i}function AL(i,e){if(i.schema[e]!=="f32")throw new _("invalid_argument",`emitter fields read f32 columns; ${e} is not one`);return i.column(e)}function Oee(i,e,t,n){if(typeof e=="string"){if(i.schema[e]!=="vec3")throw new _("invalid_argument",`emitter field ${e} must be a vec3`);for(let r=0;r<Tee;r++)t[n+r]=i.column(e,r);return}for(let r=0;r<Tee;r++)t[n+r]=AL(i,e[r]);}function $4e(i,e){let t=new Uint32Array(id).fill(yY);return Oee(i,e.position,t,pY),e.velocity!==void 0&&Oee(i,e.velocity,t,mY),e.gain!==void 0&&(t[fY]=AL(i,e.gain)),e.pitch!==void 0&&(t[_Y]=AL(i,e.pitch)),t}var j4e="hall",J4e=Math.SQRT1_2;function Cee(i,e){let t=_g.indexOf(i.distanceModel??As.distanceModel);if(t<0)throw new _("invalid_argument",`distance model ${i.distanceModel} is unknown`);let n=i.refDistance??As.refDistance,r=i.maxDistance??As.maxDistance,o=i.rolloff??As.rolloff,s=i.coneInnerAngle??As.coneInnerAngle,a=i.coneOuterAngle??As.coneOuterAngle,l=i.coneOuterGain??As.coneOuterGain,c=i.doppler??As.doppler;if(!(n>=0)||!(r>0)||!(o>=0))throw new _("invalid_argument","panner distances and rolloff must be non-negative");if(!(s>=0&&s<=kee&&a>=0&&a<=kee))throw new _("invalid_argument","cone angles are degrees from 0 to 360");if(!(l>=0&&l<=1)||!(c>=0))throw new _("invalid_argument","cone outer gain is 0 to 1 and doppler non-negative");return e[yg]=t,e[Ag]=n,e[bg]=r,e[gg]=o,e[Eg]=s,e[xg]=a,e[vg]=l,e[gY]=c,e}function Nee(i,e){if(!Number.isFinite(i)||!Number.isFinite(e)||i<0||e<0)throw new _("invalid_argument","loop points are non-negative finite seconds");if(e!==0&&e<=i)throw new _("invalid_argument","loop end must be after loop start, or 0 for the end of the sound")}var kee=360,Z4e=-1,Mc=-1,yL=-1,eGe=32,gx=class{constructor(e,t,n=64){this.occlusion=new Float32Array(nd);this.listenerEntity=4294967295;this.duckBus=yL;this.duckRemaining=0;this.duckRelease=0;this.busGain=new Float32Array(eGe).fill(1);this.spatial=new Float32Array(ui);this.loopStarts=new Map;this.loopEnds=new Map;this.feeds=[];this.pose=new Ax;this.stepFrame=new Float64Array(1);this.stepped=false;this.lockstepped=false;this.port=e,this.transforms=t,this.voiceIds=new Int32Array(n).fill(Mc),this.voiceEntity=new Uint32Array(n).fill(4294967295),this.master=e.createBus("master",Z4e),this.music=e.createBus("music",this.master),this.effects=e.createBus("effects",this.master),this.conductor=new yx(e,this.music);}get frame(){return this.require(this.port.capabilities.scheduling===true&&this.port.nowFrame!==void 0,"sample-accurate scheduling"),this.port.nowFrame?.()??0}playOn(e,t,n,r=1,o=1,s=false,a=rd){if(this.require(this.port.capabilities.scheduling===true&&this.port.playOn!==void 0,"sample-accurate scheduling"),!Number.isInteger(e)||e<0)throw new _("invalid_argument","a frame is a non-negative whole number");let l=this.port.playOn?.(t,n,r,o,s,false,_L(a),e)??Mc;return s&&this.applySoundLoop(l,t),l}stopOn(e,t,n=0){if(this.require(this.port.capabilities.scheduling===true&&this.port.stopOn!==void 0,"sample-accurate scheduling"),!Number.isInteger(t)||t<0)throw new _("invalid_argument","a frame is a non-negative whole number");this.port.stopOn?.(e,t,n);}setBinaural(e,t){this.require(this.port.capabilities.binaural===true&&this.port.setVoiceBinaural!==void 0,"binaural rendering"),this.port.setVoiceBinaural?.(e,t);}setOcclusion(e,t){if(this.require(this.port.capabilities.occlusion===true&&this.port.setVoiceOcclusion!==void 0,"occlusion"),t===null){this.port.setVoiceOcclusion?.(e,null);return}let n=t.radius??xm.radius,r=t.occludedGain??xm.occludedGain,o=t.occludedCutoff??xm.occludedCutoff,s=t.smoothingSeconds??xm.smoothingSeconds;if(!(n>=0)||!(r>=0&&r<=1)||!(o>0)||!(s>=0))throw new _("invalid_argument","occlusion takes a non-negative radius and smoothing, a gain of 0 to 1 and a positive cutoff");this.occlusion[0]=n,this.occlusion[1]=r,this.occlusion[2]=o,this.occlusion[3]=s,this.port.setVoiceOcclusion?.(e,this.occlusion);}get unlocked(){return this.port.unlocked}unlock(){this.port.unlock();}async load(e){try{return await this.port.decode(e)}catch(t){throw new _("asset_load_failed",`sound failed to load: ${String(t)}`)}}createBus(e,t){return this.port.createBus(e,t)}setBusGain(e,t,n=0){e<this.busGain.length&&(this.busGain[e]=t),this.port.setBusGain(e,t,n);}duck(e,t,n,r){this.duckBus=e,this.duckRemaining=n,this.duckRelease=r,this.port.setBusGain(e,t*this.restingGain(e),r);}get capabilities(){return this.port.capabilities}get sampleRate(){return this.port.sampleRate}createSound(e,t,n=this.port.sampleRate){if(this.require(this.port.capabilities.procedural,"procedural sounds"),!Number.isInteger(t)||t<1||e.length===0||e.length%t!==0)throw new _("invalid_argument","sound PCM must be non-empty interleaved whole frames");return this.port.createSound(e,t,n)}play(e,t,n=1,r=1,o=false,s=rd){let a=this.port.play(e,t,n,r,o,false,_L(s));return o&&this.applySoundLoop(a,e),a}setSoundLimit(e,t){if(this.require(this.port.capabilities.voiceLimits===true&&this.port.setSoundLimit!==void 0,"sound voice limits"),t===null){this.port.setSoundLimit?.(e,q1,0);return}let n=hY.indexOf(t.steal??"quietest");if(n<0)throw new _("invalid_argument",`steal policy ${t.steal} is unknown`);if(!Number.isInteger(t.voices)||t.voices<1)throw new _("invalid_argument","a sound limit allows at least one voice");this.port.setSoundLimit?.(e,t.voices,n);}setVoiceBudget(e){if(this.require(this.port.capabilities.voiceLimits===true&&this.port.setVoiceBudget!==void 0,"a voice budget"),e!==null&&(!Number.isInteger(e)||e<0))throw new _("invalid_argument","a voice budget is a whole number of voices");this.port.setVoiceBudget?.(e??q1);}setVolume(e,t,n=0){this.port.setVoiceGain(e,t,n);}setPlaybackRate(e,t,n=0){if(!(t>0)||!Number.isFinite(n))throw new _("invalid_argument","rate must be positive and detune finite");n!==0&&this.require(this.port.capabilities.detune,"detune"),this.port.setVoiceRate(e,t,n);}setPanner(e,t){this.require(this.port.capabilities.spatial,"positional audio"),this.port.setVoiceSpatial(e,Cee(t,this.spatial));}setFilter(e,t){if(this.require(this.port.capabilities.filters,"bus filters"),t===null){this.port.setBusFilter(e,Rm,0,0,0);return}this.port.setBusFilter(e,wee(t),t.frequency,Iee(t),t.gain??0);}setVoiceFilter(e,t){if(this.require(this.port.capabilities.voiceFilters===true&&this.port.setVoiceFilter!==void 0,"voice filters"),t===null){this.port.setVoiceFilter?.(e,Rm,0,0,0);return}this.port.setVoiceFilter?.(e,wee(t),t.frequency,Iee(t),t.gain??0);}setLimiter(e){if(this.require(this.port.capabilities.limiter===true&&this.port.setLimiter!==void 0,"a master limiter"),e===null){this.port.setLimiter?.(false,0,0);return}let t=e.ceilingDb??uY,n=e.releaseSeconds??dY;if(!(t<=0))throw new _("invalid_argument","the limiter ceiling is at most 0 dBFS");if(!(n>=0)||!Number.isFinite(n))throw new _("invalid_argument","the limiter release is a non-negative number of seconds");this.port.setLimiter?.(true,t,n);}meter(e,t){this.require(this.port.capabilities.meters,"meters"),this.port.meter(e,t);}createAnalyser(e,t={}){return this.require(this.port.capabilities.analyser,"the analyser"),this.port.createAnalyser(e,NY(t))}frequencyData(e,t){this.port.readAnalyser(e,bs,t);}timeDomainData(e,t){this.port.readAnalyser(e,EY,t);}createReverb(e={}){this.require(this.port.capabilities.reverb,"convolution reverb");let t=e.impulse??j4e,n;if(typeof t=="number")n=t;else {let r=See(t,this.port.sampleRate,e.seed);n=this.port.createSound(r.samples,r.channels,r.sampleRate);}return this.port.createReverb(e.parent??this.master,n)}setSend(e,t,n){if(this.require(this.port.capabilities.sends,"bus sends"),e===t)throw new _("invalid_argument","a bus cannot send to itself");if(!(n>=0))throw new _("invalid_argument","send amount must be non-negative");this.port.setBusSend(e,t,n);}setLoopPoints(e,t,n){if(this.require(this.port.capabilities.loopPoints,"loop points"),Nee(t,n),t===0&&n===0){this.loopStarts.delete(e),this.loopEnds.delete(e);return}this.loopStarts.set(e,t),this.loopEnds.set(e,n);}setVoiceLoop(e,t,n=0,r=0){this.require(this.port.capabilities.loopPoints,"loop points"),Nee(n,r),this.port.setVoiceLoop(e,t,n,r);}async openStream(e,t=this.music){this.require(this.port.capabilities.streaming,"streaming music");try{return await this.port.openStream(e,t)}catch(n){throw n instanceof _?n:new _("asset_load_failed",`stream failed to open: ${String(n)}`)}}playStream(e,t=1,n=true){this.port.playStream(e,t,n);}pauseStream(e){this.port.pauseStream(e);}seekStream(e,t){if(!(t>=0))throw new _("invalid_argument","seek position must be non-negative");this.port.seekStream(e,t);}streamTime(e){return this.port.streamTime(e)}streamDuration(e){return this.port.streamDuration(e)}closeStream(e){this.port.closeStream(e);}applySoundLoop(e,t){let n=this.loopStarts.get(t);n!==void 0&&this.port.setVoiceLoop(e,true,n,this.loopEnds.get(t)??0);}require(e,t){if(!e)throw new _("unsupported_feature",`${this.port.name} has no ${t}`)}playAt(e,t,n,r=1,o=1,s=false,a,l=rd){let c=this.port.play(t,n,r,o,s,true,_L(l));s&&this.applySoundLoop(c,t),a!==void 0&&this.setPanner(c,a);for(let u=0;u<this.voiceIds.length;u++)if(!(this.voiceIds[u]!==Mc&&this.port.isPlaying(this.voiceIds[u]))){this.voiceIds[u]=c,this.voiceEntity[u]=e;break}return c}stop(e,t=0){this.port.stop(e,t);}isPlaying(e){return this.port.isPlaying(e)}setListener(e){this.listenerEntity=e;}feedEmitters(e,t,n,r){let o=this.port.createEmitters;if(o===void 0||this.port.feedEmitters===void 0||this.port.capabilities.emitters!==true)throw new _("unsupported_feature",`${this.port.name} has no emitter tables`);if(!t.native)throw new _("invalid_argument","emitter tables must be kernel tables in engine memory");let s=r.capacity??AY;if(!Number.isInteger(s)||s<1)throw new _("invalid_argument","emitter capacity must be a positive whole number");let a=$4e(t,n),l=r.panner===void 0?null:Cee(r.panner,new Float32Array(ui)),c=o.call(this.port,r.sound,e,s,l);if(c<0)throw new _("capacity_exceeded","the audio mixer has no free emitter bank");return this.feeds.push({bank:c,table:t,columns:a}),c}stopEmitters(e){let t=this.feeds.findIndex(n=>n.bank===e);t<0||(this.feeds[t]=this.feeds[this.feeds.length-1],this.feeds.pop(),this.port.releaseEmitters?.(e));}setLockstep(e){e&&this.require(this.port.capabilities.lockstep===true&&this.port.lockstep!==void 0,"lockstep mixing"),!e&&this.stepped&&this.port.lockstep?.(0,0),this.lockstepped=e,this.stepped=false;}get lockstep(){return this.lockstepped}fixedStep(e){this.lockstepped&&this.stepLocked(e),this.feeds.length>0&&this.feedAll();}stepLocked(e){let t=this.port.lockstep;if(t===void 0)return;this.stepped=true;let n=e.values,r=n[ai];t.call(this.port,n[pm],Math.round(1/r));let o=this.transforms.store;this.listenerEntity!==4294967295&&this.pose.of(o,this.listenerEntity)&&this.port.setListener(this.pose.matrix,0);for(let s=0;s<this.voiceIds.length;s++){let a=this.voiceIds[s];if(a!==Mc){if(!this.port.isPlaying(a)||!this.pose.of(o,this.voiceEntity[s])){this.voiceIds[s]=Mc;continue}this.port.setVoicePosition(a,this.pose.matrix,0);}}this.stepFrame[0]=r,this.port.commit?.(this.stepFrame,0);}feedAll(){let e=this.port.feedEmitters;if(e!==void 0)for(let t=0;t<this.feeds.length;t++){let n=this.feeds[t];e.call(this.port,n.bank,n.table.id,n.columns);}}suspend(){this.port.suspend();}resume(){this.port.resume();}update(e){if(this.duckBus!==yL&&(this.duckRemaining-=e.values[Hn],this.duckRemaining<=0&&(this.port.setBusGain(this.duckBus,this.restingGain(this.duckBus),this.duckRelease),this.duckBus=yL)),this.stepped){this.port.flush?.();return}let t=this.transforms.store,n=t.fields.render;if(this.listenerEntity!==4294967295){let r=t.row(this.listenerEntity);r!==-1&&this.port.setListener(n,r*16);}for(let r=0;r<this.voiceIds.length;r++){let o=this.voiceIds[r];if(o===Mc)continue;let s=t.row(this.voiceEntity[r]);if(s===-1||!this.port.isPlaying(o)){this.voiceIds[r]=Mc;continue}this.port.setVoicePosition(o,n,s*16);}this.port.commit?.(e.values,Hn),this.port.flush?.();}restingGain(e){return e<this.busGain.length?this.busGain[e]:1}};var tGe=[];var nGe="hot",Lee="__cimplify_hot",Mee=null;function Ex(){let i=globalThis,e=i[Lee]??Mee;if(e!=null)return e;let t={reloader:null,reusing:false};return Object.isExtensible(i)?i[Lee]=t:Mee=t,t}function Dee(){return Ex().reloader!==null}function rGe(i){if(typeof i!="object"||i===null)return null;let e=i[nGe];return typeof e=="object"&&e!==null?e:null}function Pee(i,e=tGe){let t=Ex().reloader,n=rGe(i);return t===null||n===null?null:t.load(n,e)}function Fee(){return Ex().reusing}async function Uee(i){let e=Ex();e.reusing=true;try{return await i()}finally{e.reusing=false;}}var Hs=4294967295;function Vs(i){return i&1048575}function oGe(i){return i>>>20&1023}function sGe(i,e){return ((e&1023)<<20|i)>>>0}var xx=0,bL=1,gL=2,EL=3,aGe=4,vx=class{constructor(e){this.counters=new Uint32Array(aGe);if(e<=0||e>1048575)throw new _("invalid_argument",`entity capacity must be 1..${1048575}`);this.capacity=e,this.generations=new Uint16Array(e),this.live=new Uint8Array(e),this.freeList=new Uint32Array(e),this.views=[this.counters,this.generations,this.live,this.freeList];}get count(){return this.counters[gL]}rollbackViews(){return this.views}create(){let e=this.counters,t;if(e[xx]>0){let n=e[EL];t=this.freeList[n],e[EL]=n+1===this.capacity?0:n+1,e[xx]--;}else {if(e[bL]>=this.capacity)throw new _("capacity_exceeded",`entity capacity ${this.capacity} reached`);t=e[bL]++;}return this.live[t]=1,e[gL]++,sGe(t,this.generations[t])}destroy(e){if(!this.isAlive(e))return false;let t=Vs(e),n=this.counters;this.live[t]=0,this.generations[t]=this.generations[t]+1&1023;let r=n[EL]+n[xx];return this.freeList[r>=this.capacity?r-this.capacity:r]=t,n[xx]++,n[gL]--,true}isAlive(e){if(e===Hs)return false;let t=Vs(e);return t<this.counters[bL]&&this.live[t]===1&&this.generations[t]===oGe(e)}assertAlive(e){if(!this.isAlive(e))throw new _("dead_entity",`entity ${e} is not alive`)}};function lGe(i,e){switch(i){case "f32":return new Float32Array(e);case "f64":return new Float64Array(e);case "i8":return new Int8Array(e);case "i16":return new Int16Array(e);case "i32":return new Int32Array(e);case "u8":return new Uint8Array(e);case "u16":return new Uint16Array(e);case "u32":return new Uint32Array(e)}}var Rx={allocate(i,e){return lGe(i,e)}};var Sx=0,vL=1,cGe=2,uGe=0,Vee=new Map;function dGe(i,e){let t=Object.keys(i);if(t.length!==Object.keys(e).length)return false;for(let n of t){let r=i[n],o=e[n];if(typeof r=="string"||typeof o=="string"){if(r!==o)return false}else if(o===void 0||r[0]!==o[0]||r[1]!==o[1])return false}return true}function fh(i,e){let t=Vee.get(i);if(t!==void 0&&Fee()&&dGe(t.schema,e))return t;let n={id:uGe++,name:i,schema:e};return Vee.set(i,n),n}function hGe(i){return typeof i=="string"?1:i[1]}function pGe(i){return typeof i=="string"?i:i[0]}var Tx=class{constructor(e,t,n,r=Rx){this.counters=new Uint32Array(cGe);this.type=e,this.capacity=t,this.entities=r.allocate("u32",t),this.sparse=r.allocate("i32",n).fill(-1);let o=Object.keys(e.schema);this.arrays=[],this.arities=new Int32Array(o.length);let s={};for(let a=0;a<o.length;a++){let l=e.schema[o[a]],c=hGe(l),u=r.allocate(pGe(l),t*c);this.arrays.push(u),this.arities[a]=c,s[o[a]]=u;}this.fields=s,this.views=[this.counters,this.entities,this.sparse,...this.arrays];}get count(){return this.counters[Sx]}get version(){return this.counters[vL]}rollbackViews(){return this.views}row(e){let t=Vs(e);if(t>=this.sparse.length)return -1;let n=this.sparse[t];return n!==-1&&this.entities[n]===e?n:-1}has(e){return this.row(e)!==-1}require(e){let t=this.row(e);if(t===-1)throw new _("missing_component",`entity ${e} has no ${this.type.name}`);return t}add(e){let t=this.row(e);if(t!==-1)return t;let n=this.counters;if(n[Sx]>=this.capacity)throw new _("capacity_exceeded",`component ${this.type.name} capacity ${this.capacity} reached`);let r=n[Sx]++;this.entities[r]=e,this.sparse[Vs(e)]=r;for(let o=0;o<this.arrays.length;o++){let s=this.arities[o];this.arrays[o].fill(0,r*s,r*s+s);}return n[vL]++,r}remove(e){let t=this.row(e);if(t===-1)return false;let n=this.counters,r=--n[Sx];if(t!==r){let o=this.entities[r];this.entities[t]=o,this.sparse[Vs(o)]=t;for(let s=0;s<this.arrays.length;s++){let a=this.arities[s];this.arrays[s].copyWithin(t*a,r*a,r*a+a);}}return this.sparse[Vs(e)]=-1,n[vL]++,true}entityAt(e){return this.entities[e]}};var Hee=new Float32Array(1),mGe=new Uint32Array(Hee.buffer);function Dc(i){return Hee[0]=i,mGe[0]}function Wee(i){let e=i.lanes,t=i.signals??[],n=0,r=0,o=0;for(let d of e){if(d.points.length<2)throw new _("invalid_argument","lanes need at least two points");n+=d.points.length,r+=d.next?.length??0,o+=d.conflicts?.length??0;}let s=new Uint32Array(7+n*3+e.length*10+r+o+t.length*19);s[0]=n,s[1]=e.length,s[2]=r,s[3]=o,s[4]=t.length,s[5]=i.maxVehicles,s[6]=i.seed??0;let a=7;for(let d of e)for(let h of d.points)s[a++]=Dc(h[0]),s[a++]=Dc(h[1]),s[a++]=Dc(h[2]);let l=0,c=0,u=0;for(let d of e){let h=d.next?.length??0,p=d.conflicts?.length??0;s[a++]=l,s[a++]=d.points.length,s[a++]=Dc(d.speedLimit),s[a++]=d.signal??65535,s[a++]=d.group??0,s[a++]=d.giveWay?1:0,s[a++]=c,s[a++]=h,s[a++]=u,s[a++]=p,l+=d.points.length,c+=h,u+=p;}for(let d of e)for(let h of d.next??[])s[a++]=h;for(let d of e)for(let h of d.conflicts??[])s[a++]=h;for(let d of t){if(d.phases.length<1||d.phases.length>8)throw new _("invalid_argument",`signals take 1 to ${8} phases`);for(let h=0;h<8;h++){let p=0;for(let m of d.phases[h]?.groups??[])p|=1<<(m&31);s[a+h]=p>>>0,s[a+8+h]=Dc(d.phases[h]?.seconds??0);}s[a+16]=d.phases.length,s[a+16+1]=Dc(d.amber),s[a+16+2]=Dc(d.offset??0),a+=19;}return s}var yGe=.5,AGe=.35,bGe=1.4,gGe=8,EGe=6,_h=[4.5,1,1.4,2,1.5,2.5],xGe={tileWorld:64,maxTiles:1,maxAgents:1},yh=class{constructor(e=64){this.count=0;this.complete=false;this.points=new Float32Array(e*3);}},Ix=class{constructor(e){this.initialised=false;this.agentCount=0;this.roads=false;this.roadsOnly=false;this.driver=new Float32Array(EGe);this.nearestOut=new Float32Array(4);this.port=e;}get backend(){return this.port.name}get ready(){return this.initialised}init(e){if(this.roadsOnly)throw new _("invalid_argument","navigation was started for roads only; call game.nav.init before loadRoads when the game also walks a navmesh");if(this.initialised)throw new _("invalid_argument","navigation is already initialised");if(!(e.tileWorld>0))throw new _("invalid_argument","tileWorld must be positive");this.port.init(e),this.initialised=true;}addTile(e){return this.port.addTile(e)}removeTile(e,t){this.port.removeTile(e,t);}addLink(e){let t=e.area??63;if(!(t>0&&t<64))throw new _("invalid_argument","link area out of range");return this.port.addLink(e.start,e.end,e.radius??yGe,e.bidirectional??false,t,e.user??0)}removeLink(e){this.port.removeLink(e);}agentLink(e){return this.port.agents()[e*8+6]}agentLinkProgress(e){return this.port.agents()[e*8+7]}setAreaCost(e,t){if(e<0||e>=64||!(t>=0))throw new _("invalid_argument","area cost out of range");this.port.setAreaCost(e,t);}setIncludedAreas(e,t){this.port.setIncludeMask(e>>>0,t>>>0);}nearest(e,t){let n=this.nearestOut;return this.port.nearest(e.x,e.y,e.z,n)?(t.x=n[0],t.y=n[1],t.z=n[2],true):false}batchHandle(){return this.port.batchHandle?.()??0}findPath(e,t,n){return n.count=this.port.findPath(e.x,e.y,e.z,t.x,t.y,t.z,n.points),n.complete=this.port.pathComplete,n.count>0}addAgent(e,t={}){let n=this.port.addAgent(e.x,e.y,e.z,t.radius??AGe,t.maxSpeed??bGe,t.maxAcceleration??gGe);return this.agentCount++,n}removeAgent(e){this.port.removeAgent(e),this.agentCount--;}setAgentTarget(e,t){this.port.setAgentTarget(e,t.x,t.y,t.z);}stopAgent(e){this.port.stopAgent(e);}get agents(){return this.port.agents()}agentPosition(e,t){let n=this.port.agents(),r=e*8;return t.x=n[r+0],t.y=n[r+1],t.z=n[r+2],t}agentState(e){return this.port.agents()[e*8+5]}loadRoads(e){this.initialised||(this.port.init(xGe),this.initialised=true,this.roadsOnly=true),this.port.loadRoads(Wee(e)),this.roads=true;}addVehicle(e,t,n=0,r={}){let o=this.driver;return o[0]=r.length??_h[0],o[1]=r.desire??_h[1],o[2]=r.headway??_h[2],o[3]=r.jam??_h[3],o[4]=r.accel??_h[4],o[5]=r.decel??_h[5],this.port.addVehicle(e,t,n,o)}removeVehicle(e){this.port.removeVehicle(e);}setExternalVehicle(e,t,n,r){this.port.setExternalVehicle(e,t,n,r);}get vehicles(){return this.port.vehicles()}vehicleOffset(e){return e*8}signal(e){return this.port.signal(e)}step(e){!this.initialised||this.agentCount===0&&!this.roads||this.port.step(e);}stepFixed(e){!this.initialised||this.agentCount===0&&!this.roads||this.port.step(e.values[ai]);}dispose(){this.initialised&&this.port.dispose(),this.initialised=false,this.roadsOnly=false;}};var Kee=4,Yee=1,Xee=1,qee=64,zee=16,Qee=16,$ee=.05,jee=.5,Jee=.5,Xi=class{constructor(){this.origin=new Kt;this.direction=new Kt(0,-1,0);this.maxDistance=Number.MAX_VALUE;this.solid=true;this.includeSensors=false;this.excludeCollider=-1;}set(e,t,n,r,o,s,a){return this.origin.set(e,t,n),this.direction.set(r,o,s),this.maxDistance=a,this}},qi=class{constructor(){this.hit=false;this.collider=-1;this.distance=0;this.pointX=0;this.pointY=0;this.pointZ=0;this.normalX=0;this.normalY=0;this.normalZ=0;}},NL=class{constructor(){this.grounded=false;this.x=0;this.y=0;this.z=0;}};nn(new Xi,["maxDistance"]);nn(new qi,["distance","pointX","pointY","pointZ","normalX","normalY","normalZ"]);nn(new NL,["x","y","z"]);var it=Math.fround,WGe=16,KGe=-1,YGe={constant:0,linear:1,quadratic:2,smooth:3};function Tn(i){return i?i.index:255}function dl(i,e,t,n){let r=i.$indices(e);if(r.length!==1||!t.includes(i.$kind(r[0])))throw new _("invalid_argument",`${e} must be ${n}`);return r[0]}function Ws(i,e,t,n){return e===void 0?255:dl(i,e,t,n)}function s_(i,e,t){let n=i.$indices(e);if(n.length<t||i.$kind(n[0])!==0)throw new _("invalid_argument",`${e} must be a vec${t} or wider field`);return n[0]}function kL(i,e){return e===void 0?255:s_(i,e,3)}var Ks=[1,2],Pc=[0],nte=[3],Nx=class{constructor(e,t,n,r){let o=e.$indices(t),s=e.$indices(n);if(o.length!==s.length||o.length===0||o.length>32)throw new _("invalid_argument",`${t} and ${n} must be slot arrays of the same length, 1..${32}`);for(let a=0;a<o.length;a++)if(!Ks.includes(e.$kind(o[a]))||!Ks.includes(e.$kind(s[a])))throw new _("invalid_argument","inventory slots must be u32 or i32 arrays");if(!Number.isInteger(r)||r<0||r>4294967295)throw new _("invalid_argument","stackLimit must be 0 (unlimited) or a positive integer");this.table=e,this.layout=(o[0]|s[0]<<8|o.length<<16)>>>0,this.limit=r;}run(e,t,n,r,o,s,a=0,l=0,c=255){let u=this.table;u.$ready();let d=u.header,h=16;d[h+0]=typeof t=="number"?t:0,d[h+5]=typeof t=="number"?255:dl(u,t,Ks,"a u32 or i32 field"),d[h+1]=typeof n=="number"?n:0,d[h+6]=typeof n=="number"?255:dl(u,n,Ks,"a u32 or i32 field"),d[h+2]=a,d[h+3]=l,d[h+4]=this.limit,d[h+7]=c;let p=u.$bulk?.engine_soa_inventory;return u.$status(p?p(u.id,e,this.layout,r,o,s):u.$fallback.inventory(e,this.layout,r,o,s))}give(e,t,n,r){return this.run(0,e,t,Tn(n),255,Tn(r))}take(e,t,n,r){return this.run(1,e,t,Tn(n),255,Tn(r))}transfer(e,t,n,r,o){return this.run(2,n,r,e.index,t.index,Tn(o))}move(e,t,n,r,o){return this.run(3,0,0,Tn(n),Tn(r),Tn(o),e,t)}split(e,t,n,r,o){return this.run(4,0,t,Tn(n),Tn(r),Tn(o),e)}count(e,t,n=1,r,o){let s=t?dl(this.table,t,Ks,"a u32 or i32 field"):255;return this.run(5,e,n,Tn(r),255,Tn(o),0,0,s)}},kx=class{constructor(e,t,n){let r=n.from&&n.from!==e?n.from:null;if(r!==null&&r.native!==e.native)throw new _("invalid_argument","source and target tables must both live in the engine or both in JS");let o=r??e,s=o.$indices(n.position);if(s.length<2||o.$kind(s[0])!==0)throw new _("invalid_argument",`${n.position} must be a vec2, vec3 or vec4 field`);let a=YGe[n.falloff??"linear"];if(a===void 0)throw new _("invalid_argument",`unknown falloff ${String(n.falloff)}`);this.table=e,this.source=r,this.health=dl(e,t,Pc,"an f32 field"),this.x=s[0],this.y=s[1],this.z=s.length>2?s[2]:255,this.radiusColumn=typeof n.radius=="string"?dl(o,n.radius,Pc,"an f32 field"):255,this.radius=typeof n.radius=="number"?n.radius:0,this.amountColumn=typeof n.amount=="string"?dl(o,n.amount,Pc,"an f32 field"):255,this.amount=typeof n.amount=="number"?n.amount:0,this.falloff=a,this.multiplier=Ws(e,n.multiplier,Pc,"an f32 field"),this.low=n.min??Number.NEGATIVE_INFINITY,this.high=n.max??Number.POSITIVE_INFINITY,this.flags=n.skipSelf===false?0:1;}apply(e,t){let n=this.table;n.$ready(),this.source?.$ready();let r=n.header,o=n.params;r[16]=this.x,r[17]=this.y,r[18]=this.z,r[19]=this.radiusColumn,o[4]=this.radius,r[21]=this.amountColumn,o[6]=this.amount,r[23]=this.falloff,r[24]=this.multiplier,o[9]=this.low,o[10]=this.high,r[27]=this.flags;let s=Tn(e),a=Tn(t),l=n.$bulk?.engine_soa_effect;return l?n.$status(l(n.id,this.source?this.source.id:0,s,this.health,a)):n.$status(n.$fallback.effect(this.source?this.source.$fallback:null,s,this.health,a))}},a_=class{constructor(e,t,n,r){this.query=new Xi;this.result=new qi;let o=r?n.target:n.direction;if(o===void 0)throw new _("invalid_argument",r?"line of sight needs a target field":"rays need a direction field");this.table=e,this.physics=t,this.sight=r,this.origin=s_(e,n.origin,3),this.toward=s_(e,o,3),this.maxColumn=typeof n.maxDistance=="string"?dl(e,n.maxDistance,Pc,"an f32 field"):255,this.maxDistance=typeof n.maxDistance=="number"?n.maxDistance:1e7,this.flags=(r?1:0)|(n.solid===false?0:2)|(n.sensors?4:0),this.distance=Ws(e,n.distance,Pc,"an f32 field"),this.normal=kL(e,n.normal),this.entity=Ws(e,n.entity,Ks,"a u32 field"),this.collider=Ws(e,n.collider,Ks,"a u32 field"),this.exclude=Ws(e,n.exclude,Ks,"a u32 field"),this.mask=Ws(e,n.hit,nte,"a u8 field");}cast(e,t){let n=this.table;n.$ready();let r=n.header;r[16]=this.origin,r[17]=this.toward,r[18]=this.maxColumn,n.params[3]=this.maxDistance,r[20]=this.flags,r[21]=this.distance,r[22]=this.normal,r[23]=this.entity,r[24]=this.collider,r[25]=this.exclude,r[26]=this.mask;let o=Tn(e),s=Tn(t),a=n.$bulk?.engine_soa_raycast,l=a&&n.native?this.physics.batchHandle?.()??0:0;return a&&l!==0?n.$status(a(n.id,l,o,s)):this.fallback(e??null,t??null)}fallback(e,t){let n=this.table,r=n.columns,o=r[this.origin],s=r[this.origin+1],a=r[this.origin+2],l=r[this.toward],c=r[this.toward+1],u=r[this.toward+2],d=this.maxColumn===255?null:r[this.maxColumn],h=n.params[3],p=this.distance===255?null:r[this.distance],m=this.normal===255?null:r[this.normal],f=this.normal===255?null:r[this.normal+1],y=this.normal===255?null:r[this.normal+2],b=this.entity===255?null:r[this.entity],A=this.collider===255?null:r[this.collider],E=this.exclude===255?null:r[this.exclude],R=this.mask===255?null:r[this.mask],g=this.query,v=this.result;g.solid=(this.flags&2)!==0,g.includeSensors=(this.flags&4)!==0;let x=n.count,O=e===null?x:e.length,N=t===null?null:t.rows,I=0;for(let S=0;S<O;S++){let w=e===null?S:e.rows[S];if(w>=x)continue;let U=o[w],L=s[w],k=a[w],M=l[w],K=c[w],Y=u[w],te=Number.isFinite(U)&&Number.isFinite(L)&&Number.isFinite(k)&&Number.isFinite(M)&&Number.isFinite(K)&&Number.isFinite(Y),Z=M,de=K,Oe=Y,be;this.sight?(Z=it(M-U),de=it(K-L),Oe=it(Y-k),be=it(Math.sqrt(it(it(it(Z*Z)+it(de*de))+it(Oe*Oe))))):be=d===null?h:d[w],be=be>=0?be<1e7?be:1e7:0;let ke=E===null?4294967295:E[w]>>>0,De=false;te&&be>0&&(Z!==0||de!==0||Oe!==0)&&(g.set(U,L,k,Z,de,Oe,be),g.excludeCollider=ke===4294967295?KGe:ke,De=this.physics.raycast(g,v));let Fe=this.sight?te&&!De:De;p!==null&&(p[w]=De?v.distance:be),m!==null&&f!==null&&y!==null&&(m[w]=De?v.normalX:0,f[w]=De?v.normalY:0,y[w]=De?v.normalZ:0),b!==null&&(b[w]=De?this.physics.entityOfCollider(v.collider):4294967295),A!==null&&(A[w]=De?v.collider:4294967295),R!==null&&(R[w]=Fe?1:0),Fe&&(N!==null&&(N[I]=w),I++);}return t!==null&&(n.header[160+2*t.index+1]=I),I}},Lx=class{constructor(e,t,n){this.from={x:0,y:0,z:0};this.to={x:0,y:0,z:0};let r=n.maxCorners??WGe,o=n.budget??0;if(!Number.isInteger(r)||r<1||r>1024)throw new _("invalid_argument","maxCorners must be 1..1024");if(!Number.isInteger(o)||o<0)throw new _("invalid_argument","budget must be 0 (all rows) or a positive integer");this.table=e,this.nav=t,this.start=s_(e,n.start,3),this.goal=s_(e,n.goal,3),this.direction=kL(e,n.direction),this.corner=kL(e,n.corner),this.status=Ws(e,n.status,nte,"a u8 field"),this.length=Ws(e,n.length,Pc,"an f32 field"),this.corners=Ws(e,n.corners,Ks,"a u32 field"),this.maxCorners=r,this.budget=o,this.path=new yh(r);}get pending(){return this.table.header[12]!==0}restart(){this.table.header[12]=0;}run(e,t=this.budget){let n=this.table;if(n.$ready(),!Number.isInteger(t)||t<0)throw new _("invalid_argument","budget must be 0 (all rows) or a positive integer");let r=n.header;r[16]=this.start,r[17]=this.goal,r[18]=this.direction,r[19]=this.corner,r[20]=this.status,r[21]=this.length,r[22]=this.maxCorners,r[23]=this.corners;let o=n.$bulk?.engine_soa_paths,s=o&&n.native?this.nav.batchHandle?.()??0:0;return o&&s!==0?n.$status(o(n.id,s,Tn(e),t)):this.fallback(e??null,t)}fallback(e,t){let n=this.table,r=n.columns,o=n.header,s=n.count,a=e===null?s:e.length,l=o[12];l>=a&&(l=0);let c=t===0?a:Math.min(a,l+t),u=r[this.start],d=r[this.start+1],h=r[this.start+2],p=r[this.goal],m=r[this.goal+1],f=r[this.goal+2],y=this.path,b=y.points,A=this.from,E=this.to,R=0;for(let g=l;g<c;g++){let v=e===null?g:e.rows[g];if(v>=s)continue;A.x=u[v],A.y=d[v],A.z=h[v],E.x=p[v],E.y=m[v],E.z=f[v];let O=Number.isFinite(A.x)&&Number.isFinite(A.y)&&Number.isFinite(A.z)&&Number.isFinite(E.x)&&Number.isFinite(E.y)&&Number.isFinite(E.z)&&this.nav.findPath(A,E,y)?y.count:0;if(O===0)this.write(v,3,0,0,0,A.x,A.y,A.z,0,0);else {let N=0;for(let M=1;M<O;M++){let K=it(b[M*3]-b[M*3-3]),Y=it(b[M*3+1]-b[M*3-2]),te=it(b[M*3+2]-b[M*3-1]);N=it(N+it(Math.sqrt(it(it(it(K*K)+it(Y*Y))+it(te*te)))));}let I=(Math.min(O,2)-1)*3,S=it(b[I]-b[0]),w=it(b[I+1]-b[1]),U=it(b[I+2]-b[2]),L=it(Math.sqrt(it(it(it(S*S)+it(w*w))+it(U*U)))),k=y.complete?1:2;L>0?this.write(v,k,it(S/L),it(w/L),it(U/L),b[I],b[I+1],b[I+2],N,O):this.write(v,k,0,0,0,b[I],b[I+1],b[I+2],N,O);}R++;}return o[12]=c>=a?0:c,R}write(e,t,n,r,o,s,a,l,c,u){let d=this.table.columns;this.direction!==255&&(d[this.direction][e]=n,d[this.direction+1][e]=r,d[this.direction+2][e]=o),this.corner!==255&&(d[this.corner][e]=s,d[this.corner+1][e]=a,d[this.corner+2][e]=l),this.status!==255&&(d[this.status][e]=t),this.length!==255&&(d[this.length][e]=c),this.corners!==255&&(d[this.corners][e]=u);}};var xe=Math.fround,Vx=4,pl=0,zo=4294967295,mM=0,ute=16,ote=10,ZGe=14,ste=8,c_=255,Ah=4294967295,ate=1<<22,e6e=8,dte=4096,cM=dte-1,t6e=255,n6e=[-1,2],lte=.001,ml=xe(Math.SQRT1_2),uM=[1,-1,0,0,1,-1,1,-1],dM=[0,0,1,-1,1,1,-1,-1],r6e=[1,-1,0,0,ml,-ml,ml,-ml],i6e=[0,0,1,-1,ml,ml,-ml,-ml],bh=class{constructor(){this.status=3;this.x=0;this.z=0;this.distance=0;}};function hM(i){return i>0?Math.min(t6e,Math.max(1,Math.round(xe(xe(i)*ute)))):mM}var pM=class{constructor(e,t,n,r,o){this.goalX=0;this.goalZ=0;this.goalCell=zo;this.built=false;this.scratch=new bh;let s=r*o;this.width=r,this.height=o,this.cell=xe(n),this.originX=xe(e),this.originZ=xe(t),this.inverse=xe(1/this.cell),this.metres=xe(this.cell/(ote*ute)),this.costs=new Uint8Array(s),this.integration=new Uint32Array(s).fill(Ah),this.dirs=new Uint8Array(s).fill(c_),this.next=new Uint32Array(s).fill(zo),this.prev=new Uint32Array(s).fill(zo),this.heads=new Uint32Array(dte).fill(zo);}walkable(e,t){return e>=0&&t>=0&&e<this.width&&t<this.height&&this.costs[t*this.width+e]!==mM}step(e,t,n){let r=e+uM[n],o=t+dM[n];return this.walkable(r,o)?n<4||this.walkable(r,t)&&this.walkable(e,o):false}snap(e,t){if(this.walkable(e,t))return t*this.width+e;for(let n=1;n<=e6e;n++){let r=-1,o=0;for(let s=-n;s<=n;s++)for(let a=-n;a<=n;a++){if(Math.abs(a)!==n&&Math.abs(s)!==n||!this.walkable(e+a,t+s))continue;let l=a*a+s*s;(r<0||l<o)&&(o=l,r=(t+s)*this.width+e+a);}if(r>=0)return r}return -1}push(e,t){let n=t&cM,r=this.heads[n];this.next[e]=r,this.prev[e]=zo,r!==zo&&(this.prev[r]=e),this.heads[n]=e;}unlink(e,t){let n=this.prev[e],r=this.next[e];n===zo?this.heads[t&cM]=r:this.next[n]=r,r!==zo&&(this.prev[r]=n);}build(e,t,n){if(this.built=false,!Number.isFinite(e)||!Number.isFinite(t)||!Number.isFinite(n))return -1;let r=xe(e),o=xe(n),s=xe(xe(r-this.originX)*this.inverse),a=xe(xe(o-this.originZ)*this.inverse);if(!(s>=0&&a>=0&&s<this.width&&a<this.height))return -1;let l=this.snap(Math.min(Math.floor(s),this.width-1),Math.min(Math.floor(a),this.height-1));if(l<0)return -1;let c=this.integration,u=this.costs,d=this.width;c.fill(Ah),this.dirs.fill(c_),this.heads.fill(zo),c[l]=0,this.push(l,0);let h=1,p=0,m=0;for(;h>0;){let y=m&cM;for(;this.heads[y]!==zo;){let b=this.heads[y];this.unlink(b,m),h--,p++;let A=c[b],E=b%d,R=(b-E)/d;for(let g=0;g<8;g++){if(!this.step(E,R,g))continue;let v=(R+dM[g])*d+E+uM[g],x=Math.min(Ah,A+(g<4?ote:ZGe)*u[v]),O=c[v];x>=O||x===Ah||(O===Ah?h++:this.unlink(v,O),c[v]=x,this.push(v,x));}}m=m+1>>>0;}let f=this.dirs;for(let y=0;y<c.length;y++){let b=c[y];if(b===Ah)continue;if(y===l){f[y]=ste;continue}let A=y%d,E=(y-A)/d,R=b,g=c_;for(let v=0;v<8;v++){if(!this.step(A,E,v))continue;let x=(E+dM[v])*d+A+uM[v];c[x]<R&&(R=c[x],g=v);}f[y]=g;}return this.goalX=r,this.goalZ=o,this.goalCell=l,this.built=true,p}vector(e,t,n,r){if(e<ste){r.x=r6e[e],r.z=i6e[e];return}let o=xe(this.goalX-t),s=xe(this.goalZ-n),a=xe(Math.sqrt(xe(xe(o*o)+xe(s*s))));a>0?(r.x=xe(o/a),r.z=xe(s/a)):(r.x=0,r.z=0);}sample(e,t,n,r){if(r.status=3,r.x=0,r.z=0,r.distance=0,!this.built)return false;let o=xe(xe(e-this.originX)*this.inverse),s=xe(xe(t-this.originZ)*this.inverse);if(!(o>=0&&s>=0&&o<this.width&&s<this.height))return false;let a=Math.min(Math.floor(o),this.width-1),c=Math.min(Math.floor(s),this.height-1)*this.width+a,u=this.dirs[c];if(u===c_)return false;if(r.status=1,r.distance=xe(xe(this.integration[c])*this.metres),this.vector(u,e,t,r),!n)return true;let d=xe(o-.5),h=xe(s-.5),p=Math.floor(d),m=Math.floor(h),f=xe(d-p),y=xe(h-m),b=xe(1-f),A=xe(1-y),E=0,R=0,g=this.scratch;for(let x=0;x<4;x++){let O=p+(x&1),N=m+(x>>1);if(O<0||N<0||O>=this.width||N>=this.height)continue;let I=this.dirs[N*this.width+O];if(I===c_)continue;let S=xe(x===0?b*A:x===1?f*A:x===2?b*y:f*y);this.vector(I,e,t,g),E=xe(E+xe(S*g.x)),R=xe(R+xe(S*g.z));}let v=xe(Math.sqrt(xe(xe(E*E)+xe(R*R))));return v>0&&(r.x=xe(E/v),r.z=xe(R/v)),true}};function o6e(i){let e=i?.bulk;return !e?.engine_flow_create||!e.engine_flow_destroy||!e.engine_flow_registers||!e.engine_flow_costs||!e.engine_flow_rasterize||!e.engine_flow_build||!e.engine_soa_flow?null:e}var Hx=class{constructor(e,t=null){this.handle=pl;this.registers=pl;this.costPointer=pl;this.costView=new Uint8Array(0);this.probe={x:0,y:0,z:0};this.hit={x:0,y:0,z:0};let n=e.origin??[0,0],r=e.width*e.height;if(!Number.isInteger(e.width)||!Number.isInteger(e.height)||r<=0||r>ate)throw new _("invalid_argument",`a flow field holds 1..${ate} cells`);if(!(e.cell>0)||!Number.isFinite(e.cell)||!Number.isFinite(n[0])||!Number.isFinite(n[1]))throw new _("invalid_argument","flow field cell and origin must be finite and the cell positive");if(this.width=e.width,this.height=e.height,this.cell=xe(e.cell),this.originX=xe(n[0]),this.originZ=xe(n[1]),this.engine=t,this.exports=o6e(t),this.exports!==null&&t!==null){let o=t.exports,s=o.engine_alloc(5*Vx,Vx);if(s===pl)throw new _("capacity_exceeded","engine memory cannot hold a flow descriptor");let a=new Uint32Array(t.memory.buffer,s,5),l=new Float32Array(t.memory.buffer,s,5);if(l[0]=this.originX,l[1]=this.originZ,l[2]=this.cell,a[3]=this.width,a[4]=this.height,this.handle=this.exports.engine_flow_create(s),o.engine_free(s,5*Vx,Vx),this.handle===pl)throw new _("capacity_exceeded","the engine refused the flow field");this.registers=this.exports.engine_flow_registers(this.handle),this.costPointer=this.exports.engine_flow_costs(this.handle),this.js=null;}else this.js=new pM(this.originX,this.originZ,this.cell,this.width,this.height);}get native(){return this.handle!==pl}get $handle(){return this.handle}get $js(){return this.js}get costs(){if(this.js!==null)return this.js.costs;let e=this.engine;return (this.costView.buffer!==e.memory.buffer||this.costView.length===0)&&(this.costView=new Uint8Array(e.memory.buffer,this.costPointer,this.width*this.height)),this.costView}fill(e){this.costs.fill(hM(e));}setCost(e,t,n){if(!Number.isInteger(e)||!Number.isInteger(t)||e<0||t<0||e>=this.width||t>=this.height)throw new _("invalid_argument",`cell ${e}, ${t} is outside the flow field`);this.costs[t*this.width+e]=hM(n);}rasterize(e,t=n6e){let n=e.batchHandle?.()??0;if(this.exports!==null&&this.engine!==null&&n!==0){let c=new Float32Array(this.engine.memory.buffer,this.registers,8);return c[3]=t[0],c[4]=t[1],this.check(this.exports.engine_flow_rasterize(this.handle,n),"rasterize")}let r=this.costs,o=this.probe,s=this.hit,a=hM(1),l=0;o.y=(t[0]+t[1])*.5;for(let c=0;c<this.height;c++){o.z=xe(this.originZ+xe(xe(c+.5)*this.cell));for(let u=0;u<this.width;u++){o.x=xe(this.originX+xe(xe(u+.5)*this.cell));let d=e.nearest(o,s)&&Math.abs(s.x-o.x)<lte&&Math.abs(s.z-o.z)<lte&&s.y>=t[0]&&s.y<=t[1];r[c*this.width+u]=d?a:mM,d&&l++;}}return l}build(e){if(this.js!==null){let r=this.js.build(e.x,e.y,e.z);if(r<0)throw new _("invalid_argument","the flow goal is outside the field or not near an open cell");return r}let t=this.engine,n=new Float32Array(t.memory.buffer,this.registers,8);return n[0]=e.x,n[1]=e.y,n[2]=e.z,this.check(this.exports.engine_flow_build(this.handle),"the flow goal is outside the field or not near an open cell")}batchHandle(){return this.handle}sample(e,t,n,r){if(this.js===null)throw new _("unsupported_feature","sample an engine flow field through table.flow");return this.js.sample(e,t,n,r)}check(e,t){if(e<0)throw new _("invalid_argument",`flow field: ${t} (${e})`);return e}dispose(){this.exports!==null&&this.handle!==pl&&this.exports.engine_flow_destroy(this.handle),this.handle=pl;}};function cte(i,e){let t=i.$indices(e);if(t.length<3||i.$kind(t[0])!==0)throw new _("invalid_argument",`${e} must be a vec3 or wider field`);return t[0]}var Wx=class{constructor(e,t,n){this.sampled=new bh;if(this.table=e,this.field=t,this.position=cte(e,n.position),this.direction=cte(e,n.direction),Math.abs(this.position-this.direction)<3)throw new _("invalid_argument","direction may not alias position");if(n.distance===void 0)this.distance=255;else {let r=e.$indices(n.distance);if(r.length!==1||e.$kind(r[0])!==0)throw new _("invalid_argument",`${n.distance} must be an f32 field`);this.distance=r[0];}if(n.status===void 0)this.status=255;else {let r=e.$indices(n.status);if(r.length!==1||e.$kind(r[0])!==3)throw new _("invalid_argument",`${n.status} must be a u8 field`);this.status=r[0];}if(this.flags=n.smooth===false?0:1,t.native&&!e.native)throw new _("unsupported_feature","an engine flow field steers engine tables; create the field from this table with table.flowField")}run(e){let t=this.table;t.$ready();let n=t.header;n[16]=this.position,n[17]=this.direction,n[18]=this.distance,n[19]=this.status,n[20]=this.flags;let r=e?e.index:255,o=t.$bulk?.engine_soa_flow;if(o&&this.field.native)return t.$status(o(t.id,this.field.$handle,r));let s=this.field.$js;if(s===null)throw new _("unsupported_feature","an engine flow field steers engine tables");let a=t.columns,l=a[this.position],c=a[this.position+2],u=a[this.direction],d=a[this.direction+1],h=a[this.direction+2],p=this.distance===255?null:a[this.distance],m=this.status===255?null:a[this.status],f=this.flags===1,y=this.sampled,b=t.count,A=e?e.length:b,E=0;for(let R=0;R<A;R++){let g=e?e.rows[R]:R;g>=b||(s.sample(l[g],c[g],f,y),u[g]=y.x,d[g]=0,h[g]=y.z,p!==null&&(p[g]=y.distance),m!==null&&(m[g]=y.status),y.status===1&&E++);}return E}};var bi=Math.fround;function Qo(i,e,t,n,r){if(e===void 0)return 255;let o=i.$indices(e);if(!(n===1?o.length===1:o.length>=n)||!t.includes(i.$kind(o[0])))throw new _("invalid_argument",`${e} must be ${r}`);return o[0]}var gh=[0],fM=[2,1],A6e=[3],Kx=class{constructor(e,t,n){this.found=Yb();this.from=new Float32Array(3);this.along=new Float32Array(3);let r=n.target??n.direction;if(r===void 0)throw new _("invalid_argument","picks need a direction field, or a target field for line of sight");if(n.target!==void 0&&n.direction!==void 0)throw new _("invalid_argument","give picks a direction or a target, not both");this.table=e,this.graphics=t,this.sight=n.target!==void 0,this.origin=Qo(e,n.origin,gh,3,"a vec3 field"),this.toward=Qo(e,r,gh,3,"a vec3 field"),this.maxColumn=typeof n.maxDistance=="string"?Qo(e,n.maxDistance,gh,1,"an f32 field"):255,this.maxDistance=typeof n.maxDistance=="number"?n.maxDistance:1e7,this.layers=(n.layers??4294967295)>>>0,this.distance=Qo(e,n.distance,gh,1,"an f32 field"),this.point=Qo(e,n.point,gh,3,"a vec3 field"),this.node=Qo(e,n.node,fM,1,"a u32 field"),this.instance=Qo(e,n.instance,fM,1,"a u32 field"),this.triangle=Qo(e,n.triangle,fM,1,"a u32 field"),this.uv=Qo(e,n.uv,gh,2,"a vec2 or wider field"),this.mask=Qo(e,n.hit,A6e,1,"a u8 field");let o=[this.origin,this.origin+1,this.origin+2,this.toward,this.toward+1,this.toward+2,this.maxColumn],s=[];if(this.distance!==255&&s.push(this.distance),this.point!==255&&s.push(this.point,this.point+1,this.point+2),this.uv!==255&&s.push(this.uv,this.uv+1),s.some(a=>o.includes(a)))throw new _("invalid_argument","pick outputs may not alias the origin, direction or max distance fields")}cast(e,t){let n=this.table;n.$ready();let r=n.header;r[16]=this.origin,r[17]=this.toward,r[18]=this.maxColumn,n.params[3]=this.maxDistance,r[20]=this.sight?1:0,r[21]=this.distance,r[22]=this.point,r[23]=this.node,r[24]=this.instance,r[25]=this.layers,r[26]=this.mask,r[27]=this.triangle,r[28]=this.uv;let o=n.$bulk?.engine_soa_pick,s=o&&n.native?this.graphics.batchHandle?.()??0:0;return o&&s!==0?n.$status(o(n.id,s,e?e.index:255,t?t.index:255)):this.fallback(e??null,t??null)}fallback(e,t){let n=this.table,r=n.columns,o=r[this.origin],s=r[this.origin+1],a=r[this.origin+2],l=r[this.toward],c=r[this.toward+1],u=r[this.toward+2],d=this.maxColumn===255?null:r[this.maxColumn],h=n.params[3],p=this.distance===255?null:r[this.distance],m=this.node===255?null:r[this.node],f=this.instance===255?null:r[this.instance],y=this.triangle===255?null:r[this.triangle],b=this.mask===255?null:r[this.mask],A=this.found,E=this.from,R=this.along,g=n.count,v=e===null?g:e.length,x=t===null?null:t.rows,O=0;for(let N=0;N<v;N++){let I=e===null?N:e.rows[N];if(I>=g)continue;E[0]=o[I],E[1]=s[I],E[2]=a[I];let S=l[I],w=c[I],U=u[I],L=Number.isFinite(E[0])&&Number.isFinite(E[1])&&Number.isFinite(E[2])&&Number.isFinite(S)&&Number.isFinite(w)&&Number.isFinite(U),k;if(this.sight){let Y=bi(S-E[0]),te=bi(w-E[1]),Z=bi(U-E[2]),de=bi(Math.sqrt(bi(bi(bi(Y*Y)+bi(te*te))+bi(Z*Z))));de>0?(R[0]=bi(Y/de),R[1]=bi(te/de),R[2]=bi(Z/de)):R.fill(0),k=de;}else R[0]=S,R[1]=w,R[2]=U,k=d===null?h:d[I];k=k>=0?k<1e7?k:1e7:0;let M=L&&k>0&&this.graphics.raycast(E,R,A,k,this.layers),K=this.sight?L&&!M:M;p!==null&&(p[I]=M?A.distance:k),this.point!==255&&(r[this.point][I]=M?A.point[0]:0,r[this.point+1][I]=M?A.point[1]:0,r[this.point+2][I]=M?A.point[2]:0),m!==null&&(m[I]=M?A.node:4294967295),f!==null&&(f[I]=M?A.instance:4294967295),y!==null&&(y[I]=M?A.triangle:4294967295),this.uv!==255&&(r[this.uv][I]=M?A.uv[0]:0,r[this.uv+1][I]=M?A.uv[1]:0),b!==null&&(b[I]=K?1:0),K&&(x!==null&&(x[O]=I),O++);}return t!==null&&(n.header[160+2*t.index+1]=O),O}};var J=Math.fround;var $e=-4,Xs=16,gM=11,d_=1<<gM,yM=3,AM=d_-1,yte=2147483648,g6e=-1918454973,E6e=-669632447,x6e=-887442657,pte=2147483647,mte=-2147483648,Uc=-1,bM=-2,EM=4294967295;function u_(i,e){return i<e?i:e}function Yx(i,e){return i>e?i:e}function Wr(i){return i>=pte?pte:i<=mte?mte:i|0}function v6e(i){return (i^(i>>31|yte))>>>0}var jx=class{constructor(e){this.keys=null;this.spareKeys=null;this.rows=null;this.spareRows=null;this.counts=null;this.accumulators=new Float32Array(Xs);this.points=null;this.gridRows=null;this.starts=null;this.cells=null;this.items=null;this.gridLen=0;this.slotItems=null;this.slotCounts=null;this.inv=new xM;this.gathered=null;this.marks=null;this.mark=0;this.center=new Float64Array(4);this.v=e,this.inverseCell=J(1/J(e.cell)),this.mask=e.gridTable-1;}count(){return Math.min(this.v.header[4],this.v.capacity)}listLen(e){return Math.min(this.v.header[160+2*e+1],this.v.capacity)}guest(){return this.v.header[7]===0}validList(e){return e===255||e>=0&&e<this.v.lists.length}f32(e){return e>=0&&e<this.v.columns.length&&this.v.kinds[e]===0?this.v.columns[e]:null}turn(e){if(e>1||e<0)return $e;let t=this.v.header;return t[7]!==e&&(t[7]=e,t[8]=t[8]+1>>>0),t[8]}remove(e){if(!this.guest())return $e;let t=this.count();if(e>=t||e<0)return $e;let n=t-1;if(e!==n){let r=this.v.columns;for(let o=0;o<r.length;o++)r[o][e]=r[o][n];}return this.v.header[4]=n,n}map(e,t,n,r,o){if(!this.guest()||e<0||e>13||!this.validList(o))return $e;let s=e===2||e===3||e===4||e===7||e===8||e===9||e===12,a=this.f32(t),l=e===0?a:this.f32(n),c=s?this.f32(r):l;if(a===null||l===null||c===null)return $e;let u=this.count();return o===255?fte(e,a,l,c,this.v.params,null,u,u):fte(e,a,l,c,this.v.params,this.v.lists[o],this.listLen(o),u)}vector(e,t,n,r,o,s){if(!this.guest()||e<0||e>2||!this.validList(s))return $e;let a=this.f32(t),l=this.f32(n),c=r===255?null:this.f32(r),u=o===255?null:this.f32(o);if(a===null||l===null||r!==255&&c===null||o!==255&&u===null)return $e;let d=this.v.params;e===0&&(d[0]=0,d[1]=0,d[2]=0);let h=d[0],p=d[1],m=d[2],f=e===2,y=this.count(),b=s===255?null:this.v.lists[s],A=b===null?y:this.listLen(s),E=0;for(let R=0;R<A;R++){let g=b===null?R:b[R];if(g>=y)continue;let v=J(l[g]-h),x=J((c===null?0:c[g])-p),O=J((u===null?0:u[g])-m),N=J(J(J(v*v)+J(x*x))+J(O*O));a[g]=f?N:Math.sqrt(N),E++;}return E}select(e,t,n,r){if(!this.guest()||t<0||t>7||e<0||e>=this.v.columns.length||!this.validList(n)||r===255||!this.validList(r))return $e;let o=this.v.kinds[e];if(o===0&&t===7)return $e;let s=this.v.columns[e],a=this.v.params,l=this.v.header,c,u;o===0?(c=a[0],u=a[1]):o===1?(c=l[16]|0,u=l[17]|0):(c=l[16],u=l[17]);let d=l[16],h=this.v.lists[r],p=this.count(),m=0;if(n===255)for(let f=0;f<p;f++)h[m]=f,m+=_te(t,s[f],c,u,d)?1:0;else {let f=this.v.lists[n],y=this.listLen(n);for(let b=0;b<y;b++){let A=f[b];h[m]=A,m+=A<p&&_te(t,s[A],c,u,d)?1:0;}}return this.v.header[160+2*r+1]=m,m}reduce(e,t,n){if(!this.guest()||e<0||e>6||t<0||t>=this.v.columns.length||!this.validList(n))return $e;let r=this.v.result,o=this.v.kinds[t],s=this.v.columns[t],a=this.count();if(o===0&&n===255&&e<=3)return e===1||e===2?this.blockedExtreme(s,a,e===2):this.blockedSum(s,a),e===3&&(r[0]=a===0?0:r[0]/a),0;let l=n===255?null:this.v.lists[n],c=n===255?a:this.listLen(n);if(e===0||e===3){let d=0,h=0;for(let p=0;p<c;p++){let m=l===null?p:l[p];m>=a||(d=o===0?J(d+s[m]):d+s[m],h++);}return r[0]=e===0?d:h===0?0:d/h,0}if(e===1||e===2){let d=e===2,h=d?Number.NEGATIVE_INFINITY:Number.POSITIVE_INFINITY;for(let p=0;p<c;p++){let m=l===null?p:l[p];if(m>=a)continue;let f=s[m];h=d?f>h?f:h:f<h?f:h;}return r[0]=h,0}if(e===4||e===5){let d=e===5,h=d?Number.NEGATIVE_INFINITY:Number.POSITIVE_INFINITY,p=-1;for(let m=0;m<c;m++){let f=l===null?m:l[m];if(f>=a)continue;let y=s[f];((d?y>h:y<h)||p<0&&y===y)&&(h=y,p=f);}return r[0]=p,0}let u=0;for(let d=0;d<c;d++){let h=l===null?d:l[d];h<a&&s[h]!==0&&u++;}return r[0]=u,0}blockedSum(e,t){let n=this.accumulators;n.fill(0);let r=t-t%Xs,o=0;for(;o<r;o+=Xs)for(let a=0;a<Xs;a++)n[a]+=e[o+a];let s=0;for(let a=0;a<Xs;a++)s=J(s+n[a]);for(;o<t;o++)s=J(s+e[o]);this.v.result[0]=s;}blockedExtreme(e,t,n){let r=this.accumulators;r.fill(n?Number.NEGATIVE_INFINITY:Number.POSITIVE_INFINITY);let o=t-t%Xs,s=0;for(;s<o;s+=Xs)for(let l=0;l<Xs;l++)r[l]=n?Yx(r[l],e[s+l]):u_(r[l],e[s+l]);let a=n?Number.NEGATIVE_INFINITY:Number.POSITIVE_INFINITY;for(let l=0;l<Xs;l++)a=n?Yx(a,r[l]):u_(a,r[l]);for(;s<t;s++)a=n?Yx(a,e[s]):u_(a,e[s]);this.v.result[0]=a;}sort(e,t,n,r){if(!this.guest()||e<0||e>=this.v.columns.length||this.v.kinds[e]===3||!this.validList(t)||n===255||!this.validList(n))return $e;let o=this.v.stride;this.keys??=new Uint32Array(o),this.spareKeys??=new Uint32Array(o),this.rows??=new Uint32Array(o),this.spareRows??=new Uint32Array(o),this.counts??=new Uint32Array(d_*yM);let s=this.keys,a=this.spareKeys,l=this.rows,c=this.spareRows,u=this.counts,d=this.v.kinds[e],h=this.v.bits[e],p=this.count(),m=0,f=t===255?null:this.v.lists[t],y=t===255?p:this.listLen(t);for(let A=0;A<y;A++){let E=f===null?A:f[A];if(E>=p)continue;let R=h[E],g=d===0?v6e(R):d===1?(R^yte)>>>0:R;r&&(g=~g>>>0),s[m]=g,l[m]=E,m++;}u.fill(0);for(let A=0;A<m;A++){let E=s[A];for(let R=0;R<yM;R++)u[R*d_+(E>>>R*gM&AM)]++;}for(let A=0;A<yM;A++){let E=A*d_,R=A*gM;if(m===0||u[E+(s[0]>>>R&AM)]===m)continue;let g=0;for(let O=0;O<d_;O++){let N=u[E+O];u[E+O]=g,g+=N;}for(let O=0;O<m;O++){let N=s[O],I=E+(N>>>R&AM),S=u[I]++;a[S]=N,c[S]=l[O];}let v=s;s=a,a=v;let x=l;l=c,c=x;}this.keys=s,this.spareKeys=a,this.rows=l,this.spareRows=c;let b=this.v.lists[n];for(let A=0;A<m;A++)b[A]=l[A];return this.v.header[160+2*n+1]=m,m}cellOf(e){return Wr(Math.floor(J(e*this.inverseCell)))}hash(e,t,n){return ((Math.imul(e,g6e)^Math.imul(t,E6e)^Math.imul(n,x6e))&this.mask)>>>0}grid(e,t,n,r){if(!this.guest()||!this.validList(r))return $e;let o=this.f32(e),s=t===255?null:this.f32(t),a=n===255?null:this.f32(n);if(o===null||t!==255&&s===null||n!==255&&a===null)return $e;let l=this.v.capacity;this.points??=new Float32Array(l*3),this.gridRows??=new Uint32Array(l),this.starts??=new Uint32Array(this.v.gridTable+1),this.cells??=new Uint32Array(l),this.items??=new Uint32Array(l);let c=this.points,u=this.gridRows,d=this.count(),h=r===255?null:this.v.lists[r],p=r===255?d:this.listLen(r),m=0;for(let A=0;A<p;A++){let E=h===null?A:h[A];E>=d||(c[m*3]=o[E],c[m*3+1]=s===null?0:s[E],c[m*3+2]=a===null?0:a[E],u[m]=E,m++);}let f=this.starts,y=this.cells,b=this.items;f.fill(0);for(let A=0;A<m;A++){let E=this.hash(this.cellOf(c[A*3]),this.cellOf(c[A*3+1]),this.cellOf(c[A*3+2]));y[A]=E,f[E+1]++;}for(let A=1;A<f.length;A++)f[A]+=f[A-1];for(let A=0;A<m;A++){let E=y[A];b[f[E]]=A,f[E]++;}for(let A=f.length-1;A>=1;A--)f[A]=f[A-1];return f[0]=0,this.gridLen=m,m}query(e,t){let n=this.v.params,r=n[0],o=n[1],s=n[2],a=n[3];if(!(a>=0))return bM;let l=this.starts,c=this.items,u=this.points,d=this.gridRows;if(l===null||c===null||u===null||d===null)return e===null?Uc:0;let h=this.inverseCell,p=0,m=Uc,f=Number.POSITIVE_INFINITY,y=Wr(Math.floor(J(J(r-a)*this.inverseCell))),b=Wr(Math.floor(J(J(o-a)*this.inverseCell))),A=Wr(Math.floor(J(J(s-a)*this.inverseCell))),E=Wr(Math.floor(J(J(r+a)*this.inverseCell))),R=Wr(Math.floor(J(J(o+a)*this.inverseCell))),g=Wr(Math.floor(J(J(s+a)*this.inverseCell))),v=J(a*a);for(let x=y;x<=E;x++)for(let O=b;O<=R;O++)for(let N=A;N<=g;N++){let I=this.hash(x,O,N),S=l[I+1];for(let w=l[I];w<S;w++){let U=c[w],L=u[U*3],k=u[U*3+1],M=u[U*3+2];if(Math.floor(J(L*h))!==x||Math.floor(J(k*h))!==O||Math.floor(J(M*h))!==N)continue;let K=J(L-r),Y=J(k-o),te=J(M-s),Z=J(J(J(K*K)+J(Y*Y))+J(te*te));if(Z>v)continue;let de=d[U];e!==null?e[p++]=de:de!==t&&(Z<f||Z===f&&de<m)&&(f=Z,m=de);}}return e===null?m:p}near(e){if(!this.guest()||e===255||!this.validList(e))return $e;let t=this.query(this.v.lists[e],0);return t===bM?$e:(this.v.header[160+2*e+1]=t,t)}nearest(e,t){if(!this.guest()||t===255||!this.validList(t))return $e;let n=this.query(null,e);if(n===bM)return $e;let r=n>=0?1:0;return r===1&&(this.v.lists[t][0]=n),this.v.header[160+2*t+1]=r,r}get gridPoints(){return this.gridLen}get views(){return this.v}ints(e){if(e<0||e>=this.v.columns.length)return null;let t=this.v.kinds[e];return t===1||t===2?this.v.bits[e]:null}rowAt(e,t){let n=t;if(e!==255){if(t>=this.listLen(e))return Uc;n=this.v.lists[e][t];}return n<this.count()?n:Uc}rowsLen(e){return e===255?this.count():this.listLen(e)}inventory(e,t,n,r,o){if(!this.guest()||e<0||e>5)return $e;let s=t&255,a=t>>>8&255,l=t>>>16&255,c=this.v.columns.length,u=s+l<=a||a+l<=s;if(l===0||l>32||s+l>c||a+l>c||!u)return $e;let d=this.v.header,h=d[20],p=h===0?EM:h,m=this.slotItems??[],f=this.slotCounts??[];this.slotItems=m,this.slotCounts=f;for(let U=0;U<l;U++){let L=this.ints(s+U),k=this.ints(a+U);if(L===null||k===null)return $e;m[U]=L,f[U]=k;}let y=this.optionalInts(d[21]),b=this.optionalInts(d[22]),A=this.optionalInts(d[23]);if(y===void 0||b===void 0||A===void 0||!this.validList(o)||!this.validList(n)||!this.validList(r))return $e;let E=r!==255,R=this.rowsLen(n);if(E)R=Math.min(R,this.rowsLen(r));else if(e===2)return $e;let g=0,v=0;if((e===3||e===4)&&(g=d[18],g>=l||e===3&&(v=d[19],v>=l)))return $e;let x=this.inv;x.items=m,x.counts=f,x.len=l,x.limit=p;let O=d[16],N=d[17],I=o===255?null:this.v.lists[o],S=0,w=0;for(let U=0;U<R;U++){let L=this.rowAt(n,U);if(L===Uc)continue;let k=L;if(E&&(k=this.rowAt(r,U),k===Uc))continue;let M=y===null?O:y[L],K=b===null?N:b[L],Y;switch(e){case 0:Y=x.give(L,M,K,b);break;case 1:Y=x.take(L,M,K);break;case 2:Y=x.transfer(L,k,M,K);break;case 3:Y=x.move(L,g,k,v);break;case 4:Y=x.split(L,g,k,K);break;default:Y=x.count(L,M,K,A);}Y&&S++,(e===5?Y:!Y)&&I!==null&&(I[w++]=L);}return o!==255&&(d[160+2*o+1]=w),S}optionalInts(e){return e===255?null:this.ints(e)??void 0}optionalF32(e){return e===255?null:this.f32(e)??void 0}collect(e){let t=this.center,n=t[0],r=t[1],o=t[2],s=t[3],a=this.starts,l=this.items,c=this.points;if(a===null||l===null||c===null)return 0;let u=this.inverseCell,d=Wr(Math.floor(J(J(n-s)*u))),h=Wr(Math.floor(J(J(r-s)*u))),p=Wr(Math.floor(J(J(o-s)*u))),m=Wr(Math.floor(J(J(n+s)*u))),f=Wr(Math.floor(J(J(r+s)*u))),y=Wr(Math.floor(J(J(o+s)*u))),b=J(s*s),A=0;for(let E=d;E<=m;E++)for(let R=h;R<=f;R++)for(let g=p;g<=y;g++){let v=this.hash(E,R,g),x=a[v+1];for(let O=a[v];O<x;O++){let N=l[O],I=c[N*3],S=c[N*3+1],w=c[N*3+2];if(Math.floor(J(I*u))!==E||Math.floor(J(S*u))!==R||Math.floor(J(w*u))!==g)continue;let U=J(I-n),L=J(S-r),k=J(w-o);J(J(J(U*U)+J(L*L))+J(k*k))>b||(e[A++]=N);}}return A}effect(e,t,n,r){if(!this.guest()||e!==null&&!e.guest())return $e;let o=this.v.header,s=o[23];if(s>3)return $e;let a=this.f32(n),l=this.optionalF32(o[24]);if(a===null||l===void 0||!this.validList(r))return $e;let c=e??this;if(!c.validList(t)||e===null&&r!==255&&t===r)return $e;let u=c.f32(o[16]),d=c.optionalF32(o[17]),h=c.optionalF32(o[18]),p=c.optionalF32(o[19]),m=c.optionalF32(o[21]);if(u===null||d===void 0||h===void 0||p===void 0||m===void 0)return $e;let f=this.v.params,y=f[9],b=f[10],A=f[4],E=f[6],R=e===null&&(o[27]&1)!==0,g=J(J(this.v.cell)*16),v=this.count(),x=this.v.capacity;this.gathered??=new Uint32Array(x),this.marks??=new Uint32Array(x);let O=this.gathered,N=this.marks;r!==255&&(this.mark=this.mark+1>>>0,this.mark===0&&(N.fill(0),this.mark=1));let I=this.mark,S=r===255?null:this.v.lists[r],w=this.points,U=this.gridRows,L=c.rowsLen(t),k=0,M=0;for(let K=0;K<L;K++){let Y=c.rowAt(t,K);if(Y===Uc)continue;let te=u[Y],Z=d===null?0:d[Y],de=h===null?0:h[Y],Oe=p===null?A:p[Y],be=m===null?E:m[Y];if(!Number.isFinite(te)||!Number.isFinite(Z)||!Number.isFinite(de)||!(Oe>0)||!Number.isFinite(be))continue;Oe=u_(Oe,g);let ke=this.center;ke[0]=te,ke[1]=Z,ke[2]=de,ke[3]=Oe;let De=this.collect(O);if(!(De===0||w===null||U===null))for(let Fe=0;Fe<De;Fe++){let Ze=O[Fe],wt=U[Ze];if(wt>=v||R&&wt===Y)continue;let q=J(w[Ze*3]-te),he=J(w[Ze*3+1]-Z),ot=J(w[Ze*3+2]-de),Vt=J(Math.sqrt(J(J(J(q*q)+J(he*he))+J(ot*ot)))),_t=J(Vt/Oe),dt=J(1-(_t<1?_t:1)),_n=s===0?1:s===1?dt:J(s===2?dt*dt:J(dt*dt)*J(3-J(2*dt))),Bn=J(be*_n);l!==null&&(Bn=J(Bn*l[wt]));let Zr=J(a[wt]-Bn);a[wt]=u_(Yx(Zr,y),b),k++,S!==null&&N[wt]!==I&&(N[wt]=I,S[M++]=wt);}}return r!==255&&(o[160+2*r+1]=M),k}},xM=class{constructor(){this.items=[];this.counts=[];this.len=0;this.limit=EM;}holds(e,t,n){return this.counts[e][t]>0&&this.items[e][t]===n}set(e,t,n,r){this.items[e][t]=r===0?0:n,this.counts[e][t]=r;}held(e,t){let n=0;for(let r=0;r<this.len;r++)this.holds(r,e,t)&&(n+=this.counts[r][e]);return n}room(e,t){let n=0;for(let r=0;r<this.len;r++){let o=this.counts[r][e];o===0?n+=this.limit:this.items[r][e]===t&&(n+=o>=this.limit?0:this.limit-o);}return n}add(e,t,n){let r=n;for(let o=0;o<this.len&&r>0;o++){if(!this.holds(o,e,t))continue;let s=this.counts[o][e],a=Math.min(r,s>=this.limit?0:this.limit-s);this.set(o,e,t,s+a),r-=a;}for(let o=0;o<this.len&&r>0;o++){if(this.counts[o][e]!==0)continue;let s=Math.min(r,this.limit);this.set(o,e,t,s),r-=s;}return n-r}remove(e,t,n){let r=n;for(let o=this.len-1;o>=0&&r>0;o--){if(!this.holds(o,e,t))continue;let s=this.counts[o][e],a=Math.min(r,s);this.set(o,e,t,s-a),r-=a;}}give(e,t,n,r){if(n===0)return true;if(t===0)return false;let o=this.add(e,t,n);return r!==null&&(r[e]=n-o),o===n}take(e,t,n){return n===0?true:t===0||this.held(e,t)<n?false:(this.remove(e,t,n),true)}transfer(e,t,n,r){return r===0||e===t?r===0||n!==0&&this.held(e,n)>=r:n===0||this.held(e,n)<r||this.room(t,n)<r?false:(this.remove(e,n,r),this.add(t,n,r),true)}move(e,t,n,r){if(e===n&&t===r)return true;let o=this.counts[t][e];if(o===0)return false;let s=this.items[t][e],a=this.counts[r][n];if(a===0)return this.set(r,n,s,o),this.set(t,e,s,0),true;let l=this.items[r][n];if(l===s){let c=Math.min(o,a>=this.limit?0:this.limit-a);return c===0?false:(this.set(r,n,s,a+c),this.set(t,e,s,o-c),true)}return this.set(r,n,s,o),this.set(t,e,l,a),true}split(e,t,n,r){let o=this.counts[t][e];if(r===0||r>o)return false;let s=-1;for(let l=0;l<this.len;l++)if(this.counts[l][n]===0){s=l;break}if(s<0)return false;let a=this.items[t][e];return this.set(s,n,a,r),this.set(t,e,a,o-r),true}count(e,t,n,r){let o=t===0?0:this.held(e,t);return r!==null&&(r[e]=Math.min(o,EM)),o>=n}},R6e=[(i,e,t,n,r,o,s)=>{let a=n[0];if(r===null){for(let c=0;c<o;c++)i[c]=a;return o}let l=0;for(let c=0;c<o;c++){let u=r[c];u<s&&(i[u]=a,l++);}return l},(i,e,t,n,r,o,s)=>{if(r===null){for(let l=0;l<o;l++)i[l]=e[l];return o}let a=0;for(let l=0;l<o;l++){let c=r[l];c<s&&(i[c]=e[c],a++);}return a},(i,e,t,n,r,o,s)=>{if(r===null){for(let l=0;l<o;l++)i[l]=e[l]+t[l];return o}let a=0;for(let l=0;l<o;l++){let c=r[l];c<s&&(i[c]=e[c]+t[c],a++);}return a},(i,e,t,n,r,o,s)=>{if(r===null){for(let l=0;l<o;l++)i[l]=e[l]-t[l];return o}let a=0;for(let l=0;l<o;l++){let c=r[l];c<s&&(i[c]=e[c]-t[c],a++);}return a},(i,e,t,n,r,o,s)=>{if(r===null){for(let l=0;l<o;l++)i[l]=e[l]*t[l];return o}let a=0;for(let l=0;l<o;l++){let c=r[l];c<s&&(i[c]=e[c]*t[c],a++);}return a},(i,e,t,n,r,o,s)=>{let a=n[0];if(r===null){for(let c=0;c<o;c++)i[c]=e[c]*a;return o}let l=0;for(let c=0;c<o;c++){let u=r[c];u<s&&(i[u]=e[u]*a,l++);}return l},(i,e,t,n,r,o,s)=>{let a=n[0];if(r===null){for(let c=0;c<o;c++)i[c]=e[c]+a;return o}let l=0;for(let c=0;c<o;c++){let u=r[c];u<s&&(i[u]=e[u]+a,l++);}return l},(i,e,t,n,r,o,s)=>{let a=n[0];if(r===null){for(let c=0;c<o;c++)i[c]=e[c]+J(t[c]*a);return o}let l=0;for(let c=0;c<o;c++){let u=r[c];u<s&&(i[u]=e[u]+J(t[u]*a),l++);}return l},(i,e,t,n,r,o,s)=>{if(r===null){for(let l=0;l<o;l++)i[l]=e[l]<t[l]?e[l]:t[l];return o}let a=0;for(let l=0;l<o;l++){let c=r[l];c<s&&(i[c]=e[c]<t[c]?e[c]:t[c],a++);}return a},(i,e,t,n,r,o,s)=>{if(r===null){for(let l=0;l<o;l++)i[l]=e[l]>t[l]?e[l]:t[l];return o}let a=0;for(let l=0;l<o;l++){let c=r[l];c<s&&(i[c]=e[c]>t[c]?e[c]:t[c],a++);}return a},(i,e,t,n,r,o,s)=>{let a=n[0],l=n[1];if(r===null){for(let u=0;u<o;u++){let d=e[u]>a?e[u]:a;i[u]=d<l?d:l;}return o}let c=0;for(let u=0;u<o;u++){let d=r[u];if(d<s){let h=e[d]>a?e[d]:a;i[d]=h<l?h:l,c++;}}return c},(i,e,t,n,r,o,s)=>{if(r===null){for(let l=0;l<o;l++)i[l]=Math.abs(e[l]);return o}let a=0;for(let l=0;l<o;l++){let c=r[l];c<s&&(i[c]=Math.abs(e[c]),a++);}return a},(i,e,t,n,r,o,s)=>{let a=n[0];if(r===null){for(let c=0;c<o;c++)i[c]=e[c]+J(J(t[c]-e[c])*a);return o}let l=0;for(let c=0;c<o;c++){let u=r[c];u<s&&(i[u]=e[u]+J(J(t[u]-e[u])*a),l++);}return l},(i,e,t,n,r,o,s)=>{if(r===null){for(let l=0;l<o;l++)i[l]=-e[l];return o}let a=0;for(let l=0;l<o;l++){let c=r[l];c<s&&(i[c]=-e[c],a++);}return a}];function fte(i,e,t,n,r,o,s,a){return R6e[i](e,t,n,r,o,s,a)}function _te(i,e,t,n,r){switch(i){case 0:return e<t;case 1:return e<=t;case 2:return e>t;case 3:return e>=t;case 4:return e===t;case 5:return e!==t;case 7:return (e>>>0&r)!==0;default:return t<=e&&e<n}}function Ate(i,e,t,n){switch(e){case 0:return new Float32Array(i,t,n);case 1:return new Int32Array(i,t,n);case 3:return new Uint8Array(i,t,n);default:return new Uint32Array(i,t,n)}}function bte(i,e,t,n){return uC(e)===4?new Uint32Array(i,t,n):null}var P6e=4,F6e=4,tv=new Uint32Array(256).fill(1),BM=new Uint8Array(256),U6e={"<":0,"<=":1,">":2,">=":3,"==":4,"!=":5,range:6,bits:7},Ite={f32:0,i32:1,u32:2,u8:3},B6e={vec2:2,vec3:3,vec4:4},Tte=-1,G6e=/^(f32|i32|u32|u8)\[(\d+)\]$/,V6e=32;function rv(i){let e=G6e.exec(i);if(e===null)return null;let t=Number(e[2]);return t>=1&&t<=V6e?{kind:Ite[e[1]],length:t}:null}function iv(i){return i==="f64"||i==="u64"}var H6e=2,ov=new Float64Array(1),nv=new Uint32Array(ov.buffer),GM=class{constructor(e,t,n){this.kind=n;this.root=e,this.lo=t[0],this.hi=t[1];}get(){let e=this.root.$row;return this.kind==="u64"?BigInt(this.hi[e])<<32n|BigInt(this.lo[e]):(nv[0]=this.lo[e],nv[1]=this.hi[e],ov[0])}set(e){let t=this.root.$row;if(this.kind==="u64"){let r=BigInt.asUintN(64,typeof e=="bigint"?e:BigInt(Math.trunc(e)));this.lo[t]=Number(r&0xffffffffn),this.hi[t]=Number(r>>32n);return}ov[0]=Number(e);let n=Number.isNaN(ov[0]);this.lo[t]=n?0:nv[0],this.hi[t]=n?2146959360:nv[1];}detach(){this.lo=new Uint32Array(0),this.hi=new Uint32Array(0);}};function W6e(i){return iv(i)?H6e:i==="vec2"||i==="vec3"||i==="vec4"?B6e[i]:rv(i)?.length??1}function sv(i){return i==="f32"||i==="i32"||i==="u32"||i==="u8"}var VM=class{constructor(){this.$row=0;}},K6e=new Set(["row","$root","$slots"]),wte=new Map;function Y6e(i,e){let t=i.map(s=>`${s}:${e[s]}`).join(","),n=wte.get(t);if(n)return n;let r={};Object.defineProperty(r,"row",{get(){return this.$root.$row},enumerable:true});let o=0;for(let s of i){if(!sv(e[s]))continue;let a=o++;Object.defineProperty(r,s,{get(){return this.$slots[a].values[this.$root.$row]},set(l){this.$slots[a].values[this.$root.$row]=l;},enumerable:true});}return wte.set(t,r),r}var fl=new Float32Array(0),X6e=["x","y","z","w"],HM=class{constructor(e){this.values=e;}},WM=class{constructor(e,t){this.root=e,this.arrays=t;}get length(){return this.arrays.length}get(e){return this.arrays[e][this.root.$row]}set(e,t){this.arrays[e][this.root.$row]=t;}detach(){this.arrays=this.arrays.map(()=>fl);}},lv=class{constructor(e,t){this.root=e,this.xs=t[0],this.ys=t[1];}detach(){this.xs=fl,this.ys=fl;}get x(){return this.xs[this.root.$row]}set x(e){this.xs[this.root.$row]=e;}get y(){return this.ys[this.root.$row]}set y(e){this.ys[this.root.$row]=e;}},cv=class extends lv{constructor(e,t){super(e,t),this.zs=t[2];}detach(){super.detach(),this.zs=fl;}get z(){return this.zs[this.root.$row]}set z(e){this.zs[this.root.$row]=e;}},KM=class extends cv{constructor(e,t){super(e,t),this.ws=t[3];}detach(){super.detach(),this.ws=fl;}get w(){return this.ws[this.root.$row]}set w(e){this.ws[this.root.$row]=e;}},YM=class{constructor(e,t,n){this.index=e,this.rows=t,this.header=n;}get length(){return Math.min(this.header[160+2*this.index+1],this.rows.length)}set length(e){this.header[160+2*this.index+1]=Math.min(e,this.rows.length);}at(e){return this.rows[e]}},vh=class{constructor(e,t,n){this.state=new VM;this.accumulator=new Float64Array(1);this.scalarSlots=[];this.vectorCursors=[];this.slotCursors=[];this.wideCursors=[];this.disposed=false;let r=n.capacity,o=n.selections??P6e,s=n.cell??F6e,a=n.gridTable??16384;if(!Number.isInteger(r)||r<=0)throw new _("invalid_argument","a table needs a positive integer capacity");if(!Number.isInteger(o)||o<0||o>16)throw new _("invalid_argument",`a table holds 0..${16} selections`);if(!(s>0)||!Number.isFinite(s))throw new _("invalid_argument","the spatial cell must be a positive size");if(a<=0||(a&a-1)!==0)throw new _("invalid_argument","the grid table size must be a power of two");let l=[],c={},u={};for(let E of Object.keys(t)){if(K6e.has(E))throw new _("invalid_argument",`${E} is reserved by the cursor`);let R=t[E],g=W6e(R),v=[];for(let x=0;x<g;x++)v.push(l.length),l.push(sv(R)?Ite[R]:iv(R)?2:rv(R)?.kind??0);if(v.length===0||l.some(x=>x===void 0))throw new _("invalid_argument",`unknown field kind ${String(R)} for ${E}`);c[E]=Object.freeze(v),u[E]=v[0];}if(l.length===0||l.length>64)throw new _("invalid_argument",`a table holds 1..${64} columns`);this.schema=t,this.capacity=r,this.fields=Object.freeze(c),this.first=Object.freeze(u),this.engine=e,this.native=e!==null;let d,h;if(e){let E=e.exports,R=5+l.length,g=E.engine_alloc(R*4,4);if(g===0)throw new _("capacity_exceeded","engine memory cannot hold a table descriptor");let v=new Uint32Array(e.memory.buffer,g,R);v[0]=r,v[1]=l.length,v[2]=o,v[3]=new Uint32Array(new Float32Array([s]).buffer)[0],v[4]=a;for(let O=0;O<l.length;O++)v[5+O]=l[O];let x=E.engine_soa_create(g);if(E.engine_free(g,R*4,4),x<=0)throw new _(x===-1?"capacity_exceeded":"invalid_argument",`the engine refused the table (${x})`);this.id=x,d=e.memory.buffer,h=E.engine_soa_header(x),this.generations=new Uint32Array(d,E.engine_soa_generations(),256);}else {let E=BM.indexOf(0);if(E<0)throw new _("capacity_exceeded",`at most ${256} tables are live at once`);BM[E]=1,this.id=(tv[E]<<8|E)>>>0;let R=JY(r),g=768,v=[];for(let N of l)v.push(g),g+=ZY(N,R);let x=g;g+=o*R*4,d=new ArrayBuffer(Math.ceil(g/64)*64),h=0;let O=new Uint32Array(d,0,192);O[0]=826363731,O[1]=1,O[2]=this.id,O[3]=r,O[5]=l.length,O[6]=o,O[9]=R;for(let N=0;N<l.length;N++)O[32+2*N]=v[N],O[32+2*N+1]=l[N];for(let N=0;N<o;N++)O[160+2*N]=x+N*R*4;this.generations=tv;}if(this.slot=this.id&255,this.generation=this.id>>>8,this.header=new Uint32Array(d,h,192),this.header[0]!==826363731)throw new _("invalid_argument","the engine table header has an unknown layout");let p=this.header[9];this.params=new Float32Array(d,h+64,16),this.result=new Float64Array(d,h+40,1);let m=[],f=[];for(let E=0;E<l.length;E++){let R=this.header[32+2*E];m.push(Ate(d,l[E],R,r)),f.push(bte(d,l[E],R,r));}let y=[],b=[];for(let E=0;E<o;E++){let R=new Uint32Array(d,this.header[160+2*E],r);y.push(R),b.push(new YM(E,R,this.header));}this.columns=Object.freeze(m),this.selections=Object.freeze(b);let A={header:this.header,params:this.params,result:this.result,capacity:r,stride:p,kinds:l,columns:m,bits:f,lists:y,cell:s,gridTable:a};this.fallback=new jx(A),this.cursorObject=this.buildCursor(),this.cols=this.buildColumns();}buildColumns(){let e={};for(let t of Object.keys(this.schema)){let n=this.fields[t];if(sv(this.schema[t])){e[t]=this.columns[n[0]];continue}if(rv(this.schema[t])!==null||iv(this.schema[t])){e[t]=Object.seal(n.map(o=>this.columns[o]));continue}let r={};for(let o=0;o<n.length;o++)r[X6e[o]]=this.columns[n[o]];e[t]=Object.seal(r);}return Object.seal(e)}detachColumns(){let e=this.cols;for(let t of Object.keys(e)){let n=e[t];if(ArrayBuffer.isView(n)){e[t]=fl;continue}for(let r of Object.keys(n))n[r]=fl;}}buildCursor(){let e=Object.keys(this.schema),t=Object.create(Y6e(e,this.schema));t.$root=this.state,t.$slots=this.scalarSlots;for(let n of e){let r=this.fields[n];if(sv(this.schema[n])){this.scalarSlots.push(new HM(this.columns[r[0]]));continue}let o=this.schema[n];if(iv(o)){let l=new GM(this.state,[this.columns[r[0]],this.columns[r[1]]],o);this.wideCursors.push(l),Object.defineProperty(t,n,{get:()=>l.get(),set:c=>l.set(c),enumerable:true});continue}if(rv(this.schema[n])!==null){let l=new WM(this.state,r.map(c=>this.columns[c]));this.slotCursors.push(l),Object.defineProperty(t,n,{value:Object.seal(l),enumerable:true});continue}let s=r.map(l=>this.columns[l]),a=r.length===2?new lv(this.state,s):r.length===3?new cv(this.state,s):new KM(this.state,s);this.vectorCursors.push(a),Object.defineProperty(t,n,{value:Object.seal(a),enumerable:true});}return Object.seal(t)}get valid(){return !this.disposed&&this.header.length!==0&&this.generations[this.slot]===this.generation}get version(){return this.generation}get frame(){return this.header[8]}get count(){return Math.min(this.header[4],this.capacity)}set count(e){if(this.check(),!Number.isInteger(e)||e<0||e>this.capacity)throw new _("invalid_argument",`count must be 0..${this.capacity}`);this.header[4]=e;}check(){if(this.generations[this.slot]!==this.generation||this.disposed)throw new _("unknown_resource","this table was disposed; its views are stale");if(this.header[7]!==0)throw new _("invalid_argument","the engine holds this table's turn")}column(e,t=0){let n=this.fields[e];if(n===void 0||t<0||t>=n.length)throw new _("invalid_argument",`no column ${e}[${t}]`);return n[t]}f32(e,t=0){let n=this.columns[this.column(e,t)];if(!(n instanceof Float32Array))throw new _("invalid_argument",`${e} is not an f32 field`);return n}values(e,t=0){return this.columns[this.column(e,t)]}at(e){return this.state.$row=e,this.cursorObject}get cursor(){return this.cursorObject}spawn(){this.check();let e=this.header[4];if(e>=this.capacity)throw new _("capacity_exceeded",`table capacity ${this.capacity} reached`);let t=this.columns;for(let n=0;n<t.length;n++)t[n][e]=0;return this.header[4]=e+1,e}remove(e){return this.check(),this.status(this.engine?this.engine.exports.engine_soa_remove(this.id,e):this.fallback.remove(e))}handTo(e){if(this.generations[this.slot]!==this.generation||this.disposed)throw new _("unknown_resource","this table was disposed; its views are stale");let t=e==="engine"?1:0;return this.status(this.engine?this.engine.exports.engine_soa_turn(this.id,t):this.fallback.turn(t))}status(e){if(e>=0)return e;throw e===-3?new _("unknown_resource","this table was disposed; its views are stale"):e===-1?new _("capacity_exceeded","the table is full"):new _("invalid_argument",`the table refused the operation (${e})`)}$indices(e){let t=this.fields[e];if(t===void 0)throw new _("invalid_argument",`no field ${e}`);return t}$kind(e){return this.header[32+2*e+1]}$ready(){this.check();}$status(e){return this.status(e)}get $bulk(){return this.engine?.bulk??null}get $fallback(){return this.fallback}inventory(e,t,n=0){return new Nx(this,e,t,n)}areaEffect(e,t){return new kx(this,e,t)}rays(e,t){return new a_(this,e,t,false)}lineOfSight(e,t){return new a_(this,e,t,true)}paths(e,t){return new Lx(this,e,t)}picks(e,t){return new Kx(this,e,t)}flowField(e){return new Hx(e,this.engine)}flow(e,t){return new Wx(this,e,t)}list(e){return e?e.index:255}mapColumns(e,t,n,r,o){this.check();let s=this.fields[t],a=this.fields[n],l=this.fields[r];if(s===void 0||a===void 0||l===void 0)throw new _("invalid_argument",`unknown field in ${t}, ${n}, ${r}`);let c=s.length;if(a.length!==c&&a.length!==1||l.length!==c&&l.length!==1)throw new _("invalid_argument",`${t}, ${n} and ${r} have different widths`);let u=this.list(o),d=0;for(let h=0;h<c;h++){let p=a[a.length===1?0:h],m=l[l.length===1?0:h];d=this.status(this.engine?this.engine.exports.engine_soa_map(this.id,e,s[h],p,m,u):this.fallback.map(e,s[h],p,m,u));}return d}fill(e,t,n){return this.params[0]=t,this.mapColumns(0,e,e,e,n)}copy(e,t,n){return this.mapColumns(1,e,t,t,n)}add(e,t,n,r){return this.mapColumns(2,e,t,n,r)}sub(e,t,n,r){return this.mapColumns(3,e,t,n,r)}mul(e,t,n,r){return this.mapColumns(4,e,t,n,r)}min(e,t,n,r){return this.mapColumns(8,e,t,n,r)}max(e,t,n,r){return this.mapColumns(9,e,t,n,r)}scale(e,t,n,r){return this.params[0]=n,this.mapColumns(5,e,t,t,r)}offset(e,t,n,r){return this.params[0]=n,this.mapColumns(6,e,t,t,r)}axpy(e,t,n,r,o){return this.params[0]=r,this.mapColumns(7,e,t,n,o)}integrate(e,t,n,r){return this.params[0]=n,this.mapColumns(7,e,e,t,r)}clamp(e,t,n,r,o){return this.params[0]=n,this.params[1]=r,this.mapColumns(10,e,t,t,o)}abs(e,t,n){return this.mapColumns(11,e,t,t,n)}neg(e,t,n){return this.mapColumns(13,e,t,t,n)}lerp(e,t,n,r,o){return this.params[0]=r,this.mapColumns(12,e,t,n,o)}vectorOp(e,t,n,r,o,s,a){this.check();let l=this.fields[t],c=this.fields[n];if(l===void 0||l.length!==1||c===void 0||c.length<2)throw new _("invalid_argument",`${t} must be a scalar and ${n} a vector`);this.params[0]=r,this.params[1]=o,this.params[2]=s;let u=this.list(a),d=c.length>2?c[2]:255;return this.status(this.engine?this.engine.exports.engine_soa_vec(this.id,e,l[0],c[0],c[1],d,u):this.fallback.vector(e,l[0],c[0],c[1],d,u))}length(e,t,n){return this.vectorOp(0,e,t,0,0,0,n)}distance(e,t,n,r,o,s){return this.vectorOp(1,e,t,n,r,o,s)}distanceSquared(e,t,n,r,o,s){return this.vectorOp(2,e,t,n,r,o,s)}select(e,t,n,r,o=0,s){this.check();let a=this.first[t],l=U6e[n];if(a===void 0||l===void 0)throw new _("invalid_argument",`cannot select on ${t} with ${n}`);this.header[32+2*a+1]===0?(this.params[0]=r,this.params[1]=o):(this.header[16]=r,this.header[17]=o);let u=this.list(s);return this.status(this.engine?this.engine.exports.engine_soa_select(this.id,a,l,u,e.index):this.fallback.select(a,l,u,e.index))}reduceOp(e,t,n){this.check();let r=this.first[t];if(r===void 0||this.fields[t].length!==1)throw new _("invalid_argument",`${t} is not a scalar field`);let o=this.list(n);this.status(this.engine?this.engine.exports.engine_soa_reduce(this.id,e,r,o):this.fallback.reduce(e,r,o));}sum(e,t){return this.reduceOp(0,e,t),this.result[0]}mean(e,t){return this.reduceOp(3,e,t),this.result[0]}minimum(e,t){return this.reduceOp(1,e,t),this.result[0]}maximum(e,t){return this.reduceOp(2,e,t),this.result[0]}argmin(e,t){return this.reduceOp(4,e,t),this.result[0]}argmax(e,t){return this.reduceOp(5,e,t),this.result[0]}countNonZero(e,t){return this.reduceOp(6,e,t),this.result[0]}sort(e,t,n=false,r){this.check();let o=this.first[t];if(o===void 0)throw new _("invalid_argument",`unknown field ${t}`);let s=this.list(r);return this.status(this.engine?this.engine.exports.engine_soa_sort(this.id,o,s,e.index,n?1:0):this.fallback.sort(o,s,e.index,n))}buildGrid(e,t){this.check();let n=this.fields[e];if(n===void 0||n.length<2||this.header[32+2*n[0]+1]!==0)throw new _("invalid_argument",`${e} must be a vec2, vec3 or vec4 field`);let r=this.list(t),o=n.length>2?n[2]:255;return this.status(this.engine?this.engine.exports.engine_soa_grid(this.id,n[0],n[1],o,r):this.fallback.grid(n[0],n[1],o,r))}center(e,t,n,r){this.params[0]=e,this.params[1]=t,this.params[2]=n,this.params[3]=r;}near(e,t,n,r,o){return this.check(),this.center(t,n,r,o),this.status(this.engine?this.engine.exports.engine_soa_near(this.id,e.index):this.fallback.near(e.index))}nearest(e,t,n,r,o,s=Tte){this.check(),this.center(t,n,r,o);let a=s<0?4294967295:s;return this.status(this.engine?this.engine.exports.engine_soa_nearest(this.id,a,e.index):this.fallback.nearest(a,e.index))===0?Tte:e.rows[0]}each(e,t){this.check();let n=this.cols,r=this.count;if(t){let o=t.rows,s=t.length;for(let a=0;a<s;a++){let l=o[a];l<r&&e(l,n);}return}for(let o=0;o<r;o++)e(o,n);}forEach(e,t){this.check();let n=this.state,r=this.cursorObject;if(t){let s=t.rows,a=t.length,l=this.count;for(let c=0;c<a;c++){let u=s[c];u>=l||(n.$row=u,e(r,u));}return}let o=this.count;for(let s=0;s<o;s++)n.$row=s,e(r,s);}map(e,t,n){this.check();let r=this.columns[this.first[e]],o=this.state,s=this.cursorObject,a=this.accumulator;if(n){let c=n.rows,u=n.length,d=this.count;for(let h=0;h<u;h++){let p=c[h];p>=d||(o.$row=p,a[0]=r[p],t(s,a,p),r[p]=a[0]);}return}let l=this.count;for(let c=0;c<l;c++)o.$row=c,a[0]=r[c],t(s,a,c),r[c]=a[0];}reduce(e,t=0,n){return this.accumulator[0]=t,this.reduceRows(e,n),this.accumulator[0]}reduceRows(e,t){this.check();let n=this.state,r=this.cursorObject,o=this.accumulator;if(t){let a=t.rows,l=t.length,c=this.count;for(let u=0;u<l;u++){let d=a[u];d>=c||(n.$row=d,e(o,r,d));}return}let s=this.count;for(let a=0;a<s;a++)n.$row=a,e(o,r,a);}dispose(){if(!this.disposed){this.disposed=true;for(let e of this.scalarSlots)e.values=fl;for(let e of this.vectorCursors)e.detach();for(let e of this.slotCursors)e.detach();for(let e of this.wideCursors)e.detach();if(this.detachColumns(),this.engine){this.engine.exports.engine_soa_destroy(this.id);return}tv[this.slot]===this.generation&&(tv[this.slot]=this.generation+1&(1<<23)-1||1,BM[this.slot]=0);}}};function Ote(i,e){return i===void 0?gs:typeof i=="boolean"?i?gs:lc:e?i!==0?gs:lc:i===gs||i===yC?i:lc}function Rh(i,e,t){switch(i.kind){case "condition":return Ote(i.leaf(e,...t),true);case "action":return Ote(i.leaf(e,...t),false);case "invert":{let n=Rh(i.children[0],e,t);return n===yC?n:n===gs?lc:gs}case "sequence":for(let n of i.children){let r=Rh(n,e,t);if(r!==gs)return r}return gs;case "selector":for(let n of i.children){let r=Rh(n,e,t);if(r!==lc)return r}return lc}}function Cte(i){}var yl=4,_l=8,uv=256,dv=64,Sh=2,z6e=3,Q6e=4,$6e=5,j6e=8,J6e=1;function Z6e(i){return i===Q6e||i===$6e?j6e:i===z6e?J6e:yl}function XM(i,e){if(i>=0)return i;throw new _("invalid_argument",`${e}: the engine refused the lockstep kernel (${i})`)}var qM=class{constructor(e,t){this.engine=e;this.runRegion=t;this.descriptorAt=0;this.argsAt=0;this.spanAt=0;this.spanBytes=0;this.arena=null;this.descriptor=new Uint32Array(0);this.args=new Uint32Array(0);this.source=new Uint8Array(0);this.target=new Uint8Array(0);this.sourceBuffer=null;this.sourceAt=-1;}load(e){let t=this.engine.exports,n=Math.max(e.byteLength,yl),r=t.engine_alloc(n,yl);if(r===0)throw new _("capacity_exceeded","engine memory cannot hold a lockstep kernel");new Uint8Array(this.engine.memory.buffer,r,e.byteLength).set(e);let o=t.engine_kernel_load(r,e.byteLength);return t.engine_free(r,n,yl),XM(o,"loading a lockstep kernel")}run(e,t,n,r,o,s){if(n.length>uv*Sh||s.length>dv)throw new _("invalid_argument","a lockstep kernel has too many columns or argument words for the engine");if(this.views(),this.args.set(s),t===this.arena)return this.descriptor.set(n),XM(this.runRegion(e,this.descriptorAt,o,r,this.argsAt,s.length),"running a lockstep kernel");let a=Number.POSITIVE_INFINITY,l=0;for(let d=0;d<n.length;d+=Sh){let h=n[d],p=h+o*Z6e(n[d+1]);h<a&&(a=h),p>l&&(l=p);}a-=a%_l;let c=l-a;this.span(t,a,c);for(let d=0;d<n.length;d+=Sh)this.descriptor[d]=this.spanAt+n[d]-a,this.descriptor[d+1]=n[d+1];this.target.set(this.source);let u=XM(this.runRegion(e,this.descriptorAt,o,r,this.argsAt,s.length),"running a lockstep kernel");return this.source.set(this.target),u}views(){let e=this.engine.exports;if(this.descriptorAt===0&&(this.descriptorAt=e.engine_alloc(uv*Sh*yl,_l),this.argsAt=e.engine_alloc(dv*yl,_l),this.descriptorAt===0||this.argsAt===0))throw new _("capacity_exceeded","engine memory cannot hold lockstep kernel arguments");let t=this.engine.memory.buffer;t!==this.arena&&(this.arena=t,this.descriptor=new Uint32Array(t,this.descriptorAt,uv*Sh),this.args=new Uint32Array(t,this.argsAt,dv),this.sourceBuffer=null);}span(e,t,n){if(n>this.spanBytes){let r=this.engine.exports;if(this.spanAt!==0&&r.engine_free(this.spanAt,this.spanBytes,_l),this.spanAt=r.engine_alloc(n,_l),this.spanAt===0)throw new _("capacity_exceeded","engine memory cannot hold a lockstep table");this.spanBytes=n,this.sourceBuffer=null,this.views();}e===this.sourceBuffer&&t===this.sourceAt&&this.source.byteLength===n&&this.target.buffer===this.arena||(this.source=new Uint8Array(e,t,n),this.target=new Uint8Array(this.arena,this.spanAt,n),this.sourceBuffer=e,this.sourceAt=t);}dispose(){let e=this.engine.exports;this.descriptorAt!==0&&e.engine_free(this.descriptorAt,uv*Sh*yl,_l),this.argsAt!==0&&e.engine_free(this.argsAt,dv*yl,_l),this.spanAt!==0&&e.engine_free(this.spanAt,this.spanBytes,_l),this.descriptorAt=0,this.argsAt=0,this.spanAt=0,this.spanBytes=0,this.arena=null;}};function Nte(i){return i===null||typeof i.runRegion!="function"?null:new qM(i,i.runRegion)}function Lte(i){}function Mte(i){if(i===null)return null;let e=i.runRegion;if(typeof e!="function")return null;let t=i.exports;return {memory:i.memory,alloc:(n,r)=>t.engine_alloc(n,r),free:(n,r,o)=>{t.engine_free(n,r,o);},load:(n,r)=>t.engine_kernel_load(n,r),unload:n=>{t.engine_kernel_unload(n);},runRegion:e}}var t8e=["unknown","mobile","desktop","discrete"];var n8e=[64,44,28],r8e=4,i8e=3,Dte=4,Vte=5,Hte=4,hv={interpreter:{op:47,pair:12e3,math:3e3,gridRow:2e4,launch:5e6},cranelift:{op:40,pair:12e3,math:3400,gridRow:2e4,launch:5e6},wasm:{op:30,pair:8e3,math:3500,gridRow:25e3,launch:0}};function zM(i){let e=t=>Math.floor(t*Vte/Hte);return {op:e(i.op),pair:e(i.pair),math:e(i.math),gridRow:e(i.gridRow),launch:e(i.launch)}}var o8e={interpreter:zM(hv.interpreter),cranelift:zM(hv.cranelift),wasm:zM(hv.wasm)},s8e={setFixed:9e8,setOp:1,gather:1,launch:4e7,batchedLaunch:3e7,stage:1e7,grid:15e7,op:5,pair:25,math:700,uploadWord:80,sync:1e8,readbackWord:50,enter:51,leave:70},a8e={setFixed:1e9,setOp:1,gather:1,launch:5e7,batchedLaunch:38e6,stage:1e7,grid:12e7,op:2,pair:10,math:300,uploadWord:300,sync:2e8,readbackWord:300,enter:51,leave:70},l8e={setFixed:12e8,setOp:3,gather:3,launch:35e6,batchedLaunch:25e6,stage:15e6,grid:2e8,op:12,pair:60,math:1700,uploadWord:120,sync:15e7,readbackWord:90,enter:48,leave:70};function c8e(i){let e=i.class==="desktop"||i.class==="discrete"?hv:o8e;return e[i.backend]??e.interpreter}function JM(i){return i==="desktop"?s8e:i==="discrete"?a8e:l8e}var u8e=/Chrome\/|Chromium\/|Edg\//,d8e=/AppleWebKit\//,Fte=null;function h8e(){let i=globalThis;if(i.HermesInternal!==void 0)return "jsc-nojit";let e=i.process?.versions;if(e?.bun!==void 0)return "jsc";if(e?.v8!==void 0)return "v8";let t=i.navigator?.userAgent;return typeof t=="string"?u8e.test(t)?"v8":d8e.test(t)?"jsc":"v8":"jsc-nojit"}var p8e=Uint8Array.from([0,97,115,109,1,0,0,0,1,5,1,96,0,1,127,3,2,1,0,7,5,1,1,102,0,0,10,6,1,4,0,65,42,11]),m8e=42,y_=null;function Wte(){if(y_!==null)return y_;let i=globalThis.WebAssembly;try{let e=i===void 0?null:new i.Instance(new i.Module(p8e)).exports.f;y_=typeof e=="function"&&e()===m8e;}catch{y_=false;}return y_}function ZM(){return (Fte??=h8e(),Fte)}function Kte(i){return t8e[i]??"unknown"}function pv(i,e,t){return Math.min(Math.max(i,e),t)}function QM(i){return Math.min(i,2097152)}function b_(i){return Math.min(i,68719476736)}function A_(i,e){return Math.floor(i*e/1e3)}function Yte(i){return Math.min(i,16777216)}function mv(){return {cpuLaunch:0,cpuRow:0,cpuSerialRow:0,lanes:1,gpuFixed:0,gpuRow:0}}function Ute(i,e,t){let n=c8e(e),r=JM(e.class),o=pv(i.instructions,1,4096),s=Math.min(i.columns,256),a=Math.min(i.transcendentals,256),l=e.backend==="wasm"?1:pv(i.lanes,1,64),c=i.pairs?24:0,d=(i.batched&&!i.readback?r.batchedLaunch:r.launch)+Math.min(i.stages,64)*r.stage,h=o*r.op+a*r.math+c*r.pair;return i.pairs&&(d+=r.grid),i.resident||(h+=s*r.uploadWord),i.readback&&(d+=r.sync,h+=s*r.readbackWord),t.cpuLaunch=b_(n.launch),t.cpuRow=QM(o*n.op+c*n.pair+a*n.math),t.cpuSerialRow=QM(i.pairs?n.gridRow:0),t.lanes=l,t.gpuFixed=b_(d),t.gpuRow=QM(h),t}function f8e(i,e,t=2097152){return i.cpuLaunch=b_(A_(i.cpuLaunch,e.cpu)),i.cpuRow=Math.min(A_(i.cpuRow,e.cpu),t),i.cpuSerialRow=Math.min(A_(i.cpuSerialRow,e.cpu),t),i.gpuFixed=b_(A_(i.gpuFixed,e.gpu)),i.gpuRow=Math.min(A_(i.gpuRow,e.gpu),t),i}var Xte=16777216;function _8e(i,e){return e.cpuLaunch=i.cpuLaunch,e.cpuRow=i.cpuRow,e.cpuSerialRow=i.cpuSerialRow,e.lanes=i.lanes,e.gpuFixed=i.gpuFixed,e.gpuRow=i.gpuRow,e}var y8e={v8:{op:30,gather:1400,math:3500,step:8e3},jsc:{op:195,gather:4300,math:22e3,step:4300},"jsc-nojit":{op:1370,gather:12300,math:16e4,step:50800}};function Bte(i){return Math.min(i,16777216)}function A8e(i,e,t,n){let r=y8e[t],o=e==="script"?i.steps*r.step:i.instructions*r.op+i.gathers*r.gather+i.transcendentals*r.math;return n.class==="desktop"||n.class==="discrete"?o:Math.floor(o*Vte/Hte)}function qte(i,e,t,n,r="wasm",o=ZM()){let s=JM(t.class),a=pv(e.parts,1,256);n.cpuLaunch=0,n.cpuRow=Bte(A8e(i,r,o,t)),n.cpuSerialRow=0,n.lanes=1;let l=s.setFixed+(a-1)*s.batchedLaunch+Math.min(e.stages,64*256)*s.stage,c=e.instructions*s.setOp+e.gathers*s.gather+e.transcendentals*s.math+e.upload*s.uploadWord+e.readback*s.readbackWord;return n.gpuFixed=b_(l),n.gpuRow=Bte(c),n}function b8e(i,e){let t=Math.ceil(i/2048);return t<r8e||e<=1?1:Math.min(t,e)}function $M(i,e){let t=Yte(e),n=b8e(t,i.lanes),r=Dte+i8e*(n-1);return (n>1?i.cpuLaunch:0)+Math.floor(t*i.cpuRow*Dte/r)+t*i.cpuSerialRow}function jM(i,e){return i.gpuFixed+Yte(e)*i.gpuRow}function g8e(i,e,t,n){let r=JM(t.class),o=$M(i,e),s=jM(i,e),a=n8e[Math.min(Math.max(t.pressure|0,0),2)];if(n==="gpu")return s*64>o*Math.floor(r.leave*a/64)?"cpu":"gpu";let l=t.budgetNs>0&&o>t.budgetNs*1e3,c=Math.floor((l?Math.max(r.enter,64):r.enter)*a/64);return s*64<o*c?"gpu":"cpu"}function Gte(i,e){if(e===0)return 1e3;for(let t=1;t<e;t++){let n=i[t],r=t-1;for(;r>=0&&i[r]>n;)i[r+1]=i[r],r--;i[r+1]=n;}return i[e>>1]}function E8e(i){return i<=0?0:i<4?4:i>32?32:i&-2}var zi=class i{constructor(e,t,n,r){this.machineState=e;this.preset=r;this.current="cpu";this.decided=false;this.streak=0;this.switched=0;this.taken=0;this.pending=false;this.cpuSamples=new Uint32Array(16);this.gpuSamples=new Uint32Array(16);this.cpuLength=0;this.gpuLength=0;this.scratch=mv();this.base=mv();this.runs=E8e(t),this.pinned=n;}static model(e){return new i(e,0,null,null)}static calibrating(e,t){return new i(e,t,null,null)}static pinned(e,t){return new i(e,0,t,null)}static replaying(e,t,n){return new i(e,t,null,n)}get machine(){return this.machineState}set machine(e){this.machineState=e;}get device(){return this.current}get pin(){return this.pinned}get switches(){return this.switched}get calibrating(){return this.pinned===null&&this.taken<this.runs}get calibrationRuns(){return this.runs}get sampling(){return this.pending}route(e){return this.routeEstimate(Ute(e,this.machineState,this.base),e.rows)}routeEstimate(e,t,n=2097152){if(this.pending=false,this.calibrating){let o=$M(e,t),s=jM(e,t);if(s*16>=o&&o*16>=s){let a=this.taken<this.runs/2?"cpu":"gpu";return this.taken++,this.pending=true,this.current=a,this.streak=0,this.decided=false,a}}let r=g8e(this.pinned===null?e:f8e(_8e(e,this.scratch),this.pinned,n),t,this.machineState,this.current);return this.decided?(r===this.current?this.streak=0:(this.streak++,this.streak>=3&&(this.current=r,this.streak=0,this.switched++)),this.current):(this.decided=true,this.streak=0,this.current=r,r)}record(e,t,n){this.pending&&this.recordEstimate(e,Ute(t,this.machineState,this.base),t.rows,n);}recordEstimate(e,t,n,r){if(!this.pending)return;this.pending=false;let o=this.runs/2;if(!(this.taken===1||this.taken===o+1)){let a=Math.max(e==="cpu"?$M(t,n):jM(t,n),1),l=Math.min(Math.max(Math.floor(r),0),4294967296)*1e3,c=pv(Math.floor(l*1e3/a),250,4e3);e==="cpu"&&this.cpuLength<16?this.cpuSamples[this.cpuLength++]=c:e==="gpu"&&this.gpuLength<16&&(this.gpuSamples[this.gpuLength++]=c);}if(this.taken>=this.runs){let a=Gte(this.cpuSamples,this.cpuLength),l=Gte(this.gpuSamples,this.gpuLength);this.pinned=this.preset??{cpu:a,gpu:l},this.decided=false,this.streak=0;}}};var Al="#",Gc="%",x8e=new Map;function fv(i){return x8e.get(i)??null}var v8e=["engine_kernel_gpu_ready","engine_kernel_gpu_bind","engine_kernel_gpu_unbind","engine_kernel_gpu_run","engine_kernel_gpu_frame","engine_kernel_gpu_sync","engine_kernel_gpu_touch","engine_kernel_gpu_events","engine_kernel_gpu_clear_events"];var R8e="@",S8e=255,e3=8,T8e=new Set([nt.FPOW,nt.FATAN2,nt.FLOG2,nt.FSIN,nt.FCOS,nt.FTAN,nt.FASIN,nt.FACOS,nt.FATAN,nt.FEXP,nt.FLOG]),zte=new WeakMap;function w8e(i){let e=zte.get(i);if(e!==void 0)return e;let t={instructions:0,pairs:false,stages:1,transcendentals:0,gathers:0};if(i.byteLength>=16*Kr){let n=new DataView(i.buffer,i.byteOffset,i.byteLength),r=d=>n.getUint32(d*Kr,true),o=16+r(4)+r(5)+r(6)+r(9)*4+r(14)*4,s=i.byteLength/Kr,a=1,l=false,c=0,u=0;for(let d=o;d+4<=s;d+=4){let h=r(d),p=h&S8e;T8e.has(p)&&c++,p===Ve&&(h>>>e3===Da||h>>>e3===Pa)&&u++;let m=So(p)||p===Ve&&DC(h>>>e3);m&&!l&&a++,l=m||l&&p===nt.EXT;}t={instructions:r(8),pairs:(r(2)&1)!==0,stages:a,transcendentals:c,gathers:u};}return zte.set(i,t),t}var E_=Object.freeze([]),I8e={vec2:2,vec3:3,vec4:4},O8e=255,t3=255,Kr=4,g_=64,C8e=4294967295,Vc=-5,N8e=-1,k8e="[kernel tables] ",Qte=xs,$te=0,jte=1,Jte=2,L8e=["x","y","z","w"];function M8e(i){let e=i.path==="gpu"?"table reads run on the GPU (nine storage buffers per stage)":i.path==="cpu-limits"?"table reads run on the CPU: this device allows fewer than nine storage buffers per stage, or the tables exceed its binding size":"table reads run on the CPU: the kernel writes other tables or uses lists, tallies or picks";return `${k8e}${i.kernel}: ${e}`}function D8e(i,e){if(i===null||e===null)return i===e;if(i.length!==e.length)return false;for(let t=0;t<i.length;t++)if(i[t]!==e[t]||i[t]!==void 0&&!i[t].valid)return false;return true}function P8e(i){let e=i.data?.tables;if(e===void 0||e.length===0)return null;let t=[];for(let n=0;t.length<i.args.length;n++)e.some(r=>r.position===n)||t.push(n);return Int32Array.from(t)}var F8e=Object.freeze([]);function U8e(i){let e=null;for(let t of i.slots){let n=t.field.startsWith(Gc);if(!n&&!t.field.startsWith(Al))continue;let r=t.field.slice(1);e??=[],e.push({name:r,arg:n?i.args.findIndex(o=>o.name===r):-1,write:t.write});}return e??F8e}function Zte(i){return i.startsWith(Gc)||i.startsWith(Al)?i.slice(1):i}function B8e(i,e){return i.buffer===e.buffer&&i.byteOffset===e.byteOffset}var _v=class i{constructor(e,t){this.exports=e;this.memory=t;this.entries=new Map;this.routes=[];this.touched=new Set;this.resident=new WeakSet;this.pending=new Set;this.engineClass=null;this.argsAt=0;this.argsBuffer=null;this.words=new Uint32Array(0);this.floats=new Float32Array(0);this.priority=0;this.compute=null;this.onTables=e=>console.info(M8e(e));this.device=$te;this.mirrored=new WeakMap;}static bind(e,t){for(let n of v8e)if(typeof e[n]!="function")return null;return typeof e.engine_alloc!="function"||typeof e.engine_free!="function"?null:new i(e,t)}available(){return this.device===$te&&(this.device=this.exports.engine_kernel_gpu_ready()===1?jte:Jte),this.device===jte}deviceClass(e){if(this.engineClass===null){let t=this.exports.engine_kernel_gpu_class;this.engineClass=typeof t=="function"&&this.available()?Kte(t()):"unknown";}return this.engineClass==="unknown"?e:this.engineClass}hostBackend(){return Wte()&&this.memory instanceof WebAssembly.Memory?"wasm":"interpreter"}work(e,t,n,r,o,s,a=false){let l=w8e(t);return {rows:r,instructions:l.instructions,pairs:l.pairs,stages:l.stages,columns:e.slots.length,resident:this.resident.has(n),readback:s,lanes:o,transcendentals:l.transcendentals,batched:a}}beforeCpu(e){this.pending.has(e)&&this.sync();}afterCpu(e,t){if(this.resident.has(e)){if(t===null){this.exports.engine_kernel_gpu_touch(e.id,t3),this.resident.delete(e);return}for(let n of t.slots)n.write&&n.field in e.schema&&this.exports.engine_kernel_gpu_touch(e.id,e.column(n.field,n.component));}}tablesRoute(e,t,n){e.routed||(e.routed=true,this.onTables?.({kernel:t.name,path:n}));}joinedOf(e,t,n,r){let o=e.joined,s=t.data?.tables;if(o===null||s===void 0)return e.joined=Ka(t,n,r),e.joined;o[0]=n;for(let a=0;a<s.length;a++){let l=r[s[a].position];if(typeof l!="object"||l===null||!("schema"in l))return e.joined=Ka(t,n,r),e.joined;o[s[a].table]=l;}return o}binding(e,t,n,r){let o=this.entries.get(t);if(o===void 0&&(o={eligible:true,routed:false,bound:[],arrays:U8e(e),scalars:P8e(e),data:ks(e),joined:null},this.entries.set(t,o)),!o.eligible)return Vc;let s=o.data,a=s?this.joinedOf(o,e,n,r):null;if(a!==null&&a.some((h,p)=>p>0&&h!==void 0&&!h.native))return Vc;for(let h of o.bound)if(h.table===n&&n.valid&&D8e(h.joined,a))return h.binding;for(let h=o.bound.length-1;h>=0;h--)o.bound[h].table.valid||(this.exports.engine_kernel_gpu_unbind(o.bound[h].binding),this.compute?.unbound(Zg,o.bound[h].binding),o.bound.splice(h,1));if(e.slots.some(h=>h.field.startsWith(R8e))||o.arrays.some(h=>!this.carries(n,h,e)))return o.eligible=false,Vc;let l=new Uint32Array(e.slots.length+(a===null?0:Qte));for(let h=0;h<e.slots.length;h++){let p=e.slots[h];if(p.pool!==void 0){l[h]=4294967295;continue}let m=a!==null&&p.table!==void 0&&p.table>0?a[p.table]:n,f=Zte(p.field);if(!(f in m.schema))throw new _("invalid_argument",`kernel ${e.name} reads ${p.field}, which ${m===n?"this":"the joined"} table does not have`);l[h]=m.column(f,f===p.field?p.component:0);}if(a!==null)for(let h=0;h<Qte;h++)l[e.slots.length+h]=h<a.length&&a[h]!==void 0?a[h].id:4294967295;let c=this.copyIn(t),u=this.copyIn(new Uint8Array(l.buffer)),d=this.exports.engine_kernel_gpu_bind(c,t.byteLength,n.id,u,l.length);if(this.exports.engine_free(c,Math.max(t.byteLength,Kr),Kr),this.exports.engine_free(u,Math.max(l.byteLength,Kr),Kr),d===Vc||s&&d===N8e)return o.eligible=false,s&&this.tablesRoute(o,e,d===Vc?"cpu-ineligible":"cpu-limits"),Vc;if(d<0)throw new _("invalid_argument",`the engine refused GPU kernel ${e.name} (${d})`);return s&&this.tablesRoute(o,e,"gpu"),o.bound.push({table:n,joined:a===null?null:a.slice(),binding:d}),this.compute?.bound(Zg,d,e.name,this.priority),e.channels!==void 0&&e.channels.length>0&&this.routes.push({binding:d,meta:e}),d}carries(e,t,n){let r=e.schema[t.name];if(r!=="f32"&&r!=="i32"&&r!=="u32")return false;let o=n.slots.find(s=>Zte(s.field)===t.name&&s.field!==t.name);return o!==void 0&&o.kind===r}stage(e,t,n){for(let r of e.arrays){let o=t.values(r.name),s=r.arg>=0?n[r.arg]:fv(r.name)?.data;if(!(s instanceof o.constructor))return false;let a=s;if(!B8e(a,o)){if(r.write||a.length>o.length)return false;o.set(a),this.touched.has(t)&&this.exports.engine_kernel_gpu_touch(t.id,t.column(r.name,0));}}return true}copyIn(e){let t=this.exports.engine_alloc(Math.max(e.byteLength,Kr),Kr);if(t===0)throw new _("capacity_exceeded","engine memory cannot hold a GPU kernel binding");return new Uint8Array(this.memory.buffer,t,e.byteLength).set(e),t}argViews(){let e=this.memory.buffer;if(this.argsAt===0&&(this.argsAt=this.exports.engine_alloc(g_*Kr,Kr),this.argsAt===0))throw new _("capacity_exceeded","engine memory cannot hold kernel arguments");this.argsBuffer!==e&&(this.words=new Uint32Array(e,this.argsAt,g_),this.floats=new Float32Array(e,this.argsAt,g_),this.argsBuffer=e);}writeArg(e,t,n){if(t.kind==="f64"||t.kind==="u64")return Wa(this.words,e,t.kind,n);if(t.width===1&&ArrayBuffer.isView(n))return this.words[e]=n.length>>>0,e+1;if(t.width>1&&(Array.isArray(n)||ArrayBuffer.isView(n))){let r=n;for(let o=0;o<t.width;o++)t.kind==="f32"?this.floats[e+o]=r[o]:this.words[e+o]=r[o]>>>0;return e+t.width}if(t.width>1){let r=n;for(let o=0;o<t.width;o++)this.floats[e+o]=r[L8e[o]];return e+t.width}return t.kind==="f32"?this.floats[e]=n:t.kind==="bool"?this.words[e]=n?C8e:0:this.words[e]=n>>>0,e+1}eligible(e){return this.device!==Jte&&this.entries.get(e)?.eligible!==false}mirror(e,t){let n=this.mirrored.get(e);if(n===t||n!==void 0&&n.length===t.length&&n.every((o,s)=>o===t[s]))return;let r=this.exports.engine_kernel_gpu_mirror;if(typeof r=="function"){this.mirrored.set(e,t),r(e.id,t3,0);for(let o of t){if(!(o in e.schema))throw new _("invalid_argument",`onGpu mirrors ${o}, which this table does not have`);let s=I8e[e.schema[o]]??1;for(let a=0;a<s;a++)r(e.id,e.column(o,a),1);}}}run(e,t,n,r,o,s,a=E_){if(!n.native||e.argWords>g_||!this.available())return null;let l=this.binding(e,t,n,o);if(l===Vc)return null;let c=this.entries.get(t);if(c.arrays.length>0&&!this.stage(c,n,o))return null;this.mirror(n,a),this.argViews();let u=0,d=c.scalars;for(let m=0;m<e.args.length;m++)u=this.writeArg(u,e.args[m],o[d===null?m:d[m]]);let h=r?r.index:O8e;this.compute?.prioritise(Zg,l,this.priority);let p=this.exports.engine_kernel_gpu_run(l,h,this.argsAt,u);if(p===eE&&this.priority!==0)return 0;if(p<0)throw new _("invalid_argument",`GPU kernel ${e.name} failed (${p})`);return this.touched.add(n),this.resident.add(n),s?(this.exports.engine_kernel_gpu_sync(),this.pending.clear(),this.route()):this.pending.add(n),p}touch(e,t,n=0){this.touched.has(e)&&(t===void 0&&this.resident.delete(e),this.exports.engine_kernel_gpu_touch(e.id,t===void 0?t3:e.column(t,n)));}sync(){this.touched.size!==0&&(this.exports.engine_kernel_gpu_sync(),this.pending.clear(),this.route());}frame(){this.touched.size!==0&&(this.exports.engine_kernel_gpu_frame(),this.route());}route(){for(let{binding:e,meta:t}of this.routes){let n=this.exports.engine_kernel_gpu_events(e);n===0||t.channels===void 0||(hc(new Uint32Array(this.memory.buffer,n,er+Ro*10),t.channels),this.exports.engine_kernel_gpu_clear_events(e));}}dispose(){for(let e of this.entries.values())for(let t of e.bound)this.exports.engine_kernel_gpu_unbind(t.binding);this.argsAt!==0&&this.exports.engine_free(this.argsAt,g_*Kr,Kr),this.entries.clear(),this.routes.length=0,this.touched.clear(),this.pending.clear(),this.argsAt=0;}};var yv=4294967295,G8e=4294967295,n3=new Uint32Array(2);function V8e(i,e,t,n,r,o,s){let a=r(t,0),l=r(t,1);Object.defineProperty(i,e,{get:()=>n==="f64"?X9(a[o.row],l[o.row]):q9(a[o.row],l[o.row]),set:s?c=>{Wa(n3,0,n,c),a[o.row]=n3[0],l[o.row]=n3[1];}:bv,enumerable:true});}var H8e=["x","y","z","w"],W8e=["position","pos"],x_={vec2:2,vec3:3,vec4:4},Av=class{constructor(){this.row=0;this.rank=0;}},K8e=1;function Y8e(i){let e={children:new Map,leaf:null};for(let t of Object.keys(i)){let n=e;for(let o of t.split(".")){let s=n.children.get(o);s===void 0&&(s={children:new Map,leaf:null},n.children.set(o,s)),n=s;}let r=i[t];n.leaf=r==="f64"||r==="u64"?{field:t,width:2,wide:r}:{field:t,width:x_[r]??1};}return e}function X8e(i){if(i.children.size===0)return false;let e=0;for(let t of i.children.keys())if(t!==String(e++))return false;return true}function bv(){throw new _("invalid_argument","neighbours are read-only inside a kernel; write to the entity being updated")}function q8e(i,e,t,n,r){let o={};for(let s=0;s<e;s++){let a=t(i,s);Object.defineProperty(o,H8e[s],{get:()=>a[n.row],set:r?l=>{a[n.row]=l;}:bv,enumerable:true});}return Object.seal(o)}function r3(i,e,t,n,r){let o={};r?.(o);for(let[s,a]of i.children)z8e(o,s,a,e,t,n);if(X8e(i)){let s=i.children.size;Object.defineProperty(o,"length",{value:s,enumerable:false}),Object.defineProperty(o,Symbol.iterator,{value:function*(){for(let a=0;a<s;a++)yield o[a];},enumerable:false});}return Object.seal(o)}function z8e(i,e,t,n,r,o){if(t.leaf?.wide!==void 0){V8e(i,e,t.leaf.field,t.leaf.wide,n,r,o);return}if(t.leaf!==null&&t.leaf.width===1){let l=n(t.leaf.field,0);Object.defineProperty(i,e,{get:()=>l[r.row],set:o?c=>{l[r.row]=typeof c=="boolean"?c?1:0:c;}:bv,enumerable:true});return}let s=t.leaf!==null?q8e(t.leaf.field,t.leaf.width,n,r,o):r3(t,n,r,o),a=s;Object.defineProperty(i,e,{get:()=>s,set:o?l=>{for(let c of Object.keys(a))a[c]=l[c];}:bv,enumerable:true});}var i3=class{constructor(e){this.table=e;this.cursor=new Av;this.other=new Av;this.snapshot=new Map;this.gridRadius=-1;this.gridField="";this.count=0;this.search=null;this.schema=e.schema;let t=Y8e(e.schema),n=(s,a)=>e.values(s,a),r=(s,a)=>this.snapshot.get(s)[a];for(let s of Object.keys(e.schema)){let a=x_[e.schema[s]]??1,l=[];for(let c=0;c<a;c++){let u=e.values(s,c);l.push(new u.constructor(e.capacity));}this.snapshot.set(s,l);}this.buffer=e.values(Object.keys(e.schema)[0],0).buffer;let o=this;this.self=r3(t,n,this.cursor,true,s=>{Object.defineProperty(s,"row",{get:()=>o.cursor.row,enumerable:false}),Object.defineProperty(s,"neighbours",{value:(c,u)=>o.neighbours(c,u),enumerable:false});let a=(c,u)=>{t.children.has(c)||Object.defineProperty(s,c,{value:u,enumerable:false});},l=Math.fround;a("nearestFeatures",(c,u,d)=>o.features(c>>>0,u??1/0,d)),a("nearest",(c,u,d)=>o.query(La,u??1/0,c>>>0,null,[0,0,0],d)),a("within",(c,u)=>o.query(La,c,u?.limit??yv,null,[0,0,0],u)),a("inCone",(c,u,d,h)=>o.query(Dg,d,h?.limit??yv,c,[u,0,0],h)),a("inBox",(c,u,d)=>{let h=u.z??0,p=l(Math.sqrt(l(l(l(u.x*u.x)+l(u.y*u.y))+l(h*h))));return o.query(Pg,p,d?.limit??yv,c,[u.x,u.y,h],d)}),a("alongRay",(c,u,d,h)=>o.query(ud,u,h?.limit??yv,c,[d,0,0],h));}),this.neighbour=r3(t,r,this.other,false,s=>{Object.defineProperty(s,"row",{get:()=>o.other.row,enumerable:false}),t.children.has("rank")||Object.defineProperty(s,"rank",{get:()=>o.other.rank,enumerable:false});}),this.grid=new Fa(e.capacity);}takeSnapshot(e){this.count=e;for(let t of Object.keys(this.schema)){let n=this.snapshot.get(t);for(let r=0;r<n.length;r++)n[r].set(this.table.values(t,r).subarray(0,e));}this.gridRadius=-1;}positionField(e){if(e!==void 0){if(x_[this.schema[e]]===void 0)throw new _("invalid_argument",`${e} is not a vec2 or vec3 field`);return e}for(let t of W8e)if(x_[this.schema[t]]!==void 0)return t;throw new _("invalid_argument","neighbour queries need a vec2 or vec3 field named position or pos, or a field name")}query(e,t,n,r,o,s){let a=this.positionField(s?.field),l=this.snapshot.get(a),c=Math.fround,u=c(s?.cell??t);(this.gridRadius!==u||this.gridField!==a)&&(this.grid.rebuild(u,l[0],l[1],l.length>2?l[2]:null,this.count),this.gridRadius=u,this.gridField=a);let d={kind:e,vx:c(r?.x??0),vy:c(r?.y??0),vz:c(l.length>2?r?.z??0:0),p0:c(o[0]),p1:c(o[1]),p2:c(o[2]),reach:c(t)},h=0,p=0,m=0,f=null,y=s?.where;if(y!==void 0){let x=(this.snapshot.get(y.field)??[])[0];if(!(x instanceof Int32Array||x instanceof Uint32Array))throw new _("invalid_argument",`where.field ${y.field} must be an i32 or u32 field`);f=new Uint32Array(x.buffer,x.byteOffset,x.length),y.equals!==void 0?(h=Bg,p=(y.mask??G8e)>>>0,m=y.equals>>>0):y.any!==void 0?(h=Gg,p=y.any>>>0):y.none!==void 0&&(h=Vg,p=y.none>>>0);}let b=this.cursor.row,A=this.search??new yc(this.table.capacity);this.search=A;let E=A.run(this.grid,d,h,p,m,f,l[0][b],l[1][b],l.length>2?l[2][b]:0,b,n>>>0),R=Array.from(A.rows.subarray(0,E)),g=this.other,v=this.neighbour;return {[Symbol.iterator]:()=>{let x=0;return {next:()=>x>=R.length?{value:void 0,done:true}:(g.rank=x,g.row=R[x++],{value:v,done:false})}}}}features(e,t,n){let r=Math.fround,o=[this.positionField(n?.field),...n?.velocity===void 0?[]:[n.velocity]],s=x_[this.schema[o[0]]]??0,a=s*o.length+1,l=new Array(e*a).fill(0),c=this.cursor.row,u=this.query(La,t,e,null,[0,0,0],n)[Symbol.iterator]();for(;u.next().done!==true;){let d=this.other.rank*a;o.forEach((h,p)=>{let m=this.snapshot.get(h);for(let f=0;f<s;f++)l[d+p*s+f]=r(0+r(m[f][this.other.row]-this.table.values(h,f)[c]));}),l[d+a-1]=K8e;}return l}neighbours(e,t){let n=this.positionField(t),r=this.snapshot.get(n);(this.gridRadius!==e||this.gridField!==n)&&(this.grid.rebuild(e,r[0],r[1],r.length>2?r[2]:null,this.count),this.gridRadius=e,this.gridField=n);let o=this.cursor.row,s=[];this.grid.walk(r[0][o],r[1][o],r.length>2?r[2][o]:0,o,s);let a=this.other,l=this.neighbour;return {[Symbol.iterator]:()=>{let c=0;return {next:()=>c>=s.length?{value:void 0,done:true}:(a.row=s[c++],{value:l,done:false})}}}}},gv=class{constructor(){this.views=new WeakMap;}viewsFor(e){let t=this.views.get(e),n=e.values(Object.keys(e.schema)[0],0).buffer;return (t===void 0||t.buffer!==n)&&(t=new i3(e),this.views.set(e,t)),t}run(e,t,n,r){let o=this.viewsFor(t),s=t.count;e.neighbours&&o.takeSnapshot(s);let a=o.cursor,l=o.self,c=e.fn,u=e.tree,d=0,h=p=>{a.row=p,$g(p),c!==null?c(l,...r):u!==null&&Rh(u,l,r),d++;};if(n){let p=n.rows,m=n.length;for(let f=0;f<m;f++)p[f]<s&&h(p[f]);}else for(let p=0;p<s;p++)h(p);return d}};var ue=Math.fround,zs=4294967295,Q8e=-1,Th=1e7,$8e=3,j8e=2,J8e=1;var ene=16,tne=4,Z8e=4294967295;function nne(i,e,t,n,r,o,s,a,l,c,u,d){let h=ue,p=h(n*n),m=h(r*r),f=h(o*o),y=h(n*r),b=h(n*o),A=h(r*o),E=h(s*n),R=h(s*r),g=h(s*o),v=O=>h(O+O),x=(O,N)=>h(1-v(h(O+N)));u[d]=h(x(m,f)*a),u[d+1]=h(v(h(y+g))*a),u[d+2]=h(v(h(b-R))*a),u[d+3]=0,u[d+4]=h(v(h(y-g))*l),u[d+5]=h(x(p,f)*l),u[d+6]=h(v(h(A+E))*l),u[d+7]=0,u[d+8]=h(v(h(b+R))*c),u[d+9]=h(v(h(A-E))*c),u[d+10]=h(x(p,m)*c),u[d+11]=0,u[d+12]=i,u[d+13]=e,u[d+14]=t,u[d+15]=1;}function rne(i,e,t){return ue(Math.sqrt(ue(ue(ue(i*i)+ue(e*e))+ue(t*t))))}function $o(i,e){for(let t=0;t<e;t++)if(!Number.isFinite(i[t]))return false;return true}var xv=class{constructor(e){this.sources=e;this.query=new Xi;this.hit=new qi;this.path=new yh;this.from={x:0,y:0,z:0};this.to={x:0,y:0,z:0};this.flowSample=new bh;this.ids={physics:0,nav:0,flow:0,render:0,ui:0,audio:0,voxels:0,chemistry:0};this.cast=new Vf;this.overlapOut={count:0,entity:zs};this.voxel={material:0,solid:false};this.cellOut={species:0,kelvin:0,amount:0};this.pickHit=Yb();this.pickFrom=new Float32Array(3);this.pickDir=new Float32Array(3);this.matrix=new Float32Array(ene);this.marked=-1;this.query.solid=false,this.query.includeSensors=false,this.query.excludeCollider=Q8e;}handles(){let e=this.sources,t=this.ids;return t.physics=e.physics?.batchHandle?.()??0,t.nav=e.nav?.batchHandle?.()??0,t.flow=e.flow?.batchHandle?.()??0,t.render=e.graphics?.batchHandle?.()??0,t.ui=e.ui?.batchHandle?.()??0,t.audio=e.audio?.batchHandle?.()??0,t.voxels=e.voxels?.batchHandle?.()??0,t.chemistry=e.chemistry?.batchHandle?.()??0,t}begin(e){(e===14||e===15)&&(this.marked=-1);}end(e){(e===14||e===15)&&(this.marked=-1);}call(e,t,n){switch(e){case 6:case 7:case 8:return this.sources.physics?.writeBody===void 0?false:($o(t.subarray(1),3)&&this.sources.physics?.writeBody?.(e-6,t[0]>>>0,ue(t[1]),ue(t[2]),ue(t[3])),true);case 9:{let r=this.sources.physics;if(r?.overlap===void 0)return false;let o=this.overlapOut;return o.count=0,o.entity=zs,$o(t,4)&&t[3]>=0&&!r.overlap(ue(t[0]),ue(t[1]),ue(t[2]),ue(t[3]),o)?false:(n[0]=o.count>>>0,n[1]=o.entity>>>0,true)}case 10:return this.sweep(t,n);case 11:{let r=this.sources.graphics;return r?.setClipWeight===void 0?false:(r.setClipWeight(t[0]>>>0,ue(t[1])),true)}case 12:{let r=this.sources.graphics;if(r?.playClipIndex===void 0)return false;let o=zs;try{o=r.playClipIndex(t[0]>>>0,t[1]>>>0,t[2]!==0,ue(t[3]),ue(t[4]))>>>0;}catch{o=zs;}return n[0]=o,true}case 13:{let r=this.sources.graphics;return r?.setIkTarget===void 0?false:(r.setIkTarget(t[0]>>>0,ue(t[1]),ue(t[2]),ue(t[3]),ue(t[4])),true)}case 14:case 15:return this.instance(e===15,t);case 16:{let r=this.sources.ui;return r===void 0?false:($o(t.subarray(1),3)&&r.setAnchor(t[0]>>>0,ue(t[1]),ue(t[2]),ue(t[3])),true)}case 17:{let r=this.sources.audio;if(r===void 0)return false;if(!$o(t.subarray(2),4))return true;let o=r.play(t[0]>>>0,t[1]>>>0,ue(t[5]),1,false,true);return o<0||(nne(ue(t[2]),ue(t[3]),ue(t[4]),0,0,0,1,1,1,1,this.matrix,0),r.setVoicePosition(o,this.matrix,0)),true}case 18:return this.pick(t,n);case 19:{let r=this.sources.voxels;if(r===void 0)return false;let o=this.voxel;return o.material=0,o.solid=false,$o(t,3)&&r.voxelAt(ue(t[0]),ue(t[1]),ue(t[2]),o),n[0]=o.material>>>0,n[1]=o.solid?1:0,true}case 20:{let r=this.sources.voxels;return r===void 0?false:($o(t,3)&&t[3]<=255&&r.setVoxel(ue(t[0]),ue(t[1]),ue(t[2]),t[3]>>>0),true)}case 21:{let r=this.sources.chemistry;if(r===void 0)return false;let o=this.cellOut;return r.cell(t[0]>>>0,t[1]>>>0,t[2]>>>0,o),n[0]=o.species>>>0,n[1]=ue(o.kelvin),n[2]=o.amount>>>0,true}case 1:case 2:return this.ray(e===2,t,n);case 3:{let r=this.sources.terrain;if(r===void 0)return false;let o=r.heightAt(t[0],t[1]);return n[0]=Number.isFinite(o)?ue(o):Number.NaN,true}case 4:return this.route(t,n);case 5:{let r=this.sources.flow;if(r?.sample===void 0)return false;let o=this.flowSample;return r.sample(t[0],t[2],true,o),n[0]=o.x,n[1]=0,n[2]=o.z,n[3]=o.distance,n[4]=o.status,true}default:return false}}sweep(e,t){let n=this.sources.physics;if(n?.castShape===void 0)return false;let r=e[7],o=r>=0?r<Th?ue(r):Th:0,s=e[6],a=o>0&&$o(e,6)&&(e[3]!==0||e[4]!==0||e[5]!==0)&&Number.isFinite(s)&&s>=0,l=this.hit,c=false;if(a){let u=this.cast.ball(ue(s));u.origin.set(ue(e[0]),ue(e[1]),ue(e[2])),u.direction.set(ue(e[3]),ue(e[4]),ue(e[5])),u.rotation.set([0,0,0,1]),u.maxDistance=o,u.includeSensors=false,u.excludeBody=e[8]>>>0===zs?-1:e[8]>>>0,c=n.castShape(u,l);}return t[0]=c?l.distance:o,t[1]=c?l.normalX:0,t[2]=c?l.normalY:0,t[3]=c?l.normalZ:0,t[4]=c?n.entityOfCollider(l.collider)>>>0:zs,t[5]=c?1:0,true}pick(e,t){let n=this.sources.graphics;if(n?.raycast===void 0)return false;let r=e[6],o=r>=0?r<Th?ue(r):Th:0,s=this.pickHit,a=false;return $o(e,6)&&o>0&&(this.pickFrom.set([e[0],e[1],e[2]]),this.pickDir.set([e[3],e[4],e[5]]),a=n.raycast(this.pickFrom,this.pickDir,s,o,Z8e)),t[0]=a?s.distance:o,t[1]=a?s.node>>>0:zs,t[2]=a?s.instance>>>0:zs,t[3]=a?1:0,true}instance(e,t){let n=this.sources.graphics;if(n?.instanceBuffer===void 0)return false;let r=t[0]>>>0,o=t[1]>>>0,s=n.instanceBuffer(r,e),a=e?tne:ene;if(s===null||(o+1)*a>s.length)return true;let l=o*a;if(e)for(let c=0;c<tne;c++)s[l+c]=t[2+c];else nne(ue(t[2]),ue(t[3]),ue(t[4]),ue(t[5]),ue(t[6]),ue(t[7]),ue(t[8]),ue(t[9]),ue(t[10]),ue(t[11]),s,l);return this.marked!==r&&(n.markInstances?.(r),this.marked=r),true}ray(e,t,n){let r=this.sources.physics;if(r===void 0)return false;let o=$o(t,6),s=t[3],a=t[4],l=t[5],c;e?(s=ue(t[3]-t[0]),a=ue(t[4]-t[1]),l=ue(t[5]-t[2]),c=rne(s,a,l)):c=t[6],c=c>=0?c<Th?c:Th:0;let u=false,d=this.hit;return o&&c>0&&(s!==0||a!==0||l!==0)&&(this.query.set(t[0],t[1],t[2],s,a,l,c),u=r.raycast(this.query,d)),e?(n[0]=o&&!u?1:0,true):(n[0]=u?d.distance:c,n[1]=u?d.normalX:0,n[2]=u?d.normalY:0,n[3]=u?d.normalZ:0,n[4]=u?r.entityOfCollider(d.collider)>>>0:zs,n[5]=u?1:0,true)}route(e,t){let n=this.sources.nav;if(n===void 0)return false;let r=this.from,o=this.to;r.x=ue(e[0]),r.y=ue(e[1]),r.z=ue(e[2]),o.x=ue(e[3]),o.y=ue(e[4]),o.z=ue(e[5]);let s=this.path,a=$o(e,6)&&n.findPath(r,o,s)?s.count:0;if(t[0]=0,t[1]=0,t[2]=0,t[3]=$8e,a===0)return true;let l=s.points,c=(Math.min(a,2)-1)*3,u=ue(l[c]-l[0]),d=ue(l[c+1]-l[1]),h=ue(l[c+2]-l[2]),p=rne(u,d,h);return t[3]=s.complete?J8e:j8e,p>0&&(t[0]=ue(u/p),t[1]=ue(d/p),t[2]=ue(h/p)),true}},ine=null;function a3(i){let e=ine;return ine=i,e}var gne=null;function l3(i){let e=gne;return gne=i,e}var tVe=new Map;function Ene(i){return tVe.get(i)??null}var vv="@",rVe=1e3;function iVe(i){console.warn(lq(i));}var xne=255;function oVe(i){return Array.isArray(i)||ArrayBuffer.isView(i)}function vne(i){if(i.byteLength<64)return false;let e=new DataView(i.buffer,i.byteOffset,i.byteLength),t=e.getUint32(16,true);for(let n=0;n<t;n++)if((e.getUint32(64+n*4,true)&Lg)!==0)return true;return false}function sVe(i){let e=i.slots;for(let t=0;t<e.length;t++)if(e[t].field.startsWith(vv)||e[t].field.startsWith(Al)||e[t].field.startsWith(Gc))return true;return false}function Rne(i){if(i.byteLength<64)return false;let e=new DataView(i.buffer,i.byteOffset,i.byteLength),t=o=>e.getUint32(o*4,true),n=i.byteLength/4,r=16+t(4)+t(5)+t(6)+t(9)*4+t(14)*4;for(let o=r;o<n;o+=4)if(So(t(o)&xne)||dc(t(o)&xne,t(o)>>>8))return true;return false}var h3=Symbol.for("cimplify.kernel"),aVe="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",c3="=";var lVe=0xcbf29ce484222325n,cVe=0x100000001b3n,uVe=(1n<<64n)-1n,Sne=new Map,Tne=new WeakMap;function dVe(i){let e=Tne.get(i);if(e!==void 0)return e;let t=lVe;for(let n=0;n<i.length;n++)t=(t^BigInt(i[n]))*cVe&uVe;return Tne.set(i,t),t}function hVe(i){return Sne.size===0?null:Sne.get(dVe(i))??null}var pVe=["x","y","z","w"],mVe={vec2:2,vec3:3,vec4:4},u3=8,fVe=.5,_Ve=4;function yVe(i){let e=[];for(let t of i.slots)t.write&&!e.includes(t.field)&&e.push(t.field);return e}var d3=1e6;function wne(){return typeof globalThis.performance?.now=="function"}function R_(){return globalThis.performance?.now()??0}var AVe=Object.freeze([]);var bVe={mode:"auto",gpu:"auto",gpuRows:0,gpuClass:"mobile",cpuLanes:_Ve,cpuBackend:"auto",frameBudgetMs:0,gpuCalibrate:0,gpuPins:{},onRoute:null,onCompute:null,checkEvery:30,tolerance:.001,report:i=>{console.warn(`kernel ${i.kernel} diverged from its bytecode at ${i.field}[${i.component}] row ${i.row}: js ${i.js}, bytecode ${i.native}${i.source===null?"":` (${i.source})`}`);}},xt=bVe;function gVe(i){let e=i.endsWith(c3+c3)?i.slice(0,-2):i.endsWith(c3)?i.slice(0,-1):i,t=new Uint8Array(Math.floor(e.length*3/4)),n=0,r=0,o=0;for(let s=0;s<e.length;s++){let a=aVe.indexOf(e[s]);if(a<0)throw new _("invalid_argument","a compiled kernel carries invalid base64");r=r<<6|a,n+=6,n>=8&&(n-=8,t[o++]=r>>n&255);}return t.subarray(0,o)}function p3(i){if(i.compiled!==void 0)return i.compiled;if(i.payload===null)return i.compiled=null,null;let e=JSON.parse(i.payload);return i.compiled={meta:e.meta,program:gVe(e.program)},i.compiled}function Ine(i){return p3(i[h3])}function EVe(i){let e=[];for(let t of Object.keys(i.schema)){let n=mVe[i.schema[t]]??1;for(let r=0;r<n;r++)e.push({field:t,component:r,values:i.values(t,r)});}return e}function xVe(i,e,t){return Object.is(i,e)||Number.isNaN(i)&&Number.isNaN(e)?true:Math.abs(i-e)<=t*Math.max(1,Math.abs(i),Math.abs(e))}function vVe(i){return i.byteLength>=8&&i[4]>=3}var RVe={f32:Yn,i32:Bi,u32:Dr,u8:kd,vec2:Yn,vec3:Yn,vec4:Yn,f64:Dr,u64:Dr},SVe=4294967295,TVe={values:new Uint32Array(0),storage:Dr},m3=class{constructor(){this.services=null;this.into=null;this.report={spawned:0,dropped:0,killed:0};this.programs=new WeakMap;this.machines=new WeakMap;this.words=new Uint32Array(64);this.floats=new Float32Array(this.words.buffer);this.bound=new WeakMap;this.reports=new WeakMap;}run(e,t,n,r,o){let s=this.programs.get(t);s===void 0&&(s=gc(t),this.programs.set(t,s));let a=this.machines.get(n);a===void 0&&(a=new Map,this.machines.set(n,a));let l=a.get(t);l===void 0&&(l=new Ld(s,n.capacity),a.set(t,l)),l.services=this.services;let c=ks(e)?Ka(e,n,o):null,u=c===null?o:Z9(e,o),d=e.slots.map(f=>{if(f.scratch===true||f.spawn===true)return TVe;let y=c===null?null:ez(e,c,f);if(y!==null)return y;if(f.field.startsWith(Gc)){let b=f.field.slice(Gc.length),A=u[e.args.findIndex(R=>R.name===b)];if(!(f.kind==="f32"?A instanceof Float32Array:f.kind==="i32"?A instanceof Int32Array:A instanceof Uint32Array))throw new _("invalid_argument",`kernel ${e.name} reads table ${b}; pass a ${f.kind==="f32"?"Float32Array":f.kind==="i32"?"Int32Array":"Uint32Array"}`);return {values:A,storage:f.kind==="f32"?Yn:f.kind==="i32"?Bi:Dr}}if(f.field.startsWith(Al)){let b=fv(f.field.slice(Al.length));if(b===null)throw new _("invalid_argument",`kernel ${e.name} writes kernel array ${f.field.slice(Al.length)}; declare it with kernelArray(name, { kind, length }) before running the kernel`);return {values:b.data,storage:b.kind==="f32"?Yn:b.kind==="i32"?Bi:Dr}}if(f.field.startsWith(vv)){let b=Ene(f.field.slice(vv.length));if(b===null)throw new _("invalid_argument",`kernel ${e.name} samples ${f.field.slice(vv.length)}; bind its buffer with bindSampler(name, data) first`);return {values:b,storage:Yn}}if(!(f.field in n.schema))throw new _("invalid_argument",`kernel ${e.name} reads ${f.field}, which this table does not have`);return {values:n.values(f.field,f.component),storage:RVe[n.schema[f.field]]}}),h=0;e.args.forEach((f,y)=>{let b=u[y];if(f.kind==="f64"||f.kind==="u64")h=Wa(this.words,h,f.kind,b);else if(f.width===1&&ArrayBuffer.isView(b))this.words[h++]=b.length>>>0;else if(f.width>1&&oVe(b))for(let A=0;A<f.width;A++)f.kind==="f32"?this.floats[h++]=b[A]:this.words[h++]=b[A]>>>0;else if(f.width>1){let A=b;for(let E=0;E<f.width;E++)this.floats[h++]=A[pVe[E]];}else f.kind==="f32"?this.floats[h++]=b:f.kind==="bool"?this.words[h++]=b?SVe:0:this.words[h++]=b>>>0;});let p=r===null?null:r.rows.subarray(0,r.length);if(c!==null){let f=this.bound.get(l);f===void 0&&(f=new Map,this.bound.set(l,f)),tz(l.data,e,c,d,f);}let m=l.run(d,n.count,p,this.words);if(c!==null&&this.reports.set(t,nz(l.data,e)),e.channels!==void 0&&e.channels.length>0&&(hc(l.events,e.channels),l.clearEvents()),l.defers){let f=this.into!==null&&this.into!==n?this.into:null,y=new gf(n,f===null?e:null);Ef(l.finish(y,f===null?null:new gf(f,e)),f??n,this.report);}return m}},gi=class{constructor(e){this.js=new gv;this.vm=new m3;this.args=Array.from({length:u3+1},(e,t)=>new Array(t).fill(null));this.numericArgs=Array.from({length:u3+1},(e,t)=>new Array(t).fill(fVe));this.gpuInFrame=0;this.pressure=0;this.presented=new WeakSet;this.readers=new WeakMap;this.routers=new WeakMap;this.machineFor=null;this.machineValue=null;this.sampleRouter=null;this.sampleWork=null;this.sampleName="";this.setRouters=new WeakMap;this.setMachines=new Map;this.setMachineBase=null;this.setScratch=mv();this.world=null;this.sink=new GE;this.into=null;this.engine=e,this.native=e===null?null:new m0(e),this.native!==null&&(this.native.report=this.vm.report),this.gpu=e===null?null:_v.bind(e.exports,e.memory),this.compute=e===null?null:Jg.bind(e.exports,e.memory),this.native!==null&&(this.native.compute=this.compute),this.gpu!==null&&(this.gpu.compute=this.compute);let t=this.compute;this.inspector=e===null||t===null?null:U0.bind(e.exports,e.memory,()=>t.boundKernels());let n=this.inspector;t!==null&&n!==null&&(t.onBound=(r,o,s)=>n.label(r,o,s));}get inspectorReadout(){return this.inspector?.readout()??null}get hasGpu(){return this.gpu!==null}get computeFrame(){return this.compute?.last??null}frame(){this.gpuInFrame=0,this.gpu?.frame(),this.compute?.frame(this.pressure,xt.frameBudgetMs*rVe,xt.onCompute??iVe);}setGpuPressure(e){let t=Math.min(Math.max(Math.trunc(e),0),2);t!==this.pressure&&(this.pressure=t,this.machineValue=null);}get gpuPressure(){return this.pressure}present(e,t=true){t?this.presented.add(e):this.presented.delete(e);}presents(e){return this.presented.has(e)}readsOnHost(e,t){let n=this.readers.get(e);n===void 0&&(n=new Map,this.readers.set(e,n));for(let r of t)n.set(r,null);}feedOf(e,t,n){if(e.feeds==="host"||e.feeds==="render")return e.feeds;if(t===null||!this.presented.has(n)||t.meta.channels!==void 0&&t.meta.channels.length>0)return "host";let r=this.readers.get(n);if(r===void 0)return "render";let o=t.meta.slots;for(let s=0;s<o.length;s++){let a=o[s];if(!a.write||!r.has(a.field))continue;if(r.get(a.field)!==t.program)return "host"}return "render"}noteCpuReads(e,t){if(e===null)return;let n=this.readers.get(t),r=e.meta.slots;for(let o=0;o<r.length;o++){let s=r[o];if(!s.read)continue;n===void 0&&(n=new Map,this.readers.set(t,n));let a=n.get(s.field);a===void 0?n.set(s.field,e.program):a!==null&&a!==e.program&&n.set(s.field,null);}}syncGpu(){this.gpu?.sync();}touchGpu(e,t,n=0){this.gpu?.touch(e,t,n);}onGpu(e,t,n,r,o,s,a,l){let c=t.name;if(o==="cpu"||xt.gpu==="off")return null;let u=s&&l===E_&&this.feedOf(t,e,n)==="render"?yVe(e.meta):l;if(o==="gpu"){if(this.gpu===null||!n.native||!this.gpu.available())throw new _("unsupported_feature",`kernel ${c} asked for the GPU, but this engine has no GPU kernels`);let E=this.gpu.run(e.meta,e.program,n,r,a,!s,u);if(E===null)throw new _("unsupported_feature",`kernel ${c} is not GPU-eligible; run it on the CPU or with device "auto"`);return E}if(this.gpu===null||xt.mode!=="auto"||!n.native||!this.gpu.eligible(e.program))return null;let d=r===null?n.count:r.length;if(d<xt.gpuRows)return null;let h=this.gpu.work(e.meta,e.program,n,d,xt.cpuLanes,!s,s&&this.gpuInFrame>0),p=e.meta.name.length>0?e.meta.name:c,m=this.routerFor(p,e.program,n),f=m.route(h),y=m.sampling;if(f!=="gpu")return y&&(this.sampleRouter=m,this.sampleWork=h,this.sampleName=p),null;let b=y?R_():0,A=this.gpu.run(e.meta,e.program,n,r,a,!s,u);return y&&this.recordSample(m,p,"gpu",h,b),A!==null&&s&&this.gpuInFrame++,A}machine(){let e=this.gpu,t=e===null?xt.gpuClass:e.deviceClass(xt.gpuClass),n=this.machineValue;if(this.machineFor===xt&&n!==null&&n.class===t)return n;let r=xt.cpuBackend==="auto"?e===null?"interpreter":e.hostBackend():xt.cpuBackend,o={class:t,backend:r,budgetNs:Math.round(xt.frameBudgetMs*d3),pressure:this.pressure};return this.machineFor=xt,this.machineValue=o,o}routerFor(e,t,n){let r=this.machine(),o=this.routers.get(n);o===void 0&&(o=new Map,this.routers.set(n,o));let s=o.get(t);if(s===void 0){let a=xt.gpuPins[e],l=wne()?xt.gpuCalibrate:0;a!==void 0?s=l>0?zi.replaying(r,l,a):zi.pinned(r,a):s=l>0?zi.calibrating(r,l):zi.model(r),o.set(t,s);}else s.machine!==r&&(s.machine=r);return s}recordSample(e,t,n,r,o){let s=e.pin;e.record(n,r,(R_()-o)*d3);let a=e.pin;s===null&&a!==null&&xt.onRoute?.({kernel:t,rows:r.rows,machine:e.machine,pin:a,runs:e.calibrationRuns});}partsTable(e,t){if(this.engine===null||this.gpu===null)return null;let n=Cg(this.engine.exports,this.engine.memory);return n===null?null:new vh(n,e,{capacity:t,selections:0})}gpuReady(){return this.gpu!==null&&xt.gpu!=="off"&&this.gpu.available()}gpuClass(){return this.machine().class}runSet(e,t,n,r,o){let s=this.gpu,a=s!==null&&r!=="cpu"&&t.native&&xt.gpu!=="off"&&s.available();for(let p=0;a&&p<e.gpu.length;p++)a=s.eligible(e.gpu[p].program);if(r==="gpu"){if(!a||!this.setOnGpu(e,t))throw new _("unsupported_feature",`${e.name} asked for the GPU, but this engine cannot run it there`);return "gpu"}if(!a||n<xt.gpuRows||xt.mode!=="auto")return o.runCpu(),"cpu";let l=this.setRouterFor(e,t,o.cpuForm==="wasm"?"wasm":"interpreter"),c=qte(e.cpu,e.gpuShape,l.machine,this.setScratch,o.cpuForm,ZM()),u=l.routeEstimate(c,n,Xte),d=l.sampling,h=d?R_():0;if(u==="gpu"&&!this.setOnGpu(e,t)&&(u="cpu"),u==="cpu"&&o.runCpu(),d){let p=l.pin;l.recordEstimate(u,c,n,(R_()-h)*d3);let m=l.pin;p===null&&m!==null&&xt.onRoute?.({kernel:e.name,rows:n,machine:l.machine,pin:m,runs:l.calibrationRuns});}return u}setOnGpu(e,t){let n=this.gpu,r=e.gpu.length-1;for(let o=0;o<=r;o++)if(n.run(e.gpu[o].meta,e.gpu[o].program,t,null,AVe,o===r)===null)return false;return true}setMachine(e){let t=this.machine();this.setMachineBase!==t&&(this.setMachines.clear(),this.setMachineBase=t);let n=this.setMachines.get(e);return n===void 0&&(n={...t,backend:e},this.setMachines.set(e,n)),n}setRouterFor(e,t,n){let r=this.setMachine(n),o=this.setRouters.get(t);o===void 0&&(o=new Map,this.setRouters.set(t,o));let s=o.get(e);if(s===void 0){let a=xt.gpuPins[e.name],l=wne()?xt.gpuCalibrate:0;a!==void 0?s=l>0?zi.replaying(r,l,a):zi.pinned(r,a):s=l>0?zi.calibrating(r,l):zi.model(r),o.set(e,s);}else s.machine!==r&&(s.machine=r);return s}get hasEngine(){return this.native!==null}compiled(){return this.native===null?Promise.resolve():this.native.settled()}kernelServices(e){this.world=e===null?null:new xv(e),this.vm.services=this.world,this.native?.attach(this.world);}get spawns(){return this.vm.report}dataReport(e){let t=p3(e[h3]);return t===null?null:this.native?.dataReport(t.program)??this.vm.reports.get(t.program)??null}plain(e,t,n,r){let o=this.world===null?null:a3(this.world),s=l3(this.sink);try{return this.js.run(e.plan,t,n,r)}finally{if(l3(s),this.world!==null&&a3(o),this.sink.used){let a=this.into!==null&&this.into!==t?this.into:null;Ef(this.sink.finish(t,a,this.vm.report),a??t,this.vm.report);}}}run(e,t,n,r,o,s,a,l,c,u,d){if(d!==void 0)throw new _("invalid_argument",`kernels take at most ${u3} arguments`);let h=u!==void 0?8:c!==void 0?7:l!==void 0?6:a!==void 0?5:s!==void 0?4:o!==void 0?3:r!==void 0?2:n!==void 0?1:0,m=(h<1||typeof n=="number")&&(h<2||typeof r=="number")&&(h<3||typeof o=="number")&&(h<4||typeof s=="number")&&(h<5||typeof a=="number")&&(h<6||typeof l=="number")&&(h<7||typeof c=="number")&&(h<8||typeof u=="number")?this.numericArgs[h]:this.args[h];return h>0&&(m[0]=n),h>1&&(m[1]=r),h>2&&(m[2]=o),h>3&&(m[3]=s),h>4&&(m[4]=a),h>5&&(m[5]=l),h>6&&(m[6]=c),h>7&&(m[7]=u),this.runWith(e,t,m)}runWith(e,t,n){let r=e[h3];if(r===void 0)throw new _("invalid_argument","run() takes a kernel made with kernel() or behaviour()");let o="selection"in t&&"table"in t?t.table:t,s="selection"in t&&"table"in t?t.selection:null,a=p3(r),l="selection"in t&&"table"in t?t.target:void 0,c=l??r.device??"auto",u=l==="gpu"||this.feedOf(r,a,o)==="render",d="selection"in t&&"table"in t?t.spawns??null:null;this.into=d,this.vm.into=d;let h=nq(r.priority);if(this.native!==null&&(this.native.into=d,this.native.priority=h),this.gpu!==null&&(this.gpu.priority=h),a!==null){let b="selection"in t&&"table"in t?t.mirror??E_:E_,A=this.onGpu(a,r,o,s,c,u,n,b);if(A!==null)return A}else if(c==="gpu")throw new _("unsupported_feature",`kernel ${r.name} has no bytecode for the GPU`);if(this.gpu===null)return this.onCpu(r,a,o,s,n);let p=this.sampleRouter,m=this.sampleWork;this.sampleRouter=null,this.sampleWork=null;let f=p!==null?R_():0;this.gpu.beforeCpu(o);let y=this.onCpu(r,a,o,s,n);return this.gpu.afterCpu(o,a===null?null:a.meta),this.noteCpuReads(a,o),p!==null&&m!==null&&this.recordSample(p,this.sampleName,"cpu",m,f),y}onCpu(e,t,n,r,o){let s=this.native!==null&&t!==null&&n.native&&!sVe(t.meta)&&(!ks(t.meta)||this.native.acceptsData())&&this.native.accepts(t.program)?this.native:null,a=t===null?null:s??this.vm,l=xt.mode;if(t!==null&&s===null&&l==="auto"&&hVe(t.program)!==null)return this.plain(e,n,r,o);if(l==="native"){if(s===null||t===null)throw new _("unsupported_feature",`kernel ${e.name} has no bytecode for this engine`);return s.run(t.meta,t.program,n,r,o)}if(l==="vm"){if(t===null)throw new _("unsupported_feature",`kernel ${e.name} has no bytecode`);return this.vm.run(t.meta,t.program,n,r,o)}return l==="auto"&&s!==null&&t!==null?s.run(t.meta,t.program,n,r,o):l==="auto"&&t!==null&&(vne(t.program)||Rne(t.program)||ks(t.meta))?this.vm.run(t.meta,t.program,n,r,o):l==="auto"?this.plain(e,n,r,o):t!==null&&(vne(t.program)||Rne(t.program)||ks(t.meta))?this.vm.run(t.meta,t.program,n,r,o):l!=="dev"||a===null||t===null||vVe(t.program)?this.plain(e,n,r,o):(e.runs++,e.runs%xt.checkEvery!==0?this.plain(e,n,r,o):this.check(e,t,a,n,r,o))}check(e,t,n,r,o,s){let a=EVe(r),l=r.count,c=a.map(p=>p.values.slice(0,l)),u=this.plain(e,r,o,s),d=a.map(p=>p.values.slice(0,l));a.forEach((p,m)=>p.values.set(c[m])),n.run(t.meta,t.program,r,o,s);let h=false;return a.forEach((p,m)=>{let f=d[m];for(let y=0;y<l&&!h;y++){let b=p.values[y];(!(p.values instanceof Float32Array)?f[y]===b:xVe(f[y],b,xt.tolerance))||(h=true,xt.report({kernel:e.name,field:p.field,component:p.component,row:y,js:f[y],native:b,source:`${t.meta.source}:${t.meta.line}:${t.meta.column}`}));}p.values.set(f);}),u}dispose(){this.native?.dispose(),this.gpu?.dispose();}},f3=null,wh=null;function One(i){wh!==null&&i===f3||(wh?.dispose(),f3=i,wh=new gi(i),Cte(Nte(i)),Lte(Mte(i)));}function Rv(){return wh===null&&(wh=new gi(f3)),wh}var wVe=[];function IVe(i){return "selection"in i&&"table"in i?i.table:i}function OVe(i,e){if(i.table!==e.table)return false;for(let t of i.writes)if(e.writes.has(t)||e.reads.has(t))return true;for(let t of e.writes)if(i.reads.has(t))return true;return false}var Sv=class{constructor(e){this.runner=e;this.systems=[];this.stageOf=[];this.order=[];}add(e){if(this.systems.some(r=>r.spec.name===e.name))throw new _("invalid_argument",`a kernel system named ${e.name} already exists`);let t={spec:e,table:IVe(e.set),reads:new Set(e.reads),writes:new Set(e.writes),args:e.args??wVe},n=Ine(e.kernel);if(n!==null)for(let r of n.meta.slots){if(r.write&&!t.writes.has(r.field))throw new _("invalid_argument",`system ${e.name} writes ${r.field} but declares writes [${e.writes.join(", ")}]; add it to writes`);if((r.read||r.neighbour)&&!t.reads.has(r.field)&&!t.writes.has(r.field))throw new _("invalid_argument",`system ${e.name} reads ${r.field} but declares reads [${e.reads.join(", ")}]; add it to reads`)}return this.systems.push(t),this.build(),this}build(){this.stageOf=[],this.systems.forEach((e,t)=>{let n=0;for(let r=0;r<t;r++)OVe(e,this.systems[r])&&(n=Math.max(n,this.stageOf[r]+1));this.stageOf.push(n);}),this.order=this.systems.map((e,t)=>t).sort((e,t)=>this.stageOf[e]-this.stageOf[t]||e-t);}stages(){let e=[];for(let t of this.order)(e[this.stageOf[t]]??=[]).push(this.systems[t].spec.name);return e}run(){let e=0;for(let t=0;t<this.order.length;t++){let n=this.systems[this.order[t]];e+=this.runner.runWith(n.spec.kernel,n.spec.set,n.args);}return e}};var _3=class{constructor(e,t){this.size=0;this.stores=e,this.entities=new Uint32Array(t),this.rows=Array.from({length:e.length},()=>new Int32Array(t));}get count(){return this.size}entityAt(e){return this.entities[e]}update(){let e=this.stores,t=0;for(let s=1;s<e.length;s++)e[s].count<e[t].count&&(t=s);let n=e[t],r=n.count,o=0;for(let s=0;s<r;s++){let a=n.entities[s],l=true;for(let c=0;c<e.length;c++){let u=c===t?s:e[c].row(a);if(u===-1){l=false;break}this.rows[c][o]=u;}l&&(this.entities[o++]=a);}return this.size=o,o}},Tv=class{constructor(e,t=Rx){this.stores=[];this.storeList=[];this.listeners=[];this.streamer=null;this.kernels=null;this.views=[];this.services=null;this.entities=new vx(e),this.memory=t,this.views.push(...this.entities.rollbackViews());}rollbackViews(){return this.views}get capacity(){return this.entities.capacity}attachKernels(e){this.kernels=e,this.services!==null&&e.kernelServices(this.services);}kernelServices(e){this.services=e,this.kernels===null&&(this.kernels=new gi(null)),this.kernels.kernelServices(e);}kernelFrame(){this.kernels?.frame();}kernelGpuPressure(e){this.kernels?.setGpuPressure(e);}presentKernels(e,t=true){this.kernels===null&&(this.kernels=new gi(null)),this.kernels.present(e,t);}presentsKernels(e){return this.kernels?.presents(e)??false}hostReads(e,t){this.kernels===null&&(this.kernels=new gi(null)),this.kernels.readsOnHost(e,t);}get kernelSpawns(){return this.kernels?.spawns??null}kernelData(e){return this.kernels?.dataReport(e)??null}kernelSystems(){return this.kernels===null&&(this.kernels=new gi(null)),new Sv(this.kernels)}run(e,t,n,r,o,s,a,l,c,u,d){this.kernels===null&&(this.kernels=new gi(null));let h=d!==void 0?9:u!==void 0?8:c!==void 0?7:l!==void 0?6:a!==void 0?5:s!==void 0?4:o!==void 0?3:r!==void 0?2:n!==void 0?1:0,p=this.kernels;switch(h){case 0:return p.run(e,t);case 1:return p.run(e,t,n);case 2:return p.run(e,t,n,r);case 3:return p.run(e,t,n,r,o);case 4:return p.run(e,t,n,r,o,s);case 5:return p.run(e,t,n,r,o,s,a);case 6:return p.run(e,t,n,r,o,s,a,l);case 7:return p.run(e,t,n,r,o,s,a,l,c);default:return p.run(e,t,n,r,o,s,a,l,c,u)}}attachStreamer(e){this.streamer=e;}stream(e){if(this.streamer===null)throw new _("unsupported_feature","this game has no world streaming backend");return this.streamer.stream(e)}register(e,t){let n=this.stores[e.id];if(n)return n;let r=new Tx(e,t??this.capacity,this.capacity,this.memory);return this.stores[e.id]=r,this.storeList.push(r),this.views.push(...r.rollbackViews()),r}store(e){let t=this.stores[e.id];if(!t)throw new _("missing_component",`component ${e.name} is not registered`);return t}spawn(){return this.entities.create()}despawn(e){if(!this.entities.isAlive(e))return false;for(let t=0;t<this.listeners.length;t++)this.listeners[t].onDespawn(e);for(let t=0;t<this.storeList.length;t++)this.storeList[t].remove(e);return this.entities.destroy(e)}isAlive(e){return this.entities.isAlive(e)}add(e,t){return this.entities.assertAlive(e),this.register(t).add(e)}remove(e,t){let n=this.stores[t.id];return n?n.remove(e):false}has(e,t){let n=this.stores[t.id];return n?n.has(e):false}query(...e){if(e.length===0)throw new _("invalid_argument","a query needs at least one component");return new _3(e.map(t=>this.register(t)),this.capacity)}onDespawn(e){this.listeners.push(e);}indexOf(e){return Vs(e)}};var T_=32,R3=0,Cne=4,Nne=8,kne=12,Lne=16,Mne=24;function zne(i,e){if(e===0||i.length<T_)return "touch";let t=i[R3];return t===O3?"tilt":t===S3||t===T3||t===w3||t===I3||t===Nv?"key":"touch"}var Dne=0,LVe=1,Iv=0,Ov=1,Pne=2,y3=3,Fne=4,Une=5,Bne=6,S3=0,T3=1,A3=2,b3=3,g3=4,w3=5,I3=6,Nv=7,Gne=8,Vne=9,O3=10,Hne=11,Wne=12,Cv=13,$s={none:0,keyboard:1,pointer:2,gamepad:3},E3=.5,El=0,Hc=1,x3=2,js=3,Kne=4,Nt=-1,v3=.5,MVe=.5,Yne=1,Xne=1e-6,DVe=500,PVe=.5,S_=2,w_=class{constructor(){this.ready=false;this.startX=0;this.startY=0;this.endX=0;this.endY=0;this.deltaX=0;this.deltaY=0;this.distance=0;this.durationMs=0;this.velocityX=0;this.velocityY=0;this.curl=0;}},I_=class{constructor(){this.ready=false;this.x=0;this.y=0;}},kv=class{constructor(){this.active=false;this.down=false;this.x=0;this.y=0;this.buttons=0;this.count=0;}},Oh=class{constructor(){this.active=false;this.scale=1;this.totalScale=1;this.centerX=0;this.centerY=0;this.panX=0;this.panY=0;this.rotation=0;this.distance=0;}},Ch=class{constructor(){this.deltaX=0;this.deltaY=0;this.deltaZ=0;this.x=0;this.y=0;}},jo=class{constructor(){this.x=0;this.y=0;}},Lv=class{constructor(){this.drag=new jo;this.motion=new jo;this.wheel=new Ch;this.pinch=new Oh;this.pressed=false;this.released=false;this.releasedButtons=0;this.pressX=0;this.pressY=0;}dragging(e){return (e.down||this.released)&&e.count<=1}dragButtons(e){return e.down?e.buttons:this.releasedButtons}begin(){this.drag.x=0,this.drag.y=0,this.motion.x=0,this.motion.y=0,this.wheel.deltaX=0,this.wheel.deltaY=0,this.wheel.deltaZ=0,this.pinch.active=false,this.pinch.scale=1,this.pinch.panX=0,this.pinch.panY=0,this.pinch.rotation=0,this.pressed=false,this.released=false,this.releasedButtons=0;}},O_=class{constructor(){this.ready=false;this.x=0;this.y=0;this.durationMs=0;}},Mv=class{constructor(){this.available=false;this.alpha=0;this.beta=0;this.gamma=0;}};nn(new w_,["startX","startY","endX","endY","deltaX","deltaY","distance","durationMs","velocityX","velocityY","curl"]);nn(new I_,["x","y"]);nn(new kv,["x","y"]);nn(new Oh,["scale","totalScale","centerX","centerY","panX","panY","rotation","distance"]);nn(new Ch,["deltaX","deltaY","deltaZ","x","y"]);nn(new jo,["x","y"]);nn(new Lv,["pressX","pressY"]);nn(new O_,["x","y","durationMs"]);nn(new Mv,["alpha","beta","gamma"]);var Dv=class{constructor(e={}){this.swipe=new w_;this.tap=new I_;this.pointer=new kv;this.pinch=new Oh;this.wheel=new Ch;this.drag=new jo;this.motion=new jo;this.look=new jo;this.frame=new Lv;this.longPress=new O_;this.orientation=new Mv;this.pendingSwipe=new w_;this.pendingTap=new I_;this.pendingPinch=new Oh;this.pendingWheel=new Ch;this.pendingDrag=new jo;this.pendingMotion=new jo;this.pendingLongPress=new O_;this.pointerX=new Float32Array(10);this.pointerY=new Float32Array(10);this.pointerButtons=new Int32Array(10);this.pointerOrder=new Float64Array(10);this.pointerSerial=0;this.pinchA=Nt;this.pinchB=Nt;this.pinchDistance=0;this.pinchAngle=0;this.pinchCenterX=0;this.pinchCenterY=0;this.multiTouch=false;this.longPressFired=false;this.longPressMoved=false;this.lastEventTime=0;this.lastDevice=$s.none;this.lastDeviceTime=0;this.frameNow=0;this.pointerFilter=null;this.stage=new Float64Array(Kne);this.pointerStage=new Float64Array(Kne);this.actionNames=new Map;this.actionCount=0;this.actionKind=new Uint8Array(128);this.actionValue=new Float32Array(128);this.bindingOut=new Float64Array(1);this.actionDown=new Uint8Array(128);this.pressedLatch=new Uint8Array(128);this.releasedLatch=new Uint8Array(128);this.justPressedStep=new Uint8Array(128);this.justReleasedStep=new Uint8Array(128);this.bindingCount=0;this.bindAction=new Uint16Array(512);this.bindKind=new Uint8Array(512);this.bindA=new Int32Array(512);this.bindB=new Int32Array(512);this.bindParam=new Float32Array(512);this.bindInvert=new Uint8Array(512);this.keySlots=new Map;this.keyDown=new Uint8Array(256);this.virtualSlots=new Map;this.virtualValue=new Float32Array(256);this.virtualButtons=new Uint16Array(256);this.gamepadButtons=new Float32Array(32);this.gamepadAxes=new Float32Array(16);this.pointerIds=new Int32Array(10).fill(Nt);this.primaryPointer=Nt;this.pointerDownCount=0;this.gestureStartX=0;this.gestureStartY=0;this.gestureStartTime=0;this.sampleX=new Float32Array(64);this.sampleY=new Float32Array(64);this.sampleCount=0;this.eventType=new Uint8Array(512);this.eventA=new Int32Array(512);this.eventX=new Float32Array(512);this.eventY=new Float32Array(512);this.eventZ=new Float32Array(512);this.eventTime=new Float64Array(512);this.eventHead=0;this.eventCount=0;this.droppedEvents=0;this.unlockListener=null;this.inputTap=null;this.tapBytes=null;this.tapView=null;this.replayView=null;this.swipeMinDistance=e.swipeMinDistance??.04,this.swipeMaxDurationMs=e.swipeMaxDurationMs??800,this.longPressMs=e.longPressMs??DVe;}pointerCount(){return this.pointerDownCount}pointerAt(e,t,n=0){let r=0;for(let o=0;o<10;o++)if(this.pointerIds[o]!==Nt){if(r===e)return t[n]=this.pointerX[o],t[n+1]=this.pointerY[o],true;r++;}return false}get dropped(){return this.droppedEvents}onFirstGesture(e){this.unlockListener=e;}defineButton(e,t){let n=this.defineAction(e,Dne);for(let r of t)switch(r.device){case "key":this.bind(n,Iv,this.keySlot(r.code),0,0,false);break;case "pointer":this.bind(n,Ov,0,0,0,false);break;case "gamepad":this.bind(n,Pne,this.checkIndex(r.button,32),0,r.threshold??v3,false);break;case "virtual":{let o=this.virtualSlot(r.control);this.bind(n,y3,o,0,v3,false),this.virtualButtons[o]++;break}}return n}defineAxis(e,t){let n=this.defineAction(e,LVe);for(let r of t)switch(r.device){case "keys":this.bind(n,Fne,this.keySlot(r.negative),this.keySlot(r.positive),0,false);break;case "gamepad":this.bind(n,Une,this.checkIndex(r.axis,16),0,r.deadzone??.15,r.invert===true);break;case "virtual":this.bind(n,Bne,this.virtualSlot(r.control),0,0,r.invert===true);break}return n}hasAction(e){return this.actionNames.has(e)}axisAction(e,t,n){let r=this.actionNames.get(e);if(r!==void 0)return r;let o=[],s=Math.min(t.length,n.length);for(let a=0;a<s;a++)o.push({device:"keys",negative:t[a],positive:n[a]});return this.defineAxis(e,o)}action(e){let t=this.actionNames.get(e);if(t===void 0)throw new _("invalid_argument",`unknown action ${e}`);return t}pressed(e){return this.actionDown[e]===1}justPressed(e){return this.justPressedStep[e]===1}justReleased(e){return this.justReleasedStep[e]===1}value(e){return this.actionValue[e]}valueInto(e,t,n){t[n]=this.actionValue[e];}keyEvent(e,t,n){let r=this.keySlots.get(e);r!==void 0&&this.push(t?S3:T3,r,0,0,n);}pointerStaged(e,t,n=Yne){let r=this.stage,o=this.pointerFilter;if(o!==null){let s=this.pointerStage;if(s[El]=r[El],s[Hc]=r[Hc],s[js]=r[js],o.filterPointer(e,t,s)){if(e==="down"){r[js]=s[js],this.pushStaged(Cv,$s.pointer);return}r[El]=0,r[Hc]=0;return}}r[x3]=n,this.pushStaged(e==="down"?A3:e==="move"?b3:g3,t);}setPointerFilter(e){this.pointerFilter=e;}pointerEvent(e,t,n,r,o,s=Yne){let a=this.pointerFilter;if(a!==null){let c=this.pointerStage;if(c[El]=n,c[Hc]=r,c[js]=o,a.filterPointer(e,t,c)){e==="down"&&this.push(Cv,$s.pointer,0,0,o);return}}let l=e==="down"?A3:e==="move"?b3:g3;this.push(l,t,n,r,o,s);}wheelEvent(e,t,n,r,o,s){this.push(Hne,0,r,o,s),this.push(Gne,0,e,t,s,n);}motionEvent(e,t,n){this.push(Vne,0,e,t,n);}orientationEvent(e,t,n,r){this.push(O3,0,e,t,r,n);}gamepadButtonEvent(e,t,n){e<0||e>=32||this.push(w3,e,t,0,n);}gamepadAxisEvent(e,t,n){e<0||e>=16||this.push(I3,e,t,0,n);}virtualEvent(e,t,n){let r=this.virtualSlots.get(e);r!==void 0&&this.push(Nv,r,t,0,n);}virtualControl(e){return this.virtualSlot(e)}virtualSlotEvent(e,t,n){let r=this.stage;r[El]=t,r[js]=n,this.virtualStaged(e);}virtualStaged(e){e<0||e>=256||this.pushStaged(Nv,e);}lookEvent(e,t,n){let r=this.stage;r[El]=e,r[Hc]=t,r[js]=n,this.lookStaged();}lookStaged(){this.pushStaged(Wne,0);}deviceStaged(e){this.pushStaged(Cv,e);}deviceEvent(e,t){this.stage[js]=t,this.deviceStaged(e);}get device(){return this.lastDevice}get deviceTimeMs(){return this.lastDeviceTime}processEvents(e=this.lastEventTime){this.frameNow=e,this.drain();}processEventsFrom(e,t){this.frameNow=e[t],this.drain();}setTap(e){this.inputTap=e,e!==null&&this.tapBytes===null&&(this.tapBytes=new Uint8Array(512*T_),this.tapView=new DataView(this.tapBytes.buffer));}replay(e,t,n){if(t!==null){(this.replayView===null||this.replayView.buffer!==t.buffer)&&(this.replayView=new DataView(t.buffer));let r=this.replayView;for(let o=0;o<n;o++){let s=t.byteOffset+o*T_;this.push(r.getUint32(s+R3,true),r.getInt32(s+Cne,true),r.getFloat32(s+Nne,true),r.getFloat32(s+kne,true),r.getFloat64(s+Mne,true),r.getFloat32(s+Lne,true));}}this.frameNow=e,this.drain();}record(){let e=this.inputTap,t=this.tapView,n=this.tapBytes;if(e===null||t===null||n===null)return;let r=this.eventHead;for(let o=0;o<this.eventCount;o++){let s=o*T_;t.setUint32(s+R3,this.eventType[r],true),t.setInt32(s+Cne,this.eventA[r],true),t.setFloat32(s+Nne,this.eventX[r],true),t.setFloat32(s+kne,this.eventY[r],true),t.setFloat32(s+Lne,this.eventZ[r],true),t.setFloat64(s+Mne,this.eventTime[r],true),r=(r+1)%512;}e.drained(this.frameNow,n.subarray(0,this.eventCount*T_),this.eventCount);}drain(){this.inputTap!==null&&this.record(),this.look.x=0,this.look.y=0,this.frame.begin();let e=this.eventHead;for(let t=0;t<this.eventCount;t++)this.apply(e),e=(e+1)%512;this.eventHead=e,this.eventCount=0,this.trackPinch(),this.detectLongPress(),this.evaluate();}beginStep(){for(let n=0;n<this.actionCount;n++)this.justPressedStep[n]=this.pressedLatch[n],this.justReleasedStep[n]=this.releasedLatch[n],this.pressedLatch[n]=0,this.releasedLatch[n]=0;UVe(this.swipe,this.pendingSwipe),this.pendingSwipe.ready=false,this.tap.ready=this.pendingTap.ready,this.tap.x=this.pendingTap.x,this.tap.y=this.pendingTap.y,this.pendingTap.ready=false,FVe(this.pinch,this.pendingPinch);let e=this.pendingWheel;this.wheel.deltaX=e.deltaX,this.wheel.deltaY=e.deltaY,this.wheel.deltaZ=e.deltaZ,this.wheel.x=e.x,this.wheel.y=e.y,e.deltaX=0,e.deltaY=0,e.deltaZ=0,this.drag.x=this.pendingDrag.x,this.drag.y=this.pendingDrag.y,this.pendingDrag.x=0,this.pendingDrag.y=0,this.motion.x=this.pendingMotion.x,this.motion.y=this.pendingMotion.y,this.pendingMotion.x=0,this.pendingMotion.y=0;let t=this.pendingLongPress;this.longPress.ready=t.ready,this.longPress.x=t.x,this.longPress.y=t.y,this.longPress.durationMs=t.durationMs,t.ready=false;}trackPinch(){let e=Nt,t=Nt;for(let u=0;u<10;u++)this.pointerIds[u]!==Nt&&(e===Nt||this.pointerOrder[u]<this.pointerOrder[e]?(t=e,e=u):(t===Nt||this.pointerOrder[u]<this.pointerOrder[t])&&(t=u));let n=this.pendingPinch;if(this.pointerDownCount<S_||e===Nt||t===Nt){n.active=false,this.pinchA=Nt,this.pinchB=Nt;return}if(e>t){let u=e;e=t,t=u;}let r=this.pointerX[t]-this.pointerX[e],o=this.pointerY[t]-this.pointerY[e],s=Math.sqrt(r*r+o*o),a=Math.atan2(o,r),l=(this.pointerX[e]+this.pointerX[t])*.5,c=(this.pointerY[e]+this.pointerY[t])*.5;if(e!==this.pinchA||t!==this.pinchB)this.pinchA=e,this.pinchB=t,n.active||(n.totalScale=1);else if(this.pinchDistance>Xne&&s>Xne){let u=s/this.pinchDistance;n.scale*=u,n.totalScale*=u,n.panX+=l-this.pinchCenterX,n.panY+=c-this.pinchCenterY;let d=a-this.pinchAngle;d>Math.PI?d-=Math.PI*2:d<-Math.PI&&(d+=Math.PI*2),n.rotation+=d;let h=this.frame.pinch;h.scale*=u,h.panX+=l-this.pinchCenterX,h.panY+=c-this.pinchCenterY,h.rotation+=d;}n.active=true,this.frame.pinch.active=true,this.frame.pinch.totalScale=n.totalScale,this.frame.pinch.centerX=l,this.frame.pinch.centerY=c,this.frame.pinch.distance=s,n.centerX=l,n.centerY=c,n.distance=s,this.pinchDistance=s,this.pinchAngle=a,this.pinchCenterX=l,this.pinchCenterY=c;}detectLongPress(){if(this.primaryPointer===Nt||this.longPressFired||this.longPressMoved||this.multiTouch)return;let t=(this.frameNow>this.lastEventTime?this.frameNow:this.lastEventTime)-this.gestureStartTime;if(t<this.longPressMs)return;this.longPressFired=true;let n=this.pendingLongPress;n.ready=true,n.x=this.gestureStartX,n.y=this.gestureStartY,n.durationMs=t;}defineAction(e,t){if(this.actionNames.has(e))throw new _("invalid_argument",`action ${e} exists`);if(this.actionCount>=128)throw new _("capacity_exceeded",`at most ${128} actions`);let n=this.actionCount++;return this.actionKind[n]=t,this.actionNames.set(e,n),n}bind(e,t,n,r,o,s){if(this.bindingCount>=512)throw new _("capacity_exceeded",`at most ${512} bindings`);let a=this.bindingCount++;this.bindAction[a]=e,this.bindKind[a]=t,this.bindA[a]=n,this.bindB[a]=r,this.bindParam[a]=o,this.bindInvert[a]=s?1:0;}keySlot(e){return qne(this.keySlots,e)}virtualSlot(e){return qne(this.virtualSlots,e)}checkIndex(e,t){if(e<0||e>=t)throw new _("invalid_argument",`index ${e} out of range`);return e}pushStaged(e,t){if(this.eventCount>=512){this.droppedEvents++;return}let n=(this.eventHead+this.eventCount)%512,r=this.stage;this.eventType[n]=e,this.eventA[n]=t,this.eventX[n]=r[El],this.eventY[n]=r[Hc],this.eventZ[n]=r[x3],this.eventTime[n]=r[js],r[El]=0,r[Hc]=0,r[x3]=0,this.eventCount++;}push(e,t,n,r,o,s=0){if(this.eventCount>=512){this.droppedEvents++;return}let a=(this.eventHead+this.eventCount)%512;this.eventType[a]=e,this.eventA[a]=t,this.eventX[a]=n,this.eventY[a]=r,this.eventZ[a]=s,this.eventTime[a]=o,this.eventCount++;}apply(e){let t=this.eventA[e],n=this.eventX[e],r=this.eventY[e],o=this.eventZ[e],s=this.eventTime[e];s>this.lastEventTime&&(this.lastEventTime=s);let a=$s.none;switch(this.eventType[e]){case Gne:this.pendingWheel.deltaX+=n,this.pendingWheel.deltaY+=r,this.pendingWheel.deltaZ+=o,this.frame.wheel.deltaX+=n,this.frame.wheel.deltaY+=r,this.frame.wheel.deltaZ+=o,this.firstGesture();break;case Hne:this.pendingWheel.x=n,this.pendingWheel.y=r,this.frame.wheel.x=n,this.frame.wheel.y=r;break;case Vne:this.pendingMotion.x+=n,this.pendingMotion.y+=r,this.frame.motion.x+=n,this.frame.motion.y+=r;break;case O3:this.orientation.available=true,this.orientation.alpha=n,this.orientation.beta=r,this.orientation.gamma=o;break;case Wne:this.look.x+=n,this.look.y+=r;break;case Cv:a=t,this.firstGesture();break;case S3:this.keyDown[t]===0&&this.latchSlot(Iv,t,true),this.keyDown[t]=1,a=$s.keyboard,this.firstGesture();break;case T3:this.keyDown[t]===1&&this.latchSlot(Iv,t,false),this.keyDown[t]=0;break;case A3:this.pointerDown(t,e),a=$s.pointer,this.firstGesture();break;case b3:this.pointerMove(t,e);break;case g3:this.pointerUp(t,e);break;case w3:this.gamepadButtons[t]=n,n>=E3&&(a=$s.gamepad),this.firstGesture();break;case I3:this.gamepadAxes[t]=n,(n>=E3||n<=-E3)&&(a=$s.gamepad);break;case Nv:this.latchVirtual(t,e),this.virtualValue[t]=n,this.firstGesture();break}a!==$s.none&&(this.lastDevice=a,this.lastDeviceTime=s);}latchVirtual(e,t){if(this.virtualButtons[e]===0)return;let n=this.virtualValue[e],r=this.eventX[t];for(let o=0;o<this.bindingCount;o++){if(this.bindKind[o]!==y3||this.bindA[o]!==e)continue;let s=this.bindParam[o],a=this.bindAction[o];n<s&&r>=s?this.pressedLatch[a]=1:n>=s&&r<s&&(this.releasedLatch[a]=1);}}firstGesture(){let e=this.unlockListener;e&&(this.unlockListener=null,e());}latchSlot(e,t,n){for(let r=0;r<this.bindingCount;r++){if(this.bindKind[r]!==e||this.bindA[r]!==t)continue;let o=this.bindAction[r];n?this.pressedLatch[o]=1:this.releasedLatch[o]=1;}}pointerDown(e,t){let n=this.eventX[t],r=this.eventY[t],o=this.eventZ[t],s=this.pointerSlot(e);if(s===Nt){if(s=this.pointerSlot(Nt),s===Nt)return;this.pointerIds[s]=e,this.pointerOrder[s]=this.pointerSerial++,this.pointerDownCount++;}this.pointerX[s]=n,this.pointerY[s]=r,this.pointerButtons[s]=o,this.pointer.count=this.pointerDownCount,this.pointerDownCount>=S_&&(this.multiTouch=true),this.primaryPointer===Nt&&(this.primaryPointer=e,this.gestureStartX=n,this.gestureStartY=r,this.gestureStartTime=this.eventTime[t],this.multiTouch=this.pointerDownCount>=S_,this.longPressFired=false,this.longPressMoved=false,this.sampleCount=0,this.recordSample(t),this.pointer.active=true,this.pointer.down=true,this.pointer.x=n,this.pointer.y=r,this.pointer.buttons=o,this.frame.pressed=true,this.frame.pressX=n,this.frame.pressY=r,this.latchSlot(Ov,0,true));}pointerMove(e,t){let n=this.eventX[t],r=this.eventY[t],o=this.eventZ[t],s=this.pointerSlot(e);if(s!==Nt&&(this.pointerX[s]=n,this.pointerY[s]=r,this.pointerButtons[s]=o),e!==this.primaryPointer){this.primaryPointer===Nt&&(this.pointer.active=true,this.pointer.x=n,this.pointer.y=r);return}this.pointerDownCount<S_&&this.addDrag(n-this.pointer.x,r-this.pointer.y),this.pointer.x=n,this.pointer.y=r,this.pointer.buttons=o;let a=n-this.gestureStartX,l=r-this.gestureStartY,c=this.swipeMinDistance*PVe;a*a+l*l>c*c&&(this.longPressMoved=true),this.recordSample(t);}pointerUp(e,t){let n=this.eventX[t],r=this.eventY[t],o=this.pointerSlot(e);o!==Nt&&(this.pointerIds[o]=Nt,this.pointerButtons[o]=0,this.pointerDownCount--),this.pointer.count=this.pointerDownCount,e===this.primaryPointer&&(this.primaryPointer=Nt,this.pointerDownCount<S_-1&&this.addDrag(n-this.pointer.x,r-this.pointer.y),this.frame.releasedButtons=this.pointer.buttons,this.pointer.down=false,this.pointer.buttons=0,this.pointer.x=n,this.pointer.y=r,this.frame.released=true,this.recordSample(t),this.latchSlot(Ov,0,false),!this.multiTouch&&!this.longPressFired&&this.recognize(t));}addDrag(e,t){this.pendingDrag.x+=e,this.pendingDrag.y+=t,this.frame.drag.x+=e,this.frame.drag.y+=t;}pointerSlot(e){for(let t=0;t<10;t++)if(this.pointerIds[t]===e)return t;return Nt}recordSample(e){let t=this.sampleCount>=64?63:this.sampleCount++;this.sampleX[t]=this.eventX[e],this.sampleY[t]=this.eventY[e];}recognize(e){let t=this.eventX[e],n=this.eventY[e],r=t-this.gestureStartX,o=n-this.gestureStartY,s=(r*r+o*o)**.5,a=this.bindingOut;a[0]=this.eventTime[e]-this.gestureStartTime,a[0]<1&&(a[0]=1);let l=a[0];if(s>=this.swipeMinDistance&&l<=this.swipeMaxDurationMs){let c=this.pendingSwipe;c.ready=true,c.startX=this.gestureStartX,c.startY=this.gestureStartY,c.endX=t,c.endY=n,c.deltaX=r,c.deltaY=o,c.distance=s,c.durationMs=l,c.velocityX=r/l,c.velocityY=o/l,this.curlInto(c);return}s<this.swipeMinDistance*MVe&&(this.pendingTap.ready=true,this.pendingTap.x=t,this.pendingTap.y=n);}curlInto(e){let t=e.distance,n=this.bindingOut;n[0]=0;let r=-e.deltaY/t,o=e.deltaX/t;for(let s=0;s<this.sampleCount;s++){let a=(this.sampleX[s]-this.gestureStartX)*r+(this.sampleY[s]-this.gestureStartY)*o;Math.abs(a)>Math.abs(n[0])&&(n[0]=a);}e.curl=n[0]/t;}evaluate(){let e=this.actionValue;for(let n=0;n<this.actionCount;n++)e[n]=0;let t=this.bindingOut;for(let n=0;n<this.bindingCount;n++){let r=this.bindAction[n];this.bindingValue(n,t);let o=t[0],s=e[r];Math.abs(o)>Math.abs(s)&&(e[r]=o);}for(let n=0;n<this.actionCount;n++){if(this.actionKind[n]!==Dne)continue;let r=e[n]>=v3?1:0;r===1&&this.actionDown[n]===0&&(this.pressedLatch[n]=1),r===0&&this.actionDown[n]===1&&(this.releasedLatch[n]=1),this.actionDown[n]=r;}}bindingValue(e,t){let n=this.bindA[e],r=0;switch(this.bindKind[e]){case Iv:r=this.keyDown[n];break;case Ov:r=this.pointerDownCount>0?1:0;break;case Pne:r=this.gamepadButtons[n]>=this.bindParam[e]?1:0;break;case y3:r=this.virtualValue[n]>=this.bindParam[e]?1:0;break;case Fne:r=this.keyDown[this.bindB[e]]-this.keyDown[n];break;case Une:{let o=this.gamepadAxes[n],s=this.bindParam[e];r=(o<0?-o:o)<s?0:(o-(o>0?1:o<0?-1:o)*s)/(1-s);break}case Bne:r=this.virtualValue[n];break}t[0]=this.bindInvert[e]===1?-r:r;}};function qne(i,e){let t=i.get(e);if(t!==void 0)return t;if(i.size>=256)throw new _("capacity_exceeded",`at most ${256} input slots`);let n=i.size;return i.set(e,n),n}function FVe(i,e){i.active=e.active,i.scale=e.scale,i.totalScale=e.totalScale,i.centerX=e.centerX,i.centerY=e.centerY,i.panX=e.panX,i.panY=e.panY,i.rotation=e.rotation,i.distance=e.distance,e.scale=1,e.panX=0,e.panY=0,e.rotation=0;}function UVe(i,e){i.ready=e.ready,i.startX=e.startX,i.startY=e.startY,i.endX=e.endX,i.endY=e.endY,i.deltaX=e.deltaX,i.deltaY=e.deltaY,i.distance=e.distance,i.durationMs=e.durationMs,i.velocityX=e.velocityX,i.velocityY=e.velocityY,i.curl=e.curl;}var Pv=class{constructor(e={}){this.vec3Used=0;this.quatUsed=0;this.mat4Used=0;let t=e.vec3??256,n=e.quat??64;this.mat4Capacity=e.mat4??64,this.vec3s=Array.from({length:t},()=>new Kt),this.quats=Array.from({length:n},()=>new vc),this.mat4s=new Float32Array(this.mat4Capacity*16);}vec3(e=0,t=0,n=0){if(this.vec3Used>=this.vec3s.length)throw new _("capacity_exceeded","scratch Vec3 arena exhausted this frame");return this.vec3s[this.vec3Used++].set(e,t,n)}quat(){if(this.quatUsed>=this.quats.length)throw new _("capacity_exceeded","scratch Quat arena exhausted this frame");return this.quats[this.quatUsed++].identity()}mat4(){if(this.mat4Used>=this.mat4Capacity)throw new _("capacity_exceeded","scratch Mat4 arena exhausted this frame");return this.mat4Used++*16}get matrices(){return this.mat4s}reset(){this.vec3Used=0,this.quatUsed=0,this.mat4Used=0;}};var fHe=16;var C3=class{constructor(e){this.length=0;this.words=new Uint32Array(e),this.bytes=new DataView(this.words.buffer);}u(e){this.words[this.length++]=e>>>0;}f(e){if(!Number.isFinite(e))throw new _("invalid_argument","AI declarations take finite numbers only");this.bytes.setFloat32(this.length*4,e,true),this.length++;}pair(e){this.f(e[0]),this.f(e[1]);}};function ere(i,e){let t=new Array(fHe).fill(0),n,r=0;switch(e.kind){case "linear":n=0,t[0]=e.slope,t[1]=e.offset;break;case "polynomial":n=1,t[0]=e.exponent,t[1]=e.slope,t[2]=e.offset;break;case "logistic":n=2,t[0]=e.steepness,t[1]=e.midpoint;break;case "step":n=3,t[0]=e.threshold,t[1]=e.below,t[2]=e.above;break;case "points":if(n=4,e.x.length!==e.y.length||e.x.length<2||e.x.length>8)throw new _("invalid_argument",`curve points take 2 to ${8} matching x and y values`);r=e.x.length;for(let o=0;o<r;o++)t[o]=e.x[o],t[8+o]=e.y[o];break}i.u(n),i.u(r);for(let o of t)i.f(o);}function _He(i,e){let t=0,n=0,r=0,o=0,s=0;switch(e.kind){case "idle":break;case "move_to_focus":t=1,n=e.arriveRadius;break;case "pursue":t=2,n=e.leadSeconds,r=e.arriveRadius;break;case "flee":t=3,n=e.safeDistance;break;case "keep_distance":t=4,n=e.min,r=e.max;break;case "search":t=5,n=e.arriveRadius;break;case "wander":t=6;break;case "move_to_goal":t=7,n=e.arriveRadius;break;case "attack":t=8,n=e.range,r=e.windupTicks,o=e.strikeTicks,s=e.recoverTicks;break;case "take_cover":t=9,n=e.maxDistance;break;case "hold_formation":t=10,n=e.arriveRadius;break;case "use_object":t=11,n=e.maxDistance;for(let a of e.kinds)s|=1<<a;break;case "follow_schedule":t=12,n=e.arriveRadius;break;case "bark":t=13,s=e.lineSet;break;case "game":t=14,s=e.code;break}i.u(t),i.f(n),i.f(r),i.f(o),i.u(s);}var yHe={kinematic:0,external:1,crowd:2},AHe=8192;function tre(i){let e=Object.keys(i.inputs);if(e.length>16)throw new _("invalid_argument",`an archetype takes at most ${16} inputs`);if(i.actions.length===0||i.actions.length>16)throw new _("invalid_argument",`an archetype takes 1 to ${16} actions`);if(i.needs.length>8)throw new _("invalid_argument",`an archetype takes at most ${8} needs`);if(i.schedule.length>16)throw new _("invalid_argument",`a schedule takes at most ${16} blocks`);let t=new C3(AHe),n=i.sight;t.u(1),t.u(i.thinkEveryTicks),t.u(i.senseEveryTicks),t.u(e.length),t.u(i.actions.length),t.u(i.needs.length),t.u(i.schedule.length),t.u((n?1:0)|(i.hearing?2:0)),t.f(i.memorySeconds),t.f(i.awarenessRadius),t.f(i.scheduleJitterMinutes),t.f(i.steering.maxSpeed),t.f(i.steering.maxAcceleration),t.f(i.steering.radius),t.f(i.steering.separationWeight),t.f(i.steering.separationRadius),t.u(yHe[i.steering.motion]),t.pair(i.skill.reactionSeconds),t.pair(i.skill.aimSigma),t.pair(i.skill.perceptionScale),t.pair(i.skill.tolerance),t.pair(i.skill.mistakeChance),t.f(n?.range??0),t.f(n?.fovCos??0),t.f(n?.peripheralRange??0),t.f(n?.peripheralCos??0),t.f(n?.eyeHeight??0),t.u(n?.lineOfSight?1:0),t.f(i.hearing?.sensitivity??0);for(let r of e){let o=i.inputs[r],s=o.source;s.kind==="builtin"?(t.u(0),t.u(CQ.indexOf(s.input))):s.kind==="game"?(t.u(1),t.u(s.slot)):(t.u(2),t.u(s.need)),t.f(o.min),t.f(o.max);}for(let r of i.actions){if(r.considerations.length>8)throw new _("invalid_argument",`action ${r.name} takes at most ${8} considerations`);t.f(r.base),t.f(r.momentum),t.u(r.cooldownTicks),t.f(r.speed),_He(t,r.behaviour),t.u(r.considerations.length);for(let o of r.considerations){let s=e.indexOf(o.input);if(s<0)throw new _("invalid_argument",`action ${r.name} considers an undeclared input ${o.input}`);t.u(s),ere(t,o.curve);}}for(let r of i.needs)t.f(r.decayPerMinute),t.f(r.initial),ere(t,r.urgency);for(let r of i.schedule)t.f(r.startMinute),t.f(r.endMinute),t.u(r.activity),t.f(r.place[0]),t.f(r.place[1]),t.f(r.place[2]),t.f(r.radius);return t.words.slice(0,t.length)}function nre(i,e){let t=i.actions.findIndex(n=>n.name===e);if(t<0)throw new _("invalid_argument",`archetype ${i.name} has no action ${e}`);return t}var Dn=0,Js=4,dre=1048575,D3=4,QHe={maxTargets:16,maxSquads:8,maxObjects:0,maxCover:0,memorySlots:4,sightRaysPerTick:64,eventCapacity:256,tickHz:60,seed:0,attackTokens:2,gridCell:4,minutesPerTick:0,startMinute:0},$He=["invalid_argument","capacity_exceeded","dead_entity","unknown_resource","invalid_argument","unsupported_feature"],Bv=class{constructor(e){this.handle=Dn;this.capacity=0;this.buffer=null;this.registerWords=new Uint32Array(0);this.registerFloats=new Float32Array(0);this.viewWords=new Uint32Array(0);this.viewFloats=new Float32Array(0);this.slotFloats=new Float32Array(0);this.eventBuffer=Dn;this.eventWords=new Uint32Array(0);this.eventCapacity=0;this.scratch=Dn;this.scratchBytes=0;this.scratchWords=new Uint32Array(0);this.port=e,this.exports=e.exports;}get backend(){return this.port.name}get ready(){return this.handle!==Dn}check(e,t){if(e<0)throw new _($He[-e]??"invalid_argument",`${t} failed`);return e}require(){if(this.handle===Dn)throw new _("not_initialized","game AI is not initialised");return this.handle}refresh(){let e=this.port.buffer();if(e===this.buffer)return;this.buffer=e;let t=this.handle,n=this.exports.engine_ai_registers(t);this.registerWords=new Uint32Array(e,n,32),this.registerFloats=new Float32Array(e,n,32);let r=this.exports.engine_ai_view(t);this.viewWords=new Uint32Array(e,r,this.capacity*12),this.viewFloats=new Float32Array(e,r,this.capacity*12);let o=this.exports.engine_ai_slots(t);this.slotFloats=new Float32Array(e,o,this.capacity*16),this.eventWords=new Uint32Array(e,this.eventBuffer,this.eventCapacity*5),this.scratch!==Dn&&(this.scratchWords=new Uint32Array(e,this.scratch,this.scratchBytes/Js));}scratchFor(e){let t=e*Js;if(t>this.scratchBytes){if(this.scratch!==Dn&&this.port.free(this.scratch,this.scratchBytes,Js),this.scratch=this.port.alloc(t,Js),this.scratch===Dn)throw new _("capacity_exceeded","engine memory is full");this.scratchBytes=t,this.buffer=null;}return this.refresh(),this.scratchWords}init(e){if(this.handle!==Dn)throw new _("invalid_argument","game AI is already initialised");let t={...QHe,...e},n=this.scratchFor(16),r=new Float32Array(n.buffer,n.byteOffset,16);n.fill(0,0,16),n[0]=t.maxAgents,n[1]=t.maxTargets,n[2]=t.maxSquads,n[3]=t.maxObjects,n[4]=t.maxCover,n[5]=t.memorySlots,n[6]=t.sightRaysPerTick,n[7]=t.eventCapacity,n[8]=t.tickHz,n[9]=t.seed>>>0,n[10]=Math.floor(t.seed/4294967296)>>>0,n[11]=t.attackTokens,r[12]=t.gridCell,r[13]=t.minutesPerTick,r[14]=t.startMinute;let o=this.exports.engine_ai_create(this.scratch);if(o===Dn)throw new _("invalid_argument","the AI world description was refused");if(this.handle=o,this.capacity=t.maxAgents,this.eventCapacity=t.eventCapacity,this.eventBuffer=this.port.alloc(t.eventCapacity*5*Js,Js),this.eventBuffer===Dn)throw new _("capacity_exceeded","engine memory is full");this.buffer=null,this.refresh();}dispose(){this.handle!==Dn&&(this.exports.engine_ai_destroy(this.handle),this.eventBuffer!==Dn&&this.port.free(this.eventBuffer,this.eventCapacity*5*Js,Js),this.scratch!==Dn&&this.port.free(this.scratch,this.scratchBytes,Js),this.handle=Dn,this.eventBuffer=Dn,this.scratch=Dn,this.scratchBytes=0);}archetype(e){let t=this.require(),n=tre(e);return this.scratchFor(n.length).set(n),{id:this.check(this.exports.engine_ai_archetype(t,this.scratch,n.length),`archetype ${e.name}`),decl:e}}action(e,t){return nre(e.decl,t)}registers(){return this.refresh(),this.registerWords}writePosition(e,t,n){let r=this.registerFloats;r[3]=e,r[4]=t,r[5]=n;}spawn(e,t){let n=this.require(),r=this.registers(),o=this.registerFloats;r[1]=t.entity,r[2]=t.team??1;let s=t.position??[0,0,0];this.writePosition(s[0],s[1],s[2]);let a=t.forward??[0,1];return o[6]=a[0],o[7]=a[1],o[10]=t.skill??.5,o[11]=t.threat??1,this.check(this.exports.engine_ai_spawn(n,e.id),"spawn"),this.registerWords[0]}despawn(e){this.check(this.exports.engine_ai_despawn(this.require(),e),"despawn");}addTarget(e){let t=this.require(),n=this.registers();return n[1]=e.entity,n[2]=e.team,this.writePosition(e.position[0],e.position[1],e.position[2]),this.registerFloats[11]=e.threat??1,this.check(this.exports.engine_ai_target_add(t),"add target"),this.registerWords[0]}removeTarget(e){this.check(this.exports.engine_ai_target_remove(this.require(),e),"remove target");}moveTarget(e,t,n,r,o,s){let a=this.require();this.registers(),this.writePosition(t,n,r),this.registerFloats[8]=o,this.registerFloats[9]=s,this.check(this.exports.engine_ai_target_move(a,e),"move target");}setThreat(e,t){this.check(this.exports.engine_ai_target_threat(this.require(),e,t),"set threat");}targetOf(e){return this.check(this.exports.engine_ai_agent_target(this.require(),e),"target of"),this.registerWords[0]}noise(e,t,n,r,o,s=4294967295){let a=this.require();this.registers(),this.writePosition(e,t,n),this.registerFloats[12]=r,this.check(this.exports.engine_ai_noise(a,o,s),"noise");}setGoal(e,t,n,r){let o=this.require();this.registers(),this.writePosition(t,n,r),this.check(this.exports.engine_ai_goal(o,e,1),"set goal");}clearGoal(e){this.check(this.exports.engine_ai_goal(this.require(),e,0),"clear goal");}setFocus(e,t=4294967295,n=false){this.check(this.exports.engine_ai_focus(this.require(),e,t,n?1:0),"set focus");}setSkill(e,t){this.check(this.exports.engine_ai_skill(this.require(),e,t),"set skill");}setNeed(e,t,n){this.check(this.exports.engine_ai_need(this.require(),e,t,n),"set need");}setSpeedScale(e,t){this.check(this.exports.engine_ai_speed(this.require(),e,t),"set speed scale");}place(e,t,n,r,o,s){let a=this.require();this.registers(),this.writePosition(t,n,r),this.registerFloats[8]=o,this.registerFloats[9]=s,this.check(this.exports.engine_ai_place(a,e),"place");}slot(e){if(e<0||e>=16)throw new _("invalid_argument",`game input slots are 0 to ${15}`);return this.refresh(),this.slotFloats.subarray(e*this.capacity,(e+1)*this.capacity)}setInput(e,t,n){this.refresh(),this.slotFloats[t*this.capacity+(e&dre)]=n;}step(){this.check(this.port.step(this.require()),"step");}viewAt(e,t){return this.refresh(),(e&dre)*12+t}x(e){return this.viewFloats[this.viewAt(e,0)]}y(e){return this.viewFloats[this.viewAt(e,1)]}z(e){return this.viewFloats[this.viewAt(e,2)]}vx(e){return this.viewFloats[this.viewAt(e,3)]}vz(e){return this.viewFloats[this.viewAt(e,4)]}forwardX(e){return this.viewFloats[this.viewAt(e,5)]}forwardZ(e){return this.viewFloats[this.viewAt(e,6)]}actionOf(e){return this.viewWords[this.viewAt(e,7)]}phaseOf(e){return this.viewWords[this.viewAt(e,8)]}focusOf(e){return this.viewWords[this.viewAt(e,9)]}drainEvents(e){let t=this.require(),n=Math.min(this.eventCapacity,Math.floor(e.length/5));if(n===0)return 0;let r=this.check(this.exports.engine_ai_events(t,this.eventBuffer,n),"events");return this.refresh(),e.set(this.eventWords.subarray(0,r*5)),r}doing(e,t,n){let r=this.require(),o=this.scratchFor(Math.max(n.length,1)),s=this.check(this.exports.engine_ai_doing(r,e.id,t,this.scratch,n.length),"doing"),a=Math.min(s,n.length);return n.set(o.subarray(0,a)),a}aimNoise(e,t){return this.exports.engine_ai_aim(this.require(),e,t>>>0)}digest(e){let t=this.require(),n=this.scratchFor(2);this.check(this.exports.engine_ai_digest(t,this.scratch),"digest"),e[0]=n[0],e[1]=n[1];}squad(e){let t=this.require(),n=this.scratchFor(Math.max(e.length*2,1)),r=new Float32Array(n.buffer,n.byteOffset,e.length*2);return e.forEach((o,s)=>{r[s*2]=o[0],r[s*2+1]=o[1];}),this.check(this.exports.engine_ai_squad(t,this.scratch,e.length),"squad")}join(e,t){this.check(this.exports.engine_ai_join(this.require(),e,t),"join squad");}leave(e){this.check(this.exports.engine_ai_leave(this.require(),e),"leave squad");}addObject(e){let t=this.require();if(e.advertisements.length>D3)throw new _("invalid_argument",`a smart object advertises at most ${D3} needs`);let n=this.registers(),r=this.registerFloats;n[13]=e.kind,this.writePosition(e.position[0],e.position[1],e.position[2]);for(let o=0;o<D3;o++){let s=e.advertisements[o];n[17+o*2]=s?s[0]:0,r[17+o*2+1]=s?s[1]:0;}return n[16]=e.advertisements.length,n[14]=e.capacity,r[15]=e.useMinutes,r[12]=e.interactRadius,this.check(this.exports.engine_ai_object_add(t),"add smart object"),this.registerWords[0]}removeObject(e){this.check(this.exports.engine_ai_object_remove(this.require(),e),"remove smart object");}addCover(e,t,n){let r=this.require();return this.registers(),this.writePosition(e,t,n),this.check(this.exports.engine_ai_cover_add(r),"add cover"),this.registerWords[0]}removeCover(e){this.check(this.exports.engine_ai_cover_remove(this.require(),e),"remove cover");}};var dn=6,hre=32768,lt=-1,jHe=1447120451,JHe=2,P3=60,pre=10,Wc=3,ZHe=dn*4+2,Qi=4096,Zs=4096,eWe=.01,F3=[-1,0,1,0],U3=[0,1,0,-1],Jo=8,B3=class{constructor(e){this.bmin=new Float64Array(3);this.bmax=new Float64Array(3);this.salt=1;this.linkTarget=new Float64Array(0);this.linkEdge=new Uint8Array(0);this.linkMin=new Float64Array(0);this.linkMax=new Float64Array(0);this.linkStart=new Uint32Array(0);this.gridStart=new Uint32Array(Jo*Jo+1);this.gridPolys=new Uint16Array(0);let t=new DataView(e.buffer,e.byteOffset,e.byteLength);if(e.byteLength<P3||t.getUint32(0,true)!==jHe||t.getUint32(4,true)!==JHe)throw new _("invalid_argument","not a navmesh tile");this.x=t.getInt32(8,true),this.z=t.getInt32(12,true);for(let c=0;c<3;c++)this.bmin[c]=t.getFloat32(16+c*4,true),this.bmax[c]=t.getFloat32(28+c*4,true);this.climb=t.getFloat32(40,true);let n=t.getUint32(44,true),r=t.getUint32(48,true),o=t.getUint32(52,true),s=t.getUint32(56,true),a=P3+n*12+r*(ZHe+pre)+o*12+s*Wc;if(e.byteLength!==a||r===0||r>Qi)throw new _("invalid_argument","navmesh tile has the wrong size");this.polys=r,this.verts=new Float64Array(n*3);let l=P3;for(let c=0;c<n*3;c++,l+=4)this.verts[c]=t.getFloat32(l,true);this.polyVerts=new Uint16Array(r*dn),this.polyNeis=new Uint16Array(r*dn),this.polyCount=new Uint8Array(r),this.polyArea=new Uint8Array(r),this.bounds=new Float64Array(r*6);for(let c=0;c<r;c++){for(let h=0;h<dn;h++,l+=2)this.polyVerts[c*dn+h]=t.getUint16(l,true);for(let h=0;h<dn;h++,l+=2)this.polyNeis[c*dn+h]=t.getUint16(l,true);let u=t.getUint8(l);if(this.polyCount[c]=u,this.polyArea[c]=t.getUint8(l+1),l+=2,u<3||u>dn)throw new _("invalid_argument","navmesh polygon is malformed");let d=c*6;this.bounds[d]=this.bounds[d+1]=this.bounds[d+2]=1/0,this.bounds[d+3]=this.bounds[d+4]=this.bounds[d+5]=-1/0;for(let h=0;h<u;h++){let p=this.polyVerts[c*dn+h];if(p>=n)throw new _("invalid_argument","navmesh vertex out of range");for(let m=0;m<3;m++)this.bounds[d+m]=Math.min(this.bounds[d+m],this.verts[p*3+m]),this.bounds[d+3+m]=Math.max(this.bounds[d+3+m],this.verts[p*3+m]);}}this.detailVertBase=new Uint32Array(r),this.detailTriBase=new Uint32Array(r),this.detailVertCount=new Uint8Array(r),this.detailTriCount=new Uint8Array(r);for(let c=0;c<r;c++,l+=pre)if(this.detailVertBase[c]=t.getUint32(l,true),this.detailTriBase[c]=t.getUint32(l+4,true),this.detailVertCount[c]=t.getUint8(l+8),this.detailTriCount[c]=t.getUint8(l+9),this.detailVertBase[c]+this.detailVertCount[c]>o||this.detailTriBase[c]+this.detailTriCount[c]>s)throw new _("invalid_argument","navmesh detail is malformed");this.detailVerts=new Float64Array(o*3);for(let c=0;c<o*3;c++,l+=4)this.detailVerts[c]=t.getFloat32(l,true);this.detailTris=e.slice(l,l+s*Wc);for(let c=0;c<r;c++){let u=this.polyCount[c]+this.detailVertCount[c],d=this.detailTriBase[c]*Wc;for(let h=0;h<this.detailTriCount[c]*Wc;h++)if(this.detailTris[d+h]>=u)throw new _("invalid_argument","navmesh detail index out of range")}this.buildGrid();}detailCorner(e,t,n,r){let o=this.polyCount[e],s=t<o?this.polyVerts[e*dn+t]*3:(this.detailVertBase[e]+t-o)*3,a=t<o?this.verts:this.detailVerts;n[r]=a[s],n[r+1]=a[s+1],n[r+2]=a[s+2];}cell(e,t){let n=(this.bmax[t]-this.bmin[t])/Jo,r=Math.floor((e-this.bmin[t])/n);return r<0?0:r>=Jo?Jo-1:r}buildGrid(){let e=this.gridStart;e.fill(0);for(let n=0;n<this.polys;n++){let r=n*6;for(let o=this.cell(this.bounds[r+2],2);o<=this.cell(this.bounds[r+5],2);o++)for(let s=this.cell(this.bounds[r],0);s<=this.cell(this.bounds[r+3],0);s++)e[o*Jo+s+1]++;}for(let n=1;n<e.length;n++)e[n]+=e[n-1];let t=e.slice();this.gridPolys=new Uint16Array(e[Jo*Jo]);for(let n=0;n<this.polys;n++){let r=n*6;for(let o=this.cell(this.bounds[r+2],2);o<=this.cell(this.bounds[r+5],2);o++)for(let s=this.cell(this.bounds[r],0);s<=this.cell(this.bounds[r+3],0);s++)this.gridPolys[t[o*Jo+s]++]=n;}}collect(e,t,n,r,o,s,a){let l=0;if(r<this.bmin[0]||e>this.bmax[0]||s<this.bmin[2]||n>this.bmax[2])return l;let c=this.cell(e,0),u=this.cell(r,0),d=this.cell(n,2),h=this.cell(s,2);for(let p=d;p<=h;p++)for(let m=c;m<=u;m++){let f=p*Jo+m;for(let y=this.gridStart[f];y<this.gridStart[f+1];y++){let b=this.gridPolys[y],A=b*6;if(this.bounds[A]>r||this.bounds[A+3]<e||this.bounds[A+2]>s||this.bounds[A+5]<n||this.bounds[A+1]>o||this.bounds[A+4]<t)continue;let E=Math.max(this.cell(this.bounds[A],0),c),R=Math.max(this.cell(this.bounds[A+2],2),d);E!==m||R!==p||l<a.length&&(a[l++]=b);}}return l}edge(e,t){let n=this.polyCount[e];return this.polyVerts[e*dn+(t+1===n?0:t+1)]}},Gv=class{constructor(e,t,n,r){this.lookup=new Map;this.linkTarget=[];this.linkEdge=[];this.linkMin=[];this.linkMax=[];if(!(n>0)||r<1||r>=Zs)throw new _("invalid_argument","navmesh bounds are invalid");this.originX=e,this.originZ=t,this.tileWorld=n,this.tiles=Array.from({length:r},()=>null),this.salts=new Uint32Array(r).fill(1),this.free=[];for(let o=r-1;o>=0;o--)this.free.push(o);}key(e,t){return (e+32768)*65536+(t+32768)}tileCoordinate(e,t){return Math.floor((e-t)/this.tileWorld)}slotAt(e,t){return this.lookup.get(this.key(e,t))??-1}tile(e){return e>=0&&e<this.tiles.length?this.tiles[e]:null}ref(e,t){return (this.salts[e]*Zs+e)*Qi+t}tileOf(e){if(e<0)return null;let t=e%Qi,n=(e-t)/Qi,r=n%Zs,o=(n-r)/Zs,s=this.tile(r);return !s||s.salt!==o||t>=s.polys?null:s}polyOf(e){return e%Qi}addTile(e){let t=new B3(e);if(this.lookup.has(this.key(t.x,t.z)))throw new _("invalid_argument","tile is already loaded");let n=this.free.pop();if(n===void 0)throw new _("capacity_exceeded","navmesh tile capacity reached");t.salt=this.salts[n],this.tiles[n]=t,this.lookup.set(this.key(t.x,t.z),n),this.connect(n);for(let r=0;r<4;r++){let o=this.slotAt(t.x+F3[r],t.z+U3[r]);o>=0&&this.connect(o);}return n}removeTile(e,t){let n=this.slotAt(e,t);if(n<0)throw new _("unknown_resource","tile is not loaded");this.lookup.delete(this.key(e,t)),this.tiles[n]=null,this.salts[n]=this.salts[n]+1&255||1,this.free.push(n);for(let r=0;r<4;r++){let o=this.slotAt(e+F3[r],t+U3[r]);o>=0&&this.connect(o);}}connect(e){let t=this.tiles[e],n=this.linkTarget,r=this.linkEdge,o=this.linkMin,s=this.linkMax;n.length=0,r.length=0,o.length=0,s.length=0,t.linkStart=new Uint32Array(t.polys+1);for(let a=0;a<t.polys;a++){t.linkStart[a]=n.length;let l=t.polyCount[a];for(let c=0;c<l;c++){let u=t.polyNeis[a*dn+c];if(u===0)continue;if((u&hre)===0){n.push(this.ref(e,u-1)),r.push(c),o.push(0),s.push(1);continue}let d=u&3,h=this.tile(this.slotAt(t.x+F3[d],t.z+U3[d]));if(!h)continue;let p=this.slotAt(h.x,h.z),m=t.polyVerts[a*dn+c],f=t.edge(a,c),y=d===0||d===2?2:0,b=d+2&3,A=t.verts[m*3+y],E=t.verts[f*3+y],R=Math.max(t.climb,h.climb);for(let g=0;g<h.polys;g++){let v=h.polyCount[g];for(let x=0;x<v;x++){if(h.polyNeis[g*dn+x]!==(hre|b))continue;let O=h.polyVerts[g*dn+x],N=h.edge(g,x),I=h.verts[O*3+y],S=h.verts[N*3+y],w=Math.max(Math.min(A,E),Math.min(I,S)),U=Math.min(Math.max(A,E),Math.max(I,S));if(U-w<=eWe||E===A||S===I)continue;let L=(w+U)*.5,k=(L-A)/(E-A),M=(L-I)/(S-I),K=t.verts[m*3+1]+(t.verts[f*3+1]-t.verts[m*3+1])*k,Y=h.verts[O*3+1]+(h.verts[N*3+1]-h.verts[O*3+1])*M;if(Math.abs(K-Y)>R)continue;let te=Math.min(Math.max((w-A)/(E-A),0),1),Z=Math.min(Math.max((U-A)/(E-A),0),1);n.push(this.ref(p,g)),r.push(c),o.push(Math.min(te,Z)),s.push(Math.max(te,Z));}}}}t.linkStart[t.polys]=n.length,t.linkTarget=Float64Array.from(n),t.linkEdge=Uint8Array.from(r),t.linkMin=Float64Array.from(o),t.linkMax=Float64Array.from(s);}};var mre=0,Hv=1,tWe=2,fre=.999,Nh=-1,G3=1,nWe=2,rWe=512,_re=16,Are=1/16384*(1/16384),iWe=.001*.001,kh=-1e-4,Lh=class{constructor(){this.costs=new Float64Array(64).fill(1);this.includeLow=4294967294;this.includeHigh=4294967295;}passes(e){return e<32?(this.includeLow>>>e&1)===1:(this.includeHigh>>>e-32&1)===1}},k_=class{constructor(e,t,n=null){this.generation=0;this.used=0;this.heapLen=0;this.candidates=new Uint16Array(rWe);this.surfacePoly=new Float64Array(_re);this.point=new Float64Array(3);this.inside=false;this.pathLength=0;this.complete=false;this.written=0;this.corners=new Float64Array(9);this.portalLeft=new Float64Array(3);this.portalRight=new Float64Array(3);this.flags=null;this.refs=null;this.lastBest=Nh;this.lastBestCost=0;this.mesh=e,this.links=n,this.capacity=t,this.nodePoly=new Float64Array(t),this.nodeParent=new Int32Array(t),this.nodeG=new Float64Array(t),this.nodeF=new Float64Array(t),this.nodePos=new Float64Array(t*3),this.nodeState=new Uint8Array(t),this.nodeHeap=new Int32Array(t);let r=1;for(;r<t*2;)r*=2;this.slots=new Int32Array(r),this.stamps=new Uint32Array(r),this.mask=r-1,this.heap=new Int32Array(t);}closestOnPoly(e,t,n,r,o){let s=e.polyCount[t],a=t*dn,l=e.verts,c=false;for(let d=0,h=s-1;d<s;h=d++){let p=e.polyVerts[a+d]*3,m=e.polyVerts[a+h]*3;l[p+2]>o!=l[m+2]>o&&n<(l[m]-l[p])*(o-l[p+2])/(l[m+2]-l[p+2])+l[p]&&(c=!c);}if(c&&e.detailTriCount[t]>0){let d=this.corners,h=e.detailTriBase[t]*Wc;for(let p=0;p<e.detailTriCount[t];p++){let m=h+p*Wc;e.detailCorner(t,e.detailTris[m],d,0),e.detailCorner(t,e.detailTris[m+1],d,3),e.detailCorner(t,e.detailTris[m+2],d,6);let f=oWe(d,n,o);if(f!==null){this.point[0]=n,this.point[1]=f,this.point[2]=o,this.inside=true;return}}}if(c){let d=e.polyVerts[a]*3;for(let h=1;h<s-1;h++){let p=e.polyVerts[a+h]*3,m=e.polyVerts[a+h+1]*3,f=l[m]-l[d],y=l[m+2]-l[d+2],b=l[p]-l[d],A=l[p+2]-l[d+2],E=n-l[d],R=o-l[d+2],g=f*A-y*b;if(Math.abs(g)<1e-12)continue;let v=(A*E-b*R)/g,x=(f*R-y*E)/g;if(v>=kh&&x>=kh&&v+x<=1-kh){this.point[0]=n,this.point[1]=l[d+1]+(l[m+1]-l[d+1])*v+(l[p+1]-l[d+1])*x,this.point[2]=o,this.inside=true;return}}}let u=1/0;for(let d=0;d<s;d++){let h=e.polyVerts[a+d]*3,p=e.edge(t,d)*3,m=this.segmentT(n,o,l[h],l[h+2],l[p],l[p+2]),f=l[h]+(l[p]-l[h])*m,y=l[h+2]+(l[p+2]-l[h+2])*m,b=(f-n)*(f-n)+(y-o)*(y-o);b<u&&(u=b,this.point[0]=f,this.point[1]=l[h+1]+(l[p+1]-l[h+1])*m,this.point[2]=y);}this.inside=false;}segmentT(e,t,n,r,o,s){let a=o-n,l=s-r,c=a*a+l*l,u=a*(e-n)+l*(t-r);return c>0&&(u/=c),u<0?0:u>1?1:u}nearest(e,t,n,r,o,s,a){let l=this.mesh,c=l.tileCoordinate(e-r,l.originX),u=l.tileCoordinate(e+r,l.originX),d=l.tileCoordinate(n-s,l.originZ),h=l.tileCoordinate(n+s,l.originZ),p=lt,m=1/0,f=0,y=0,b=0;for(let A=d;A<=h;A++)for(let E=c;E<=u;E++){let R=l.slotAt(E,A),g=l.tile(R);if(!g)continue;let v=g.collect(e-r,t-o,n-s,e+r,t+o,n+s,this.candidates);for(let x=0;x<v;x++){let O=this.candidates[x];if(!a.passes(g.polyArea[O]))continue;this.closestOnPoly(g,O,e,t,n);let N=this.point[1]-t,I=this.point[0]-e,S=this.point[2]-n,w=this.inside?N*N:I*I+N*N+S*S;w<m&&(m=w,p=l.ref(R,O),f=this.point[0],y=this.point[1],b=this.point[2]);}}return this.point[0]=f,this.point[1]=y,this.point[2]=b,p}nodeOf(e){let t=this.mask,n=e*2654435761>>>0&t;for(;this.stamps[n]===this.generation;){let o=this.slots[n];if(this.nodePoly[o]===e)return o;n=n+1&t;}if(this.used>=this.capacity)return Nh;let r=this.used++;return this.stamps[n]=this.generation,this.slots[n]=r,this.nodePoly[r]=e,this.nodeParent[r]=Nh,this.nodeG[r]=0,this.nodeF[r]=0,this.nodeState[r]=0,r}less(e,t){let n=this.nodeF[e],r=this.nodeF[t];if(n!==r)return n<r;let o=this.nodeG[e],s=this.nodeG[t];return o!==s?o<s:this.nodePoly[e]<this.nodePoly[t]}siftUp(e){let t=this.heap[e];for(;e>0;){let n=e-1>>1;if(!this.less(t,this.heap[n]))break;this.heap[e]=this.heap[n],this.nodeHeap[this.heap[e]]=e,e=n;}this.heap[e]=t,this.nodeHeap[t]=e;}siftDown(e){let t=this.heap[e];for(;;){let n=e*2+1;if(n>=this.heapLen)break;let r=n+1,o=r<this.heapLen&&this.less(this.heap[r],this.heap[n])?r:n;if(!this.less(this.heap[o],t))break;this.heap[e]=this.heap[o],this.nodeHeap[this.heap[e]]=e,e=o;}this.heap[e]=t,this.nodeHeap[t]=e;}distance(e,t,n,r){let o=this.nodePos,s=o[e*3]-t,a=o[e*3+1]-n,l=o[e*3+2]-r;return Math.sqrt(s*s+a*a+l*l)}findPath(e,t,n,r,o,s,a,l,c,u){let d=this.mesh;if(this.complete=false,!d.tileOf(e)||!d.tileOf(t)||u.length===0)return 0;if(e===t)return u[0]=e,this.complete=true,1;this.generation=this.generation+1>>>0,this.generation===0&&(this.stamps.fill(0),this.generation=1),this.used=0,this.heapLen=0;let h=this.nodeOf(e);this.nodePos[h*3]=n,this.nodePos[h*3+1]=r,this.nodePos[h*3+2]=o;let p=Math.sqrt((n-s)*(n-s)+(r-a)*(r-a)+(o-l)*(o-l))*fre;this.nodeF[h]=p,this.nodeState[h]=G3,this.heap[this.heapLen++]=h,this.nodeHeap[h]=0,this.lastBest=h,this.lastBestCost=p;let m=this.links;for(;this.heapLen>0;){let R=this.heap[0];this.heapLen--,this.heapLen>0&&(this.heap[0]=this.heap[this.heapLen],this.siftDown(0)),this.nodeState[R]=nWe;let g=this.nodePoly[R];if(g===t){this.lastBest=R;break}if(m&&m.isLink(g)){if(!m.view(g))continue;let U=m.to,L=d.tileOf(U);if(!L)continue;let k=L.polyArea[d.polyOf(U)];if(!c.passes(k))continue;let M=m.exit;this.relax(R,U,M[0],M[1],M[2],c.costs[m.area&63],k,t,s,a,l,c);continue}let v=d.tileOf(g);if(!v)continue;let x=d.polyOf(g),O=this.nodeParent[R],N=O===Nh?lt:this.nodePoly[O],I=c.costs[v.polyArea[x]&63];for(let U=v.linkStart[x];U<v.linkStart[x+1];U++){let L=v.linkTarget[U];if(L===N)continue;let k=d.tileOf(L);if(!k)continue;let M=k.polyArea[d.polyOf(L)];if(!c.passes(M))continue;let K=v.linkEdge[U],Y=v.polyVerts[x*dn+K]*3,te=v.edge(x,K)*3,Z=v.verts,de=(v.linkMin[U]+v.linkMax[U])*.5;this.relax(R,L,Z[Y]+(Z[te]-Z[Y])*de,Z[Y+1]+(Z[te+1]-Z[Y+1])*de,Z[Y+2]+(Z[te+2]-Z[Y+2])*de,I,M,t,s,a,l,c);}if(!m)continue;let S=m.fromStart(g),w=m.fromEnd(g,S);for(let U=S;U<w;U++){let L=m.fromLink[U];if(L===N||!m.view(L)||!c.passes(m.area))continue;let k=m.entry;this.relax(R,L,k[0],k[1],k[2],I,m.area,t,s,a,l,c);}}let f=this.lastBest,y=0;for(let R=f;R!==Nh;R=this.nodeParent[R])y++;let b=Math.max(y-u.length,0),A=f;for(let R=0;R<b;R++)A=this.nodeParent[A];let E=y-b;for(let R=E-1;R>=0;R--)u[R]=this.nodePoly[A],A=this.nodeParent[A];return this.complete=this.nodePoly[f]===t&&b===0,this.pathLength=E,E}relax(e,t,n,r,o,s,a,l,c,u,d,h){let p=this.used,m=this.nodeOf(t);if(m===Nh)return;m===p&&(this.nodePos[m*3]=n,this.nodePos[m*3+1]=r,this.nodePos[m*3+2]=o);let f=this.nodeG[e]+this.distance(m,this.nodePos[e*3],this.nodePos[e*3+1],this.nodePos[e*3+2])*s,y,b;t===l?(y=f+this.distance(m,c,u,d)*h.costs[a&63],b=0):(y=f,b=this.distance(m,c,u,d)*fre);let A=y+b,E=this.nodeState[m];E!==0&&A>=this.nodeF[m]||(this.nodeParent[m]=e,this.nodeG[m]=y,this.nodeF[m]=A,E===G3?this.siftUp(this.nodeHeap[m]):(this.nodeState[m]=G3,this.heap[this.heapLen]=m,this.siftUp(this.heapLen++)),b<this.lastBestCost&&(this.lastBestCost=b,this.lastBest=m));}portal(e,t){let n=this.mesh,r=n.tileOf(e);if(!r)return false;let o=n.polyOf(e);for(let s=r.linkStart[o];s<r.linkStart[o+1];s++){if(r.linkTarget[s]!==t)continue;let a=r.linkEdge[s],l=r.polyVerts[o*dn+a]*3,c=r.edge(o,a)*3,u=r.verts,d=r.linkMin[s],h=r.linkMax[s];for(let p=0;p<3;p++)this.portalLeft[p]=u[l+p]+(u[c+p]-u[l+p])*d,this.portalRight[p]=u[l+p]+(u[c+p]-u[l+p])*h;return true}return false}straightPath(e,t,n,r,o,s,a,l,c){return this.straightPathDetailed(e,t,n,r,o,s,a,0,l,c,null,null)}clampTo(e,t,n,r){let o=this.mesh.tileOf(e);o?this.closestOnPoly(o,this.mesh.polyOf(e),t,n,r):(this.point[0]=t,this.point[1]=n,this.point[2]=r);}straightPathDetailed(e,t,n,r,o,s,a,l,c,u,d,h){let p=Math.floor(u.length/3);if(this.written=0,c<=l||p===0)return 0;this.flags=d,this.refs=h;let m=this.links;this.clampTo(a[l],e,t,n);let f=this.point[0],y=this.point[1],b=this.point[2],A=l;for(;A<c;){let E=A;for(;E<c&&!(m&&m.isLink(a[E]));)E++;if(E===A){A++;continue}let R=E<c&&m!==null&&m.view(a[E]);R?this.clampTo(a[E-1],m.entry[0],m.entry[1],m.entry[2]):this.clampTo(a[E-1],r,o,s);let g=this.point[0],v=this.point[1],x=this.point[2],O=R?m.exit[0]:0,N=R?m.exit[1]:0,I=R?m.exit[2]:0;if(!this.funnel(f,y,b,g,v,x,a,A,E,u,p))return this.written;if(!R)break;let S=a[E];if(!this.push(u,p,g,v,x,Hv,S)||!this.push(u,p,O,N,I,tWe,S))return this.written;f=O,y=N,b=I,A=E+1;}return this.written}funnel(e,t,n,r,o,s,a,l,c,u,d){let h=this.mesh;if(!this.push(u,d,e,t,n))return false;if(c-l>1){let p=e,m=t,f=n,y=e,b=t,A=n,E=e,R=t,g=n,v=l,x=l,O=l;for(;O<c;){let N,I,S,w,U,L;if(O+1<c){if(!this.portal(a[O],a[O+1])){let k=h.tileOf(a[O]);k&&(this.closestOnPoly(k,h.polyOf(a[O]),r,o,s),r=this.point[0],o=this.point[1],s=this.point[2]);break}if(N=this.portalLeft[0],I=this.portalLeft[1],S=this.portalLeft[2],w=this.portalRight[0],U=this.portalRight[1],L=this.portalRight[2],O===l){let k=this.segmentT(p,f,N,S,w,L),M=N+(w-N)*k-p,K=S+(L-S)*k-f;if(M*M+K*K<iWe){O++;continue}}}else N=w=r,I=U=o,S=L=s;if(Vv(p,f,E,g,w,L)<=0)if(yre(p,m,f,E,R,g)||Vv(p,f,y,A,w,L)>0)E=w,R=U,g=L,x=O;else {p=y,m=b,f=A;let k=v;if(!this.push(u,d,p,m,f))return false;E=y=p,R=b=m,g=A=f,v=x=k,O=k+1;continue}if(Vv(p,f,y,A,N,S)>=0)if(yre(p,m,f,y,b,A)||Vv(p,f,E,g,N,S)<0)y=N,b=I,A=S,v=O;else {p=E,m=R,f=g;let k=x;if(!this.push(u,d,p,m,f))return false;E=y=p,R=b=m,g=A=f,v=x=k,O=k+1;continue}O++;}}return this.push(u,d,r,o,s)}push(e,t,n,r,o,s=mre,a=lt){let l=this.written;if(l>0){let c=(l-1)*3,u=e[c]-n,d=e[c+1]-r,h=e[c+2]-o;if(u*u+d*d+h*h<Are)return s!==mre&&this.mark(l-1,s,a),l<t}return l<t&&(e[l*3]=n,e[l*3+1]=r,e[l*3+2]=o,this.mark(l,s,a),this.written=l+1),this.written<t}mark(e,t,n){this.flags&&e<this.flags.length&&(this.flags[e]=t),this.refs&&e<this.refs.length&&(this.refs[e]=n);}moveAlongSurface(e,t,n,r,o,s,a,l){let c=this.mesh;if(!c.tileOf(e))return lt;let u=Math.sqrt((o-t)**2+(s-n)**2+(a-r)**2)*.5+.001,d=u*u,h=(t+o)*.5,p=(r+a)*.5;this.surfacePoly[0]=e;let m=0,f=1,y=t,b=n,A=r,E=1/0,R=e;for(;m<f;){let g=this.surfacePoly[m++],v=c.tileOf(g);if(!v)continue;let x=c.polyOf(g),O=v.polyCount[x],N=x*dn,I=v.verts,S=false;for(let w=0,U=O-1;w<O;U=w++){let L=v.polyVerts[N+w]*3,k=v.polyVerts[N+U]*3;I[L+2]>a!=I[k+2]>a&&o<(I[k]-I[L])*(a-I[L+2])/(I[k+2]-I[L+2])+I[L]&&(S=!S);}if(S)return this.point[0]=o,this.point[1]=s,this.point[2]=a,g;for(let w=0;w<O;w++){let U=v.polyVerts[N+w]*3,L=v.edge(x,w)*3,k=false;for(let M=v.linkStart[x];M<v.linkStart[x+1];M++){if(v.linkEdge[M]!==w)continue;let K=v.linkTarget[M],Y=c.tileOf(K);if(!Y||!l.passes(Y.polyArea[c.polyOf(K)]))continue;k=true;let te=false;for(let be=0;be<f;be++)this.surfacePoly[be]===K&&(te=true);if(te||f>=_re)continue;let Z=this.segmentT(h,p,I[U],I[U+2],I[L],I[L+2]),de=I[U]+(I[L]-I[U])*Z-h,Oe=I[U+2]+(I[L+2]-I[U+2])*Z-p;de*de+Oe*Oe>d||(this.surfacePoly[f++]=K);}if(!k){let M=this.segmentT(o,a,I[U],I[U+2],I[L],I[L+2]),K=I[U]+(I[L]-I[U])*M,Y=I[U+2]+(I[L+2]-I[U+2])*M,te=(K-o)**2+(Y-a)**2;te<E&&(E=te,y=K,b=I[U+1]+(I[L+1]-I[U+1])*M,A=Y,R=g);}}}return this.point[0]=y,this.point[1]=b,this.point[2]=A,R}};function oWe(i,e,t){let n=i[6]-i[0],r=i[8]-i[2],o=i[3]-i[0],s=i[5]-i[2],a=e-i[0],l=t-i[2],c=n*s-r*o;if(Math.abs(c)<1e-12)return null;let u=(s*a-o*l)/c,d=(n*l-r*a)/c;return u<kh||d<kh||u+d>1-kh?null:i[1]+(i[7]-i[1])*u+(i[4]-i[1])*d}function Vv(i,e,t,n,r,o){return (r-i)*(n-e)-(t-i)*(o-e)}function yre(i,e,t,n,r,o){return (i-n)**2+(e-r)**2+(t-o)**2<Are}var cWe=.01,gr=8,gre=1e-5,Ere=1e-6,xre=.25,vre=.2,uWe=2,D_=4096,$i=-1,Rre=-1918454973,Sre=-887442657,Kv=class{constructor(e,t,n,r,o=null){this.searches=0;this.count=0;this.requestHead=0;this.requestLen=0;this.cellStart=new Int32Array(D_+1);this.cellCursor=new Int32Array(D_+1);this.best=new Float64Array(gr);this.bestIndex=new Int32Array(gr);this.lpx=new Float64Array(gr);this.lpz=new Float64Array(gr);this.ldx=new Float64Array(gr);this.ldz=new Float64Array(gr);this.qpx=new Float64Array(gr);this.qpz=new Float64Array(gr);this.qdx=new Float64Array(gr);this.qdz=new Float64Array(gr);this.rx=0;this.rz=0;this.mesh=e,this.query=t,this.filter=n,this.settings=r,this.links=o;let s=r.maxAgents,a=r.maxPathPolys;this.cap=a,this.cornerFlags=new Uint8Array(s*Ut),this.cornerRefs=new Float64Array(s*Ut).fill(lt),this.corridor=new Float64Array(s*a).fill(lt),this.corridorLen=new Uint32Array(s),this.corridorAt=new Uint32Array(s),this.resume=new Uint8Array(s),this.endPoint=new Float64Array(s*3),this.linkRef=new Float64Array(s).fill(lt),this.linkFrom=new Float64Array(s*3),this.linkTo=new Float64Array(s*3),this.linkT=new Float64Array(s),this.afterLink=new Uint8Array(s),this.out=new Float32Array(s*8),this.px=new Float64Array(s),this.py=new Float64Array(s),this.pz=new Float64Array(s),this.vx=new Float64Array(s),this.vz=new Float64Array(s),this.nx=new Float64Array(s),this.nz=new Float64Array(s),this.prefX=new Float64Array(s),this.prefZ=new Float64Array(s),this.radius=new Float64Array(s),this.speed=new Float64Array(s),this.accel=new Float64Array(s),this.poly=new Float64Array(s).fill(lt),this.state=new Uint8Array(s),this.target=new Float64Array(s*3),this.corners=new Float32Array(s*Ut*3),this.cornerCount=new Uint8Array(s),this.cornerAt=new Uint8Array(s),this.ids=new Int32Array(s).fill($i),this.indexOf=new Int32Array(s).fill($i),this.free=new Int32Array(s);for(let l=0;l<s;l++)this.free[l]=s-1-l;this.freeCount=s,this.requests=new Int32Array(s*2),this.cornerViews=[],this.flagViews=[],this.refViews=[],this.corridorViews=[];for(let l=0;l<s;l++)this.cornerViews.push(this.corners.subarray(l*Ut*3,(l+1)*Ut*3)),this.flagViews.push(this.cornerFlags.subarray(l*Ut,(l+1)*Ut)),this.refViews.push(this.cornerRefs.subarray(l*Ut,(l+1)*Ut)),this.corridorViews.push(this.corridor.subarray(l*a,(l+1)*a));this.cellOf=new Int32Array(s),this.cellItems=new Int32Array(s);}get size(){return this.count}add(e,t,n,r,o,s){if(!(r>=0)||!(o>=0)||!(s>0))throw new _("invalid_argument","agent parameters are invalid");let a=this.settings.extents,l=this.query.nearest(e,t,n,a[0],a[1],a[2],this.filter);if(l===lt)throw new _("invalid_argument","agent is not on the navmesh");if(this.freeCount===0)throw new _("capacity_exceeded","agent capacity reached");let c=this.free[--this.freeCount],u=this.count++;return this.ids[u]=c,this.indexOf[c]=u,this.px[u]=this.query.point[0],this.py[u]=this.query.point[1],this.pz[u]=this.query.point[2],this.vx[u]=this.vz[u]=this.prefX[u]=this.prefZ[u]=0,this.radius[u]=r,this.speed[u]=o,this.accel[u]=s,this.poly[u]=l,this.state[u]=0,this.cornerCount[u]=this.cornerAt[u]=0,this.corridorLen[u]=this.corridorAt[u]=0,this.resume[u]=0,this.linkRef[u]=lt,this.writeOut(u),c}remove(e){let t=this.indexOf[e]??$i;if(t===$i)throw new _("unknown_resource",`agent ${e} does not exist`);let n=--this.count;if(t!==n){let r=[this.px,this.py,this.pz,this.vx,this.vz,this.prefX,this.prefZ,this.radius,this.speed,this.accel,this.poly,this.linkRef,this.linkT];for(let a of r)a[t]=a[n];let o=[this.state,this.cornerCount,this.cornerAt,this.resume,this.afterLink];for(let a of o)a[t]=a[n];this.corridorLen[t]=this.corridorLen[n],this.corridorAt[t]=this.corridorAt[n];for(let a of [this.target,this.endPoint,this.linkFrom,this.linkTo])a.copyWithin(t*3,n*3,n*3+3);this.corners.copyWithin(t*Ut*3,n*Ut*3,(n+1)*Ut*3),this.cornerFlags.copyWithin(t*Ut,n*Ut,(n+1)*Ut),this.cornerRefs.copyWithin(t*Ut,n*Ut,(n+1)*Ut),this.corridor.copyWithin(t*this.cap,n*this.cap,n*this.cap+this.corridorLen[n]);let s=this.ids[n];this.ids[t]=s,this.indexOf[s]=t;}this.ids[n]=$i,this.indexOf[e]=$i,this.free[this.freeCount++]=e;}setTarget(e,t,n,r){let o=this.indexOf[e]??$i;if(o===$i)throw new _("unknown_resource",`agent ${e} does not exist`);this.target[o*3]=t,this.target[o*3+1]=n,this.target[o*3+2]=r,this.state[o]===5?this.afterLink[o]=1:this.request(o);}stop(e){let t=this.indexOf[e]??$i;if(t===$i)throw new _("unknown_resource",`agent ${e} does not exist`);this.state[t]===5?this.afterLink[t]=0:this.state[t]=0;}request(e){this.state[e]!==1&&(this.state[e]=1,this.requestLen!==this.requests.length&&(this.requests[(this.requestHead+this.requestLen)%this.requests.length]=this.ids[e],this.requestLen++));}plan(e){let t=this.settings.extents,n=this.query.nearest(this.target[e*3],this.target[e*3+1],this.target[e*3+2],t[0],t[1],t[2],this.filter);if(n===lt)return this.state[e]=4,false;let r=this.query.point[0],o=this.query.point[1],s=this.query.point[2];if(this.endPoint[e*3]=r,this.endPoint[e*3+1]=o,this.endPoint[e*3+2]=s,this.retarget(e,n)&&this.refresh(e))return this.resume[e]=0,this.state[e]=2,false;let a=this.poly[e];if(!this.mesh.tileOf(a)){if(a=this.query.nearest(this.px[e],this.py[e],this.pz[e],t[0],t[1],t[2],this.filter),a===lt)return this.state[e]=4,false;this.poly[e]=a;}this.searches++;let l=this.query.findPath(a,n,this.px[e],this.py[e],this.pz[e],r,o,s,this.filter,this.corridorViews[e]);return l===0?(this.state[e]=4,true):(this.corridorLen[e]=l,this.corridorAt[e]=0,this.resume[e]=!this.query.complete&&l===this.cap?1:0,this.state[e]=this.refresh(e)?2:4,true)}retarget(e,t){let n=this.corridorAt[e],r=this.corridorLen[e],o=e*this.cap;if(n>=r||this.corridor[o+n]!==this.poly[e]||!this.mesh.tileOf(this.poly[e]))return false;for(let s=n;s<r;s++)if(this.corridor[o+s]===t)return this.corridorLen[e]=s+1,true;return this.resume[e]===1||r===this.cap||!this.query.portal(this.corridor[o+r-1],t)?false:(this.corridor[o+r]=t,this.corridorLen[e]=r+1,true)}refresh(e){let t=e*this.cap,n=this.corridorAt[e],r=this.corridorLen[e];if(n>=r)return false;let o=this.links;for(let a=t+n;a<t+r;a++){let l=this.corridor[a];if(!(o&&o.isLink(l)?o.view(l):this.mesh.tileOf(l)!==null))return false}let s=this.query.straightPathDetailed(this.px[e],this.py[e],this.pz[e],this.endPoint[e*3],this.endPoint[e*3+1],this.endPoint[e*3+2],this.corridor,t+n,t+r,this.cornerViews[e],this.flagViews[e],this.refViews[e]);return this.cornerCount[e]=s,this.cornerAt[e]=s>1&&this.cornerFlags[e*Ut]!==Hv?1:0,true}track(e){let t=e*this.cap,n=this.corridorAt[e],r=this.corridorLen[e],o=this.poly[e];if(n<r&&this.corridor[t+n]===o)return;let s=Math.min(n,r),a=-1;for(let c=s;c<r&&a<0;c++)this.corridor[t+c]===o&&(a=c);for(let c=s-1;c>=0&&a<0;c--)this.corridor[t+c]===o&&(a=c);let l;if(a>=0)this.corridorAt[e]=a,l=a===n+1||this.refresh(e);else if(n<r&&this.query.portal(o,this.corridor[t+n])){if(n>0)this.corridor[t+n-1]=o,this.corridorAt[e]=n-1;else if(r<this.cap)this.corridor.copyWithin(t+1,t,t+r),this.corridor[t]=o,this.corridorLen[e]=r+1;else {this.request(e);return}l=this.refresh(e);}else l=false;l||this.request(e);}beginLink(e){let t=this.cornerRefs[e*Ut+this.cornerAt[e]],n=this.links;if(!n||!n.view(t)){this.request(e);return}this.linkRef[e]=t,this.linkFrom[e*3]=this.px[e],this.linkFrom[e*3+1]=this.py[e],this.linkFrom[e*3+2]=this.pz[e];for(let r=0;r<3;r++)this.linkTo[e*3+r]=n.exit[r];this.linkT[e]=0,this.afterLink[e]=2,this.state[e]=5;}traverse(e,t){let n=this.linkTo[e*3]-this.linkFrom[e*3],r=this.linkTo[e*3+1]-this.linkFrom[e*3+1],o=this.linkTo[e*3+2]-this.linkFrom[e*3+2],s=Math.max(Math.sqrt(n*n+r*r+o*o),cWe),a=Math.min(this.linkT[e]+this.speed[e]*t/s,1);this.linkT[e]=a,this.px[e]=this.linkFrom[e*3]+n*a,this.py[e]=this.linkFrom[e*3+1]+r*a,this.pz[e]=this.linkFrom[e*3+2]+o*a;let l=this.speed[e]/s;this.vx[e]=n*l,this.vz[e]=o*l,a>=1&&this.land(e);}land(e){let t=this.linkRef[e];this.linkRef[e]=lt;let n=this.links,r=n&&n.view(t)&&this.mesh.tileOf(n.to)?n.to:lt;if(r===lt){let u=this.settings.extents;r=this.query.nearest(this.linkTo[e*3],this.linkTo[e*3+1],this.linkTo[e*3+2],u[0],u[1],u[2],this.filter);}if(r===lt){this.state[e]=4;return}this.poly[e]=r;let o=this.mesh.tileOf(r);o&&(this.query.closestOnPoly(o,this.mesh.polyOf(r),this.px[e],this.py[e],this.pz[e]),this.py[e]=this.query.point[1]);let s=this.afterLink[e];if(this.state[e]=2,s===0){this.state[e]=0;return}if(s!==2){this.request(e);return}let a=e*this.cap,l=this.corridorLen[e],c=-1;for(let u=this.corridorAt[e];u+1<l&&c<0;u++)this.corridor[a+u]===t&&this.corridor[a+u+1]===r&&(c=u+1);if(c<0){this.request(e);return}this.corridorAt[e]=c,this.refresh(e)||this.request(e);}drive(e,t,n,r,o){let s=this.speed[e]*o/r;this.prefX[e]=t*s,this.prefZ[e]=n*s;}steer(e){if(this.prefX[e]=0,this.prefZ[e]=0,this.state[e]!==2)return;let t=e*Ut*3,n=false;for(;;){let r=this.cornerCount[e],o=this.cornerAt[e];if(o>=r){this.state[e]=3;return}let s=this.corners[t+o*3],a=this.corners[t+o*3+2],l=s-this.px[e],c=a-this.pz[e],u=Math.sqrt(l*l+c*c);if(this.cornerFlags[e*Ut+o]===Hv){u<=xre+this.radius[e]?this.beginLink(e):this.drive(e,l,c,u,1);return}if(o+1===r){let h=r===Ut;if(u<=vre){if(h&&!n){if(n=true,this.refresh(e))continue;this.request(e);}else h||this.resume[e]===1?this.request(e):this.state[e]=3;return}let p=this.radius[e]*uWe+vre,m=u<p&&!h&&this.resume[e]===0?u/p:1;this.drive(e,l,c,u,m);return}let d=o>0&&(s-this.corners[t+(o-1)*3])*-l+(a-this.corners[t+(o-1)*3+2])*-c>0;if(u<=xre||d){this.cornerAt[e]++;continue}this.drive(e,l,c,u,1);return}}cellHash(e,t){let n=1/this.settings.neighbourDistance,r=Math.floor(e*n),o=Math.floor(t*n);return (Math.imul(r,Rre)^Math.imul(o,Sre))&D_-1}grid(){let e=this.count;this.cellStart.fill(0);for(let t=0;t<e;t++){let n=this.cellHash(this.px[t],this.pz[t]);this.cellOf[t]=n,this.cellStart[n+1]++;}for(let t=1;t<=D_;t++)this.cellStart[t]+=this.cellStart[t-1];this.cellCursor.set(this.cellStart);for(let t=0;t<e;t++)this.cellItems[this.cellCursor[this.cellOf[t]]++]=t;}neighbours(e){let t=this.settings.neighbourDistance,n=t*t,r=0,o=this.px[e],s=this.pz[e],a=1/t,l=Math.floor(o*a),c=Math.floor(s*a);for(let u=c-1;u<=c+1;u++)for(let d=l-1;d<=l+1;d++){let h=(Math.imul(d,Rre)^Math.imul(u,Sre))&D_-1;for(let p=this.cellStart[h];p<this.cellStart[h+1];p++){let m=this.cellItems[p];if(m===e||Math.floor(this.px[m]*a)!==d||Math.floor(this.pz[m]*a)!==u)continue;let f=this.px[m]-o,y=this.pz[m]-s,b=f*f+y*y;if(b>n||r===gr&&(b>this.best[r-1]||b===this.best[r-1]&&m>this.bestIndex[r-1]))continue;let A=r<gr?r:gr-1;for(;A>0&&(b<this.best[A-1]||b===this.best[A-1]&&m<this.bestIndex[A-1]);)this.best[A]=this.best[A-1],this.bestIndex[A]=this.bestIndex[A-1],A--;this.best[A]=b,this.bestIndex[A]=m,r<gr&&r++;}}return r}lines(e,t,n,r){let o=this.vx[e],s=this.vz[e];for(let a=0;a<t;a++){let l=this.bestIndex[a],c=this.px[l]-this.px[e],u=this.pz[l]-this.pz[e],d=o-this.vx[l],h=s-this.vz[l],p=c*c+u*u,m=this.radius[e]+this.radius[l],f=m*m,y,b,A,E;if(p>f){let R=d-n*c,g=h-n*u,v=R*R+g*g,x=R*c+g*u;if(x<0&&x*x>f*v){let O=Math.max(Math.sqrt(v),Ere),N=R/O,I=g/O;y=I,b=-N;let S=m*n-O;A=S*N,E=S*I;}else {let O=Math.sqrt(Math.max(p-f,0));c*g-u*R>0?(y=(c*O-u*m)/p,b=(c*m+u*O)/p):(y=-(c*O+u*m)/p,b=-(u*O-c*m)/p);let N=d*y+h*b;A=N*y-d,E=N*b-h;}}else {let R=d-r*c,g=h-r*u,v=Math.max(Math.sqrt(R*R+g*g),Ere),x=R/v,O=g/v;y=O,b=-x;let N=m*r-v;A=N*x,E=N*O;}this.lpx[a]=o+.5*A,this.lpz[a]=s+.5*E,this.ldx[a]=y,this.ldz[a]=b;}}program1(e,t,n,r,o,s,a,l,c){let u=e[o]*n[o]+t[o]*r[o],d=u*u+s*s-(e[o]*e[o]+t[o]*t[o]);if(d<0)return false;let h=Math.sqrt(d),p=-u-h,m=-u+h;for(let y=0;y<o;y++){let b=n[o]*r[y]-r[o]*n[y],A=n[y]*(t[o]-t[y])-r[y]*(e[o]-e[y]);if(Math.abs(b)<=gre){if(A<0)return false;continue}let E=A/b;if(b>=0?m=Math.min(m,E):p=Math.max(p,E),p>m)return false}let f;return c?f=a*n[o]+l*r[o]>0?m:p:(f=n[o]*(a-e[o])+r[o]*(l-t[o]),f<p?f=p:f>m&&(f=m)),this.rx=e[o]+f*n[o],this.rz=t[o]+f*r[o],true}program2(e,t,n,r,o,s,a,l,c){let u=a*a+l*l;if(c)this.rx=a*s,this.rz=l*s;else if(u>s*s){let d=Math.sqrt(u);this.rx=a/d*s,this.rz=l/d*s;}else this.rx=a,this.rz=l;for(let d=0;d<o;d++)if(n[d]*(t[d]-this.rz)-r[d]*(e[d]-this.rx)>0){let h=this.rx,p=this.rz;if(!this.program1(e,t,n,r,d,s,a,l,c))return this.rx=h,this.rz=p,d}return o}program3(e,t,n){let r=0;for(let o=t;o<e;o++){if(this.ldx[o]*(this.lpz[o]-this.rz)-this.ldz[o]*(this.lpx[o]-this.rx)<=r)continue;let s=0;for(let c=0;c<o;c++){let u=this.ldx[o]*this.ldz[c]-this.ldz[o]*this.ldx[c],d,h;if(Math.abs(u)<=gre){if(this.ldx[o]*this.ldx[c]+this.ldz[o]*this.ldz[c]>0)continue;d=.5*(this.lpx[o]+this.lpx[c]),h=.5*(this.lpz[o]+this.lpz[c]);}else {let y=(this.ldx[c]*(this.lpz[o]-this.lpz[c])-this.ldz[c]*(this.lpx[o]-this.lpx[c]))/u;d=this.lpx[o]+y*this.ldx[o],h=this.lpz[o]+y*this.ldz[o];}let p=this.ldx[c]-this.ldx[o],m=this.ldz[c]-this.ldz[o],f=Math.sqrt(p*p+m*m);this.qpx[s]=d,this.qpz[s]=h,this.qdx[s]=p/f,this.qdz[s]=m/f,s++;}let a=this.rx,l=this.rz;this.program2(this.qpx,this.qpz,this.qdx,this.qdz,s,n,-this.ldz[o],this.ldx[o],true)<s&&(this.rx=a,this.rz=l),r=this.ldx[o]*(this.lpz[o]-this.rz)-this.ldz[o]*(this.lpx[o]-this.rx);}}writeOut(e){let t=this.ids[e]*8,n=this.out;n[t+0]=this.px[e],n[t+1]=this.py[e],n[t+2]=this.pz[e],n[t+3]=this.vx[e],n[t+4]=this.vz[e],n[t+5]=this.state[e];let r=this.state[e]===5&&this.links!==null&&this.links.view(this.linkRef[e]);n[t+6]=r&&this.links?this.links.id:-1,n[t+7]=r?this.linkT[e]:0;}update(e){let t=this.settings.pathBudget;for(;t>0&&this.requestLen>0;){let s=this.requests[this.requestHead];this.requestHead=(this.requestHead+1)%this.requests.length,this.requestLen--;let a=this.indexOf[s];a!==$i&&this.state[a]===1&&this.plan(a)&&t--;}let n=this.count;for(let s=0;s<n;s++)this.steer(s);this.grid();let r=1/this.settings.timeHorizon,o=1/e;for(let s=0;s<n;s++){let a=this.neighbours(s);this.lines(s,a,r,o);let l=this.program2(this.lpx,this.lpz,this.ldx,this.ldz,a,this.speed[s],this.prefX[s],this.prefZ[s],false);l<a&&this.program3(a,l,this.speed[s]);let c=this.rx*this.rx+this.rz*this.rz,u=this.speed[s],d=c>u*u?u/Math.sqrt(c):1;this.nx[s]=this.rx*d,this.nz[s]=this.rz*d;}for(let s=0;s<n;s++){let a=this.nx[s]-this.vx[s],l=this.nz[s]-this.vz[s],c=Math.sqrt(a*a+l*l),u=this.accel[s]*e;c>u?(this.vx[s]+=a*u/c,this.vz[s]+=l*u/c):(this.vx[s]=this.nx[s],this.vz[s]=this.nz[s]);}for(let s=0;s<n;s++){if(this.state[s]===5){this.traverse(s,e),this.writeOut(s);continue}let a=this.px[s],l=this.pz[s],c=a+this.vx[s]*e,u=l+this.vz[s]*e,d=this.poly[s];if(this.mesh.tileOf(d))d=this.query.moveAlongSurface(d,a,this.py[s],l,c,this.py[s],u,this.filter);else {let f=this.settings.extents;d=this.query.nearest(c,this.py[s],u,f[0],f[1],f[2],this.filter);}if(d===lt){this.state[s]=4,this.writeOut(s);continue}let h=this.query.point[0],p=this.query.point[2];this.poly[s]=d,this.px[s]=h,this.pz[s]=p;let m=this.mesh.tileOf(d);m&&(this.query.closestOnPoly(m,this.mesh.polyOf(d),h,this.py[s],p),this.py[s]=this.query.point[1]),this.state[s]===2&&this.track(s),this.writeOut(s);}}};var Tre=Zs-1,Yv=Qi>>1,dWe=256,hWe=.5,wre=2,pWe=255,Xr=7,Xv=class{constructor(e=dWe){this.fromCount=0;this.all=new Lh;this.entry=new Float64Array(3);this.exit=new Float64Array(3);this.from=lt;this.to=lt;this.area=0;this.user=0;this.id=0;if(e<1||e>Yv)throw new _("invalid_argument","link capacity is out of range");this.desc=new Float64Array(e*Xr),this.bidirectional=new Uint8Array(e),this.areas=new Uint8Array(e),this.users=new Uint32Array(e),this.live=new Uint8Array(e),this.salts=new Uint32Array(e),this.startPoly=new Float64Array(e).fill(lt),this.endPoly=new Float64Array(e).fill(lt),this.fromPoly=new Float64Array(e*2),this.fromLink=new Float64Array(e*2);}add(e,t,n,r,o,s,a){for(let u=0;u<3;u++)if(!Number.isFinite(e[u])||!Number.isFinite(t[u]))throw new _("invalid_argument","link endpoints must be finite");if(!(n>=0)||!(o>=0&&o<64))throw new _("invalid_argument","link radius or area is out of range");let l=this.live.indexOf(0);if(l<0)throw new _("capacity_exceeded","link capacity reached");let c=this.desc;for(let u=0;u<3;u++)c[l*Xr+u]=e[u],c[l*Xr+3+u]=t[u];return c[l*Xr+6]=n,this.bidirectional[l]=r?1:0,this.areas[l]=o,this.users[l]=s>>>0,this.live[l]=1,this.salts[l]=this.salts[l]%pWe+1,this.resolve(a),l}remove(e,t){if(!(e>=0&&e<this.live.length)||this.live[e]===0)throw new _("unknown_resource",`link ${e} does not exist`);this.live[e]=0,this.resolve(t);}isLink(e){return e>=0&&Math.floor(e/Qi)%Zs===Tre}ref(e,t){return (this.salts[e]*Zs+Tre)*Qi+e+(t?Yv:0)}view(e){if(!this.isLink(e))return false;let t=e%Qi,n=Math.floor(e/(Qi*Zs)),r=t>=Yv,o=r?t-Yv:t;if(o>=this.live.length||this.live[o]===0||this.salts[o]!==n)return false;let s=this.desc,a=r?3:0,l=r?0:3;for(let c=0;c<3;c++)this.entry[c]=s[o*Xr+a+c],this.exit[c]=s[o*Xr+l+c];return this.from=r?this.endPoly[o]:this.startPoly[o],this.to=r?this.startPoly[o]:this.endPoly[o],this.area=this.areas[o],this.user=this.users[o],this.id=o,true}fromStart(e){let t=0,n=this.fromCount;for(;t<n;){let r=t+n>>1;this.fromPoly[r]<e?t=r+1:n=r;}return t}fromEnd(e,t){let n=t;for(;n<this.fromCount&&this.fromPoly[n]===e;)n++;return n}resolve(e){let t=this.desc;for(let r=0;r<this.live.length;r++){if(this.live[r]===0)continue;let o=Math.max(t[r*Xr+6],hWe);this.startPoly[r]=e.nearest(t[r*Xr],t[r*Xr+1],t[r*Xr+2],o,wre,o,this.all),this.endPoly[r]=e.nearest(t[r*Xr+3],t[r*Xr+4],t[r*Xr+5],o,wre,o,this.all);}let n=0;for(let r=0;r<this.live.length;r++)this.live[r]===0||this.startPoly[r]===lt||this.endPoly[r]===lt||(this.insert(n++,this.startPoly[r],this.ref(r,false)),this.bidirectional[r]===1&&this.insert(n++,this.endPoly[r],this.ref(r,true)));this.fromCount=n;}insert(e,t,n){let r=e;for(;r>0&&(this.fromPoly[r-1]>t||this.fromPoly[r-1]===t&&this.fromLink[r-1]>n);)this.fromPoly[r]=this.fromPoly[r-1],this.fromLink[r]=this.fromLink[r-1],r--;this.fromPoly[r]=t,this.fromLink[r]=n;}};var EWe=1e4,H3=1,xWe=3.5,vWe=60,RWe=.5,SWe=.01,Dh=-1,Ore=new Float32Array(1),wWe=new Uint32Array(Ore.buffer);function P_(i){return wWe[0]=i,Ore[0]}var zv=class{constructor(e){let[t,n,r,o,s,a,l]=e,c=7+t*3+n*10+r+o+s*19;if(e.length!==c)throw new _("invalid_argument","road graph has the wrong size");let u=7;this.points=new Float64Array(t*3);for(let h=0;h<t*3;h++)this.points[h]=P_(e[u++]);this.lanes=n,this.laneFirst=new Int32Array(n),this.laneCount=new Int32Array(n),this.laneLimit=new Float64Array(n),this.laneSignal=new Int32Array(n),this.laneGroup=new Int32Array(n),this.laneGiveWay=new Uint8Array(n),this.laneNext=new Int32Array(n),this.laneNextCount=new Int32Array(n),this.laneConflict=new Int32Array(n),this.laneConflictCount=new Int32Array(n),this.laneLength=new Float64Array(n),this.cumulative=new Float64Array(t);for(let h=0;h<n;h++){this.laneFirst[h]=e[u],this.laneCount[h]=e[u+1],this.laneLimit[h]=P_(e[u+2]),this.laneSignal[h]=e[u+3]===65535?-1:e[u+3],this.laneGroup[h]=e[u+4],this.laneGiveWay[h]=e[u+5],this.laneNext[h]=e[u+6],this.laneNextCount[h]=e[u+7],this.laneConflict[h]=e[u+8],this.laneConflictCount[h]=e[u+9],u+=10;let p=this.laneFirst[h],m=this.laneCount[h];if(m<2||p+m>t||!(this.laneLimit[h]>0))throw new _("invalid_argument",`lane ${h} is malformed`);let f=0;this.cumulative[p]=0;for(let y=1;y<m;y++){let b=(p+y-1)*3,A=(p+y)*3;f+=Math.hypot(this.points[A]-this.points[b],this.points[A+1]-this.points[b+1],this.points[A+2]-this.points[b+2]),this.cumulative[p+y]=f;}this.laneLength[h]=f;}this.successors=Int32Array.from(e.subarray(u,u+r)),u+=r,this.conflicts=Int32Array.from(e.subarray(u,u+o)),u+=o,this.signalMasks=new Uint32Array(s*8),this.signalSeconds=new Float64Array(s*8),this.signalPhases=new Int32Array(s),this.signalAmber=new Float64Array(s),this.signalCycle=new Float64Array(s),this.signalTime=new Float64Array(s);for(let h=0;h<s;h++){let p=0;for(let m=0;m<8;m++)this.signalMasks[h*8+m]=e[u+m],this.signalSeconds[h*8+m]=P_(e[u+8+m]);this.signalPhases[h]=e[u+16];for(let m=0;m<this.signalPhases[h];m++)p+=this.signalSeconds[h*8+m];if(!(p>0))throw new _("invalid_argument",`signal ${h} has no cycle`);this.signalAmber[h]=P_(e[u+16+1]),this.signalCycle[h]=p,this.signalTime[h]=(P_(e[u+16+2])%p+p)%p,u+=19;}let d=Math.ceil(a/4)*4;this.poses=new Float32Array(d*8),this.alive=new Uint8Array(d),this.external=new Uint8Array(d),this.lane=new Int32Array(d).fill(Dh),this.next=new Int32Array(d).fill(Dh),this.segment=new Int32Array(d),this.length=new Float64Array(d),this.position=new Float64Array(d),this.speed=new Float64Array(d),this.params=new Float64Array(d*6),this.gap=new Float64Array(d),this.approach=new Float64Array(d),this.order=new Int32Array(d),this.laneStart=new Int32Array(n+1),this.cursor=new Int32Array(n+1),this.free=new Int32Array(a);for(let h=0;h<a;h++)this.free[h]=a-1-h;this.freeCount=a,this.seed=l|0;}random(e){this.seed=this.seed+1831565813|0;let t=this.seed;return t=Math.imul(t^t>>>15,t|1),t^=t+Math.imul(t^t>>>7,t|61),((t^t>>>14)>>>0)%e}choose(e){let t=this.laneNextCount[e];return t===0?Dh:t===1?this.successors[this.laneNext[e]]:this.successors[this.laneNext[e]+this.random(t)]}signalState(e){let t=this.laneSignal[e];if(t===void 0||t<0)return 0;let n=1<<(this.laneGroup[e]&31),r=this.signalTime[t],o=this.signalPhases[t];for(let s=0;s<o;s++){let a=this.signalSeconds[t*8+s];if(r<a){if((this.signalMasks[t*8+s]&n)===0)return 2;let l=(s+1)%o;return a-r<=this.signalAmber[t]&&(this.signalMasks[t*8+l]&n)===0?1:0}r-=a;}return 2}add(e,t,n,r){if(e<0||e>=this.lanes)throw new _("invalid_argument","unknown lane");if(this.freeCount===0)throw new _("capacity_exceeded","vehicle capacity reached");let o=this.free[--this.freeCount];this.alive[o]=1,this.external[o]=0,this.lane[o]=e,this.next[o]=this.choose(e),this.segment[o]=0,this.position[o]=Math.min(Math.max(t,0),this.laneLength[e]),this.speed[o]=Math.max(n,0),this.length[o]=r[0];for(let s=0;s<6;s++)this.params[o*6+s]=r[s];return this.pose(o),o}remove(e){if(this.alive[e]!==1)throw new _("unknown_resource",`vehicle ${e} does not exist`);this.alive[e]=0,this.lane[e]=Dh,this.free[this.freeCount++]=e;}setExternal(e,t,n,r){if(this.alive[e]!==1||t<0||t>=this.lanes)throw new _("invalid_argument","unknown vehicle or lane");this.external[e]=1,this.lane[e]!==t&&(this.lane[e]=t,this.segment[e]=0,this.next[e]=this.choose(t)),this.position[e]=n,this.speed[e]=Math.max(r,0),this.pose(e);}sort(){let e=this.alive.length;this.laneStart.fill(0);for(let t=0;t<e;t++)this.alive[t]===1&&this.laneStart[this.lane[t]+1]++;for(let t=0;t<this.lanes;t++)this.laneStart[t+1]+=this.laneStart[t];this.cursor.set(this.laneStart);for(let t=0;t<e;t++)this.alive[t]===1&&(this.order[this.cursor[this.lane[t]]++]=t);for(let t=0;t<this.lanes;t++){let n=this.laneStart[t],r=this.laneStart[t+1];for(let o=n+1;o<r;o++){let s=this.order[o],a=this.position[s],l=o;for(;l>n;){let c=this.order[l-1],u=this.position[c];if(u<a||u===a&&c<s)break;this.order[l]=c,l--;}this.order[l]=s;}}}conflictAhead(e){for(let t=0;t<this.laneConflictCount[e];t++){let n=this.conflicts[this.laneConflict[e]+t],r=this.laneStart[n],o=this.laneStart[n+1];if(r===o)continue;let s=this.order[o-1],a=this.laneLength[n]-this.position[s];if(!(a>vWe)&&a/Math.max(this.speed[s],RWe)<xWe)return true}return false}update(e){for(let t=0;t<this.signalTime.length;t++)for(this.signalTime[t]+=e;this.signalTime[t]>=this.signalCycle[t];)this.signalTime[t]-=this.signalCycle[t];this.sort();for(let t=0;t<this.lanes;t++){let n=this.laneStart[t],r=this.laneStart[t+1];if(n===r)continue;let o=this.laneLength[t],s=this.signalState(t),a=this.laneGiveWay[t]===1&&this.conflictAhead(t);for(let l=n;l<r;l++){let c=this.order[l],u=this.speed[c],d=EWe,h=0;if(l+1<r){let y=this.order[l+1];d=this.position[y]-this.position[c]-this.length[y],h=u-this.speed[y];}else if(this.next[c]!==Dh){let y=this.next[c];if(this.laneStart[y]<this.laneStart[y+1]){let b=this.order[this.laneStart[y]];d=o-this.position[c]+this.position[b]-this.length[b],h=u-this.speed[b];}}else d=o-this.position[c],h=u;let p=o-H3-this.position[c],m=u*u/(2*this.params[c*6+5]);(s===2&&p>-H3||s===1&&p>m||a&&p>-H3)&&p<d&&(d=p,h=u),this.gap[c]=d,this.approach[c]=h;}}for(let t=0;t<this.lanes;t++)for(let n=this.laneStart[t];n<this.laneStart[t+1];n++){let r=this.order[n];if(this.external[r]===1)continue;let o=r*6,s=this.speed[r],a=this.laneLimit[t]*this.params[o+1],l=this.params[o+4],c=s/a,u=c*c,d=s*this.params[o+2]+s*this.approach[r]/(2*Math.sqrt(l*this.params[o+5])),h=(this.params[o+3]+Math.max(d,0))/Math.max(this.gap[r],SWe),p=Math.max(l*(1-u*u-h*h),-9),m=Math.max(s+p*e,0);this.position[r]+=(s+m)*.5*e,this.speed[r]=m;}for(let t=0;t<this.alive.length;t++)if(this.alive[t]===1){if(this.external[t]===0)for(;;){let n=this.lane[t],r=this.laneLength[n];if(this.position[t]<r)break;let o=this.next[t];if(o===Dh){this.position[t]=r,this.speed[t]=0;break}this.position[t]-=r,this.lane[t]=o,this.segment[t]=0,this.next[t]=this.choose(o);}this.pose(t);}}pose(e){let t=this.lane[e],n=this.laneFirst[t],r=this.laneCount[t]-2,o=this.position[e],s=Math.min(this.segment[e],r);for(;s<r&&this.cumulative[n+s+1]<o;)s++;for(;s>0&&this.cumulative[n+s]>o;)s--;this.segment[e]=s;let a=(n+s)*3,l=a+3,c=this.cumulative[n+s+1]-this.cumulative[n+s],u=Math.min(Math.max((o-this.cumulative[n+s])/c,0),1),d=this.points[l]-this.points[a],h=this.points[l+2]-this.points[a+2],p=Math.sqrt(d*d+h*h),m=e*8;this.poses[m+0]=this.points[a]+d*u,this.poses[m+1]=this.points[a+1]+(this.points[l+1]-this.points[a+1])*u,this.poses[m+2]=this.points[a+2]+h*u,p>0&&(this.poses[m+3]=d/p,this.poses[m+4]=h/p),this.poses[m+5]=this.speed[e],this.poses[m+6]=t;}};var Cre=new Float32Array(0),Qv=class{constructor(){this.name="js-nav";this.mesh=null;this.links=null;this.query=null;this.crowd=null;this.traffic=null;this.filter=new Lh;this.extents=Gf;this.path=new Float64Array(0);this.complete=false;}get pathComplete(){return this.complete}requireMesh(){if(!this.mesh)throw new _("not_initialized","navigation is not initialised");return this.mesh}requireQuery(){if(!this.query)throw new _("not_initialized","navigation is not initialised");return this.query}requireCrowd(){if(!this.crowd)throw new _("not_initialized","navigation is not initialised");return this.crowd}init(e){let t=e.origin??[0,0];this.extents=e.extents??Gf;let n=new Gv(t[0],t[1],e.tileWorld,e.maxTiles??256),r=new Xv,o=new k_(n,e.queryNodes??2048,r),s=new k_(n,e.queryNodes??2048,r);this.path=new Float64Array(e.maxPathPolys??256),this.mesh=n,this.links=r,this.query=o,this.crowd=new Kv(n,s,this.filter,{maxAgents:e.maxAgents??512,neighbourDistance:e.neighbourDistance??4,timeHorizon:e.timeHorizon??2,pathBudget:e.pathBudget??16,maxPathPolys:e.maxPathPolys??256,extents:this.extents},r);}requireLinks(){if(!this.links)throw new _("not_initialized","navigation is not initialised");return this.links}addTile(e){let t=this.requireMesh().addTile(e);return this.requireLinks().resolve(this.requireQuery()),t}removeTile(e,t){this.requireMesh().removeTile(e,t),this.requireLinks().resolve(this.requireQuery());}addLink(e,t,n,r,o,s){return this.requireLinks().add(e,t,n,r,o,s,this.requireQuery())}removeLink(e){this.requireLinks().remove(e,this.requireQuery());}setAreaCost(e,t){this.filter.costs[e]=t;}setIncludeMask(e,t){this.filter.includeLow=e>>>0,this.filter.includeHigh=t>>>0;}nearest(e,t,n,r){let o=this.requireQuery(),s=this.extents;return o.nearest(e,t,n,s[0],s[1],s[2],this.filter)===lt?false:(r[0]=o.point[0],r[1]=o.point[1],r[2]=o.point[2],true)}findPath(e,t,n,r,o,s,a){let l=this.requireQuery(),c=this.extents;this.complete=false;let u=l.nearest(e,t,n,c[0],c[1],c[2],this.filter);if(u===lt)return 0;let d=l.point[0],h=l.point[1],p=l.point[2],m=l.nearest(r,o,s,c[0],c[1],c[2],this.filter);if(m===lt)return 0;let f=l.point[0],y=l.point[1],b=l.point[2],A=l.findPath(u,m,d,h,p,f,y,b,this.filter,this.path);return this.complete=l.complete,l.straightPath(d,h,p,f,y,b,this.path,A,a)}addAgent(e,t,n,r,o,s){return this.requireCrowd().add(e,t,n,r,o,s)}removeAgent(e){this.requireCrowd().remove(e);}setAgentTarget(e,t,n,r){this.requireCrowd().setTarget(e,t,n,r);}stopAgent(e){this.requireCrowd().stop(e);}agents(){return this.crowd?this.crowd.out:Cre}loadRoads(e){this.traffic=new zv(e);}roads(){if(!this.traffic)throw new _("unsupported_feature","no road graph is loaded");return this.traffic}addVehicle(e,t,n,r){return this.roads().add(e,t,n,r)}removeVehicle(e){this.roads().remove(e);}setExternalVehicle(e,t,n,r){this.roads().setExternal(e,t,n,r);}vehicles(){return this.traffic?this.traffic.poses:Cre}signal(e){return this.traffic?this.traffic.signalState(e):0}step(e){this.crowd&&this.crowd.size>0&&this.crowd.update(e),this.traffic&&this.traffic.update(e);}dispose(){this.mesh=null,this.links=null,this.query=null,this.crowd=null,this.traffic=null;}};var We={Truncated:-1,BufferTooSmall:-2,UnknownKind:-3,UnsupportedVersion:-4,UnexpectedKind:-5,PayloadTooLarge:-6,TooManyEntries:-7,ReservedBitsSet:-8,UnknownCode:-9},Gt={channel:et.channel.code,room_input:et.room_input.code,move_input:et.move_input.code,presence_tick:et.presence_tick.code,ack:et.ack.code,fast_read:et.fast_read.code,fast_value:et.fast_value.code,counter_add:et.counter_add.code,counter_value:et.counter_value.code,presence_delta:et.presence_delta.code},fe=true,Mre=15,Dre=4,IWe=.5,Pre=2*Math.PI,OWe=-1,CWe=1,NWe=65535;var kWe=-1,gn=et.channel,sn=et.room_input,Er=et.move_input,ct=et.presence_tick,Pn=et.ack,Zo=et.fast_read,qr=et.fast_value,wn=et.counter_add,LWe=et.counter_value,zr=et.presence_delta,xl=Oi.presence_delta,MWe=0,DWe=1,Nre=2,PWe=64,FWe=128,UWe=127,BWe=7,kre=3,GWe=3,W3=4294967296,Fre=new Uint8Array(Mre+1);for(let i of Object.values(Gt))Fre[i]=1;var Ure=256,K3=new Uint8Array(Ure);for(let i of Object.values(tm.fast_status))K3[i]=1;var VWe=new Uint8Array(Ure);for(let i of Object.values(tm.fast_target))VWe[i]=1;function Ph(i){return BI<<Dre|i}function vl(i,e,t){if(t-e<1)return We.Truncated;let n=i.getUint8(e);if(n>>Dre!==BI)return We.UnsupportedVersion;let r=n&Mre;return Fre[r]===1?r:We.UnknownKind}function Bre(i,e,t){if(t-e<ct.header_bytes)return We.Truncated;let n=i.getUint16(e+ct.fields.count,fe);if(n>an.max_presence_entries)return We.TooManyEntries;let r=ct.header_bytes+n*ct.entry_bytes;return t-e<r?We.Truncated:r}function F_(i,e,t,n,r){let o=vl(i,e,t);return o<0?o:o!==n?We.UnexpectedKind:t-e<r?We.Truncated:0}function Yc(i,e,t,n,r,o,s){let a=F_(i,e,t,n,r);if(a<0)return a;let l=i.getUint16(e+o,fe);if(l>s)return We.PayloadTooLarge;let c=r+l;return t-e<c?We.Truncated:c}function Jv(i,e,t){let n=vl(i,e,t);switch(n){case Gt.channel:return Yc(i,e,t,n,gn.header_bytes,gn.fields.payload_length,an.max_channel_payload_bytes);case Gt.room_input:return Yc(i,e,t,n,sn.header_bytes,sn.fields.payload_length,an.max_room_input_payload_bytes);case Gt.move_input:return t-e<Er.header_bytes?We.Truncated:Er.header_bytes;case Gt.ack:return t-e<Pn.header_bytes?We.Truncated:Pn.header_bytes;case Gt.presence_tick:return Bre(i,e,t);case Gt.presence_delta:return Hre(i,e,t);case Gt.fast_read:return Yc(i,e,t,n,Zo.header_bytes,Zo.fields.key_length,an.max_fast_key_bytes);case Gt.fast_value:return Yc(i,e,t,n,qr.header_bytes,qr.fields.value_length,an.max_fast_value_bytes);case Gt.counter_add:case Gt.counter_value:return t-e<wn.header_bytes?We.Truncated:wn.header_bytes;default:return n}}function Zv(i,e,t,n){if(n>an.max_channel_payload_bytes)return We.PayloadTooLarge;let r=gn.header_bytes+n;return i.byteLength-e<r?We.BufferTooSmall:(i.setUint8(e+gn.fields.tag,Ph(gn.code)),i.setUint8(e+gn.fields.flags,t.flags),i.setUint16(e+gn.fields.slot,t.slot,fe),i.setUint32(e+gn.fields.sequence,t.sequence,fe),i.setUint16(e+gn.fields.sender,t.sender,fe),i.setUint16(e+gn.fields.payload_length,n,fe),r)}function eR(i,e,t,n){let r=Yc(i,e,t,gn.code,gn.header_bytes,gn.fields.payload_length,an.max_channel_payload_bytes);return r<0||(n.flags=i.getUint8(e+gn.fields.flags),n.slot=i.getUint16(e+gn.fields.slot,fe),n.sequence=i.getUint32(e+gn.fields.sequence,fe),n.sender=i.getUint16(e+gn.fields.sender,fe),n.payload_offset=e+gn.fields.payload,n.payload_length=r-gn.header_bytes),r}function U_(i,e,t,n){if(n>an.max_room_input_payload_bytes)return We.PayloadTooLarge;let r=sn.header_bytes+n;return i.byteLength-e<r?We.BufferTooSmall:(i.setUint8(e+sn.fields.tag,Ph(sn.code)),i.setUint8(e+sn.fields.flags,t.flags),i.setUint16(e+sn.fields.action,t.action,fe),i.setUint32(e+sn.fields.sequence,t.sequence,fe),i.setUint32(e+sn.fields.client_tick,t.client_tick,fe),i.setUint16(e+sn.fields.sender,t.sender,fe),i.setUint16(e+sn.fields.payload_length,n,fe),r)}function Gre(i,e,t,n){let r=Yc(i,e,t,sn.code,sn.header_bytes,sn.fields.payload_length,an.max_room_input_payload_bytes);return r<0||(n.flags=i.getUint8(e+sn.fields.flags),n.action=i.getUint16(e+sn.fields.action,fe),n.sequence=i.getUint32(e+sn.fields.sequence,fe),n.client_tick=i.getUint32(e+sn.fields.client_tick,fe),n.sender=i.getUint16(e+sn.fields.sender,fe),n.payload_offset=e+sn.fields.payload,n.payload_length=r-sn.header_bytes),r}function tR(i,e,t){return i.byteLength-e<Er.header_bytes?We.BufferTooSmall:(i.setUint8(e+Er.fields.tag,Ph(Er.code)),i.setUint8(e+Er.fields.buttons,t.buttons),i.setUint16(e+Er.fields.sequence,t.sequence,fe),i.setUint32(e+Er.fields.client_tick,t.client_tick,fe),i.setInt16(e+Er.fields.axis_x,t.axis_x,fe),i.setInt16(e+Er.fields.axis_z,t.axis_z,fe),i.setUint16(e+Er.fields.yaw,t.yaw,fe),i.setUint8(e+Er.fields.layer,t.layer),i.setUint8(e+Er.fields.subtick,t.subtick),Er.header_bytes)}function nR(i,e,t,n){let r=F_(i,e,t,ct.code,ct.header_bytes);if(r<0)return r;let o=Bre(i,e,t);return o<0||(n.flags=i.getUint8(e+ct.fields.flags),n.count=i.getUint16(e+ct.fields.count,fe),n.server_tick=i.getUint32(e+ct.fields.server_tick,fe),n.cell_index=i.getUint32(e+ct.fields.cell_index,fe),n.acked_input=i.getUint16(e+ct.fields.acked_input,fe),n.layer=i.getUint8(e+ct.fields.layer),n.baseline_age=i.getUint8(e+ct.fields.baseline_age),n.entries_offset=e+ct.header_bytes),o}function Vre(i,e,t,n){if(t<0||t>=e.count)return false;let r=e.entries_offset+t*ct.entry_bytes;return n.slot=i.getUint16(r+ct.entry_fields.slot,fe),n.x=i.getUint16(r+ct.entry_fields.x,fe),n.y=i.getInt16(r+ct.entry_fields.y,fe),n.z=i.getUint16(r+ct.entry_fields.z,fe),n.yaw=i.getUint16(r+ct.entry_fields.yaw,fe),n.animation=i.getUint8(r+ct.entry_fields.animation),n.flags=i.getUint8(r+ct.entry_fields.flags),true}var es=0;function $v(i,e,t,n,r){if(es=0,(n&r)===0)return e;let o=0;for(let s=0;s<kre;s++){if(e+s>=t)return We.Truncated;let a=i.getUint8(e+s);if(s===kre-1&&a>GWe)return We.ReservedBitsSet;if(o|=(a&UWe)<<BWe*s,(a&FWe)===0)return es=o>>>1^-(o&1),e+s+1}return We.ReservedBitsSet}function Lre(i,e,t,n,r){return es=0,(n&r)===0?e:e>=t?We.Truncated:(es=i.getUint8(e),e+1)}function Y3(i,e,t,n){if(t-e<Nre)return We.Truncated;let r=i.getUint8(e+DWe);if(n.slot=i.getUint8(e+MWe),n.mask=r,(r&PWe)!==0)return We.ReservedBitsSet;if((r&xl.entry_full)!==0)return r!==xl.entry_full?We.ReservedBitsSet:t-e<ct.entry_bytes?We.Truncated:(n.x=i.getUint16(e+ct.entry_fields.x,fe),n.y=i.getInt16(e+ct.entry_fields.y,fe),n.z=i.getUint16(e+ct.entry_fields.z,fe),n.yaw=i.getUint16(e+ct.entry_fields.yaw,fe),n.animation=i.getUint8(e+ct.entry_fields.animation),n.flags=i.getUint8(e+ct.entry_fields.flags),e+ct.entry_bytes);let o=$v(i,e+Nre,t,r,xl.entry_x);return o<0||(n.x=es,o=$v(i,o,t,r,xl.entry_y),o<0)||(n.y=es,o=$v(i,o,t,r,xl.entry_z),o<0)||(n.z=es,o=$v(i,o,t,r,xl.entry_yaw),o<0)||(n.yaw=es,o=Lre(i,o,t,r,xl.entry_animation),o<0)||(n.animation=es,o=Lre(i,o,t,r,xl.entry_flags),o<0)||(n.flags=es),o}var HWe={slot:0,mask:0,x:0,y:0,z:0,yaw:0,animation:0,flags:0};function Hre(i,e,t){if(t-e<zr.header_bytes)return We.Truncated;let n=i.getUint16(e+zr.fields.count,fe);if(n>an.max_presence_entries)return We.TooManyEntries;let r=e+zr.header_bytes;for(let o=0;o<n;o++)if(r=Y3(i,r,t,HWe),r<0)return r;return r-e}function Wre(i,e,t,n){let r=F_(i,e,t,zr.code,zr.header_bytes);if(r<0)return r;let o=Hre(i,e,t);return o<0||(n.flags=i.getUint8(e+zr.fields.flags),n.count=i.getUint16(e+zr.fields.count,fe),n.server_tick=i.getUint32(e+zr.fields.server_tick,fe),n.cell_index=i.getUint32(e+zr.fields.cell_index,fe),n.acked_input=i.getUint16(e+zr.fields.acked_input,fe),n.layer=i.getUint8(e+zr.fields.layer),n.baseline_age=i.getUint8(e+zr.fields.baseline_age),n.entries_offset=e+zr.header_bytes,n.end=e+o),o}function X3(i,e,t){return i.byteLength-e<Pn.header_bytes?We.BufferTooSmall:(i.setUint8(e+Pn.fields.tag,Ph(Pn.code)),i.setUint8(e+Pn.fields.reserved,0),i.setUint16(e+Pn.fields.slot,t.slot,fe),i.setUint32(e+Pn.fields.sequence,t.sequence,fe),i.setUint32(e+Pn.fields.received_mask,t.received_mask,fe),Pn.header_bytes)}function Kre(i,e,t,n){let r=F_(i,e,t,Pn.code,Pn.header_bytes);return r<0?r:i.getUint8(e+Pn.fields.reserved)!==0?We.ReservedBitsSet:(n.slot=i.getUint16(e+Pn.fields.slot,fe),n.sequence=i.getUint32(e+Pn.fields.sequence,fe),n.received_mask=i.getUint32(e+Pn.fields.received_mask,fe),Pn.header_bytes)}function Yre(i,e,t,n){if(n>an.max_fast_key_bytes)return We.PayloadTooLarge;let r=Zo.header_bytes+n;return i.byteLength-e<r?We.BufferTooSmall:(i.setUint8(e+Zo.fields.tag,Ph(Zo.code)),i.setUint8(e+Zo.fields.target,t.target),i.setUint16(e+Zo.fields.slot,t.slot,fe),i.setUint32(e+Zo.fields.correlation,t.correlation,fe),i.setUint16(e+Zo.fields.key_length,n,fe),i.setUint16(e+Zo.fields.reserved,0,fe),r)}function Xre(i,e,t,n){let r=Yc(i,e,t,qr.code,qr.header_bytes,qr.fields.value_length,an.max_fast_value_bytes);return r<0?r:i.getUint16(e+qr.fields.reserved,fe)!==0?We.ReservedBitsSet:(n.status=i.getUint8(e+qr.fields.status),K3[n.status]!==1?We.UnknownCode:(n.slot=i.getUint16(e+qr.fields.slot,fe),n.correlation=i.getUint32(e+qr.fields.correlation,fe),n.stamp_low=i.getUint32(e+qr.fields.stamp_low,fe),n.stamp_high=i.getUint32(e+qr.fields.stamp_high,fe),n.value_offset=e+qr.fields.value,n.value_length=r-qr.header_bytes,r))}function WWe(i,e,t,n){if(i.byteLength-e<wn.header_bytes)return We.BufferTooSmall;let r=Math.floor(n.value/W3);return i.setUint8(e+wn.fields.tag,Ph(t)),i.setUint8(e+wn.fields.status,n.status),i.setUint16(e+wn.fields.slot,n.slot,fe),i.setUint32(e+wn.fields.correlation,n.correlation,fe),i.setUint32(e+wn.fields.low,n.value-r*W3,fe),i.setInt32(e+wn.fields.high,r,fe),wn.header_bytes}function KWe(i,e,t,n,r){let o=F_(i,e,t,n,wn.header_bytes);return o<0?o:(r.status=i.getUint8(e+wn.fields.status),r.slot=i.getUint16(e+wn.fields.slot,fe),r.correlation=i.getUint32(e+wn.fields.correlation,fe),r.value=i.getInt32(e+wn.fields.high,fe)*W3+i.getUint32(e+wn.fields.low,fe),wn.header_bytes)}function qre(i,e,t){return WWe(i,e,wn.code,t)}function zre(i,e,t,n){let r=KWe(i,e,t,LWe.code,n);return r>0&&K3[n.status]!==1?We.UnknownCode:r}function q3(i){return Math.floor(i+IWe)}function z3(i){return Number.isNaN(i)?0:i}function Qre(i,e,t){return Math.min(Math.max(i,e),t)}function Q3(i){return z3(q3(Qre(i,OWe,CWe)*Ir.axis_scale))}function $re(i){let e=i/Pre%1;return e<0&&(e+=1),z3(q3(e*Ir.yaw_units_per_turn)%Ir.yaw_units_per_turn)}function $3(i){return i/Ir.yaw_units_per_turn*Pre}function j3(i){return z3(Qre(q3(i*Ir.position_units_per_metre),0,NWe))}function Xc(i){return i/Ir.position_units_per_metre}function J3(i){return i/Ir.position_units_per_metre}var jv=class{constructor(e,t=ib){this.capacity=e,this.slot_bytes=t;let n=new ArrayBuffer(e*t);this.views=Array.from({length:e},(r,o)=>new DataView(n,o*t,t)),this.arrays=Array.from({length:e},(r,o)=>new Uint8Array(n,o*t,t)),this.free=Int32Array.from({length:e},(r,o)=>e-1-o),this.top=e;}get available(){return this.top}acquire(){return this.top===0?kWe:(this.top-=1,this.free[this.top])}release(e){this.top!==this.capacity&&(this.free[this.top]=e,this.top+=1);}view(e){return this.views[e]}bytes(e){return this.arrays[e]}};var jre=65535,Jre=65534,Zre=65533,eie=65532,rR=65535,tie=65535,nie=0,Rl={Datagram:0,Reliable:1},B_=1,Fh=2,rie=1,iie=2,iR=4,oie=36,Z3=16;var sie=2048,Uh=ib,eD=16,ea=64;var hn=128,ta=32,oR=64,aie=32,lie=4,G_=16,V_=65535,ji=4294967296,cie=65536,qt=256,tD=32,uie=2,nD=256,rD=nD-1,iD=255,die=8,hie=16,Ji={Steady:0,Faster:1,Slower:2},pie=.95,mie=1.05,fie=5,H_=1e3,oD=1e9,_ie=2,sR=16,yie=.125,aR=64,Aie=.0625,bie=2,sD=2,gie=.1,Eie=400,xie=250,vie=220,Rie=200,Sie=100,aD=.5,Zi=32,Tie=1500,wie=1e4,Iie=2e3,Oie=3e4,Cie=864e5,lD="cimplify.rooms.transport.",Nie="default",kie=6,Lie=500,Mie=tD/4,Die=250,cD=65535,uD=32767,dD=512,hD=16,Sl=Ir.axis_scale,pD=1<<24,Pie=6*Ir.position_units_per_metre,Fie=10*Ir.position_units_per_metre,Uie=Oi.move_input.sprint,Bie=Oi.presence_tick.keyframe,qc=Ir.yaw_units_per_turn,mD=qc/2;var lR=class{constructor(){this.tickMs=0;this.sendIntervalMs=0;this.offsets=new Float64Array(aR);this.rtts=new Float64Array(sR);this.offsetCount=0;this.offsetNext=0;this.rttCount=0;this.rttNext=0;this.offsetMs=0;this.jitter=0;this.smoothedRtt=0;this.delay=0;}configure(e,t,n){this.tickMs=H_/e,this.sendIntervalMs=H_/t,this.offsetCount=0,this.offsetNext=0,this.rttCount=0,this.rttNext=0,this.jitter=0,this.offsetMs=0,this.smoothedRtt=n,this.delay=sD*this.sendIntervalMs;}get tickIntervalMs(){return this.tickMs}get rttMs(){return this.smoothedRtt}get jitterMs(){return this.jitter}get interpolationDelayMs(){return this.delay}get synchronised(){return this.offsetCount>0}snapshot(e,t){let n=e*this.tickMs-t;this.offsets[this.offsetNext]=n,this.offsetNext=(this.offsetNext+1)%aR,this.offsetCount<aR&&(this.offsetCount+=1);let r=n;for(let s=0;s<this.offsetCount;s++)this.offsets[s]>r&&(r=this.offsets[s]);this.offsetMs=r,this.jitter+=(r-n-this.jitter)*Aie;let o=Math.min(sD*this.sendIntervalMs+bie*this.jitter,Eie);this.delay+=(o-this.delay)*gie;}roundTrip(e){if(!(e>=0))return;this.rtts[this.rttNext]=e,this.rttNext=(this.rttNext+1)%sR,this.rttCount<sR&&(this.rttCount+=1);let t=e;for(let n=0;n<this.rttCount;n++)this.rtts[n]<t&&(t=this.rtts[n]);this.smoothedRtt+=(t-this.smoothedRtt)*yie;}serverTick(e){return (e+this.offsetMs)/this.tickMs}renderTick(e){return (e+this.offsetMs-this.delay)/this.tickMs}leadTicks(){return this.smoothedRtt/2/this.tickMs}};var Qr={Idle:0,Pending:1,Won:2,Failed:3},zc={Waiting:0,Dialed:1,Failed:2},cR=class{constructor(e,t){this.settled=zc.Waiting;this.dialed=null;this.done=e=>{this.dialed=e,this.settled=e?zc.Dialed:zc.Failed,this.race.settled(this);};this.failed=()=>{this.done(null);};this.dialer=e,this.race=t;}start(e){this.dialer.dial(e,this).then(this.done,this.failed);}frame(e,t){this.race.forward(this,e,t);}closed(){this.race.lost(this);}backpressure(e,t){this.race.backpressure(this,e,t);}},W_=class{constructor(e,t,n,r){this.sink=null;this.request=null;this.first=null;this.second=null;this.won=null;this.networkKey="";this.startedAt=0;this.lastNow=0;this.state=Qr.Idle;this.primary=e,this.fallback=t,this.memory=n,this.network=r;}get winner(){return this.won?.dialed??null}begin(e,t,n){this.cancel(),this.sink=t,this.request=e,this.startedAt=n,this.lastNow=n,this.state=Qr.Pending,this.networkKey=this.network();let r=this.memory.recall(this.networkKey,n),s=this.fallback!==null&&r===this.fallback.transport||!this.primary?this.fallback:this.primary;if(!s){this.state=Qr.Failed;return}this.first=new cR(s,this),s===this.fallback&&(this.second=this.first),this.first.start(e);}poll(e){if(this.lastNow=e,this.state!==Qr.Pending)return this.state;let t=e-this.startedAt;return !this.second&&this.fallback&&(t>=Tie||this.first?.settled===zc.Failed)&&this.launchFallback(),this.state===Qr.Pending&&(t>=wie||this.exhausted())&&this.fail(),this.state}cancel(){for(let e of [this.first,this.second])e?.dialed?.link.close();this.first=null,this.second=null,this.won=null,this.sink=null,this.state=Qr.Idle;}release(){let e=this.winner;return this.first=null,this.second=null,this.state=Qr.Idle,e}forward(e,t,n){e===this.won&&this.sink?.frame(t,n);}lost(e){e===this.won&&this.sink?.closed();}backpressure(e,t,n){e===this.won&&this.sink?.backpressure?.(t,n);}settled(e){if(e!==this.first&&e!==this.second){e.dialed?.link.close();return}if(e.settled!==zc.Dialed)return;if(this.won){e!==this.won&&e.dialed?.link.close();return}this.won=e,this.state=Qr.Won;let t=e===this.first?this.second:this.first;t&&t!==e&&t.dialed?.link.close(),this.primary&&this.fallback&&this.memory.remember(this.networkKey,e.dialer.transport,this.lastNow);}launchFallback(){!this.fallback||!this.request||(this.second=new cR(this.fallback,this),this.second.start(this.request));}exhausted(){let e=!this.first||this.first.settled===zc.Failed,t=this.second?this.second.settled===zc.Failed:!this.fallback;return e&&t}fail(){let e=this.sink;this.cancel(),this.sink=e,this.state=Qr.Failed;}};var uR=class{constructor(){this.pool=new jv(ea,Uh);this.slots=new Int32Array(ea);this.lanes=new Uint8Array(ea);this.lengths=new Int32Array(ea);this.head=0;this.count=0;this.current=-1;this.dropped=0;this.sendFailures=0;this.lastSendStatus=0;this.lost=false;}clear(){for(this.release();this.count>0;)this.pool.release(this.slots[this.head]),this.head=(this.head+1)%ea,this.count-=1;this.lost=false;}frame(e,t){if(t.length>Uh||this.count===ea){this.dropped+=1;return}let n=this.pool.acquire();if(n<0){this.dropped+=1;return}this.pool.bytes(n).set(t);let r=(this.head+this.count)%ea;this.slots[r]=n,this.lanes[r]=e,this.lengths[r]=t.length,this.count+=1;}closed(){this.lost=true;}backpressure(e,t){this.sendFailures+=e,this.lastSendStatus=t;}next(){return this.release(),this.count===0?false:(this.current=this.head,this.head=(this.head+1)%ea,this.count-=1,true)}get view(){return this.pool.view(this.slots[this.current])}get length(){return this.lengths[this.current]}get lane(){return this.lanes[this.current]}release(){this.current<0||(this.pool.release(this.slots[this.current]),this.current=-1);}};var dR=class{constructor(){this.buttons=new Uint8Array(qt);this.axisX=new Int16Array(qt);this.axisZ=new Int16Array(qt);this.yaw=new Uint16Array(qt);this.clientTick=new Float64Array(qt);this.subtick=new Uint8Array(qt);this.sentAt=new Float64Array(qt);this.frame={buttons:0,sequence:0,client_tick:0,axis_x:0,axis_z:0,yaw:0,layer:nie,subtick:0};this.latestSequence=0;this.appliedSequence=0;this.durableSequence=0;}get latest(){return this.latestSequence}get applied(){return this.appliedSequence}get durable(){return this.durableSequence}get pending(){return this.latestSequence-this.appliedSequence}rebase(e){this.appliedSequence=e,this.durableSequence>e&&(this.durableSequence=e),(this.latestSequence<e||this.latestSequence-this.durableSequence>=qt)&&(this.latestSequence=e,this.durableSequence=e);}reset(e){this.latestSequence=e,this.appliedSequence=e,this.durableSequence=e;}acknowledge(e){return e<=this.appliedSequence||e>this.latestSequence?false:(this.appliedSequence=e,true)}persist(e){e>this.durableSequence&&(this.durableSequence=Math.min(e,this.latestSequence));}holds(e){return e>this.durableSequence&&e<=this.latestSequence}push(e,t,n,r,o,s){this.latestSequence-this.durableSequence>=qt&&(this.durableSequence+=1);let a=this.latestSequence+1,l=a%qt;return this.axisX[l]=e,this.axisZ[l]=t,this.yaw[l]=n,this.buttons[l]=r,this.clientTick[l]=o,this.subtick[l]=s,this.sentAt[l]=Number.NaN,this.latestSequence=a,a}axisXOf(e){return this.axisX[e%qt]}axisZOf(e){return this.axisZ[e%qt]}buttonsOf(e){return this.buttons[e%qt]}yawOf(e){return this.yaw[e%qt]}sentAtOf(e){return this.holds(e)?this.sentAt[e%qt]:Number.NaN}write(e,t,n){let r=Math.max(this.appliedSequence,this.durableSequence)+1,o=Math.min(this.latestSequence,r+tD-1),s=t,a=this.frame;for(let l=r;l<=o;l++){let c=l%qt;a.buttons=this.buttons[c],a.sequence=l%cie,a.client_tick=this.clientTick[c]>>>0,a.axis_x=this.axisX[c],a.axis_z=this.axisZ[c],a.yaw=this.yaw[c],a.subtick=this.subtick[c];let u=tR(e,s,a);if(u<0)break;s+=u,Number.isNaN(this.sentAt[c])&&(this.sentAt[c]=n);}return s-t}};var Qc={None:0,Interpolated:1,Extrapolated:2},Bh=hn*Zi;function YWe(i,e,t){let n=e-i;return n>mD?n-=qc:n<-mD&&(n+=qc),((i+n*t)%qc+qc)%qc}var hR=class{constructor(){this.ticks=new Float64Array(Bh);this.xs=new Int32Array(Bh);this.ys=new Int32Array(Bh);this.zs=new Int32Array(Bh);this.yaws=new Uint16Array(Bh);this.animations=new Uint8Array(Bh);this.heads=new Int32Array(hn);this.counts=new Int32Array(hn);}reset(){this.counts.fill(0),this.heads.fill(0);}newestTick(e){return this.counts[e]===0?-1:this.ticks[e*Zi+this.heads[e]]}push(e,t,n,r,o,s,a){if(this.counts[e]>0&&t<=this.newestTick(e))return;let l=this.counts[e]===0?0:(this.heads[e]+1)%Zi,c=e*Zi+l;this.ticks[c]=t,this.xs[c]=n,this.ys[c]=r,this.zs[c]=o,this.yaws[c]=s,this.animations[c]=a,this.heads[e]=l,this.counts[e]<Zi&&(this.counts[e]+=1);}sample(e,t,n,r){let o=this.counts[e];if(o===0)return Qc.None;let s=e*Zi,a=s+this.heads[e];if(t>=this.ticks[a]){if(o===1)return this.copy(a,r),Qc.Extrapolated;let c=s+(this.heads[e]+Zi-1)%Zi,u=this.ticks[a]-this.ticks[c],d=Math.min(t-this.ticks[a],n);return this.blend(c,a,u>0?1+d/u:1,r),Qc.Extrapolated}let l=a;for(let c=1;c<o;c++){let u=s+(this.heads[e]+Zi-c)%Zi;if(this.ticks[u]<=t){let d=this.ticks[l]-this.ticks[u];return this.blend(u,l,d>0?(t-this.ticks[u])/d:0,r),Qc.Interpolated}l=u;}return this.copy(l,r),Qc.Interpolated}copy(e,t){t.x=this.xs[e],t.y=this.ys[e],t.z=this.zs[e],t.yaw=this.yaws[e],t.animation=this.animations[e];}blend(e,t,n,r){r.x=this.xs[e]+(this.xs[t]-this.xs[e])*n,r.y=this.ys[e]+(this.ys[t]-this.ys[e])*n,r.z=this.zs[e]+(this.zs[t]-this.zs[e])*n,r.yaw=YWe(this.yaws[e],this.yaws[t],n),r.animation=this.animations[t];}};var eo={Admitted:0,Malformed:1,Expired:3,UnknownResume:4,Full:5,Overloaded:6,Unavailable:7,Denied:9},XWe=eo.Denied,$c=true;function fD(){return {status:eo.Unavailable,slot:0,route:0,resume:new Uint8Array(Z3),simulationHz:0,sendHz:0,tick:0}}function Gie(i,e,t){if(iR+e.length>sie)throw new RangeError("the join request is too large");let n=new Uint8Array(iR+e.length),r=new DataView(n.buffer);return r.setUint8(0,t),r.setUint8(1,i),r.setUint16(2,e.length,$c),n.set(e,iR),n}function _D(i,e=Fh){return Gie(rie,i,e)}function yD(i,e=Fh){return Gie(iie,i,e)}function Vie(i){return i.length===0||i[0]!==Fh?false:(i[0]=B_,true)}function AD(i,e){if(i.length!==oie)return false;let t=new DataView(i.buffer,i.byteOffset,i.byteLength);if(t.getUint8(0)!==B_)return false;let n=t.getUint8(1);return n>XWe?false:(e.status=n,e.slot=t.getUint16(2,$c),e.route=t.getUint32(4,$c),e.resume.set(i.subarray(8,8+Z3)),e.simulationHz=t.getUint16(24,$c),e.sendHz=t.getUint16(26,$c),e.tick=t.getUint32(32,$c)*ji+t.getUint32(28,$c),true)}var qWe=BigInt(24),zWe=Sl*Sl;function bD(i,e){let t=BigInt(i)*BigInt(e)<<qWe,n=BigInt(Sl)*BigInt(oD);return Number(t/n)}function Wie(i){let e=Math.floor(Math.sqrt(i));for(;e*e>i;)e-=1;for(;(e+1)*(e+1)<=i;)e+=1;return e}function gD(i,e){i.x=uD+e%hD*dD,i.z=uD+Math.floor(e/hD)*dD,i.axisX=0,i.axisZ=0,i.buttons=0;}function ED(i,e,t,n){let r=Math.max(e,-Sl),o=Math.max(t,-Sl),s=r*r+o*o;if(s<=zWe)i.axisX=r,i.axisZ=o;else {let a=Wie(s);i.axisX=Math.trunc(r*Sl/a),i.axisZ=Math.trunc(o*Sl/a);}i.buttons=n;}function Hie(i){return i<0?0:i>cD?cD:i}var K_=class{constructor(e,t){this.substeps=Math.ceil(t/e),this.stepNs=Math.floor(oD/(e*this.substeps)),this.walk=bD(Pie,this.stepNs),this.sprint=bD(Fie,this.stepNs);}step(e){let t=(e.buttons&Uie)!==0?this.sprint:this.walk,n=Math.floor(e.axisX*t/pD),r=Math.floor(e.axisZ*t/pD);e.x=Hie(e.x+n*this.substeps),e.z=Hie(e.z+r*this.substeps);}};var QWe=0,pR=class{constructor(e,t){this.toleranceUnits=QWe;this.body={x:0,z:0,axisX:0,axisZ:0,buttons:0};this.locomotion=new K_(e,t);}get x(){return this.body.x}get y(){return 0}get z(){return this.body.z}spawn(e){gD(this.body,e);}steer(e,t,n){ED(this.body,e,t,n);}step(){this.locomotion.step(this.body);}place(e,t,n){this.body.x=e,this.body.z=n;}},xD=(i,e)=>new pR(i,e);function $We(i){return i===ri.WebTransport||i===ri.WebSocket}function Kie(i,e){return !i||e-i.at>Cie?null:i.transport}var mR=class{constructor(){this.entries=new Map;}recall(e,t){return Kie(this.entries.get(e),t)}remember(e,t,n){this.entries.set(e,{transport:t,at:n});}},Y_=class{constructor(){this.fallback=new mR;}recall(e,t){try{let n=globalThis.localStorage?.getItem(lD+e);if(!n)return this.fallback.recall(e,t);let r=JSON.parse(n);if(typeof r!="object"||r===null)return null;let o=r;return !$We(o.transport)||typeof o.at!="number"?null:Kie({transport:o.transport,at:o.at},t)}catch{return this.fallback.recall(e,t)}}remember(e,t,n){this.fallback.remember(e,t,n);try{globalThis.localStorage?.setItem(lD+e,JSON.stringify({transport:t,at:n}));}catch{return}}};function vD(){let e=globalThis.navigator?.connection;return e?.type??e?.effectiveType??Nie}function Yie(i){return i===Ji.Faster?Ji.Faster:i===Ji.Slower?Ji.Slower:Ji.Steady}var fR=class{constructor(){this.nominalMs=0;this.intervalMs=0;this.nextAt=0;this.lastAt=0;this.current=Ji.Steady;this.tick=0;this.changes=0;}start(e,t,n){this.nominalMs=H_/e,this.intervalMs=this.nominalMs,this.current=Ji.Steady,this.tick=t,this.lastAt=n,this.nextAt=n+this.intervalMs;}get pace(){return this.current}get interval(){return this.intervalMs}steer(e){e!==this.current&&(this.current=e,this.changes+=1,this.intervalMs=e===Ji.Faster?this.nominalMs*pie:e===Ji.Slower?this.nominalMs*mie:this.nominalMs);}due(e){if(e<this.nextAt)return 0;let t=0;for(;e>=this.nextAt&&t<fie;)this.lastAt=this.nextAt,this.nextAt+=this.intervalMs,t+=1;return e>=this.nextAt&&(this.lastAt=e,this.nextAt=e+this.intervalMs),t}subtick(e){let t=(e-this.lastAt)/this.intervalMs,n=Math.floor(t*nD);return n<0?0:n>rD?rD:n}};var _R=class{constructor(e){this.xs=new Int32Array(qt);this.zs=new Int32Array(qt);this.predicted=new Float64Array(qt).fill(-1);this.settled=false;this.offsetX=0;this.offsetZ=0;this.stats={corrections:0,maxUnits:0,totalUnits:0};this.motion=e;}get x(){return this.motion.x}get z(){return this.motion.z}get renderX(){return this.motion.x+this.offsetX}get renderZ(){return this.motion.z+this.offsetZ}begin(e,t){this.motion.spawn(e),this.predicted.fill(-1),this.remember(t),this.settled=false,this.offsetX=0,this.offsetZ=0;}predict(e,t){this.apply(e,t),this.remember(e);}reconcile(e,t,n,r,o){let s=e%qt;if(this.predicted[s]!==e)return false;let a=t-this.xs[s],l=r-this.zs[s],c=this.motion.toleranceUnits;if(Math.abs(a)<=c&&Math.abs(l)<=c)return this.settled=true,true;let u=this.motion,d=u.x+this.offsetX,h=u.z+this.offsetZ;u.place(t,n,r),this.remember(e);for(let p=e+1;p<=o.latest;p++)this.predict(p,o);if(this.settled){let p=Math.hypot(a,l);this.stats.corrections+=1,this.stats.totalUnits+=p,p>this.stats.maxUnits&&(this.stats.maxUnits=p),this.offsetX=d-u.x,this.offsetZ=h-u.z;}return this.settled=true,true}decay(e){if(this.offsetX===0&&this.offsetZ===0)return;let t=Math.exp(-e/Sie);this.offsetX*=t,this.offsetZ*=t,Math.abs(this.offsetX)<aD&&Math.abs(this.offsetZ)<aD&&(this.offsetX=0,this.offsetZ=0);}apply(e,t){let n=this.motion;n.steer(t.axisXOf(e),t.axisZOf(e),t.buttonsOf(e)),n.step();}remember(e){let t=e%qt;this.xs[t]=this.motion.x,this.zs[t]=this.motion.z,this.predicted[t]=e;}};var yR=class{constructor(){this.stride=1;this.shed=0;this.skipped=0;this.calmSince=0;}get pressured(){return this.stride>1}pressure(e){this.stride=Math.min(this.stride*2,Mie),this.calmSince=e;}recover(e){this.stride===1||e-this.calmSince<Die||(this.stride>>=1,this.calmSince=e,this.stride===1&&(this.skipped=0));}admit(){return this.stride===1?true:(this.skipped+=1,this.skipped<this.stride?(this.shed+=1,false):(this.skipped=0,true))}force(){return this.skipped=0,true}reset(){this.stride=1,this.skipped=0,this.calmSince=0;}};var X_=class{constructor(e){this.buffer=e,this.view=new DataView(e.buffer,e.byteOffset,e.byteLength),this.views=Array.from({length:e.length+1});}of(e){let t=this.views[e];if(t)return t;let n=this.buffer.subarray(0,e);return this.views[e]=n,n}};var Zc={Stored:0,Duplicate:1,MissingBaseline:2,Malformed:3},jWe=Oi.presence_delta.entry_full,JWe=Oi.presence_delta.entry_animation,ZWe=Oi.presence_delta.entry_flags,jc=-1,to=-1,Jc=ta*hn;function q_(i,e){let t=(i-e+ji)%ji;return t!==0&&t<ji/2}var AR=class{constructor(){this.present=new Uint8Array(Jc);this.x=new Uint16Array(Jc);this.y=new Int16Array(Jc);this.z=new Uint16Array(Jc);this.yaw=new Uint16Array(Jc);this.animation=new Uint8Array(Jc);this.flags=new Uint8Array(Jc);this.ticks=new Float64Array(ta).fill(jc);this.seen=new Float64Array(oR).fill(jc);this.header={flags:0,server_tick:0,cell_index:0,acked_input:0,layer:0,baseline_age:0,count:0,entries_offset:0,end:0};this.entry={slot:0,x:0,y:0,z:0,yaw:0,animation:0,flags:0};this.delta={slot:0,mask:0,x:0,y:0,z:0,yaw:0,animation:0,flags:0};this.next=0;this.latestRow=to;this.lastKeyframe=false;}reset(){this.ticks.fill(jc),this.seen.fill(jc),this.present.fill(0),this.next=0,this.latestRow=to;}get hasLatest(){return this.latestRow!==to}get latestTick(){return this.latestRow===to?jc:this.ticks[this.latestRow]}get latest(){return this.latestRow}tickOf(e){return this.ticks[e]}row(e){for(let t=0;t<ta;t++)if(this.ticks[t]===e)return t;return to}rowByShortTick(e){let t=to;for(let n=0;n<ta;n++){let r=this.ticks[n];r===jc||(r&V_)!==e||(t===to||q_(r,this.ticks[t]))&&(t=n);}return t}received(e){return this.seen[e%oR]===e}decode(e,t,n){let r=this.header,o=vl(e,t,n)===Gt.presence_delta;if((o?Wre(e,t,n,r):nR(e,t,n,r))<0)return Zc.Malformed;let a=r.server_tick;if(this.row(a)!==to)return Zc.Duplicate;let l=(r.flags&Bie)!==0,c=this.next,u=c*hn;if(l)this.present.fill(0,u,u+hn);else {let d=this.row((a-r.baseline_age+ji)%ji);if(d===to)return Zc.MissingBaseline;d!==c&&this.copyRow(d*hn,u);}return o?this.applyDelta(e,u):this.applyFull(e,u),this.ticks[c]=a,this.seen[a%oR]=a,this.next=(c+1)%ta,this.lastKeyframe=l,this.latestRow=this.newestRow(),Zc.Stored}applyFull(e,t){let n=this.header,r=this.entry;for(let o=0;o<n.count;o++){if(Vre(e,n,o,r),r.slot>=hn)continue;let s=t+r.slot;this.present[s]=1,this.x[s]=r.x,this.y[s]=r.y,this.z[s]=r.z,this.yaw[s]=r.yaw,this.animation[s]=r.animation,this.flags[s]=r.flags;}}applyDelta(e,t){let n=this.header,r=this.delta,o=n.entries_offset;for(let s=0;s<n.count;s++){if(o=Y3(e,o,n.end,r),o<0)return;if(r.slot>=hn)continue;let a=t+r.slot;if(this.present[a]=1,(r.mask&jWe)!==0){this.x[a]=r.x,this.y[a]=r.y,this.z[a]=r.z,this.yaw[a]=r.yaw,this.animation[a]=r.animation,this.flags[a]=r.flags;continue}this.x[a]+=r.x,this.y[a]+=r.y,this.z[a]+=r.z,this.yaw[a]+=r.yaw,(r.mask&JWe)!==0&&(this.animation[a]=r.animation),(r.mask&ZWe)!==0&&(this.flags[a]=r.flags);}}newestRow(){let e=to;for(let t=0;t<ta;t++)this.ticks[t]!==jc&&(e===to||q_(this.ticks[t],this.ticks[e]))&&(e=t);return e}get decodedRow(){return (this.next+ta-1)%ta}copyRow(e,t){let n=e+hn;this.present.copyWithin(t,e,n),this.x.copyWithin(t,e,n),this.y.copyWithin(t,e,n),this.z.copyWithin(t,e,n),this.yaw.copyWithin(t,e,n),this.animation.copyWithin(t,e,n),this.flags.copyWithin(t,e,n);}};var ir={Idle:0,Ticketing:1,Connecting:2,Joined:3,Waiting:4,Refused:5,Closed:6},zie=an.game_channel_slots,Qie=an.game_channel_reliable_base,ts=-1,e5e=65536,Xie=Oi.room_input.command,qie=et.room_input.header_bytes,t5e=et.channel.header_bytes,RD=true,n5e=[eo.Full,eo.Overloaded,eo.Unavailable],z_=class{constructor(e){this.queue=new uR;this.outbound=Array.from({length:eD},()=>new X_(new Uint8Array(Uh)));this.reply=fD();this.ack={slot:0,sequence:0,received_mask:0};this.streamAcks=[];this.clock=new lR;this.ticker=new fR;this.governor=new yR;this.seenSendFailures=0;this.leadBoost=0;this.log=new dR;this.store=new AR;this.tracks=new hR;this.units={x:0,y:0,z:0,yaw:0,animation:0};this.appliedShort=new Int32Array(G_).fill(ts);this.appliedSequence=new Float64Array(G_);this.remoteSlots=new Uint16Array(hn);this.roomInput={flags:Xie,action:0,sequence:0,client_tick:0,sender:0};this.channelHeader={flags:0,slot:0,sequence:0,sender:0};this.channelMessage={flags:0,slot:0,sequence:0,sender:0,payload_offset:0,payload_length:0};this.channelSequence=0;this.statistics={slot:rR,transport:null,corrections:0,maxCorrectionM:0,meanCorrectionM:0,inputsSent:0,snapshots:0,deltas:0,keyframes:0,missingBaselines:0,rttMs:0,interpolationDelayMs:0,extrapolatingFrames:0,paceChanges:0,reconnects:0,dropped:0,sendFailures:0,sendStride:1,statesShed:0};this.predictor=null;this.predictorRates=0;this.link=null;this.stateValue=ir.Idle;this.pendingTicket=null;this.ticketFailed=false;this.resumeToken=null;this.joinVersion=Fh;this.request=null;this.admittedAt=0;this.dialStartedAt=0;this.retryAt=0;this.lastUpdate=0;this.outboundNext=0;this.appliedNext=0;this.remoteCountValue=0;this.joins=0;this.slotValue=rR;this.watcher=true;this.started=false;this.freshSnapshot=false;this.lastReconciled=ts;this.extrapolating=false;this.ownTick=ts;this.ownX=0;this.ownY=0;this.ownZ=0;this.ownVelocityX=0;this.ownVelocityZ=0;this.inputAxisX=0;this.inputAxisZ=0;this.inputYaw=0;this.inputButtons=0;this.inputSubtick=0;this.commandSequence=0;this.cameraSequence=0;this.cameraX=0;this.cameraZ=0;this.cameraRadius=0;this.cameraDirty=false;this.cameraSentAt=Number.NEGATIVE_INFINITY;this.unackedSnapshots=0;this.ticketArrived=e=>{this.pendingTicket=e;};this.ticketRefused=()=>{this.ticketFailed=true;};this.tickets=e.tickets,this.spectatorAckEvery=Math.max(1,Math.floor(e.spectatorAckEvery??lie)),this.physicsHz=e.physicsHz??0,this.channelSink=e.channels??null,this.motionFactory=e.motion??xD,this.connector=new W_(e.primary??null,e.fallback??null,e.memory??new Y_,e.network??vD);}get state(){return this.stateValue}get slot(){return this.slotValue}ackStream(e,t){this.streamAcks.push({slot:e,sequence:t});}get watching(){return this.watcher}get extrapolatingLocal(){return this.extrapolating}get serverTick(){return this.store.latestTick}get remoteCount(){return this.remoteCountValue}remoteSlot(e){return this.remoteSlots[e]}get stats(){let e=this.statistics,t=this.predictor?.stats;return e.slot=this.slotValue,e.transport=this.link?.transport??null,e.corrections=t?.corrections??0,e.maxCorrectionM=Xc(t?.maxUnits??0),e.meanCorrectionM=t&&t.corrections>0?Xc(t.totalUnits/t.corrections):0,e.rttMs=this.clock.rttMs,e.interpolationDelayMs=this.clock.interpolationDelayMs,e.paceChanges=this.ticker.changes,e.dropped=this.queue.dropped,e.sendFailures=this.queue.sendFailures,e.sendStride=this.governor.stride,e.statesShed=this.governor.shed,e}start(e){this.stateValue===ir.Idle&&(this.lastUpdate=e,this.fetchTicket());}close(){this.connector.cancel(),this.link?.close(),this.link=null,this.stateValue=ir.Closed;}setInput(e,t,n,r,o){this.inputAxisX=Q3(e),this.inputAxisZ=Q3(t),this.inputYaw=$re(n),this.inputButtons=r,this.inputSubtick=this.ticker.subtick(o);}setCamera(e,t,n){this.cameraX=j3(e),this.cameraZ=j3(t),this.cameraRadius=Math.max(0,Math.min(Math.round(n),V_)),this.cameraSequence+=1,this.cameraDirty=true;}sendCommand(e,t,n){let r=this.link;if(!r||this.watcher||this.stateValue!==ir.Joined)return -1;let o=this.packet(),s=this.roomInput;s.flags=Xie,s.action=e,s.sequence=(this.commandSequence+1)%ji,s.client_tick=this.ticker.tick>>>0;let a=U_(o.view,0,s,n);if(a<0)return a;let l=o.buffer;for(let c=0;c<n;c++)l[qie+c]=t[c];return this.commandSequence=s.sequence,r.send(Rl.Reliable,o.of(a)),s.sequence}sendChannel(e,t,n){let r=this.link;if(!r||this.watcher||this.stateValue!==ir.Joined||e<0||e>=zie)return -1;let o=this.packet(),s=this.channelHeader;s.slot=e,s.sequence=(this.channelSequence+1)%ji;let a=Zv(o.view,0,s,n);if(a<0)return a;let l=o.buffer;for(let c=0;c<n;c++)l[t5e+c]=t[c];return this.channelSequence=s.sequence,r.send(e<Qie?Rl.Datagram:Rl.Reliable,o.of(a)),s.sequence}update(e){let t=e-this.lastUpdate;switch(this.lastUpdate=e,this.stateValue){case ir.Ticketing:this.dial(e);break;case ir.Connecting:this.connecting(e);break;case ir.Waiting:e>=this.retryAt&&this.fetchTicket();break;}if(this.stateValue===ir.Joined){if(this.drain(e),this.queue.lost){this.reconnect(e);return}this.govern(e),this.play(e),this.predictor?.decay(t),this.watchLatency();}}localPose(e,t){let n=this.predictor;if(!n||!this.started)return false;let r=n.renderX,o=n.renderZ;if(this.extrapolating&&this.ownTick!==ts){let s=this.clock.serverTick(t)+this.clock.leadTicks(),a=Math.max(0,Math.min(s-this.ownTick,this.capTicks()));r=this.ownX+this.ownVelocityX*a,o=this.ownZ+this.ownVelocityZ*a;}return e.x=Xc(r),e.y=J3(this.ownY),e.z=Xc(o),e.yaw=$3(this.inputYaw),e.animation=0,true}presence(e,t){let n=this.store,r=n.latest;if(e<0||e>=hn||!n.hasLatest)return false;let o=r*hn+e;return n.present[o]===0?false:(t.tick=n.tickOf(r),t.x=n.x[o],t.y=n.y[o],t.z=n.z[o],t.yaw=n.yaw[o],t.animation=n.animation[o],t.flags=n.flags[o],true)}remotePose(e,t,n){if(e>=hn)return false;let r=this.units;return this.tracks.sample(e,this.clock.renderTick(n),this.capTicks(),r)===Qc.None?false:(t.x=Xc(r.x),t.y=J3(r.y),t.z=Xc(r.z),t.yaw=$3(r.yaw),t.animation=r.animation,true)}capTicks(){return xie/this.clock.tickIntervalMs}fetchTicket(){this.stateValue=ir.Ticketing,this.pendingTicket=null,this.ticketFailed=false,this.tickets().then(this.ticketArrived,this.ticketRefused);}dial(e){if(this.ticketFailed){this.waitAndRetry(e);return}let t=this.pendingTicket;t&&(this.pendingTicket=null,this.begin(_D(t,this.joinVersion),e));}begin(e,t){this.request=e,this.queue.clear(),this.dialStartedAt=t,this.stateValue=ir.Connecting,this.connector.begin(e,this.queue,t);}connecting(e){let t=this.connector.poll(e);if(t===Qr.Failed){this.waitAndRetry(e);return}if(t!==Qr.Won)return;let n=this.connector.release();if(!n||!AD(n.reply,this.reply)){n?.link.close(),this.waitAndRetry(e);return}let r=this.reply.status;if(r===eo.Admitted){this.joined(n.link,e);return}n.link.close();let o=this.request;if(r===eo.Malformed&&o!==null&&Vie(o)){this.joinVersion=B_,this.begin(o,e);return}r===eo.UnknownResume||r===eo.Expired?(this.resumeToken=null,this.fetchTicket()):n5e.indexOf(r)>=0?this.waitAndRetry(e):this.stateValue=ir.Refused;}waitAndRetry(e){this.stateValue=ir.Waiting,this.retryAt=e+Iie;}reconnect(e){this.link?.close(),this.link=null;let t=this.resumeToken;if(t&&e-this.admittedAt<Oie){this.resumeToken=null,this.begin(yD(t,this.joinVersion),e);return}this.resumeToken=null,this.fetchTicket();}joined(e,t){let n=this.reply;this.link=e,this.stateValue=ir.Joined,this.admittedAt=t,this.resumeToken=n.resume.slice(),this.slotValue=n.slot,this.watcher=n.slot===rR,this.joins>0&&(this.statistics.reconnects+=1),this.joins+=1,this.clock.configure(n.simulationHz,n.sendHz,t-this.dialStartedAt);let r=this.physicsHz>0?this.physicsHz:n.simulationHz*_ie,o=n.simulationHz*e5e+r;(!this.predictor||this.predictorRates!==o)&&(this.predictor=new _R(this.motionFactory(n.simulationHz,r)),this.predictorRates=o),this.store.reset(),this.tracks.reset(),this.appliedShort.fill(ts),this.remoteCountValue=0,this.lastReconciled=ts,this.ownTick=ts,this.started=false,this.freshSnapshot=false,this.extrapolating=false,this.cameraDirty=this.cameraSequence>0,this.governor.reset(),this.seenSendFailures=this.queue.sendFailures,this.leadBoost=0;}govern(e){let t=this.queue.sendFailures;if(t===this.seenSendFailures){this.governor.recover(e);return}this.seenSendFailures=t,this.governor.pressure(e);}drain(e){let t=this.queue;for(;t.next();){let n=t.view,r=t.length,o=0;for(;o<r;){let s=Jv(n,o,r);if(s<=0)break;let a=vl(n,o,r);a===Gt.presence_tick||a===Gt.presence_delta?this.snapshot(n,o,o+s,e):a===Gt.ack&&Kre(n,o,o+s,this.ack)>0?this.acknowledged(e):a===Gt.channel&&this.channel(n,o,o+s),o+=s;}}}channel(e,t,n){let r=this.channelSink;if(r===null)return;let o=this.channelMessage;eR(e,t,n,o)<0||r.deliver(o.slot,o.sender,e,o.payload_offset,o.payload_length);}snapshot(e,t,n,r){let o=this.store,s=o.decode(e,t,n);if(s===Zc.MissingBaseline){this.statistics.missingBaselines+=1;return}if(s!==Zc.Stored)return;let a=this.statistics;a.snapshots+=1,o.lastKeyframe?a.keyframes+=1:a.deltas+=1;let l=o.decodedRow,c=o.tickOf(l);this.clock.snapshot(c,r),this.freshSnapshot=true;let u=l===o.latest,d=l*hn;u&&(this.remoteCountValue=0);for(let p=0;p<hn;p++){let m=d+p;if(o.present[m]!==0){if(p===this.slotValue){this.observeOwn(c,o.x[m],o.y[m],o.z[m]);continue}this.tracks.push(p,c,o.x[m],o.y[m],o.z[m],o.yaw[m],o.animation[m]),u&&(this.remoteSlots[this.remoteCountValue++]=p);}}let h=c&V_;for(let p=0;p<G_;p++)this.appliedShort[p]===h&&this.reconcile(this.appliedSequence[p],l);}observeOwn(e,t,n,r){if(!(this.ownTick!==ts&&!q_(e,this.ownTick))){if(this.ownTick!==ts){let o=e-this.ownTick;this.ownVelocityX=(t-this.ownX)/o,this.ownVelocityZ=(r-this.ownZ)/o;}this.ownTick=e,this.ownX=t,this.ownY=n,this.ownZ=r;}}acknowledged(e){let t=this.ack;switch(t.slot){case Jre:this.applied(t.sequence,t.received_mask,e);return;case Zre:this.log.persist(t.sequence);return;case eie:t.sequence>this.commandSequence&&(this.commandSequence=t.sequence);return;default:return}}applied(e,t,n){let r=t&iD,o=Yie(t>>>die&iD),s=t>>>hie;if(this.watcher)return;this.started?this.log.acknowledge(e)&&this.clock.roundTrip(n-this.log.sentAtOf(e)-r*this.clock.tickIntervalMs):this.beginSession(e,n),this.ticker.steer(o),this.appliedShort[this.appliedNext]=s,this.appliedSequence[this.appliedNext]=e,this.appliedNext=(this.appliedNext+1)%G_;let a=this.store.rowByShortTick(s);a>=0&&this.reconcile(e,a);}beginSession(e,t){let n=this.log;n.latest>e&&n.holds(e+1)?n.rebase(e):(n.reset(e),this.predictor?.begin(this.slotValue,e));let o=Math.ceil(this.clock.leadTicks())+uie;this.ticker.start(this.reply.simulationHz,this.reply.tick+o,t),this.started=true;}reconcile(e,t){let n=this.predictor;if(!n||!this.started)return;let r=this.store,o=r.tickOf(t);if(this.lastReconciled!==ts&&!q_(o,this.lastReconciled))return;let s=t*hn+this.slotValue;r.present[s]!==0&&n.reconcile(e,r.x[s],r.y[s],r.z[s],this.log)&&(this.lastReconciled=o);}play(e){if(this.watcher){this.freshSnapshot&&(this.unackedSnapshots+=1),(this.unackedSnapshots>=this.spectatorAckEvery||this.cameraDue(e))&&(this.unackedSnapshots=0,this.governor.admit()&&this.send(e)),this.freshSnapshot=false;return}if(!this.started)return;let t=this.predictor;if(!t)return;let n=this.leadDebt(),r=this.ticker.due(e)+n,o=this.governor.pressured;for(let s=0;s<r;s++){let a=this.log.push(this.inputAxisX,this.inputAxisZ,this.inputYaw,this.inputButtons,this.ticker.tick,this.inputSubtick);this.ticker.tick+=1,this.inputSubtick=0,t.predict(a,this.log),this.statistics.inputsSent+=1,o||this.send(e);}o&&r>0&&(n>0?this.governor.force():this.governor.admit())&&this.send(e),this.freshSnapshot=false;}leadDebt(){let e=this.governor.stride-1;if(e<=this.leadBoost)return this.leadBoost=e,0;let t=e-this.leadBoost;return this.leadBoost=e,t}cameraDue(e){return this.cameraSequence>0&&(this.cameraDirty||e-this.cameraSentAt>=Lie)}packet(){let e=this.outbound[this.outboundNext];return this.outboundNext=(this.outboundNext+1)%eD,e}send(e){let t=this.link;if(!t)return;let n=this.packet(),r=n.view,o=this.watcher?0:this.log.write(r,0,e);if(this.watcher&&this.cameraDue(e)&&(o+=this.writeCamera(r,o,e)),this.store.hasLatest){let s=this.ack;s.slot=jre,s.sequence=this.store.latestTick,s.received_mask=this.receivedMask(s.sequence);let a=X3(r,o,s);a>0&&(o+=a);}for(let s=0;s<this.streamAcks.length;s++){let a=this.streamAcks[s],l=a.sequence();if(l<0)continue;let c=this.ack;c.slot=a.slot,c.sequence=l>>>0,c.received_mask=0;let u=X3(r,o,c);u>0&&(o+=u);}o>0&&t.send(Rl.Datagram,n.of(o));}writeCamera(e,t,n){let r=this.roomInput;r.flags=0,r.action=tie,r.sequence=this.cameraSequence,r.client_tick=0;let o=U_(e,t,r,kie);if(o<0)return 0;let s=t+qie;return e.setUint16(s,this.cameraX,RD),e.setUint16(s+2,this.cameraZ,RD),e.setUint16(s+4,this.cameraRadius,RD),this.cameraDirty=false,this.cameraSentAt=n,o}receivedMask(e){let t=this.reply.simulationHz,n=this.reply.sendHz,r=0,o=e;for(let s=0;s<aie&&(o=jie(o,t,n),!(o<0));s++)this.store.received(o)&&(r=(r|1<<s)>>>0);return r}watchLatency(){let e=this.clock.rttMs;!this.extrapolating&&e>vie?this.extrapolating=true:this.extrapolating&&e<Rie&&(this.extrapolating=false),this.extrapolating&&(this.statistics.extrapolatingFrames+=1);}};function $ie(i,e,t){return Math.floor(i*t/e)!==Math.floor((i-1)*t/e)}function jie(i,e,t){for(let n=i-1;n>0;n--)if($ie(n,e,t))return n;return -1}var Q_=0,bR=1,Zie=2,eoe=3,s5e=4,a5e=8,toe=8,eu=32,noe=256,roe=new Float32Array(1),l5e=new Uint32Array(roe.buffer),no=new Float64Array(1),Jie=new Uint32Array(no.buffer);function c5e(i){if(typeof i!="string"){if(i.bits<1||i.bits>32||!(i.max>i.min))throw new _("invalid_argument","quantized fields need 1..32 bits and max > min");return {kind:s5e,bits:i.bits}}switch(i){case "bool":return {kind:Q_,bits:1};case "u8":return {kind:Q_,bits:8};case "u16":return {kind:Q_,bits:16};case "u32":return {kind:Q_,bits:32};case "i8":return {kind:bR,bits:8};case "i16":return {kind:bR,bits:16};case "i32":return {kind:bR,bits:32};case "f32":return {kind:Zie,bits:32};case "f64":return {kind:eoe,bits:64}}}var gR=class{constructor(e,t,n){this.names=new Map;if(e<0||e>=noe)throw new _("invalid_argument","message id out of range");this.id=e,this.name=t;let r=Object.keys(n);this.fieldKind=new Uint8Array(r.length),this.fieldBits=new Uint8Array(r.length),this.fieldOffset=new Uint32Array(r.length),this.fieldMin=new Float64Array(r.length),this.fieldScale=new Float64Array(r.length),this.fieldMax=new Float64Array(r.length);let o=a5e;for(let s=0;s<r.length;s++){let a=n[r[s]],{kind:l,bits:c}=c5e(a);if(this.fieldKind[s]=l,this.fieldBits[s]=c,this.fieldOffset[s]=o,typeof a!="string"){let u=Math.pow(2,a.bits)-1;this.fieldMin[s]=a.min,this.fieldMax[s]=u,this.fieldScale[s]=u/(a.max-a.min);}this.names.set(r[s],s),o+=c;}this.bytes=Math.ceil(o/toe);}field(e){let t=this.names.get(e);if(t===void 0)throw new _("invalid_argument",`message ${this.name} has no field ${e}`);return t}},tu=new Uint32Array(1);function Gh(i,e,t,n){let r=0,o=0,s=t;for(;o<n;){let a=e+(s>>>3),l=s&7,c=Math.min(toe-l,n-o),u=i[a]>>>l&(1<<c)-1;r|=u<<o,o+=c,s+=c;}tu[0]=r;}var ER=class{constructor(e){this.bytes=new Uint8Array(0);this.base=0;this.size=0;this.type=null;this.types=e;}get messageType(){return this.type}get length(){return this.size}bind(e,t,n){this.bytes=e,this.base=t,this.size=n;let r=n>0?this.types[e[t]]:null;return this.type=r&&r.bytes<=n?r:null,this.type!==null}is(e){return this.type===e}get(e){return this.decode(e),no[0]}getInto(e,t,n){this.decode(e),t[n]=no[0];}getBool(e){return this.decode(e),no[0]!==0}getVec3(e,t,n,r){return this.decode(e),r.x=no[0],this.decode(t),r.y=no[0],this.decode(n),r.z=no[0],r}decode(e){let t=this.type,n=t.fieldOffset[e],r=t.fieldBits[e];switch(t.fieldKind[e]){case Q_:Gh(this.bytes,this.base,n,r),no[0]=tu[0];return;case bR:{Gh(this.bytes,this.base,n,r);let o=tu[0]|0;no[0]=r===eu?o:o<<eu-r>>eu-r;return}case Zie:Gh(this.bytes,this.base,n,eu),l5e[0]=tu[0],no[0]=roe[0];return;case eoe:Gh(this.bytes,this.base,n,eu),Jie[0]=tu[0],Gh(this.bytes,this.base,n+eu,eu),Jie[1]=tu[0];return;default:Gh(this.bytes,this.base,n,r),no[0]=tu[0]/t.fieldScale[e]+t.fieldMin[e];}}};var ioe=noe;var SD=class{constructor(e,t,n){this.transport=e,this.name=t,this.delivery=n,this.id=e.open(t,n);}send(e){if(e.length===0)throw new _("invalid_argument","writer holds no message");this.transport.send(this.id,e.buffer,e.length);}receive(e){return this.transport.receive(this.id,e)}},xR=class{constructor(){this.types=Array.from({length:ioe},()=>null);this.typeCount=0;this.transport=null;this.joinedRoom=null;}joinRoom(e,t){this.joinedRoom?.close();let n=new z_(e);return n.start(t),this.joinedRoom=n,n}get room(){return this.joinedRoom}defineMessage(e,t){let n=new gR(this.typeCount,e,t);return this.types[this.typeCount++]=n,n}reader(){return new ER(this.types)}connect(e){this.transport=e;}get connected(){return this.transport!==null}get participant(){return this.requireTransport().participant}channel(e,t){return new SD(this.requireTransport(),e,t)}disconnect(){this.transport?.close(),this.transport=null,this.joinedRoom?.close(),this.joinedRoom=null;}requireTransport(){if(!this.transport)throw new _("not_initialized","no room transport is connected");return this.transport}};var ty=9.81,RR=Math.fround(Math.PI/2),u5e=3,d5e=.45,ooe=.6,h5e=.025,coe=.02,p5e=.008,m5e=.35,CR=.05,soe=1.05,aoe=.3,f5e=.15,uoe=[0,0,1],doe=[0,1,0],_5e=[-1,0,0],y5e=[1,0,0],hoe=[1,0,0];function Tl(i,e){return {halfExtents:i,mass:e}}function vR(i,e,t,n){return {halfExtents:i,mass:e,wing:t,wingMass:e*n}}var OD={canoe:Tl([.4,.25,2.5],160),speedboat:Tl([1.1,.5,3],1500),ferry:Tl([5,2,20],3e5),cargo_ship:Tl([12.5,6,75],12e6),sailboat:Tl([1.3,.7,4],3e3),light_plane:vR([.6,.7,3.5],1e3,[5.5,.08,.75],.3),jet:vR([1,1,7],9e3,[6,.1,1.7],.3),glider:vR([.4,.5,3.5],350,[8.5,.05,.45],.4),helicopter:Tl([.8,.9,2.2],1200),quadcopter:Tl([.15,.05,.15],1.5),tiltrotor:vR([.8,.8,4],6e3,[4,.1,1],.3),blimp:Tl([3,3,15],2e3)};function $_(i,e,t,n,r){return {kind:"boat",length:i,beam:e,depth:t,bow:n,resolution:r}}function j_(i,e,t,n={}){return {position:i,chord:uoe,normal:_5e,area:e,curve:t,...n}}function ID(i,e,t,n={}){return {position:i,chord:uoe,normal:doe,area:e,curve:t,...n}}function CD(i,e,t,n){return j_([0,e,i],t,{kind:"analytic",slope:u5e,stall:d5e,cd0:0,induced:.1},{deflection:Yt(1,-ooe),maxDeflection:ooe,rate:n})}function ND(i,e,t,n,r){return {position:i,maxThrust:e,reverse:t,maxSpeed:n,spoolRate:r,medium:"water",throttle:Yt(0,1)}}function A5e(){return {hull:$_(5,.8,.5,.8,[3,3,12]),hydro:{drag:[1.2,2,.06],linearDrag:[1,7,.3],angularDrag:60,righting:1500},thrusters:[ND([0,-0.22,-1.2],320,.6,3.5,3)],foils:[CD(-2.2,-0.24,.08,4)]}}function b5e(){return {hull:$_(6,2.2,1,.7,[4,3,12]),hydro:{drag:[1,2,.1],linearDrag:[1,8.5,.2],angularDrag:900,righting:0},planing:{speed:6,lift:40,dragFactor:.35,position:[0,-0.4,-0.6]},thrusters:[{...ND([0,-0.45,-3],12e3,.4,25,2),vector:{axis:doe,angle:Yt(1,.5),maxAngle:.5,rate:3}}]}}function loe(i,e,t,n,r,o,s,a,l,c){return {hull:i,hydro:{drag:e,linearDrag:t,angularDrag:n,righting:0},thrusters:[ND(r,o,.5,s,l)],foils:[CD(a[2],a[1],a[0],c)]}}function g5e(){return {hull:$_(8,2.6,1.4,.8,[4,3,12]),hydro:{drag:[2.5,2,.05],linearDrag:[1,10,.2],angularDrag:2e3,righting:45e3},foils:[CD(-3.8,-0.6,.6,2),j_([0,-1.6,0],1.6,{kind:"analytic",slope:5,stall:.3,cd0:0,induced:0}),j_([0,5,.3],30,{kind:"analytic",slope:5,stall:.35,cd0:.05,induced:.1},{deflection:Yt(2,1.4),maxDeflection:1.4,rate:.6,leeward:true})]}}var NR={engine:[0,0,3],thrust:3200,spool:1.5,propSpeed:75,wingX:2.75,wingArea:16,wingSpan:11,stall:.27,cd0:h5e,zeroLift:-0.05,tailZ:-4.5,tailArea:3,tailSpan:3.4,finArea:1.5,finSpan:1.5,aileron:.3,elevator:.4,rudder:.4,gear:[1.8,-0.4,1.2,-0.6]},E5e={...NR,engine:[0,0,-6],thrust:6e4,spool:.6,propSpeed:0,wingX:3,wingArea:40,wingSpan:12,stall:.3,zeroLift:-0.02,tailZ:-7,tailArea:8,tailSpan:5,finArea:5,finSpan:3,aileron:.35,elevator:.35,rudder:.35,gear:[4,-0.8,1.6,-1]},x5e={...NR,engine:[0,0,0],thrust:0,spool:1,propSpeed:0,wingX:4.25,wingArea:15,wingSpan:17,stall:.22,cd0:p5e,zeroLift:-0.06,tailZ:-5,tailArea:1.5,tailSpan:3,finArea:1,finSpan:1.2,gear:[1.5,-0.3,.5,-0.5]};function TD(i,e,t,n){let r=e*12;return {position:i,restLength:.4,radius:.25,spring:{stiffness:r,dampingCompression:r*.12,dampingRelaxation:r*.08,maxForce:e*8},steer:t,brake:n,grip:.9,rolling:.02}}function poe(i,e){if(!e)return;let t=i*3;return {level:1,rateDamping:[t,t,t],autoLevel:t*2,stallGuard:1,coordination:.3,pitch:0,roll:1,yaw:2,lift:255}}function moe(i){let e={kind:"wing",aspect:i.wingSpan*i.wingSpan/i.wingArea,zeroLift:i.zeroLift,stall:i.stall,cd0:i.cd0},t=(r,o)=>ID([r,.3,0],i.wingArea*.5,e,{deflection:el(Yt(1,o),4,aoe),maxDeflection:i.aileron+aoe,effectiveness:.4,deflectionDrag:f5e,groundEffect:true}),n=(r,o)=>({kind:"wing",aspect:o*o/r,stall:m5e,cd0:coe});return [t(i.wingX,i.aileron),t(-i.wingX,-i.aileron),ID([0,.3,i.tailZ],i.tailArea,n(i.tailArea,i.tailSpan),{deflection:Yt(0,-i.elevator),maxDeflection:i.elevator,effectiveness:.5}),j_([0,.9,i.tailZ],i.finArea,n(i.finArea,i.finSpan),{deflection:Yt(2,-i.rudder),maxDeflection:i.rudder,effectiveness:.5})]}function wD(i,e,t){let n=i.mass*ty,[r,o,s,a]=e.gear;return {airDrag:[.8,1,.08],gear:{steer:Yt(2,1),brake:Yt(5,1),deploy:Yt(6,1),retractRate:0},assist:poe(i.mass,t),stall:e.stall,span:e.wingSpan,groundEffect:.3,probeOffset:i.halfExtents[1]+CR,thrusters:[{position:e.engine,maxThrust:e.thrust,throttle:Yt(3,1),spoolRate:e.spool,medium:"air",maxSpeed:e.propSpeed}],wheels:[TD([0,a,r],n*.2,.5,0),TD([s,a,o],n*.4,0,.6),TD([-s,a,o],n*.4,0,.6)],foils:moe(e)}}function foe(i,e,t,n){let r=i*ty,o=(s,a)=>({position:[s,n,a],restLength:.2,radius:.05,spring:{stiffness:r*15,dampingCompression:r*2,dampingRelaxation:r*1.2,maxForce:r*6},steer:0,brake:.8,grip:1,rolling:.3});return [o(e,t),o(-e,t),o(e,-t),o(-e,-t)]}function _oe(i,e,t){if(!e)return;let n=i*6;return {level:1,rateDamping:[n,n,n],autoLevel:n*2,hoverHold:t,pitch:1,roll:2,yaw:3,lift:0}}function v5e(i,e){let t=i.mass*ty*1.7,n=1500,r=.1*t/6/n;return {airDrag:[3,4,1],assist:_oe(i.mass,e,e?.05:0),span:10,probeOffset:i.halfExtents[1]+CR,rotors:[{position:[0,1.5,0],radius:5,maxThrust:t,collective:Yt(0,1),cyclicPitch:Yt(1,-1),cyclicRoll:Yt(2,-1),cyclicTilt:.15,hubStiffness:i.mass*10,torqueReaction:.1,power:Yt(4,1),governorRate:.5,rotorDrag:.3,autorotation:.06,inflow:.06,groundEffect:.25}],thrusters:[{position:[0,.5,-6],axis:y5e,maxThrust:n,reverse:1,medium:"air",throttle:el(Yt(3,.5),0,r)}],wheels:foe(i.mass,.9,1,-0.8)}}function R5e(i,e){let t=i.mass*ty*.5,n=[];for(let[o,s]of [[1,1],[-1,1],[-1,-1],[1,-1]]){let a=o*s>0?1:-1,l=el(el(el(Yt(0,1),1,-0.2*s),2,.2*o),3,-0.2*a);n.push({position:[o*.25,.05,s*.25],radius:.12,maxThrust:t,collective:l,torqueReaction:.02*a});}let r=_oe(i.mass,e,e?.1:0);return {airDrag:[.02,.04,.02],assist:r&&{...r,autoLevel:i.mass*3,rateDamping:[i.mass*.3,i.mass*.3,i.mass*.3]},probeOffset:i.halfExtents[1]+CR,rotors:n}}function S5e(i,e){let t=i.mass*ty*.8,n={axis:hoe,angle:Yt(7,RR),maxAngle:RR,rate:.3},r=poe(i.mass,e),o={...NR,wingX:2.5,wingArea:25,wingSpan:14,stall:.28,zeroLift:-0.04,tailZ:-5.5,tailArea:6,tailSpan:5,finArea:4,finSpan:2.5};return {airDrag:[1,1.5,.15],assist:r&&{...r,lift:3,hoverHold:.05},stall:.28,span:14,groundEffect:.3,probeOffset:i.halfExtents[1]+CR,rotors:[4.5,-4.5].map(s=>({position:[s,1,0],radius:3,maxThrust:t,collective:el(Yt(3,1),1,.15*Math.sign(s)),governorRate:.5,tilt:n})),foils:moe(o),wheels:foe(i.mass,1,2.5,-0.9)}}function T5e(i){let e={kind:"wing",aspect:2,stall:.35,cd0:coe},t=n=>({position:[n,-2.5,0],maxThrust:1500,throttle:el(Yt(0,1),1,.5*Math.sign(n)),medium:"air",spoolRate:.5,reverse:.5,vector:{axis:hoe,angle:Yt(2,-RR),maxAngle:RR,rate:.5}});return {airDrag:[40,40,8],gas:{volume:i.mass/soe*.99,netDensity:soe,center:[0,.5,0]},assist:{level:1,rateDamping:[i.mass*8,i.mass*8,i.mass*8],autoLevel:i.mass*40},thrusters:[t(3.5),t(-3.5)],foils:[ID([0,0,-13],12,e),j_([0,2,-13],10,e,{deflection:Yt(1,-0.5),maxDeflection:.5,rate:1})]}}function yoe(i,e){let t=OD[i];switch(i){case "canoe":return A5e();case "speedboat":return b5e();case "ferry":return loe($_(40,10,4,.6,[6,3,14]),[1,2,.06],[1,17,.2],4e6,[0,-1.8,-19],4e5,9,[8,-1.6,-19.5],.25,.5);case "cargo_ship":return loe($_(150,25,12,.5,[6,3,16]),[1,2,.05],[1,25,.2],6e8,[0,-5,-72],3e6,10,[40,-4.5,-74],.05,.1);case "sailboat":return g5e();case "light_plane":return wD(t,NR,e);case "jet":return wD(t,E5e,e);case "glider":return wD(t,x5e,e);case "helicopter":return v5e(t,e);case "quadcopter":return R5e(t,e);case "tiltrotor":return S5e(t,e);case "blimp":return T5e(t)}}function Aoe(i,e){let t=c=>c!==void 0&&c>0?c:1,n=t(e.thrust),r=t(e.drag),o=t(e.response),s=t(e.lift),a=(c,u)=>c&&[c[0]*u,c[1]*u,c[2]*u],l=c=>c&&{...c,rate:(c.rate??0)*o};return {...i,hydro:i.hydro&&{...i.hydro,drag:a(i.hydro.drag,r)},airDrag:a(i.airDrag,r),gas:i.gas&&{...i.gas,volume:i.gas.volume*s},foils:i.foils?.map(c=>({...c,area:c.area*s,rate:(c.rate??0)*o})),thrusters:i.thrusters?.map(c=>({...c,maxThrust:c.maxThrust*n,spoolRate:(c.spoolRate??0)*o,vector:l(c.vector)})),rotors:i.rotors?.map(c=>({...c,maxThrust:c.maxThrust*n,governorRate:(c.governorRate??0)*o,tilt:l(c.tilt)}))}}var MD=1,ny=72,MR=ny+1,DD=Go/ny,ro=5,k5e=.15,L5e=2,M5e=1,D5e=.8,goe=[0,0,1],Eoe=[0,1,0],P5e=1e-7,xoe=[1,.001,.002],F5e={any:0,water:1,air:2},kD={sin:0,cos:0};function U5e(i,e,t,n,r,o){let s=e*Math.min(Math.max(i,-t),t);yr(i,kD);let a=kD.sin,l=kD.cos,c=M5e*2*a*l,u=Math.min(Math.max((Math.abs(i)-t)/k5e,0),1),d=s+(c-s)*u,h=n+r*d*d,p=n+L5e*a*a;return o[0]=d,o[1]=h+(p-h)*u,o}function B5e(i,e){let t=[],n=[],r=new Float64Array(2);for(let o=0;o<MR;o++){let s=-Zd+DD*o;if(i.kind==="table"){t.push(rk(i.lift,s)),n.push(rk(i.drag,s));continue}let a=i.zeroLift??0,l=i.kind==="wing"?Go*i.aspect/(i.aspect+2):i.slope,c=i.kind==="wing"?1/(Zd*D5e*i.aspect):i.induced;U5e(tl(s-a),l,i.stall,i.cd0,c,r),t.push(r[0]),n.push(r[1]);}i.kind==="table"&&(ih(i.lift,64,"lift curve"),ih(i.drag,64,"drag curve")),e.push(...t,...n);}function ns(i,e,t=0){i.push(e?e.bias??0:t);for(let n=0;n<16;n++)i.push(e?.gains?.[n]??0);}function voe(i,e){i.push(...e?.axis??[1,0,0]),ns(i,e?.angle),i.push(e?.maxAngle??0,e?.rate??0);}function Roe(i,e){return [i[1]*e[2]-i[2]*e[1],i[2]*e[0]-i[0]*e[2],i[0]*e[1]-i[1]*e[0]]}function kR(i,e){return i[0]*e[0]+i[1]*e[1]+i[2]*e[2]}function LD(i,e){return [i[0]-e[0],i[1]-e[1],i[2]-e[2]]}function G5e(i,e,t,n){let r=LD(t,e),o=LD(n,e),s=Roe(xoe,o),a=kR(r,s);if(Math.abs(a)<P5e)return false;let l=1/a,c=LD(i,e),u=kR(c,s)*l;if(u<0||u>1)return false;let d=Roe(c,r),h=kR(xoe,d)*l;return h<0||u+h>1?false:kR(o,d)*l>0}function Soe(i){if(i.some(e=>!Number.isInteger(e)||e<=0||e>16))throw new _("invalid_argument","hull resolution must be 1 to 16 per axis")}function Toe(i,e,t,n,r){let[o,s,a]=t,l=[2*i[0]/o,2*i[1]/s,2*i[2]/a],c=l[0]*l[1]*l[2],u=0;for(let d=0;d<o*s*a;d++){let h=[d%o,Math.floor(d/o)%s,Math.floor(d/(o*s))],p=[e[0]+l[0]*(h[0]+.5),e[1]+l[1]*(h[1]+.5),e[2]+l[2]*(h[2]+.5)];n(p)&&(r.push(p[0],p[1],p[2],c,l[1]),u++);}return u}function V5e(i){let e=[];if(!i)return new Float32Array(0);if(i.kind==="points"){if(i.samples.length%ro!==0)throw new _("invalid_argument","hull samples are x, y, z, volume, height");e.push(...i.samples);}else if(i.kind==="mesh"){Soe(i.resolution);let t=i.vertices,n=[1/0,1/0,1/0],r=[-1/0,-1/0,-1/0];for(let c=0;c<t.length;c+=3)for(let u=0;u<3;u++)n[u]=Math.min(n[u],t[c+u]),r[u]=Math.max(r[u],t[c+u]);let o=c=>[t[c*3],t[c*3+1],t[c*3+2]],s=i.indices,a=c=>{let u=0;for(let d=0;d+2<s.length;d+=3)G5e(c,o(s[d]),o(s[d+1]),o(s[d+2]))&&u++;return (u&1)===1},l=[(r[0]-n[0])/2,(r[1]-n[1])/2,(r[2]-n[2])/2];Toe(l,n,i.resolution,a,e);}else {Soe(i.resolution);let t=i.kind==="box"?i.halfExtents:i.kind==="boat"?[i.beam/2,i.depth/2,i.length/2]:[i.radius,i.radius,i.radius],n=r=>{if(i.kind==="box")return true;if(i.kind==="ball")return r[0]*r[0]+r[1]*r[1]+r[2]*r[2]<=i.radius*i.radius;let o=r[2]/t[2],s=o>0?1-i.bow*o*o:1-.25*i.bow*o*o,a=(t[1]-r[1])/(2*t[1]),l=.35+.65*(1-a*a);return Math.abs(r[0])<=t[0]*s*l};Toe(t,[-t[0],-t[1],-t[2]],i.resolution,n,e);}if(e.length/ro>512)throw new _("invalid_argument","hull has more than 512 sample points");return new Float32Array(e)}function LR(i,e,t){if(e>t)throw new _("capacity_exceeded",`a craft holds at most ${t} ${i}`);return e}function woe(i){let e=V5e(i.hull),t=i.foils??[],n=i.thrusters??[],r=i.rotors??[],o=i.wheels??[],s=[MD,e.length/ro,LR("foils",t.length,16),LR("thrusters",n.length,8),LR("rotors",r.length,8),LR("wheels",o.length,8)],a=i.hydro??{};s.push(...a.drag??[0,0,0],...a.linearDrag??[0,0,0],a.angularDrag??0,a.righting??0);let l=i.planing;s.push(l?.speed??0,l?.lift??0,l?.dragFactor??1,...l?.position??[0,0,0]),s.push(...i.airDrag??[0,0,0]),s.push(i.gas?.volume??0,i.gas?.netDensity??0,...i.gas?.center??[0,0,0]),ns(s,i.gear?.steer),ns(s,i.gear?.brake),ns(s,i.gear?.deploy,1),s.push(i.gear?.retractRate??0);let c=i.assist;s.push(c?.level??0,...c?.rateDamping??[0,0,0],c?.autoLevel??0,c?.stallGuard??0,c?.coordination??0,c?.hoverHold??0,c?.pitch??255,c?.roll??255,c?.yaw??255,c?.lift??255,i.stall??34028234663852886e22,i.span??0,i.groundEffect??0,i.probeOffset??0),s.push(...e);for(let u of t)s.push(...u.position,...u.chord??goe,...u.normal??Eoe,u.area),ns(s,u.deflection),s.push(u.maxDeflection??0,u.effectiveness??1,u.rate??0,u.deflectionDrag??0,u.groundEffect?1:0,u.leeward?1:0),B5e(u.curve,s);for(let u of n)s.push(...u.position,...u.axis??goe,u.maxThrust,u.reverse??0),ns(s,u.throttle),s.push(u.spoolRate??0,F5e[u.medium??"any"],u.maxSpeed??0,u.torque??0),voe(s,u.vector);for(let u of r)s.push(...u.position,...u.axis??Eoe,u.radius,u.maxThrust),ns(s,u.collective),ns(s,u.cyclicPitch),ns(s,u.cyclicRoll),s.push(u.cyclicTilt??0,u.hubStiffness??0,u.torqueReaction??0),ns(s,u.power,1),s.push(u.governorRate??0,u.rotorDrag??0,u.autorotation??0,u.inflow??0,u.groundEffect??0),voe(s,u.tilt);for(let u of o){let d=u.spring;s.push(...u.position,u.restLength,u.radius,d.stiffness,d.dampingCompression,d.dampingRelaxation,d.maxForce,u.steer??0,u.brake??0,u.grip??1,u.rolling??0);}if(s.some(u=>Number.isNaN(u)))throw new _("invalid_argument","craft description has a NaN");return new Float32Array(s)}var io={stretch:1e-6,bend:1e-4,volume:0,damping:.5,gravity:{x:0,y:-9.81,z:0},substeps:10,radius:.01,friction:.3,contraction:.3,density:1e3,ropeMass:.02},Ioe=32;function Ooe(i,e,t){let n=t.substeps??io.substeps;if(!Number.isInteger(n)||n<1||n>Ioe)throw new _("invalid_argument",`soft body substeps must be a whole number from 1 to ${Ioe}`);let r=t.gravity??io.gravity;i[C$]=t.stretch??io.stretch,i[N$]=t.bend??io.bend,i[k$]=t.volume??io.volume,i[L$]=t.damping??io.damping,i[O0]=r.x,i[O0+1]=r.y,i[O0+2]=r.z,e[M$]=n,i[D$]=t.radius??io.radius,i[P$]=t.friction??io.friction,i[F$]=t.contraction??io.contraction,i[U$]=t.plastic?.yieldStrain??0,i[B$]=t.plastic?t.plastic.creep??1:0,i[G$]=t.plastic?t.plastic.limit??.5:0,i[C0]=t.fibre?.x??0,i[C0+1]=t.fibre?.y??0,i[C0+2]=t.fibre?.z??0;}function H5e(i,e,t){i.fill(0,e,e+nh);let n=(r,o)=>{i[e+r]=o.x,i[e+r+1]=o.y,i[e+r+2]=o.z;};if("plane"in t)i[e]=V$,n(1,t.plane.normal),i[e+7]=t.plane.offset;else if("sphere"in t)i[e]=H$,n(1,t.sphere.center),i[e+7]=t.sphere.radius;else if("capsule"in t)i[e]=W$,n(1,t.capsule.a),n(4,t.capsule.b),i[e+7]=t.capsule.radius;else {i[e]=K$,n(1,t.box.center),n(4,t.box.half);let r=t.box.rotation??{x:0,y:0,z:0,w:1};i[e+8]=r.x,i[e+9]=r.y,i[e+10]=r.z,i[e+11]=r.w;}}function W5e(i,e,t){let n=new Float32Array(Y$),r=Math.max(t.x-e.x,t.y-e.y,t.z-e.z),o=i.cells??[4,2,6];return n.set(o,0),n.set([e.x,e.y,e.z,t.x,t.y,t.z],3),n[9]=i.threshold??3,n[10]=i.crush??.02,n[11]=i.maxDepth??.35,n[12]=i.radius??r*.25,n[13]=i.stiffness??1e-5,n}var PD=class{constructor(e,t,n){this.port=e;this.info=t;this.disposed=false;this.particles=t.particles,this.skinned=t.skinned,this.tets=t.tets,this.geometry=n;}get id(){return this.info.id}positions(){return this.port.positions(this.info.id,this.particles)}attach(e){if(e!==null&&this.skinned===0)throw new _("invalid_argument","this soft body has no embedded surface to draw");this.geometry=e;}setOptions(e){Ooe(this.port.prepare(),this.port.registers,e),this.port.params(this.info.id);}setActivation(e){if(!(e>=0&&e<=1))throw new _("invalid_argument","muscle activation runs from 0 to 1");this.port.activate(this.info.id,e);}setAnchors(e){this.port.anchors(this.info.id,e);}push(e,t){this.port.move(this.info.id,[e.x,e.y,e.z],[t.x,t.y,t.z]);}present(){return this.disposed||this.geometry===null?0:this.port.present(this.info.id,this.geometry)}dispose(){this.disposed||(this.disposed=true,this.port.remove(this.info.id));}},DR=class{constructor(e){this.port=e;this.bodies=[];this.block=new Float32Array(nh*wc);}create(e,t={}){Ooe(this.port.prepare(),this.port.registers,t);let n;if("lattice"in e){let o=e.lattice;n=this.port.lattice({cells:o.cells,size:[o.size.x,o.size.y,o.size.z],origin:[o.origin.x,o.origin.y,o.origin.z],density:o.density??io.density},e.surface??null);}else "rope"in e?n=this.port.rope(e.rope.points,e.rope.mass??io.ropeMass,e.rope.pinFirst??false):n=this.port.asset(e.asset);let r=new PD(this.port,n,t.geometry??null);return this.bodies.push(r),r}remove(e){let t=this.bodies.indexOf(e);t>=0&&this.bodies.splice(t,1),e.dispose();}setColliders(e){if(e.length>wc)throw new _("capacity_exceeded",`soft bodies collide with at most ${wc} shapes`);for(let t=0;t<e.length;t++)H5e(this.block,t*nh,e[t]);this.port.colliders(this.block,e.length);}couple(e){if(this.port.couple===void 0)throw new _("unsupported_feature","soft bodies couple to rigid bodies only on the native engine (feature rigid_coupling_1)");return this.port.couple(e)}uncouple(e){this.port.uncouple?.(e);}get count(){return this.bodies.length}step(e){this.bodies.length>0&&this.port.step(e);}present(){for(let e=0;e<this.bodies.length;e++)this.bodies[e].present();}digest(){return this.port.digest()}dispose(){for(let e of this.bodies)e.dispose();this.bodies.length=0,this.port.dispose();}};function Coe(i,e){if(e===void 0)return null;let t={x:1/0,y:1/0,z:1/0},n={x:-1/0,y:-1/0,z:-1/0};for(let r=0;r<i.length;r+=3)t.x=Math.min(t.x,i[r]),t.y=Math.min(t.y,i[r+1]),t.z=Math.min(t.z,i[r+2]),n.x=Math.max(n.x,i[r]),n.y=Math.max(n.y,i[r+1]),n.z=Math.max(n.z,i[r+2]);return W5e(e,t,n)}var iu=class{constructor(e,t,n){this.system=e,this.id=t,this.entity=n;}setChannel(e,t){if(e<0||e>=16)throw new _("invalid_argument","craft channel is 0 to 15");this.system.controls()[this.id*16+e]=t;}channel(e){return this.system.controls()[this.id*16+e]}telemetry(e){return this.system.telemetry()[this.id*16+e]}get speed(){return this.telemetry(0)}get submerged(){return this.telemetry(1)}get planing(){return this.telemetry(2)}get bank(){return this.telemetry(3)}get pitchAttitude(){return this.telemetry(15)}get airspeed(){return this.telemetry(4)}get angleOfAttack(){return this.telemetry(5)}get stalled(){return this.telemetry(6)>.5}get groundEffect(){return this.telemetry(7)}get onGround(){return this.telemetry(8)>0}get spool(){return this.telemetry(10)}get rotorSpeed(){return this.telemetry(11)}get thrust(){return this.telemetry(12)}get climb(){return this.telemetry(13)}get apparentWind(){return this.telemetry(14)}crumple(e,t,n){this.system.crumple(this,e,t,n);}impact(e,t){return this.system.impact(this,e,t)}get damage(){return this.system.damage(this)}remove(){this.system.remove(this);}},FD=class extends iu{get throttle(){return this.channel(0)}set throttle(e){this.setChannel(0,e);}get steer(){return this.channel(1)}set steer(e){this.setChannel(1,e);}get sheet(){return this.channel(2)}set sheet(e){this.setChannel(2,e);}},UD=class extends iu{get pitch(){return this.channel(0)}set pitch(e){this.setChannel(0,e);}get roll(){return this.channel(1)}set roll(e){this.setChannel(1,e);}get yaw(){return this.channel(2)}set yaw(e){this.setChannel(2,e);}get throttle(){return this.channel(3)}set throttle(e){this.setChannel(3,e);}get flaps(){return this.channel(4)}set flaps(e){this.setChannel(4,e);}get brake(){return this.channel(5)}set brake(e){this.setChannel(5,e);}get gearDown(){return this.channel(6)>.5}set gearDown(e){this.setChannel(6,e?1:0);}get tilt(){return this.channel(7)}set tilt(e){this.setChannel(7,e);}},BD=class extends iu{get collective(){return this.channel(0)}set collective(e){this.setChannel(0,e);}get cyclicPitch(){return this.channel(1)}set cyclicPitch(e){this.setChannel(1,e);}get cyclicRoll(){return this.channel(2)}set cyclicRoll(e){this.setChannel(2,e);}get pedal(){return this.channel(3)}set pedal(e){this.setChannel(3,e);}get engine(){return this.channel(4)>.5}set engine(e){this.setChannel(4,e?1:0);}},GD=class{constructor(e){this.one=new Float32Array(2);this.oneOut=new Float32Array(Vo);this.level=0;this.currentX=0;this.currentZ=0;this.windX=0;this.windZ=0;this.gust=0;this.gustPeriod=0;this.port=e;}configure(e){this.port.configureWater(e),this.remember(e);}sea(e,t={}){let n=t.windDirection??0,r=t.seed??1,o=v0(e,n,r);return this.port.sea(e,n,r),this.remember(o),o}ocean(e){this.port.setOcean(e);}cascades(e){if(!this.port.setCascades)throw new _("unsupported_feature","this craft backend has no FFT ocean");this.port.setCascades(e);}puddles(e){if(!this.port.setPuddles)throw new _("unsupported_feature","this craft backend has no puddles");this.port.setPuddles(e);}setPuddleBed(e){this.port.setPuddleBed?.(e);}pour(e,t,n){this.port.pourPuddles?.(e,t,n);}puddleWeather(e,t){this.port.puddleWeather?.(e,t);}ripples(e){if(!this.port.setRipples)throw new _("unsupported_feature","this craft backend has no ripples");this.port.setRipples(e);}followRipples(e,t){this.port.followRipples?.(e,t);}splash(e,t,n){this.port.pushRipples?.(e,t,n);}setLevel(e){this.level=e,this.flow();}setCurrent(e,t){this.currentX=e,this.currentZ=t,this.flow();}setWind(e,t,n=0,r=0){this.windX=e,this.windZ=t,this.gust=n,this.gustPeriod=r,this.flow();}height(e,t){return this.one[0]=e,this.one[1]=t,this.port.sampleWater(this.one,1,this.oneOut),this.oneOut[0]}sample(e,t,n=new Rc){this.one[0]=e,this.one[1]=t,this.port.sampleWater(this.one,1,this.oneOut);let r=this.oneOut;return n.height=r[0],n.normalX=r[1],n.normalY=r[2],n.normalZ=r[3],n.velocityX=r[4],n.velocityY=r[5],n.velocityZ=r[6],n}sampleBatch(e,t,n){if(e.length<t*2||n.length<t*Vo)throw new _("invalid_argument","water sample buffers are too small");this.port.sampleWater(e,t,n);}remember(e){this.level=e.level??0,this.currentX=e.current?.[0]??0,this.currentZ=e.current?.[1]??0,this.windX=e.wind?.[0]??0,this.windZ=e.wind?.[1]??0,this.gust=e.gust??0,this.gustPeriod=e.gustPeriod??0;}flow(){this.port.setFlow({level:this.level,current:[this.currentX,this.currentZ],wind:[this.windX,this.windZ],gust:this.gust,gustPeriod:this.gustPeriod});}},PR=class{constructor(e){this.crumpled=new Map;this.active=0;this.port=e,this.water=new GD(e),this.handles=Array.from({length:e.capacity},()=>null);}get backend(){return this.port.name}get count(){return this.active}controls(){return this.port.controls()}telemetry(){return this.port.telemetry()}create(e,t,n,r={}){return this.build(e,t,n,r,iu)}preset(e,t,n,r={}){return this.fromPreset(e,t,n,r,iu)}boat(e,t,n){return this.fromPreset(e,t,n.preset,n,FD)}aircraft(e,t,n){return this.fromPreset(e,t,n.preset,n,UD)}helicopter(e,t,n={}){return this.fromPreset(e,t,n.preset??"helicopter",{running:true,...n},BD)}remove(e){this.handles[e.id]===e&&(this.port.removeCraft(e.id),this.crumpled.delete(e.id),this.handles[e.id]=null,this.active--);}forget(e){for(let t of this.handles)t&&t.entity===e&&this.remove(t);}step(){if(this.port.step(),!(this.crumpled.size===0||!this.port.presentCrumple))for(let[e,t]of this.crumpled)this.port.presentCrumple(e,t);}crumple(e,t,n,r){if(!this.port.crumple)throw new _("unsupported_feature","vehicle crumple needs the native engine with feature soft_body_1");this.port.crumple(e.id,n,Coe(n,r)),this.crumpled.set(e.id,t);}impact(e,t,n){return !this.port.impact||!this.crumpled.has(e.id)?false:this.port.impact(e.id,[t.x,t.y,t.z],[n.x,n.y,n.z])}damage(e){return this.port.damage&&this.crumpled.has(e.id)?this.port.damage(e.id):0}dispose(){this.port.dispose();}fromPreset(e,t,n,r,o){let s=Aoe(yoe(n,(r.mode??"arcade")==="arcade"),r);return this.build(e,t,s,{body:OD[n],...r},o)}build(e,t,n,r,o){let s=woe(n),[a,l]=this.attach(e,t,r.body),c=this.port.createCraft(t,a,r.collider??l,s,r.running??false),u=new o(this,c,t);return this.handles[c]=u,this.active++,u}attach(e,t,n){if(e.hasBody(t))return [e.bodyOf(t),4294967295];if(!n)throw new _("invalid_argument","a custom craft needs an existing body or a body shape");let r=e.addBody(t,{kind:"dynamic",canSleep:false}),o=n.wingMass??0,s=e.addCollider(t,{shape:{kind:"cuboid",halfExtents:n.halfExtents},mass:n.mass-o});return n.wing&&o>0&&e.addCollider(t,{shape:{kind:"cuboid",halfExtents:n.wing},mass:o}),[r,s]}};var oKe=4,sKe=16,Noe=.08,koe=.001,aKe=1.15,lKe=.2,cKe=1.2,uKe=.5,Loe=.5,dKe=1e-6,hKe=1e-6,pKe=.01,mKe=1e-5,fKe=0,_Ke=1,yKe=2;function kt(i,e,t){return i<e?e:i>t?t:i}function zh(i,e,t,n){if(t<=0)return e;let r=t*n;return i+kt(e-i,-r,r)}var FR=class{constructor(){this.position=new Float64Array(3);this.linear=new Float64Array(3);this.angular=new Float64Array(3);this.basis=new g0;}pointVelocity(e,t,n,r,o=0){let s=this.angular;return r[o]=this.linear[0]+(s[1]*n-s[2]*t),r[o+1]=this.linear[1]+(s[2]*e-s[0]*n),r[o+2]=this.linear[2]+(s[0]*t-s[1]*e),r}},UR=class{constructor(){this.force=new Float64Array(3);this.torque=new Float64Array(3);}clear(){return this.force.fill(0),this.torque.fill(0),this}addAt(e,t,n,r,o,s){this.force[0]+=r,this.force[1]+=o,this.force[2]+=s,this.torque[0]+=t*s-n*o,this.torque[1]+=n*r-e*s,this.torque[2]+=e*o-t*r;}addTorque(e,t,n){this.torque[0]+=e,this.torque[1]+=t,this.torque[2]+=n;}},HD=class{constructor(e){this.words=e;this.at=0;}f(){if(this.at>=this.words.length)throw new _("invalid_argument","craft description is truncated");return this.words[this.at++]}v3(){return [this.f(),this.f(),this.f()]}mix(){let e=new Float64Array(17);for(let t=0;t<e.length;t++)e[t]=this.f();return e}floats(e){let t=new Float64Array(e);for(let n=0;n<e;n++)t[n]=this.f();return t}};function oo(i,e,t){let n=0;for(let r=0;r<16;r++)n+=i[r+1]*e[t+r];return i[0]+n}function Moe(i){return {axis:i.v3(),angle:i.mix(),maxAngle:i.f(),rate:i.f()}}function Doe(i,e,t,n,r){if(t===0)return r[0]=i[0],r[1]=i[1],r[2]=i[2],r;yr(t,n);let o=n.sin,s=n.cos,a=e[1]*i[2]-e[2]*i[1],l=e[2]*i[0]-e[0]*i[2],c=e[0]*i[1]-e[1]*i[0],u=(e[0]*i[0]+e[1]*i[1]+e[2]*i[2])*(1-s);return r[0]=i[0]*s+a*o+e[0]*u,r[1]=i[1]*s+l*o+e[1]*u,r[2]=i[2]*s+c*o+e[2]*u,r}function AKe(i,e,t){let n=Math.abs(i[2])<.9,r=n?0:1,o=n?1:0;e[0]=i[1]*o,e[1]=i[2]*r-i[0]*o,e[2]=-i[1]*r;let s=Math.max(Math.hypot(e[0],e[1],e[2]),hKe);e[0]/=s,e[1]/=s,e[2]/=s,t[0]=i[1]*e[2]-i[2]*e[1],t[1]=i[2]*e[0]-i[0]*e[2],t[2]=i[0]*e[1]-i[1]*e[0];}function Poe(i,e,t){if(Number.isNaN(t)||e<=0||i<=0)return 1;let n=sKe*Math.max(t,0)/e,r=n*n/(1+n*n);return 1+i*(1-r)}function bKe(i,e,t,n){let r=kt((t+Zd)/DD,0,ny),o=Math.min(Math.floor(r),ny-1),s=r-o;n[0]=i[o]+(i[o+1]-i[o])*s,n[1]=e[o]+(e[o+1]-e[o])*s;}var BR=class{constructor(){this.hit=new Uint8Array(8);this.distance=new Float64Array(8);this.normal=new Float64Array(24);}},GR=class{constructor(e){this.telemetry=new Float64Array(16);this.foils=[];this.thrusters=[];this.rotors=[];this.wheels=[];this.deflection=new Float64Array(16);this.spool=new Float64Array(8);this.vector=new Float64Array(8);this.rotor=new Float64Array(8);this.tilt=new Float64Array(8);this.previous=new Float64Array(8);this.deployed=1;this.contacts=0;this.sample=new Rc;this.v=new Float64Array(12);this.coefficients=new Float64Array(2);this.sc={sin:0,cos:0};this.windOut=new Float64Array(3);this.channels=new Float32Array(16);this.wet=new Uint8Array(32);this.offsets=new Float64Array(96);this.fluid=new Float64Array(96);this.axisScratch=[0,0,0];this.sideScratch=[0,0,0];this.frontScratch=[0,0,0];this.parts=[];let t=new HD(e);if(t.f()!==MD)throw new _("invalid_argument","craft description version mismatch");let n=t.f(),r=[t.f(),t.f(),t.f(),t.f()];this.hydroDrag=t.v3(),this.linearDrag=t.v3(),this.angularDrag=t.f(),this.righting=t.f(),this.planingSpeed=t.f(),this.planingLift=t.f(),this.planingDrag=t.f(),this.planingPosition=t.v3(),this.airDrag=t.v3(),this.gasVolume=t.f(),this.gasDensity=t.f(),this.gasCenter=t.v3(),this.gearSteer=t.mix(),this.gearBrake=t.mix(),this.gearDeploy=t.mix(),this.retractRate=t.f(),this.assist=t.floats(8),this.assistChannels=[t.f(),t.f(),t.f(),t.f()],this.stall=t.f(),this.span=t.f(),this.groundEffect=t.f(),this.probeOffset=t.f(),this.hullCount=n,this.hull=t.floats(n*ro);let o=0;for(let h=0;h<n;h++)o+=this.hull[h*ro+3];this.hullVolume=o;let s=o>0?1/Math.cbrt(o):0;this.hullArea=new Float64Array(n);for(let h=0;h<n;h++)this.hullArea[h]=this.hull[h*ro+3]*s;this.columnOf=new Uint32Array(n);let a=[],l=[],c=[],u=[];for(let h=0;h<n;h++){let p=h*ro,m=a.findIndex((f,y)=>f===this.hull[p]&&l[y]===this.hull[p+2]);m<0&&(m=a.length,a.push(this.hull[p]),l.push(this.hull[p+2]),c.push(0),u.push(0)),c[m]+=this.hull[p+1],u[m]+=1,this.columnOf[h]=m;}this.columnX=Float64Array.from(a),this.columnY=Float64Array.from(c.map((h,p)=>Math.fround(h/u[p]))),this.columnZ=Float64Array.from(l),this.columnWet=new Uint8Array(a.length),this.columnSample=new Float64Array(a.length*4);for(let h=0;h<r[0];h++)this.foils.push({position:t.v3(),chord:t.v3(),normal:t.v3(),area:t.f(),deflection:t.mix(),maxDeflection:t.f(),effectiveness:t.f(),rate:t.f(),deflectionDrag:t.f(),groundEffect:t.f()!==0,leeward:t.f()!==0,cl:t.floats(MR),cd:t.floats(MR)});for(let h=0;h<r[1];h++)this.thrusters.push({position:t.v3(),axis:t.v3(),maxThrust:t.f(),reverse:t.f(),throttle:t.mix(),spoolRate:t.f(),medium:t.f(),maxSpeed:t.f(),torque:t.f(),vector:Moe(t)});for(let h=0;h<r[2];h++)this.rotors.push({position:t.v3(),axis:t.v3(),radius:t.f(),maxThrust:t.f(),collective:t.mix(),cyclicPitch:t.mix(),cyclicRoll:t.mix(),cyclicTilt:t.f(),hubStiffness:t.f(),torqueReaction:t.f(),power:t.mix(),governorRate:t.f(),rotorDrag:t.f(),autorotation:t.f(),inflow:t.f(),groundEffect:t.f(),tilt:Moe(t)});for(let h=0;h<r[3];h++)this.wheels.push({position:t.v3(),restLength:t.f(),radius:t.f(),stiffness:t.f(),dampingCompression:t.f(),dampingRelaxation:t.f(),maxForce:t.f(),steer:t.f(),brake:t.f(),grip:t.f(),rolling:t.f()}),this.previous[h]=this.wheels[h].restLength;if(t.at!==e.length)throw new _("invalid_argument","craft description has trailing words");let d=0;for(let h=0;h<n;h++){let p=h*ro;d=Math.max(d,Math.hypot(this.hull[p],this.hull[p+1],this.hull[p+2]));}for(let h of this.foils)d=Math.max(d,Math.hypot(...h.position));for(let h of this.thrusters)d=Math.max(d,Math.hypot(...h.position));for(let h of this.rotors)d=Math.max(d,Math.hypot(...h.position)+h.radius);for(let h of this.wheels)d=Math.max(d,Math.hypot(...h.position)+h.restLength+h.radius);this.reach=d;for(let h of this.foils)this.parts.push(h.position);for(let h of this.thrusters)this.parts.push(h.position);for(let h of this.rotors)this.parts.push(h.position);}get needsProbes(){return this.wheels.length>0||this.groundEffect>0||this.rotors.some(e=>e.groundEffect>0)}spinUp(){this.rotor.fill(1),this.spool.fill(0);}gearRay(e,t,n,r){let o=this.wheels[e];return t.basis.toWorld(o.position[0],o.position[1],o.position[2],n,0),n[0]+=t.position[0],n[1]+=t.position[1],n[2]+=t.position[2],r[0]=-t.basis.ux,r[1]=-t.basis.uy,r[2]=-t.basis.uz,(o.restLength+o.radius)*this.deployed}step(e,t,n,r,o,s,a,l){let c=e.basis,u=this.v,d=this.channels;for(let k=0;k<16;k++)d[k]=o[s+k];let h=t.windInto(this.windOut),p=e.linear[0]-h[0],m=e.linear[1]-h[1],f=e.linear[2]-h[2],y=Math.hypot(p,m,f),b=p*c.ux+m*c.uy+f*c.uz;this.assistControls(c,p,m,f,b,d);let A=e.linear[0]*c.bx+e.linear[1]*c.by+e.linear[2]*c.bz,E=this.planingSpeed>0?kt((A-this.planingSpeed)/this.planingSpeed,0,1):0;l.clear();let R=this.parts,g=e.position[1]-this.reach<=t.crest(),v=0,x=t.density;for(let k=0;k<R.length;k++){let M=R[k];if(c.toWorld(M[0],M[1],M[2],this.offsets,k*3),this.wet[k]=0,this.fluid[k*3]=h[0],this.fluid[k*3+1]=h[1],this.fluid[k*3+2]=h[2],!g)continue;let K=e.position[0]+this.offsets[k*3],Y=e.position[1]+this.offsets[k*3+1],te=e.position[2]+this.offsets[k*3+2];t.sample(K,te,this.sample),this.sample.height>Y&&(this.wet[k]=1,this.fluid[k*3]=this.sample.velocityX,this.fluid[k*3+1]=this.sample.velocityY,this.fluid[k*3+2]=this.sample.velocityZ);}g&&this.hullCount>0&&(v=this.hydro(e,t,E,l));let O=Poe(this.groundEffect,this.span,n),N=false,I=eh(-b,Math.max(p*c.bx+m*c.by+f*c.bz,koe));for(let k=0;k<this.foils.length;k++){let M=this.foils[k],K=kt(oo(M.deflection,d,0),-M.maxDeflection,M.maxDeflection);this.deflection[k]=zh(this.deflection[k],K,M.rate,a);let Y=this.offsets[k*3],te=this.offsets[k*3+1],Z=this.offsets[k*3+2];e.pointVelocity(Y,te,Z,u,0),c.toLocal(u[0]-this.fluid[k*3],u[1]-this.fluid[k*3+1],u[2]-this.fluid[k*3+2],u,3);let de=u[3]*M.chord[0]+u[4]*M.chord[1]+u[5]*M.chord[2],Oe=u[3]*M.normal[0]+u[4]*M.normal[1]+u[5]*M.normal[2],be=de*de+Oe*Oe;if(be<=0||M.area<=0)continue;let ke=eh(-Oe,de),De=this.deflection[k];M.leeward&&(De=ke<0?Math.abs(De):-Math.abs(De)),bKe(M.cl,M.cd,tl(ke+M.effectiveness*De),this.coefficients);let Fe=this.coefficients[0],Ze=this.coefficients[1]+M.deflectionDrag*Math.abs(De);M.groundEffect&&!this.wet[k]&&(Fe*=O,I=ke,Math.abs(ke)>this.stall&&(N=true));let wt=1/Math.sqrt(be),q=M.chord,he=M.normal,ot=(q[0]*de+he[0]*Oe)*wt,Vt=(q[1]*de+he[1]*Oe)*wt,_t=(q[2]*de+he[2]*Oe)*wt,dt=q[1]*he[2]-q[2]*he[1],_n=q[2]*he[0]-q[0]*he[2],Bn=q[0]*he[1]-q[1]*he[0],Zr=_n*_t-Bn*Vt,zn=Bn*ot-dt*_t,Gn=dt*Vt-_n*ot,ei=.5*(this.wet[k]?x:ZN)*be*M.area;c.toWorld(Zr*ei*Fe-ot*ei*Ze,zn*ei*Fe-Vt*ei*Ze,Gn*ei*Fe-_t*ei*Ze,u,6),l.addAt(Y,te,Z,u[6],u[7],u[8]);}let S=0,w=0;for(let k=0;k<this.thrusters.length;k++){let M=this.thrusters[k],K=this.foils.length+k,Y=kt(oo(M.throttle,d,0),-1,1);this.spool[k]=zh(this.spool[k],Y,M.spoolRate,a),w+=Math.abs(this.spool[k]);let te=M.vector;this.vector[k]=zh(this.vector[k],kt(oo(te.angle,d,0),-te.maxAngle,te.maxAngle),te.rate,a);let Z=this.wet[K]===1;if(!(M.medium===fKe||(M.medium===_Ke?Z:M.medium===yKe&&!Z)))continue;let Oe=Doe(M.axis,te.axis,this.vector[k],this.sc,this.axisScratch);c.toWorld(Oe[0],Oe[1],Oe[2],u,0);let be=this.offsets[K*3],ke=this.offsets[K*3+1],De=this.offsets[K*3+2];e.pointVelocity(be,ke,De,u,3);let Fe=(u[3]-this.fluid[K*3])*u[0]+(u[4]-this.fluid[K*3+1])*u[1]+(u[5]-this.fluid[K*3+2])*u[2],Ze=this.spool[k],wt=Ze>=0?1:M.reverse,q=M.maxSpeed>0&&Ze>0?kt(1-Fe/M.maxSpeed,0,1):1,he=Ze*wt*M.maxThrust*q;S+=Math.abs(he),l.addAt(be,ke,De,u[0]*he,u[1]*he,u[2]*he),l.addTorque(u[0]*M.torque*he,u[1]*M.torque*he,u[2]*M.torque*he);}let U=0;for(let k=0;k<this.rotors.length;k++){let M=this.rotors[k],K=this.foils.length+this.thrusters.length+k,Y=M.tilt;this.tilt[k]=zh(this.tilt[k],kt(oo(Y.angle,d,0),-Y.maxAngle,Y.maxAngle),Y.rate,a);let te=Doe(M.axis,Y.axis,this.tilt[k],this.sc,this.axisScratch),Z=this.sideScratch,de=this.frontScratch;AKe(te,Z,de),c.toWorld(te[0],te[1],te[2],u,0);let Oe=this.offsets[K*3],be=this.offsets[K*3+1],ke=this.offsets[K*3+2];e.pointVelocity(Oe,be,ke,u,3);let De=(u[3]-h[0])*u[0]+(u[4]-h[1])*u[1]+(u[5]-h[2])*u[2],Fe=kt(oo(M.collective,d,0),0,1);if(oo(M.power,d,0)>uKe)this.rotor[k]=zh(this.rotor[k],1,M.governorRate,a);else {let ti=Math.max(-De,0),mA=M.autorotation*ti*(1-Fe),Cu=M.rotorDrag*(lKe+Fe)*this.rotor[k];this.rotor[k]=kt(this.rotor[k]+(mA-Cu)*a,0,aKe);}U+=this.rotor[k];let Ze=this.rotor[k]*this.rotor[k],wt=kt(Fe-De*M.inflow,0,cKe),q=M.maxThrust*wt*Ze*Poe(M.groundEffect,2*M.radius,n);S+=q;let he=kt(oo(M.cyclicPitch,d,0),-1,1),ot=kt(oo(M.cyclicRoll,d,0),-1,1);yr(ot*M.cyclicTilt,this.sc);let Vt=this.sc.sin,_t=this.sc.cos;yr(he*M.cyclicTilt,this.sc);let dt=this.sc.sin,_n=this.sc.cos,Bn=Z[0]*Vt*_n+te[0]*_t*_n+de[0]*dt,Zr=Z[1]*Vt*_n+te[1]*_t*_n+de[1]*dt,zn=Z[2]*Vt*_n+te[2]*_t*_n+de[2]*dt;c.toWorld(Bn*q,Zr*q,zn*q,u,6),l.addAt(Oe,be,ke,u[6],u[7],u[8]);let Gn=M.hubStiffness*Ze;c.toWorld(Z[0]*-he*Gn+de[0]*ot*Gn,Z[1]*-he*Gn+de[1]*ot*Gn,Z[2]*-he*Gn+de[2]*ot*Gn,u,9),l.addTorque(u[9],u[10],u[11]);let ei=M.torqueReaction*q;l.addTorque(u[0]*ei,u[1]*ei,u[2]*ei);}if(this.gasVolume>0){let k=this.gasCenter;c.toWorld(k[0],k[1],k[2],u,0),l.addAt(u[0],u[1],u[2],0,this.gasVolume*this.gasDensity*t.gravity,0);}if(this.airDrag[0]>0||this.airDrag[1]>0||this.airDrag[2]>0){c.toLocal(p,m,f,u,0);let k=-0.5*ZN*y;c.toWorld(k*this.airDrag[0]*u[0],k*this.airDrag[1]*u[1],k*this.airDrag[2]*u[2],u,3),l.addAt(0,0,0,u[3],u[4],u[5]);}if(v>0){if(this.planingSpeed>0&&E>0){let K=kt(v*oKe,0,1),Y=this.planingLift*E*A*A*K,te=this.planingPosition;c.toWorld(te[0],te[1],te[2],u,0),l.addAt(u[0],u[1],u[2],0,Y,0);}let k=this.righting*v;l.addTorque(-c.uz*k,0,c.ux*k);let M=-this.angularDrag*v;l.addTorque(e.angular[0]*M,e.angular[1]*M,e.angular[2]*M);}this.assistForces(e,d,l),this.gear(e,r,oo(this.gearSteer,d,0),oo(this.gearBrake,d,0),oo(this.gearDeploy,d,0),a,l);let L=this.telemetry;return L[0]=A,L[1]=v,L[2]=E,L[3]=eh(c.ry,c.uy),L[4]=y,L[5]=I,L[6]=N?1:0,L[7]=O,L[8]=this.contacts,L[9]=this.deployed,L[10]=w/Math.max(this.thrusters.length,1),L[11]=U/Math.max(this.rotors.length,1),L[12]=S,L[13]=b,L[14]=Math.hypot(h[0]-e.linear[0],h[1]-e.linear[1],h[2]-e.linear[2]),L[15]=eh(c.by,Math.hypot(c.bx,c.bz)),l}hydro(e,t,n,r){let o=e.basis,s=this.v,a=this.sample,l=t.density,c=l*t.gravity,u=1+(this.planingDrag-1)*n,d=0,h=t.crest()+pKe+Math.abs(t.crest())*mKe,p=this.columnX.length;this.columnWet.fill(0);for(let m=0;m<this.hullCount;m++){let f=m*ro;o.toWorld(this.hull[f],this.hull[f+1],this.hull[f+2],s,0),h<e.position[1]+s[1]-this.hull[f+4]*.5||(this.columnWet[this.columnOf[m]]=1);}for(let m=0;m<p;m++){if(!this.columnWet[m])continue;o.toWorld(this.columnX[m],this.columnY[m],this.columnZ[m],s,0),t.sample(e.position[0]+s[0],e.position[2]+s[2],a);let f=m*4;this.columnSample[f]=a.height,this.columnSample[f+1]=a.velocityX,this.columnSample[f+2]=a.velocityY,this.columnSample[f+3]=a.velocityZ;}for(let m=0;m<this.hullCount;m++){let f=m*ro,y=this.columnOf[m];if(!this.columnWet[y])continue;o.toWorld(this.hull[f],this.hull[f+1],this.hull[f+2],s,0);let b=s[0],A=s[1],E=s[2],R=y*4;a.height=this.columnSample[R],a.velocityX=this.columnSample[R+1],a.velocityY=this.columnSample[R+2],a.velocityZ=this.columnSample[R+3];let g=a.height-(e.position[1]+A),v=kt(g/this.hull[f+4]+.5,0,1);if(v<=0)continue;let x=v*this.hull[f+3];d+=x,e.pointVelocity(b,A,E,s,3);let O=s[3]-a.velocityX,N=s[4]-a.velocityY,I=s[5]-a.velocityZ;o.toLocal(O,N,I,s,6);let S=Math.sqrt(O*O+N*N+I*I),w=v*this.hullArea[m],U=-0.5*l*w*S,L=-l*w,k=(U*this.hydroDrag[0]+L*this.linearDrag[0])*s[6],M=(U*this.hydroDrag[1]+L*this.linearDrag[1])*s[7],K=(U*this.hydroDrag[2]*u+L*this.linearDrag[2])*s[8];o.toWorld(k,M,K,s,9),r.addAt(b,A,E,s[9],s[10]+c*x,s[11]);}return this.hullVolume>0?d/this.hullVolume:0}assistControls(e,t,n,r,o,s){let a=this.assist[0];if(a<=0)return;let[l,c,u,d]=this.assistChannels;e.toLocal(t,n,r,this.v,0);let h=eh(-this.v[1],Math.max(this.v[2],koe));if(l!==255&&s[l]>0&&h>this.stall-Noe){let m=kt((this.stall-h)/Noe,0,1);s[l]*=1-a*this.assist[5]*(1-m);}let p=c!==255?s[c]:0;u!==255&&(s[u]=kt(s[u]+a*this.assist[6]*p,-1,1)),d!==255&&(s[d]=kt(s[d]-a*this.assist[7]*o,0,1));}assistForces(e,t,n){let r=this.assist[0];if(r<=0)return;let o=e.basis,s=this.v;o.toLocal(e.angular[0],e.angular[1],e.angular[2],s,0),o.toWorld(-r*this.assist[1]*s[0],-r*this.assist[2]*s[1],-r*this.assist[3]*s[2],s,3),n.addTorque(s[3],s[4],s[5]);let[a,l]=this.assistChannels,c=Math.max(a!==255?Math.abs(t[a]):0,l!==255?Math.abs(t[l]):0),u=r*this.assist[4]*(1-kt(c,0,1));n.addTorque(-o.uz*u,0,o.ux*u);}gear(e,t,n,r,o,s,a){this.deployed=zh(this.deployed,kt(o,0,1),this.retractRate,s);let l=e.basis,c=this.v,u=1/Math.max(s,dKe),d=0;for(let h=0;h<this.wheels.length;h++){let p=this.wheels[h],m=p.restLength*this.deployed;if(!t.hit[h]||this.deployed<=0){this.previous[h]=m;continue}let f=kt(t.distance[h]-p.radius,0,m),y=(this.previous[h]-f)*u;this.previous[h]=f;let b=y>0?p.dampingCompression:p.dampingRelaxation,A=kt(p.stiffness*(m-f)+b*y,0,p.maxForce);if(A<=0)continue;d|=1<<h,l.toWorld(p.position[0],p.position[1],p.position[2],c,0);let E=f+p.radius,R=c[0]-l.ux*E,g=c[1]-l.uy*E,v=c[2]-l.uz*E,x=t.normal[h*3],O=t.normal[h*3+1],N=t.normal[h*3+2];yr(n*p.steer,this.sc),l.toWorld(-this.sc.sin,0,this.sc.cos,c,3);let I=c[3]*x+c[4]*O+c[5]*N,S=c[3]-x*I,w=c[4]-O*I,U=c[5]-N*I,L=Math.hypot(S,w,U);L>0?(S/=L,w/=L,U/=L):(S=l.bx,w=l.by,U=l.bz);let k=O*U-N*w,M=N*S-x*U,K=x*w-O*S;e.pointVelocity(R,g,v,c,6);let Y=c[6]*S+c[7]*w+c[8]*U,te=c[6]*k+c[7]*M+c[8]*K,Z=-p.grip*A*kt(te/Loe,-1,1),de=-(p.rolling+p.brake*kt(r,0,1))*A*kt(Y/Loe,-1,1);a.addAt(R,g,v,l.ux*A+k*Z+S*de,l.uy*A+M*Z+w*de,l.uz*A+K*Z+U*de);}this.contacts=d;}};var gKe="script-craft",EKe=2,VR=class{constructor(e,t,n,r=64){this.name=gKe;this.water=new x0;this.state=new FR;this.wrench=new UR;this.hits=new BR;this.origin=new Float64Array(3);this.direction=new Float64Array(3);this.ray=new Xi;this.hit=new qi;this.vector=new Kt;this.ocean=null;this.port=e,this.transforms=t,this.stepSeconds=n,this.clock=Float64Array.of(n),this.capacity=r,this.slots=Array.from({length:r},()=>null),this.controlTable=new Float32Array(r*16),this.telemetryTable=new Float32Array(r*16);}configureWater(e){this.water.configure(e);}sea(e,t,n){this.water.configure(v0(e,t,n));}setOcean(e){this.ocean=e;}get oceanDesc(){return this.ocean}setFlow(e){this.water.level=Math.fround(e.level),this.water.setCurrent(e.current[0],e.current[1]),this.water.setWind(e.wind[0],e.wind[1],e.gust,e.gustPeriod);}createCraft(e,t,n,r,o){let s=new GR(r);o&&s.spinUp();let a=this.slots.indexOf(null);if(a<0)throw new _("capacity_exceeded","craft capacity reached");return this.slots[a]={entity:e,body:t,collider:n,model:s},this.controlTable.fill(0,a*16,(a+1)*16),a}removeCraft(e){if(!this.slots[e])throw new _("unknown_resource","craft does not exist");this.slots[e]=null,this.controlTable.fill(0,e*16,(e+1)*16),this.telemetryTable.fill(0,e*16,(e+1)*16);}controls(){return this.controlTable}telemetry(){return this.telemetryTable}sampleWater(e,t,n){this.water.sampleBatch(e,t,n);}step(){let e=this.stepSeconds;this.water.advanceFrom(this.clock,0);for(let t=0;t<this.slots.length;t++){let n=this.slots[t];if(!n||!this.read(n))continue;let r=n.model,o=Number.NaN;this.hits.hit.fill(0),r.needsProbes&&(o=this.ground(n,Math.max(r.span,r.reach),r.probeOffset),this.castGear(n)),r.step(this.state,this.water,o,this.hits,this.controlTable,t*16,e,this.wrench),this.telemetryTable.set(r.telemetry,t*16);let s=this.wrench.force,a=this.wrench.torque;this.port.applyImpulse(n.body,this.vector.set(s[0]*e,s[1]*e,s[2]*e)),this.port.applyTorqueImpulse(n.body,this.vector.set(a[0]*e,a[1]*e,a[2]*e));}}dispose(){this.slots.fill(null);}read(e){let t=this.transforms.store;if(!t.has(e.entity))return false;let n=this.transforms.row(e.entity),r=t.fields,o=n*3,s=n*4,a=this.state;return a.position[0]=r.position[o],a.position[1]=r.position[o+1],a.position[2]=r.position[o+2],a.basis.fromQuaternion(r.rotation[s],r.rotation[s+1],r.rotation[s+2],r.rotation[s+3]),this.port.linearVelocity(e.body,this.vector),a.linear[0]=this.vector.x,a.linear[1]=this.vector.y,a.linear[2]=this.vector.z,this.port.angularVelocity(e.body,this.vector),a.angular[0]=this.vector.x,a.angular[1]=this.vector.y,a.angular[2]=this.vector.z,true}cast(e,t,n,r,o,s,a,l){let c=this.ray.set(t,n,r,o,s,a,l);return c.excludeCollider=e.collider===4294967295?-1:e.collider,this.port.raycast(c,this.hit)?this.hit.distance:Number.NaN}ground(e,t,n){let r=t*EKe,o=this.state.position,s=this.cast(e,o[0],o[1]-n,o[2],0,-1,0,r)+n,a=o[1]-this.water.height(o[0],o[2]),l=a>=0&&a<=r?a:Number.NaN;return Number.isNaN(s)?l:Number.isNaN(l)?s:Math.min(s,l)}castGear(e){let t=this.hits,n=e.model;for(let r=0;r<n.wheels.length;r++){let o=n.gearRay(r,this.state,this.origin,this.direction);if(o<=0)continue;let s=this.origin,a=this.direction,l=this.cast(e,s[0],s[1],s[2],a[0],a[1],a[2],o);Number.isNaN(l)||(t.hit[r]=1,t.distance[r]=l,t.normal[r*3]=this.hit.normalX,t.normal[r*3+1]=this.hit.normalY,t.normal[r*3+2]=this.hit.normalZ);}}};var Foe=fh("rigid_body",{body:"u32",kind:"u8"}),xKe=0,vKe=1,RKe=2,SKe=[0,1,0],Uoe=65535,TKe=0,wKe=1;function WD(i,e,t,n){if(!Number.isInteger(i)||i<e||i>t)throw new _("invalid_argument",`${n} must be an integer from ${e} to ${t}`);return i}function IKe(i){return i==="dynamic"?xKe:i==="kinematic"?vKe:RKe}var HR=class{constructor(e,t,n,r,o={}){this.zero=new Kt;this.vehicleDesc=new Float32Array(il);this.vehicles=[];this.rollbackStates=[];this.enrolledIn=null;this.sphereOverlap={count:0,collider:-1};this.bodyWrite=new Kt;this.port=e,this.world=t,this.transforms=n,this.bodies=t.register(Foe,o.maxBodies);let s=o.maxColliders??4096;this.colliderEntity=new Uint32Array(s).fill(4294967295),this.views=[this.colliderEntity],this.desc={gravity:o.gravity??[0,-9.81,0],stepSeconds:r,maxBodies:this.bodies.capacity,maxColliders:s,maxJoints:o.maxJoints,maxContactEvents:o.maxContactEvents,maxCharacterControllers:o.maxCharacterControllers,rollback:o.rollback},this.solver=o.solver,this.craft=new PR(e.craft??new VR(e,n,r)),this.craftHost={hasBody:a=>this.hasBody(a),bodyOf:a=>this.bodyOf(a),addBody:(a,l)=>this.addBody(a,l),addCollider:(a,l)=>this.addCollider(a,l)},e.bindTransforms(n.columns),t.onDespawn(this);}get backend(){return this.port.name}async init(){await this.port.init(this.desc),this.solver&&this.setSolver(this.solver);}setSolver(e){let t=this.port;if(t.setSolver===void 0)throw new _("unsupported_feature",`${t.name} physics has no solver settings`);t.setSolver(WD(e.iterations??Kee,1,qee,"solver iterations"),WD(e.pgsIterations??Yee,1,zee,"PGS iterations"),WD(e.ccdSubsteps??Xee,0,Qee,"CCD substeps"));}setSoftCcd(e,t){let n=this.port;if(n.setSoftCcd===void 0)throw new _("unsupported_feature",`${n.name} physics has no soft CCD`);if(!(Number.isFinite(t)&&t>=0))throw new _("invalid_argument","soft CCD distance must be finite and not negative");n.setSoftCcd(this.bodyOf(e),t);}setSleepThresholds(e,t){let n=this.port;if(n.setSleepThresholds===void 0)throw new _("unsupported_feature",`${n.name} physics has no sleep thresholds`);let r=t.linear??$ee,o=t.angular??jee,s=t.seconds??Jee;if(!(Number.isFinite(r)&&Number.isFinite(o)&&Number.isFinite(s)&&s>=0))throw new _("invalid_argument","sleep thresholds must be finite and the sleep delay not negative");n.setSleepThresholds(this.bodyOf(e),r,o,s);}get rollback(){let e=this.port.rollback??null;if(e!==null&&this.enrolledIn!==e){this.enrolledIn=e,e.attach(this);for(let t of this.rollbackStates)e.attach(t);}return e}enrolRollback(...e){for(let t of e)this.rollbackStates.push(t),this.enrolledIn?.attach(t);}rollbackViews(){return this.views}setGravity(e){this.port.setGravity(e);}addBody(e,t){this.transforms.row(e);let n=this.port.createBody(e,t),r=this.world.add(e,Foe);return this.bodies.fields.body[r]=n,this.bodies.fields.kind[r]=IKe(t.kind),n}addCollider(e,t){this.bodies.has(e)||this.addBody(e,{kind:"fixed"});let n=this.port.createCollider(this.bodyOf(e),t);if(n>=this.colliderEntity.length)throw new _("capacity_exceeded","collider capacity reached");return this.colliderEntity[n]=e,n}removeCollider(e){this.port.destroyCollider(e),this.colliderEntity[e]=4294967295;}setColliderEnabled(e,t){this.port.setColliderEnabled(e,t);}overlap(e,t,n,r,o){let s=this.port;if(s.overlapSphere===void 0)return false;let a=this.sphereOverlap;return s.overlapSphere(e,t,n,r,false,a),o.count=a.count,o.entity=a.count>0?this.entityOfCollider(a.collider):Hs,true}entityOfCollider(e){return e<0||e>=this.colliderEntity.length?Hs:this.colliderEntity[e]}hasBody(e){return this.bodies.has(e)}get joints(){let e=this.port.jointPort;if(!e)throw new _("unsupported_feature",`${this.port.name} physics has no joint drives, breakable joints or ragdolls (feature joints_6dof_1)`);return e}ragdoll(e){return this.joints.createRagdoll(e)}joint(e,t,n){return this.port.createJoint(this.bodyOf(e),this.bodyOf(t),n)}setJointMotor(e,t,n){this.port.setJointMotor(e,t,n);}removeJoint(e){this.port.destroyJoint(e);}applyImpulse(e,t){this.port.applyImpulse(this.bodyOf(e),t);}applyTorqueImpulse(e,t){this.port.applyTorqueImpulse(this.bodyOf(e),t);}addForce(e,t){this.port.addForce(this.bodyOf(e),t);}applyImpulseAtPoint(e,t,n){this.port.applyImpulseAtPoint(this.bodyOf(e),t,n);}addForceAtPoint(e,t,n){this.port.addForceAtPoint(this.bodyOf(e),t,n);}addTorque(e,t){this.port.addTorque(this.bodyOf(e),t);}velocityAtPoint(e,t,n){return this.port.velocityAtPoint(this.bodyOf(e),t,n),n}setJointMotorPosition(e,t,n,r){this.port.setJointMotorPosition(e,t,n,r);}castShape(e,t){return this.port.castShape(e,t)}setColliderClass(e,t){this.port.setColliderClass(e,Za(t));}setContactRule(e,t,n){Za(e),Za(t),this.port.setContactRule(e,t,n);}setCollisionGroups(e,t,n){if(!(Number.isInteger(t)&&Number.isInteger(n)&&t>=0&&n>=0&&t<=Uoe&&n<=Uoe))throw new _("invalid_argument","collision groups are 16-bit membership and filter masks");this.port.setCollisionGroups(e,t,n);}removeContactRule(e,t){this.setContactRule(e,t,HQ);}ignoreContacts(e,t){this.setContactRule(e,t,{ignore:true});}oneWayPlatform(e,t,n=SKe){this.setContactRule(e,t,{oneWay:n});}bodyId(e){return this.bodyOf(e)}resetForces(e){this.port.resetForces(this.bodyOf(e));}setLinearVelocity(e,t){this.port.setLinearVelocity(this.bodyOf(e),t);}setAngularVelocity(e,t){this.port.setAngularVelocity(this.bodyOf(e),t);}linearVelocity(e,t){return this.port.linearVelocity(this.bodyOf(e),t),t}angularVelocity(e,t){return this.port.angularVelocity(this.bodyOf(e),t),t}isSleeping(e){return this.port.isSleeping(this.bodyOf(e))}wake(e){this.port.wake(this.bodyOf(e));}teleport(e,t){let n=this.transforms.row(e),r=this.transforms.store.fields,o=n*3;r.position[o]=t.x,r.position[o+1]=t.y,r.position[o+2]=t.z;let s=this.bodyOf(e);this.port.setBodyPose(s,r.position,o,r.rotation,n*4),this.port.setLinearVelocity(s,this.zero),this.port.setAngularVelocity(s,this.zero),this.port.resetForces(s),this.transforms.teleport(e);}batchHandle(){return this.port.batchHandle?.()??0}writeBody(e,t,n,r,o){let s=this.bodyWrite;s.x=n,s.y=r,s.z=o;try{e===TKe?this.port.addForce(t,s):e===wKe?this.port.applyImpulse(t,s):this.port.setLinearVelocity(t,s);}catch{return}}raycast(e,t){let n=e.direction;if(n.x===0&&n.y===0&&n.z===0)throw new _("invalid_argument","raycast direction is zero");return this.port.raycast(e,t)}contactCount(){return this.port.contactCount()}contactEntityA(e){return this.entityOfCollider(this.port.contactColliderA(e))}contactEntityB(e){return this.entityOfCollider(this.port.contactColliderB(e))}contactColliderA(e){return this.port.contactColliderA(e)}contactColliderB(e){return this.port.contactColliderB(e)}contactStarted(e){return this.port.contactStarted(e)}createCharacterController(e={}){return this.port.createCharacterController(e)}moveCharacter(e,t,n,r){this.port.moveCharacter(e,t,n,r);let o=this.transforms.row(this.entityOfCollider(t)),s=this.transforms.store.fields.position,a=o*3;return s[a]+=r.x,s[a+1]+=r.y,s[a+2]+=r.z,r}get water(){return this.craft.water}createCraft(e,t,n={}){return this.craft.create(this.craftHost,e,t,n)}createCraftPreset(e,t,n={}){return this.craft.preset(this.craftHost,e,t,n)}createBoat(e,t){return this.craft.boat(this.craftHost,e,t)}createAircraft(e,t){return this.craft.aircraft(this.craftHost,e,t)}createHelicopter(e,t={}){return this.craft.helicopter(this.craftHost,e,t)}createVehicle(e,t){let n=this.port.vehicles;if(!n)throw new _("unsupported_feature",`${this.port.name} physics has no vehicle controller`);yj(t,this.vehicleDesc);let r=n.createVehicle(this.bodyOf(e),this.vehicleDesc),o=new M0(n,r,e,t.wheels.length);for(let s of this.vehicles)s.refresh();return this.vehicles.push(o),o}destroyVehicle(e){let t=this.port.vehicles;if(!t)return;t.destroyVehicle(e.id);let n=this.vehicles.indexOf(e);n>=0&&this.vehicles.splice(n,1);}onDespawn(e){this.craft.forget(e);for(let n=this.vehicles.length-1;n>=0;n--)this.vehicles[n].entity===e&&this.vehicles.splice(n,1);let t=this.bodies.row(e);if(t!==-1){for(let n=0;n<this.colliderEntity.length;n++)this.colliderEntity[n]===e&&(this.colliderEntity[n]=4294967295);this.port.destroyBody(this.bodies.fields.body[t]);}}step(){this.bodies.count!==0&&(this.craft.step(),this.port.step());}bodyOf(e){return this.bodies.fields.body[this.bodies.require(e)]}};var OKe=32,KD=2,ry=0,WR=1,Boe=16,Goe=1<<24,CKe=1<<20,NKe=1073741823;function Voe(i){return typeof i=="number"?()=>i:i}var ou=class{constructor(e){this.place=new Float64Array(8);this.placed=false;let t=e.items,n=t.length;this.name=e.name??"layer",this.count=n,this.x=new Float64Array(n),this.y=new Float64Array(n),this.z=new Float64Array(n),this.radius=new Float64Array(n),this.entryStart=new Int32Array(n+1);let r=0,o=0,s=1/0,a=1/0,l=-1/0,c=-1/0;for(let f=0;f<n;f++){let y=t[f],b=y.levels.length;if(b===0||b>Boe)throw new _("invalid_argument",`prefetch item ${f} needs 1 to ${Boe} levels`);this.x[f]=y.center[0],this.y[f]=y.center[1],this.z[f]=y.center[2];let A=Math.max(0,y.radius??0);this.radius[f]=A,A>o&&(o=A),y.center[0]<s&&(s=y.center[0]),y.center[2]<a&&(a=y.center[2]),y.center[0]>l&&(l=y.center[0]),y.center[2]>c&&(c=y.center[2]),this.entryStart[f]=r,r+=b;}if(r>Goe)throw new _("invalid_argument",`a prefetch layer holds at most ${Goe} levels`);this.entryStart[n]=r,this.entries=r,this.entryItem=new Int32Array(r),this.entryLevel=new Uint8Array(r),this.entryWithin=new Float64Array(r),this.entryBytes=new Int32Array(r);let u=[];for(let f=0;f<n;f++){let y=t[f];for(let b=0;b<y.levels.length;b++){let A=this.entryStart[f]+b,E=y.levels[b];this.entryItem[A]=f,this.entryLevel[A]=b,this.entryWithin[A]=E.within??1/0,this.entryBytes[A]=Math.min(NKe,Math.max(0,Math.round(E.bytes??(b===0?y.bytes??0:0)))),u.push(E.path);}}this.paths=u,this.maxRadius=o;let d=e.cellSize??OKe;if(!(d>0))throw new _("invalid_argument","a prefetch layer cell size must be above zero");for(n===0&&(s=0,a=0,l=0,c=0);Math.floor((l-s)/d+1)*Math.floor((c-a)/d+1)>CKe;)d*=2;this.cellSize=d,this.originX=s,this.originZ=a,this.cols=Math.floor((l-s)/d)+1,this.rows=Math.floor((c-a)/d)+1;let h=this.cols*this.rows;this.cellStart=new Int32Array(h+1),this.cellItems=new Int32Array(n);let p=new Int32Array(n);for(let f=0;f<n;f++){let y=this.cellIndex(this.x[f],this.z[f]);p[f]=y,this.cellStart[y+1]++;}for(let f=0;f<h;f++)this.cellStart[f+1]+=this.cellStart[f];let m=this.cellStart.slice(0,h);for(let f=0;f<n;f++)this.cellItems[m[p[f]]++]=f;this.loadRadius=Voe(e.radius),this.needRadius=Voe(e.need??e.radius),this.held=e.held??null,this.busy=e.busy??null,this.flow=e.flow!==void 0&&e.flow.length>=KD?e.flow:null,this.place[6]=1,this.place[7]=1;}cellIndex(e,t){let n=Math.min(this.cols-1,Math.max(0,Math.floor((e-this.originX)/this.cellSize)));return Math.min(this.rows-1,Math.max(0,Math.floor((t-this.originZ)/this.cellSize)))*this.cols+n}get scale(){return this.place[7]}setPlacement(e){let t=this.place;if(e===null){t.fill(0),t[6]=1,t[7]=1,this.placed=false;return}let n=Math.hypot(e[3],e[4],e[5],e[6])||1;t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3]/n,t[4]=e[4]/n,t[5]=e[5]/n,t[6]=e[6]/n,t[7]=e[7]>0?e[7]:1,this.placed=true;}toLocal(e,t,n,r){let o=e[0],s=e[1],a=e[2];if(!this.placed){t[n]=o,t[n+1]=s,t[n+2]=a;return}let l=this.place;r&&(o-=l[0],s-=l[1],a-=l[2]);let c=-l[3],u=-l[4],d=-l[5],h=l[6],p=2*(u*a-d*s),m=2*(d*o-c*a),f=2*(c*s-u*o),y=1/l[7];t[n]=(o+h*p+(u*f-d*m))*y,t[n+1]=(s+h*m+(d*p-c*f))*y,t[n+2]=(a+h*f+(c*m-u*p))*y;}};var UKe=["dx","dy","dz"],BKe=["rx","ry","rz"],GKe=1e3,VKe=0,HKe=1297109827,WKe=1,Hoe=2,jD=255;var Woe=1,JD=2,KKe=20,YKe=255,XKe=8,qKe=3,zKe=".cspl",KR=32,YD=80,QKe=48,$Ke=32,jKe=4,JKe=8,ZKe=12,eYe=16,tYe=20,nYe=24,rYe=28,iYe=1024,oYe=16,sYe=256,aYe=/^[a-z][a-z0-9+.-]*:/i,lYe=Array.from({length:sYe},(i,e)=>e.toString(oYe).padStart(2,"0")),cYe=new Uint32Array(20);function uYe(i){return i===Woe?1:i===JD?0:2}function Koe(i,e){let t=uYe(i);return t===0?e.near:t===1?e.near*qKe:e.far}function Yoe(i,e){let t=Array.from({length:e},(o,s)=>s),n=i.groups,r=i.parts;return n!==void 0&&r!==void 0&&t.sort((o,s)=>n[o]-n[s]||r[o]-r[s]||o-s),Int32Array.from(t)}var dYe=16,hYe=24,$h=6,Xoe=1.1,pYe=1.35,mYe=3,qD=[{near:40,far:600},{near:25,far:350},{near:14,far:180}];function YR(i){return qD[Math.min(qD.length-1,Math.max(0,i))]}function fYe(i,e,t=qD[0]){let n=[],r=i.bounds,o=Yoe(i,e.length),s=0;for(;s<o.length;){let a=i.groups?.[o[s]]??o[s],l=s+1;for(;l<o.length&&i.groups!==void 0&&i.groups[o[l]]===a;)l++;let c=[1/0,1/0,1/0],u=[-1/0,-1/0,-1/0],d=[];for(let f=s;f<l;f++){let y=o[f];for(let E=0;E<3;E++)c[E]=Math.min(c[E],r[y*$h+E]),u[E]=Math.max(u[E],r[y*$h+3+E]);let b=i.parts?.[y]??jD,A=b===Woe||b===JD;d.push(A?{path:e[y],bytes:i.bytes[y],within:Koe(b,t)*Xoe}:{path:e[y],bytes:i.bytes[y]});}let h=u[0]-c[0],p=u[1]-c[1],m=u[2]-c[2];n.push({center:[(c[0]+u[0])*.5,(c[1]+u[1])*.5,(c[2]+u[2])*.5],radius:Math.sqrt(h*h+p*p+m*m)*.5,bytes:i.bytes[o[s]],levels:d}),s=l;}return n}function iy(i){return new _("invalid_argument",`the scenery manifest is malformed: ${i}`)}function _Ye(i,e){let t="";for(let n=0;n<$Ke;n++)t+=lYe[i[e+n]];return t+zKe}function yYe(i){if(i.byteLength<KR)throw iy("too short");let e=new DataView(i.buffer,i.byteOffset,i.byteLength);if(e.getUint32(0,true)!==HKe)throw iy("not a CSPM file");let t=e.getUint32(jKe,true);if(t!==WKe&&t!==Hoe)throw iy(`version ${t} is not supported`);let n=e.getUint32(JKe,true);if(i.byteLength<KR+n*YD)throw iy(`${n} entries do not fit`);let r=Array.from({length:n},(c,u)=>_Ye(i,KR+u*YD+QKe)),o=new Float32Array(n*$h),s=new Uint32Array(n),a=new Uint8Array(n).fill(jD),l=new Uint32Array(n);for(let c=0;c<n;c++){let u=KR+c*YD;s[c]=e.getUint32(u+dYe,true);for(let p=0;p<$h;p++)o[c*$h+p]=e.getFloat32(u+hYe+4*p,true);if(l[c]=c,t!==Hoe)continue;let d=e.getUint32(u+KKe,true),h=d&YKe;if(h>JD)throw iy(`entry ${c} has part ${h}`);a[c]=h,l[c]=d>>>XKe;}return {bounds:o,bytes:s,parts:a,groups:l,grid:{cellSize:e.getFloat32(ZKe,true),origin:[e.getFloat32(eYe,true),e.getFloat32(tYe,true)],cols:e.getUint32(nYe,true),rows:e.getUint32(rYe,true)},chunks:r}}function AYe(i,e){if(aYe.test(i))return new URL(e,i).href;let t=i.lastIndexOf("/");return t<0?e:i.slice(0,t+1)+e}async function bYe(i){let e=await fetch(i);if(!e.ok)throw new _("asset_load_failed",`scenery ${i} failed with ${e.status}`);return new Uint8Array(await e.arrayBuffer())}var gYe=8*1024*1024,XD=0,XR=1,oy=2,EYe=256,Qh=4,qoe=0,xYe=1,vYe="budget";function RYe(i){return typeof i=="object"&&i!==null&&i.reason===vYe}var zD=class{constructor(e,t=gYe){this.assets=e;this.cacheBytes=t;this.kept=new Map;this.cache=new Map;this.cached=0;}lazy(e){let t=this.assets;return t!==null&&t.requests?.()===true&&t.lazy?.(e)===true}read(e,t=qoe){let n=this.assets;if(n===null)return bYe(e);if(!this.lazy(e))return this.retained(n,e);let r=this.cache.get(e);return r!==void 0?(this.cache.delete(e),this.cache.set(e,r),Promise.resolve(r)):n.take(e,t,false).catch(o=>{if(!RYe(o)||!this.reclaim())throw o;return n.take(e,t,false)})}holds(e){return this.cache.has(e)}get reader(){return this.assets}retained(e,t){let n=this.kept.get(t);if(n!==void 0)return n;let r=e.take(t);return this.kept.set(t,r),r.catch(()=>this.kept.delete(t)),r}delivered(e,t){if(!(!this.lazy(e)||this.cache.has(e)))for(this.cache.set(e,t),this.cached+=t.byteLength;this.cached>this.cacheBytes&&this.cache.size>0;)this.evictColdest();}reclaim(){let e=Math.floor(this.cache.size/2);if(this.cache.size===0)return false;for(;this.cache.size>e;)this.evictColdest();return true}evictColdest(){for(let[e,t]of this.cache){this.cache.delete(e),this.cached-=t.byteLength,this.assets?.release?.(e);return}}get cachedBytes(){return this.cached}close(){for(;this.cache.size>0;)this.evictColdest();this.kept.clear();}},QD=class{constructor(e){this.read=e;}get chunks(){return this.read()[Xt.chunks]}get resident(){return this.read()[Xt.resident]}get requested(){return this.read()[Xt.requested]}get installed(){return this.read()[Xt.installed]}get evicted(){return this.read()[Xt.evicted]}get deferred(){return this.read()[Xt.deferred]}get failed(){return this.read()[Xt.failed]}get installedBytes(){return this.read()[Xt.installedKib]*iYe}get residentSplats(){return this.read()[Xt.residentSplats]}get drawnSplats(){return this.read()[Xt.drawnSplats]}get listedPages(){return this.read()[Xt.listedPages]}get poolCapacity(){return this.read()[Xt.poolCapacity]}get poolFreePages(){return this.read()[Xt.poolFreePages]}get tier(){return this.read()[Xt.tier]}get updates(){return this.read()[Xt.updates]}get heroSplats(){return this.read()[Xt.heroSplats]}get heroShed(){return this.read()[Xt.heroShed]}get standIn(){return this.read()[Xt.standIn]!==0}get deformedSplats(){return this.read()[Xt.deformedSplats]}},$D=class{constructor(e,t,n,r,o,s,a={}){this.port=e;this.handle=t;this.chunkPaths=r;this.chunks=o;this.owner=s;this.requests=new Uint32Array(8);this.transform=new Float32Array(8);this.lastEye=new Float64Array(3);this.registers=null;this.predictor=null;this.hasEye=false;this.sweep=0;this.waiting=0;this.flow=new Float64Array(KD);this.closed=false;this.editValues=new Float32Array(3);this.standing=false;this.kernel=null;if(this.regionNames=a.regions??{},this.standInTarget=a.standIn??null,a.heroBudget!==void 0){let u=new Uint32Array(3);u.set(a.heroBudget),this.bodyPort().heroBudget(t,u);}this.grid=n.grid,this.stats=new QD(()=>this.view());let l=r.length;this.engineState=new Uint8Array(l),this.entryRow=Yoe(n,l),this.rowBytes=n.bytes,this.rowPart=n.parts??new Uint8Array(l).fill(jD),this.rowSphere=new Float32Array(l*Qh);for(let u=0;u<l;u++){let d=n.bounds,h=u*$h,p=d[h+3]-d[h],m=d[h+4]-d[h+1],f=d[h+5]-d[h+2];this.rowSphere[u*Qh]=(d[h]+d[h+3])*.5,this.rowSphere[u*Qh+1]=(d[h+1]+d[h+4])*.5,this.rowSphere[u*Qh+2]=(d[h+2]+d[h+5])*.5,this.rowSphere[u*Qh+3]=Math.sqrt(p*p+m*m+f*f)*.5;}let c=YR(e.registers(t)[Xt.tier]??0);this.layer=new ou({name:"scenery",items:fYe(n,r,c),radius:()=>YR(this.tier()).far*Xoe,need:()=>YR(this.tier()).near*mYe,cellSize:n.grid.cellSize>0?n.grid.cellSize:void 0,held:u=>{let d=this.entryRow[u];return this.engineState[d]!==XD||this.chunks.holds(this.chunkPaths[d])},busy:()=>this.waiting>0,flow:this.flow});}tier(){return this.closed?0:this.view()[Xt.tier]}get prefetcher(){return this.predictor}stream(e){if(this.predictor!==null||this.closed)return;let t=this.chunks.reader;t===null||t.prefetch===void 0||(this.predictor=e.stream(this.layer,{stalled:()=>this.stalled(),assets:t}));}stalled(){if(this.closed||!this.hasEye)return false;let e=this.layer,t=this.lastEye,n=e.needRadius()/e.scale,r=e.cellSize,o=Math.max(0,Math.floor((t[0]-n-e.maxRadius-e.originX)/r)),s=Math.min(e.cols-1,Math.floor((t[0]+n+e.maxRadius-e.originX)/r)),a=Math.max(0,Math.floor((t[2]-n-e.maxRadius-e.originZ)/r)),l=Math.min(e.rows-1,Math.floor((t[2]+n+e.maxRadius-e.originZ)/r));for(let c=a;c<=l;c++)for(let u=o;u<=s;u++){let d=c*e.cols+u;for(let h=e.cellStart[d];h<e.cellStart[d+1];h++){let p=e.cellItems[h];if(this.engineState[this.entryRow[e.entryStart[p]]]===oy)continue;let m=e.x[p]-t[0],f=e.y[p]-t[1],y=e.z[p]-t[2];if(Math.sqrt(m*m+f*f+y*y)-e.radius[p]<=n)return true}}return false}get removed(){return this.closed}setTransform(e,t,n=1){if(this.closed)return;if(!(n>0))throw new _("invalid_argument",`scenery scale must be above zero, got ${n}`);let r=this.transform;r[0]=e.x,r[1]=e.y,r[2]=e.z,r[3]=t?.x??0,r[4]=t?.y??0,r[5]=t?.z??0,r[6]=t?.w??1,r[7]=n,this.port.setTransform(this.handle,r),this.layer.setPlacement(r);}bodyPort(){let e=this.port.bodies;if(e==null)throw new _("unsupported_feature","this engine build does not move or edit splats");return e}regionOf(e){let t=typeof e=="string"?this.regionNames[e]:e;if(t===void 0||!Number.isInteger(t)||t<0||t>=256)throw new _("invalid_argument",`no splat region ${String(e)}`);return t}edit(e,t){if(this.closed)return;let n=this.editValues;if(n[0]=t.hue??0,n[1]=t.saturation??1,n[2]=t.gain??1,!(n[1]>=0)||!(n[2]>=0)||!Number.isFinite(n[0]))throw new _("invalid_argument","a splat edit needs a finite hue and non-negative saturation and gain");this.bodyPort().edit(this.handle,this.regionOf(e),n);}bind(e){this.closed||this.bodyPort().bind(this.handle,e??VKe);}drape(e,t,n={}){if(this.closed)return;let r=e.engineHost;if(r===null)throw new _("unsupported_feature","this cloth is not simulated by the engine");this.bodyPort().drape(this.handle,r,e.id,this.regionOf(t),n.rest??null);}get motionRows(){return this.closed?0:this.bodyPort().motionRows(this.handle)}motion(e,t){if(this.closed)return;let n=this.bodyPort();if(e===null||t===void 0){this.kernel=null,n.motion(this.handle,0,null,0,0);return}let r=t.table,o=t.rotation!==void 0||t.colour!==void 0||t.opacity!==void 0,s=t.offset??(o?void 0:UKe),a=0,l=[...t.rest??BKe],c=(d,h)=>{h!==void 0&&(a|=d,l.push(...h));};c(1,s),c(2,t.rotation),c(4,t.colour),c(8,t.opacity===void 0?void 0:[t.opacity]);let u=new Uint32Array(14);if(l.forEach((d,h)=>{u[h]=r.column(d);}),!(t.reach>=0))throw new _("invalid_argument","a splat motion reach must not be negative");n.motion(this.handle,r.id,u,Math.ceil(t.reach*GKe),a),this.kernel=()=>e(r);}follow(){this.kernel?.();let e=this.standInTarget;if(e===null)return;let t=this.view()[Xt.standIn]!==0;t!==this.standing&&(this.standing=t,t?e.show():e.hide());}remove(){this.closed||(this.closed=true,this.registers=null,this.predictor!==null&&this.owner.unstream(this.predictor),this.predictor=null,this.owner.release(this),this.port.close(this.handle),this.chunks.close());}update(e){if(this.closed)return;let t=this.port.update(this.handle,e,this.requests);for(let n=0;n<t;n++)this.fetch(this.requests[n],n===0?qoe:xYe);this.layer.toLocal(e,this.lastEye,0,true),this.hasEye=true,this.forget(),this.follow();}forget(){let e=this.layer,t=this.lastEye,n=YR(this.tier()),r=e.scale,o=this.engineState,s=this.rowSphere,a=this.sweep,l=Math.min(o.length,a+EYe);for(let c=a;c<l;c++){if(o[c]!==oy)continue;let u=c*Qh,d=s[u]-t[0],h=s[u+1]-t[1],p=s[u+2]-t[2],m=Koe(this.rowPart[c],n)*pYe/r;Math.sqrt(d*d+h*h+p*p)-s[u+3]>m&&(o[c]=XD);}this.sweep=l>=o.length?0:l;}fetch(e,t){let n=this.chunkPaths[e];if(n===void 0){this.port.fail(this.handle,e);return}this.mark(e,XR);let r=this.chunks.reader;if(r?.progressive!==void 0&&r.isProgressive?.(n)===true&&!this.chunks.holds(n)){let o=true;r.progressive(n,a=>{o?(o=false,this.deliver(e,n,a,false)):this.upgrade(e,a);},t).done.then(a=>this.chunks.delivered(n,a),()=>{o&&this.failed(e);});return}this.chunks.read(n,t).then(o=>this.deliver(e,n,o,true),()=>this.failed(e));}deliver(e,t,n,r){if(!this.closed){try{this.port.provide(this.handle,e,n);}catch{this.failed(e);return}this.mark(e,oy),r&&this.chunks.delivered(t,n);}}upgrade(e,t){if(!(this.closed||this.engineState[e]!==oy))try{this.port.provide(this.handle,e,t);}catch{return}}failed(e){this.closed||(this.mark(e,XD),this.port.fail(this.handle,e));}mark(e,t){let n=this.engineState[e],r=this.rowBytes[e];n===XR&&(this.waiting--,this.flow[ry]-=r),t===XR&&(this.waiting++,this.flow[ry]+=r),n===XR&&t===oy&&(this.flow[WR]+=r),this.engineState[e]=t;}view(){if(this.closed)return cYe;let e=this.registers;return e!==null&&e.byteLength>0?e:(this.registers=this.port.registers(this.handle),this.registers)}},qR=class{constructor(e,t){this.port=e;this.eye=t;this.live=[];this.eyeBuffer=new Float32Array(3);this.prefetch=null;}attachPrefetch(e){if(this.prefetch=e,e!==null)for(let t=0;t<this.live.length;t++)this.live[t].stream(e);}unstream(e){this.prefetch?.removeStream(e);}get supported(){return this.port!==null}load(e,t={}){let n=this.port;if(n===null)throw new _("unsupported_feature","this backend does not draw splat scenery");let r=typeof e=="string"?e:e.href,o=t.assets;return this.open(n,r,new zD(o??null,t.cacheBytes),t)}async splatBody(e){let t=await this.load(e.manifest,e);return t.bind(e.rig),t}async open(e,t,n,r){let o=await n.read(t),s=yYe(o),a=s.chunks.map(u=>AYe(t,u)),l=e.open(o),c=new $D(e,l,s,a,n,this,r);return this.live.push(c),this.prefetch!==null&&c.stream(this.prefetch),c}get count(){return this.live.length}release(e){let t=this.live.indexOf(e);t>=0&&this.live.splice(t,1);}frame(){let e=this.live;if(!(e.length===0||!this.eye(this.eyeBuffer)))for(let t=0;t<e.length;t++)e[t].update(this.eyeBuffer);}dispose(){for(let e=this.live.length-1;e>=0;e--)this.live[e].remove();}};var SYe=6,TYe=12,wYe=13,IYe=14,sy=0,Joe=1,zR=2,zoe=fh("renderable",{node:"u32"}),Zoe=4294967295,OYe=3,Qoe=1024;function $oe(i,e){if(i.schema[e]!=="f32")throw new _("invalid_argument",`instance feeds read f32 fields; ${e} is not one`);return i.column(e)}function joe(i,e){if(e===void 0)return Zoe;if(i.schema[e]!=="u32")throw new _("invalid_argument",`instance rotation and animation read packed u32 fields; ${e} is not one`);return i.column(e)}function CYe(i,e){if(!(e.rotation===void 0&&e.animation===void 0))return [joe(i,e.rotation),joe(i,e.animation)]}function NYe(i){let e=typeof i.position=="string"?[i.position]:[...i.position];return i.scale!==void 0&&e.push(i.scale),i.rotation!==void 0&&e.push(i.rotation),i.animation!==void 0&&e.push(i.animation),e}function kYe(i,e){let t=[];if(typeof e.position=="string"){if(i.schema[e.position]!=="vec3")throw new _("invalid_argument",`instance feed position ${e.position} must be a vec3 field`);for(let n=0;n<OYe;n++)t.push(i.column(e.position,n));}else for(let n of e.position)t.push($oe(i,n));return t.push(e.scale===void 0?Zoe:$oe(i,e.scale)),t}var QR=class{constructor(e,t,n,r=null){this.fed=new Map;this.presentedByFeeds=new Set;this.cameraMatrix=new Float32Array(16);this.activeCamera=null;this.port=e,this.world=t,this.transforms=n,this.renderables=t.register(zoe),this.nodeIds=new Uint32Array(this.renderables.capacity),this.matrixRows=new Int32Array(this.renderables.capacity),this.scenery=new qR(r,o=>this.readCameraEye(o)),t.onDespawn(this);}readCameraEye(e){let t=this.activeCamera;if(t===null)return false;let n=this.cameraMatrix;return this.port.readNodeMatrix(t,n,0),e[0]=n[TYe],e[1]=n[wYe],e[2]=n[IYe],true}get capabilities(){return this.port.capabilities}get gpu(){return this.port.gpu}attach(e){return this.port.attach(e)}resize(e,t,n){this.port.resize(e,t,n);}createGeometry(e){return this.port.createGeometry(e)}geometryAttribute(e,t){return this.port.geometryAttribute(e,t)}markGeometryDirty(e,t,n=0,r=-1){this.port.markGeometryDirty(e,t,n,r);}setDrawRange(e,t,n){this.port.setDrawRange(e,t,n);}destroyGeometry(e){this.port.destroyGeometry(e);}createTexture(e){return this.port.createTexture(e)}loadTexture(e){return this.port.loadTexture(e)}upgradeTexture(e,t){return this.port.upgradeTexture||this.unsupported("texture upgrades"),this.port.upgradeTexture(e,t)}upgradeModel(e,t){return this.port.upgradeModel||this.unsupported("model upgrades"),this.port.upgradeModel(e,t)}markTextureDirty(e,t){this.port.markTextureDirty(e,t);}pushVideoFrame(e,t,n,r){return this.port.pushVideoFrame||this.unsupported("video textures"),this.port.pushVideoFrame(e,t,n,r)}readRenderTarget(e,t,n=0){return this.port.readRenderTarget||this.unsupported("render target readback"),this.port.readRenderTarget(e,t,n)}vectorPort(){let e=this.port.vectorSurfaces;return e==null&&this.unsupported("vector surfaces"),e}get vectorSurfaceCap(){return this.port.vectorSurfaces?.cap??0}loadVector(e){return this.vectorPort().load(e)}unloadVector(e){this.vectorPort().unload(e);}vectorSurface(e){return this.port.capabilities.renderTargets||this.unsupported("render targets"),this.vectorPort().create(e)}destroyVectorSurface(e){this.vectorPort().destroy(e);}setVectorSurfaceNode(e,t){this.vectorPort().setNode(e,t);}playVectorSurface(e,t,n=0){this.vectorPort().play(e,t,n);}seekVectorSurface(e,t,n,r){let o=this.vectorPort();o.seek||this.unsupported("vector surface seeking"),o.seek(e,t,n,r);}vectorSurfaceInput(e,t){return this.vectorPort().inputIndex(e,t)}setVectorSurfaceInput(e,t,n){this.vectorPort().setInput(e,t,typeof n=="boolean"?Number(n):n);}vectorSurfaceData(e,t){return this.vectorPort().dataIndex(e,t)}setVectorSurfaceData(e,t,n,r=0){this.vectorPort().setData(e,t,n,r);}vectorSurfacePointer(e,t,n,r){return this.vectorPort().pointer(e,t,n,r)}pickVectorSurface(e,t,n,r=1e3){return this.vectorPort().pick(e,t,r,n)}vectorSurfaceEvents(e=[]){return this.vectorPort().events(e),e}vectorSurfaceStats(e=x5()){return this.vectorPort().stats(e),e}setVectorSurfaceTier(e){this.vectorPort().setTier(e);}createMaterial(e){return e.kind==="shader"&&this.checkShader(e.shader.glsl!==void 0),this.port.createMaterial(e)}setMaterialColor(e,t){this.port.setMaterialColor(e,(t>>16&255)/255,(t>>8&255)/255,(t&255)/255);}setMaterialRgb(e,t,n,r){this.port.setMaterialColor(e,t,n,r);}setMaterialOpacity(e,t){this.port.setMaterialOpacity(e,t);}setMaterialTexture(e,t,n){this.port.setMaterialTexture(e,t,n);}setUniform(e,t,n){this.port.setMaterialScalar(e,t,n);}setUniformVector(e,t,n){this.port.setMaterialVector(e,t,n);}setUniformTexture(e,t,n){this.port.setMaterialUniformTexture(e,t,n);}setMaterialState(e,t){this.port.setMaterialState(e,t);}createEmitter(e){return this.port.capabilities.particles||this.unsupported("particles"),this.port.createEmitter(e)}particles(e,t){return this.create(e,{kind:"particles",emitter:t})}emit(e,t){this.port.emit(e,t);}setEmitterRate(e,t){this.port.setEmitterRate(e,t);}clearEmitter(e){this.port.clearEmitter(e);}destroyEmitter(e){this.port.destroyEmitter(e);}setRenderOrder(e,t){this.port.setRenderOrder(e,t);}setShadow(e,t){this.port.setShadow(e,t);}setLod(e,t,n,r=0){if(t<0||n>0&&n<=t||r<0)throw new _("invalid_argument",`lod range ${t}..${n} with hysteresis ${r} is invalid`);this.port.setLod(e,t,n,r);}lodLevels(e,t=0){for(let n=0;n<e.length;n++){let r=n+1<e.length?e[n+1].distance:0;this.setLod(e[n].node,e[n].distance,r,t);}}setSprite(e,t,n=.5,r=.5){this.port.setSprite(e,t,n,r);}setProbeCoefficients(e,t){if(t.length<mm)throw new _("invalid_argument",`light probes take ${mm} coefficients (9 RGB)`);this.port.setProbeCoefficients(e,t);}decal(e,t,n={}){return this.port.capabilities.decals||this.unsupported("decals"),this.create(e,{kind:"decal",material:t,...n})}setProjectionMatrix(e,t,n,r){if(t!==null&&t.length<16)throw new _("invalid_argument","projection matrices hold 16 floats");this.port.capabilities.customProjection||this.unsupported("custom projections"),this.port.setProjectionMatrix(e,t,n,r);}setViewOffset(e,t){if(t!==null&&(t.fullWidth<=0||t.fullHeight<=0||t.width<=0||t.height<=0))throw new _("invalid_argument","view offsets need positive sizes");this.port.capabilities.customProjection||this.unsupported("view offsets"),this.port.setViewOffset(e,t);}gpuStats(e){return this.port.gpuStats(e)}attachNode(e,t){this.transforms.row(e);let n=this.world.add(e,zoe);return this.renderables.fields.node[n]=t,t}create(e,t){return this.attachNode(e,this.createDetached(t))}createDetached(e){return this.checkNode(e),this.port.createNode(e)}mesh(e,t,n){return this.create(e,{kind:"mesh",geometry:t,material:n,castShadow:true,receiveShadow:true})}camera(e,t=60,n=.1,r=1e3){let o=this.create(e,{kind:"camera",projection:"perspective",fov:t,near:n,far:r});return this.port.setActiveCamera(o),this.activeCamera=o,o}instanced(e){this.port.capabilities.instancing||this.unsupported("instancing");let t=this.port.createNode({kind:"instanced",...e});return {node:t,capacity:e.capacity,matrices:this.port.instanceMatrices(t),colors:this.port.instanceColors(t)}}batchedDraw(e){if(!this.port.capabilities.instancing||e.slots<=0)return null;let{slots:t,...n}=e,r=this.port.createNode({kind:"instanced",...n,batchSlots:t}),o=this.port.batchBuffers(r);return o===null?(this.port.destroyNode(r),null):{node:r,capacity:e.capacity,matrices:this.port.instanceMatrices(r),colors:this.port.instanceColors(r),slots:o.slots,ranges:o.ranges}}markBatch(e){this.port.markBatch(e.node);}setInstanceCount(e,t){if(t<0||t>e.capacity)throw new _("invalid_argument",`instance count ${t} exceeds ${e.capacity}`);this.port.setInstanceCount(e.node,t);}markInstancesDirty(e){this.port.markInstancesDirty(e.node);}feedInstances(e,t,n,r={}){if(!t.native||this.port.setInstanceFeed===void 0)return false;let o=kYe(t,n),s=CYe(t,n),a=r.hostReads===true;return this.port.setInstanceFeed(e.node,t.id,o,a,s)?(this.forget(e.node),this.world.presentsKernels(t)||(this.world.presentKernels(t),this.presentedByFeeds.add(t)),this.fed.set(e.node,t),a&&this.world.hostReads(t,NYe(n)),true):false}setInstancePalette(e,t,n){if(this.port.setInstancePalette===void 0)return false;if(n===null)return this.port.setInstancePalette(e.node,t,0,0,0,0);let r=n.skin??0,o=n.firstClip??0,s=a=>Number.isInteger(a)&&a>=0;if(!s(r)||!s(o)||!s(n.clips)||n.clips<1||!s(n.frames)||n.frames<1||n.frames>Qoe)throw new _("invalid_argument",`an instance palette needs whole clips of at least 1 and 1 to ${Qoe} frames per clip`);return this.port.setInstancePalette(e.node,t,r,o,n.clips,n.frames)}stopFeedingInstances(e){this.fed.has(e.node)&&this.port.clearInstanceFeed?.(e.node),this.forget(e.node);}forget(e){let t=this.fed.get(e);if(t!==void 0){this.fed.delete(e);for(let n of this.fed.values())if(n===t)return;this.presentedByFeeds.delete(t)&&this.world.presentKernels(t,false);}}morphWeights(e){return this.port.capabilities.morphTargets||this.unsupported("morph targets"),this.port.morphWeights(e)}markMorphWeightsDirty(e){this.port.markMorphWeightsDirty(e);}skeletonPose(e){return this.port.capabilities.skinning||this.unsupported("skinning"),this.port.skeletonPose(e)}markSkeletonDirty(e){this.port.markSkeletonDirty(e);}setVisible(e,t){this.port.setNodeVisible(e,t);}setLayers(e,t){this.port.setNodeLayers(e,t);}setNodeMaterial(e,t){this.port.setNodeMaterial(e,t);}setText(e,t){this.port.setNodeText(e,t);}loadFont(e,t){return this.port.capabilities.text||this.unsupported("text"),this.port.loadFont(e,t)}text3d(e,t,n,r={}){return this.create(e,{...r,kind:"text3d",font:t,text:n})}setTextStyle(e,t){this.port.setTextStyle(e,t);}textBounds(e,t){this.port.textBounds(e,t);}raycast(e,t,n,r=0,o=4294967295){return this.port.capabilities.picking||this.unsupported("picking"),this.port.raycast(e,t,r,o,n)}batchHandle(){return this.port.capabilities.picking?this.port.batchHandle?.()??0:0}governorPressure(){return this.port.governorPressure?.()??0}forceQualityTier(e){if(e!==null&&!(Number.isInteger(e)&&e>=sy&&e<=zR))throw new _("invalid_argument",`quality tiers run from ${sy} to ${zR}`);return this.port.forceQualityTier?.(e)??false}qualityTier(){return this.port.qualityTier?.()??sy}setPerspective(e,t,n,r){this.port.setCameraPerspective(e,t,n,r);}setPerspectiveFrom(e,t,n=0){this.port.setCameraPerspectiveFrom(e,t,n);}setOrthographic(e,t,n,r){this.port.setCameraOrthographic(e,t,n,r);}setActiveCamera(e){this.port.setActiveCamera(e),this.activeCamera=e;}setLight(e,t,n){this.port.setLight(e,t,n);}setEnvironment(e){this.port.setEnvironment(e);}createRenderTarget(e){return this.port.capabilities.renderTargets||this.unsupported("render targets"),this.port.createRenderTarget(e)}renderTargetTexture(e){return this.port.renderTargetTexture(e)}renderTargetAttachment(e,t){return t===0?this.port.renderTargetTexture(e):(this.port.renderTargetAttachment||this.unsupported("multiple render target attachments"),this.port.renderTargetAttachment(e,t))}captureCube(e,t){return Array.from({length:SYe},(n,r)=>this.port.createRenderPass({camera:t,target:e,slice:r,cubeFace:true,once:true}))}createReflector(e,t,n,r=-1){return this.port.createRenderPass({camera:t,target:e,reflect:n,order:r})}renderTargetDepthTexture(e){return this.port.renderTargetDepthTexture||this.unsupported("sampled render target depth"),this.port.renderTargetDepthTexture(e)}resizeRenderTarget(e,t,n){this.port.resizeRenderTarget(e,t,n);}createPostChain(e){this.port.capabilities.postProcessing||this.unsupported("post-processing");for(let t of e.effects)t.kind==="shader"&&this.checkShader(t.shader.glsl!==void 0);return this.port.createPostChain(e)}setPostChain(e){this.port.setPostChain(e);}setWeather(e){this.port.setWeather(e);}setTimeOfDay(e,t,n){this.port.setTimeOfDay(e,t,n);}mediaVolume(e){let t=this.port,{createMedium:n,setMedium:r,mediumTexels:o,markMedium:s,destroyMedium:a}=t;if(n===void 0||r===void 0||o===void 0||s===void 0||a===void 0)throw new _("unsupported_feature","media volumes need the native engine with feature media_volume_1");let l={createMedium:n.bind(t),setMedium:r.bind(t),mediumTexels:o.bind(t),markMedium:s.bind(t),destroyMedium:a.bind(t)};return new sg(l,l.createMedium(e),e)}setPostUniform(e,t,n,r){this.port.setPostScalar(e,t,n,r);}createRenderPass(e){return e.target!==null&&!this.port.capabilities.renderTargets&&this.unsupported("render targets"),this.port.createRenderPass(e)}setRenderPassEnabled(e,t){this.port.setRenderPassEnabled(e,t);}loadModel(e){return this.port.capabilities.models||this.unsupported("models"),this.port.loadModel(e)}loadClips(e,t,n){return this.port.loadClips||this.unsupported("animation clip import"),this.port.loadClips(e,t,n)}setTint(e,t){this.port.setTint||this.unsupported("kit tints"),this.port.setTint(e,t);}instantiate(e,t){return this.attachNode(e,this.port.instantiateModel(t))}findNode(e,t){return this.port.findNode(e,t)}playClip(e,t,n=true,r=0,o=1){return this.port.playClip(e,t,n,r,o)}setClipWeight(e,t){this.port.setClipWeight(e,t);}clipIndex(e,t){return this.port.clipIndex?.(e,t)??-1}playClipIndex(e,t,n,r,o){return this.port.playClipIndex===void 0&&this.unsupported("clip playback by index"),this.port.playClipIndex(e,t,n,r,o)}setIkTarget(e,t,n,r,o){this.clips.setIkTarget(e,t,n,r,o);}instanceBuffer(e,t){try{return t?this.port.instanceColors(e):this.port.instanceMatrices(e)}catch{return null}}markInstances(e){this.port.markInstancesDirty(e);}stopClip(e,t=0){this.port.stopClip(e,t);}get clips(){return this.port.clips??this.unsupported("clip animation (actions, masks, blend spaces, IK, retargeting, root motion)")}get hasClipAnimation(){return this.port.clips!==void 0}nodeOf(e){let t=this.renderables.row(e);return t===-1?null:this.renderables.fields.node[t]}entityOfNode(e){let t=this.renderables.fields.node,n=this.renderables.count;for(let r=0;r<n;r++)if(t[r]===e)return this.renderables.entities[r];return Hs}readNodeMatrix(e,t,n=0){this.port.readNodeMatrix(e,t,n);}stats(e){this.port.stats(e);}onDespawn(e){let t=this.renderables.row(e);if(t===-1)return;let n=this.renderables.fields.node[t];n===this.activeCamera&&(this.activeCamera=null),this.forget(n),this.port.destroyNode(n);}sync(e){let t=this.renderables,n=this.transforms.store,r=t.count,o=0;for(let s=0;s<r;s++){let a=n.row(t.entities[s]);a!==-1&&(this.nodeIds[o]=t.fields.node[s],this.matrixRows[o]=a,o++);}this.port.writeNodeMatrices(this.nodeIds,n.fields.render,this.matrixRows,o),this.port.advanceAnimations(e);}render(e){this.scenery.frame(),this.port.render(e);}checkNode(e){let t=this.port.capabilities;if(e.kind==="skinned"&&!t.skinning&&this.unsupported("skinning"),e.kind==="instanced"&&!t.instancing&&this.unsupported("instancing"),e.kind==="particles"&&!t.particles&&this.unsupported("particles"),e.kind==="decal"&&!t.decals&&this.unsupported("decals"),e.kind==="camera"&&e.projection==="custom"&&!t.customProjection&&this.unsupported("custom projections"),e.kind==="light"&&e.light==="probe"&&e.sh!==void 0&&e.sh.length<mm)throw new _("invalid_argument",`light probes take ${mm} coefficients (9 RGB)`)}checkShader(e){if(!(this.port.capabilities.shaderLanguages.indexOf("wgsl")>=0)&&!e)throw new _("shader_requires_translation","this backend draws with WebGL2; the shader needs its admitted GLSL translation")}unsupported(e){throw new _("unsupported_feature",`${this.port.capabilities.backend} does not support ${e}`)}};var LYe="__cimplify_inspect";function tse(){let i=globalThis[LYe];return typeof i=="object"&&i!==null?i:null}var ese=new WeakSet;function ZD(i){let e=tse();if(e===null||ese.has(e))return null;let t=e.scene();return t===null||!i(t)?null:(ese.add(e),e.sceneApplied(t),t)}function nse(i,e){return ZD(e)??i}function rse(i){tse()?.sceneEntered?.(i);}var MYe=new Set(["name","systems","prefetch"]);function DYe(i,e){return Object.getPrototypeOf(i)?.constructor?.name===Object.getPrototypeOf(e)?.constructor?.name}function ose(i,e){if(typeof e.adopt=="function"){e.adopt(i);return}let t=i,n=e;for(let r of Object.keys(t))MYe.has(r)||typeof t[r]=="function"||!Object.prototype.hasOwnProperty.call(n,r)||(n[r]=t[r]);}function ise(i,e){if(i===void 0||e===void 0)return 0;let t=0;for(let n=0;n<Math.min(i.length,e.length);n++)DYe(i[n],e[n])&&(ose(i[n],e[n]),t++);return t}var $R=class{constructor(){this.scenes=new Map;this.globalSystems=[];this.active=null;this.pending=null;this.registered=e=>this.scenes.has(e);this.enterListeners=[];this.registerListeners=[];}register(e){if(this.scenes.has(e.name))throw new _("invalid_argument",`scene ${e.name} exists`);this.scenes.set(e.name,e);for(let t of this.registerListeners)t(e);}onEnter(e){this.enterListeners.push(e);}onRegister(e){this.registerListeners.push(e);for(let t of this.scenes.values())e(t);}has(e){return this.scenes.has(e)}addSystem(e){this.globalSystems.push(e);}replace(e){let t=this.scenes.get(e.name);return t===void 0?(this.register(e),false):(this.scenes.set(e.name,e),this.active===t&&(this.active=e),this.pending===t&&(this.pending=e),true)}replaceSystem(e,t){let n=this.globalSystems.indexOf(e);return n===-1?false:(this.globalSystems[n]=t,true)}removeSystem(e){let t=this.globalSystems.indexOf(e);return t===-1?false:(this.globalSystems.splice(t,1),true)}switchTo(e){let t=this.scenes.get(nse(e,this.registered));if(!t)throw new _("invalid_argument",`unknown scene ${e}`);this.pending=t;}get current(){return this.active?this.active.name:null}applyPending(e){let t=this.pending;if(t){this.pending=null,this.active?.exit?.(e),this.active=t;for(let n of this.enterListeners)n(t);rse(t.name),t.enter?.(e);}}reload(e,t){let n=[],r=[],o=0;for(let s of e.scenes??[]){let a=this.scenes.get(s.name);if(this.scenes.set(s.name,s),a===void 0){r.push(s.name);for(let l of this.registerListeners)l(s);continue}if(n.push(s.name),ose(a,s),o+=ise(a.systems,s.systems),this.pending===a&&(this.pending=s),this.active===a){this.active=s,s.reloaded?.(t);for(let l of s.systems??[])l.reloaded?.(t);}}if(e.systems!==void 0){o+=ise(this.globalSystems,e.systems),this.globalSystems.length=0;for(let s of e.systems)this.globalSystems.push(s),s.reloaded?.(t);}return {replaced:n,added:r,systems:o}}fixedUpdate(e){let t=this.globalSystems;for(let o=0;o<t.length;o++)t[o].fixedUpdate?.(e);let n=this.active;if(!n)return;let r=n.systems;if(r)for(let o=0;o<r.length;o++)r[o].fixedUpdate?.(e);n.fixedUpdate?.(e);}update(e){let t=this.globalSystems;for(let o=0;o<t.length;o++)t[o].update?.(e);let n=this.active;if(!n)return;let r=n.systems;if(r)for(let o=0;o<r.length;o++)r[o].update?.(e);n.update?.(e);}};var PYe=new Map;function jR(i){let e=Object.getPrototypeOf(i);e!==null&&PYe.set(e,i);}function sse(i){jR(i.graphics),jR(i.physics),jR(i.audio),jR(i.transforms);}var FYe="cimplify-gpu-probe ",UYe="__CIMPLIFY_GPU_PROBE__",BYe=64,wl=1<<18,eP=64,ase=eP+1024,tP=16,lse=tP+128,GYe=3,cse=7,VYe=1e9,HYe=1e6,WYe=2654435761,KYe=1065353216,YYe=0,ZR=1,Ase=2,Il=4294967295,XYe={x:"f32",y:"f32",table:"u32"},qYe=["x","y","table"],use={parts:1,instructions:0,gathers:0,transcendentals:0,stages:0,upload:0,readback:0,steps:0};function dse(){return globalThis.performance?.now()??0}function bse(i,e,t,n){let r=[256,512,2|AC|256],o=new Uint32Array(16+r.length+e.length+i.length);o[0]=827345731,o[1]=n,o[3]=t,o[4]=r.length,o[6]=e.length,o[8]=i.length/4,o[10]=Il,o[11]=Il,o[12]=Il,o[13]=Il;let s=16;for(let a of r)o[s++]=a>>>0;for(let a of e)o[s++]=a>>>0;return o.set(i,s),new Uint8Array(o.buffer)}function su(i,e,t,n,r=Il,o=Il){i.push((e|t<<8)>>>0,n>>>0,r>>>0,o>>>0);}function hse(i){let e=[];su(e,nt.LOAD,0,YYe);for(let t=0;t<i;t++)su(e,nt.FADD,0,0,2147483648);return su(e,nt.STORE,0,ZR,0),bse(e,[KYe],1,4)}function pse(i,e){let t=[];su(t,nt.ROW,0,Il);for(let n=0;n<i;n++)su(t,Ve|Da<<8,0,Ase,0,2147483648),su(t,nt.EXT,0,Il);return su(t,nt.STORE,0,ZR,0),bse(t,[e],1,4)}function zYe(i,e){return {meta:{id:`gpu-probe#${e}`,name:`gpu probe ${e}`,source:"gpu-probe",line:0,column:0,program:0,slots:qYe.map((n,r)=>({field:n,component:0,kind:r===Ase?"u32":"f32",read:r!==ZR,write:r===ZR,neighbour:false})),args:[],argWords:0,position:null,groups:0,behaviour:null,map:[]},program:i}}function JR(i,e){return {name:`gpu probe ${e}`,gpu:[zYe(i,e)],cpu:use,gpuShape:use}}var mse={cpuForm:"script",runCpu(){}};function fse(i,e,t,n){t.count=n;for(let o=0;o<GYe;o++)i.runSet(e,t,n,"gpu",mse);let r=[];for(let o=0;o<cse;o++){let s=dse();i.runSet(e,t,n,"gpu",mse),r.push(dse()-s);}return r.sort((o,s)=>o-s),r[cse>>1]}function QYe(i=Rv()){if(!i.gpuReady()||typeof globalThis.performance?.now!="function")return null;let e=i.partsTable(XYe,wl);if(e===null)return null;try{let t=e.values("x"),n=e.values("table");for(let h=0;h<wl;h++)t[h]=h,n[h]=Math.imul(h,WYe)+1&wl-1;let r=JR(hse(eP),"short ops"),o=JR(hse(ase),"long ops"),s=JR(pse(tP,wl),"short gathers"),a=JR(pse(lse,wl),"long gathers"),l=fse(i,r,e,BYe),c=h=>fse(i,h,e,wl)*VYe/wl,u=Math.max(0,c(o)-c(r))/(ase-eP),d=Math.max(0,c(a)-c(s))/(lse-tP);return {class:i.gpuClass(),rows:wl,setFixedNs:l*HYe,setOpPs:u,gatherPs:Math.max(0,d-u)}}finally{e.dispose();}}function $Ye(i=Rv()){let e=QYe(i);return console.info(`${FYe}${e===null?"unavailable":JSON.stringify(e)}`),e}var _se=false;function gse(i=Rv()){return _se||globalThis[UYe]!==true?null:(_se=true,$Ye(i))}var eXe=["unknown_species","bad_formula","duplicate_name","bad_name","too_many_terms","bad_count","element_imbalance","energy_mismatch","bad_rate","bad_window","property_out_of_range","book_full","policy_disabled","too_energetic","duplicate_term","bad_debris","bad_aqueous","catalyst_consumed","no_products","unreachable","bad_placement","bad_batch","unknown_element","no_reactants","overflow","malformed"],tXe={unknown_species:"a named substance is not in this world",bad_formula:"the chemical formula does not parse",duplicate_name:"that name is already taken",bad_name:"names are 1 to 32 letters, digits, underscores or dashes",too_many_terms:"at most four reactants and four products",bad_count:"coefficients are whole numbers from 1 to 16",element_imbalance:"atoms are not conserved: the two sides hold different elements",energy_mismatch:"the stated reaction energy disagrees with the substances' formation enthalpies",bad_rate:"activation energy or rate is outside the allowed range",bad_window:"the temperature window is empty or out of range",property_out_of_range:"a property is outside the stable range",book_full:"this world's chemistry book is full",policy_disabled:"this world does not allow that kind of chemistry",too_energetic:"the reaction releases more energy than this world allows",duplicate_term:"a substance appears twice on one side",bad_debris:"debris must have the same formula and enthalpy as the material",bad_aqueous:"a dissolved form must have the same formula and be aqueous",catalyst_consumed:"a catalyst cannot also be a reactant or product",no_products:"a reaction needs at least one product",unreachable:"the reaction needs a temperature this world cannot reach yet",bad_placement:"a product placement refers to a missing term",bad_batch:"batch is from 1 to 16",unknown_element:"the formula uses an element this world does not have",no_reactants:"a reaction needs at least one reactant",overflow:"amounts or energies overflow the simulation range",malformed:"the definition text is malformed"},Ese=["fuel","oxidiser","acid","base","metal","salt","ore","oxide","organic","aqueous","powder","catalyst","explosive","inert","solvent","carbonate","polymer","sugar","living","reducer","toxic","mineral","atmosphere","custom"],xse=["empty","gas","liquid","powder","solid"],Ise=["none","reaction","explosion","threshold","phase","fracture"],Fn=0,cy=4,vse=64,na=16,nXe=8,Rse=255,ly=256,rXe=1,iXe=0,oXe=1,sXe=0;function Ose(i,e){throw i===-1?new _("capacity_exceeded",`${e}: the engine is out of room`):i===-3?new _("unknown_resource",`${e}: unknown material, reaction or handle`):new _("invalid_argument",`${e}: the engine refused (${i})`)}function Lt(i,e){return i>=0?i:Ose(i,e)}var oP=class{constructor(e){this.engine=e;this.buffer=null;this.words=new Uint32Array(0);this.ints=new Int32Array(0);this.halves=new Uint16Array(0);this.bytes=new Uint8Array(0);}views(){let e=this.engine.memory.buffer;return e!==this.buffer&&(this.buffer=e,this.words=new Uint32Array(e),this.ints=new Int32Array(e),this.halves=new Uint16Array(e),this.bytes=new Uint8Array(e)),this}},uy=class{constructor(e,t={}){this.engine=e;this.nature=t;this.handle=Fn;this.scratch=Fn;this.opened=null;this.memory=null;this.names=new Map;this.encoder=new TextEncoder;this.decoder=new TextDecoder;}get available(){return this.engine!==null}ensure(){if(this.opened!==null)return this.opened;let e=this.engine;if(e===null)throw new _("unsupported_feature","this engine build has no chemistry (needs the chemistry_1 engine feature)");if(this.memory===null&&(this.memory=new oP(e)),this.scratch===Fn&&(this.scratch=e.exports.engine_alloc(vse*cy,na),this.scratch===Fn))throw new _("capacity_exceeded","engine memory cannot hold chemistry scratch");if(this.handle===Fn){let t=this.memory.views().words,n=this.scratch>>>2,r=this.nature;if(t[n]=r.tickHz??0,t[n+1]=r.ambientK??0,t[n+2]=r.pressureAtm===void 0?4294967295:Math.round(r.pressureAtm*ly),t[n+3]=r.gravity===void 0?4294967295:Math.round(r.gravity*ly),t[n+4]=r.conduction===void 0?4294967295:Math.round(r.conduction*ly),t[n+5]=Math.round((r.rateShift??0)*ly)>>>0,t[n+6]=r.radiation===void 0?4294967295:Math.round(r.radiation*ly),t[n+7]=r.atmosphere==="mars"?oXe:sXe,this.handle=e.exports.engine_chemistry_open(this.scratch),this.handle===Fn)throw new _("invalid_argument","the engine refused these nature parameters")}return this.opened={engine:e,memory:this.memory,handle:this.handle,scratch:this.scratch},this.opened}get handleValue(){return this.ensure().handle}withText(e,t){let{engine:n,memory:r}=this.ensure(),o=this.encoder.encode(e),s=Math.max(o.length,1),a=n.exports.engine_alloc(s,na);if(a===Fn)throw new _("capacity_exceeded","engine memory cannot hold the text");try{return r.views().bytes.set(o,a),t(a,o.length)}finally{n.exports.engine_free(a,s,na);}}define(e,t={}){let{engine:n,handle:r}=this.ensure(),o=this.withText(e,(l,c)=>n.exports.engine_chemistry_define(r,l,c,t.proposal===true?rXe:iXe));if(o>=0)return this.names.clear(),{ok:true,added:o};let s=-o;(s&65536)===0&&Ose(o,"define");let a=eXe[(s&Rse)-1]??"malformed";return {ok:false,line:s>>nXe&Rse,refusal:a,reason:tXe[a]}}find(e,t){let n=`${e}:${t}`,r=this.names.get(n);if(r!==void 0)return r;let{engine:o,handle:s}=this.ensure(),a=this.withText(t,(l,c)=>o.exports.engine_chemistry_find(s,e,l,c));if(a<0)throw new _("unknown_resource",`${e===0?"material":"reaction"} ${t} is not in this world`);return this.names.set(n,a),a}material(e){return this.find(0,e)}hasMaterial(e){try{return this.find(0,e),!0}catch{return false}}reaction(e){return this.find(1,e)}get counts(){let{engine:e,handle:t}=this.ensure(),n=e.exports.engine_chemistry_counts(t)>>>0;return {materials:n&65535,reactions:n>>>16}}text(e,t){let{engine:n,memory:r,handle:o}=this.ensure(),s=Lt(n.exports.engine_chemistry_catalog(o,e,t),"catalog"),a=n.exports.engine_chemistry_text(o);return this.decoder.decode(r.views().bytes.slice(a,a+s))}catalog(){return this.text(0,0)}materialName(e){return this.text(1,e)}reactionName(e){return this.text(2,e)}materialInfo(e){let{engine:t,memory:n,handle:r,scratch:o}=this.ensure();Lt(t.exports.engine_chemistry_species_info(r,e,o),"material info");let s=n.views().words,a=o>>>2,l=aXe(s[a+4]);return {id:e,name:this.materialName(e),molarMassGrams:s[a]/1e3,meltK:s[a+2]===0?null:s[a+2],boilK:s[a+3]===0?null:s[a+3],ignitionK:s[a+12]===0?null:s[a+12],groups:l,colours:[s[a+5],s[a+6],s[a+7]],density:[s[a+8]&65535,s[a+8]>>>16],heatCapacity:[s[a+10]&65535,s[a+10]>>>16,s[a+11]&65535],volume:s[a+11]>>>16&255,hardness:s[a+15]&65535,electrical:s[a+15]>>>16,strengthKpa:s[a+13]}}reactionInfo(e){let{engine:t,memory:n,handle:r,scratch:o}=this.ensure();Lt(t.exports.engine_chemistry_reaction_info(r,e,o),"reaction info");let s=n.views().words,a=o>>>2,l=[],c=[];for(let h=0;h<4;h++){let p=s[a+h];(p&65535)!==0&&l.push({material:p&65535,count:p>>>16&255});let m=s[a+4+h];(m&65535)!==0&&c.push({material:m&65535,count:m>>>16&255});}let u=s[a+11],d=n.ints[a+12];return {id:e,name:this.reactionName(e),reactants:l,products:c,catalyst:s[a+8]===0?null:s[a+8],minK:s[a+9],maxK:s[a+10]===4294967295?null:s[a+10],enthalpyJ:d*4294967296+u,electricJ:s[a+13],generatesJ:s[a+14]}}region(e){let{engine:t,handle:n}=this.ensure(),r=e.depth??1,o=t.exports.engine_chemistry_grid_open(n,e.width,e.height,r,(e.seed??0)>>>0,e.open===true?1:0);if(o===Fn)throw new _("invalid_argument",`a ${e.width}x${e.height}x${r} region is outside the limits`);return new tS(this,t,o)}loadRegion(e,t={}){let{engine:n,memory:r,handle:o}=this.ensure(),s=Math.max(e.length,1),a=n.exports.engine_alloc(s,na);if(a===Fn)throw new _("capacity_exceeded","engine memory cannot hold the saved region");try{r.views().bytes.set(e,a);let l=n.exports.engine_chemistry_grid_load(o,a,e.length,(t.seed??0)>>>0,t.open===!0?1:0);if(l===Fn)throw new _("asset_load_failed","the saved region does not match this world's chemistry");return new tS(this,n,l)}finally{n.exports.engine_free(a,s,na);}}vessel(e=1,t=0){let{engine:n}=this.ensure();return new sP(this,n,n.exports.engine_chemistry_vessel_open(e,t>>>0))}particles(e,t=0){let{engine:n}=this.ensure();return new aP(this,n,n.exports.engine_chemistry_particles_open(e,t>>>0),e)}scratchWords(){let{memory:e,scratch:t}=this.ensure();return e.views(),{words:e.words,ints:e.ints,at:t>>>2,pointer:t}}views(){return this.ensure().memory.views()}dispose(){this.engine!==null&&(this.handle!==Fn&&this.engine.exports.engine_chemistry_close(this.handle),this.scratch!==Fn&&this.engine.exports.engine_free(this.scratch,vse*cy,na),this.handle=Fn,this.scratch=Fn,this.opened=null);}};function eS(i,e){let t=i.scratchWords(),n=t.words;return n[t.at]=e.x0,n[t.at+1]=e.y0,n[t.at+2]=e.z0??0,n[t.at+3]=e.x1,n[t.at+4]=e.y1,n[t.at+5]=e.z1??1,t.pointer}var tS=class{constructor(e,t,n){this.chemistry=e;this.engine=t;this.handle=n;this.columns=new Uint32Array(16);this.buffer=null;this.speciesViews=[];this.amountViews=[];this.heatView=new Int32Array(0);this.tempView=new Int32Array(0);this.infoView=new Uint32Array(0);this.powerView=new Uint32Array(0);this.colourView=new Uint32Array(0);this.disposed=false;this.event={kind:"none",code:0,cell:0,x:0,y:0,z:0,value:0,extra:0};this.probeOut={cls:"empty",kelvin:0,pressureAtm:0,materials:[0,0,0,0],amounts:[0,0,0,0],heat:0,power:0};let r=e.views(),o=t.exports.engine_chemistry_grid_columns(n)>>>2;this.columns.set(r.words.subarray(o,o+16)),this.width=this.columns[13],this.height=this.columns[14],this.depth=this.columns[15],this.cells=this.width*this.height*this.depth;}live(){if(this.disposed)throw new _("unknown_resource","this chemistry region was disposed");return this.handle}refresh(){let e=this.engine.memory.buffer;if(e===this.buffer)return;this.buffer=e;let t=this.columns,n=this.cells;this.speciesViews=[],this.amountViews=[];for(let r=0;r<4;r++)this.speciesViews.push(new Uint16Array(e,t[r],n)),this.amountViews.push(new Uint16Array(e,t[4+r],n));this.heatView=new Int32Array(e,t[8],n),this.tempView=new Int32Array(e,t[9],n),this.infoView=new Uint32Array(e,t[10],n),this.powerView=new Uint32Array(e,t[11],n),this.colourView=new Uint32Array(0);}index(e,t,n=0){return e+t*this.width+n*this.width*this.height}species(e=0){return this.refresh(),this.speciesViews[e]}amounts(e=0){return this.refresh(),this.amountViews[e]}get heat(){return this.refresh(),this.heatView}get temperatureQ4(){return this.refresh(),this.tempView}get info(){return this.refresh(),this.infoView}get power(){return this.refresh(),this.powerView}kelvinAt(e,t,n=0){return this.temperatureQ4[this.index(e,t,n)]/16}classAt(e,t,n=0){return xse[this.info[this.index(e,t,n)]&7]??"empty"}fill(e,t,n=0){let r=e==="air"?0:e==="vacuum"?4294967295:e,o=eS(this.chemistry,t);return Lt(this.engine.exports.engine_chemistry_grid_paint(this.live(),this.chemistry.handleValue,o,r,n>0?n:293),"fill")}paint(e,t,n,r=0,o=0){return this.fill(e,{x0:t,y0:n,z0:r,x1:t+1,y1:n+1,z1:r+1},o)}set(e,t,n,r,o){let s=this.chemistry.scratchWords();for(let a=0;a<4;a++){let l=r[a];s.words[s.at+a]=l===void 0?0:(l[0]&65535|(l[1]&65535)<<16)>>>0;}Lt(this.engine.exports.engine_chemistry_grid_set(this.live(),this.chemistry.handleValue,e,t,n,s.pointer,o),"set");}heatBox(e,t){let n=eS(this.chemistry,e);return Lt(this.engine.exports.engine_chemistry_grid_heat(this.live(),this.chemistry.handleValue,n,t|0),"heat")}powerBox(e,t){let n=eS(this.chemistry,e);return Lt(this.engine.exports.engine_chemistry_grid_power(this.live(),n,t>>>0),"power")}step(e=1){return Lt(this.engine.exports.engine_chemistry_grid_step(this.live(),this.chemistry.handleValue,e),"step")}colours(){let e=this.engine.exports.engine_chemistry_grid_colours(this.live(),this.chemistry.handleValue);return this.refresh(),(this.colourView.length===0||this.colourView.byteOffset!==e)&&(this.colourView=new Uint32Array(this.engine.memory.buffer,e,this.cells)),this.colourView}probe(e,t,n=0){let r=this.chemistry.scratchWords();Lt(this.engine.exports.engine_chemistry_grid_probe(this.live(),this.chemistry.handleValue,e,t,n,r.pointer),"probe");let o=this.chemistry.scratchWords().words,s=this.probeOut;s.cls=xse[o[r.at]&7]??"empty",s.kelvin=(o[r.at+1]|0)/16,s.pressureAtm=o[r.at+2]/256;for(let a=0;a<4;a++)s.materials[a]=o[r.at+3+a]&65535,s.amounts[a]=o[r.at+3+a]>>>16;return s.heat=o[r.at+7]|0,s.power=o[r.at+8],s}watchReaction(e,t=true){Lt(this.engine.exports.engine_chemistry_grid_watch(this.live(),0,e,t?1:0),"watch");}watchMaterial(e,t=true){Lt(this.engine.exports.engine_chemistry_grid_watch(this.live(),1,e,t?1:0),"watch");}threshold(e,t){let n=eS(this.chemistry,e);return Lt(this.engine.exports.engine_chemistry_grid_threshold(this.live(),n,t),"threshold")}clearThreshold(e){Lt(this.engine.exports.engine_chemistry_grid_unthreshold(this.live(),e),"threshold");}events(e){let t=this.engine.exports.engine_chemistry_grid_events(this.live())>>>2,n=this.chemistry.views().words,r=n[t],o=this.event,s=this.width*this.height;for(let a=0;a<r;a++){let l=t+2+a*4;o.kind=Ise[n[l]&65535]??"none",o.code=n[l]>>>16,o.cell=n[l+1],o.z=Math.floor(o.cell/s),o.y=Math.floor((o.cell-o.z*s)/this.width),o.x=o.cell-o.z*s-o.y*this.width,o.value=n[l+2]|0,o.extra=n[l+3]|0,e(o);}return this.engine.exports.engine_chemistry_grid_clear_events(this.handle),r}fired(e){let t=this.engine.exports.engine_chemistry_grid_fired(this.live())>>>2;return this.chemistry.views().words[t+e]}stats(e={tick:0,activeTiles:0,blocks:0,fired:0,moves:0,massMilligrams:0,energyJ:0,events:0,dropped:0,digest:""}){let t=this.chemistry.scratchWords();Lt(this.engine.exports.engine_chemistry_grid_stats(this.live(),this.chemistry.handleValue,t.pointer),"stats");let n=this.chemistry.scratchWords().words,r=this.chemistry.scratchWords().ints,o=t.at;return e.tick=n[o+1]*4294967296+n[o],e.digest=n[o+3].toString(16).padStart(8,"0")+n[o+2].toString(16).padStart(8,"0"),e.activeTiles=n[o+4],e.blocks=n[o+5],e.fired=n[o+6],e.moves=n[o+7],e.massMilligrams=r[o+9]*4294967296+n[o+8],e.energyJ=r[o+11]*4294967296+n[o+10],e.events=n[o+12],e.dropped=n[o+13],e}save(){let e=Lt(this.engine.exports.engine_chemistry_grid_save(this.live(),this.chemistry.handleValue),"save"),t=this.engine.exports.engine_chemistry_grid_saved(this.handle);return this.chemistry.views().bytes.slice(t,t+e)}dispose(){this.disposed||(this.disposed=true,this.engine.exports.engine_chemistry_grid_close(this.handle));}},sP=class{constructor(e,t,n){this.chemistry=e;this.engine=t;this.handle=n;this.disposed=false;this.out={kelvin:0,pressureAtm:0,power:0,generated:0,materials:[],amounts:[]};}live(){if(this.disposed)throw new _("unknown_resource","this vessel was disposed");return this.handle}add(e,t,n=293){Lt(this.engine.exports.engine_chemistry_vessel_add(this.live(),this.chemistry.handleValue,e,t,n),"vessel add");}take(e,t){return Lt(this.engine.exports.engine_chemistry_vessel_take(this.live(),this.chemistry.handleValue,e,t),"vessel take")}heat(e){Lt(this.engine.exports.engine_chemistry_vessel_heat(this.live(),this.chemistry.handleValue,e|0),"vessel heat");}power(e){return Lt(this.engine.exports.engine_chemistry_vessel_power(this.live(),e>>>0),"vessel power")}step(e=1){return Lt(this.engine.exports.engine_chemistry_vessel_step(this.live(),this.chemistry.handleValue,e),"vessel step")}vent(e){return Lt(this.engine.exports.engine_chemistry_vessel_vent(this.live(),this.chemistry.handleValue,Math.round(e*256)),"vessel vent")}state(){let e=this.chemistry.scratchWords();Lt(this.engine.exports.engine_chemistry_vessel_state(this.live(),this.chemistry.handleValue,e.pointer),"vessel state");let t=this.chemistry.scratchWords().words,n=this.out;n.kelvin=(t[e.at]|0)/16,n.pressureAtm=t[e.at+1]/256,n.power=t[e.at+2],n.generated=t[e.at+3],n.materials.length=0,n.amounts.length=0;for(let r=0;r<16;r++){let o=t[e.at+5+2*r];o!==0&&(n.materials.push(t[e.at+4+2*r]),n.amounts.push(o));}return n}dispose(){this.disposed||(this.disposed=true,this.engine.exports.engine_chemistry_vessel_close(this.handle));}},aP=class{constructor(e,t,n,r){this.chemistry=e;this.engine=t;this.handle=n;this.capacity=r;this.disposed=false;this.pairs=0;this.pairCapacity=0;this.event={kind:"none",code:0,cell:0,x:0,y:0,z:0,value:0,extra:0};}live(){if(this.disposed)throw new _("unknown_resource","these particles were disposed");return this.handle}spawn(e,t,n=293){Lt(this.engine.exports.engine_chemistry_particles_spawn(this.live(),this.chemistry.handleValue,e,t,n),"particle spawn");}despawn(e){Lt(this.engine.exports.engine_chemistry_particles_spawn(this.live(),this.chemistry.handleValue,e,4294967295,0),"particle despawn");}step(e,t,n){let r=Math.max(n*2,2);if(r>this.pairCapacity&&(this.pairs!==Fn&&this.engine.exports.engine_free(this.pairs,this.pairCapacity*cy,na),this.pairCapacity=r*2,this.pairs=this.engine.exports.engine_alloc(this.pairCapacity*cy,na),this.pairs===Fn))throw new _("capacity_exceeded","engine memory cannot hold the particle pairs");return this.chemistry.views().words.set(t.subarray(0,n*2),this.pairs>>>2),Lt(this.engine.exports.engine_chemistry_particles_step(this.live(),this.chemistry.handleValue,e,this.pairs,n),"particle step")}columns(){let e=this.engine.exports.engine_chemistry_particles_columns(this.live())>>>2;return this.chemistry.views().words.subarray(e,e+16)}events(e){let t=this.engine.exports.engine_chemistry_particles_events(this.live())>>>2,n=this.chemistry.views().words,r=n[t],o=this.event;for(let s=0;s<r;s++){let a=t+2+s*4;o.kind=Ise[n[a]&65535]??"none",o.code=n[a]>>>16,o.cell=n[a+1],o.x=o.cell,o.y=0,o.z=0,o.value=n[a+2]|0,o.extra=n[a+3]|0,e(o);}return r}dispose(){this.disposed||(this.disposed=true,this.pairs!==Fn&&this.engine.exports.engine_free(this.pairs,this.pairCapacity*cy,na),this.engine.exports.engine_chemistry_particles_close(this.handle));}};function aXe(i){let e=[];for(let t=0;t<Ese.length;t++)(i&1<<t)!==0&&e.push(Ese[t]);return e}var Cse=fh("transform",{position:["f32",3],rotation:["f32",4],scale:["f32",3],previousPosition:["f32",3],previousRotation:["f32",4],previousScale:["f32",3],parent:"u32",render:["f32",16]});function lXe(i){let e=i.fields;return {capacity:i.capacity,position:e.position,rotation:e.rotation,scale:e.scale,previousPosition:e.previousPosition,previousRotation:e.previousRotation,previousScale:e.previousScale,parent:e.parent,render:e.render,entities:i.entities,sparse:i.sparse}}var nS=class{constructor(e,t){this.hierarchyVersion=0;this.world=e,this.port=t,this.store=e.register(Cse),this.columns=lXe(this.store),t.bind(this.columns),e.onDespawn(this);}add(e,t=0,n=0,r=0){let o=this.world.add(e,Cse),s=this.store.fields,a=o*3,l=o*4;return s.position[a]=t,s.position[a+1]=n,s.position[a+2]=r,s.rotation[l+3]=1,s.scale[a]=1,s.scale[a+1]=1,s.scale[a+2]=1,s.parent[o]=4294967295,this.teleportRow(o),this.hierarchyVersion++,o}onDespawn(e){let t=this.store.fields.parent,n=this.store.count;for(let r=0;r<n;r++)t[r]===e&&(t[r]=4294967295);this.hierarchyVersion++;}row(e){return this.store.require(e)}setPosition(e,t,n,r){let o=this.row(e)*3,s=this.store.fields.position;s[o]=t,s[o+1]=n,s[o+2]=r;}setRotation(e,t,n,r,o){let s=this.row(e)*4,a=this.store.fields.rotation;a[s]=t,a[s+1]=n,a[s+2]=r,a[s+3]=o;}setRotationQuat(e,t){this.setRotation(e,t.x,t.y,t.z,t.w);}setScale(e,t,n,r){let o=this.row(e)*3,s=this.store.fields.scale;s[o]=t,s[o+1]=n,s[o+2]=r;}translate(e,t){let n=this.row(e)*3,r=this.store.fields.position;r[n]+=t.x,r[n+1]+=t.y,r[n+2]+=t.z;}position(e,t){return t.readFrom(this.store.fields.position,this.row(e)*3)}rotation(e,t){return t.readFrom(this.store.fields.rotation,this.row(e)*4)}renderPosition(e,t){let n=this.row(e)*16,r=this.store.fields.render;return t.set(r[n+12],r[n+13],r[n+14])}setParent(e,t){let n=this.row(e),r=this.store.fields.parent;if(t===Hs)r[n]=4294967295;else {if(this.row(t),t===e)throw new _("invalid_argument","an entity cannot parent itself");r[n]=t;}this.hierarchyVersion++;}parentOf(e){let t=this.store.fields.parent[this.row(e)];return t===4294967295?Hs:t}teleport(e){this.teleportRow(this.row(e));}snapshot(){this.port.snapshot(this.store.count);}computeRender(e){this.port.computeRender(this.store.count,e,this.hierarchyVersion+this.store.version);}teleportRow(e){let t=this.store.fields,n=e*3,r=e*4;for(let o=0;o<3;o++)t.previousPosition[n+o]=t.position[n+o],t.previousScale[n+o]=t.scale[n+o];for(let o=0;o<4;o++)t.previousRotation[r+o]=t.rotation[r+o];}};var uXe=-1,rS=class{constructor(e,t=64){this.layout=[];this.dirtyCount=0;this.declaredSize=-1;this.actions=new Map;this.queue=new Int16Array(128);this.queueHead=0;this.queueCount=0;this.host=e,this.numbers=new Float64Array(t),this.texts=Array.from({length:t},()=>""),this.dirtyFlags=new Uint8Array(t),this.dirty=new Uint16Array(t);}hudNumber(e,t=0){let n=this.declare(e,"number");return this.setNumber(n,t),n}hudText(e,t=""){let n=this.declare(e,"text");return this.setText(n,t),n}setNumber(e,t){this.numbers[e]===t&&this.dirtyFlags[e]===0||(this.numbers[e]=t,this.markDirty(e));}setText(e,t){this.texts[e]===t&&this.dirtyFlags[e]===0||(this.texts[e]=t,this.markDirty(e));}number(e){return this.numbers[e]}text(e){return this.texts[e]}show(e,t={}){this.host?.showPanel(e,t);}hide(e){this.host?.hidePanel(e);}haptic(e){this.host?.haptic(e);}defineAction(e){let t=this.actions.get(e);if(t!==void 0)return t;if(this.actions.size>=128)throw new _("capacity_exceeded",`at most ${128} ui actions`);let n=this.actions.size;return this.actions.set(e,n),n}dispatch(e){let t=this.actions.get(e);if(t===void 0||this.queueCount>=128)return false;let n=(this.queueHead+this.queueCount)%128;return this.queue[n]=t,this.queueCount++,true}pollAction(){if(this.queueCount===0)return uXe;let e=this.queue[this.queueHead];return this.queueHead=this.queueHead+1===128?0:this.queueHead+1,this.queueCount--,e}flush(){if(!this.host){this.clearDirty();return}this.declaredSize!==this.layout.length&&(this.declaredSize=this.layout.length,this.host.declareHud(this.layout)),this.dirtyCount!==0&&(this.host.publishHud(this.numbers,this.texts,this.dirty,this.dirtyCount),this.clearDirty());}declare(e,t){if(this.layout.length>=this.numbers.length)throw new _("capacity_exceeded",`at most ${this.numbers.length} hud slots`);return this.layout.push({name:e,kind:t}),this.layout.length-1}markDirty(e){this.dirtyFlags[e]!==1&&(this.dirtyFlags[e]=1,this.dirty[this.dirtyCount++]=e);}clearDirty(){for(let e=0;e<this.dirtyCount;e++)this.dirtyFlags[this.dirty[e]]=0;this.dirtyCount=0;}};var dXe=[],hXe=[],iS=-1,pXe=30,mXe=600,fXe=5,_Xe=16,yXe=8,AXe=1/60,oS=1024,lP=-1,bXe=68,Nse=72,gXe=8,EXe=12,xXe=16,vXe=20,Pse=24,Fse=36,RXe=100,SXe=1145853763,kse=3,sS=4,Lse=132,TXe=124,wXe=156,IXe=1413764931,Use=4,OXe=44,Bse=48,CXe=96,NXe=120,aS=72,Gse=60,kXe=64,LXe=68,cP=8,Mse=4294967295,MXe=92,DXe=1.5,Vse=4294967295,PXe=1447974723,Hse=16,FXe=16,UXe=8,BXe=12,GXe=.9;function Wse(i){if(i.byteLength<NXe)throw new _("invalid_argument","the world file is shorter than its header");let e=new DataView(i.buffer,i.byteOffset,i.byteLength),t=e.getUint32(Use,true);if(e.getUint32(0,true)!==SXe||t!==kse&&t!==sS)throw new _("invalid_argument",`the world file is not world format ${kse} or ${sS}; bake it again with engine-world`);let n=e.getUint32(vXe,true),r=n*e.getUint32(Pse,true),o=t===sS,s=e.getUint32(Bse,true);if(!o&&s+r*aS>i.byteLength)throw new _("invalid_argument","the world file's cell table runs past its end");let a=o?r:0;if(!o)for(let l=0;l<r;l++)e.getUint32(s+l*aS+Gse,true)!==Vse&&a++;return {cellSize:e.getFloat32(gXe,true),origin:[e.getFloat32(EXe,true),e.getFloat32(xXe,true)],cols:n,meshPacks:e.getUint32(OXe,true),navPacks:e.getUint32(CXe,true),navTiles:a,partitioned:o}}function VXe(i,e){let t=Wse(i),n=new DataView(i.buffer,i.byteOffset,i.byteLength);if(t.partitioned)return HXe(t,n,e);let r=n.getUint32(Bse,true),o=t.cols*n.getUint32(Pse,true),s=t.meshPacks,a=new Float64Array(s),l=new Float64Array(s),c=new Uint32Array(s),u=new Int32Array(s).fill(-1),d=new Int32Array(s).fill(-1),h=new Float64Array(s),p=new Float64Array(s),m=new Uint32Array(s),f=t.cellSize/2,y=I=>[t.origin[0]+I%t.cols*t.cellSize+f,t.origin[1]+Math.floor(I/t.cols)*t.cellSize+f];for(let I=0;I<o;I++){let S=r+I*aS,w=n.getUint32(S,true);if(w>=s)throw new _("invalid_argument",`cell ${I} names pack ${w} of ${s}`);let[U,L]=y(I);a[w]+=U,l[w]+=L,c[w]++;let k=n.getUint32(S+Gse,true);k!==Vse&&(u[w]=k);let M=n.getUint32(S+kXe,true);M!==Mse&&M!==w&&(d[w]=M);let K=n.getUint32(S+LXe,true);K!==Mse&&K<s&&(h[K]+=U,p[K]+=L,m[K]++);}let b=new Float64Array(s),A=f*Math.SQRT2;for(let I=0;I<o;I++){let S=n.getUint32(r+I*aS,true),[w,U]=y(I),L=Math.hypot(w-a[S]/c[S],U-l[S]/c[S])+A;L>b[S]&&(b[S]=L);}let E=n.getFloat32(Fse,true),R=n.getFloat32(RXe,true),g=Math.min(E,Math.max(0,n.getFloat32(MXe,true))*DXe),v=I=>R>0?Math.max(0,R-I):E,x=I=>e.bytes?.(I)??0,O=[];for(let I=0;I<s;I++){if(c[I]===0)continue;let S=e.paths[I];if(S===void 0)throw new _("invalid_argument",`no path for world pack ${I}`);let w=[{path:S,bytes:x(S)}],U=d[I]>=0?e.paths[d[I]]:void 0;U!==void 0&&w.push({path:U,within:g,bytes:x(U)});let L=u[I]>=0?e.paths[s+u[I]]:void 0;L!==void 0&&w.push({path:L,within:v(b[I]),bytes:x(L)}),O.push({center:[a[I]/c[I],0,l[I]/c[I]],radius:b[I],levels:w});}let N=cP*t.cellSize*Math.SQRT1_2;for(let I=0;I<s;I++){if(m[I]===0)continue;let S=e.paths[I];if(S===void 0)throw new _("invalid_argument",`no path for world proxy pack ${I}`);O.push({center:[h[I]/m[I],0,p[I]/m[I]],radius:N,levels:[{path:S,bytes:x(S)}]});}return {name:e.name??"world",items:O,radius:E,cellSize:t.cellSize}}function HXe(i,e,t){let n=e.getUint32(TXe,true),r=Math.ceil(i.cols/cP),o=cP*i.cellSize,s=t.paths.length-2*n-(e.getUint32(wXe,true)===1?1:0);if(s<0)throw new _("invalid_argument",`the world names ${n} districts but there are ${t.paths.length} paths`);let a=[];for(let l=0;l<n;l++){let c=t.paths[s+l],u=[i.origin[0]+(l%r+.5)*o,0,i.origin[1]+(Math.floor(l/r)+.5)*o];a.push({center:u,radius:o*Math.SQRT1_2,levels:[{path:c,bytes:t.bytes?.(c)??0}]});}return {name:t.name??"world",items:a,radius:e.getFloat32(Fse,true),cellSize:i.cellSize}}function WXe(i){return i.byteLength>=4&&new DataView(i.buffer,i.byteOffset,i.byteLength).getUint32(0,true)===IXe}function KXe(i){if(i.byteLength<Hse)return -1;let e=new DataView(i.buffer,i.byteOffset,i.byteLength);return e.getUint32(0,true)===PXe?e.getUint32(BXe,true):-1}function Dse(i,e){let t=new DataView(i.buffer,i.byteOffset,i.byteLength),n=t.getUint32(UXe,true);for(let r=0;r<n;r++){let o=Hse+r*FXe,s=t.getUint32(o+4,true);e(t.getUint32(o,true),i.subarray(s,s+t.getUint32(o+8,true)));}}function YXe(i){let e=new DataView(i.buffer,i.byteOffset,i.byteLength);if(i.byteLength<Nse+4)return 0;if(e.getUint32(Use,true)===sS)return i.byteLength>=Lse+4?e.getUint32(Lse,true):0;let t=e.getUint32(bXe,true);return e.getUint32(Nse,true)<4||t+4>i.byteLength?0:e.getUint32(t,true)}var uP=class{constructor(e){this.read=e;}get live(){return this.read()[Ar.live]}get loading(){return this.read()[Ar.loading]}get waiting(){return this.read()[Ar.waiting]}get failed(){return this.read()[Ar.failed]}get inflight(){return this.read()[Ar.inflight]}get installed(){return this.read()[Ar.installed]}get installedBytes(){return this.read()[Ar.installedBytes]}get evicted(){return this.read()[Ar.evicted]}get residentBytes(){return this.read()[Ar.residentKib]*oS}get poolBytes(){return this.read()[Ar.poolKib]*oS}get proxyBytes(){return this.read()[Ar.proxyKib]*oS}get sourceBytes(){return this.read()[Ar.sourceKib]*oS}get totalInstalls(){return this.read()[Ar.totalInstalls]}},dP=class{constructor(e,t,n,r,o,s,a,l=false){this.port=e;this.handle=t;this.physics=r;this.world=o;this.transforms=s;this.lazy=l;this.eye=new Float32Array(qf);this.collider=new Float32Array(sh);this.extents=[0,0,0];this.offset=[0,0,0];this.rotation=[0,0,0,1];this.actorCount=0;this.waitingEager=[];this.collidersWaiting=false;this.closed=false;this.registers=null;this.anchor=null;this.frames=0;this.navTarget=null;this.navTileCount=0;this.paths=n.packPaths??dXe,this.reader=n.assets??null;let c=l?this.paths.length:0;this.kept=Array.from({length:c},()=>null),this.contended=Array.from({length:c},()=>null),this.fetching=new Uint8Array(c),this.dropped=new Uint8Array(c),this.retryAt=new Int32Array(c).fill(iS),this.retryPriority=new Uint8Array(c),this.backoff=new Uint16Array(c),this.stats=new uP(()=>this.view()),this.worldBytes=n.world,this.shape=Wse(n.world),this.navHeld=Array.from({length:this.shape.navPacks},()=>null),this.navLoaded=new Uint8Array(this.shape.navPacks);let u=n.colliders===false?null:n.colliders??{},d=u?.actors??yXe,h=u?.budget??_Xe;this.actorBuffer=new Float32Array(d*Fs),this.ops=new Uint32Array(u&&r&&a>0?h:0),this.physicsOf=new Int32Array(this.ops.length>0?a:0).fill(lP),this.desc={shape:{kind:"cuboid",halfExtents:this.extents},offset:this.offset,rotation:this.rotation,friction:GXe},this.ops.length>0&&e.openLogic(t,u?.stepSeconds??AXe,h,d);let p=this.reader,m=n.packs??(l||p===null?hXe:this.paths.map((f,y)=>p.take(f,y===nJ?eJ:tJ)));this.ready=this.feed(m);}servePacks(){let e=this.view(),t=Math.min(e[$j],Ik);for(let o=0;o<t;o++){let s=e[Ck+o];this.request(s&rJ,s>>>kk);}let n=Math.min(e[jj],Ok);for(let o=0;o<n;o++){let s=e[Nk+o];s>=this.shape.meshPacks&&this.dropNav(s-this.shape.meshPacks),s<this.dropped.length&&(this.dropped[s]=this.fetching[s],this.retryAt[s]=iS);let a=this.paths[s];a!==void 0&&this.reader?.lazy?.(a)===true&&this.reader.release?.(a);}for(let o=0;o<this.contended.length;o++){let s=this.contended[o];s!==null&&this.providePack(o,s);}let r=this.retryAt;for(let o=0;o<r.length;o++)r[o]===iS||r[o]>this.frames||(r[o]=iS,this.request(o,this.retryPriority[o]));}request(e,t){let n=this.paths[e],r=this.reader;if(n===void 0||r===null||(this.dropped[e]=0,this.fetching[e]!==0))return;let o=this.kept[e];if(o!==null){this.providePack(e,o);return}this.fetching[e]=1;let s=()=>{if(this.fetching[e]=0,this.dropped[e]!==0){this.dropped[e]=0;return}let c=Math.min(pXe<<this.backoff[e],mXe);this.backoff[e]=Math.min(this.backoff[e]+1,fXe),this.retryAt[e]=this.frames+c,this.retryPriority[e]=t;},a=c=>{this.fetching[e]=0,this.backoff[e]=0,r.lazy?.(n)!==true&&(this.kept[e]=c);},l=c=>{this.dropped[e]===0&&this.providePack(e,c);};if(r.progressive!==void 0&&r.isProgressive?.(n)===true){r.progressive(n,l,t).done.then(c=>{this.dropped[e]=0,a(c);},s);return}r.take(n,t).then(c=>{a(c),l(c),this.dropped[e]=0;},s);}providePack(e,t){if(!this.closed)try{this.contended[e]=this.port.provide(this.handle,t)===Ic?t:null,this.holdNav(t);}catch{this.kept[e]=null,this.contended[e]=null;}}holdNav(e){let t=KXe(e);t<0||t>=this.navHeld.length||(this.navHeld[t]=e,this.loadNavPack(t));}loadNavPack(e){let t=this.navTarget,n=this.navHeld[e];t===null||n===null||this.navLoaded[e]!==0||(this.navLoaded[e]=1,Dse(n,(r,o)=>{t.addTile(o),this.navTileCount++;}));}dropNav(e){let t=this.navHeld[e];if(this.navHeld[e]=null,t===null||this.navLoaded[e]===0)return;this.navLoaded[e]=0;let n=this.navTarget;if(n===null)return;let r=this.shape.cols;Dse(t,o=>{n.removeTile(o%r,Math.floor(o/r)),this.navTileCount--;});}async feed(e){if(e.length!==0){this.provide(await e[0]);for(let t=1;t<e.length;t++){let n=e[t];n instanceof Uint8Array?this.provide(n):n.then(r=>this.provide(r),()=>{});}}}provide(e){if(!this.closed){if(this.port.provide(this.handle,e)===Ic){this.waitingEager.push(e);return}if(this.holdNav(e),WXe(e)&&this.waitingEager.length>0)for(let t of this.waitingEager.splice(0))this.provide(t);}}view(){if(this.closed)throw new _("unknown_resource","world stream is closed");let e=this.registers;return e!==null&&e.byteLength>0?e:(this.registers=this.port.registers(this.handle),this.registers)}update(e,t){if(this.closed)return;let n=this.eye;n[0]=e.x,n[1]=e.y,n[2]=e.z,n[3]=t.x,n[4]=t.y,n[5]=t.z,this.port.update(this.handle,n),this.lazy&&(this.frames++,this.servePacks());}get streamsOnRequest(){return this.lazy}setActor(e,t){let n=e*Fs;if(n+1>=this.actorBuffer.length)throw new _("capacity_exceeded",`world colliders track at most ${this.actorBuffer.length/Fs} actors`);this.actorBuffer[n]=t.x,this.actorBuffer[n+1]=t.z,e>=this.actorCount&&(this.actorCount=e+1);}setActorCount(e){this.actorCount=Math.min(e,this.actorBuffer.length/Fs);}loadNav(e,t={}){let{cellSize:n,origin:r,navTiles:o}=this.shape;e.init({...t,tileWorld:n,origin:r,maxTiles:t.maxTiles??Math.max(1,o)}),this.navTarget=e,this.navTileCount=0,this.navLoaded.fill(0);for(let s=0;s<this.navHeld.length;s++)this.loadNavPack(s);return this.navTileCount}get navTiles(){return this.navTileCount}prefetchLayer(e){return VXe(this.worldBytes,{paths:this.paths,bytes:e})}get navPackBase(){return this.shape.meshPacks}get waitingForDistricts(){return this.collidersWaiting}stepColliders(){let e=this.physics;if(this.closed||e===null||this.ops.length===0)return 0;let t=this.port.stepLogic(this.handle,this.actorBuffer,this.actorCount,this.ops);if(this.collidersWaiting=t===Ic,this.collidersWaiting)return 0;for(let n=0;n<t;n++){let r=this.ops[n],o=r>>>1;(r&iJ)!==0?this.insert(e,o):this.remove(e,o);}return t}body(e){return this.anchor===null&&(this.anchor=this.world.spawn(),this.transforms.add(this.anchor),e.addBody(this.anchor,{kind:"fixed"})),this.anchor}insert(e,t){let n=this.collider;this.port.collider(this.handle,t,n),this.offset[0]=n[0],this.offset[1]=n[1],this.offset[2]=n[2],this.extents[0]=n[3],this.extents[1]=n[4],this.extents[2]=n[5];let r=n[6]*.5;this.rotation[0]=0,this.rotation[1]=Math.sin(r),this.rotation[2]=0,this.rotation[3]=Math.cos(r),this.physicsOf[t]=e.addCollider(this.body(e),this.desc);}remove(e,t){let n=this.physicsOf[t];n!==lP&&(e.removeCollider(n),this.physicsOf[t]=lP);}dispose(){if(this.closed)return;let e=this.physics;if(e!==null)for(let t=0;t<this.physicsOf.length;t++)this.remove(e,t);this.anchor!==null&&this.world.despawn(this.anchor),this.closed=true,this.port.close(this.handle);}},lS=class{constructor(e,t,n,r){this.port=e;this.world=t;this.transforms=n;this.physics=r;}get supported(){return this.port!==null}stream(e){let t=this.port;if(t===null)throw new _("unsupported_feature","this backend does not stream worlds");let n=YXe(e.world),r=e.assets??null;if(e.packs===void 0&&(r===null||e.packPaths===void 0))throw new _("invalid_argument","a world stream needs its packs, or packPaths with assets");let o=e.packs===void 0&&r?.requests?.()===true&&t.lazyPacks?.()===true,s=oJ[e.tier??"mid"]|(o?Zj:0),a=t.open(e.world,e.materials,s);return new dP(t,a,e,this.physics,this.world,this.transforms,n,o)}};var Xse={water:0,sand:1,jelly:2,snow:3,mud:4};function XXe(i){return i==="jelly"||i==="snow"||i==="mud"}var qXe={water:{restDensity:4,stiffness:1700,viscosity:2.4,friction:0,maxStep:1/120,foam:1,plasticity:0},sand:{restDensity:4,stiffness:2400,viscosity:0,friction:.6,maxStep:1/120,foam:0,plasticity:0},jelly:{restDensity:8,stiffness:4e4,viscosity:.3,friction:.4,maxStep:1/240,foam:0,plasticity:0},snow:{restDensity:8,stiffness:2e4,viscosity:.2,friction:.8,maxStep:1/240,foam:0,plasticity:1},mud:{restDensity:8,stiffness:2e4,viscosity:.35,friction:.9,maxStep:1/240,foam:0,plasticity:1}},zXe=32,qse=32768,QXe=.1,cS=8,uS=512,$Xe={color:[.02,.18,.24],absorption:[.45,.09,.06],refraction:.04,smoothing:2,foam:[.92,.95,.97],reflection:[.55,.68,.85],resolution:.5,visible:true},jXe={color:[.76,.62,.4],absorption:[60,60,60],refraction:0,smoothing:1,foam:[0,0,0],reflection:[0,0,0],resolution:.5,visible:true},JXe={color:[.85,.12,.2],absorption:[.6,3.2,2.8],refraction:.03,smoothing:2,foam:[0,0,0],reflection:[.6,.6,.65],resolution:.5,visible:true},ZXe={color:[.92,.94,.97],absorption:[40,40,40],refraction:0,smoothing:1.5,foam:[0,0,0],reflection:[.2,.2,.22],resolution:.5,visible:true},eqe={color:[.3,.2,.12],absorption:[80,80,80],refraction:0,smoothing:1.5,foam:[0,0,0],reflection:[.12,.1,.08],resolution:.5,visible:true},tqe={water:$Xe,sand:jXe,jelly:JXe,snow:ZXe,mud:eqe},nqe=0,rqe=1,iqe=2,Kse=3,oqe=[0,0,0];function Yse(i,e,t){let n=tqe[t],r=e.color??n.color,o=e.absorption??n.absorption,s=e.foam??n.foam,a=e.reflection??n.reflection;i[0]=e.radius??0,i.set(r,1),i.set(o,4),i[7]=e.refraction??n.refraction,i[8]=e.smoothing??n.smoothing,i.set(s,9),i.set(a,12),i[15]=e.resolution??n.resolution,i[16]=e.visible??n.visible?1:0;}function zse(i,e,t){let n=qXe[e];i[9]=t.restDensity??n.restDensity,i[10]=t.stiffness??n.stiffness,i[11]=t.viscosity??n.viscosity,i[12]=t.friction??n.friction,i[13]=t.gravity?.x??0,i[14]=t.gravity?.y??-9.81,i[15]=t.gravity?.z??0,i[16]=t.maxStep??n.maxStep,i[17]=XXe(e)?t.plasticity??n.plasticity:t.foam??n.foam;}function Qse(i,e,t={}){let n=e.material??"water";if(!e.cells.every(r=>Number.isInteger(r)&&r>=cS&&r<=uS))throw new _("invalid_argument",`a fluid grid spans ${cS} to ${uS} whole cells per axis`);i[0]=e.capacity??qse,i[1]=Xse[n],i[2]=e.origin.x,i[3]=e.origin.y,i[4]=e.origin.z,i[5]=e.cell,i[6]=e.cells[0],i[7]=e.cells[1],i[8]=e.cells[2],zse(i,n,t);}function dS(i,e){if(i.fill(0),e===null)return;let t=e.kind==="stream"?0:e.kind==="box"?1:2,n=e.radius??.1,r=e.size??{x:n,y:n,z:n};i[0]=t,i[1]=e.position.x,i[2]=e.position.y,i[3]=e.position.z,i[4]=t===1?r.x:n,i[5]=t===1?r.y:n,i[6]=t===1?r.z:n,i[7]=e.velocity?.x??0,i[8]=e.velocity?.y??0,i[9]=e.velocity?.z??0,i[10]=e.rate??0,i[11]=1;}var hS=class{constructor(e,t,n,r){this.port=e;this.transforms=t;this.physics=n;this.desc=new Float32Array(Bs);this.look=new Float32Array(xJ);this.emitter=new Float32Array(Oc);this.block=new Float32Array(ah*al);this.forces=new Float32Array(ex);this.slots=[];this.order=new Int32Array(al);this.used=new Array($f).fill(false);this.position=new Kt;this.rotation=new vc;this.velocity=new Kt;this.spin=new Kt;this.impulse=new Kt;this.offset=new Kt;this.feedback=0;this.disposed=false;if((e.caps&RJ)===0)throw new _("unsupported_feature","this device has no GPU compute for fluids (engine feature fluid_1 reports no simulation)");this.material=r.material??"water";let o=r.cell??QXe;this.cell=o;let{min:s,max:a}=r.bounds,l=(d,h)=>{let p=Math.ceil((h-d)/o);if(!Number.isFinite(p)||p<cS||p>uS)throw new _("invalid_argument",`fluid bounds must span ${cS} to ${uS} cells per axis at cell ${o} m (got ${p})`);return p},c=this.desc;c[0]=r.capacity??qse,c[1]=Xse[this.material],c[2]=s.x,c[3]=s.y,c[4]=s.z,c[5]=o,c[6]=l(s.x,a.x),c[7]=l(s.y,a.y),c[8]=l(s.z,a.z),this.writeParameters(r),Yse(this.look,r.look??{},this.material),this.id=e.create(this.desc,this.look);let u=r.emitters??[];for(let d=0;d<u.length;d++)this.emit(u[d]);}writeParameters(e){zse(this.desc,this.material,e);}get count(){return this.port.count(this.id)}setParameters(e){this.writeParameters(e),this.port.parameters(this.id,this.desc);}setLook(e){Yse(this.look,e,this.material),this.port.surface(this.id,this.look);}emit(e){let t=this.used.indexOf(false);if(t<0)throw new _("capacity_exceeded",`a fluid holds at most ${$f} emitters`);return this.setEmitter(t,e),t}pour(e){if(e.kind==="stream")throw new _("invalid_argument","pour fills a box or a sphere once; use emit for streams");let t=this.used.indexOf(false),n=t<0?$f-1:t;dS(this.emitter,e),this.port.emitter(this.id,n,this.emitter);}setEmitter(e,t){if(e<0||e>=$f)throw new _("invalid_argument","emitter index out of range");dS(this.emitter,t),this.port.emitter(this.id,e,this.emitter),this.used[e]=t!==null&&t.kind==="stream";}collider(e,t,n={}){let r=this.slots.indexOf(null);if(r<0&&(r=this.slots.length),r>=al)throw new _("capacity_exceeded",`a fluid couples at most ${al} colliders`);let o=nqe,s=[0,0,0],a=0,l=oqe;if("sphere"in t)s=[t.sphere,0,0];else if("box"in t)o=rqe,s=[t.box.x,t.box.y,t.box.z];else if("capsule"in t)o=iqe,s=[t.capsule.radius,t.capsule.halfHeight,0];else {let u=t.mesh,d=this.port.volume(this.id,u.positions,u.indices,u.resolution??zXe,u.padding??this.cell);o=Kse,s=[d.half[0],d.half[1],d.half[2]],a=d.index,l=d.centre;}let c=n.feedback??this.physics.hasBody(e);return this.slots[r]={entity:e,kind:o,extent:s,friction:n.friction??.1,feedback:c,volume:a,centre:l},this.recount(),r}removeCollider(e){e>=0&&e<this.slots.length&&(this.slots[e]=null),this.recount();}recount(){let e=0;for(let t of this.slots)t?.feedback&&e++;this.feedback=e;}pause(e){this.port.pause(this.id,e);}clear(){this.port.clear(this.id);}update(e){if(this.disposed)return;let t=0;for(let n=0;n<this.slots.length;n++){let r=this.slots[n];if(r===null)continue;let o=t*ah,s=this.block;this.order[t]=n,this.transforms.position(r.entity,this.position),this.transforms.rotation(r.entity,this.rotation),r.kind===Kse&&(this.offset.set(r.centre[0],r.centre[1],r.centre[2]).applyQuat(this.rotation),this.position.set(this.position.x+this.offset.x,this.position.y+this.offset.y,this.position.z+this.offset.z)),this.physics.hasBody(r.entity)?(this.physics.linearVelocity(r.entity,this.velocity),this.physics.angularVelocity(r.entity,this.spin)):(this.velocity.set(0,0,0),this.spin.set(0,0,0)),s[o]=r.kind,s[o+1]=this.position.x,s[o+2]=this.position.y,s[o+3]=this.position.z,s[o+4]=this.rotation.x,s[o+5]=this.rotation.y,s[o+6]=this.rotation.z,s[o+7]=this.rotation.w,s[o+8]=r.extent[0],s[o+9]=r.extent[1],s[o+10]=r.extent[2],s[o+11]=this.velocity.x,s[o+12]=this.velocity.y,s[o+13]=this.velocity.z,s[o+14]=this.spin.x,s[o+15]=this.spin.y,s[o+16]=this.spin.z,s[o+17]=r.friction,s[o+vJ]=r.volume,t++;}if(this.port.colliders(this.id,this.block,t),this.port.step(this.id,e),this.feedback!==0){this.port.forces(this.id,this.forces);for(let n=0;n<t;n++){let r=this.slots[this.order[n]];if(r===null||!r.feedback||!this.physics.hasBody(r.entity))continue;let o=n*Vk;this.impulse.set(this.forces[o],this.forces[o+1],this.forces[o+2]),this.physics.applyImpulse(r.entity,this.impulse),this.impulse.set(this.forces[o+3],this.forces[o+4],this.forces[o+5]),this.physics.applyTorqueImpulse(r.entity,this.impulse);}}}dispose(){this.disposed||(this.disposed=true,this.port.destroy(this.id));}};var pn={liquidKelvin:293,parcels:1,contact:1,coupling:4,maxPairs:65536,seed:0,framesPerTick:2,smoke:["CO2","H2O"],metal:"Fe",layers:2,startK:293,flameK:1300,flameJoules:6e3,flameLayers:2,preheatTicks:1200,emission:24,extinction:18,albedo:[.35,.33,.31]},$se=256,jse=255,sqe=64,dy=0,Jse=3,Zse=4294967296,Ol=7999,eae=2147483647,tae=new Uint32Array(1),aqe=new Float32Array(tae.buffer);function hP(i){return tae[0]=i,aqe[0]}function lqe(){return {tick:0,particles:0,pairs:0,droppedPairs:0,fired:0,vented:0,retired:0,panK:0,burning:0,smoky:0,hottestK:0,plumes:0,lit:false}}function zt(i,e,t,n){if(!Number.isInteger(i)||i<e||i>t)throw new _("invalid_argument",`${n} must be a whole number from ${e} to ${t}`);return i}function hy(i,e){if(!Number.isFinite(i))throw new _("invalid_argument",`${e} must be finite`);return i}var pS=class{constructor(e,t,n,r=false){this.port=e;this.chemistry=t;this.ownsChemistry=r;this.emitterWords=new Float32Array(Oc);this.medium=null;this.frame=0;this.disposed=false;this.framesPerTick=zt(n.framesPerTick??pn.framesPerTick,1,sqe,"framesPerTick"),this.volume=n.volume,this.cells=[...n.volume.cells];let o=new Uint32Array(lh),s=new Float32Array(o.buffer);for(let u=0;u<Jse;u++)o[GJ+u]=zt(n.volume.cells[u],1,Jf,"a reactive volume axis");s[sx]=hy(n.volume.origin.x,"the volume origin"),s[sx+1]=hy(n.volume.origin.y,"the volume origin"),s[sx+2]=hy(n.volume.origin.z,"the volume origin"),s[VJ]=hy(n.volume.cell,"the volume cell"),o[HJ]=this.species(n.liquid),o[WJ]=zt(n.liquidKelvin??pn.liquidKelvin,1,Ol,"liquidKelvin"),o[KJ]=zt(n.parcels??pn.parcels,1,jse,"parcels"),s[YJ]=hy(n.contact??pn.contact,"contact"),o[XJ]=zt(Math.round((n.coupling??pn.coupling)*$se),0,4294967295,"coupling"),o[qJ]=zt(n.maxPairs??pn.maxPairs,1,4294967295,"maxPairs");let a=zt(n.seed??pn.seed,0,Number.MAX_SAFE_INTEGER,"seed");o[zJ]=a>>>0,o[QJ]=Math.floor(a/Zse)>>>0;let l=n.smoke??pn.smoke;if(l.length>Xk)throw new _("invalid_argument",`at most ${Xk} smoke species`);for(let u=0;u<l.length;u++)o[$J+u]=this.species(l[u]);o[jJ]=n.glowFromK===void 0?dy:zt(n.glowFromK,1,Ol,"glowFromK"),o[JJ]=n.glowFullK===void 0?dy:zt(n.glowFullK,1,Ol,"glowFullK"),o[ZJ]=n.smokeFullParcels===void 0?dy:zt(n.smokeFullParcels,1,jse,"smokeFullParcels"),o[eZ]=n.flameExtinction===void 0?dy:zt(Math.round(n.flameExtinction*$se),1,4294967295,"flameExtinction"),o[tZ]=n.plumeFromK===void 0?dy:zt(n.plumeFromK,1,Ol,"plumeFromK");let c=new Float32Array(Bs);Qse(c,n.fluid,n.fluid),this.handle=e.open(t.handleValue,c,o),this.capacity=e.registers(this.handle)[EZ];}species(e){return typeof e=="number"?zt(e,1,65535,"a material id"):this.chemistry.material(e)}live(){if(this.disposed)throw new _("unknown_resource","this reactive fluid was disposed");return this.handle}hob(e){let t=new Uint32Array(qk),n=r=>zt(r,0,Jf,"a hob cell");t[zk]=n(e.first[0]),t[zk+1]=n(e.first[1]),t[Qk]=n(e.last[0]),t[Qk+1]=n(e.last[1]),t[nZ]=zt(e.layers??pn.layers,1,Jf,"layers"),t[rZ]=this.species(e.metal??pn.metal),t[iZ]=zt(e.startK??pn.startK,1,Ol,"startK"),t[oZ]=zt(e.panK,1,Ol,"panK"),t[sZ]=zt(e.panJoules,0,eae,"panJoules"),t[aZ]=zt(e.flameK??pn.flameK,1,Ol,"flameK"),t[lZ]=zt(e.flameJoules??pn.flameJoules,0,eae,"flameJoules"),t[cZ]=zt(e.flameLayers??pn.flameLayers,0,Jf,"flameLayers"),this.port.hob(this.live(),t);}setLit(e){this.port.lit(this.live(),e);}pour(e,t=0){dS(this.emitterWords,e),this.port.emitter(this.live(),t,this.emitterWords);}preheat(e,t=pn.preheatTicks){return this.port.preheat(this.live(),zt(e,1,Ol,"targetK"),zt(t,0,OZ,"maxTicks"))}step(e){if(!(e>=0&&e<=jk))throw new _("invalid_argument",`a reactive step runs 0 to ${jk} s`);let t=this.frame%this.framesPerTick===0;return this.frame++,this.port.step(this.live(),e,t),t&&this.medium!==null&&this.port.media(this.handle,this.medium.id),t}mediumDesc(e={}){let t=this.volume;return {origin:t.origin,extent:{x:t.cells[0]*t.cell,y:t.cells[1]*t.cell,z:t.cells[2]*t.cell},size:this.cells,emission:e.emission??pn.emission,extinction:e.extinction??pn.extinction,albedo:e.albedo??pn.albedo}}attach(e){if(this.live(),e!==null&&!e.size.every((t,n)=>t===this.cells[n]))throw new _("invalid_argument",`the media volume must be ${this.cells.join(" x ")} texels to mirror this reactive volume`);this.medium=e,e!==null&&this.port.media(this.handle,e.id);}writeMedia(){return this.port.media(this.live(),this.medium===null?0:this.medium.id)}get texels(){return this.port.texels(this.live(),this.cells[0]*this.cells[1]*this.cells[2])}get particles(){return this.port.registers(this.live())[$k]}positions(){return this.port.positions(this.live(),this.capacity)}get plumeCount(){return this.port.registers(this.live())[ax]}plume(e,t){let n=this.port.registers(this.live());if(!(e>=0&&e<Math.min(n[ax],SZ)))return false;let r=vZ+e*RZ;for(let o=0;o<Jse;o++)t.cell[o]=n[r+TZ+o];return t.kelvin=n[r+wZ],t.smoke=n[r+IZ],t.position.x=hP(n[r+lx]),t.position.y=hP(n[r+lx+1]),t.position.z=hP(n[r+lx+2]),true}stats(e=lqe()){let t=this.port.registers(this.live());return e.tick=t[uZ]+t[dZ]*Zse,e.particles=t[$k],e.pairs=t[hZ],e.droppedPairs=t[pZ],e.fired=t[_Z],e.vented=t[mZ],e.retired=t[fZ],e.panK=t[yZ],e.burning=t[AZ],e.smoky=t[bZ],e.hottestK=t[gZ],e.plumes=t[ax],e.lit=t[xZ]!==0,e}digest(){return this.port.digest(this.live())}dispose(){this.disposed||(this.disposed=true,this.medium=null,this.port.close(this.handle),this.ownsChemistry&&this.chemistry.dispose());}};var nae=4,rae=64;var cqe={r:1,g:1,b:1},uqe={step:1/60,ambientKelvin:293.15,smokeWeight:.08,lift:.012,vorticity:.35,smokeHalfLife:4,coolingHalfLife:.8,ignitionKelvin:600,burnRate:3,heatRelease:1200,soot:.3,expansion:2,pressureCycles:2,smokeFull:1,glowFromKelvin:800,glowFullKelvin:1600,flameExtinction:96};function dqe(i){return Number.isInteger(i)&&i>=nae&&i<=rae&&(i&i-1)===0}function hqe(i,e){if(!i.cells.every(dqe))throw new _("invalid_argument",`smoke cells must be powers of two from ${nae} to ${rae} per axis`);let t={...uqe,...i},n=[i.cells[0],i.cells[1],i.cells[2],i.origin.x,i.origin.y,i.origin.z,i.cell,t.step,t.ambientKelvin,t.smokeWeight,t.lift,t.vorticity,t.smokeHalfLife,t.coolingHalfLife,t.ignitionKelvin,t.burnRate,t.heatRelease,t.soot,t.expansion,t.pressureCycles,t.smokeFull,t.glowFromKelvin,t.glowFullKelvin,t.flameExtinction];return e.set(n.slice(0,ch)),e}function pP(i){return i>=0&&i<=1}function pqe(i,e,t){let n=i.velocity??{x:0,y:0,z:0};e[t]=i.position.x,e[t+1]=i.position.y,e[t+2]=i.position.z,e[t+3]=i.radius,e[t+4]=i.density??0,e[t+5]=i.heat??0,e[t+6]=i.fuel??0,e[t+7]=n.x,e[t+8]=n.y,e[t+9]=n.z,e[t+10]=i.strength??0;let r=i.tint??cqe;if(!(pP(r.r)&&pP(r.g)&&pP(r.b)))throw new _("invalid_argument","a flame tint takes channels from 0 to 1");e[t+e_]=r.r,e[t+e_+1]=r.g,e[t+e_+2]=r.b;}var mS=class{constructor(e,t){this.port=e;this.emitterFloats=new Float32Array(t_*cl);this.disposed=false;this.handle=e.create(hqe(t,new Float32Array(ch)),t.medium.id);}setEmitters(e){if(this.disposed)throw new _("unknown_resource","this smoke volume was disposed");if(e.length>t_)throw new _("capacity_exceeded",`a smoke volume takes at most ${t_} emitters`);for(let t=0;t<e.length;t++)pqe(e[t],this.emitterFloats,t*cl);this.port.emitters(this.handle,this.emitterFloats,e.length);}follow(e){if(this.disposed)throw new _("unknown_resource","this smoke volume was disposed");if(this.port.follow===void 0)throw new _("unsupported_feature","this engine cannot move a smoke volume");this.port.follow(this.handle,e.x,e.y,e.z);}step(e){return this.disposed?0:this.port.step(this.handle,e)}dispose(){this.disposed||(this.disposed=true,this.port.destroy(this.handle));}};var au=["bool","int","number","text"],iae=["play","player","shared"],mqe=["tap","hold","swipe","gift","vote"];var fqe=["set","add","go","say","show","hide","emit"],_qe={variable:iL,choice:oL,beat:sL,scene:aL,track:aee,actor:lL,rule:cL,action:uL};var oae=16,sae=8,aae=0,lae=1,cae=3,yqe=0,Aqe=0,fS=class{constructor(e,t,n={}){this.port=e;this.handlers=n;this.byName=new Map;this.inputs=new Uint32Array(kc*uh);this.pending=0;this.disposed=false;this.handle=e.create(t),this.buffer=e.buffer(),this.views=e.views(this.handle);let r=[];for(let o=0;o<this.views.registers[YZ];o++){let s=e.variable(this.handle,o),a=this.text(iL,o),l={index:o,name:a,type:au[s&rL],persist:iae[s>>>QZ&rL]};r.push(l),a!==""&&this.byName.set(a,l);}this.variables=r;}live(){if(this.disposed)throw new _("unknown_resource","this story was disposed");let e=this.port.buffer();return e!==this.buffer&&(this.buffer=e,this.views=this.port.views(this.handle)),this.views}text(e,t,n=Aqe){let r=this.port.textOf(this.handle,e,t,n);return r===n_?"":this.port.programText(this.handle,r)}dispatch(){let{registers:e,events:t}=this.live(),n=this.handlers,r=e[KZ];for(let o=0;o<r;o++){let s=o*tL,a=t[s+1],l=t[s+2];switch(t[s]){case $Z:n.entered?.(a,l);break;case jZ:n.offered?.(a);break;case JZ:n.taken?.(a);break;case ZZ:n.refused?.(a);break;case eee:n.logic?.(a,l);break;case tee:n.key?.(a,l);break;case nee:n.finished?.(a);break;case ree:n.rule?.(a,l,fqe[t[s+3]]);break}}}queue(e,t,n){if(this.live(),this.pending===kc)throw new _("capacity_exceeded",`a story step takes at most ${kc} inputs`);let r=this.pending*uh;this.inputs[r]=e,this.inputs[r+1]=t,this.inputs[r+2]=n,this.pending++;}start(){this.live(),this.pending=0,this.port.start(this.handle),this.dispatch();}step(){this.live();let e=this.pending;this.pending=0,this.port.step(this.handle,this.inputs,e),this.dispatch();}choose(e){this.queue(iee,e,0);}interact(e,t=n_){this.queue(oee,mqe.indexOf(e),t);}gift(e){this.queue(see,this.port.textIndex(this.handle,e),0);}seek(e){this.live(),this.port.seek(this.handle,e);}available(e){return this.live(),this.port.available(this.handle,e)}label(e){return this.text(oL,e)}beatName(e){return this.text(sL,e)}sceneName(e){return this.text(aL,e)}actorName(e){return this.text(lL,e)}keyText(e,t){return this.text(lee,e,t)}ruleName(e){return this.text(cL,e)}actionText(e){return this.text(uL,e)}nodeId(e,t){return this.live(),this.port.idOf(this.handle,_qe[e],t)}variable(e){let t=typeof e=="number"?this.variables[e]:this.byName.get(e);if(t===void 0)throw new _("unknown_resource",`the story has no variable ${String(e)}`);return t}get(e){this.live();let t=this.variable(e);if(t.type===au[cae])return this.port.variableText(this.handle,t.index);let n=this.port.get(this.handle,t.index);return t.type===au[aae]?n!==0:n}set(e,t){this.live();let n=this.variable(e);if(n.type===au[cae]){if(typeof t!="string")throw new _("invalid_argument",`the story variable ${n.name} holds text`);this.port.setText(this.handle,n.index,t);}else if(n.type===au[aae]){if(typeof t!="boolean")throw new _("invalid_argument",`the story variable ${n.name} holds true or false`);this.port.set(this.handle,n.index,t?1:0);}else {if(typeof t!="number"||n.type===au[lae]&&!Number.isInteger(t))throw new _("invalid_argument",`the story variable ${n.name} holds ${n.type===au[lae]?"a whole number":"a number"}`);this.port.set(this.handle,n.index,t);}n.persist!==iae[yqe]&&this.handlers.persist?.(n,t);}sample(e,t){let{registers:n,samples:r}=this.live();if(e<0||e>=n[Zk])throw new _("invalid_argument",`the story has no sample ${e}`);let o=e*nL;return t.track=r[o],t.target=r[o+1],t.channel=r[o+2],t.key=r[o+3],t.x=r[o+4],t.y=r[o+5],t.z=r[o+6],t.w=r[o+7],t}get sampleCount(){return this.live().registers[Zk]}get beat(){return this.live().registers[BZ]}get scene(){return this.live().registers[GZ]}get beatTick(){return this.live().registers[VZ]}get sceneTick(){return this.live().registers[HZ]}get sceneLength(){return this.live().registers[WZ]}get tickRate(){return this.live().registers[XZ]}get started(){return (this.live().registers[Jk]&qZ)!==0}get finished(){return (this.live().registers[Jk]&zZ)!==0}digest(){let e=this.live().registers;return e[eL+1].toString(oae).padStart(sae,"0")+e[eL].toString(oae).padStart(sae,"0")}dispose(){this.disposed||(this.disposed=true,this.port.destroy(this.handle));}};var ra={mass:.01,stretch:1e-7,bend:1e-4,tetherSlack:.05,damping:.5,gravity:{x:0,y:-9.81,z:0},substeps:8,thickness:.005,friction:.2},uae=64,dae=2,bqe={none:b$,top:g$,corners:E$};function lu(i){throw new _("invalid_argument",`cloth ${i}`)}function py(i,e){return Number.isFinite(i)&&i>=0||lu(`${e} must be finite and not negative`),i}function Jh(i,e){return Number.isFinite(i)||lu(`${e} must be finite`),i}function hae(i,e,t){let n=t.substeps??ra.substeps;(!Number.isInteger(n)||n<1||n>uae)&&lu(`substeps must be a whole number from 1 to ${uae}`);let r=t.mass??ra.mass;Number.isFinite(r)&&r>0||lu("mass must be positive");let o=t.friction??ra.friction;o>=0&&o<=1||lu("friction runs from 0 to 1");let s=t.gravity??ra.gravity;i[i$]=r,i[o$]=py(t.stretch??ra.stretch,"stretch"),i[s$]=py(t.bend??ra.bend,"bend"),i[a$]=py(t.tetherSlack??ra.tetherSlack,"tetherSlack"),i[l$]=py(t.damping??ra.damping,"damping"),i[T0]=Jh(s.x,"gravity"),i[T0+1]=Jh(s.y,"gravity"),i[T0+2]=Jh(s.z,"gravity"),e[c$]=n,i[u$]=py(t.thickness??ra.thickness,"thickness"),i[d$]=o;}function gqe(i,e,t){let n=(o,s)=>((!Number.isInteger(o)||o<dae)&&lu(`${s} must be a whole number of at least ${dae}`),o);e[h$]=n(t.columns,"columns"),e[p$]=n(t.rows,"rows"),Number.isFinite(t.spacing)&&t.spacing>0||lu("spacing must be positive"),i[m$]=t.spacing;let r=(o,s)=>{i[o]=s===void 0?0:Jh(s.x,"axes"),i[o+1]=s===void 0?0:Jh(s.y,"axes"),i[o+2]=s===void 0?0:Jh(s.z,"axes");};r(f$,t.origin),r(_$,t.across),r(y$,t.down),e[A$]=bqe[t.pin??"top"];}function Eqe(i,e,t){i.fill(0,e,e+th);let n=(r,o)=>{i[e+r]=o.x,i[e+r+1]=o.y,i[e+r+2]=o.z;};"sphere"in t?(i[e]=x$,n(1,t.sphere.center),i[e+7]=t.sphere.radius):(i[e]=v$,n(1,t.capsule.a),n(4,t.capsule.b),i[e+7]=t.capsule.radius);}var mP=class{constructor(e,t,n){this.port=e;this.info=t;this.disposed=false;this.particles=t.particles,this.triangles=t.triangles,this.pins=t.pins,this.geometry=n;}get id(){return this.info.id}get engineHost(){return this.port.engineHost??null}positions(){return this.port.positions(this.info.id,this.particles)}attach(e){this.geometry=e;}setOptions(e){hae(this.port.prepare(),this.port.registers,e),this.port.params(this.info.id);}setAnchors(e){this.port.anchors(this.info.id,e);}present(){return this.disposed||this.geometry===null?0:this.port.present(this.info.id,this.geometry)}dispose(){this.disposed||(this.disposed=true,this.port.remove(this.info.id));}},_S=class{constructor(e){this.port=e;this.sheets=[];this.block=new Float32Array(th*Tc);}create(e,t={}){let n=this.port.prepare();hae(n,this.port.registers,t);let r;if("grid"in e){gqe(n,this.port.registers,e.grid);let s=e.grid.pins;r=this.port.grid(s===void 0||s.length===0?null:Uint32Array.from(s));}else r=this.port.mesh(e.mesh.positions,e.mesh.triangles,e.mesh.pins??null);let o=new mP(this.port,r,t.geometry??null);return this.sheets.push(o),o}remove(e){let t=this.sheets.indexOf(e);t>=0&&this.sheets.splice(t,1),e.dispose();}setColliders(e){if(e.length>Tc)throw new _("capacity_exceeded",`cloth collides with at most ${Tc} shapes`);for(let t=0;t<e.length;t++)Eqe(this.block,t*th,e[t]);this.port.colliders(this.block,e.length);}couple(e){if(this.port.couple===void 0)throw new _("unsupported_feature","cloth couples to rigid bodies only on the native engine (feature rigid_coupling_1)");return this.port.couple(e)}uncouple(e){this.port.uncouple?.(e);}get count(){return this.sheets.length}step(e){this.sheets.length>0&&this.port.step(e);}present(){for(let e=0;e<this.sheets.length;e++)this.sheets[e].present();}digest(){return this.port.digest()}dispose(){for(let e of this.sheets)e.dispose();this.sheets.length=0,this.port.dispose();}};var so={kernels:0,input:1,steps:2,update:3,transforms:4,sync:5,fluids:6,audio:7,ui:8,render:9};var vqe=["damage","impact","support","overflow","lifetime","stress","joint"],fP="fragment_",Rqe="intact",yS=class{constructor(e,t,n,r,o,s){this.port=e;this.world=t;this.transforms=n;this.graphics=r;this.desc=s;this.event={kind:"break",fragment:0,cause:"damage",x:0,y:0,z:0,speed:0};this.chipX=0;this.chipY=0;this.chipZ=0;this.chipCount=0;this.disposed=false;let a=o.nodeNames.filter(y=>y.startsWith(fP)).length;if(a===0)throw new _("invalid_argument","the model has no fragment_N nodes; bake it with `engine-bake fracture`");this.root=t.spawn(),n.add(this.root);let l=r.instantiate(this.root,o.id),c=s.position??{x:0,y:0,z:0},u=s.rotation??[0,0,0,1];this.intact=t.spawn(),n.add(this.intact,c.x,c.y,c.z),n.setRotation(this.intact,u[0],u[1],u[2],u[3]);let d=s.scale??1;n.setScale(this.intact,d,d,d);let h=r.findNode(l,Rqe);h!==null&&r.attachNode(this.intact,h);let p=[],m=new Uint32Array(a);for(let y=0;y<a;y++){let b=t.spawn();n.add(b,c.x,c.y,c.z),n.setScale(b,d,d,d);let A=r.findNode(l,`${fP}${y}`);if(A===null)throw new _("invalid_argument",`fragment node ${fP}${y} is missing`);r.attachNode(b,A),p.push(b),m[y]=b;}this.fragments=p;let f=new Float32Array(Kk);f[0]=c.x,f[1]=c.y,f[2]=c.z,f.set(u,3),f[7]=s.health??1,f[8]=s.impactThreshold??50,f[9]=s.impactScale??.01,f[10]=s.spread??1,f[11]=s.density??2400,f[12]=s.friction??.7,f[13]=s.restitution??.05,f[14]=s.breakSpeed??2,f[15]=s.maxDebris??512,f[16]=s.lifetime??8,f[17]=s.removeRetired?1:0,f[18]=s.support??true?1:0,f[19]=d,f[20]=s.collisionGroups?.membership??0,f[21]=s.collisionGroups?.filter??0,f[22]=s.maxBreaksPerStep??64,f[23]=s.debrisCollide?1:0,this.id=e.create(s.fracture,m,this.intact,f);}get attached(){return this.port.attached(this.id)}damage(e,t,n){return this.port.damage(this.id,e.x,e.y,e.z,t,n)}configure(e){if(this.port.configure===void 0)throw new _("unsupported_feature","structural destruction needs the native engine (feature destruction_2)");this.port.configure(this.id,e);}handle(e,t,n){let r=e[n],o=e[n+2],s=this.event;if(s.fragment=o,s.cause=vqe[e[n+3]]??"damage",s.x=t[n+4],s.y=t[n+5],s.z=t[n+6],s.speed=t[n+7],r===LJ)s.kind="intact_lost";else if(r===NJ)s.kind="break",this.chipX+=s.x,this.chipY+=s.y,this.chipZ+=s.z,this.chipCount++;else if(r===MJ)s.kind="remove";else if(r===kJ)s.kind="retire";else if(r===DJ)s.kind="bond";else return;this.desc.onBreak?.(s);}flushChips(){let e=this.desc.chips;if(this.chipCount===0||e===void 0){this.chipCount=0;return}let t=1/this.chipCount;this.transforms.setPosition(e.entity,this.chipX*t,this.chipY*t,this.chipZ*t),this.graphics.emit(e.emitter,(e.perBreak??6)*this.chipCount),this.chipX=0,this.chipY=0,this.chipZ=0,this.chipCount=0;}dispose(){if(!this.disposed){this.disposed=true,this.port.destroy(this.id);for(let e of this.fragments)this.world.despawn(e);this.world.despawn(this.intact),this.world.despawn(this.root);}}},AS=class{constructor(e){this.port=e;this.items=[];}add(e){this.items[e.id]=e;}remove(e){this.items[e.id]===e&&(this.items[e.id]=null),e.dispose();}step(e){let t=this.port.update(e);for(let n=0;n<t.count;n++){let r=t.offset+n*CJ;this.items[t.words[r+1]]?.handle(t.words,t.floats,r);}if(t.count>0)for(let n of this.items)n?.flushChips();}dispose(){this.port.dispose();}};var my={open:{horizons:3,prefetch:true,feed:"full",feed_bytes:33554432,feed_concurrency:2},cellular:{horizons:3,prefetch:true,feed:"lead",feed_bytes:8388608,feed_concurrency:1},metered:{horizons:2,prefetch:true,feed:"lead",feed_bytes:2097152,feed_concurrency:1},saver:{horizons:1,prefetch:false,feed:"none",feed_bytes:0,feed_concurrency:0}};function bS(i){return i===null?my.open:i.saver?my.saver:i.metered?my.metered:i.kind==="cellular"?my.cellular:my.open}var Sqe=["unknown","wifi","ethernet","cellular"],Tqe=1,wqe=2,Iqe=1,Oqe=2,Cqe=3,pae=7;function mae(i){if(i.length<pae)return null;let e=new DataView(i.buffer,i.byteOffset,pae).getUint32(Cqe,true),t=i[Oqe],n={kind:Sqe[i[Iqe]]??"unknown",metered:(t&Tqe)!==0,saver:(t&wqe)!==0};return e>0?{...n,downlink_kbps:e}:n}yn();yn();var fae=[1,3,8],Nqe=10,kqe=.35,Lqe=1.5,Mqe=3,Dqe=6,Pqe=24*1024*1024,Fqe=8,Uqe=2,Bqe=1024,Gqe=50,Vqe=.3,_ae=2,tn={idle:0,pending:1,resident:2,consumed:3},_P=16,cu=1<<20,gS=1<<24,ES=1e3,xS=1e-9,Zh=-1,Hqe=-1,yae=7,ep=0,Aae=1,tp=2,yP=3,bae=4,AP=5,gae=6,vS=7,RS=8,SS=9,TS=10,np=11,fy=12,wS=13,Eae=14,_y=15,bP=16,xae=17,vae=18,rp=19,gP=20,Rae=21,Wqe=22,Kqe=.25,Yqe=.5,Xqe=2,Cl={free:0,loaded:1,saturated:2},Sae=0,Tae=1,qqe=2,zqe=3,Qqe=4,$qe=5,jqe=2,Jqe=0,Zqe=1,e7e=2,wae=3,t7e=4,n7e=5,r7e=6,i7e=7,IS=class{constructor(e,t,n={}){this.stats={plans:0,requested:0,reprioritised:0,released:0,consumed:0,pendingBytes:0,pending:0,tracked:0};this.local=new Float64Array(3);this.previous=new Float64Array(3);this.velocity=new Float64Array(3);this.s=new Float64Array(Wqe);this.r=new Float64Array(6);this.trackedCount=0;this.candidateCount=0;this.planId=0;this.frames=0;this.hasPrevious=false;this.idleMode=false;this.pendingCount=0;this.pendingBytes=0;this.inFlight=0;this.linkLoad=Cl.free;this.prefetchAllowed=true;this.layer=e,this.assets=t;let r=e.entries;this.state=new Uint8Array(r),this.priority=new Uint8Array(r),this.time=new Float64Array(r).fill(1/0),this.stamp=new Uint32Array(r),this.slot=new Int32Array(r).fill(Zh),this.tracked=new Int32Array(r),this.keys=new Float64Array(Math.max(1,n.capacity??Bqe));let o=n.horizons??fae;this.horizons=Float64Array.from(o.length>0?o:fae),this.tuning=Float64Array.of(n.maxSpeed??Nqe,n.spread??kqe,Math.max(xS,n.minSpread??Lqe),Math.max(1,n.turnPenalty??Mqe),n.releaseSeconds??this.horizons[this.horizons.length-1]*2,n.teleport??Gqe,Math.min(1,Math.max(xS,n.smoothing??Vqe)),Math.max(xS,n.saturationSeconds??Xqe)),this.budget=Math.max(0,Math.floor(n.budgetBytes??Pqe)),this.interval=Math.max(1,Math.floor(n.interval??Dqe)),this.maxPending=Math.max(1,n.maxPending??Fqe),this.maxSpeculative=Math.max(1,n.maxSpeculative??Uqe);let s=n.reach??null;if(this.reach=s,this.reachCell=new Int32Array(s===null?0:e.count),s!==null)for(let a=0;a<e.count;a++)this.reachCell[a]=s.cellAt(e.x[a],e.z[a]);}attach(e){e!==this.assets&&(this.releaseAll(),this.assets=e);}set idle(e){this.idleMode=e;}get idle(){return this.idleMode}get stopTime(){return this.s[RS]}get bytesPending(){return this.pendingBytes}get speed(){let e=this.velocity;return Math.sqrt(e[0]*e[0]+e[1]*e[1]+e[2]*e[2])}velocityInto(e){e[0]=this.velocity[0],e[1]=this.velocity[1],e[2]=this.velocity[2];}activeHorizons(e){return this.idleMode&&e.horizons>1?this.horizons.length:Math.min(this.horizons.length,Math.max(1,e.horizons))}horizonLimit(e){let t=this.horizons[this.activeHorizons(e)-1];return this.idleMode&&e.horizons>1?t*_ae:t}frame(e,t){this.s[_y]=t,this.step(e);}frameAt(e,t,n){this.s[_y]=t[n],this.step(e);}get load(){return this.linkLoad}get throughput(){return this.s[rp]}step(e){this.s[_y]>0&&(this.s[bP]+=this.s[_y]),this.layer.toLocal(e,this.local,0,true),this.observe();let t=this.frames%this.interval===0;this.frames++,t&&this.assets!==null&&this.assets.prefetch!==void 0&&this.plan();}observe(){let e=this.s[_y],t=this.local,n=this.previous,r=this.velocity,o=!this.hasPrevious,s=t[0]-n[0],a=t[1]-n[1],l=t[2]-n[2];n[0]=t[0],n[1]=t[1],n[2]=t[2],this.hasPrevious=true;let c=this.tuning[n7e]/this.layer.place[yae];if(o||s*s+a*a+l*l>c*c){r[0]=0,r[1]=0,r[2]=0;return}if(!(e>0))return;let u=this.tuning[r7e];r[0]+=(s/e-r[0])*u,r[1]+=(a/e-r[1])*u,r[2]+=(l/e-r[2])*u;}plan(){let e=this.layer,t=this.assets,n=this.s,r=this.tuning;this.planId=this.planId+1>>>0||1,this.stats.plans++;let o=bS(t?.networkHint?.()??null);this.prefetchAllowed=o.prefetch;let s=this.idleMode&&o.horizons>1,a=s?this.horizons.length:Math.min(this.horizons.length,Math.max(1,o.horizons));n[TS]=s?this.horizons[a-1]*_ae:this.horizons[a-1],n[np]=Math.max(r[t7e],n[TS]*2),this.linkLoad=this.measureLoad(),this.linkLoad!==Cl.free&&(n[TS]=this.horizons[0],this.prefetchAllowed=false),n[fy]=e.place[yae],n[SS]=e.needRadius()/n[fy],n[ep]=this.local[0],n[Aae]=this.local[1],n[tp]=this.local[2];let l=this.velocity;n[yP]=l[0],n[bae]=l[1],n[AP]=l[2];let c=Math.sqrt(l[0]*l[0]+l[1]*l[1]+l[2]*l[2]);n[gae]=Math.max(r[e7e]/n[fy],c*r[Zqe]),n[vS]=Math.max(r[Jqe]/n[fy],c),n[RS]=1/0;let u=this.reach;if(u!==null){let b=this.r;b[Sae]=n[ep],b[Tae]=n[tp],b[jqe]=n[vS]*n[np]*r[wae]+n[SS],u.updateFrom(b),b[Sae]=n[ep],b[Tae]=n[tp],b[qqe]=n[yP],b[zqe]=n[AP],b[Qqe]=n[np],u.stopTimeInto(b),n[RS]=b[$qe];}let d=n[SS]+e.maxRadius+n[vS]*n[np],h=e.cellSize,p=Math.max(0,Math.floor((n[ep]-d-e.originX)/h)),m=Math.min(e.cols-1,Math.floor((n[ep]+d-e.originX)/h)),f=Math.max(0,Math.floor((n[tp]-d-e.originZ)/h)),y=Math.min(e.rows-1,Math.floor((n[tp]+d-e.originZ)/h));this.candidateCount=0;for(let b=f;b<=y;b++)for(let A=p;A<=m;A++){let E=b*e.cols+A,R=e.cellStart[E+1];for(let g=e.cellStart[E];g<R;g++)this.consider(e.cellItems[g]);}this.refresh(),this.issue(),this.stats.pendingBytes=this.pendingBytes,this.stats.pending=this.pendingCount,this.stats.tracked=this.trackedCount;}consider(e){let t=this.layer,n=this.s,r=t.x[e]-n[ep],o=t.y[e]-n[Aae],s=t.z[e]-n[tp],a=Math.sqrt(r*r+o*o+s*s),l=n[SS],c=t.radius[e],u=n[vS],d=n[np];if(a-c-l>u*d)return;let h=t.held,p=a;if(this.reach!==null){let x=this.reachCell[e],O=x===Hqe?1/0:this.reach.distance[x];O>p&&(p=O);}let m=n[yP],f=n[bae],y=n[AP],b=n[gae],A=n[RS],E=n[TS],R=n[fy],g=this.tuning[wae],v=this.horizons[0];for(let x=t.entryStart[e];x<t.entryStart[e+1];x++){let O=t.entryWithin[x]/R,N=(O<l?O:l)+c,I=0;if(a>N){let k=a*a-N*N,M=m*m+f*f+y*y-b*b,K=-2*(r*m+o*f+s*y+N*b),Y=1/0;if(Math.abs(M)<xS)K<0&&(Y=-k/K);else {let de=K*K-4*M*k;if(de>=0){let Oe=Math.sqrt(de),be=(-K-Oe)/(2*M),ke=(-K+Oe)/(2*M);M>0?Y=ke<0?1/0:be>0?be:0:Y=be>ke?be:ke;}}if(Y>A){let de=r-m*A,Oe=o-f*A,be=s-y*A,ke=(Math.sqrt(de*de+Oe*Oe+be*be)-N)/b;Y=ke>A?ke:A;}let te=p===1/0?1/0:(p-N)/u*g,Z=(a-N)/u;I=Y<te?Y:te,I<Z&&(I=Z);}if(this.stamp[x]=this.planId,this.time[x]=I,I>E||h!==null&&h(x))continue;let S=t.entryLevel[x],w=Je.prefetch;if(S===0&&I<=v)w=Je.soon;else if(!this.prefetchAllowed)continue;let U=this.state[x];if(U!==tn.idle&&!(U===tn.pending&&w<this.priority[x]))continue;let L=I*ES<cu-1?Math.floor(I*ES):cu-1;n[wS]=((w*_P+S)*cu+L)*gS+x,this.candidate();}}candidate(){let e=this.keys,t=this.s[wS];if(this.candidateCount<e.length){e[this.candidateCount++]=t;return}let n=0;for(let r=1;r<this.candidateCount;r++)e[r]>e[n]&&(n=r);t<e[n]&&(e[n]=t);}measureLoad(){let e=this.layer.flow;if(e===null)return Cl.free;let t=this.s,n=e[WR]+t[xae],r=t[bP];if(r>0){if(t[Rae]>0){let a=(n-t[vae])/r;t[rp]=t[rp]>0?t[rp]+(a-t[rp])*Kqe:a;}t[vae]=n,t[bP]=0;}let o=e[ry]+t[gP];if(t[Rae]=o,o<=0)return Cl.free;let s=t[rp]*this.tuning[i7e];return o>s?Cl.saturated:o>s*Yqe?Cl.loaded:Cl.free}refresh(){let e=this.assets,t=this.planId,n=this.s[np];this.inFlight=0,this.s[gP]=0;for(let r=this.trackedCount-1;r>=0;r--){let o=this.tracked[r],s=this.layer.paths[o],a=this.state[o];if(a===tn.pending||a===tn.resident){let c=e?.resident?.(s)===true,u=!c&&e?.pending?.(s)===true;c?(a===tn.pending&&(this.s[xae]+=this.layer.entryBytes[o]),a=tn.resident):u||(a=tn.consumed,this.stats.consumed++,this.untrackBytes(o)),this.state[o]=a;}let l=this.stamp[o]===t&&this.time[o]<=n;l&&a===tn.pending&&(this.s[gP]+=this.layer.entryBytes[o],this.priority[o]===Je.prefetch&&this.inFlight++),!l&&((a===tn.pending||a===tn.resident)&&(e?.cancelPrefetch?.(s),this.stats.released++,this.untrackBytes(o)),this.state[o]=tn.idle,this.untrack(r));}}issue(){let e=this.assets,t=this.keys,n=this.candidateCount;if(o7e(t,n),e===null||e.prefetch===void 0)return;let r=this.layer.busy!==null&&this.layer.busy();for(let o=0;o<n;o++){let s=t[o],a=s%gS|0,l=Math.floor(s/gS/cu/_P)|0,c=this.state[a],u=this.layer.paths[a];if(c===tn.pending){e.prefetch(u,l)&&(this.priority[a]=l,this.stats.reprioritised++);continue}if(this.linkLoad!==Cl.free||this.pendingCount>=this.maxPending||r&&l===Je.prefetch||l===Je.prefetch&&this.inFlight>=this.maxSpeculative)continue;let d=this.layer.entryBytes[a];if(!(this.pendingBytes+d>this.budget&&(this.s[wS]=s,this.s[Eae]=d,!this.evict()))){if(!e.prefetch(u,l)){this.state[a]=tn.consumed,this.track(a);continue}this.state[a]=e.resident?.(u)===true?tn.resident:tn.pending,this.priority[a]=l,this.track(a),this.pendingBytes+=d,this.pendingCount++,l===Je.prefetch&&this.state[a]===tn.pending&&this.inFlight++,this.stats.requested++;}}}evict(){let e=this.assets,t=this.s[wS],n=this.s[Eae];for(;this.pendingBytes+n>this.budget;){let r=Zh,o=t;for(let a=0;a<this.trackedCount;a++){let l=this.tracked[a],c=this.state[l];if(c!==tn.resident&&c!==tn.pending)continue;let u=this.time[l],d=u*ES<cu-1?Math.floor(u*ES):cu-1,h=((this.priority[l]*_P+this.layer.entryLevel[l])*cu+d)*gS+l;h>o&&(o=h,r=a);}if(r===Zh)return false;let s=this.tracked[r];e?.cancelPrefetch?.(this.layer.paths[s]),this.stats.released++,this.untrackBytes(s),this.state[s]=tn.idle,this.untrack(r);}return true}track(e){this.slot[e]===Zh&&(this.slot[e]=this.trackedCount,this.tracked[this.trackedCount++]=e);}untrack(e){let t=this.tracked[e],n=this.tracked[--this.trackedCount];this.tracked[e]=n,this.slot[n]=e,this.slot[t]=Zh;}untrackBytes(e){let t=this.pendingBytes-this.layer.entryBytes[e];this.pendingBytes=t>0?t:0,this.pendingCount>0&&this.pendingCount--;}releaseAll(){let e=this.assets;for(let t=this.trackedCount-1;t>=0;t--){let n=this.tracked[t],r=this.state[n];(r===tn.pending||r===tn.resident)&&(e?.cancelPrefetch?.(this.layer.paths[n]),this.stats.released++),this.state[n]=tn.idle,this.slot[n]=Zh;}this.trackedCount=0,this.pendingBytes=0,this.pendingCount=0;}reset(){this.releaseAll(),this.hasPrevious=false,this.velocity.fill(0),this.frames=0;}};function o7e(i,e){for(let t=(e>>1)-1;t>=0;t--)Iae(i,t,e);for(let t=e-1;t>0;t--){let n=i[0];i[0]=i[t],i[t]=n,Iae(i,0,t);}}function Iae(i,e,t){let n=e,r=i[n];for(;;){let o=2*n+1;if(o>=t||(o+1<t&&i[o+1]>i[o]&&o++,i[o]<=r))break;i[n]=i[o],n=o;}i[n]=r;}var Oae=4*1024*1024,EP=class{constructor(e,t,n){this.name=e;this.paths=t;this.owner=n;this.requestedCount=0;this.active=false;}get requested(){return this.requestedCount}get total(){return this.paths.length}get resident(){let e=this.owner.assets;if(e===null||e.resident===void 0)return 0;let t=0;for(let n=0;n<this.paths.length;n++)e.resident(this.paths[n])&&t++;return t}get ready(){let e=this.owner.assets;if(e===null||this.requestedCount<this.paths.length)return false;for(let t=0;t<this.paths.length;t++){let n=this.paths[t];if(e.pending?.(n)===true)return false}return true}get running(){return this.active}start(e,t){let n=this.owner.assets;if(this.active=true,n===null||n.prefetch===void 0)return;let r=Math.min(this.paths.length,t);for(let o=this.requestedCount;o<r;o++)n.prefetch(this.paths[o],e);r>this.requestedCount&&(this.requestedCount=r);}cancel(){let e=this.owner.assets;this.active=false;for(let t=0;t<this.requestedCount;t++)e?.cancelPrefetch?.(this.paths[t]);this.requestedCount=0;}},OS=class{constructor(e=null){this.scenes=new Map;this.running=new Map;this.streams=[];this.stallChecks=[];this.overrides=[];this.eye=new Float32Array(3);this.position=new Float64Array(3);this.sizes=new Map;this.idleMode=false;this.enabled=true;this.current=null;this.source=e;}get assets(){return this.enabled?this.source:null}get network(){return this.source?.networkHint?.()??null}get depth(){return bS(this.network)}get streamCount(){return this.streams.length}get idling(){return this.idleMode}attach(e){if(e!==this.source){for(let t of this.running.values())t.cancel();this.running.clear(),this.source=e;for(let t=0;t<this.streams.length;t++)this.streams[t].attach(this.streamAssets(this.overrides[t]));}}setEnabled(e){if(e!==this.enabled){if(!e){for(let t of this.running.values())t.cancel();this.running.clear();for(let t=0;t<this.streams.length;t++)this.streams[t].releaseAll();}this.enabled=e;for(let t=0;t<this.streams.length;t++)this.streams[t].attach(this.streamAssets(this.overrides[t]));}}sized(e,t){this.sizes.set(e,t);}stream(e,t={}){let n=e instanceof ou?e:new ou(e),r=t.assets??null;this.source===null&&r!==null&&(this.source=r);let o=new IS(n,this.streamAssets(r),t);return o.idle=this.idleMode,this.streams.push(o),this.stallChecks.push(t.stalled??null),this.overrides.push(r),o}streamAssets(e){return this.enabled?e??this.source:null}removeStream(e){let t=this.streams.indexOf(e);t<0||(e.releaseAll(),this.streams.splice(t,1),this.stallChecks.splice(t,1),this.overrides.splice(t,1));}describe(e,t){this.scenes.set(e,t);}scene(e,t=Je.prefetch){let n=this.scenes.get(e);if(n===void 0)throw new _("invalid_argument",`no prefetch description for scene ${e}; add assets to the scene or call game.prefetch.describe`);let r=this.running.get(e);return r===void 0&&(r=new EP(e,n.assets??[],this),this.running.set(e,r)),(this.depth.feed!=="none"||t<Je.prefetch)&&r.start(t,this.limitFor(r,t)),r}cancelScene(e){let t=this.running.get(e);t!==void 0&&(t.cancel(),this.running.delete(e));}idle(e){if(e!==this.idleMode){this.idleMode=e;for(let t=0;t<this.streams.length;t++)this.streams[t].idle=e;e&&this.hintNext(this.current,true);}}get currentScene(){return this.current}entered(e){let t=this.current;this.current=e,this.running.has(e)&&this.running.delete(e);let n=this.scenes.get(e)?.next??[];for(let[s,a]of this.running)n.indexOf(s)>=0||(a.cancel(),this.running.delete(s));let r=this.scenes.get(e)?.idle===true,o=r!==this.idleMode;this.idle(r),t!==e&&!(o&&r)&&this.hintNext(e,this.idleMode);}hintNext(e,t){if(e===null||this.assets===null)return;let n=this.scenes.get(e)?.next;if(n!==void 0)for(let r of n)this.scenes.has(r)&&this.scene(r,Je.prefetch).start(Je.prefetch,t?1/0:this.limitFor(this.running.get(r),Je.prefetch));}limitFor(e,t){if(e===void 0)return 0;if(this.idleMode||t<Je.prefetch)return 1/0;let n=Math.min(Oae,this.depth.feed_bytes>0?this.depth.feed_bytes:Oae),r=0,o=0;for(let s of e.paths){let a=this.sizes.get(s)??0;if(o>0&&r+a>n)break;r+=a,o++;}return o}frameAt(e,t,n){let r=this.streams;if(r.length===0)return false;let o=this.enabled&&e.readCameraEye(this.eye);o&&(this.position[0]=this.eye[0],this.position[1]=this.eye[1],this.position[2]=this.eye[2]);let s=false;for(let a=0;a<r.length;a++){o&&r[a].frameAt(this.position,t,n);let l=this.stallChecks[a];l!==null&&l()&&(s=true);}return s}frame(e,t){let n=false,r=this.streams;if(r.length===0)return false;let o=null;e!==null&&("readCameraEye"in e?o=e.readCameraEye(this.eye)?this.eye:null:o=e);for(let s=0;s<r.length;s++){o!==null&&this.enabled&&r[s].frame(o,t);let a=this.stallChecks[s];a!==null&&a()&&(n=true);}return n}dispose(){for(let e of this.running.values())e.cancel();this.running.clear();for(let e=0;e<this.streams.length;e++)this.streams[e].releaseAll();this.streams.length=0,this.stallChecks.length=0,this.overrides.length=0;}};var s7e={on:false,tier:"high",pin:false},kae=30,Cae="__cimplify_meters",Nae=null;function yy(){let i=globalThis,e=i[Cae]??Nae;if(e!=null)return e;let t={request:s7e,sink:null,scriptHeap:null,listeners:new Set};return Object.isExtensible(i)?i[Cae]=t:Nae=t,t}function Lae(i){let e=yy(),t=e.request;if(!(t.on===i.on&&t.tier===i.tier&&t.pin===i.pin)){e.request=i;for(let n of e.listeners)n(i);}}function Mae(i){let e=yy();return e.listeners.add(i),e.request.on&&i(e.request),()=>{e.listeners.delete(i);}}function Dae(i,e=null){let t=yy();t.sink=i,t.scriptHeap=e;}function Pae(){return yy().scriptHeap?.()??0}function Fae(i){yy().sink?.(i);}function uu(i){return i!==null&&i.runs>0}function Uae(i,e){let t=null;for(let n of i)n.tier!==e||n.runs===0||(t===null||n.runs>t.runs)&&(t=n);return t}var Bae={low:{download_bytes:67108864,first_play_bytes:8388608,stream_bytes_per_second:187500,stream_latency_ms:150},mid:{download_bytes:268435456,first_play_bytes:25165824,stream_bytes_per_second:75e4,stream_latency_ms:80},high:{download_bytes:1073741824,first_play_bytes:67108864,stream_bytes_per_second:3125e3,stream_latency_ms:40}};var l7e=4;function xP(i){let e=Bae[i];return {downloadBytes:e.download_bytes,firstPlayBytes:e.first_play_bytes,link:{bytesPerSecond:e.stream_bytes_per_second,latencyMs:e.stream_latency_ms,concurrency:l7e}}}({low:xP("low"),mid:xP("mid"),high:xP("high")});var vP=60,Gae=.95,Vae=.8,Hae=OG,Wae=.8,Kae=.6,Yae=.85,Xae=1,qae=2;var u7e=.5,d7e=.2,zae=3,h7e={cull:"Working out what is on screen",particles:"Particles and effects",shadow:"Shadows",main:"Drawing the scene",overlay:"On-screen interface",post:"Screen effects such as glow and blur",targets:"Mirrors, cameras and screens",gi:"Bounced light",rt:"Reflections",volumetrics:"Fog, smoke and weather"};function p7e(i){return i>=u7e?"most":i>=d7e?"some":"a_little"}function RP(i,e=zae){let t=0;for(let n of i)n.cost>0&&(t+=n.cost);return t<=0?[]:i.filter(n=>n.cost>0).map(n=>({label:n.label,share:n.cost/t,amount:p7e(n.cost/t)})).sort((n,r)=>r.share-n.share||n.label.localeCompare(r.label)).slice(0,e)}function Qae(i,e=zae){let t=[];for(let n=0;n<Qu.length&&n<i.length;n++)t.push({label:h7e[Qu[n]],cost:i[n]});return RP(t,e)}var CS=600,Ay=65535,m7e=64,SP=1e3,f7e=1e6,_7e=.5,$ae=.95,y7e=.99;function TP(i,e){return i.length===0?0:i[Math.min(i.length-1,Math.floor(e*i.length))]}function A7e(i,e=vP){let t=i/e;return t>=Gae?"smooth":t>=Vae?"slight":"stutters"}function b7e(i,e){return i>=Yae||e>=qae?"hot":i>=Kae||e>=Xae?"warm":"cool"}var NS=class{constructor(){this.frameMs=new Float64Array(CS);this.moments=new Uint16Array(CS);this.passNs=new Float64Array(Qu.length);this.labels=[];this.head=0;this.count=0;this.moment=Ay;this.gpuFrames=0;this.busyNs=0;this.spanNs=0;this.pressure=0;}mark(e){if(e===null){this.moment=Ay;return}let t=this.labels.indexOf(e);t<0&&this.labels.length<m7e&&(t=this.labels.push(e)-1),this.moment=t<0?Ay:t;}frame(e){!(e>0)||!Number.isFinite(e)||(this.frameMs[this.head]=e*SP,this.moments[this.head]=this.moment,this.head=(this.head+1)%CS,this.count<CS&&this.count++,this.spanNs+=e*SP*f7e);}gpu(e,t,n){e>0&&(this.busyNs+=e,this.gpuFrames++);for(let r=0;r<this.passNs.length&&r<t.length;r++)this.passNs[r]+=t[r];n>this.pressure&&(this.pressure=n);}reset(){this.head=0,this.count=0,this.gpuFrames=0,this.busyNs=0,this.spanNs=0,this.pressure=0,this.passNs.fill(0);}get frames(){return this.count}heat(){let e=this.gpuFrames,t=this.count===0?0:this.spanNs/this.count,n=e===0||t===0?0:Math.min(1,this.busyNs/e/t);return {busyShare:n,pressure:this.pressure,heat:b7e(n,this.pressure)}}meter(e,t=null,n=vP){let r=uu(t)?t.frameScale:1,o=this.frameMs.slice(0,this.count).sort();for(let l=0;l<o.length;l++)o[l]*=r;let s=TP(o,$ae),a=s>0?Math.min(n,SP/s):n;return {tier:e,frames:this.count,p50Ms:TP(o,_7e),p95Ms:s,p99Ms:TP(o,y7e),fps:a,targetFps:n,smooth:A7e(a,n),worstMoment:this.worstMoment(),causes:Qae(this.passNs),calibrated:uu(t),device:uu(t)?t.device:null}}worstMoment(){let e=Ay,t=0;for(let n=0;n<this.labels.length;n++){let r=[];for(let s=0;s<this.count;s++)this.moments[s]===n&&r.push(this.frameMs[s]);if(r.length===0)continue;r.sort((s,a)=>s-a);let o=r[Math.min(r.length-1,Math.floor($ae*r.length))];o>t&&(t=o,e=n);}return e===Ay?null:this.labels[e]}};var kS=class{constructor(){this.script=0;this.engine=0;this.graphics=0;}note(e){e.scriptBytes>this.script&&(this.script=e.scriptBytes),e.engineBytes>this.engine&&(this.engine=e.engineBytes),e.graphicsBytes>this.graphics&&(this.graphics=e.graphicsBytes);}noteScript(e){e>this.script&&(this.script=e);}noteEngine(e){e>this.engine&&(this.engine=e);}noteGraphics(e){e>this.graphics&&(this.graphics=e);}reset(){this.script=0,this.engine=0,this.graphics=0;}get peak(){return {scriptBytes:this.script,engineBytes:this.engine,graphicsBytes:this.graphics}}};function jae(i,e,t=null){let n=uu(t)?t.memoryScale:1,r=(i.scriptBytes+i.engineBytes+i.graphicsBytes)*n,o=Hae[e];return {tier:e,bytes:r,ceilingBytes:o,memory:r>o?"too_much":r>o*Wae?"tight":"fits",causes:RP([{label:"Game code and data",cost:i.scriptBytes},{label:"World, physics and sound",cost:i.engineBytes},{label:"Pictures, models and screens",cost:i.graphicsBytes}]),calibrated:uu(t)}}var g7e=30,E7e={low:zR,mid:Joe,high:sy},LS=class{constructor(e,t,n=[]){this.game=e;this.calibrations=n;this.recorder=new NS;this.memory=new kS;this.stats=G5();this.forced=false;this.sinceGpu=0;this.tier=t;}get playingAs(){return this.tier}get simulating(){return this.forced}playAs(e){let t=this.game.graphics;if(e===null)return t.forceQualityTier(null),this.forced=false,this.reset(),true;let n=t.forceQualityTier(E7e[e]);return this.forced=n,n&&(this.tier=e),this.reset(),n}measureAs(e,t){return t?this.playAs(e):(this.forced&&this.game.graphics.forceQualityTier(null),this.forced=false,this.tier=e,this.reset(),true)}moment(e){this.recorder.mark(e);}update(){if(this.recorder.frame(this.game.clock[Hn]),++this.sinceGpu<g7e)return;this.sinceGpu=0;let e=this.game.graphics;e.gpuStats(this.stats)&&(this.recorder.gpu(this.stats.gpuP50Ns,this.stats.passNs,e.governorPressure()),this.memory.noteGraphics(this.stats.gpuBytes));}noteInspector(e){this.memory.noteEngine(e.arena.highWaterBytes);}noteScriptHeap(e){this.memory.noteScript(e);}reset(){this.recorder.reset(),this.memory.reset(),this.sinceGpu=0;}read(){let e=Uae(this.calibrations,this.tier);return {tier:this.tier,asTier:this.forced,frames:this.recorder.meter(this.tier,e),heat:this.recorder.heat(),memory:jae(this.memory.peak,this.tier,e)}}};yn();var x7e="studio.grant",MS=9,by=1<<20,gy=16<<20,rle=gy/by,IP=64,v7e=8,ile=1,ole=5,sle=7,ip=1,R7e=4,op=ip+R7e,S7e="null",Jae="__cimplify_studio",Zae=new TextEncoder,ele=new TextDecoder,xr=class extends Error{constructor(e){super(e),this.name="StudioFrameError";}};function T7e(i){let e=Zae.encode(i.topic);if(e.length===0||e.length>IP)throw new xr(`a studio topic is 1 to ${IP} bytes`);let t=Zae.encode(i.json??(i.body===void 0?S7e:JSON.stringify(i.body))),n=i.bytes??null,r=op+e.length+t.length+(n?.length??0);if(r>gy)throw new xr(`a studio message is at most ${gy} bytes`);let o=new Uint8Array(r),s=new DataView(o.buffer);return o[0]=e.length,o.set(e,ip),s.setUint32(ip+e.length,t.length,true),o.set(t,op+e.length),n!==null&&o.set(n,op+e.length+t.length),o}function w7e(i,e,t){let n=Math.max(1,Math.ceil(t.length/by));if(n>rle)throw new xr(`a studio message is at most ${gy} bytes`);let r=[];for(let o=0;o<n;o++){let s=t.subarray(o*by,Math.min(t.length,(o+1)*by)),a=new Uint8Array(MS+s.length),l=new DataView(a.buffer);a[0]=i,l.setUint32(ile,e>>>0,true),l.setUint16(ole,o,true),l.setUint16(sle,n,true),a.set(s,MS),r.push(a);}return r}function tle(i){if(i.length<op)throw new xr("a studio message is cut short");let e=i[0];if(e===0||e>IP||i.length<op+e)throw new xr("a studio message has no readable topic");let n=new DataView(i.buffer,i.byteOffset,i.byteLength).getUint32(ip+e,true),r=op+e;if(r+n>i.length)throw new xr("a studio message body runs past its end");let o=ele.decode(i.subarray(ip,ip+e)),s;try{s=JSON.parse(ele.decode(i.subarray(r,r+n)));}catch{throw new xr("a studio message body is not JSON")}let a=r+n;return {topic:o,body:s,bytes:a<i.length?i.slice(a):null}}var DS=class{constructor(){this.seq=-1;this.count=0;this.next=0;this.size=0;this.parts=[];}get pending(){return this.next>0}reset(){this.seq=-1,this.count=0,this.next=0,this.size=0,this.parts=[];}accept(e){try{return this.take(e)}catch(t){throw this.reset(),t}}take(e){if(e.length<MS)throw new xr("a studio frame is cut short");let t=new DataView(e.buffer,e.byteOffset,e.byteLength),n=t.getUint32(ile,true),r=t.getUint16(ole,true),o=t.getUint16(sle,true);if(o===0||o>rle||r>=o)throw new xr("a studio frame has an impossible part count");if(r===0)this.reset(),this.seq=n,this.count=o;else if(n!==this.seq||o!==this.count||r!==this.next)throw new xr("a studio frame arrived out of order");let s=e.subarray(MS);if(s.length>by)throw new xr("a studio frame is over its part size");if(this.size+=s.length,this.size>gy)throw new xr("a studio message is over its size");if(this.next=r+1,o===1)return this.reset(),tle(s);if(this.parts.push(s.slice()),this.next<o)return null;let a=new Uint8Array(this.size),l=0;for(let c of this.parts)a.set(c,l),l+=c.length;return this.reset(),tle(a)}},PS=class{constructor(e,t){this.tag=e;this.send=t;this.seq=0;}post(e){let t=w7e(this.tag,this.seq,T7e(e));this.seq=this.seq+1>>>0;for(let n of t)this.send(n);}},nle=null;function FS(){let i=globalThis,e=i[Jae]??nle;if(e!=null)return e;let t={sink:null,listeners:new Set,held:[]};return Object.isExtensible(i)?i[Jae]=t:nle=t,t}function ale(i){let e=FS();e.sink=i,i===null&&(e.held.length=0);}function lle(i){let e=FS().sink;return e===null?false:(e(i),true)}function cle(i){let e=FS();if(!(e.sink===null||i.topic===x7e)){if(e.listeners.size===0){e.held.length<v7e&&e.held.push(i);return}for(let t of e.listeners)t(i);}}function ule(i){let e=FS();e.listeners.add(i);let t=e.held.splice(0);for(let n of t)i(n);return ()=>{e.listeners.delete(i);}}ee.studio;ee.studio_report;var OP="timeline.",Nl={record:"timeline.record",stop:"timeline.stop",seek:"timeline.seek",play:"timeline.play",moment:"timeline.moment",prove:"timeline.prove"},sp={state:"timeline.state",moment:"timeline.moment_report",proof:"timeline.proof",refused:"timeline.refused"},US="This preview can't rewind.",ap="Record a play first.";var I7e=4,O7e=0,CP=1;function C7e(i){return !(typeof i!="object"||i===null||ArrayBuffer.isView(i)||i instanceof Map||i instanceof Set||i instanceof ArrayBuffer||Array.isArray(i))}var BS=class{constructor(e,t,n=new Set){this.slots=t;this.scalars=[];this.arrays=[];this.copies=[];if(!Number.isInteger(t)||t<1)throw new _("invalid_argument","a state mirror needs at least one slot");let r=0,o=(s,a)=>{for(let l of Object.keys(s)){if(n.has(l))continue;let c=s[l];if(typeof c=="number")this.scalars.push({holder:s,key:l,kind:O7e});else if(typeof c=="boolean")this.scalars.push({holder:s,key:l,kind:CP});else if(ArrayBuffer.isView(c)&&!(c instanceof DataView)){let u=new Uint8Array(c.buffer,c.byteOffset,c.byteLength);this.arrays.push({view:u,offset:r}),r+=u.byteLength;}else a<I7e&&C7e(c)&&o(c,a+1);}};o(e,0),this.arrayBytes=r,this.scalarSlots=new Float64Array(this.scalars.length*t),this.arraySlots=new Uint8Array(r*t);for(let s=0;s<t;s++)for(let a of this.arrays){let l=s*r+a.offset;this.copies.push(this.arraySlots.subarray(l,l+a.view.byteLength));}}get bytes(){return this.scalarSlots.byteLength+this.arraySlots.byteLength}save(e){let t=this.slot(e),n=t*this.scalars.length;for(let s=0;s<this.scalars.length;s++){let a=this.scalars[s],l=a.holder[a.key];this.scalarSlots[n+s]=a.kind===CP?l===true?1:0:l;}let r=this.copies,o=t*this.arrays.length;for(let s=0;s<this.arrays.length;s++)r[o+s].set(this.arrays[s].view);}load(e){let t=this.slot(e),n=t*this.scalars.length;for(let s=0;s<this.scalars.length;s++){let a=this.scalars[s],l=this.scalarSlots[n+s];a.holder[a.key]=a.kind===CP?l===1:l;}let r=this.copies,o=t*this.arrays.length;for(let s=0;s<this.arrays.length;s++)this.arrays[s].view.set(r[o+s]);}slot(e){if(!Number.isInteger(e)||e<0||e>=this.slots)throw new _("invalid_argument",`a state mirror has slots 0 to ${this.slots-1}`);return e}};var dle=["touch","gesture","tilt","key","choice","gift","vote","ai"],du=3,N7e=65536,k7e=1<<20,NP=-1;function hle(){return {tick:0,source:"touch",a:0,b:0,c:0,bytes:null}}var GS=class{constructor(e=N7e,t=k7e){this.count=0;this.used=0;this.ticks=new Uint32Array(e),this.sources=new Uint8Array(e),this.words=new Float64Array(e*du),this.at=new Int32Array(e),this.lengths=new Uint32Array(e),this.pool=new Uint8Array(t);}get length(){return this.count}get lastTick(){return this.count===0?-1:this.ticks[this.count-1]}record(e,t,n=0,r=0,o=0,s=null){if(this.count===this.ticks.length)throw new _("capacity_exceeded",`the input log holds ${this.ticks.length} inputs`);if(this.count>0&&e<this.ticks[this.count-1])throw new _("invalid_argument","inputs are recorded in tick order");let a=this.count;if(this.ticks[a]=e,this.sources[a]=dle.indexOf(t),this.words[a*du]=n,this.words[a*du+1]=r,this.words[a*du+2]=o,s===null)this.at[a]=NP,this.lengths[a]=0;else {if(this.used+s.length>this.pool.length)throw new _("capacity_exceeded",`the input log holds ${this.pool.length} payload bytes`);this.pool.set(s,this.used),this.at[a]=this.used,this.lengths[a]=s.length,this.used+=s.length;}this.count++;}first(e){let t=0,n=this.count;for(;t<n;){let r=t+n>>>1;this.ticks[r]<e?t=r+1:n=r;}return t}read(e,t){if(e<0||e>=this.count)throw new _("invalid_argument",`the input log has no input ${e}`);return t.tick=this.ticks[e],t.source=dle[this.sources[e]],t.a=this.words[e*du],t.b=this.words[e*du+1],t.c=this.words[e*du+2],t.bytes=this.at[e]===NP?null:this.pool.subarray(this.at[e],this.at[e]+this.lengths[e]),t}forEachAt(e,t,n){let r=0;for(let o=this.first(e);o<this.count&&this.ticks[o]===e;o++)t(this.read(o,n)),r++;return r}truncateAfter(e){let t=this.first(e+1);if(t>=this.count)return;let n=this.used;for(let r=t;r<this.count;r++)this.at[r]!==NP&&(n=Math.min(n,this.at[r]));this.used=n,this.count=t;}clear(){this.count=0,this.used=0;}},VS=class{constructor(e,t,n){this.store=e;this.log=t;this.sim=n;this.tickValue=0;}get tick(){return this.tickValue}start(){this.tickValue=0,this.store.clearKeyframes(),this.store.keyframe(0);}advance(){this.sim.step(this.tickValue,this.log),this.tickValue++,this.tickValue%this.store.keyframeEvery===0&&this.store.keyframe(this.tickValue);}diverge(){this.log.truncateAfter(this.tickValue-1),this.store.truncateKeyframes(this.tickValue);}seek(e){if(!Number.isInteger(e)||e<0)throw new _("invalid_argument","seek to a whole tick");let t=this.store.nearestKeyframe(e);for(e>this.tickValue?t!==null&&t>this.tickValue&&this.store.seekKeyframe(t)&&(this.tickValue=t):e<this.tickValue&&(t!==null&&this.store.seekKeyframe(t)?this.tickValue=t:(this.sim.restart(),this.start()));this.tickValue<e;)this.advance();return this.tickValue}};var lp=30,HS=64,L7e=16384,ple=3600*10,M7e=15,D7e=16,P7e=16,WS=0n;function mle(i){return i.toString(D7e).padStart(P7e,"0")}function fle(i,e){if(typeof i!="object"||i===null)return null;let t=i[e];return typeof t=="number"&&Number.isFinite(t)?t:null}var KS=class{constructor(e,t){this.game=e;this.send=t;this.keyframeEvery=lp;this.log=new GS;this.scratch=hle();this.digests=new BigUint64Array(Math.ceil(ple/lp)+1);this.travel=null;this.store=null;this.live=true;this.proving=false;this.divergence=null;this.checked=0;this.endTick=0;this.recordingValue=false;this.holdingValue=false;this.replayInput=e=>{this.game.input.replay(e.a,e.bytes,e.b);};this.sim={restart:()=>{},step:(e,t)=>{this.live||t.forEachAt(e,this.replayInput,this.scratch),this.game.step();}};this.mirror=new BS(e.input,HS);}get recording(){return this.recordingValue}get holding(){return this.holdingValue}get tick(){return this.travel?.tick??0}handle(e){switch(e.topic){case Nl.record:this.record();return;case Nl.stop:this.stop();return;case Nl.seek:{let t=fle(e.body,"tick");t!==null&&this.seek(t);return}case Nl.play:this.play();return;case Nl.moment:{let t=fle(e.body,"tick");t!==null&&this.moment(t);return}case Nl.prove:this.prove();return}}record(){let e=this.store??this.game.snapshots();if(e===null)return this.refuse("record",US);if(this.store===null){if(!e.enableKeyframes({every:lp,slots:HS,leaves:L7e}))return this.refuse("record",US);this.store=e;}this.log.clear(),this.digests.fill(WS),this.endTick=0,this.live=true,this.travel=new VS(this,this.log,this.sim),this.travel.start(),this.recordingValue=true,this.holdingValue=false,this.game.input.setTap(this),this.report();}stop(){this.game.input.setTap(null),this.recordingValue=false,this.holdingValue=false,this.store?.clearKeyframes(),this.travel=null,this.report();}step(){let e=this.travel;if(e===null||this.holdingValue){this.game.step();return}if(e.tick>=ple){this.recordingValue=false,this.game.input.setTap(null),this.game.step(),this.report();return}e.advance(),this.endTick=e.tick,e.tick%M7e===0&&this.report();}seek(e){let t=this.travel;if(t===null)return this.refuse("seek",ap);let n=Math.max(this.from(),Math.min(this.endTick,Math.round(e)));this.holdingValue=true,this.resimulate(()=>t.seek(n)),this.report();}play(){let e=this.travel;if(e===null)return this.refuse("play",ap);if(e.tick<this.endTick){e.diverge();let t=Math.floor(e.tick/lp)+1;this.digests.fill(WS,t),this.endTick=e.tick;}this.holdingValue=false,this.report();}moment(e){if(this.travel===null)return this.refuse("moment",ap);this.seek(e);let t=this.store,n={tick:this.tick,digest:mle(t===null?WS:t.digest()),values:this.game.values()};this.send({topic:sp.moment,body:n});}prove(){let e=this.travel;if(e===null)return this.refuse("prove",ap);let t=this.from(),n=this.holdingValue?e.tick:this.endTick;this.holdingValue=true,this.divergence=null,this.checked=0,this.resimulate(()=>{e.seek(t),this.proving=true;try{e.seek(n);}finally{this.proving=false;}});let r={exact:this.divergence===null,from:t,to:n,checked:this.checked,firstDivergence:this.divergence};this.send({topic:sp.proof,body:r}),this.report();}drained(e,t,n){let r=this.travel;!this.recordingValue||!this.live||r===null||this.holdingValue||this.log.record(r.tick,zne(t,n),e,n,0,n>0?t:null);}keyframe(e){let t=this.store;if(t===null||!t.keyframe(e))return false;let n=e/lp;if(this.mirror.save(n%HS),n>=this.digests.length)return true;let r=t.digest();return this.live?this.digests[n]=r:this.proving&&this.digests[n]!==WS&&(this.checked++,this.digests[n]!==r&&this.divergence===null&&(this.divergence=e)),true}nearestKeyframe(e){return this.store?.nearestKeyframe(e)??null}seekKeyframe(e){let t=this.store;return t===null||!t.seekKeyframe(e)?false:(this.mirror.load(e/lp%HS),true)}truncateKeyframes(e){this.store?.truncateKeyframes(e);}clearKeyframes(){this.store?.clearKeyframes();}from(){return this.store?.keyframeStats()?.oldest??0}resimulate(e){this.live=false;try{e();}finally{this.live=true;}}refuse(e,t){let n={action:e,message:t};this.send({topic:sp.refused,body:n});}report(){let e={recording:this.recordingValue,holding:this.holdingValue,tick:this.tick,end:this.endTick,from:this.travel===null?0:this.from(),tickHz:this.game.tickHz};this.send({topic:sp.state,body:e});}};var U7e=16,kP=class{constructor(e){this.phases=null;this.tables=[];this.chemistryApi=null;this.fluids=[];this.destruction=null;this.softBodySystem=null;this.reactives=[];this.smokes=[];this.stories=[];this.clothSystem=null;this.meters=null;this.meterFrames=0;this.stopMeters=null;this.timeline=null;this.stopTimeline=null;this.disposed=false;this.governorFrames=0;this.backend=e.backend,this.world=new Tv(e.capacity??4096,e.backend.memory),this.transforms=new nS(this.world,e.backend.transforms),this.loop=new Ub(e),this.clock=this.loop.time.values,this.random=new mh(e.seed??0),this.input=new Dv(e.gestures),this.physics=new HR(e.backend.physics,this.world,this.transforms,this.loop.stepSeconds,e.physics),this.physics.enrolRollback(this.world,this.random,this.loop),this.kernelRunner=new gi(e.backend.kernels??null),this.world.attachKernels(this.kernelRunner),One(e.backend.kernels??null),gse(),this.world.attachStreamer(new lS(e.backend.streaming??null,this.world,this.transforms,this.physics)),this.nav=new Ix(e.backend.nav??new Qv),this.ai=e.backend.ai?new Bv(e.backend.ai):null,this.graphics=new QR(e.backend.graphics,this.world,this.transforms,e.backend.scenery??null),this.world.kernelServices({physics:this.physics,nav:this.nav,graphics:this.graphics}),this.animation=new fx(this.world,this.transforms,e.animation),this.audio=new gx(e.backend.audio,this.transforms,e.maxVoices),this.ui=new rS(e.ui??null,e.maxHudSlots),this.net=new xR,this.scratch=new Pv(e.scratch),this.scenes=new $R;let t=new OS(e.assets??null);this.prefetch=t,this.graphics.scenery.attachPrefetch(t),this.scenes.onRegister(r=>{r.prefetch!==void 0&&t.describe(r.name,r.prefetch);}),this.scenes.onEnter(r=>t.entered(r.name));let n=this.audio;this.input.onFirstGesture(()=>n.unlock()),this.nature=e.nature??{};}applyMeters(e){if(this.disposed)return;if(!e.on){this.meters?.playAs(null),this.meters=null;return}let t=this.meters??new LS(this,e.tier);this.meters=t,this.meterFrames=0,t.measureAs(e.tier,e.pin);}meter(e){if(e.update(),++this.meterFrames<kae)return;this.meterFrames=0;let t=this.kernelRunner.inspectorReadout;t!==null&&e.noteInspector(t),e.noteScriptHeap(Pae()),Fae(e.read());}get chemistry(){if(this.chemistryApi===null){let e=this.nature.tickHz??Math.round(1/this.loop.stepSeconds);this.chemistryApi=new uy(this.backend.chemistry??null,{...this.nature,tickHz:e});}return this.chemistryApi}get tick(){return this.clock[pm]}get alpha(){return this.clock[ys]}get stepSeconds(){return this.clock[ai]}get frameSeconds(){return this.clock[Hn]}get time(){return this.loop.time}fluid(e){let t=this.backend.fluids;if(!t)throw new _("unsupported_feature","fluids need the native engine with feature fluid_1");let n=new hS(t,this.transforms,this.physics,e);return this.fluids.push(n),n}get softBodies(){if(this.softBodySystem===null){let e=this.backend.softBodies;if(!e)throw new _("unsupported_feature","soft bodies need the native engine with feature soft_body_1");this.softBodySystem=new DR(e);}return this.softBodySystem}softBody(e,t){return this.softBodies.create(e,t)}get cloths(){if(this.clothSystem===null){let e=this.backend.cloths;if(!e)throw new _("unsupported_feature","cloth needs the native engine with feature cloth_1");this.clothSystem=new _S(e);}return this.clothSystem}cloth(e,t){return this.cloths.create(e,t)}reactiveFluid(e){let t=this.backend.reactive;if(!t)throw new _("unsupported_feature","reactive fluids need the native engine with feature reactive_fluid_1");let n=e.framesPerTick??pn.framesPerTick,r=e.chemistry===void 0,o=Math.round(1/(this.loop.stepSeconds*n)),s=e.chemistry??new uy(this.backend.chemistry??null,{...this.nature,tickHz:o});try{let a=new pS(t,s,e,r);return this.reactives.push(a),a}catch(a){throw r&&s.dispose(),a}}smokeVolume(e){let t=this.backend.smoke;if(!t)throw new _("unsupported_feature","smoke volumes need the native engine with feature gpu_smoke_1");let n=new mS(t,e);return this.smokes.push(n),n}story(e,t={}){let n=this.backend.story;if(!n)throw new _("unsupported_feature","stories need the native engine with the story runtime");let r=new fS(n,e,t);return this.stories.push(r),r}removeStory(e){let t=this.stories.indexOf(e);t>=0&&this.stories.splice(t,1),e.dispose();}removeSmokeVolume(e){let t=this.smokes.indexOf(e);t>=0&&this.smokes.splice(t,1),e.dispose();}removeReactiveFluid(e){let t=this.reactives.indexOf(e);t>=0&&this.reactives.splice(t,1),e.dispose();}removeFluid(e){let t=this.fluids.indexOf(e);t>=0&&this.fluids.splice(t,1),e.dispose();}destructible(e,t){let n=this.backend.destruction;if(!n)throw new _("unsupported_feature","destruction needs the native engine with feature destruction_1");this.destruction??=new AS(n);let r=new yS(n,this.world,this.transforms,this.graphics,e,t);return this.destruction.add(r),r}async breakable(e,t,n={}){let r=this.backend.destruction;if(!r?.fracture)throw new _("unsupported_feature","breaking a made thing needs the native engine with live fracture");let o=r.fracture(e,t),s=await this.graphics.loadModel({bytes:o.model.slice().buffer});return this.destructible(s,{...n,fracture:o.asset})}removeDestructible(e){this.destruction?.remove(e);}table(e,t){let n=new vh(this.backend.soa??null,e,t);return this.tables.push(n),n}addScene(e){this.scenes.register(e);}addSystem(e){this.scenes.addSystem(e);}reload(e){return this.scenes.reload(e,this)}start(e){this.scenes.switchTo(ZD(t=>this.scenes.has(t))??e),this.scenes.applyPending(this),this.stopMeters??=Mae(t=>this.applyMeters(t)),this.stopTimeline??=ule(t=>this.studio(t));}studio(e){this.disposed||!e.topic.startsWith(OP)||(this.timeline??=new KS(this.timelineGame(),t=>{lle(t);}),this.timeline.handle(e));}timelineGame(){return {input:this.input,tickHz:Math.round(1/this.loop.stepSeconds),snapshots:()=>this.physics.rollback,step:()=>this.fixedStep(),values:()=>this.storyValues()}}storyValues(){let e={};return this.stories.forEach((t,n)=>{let r=n===0?"":`${n+1}.`;t.started&&(e[`${r}moment`]=t.beatName(t.beat));for(let o of t.variables)e[`${r}${o.name}`]=String(t.get(o.index));}),e}steps(e){let t=this.timeline;if(t!==null&&t.recording)for(let n=0;n<e;n++)t.step();else for(let n=0;n<e;n++)this.fixedStep();}frame(e){this.clock[ki]=e,this.runFrame();}sampleGovernor(){this.governorFrames++%U7e===0&&this.world.kernelGpuPressure(this.graphics.governorPressure());}runFrame(){this.sampleGovernor();let e=this.phases;if(e!==null){this.profiledFrame(e);return}if(this.world.kernelFrame(),this.timeline?.holding===true){this.loop.hold(),this.present();return}this.input.processEventsFrom(this.clock,ki),this.steps(this.loop.beginAtClock()),this.present();let t=this.meters;t!==null&&this.meter(t);}profiledFrame(e){e.begin(),this.world.kernelFrame(),e.lap(so.kernels);let t=this.timeline?.holding===true;t||this.input.processEventsFrom(this.clock,ki),e.lap(so.input),t&&this.loop.hold();let n=t?0:this.loop.beginAtClock();e.steps=n,this.steps(n),e.lap(so.steps);let r=this.loop.time;this.scenes.update(this),e.lap(so.update),this.transforms.computeRender(r),e.lap(so.transforms),this.graphics.sync(r),e.lap(so.sync);for(let s=0;s<this.fluids.length;s++)this.fluids[s].update(this.frameSeconds);this.softBodySystem?.present(),this.clothSystem?.present(),e.lap(so.fluids),this.audio.update(r),e.lap(so.audio),this.ui.flush(),e.lap(so.ui),this.graphics.render(r),this.stream(),this.scratch.reset(),e.lap(so.render),e.end();let o=this.meters;o!==null&&this.meter(o);}advance(e){this.sampleGovernor(),this.world.kernelFrame(),this.input.processEvents();for(let t=0;t<e;t++)this.fixedStep();this.loop.settle(e),this.present();}dispose(){if(!this.disposed){this.disposed=true,this.stopMeters?.(),this.stopMeters=null,this.meters=null,this.stopTimeline?.(),this.stopTimeline=null,this.timeline?.stop(),this.timeline=null,this.net.disconnect(),this.chemistryApi?.dispose(),this.chemistryApi=null;for(let e of this.tables)e.dispose();this.tables.length=0;for(let e of this.fluids)e.dispose();this.fluids.length=0,this.destruction?.dispose(),this.destruction=null,this.softBodySystem?.dispose(),this.softBodySystem=null;for(let e of this.reactives)e.dispose();this.reactives.length=0;for(let e of this.smokes)e.dispose();this.smokes.length=0;for(let e of this.stories)e.dispose();this.stories.length=0,this.clothSystem?.dispose(),this.clothSystem=null,this.graphics.scenery.dispose(),this.prefetch.dispose(),this.backend.graphics.dispose(),this.backend.physics.dispose(),this.nav.dispose(),this.ai?.dispose(),this.backend.audio.dispose(),sse(this.backend);}}fixedStep(){this.scenes.applyPending(this),this.input.beginStep(),this.transforms.snapshot(),this.scenes.fixedUpdate(this),this.ai?.ready&&this.ai.step(),this.animation.update(this.loop.time),this.physics.step(),this.destruction?.step(this.loop.stepSeconds),this.softBodySystem?.step(this.loop.stepSeconds);for(let e=0;e<this.reactives.length;e++)this.reactives[e].step(this.loop.stepSeconds);for(let e=0;e<this.smokes.length;e++)this.smokes[e].step(this.loop.stepSeconds);this.clothSystem?.step(this.loop.stepSeconds),this.nav.stepFixed(this.loop.time),this.audio.fixedStep(this.loop.time),this.loop.completeStep(),this.scratch.reset();}present(){let e=this.loop.time;this.scenes.update(this),this.transforms.computeRender(e),this.graphics.sync(e);for(let t=0;t<this.fluids.length;t++)this.fluids[t].update(this.frameSeconds);this.softBodySystem?.present(),this.clothSystem?.present(),this.audio.update(e),this.ui.flush(),this.graphics.render(e),this.stream(),this.scratch.reset();}stream(){u8(this.prefetch.frameAt(this.graphics,this.clock,Hn));}};async function _le(i){let e=new kP(i);return await e.physics.init(),await e.graphics.attach(i.surface??null),e}var B7e=2400,G7e=32,V7e=512,H7e=4,W7e=120,yle=50,Ale=.5,YS=8,ble=1.5,K7e=2,Y7e=.5,X7e=5,q7e=10;async function z7e(i){let e=yee(i,r=>new dr(r,void 0,null),_ee({})),t=await _le({backend:e}),n=Kp(i.symbols);for(let r=0;r<V7e;r++)t.transforms.add(t.world.spawn(),r%YS,0,r/YS|0);if(n){let r=t.world.spawn();t.transforms.add(r,0,-Ale,0),t.physics.addCollider(r,{shape:{kind:"cuboid",halfExtents:[yle,Ale,yle]}});for(let o=0;o<G7e;o++){let s=t.world.spawn();t.transforms.add(s,o%YS*ble,K7e,(o/YS|0)*ble),t.physics.addBody(s,{kind:"dynamic",canSleep:false}),t.physics.addCollider(s,{shape:{kind:"ball",radius:Y7e}});}}return {game:t,ray:new Xi().set(0,X7e,0,0,-1,0,q7e),hit:new qi,physics:n}}function Q7e(i){if(i.physics)for(let e=0;e<H7e;e++)i.game.physics.raycast(i.ray,i.hit);i.game.advance(1);}function gle(i,e,t=B7e){let n=false,o=(async()=>{let s=await z7e(i);try{for(let a=0;a<t&&!n;a++)Q7e(s),(a+1)%W7e===0&&await e();}finally{s.game.dispose();}})();return o.catch(()=>{}),{done:o,stop(){n=true;}}}yn();var Ele=0,$7e=16;function $S(i,e,t){return i.set(e,[...i.get(e)??[],t]),()=>{let n=(i.get(e)??[]).filter(r=>r!==t);n.length===0?i.delete(e):i.set(e,n);}}function xle(i,e,t,n){for(let r=0;r<n;r++)e[t+r]=i[r];}function Ey(i,e,t,n){let r=i.get(e);if(r!==void 0)for(let o=0;o<r.length;o++)r[o](t,n);}var XS=class{constructor(e){this.bridge=e;this.length=Ae;this.scheduled=false;this.channel={flags:0,slot:0,sequence:0,sender:0,payload_offset:0,payload_length:0};this.roomInput={flags:0,action:0,sequence:0,client_tick:0,sender:0,payload_offset:0,payload_length:0};this.fastValue={status:0,slot:0,correlation:0,stamp_low:0,stamp_high:0,value_offset:0,value_length:0};this.counterValue={status:0,slot:0,correlation:0,value:0};this.presence={flags:0,server_tick:0,cell_index:0,acked_input:0,layer:0,baseline_age:0,count:0,entries_offset:0};this.channels=new Map;this.roomInputs=new Map;this.fastValues=new Map;this.counterValues=new Map;this.presenceTicks=new Map;this.faults=new Uint32Array($7e);this.flush=()=>{this.scheduled=false,this.length!==Ae&&(this.bridge.send(this.out,this.length),this.length=Ae);};this.out=new Uint8Array(fs.frame_outbox_bytes),this.out[0]=ee.frames,this.view=new DataView(this.out.buffer);}reserve(e){return this.length+e>this.out.length&&this.flush(),this.scheduled||(this.scheduled=true,queueMicrotask(this.flush)),this.length}commit(e){return e>0&&(this.length+=e),e}receive(e){let t=new DataView(e.buffer,e.byteOffset,e.byteLength),n=e.byteLength,r=Ae;for(;r<n;){let o=vl(t,r,n),s=Jv(t,r,n);if(o<0||s<0){this.faults[0]+=1;return}switch(o){case Gt.channel:eR(t,r,n,this.channel)>0&&Ey(this.channels,this.channel.slot,this.channel,t);break;case Gt.room_input:Gre(t,r,n,this.roomInput)>0&&Ey(this.roomInputs,this.roomInput.sender,this.roomInput,t);break;case Gt.fast_value:Xre(t,r,n,this.fastValue)>0&&Ey(this.fastValues,this.fastValue.slot,this.fastValue,t);break;case Gt.counter_value:zre(t,r,n,this.counterValue)>0&&Ey(this.counterValues,this.counterValue.slot,this.counterValue,t);break;case Gt.presence_tick:nR(t,r,n,this.presence)>0&&Ey(this.presenceTicks,Ele,this.presence,t);break;default:this.faults[o]+=1;}r+=s;}}};function jS(i,e,t){return $S(i,e,t)}function vle(i,e){return $S(i.presenceTicks,Ele,e)}var qS=class{constructor(e,t,n,r){this.lane=e;this.slot=t;this.headerBytes=r;this.sequence=0;this.max_payload_bytes=n,this.scratch=new Uint8Array(n),this.scratchView=new DataView(this.scratch.buffer);}payload(){return this.scratchView}send(e,t=0){if(e<0||e>this.max_payload_bytes)return -1;let n=this.lane.reserve(this.headerBytes+e),r=this.header(n,e,t);if(r<0)return r;xle(this.scratch,this.lane.out,n+this.headerBytes,e),this.lane.commit(r);let o=this.sequence;return this.sequence=this.sequence+1>>>0,o}},xy=class extends qS{constructor(t,n,r){super(t,n,Math.min(r,an.max_channel_payload_bytes),et.channel.header_bytes);this.frame={flags:0,slot:0,sequence:0,sender:0};this.frame.slot=n;}header(t,n,r){return this.frame.flags=r,this.frame.sequence=this.sequence,Zv(this.lane.view,t,this.frame,n)}},zS=class extends qS{constructor(t,n){super(t,n,an.max_room_input_payload_bytes,et.room_input.header_bytes);this.frame={flags:0,action:0,sequence:0,client_tick:0,sender:0};this.frame.sender=n;}header(t,n,r){return this.frame.flags=r,this.frame.sequence=this.sequence,U_(this.lane.view,t,this.frame,n)}},vy=class{constructor(e,t,n){this.lane=e;this.slot=t;this.keyBytes=new Uint8Array(an.max_fast_key_bytes);this.frame={target:tm.fast_target[n],slot:t,correlation:0};}key(){return this.keyBytes}read(e,t){if(e<0||e>this.keyBytes.length)return -1;let n=this.lane.reserve(et.fast_read.header_bytes+e);this.frame.correlation=t>>>0;let r=Yre(this.lane.view,n,this.frame,e);return r<0?r:(xle(this.keyBytes,this.lane.out,n+et.fast_read.header_bytes,e),this.lane.commit(r))}on_value(e){return $S(this.lane.fastValues,this.slot,e)}},QS=class{constructor(e,t){this.lane=e;this.slot=t;this.frame={status:0,slot:0,correlation:0,value:0};this.frame.slot=t;}add(e,t){let n=this.lane.reserve(et.counter_add.header_bytes);return this.frame.correlation=t>>>0,this.frame.value=e,this.lane.commit(qre(this.lane.view,n,this.frame))}on_value(e){return $S(this.lane.counterValues,this.slot,t=>e(t))}};function Rle(i,e){let t=i.reserve(et.move_input.header_bytes);return i.commit(tR(i.view,t,e))}var Sle="Q1VOSSQJAAAAAAAACQAAAAoAAAALAAAADQAAAA4AAAAgAAAAIQAAACIAAAAjAAAAJAAAACUAAAAmAAAAJwAAACgAAAApAAAAKgAAACsAAAAsAAAALQAAAC4AAAAvAAAAMAAAADoAAAA8AAAAPwAAAEAAAABbAAAAXAAAAF0AAABeAAAAewAAAHwAAAB9AAAAfgAAAH8AAACFAAAAhgAAAKAAAAChAAAAogAAAKMAAACmAAAAqQAAAKoAAACrAAAArAAAAK0AAACuAAAArwAAALAAAACxAAAAsgAAALQAAAC1AAAAuwAAALwAAAC/AAAAwAAAAMgCAADJAgAAzAIAAM0CAADfAgAA4AIAAAADAABPAwAAUAMAAFwDAABjAwAAcAMAAH4DAAB/AwAAgwQAAIoEAACJBQAAigUAAIsFAACPBQAAkAUAAJEFAAC+BQAAvwUAAMAFAADBBQAAwwUAAMQFAADGBQAAxwUAAMgFAADQBQAA6wUAAO8FAADzBQAAAAYAAAYGAAAJBgAADAYAAA4GAAAQBgAAGwYAABwGAAAdBgAAIAYAAEsGAABgBgAAagYAAGsGAABtBgAAcAYAAHEGAADUBgAA1QYAANYGAADdBgAA3gYAAN8GAADlBgAA5wYAAOkGAADqBgAA7gYAAPAGAAD6BgAADwcAABAHAAARBwAAEgcAADAHAABLBwAApgcAALEHAADABwAAygcAAOsHAAD0BwAA+AcAAPkHAAD6BwAA/QcAAP4HAAAACAAAFggAABoIAAAbCAAAJAgAACUIAAAoCAAAKQgAAC4IAABZCAAAXAgAAJAIAACSCAAAlwgAAKAIAADKCAAA4ggAAOMIAAADCQAABAkAADoJAAA7CQAAPAkAAD0JAAA+CQAAQQkAAEkJAABNCQAATgkAAFAJAABRCQAAWAkAAGIJAABkCQAAZgkAAHAJAACBCQAAggkAAIQJAAC8CQAAvQkAAL4JAAC/CQAAwQkAAMUJAADHCQAAyQkAAMsJAADNCQAAzgkAANcJAADYCQAA4gkAAOQJAADmCQAA8AkAAPIJAAD0CQAA+QkAAPoJAAD7CQAA/AkAAP4JAAD/CQAAAQoAAAMKAAAECgAAPAoAAD0KAAA+CgAAQQoAAEMKAABHCgAASQoAAEsKAABOCgAAUQoAAFIKAABmCgAAcAoAAHIKAAB1CgAAdgoAAIEKAACDCgAAhAoAALwKAAC9CgAAvgoAAMEKAADGCgAAxwoAAMkKAADKCgAAywoAAM0KAADOCgAA4goAAOQKAADmCgAA8AoAAPEKAADyCgAA+goAAAALAAABCwAAAgsAAAQLAAA8CwAAPQsAAD4LAABACwAAQQsAAEULAABHCwAASQsAAEsLAABNCwAATgsAAFULAABYCwAAYgsAAGQLAABmCwAAcAsAAIILAACDCwAAvgsAAL8LAADACwAAwQsAAMMLAADGCwAAyQsAAMoLAADNCwAAzgsAANcLAADYCwAA5gsAAPALAAD5CwAA+gsAAAAMAAABDAAABAwAAAUMAAA8DAAAPQwAAD4MAABBDAAARQwAAEYMAABJDAAASgwAAE4MAABVDAAAVwwAAGIMAABkDAAAZgwAAHAMAAB3DAAAeAwAAIEMAACCDAAAhAwAAIUMAAC8DAAAvQwAAL4MAAC/DAAAwQwAAMIMAADDDAAAxQwAAMYMAADJDAAAygwAAM4MAADVDAAA1wwAAOIMAADkDAAA5gwAAPAMAADzDAAA9AwAAAANAAACDQAABA0AADsNAAA9DQAAPg0AAD8NAABBDQAARQ0AAEYNAABJDQAASg0AAE0NAABODQAATw0AAFcNAABYDQAAYg0AAGQNAABmDQAAcA0AAHkNAAB6DQAAgQ0AAIINAACEDQAAyg0AAMsNAADPDQAA0A0AANINAADVDQAA1g0AANcNAADYDQAA3w0AAOANAADmDQAA8A0AAPINAAD0DQAAAQ4AADEOAAAyDgAAMw4AADQOAAA7DgAAPw4AAEAOAABHDgAATw4AAFAOAABaDgAAXA4AAIEOAACDDgAAhA4AAIUOAACGDgAAiw4AAIwOAACkDgAApQ4AAKYOAACnDgAAsQ4AALIOAACzDgAAtA4AAL0OAAC+DgAAwA4AAMUOAADGDgAAxw4AAMgOAADPDgAA0A4AANoOAADcDgAA4A4AAAEPAAAFDwAABg8AAAgPAAAJDwAACw8AAAwPAAANDwAAEg8AABMPAAAUDwAAFQ8AABgPAAAaDwAAIA8AACoPAAA0DwAANQ8AADYPAAA3DwAAOA8AADkPAAA6DwAAOw8AADwPAAA9DwAAPg8AAEAPAABxDwAAfw8AAIAPAACFDwAAhg8AAIgPAACNDwAAmA8AAJkPAAC9DwAAvg8AAMAPAADGDwAAxw8AANAPAADSDwAA0w8AANQPAADZDwAA2w8AAAAQAAArEAAALRAAADEQAAAyEAAAOBAAADkQAAA7EAAAPRAAAD8QAABAEAAAShAAAEwQAABQEAAAVhAAAFgQAABaEAAAXhAAAGEQAABiEAAAZRAAAGcQAABuEAAAcRAAAHUQAACCEAAAgxAAAIQQAACFEAAAhxAAAI0QAACOEAAAjxAAAJAQAACaEAAAnRAAAJ4QAACgEAAAABEAAGARAACoEQAAABIAAF0TAABgEwAAYRMAAGITAAAAFAAAARQAAIAWAACBFgAAmxYAAJwWAACdFgAA6xYAAO4WAAASFwAAFhcAADIXAAA1FwAANxcAAFIXAABUFwAAchcAAHQXAACAFwAAtBcAALYXAAC3FwAAvhcAAMYXAADHFwAAyRcAANQXAADWFwAA1xcAANgXAADZFwAA2hcAANsXAADcFwAA3RcAAN4XAADgFwAA6hcAAAIYAAAEGAAABhgAAAcYAAAIGAAAChgAAAsYAAAOGAAADxgAABAYAAAaGAAAhRgAAIcYAACpGAAAqhgAACAZAAAjGQAAJxkAACkZAAAsGQAAMBkAADIZAAAzGQAAORkAADwZAABEGQAARhkAAFAZAABuGQAAcBkAAHUZAACAGQAArBkAALAZAADKGQAA0BkAANsZAADeGQAA4BkAABcaAAAZGgAAGxoAABwaAAAgGgAAVRoAAFYaAABXGgAAWBoAAF8aAABgGgAAYRoAAGIaAABjGgAAZRoAAG0aAABzGgAAfRoAAH8aAACAGgAAihoAAJAaAACaGgAAoBoAAK4aAACwGgAAzxoAAAAbAAAEGwAABRsAADQbAAA+GwAAQhsAAEQbAABFGwAATRsAAE4bAABQGwAAWhsAAFwbAABdGwAAYRsAAGsbAAB0GwAAfRsAAIAbAACCGwAAgxsAAKEbAACiGwAAphsAAKgbAACuGwAAsBsAALobAADAGwAA5hsAAOcbAADoGwAA6hsAAO0bAADuGwAA7xsAAPIbAAD0GwAAJBwAACwcAAA0HAAANhwAADgcAAA7HAAAQBwAAEocAABQHAAAWhwAAH4cAACAHAAA0BwAANMcAADUHAAA4RwAAOIcAADpHAAA7RwAAO4cAAD0HAAA9RwAAPccAAD4HAAA+hwAAMAdAADNHQAAzh0AAPwdAAD9HQAAAB4AAP0fAAD+HwAAACAAAAcgAAAIIAAACyAAAAwgAAANIAAADiAAABAgAAARIAAAEiAAABQgAAAVIAAAGCAAABkgAAAaIAAAGyAAAB0gAAAeIAAAHyAAACAgAAAkIAAAJyAAACggAAAqIAAALyAAADAgAAA4IAAAOSAAADogAAA7IAAAPCAAAD0gAAA+IAAARCAAAEUgAABGIAAARyAAAEkgAABKIAAAViAAAFcgAABYIAAAXCAAAF0gAABgIAAAYSAAAGYgAABwIAAAfSAAAH4gAAB/IAAAjSAAAI4gAACPIAAAoCAAAKcgAACoIAAAqSAAAKogAAC2IAAAtyAAALsgAAC8IAAAviAAAL8gAADAIAAAwSAAANAgAADxIAAAAyEAAAQhAAAJIQAACiEAABYhAAAXIQAAIiEAACMhAAA5IQAAOiEAAJQhAACaIQAAqSEAAKshAAASIgAAFCIAAO8iAADwIgAACCMAAAkjAAAKIwAACyMAAAwjAAAaIwAAHCMAACgjAAApIwAAKiMAACsjAACIIwAAiSMAAM8jAADQIwAA6SMAAO0jAADwIwAA8SMAAPMjAAD0IwAA+CMAAPsjAADCJAAAwyQAAKolAACsJQAAtiUAALclAADAJQAAwSUAAPslAAD9JQAA/yUAAAAmAAAEJgAABiYAAAcmAAATJgAAFCYAABYmAAAYJgAAGSYAABomAAAdJgAAHiYAACAmAAAwJgAAOCYAADkmAAA8JgAASCYAAFQmAABoJgAAaSYAAH8mAACAJgAAhiYAAIomAACQJgAAkyYAAJQmAAChJgAAoiYAAKomAACsJgAAvSYAAL8mAADEJgAAxiYAAMkmAADNJgAAziYAAM8mAADSJgAA0yYAANQmAADVJgAA2CYAANomAADcJgAA3SYAAN8mAADiJgAA6iYAAOsmAADxJgAA8iYAAPQmAAD1JgAA9iYAAPcmAAD5JgAA+iYAAPsmAAD9JgAA/iYAAAUnAAAGJwAACCcAAAonAAAMJwAADicAABMnAAAUJwAAFScAABYnAAAXJwAAHScAAB4nAAAhJwAAIicAACgnAAApJwAAMycAADUnAABEJwAARScAAEcnAABIJwAATCcAAE0nAABOJwAATycAAFMnAABWJwAAVycAAFgnAABbJwAAYScAAGInAABjJwAAZCcAAGUnAABoJwAAaScAAGonAABrJwAAbCcAAG0nAABuJwAAbycAAHAnAABxJwAAcicAAHMnAAB0JwAAdScAAHYnAACVJwAAmCcAAKEnAACiJwAAsCcAALEnAAC/JwAAwCcAAMUnAADGJwAAxycAAOYnAADnJwAA6CcAAOknAADqJwAA6ycAAOwnAADtJwAA7icAAO8nAADwJwAANCkAADYpAACDKQAAhCkAAIUpAACGKQAAhykAAIgpAACJKQAAiikAAIspAACMKQAAjSkAAI4pAACPKQAAkCkAAJEpAACSKQAAkykAAJQpAACVKQAAlikAAJcpAACYKQAAmSkAANgpAADZKQAA2ikAANspAADcKQAA/CkAAP0pAAD+KQAABSsAAAgrAAAbKwAAHSsAAFArAABRKwAAVSsAAFYrAADvLAAA8iwAAPksAAD6LAAA/SwAAP4sAAD/LAAAAC0AAHAtAABxLQAAfy0AAIAtAADgLQAAAC4AAAIuAAADLgAABC4AAAUuAAAGLgAACS4AAAouAAALLgAADC4AAA0uAAAOLgAAFi4AABcuAAAYLgAAGS4AABouAAAcLgAAHS4AAB4uAAAgLgAAIS4AACIuAAAjLgAAJC4AACUuAAAmLgAAJy4AACguAAApLgAAKi4AAC4uAAAvLgAAMC4AADIuAAAzLgAANS4AADouAAA8LgAAPy4AAEAuAABCLgAAQy4AAEsuAABMLgAATS4AAE4uAABQLgAAUy4AAFUuAABWLgAAVy4AAFguAABZLgAAWi4AAFsuAABcLgAAXS4AAF4uAACALgAAmi4AAJsuAAD0LgAAAC8AANYvAADwLwAAADAAAAEwAAADMAAABTAAAAYwAAAIMAAACTAAAAowAAALMAAADDAAAA0wAAAOMAAADzAAABAwAAARMAAAEjAAABQwAAAVMAAAFjAAABcwAAAYMAAAGTAAABowAAAbMAAAHDAAAB0wAAAeMAAAIDAAACowAAAwMAAAMTAAADUwAAA2MAAAOzAAAD0wAAA+MAAAPzAAAEAwAABBMAAAQjAAAEMwAABEMAAARTAAAEYwAABHMAAASDAAAEkwAABKMAAAYzAAAGQwAACDMAAAhDAAAIUwAACGMAAAhzAAAIgwAACOMAAAjzAAAJUwAACXMAAAmTAAAJswAACfMAAAoDAAAKIwAACjMAAApDAAAKUwAACmMAAApzAAAKgwAACpMAAAqjAAAMMwAADEMAAA4zAAAOQwAADlMAAA5jAAAOcwAADoMAAA7jAAAO8wAAD1MAAA9zAAAPswAAD/MAAAADEAAAUxAAAwMQAAMTEAAI8xAACQMQAA5jEAAO8xAADwMQAAADIAAB8yAAAgMgAASDIAAFAyAACXMgAAmDIAAJkyAACaMgAAwE0AAABOAAAVoAAAFqAAAI2kAACQpAAAx6QAAP6kAAAApQAADaYAAA6mAAAPpgAAEKYAACCmAAAqpgAAb6YAAHOmAAB0pgAAfqYAAJ6mAACgpgAA8KYAAPKmAADzpgAA+KYAAAKoAAADqAAABqgAAAeoAAALqAAADKgAACOoAAAlqAAAJ6gAACioAAAsqAAALagAADioAAA5qAAAdKgAAHaoAAB4qAAAgKgAAIKoAAC0qAAAxKgAAMaoAADOqAAA0KgAANqoAADgqAAA8qgAAPyoAAD9qAAA/6gAAACpAAAKqQAAJqkAAC6pAAAwqQAAR6kAAFKpAABTqQAAVKkAAGCpAAB9qQAAgKkAAIOpAACEqQAAs6kAALSpAAC2qQAAuqkAALypAAC+qQAAwKkAAMGpAADHqQAAyqkAAM6pAADPqQAA0KkAANqpAADeqQAA4KkAAOWpAADmqQAA8KkAAPqpAAD/qQAAAKoAACmqAAAvqgAAMaoAADOqAAA1qgAAN6oAAECqAABDqgAARKoAAEyqAABNqgAATqoAAFCqAABaqgAAXKoAAF2qAABgqgAAe6oAAHyqAAB9qgAAfqoAALCqAACxqgAAsqoAALWqAAC3qgAAuaoAAL6qAADAqgAAwaoAAMKqAADDqgAA26oAAOCqAADrqgAA7KoAAO6qAADwqgAA8qoAAPWqAAD2qgAA96oAAOOrAADlqwAA5qsAAOirAADpqwAA66sAAOyrAADtqwAA7qsAAPCrAAD6qwAAAKwAAKTXAACw1wAAx9cAAMvXAAD81wAAAPkAAAD7AAAd+wAAHvsAAB/7AAAp+wAAKvsAADf7AAA4+wAAPfsAAD77AAA/+wAAQPsAAEL7AABD+wAARfsAAEb7AABQ+wAAPv0AAD/9AABA/QAA/P0AAP39AAAA/gAAEP4AABP+AAAV/gAAF/4AABj+AAAZ/gAAGv4AACD+AAAh/gAAIv4AACP+AAAk/gAAJf4AACb+AAAo/gAAKf4AACr+AAAr/gAALP4AAC3+AAAv/gAAMP4AADX+AAA2/gAAN/4AADj+AAA5/gAAOv4AADv+AAA8/gAAPf4AAD7+AAA//gAAQP4AAEH+AABC/gAAQ/4AAET+AABF/gAAR/4AAEj+AABJ/gAAUP4AAFH+AABS/gAAU/4AAFT+AABW/gAAWP4AAFn+AABa/gAAW/4AAFz+AABd/gAAXv4AAF/+AABn/gAAaP4AAGn+AABq/gAAa/4AAGz+AAD//gAAAP8AAAH/AAAC/wAABP8AAAX/AAAG/wAACP8AAAn/AAAK/wAADP8AAA3/AAAO/wAAD/8AABr/AAAc/wAAH/8AACD/AAA7/wAAPP8AAD3/AAA+/wAAW/8AAFz/AABd/wAAXv8AAF//AABg/wAAYv8AAGP/AABl/wAAZv8AAGf/AABx/wAAnv8AAKD/AAC//wAAwv8AAMj/AADK/wAA0P8AANL/AADY/wAA2v8AAN3/AADg/wAA4f8AAOL/AADl/wAA5/8AAOj/AADv/wAA8P8AAPn/AAD8/wAA/f8AAAABAQADAQEA/QEBAP4BAQDgAgEA4QIBAHYDAQB7AwEAnwMBAKADAQDQAwEA0QMBAKAEAQCqBAEAVwgBAFgIAQAfCQEAIAkBAAEKAQAECgEABQoBAAcKAQAMCgEAEAoBADgKAQA7CgEAPwoBAEAKAQBQCgEAWAoBAOUKAQDnCgEA8AoBAPYKAQD3CgEAOQsBAEALAQAkDQEAKA0BADANAQA6DQEAQA0BAEoNAQBpDQEAbg0BAG8NAQCrDgEArQ4BAK4OAQD8DgEAAA8BAEYPAQBRDwEAgg8BAIYPAQAAEAEAARABAAIQAQADEAEABRABADgQAQBGEAEARxABAEkQAQBOEAEAUhABAGYQAQBwEAEAcRABAHMQAQB1EAEAdhABAH8QAQCAEAEAghABAIMQAQCwEAEAsxABALcQAQC5EAEAuxABAL0QAQC+EAEAwhABAMMQAQDNEAEAzhABAPAQAQD6EAEAABEBAAMRAQAnEQEALBEBAC0RAQA1EQEANhEBAEARAQBEEQEARREBAEcRAQBzEQEAdBEBAHURAQB2EQEAgBEBAIIRAQCDEQEAsxEBALYRAQC/EQEAwBEBAMERAQDCEQEAxBEBAMURAQDHEQEAyBEBAMkRAQDNEQEAzhEBAM8RAQDQEQEA2hEBANsRAQDcEQEA3REBAOARAQAsEgEALxIBADISAQA0EgEAOBIBADoSAQA7EgEAPRIBAD4SAQA/EgEAQRIBAEISAQCpEgEAqhIBAN8SAQDgEgEA4xIBAOsSAQDwEgEA+hIBAAATAQACEwEABBMBAAUTAQANEwEADxMBABETAQATEwEAKRMBACoTAQAxEwEAMhMBADQTAQA1EwEAOhMBADsTAQA9EwEAPhMBAD8TAQBAEwEAQRMBAEUTAQBHEwEASRMBAEsTAQBNEwEAThMBAFATAQBREwEAVxMBAFgTAQBdEwEAXhMBAGATAQBiEwEAZBMBAGYTAQBtEwEAcBMBAHUTAQCAEwEAihMBAIsTAQCMEwEAjhMBAI8TAQCQEwEAkhMBALYTAQC3EwEAuBMBALkTAQC7EwEAwRMBAMITAQDDEwEAxRMBAMYTAQDHEwEAyhMBAMsTAQDMEwEAzhMBANATAQDREwEA0hMBANMTAQDWEwEA1xMBANkTAQDhEwEA4xMBADUUAQA4FAEAQBQBAEIUAQBFFAEARhQBAEcUAQBLFAEATxQBAFAUAQBaFAEAXBQBAF4UAQBfFAEAsBQBALEUAQCzFAEAuRQBALoUAQC7FAEAvRQBAL4UAQC/FAEAwRQBAMIUAQDEFAEA0BQBANoUAQCvFQEAsBUBALIVAQC2FQEAuBUBALwVAQC+FQEAvxUBAMEVAQDCFQEAxBUBAMYVAQDJFQEA2BUBANwVAQDeFQEAMBYBADMWAQA7FgEAPRYBAD4WAQA/FgEAQRYBAEMWAQBQFgEAWhYBAGAWAQBtFgEAqxYBAKwWAQCtFgEArhYBALAWAQC4FgEAwBYBAMoWAQDQFgEA5BYBAAAXAQAbFwEAHRcBAB4XAQAfFwEAIBcBACIXAQAmFwEAJxcBACwXAQAwFwEAOhcBADwXAQA/FwEARxcBACwYAQAvGAEAOBgBADkYAQA7GAEA4BgBAOoYAQAAGQEABxkBAAkZAQAKGQEADBkBABQZAQAVGQEAFxkBABgZAQAwGQEAMRkBADYZAQA3GQEAORkBADsZAQA+GQEAPxkBAEAZAQBBGQEAQhkBAEMZAQBEGQEARxkBAFAZAQBaGQEA0RkBANQZAQDYGQEA2hkBANwZAQDgGQEA4RkBAOIZAQDjGQEA5BkBAOUZAQABGgEACxoBADMaAQA5GgEAOhoBADsaAQA/GgEAQBoBAEEaAQBFGgEARhoBAEcaAQBIGgEAURoBAFcaAQBZGgEAXBoBAIQaAQCKGgEAlxoBAJgaAQCaGgEAnRoBAJ4aAQChGgEAoxoBAAAbAQAKGwEA8BsBAPobAQAvHAEAMBwBADccAQA4HAEAPhwBAD8cAQBAHAEAQRwBAEYcAQBQHAEAWhwBAHAcAQBxHAEAchwBAJIcAQCoHAEAqRwBAKocAQCxHAEAshwBALQcAQC1HAEAtxwBADEdAQA3HQEAOh0BADsdAQA8HQEAPh0BAD8dAQBGHQEARx0BAEgdAQBQHQEAWh0BAIodAQCPHQEAkB0BAJIdAQCTHQEAlR0BAJYdAQCXHQEAmB0BAKAdAQCqHQEA4B4BAPIeAQDzHgEA9R4BAPceAQD5HgEAAB8BAAIfAQADHwEABB8BABEfAQASHwEANB8BADYfAQA7HwEAPh8BAEAfAQBCHwEAQx8BAEUfAQBQHwEAWh8BAFsfAQDdHwEA4R8BAP8fAQAAIAEAcCQBAHUkAQBYMgEAWzIBAF4yAQCCMgEAgzIBAIYyAQCHMgEAiDIBAIkyAQCKMgEAeTMBAHozAQB8MwEALzQBADA0AQA3NAEAODQBADk0AQA8NAEAPTQBAD40AQA/NAEAQDQBAEE0AQBHNAEAVjQBAM5FAQDPRQEA0EUBAABhAQAeYQEAKmEBAC1hAQAwYQEAOmEBAGBqAQBqagEAbmoBAHBqAQDAagEAymoBAPBqAQD1agEA9moBADBrAQA3awEAOmsBAERrAQBFawEAUGsBAFprAQBjbQEAZG0BAGdtAQBrbQEAbm0BAHBtAQB6bQEAl24BAJluAQBPbwEAUG8BAFFvAQCIbwEAj28BAJNvAQDgbwEA5G8BAOVvAQDwbwEA8m8BAABwAQD4hwEAAIgBAACLAQDWjAEA/4wBAACNAQAJjQEA8K8BAPSvAQD1rwEA/K8BAP2vAQD/rwEAALABACOxAQAysQEAM7EBAFCxAQBTsQEAVbEBAFaxAQBksQEAaLEBAHCxAQD8sgEAnbwBAJ+8AQCgvAEApLwBAPDMAQD6zAEAAM8BAC7PAQAwzwEAR88BAGXRAQBq0QEAbdEBAHPRAQB70QEAg9EBAIXRAQCM0QEAqtEBAK7RAQBC0gEARdIBAADTAQBX0wEAYNMBAHfTAQDO1wEAANgBAADaAQA32gEAO9oBAG3aAQB12gEAdtoBAITaAQCF2gEAh9oBAIvaAQCb2gEAoNoBAKHaAQCw2gEAAOABAAfgAQAI4AEAGeABABvgAQAi4AEAI+ABACXgAQAm4AEAK+ABAI/gAQCQ4AEAMOEBADfhAQBA4QEASuEBAK7iAQCv4gEA7OIBAPDiAQD64gEA/+IBAADjAQDs5AEA8OQBAPrkAQDu5QEA8OUBAPHlAQD75QEA0OgBANfoAQBE6QEAS+kBAFDpAQBa6QEAXukBAGDpAQCs7AEArewBALDsAQCx7AEAAPABAATwAQAF8AEALPABADDwAQCU8AEAoPABAK/wAQCx8AEAwPABAMHwAQDP8AEA0PABANHwAQD28AEAAPEBAA3xAQAQ8QEAL/EBADDxAQBs8QEAcvEBAH7xAQCA8QEAjvEBAI/xAQCR8QEAm/EBAK3xAQCu8QEA5vEBAADyAQAB8gEAA/IBABDyAQAa8gEAG/IBAC/yAQAw8gEAMvIBADvyAQA88gEAQPIBAEnyAQBQ8gEAUvIBAGDyAQBm8gEAAPMBACHzAQAt8wEANvMBADfzAQB98wEAfvMBAIXzAQCG8wEAlPMBAJzzAQCe8wEAoPMBALXzAQC38wEAvPMBAL3zAQDC8wEAxfMBAMfzAQDI8wEAyvMBAMvzAQDN8wEAz/MBANTzAQDg8wEA8fMBAPTzAQD18wEA+PMBAPvzAQAA9AEAP/QBAED0AQBB9AEAQvQBAET0AQBG9AEAUfQBAGb0AQB59AEAfPQBAH30AQCB9AEAhPQBAIX0AQCI9AEAj/QBAJD0AQCR9AEAkvQBAKD0AQCh9AEAovQBAKP0AQCk9AEApfQBAKr0AQCr9AEAr/QBALD0AQCx9AEAs/QBAP30AQD/9AEAAPUBAAf1AQAX9QEAJfUBADL1AQA+9QEARvUBAEr1AQBL9QEAT/UBAFD1AQBo9QEAdPUBAHb1AQB69QEAe/UBAJD1AQCR9QEAlfUBAJf1AQCk9QEApfUBANT1AQDc9QEA9PUBAPr1AQD79QEARfYBAEj2AQBL9gEAUPYBAHb2AQB59gEAfPYBAID2AQCj9gEApPYBALT2AQC39gEAwPYBAMH2AQDG9gEAzPYBAM32AQDQ9gEA0/YBANX2AQDY9gEA3PYBAOD2AQDr9gEA7fYBAPD2AQD09gEA/fYBAAD3AQB09wEAd/cBAHv3AQCA9wEA1fcBANr3AQDg9wEA7PcBAPD3AQDx9wEAAPgBAAz4AQAQ+AEASPgBAFD4AQBa+AEAYPgBAIj4AQCQ+AEArvgBALD4AQC8+AEAwPgBAML4AQAA+QEADPkBAA35AQAP+QEAEPkBABj5AQAg+QEAJvkBACf5AQAw+QEAOvkBADv5AQA8+QEAP/kBAEb5AQBH+QEAd/kBAHj5AQC1+QEAt/kBALj5AQC6+QEAu/kBALz5AQDN+QEA0PkBANH5AQDe+QEAAPoBAFT6AQBg+gEAbvoBAHD6AQB9+gEAgPoBAIr6AQCP+gEAw/oBAMb6AQDH+gEAzvoBAN36AQDf+gEA6voBAPD6AQD5+gEAAPsBAPD7AQD6+wEAAPwBAP7/AQAAAAIA/v8CAAAAAwD+/wMAAAAOAAEADgACAA4AIAAOAIAADgAAAQ4A8AEOAAAQDgDIAMsAgwDBAEIAyAAFABEAFgAAABgAGQAAABYAFQAQAAAAGAATAAwAEwAXABoAEwAAABEAAAAVABgAEAAAABUACwAPAAAAyADEAMgACgAVABkAGAAAAAAEAAAWEAAAywAABAAAGQAYAAAADQAAABYgAAAVAAAADQAAAA0AAAANAAAACAEKAQgBCgEIAQAAEwAAAAgBAAATAAsAAAAYAAAACAELAAgBAAAIAQAACAERAAgBAAAbAAAAGwAAANoBAAAZABMAAAAIAREAyAARAAAACAEaABkAGgAAAAgBAAARAAAACAHaAQAACAEAAAgBAAAIAQAAGgAAAMABAAAIAQAACAEAAAgBAAAaAAAACAEAABMAEQAAAAgBGAAAAAgBAAAIAQAACAEAAAgBAAAIAQAA2gEAAAgBAAAIAdoBCAEIAgAACAEIAggBAAAIAggBCAIIAQgCAAAIAQAACAELABoAAAAIAQgCAAAIAQAACAEIAggBAAAIAgAACAIIAQAACAEAAAgBAAAaAAAAGQAAABkAAAAYAAAACAEAAAgBCAIAAAgBAAAIAggBAAAIAQAACAEAAAgBAAAaAAgBAAAIAQAACAEIAgAACAEAAAgCCAEAAAgBCAIAAAgCCAEAAAgBAAAaAAAAGAAAAAgBAAAIAQgCAAAIAQAACAEIAggBAAAIAgAACAIIAQAACAEAAAgBAAAaAAAACAEAAAgBCAIIAQgCAAAIAgAACAIIAQAACAEAABoAAAAYAAAACAEIAggBAAAIAQAACAEIAgAACAEAAAgBAAAIAQAACAEAABoAAAANAAAACAEIAg0AAAAIAQAACAIIAQgCCAEIAgAACAEAAAgBAAAIAQAACAEAABoAAAAIAgAACAEIAgAACAEAAAgBCAIIAQAACAIAAAgCCAHAAQAACAEAAAgBAAAaAAAAGQAAAAgBCAIAAAgBAAAIAQgCCAEAAAgBAAAIAggBAAAaAAAACAIAAACACIEAgACCCIEAABgAAIAIgQAAGgALAAAAAIAAAACAAAAAgAAAAIAAAACAAAAAgAiBAIAAggiBAIAAAACAAAAAgAAACIEAABoAAAAAgAAADQAAAA0ACgANAAsACgARAAoAAAARAAAACAEAABoAAAALAAgBAAAIAQAACAEVAA8AFQAPAAgCAAAIAQsCCAELAAgBAAAIAQAACAEAAAsAAAAIAQAADQALAA0AAAAKAAAAAIAIgAiBCIIIgQiACIEIggiBAIAaAAsAAAAAgAiCCIEAgAiBAIAIgACACIAAgAiBAIAIgQiACIIIgQiACIEAgAiAGgAIgAiBAIAAAGAKoQLiAgAACAEAAAsAAAALAAAACwAAABUADwAAAAsAAAAIAQAACAELAAAACAEAAAgBAAAAgAiBCIIIgQiCCIEIggiBCwAUAACACwAAAAsAGAAAgAiBAAAaAAAAEQALAA0AAAARAAAACAHKAAgBGgAAAAgBAAAIAQAACAEIAggBCAIAAAgCCAEIAggBAAARABoAAIAAAACAAAAAgAAAAIAAABoAAAAAgAAACAEIAggBAAAAgAiCCIEIggiBAAAIgQiACIEIgAiBCIIIgQAACAEaAAAAGgAAAACAAAAIAQAACAEIAiYACAEIAggBKAEmAAAACwAnAAsAHAALABwACAEcAAsACAEIAgAACAIIAQgCCAEAABoAAAAnAAgBCAIIAQgCCAEIAggBKQEAAAgCCAEIAggBAAALABoAAAAaAAAACwAAAAgBAAAIAQgCCAEAAAgBAAAIAQAACAIIAQAACAEKAQgBCgEIAQAADQAAAAsACgALAMYACAFHAcgACwAKAAsADgAAABYQFiAVABYQFiAVABYQAAASAAsAwQDIAAoAGQAAABYQFiAAABQEFAAAABMAFQAPABQAFAQAAAsAGQALAAAACwDJAMAAyAAAABUADwAAABUADwAAABgAGQAYABgIGAAZABgAGQAYABkAGAAZABgACAEAABkAAAAZAAAAGAAAAAAEAAAABAAAAAQAAAAEAAAYAAAAEgAAABUADwAVAA8AAAAcDAAAAAQVCA8IAAAABAAAAAQAAAAMAAQcDBwEHAwAAAAEAAAABAAAAAQAAAAEAAAABAAAAAQADAAAHAQABAAAAAQAABwMAAQcBAAEHAQjBBwEAAQADAAEHAQABAAMAAQcBAAEHAwABAAAAAgABAAMAAQADAAEAAwABBwMHAQcDBwEAAQcBAAMHAQABBwEHAwABBwEAAQcBAAEHAQABBwMAAQcBBwMHAQcDAAEHAQjBBwMAAQcDBwEAAwAABwEIwwjBAAEAAAABAAAAAQAAAAEAAAABAAAAAwAAAAEAAAABAAAAAQAAAAMAAAADAAAAAwAAAAMAAAWAAAAEQARBBwEAAQVAA8AFQAPABUADwAVAA8AFQAPABUADwAVAA8AAAAADAAAAAQAAAAMAAAADAAAFQAPAAAAFQAPABUADwAVAA8AFQAPABUADwAAAAAEAAAVAA8AFQAPABUADwAVAA8AFQAPABUADwAVAA8AFQAPABUADwAVAA8AFQAPAAAAFQAPABUADwAAABUADwAAAAAEAAAADAAAAAwAAAAMAAAIAQAAEQALAAAAEQALAAAACwAAAAgBAAAIARYAFhAWIBYQFiAWABYQFiAWABYQFiALAAAACwAVAAsAAAAWEBYgAAAWEBYgFQAPABUADwAVAA8AFQAPAAsAEQAAAAsAAAALAAAADgALAAAACwAVAAsAAAALAAAACwAAABEAFQAQABUAEAAVABAAFQAQAAsAAAAcCAAAHAgAABwIAAAcCAsIDwgcCBQIHAgVCA8IFQgPCBUIDwgVCA8IFQgPCBwIFQgPCBUIDwgVCA8IFQgPCBQIFQgPCBwICAkcDBwICAgcCBQIHAwcCBwAAAAUCBwIFAgcCBQIHAgUCBwIFAgcCBQIHAgUCBwIFAgcCBQIHAgUCBwIFAgAAAgJFAgcCBQIHAgUCBwIFAgcCBQIHAgUCBwIFAgcCBQIHAgUCBwIFAgcCBQIHAgUCBwIFAgcCAAAHAgAABwIAAAcCAAAHAgUCBwIAAAcCAAAHAgcDBwIHAwcCAAIHAgUCBwIAAAcCAAACwAAAAsAEQALAAAAGgAAAAgBAAAIAQAACAEAAAgBAAALAAAACAEAAAgBAAAIAQAACAIIAQgCAAAIAQAAGQAAAA0AEQAAAAgCAAAIAggBAAALABoAAAAIAQAADQAAAAgBGgAAAAgBCwAAAAgBCAIIAQAAYAoAAAgBCAImAAgBCAIIAQgCCAEIAigBHAALABwAAAALACcAAAAcAACACIEAgBoAAIAAACcACAEIAggBCAIIAQAACwAIAQsACAEIAgAAJwAAABwACwAAgAiACIEIgACACIEAgAiBAIAIgQCACIEAgAiBAIAAAACAAAAIAggBCAILAAAACAIIAQAACAIIAQgCCAEIAgsACAIIAQAAGgAAACQLAAChAgAA4gIAABwIAAAbAAgBGwAAABsAAAAbAAAAGwAAABsAAAAbAAAAGwAAAA8AFQAAABkAAAAIAQ8IFAgRCBUIDwgSCAAACgEIAQoBCAEKAQgBCgEIAQoBCAEKAQgBCgEIARwIFQgPCBUIDwgVCA8IFQgPCBUIDwgVCA8IFQgPCBUIDwgcCBUIDwgcCA8IHAgPCAAAFAgRCBwIFQgPCBUIDwgVCA8IHAgAABwIGAgZCBwIAADJAAAAEQgcCBgIGQgcCBUIDwgcCA8IHAgPCBwIFAgcCBEIHAgVCBwIDwgcCBUIHAgPCBwIFQgPCBUIDwgUCBwIFAgcCBQJHAgAABwIAAAcCAAAHAgAABwIAAAZCBgIHAgYCAAAAAgAAMAAyAAeAAAACwAAAAgBAAAIAQAACAEAAAsAAAALAAAAGgAAAAsAAAALAAAACAEAAAgBAAAIAQAACAEAAAgBAAALAAAACAEAAAsAEgAAAAsAAAAIAQAAGgAAABoAAAAIAQsAAAAIAQsAAAAIAQAACAEAAAgBAAAIAggBCAIqACYACAEoAQsAHAAAABwAJwAIASYACAEmAAAACgEIAQgCAAAIAggBCAIIAQAA2gELAAgBAADaAQAAGgAAAAgBAAAIAQgCCAEAABoACwAAAAgCAAAIAQAADQAAAAgBCAIAAAgCCAEIAggBAADAAQAACwAAAAsACAEAAAgCCAEaAAAADQAAAAsAAAAIAggBCAIIAQsAAAALAAAACAEAAAgBAAALAAAACAEIAggBAAAaAAAACAEIAgAAJgAAACYAAAAmAAAAJgAAACYAAAAmAAAACAELAAgBCAIIAQgCAAAIAgAACAIoAQAAJwAAAAgBAAALACcAJgAIAgAACAEAAAgBAAAnAAAAJwAAACcAAAAnACYAAAAcAAgBCAIIAQAACAEAAAgBAAAIAQgCAAAIAggBKAHqAQgBHAAAABwAAAAIAQAACAIIAQgCCAEIAggBAAALAAAAGgALAAAACAEAAAgBCAIIAQgCCAEIAggBCAIIAQgCCAEAABoAAAAIAQgCCAEAAAgCCAEIAggBDQALABEAAAALAAAACAEAAAgCCAEIAggBCAIIAQsAAAAaAAAADQAAAAgBCAIIAQgCCAEAABoAAAAaAAAAAIAAAAiBCIIIgQiACIEIggiBAAAaAACACwAAgAAACAIIAQgCCAEAABoAAAAmAAAAJgAAACYAAAAmAAAAJgAIAQgCAAAIAgAACAEoAeoBCALqAQgCCAELAAAAJwAAAAgCCAEAAAgBCAIIAQAADQAAAAgCAAAIAQAACAEIAsABCAENAAAACwANAAAACAEAAAgBCAIIAQAAwAEIAQgCCAELAAAADQALAAAADQAAABoAAAAIAggBAAAIAQgCCAEAAAsAAAAaAAAADQARAAAACAEAAAgCCAEIAggBCAIIAQAACAEAAAgBAAAIAQAACAHAAQgBAAAaAAAACAIAAAgBAAAIAggBCAIIAQAAGgAAACcACwAIAQgCCwAAAAgB6gEIAiYAAAAmAAgCCAEAAAgCCAEoAQsAHAAnAAgBAAAZAAAACwAAAAsAAAAVAA8AAAAPAAAAFQAPABUADwAAABUADwAAABUAygDVAM8AygDVAM8A1QDPAAgBAAAIAQAAFQAPAAAAJwAIAQgCCAEnAAAAGgAAAAsAAAAaAAAACAELAAAACAELAAAACwAAABoAAACAAgAAgAIAAAsAGgAAAAsAAAAIAQAACAIAAAgBAAAUCAoJAAAICQAAHAgAABwIAAgAAAAIHAgAAAAIAAAACAAAAAgAABwIAAAUCAAAFAgAABQIAAAUCAAAHAgAAAgBCwDIAAAAGgAAAAgBAAAIAQAACAEAAAgByAAIAQAACAEAAAgBAAAIAQAAAAgAAAAIAAAaAAAACAEAAAgBAAAIAQAACAEAAAsAAAAIAQAACAEAAAgBAAAIAQAACAEAAAgBAAAIAQAACAEAAAgBAAAaAAAACAEAAAgBGgAAABgAAAAIARoAAAAIAQAAGgAAAAgBAAAIAQAAGgAAABUAAAAZAAAAGQAAABwEHAwcBBxEHAQcRBwEHEQcBBxEHAQcDBxEHAQcRAAAAAQAAAAEAAAABAAAAAQAAAAMAAAADAAAAAQcRJ8BHAgcDBxEHAgcDBwIHAwcCBwMHAgcRBwIHEQcDBxEHAwcRBwMHAQcDBwEHAwcBBwMIwwcDBwEAAQcBBwMAAwcDAAMHAwjDBwMIwwcDCMMIwQcBBwMHAQcDBwEHAwcBBwMHQkcDBwEHAwcBCMMHAwjDBwMIwwcDCMMHAwjDBwMIwwcDCMMHAwjDBwMAAwcDAAMHAwADBwMIwwcDAAMHAwADBwMHAQcDAAMHAwADBwMAAwAAAAEHAQcDBwEHAwcBCMEHAQjDBwEIwQcBCMMHAQcDBwEAAQcBAAEHAQcDCMMHAwjDAAAFgAUAAAAHAwjDBwMIwwcDCMMHAwcBCMMHAQcDBwEHAwcRBwMHAQcDBxEHAQcDBxEAAAcBBxEHAQAABwEHEQcDBxEHAwcRAAAHEQAABxEAAAcRAAAHEQAABxEAAQcRAAEHEQAACMMHAwjDBwMIwwcDCMMHAwjDBwMHAAjDBwMHAAcDCMMHAwjDBwMIwwcDCMMHAwjDBwMIwwcDAAEHEQcBBxEHAwcRBwMHEQcDCMMHAwcRBwMHEQcDBxEIwwcRAAAGgAAABxEAAAcCAAAHAgAAMAAyADAAAgBwAAIAcAAAAA=";var up=0,Sy=1,PP=2,dp=3,Ty=4,rs=5,ia=6,hu=7,hp=8,pp=9,mp=10,ZS=11,fp=12,wle=13,FP=14,wy=15,_p=16,UP=17,Ile=18,pu=19,BP=20,Iy=21,oa=22,Oy=23,mu=24,fu=25,Ei=26,_u=27,GP=28,eT=29,tT=30,nT=31,rT=32,Cy=33,Ny=34,iT=35,cp=36,ky=37,VP=38,Ole=39,HP=40,WP=41,Cle=42;var oT=1,sT=2,KP=3,aT=4,Ly=5,My=6,Nle=7,kle=8,YP=9,lT=10,cT=11,Ry=12,uT=13,MP=63,JS=6,DP=15,j7e=1024,XP=2048,dT=4096,hT=8192,qP=16384,J7e=32768,Z7e=1229870403,Tle=8,LP=4,e9e=2,t9e=44032,n9e=28,zP=128;function r9e(){let i=tb(Sle),e=new DataView(i.buffer);if(e.getUint32(0,true)!==Z7e)throw new Error("unicode table is corrupt");let t=e.getUint32(LP,true),n=new Uint32Array(t),r=new Uint16Array(t);for(let o=0;o<t;o++)n[o]=e.getUint32(Tle+o*LP,true),r[o]=e.getUint16(Tle+t*LP+o*e9e,true);return {starts:n,props:r}}var Lle=r9e(),i9e=Lle.starts,o9e=Lle.props;function sa(i){return i&MP}function pT(i){return i>>>JS&DP}function yp(i){return (i&j7e)!==0}function QP(i){return (i&J7e)!==0}function Mle(i){let e=i9e,t=0,n=e.length;for(;n-t>1;){let o=t+n>>>1;e[o]<=i?t=o:n=o;}let r=o9e[t];if((r&MP)===cp&&(r>>>JS&DP)===Ry){let o=(i-t9e)%n9e===0;return r&-1024|(o?cp:ky)|(o?Ry:uT)<<JS}return r}var Dle=new Uint16Array(zP);for(let i=0;i<zP;i++)Dle[i]=Mle(i);function Ple(i){return i<zP?Dle[i]:Mle(i)}var ao=1,Fle=2,is=4,s9e=XP|dT|hT|qP,xi=-1,a9e=8208,Ule=9676;function Dy(i){return i===Sy||i===PP||i===dp||i===Ty}function yu(i){return i===up||i===_u}function Ble(i){return i===rT||i===Cy||i===Ny||i===cp||i===ky}var aa=class{constructor(){this.cls=xi;this.flags=0;this.cp=0;}set(e,t,n){this.cls=e,this.flags=t,this.cp=n;}copy(e){this.cls=e.cls,this.flags=e.flags,this.cp=e.cp;}ea(){return (this.flags&XP)!==0}aksara(){return this.cls===VP||this.cp===Ule}syllable(){return this.cls===VP||this.cls===Ole||this.cp===Ule}},$P=class{constructor(){this.cur=new aa;this.a=new aa;this.a1=new aa;this.b=new aa;this.b1=new aa;this.next=new aa;this.next2=new aa;this.regional=0;this.numeric=false;this.closed=false;this.props=new Uint16Array(0);this.codepoints=new Uint32Array(0);this.n=0;}unitAt(e,t){let n=this.props[e],r=sa(n);r===hp||r===hu?t.set(up,0,this.codepoints[e]):t.set(r,n&s9e,this.codepoints[e]);}after(e,t){let n=e+1;for(;n<this.n;){let r=sa(this.props[n]);if(r!==hp&&r!==hu)break;n++;}return n>=this.n?(t.set(xi,0,0),this.n):(this.unitAt(n,t),n)}reset(){this.a.set(xi,0,0),this.a1.set(xi,0,0),this.b.set(xi,0,0),this.b1.set(xi,0,0),this.regional=0,this.numeric=false,this.closed=false;}push(){let e=this.cur.cls,t=this.numeric;this.numeric=e===Ei||t&&(e===Oy||e===pu),this.closed=t&&(e===wy||e===_p),this.regional=e===nT?this.regional+1:0,this.a1.copy(this.a),this.a.copy(this.cur),e!==rs&&(this.b1.copy(this.a1),this.b.copy(this.cur));}decide(e,t){let n=sa(this.props[e]);return t===Sy||t===dp||t===Ty?Fle:t===PP?n===dp?0:Fle:Dy(n)||n===rs||n===ia?0:this.b.cls===ia?ao:t===hu?0:this.pair(e)}pair(e){let t=this.cur,n=this.a,r=t.cls,o=n.cls;if(r===pp||o===pp||o===mp||r===mp&&o!==rs&&o!==ZS&&o!==fp||r===wy||r===_p||r===UP||r===Oy||this.b.cls===Iy)return 0;if(this.b.cls===oa&&(this.b.flags&dT)!==0){let s=this.b1.cls;if(s===xi||Dy(s)||s===Iy||s===oa||s===mp||s===rs||s===ia)return 0}if(r===oa&&(t.flags&hT)!==0){this.after(e,this.next);let s=this.next.cls;if(s===xi||s===rs||s===mp||s===pp||s===wy||s===oa||s===_p||s===UP||s===pu||s===Oy||Dy(s)||s===ia)return 0}if(r===pu)return o===rs&&(this.after(e,this.next),this.next.cls===Ei)?ao:0;if(r===BP&&(this.b.cls===wy||this.b.cls===_p)||r===FP&&this.b.cls===FP)return 0;if(o===rs)return ao;if(r===oa&&(t.flags&dT)===0||o===oa&&(n.flags&hT)===0||r===oa&&(!n.ea()||(this.after(e,this.next),this.next.cls===xi||!this.next.ea()))||o===oa&&(!t.ea()||this.a1.cls===xi||!this.a1.ea()))return 0;if(r===tT||o===tT)return ao;if((o===fp||n.cp===a9e)&&r===up){let s=this.a1.cls;if(s===xi||Dy(s)||s===rs||s===ia||s===tT||s===mp)return 0}if(r===ZS||r===fp||r===BP||o===wle||(o===fp||o===ZS&&!n.ea())&&this.a1.cls===_u&&r!==_u||o===Oy&&r===_u||r===Ile||yu(o)&&r===Ei||o===Ei&&yu(r)||o===mu&&(r===GP||r===iT||r===eT)||(o===GP||o===iT||o===eT)&&r===fu||(o===mu||o===fu)&&yu(r)||yu(o)&&(r===mu||r===fu)||(this.numeric||this.closed)&&(r===fu||r===mu))return 0;if(o===mu||o===fu){if(r===Ei)return 0;if(r===Iy){let s=this.after(e,this.next);if(this.next.cls===Ei||this.next.cls===pu&&(this.after(s,this.next2),this.next2.cls===Ei))return 0}}if((o===fp||o===pu)&&r===Ei||this.numeric&&r===Ei||o===rT&&(r===rT||r===Cy||r===cp||r===ky)||(o===Cy||o===cp)&&(r===Cy||r===Ny)||(o===Ny||o===ky)&&r===Ny||Ble(o)&&r===fu||o===mu&&Ble(r)||yu(o)&&yu(r)||o===Cle&&t.syllable()||n.syllable()&&(r===WP||r===HP))return 0;if(o===HP&&t.aksara()){let s=this.a1;if(s.cls!==xi&&s.syllable())return 0}return n.syllable()&&t.syllable()&&(this.after(e,this.next),this.next.cls===WP)||o===pu&&yu(r)||(o===up||o===_u||o===Ei)&&r===Iy&&!t.ea()||o===_p&&!n.ea()&&(r===up||r===_u||r===Ei)||o===nT&&r===nT&&this.regional%2===1||r===eT&&(o===iT||(n.flags&qP)!==0)?0:ao}},l9e=new $P;function Gle(i,e,t,n){if(t===0)return;let r=l9e;r.props=i,r.codepoints=e,r.n=t,r.reset(),r.unitAt(0,r.cur),r.push(),n[0]=0;for(let o=1;o<t;o++){let s=sa(i[o]),a=sa(i[o-1]);if((s===hp||s===hu)&&!(Dy(r.a.cls)||r.a.cls===rs||r.a.cls===ia)){n[o]=0;continue}r.unitAt(o,r.cur),n[o]=r.decide(o,a),r.push();}}var c9e=[2381,2509,2765,2893,3149,3405],u9e=[[2325,2361],[2392,2399],[2424,2431],[2453,2472],[2474,2480],[2482,2482],[2486,2489],[2524,2525],[2527,2527],[2544,2545],[2709,2728],[2730,2736],[2738,2739],[2741,2745],[2809,2809],[2837,2856],[2858,2864],[2866,2867],[2869,2873],[2908,2909],[2911,2911],[2929,2929],[3093,3112],[3114,3129],[3160,3162],[3349,3386]],Ap=0,jP=1,mT=2,d9e=3;function h9e(i,e){if(c9e.includes(i))return mT;if(u9e.some(([n,r])=>i>=n&&i<=r))return jP;let t=pT(e);return t===aT||t===Ly?d9e:Ap}function Vle(i,e,t,n){let r=Ap;for(let o=0;o<t;o++){let s=h9e(e[o],i[o]);s===jP?(r===mT&&(n[o]|=is),r=jP):s===mT?r=r===Ap?Ap:mT:s===Ap&&(r=Ap);}}function Hle(i,e,t){if(e===0)return;let n=pT(i[0]),r=n===My?1:0,o=yp(i[0])?1:0;for(let s=1;s<e;s++){let a=pT(i[s]),l;n===oT&&a===sT?l=true:n===KP||n===oT||n===sT||a===KP||a===oT||a===sT?l=false:n===YP&&(a===YP||a===lT||a===Ry||a===uT)||(n===Ry||n===lT)&&(a===lT||a===cT)||(n===uT||n===cT)&&a===cT||a===aT||a===Ly||a===kle||n===Nle||n===Ly&&o===2&&yp(i[s])?l=true:n===My&&a===My?l=r%2===1:l=false,l?t[s]|=is:t[s]&=~is,r=a===My?r+1:0,o=yp(i[s])||o===1&&a===aT?1:o===1&&a===Ly?2:0,n=a;}}var p9e=1128875075,m9e=1,os=4,JP=12,Wle=5,bp=8,f9e=255,_9e=256,Yle=512,Xle=10,qle=(1<<22)-1,y9e=1,A9e=100,Kle=4294967295,ss=-1,ZP=class{constructor(e){this.first=new Uint32Array(bp);this.last=new Uint32Array(bp);this.offset=new Uint32Array(bp);this.count=new Uint32Array(bp);this.root=new Uint32Array(bp);let t=new DataView(e);if(e.byteLength<JP||t.getUint32(0,true)!==p9e||t.getUint32(os,true)!==m9e)throw new Error("break dictionaries are not a Cimplify dictionary file");let n=t.getUint32(2*os,true),r=JP+n*Wle*os;if(n>bp||e.byteLength<r)throw new Error("break dictionaries are truncated");let o=(e.byteLength-r)/os;this.languages=n;for(let s=0;s<n;s++){let a=JP+s*Wle*os;if(this.first[s]=t.getUint32(a,true),this.last[s]=t.getUint32(a+os,true),this.offset[s]=t.getUint32(a+2*os,true),this.count[s]=t.getUint32(a+3*os,true),this.root[s]=t.getUint32(a+4*os,true),this.offset[s]+this.count[s]>o||this.root[s]>=this.count[s])throw new Error("break dictionaries are corrupt")}this.edges=new Uint32Array(e.slice(r,r+o*os));}language(e){for(let t=0;t<this.languages;t++)if(this.first[t]<=e&&e<=this.last[t])return t;return ss}child(e,t,n){let r=this.offset[e],o=this.count[e];for(let s=t;s<o;s++){let a=this.edges[r+s],l=a&f9e;if(l===n)return a;if(l>n||(a&_9e)!==0)return ss}return ss}contains(e){let t=ss,n=0,r=false;for(let o of e){let s=o.codePointAt(0)??0;if(t===ss){if(t=this.language(s),t===ss)return false;n=this.root[t];}if(n===qle||s<this.first[t]||s>this.last[t])return false;let a=this.child(t,n,s-this.first[t]);if(a===ss)return false;r=(a&Yle)!==0,n=a>>>Xle;}return r}rootOf(e){return this.root[e]}firstOf(e){return this.first[e]}lastOf(e){return this.last[e]}},fT=class{constructor(e){this.cost=new Uint32Array(e+1),this.back=new Uint32Array(e+1),this.unknown=new Uint8Array(e+1);}relax(e,t,n,r){t<this.cost[e]&&(this.cost[e]=t,this.back[e]=n,this.unknown[e]=r?1:0);}segment(e,t,n,r,o){let s=0;for(;s<r;){let a=QP(n[s])?e.language(t[s]):ss;if(a===ss){s++;continue}let l=s+1;for(;l<r&&QP(n[l])&&e.language(t[l])===a;)l++;this.run(e,a,t,o,s,l),s=l;}}run(e,t,n,r,o,s){let a=s-o,l=e.firstOf(t),c=e.lastOf(t);this.cost[0]=0,this.cost.fill(Kle,1,a+1);let u=h=>h===a||(r[o+h]&is)===0;for(let h=0;h<a;h++){let p=this.cost[h];if(p===Kle||!u(h))continue;let m=e.rootOf(t);for(let y=h;y<a&&m!==qle;y++){let b=n[o+y];if(b<l||b>c)break;let A=e.child(t,m,b-l);if(A===ss)break;(A&Yle)!==0&&u(y+1)&&this.relax(y+1,p+y9e,h,false),m=A>>>Xle;}let f=h+1;for(;f<a&&(r[o+f]&is)!==0;)f++;this.relax(f,p+A9e,h,true);}let d=a;for(;d>0;){let h=this.back[d];h>0&&!(this.unknown[d]===1&&this.unknown[h]===1)&&(r[o+h]|=ao),d=h;}}},eF=null,Py=null,tF=new Set;function zle(i){if(eF=i===null?null:new ZP(i),Py=i===null?null:new Uint8Array(i),Py!==null)for(let e of tF)e(Py);return eF}function Qle(i){return tF.add(i),Py!==null&&i(Py),()=>{tF.delete(i);}}function gp(){return eF}var b9e=[[1424,2303],[64285,65023],[65136,65279],[67584,69631],[124928,126975],[8207,8207]],$le=[[48,57],[1632,1641],[1776,1785]],jle=[[0,47],[58,64],[91,96],[123,191],[215,215],[247,247],[8192,8206],[8208,8303],[12288,12351]],g9e=[[1570,1573],[1575,1575],[1577,1577],[1583,1586],[1608,1608],[1649,1651],[1653,1655],[1672,1689],[1728,1728],[1731,1739],[1741,1741],[1743,1743],[1746,1747],[1749,1749],[1774,1775],[1881,1883],[1899,1900]],E9e=[[1574,1574],[1576,1576],[1578,1582],[1587,1599],[1600,1600],[1601,1607],[1609,1610],[1646,1647],[1656,1671],[1690,1727],[1729,1730],[1740,1740],[1742,1742],[1744,1745],[1786,1788],[1791,1791],[1872,1880],[1884,1898],[8205,8205]],x9e=[[1552,1562],[1611,1631],[1648,1648],[1750,1756],[1759,1764],[1767,1768],[1770,1773],[8203,8204]],v9e=new Map([[40,41],[41,40],[60,62],[62,60],[91,93],[93,91],[123,125],[125,123],[171,187],[187,171],[8249,8250],[8250,8249],[8804,8805],[8805,8804],[12296,12297],[12297,12296],[64830,64831],[64831,64830]]),_T=128,nF=127,R9e=127,S9e=8204;function kl(i,e,t=i.length){for(let n=0;n<t;n++)if(e>=i[n][0]&&e<=i[n][1])return true;return false}function Jle(i){return i<128?kl($le,i,1)?2:kl(jle,i,4)?3:0:kl($le,i)?2:kl(b9e,i)?1:kl(jle,i)?3:0}function Zle(i,e){for(let t=0;t<e;t++){if(i[t]===0)return false;if(i[t]===1)return true}return false}function ece(i,e,t,n,r){let o=n?1:0,s=n?2:0,a=n;for(let c=e;c<t;c++){let u=i[c];u===0?(a=false,r[c]=s):u===1?(a=true,r[c]=1|_T):u===2?r[c]=a?2|_T:s:r[c]=nF;}let l=e;for(;l<t;){if(r[l]!==nF){l++;continue}let c=l;for(;l<t&&r[l]===nF;)l++;let u=c>e?(r[c-1]&_T)!==0:n,d=l<t?(r[l]&_T)!==0:n,h=u&&d?1:!u&&!d?s:o;r.fill(h,c,l);}for(let c=e;c<t;c++)r[c]&=R9e;}function tce(i,e,t,n){let r=0;for(let o=e;o<t;o++)n[o]=o-e,r=Math.max(r,i[o]);for(let o=r;o>=1;o--){let s=e;for(;s<t;){if(i[s]<o){s++;continue}let a=s;for(;s<t&&i[s]>=o;)s++;n.subarray(a,s).reverse();}}}function yT(i){return !(i>=1536&&i<=1919)&&(i<8203||i>8205)||i===S9e?0:kl(x9e,i)?3:kl(E9e,i)?2:kl(g9e,i)?1:0}function nce(i){return i===1570||i===1571||i===1573||i===1575}function rce(i){return v9e.get(i)}var Uy=1,Fy=2,AT=4,Au=8,bT=16,ace=32,C9e=4,N9e=32,lce=45,k9e=173,L9e=0,M9e=1,cce=65535,D9e=16,uce=8,dce=.5,iF=0,hce=1,pce=2,mce=8,je=Math.fround;function fce(){return {size:1,lineHeight:0,letterSpacing:0,maxWidth:0,align:"start",direction:"auto",anchorX:0,anchorY:0}}function P9e(i,e){let t=sa(e);return t===Sy||t===dp||t===Ty?Fy:i===9?Uy|AT:i===32||i===12288||i>=8194&&i<=8202?Uy:i===k9e?bT:0}function F9e(i){return Math.floor(Math.min(Math.max(i,0),1)*cce+.5)/cce}var gT=class{constructor(e){this.bounds=new Float32Array(4);this.count=0;this.lines=0;this.rows=0;this.width=0;this.truncated=false;this.rightToLeft=false;this.hyphen=0;this.blockWidth=0;this.blockHeight=0;this.lineAdvance=0;this.cut=pce;this.cutAt=0;this.segmenter=null;let t=Math.max(1,e);this.capacity=t,this.glyphs=new Float32Array(t*mce),this.codepoint=new Uint32Array(t),this.glyph=new Uint16Array(t),this.classes=new Uint8Array(t),this.kind=new Uint8Array(t),this.props=new Uint16Array(t),this.breaks=new Uint8Array(t),this.x=new Float32Array(t),this.levels=new Uint8Array(t),this.order=new Uint32Array(t),this.lineStart=new Uint32Array(t+1),this.lineEnd=new Uint32Array(t+1),this.lineWidth=new Float32Array(t+1),this.lineRow=new Uint32Array(t+1),this.lineSoft=new Uint8Array(t+1);}lineRange(e,t){return e>=this.lines?false:(t[0]=this.lineStart[e],t[1]=this.lineEnd[e],true)}measure(e,t,n,r){let o=this.compose(e,t,n);return this.count=0,r.lines=this.lines,r.rows=this.rows,r.width=this.width,r.height=je(this.blockHeight*o),r}set(e,t,n){let r=this.compose(e,t,n),o=e.metrics,s=this.rightToLeft,a=n.align==="center"?dce:n.align==="left"||n.align==="start"&&!s||n.align==="end"&&s?0:1,l=-n.anchorX*this.blockWidth*r,c=n.anchorY*this.blockHeight*r,u=0;for(let d=0;d<this.lines;d++){let h=(this.blockWidth-this.lineWidth[d])*a,p=-(o.ascender+this.lineAdvance*this.lineRow[d]);for(let m=this.lineStart[d];m<this.lineEnd[d];m++){let f=this.glyph[m],y=e.plane(f,0),b=e.plane(f,1),A=e.plane(f,2),E=e.plane(f,3);if(this.kind[m]&(Fy|Au)||A<=y||E<=b)continue;let R=u*mce,g=this.x[m]+h;this.glyphs[R]=(g+y)*r+l,this.glyphs[R+1]=(p+b)*r+c,this.glyphs[R+2]=(g+A)*r+l,this.glyphs[R+3]=(p+E)*r+c;for(let v=0;v<4;v++)this.glyphs[R+4+v]=F9e(e.uv(f,v));u++;}}return this.count=u,this.bounds[0]=l,this.bounds[1]=c-this.blockHeight*r,this.bounds[2]=l+this.blockWidth*r,this.bounds[3]=c,u}compose(e,t,n){let r=this.decode(e,t);this.segment(r);let o=je(n.letterSpacing),s=0;for(let m=0;m<r;m++)m>0&&((this.kind[m-1]|this.kind[m])&(Fy|AT|Au))===0&&(s=je(s+e.kerning(this.glyph[m-1],this.glyph[m]))),this.x[m]=s,s=je(s+this.advance(e,m,o));let a=n.size>0?je(n.size):1,l=n.maxWidth>0?je(je(n.maxWidth)/a):Number.POSITIVE_INFINITY,c=e.metrics,u=je(je(c.ascender-c.descender)+c.lineGap);this.lineAdvance=n.lineHeight>0?je(n.lineHeight):u,this.hyphen=e.advance(e.glyph(lce));let d=Number.isFinite(l)?this.wrapWidth(e,r,l,n.wrap??"greedy"):l;this.simpleLines(e,r,d);let h=n.direction==="rtl"?true:n.direction==="ltr"?false:Zle(this.classes,r),p=0;for(let m=0;m<this.lines;m++)p=Math.max(p,this.placeLine(e,m,h,o));return this.blockWidth=Number.isFinite(l)?l:p,this.blockHeight=je(je(c.ascender-c.descender)+je(this.lineAdvance*Math.max(0,this.rows-1))),this.width=je(p*a),this.rightToLeft=h,a}decode(e,t){let n=0,r=false;this.truncated=false;for(let o of t){let s=o.codePointAt(0)??0;if(s===13)continue;if(n===this.capacity){this.truncated=true;break}let a=Ple(s),l=P9e(s,a),c=e.lookup(l&AT?N9e:s);this.glyph[n]=c===xo?e.fallback:c,this.props[n]=a,this.classes[n]=Jle(s),this.kind[n]=l|(c===xo?ace:0),this.codepoint[n]=s,r||=s>=1536&&s<=1919,n++;}return r&&e.hasForms&&this.shape(e,n),n}segment(e){Gle(this.props,this.codepoint,e,this.breaks),Hle(this.props,e,this.breaks),Vle(this.props,this.codepoint,e,this.breaks);let t=gp();t!==null&&(this.segmenter??=new fT(this.capacity),this.segmenter.segment(t,this.codepoint,this.props,e,this.breaks));for(let n=0;n<e;n++){let r=this.props[n],o=(this.breaks[n]&is)!==0;o&&(this.breaks[n]&=~ao);let s=this.kind[n],a=sa(r),l=a===ia||a===hu||a===pp||a===hp||o;(s&bT||s&ace&&l||o&&yp(r))&&(this.kind[n]|=Au);}}advance(e,t,n){let r=this.kind[t];return r&(Fy|Au)?0:r&AT?je(je(e.advance(this.glyph[t])*C9e)+n):je(e.advance(this.glyph[t])+n)}nextJoining(e,t){for(let n=e;n<t;n++)if(yT(this.codepoint[n])!==3)return n;return -1}shape(e,t){let n=false,r=0;for(;r<t;){let o=this.codepoint[r],s=yT(o);if(s===3){r++;continue}if(s===0){n=false,r++;continue}let a=n,l=this.nextJoining(r+1,t),c=l<0?0:yT(this.codepoint[l]);if(o===1604&&l>=0&&nce(this.codepoint[l])){let p=e.ligature(1604,this.codepoint[l],a?M9e:L9e);if(p!==xo){this.glyph[r]=p,this.kind[l]|=Au,n=false,r=l+1;continue}}let u=s===2&&(c===2||c===1),d=a?u?$W:zW:u?QW:qW,h=e.form(o,d);h!==xo&&(this.glyph[r]=h),n=s===2,r++;}}breakLine(e,t,n,r){let o=n<t?this.x[n]:0,s=n;for(let a=n;a<t;a++){let l=this.kind[a];if(l&Fy){this.cut=hce,this.cutAt=a;return}if(a>n&&this.breaks[a]&ao&&this.fitsHyphen(a,o,r)&&(s=a),a>n&&(l&Uy)===0&&je(je(this.x[a]+this.advance(e,a,0))-o)>r){if(this.cut=iF,s>n){this.cutAt=s;return}let c=a;for(;c>n&&this.breaks[c]&is;)c--;if(c===n)for(c=a+1;c<t&&this.breaks[c]&is;)c++;this.cutAt=c;return}}this.cut=pce,this.cutAt=t;}fitsHyphen(e,t,n){return (this.kind[e-1]&bT)===0||je(je(this.x[e-1]+this.hyphen)-t)<=n}simpleLines(e,t,n){let r=0,o=0;for(;;)if(this.breakLine(e,t,o,n),this.lineStart[r]=o,this.lineEnd[r]=this.cutAt,this.lineWidth[r]=0,this.lineRow[r]=r,this.lineSoft[r]=this.cut===iF?1:0,r++,this.cut===iF)for(o=this.cutAt;o<t&&this.kind[o]&Uy;)o++;else if(this.cut===hce)o=this.cutAt+1;else break;this.lines=r,this.rows=r;}lonelyLast(){if(this.lines<2)return false;let e=this.lines-1;for(let t=this.lineStart[e]+1;t<this.lineEnd[e];t++)if(this.breaks[t]&ao)return false;return true}wrapWidth(e,t,n,r){if(r==="greedy")return n;this.simpleLines(e,t,n);let o=this.lines;if(o<2||r==="pretty"&&!this.lonelyLast())return n;let s=0,a=n;for(let l=0;l<D9e;l++){let c=je(je(s+a)*dce);this.simpleLines(e,t,c),this.lines<=o?a=c:s=c;}if(r==="balance")return a;for(let l=1;l<=uce;l++){let c=je(n-je(je(je(n-a)*l)/uce));if(this.simpleLines(e,t,c),this.lines===o&&!this.lonelyLast())return c}return n}placeLine(e,t,n,r){let o=this.lineStart[t],s=this.lineEnd[t];this.lineSoft[t]&&s>o&&this.kind[s-1]&bT&&(this.glyph[s-1]=e.glyph(lce),this.kind[s-1]&=~Au);let a=s;for(;a>o&&this.kind[a-1]&Uy;)a--;let l=n;for(let h=o;h<s&&!l;h++)l=this.classes[h]===1;if(!l){let h=s>o?this.x[o]:0;for(let m=o;m<s;m++)this.x[m]=je(this.x[m]-h);let p=a>o?je(je(this.x[a-1]+this.advance(e,a-1,r))-r):0;return this.lineWidth[t]=p,p}ece(this.classes,o,s,n,this.levels),tce(this.levels,o,s,this.order);for(let h=o;h<s;h++){if((this.levels[h]&1)===0)continue;let p=rce(this.codepoint[h]);if(p===void 0)continue;let m=e.lookup(p);m!==xo&&(this.glyph[h]=m);}let c=0,u=0,d=-1;for(let h=o;h<s;h++){let p=o+this.order[h];if(this.kind[p]&Au){this.x[p]=c;continue}let m=this.glyph[p];d>=0&&(c=je(c+e.kerning(d,m))),this.x[p]=c,c=je(c+this.advance(e,p,r)),p<a&&(u=Math.max(u,je(c-r))),d=m;}return this.lineWidth[t]=u,u}};var U9e=2048,B9e=16,G9e=.01,V9e=16384,bu=Math.fround,ET=class{constructor(){this.layout=new gT(U9e);this.style=fce();this.result={lines:0,rows:0,width:0,height:0};this.memo=new Map;this.hits=0;this.misses=0;this.dictionaries=null;}measure(e,t,n,r,o){let s=n.fontSize??B9e,a=n.lineHeight??0,l=n.letterSpacing??0,c=n.textWrapStyle??"greedy",u=r>0&&Number.isFinite(r)?r:Number.POSITIVE_INFINITY,d=gp();d!==this.dictionaries&&(this.dictionaries=d,this.memo.clear());let h=this.memo.get(t);if(h!==void 0&&h.table===e&&h.size===s&&h.lineHeight===a&&h.letterSpacing===l&&h.wrap===c&&h.limit===u)return this.hits++,o.lines=h.lines,o.width=h.width,o.height=h.height,o;this.misses++;let p=bu(Math.max(s,11920929e-14)),m=this.style;m.size=p,m.lineHeight=bu(a),m.letterSpacing=bu(bu(l)/p),m.maxWidth=Number.isFinite(u)?bu(bu(u)+bu(G9e)):0,m.wrap=c;let f=this.layout.measure(e,t,m,this.result);return o.lines=f.lines,o.width=f.width,o.height=f.height,h!==void 0?(h.table=e,h.size=s,h.lineHeight=a,h.letterSpacing=l,h.wrap=c,h.limit=u,h.lines=f.lines,h.width=f.width,h.height=f.height):(this.memo.size>=V9e&&this.memo.clear(),this.memo.set(t,{table:e,size:s,lineHeight:a,letterSpacing:l,wrap:c,limit:u,lines:f.lines,width:f.width,height:f.height})),o}clear(){this.memo.clear();}};var Se={create:1,destroy:2,insert:3,remove:4,root:5,world_root:6,unroot:7,prop:8,text:9,number:10,string:11,text_ref:12,label:13,value:14,placeholder:15,image:16,path:17,transition:18,scroll_to:19,focus:20,blur:21,font:22,anchor:23,occluded:24,style:25,style_clear:26,tokens:27,slots:28,exclusions:29,text_options:30,vector_load:31,vector_unload:32,vector:33,vector_detach:34,vector_play:35,vector_input:36,vector_input_name:37,vector_data:38,vector_seek:39};var Gy={number:0,bool:1,color:2,fire:4};function xT(i){return Math.floor((i+4-1)/4)}var cF={dictionaries:1,data:2},vp={rect:0,ellipse:1,polygon:2},H9e=7,vT=8,W9e=8,_ce=65535,K9e=1,oF=2147483648,Y9e=1<<24,X9e=1<<25,q9e=16,z9e=255,sF=2,Ace={box:0,text:1,image:2,shape:3,scroll:4,input:5,vector:6},G={width:0,height:1,min_width:2,min_height:3,max_width:4,max_height:5,basis:6,padding:7,margin:8,border_width:9,inset_top:10,inset_right:11,inset_bottom:12,inset_left:13,gap:14,grow:15,shrink:16,aspect:17,direction:18,justify:19,align_items:20,align_self:21,align_content:22,position:23,wrap:24,display_none:25,fill:32,border_color:33,radii:34,opacity:35,translate:36,scale:37,rotate:38,origin:39,z_index:40,hidden:41,clip:42,pointer_events_none:43,flags:44,shadow:45,gradient:46,disabled:47,focusable:48,font_family:64,font_weight:65,font_size:66,line_height:67,letter_spacing:68,text_align:69,text_color:70,text_wrap:71,vertical_align:72,placeholder_color:73,text_wrap_style:74,image_tint:80,image_uv:81,nine_slice:82,nine_slice_uv:83,shape_kind:96,stroke_color:97,stroke_width:98,scroll_axes:112,role:128,traits:129,actions:130},In={auto:0,points:1,percent:2},vi={tap:8,press:16,drag:32,long_press:64,layer:128},bce={integer:0,fixed:1,timer:2,timer_hours:3,compact:4,percent:5},gce={linear:0,ease:1,ease_in:2,ease_out:3,ease_in_out:4,back_out:5,bezier:6,spring:7},Ece={opacity:1,translate_x:2,translate_y:4,scale_x:8,scale_y:16,rotate:32,fill:64,text_color:128},xce={top_left:0,top:1,top_right:2,left:3,center:4,right:5,bottom_left:6,bottom:7,bottom_right:8,fill:9},On={none:0,group:1,text:2,button:3,image:4,header:5,link:6,adjustable:7,tab:8,tab_list:9,progress:10,text_field:11,scroll_view:12,alert:13},vr={selected:1,disabled:2,hidden:4,live:8,modal:16},Ri={activate:1,increment:2,decrement:4,dismiss:8,scroll:16},Eu={press:1,release:2,tap:3,long_press:4,drag_start:5,drag_move:6,drag_end:7,scroll:8,focus:9,action:10,passthrough:11,change:12,blur:13,vector:14},uF={secure:1,numeric:2},RT=0,Q9e=1,$9e=2,ST=4,TT=8,wT=12,dF=16,hF=20,Vy=24,IT=28,vce=128,j9e=2048,aF=55296,By=56320,lF=57344,J9e=10,yce=65536,Z9e=65533,Ep=128,xp=63,eze=192,tze=224,nze=240,la=new Uint8Array(new Uint32Array([1]).buffer)[0]===1;function Rce(i,e,t,n=i.length){let r=t;for(let o=0;o<n;o++){let s=i.charCodeAt(o);if(s>=aF&&s<lF){let a=o+1<n?i.charCodeAt(o+1):0;s<By&&a>=By&&a<lF?(s=yce+(s-aF<<J9e)+(a-By),o++):s=Z9e;}s<vce?e[r++]=s:s<j9e?(e[r++]=eze|s>>6,e[r++]=Ep|s&xp):s<yce?(e[r++]=tze|s>>12,e[r++]=Ep|s>>6&xp,e[r++]=Ep|s&xp):(e[r++]=nze|s>>18,e[r++]=Ep|s>>12&xp,e[r++]=Ep|s>>6&xp,e[r++]=Ep|s&xp);}return r-t}var rze=1,gu=class{constructor(e=16384,t=0){this.count=0;this.reserve=t,this.buffer=new Uint8Array(e),this.view=new DataView(this.buffer.buffer),this.words=new Uint32Array(this.buffer.buffer,0,e>>2),this.floats=new Float32Array(this.buffer.buffer,0,e>>2),this.cursor=0,this.reset();}get bytes(){return this.buffer}get length(){return this.cursor}get records(){return this.count}get empty(){return this.count===0}reset(){this.count=0;let e=this.reserve;this.view.setUint32(e,826889539,true),this.view.setUint16(e+4,1,true),this.view.setUint16(e+4+2,0,true),this.view.setUint32(e+8,0,true),this.cursor=e+12;}finish(){return this.view.setUint32(this.reserve+8,this.count,true),this.cursor}ensure(e){let t=this.cursor+e;if(t<=this.buffer.length)return;let n=this.buffer.length*2;for(;n<t;)n*=2;let r=new Uint8Array(n);r.set(this.buffer.subarray(0,this.cursor)),this.buffer=r,this.view=new DataView(r.buffer),this.words=new Uint32Array(r.buffer,0,n>>2),this.floats=new Float32Array(r.buffer,0,n>>2);}record(e,t,n,r){this.ensure(t*4);let o=this.cursor;this.buffer[o]=e,this.buffer[o+1]=t,this.view.setUint16(o+2,n,true),this.view.setUint32(o+4,r>>>0,true),this.cursor=o+8,this.count++;}u32(e){let t=this.cursor;la&&(t&3)===0?this.words[t>>2]=e:this.view.setUint32(t,e>>>0,true),this.cursor=t+4;}f32(e){let t=this.cursor;la&&(t&3)===0?this.floats[t>>2]=e:this.view.setFloat32(t,e,true),this.cursor=t+4;}simple(e,t,n=0){this.record(e,2,n,t);}create(e,t){this.simple(Se.create,e,t);}destroy(e){this.simple(Se.destroy,e);}insert(e,t,n=4294967295){this.record(Se.insert,4,0,e),this.u32(t),this.u32(n);}remove(e){this.simple(Se.remove,e);}root(e,t,n,r,o,s){this.record(Se.root,7,0,e),this.u32(t),this.u32(n?1:0),this.f32(r),this.f32(o),this.u32(s|0);}worldRoot(e,t){this.record(Se.world_root,15,0,e),this.f32(t.position[0]),this.f32(t.position[1]),this.f32(t.position[2]),this.f32(t.pivot[0]),this.f32(t.pivot[1]),this.f32(t.offset[0]),this.f32(t.offset[1]),this.f32(t.reference_distance),this.f32(t.min_scale),this.f32(t.max_scale),this.u32(t.hide_when_occluded?rze:0),this.f32(t.occluded_opacity),this.u32(t.z|0);}unroot(e){this.simple(Se.unroot,e);}propWord(e,t,n,r=0){this.record(Se.prop,3,t|r<<8,e),this.u32(n);}propFloat(e,t,n,r=0){this.record(Se.prop,3,t|r<<8,e),this.f32(n);}propWordAt(e,t,n,r,o=0){this.record(Se.prop,3,t|o<<8,e),this.u32(n[r]);}propFloatAt(e,t,n,r,o=0){this.record(Se.prop,3,t|o<<8,e);let s=this.cursor;la&&(s&3)===0?this.floats[s>>2]=n[r]:this.view.setFloat32(s,n[r],true),this.cursor=s+4;}propFloats(e,t,n){let r=n.length;this.open(Se.prop,t,e,r);let o=this.cursor;if(la&&(o&3)===0){let s=this.floats,a=o>>2;for(let l=0;l<r;l++)s[a+l]=n[l];}else for(let s=0;s<r;s++)this.view.setFloat32(o+s*4,n[s],true);this.cursor=o+r*4;}propF32(e,t,n){let r=n.length;this.open(Se.prop,t,e,r);let o=this.cursor;if(la&&(o&3)===0){let s=this.floats,a=o>>2;for(let l=0;l<r;l++)s[a+l]=n[l];}else for(let s=0;s<r;s++)this.view.setFloat32(o+s*4,n[s],true);this.cursor=o+r*4;}propWords(e,t,n){this.open(Se.prop,t,e,n.length);for(let r=0;r<n.length;r++)this.u32(n[r]);}propMixed(e,t,n,r){this.open(Se.prop,t,e,n.length+r.length);for(let a=0;a<n.length;a++)this.u32(n[a]);let o=r.length,s=this.cursor;if(la&&(s&3)===0){let a=this.floats,l=s>>2;for(let c=0;c<o;c++)a[l+c]=r[c];}else for(let a=0;a<o;a++)this.view.setFloat32(s+a*4,r[a],true);this.cursor=s+o*4;}textual(e,t,n,r=n.length){let o=r*3,s=16;this.ensure(s+o+4);let a=this.cursor,l=a+s,c=this.buffer,u=r;for(let p=0;p<r;p++){let m=n.charCodeAt(p);if(m>=vce){u=Rce(n,c,l,r);break}c[l+p]=m;}let d=u+4-1&-4;this.buffer.fill(0,l+u,l+d);let h=3+d/4;if(h<=255){this.buffer.copyWithin(a+12,l,l+d),this.record(e,h,0,t),this.u32(u),this.cursor+=d;return}this.record(e,0,0,t),this.u32(h+1),this.u32(u),this.cursor+=d;}text(e,t){this.textual(Se.text,e,t);}textPrefix(e,t,n){this.textual(Se.text,e,t,n<0?0:n>t.length?t.length:n);}string(e,t){this.textual(Se.string,e,t);}label(e,t){this.textual(Se.label,e,t);}value(e,t){this.textual(Se.value,e,t);}placeholder(e,t){this.textual(Se.placeholder,e,t);}textRef(e,t){this.record(Se.text_ref,3,0,e),this.u32(t);}number(e,t,n,r,o){this.record(Se.number,5,0,e),this.view.setFloat64(this.cursor,t,true),this.cursor+=8,this.buffer[this.cursor]=n,this.buffer[this.cursor+1]=r,this.buffer[this.cursor+2]=o,this.buffer[this.cursor+3]=0,this.cursor+=4;}image(e,t,n,r){this.record(Se.image,5,0,e),this.u32(t),this.f32(n),this.f32(r);}path(e,t){let n=t.length-t.length%2;this.ensure((3+n)*4),2+n>255?(this.record(Se.path,0,0,e),this.u32(3+n)):this.record(Se.path,2+n,0,e);let r=this.cursor;if(la&&(r&3)===0){let o=this.floats,s=r>>2;for(let a=0;a<n;a++)o[s+a]=t[a];}else for(let o=0;o<n;o++)this.view.setFloat32(r+o*4,t[o],true);this.cursor=r+n*4;}transition(e,t,n,r,o){this.record(Se.transition,8,t,e),this.f32(n),this.u32(r);for(let s=0;s<4;s++)this.f32(o===null?0:o[s]??0);}scrollTo(e,t,n){this.record(Se.scroll_to,4,0,e),this.f32(t),this.f32(n);}focus(e){this.simple(Se.focus,e);}blur(e){this.simple(Se.blur,e);}font(e,t,n){this.record(Se.font,5,0,0),this.u32(e),this.u32(t),this.u32(n);}textOptions(e){this.record(Se.text_options,3,0,0),this.u32(e);}textDictionaries(e){if(e.byteLength%4!==0)throw new Error("break dictionaries must be a whole number of words");this.open(Se.text_options,0,0,1+e.byteLength/4),this.u32(cF.data),this.buffer.set(e,this.cursor),this.cursor+=e.byteLength;}vectorLoad(e,t){this.open(Se.vector_load,0,e,1+xT(t.byteLength)),this.sizedBytes(t);}vectorUnload(e){this.record(Se.vector_unload,2,0,e);}vector(e,t,n){this.record(Se.vector,4,0,e),this.u32(t),this.u32(n);}vectorDetach(e){this.record(Se.vector_detach,2,0,e);}vectorPlay(e,t,n){this.record(Se.vector_play,4,0,e),this.u32(t),this.u32(n);}vectorSeek(e,t,n,r){this.record(Se.vector_seek,5,0,e),this.u32(t),this.u32(n),this.f32(r);}vectorInput(e,t,n){this.record(Se.vector_input,4,0,e),this.u32(t),this.f32(n);}vectorInputName(e,t,n){this.open(Se.vector_input_name,0,e,2+xT(t.byteLength)),this.f32(n),this.sizedBytes(t);}vectorData(e,t,n,r,o){this.open(Se.vector_data,t,e,3+xT(n.byteLength)),this.f32(r),this.u32(o),this.sizedBytes(n);}sizedBytes(e){let t=xT(e.byteLength)*4;this.u32(e.byteLength),this.buffer.set(e,this.cursor),this.buffer.fill(0,this.cursor+e.byteLength,this.cursor+t),this.cursor+=t;}anchor(e,t,n,r){this.record(Se.anchor,5,0,e),this.f32(t),this.f32(n),this.f32(r);}anchorFrom(e,t,n){this.record(Se.anchor,5,0,e);let r=this.cursor;if(la&&(r&3)===0){let o=this.floats,s=r>>2;o[s]=t[n],o[s+1]=t[n+1],o[s+2]=t[n+2];}else {let o=this.view;o.setFloat32(r,t[n],true),o.setFloat32(r+4,t[n+1],true),o.setFloat32(r+8,t[n+2],true);}this.cursor=r+12;}occluded(e,t){this.record(Se.occluded,3,0,e),this.u32(t?1:0);}open(e,t,n,r){this.ensure((3+r)*4),2+r>255?(this.record(e,0,t,n),this.u32(3+r)):this.record(e,2+r,t,n);}style(e,t,n,r=0){let o=n.length;this.open(Se.style,t,e,o);let s=0;for(;s<o;){let a=n[s++];this.u32(a);let l=a>>>q9e&z9e,c=0;(a&Y9e)!==0&&(c=n[s++],this.u32(c)),(a&X9e)!==0&&this.u32(n[s++]);for(let u=0;u<l;u++){let d=n[s++],h=(c&1<<u)!==0&&(d&oF)!==0;this.u32(h?(oF|(d&~oF)+r)>>>0:d);}}}styleClear(e){this.simple(Se.style_clear,e);}exclusions(e,t,n=t.length){let r=0;for(let o=0;o<n;o++){let s=t[o].points,a=s===null?0:s.length-s.length%2;if(a/2>_ce)throw new Error(`an exclusion polygon has ${a/2} points; the limit is ${_ce}`);r+=H9e+a;}this.open(Se.exclusions,0,e,r);for(let o=0;o<n;o++){let s=t[o],a=s.points,l=a===null?0:(a.length-a.length%2)/2;if(this.u32((s.shape|l<<W9e)>>>0),this.u32(s.sibling),this.f32(s.margin),this.f32(s.x),this.f32(s.y),this.f32(s.width),this.f32(s.height),a!==null)for(let c=0;c<l*2;c++)this.f32(a[c]);}}tokens(e,t){this.open(Se.tokens,e?K9e:0,0,t*sF);}pair(e,t){this.u32(e),this.u32(t);}slot(e,t){this.record(Se.slots,2+sF,0,0),this.u32(e),this.u32(t);}slotAt(e,t,n){this.record(Se.slots,2+sF,0,0),this.u32(e);let r=this.cursor;la&&(r&3)===0?this.words[r>>2]=t[n]:this.view.setUint32(r,t[n],true),this.cursor=r+4;}};function Sce(i,e,t){t.kind=i.getUint8(e+RT),t.phase=i.getUint8(e+Q9e),t.pointer=i.getUint16(e+$9e,true),t.node=i.getUint32(e+ST,true),t.x=i.getFloat32(e+TT,true),t.y=i.getFloat32(e+wT,true),t.dx=i.getFloat32(e+dF,true),t.dy=i.getFloat32(e+hF,true),t.value=i.getFloat32(e+Vy,true),t.time_ms=i.getUint32(e+IT,true);}function pF(i){return Math.ceil(i/32)*32}function Tce(i){return 32+pF(i.length*3)}function wce(i,e,t,n,r,o,s=null){let a=new DataView(i.buffer,i.byteOffset,i.byteLength),l=e+32,c=Rce(r,i,l),u=pF(c);return i.fill(0,e,e+32),i.fill(0,l+c,l+u),a.setUint8(e+RT,t),a.setUint32(e+ST,n>>>0,true),s!==null&&(a.setFloat32(e+TT,s.start,true),a.setFloat32(e+wT,s.end,true)),a.setFloat32(e+Vy,c,true),a.setUint32(e+IT,o>>>0,true),32+u}function mF(i,e){let t=0,n=Math.min(e,i.length);for(let r=0;r<n;r++){let o=i.charCodeAt(r);if(o>=aF&&o<By&&r+1<n){let s=i.charCodeAt(r+1);s>=By&&s<lF&&r++;}t++;}return t}function Ice(i,e,t){return i!==Eu.change?32:32+pF(e.getFloat32(t+Vy,true))}var fn=class extends Error{constructor(e){super(e),this.name="UiStyleError";}},fF=16,Oce=3,ize=4,oze=6,sze=8,Cce=255,_F=8,aze=17,as=4,yF=1,OT=4,AF=8,lze="%",cze="#",uze=16,Nce=new Map;function Un(i){if(typeof i=="number")return i>>>0;let e=Nce.get(i);if(e!==void 0)return e;let t=i.startsWith(cze)?i.slice(1):i,n;if(t.length===Oce||t.length===ize){n=0;for(let r=0;r<t.length;r++)n=n<<_F|Number.parseInt(t[r],fF)*aze;t.length===Oce&&(n=n<<_F|Cce);}else if(t.length===oze)n=Number.parseInt(t,fF)<<_F|Cce;else if(t.length===sze)n=Number.parseInt(t,fF);else throw new fn(`color ${i} must be #rgb, #rgba, #rrggbb or #rrggbbaa`);if(Number.isNaN(n))throw new fn(`color ${i} is not hexadecimal`);return n>>>=0,Nce.set(i,n),n}var NT={row:0,column:1,"row-reverse":2,"column-reverse":3},kT={start:0,end:1,center:2,"space-between":3,"space-around":4,"space-evenly":5},ls={auto:0,start:1,end:2,center:3,stretch:4},LT={start:0,end:1,left:2,center:3,right:4},MT={top:0,center:1,bottom:2},DT={greedy:0,balance:1,pretty:2},PT={rect:0,ellipse:1,path:2},FT={none:0,x:1,y:2,both:3},bF={linear:0,radial:1},CT=class{constructor(){this.sent=new Map;}changed(e,t,n){let r=this.sent.get(e);if(r!==void 0&&r.length===n){let o=true;for(let s=0;s<n;s++)if(!Object.is(r[s],t[s])){o=false;break}if(o)return false}(r===void 0||r.length!==n)&&(r=new Float64Array(n),this.sent.set(e,r));for(let o=0;o<n;o++)r[o]=t[o];return true}forget(e){this.sent.delete(e);}},mn=new Float64Array(uze);function dze(i){if(typeof i=="number")return [i,In.points];if(i==="auto")return [0,In.auto];if(i.endsWith(lze))return [Number.parseFloat(i),In.percent];throw new fn(`length ${i} must be a number, a percentage or auto`)}function Rp(i){return typeof i=="number"?[i,i,i,i]:i}function lo(i,e,t,n,r){let[o,s]=dze(r);mn[0]=o,mn[1]=s,e.changed(n,mn,2)&&i.propFloat(t,n,o,s);}function ca(i,e,t,n,r){mn[0]=r,e.changed(n,mn,1)&&i.propFloat(t,n,r);}function Mt(i,e,t,n,r){mn[0]=r>>>0,e.changed(n,mn,1)&&i.propWord(t,n,r);}function co(i,e,t,n,r){for(let o=0;o<r.length;o++)mn[o]=r[o];e.changed(n,mn,r.length)&&i.propFloats(t,n,r);}function hze(i,e,t,n,r){for(let o=0;o<r.length;o++)mn[o]=r[o]>>>0;e.changed(n,mn,r.length)&&i.propWords(t,n,r);}function uo(i,e,t){let n=i[e];if(n===void 0)throw new fn(`${t} ${e} is not supported`);return n}function pze(i,e,t,n){if(n===null){mn.fill(0,0,yF+OT),e.changed(G.shadow,mn,yF+OT)&&i.propMixed(t,G.shadow,[0],[0,0,0,0]);return}let r=Un(n.color),o=[n.x??0,n.y??0,n.blur??0,n.spread??0];mn[0]=r;for(let s=0;s<OT;s++)mn[1+s]=o[s];e.changed(G.shadow,mn,yF+OT)&&i.propMixed(t,G.shadow,[r],o);}function mze(i,e,t,n){if(n===null){e.forget(G.gradient),i.propWords(t,G.gradient,[]);return}if(n.stops.length===0||n.stops.length>as)throw new fn(`a gradient needs between 1 and ${as} stops`);let r=uo(bF,n.kind??"linear","gradient"),o=[0,0,0,0],s=Array.from({length:AF},()=>0);for(let c=0;c<as;c++){let u=n.stops[Math.min(c,n.stops.length-1)];o[c]=Un(u[0]),s[c]=u[1];}let a=n.from??[0,0],l=n.to??[0,1];s[as]=a[0],s[as+1]=a[1],s[as+2]=l[0],s[as+3]=l[1],mn[0]=r;for(let c=0;c<as;c++)mn[1+c]=o[c];for(let c=0;c<AF;c++)mn[1+as+c]=s[c];e.changed(G.gradient,mn,1+as+AF)&&i.propMixed(t,G.gradient,[r,...o],s);}function kce(i,e,t,n){for(let r in n){let o=n[r];if(o!==void 0)switch(r){case "width":lo(i,e,t,G.width,o);break;case "height":lo(i,e,t,G.height,o);break;case "minWidth":lo(i,e,t,G.min_width,o);break;case "minHeight":lo(i,e,t,G.min_height,o);break;case "maxWidth":lo(i,e,t,G.max_width,o);break;case "maxHeight":lo(i,e,t,G.max_height,o);break;case "basis":lo(i,e,t,G.basis,o);break;case "top":lo(i,e,t,G.inset_top,o);break;case "right":lo(i,e,t,G.inset_right,o);break;case "bottom":lo(i,e,t,G.inset_bottom,o);break;case "left":lo(i,e,t,G.inset_left,o);break;case "padding":co(i,e,t,G.padding,Rp(o));break;case "margin":co(i,e,t,G.margin,Rp(o));break;case "borderWidth":co(i,e,t,G.border_width,Rp(o));break;case "radius":co(i,e,t,G.radii,Rp(o));break;case "nineSlice":co(i,e,t,G.nine_slice,Rp(o));break;case "nineSliceUv":co(i,e,t,G.nine_slice_uv,Rp(o));break;case "uv":co(i,e,t,G.image_uv,o);break;case "gap":{let s=o;co(i,e,t,G.gap,typeof s=="number"?[s,s]:s);break}case "grow":ca(i,e,t,G.grow,o);break;case "shrink":ca(i,e,t,G.shrink,o);break;case "aspect":ca(i,e,t,G.aspect,o);break;case "opacity":ca(i,e,t,G.opacity,o);break;case "rotate":ca(i,e,t,G.rotate,o);break;case "fontSize":ca(i,e,t,G.font_size,o);break;case "lineHeight":ca(i,e,t,G.line_height,o);break;case "letterSpacing":ca(i,e,t,G.letter_spacing,o);break;case "strokeWidth":ca(i,e,t,G.stroke_width,o);break;case "translate":co(i,e,t,G.translate,o);break;case "scale":{let s=o;co(i,e,t,G.scale,typeof s=="number"?[s,s]:s);break}case "origin":co(i,e,t,G.origin,o);break;case "direction":Mt(i,e,t,G.direction,uo(NT,o,"direction"));break;case "justify":Mt(i,e,t,G.justify,uo(kT,o,"justify"));break;case "alignItems":Mt(i,e,t,G.align_items,uo(ls,o,"alignItems"));break;case "alignSelf":Mt(i,e,t,G.align_self,uo(ls,o,"alignSelf"));break;case "alignContent":Mt(i,e,t,G.align_content,uo(ls,o,"alignContent"));break;case "position":Mt(i,e,t,G.position,o==="absolute"?1:0);break;case "wrap":Mt(i,e,t,G.wrap,o?1:0);break;case "display":Mt(i,e,t,G.display_none,o==="none"?1:0);break;case "zIndex":Mt(i,e,t,G.z_index,o|0);break;case "hidden":Mt(i,e,t,G.hidden,o?1:0);break;case "clip":Mt(i,e,t,G.clip,o?1:0);break;case "pointerEvents":Mt(i,e,t,G.pointer_events_none,o==="none"?1:0);break;case "fill":Mt(i,e,t,G.fill,Un(o));break;case "textColor":Mt(i,e,t,G.text_color,Un(o));break;case "placeholderColor":Mt(i,e,t,G.placeholder_color,Un(o));break;case "tint":Mt(i,e,t,G.image_tint,Un(o));break;case "stroke":Mt(i,e,t,G.stroke_color,Un(o));break;case "borderColor":{let s=o,a=Array.isArray(s)?s.map(Un):[Un(s),Un(s),Un(s),Un(s)];hze(i,e,t,G.border_color,a);break}case "fontFamily":Mt(i,e,t,G.font_family,o);break;case "fontWeight":Mt(i,e,t,G.font_weight,o);break;case "textAlign":Mt(i,e,t,G.text_align,uo(LT,o,"textAlign"));break;case "verticalAlign":Mt(i,e,t,G.vertical_align,uo(MT,o,"verticalAlign"));break;case "textWrap":Mt(i,e,t,G.text_wrap,o?1:0);break;case "textWrapStyle":Mt(i,e,t,G.text_wrap_style,uo(DT,o,"textWrapStyle"));break;case "shape":Mt(i,e,t,G.shape_kind,uo(PT,o,"shape"));break;case "scrollAxes":Mt(i,e,t,G.scroll_axes,uo(FT,o,"scrollAxes"));break;case "shadow":pze(i,e,t,o);break;case "gradient":mze(i,e,t,o);break;case "layer":break;default:throw new fn(`style ${r} is not supported`)}}}var Be={length:0,float:1,int:2,color:3,enumeration:4,bool:5,edges:6,pair:7,colors:8,quad:9,shadow:10,gradient:11},xu=4,fze=5,RF=1+xu*2+4,Mce=1+xu,Dce=[1,1,1,1,1,1,4,2,4,4,fze,RF];function Ml(i,e){switch(i){case Be.length:case Be.float:case Be.edges:case Be.pair:case Be.quad:return true;case Be.shadow:return e>0;case Be.gradient:return e>=Mce;default:return false}}function BT(i,e){return i===Be.color||i===Be.colors?true:i===Be.shadow?e===0:i===Be.gradient?e>0&&e<Mce:false}var GT={shorthandOfShorthands:1e3,shorthandOfLonghands:2e3,plain:3e3,longhand:4e3},Pce={flex:0,none:1},Fce={relative:0,absolute:1},Uce={auto:0,none:1},X=Be,Hy=GT.shorthandOfShorthands,Rr=GT.shorthandOfLonghands,Te=GT.plain,ut=GT.longhand,Tp=[{name:"width",type:X.length,tier:Te},{name:"height",type:X.length,tier:Te},{name:"minWidth",type:X.length,tier:Te},{name:"minHeight",type:X.length,tier:Te},{name:"maxWidth",type:X.length,tier:Te},{name:"maxHeight",type:X.length,tier:Te},{name:"basis",type:X.length,tier:Te},{name:"inset",type:X.length,tier:Hy},{name:"insetInline",type:X.length,tier:Rr},{name:"insetBlock",type:X.length,tier:Rr},{name:"top",type:X.length,tier:ut},{name:"right",type:X.length,tier:ut},{name:"bottom",type:X.length,tier:ut},{name:"left",type:X.length,tier:ut},{name:"padding",type:X.edges,tier:Hy},{name:"paddingInline",type:X.float,tier:Rr},{name:"paddingBlock",type:X.float,tier:Rr},{name:"paddingTop",type:X.float,tier:ut},{name:"paddingRight",type:X.float,tier:ut},{name:"paddingBottom",type:X.float,tier:ut},{name:"paddingLeft",type:X.float,tier:ut},{name:"margin",type:X.edges,tier:Hy},{name:"marginInline",type:X.float,tier:Rr},{name:"marginBlock",type:X.float,tier:Rr},{name:"marginTop",type:X.float,tier:ut},{name:"marginRight",type:X.float,tier:ut},{name:"marginBottom",type:X.float,tier:ut},{name:"marginLeft",type:X.float,tier:ut},{name:"borderWidth",type:X.edges,tier:Hy},{name:"borderInlineWidth",type:X.float,tier:Rr},{name:"borderBlockWidth",type:X.float,tier:Rr},{name:"borderTopWidth",type:X.float,tier:ut},{name:"borderRightWidth",type:X.float,tier:ut},{name:"borderBottomWidth",type:X.float,tier:ut},{name:"borderLeftWidth",type:X.float,tier:ut},{name:"gap",type:X.pair,tier:Rr},{name:"columnGap",type:X.float,tier:ut},{name:"rowGap",type:X.float,tier:ut},{name:"grow",type:X.float,tier:Te},{name:"shrink",type:X.float,tier:Te},{name:"aspect",type:X.float,tier:Te},{name:"direction",type:X.enumeration,tier:Te,table:NT},{name:"justify",type:X.enumeration,tier:Te,table:kT},{name:"alignItems",type:X.enumeration,tier:Te,table:ls},{name:"alignSelf",type:X.enumeration,tier:Te,table:ls},{name:"alignContent",type:X.enumeration,tier:Te,table:ls},{name:"position",type:X.enumeration,tier:Te,table:Fce},{name:"wrap",type:X.bool,tier:Te},{name:"display",type:X.enumeration,tier:Te,table:Pce},{name:"fill",type:X.color,tier:Te},{name:"borderColor",type:X.colors,tier:Hy},{name:"borderInlineColor",type:X.color,tier:Rr},{name:"borderBlockColor",type:X.color,tier:Rr},{name:"borderTopColor",type:X.color,tier:ut},{name:"borderRightColor",type:X.color,tier:ut},{name:"borderBottomColor",type:X.color,tier:ut},{name:"borderLeftColor",type:X.color,tier:ut},{name:"radius",type:X.edges,tier:Rr},{name:"radiusTopLeft",type:X.float,tier:ut},{name:"radiusTopRight",type:X.float,tier:ut},{name:"radiusBottomRight",type:X.float,tier:ut},{name:"radiusBottomLeft",type:X.float,tier:ut},{name:"opacity",type:X.float,tier:Te},{name:"translate",type:X.pair,tier:Rr},{name:"translateX",type:X.float,tier:ut},{name:"translateY",type:X.float,tier:ut},{name:"scale",type:X.pair,tier:Rr},{name:"scaleX",type:X.float,tier:ut},{name:"scaleY",type:X.float,tier:ut},{name:"rotate",type:X.float,tier:Te},{name:"origin",type:X.pair,tier:Te},{name:"zIndex",type:X.int,tier:Te},{name:"hidden",type:X.bool,tier:Te},{name:"clip",type:X.bool,tier:Te},{name:"pointerEvents",type:X.enumeration,tier:Te,table:Uce},{name:"layer",type:X.bool,tier:Te},{name:"shadow",type:X.shadow,tier:Te},{name:"gradient",type:X.gradient,tier:Te},{name:"fontFamily",type:X.int,tier:Te},{name:"fontWeight",type:X.int,tier:Te},{name:"fontSize",type:X.float,tier:Te},{name:"lineHeight",type:X.float,tier:Te},{name:"letterSpacing",type:X.float,tier:Te},{name:"textAlign",type:X.enumeration,tier:Te,table:LT},{name:"textColor",type:X.color,tier:Te},{name:"textWrap",type:X.bool,tier:Te},{name:"verticalAlign",type:X.enumeration,tier:Te,table:MT},{name:"placeholderColor",type:X.color,tier:Te},{name:"tint",type:X.color,tier:Te},{name:"uv",type:X.quad,tier:Te},{name:"nineSlice",type:X.edges,tier:Te},{name:"nineSliceUv",type:X.edges,tier:Te},{name:"shape",type:X.enumeration,tier:Te,table:PT},{name:"stroke",type:X.color,tier:Te},{name:"strokeWidth",type:X.float,tier:Te},{name:"scrollAxes",type:X.enumeration,tier:Te,table:FT},{name:"textWrapStyle",type:X.enumeration,tier:Te,table:DT}],po=Tp.length,SF=Tp.map(i=>i.name),ua=Uint8Array.from(Tp,i=>i.type),Xy=Uint16Array.from(Tp,i=>i.tier),VT=Tp.map(i=>i.table??null),_ze={borderRadius:"radius",borderTopLeftRadius:"radiusTopLeft",borderTopRightRadius:"radiusTopRight",borderBottomRightRadius:"radiusBottomRight",borderBottomLeftRadius:"radiusBottomLeft",paddingHorizontal:"paddingInline",paddingVertical:"paddingBlock",marginHorizontal:"marginInline",marginVertical:"marginBlock",flexGrow:"grow",flexShrink:"shrink",flexBasis:"basis",flexDirection:"direction",justifyContent:"justify",backgroundColor:"fill",color:"textColor",aspectRatio:"aspect"},Yy=new Map;Tp.forEach((i,e)=>Yy.set(i.name,e));for(let[i,e]of Object.entries(_ze))Yy.set(i,Yy.get(e));function Ll(i){return Yy.get(i)??-1}var TF=[...Yy.keys()],Ne={pressed:1,focus:2,disabled:4,landscape:8,portrait:16,safe:32,sm:64,lg:128},wF=Ne.pressed|Ne.focus|Ne.disabled,IF=Ne.landscape|Ne.portrait|Ne.safe|Ne.sm|Ne.lg,OF={":pressed":Ne.pressed,":active":Ne.pressed,":focus":Ne.focus,":disabled":Ne.disabled,"@landscape":Ne.landscape,"@portrait":Ne.portrait,"@safe":Ne.safe,"@sm":Ne.sm,"@lg":Ne.lg},yze=170,Aze=150,bze=92,Wy=200,gze=8,Eze=[yze,Aze,bze,Wy,Wy,Wy,Wy,Wy];function qy(i){let e=0;for(let t=0;t<gze;t++)i&1<<t&&(e+=Eze[t]);return e}var _e={length:0,float:1,word:2,floats:3,words:4,shadow:5,gradient:6,flag:7},Sp=0,Lce=4294967295,xze=4294967168,vze=400,Rze=16,Sze=.5;function ho(i,e){return {prop:i,emit:_e.length,components:[e],defaults:[0,In.auto]}}function Xe(i,e,t,n){return {prop:i,emit:e,components:[[[t,0]]],defaults:[n]}}function gF(i,e,t,n,r,o,s,a){return {prop:i,emit:_e.floats,components:[[[e,0],[n,0],[r,0]],[[e,1],[t,0],[o,0]],[[e,2],[n,0],[s,0]],[[e,3],[t,0],[a,0]]],defaults:[0,0,0,0]}}function UT(i,e,t,n,r){return {prop:i,emit:_e.floats,components:[t===null?[[e,0]]:[[e,0],[t,0]],n===null?[[e,1]]:[[e,1],[n,0]]],defaults:[r,r]}}function Ky(i,e,t,n){return {prop:i,emit:e,components:n.map((r,o)=>[[t,o]]),defaults:n}}var zy=[ho(G.width,[["width",0]]),ho(G.height,[["height",0]]),ho(G.min_width,[["minWidth",0]]),ho(G.min_height,[["minHeight",0]]),ho(G.max_width,[["maxWidth",0]]),ho(G.max_height,[["maxHeight",0]]),ho(G.basis,[["basis",0]]),ho(G.inset_top,[["inset",0],["insetBlock",0],["top",0]]),ho(G.inset_right,[["inset",0],["insetInline",0],["right",0]]),ho(G.inset_bottom,[["inset",0],["insetBlock",0],["bottom",0]]),ho(G.inset_left,[["inset",0],["insetInline",0],["left",0]]),gF(G.padding,"padding","paddingInline","paddingBlock","paddingTop","paddingRight","paddingBottom","paddingLeft"),gF(G.margin,"margin","marginInline","marginBlock","marginTop","marginRight","marginBottom","marginLeft"),gF(G.border_width,"borderWidth","borderInlineWidth","borderBlockWidth","borderTopWidth","borderRightWidth","borderBottomWidth","borderLeftWidth"),UT(G.gap,"gap","columnGap","rowGap",0),Xe(G.grow,_e.float,"grow",0),Xe(G.shrink,_e.float,"shrink",1),Xe(G.aspect,_e.float,"aspect",0),Xe(G.direction,_e.word,"direction",NT.column),Xe(G.justify,_e.word,"justify",kT.start),Xe(G.align_items,_e.word,"alignItems",ls.stretch),Xe(G.align_self,_e.word,"alignSelf",ls.auto),Xe(G.align_content,_e.word,"alignContent",ls.stretch),Xe(G.position,_e.word,"position",Fce.relative),Xe(G.wrap,_e.word,"wrap",0),Xe(G.display_none,_e.word,"display",Pce.flex),Xe(G.fill,_e.word,"fill",Sp),{prop:G.border_color,emit:_e.words,components:[[["borderColor",0],["borderBlockColor",0],["borderTopColor",0]],[["borderColor",1],["borderInlineColor",0],["borderRightColor",0]],[["borderColor",2],["borderBlockColor",0],["borderBottomColor",0]],[["borderColor",3],["borderInlineColor",0],["borderLeftColor",0]]],defaults:[Sp,Sp,Sp,Sp]},{prop:G.radii,emit:_e.floats,components:[[["radius",0],["radiusTopLeft",0]],[["radius",1],["radiusTopRight",0]],[["radius",2],["radiusBottomRight",0]],[["radius",3],["radiusBottomLeft",0]]],defaults:[0,0,0,0]},Xe(G.opacity,_e.float,"opacity",1),UT(G.translate,"translate","translateX","translateY",0),UT(G.scale,"scale","scaleX","scaleY",1),Xe(G.rotate,_e.float,"rotate",0),UT(G.origin,"origin",null,null,Sze),Xe(G.z_index,_e.word,"zIndex",0),Xe(G.hidden,_e.word,"hidden",0),Xe(G.clip,_e.word,"clip",0),Xe(G.pointer_events_none,_e.word,"pointerEvents",Uce.auto),Xe(G.flags,_e.flag,"layer",0),Ky(G.shadow,_e.shadow,"shadow",[0,0,0,0,0]),Ky(G.gradient,_e.gradient,"gradient",new Array(RF).fill(0)),Xe(G.font_family,_e.word,"fontFamily",0),Xe(G.font_weight,_e.word,"fontWeight",vze),Xe(G.font_size,_e.float,"fontSize",Rze),Xe(G.line_height,_e.float,"lineHeight",0),Xe(G.letter_spacing,_e.float,"letterSpacing",0),Xe(G.text_align,_e.word,"textAlign",LT.start),Xe(G.text_color,_e.word,"textColor",Lce),Xe(G.text_wrap,_e.word,"textWrap",0),Xe(G.vertical_align,_e.word,"verticalAlign",MT.top),Xe(G.placeholder_color,_e.word,"placeholderColor",xze),Xe(G.image_tint,_e.word,"tint",Lce),Ky(G.image_uv,_e.floats,"uv",[0,0,1,1]),Ky(G.nine_slice,_e.floats,"nineSlice",[0,0,0,0]),Ky(G.nine_slice_uv,_e.floats,"nineSliceUv",[0,0,0,0]),Xe(G.shape_kind,_e.word,"shape",PT.rect),Xe(G.stroke_color,_e.word,"stroke",Sp),Xe(G.stroke_width,_e.float,"strokeWidth",0),Xe(G.scroll_axes,_e.word,"scrollAxes",FT.none),Xe(G.text_wrap_style,_e.word,"textWrapStyle",DT.greedy)],wp=zy.length,HT=Uint8Array.from(zy,i=>i.prop),Qy=Uint8Array.from(zy,i=>i.emit),WT=new Uint16Array(wp),Ip=new Uint8Array(wp),CF=new Uint8Array(wp),EF=[],Bce=[],Gce=[],Vce=[],xF=[],Hce=[],vF=Array.from({length:po},()=>[]);zy.forEach((i,e)=>{WT[e]=EF.length,Ip[e]=i.components.length,CF[e]=i.emit===_e.length?i.defaults[1]:0,i.components.forEach((t,n)=>{EF.push(EF.length),Bce.push(i.defaults[n]),Gce.push(xF.length),Vce.push(t.length);for(let[r,o]of t){let s=Ll(r);if(s<0)throw new Error(`wire chain names unknown key ${r}`);xF.push(s),Hce.push(o),vF[s].indexOf(e)<0&&vF[s].push(e);}});});var Wce=Array.from({length:po},()=>new Set);for(let i of zy)for(let e of i.components)for(let t=0;t<e.length;t++)for(let n=t+1;n<e.length;n++)Wce[Ll(e[t][0])].add(Ll(e[n][0]));var Kce=Wce.map(i=>[...i].sort((e,t)=>e-t)),Yce=Float64Array.from(Bce),NF=Uint16Array.from(Gce),kF=Uint8Array.from(Vce),LF=Uint8Array.from(xF),Xce=Uint8Array.from(Hce),qce=vF.map(i=>Uint8Array.from(i)),MF=RF;function Tze(i,e){let t=i.length+1,n=e.length+1,r=new Array(t*n).fill(0);for(let o=0;o<t;o++)r[o*n]=o;for(let o=0;o<n;o++)r[o]=o;for(let o=1;o<t;o++)for(let s=1;s<n;s++){let a=i[o-1]===e[s-1]?0:1,l=Math.min(r[(o-1)*n+s]+1,r[o*n+s-1]+1,r[(o-1)*n+s-1]+a);o>1&&s>1&&i[o-1]===e[s-2]&&i[o-2]===e[s-1]&&(l=Math.min(l,r[(o-2)*n+s-2]+1)),r[o*n+s]=l;}return r[t*n-1]}function Dl(i,e){let t=Math.max(2,Math.floor(i.length/3)),n=null,r=Number.POSITIVE_INFINITY,o=i.toLowerCase();for(let s of e){let a=s.toLowerCase()===o?0:Tze(i,s);(a<r||a===r&&n!==null&&s<n)&&(n=s,r=a);}return r<=t?n:null}function KT(i,e){let t=Dl(i,e);return t===null?"":`; did you mean "${t}"?`}var wze=2166136261,Ize=16777619,Oze=1073741823;function Qce(i,e){let t=`${i}.${e}`,n=wze;for(let r=0;r<t.length;r++)n^=t.charCodeAt(r),n=Math.imul(n,Ize);return n>>>0&Oze}var Pl=class{constructor(e,t,n){this.id=e;this.name=t;this.fallback=n;}},vu=class{constructor(e,t=false){this.index=e;this.percent=t;}},$ce=new Map,zce=new Map;function $y(i){return $ce.get(i)}function DF(i,e){let t={};for(let n of Object.keys(e)){let r=`${i}.${n}`,o=Qce(i,n),s=zce.get(o);if(s!==void 0&&s!==r)throw new fn(`style variable ${r} collides with ${s}; rename one of them`);zce.set(o,r),$ce.set(o,e[n]),t[n]=new Pl(o,r,e[n]);}return Object.freeze(t)}var cs=class{constructor(e){this.values=e;}};function jce(i){let e=new Map;for(let t of i)for(let[n,r]of t.values)e.set(n,r);return new cs(e)}var BF=827937875,GF=1,Jce=2,Ul={literal:0,null:1,referenced:2},jy=2147483648,YT=255,tue=8,nue=8,PF=16,rue=20,Zce=15,iue=16,Cze=65535,eue="%",Nze="auto",oue="default",Sr=class extends fn{constructor(t,n,r,o){super(t);this.kind=n;this.subject=r;this.suggestion=o;this.name="UiStyleCompileError";}};function kze(i){let e=Dl(i,TF);return new Sr(`unknown style property "${i}"${e===null?"":`; did you mean "${e}"?`}`,"property",i,e)}function Cn(i,e){return new Sr(`${i}: ${e}`,"value",i,null)}var VF=new Float32Array(1),sue=new Uint32Array(VF.buffer);function Ru(i){return VF[0]=i,sue[0]}function Lze(i){return sue[0]=i,VF[0]}function Fl(i){return i instanceof Pl||i instanceof vu}function Mze(i){return i instanceof vu?(jy|i.index)>>>0:i.id}function XT(i){if(typeof i!="object"||i===null||Array.isArray(i)||Fl(i))return false;let e=Object.getPrototypeOf(i);return e===Object.prototype||e===null}function Dze(i){if(!XT(i))return false;for(let e of Object.keys(i))if(e===oue||e.startsWith(":")||e.startsWith("@"))return true;return false}function FF(i,e,t,n){if(!Dze(e)){n.delete(t),n.set(t,e);return}for(let[r,o]of Object.entries(e)){if(r===oue){FF(i,o,t,n);continue}let s=OF[r];if(s===void 0){let a=Dl(r,Object.keys(OF));throw new Sr(`${i}: unknown condition "${r}"${a===null?"":`; did you mean "${a}"?`}`,"condition",r,a)}FF(i,o,t|s,n);}}var UF=class{constructor(e){this.key=e;this.words=[];this.refs=0;this.unit=0;}reference(e){this.refs|=1<<this.words.length,this.words.push(Mze(e));}float(e){if(Fl(e))return this.reference(e);if(typeof e!="number"||!Number.isFinite(e))throw Cn(this.key,`${String(e)} must be a finite number`);this.words.push(Ru(e));}color(e){if(Fl(e))return this.reference(e);if(typeof e!="number"&&typeof e!="string")throw Cn(this.key,`${String(e)} must be a colour`);try{this.words.push(Un(e));}catch(t){throw Cn(this.key,t.message)}}length(e){if(Fl(e))return this.unit=e instanceof vu&&e.percent?In.percent:In.points,this.reference(e);if(typeof e=="number"&&Number.isFinite(e)){this.unit=In.points,this.words.push(Ru(e));return}if(e===Nze){this.unit=In.auto,this.words.push(0);return}if(typeof e=="string"&&e.endsWith(eue)){let t=Number(e.slice(0,-eue.length));if(Number.isFinite(t)){this.unit=In.percent,this.words.push(Ru(t));return}}throw Cn(this.key,`length ${String(e)} must be a number, a percentage or auto`)}enumeration(e,t){if(Fl(e))return this.reference(e);let n=typeof e=="string"?t[e]:void 0;if(n===void 0)throw Cn(this.key,`${String(e)} is not one of ${Object.keys(t).join(", ")}${KT(String(e),Object.keys(t))}`);this.words.push(n);}bool(e){if(Fl(e))return this.reference(e);if(typeof e!="boolean")throw Cn(this.key,`${String(e)} must be true or false`);this.words.push(e?1:0);}int(e){if(Fl(e))return this.reference(e);if(typeof e!="number"||!Number.isInteger(e))throw Cn(this.key,`${String(e)} must be an integer`);this.words.push((e|0)>>>0);}repeat(e,t,n,r){if(Array.isArray(e)){if(e.length!==t)throw Cn(this.key,`${r} takes one value or ${t} values`);for(let o of e)n(o);return}for(let o=0;o<t;o++)n(e);}shadow(e){if(!XT(e))throw Cn(this.key,"a shadow is { color, x, y, blur, spread }");let t=["color","x","y","blur","spread"];for(let n of Object.keys(e))if(t.indexOf(n)<0)throw Cn(this.key,`shadow has no ${n}${KT(n,t)}`);this.color(e.color),this.float(e.x??0),this.float(e.y??0),this.float(e.blur??0),this.float(e.spread??0);}gradient(e){if(!XT(e))throw Cn(this.key,"a gradient is { kind, stops, from, to }");let t=["kind","stops","from","to"];for(let a of Object.keys(e))if(t.indexOf(a)<0)throw Cn(this.key,`gradient has no ${a}${KT(a,t)}`);let n=e.stops;if(!Array.isArray(n)||n.length===0||n.length>xu)throw Cn(this.key,`a gradient needs between 1 and ${xu} stops`);this.enumeration(e.kind??"linear",bF);let r=a=>{let l=n[Math.min(a,n.length-1)];if(!Array.isArray(l)||l.length!==2)throw Cn(this.key,"each gradient stop is [colour, offset]");return l};for(let a=0;a<xu;a++)this.color(r(a)[0]);for(let a=0;a<xu;a++)this.float(r(a)[1]);let o=e.from??[0,0],s=e.to??[0,1];if(!Array.isArray(o)||o.length!==2||!Array.isArray(s)||s.length!==2)throw Cn(this.key,"gradient from and to are [x, y] points");this.float(o[0]),this.float(o[1]),this.float(s[0]),this.float(s[1]);}};function Pze(i,e,t,n){let r=new UF(i),o=Fl(n);if(o&&(e===Be.shadow||e===Be.gradient))throw Cn(i,"a variable can fill a colour or a number inside a shadow or gradient, not the whole value");switch(e){case Be.length:r.length(n);break;case Be.float:r.float(n);break;case Be.int:r.int(n);break;case Be.color:r.color(n);break;case Be.enumeration:r.enumeration(n,t);break;case Be.bool:r.bool(n);break;case Be.edges:r.repeat(n,4,s=>r.float(s),"an edge value");break;case Be.pair:r.repeat(n,2,s=>r.float(s),"a pair");break;case Be.colors:r.repeat(n,4,s=>r.color(s),"a border colour");break;case Be.quad:if(!Array.isArray(n)&&!o)throw Cn(i,"takes four numbers");r.repeat(n,4,s=>r.float(s),"a quad");break;case Be.shadow:r.shadow(n);break;case Be.gradient:r.gradient(n);break}if(r.words.length!==Dce[e])throw Cn(i,"encoded to the wrong width");return r}function Su(i){if(!XT(i))throw new Sr("a style is an object of style properties","value","style",null);let e=new Map;for(let[r,o]of Object.entries(i)){if(o===void 0)continue;let s=Ll(r);if(s<0)throw kze(r);let a=new Map;FF(r,o,0,a),e.delete(s),e.set(s,a);for(let l of Kce[s])e.delete(l),e.set(l,new Map([[0,null]]));}let t=[...e.keys()].sort((r,o)=>r-o),n=[BF,t.length|GF<<iue];for(let r of t){let o=e.get(r),s=[...o.keys()].sort((l,c)=>l-c);n.push(r|s.length<<tue);let a=ua[r];for(let l of s){let c=o.get(l);if(c===null){n.push(l|Ul.null<<PF);continue}let u=Pze(SF[r],a,VT[r],c),d=u.refs===0?Ul.literal:Ul.referenced;n.push((l|u.words.length<<nue|d<<PF|u.unit<<rue)>>>0),d===Ul.referenced&&n.push(u.refs);for(let h of u.words)n.push(h>>>0);}}return Uint32Array.from(n)}function HF(i){if(i.length<Jce||i[0]>>>0!==BF)throw new fn("compiled style data is not a style block");let e=i[1]>>>iue;if(e!==GF)throw new fn(`compiled style block version ${e} is not supported; rebuild with this SDK`);let t=i[1]&Cze,n=[],r=Jce;for(let o=0;o<t;o++){let s=i[r++],a=s&YT,l=s>>>tue&YT;for(let c=0;c<l;c++){let u=i[r++],d=u>>>PF&Zce,h=u>>>nue&YT,p=d===Ul.referenced?i[r++]:0,m=[];for(let f=0;f<h;f++)m.push(i[r++]>>>0);n.push({key:a,mask:u&YT,kind:d,unit:u>>>rue&Zce,refs:p,payload:m});}}if(r!==i.length)throw new fn("compiled style block has trailing words");return n}function aue(i,e,t){return Ml(i,e)?Lze(t):i===Be.int?t|0:t>>>0}var lue={surface:"#141821e6",raised:"#222a38ff",border:"#ffffff1f",accent:"#f5b833ff",on_accent:"#1a1205ff",text:"#f4f6faff",muted:"#a6aebcff",track:"#ffffff26",danger:"#ef4b4bff",success:"#3ccf7aff",gold:"#ffd447ff"};var cue="ui";function Uze(i){return {surface:i.surface,raised:i.raised,border:i.border,accent:i.accent,onAccent:i.on_accent,text:i.text,muted:i.muted,track:i.track,danger:i.danger,success:i.success,gold:i.gold}}var WF=DF(cue,Uze(lue));var Bze=4,pue=["0","0.5","1","1.5","2","2.5","3","3.5","4","5","6","7","8","9","10","11","12","14","16","20","24","28","32","36","40","44","48","52","56","60","64","72","80","96"],Gze=new Set(pue),mue=["1/2","1/3","2/3","1/4","2/4","3/4","1/5","2/5","3/5","4/5","1/6","5/6"],Jy=100,Vze="100%",pa="auto",jT="px",KF={none:0,sm:2,"":4,md:6,lg:8,xl:12,"2xl":16,"3xl":24,full:9999},YF={"":1,0:0,2:2,4:4,8:8},XF=5,uue=["0","10","20","30","40","50","auto"],fue=["0","50","75","90","95","100","105","110","125","150"],due=["0","1","2","3","6","12","45","90","180"],Hze=Math.PI/180,Wze={xs:12,sm:14,base:16,lg:18,xl:20,"2xl":24,"3xl":30,"4xl":36,"5xl":48,"6xl":60,"7xl":72},Kze={thin:100,extralight:200,light:300,normal:400,medium:500,semibold:600,bold:700,extrabold:800,black:900},qF={none:1,tight:1.25,snug:1.375,normal:1.5,relaxed:1.625,loose:2},qT="#0000001a",Yze={sm:{color:"#0000000d",x:0,y:1,blur:2,spread:0},"":{color:qT,x:0,y:1,blur:3,spread:0},md:{color:qT,x:0,y:4,blur:6,spread:-1},lg:{color:qT,x:0,y:10,blur:15,spread:-3},xl:{color:qT,x:0,y:20,blur:25,spread:-5},"2xl":{color:"#00000040",x:0,y:25,blur:50,spread:-12},none:null},Xze={center:[.5,.5],top:[.5,0],"top-right":[1,0],right:[1,.5],"bottom-right":[1,1],bottom:[.5,1],"bottom-left":[0,1],left:[0,.5],"top-left":[0,0]},QF={t:[.5,1,.5,0],tr:[0,1,1,0],r:[0,.5,1,.5],br:[0,0,1,1],b:[.5,0,.5,1],bl:[1,0,0,1],l:[1,.5,0,.5],tl:[1,1,0,0]},qze=[.5,.5,.5,0],zze=.5,jF={white:"#ffffffff",black:"#000000ff",transparent:"#00000000"},hue=jF.transparent,$F={pressed:Ne.pressed,active:Ne.pressed,focus:Ne.focus,disabled:Ne.disabled,landscape:Ne.landscape,portrait:Ne.portrait,safe:Ne.safe,sm:Ne.sm,lg:Ne.lg},_ue=[":pressed",":focus",":disabled","@landscape","@portrait","@safe","@sm","@lg"];function Qze(i){return i.replace(/[A-Z]/g,e=>`-${e.toLowerCase()}`)}var JF=new Map;for(let[i,e]of Object.entries(WF))JF.set(Qze(i),e);var QT=[...JF.keys(),...Object.keys(jF)];function ZF(i){return i.length>2&&i.startsWith("[")&&i.endsWith("]")?i.slice(1,-1):null}function mo(i){let e=ZF(i);if(e===null)return null;let t=e.endsWith(jT)?e.slice(0,-jT.length):e,n=Number(t);return t.length>0&&Number.isFinite(n)?n:null}function yue(i){return i===jT?1:Gze.has(i)?Number(i)*Bze:mo(i)}function $ze(i){if(i==="full")return Vze;if(i===pa)return pa;let e=i.indexOf("/");if(e>0&&mue.indexOf(i)>=0)return `${Number(i.slice(0,e))/Number(i.slice(e+1))*Jy}%`;let t=ZF(i);return t!==null&&t.endsWith("%")&&Number.isFinite(Number(t.slice(0,-1)))?t:yue(i)}function $T(i){let e=JF.get(i);if(e!==void 0)return e;let t=jF[i];if(t!==void 0)return t;let n=ZF(i);return n!==null&&n.startsWith("#")?n:null}function jze(i){return fue.indexOf(i)>=0?Number(i)/Jy:mo(i)}var Zy=(i,e)=>i?-e:e,Aue=()=>[jT,...pue],Jze=()=>[...Aue(),...mue,"full",pa];function da(i,e){return {prefix:i,values:()=>[""],apply:(t,n)=>t!==""?false:(e(n),true)}}function Dt(i,e,t){return {prefix:i,values:()=>Object.keys(e),apply:(n,r)=>Object.prototype.hasOwnProperty.call(e,n)?(t(e[n],r),true):false}}function En(i,e,t){return {prefix:i,negative:t,values:Aue,apply:(n,r,o)=>{let s=yue(n);if(s===null)return false;for(let a of e)r.set(a,Zy(o,s));return true}}}function or(i,e,t){return {prefix:i,negative:t,values:Jze,apply:(n,r,o)=>{let s=$ze(n);if(s===null||o&&s===pa)return false;let a=typeof s=="number"?Zy(o,s):o?`-${s}`:s;for(let l of e)r.set(l,a);return true}}}function jr(i,e){return {prefix:i,values:()=>QT,apply:(t,n)=>{let r=$T(t);if(r===null)return false;for(let o of e)n.set(o,r);return true}}}function Tu(i,e){return {prefix:i,values:()=>Object.keys(YF),apply:(t,n)=>{let r=Object.prototype.hasOwnProperty.call(YF,t)?YF[t]:mo(t);return r===null?false:(n.set(e,r),true)}}}function ha(i,e){return {prefix:i,values:()=>Object.keys(KF),apply:(t,n)=>{let r=Object.prototype.hasOwnProperty.call(KF,t)?KF[t]:mo(t);if(r===null)return false;for(let o of e)n.set(o,r);return true}}}function zF(i,e){return {prefix:i,values:()=>fue,apply:(t,n)=>{let r=jze(t);if(r===null)return false;for(let o of e)n.set(o,r);return true}}}var bue=[da("flex",i=>i.set("display","flex")),da("hidden",i=>i.set("display","none")),da("invisible",i=>i.set("hidden",true)),da("visible",i=>i.set("hidden",false)),Dt("flex",{row:"row",col:"column","row-reverse":"row-reverse","col-reverse":"column-reverse"},(i,e)=>e.set("direction",i)),Dt("flex",{wrap:true,nowrap:false},(i,e)=>e.set("wrap",i)),Dt("flex",{1:[1,1,"0%"],auto:[1,1,pa],initial:[0,1,pa],none:[0,0,pa]},(i,e)=>{e.set("grow",i[0]),e.set("shrink",i[1]),e.set("basis",i[2]);}),da("grow",i=>i.set("grow",1)),Dt("grow",{0:0},(i,e)=>e.set("grow",i)),da("shrink",i=>i.set("shrink",1)),Dt("shrink",{0:0},(i,e)=>e.set("shrink",i)),or("basis",["basis"],false),Dt("justify",{start:"start",end:"end",center:"center",between:"space-between",around:"space-around",evenly:"space-evenly"},(i,e)=>e.set("justify",i)),Dt("items",{start:"start",end:"end",center:"center",stretch:"stretch"},(i,e)=>e.set("alignItems",i)),Dt("self",{auto:"auto",start:"start",end:"end",center:"center",stretch:"stretch"},(i,e)=>e.set("alignSelf",i)),Dt("content",{start:"start",end:"end",center:"center",stretch:"stretch"},(i,e)=>e.set("alignContent",i)),da("absolute",i=>i.set("position","absolute")),da("relative",i=>i.set("position","relative")),Dt("overflow",{hidden:true,visible:false,clip:true},(i,e)=>e.set("clip",i)),Dt("overflow",{scroll:"both",auto:"both"},(i,e)=>e.set("scrollAxes",i)),Dt("overflow-x",{scroll:"x",auto:"x"},(i,e)=>e.set("scrollAxes",i)),Dt("overflow-y",{scroll:"y",auto:"y"},(i,e)=>e.set("scrollAxes",i)),Dt("pointer-events",{none:"none",auto:"auto"},(i,e)=>e.set("pointerEvents",i)),{prefix:"aspect",values:()=>["square","video"],apply:(i,e)=>{let t=i==="square"?1:i==="video"?1.7777777777777777:mo(i);return t===null?false:(e.set("aspect",t),true)}},{prefix:"z",negative:true,values:()=>uue,apply:(i,e,t)=>{let n=i===pa?0:uue.indexOf(i)>=0?Number(i):mo(i);return n===null||!Number.isInteger(n)?false:(e.set("zIndex",Zy(t,n)),true)}},{prefix:"opacity",values:()=>Array.from({length:Jy/XF+1},(i,e)=>String(e*XF)),apply:(i,e)=>{let t=Number(i),n=i.length>0&&Number.isInteger(t)&&t>=0&&t<=Jy&&t%XF===0?t/Jy:mo(i);return n===null?false:(e.set("opacity",n),true)}},En("p",["padding"],false),En("px",["paddingInline"],false),En("py",["paddingBlock"],false),En("pt",["paddingTop"],false),En("pr",["paddingRight"],false),En("pb",["paddingBottom"],false),En("pl",["paddingLeft"],false),En("m",["margin"],true),En("mx",["marginInline"],true),En("my",["marginBlock"],true),En("mt",["marginTop"],true),En("mr",["marginRight"],true),En("mb",["marginBottom"],true),En("ml",["marginLeft"],true),En("gap",["gap"],false),En("gap-x",["columnGap"],false),En("gap-y",["rowGap"],false),or("w",["width"],false),or("h",["height"],false),or("min-w",["minWidth"],false),or("min-h",["minHeight"],false),or("max-w",["maxWidth"],false),or("max-h",["maxHeight"],false),or("size",["width","height"],false),or("inset",["inset"],true),or("inset-x",["insetInline"],true),or("inset-y",["insetBlock"],true),or("top",["top"],true),or("right",["right"],true),or("bottom",["bottom"],true),or("left",["left"],true),ha("rounded",["radius"]),ha("rounded-t",["radiusTopLeft","radiusTopRight"]),ha("rounded-r",["radiusTopRight","radiusBottomRight"]),ha("rounded-b",["radiusBottomRight","radiusBottomLeft"]),ha("rounded-l",["radiusTopLeft","radiusBottomLeft"]),ha("rounded-tl",["radiusTopLeft"]),ha("rounded-tr",["radiusTopRight"]),ha("rounded-br",["radiusBottomRight"]),ha("rounded-bl",["radiusBottomLeft"]),Tu("border","borderWidth"),Tu("border-x","borderInlineWidth"),Tu("border-y","borderBlockWidth"),Tu("border-t","borderTopWidth"),Tu("border-r","borderRightWidth"),Tu("border-b","borderBottomWidth"),Tu("border-l","borderLeftWidth"),jr("border",["borderColor"]),jr("border-x",["borderInlineColor"]),jr("border-y",["borderBlockColor"]),jr("border-t",["borderTopColor"]),jr("border-r",["borderRightColor"]),jr("border-b",["borderBottomColor"]),jr("border-l",["borderLeftColor"]),jr("bg",["fill"]),jr("fill",["fill"]),jr("tint",["tint"]),jr("stroke",["stroke"]),Dt("stroke",{0:0,1:1,2:2},(i,e)=>e.set("strokeWidth",i)),jr("placeholder",["placeholderColor"]),jr("text",["textColor"]),Dt("text",Wze,(i,e)=>e.set("fontSize",i)),{prefix:"text",values:()=>[],apply:(i,e)=>{let t=mo(i);return t===null?false:(e.set("fontSize",t),true)}},Dt("text",{left:"left",center:"center",right:"right",start:"start",end:"end"},(i,e)=>e.set("textAlign",i)),Dt("text",{wrap:true,nowrap:false},(i,e)=>e.set("textWrap",i)),Dt("text",{balance:"balance",pretty:"pretty"},(i,e)=>{e.set("textWrap",true),e.set("textWrapStyle",i);}),Dt("font",Kze,(i,e)=>e.set("fontWeight",i)),{prefix:"leading",values:()=>Object.keys(qF),apply:(i,e)=>{let t=Object.prototype.hasOwnProperty.call(qF,i)?qF[i]:mo(i);return t===null?false:(e.set("lineHeight",t),true)}},{prefix:"tracking",negative:true,values:()=>[],apply:(i,e,t)=>{let n=mo(i);return n===null?false:(e.set("letterSpacing",Zy(t,n)),true)}},Dt("align",{top:"top",middle:"center",bottom:"bottom"},(i,e)=>e.set("verticalAlign",i)),zF("scale",["scale"]),zF("scale-x",["scaleX"]),zF("scale-y",["scaleY"]),{prefix:"rotate",negative:true,values:()=>due,apply:(i,e,t)=>{let n=due.indexOf(i)>=0?Number(i):mo(i);return n===null?false:(e.set("rotate",Zy(t,n)*Hze),true)}},En("translate-x",["translateX"],true),En("translate-y",["translateY"],true),Dt("origin",Xze,(i,e)=>e.set("origin",i)),Dt("shadow",Yze,(i,e)=>e.set("shadow",i)),Dt("bg-gradient-to",QF,(i,e)=>{e.gradient.kind="linear",e.gradient.geometry=i;}),Dt("bg-linear-to",QF,(i,e)=>{e.gradient.kind="linear",e.gradient.geometry=i;}),da("bg-radial",i=>{i.gradient.kind="radial",i.gradient.geometry=qze;}),{prefix:"from",values:()=>QT,apply:(i,e)=>{let t=$T(i);return t===null?false:(e.gradient.from=t,true)}},{prefix:"via",values:()=>QT,apply:(i,e)=>{let t=$T(i);return t===null?false:(e.gradient.via=t,true)}},{prefix:"to",values:()=>QT,apply:(i,e)=>{let t=$T(i);return t===null?false:(e.gradient.to=t,true)}}],Zze=[...bue].sort((i,e)=>e.prefix.length-i.prefix.length),zT=null;function gue(){if(zT!==null)return zT;let i=new Set;for(let e of bue)for(let t of e.values()){let n=t===""?e.prefix:`${e.prefix}-${t}`;i.add(n),e.negative===true&&t!==""&&t!=="0"&&t!==pa&&i.add(`-${n}`);}for(let e of Object.keys($F))i.add(`${e}:`);return zT=[...i],zT}function eQe(i){let e=[],t=0,n=0;for(let r=0;r<i.length;r++){let o=i[r];o==="["?t++:o==="]"?t--:o===":"&&t===0&&(e.push(i.slice(n,r)),n=r+1);}return e.push(i.slice(n)),e}function tQe(i,e){let t=i.startsWith("-"),n=t?i.slice(1):i;for(let r of Zze){if(t&&r.negative!==true)continue;let o=null;if(n===r.prefix?o="":n.startsWith(`${r.prefix}-`)&&(o=n.slice(r.prefix.length+1)),o!==null&&r.apply(o,e,t))return true}return false}function Eue(i,e,t){if(e.length===0){i.default=t;return}let n=_ue[e[0]],r=i[n]??{};i[n]=r,Eue(r,e.slice(1),t);}function nQe(i){let e=[];for(let t=0;t<_ue.length;t++)i&1<<t&&e.push(t);return e}function rQe(i){let e=i.geometry??QF.b,t=i.from??hue,n=i.to??hue,r=i.via===void 0?[[t,0],[n,1]]:[[t,0],[i.via,zze],[n,1]];return {kind:i.kind??"linear",stops:r,from:[e[0],e[1]],to:[e[2],e[3]]}}function xue(i){let e=new Map,t=new Map,n=s=>(a,l)=>{let c=e.get(a);c===void 0&&(c=new Map,e.set(a,c)),c.delete(s),c.set(s,l);};for(let s of i.split(/\s+/)){if(s.length===0)continue;let a=eQe(s),l=a[a.length-1],c=0;for(let d=0;d<a.length-1;d++){let h=$F[a[d]];if(h===void 0){let p=Dl(a[d],Object.keys($F));throw new Sr(`unknown variant "${a[d]}:" in "${s}"${p===null?"":`; did you mean "${p}:"?`}`,"class",s,p===null?null:`${p}:${l}`)}c|=h;}if(l.length===0)throw new Sr(`class "${s}" has no utility after its variants`,"class",s,null);let u=t.get(c);if(u===void 0&&(u={},t.set(c,u)),!tQe(l,{set:n(c),gradient:u})){let d=Dl(l,gue()),h=a.slice(0,-1).map(p=>`${p}:`).join("");throw new Sr(`unknown class "${s}"${d===null?"":`; did you mean "${h}${d}"?`}`,"class",s,d===null?null:`${h}${d}`)}}for(let[s,a]of t)a.kind===void 0&&a.from===void 0&&a.via===void 0&&a.to===void 0||n(s)("gradient",rQe(a));let r={},o=[...e].sort((s,a)=>Xy[Ll(s[0])]-Xy[Ll(a[0])]);for(let[s,a]of o){if(a.size===1&&a.has(0)){r[s]=a.get(0);continue}let l={};for(let c of [...a.keys()].sort((u,d)=>u-d))Eue(l,nQe(c),a.get(c));r[s]=l;}return r}function eU(i){return Su(xue(i))}var Op=-1,Due=1,eA=2,vue=65535,iQe="%",Rue=0,Sue=1,Tue=2,Pue=new Float32Array(1),oQe=new Uint32Array(Pue.buffer),sQe="auto",Tr=class{constructor(e){this.first=new Int16Array(po).fill(Op);this.count=new Uint8Array(po);this.variantKey=new Uint8Array(0);this.mask=new Uint8Array(0);this.priority=new Uint16Array(0);this.empty=new Uint8Array(0);this.unit=new Uint8Array(0);this.start=new Uint16Array(0);this.values=new Float64Array(0);this.refKind=new Uint8Array(0);this.refId=new Int32Array(0);this.stateMask=0;this.contextMask=0;this.usesVars=false;this.slots=0;this.version=0;this.slotPos=new Int32Array(0);this.slotFloat=new Uint8Array(0);this.slotRefPos=new Int32Array(0);this.slotRefSlot=new Int32Array(0);this.slotRefMode=new Uint8Array(0);this.load(e);}slotBits(e){let t=this.values[this.slotPos[e]];return this.slotFloat[e]===1?Ru(t):t>>>0}load(e){let t=HF(e),n=t.length,r=0;for(let c of t)r+=c.payload.length;this.first.fill(Op),this.count.fill(0),this.variantKey=new Uint8Array(n),this.mask=new Uint8Array(n),this.priority=new Uint16Array(n),this.empty=new Uint8Array(n),this.unit=new Uint8Array(n),this.start=new Uint16Array(n),this.values=new Float64Array(r),this.refKind=new Uint8Array(r),this.refId=new Int32Array(r),this.stateMask=0,this.contextMask=0,this.usesVars=false,this.slots=0;let o=0;t.forEach((c,u)=>{this.first[c.key]===Op&&(this.first[c.key]=u),this.count[c.key]++,this.variantKey[u]=c.key,this.mask[u]=c.mask,this.priority[u]=Xy[c.key]+qy(c.mask),this.empty[u]=c.kind===Ul.null?1:0,this.unit[u]=c.unit,this.start[u]=o,this.stateMask|=c.mask&wF,this.contextMask|=c.mask&IF;let d=ua[c.key];c.payload.forEach((h,p)=>{let m=o+p;if(c.refs&1<<p){h&jy?(this.refKind[m]=eA,this.refId[m]=h&vue,this.slots=Math.max(this.slots,(h&vue)+1)):(this.refKind[m]=Due,this.refId[m]=h,this.usesVars=true);return}this.values[m]=aue(d,p,h);}),o+=c.payload.length;}),this.slotPos=new Int32Array(this.slots).fill(-1),this.slotFloat=new Uint8Array(this.slots);for(let c=0;c<n;c++){let u=this.start[c],d=c+1<n?this.start[c+1]:r;for(let h=u;h<d;h++){if(this.refKind[h]!==eA||this.slotPos[this.refId[h]]>=0)continue;let p=ua[this.variantKey[c]];this.slotPos[this.refId[h]]=h,this.slotFloat[this.refId[h]]=Ml(p,h-u)?1:0;}}let s=[],a=[],l=[];for(let c=0;c<n;c++){let u=this.start[c],d=c+1<n?this.start[c+1]:r,h=ua[this.variantKey[c]];for(let p=u;p<d;p++){if(this.refKind[p]!==eA)continue;let m=p-u;s.push(p),a.push(this.refId[p]),l.push(BT(h,m)?Tue:Ml(h,m)?Rue:h===Be.int?Sue:Tue);}}this.slotRefPos=Int32Array.from(s),this.slotRefSlot=Int32Array.from(a),this.slotRefMode=Uint8Array.from(l),this.version++;}keySignature(){let e="";for(let t=0;t<po;t++)this.first[t]!==Op&&(e+=`${t},`);return e}setSlotsFrom(e,t=0){let n=this.slotRefPos,r=this.slotRefSlot,o=this.slotRefMode,s=this.values;for(let a=0;a<n.length;a++){let l=o[a],c=e[t+r[a]];s[n[a]]=l===Rue?c:l===Sue?c|0:c>>>0;}return this}slotBitsTo(e,t,n){let r=this.values[this.slotPos[e]];this.slotFloat[e]===1?(Pue[0]=r,t[n]=oQe[0]):t[n]=r>>>0;}setSlot(e,t){let n=this.values.length;for(let r=0;r<this.variantKey.length;r++){let o=this.start[r],s=r+1<this.variantKey.length?this.start[r+1]:n;for(let a=o;a<s;a++){if(this.refKind[a]!==eA||this.refId[a]!==e)continue;let l=this.variantKey[r];Fue(l,a-o,t),this.values[a]=Bl[0],ua[l]===Be.length&&typeof t=="string"&&this.unit[r]!==Cp&&(this.unit[r]=Cp,this.version++);}}}},Bl=new Float64Array(1),Cp=In.points;function Fue(i,e,t){let n=ua[i];if(Cp=In.points,BT(n,e)){Bl[0]=typeof t=="number"?t>>>0:Un(t);return}if(typeof t=="number"){Bl[0]=Ml(n,e)?t:n===Be.int?t|0:t>>>0;return}if(typeof t=="boolean"){Bl[0]=t?1:0;return}if(n===Be.enumeration){let o=VT[i][t];if(o===void 0)throw new fn(`style variable value ${t} is not valid here`);Bl[0]=o;return}if(n===Be.length&&t===sQe){Cp=In.auto,Bl[0]=0;return}n===Be.length&&t.endsWith(iQe)&&(Cp=In.percent);let r=Number.parseFloat(t);Bl[0]=Ml(n,e)?r:n===Be.int?r|0:r>>>0;}var fo=class i{constructor(e){this.owner=new Array(po).fill(null);this.wireSet=new Uint8Array(wp);this.encoded=null;this.encodedVersion=-1;let t=[];for(let c of e){if(c instanceof cs){t.push(c);continue}if(c instanceof i){c.theme!==null&&t.push(c.theme);for(let u=0;u<po;u++)c.owner[u]!==null&&(this.owner[u]=c.owner[u]);continue}for(let u=0;u<po;u++)c.first[u]!==Op&&(this.owner[u]=c);}let n=new Set,r=0,o=0,s=false;for(let c=0;c<po;c++){let u=this.owner[c];if(u===null)continue;for(let h of qce[c])n.add(h);let d=u.first[c];for(let h=d;h<d+u.count[c];h++)r|=u.mask[h]&wF,o|=u.mask[h]&IF;s||=u.usesVars;}this.wires=Uint8Array.from([...n].sort((c,u)=>c-u));for(let c of this.wires)this.wireSet[c]=1;let a=[];for(let c=0;c<po;c++){let u=this.owner[c];u!==null&&a.indexOf(u)<0&&a.push(u);}this.styles=a,this.dynamics=a.filter(c=>c.slots>0),this.slotOffsets=new Int32Array(this.dynamics.length);let l=0;this.dynamics.forEach((c,u)=>{this.slotOffsets[u]=l,l+=c.slots;}),this.slotCount=l,this.stateMask=r,this.contextMask=o,this.usesVars=s,this.theme=t.length===0?null:t.length===1?t[0]:jce(t);}version(){let e=0;for(let t=0;t<this.styles.length;t++)e+=this.styles[t].version;return e}slotOffset(e){for(let t=0;t<this.dynamics.length;t++)if(this.dynamics[t]===e)return this.slotOffsets[t];return 0}},wue=new Map,Iue=new WeakMap;function JT(i){return i instanceof Uint32Array||Array.isArray(i)&&typeof i[0]=="number"}function Uue(i){if(i instanceof Tr||i instanceof fo||i instanceof cs)return i;if(typeof i=="string"){let t=wue.get(i);return t===void 0&&(t=new Tr(eU(i)),wue.set(i,t)),t}let e=Iue.get(i);return e===void 0&&(e=new Tr(JT(i)?i:Su(i)),Iue.set(i,e)),e}var ZT=class{constructor(){this.next=null;this.result=null;}},Bue=new ZT,Gue=new fo([]);Bue.result=Gue;function Vue(i){return Array.isArray(i)&&!JT(i)}function ma(i,e){if(e===false||e===null||e===void 0)return i;if(Vue(e)){let o=i;for(let s=0;s<e.length;s++)o=ma(o,e[s]);return o}let t=typeof e=="string"||e instanceof Tr||e instanceof fo||e instanceof cs?e:Uue(e),n=i.next;n===null&&(n=new Map,i.next=n);let r=n.get(t);return r===void 0&&(r=new ZT,n.set(t,r)),r}function Hue(i,e){if(!(i===false||i===null||i===void 0)){if(Vue(i)){for(let t of i)Hue(t,e);return}e.push(Uue(i));}}function Wue(i,e,t,n,r,o,s,a){let l=ma(Bue,i);if(l=ma(l,e),l=ma(l,t),l=ma(l,n),l=ma(l,r),l=ma(l,o),l=ma(l,s),l=ma(l,a),l.result!==null)return l.result;let c=[];return Hue([i,e,t,n,r,o,s,a],c),l.result=c.length===1&&c[0]instanceof fo?c[0]:new fo(c),l.result}function Kue(i,e){throw e instanceof Sr?new Sr(`styles.${i}: ${e.message}`,e.kind,e.subject,e.suggestion):e}function aQe(i){let e=new Tr(i[0]),t=i[1];return (n,r,o,s)=>{for(let a=0;a<t.length;a++)e.setSlot(a,t[a](n,r,o,s));return e}}function lQe(i,e){let t=null,n="";return (r,o,s,a)=>{let l;try{l=Su(e(r,o,s,a));}catch(c){Kue(i,c);}if(t===null)return t=new Tr(l),n=t.keySignature(),t;if(t.load(l),t.keySignature()!==n)throw new fn(`styles.${i}: a dynamic style must return the same properties on every call`);return t}}function Yue(i,e){let t={},n=new Set([...Object.keys(i),...Object.keys(e??{})]);for(let r of n){let o=e?.[r],s=i[r];if(o!==void 0&&!JT(o)&&typeof o[1]=="function"){let a=new Tr(o[0]);t[r]=o[1](a,new Float64Array(Math.max(1,a.slots)));continue}if(o!==void 0&&!JT(o)){t[r]=aQe(o);continue}if(o!==void 0){t[r]=new Tr(o);continue}if(typeof s=="function"){t[r]=lQe(r,s);continue}try{t[r]=new Tr(Su(s));}catch(a){Kue(r,a);}}return t}var nU={color:1,float:2};var Oue=new Map,ew=[],rU=[],tw=null,iU=false,Cue=null;function cQe(i,e){return BT(i,e)?nU.color:i!==Be.length&&Ml(i,e)?nU.float:0}function uQe(i,e){if(e===0)return false;let t=Oue.get(i);if(t===void 0)Oue.set(i,e);else if(t!==e)return false;return ew.indexOf(i)<0&&(ew.push(i),rU.push(e)),true}function Xue(i,e){return i===nU.color?typeof e=="number"?e>>>0:Un(e):Ru(typeof e=="number"?e:Number.parseFloat(e))}var Si=new Float64Array(MF),dQe=new Float64Array(2),Nue=new Float64Array(4),kue=new Float64Array(1),hQe=new Float64Array(4),pQe=new Float64Array(0),fa=0,tA=false,Gl=0,nA=0;var mQe=4,fQe=5;function _Qe(i,e,t,n,r){let o=i.start[e]+t;fa=i.unit[e];let s=i.refKind[o];if(s===eA&&tA&&tw!==null){Si[r]=(jy|tw.slotOffset(i)+i.refId[o])>>>0,Gl|=1<<r;return}if(s!==Due){Si[r]=i.values[o];return}let a=i.refId[o];if(tA){if(n.scopedVar(a)===void 0&&uQe(a,cQe(ua[i.variantKey[e]],t))){Si[r]=a,Gl|=1<<r;return}iU=true;}let l=n.resolveVar(a)??$y(a);if(l===void 0)throw new fn(`style variable ${a} has no value; define it with defineVars`);Fue(i.variantKey[e],t,l),Si[r]=Bl[0],fa=Cp;}function yQe(i,e){return i===G.padding||i===G.margin?e:i>=G.inset_top&&i<=G.inset_left?i-G.inset_top:-1}function que(i,e,t,n){let r=WT[e],o=Ip[e],s=false;Gl=0,nA=0,fa=CF[e];let a=fa;for(let l=0;l<o;l++){let c=r+l,u=NF[c],d=u+kF[c],h=-1,p=null,m=Op,f=0;for(let y=u;y<d;y++){let b=LF[y],A=i[b];if(A===null)continue;let E=A.first[b],R=E+A.count[b];for(let g=E;g<R;g++)A.empty[g]===1||(A.mask[g]&~t)!==0||A.priority[g]>=h&&(h=A.priority[g],p=A,m=g,f=Xce[y]);}if(p===null){Si[l]=Yce[c];continue}if(s=true,_Qe(p,m,f,n,l),(p.mask[m]&Ne.safe)!==0){let y=yQe(HT[e],l);y>=0&&(Qy[e]!==_e.length||fa===In.points)&&(tA?nA|=1<<l:Cue!==null);}a=fa;}return fa=a,s}function tU(i,e,t){for(let n=0;n<t;n++)i[n]=Si[e+n];return i}function zue(i,e){let t=Qy[e];if(t===_e.flag)return;que(Gue.owner,e,0,i);let n=HT[e],{writer:r,id:o}=i;switch(i.cache.forget(n),t){case _e.length:r.propFloatAt(o,n,Si,0,fa);return;case _e.float:r.propFloatAt(o,n,Si,0);return;case _e.word:r.propWordAt(o,n,Si,0);return;case _e.floats:{let s=Ip[e];r.propFloats(o,n,tU(s===2?dQe:Nue,0,s));return}case _e.words:r.propWords(o,n,tU(hQe,0,4));return;case _e.shadow:kue[0]=Si[0],r.propMixed(o,n,kue,tU(Nue,1,mQe));return;case _e.gradient:r.propWords(o,n,pQe);return}}var Que=1<<24,$ue=1<<25,AQe=8,bQe=16,Lue=64,gQe={writer:null,cache:null,id:0,resolveVar:()=>{},scopedVar:()=>{},setLayer:()=>{}};function EQe(i,e){let t=[0],n=WT[e];for(let r=n;r<n+Ip[e];r++){let o=NF[r];for(let s=o;s<o+kF[r];s++){let a=LF[s],l=i[a];if(l!==null)for(let c=l.first[a];c<l.first[a]+l.count[a];c++){let u=l.mask[c];if(l.empty[c]===1||u===0||t.indexOf(u)>=0)continue;let d=t.length;for(let h=0;h<d;h++)t.indexOf(t[h]|u)<0&&t.push(t[h]|u);if(t.length>Lue)throw new fn(`a style property combines more than ${Lue} condition sets; split it across elements`)}}}return t}function xQe(i,e){return i===_e.length||i===_e.float||i===_e.floats?true:i===_e.shadow?e>0:i===_e.gradient?e>=fQe:false}function vQe(i,e){let t=Qy[e],n=Ip[e],r=Gl!==0,o=nA!==0,s=t===_e.length?fa:0;i.push((HT[e]|s<<AQe|n<<bQe|(r?Que:0)|(o?$ue:0))>>>0),r&&i.push(Gl>>>0),o&&i.push(nA>>>0);for(let a=0;a<n;a++){let l=Si[a];i.push((Gl&1<<a)!==0?l>>>0:xQe(t,a)?Ru(l):l>>>0);}}function Mue(i,e){let t=[],n=new Uint8Array(wp);tA=true,tw=i,iU=false,ew.length=0,rU.length=0;try{let r=Array.from(i.wires).filter(a=>Qy[a]!==_e.flag),o=r.map(a=>EQe(i.owner,a)),s=[...new Set(o.flat())].sort((a,l)=>qy(a)-qy(l)||a-l);for(let a of s){let l=[];for(let c=0;c<r.length;c++){let u=r[c];o[c].indexOf(a)<0||!que(i.owner,u,a,e)||(vQe(l,u),n[u]=1);}a!==0&&l.length===0||t.push({mask:a,words:Uint32Array.from(l)});}return {records:t,wires:n,tokenIds:Uint32Array.from(ew),tokenKinds:Uint8Array.from(rU),literal:iU}}finally{tA=false,tw=null,Gl=0,nA=0;}}function jue(i,e,t){let n=i.version(),r=i.encoded;return (r===null||i.encodedVersion!==n)&&(r=Mue(i,gQe),i.encoded=r,i.encodedVersion=n),t||r.literal?Mue(i,e):r}function Jue(i,e){return Yue(i,e)}var oU=Wue;var RQe=3,SQe=2,sU=Array.from({length:vT},()=>({shape:0,sibling:0,margin:0,x:0,y:0,width:0,height:0,points:null})),TQe=640,wQe=1024,IQe=new Set(["width","height","minWidth","minHeight","maxWidth","maxHeight","basis","top","right","bottom","left","padding","margin","borderWidth","gap","grow","shrink","aspect","direction","justify","alignItems","alignSelf","alignContent","position","wrap","display","fill","borderColor","radius","opacity","translate","scale","rotate","origin","zIndex","hidden","clip","pointerEvents","layer","shadow","gradient","fontFamily","fontWeight","fontSize","lineHeight","letterSpacing","textAlign","textColor","textWrap","verticalAlign","placeholderColor","tint","uv","nineSlice","nineSliceUv","shape","stroke","strokeWidth","scrollAxes","textWrapStyle"]);function OQe(i){if(typeof i!="object"||i===null||Array.isArray(i))return false;for(let e in i)if(e==="default"||e.startsWith(":")||e.startsWith("@"))return true;return false}function CQe(i){if(typeof i!="object"||i===null||Array.isArray(i)||ArrayBuffer.isView(i)||i instanceof Tr||i instanceof fo||i instanceof cs)return false;for(let e in i){if(!IQe.has(e))return false;let t=i[e];if(t instanceof Pl||OQe(t))return false}return true}function NQe(i,e){let t=i.records;for(let n=0;n<t.length;n++)if(t[n].mask===e)return true;return false}var sr=class extends Error{constructor(e){super(e),this.name="GameUiError";}},kQe=4096,LQe=4096,nw=-1,MQe=new Uint32Array(0),rw=new Uint32Array(1),DQe={},aU=400,PQe=[.5,1],Zue=[0,0],FQe=.25,UQe=2,BQe=.35,GQe=0,VQe=44,HQe={press:vi.press,release:vi.press,tap:vi.tap,long_press:vi.long_press,drag_start:vi.drag,drag_move:vi.drag,drag_end:vi.drag,scroll:0,focus:0,action:vi.tap,passthrough:0,change:0,blur:0,vector:0},ede=1,tde=0,WQe=new TextEncoder,nde=new Map;function rA(i){let e=nde.get(i);return e===void 0&&(e=WQe.encode(i),nde.set(i,e)),e}var KQe=new TextDecoder,YQe=(()=>{let i=[];for(let[e,t]of Object.entries(Eu))i[t]=e;return i})(),lU=class{constructor(e,t,n){this.ui=e;this.id=t;this.kind=n;this.cache=new CT;this.flags=0;this.listeners=null;this.alive=true;this.edited="";this.parentElement=null;this.kids=[];this.current=null;this.sent=null;this.sentVersion=-1;this.forced=false;this.focusable=false;this.slotBase=nw;this.slotSize=0;this.slotFresh=false;this.slotBits=null;this.stateBits=0;this.scope=null;}get writer(){return this.ui.writer}get props(){return this.current}get state(){return this.stateBits}resolveVar(e){let t=this;for(;t!==null;){let r=t.scope;if(r!==null){let o=r.values.get(e);if(o!==void 0)return o}t=t.parentElement;}let n=this.ui.rootTheme;if(n!==null){let r=n.values.get(e);if(r!==void 0)return r}return $y(e)}scopedVar(e){let t=this;for(;t!==null;){let n=t.scope;if(n!==null){let r=n.values.get(e);if(r!==void 0)return r}t=t.parentElement;}}scoped(){let e=this;for(;e!==null;){if(e.scope!==null)return true;e=e.parentElement;}return false}get perElement(){return this.sent!==null&&(this.sent.literal||this.sent!==this.current?.encoded)}setLayer(e){this.setFlag(vi.layer,e);}applyProps(e){let t=this.scope,n=this.current;if(this.current=e,this.scope=e.theme,(e.stateMask&Ne.pressed)!==0&&this.setFlag(vi.press,true),(e.stateMask&Ne.focus)!==0&&!this.focusable&&(this.focusable=true,this.ui.writer.propWord(this.id,G.focusable,1)),this.send(n,e),t!==this.scope)for(let r=0;r<this.kids.length;r++)this.kids[r].restyleVars();}send(e,t){let n=t.version();if(t!==e||this.sent===null||this.forced||n!==this.sentVersion){let r=jue(t,this,this.scoped());t.slotCount>this.slotSize&&this.allocateSlots(t.slotCount),this.ui.ensureTokens(r.tokenIds,r.tokenKinds);let o=this.ui.writer,s=this.sent;if(s!==null&&s!==r){let c=s.records;for(let u=0;u<c.length;u++){let d=c[u].mask;d!==0&&!NQe(r,d)&&o.style(this.id,d,MQe);}}let a=r.records,l=this.slotBase<0?0:this.slotBase;for(let c=0;c<a.length;c++)o.style(this.id,a[c].mask,a[c].words,l);if(s!==null&&s!==r){let c=s.wires,u=r.wires;for(let d=0;d<c.length;d++)c[d]===1&&u[d]===0&&zue(this,d);}this.sent=r,this.sentVersion=n,this.forced=false;}this.writeSlots(t);}allocateSlots(e){this.slotBase!==nw&&this.ui.freeSlots(this.slotBase,this.slotSize),this.slotBase=this.ui.allocateSlots(e),this.slotSize=e,this.slotBits=new Uint32Array(e),this.slotFresh=true;}writeSlots(e){let t=this.slotBits;if(t===null||e.slotCount===0)return;let n=e.dynamics;for(let r=0;r<n.length;r++){let o=n[r],s=e.slotOffsets[r];for(let a=0;a<o.slots;a++){o.slotBitsTo(a,rw,0);let l=s+a;!this.slotFresh&&t[l]===rw[0]||(t[l]=rw[0],this.ui.writer.slotAt(this.slotBase+l,rw,0));}}this.slotFresh=false;}active(){let e=0,t=this;for(;t!==null;)e|=t.stateBits,t=t.parentElement;return (e&Ne.disabled)!==0&&(e&=-4),e|this.ui.context}restyle(){this.current===null||!this.alive||(this.forced=true,this.send(this.current,this.current),this.ui.touched());}restyleVars(){this.current!==null&&this.current.usesVars&&this.restyle();for(let e=0;e<this.kids.length;e++)this.kids[e].restyleVars();}setState(e,t){let n=Ne[e],r=t?this.stateBits|n:this.stateBits&~n;return r===this.stateBits?this:(this.stateBits=r,e==="disabled"&&this.alive&&(this.ui.writer.propWord(this.id,G.disabled,t?1:0),this.ui.touched()),this)}get parent(){return this.parentElement}get children(){return this.kids}contains(e){let t=e.parentElement;for(;t!==null;){if(t===this)return true;t=t.parentElement;}return false}detach(){let e=this.parentElement;if(e===null)return;let t=e.kids.indexOf(this);t>=0&&e.kids.splice(t,1),this.parentElement=null;}adopt(e,t){if(e===this||e.contains(this))throw new sr(`inserting ui element ${e.id} would create a cycle`);e.parentElement!==null&&e.detach();let n=t===null?-1:this.kids.indexOf(t);n<0?this.kids.push(e):this.kids.splice(n,0,e),e.parentElement=this;}get destroyed(){return !this.alive}style(e){return this.ui.check(this),CQe(e)?(e.layer!==void 0&&this.setFlag(vi.layer,e.layer),kce(this.ui.writer,this.cache,this.id,e)):this.applyProps(e instanceof fo?e:oU(e)),this.ui.touched(),this}append(e){return this.ui.check(this),this.ui.check(e),this.adopt(e,null),this.ui.writer.insert(e.id,this.id,4294967295),this.ui.touched(),this}insertBefore(e,t){if(this.ui.check(this),this.ui.check(e),t.parentElement!==this)throw new sr(`ui element ${t.id} is not a child of ${this.id}`);return this.adopt(e,t),this.ui.writer.insert(e.id,this.id,t.id),this.ui.touched(),this}remove(){return this.ui.check(this),this.detach(),this.ui.writer.remove(this.id),this.ui.touched(),this}destroy(){this.alive&&(this.ui.release(this),this.alive=false);}get value(){return this.edited}accept(e){this.edited=e;}text(e){return this.ui.check(this),this.kind==="input"&&(this.edited=e),this.ui.writer.text(this.id,e),this.ui.touched(),this}textPrefix(e,t){return this.ui.check(this),this.ui.writer.textPrefix(this.id,e,t),this.ui.touched(),this}textRef(e){return this.ui.check(this),this.ui.writer.textRef(this.id,e),this.ui.touched(),this}number(e,t={}){this.ui.check(this);let n=t.separator===void 0?VQe:t.separator.length===0?GQe:t.separator.charCodeAt(0);return this.ui.writer.number(this.id,e,bce[t.format??"integer"],t.decimals??0,n),this.ui.touched(),this}placeholder(e){return this.ui.check(this),this.ui.writer.placeholder(this.id,e),this.ui.touched(),this}image(e,t,n){return this.ui.check(this),this.ui.writer.image(this.id,e,t,n),this.ui.touched(),this}path(e){return this.ui.check(this),this.ui.writer.path(this.id,e),this.ui.touched(),this}vector(e,t=0){return this.requireVector(),this.ui.writer.vector(this.id,e,t),this.ui.touched(),this}play(e,t){return this.requireVector(),this.ui.writer.vectorPlay(this.id,e,t),this.ui.touched(),this}seek(e,t,n){return this.requireVector(),this.ui.writer.vectorSeek(this.id,e,t,n),this.ui.touched(),this}setInput(e,t){this.requireVector();let n=typeof t=="boolean"?t?ede:tde:t;return typeof e=="number"?this.ui.writer.vectorInput(this.id,e,n):this.ui.writer.vectorInputName(this.id,rA(e),n),this.ui.touched(),this}setData(e,t){return this.requireVector(),typeof t=="boolean"?this.ui.writer.vectorData(this.id,Gy.bool,rA(e),t?ede:tde,0):this.ui.writer.vectorData(this.id,Gy.number,rA(e),t,0),this.ui.touched(),this}setDataColor(e,t){return this.requireVector(),this.ui.writer.vectorData(this.id,Gy.color,rA(e),0,t>>>0),this.ui.touched(),this}fireData(e){return this.requireVector(),this.ui.writer.vectorData(this.id,Gy.fire,rA(e),0,0),this.ui.touched(),this}detachVector(){return this.requireVector(),this.ui.writer.vectorDetach(this.id),this.ui.touched(),this}requireVector(){if(this.ui.check(this),this.kind!=="vector")throw new sr(`ui ${this.kind} ${this.id} is not a vector element; create it with ui.vector`)}flowAround(e){if(this.ui.check(this),this.kind==="image"||this.kind==="shape")throw new sr(`ui ${this.kind} ${this.id} cannot flow around shapes; use text, input, box or scroll`);let t=e===null?0:e.length;if(t>vT)throw new sr(`ui element ${this.id} flows around at most ${vT} shapes`);for(let n=0;n<t;n++)this.exclusionRecord(e[n],sU[n]);this.ui.writer.exclusions(this.id,sU,t);for(let n=0;n<t;n++)sU[n].points=null;return this.ui.touched(),this}exclusionRecord(e,t){if(t.margin=e.margin??0,t.sibling=4294967295,t.x=0,t.y=0,t.width=0,t.height=0,t.points=null,"rect"in e)t.shape=vp.rect,t.x=e.rect[0],t.y=e.rect[1],t.width=e.rect[2],t.height=e.rect[3];else if("circle"in e){let[n,r,o]=e.circle;t.shape=vp.ellipse,t.x=n-o,t.y=r-o,t.width=o*2,t.height=o*2;}else if("polygon"in e){if(e.polygon.length<RQe*SQe)throw new sr("an exclusion polygon needs at least three points");t.shape=vp.polygon,t.points=e.polygon,e.element!==void 0&&(t.sibling=this.exclusionTarget(e.element));}else t.shape=e.shape==="circle"?vp.ellipse:vp.rect,t.sibling=this.exclusionTarget(e.element);}exclusionTarget(e){if(this.ui.check(e),e===this)throw new sr(`ui element ${this.id} cannot flow around itself`);return e.id}transition(e,t){this.ui.check(this);let n=0;for(let s of e)n|=Ece[s];let r=t.spring!==void 0?"spring":t.bezier!==void 0?"bezier":t.easing??"ease",o=t.spring!==void 0?[t.spring.damping,t.spring.cycles,0,0]:t.bezier??null;return this.ui.writer.transition(this.id,n,t.duration,gce[r],o),this.ui.touched(),this}accessibility(e){this.ui.check(this);let t=this.ui.writer;e.role!==void 0&&t.propWord(this.id,G.role,On[e.role]),e.label!==void 0&&t.label(this.id,e.label),e.value!==void 0&&t.value(this.id,e.value);let n=(e.selected?vr.selected:0)|(e.disabled?vr.disabled:0)|(e.hidden?vr.hidden:0)|(e.live?vr.live:0)|(e.modal?vr.modal:0);if(t.propWord(this.id,G.traits,n),this.setState("disabled",e.disabled===true),e.actions!==void 0){let r=0;for(let o of e.actions)r|=Ri[o];t.propWord(this.id,G.actions,r);}return this.ui.touched(),this}scrollTo(e,t){return this.ui.check(this),this.ui.writer.scrollTo(this.id,e,t),this.ui.touched(),this}focus(){return this.ui.check(this),this.ui.writer.focus(this.id),this.ui.touched(),this}blur(){return this.ui.check(this),this.ui.writer.blur(this.id),this.ui.touched(),this}on(e,t){this.ui.check(this),this.listeners===null&&(this.listeners=new Map);let n=this.listeners.get(e);return n===void 0&&(n=[],this.listeners.set(e,n)),n.push(t),this.setFlag(HQe[e],true),()=>{let r=n.indexOf(t);r>=0&&n.splice(r,1);}}emit(e,t){e==="press"?this.setState("pressed",true):e==="release"?this.setState("pressed",false):e==="focus"?this.setState("focus",true):e==="blur"&&this.setState("focus",false);let n=this.listeners?.get(e);if(n===void 0||n.length===0)return false;for(let r=0;r<n.length;r++)n[r](t,this);return true}setFlag(e,t){if(e===0)return;let n=t?this.flags|e:this.flags&~e;n!==this.flags&&(this.flags=n,this.ui.writer.propWord(this.id,G.flags,n),this.ui.touched());}dispose(){this.alive=false,this.listeners=null,this.current=null,this.sent=null,this.scope=null,this.slotBase!==nw&&this.ui.freeSlots(this.slotBase,this.slotSize),this.slotBase=nw,this.slotSize=0,this.slotBits=null;}},iw=class{constructor(e,t={}){this.sink=e;this.elements=[];this.free=[];this.next=0;this.strings=new Map;this.families=new Map;this.fontFamilies=[];this.fontWeights=[];this.fontIds=[];this.measurer=new ET;this.passthrough=[];this.event={kind:0,phase:0,pointer:0,node:0,x:0,y:0,dx:0,dy:0,value:0,time_ms:0};this.scheduled=false;this.contextBits=Ne.portrait|Ne.safe;this.themeRoot=null;this.tokenIds=[];this.tokenKinds=[];this.tokenSent=new Set;this.themeBits=new WeakMap;this.slotTop=0;this.freeSlotBlocks=new Map;this.flushTask=()=>{this.flush();};this.maxNodes=t.max_nodes??kQe,this.maxSlots=t.max_slots??LQe,this.autoFlush=t.auto_flush??true,this.writer=new gu(t.capacity,t.reserve??0),t.dictionaries===true&&this.textDictionaries(true);}get context(){return this.contextBits}get rootTheme(){return this.themeRoot}styles(e,t){return Jue(e,t)}props(e,t,n,r,o,s,a,l){return oU(e,t,n,r,o,s,a,l)}environment(e){let t=e.width;this.contextBits=(t>e.height?Ne.landscape:Ne.portrait)|Ne.safe|(t>=TQe?Ne.sm:0)|(t>=wQe?Ne.lg:0);}tokenValue(e,t,n){let r=e??DQe,o=this.themeBits.get(r);o===void 0&&(o=[new Map,new Map,new Map],this.themeBits.set(r,o));let s=o[n],a=s.get(t);if(a===void 0){let l=e?.values.get(t)??$y(t);if(l===void 0)throw new sr(`style variable ${t} has no value; define it with defineVars`);a=Xue(n,l),s.set(t,a);}return a}ensureTokens(e,t){let n=0;for(let r=0;r<e.length;r++)this.tokenSent.has(e[r])||n++;if(n!==0){this.writer.tokens(false,n);for(let r=0;r<e.length;r++){let o=e[r];this.tokenSent.has(o)||(this.tokenSent.add(o),this.tokenIds.push(o),this.tokenKinds.push(t[r]),this.writer.pair(o,this.tokenValue(this.themeRoot,o,t[r])));}}}theme(e){if(e===this.themeRoot)return;this.themeRoot=e;let t=this.tokenIds.length;if(t>0){this.writer.tokens(true,t);for(let n=0;n<t;n++)this.writer.pair(this.tokenIds[n],this.tokenValue(e,this.tokenIds[n],this.tokenKinds[n]));}for(let n=0;n<this.elements.length;n++){let r=this.elements[n];r!==void 0&&r.perElement&&r.restyle();}this.touched();}allocateSlots(e){let t=this.freeSlotBlocks.get(e);if(t!==void 0&&t.length>0)return t.pop();let n=this.slotTop;if(n+e>this.maxSlots)throw new sr(`a game ui holds at most ${this.maxSlots} dynamic style slots`);return this.slotTop=n+e,n}freeSlots(e,t){let n=this.freeSlotBlocks.get(t);n===void 0&&(n=[],this.freeSlotBlocks.set(t,n)),n.push(e);}textDictionaries(e){this.writer.textOptions(e?cF.dictionaries:0),this.touched();}check(e){if(e.ui!==this)throw new sr("this element belongs to another game ui");if(e.destroyed)throw new sr(`ui element ${e.id} was destroyed`)}touched(){!this.autoFlush||this.scheduled||(this.scheduled=true,queueMicrotask(this.flushTask));}allocate(e){let t=this.free.length>0?this.free.pop():this.next++;if(t>=this.maxNodes)throw new sr(`a game ui holds at most ${this.maxNodes} nodes`);let n=new lU(this,t,e);return this.elements[t]=n,this.writer.create(t,Ace[e]),this.touched(),n}release(e){this.check(e),this.writer.destroy(e.id),this.touched(),this.forget(e);}forget(e){e.detach();let t=e.children.slice();for(let n=0;n<t.length;n++)this.forget(t[n]);this.elements[e.id]=void 0,this.free.push(e.id),e.dispose();}element(e){return this.elements[e]}box(e){let t=this.allocate("box");return e!==void 0&&t.style(e),t}text(e,t,n){let r=this.allocate("text");return t!==void 0&&r.style(t),e.length>0&&r.text(e),n?.flowAround!==void 0&&r.flowAround(n.flowAround),r}fontFor(e,t=aU){let n=typeof e=="number"?e:this.family(e),r=n,o=Number.POSITIVE_INFINITY;for(let s=0;s<this.fontFamilies.length;s++){if(this.fontFamilies[s]!==n)continue;let a=Math.abs(this.fontWeights[s]-t);a<o&&(o=a,r=this.fontIds[s]);}return r}measureText(e,t={},n=0,r){let o=this.fontFor(t.fontFamily??0,t.fontWeight??aU),s=ZW(o);if(s===void 0)throw new sr(`measureText needs the table of render font ${o}; load it with graphics.loadFont before measuring`);return this.measurer.measure(s,e,t,n,r??{lines:0,width:0,height:0})}get measureStats(){return {hits:this.measurer.hits,misses:this.measurer.misses}}image(e,t,n){let r=this.allocate("image");return r.image(e,t[0],t[1]),n!==void 0&&r.style(n),r}loadVector(e,t){this.writer.vectorLoad(e,t),this.touched();}unloadVector(e){this.writer.vectorUnload(e),this.touched();}vector(e,t=0,n){let r=this.allocate("vector");return r.vector(e,t),n!==void 0&&r.style(n),r}shape(e,t){let n=this.allocate("shape");return e!==void 0&&n.style(e),t!==void 0&&n.path(t),n}scroll(e){let t=this.allocate("scroll");return e!==void 0&&t.style(e),t}input(e,t){let n=this.allocate("input");return t!==void 0&&n.style(t),e.length>0&&n.placeholder(e),n}root(e,t={}){this.check(e);let n=t.offset??Zue;return this.writer.root(e.id,xce[t.anchor??"top_left"],t.safe_area??true,n[0],n[1],t.z??0),this.touched(),e}worldRoot(e,t){return this.check(e),this.writer.worldRoot(e.id,{position:t.position,pivot:t.pivot??PQe,offset:t.offset??Zue,reference_distance:t.reference_distance??0,min_scale:t.min_scale??FQe,max_scale:t.max_scale??UQe,hide_when_occluded:t.hide_when_occluded??false,occluded_opacity:t.occluded_opacity??BQe,z:t.z??0}),this.touched(),e}unroot(e){this.check(e),this.writer.unroot(e.id),this.touched();}move(e,t,n,r){this.check(e),this.writer.anchor(e.id,t,n,r),this.touched();}moveFrom(e,t,n){this.check(e),this.writer.anchorFrom(e.id,t,n),this.touched();}occlude(e,t){this.check(e),this.writer.occluded(e.id,t),this.touched();}intern(e){let t=this.strings.get(e);if(t!==void 0)return t;let n=this.strings.size;return this.strings.set(e,n),this.writer.string(n,e),this.touched(),n}family(e){let t=this.families.get(e);if(t!==void 0)return t;let n=this.families.size;return this.families.set(e,n),n}registerFont(e,t,n=aU){let r=this.family(e),o=-1;for(let s=0;s<this.fontFamilies.length;s++)this.fontFamilies[s]===r&&this.fontWeights[s]===n&&(o=s);return o<0?(this.fontFamilies.push(r),this.fontWeights.push(n),this.fontIds.push(t)):this.fontIds[o]=t,this.writer.font(r,n,t),this.touched(),r}onPassthrough(e){return this.passthrough.push(e),()=>{let t=this.passthrough.indexOf(e);t>=0&&this.passthrough.splice(t,1);}}flush(){if(this.scheduled=false,this.writer.empty)return 0;let e=this.writer.finish();return this.sink.submit(this.writer.bytes,e),this.writer.reset(),e}dispatch(e,t=0){let n=new DataView(e.buffer,e.byteOffset,e.byteLength),r=0,o=32;for(let s=t;s+32<=e.byteLength;s+=o){Sce(n,s,this.event),o=Ice(this.event.kind,n,s),this.event.text=void 0;let a=YQe[this.event.kind];if(a==null)continue;if(a==="change"){let c=s+32,u=Math.min(c+this.event.value,e.byteLength),d=KQe.decode(e.subarray(c,u));this.event.text=d;let h=this.elements[this.event.node];if(h===void 0)continue;h.accept(d),h.emit(a,this.event)&&r++;continue}if(a==="passthrough"){for(let c=0;c<this.passthrough.length;c++)this.passthrough[c](this.event);r++;continue}let l=this.elements[this.event.node];l!==void 0&&l.emit(a,this.event)&&r++;}return r}};function _a(i,e=false){return {json:i,optional:e}}function wu(i,e){return e===void 0?i:{...i,description:e}}function ow(i,e,t){return Math.min(Math.max(0,Math.floor(i??e)),t)}var iA={string(i={}){let e={type:"string",maxLength:ow(i.max,200,2e3)};return i.min!==void 0&&(e.minLength=ow(i.min,0,2e3)),_a(wu(e,i.note))},integer(i={}){let e={type:"integer"};return i.min!==void 0&&(e.minimum=i.min),i.max!==void 0&&(e.maximum=i.max),_a(wu(e,i.note))},number(i={}){let e={type:"number"};return i.min!==void 0&&(e.minimum=i.min),i.max!==void 0&&(e.maximum=i.max),_a(wu(e,i.note))},boolean(i){return _a(wu({type:"boolean"},i))},literal(i){return _a({const:i})},enum(i,e){return _a(wu({enum:i},e))},array(i,e={}){let t={type:"array",items:i.json,maxItems:ow(e.max,16,64)};return e.min!==void 0&&(t.minItems=ow(e.min,0,64)),_a(wu(t,e.note))},object(i,e){let t={},n=[];for(let[r,o]of Object.entries(i))t[r]=o.json,o.optional||n.push(r);return _a(wu({type:"object",additionalProperties:false,properties:t,required:n},e))},union(...i){return _a({anyOf:i.map(e=>e.json)})},optional(i){return {json:i.json,optional:true}}},rde=iA.object({speaker:iA.optional(iA.string({max:40})),lines:iA.array(iA.string({max:240}),{min:1,max:6})});function sw(i){return i!==null&&typeof i=="object"&&!Array.isArray(i)}function XQe(i,e){switch(i){case "object":return e!==null&&typeof e=="object"&&!Array.isArray(e);case "array":return Array.isArray(e);case "string":return typeof e=="string";case "integer":return typeof e=="number"&&Number.isInteger(e);case "number":return typeof e=="number"&&Number.isFinite(e);case "boolean":return typeof e=="boolean";case "null":return e===null;default:return false}}function ide(i,e){return JSON.stringify(i)===JSON.stringify(e)}function oA(i,e,t="$"){let n=i.enum;if(Array.isArray(n))return n.some(o=>ide(o,e))?null:`${t} is not one of the allowed values`;if("const"in i)return ide(i.const,e)?null:`${t} must be ${JSON.stringify(i.const)}`;let r=i.anyOf;if(Array.isArray(r))return r.some(o=>sw(o)&&oA(o,e,t)===null)?null:`${t} matches none of the allowed shapes`;if(i.type!==void 0&&!XQe(i.type,e))return `${t} must be a ${String(i.type)}`;if(Array.isArray(e)){let o=i.minItems,s=i.maxItems;if(typeof o=="number"&&e.length<o)return `${t} has too few items`;if(typeof s=="number"&&e.length>s)return `${t} has too many items`;let a=i.items;if(sw(a))for(let l=0;l<e.length;l++){let c=oA(a,e[l],`${t}[${l}]`);if(c!==null)return c}return null}if(e!==null&&typeof e=="object"){let o=e,s=sw(i.properties)?i.properties:{},a=Array.isArray(i.required)?i.required:[];for(let l of a)if(typeof l=="string"&&!(l in o))return `${t}.${l} is missing`;for(let[l,c]of Object.entries(o)){let u=s[l];if(sw(u)){let d=oA(u,c,`${t}.${l}`);if(d!==null)return d}else if(i.additionalProperties===false)return `${t}.${l} is not allowed`}return null}if(typeof e=="string"){let o=[...e].length;return typeof i.minLength=="number"&&o<i.minLength?`${t} is too short`:typeof i.maxLength=="number"&&o>i.maxLength?`${t} is too long`:null}if(typeof e=="number"){if(typeof i.minimum=="number"&&e<i.minimum)return `${t} is below its minimum`;if(typeof i.maximum=="number"&&e>i.maximum)return `${t} is above its maximum`}return null}function qQe(i,e){let t=[i];for(let n of e.split(".")){let r=[];for(let o of t)if(n==="*")Array.isArray(o)?r.push(...o):o!==null&&typeof o=="object"&&r.push(...Object.values(o));else if(Array.isArray(o)){let s=Number(n);Number.isInteger(s)&&s>=0&&s<o.length&&r.push(o[s]);}else o!==null&&typeof o=="object"&&n in o&&r.push(o[n]);t=r;}return t}function ode(i,e){for(let t of i){let n=qQe(e,t.path);switch(t.kind){case "range":if(n.some(r=>typeof r!="number"||r<t.min||r>t.max))return `${t.path} must stay between ${t.min} and ${t.max}`;break;case "total":{let r=0;for(let o of n){if(typeof o!="number")return `${t.path} must be a number`;r+=o;}if(r>t.max)return `${t.path} must add up to at most ${t.max}`;break}case "count":if(n.length<t.min||n.length>t.max)return `${t.path} must appear ${t.min} to ${t.max} times`;break;case "one_of":if(n.some(r=>typeof r!="string"||!t.values.includes(r)))return `${t.path} must be one of the game's values`;break;case "distinct":{if(new Set(n.map(o=>JSON.stringify(o))).size!==n.length)return `${t.path} must not repeat`;break}}}return null}var zQe=4e3,QQe=nb.min_ai_content_timeout_ms,$Qe=nb.max_ai_content_timeout_ms,jQe=nb.max_ai_content_retries,JQe=250,sde=0;function ZQe(i){return typeof i=="function"?i():i}function e$e(i){return Math.min(Math.max(Math.round(i??zQe),QQe),$Qe)}function kp(i,e,t){return {value:ZQe(i.fallback),source:"fallback",reason:e,seed:t,runId:null,digest:null}}function t$e(i){switch(i!==null&&typeof i=="object"&&"code"in i?i.code:null){case "meter_exhausted":return "budget";case "denied":case "consent_required":return "denied";case "invalid_arguments":return "invalid_request";default:return "unavailable"}}function n$e(i,e){return e!==void 0?e.json:i==="dialogue"?rde.json:null}function ade(i,e,t,n){let r=i==="dialogue"&&e.schema===void 0?void 0:e.schema?.json;return {request_key:n,kind:i,prompt:e.prompt,schema:r??null,rules:[...e.rules??[]],slots:[...e.slots??[]],context:e.context??null,scope:t===null?{kind:"player"}:{kind:"room",room_id:t.room_id,key:t.key},language:e.language??null,variant:e.variant??0,seed:e.seed??null,retries:e.retries??jQe,timeout_ms:e$e(e.timeoutMs),payment:e.payment??null}}function r$e(i,e,t){if(t.outcome==="fallback"||t.value===void 0||t.value===null)return kp(e,t.fallback??"unavailable",t.seed);let n=t.value,r=n$e(i,e.schema);return r!==null&&oA(r,n)!==null||ode(e.rules??[],n)!==null?kp(e,"invalid",t.seed):e.check!==void 0&&e.check(n)!==true?kp(e,"check",t.seed):{value:n,source:t.outcome,reason:null,seed:t.seed,runId:t.run_id,digest:t.output_digest??null}}function i$e(i){let e;return {done:new Promise(n=>{e=setTimeout(()=>n("timeout"),i);}),cancel:()=>clearTimeout(e)}}async function Np(i,e,t,n,r){let o=ade(e,t,n,r),s=i$e(o.timeout_ms+JQe);try{let a=await Promise.race([i.content(o),s.done]);return a==="timeout"?kp(t,"timed_out",t.seed??0):r$e(e,t,a)}catch(a){return kp(t,t$e(a),t.seed??0)}finally{s.cancel();}}function lde(i,e={}){let t=e.keyPrefix??"gen",n=o=>o!==void 0?o:(sde+=1,`${t}-${sde}`),r=((o,s)=>Np(i,o,s,null,n(s.key)));return r.dialogue=o=>Np(i,"dialogue",o,null,n(o.key)),r.text=o=>Np(i,"text",o,null,n(o.key)),r.item=o=>Np(i,"item",o,null,n(o.key)),r.quest=o=>Np(i,"quest",o,null,n(o.key)),r.room=o=>Np(i,"room",o,null,n(o.key)),r.prefetch=async o=>{try{return await i.content_prefetch({requests:o.map(s=>ade(s.kind,s,null,n(s.key)))})}catch{return {accepted:0,already_cached:0,refused:o.length}}},r}var o$e=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),s$e=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),lw=32,Lp=64,a$e=8,l$e=128,c$e=4294967296,Iu=new Uint32Array(64),Nn=new Uint32Array(8),aw=new Uint8Array(Lp*2),cU=new DataView(aw.buffer);function ds(i,e){return i>>>e|i<<32-e}function cde(i,e){for(let t=0;t<16;t++)Iu[t]=i.getUint32(e+t*4,false);u$e();}function u$e(){for(let l=16;l<64;l++){let c=Iu[l-15],u=Iu[l-2],d=ds(c,7)^ds(c,18)^c>>>3,h=ds(u,17)^ds(u,19)^u>>>10;Iu[l]=Iu[l-16]+d+Iu[l-7]+h|0;}let i=Nn[0],e=Nn[1],t=Nn[2],n=Nn[3],r=Nn[4],o=Nn[5],s=Nn[6],a=Nn[7];for(let l=0;l<64;l++){let c=a+(ds(r,6)^ds(r,11)^ds(r,25))+(r&o^~r&s)+o$e[l]+Iu[l]|0,u=(ds(i,2)^ds(i,13)^ds(i,22))+(i&e^i&t^e&t)|0;a=s,s=o,o=r,r=n+c|0,n=t,t=e,e=i,i=c+u|0;}Nn[0]+=i,Nn[1]+=e,Nn[2]+=t,Nn[3]+=n,Nn[4]+=r,Nn[5]+=o,Nn[6]+=s,Nn[7]+=a;}function cw(i,e){Nn.set(s$e);let t=new DataView(i.buffer,i.byteOffset,i.byteLength),n=i.length-i.length%Lp;for(let c=0;c<n;c+=Lp)cde(t,c);let r=i.length-n;aw.fill(0),aw.set(i.subarray(n),0),aw[r]=l$e;let o=r+1+a$e>Lp?2:1,s=i.length*8,a=o*Lp;cU.setUint32(a-8,Math.floor(s/c$e),false),cU.setUint32(a-4,s>>>0,false);for(let c=0;c<o;c++)cde(cU,c*Lp);let l=new DataView(e.buffer,e.byteOffset,lw);for(let c=0;c<8;c++)l.setUint32(c*4,Nn[c],false);}var pU=4294967296,d$e=4,ude="0123456789ABCDEFGHJKMNPQRSTVWXYZ",dde="abcdefghijkmnopqrstuvwxyz23456789",hde="0123456789abcdef",uU=16,h$e=10,p$e=16,m$e=112,f$e=128,dU=256,uw=class{constructor(e){this.services=e;this.bytes=new Uint8Array(dU);this.words=new Uint32Array(this.bytes.buffer);this.cursor=dU;}u32(){this.cursor+4>dU&&(this.services.random_fill(this.bytes),this.cursor=0);let e=this.words[this.cursor>>2];return this.cursor+=4,e}byte(){return this.u32()&255}},hU=class{constructor(e){this.a=e[0]>>>0,this.b=e[1]>>>0,this.c=e[2]>>>0,this.d=e[3]>>>0||1;}next_u32(){let e=Math.imul(pde(Math.imul(this.b,5),7),9)>>>0,t=this.b<<9;return this.c^=this.a,this.d^=this.b,this.b^=this.c,this.a^=this.d,this.c^=t,this.d=pde(this.d,11),e}next_float(){return this.next_u32()/pU}};function pde(i,e){return (i<<e|i>>>32-e)>>>0}function mde(i){let e=new uw(i);return {cosmetic:()=>e.u32()/pU,async seed(t){let n=[0,0,0,0];for(let r=0;r<d$e;r++)n[r]=e.u32();return {label:t.label,recorded:false,scope:t.scope,words:n}},stream:t=>new hU(t.words)}}function fde(i){return {sha256:(e,t)=>cw(e,t),random_bytes:e=>i.random_fill(e),verify:(e,t,n)=>i.verify_ed25519(e,t,n)}}function _de(i){let e=new uw(i),t=new Uint8Array(uU);return {uuid_v7(){let n=i.now_ms(),r=Math.floor(n/pU),o=n>>>0;t[0]=r>>>8&255,t[1]=r&255,t[2]=o>>>24,t[3]=o>>>16&255,t[4]=o>>>8&255,t[5]=o&255;for(let a=6;a<uU;a++)t[a]=e.byte();t[6]=m$e|t[6]&15,t[8]=f$e|t[8]&63;let s="";for(let a=0;a<uU;a++)(a===4||a===6||a===8||a===10)&&(s+="-"),s+=hde[t[a]>>>4]+hde[t[a]&15];return s},ulid(){let n=i.now_ms(),r="";for(let s=0;s<h$e;s++)r=ude[n%32]+r,n=Math.floor(n/32);let o="";for(let s=0;s<p$e;s++)o+=ude[e.byte()&31];return r+o},short(n){let r="";for(let o=0;o<n;o++)r+=dde[e.u32()%dde.length];return r},fill:n=>i.random_fill(n)}}function yde(i,e){let t=()=>i.now_ms()+e;return {now:t,async sync(){return {now:t(),source:"app_clock",display_offset_ms:e,room_tick:null}}}}function Ade(i){let e=new Map,t=new Map,n=new Intl.DateTimeFormat(i.language,{timeStyle:"short",timeZone:i.time_zone});return {...i,format_number(r,o){let s=o??-1,a=e.get(s);return a===void 0&&(a=new Intl.NumberFormat(i.language,s<0?{}:{minimumFractionDigits:s,maximumFractionDigits:s}),e.set(s,a)),a.format(r)},format_money(r,o){let s=o??i.currency,a=t.get(s);return a===void 0&&(a=new Intl.NumberFormat(i.language,{style:"currency",currency:s}),t.set(s,a)),a.format(Number(r))},format_time:r=>n.format(r)}}var _$e=0,y$e=-1,A$e=52,ar={sequence:0,faces:1,measured:2,header_words:3,expression_floats:jl.expressions.length,arkit_floats:A$e,pose_floats:jl.head_pose.length},b$e=ar.expression_floats+ar.arkit_floats+ar.pose_floats,g$e=(ar.header_words+b$e)*Float32Array.BYTES_PER_ELEMENT,bde=ar.expression_floats,E$e=bde+ar.arkit_floats;var sA=class extends Error{constructor(t){super(`the identity capture ended: ${t}`);this.code=t;this.name="IdentityCaptureError";}};function x$e(i){return HI.includes(i)?i:"unavailable"}var Ou=class extends Error{constructor(t){super(`the camera could not start: ${t}`);this.reason=t;this.name="CameraError";}};function gde(i){return JSON.stringify({x:i.x,y:i.y,width:i.width,height:i.height,mirror:i.mirror??true,layer:i.layer??"over"})}var mU=class{constructor(e,t,n){this.host=e;this.grant=t;this.seen=0;this.open=true;if(n.byteLength<g$e)throw new Ou("face buffer is too small");let r=Float32Array.BYTES_PER_ELEMENT,o=ar.header_words*r;this.header=new Uint32Array(n,0,ar.header_words),this.expressions=new Float32Array(n,o,ar.expression_floats),this.arkit=new Float32Array(n,o+bde*r,ar.arkit_floats),this.head_pose=new Float32Array(n,o+E$e*r,ar.pose_floats);}get faces(){return this.header[ar.faces]}get measured(){return this.header[ar.measured]}update(){if(!this.open)return false;let e=this.header[ar.sequence];return e===this.seen?false:(this.seen=e,this.header[ar.faces]>0)}colours(){return this.open?new Promise(e=>{this.host.colours(this.grant,(t,n,r)=>{e(t===y$e?null:{skin:t,hair:n,eye:r});});}):Promise.resolve(null)}close(){this.open&&(this.open=false,this.host.untrack(this.grant));}},fU=class{constructor(e,t){this.host=e;this.handle=t;this.open=true;}place(e){if(!this.open)throw new Ou("the camera view is closed");if(!this.host.place(this.handle,gde(e)))throw new Ou("camera_bad_placement")}hide(){this.open&&this.host.hide(this.handle);}show(){this.open&&this.host.show(this.handle);}close(){this.open&&(this.open=false,this.host.close_view(this.handle));}},dw=class{constructor(e){this.host=e;}track_face(e){return new Promise((t,n)=>{this.host.track(e,(r,o)=>{if(r===null)return n(new Ou(o));try{t(new mU(this.host,e,r));}catch(s){n(s);}});})}view(e,t){return new Promise((n,r)=>{this.host.view(e,gde(t),(o,s)=>{o===_$e?r(new Ou(s)):n(new fU(this.host,o));});})}capture_identity(e){return new Promise((t,n)=>{this.host.capture_identity(e,(r,o)=>{r===null||r===""?n(new sA(x$e(o))):t({identity:r});});})}};yn();var Aa=class extends Error{constructor(e){super(`ctx.${e} is not available in the native profile`),this.name="GuestUnavailableError",this.member=e;}},v$e=new Set(["unavailable","nothing_recorded","unknown_clip","camera_consent","failed"]),aA=class extends Error{constructor(t){super(`the clip was not saved (${t})`);this.code=t;this.name="ClipError";}};function _U(i){if(i===null||typeof i!="object")throw new aA("unavailable");let e=i;if(typeof e.media_id=="string")return typeof e.url=="string"?{media_id:e.media_id,url:e.url}:{media_id:e.media_id};let t=e.error?.code;throw new aA(typeof t=="string"&&v$e.has(t)?t:"failed")}function R$e(i){return {open:()=>Promise.reject(new Aa("media.open")),async record_clip(e,t){let n=await i.command({kind:"clip_start",max_ms:t},true);if(n===null||typeof n!="object"||typeof n.clip!="number")throw new aA("unavailable");let r=n.clip;return {stop:async()=>_U(await i.command({kind:"clip_stop",clip:r},true)),cancel:()=>{i.command({kind:"clip_cancel",clip:r},false);}}},keep_clip:async e=>_U(await i.command({kind:"clip_keep",ms:e},true)),save_replay:async e=>_U(await i.command({kind:"replay_save",replay:Vu(e)},true)),on_replay:e=>i.on_replay===void 0?()=>{}:i.on_replay(e)}}var S$e={};function ya(i){throw new Aa(i)}function Mp(i,e){let t={};for(let n of e)Object.defineProperty(t,n,{get:()=>ya(`${i}.${n}`),enumerable:true});return t}function Ede(i,e){let t=i.tick;if(e===null||t===null||t===void 0)return null;let n=e.dialers(t.endpoints);return {ticket:tb(t.ticket),expires_at:t.expires_at,primary:n.primary,fallback:n.fallback}}function hw(i,e=null){let t=g=>v=>i.call(g,v),n=g=>()=>i.call(g,S$e),r=(g,v,x)=>O=>i.call(g,{...O,[v]:x}),o=(g,v)=>()=>i.call(g,v),s=g=>({on_event(v){return i.subscribe(g,x=>v(x.event))}}),a=g=>({on_event(v){return i.family(g,x=>v(x.event))}}),l={...i.program,set_status:t("program.set_status"),ready:()=>i.mark("ready_for_input")},c=async g=>{let v=await i.call("store.open",g),x=v.store_id,O=null;return {handle:v,get:r("store.get","store_id",x),list:r("store.list","store_id",x),commit:r("store.commit","store_id",x),checkpoint:r("store.checkpoint","store_id",x),restore:r("store.restore","store_id",x),migrate:r("store.migrate","store_id",x),on_event(N){O??=i.call("store.subscribe",{store_id:x}).then(w=>w.grant);let I=null,S=false;return O.then(w=>{S||(I=i.subscribe(w,U=>N(U.event)));}),()=>{S=true,I?.();}}}},u=g=>{let v=g.state.room_id;return {handle:g,realtime:Ede(g,e),inputs:new zS(i.lane,g.slot),leave:o("room.leave",{room_id:v}),state:o("room.state",{room_id:v}),move:r("room.move","room_id",v),view:o("room.view",{room_id:v}),history:r("room.history","room_id",v),control:r("room.control","room_id",v),commit_result:r("room.commit_result","room_id",v),on_input:x=>jS(i.lane.roomInputs,g.slot,x),...s(g.grant)}},d=g=>{let v=new xy(i.lane,g.slot,g.max_payload_bytes);return {handle:g,slot:g.slot,max_payload_bytes:v.max_payload_bytes,payload:()=>v.payload(),send:(x,O)=>v.send(x,O),on_message:x=>jS(i.lane.channels,g.slot,x),close:o("channel.close",{channel_id:g.channel_id}),on_event:x=>i.family("channel",O=>x(O.event))}},h=g=>({invite:r("world.invite","world_id",g),set_role:r("world.set_role","world_id",g),moderate:r("world.moderate","world_id",g)}),p=g=>{let v=g.world_id;return {session:g,realtime:Ede(g,e),...h(v),move:x=>Rle(i.lane,x),on_presence:x=>vle(i.lane,x),emote:r("world.emote","world_id",v),set_visibility:r("world.set_visibility","world_id",v),enter_venue:r("world.enter_venue","world_id",v),exit_venue:t("world.exit_venue"),nearby:r("world.nearby","world_id",v),leave:o("world.leave",{world_id:v}),...s(g.grant)}},m=null,f={game:g=>{if(m!==null)return m;let v=e?.assets,x=v?.has?.(fI)===true,O=new iw({submit:(N,I)=>i.game_ui(N,I)},{...g,reserve:Ae,dictionaries:g?.dictionaries??x});return x&&v!==void 0&&gp()===null&&v.take(fI).then(N=>{zle(N.slice().buffer);},()=>{}),i.on_game_ui(N=>O.dispatch(N,Ae)),m=O,O},render:g=>i.render(g),present:g=>i.command({kind:"present",mode:g},true).then(()=>{}),open_sheet:g=>i.command({kind:"open_sheet",request:g},true),open_handoff:g=>i.command({kind:"open_handoff",handoff_id:g},true),toast:g=>{i.command({kind:"toast",text:g},false);},haptic:g=>{i.command({kind:"haptic",haptic:g},false);},announce:g=>{i.command({kind:"announce",text:g},false);},on_event:g=>i.on_ui(g)},y=e?.loop,b=e?.camera,A=Mp("game",y===void 0?["kit_version","loop","scenes","camera","feel"]:["kit_version","scenes","camera","feel"]);y!==void 0&&Object.defineProperty(A,"loop",{value:y,enumerable:true});let E=Object.assign(A,{create_physics:()=>ya("game.create_physics"),saves:()=>ya("game.saves"),turns:()=>ya("game.turns"),leaderboards:{async submit(g){let v=await i.call("game.leaderboards.submit",g);return v.status!=="rejected"&&i.complete({outcome:"finished",score:v.score}),v},page:t("game.leaderboards.page")},achievements:{list:n("game.achievements.list"),progress:t("game.achievements.progress")},economy:{catalogue:n("game.economy.catalogue"),balances:t("game.economy.balances"),grant:t("game.economy.grant"),spend:t("game.economy.spend"),propose_trade:t("game.economy.trade.propose"),accept_trade:t("game.economy.trade.accept"),cancel_trade:t("game.economy.trade.cancel"),exchange:t("game.economy.exchange")}});return {program:l,session:{complete(g){return i.complete({outcome:g.outcome,score:g.score??null}),i.call("program.complete",g)}},clock:yde(i.services,i.clock_offset_ms),random:mde(i.services),locale:Ade(i.locale),identity:{current:n("identity.current"),personas:t("identity.personas"),profile:n("identity.profile")},social:{friends:t("social.friends"),challenge:t("social.challenge"),invite:t("social.invite"),post:t("social.post"),remix_lineage:n("social.remix_lineage"),avatars:t("social.avatars"),avatar_consent:t("social.avatar_consent")},open_store:c,async schedule(g){let v=await i.call("schedule.create",g),x={task_id:v.task_id};return {task:v,status:o("schedule.status",x),cancel:o("schedule.cancel",x),...a("schedule")}},compute:t("compute.invoke"),async create_worker(g){let v=await i.call("worker.create",g);return {handle:v,post:r("worker.post","worker_id",v.worker_id),terminate:o("worker.terminate",{worker_id:v.worker_id}),...s(v.grant)}},create_local_worker:()=>ya("create_local_worker"),create_room:async g=>u(await i.call("room.create",g)),join_room:async g=>u(await i.call("room.join",g)),create_channel:async g=>d(await i.call("channel.open",g)),create_world:async g=>{let v=await i.call("world.create",g);return {handle:v,...h(v.world_id)}},join_world:async g=>p(await i.call("world.join",g)),list_worlds:t("world.list"),game:E,services:{catalogue:{search:t("services.catalogue.search"),product:t("services.catalogue.product")},cart:{get:t("services.cart.get"),add:t("services.cart.add"),update:t("services.cart.update")},delivery:{quote:t("services.delivery.quote")},purchase_intents:{create:t("services.purchase_intents.create"),status:t("services.purchase_intents.status")},orders:{list:t("services.orders.list"),get:t("services.orders.get")},scheduling:{availability:t("services.scheduling.availability"),book:t("services.scheduling.book")},places:{search:t("services.places.search"),get:t("services.places.get"),contribute:t("services.places.contribute")},arcs:{progress:t("services.arcs.progress"),record:t("services.arcs.record"),challenges:t("services.arcs.challenges")}},gifts:{kinds:t("gifts.kinds"),send:t("gifts.send"),prizes:t("gifts.prizes"),...a("gifts")},wallet:{offers:n("wallet.offers"),spend:t("wallet.spend"),entitlements:n("wallet.entitlements"),allowance:n("wallet.allowance"),consume:t("wallet.consume")},ads:{placement:t("ads.placement"),sponsored_items:t("ads.sponsored_items")},notify:{status:n("notify.status"),request_opt_in:t("notify.request_opt_in"),send:t("notify.send")},moderate:{submit:t("moderate.submit"),status:t("moderate.status")},report:{submit:t("report.submit"),block:t("report.block")},actions:{prepare:t("actions.prepare"),execute:t("actions.execute"),receipt:t("actions.receipt")},provider:{call:t("provider.call"),subscribe:t("provider.subscribe"),...a("provider")},flow:{status:t("flow.status"),checkpoint:t("flow.checkpoint"),resume:t("flow.resume"),report_result:t("flow.report_result")},agent:{ask:t("agent.ask"),cancel:t("agent.cancel"),request_edit:t("agent.request_edit"),...a("agent")},share:t("share.open"),db:{describe:n("db.describe"),migrate:t("db.migrate"),query:t("db.query")},tx:{begin:t("tx.begin"),stage:t("tx.stage"),commit:t("tx.commit"),abort:t("tx.abort")},async open_kv(g){let v=await i.call("kv.open",g),x=v.namespace_id;return {handle:v,fast:new vy(i.lane,v.slot,"kv"),get:r("kv.get","namespace_id",x),set:r("kv.set","namespace_id",x),compare_and_set:r("kv.compare_and_set","namespace_id",x),delete:r("kv.delete","namespace_id",x),list:r("kv.list","namespace_id",x)}},async open_cache(g){let v=await i.call("cache.open",g),x=v.namespace_id;return {handle:v,fast:new vy(i.lane,v.slot,"cache"),get:r("cache.get","namespace_id",x),set:r("cache.set","namespace_id",x),delete:r("cache.delete","namespace_id",x)}},async open_counter(g){let v=await i.call("counter.open",g),x=v.counter_id,O=new QS(i.lane,v.slot);return {handle:v,add_fast:(N,I)=>O.add(N,I),on_value:N=>O.on_value(N),add:r("counter.add","counter_id",x),read:r("counter.read","counter_id",x),rate_limit:r("counter.rate_limit","counter_id",x),rank:r("counter.rank","counter_id",x),rank_range:r("counter.rank_range","counter_id",x),rank_of:r("counter.rank_of","counter_id",x)}},blob:{put:t("blob.put"),transfer:()=>ya("blob.transfer"),commit:t("blob.commit"),get:t("blob.get"),read:()=>ya("blob.read"),list:t("blob.list"),delete:t("blob.delete")},queue:{enqueue:t("queue.enqueue"),status:t("queue.status"),cancel:t("queue.cancel"),stats:t("queue.stats"),...a("queue")},search:{index:t("search.index"),query:t("search.query"),remove:t("search.remove")},ai:{generate:t("ai.generate"),converse:t("ai.converse"),speak:t("ai.speak"),transcribe:t("ai.transcribe"),image:t("ai.image"),translate:t("ai.translate"),prefetch:t("ai.prefetch"),cancel:t("ai.cancel"),forget:t("ai.forget"),usage:n("ai.usage"),content:t("ai.content"),content_prefetch:t("ai.content_prefetch"),watch(g,v){return g.grant?i.subscribe(g.grant,x=>v(x.event)):(g.result&&v({kind:"completed",result:g.result}),()=>{})},...a("ai")},generate:lde({content:t("ai.content"),content_prefetch:t("ai.content_prefetch")}),pubsub:{async subscribe(g){let v=await i.call("pubsub.subscribe",g),x=new xy(i.lane,v.slot,v.max_payload_bytes);return {subscription:v,slot:v.slot,max_payload_bytes:x.max_payload_bytes,payload:()=>x.payload(),send:(O,N)=>x.send(O,N),publish:r("pubsub.publish","topic",v.topic),on_message:O=>jS(i.lane.channels,v.slot,O),close:()=>i.call("events.cancel",{subscription_id:v.grant.subscription_id}).then(()=>{})}}},analytics:{track:t("analytics.track"),record:t("analytics.record"),summary:t("analytics.summary")},secrets:{handle:t("secrets.handle"),sign:t("secrets.sign")},ui:f,graphics:e?.graphics??Mp("graphics",["features","engine","acquire_surface","attach_engine","on_context_lost","on_context_restored"]),input:e?.input??Mp("input",["bind","pointers","remap"]),audio:e?.audio??Mp("audio",["unlocked","unlock","bus","load","play","stop"]),media:R$e(i),files:Mp("files",["pick","save"]),assets:e?.assets??Mp("assets",["take","module"]),camera:{request:t("camera.request"),release:t("camera.release"),track_face:b?g=>b.track_face(g):()=>ya("camera.track_face"),view:b?(g,v)=>b.view(g,v):()=>ya("camera.view"),capture_identity:b?g=>b.capture_identity(g):()=>Promise.reject(new sA("unavailable"))},lifecycle:i.lifecycle,events:{subscribe:(g,v)=>i.family(g,x=>v(x.event)),cancel:t("events.cancel"),resume:t("events.resume")},crypto:fde(i.services),id:_de(i.services),on_dispose:g=>i.on_dispose(g)}}var Tde={kind:"prepared"},xde=4,T$e=8,w$e=4096,I$e="position:fixed;inset:0;width:100%;height:100%;display:block;touch-action:none;outline:none",vde=["pointerdown","keydown","touchend"],O$e=["music","effects","voice","ui"],pw="running",Rde="webgl2";function Sde(i,e){return i.api===e.api&&i.transparent===e.transparent&&i.pixel_ratio_cap===e.pixel_ratio_cap&&i.offscreen===e.offscreen}var C$e=0;function N$e(){return new Promise(i=>setTimeout(i,C$e))}function k$e(i,e){let t=i.indexOf(e);t>=0&&i.splice(t,1);}function yU(i,e){return i.push(e),()=>k$e(i,e)}function L$e(i){let e=[],t=w$e,r=i.document.createElement("canvas").getContext("webgl2");r!==null&&(e.push("webgl2"),t=r.getParameter(r.MAX_TEXTURE_SIZE),r.getExtension("WEBGL_lose_context")?.loseContext()),i.GPU!==void 0&&e.push("webgpu"),e.push("canvas2d");let o=i.navigator.hardwareConcurrency??xde;return {apis:e,max_texture_size:t,device_tier:o>=T$e?"high":o>xde?"mid":"low"}}var mw=class{constructor(e,t,n,r=null){this.scope=e;this.platform=t;this.mark=n;this.gameUi=r;this.probed=null;this.device=null;this.warmEngine=null;this.tiering=null;this.prepared=null;this.engines=new Map;this.lost=[];this.restored=[];this.gpu=e.navigator?.gpu;}get features(){return this.probed??=L$e(this.scope),this.probed}engine(){return this.stopTiering(),this.webgpu(),this.platform()}stopTiering(){this.tiering?.stop(),this.tiering=null;}prepare(e,t){if(e.api!==Rde||e.offscreen)return null;if(this.prepared!==null)return Sde(this.prepared.options,e)?this.prepared.surface.canvas:null;let n=new fw(this.scope,e,this.lost,this.restored);return n.canvas.getContext(Rde,t),this.prepared={options:e,surface:n},n.canvas}hold(e,t){this.engines.set(e,t);}take_prepared(e){let t=this.prepared,n=this.engines.get(e);return t===null||n===void 0?null:(this.mark("attach_requested"),this.prepared=null,this.engines.delete(e),t.surface.measure(),this.mark("attach_resolved"),{surface:t.surface,instance:n})}acquire_surface(e){this.mark("attach_requested");let t=this.prepared;this.prepared=null;let n;return t!==null&&Sde(t.options,e)?(n=t.surface,n.reveal()):(t?.surface.release(),n=new fw(this.scope,e,this.lost,this.restored)),this.mark("attach_resolved"),Promise.resolve(n)}webgpu(){return this.device??=sV(this.gpu).catch(()=>null),this.device}async webTarget(){let e=await this.platform(),t=e.kind==="engine"?e.runtime.gpu??null:null;if(e.kind!=="engine"||t===null)return null;let n=await this.webgpu();return n===null?null:{scope:this.scope,runtime:e.runtime,executor:t,device:n}}async prewarm_engine(){let e=await this.platform();e.kind==="engine"&&this.tiering===null&&(this.tiering=gle(A6(e.runtime),N$e));let t=await this.webTarget();t===null||this.warmEngine!==null||(this.warmEngine=lV(t,void 0));}async attach_engine(e,t){let n=await this.webTarget();if(n===null)return this.attachWebGl(e,t);this.stopTiering(),this.mark("attach_requested");let r=this.warmEngine;this.warmEngine=null;let o=this.gameUi,a=cV({...n,render:e,options:t,prepared:r,overlay:o===null?null:(l,c,u)=>o.overlay(n.runtime,l,c,u)});return this.mark("attach_resolved"),a}async attachWebGl(e,t){let n=await this.platform(),r=n.kind==="engine"?n.runtime.gl??null:null;if(n.kind!=="engine"||r===null)throw new _("unsupported_feature","neither WebGPU nor the WebGL2 engine build is available on this device");this.stopTiering(),this.mark("attach_requested");let o=this.gameUi,s=n.runtime,a=o===null?null:(c,u,d)=>o.overlay(s,c,u,d),l=uV({scope:this.scope,runtime:s,executor:r,render:e,options:t,overlay:a});return this.mark("attach_resolved"),l}on_context_lost(e){return yU(this.lost,e)}on_context_restored(e){return yU(this.restored,e)}},fw=class{constructor(e,t,n,r){this.scope=e;this.lost=n;this.restored=r;this.resized=[];this.onLost=e=>{e.preventDefault();for(let t=0;t<this.lost.length;t++)this.lost[t]();};this.onRestored=()=>{for(let e=0;e<this.restored.length;e++)this.restored[e]();};this.onResize=()=>{let e=this.element.clientWidth,t=this.element.clientHeight;if(!(e===this.width&&t===this.height)){this.width=e,this.height=t,this.canvas!==this.element&&(this.canvas.width=Math.round(e*this.pixel_ratio),this.canvas.height=Math.round(t*this.pixel_ratio));for(let n=0;n<this.resized.length;n++)this.resized[n](e,t);}};let o=e.document.createElement("canvas");o.setAttribute("style",I$e),o.tabIndex=0,e.document.body.appendChild(o),this.element=o,this.pixel_ratio=Math.min(e.devicePixelRatio||1,t.pixel_ratio_cap),this.width=0,this.height=0,o.addEventListener("webglcontextlost",this.onLost),o.addEventListener("webglcontextrestored",this.onRestored);let s=o.transferControlToOffscreen;this.reveal(),this.canvas=t.offscreen&&s!==void 0?s.call(o):o;let a=e.ResizeObserver;this.observer=a===void 0?null:new a(this.onResize),this.observer?.observe(o);}reveal(){this.measure(),this.element.width=Math.round(this.width*this.pixel_ratio),this.element.height=Math.round(this.height*this.pixel_ratio);}measure(){this.width=this.element.clientWidth,this.height=this.element.clientHeight,this.element.focus();}on_resize(e){return yU(this.resized,e)}release(){this.observer?.disconnect(),this.element.removeEventListener("webglcontextlost",this.onLost),this.element.removeEventListener("webglcontextrestored",this.onRestored),this.element.remove(),this.resized.length=0;}},AU=class{constructor(e,t){this.node=e;this.context=t;this.level=1;this.silenced=false;}get volume(){return this.level}set volume(e){this.level=e,this.apply();}get muted(){return this.silenced}set muted(e){this.silenced=e,this.apply();}duck(e,t){let n=this.context.currentTime,r=this.node.gain;r.cancelScheduledValues(n),r.setValueAtTime(this.silenced?0:this.level*e,n),r.linearRampToValueAtTime(this.silenced?0:this.level,n+t/1e3);}apply(){this.node.gain.value=this.silenced?0:this.level;}},_w=class{constructor(e){this.scope=e;this.context=null;this.output=null;this.tap=null;this.buses=new Map;this.gesture=()=>{this.unlock().then(e=>{if(e)for(let t of vde)this.scope.removeEventListener(t,this.gesture);});};for(let t of vde)e.addEventListener(t,this.gesture,{capture:true,passive:true});}get unlocked(){return this.context?.state===pw}audio(){if(this.context!==null)return this.context;let e=this.scope.AudioContext;if(e===void 0)throw new Aa("audio");let t=new e({latencyHint:"interactive"}),n=t.createGain();n.connect(t.destination),hV(t,n);for(let r of O$e){let o=t.createGain();o.connect(n),this.buses.set(r,new AU(o,t));}return this.context=t,this.output=n,t}clipStream(){if(this.tap!==null)return this.tap.stream;let e=this.audioContext(),t=this.output;if(e===null||t===null||typeof e.createMediaStreamDestination!="function")return null;let n=e.createMediaStreamDestination();return t.connect(n),this.tap=n,n.stream}audioContext(){try{return this.audio()}catch{return null}}async unlock(){let e=this.audio();return e.state!==pw&&await e.resume(),e.state===pw}suspend(){this.context?.suspend();}resume(){this.context!==null&&this.context.state!==pw&&this.context.resume();}bus(e){return this.audio(),this.buses.get(e)}load(e){return Promise.reject(new Aa("audio.load"))}play(e,t){throw new Aa("audio.play")}stop(e){throw new Aa("audio.stop")}};var Dp=16.666666666666668,wde=250,lA=-1,yw=class{constructor(e){this.clock=e;this.fixed_step_ms=Dp;this.callbacks=null;this.handle=lA;this.last=-1;this.accumulator=0;this.ticks=0;this.paused=false;this.held=false;this.frame=e=>{this.handle=lA;let t=this.callbacks;if(t===null)return;if(this.schedule(),this.paused){this.last=e;return}let n=this.last<0?Dp:e-this.last;for(this.last=e,this.accumulator+=n>wde?wde:n;this.accumulator>=Dp;)t.update(Dp,this.ticks),this.ticks++,this.accumulator-=Dp;t.render(this.accumulator/Dp);};}get tick(){return this.ticks}start(e){this.callbacks=e,this.paused=false,this.last=-1,this.schedule();}pause(){this.paused=true;}resume(){this.paused=false;}hold(){this.held=true,this.cancel();}release(){this.held=false,this.last=-1,this.schedule();}stop(){this.callbacks=null,this.cancel();}schedule(){this.callbacks===null||this.held||this.handle!==lA||(this.handle=this.clock.requestAnimationFrame(this.frame));}cancel(){this.handle!==lA&&this.clock.cancelAnimationFrame(this.handle),this.handle=lA;}};Cm();function M$e(i,e,t){let n=Object.getOwnPropertyDescriptor(i,e);n!==void 0&&n.configurable===false||Object.defineProperty(i,e,{value:t,writable:false,enumerable:false,configurable:false});}var D$e=["fetch","XMLHttpRequest","WebSocket","WebTransport","EventSource","RTCPeerConnection","importScripts","open","__cimplify_host"];function Ide(i){for(let e of D$e)(e in i||Object.getOwnPropertyDescriptor(i,e)!==void 0)&&M$e(i,e,void 0);}yn();var P$e="/w/",F$e="/j/",U$e="p",B$e=",";var Ode=".wasm",G$e="sha256-";var V$e=/^[0-9a-f]{64}$/;function H$e(i){return V$e.test(i)}function bU(i){let e=new Uint8Array(lw);return !H$e(i)||!U6(i,e)?null:G$e+Vu(e)}function Cde(i){return P$e+i+Ode}function Nde(i,e){return `${F$e}${i}${Ode}?${U$e}=${e.join(B$e)}`}var Mde="null",kde={credentials:"omit",mode:"same-origin",redirect:"error"};function Dde(i){let e=new Map;return {async fetch(t,n){let r=bU(n);if(r===null)throw new Error(`chunk ${t} names no payload digest`);let o=await i(Cde(t),{...kde,integrity:r});if(!o.ok)throw new Error(`chunk ${t} answered ${o.status}`);let s=o.clone(),a=WebAssembly.compileStreaming(o);return a.catch(()=>{}),e.set(t,a),new Uint8Array(await s.arrayBuffer())},compiled(t){return e.get(t)??null},async joined(t,n){let r=bU(t);if(r===null)throw new Error(`${t} is not a sha256 digest`);return WebAssembly.compileStreaming(i(Nde(t,n),{...kde,integrity:r}))}}}var W$e=";",K$e="=",Lde=".",Y$e=2;function X$e(i){let e=i.split(Lde),t=[];for(let n=0;n+Y$e<=e.length;n++)t.push(e.slice(n).join(Lde));return t}function Pde(i,e){let t=i.cookie,n=X$e(i.location.hostname);for(let r of t.split(W$e)){let o=r.split(K$e)[0].trim();if(o!==""){i.cookie=`${o}=; Max-Age=0; Path=/`;for(let s of n)i.cookie=`${o}=; Max-Age=0; Path=/; Domain=${s}`;}}Object.defineProperty(i,"cookie",{configurable:false,enumerable:true,get:()=>"",set:()=>{}}),Object.defineProperty(e,"cookieStore",{configurable:false,enumerable:false,value:void 0,writable:false});}var q$e=["engine_ui_create","engine_ui_destroy","engine_ui_patch_buffer","engine_ui_apply","engine_ui_apply_bytes","engine_ui_viewport","engine_ui_view","engine_ui_set_anchor","engine_ui_occluded","engine_ui_frame","engine_ui_render","engine_ui_pointer","engine_ui_wheel","engine_ui_events","engine_ui_event_count","engine_ui_clear_events","engine_ui_accessibility","engine_ui_accessibility_export","engine_ui_perform_action","engine_ui_register_font","engine_ui_view_from_camera","engine_render_camera_view_projection","engine_ui_text","engine_ui_text_length"],gU={accessibility:4,events:8};var EU=1,Pt=0;function Fde(i){for(let e of q$e)if(typeof i[e]!="function")return null;return i}var z$e=["engine_ui_vector_load","engine_ui_vector_unload","engine_ui_vector_attach","engine_ui_vector_detach","engine_ui_vector_play","engine_ui_vector_input_index","engine_ui_vector_input"];var Hl=-1;function Ude(i){for(let e of z$e)if(typeof i[e]!="function")return null;return i}var Q$e=["engine_ui_vector_fallback_request","engine_ui_vector_fallback_font"];function Bde(i){for(let e of Q$e)if(typeof i[e]!="function")return null;return i}var Gde=32,Vde=0;var j$e=["engine_ui_vector_fetch_origins","engine_ui_vector_fetch_pending","engine_ui_vector_fetch_next","engine_ui_vector_fetch_settle"];function Wde(i){for(let e of j$e)if(typeof i[e]!="function")return null;return i}var Hde={request:1,cancel:2},xU={timeout:3,tooLarge:5,network:6},J$e=0,Z$e=16*1024*1024,vU=4,eje=0,tje="the request timed out",nje="the response is larger than scripts may receive",uA=new TextEncoder,Aw=new TextDecoder,RU=class{constructor(e){this.bytes=e;this.at=0;this.view=new DataView(e.buffer,e.byteOffset,e.byteLength);}word(){if(this.at+vU>this.bytes.byteLength)return null;let e=this.view.getUint32(this.at,true);return this.at+=vU,e}run(){let e=this.word();if(e===null||this.at+e>this.bytes.byteLength)return null;let t=this.bytes.subarray(this.at,this.at+e);return this.at+=e,t}get done(){return this.at===this.bytes.byteLength}};function rje(i){let e=new RU(i),t=e.word(),n=e.word();if(t===null||n===null)return null;if(t===Hde.cancel)return {kind:"cancel",ticket:n};if(t!==Hde.request)return null;let r=e.word(),o=e.run(),s=e.run(),a=e.word();if(r===null||o===null||s===null||a===null)return null;let l=[];for(let u=0;u<a;u++){let d=e.run(),h=e.run();if(d===null||h===null)return null;l.push([Aw.decode(d),Aw.decode(h)]);}let c=e.run();return c===null||!e.done?null:{kind:"request",request:{ticket:n,timeoutMs:r,method:Aw.decode(o),url:Aw.decode(s),headers:l,body:c.slice()}}}function cA(i,e){SU(i,e.byteLength);for(let t of e)i.push(t);}function SU(i,e){i.push(e&255,e>>>8&255,e>>>16&255,e>>>24&255);}function ije(i,e,t,n,r){let o=[];SU(o,i),cA(o,uA.encode(e)),cA(o,uA.encode(t)),SU(o,n.length);for(let[s,a]of n)cA(o,uA.encode(s)),cA(o,uA.encode(a));return cA(o,r),Uint8Array.from(o)}var bw=class{constructor(e,t=(n,r)=>fetch(n,r)){this.port=e;this.fetcher=t;this.running=new Map;}get inFlight(){return this.running.size}pump(){for(let e=this.port.pending();e>0;e=this.port.pending()){let t=this.port.next(e);if(t===null)return;let n=rje(t);n!==null&&(n.kind==="cancel"?this.cancel(n.ticket):this.start(n.request));}}close(){for(let e of this.running.values())e.abort();this.running.clear();}cancel(e){let t=this.running.get(e);t!==void 0&&(this.running.delete(e),t.abort());}start(e){let t=new AbortController;this.running.set(e.ticket,t);let n=false,r=e.timeoutMs===eje?null:setTimeout(()=>{n=true,t.abort();},e.timeoutMs),o=new Headers;for(let[a,l]of e.headers)o.append(a,l);let s={method:e.method,headers:o,signal:t.signal};e.body.byteLength>0&&(s.body=new Uint8Array(e.body)),this.fetcher(e.url,s).then(async a=>{let l=new Uint8Array(await a.arrayBuffer());if(l.byteLength>Z$e)return this.fail(e.ticket,xU.tooLarge,nje);let c=[];a.headers.forEach((d,h)=>c.push([h,d]));let u=ije(a.status,a.statusText,a.url,c,l);this.running.delete(e.ticket)&&this.port.settle(e.ticket,J$e,u);}).catch(a=>{if(n)return this.fail(e.ticket,xU.timeout,tje);this.fail(e.ticket,xU.network,a instanceof Error?a.message:String(a));}).finally(()=>{r!==null&&clearTimeout(r);});}fail(e,t,n){this.running.delete(e)&&this.port.settle(e,t,uA.encode(n));}};yn();var Yde=13,TU=2,sje=0,aje=1,lje=2,cje=3,uje=4,dje=5,hje=6,pje=1;function wU(i){return {bytes:new Uint8Array(i),words:new Uint32Array(i),floats:new Float32Array(i)}}var mje=0,fje=1,_je=2,yje=3,Aje=4,bje=5,gje=6,Eje=7,xje=8,vje=9,Rje=10,Sje=11,Tje=12,wje="data-cimplify-ui-node",Ije="data-cimplify-ui-mirror",Oje="position:fixed;left:0;top:0;width:0;height:0;transform:translateZ(0);opacity:0;pointer-events:none;overflow:visible",Cje="position:fixed;margin:0;padding:0;border:0;overflow:hidden;",Nje=0,kje=-1,gw="true",Lje="polite",Mje=-1,Dje=(()=>{let i=[];return i[On.none]=null,i[On.group]="group",i[On.text]=null,i[On.button]="button",i[On.image]="img",i[On.header]="heading",i[On.link]="link",i[On.adjustable]="slider",i[On.tab]="tab",i[On.tab_list]="tablist",i[On.progress]="progressbar",i[On.text_field]="textbox",i[On.scroll_view]="region",i[On.alert]="alert",i})(),Pje=[[vr.selected,"aria-selected",gw],[vr.disabled,"aria-disabled",gw],[vr.hidden,"aria-hidden",gw],[vr.live,"aria-live",Lje],[vr.modal,"aria-modal",gw]],Fje=new Set(["Enter"," "]),Uje=new Set(["ArrowUp","ArrowRight"]),Bje=new Set(["ArrowDown","ArrowLeft"]),Gje="Escape",Vje=new TextDecoder;function Kde(i,e,t,n,r){return r===0||n+r>t?"":Vje.decode(i.subarray(e+n,e+n+r))}var Ew=class{constructor(e,t){this.document=e;this.perform=t;this.nodes=new Map;this.owners=new WeakMap;this.touched=[];this.generation=0;this.onClick=e=>{let t=this.owner(e.target);if(t===null)return;let n=this.nodes.get(t);n===void 0||(n.actions&Ri.activate)===0||(e.preventDefault(),this.perform(t,Ri.activate));};this.onKey=e=>{let t=e.key,n=this.owner(e.target);if(n===null)return;let r=this.nodes.get(n);if(r===void 0)return;let o=Fje.has(t)?Ri.activate:Uje.has(t)?Ri.increment:Bje.has(t)?Ri.decrement:t===Gje?Ri.dismiss:0;o===0||(r.actions&o)===0||(e.preventDefault(),this.perform(n,o));};let n=e.createElement("div");n.setAttribute("style",Oje),n.setAttribute(Ije,""),n.addEventListener("click",this.onClick),n.addEventListener("keydown",this.onKey),e.body.appendChild(n),this.root=n;}get size(){return this.nodes.size}element(e){return this.nodes.get(e)?.element??null}place(e,t,n,r){let o=this.root.style;o.left=`${e}px`,o.top=`${t}px`,o.width=`${n}px`,o.height=`${r}px`;}apply(e,t){let n=e.words,r=e.floats,o=t>>>TU,s=n[o+sje]===pje,a=n[o+aje]>>>TU,l=n[o+lje],c=n[o+cje]>>>TU,u=n[o+uje],d=n[o+dje],h=n[o+hje];this.generation++,this.touched.length=0;for(let p=0;p<l;p++){let m=a+p*Yde,f=n[m+mje];this.update(f,n[m+fje],n[m+_je],n[m+yje],n[m+Aje],r[m+bje],r[m+gje],r[m+Eje],r[m+xje],Kde(e.bytes,d,h,n[m+vje],n[m+Rje]),Kde(e.bytes,d,h,n[m+Sje],n[m+Tje])),this.touched.push(f);}for(let p=0;p<this.touched.length;p++)this.attach(this.touched[p]);for(let p=0;p<u;p++)this.remove(n[c+p]);if(s)for(let[p,m]of this.nodes)m.seen!==this.generation&&this.remove(p);}update(e,t,n,r,o,s,a,l,c,u,d){let h=this.nodes.get(e);if(h===void 0){let f=this.document.createElement("div");f.setAttribute(wje,String(e)),this.owners.set(f,e),h={element:f,parent:t,role:Mje,actions:0,text:null,seen:0},this.nodes.set(e,h);}h.seen=this.generation;let p=h.element;if(h.parent=t,h.actions=o,p.setAttribute("style",`${Cje}left:${s}px;top:${a}px;width:${l}px;height:${c}px`),h.role!==n){h.role=n;let f=Dje[n]??null;f===null?p.removeAttribute("role"):p.setAttribute("role",f);}n===On.text?(h.text===null?(h.text=this.document.createTextNode(u),p.insertBefore(h.text,p.firstChild)):h.text.nodeValue!==u&&(h.text.nodeValue=u),p.removeAttribute("aria-label")):(h.text!==null&&(h.text.remove(),h.text=null),u.length>0?p.setAttribute("aria-label",u):p.removeAttribute("aria-label")),d.length>0?p.setAttribute("aria-valuetext",d):p.removeAttribute("aria-valuetext");for(let[f,y,b]of Pje)(r&f)!==0?p.setAttribute(y,b):p.removeAttribute(y);let m=(o&Ri.activate)!==0&&(r&(vr.disabled|vr.hidden))===0;p.tabIndex=m||(o&(Ri.increment|Ri.decrement))!==0?Nje:kje;}attach(e){let t=this.nodes.get(e);if(t===void 0)return;let n=this.nodes.get(t.parent)?.element??this.root;t.element.parentNode!==n&&n.appendChild(t.element);}remove(e){let t=this.nodes.get(e);if(t===void 0)return;this.nodes.delete(e);let n=t.element,r=n.parentNode;if(r!==null){for(;n.firstElementChild!==null;)r.appendChild(n.firstElementChild);n.remove();}}clear(){for(this.nodes.clear();this.root.firstChild!==null;)this.root.firstChild.remove();}owner(e){let t=e instanceof Element?e:null;for(;t!==null&&t!==this.root;){let n=this.owners.get(t);if(n!==void 0&&this.nodes.has(n))return n;t=t.parentElement;}return null}dispose(){this.root.removeEventListener("click",this.onClick),this.root.removeEventListener("keydown",this.onKey),this.clear(),this.root.remove();}};var Hje="position:fixed;margin:0;padding:0;border:0;outline:none;background:transparent;color:transparent;caret-color:transparent;opacity:0;font-size:16px;box-sizing:border-box",Wje="data-cimplify-ui-input",qde="none",Kje="block",Yje="password",zde="text",Xje="numeric",qje="Enter",Wl=-1;function zje(i,e,t){let n=Math.min(Math.max(e,0),i.length),r=Math.min(n+t.length,i.length);return {start:mF(i,n),end:mF(i,r)}}var xw=class{constructor(e,t){this.sink=t;this.node=4294967295;this.composeStart=Wl;this.preedit="";this.onCompositionStart=()=>{let e=this.element;this.composeStart=e.selectionStart??e.value.length,this.preedit="";};this.onCompositionUpdate=e=>{this.composeStart===Wl&&this.onCompositionStart(),this.preedit=e.data??"";};this.onCompositionEnd=e=>{this.composeStart=Wl,this.preedit="",this.node!==4294967295&&this.sink.change(this.node,this.element.value,e.timeStamp,null);};this.onInput=e=>{this.node!==4294967295&&this.sink.change(this.node,this.element.value,e.timeStamp,this.composition());};this.onBlur=e=>{let t=this.node;t!==4294967295&&(this.node=4294967295,this.composeStart=Wl,this.preedit="",this.element.style.display=qde,this.sink.blur(t,e.timeStamp));};this.onKey=e=>{let t=e;t.isComposing||this.composeStart!==Wl||t.key===qje&&this.element.blur();};let n=e.createElement("input");n.setAttribute("style",Hje),n.setAttribute(Wje,""),n.setAttribute("autocomplete","off"),n.style.display=qde,n.addEventListener("input",this.onInput),n.addEventListener("blur",this.onBlur),n.addEventListener("keydown",this.onKey),n.addEventListener("compositionstart",this.onCompositionStart),n.addEventListener("compositionupdate",this.onCompositionUpdate),n.addEventListener("compositionend",this.onCompositionEnd),e.body.appendChild(n),this.element=n;}get focused(){return this.node}get composing(){return this.composeStart!==Wl}focus(e,t,n,r,o,s,a,l){let c=this.node;c!==4294967295&&c!==e&&this.sink.blur(c,l),this.node=e;let u=this.element,d=(s&uF.secure)!==0,h=(s&uF.numeric)!==0;u.type=d?Yje:zde,u.inputMode=h?Xje:zde,c!==e&&(u.value=a,this.composeStart=Wl,this.preedit="");let p=u.style;p.left=`${t}px`,p.top=`${n}px`,p.width=`${r}px`,p.height=`${o}px`,p.display=Kje,u.focus();}composition(){return this.composeStart===Wl?null:zje(this.element.value,this.composeStart,this.preedit)}dispose(){this.node=4294967295;let e=this.element;e.removeEventListener("input",this.onInput),e.removeEventListener("blur",this.onBlur),e.removeEventListener("keydown",this.onKey),e.removeEventListener("compositionstart",this.onCompositionStart),e.removeEventListener("compositionupdate",this.onCompositionUpdate),e.removeEventListener("compositionend",this.onCompositionEnd),e.remove();}};var $je=4096,jje=new TextDecoder,$de=new TextEncoder,Jje=0,jde=8,Zje=64,eJe=4*1024,Jde=Ae+512,tJe=1024,nJe=1e3,Zde=1e6,ehe=-1,rJe=1,iJe=0,oJe="position:fixed;left:0;top:0;width:0;height:0;visibility:hidden;pointer-events:none;padding:env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left)",Kl=2,sJe=ST>>>Kl,aJe=TT>>>Kl,lJe=wT>>>Kl,cJe=dF>>>Kl,uJe=hF>>>Kl,dJe=Vy>>>Kl,hJe=IT>>>Kl;function IU(i,e){if(e<=i.length)return i;let t=Math.max(i.length,32);for(;t<e;)t*=2;let n=new Uint8Array(t);return n.set(i),n}function Rw(i,e,t,n,r){for(let o=0;o<r;o++)i[e+o]=t[n+o];}function vw(i){let e=Number.parseFloat(i);return Number.isFinite(e)?e:0}var Sw=class{constructor(e,t,n={}){this.scope=e;this.deliver=t;this.pending=new Uint8Array(eJe);this.pendingView=new DataView(this.pending.buffer);this.pendingLength=0;this.pendingRecords=0;this.binding=null;this.dictionaryBytes=null;this.accessibility=n.accessibility??true,this.fallbackFonts=n.fallback_fonts??null,this.maxNodes=n.max_nodes??$je,this.maxPending=n.max_pending_bytes??fs.max_message_bytes,Qle(r=>{this.dictionaryBytes=r,this.binding?.installDictionaries(r);});}get bound(){return this.binding}get dictionaries(){return this.dictionaryBytes}get queued(){return this.pendingRecords}patch(e,t){if(t<Ae+12)return;let n=this.binding;if(n!==null&&n.ready()){n.apply(e,Ae,t-Ae);return}this.queue(e,t),n!==null&&n.start();}queue(e,t){let n=new DataView(e.buffer,e.byteOffset,t);if(n.getUint32(Ae,true)!==826889539)return;let r=n.getUint32(Ae+jde,true),o=this.pendingLength===0?Ae:Ae+12,s=t-o;if(this.pendingLength+s>this.maxPending)return;let a=IU(this.pending,this.pendingLength+s);a!==this.pending&&(this.pending=a,this.pendingView=new DataView(a.buffer)),Rw(this.pending,this.pendingLength,e,o,s),this.pendingLength+=s,this.pendingRecords+=r,this.pendingView.setUint32(jde,this.pendingRecords,true);}drain(e){if(this.pendingLength===0)return;let t=this.pendingLength;this.pendingLength=0,this.pendingRecords=0,e.apply(this.pending,0,t);}overlay(e,t,n,r){let o=Fde(e.exports);if(o===null)return null;this.binding?.release();let s=new OU(this,o,e.memory,t,n,r);return this.binding=s,this.pendingLength>0&&s.start(),s}unbind(e){this.binding===e&&(this.binding=null);}},OU=class{constructor(e,t,n,r,o,s){this.owner=e;this.exports=t;this.memory=n;this.canvas=r;this.render=o;this.pixelRatio=s;this.ui=Pt;this.events=new Uint8Array(Jde);this.eventViews=new Map;this.eventsLength=0;this.textEvents=new Uint8Array(Jde);this.writer=new gu(tJe);this.mirror=null;this.input=null;this.probe=null;this.width=0;this.height=0;this.left=0;this.top=0;this.insetTop=0;this.insetRight=0;this.insetBottom=0;this.insetLeft=0;this.lastFrame=ehe;this.released=false;this.failed=false;this.scheduled=false;this.fetches=new Map;this.fallbackFaces=new WeakSet;this.fallbackSlot=0;this.flushEvents=()=>{this.scheduled=false;let e=this.eventsLength;if(this.eventsLength=0,e<=Ae||this.released)return;let t=this.eventViews.get(e);t===void 0&&(t=this.events.subarray(0,e),this.eventViews.set(e,t)),this.owner.deliver(t);};this.textSink={change:(e,t,n,r)=>{this.ui!==Pt&&(this.writer.reset(),this.writer.text(e,t),this.apply(this.writer.bytes,0,this.writer.finish()),this.sendText(Eu.change,e,t,n,r));},blur:(e,t)=>{this.ui!==Pt&&(this.writer.reset(),this.writer.blur(e),this.apply(this.writer.bytes,0,this.writer.finish()),this.sendText(Eu.blur,e,"",t));}};this.perform=(e,t)=>{this.ui!==Pt&&this.exports.engine_ui_perform_action(this.ui,e,t);};this.heap=wU(n.buffer),this.events[0]=ee.game_ui_event,this.vectors=Ude(t),this.fetchExports=Wde(t),this.fallbackExports=Bde(t);}pumpFallbacks(){let e=this.fallbackExports,t=this.owner.fallbackFonts;if(!(e===null||t===null))for(let n=e.engine_ui_vector_fallback_request();n!==Vde;n=e.engine_ui_vector_fallback_request())t(n).then(r=>this.registerFallback(r),()=>{});}registerFallback(e){let t=this.fallbackExports;if(!(e===null||e.byteLength===0||t===null||this.ui===Pt||this.released)&&!this.fallbackFaces.has(e))for(this.fallbackFaces.add(e);this.fallbackSlot<Gde;){let n=this.stage(e);if(n===0)return;let r=t.engine_ui_vector_fallback_font(this.fallbackSlot,n,e.byteLength);if(this.fallbackSlot+=1,r!==Ao)return}}get vectorFetchSupported(){return this.fetchExports!==null}vectorFetch(e,t){let n=this.fetchExports;if(n===null||this.ui===Pt)return false;let r=$de.encode(t.join(`
148
+ `)),o=r.byteLength===0?0:this.stage(r);return r.byteLength>0&&o===0||n.engine_ui_vector_fetch_origins(this.ui,e,o,r.byteLength)<0?false:(this.fetches.has(e)||this.fetches.set(e,new bw(this.fetchPort(n,e))),true)}fetchPort(e,t){return {pending:()=>this.ui===Pt?0:Math.max(0,e.engine_ui_vector_fetch_pending(this.ui,t)),next:n=>{let r=this.exports.engine_ui_patch_buffer(this.ui,n);if(r===0)return null;let o=e.engine_ui_vector_fetch_next(this.ui,t,r,n);return o<=0?null:this.view().bytes.slice(r,r+o)},settle:(n,r,o)=>{if(this.ui===Pt)return false;let s=o.byteLength===0?0:this.stage(o);return o.byteLength>0&&s===0?false:e.engine_ui_vector_fetch_settle(this.ui,t,n,r,s,o.byteLength)>=0}}}get vectorSupported(){return this.vectors!==null}stage(e){let t=this.exports.engine_ui_patch_buffer(this.ui,e.byteLength);return t!==0&&Rw(this.view().bytes,t,e,0,e.byteLength),t}loadVector(e){let t=this.vectors;if(t===null||this.ui===Pt||e.byteLength===0)return Hl;let n=this.stage(e);if(n===0)return Hl;let r=t.engine_ui_vector_load(this.ui,n,e.byteLength);return r<0?Hl:r}unloadVector(e){return this.vectorCall((t,n)=>t.engine_ui_vector_unload(n,e))}attachVector(e,t,n=Jje){return this.vectorCall((r,o)=>r.engine_ui_vector_attach(o,e,t,n))}detachVector(e){return this.fetches.get(e)?.close(),this.fetches.delete(e),this.vectorCall((t,n)=>t.engine_ui_vector_detach(n,e))}playVector(e,t,n){return this.vectorCall((r,o)=>r.engine_ui_vector_play(o,e,t,n))}vectorInputIndex(e,t){let n=this.vectors;if(n===null||this.ui===Pt)return Hl;let r=$de.encode(t);if(r.byteLength===0)return Hl;let o=this.stage(r);if(o===0)return Hl;let s=n.engine_ui_vector_input_index(this.ui,e,o,r.byteLength);return s<0?Hl:s}vectorInput(e,t,n){let r=this.vectors;return r===null||this.ui===Pt?false:r.engine_ui_vector_input(this.ui,e,t,n)>=0}vectorCall(e){let t=this.vectors;return t===null||this.ui===Pt?false:e(t,this.ui)>=0}installDictionaries(e){if(this.ui===Pt||this.released)return false;let t=new gu(e.byteLength+Zje);return t.reset(),t.textDictionaries(e),this.apply(t.bytes,0,t.finish())>0}get handle(){return this.ui}get aria(){return this.mirror}get textInput(){return this.input}ready(){return this.ui!==Pt}start(){if(this.ui!==Pt||this.released||this.failed)return;let e=this.exports.engine_ui_create(this.render,this.owner.maxNodes);if(e===Pt){this.failed=true;return}this.ui=e;let t=this.owner.dictionaries;t!==null&&this.installDictionaries(t),this.measure(),this.owner.accessibility?(this.exports.engine_ui_accessibility(e,rJe),this.mirror=new Ew(this.owner.scope.document,this.perform),this.mirror.place(this.left,this.top,this.width,this.height)):this.exports.engine_ui_accessibility(e,iJe),this.owner.drain(this);}view(){let e=this.memory.buffer;return this.heap.bytes.buffer!==e&&(this.heap=wU(e)),this.heap}apply(e,t,n){if(this.ui===Pt)return 0;let r=this.exports.engine_ui_patch_buffer(this.ui,n);return r===0?0:(Rw(this.view().bytes,r,e,t,n),this.exports.engine_ui_apply(this.ui,n))}measure(){let e=this.canvas.getBoundingClientRect();this.left=e.left,this.top=e.top;let t=this.owner.scope,n=this.probe;n===null&&(n=t.document.createElement("div"),n.setAttribute("style",oJe),t.document.body.appendChild(n),this.probe=n);let r=t.getComputedStyle(n);this.insetTop=vw(r.paddingTop),this.insetRight=vw(r.paddingRight),this.insetBottom=vw(r.paddingBottom),this.insetLeft=vw(r.paddingLeft),this.viewport();}safeArea(e){e[vb]=this.insetTop,e[Rb]=this.insetRight,e[Sb]=this.insetBottom,e[Tb]=this.insetLeft;}viewport(){this.ui!==Pt&&this.exports.engine_ui_viewport(this.ui,this.width,this.height,this.pixelRatio,this.insetTop,this.insetRight,this.insetBottom,this.insetLeft);}resize(e,t,n){this.width=e,this.height=t,this.pixelRatio=n,this.ui!==Pt&&(this.measure(),this.mirror?.place(this.left,this.top,e,t));}pointer(e,t,n,r,o){return this.ui===Pt?false:this.exports.engine_ui_pointer(this.ui,e,t,n-this.left,r-this.top,o>>>0)===EU}wheel(e,t,n,r){return this.ui===Pt?false:this.exports.engine_ui_wheel(this.ui,e-this.left,t-this.top,n,r)===EU}frame(e){let t=this.ui;if(t===Pt)return;let n=this.lastFrame===ehe?0:Math.round((e-this.lastFrame)*nJe);this.lastFrame=e,this.exports.engine_ui_view_from_camera(t,this.render);let r=this.exports.engine_ui_frame(t,n<0?0:n>Zde?Zde:n);this.exports.engine_ui_render(t,this.render);for(let o of this.fetches.values())o.pump();if(this.pumpFallbacks(),!(r<0)&&((r&gU.events)!==0&&this.collect(),(r&gU.accessibility)!==0&&this.mirror!==null)){let o=this.exports.engine_ui_accessibility_export(t);o!==0&&this.mirror.apply(this.view(),o);}}collect(){let e=this.ui,t=this.exports.engine_ui_event_count(e),n=this.exports.engine_ui_events(e);if(t===0||n===0){this.exports.engine_ui_clear_events(e);return}let r=t*32,o=this.scheduled?this.eventsLength:Ae,s=o+r;s>this.events.length&&(this.events=IU(this.events,s),this.eventViews.clear());let a=this.view();Rw(this.events,o,a.bytes,n,r),this.eventsLength=s;for(let c=n;c<n+r;c+=32)a.bytes[c+RT]===Eu.focus&&this.focusInput(a,c>>>Kl);if(this.exports.engine_ui_clear_events(e),this.scheduled)return;this.scheduled=true;let l=this.owner.scope.queueMicrotask;l!==void 0?l.call(this.owner.scope,this.flushEvents):Promise.resolve().then(this.flushEvents);}focusInput(e,t){let n=e.words,r=e.floats,o=n[t+sJe],s=this.left+r[t+aJe],a=this.top+r[t+lJe],l=r[t+cJe],c=r[t+uJe],u=r[t+dJe]|0,d=n[t+hJe],h=this.input;h===null&&(h=new xw(this.owner.scope.document,this.textSink),this.input=h),h.focus(o,s,a,l,c,u,this.nodeText(e,o),d);}nodeText(e,t){let n=this.exports.engine_ui_text_length(this.ui,t);if(n<=0)return "";let r=this.exports.engine_ui_text(this.ui,t);if(r===0)return "";let o=this.memory.buffer===e.bytes.buffer?e.bytes:this.view().bytes;return jje.decode(o.subarray(r,r+n))}sendText(e,t,n,r,o=null){let s=Ae+Tce(n);s>this.textEvents.length&&(this.textEvents=IU(this.textEvents,s));let a=this.textEvents;a[0]=ee.game_ui_event;let l=wce(a,Ae,e,t,n,r,o);this.owner.deliver(a.subarray(0,Ae+l));}release(){if(!this.released){this.released=true,this.input?.dispose(),this.input=null,this.mirror?.dispose(),this.mirror=null,this.probe?.remove(),this.probe=null;for(let e of this.fetches.values())e.close();this.fetches.clear(),this.ui!==Pt&&this.exports.engine_ui_destroy(this.ui),this.ui=Pt,this.owner.unbind(this);}}};PU();yn();var hA=class extends Error{constructor(){super("the Interactive ran past its time slice without returning to the host"),this.name="SliceExceeded";}};var FU=0,ww=class{constructor(e){this.budget=e;this.counter=new Int32Array(1);this.exceeded=false;this.tick=()=>{let e=this.counter;++e[FU]<1024||this.check();};}get dead(){return this.exceeded}begin(){this.exceeded||this.budget.begin();}check(){let e=this.counter;if(e[FU]=0,!this.exceeded){if(!this.budget.over())return;this.exceeded=true;}throw e[FU]=1024,new hA}};yn();var pA=class extends Error{constructor(e){super(e),this.name="TreeError";}},LJe="",MJe=[];function hhe(i){return i.children??MJe}var UU=class{constructor(){this.nodes=0;}admit(e){if(this.nodes+=1,this.nodes>fs.max_tree_nodes)throw new pA(`a tree may hold at most ${fs.max_tree_nodes} nodes`);if(e>fs.max_tree_depth)throw new pA(`a tree may nest at most ${fs.max_tree_depth} levels`)}};function phe(i,e,t){if(typeof i!="object"||i===null||typeof i.type!="string")throw new pA("every tree node needs a string type");t.admit(e);let r=hhe(i).map(o=>phe(o,e+1,t));return {type:i.type,key:i.key??null,props:i.props===void 0?LJe:JSON.stringify(i.props),children:r}}function BU(i,e){return i.type===e.type&&i.key===e.key}var Iw=class{constructor(){this.shadow=null;}diff(e){let t=[];if(e===null)return this.shadow!==null&&t.push({op:"root",node:null}),this.shadow=null,t;let n=phe(e,0,new UU),r=this.shadow;return this.shadow=n,r===null||!BU(r,n)?(t.push({op:"root",node:e}),t):(GU(r,n,e,[],t),t)}};function GU(i,e,t,n,r){i.props!==e.props&&r.push({op:"props",at:n.slice(),props:t.props??null});let o=i.children,s=e.children,a=hhe(t),l=0,c=o.length<s.length?o.length:s.length;for(;l<c&&BU(o[l],s[l]);)l++;let u=0;for(;u<c-l&&BU(o[o.length-1-u],s[s.length-1-u]);)u++;for(let p=0;p<l;p++)n.push(p),GU(o[p],s[p],a[p],n,r),n.pop();let d=o.length-l-u,h=s.length-l-u;if(d>0||h>0){let p=a.slice(l,l+h);r.push({op:"splice",at:n.slice(),start:l,remove:d,insert:p});}for(let p=0;p<u;p++){let m=o.length-u+p,f=s.length-u+p;n.push(f),GU(o[m],s[f],a[f],n,r),n.pop();}}var PJe=5e3,FJe=3e5,UJe={ai:12e4,compute:6e4,worker:6e4,agent:12e4,flow:3e5,share:3e5,camera:3e5},_he=d8,mhe="never",fhe=".";function BJe(i){let e=i;for(;!(e in _he);){let t=e.lastIndexOf(fhe);if(t<0)return i.slice(0,Math.max(0,i.indexOf(fhe)));e=e.slice(0,t);}return e}function GJe(i){let e=UJe[i];return e!==void 0?e:(_he[i]?.confirmation??mhe)===mhe?PJe:FJe}function VJe(){return typeof globalThis.setTimeout=="function"?globalThis.setTimeout.bind(globalThis):null}function HJe(){return typeof globalThis.clearTimeout=="function"?globalThis.clearTimeout.bind(globalThis):null}var WJe=new hA().message,KJe={ready:"ready",visible:"visible",hidden:"hidden",suspend:"suspended",resume:"visible",revision_update:null,dispose:"disposed"};function YJe(i,e){return i instanceof Error?i.message:e==="slice"?WJe:typeof i=="object"&&i!==null?JSON.stringify(i):String(i)}function Ow(i,e){let t=i.indexOf(e);t>=0&&i.splice(t,1);}var Cw=class{constructor(e){this.options=e;this.writer=new BA;this.pending=new Map;this.subscriptions=new Map;this.families=new Map;this.uiListeners=[];this.gameUiListeners=[];this.replies=new Map;this.lifecycleListeners=new Map;this.disposers=[];this.replayListeners=[];this.heldReplay=null;this.differ=new Iw;this.pong=new Uint8Array(AI);this.milestoneMessage=new Uint8Array(yI);this.completeMessage=new Uint8Array(UA);this.reached=new Set;this.pongView=new DataView(this.pong.buffer);this.boot=null;this.state="loading";this.nextRequest=0;this.nextCommand=0;this.sliceReported=false;this.arriving=[];this.wanted=new Map;this.requested=new Yp(ee.chunk_request,D6);this.released=new Yp(ee.chunk_release,P6);this.chunkFlushQueued=false;this.studioIn=new DS;this.studioOut=new PS(ee.studio_report,e=>this.bridge.send(e,e.length));this.flushChunks=()=>{this.chunkFlushQueued=false,this.released.size>0&&this.bridge.send(this.released.bytes,this.released.seal()),this.requested.size>0&&this.bridge.send(this.requested.bytes,this.requested.seal());};this.chunkChannel={request:(e,t)=>this.queueChunk(this.requested,e,t),release:e=>this.queueChunk(this.released,e,Je.now)};this.starting=false;this.startTimer=void 0;this.stopTimer=void 0;this.lifecycle=XJe(this);this.bridge=e.bridge,this.services=e.services,this.assembler=new Tw(e.on_runtime_wasm??null,e.native_runtimes??null,e.assets??null),this.lane=new XS(this.bridge),this.bridge.on_message(t=>this.receive(t)),Dae(t=>this.send(this.writer.json(ee.meter_report,t)),e.heap_bytes??null),this.pong[0]=ee.pong,this.send(this.writer.tag(ee.ready));}get program(){return this.boot.program}get locale(){return this.boot.locale}get clock_offset_ms(){return this.boot.clock_offset_ms}current(){return this.state}onLifecycle(e,t){let n=this.lifecycleListeners.get(e)??[];return n.push(t),this.lifecycleListeners.set(e,n),()=>Ow(n,t)}needRuntime(e,t=Je.now){let n=this.assembler.lateRuntime(e);return n===null||this.assembler.holdsWasm(n)?false:(this.queueChunk(this.requested,n,t),true)}mark(e){let t=C6[e];this.reached.has(t)||(this.reached.add(t),this.milestoneMessage[0]=ee.milestone,this.milestoneMessage[1]=t,this.bridge.send(this.milestoneMessage,yI));}send(e){this.bridge.send(this.writer.bytes,e);}fault(e,t){if(this.services.slice.dead){if(this.sliceReported)return;this.sliceReported=true,e="slice";}let n={phase:e,message:YJe(t,e),stack:t instanceof Error&&typeof t.stack=="string"?t.stack:null};this.send(this.writer.json(ee.fault,n));}call(e,t){let n=this.boot,r=`g${this.nextRequest++}`,o={contract_version:1,request_id:r,interactive_id:n.program.interactive_id,revision:n.program.revision,deadline_ms:n.deadline_ms,call:{operation:e,arguments:t}},s=BJe(e),a=this.options.request_deadline_ms?.(s)??GJe(s);this.startTimer??=VJe();let l=this.startTimer;return new Promise((c,u)=>{let d=l===null?null:l(()=>this.expire(r,s),a);this.pending.set(r,{resolve:c,reject:u,timer:d}),this.send(this.writer.json(ee.request,o));})}expire(e,t){let n=this.pending.get(e);n!==void 0&&(this.pending.delete(e),n.reject({code:"unavailable",family:t,retry_after_ms:null}));}subscribe(e,t){return this.listen(this.subscriptions,e.subscription_id,t)}family(e,t){return this.listen(this.families,e,t)}listen(e,t,n){return e.set(t,[...e.get(t)??[],n]),()=>{let r=(e.get(t)??[]).filter(o=>o!==n);r.length===0?e.delete(t):e.set(t,r);}}render(e){if(this.state!=="disposed")try{let t=this.differ.diff(e);t.length>0&&this.send(this.writer.json(ee.render,t));}catch(t){this.fault("render",t);}}command(e,t){let n=t?++this.nextCommand:0;return this.send(this.writer.json(ee.ui_command,{id:n,command:e})),t?new Promise(r=>this.replies.set(n,r)):Promise.resolve(void 0)}on_ui(e){return this.uiListeners.push(e),()=>Ow(this.uiListeners,e)}complete(e){this.state!=="disposed"&&this.bridge.send(this.completeMessage,N6(this.completeMessage,e));}game_ui(e,t){this.state!=="disposed"&&(e[0]=ee.game_ui,this.bridge.send(e,t));}on_game_ui(e){return this.gameUiListeners.push(e),()=>Ow(this.gameUiListeners,e)}dispatchGameUi(e){for(let t=0;t<this.gameUiListeners.length;t++)try{this.gameUiListeners[t](e);}catch(n){this.fault("run",n);}}on_dispose(e){this.disposers.push(e);}receive(e){this.services.slice.begin();try{this.handle(e);}catch(t){this.fault("run",t);}this.services.slice.dead&&this.fault("slice",null);}notify(e,t){if(e!==void 0)for(let n=0;n<e.length;n++)try{e[n](t);}catch(r){this.fault("run",r);}}handle(e){switch(e[0]){case ee.response:this.answer(Ti(e));return;case ee.event:this.deliver(Ti(e));return;case ee.frames:this.lane.receive(e);return;case ee.ui_event:this.dispatchUi(Ti(e));return;case ee.ui_reply:this.reply(Ti(e));return;case ee.game_ui_event:this.dispatchGameUi(e);return;case ee.ping:this.answerPing(e);return;case ee.lifecycle:this.transition(O6[e[Ae]]??null);return;case ee.boot:this.boot=Ti(e),this.options.on_boot?.(this.boot),(this.boot.chunk_requests??0)>=M6&&this.options.assets?.connect?.(this.chunkChannel),this.boot.network!==void 0&&this.options.assets?.network?.(this.boot.network);return;case ee.network:{let t=mae(e);t!==null&&this.options.assets?.network?.(t);return}case ee.inspector:Vj(e[Ae]===k6);return;case ee.meters:Lae(Ti(e));return;case ee.studio:{ale(n=>this.studioOut.post(n));let t=this.studioIn.accept(e);t!==null&&cle(t);return}case ee.chunk_failed:this.chunkFailed(e);return;case ee.chunk:this.acceptChunk(e);return;case ee.stage:this.stageChunk(e);return;case ee.chunk_ref:this.acceptRef(e,false);return;case ee.stage_ref:this.acceptRef(e,true);return;case ee.warm:this.warm(Ti(e));return;case ee.start:this.start();return;case ee.hot:this.hot(Ti(e));return;case ee.replay:{let t=G8(e);if(t===null)return;this.replayListeners.length===0&&(this.heldReplay=t);for(let n=0;n<this.replayListeners.length;n++)this.replayListeners[n](t.replay,t.mode);return}}}on_replay(e){this.replayListeners.push(e);let t=this.heldReplay;return this.heldReplay=null,t!==null&&e(t.replay,t.mode),()=>Ow(this.replayListeners,e)}async hot(e){let t=o=>this.send(this.writer.json(ee.hot_done,o)),n=this.services.linker;if(!this.starting||this.state==="loading"||this.state==="disposed")return t({swapped:false,reason:"the Interactive is not running"});if(n.relink===void 0)return t({swapped:false,reason:"this host cannot swap code in place"});if(!Dee())return t({swapped:false,reason:"the Interactive does not accept code swaps"});await this.arrivals();let r=this.assembler.swapIndex(e.chunks);if(r===null)return t({swapped:false,reason:"more than the code and assets changed"});try{let{entry:o,modules:s}=this.assembler.modules(new Set(this.boot?.bytecode_modules??[])),a=await Uee(()=>n.relink.call(n,s,o,this.services.slice.tick)),l=Pee(a,r);t(l===null?{swapped:!1,reason:"the new code has no hot export"}:{swapped:!0,report:l});}catch(o){t({swapped:false,reason:o instanceof Error?o.message:String(o)});}}acceptChunk(e){DI()?.chunk(e.length-Ae-Ft);try{this.assembler.accept(e.subarray(Ae,Ae+Ft),e.subarray(Ae+Ft));}catch(t){this.fault("boot",t);}this.arrived(e);}arrived(e){if(this.wanted.size===0)return;let t=wi(e.subarray(Ae,Ae+Ft)),n=this.wanted.get(t);n!==void 0&&(this.wanted.delete(t),n());}acceptRef(e,t){let n=wi(e.subarray(Ae,Ae+Ft)),r=wi(e.subarray(Ae+Ft,Ae+Ft+Ft));this.arriving.push(this.fetchRef(n,r,t));}async fetchRef(e,t,n){let r=this.options.fetch_wasm?.(e,t)??null,o=r===null?null:await r.catch(()=>null);if(o===null){await this.want(e);return}n?this.options.on_staged_wasm?.(e,this.assembler.stage(e,o)):this.assembler.acceptWasmPayload(e,o);}want(e){return new Promise(t=>{this.wanted.set(e,t),this.queueChunk(this.requested,e,Je.now);})}queueChunk(e,t,n){e.full&&this.flushChunks(),e.add(t,n)&&(this.chunkFlushQueued||(this.chunkFlushQueued=true,queueMicrotask(this.flushChunks)));}chunkFailed(e){let t=F6(e);t!==null&&(this.wanted.has(t.digest)&&(this.wanted.delete(t.digest),this.fault("boot",new Error(`the host could not deliver chunk ${t.digest} (${t.reason})`))),this.options.assets?.fail?.(t.digest,t.reason));}async arrivals(){for(;this.arriving.length>0;)await Promise.all(this.arriving.splice(0));}async warm(e){await this.arrivals(),await this.options.on_warm?.(e)?.catch(()=>{}),this.send(this.writer.tag(ee.warmed));}stageChunk(e){try{let t=DU(e.subarray(Ae+Ft)),n=wi(e.subarray(Ae,Ae+Ft));t.kind===Jr.data?this.options.assets?.accept(n,t.payload):t.kind===Jr.wasm?this.options.on_staged_wasm?.(n,this.assembler.stage(n,t.payload)):t.kind===Jr.code&&this.options.on_staged_code?.(this.assembler.stageCode(n,t.payload));}catch(t){this.fault("boot",t);}this.arrived(e);}answerPing(e){this.pong[1]=e[1],this.pong[2]=e[2],this.pong[3]=e[3],this.pong[4]=e[4],this.pongView.setFloat64(5,this.options.heap_bytes?.()??0,true),this.bridge.send(this.pong,AI);}answer(e){let t=this.pending.get(e.request_id);t!==void 0&&(this.pending.delete(e.request_id),this.stopTimer??=HJe(),t.timer!==null&&this.stopTimer!==null&&this.stopTimer(t.timer),e.outcome.status==="ok"?t.resolve(e.outcome.response.result):t.reject(e.outcome.error));}deliver(e){let t=e.event;if(t.family==="ui"){this.dispatchUi(t.event);return}this.notify(this.subscriptions.get(e.subscription_id),t),this.notify(this.families.get(t.family),t);}dispatchUi(e){if(this.state==="disposed")return;let t=this.uiListeners.slice();for(let n=0;n<t.length;n++)try{t[n](e);}catch(r){this.fault("run",r);}}reply(e){let t=this.replies.get(e.id);t!==void 0&&(this.replies.delete(e.id),t(e.value));}transition(e){if(e===null||this.state==="disposed")return;let t=KJe[e];t!==null&&(this.state=t);let n=(this.lifecycleListeners.get(e)??[]).slice();for(let r of n)try{r();}catch(o){this.fault("run",o);}if(e==="dispose"){for(let r=this.disposers.length-1;r>=0;r--)try{this.disposers[r]();}catch(o){this.fault("run",o);}this.disposers.length=0,this.uiListeners.length=0,this.lane.flush(),this.send(this.writer.tag(ee.disposed));}}async start(){if(this.boot===null||this.state!=="loading"||this.starting){this.fault("start",new Error("start arrived before boot or twice"));return}this.starting=true,await this.arrivals();try{this.services.harden();}catch(t){this.fault("guard",t);return}let e;try{let{entry:t,modules:n,runtimes:r}=this.assembler.modules(new Set(this.boot.bytecode_modules??[])),o=await this.services.linker.link(n,t,this.services.slice.tick,r);if(typeof o.default!="function")throw new Error(`${t} does not export a default function`);e=o.default;}catch(t){this.fault("link",t);return}this.mark("linked");try{let t=(this.options.ctx??hw)(this);this.transition("ready"),this.mark("main_entered"),await e(t);}catch(t){this.fault("start",t);return}this.current()==="ready"&&this.transition("visible"),this.send(this.writer.tag(ee.started));}};function XJe(i){return {get state(){return i.current()},on:(e,t)=>i.onLifecycle(e,t)}}PU();function yhe(i=globalThis){let e=i.requestAnimationFrame?.bind(i);return {task:t=>queueMicrotask(t),frame:e===void 0?t=>queueMicrotask(t):t=>{e(t);}}}var Nw=class{constructor(e,t){this.port=e;this.scheduler=t;this.free=[];this.transfer=[new ArrayBuffer(0)];this.listener=()=>{};this.buffer=null;this.bytes=new Uint8Array(0);this.view=new DataView(new ArrayBuffer(4));this.used=4;this.taskPending=false;this.framePending=false;this.allocatedCount=0;this.batchCount=0;this.recordCount=0;this.flushTask=()=>{this.taskPending=false,this.flush();};this.flushFrame=()=>{this.framePending=false,this.flush();};e.addEventListener("message",n=>this.receive(n.data)),e.start?.();}get stats(){return {allocated:this.allocatedCount,batches:this.batchCount,records:this.recordCount}}get pooled(){return this.free.length}on_message(e){this.listener=e;}send(e,t){this.write(e,t),this.scheduleTask();}sendFrame(e,t){this.write(e,t),this.scheduleFrame();}write(e,t){let n=this.reserve(t);this.bytes.set(e.subarray(0,t),n);}reserve(e){let t=4+e;if(4+t>65536)return this.dedicated(e);(this.buffer===null||this.used+t>65536)&&(this.flush(),this.open()),this.view.setUint32(this.used,e,true);let n=this.used+4;return this.used+=t,this.recordCount++,n}get out(){return this.bytes}commitFrame(){this.scheduleFrame();}commitTask(){this.scheduleTask();}dedicated(e){this.flush();let t=new ArrayBuffer(8+e);return this.buffer=t,this.bytes=new Uint8Array(t),this.view=new DataView(t),this.view.setUint32(4,e,true),this.used=t.byteLength,this.recordCount++,8}open(){let e=this.free.pop();e===void 0&&(e=new ArrayBuffer(65536),this.allocatedCount++),this.buffer=e,this.bytes=new Uint8Array(e),this.view=new DataView(e),this.used=4;}scheduleTask(){this.taskPending||(this.taskPending=true,this.scheduler.task(this.flushTask));}scheduleFrame(){this.framePending||this.taskPending||(this.framePending=true,this.scheduler.frame(this.flushFrame));}flush(){let e=this.buffer;e===null||this.used===4||(this.view.setUint32(0,this.used,true),this.buffer=null,this.used=4,this.batchCount++,this.post(e));}post(e){this.transfer[0]=e,this.port.postMessage(e,this.transfer);}receive(e){if(e.byteLength<4)return;let t=new DataView(e),n=t.getUint32(0,true);if(n===0){e.byteLength===65536&&this.free.push(e);return}let r=Math.min(n,e.byteLength),o=4;for(;o+4<=r;){let s=t.getUint32(o,true);o+=4,this.listener(new Uint8Array(e,o,s)),o+=s;}e.byteLength===65536&&(t.setUint32(0,0,true),this.post(e));}};yn();var VU="@cimplify/engine-audio";var WU="legacy",qJe=new Uint8Array([0,97,115,109,1,0,0,0,1,4,1,96,0,0,3,2,1,0,13,3,1,0,0,10,11,1,9,0,6,64,8,0,7,0,11,11]),zJe=new Uint8Array([0,97,115,109,1,0,0,0,1,4,1,96,0,0,3,2,1,0,13,3,1,0,0,10,15,1,13,0,2,64,31,64,1,2,0,8,0,11,11,11]);function Ahe(i,e){try{return i(e)}catch{return false}}var HU=globalThis.WebAssembly,QJe=typeof HU?.validate=="function"?HU.validate.bind(HU):null;function KU(i=QJe){return i===null?{legacy:false,exnref:false}:{legacy:Ahe(i,qJe),exnref:Ahe(i,zJe)}}function YU(i,e){return e==="legacy"?i.legacy:i.exnref}Cm();var $Je="application/wasm",jJe="content-type",JJe=typeof WebAssembly>"u"?null:WebAssembly,bhe=i=>{let e=JJe;if(e===null)return Promise.reject(new Error("this browser cannot run the script runtime"));let t=typeof e.compileStreaming=="function"&&(i.headers.get(jJe)??"").startsWith($Je);return Om(t?e.compileStreaming(i):i.arrayBuffer().then(n=>e.compile(n)))},kw=class{constructor(e=bhe){this.compile=e;this.compiled=new Map;this.started=0;}get compilations(){return this.started}has(e){return this.compiled.has(e)}get(e){return this.compiled.get(e)??null}streamed(e,t){return this.remember(e,()=>t().then(n=>{if(!n.ok)throw new Error(`the script runtime answered ${n.status}`);return this.compile(n)}))}adopt(e,t){return this.remember(e,()=>Om(t()))}remember(e,t){let n=this.compiled.get(e);if(n!==void 0)return n;this.started++;let r=t();return this.compiled.set(e,r),r.catch(()=>{this.compiled.get(e)===r&&this.compiled.delete(e);}),r}},XU=new kw;ghe();var xhe="@cimplify/engine-luau";var vhe="@cimplify/engine-core-scripts";var Ehe=null;function Rhe(){return Ehe??=KU(),YU(Ehe,WU)}var eZe=250,She=",";var tZe=0,nZe=8,The="Ed25519",qU=-1;function rZe(i){let e=new Float64Array(1);return e[0]=qU,{begin(){e[0]=qU;},over(){let t=i();return e[0]===qU?(e[0]=t,false):t-e[0]>2e3}}}function whe(i,e,t){let n=new Int32Array(e,0,1),r=new Float64Array(e,nZe,1),o=()=>{Atomics.add(n,tZe,1),r[0]=t();};o(),i.setInterval(o,eZe);}var Ihe=()=>0,iZe=["requestAnimationFrame","setTimeout","setInterval"];function oZe(i,e){for(let t of iZe){let n=i[t];if(typeof n!="function")continue;let r=n.bind(i);i[t]=(o,...s)=>{if(typeof o!="function")return r(o,...s);let a=o;return r((...l)=>(e(),a(...l)),...s)};}}function sZe(i,e){let t=i.requestAnimationFrame;i.requestAnimationFrame=n=>(i.requestAnimationFrame=t,e("first_frame_scheduled"),t.call(i,n));}function aZe(i,e,t){let n=i.location?.origin!==void 0&&i.location.origin!==Mde;n&&Pde(i.document,i);let r=n&&typeof i.fetch=="function"?Dde(i.fetch.bind(i)):null,o=i.performance.now.bind(i.performance),s=Date.now,a=i.crypto.subtle,l=i.crypto.getRandomValues.bind(i.crypto),c=i.performance.memory,u=q=>import(q),d=new Nw(e,yhe(i)),h=new YA(d),p=new ub(d),m=new bb(d),f=()=>{},y=new yb(i,d,{canvas:()=>q8(i.document),audio:()=>Y.clipStream()});d.on_message(q=>{!h.receive(q)&&!p.receive(q)&&!m.receive(q)&&!y.receive(q)&&f(q);});let b=new Sw(i,q=>f(q),{accessibility:t.game_ui_accessibility,fallback_fonts:m.source}),A={send(q,he){q[0]===ee.game_ui?b.patch(q,he):q[0]===ee.frames?d.sendFrame(q,he):d.send(q,he);},on_message(q){f=q;}},E=null,R=null,g=new Map,v=null,x=null,O=null,N=eI(void 0),I=null,S=null,w=()=>I!==null?I:Fe.needRuntime(VU,Je.soon)?(I=new Promise(q=>{S=q;}),I):null,U=q=>{if(q.kind!=="engine")return q;let he=w();return he===null?q:{kind:"engine",runtime:{...q.runtime,audio_context:()=>Y.audioContext(),audio_worklet:he}}},L=()=>{let q=E??v;return O??=q===null?Promise.resolve(Tde):Promise.all([q,v]).then(([he,ot])=>b6(he,ot===null?{session:t.engine_session,memoryPages:N}:{threaded:ot,session:t.engine_session,memoryPages:N})).then(U),O},k=new ww(rZe(o));oZe(i,()=>k.begin());let M={mark:()=>{}},K=new mw(i,L,q=>M.mark(q),b),Y=new _w(i),te=r===null?new em(null,q=>WebAssembly.compile(q)):new em((q,he)=>r.joined(q,he)),Z=new yw(i),de={graphics:K,audio:Y,assets:te,loop:Z,camera:new dw(p),dialers:q=>({primary:q.web_transport?h.dialer(ri.WebTransport,q.web_transport):null,fallback:q.web_socket?h.dialer(ri.WebSocket,q.web_socket):null})},Oe=uhe(dhe(che,u)),be=c===void 0?Ihe:()=>c.usedJSHeapSize,ke=typeof SharedArrayBuffer=="function"&&t.heartbeat instanceof SharedArrayBuffer?t.heartbeat:null;ke!==null&&whe(i,ke,be);let De={linker:lhe(Oe,(q,he)=>q===GA&&he===R?E:q===VA&&he===x?v:null),slice:k,harden:()=>Ide(i),now_ms:()=>s(),random_fill:q=>{l(q);},async verify_ed25519(q,he,ot){let Vt=await a.importKey("raw",new Uint8Array(q),{name:The},false,["verify"]);return a.verify({name:The},Vt,new Uint8Array(ot),new Uint8Array(he))}},Fe=new Cw({bridge:A,services:De,heap_bytes:be,on_boot:q=>{N=eI(q.engine_heap_bytes);},on_runtime_wasm:(q,he,ot)=>{if((q===GA||q===vhe||q===g6)&&t.engine==="core"&&R!==he&&(R=he,E=r?.compiled(ot)??WebAssembly.compile(he)),q===VA&&t.engine==="core"&&v===null&&(x=he,v=r?.compiled(ot)??WebAssembly.compile(he)),q===VU){let Vt=r?.compiled(ot)??WebAssembly.compile(he);S!==null?S(Vt):I??=Vt,S=null;}q===xhe&&Rhe()&&XU.adopt(ot,()=>r?.compiled(ot)??WebAssembly.compile(he));},fetch_wasm:r===null?void 0:(q,he)=>r.fetch(q,he),assets:te,on_staged_code:q=>Oe.prepare(q),on_staged_wasm:(q,he)=>{g.set(q,he);},on_warm:q=>{let he=[],ot=new Map;for(let _t of Object.values(q.files))ot.set(_t.join(She),te.binary(_t));for(let[_t,dt]of Object.entries(q.files)){let _n=_t===GA&&t.engine==="core"?g.get(dt[0])??null:null,Bn=_t===VA&&t.engine==="core"&&v===null?g.get(dt[0])??null:null;if(Bn!==null)x=Bn,v=r?.compiled(dt[0])??WebAssembly.compile(Bn),he.push(K.prewarm_engine());else if(_n!==null)R=_n,E=r?.compiled(dt[0])??WebAssembly.compile(_n),he.push(K.prewarm_engine());else if(_t.endsWith(I6)){let Zr=te.warm(dt,zn=>XA(te,zn));Zr!==null&&he.push(Zr);}}let Vt=z6({assets:te,binary:_t=>ot.get(_t.join(She))??null,prepare:(_t,dt)=>K.prepare(_t,dt),hold:(_t,dt)=>K.hold(_t,dt)},q.files);return Vt!==null&&he.push(Vt),Promise.all(he)},ctx:q=>hw(q,de)});M.mark=q=>Fe.mark(q),Fe.onLifecycle("ready",()=>sZe(i,M.mark));let Ze=()=>{Z.hold(),Y.suspend();},wt=()=>{Z.release(),Y.resume();};return Fe.onLifecycle("hidden",Ze),Fe.onLifecycle("suspend",Ze),Fe.onLifecycle("visible",wt),Fe.onLifecycle("resume",wt),Fe.onLifecycle("dispose",()=>{Z.stop(),p.dispose(),y.dispose();}),Fe}function Ohe(i){let e=i.performance.memory,t=r=>{let o=r.data?.heartbeat;r.source!==i.parent||typeof SharedArrayBuffer!="function"||!(o instanceof SharedArrayBuffer)||(i.removeEventListener("message",t),whe(i,o,e===void 0?Ihe:()=>e.usedJSHeapSize));},n=r=>{r.source!==i.parent||r.ports.length!==1||(i.removeEventListener("message",n),aZe(i,r.ports[0],r.data),i.addEventListener("message",t));};i.addEventListener("message",n);}Ohe(globalThis);})();