@mountaya/elements 0.0.0-stage → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (828) hide show
  1. package/CHANGELOG.md +273 -0
  2. package/LICENCE.fr.txt +280 -0
  3. package/LICENSE.txt +262 -0
  4. package/README.md +1510 -2
  5. package/THIRD-PARTY-NOTICES.txt +103 -0
  6. package/dist/agent/index.cjs +1211 -0
  7. package/dist/agent/index.cjs.map +1 -0
  8. package/dist/agent/index.d.cts +1966 -0
  9. package/dist/agent/index.d.ts +1966 -0
  10. package/dist/agent/index.js +1181 -0
  11. package/dist/agent/index.js.map +1 -0
  12. package/dist/camera/index.cjs +2512 -0
  13. package/dist/camera/index.cjs.map +1 -0
  14. package/dist/camera/index.d.cts +1723 -0
  15. package/dist/camera/index.d.ts +1723 -0
  16. package/dist/camera/index.js +2443 -0
  17. package/dist/camera/index.js.map +1 -0
  18. package/dist/chunk-5pTPpv4v.d.cts +897 -0
  19. package/dist/chunk-5pTPpv4v.d.ts +897 -0
  20. package/dist/chunk-6JzFMFHh.d.ts +119 -0
  21. package/dist/chunk-6qyuJVvt.d.ts +513 -0
  22. package/dist/chunk-9fp0lDic.cjs +583 -0
  23. package/dist/chunk-9fp0lDic.cjs.map +1 -0
  24. package/dist/chunk-A48H1rDg.d.cts +73 -0
  25. package/dist/chunk-A48H1rDg.d.ts +73 -0
  26. package/dist/chunk-B-m1AchR.cjs +57 -0
  27. package/dist/chunk-B-m1AchR.cjs.map +1 -0
  28. package/dist/chunk-B-qFTf04.d.ts +216 -0
  29. package/dist/chunk-B0YROiZh.d.cts +1475 -0
  30. package/dist/chunk-B14wgOvH.d.cts +68 -0
  31. package/dist/chunk-B19l3j9r.cjs +150 -0
  32. package/dist/chunk-B19l3j9r.cjs.map +1 -0
  33. package/dist/chunk-B2PtjVKg.cjs +86 -0
  34. package/dist/chunk-B2PtjVKg.cjs.map +1 -0
  35. package/dist/chunk-B56Oyb7W.cjs +70 -0
  36. package/dist/chunk-B56Oyb7W.cjs.map +1 -0
  37. package/dist/chunk-B5WGMQwK.cjs +113 -0
  38. package/dist/chunk-B5WGMQwK.cjs.map +1 -0
  39. package/dist/chunk-B98mKrdu.d.cts +302 -0
  40. package/dist/chunk-BB0PmqIM.d.cts +44 -0
  41. package/dist/chunk-BBikve0Z.cjs +269 -0
  42. package/dist/chunk-BBikve0Z.cjs.map +1 -0
  43. package/dist/chunk-BHeXmM0X.js +37 -0
  44. package/dist/chunk-BHeXmM0X.js.map +1 -0
  45. package/dist/chunk-BI8WZLpU.cjs +281 -0
  46. package/dist/chunk-BI8WZLpU.cjs.map +1 -0
  47. package/dist/chunk-BIEc_SkR.cjs +29 -0
  48. package/dist/chunk-BIEc_SkR.cjs.map +1 -0
  49. package/dist/chunk-BJ6L6_W9.cjs +553 -0
  50. package/dist/chunk-BJ6L6_W9.cjs.map +1 -0
  51. package/dist/chunk-BJ91UCbB.js +11 -0
  52. package/dist/chunk-BJ91UCbB.js.map +1 -0
  53. package/dist/chunk-BJEZWTKj.cjs +166 -0
  54. package/dist/chunk-BJEZWTKj.cjs.map +1 -0
  55. package/dist/chunk-BJz54mfg.cjs +10 -0
  56. package/dist/chunk-BJz54mfg.cjs.map +1 -0
  57. package/dist/chunk-BNX5LAfN.d.cts +912 -0
  58. package/dist/chunk-BP6KgA86.js +35 -0
  59. package/dist/chunk-BP6KgA86.js.map +1 -0
  60. package/dist/chunk-BRnjQq6K.d.cts +157 -0
  61. package/dist/chunk-BSiMEwPS.js +46 -0
  62. package/dist/chunk-BSiMEwPS.js.map +1 -0
  63. package/dist/chunk-BTPjDw_y.cjs +16 -0
  64. package/dist/chunk-BTPjDw_y.cjs.map +1 -0
  65. package/dist/chunk-BTUUABGI.js +17 -0
  66. package/dist/chunk-BTUUABGI.js.map +1 -0
  67. package/dist/chunk-BUeL9y7s.cjs +45 -0
  68. package/dist/chunk-BUeL9y7s.cjs.map +1 -0
  69. package/dist/chunk-BWMuCNc9.cjs +172 -0
  70. package/dist/chunk-BWMuCNc9.cjs.map +1 -0
  71. package/dist/chunk-BWjRfhpF.js +126 -0
  72. package/dist/chunk-BWjRfhpF.js.map +1 -0
  73. package/dist/chunk-BZ5KyZXI.d.ts +302 -0
  74. package/dist/chunk-B_4SVmvh.js +94 -0
  75. package/dist/chunk-B_4SVmvh.js.map +1 -0
  76. package/dist/chunk-BcTUuZQ3.js +95 -0
  77. package/dist/chunk-BcTUuZQ3.js.map +1 -0
  78. package/dist/chunk-BdkqSsJe.cjs +140 -0
  79. package/dist/chunk-BdkqSsJe.cjs.map +1 -0
  80. package/dist/chunk-BfktMVmI.js +70 -0
  81. package/dist/chunk-BfktMVmI.js.map +1 -0
  82. package/dist/chunk-BfzQb0EK.cjs +6 -0
  83. package/dist/chunk-BhWfT-22.d.cts +808 -0
  84. package/dist/chunk-BjJcqX5J.cjs +60 -0
  85. package/dist/chunk-BjJcqX5J.cjs.map +1 -0
  86. package/dist/chunk-Bk0L8g5J.d.cts +77 -0
  87. package/dist/chunk-Bk0L8g5J.d.ts +77 -0
  88. package/dist/chunk-Bl4_uVa6.cjs +11 -0
  89. package/dist/chunk-Bl4_uVa6.cjs.map +1 -0
  90. package/dist/chunk-BlKF4lrp.js +43 -0
  91. package/dist/chunk-BlKF4lrp.js.map +1 -0
  92. package/dist/chunk-Bm1FieGR.js +4 -0
  93. package/dist/chunk-Bm1FieGR.js.map +1 -0
  94. package/dist/chunk-Bn6ZbxkS.cjs +27 -0
  95. package/dist/chunk-BpN3hr6a.cjs +541 -0
  96. package/dist/chunk-BpN3hr6a.cjs.map +1 -0
  97. package/dist/chunk-Bq_WHTfd.d.cts +119 -0
  98. package/dist/chunk-Bqt4LBBz.cjs +648 -0
  99. package/dist/chunk-Bqt4LBBz.cjs.map +1 -0
  100. package/dist/chunk-Bqt97zwf.d.cts +54 -0
  101. package/dist/chunk-Bqt97zwf.d.ts +54 -0
  102. package/dist/chunk-BsBiN4w6.d.cts +245 -0
  103. package/dist/chunk-BvTpOUoC.cjs +207 -0
  104. package/dist/chunk-BvTpOUoC.cjs.map +1 -0
  105. package/dist/chunk-BwK6Hl3q.cjs +446 -0
  106. package/dist/chunk-BwK6Hl3q.cjs.map +1 -0
  107. package/dist/chunk-BxDQZDXR.d.cts +76 -0
  108. package/dist/chunk-BxDQZDXR.d.ts +76 -0
  109. package/dist/chunk-BxUio8kX.js +20 -0
  110. package/dist/chunk-BxUio8kX.js.map +1 -0
  111. package/dist/chunk-BxaocpFi.d.cts +1 -0
  112. package/dist/chunk-Bywi0K1N.js +36 -0
  113. package/dist/chunk-Bywi0K1N.js.map +1 -0
  114. package/dist/chunk-C-IlmkDl.js +59 -0
  115. package/dist/chunk-C-IlmkDl.js.map +1 -0
  116. package/dist/chunk-C5PtVewq.d.ts +389 -0
  117. package/dist/chunk-C5dpC7mQ.js +19 -0
  118. package/dist/chunk-C5dpC7mQ.js.map +1 -0
  119. package/dist/chunk-C5q1sgSa.js +46 -0
  120. package/dist/chunk-C5q1sgSa.js.map +1 -0
  121. package/dist/chunk-C6fU9G5I.cjs +221 -0
  122. package/dist/chunk-C6fU9G5I.cjs.map +1 -0
  123. package/dist/chunk-C71dpWUK.js +5 -0
  124. package/dist/chunk-C71dpWUK.js.map +1 -0
  125. package/dist/chunk-C82N1gQX.d.ts +1831 -0
  126. package/dist/chunk-C8HdaHpu.js +118 -0
  127. package/dist/chunk-C8HdaHpu.js.map +1 -0
  128. package/dist/chunk-C8ZGryck.js +236 -0
  129. package/dist/chunk-C8ZGryck.js.map +1 -0
  130. package/dist/chunk-C95NG0oD.cjs +43 -0
  131. package/dist/chunk-C95NG0oD.cjs.map +1 -0
  132. package/dist/chunk-C9aR8DXb.js +9 -0
  133. package/dist/chunk-C9aR8DXb.js.map +1 -0
  134. package/dist/chunk-CAUZnoCs.d.ts +525 -0
  135. package/dist/chunk-CBXWWuM9.cjs +82 -0
  136. package/dist/chunk-CBXWWuM9.cjs.map +1 -0
  137. package/dist/chunk-CC_Kquu7.d.cts +125 -0
  138. package/dist/chunk-CC_Kquu7.d.ts +125 -0
  139. package/dist/chunk-CCp85vXg.cjs +60 -0
  140. package/dist/chunk-CCp85vXg.cjs.map +1 -0
  141. package/dist/chunk-CEcB1_uK.js +39 -0
  142. package/dist/chunk-CEcB1_uK.js.map +1 -0
  143. package/dist/chunk-CFIo021l.d.cts +216 -0
  144. package/dist/chunk-CH_IZoJE.js +33 -0
  145. package/dist/chunk-CH_IZoJE.js.map +1 -0
  146. package/dist/chunk-CHrasH_g.cjs +25 -0
  147. package/dist/chunk-CHrasH_g.cjs.map +1 -0
  148. package/dist/chunk-CJVoSaAE.cjs +3 -0
  149. package/dist/chunk-CJp8nGcb.js +96 -0
  150. package/dist/chunk-CJp8nGcb.js.map +1 -0
  151. package/dist/chunk-CJwUtkOt.js +112 -0
  152. package/dist/chunk-CJwUtkOt.js.map +1 -0
  153. package/dist/chunk-CKhCOVIf.d.cts +751 -0
  154. package/dist/chunk-CKiVSRYg.js +50 -0
  155. package/dist/chunk-CKiVSRYg.js.map +1 -0
  156. package/dist/chunk-CKtd19eD.cjs +59 -0
  157. package/dist/chunk-CKtd19eD.cjs.map +1 -0
  158. package/dist/chunk-CL92KE3j.d.ts +3188 -0
  159. package/dist/chunk-CLqUlkAe.js +54 -0
  160. package/dist/chunk-CLqUlkAe.js.map +1 -0
  161. package/dist/chunk-CMG5OV0q.cjs +4741 -0
  162. package/dist/chunk-CMG5OV0q.cjs.map +1 -0
  163. package/dist/chunk-CN_TKSgm.js +10 -0
  164. package/dist/chunk-CN_TKSgm.js.map +1 -0
  165. package/dist/chunk-CNe6MtqV.cjs +29 -0
  166. package/dist/chunk-CNe6MtqV.cjs.map +1 -0
  167. package/dist/chunk-COQkDTC5.js +83 -0
  168. package/dist/chunk-COQkDTC5.js.map +1 -0
  169. package/dist/chunk-CPBl6K4M.cjs +168 -0
  170. package/dist/chunk-CPBl6K4M.cjs.map +1 -0
  171. package/dist/chunk-CPx0ZYFB.d.ts +3 -0
  172. package/dist/chunk-CQQhcP_C.d.ts +197 -0
  173. package/dist/chunk-CTNoajFh.d.cts +389 -0
  174. package/dist/chunk-CTd-qgJc.cjs +384 -0
  175. package/dist/chunk-CTd-qgJc.cjs.map +1 -0
  176. package/dist/chunk-CW80YYtU.cjs +1056 -0
  177. package/dist/chunk-CW80YYtU.cjs.map +1 -0
  178. package/dist/chunk-CWpqBgkF.d.cts +24 -0
  179. package/dist/chunk-CWpqBgkF.d.ts +24 -0
  180. package/dist/chunk-CXjRArgy.d.ts +3 -0
  181. package/dist/chunk-CXonfH3-.cjs +14 -0
  182. package/dist/chunk-CXonfH3-.cjs.map +1 -0
  183. package/dist/chunk-CYcouGXN.d.ts +825 -0
  184. package/dist/chunk-CZDAzEBw.cjs +1621 -0
  185. package/dist/chunk-CZDAzEBw.cjs.map +1 -0
  186. package/dist/chunk-C_fQFr70.d.cts +159 -0
  187. package/dist/chunk-C_fQFr70.d.ts +159 -0
  188. package/dist/chunk-CbOtHnnB.cjs +359 -0
  189. package/dist/chunk-CbOtHnnB.cjs.map +1 -0
  190. package/dist/chunk-CdA6ZMGk.d.cts +825 -0
  191. package/dist/chunk-Ce1_thm7.js +146 -0
  192. package/dist/chunk-Ce1_thm7.js.map +1 -0
  193. package/dist/chunk-CeD8Hw0j.d.cts +3188 -0
  194. package/dist/chunk-CeiTuMyt.d.cts +525 -0
  195. package/dist/chunk-Ch1OLzLi.js +1 -0
  196. package/dist/chunk-Cizu_j1N.cjs +87 -0
  197. package/dist/chunk-Cizu_j1N.cjs.map +1 -0
  198. package/dist/chunk-CjDe9z6A.d.cts +427 -0
  199. package/dist/chunk-Cl1etdlu.js +63 -0
  200. package/dist/chunk-Cl1etdlu.js.map +1 -0
  201. package/dist/chunk-CmoVJDoz.js +4 -0
  202. package/dist/chunk-CmoVJDoz.js.map +1 -0
  203. package/dist/chunk-CnLucxjG.cjs +197 -0
  204. package/dist/chunk-CnLucxjG.cjs.map +1 -0
  205. package/dist/chunk-CsWjBmdi.cjs +56 -0
  206. package/dist/chunk-CsWjBmdi.cjs.map +1 -0
  207. package/dist/chunk-CuseO5MZ.d.cts +3 -0
  208. package/dist/chunk-CvMHibbA.d.ts +427 -0
  209. package/dist/chunk-CwDeiN5U.js +870 -0
  210. package/dist/chunk-CwDeiN5U.js.map +1 -0
  211. package/dist/chunk-Cwdmx4tG.js +1 -0
  212. package/dist/chunk-D-4MxHTt.d.cts +105 -0
  213. package/dist/chunk-D-4MxHTt.d.ts +105 -0
  214. package/dist/chunk-D0LF-99V.js +1093 -0
  215. package/dist/chunk-D0LF-99V.js.map +1 -0
  216. package/dist/chunk-D1fe-0c_.js +367 -0
  217. package/dist/chunk-D1fe-0c_.js.map +1 -0
  218. package/dist/chunk-D21fEI6A.d.ts +1926 -0
  219. package/dist/chunk-D39gAxya.cjs +89 -0
  220. package/dist/chunk-D39gAxya.cjs.map +1 -0
  221. package/dist/chunk-D6KdIW5e.cjs +228 -0
  222. package/dist/chunk-D6KdIW5e.cjs.map +1 -0
  223. package/dist/chunk-D6qHYbgW.d.cts +36 -0
  224. package/dist/chunk-D89E-w70.d.ts +44 -0
  225. package/dist/chunk-D8bdTysL.js +552 -0
  226. package/dist/chunk-D8bdTysL.js.map +1 -0
  227. package/dist/chunk-D96QJT24.cjs +109 -0
  228. package/dist/chunk-D96QJT24.cjs.map +1 -0
  229. package/dist/chunk-DAmkQl-i.js +119 -0
  230. package/dist/chunk-DAmkQl-i.js.map +1 -0
  231. package/dist/chunk-DEfsb2lc.cjs +10 -0
  232. package/dist/chunk-DEfsb2lc.cjs.map +1 -0
  233. package/dist/chunk-DIFjT5-V.d.cts +66 -0
  234. package/dist/chunk-DJpUw8TN.d.ts +912 -0
  235. package/dist/chunk-DK6lm2IZ.cjs +11 -0
  236. package/dist/chunk-DK6lm2IZ.cjs.map +1 -0
  237. package/dist/chunk-DKqgr31j.cjs +61 -0
  238. package/dist/chunk-DKqgr31j.cjs.map +1 -0
  239. package/dist/chunk-DLZ0QYm9.js +37 -0
  240. package/dist/chunk-DLZ0QYm9.js.map +1 -0
  241. package/dist/chunk-DLjS0uaC.js +4 -0
  242. package/dist/chunk-DLjS0uaC.js.map +1 -0
  243. package/dist/chunk-DMokwmOV.cjs +49 -0
  244. package/dist/chunk-DMokwmOV.cjs.map +1 -0
  245. package/dist/chunk-DMvWgBZL.d.cts +1831 -0
  246. package/dist/chunk-DNfGfIF3.js +31 -0
  247. package/dist/chunk-DNfGfIF3.js.map +1 -0
  248. package/dist/chunk-DQbSRe8D.d.ts +245 -0
  249. package/dist/chunk-DSGkP8_y.js +45 -0
  250. package/dist/chunk-DSGkP8_y.js.map +1 -0
  251. package/dist/chunk-DTctvfSd.d.cts +197 -0
  252. package/dist/chunk-DWe7igyw.cjs +206 -0
  253. package/dist/chunk-DWe7igyw.cjs.map +1 -0
  254. package/dist/chunk-DWsMP5JR.d.ts +68 -0
  255. package/dist/chunk-DWsm3HIW.d.cts +120 -0
  256. package/dist/chunk-DWsm3HIW.d.ts +120 -0
  257. package/dist/chunk-DXABHjLa.cjs +3 -0
  258. package/dist/chunk-D_BeqSbc.cjs +42 -0
  259. package/dist/chunk-D_BeqSbc.cjs.map +1 -0
  260. package/dist/chunk-D_svQNdW.d.ts +66 -0
  261. package/dist/chunk-Dav4xWrp.js +330 -0
  262. package/dist/chunk-Dav4xWrp.js.map +1 -0
  263. package/dist/chunk-DbCPhepL.js +293 -0
  264. package/dist/chunk-DbCPhepL.js.map +1 -0
  265. package/dist/chunk-DcrTy-y2.cjs +43 -0
  266. package/dist/chunk-DcrTy-y2.cjs.map +1 -0
  267. package/dist/chunk-Ddv484ld.js +487 -0
  268. package/dist/chunk-Ddv484ld.js.map +1 -0
  269. package/dist/chunk-De0bjnhY.cjs +88 -0
  270. package/dist/chunk-De0bjnhY.cjs.map +1 -0
  271. package/dist/chunk-De2FmNPu.cjs +32 -0
  272. package/dist/chunk-De2FmNPu.cjs.map +1 -0
  273. package/dist/chunk-DeSjQXiI.d.ts +157 -0
  274. package/dist/chunk-Den0Ta6C.js +132 -0
  275. package/dist/chunk-Den0Ta6C.js.map +1 -0
  276. package/dist/chunk-DiDKEeEa.js +8 -0
  277. package/dist/chunk-DiDKEeEa.js.map +1 -0
  278. package/dist/chunk-Dj60k5PU.js +197 -0
  279. package/dist/chunk-Dj60k5PU.js.map +1 -0
  280. package/dist/chunk-DjnYQBCN.js +4705 -0
  281. package/dist/chunk-DjnYQBCN.js.map +1 -0
  282. package/dist/chunk-Dk9VKvyq.d.ts +1 -0
  283. package/dist/chunk-Dor1ERI9.cjs +85 -0
  284. package/dist/chunk-Dor1ERI9.cjs.map +1 -0
  285. package/dist/chunk-DpMouOoH.js +451 -0
  286. package/dist/chunk-DpMouOoH.js.map +1 -0
  287. package/dist/chunk-DposgdNL.cjs +52 -0
  288. package/dist/chunk-DposgdNL.cjs.map +1 -0
  289. package/dist/chunk-DqLTG_5Q.d.cts +3 -0
  290. package/dist/chunk-Dr5MCIpS.d.cts +63 -0
  291. package/dist/chunk-Dr5MCIpS.d.ts +63 -0
  292. package/dist/chunk-DrudttCC.cjs +4 -0
  293. package/dist/chunk-DsDYVJQC.js +173 -0
  294. package/dist/chunk-DsDYVJQC.js.map +1 -0
  295. package/dist/chunk-Dw8ur6FJ.js +27 -0
  296. package/dist/chunk-Dw8ur6FJ.js.map +1 -0
  297. package/dist/chunk-DwG6M_0v.js +64 -0
  298. package/dist/chunk-DwG6M_0v.js.map +1 -0
  299. package/dist/chunk-Dy9a5ibO.js +284 -0
  300. package/dist/chunk-Dy9a5ibO.js.map +1 -0
  301. package/dist/chunk-DyayZlQJ.js +157 -0
  302. package/dist/chunk-DyayZlQJ.js.map +1 -0
  303. package/dist/chunk-DyhJZC2i.js +126 -0
  304. package/dist/chunk-DyhJZC2i.js.map +1 -0
  305. package/dist/chunk-F9zBzmmG.cjs +45 -0
  306. package/dist/chunk-F9zBzmmG.cjs.map +1 -0
  307. package/dist/chunk-FyCYofv2.js +116 -0
  308. package/dist/chunk-FyCYofv2.js.map +1 -0
  309. package/dist/chunk-GHJRjAk2.js +1 -0
  310. package/dist/chunk-H14isiSf.d.ts +751 -0
  311. package/dist/chunk-HIJzXoN4.js +7 -0
  312. package/dist/chunk-HIJzXoN4.js.map +1 -0
  313. package/dist/chunk-Id_8kRtu.d.ts +36 -0
  314. package/dist/chunk-KN60yxBQ.js +5 -0
  315. package/dist/chunk-KN60yxBQ.js.map +1 -0
  316. package/dist/chunk-NM5yg6bh.cjs +82 -0
  317. package/dist/chunk-NM5yg6bh.cjs.map +1 -0
  318. package/dist/chunk-OXr3zJfM.cjs +119 -0
  319. package/dist/chunk-OXr3zJfM.cjs.map +1 -0
  320. package/dist/chunk-QGqgNC4z.d.ts +928 -0
  321. package/dist/chunk-QJBtJrZ0.js +36 -0
  322. package/dist/chunk-QJBtJrZ0.js.map +1 -0
  323. package/dist/chunk-QKWhxfPv.d.cts +361 -0
  324. package/dist/chunk-QKWhxfPv.d.ts +361 -0
  325. package/dist/chunk-QXW7b4Ev.d.cts +410 -0
  326. package/dist/chunk-RHZrxUrM.cjs +39 -0
  327. package/dist/chunk-RHZrxUrM.cjs.map +1 -0
  328. package/dist/chunk-RTxe2i66.js +91 -0
  329. package/dist/chunk-RTxe2i66.js.map +1 -0
  330. package/dist/chunk-RrKkJb6P.js +16 -0
  331. package/dist/chunk-RrKkJb6P.js.map +1 -0
  332. package/dist/chunk-VOJqpcnM.cjs +181 -0
  333. package/dist/chunk-VOJqpcnM.cjs.map +1 -0
  334. package/dist/chunk-VljGTrid.js +1 -0
  335. package/dist/chunk-X3UVwUEK.d.cts +513 -0
  336. package/dist/chunk-X9K2WChn.cjs +28 -0
  337. package/dist/chunk-X9K2WChn.cjs.map +1 -0
  338. package/dist/chunk-YrtOx6oy.js +251 -0
  339. package/dist/chunk-YrtOx6oy.js.map +1 -0
  340. package/dist/chunk-bY7ySujI.d.cts +928 -0
  341. package/dist/chunk-bYf1sBz5.d.cts +11 -0
  342. package/dist/chunk-bYf1sBz5.d.ts +11 -0
  343. package/dist/chunk-blfknWoM.d.cts +1926 -0
  344. package/dist/chunk-blqsohAb.js +113 -0
  345. package/dist/chunk-blqsohAb.js.map +1 -0
  346. package/dist/chunk-cDMCjodI.cjs +58 -0
  347. package/dist/chunk-cDMCjodI.cjs.map +1 -0
  348. package/dist/chunk-cWjE3qd6.cjs +10 -0
  349. package/dist/chunk-cWjE3qd6.cjs.map +1 -0
  350. package/dist/chunk-dfOgV3fu.js +26 -0
  351. package/dist/chunk-dfOgV3fu.js.map +1 -0
  352. package/dist/chunk-f9cTwUX1.cjs +125 -0
  353. package/dist/chunk-f9cTwUX1.cjs.map +1 -0
  354. package/dist/chunk-fHVYEZs4.cjs +28 -0
  355. package/dist/chunk-fHVYEZs4.cjs.map +1 -0
  356. package/dist/chunk-fWRUMgRI.js +22 -0
  357. package/dist/chunk-fWRUMgRI.js.map +1 -0
  358. package/dist/chunk-fozLXfHY.d.cts +55 -0
  359. package/dist/chunk-fozLXfHY.d.ts +55 -0
  360. package/dist/chunk-gWmB1l3A.cjs +3122 -0
  361. package/dist/chunk-gWmB1l3A.cjs.map +1 -0
  362. package/dist/chunk-gbj2R-_w.js +58 -0
  363. package/dist/chunk-gbj2R-_w.js.map +1 -0
  364. package/dist/chunk-iIWxsAXd.js +59 -0
  365. package/dist/chunk-iIWxsAXd.js.map +1 -0
  366. package/dist/chunk-lItIuOIS.cjs +137 -0
  367. package/dist/chunk-lItIuOIS.cjs.map +1 -0
  368. package/dist/chunk-m6Rh4PCe.cjs +798 -0
  369. package/dist/chunk-m6Rh4PCe.cjs.map +1 -0
  370. package/dist/chunk-o3IRANDf.cjs +99 -0
  371. package/dist/chunk-o3IRANDf.cjs.map +1 -0
  372. package/dist/chunk-obUcg3Sk.d.ts +808 -0
  373. package/dist/chunk-ohsf-6Rn.js +600 -0
  374. package/dist/chunk-ohsf-6Rn.js.map +1 -0
  375. package/dist/chunk-pBleU6Nv.js +3061 -0
  376. package/dist/chunk-pBleU6Nv.js.map +1 -0
  377. package/dist/chunk-px4e99cy.js +71 -0
  378. package/dist/chunk-px4e99cy.js.map +1 -0
  379. package/dist/chunk-qwYDLeXc.cjs +99 -0
  380. package/dist/chunk-qwYDLeXc.cjs.map +1 -0
  381. package/dist/chunk-rF_859Qk.cjs +101 -0
  382. package/dist/chunk-rF_859Qk.cjs.map +1 -0
  383. package/dist/chunk-rLJkqJ5j.d.ts +1475 -0
  384. package/dist/chunk-twQItIRg.cjs +338 -0
  385. package/dist/chunk-twQItIRg.cjs.map +1 -0
  386. package/dist/chunk-vnPrMVjY.js +10 -0
  387. package/dist/chunk-vnPrMVjY.js.map +1 -0
  388. package/dist/chunk-ws3bVwaS.d.ts +410 -0
  389. package/dist/chunk-xh3UkuVs.cjs +246 -0
  390. package/dist/chunk-xh3UkuVs.cjs.map +1 -0
  391. package/dist/chunk-yMzRr26E.js +153 -0
  392. package/dist/chunk-yMzRr26E.js.map +1 -0
  393. package/dist/collab/index.cjs +831 -0
  394. package/dist/collab/index.cjs.map +1 -0
  395. package/dist/collab/index.d.cts +824 -0
  396. package/dist/collab/index.d.ts +824 -0
  397. package/dist/collab/index.js +819 -0
  398. package/dist/collab/index.js.map +1 -0
  399. package/dist/data/index.cjs +39 -0
  400. package/dist/data/index.d.cts +6 -0
  401. package/dist/data/index.d.ts +6 -0
  402. package/dist/data/index.js +7 -0
  403. package/dist/editor/index.cjs +2713 -0
  404. package/dist/editor/index.cjs.map +1 -0
  405. package/dist/editor/index.d.cts +10 -0
  406. package/dist/editor/index.d.ts +10 -0
  407. package/dist/editor/index.js +2702 -0
  408. package/dist/editor/index.js.map +1 -0
  409. package/dist/errors/index.cjs +11 -0
  410. package/dist/errors/index.d.cts +2 -0
  411. package/dist/errors/index.d.ts +2 -0
  412. package/dist/errors/index.js +1 -0
  413. package/dist/geo/index.cjs +68 -0
  414. package/dist/geo/index.d.cts +6 -0
  415. package/dist/geo/index.d.ts +6 -0
  416. package/dist/geo/index.js +11 -0
  417. package/dist/i18n/fr/index.cjs +333 -0
  418. package/dist/i18n/fr/index.cjs.map +1 -0
  419. package/dist/i18n/fr/index.d.cts +18 -0
  420. package/dist/i18n/fr/index.d.ts +18 -0
  421. package/dist/i18n/fr/index.js +328 -0
  422. package/dist/i18n/fr/index.js.map +1 -0
  423. package/dist/i18n/index.cjs +451 -0
  424. package/dist/i18n/index.cjs.map +1 -0
  425. package/dist/i18n/index.d.cts +268 -0
  426. package/dist/i18n/index.d.ts +268 -0
  427. package/dist/i18n/index.js +430 -0
  428. package/dist/i18n/index.js.map +1 -0
  429. package/dist/icons/index.cjs +37 -0
  430. package/dist/icons/index.d.cts +4 -0
  431. package/dist/icons/index.d.ts +4 -0
  432. package/dist/icons/index.js +8 -0
  433. package/dist/index.cjs +517 -0
  434. package/dist/index.cjs.map +1 -0
  435. package/dist/index.d.cts +174 -0
  436. package/dist/index.d.ts +174 -0
  437. package/dist/index.js +54 -0
  438. package/dist/index.js.map +1 -0
  439. package/dist/layers/index.cjs +83 -0
  440. package/dist/layers/index.d.cts +3 -0
  441. package/dist/layers/index.d.ts +3 -0
  442. package/dist/layers/index.js +5 -0
  443. package/dist/map-client/index.cjs +5 -0
  444. package/dist/map-client/index.d.cts +6 -0
  445. package/dist/map-client/index.d.ts +6 -0
  446. package/dist/map-client/index.js +0 -0
  447. package/dist/maplibre-worker.mjs +12 -0
  448. package/dist/navigation/index.cjs +612 -0
  449. package/dist/navigation/index.cjs.map +1 -0
  450. package/dist/navigation/index.d.cts +551 -0
  451. package/dist/navigation/index.d.ts +551 -0
  452. package/dist/navigation/index.js +599 -0
  453. package/dist/navigation/index.js.map +1 -0
  454. package/dist/profile/index.cjs +177 -0
  455. package/dist/profile/index.d.cts +8 -0
  456. package/dist/profile/index.d.ts +8 -0
  457. package/dist/profile/index.js +10 -0
  458. package/dist/seams/index.cjs +15 -0
  459. package/dist/seams/index.d.cts +4 -0
  460. package/dist/seams/index.d.ts +4 -0
  461. package/dist/seams/index.js +4 -0
  462. package/dist/search/index.cjs +39 -0
  463. package/dist/search/index.d.cts +6 -0
  464. package/dist/search/index.d.ts +6 -0
  465. package/dist/search/index.js +3 -0
  466. package/dist/style/index.cjs +34 -0
  467. package/dist/style/index.d.cts +5 -0
  468. package/dist/style/index.d.ts +5 -0
  469. package/dist/style/index.js +5 -0
  470. package/dist/styles.css +11 -0
  471. package/dist/testing/index.cjs +444 -0
  472. package/dist/testing/index.cjs.map +1 -0
  473. package/dist/testing/index.d.cts +217 -0
  474. package/dist/testing/index.d.ts +217 -0
  475. package/dist/testing/index.js +435 -0
  476. package/dist/testing/index.js.map +1 -0
  477. package/dist/timezone/index.cjs +1953 -0
  478. package/dist/timezone/index.cjs.map +1 -0
  479. package/dist/timezone/index.d.cts +28 -0
  480. package/dist/timezone/index.d.ts +28 -0
  481. package/dist/timezone/index.js +1948 -0
  482. package/dist/timezone/index.js.map +1 -0
  483. package/dist/units/index.cjs +29 -0
  484. package/dist/units/index.d.cts +3 -0
  485. package/dist/units/index.d.ts +3 -0
  486. package/dist/units/index.js +3 -0
  487. package/dist/video/index.cjs +1713 -0
  488. package/dist/video/index.cjs.map +1 -0
  489. package/dist/video/index.d.cts +846 -0
  490. package/dist/video/index.d.ts +846 -0
  491. package/dist/video/index.js +1689 -0
  492. package/dist/video/index.js.map +1 -0
  493. package/dist/view/index.cjs +7 -0
  494. package/dist/view/index.d.cts +3 -0
  495. package/dist/view/index.d.ts +3 -0
  496. package/dist/view/index.js +1 -0
  497. package/package.json +433 -4
  498. package/src/agent/engines/session.ts +2255 -0
  499. package/src/agent/index.ts +109 -0
  500. package/src/agent/rules/agentError.ts +128 -0
  501. package/src/agent/rules/boundedInputJson.ts +53 -0
  502. package/src/agent/rules/conversation.ts +629 -0
  503. package/src/agent/rules/conversationFaults.ts +349 -0
  504. package/src/agent/rules/conversationHost.ts +390 -0
  505. package/src/agent/rules/dispatcher.ts +102 -0
  506. package/src/agent/rules/errorCodes.ts +78 -0
  507. package/src/agent/rules/errorStatus.ts +65 -0
  508. package/src/agent/rules/scriptedTransport.ts +390 -0
  509. package/src/agent/rules/stickToBottom.ts +38 -0
  510. package/src/agent/rules/toolResultPayload.ts +197 -0
  511. package/src/auth/rules/clientHeader.ts +22 -0
  512. package/src/auth/rules/sentCredential.ts +76 -0
  513. package/src/auth/rules/transformRequest.ts +803 -0
  514. package/src/camera/engines/videoFlight.ts +1758 -0
  515. package/src/camera/index.ts +157 -0
  516. package/src/camera/rules/clearance.ts +1099 -0
  517. package/src/camera/rules/fit.ts +132 -0
  518. package/src/camera/rules/modes.ts +1019 -0
  519. package/src/camera/rules/plan.ts +478 -0
  520. package/src/camera/rules/planner.ts +129 -0
  521. package/src/camera/rules/poseRanges.ts +38 -0
  522. package/src/camera/rules/presets.ts +185 -0
  523. package/src/camera/rules/profileSamples.ts +243 -0
  524. package/src/camera/rules/route.ts +596 -0
  525. package/src/camera/rules/routeContent.ts +105 -0
  526. package/src/camera/rules/spline.ts +765 -0
  527. package/src/camera/rules/sweptViewports.ts +39 -0
  528. package/src/camera/rules/track.ts +1412 -0
  529. package/src/camera/rules/vocabulary.ts +130 -0
  530. package/src/camera/rules/zoom.ts +216 -0
  531. package/src/collab/engines/session.ts +1902 -0
  532. package/src/collab/engines/trailingThrottle.ts +151 -0
  533. package/src/collab/index.ts +52 -0
  534. package/src/collab/rules/dispatch.ts +143 -0
  535. package/src/collab/rules/peerNames.ts +51 -0
  536. package/src/collab/rules/scriptedTransport.ts +244 -0
  537. package/src/compose/engines/baseMapSwitch.ts +1136 -0
  538. package/src/compose/engines/events.ts +962 -0
  539. package/src/compose/engines/mountayaMap.ts +5648 -0
  540. package/src/compose/engines/sentCredentials.ts +146 -0
  541. package/src/compose/engines/slotRequests.ts +413 -0
  542. package/src/compose/rules/accessRefusal.ts +109 -0
  543. package/src/compose/rules/accessStanding.ts +75 -0
  544. package/src/compose/rules/analysisKinds.ts +331 -0
  545. package/src/compose/rules/analysisLayers.ts +176 -0
  546. package/src/compose/rules/cameraMoves.ts +38 -0
  547. package/src/compose/rules/carriedLayers.ts +87 -0
  548. package/src/compose/rules/developmentWarnings.ts +167 -0
  549. package/src/compose/rules/fitBox.ts +67 -0
  550. package/src/compose/rules/fitCamera.ts +54 -0
  551. package/src/compose/rules/geoJsonSlot.ts +61 -0
  552. package/src/compose/rules/geometrySlots.ts +155 -0
  553. package/src/compose/rules/glyphNode.ts +62 -0
  554. package/src/compose/rules/layerKeys.ts +92 -0
  555. package/src/compose/rules/layerOrder.ts +85 -0
  556. package/src/compose/rules/layersManifest.ts +26 -0
  557. package/src/compose/rules/mapOptions.ts +300 -0
  558. package/src/compose/rules/maplibreWorkerVersion.gen.ts +8 -0
  559. package/src/compose/rules/markerPin.ts +122 -0
  560. package/src/compose/rules/markerRegistry.ts +85 -0
  561. package/src/compose/rules/markerSprite.ts +382 -0
  562. package/src/compose/rules/maxBounds.ts +120 -0
  563. package/src/compose/rules/overlayLookup.ts +49 -0
  564. package/src/compose/rules/paintDiff.ts +38 -0
  565. package/src/compose/rules/panLock.ts +77 -0
  566. package/src/compose/rules/patch.ts +124 -0
  567. package/src/compose/rules/queriedFeature.ts +55 -0
  568. package/src/compose/rules/queryLayers.ts +46 -0
  569. package/src/compose/rules/searchHighlight.ts +313 -0
  570. package/src/compose/rules/slotNames.ts +19 -0
  571. package/src/compose/rules/stripeImage.ts +253 -0
  572. package/src/compose/rules/swapMarker.ts +66 -0
  573. package/src/compose/rules/terrainVariant.ts +88 -0
  574. package/src/compose/rules/types.ts +559 -0
  575. package/src/compose/rules/urlHash.ts +19 -0
  576. package/src/compose/rules/viewOptions.ts +451 -0
  577. package/src/compose/rules/workerUrl.ts +131 -0
  578. package/src/data/engines/itineraryResource.ts +643 -0
  579. package/src/data/index.ts +78 -0
  580. package/src/data/rules/adapt.ts +473 -0
  581. package/src/data/rules/editModes.ts +51 -0
  582. package/src/data/rules/itinerary.ts +168 -0
  583. package/src/data/rules/nullable.ts +63 -0
  584. package/src/data/rules/roadAccess.ts +169 -0
  585. package/src/data/rules/segmentGroups.ts +309 -0
  586. package/src/data/rules/selectors.ts +95 -0
  587. package/src/data/rules/zones.ts +79 -0
  588. package/src/draw/engines/boundaryEngine.ts +1003 -0
  589. package/src/draw/engines/framedAdapter.ts +198 -0
  590. package/src/draw/engines/pointerCursor.ts +205 -0
  591. package/src/draw/engines/segmentEngine.ts +1405 -0
  592. package/src/draw/engines/snapIndex.ts +254 -0
  593. package/src/draw/engines/waypointEngine.ts +574 -0
  594. package/src/draw/engines/zoneEngine.ts +1137 -0
  595. package/src/draw/rules/drawFrame.ts +123 -0
  596. package/src/draw/rules/insertVertex.ts +226 -0
  597. package/src/draw/rules/screenSpace.ts +62 -0
  598. package/src/draw/rules/seeds.ts +185 -0
  599. package/src/draw/rules/snap.ts +115 -0
  600. package/src/draw/rules/snapCameraKey.ts +50 -0
  601. package/src/draw/rules/terraDrawShared.ts +214 -0
  602. package/src/draw/rules/zoneOutline.ts +213 -0
  603. package/src/editing/engines/cursor.ts +505 -0
  604. package/src/editing/engines/draftMarker.ts +149 -0
  605. package/src/editing/rules/accent.ts +11 -0
  606. package/src/editing/rules/engine.ts +288 -0
  607. package/src/editing/rules/placement.ts +22 -0
  608. package/src/editing/rules/positions.ts +89 -0
  609. package/src/editing/rules/sources.ts +9 -0
  610. package/src/editing/rules/types.ts +457 -0
  611. package/src/editing/rules/vocabulary.ts +10 -0
  612. package/src/editing/rules/waypointCursor.ts +228 -0
  613. package/src/editor/engines/directionArrows.ts +459 -0
  614. package/src/editor/engines/directions.ts +1383 -0
  615. package/src/editor/engines/editorClient.ts +134 -0
  616. package/src/editor/engines/eventScope.ts +59 -0
  617. package/src/editor/engines/frameLoop.ts +159 -0
  618. package/src/editor/engines/itineraryPreview.ts +272 -0
  619. package/src/editor/engines/mapLockGuard.ts +66 -0
  620. package/src/editor/engines/overlayRenderer.ts +2696 -0
  621. package/src/editor/engines/peerDraft.ts +760 -0
  622. package/src/editor/engines/poiPick.ts +305 -0
  623. package/src/editor/engines/pointPick.ts +84 -0
  624. package/src/editor/engines/roadAccessLine.ts +140 -0
  625. package/src/editor/engines/searchHighlight.ts +183 -0
  626. package/src/editor/engines/viewClient.ts +4091 -0
  627. package/src/editor/engines/zoneBadges.ts +503 -0
  628. package/src/editor/index.ts +97 -0
  629. package/src/editor/rules/accentColor.ts +116 -0
  630. package/src/editor/rules/camera.ts +121 -0
  631. package/src/editor/rules/contract.ts +120 -0
  632. package/src/editor/rules/icons.ts +825 -0
  633. package/src/editor/rules/markerElements.ts +244 -0
  634. package/src/editor/rules/style.ts +51 -0
  635. package/src/editor/rules/terrain.ts +98 -0
  636. package/src/editor/rules/tileWarm.ts +191 -0
  637. package/src/editor/rules/tilesReload.ts +158 -0
  638. package/src/editor/rules/zoneBadgePlacement.ts +1832 -0
  639. package/src/editor/rules/zoneTimeStyling.ts +119 -0
  640. package/src/errors/index.ts +25 -0
  641. package/src/errors/rules/errors.ts +158 -0
  642. package/src/errors/rules/print.ts +129 -0
  643. package/src/geo/index.ts +89 -0
  644. package/src/geo/rules/boundaries.ts +105 -0
  645. package/src/geo/rules/camera.ts +496 -0
  646. package/src/geo/rules/corridor.ts +242 -0
  647. package/src/geo/rules/elevationTiles.ts +269 -0
  648. package/src/geo/rules/formatLngLat.ts +63 -0
  649. package/src/geo/rules/geodesy.ts +125 -0
  650. package/src/geo/rules/geometry.ts +362 -0
  651. package/src/geo/rules/lineWalk.ts +77 -0
  652. package/src/geo/rules/longitude.ts +99 -0
  653. package/src/geo/rules/searchLimits.ts +22 -0
  654. package/src/geo/rules/segmentGeometry.ts +80 -0
  655. package/src/geo/rules/terrain.ts +107 -0
  656. package/src/geo/rules/tuples.ts +124 -0
  657. package/src/geo/rules/types.ts +54 -0
  658. package/src/geo/rules/webMercator.ts +57 -0
  659. package/src/i18n/fr/index.ts +17 -0
  660. package/src/i18n/fr/rules/fr.ts +85 -0
  661. package/src/i18n/fr/rules/words.gen.ts +277 -0
  662. package/src/i18n/index.ts +82 -0
  663. package/src/i18n/rules/bundle.ts +378 -0
  664. package/src/i18n/rules/config.ts +71 -0
  665. package/src/i18n/rules/dates.ts +165 -0
  666. package/src/i18n/rules/endonyms.gen.ts +19 -0
  667. package/src/i18n/rules/language.ts +92 -0
  668. package/src/i18n/rules/localizedName.ts +33 -0
  669. package/src/i18n/rules/merge.ts +106 -0
  670. package/src/i18n/rules/scope.ts +127 -0
  671. package/src/i18n/rules/strings.ts +632 -0
  672. package/src/i18n/rules/videoOverlay.ts +121 -0
  673. package/src/i18n/rules/wordForms.ts +95 -0
  674. package/src/i18n/rules/words.gen.ts +277 -0
  675. package/src/icons/index.ts +54 -0
  676. package/src/icons/rules/activities.ts +40 -0
  677. package/src/icons/rules/amenities.ts +250 -0
  678. package/src/icons/rules/artwork.gen.ts +83 -0
  679. package/src/icons/rules/artwork.ts +47 -0
  680. package/src/icons/rules/fallback.ts +21 -0
  681. package/src/icons/rules/lucideMarkers.gen.ts +112 -0
  682. package/src/icons/rules/lucideUi.gen.ts +197 -0
  683. package/src/icons/rules/paint.ts +107 -0
  684. package/src/icons/rules/parse.ts +475 -0
  685. package/src/icons/rules/provider.ts +373 -0
  686. package/src/icons/rules/sprites.ts +54 -0
  687. package/src/icons/rules/ui.ts +348 -0
  688. package/src/icons/rules/waypoints.ts +215 -0
  689. package/src/index.ts +993 -0
  690. package/src/layers/engines/layersSelection.ts +515 -0
  691. package/src/layers/engines/readoutEngine.ts +131 -0
  692. package/src/layers/index.ts +151 -0
  693. package/src/layers/rules/analysis.ts +135 -0
  694. package/src/layers/rules/enrichment.ts +30 -0
  695. package/src/layers/rules/geoJson.ts +270 -0
  696. package/src/layers/rules/hover.ts +67 -0
  697. package/src/layers/rules/itineraries.ts +182 -0
  698. package/src/layers/rules/layersPanel.ts +237 -0
  699. package/src/layers/rules/order.ts +194 -0
  700. package/src/layers/rules/overlayInstant.ts +49 -0
  701. package/src/layers/rules/overlays.ts +52 -0
  702. package/src/layers/rules/poiPanel.ts +119 -0
  703. package/src/layers/rules/pois.ts +114 -0
  704. package/src/layers/rules/readout.ts +340 -0
  705. package/src/layers/rules/streetView.ts +16 -0
  706. package/src/layers/rules/tileTimestamp.ts +146 -0
  707. package/src/layers/rules/timeSlider.ts +192 -0
  708. package/src/layers/rules/timeWindow.ts +123 -0
  709. package/src/layers/rules/zones.ts +43 -0
  710. package/src/layers/rules/zoom.ts +77 -0
  711. package/src/map-client/index.ts +71 -0
  712. package/src/map-client/rules/mapClient.ts +1945 -0
  713. package/src/navigation/engines/navigation.ts +493 -0
  714. package/src/navigation/index.ts +51 -0
  715. package/src/navigation/rules/followedRoute.ts +78 -0
  716. package/src/navigation/rules/instructions.ts +89 -0
  717. package/src/navigation/rules/itineraryRoute.ts +232 -0
  718. package/src/navigation/rules/offRoute.ts +41 -0
  719. package/src/navigation/rules/progress.ts +230 -0
  720. package/src/navigation/rules/prompts.ts +217 -0
  721. package/src/navigation/rules/routeRequest.ts +98 -0
  722. package/src/navigation/rules/status.ts +142 -0
  723. package/src/navigation/rules/steps.ts +234 -0
  724. package/src/navigation/rules/types.ts +83 -0
  725. package/src/profile/index.ts +307 -0
  726. package/src/profile/rules/amenityBadge.ts +35 -0
  727. package/src/profile/rules/amenityFilter.ts +74 -0
  728. package/src/profile/rules/amenityStacks.ts +66 -0
  729. package/src/profile/rules/axis.ts +89 -0
  730. package/src/profile/rules/axisCulling.ts +83 -0
  731. package/src/profile/rules/axisLookup.ts +180 -0
  732. package/src/profile/rules/climbs.ts +292 -0
  733. package/src/profile/rules/cursorMarker.ts +122 -0
  734. package/src/profile/rules/cursorReadout.ts +104 -0
  735. package/src/profile/rules/curvePlacement.ts +216 -0
  736. package/src/profile/rules/dock.ts +293 -0
  737. package/src/profile/rules/elevation.ts +1263 -0
  738. package/src/profile/rules/instant.ts +89 -0
  739. package/src/profile/rules/intl.ts +237 -0
  740. package/src/profile/rules/legEmphasis.ts +53 -0
  741. package/src/profile/rules/profileColors.ts +66 -0
  742. package/src/profile/rules/profileLayout.ts +59 -0
  743. package/src/profile/rules/profileSlices.ts +55 -0
  744. package/src/profile/rules/routeProfile.ts +475 -0
  745. package/src/profile/rules/rowMatch.ts +50 -0
  746. package/src/profile/rules/scale.ts +646 -0
  747. package/src/profile/rules/scaleFrame.ts +171 -0
  748. package/src/profile/rules/sectionChips.ts +83 -0
  749. package/src/profile/rules/sections.ts +923 -0
  750. package/src/profile/rules/slopeRamp.ts +160 -0
  751. package/src/profile/rules/statStrip.ts +103 -0
  752. package/src/profile/rules/steepness.ts +51 -0
  753. package/src/profile/rules/tableCells.ts +269 -0
  754. package/src/profile/rules/tableCursor.ts +87 -0
  755. package/src/profile/rules/unitPatterns.ts +335 -0
  756. package/src/profile/rules/units.ts +1025 -0
  757. package/src/profile/rules/waypointCard.ts +590 -0
  758. package/src/profile/rules/webAddress.ts +130 -0
  759. package/src/profile/rules/windowSpans.ts +65 -0
  760. package/src/rules/asciiFold.ts +17 -0
  761. package/src/rules/inDevelopment.ts +54 -0
  762. package/src/rules/listeners.ts +62 -0
  763. package/src/rules/timers.ts +9 -0
  764. package/src/rules/types.ts +22 -0
  765. package/src/rules/uuid.ts +87 -0
  766. package/src/seams/engines/geolocateControl.ts +286 -0
  767. package/src/seams/index.ts +50 -0
  768. package/src/seams/rules/clock.ts +169 -0
  769. package/src/seams/rules/geolocation.ts +165 -0
  770. package/src/seams/rules/segmentRoute.ts +187 -0
  771. package/src/search/engines/search.ts +1093 -0
  772. package/src/search/index.ts +99 -0
  773. package/src/search/rules/describe.ts +383 -0
  774. package/src/search/rules/filters.ts +195 -0
  775. package/src/search/rules/highlight.ts +270 -0
  776. package/src/search/rules/pick.ts +90 -0
  777. package/src/search/rules/rows.ts +258 -0
  778. package/src/search/rules/searchFocus.ts +27 -0
  779. package/src/search/rules/searchViewport.ts +44 -0
  780. package/src/search/rules/shown.ts +77 -0
  781. package/src/search/rules/types.ts +340 -0
  782. package/src/stream/rules/reconnectSchedule.ts +83 -0
  783. package/src/style/engines/organizationRead.ts +80 -0
  784. package/src/style/index.ts +63 -0
  785. package/src/style/rules/apply.ts +268 -0
  786. package/src/style/rules/attribution.ts +119 -0
  787. package/src/style/rules/itineraryLine.ts +142 -0
  788. package/src/style/rules/language.ts +668 -0
  789. package/src/style/rules/layout.gen.ts +27 -0
  790. package/src/style/rules/organization.ts +96 -0
  791. package/src/style/rules/paint.ts +143 -0
  792. package/src/style/rules/panelLayout.ts +51 -0
  793. package/src/style/rules/roadAccessColors.ts +29 -0
  794. package/src/style/rules/roadAccessLine.ts +267 -0
  795. package/src/style/rules/segmentColors.ts +207 -0
  796. package/src/testing/catalogs.ts +103 -0
  797. package/src/testing/index.ts +30 -0
  798. package/src/testing/mapClient.ts +241 -0
  799. package/src/testing/mountayaMap.ts +741 -0
  800. package/src/timezone/index.ts +14 -0
  801. package/src/timezone/rules/viewport.ts +875 -0
  802. package/src/units/index.ts +55 -0
  803. package/src/units/rules/conversions.ts +620 -0
  804. package/src/units/rules/preferenceChoices.ts +124 -0
  805. package/src/units/rules/preferences.ts +77 -0
  806. package/src/units/rules/rounding.ts +69 -0
  807. package/src/video/engines/videoRun.ts +654 -0
  808. package/src/video/engines/viewClient.ts +6 -0
  809. package/src/video/index.ts +83 -0
  810. package/src/video/profileOverlay/rules/contract.ts +210 -0
  811. package/src/video/profileOverlay/rules/curve.ts +216 -0
  812. package/src/video/profileOverlay/rules/draw.ts +410 -0
  813. package/src/video/profileOverlay/rules/fonts.ts +54 -0
  814. package/src/video/profileOverlay/rules/graphDesign.ts +690 -0
  815. package/src/video/profileOverlay/rules/minimalDesign.ts +144 -0
  816. package/src/video/profileOverlay/rules/registry.ts +23 -0
  817. package/src/video/profileOverlay/rules/staticLayer.ts +582 -0
  818. package/src/video/profileOverlay/rules/stripDesign.ts +327 -0
  819. package/src/video/profileOverlay/rules/types.ts +78 -0
  820. package/src/video/rules/videoConstants.ts +250 -0
  821. package/src/video/rules/videoEncoder.ts +277 -0
  822. package/src/video/rules/videoFrames.ts +99 -0
  823. package/src/video/rules/videoPreview.ts +185 -0
  824. package/src/video/rules/videoRecorder.ts +746 -0
  825. package/src/video/rules/videoWatermark.ts +155 -0
  826. package/src/video/rules/watermarkMark.ts +40 -0
  827. package/src/view/engines/viewClient.ts +6 -0
  828. package/src/view/index.ts +20 -0
