@mountaya/studio 0.0.0-stage → 0.1.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 (524) hide show
  1. package/CHANGELOG.md +39 -0
  2. package/LICENCE.fr.txt +280 -0
  3. package/LICENSE.txt +262 -0
  4. package/README.md +917 -2
  5. package/dist/agent/index.cjs +2854 -0
  6. package/dist/agent/index.cjs.map +1 -0
  7. package/dist/agent/index.d.cts +1257 -0
  8. package/dist/agent/index.d.ts +1257 -0
  9. package/dist/agent/index.js +2818 -0
  10. package/dist/agent/index.js.map +1 -0
  11. package/dist/bus-BwiNiXdH.d.ts +514 -0
  12. package/dist/bus-DzmhPwdK.d.cts +514 -0
  13. package/dist/chainModel-B23pEP_1.d.cts +127 -0
  14. package/dist/chainModel-B23pEP_1.d.ts +127 -0
  15. package/dist/chunk-2HFY7ETU.js +5721 -0
  16. package/dist/chunk-2HFY7ETU.js.map +1 -0
  17. package/dist/chunk-355TOXSB.js +72 -0
  18. package/dist/chunk-355TOXSB.js.map +1 -0
  19. package/dist/chunk-4ZCUZVSV.js +10275 -0
  20. package/dist/chunk-4ZCUZVSV.js.map +1 -0
  21. package/dist/chunk-6HEKY3NF.js +95 -0
  22. package/dist/chunk-6HEKY3NF.js.map +1 -0
  23. package/dist/chunk-7GFLGGBX.cjs +8 -0
  24. package/dist/chunk-7GFLGGBX.cjs.map +1 -0
  25. package/dist/chunk-7NBRCENN.cjs +19 -0
  26. package/dist/chunk-7NBRCENN.cjs.map +1 -0
  27. package/dist/chunk-AF5GCXE3.js +8 -0
  28. package/dist/chunk-AF5GCXE3.js.map +1 -0
  29. package/dist/chunk-CJDIFRGZ.cjs +2005 -0
  30. package/dist/chunk-CJDIFRGZ.cjs.map +1 -0
  31. package/dist/chunk-CNPZY7N3.js +349 -0
  32. package/dist/chunk-CNPZY7N3.js.map +1 -0
  33. package/dist/chunk-DZJHTWSF.cjs +45 -0
  34. package/dist/chunk-DZJHTWSF.cjs.map +1 -0
  35. package/dist/chunk-EABIHHWA.js +42 -0
  36. package/dist/chunk-EABIHHWA.js.map +1 -0
  37. package/dist/chunk-EKZWV6RS.cjs +415 -0
  38. package/dist/chunk-EKZWV6RS.cjs.map +1 -0
  39. package/dist/chunk-EOKRXXAC.cjs +24 -0
  40. package/dist/chunk-EOKRXXAC.cjs.map +1 -0
  41. package/dist/chunk-F73W2ZTJ.js +1126 -0
  42. package/dist/chunk-F73W2ZTJ.js.map +1 -0
  43. package/dist/chunk-H4DVOZ5O.js +1897 -0
  44. package/dist/chunk-H4DVOZ5O.js.map +1 -0
  45. package/dist/chunk-HI52PBFT.cjs +10314 -0
  46. package/dist/chunk-HI52PBFT.cjs.map +1 -0
  47. package/dist/chunk-IDBXFBLG.cjs +1225 -0
  48. package/dist/chunk-IDBXFBLG.cjs.map +1 -0
  49. package/dist/chunk-LBWTJZUJ.js +297 -0
  50. package/dist/chunk-LBWTJZUJ.js.map +1 -0
  51. package/dist/chunk-NCLA6DKD.cjs +310 -0
  52. package/dist/chunk-NCLA6DKD.cjs.map +1 -0
  53. package/dist/chunk-O4MC5DPD.js +19 -0
  54. package/dist/chunk-O4MC5DPD.js.map +1 -0
  55. package/dist/chunk-OP37FKW6.cjs +98 -0
  56. package/dist/chunk-OP37FKW6.cjs.map +1 -0
  57. package/dist/chunk-OQSYFH3Z.cjs +5945 -0
  58. package/dist/chunk-OQSYFH3Z.cjs.map +1 -0
  59. package/dist/chunk-PACIO4NS.cjs +26 -0
  60. package/dist/chunk-PACIO4NS.cjs.map +1 -0
  61. package/dist/chunk-PSZ2R3TC.cjs +75 -0
  62. package/dist/chunk-PSZ2R3TC.cjs.map +1 -0
  63. package/dist/chunk-QFO5CZG2.cjs +136 -0
  64. package/dist/chunk-QFO5CZG2.cjs.map +1 -0
  65. package/dist/chunk-QL63MUEW.cjs +140 -0
  66. package/dist/chunk-QL63MUEW.cjs.map +1 -0
  67. package/dist/chunk-RFUPPVZO.js +17 -0
  68. package/dist/chunk-RFUPPVZO.js.map +1 -0
  69. package/dist/chunk-RPG2LWMP.js +23 -0
  70. package/dist/chunk-RPG2LWMP.js.map +1 -0
  71. package/dist/chunk-TIBXK6B7.cjs +12 -0
  72. package/dist/chunk-TIBXK6B7.cjs.map +1 -0
  73. package/dist/chunk-UU65VNEV.js +381 -0
  74. package/dist/chunk-UU65VNEV.js.map +1 -0
  75. package/dist/chunk-VGX6TR2I.js +209 -0
  76. package/dist/chunk-VGX6TR2I.js.map +1 -0
  77. package/dist/chunk-WUTDDBVP.js +130 -0
  78. package/dist/chunk-WUTDDBVP.js.map +1 -0
  79. package/dist/chunk-WVQQLKCI.cjs +224 -0
  80. package/dist/chunk-WVQQLKCI.cjs.map +1 -0
  81. package/dist/chunk-WZYXG3SE.js +111 -0
  82. package/dist/chunk-WZYXG3SE.js.map +1 -0
  83. package/dist/chunk-XDI2X3KE.js +6 -0
  84. package/dist/chunk-XDI2X3KE.js.map +1 -0
  85. package/dist/chunk-XKHLRIC7.cjs +381 -0
  86. package/dist/chunk-XKHLRIC7.cjs.map +1 -0
  87. package/dist/context-DNtd2WUv.d.cts +11666 -0
  88. package/dist/context-DgB72Bur.d.ts +11666 -0
  89. package/dist/directorThreads-CqmvsV8b.d.cts +80 -0
  90. package/dist/directorThreads-CqmvsV8b.d.ts +80 -0
  91. package/dist/en-Bu4Ti9Ev.d.cts +2315 -0
  92. package/dist/en-Bu4Ti9Ev.d.ts +2315 -0
  93. package/dist/engines/index.cjs +3446 -0
  94. package/dist/engines/index.cjs.map +1 -0
  95. package/dist/engines/index.d.cts +2216 -0
  96. package/dist/engines/index.d.ts +2216 -0
  97. package/dist/engines/index.js +3416 -0
  98. package/dist/engines/index.js.map +1 -0
  99. package/dist/handlers/index.cjs +99 -0
  100. package/dist/handlers/index.cjs.map +1 -0
  101. package/dist/handlers/index.d.cts +445 -0
  102. package/dist/handlers/index.d.ts +445 -0
  103. package/dist/handlers/index.js +42 -0
  104. package/dist/handlers/index.js.map +1 -0
  105. package/dist/index.cjs +4562 -0
  106. package/dist/index.cjs.map +1 -0
  107. package/dist/index.d.cts +7297 -0
  108. package/dist/index.d.ts +7297 -0
  109. package/dist/index.js +3223 -0
  110. package/dist/index.js.map +1 -0
  111. package/dist/plugins/index.cjs +977 -0
  112. package/dist/plugins/index.cjs.map +1 -0
  113. package/dist/plugins/index.d.cts +313 -0
  114. package/dist/plugins/index.d.ts +313 -0
  115. package/dist/plugins/index.js +933 -0
  116. package/dist/plugins/index.js.map +1 -0
  117. package/dist/saveFile-j-1kkApx.d.cts +123 -0
  118. package/dist/saveFile-j-1kkApx.d.ts +123 -0
  119. package/dist/seams/index.cjs +152 -0
  120. package/dist/seams/index.cjs.map +1 -0
  121. package/dist/seams/index.d.cts +485 -0
  122. package/dist/seams/index.d.ts +485 -0
  123. package/dist/seams/index.js +79 -0
  124. package/dist/seams/index.js.map +1 -0
  125. package/dist/shareLink-B6hlt942.d.ts +144 -0
  126. package/dist/shareLink-C7rIMb7x.d.ts +527 -0
  127. package/dist/shareLink-CnTxxXjp.d.cts +144 -0
  128. package/dist/shareLink-DyZVYH2V.d.cts +527 -0
  129. package/dist/strings/fr/index.cjs +2121 -0
  130. package/dist/strings/fr/index.cjs.map +1 -0
  131. package/dist/strings/fr/index.d.cts +19 -0
  132. package/dist/strings/fr/index.d.ts +19 -0
  133. package/dist/strings/fr/index.js +2119 -0
  134. package/dist/strings/fr/index.js.map +1 -0
  135. package/dist/strings/index.cjs +2678 -0
  136. package/dist/strings/index.cjs.map +1 -0
  137. package/dist/strings/index.d.cts +731 -0
  138. package/dist/strings/index.d.ts +731 -0
  139. package/dist/strings/index.js +2644 -0
  140. package/dist/strings/index.js.map +1 -0
  141. package/dist/studioPlugin-C3C7VjMy.d.ts +847 -0
  142. package/dist/studioPlugin-Cf3OBNUv.d.cts +847 -0
  143. package/dist/tabs-B2nRO4p_.d.cts +15 -0
  144. package/dist/tabs-B2nRO4p_.d.ts +15 -0
  145. package/dist/testing/index.cjs +292 -0
  146. package/dist/testing/index.cjs.map +1 -0
  147. package/dist/testing/index.d.cts +306 -0
  148. package/dist/testing/index.d.ts +306 -0
  149. package/dist/testing/index.js +284 -0
  150. package/dist/testing/index.js.map +1 -0
  151. package/dist/time/index.cjs +28 -0
  152. package/dist/time/index.cjs.map +1 -0
  153. package/dist/time/index.d.cts +43 -0
  154. package/dist/time/index.d.ts +43 -0
  155. package/dist/time/index.js +26 -0
  156. package/dist/time/index.js.map +1 -0
  157. package/dist/types-BzJRV6UI.d.cts +845 -0
  158. package/dist/types-BzJRV6UI.d.ts +845 -0
  159. package/dist/zoneForm-CdYNtnnA.d.cts +320 -0
  160. package/dist/zoneForm-mG85yt5e.d.ts +320 -0
  161. package/package.json +225 -4
  162. package/src/agent/engines/agentThreads.ts +1601 -0
  163. package/src/agent/engines/directorChat.ts +500 -0
  164. package/src/agent/index.ts +67 -0
  165. package/src/agent/rules/agentEditLock.ts +115 -0
  166. package/src/agent/rules/agentErrorCopy.ts +44 -0
  167. package/src/agent/rules/copilotOrganization.ts +36 -0
  168. package/src/agent/rules/playbook.gen.ts +444 -0
  169. package/src/agent/rules/router.ts +518 -0
  170. package/src/agent/rules/stateDelta.ts +28 -0
  171. package/src/agent/rules/studioRouter.ts +123 -0
  172. package/src/agent/rules/surfaces.gen.ts +633 -0
  173. package/src/agent/rules/threadsUrl.ts +48 -0
  174. package/src/agent/rules/transcriptObserver.ts +90 -0
  175. package/src/agent/stores/agentThreads.ts +454 -0
  176. package/src/bus/contracts/noData.ts +18 -0
  177. package/src/bus/contracts/shared.ts +172 -0
  178. package/src/bus/contracts/studioTools.ts +224 -0
  179. package/src/bus/rules/bus.ts +858 -0
  180. package/src/bus/rules/confirmation.ts +22 -0
  181. package/src/bus/rules/defineRegistry.ts +26 -0
  182. package/src/bus/rules/errors.ts +401 -0
  183. package/src/bus/rules/handlerErrors.ts +103 -0
  184. package/src/bus/rules/handlerRegistry.ts +627 -0
  185. package/src/bus/rules/inputSchema.ts +232 -0
  186. package/src/bus/rules/invalidInput.ts +441 -0
  187. package/src/bus/rules/lateBoundTools.ts +100 -0
  188. package/src/bus/rules/studioRegistry.ts +324 -0
  189. package/src/bus/rules/studioToolBus.ts +73 -0
  190. package/src/bus/rules/types.ts +805 -0
  191. package/src/chrome/contracts/alert.ts +42 -0
  192. package/src/chrome/contracts/itinerary.ts +26 -0
  193. package/src/chrome/contracts/map.ts +23 -0
  194. package/src/chrome/contracts/overlay.ts +46 -0
  195. package/src/chrome/contracts/panel.ts +29 -0
  196. package/src/chrome/contracts/question.ts +52 -0
  197. package/src/chrome/contracts/selection.ts +26 -0
  198. package/src/chrome/contracts/sidenav.ts +23 -0
  199. package/src/chrome/contracts/snapshot.ts +319 -0
  200. package/src/chrome/contracts/state.ts +22 -0
  201. package/src/chrome/contracts/tabs.ts +56 -0
  202. package/src/chrome/handlers/alert.ts +91 -0
  203. package/src/chrome/handlers/introspection.ts +180 -0
  204. package/src/chrome/handlers/panels.ts +42 -0
  205. package/src/chrome/handlers/question.ts +24 -0
  206. package/src/chrome/handlers/sidenav.ts +116 -0
  207. package/src/chrome/handlers/snapshot.ts +451 -0
  208. package/src/chrome/handlers/stateDelta.ts +125 -0
  209. package/src/chrome/handlers/tabs.ts +143 -0
  210. package/src/chrome/handlers/timestamp.ts +19 -0
  211. package/src/chrome/rules/agentSelectors.ts +210 -0
  212. package/src/chrome/rules/mapAlert.ts +13 -0
  213. package/src/chrome/rules/question.ts +25 -0
  214. package/src/chrome/rules/tabs.ts +13 -0
  215. package/src/chrome/stores/activeDraftSession.ts +134 -0
  216. package/src/chrome/stores/chrome.ts +527 -0
  217. package/src/chrome/stores/uiStore.ts +573 -0
  218. package/src/collab/contracts/collab.ts +261 -0
  219. package/src/collab/handlers/collab.ts +468 -0
  220. package/src/collab/rules/toolNames.ts +33 -0
  221. package/src/collab/stores/collab.ts +899 -0
  222. package/src/collections/contracts/collection.ts +182 -0
  223. package/src/collections/handlers/collectionAttach.ts +141 -0
  224. package/src/collections/handlers/collections.ts +499 -0
  225. package/src/collections/handlers/heldCollection.ts +42 -0
  226. package/src/collections/handlers/restCollections.ts +386 -0
  227. package/src/collections/rules/collections.ts +138 -0
  228. package/src/collections/rules/entityCollections.ts +53 -0
  229. package/src/collections/stores/collections.ts +133 -0
  230. package/src/data/contracts/data.ts +233 -0
  231. package/src/data/contracts/itinerary.ts +71 -0
  232. package/src/data/handlers/activityResolve.ts +76 -0
  233. package/src/data/handlers/data.ts +200 -0
  234. package/src/data/handlers/graphql.ts +26 -0
  235. package/src/data/handlers/mutationSink.ts +1577 -0
  236. package/src/data/handlers/profile.ts +83 -0
  237. package/src/data/handlers/writeThrough.ts +417 -0
  238. package/src/data/rules/cache.ts +181 -0
  239. package/src/data/rules/dataTypes.ts +40 -0
  240. package/src/data/rules/keys.ts +106 -0
  241. package/src/data/rules/persistence.ts +1058 -0
  242. package/src/data/rules/requestBody.ts +43 -0
  243. package/src/data/rules/restErrors.ts +354 -0
  244. package/src/data/rules/sessionSurface.ts +156 -0
  245. package/src/data/rules/toolResultData.ts +73 -0
  246. package/src/data/rules/uuid.ts +24 -0
  247. package/src/edit/contracts/edit.ts +37 -0
  248. package/src/edit/contracts/itinerary.ts +57 -0
  249. package/src/edit/handlers/draftCommit.ts +257 -0
  250. package/src/edit/handlers/editDiscard.ts +34 -0
  251. package/src/edit/handlers/editLock.ts +949 -0
  252. package/src/edit/handlers/editor.ts +203 -0
  253. package/src/edit/handlers/formUnsaved.ts +24 -0
  254. package/src/edit/rules/draftMetadata.ts +117 -0
  255. package/src/edit/rules/editKeyboard.ts +222 -0
  256. package/src/edit/rules/editShortcuts.ts +102 -0
  257. package/src/edit/rules/editTooltip.ts +174 -0
  258. package/src/edit/rules/editorTaken.ts +49 -0
  259. package/src/edit/rules/history.ts +26 -0
  260. package/src/edit/rules/unsavedWork.ts +60 -0
  261. package/src/edit/stores/editorReservation.ts +70 -0
  262. package/src/edit/stores/formsUnsaved.ts +54 -0
  263. package/src/embed/contracts/embed.ts +48 -0
  264. package/src/embed/engines/embedFraming.ts +1329 -0
  265. package/src/embed/engines/embedReady.ts +353 -0
  266. package/src/embed/engines/framingPageSession.ts +169 -0
  267. package/src/embed/handlers/embed.ts +130 -0
  268. package/src/embed/rules/allowedDomains.ts +71 -0
  269. package/src/embed/rules/bridgeMessages.ts +224 -0
  270. package/src/embed/rules/defaults.ts +173 -0
  271. package/src/embed/rules/displaySeed.ts +115 -0
  272. package/src/embed/rules/embedAllowlist.ts +146 -0
  273. package/src/embed/rules/embedConstraints.ts +215 -0
  274. package/src/embed/rules/embedElements.ts +277 -0
  275. package/src/embed/rules/embedSectionFields.ts +126 -0
  276. package/src/embed/rules/embedSecurity.ts +116 -0
  277. package/src/embed/rules/fieldDependencies.ts +87 -0
  278. package/src/embed/rules/fieldOptions.ts +138 -0
  279. package/src/embed/rules/layerOptions.ts +161 -0
  280. package/src/embed/rules/readyProtocol.ts +66 -0
  281. package/src/embed/rules/safetyRules.ts +213 -0
  282. package/src/embed/rules/snippet.ts +531 -0
  283. package/src/embed/rules/tableCode.ts +269 -0
  284. package/src/embed/stores/embed.ts +60 -0
  285. package/src/embed/stores/embedContent.ts +77 -0
  286. package/src/engines/index.ts +81 -0
  287. package/src/handlers/index.ts +66 -0
  288. package/src/index.ts +1086 -0
  289. package/src/itinerary/contracts/itinerary.ts +705 -0
  290. package/src/itinerary/engines/itineraryPace.ts +612 -0
  291. package/src/itinerary/engines/profileMarker.ts +238 -0
  292. package/src/itinerary/handlers/importStaging.ts +352 -0
  293. package/src/itinerary/handlers/itinerary.ts +572 -0
  294. package/src/itinerary/handlers/itineraryDuplicate.ts +177 -0
  295. package/src/itinerary/handlers/itineraryExport.ts +117 -0
  296. package/src/itinerary/handlers/itineraryImport.ts +783 -0
  297. package/src/itinerary/handlers/itineraryPublish.ts +118 -0
  298. package/src/itinerary/handlers/itinerarySelection.ts +354 -0
  299. package/src/itinerary/handlers/itinerarySuggest.ts +1186 -0
  300. package/src/itinerary/handlers/itineraryUnpublish.ts +101 -0
  301. package/src/itinerary/handlers/publicationScope.ts +118 -0
  302. package/src/itinerary/handlers/restItineraries.ts +752 -0
  303. package/src/itinerary/handlers/restItineraryExport.ts +70 -0
  304. package/src/itinerary/handlers/restItineraryImport.ts +311 -0
  305. package/src/itinerary/handlers/restItineraryPace.ts +87 -0
  306. package/src/itinerary/handlers/restItineraryRecord.ts +36 -0
  307. package/src/itinerary/handlers/suggestParams.ts +379 -0
  308. package/src/itinerary/handlers/suggestStaging.ts +363 -0
  309. package/src/itinerary/handlers/surfaceOpen.ts +389 -0
  310. package/src/itinerary/rules/activity.ts +139 -0
  311. package/src/itinerary/rules/analysis.ts +42 -0
  312. package/src/itinerary/rules/ceiling.ts +49 -0
  313. package/src/itinerary/rules/createFlow.ts +107 -0
  314. package/src/itinerary/rules/densify.ts +440 -0
  315. package/src/itinerary/rules/draftSurface.ts +219 -0
  316. package/src/itinerary/rules/editorView.ts +83 -0
  317. package/src/itinerary/rules/export.ts +159 -0
  318. package/src/itinerary/rules/friendlyName.ts +77 -0
  319. package/src/itinerary/rules/import.ts +1052 -0
  320. package/src/itinerary/rules/importFiles.ts +140 -0
  321. package/src/itinerary/rules/importTotals.ts +77 -0
  322. package/src/itinerary/rules/liveSegment.ts +712 -0
  323. package/src/itinerary/rules/lngLat.ts +17 -0
  324. package/src/itinerary/rules/mapSync.ts +100 -0
  325. package/src/itinerary/rules/previewRender.ts +416 -0
  326. package/src/itinerary/rules/profileReadout.ts +216 -0
  327. package/src/itinerary/rules/routing.ts +707 -0
  328. package/src/itinerary/rules/suggest.ts +522 -0
  329. package/src/itinerary/rules/suggestionPreview.ts +119 -0
  330. package/src/itinerary/rules/view.ts +61 -0
  331. package/src/itinerary/stores/importSession.ts +319 -0
  332. package/src/itinerary/stores/itinerary.ts +331 -0
  333. package/src/itinerary/stores/itineraryDuplicate.ts +76 -0
  334. package/src/itinerary/stores/sessionIdentity.ts +43 -0
  335. package/src/itinerary/stores/suggestSession.ts +418 -0
  336. package/src/layers/contracts/itinerary.ts +46 -0
  337. package/src/layers/contracts/overlay.ts +132 -0
  338. package/src/layers/handlers/enrichment.ts +36 -0
  339. package/src/layers/handlers/overlay.ts +406 -0
  340. package/src/layers/handlers/restLayers.ts +94 -0
  341. package/src/layers/handlers/tiles.ts +25 -0
  342. package/src/layers/rules/layers.ts +212 -0
  343. package/src/layers/rules/overlayInstant.ts +12 -0
  344. package/src/layers/rules/reachabilityIcon.ts +18 -0
  345. package/src/layers/rules/readout.ts +102 -0
  346. package/src/layers/stores/layers.ts +262 -0
  347. package/src/map/contracts/contextmenu.ts +33 -0
  348. package/src/map/contracts/geolocate.ts +37 -0
  349. package/src/map/contracts/map.ts +146 -0
  350. package/src/map/contracts/streetview.ts +53 -0
  351. package/src/map/contracts/terrain.ts +152 -0
  352. package/src/map/handlers/contextMenu.ts +135 -0
  353. package/src/map/handlers/geolocate.ts +52 -0
  354. package/src/map/handlers/map.ts +391 -0
  355. package/src/map/handlers/streetview.ts +94 -0
  356. package/src/map/handlers/terrain.ts +663 -0
  357. package/src/map/rules/baseTerrain.ts +75 -0
  358. package/src/map/rules/clickTargets.ts +464 -0
  359. package/src/map/rules/constraints.ts +32 -0
  360. package/src/map/rules/contextMenuReadout.ts +67 -0
  361. package/src/map/rules/coordinates.ts +71 -0
  362. package/src/map/rules/itineraryFit.ts +8 -0
  363. package/src/map/rules/mapEvents.ts +64 -0
  364. package/src/map/rules/mapProjection.ts +476 -0
  365. package/src/map/rules/terrainReading.ts +62 -0
  366. package/src/plugins/contracts/ids.ts +66 -0
  367. package/src/plugins/contracts/plugin.ts +200 -0
  368. package/src/plugins/contracts/slots.ts +137 -0
  369. package/src/plugins/engines/studioPlugin.ts +1365 -0
  370. package/src/plugins/index.ts +111 -0
  371. package/src/plugins/rules/contributions.ts +152 -0
  372. package/src/plugins/rules/errors.ts +60 -0
  373. package/src/plugins/rules/ids.ts +42 -0
  374. package/src/plugins/rules/validation.ts +249 -0
  375. package/src/rules/listeners.ts +57 -0
  376. package/src/rules/origin.ts +13 -0
  377. package/src/rules/storeWrite.ts +37 -0
  378. package/src/rules/types.ts +136 -0
  379. package/src/seams/index.ts +79 -0
  380. package/src/seams/rules/clock.ts +28 -0
  381. package/src/seams/rules/formatters.ts +209 -0
  382. package/src/seams/rules/ids.ts +102 -0
  383. package/src/seams/rules/links.ts +66 -0
  384. package/src/seams/rules/navigation.ts +222 -0
  385. package/src/seams/rules/notify.ts +49 -0
  386. package/src/seams/rules/persistenceDrawer.ts +220 -0
  387. package/src/seams/rules/saveFile.ts +101 -0
  388. package/src/seams/rules/seams.ts +156 -0
  389. package/src/seams/rules/storage.ts +116 -0
  390. package/src/search/contracts/overlay.ts +74 -0
  391. package/src/search/contracts/search.ts +197 -0
  392. package/src/search/handlers/pois.ts +57 -0
  393. package/src/search/handlers/search.ts +280 -0
  394. package/src/search/rules/params.ts +925 -0
  395. package/src/search/rules/poiGroups.ts +138 -0
  396. package/src/search/rules/searchFetch.ts +139 -0
  397. package/src/search/rules/timeWindow.ts +30 -0
  398. package/src/search/stores/search.ts +51 -0
  399. package/src/segments/contracts/itinerary.ts +433 -0
  400. package/src/segments/contracts/segment.ts +35 -0
  401. package/src/segments/engines/segmentDraft.ts +926 -0
  402. package/src/segments/handlers/chainGuards.ts +67 -0
  403. package/src/segments/handlers/directions.ts +44 -0
  404. package/src/segments/handlers/itineraryEcho.ts +45 -0
  405. package/src/segments/handlers/roadAccessDialog.ts +34 -0
  406. package/src/segments/handlers/segment.ts +111 -0
  407. package/src/segments/handlers/segmentEdit.ts +1341 -0
  408. package/src/segments/handlers/segmentGroups.ts +347 -0
  409. package/src/segments/handlers/segmentStructure.ts +1144 -0
  410. package/src/segments/rules/chain.ts +196 -0
  411. package/src/segments/rules/chainModel.ts +217 -0
  412. package/src/segments/rules/colors.ts +11 -0
  413. package/src/segments/rules/commit.ts +76 -0
  414. package/src/segments/rules/draft.ts +90 -0
  415. package/src/segments/rules/draftDisposition.ts +43 -0
  416. package/src/segments/rules/draftSegmentEdit.ts +129 -0
  417. package/src/segments/rules/engine.ts +222 -0
  418. package/src/segments/rules/groupSave.ts +234 -0
  419. package/src/segments/rules/hazardPrompt.ts +60 -0
  420. package/src/segments/rules/itineraryEcho.ts +40 -0
  421. package/src/segments/rules/liveSegmentProjection.ts +55 -0
  422. package/src/segments/rules/merge.ts +51 -0
  423. package/src/segments/rules/metrics.ts +456 -0
  424. package/src/segments/rules/naming.ts +168 -0
  425. package/src/segments/rules/segmentArming.ts +144 -0
  426. package/src/segments/rules/splitPick.ts +84 -0
  427. package/src/segments/rules/viaSimplify.ts +230 -0
  428. package/src/segments/stores/directions.ts +77 -0
  429. package/src/segments/stores/roadAccessDialog.ts +58 -0
  430. package/src/segments/stores/segmentEdit.ts +922 -0
  431. package/src/segments/stores/segmentGroupEdit.ts +84 -0
  432. package/src/segments/stores/segmentSplit.ts +77 -0
  433. package/src/share/contracts/share.ts +39 -0
  434. package/src/share/contracts/shareLink.ts +63 -0
  435. package/src/share/engines/shareLink.ts +1053 -0
  436. package/src/share/handlers/share.ts +47 -0
  437. package/src/share/handlers/shareLink.ts +231 -0
  438. package/src/share/handlers/shareScope.ts +54 -0
  439. package/src/share/rules/link.ts +89 -0
  440. package/src/share/rules/shareLink.ts +218 -0
  441. package/src/share/rules/targets.ts +92 -0
  442. package/src/share/rules/viewConfig.ts +95 -0
  443. package/src/share/stores/share.ts +58 -0
  444. package/src/strings/fr/index.ts +18 -0
  445. package/src/strings/fr/rules/fr.ts +2368 -0
  446. package/src/strings/index.ts +98 -0
  447. package/src/strings/rules/confirmCopy.ts +156 -0
  448. package/src/strings/rules/draftToolNames.ts +94 -0
  449. package/src/strings/rules/en.ts +2519 -0
  450. package/src/strings/rules/failureAlert.ts +115 -0
  451. package/src/strings/rules/formError.ts +400 -0
  452. package/src/strings/rules/maneuvers.ts +107 -0
  453. package/src/strings/rules/outputOptions.ts +126 -0
  454. package/src/strings/rules/publicationState.ts +100 -0
  455. package/src/strings/rules/routeHazardCopy.ts +62 -0
  456. package/src/strings/rules/searchLabels.ts +50 -0
  457. package/src/strings/rules/segmentChainVerbs.ts +62 -0
  458. package/src/strings/rules/studioCopy.ts +130 -0
  459. package/src/strings/rules/unitOptions.ts +119 -0
  460. package/src/testing/checkedBus.ts +226 -0
  461. package/src/testing/index.ts +34 -0
  462. package/src/testing/plugins.ts +106 -0
  463. package/src/testing/studio.ts +267 -0
  464. package/src/testing/urlSeam.ts +153 -0
  465. package/src/time/index.ts +12 -0
  466. package/src/time/rules/sun.ts +78 -0
  467. package/src/video/contracts/cameraSchemas.ts +266 -0
  468. package/src/video/contracts/profileSchemas.ts +37 -0
  469. package/src/video/contracts/video.ts +601 -0
  470. package/src/video/handlers/video.ts +1638 -0
  471. package/src/video/handlers/videoDirector.ts +114 -0
  472. package/src/video/rules/previewRefresh.ts +76 -0
  473. package/src/video/rules/profileSource.ts +51 -0
  474. package/src/video/rules/routeSpans.ts +79 -0
  475. package/src/video/rules/shotDefaults.ts +28 -0
  476. package/src/video/rules/stepOrder.ts +17 -0
  477. package/src/video/rules/videoSnapshot.ts +136 -0
  478. package/src/video/stores/directorThreads.ts +167 -0
  479. package/src/video/stores/videoExport.ts +290 -0
  480. package/src/viewer/contracts/preferences.ts +40 -0
  481. package/src/viewer/handlers/preferences.ts +91 -0
  482. package/src/viewer/rules/capabilities.ts +42 -0
  483. package/src/viewer/rules/config.ts +266 -0
  484. package/src/viewer/rules/context.ts +375 -0
  485. package/src/viewer/rules/ownership.ts +134 -0
  486. package/src/viewer/rules/platformViewer.ts +198 -0
  487. package/src/viewer/rules/scope.ts +197 -0
  488. package/src/viewer/rules/url.ts +145 -0
  489. package/src/viewer/rules/viewer.ts +307 -0
  490. package/src/viewer/rules/viewerSeam.ts +49 -0
  491. package/src/viewer/rules/viewerUnits.ts +34 -0
  492. package/src/waypoints/contracts/itinerary.ts +417 -0
  493. package/src/waypoints/handlers/poiWaypointStyle.ts +32 -0
  494. package/src/waypoints/handlers/waypointDetailsDialog.ts +38 -0
  495. package/src/waypoints/handlers/waypointEdit.ts +1073 -0
  496. package/src/waypoints/rules/amenities.ts +30 -0
  497. package/src/waypoints/rules/defaults.ts +31 -0
  498. package/src/waypoints/rules/details.ts +213 -0
  499. package/src/waypoints/rules/detailsDraft.ts +312 -0
  500. package/src/waypoints/rules/detailsPreview.ts +76 -0
  501. package/src/waypoints/rules/detailsSave.ts +356 -0
  502. package/src/waypoints/rules/draftDirty.ts +45 -0
  503. package/src/waypoints/rules/icons.ts +32 -0
  504. package/src/waypoints/rules/liveWaypoint.ts +63 -0
  505. package/src/waypoints/rules/naming.ts +185 -0
  506. package/src/waypoints/rules/sections.ts +77 -0
  507. package/src/waypoints/rules/waypointDraft.ts +62 -0
  508. package/src/waypoints/stores/waypointDetails.ts +62 -0
  509. package/src/waypoints/stores/waypointEdit.ts +566 -0
  510. package/src/zones/contracts/collection.ts +37 -0
  511. package/src/zones/contracts/zone.ts +528 -0
  512. package/src/zones/engines/zoneForm.ts +1773 -0
  513. package/src/zones/handlers/restZones.ts +287 -0
  514. package/src/zones/handlers/zonePublish.ts +206 -0
  515. package/src/zones/handlers/zoneUnpublish.ts +56 -0
  516. package/src/zones/handlers/zones.ts +2254 -0
  517. package/src/zones/rules/geometry.ts +946 -0
  518. package/src/zones/rules/zoneDefaults.ts +34 -0
  519. package/src/zones/rules/zoneDraft.ts +54 -0
  520. package/src/zones/rules/zoneForm.ts +563 -0
  521. package/src/zones/rules/zoneMetadata.ts +29 -0
  522. package/src/zones/rules/zoneSource.ts +87 -0
  523. package/src/zones/rules/zoneSourceRefusal.ts +104 -0
  524. package/src/zones/stores/zoneEdit.ts +998 -0
