@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,1832 @@
1
+ import type { Feature, FeatureCollection, Geometry, Point, Position } from "geojson";
2
+
3
+ import { MARKER_SPRITE_PX } from "../../compose/rules/markerSprite.js";
4
+ import { WEB_MERCATOR_MAX_LAT } from "../../geo/rules/camera.js";
5
+ import { wrapLongitude } from "../../geo/rules/longitude.js";
6
+ import type { LngLat } from "../../geo/rules/types.js";
7
+ import { DEGREES_PER_TURN, DEGREES_TO_RADIANS } from "../../units/rules/conversions.js";
8
+
9
+ /**
10
+ * Where the clock badge of each out-of-window zone stands: one point per zone on screen, inside
11
+ * the part of the zone the screen shows.
12
+ *
13
+ * A zone reaches the renderer in pieces, one per tile, and a tile carries each polygon as far as
14
+ * a window around itself: neighbouring tiles hold overlapping pieces of one zone, and a tile
15
+ * wholly inside a zone holds the window's square. A symbol laid out per piece is therefore drawn
16
+ * once per tile, or not at all where the piece's own middle lies outside its tile. So the badge
17
+ * is not laid out per piece. The pieces on screen are grouped by the zone they belong to, and one
18
+ * point is taken inside the piece that covers most of the screen, cut to it.
19
+ *
20
+ * The point is a true interior one: the place inside the visible part that is furthest from its
21
+ * outline (the pole of inaccessibility), since a zone can be concave or ring-shaped and its
22
+ * centroid can fall in a bay or a hole. It is measured on the screen, so the badge stands
23
+ * mid-screen in a zone that fills a tilted view, where the same measure on the ground would push
24
+ * it to the far edge.
25
+ *
26
+ * A badge that has a place keeps it: while the point still lies on its zone and inside the
27
+ * screen less a margin, a pan, a zoom or a tile more moves nothing. It is placed again only once
28
+ * it leaves, or once another badge covers it. A badge is placed where no other badge stands when
29
+ * its zone leaves the room, so concentric zones do not stack theirs on one point.
30
+ *
31
+ * No input holds the main thread. The search for one zone's point does a bounded amount of work
32
+ * ({@link ZONE_BADGE_SEARCH_VISITS}) and keeps the best point it found, and a placement goes one
33
+ * zone at a time ({@link placeZoneBadgesStepwise}) so a caller spreads many zones over frames.
34
+ *
35
+ * Everything here is arithmetic over polygons, four corners and a size. The renderer supplies the
36
+ * pieces it has on screen and the ground its four corners show, and is asked nothing else.
37
+ */
38
+
39
+ /** A position on a plane: screen pixels, or the unit square Web Mercator lays the world on. */
40
+ export type PlanePoint = readonly [x: number, y: number];
41
+
42
+ /**
43
+ * A polygon on a plane: its outline, then its holes. A ring is written once round, without
44
+ * repeating its first point, and a point is inside the polygon when it is inside an odd number
45
+ * of its rings.
46
+ */
47
+ export type PlanePolygon = readonly (readonly PlanePoint[])[];
48
+
49
+ /** The four corners of a view, clockwise from the top left as the screen shows them. */
50
+ type PlaneQuad = readonly [PlanePoint, PlanePoint, PlanePoint, PlanePoint];
51
+
52
+ /** A rectangle on a plane, by its edges. */
53
+ interface PlaneRectangle {
54
+ readonly maxX: number;
55
+ readonly maxY: number;
56
+ readonly minX: number;
57
+ readonly minY: number;
58
+ }
59
+
60
+ /**
61
+ * ZONE_BADGE_KEEP_MARGIN_PX is how far inside the screen's edge a badge has to stand to keep its
62
+ * place, in CSS pixels: half the badge and a little more, so a badge that stays is drawn whole.
63
+ */
64
+ export const ZONE_BADGE_KEEP_MARGIN_PX = 24;
65
+
66
+ /**
67
+ * ZONE_BADGE_PLACE_MARGIN_PX is how far inside the screen's edge a badge is placed where its zone
68
+ * leaves the room, in CSS pixels. It is wider than {@link ZONE_BADGE_KEEP_MARGIN_PX}, so a badge
69
+ * just placed is not placed again by the next few pixels of a pan.
70
+ */
71
+ export const ZONE_BADGE_PLACE_MARGIN_PX = 48;
72
+
73
+ /** ZONE_BADGE_ICON_SIZE is the scale the badge layer draws the marker sprite at. */
74
+ export const ZONE_BADGE_ICON_SIZE = 0.9;
75
+
76
+ /**
77
+ * ZONE_BADGE_ROOM_PX is how far apart two badges stand for neither to cover the other, in CSS
78
+ * pixels: the badge's width on screen and a pixel between.
79
+ */
80
+ export const ZONE_BADGE_ROOM_PX = MARKER_SPRITE_PX * ZONE_BADGE_ICON_SIZE + 1;
81
+
82
+ /**
83
+ * ZONE_BADGE_SEARCH_VISITS is the most work the search for one zone's point does, in edge visits:
84
+ * reading how far one point stands inside a polygon visits each of its edges once, and each badge
85
+ * it keeps clear of once. Measured on a laptop core it is a couple of milliseconds, whatever the
86
+ * outline: a comb of a thousand teeth searched to the last pixel takes seconds instead.
87
+ */
88
+ export const ZONE_BADGE_SEARCH_VISITS = 200_000;
89
+
90
+ /**
91
+ * ZONE_BADGE_PROJECT_VISITS is what drawing one place through the renderer's projection over
92
+ * relief costs, in edge visits: MapLibre reads the place's height off its elevation tiles, about
93
+ * 0.6 us, where a visit is about 10 ns.
94
+ */
95
+ export const ZONE_BADGE_PROJECT_VISITS = 64;
96
+
97
+ /**
98
+ * ZONE_BADGE_UNPROJECT_VISITS is what reading the place a pixel shows over relief costs, in edge
99
+ * visits: about 2 us.
100
+ */
101
+ export const ZONE_BADGE_UNPROJECT_VISITS = 256;
102
+
103
+ /**
104
+ * FRONT_DEPTH is the depth below which ground counts as behind the viewer, as a share of the
105
+ * depth of the middle of the view. Ground the screen shows is many times deeper, at any tilt a
106
+ * map takes.
107
+ */
108
+ const FRONT_DEPTH = 1e-3;
109
+
110
+ /** The smallest area a cut polygon has to keep to be a part of its zone, in square pixels. */
111
+ const VISIBLE_AREA_MIN = 1e-9;
112
+
113
+ /** How finely the search for an interior point resolves, as a share of the shape's shorter side. */
114
+ const INTERIOR_PRECISION_SHARE = 0.01;
115
+
116
+ /** The coarsest the search for an interior point resolves, in the plane's units. */
117
+ const INTERIOR_PRECISION_MAX = 1;
118
+
119
+ /** How many cells the search for an interior point lays along the longer side of a thin shape. */
120
+ const INTERIOR_CELLS_ALONG = 64;
121
+
122
+ /** The heights a scanline is drawn at across a shape whose pole no cell found, top to bottom. */
123
+ const SCANLINE_HEIGHTS = [0.5, 0.25, 0.75, 0.125, 0.375, 0.625, 0.875] as const;
124
+
125
+ /** How many of a shape's longest edges are tried for a point beside one, as the last resort. */
126
+ const EDGE_POINT_TRIES = 16;
127
+
128
+ /**
129
+ * How close one badge has to stand to another to count as covering it, short of the room: the
130
+ * slack a position read back from a longitude and a latitude needs.
131
+ */
132
+ const COVER_SLACK_PX = 1;
133
+
134
+ /**
135
+ * How long a stretch of an outline is drawn as one straight edge over relief, in pixels of flat
136
+ * ground: an edge draped over a hill bends, and is followed in steps of this length at most.
137
+ */
138
+ const DRAPE_STEP_PX = 32;
139
+
140
+ /**
141
+ * How far, in pixels of flat ground, the place a pixel shows may stand from a badge's own for
142
+ * the badge to count as shown there rather than hidden by relief in front of it: the slack the
143
+ * renderer's reading of a pixel's place needs.
144
+ */
145
+ const SHOWN_SLACK_PX = 12;
146
+
147
+ /**
148
+ * How many points of a zone's part on the screen are tried, beyond the search's own, for one the
149
+ * zone shows at where relief hides the others: a grid over the part, the nearest the search's
150
+ * point first. Each costs a walk of the part's edges to find, then a reading of the pixel's place
151
+ * and a walk of the zone's edges.
152
+ */
153
+ const SHOWN_CANDIDATES = 128;
154
+
155
+ /** The closest the grid of {@link SHOWN_CANDIDATES} lays its points, in pixels. */
156
+ const SHOWN_SPACING_MIN_PX = 4;
157
+
158
+ /**
159
+ * gridOver lays a grid of about {@link SHOWN_CANDIDATES} points over a box, no closer together
160
+ * than {@link SHOWN_SPACING_MIN_PX}, and answers them nearest a point first.
161
+ */
162
+ const gridOver = (bounds: PlaneRectangle, from: PlanePoint): PlanePoint[] => {
163
+ const width = bounds.maxX - bounds.minX;
164
+ const height = bounds.maxY - bounds.minY;
165
+ const spacing = Math.max(SHOWN_SPACING_MIN_PX, Math.sqrt((width * height) / SHOWN_CANDIDATES));
166
+ const points: { readonly distance: number; readonly point: PlanePoint }[] = [];
167
+ for (let x = bounds.minX + spacing / 2; x < bounds.maxX; x += spacing) {
168
+ for (let y = bounds.minY + spacing / 2; y < bounds.maxY; y += spacing) {
169
+ points.push({ distance: Math.hypot(x - from[0], y - from[1]), point: [x, y] });
170
+ }
171
+ }
172
+
173
+ return points.sort((left, right) => left.distance - right.distance).map(({ point }) => point);
174
+ };
175
+
176
+ /**
177
+ * clipRing keeps the part of a ring on the side of a line where `a * x + b * y + c` is zero or
178
+ * more, by Sutherland and Hodgman's walk: each edge that crosses the line gives the point it
179
+ * crosses at.
180
+ *
181
+ * A concave ring cut in two comes back as one ring whose parts are joined along the line. The
182
+ * join encloses no area, so the even-odd test and the areas below read the ring as its parts.
183
+ */
184
+ const clipRing = (ring: readonly PlanePoint[], a: number, b: number, c: number): PlanePoint[] => {
185
+ const kept: PlanePoint[] = [];
186
+ let previous = ring[ring.length - 1];
187
+ if (previous === undefined) {
188
+ return kept;
189
+ }
190
+
191
+ let previousSide = a * previous[0] + b * previous[1] + c;
192
+ for (const current of ring) {
193
+ const side = a * current[0] + b * current[1] + c;
194
+ if (side >= 0 !== previousSide >= 0) {
195
+ const along = previousSide / (previousSide - side);
196
+ kept.push([
197
+ previous[0] + (current[0] - previous[0]) * along,
198
+ previous[1] + (current[1] - previous[1]) * along,
199
+ ]);
200
+ }
201
+
202
+ if (side >= 0) {
203
+ kept.push(current);
204
+ }
205
+
206
+ previous = current;
207
+ previousSide = side;
208
+ }
209
+
210
+ return kept;
211
+ };
212
+
213
+ /** ringArea is the area a ring encloses, signed by the way it turns. */
214
+ const ringArea = (ring: readonly PlanePoint[]): number => {
215
+ let doubled = 0;
216
+ let previous = ring[ring.length - 1];
217
+ for (const current of ring) {
218
+ if (previous !== undefined) {
219
+ doubled += previous[0] * current[1] - current[0] * previous[1];
220
+ }
221
+
222
+ previous = current;
223
+ }
224
+
225
+ return doubled / 2;
226
+ };
227
+
228
+ /** polygonArea is the area of a polygon: its outline's, less its holes'. */
229
+ const polygonArea = (polygon: PlanePolygon): number =>
230
+ polygon.reduce(
231
+ (area, ring, index) => area + (index === 0 ? 1 : -1) * Math.abs(ringArea(ring)),
232
+ 0,
233
+ );
234
+
235
+ /**
236
+ * clipPolygon keeps the part of a polygon on the kept side of every line given, each written as
237
+ * the `[a, b, c]` of `a * x + b * y + c >= 0`.
238
+ *
239
+ * @returns The polygon cut, or null when nothing of its outline is left.
240
+ */
241
+ const clipPolygon = (
242
+ polygon: PlanePolygon,
243
+ lines: readonly (readonly [a: number, b: number, c: number])[],
244
+ ): PlanePolygon | null => {
245
+ const rings: PlanePoint[][] = [];
246
+ for (const [index, ring] of polygon.entries()) {
247
+ let kept: readonly PlanePoint[] = ring;
248
+ for (const [a, b, c] of lines) {
249
+ kept = clipRing(kept, a, b, c);
250
+ }
251
+
252
+ if (kept.length >= 3) {
253
+ rings.push([...kept]);
254
+ } else if (index === 0) {
255
+ return null;
256
+ }
257
+ }
258
+
259
+ return rings.length > 0 ? rings : null;
260
+ };
261
+
262
+ /**
263
+ * clipPolygonToRectangle keeps the part of a polygon a rectangle holds: its outline and each of
264
+ * its holes, cut along the rectangle's four edges.
265
+ *
266
+ * @param polygon The polygon, outline first.
267
+ * @param rectangle The rectangle to cut it to.
268
+ * @returns The part inside, or null when the rectangle holds none of the polygon's area.
269
+ */
270
+ export const clipPolygonToRectangle = (
271
+ polygon: PlanePolygon,
272
+ rectangle: PlaneRectangle,
273
+ ): PlanePolygon | null => {
274
+ const clipped = clipPolygon(polygon, [
275
+ [1, 0, -rectangle.minX],
276
+ [-1, 0, rectangle.maxX],
277
+ [0, 1, -rectangle.minY],
278
+ [0, -1, rectangle.maxY],
279
+ ]);
280
+
281
+ return clipped !== null && polygonArea(clipped) > VISIBLE_AREA_MIN ? clipped : null;
282
+ };
283
+
284
+ /**
285
+ * polygonContains reports whether a point is inside a polygon, by the even-odd rule: inside an
286
+ * odd number of its rings. A point in a hole is inside two, and is not inside the polygon.
287
+ *
288
+ * @param polygon The polygon, outline first.
289
+ * @param point The point asked about.
290
+ */
291
+ export const polygonContains = (polygon: PlanePolygon, [x, y]: PlanePoint): boolean => {
292
+ let inside = false;
293
+ for (const ring of polygon) {
294
+ let previous = ring[ring.length - 1];
295
+ for (const current of ring) {
296
+ if (
297
+ previous !== undefined &&
298
+ current[1] > y !== previous[1] > y &&
299
+ x <
300
+ ((previous[0] - current[0]) * (y - current[1])) / (previous[1] - current[1]) + current[0]
301
+ ) {
302
+ inside = !inside;
303
+ }
304
+
305
+ previous = current;
306
+ }
307
+ }
308
+
309
+ return inside;
310
+ };
311
+
312
+ /** The square of the distance from a point to a segment. */
313
+ const segmentDistanceSquared = (x: number, y: number, a: PlanePoint, b: PlanePoint): number => {
314
+ let nearestX = a[0];
315
+ let nearestY = a[1];
316
+ const alongX = b[0] - nearestX;
317
+ const alongY = b[1] - nearestY;
318
+ if (alongX !== 0 || alongY !== 0) {
319
+ const share = ((x - nearestX) * alongX + (y - nearestY) * alongY) / (alongX ** 2 + alongY ** 2);
320
+ if (share > 1) {
321
+ nearestX = b[0];
322
+ nearestY = b[1];
323
+ } else if (share > 0) {
324
+ nearestX += alongX * share;
325
+ nearestY += alongY * share;
326
+ }
327
+ }
328
+
329
+ return (x - nearestX) ** 2 + (y - nearestY) ** 2;
330
+ };
331
+
332
+ /**
333
+ * clearanceAt is how far a point stands from a polygon's nearest edge: positive inside the
334
+ * polygon, negative outside it. One walk of the edges reads both the distance and the even-odd
335
+ * parity {@link polygonContains} reads.
336
+ */
337
+ const clearanceAt = (polygon: PlanePolygon, x: number, y: number): number => {
338
+ let nearest = Number.POSITIVE_INFINITY;
339
+ let inside = false;
340
+ // Indexed rather than iterated: this loop is the whole cost of the search.
341
+ for (let ringIndex = 0; ringIndex < polygon.length; ringIndex += 1) {
342
+ const ring = polygon[ringIndex] ?? [];
343
+ let previous = ring[ring.length - 1];
344
+ for (let index = 0; index < ring.length; index += 1) {
345
+ const current = ring[index];
346
+ if (previous !== undefined && current !== undefined) {
347
+ nearest = Math.min(nearest, segmentDistanceSquared(x, y, previous, current));
348
+ if (
349
+ current[1] > y !== previous[1] > y &&
350
+ x <
351
+ ((previous[0] - current[0]) * (y - current[1])) / (previous[1] - current[1]) +
352
+ current[0]
353
+ ) {
354
+ inside = !inside;
355
+ }
356
+ }
357
+
358
+ previous = current;
359
+ }
360
+ }
361
+
362
+ return (inside ? 1 : -1) * Math.sqrt(nearest);
363
+ };
364
+
365
+ /** The edges a polygon has: one per position of each of its rings. */
366
+ const edgeCount = (polygon: PlanePolygon): number =>
367
+ polygon.reduce((count, ring) => count + ring.length, 0);
368
+
369
+ /** One square of the search for an interior point: its middle, half its side and what it promises. */
370
+ interface SearchCell {
371
+ /**
372
+ * The clearance at the cell's middle: from the polygon's edges, and from the room of every
373
+ * badge kept clear of. Positive where a badge fits inside the polygon and beside the others.
374
+ */
375
+ readonly clearance: number;
376
+ /** The clearance at the cell's middle from the polygon's edges alone: positive inside it. */
377
+ readonly edge: number;
378
+ readonly half: number;
379
+ /** The most clearance any point of the cell can have. */
380
+ readonly reach: number;
381
+ readonly x: number;
382
+ readonly y: number;
383
+ }
384
+
385
+ /**
386
+ * SearchChoice is what a search holds on to: the best square it read, and the one furthest inside
387
+ * the polygon whatever the badges, which is the answer where the polygon leaves no room beside
388
+ * them.
389
+ */
390
+ interface SearchChoice {
391
+ best: SearchCell | null;
392
+ inside: SearchCell | null;
393
+ }
394
+
395
+ /**
396
+ * searchCell reads one square of the search. The clearance is the least of the distance to the
397
+ * polygon's outline and the distance to each badge less its room: a distance less a constant, so
398
+ * no point of the square clears more than its middle does by more than half its diagonal.
399
+ */
400
+ const searchCell = (
401
+ polygon: PlanePolygon,
402
+ x: number,
403
+ y: number,
404
+ half: number,
405
+ avoid: readonly PlanePoint[],
406
+ room: number,
407
+ ): SearchCell => {
408
+ const edge = clearanceAt(polygon, x, y);
409
+ let clearance = edge;
410
+ for (const [avoidX, avoidY] of avoid) {
411
+ clearance = Math.min(clearance, Math.hypot(x - avoidX, y - avoidY) - room);
412
+ }
413
+
414
+ return { clearance, edge, half, reach: clearance + half * Math.SQRT2, x, y };
415
+ };
416
+
417
+ /** pushCell adds a cell to a heap kept with the cell of greatest reach first. */
418
+ const pushCell = (heap: SearchCell[], cell: SearchCell): void => {
419
+ let index = heap.push(cell) - 1;
420
+ while (index > 0) {
421
+ const parentIndex = (index - 1) >> 1;
422
+ const parent = heap[parentIndex];
423
+ if (parent === undefined || parent.reach >= cell.reach) {
424
+ break;
425
+ }
426
+
427
+ heap[index] = parent;
428
+ index = parentIndex;
429
+ }
430
+
431
+ heap[index] = cell;
432
+ };
433
+
434
+ /** popCell takes the cell of greatest reach off the heap. */
435
+ const popCell = (heap: SearchCell[]): SearchCell | undefined => {
436
+ const [top] = heap;
437
+ const last = heap.pop();
438
+ if (top === undefined || last === undefined || heap.length === 0) {
439
+ return top;
440
+ }
441
+
442
+ let index = 0;
443
+ for (;;) {
444
+ let childIndex = index * 2 + 1;
445
+ const left = heap[childIndex];
446
+ const right = heap[childIndex + 1];
447
+ let child = left;
448
+ if (left !== undefined && right !== undefined && right.reach > left.reach) {
449
+ child = right;
450
+ childIndex += 1;
451
+ }
452
+
453
+ if (child === undefined || child.reach <= last.reach) {
454
+ break;
455
+ }
456
+
457
+ heap[index] = child;
458
+ index = childIndex;
459
+ }
460
+
461
+ heap[index] = last;
462
+
463
+ return top;
464
+ };
465
+
466
+ /** The box around a polygon's outline. */
467
+ const boundsOf = (polygon: PlanePolygon): PlaneRectangle | null => {
468
+ const [outline] = polygon;
469
+ if (outline === undefined || outline.length === 0) {
470
+ return null;
471
+ }
472
+
473
+ let minX = Number.POSITIVE_INFINITY;
474
+ let minY = Number.POSITIVE_INFINITY;
475
+ let maxX = Number.NEGATIVE_INFINITY;
476
+ let maxY = Number.NEGATIVE_INFINITY;
477
+ for (const [x, y] of outline) {
478
+ minX = Math.min(minX, x);
479
+ minY = Math.min(minY, y);
480
+ maxX = Math.max(maxX, x);
481
+ maxY = Math.max(maxY, y);
482
+ }
483
+
484
+ return { maxX, maxY, minX, minY };
485
+ };
486
+
487
+ /**
488
+ * scanlinePoint is the middle of the widest stretch of a polygon along a horizontal line, tried
489
+ * at a handful of heights: an interior point of any polygon one of those lines crosses over a
490
+ * stretch of some width, however thin the polygon is.
491
+ */
492
+ const scanlinePoint = (polygon: PlanePolygon, bounds: PlaneRectangle): PlanePoint | null => {
493
+ for (const share of SCANLINE_HEIGHTS) {
494
+ const point = scanlineAt(polygon, bounds.minY + (bounds.maxY - bounds.minY) * share);
495
+ if (point !== null) {
496
+ return point;
497
+ }
498
+ }
499
+
500
+ return null;
501
+ };
502
+
503
+ /**
504
+ * scanlineAt answers the middle of the widest stretch of a polygon along the horizontal line at
505
+ * `y`, or null where the line crosses it over no width: two walks of its edges.
506
+ */
507
+ const scanlineAt = (polygon: PlanePolygon, y: number): PlanePoint | null => {
508
+ const crossings: number[] = [];
509
+ for (const ring of polygon) {
510
+ let previous = ring[ring.length - 1];
511
+ for (const current of ring) {
512
+ if (previous !== undefined && current[1] > y !== previous[1] > y) {
513
+ crossings.push(
514
+ ((previous[0] - current[0]) * (y - current[1])) / (previous[1] - current[1]) + current[0],
515
+ );
516
+ }
517
+
518
+ previous = current;
519
+ }
520
+ }
521
+
522
+ crossings.sort((left, right) => left - right);
523
+ let widest = 0;
524
+ let middle: number | null = null;
525
+ for (let index = 0; index + 1 < crossings.length; index += 2) {
526
+ const enter = crossings[index];
527
+ const leave = crossings[index + 1];
528
+ if (enter !== undefined && leave !== undefined && leave - enter > widest) {
529
+ widest = leave - enter;
530
+ middle = (enter + leave) / 2;
531
+ }
532
+ }
533
+
534
+ return middle !== null && polygonContains(polygon, [middle, y]) ? [middle, y] : null;
535
+ };
536
+
537
+ /**
538
+ * shownCandidates yields the points of a zone's part on the screen tried, past the search's own,
539
+ * for one the zone shows at where relief hides it: the middles of scanlines across the part, then
540
+ * the points of a grid over it that the part holds, the nearest `from` first, up to
541
+ * {@link SHOWN_CANDIDATES} of them.
542
+ *
543
+ * Finding each is paid for out of `budget`: a walk of the part's edges for its box, two for each
544
+ * scanline, one for each point of the grid tested. A point is looked for only while the budget
545
+ * leaves `reserve` beyond its finding, what reading it back costs, so the points stop where the
546
+ * budget does.
547
+ */
548
+ function* shownCandidates(
549
+ part: PlanePolygon,
550
+ from: PlanePoint,
551
+ budget: InteriorSearchBudget,
552
+ reserve: number,
553
+ ): Generator<PlanePoint, void, unknown> {
554
+ const walk = edgeCount(part);
555
+ const pays = (cost: number): boolean => {
556
+ if (budget.visits < cost + reserve) {
557
+ return false;
558
+ }
559
+
560
+ budget.visits -= cost;
561
+
562
+ return true;
563
+ };
564
+
565
+ const bounds = pays(walk) ? boundsOf(part) : null;
566
+ if (bounds === null) {
567
+ return;
568
+ }
569
+
570
+ for (const share of SCANLINE_HEIGHTS) {
571
+ if (!pays(walk * 2)) {
572
+ return;
573
+ }
574
+
575
+ const point = scanlineAt(part, bounds.minY + (bounds.maxY - bounds.minY) * share);
576
+ if (point !== null) {
577
+ yield point;
578
+ }
579
+ }
580
+
581
+ let held = 0;
582
+ for (const point of gridOver(bounds, from)) {
583
+ if (held >= SHOWN_CANDIDATES || !pays(walk)) {
584
+ return;
585
+ }
586
+
587
+ if (polygonContains(part, point)) {
588
+ held += 1;
589
+ yield point;
590
+ }
591
+ }
592
+ }
593
+
594
+ /**
595
+ * edgePoint answers a point beside one of a polygon's longest edges, on its inner side: the last
596
+ * resort, which answers wherever the polygon has an inside, with no search.
597
+ *
598
+ * Within half the distance from an edge's middle to every other edge, the edge is the only part
599
+ * of the outline, so of the two points that far from the middle on either side of it, exactly
600
+ * one is inside by the even-odd rule. An edge another lies along, or crosses at its middle, has
601
+ * no such distance and is passed over. Linear in the edges for each edge tried, and a handful are.
602
+ */
603
+ const edgePoint = (polygon: PlanePolygon): PlanePoint | null => {
604
+ const edges: { readonly from: PlanePoint; readonly length: number; readonly to: PlanePoint }[] =
605
+ [];
606
+ for (const ring of polygon) {
607
+ let previous = ring[ring.length - 1];
608
+ for (const current of ring) {
609
+ if (previous !== undefined) {
610
+ const length = Math.hypot(current[0] - previous[0], current[1] - previous[1]);
611
+ if (length > 0) {
612
+ edges.push({ from: previous, length, to: current });
613
+ }
614
+ }
615
+
616
+ previous = current;
617
+ }
618
+ }
619
+
620
+ edges.sort((left, right) => right.length - left.length);
621
+ for (const edge of edges.slice(0, EDGE_POINT_TRIES)) {
622
+ const middleX = (edge.from[0] + edge.to[0]) / 2;
623
+ const middleY = (edge.from[1] + edge.to[1]) / 2;
624
+ let nearest = Number.POSITIVE_INFINITY;
625
+ for (const other of edges) {
626
+ if (other !== edge) {
627
+ nearest = Math.min(nearest, segmentDistanceSquared(middleX, middleY, other.from, other.to));
628
+ }
629
+ }
630
+
631
+ const offset = Math.sqrt(nearest) / 2;
632
+ if (!(offset > 0) || !Number.isFinite(offset)) {
633
+ continue;
634
+ }
635
+
636
+ const normalX = (-(edge.to[1] - edge.from[1]) / edge.length) * offset;
637
+ const normalY = ((edge.to[0] - edge.from[0]) / edge.length) * offset;
638
+ for (const side of [1, -1]) {
639
+ const point: PlanePoint = [middleX + side * normalX, middleY + side * normalY];
640
+ if (polygonContains(polygon, point)) {
641
+ return point;
642
+ }
643
+ }
644
+ }
645
+
646
+ return null;
647
+ };
648
+
649
+ /**
650
+ * InteriorSearchBudget is how much work a search for an interior point may still do, in edge
651
+ * visits. A search takes from it as it reads each square, so one budget handed to several
652
+ * searches bounds them together.
653
+ */
654
+ export interface InteriorSearchBudget {
655
+ visits: number;
656
+ }
657
+
658
+ /**
659
+ * interiorPoint answers a point inside a polygon: the one furthest from its outline and its
660
+ * holes, the pole of inaccessibility, as near as its budget lets the search come. Among points
661
+ * as far inside as one another it answers the middle of the polygon's box where that is one.
662
+ *
663
+ * The search is the one MapLibre lays a polygon's label out with, which it does not publish: the
664
+ * polygon's box is covered with squares, the square whose middle is furthest inside is kept, and
665
+ * a square is split in four while some point of it could still beat the best by more than the
666
+ * precision, a hundredth of the polygon's shorter side and never coarser than one unit. A
667
+ * centroid would not do: it lies in the bay of a concave zone and in the hole of a ring-shaped
668
+ * one.
669
+ *
670
+ * Its cost has no bound of its own: a shape whose furthest points run along long ridges (a comb,
671
+ * a corridor, a block of streets) keeps every square along them in play. So each square is paid
672
+ * for out of `budget`, at one visit an edge and one a badge to keep clear of, and the search
673
+ * stops at the first square it cannot pay for, with the best point it found. A point inside is
674
+ * all a badge needs; the furthest one is a nicety.
675
+ *
676
+ * Where no square it could pay for had its middle inside, the answer is the middle of the widest
677
+ * stretch of the polygon along a scanline, and failing that a point beside one of its longest
678
+ * edges. Neither is searched, and each costs a few walks of the edges, so the answer is null only
679
+ * for a polygon with no inside at all: one that encloses no area, or one its own holes cover.
680
+ *
681
+ * With `avoid`, the search prefers points at least `room` away from each of them: where badges
682
+ * already stand. Where the polygon leaves no such room it answers the point furthest inside it
683
+ * among those it read, and a badge then stands on another rather than not at all.
684
+ *
685
+ * @param polygon The polygon, outline first.
686
+ * @param budget The work the search may do, which it takes from. Left out, a zone's worth.
687
+ * @param avoid Points to keep `room` away from where the polygon has space for it.
688
+ * @param room How far from each point of `avoid` to keep.
689
+ * @returns A point strictly inside the polygon, or null when it has no inside.
690
+ */
691
+ export const interiorPoint = (
692
+ polygon: PlanePolygon,
693
+ budget: InteriorSearchBudget = { visits: ZONE_BADGE_SEARCH_VISITS },
694
+ avoid: readonly PlanePoint[] = [],
695
+ room = 0,
696
+ ): PlanePoint | null => {
697
+ const bounds = boundsOf(polygon);
698
+ if (bounds === null) {
699
+ return null;
700
+ }
701
+
702
+ const width = bounds.maxX - bounds.minX;
703
+ const height = bounds.maxY - bounds.minY;
704
+ const shorter = Math.min(width, height);
705
+ const longer = Math.max(width, height);
706
+ if (!(longer > 0) || !Number.isFinite(longer)) {
707
+ return null;
708
+ }
709
+
710
+ const precision = Math.min(INTERIOR_PRECISION_MAX, shorter * INTERIOR_PRECISION_SHARE);
711
+ const cost = edgeCount(polygon) + avoid.length;
712
+ const read = (x: number, y: number, half: number): SearchCell | null => {
713
+ if (budget.visits < cost) {
714
+ return null;
715
+ }
716
+
717
+ budget.visits -= cost;
718
+
719
+ return searchCell(polygon, x, y, half, avoid, room);
720
+ };
721
+
722
+ const chosen: SearchChoice = { best: null, inside: null };
723
+ const consider = (cell: SearchCell): void => {
724
+ // The middle of the box is read first, and a square takes the place of the best only by
725
+ // clearing it by more than half the precision. Where the furthest point is no single point
726
+ // (a rectangle holds a run of them along its longer side) the answer is then the one nearest
727
+ // the middle, whatever the last digit of a coordinate says.
728
+ const { best, inside } = chosen;
729
+ if (
730
+ best === null ||
731
+ (!(best.clearance > 0) && cell.clearance > best.clearance) ||
732
+ cell.clearance > best.clearance + precision / 2
733
+ ) {
734
+ chosen.best = cell;
735
+ }
736
+
737
+ if (cell.edge > 0 && (inside === null || cell.edge > inside.edge)) {
738
+ chosen.inside = cell;
739
+ }
740
+ };
741
+
742
+ const middle = read(bounds.minX + width / 2, bounds.minY + height / 2, 0);
743
+ if (middle !== null) {
744
+ consider(middle);
745
+ }
746
+
747
+ // A middle outside the polygon is a poor first best: a point on a scanline across it starts
748
+ // the search from inside instead.
749
+ let scanned: PlanePoint | null | undefined;
750
+ if (chosen.inside === null) {
751
+ scanned = scanlinePoint(polygon, bounds);
752
+ const seed = scanned === null ? null : read(scanned[0], scanned[1], 0);
753
+ if (seed !== null) {
754
+ consider(seed);
755
+ }
756
+ }
757
+
758
+ // A thin shape is covered along its longer side by a bounded row of squares rather than by
759
+ // one square per width of its shorter side, which would be a row with no end to it.
760
+ const size = Math.max(shorter, longer / INTERIOR_CELLS_ALONG);
761
+ const heap: SearchCell[] = [];
762
+ let paid = true;
763
+ for (let x = bounds.minX; paid && x < bounds.maxX; x += size) {
764
+ for (let y = bounds.minY; paid && y < bounds.maxY; y += size) {
765
+ const cell = read(x + size / 2, y + size / 2, size / 2);
766
+ if (cell === null) {
767
+ paid = false;
768
+ } else {
769
+ consider(cell);
770
+ pushCell(heap, cell);
771
+ }
772
+ }
773
+ }
774
+
775
+ for (let cell = popCell(heap); paid && cell !== undefined; cell = popCell(heap)) {
776
+ // No point of this square beats the best by more than the precision, and no square left on
777
+ // the heap reaches further than this one.
778
+ if (chosen.best !== null && cell.reach - chosen.best.clearance <= precision) {
779
+ break;
780
+ }
781
+
782
+ const half = cell.half / 2;
783
+ for (const [dx, dy] of QUARTERS) {
784
+ const quarter = read(cell.x + dx * half, cell.y + dy * half, half);
785
+ if (quarter === null) {
786
+ paid = false;
787
+ break;
788
+ }
789
+
790
+ consider(quarter);
791
+ pushCell(heap, quarter);
792
+ }
793
+ }
794
+
795
+ if (chosen.best !== null && chosen.best.clearance > 0) {
796
+ return [chosen.best.x, chosen.best.y];
797
+ }
798
+
799
+ if (chosen.inside !== null) {
800
+ return [chosen.inside.x, chosen.inside.y];
801
+ }
802
+
803
+ if (scanned === undefined) {
804
+ scanned = scanlinePoint(polygon, bounds);
805
+ }
806
+
807
+ return scanned ?? edgePoint(polygon);
808
+ };
809
+
810
+ /** The four quarters a square of the search splits into, as signs of the offset from its middle. */
811
+ const QUARTERS = [
812
+ [-1, -1],
813
+ [1, -1],
814
+ [-1, 1],
815
+ [1, 1],
816
+ ] as const;
817
+
818
+ /**
819
+ * solveLinear solves a square system of linear equations by Gaussian elimination, taking the
820
+ * largest pivot of each column.
821
+ *
822
+ * @param rows The system, each row its coefficients followed by its right-hand side.
823
+ * @returns The unknowns, or null when the equations do not determine them.
824
+ */
825
+ const solveLinear = (rows: number[][]): number[] | null => {
826
+ const size = rows.length;
827
+ for (let column = 0; column < size; column += 1) {
828
+ let pivot = column;
829
+ for (let row = column + 1; row < size; row += 1) {
830
+ if (Math.abs(rows[row]?.[column] ?? 0) > Math.abs(rows[pivot]?.[column] ?? 0)) {
831
+ pivot = row;
832
+ }
833
+ }
834
+
835
+ const pivotRow = rows[pivot];
836
+ const displaced = rows[column];
837
+ if (pivotRow === undefined || displaced === undefined) {
838
+ return null;
839
+ }
840
+
841
+ const lead = pivotRow[column] ?? 0;
842
+ if (Math.abs(lead) < 1e-12) {
843
+ return null;
844
+ }
845
+
846
+ rows[pivot] = displaced;
847
+ rows[column] = pivotRow;
848
+ for (let row = column + 1; row < size; row += 1) {
849
+ const target = rows[row];
850
+ if (target === undefined) {
851
+ continue;
852
+ }
853
+
854
+ const factor = (target[column] ?? 0) / lead;
855
+ for (let index = column; index <= size; index += 1) {
856
+ target[index] = (target[index] ?? 0) - factor * (pivotRow[index] ?? 0);
857
+ }
858
+ }
859
+ }
860
+
861
+ const solution = new Array<number>(size).fill(0);
862
+ for (let row = size - 1; row >= 0; row -= 1) {
863
+ const current = rows[row];
864
+ if (current === undefined) {
865
+ return null;
866
+ }
867
+
868
+ let rest = current[size] ?? 0;
869
+ for (let index = row + 1; index < size; index += 1) {
870
+ rest -= (current[index] ?? 0) * (solution[index] ?? 0);
871
+ }
872
+
873
+ solution[row] = rest / (current[row] ?? 1);
874
+ }
875
+
876
+ return solution;
877
+ };
878
+
879
+ /** A quad written about its own middle, at its own size, which keeps the solve well conditioned. */
880
+ interface Frame {
881
+ readonly centerX: number;
882
+ readonly centerY: number;
883
+ readonly scale: number;
884
+ }
885
+
886
+ const frameOf = (quad: PlaneQuad): Frame | null => {
887
+ const centerX = (quad[0][0] + quad[1][0] + quad[2][0] + quad[3][0]) / 4;
888
+ const centerY = (quad[0][1] + quad[1][1] + quad[2][1] + quad[3][1]) / 4;
889
+ const spread =
890
+ quad.reduce((sum, [x, y]) => sum + Math.hypot(x - centerX, y - centerY), 0) / quad.length;
891
+
892
+ return spread > 0 && Number.isFinite(spread) ? { centerX, centerY, scale: 1 / spread } : null;
893
+ };
894
+
895
+ /**
896
+ * PlaneProjection carries positions between the ground and the screen that shows it, for a view
897
+ * read off its four corners.
898
+ */
899
+ interface PlaneProjection {
900
+ /**
901
+ * ahead cuts off the part of a ground polygon behind the viewer, and answers the rest still on
902
+ * the ground, or null when all of it is behind.
903
+ */
904
+ readonly ahead: (polygon: PlanePolygon) => PlanePolygon | null;
905
+ /**
906
+ * project draws a ground polygon on the screen. The part of it behind the viewer is cut off
907
+ * first: ground there has no place on the screen, and a corner carried across anyway lands
908
+ * mirrored on the far side of it.
909
+ *
910
+ * @returns The polygon in screen pixels, or null when all of it is behind the viewer.
911
+ */
912
+ readonly project: (polygon: PlanePolygon) => PlanePolygon | null;
913
+ /** toGround answers the ground a screen position shows. */
914
+ readonly toGround: (screen: PlanePoint) => PlanePoint;
915
+ /** toScreen answers where a ground position is drawn, or null for ground behind the viewer. */
916
+ readonly toScreen: (ground: PlanePoint) => PlanePoint | null;
917
+ }
918
+
919
+ /**
920
+ * planeProjection reads the projection between flat ground and a screen off four corners of the
921
+ * screen and the ground each one shows.
922
+ *
923
+ * A camera over flat ground draws it through a homography: straight lines stay straight, and
924
+ * four points and their images determine it whatever the camera's turn, tilt, field of view and
925
+ * padding are. So the renderer is asked for four corners and for nothing about its camera, and
926
+ * every other position is carried across by arithmetic.
927
+ *
928
+ * @param ground The ground the four corners show, clockwise from the top left of the screen.
929
+ * @param screen The four corners on the screen, in the same order.
930
+ * @returns The projection, or null when the corners outline no view: a quad with no area, or one
931
+ * that crosses itself or folds back, which is what corners read above the horizon give.
932
+ */
933
+ export const planeProjection = (ground: PlaneQuad, screen: PlaneQuad): PlaneProjection | null => {
934
+ const from = frameOf(ground);
935
+ const to = frameOf(screen);
936
+ if (from === null || to === null) {
937
+ return null;
938
+ }
939
+
940
+ const rows: number[][] = [];
941
+ for (const [index, [groundX, groundY]] of ground.entries()) {
942
+ const [screenX, screenY] = screen[index] ?? [0, 0];
943
+ const x = (groundX - from.centerX) * from.scale;
944
+ const y = (groundY - from.centerY) * from.scale;
945
+ const u = (screenX - to.centerX) * to.scale;
946
+ const v = (screenY - to.centerY) * to.scale;
947
+ rows.push([x, y, 1, 0, 0, 0, -u * x, -u * y, u], [0, 0, 0, x, y, 1, -v * x, -v * y, v]);
948
+ }
949
+
950
+ const solved = solveLinear(rows);
951
+ if (solved === null) {
952
+ return null;
953
+ }
954
+
955
+ const [a = 0, b = 0, c = 0, d = 0, e = 0, f = 0, g = 0, h = 0] = solved;
956
+ // The depth of a ground position: one at the middle of the ground quad, zero on the line the
957
+ // viewer stands over, negative behind it. A view has every corner in front of the viewer.
958
+ const depthAt = (x: number, y: number): number => g * x + h * y + 1;
959
+ for (const [groundX, groundY] of ground) {
960
+ const depth = depthAt(
961
+ (groundX - from.centerX) * from.scale,
962
+ (groundY - from.centerY) * from.scale,
963
+ );
964
+ if (!(depth > FRONT_DEPTH)) {
965
+ return null;
966
+ }
967
+ }
968
+
969
+ const determinant = a * (e - f * h) - b * (d - f * g) + c * (d * h - e * g);
970
+ if (!(Math.abs(determinant) > 1e-12) || !Number.isFinite(determinant)) {
971
+ return null;
972
+ }
973
+
974
+ // The inverse, up to a factor the division below cancels.
975
+ const inverse = [
976
+ e - f * h,
977
+ c * h - b,
978
+ b * f - c * e,
979
+ f * g - d,
980
+ a - c * g,
981
+ c * d - a * f,
982
+ d * h - e * g,
983
+ b * g - a * h,
984
+ a * e - b * d,
985
+ ] as const;
986
+
987
+ // Where a ground position is drawn, given the depth to draw it at.
988
+ const drawAt = (x: number, y: number, depth: number): PlanePoint => [
989
+ (a * x + b * y + c) / depth / to.scale + to.centerX,
990
+ (d * x + e * y + f) / depth / to.scale + to.centerY,
991
+ ];
992
+
993
+ const toScreen = ([groundX, groundY]: PlanePoint): PlanePoint | null => {
994
+ const x = (groundX - from.centerX) * from.scale;
995
+ const y = (groundY - from.centerY) * from.scale;
996
+ const depth = depthAt(x, y);
997
+
998
+ return depth >= FRONT_DEPTH ? drawAt(x, y, depth) : null;
999
+ };
1000
+
1001
+ const toGround = ([screenX, screenY]: PlanePoint): PlanePoint => {
1002
+ const u = (screenX - to.centerX) * to.scale;
1003
+ const v = (screenY - to.centerY) * to.scale;
1004
+ const weight = inverse[6] * u + inverse[7] * v + inverse[8];
1005
+
1006
+ return [
1007
+ (inverse[0] * u + inverse[1] * v + inverse[2]) / weight / from.scale + from.centerX,
1008
+ (inverse[3] * u + inverse[4] * v + inverse[5]) / weight / from.scale + from.centerY,
1009
+ ];
1010
+ };
1011
+
1012
+ // The ground in front of the viewer, as a line in the ground's own coordinates.
1013
+ const front: readonly [number, number, number] = [
1014
+ g * from.scale,
1015
+ h * from.scale,
1016
+ 1 - FRONT_DEPTH - (g * from.centerX + h * from.centerY) * from.scale,
1017
+ ];
1018
+
1019
+ const ahead = (polygon: PlanePolygon): PlanePolygon | null => clipPolygon(polygon, [front]);
1020
+
1021
+ const project = (polygon: PlanePolygon): PlanePolygon | null => {
1022
+ const kept = ahead(polygon);
1023
+ if (kept === null) {
1024
+ return null;
1025
+ }
1026
+
1027
+ // A point the cut made lies on the line itself, where rounding can read its depth a hair
1028
+ // short of the line's: it is drawn at the line's depth, never dropped.
1029
+ return kept.map((ring) =>
1030
+ ring.map(([groundX, groundY]) => {
1031
+ const x = (groundX - from.centerX) * from.scale;
1032
+ const y = (groundY - from.centerY) * from.scale;
1033
+
1034
+ return drawAt(x, y, Math.max(depthAt(x, y), FRONT_DEPTH));
1035
+ }),
1036
+ );
1037
+ };
1038
+
1039
+ return { ahead, project, toGround, toScreen };
1040
+ };
1041
+
1042
+ /**
1043
+ * groundOf places a longitude and latitude on the unit square Web Mercator lays the world on:
1044
+ * 0 to 1 eastward from the antimeridian, 0 to 1 southward from the projection's northern edge.
1045
+ * A longitude counted on past the antimeridian lands past the square, on the next copy of the
1046
+ * world, which is where a renderer panned across the line draws it.
1047
+ *
1048
+ * The ordinate is the projection's own, in the form that reads the latitude's sine:
1049
+ * `ln((1 + sin φ) / (1 - sin φ)) / 2` is the Mercator northing of a latitude φ.
1050
+ */
1051
+ const groundOf = ([lng = 0, lat = 0]: readonly number[]): PlanePoint => {
1052
+ const latitude = Math.max(-WEB_MERCATOR_MAX_LAT, Math.min(WEB_MERCATOR_MAX_LAT, lat));
1053
+ const sine = Math.sin(latitude * DEGREES_TO_RADIANS);
1054
+
1055
+ return [lng / DEGREES_PER_TURN + 0.5, 0.5 - Math.log((1 + sine) / (1 - sine)) / (4 * Math.PI)];
1056
+ };
1057
+
1058
+ /**
1059
+ * lngLatOf reads a ground position back as a longitude within the wire's range and a latitude:
1060
+ * the inverse of {@link groundOf}, whose northing a latitude's sine is the hyperbolic tangent of.
1061
+ */
1062
+ const lngLatOf = ([x, y]: PlanePoint): LngLat => [
1063
+ wrapLongitude((x - 0.5) * DEGREES_PER_TURN),
1064
+ Math.asin(Math.tanh((0.5 - y) * 2 * Math.PI)) / DEGREES_TO_RADIANS,
1065
+ ];
1066
+
1067
+ /**
1068
+ * groundRing writes a GeoJSON ring on the ground, a whole number of worlds across from where it
1069
+ * is written, and without the closing position GeoJSON repeats.
1070
+ */
1071
+ const groundRing = (ring: readonly Position[], worlds: number): PlanePoint[] => {
1072
+ const points: PlanePoint[] = [];
1073
+ for (const position of ring) {
1074
+ const [x, y] = groundOf(position);
1075
+ points.push([x + worlds, y]);
1076
+ }
1077
+
1078
+ const first = points[0];
1079
+ const last = points[points.length - 1];
1080
+ if (points.length > 1 && first !== undefined && last !== undefined) {
1081
+ if (first[0] === last[0] && first[1] === last[1]) {
1082
+ points.pop();
1083
+ }
1084
+ }
1085
+
1086
+ return points;
1087
+ };
1088
+
1089
+ /**
1090
+ * ZonePolygon is one polygon of a piece of a zone, located on the ground before it is written
1091
+ * there: the box its outline spans on the ground, and the polygon itself, written once and only
1092
+ * when something reads it. Writing a polygon is a sine and a logarithm a position, so a zone of
1093
+ * ten thousand positions in a dozen pieces is written only where a placement needs it.
1094
+ */
1095
+ interface ZonePolygon {
1096
+ readonly box: PlaneRectangle;
1097
+ /** How many edges its rings hold: what a walk of them costs, in visits. */
1098
+ readonly edges: number;
1099
+ readonly written: () => PlanePolygon;
1100
+ }
1101
+
1102
+ /**
1103
+ * zonePolygons locates a zone geometry's polygons on the ground, each on the copy of the world
1104
+ * nearest a longitude: the middle of the view.
1105
+ *
1106
+ * A tile writes its longitudes within one turn, and a view across the antimeridian counts on
1107
+ * past it, so the two halves of a zone the line splits are written a whole world apart. Each
1108
+ * polygon is moved by the number of worlds that brings its middle nearest the view's.
1109
+ */
1110
+ const zonePolygons = (geometry: Geometry, aroundX: number): ZonePolygon[] => {
1111
+ const written =
1112
+ geometry.type === "Polygon"
1113
+ ? [geometry.coordinates]
1114
+ : geometry.type === "MultiPolygon"
1115
+ ? geometry.coordinates
1116
+ : [];
1117
+
1118
+ const polygons: ZonePolygon[] = [];
1119
+ for (const rings of written) {
1120
+ const [outline] = rings;
1121
+ if (outline === undefined || outline.length < 3) {
1122
+ continue;
1123
+ }
1124
+
1125
+ let west = Number.POSITIVE_INFINITY;
1126
+ let east = Number.NEGATIVE_INFINITY;
1127
+ let south = Number.POSITIVE_INFINITY;
1128
+ let north = Number.NEGATIVE_INFINITY;
1129
+ for (const [lng = 0, lat = 0] of outline) {
1130
+ west = Math.min(west, lng);
1131
+ east = Math.max(east, lng);
1132
+ south = Math.min(south, lat);
1133
+ north = Math.max(north, lat);
1134
+ }
1135
+
1136
+ const worlds = Math.round(aroundX - ((west + east) / 2 / DEGREES_PER_TURN + 0.5));
1137
+ const [minX, minY] = groundOf([west, north]);
1138
+ const [maxX, maxY] = groundOf([east, south]);
1139
+ let ground: PlanePolygon | null = null;
1140
+ polygons.push({
1141
+ box: { maxX: maxX + worlds, maxY, minX: minX + worlds, minY },
1142
+ edges: rings.reduce((count, ring) => count + ring.length, 0),
1143
+ written: () => {
1144
+ ground ??= rings.map((ring) => groundRing(ring, worlds));
1145
+
1146
+ return ground;
1147
+ },
1148
+ });
1149
+ }
1150
+
1151
+ return polygons;
1152
+ };
1153
+
1154
+ /**
1155
+ * ZoneFeature is one piece of a zone as the renderer hands it over: the geometry a tile carries
1156
+ * for it, in longitudes and latitudes, and the zone's properties, its `id` among them.
1157
+ *
1158
+ * A feature MapLibre answers a query with is one. Its geometry is read only where a placement
1159
+ * needs it, which matters for a renderer that decodes it on the first read.
1160
+ */
1161
+ export interface ZoneFeature {
1162
+ readonly geometry: Geometry;
1163
+ readonly properties: Readonly<Record<string, unknown>> | null;
1164
+ }
1165
+
1166
+ /**
1167
+ * ZoneBadgeSurface is the renderer's own projection of the ground it draws, relief included, for
1168
+ * a view drawn over relief. Flat ground is a projection four corners determine; ground over relief
1169
+ * is not, and a place on a hill is drawn higher on the screen than flat ground puts it.
1170
+ */
1171
+ export interface ZoneBadgeSurface {
1172
+ /** Where a place is drawn on the screen, at its height, in CSS pixels. */
1173
+ readonly project: (lngLat: LngLat) => PlanePoint;
1174
+ /**
1175
+ * The place a pixel of the screen shows: on the surface nearest the viewer, so never one that
1176
+ * relief in front of it hides.
1177
+ */
1178
+ readonly unproject: (point: PlanePoint) => LngLat;
1179
+ }
1180
+
1181
+ /** ZoneBadgeViewport is the view badges are placed in: the screen's size and the ground it shows. */
1182
+ export interface ZoneBadgeViewport {
1183
+ /**
1184
+ * The longitude and latitude each corner of the screen shows, clockwise from the top left, as
1185
+ * the renderer unprojects them: counted on past the antimeridian where the view crosses it.
1186
+ */
1187
+ readonly corners: readonly [
1188
+ readonly [number, number],
1189
+ readonly [number, number],
1190
+ readonly [number, number],
1191
+ readonly [number, number],
1192
+ ];
1193
+ /** The screen's height, in CSS pixels. */
1194
+ readonly height: number;
1195
+ /**
1196
+ * The renderer's projection over relief, where the view is drawn over relief. Left out, the
1197
+ * ground is flat and the four corners say where all of it is drawn.
1198
+ */
1199
+ readonly surface?: ZoneBadgeSurface | undefined;
1200
+ /** The screen's width, in CSS pixels. */
1201
+ readonly width: number;
1202
+ }
1203
+
1204
+ /** ZoneBadge is the badge of one zone: where it stands, and the zone's properties. */
1205
+ export interface ZoneBadge {
1206
+ readonly lngLat: LngLat;
1207
+ readonly properties: Readonly<Record<string, unknown>>;
1208
+ }
1209
+
1210
+ /** The zone a piece belongs to: its `id` property, or null for a piece that states none. */
1211
+ const zoneIdOf = (feature: ZoneFeature): string | null => {
1212
+ const id = feature.properties?.id;
1213
+
1214
+ return typeof id === "string" || typeof id === "number" ? String(id) : null;
1215
+ };
1216
+
1217
+ /** insetOf is the screen less a margin along each edge, or null when the margin leaves nothing. */
1218
+ const insetOf = (viewport: ZoneBadgeViewport, margin: number): PlaneRectangle | null =>
1219
+ viewport.width > margin * 2 && viewport.height > margin * 2
1220
+ ? {
1221
+ maxX: viewport.width - margin,
1222
+ maxY: viewport.height - margin,
1223
+ minX: margin,
1224
+ minY: margin,
1225
+ }
1226
+ : null;
1227
+
1228
+ /**
1229
+ * TakenRoom is where the badges decided so far stand on the screen, filed by squares as wide as a
1230
+ * badge's room, so a zone asks for the few near it rather than for all of them.
1231
+ */
1232
+ interface TakenRoom {
1233
+ /** add files a badge standing at a point of the screen. */
1234
+ readonly add: (point: PlanePoint) => void;
1235
+ /** covers reports whether a badge already stands closer to a point than its room, less a slack. */
1236
+ readonly covers: (point: PlanePoint) => boolean;
1237
+ /** near answers the badges standing within a room of a rectangle. */
1238
+ readonly near: (rectangle: PlaneRectangle) => PlanePoint[];
1239
+ }
1240
+
1241
+ const takenRoom = (room: number): TakenRoom => {
1242
+ const squares = new Map<string, PlanePoint[]>();
1243
+ const square = (value: number): number => Math.floor(value / room);
1244
+ const within = (rectangle: PlaneRectangle): PlanePoint[] => {
1245
+ const found: PlanePoint[] = [];
1246
+ for (let x = square(rectangle.minX - room); x <= square(rectangle.maxX + room); x += 1) {
1247
+ for (let y = square(rectangle.minY - room); y <= square(rectangle.maxY + room); y += 1) {
1248
+ found.push(...(squares.get(`${x},${y}`) ?? []));
1249
+ }
1250
+ }
1251
+
1252
+ return found;
1253
+ };
1254
+
1255
+ return {
1256
+ add: (point) => {
1257
+ const key = `${square(point[0])},${square(point[1])}`;
1258
+ squares.set(key, [...(squares.get(key) ?? []), point]);
1259
+ },
1260
+ covers: ([x, y]) =>
1261
+ within({ maxX: x, maxY: y, minX: x, minY: y }).some(
1262
+ ([otherX, otherY]) => Math.hypot(x - otherX, y - otherY) < room - COVER_SLACK_PX,
1263
+ ),
1264
+ near: within,
1265
+ };
1266
+ };
1267
+
1268
+ /** A point a placement found, and the part of the zone on screen it found it in. */
1269
+ interface PlacedPoint {
1270
+ readonly part: PlanePolygon;
1271
+ readonly point: PlanePoint;
1272
+ }
1273
+
1274
+ /** Where a badge is placed: its place, and the pixel it is drawn at. */
1275
+ interface PlacedSpot {
1276
+ readonly lngLat: LngLat;
1277
+ readonly point: PlanePoint;
1278
+ }
1279
+
1280
+ /**
1281
+ * placeOn answers a point inside the largest part of a zone a rectangle of the screen holds, as
1282
+ * far from the badges taken as the part leaves room for, with that part, or null when the
1283
+ * rectangle holds none of the zone. Every search it runs takes from the one budget.
1284
+ */
1285
+ const placeOn = (
1286
+ drawn: readonly PlanePolygon[],
1287
+ rectangle: PlaneRectangle | null,
1288
+ budget: InteriorSearchBudget,
1289
+ taken: TakenRoom,
1290
+ ): PlacedPoint | null => {
1291
+ if (rectangle === null) {
1292
+ return null;
1293
+ }
1294
+
1295
+ const parts: { readonly area: number; readonly polygon: PlanePolygon }[] = [];
1296
+ for (const polygon of drawn) {
1297
+ const part = clipPolygonToRectangle(polygon, rectangle);
1298
+ if (part !== null) {
1299
+ parts.push({ area: polygonArea(part), polygon: part });
1300
+ }
1301
+ }
1302
+
1303
+ parts.sort((left, right) => right.area - left.area);
1304
+ for (const { polygon } of parts) {
1305
+ const bounds = boundsOf(polygon);
1306
+ const avoid = bounds === null ? [] : taken.near(bounds);
1307
+ const point = interiorPoint(polygon, budget, avoid, ZONE_BADGE_ROOM_PX);
1308
+ if (point !== null) {
1309
+ return { part: polygon, point };
1310
+ }
1311
+ }
1312
+
1313
+ return null;
1314
+ };
1315
+
1316
+ /** One zone a placement holds: its id, its polygons on the ground, and its properties. */
1317
+ interface PlacedZone {
1318
+ readonly id: string;
1319
+ /** The polygons of every piece of the zone, located on the ground, written when read. */
1320
+ readonly polygons: readonly ZonePolygon[];
1321
+ readonly properties: Readonly<Record<string, unknown>>;
1322
+ }
1323
+
1324
+ /** boxContains reports whether a box holds a point, its edges included. */
1325
+ const boxContains = (box: PlaneRectangle, [x, y]: PlanePoint): boolean =>
1326
+ x >= box.minX && x <= box.maxX && y >= box.minY && y <= box.maxY;
1327
+
1328
+ /**
1329
+ * placeZoneBadgesStepwise answers where the badge of each zone on screen stands, one zone at a
1330
+ * time: one badge per zone, at a point inside the part of the zone the screen shows.
1331
+ *
1332
+ * The pieces are grouped by the zone's `id`, whichever tile or source handed each over, so a zone
1333
+ * in a dozen tiles, or drawn by two sources, has one badge. A piece that states no `id` belongs
1334
+ * to no zone and is passed over. Zones are taken in the order of their ids, so the same pieces
1335
+ * give the same badges whatever order the renderer answered them in.
1336
+ *
1337
+ * The first step keeps every badge that stands: a zone that had one keeps it, the same `lngLat`
1338
+ * by identity, while that point is still on one of the zone's pieces, inside the screen less
1339
+ * {@link ZONE_BADGE_KEEP_MARGIN_PX}, and not covered by a badge kept before it. A tile more or
1340
+ * less of the zone moves nothing.
1341
+ *
1342
+ * Every other zone is then placed, one a step: those with no badge first, then those whose badge
1343
+ * left. A badge is placed at the interior point of the zone's polygon whose box covers most of
1344
+ * the screen, looked for first where it has room on every side and, for a zone that shows only
1345
+ * along an edge, on the whole screen, and away from every badge already decided where the zone
1346
+ * leaves room for that. The next polygon is tried only where that one shows nothing, and the
1347
+ * others are never written on the ground at all. A zone with no part on screen has no badge, and
1348
+ * neither has a ring-shaped one whose hole covers the screen. A zone waiting for its step keeps
1349
+ * the badge it had meanwhile.
1350
+ *
1351
+ * Each step is bounded by {@link ZONE_BADGE_SEARCH_VISITS}. The badges that stand are read that
1352
+ * much at a time. A zone's placement reads one polygon a step, a few walks of its edges, and pays
1353
+ * its search, and over relief every place drawn and every pixel read through the renderer (at
1354
+ * {@link ZONE_BADGE_PROJECT_VISITS} and {@link ZONE_BADGE_UNPROJECT_VISITS}), out of that budget.
1355
+ * A zone whose polygons show nothing takes a step for each it tries. The steps yield the
1356
+ * placement so far, the one map every step writes to: copy it to keep it.
1357
+ *
1358
+ * @param features The pieces the renderer has on screen, of out-of-window zones alone.
1359
+ * @param previous The badges the last placement answered, by zone id.
1360
+ * @param viewport The screen's size and the ground its corners show.
1361
+ * @returns The badges by zone id once every zone is placed, or null at once when the viewport has
1362
+ * no size or its corners outline no view, in which case the badges drawn stand as they are.
1363
+ */
1364
+ export function* placeZoneBadgesStepwise(
1365
+ features: readonly ZoneFeature[],
1366
+ previous: ReadonlyMap<string, ZoneBadge>,
1367
+ viewport: ZoneBadgeViewport,
1368
+ ): Generator<ReadonlyMap<string, ZoneBadge>, Map<string, ZoneBadge> | null, unknown> {
1369
+ if (!(viewport.width > 0) || !(viewport.height > 0)) {
1370
+ return null;
1371
+ }
1372
+
1373
+ const [topLeft, topRight, bottomRight, bottomLeft] = viewport.corners;
1374
+ const ground: PlaneQuad = [
1375
+ groundOf(topLeft),
1376
+ groundOf(topRight),
1377
+ groundOf(bottomRight),
1378
+ groundOf(bottomLeft),
1379
+ ];
1380
+ const projection = planeProjection(ground, [
1381
+ [0, 0],
1382
+ [viewport.width, 0],
1383
+ [viewport.width, viewport.height],
1384
+ [0, viewport.height],
1385
+ ]);
1386
+ if (projection === null) {
1387
+ return null;
1388
+ }
1389
+
1390
+ const aroundX = (ground[0][0] + ground[1][0] + ground[2][0] + ground[3][0]) / 4;
1391
+ const keepWithin = insetOf(viewport, ZONE_BADGE_KEEP_MARGIN_PX);
1392
+ const placeWithin = [
1393
+ insetOf(viewport, ZONE_BADGE_PLACE_MARGIN_PX),
1394
+ keepWithin,
1395
+ insetOf(viewport, 0),
1396
+ ];
1397
+
1398
+ const surface = viewport.surface;
1399
+ // A ground position written as a longitude counted from the view's world, as a renderer draws
1400
+ // it across the antimeridian, and a place moved onto that world.
1401
+ const counted = ([x, y]: PlanePoint): LngLat => [
1402
+ (x - 0.5) * DEGREES_PER_TURN,
1403
+ lngLatOf([x, y])[1],
1404
+ ];
1405
+ const nearView = (lngLat: LngLat): PlanePoint => {
1406
+ const [x, y] = groundOf(lngLat);
1407
+
1408
+ return [x + Math.round(aroundX - x), y];
1409
+ };
1410
+ // How much of the view a zone drawn over relief is followed in: the screen and a screen's width
1411
+ // and height around it, where relief can carry ground onto the screen. A zone a continent wide
1412
+ // is not draped edge by edge beyond it.
1413
+ const around: PlaneRectangle = {
1414
+ maxX: viewport.width * 2,
1415
+ maxY: viewport.height * 2,
1416
+ minX: -viewport.width,
1417
+ minY: -viewport.height,
1418
+ };
1419
+
1420
+ /**
1421
+ * draw answers where a ground polygon is drawn on the screen: by the four corners' projection
1422
+ * over flat ground, or, over relief, by the renderer's, every edge followed in steps so that one
1423
+ * draped over a hill is read where it bends.
1424
+ *
1425
+ * Over relief each place drawn is paid for out of `budget`, at {@link ZONE_BADGE_PROJECT_VISITS},
1426
+ * and the drawing may take half of what is left. A polygon whose drape would cost more is drawn
1427
+ * over flat ground instead: its search runs there, and the points it finds are read back
1428
+ * through the renderer all the same, so a badge still stands where the zone shows.
1429
+ */
1430
+ const draw = (polygon: PlanePolygon, budget: InteriorSearchBudget): PlanePolygon | null => {
1431
+ const flat = projection.project(polygon);
1432
+ if (surface === undefined || flat === null) {
1433
+ return flat;
1434
+ }
1435
+
1436
+ const near = clipPolygonToRectangle(flat, around);
1437
+ if (near === null) {
1438
+ return null;
1439
+ }
1440
+
1441
+ const stepsOf = (from: PlanePoint, to: PlanePoint): number =>
1442
+ Math.max(1, Math.ceil(Math.hypot(to[0] - from[0], to[1] - from[1]) / DRAPE_STEP_PX));
1443
+ let places = 0;
1444
+ for (const ring of near) {
1445
+ for (const [index, current] of ring.entries()) {
1446
+ places += stepsOf(current, ring[(index + 1) % ring.length] ?? current);
1447
+ }
1448
+ }
1449
+
1450
+ const cost = places * ZONE_BADGE_PROJECT_VISITS;
1451
+ if (cost > budget.visits / 2) {
1452
+ return flat;
1453
+ }
1454
+
1455
+ budget.visits -= cost;
1456
+
1457
+ return near.map((ring) =>
1458
+ ring.flatMap((current, index) => {
1459
+ const next = ring[(index + 1) % ring.length] ?? current;
1460
+ const steps = stepsOf(current, next);
1461
+
1462
+ return Array.from({ length: steps }, (_, step): PlanePoint => {
1463
+ const share = step / steps;
1464
+
1465
+ return surface.project(
1466
+ counted(
1467
+ projection.toGround([
1468
+ current[0] + (next[0] - current[0]) * share,
1469
+ current[1] + (next[1] - current[1]) * share,
1470
+ ]),
1471
+ ),
1472
+ );
1473
+ });
1474
+ }),
1475
+ );
1476
+ };
1477
+
1478
+ /**
1479
+ * holds reports whether a zone's polygons hold a place, on the view's world, paying out of
1480
+ * `budget` a visit for each edge of each polygon it walks.
1481
+ */
1482
+ const holds = (zone: PlacedZone, lngLat: LngLat, budget: InteriorSearchBudget): boolean => {
1483
+ const at = nearView(lngLat);
1484
+
1485
+ return zone.polygons.some((polygon) => {
1486
+ if (!boxContains(polygon.box, at)) {
1487
+ return false;
1488
+ }
1489
+
1490
+ budget.visits -= polygon.edges;
1491
+
1492
+ return polygonContains(polygon.written(), at);
1493
+ });
1494
+ };
1495
+
1496
+ /** The most a walk of a zone's polygons costs, in visits. */
1497
+ const edgesOf = (zone: PlacedZone): number =>
1498
+ zone.polygons.reduce((count, polygon) => count + polygon.edges, 0);
1499
+
1500
+ /**
1501
+ * The most reading back one point over relief costs, in visits: the pixel's place, then a walk
1502
+ * of the zone's polygons for it.
1503
+ */
1504
+ const readingOf = (zone: PlacedZone): number => ZONE_BADGE_UNPROJECT_VISITS + edgesOf(zone);
1505
+
1506
+ /**
1507
+ * shows reports whether the screen shows a place at the pixel it is drawn at, rather than
1508
+ * relief in front of it: the place the pixel shows stands within a slack of it.
1509
+ */
1510
+ const shows = (lngLat: LngLat, drawnAt: PlanePoint, budget: InteriorSearchBudget): boolean => {
1511
+ if (surface === undefined) {
1512
+ return true;
1513
+ }
1514
+
1515
+ budget.visits -= ZONE_BADGE_UNPROJECT_VISITS;
1516
+ const seen = projection.toScreen(nearView(surface.unproject(drawnAt)));
1517
+ const own = projection.toScreen(nearView(lngLat));
1518
+
1519
+ return (
1520
+ seen !== null &&
1521
+ own !== null &&
1522
+ Math.hypot(seen[0] - own[0], seen[1] - own[1]) <= SHOWN_SLACK_PX
1523
+ );
1524
+ };
1525
+
1526
+ /**
1527
+ * placeAt answers the place a badge stands at for a point a search found on the screen. Over
1528
+ * flat ground it is the ground the point shows. Over relief it is the place the renderer shows
1529
+ * at that pixel, which relief cannot hide, where that place is on the zone; where relief in
1530
+ * front hides the zone there, other points of the part are tried: along scanlines across it,
1531
+ * then on a grid over it, the nearest the search's point first. Each is paid for out of
1532
+ * `budget`: finding it, then reading its pixel's place and walking the zone's edges for it.
1533
+ * Null where none of those it could pay for shows the zone.
1534
+ */
1535
+ const placeAt = (
1536
+ zone: PlacedZone,
1537
+ found: PlacedPoint,
1538
+ budget: InteriorSearchBudget,
1539
+ ): PlacedSpot | null => {
1540
+ if (surface === undefined) {
1541
+ return { lngLat: lngLatOf(projection.toGround(found.point)), point: found.point };
1542
+ }
1543
+
1544
+ const reading = readingOf(zone);
1545
+ const shown = (candidate: PlanePoint): PlacedSpot | null => {
1546
+ budget.visits -= ZONE_BADGE_UNPROJECT_VISITS;
1547
+ const seen = surface.unproject(candidate);
1548
+
1549
+ return holds(zone, seen, budget)
1550
+ ? { lngLat: [wrapLongitude(seen[0]), seen[1]], point: candidate }
1551
+ : null;
1552
+ };
1553
+
1554
+ if (budget.visits < reading) {
1555
+ return null;
1556
+ }
1557
+
1558
+ const own = shown(found.point);
1559
+ if (own !== null) {
1560
+ return own;
1561
+ }
1562
+
1563
+ for (const candidate of shownCandidates(found.part, found.point, budget, reading)) {
1564
+ const spot = shown(candidate);
1565
+ if (spot !== null) {
1566
+ return spot;
1567
+ }
1568
+ }
1569
+
1570
+ return null;
1571
+ };
1572
+
1573
+ const grouped = new Map<string, ZoneFeature[]>();
1574
+ for (const feature of features) {
1575
+ const id = zoneIdOf(feature);
1576
+ if (id === null) {
1577
+ continue;
1578
+ }
1579
+
1580
+ const pieces = grouped.get(id);
1581
+ if (pieces) {
1582
+ pieces.push(feature);
1583
+ } else {
1584
+ grouped.set(id, [feature]);
1585
+ }
1586
+ }
1587
+
1588
+ const badges = new Map<string, ZoneBadge>();
1589
+ const taken = takenRoom(ZONE_BADGE_ROOM_PX);
1590
+ const unbadged: PlacedZone[] = [];
1591
+ const standingZones: { readonly kept: ZoneBadge; readonly zone: PlacedZone }[] = [];
1592
+ for (const id of [...grouped.keys()].sort()) {
1593
+ const pieces = grouped.get(id) ?? [];
1594
+ const zone: PlacedZone = {
1595
+ id,
1596
+ polygons: pieces.flatMap((piece) => zonePolygons(piece.geometry, aroundX)),
1597
+ properties: pieces[0]?.properties ?? {},
1598
+ };
1599
+
1600
+ const kept = previous.get(id);
1601
+ if (kept === undefined) {
1602
+ unbadged.push(zone);
1603
+ } else {
1604
+ // It stands where it was until it is read, kept or placed again.
1605
+ badges.set(id, { lngLat: kept.lngLat, properties: zone.properties });
1606
+ standingZones.push({ kept, zone });
1607
+ }
1608
+ }
1609
+
1610
+ // The badges that stand are read a step's budget at a time: over relief each costs a drawing
1611
+ // and a reading through the renderer, and a crowd of them is no step of its own.
1612
+ const moved: PlacedZone[] = [];
1613
+ let step: InteriorSearchBudget = { visits: ZONE_BADGE_SEARCH_VISITS };
1614
+ for (const { kept, zone } of standingZones) {
1615
+ const most =
1616
+ edgesOf(zone) +
1617
+ (surface === undefined ? 0 : ZONE_BADGE_PROJECT_VISITS + ZONE_BADGE_UNPROJECT_VISITS);
1618
+ if (step.visits < ZONE_BADGE_SEARCH_VISITS && step.visits < most) {
1619
+ yield badges;
1620
+ step = { visits: ZONE_BADGE_SEARCH_VISITS };
1621
+ }
1622
+
1623
+ const standing = nearView(kept.lngLat);
1624
+ if (surface !== undefined) {
1625
+ step.visits -= ZONE_BADGE_PROJECT_VISITS;
1626
+ }
1627
+ const onScreen =
1628
+ surface === undefined ? projection.toScreen(standing) : surface.project(counted(standing));
1629
+ if (
1630
+ keepWithin !== null &&
1631
+ onScreen !== null &&
1632
+ onScreen[0] >= keepWithin.minX &&
1633
+ onScreen[0] <= keepWithin.maxX &&
1634
+ onScreen[1] >= keepWithin.minY &&
1635
+ onScreen[1] <= keepWithin.maxY &&
1636
+ !taken.covers(onScreen) &&
1637
+ holds(zone, kept.lngLat, step) &&
1638
+ shows(kept.lngLat, onScreen, step)
1639
+ ) {
1640
+ taken.add(onScreen);
1641
+ } else {
1642
+ moved.push(zone);
1643
+ }
1644
+ }
1645
+
1646
+ // How much of the screen a polygon's box covers: where its badge is looked for first.
1647
+ const screen = insetOf(viewport, 0);
1648
+ const cover = (box: PlaneRectangle): number => {
1649
+ const drawn = projection.project([
1650
+ [
1651
+ [box.minX, box.minY],
1652
+ [box.maxX, box.minY],
1653
+ [box.maxX, box.maxY],
1654
+ [box.minX, box.maxY],
1655
+ ],
1656
+ ]);
1657
+ const shown = drawn === null || screen === null ? null : clipPolygonToRectangle(drawn, screen);
1658
+
1659
+ return shown === null ? 0 : polygonArea(shown);
1660
+ };
1661
+
1662
+ const queue = [...unbadged, ...moved];
1663
+ // The reading of the badges that stand took a step of its own where it cost anything, so the
1664
+ // first zone placed starts a step with its whole budget.
1665
+ if (queue.length > 0 && step.visits < ZONE_BADGE_SEARCH_VISITS) {
1666
+ yield badges;
1667
+ }
1668
+
1669
+ for (const [index, zone] of queue.entries()) {
1670
+ // The polygon whose box covers most of the screen is written, drawn and searched first, and
1671
+ // the next only where it shows nothing: the others are never written at all. Pieces of one
1672
+ // zone overlap, so the one that covers most of the screen holds most of what shows of it.
1673
+ const ranked = zone.polygons
1674
+ .map((polygon) => ({ cover: cover(polygon.box), polygon }))
1675
+ .filter((entry) => entry.cover > 0)
1676
+ .sort((left, right) => right.cover - left.cover);
1677
+ const budget: InteriorSearchBudget = { visits: ZONE_BADGE_SEARCH_VISITS };
1678
+ let placed: PlacedSpot | null = null;
1679
+ for (const [tried, { polygon }] of ranked.entries()) {
1680
+ const drawn = draw(polygon.written(), budget);
1681
+ if (drawn !== null) {
1682
+ for (const rectangle of placeWithin) {
1683
+ // Over relief a point the budget could not read back is not looked for.
1684
+ if (surface !== undefined && budget.visits < readingOf(zone)) {
1685
+ break;
1686
+ }
1687
+
1688
+ // Over relief the search takes half of what is left, so the points it finds can be
1689
+ // read back through the renderer with the rest.
1690
+ const search: InteriorSearchBudget =
1691
+ surface === undefined ? budget : { visits: Math.floor(budget.visits / 2) };
1692
+ const allotted = search.visits;
1693
+ const found = placeOn([drawn], rectangle, search, taken);
1694
+ if (search !== budget) {
1695
+ budget.visits -= allotted - search.visits;
1696
+ }
1697
+
1698
+ placed = found === null ? null : placeAt(zone, found, budget);
1699
+ if (placed !== null) {
1700
+ break;
1701
+ }
1702
+ }
1703
+ }
1704
+
1705
+ if (placed === null && surface !== undefined) {
1706
+ // Relief in front hides every point tried: the badge stands on the zone all the same,
1707
+ // where flat ground would put it, rather than on the relief that hides it.
1708
+ const flat = projection.project(polygon.written());
1709
+ const found = flat === null ? null : placeOn([flat], placeWithin[2] ?? null, budget, taken);
1710
+ if (found !== null) {
1711
+ placed = { lngLat: lngLatOf(projection.toGround(found.point)), point: found.point };
1712
+ }
1713
+ }
1714
+
1715
+ if (placed !== null) {
1716
+ break;
1717
+ }
1718
+
1719
+ // A polygon tried is a step of its own: a zone of many pieces that show nothing spreads
1720
+ // over frames like many zones do.
1721
+ if (tried < ranked.length - 1) {
1722
+ yield badges;
1723
+ }
1724
+ }
1725
+
1726
+ if (placed === null) {
1727
+ badges.delete(zone.id);
1728
+ } else {
1729
+ badges.set(zone.id, { lngLat: placed.lngLat, properties: zone.properties });
1730
+ taken.add(placed.point);
1731
+ }
1732
+
1733
+ if (index < queue.length - 1) {
1734
+ yield badges;
1735
+ }
1736
+ }
1737
+
1738
+ return badges;
1739
+ }
1740
+
1741
+ /**
1742
+ * placeZoneBadges answers where the badge of each zone on screen stands, every zone in one go:
1743
+ * {@link placeZoneBadgesStepwise} run to its end.
1744
+ *
1745
+ * @param features The pieces the renderer has on screen, of out-of-window zones alone.
1746
+ * @param previous The badges the last placement answered, by zone id.
1747
+ * @param viewport The screen's size and the ground its corners show.
1748
+ * @returns The badges by zone id, or null when the viewport has no size or its corners outline no
1749
+ * view, in which case the badges drawn stand as they are.
1750
+ */
1751
+ export const placeZoneBadges = (
1752
+ features: readonly ZoneFeature[],
1753
+ previous: ReadonlyMap<string, ZoneBadge>,
1754
+ viewport: ZoneBadgeViewport,
1755
+ ): Map<string, ZoneBadge> | null => {
1756
+ const steps = placeZoneBadgesStepwise(features, previous, viewport);
1757
+ let step = steps.next();
1758
+ while (step.done !== true) {
1759
+ step = steps.next();
1760
+ }
1761
+
1762
+ return step.value;
1763
+ };
1764
+
1765
+ /** sameProperties reports whether two zones' properties hold the same values under the same names. */
1766
+ const sameProperties = (
1767
+ left: Readonly<Record<string, unknown>>,
1768
+ right: Readonly<Record<string, unknown>>,
1769
+ ): boolean => {
1770
+ const names = Object.keys(left);
1771
+
1772
+ return (
1773
+ names.length === Object.keys(right).length &&
1774
+ names.every((name) => Object.hasOwn(right, name) && left[name] === right[name])
1775
+ );
1776
+ };
1777
+
1778
+ /**
1779
+ * sameZoneBadges reports whether two placements draw the same: the same zones, each at the same
1780
+ * place with the same properties. It is what spares the renderer a write of badges that did not
1781
+ * move, and what ends the round of placements a write would otherwise start again.
1782
+ *
1783
+ * @param left One placement, by zone id.
1784
+ * @param right The other.
1785
+ */
1786
+ export const sameZoneBadges = (
1787
+ left: ReadonlyMap<string, ZoneBadge>,
1788
+ right: ReadonlyMap<string, ZoneBadge>,
1789
+ ): boolean => {
1790
+ if (left.size !== right.size) {
1791
+ return false;
1792
+ }
1793
+
1794
+ for (const [id, badge] of left) {
1795
+ const other = right.get(id);
1796
+ if (
1797
+ other === undefined ||
1798
+ other.lngLat[0] !== badge.lngLat[0] ||
1799
+ other.lngLat[1] !== badge.lngLat[1] ||
1800
+ !sameProperties(badge.properties, other.properties)
1801
+ ) {
1802
+ return false;
1803
+ }
1804
+ }
1805
+
1806
+ return true;
1807
+ };
1808
+
1809
+ /**
1810
+ * zoneBadgeCollection writes a placement as the GeoJSON the badge layer draws: one point per
1811
+ * zone, carrying the zone's properties, in the order of the zones' ids so the same placement is
1812
+ * always the same document.
1813
+ *
1814
+ * @param badges The placement, by zone id.
1815
+ */
1816
+ export const zoneBadgeCollection = (
1817
+ badges: ReadonlyMap<string, ZoneBadge>,
1818
+ ): FeatureCollection<Point> => {
1819
+ const features: Feature<Point>[] = [];
1820
+ for (const id of [...badges.keys()].sort()) {
1821
+ const badge = badges.get(id);
1822
+ if (badge !== undefined) {
1823
+ features.push({
1824
+ geometry: { coordinates: [badge.lngLat[0], badge.lngLat[1]], type: "Point" },
1825
+ properties: { ...badge.properties },
1826
+ type: "Feature",
1827
+ });
1828
+ }
1829
+ }
1830
+
1831
+ return { features, type: "FeatureCollection" };
1832
+ };