@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,2702 @@
1
+ import { c as attachCursorReassert, l as attachEditHoverCursor, s as ZONE_CREATE_CURSOR } from "../chunk-yMzRr26E.js";
2
+ import { o as printValue, t as MountayaElementsError } from "../chunk-Cl1etdlu.js";
3
+ import { a as wrapLongitudePastRange } from "../chunk-C9aR8DXb.js";
4
+ import { m as normalizeBoundingBox } from "../chunk-DyhJZC2i.js";
5
+ import { t as boundingBoxToPolygon } from "../chunk-CJwUtkOt.js";
6
+ import { n as surfaceFault, t as notifyListeners } from "../chunk-BTUUABGI.js";
7
+ import { t as localId } from "../chunk-DNfGfIF3.js";
8
+ import { n as DEGREES_TO_RADIANS, o as RADIANS_TO_DEGREES } from "../chunk-DsDYVJQC.js";
9
+ import "../chunk-fWRUMgRI.js";
10
+ import { t as inDevelopment } from "../chunk-CN_TKSgm.js";
11
+ import { r as waypointIconImageId } from "../chunk-HIJzXoN4.js";
12
+ import "../chunk-CJp8nGcb.js";
13
+ import { a as blankStyle, n as bindEditEngines, o as isGeoJsonSource, t as MapLibreViewClient } from "../chunk-DjnYQBCN.js";
14
+ import { l as SVG_NAMESPACE, u as describeWaypointSvg } from "../chunk-Ce1_thm7.js";
15
+ import { t as SEGMENT_ROUTE_REFUSED } from "../chunk-CmoVJDoz.js";
16
+ import { t as omtCategoryToPoiEnum } from "../chunk-blqsohAb.js";
17
+ import { n as ZONE_MODES, t as ZONE_LEVELS } from "../chunk-RrKkJb6P.js";
18
+ import { TerraDraw, TerraDrawCircleMode, TerraDrawFreehandMode, TerraDrawLineStringMode, TerraDrawPointMode, TerraDrawPolygonMode, TerraDrawRectangleMode, TerraDrawSectorMode, TerraDrawSelectMode, TerraDrawSensorMode, ValidateNotSelfIntersecting } from "terra-draw";
19
+ import { TerraDrawMapLibreGLAdapter } from "terra-draw-maplibre-gl-adapter";
20
+ import MapLibreGlDirections, { layersFactory } from "@maplibre/maplibre-gl-directions";
21
+ const isFiniteNumber = (value) => typeof value === "number" && Number.isFinite(value);
22
+ const readEditPosition = (position, owner, member, absence = "leave it out") => {
23
+ if (position === void 0 || position === null) return position;
24
+ const written = position;
25
+ const [longitude, latitude] = Array.isArray(written) ? written : [];
26
+ if (!(isFiniteNumber(longitude) && isFiniteNumber(latitude) && Math.abs(latitude) <= 90)) throw new MountayaElementsError(`${owner}: ${member} is ${printValue(written)}; pass [longitude, latitude] as two finite numbers, the latitude from -90 to 90, or ${absence}.`);
27
+ return position;
28
+ };
29
+ const hexColor = /^#(?:[0-9a-f]{6}|[0-9a-f]{3})$/i;
30
+ const readEditColor = (color, owner) => {
31
+ const written = color;
32
+ if (typeof written !== "string" || !hexColor.test(written)) throw new MountayaElementsError(`${owner}: color is ${printValue(written)}; pass a colour as #rrggbb or #rgb, hexadecimal digits.`);
33
+ const digits = written.slice(1);
34
+ return digits.length === 3 ? `#${digits.replace(/./g, (digit) => digit + digit)}` : `#${digits}`;
35
+ };
36
+ const projectPointToSegmentPx = (p, a, b) => {
37
+ const dx = b.x - a.x;
38
+ const dy = b.y - a.y;
39
+ const lengthSq = dx * dx + dy * dy;
40
+ if (lengthSq === 0) return {
41
+ x: a.x,
42
+ y: a.y
43
+ };
44
+ const t = ((p.x - a.x) * dx + (p.y - a.y) * dy) / lengthSq;
45
+ const clamped = Math.max(0, Math.min(1, t));
46
+ return {
47
+ x: a.x + clamped * dx,
48
+ y: a.y + clamped * dy
49
+ };
50
+ };
51
+ const sqDist = (a, b) => {
52
+ const dx = a.x - b.x;
53
+ const dy = a.y - b.y;
54
+ return dx * dx + dy * dy;
55
+ };
56
+ const COORDINATE_PRECISION = 9;
57
+ const clampCoordinatePrecision = (position) => {
58
+ const factor = 10 ** COORDINATE_PRECISION;
59
+ return [Math.round((position[0] ?? 0) * factor) / factor, Math.round((position[1] ?? 0) * factor) / factor];
60
+ };
61
+ const pointerPosition = (lngLat) => clampCoordinatePrecision([wrapLongitudePastRange(lngLat.lng), lngLat.lat]);
62
+ const nearestEdgeInsertion = ({ line, lngLat, map, thresholdPx }) => {
63
+ if (line.length < 2) return null;
64
+ const cursorPx = map.project({
65
+ lat: lngLat[1] ?? 0,
66
+ lng: lngLat[0] ?? 0
67
+ });
68
+ let bestDistSq = Number.POSITIVE_INFINITY;
69
+ let bestPx = null;
70
+ let bestIndex = -1;
71
+ for (let i = 1; i < line.length; i++) {
72
+ const prev = line[i - 1];
73
+ const next = line[i];
74
+ if (!prev || !next) continue;
75
+ const a = map.project({
76
+ lat: prev[1] ?? 0,
77
+ lng: prev[0] ?? 0
78
+ });
79
+ const b = map.project({
80
+ lat: next[1] ?? 0,
81
+ lng: next[0] ?? 0
82
+ });
83
+ const projected = projectPointToSegmentPx(cursorPx, a, b);
84
+ const distSq = sqDist(cursorPx, projected);
85
+ if (distSq < bestDistSq) {
86
+ bestDistSq = distSq;
87
+ bestPx = projected;
88
+ bestIndex = i;
89
+ }
90
+ }
91
+ if (bestPx === null || bestDistSq > thresholdPx * thresholdPx) return null;
92
+ const snapped = map.unproject([bestPx.x, bestPx.y]);
93
+ return {
94
+ index: bestIndex,
95
+ lngLat: clampCoordinatePrecision([snapped.lng, snapped.lat])
96
+ };
97
+ };
98
+ const nearestVertex = ({ line, lngLat, map }) => {
99
+ if (line.length === 0) return {
100
+ distancePx: Number.POSITIVE_INFINITY,
101
+ index: -1
102
+ };
103
+ const cursorPx = map.project({
104
+ lat: lngLat[1] ?? 0,
105
+ lng: lngLat[0] ?? 0
106
+ });
107
+ let bestDistSq = Number.POSITIVE_INFINITY;
108
+ let bestIndex = -1;
109
+ for (const [index, vertex] of line.entries()) {
110
+ if (!vertex) continue;
111
+ const vertexPx = map.project({
112
+ lat: vertex[1] ?? 0,
113
+ lng: vertex[0] ?? 0
114
+ });
115
+ const distSq = sqDist(cursorPx, vertexPx);
116
+ if (distSq < bestDistSq) {
117
+ bestDistSq = distSq;
118
+ bestIndex = index;
119
+ }
120
+ }
121
+ return {
122
+ distancePx: Math.sqrt(bestDistSq),
123
+ index: bestIndex
124
+ };
125
+ };
126
+ const SELECT_MODE = "select";
127
+ const TERRA_DRAW_MID_POINT_PROPERTY = "midPoint";
128
+ const isProgrammaticChange = (context) => typeof context === "object" && context !== null && "origin" in context && context.origin === "api";
129
+ const drawIdStrategy = {
130
+ getId: () => localId(),
131
+ isValidId: (id) => typeof id === "string" || typeof id === "number"
132
+ };
133
+ const DRAW_REFUSAL_PREFIX = "Feature validation failed: ";
134
+ const DRAW_REFUSAL_REMEDY = "Pass positions of two finite numbers, a longitude from -180 to 180 and a latitude from -90 to 90, and for an area one closed ring with no hole.";
135
+ const refusalOf = ({ engine, remedy = DRAW_REFUSAL_REMEDY, shape }, reason, cause) => new MountayaElementsError(`${engine}: TerraDraw refuses the ${shape} (${reason ?? "no reason given"}). ${remedy}`, cause === void 0 ? void 0 : { cause });
136
+ const addDrawFeature = (draw, feature, subject) => {
137
+ const [verdict] = draw.addFeatures([feature]);
138
+ if (verdict !== void 0 && !verdict.valid) throw refusalOf(subject, verdict.reason);
139
+ };
140
+ const updateDrawGeometry = (draw, id, geometry, subject) => {
141
+ try {
142
+ draw.updateFeatureGeometry(id, geometry);
143
+ } catch (error) {
144
+ if (error instanceof Error && error.message.startsWith(DRAW_REFUSAL_PREFIX)) throw refusalOf(subject, error.message.slice(27), error);
145
+ throw error;
146
+ }
147
+ };
148
+ const applyHeldWrite = (write) => {
149
+ try {
150
+ write();
151
+ } catch (error) {
152
+ surfaceFault(error);
153
+ }
154
+ };
155
+ const copyPositions = (positions) => positions.map((position) => [...position]);
156
+ const frameLongitudeFor = (longitudes) => {
157
+ let west = Number.POSITIVE_INFINITY;
158
+ let east = Number.NEGATIVE_INFINITY;
159
+ for (const longitude of longitudes) {
160
+ if (!Number.isFinite(longitude)) return 0;
161
+ west = Math.min(west, longitude);
162
+ east = Math.max(east, longitude);
163
+ }
164
+ if (west > east) return 0;
165
+ return 180 * Math.round((west + east) / 2 / 180) + 0;
166
+ };
167
+ const polygonFrameLongitude = (geometry) => frameLongitudeFor(geometry.coordinates.flatMap((ring) => ring.map(([lng = 0]) => lng)));
168
+ const intoFrame = (position, frameLongitude) => clampCoordinatePrecision([(position[0] ?? 0) - frameLongitude, position[1] ?? 0]);
169
+ const outOfFrame = (position, frameLongitude) => clampCoordinatePrecision([(position[0] ?? 0) + frameLongitude, position[1] ?? 0]);
170
+ const shownCopyOffset = (frameLongitude, centerLongitude) => 360 * Math.round((centerLongitude - frameLongitude) / 360) + 0;
171
+ const shiftedBy = (feature, degrees) => {
172
+ const { geometry } = feature;
173
+ switch (geometry.type) {
174
+ case "Point": {
175
+ const [lng = 0, lat = 0] = geometry.coordinates;
176
+ return {
177
+ ...feature,
178
+ geometry: {
179
+ coordinates: [lng + degrees, lat],
180
+ type: "Point"
181
+ }
182
+ };
183
+ }
184
+ case "LineString": return {
185
+ ...feature,
186
+ geometry: {
187
+ coordinates: geometry.coordinates.map(([lng = 0, lat = 0]) => [lng + degrees, lat]),
188
+ type: "LineString"
189
+ }
190
+ };
191
+ case "Polygon": return {
192
+ ...feature,
193
+ geometry: {
194
+ coordinates: geometry.coordinates.map((ring) => ring.map(([lng = 0, lat = 0]) => [lng + degrees, lat])),
195
+ type: "Polygon"
196
+ }
197
+ };
198
+ }
199
+ };
200
+ const inertSource = { setData: () => {} };
201
+ const styleGuarded = (map) => {
202
+ const getSource = (id) => map.getSource(id) ?? inertSource;
203
+ const removeLayer = (id) => map.getLayer(id) === void 0 ? map : map.removeLayer(id);
204
+ const removeSource = (id) => map.getSource(id) === void 0 ? map : map.removeSource(id);
205
+ const bound = /* @__PURE__ */ new Map();
206
+ return new Proxy(map, { get: (target, key) => {
207
+ if (key === "getSource") return getSource;
208
+ if (key === "removeLayer") return removeLayer;
209
+ if (key === "removeSource") return removeSource;
210
+ const value = Reflect.get(target, key, target);
211
+ if (typeof value !== "function") return value;
212
+ let method = bound.get(key);
213
+ if (method === void 0) {
214
+ method = value.bind(target);
215
+ bound.set(key, method);
216
+ }
217
+ return method;
218
+ } });
219
+ };
220
+ var FramedMapLibreAdapter = class extends TerraDrawMapLibreGLAdapter {
221
+ frame;
222
+ framedMap;
223
+ constructor(config, frame) {
224
+ super({
225
+ ...config,
226
+ map: styleGuarded(config.map)
227
+ });
228
+ this.frame = frame;
229
+ this.framedMap = config.map;
230
+ }
231
+ project(lng, lat) {
232
+ return super.project(lng + this.worldOffset(), lat);
233
+ }
234
+ unproject(x, y) {
235
+ const { lat, lng } = super.unproject(x, y);
236
+ return {
237
+ lat,
238
+ lng: lng - this.worldOffset()
239
+ };
240
+ }
241
+ render(changes, styling) {
242
+ const degrees = this.frame.longitude;
243
+ if (degrees === 0) {
244
+ super.render(changes, styling);
245
+ return;
246
+ }
247
+ super.render({
248
+ created: changes.created.map((feature) => shiftedBy(feature, degrees)),
249
+ deletedIds: changes.deletedIds,
250
+ unchanged: changes.unchanged.map((feature) => shiftedBy(feature, degrees)),
251
+ updated: changes.updated.map((feature) => shiftedBy(feature, degrees))
252
+ }, styling);
253
+ }
254
+ worldOffset() {
255
+ const frameLongitude = this.frame.longitude;
256
+ if (frameLongitude === 0) return 0;
257
+ return frameLongitude + shownCopyOffset(frameLongitude, this.framedMap.getCenter().lng);
258
+ }
259
+ };
260
+ const BOUNDARY_DRAW_MODE_NAME = "rectangle";
261
+ const BOUNDARY_TERRADRAW_PREFIX = "td-boundary";
262
+ const BOUNDARY_FILL_LAYER_ID = `${BOUNDARY_TERRADRAW_PREFIX}-polygon`;
263
+ const BOUNDARY_VERTEX_LAYER_ID = `${BOUNDARY_TERRADRAW_PREFIX}-point`;
264
+ const BOUNDARY_RING_CORNERS = 4;
265
+ const boundaryRefusal = {
266
+ engine: "TerraDrawBoundaryEngine",
267
+ shape: "box"
268
+ };
269
+ const buildBoundaryDrawMode = () => new TerraDrawRectangleMode();
270
+ const buildBoundarySelectFlags = () => ({ [BOUNDARY_DRAW_MODE_NAME]: { feature: {
271
+ coordinates: {
272
+ deletable: false,
273
+ draggable: true,
274
+ midpoints: false
275
+ },
276
+ draggable: true
277
+ } } });
278
+ const defaultBoundaryDrawFactory = ({ map, prefixId }) => new TerraDraw({
279
+ adapter: new FramedMapLibreAdapter({
280
+ map,
281
+ prefixId
282
+ }, { longitude: 0 }),
283
+ idStrategy: drawIdStrategy,
284
+ modes: [buildBoundaryDrawMode(), new TerraDrawSelectMode({ flags: buildBoundarySelectFlags() })]
285
+ });
286
+ const ringCorners = (geometry) => {
287
+ const ring = geometry.coordinates[0];
288
+ if (!ring || ring.length !== 5) return null;
289
+ return ring.slice(0, BOUNDARY_RING_CORNERS);
290
+ };
291
+ const isAxisAlignedRectangle = (corners) => {
292
+ const lngs = new Set(corners.map((corner) => corner[0]));
293
+ const lats = new Set(corners.map((corner) => corner[1]));
294
+ if (lngs.size > 2 || lats.size > 2) return false;
295
+ const held = new Set(corners.map((corner) => `${corner[0]}|${corner[1]}`));
296
+ return [...lngs].every((lng) => [...lats].every((lat) => held.has(`${lng}|${lat}`)));
297
+ };
298
+ const cornersFromCornerDrag = (previous, corners) => {
299
+ if (!previous || previous.length !== corners.length) return null;
300
+ const moved = corners.reduce((indices, corner, index) => {
301
+ const before = previous[index];
302
+ if (!before || before[0] !== corner[0] || before[1] !== corner[1]) indices.push(index);
303
+ return indices;
304
+ }, []);
305
+ const movedIndex = moved.length === 1 ? moved[0] : void 0;
306
+ if (movedIndex === void 0) return null;
307
+ const besideIndex = (movedIndex + 1) % BOUNDARY_RING_CORNERS;
308
+ const anchorIndex = (movedIndex + 2) % BOUNDARY_RING_CORNERS;
309
+ const acrossIndex = (movedIndex + 3) % BOUNDARY_RING_CORNERS;
310
+ const [draggedLng, draggedLat] = corners[movedIndex] ?? [];
311
+ const [anchorLng, anchorLat] = corners[anchorIndex] ?? [];
312
+ if (draggedLng === void 0 || draggedLat === void 0 || anchorLng === void 0 || anchorLat === void 0) return null;
313
+ const [west, south, east, north] = normalizeBoundingBox([
314
+ draggedLng,
315
+ draggedLat,
316
+ anchorLng,
317
+ anchorLat
318
+ ]);
319
+ const draggedIsWest = draggedLng <= anchorLng;
320
+ const draggedIsSouth = draggedLat <= anchorLat;
321
+ const dragged = [draggedIsWest ? west : east, draggedIsSouth ? south : north];
322
+ const anchor = [draggedIsWest ? east : west, draggedIsSouth ? north : south];
323
+ const besideSharesLng = previous[besideIndex]?.[0] === previous[movedIndex]?.[0];
324
+ const onDraggedMeridian = [dragged[0] ?? 0, anchor[1] ?? 0];
325
+ const onDraggedParallel = [anchor[0] ?? 0, dragged[1] ?? 0];
326
+ const rebuilt = [...corners];
327
+ rebuilt[movedIndex] = dragged;
328
+ rebuilt[anchorIndex] = anchor;
329
+ rebuilt[besideIndex] = besideSharesLng ? onDraggedMeridian : onDraggedParallel;
330
+ rebuilt[acrossIndex] = besideSharesLng ? onDraggedParallel : onDraggedMeridian;
331
+ return rebuilt;
332
+ };
333
+ const closedRing = (corners) => ({
334
+ coordinates: [[...corners, ...corners.slice(0, 1)]],
335
+ type: "Polygon"
336
+ });
337
+ const drawableBox = (bbox) => {
338
+ const [west, south, east, north] = normalizeBoundingBox(bbox);
339
+ const [drawnWest, drawnEast] = west === 180 && east > 180 ? [-180, east - west - 180] : [west, Math.min(east, 180)];
340
+ const southWest = clampCoordinatePrecision([drawnWest, south]);
341
+ const northEast = clampCoordinatePrecision([drawnEast, north]);
342
+ return [
343
+ southWest[0],
344
+ southWest[1],
345
+ northEast[0],
346
+ northEast[1]
347
+ ];
348
+ };
349
+ const sameBoundingBox = (a, b) => {
350
+ if (a === null || b === null) return a === b;
351
+ return a.every((value, index) => value === b[index]);
352
+ };
353
+ var TerraDrawBoundaryEngine = class {
354
+ map;
355
+ emitDraft;
356
+ draw;
357
+ featureId;
358
+ activeFeatureId;
359
+ hasBox = false;
360
+ lastCorners = null;
361
+ lastEmitted = null;
362
+ color;
363
+ events;
364
+ cursor;
365
+ detachHoverCursor = null;
366
+ gestureOpen = false;
367
+ repairing = false;
368
+ detachCursorReassert = null;
369
+ changeHandler;
370
+ finishHandler;
371
+ detachedBbox = null;
372
+ detached = false;
373
+ heldDraft;
374
+ disposed = false;
375
+ constructor(map, options, emitDraft, createDraw = defaultBoundaryDrawFactory, events, cursor) {
376
+ this.map = map;
377
+ this.emitDraft = emitDraft;
378
+ this.featureId = options.featureId;
379
+ this.activeFeatureId = options.featureId;
380
+ this.color = readEditColor(options.color, "TerraDrawBoundaryEngine");
381
+ this.events = events ?? null;
382
+ this.cursor = cursor ?? null;
383
+ this.changeHandler = (ids, _type, context) => {
384
+ this.handleChange(ids, isProgrammaticChange(context));
385
+ };
386
+ this.finishHandler = (id) => {
387
+ this.handleFinish(id);
388
+ };
389
+ this.draw = createDraw({
390
+ map: this.map,
391
+ prefixId: BOUNDARY_TERRADRAW_PREFIX
392
+ });
393
+ this.draw.start();
394
+ this.attachDrawListeners();
395
+ if (options.seedBbox) {
396
+ const seed = drawableBox(options.seedBbox);
397
+ this.lastEmitted = seed;
398
+ try {
399
+ this.seedFeature(seed);
400
+ } catch (error) {
401
+ this.dispose();
402
+ throw error;
403
+ }
404
+ } else this.armDrawMode();
405
+ this.applyBoundaryDraftStyle(this.color);
406
+ this.detachHoverCursor = this.attachHoverCursor();
407
+ this.detachCursorReassert = this.attachCursorReassert();
408
+ }
409
+ setDraftStyle(style) {
410
+ if (this.disposed) return;
411
+ this.color = readEditColor(style.color, "TerraDrawBoundaryEngine");
412
+ if (this.detached) return;
413
+ this.applyBoundaryDraftStyle(this.color);
414
+ }
415
+ readDraft() {
416
+ if (this.disposed) return null;
417
+ if (this.detached) {
418
+ const held = this.heldDraft === void 0 ? this.detachedBbox : this.heldDraft;
419
+ return held === null ? null : [...held];
420
+ }
421
+ return this.currentBbox();
422
+ }
423
+ applyDraft(bbox) {
424
+ if (this.disposed) return;
425
+ const normalized = drawableBox(bbox);
426
+ if (this.detached) {
427
+ this.heldDraft = normalized;
428
+ return;
429
+ }
430
+ if (this.hasBox) {
431
+ updateDrawGeometry(this.draw, this.activeFeatureId, boundingBoxToPolygon(normalized), boundaryRefusal);
432
+ return;
433
+ }
434
+ this.seedFeature(normalized);
435
+ this.emitBbox(normalized, true, "settled");
436
+ }
437
+ clearDraft() {
438
+ if (this.disposed) return;
439
+ if (this.detached) {
440
+ this.heldDraft = null;
441
+ return;
442
+ }
443
+ this.draw.clear();
444
+ this.hasBox = false;
445
+ this.lastCorners = null;
446
+ this.activeFeatureId = this.featureId;
447
+ this.armDrawMode();
448
+ this.gestureOpen = false;
449
+ this.emitBbox(null, false, "settled");
450
+ }
451
+ dispose() {
452
+ this.detachCursorReassert?.();
453
+ this.detachCursorReassert = null;
454
+ this.detachHoverCursor?.();
455
+ this.detachHoverCursor = null;
456
+ this.cursor?.popOverride();
457
+ this.cursor?.unlock();
458
+ this.detachDrawListeners();
459
+ if (this.draw.enabled) this.draw.clear();
460
+ this.draw.stop();
461
+ this.disposed = true;
462
+ this.heldDraft = void 0;
463
+ this.detachedBbox = null;
464
+ }
465
+ detachBeforeStyleReload() {
466
+ if (this.disposed) return;
467
+ if (this.detached) return;
468
+ this.detached = true;
469
+ this.detachedBbox = this.currentBbox();
470
+ this.detachDrawListeners();
471
+ this.draw.stop();
472
+ }
473
+ replayAfterStyleReload() {
474
+ if (this.disposed) return;
475
+ const bbox = this.detachedBbox ?? this.currentBbox();
476
+ this.detachedBbox = null;
477
+ this.detached = false;
478
+ this.draw.start();
479
+ this.attachDrawListeners();
480
+ if (bbox) {
481
+ this.draw.clear();
482
+ this.seedFeature(bbox);
483
+ } else this.armDrawMode();
484
+ this.applyBoundaryDraftStyle(this.color);
485
+ this.detachHoverCursor?.();
486
+ this.detachHoverCursor = this.attachHoverCursor();
487
+ this.detachCursorReassert?.();
488
+ this.detachCursorReassert = this.attachCursorReassert();
489
+ const held = this.heldDraft;
490
+ this.heldDraft = void 0;
491
+ if (held === null) applyHeldWrite(() => this.clearDraft());
492
+ else if (held !== void 0) applyHeldWrite(() => this.applyDraft(held));
493
+ }
494
+ attachDrawListeners() {
495
+ this.draw.on("change", this.changeHandler);
496
+ this.draw.on("finish", this.finishHandler);
497
+ }
498
+ detachDrawListeners() {
499
+ this.draw.off("change", this.changeHandler);
500
+ this.draw.off("finish", this.finishHandler);
501
+ }
502
+ handleChange(ids, programmatic) {
503
+ if (this.repairing) return;
504
+ if (!ids.includes(this.activeFeatureId)) return;
505
+ const geometry = this.geometryOf(this.activeFeatureId);
506
+ if (!geometry) return;
507
+ const corners = ringCorners(geometry);
508
+ if (!corners) return;
509
+ if (!isAxisAlignedRectangle(corners)) {
510
+ const dragged = cornersFromCornerDrag(this.lastCorners, corners);
511
+ const repairedPolygon = dragged ? closedRing(dragged) : boundingBoxToPolygon(this.extentOf(geometry));
512
+ const repaired = this.extentOf(repairedPolygon);
513
+ this.lastCorners = ringCorners(repairedPolygon);
514
+ this.emitChange(repaired, programmatic);
515
+ this.repairing = true;
516
+ try {
517
+ this.draw.updateFeatureGeometry(this.activeFeatureId, repairedPolygon);
518
+ } finally {
519
+ this.repairing = false;
520
+ }
521
+ return;
522
+ }
523
+ this.lastCorners = corners;
524
+ this.emitChange(this.extentOf(geometry), programmatic);
525
+ }
526
+ emitChange(bbox, programmatic) {
527
+ const phase = programmatic ? "settled" : "live";
528
+ this.gestureOpen = phase === "live";
529
+ this.emitBbox(bbox, programmatic, phase);
530
+ }
531
+ handleFinish(id) {
532
+ if (this.hasBox) {
533
+ if (id === this.activeFeatureId) this.settleGesture();
534
+ return;
535
+ }
536
+ const geometry = this.geometryOf(id);
537
+ const corners = geometry ? ringCorners(geometry) : null;
538
+ if (!geometry || !corners) return;
539
+ this.activeFeatureId = id;
540
+ this.adoptBox(corners);
541
+ this.draw.selectFeature(id);
542
+ this.emitBbox(this.extentOf(geometry), false, "settled");
543
+ }
544
+ settleGesture() {
545
+ if (!this.gestureOpen) return;
546
+ this.gestureOpen = false;
547
+ const bbox = this.currentBbox();
548
+ if (bbox !== null) this.emitBbox(bbox, false, "settled", true);
549
+ }
550
+ seedFeature(bbox) {
551
+ const feature = {
552
+ geometry: boundingBoxToPolygon(bbox),
553
+ id: this.featureId,
554
+ properties: { mode: BOUNDARY_DRAW_MODE_NAME },
555
+ type: "Feature"
556
+ };
557
+ addDrawFeature(this.draw, feature, boundaryRefusal);
558
+ this.activeFeatureId = this.featureId;
559
+ const corners = ringCorners(boundingBoxToPolygon(bbox));
560
+ this.adoptBox(corners ?? []);
561
+ this.draw.selectFeature(this.featureId);
562
+ }
563
+ adoptBox(corners) {
564
+ this.hasBox = true;
565
+ this.lastCorners = corners;
566
+ this.draw.setMode(SELECT_MODE);
567
+ this.cursor?.unlock();
568
+ }
569
+ armDrawMode() {
570
+ this.draw.setMode(BOUNDARY_DRAW_MODE_NAME);
571
+ this.cursor?.lock(ZONE_CREATE_CURSOR);
572
+ }
573
+ emitBbox(bbox, programmatic, phase, closesGesture = false) {
574
+ if (!closesGesture && sameBoundingBox(bbox, this.lastEmitted)) return;
575
+ this.lastEmitted = bbox;
576
+ notifyListeners([this.emitDraft], {
577
+ bbox,
578
+ phase,
579
+ programmatic
580
+ });
581
+ }
582
+ currentBbox() {
583
+ const geometry = this.geometryOf(this.activeFeatureId);
584
+ return geometry ? this.extentOf(geometry) : null;
585
+ }
586
+ extentOf(geometry) {
587
+ let west = Number.POSITIVE_INFINITY;
588
+ let south = Number.POSITIVE_INFINITY;
589
+ let east = Number.NEGATIVE_INFINITY;
590
+ let north = Number.NEGATIVE_INFINITY;
591
+ for (const [lng, lat] of geometry.coordinates[0] ?? []) {
592
+ if (lng === void 0 || lat === void 0 || !Number.isFinite(lng) || !Number.isFinite(lat)) continue;
593
+ west = Math.min(west, lng);
594
+ south = Math.min(south, lat);
595
+ east = Math.max(east, lng);
596
+ north = Math.max(north, lat);
597
+ }
598
+ return normalizeBoundingBox(west <= east ? [
599
+ west,
600
+ south,
601
+ east,
602
+ north
603
+ ] : [
604
+ 0,
605
+ 0,
606
+ 0,
607
+ 0
608
+ ]);
609
+ }
610
+ geometryOf(id) {
611
+ const feature = this.draw.getSnapshotFeature(id);
612
+ if (!feature) return null;
613
+ const geometry = feature.geometry;
614
+ return geometry.type === "Polygon" ? geometry : null;
615
+ }
616
+ applyBoundaryDraftStyle(hex) {
617
+ this.draw.updateModeOptions(BOUNDARY_DRAW_MODE_NAME, { styles: {
618
+ fillColor: hex,
619
+ fillOpacity: .2,
620
+ outlineColor: hex,
621
+ outlineWidth: 2
622
+ } });
623
+ this.draw.updateModeOptions(SELECT_MODE, { styles: {
624
+ selectedLineStringColor: hex,
625
+ selectedPointColor: hex,
626
+ selectedPolygonColor: hex,
627
+ selectedPolygonOutlineColor: hex,
628
+ selectionPointColor: hex
629
+ } });
630
+ }
631
+ attachCursorReassert() {
632
+ if (!this.events || !this.cursor) return null;
633
+ return attachCursorReassert(this.events, this.cursor);
634
+ }
635
+ attachHoverCursor() {
636
+ const events = this.events;
637
+ const cursor = this.cursor;
638
+ if (!events || !cursor) return () => {};
639
+ return attachEditHoverCursor({
640
+ cursor,
641
+ events,
642
+ layers: [{
643
+ kind: "handle",
644
+ layerId: BOUNDARY_VERTEX_LAYER_ID,
645
+ midpointProperty: "midPoint"
646
+ }, {
647
+ kind: "interior",
648
+ layerId: BOUNDARY_FILL_LAYER_ID
649
+ }],
650
+ map: this.map
651
+ });
652
+ }
653
+ };
654
+ const sameOrdinate = (a, b) => a === b || Number.isNaN(a) && Number.isNaN(b);
655
+ const samePoint = (a, b) => sameOrdinate(a[0], b[0]) && sameOrdinate(a[1], b[1]);
656
+ const pointText = (position) => `[${position.slice(0, 2).join(", ")}]`;
657
+ const refusePinMismatch = (seed, startPin, endPin, owner) => {
658
+ if (seed.length < 2) {
659
+ if (startPin && endPin && !samePoint(startPin, endPin)) throw new MountayaElementsError(`${owner}: pinnedStart is ${pointText(startPin)} and pinnedEnd is ${pointText(endPin)}, with fewer than two seedVias. An edit pinned at both ends opens on the line between them: pass seedVias that start at pinnedStart and end at pinnedEnd.`);
660
+ return;
661
+ }
662
+ const head = seed[0];
663
+ if (startPin && head && !samePoint(head, startPin)) throw new MountayaElementsError(`${owner}: seedVias starts at ${pointText(head)} and pinnedStart is ${pointText(startPin)}. A pinned start is the line's first via: pass one position for both, or leave pinnedStart out to leave the start free.`);
664
+ const tail = seed.at(-1);
665
+ if (endPin && tail && !samePoint(tail, endPin)) throw new MountayaElementsError(`${owner}: seedVias ends at ${pointText(tail)} and pinnedEnd is ${pointText(endPin)}. A pinned end is the line's last via: pass one position for both, or leave pinnedEnd out to leave the end free.`);
666
+ };
667
+ const refuseSegmentPositions = (options, owner) => {
668
+ const startPin = readEditPosition(options.pinnedStart, owner, "pinnedStart");
669
+ const endPin = readEditPosition(options.pinnedEnd, owner, "pinnedEnd");
670
+ const written = options.seedVias;
671
+ if (written !== void 0 && written !== null && !Array.isArray(written)) throw new MountayaElementsError(`${owner}: seedVias is ${printValue(written)}; pass a list of [longitude, latitude] positions, or leave it out to draw a new segment.`);
672
+ for (const [index, via] of (options.seedVias ?? []).entries()) readEditPosition(via, owner, `seedVias[${index}]`, "leave the via out");
673
+ return {
674
+ endPin,
675
+ startPin
676
+ };
677
+ };
678
+ const refuseSegmentSeed = (options, owner) => {
679
+ const { endPin, startPin } = refuseSegmentPositions(options, owner);
680
+ refusePinMismatch((options.seedVias ?? []).map(clampCoordinatePrecision), startPin ? clampCoordinatePrecision(startPin) : void 0, endPin ? clampCoordinatePrecision(endPin) : void 0, owner);
681
+ };
682
+ const refuseZoneSeed = (options, owner) => {
683
+ const written = options.seedGeometry;
684
+ if (written === void 0 || written === null) return;
685
+ const kind = typeof written === "object" && written !== null && "type" in written ? written.type : null;
686
+ if (kind !== "Polygon") throw new MountayaElementsError(`${owner}: seedGeometry is ${typeof kind === "string" ? `a ${kind}` : printValue(written)}; pass a Polygon of one closed ring, or leave it out to draw a new zone.`);
687
+ const rings = typeof written === "object" && "coordinates" in written ? written.coordinates : void 0;
688
+ if (!Array.isArray(rings) || rings.length === 0) throw new MountayaElementsError(`${owner}: seedGeometry is a Polygon whose coordinates are ${printValue(rings)}; pass one closed ring, or leave seedGeometry out to draw a new zone.`);
689
+ if (rings.length > 1) throw new MountayaElementsError(`${owner}: seedGeometry holds ${rings.length} rings; a zone is one closed ring with no hole. Pass the outer ring alone.`);
690
+ };
691
+ const EDIT_MODE = "linestring";
692
+ const SEGMENT_TERRADRAW_PREFIX = "td-edit";
693
+ const SEGMENT_VERTEX_LAYER_ID = `${SEGMENT_TERRADRAW_PREFIX}-point`;
694
+ const ANALYZE_DEBOUNCE_MS = 300;
695
+ const segmentRefusal = {
696
+ engine: "TerraDrawLinestringSegmentEngine",
697
+ shape: "line"
698
+ };
699
+ const liesOn = (end, pin) => end !== void 0 && pin !== void 0 && samePoint(end, pin);
700
+ const normalizeDraftLine = (line) => {
701
+ const collapsed = [];
702
+ for (const coordinate of line) {
703
+ const previous = collapsed[collapsed.length - 1];
704
+ if (!previous || previous[0] !== coordinate[0] || previous[1] !== coordinate[1]) collapsed.push(coordinate);
705
+ }
706
+ return collapsed;
707
+ };
708
+ const pinFirstCoordinate = (firstCoordinate) => (feature) => {
709
+ const pinned = firstCoordinate();
710
+ if (!pinned) return { valid: true };
711
+ const geometry = feature.geometry;
712
+ if (geometry.type !== "LineString") return { valid: true };
713
+ const head = geometry.coordinates[0];
714
+ if (!head) return {
715
+ reason: "vertex 0 is pinned",
716
+ valid: false
717
+ };
718
+ if (!samePoint(head, pinned)) return {
719
+ reason: "vertex 0 is pinned",
720
+ valid: false
721
+ };
722
+ return { valid: true };
723
+ };
724
+ const pinLastCoordinate = (lastCoordinate) => (feature) => {
725
+ const pinned = lastCoordinate();
726
+ if (!pinned) return { valid: true };
727
+ const geometry = feature.geometry;
728
+ if (geometry.type !== "LineString") return { valid: true };
729
+ const tail = geometry.coordinates.at(-1);
730
+ if (!tail) return {
731
+ reason: "the last vertex is pinned",
732
+ valid: false
733
+ };
734
+ if (!samePoint(tail, pinned)) return {
735
+ reason: "the last vertex is pinned",
736
+ valid: false
737
+ };
738
+ return { valid: true };
739
+ };
740
+ const bothBoundariesPinned = (first, last) => (feature) => {
741
+ const head = first(feature);
742
+ if (!head.valid) return head;
743
+ return last(feature);
744
+ };
745
+ const defaultSegmentDrawFactory = ({ map, prefixId, validation }) => new TerraDraw({
746
+ adapter: new FramedMapLibreAdapter({
747
+ map,
748
+ prefixId
749
+ }, { longitude: 0 }),
750
+ idStrategy: drawIdStrategy,
751
+ modes: [new TerraDrawLineStringMode({ validation }), new TerraDrawSelectMode({
752
+ allowManualDeselection: false,
753
+ flags: { [EDIT_MODE]: { feature: {
754
+ coordinates: {
755
+ deletable: false,
756
+ draggable: true,
757
+ midpoints: true
758
+ },
759
+ draggable: false,
760
+ validation
761
+ } } },
762
+ keyEvents: null
763
+ })]
764
+ });
765
+ var TerraDrawLinestringSegmentEngine = class {
766
+ map;
767
+ emitDraft;
768
+ emitViaPrompt;
769
+ draw;
770
+ featureId;
771
+ pinnedFirst;
772
+ pinnedLast;
773
+ firstPinAtOpen;
774
+ lastPinAtOpen;
775
+ chainSeedPin;
776
+ interactiveWrite = false;
777
+ gestureConsumed = false;
778
+ gestureOpen = false;
779
+ changeHandler;
780
+ finishHandler;
781
+ detachedLine = null;
782
+ detached = false;
783
+ heldDraft;
784
+ disposed = false;
785
+ color;
786
+ events;
787
+ cursor;
788
+ detachVertexCursor = null;
789
+ detachClickInsert = null;
790
+ detachVertexPrompt = null;
791
+ viaPromptPending = false;
792
+ detachCursorReassert = null;
793
+ analyzeFn;
794
+ activitySlug;
795
+ lastRoute = null;
796
+ analyzeTimer = null;
797
+ analyzeToken = 0;
798
+ analyzeController = null;
799
+ analyzeFaultReported = false;
800
+ constructor(map, events, cursor, options, emitDraft, emitViaPrompt, createDraw = defaultSegmentDrawFactory) {
801
+ this.map = map;
802
+ this.emitDraft = emitDraft;
803
+ this.emitViaPrompt = emitViaPrompt;
804
+ this.events = events;
805
+ this.cursor = cursor;
806
+ this.featureId = options.featureId;
807
+ this.color = readEditColor(options.color, segmentRefusal.engine);
808
+ this.analyzeFn = options.analyzeFn ?? null;
809
+ this.activitySlug = options.activitySlug ?? "";
810
+ const seed = (options.seedVias ?? []).map(clampCoordinatePrecision);
811
+ const rawStartPin = options.pinnedStart;
812
+ const rawEndPin = options.pinnedEnd;
813
+ const startPin = rawStartPin ? clampCoordinatePrecision(rawStartPin) : void 0;
814
+ const endPin = rawEndPin ? clampCoordinatePrecision(rawEndPin) : void 0;
815
+ refuseSegmentSeed(options, segmentRefusal.engine);
816
+ this.pinnedFirst = startPin;
817
+ this.pinnedLast = endPin;
818
+ this.firstPinAtOpen = startPin;
819
+ this.lastPinAtOpen = endPin;
820
+ if (seed.length >= 2) this.chainSeedPin = void 0;
821
+ else this.chainSeedPin = startPin ?? endPin;
822
+ this.changeHandler = (ids, _type, context) => {
823
+ if (context?.target === "properties") return;
824
+ this.handleChange(ids, isProgrammaticChange(context));
825
+ };
826
+ this.finishHandler = (id) => {
827
+ this.handleFinish(id);
828
+ };
829
+ const validation = bothBoundariesPinned(pinFirstCoordinate(() => this.pinnedFirst), pinLastCoordinate(() => this.pinnedLast));
830
+ this.draw = createDraw({
831
+ map: this.map,
832
+ prefixId: SEGMENT_TERRADRAW_PREFIX,
833
+ validation
834
+ });
835
+ this.detachClickInsert = this.attachClickInsert();
836
+ this.detachVertexPrompt = this.attachVertexPrompt();
837
+ this.draw.start();
838
+ this.draw.on("change", this.changeHandler);
839
+ this.draw.on("finish", this.finishHandler);
840
+ this.draw.setMode(SELECT_MODE);
841
+ try {
842
+ if (seed.length >= 2) this.seedFeature(seed);
843
+ else if (this.chainSeedPin) this.seedFeature([this.chainSeedPin, this.chainSeedPin]);
844
+ } catch (error) {
845
+ this.dispose();
846
+ throw error;
847
+ }
848
+ this.applySegmentDraftStyle(this.color);
849
+ this.detachVertexCursor = this.attachVertexCursor();
850
+ this.detachCursorReassert = attachCursorReassert(this.events, this.cursor);
851
+ if (seed.length >= 2) this.scheduleAnalyze();
852
+ }
853
+ setDraftStyle(style) {
854
+ if (this.disposed) return;
855
+ this.color = readEditColor(style.color, segmentRefusal.engine);
856
+ if (this.detached) return;
857
+ this.applySegmentDraftStyle(this.color);
858
+ }
859
+ setViaPromptPending(pending) {
860
+ if (this.disposed) return;
861
+ if (this.viaPromptPending === pending) return;
862
+ this.viaPromptPending = pending;
863
+ if (pending) {
864
+ this.detachClickInsert?.();
865
+ this.detachClickInsert = null;
866
+ return;
867
+ }
868
+ this.detachClickInsert ??= this.attachClickInsert();
869
+ }
870
+ readDraft() {
871
+ if (this.disposed) return null;
872
+ if (this.detached) {
873
+ const line = this.heldDraft === void 0 ? this.detachedLine : this.lineForDraft(this.heldDraft);
874
+ return line === null ? null : copyPositions(line);
875
+ }
876
+ return this.currentLine();
877
+ }
878
+ applyDraft(draft) {
879
+ if (this.disposed) return;
880
+ const coordinates = draft.map(clampCoordinatePrecision);
881
+ if (this.detached) {
882
+ this.heldDraft = coordinates;
883
+ return;
884
+ }
885
+ const lastRoute = this.lastRoute;
886
+ this.lastRoute = null;
887
+ const pinnedFirst = this.pinnedFirst;
888
+ const pinnedLast = this.pinnedLast;
889
+ try {
890
+ this.writeDraft(coordinates);
891
+ } catch (error) {
892
+ this.pinnedFirst = pinnedFirst;
893
+ this.pinnedLast = pinnedLast;
894
+ this.lastRoute = lastRoute;
895
+ throw error;
896
+ }
897
+ }
898
+ lineForDraft(coordinates) {
899
+ if (coordinates.length >= 2) return coordinates;
900
+ const head = coordinates[0] ?? this.chainSeedPin;
901
+ return head === void 0 ? null : [head, head];
902
+ }
903
+ writeDraft(coordinates) {
904
+ const line = this.lineForDraft(coordinates);
905
+ if (coordinates.length === 0 && this.draw.getSnapshotFeature(this.featureId)) this.draw.removeFeatures([this.featureId]);
906
+ if (line === null) return;
907
+ const head = line[0];
908
+ if (this.pinnedFirst !== void 0 || liesOn(head, this.firstPinAtOpen)) this.pinnedFirst = head;
909
+ const tail = line.at(-1);
910
+ if (this.pinnedLast !== void 0 || liesOn(tail, this.lastPinAtOpen)) this.pinnedLast = tail;
911
+ this.writeOrSeedLine(line);
912
+ }
913
+ dispose() {
914
+ this.detachCursorReassert?.();
915
+ this.detachCursorReassert = null;
916
+ this.detachVertexCursor?.();
917
+ this.detachVertexCursor = null;
918
+ this.cursor.popOverride();
919
+ this.detachClickInsert?.();
920
+ this.detachClickInsert = null;
921
+ this.detachVertexPrompt?.();
922
+ this.detachVertexPrompt = null;
923
+ this.cancelAnalyze();
924
+ this.analyzeToken += 1;
925
+ this.lastRoute = null;
926
+ this.draw.off("change", this.changeHandler);
927
+ this.draw.off("finish", this.finishHandler);
928
+ if (this.draw.enabled) this.draw.clear();
929
+ this.draw.stop();
930
+ this.disposed = true;
931
+ this.heldDraft = void 0;
932
+ this.detachedLine = null;
933
+ }
934
+ detachBeforeStyleReload() {
935
+ if (this.disposed) return;
936
+ if (this.detached) return;
937
+ this.detached = true;
938
+ this.detachedLine = this.currentLine();
939
+ this.draw.off("change", this.changeHandler);
940
+ this.draw.off("finish", this.finishHandler);
941
+ this.draw.stop();
942
+ }
943
+ replayAfterStyleReload() {
944
+ if (this.disposed) return;
945
+ const line = this.detachedLine ?? this.currentLine();
946
+ this.detachedLine = null;
947
+ this.detached = false;
948
+ this.detachClickInsert?.();
949
+ this.detachClickInsert = this.viaPromptPending ? null : this.attachClickInsert();
950
+ this.detachVertexPrompt?.();
951
+ this.detachVertexPrompt = this.attachVertexPrompt();
952
+ this.draw.off("change", this.changeHandler);
953
+ this.draw.off("finish", this.finishHandler);
954
+ this.draw.start();
955
+ this.draw.on("change", this.changeHandler);
956
+ this.draw.on("finish", this.finishHandler);
957
+ this.draw.setMode(SELECT_MODE);
958
+ if (line) {
959
+ this.draw.clear();
960
+ this.seedFeature(line);
961
+ }
962
+ this.applySegmentDraftStyle(this.color);
963
+ this.detachVertexCursor?.();
964
+ this.detachVertexCursor = this.attachVertexCursor();
965
+ this.detachCursorReassert?.();
966
+ this.detachCursorReassert = attachCursorReassert(this.events, this.cursor);
967
+ const held = this.heldDraft;
968
+ this.heldDraft = void 0;
969
+ if (held !== void 0) applyHeldWrite(() => this.applyDraft(held));
970
+ }
971
+ handleChange(ids, apiOrigin) {
972
+ if (!ids.includes(this.featureId)) return;
973
+ const programmatic = apiOrigin && !this.interactiveWrite;
974
+ const phase = apiOrigin ? "settled" : "live";
975
+ if (!programmatic) this.gestureConsumed = true;
976
+ this.gestureOpen = phase === "live";
977
+ const line = normalizeDraftLine(this.currentLine() ?? []);
978
+ if (line.length < 2) {
979
+ this.lastRoute = null;
980
+ this.cancelAnalyze();
981
+ this.analyzeToken += 1;
982
+ notifyListeners([this.emitDraft], {
983
+ phase,
984
+ programmatic,
985
+ route: null,
986
+ vias: line
987
+ });
988
+ return;
989
+ }
990
+ notifyListeners([this.emitDraft], {
991
+ phase,
992
+ programmatic,
993
+ route: this.lastRoute,
994
+ vias: line
995
+ });
996
+ this.scheduleAnalyze();
997
+ }
998
+ handleFinish(id) {
999
+ if (id !== this.featureId || !this.gestureOpen) return;
1000
+ this.gestureOpen = false;
1001
+ const line = normalizeDraftLine(this.currentLine() ?? []);
1002
+ const route = line.length < 2 ? null : this.lastRoute;
1003
+ notifyListeners([this.emitDraft], {
1004
+ phase: "settled",
1005
+ programmatic: false,
1006
+ route,
1007
+ vias: line
1008
+ });
1009
+ }
1010
+ scheduleAnalyze() {
1011
+ if (!this.analyzeFn) return;
1012
+ this.cancelAnalyze();
1013
+ this.analyzeToken += 1;
1014
+ const token = this.analyzeToken;
1015
+ this.analyzeTimer = setTimeout(() => {
1016
+ this.analyzeTimer = null;
1017
+ const analyze = this.analyzeFn;
1018
+ if (!analyze) return;
1019
+ const controller = new AbortController();
1020
+ this.analyzeController = controller;
1021
+ const line = normalizeDraftLine(this.currentLine() ?? []);
1022
+ (async () => analyze(this.activitySlug, line, { signal: controller.signal }))().then((route) => {
1023
+ if (token !== this.analyzeToken) return;
1024
+ this.lastRoute = route;
1025
+ notifyListeners([this.emitDraft], {
1026
+ phase: "settled",
1027
+ programmatic: true,
1028
+ route,
1029
+ vias: this.currentLine() ?? line
1030
+ });
1031
+ }, (fault) => {
1032
+ if (token === this.analyzeToken) this.warnOnAnalyzeFault(fault);
1033
+ });
1034
+ }, ANALYZE_DEBOUNCE_MS);
1035
+ }
1036
+ warnOnAnalyzeFault(fault) {
1037
+ if (this.analyzeFaultReported || !inDevelopment()) return;
1038
+ this.analyzeFaultReported = true;
1039
+ console.warn("[@mountaya/elements] TerraDrawLinestringSegmentEngine: analyzeFn threw, so the edit shows no fresh profile for this line. An analyzer that finds none resolves to null; one that throws or rejects is read the same way and the edit stays open. The error it threw follows.", fault);
1040
+ }
1041
+ cancelAnalyze() {
1042
+ if (this.analyzeTimer !== null) {
1043
+ clearTimeout(this.analyzeTimer);
1044
+ this.analyzeTimer = null;
1045
+ }
1046
+ this.analyzeController?.abort();
1047
+ this.analyzeController = null;
1048
+ }
1049
+ seedFeature(coordinates) {
1050
+ const feature = {
1051
+ geometry: {
1052
+ coordinates,
1053
+ type: "LineString"
1054
+ },
1055
+ id: this.featureId,
1056
+ properties: { mode: EDIT_MODE },
1057
+ type: "Feature"
1058
+ };
1059
+ addDrawFeature(this.draw, feature, segmentRefusal);
1060
+ this.draw.setMode(SELECT_MODE);
1061
+ this.draw.selectFeature(this.featureId);
1062
+ }
1063
+ writeOrSeedLine(coordinates) {
1064
+ if (this.draw.getSnapshotFeature(this.featureId)) updateDrawGeometry(this.draw, this.featureId, {
1065
+ coordinates,
1066
+ type: "LineString"
1067
+ }, segmentRefusal);
1068
+ else this.seedFeature(coordinates);
1069
+ }
1070
+ applySegmentDraftStyle(hex) {
1071
+ this.draw.updateModeOptions(EDIT_MODE, { styles: {
1072
+ coordinatePointColor: hex,
1073
+ lineStringColor: hex,
1074
+ lineStringWidth: 4
1075
+ } });
1076
+ this.draw.updateModeOptions(SELECT_MODE, { styles: {
1077
+ midPointColor: hex,
1078
+ selectedLineStringColor: hex,
1079
+ selectedPointColor: hex,
1080
+ selectionPointColor: hex
1081
+ } });
1082
+ }
1083
+ currentLine() {
1084
+ return this.lineOf(this.featureId);
1085
+ }
1086
+ lineOf(id) {
1087
+ const feature = this.draw.getSnapshotFeature(id);
1088
+ if (feature?.geometry.type !== "LineString") return null;
1089
+ return feature.geometry.coordinates;
1090
+ }
1091
+ attachVertexCursor() {
1092
+ return attachEditHoverCursor({
1093
+ cursor: this.cursor,
1094
+ events: this.events,
1095
+ layers: [{
1096
+ kind: "handle",
1097
+ layerId: SEGMENT_VERTEX_LAYER_ID,
1098
+ midpointProperty: TERRA_DRAW_MID_POINT_PROPERTY
1099
+ }],
1100
+ map: this.map
1101
+ });
1102
+ }
1103
+ attachClickInsert() {
1104
+ const onDown = () => {
1105
+ this.gestureConsumed = false;
1106
+ };
1107
+ const onClick = (event) => {
1108
+ if (this.gestureConsumed || this.detached) return;
1109
+ const clickLngLat = pointerPosition(event.lngLat);
1110
+ const line = this.currentLine() ?? [];
1111
+ const vertex = nearestVertex({
1112
+ line,
1113
+ lngLat: clickLngLat,
1114
+ map: this.map
1115
+ });
1116
+ if (vertex.distancePx < 40) {
1117
+ this.promptForVertex(line, vertex.index);
1118
+ this.consumeClick(event);
1119
+ return;
1120
+ }
1121
+ if (line.length === 0) {
1122
+ this.pinnedFirst = void 0;
1123
+ this.pinnedLast = void 0;
1124
+ this.runInteractiveWrite(() => this.seedFeature([clickLngLat, clickLngLat]));
1125
+ this.consumeClick(event);
1126
+ return;
1127
+ }
1128
+ if (normalizeDraftLine(line).length < 2) {
1129
+ const pin = line[0] ?? clickLngLat;
1130
+ const coordinates = this.pinnedLast !== void 0 ? [clickLngLat, pin] : [pin, clickLngLat];
1131
+ this.runInteractiveWrite(() => updateDrawGeometry(this.draw, this.featureId, {
1132
+ coordinates,
1133
+ type: "LineString"
1134
+ }, segmentRefusal));
1135
+ this.consumeClick(event);
1136
+ return;
1137
+ }
1138
+ const insertion = nearestEdgeInsertion({
1139
+ line,
1140
+ lngLat: clickLngLat,
1141
+ map: this.map,
1142
+ thresholdPx: 40
1143
+ });
1144
+ const next = [...line];
1145
+ if (insertion) next.splice(insertion.index, 0, insertion.lngLat);
1146
+ else if (this.pinnedLast !== void 0) next.splice(next.length - 1, 0, clickLngLat);
1147
+ else next.push(clickLngLat);
1148
+ this.runInteractiveWrite(() => updateDrawGeometry(this.draw, this.featureId, {
1149
+ coordinates: next,
1150
+ type: "LineString"
1151
+ }, segmentRefusal));
1152
+ this.consumeClick(event);
1153
+ };
1154
+ const detachClick = this.events.on("click", onClick);
1155
+ const detachDown = this.events.on("mousedown", onDown);
1156
+ return () => {
1157
+ detachClick();
1158
+ detachDown();
1159
+ };
1160
+ }
1161
+ attachVertexPrompt() {
1162
+ return this.events.on("contextmenu", (event) => {
1163
+ const lngLat = pointerPosition(event.lngLat);
1164
+ const line = this.currentLine() ?? [];
1165
+ const vertex = nearestVertex({
1166
+ line,
1167
+ lngLat,
1168
+ map: this.map
1169
+ });
1170
+ if (vertex.distancePx >= 40) return;
1171
+ this.promptForVertex(line, vertex.index);
1172
+ this.consumeClick(event);
1173
+ });
1174
+ }
1175
+ promptForVertex(line, index) {
1176
+ const vertex = line[index];
1177
+ if (!vertex) return;
1178
+ notifyListeners([this.emitViaPrompt], {
1179
+ index,
1180
+ lngLat: [vertex[0] ?? 0, vertex[1] ?? 0]
1181
+ });
1182
+ }
1183
+ runInteractiveWrite(write) {
1184
+ this.interactiveWrite = true;
1185
+ try {
1186
+ write();
1187
+ } finally {
1188
+ this.interactiveWrite = false;
1189
+ }
1190
+ }
1191
+ consumeClick(event) {
1192
+ event.preventDefault();
1193
+ const originalEvent = event.originalEvent;
1194
+ if (originalEvent && typeof originalEvent.stopPropagation === "function") originalEvent.stopPropagation();
1195
+ }
1196
+ };
1197
+ const DRAFT_SOURCE = "td-waypoint-draft-source";
1198
+ const DRAFT_LAYER = "td-waypoint-draft-layer";
1199
+ var DraftWaypointMarker = class {
1200
+ map;
1201
+ placement;
1202
+ lastSnapshot = null;
1203
+ constructor(map, placement) {
1204
+ this.map = map;
1205
+ this.placement = placement;
1206
+ }
1207
+ apply(snapshot) {
1208
+ this.lastSnapshot = snapshot;
1209
+ const data = {
1210
+ geometry: {
1211
+ coordinates: snapshot.lngLat,
1212
+ type: "Point"
1213
+ },
1214
+ properties: {},
1215
+ type: "Feature"
1216
+ };
1217
+ const existing = this.map.getSource(DRAFT_SOURCE);
1218
+ if (isGeoJsonSource(existing)) {
1219
+ existing.setData(data);
1220
+ this.ensureLayerIcon(snapshot);
1221
+ return;
1222
+ }
1223
+ this.map.addSource(DRAFT_SOURCE, {
1224
+ data,
1225
+ type: "geojson"
1226
+ });
1227
+ this.placement.addLayerOrdered({
1228
+ id: DRAFT_LAYER,
1229
+ layout: {
1230
+ "icon-allow-overlap": true,
1231
+ "icon-ignore-placement": true,
1232
+ "icon-image": waypointIconImageId(snapshot.icon, snapshot.color),
1233
+ "icon-size": .7
1234
+ },
1235
+ source: DRAFT_SOURCE,
1236
+ type: "symbol"
1237
+ }, 100);
1238
+ }
1239
+ setStyle(style) {
1240
+ if (!this.lastSnapshot) return;
1241
+ this.lastSnapshot = {
1242
+ ...this.lastSnapshot,
1243
+ ...style
1244
+ };
1245
+ this.ensureLayerIcon(this.lastSnapshot);
1246
+ }
1247
+ clear() {
1248
+ this.placement.forgetLayerRank(DRAFT_LAYER);
1249
+ if (this.map.getSource(DRAFT_SOURCE)) this.map.removeSource(DRAFT_SOURCE);
1250
+ this.lastSnapshot = null;
1251
+ }
1252
+ replay() {
1253
+ if (!this.lastSnapshot) return;
1254
+ const snapshot = this.lastSnapshot;
1255
+ this.lastSnapshot = null;
1256
+ this.apply(snapshot);
1257
+ }
1258
+ read() {
1259
+ return this.lastSnapshot;
1260
+ }
1261
+ ensureLayerIcon(snapshot) {
1262
+ if (!this.map.getLayer(DRAFT_LAYER)) return;
1263
+ this.map.setLayoutProperty(DRAFT_LAYER, "icon-image", waypointIconImageId(snapshot.icon, snapshot.color));
1264
+ }
1265
+ };
1266
+ const PROJECTION_PROBE_OFFSET_DEG = .001;
1267
+ const snapCameraKey = (map) => {
1268
+ const center = map.getCenter();
1269
+ const canvas = map.getCanvas();
1270
+ const at = map.project(center);
1271
+ const beside = map.project({
1272
+ lat: center.lat + PROJECTION_PROBE_OFFSET_DEG,
1273
+ lng: center.lng + PROJECTION_PROBE_OFFSET_DEG
1274
+ });
1275
+ return `${map.getZoom()}|${center.lng}|${center.lat}|${map.getBearing()}|${map.getPitch()}|${canvas.width}|${canvas.height}|${at.x}|${at.y}|${beside.x}|${beside.y}`;
1276
+ };
1277
+ const svgElementOf = (owner, node) => {
1278
+ const element = owner.createElementNS(SVG_NAMESPACE, node.tag);
1279
+ for (const [name, value] of Object.entries(node.attributes)) element.setAttribute(name, value);
1280
+ for (const child of node.children ?? []) element.append(svgElementOf(owner, child));
1281
+ return element;
1282
+ };
1283
+ var PointerWaypointCursor = class {
1284
+ map;
1285
+ options;
1286
+ node;
1287
+ currentStyle;
1288
+ mounted = false;
1289
+ constructor(map, initial, options) {
1290
+ this.map = map;
1291
+ this.options = options;
1292
+ this.currentStyle = initial;
1293
+ this.node = document.createElement("div");
1294
+ this.paint();
1295
+ Object.assign(this.node.style, {
1296
+ height: `${options.size}px`,
1297
+ left: "0",
1298
+ pointerEvents: "none",
1299
+ position: "absolute",
1300
+ top: "0",
1301
+ transform: "translate3d(-9999px, -9999px, 0)",
1302
+ visibility: "visible",
1303
+ width: `${options.size}px`,
1304
+ willChange: "transform",
1305
+ zIndex: "5"
1306
+ });
1307
+ }
1308
+ attach() {
1309
+ if (this.mounted) return;
1310
+ this.map.getCanvasContainer().appendChild(this.node);
1311
+ this.mounted = true;
1312
+ }
1313
+ setStyle(style) {
1314
+ this.currentStyle = style;
1315
+ this.paint();
1316
+ }
1317
+ setPosition(point) {
1318
+ const half = this.options.size / 2;
1319
+ this.node.style.transform = `translate3d(${point.x - half}px, ${point.y - half}px, 0)`;
1320
+ }
1321
+ setVisible(visible) {
1322
+ this.node.style.visibility = visible ? "visible" : "hidden";
1323
+ }
1324
+ dispose() {
1325
+ if (!this.mounted) return;
1326
+ this.node.remove();
1327
+ this.mounted = false;
1328
+ }
1329
+ paint() {
1330
+ const drawing = describeWaypointSvg({
1331
+ ...this.currentStyle,
1332
+ ...this.options
1333
+ }, "PointerWaypointCursor");
1334
+ this.node.replaceChildren(svgElementOf(this.node.ownerDocument, drawing));
1335
+ }
1336
+ };
1337
+ var ScreenSpaceSnapIndex = class {
1338
+ cachedCameraKey = null;
1339
+ cachedLineRefs = [];
1340
+ cachedLines = [];
1341
+ snap(input) {
1342
+ const { cameraKey, lngLat, map, segments, thresholdPx } = input;
1343
+ if (segments.length === 0) return {
1344
+ lngLat,
1345
+ snapped: false
1346
+ };
1347
+ this.ensureBuilt(cameraKey, map, segments);
1348
+ const cursorPx = map.project({
1349
+ lat: lngLat[1] ?? 0,
1350
+ lng: lngLat[0] ?? 0
1351
+ });
1352
+ let bestDistSq = Number.POSITIVE_INFINITY;
1353
+ let bestPx = null;
1354
+ for (const line of this.cachedLines) {
1355
+ if (!line.hasBbox) continue;
1356
+ if (cursorPx.x < line.bbox.minX - thresholdPx || cursorPx.x > line.bbox.maxX + thresholdPx || cursorPx.y < line.bbox.minY - thresholdPx || cursorPx.y > line.bbox.maxY + thresholdPx) continue;
1357
+ const { pixels, valid } = line;
1358
+ const count = valid.length;
1359
+ for (let i = 1; i < count; i++) {
1360
+ if (valid[i - 1] === 0 || valid[i] === 0) continue;
1361
+ const a = {
1362
+ x: pixels[(i - 1) * 2] ?? 0,
1363
+ y: pixels[(i - 1) * 2 + 1] ?? 0
1364
+ };
1365
+ const b = {
1366
+ x: pixels[i * 2] ?? 0,
1367
+ y: pixels[i * 2 + 1] ?? 0
1368
+ };
1369
+ const projected = projectPointToSegmentPx(cursorPx, a, b);
1370
+ const distSq = sqDist(cursorPx, projected);
1371
+ if (distSq < bestDistSq) {
1372
+ bestDistSq = distSq;
1373
+ bestPx = projected;
1374
+ }
1375
+ }
1376
+ }
1377
+ if (bestPx === null || bestDistSq > thresholdPx * thresholdPx) return {
1378
+ lngLat,
1379
+ snapped: false
1380
+ };
1381
+ const snapped = map.unproject([bestPx.x, bestPx.y]);
1382
+ return {
1383
+ lngLat: [snapped.lng, snapped.lat],
1384
+ snapped: true
1385
+ };
1386
+ }
1387
+ ensureBuilt(cameraKey, map, segments) {
1388
+ if (this.cachedCameraKey === cameraKey && this.lineRefsMatch(segments)) return;
1389
+ this.build(cameraKey, map, segments);
1390
+ }
1391
+ lineRefsMatch(segments) {
1392
+ if (segments.length !== this.cachedLineRefs.length) return false;
1393
+ for (let i = 0; i < segments.length; i++) if (segments[i] !== this.cachedLineRefs[i]) return false;
1394
+ return true;
1395
+ }
1396
+ build(cameraKey, map, segments) {
1397
+ const lines = [];
1398
+ for (const line of segments) {
1399
+ const length = line.length;
1400
+ const pixels = new Float64Array(length * 2);
1401
+ const valid = new Uint8Array(length);
1402
+ let minX = Number.POSITIVE_INFINITY;
1403
+ let minY = Number.POSITIVE_INFINITY;
1404
+ let maxX = Number.NEGATIVE_INFINITY;
1405
+ let maxY = Number.NEGATIVE_INFINITY;
1406
+ let validCount = 0;
1407
+ for (let i = 0; i < length; i++) {
1408
+ const coord = line[i];
1409
+ if (!coord) continue;
1410
+ const px = map.project({
1411
+ lat: coord[1] ?? 0,
1412
+ lng: coord[0] ?? 0
1413
+ });
1414
+ pixels[i * 2] = px.x;
1415
+ pixels[i * 2 + 1] = px.y;
1416
+ valid[i] = 1;
1417
+ validCount++;
1418
+ if (px.x < minX) minX = px.x;
1419
+ if (px.x > maxX) maxX = px.x;
1420
+ if (px.y < minY) minY = px.y;
1421
+ if (px.y > maxY) maxY = px.y;
1422
+ }
1423
+ const hasBbox = validCount >= 2;
1424
+ lines.push({
1425
+ bbox: {
1426
+ maxX,
1427
+ maxY,
1428
+ minX,
1429
+ minY
1430
+ },
1431
+ hasBbox,
1432
+ pixels,
1433
+ valid
1434
+ });
1435
+ }
1436
+ this.cachedCameraKey = cameraKey;
1437
+ this.cachedLineRefs = segments.slice();
1438
+ this.cachedLines = lines;
1439
+ }
1440
+ };
1441
+ const POINT_MODE = "point";
1442
+ const WAYPOINT_TERRADRAW_PREFIX = "td-waypoint";
1443
+ const buildWaypointPointMode = () => new TerraDrawPointMode({ styles: {
1444
+ pointOpacity: 0,
1445
+ pointOutlineOpacity: 0
1446
+ } });
1447
+ const defaultWaypointDrawFactory = ({ map, prefixId }) => new TerraDraw({
1448
+ adapter: new FramedMapLibreAdapter({
1449
+ map,
1450
+ prefixId
1451
+ }, { longitude: 0 }),
1452
+ idStrategy: drawIdStrategy,
1453
+ modes: [buildWaypointPointMode()]
1454
+ });
1455
+ var TerraDrawPointWaypointEngine = class {
1456
+ map;
1457
+ emitChange;
1458
+ getSnapSegments;
1459
+ draw;
1460
+ marker;
1461
+ pointerCursor;
1462
+ currentIcon;
1463
+ currentColor;
1464
+ events;
1465
+ cursor;
1466
+ draftFeatureId = null;
1467
+ detachCursorReassert = null;
1468
+ detachPointerMove = null;
1469
+ detachPointerOut = null;
1470
+ detachPointerIn = null;
1471
+ pointerFrame = null;
1472
+ lastPointerEvent = null;
1473
+ snapIndex = new ScreenSpaceSnapIndex();
1474
+ changeHandler;
1475
+ constructor(map, placement, options, emitChange, createDraw = defaultWaypointDrawFactory, getSnapSegments = () => [], events, cursor, pointerCursorOptions) {
1476
+ this.map = map;
1477
+ this.emitChange = emitChange;
1478
+ this.getSnapSegments = getSnapSegments;
1479
+ const initialLngLat = readEditPosition(options.initialLngLat, "TerraDrawPointWaypointEngine", "initialLngLat", "pass null for a waypoint not placed yet");
1480
+ this.currentIcon = options.initialIcon;
1481
+ this.currentColor = options.initialColor;
1482
+ this.events = events ?? null;
1483
+ this.cursor = cursor ?? null;
1484
+ this.pointerCursor = events && pointerCursorOptions ? new PointerWaypointCursor(this.map, {
1485
+ color: this.currentColor,
1486
+ icon: this.currentIcon
1487
+ }, pointerCursorOptions) : null;
1488
+ this.marker = new DraftWaypointMarker(this.map, placement);
1489
+ const validation = () => ({ valid: true });
1490
+ this.draw = createDraw({
1491
+ map: this.map,
1492
+ prefixId: WAYPOINT_TERRADRAW_PREFIX,
1493
+ validation
1494
+ });
1495
+ this.changeHandler = (ids, type, context) => {
1496
+ this.handleChange(ids, type, isProgrammaticChange(context));
1497
+ };
1498
+ this.draw.start();
1499
+ this.draw.setMode(POINT_MODE);
1500
+ this.draw.on("change", this.changeHandler);
1501
+ this.detachCursorReassert = this.attachCursorReassert();
1502
+ if (initialLngLat) this.marker.apply({
1503
+ color: this.currentColor,
1504
+ icon: this.currentIcon,
1505
+ lngLat: initialLngLat
1506
+ });
1507
+ if (events && this.pointerCursor) {
1508
+ this.pointerCursor.attach();
1509
+ this.detachPointerMove = events.on("mousemove", (event) => {
1510
+ this.lastPointerEvent = {
1511
+ lngLat: [event.lngLat.lng, event.lngLat.lat],
1512
+ point: {
1513
+ x: event.point.x,
1514
+ y: event.point.y
1515
+ }
1516
+ };
1517
+ if (this.pointerFrame !== null) return;
1518
+ this.pointerFrame = requestAnimationFrame(() => {
1519
+ this.pointerFrame = null;
1520
+ this.placePointerCursor();
1521
+ });
1522
+ });
1523
+ this.detachPointerOut = events.on("mouseout", () => {
1524
+ this.pointerCursor?.setVisible(false);
1525
+ });
1526
+ this.detachPointerIn = events.on("mouseover", () => {
1527
+ this.pointerCursor?.setVisible(true);
1528
+ });
1529
+ }
1530
+ }
1531
+ setDraftStyle(style) {
1532
+ this.currentColor = style.color;
1533
+ this.currentIcon = style.icon;
1534
+ this.marker.setStyle(style);
1535
+ this.pointerCursor?.setStyle(style);
1536
+ }
1537
+ readDraft() {
1538
+ return this.marker.read();
1539
+ }
1540
+ clearDraft() {
1541
+ this.marker.clear();
1542
+ if (this.draftFeatureId !== null && this.draw.enabled) this.draw.removeFeatures([this.draftFeatureId]);
1543
+ this.draftFeatureId = null;
1544
+ }
1545
+ applyDraft(snapshot) {
1546
+ this.currentColor = snapshot.color;
1547
+ this.currentIcon = snapshot.icon;
1548
+ this.marker.apply(snapshot);
1549
+ this.pointerCursor?.setStyle({
1550
+ color: snapshot.color,
1551
+ icon: snapshot.icon
1552
+ });
1553
+ }
1554
+ dispose() {
1555
+ this.detachCursorReassert?.();
1556
+ this.detachCursorReassert = null;
1557
+ this.detachPointerMove?.();
1558
+ this.detachPointerMove = null;
1559
+ this.detachPointerOut?.();
1560
+ this.detachPointerOut = null;
1561
+ this.detachPointerIn?.();
1562
+ this.detachPointerIn = null;
1563
+ if (this.pointerFrame !== null) {
1564
+ cancelAnimationFrame(this.pointerFrame);
1565
+ this.pointerFrame = null;
1566
+ }
1567
+ this.lastPointerEvent = null;
1568
+ this.pointerCursor?.dispose();
1569
+ this.marker.clear();
1570
+ this.draw.off("change", this.changeHandler);
1571
+ if (this.draw.enabled) this.draw.clear();
1572
+ this.draw.stop();
1573
+ }
1574
+ detachBeforeStyleReload() {
1575
+ this.draw.off("change", this.changeHandler);
1576
+ this.draw.stop();
1577
+ this.draftFeatureId = null;
1578
+ }
1579
+ replayAfterStyleReload() {
1580
+ this.draw.start();
1581
+ this.draw.setMode(POINT_MODE);
1582
+ this.draw.on("change", this.changeHandler);
1583
+ this.marker.replay();
1584
+ this.pointerCursor?.attach();
1585
+ this.detachCursorReassert?.();
1586
+ this.detachCursorReassert = this.attachCursorReassert();
1587
+ }
1588
+ handleChange(ids, type, programmatic) {
1589
+ if (programmatic) return;
1590
+ if (type !== "create") return;
1591
+ const id = ids[0];
1592
+ if (id === void 0) return;
1593
+ const feature = this.draw.getSnapshotFeature(id);
1594
+ if (feature?.geometry.type !== "Point") return;
1595
+ const [lng, lat] = feature.geometry.coordinates;
1596
+ const rawLngLat = pointerPosition({
1597
+ lat: lat ?? 0,
1598
+ lng: lng ?? 0
1599
+ });
1600
+ const snap = this.snapOnto(rawLngLat);
1601
+ const lngLat = [snap.lngLat[0] ?? 0, snap.lngLat[1] ?? 0];
1602
+ if (this.draftFeatureId !== null && this.draftFeatureId !== id) this.draw.removeFeatures([this.draftFeatureId]);
1603
+ this.draftFeatureId = id;
1604
+ this.marker.apply({
1605
+ color: this.currentColor,
1606
+ icon: this.currentIcon,
1607
+ lngLat
1608
+ });
1609
+ notifyListeners([this.emitChange], {
1610
+ lngLat,
1611
+ poiSeed: null
1612
+ });
1613
+ }
1614
+ placePointerCursor() {
1615
+ const latest = this.lastPointerEvent;
1616
+ if (!latest || !this.pointerCursor) return;
1617
+ const [pointerLng, pointerLat] = latest.lngLat;
1618
+ const snap = this.snapOnto(pointerPosition({
1619
+ lat: pointerLat,
1620
+ lng: pointerLng
1621
+ }));
1622
+ if (snap.snapped) {
1623
+ const footLng = snap.lngLat[0] ?? 0;
1624
+ const target = this.map.project({
1625
+ lat: snap.lngLat[1] ?? 0,
1626
+ lng: footLng + 360 * Math.round((pointerLng - footLng) / 360)
1627
+ });
1628
+ this.pointerCursor.setPosition({
1629
+ x: target.x,
1630
+ y: target.y
1631
+ });
1632
+ return;
1633
+ }
1634
+ this.pointerCursor.setPosition(latest.point);
1635
+ }
1636
+ snapOnto(lngLat) {
1637
+ const segments = this.getSnapSegments();
1638
+ return this.snapIndex.snap({
1639
+ cameraKey: segments.length === 0 ? "" : snapCameraKey(this.map),
1640
+ lngLat,
1641
+ map: this.map,
1642
+ segments,
1643
+ thresholdPx: 40
1644
+ });
1645
+ }
1646
+ attachCursorReassert() {
1647
+ if (!this.events || !this.cursor) return null;
1648
+ return attachCursorReassert(this.events, this.cursor);
1649
+ }
1650
+ };
1651
+ const admitted = { valid: true };
1652
+ const ringOf = (feature) => feature.geometry.type === "Polygon" ? feature.geometry.coordinates[0] ?? null : null;
1653
+ const judged = ({ kind, positions }) => ValidateNotSelfIntersecting({
1654
+ geometry: kind === "ring" ? {
1655
+ coordinates: [positions],
1656
+ type: "Polygon"
1657
+ } : {
1658
+ coordinates: positions,
1659
+ type: "LineString"
1660
+ },
1661
+ properties: {},
1662
+ type: "Feature"
1663
+ });
1664
+ const drawnOnTheMap = ({ kind, positions }) => {
1665
+ const projected = [];
1666
+ for (const [longitude = NaN, latitude = NaN] of positions) {
1667
+ if (Math.abs(latitude) >= 90) return null;
1668
+ const sine = Math.sin(latitude * DEGREES_TO_RADIANS);
1669
+ projected.push([longitude, Math.log((1 + sine) / (1 - sine)) / 2 * RADIANS_TO_DEGREES]);
1670
+ }
1671
+ return {
1672
+ kind,
1673
+ positions: projected
1674
+ };
1675
+ };
1676
+ const onTheMap = (shape) => {
1677
+ const drawn = drawnOnTheMap(shape);
1678
+ return drawn === null ? admitted : judged(drawn);
1679
+ };
1680
+ const crossingOf = (shape) => {
1681
+ const stored = judged(shape);
1682
+ return stored.valid ? onTheMap(shape) : stored;
1683
+ };
1684
+ const drawnOutlineVerdict = (feature, updateType) => {
1685
+ const ring = ringOf(feature);
1686
+ if (ring === null || ring.length > 1e3) return admitted;
1687
+ if (updateType === "finish") return crossingOf({
1688
+ kind: "ring",
1689
+ positions: ring
1690
+ });
1691
+ return crossingOf({
1692
+ kind: "path",
1693
+ positions: ring.slice(0, -1)
1694
+ });
1695
+ };
1696
+ const reshapedOutlineVerdict = (feature, standing, updateType) => {
1697
+ const ring = ringOf(feature);
1698
+ if (ring === null || standing === null || ring.length > 1e3) return admitted;
1699
+ const judge = updateType === "provisional" ? onTheMap : updateType === "commit" && ring.length < standing.length ? crossingOf : null;
1700
+ if (judge === null) return admitted;
1701
+ const verdict = judge({
1702
+ kind: "ring",
1703
+ positions: ring
1704
+ });
1705
+ if (verdict.valid || !judge({
1706
+ kind: "ring",
1707
+ positions: standing
1708
+ }).valid) return admitted;
1709
+ return verdict;
1710
+ };
1711
+ const ZONE_TERRADRAW_PREFIX = "td-zone";
1712
+ const ZONE_VERTEX_LAYER_ID = `${ZONE_TERRADRAW_PREFIX}-point`;
1713
+ const ZONE_FILL_LAYER_ID = `${ZONE_TERRADRAW_PREFIX}-polygon`;
1714
+ const zoneRefusal = {
1715
+ engine: "TerraDrawZoneEngine",
1716
+ remedy: "Pass one closed ring with no hole, of positions of two finite numbers: longitudes within half a turn of each other, continuous across the antimeridian, and latitudes from -90 to 90.",
1717
+ shape: "zone"
1718
+ };
1719
+ const drawablePolygon = (geometry, frameLongitude) => ({
1720
+ coordinates: geometry.coordinates.map((ring) => ring.map((position) => intoFrame(position, frameLongitude))),
1721
+ type: "Polygon"
1722
+ });
1723
+ const worldPolygon = (geometry, frameLongitude) => frameLongitude === 0 ? geometry : {
1724
+ coordinates: geometry.coordinates.map((ring) => ring.map((position) => outOfFrame(position, frameLongitude))),
1725
+ type: "Polygon"
1726
+ };
1727
+ const zoneDrawModeNames = {
1728
+ circle: "circle",
1729
+ freehand: "freehand",
1730
+ polygon: "polygon",
1731
+ sector: "sector",
1732
+ sensor: "sensor"
1733
+ };
1734
+ const buildZoneDrawMode = (mode, validation) => {
1735
+ switch (mode) {
1736
+ case "circle": return new TerraDrawCircleMode();
1737
+ case "polygon": return new TerraDrawPolygonMode({
1738
+ editable: true,
1739
+ validation
1740
+ });
1741
+ case "sector": return new TerraDrawSectorMode();
1742
+ case "sensor": return new TerraDrawSensorMode();
1743
+ case "freehand": return new TerraDrawFreehandMode({ validation });
1744
+ }
1745
+ };
1746
+ const buildZoneSelectFlags = (mode, validation) => ({ [zoneDrawModeNames[mode]]: { feature: {
1747
+ coordinates: {
1748
+ deletable: true,
1749
+ draggable: true,
1750
+ midpoints: true
1751
+ },
1752
+ draggable: true,
1753
+ validation
1754
+ } } });
1755
+ const defaultZoneDrawFactory = ({ frame, map, mode, prefixId, validation }) => new TerraDraw({
1756
+ adapter: new FramedMapLibreAdapter({
1757
+ map,
1758
+ prefixId
1759
+ }, frame),
1760
+ idStrategy: drawIdStrategy,
1761
+ modes: [buildZoneDrawMode(mode, validation.draw), new TerraDrawSelectMode({ flags: buildZoneSelectFlags(mode, validation.reshape) })]
1762
+ });
1763
+ var TerraDrawZoneEngine = class {
1764
+ map;
1765
+ emitDraft;
1766
+ draw;
1767
+ featureId;
1768
+ activeFeatureId;
1769
+ drawCompleted = false;
1770
+ gestureOpen = false;
1771
+ mode;
1772
+ drawModeName;
1773
+ color;
1774
+ events;
1775
+ cursor;
1776
+ detachHoverCursor = null;
1777
+ detachCursorReassert = null;
1778
+ changeHandler;
1779
+ finishHandler;
1780
+ detachedGeometry = null;
1781
+ detached = false;
1782
+ heldDraft;
1783
+ disposed = false;
1784
+ frame = { longitude: 0 };
1785
+ detachFrameFollow = null;
1786
+ writing = false;
1787
+ refused = false;
1788
+ onOutlineRefusedChange;
1789
+ constructor(map, options, emitDraft, createDraw = defaultZoneDrawFactory, events, cursor) {
1790
+ this.map = map;
1791
+ this.emitDraft = emitDraft;
1792
+ this.featureId = options.featureId;
1793
+ this.activeFeatureId = options.featureId;
1794
+ this.mode = options.mode;
1795
+ this.drawModeName = zoneDrawModeNames[options.mode];
1796
+ this.color = readEditColor(options.color, zoneRefusal.engine);
1797
+ this.onOutlineRefusedChange = options.onOutlineRefusedChange ?? null;
1798
+ this.events = events ?? null;
1799
+ this.cursor = cursor ?? null;
1800
+ this.changeHandler = (ids, type, context) => {
1801
+ if (context?.target === "properties") return;
1802
+ this.handleChange(ids, type, isProgrammaticChange(context));
1803
+ };
1804
+ this.finishHandler = (id) => {
1805
+ this.handleFinish(id);
1806
+ };
1807
+ refuseZoneSeed(options, zoneRefusal.engine);
1808
+ this.draw = createDraw({
1809
+ frame: this.frame,
1810
+ map: this.map,
1811
+ mode: options.mode,
1812
+ prefixId: ZONE_TERRADRAW_PREFIX,
1813
+ validation: {
1814
+ draw: (feature, { updateType }) => this.writing ? { valid: true } : this.heard(drawnOutlineVerdict(feature, updateType)),
1815
+ reshape: (feature, { updateType }) => {
1816
+ const verdict = reshapedOutlineVerdict(feature, this.standingRing(), updateType);
1817
+ return updateType === "provisional" && !verdict.valid ? verdict : this.heard(verdict);
1818
+ }
1819
+ }
1820
+ });
1821
+ this.draw.start();
1822
+ this.attachDrawListeners();
1823
+ if (options.seedGeometry) try {
1824
+ this.seedFeature(options.seedGeometry);
1825
+ } catch (error) {
1826
+ this.dispose();
1827
+ throw error;
1828
+ }
1829
+ else {
1830
+ this.frameOnMapCenter();
1831
+ this.draw.setMode(this.drawModeName);
1832
+ }
1833
+ this.detachFrameFollow = this.events?.on("moveend", () => this.followMap()) ?? null;
1834
+ this.applyZoneDraftStyle(this.color);
1835
+ this.detachHoverCursor = this.attachHoverCursor();
1836
+ this.detachCursorReassert = this.attachCursorReassert();
1837
+ }
1838
+ setDraftStyle(style) {
1839
+ if (this.disposed) return;
1840
+ this.color = readEditColor(style.color, zoneRefusal.engine);
1841
+ if (this.detached) return;
1842
+ this.applyZoneDraftStyle(this.color);
1843
+ }
1844
+ readDraft() {
1845
+ if (this.disposed) return null;
1846
+ if (this.detached) {
1847
+ const held = this.heldDraft ?? this.detachedGeometry;
1848
+ return held === null ? null : {
1849
+ coordinates: held.coordinates.map(copyPositions),
1850
+ type: "Polygon"
1851
+ };
1852
+ }
1853
+ return this.currentGeometry();
1854
+ }
1855
+ applyDraft(geometry) {
1856
+ if (this.disposed) return;
1857
+ if (!this.geometryMatchesMode(geometry)) return;
1858
+ if (this.detached) {
1859
+ this.heldDraft = drawablePolygon(geometry, 0);
1860
+ return;
1861
+ }
1862
+ if (this.draw.getSnapshotFeature(this.activeFeatureId) === void 0) {
1863
+ this.seedFeature(geometry);
1864
+ return;
1865
+ }
1866
+ const standingFrame = this.frame.longitude;
1867
+ this.frame.longitude = polygonFrameLongitude(geometry);
1868
+ try {
1869
+ this.write(() => updateDrawGeometry(this.draw, this.activeFeatureId, drawablePolygon(geometry, this.frame.longitude), zoneRefusal));
1870
+ } catch (error) {
1871
+ this.frame.longitude = standingFrame;
1872
+ throw error;
1873
+ }
1874
+ }
1875
+ dispose() {
1876
+ this.tellRefused(false);
1877
+ this.detachCursorReassert?.();
1878
+ this.detachCursorReassert = null;
1879
+ this.detachFrameFollow?.();
1880
+ this.detachFrameFollow = null;
1881
+ this.detachHoverCursor?.();
1882
+ this.detachHoverCursor = null;
1883
+ this.cursor?.popOverride();
1884
+ this.disposed = true;
1885
+ this.heldDraft = void 0;
1886
+ this.detachedGeometry = null;
1887
+ this.detachDrawListeners();
1888
+ try {
1889
+ if (this.draw.enabled) this.draw.clear();
1890
+ } finally {
1891
+ this.draw.stop();
1892
+ }
1893
+ }
1894
+ detachBeforeStyleReload() {
1895
+ if (this.disposed) return;
1896
+ if (this.detached) return;
1897
+ this.detached = true;
1898
+ this.detachedGeometry = this.currentGeometry();
1899
+ this.detachDrawListeners();
1900
+ this.draw.stop();
1901
+ }
1902
+ attachDrawListeners() {
1903
+ this.draw.on("change", this.changeHandler);
1904
+ this.draw.on("finish", this.finishHandler);
1905
+ }
1906
+ detachDrawListeners() {
1907
+ this.draw.off("change", this.changeHandler);
1908
+ this.draw.off("finish", this.finishHandler);
1909
+ }
1910
+ replayAfterStyleReload() {
1911
+ if (this.disposed) return;
1912
+ const geometry = this.detachedGeometry ?? this.currentGeometry();
1913
+ this.detachedGeometry = null;
1914
+ this.detached = false;
1915
+ this.draw.start();
1916
+ this.attachDrawListeners();
1917
+ if (geometry) {
1918
+ this.draw.clear();
1919
+ this.seedFeature(geometry);
1920
+ } else {
1921
+ this.frameOnMapCenter();
1922
+ this.draw.setMode(this.drawModeName);
1923
+ }
1924
+ this.applyZoneDraftStyle(this.color);
1925
+ this.detachHoverCursor?.();
1926
+ this.detachHoverCursor = this.attachHoverCursor();
1927
+ this.detachCursorReassert?.();
1928
+ this.detachCursorReassert = this.attachCursorReassert();
1929
+ const held = this.heldDraft;
1930
+ this.heldDraft = void 0;
1931
+ if (held !== void 0) applyHeldWrite(() => this.applyDraft(held));
1932
+ }
1933
+ handleChange(ids, _type, programmatic) {
1934
+ if (!ids.includes(this.activeFeatureId)) return;
1935
+ const geometry = this.currentGeometry();
1936
+ if (!geometry) return;
1937
+ const phase = programmatic ? "settled" : "live";
1938
+ this.gestureOpen = phase === "live";
1939
+ this.emit({
1940
+ geometry,
1941
+ mode: this.mode,
1942
+ phase,
1943
+ programmatic
1944
+ });
1945
+ }
1946
+ handleFinish(id) {
1947
+ if (id === this.activeFeatureId) {
1948
+ this.settleGesture();
1949
+ return;
1950
+ }
1951
+ if (this.drawCompleted) return;
1952
+ const geometry = this.geometryOf(id);
1953
+ if (!geometry) return;
1954
+ this.drawCompleted = true;
1955
+ this.activeFeatureId = id;
1956
+ this.draw.setMode(SELECT_MODE);
1957
+ this.draw.selectFeature(id);
1958
+ this.gestureOpen = false;
1959
+ this.emit({
1960
+ geometry,
1961
+ mode: this.mode,
1962
+ phase: "settled",
1963
+ programmatic: false
1964
+ });
1965
+ }
1966
+ settleGesture() {
1967
+ if (!this.gestureOpen) return;
1968
+ const geometry = this.currentGeometry();
1969
+ if (!geometry) return;
1970
+ this.gestureOpen = false;
1971
+ this.emit({
1972
+ geometry,
1973
+ mode: this.mode,
1974
+ phase: "settled",
1975
+ programmatic: false
1976
+ });
1977
+ }
1978
+ seedFeature(geometry) {
1979
+ if (!this.geometryMatchesMode(geometry)) return;
1980
+ const standingFrame = this.frame.longitude;
1981
+ this.frame.longitude = polygonFrameLongitude(geometry);
1982
+ const feature = {
1983
+ geometry: drawablePolygon(geometry, this.frame.longitude),
1984
+ id: this.featureId,
1985
+ properties: { mode: this.drawModeName },
1986
+ type: "Feature"
1987
+ };
1988
+ try {
1989
+ this.write(() => addDrawFeature(this.draw, feature, zoneRefusal));
1990
+ } catch (error) {
1991
+ this.frame.longitude = standingFrame;
1992
+ throw error;
1993
+ }
1994
+ this.activeFeatureId = this.featureId;
1995
+ this.draw.setMode(SELECT_MODE);
1996
+ this.draw.selectFeature(this.featureId);
1997
+ }
1998
+ applyZoneDraftStyle(hex) {
1999
+ this.applyPolygonDrawStyle(hex);
2000
+ this.draw.updateModeOptions(SELECT_MODE, { styles: {
2001
+ midPointColor: hex,
2002
+ selectedLineStringColor: hex,
2003
+ selectedPointColor: hex,
2004
+ selectedPolygonColor: hex,
2005
+ selectedPolygonOutlineColor: hex,
2006
+ selectionPointColor: hex
2007
+ } });
2008
+ }
2009
+ applyPolygonDrawStyle(hex) {
2010
+ const styles = {
2011
+ fillColor: hex,
2012
+ fillOpacity: .2,
2013
+ outlineColor: hex,
2014
+ outlineWidth: 2
2015
+ };
2016
+ switch (this.mode) {
2017
+ case "circle":
2018
+ this.draw.updateModeOptions(this.drawModeName, { styles });
2019
+ return;
2020
+ case "polygon":
2021
+ this.draw.updateModeOptions(this.drawModeName, { styles });
2022
+ return;
2023
+ case "sector":
2024
+ this.draw.updateModeOptions(this.drawModeName, { styles });
2025
+ return;
2026
+ case "sensor":
2027
+ this.draw.updateModeOptions(this.drawModeName, { styles });
2028
+ return;
2029
+ case "freehand":
2030
+ this.draw.updateModeOptions(this.drawModeName, { styles });
2031
+ return;
2032
+ }
2033
+ }
2034
+ currentGeometry() {
2035
+ return this.geometryOf(this.activeFeatureId);
2036
+ }
2037
+ geometryOf(id) {
2038
+ const feature = this.draw.getSnapshotFeature(id);
2039
+ if (!feature) return null;
2040
+ const geometry = feature.geometry;
2041
+ return geometry.type === "Polygon" ? worldPolygon(geometry, this.frame.longitude) : null;
2042
+ }
2043
+ heard(verdict) {
2044
+ this.tellRefused(!verdict.valid);
2045
+ return verdict;
2046
+ }
2047
+ tellRefused(refused) {
2048
+ if (refused === this.refused) return;
2049
+ this.refused = refused;
2050
+ try {
2051
+ this.onOutlineRefusedChange?.(refused);
2052
+ } catch (fault) {
2053
+ surfaceFault(fault);
2054
+ }
2055
+ }
2056
+ write(store) {
2057
+ const outer = this.writing;
2058
+ this.writing = true;
2059
+ try {
2060
+ store();
2061
+ } finally {
2062
+ this.writing = outer;
2063
+ }
2064
+ }
2065
+ standingRing() {
2066
+ const geometry = this.draw.getSnapshotFeature(this.activeFeatureId)?.geometry;
2067
+ return geometry?.type === "Polygon" ? geometry.coordinates[0] ?? null : null;
2068
+ }
2069
+ emit(draft) {
2070
+ try {
2071
+ this.emitDraft(draft);
2072
+ } catch (fault) {
2073
+ surfaceFault(fault);
2074
+ }
2075
+ }
2076
+ frameOnMapCenter() {
2077
+ this.frame.longitude = frameLongitudeFor([this.map.getCenter().lng]);
2078
+ }
2079
+ followMap() {
2080
+ if (this.disposed || this.detached) return;
2081
+ if (this.draw.getSnapshot().length === 0) this.frameOnMapCenter();
2082
+ }
2083
+ geometryMatchesMode(geometry) {
2084
+ return geometry.type === "Polygon";
2085
+ }
2086
+ attachCursorReassert() {
2087
+ if (!this.events || !this.cursor) return null;
2088
+ return attachCursorReassert(this.events, this.cursor);
2089
+ }
2090
+ attachHoverCursor() {
2091
+ const events = this.events;
2092
+ const cursor = this.cursor;
2093
+ if (!events || !cursor) return () => {};
2094
+ return attachEditHoverCursor({
2095
+ cursor,
2096
+ events,
2097
+ layers: [{
2098
+ kind: "handle",
2099
+ layerId: ZONE_VERTEX_LAYER_ID,
2100
+ midpointProperty: TERRA_DRAW_MID_POINT_PROPERTY
2101
+ }, {
2102
+ kind: "interior",
2103
+ layerId: ZONE_FILL_LAYER_ID
2104
+ }],
2105
+ map: this.map
2106
+ });
2107
+ }
2108
+ };
2109
+ const PINNED_BOUNDARY_TOLERANCE = 1e-7;
2110
+ const isPinnedWaypointIntact = (waypoints, pinned, index) => {
2111
+ const at = waypoints[index];
2112
+ if (!at) return false;
2113
+ const pinnedLng = pinned[0] ?? 0;
2114
+ const pinnedLat = pinned[1] ?? 0;
2115
+ return Math.abs(at[0] - pinnedLng) <= PINNED_BOUNDARY_TOLERANCE && Math.abs(at[1] - pinnedLat) <= PINNED_BOUNDARY_TOLERANCE;
2116
+ };
2117
+ const seedOnPins = (seed, pinnedStart, pinnedEnd) => {
2118
+ const vias = [...seed];
2119
+ if (vias.length < 2) return vias;
2120
+ const pairs = vias.map((via) => [via[0] ?? 0, via[1] ?? 0]);
2121
+ if (pinnedStart && !isPinnedWaypointIntact(pairs, pinnedStart, 0)) vias[0] = pinnedStart;
2122
+ if (pinnedEnd && !isPinnedWaypointIntact(pairs, pinnedEnd, vias.length - 1)) vias[vias.length - 1] = pinnedEnd;
2123
+ return vias;
2124
+ };
2125
+ const darkenColor = (hex, fraction) => {
2126
+ const value = Number.parseInt(hex.replace("#", ""), 16);
2127
+ const r = Math.max(0, (value >> 16) - Math.round(255 * fraction));
2128
+ const g = Math.max(0, (value >> 8 & 255) - Math.round(255 * fraction));
2129
+ const b = Math.max(0, (value & 255) - Math.round(255 * fraction));
2130
+ return `#${(r << 16 | g << 8 | b).toString(16).padStart(6, "0")}`;
2131
+ };
2132
+ const removalGuarded = (map) => {
2133
+ const removeLayer = (id) => map.getLayer(id) === void 0 ? map : map.removeLayer(id);
2134
+ const removeSource = (id) => map.getSource(id) === void 0 ? map : map.removeSource(id);
2135
+ const bound = /* @__PURE__ */ new Map();
2136
+ return new Proxy(map, { get: (target, key) => {
2137
+ if (key === "removeLayer") return removeLayer;
2138
+ if (key === "removeSource") return removeSource;
2139
+ const value = Reflect.get(target, key, target);
2140
+ if (typeof value !== "function") return value;
2141
+ let method = bound.get(key);
2142
+ if (method === void 0) {
2143
+ method = value.bind(target);
2144
+ bound.set(key, method);
2145
+ }
2146
+ return method;
2147
+ } });
2148
+ };
2149
+ const directionsLayers = (color) => {
2150
+ const casing = darkenColor(color, .2);
2151
+ return layersFactory().map((layer) => {
2152
+ const next = { ...layer };
2153
+ if (layer.id.includes("routeline-casing") || layer.id.includes("alt-routeline-casing")) next.paint = {
2154
+ ...layer.paint,
2155
+ "line-color": casing
2156
+ };
2157
+ else if (layer.id.includes("routeline") || layer.id.includes("alt-routeline")) next.paint = {
2158
+ ...layer.paint,
2159
+ "line-color": color
2160
+ };
2161
+ else if (layer.id.includes("waypoint-casing") || layer.id.includes("snappoint-casing") || layer.id.includes("hoverpoint-casing")) next.paint = {
2162
+ ...layer.paint,
2163
+ "circle-color": casing
2164
+ };
2165
+ else if (layer.id.includes("waypoint") || layer.id.includes("snappoint") || layer.id.includes("hoverpoint")) next.paint = {
2166
+ ...layer.paint,
2167
+ "circle-color": color
2168
+ };
2169
+ else if (layer.id.includes("snapline")) next.paint = {
2170
+ ...layer.paint,
2171
+ "line-color": color
2172
+ };
2173
+ return next;
2174
+ });
2175
+ };
2176
+ const lineColorLayers = [
2177
+ "maplibre-gl-directions-routeline",
2178
+ "maplibre-gl-directions-alt-routeline",
2179
+ "maplibre-gl-directions-snapline"
2180
+ ];
2181
+ const lineCasingLayers = ["maplibre-gl-directions-routeline-casing", "maplibre-gl-directions-alt-routeline-casing"];
2182
+ const circleColorLayers = [
2183
+ "maplibre-gl-directions-waypoint",
2184
+ "maplibre-gl-directions-snappoint",
2185
+ "maplibre-gl-directions-hoverpoint"
2186
+ ];
2187
+ const circleCasingLayers = [
2188
+ "maplibre-gl-directions-waypoint-casing",
2189
+ "maplibre-gl-directions-snappoint-casing",
2190
+ "maplibre-gl-directions-hoverpoint-casing"
2191
+ ];
2192
+ const snapWaypointsToRoute = (vias, route) => {
2193
+ if (route.length === 0) return vias.map((via) => [via[0] ?? 0, via[1] ?? 0]);
2194
+ const first = route[0] ?? [0, 0];
2195
+ const last = route[route.length - 1] ?? first;
2196
+ return vias.map((via, index) => {
2197
+ if (index === 0) return first;
2198
+ if (index === vias.length - 1) return last;
2199
+ const lng = via[0] ?? 0;
2200
+ const lat = via[1] ?? 0;
2201
+ let nearest = first;
2202
+ let nearestDistance = Number.POSITIVE_INFINITY;
2203
+ for (const coord of route) {
2204
+ const dx = (coord[0] ?? 0) - lng;
2205
+ const dy = (coord[1] ?? 0) - lat;
2206
+ const distance = dx * dx + dy * dy;
2207
+ if (distance < nearestDistance) {
2208
+ nearestDistance = distance;
2209
+ nearest = coord;
2210
+ }
2211
+ }
2212
+ return nearest;
2213
+ });
2214
+ };
2215
+ const parseWaypoints = (url) => {
2216
+ const coords = url.split("/").pop()?.split("?")[0] ?? "";
2217
+ if (coords.length === 0) return [];
2218
+ return coords.split(";").map((pair) => {
2219
+ const [lng, lat] = pair.split(",").map(Number);
2220
+ return [lng ?? 0, lat ?? 0];
2221
+ });
2222
+ };
2223
+ const routeFnFrom = (options) => {
2224
+ const { routeFn } = options;
2225
+ if (typeof routeFn !== "function") throw new MountayaElementsError(`DirectionsSegmentEngine: routeFn is ${String(routeFn)}. A directions edit draws the line its router answers: pass the function that routes the vias as routeFn, or begin the edit in linestring mode.`);
2226
+ return routeFn;
2227
+ };
2228
+ const activitySlugFrom = (options) => {
2229
+ const { activitySlug } = options;
2230
+ if (typeof activitySlug !== "string" || activitySlug === "") throw new MountayaElementsError(`DirectionsSegmentEngine: activitySlug is ${typeof activitySlug === "string" ? "\"\"" : String(activitySlug)}. A directions edit routes for one activity: pass the slug of the itinerary's activity as activitySlug, or begin the edit in linestring mode.`);
2231
+ return activitySlug;
2232
+ };
2233
+ const refuseUnroutableEdit = (options) => {
2234
+ routeFnFrom(options);
2235
+ activitySlugFrom(options);
2236
+ refuseSegmentPositions(options, "DirectionsSegmentEngine");
2237
+ };
2238
+ var DirectionsSegmentEngine = class {
2239
+ map;
2240
+ events;
2241
+ cursor;
2242
+ emitDraft;
2243
+ emitViaPrompt;
2244
+ directions = null;
2245
+ color;
2246
+ routeFn;
2247
+ activitySlug;
2248
+ vias;
2249
+ pinnedStart;
2250
+ pinnedEnd;
2251
+ onViaCapRefused;
2252
+ reverting = false;
2253
+ detachRouteCursor = null;
2254
+ detachCursorReassert = null;
2255
+ lastRoute = null;
2256
+ acceptedVias;
2257
+ routeToken = 0;
2258
+ routesInFlight = /* @__PURE__ */ new Map();
2259
+ viaPromptPending = false;
2260
+ routeFaultReported = false;
2261
+ disposed = false;
2262
+ constructor(map, events, cursor, options, emitDraft, emitViaPrompt) {
2263
+ this.map = map;
2264
+ this.events = events;
2265
+ this.cursor = cursor;
2266
+ this.emitDraft = emitDraft;
2267
+ this.emitViaPrompt = emitViaPrompt;
2268
+ this.routeFn = routeFnFrom(options);
2269
+ this.activitySlug = activitySlugFrom(options);
2270
+ const { endPin: pinnedEnd, startPin: pinnedStart } = refuseSegmentPositions(options, "DirectionsSegmentEngine");
2271
+ this.color = readEditColor(options.color, "DirectionsSegmentEngine");
2272
+ this.vias = seedOnPins(options.seedVias ?? [], pinnedStart, pinnedEnd);
2273
+ this.acceptedVias = [...this.vias];
2274
+ this.pinnedStart = pinnedStart;
2275
+ this.pinnedEnd = pinnedEnd;
2276
+ this.onViaCapRefused = options.onViaCapRefused;
2277
+ const directions = this.attach();
2278
+ if (this.vias.length > 0) directions.setWaypoints(this.toLngLatPairs(this.vias));
2279
+ }
2280
+ setDraftStyle(style) {
2281
+ this.color = readEditColor(style.color, "DirectionsSegmentEngine");
2282
+ const map = this.map;
2283
+ const casing = darkenColor(this.color, .2);
2284
+ for (const id of lineColorLayers) if (map.getLayer(id)) map.setPaintProperty(id, "line-color", this.color);
2285
+ for (const id of lineCasingLayers) if (map.getLayer(id)) map.setPaintProperty(id, "line-color", casing);
2286
+ for (const id of circleColorLayers) if (map.getLayer(id)) map.setPaintProperty(id, "circle-color", this.color);
2287
+ for (const id of circleCasingLayers) if (map.getLayer(id)) map.setPaintProperty(id, "circle-color", casing);
2288
+ }
2289
+ readDraft() {
2290
+ if (this.disposed) return null;
2291
+ return this.directions ? [...this.directions.waypoints] : this.vias.map((via) => [...via]);
2292
+ }
2293
+ setViaPromptPending(pending) {
2294
+ this.viaPromptPending = pending;
2295
+ if (this.directions) this.directions.interactive = !pending;
2296
+ }
2297
+ applyDraft(coordinates) {
2298
+ if (this.disposed) return;
2299
+ if (!this.directions) {
2300
+ this.lastRoute = null;
2301
+ this.vias = [...coordinates];
2302
+ return;
2303
+ }
2304
+ this.lastRoute = null;
2305
+ this.vias = [...coordinates];
2306
+ this.directions.setWaypoints(this.toLngLatPairs(coordinates));
2307
+ }
2308
+ dispose() {
2309
+ this.detachRouteCursor?.();
2310
+ this.detachRouteCursor = null;
2311
+ this.detachCursorReassert?.();
2312
+ this.detachCursorReassert = null;
2313
+ this.lastRoute = null;
2314
+ this.routeToken += 1;
2315
+ this.dropRoutesInFlight();
2316
+ this.disposed = true;
2317
+ this.destroyDirections();
2318
+ }
2319
+ destroyDirections() {
2320
+ this.reverting = true;
2321
+ try {
2322
+ this.directions?.destroy();
2323
+ } finally {
2324
+ this.reverting = false;
2325
+ }
2326
+ this.directions = null;
2327
+ }
2328
+ detachBeforeStyleReload() {
2329
+ if (this.disposed) return;
2330
+ this.detachRouteCursor?.();
2331
+ this.detachRouteCursor = null;
2332
+ this.detachCursorReassert?.();
2333
+ this.detachCursorReassert = null;
2334
+ this.lastRoute = null;
2335
+ this.destroyDirections();
2336
+ }
2337
+ replayAfterStyleReload() {
2338
+ if (this.disposed) return;
2339
+ if (this.directions) this.detachBeforeStyleReload();
2340
+ const directions = this.attach();
2341
+ if (this.vias.length > 0) directions.setWaypoints(this.toLngLatPairs(this.vias));
2342
+ }
2343
+ attach() {
2344
+ const configuration = {
2345
+ api: "https://routing.invalid/route/v1",
2346
+ dragThreshold: 0,
2347
+ layers: directionsLayers(this.color),
2348
+ profile: "route",
2349
+ requestOptions: {
2350
+ geometries: "geojson",
2351
+ overview: "full"
2352
+ }
2353
+ };
2354
+ const directions = new MapLibreGlDirections(removalGuarded(this.map), configuration);
2355
+ this.directions = directions;
2356
+ directions.fetch = (request) => this.routeViaInjection(request);
2357
+ directions.on("addwaypoint", () => {
2358
+ if (this.enforceViaCap()) return;
2359
+ if (this.enforcePinnedEnd(true)) return;
2360
+ this.emitFromSdk(false);
2361
+ });
2362
+ directions.on("beforeremovewaypoint", (event) => {
2363
+ event.preventDefault();
2364
+ const via = this.vias[event.data.index];
2365
+ if (!via) return;
2366
+ notifyListeners([this.emitViaPrompt], {
2367
+ index: event.data.index,
2368
+ lngLat: [via[0] ?? 0, via[1] ?? 0]
2369
+ });
2370
+ });
2371
+ directions.on("removewaypoint", () => {
2372
+ if (this.enforcePinnedStart() || this.enforcePinnedEnd()) return;
2373
+ this.emitFromSdk(false);
2374
+ });
2375
+ directions.on("movewaypoint", () => {
2376
+ if (this.enforcePinnedStart() || this.enforcePinnedEnd()) return;
2377
+ this.emitFromSdk(false);
2378
+ });
2379
+ directions.on("setwaypoints", () => {
2380
+ if (this.reverting) return;
2381
+ this.emitFromSdk(true);
2382
+ });
2383
+ directions.interactive = !this.viaPromptPending;
2384
+ this.detachRouteCursor = this.attachRouteCursor();
2385
+ this.detachCursorReassert = this.attachCursorReassert();
2386
+ return directions;
2387
+ }
2388
+ routeViaInjection(request) {
2389
+ return this.computeRoute(parseWaypoints(request.url), request.url);
2390
+ }
2391
+ routeOnce(key, waypoints) {
2392
+ const inFlight = this.routesInFlight.get(key);
2393
+ if (inFlight !== void 0) return inFlight;
2394
+ const controller = new AbortController();
2395
+ const call = this.routeFn(this.activitySlug, waypoints, { signal: controller.signal });
2396
+ const request = {
2397
+ call,
2398
+ controller
2399
+ };
2400
+ this.routesInFlight.set(key, request);
2401
+ const forget = () => {
2402
+ if (this.routesInFlight.get(key) === request) this.routesInFlight.delete(key);
2403
+ };
2404
+ call.then(forget, forget);
2405
+ return request;
2406
+ }
2407
+ dropRoutesInFlight(kept) {
2408
+ for (const [key, request] of [...this.routesInFlight]) if (key !== kept) {
2409
+ this.routesInFlight.delete(key);
2410
+ request.controller.abort();
2411
+ }
2412
+ }
2413
+ async computeRoute(waypoints, key) {
2414
+ const noRoute = {
2415
+ code: "NoRoute",
2416
+ routes: [],
2417
+ waypoints: []
2418
+ };
2419
+ this.routeToken += 1;
2420
+ const token = this.routeToken;
2421
+ this.dropRoutesInFlight(key);
2422
+ if (waypoints.length < 2 || waypoints.length > 45) {
2423
+ this.lastRoute = null;
2424
+ return noRoute;
2425
+ }
2426
+ let request = null;
2427
+ let route;
2428
+ try {
2429
+ request = this.routeOnce(key, waypoints);
2430
+ route = await request.call;
2431
+ } catch (fault) {
2432
+ request?.controller.signal.throwIfAborted();
2433
+ this.warnOnRouteFault(fault);
2434
+ if (token === this.routeToken) this.lastRoute = null;
2435
+ return noRoute;
2436
+ }
2437
+ request.controller.signal.throwIfAborted();
2438
+ if (route === "refused") {
2439
+ if (token === this.routeToken) this.revertToAcceptedVias();
2440
+ return noRoute;
2441
+ }
2442
+ if (!route) {
2443
+ if (token === this.routeToken) this.lastRoute = null;
2444
+ return noRoute;
2445
+ }
2446
+ if (token === this.routeToken) {
2447
+ this.lastRoute = route;
2448
+ this.acceptedVias = [...waypoints];
2449
+ notifyListeners([this.emitDraft], {
2450
+ phase: "settled",
2451
+ programmatic: true,
2452
+ route,
2453
+ vias: waypoints
2454
+ });
2455
+ }
2456
+ const coordinates2d = route.geometry.coordinates.map((coordinate) => [coordinate[0] ?? 0, coordinate[1] ?? 0]);
2457
+ const snapped = snapWaypointsToRoute(waypoints, coordinates2d);
2458
+ const legs = Array.from({ length: Math.max(waypoints.length - 1, 0) }, () => ({
2459
+ annotation: {
2460
+ congestion: [],
2461
+ distance: [],
2462
+ duration: []
2463
+ },
2464
+ distance: 0,
2465
+ duration: 0,
2466
+ steps: [],
2467
+ summary: ""
2468
+ }));
2469
+ return {
2470
+ code: "Ok",
2471
+ routes: [{
2472
+ distance: route.distance,
2473
+ duration: route.duration,
2474
+ geometry: { coordinates: coordinates2d },
2475
+ legs
2476
+ }],
2477
+ waypoints: snapped.map((location) => ({ location }))
2478
+ };
2479
+ }
2480
+ warnOnRouteFault(fault) {
2481
+ if (this.routeFaultReported || !inDevelopment()) return;
2482
+ this.routeFaultReported = true;
2483
+ console.warn("[@mountaya/elements] DirectionsSegmentEngine: routeFn threw, so the edit draws no route for these vias. A router that finds no route resolves to null; one that throws is read the same way and the edit stays open. The error it threw follows.", fault);
2484
+ }
2485
+ enforcePinnedStart() {
2486
+ if (!this.pinnedStart || !this.directions) return false;
2487
+ const current = this.directions.waypoints;
2488
+ if (isPinnedWaypointIntact(current, this.pinnedStart, 0)) return false;
2489
+ const corrected = [[this.pinnedStart[0] ?? 0, this.pinnedStart[1] ?? 0], ...current.slice(1)];
2490
+ this.reverting = true;
2491
+ try {
2492
+ this.directions.setWaypoints(corrected);
2493
+ } finally {
2494
+ this.reverting = false;
2495
+ }
2496
+ this.vias = corrected.map((point) => [point[0], point[1]]);
2497
+ return true;
2498
+ }
2499
+ enforcePinnedEnd(emitInteractive = false) {
2500
+ if (!this.pinnedEnd || !this.directions) return false;
2501
+ const current = this.directions.waypoints;
2502
+ if (isPinnedWaypointIntact(current, this.pinnedEnd, current.length - 1)) return false;
2503
+ const pinned = [this.pinnedEnd[0] ?? 0, this.pinnedEnd[1] ?? 0];
2504
+ const pinIndex = current.findIndex((_waypoint, index) => isPinnedWaypointIntact(current, pinned, index));
2505
+ const corrected = [...pinIndex === -1 ? current.slice(0, -1) : current.filter((_wp, index) => index !== pinIndex), pinned];
2506
+ this.reverting = true;
2507
+ try {
2508
+ this.directions.setWaypoints(corrected);
2509
+ } finally {
2510
+ this.reverting = false;
2511
+ }
2512
+ this.vias = corrected.map((point) => [point[0], point[1]]);
2513
+ if (emitInteractive) this.emitFromSdk(false);
2514
+ return true;
2515
+ }
2516
+ enforceViaCap() {
2517
+ if (!this.directions || this.directions.waypoints.length <= 45) return false;
2518
+ this.reverting = true;
2519
+ try {
2520
+ this.directions.setWaypoints(this.toLngLatPairs(this.vias));
2521
+ } finally {
2522
+ this.reverting = false;
2523
+ }
2524
+ if (this.onViaCapRefused !== void 0) notifyListeners([this.onViaCapRefused]);
2525
+ return true;
2526
+ }
2527
+ revertToAcceptedVias() {
2528
+ if (!this.directions) return;
2529
+ this.vias = [...this.acceptedVias];
2530
+ this.reverting = true;
2531
+ try {
2532
+ this.directions.setWaypoints(this.toLngLatPairs(this.acceptedVias));
2533
+ } finally {
2534
+ this.reverting = false;
2535
+ }
2536
+ }
2537
+ emitFromSdk(programmatic) {
2538
+ if (!this.directions) return;
2539
+ const vias = [...this.directions.waypoints];
2540
+ this.vias = vias;
2541
+ const draft = {
2542
+ phase: "settled",
2543
+ programmatic,
2544
+ route: this.lastRoute,
2545
+ vias
2546
+ };
2547
+ notifyListeners([this.emitDraft], draft);
2548
+ }
2549
+ attachRouteCursor() {
2550
+ return attachEditHoverCursor({
2551
+ cursor: this.cursor,
2552
+ events: this.events,
2553
+ layers: [{
2554
+ cursor: "pointer",
2555
+ kind: "fixed",
2556
+ layerId: "maplibre-gl-directions-routeline"
2557
+ }],
2558
+ map: this.map
2559
+ });
2560
+ }
2561
+ attachCursorReassert() {
2562
+ return attachCursorReassert(this.events, this.cursor);
2563
+ }
2564
+ toLngLatPairs(coordinates) {
2565
+ return coordinates.map((coordinate) => [coordinate[0] ?? 0, coordinate[1] ?? 0]);
2566
+ }
2567
+ };
2568
+ const isCapturable = (poi) => omtCategoryToPoiEnum(poi.category) !== null;
2569
+ var PoiPickWaypointEngine = class {
2570
+ emitChange;
2571
+ marker;
2572
+ detachClick;
2573
+ detachPointerMove;
2574
+ detachCursorReassert = null;
2575
+ currentIcon;
2576
+ currentColor;
2577
+ pointerFrame = null;
2578
+ lastPointerMove = null;
2579
+ onPoiHoverChange;
2580
+ isOverPoi = false;
2581
+ constructor(map, placement, options, emitChange, query, events, cursor) {
2582
+ this.emitChange = emitChange;
2583
+ const initialLngLat = readEditPosition(options.initialLngLat, "PoiPickWaypointEngine", "initialLngLat", "pass null for a waypoint not placed yet");
2584
+ this.currentIcon = options.initialIcon;
2585
+ this.currentColor = options.initialColor;
2586
+ this.onPoiHoverChange = options.onPoiHoverChange;
2587
+ this.marker = new DraftWaypointMarker(map, placement);
2588
+ if (initialLngLat) this.marker.apply({
2589
+ color: this.currentColor,
2590
+ icon: this.currentIcon,
2591
+ lngLat: initialLngLat
2592
+ });
2593
+ this.detachClick = query.onMapClick((lngLat) => {
2594
+ this.handleClick(lngLat, query);
2595
+ });
2596
+ this.detachPointerMove = this.onPoiHoverChange === void 0 ? () => {} : query.onPointerMove((move) => {
2597
+ this.lastPointerMove = { lngLat: move.lngLat };
2598
+ if (this.pointerFrame === null) this.pointerFrame = requestAnimationFrame(() => {
2599
+ this.pointerFrame = null;
2600
+ const latest = this.lastPointerMove;
2601
+ if (!latest) return;
2602
+ this.reportHover(query.queryPoisAt(latest.lngLat).some(isCapturable));
2603
+ });
2604
+ });
2605
+ if (events && cursor) this.detachCursorReassert = attachCursorReassert(events, cursor);
2606
+ }
2607
+ setDraftStyle(style) {
2608
+ this.currentColor = style.color;
2609
+ this.currentIcon = style.icon;
2610
+ this.marker.setStyle(style);
2611
+ }
2612
+ readDraft() {
2613
+ return this.marker.read();
2614
+ }
2615
+ clearDraft() {
2616
+ this.marker.clear();
2617
+ }
2618
+ applyDraft(snapshot) {
2619
+ this.currentColor = snapshot.color;
2620
+ this.currentIcon = snapshot.icon;
2621
+ this.marker.apply(snapshot);
2622
+ }
2623
+ dispose() {
2624
+ this.detachCursorReassert?.();
2625
+ this.detachCursorReassert = null;
2626
+ this.detachClick();
2627
+ this.detachPointerMove();
2628
+ if (this.pointerFrame !== null) {
2629
+ cancelAnimationFrame(this.pointerFrame);
2630
+ this.pointerFrame = null;
2631
+ }
2632
+ this.lastPointerMove = null;
2633
+ this.marker.clear();
2634
+ this.reportHover(false);
2635
+ }
2636
+ detachBeforeStyleReload() {}
2637
+ replayAfterStyleReload() {
2638
+ this.marker.replay();
2639
+ }
2640
+ handleClick(lngLat, query) {
2641
+ const first = query.queryPoisAt(lngLat).find(isCapturable);
2642
+ if (!first) return;
2643
+ const category = omtCategoryToPoiEnum(first.category);
2644
+ if (!category) return;
2645
+ const seed = {
2646
+ category,
2647
+ name: first.name,
2648
+ sourceFeatureId: first.id
2649
+ };
2650
+ this.marker.apply({
2651
+ color: this.currentColor,
2652
+ icon: this.currentIcon,
2653
+ lngLat
2654
+ });
2655
+ notifyListeners([this.emitChange], {
2656
+ lngLat,
2657
+ poiSeed: seed
2658
+ });
2659
+ }
2660
+ reportHover(isOverPoi) {
2661
+ if (isOverPoi === this.isOverPoi) return;
2662
+ this.isOverPoi = isOverPoi;
2663
+ try {
2664
+ this.onPoiHoverChange?.(isOverPoi);
2665
+ } catch (fault) {
2666
+ surfaceFault(fault);
2667
+ }
2668
+ }
2669
+ };
2670
+ const editEngines = {
2671
+ boundary: (seams, options, emitDraft) => new TerraDrawBoundaryEngine(seams.map, options, emitDraft, void 0, seams.events, seams.cursor),
2672
+ refuseBoundary: (options) => {
2673
+ readEditColor(options.color, "TerraDrawBoundaryEngine");
2674
+ },
2675
+ refuseSegment: (options) => {
2676
+ if (options.mode === "directions") {
2677
+ refuseUnroutableEdit(options);
2678
+ readEditColor(options.color, "DirectionsSegmentEngine");
2679
+ } else {
2680
+ refuseSegmentSeed(options, "TerraDrawLinestringSegmentEngine");
2681
+ readEditColor(options.color, "TerraDrawLinestringSegmentEngine");
2682
+ }
2683
+ },
2684
+ refuseWaypoint: (options) => {
2685
+ readEditPosition(options.initialLngLat, options.mode === "point" ? "TerraDrawPointWaypointEngine" : "PoiPickWaypointEngine", "initialLngLat", "pass null for a waypoint not placed yet");
2686
+ },
2687
+ refuseZone: (options) => {
2688
+ refuseZoneSeed(options, "TerraDrawZoneEngine");
2689
+ readEditColor(options.color, "TerraDrawZoneEngine");
2690
+ },
2691
+ segment: (seams, options, emitDraft, emitViaPrompt) => options.mode === "directions" ? new DirectionsSegmentEngine(seams.map, seams.events, seams.cursor, options, emitDraft, emitViaPrompt) : new TerraDrawLinestringSegmentEngine(seams.map, seams.events, seams.cursor, options, emitDraft, emitViaPrompt),
2692
+ waypoint: (seams, options, emitDraftChange) => options.mode === "point" ? new TerraDrawPointWaypointEngine(seams.map, seams.placement, options, emitDraftChange, void 0, seams.snapSegments, seams.events, seams.cursor, seams.cursorOptions) : new PoiPickWaypointEngine(seams.map, seams.placement, options, emitDraftChange, seams.pick, seams.events, seams.cursor),
2693
+ zone: (seams, options, emitDraft) => new TerraDrawZoneEngine(seams.map, options, emitDraft, void 0, seams.events, seams.cursor)
2694
+ };
2695
+ var MapLibreClient = class MapLibreClient extends MapLibreViewClient {
2696
+ static {
2697
+ bindEditEngines(MapLibreClient.prototype, editEngines);
2698
+ }
2699
+ };
2700
+ export { MapLibreClient, SEGMENT_ROUTE_REFUSED, ZONE_LEVELS, ZONE_MODES, blankStyle };
2701
+
2702
+ //# sourceMappingURL=index.js.map