@@ -0,0 +1,168 @@
1
+ import { DISPLAY_NAME_MAX_LENGTH } from "../../edit/rules/draftMetadata.js";
2
+
3
+ /**
4
+ * defaultNamePattern matches `Segment #N` where N is a positive integer with
5
+ * no leading zeros. Renaming auto-derives from this match so a user-customised
6
+ * name like "Golden Ridge" survives every reorder.
7
+ */
8
+ const defaultNamePattern = /^Segment #([1-9]\d*)$/;
9
+
10
+ /**
11
+ * defaultSegmentName returns the auto-name assigned when a segment is created.
12
+ * The index is 0-based so the first segment reads as "Segment #1". The single
13
+ * source of the convention: an editor's add-segment control, an import draft's
14
+ * projection, and the renumber pass all read it, so a segment's positional label
15
+ * is identical wherever it is born.
16
+ */
17
+ export const defaultSegmentName = (index: number): string => `Segment #${index + 1}`;
18
+
19
+ /**
20
+ * isDefaultSegmentName tells whether a name was assigned by the auto-namer (so
21
+ * a reorder may rewrite it) or is a user-customised label (which stays put).
22
+ */
23
+ export const isDefaultSegmentName = (name: string): boolean => defaultNamePattern.test(name);
24
+
25
+ /**
26
+ * partSuffixPattern matches the ` - Part N` a previous split appended, so
27
+ * splitting a half again replaces that suffix instead of stacking a second one.
28
+ */
29
+ const partSuffixPattern = / - Part [1-9]\d*$/;
30
+
31
+ /**
32
+ * partName is one half's name: the base with ` - Part N` behind it, the base clipped so the whole
33
+ * name holds at most `maxLength` code points. A clip never ends on a space.
34
+ */
35
+ const partName = (base: string, part: number, maxLength: number): string => {
36
+ const suffix = ` - Part ${part}`;
37
+ const room = Math.max(0, maxLength - suffix.length);
38
+ const characters = Array.from(base);
39
+ const clipped = characters.length <= room ? base : characters.slice(0, room).join("").trimEnd();
40
+
41
+ return `${clipped}${suffix}`;
42
+ };
43
+
44
+ /**
45
+ * splitSegmentNames derives the two names a split's halves take from the name of
46
+ * the segment being cut: `Climb` becomes `Climb - Part 1` and `Climb - Part 2`.
47
+ * Without it a split leaves two identically-named rows, since the API copies the
48
+ * name onto both halves verbatim. A name that already ends in ` - Part N` has that
49
+ * suffix replaced rather than extended, so re-splitting a half never nests a second one.
50
+ *
51
+ * The halves take the two lowest part numbers `siblingNames` leave free, in order, so no two rows
52
+ * of the chain share a name. The second half of an earlier split, cut beside its first half,
53
+ * becomes `Climb - Part 2` and `Climb - Part 3`. The first half cut beside the second becomes
54
+ * `Climb - Part 1` and `Climb - Part 3`: a sibling keeps the name it has, since renaming it would
55
+ * be a second write to a segment nobody cut.
56
+ *
57
+ * Both names fit a `maxLength` that holds the suffix: the name is clipped, in code points as the
58
+ * API counts them, to leave room for the suffix, so a segment whose name runs to the bound can
59
+ * still be split. A bound shorter than the suffix leaves the suffix alone: the name is clipped to
60
+ * nothing and each half is its ` - Part N` whole, past the bound.
61
+ *
62
+ * It applies to auto-named segments too: the renumber pass runs only on the delete
63
+ * path and is never persisted, so nothing else would tell two `Segment #3` rows
64
+ * apart.
65
+ *
66
+ * The wording is English regardless of the viewer's language, matching
67
+ * {@link defaultSegmentName}'s `Segment #N`. A segment name is stored, shared, and
68
+ * exported, so it cannot depend on who happened to create it; localising `Part`
69
+ * while auto-names stay English would be the inconsistent half-step, and moving
70
+ * both is its own change.
71
+ *
72
+ * @param name The name of the segment being cut.
73
+ * @param siblingNames The names the chain's other segments carry. Left out, the halves are
74
+ * `Part 1` and `Part 2`.
75
+ * @param maxLength The most code points a segment name holds. Defaults to
76
+ * {@link DISPLAY_NAME_MAX_LENGTH}, the bound the API holds a segment name to and the ceiling
77
+ * `displayNameSchema` enforces.
78
+ * @returns The first half's name, then the second half's.
79
+ *
80
+ * @example
81
+ * ```ts
82
+ * splitSegmentNames("Climb"); // ["Climb - Part 1", "Climb - Part 2"]
83
+ * splitSegmentNames("Climb - Part 2", ["Climb - Part 1"]); // ["Climb - Part 2", "Climb - Part 3"]
84
+ * ```
85
+ */
86
+ export const splitSegmentNames = (
87
+ name: string,
88
+ siblingNames: readonly string[] = [],
89
+ maxLength: number = DISPLAY_NAME_MAX_LENGTH,
90
+ ): [string, string] => {
91
+ const base = name.replace(partSuffixPattern, "");
92
+ const taken = new Set(siblingNames);
93
+
94
+ // Two free numbers always exist among the first `taken.size + 2`: each sibling holds one name.
95
+ const free: string[] = [];
96
+ for (let part = 1; free.length < 2 && part <= taken.size + 2; part += 1) {
97
+ const candidate = partName(base, part, maxLength);
98
+ if (!taken.has(candidate)) {
99
+ free.push(candidate);
100
+ }
101
+ }
102
+
103
+ return [free[0] ?? partName(base, 1, maxLength), free[1] ?? partName(base, 2, maxLength)];
104
+ };
105
+
106
+ /**
107
+ * defaultSegmentGroupName derives the name proposed when a run of segments is grouped: the run
108
+ * reads `First - Last`, which is what the user is looking at.
109
+ *
110
+ * The length rule is the whole reason this is a function. A group name is bound by the same 2–30
111
+ * limit every other name is, and two real segment names joined by a separator pass it constantly:
112
+ * "Col du Galibier" and "Refuge des Écrins" are 33 characters together. Composing blindly opens a
113
+ * dialog with its confirm already disabled and an error under a field the user never touched, which
114
+ * reads as the form being broken rather than as a suggestion that did not fit.
115
+ *
116
+ * So it degrades instead: the pair when the pair fits, otherwise the head segment alone, which is
117
+ * bound by the same limit and so always does. A head longer than the limit can only come from a
118
+ * caller passing something that is not a segment name, and is clipped rather than trusted.
119
+ *
120
+ * `maxLength` is a parameter rather than a constant because the limit is declared by the API schema
121
+ * and enforced at the mutation boundary. Taking it in keeps one source of the number (the schema)
122
+ * rather than a second copy of 30 down here that would drift the first time the API widened the
123
+ * field.
124
+ *
125
+ * Lengths are counted, and a head clipped, in code points, which is how the schema's `maxLength`
126
+ * counts them: an emoji in a segment name is one character to the API and two UTF-16 units to
127
+ * `.length`, and clipping at a unit could split it in half.
128
+ */
129
+ export const defaultSegmentGroupName = (first: string, last: string, maxLength: number): string => {
130
+ const head = first.trim();
131
+ const tail = last.trim();
132
+
133
+ if (head === "") {
134
+ return "";
135
+ }
136
+
137
+ const paired = tail === "" || tail === head ? head : `${head} - ${tail}`;
138
+ if (Array.from(paired).length <= maxLength) {
139
+ return paired;
140
+ }
141
+
142
+ const headCharacters = Array.from(head);
143
+
144
+ return headCharacters.length <= maxLength
145
+ ? head
146
+ : headCharacters.slice(0, maxLength).join("").trimEnd();
147
+ };
148
+
149
+ /**
150
+ * SegmentLike is the slice of a segment the renumberer reads: the persisted segment type carries
151
+ * more, but only `id` and `name` participate here.
152
+ */
153
+ export interface SegmentLike {
154
+ id: string;
155
+ name: string;
156
+ }
157
+
158
+ /**
159
+ * renumberDefaultSegments walks the segments in order and rewrites any default-named entry so its
160
+ * number matches its 1-based position. Segments whose names don't match the default pattern are
161
+ * left untouched, so a user's "Golden Ridge" survives a reorder while a sibling "Segment #4"
162
+ * becomes "Segment #2" when it moves up. The function is pure: callers feed in the desired order
163
+ * and apply the returned list themselves.
164
+ */
165
+ export const renumberDefaultSegments = <T extends SegmentLike>(segments: readonly T[]): T[] =>
166
+ segments.map((segment, index) =>
167
+ isDefaultSegmentName(segment.name) ? { ...segment, name: defaultSegmentName(index) } : segment,
168
+ );
@@ -0,0 +1,144 @@
1
+ import type { Position } from "geojson";
2
+
3
+ import type { Mountaya } from "@mountaya/client";
4
+ import type { SegmentEditOptions } from "@mountaya/elements/map-client";
5
+ import { DEFAULT_SEGMENT_COLOR } from "@mountaya/elements/style";
6
+
7
+ import type { ConfirmationRequest } from "../../bus/rules/types.js";
8
+ import {
9
+ buildAnalyzeFn,
10
+ buildRouteFn,
11
+ type RouteAdvisory,
12
+ type RouteHazardMemo,
13
+ } from "../../itinerary/rules/routing.js";
14
+ import { HAZARD_CODE_SEPARATOR, routeHazardBody } from "../../strings/rules/routeHazardCopy.js";
15
+ import type { SegmentEditSession } from "../stores/segmentEdit.js";
16
+
17
+ /**
18
+ * SegmentArmingSeams are what arming a segment edit takes beyond its session: the client its
19
+ * routes and profiles resolve through, and the answers only a host can give. The editor calls
20
+ * each one when it needs it, so a closure reading the host's current state stays current.
21
+ */
22
+ export interface SegmentArmingSeams {
23
+ /**
24
+ * The client a directions edit routes through and a freehand edit analyses its line through.
25
+ * Undefined arms the editor with neither resolver.
26
+ */
27
+ readonly client: Mountaya | undefined;
28
+ /**
29
+ * Asks the person to approve a routed line's hazards this session has not accepted, resolving
30
+ * true to adopt the line and false to undo the placement behind it. Omitted, the line is
31
+ * adopted. See {@link routeHazardConfirmation}.
32
+ */
33
+ readonly confirmHazards?: ((hazards: RouteAdvisory[]) => Promise<boolean>) | undefined;
34
+ /**
35
+ * The session's record of accepted hazards, so one way is asked about once per edit. Omitted,
36
+ * the routing function keeps its own for as long as it lives.
37
+ */
38
+ readonly hazardMemo?: RouteHazardMemo | undefined;
39
+ /** Told when a click is declined because the draft holds the router's maximum vias. */
40
+ readonly onViaCapRefused?: (() => void) | undefined;
41
+ }
42
+
43
+ /**
44
+ * buildSegmentEditOptions builds what the map's segment editor is armed with for one open segment
45
+ * edit session: its segment, mode, colour, activity, pinned boundaries and seed handles, and the
46
+ * resolvers the editor calls back through.
47
+ *
48
+ * A directions edit routes through {@link buildRouteFn}, which adopts the opening shape's own
49
+ * hazards without asking; a freehand edit resolves its line's profile through
50
+ * {@link buildAnalyzeFn}. An absent activity or pin arms as `undefined`, the editor's defaults, and
51
+ * an absent colour as `DEFAULT_SEGMENT_COLOR`, the colour the map draws such a segment in. Every
52
+ * coordinate is a copy. Arming the same segment and mode again with an unchanged seed is the map
53
+ * client's no-op, so a caller re-arms on any change.
54
+ *
55
+ * @example
56
+ * ```ts
57
+ * const session = ctx.ui.getState().segmentEditSession;
58
+ * if (session !== null) {
59
+ * ctx.map?.beginSegmentEdit(buildSegmentEditOptions(session, { client: ctx.api?.client }));
60
+ * }
61
+ * ```
62
+ */
63
+ export const buildSegmentEditOptions = (
64
+ session: SegmentEditSession,
65
+ seams: SegmentArmingSeams,
66
+ ): SegmentEditOptions => {
67
+ const { client, confirmHazards, hazardMemo, onViaCapRefused } = seams;
68
+ const seedVias = session.seedVias.map((via): Position => [via[0], via[1]]);
69
+
70
+ return {
71
+ activitySlug: session.activitySlug ?? undefined,
72
+ analyzeFn: session.mode === "linestring" && client ? buildAnalyzeFn(client) : undefined,
73
+ color: session.draftColor ?? DEFAULT_SEGMENT_COLOR,
74
+ featureId: session.segmentId,
75
+ mode: session.mode,
76
+ onViaCapRefused,
77
+ pinnedEnd: session.pinnedEnd ? [session.pinnedEnd[0], session.pinnedEnd[1]] : undefined,
78
+ pinnedStart: session.pinnedStart ? [session.pinnedStart[0], session.pinnedStart[1]] : undefined,
79
+ routeFn:
80
+ session.mode === "directions" && client
81
+ ? buildRouteFn(client, { confirmHazards, hazardMemo, seedVias })
82
+ : undefined,
83
+ seedVias,
84
+ };
85
+ };
86
+
87
+ /**
88
+ * RouteHazardPromptTexts are the words the route-hazard prompt is written in, resolved once per
89
+ * language: how it tells each hazard, its title for several, and the line its body closes on.
90
+ */
91
+ export interface RouteHazardPromptTexts {
92
+ /** The line the prompt's body closes on, after the sentence of each hazard it names. */
93
+ readonly closing: string;
94
+ /**
95
+ * Each hazard a route can cross: the prompt's title when it is the only kind the route
96
+ * crosses, and the sentence its body tells it in, saying who the way is for.
97
+ */
98
+ readonly hazards: Readonly<
99
+ Record<RouteAdvisory, { readonly sentence: string; readonly title: string }>
100
+ >;
101
+ /** The prompt's title when the route crosses more than one kind of hazard. */
102
+ readonly severalTitle: string;
103
+ }
104
+
105
+ /**
106
+ * routeHazardConfirmation is the question a confirm gate is asked when a routed segment crosses a
107
+ * hazard the session has not accepted: whether to adopt the line anyway.
108
+ *
109
+ * The prompt is titled by the one kind of hazard the route crosses (a private way, a tollway), or
110
+ * by the title for several kinds, and its body tells each hazard in its own sentence, in the order
111
+ * given, then closes on what the reader can do. The request carries the hazards as their codes,
112
+ * joined with a comma, under the `hazards` value the studio's `editing.routeHazard*` labels read,
113
+ * so a confirm gate builds the title and the body in its own reader's language; `description`
114
+ * holds the body in the words given here, for a gate that resolves no label. The tone is
115
+ * `cautionary`: nothing is lost, but the line may cross a way the person is not allowed on. It is
116
+ * a question rather than a tool's confirmation policy because whether to ask depends on the route
117
+ * that came back.
118
+ *
119
+ * @example
120
+ * ```ts
121
+ * declare const strings: StudioStrings;
122
+ *
123
+ * const approved = await ctx.confirm?.(
124
+ * routeHazardConfirmation(["private"], {
125
+ * closing: strings.editing.routeHazardClosing,
126
+ * hazards: strings.editing.routeHazards,
127
+ * severalTitle: strings.editing.routeHazardsTitle,
128
+ * }),
129
+ * );
130
+ * ```
131
+ */
132
+ export const routeHazardConfirmation = (
133
+ hazards: readonly RouteAdvisory[],
134
+ texts: RouteHazardPromptTexts,
135
+ ): ConfirmationRequest => ({
136
+ confirmLabel: "editing.routeHazardConfirm",
137
+ description: routeHazardBody(hazards, texts),
138
+ descriptionLabel: "editing.routeHazardDescription",
139
+ input: { hazards },
140
+ name: "studio.segment.route.hazard",
141
+ titleLabel: "editing.routeHazardTitle",
142
+ tone: "cautionary",
143
+ values: { hazards: hazards.join(HAZARD_CODE_SEPARATOR) },
144
+ });
@@ -0,0 +1,84 @@
1
+ import type { Geometry } from "geojson";
2
+
3
+ import {
4
+ projectOnSegment,
5
+ type SegmentPoint,
6
+ type SegmentProjection,
7
+ SPLIT_MIN_END_DISTANCE_METERS,
8
+ segmentLengthMeters,
9
+ } from "./metrics.js";
10
+
11
+ /**
12
+ * SplitPickVerdict is {@link splitPickVerdict}'s answer: the `fraction` of the segment's length
13
+ * a cut lands at, or the tool bus code refusing it. A refused point that does project onto the
14
+ * line carries that `projection`, so a preview can still pin where the pointer is aimed.
15
+ */
16
+ export type SplitPickVerdict =
17
+ | { readonly fraction: number; readonly ok: true; readonly projection: SegmentProjection }
18
+ | { readonly code: "invalid-input"; readonly ok: false }
19
+ | {
20
+ readonly code: "split-on-end" | "split-too-far";
21
+ readonly ok: false;
22
+ readonly projection: SegmentProjection;
23
+ };
24
+
25
+ /**
26
+ * splitPickVerdict judges a point picked to split a segment, the one judgement a split pick's
27
+ * preview and its click both make: it projects the point onto the segment's line and answers
28
+ * the fraction the cut lands at, or the first of these refusals.
29
+ *
30
+ * 1. `invalid-input`: the segment has no line to project onto.
31
+ * 2. `split-too-far`: the point is further from the line than `toleranceMeters`, the pick's
32
+ * screen reach in ground meters where it was picked (`SPLIT_PICK_TOLERANCE_PX` pixels of
33
+ * `groundMetersPerPixel` each). A projection always lands, so without a reach a click
34
+ * anywhere would cut at an end. A point exactly at the reach is taken,
35
+ * `Number.POSITIVE_INFINITY` judges no reach (a point never aimed with a pointer), and a
36
+ * tolerance that is not a number refuses every point.
37
+ * 3. `split-on-end`: the cut lands on an end, as {@link isSplitOnEnd} judges it.
38
+ */
39
+ export const splitPickVerdict = (
40
+ geojson: Geometry | null | undefined,
41
+ lngLat: SegmentPoint,
42
+ toleranceMeters: number,
43
+ ): SplitPickVerdict => {
44
+ const projection = projectOnSegment(geojson, lngLat);
45
+ if (!projection) {
46
+ return { code: "invalid-input", ok: false };
47
+ }
48
+
49
+ // Written as "not within reach" so a tolerance that is not a number refuses rather than
50
+ // passes: NaN compares false both ways.
51
+ if (!(projection.distanceMeters <= toleranceMeters)) {
52
+ return { code: "split-too-far", ok: false, projection };
53
+ }
54
+
55
+ const { fraction } = projection;
56
+ if (isSplitOnEnd(geojson, fraction)) {
57
+ return { code: "split-on-end", ok: false, projection };
58
+ }
59
+
60
+ return { fraction, ok: true, projection };
61
+ };
62
+
63
+ /**
64
+ * isSplitOnEnd reports whether a cut at `fraction` of a segment's length lands on one of its
65
+ * ends: at the fraction 0 or 1, or leaving less than {@link SPLIT_MIN_END_DISTANCE_METERS} of
66
+ * line on either side.
67
+ *
68
+ * The one statement of the end floor, for a cut picked on the map and for a fraction given
69
+ * outright. Such a cut makes nothing or a piece the API refuses.
70
+ *
71
+ * @param geojson The segment's geometry. One with no length is on its end at every fraction.
72
+ * @param fraction Where the cut lands, as a share of the segment's length from 0 to 1.
73
+ */
74
+ export const isSplitOnEnd = (geojson: Geometry | null | undefined, fraction: number): boolean => {
75
+ const lengthMeters = segmentLengthMeters(geojson);
76
+ const headMeters = lengthMeters * fraction;
77
+
78
+ return (
79
+ fraction <= 0 ||
80
+ fraction >= 1 ||
81
+ headMeters < SPLIT_MIN_END_DISTANCE_METERS ||
82
+ lengthMeters - headMeters < SPLIT_MIN_END_DISTANCE_METERS
83
+ );
84
+ };
@@ -0,0 +1,230 @@
1
+ import type { Position } from "geojson";
2
+
3
+ /**
4
+ * chordDistance is the distance from `point` to the chord from `start` to `end`, in the
5
+ * coordinate units of the positions. It is the deviation the Ramer–Douglas–Peucker pass keeps a
6
+ * vertex for: a vertex far off the chord between its neighbours is a salient corner, one on the
7
+ * chord is redundant.
8
+ *
9
+ * The chord is the stretch between the two ends and not the line through them. A vertex that
10
+ * projects between the ends is measured at right angles to the chord, and one that projects
11
+ * beyond an end is measured to that end, so the turnaround of an out-and-back is as far off the
12
+ * chord as the walk went past its end. When `start` and `end` coincide it is the plain distance
13
+ * to that shared point. Longitude is not scaled by latitude: the pass only compares deviations
14
+ * with one another, and a uniform planar metric ranks them as a scaled one would over a line of
15
+ * an editor's resolution.
16
+ */
17
+ const chordDistance = (point: Position, start: Position, end: Position): number => {
18
+ const [px = 0, py = 0] = point;
19
+ const [sx = 0, sy = 0] = start;
20
+ const [ex = 0, ey = 0] = end;
21
+
22
+ const dx = ex - sx;
23
+ const dy = ey - sy;
24
+ const lengthSq = dx * dx + dy * dy;
25
+ if (lengthSq === 0) {
26
+ return Math.hypot(px - sx, py - sy);
27
+ }
28
+
29
+ // Where the point projects along the chord, held between its two ends.
30
+ const along = Math.min(1, Math.max(0, ((px - sx) * dx + (py - sy) * dy) / lengthSq));
31
+
32
+ return Math.hypot(px - (sx + along * dx), py - (sy + along * dy));
33
+ };
34
+
35
+ /**
36
+ * douglasPeucker returns the indices of `line` to keep when simplified at the given epsilon: the
37
+ * first and last index always, plus every vertex whose perpendicular distance to the chord of its
38
+ * retained neighbours exceeds epsilon. It is the classic recursive Ramer–Douglas–Peucker split:
39
+ * find the vertex farthest from the chord, and if it deviates by more than epsilon keep it and
40
+ * recurse on both halves; otherwise drop the whole span between the endpoints. The returned indices
41
+ * are ascending, so a caller maps them straight back onto positions. Implemented with an explicit
42
+ * stack rather than recursion so a dense line cannot overflow the call stack.
43
+ */
44
+ const douglasPeucker = (line: Position[], epsilon: number): number[] => {
45
+ const lastIndex = line.length - 1;
46
+ const keep = new Set<number>([0, lastIndex]);
47
+ const stack: [number, number][] = [[0, lastIndex]];
48
+
49
+ while (stack.length > 0) {
50
+ const span = stack.pop();
51
+ if (!span) {
52
+ continue;
53
+ }
54
+
55
+ const [from, to] = span;
56
+ if (to - from < 2) {
57
+ continue;
58
+ }
59
+
60
+ const start = line[from];
61
+ const end = line[to];
62
+ if (!start || !end) {
63
+ continue;
64
+ }
65
+
66
+ let farthest = -1;
67
+ let farthestDistance = -1;
68
+ for (let index = from + 1; index < to; index += 1) {
69
+ const point = line[index];
70
+ if (!point) {
71
+ continue;
72
+ }
73
+
74
+ const distance = chordDistance(point, start, end);
75
+ if (distance > farthestDistance) {
76
+ farthest = index;
77
+ farthestDistance = distance;
78
+ }
79
+ }
80
+
81
+ if (farthest !== -1 && farthestDistance > epsilon) {
82
+ keep.add(farthest);
83
+ stack.push([from, farthest]);
84
+ stack.push([farthest, to]);
85
+ }
86
+ }
87
+
88
+ return [...keep].sort((a, b) => a - b);
89
+ };
90
+
91
+ /**
92
+ * strideSlots answers `count` positions spread evenly over `length` slots, always the first and
93
+ * the last, in ascending order. It is the stride both thinning passes take, computed rather than
94
+ * read off a list, so a stride over a long line allocates the positions it keeps and no others.
95
+ * Assumes `count >= 2` and `length > count` (the callers gate both).
96
+ */
97
+ const strideSlots = (length: number, count: number): number[] => {
98
+ const last = length - 1;
99
+ const stride = last / (count - 1);
100
+ const slots: number[] = [];
101
+ for (let slot = 0; slot < count - 1; slot += 1) {
102
+ slots.push(Math.round(slot * stride));
103
+ }
104
+
105
+ slots.push(last);
106
+
107
+ return slots;
108
+ };
109
+
110
+ /**
111
+ * decimateIndices evenly thins an ascending index list down to exactly `count` entries, always
112
+ * keeping the first and last so the span is preserved. It is the hard fallback simplifyToVias
113
+ * applies when even the coarsest Ramer–Douglas–Peucker pass leaves more vertices than the cap
114
+ * allows: a uniform stride across the kept indices guarantees the result lands at the cap rather
115
+ * than one above it. Assumes `count >= 2` and `indices.length > count` (the caller gates both).
116
+ */
117
+ const decimateIndices = (indices: readonly number[], count: number): number[] =>
118
+ strideSlots(indices.length, count)
119
+ .map((slot) => indices[slot])
120
+ .filter((index): index is number => index !== undefined);
121
+
122
+ /**
123
+ * SIMPLIFY_EPSILON_STEPS is how many times simplifyToVias doubles the
124
+ * Ramer–Douglas–Peucker tolerance while searching for a simplification that fits
125
+ * the via cap. The search starts from a tolerance seeded off the line's own
126
+ * extent (so it scales with the itinerary's size) and doubles each step; this bounds
127
+ * the loop so a pathological line falls through to the even-decimation fallback
128
+ * rather than looping unbounded.
129
+ */
130
+ const SIMPLIFY_EPSILON_STEPS = 24;
131
+
132
+ /**
133
+ * SIMPLIFY_INPUT_MAX is how many input vertices the tolerance search is allowed to see.
134
+ *
135
+ * Every other bound in this module is on the OUTPUT, and the output is not where the cost is: it is
136
+ * two to forty-five vias however long the line is. The cost is on the input. Ramer–Douglas–Peucker
137
+ * is O(n log n) on a balanced split and O(n²) on a pathological one, the search below runs it once
138
+ * more than {@link SIMPLIFY_EPSILON_STEPS} times at most, and all of that is synchronous on the
139
+ * main thread, so a line's LENGTH, not its shape, decides whether the browser stalls.
140
+ *
141
+ * That length is a consumer's file. A routed segment from the API is hundreds of coordinates and
142
+ * cheap; an imported GPX track is a device's raw log, commonly tens of thousands of points and
143
+ * occasionally hundreds of thousands, and it reaches here through the same call. The first symptom
144
+ * is the tab freezing on drop, with no error and nothing to blame.
145
+ *
146
+ * Two thousand, because the relationship that matters is to the CAP rather than to the line: at
147
+ * forty-five vias the sampled line is still oversampled by more than forty to one, so the salient
148
+ * corners a via set is meant to land on are all present. Decimating further would start to cost
149
+ * shape; not decimating at all costs a frozen tab for a file somebody exported from a watch.
150
+ */
151
+ const SIMPLIFY_INPUT_MAX = 2_000;
152
+
153
+ /**
154
+ * simplifyToVias reduces a dense routed line to a shape-preserving via set of at most `maxVias`
155
+ * points, always keeping the first and last coordinate so the via set spans the whole itinerary. It
156
+ * runs Ramer–Douglas–Peucker at a tolerance seeded off the line's bounding extent and doubles that
157
+ * tolerance until the kept set fits the cap; if the coarsest pass in that search still exceeds the
158
+ * cap, it falls back to an even decimation of the simplified set down to exactly the cap. The
159
+ * result is always within `[2, maxVias]` for an input of two or more points: a straight line
160
+ * collapses to its two endpoints, a zigzag keeps its salient corners up to the cap. An input
161
+ * shorter than two points is returned unchanged (it cannot describe a line); a `maxVias` below two
162
+ * is treated as two so the endpoints always survive. Pure (no side effects), so the suggest
163
+ * hand-off can derive the seed vias deterministically from the chosen itinerary's coordinates.
164
+ *
165
+ * A line longer than {@link SIMPLIFY_INPUT_MAX} is evenly strided down to that length first, so the
166
+ * tolerance search's cost is bounded by a constant rather than by whatever file a consumer dropped
167
+ * on the map. The first and last coordinate survive the stride, so the via set still spans the
168
+ * whole itinerary.
169
+ */
170
+ export const simplifyToVias = (line: Position[], maxVias: number): Position[] => {
171
+ // An input that cannot describe a line is returned as-is: the caller assumes two or more points,
172
+ // and this is the defensive floor.
173
+ if (line.length < 2) {
174
+ return line;
175
+ }
176
+
177
+ // A cap below two, or one that is no number, reads as two: `Math.max(2, NaN)` is NaN, which
178
+ // no length exceeds, and the search below would then bound nothing.
179
+ const cap = maxVias >= 2 ? maxVias : 2;
180
+
181
+ // Bound what the search sees, BEFORE the search. An even stride rather than a
182
+ // simplification, deliberately: deciding which vertices matter is the tolerance
183
+ // search's job and doing it twice with two metrics would make the result depend
184
+ // on the input's length. A stride is shape-agnostic and costs one pass.
185
+ const sampled =
186
+ line.length <= SIMPLIFY_INPUT_MAX
187
+ ? line
188
+ : strideSlots(line.length, SIMPLIFY_INPUT_MAX)
189
+ .map((index) => line[index])
190
+ .filter((point): point is Position => point !== undefined);
191
+
192
+ // First simplify at a zero tolerance: this keeps every genuine corner and drops
193
+ // only vertices that lie exactly on the chord between their neighbours, so a
194
+ // dead-straight line collapses to its two endpoints while a curved line under
195
+ // the cap keeps all its shape. Only when even that exact-redundancy pass leaves
196
+ // more vertices than the cap does the tolerance escalate.
197
+ let indices = douglasPeucker(sampled, 0);
198
+ if (indices.length > cap) {
199
+ // Seed the escalation step off the line's extent so the doubling search
200
+ // scales with the itinerary's size; a degenerate (zero-extent) line seeds a tiny
201
+ // positive epsilon so the search still makes progress.
202
+ let minX = Number.POSITIVE_INFINITY;
203
+ let minY = Number.POSITIVE_INFINITY;
204
+ let maxX = Number.NEGATIVE_INFINITY;
205
+ let maxY = Number.NEGATIVE_INFINITY;
206
+ for (const [x = 0, y = 0] of sampled) {
207
+ minX = Math.min(minX, x);
208
+ minY = Math.min(minY, y);
209
+ maxX = Math.max(maxX, x);
210
+ maxY = Math.max(maxY, y);
211
+ }
212
+
213
+ const extent = Math.hypot(maxX - minX, maxY - minY);
214
+ let epsilon = extent > 0 ? extent / sampled.length : Number.EPSILON;
215
+
216
+ for (let step = 0; step < SIMPLIFY_EPSILON_STEPS && indices.length > cap; step += 1) {
217
+ indices = douglasPeucker(sampled, epsilon);
218
+ epsilon *= 2;
219
+ }
220
+ }
221
+
222
+ // If the coarsest tried tolerance still leaves more vertices than the cap,
223
+ // evenly decimate the simplified set down to exactly the cap so the result is
224
+ // guaranteed to be within [2, cap].
225
+ const capped = indices.length > cap ? decimateIndices(indices, cap) : indices;
226
+
227
+ return capped
228
+ .map((index) => sampled[index])
229
+ .filter((point): point is Position => point !== undefined);
230
+ };