@@ -0,0 +1,1758 @@
1
+ import type {
2
+ RecordingCamera,
3
+ RecordOutput,
4
+ RecordProfile,
5
+ VideoProgress,
6
+ VideoRecordingResult,
7
+ } from "../../editor/rules/camera.js";
8
+ import { errorFrom, MountayaElementsError } from "../../errors/rules/errors.js";
9
+ import type { BoundingBox } from "../../geo/rules/types.js";
10
+ import type { UnitFormatOptions } from "../../profile/rules/units.js";
11
+ import { notifyListeners } from "../../rules/listeners.js";
12
+ import { type CameraPlan, type RouteGeometry, refuseUnplannablePlan } from "../rules/plan.js";
13
+ import { type CameraPlanner, synchronousCameraPlanner } from "../rules/planner.js";
14
+ import type { ProfileSource } from "../rules/profileSamples.js";
15
+ import { continuousLine } from "../rules/route.js";
16
+ import { holdsRouteContent, type RouteContent, routeContentOf } from "../rules/routeContent.js";
17
+ import { planDurationMs } from "../rules/spline.js";
18
+ import { capturesSweptViewports } from "../rules/sweptViewports.js";
19
+ import { clearanceStrideFor, posePlanSignature, resolveRouteMarkers } from "../rules/track.js";
20
+ import type { ProfileDesign, VideoRecordingPhase } from "../rules/vocabulary.js";
21
+
22
+ // Published from here, where a flight takes and answers them, and declared beside the recorder,
23
+ // the bounds and the unit options they describe. A consumer of the camera entry names them in a
24
+ // flight's signatures, and reaches them without the editor's renderer.
25
+ export type {
26
+ RecordingCamera,
27
+ RecordOutput,
28
+ RecordProfile,
29
+ VideoProgress,
30
+ VideoRecordingResult,
31
+ } from "../../editor/rules/camera.js";
32
+ export type { BoundingBox } from "../../geo/rules/types.js";
33
+ export type { UnitFormatOptions } from "../../profile/rules/units.js";
34
+
35
+ /**
36
+ * Authoring and running one fly-through, with no product around it.
37
+ *
38
+ * This is the orchestration between a camera plan and a map: resolve the plan to poses against
39
+ * whatever terrain is loaded, warm the tiles the flight will cross, fly it live, capture it, and
40
+ * report progress while that happens. `VideoRunEngine` of `@mountaya/elements/video` owns a
41
+ * single RUN (the abort signal, the camera it restores to, the moving dot). This owns the SESSION: the plan being
42
+ * authored, the route it is anchored to, the overlay settings, the progress a UI reads, and the
43
+ * resolved-pose cache that makes a burst of plan edits cheap. It is a fly-through over a route a
44
+ * host holds, with no product around it: no itinerary id, no entitlement, no store, no bus.
45
+ *
46
+ * It names no renderer: the map is declared structurally and every type it reads is
47
+ * renderer-free, so `@mountaya/elements/camera` publishes it. A consumer recording with MapLibre
48
+ * builds the map from `@mountaya/elements/video`, and `@mountaya/studio` flies its video wizard
49
+ * on it with no renderer in its graph.
50
+ *
51
+ * **State, subscribe, commands, teardown**, in that order, because it is the contract a
52
+ * binding is written against. `getSnapshot` and `subscribe` are `useSyncExternalStore`'s two
53
+ * arguments exactly, so a React binding is a few lines; they are equally a Vue `shallowRef` or a
54
+ * Svelte store, which is the property that makes this the layer a second framework binds to rather
55
+ * than a layer it reimplements. Nothing here imports React.
56
+ */
57
+
58
+ /**
59
+ * The map surface a flight drives, declared structurally.
60
+ *
61
+ * Structural rather than `MapClient`, for the same reason `CollabDispatch` is: a flight needs a
62
+ * few methods, and a consumer driving their own renderer should be able to satisfy it without
63
+ * adopting a platform-agnostic command interface built for a tool bus. `MapLibreClient` satisfies
64
+ * it by having the right shape, and so does a test double.
65
+ *
66
+ * `prewarmTerrain` and `warmPoses` are two warms and not one, which looks redundant until the
67
+ * failure is named. `prewarmTerrain` frames the route's bounds and settles the DEM, so the
68
+ * clearance pass reads real peak heights rather than null: without it a flight plans through a
69
+ * mountain. `warmPoses` jumps the camera through the flight's own viewports at the flight's own
70
+ * ZOOM, so the capture loop films loaded tiles rather than black ones. The first is about the
71
+ * plan; the second is about the picture.
72
+ */
73
+ export interface VideoFlightMap {
74
+ /**
75
+ * jumpToPose lands the camera on one full pose immediately, with no animation.
76
+ *
77
+ * The full pose and not a centre: a scrubbed frame has to match the pitch and bearing the flight
78
+ * would be at that fraction, or the scrubber shows a picture the video never contains.
79
+ */
80
+ jumpToPose: (pose: RecordingCamera) => void;
81
+ /**
82
+ * prewarmTerrain frames the route's bounds and resolves once the DEM under them has settled.
83
+ *
84
+ * The box of a route across the antimeridian runs past 180 or below -180, the form a
85
+ * renderer frames across the line.
86
+ */
87
+ prewarmTerrain: (bounds: BoundingBox) => Promise<void>;
88
+ previewPoses: (
89
+ poses: RecordingCamera[],
90
+ options: {
91
+ focusGlyphUrl?: string | undefined;
92
+ markers?: [number, number][] | undefined;
93
+ onProgress?: ((progress: VideoProgress) => void) | undefined;
94
+ planDurationMs?: number | undefined;
95
+ signal: AbortSignal;
96
+ },
97
+ ) => Promise<void>;
98
+ recordPoses: (
99
+ poses: readonly RecordingCamera[],
100
+ output: RecordOutput,
101
+ options: {
102
+ focusGlyphUrl?: string | undefined;
103
+ markers?: [number, number][] | undefined;
104
+ onProgress?: ((progress: VideoProgress) => void) | undefined;
105
+ profile?: RecordProfile | undefined;
106
+ signal: AbortSignal;
107
+ /**
108
+ * Whether the caller has just warmed these very poses' viewports, every frame's zoom and
109
+ * pitch included, so the recorder captures without a warm pass of its own. Absent or
110
+ * false, the recorder warms them first.
111
+ */
112
+ warmed?: boolean | undefined;
113
+ },
114
+ ) => Promise<VideoRecordingResult>;
115
+ sampleTerrainElevation: (lngLat: [number, number]) => number | null;
116
+ warmPoses: (poses: readonly RecordingCamera[], signal?: AbortSignal) => Promise<void>;
117
+ }
118
+
119
+ /**
120
+ * The elevation overlay burnt into the frame, and the units it is written in.
121
+ *
122
+ * The units are the FLIGHT's rather than the surrounding application's, which is the whole reason
123
+ * they are here: a video is shared with people who are not the author, so a French creator
124
+ * exporting for an American audience states imperial on the export without touching what their own
125
+ * screen reads in. `language` doubles as the BCP 47 locale the numbers are formatted with.
126
+ */
127
+ export interface VideoFlightProfile {
128
+ readonly design: ProfileDesign;
129
+ readonly enabled: boolean;
130
+ readonly language: UnitFormatOptions["language"];
131
+ readonly length: UnitFormatOptions["length"];
132
+ readonly pace: UnitFormatOptions["pace"];
133
+ readonly slope: UnitFormatOptions["slope"];
134
+ }
135
+
136
+ /**
137
+ * The overlay a flight opens with: off, the graph design, metric, degrees and a speed
138
+ * stated per unit of time, in English.
139
+ */
140
+ export const defaultVideoFlightProfile: VideoFlightProfile = {
141
+ design: "graph",
142
+ enabled: false,
143
+ language: "en",
144
+ length: "metric",
145
+ pace: "per-time",
146
+ slope: "degrees",
147
+ };
148
+
149
+ /**
150
+ * What a flight is doing, as a subscriber reads it.
151
+ *
152
+ * A discriminated union rather than a pair of booleans and a number, because the states carry
153
+ * different payloads: idle carries none, a preview carries how far through it is, a parked camera
154
+ * carries where it rests, and a recording carries how far through it is plus which phase the
155
+ * work is in. A progress bar at 100% during `encoding` is a muxer finalising a long file, and a
156
+ * readout that could not say so reads as a hang.
157
+ *
158
+ * `parked` is the camera at rest on a frame of the flight, where a {@link VideoFlightEngine.seek}
159
+ * left it: `fraction` is how far through the flight that frame is, between 0 and 1. It is a kind
160
+ * of its own, apart from `previewing`, so a transport draws Play over a parked camera and Pause
161
+ * over a preview under way, and a scrubber reads its position off either.
162
+ */
163
+ export type VideoFlightStatus =
164
+ | { readonly kind: "idle" }
165
+ | { readonly fraction: number; readonly kind: "parked" }
166
+ | { readonly fraction: number; readonly kind: "previewing" }
167
+ | { readonly fraction: number; readonly kind: "recording"; readonly phase: VideoRecordingPhase };
168
+
169
+ /** Everything a UI renders from, and the whole of what `subscribe` announces a change to. */
170
+ export interface VideoFlight {
171
+ /**
172
+ * The activity silhouette the moving focus dot masks over its white disc, or null for a plain
173
+ * disc. A URL rather than a glyph name: what artwork an activity has is the caller's vocabulary.
174
+ */
175
+ readonly activityGlyphUrl: string | null;
176
+ readonly plan: CameraPlan;
177
+ readonly profile: VideoFlightProfile;
178
+ /**
179
+ * Where the overlay's per-frame readouts are resolved from. Null leaves the overlay unpainted.
180
+ */
181
+ readonly profileSource: ProfileSource | null;
182
+ /** The flattened route the plan is anchored to. Null until a caller supplies one. */
183
+ readonly route: RouteGeometry | null;
184
+ readonly status: VideoFlightStatus;
185
+ }
186
+
187
+ /**
188
+ * Why a flight did not run, as a value rather than a throw.
189
+ *
190
+ * `recordPoses` already resolves rather than rejecting, and a preview that was cancelled is the
191
+ * normal case rather than an error, so the whole surface answers the same way. `aborted` covers a
192
+ * caller's cancel, a newer run replacing this one and a dispose, whenever each lands, the terrain
193
+ * warm-up included: they are indistinguishable to the run that stopped, and a caller that needs
194
+ * to tell them apart knows which one it asked for.
195
+ *
196
+ * `failed` is the one refusal that carries a payload, the `error` the flight stopped on: a throw
197
+ * from the map or the planner, or a fraction that is no number. A thrown value that is no
198
+ * `Error` arrives wrapped in a `MountayaElementsRejectionError` that holds it as the cause. A
199
+ * subscriber that throws is no failure of the flight, and never arrives here.
200
+ */
201
+ export type VideoFlightOutcome =
202
+ | { readonly ok: true }
203
+ | { readonly error: Error; readonly ok: false; readonly reason: "failed" }
204
+ | { readonly ok: false; readonly reason: "aborted" | "no-map" | "no-route" };
205
+
206
+ /**
207
+ * A finished recording, or why there is not one.
208
+ *
209
+ * `failed` is the one refusal that carries a payload, the `error` the run stopped on, because a
210
+ * caller has something to tell its user there: the recorder's own (a missing `mediabunny`, a
211
+ * surface, frame capture or encoder that could not be built, a capture or encode that threw), or
212
+ * a throw from the map or the planner before the first frame. `aborted` is a cancel, as in
213
+ * {@link VideoFlightOutcome}. `unavailable` is a recording that could not start, which nobody
214
+ * cancelled: no recorder wired to the map, no drawing buffer to read, a canvas under the minimum
215
+ * size, no 2D context to composite in, a first frame that read black. `no-frames` is a result with
216
+ * no blob, no cancel and no error, which the shipped recorder never resolves and a map a host
217
+ * supplies may.
218
+ */
219
+ export type VideoFlightRecording =
220
+ | { readonly blob: Blob; readonly extension: string; readonly ok: true }
221
+ | { readonly error: Error; readonly ok: false; readonly reason: "failed" }
222
+ | {
223
+ readonly ok: false;
224
+ readonly reason: "aborted" | "no-frames" | "no-map" | "no-route" | "unavailable";
225
+ };
226
+
227
+ /**
228
+ * VideoFlightOptions is what a {@link VideoFlightEngine} is built with: the plan it opens on, and
229
+ * optionally the map it drives, where the plan is resolved, how many resolved flights it keeps
230
+ * and whether a recording carries the brand mark.
231
+ */
232
+ export interface VideoFlightOptions {
233
+ /**
234
+ * The plan a flight opens on. Required, because there is no default worth inventing: a plan
235
+ * names a mode, an output and a keyframe list, and `cameraPlanGenerators` builds one from a
236
+ * route in a line.
237
+ */
238
+ readonly plan: CameraPlan;
239
+ /**
240
+ * The map the flight drives. Omitted or null, every run answers `no-map` and the state still
241
+ * works, which is what lets a caller author a plan before a canvas exists.
242
+ */
243
+ readonly map?: VideoFlightMap | null | undefined;
244
+ /**
245
+ * Where a plan is turned into per-frame poses. Defaults to resolving on the calling thread,
246
+ * which is what the studio does; `measuredCameraPlanner` answers whether anything else is
247
+ * warranted.
248
+ */
249
+ readonly planner?: CameraPlanner | undefined;
250
+ /**
251
+ * How many resolved flights to memoize. Four covers a session's working set (the current
252
+ * preview, the record's full-density resolve, and a recent edit or two) while keeping the
253
+ * retained per-frame pose arrays to a handful.
254
+ *
255
+ * A whole number, 0 or more. At 0 no flight is kept and every run resolves again.
256
+ *
257
+ * @default 4
258
+ */
259
+ readonly poseCacheSize?: number | undefined;
260
+ }
261
+
262
+ /** The command a failure is named after when what was thrown is no `Error`. */
263
+ type VideoFlightCommand = "Preview" | "Recording" | "Seek";
264
+
265
+ /** The resolved flight one cache entry holds, with the plan and the route it was resolved for. */
266
+ interface ResolvedFlight {
267
+ readonly markers: [number, number][];
268
+ readonly plan: CameraPlan;
269
+ readonly planDurationMs: number;
270
+ readonly poses: RecordingCamera[];
271
+ readonly route: RouteGeometry;
272
+ }
273
+
274
+ /** A warm in progress: the route revision it is for, and what every flight that wants it awaits. */
275
+ interface TerrainWarm {
276
+ readonly revision: number;
277
+ settled: Promise<void>;
278
+ }
279
+
280
+ /**
281
+ * A flight warm in progress: a {@link TerrainWarm} with the handle that ends its sweep early, and
282
+ * the flights waiting on it, each as the answer to whether it has let go of the camera: a preview
283
+ * whose run was stopped, a seek a newer flight overtook. A sweep every one of them has left moves
284
+ * the camera for nobody, and a pause or a stop ends it.
285
+ */
286
+ interface FlightWarm extends TerrainWarm {
287
+ readonly controller: AbortController;
288
+ readonly waiters: Set<() => boolean>;
289
+ }
290
+
291
+ /**
292
+ * The run a preview or a record holds: the handle that stops it, which of the two it is, and
293
+ * whether a preview's flight has begun.
294
+ */
295
+ interface FlightRun {
296
+ readonly controller: AbortController;
297
+ /**
298
+ * Whether the preview has stated its first `previewing` status. A run that replaced a flight in
299
+ * the air keeps the status that flight left until it flies, so the status alone does not say
300
+ * the flight is this run's.
301
+ */
302
+ flying: boolean;
303
+ readonly kind: "preview" | "record";
304
+ readonly signal: AbortSignal;
305
+ }
306
+
307
+ /** A record's own sweep in progress: a {@link TerrainWarm} with the run's signal it ends on. */
308
+ interface RecordWarm extends TerrainWarm {
309
+ readonly signal: AbortSignal;
310
+ }
311
+
312
+ const DEFAULT_POSE_CACHE_SIZE = 4;
313
+
314
+ /** The fewest vertices a line a flight follows holds: one vertex has no direction to fly in. */
315
+ const ROUTE_VERTICES_MIN = 2;
316
+
317
+ /**
318
+ * A route's bounding box, or null when it has no usable coordinates.
319
+ *
320
+ * Read off the route as one continuous line, so a route across the antimeridian is boxed the
321
+ * short way round, with `east` past 180 or `west` below -180: the box of its longitudes as
322
+ * written is the whole world's width, and a warm that frames it settles no tile the flight
323
+ * crosses.
324
+ */
325
+ const routeBounds = (route: RouteGeometry): BoundingBox | null => {
326
+ let west = Number.POSITIVE_INFINITY;
327
+ let south = Number.POSITIVE_INFINITY;
328
+ let east = Number.NEGATIVE_INFINITY;
329
+ let north = Number.NEGATIVE_INFINITY;
330
+
331
+ for (const [lng, lat] of continuousLine(route.line)) {
332
+ if (lng === undefined || lat === undefined) {
333
+ continue;
334
+ }
335
+
336
+ west = Math.min(west, lng);
337
+ south = Math.min(south, lat);
338
+ east = Math.max(east, lng);
339
+ north = Math.max(north, lat);
340
+ }
341
+
342
+ return Number.isFinite(west) ? [west, south, east, north] : null;
343
+ };
344
+
345
+ /**
346
+ * flightError is the error a `failed` outcome carries: what the map or the planner threw, as
347
+ * {@link errorFrom} turns a caught value into an `Error`. A value that is no `Error` arrives as
348
+ * a `MountayaElementsRejectionError` holding it as its cause, so the field always has a message a
349
+ * caller can show, whatever was thrown.
350
+ */
351
+ const flightError = (flight: VideoFlightCommand, cause: unknown): Error =>
352
+ errorFrom(cause, `${flight} failed.`);
353
+
354
+ /**
355
+ * poseCacheSizeFrom reads how many flights the engine memoizes, refusing a count no cache keeps.
356
+ *
357
+ * @throws {MountayaElementsError} When the size is not a whole number, 0 or more. `NaN` never
358
+ * trims the cache and a negative evicts every flight as it is stored, so either would read as a
359
+ * setting while holding nothing to it.
360
+ */
361
+ const poseCacheSizeFrom = (size: number | undefined): number => {
362
+ if (size === undefined) {
363
+ return DEFAULT_POSE_CACHE_SIZE;
364
+ }
365
+
366
+ if (!Number.isInteger(size) || size < 0) {
367
+ throw new MountayaElementsError(
368
+ `VideoFlightEngine: poseCacheSize is ${String(size)}; pass a whole number of flights, 0 ` +
369
+ `or more, or omit it for ${DEFAULT_POSE_CACHE_SIZE}.`,
370
+ );
371
+ }
372
+
373
+ return size;
374
+ };
375
+
376
+ /**
377
+ * planFrom reads a plan a caller hands over, refusing the members no flight can be planned with.
378
+ *
379
+ * The compiler holds each of them for a caller it type-checks, and `createCameraPlan` refuses the
380
+ * same members as it builds a plan, through the one rule both read
381
+ * ({@link refuseUnplannablePlan}). This is for the plans neither saw: one read back from storage,
382
+ * or composed in JavaScript. A bitrate above 0 and outside the encoder's window is taken as it
383
+ * is, because the recorder clamps it.
384
+ *
385
+ * @throws {MountayaElementsError} Naming `plan`, when it is no object, as a key never written
386
+ * reads back `null`. Naming the member as `plan.member`, when `output` is no object, `shots`
387
+ * no array or an entry of `shots` no object, when `version` is not 1, when
388
+ * `targetDurationMs` is not a finite number above 0, when `output.fps` is not one of the frame
389
+ * rates a plan records at, when a stated `output.bitrateMbps` is not a finite number above 0, or
390
+ * when a shot holds a number that is not finite, a `holdMs` below 0 or a `speedScale` at or
391
+ * below 0.
392
+ */
393
+ const planFrom = (plan: CameraPlan): CameraPlan => {
394
+ refuseUnplannablePlan("VideoFlightEngine", plan, "plan");
395
+
396
+ return plan;
397
+ };
398
+
399
+ /**
400
+ * Whether a recording result states that the run could not start, as opposed to a cancel. A
401
+ * result that states no `reason` beside its `cancelled` is a cancel.
402
+ */
403
+ const couldNotStart = (result: VideoRecordingResult): boolean => result.reason === "unavailable";
404
+
405
+ /**
406
+ * VideoFlightEngine authors and runs one fly-through over a route a host holds: it holds the
407
+ * plan, the route and the overlay settings, previews the flight on the map, pauses and plays it
408
+ * on, records it to a video file, and parks the camera at any point of it.
409
+ *
410
+ * The contract a binding is written against is state, subscribe, commands, teardown.
411
+ * {@link getSnapshot} answers the state, the same object until something changes, and
412
+ * {@link subscribe} hears every change, so the two are `useSyncExternalStore`'s arguments as they
413
+ * are. The commands (`setPlan`, `setRoute`, `setProfile`, `preview`, `play`, `pause`, `seek`,
414
+ * `stop`, `record`, `abort`) write it, and a run answers an outcome rather than rejecting.
415
+ * {@link dispose} ends every run and lets go of the map, which the engine never owns.
416
+ *
417
+ * Recording needs a map built with `preserveDrawingBuffer` and the `mediabunny` peer, which
418
+ * `@mountaya/elements/video` loads only when a recording starts.
419
+ *
420
+ * @example
421
+ * ```ts
422
+ * import { MountayaMap } from "@mountaya/elements";
423
+ * import {
424
+ * cameraPlanGenerators,
425
+ * type RouteGeometry,
426
+ * VideoFlightEngine,
427
+ * } from "@mountaya/elements/camera";
428
+ * import { MapLibreViewClient, VideoRunEngine } from "@mountaya/elements/video";
429
+ *
430
+ * declare const map: MountayaMap;
431
+ * declare const route: RouteGeometry;
432
+ *
433
+ * const flight = new VideoFlightEngine({
434
+ * map: new MapLibreViewClient(map, {
435
+ * video: new VideoRunEngine(map.raw, map.events, () => map.loadOrganization()),
436
+ * }),
437
+ * plan: cameraPlanGenerators.overview(route, { targetDurationMs: 20_000 }),
438
+ * });
439
+ * flight.setRoute(route);
440
+ * flight.subscribe(() => console.log(flight.getSnapshot().status.kind));
441
+ *
442
+ * const result = await flight.record();
443
+ * if (result.ok) {
444
+ * console.log(`flight.${result.extension}`, result.blob.size);
445
+ * }
446
+ * flight.dispose();
447
+ * ```
448
+ */
449
+ export class VideoFlightEngine {
450
+ private flight: VideoFlight;
451
+ private readonly listeners = new Set<() => void>();
452
+ private readonly map: VideoFlightMap | null;
453
+ private readonly planner: CameraPlanner;
454
+ private readonly poseCacheSize: number;
455
+
456
+ /**
457
+ * The run in flight. One at a time: every preview and record stops the run before it as it
458
+ * starts, because two flights over one map would fight for the camera.
459
+ */
460
+ private run: FlightRun | null = null;
461
+
462
+ /**
463
+ * How far through the flight a preview that {@link pause} stopped in the air had flown, which
464
+ * {@link play} flies on from. Null when no flight is paused.
465
+ */
466
+ private pausedAt: number | null = null;
467
+
468
+ /**
469
+ * The memoized flights, an insertion-ordered LRU. Keyed on the pose-affecting plan fields, the
470
+ * route's revision, whether this is the full-density record resolve or a decimated preview one,
471
+ * and the DEM epoch, so a format-only edit collapses onto the same key and reuses the flight,
472
+ * while a resolve cached against a cold DEM is dropped once the flight warm lands.
473
+ */
474
+ private readonly poseCache = new Map<string, ResolvedFlight>();
475
+
476
+ /** Bumped when the flight terrain warms, which is what invalidates a cold-DEM resolve. */
477
+ private demEpoch = 0;
478
+
479
+ /**
480
+ * Advanced each time the route's content is read and differs from {@link routeContent}: as
481
+ * {@link setRoute} is handed a route, and as a flight begins. The warm guards and the pose
482
+ * cache name a route by it, so telling two routes apart costs one walk per `setRoute` and one
483
+ * per flight, each ending at the first difference.
484
+ */
485
+ private routeRevision = 0;
486
+
487
+ /** What the held route held when it was last read, or null while no route is held. */
488
+ private routeContent: RouteContent | null = null;
489
+
490
+ /** The route revision each warm has already run for, so neither repeats. */
491
+ private terrainWarmedRevision: number | null = null;
492
+ private flightWarmedRevision: number | null = null;
493
+
494
+ /** The terrain warm in progress, which a flight asked for meanwhile over the same route joins. */
495
+ private terrainWarm: TerrainWarm | null = null;
496
+
497
+ /**
498
+ * The flight warm in progress, shared the same way. One sweep at a time moves the camera, and
499
+ * the engine holds the handle that ends it: {@link abort}, {@link dispose}, another route and
500
+ * a record, which sweeps for itself, each end it.
501
+ */
502
+ private flightWarm: FlightWarm | null = null;
503
+
504
+ /**
505
+ * The sweep a record makes for itself, while it is in progress. It is the flight's sweep over
506
+ * that route, so a flight asked for meanwhile joins it and starts none of its own. It ends on
507
+ * the record's run and on nothing else, which is why it is held apart from
508
+ * {@link flightWarm}: another route set meanwhile ends a shared sweep, and leaves a record on
509
+ * the route it began with.
510
+ */
511
+ private recordWarm: RecordWarm | null = null;
512
+
513
+ /**
514
+ * The settling of every map call that still holds the camera: the run in flight's, and that of
515
+ * each flight stopped since whose `previewPoses` or `recordPoses` has yet to settle. A seek
516
+ * parks the camera once all of them have let go of it.
517
+ */
518
+ private readonly landings = new Set<Promise<void>>();
519
+
520
+ /**
521
+ * Whether a seek stopped a flight and no status has replaced the one that flight left. A
522
+ * stopped flight's own exit commits nothing, so its status is settled by the seek that
523
+ * stopped it or, when that seek was overtaken, by the one that parks or fails in its place.
524
+ * {@link commit} clears it on every status it states.
525
+ */
526
+ private seekStoppedFlight = false;
527
+
528
+ /** The last encoded recording, so a save does not re-encode. */
529
+ private lastRecording: { blob: Blob; extension: string } | null = null;
530
+
531
+ /** Aborted by {@link dispose}, and the signal a seek resolves under, since it holds no run. */
532
+ private readonly disposal = new AbortController();
533
+
534
+ /** Whether {@link dispose} has run, read off the one signal it aborts. */
535
+ private get disposed(): boolean {
536
+ return this.disposal.signal.aborted;
537
+ }
538
+
539
+ /**
540
+ * Advanced by every flight asked for, a seek included, and by {@link abort}. A seek holds no
541
+ * run, so it reads this after each of its awaits to learn whether a newer preview, record or
542
+ * seek was asked for since it began, or an abort, and leaves the camera alone when one was.
543
+ */
544
+ private flightSequence = 0;
545
+
546
+ /**
547
+ * @throws {MountayaElementsError} When `poseCacheSize` is not a whole number, 0 or more, when
548
+ * the plan is no object, or when it holds a member no flight can be planned with.
549
+ * {@link setPlan} lists them.
550
+ */
551
+ constructor(options: VideoFlightOptions) {
552
+ this.map = options.map ?? null;
553
+ this.planner = options.planner ?? synchronousCameraPlanner();
554
+ this.poseCacheSize = poseCacheSizeFrom(options.poseCacheSize);
555
+ this.flight = {
556
+ activityGlyphUrl: null,
557
+ plan: planFrom(options.plan),
558
+ profile: defaultVideoFlightProfile,
559
+ profileSource: null,
560
+ route: null,
561
+ status: { kind: "idle" },
562
+ };
563
+ }
564
+
565
+ // -----------------------------------------------------------------------------------------
566
+ // State
567
+ // -----------------------------------------------------------------------------------------
568
+
569
+ /**
570
+ * getSnapshot returns the current flight, by reference.
571
+ *
572
+ * Stable between changes, deliberately: it is `useSyncExternalStore`'s second argument, and a
573
+ * fresh object per call makes React's own tearing check loop forever. Every command below
574
+ * replaces the object rather than mutating it, so identity IS the change signal.
575
+ */
576
+ getSnapshot(): VideoFlight {
577
+ return this.flight;
578
+ }
579
+
580
+ /**
581
+ * subscribe registers a listener for every change, and returns its own unsubscribe.
582
+ *
583
+ * A listener that throws keeps no other listener from being told and changes no command's
584
+ * answer: a setter, {@link abort} and {@link reset} throw nothing, and a preview, a record or
585
+ * a seek answers for the flight alone. What the listener threw is the subscribing program's
586
+ * own fault, and it reaches the runtime as an uncaught error on a microtask, once per change
587
+ * the listener threw at.
588
+ */
589
+ subscribe(listener: () => void): () => void {
590
+ this.listeners.add(listener);
591
+
592
+ return () => {
593
+ this.listeners.delete(listener);
594
+ };
595
+ }
596
+
597
+ /** The last encoded recording, or null. Held so a save does not re-encode what was just made. */
598
+ get recording(): { blob: Blob; extension: string } | null {
599
+ return this.lastRecording;
600
+ }
601
+
602
+ // -----------------------------------------------------------------------------------------
603
+ // Commands
604
+ // -----------------------------------------------------------------------------------------
605
+
606
+ /**
607
+ * setPlan replaces the plan. Does not abort a run: a plan edit mid-preview takes on the next.
608
+ *
609
+ * @throws {MountayaElementsError} Naming `plan`, when it is no object. Naming the member,
610
+ * when `output` is no object, `shots` no array or an entry of `shots` no object, when
611
+ * `version` is not 1, when `targetDurationMs` is
612
+ * not a finite number above 0, when `output.fps` is not 24, 30 or 60, when a stated
613
+ * `output.bitrateMbps` is not a finite number above 0, or when a shot holds a number that is
614
+ * not finite, a `holdMs` below 0 or a `speedScale` at or below 0: what `createCameraPlan`
615
+ * refuses, by the same rule. The plan the engine held stands.
616
+ */
617
+ setPlan(plan: CameraPlan): void {
618
+ this.commit({ plan: planFrom(plan) });
619
+ }
620
+
621
+ /**
622
+ * setRoute anchors the flight to a route, and resets both warm guards when it changes.
623
+ *
624
+ * Reset on CONTENT, so a re-supplied identical route keeps its warms. A different route has
625
+ * different terrain under it and different tiles to settle, so neither warm carries over, and
626
+ * a flight warm still sweeping the route before it ends at its next stop.
627
+ *
628
+ * The route is held as the object it is given, never copied for a reader, and its content is
629
+ * read here and again as each preview, record and seek begins. So a route edited in place (a
630
+ * track that grows by a push) is flown as it stands when the next flight is asked for, with
631
+ * its warms run again, whether or not it is handed over a second time.
632
+ *
633
+ * A line of fewer than two vertices is held as it is given and flown as no route: every run
634
+ * over it answers `no-route`.
635
+ *
636
+ * Another route stops a preview flying the one before it, and lands a `previewing` or a
637
+ * `parked` status on idle: the camera would fly, or rest on, a route the engine has let go
638
+ * of, under a status that says otherwise. It forgets a paused flight as well, so the next
639
+ * {@link play} flies the route that arrived from its first frame. A preview still in its
640
+ * warm-up flies the route that arrived, and a record flies the route it began with.
641
+ */
642
+ setRoute(route: RouteGeometry | null): void {
643
+ const content = this.routeContent;
644
+ const changed =
645
+ route === null || content === null
646
+ ? (route === null) !== (content === null)
647
+ : !holdsRouteContent(route, content);
648
+
649
+ if (!changed) {
650
+ this.commit({ route });
651
+
652
+ return;
653
+ }
654
+
655
+ this.routeChanged(route);
656
+ const status = this.flight.status.kind;
657
+ if (status !== "previewing" && status !== "parked") {
658
+ this.commit({ route });
659
+
660
+ return;
661
+ }
662
+
663
+ // A preview in the air flies poses of the route that leaves. One still in its warm-up has
664
+ // flown nothing, and flies the route that arrived.
665
+ if (status === "previewing" && this.run?.kind === "preview" && this.run.flying) {
666
+ this.run.controller.abort();
667
+ this.run = null;
668
+ }
669
+
670
+ this.commit({ route, status: { kind: "idle" } });
671
+ }
672
+
673
+ /**
674
+ * setProfile merges a partial overlay update over the current one.
675
+ *
676
+ * A merge rather than a replacement, because every caller changes one field (the enable flag, a
677
+ * unit, the design), and a replacement would make each of those restate the others.
678
+ */
679
+ setProfile(profile: Partial<VideoFlightProfile>): void {
680
+ this.commit({ profile: { ...this.flight.profile, ...profile } });
681
+ }
682
+
683
+ /** setProfileSource sets where the overlay's per-frame readouts are resolved from. */
684
+ setProfileSource(profileSource: ProfileSource | null): void {
685
+ this.commit({ profileSource });
686
+ }
687
+
688
+ /** setActivityGlyph sets the silhouette the moving focus dot masks, or null for a plain disc. */
689
+ setActivityGlyph(activityGlyphUrl: string | null): void {
690
+ this.commit({ activityGlyphUrl });
691
+ }
692
+
693
+ // -----------------------------------------------------------------------------------------
694
+ // Running
695
+ // -----------------------------------------------------------------------------------------
696
+
697
+ /**
698
+ * preview flies the plan live over the map from its first frame, encoding nothing, and reports
699
+ * progress. It forgets a flight {@link pause} stopped.
700
+ *
701
+ * Paced to the plan's own wall-clock so the rehearsal runs at the speed the recording will and
702
+ * dwells on holds: a preview that ran at frame rate would mislead about both.
703
+ *
704
+ * The run opens before the two warms rather than after them. Both warms move the camera and can
705
+ * take seconds on a cold cache, which is when a caller reaches for {@link pause}: a run opened
706
+ * after them would leave a pause, an abort, a dispose or a newer flight during the warm with
707
+ * nothing to stop, and the fly would start anyway. A stop there answers `aborted`, starts no
708
+ * further warm and flies no frame.
709
+ *
710
+ * The flight is of the plan and the route the engine holds once both warms have settled. A
711
+ * route set during a warm is warmed in turn, the DEM over its bounds and then its viewports,
712
+ * before any pose is resolved over it.
713
+ *
714
+ * It never rejects. A map or a planner that throws answers `failed` with the error it stopped
715
+ * on. A throw that follows a stop answers `aborted`, because the caller asked the run to
716
+ * stop. A subscriber that throws changes neither ({@link subscribe}). Every exit ends the run
717
+ * and lands on idle unless a newer one holds it by then.
718
+ */
719
+ preview(): Promise<VideoFlightOutcome> {
720
+ return this.startPreview(false);
721
+ }
722
+
723
+ /**
724
+ * play flies the plan on from where a flight was stopped, as {@link preview} flies it.
725
+ *
726
+ * It resumes a preview {@link pause} stopped in the air, from the frame nearest where it was and
727
+ * over the rest of the plan's wall-clock. Over a `parked` status it flies on from the frame
728
+ * {@link seek} parked the camera on, as a player plays on from where its reader put the head.
729
+ * It flies from the first frame when there is neither, and when nothing is left to fly past the
730
+ * frame it would start on. A play stopped in its warm-up flies nothing, and keeps where it was
731
+ * to fly on from for the next one.
732
+ */
733
+ play(): Promise<VideoFlightOutcome> {
734
+ return this.startPreview(true);
735
+ }
736
+
737
+ /**
738
+ * startPreview is {@link preview} and {@link play}: it opens the run, reads where the flight
739
+ * flies on from, and answers what the fly settled on.
740
+ */
741
+ private async startPreview(resume: boolean): Promise<VideoFlightOutcome> {
742
+ const map = this.map;
743
+ if (!map) {
744
+ return { ok: false, reason: "no-map" };
745
+ }
746
+
747
+ const run = this.beginRun("preview");
748
+ if (run.signal.aborted) {
749
+ return { ok: false, reason: "aborted" };
750
+ }
751
+
752
+ this.readRoute();
753
+ const status = this.flight.status;
754
+ if (!resume) {
755
+ this.pausedAt = null;
756
+ } else if (this.pausedAt === null && status.kind === "parked") {
757
+ // Read as the play is asked for: the status moves once the flight begins, and a play
758
+ // stopped in its warm-up keeps the frame for the next.
759
+ this.pausedAt = status.fraction;
760
+ }
761
+
762
+ let outcome: VideoFlightOutcome;
763
+ try {
764
+ outcome = await this.flyPreview(map, run);
765
+ } catch (cause) {
766
+ // A map may end a warm or a fly on its signal by rejecting, and the run stopped then
767
+ // because the caller asked it to.
768
+ outcome = run.signal.aborted
769
+ ? { ok: false, reason: "aborted" }
770
+ : { error: flightError("Preview", cause), ok: false, reason: "failed" };
771
+ }
772
+
773
+ return this.endRun(run, outcome);
774
+ }
775
+
776
+ /**
777
+ * flyPreview is {@link preview} and {@link play} from their first warm to the end of their
778
+ * fly, under the run they opened. It throws what the map or the planner threw, which they
779
+ * answer.
780
+ */
781
+ private async flyPreview(map: VideoFlightMap, run: FlightRun): Promise<VideoFlightOutcome> {
782
+ await this.warmRoute(() => run.signal.aborted);
783
+ if (run.signal.aborted) {
784
+ return { ok: false, reason: "aborted" };
785
+ }
786
+
787
+ const resolved = await this.resolve({ pass: "preview", signal: run.signal });
788
+ if (run.signal.aborted) {
789
+ return { ok: false, reason: "aborted" };
790
+ }
791
+
792
+ if (!resolved) {
793
+ return { ok: false, reason: "no-route" };
794
+ }
795
+
796
+ const lastIndex = Math.max(0, resolved.poses.length - 1);
797
+ const resumeAt = Math.min(lastIndex, Math.round((this.pausedAt ?? 0) * lastIndex));
798
+ // Nothing is left to fly past the last frame, so a flight that would start there starts over.
799
+ const from = resumeAt === lastIndex ? 0 : resumeAt;
800
+ const startFraction = lastIndex === 0 ? 0 : from / lastIndex;
801
+ this.pausedAt = null;
802
+ run.flying = true;
803
+ this.commit({ status: { fraction: startFraction, kind: "previewing" } });
804
+ await this.fly(
805
+ map.previewPoses(from === 0 ? resolved.poses : resolved.poses.slice(from), {
806
+ ...(this.flight.activityGlyphUrl === null
807
+ ? {}
808
+ : { focusGlyphUrl: this.flight.activityGlyphUrl }),
809
+ markers: from === 0 ? resolved.markers : resolved.markers.slice(from),
810
+ onProgress: (progress) => {
811
+ // A frame reported after the run was stopped is not this flight's to state.
812
+ if (this.run === run) {
813
+ this.commit({
814
+ status: {
815
+ fraction: startFraction + progress.fraction * (1 - startFraction),
816
+ kind: "previewing",
817
+ },
818
+ });
819
+ }
820
+ },
821
+ planDurationMs: resolved.planDurationMs * (1 - startFraction),
822
+ signal: run.signal,
823
+ }),
824
+ );
825
+
826
+ return run.signal.aborted ? { ok: false, reason: "aborted" } : { ok: true };
827
+ }
828
+
829
+ /**
830
+ * record captures one frame per pose and encodes them, reporting progress with its phase.
831
+ *
832
+ * Resolved at full density (stride 1), where a preview resolves at the decimated clearance
833
+ * stride, so the artifact is what the plan describes rather than what was cheap to rehearse.
834
+ *
835
+ * The run opens before the terrain warm, for the reason {@link preview} gives, and the flight
836
+ * warm inside the resolve takes its signal: a stop, an abort or a dispose during either warm
837
+ * answers `aborted`, starts no further warm and captures no frame. Over a route a flight can
838
+ * follow, the status reads `recording` in its `preparing` phase from the moment the run opens,
839
+ * so a reader sees the press land while the terrain warms.
840
+ *
841
+ * A run stopped before the recorder answers keeps nothing: it answers `aborted`, whatever the
842
+ * map resolved, since a recorder a host supplies may finish a file after its signal aborted.
843
+ *
844
+ * It never rejects. A recorder that fails, or a map or planner that throws on the way to the
845
+ * first frame, answers `failed` with the error it stopped on, and a throw that follows an abort
846
+ * answers `aborted`, because the caller asked the run to stop. A subscriber that throws
847
+ * changes neither ({@link subscribe}). A recording
848
+ * the map could not start answers `unavailable`, which is no cancel: the result states
849
+ * `reason: "unavailable"` beside its `cancelled`. Every exit ends the run and lands on idle
850
+ * unless a newer run holds it by then, so a caller holding a recording state always has an
851
+ * outcome to settle it on.
852
+ *
853
+ * The record flies the plan and the route it began with. One set while it warms takes on the
854
+ * next flight, so the poses, the encoder's output and the overlay's samples stay those of one
855
+ * plan. Whether its frames carry the Mountaya watermark is the map's organization's to answer,
856
+ * read as the capture begins: no member of the engine takes the mark off.
857
+ */
858
+ async record(): Promise<VideoFlightRecording> {
859
+ const map = this.map;
860
+ if (!map) {
861
+ return { ok: false, reason: "no-map" };
862
+ }
863
+
864
+ const run = this.beginRun("record");
865
+ if (run.signal.aborted) {
866
+ return { ok: false, reason: "aborted" };
867
+ }
868
+
869
+ this.readRoute();
870
+
871
+ // A record sweeps the flight for itself, under its own signal, so a sweep an earlier flight
872
+ // left running ends here: two would fight for the camera.
873
+ this.endFlightWarm();
874
+
875
+ if (this.flyableRoute()) {
876
+ this.commit({ status: { fraction: 0, kind: "recording", phase: "preparing" } });
877
+ }
878
+
879
+ let outcome: VideoFlightRecording;
880
+ try {
881
+ outcome = await this.flyRecording(map, run);
882
+ } catch (cause) {
883
+ // A map may end a warm or a capture on its signal by rejecting, and the run stopped then
884
+ // because the caller asked it to.
885
+ outcome = run.signal.aborted
886
+ ? { ok: false, reason: "aborted" }
887
+ : { error: flightError("Recording", cause), ok: false, reason: "failed" };
888
+ }
889
+
890
+ return this.endRun(run, outcome);
891
+ }
892
+
893
+ /**
894
+ * flyRecording is {@link record} from its terrain warm to the recorder's answer, under the run
895
+ * it opened. It throws what the map or the planner threw, which `record` answers.
896
+ */
897
+ private async flyRecording(map: VideoFlightMap, run: FlightRun): Promise<VideoFlightRecording> {
898
+ // A subscriber told of `preparing` may have stopped the run already.
899
+ if (run.signal.aborted) {
900
+ return { ok: false, reason: "aborted" };
901
+ }
902
+
903
+ await this.prewarmRoute();
904
+ if (run.signal.aborted) {
905
+ return { ok: false, reason: "aborted" };
906
+ }
907
+
908
+ // Whether this record swept, for itself, the very viewports it captures: the recorder then
909
+ // captures without a second sweep. Poses from the cache were swept by nobody this time, and a
910
+ // frame the clearance pass moved shows ground the sweep never framed.
911
+ let swept = false;
912
+ const resolved = await this.resolve({
913
+ onSwept: () => {
914
+ swept = true;
915
+ },
916
+ pass: "record",
917
+ signal: run.signal,
918
+ });
919
+ if (run.signal.aborted) {
920
+ return { ok: false, reason: "aborted" };
921
+ }
922
+
923
+ if (!resolved) {
924
+ return { ok: false, reason: "no-route" };
925
+ }
926
+
927
+ const profile = this.recordProfile(resolved);
928
+ const result = await this.fly(
929
+ map.recordPoses(resolved.poses, resolved.plan.output, {
930
+ ...(this.flight.activityGlyphUrl === null
931
+ ? {}
932
+ : { focusGlyphUrl: this.flight.activityGlyphUrl }),
933
+ markers: resolved.markers,
934
+ onProgress: (progress) => {
935
+ // The recorder reports a frame once it is encoded and reads its signal at the top of
936
+ // the next one, so a frame in flight when the run was stopped still reports.
937
+ if (this.run === run) {
938
+ this.commit({
939
+ status: { fraction: progress.fraction, kind: "recording", phase: progress.phase },
940
+ });
941
+ }
942
+ },
943
+ ...(profile === undefined ? {} : { profile }),
944
+ signal: run.signal,
945
+ ...(swept ? { warmed: true } : {}),
946
+ }),
947
+ );
948
+
949
+ if (run.signal.aborted) {
950
+ return { ok: false, reason: "aborted" };
951
+ }
952
+
953
+ if (result.error !== undefined) {
954
+ return { error: result.error, ok: false, reason: "failed" };
955
+ }
956
+
957
+ if (couldNotStart(result)) {
958
+ return { ok: false, reason: "unavailable" };
959
+ }
960
+
961
+ if (result.cancelled) {
962
+ return { ok: false, reason: "aborted" };
963
+ }
964
+
965
+ if (!result.blob) {
966
+ return { ok: false, reason: "no-frames" };
967
+ }
968
+
969
+ this.lastRecording = { blob: result.blob, extension: result.extension };
970
+
971
+ return { blob: result.blob, extension: result.extension, ok: true };
972
+ }
973
+
974
+ /**
975
+ * seek parks the camera on the pose the flight is at, a fraction of the way through.
976
+ *
977
+ * It aborts any live fly first (a seek that did not would be overwritten by the next preview
978
+ * frame), resolves the flight, and jumps to the nearest frame's FULL pose. The status is left
979
+ * reading `parked` at the requested fraction rather than idle, because that is what a
980
+ * scrubber reads to position itself: the camera is parked mid-flight, not stopped.
981
+ *
982
+ * The pose is of the plan and the route the engine holds as the camera lands. One set while
983
+ * the seek waits, on a warm or on a stopped flight that still holds the camera, is warmed and
984
+ * resolved before the seek parks.
985
+ *
986
+ * The fraction is clamped rather than validated, so a scrubber dragged past its own track is a
987
+ * camera at an endpoint instead of a failure a UI has to render. A fraction that is no number
988
+ * (`NaN`, or a value of another type from a caller the compiler does not check) has no end to
989
+ * clamp to: the seek answers `failed` and touches nothing.
990
+ *
991
+ * A seek waits on the warms like any flight and starts neither twice: one asked for while a
992
+ * warm over the same route is in progress joins it, so a scrubber dragged on a cold route sweeps
993
+ * the camera once. A {@link pause} or a {@link stop} takes no camera, so a seek in its warm-up
994
+ * goes on to park, and the sweep it waits on goes on with it. A seek that parks forgets a
995
+ * paused flight: the next {@link play} flies on from the frame it parked on.
996
+ *
997
+ * A stopped flight lets go of the camera before the seek parks it, whoever stopped it: this
998
+ * seek, a seek before it, an {@link abort} or a newer flight. The seek waits for the map's
999
+ * `previewPoses` or `recordPoses` to settle on the aborted signal, because a run restores the
1000
+ * camera it found as it settles, which for a record is once the frame in flight has ended, and
1001
+ * that restore would land on top of the parked pose.
1002
+ *
1003
+ * A seek after {@link dispose}, or one whose warms a dispose overtook, answers `aborted` and
1004
+ * leaves the camera where it is: a disposed engine does not move the map it let go of. A dispose
1005
+ * during the terrain warm starts no flight warm, and one during the flight warm ends its sweep
1006
+ * at the next stop, as an {@link abort} does. A seek a newer preview, record or seek overtook
1007
+ * during its warms answers `aborted` as well and leaves the camera to the newer one, so a scrub
1008
+ * that lands late never aborts a flight asked for after it, nor parks the camera over a later
1009
+ * scrub.
1010
+ *
1011
+ * It never rejects. A map or a planner that throws answers `failed` with the error it stopped
1012
+ * on and leaves the status as it was, or on idle when a seek had stopped a flight whose status
1013
+ * nothing had replaced: this seek, or one it overtook before that one parked. A seek that
1014
+ * answers `no-route` settles such a status the same way. A subscriber that throws changes
1015
+ * none of it ({@link subscribe}).
1016
+ */
1017
+ async seek(fraction: number): Promise<VideoFlightOutcome> {
1018
+ const map = this.map;
1019
+ if (!map) {
1020
+ return { ok: false, reason: "no-map" };
1021
+ }
1022
+
1023
+ if (this.disposed) {
1024
+ return { ok: false, reason: "aborted" };
1025
+ }
1026
+
1027
+ // Refused before it counts as a flight asked for, so it overtakes no seek still warming.
1028
+ // The kind is read for a caller the compiler does not check: `Math.max` turns what is no
1029
+ // number into NaN, which would park nothing and state a fraction of NaN.
1030
+ if (typeof fraction !== "number" || Number.isNaN(fraction)) {
1031
+ return {
1032
+ error: new MountayaElementsError(
1033
+ `VideoFlightEngine: seek's fraction is ${String(fraction)}; pass a number, which is ` +
1034
+ "held between 0 and 1.",
1035
+ ),
1036
+ ok: false,
1037
+ reason: "failed",
1038
+ };
1039
+ }
1040
+
1041
+ this.readRoute();
1042
+ this.flightSequence += 1;
1043
+ const sequence = this.flightSequence;
1044
+ // A seek installs no run of its own, so it is overtaken rather than aborted: by a dispose, by
1045
+ // an abort, or by a newer preview, record or seek asked for while it warms.
1046
+ const overtaken = (): boolean => this.disposed || this.flightSequence !== sequence;
1047
+
1048
+ let outcome: VideoFlightOutcome;
1049
+ try {
1050
+ outcome = await this.park(map, fraction, overtaken);
1051
+ } catch (cause) {
1052
+ outcome = overtaken()
1053
+ ? { ok: false, reason: "aborted" }
1054
+ : { error: flightError("Seek", cause), ok: false, reason: "failed" };
1055
+ }
1056
+
1057
+ // A parked seek has stated where the camera rests, and an overtaken one leaves the status to
1058
+ // what overtook it. Any other exit settles the status of a flight a seek stopped: that
1059
+ // flight's own exit commits nothing, and no run is held to land it on idle.
1060
+ if (outcome.ok || overtaken() || !this.seekStoppedFlight) {
1061
+ return outcome;
1062
+ }
1063
+
1064
+ return this.land(outcome);
1065
+ }
1066
+
1067
+ /**
1068
+ * park is {@link seek} from its first warm to the pose it lands on. `overtaken` answers
1069
+ * whether a dispose, an abort or a newer flight has taken the camera since the seek began. It
1070
+ * throws what the map or the planner threw, which `seek` answers.
1071
+ */
1072
+ private async park(
1073
+ map: VideoFlightMap,
1074
+ fraction: number,
1075
+ overtaken: () => boolean,
1076
+ ): Promise<VideoFlightOutcome> {
1077
+ for (;;) {
1078
+ await this.warmRoute(overtaken);
1079
+ if (overtaken()) {
1080
+ return { ok: false, reason: "aborted" };
1081
+ }
1082
+
1083
+ const plan = this.flight.plan;
1084
+ const revision = this.routeRevision;
1085
+
1086
+ const resolved = await this.resolve({ pass: "preview", signal: this.disposal.signal });
1087
+ if (overtaken()) {
1088
+ return { ok: false, reason: "aborted" };
1089
+ }
1090
+
1091
+ if (!resolved) {
1092
+ return { ok: false, reason: "no-route" };
1093
+ }
1094
+
1095
+ // Any run still held began before this seek, and its next frame would overwrite the pose.
1096
+ // One stopped in its warm-up had stated no status, so it leaves none to settle.
1097
+ if (this.run) {
1098
+ this.run.controller.abort();
1099
+ this.run = null;
1100
+ this.seekStoppedFlight ||= this.flight.status.kind !== "idle";
1101
+ }
1102
+
1103
+ this.pausedAt = null;
1104
+
1105
+ // A stopped flight holds the camera until its map call settles, and restores the pose it
1106
+ // found as it does. That holds for the run stopped above and for one stopped earlier.
1107
+ if (this.landings.size > 0) {
1108
+ await Promise.all(this.landings);
1109
+ if (overtaken()) {
1110
+ return { ok: false, reason: "aborted" };
1111
+ }
1112
+ }
1113
+
1114
+ // A plan or a route set while the seek waited is the one the engine holds, and the pose
1115
+ // resolved before it belongs to a flight the engine has let go of: the seek warms and
1116
+ // resolves again, over what it holds now.
1117
+ this.readRoute();
1118
+ if (plan !== this.flight.plan || revision !== this.routeRevision) {
1119
+ continue;
1120
+ }
1121
+
1122
+ const at = Math.min(1, Math.max(0, fraction));
1123
+ const pose = resolved.poses[Math.round(at * Math.max(0, resolved.poses.length - 1))];
1124
+ if (pose) {
1125
+ map.jumpToPose(pose);
1126
+ }
1127
+
1128
+ this.commit({ status: { fraction: at, kind: "parked" } });
1129
+
1130
+ return { ok: true };
1131
+ }
1132
+ }
1133
+
1134
+ /**
1135
+ * invalidatePoses drops the memoized flights without touching the terrain warms.
1136
+ *
1137
+ * What a PLAN edit needs, and the distinction from {@link reset} is the expensive half: a new
1138
+ * plan resolves to different poses over the same ground, so the pose cache is stale and the
1139
+ * warms are not. Clearing both would re-run a visible multi-second camera sweep on every shot
1140
+ * nudge.
1141
+ */
1142
+ invalidatePoses(): void {
1143
+ this.poseCache.clear();
1144
+ }
1145
+
1146
+ /**
1147
+ * reset returns the engine to the state a fresh session starts in: no run, no caches, no
1148
+ * warms, no recording, no paused flight, status idle. The plan and the route are left alone:
1149
+ * a caller that wants those changed says so.
1150
+ *
1151
+ * It throws nothing, whatever a subscriber throws as the idle is announced
1152
+ * ({@link subscribe}).
1153
+ */
1154
+ reset(): void {
1155
+ this.abort();
1156
+ this.poseCache.clear();
1157
+ this.terrainWarmedRevision = null;
1158
+ this.flightWarmedRevision = null;
1159
+ this.demEpoch = 0;
1160
+ this.lastRecording = null;
1161
+ }
1162
+
1163
+ /**
1164
+ * pause stops the run in flight and lands on idle, remembering how far a preview in the air
1165
+ * had flown, which {@link play} flies on from.
1166
+ *
1167
+ * A preview stopped in its warm-up had flown nothing, so the flight paused before it stays
1168
+ * paused. It takes no camera: a {@link seek} in its warm-up goes on to park, and a flight warm
1169
+ * it waits on goes on sweeping. A sweep only stopped flights wait on ends at its next stop.
1170
+ * With nothing running it lands a `parked` status on idle. Idempotent.
1171
+ */
1172
+ pause(): void {
1173
+ // A `previewing` status with no run held is a flight a seek stopped, whose frame the seek
1174
+ // parks on in its place, and one under a run still in its warm-up is the flight that run
1175
+ // replaced.
1176
+ const status = this.flight.status;
1177
+ if (
1178
+ this.run?.kind === "preview" &&
1179
+ this.run.flying &&
1180
+ status.kind === "previewing" &&
1181
+ Number.isFinite(status.fraction)
1182
+ ) {
1183
+ this.pausedAt = Math.min(1, Math.max(0, status.fraction));
1184
+ }
1185
+
1186
+ this.stopRun();
1187
+ }
1188
+
1189
+ /**
1190
+ * stop stops the run in flight, forgets a paused flight and lands on idle, and answers which
1191
+ * run it stopped: `"preview"` for a preview or a play in the air or in its warm-up,
1192
+ * `"record"` for a recording, and null when nothing was running.
1193
+ *
1194
+ * Like {@link pause} it takes no camera: a {@link seek} in its warm-up goes on to park. The run
1195
+ * a stop ends answers `aborted`. Idempotent, and safe with nothing running.
1196
+ */
1197
+ stop(): "preview" | "record" | null {
1198
+ const stopped = this.run?.kind ?? null;
1199
+ this.pausedAt = null;
1200
+ this.stopRun();
1201
+
1202
+ return stopped;
1203
+ }
1204
+
1205
+ /**
1206
+ * abort stops whatever is running, a seek in its warm-up included, forgets a paused flight and
1207
+ * lands on idle.
1208
+ *
1209
+ * Idempotent, and safe with nothing running, which is what lets a UI wire it to a close button
1210
+ * and an unmount without either of them checking first.
1211
+ *
1212
+ * A seek still in its warm-up holds no run, so the abort overtakes it the way a newer flight
1213
+ * does: it answers `aborted` when its warm settles and parks no camera. A flight warm in
1214
+ * progress ends its sweep at the next stop, whichever flight began it.
1215
+ */
1216
+ abort(): void {
1217
+ this.flightSequence += 1;
1218
+ this.endFlightWarm();
1219
+ this.pausedAt = null;
1220
+
1221
+ if (this.run) {
1222
+ this.run.controller.abort();
1223
+ this.run = null;
1224
+ }
1225
+
1226
+ if (this.flight.status.kind !== "idle") {
1227
+ this.commit({ status: { kind: "idle" } });
1228
+ }
1229
+ }
1230
+
1231
+ /**
1232
+ * dispose aborts the run, drops every listener and forgets the caches.
1233
+ *
1234
+ * Idempotent. It does NOT dispose the map: the engine was handed one and does not own it,
1235
+ * which is the same one-way dependency `VideoRunEngine` keeps. For the same reason it starts
1236
+ * nothing on the map after it: a warm in progress holds a signal this aborts, which ends its
1237
+ * sweep at the next stop, and a preview, record or seek still in its warm-up, or asked for
1238
+ * later, answers `aborted` without warming again, flying, capturing or parking the camera.
1239
+ *
1240
+ * A disposed engine keeps the snapshot it showed. Nothing is announced after a dispose, so a
1241
+ * reader that still holds the engine reads the status it last saw, a flight in progress
1242
+ * included, and no later command changes it.
1243
+ */
1244
+ dispose(): void {
1245
+ if (this.disposed) {
1246
+ return;
1247
+ }
1248
+ this.disposal.abort();
1249
+
1250
+ this.abort();
1251
+ this.listeners.clear();
1252
+ this.poseCache.clear();
1253
+ this.lastRecording = null;
1254
+ }
1255
+
1256
+ // -----------------------------------------------------------------------------------------
1257
+ // Internals
1258
+ // -----------------------------------------------------------------------------------------
1259
+
1260
+ /**
1261
+ * commit replaces the snapshot and announces it. A no-op after dispose.
1262
+ *
1263
+ * It never throws. Every listener is told through {@link notifyListeners}, one that throws
1264
+ * included, and the first thing a listener threw is surfaced once they all have been, so no
1265
+ * command has to decide what a listener's exception does to a flight. The snapshot is replaced
1266
+ * before anyone is told, so what a later reader holds is the change, whatever a listener did
1267
+ * with it.
1268
+ */
1269
+ private commit(patch: Partial<VideoFlight>): void {
1270
+ if (this.disposed) {
1271
+ return;
1272
+ }
1273
+
1274
+ this.flight = { ...this.flight, ...patch };
1275
+ if (patch.status !== undefined) {
1276
+ // A status stated since a seek stopped a flight replaces the one that flight left.
1277
+ this.seekStoppedFlight = false;
1278
+ }
1279
+
1280
+ notifyListeners(this.listeners);
1281
+ }
1282
+
1283
+ /**
1284
+ * beginRun opens the one run a flight holds, aborting the one before it, and advances the
1285
+ * {@link flightSequence} a seek in its warm-up reads.
1286
+ *
1287
+ * After {@link dispose} the run is born aborted and is not held, so every entry point answers
1288
+ * `aborted` before it touches the map: a disposed engine was handed its map and let go of it.
1289
+ */
1290
+ private beginRun(kind: FlightRun["kind"]): FlightRun {
1291
+ const controller = new AbortController();
1292
+ const run: FlightRun = { controller, flying: false, kind, signal: controller.signal };
1293
+ if (this.disposed) {
1294
+ controller.abort();
1295
+
1296
+ return run;
1297
+ }
1298
+
1299
+ this.flightSequence += 1;
1300
+ this.run?.controller.abort();
1301
+ this.run = run;
1302
+
1303
+ return run;
1304
+ }
1305
+
1306
+ /**
1307
+ * stopRun is {@link pause} and {@link stop} past what each remembers: it stops the run in
1308
+ * flight, ends a flight warm only stopped flights wait on, and lands on idle. It advances no
1309
+ * {@link flightSequence}, so a seek in its warm-up goes on to park.
1310
+ */
1311
+ private stopRun(): void {
1312
+ if (this.run) {
1313
+ this.run.controller.abort();
1314
+ this.run = null;
1315
+ }
1316
+
1317
+ const warm = this.flightWarm;
1318
+ if (warm && [...warm.waiters].every((stopped) => stopped())) {
1319
+ this.endFlightWarm();
1320
+ }
1321
+
1322
+ if (this.flight.status.kind !== "idle") {
1323
+ this.commit({ status: { kind: "idle" } });
1324
+ }
1325
+ }
1326
+
1327
+ /**
1328
+ * endRun lands on idle unless a newer run has already replaced this one, and answers the
1329
+ * outcome the run settled on, as {@link land} reads it.
1330
+ */
1331
+ private endRun<Outcome extends VideoFlightOutcome | VideoFlightRecording>(
1332
+ run: FlightRun,
1333
+ outcome: Outcome,
1334
+ ): Outcome {
1335
+ if (this.run !== run) {
1336
+ return outcome;
1337
+ }
1338
+
1339
+ this.run = null;
1340
+
1341
+ return this.land(outcome);
1342
+ }
1343
+
1344
+ /** land commits idle and answers the outcome the flight settled on. */
1345
+ private land<Outcome extends VideoFlightOutcome | VideoFlightRecording>(
1346
+ outcome: Outcome,
1347
+ ): Outcome {
1348
+ this.commit({ status: { kind: "idle" } });
1349
+
1350
+ return outcome;
1351
+ }
1352
+
1353
+ /**
1354
+ * routeChanged names a route whose content differs from the one last read: it keeps the new
1355
+ * content, advances the revision the warms and the pose cache are keyed on, ends a flight warm
1356
+ * still sweeping the content before it, and forgets a flight paused over it.
1357
+ */
1358
+ private routeChanged(route: RouteGeometry | null): void {
1359
+ this.routeContent = route === null ? null : routeContentOf(route);
1360
+ this.routeRevision += 1;
1361
+ this.endFlightWarm();
1362
+ this.poseCache.clear();
1363
+ this.pausedAt = null;
1364
+ }
1365
+
1366
+ /**
1367
+ * readRoute reads the held route against the content it held when it was last read, as a
1368
+ * flight begins: the route is the caller's own object, and one edited in place since is
1369
+ * another route. One walk that ends at the first difference, small beside a resolve.
1370
+ */
1371
+ private readRoute(): void {
1372
+ const route = this.flight.route;
1373
+ if (
1374
+ route !== null &&
1375
+ this.routeContent !== null &&
1376
+ !holdsRouteContent(route, this.routeContent)
1377
+ ) {
1378
+ this.routeChanged(route);
1379
+ }
1380
+ }
1381
+
1382
+ /**
1383
+ * endFlightWarm ends the flight warm in progress at its next stop, and lets go of it so a flight
1384
+ * asked for afterwards sweeps for itself and does not wait on a sweep that is ending.
1385
+ */
1386
+ private endFlightWarm(): void {
1387
+ this.flightWarm?.controller.abort();
1388
+ this.flightWarm = null;
1389
+ }
1390
+
1391
+ /**
1392
+ * fly awaits a map call that holds the camera, keeping its settling among the
1393
+ * {@link landings} until it has settled, a stop of its run in between or not.
1394
+ */
1395
+ private async fly<T>(flight: Promise<T>): Promise<T> {
1396
+ const landing = flight.then(
1397
+ () => undefined,
1398
+ () => undefined,
1399
+ );
1400
+ this.landings.add(landing);
1401
+
1402
+ try {
1403
+ return await flight;
1404
+ } finally {
1405
+ this.landings.delete(landing);
1406
+ }
1407
+ }
1408
+
1409
+ /**
1410
+ * flyableRoute is the route a flight can follow, or null: no route, or a line of fewer than
1411
+ * {@link ROUTE_VERTICES_MIN} vertices, which has no direction to fly in and whose bounds frame
1412
+ * nothing.
1413
+ */
1414
+ private flyableRoute(): RouteGeometry | null {
1415
+ const route = this.flight.route;
1416
+
1417
+ return route && route.line.length >= ROUTE_VERTICES_MIN ? route : null;
1418
+ }
1419
+
1420
+ /**
1421
+ * prewarmRoute settles the DEM over the route's bounds, once per route.
1422
+ *
1423
+ * Before any resolve, because the clearance pass samples terrain through the live map: without
1424
+ * this it reads null and the flight plans a camera straight through a ridge. Once per route
1425
+ * because it is a visible camera move that can take seconds on a cold cache, and repeating it on
1426
+ * every play would make each transport action drag.
1427
+ *
1428
+ * A flight asked for while the warm is in progress awaits the one in progress. A warm that
1429
+ * rejects is not recorded as done, and rejects for every flight that waited on it.
1430
+ */
1431
+ private prewarmRoute(): Promise<void> {
1432
+ const map = this.map;
1433
+ const route = this.flyableRoute();
1434
+ const revision = this.routeRevision;
1435
+ if (!map || !route || this.terrainWarmedRevision === revision) {
1436
+ return Promise.resolve();
1437
+ }
1438
+
1439
+ if (this.terrainWarm?.revision === revision) {
1440
+ return this.terrainWarm.settled;
1441
+ }
1442
+
1443
+ const bounds = routeBounds(route);
1444
+ if (!bounds) {
1445
+ return Promise.resolve();
1446
+ }
1447
+
1448
+ // Held before the warm begins, so a map that throws as it is called still clears it.
1449
+ const warm: TerrainWarm = { revision, settled: Promise.resolve() };
1450
+ this.terrainWarm = warm;
1451
+ warm.settled = (async () => {
1452
+ try {
1453
+ await map.prewarmTerrain(bounds);
1454
+ // A warm that outlived its route says nothing about the one set since.
1455
+ if (this.routeRevision === revision) {
1456
+ this.terrainWarmedRevision = revision;
1457
+ }
1458
+ } finally {
1459
+ if (this.terrainWarm === warm) {
1460
+ this.terrainWarm = null;
1461
+ }
1462
+ }
1463
+ })();
1464
+
1465
+ return warm.settled;
1466
+ }
1467
+
1468
+ /**
1469
+ * warmRoute warms the route the engine holds as a preview or a seek takes it: the DEM over its
1470
+ * bounds ({@link prewarmRoute}), then its flight's viewports ({@link warmFlight}), each once per
1471
+ * route.
1472
+ *
1473
+ * The route is read again after each warm. One set while a warm ran is the route the flight is
1474
+ * of, so it is warmed in turn, the DEM before the sweep, and no pose is resolved over terrain a
1475
+ * warm of another route settled. It settles once the route it last warmed is the one held, or
1476
+ * as soon as `stopped` answers true after a warm.
1477
+ *
1478
+ * @param stopped Whether the flight has let go of the camera: its run was stopped, or a newer
1479
+ * flight overtook it. The flight warm reads it to tell a sweep somebody still waits on from
1480
+ * one nobody does.
1481
+ */
1482
+ private async warmRoute(stopped: () => boolean): Promise<void> {
1483
+ for (;;) {
1484
+ this.readRoute();
1485
+ const revision = this.routeRevision;
1486
+
1487
+ await this.prewarmRoute();
1488
+ this.readRoute();
1489
+ if (stopped()) {
1490
+ return;
1491
+ }
1492
+
1493
+ if (revision !== this.routeRevision) {
1494
+ continue;
1495
+ }
1496
+
1497
+ await this.warmFlight(stopped);
1498
+ this.readRoute();
1499
+ if (stopped() || revision === this.routeRevision) {
1500
+ return;
1501
+ }
1502
+ }
1503
+ }
1504
+
1505
+ /**
1506
+ * warmFlight jumps the camera through the flight's own viewports, once per route.
1507
+ *
1508
+ * The sampler-free resolve is used for the warm pass (its centers and bearings match the final
1509
+ * poses, so warming against it loads exactly the tiles the flight crosses), and the DEM epoch is
1510
+ * bumped afterwards, which drops any resolve cached against the colder terrain.
1511
+ *
1512
+ * A flight asked for while the sweep is in progress awaits the one in progress, a record's own
1513
+ * sweep included ({@link sweepForRecord}): two sweeps over one route would fight for the
1514
+ * camera. The sweep takes a signal of its own, which {@link endFlightWarm} aborts. A warm cut
1515
+ * short covered part of the flight, so it is not recorded as done and the next flight warms
1516
+ * again.
1517
+ *
1518
+ * @param stopped Whether the waiting flight has let go of the camera, held among the sweep's
1519
+ * waiters while it waits.
1520
+ */
1521
+ private async warmFlight(stopped: () => boolean): Promise<void> {
1522
+ const map = this.map;
1523
+ const route = this.flyableRoute();
1524
+ const revision = this.routeRevision;
1525
+ if (!map || !route || this.flightWarmedRevision === revision) {
1526
+ return;
1527
+ }
1528
+
1529
+ // A record's sweep over this route is the one in progress, unless its run was stopped: a
1530
+ // sweep that is ending covers part of the flight, and is not waited on. It ends on the
1531
+ // record's run alone.
1532
+ const recording = this.recordWarm;
1533
+ if (this.flightWarm?.revision !== revision && recording?.revision === revision) {
1534
+ if (!recording.signal.aborted) {
1535
+ await recording.settled;
1536
+
1537
+ return;
1538
+ }
1539
+ }
1540
+
1541
+ let warm = this.flightWarm;
1542
+ if (warm?.revision !== revision) {
1543
+ const controller = new AbortController();
1544
+ // Held before the sweep begins, so a planner or a map that throws as it is called clears it.
1545
+ const begun: FlightWarm = {
1546
+ controller,
1547
+ revision,
1548
+ settled: Promise.resolve(),
1549
+ waiters: new Set(),
1550
+ };
1551
+ this.flightWarm = begun;
1552
+ begun.settled = (async () => {
1553
+ try {
1554
+ await map.warmPoses(
1555
+ this.planner.resolveTrack(this.flight.plan, route),
1556
+ controller.signal,
1557
+ );
1558
+ if (!controller.signal.aborted) {
1559
+ this.flightWarmedRevision = revision;
1560
+ this.demEpoch += 1;
1561
+ }
1562
+ } finally {
1563
+ if (this.flightWarm === begun) {
1564
+ this.flightWarm = null;
1565
+ }
1566
+ }
1567
+ })();
1568
+ warm = begun;
1569
+ }
1570
+
1571
+ warm.waiters.add(stopped);
1572
+ try {
1573
+ await warm.settled;
1574
+ } finally {
1575
+ warm.waiters.delete(stopped);
1576
+ }
1577
+ }
1578
+
1579
+ /**
1580
+ * sweepForRecord jumps the camera through the sampler-free viewports of the flight a record is
1581
+ * about to capture, under the record's own run.
1582
+ *
1583
+ * It settles the DEM at flight zoom before the full-density resolve samples clearance. The
1584
+ * recorder skips its own warm pass only where the clearance pass moved no frame
1585
+ * ({@link capturesSweptViewports}): a frame it widened or tilted frames ground this sweep never
1586
+ * did.
1587
+ *
1588
+ * A record sweeps whenever its poses are not cached, whatever was warmed before, so the capture
1589
+ * never films a tile that has been let go since. The sweep is the flight's own over that
1590
+ * route, so it is held where {@link warmFlight} finds it: a seek asked for meanwhile waits on
1591
+ * it and starts no second sweep. One that runs to its end counts as the route's flight warm,
1592
+ * with the DEM epoch moved as `warmFlight` moves it. One its run cut short counts for nothing.
1593
+ *
1594
+ * @param track The sampler-free track of the plan and the route the record began with.
1595
+ * @param revision The route's revision as the record began.
1596
+ * @param signal The record's run.
1597
+ */
1598
+ private sweepForRecord(
1599
+ track: readonly RecordingCamera[],
1600
+ revision: number,
1601
+ signal: AbortSignal,
1602
+ ): Promise<void> {
1603
+ const map = this.map;
1604
+ if (!map) {
1605
+ return Promise.resolve();
1606
+ }
1607
+
1608
+ // Held before the sweep begins, so a map that throws as it is called clears it.
1609
+ const warm: RecordWarm = { revision, settled: Promise.resolve(), signal };
1610
+ this.recordWarm = warm;
1611
+ warm.settled = (async () => {
1612
+ try {
1613
+ await map.warmPoses(track, signal);
1614
+ // A sweep that outlived its route says nothing about the one set since.
1615
+ if (!signal.aborted && this.routeRevision === revision) {
1616
+ this.flightWarmedRevision = revision;
1617
+ this.demEpoch += 1;
1618
+ }
1619
+ } finally {
1620
+ if (this.recordWarm === warm) {
1621
+ this.recordWarm = null;
1622
+ }
1623
+ }
1624
+ })();
1625
+
1626
+ return warm.settled;
1627
+ }
1628
+
1629
+ /**
1630
+ * resolve turns the plan into poses, markers and a duration, memoized.
1631
+ *
1632
+ * Returns null when there is no route a flight can follow, which is the one input a flight
1633
+ * cannot be invented without. The record pass warms the flight-zoom tiles first so the capture
1634
+ * never films an unloaded tile and the clearance sampler reads real peak heights; the preview
1635
+ * pass skips that internal warm because `preview` already ran it once per route.
1636
+ *
1637
+ * It also returns null when `signal` aborted before or during that warm, which its caller reads
1638
+ * off the signal: a warm never starts on a dead signal, because the sweep moves the camera and a
1639
+ * map a host supplies need not honour one; and the full-density resolve after it is the costliest
1640
+ * step a record takes before its first frame, so poses sampled against a half-warmed DEM do not
1641
+ * belong in the cache.
1642
+ *
1643
+ * The plan and the route are read once, as the resolve begins, and the flight it answers names
1644
+ * both. A plan or a route set while the record pass warms takes on the next flight: the one in
1645
+ * progress is resolved, stored and recorded for what it began with.
1646
+ */
1647
+ private async resolve(options: {
1648
+ /**
1649
+ * Told when the record pass swept the flight's viewports to their end and the poses it
1650
+ * resolved frame exactly the viewports swept.
1651
+ */
1652
+ onSwept?: (() => void) | undefined;
1653
+ pass: "preview" | "record";
1654
+ signal: AbortSignal;
1655
+ }): Promise<ResolvedFlight | null> {
1656
+ const route = this.flyableRoute();
1657
+ if (!route) {
1658
+ return null;
1659
+ }
1660
+
1661
+ const plan = this.flight.plan;
1662
+ const revision = this.routeRevision;
1663
+ // Read again once the warm has settled: a flight warm that lands meanwhile moves the epoch.
1664
+ const key = (): string =>
1665
+ [posePlanSignature(plan), revision, options.pass, this.demEpoch].join("|");
1666
+
1667
+ const cached = this.poseCache.get(key());
1668
+ if (cached) {
1669
+ // Refresh recency so the cap evicts the genuinely-oldest entry rather than this one.
1670
+ this.poseCache.delete(key());
1671
+ this.poseCache.set(key(), cached);
1672
+
1673
+ return cached;
1674
+ }
1675
+
1676
+ // The track the record pass swept, which the poses it resolves are compared against.
1677
+ let swept: readonly RecordingCamera[] | null = null;
1678
+ if (options.pass === "record") {
1679
+ if (options.signal.aborted) {
1680
+ return null;
1681
+ }
1682
+
1683
+ swept = this.planner.resolveTrack(plan, route);
1684
+ await this.sweepForRecord(swept, revision, options.signal);
1685
+ if (options.signal.aborted) {
1686
+ return null;
1687
+ }
1688
+ }
1689
+
1690
+ const resolved: ResolvedFlight = {
1691
+ markers: resolveRouteMarkers(plan, route),
1692
+ plan,
1693
+ planDurationMs: planDurationMs(plan),
1694
+ // A copy, once per resolve: the planner answers a readonly track, and the map's
1695
+ // `previewPoses` and `recordPoses` take the array a run hands them.
1696
+ poses: [
1697
+ ...this.planner.resolveTrack(
1698
+ plan,
1699
+ route,
1700
+ (lngLat) => this.map?.sampleTerrainElevation(lngLat) ?? null,
1701
+ options.pass === "record" ? 1 : clearanceStrideFor(plan, route),
1702
+ ),
1703
+ ],
1704
+ route,
1705
+ };
1706
+
1707
+ if (swept !== null && capturesSweptViewports(swept, resolved.poses)) {
1708
+ options.onSwept?.();
1709
+ }
1710
+
1711
+ // A route set during the warm cleared the cache for the route after it, and this flight is
1712
+ // over the one before.
1713
+ if (revision !== this.routeRevision) {
1714
+ return resolved;
1715
+ }
1716
+
1717
+ this.poseCache.set(key(), resolved);
1718
+ if (this.poseCache.size > this.poseCacheSize) {
1719
+ const oldest = this.poseCache.keys().next().value;
1720
+ if (oldest !== undefined) {
1721
+ this.poseCache.delete(oldest);
1722
+ }
1723
+ }
1724
+
1725
+ return resolved;
1726
+ }
1727
+
1728
+ /**
1729
+ * recordProfile builds the overlay's recording input for a resolved flight, or nothing.
1730
+ *
1731
+ * All three inputs or none: the overlay is composited only when a caller enabled it AND both the
1732
+ * route and the profile source are present. The samples are resolved through the same planner and
1733
+ * the same frame progression as the poses, over the plan and the route the poses were resolved
1734
+ * for, so the readout on frame N describes the place frame N is looking at: index alignment is
1735
+ * the whole correctness condition here.
1736
+ */
1737
+ private recordProfile(resolved: ResolvedFlight): RecordProfile | undefined {
1738
+ const { profile, profileSource } = this.flight;
1739
+ if (!profile.enabled || !profileSource) {
1740
+ return undefined;
1741
+ }
1742
+
1743
+ return {
1744
+ design: profile.design,
1745
+ format: {
1746
+ language: profile.language,
1747
+ length: profile.length,
1748
+ pace: profile.pace,
1749
+ slope: profile.slope,
1750
+ // The overlay states distance, elevation, grade and speed, and never a temperature,
1751
+ // so there is no scale here for a viewer to have chosen. Pinned rather than
1752
+ // carried on VideoFlightProfile, which would publish a setting with nothing to set.
1753
+ temperature: "celsius",
1754
+ },
1755
+ samples: this.planner.resolveSamples(resolved.plan, resolved.route, profileSource),
1756
+ };
1757
+ }
1758
+ }