@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,1383 @@
1
+ import MapLibreGlDirections, {
2
+ type Directions,
3
+ layersFactory,
4
+ type MapLibreGlDirectionsConfiguration,
5
+ } from "@maplibre/maplibre-gl-directions";
6
+ import type { Position } from "geojson";
7
+ import type { LayerSpecification, Map as MapLibreMap } from "maplibre-gl";
8
+
9
+ import type { MapEventEngine } from "../../compose/engines/events.js";
10
+ import { refuseSegmentPositions } from "../../draw/rules/seeds.js";
11
+ import {
12
+ attachCursorReassert,
13
+ attachEditHoverCursor,
14
+ type CursorEngine,
15
+ } from "../../editing/engines/cursor.js";
16
+ import type {
17
+ EmitSegmentDraft,
18
+ EmitSegmentViaPrompt,
19
+ SegmentEditEngine,
20
+ } from "../../editing/rules/engine.js";
21
+ import { readEditColor } from "../../editing/rules/positions.js";
22
+ import { MountayaElementsError } from "../../errors/rules/errors.js";
23
+ import { DIRECTIONS_VIA_MAX, DIRECTIONS_VIA_MIN } from "../../geo/rules/segmentGeometry.js";
24
+ import { inDevelopment } from "../../rules/inDevelopment.js";
25
+ import { notifyListeners } from "../../rules/listeners.js";
26
+ import type {
27
+ SegmentDraft,
28
+ SegmentEditOptions,
29
+ SegmentRoute,
30
+ SegmentRouteFn,
31
+ SegmentRouteResult,
32
+ } from "../rules/contract.js";
33
+ import { SEGMENT_ROUTE_REFUSED } from "../rules/contract.js";
34
+
35
+ /**
36
+ * RequestData is the shape the SDK's protected `fetch` receives: the method,
37
+ * the built URL (carrying the waypoint coordinates), and the form payload. The
38
+ * SDK does not export it from its entry, so it is redeclared here for the
39
+ * override's parameter; only `url` is read (the coordinates are parsed from it).
40
+ */
41
+ interface RequestData {
42
+ method: "get" | "post";
43
+ payload: URLSearchParams;
44
+ url: string;
45
+ }
46
+
47
+ /**
48
+ * DirectionsFetchOverride is the private `fetch` slot the engine overrides on
49
+ * the MapLibreGlDirections instance to route through the injected routeFn
50
+ * instead of an HTTP API-provider. Declared here so the assignment site uses a
51
+ * precise type rather than reaching through `unknown`; it mirrors the SDK's own
52
+ * `fetch({ method, url, payload }): Promise<Directions>` signature.
53
+ */
54
+ interface DirectionsFetchOverride {
55
+ fetch: (request: RequestData) => Promise<Directions>;
56
+ }
57
+
58
+ // The minimum waypoints a route can form (a single point cannot be routed) and
59
+ // the maximum the router accepts. They mirror the bus-boundary via window so the
60
+ // engine never asks the routeFn for an unroutable or oversized set.
61
+
62
+ // Horizontal coord-equality tolerance for the pinned-boundary guards. Matches the
63
+ // backend's segment-continuity check, which rounds to 1e-7, so a drag
64
+ // that nudges a pinned waypoint by less than ~1cm is treated as the same point
65
+ // and admitted; anything larger is restored. The check is per-axis (lng + lat)
66
+ // rather than great-circle, mirroring the backend contract directly.
67
+ const PINNED_BOUNDARY_TOLERANCE = 1e-7;
68
+
69
+ /**
70
+ * isPinnedWaypointIntact reports whether the waypoint at `index` still matches the
71
+ * pinned coordinate within the backend's horizontal tolerance. A missing waypoint
72
+ * (the vertex was deleted) reads as drifted; both axes are compared so a drag on
73
+ * either lng or lat is caught. Both boundary guards share it: the head guard passes
74
+ * index 0, the tail guard passes the last index.
75
+ */
76
+ const isPinnedWaypointIntact = (
77
+ waypoints: ReadonlyArray<readonly [number, number]>,
78
+ pinned: Position,
79
+ index: number,
80
+ ): boolean => {
81
+ const at = waypoints[index];
82
+ if (!at) {
83
+ return false;
84
+ }
85
+
86
+ const pinnedLng = pinned[0] ?? 0;
87
+ const pinnedLat = pinned[1] ?? 0;
88
+
89
+ return (
90
+ Math.abs(at[0] - pinnedLng) <= PINNED_BOUNDARY_TOLERANCE &&
91
+ Math.abs(at[1] - pinnedLat) <= PINNED_BOUNDARY_TOLERANCE
92
+ );
93
+ };
94
+
95
+ /**
96
+ * seedOnPins writes a seed's head and tail onto its pins, as the boundary guards write a via
97
+ * dragged off one: a head or a tail further from its pin than the backend's tolerance is
98
+ * replaced by the pin, and one within it is kept as it was given.
99
+ *
100
+ * A seed of fewer than two vias is kept as it was given: the pins it is opened with are placed
101
+ * as the user draws.
102
+ *
103
+ * @param seed The vias the edit is seeded with.
104
+ * @param pinnedStart The pinned start, or `undefined` for a free start.
105
+ * @param pinnedEnd The pinned end, or `undefined` for a free end.
106
+ * @returns A new list of the seed's vias, its head and tail on their pins.
107
+ */
108
+ const seedOnPins = (
109
+ seed: readonly Position[],
110
+ pinnedStart: Position | undefined,
111
+ pinnedEnd: Position | undefined,
112
+ ): Position[] => {
113
+ const vias = [...seed];
114
+ if (vias.length < DIRECTIONS_VIA_MIN) {
115
+ return vias;
116
+ }
117
+
118
+ const pairs = vias.map((via): readonly [number, number] => [via[0] ?? 0, via[1] ?? 0]);
119
+ if (pinnedStart && !isPinnedWaypointIntact(pairs, pinnedStart, 0)) {
120
+ vias[0] = pinnedStart;
121
+ }
122
+
123
+ if (pinnedEnd && !isPinnedWaypointIntact(pairs, pinnedEnd, vias.length - 1)) {
124
+ vias[vias.length - 1] = pinnedEnd;
125
+ }
126
+
127
+ return vias;
128
+ };
129
+
130
+ /**
131
+ * darkenColor darkens a hex color by a fraction, used for the casing layers
132
+ * drawn beneath the routed line + the waypoints so they read against any base
133
+ * map. The casing is a darkened shade of the segment color so the SDK's render
134
+ * matches the rest of the studio.
135
+ */
136
+ const darkenColor = (hex: string, fraction: number): string => {
137
+ const value = Number.parseInt(hex.replace("#", ""), 16);
138
+ const r = Math.max(0, (value >> 16) - Math.round(255 * fraction));
139
+ const g = Math.max(0, ((value >> 8) & 0x00ff) - Math.round(255 * fraction));
140
+ const b = Math.max(0, (value & 0x0000ff) - Math.round(255 * fraction));
141
+
142
+ return `#${((r << 16) | (g << 8) | b).toString(16).padStart(6, "0")}`;
143
+ };
144
+
145
+ /**
146
+ * removalGuarded answers the map handed to the directions SDK: the map itself, every member read
147
+ * from it and every method called on it, except that a layer or a source its style does not hold
148
+ * is not removed.
149
+ *
150
+ * The SDK's `destroy()` ends with a `removeLayer` per configured layer and a `removeSource`, all
151
+ * unguarded, and that is the only way to have it let go of its waypoints and its listeners on
152
+ * the map. MapLibre holds no style while the renderer's WebGL context is lost, and removes
153
+ * through the style it no longer holds: an edit ended then, a mount torn down among them, would
154
+ * throw from its teardown. After a base-map switch the style holds none of the SDK's layers and
155
+ * no source, and MapLibre reports each missing layer as an error event and throws for the
156
+ * source. Guarded, a removal of what the style does not hold is no removal, and the rest of the
157
+ * teardown runs as it does on a style that holds them. It is the guard TerraDraw's adapter
158
+ * removes its layers through.
159
+ */
160
+ const removalGuarded = (map: MapLibreMap): MapLibreMap => {
161
+ const removeLayer = (id: string): MapLibreMap =>
162
+ map.getLayer(id) === undefined ? map : map.removeLayer(id);
163
+ const removeSource = (id: string): MapLibreMap =>
164
+ map.getSource(id) === undefined ? map : map.removeSource(id);
165
+ // A method is bound to the map once, so a call made through the guard runs on the map itself
166
+ // and a pointer move allocates nothing.
167
+ const bound = new Map<PropertyKey, unknown>();
168
+
169
+ return new Proxy(map, {
170
+ get: (target, key) => {
171
+ if (key === "removeLayer") {
172
+ return removeLayer;
173
+ }
174
+
175
+ if (key === "removeSource") {
176
+ return removeSource;
177
+ }
178
+
179
+ const value: unknown = Reflect.get(target, key, target);
180
+ if (typeof value !== "function") {
181
+ return value;
182
+ }
183
+
184
+ let method = bound.get(key);
185
+ if (method === undefined) {
186
+ method = value.bind(target);
187
+ bound.set(key, method);
188
+ }
189
+
190
+ return method;
191
+ },
192
+ });
193
+ };
194
+
195
+ /**
196
+ * directionsLayers builds the SDK layer set colored with the segment color: the
197
+ * routed line + alt routes in the color, their casings + the point casings in a
198
+ * darkened shade, and the waypoint/snappoint/hoverpoint circles in the color.
199
+ * The SDK accepts any `LayerSpecification[]` for its `layers` option, so this
200
+ * recolors the factory defaults by id rather than restyling after construction.
201
+ */
202
+ const directionsLayers = (color: string): LayerSpecification[] => {
203
+ const casing = darkenColor(color, 0.2);
204
+
205
+ return layersFactory().map((layer) => {
206
+ const next = { ...layer };
207
+ if (layer.id.includes("routeline-casing") || layer.id.includes("alt-routeline-casing")) {
208
+ next.paint = { ...layer.paint, "line-color": casing };
209
+ } else if (layer.id.includes("routeline") || layer.id.includes("alt-routeline")) {
210
+ next.paint = { ...layer.paint, "line-color": color };
211
+ } else if (
212
+ layer.id.includes("waypoint-casing") ||
213
+ layer.id.includes("snappoint-casing") ||
214
+ layer.id.includes("hoverpoint-casing")
215
+ ) {
216
+ next.paint = { ...layer.paint, "circle-color": casing };
217
+ } else if (
218
+ layer.id.includes("waypoint") ||
219
+ layer.id.includes("snappoint") ||
220
+ layer.id.includes("hoverpoint")
221
+ ) {
222
+ next.paint = { ...layer.paint, "circle-color": color };
223
+ } else if (layer.id.includes("snapline")) {
224
+ next.paint = { ...layer.paint, "line-color": color };
225
+ }
226
+
227
+ // The spread widens a layer of one type into a record whose paint the checker cannot tie
228
+ // back to that type. Each branch above writes a paint property of the type its id names,
229
+ // so the copy is the layer it was copied from, recoloured.
230
+ return next as LayerSpecification;
231
+ });
232
+ };
233
+
234
+ // The paint property + color each SDK layer id is recolored with on a live
235
+ // setDraftStyle. The routed lines + circles take the segment color; the casings
236
+ // take the darkened shade. Mirrors the build above so a recolor matches the
237
+ // initial paint without rebuilding the instance.
238
+ const lineColorLayers = [
239
+ "maplibre-gl-directions-routeline",
240
+ "maplibre-gl-directions-alt-routeline",
241
+ "maplibre-gl-directions-snapline",
242
+ ];
243
+ const lineCasingLayers = [
244
+ "maplibre-gl-directions-routeline-casing",
245
+ "maplibre-gl-directions-alt-routeline-casing",
246
+ ];
247
+ const circleColorLayers = [
248
+ "maplibre-gl-directions-waypoint",
249
+ "maplibre-gl-directions-snappoint",
250
+ "maplibre-gl-directions-hoverpoint",
251
+ ];
252
+ const circleCasingLayers = [
253
+ "maplibre-gl-directions-waypoint-casing",
254
+ "maplibre-gl-directions-snappoint-casing",
255
+ "maplibre-gl-directions-hoverpoint-casing",
256
+ ];
257
+
258
+ /**
259
+ * snapWaypointsToRoute echoes each input via as a coordinate that exists on the
260
+ * routed line, so the SDK's `buildRoutelines` coord-match loop in geojson mode
261
+ * (which compares snappoint locations to route coords with strict 2D equality)
262
+ * finds an anchor for every via. The first via is pinned to the route's first
263
+ * coord, the last via to its last coord (so the start + end legs always match
264
+ * even when the router snapped them off the input), and intermediate vias are
265
+ * anchored to the nearest route vertex by squared 2D distance. The router
266
+ * already returned the routed line for these vias, so the nearest vertex is the
267
+ * point the route "passes through" for that via, exactly what the SDK wants to
268
+ * cut a leg on.
269
+ */
270
+ const snapWaypointsToRoute = (vias: Position[], route: [number, number][]): [number, number][] => {
271
+ if (route.length === 0) {
272
+ return vias.map((via) => [via[0] ?? 0, via[1] ?? 0]);
273
+ }
274
+
275
+ const first = route[0] ?? [0, 0];
276
+ const last = route[route.length - 1] ?? first;
277
+
278
+ return vias.map((via, index) => {
279
+ if (index === 0) {
280
+ return first;
281
+ }
282
+
283
+ if (index === vias.length - 1) {
284
+ return last;
285
+ }
286
+
287
+ const lng = via[0] ?? 0;
288
+ const lat = via[1] ?? 0;
289
+ let nearest = first;
290
+ let nearestDistance = Number.POSITIVE_INFINITY;
291
+ for (const coord of route) {
292
+ const dx = (coord[0] ?? 0) - lng;
293
+ const dy = (coord[1] ?? 0) - lat;
294
+ const distance = dx * dx + dy * dy;
295
+ if (distance < nearestDistance) {
296
+ nearestDistance = distance;
297
+ nearest = coord;
298
+ }
299
+ }
300
+
301
+ return nearest;
302
+ });
303
+ };
304
+
305
+ /**
306
+ * RouteInFlight is one call of the injected router that has not settled: its promise, and the
307
+ * controller whose signal the router was handed.
308
+ */
309
+ interface RouteInFlight {
310
+ readonly call: Promise<SegmentRouteResult>;
311
+ readonly controller: AbortController;
312
+ }
313
+
314
+ /**
315
+ * parseWaypoints reads the waypoint coordinates out of the SDK-built request
316
+ * URL. The SDK builds `.../profile/lng1,lat1;lng2,lat2?query`, so the engine's
317
+ * fetch override slices the coordinate segment and parses the pairs to feed the
318
+ * routeFn. A malformed coordinate yields NaN, which the routeFn (and the router
319
+ * behind it) rejects.
320
+ */
321
+ const parseWaypoints = (url: string): Position[] => {
322
+ const coords = url.split("/").pop()?.split("?")[0] ?? "";
323
+ if (coords.length === 0) {
324
+ return [];
325
+ }
326
+
327
+ return coords.split(";").map((pair) => {
328
+ const [lng, lat] = pair.split(",").map(Number);
329
+
330
+ return [lng ?? 0, lat ?? 0];
331
+ });
332
+ };
333
+
334
+ /**
335
+ * routeFnFrom reads the router a directions edit is begun with, refusing an edit that has none.
336
+ *
337
+ * `SegmentEditOptions` leaves `routeFn` optional because a freehand edit takes none. A
338
+ * directions edit with none would arm, take every click and never draw a line, with nothing to
339
+ * say why.
340
+ *
341
+ * @throws {MountayaElementsError} When `routeFn` is not a function. The message names the
342
+ * member and the two ways out.
343
+ */
344
+ const routeFnFrom = (options: SegmentEditOptions): SegmentRouteFn => {
345
+ const { routeFn } = options;
346
+ if (typeof routeFn !== "function") {
347
+ throw new MountayaElementsError(
348
+ `DirectionsSegmentEngine: routeFn is ${String(routeFn)}. A directions edit draws the ` +
349
+ "line its router answers: pass the function that routes the vias as routeFn, or " +
350
+ "begin the edit in linestring mode.",
351
+ );
352
+ }
353
+
354
+ return routeFn;
355
+ };
356
+
357
+ /**
358
+ * activitySlugFrom reads the activity a directions edit routes for, refusing an edit that
359
+ * names none.
360
+ *
361
+ * @throws {MountayaElementsError} When `activitySlug` is not a string, or is empty: the router
362
+ * is asked for a route for an activity, and an empty slug names none. The message names the
363
+ * member.
364
+ */
365
+ const activitySlugFrom = (options: SegmentEditOptions): string => {
366
+ const { activitySlug } = options;
367
+ if (typeof activitySlug !== "string" || activitySlug === "") {
368
+ const shown = typeof activitySlug === "string" ? '""' : String(activitySlug);
369
+
370
+ throw new MountayaElementsError(
371
+ `DirectionsSegmentEngine: activitySlug is ${shown}. A directions edit routes for one ` +
372
+ "activity: pass the slug of the itinerary's activity as activitySlug, or begin the " +
373
+ "edit in linestring mode.",
374
+ );
375
+ }
376
+
377
+ return activitySlug;
378
+ };
379
+
380
+ /**
381
+ * refuseUnroutableEdit refuses a directions edit that states no router or no activity, or opens
382
+ * on positions no map can place ({@link refuseSegmentPositions}), as
383
+ * {@link DirectionsSegmentEngine} does when it is built, and builds nothing.
384
+ *
385
+ * A seed whose head or tail is not on its pin is no refusal: the engine opens on the pin in its
386
+ * place, as it does for a via dragged off one.
387
+ *
388
+ * A map client reads it before it ends the edit a begin replaces, so a begin the engine would
389
+ * refuse leaves the edit that stood open.
390
+ *
391
+ * @throws {MountayaElementsError} When `routeFn` is not a function, or `activitySlug` is not a
392
+ * string or is empty, and when a pin or a seed via is refused. The message names the member.
393
+ */
394
+ export const refuseUnroutableEdit = (options: SegmentEditOptions): void => {
395
+ routeFnFrom(options);
396
+ activitySlugFrom(options);
397
+ refuseSegmentPositions(options, "DirectionsSegmentEngine");
398
+ };
399
+
400
+ /**
401
+ * DirectionsSegmentEngine is the routed-vias segment-edit engine the MapLibreClient builds for a
402
+ * `directions` edit. It wraps `@maplibre/maplibre-gl-directions` (which lives in this quarantined
403
+ * package alongside maplibre-gl): the SDK draws the draggable waypoints AND the routed line between
404
+ * them and handles drag-to-reroute + click-route-to-insert natively, so this engine owns the
405
+ * directions rendering + manipulation internally and the editor needs no separate routed-line
406
+ * layer.
407
+ *
408
+ * Routing is INJECTED: the SDK's HTTP request is overridden with the routeFn the host hands
409
+ * `beginSegmentEdit`, so the engine computes a route without naming what routes, and this package
410
+ * calls no `fetch`. A request identical to one still in flight shares its routing call, and the
411
+ * router is handed a signal that aborts as the engine drops the request it answers: a request for
412
+ * other waypoints replaced it, or the edit ended. Every waypoint add/move/insert/remove flows out
413
+ * through the draft sink as the via array; a commit persists the vias (the backend re-routes
414
+ * authoritatively), not the SDK's display route. The latest routed result rides back on
415
+ * `SegmentDraft.route`, the engine's private routing extension over the shared base contract, so
416
+ * the client never grows a routing member the freehand engine lacks. It implements the same
417
+ * SegmentEditEngine contract as the TerraDraw engine, so the client's engine-agnostic concerns sit
418
+ * above it identically.
419
+ */
420
+ export class DirectionsSegmentEngine implements SegmentEditEngine {
421
+ private directions: MapLibreGlDirections | null = null;
422
+ private color: `#${string}`;
423
+ private readonly routeFn: SegmentRouteFn;
424
+ private readonly activitySlug: string;
425
+ // The vias the SDK currently holds, mirrored here so a base-map-switch replay
426
+ // can re-seed the rebuilt instance from the last known state.
427
+ private vias: Position[];
428
+ // The pinned first-vertex coordinate. When set, the head of the SDK's
429
+ // waypoints is locked to this position: any interactive change (move-vertex-0
430
+ // or remove-vertex-0) that drifts it past `PINNED_BOUNDARY_TOLERANCE` triggers
431
+ // a programmatic revert. The constraint expresses the backend's segment
432
+ // continuity (segment N's start = segment N-1's end) inside the editor so a
433
+ // drag never breaks the chain.
434
+ private readonly pinnedStart: Position | undefined;
435
+ // The pinned last-vertex coordinate, the mirror of pinnedStart: segment N's end
436
+ // locked to segment N+1's start. Set only for an insert, which is the one edit
437
+ // with a successor to meet. It also changes where a click lands: an added
438
+ // waypoint is moved in FRONT of the pin so the drawn line always finishes on its
439
+ // neighbour rather than running past it.
440
+ private readonly pinnedEnd: Position | undefined;
441
+ // Reports an interactive add declined by the via cap, so the app can say so. The
442
+ // decline is otherwise invisible: the SDK's waypoint is reverted and no draft is
443
+ // emitted, leaving the click indistinguishable from a miss.
444
+ private readonly onViaCapRefused: (() => void) | undefined;
445
+ // Guard against re-entering the setwaypoints listener during a pinned-start
446
+ // revert: the programmatic setWaypoints call fires its own setwaypoints
447
+ // event, which would otherwise re-run the same check on the just-restored
448
+ // state. The flag is raised before the revert call and cleared after the
449
+ // event drains.
450
+ private reverting = false;
451
+ // Detaches the routed-line "+"-insert cursor affordance (our listeners through
452
+ // the shared event engine), set when the engine attaches and cleared on dispose.
453
+ private detachRouteCursor: (() => void) | null = null;
454
+ // Detaches the map-level mousemove re-assert (our listener through the shared
455
+ // event engine), set when the engine attaches and cleared on dispose. It
456
+ // counters the SDK's own global move handler, which writes the canvas cursor
457
+ // directly and re-enables drag-pan when the pointer is off every sensitive
458
+ // layer: i.e. over empty map, the from-scratch "add the next point" state.
459
+ private detachCursorReassert: (() => void) | null = null;
460
+ // The most recent SegmentRoute the injected routeFn returned for the current
461
+ // vias, kept on the engine so the next SegmentDraft emit can carry it to the
462
+ // live elevation panel. The SDK consumes a 2D-projected sibling; this field
463
+ // holds the full 3D geometry + elevation + analysis the live preview reads.
464
+ private lastRoute: SegmentRoute | null = null;
465
+ // The last via set whose route the routeFn ACCEPTED, kept as the restore point
466
+ // for a refused route. It trails `vias`: the SDK's waypoint events update
467
+ // `vias` the moment a click lands, while the accept/refuse verdict only
468
+ // arrives when the router resolves, so the two differ exactly across an
469
+ // in-flight placement, which is the window a refusal has to undo.
470
+ private acceptedVias: Position[];
471
+ // Monotonic guard for out-of-order routeFn resolutions. Each computeRoute call
472
+ // captures the token it bumps before awaiting the router; on resolution it
473
+ // updates lastRoute and emits the fresh-route draft ONLY when its token is
474
+ // still current, so a superseded via-set's late resolution cannot clobber a
475
+ // newer route or push a stale live profile. Mirrors the freehand engine's
476
+ // analyzeToken, the same race guard both engines need over an async resolver.
477
+ // dispose() bumps it too, so a resolution landing after the edit ended emits nothing.
478
+ private routeToken = 0;
479
+ // The routing calls still in flight, by the request the SDK built (its URL encodes the
480
+ // waypoints). A request identical to one in flight shares that call rather than asking the
481
+ // router twice, and still resolves under its own token, with its own emit. Only a call in
482
+ // flight is shared, and only within this engine: a settled answer read back later would skip
483
+ // the route a restore needs emitted again, and an answer another engine asked for is that
484
+ // engine's to emit.
485
+ //
486
+ // Each call holds the controller whose signal its router was handed. A call the engine drops
487
+ // (a request for other waypoints replaced the one it answered, or the edit ended) is aborted
488
+ // and taken out of the map in the same step, so a later request for its waypoints shares
489
+ // nothing with a call whose router was told to stop.
490
+ private readonly routesInFlight = new Map<string, RouteInFlight>();
491
+
492
+ // Whether the app currently holds a via prompt open. While true the SDK's own
493
+ // interactivity is off, so no click adds, moves, or removes a waypoint until
494
+ // the prompt resolves.
495
+ private viaPromptPending = false;
496
+
497
+ // Whether this edit has said in the console that its router threw.
498
+ private routeFaultReported = false;
499
+
500
+ // Whether the edit is over. The plugin is gone both after a dispose and between the detach
501
+ // before a style reload and the replay after it, and only the second has a replay to come:
502
+ // there the engine reads and writes the vias it holds, and here it holds none.
503
+ private disposed = false;
504
+
505
+ /**
506
+ * Builds the directions plugin over the map and opens the edit on its seed. A seed whose head
507
+ * or tail is further from its pin than the backend's tolerance opens with the pin in its place.
508
+ *
509
+ * @param map The map the edit is drawn on.
510
+ * @param events The event engine the cursor listeners are registered through.
511
+ * @param cursor The cursor engine the edit's cursors are locked on.
512
+ * @param options The edit: its colour, its seed and pins, its router and its activity.
513
+ * @param emitDraft The sink every change of the vias, and every route, is pushed at.
514
+ * @param emitViaPrompt The sink a click on an existing via is handed to.
515
+ *
516
+ * @throws {MountayaElementsError} When `options.routeFn` is not a function, when
517
+ * `options.activitySlug` is missing or empty, when `options.pinnedStart`, `options.pinnedEnd`
518
+ * or a seed via is not a longitude and a latitude a map can place (two finite numbers, the
519
+ * latitude from -90 to 90), and when `options.color` is neither `#rrggbb` nor `#rgb`. Each is
520
+ * refused before the directions plugin is built, so a refused edit leaves no layer, source or
521
+ * listener on the map.
522
+ */
523
+ constructor(
524
+ private readonly map: MapLibreMap,
525
+ private readonly events: MapEventEngine,
526
+ private readonly cursor: CursorEngine,
527
+ options: SegmentEditOptions,
528
+ private readonly emitDraft: EmitSegmentDraft,
529
+ private readonly emitViaPrompt: EmitSegmentViaPrompt,
530
+ ) {
531
+ // Read first: each one throws for an edit that could route nothing, and nothing has been
532
+ // attached to the map yet.
533
+ this.routeFn = routeFnFrom(options);
534
+ this.activitySlug = activitySlugFrom(options);
535
+ const { endPin: pinnedEnd, startPin: pinnedStart } = refuseSegmentPositions(
536
+ options,
537
+ "DirectionsSegmentEngine",
538
+ );
539
+ this.color = readEditColor(options.color, "DirectionsSegmentEngine");
540
+ this.vias = seedOnPins(options.seedVias ?? [], pinnedStart, pinnedEnd);
541
+ // The seed is accepted by construction: it is the segment's saved shape, not
542
+ // a placement the user is making now, so it is the restore point a refusal
543
+ // falls back to from the very first click.
544
+ this.acceptedVias = [...this.vias];
545
+ // The pinned head locks segment N's first via to segment N-1's last via so
546
+ // the backend's continuity contract holds through the edit; null when the
547
+ // edit is the first segment in the itinerary (no predecessor to anchor to).
548
+ this.pinnedStart = pinnedStart;
549
+ // The pinned tail locks segment N's last via to segment N+1's first via for an
550
+ // insert; undefined for an append or a reshape, whose end is the user's to drag.
551
+ this.pinnedEnd = pinnedEnd;
552
+ this.onViaCapRefused = options.onViaCapRefused;
553
+
554
+ const directions = this.attach();
555
+
556
+ // Seed an existing segment's saved vias so the route + draggable markers render
557
+ // immediately. setWaypoints fires the setwaypoints event, which the engine
558
+ // emits as a PROGRAMMATIC draft, so the seed is not recorded as a fresh history
559
+ // entry: it restores saved state rather than being a user edit. A new segment
560
+ // seeds nothing; its first via comes from the SDK's click-to-add.
561
+ if (this.vias.length > 0) {
562
+ void directions.setWaypoints(this.toLngLatPairs(this.vias));
563
+ }
564
+ }
565
+
566
+ setDraftStyle(style: { color: string }): void {
567
+ this.color = readEditColor(style.color, "DirectionsSegmentEngine");
568
+ const map = this.map;
569
+ const casing = darkenColor(this.color, 0.2);
570
+
571
+ for (const id of lineColorLayers) {
572
+ if (map.getLayer(id)) {
573
+ map.setPaintProperty(id, "line-color", this.color);
574
+ }
575
+ }
576
+
577
+ for (const id of lineCasingLayers) {
578
+ if (map.getLayer(id)) {
579
+ map.setPaintProperty(id, "line-color", casing);
580
+ }
581
+ }
582
+
583
+ for (const id of circleColorLayers) {
584
+ if (map.getLayer(id)) {
585
+ map.setPaintProperty(id, "circle-color", this.color);
586
+ }
587
+ }
588
+
589
+ for (const id of circleCasingLayers) {
590
+ if (map.getLayer(id)) {
591
+ map.setPaintProperty(id, "circle-color", casing);
592
+ }
593
+ }
594
+ }
595
+
596
+ readDraft(): Position[] | null {
597
+ // The edit is over, and a disposed engine holds no draft.
598
+ if (this.disposed) {
599
+ return null;
600
+ }
601
+
602
+ // The plugin is destroyed between the detach and the replay, and the line still exists: it
603
+ // is the vias the engine holds for the replay, answered as a list of the caller's own.
604
+ return this.directions ? [...this.directions.waypoints] : this.vias.map((via) => [...via]);
605
+ }
606
+
607
+ setViaPromptPending(pending: boolean): void {
608
+ this.viaPromptPending = pending;
609
+
610
+ if (this.directions) {
611
+ // The SDK's whole click/drag grammar rides one flag, so suspending it stops
612
+ // the append that would otherwise ride the click dismissing the prompt.
613
+ this.directions.interactive = !pending;
614
+ }
615
+ }
616
+
617
+ applyDraft(coordinates: Position[]): void {
618
+ // The edit is over. A disposed engine writes and builds nothing, wherever it was disposed.
619
+ if (this.disposed) {
620
+ return;
621
+ }
622
+
623
+ // Between the detach and the replay there is no plugin to write into, so the draft is held,
624
+ // the latest one alone, as the vias the replay seeds the plugin it builds from. That seed
625
+ // reports it, programmatic, as the write below would have.
626
+ if (!this.directions) {
627
+ this.lastRoute = null;
628
+ this.vias = [...coordinates];
629
+
630
+ return;
631
+ }
632
+
633
+ // A programmatic re-seed (undo/redo restore): setWaypoints fires the setwaypoints
634
+ // event SYNCHRONOUSLY, which the engine emits as a PROGRAMMATIC draft, so a history
635
+ // subscriber skips it. Invalidate the cached route FIRST: it belongs to the PREVIOUS
636
+ // vias, so the synchronous echo must not carry it: a stale route would overwrite the
637
+ // restored elevation the store just set (the "profile stuck after cmd+z" bug). The echo
638
+ // rides route:null; the SDK's own re-route for the restored vias emits the fresh route
639
+ // when it resolves.
640
+ this.lastRoute = null;
641
+ this.vias = [...coordinates];
642
+ void this.directions.setWaypoints(this.toLngLatPairs(coordinates));
643
+ }
644
+
645
+ dispose(): void {
646
+ this.detachRouteCursor?.();
647
+ this.detachRouteCursor = null;
648
+ this.detachCursorReassert?.();
649
+ this.detachCursorReassert = null;
650
+ this.lastRoute = null;
651
+ // Supersedes every resolution still in flight: the edit it would emit into has ended.
652
+ this.routeToken += 1;
653
+ // Each router still routing is told so: nobody reads its answer.
654
+ this.dropRoutesInFlight();
655
+ // A dispose inside the detach window ends an edit whose replay never comes: a late replay
656
+ // builds nothing, a late draft is held by nothing, and a late read answers no line.
657
+ this.disposed = true;
658
+
659
+ // destroy removes every MapLibreGlDirections layer and source and detaches the SDK's own
660
+ // interaction listeners, which leaves the map clean. An edit that ends is no change to its
661
+ // geometry, so the clear inside it reaches no subscriber.
662
+ this.destroyDirections();
663
+ }
664
+
665
+ /**
666
+ * destroyDirections destroys the SDK instance, if one stands, and pushes nothing at the draft
667
+ * sink while it does.
668
+ *
669
+ * The SDK's `destroy()` calls `clear()`, which is `setWaypoints([])`, which fires
670
+ * `setwaypoints`. The engine's own listener reads that event as a programmatic change: it
671
+ * replaces `this.vias` with the SDK's empty list and emits a draft with no via and no route.
672
+ * `reverting` is the flag that listener already stands down for, so the destroy runs under it
673
+ * at every teardown: the end of an edit, and the detach before a style reload.
674
+ */
675
+ private destroyDirections(): void {
676
+ this.reverting = true;
677
+ try {
678
+ this.directions?.destroy();
679
+ } finally {
680
+ this.reverting = false;
681
+ }
682
+ this.directions = null;
683
+ }
684
+
685
+ /**
686
+ * detachBeforeStyleReload destroys the MapLibreGlDirections instance BEFORE the swap,
687
+ * so {@link replayAfterStyleReload} can build a fresh one on the style that arrives.
688
+ * See {@link EditEngine.detachBeforeStyleReload} for the shared half of the reason;
689
+ * two things are specific to this engine.
690
+ *
691
+ * **The order is not a preference.** `destroy()` ends with a `removeLayer` per
692
+ * configured layer and one `removeSource`, unguarded in the SDK. Run before the swap,
693
+ * every one of them is still on the style and is removed with the edit. Run after, the
694
+ * swap has already taken them off, and the map the SDK is handed through
695
+ * {@link removalGuarded} removes nothing that is gone: unguarded, MapLibre would fire an
696
+ * `ErrorEvent` per missing layer and throw on the missing source.
697
+ *
698
+ * **And the teardown wipes the vias it is about to be replayed from.** `destroy()`
699
+ * calls `clear()`, which is `setWaypoints([])`, which fires `setwaypoints`, which the
700
+ * engine's own listener turns into `emitFromSdk(true)`, and that replaces `this.vias`
701
+ * with the SDK's now-empty list and pushes an empty draft at the sink. `reverting` is
702
+ * the guard this engine already owns for exactly that re-entry, so the destroy sits
703
+ * inside it. Without this the replay below would re-seed nothing even once the
704
+ * instance rebuilt correctly.
705
+ */
706
+ detachBeforeStyleReload(): void {
707
+ // The edit is over. A disposed engine writes and builds nothing, wherever it was disposed.
708
+ if (this.disposed) {
709
+ return;
710
+ }
711
+
712
+ this.detachRouteCursor?.();
713
+ this.detachRouteCursor = null;
714
+ this.detachCursorReassert?.();
715
+ this.detachCursorReassert = null;
716
+ this.lastRoute = null;
717
+
718
+ this.destroyDirections();
719
+ }
720
+
721
+ /**
722
+ * replayAfterStyleReload re-renders the active edit's scene after a base-map
723
+ * switch wiped the style. setStyle removed the SDK's layers + sources, so a whole
724
+ * MapLibreGlDirections instance is built on the fresh style and re-seeded with the
725
+ * vias the engine held; attach() re-wires the fetch override + the SDK's interaction
726
+ * listeners + the cursor affordances.
727
+ *
728
+ * The instance it replaces was destroyed by {@link detachBeforeStyleReload}, before
729
+ * the swap rather than here: without that this rebuilds onto layers the swap has
730
+ * already taken away, and `this.vias` has been emptied by the teardown's own
731
+ * `setwaypoints`. Both cursor listeners were detached there and are re-created by
732
+ * attach(), so the pair is net-zero (no double-bind). Unlike the waypoint engines,
733
+ * which leave their map-level subscriptions alone because a map-level listener
734
+ * survives setStyle untouched, the map-level cursor re-assert is rebuilt
735
+ * deliberately: it was bound to the destroyed SDK instance, so it is re-registered
736
+ * AFTER the rebuilt SDK attaches its own move handler, preserving the dispatch order
737
+ * attach() relies on.
738
+ */
739
+ replayAfterStyleReload(): void {
740
+ // The edit is over. A disposed engine writes and builds nothing, wherever it was disposed.
741
+ if (this.disposed) {
742
+ return;
743
+ }
744
+
745
+ // Defensive rather than ordinary: the pair is driven by the host, which detaches
746
+ // before the swap and replays after it. An instance still standing here means the
747
+ // detach was skipped, and building a second one over it would leak the first's
748
+ // layers and listeners onto the map.
749
+ if (this.directions) {
750
+ this.detachBeforeStyleReload();
751
+ }
752
+
753
+ const directions = this.attach();
754
+
755
+ if (this.vias.length > 0) {
756
+ void directions.setWaypoints(this.toLngLatPairs(this.vias));
757
+ }
758
+ }
759
+
760
+ /**
761
+ * attach builds the MapLibreGlDirections instance with the segment-colored
762
+ * layers, overrides its request to route through the injected routeFn (sharing
763
+ * a call still in flight), wires the typed waypoint events to the draft sink,
764
+ * reconciles the SDK's internal cursor handling so our cross/"+" win on the
765
+ * routed line, and enables interactivity so a click adds a waypoint. It is the single
766
+ * construct-and-wire point, reused by the constructor and the style-reload
767
+ * replay. Returns the built instance so a caller can re-seed it without
768
+ * re-reading the field (the control-flow narrowing cannot see this method
769
+ * reassigns it).
770
+ */
771
+ private attach(): MapLibreGlDirections {
772
+ // The api/profile are placeholders: the fetch override below never makes
773
+ // an HTTP request, so the URL the SDK builds is parsed for its
774
+ // coordinates and discarded. requestOptions ask for GeoJSON geometry + a
775
+ // full overview so the built URL is well-formed. dragThreshold is set to
776
+ // 0 so a click on the routed line (which the SDK only treats as an
777
+ // insert when the mouseup screen position moved past the threshold from
778
+ // mousedown) registers on every realistic user gesture: a "click" via
779
+ // mouse hardware lands with a few pixels of natural jitter between
780
+ // mousedown and mouseup, so the default-10 threshold swallows
781
+ // them. At 0 any real motion counts, and the click-route-insert
782
+ // affordance the "+" cursor cues actually fires.
783
+ const configuration: Partial<MapLibreGlDirectionsConfiguration> = {
784
+ api: "https://routing.invalid/route/v1",
785
+ dragThreshold: 0,
786
+ layers: directionsLayers(this.color),
787
+ profile: "route",
788
+ requestOptions: { geometries: "geojson", overview: "full" },
789
+ };
790
+ // Through the guard, so the SDK's own teardown removes nothing the style does not hold.
791
+ const directions = new MapLibreGlDirections(removalGuarded(this.map), configuration);
792
+ this.directions = directions;
793
+
794
+ // Override the SDK's request to route through the injected routeFn instead of
795
+ // an HTTP provider; an identical request still in flight shares its call.
796
+ // Through `unknown`: the plugin declares `fetch` protected, and a class with a protected
797
+ // member converts to no interface that declares it public.
798
+ (directions as unknown as DirectionsFetchOverride).fetch = (request) =>
799
+ this.routeViaInjection(request);
800
+
801
+ // The typed waypoint events are the draft seam, and the SDK's own event
802
+ // taxonomy carries the interactive/programmatic distinction directly: an add
803
+ // (click-to-add or click-route-insert), a move (drag-reroute), and a remove are
804
+ // INTERACTIVE user gestures, while setwaypoints fires only from the SDK's
805
+ // setWaypoints method: i.e. a programmatic re-seed (the constructor seed, an
806
+ // applyDraft restore). So each event emits the current vias with its inherent
807
+ // flag rather than a time-windowed suppression boolean, mirroring the TerraDraw
808
+ // engine's origin-tagged distinction.
809
+ directions.on("addwaypoint", () => {
810
+ // An interactive add (click-to-add or click-route-insert) can push the via
811
+ // count past the router's cap; refuse it before the draft emits rather than
812
+ // routing an over-cap set (which the routeFn floors to NoRoute, clearing the
813
+ // whole line). The revert restores the pre-insert vias and keeps the current
814
+ // routed line intact.
815
+ if (this.enforceViaCap()) {
816
+ return;
817
+ }
818
+
819
+ // With a pinned tail the SDK's append would leave the added via PAST the
820
+ // neighbour's start; move it back in front so the line still finishes there.
821
+ // The reorder emits its own draft, so this listener stops here.
822
+ if (this.enforcePinnedEnd(true)) {
823
+ return;
824
+ }
825
+
826
+ this.emitFromSdk(false);
827
+ });
828
+ // Clicking an existing via is ambiguous: the SDK's default is to delete it,
829
+ // but a user closing a loop clicked it to route through it a second time. The
830
+ // cancelable `before` hook is the only place that default can be stopped, so
831
+ // it is refused here and the ambiguity is handed to the app as a prompt
832
+ // anchored at the clicked via. Nothing about the draft changes yet; whichever
833
+ // resolution the user picks comes back through applyDraft.
834
+ directions.on("beforeremovewaypoint", (event) => {
835
+ event.preventDefault();
836
+
837
+ const via = this.vias[event.data.index];
838
+ if (!via) {
839
+ return;
840
+ }
841
+
842
+ notifyListeners([this.emitViaPrompt], {
843
+ index: event.data.index,
844
+ lngLat: [via[0] ?? 0, via[1] ?? 0],
845
+ });
846
+ });
847
+ directions.on("removewaypoint", () => {
848
+ // A remove reaches this listener only from a programmatic setWaypoints (the
849
+ // interactive path is refused above), but the pinned boundaries are restored
850
+ // here all the same so a subscriber never sees the broken-continuity state.
851
+ if (this.enforcePinnedStart() || this.enforcePinnedEnd()) {
852
+ return;
853
+ }
854
+
855
+ this.emitFromSdk(false);
856
+ });
857
+ directions.on("movewaypoint", () => {
858
+ // A drag on either pinned boundary drifts it off its neighbour; restore it
859
+ // before the draft emits so the chain stays intact.
860
+ if (this.enforcePinnedStart() || this.enforcePinnedEnd()) {
861
+ return;
862
+ }
863
+
864
+ this.emitFromSdk(false);
865
+ });
866
+ directions.on("setwaypoints", () => {
867
+ // A revert call fires its own setwaypoints event; skip the emit so the
868
+ // restored state does not enter history a second time. The flag is
869
+ // cleared at the end of the revert's synchronous tick.
870
+ if (this.reverting) {
871
+ return;
872
+ }
873
+
874
+ this.emitFromSdk(true);
875
+ });
876
+
877
+ // Enable interactivity so a click adds a waypoint and a drag reroutes (and,
878
+ // over empty map, the SDK leaves drag-pan enabled so a drag pans). Wire this
879
+ // BEFORE attachRouteCursor so MapLibre dispatches the SDK's mousemove listener
880
+ // before ours: our mousemove cursor re-pin then runs LAST and overwrites the
881
+ // SDK's own `canvas.style.cursor` write with our two-state affordance. A style
882
+ // reload that happens while a via prompt is open rebuilds through here, so the
883
+ // suspend is re-applied rather than silently lifted.
884
+ directions.interactive = !this.viaPromptPending;
885
+
886
+ // Reconcile the SDK's internal cursor: it writes the canvas cursor directly on
887
+ // its routeline hover, which would bypass our cursor lock. Pushing the
888
+ // "pointer" override on a routed-line mouseenter and popping it on mouseleave
889
+ // makes OUR insert affordance win while the SDK still drives the actual insert
890
+ // on click. The listeners go through the shared event engine so they detach
891
+ // by reference; they are scoped to the SDK's sensitive routeline layer.
892
+ this.detachRouteCursor = this.attachRouteCursor();
893
+
894
+ // Counter the SDK's GLOBAL move handler with the shared map-level re-assert:
895
+ // over empty map it clears `canvas.style.cursor` on every move (wiping the
896
+ // locked "+" cross, the "add the next point" append state) and on the
897
+ // routeline it overwrites it; `reassert` re-pins whichever tier is held, so
898
+ // one listener covers both. Registered LAST so MapLibre dispatches us after
899
+ // the SDK's own move handler the `interactive = true` setter just attached,
900
+ // and it leaves the SDK's drag-pan management alone so a drag over empty map
901
+ // pans.
902
+ this.detachCursorReassert = this.attachCursorReassert();
903
+
904
+ return directions;
905
+ }
906
+
907
+ /**
908
+ * routeViaInjection is the fetch override body: it parses the waypoints from the
909
+ * SDK-built URL, resolves them through the injected routeFn (sharing a call an
910
+ * identical request has in flight, see {@link routeOnce}), and shapes the result
911
+ * into the SDK's Directions response. Fewer than two waypoints or a null routeFn
912
+ * result yields a NoRoute response so the SDK clears the routed line rather than
913
+ * drawing a stale one.
914
+ */
915
+ private routeViaInjection(request: RequestData): Promise<Directions> {
916
+ return this.computeRoute(parseWaypoints(request.url), request.url);
917
+ }
918
+
919
+ /**
920
+ * routeOnce calls the injected routeFn for one request, or joins the call an identical
921
+ * request already has in flight, keyed by the request's URL. The call is forgotten as it
922
+ * settles, so the next request for the same waypoints routes again.
923
+ *
924
+ * The router is handed the signal of the call's own controller, which
925
+ * {@link dropRoutesInFlight} aborts. It is the engine's and not the plugin's: the plugin
926
+ * aborts its request at every write of its waypoints, a re-seed with the same ones included,
927
+ * and that request shares this call.
928
+ */
929
+ private routeOnce(key: string, waypoints: Position[]): RouteInFlight {
930
+ const inFlight = this.routesInFlight.get(key);
931
+ if (inFlight !== undefined) {
932
+ return inFlight;
933
+ }
934
+
935
+ const controller = new AbortController();
936
+ const call = this.routeFn(this.activitySlug, waypoints, { signal: controller.signal });
937
+ const request: RouteInFlight = { call, controller };
938
+ this.routesInFlight.set(key, request);
939
+ const forget = (): void => {
940
+ if (this.routesInFlight.get(key) === request) {
941
+ this.routesInFlight.delete(key);
942
+ }
943
+ };
944
+ call.then(forget, forget);
945
+
946
+ return request;
947
+ }
948
+
949
+ /**
950
+ * dropRoutesInFlight aborts every routing call in flight but the one for `kept`, and forgets
951
+ * each: the request it answered was replaced by one for other waypoints, or the edit ended,
952
+ * and nobody reads its answer. With no `kept`, every call is dropped.
953
+ *
954
+ * A call is forgotten before it is aborted, so a request made from inside a router's own
955
+ * `abort` listener joins no call that is being told to stop.
956
+ *
957
+ * @param kept The key of the request being asked for, whose call in flight is shared.
958
+ */
959
+ private dropRoutesInFlight(kept?: string): void {
960
+ for (const [key, request] of [...this.routesInFlight]) {
961
+ if (key !== kept) {
962
+ this.routesInFlight.delete(key);
963
+ request.controller.abort();
964
+ }
965
+ }
966
+ }
967
+
968
+ /**
969
+ * computeRoute calls the injected routeFn for the waypoints and maps the result
970
+ * onto the SDK's Directions shape (a single route with the GeoJSON line +
971
+ * distance/duration, the snapped waypoints echoed). A below-floor waypoint count
972
+ * or a null result (the router found nothing) returns a NoRoute response; a
973
+ * thrown routeFn (a transport error, an unknown activity slug, a partial GraphQL
974
+ * response) is absorbed into NoRoute so the edit stays usable rather than
975
+ * surfacing inside the renderer, and {@link warnOnRouteFault} says it in the console,
976
+ * once per edit and in development only, so a line that never paints has a reason.
977
+ *
978
+ * The returned geometry strips the elevation axis so the SDK's interactive math
979
+ * (`Ve` compares snappoint locations to route coords with strict 2D equality in
980
+ * geojson mode) sees coordinates of the same dimension as the snappoints the
981
+ * SDK builds: a 3D-vs-2D mismatch otherwise drops every intermediate leg to a
982
+ * one-coord empty slice in buildRoutelines and the routed line never paints.
983
+ * The snappoints echo a route-anchored coordinate so the SDK's coord-match loop
984
+ * finds them: the first via lands at the route's first coord, the last via at
985
+ * its last coord, and any intermediate via at its nearest route vertex. That
986
+ * is the only contract buildRoutelines needs to cut a route into legs.
987
+ *
988
+ * `key` names the request, for {@link routeOnce} to share a call still in flight. Every call
989
+ * in flight for other waypoints is dropped as this one begins ({@link dropRoutesInFlight}),
990
+ * and a dropped request rejects here with the abort's reason, whatever its router answers:
991
+ * a route, no route, or a rejection. The plugin reads that as a request of its own that it
992
+ * aborted, and draws nothing for it.
993
+ */
994
+ private async computeRoute(waypoints: Position[], key: string): Promise<Directions> {
995
+ const noRoute: Directions = { code: "NoRoute", routes: [], waypoints: [] };
996
+
997
+ // Bump + capture the resolution token before the await: a later computeRoute
998
+ // (a fresher via-set) bumps it again, so when an older resolution lands its
999
+ // token no longer matches and its live-preview side effects are dropped. A request
1000
+ // for the same waypoints shares the call and is handed its route: the plugin draws
1001
+ // the same line for both. Only lastRoute + the emit are gated by the token.
1002
+ this.routeToken += 1;
1003
+ const token = this.routeToken;
1004
+
1005
+ // This request replaces the one each call for other waypoints answered: those calls are
1006
+ // dropped, and their routers told. A call for these same waypoints is kept, and shared.
1007
+ this.dropRoutesInFlight(key);
1008
+
1009
+ if (waypoints.length < DIRECTIONS_VIA_MIN || waypoints.length > DIRECTIONS_VIA_MAX) {
1010
+ this.lastRoute = null;
1011
+
1012
+ return noRoute;
1013
+ }
1014
+
1015
+ let request: RouteInFlight | null = null;
1016
+ let route: SegmentRouteResult;
1017
+ try {
1018
+ request = this.routeOnce(key, waypoints);
1019
+ route = await request.call;
1020
+ } catch (fault) {
1021
+ // What the router of a dropped request rejects with is the abort it was told of, not a
1022
+ // fault of the route: see below for why the plugin is answered as it answers itself.
1023
+ request?.controller.signal.throwIfAborted();
1024
+
1025
+ // A routeFn throw (transport, auth, malformed response) is absorbed into
1026
+ // NoRoute so the renderer stays usable rather than surfacing inside it.
1027
+ this.warnOnRouteFault(fault);
1028
+ if (token === this.routeToken) {
1029
+ this.lastRoute = null;
1030
+ }
1031
+
1032
+ return noRoute;
1033
+ }
1034
+
1035
+ // A dropped request answers the plugin as the plugin's own `fetch` answers a request it
1036
+ // aborted, whatever its router came back with: it rejects with the abort's reason, and the
1037
+ // plugin then draws nothing for it. The plugin draws whatever it is answered and reads no
1038
+ // signal once the answer is in. So a "no route" for a request it has replaced would wipe
1039
+ // the line its reader still sees until the newer answer lands, and a route for it that
1040
+ // lands after the newer one would be drawn over the vias that replaced it. A router is free
1041
+ // to resolve to a route, to null or to a refusal once it is told to stop.
1042
+ request.controller.signal.throwIfAborted();
1043
+
1044
+ // The user was asked to accept this route and declined, so the placement that
1045
+ // produced it is undone: the SDK is re-seeded with the last accepted vias,
1046
+ // which fires a fresh routing round-trip that repaints the route they kept.
1047
+ // lastRoute is deliberately left alone: it still describes the accepted
1048
+ // shape, and clearing it would blank the live elevation panel between here
1049
+ // and that round-trip.
1050
+ if (route === SEGMENT_ROUTE_REFUSED) {
1051
+ if (token === this.routeToken) {
1052
+ this.revertToAcceptedVias();
1053
+ }
1054
+
1055
+ return noRoute;
1056
+ }
1057
+
1058
+ if (!route) {
1059
+ if (token === this.routeToken) {
1060
+ this.lastRoute = null;
1061
+ }
1062
+
1063
+ return noRoute;
1064
+ }
1065
+
1066
+ // When still current, cache the full route (3D geometry + elevation +
1067
+ // analysis) AND emit it as a fresh-route draft so the live elevation panel
1068
+ // reflects THIS resolution: the authoritative emit the SDK's waypoint events
1069
+ // never fire after a fetch settles (they carry the previous lastRoute, so the
1070
+ // profile would otherwise lag one routing round-trip and never catch the
1071
+ // final shape once a drag ends). programmatic:true updates the live segment
1072
+ // without re-entering undo history: the gesture already recorded the
1073
+ // geometry. The draft is settled, as every programmatic write is. An older
1074
+ // request for these same waypoints skips both and still returns the response
1075
+ // below, which is the route the newer one draws.
1076
+ if (token === this.routeToken) {
1077
+ this.lastRoute = route;
1078
+ // These vias now have an accepted route behind them, so they become the
1079
+ // restore point the next refusal reverts to.
1080
+ this.acceptedVias = [...waypoints];
1081
+ notifyListeners([this.emitDraft], {
1082
+ phase: "settled",
1083
+ programmatic: true,
1084
+ route,
1085
+ vias: waypoints,
1086
+ });
1087
+ }
1088
+
1089
+ const coordinates2d = route.geometry.coordinates.map((coordinate): [number, number] => [
1090
+ coordinate[0] ?? 0,
1091
+ coordinate[1] ?? 0,
1092
+ ]);
1093
+
1094
+ const snapped = snapWaypointsToRoute(waypoints, coordinates2d);
1095
+
1096
+ // The SDK's buildRoutelines iterates legs[] to cut the route geometry into
1097
+ // per-leg features and pulls each leg's annotation while doing so; an empty
1098
+ // legs array short-circuits the loop and the routed line never paints. A
1099
+ // minimal leg per gap between vias (one fewer than the via count) is all the
1100
+ // slicer needs: the values are zeros because the live preview reads the
1101
+ // route metrics directly, not the leg-level numbers.
1102
+ const legs = Array.from({ length: Math.max(waypoints.length - 1, 0) }, () => ({
1103
+ annotation: { congestion: [], distance: [], duration: [] },
1104
+ distance: 0,
1105
+ duration: 0,
1106
+ steps: [],
1107
+ summary: "",
1108
+ }));
1109
+
1110
+ return {
1111
+ code: "Ok",
1112
+ routes: [
1113
+ {
1114
+ distance: route.distance,
1115
+ duration: route.duration,
1116
+ geometry: { coordinates: coordinates2d },
1117
+ legs,
1118
+ },
1119
+ ],
1120
+ waypoints: snapped.map((location) => ({ location })),
1121
+ };
1122
+ }
1123
+
1124
+ /**
1125
+ * warnOnRouteFault says in the console, once per edit and in development only, that the
1126
+ * injected router threw.
1127
+ *
1128
+ * The engine reads a throw as no route found, so nothing the host holds rejects and the line
1129
+ * simply does not paint. The console is where the developer who wired the router is looking,
1130
+ * and the error rides beside the sentence with its stack. Once per edit, because a drag asks
1131
+ * for a route at every position it settles on and a router that is down fails each one for
1132
+ * the same reason. A production build says nothing: the fault is the host's to report through
1133
+ * its own router.
1134
+ */
1135
+ private warnOnRouteFault(fault: unknown): void {
1136
+ if (this.routeFaultReported || !inDevelopment()) {
1137
+ return;
1138
+ }
1139
+
1140
+ this.routeFaultReported = true;
1141
+ console.warn(
1142
+ "[@mountaya/elements] DirectionsSegmentEngine: routeFn threw, so the edit draws no route " +
1143
+ "for these vias. A router that finds no route resolves to null; one that throws is read " +
1144
+ "the same way and the edit stays open. The error it threw follows.",
1145
+ fault,
1146
+ );
1147
+ }
1148
+
1149
+ /**
1150
+ * enforcePinnedStart inspects the SDK's current first waypoint against the
1151
+ * pinned-start coordinate. If the head drifted past the backend's horizontal
1152
+ * tolerance (or was removed outright), it restores `pinnedStart` at index 0
1153
+ * via a programmatic setWaypoints, flagged through `reverting` so the
1154
+ * resulting setwaypoints event short-circuits in the listener and the
1155
+ * revert never enters history. Returns true when a revert ran so the caller
1156
+ * (the interactive move/remove listener) skips its own normal emit; the
1157
+ * revert's own setwaypoints event would have emitted a programmatic draft,
1158
+ * but the `reverting` guard suppresses it: the restored state is the same
1159
+ * state the next interactive gesture will read, so a duplicate emit is just
1160
+ * noise. Without a pinnedStart configured, the guard always returns false.
1161
+ */
1162
+ private enforcePinnedStart(): boolean {
1163
+ if (!this.pinnedStart || !this.directions) {
1164
+ return false;
1165
+ }
1166
+
1167
+ const current = this.directions.waypoints;
1168
+ if (isPinnedWaypointIntact(current, this.pinnedStart, 0)) {
1169
+ return false;
1170
+ }
1171
+
1172
+ const pinned: [number, number] = [this.pinnedStart[0] ?? 0, this.pinnedStart[1] ?? 0];
1173
+ // Build the corrected list: the pinned head at index 0, the rest of the
1174
+ // current waypoints after it. A head-remove (vertex 0 gone) shifts the
1175
+ // previous index-1 into the head slot; this restores the lock by
1176
+ // prepending the pinned coord so the rest of the chain stays as the user
1177
+ // had it after the interactive edit. A head-drag replaces the drifted
1178
+ // first coord with the pinned one and leaves the tail untouched.
1179
+ const tail = current.slice(1);
1180
+ const corrected: [number, number][] = [pinned, ...tail];
1181
+
1182
+ this.reverting = true;
1183
+ try {
1184
+ void this.directions.setWaypoints(corrected);
1185
+ } finally {
1186
+ this.reverting = false;
1187
+ }
1188
+ // Mirror the restored state onto the engine's via cache so a base-map
1189
+ // replay or readDraft after the revert reflects the locked head.
1190
+ this.vias = corrected.map((point): Position => [point[0], point[1]]);
1191
+
1192
+ return true;
1193
+ }
1194
+
1195
+ /**
1196
+ * enforcePinnedEnd is the tail mirror of {@link enforcePinnedStart}, with one
1197
+ * extra job. It keeps the pinned coordinate LAST, which covers two situations:
1198
+ *
1199
+ * - a drag or a programmatic remove moved the tail off the neighbour's start, so
1200
+ * the pin is restored in place exactly as the head guard restores index 0;
1201
+ * - an interactive add appended a via PAST the pin, so the pin is moved back
1202
+ * behind it. The click is kept, not reverted: the user asked for a point and
1203
+ * gets one, it just lands before the neighbour instead of after it.
1204
+ *
1205
+ * The second case is a real geometry change, so `emitInteractive` makes the
1206
+ * reorder emit its own interactive draft (the `reverting` flag suppresses the
1207
+ * setwaypoints event's emit, and the added via must still reach history and the
1208
+ * router). The restore cases pass false and stay silent, like the head guard.
1209
+ *
1210
+ * Returns true when it corrected the waypoints, so the caller skips its own emit.
1211
+ * Without a pinnedEnd configured it always returns false.
1212
+ */
1213
+ private enforcePinnedEnd(emitInteractive = false): boolean {
1214
+ if (!this.pinnedEnd || !this.directions) {
1215
+ return false;
1216
+ }
1217
+
1218
+ const current = this.directions.waypoints;
1219
+ if (isPinnedWaypointIntact(current, this.pinnedEnd, current.length - 1)) {
1220
+ return false;
1221
+ }
1222
+
1223
+ const pinned: [number, number] = [this.pinnedEnd[0] ?? 0, this.pinnedEnd[1] ?? 0];
1224
+ // Where the pin sits now. Found means an add pushed past it, so it is lifted out
1225
+ // and re-appended and every other via (including the new one) keeps its order.
1226
+ // Not found means the pin itself drifted or was dropped, so the last via is the
1227
+ // corrupted one and gets replaced, the same correction the head guard applies.
1228
+ const pinIndex = current.findIndex((_waypoint, index) =>
1229
+ isPinnedWaypointIntact(current, pinned, index),
1230
+ );
1231
+ const rest =
1232
+ pinIndex === -1 ? current.slice(0, -1) : current.filter((_wp, index) => index !== pinIndex);
1233
+ const corrected: [number, number][] = [...rest, pinned];
1234
+
1235
+ this.reverting = true;
1236
+ try {
1237
+ void this.directions.setWaypoints(corrected);
1238
+ } finally {
1239
+ this.reverting = false;
1240
+ }
1241
+ this.vias = corrected.map((point): Position => [point[0], point[1]]);
1242
+
1243
+ if (emitInteractive) {
1244
+ this.emitFromSdk(false);
1245
+ }
1246
+
1247
+ return true;
1248
+ }
1249
+
1250
+ /**
1251
+ * enforceViaCap refuses an interactive add that would push the via count past
1252
+ * `DIRECTIONS_VIA_MAX`. The router floors an over-cap set to a NoRoute response
1253
+ * (the SDK then clears the whole routed line), so rather than route it, the
1254
+ * engine reverts the SDK to the pre-insert vias it still holds in `this.vias`
1255
+ * and keeps the current `lastRoute` so the painted line survives the declined
1256
+ * insert. The revert is a programmatic setWaypoints flagged through `reverting`,
1257
+ * so the resulting setwaypoints event short-circuits in the listener and the
1258
+ * decline never enters history. Returns true when a revert ran so the
1259
+ * `addwaypoint` listener skips its own emit; false (the common case) leaves the
1260
+ * add to flow through normally. Mirrors `enforcePinnedStart`'s revert exactly.
1261
+ */
1262
+ private enforceViaCap(): boolean {
1263
+ if (!this.directions || this.directions.waypoints.length <= DIRECTIONS_VIA_MAX) {
1264
+ return false;
1265
+ }
1266
+
1267
+ this.reverting = true;
1268
+ try {
1269
+ void this.directions.setWaypoints(this.toLngLatPairs(this.vias));
1270
+ } finally {
1271
+ this.reverting = false;
1272
+ }
1273
+
1274
+ // Say so. Everything above this line is invisible to the user: the dot never
1275
+ // appears, the line does not change, and no draft flows out, so an unannounced
1276
+ // decline reads as a click that simply missed.
1277
+ if (this.onViaCapRefused !== undefined) {
1278
+ notifyListeners([this.onViaCapRefused]);
1279
+ }
1280
+
1281
+ return true;
1282
+ }
1283
+
1284
+ /**
1285
+ * revertToAcceptedVias undoes an in-flight placement by re-seeding the SDK with
1286
+ * the last via set whose route was accepted. `vias` is reset alongside so the
1287
+ * engine's mirror does not keep describing the refused set, and the `reverting`
1288
+ * guard keeps the resulting `setwaypoints` event from re-entering the pinned
1289
+ * checks on the just-restored state, the same shape as enforceViaCap's revert.
1290
+ *
1291
+ * The re-seed fires its own routing round-trip, for vias the router has already
1292
+ * answered and the user accepted: a router that asks the user before it answers
1293
+ * asks nothing of a set it answered before (the studio's remembers them), and the
1294
+ * route the user kept repaints.
1295
+ */
1296
+ private revertToAcceptedVias(): void {
1297
+ if (!this.directions) {
1298
+ return;
1299
+ }
1300
+
1301
+ this.vias = [...this.acceptedVias];
1302
+ this.reverting = true;
1303
+ try {
1304
+ void this.directions.setWaypoints(this.toLngLatPairs(this.acceptedVias));
1305
+ } finally {
1306
+ this.reverting = false;
1307
+ }
1308
+ }
1309
+
1310
+ /**
1311
+ * emitFromSdk reads the SDK's current waypoints, mirrors them onto the engine's
1312
+ * via cache, and forwards them as a draft with the given programmatic flag. The
1313
+ * flag comes from the event that triggered it (false for an interactive
1314
+ * add/move/remove, true for a programmatic setwaypoints re-seed) so a restore's
1315
+ * setwaypoints event does not re-enter history while a user gesture does.
1316
+ *
1317
+ * Every draft it forwards is `settled`. The SDK reports a waypoint once per gesture: an add
1318
+ * on the click, a move when the drag lets go (it reports no frame while `refreshOnMove` is
1319
+ * off, as this engine leaves it), a re-seed in one call. So there is never a frame to report.
1320
+ */
1321
+ private emitFromSdk(programmatic: boolean): void {
1322
+ if (!this.directions) {
1323
+ return;
1324
+ }
1325
+
1326
+ const vias = [...this.directions.waypoints];
1327
+ this.vias = vias;
1328
+
1329
+ // The cached route is the latest routeFn response the engine resolved for
1330
+ // these vias; it rides the draft so the live elevation panel reads the same
1331
+ // elevation + analysis the SDK just painted. null when no route currently
1332
+ // resolves (a below-floor via count, a routeFn throw, a NoRoute result).
1333
+ const draft: SegmentDraft = { phase: "settled", programmatic, route: this.lastRoute, vias };
1334
+ notifyListeners([this.emitDraft], draft);
1335
+ }
1336
+
1337
+ /**
1338
+ * attachRouteCursor shows "pointer" as an override while the pointer sits on the SDK's
1339
+ * sensitive routeline layer, through the shared {@link attachEditHoverCursor}, and the base
1340
+ * "+" append cross off it. So the cursor reads "pointer" on the routed line between two
1341
+ * existing points, where a click inserts a point, and "+" elsewhere, where a click adds the
1342
+ * next one. The override (not a fresh lock) keeps the base cross intact, the same
1343
+ * reconciliation the rest of the cursor system uses.
1344
+ *
1345
+ * The SDK's own `onMove` writes `canvas.style.cursor` directly on every move (clearing it over
1346
+ * empty map, overwriting it on the routeline); the map-level {@link attachCursorReassert}
1347
+ * re-pins the effective held cursor after it, the routeline override included.
1348
+ */
1349
+ private attachRouteCursor(): () => void {
1350
+ return attachEditHoverCursor({
1351
+ cursor: this.cursor,
1352
+ events: this.events,
1353
+ layers: [{ cursor: "pointer", kind: "fixed", layerId: "maplibre-gl-directions-routeline" }],
1354
+ map: this.map,
1355
+ });
1356
+ }
1357
+
1358
+ /**
1359
+ * attachCursorReassert subscribes the shared map-level mousemove re-assert that
1360
+ * re-pins the EFFECTIVE held cursor (the routeline "pointer" override when one
1361
+ * is held, else the locked "+" cross) after the SDK's own global move handler
1362
+ * has run. The SDK's `onMove` writes `canvas.style.cursor` directly: over empty
1363
+ * map (the "add the next point" append state) it clears it to "", on the
1364
+ * routeline it overwrites it; one map-level listener counters both because
1365
+ * `reassert` re-pins whichever tier is held.
1366
+ *
1367
+ * It deliberately does NOT touch drag-pan: the SDK owns pan itself: it enables
1368
+ * panning over empty map (so a drag pans the map while editing, and a click
1369
+ * still adds the next point) and disables it only while dragging a waypoint or
1370
+ * the routed line (so that drag reshapes). Registering it LAST (after
1371
+ * `interactive = true` has attached the SDK's move handler) means MapLibre
1372
+ * dispatches us after the SDK, so our cursor re-pin wins; it detaches by
1373
+ * reference through the shared manager.
1374
+ */
1375
+ private attachCursorReassert(): () => void {
1376
+ return attachCursorReassert(this.events, this.cursor);
1377
+ }
1378
+
1379
+ /** toLngLatPairs widens Position[] to the [number, number][] the SDK's setWaypoints expects, defaulting a missing axis to 0. */
1380
+ private toLngLatPairs(coordinates: Position[]): [number, number][] {
1381
+ return coordinates.map((coordinate) => [coordinate[0] ?? 0, coordinate[1] ?? 0]);
1382
+ }
1383
+ }