@mountaya/studio 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 (521) hide show
  1. package/CHANGELOG.md +69 -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 +2600 -0
  6. package/dist/agent/index.cjs.map +1 -0
  7. package/dist/agent/index.d.cts +1237 -0
  8. package/dist/agent/index.d.ts +1237 -0
  9. package/dist/agent/index.js +2581 -0
  10. package/dist/agent/index.js.map +1 -0
  11. package/dist/chunk-3Oi_Zrtm.js +9 -0
  12. package/dist/chunk-3Oi_Zrtm.js.map +1 -0
  13. package/dist/chunk-B18OPIu_.js +6 -0
  14. package/dist/chunk-B18OPIu_.js.map +1 -0
  15. package/dist/chunk-B5Uz3Qct.cjs +15 -0
  16. package/dist/chunk-B5Uz3Qct.cjs.map +1 -0
  17. package/dist/chunk-BBEJwkd3.d.cts +839 -0
  18. package/dist/chunk-BIEc_SkR.cjs +29 -0
  19. package/dist/chunk-BIEc_SkR.cjs.map +1 -0
  20. package/dist/chunk-BKMFOe-N.js +171 -0
  21. package/dist/chunk-BKMFOe-N.js.map +1 -0
  22. package/dist/chunk-BP4uy7E1.d.ts +11583 -0
  23. package/dist/chunk-BSHTsFiB.js +1403 -0
  24. package/dist/chunk-BSHTsFiB.js.map +1 -0
  25. package/dist/chunk-BTUUABGI.js +17 -0
  26. package/dist/chunk-BTUUABGI.js.map +1 -0
  27. package/dist/chunk-BaPiaz5X.cjs +115 -0
  28. package/dist/chunk-BaPiaz5X.cjs.map +1 -0
  29. package/dist/chunk-BeCVpkYr.cjs +542 -0
  30. package/dist/chunk-BeCVpkYr.cjs.map +1 -0
  31. package/dist/chunk-BgngsvK8.cjs +6202 -0
  32. package/dist/chunk-BgngsvK8.cjs.map +1 -0
  33. package/dist/chunk-BhInd7CJ.d.cts +253 -0
  34. package/dist/chunk-Bn6ZbxkS.cjs +27 -0
  35. package/dist/chunk-By9ZnkVI.js +60 -0
  36. package/dist/chunk-By9ZnkVI.js.map +1 -0
  37. package/dist/chunk-BzqPhxsz.cjs +367 -0
  38. package/dist/chunk-BzqPhxsz.cjs.map +1 -0
  39. package/dist/chunk-C2mMX81q.d.ts +443 -0
  40. package/dist/chunk-C2rr9Q0V.cjs +1402 -0
  41. package/dist/chunk-C2rr9Q0V.cjs.map +1 -0
  42. package/dist/chunk-CDJCbwIQ.d.cts +78 -0
  43. package/dist/chunk-CLGvBOVH.d.cts +1654 -0
  44. package/dist/chunk-COdw1dc6.d.ts +525 -0
  45. package/dist/chunk-CQCJnT2i.d.ts +511 -0
  46. package/dist/chunk-CSyHY67q.cjs +353 -0
  47. package/dist/chunk-CSyHY67q.cjs.map +1 -0
  48. package/dist/chunk-CiK1Iqrv.js +950 -0
  49. package/dist/chunk-CiK1Iqrv.js.map +1 -0
  50. package/dist/chunk-CmJBgSwZ.cjs +24 -0
  51. package/dist/chunk-CmJBgSwZ.cjs.map +1 -0
  52. package/dist/chunk-CnrsRK2u.cjs +83 -0
  53. package/dist/chunk-CnrsRK2u.cjs.map +1 -0
  54. package/dist/chunk-Co782_9r.js +326 -0
  55. package/dist/chunk-Co782_9r.js.map +1 -0
  56. package/dist/chunk-Csr3KDpZ.cjs +32 -0
  57. package/dist/chunk-Csr3KDpZ.cjs.map +1 -0
  58. package/dist/chunk-CwkmccXv.js +89 -0
  59. package/dist/chunk-CwkmccXv.js.map +1 -0
  60. package/dist/chunk-D0Q4iL9B.cjs +255 -0
  61. package/dist/chunk-D0Q4iL9B.cjs.map +1 -0
  62. package/dist/chunk-DFwiSzUS.cjs +72 -0
  63. package/dist/chunk-DFwiSzUS.cjs.map +1 -0
  64. package/dist/chunk-DIFayl2P.d.cts +443 -0
  65. package/dist/chunk-DIGF58ux.d.cts +525 -0
  66. package/dist/chunk-DKuuuld5.js +101 -0
  67. package/dist/chunk-DKuuuld5.js.map +1 -0
  68. package/dist/chunk-DMePkFEo.js +5054 -0
  69. package/dist/chunk-DMePkFEo.js.map +1 -0
  70. package/dist/chunk-DO5SIBgu.js +305 -0
  71. package/dist/chunk-DO5SIBgu.js.map +1 -0
  72. package/dist/chunk-DOQ_7eE5.d.ts +6662 -0
  73. package/dist/chunk-DThaaNeb.d.cts +15 -0
  74. package/dist/chunk-DThaaNeb.d.ts +15 -0
  75. package/dist/chunk-DUQzjUJy.d.ts +78 -0
  76. package/dist/chunk-DX37IPhV.cjs +1903 -0
  77. package/dist/chunk-DX37IPhV.cjs.map +1 -0
  78. package/dist/chunk-Damps5Tk.cjs +155 -0
  79. package/dist/chunk-Damps5Tk.cjs.map +1 -0
  80. package/dist/chunk-DbK5PhpJ.d.ts +1654 -0
  81. package/dist/chunk-De0vAASv.d.ts +253 -0
  82. package/dist/chunk-DhSZ7YZt.d.cts +6662 -0
  83. package/dist/chunk-DjEvqvPA.cjs +43 -0
  84. package/dist/chunk-DjEvqvPA.cjs.map +1 -0
  85. package/dist/chunk-DkwDzwvu.d.cts +121 -0
  86. package/dist/chunk-DkwDzwvu.d.ts +121 -0
  87. package/dist/chunk-Dmszv9If.js +71 -0
  88. package/dist/chunk-Dmszv9If.js.map +1 -0
  89. package/dist/chunk-Dp_ftNWY.d.cts +511 -0
  90. package/dist/chunk-DsHQySz0.js +31 -0
  91. package/dist/chunk-DsHQySz0.js.map +1 -0
  92. package/dist/chunk-DwoUyHHh.js +281 -0
  93. package/dist/chunk-DwoUyHHh.js.map +1 -0
  94. package/dist/chunk-IaIDQflj.d.cts +2315 -0
  95. package/dist/chunk-IaIDQflj.d.ts +2315 -0
  96. package/dist/chunk-cVXLsZfL.d.ts +839 -0
  97. package/dist/chunk-mIaCX9EJ.d.cts +11583 -0
  98. package/dist/chunk-nJQxbOwQ.cjs +8962 -0
  99. package/dist/chunk-nJQxbOwQ.cjs.map +1 -0
  100. package/dist/chunk-o9jaxhCO.js +8852 -0
  101. package/dist/chunk-o9jaxhCO.js.map +1 -0
  102. package/dist/chunk-p-Tt_Lwz.js +14 -0
  103. package/dist/chunk-p-Tt_Lwz.js.map +1 -0
  104. package/dist/engines/index.cjs +2091 -0
  105. package/dist/engines/index.cjs.map +1 -0
  106. package/dist/engines/index.d.cts +2176 -0
  107. package/dist/engines/index.d.ts +2176 -0
  108. package/dist/engines/index.js +2075 -0
  109. package/dist/engines/index.js.map +1 -0
  110. package/dist/handlers/index.cjs +53 -0
  111. package/dist/handlers/index.cjs.map +1 -0
  112. package/dist/handlers/index.d.cts +403 -0
  113. package/dist/handlers/index.d.ts +403 -0
  114. package/dist/handlers/index.js +33 -0
  115. package/dist/handlers/index.js.map +1 -0
  116. package/dist/index.cjs +3511 -0
  117. package/dist/index.cjs.map +1 -0
  118. package/dist/index.d.cts +8 -0
  119. package/dist/index.d.ts +8 -0
  120. package/dist/index.js +3033 -0
  121. package/dist/index.js.map +1 -0
  122. package/dist/plugins/index.cjs +510 -0
  123. package/dist/plugins/index.cjs.map +1 -0
  124. package/dist/plugins/index.d.cts +296 -0
  125. package/dist/plugins/index.d.ts +296 -0
  126. package/dist/plugins/index.js +489 -0
  127. package/dist/plugins/index.js.map +1 -0
  128. package/dist/seams/index.cjs +89 -0
  129. package/dist/seams/index.cjs.map +1 -0
  130. package/dist/seams/index.d.cts +452 -0
  131. package/dist/seams/index.d.ts +452 -0
  132. package/dist/seams/index.js +49 -0
  133. package/dist/seams/index.js.map +1 -0
  134. package/dist/strings/fr/index.cjs +2135 -0
  135. package/dist/strings/fr/index.cjs.map +1 -0
  136. package/dist/strings/fr/index.d.cts +17 -0
  137. package/dist/strings/fr/index.d.ts +17 -0
  138. package/dist/strings/fr/index.js +2130 -0
  139. package/dist/strings/fr/index.js.map +1 -0
  140. package/dist/strings/index.cjs +2384 -0
  141. package/dist/strings/index.cjs.map +1 -0
  142. package/dist/strings/index.d.cts +3 -0
  143. package/dist/strings/index.d.ts +3 -0
  144. package/dist/strings/index.js +2353 -0
  145. package/dist/strings/index.js.map +1 -0
  146. package/dist/testing/index.cjs +230 -0
  147. package/dist/testing/index.cjs.map +1 -0
  148. package/dist/testing/index.d.cts +246 -0
  149. package/dist/testing/index.d.ts +246 -0
  150. package/dist/testing/index.js +219 -0
  151. package/dist/testing/index.js.map +1 -0
  152. package/dist/time/index.cjs +28 -0
  153. package/dist/time/index.cjs.map +1 -0
  154. package/dist/time/index.d.cts +41 -0
  155. package/dist/time/index.d.ts +41 -0
  156. package/dist/time/index.js +23 -0
  157. package/dist/time/index.js.map +1 -0
  158. package/package.json +224 -4
  159. package/src/agent/engines/agentThreads.ts +1601 -0
  160. package/src/agent/engines/directorChat.ts +500 -0
  161. package/src/agent/index.ts +67 -0
  162. package/src/agent/rules/agentEditLock.ts +115 -0
  163. package/src/agent/rules/agentErrorCopy.ts +44 -0
  164. package/src/agent/rules/copilotOrganization.ts +36 -0
  165. package/src/agent/rules/playbook.gen.ts +444 -0
  166. package/src/agent/rules/router.ts +518 -0
  167. package/src/agent/rules/stateDelta.ts +29 -0
  168. package/src/agent/rules/studioRouter.ts +123 -0
  169. package/src/agent/rules/surfaces.gen.ts +633 -0
  170. package/src/agent/rules/threadsUrl.ts +48 -0
  171. package/src/agent/rules/transcriptObserver.ts +90 -0
  172. package/src/agent/stores/agentThreads.ts +451 -0
  173. package/src/bus/contracts/noData.ts +18 -0
  174. package/src/bus/contracts/shared.ts +172 -0
  175. package/src/bus/contracts/studioTools.ts +224 -0
  176. package/src/bus/rules/bus.ts +857 -0
  177. package/src/bus/rules/confirmation.ts +22 -0
  178. package/src/bus/rules/defineRegistry.ts +24 -0
  179. package/src/bus/rules/errors.ts +401 -0
  180. package/src/bus/rules/handlerErrors.ts +103 -0
  181. package/src/bus/rules/handlerRegistry.ts +627 -0
  182. package/src/bus/rules/inputSchema.ts +232 -0
  183. package/src/bus/rules/invalidInput.ts +441 -0
  184. package/src/bus/rules/lateBoundTools.ts +100 -0
  185. package/src/bus/rules/studioRegistry.ts +324 -0
  186. package/src/bus/rules/studioToolBus.ts +73 -0
  187. package/src/bus/rules/types.ts +804 -0
  188. package/src/chrome/contracts/alert.ts +42 -0
  189. package/src/chrome/contracts/itinerary.ts +26 -0
  190. package/src/chrome/contracts/map.ts +23 -0
  191. package/src/chrome/contracts/overlay.ts +46 -0
  192. package/src/chrome/contracts/panel.ts +29 -0
  193. package/src/chrome/contracts/question.ts +52 -0
  194. package/src/chrome/contracts/selection.ts +26 -0
  195. package/src/chrome/contracts/sidenav.ts +23 -0
  196. package/src/chrome/contracts/snapshot.ts +319 -0
  197. package/src/chrome/contracts/state.ts +22 -0
  198. package/src/chrome/contracts/tabs.ts +56 -0
  199. package/src/chrome/handlers/alert.ts +91 -0
  200. package/src/chrome/handlers/introspection.ts +180 -0
  201. package/src/chrome/handlers/panels.ts +42 -0
  202. package/src/chrome/handlers/question.ts +24 -0
  203. package/src/chrome/handlers/sidenav.ts +116 -0
  204. package/src/chrome/handlers/snapshot.ts +451 -0
  205. package/src/chrome/handlers/stateDelta.ts +125 -0
  206. package/src/chrome/handlers/tabs.ts +143 -0
  207. package/src/chrome/handlers/timestamp.ts +19 -0
  208. package/src/chrome/rules/agentSelectors.ts +210 -0
  209. package/src/chrome/rules/mapAlert.ts +13 -0
  210. package/src/chrome/rules/question.ts +25 -0
  211. package/src/chrome/rules/tabs.ts +13 -0
  212. package/src/chrome/stores/activeDraftSession.ts +134 -0
  213. package/src/chrome/stores/chrome.ts +527 -0
  214. package/src/chrome/stores/uiStore.ts +575 -0
  215. package/src/collab/contracts/collab.ts +261 -0
  216. package/src/collab/handlers/collab.ts +468 -0
  217. package/src/collab/rules/toolNames.ts +33 -0
  218. package/src/collab/stores/collab.ts +899 -0
  219. package/src/collections/contracts/collection.ts +182 -0
  220. package/src/collections/handlers/collectionAttach.ts +141 -0
  221. package/src/collections/handlers/collections.ts +499 -0
  222. package/src/collections/handlers/heldCollection.ts +42 -0
  223. package/src/collections/handlers/restCollections.ts +386 -0
  224. package/src/collections/rules/collections.ts +138 -0
  225. package/src/collections/rules/entityCollections.ts +53 -0
  226. package/src/collections/stores/collections.ts +133 -0
  227. package/src/data/contracts/data.ts +233 -0
  228. package/src/data/contracts/itinerary.ts +71 -0
  229. package/src/data/handlers/activityResolve.ts +76 -0
  230. package/src/data/handlers/data.ts +200 -0
  231. package/src/data/handlers/graphql.ts +26 -0
  232. package/src/data/handlers/mutationSink.ts +1577 -0
  233. package/src/data/handlers/profile.ts +83 -0
  234. package/src/data/handlers/writeThrough.ts +417 -0
  235. package/src/data/rules/cache.ts +181 -0
  236. package/src/data/rules/dataTypes.ts +40 -0
  237. package/src/data/rules/keys.ts +106 -0
  238. package/src/data/rules/persistence.ts +1058 -0
  239. package/src/data/rules/requestBody.ts +43 -0
  240. package/src/data/rules/restErrors.ts +354 -0
  241. package/src/data/rules/sessionSurface.ts +156 -0
  242. package/src/data/rules/toolResultData.ts +73 -0
  243. package/src/data/rules/uuid.ts +24 -0
  244. package/src/edit/contracts/edit.ts +37 -0
  245. package/src/edit/contracts/itinerary.ts +57 -0
  246. package/src/edit/handlers/draftCommit.ts +257 -0
  247. package/src/edit/handlers/editDiscard.ts +34 -0
  248. package/src/edit/handlers/editLock.ts +949 -0
  249. package/src/edit/handlers/editor.ts +203 -0
  250. package/src/edit/handlers/formUnsaved.ts +24 -0
  251. package/src/edit/rules/draftMetadata.ts +117 -0
  252. package/src/edit/rules/editKeyboard.ts +222 -0
  253. package/src/edit/rules/editShortcuts.ts +102 -0
  254. package/src/edit/rules/editTooltip.ts +174 -0
  255. package/src/edit/rules/editorTaken.ts +49 -0
  256. package/src/edit/rules/history.ts +26 -0
  257. package/src/edit/rules/unsavedWork.ts +60 -0
  258. package/src/edit/stores/editorReservation.ts +70 -0
  259. package/src/edit/stores/formsUnsaved.ts +54 -0
  260. package/src/embed/contracts/embed.ts +48 -0
  261. package/src/embed/engines/embedFraming.ts +1329 -0
  262. package/src/embed/engines/embedReady.ts +353 -0
  263. package/src/embed/engines/framingPageSession.ts +169 -0
  264. package/src/embed/handlers/embed.ts +130 -0
  265. package/src/embed/rules/allowedDomains.ts +71 -0
  266. package/src/embed/rules/bridgeMessages.ts +224 -0
  267. package/src/embed/rules/defaults.ts +173 -0
  268. package/src/embed/rules/displaySeed.ts +115 -0
  269. package/src/embed/rules/embedAllowlist.ts +146 -0
  270. package/src/embed/rules/embedConstraints.ts +215 -0
  271. package/src/embed/rules/embedElements.ts +277 -0
  272. package/src/embed/rules/embedSectionFields.ts +126 -0
  273. package/src/embed/rules/embedSecurity.ts +116 -0
  274. package/src/embed/rules/fieldDependencies.ts +89 -0
  275. package/src/embed/rules/fieldOptions.ts +138 -0
  276. package/src/embed/rules/layerOptions.ts +161 -0
  277. package/src/embed/rules/readyProtocol.ts +66 -0
  278. package/src/embed/rules/safetyRules.ts +215 -0
  279. package/src/embed/rules/snippet.ts +531 -0
  280. package/src/embed/rules/tableCode.ts +270 -0
  281. package/src/embed/stores/embed.ts +60 -0
  282. package/src/embed/stores/embedContent.ts +77 -0
  283. package/src/engines/index.ts +81 -0
  284. package/src/handlers/index.ts +66 -0
  285. package/src/index.ts +1065 -0
  286. package/src/itinerary/contracts/itinerary.ts +705 -0
  287. package/src/itinerary/engines/itineraryPace.ts +612 -0
  288. package/src/itinerary/engines/profileMarker.ts +238 -0
  289. package/src/itinerary/handlers/importStaging.ts +352 -0
  290. package/src/itinerary/handlers/itinerary.ts +572 -0
  291. package/src/itinerary/handlers/itineraryDuplicate.ts +177 -0
  292. package/src/itinerary/handlers/itineraryExport.ts +117 -0
  293. package/src/itinerary/handlers/itineraryImport.ts +783 -0
  294. package/src/itinerary/handlers/itineraryPublish.ts +118 -0
  295. package/src/itinerary/handlers/itinerarySelection.ts +354 -0
  296. package/src/itinerary/handlers/itinerarySuggest.ts +1186 -0
  297. package/src/itinerary/handlers/itineraryUnpublish.ts +101 -0
  298. package/src/itinerary/handlers/publicationScope.ts +118 -0
  299. package/src/itinerary/handlers/restItineraries.ts +752 -0
  300. package/src/itinerary/handlers/restItineraryExport.ts +70 -0
  301. package/src/itinerary/handlers/restItineraryImport.ts +311 -0
  302. package/src/itinerary/handlers/restItineraryPace.ts +87 -0
  303. package/src/itinerary/handlers/restItineraryRecord.ts +36 -0
  304. package/src/itinerary/handlers/suggestParams.ts +379 -0
  305. package/src/itinerary/handlers/suggestStaging.ts +363 -0
  306. package/src/itinerary/handlers/surfaceOpen.ts +389 -0
  307. package/src/itinerary/rules/activity.ts +139 -0
  308. package/src/itinerary/rules/analysis.ts +42 -0
  309. package/src/itinerary/rules/ceiling.ts +49 -0
  310. package/src/itinerary/rules/createFlow.ts +107 -0
  311. package/src/itinerary/rules/densify.ts +440 -0
  312. package/src/itinerary/rules/draftSurface.ts +219 -0
  313. package/src/itinerary/rules/editorView.ts +83 -0
  314. package/src/itinerary/rules/export.ts +159 -0
  315. package/src/itinerary/rules/friendlyName.ts +77 -0
  316. package/src/itinerary/rules/import.ts +1050 -0
  317. package/src/itinerary/rules/importFiles.ts +140 -0
  318. package/src/itinerary/rules/importTotals.ts +77 -0
  319. package/src/itinerary/rules/liveSegment.ts +712 -0
  320. package/src/itinerary/rules/lngLat.ts +17 -0
  321. package/src/itinerary/rules/mapSync.ts +100 -0
  322. package/src/itinerary/rules/previewRender.ts +416 -0
  323. package/src/itinerary/rules/profileReadout.ts +216 -0
  324. package/src/itinerary/rules/routing.ts +707 -0
  325. package/src/itinerary/rules/suggest.ts +522 -0
  326. package/src/itinerary/rules/suggestionPreview.ts +119 -0
  327. package/src/itinerary/rules/view.ts +61 -0
  328. package/src/itinerary/stores/importSession.ts +319 -0
  329. package/src/itinerary/stores/itinerary.ts +331 -0
  330. package/src/itinerary/stores/itineraryDuplicate.ts +76 -0
  331. package/src/itinerary/stores/sessionIdentity.ts +43 -0
  332. package/src/itinerary/stores/suggestSession.ts +418 -0
  333. package/src/layers/contracts/itinerary.ts +46 -0
  334. package/src/layers/contracts/overlay.ts +132 -0
  335. package/src/layers/handlers/enrichment.ts +36 -0
  336. package/src/layers/handlers/overlay.ts +406 -0
  337. package/src/layers/handlers/restLayers.ts +94 -0
  338. package/src/layers/handlers/tiles.ts +25 -0
  339. package/src/layers/rules/layers.ts +212 -0
  340. package/src/layers/rules/overlayInstant.ts +12 -0
  341. package/src/layers/rules/reachabilityIcon.ts +18 -0
  342. package/src/layers/rules/readout.ts +102 -0
  343. package/src/layers/stores/layers.ts +262 -0
  344. package/src/map/contracts/contextmenu.ts +33 -0
  345. package/src/map/contracts/geolocate.ts +37 -0
  346. package/src/map/contracts/map.ts +146 -0
  347. package/src/map/contracts/streetview.ts +53 -0
  348. package/src/map/contracts/terrain.ts +152 -0
  349. package/src/map/handlers/contextMenu.ts +135 -0
  350. package/src/map/handlers/geolocate.ts +52 -0
  351. package/src/map/handlers/map.ts +391 -0
  352. package/src/map/handlers/streetview.ts +94 -0
  353. package/src/map/handlers/terrain.ts +663 -0
  354. package/src/map/rules/baseTerrain.ts +75 -0
  355. package/src/map/rules/clickTargets.ts +464 -0
  356. package/src/map/rules/constraints.ts +32 -0
  357. package/src/map/rules/contextMenuReadout.ts +67 -0
  358. package/src/map/rules/coordinates.ts +71 -0
  359. package/src/map/rules/itineraryFit.ts +8 -0
  360. package/src/map/rules/mapEvents.ts +64 -0
  361. package/src/map/rules/mapProjection.ts +476 -0
  362. package/src/map/rules/terrainReading.ts +62 -0
  363. package/src/plugins/contracts/ids.ts +66 -0
  364. package/src/plugins/contracts/plugin.ts +202 -0
  365. package/src/plugins/contracts/slots.ts +137 -0
  366. package/src/plugins/engines/studioPlugin.ts +1365 -0
  367. package/src/plugins/index.ts +111 -0
  368. package/src/plugins/rules/contributions.ts +152 -0
  369. package/src/plugins/rules/errors.ts +60 -0
  370. package/src/plugins/rules/ids.ts +42 -0
  371. package/src/plugins/rules/validation.ts +249 -0
  372. package/src/rules/listeners.ts +57 -0
  373. package/src/rules/origin.ts +13 -0
  374. package/src/rules/storeWrite.ts +37 -0
  375. package/src/rules/types.ts +136 -0
  376. package/src/seams/index.ts +79 -0
  377. package/src/seams/rules/clock.ts +28 -0
  378. package/src/seams/rules/formatters.ts +211 -0
  379. package/src/seams/rules/ids.ts +102 -0
  380. package/src/seams/rules/links.ts +66 -0
  381. package/src/seams/rules/navigation.ts +222 -0
  382. package/src/seams/rules/notify.ts +49 -0
  383. package/src/seams/rules/persistenceDrawer.ts +220 -0
  384. package/src/seams/rules/saveFile.ts +101 -0
  385. package/src/seams/rules/seams.ts +156 -0
  386. package/src/seams/rules/storage.ts +116 -0
  387. package/src/search/contracts/overlay.ts +74 -0
  388. package/src/search/contracts/search.ts +197 -0
  389. package/src/search/handlers/pois.ts +57 -0
  390. package/src/search/handlers/search.ts +280 -0
  391. package/src/search/rules/params.ts +925 -0
  392. package/src/search/rules/poiGroups.ts +138 -0
  393. package/src/search/rules/searchFetch.ts +139 -0
  394. package/src/search/rules/timeWindow.ts +30 -0
  395. package/src/search/stores/search.ts +51 -0
  396. package/src/segments/contracts/itinerary.ts +433 -0
  397. package/src/segments/contracts/segment.ts +35 -0
  398. package/src/segments/engines/segmentDraft.ts +926 -0
  399. package/src/segments/handlers/chainGuards.ts +67 -0
  400. package/src/segments/handlers/directions.ts +44 -0
  401. package/src/segments/handlers/itineraryEcho.ts +45 -0
  402. package/src/segments/handlers/roadAccessDialog.ts +34 -0
  403. package/src/segments/handlers/segment.ts +111 -0
  404. package/src/segments/handlers/segmentEdit.ts +1341 -0
  405. package/src/segments/handlers/segmentGroups.ts +347 -0
  406. package/src/segments/handlers/segmentStructure.ts +1144 -0
  407. package/src/segments/rules/chain.ts +196 -0
  408. package/src/segments/rules/chainModel.ts +217 -0
  409. package/src/segments/rules/colors.ts +11 -0
  410. package/src/segments/rules/commit.ts +76 -0
  411. package/src/segments/rules/draft.ts +90 -0
  412. package/src/segments/rules/draftDisposition.ts +43 -0
  413. package/src/segments/rules/draftSegmentEdit.ts +129 -0
  414. package/src/segments/rules/engine.ts +222 -0
  415. package/src/segments/rules/groupSave.ts +234 -0
  416. package/src/segments/rules/hazardPrompt.ts +60 -0
  417. package/src/segments/rules/itineraryEcho.ts +40 -0
  418. package/src/segments/rules/liveSegmentProjection.ts +55 -0
  419. package/src/segments/rules/merge.ts +51 -0
  420. package/src/segments/rules/metrics.ts +456 -0
  421. package/src/segments/rules/naming.ts +168 -0
  422. package/src/segments/rules/segmentArming.ts +144 -0
  423. package/src/segments/rules/splitPick.ts +84 -0
  424. package/src/segments/rules/viaSimplify.ts +230 -0
  425. package/src/segments/stores/directions.ts +77 -0
  426. package/src/segments/stores/roadAccessDialog.ts +58 -0
  427. package/src/segments/stores/segmentEdit.ts +922 -0
  428. package/src/segments/stores/segmentGroupEdit.ts +84 -0
  429. package/src/segments/stores/segmentSplit.ts +77 -0
  430. package/src/share/contracts/share.ts +39 -0
  431. package/src/share/contracts/shareLink.ts +63 -0
  432. package/src/share/engines/shareLink.ts +1053 -0
  433. package/src/share/handlers/share.ts +47 -0
  434. package/src/share/handlers/shareLink.ts +231 -0
  435. package/src/share/handlers/shareScope.ts +54 -0
  436. package/src/share/rules/link.ts +89 -0
  437. package/src/share/rules/shareLink.ts +218 -0
  438. package/src/share/rules/targets.ts +92 -0
  439. package/src/share/rules/viewConfig.ts +95 -0
  440. package/src/share/stores/share.ts +58 -0
  441. package/src/strings/fr/index.ts +18 -0
  442. package/src/strings/fr/rules/fr.ts +2368 -0
  443. package/src/strings/index.ts +98 -0
  444. package/src/strings/rules/confirmCopy.ts +156 -0
  445. package/src/strings/rules/draftToolNames.ts +94 -0
  446. package/src/strings/rules/en.ts +2519 -0
  447. package/src/strings/rules/failureAlert.ts +115 -0
  448. package/src/strings/rules/formError.ts +400 -0
  449. package/src/strings/rules/maneuvers.ts +107 -0
  450. package/src/strings/rules/outputOptions.ts +126 -0
  451. package/src/strings/rules/publicationState.ts +100 -0
  452. package/src/strings/rules/routeHazardCopy.ts +62 -0
  453. package/src/strings/rules/searchLabels.ts +50 -0
  454. package/src/strings/rules/segmentChainVerbs.ts +62 -0
  455. package/src/strings/rules/studioCopy.ts +130 -0
  456. package/src/strings/rules/unitOptions.ts +119 -0
  457. package/src/testing/checkedBus.ts +226 -0
  458. package/src/testing/index.ts +30 -0
  459. package/src/testing/plugins.ts +106 -0
  460. package/src/testing/studio.ts +267 -0
  461. package/src/testing/urlSeam.ts +153 -0
  462. package/src/time/index.ts +12 -0
  463. package/src/time/rules/sun.ts +78 -0
  464. package/src/video/contracts/cameraSchemas.ts +266 -0
  465. package/src/video/contracts/profileSchemas.ts +37 -0
  466. package/src/video/contracts/video.ts +601 -0
  467. package/src/video/handlers/video.ts +1638 -0
  468. package/src/video/handlers/videoDirector.ts +114 -0
  469. package/src/video/rules/previewRefresh.ts +76 -0
  470. package/src/video/rules/profileSource.ts +51 -0
  471. package/src/video/rules/routeSpans.ts +79 -0
  472. package/src/video/rules/shotDefaults.ts +28 -0
  473. package/src/video/rules/stepOrder.ts +17 -0
  474. package/src/video/rules/videoSnapshot.ts +136 -0
  475. package/src/video/stores/directorThreads.ts +167 -0
  476. package/src/video/stores/videoExport.ts +290 -0
  477. package/src/viewer/contracts/preferences.ts +40 -0
  478. package/src/viewer/handlers/preferences.ts +91 -0
  479. package/src/viewer/rules/capabilities.ts +42 -0
  480. package/src/viewer/rules/config.ts +266 -0
  481. package/src/viewer/rules/context.ts +375 -0
  482. package/src/viewer/rules/ownership.ts +134 -0
  483. package/src/viewer/rules/platformViewer.ts +199 -0
  484. package/src/viewer/rules/scope.ts +197 -0
  485. package/src/viewer/rules/url.ts +145 -0
  486. package/src/viewer/rules/viewer.ts +307 -0
  487. package/src/viewer/rules/viewerSeam.ts +49 -0
  488. package/src/viewer/rules/viewerUnits.ts +34 -0
  489. package/src/waypoints/contracts/itinerary.ts +417 -0
  490. package/src/waypoints/handlers/poiWaypointStyle.ts +32 -0
  491. package/src/waypoints/handlers/waypointDetailsDialog.ts +38 -0
  492. package/src/waypoints/handlers/waypointEdit.ts +1073 -0
  493. package/src/waypoints/rules/amenities.ts +30 -0
  494. package/src/waypoints/rules/defaults.ts +31 -0
  495. package/src/waypoints/rules/details.ts +213 -0
  496. package/src/waypoints/rules/detailsDraft.ts +312 -0
  497. package/src/waypoints/rules/detailsPreview.ts +76 -0
  498. package/src/waypoints/rules/detailsSave.ts +356 -0
  499. package/src/waypoints/rules/draftDirty.ts +45 -0
  500. package/src/waypoints/rules/icons.ts +32 -0
  501. package/src/waypoints/rules/liveWaypoint.ts +63 -0
  502. package/src/waypoints/rules/naming.ts +185 -0
  503. package/src/waypoints/rules/sections.ts +77 -0
  504. package/src/waypoints/rules/waypointDraft.ts +62 -0
  505. package/src/waypoints/stores/waypointDetails.ts +62 -0
  506. package/src/waypoints/stores/waypointEdit.ts +566 -0
  507. package/src/zones/contracts/collection.ts +37 -0
  508. package/src/zones/contracts/zone.ts +528 -0
  509. package/src/zones/engines/zoneForm.ts +1773 -0
  510. package/src/zones/handlers/restZones.ts +287 -0
  511. package/src/zones/handlers/zonePublish.ts +206 -0
  512. package/src/zones/handlers/zoneUnpublish.ts +56 -0
  513. package/src/zones/handlers/zones.ts +2254 -0
  514. package/src/zones/rules/geometry.ts +946 -0
  515. package/src/zones/rules/zoneDefaults.ts +34 -0
  516. package/src/zones/rules/zoneDraft.ts +54 -0
  517. package/src/zones/rules/zoneForm.ts +563 -0
  518. package/src/zones/rules/zoneMetadata.ts +29 -0
  519. package/src/zones/rules/zoneSource.ts +87 -0
  520. package/src/zones/rules/zoneSourceRefusal.ts +104 -0
  521. package/src/zones/stores/zoneEdit.ts +998 -0
@@ -0,0 +1,1402 @@
1
+ "use strict";
2
+ const require_rolldown_runtime = require("./chunk-Bn6ZbxkS.cjs");
3
+ let zod = require("zod");
4
+ zod = require_rolldown_runtime.__toESM(zod);
5
+ let _mountaya_elements_geo = require("@mountaya/elements/geo");
6
+ let _mountaya_elements_data = require("@mountaya/elements/data");
7
+ let _mountaya_elements_units = require("@mountaya/elements/units");
8
+ let _mountaya_elements_errors = require("@mountaya/elements/errors");
9
+ let _mountaya_elements_profile = require("@mountaya/elements/profile");
10
+ const toolNoDataSchema = zod.undefined();
11
+ const appendHistoryStep = (history, step) => {
12
+ const next = [...history, step];
13
+ return next.length > 100 ? next.slice(next.length - 100) : next;
14
+ };
15
+ const restActivitySlugs = {
16
+ "hiking-and-trail": "hiking-and-trail",
17
+ "professional-trail": "professional-trail",
18
+ running: "running",
19
+ "road-cycling": "road-cycling",
20
+ "gravel-bike": "gravel-bike",
21
+ "mountain-bike": "mountain-bike",
22
+ "backcountry-skiing": "backcountry-skiing",
23
+ "ski-touring": "ski-touring",
24
+ "cross-country-skiing": "cross-country-skiing",
25
+ "snowshoe-walking": "snowshoe-walking"
26
+ };
27
+ const restActivitySlugSchema = zod.enum(restActivitySlugs);
28
+ const toDataActivity = (slug) => {
29
+ const parsed = restActivitySlugSchema.safeParse(slug);
30
+ if (!parsed.success) throw new _mountaya_elements_errors.MountayaElementsError(`toDataActivity: ${JSON.stringify(slug)} is not an activity slug of the REST API; pass one of ${restActivitySlugSchema.options.join(", ")}`, { cause: parsed.error });
31
+ return parsed.data.toUpperCase().replaceAll("-", "_");
32
+ };
33
+ const toRestActivity = (value) => value.toLowerCase().replaceAll("_", "-");
34
+ const isRestActivity = (slug) => Object.hasOwn(restActivitySlugs, slug);
35
+ const isDataActivity = (slug) => {
36
+ const rest = slug.toLowerCase().replaceAll("_", "-");
37
+ return isRestActivity(rest) && rest.toUpperCase().replaceAll("-", "_") === slug;
38
+ };
39
+ const resolveActivity = (slug) => {
40
+ if (isRestActivity(slug)) return slug;
41
+ return isDataActivity(slug) ? toRestActivity(slug) : void 0;
42
+ };
43
+ const itinerarySelectionSchema = zod.discriminatedUnion("kind", [zod.object({
44
+ id: zod.string(),
45
+ kind: zod.literal("segment")
46
+ }), zod.object({
47
+ id: zod.string(),
48
+ kind: zod.literal("waypoint")
49
+ })]);
50
+ const mapSegments = (itinerary, transform) => {
51
+ if (!itinerary) return null;
52
+ return {
53
+ ...itinerary,
54
+ segments: transform(itinerary.segments)
55
+ };
56
+ };
57
+ const applyWaypointDetails = (waypoint, details) => {
58
+ const { amenities, ...rest } = details;
59
+ return {
60
+ ...waypoint,
61
+ ...rest,
62
+ ...amenities === void 0 ? {} : { amenities: amenities ?? [] }
63
+ };
64
+ };
65
+ const mapWaypoints = (itinerary, transform) => {
66
+ if (!itinerary) return null;
67
+ return {
68
+ ...itinerary,
69
+ waypoints: transform(itinerary.waypoints)
70
+ };
71
+ };
72
+ const patchSegment = (state, segmentId, patch) => {
73
+ if (!state.activeItinerary?.segments.some((segment) => segment.id === segmentId)) return state;
74
+ return { activeItinerary: mapSegments(state.activeItinerary, (segments) => segments.map((segment) => segment.id === segmentId ? patch(segment) : segment)) };
75
+ };
76
+ const patchWaypoint = (state, waypointId, patch) => {
77
+ if (!state.activeItinerary?.waypoints.some((waypoint) => waypoint.id === waypointId)) return state;
78
+ return { activeItinerary: mapWaypoints(state.activeItinerary, (waypoints) => waypoints.map((waypoint) => waypoint.id === waypointId ? patch(waypoint) : waypoint)) };
79
+ };
80
+ const renumber = (items) => items.map((item, index) => ({
81
+ ...item,
82
+ position: index
83
+ }));
84
+ const itineraryInitialState = {
85
+ activeItinerary: null,
86
+ hoveredEntity: null,
87
+ selection: null
88
+ };
89
+ const createItinerarySlice = (set) => ({
90
+ moveWaypoint: (waypointId, geometry) => set((state) => patchWaypoint(state, waypointId, (waypoint) => ({
91
+ ...waypoint,
92
+ geojson: geometry
93
+ }))),
94
+ recolorSegment: (segmentId, color) => set((state) => patchSegment(state, segmentId, (segment) => ({
95
+ ...segment,
96
+ color
97
+ }))),
98
+ recolorWaypoint: (waypointId, color) => set((state) => patchWaypoint(state, waypointId, (waypoint) => ({
99
+ ...waypoint,
100
+ color
101
+ }))),
102
+ setWaypointDetails: (waypointId, details) => set((state) => patchWaypoint(state, waypointId, (waypoint) => applyWaypointDetails(waypoint, details))),
103
+ renameActiveItinerary: (name) => set((state) => state.activeItinerary ? { activeItinerary: {
104
+ ...state.activeItinerary,
105
+ name
106
+ } } : state),
107
+ renameSegment: (segmentId, name) => set((state) => patchSegment(state, segmentId, (segment) => ({
108
+ ...segment,
109
+ name
110
+ }))),
111
+ renameWaypoint: (waypointId, name) => set((state) => patchWaypoint(state, waypointId, (waypoint) => ({
112
+ ...waypoint,
113
+ name
114
+ }))),
115
+ select: (selection) => set({ selection }),
116
+ setActiveItinerary: (activeItinerary) => set({ activeItinerary }),
117
+ setHoveredEntity: (hoveredEntity) => set((state) => state.hoveredEntity?.id === hoveredEntity?.id && state.hoveredEntity?.kind === hoveredEntity?.kind ? state : { hoveredEntity }),
118
+ setSegmentGeometry: (segmentId, geometry) => set((state) => patchSegment(state, segmentId, (segment) => ({
119
+ ...segment,
120
+ geojson: geometry
121
+ }))),
122
+ setSegmentSpeed: (segmentId, speed, duration) => set((state) => patchSegment(state, segmentId, (segment) => ({
123
+ ...segment,
124
+ duration,
125
+ speed
126
+ }))),
127
+ setWaypointIcon: (waypointId, icon) => set((state) => patchWaypoint(state, waypointId, (waypoint) => ({
128
+ ...waypoint,
129
+ icon
130
+ })))
131
+ });
132
+ const DISPLAY_NAME_MAX_LENGTH = 30;
133
+ const DISPLAY_NAME_MIN_LENGTH = 2;
134
+ const displayNameSchema = zod.string().trim().min(2).max(30);
135
+ const fitDisplayName = (text) => {
136
+ const collapsed = text.replace(/\s+/g, " ").trim();
137
+ const characters = Array.from(collapsed);
138
+ const lead = characters.slice(0, 31).join("");
139
+ const boundary = lead.lastIndexOf(" ");
140
+ const fitted = characters.length <= 30 ? collapsed : boundary > 0 ? lead.slice(0, boundary).trimEnd() : characters.slice(0, 30).join("");
141
+ return displayNameSchema.safeParse(fitted).success ? fitted : "";
142
+ };
143
+ const DESCRIPTION_MAX_LENGTH = 100;
144
+ const descriptionSchema = zod.string().trim().max(100);
145
+ const draftActivityInput = zod.object({ activityId: zod.string().nullable() });
146
+ const draftNameInput = zod.object({ name: zod.string() });
147
+ const draftOrganizationInput = zod.object({ organizationId: zod.string().nullable() });
148
+ const draftPrivateInput = zod.object({ isPrivate: zod.boolean() });
149
+ const draftCollectionsInput = zod.object({ collectionIds: zod.array(zod.string()) });
150
+ const originBase = (origin) => origin.endsWith("/") ? origin.slice(0, -1) : origin;
151
+ const shareLinkTargetSchema = zod.object({
152
+ id: zod.string(),
153
+ kind: zod.enum(["collection", "itinerary"])
154
+ });
155
+ const buildShareSearch = (input) => input.collectionId !== void 0 ? [["collection_id", input.collectionId], ["share_token", input.shareToken]] : [["itinerary_id", input.itineraryId], ["share_token", input.shareToken]];
156
+ const buildShareSrc = (origin, input) => {
157
+ const params = new URLSearchParams(buildShareSearch(input));
158
+ return `${originBase(origin)}/studio/share?${params.toString()}`;
159
+ };
160
+ const switchOverridesSchema = zod.object({
161
+ terrain: zod.string().optional(),
162
+ withAccessRestrictions: zod.boolean().optional(),
163
+ withDirectionsControl: zod.boolean().optional(),
164
+ withDownloadControl: zod.boolean().optional(),
165
+ withNavigationControl: zod.boolean().optional(),
166
+ withOverlays: zod.array(zod.string()).nullable().optional(),
167
+ withOverlaysControl: zod.boolean().optional(),
168
+ withPreferencesControl: zod.boolean().optional(),
169
+ withProfileAnalysis: zod.boolean().optional(),
170
+ withProfileCharacteristics: zod.boolean().optional(),
171
+ withProfileElevation: zod.boolean().optional(),
172
+ withProfilePaceControl: zod.boolean().optional(),
173
+ withStreetviewControl: zod.boolean().optional(),
174
+ withTerrains: zod.array(zod.string()).nullable().optional()
175
+ });
176
+ const embedSetContentInput = switchOverridesSchema.extend({ itineraryId: zod.string().nullable() });
177
+ const SET_ITINERARY_MESSAGE = "mountaya:setItinerary";
178
+ const READY_MESSAGE = "mountaya:ready";
179
+ const REQUEST_CAMERA_MESSAGE = "mountaya:requestCamera";
180
+ const CAMERA_MESSAGE = "mountaya:camera";
181
+ const requestCameraMessageSchema = zod.object({ type: zod.literal(REQUEST_CAMERA_MESSAGE) });
182
+ const cameraMessageSchema = zod.object({
183
+ bearing: zod.number(),
184
+ center: zod.tuple([zod.number(), zod.number()]),
185
+ pitch: zod.number(),
186
+ type: zod.literal(CAMERA_MESSAGE),
187
+ zoom: zod.number()
188
+ });
189
+ const REQUEST_SESSION_TOKEN_MESSAGE = "mountaya:requestSessionToken";
190
+ const SET_SESSION_TOKEN_MESSAGE = "mountaya:setSessionToken";
191
+ const requestSessionTokenMessageSchema = zod.object({ type: zod.literal(REQUEST_SESSION_TOKEN_MESSAGE) });
192
+ const setSessionTokenMessageSchema = zod.object({
193
+ expiresAt: zod.iso.datetime({ offset: true }),
194
+ token: zod.string().regex(/^sess_\S+$/),
195
+ type: zod.literal(SET_SESSION_TOKEN_MESSAGE)
196
+ });
197
+ const inboundBridgeMessageSchema = zod.discriminatedUnion("type", [embedSetContentInput.extend({ type: zod.literal(SET_ITINERARY_MESSAGE) })]);
198
+ const readyErrorSchema = zod.enum(["timeout", "not_found"]).nullable();
199
+ const mapBoundsSchema = zod.tuple([
200
+ zod.number(),
201
+ zod.number(),
202
+ zod.number(),
203
+ zod.number()
204
+ ]).nullable();
205
+ const readyMessageSchema = zod.object({
206
+ bounds: mapBoundsSchema,
207
+ error: readyErrorSchema,
208
+ itineraryId: zod.string().nullable(),
209
+ terrain: zod.string(),
210
+ type: zod.literal(READY_MESSAGE)
211
+ });
212
+ const lineLengthMeters = (line) => {
213
+ let meters = 0;
214
+ for (let index = 1; index < line.length; index += 1) {
215
+ const previous = line[index - 1];
216
+ const current = line[index];
217
+ if (previous && current) meters += (0, _mountaya_elements_profile.haversineMeters)(previous, current);
218
+ }
219
+ return meters;
220
+ };
221
+ const LINESTRING_PROFILE_MAX_SAMPLES = 4e3;
222
+ const profileSampleCap = (lengthMeters) => {
223
+ const needed = Math.floor(lengthMeters / 50) + 2;
224
+ if (!(needed >= 400)) return 400;
225
+ if (needed > 4e3) return LINESTRING_PROFILE_MAX_SAMPLES;
226
+ return needed;
227
+ };
228
+ const MAX_SEGMENT_POSITIONS = 1e4;
229
+ const freehandInsertBudget = (drawnVertices, sampleCap, keepsVias) => {
230
+ const held = keepsVias ? drawnVertices * 2 : drawnVertices;
231
+ return Math.min(sampleCap, MAX_SEGMENT_POSITIONS - held);
232
+ };
233
+ const FREEHAND_FIT_FIRST_TOLERANCE_METERS = 3;
234
+ const FREEHAND_FIT_ROUNDS = 40;
235
+ const keptWithinTolerance = (line, indices, toleranceMeters, metersPerDegree) => {
236
+ if (indices.length < 3) return [...indices];
237
+ const toleranceSquared = toleranceMeters * toleranceMeters;
238
+ const keep = new Uint8Array(indices.length);
239
+ keep[0] = 1;
240
+ keep[indices.length - 1] = 1;
241
+ const stack = [[0, indices.length - 1]];
242
+ while (stack.length > 0) {
243
+ const span = stack.pop();
244
+ if (!span) continue;
245
+ const [from, to] = span;
246
+ const start = line[indices[from] ?? -1];
247
+ const end = line[indices[to] ?? -1];
248
+ if (to - from < 2 || !start || !end) continue;
249
+ const [startLng = 0, startLat = 0] = start;
250
+ const lngMeters = metersPerDegree * Math.cos(startLat * _mountaya_elements_units.DEGREES_TO_RADIANS);
251
+ const endX = (0, _mountaya_elements_geo.longitudeDelta)(startLng, end[0] ?? 0) * lngMeters;
252
+ const endY = ((end[1] ?? 0) - startLat) * metersPerDegree;
253
+ const lengthSquared = endX * endX + endY * endY;
254
+ let farthest = -1;
255
+ let farthestSquared = -1;
256
+ for (let at = from + 1; at < to; at += 1) {
257
+ const point = line[indices[at] ?? -1];
258
+ if (!point) continue;
259
+ const x = (0, _mountaya_elements_geo.longitudeDelta)(startLng, point[0] ?? 0) * lngMeters;
260
+ const y = ((point[1] ?? 0) - startLat) * metersPerDegree;
261
+ const along = lengthSquared === 0 ? 0 : Math.min(1, Math.max(0, (x * endX + y * endY) / lengthSquared));
262
+ const offX = x - along * endX;
263
+ const offY = y - along * endY;
264
+ const squared = offX * offX + offY * offY;
265
+ if (squared > farthestSquared) {
266
+ farthest = at;
267
+ farthestSquared = squared;
268
+ }
269
+ }
270
+ if (farthest !== -1 && farthestSquared > toleranceSquared) {
271
+ keep[farthest] = 1;
272
+ stack.push([from, farthest], [farthest, to]);
273
+ }
274
+ }
275
+ return indices.filter((_index, at) => keep[at] === 1);
276
+ };
277
+ const fitFreehandLines = (lines) => {
278
+ const positions = (sets) => sets.reduce((sum, set) => sum + set.length, 0);
279
+ if (positions(lines) <= 1e4) return null;
280
+ const metersPerDegree = _mountaya_elements_geo.EARTH_RADIUS_METERS * _mountaya_elements_units.DEGREES_TO_RADIANS;
281
+ let tolerance = FREEHAND_FIT_FIRST_TOLERANCE_METERS;
282
+ let kept = lines.map((line) => keptWithinTolerance(line, line.map((_position, index) => index), tolerance, metersPerDegree));
283
+ for (let round = 0; round < FREEHAND_FIT_ROUNDS && positions(kept) > 1e4; round += 1) {
284
+ tolerance *= 2;
285
+ kept = kept.map((indices, at) => keptWithinTolerance(lines[at] ?? [], indices, tolerance, metersPerDegree));
286
+ }
287
+ return kept;
288
+ };
289
+ const storedMeters = (meters) => Math.round(meters * 100) / 100;
290
+ const interpolateGreatCircle = (start, end, fraction) => {
291
+ const latStart = (start[1] ?? 0) * _mountaya_elements_units.DEGREES_TO_RADIANS;
292
+ const lngStart = (start[0] ?? 0) * _mountaya_elements_units.DEGREES_TO_RADIANS;
293
+ const latEnd = (end[1] ?? 0) * _mountaya_elements_units.DEGREES_TO_RADIANS;
294
+ const lngEnd = (end[0] ?? 0) * _mountaya_elements_units.DEGREES_TO_RADIANS;
295
+ const delta = 2 * Math.asin(Math.min(1, Math.sqrt(Math.sin((latEnd - latStart) / 2) ** 2 + Math.cos(latStart) * Math.cos(latEnd) * Math.sin((lngEnd - lngStart) / 2) ** 2)));
296
+ if (delta === 0) return [start[0] ?? 0, start[1] ?? 0];
297
+ const a = Math.sin((1 - fraction) * delta) / Math.sin(delta);
298
+ const b = Math.sin(fraction * delta) / Math.sin(delta);
299
+ const x = a * Math.cos(latStart) * Math.cos(lngStart) + b * Math.cos(latEnd) * Math.cos(lngEnd);
300
+ const y = a * Math.cos(latStart) * Math.sin(lngStart) + b * Math.cos(latEnd) * Math.sin(lngEnd);
301
+ const z = a * Math.sin(latStart) + b * Math.sin(latEnd);
302
+ return [Math.atan2(y, x) * _mountaya_elements_units.RADIANS_TO_DEGREES, Math.atan2(z, Math.hypot(x, y)) * _mountaya_elements_units.RADIANS_TO_DEGREES];
303
+ };
304
+ const vertexWithinRange = (vertex) => [(0, _mountaya_elements_geo.wrapLongitudePastRange)(vertex[0] ?? 0), vertex[1] ?? 0];
305
+ const densifyLine = (line, intervalMeters, maxSamples) => {
306
+ if (line.length < 2) return line.map(vertexWithinRange);
307
+ const totalMeters = lineLengthMeters(line);
308
+ const interval = totalMeters > 0 ? Math.max(intervalMeters, totalMeters / maxSamples) : intervalMeters;
309
+ const head = line[0];
310
+ const densified = head ? [vertexWithinRange(head)] : [];
311
+ for (let index = 1; index < line.length; index += 1) {
312
+ const start = line[index - 1];
313
+ const end = line[index];
314
+ if (!start || !end) continue;
315
+ const edgeMeters = (0, _mountaya_elements_profile.haversineMeters)(start, end);
316
+ const steps = interval > 0 ? Math.max(1, Math.ceil(edgeMeters / interval)) : 1;
317
+ for (let step = 1; step < steps; step += 1) densified.push(interpolateGreatCircle(start, end, step / steps));
318
+ densified.push(vertexWithinRange(end));
319
+ }
320
+ return densified;
321
+ };
322
+ const densifyFreehandLine = (line) => {
323
+ const meters = lineLengthMeters(line);
324
+ const keepsVias = line.length < profileSampleCap(storedMeters(meters));
325
+ const budget = freehandInsertBudget(line.length, profileSampleCap(meters), keepsVias);
326
+ if (budget <= 0) return line.map(vertexWithinRange);
327
+ return densifyLine(line, 50, budget);
328
+ };
329
+ const surfaceTypeSchema = zod.enum({
330
+ unknown: "unknown",
331
+ paved: "paved",
332
+ unpaved: "unpaved",
333
+ asphalt: "asphalt",
334
+ concrete: "concrete",
335
+ cobblestone: "cobblestone",
336
+ metal: "metal",
337
+ wood: "wood",
338
+ "compacted-gravel": "compacted-gravel",
339
+ "fine-gravel": "fine-gravel",
340
+ gravel: "gravel",
341
+ dirt: "dirt",
342
+ ground: "ground",
343
+ ice: "ice",
344
+ "paving-stones": "paving-stones",
345
+ sand: "sand",
346
+ woodchips: "woodchips",
347
+ grass: "grass",
348
+ "grass-paver": "grass-paver"
349
+ });
350
+ const wayTypeSchema = zod.enum({
351
+ unknown: "unknown",
352
+ "state-road": "state-road",
353
+ road: "road",
354
+ street: "street",
355
+ path: "path",
356
+ track: "track",
357
+ cycleway: "cycleway",
358
+ footway: "footway",
359
+ steps: "steps",
360
+ ferry: "ferry",
361
+ construction: "construction"
362
+ });
363
+ const trailDifficultyTypeSchema = zod.enum({
364
+ unknown: "unknown",
365
+ hiking: "hiking",
366
+ "mountain-hiking": "mountain-hiking",
367
+ "demanding-mountain-hiking": "demanding-mountain-hiking",
368
+ "alpine-hiking": "alpine-hiking",
369
+ "demanding-alpine-hiking": "demanding-alpine-hiking",
370
+ "difficult-alpine-hiking": "difficult-alpine-hiking",
371
+ "mtb-0": "mtb-0",
372
+ "mtb-1": "mtb-1",
373
+ "mtb-2": "mtb-2",
374
+ "mtb-3": "mtb-3",
375
+ "mtb-4": "mtb-4",
376
+ "mtb-5": "mtb-5",
377
+ "mtb-6": "mtb-6"
378
+ });
379
+ const indexedInfoSchema = (value) => zod.object({
380
+ from_index: zod.number().int(),
381
+ to_index: zod.number().int(),
382
+ value
383
+ });
384
+ const liveSegmentRouteAnalysisSchema = zod.object({
385
+ slopeInfo: zod.array(indexedInfoSchema(zod.number())),
386
+ speedInfo: zod.array(indexedInfoSchema(zod.number())),
387
+ surfaceInfo: zod.array(indexedInfoSchema(surfaceTypeSchema)),
388
+ trailDifficultyInfo: zod.array(indexedInfoSchema(trailDifficultyTypeSchema)),
389
+ wayTypeInfo: zod.array(indexedInfoSchema(wayTypeSchema))
390
+ });
391
+ const liveSegmentRouteElevationSchema = zod.object({
392
+ altitudeMax: zod.number(),
393
+ altitudeMin: zod.number(),
394
+ ascent: zod.number(),
395
+ descent: zod.number(),
396
+ gradientMax: zod.number(),
397
+ gradientMin: zod.number()
398
+ });
399
+ zod.enum({
400
+ ASPHALT: "ASPHALT",
401
+ COBBLESTONE: "COBBLESTONE",
402
+ COMPACTED_GRAVEL: "COMPACTED_GRAVEL",
403
+ CONCRETE: "CONCRETE",
404
+ DIRT: "DIRT",
405
+ FINE_GRAVEL: "FINE_GRAVEL",
406
+ GRASS: "GRASS",
407
+ GRASS_PAVER: "GRASS_PAVER",
408
+ GRAVEL: "GRAVEL",
409
+ GROUND: "GROUND",
410
+ ICE: "ICE",
411
+ METAL: "METAL",
412
+ PAVED: "PAVED",
413
+ PAVING_STONES: "PAVING_STONES",
414
+ SAND: "SAND",
415
+ UNKNOWN: "UNKNOWN",
416
+ UNPAVED: "UNPAVED",
417
+ WOOD: "WOOD",
418
+ WOODCHIPS: "WOODCHIPS"
419
+ });
420
+ zod.enum({
421
+ CONSTRUCTION: "CONSTRUCTION",
422
+ CYCLEWAY: "CYCLEWAY",
423
+ FERRY: "FERRY",
424
+ FOOTWAY: "FOOTWAY",
425
+ PATH: "PATH",
426
+ ROAD: "ROAD",
427
+ STATE_ROAD: "STATE_ROAD",
428
+ STEPS: "STEPS",
429
+ STREET: "STREET",
430
+ TRACK: "TRACK",
431
+ UNKNOWN: "UNKNOWN"
432
+ });
433
+ zod.enum({
434
+ ALPINE_HIKING: "ALPINE_HIKING",
435
+ DEMANDING_ALPINE_HIKING: "DEMANDING_ALPINE_HIKING",
436
+ DEMANDING_MOUNTAIN_HIKING: "DEMANDING_MOUNTAIN_HIKING",
437
+ DIFFICULT_ALPINE_HIKING: "DIFFICULT_ALPINE_HIKING",
438
+ HIKING: "HIKING",
439
+ MOUNTAIN_HIKING: "MOUNTAIN_HIKING",
440
+ MTB_0: "MTB_0",
441
+ MTB_1: "MTB_1",
442
+ MTB_2: "MTB_2",
443
+ MTB_3: "MTB_3",
444
+ MTB_4: "MTB_4",
445
+ MTB_5: "MTB_5",
446
+ MTB_6: "MTB_6",
447
+ UNKNOWN: "UNKNOWN"
448
+ });
449
+ const dataToRestSurface = {
450
+ ASPHALT: "asphalt",
451
+ COBBLESTONE: "cobblestone",
452
+ COMPACTED_GRAVEL: "compacted-gravel",
453
+ CONCRETE: "concrete",
454
+ DIRT: "dirt",
455
+ FINE_GRAVEL: "fine-gravel",
456
+ GRASS: "grass",
457
+ GRASS_PAVER: "grass-paver",
458
+ GRAVEL: "gravel",
459
+ GROUND: "ground",
460
+ ICE: "ice",
461
+ METAL: "metal",
462
+ PAVED: "paved",
463
+ PAVING_STONES: "paving-stones",
464
+ SAND: "sand",
465
+ UNKNOWN: "unknown",
466
+ UNPAVED: "unpaved",
467
+ WOOD: "wood",
468
+ WOODCHIPS: "woodchips"
469
+ };
470
+ const dataToRestWaytype = {
471
+ CONSTRUCTION: "construction",
472
+ CYCLEWAY: "cycleway",
473
+ FERRY: "ferry",
474
+ FOOTWAY: "footway",
475
+ PATH: "path",
476
+ ROAD: "road",
477
+ STATE_ROAD: "state-road",
478
+ STEPS: "steps",
479
+ STREET: "street",
480
+ TRACK: "track",
481
+ UNKNOWN: "unknown"
482
+ };
483
+ const dataToRestTrailDifficulty = {
484
+ ALPINE_HIKING: "alpine-hiking",
485
+ DEMANDING_ALPINE_HIKING: "demanding-alpine-hiking",
486
+ DEMANDING_MOUNTAIN_HIKING: "demanding-mountain-hiking",
487
+ DIFFICULT_ALPINE_HIKING: "difficult-alpine-hiking",
488
+ HIKING: "hiking",
489
+ MOUNTAIN_HIKING: "mountain-hiking",
490
+ MTB_0: "mtb-0",
491
+ MTB_1: "mtb-1",
492
+ MTB_2: "mtb-2",
493
+ MTB_3: "mtb-3",
494
+ MTB_4: "mtb-4",
495
+ MTB_5: "mtb-5",
496
+ MTB_6: "mtb-6",
497
+ UNKNOWN: "unknown"
498
+ };
499
+ const toRestSurface = (value) => dataToRestSurface[value];
500
+ const toRestWayType = (value) => dataToRestWaytype[value];
501
+ const toRestTrailDifficulty = (value) => dataToRestTrailDifficulty[value];
502
+ const dataToRestRoadAccess = {
503
+ AGRICULTURAL: "agricultural",
504
+ CUSTOMERS: "customers",
505
+ DELIVERY: "delivery",
506
+ DESTINATION: "destination",
507
+ FORESTRY: "forestry",
508
+ NO: "no",
509
+ PERMISSIVE: "permissive",
510
+ PERMIT: "permit",
511
+ PRIVATE: "private",
512
+ RESTRICTED: "restricted",
513
+ SERVICE: "service",
514
+ UNKNOWN: "unknown"
515
+ };
516
+ const graphqlRoadAccessToInfo = (advisories) => advisories.roadAccessInfo.map((info) => ({
517
+ from_index: info.fromIndex,
518
+ to_index: info.toIndex,
519
+ values: info.values.map((value) => dataToRestRoadAccess[value])
520
+ }));
521
+ const toAnalysisEntries = (entries, convert) => entries.map((entry) => ({
522
+ from_index: entry.fromIndex,
523
+ to_index: entry.toIndex,
524
+ value: convert(entry.value)
525
+ }));
526
+ const graphqlElevationToSummary = (elevation) => ({
527
+ altitudeMax: elevation.altitude.max,
528
+ altitudeMin: elevation.altitude.min,
529
+ ascent: elevation.ascent,
530
+ descent: elevation.descent,
531
+ gradientMax: elevation.gradient.max,
532
+ gradientMin: elevation.gradient.min
533
+ });
534
+ const graphqlAnalysisToEntries = (analysis) => ({
535
+ slopeInfo: toAnalysisEntries(analysis.slopeInfo, (value) => value),
536
+ speedInfo: toAnalysisEntries(analysis.speedInfo, (value) => value),
537
+ surfaceInfo: toAnalysisEntries(analysis.surfaceInfo, toRestSurface),
538
+ trailDifficultyInfo: toAnalysisEntries(analysis.trailDifficultyInfo, toRestTrailDifficulty),
539
+ wayTypeInfo: toAnalysisEntries(analysis.wayTypeInfo, toRestWayType)
540
+ });
541
+ const routeLineOf = (geometry) => {
542
+ const lines = (0, _mountaya_elements_geo.extractLines)(geometry);
543
+ const [only] = lines;
544
+ if (lines.length === 1 && only !== void 0) return only;
545
+ return {
546
+ coordinates: (0, _mountaya_elements_geo.segmentLineCoordinates)(geometry),
547
+ type: "LineString"
548
+ };
549
+ };
550
+ const graphqlRouteToLiveRoute = (itinerary) => ({
551
+ analysis: itinerary.analysis ? graphqlAnalysisToEntries(itinerary.analysis) : void 0,
552
+ distance: itinerary.distance,
553
+ duration: itinerary.duration,
554
+ elevation: itinerary.elevation ? graphqlElevationToSummary(itinerary.elevation) : void 0,
555
+ geometry: itinerary.geometry,
556
+ roadAccessInfo: itinerary.analysis ? graphqlRoadAccessToInfo(itinerary.analysis.advisories) : void 0
557
+ });
558
+ const overlayRouteAnalysis = (base, itinerary) => ({
559
+ ...base,
560
+ altitude_max: itinerary.elevation?.altitudeMax ?? base.altitude_max,
561
+ altitude_min: itinerary.elevation?.altitudeMin ?? base.altitude_min,
562
+ ascent: itinerary.elevation?.ascent ?? base.ascent,
563
+ descent: itinerary.elevation?.descent ?? base.descent,
564
+ gradient_max: itinerary.elevation?.gradientMax ?? base.gradient_max,
565
+ gradient_min: itinerary.elevation?.gradientMin ?? base.gradient_min,
566
+ road_access_info: itinerary.roadAccessInfo ? [...itinerary.roadAccessInfo] : null,
567
+ slope_info: itinerary.analysis?.slopeInfo ?? base.slope_info,
568
+ speed_info: itinerary.analysis?.speedInfo ?? base.speed_info,
569
+ surface_info: itinerary.analysis?.surfaceInfo ?? base.surface_info,
570
+ trail_difficulty_info: itinerary.analysis?.trailDifficultyInfo ?? base.trail_difficulty_info,
571
+ way_type_info: itinerary.analysis?.wayTypeInfo ?? base.way_type_info
572
+ });
573
+ const buildLiveSegment = (base, itinerary) => {
574
+ const geojson = {
575
+ geometries: [itinerary.geometry],
576
+ type: "GeometryCollection"
577
+ };
578
+ return {
579
+ ...overlayRouteAnalysis(base, itinerary),
580
+ distance: itinerary.distance,
581
+ duration: itinerary.duration,
582
+ geojson
583
+ };
584
+ };
585
+ const substituteLiveSegment = (segments, live, insertAnchor) => {
586
+ if (!live) return segments;
587
+ if (segments.some((segment) => segment.id === live.id)) return segments.map((segment) => segment.id === live.id ? live : segment);
588
+ if (insertAnchor === void 0) return [...segments, live];
589
+ const anchorIndex = insertAnchor === null ? -1 : segments.findIndex((s) => s.id === insertAnchor);
590
+ if (insertAnchor !== null && anchorIndex === -1) return [...segments, live];
591
+ return [
592
+ ...segments.slice(0, anchorIndex + 1),
593
+ live,
594
+ ...segments.slice(anchorIndex + 1)
595
+ ];
596
+ };
597
+ const draftPositionCount = (geometry) => {
598
+ const leaf = geometry.type === "GeometryCollection" ? geometry.geometries[0] : geometry;
599
+ if (leaf && (leaf.type === "MultiPoint" || leaf.type === "LineString")) return leaf.coordinates.length;
600
+ return 0;
601
+ };
602
+ const draftCoordinates = (draft) => {
603
+ if (!draft) return [];
604
+ const leaves = draft.type === "GeometryCollection" ? draft.geometries : [draft];
605
+ for (const leaf of leaves) if (leaf.type === "MultiPoint" || leaf.type === "LineString") return leaf.coordinates;
606
+ return [];
607
+ };
608
+ const segmentDraftHandles = (draft, seedVias) => draft === null ? seedVias : draftCoordinates(draft);
609
+ const sameHandles = (a, b) => a.length === b.length && a.every((handle, index) => {
610
+ const other = b[index];
611
+ return other !== void 0 && handle[0] === other[0] && handle[1] === other[1];
612
+ });
613
+ const isSegmentDraftDirty = (session) => session !== null && !sameHandles(segmentDraftHandles(session.draft, session.seedVias), session.savedVias);
614
+ const segmentEditModeSchema = zod.enum(_mountaya_elements_data.SEGMENT_EDIT_MODES);
615
+ const synthesizeDraftSegment = (params) => ({
616
+ altitude_max: null,
617
+ altitude_min: null,
618
+ ascent: null,
619
+ color: params.draftColor,
620
+ created_at: /* @__PURE__ */ new Date(0),
621
+ created_by: { id: "" },
622
+ descent: null,
623
+ description: null,
624
+ distance: null,
625
+ duration: null,
626
+ geojson: null,
627
+ gradient_max: null,
628
+ gradient_min: null,
629
+ group_id: null,
630
+ id: params.segmentId,
631
+ itinerary_id: params.itineraryId,
632
+ mode: params.mode,
633
+ name: params.draftName ?? "",
634
+ position: 0,
635
+ revision: 0,
636
+ road_access_info: null,
637
+ slope_info: [],
638
+ speed: null,
639
+ speed_info: [],
640
+ start_at: null,
641
+ steps: [],
642
+ surface_info: [],
643
+ trail_difficulty_info: [],
644
+ way_type_info: []
645
+ });
646
+ const segmentInsertAnchorSchema = zod.object({ afterSegmentId: zod.string().nullable() });
647
+ const segmentEditSessionMark = (session) => session.seedVias;
648
+ const seedViasEqual = (a, b) => {
649
+ if (a.length !== b.length) return false;
650
+ return a.every((via, index) => {
651
+ const other = b[index];
652
+ return other !== void 0 && via[0] === other[0] && via[1] === other[1];
653
+ });
654
+ };
655
+ const pinnedPointsEqual = (a, b) => a === null || b === null ? a === null && b === null : a[0] === b[0] && a[1] === b[1];
656
+ const segmentEditInitialState = {
657
+ editDirtyTick: 0,
658
+ segmentEditSession: null,
659
+ segmentViaPrompt: null
660
+ };
661
+ const createSegmentEditSlice = (set) => ({
662
+ acknowledgeRouteHazards: (keys) => set((state) => {
663
+ const session = state.segmentEditSession;
664
+ if (!session) return {};
665
+ const held = new Set(session.acknowledgedRouteHazards);
666
+ const added = [...new Set(keys)].filter((key) => !held.has(key));
667
+ if (added.length === 0) return {};
668
+ return { segmentEditSession: {
669
+ ...session,
670
+ acknowledgedRouteHazards: [...session.acknowledgedRouteHazards, ...added]
671
+ } };
672
+ }),
673
+ adoptCreatedSegment: (saved) => set((state) => {
674
+ const session = state.segmentEditSession;
675
+ if (!session) return {};
676
+ const rekeyed = (segment) => segment ? {
677
+ ...segment,
678
+ id: saved.id
679
+ } : null;
680
+ const rekeyedStep = (step) => ({
681
+ draft: step.draft,
682
+ liveSegment: rekeyed(step.liveSegment)
683
+ });
684
+ const itinerary = state.activeItinerary;
685
+ return {
686
+ activeItinerary: itinerary !== null && itinerary.id === saved.itinerary_id && !itinerary.segments.some((segment) => segment.id === saved.id) ? {
687
+ ...itinerary,
688
+ segments: substituteLiveSegment(itinerary.segments, saved, session.insertAnchor === null ? void 0 : session.insertAnchor.afterSegmentId)
689
+ } : itinerary,
690
+ editDirtyTick: state.editDirtyTick + 1,
691
+ segmentEditSession: {
692
+ ...session,
693
+ draftName: null,
694
+ future: session.future.map(rekeyedStep),
695
+ gestureStart: session.gestureStart && rekeyedStep(session.gestureStart),
696
+ insertAnchor: null,
697
+ liveSegment: rekeyed(session.liveSegment),
698
+ past: session.past.map(rekeyedStep),
699
+ segmentId: saved.id
700
+ }
701
+ };
702
+ }),
703
+ beginSegmentEdit: (begin) => set((state) => {
704
+ const active = state.segmentEditSession;
705
+ if (active?.segmentId === begin.segmentId && active?.mode === begin.mode && seedViasEqual(active.seedVias, begin.seedVias ?? []) && pinnedPointsEqual(active.pinnedStart, begin.pinnedStart ?? null) && pinnedPointsEqual(active.pinnedEnd, begin.pinnedEnd ?? null)) return {};
706
+ const liveSegment = state.activeItinerary?.segments?.find((segment) => segment.id === begin.segmentId) ? null : synthesizeDraftSegment({
707
+ draftColor: begin.draftColor ?? null,
708
+ draftName: begin.draftName ?? null,
709
+ itineraryId: state.activeItinerary?.id ?? "",
710
+ mode: begin.mode,
711
+ segmentId: begin.segmentId
712
+ });
713
+ return {
714
+ editDirtyTick: state.editDirtyTick + 1,
715
+ segmentEditSession: {
716
+ acknowledgedRouteHazards: [],
717
+ activitySlug: begin.activitySlug ?? null,
718
+ draft: null,
719
+ draftColor: begin.draftColor ?? null,
720
+ draftName: begin.draftName ?? null,
721
+ future: [],
722
+ gestureStart: null,
723
+ insertAnchor: begin.insertAnchor ?? null,
724
+ liveSegment,
725
+ mode: begin.mode,
726
+ past: [],
727
+ pinnedEnd: begin.pinnedEnd ?? null,
728
+ pinnedStart: begin.pinnedStart ?? null,
729
+ savedVias: [...begin.savedVias ?? begin.seedVias ?? []],
730
+ seedVias: [...begin.seedVias ?? []],
731
+ segmentId: begin.segmentId
732
+ },
733
+ segmentViaPrompt: null,
734
+ selection: null
735
+ };
736
+ }),
737
+ bumpEditDirtyTick: () => set((state) => ({ editDirtyTick: state.editDirtyTick + 1 })),
738
+ cancelSegmentEdit: () => set((state) => ({
739
+ editDirtyTick: state.editDirtyTick + 1,
740
+ segmentEditSession: null,
741
+ segmentViaPrompt: null
742
+ })),
743
+ commitSegmentEdit: () => set((state) => ({
744
+ editDirtyTick: state.editDirtyTick + 1,
745
+ segmentEditSession: null,
746
+ segmentViaPrompt: null
747
+ })),
748
+ markSegmentDraftSaved: (draft) => set((state) => {
749
+ const session = state.segmentEditSession;
750
+ if (!session) return {};
751
+ const saved = segmentDraftHandles(draft, session.seedVias).map(([lng = 0, lat = 0]) => [lng, lat]);
752
+ return { segmentEditSession: {
753
+ ...session,
754
+ savedVias: saved
755
+ } };
756
+ }),
757
+ pushSegmentDraft: (geometry) => set((state) => {
758
+ if (!state.segmentEditSession) return {};
759
+ const { draft, gestureStart, liveSegment, past } = state.segmentEditSession;
760
+ return {
761
+ editDirtyTick: state.editDirtyTick + 1,
762
+ segmentEditSession: {
763
+ ...state.segmentEditSession,
764
+ draft: geometry,
765
+ future: [],
766
+ gestureStart: null,
767
+ past: appendHistoryStep(past, gestureStart ?? {
768
+ draft,
769
+ liveSegment
770
+ })
771
+ }
772
+ };
773
+ }),
774
+ recolorSegmentEditLive: (color) => set((state) => {
775
+ const session = state.segmentEditSession;
776
+ if (!session) return {};
777
+ const recolor = (segment) => segment ? {
778
+ ...segment,
779
+ color
780
+ } : null;
781
+ return {
782
+ editDirtyTick: state.editDirtyTick + 1,
783
+ segmentEditSession: {
784
+ ...session,
785
+ draftColor: color,
786
+ future: session.future.map((snapshot) => ({
787
+ ...snapshot,
788
+ liveSegment: recolor(snapshot.liveSegment)
789
+ })),
790
+ gestureStart: session.gestureStart && {
791
+ ...session.gestureStart,
792
+ liveSegment: recolor(session.gestureStart.liveSegment)
793
+ },
794
+ liveSegment: recolor(session.liveSegment),
795
+ past: session.past.map((snapshot) => ({
796
+ ...snapshot,
797
+ liveSegment: recolor(snapshot.liveSegment)
798
+ }))
799
+ }
800
+ };
801
+ }),
802
+ redoSegmentDraft: () => set((state) => {
803
+ const session = state.segmentEditSession;
804
+ if (!session) return {};
805
+ if (session.future.length === 0) return {};
806
+ const { draft, future, liveSegment, past } = session;
807
+ const [next, ...remaining] = future;
808
+ if (next === void 0) return {};
809
+ return {
810
+ editDirtyTick: state.editDirtyTick + 1,
811
+ segmentEditSession: {
812
+ ...session,
813
+ draft: next.draft,
814
+ future: remaining,
815
+ gestureStart: null,
816
+ liveSegment: next.liveSegment,
817
+ past: appendHistoryStep(past, {
818
+ draft,
819
+ liveSegment
820
+ })
821
+ }
822
+ };
823
+ }),
824
+ removeSegment: (segmentId) => set((state) => {
825
+ const activeItinerary = mapSegments(state.activeItinerary, (segments) => segments.filter((segment) => segment.id !== segmentId));
826
+ if (state.segmentEditSession?.segmentId !== segmentId) return { activeItinerary };
827
+ return {
828
+ activeItinerary,
829
+ editDirtyTick: state.editDirtyTick + 1,
830
+ segmentEditSession: null,
831
+ segmentViaPrompt: null
832
+ };
833
+ }),
834
+ setSegmentEditDraft: (geometry) => set((state) => state.segmentEditSession ? { segmentEditSession: {
835
+ ...state.segmentEditSession,
836
+ draft: geometry
837
+ } } : {}),
838
+ setSegmentEditLiveDraft: (geometry) => set((state) => {
839
+ const session = state.segmentEditSession;
840
+ if (!session) return {};
841
+ return { segmentEditSession: {
842
+ ...session,
843
+ draft: geometry,
844
+ gestureStart: session.gestureStart ?? {
845
+ draft: session.draft,
846
+ liveSegment: session.liveSegment
847
+ }
848
+ } };
849
+ }),
850
+ setSegmentEditLiveSegment: (segment, routedFor) => set((state) => {
851
+ const session = state.segmentEditSession;
852
+ if (!session) return {};
853
+ if (routedFor === void 0 || segment === null) return {
854
+ editDirtyTick: state.editDirtyTick + 1,
855
+ segmentEditSession: {
856
+ ...session,
857
+ liveSegment: segment
858
+ }
859
+ };
860
+ const pair = (step) => sameHandles(segmentDraftHandles(step.draft, session.seedVias), routedFor) ? {
861
+ ...step,
862
+ liveSegment: segment
863
+ } : step;
864
+ return {
865
+ editDirtyTick: state.editDirtyTick + 1,
866
+ segmentEditSession: {
867
+ ...session,
868
+ future: session.future.map(pair),
869
+ gestureStart: session.gestureStart && pair(session.gestureStart),
870
+ liveSegment: segment,
871
+ past: session.past.map(pair)
872
+ }
873
+ };
874
+ }),
875
+ setSegmentViaPrompt: (segmentViaPrompt) => set((state) => segmentViaPrompt !== null && !state.segmentEditSession ? {} : { segmentViaPrompt }),
876
+ undoSegmentDraft: () => set((state) => {
877
+ const session = state.segmentEditSession;
878
+ if (!session) return {};
879
+ if (session.past.length === 0) return {};
880
+ const { draft, future, liveSegment, past } = session;
881
+ const previous = past[past.length - 1];
882
+ if (previous === void 0) return {};
883
+ return {
884
+ editDirtyTick: state.editDirtyTick + 1,
885
+ segmentEditSession: {
886
+ ...session,
887
+ draft: previous.draft,
888
+ future: [{
889
+ draft,
890
+ liveSegment
891
+ }, ...future],
892
+ gestureStart: null,
893
+ liveSegment: previous.liveSegment,
894
+ past: past.slice(0, -1)
895
+ }
896
+ };
897
+ })
898
+ });
899
+ const issuedShareTokenSchema = zod.strictObject({ shareToken: zod.string().min(1) });
900
+ const shareLinkToolContracts = {
901
+ "studio.shareLink.disable": {
902
+ capability: "editor",
903
+ description: "Disable the share link for an itinerary or a collection. The token is revoked and every URL carrying it stops working; a later mint issues a different link.",
904
+ input: shareLinkTargetSchema,
905
+ output: toolNoDataSchema
906
+ },
907
+ "studio.shareLink.mint": {
908
+ capability: "editor",
909
+ description: "Get or create the read-only share link for an itinerary or a collection and return its token. Idempotent: an existing link is returned unchanged rather than replaced.",
910
+ input: shareLinkTargetSchema,
911
+ output: issuedShareTokenSchema
912
+ },
913
+ "studio.shareLink.rotate": {
914
+ capability: "editor",
915
+ description: "Reset the share link for an itinerary or a collection, retiring the current token and returning a fresh one. Every URL already handed out stops working.",
916
+ input: shareLinkTargetSchema,
917
+ output: issuedShareTokenSchema
918
+ }
919
+ };
920
+ const zoneNameSchema = displayNameSchema;
921
+ const zoneDescriptionSchema = descriptionSchema;
922
+ const defaultStudioScope = { isPersonalScope: (organizationId) => organizationId === null || organizationId === void 0 };
923
+ const writeResourceNames = {
924
+ collection: "a collection",
925
+ itinerary: "an itinerary",
926
+ zone: "a zone"
927
+ };
928
+ const requireWritableScope = (ctx, resource, organizationId) => {
929
+ const refusal = ctx.scope?.writeRefusal?.(resource, organizationId) ?? null;
930
+ const name = writeResourceNames[resource];
931
+ switch (refusal) {
932
+ case "personal": return {
933
+ code: "forbidden",
934
+ error: `the personal space holds no ${resource}: write ${name} in an organization whose agreement includes Map Studio`,
935
+ ok: false
936
+ };
937
+ case "agreement": return {
938
+ code: "upgrade-required",
939
+ error: `not part of the organization's agreement: writing ${name} needs an organization whose agreement includes Map Studio`,
940
+ ok: false
941
+ };
942
+ default: return null;
943
+ }
944
+ };
945
+ const activeStudioScope = (ctx) => {
946
+ const named = ctx.url?.read().organization_id;
947
+ const { isPersonalScope } = ctx.scope ?? defaultStudioScope;
948
+ return named === void 0 || named === "" || isPersonalScope(named) ? null : named;
949
+ };
950
+ const isPublishableScope = (organizationId, isPersonalScope) => Boolean(organizationId) && !isPersonalScope(organizationId);
951
+ Object.defineProperty(exports, "CAMERA_MESSAGE", {
952
+ enumerable: true,
953
+ get: function() {
954
+ return CAMERA_MESSAGE;
955
+ }
956
+ });
957
+ Object.defineProperty(exports, "DESCRIPTION_MAX_LENGTH", {
958
+ enumerable: true,
959
+ get: function() {
960
+ return DESCRIPTION_MAX_LENGTH;
961
+ }
962
+ });
963
+ Object.defineProperty(exports, "DISPLAY_NAME_MAX_LENGTH", {
964
+ enumerable: true,
965
+ get: function() {
966
+ return DISPLAY_NAME_MAX_LENGTH;
967
+ }
968
+ });
969
+ Object.defineProperty(exports, "DISPLAY_NAME_MIN_LENGTH", {
970
+ enumerable: true,
971
+ get: function() {
972
+ return DISPLAY_NAME_MIN_LENGTH;
973
+ }
974
+ });
975
+ Object.defineProperty(exports, "READY_MESSAGE", {
976
+ enumerable: true,
977
+ get: function() {
978
+ return READY_MESSAGE;
979
+ }
980
+ });
981
+ Object.defineProperty(exports, "REQUEST_CAMERA_MESSAGE", {
982
+ enumerable: true,
983
+ get: function() {
984
+ return REQUEST_CAMERA_MESSAGE;
985
+ }
986
+ });
987
+ Object.defineProperty(exports, "REQUEST_SESSION_TOKEN_MESSAGE", {
988
+ enumerable: true,
989
+ get: function() {
990
+ return REQUEST_SESSION_TOKEN_MESSAGE;
991
+ }
992
+ });
993
+ Object.defineProperty(exports, "SET_ITINERARY_MESSAGE", {
994
+ enumerable: true,
995
+ get: function() {
996
+ return SET_ITINERARY_MESSAGE;
997
+ }
998
+ });
999
+ Object.defineProperty(exports, "SET_SESSION_TOKEN_MESSAGE", {
1000
+ enumerable: true,
1001
+ get: function() {
1002
+ return SET_SESSION_TOKEN_MESSAGE;
1003
+ }
1004
+ });
1005
+ Object.defineProperty(exports, "activeStudioScope", {
1006
+ enumerable: true,
1007
+ get: function() {
1008
+ return activeStudioScope;
1009
+ }
1010
+ });
1011
+ Object.defineProperty(exports, "appendHistoryStep", {
1012
+ enumerable: true,
1013
+ get: function() {
1014
+ return appendHistoryStep;
1015
+ }
1016
+ });
1017
+ Object.defineProperty(exports, "buildLiveSegment", {
1018
+ enumerable: true,
1019
+ get: function() {
1020
+ return buildLiveSegment;
1021
+ }
1022
+ });
1023
+ Object.defineProperty(exports, "buildShareSearch", {
1024
+ enumerable: true,
1025
+ get: function() {
1026
+ return buildShareSearch;
1027
+ }
1028
+ });
1029
+ Object.defineProperty(exports, "buildShareSrc", {
1030
+ enumerable: true,
1031
+ get: function() {
1032
+ return buildShareSrc;
1033
+ }
1034
+ });
1035
+ Object.defineProperty(exports, "cameraMessageSchema", {
1036
+ enumerable: true,
1037
+ get: function() {
1038
+ return cameraMessageSchema;
1039
+ }
1040
+ });
1041
+ Object.defineProperty(exports, "createItinerarySlice", {
1042
+ enumerable: true,
1043
+ get: function() {
1044
+ return createItinerarySlice;
1045
+ }
1046
+ });
1047
+ Object.defineProperty(exports, "createSegmentEditSlice", {
1048
+ enumerable: true,
1049
+ get: function() {
1050
+ return createSegmentEditSlice;
1051
+ }
1052
+ });
1053
+ Object.defineProperty(exports, "defaultStudioScope", {
1054
+ enumerable: true,
1055
+ get: function() {
1056
+ return defaultStudioScope;
1057
+ }
1058
+ });
1059
+ Object.defineProperty(exports, "densifyFreehandLine", {
1060
+ enumerable: true,
1061
+ get: function() {
1062
+ return densifyFreehandLine;
1063
+ }
1064
+ });
1065
+ Object.defineProperty(exports, "descriptionSchema", {
1066
+ enumerable: true,
1067
+ get: function() {
1068
+ return descriptionSchema;
1069
+ }
1070
+ });
1071
+ Object.defineProperty(exports, "displayNameSchema", {
1072
+ enumerable: true,
1073
+ get: function() {
1074
+ return displayNameSchema;
1075
+ }
1076
+ });
1077
+ Object.defineProperty(exports, "draftActivityInput", {
1078
+ enumerable: true,
1079
+ get: function() {
1080
+ return draftActivityInput;
1081
+ }
1082
+ });
1083
+ Object.defineProperty(exports, "draftCollectionsInput", {
1084
+ enumerable: true,
1085
+ get: function() {
1086
+ return draftCollectionsInput;
1087
+ }
1088
+ });
1089
+ Object.defineProperty(exports, "draftCoordinates", {
1090
+ enumerable: true,
1091
+ get: function() {
1092
+ return draftCoordinates;
1093
+ }
1094
+ });
1095
+ Object.defineProperty(exports, "draftNameInput", {
1096
+ enumerable: true,
1097
+ get: function() {
1098
+ return draftNameInput;
1099
+ }
1100
+ });
1101
+ Object.defineProperty(exports, "draftOrganizationInput", {
1102
+ enumerable: true,
1103
+ get: function() {
1104
+ return draftOrganizationInput;
1105
+ }
1106
+ });
1107
+ Object.defineProperty(exports, "draftPositionCount", {
1108
+ enumerable: true,
1109
+ get: function() {
1110
+ return draftPositionCount;
1111
+ }
1112
+ });
1113
+ Object.defineProperty(exports, "draftPrivateInput", {
1114
+ enumerable: true,
1115
+ get: function() {
1116
+ return draftPrivateInput;
1117
+ }
1118
+ });
1119
+ Object.defineProperty(exports, "embedSetContentInput", {
1120
+ enumerable: true,
1121
+ get: function() {
1122
+ return embedSetContentInput;
1123
+ }
1124
+ });
1125
+ Object.defineProperty(exports, "fitDisplayName", {
1126
+ enumerable: true,
1127
+ get: function() {
1128
+ return fitDisplayName;
1129
+ }
1130
+ });
1131
+ Object.defineProperty(exports, "fitFreehandLines", {
1132
+ enumerable: true,
1133
+ get: function() {
1134
+ return fitFreehandLines;
1135
+ }
1136
+ });
1137
+ Object.defineProperty(exports, "graphqlAnalysisToEntries", {
1138
+ enumerable: true,
1139
+ get: function() {
1140
+ return graphqlAnalysisToEntries;
1141
+ }
1142
+ });
1143
+ Object.defineProperty(exports, "graphqlElevationToSummary", {
1144
+ enumerable: true,
1145
+ get: function() {
1146
+ return graphqlElevationToSummary;
1147
+ }
1148
+ });
1149
+ Object.defineProperty(exports, "graphqlRoadAccessToInfo", {
1150
+ enumerable: true,
1151
+ get: function() {
1152
+ return graphqlRoadAccessToInfo;
1153
+ }
1154
+ });
1155
+ Object.defineProperty(exports, "graphqlRouteToLiveRoute", {
1156
+ enumerable: true,
1157
+ get: function() {
1158
+ return graphqlRouteToLiveRoute;
1159
+ }
1160
+ });
1161
+ Object.defineProperty(exports, "inboundBridgeMessageSchema", {
1162
+ enumerable: true,
1163
+ get: function() {
1164
+ return inboundBridgeMessageSchema;
1165
+ }
1166
+ });
1167
+ Object.defineProperty(exports, "indexedInfoSchema", {
1168
+ enumerable: true,
1169
+ get: function() {
1170
+ return indexedInfoSchema;
1171
+ }
1172
+ });
1173
+ Object.defineProperty(exports, "isPublishableScope", {
1174
+ enumerable: true,
1175
+ get: function() {
1176
+ return isPublishableScope;
1177
+ }
1178
+ });
1179
+ Object.defineProperty(exports, "isSegmentDraftDirty", {
1180
+ enumerable: true,
1181
+ get: function() {
1182
+ return isSegmentDraftDirty;
1183
+ }
1184
+ });
1185
+ Object.defineProperty(exports, "issuedShareTokenSchema", {
1186
+ enumerable: true,
1187
+ get: function() {
1188
+ return issuedShareTokenSchema;
1189
+ }
1190
+ });
1191
+ Object.defineProperty(exports, "itineraryInitialState", {
1192
+ enumerable: true,
1193
+ get: function() {
1194
+ return itineraryInitialState;
1195
+ }
1196
+ });
1197
+ Object.defineProperty(exports, "itinerarySelectionSchema", {
1198
+ enumerable: true,
1199
+ get: function() {
1200
+ return itinerarySelectionSchema;
1201
+ }
1202
+ });
1203
+ Object.defineProperty(exports, "lineLengthMeters", {
1204
+ enumerable: true,
1205
+ get: function() {
1206
+ return lineLengthMeters;
1207
+ }
1208
+ });
1209
+ Object.defineProperty(exports, "liveSegmentRouteAnalysisSchema", {
1210
+ enumerable: true,
1211
+ get: function() {
1212
+ return liveSegmentRouteAnalysisSchema;
1213
+ }
1214
+ });
1215
+ Object.defineProperty(exports, "liveSegmentRouteElevationSchema", {
1216
+ enumerable: true,
1217
+ get: function() {
1218
+ return liveSegmentRouteElevationSchema;
1219
+ }
1220
+ });
1221
+ Object.defineProperty(exports, "mapBoundsSchema", {
1222
+ enumerable: true,
1223
+ get: function() {
1224
+ return mapBoundsSchema;
1225
+ }
1226
+ });
1227
+ Object.defineProperty(exports, "mapWaypoints", {
1228
+ enumerable: true,
1229
+ get: function() {
1230
+ return mapWaypoints;
1231
+ }
1232
+ });
1233
+ Object.defineProperty(exports, "originBase", {
1234
+ enumerable: true,
1235
+ get: function() {
1236
+ return originBase;
1237
+ }
1238
+ });
1239
+ Object.defineProperty(exports, "overlayRouteAnalysis", {
1240
+ enumerable: true,
1241
+ get: function() {
1242
+ return overlayRouteAnalysis;
1243
+ }
1244
+ });
1245
+ Object.defineProperty(exports, "readyErrorSchema", {
1246
+ enumerable: true,
1247
+ get: function() {
1248
+ return readyErrorSchema;
1249
+ }
1250
+ });
1251
+ Object.defineProperty(exports, "readyMessageSchema", {
1252
+ enumerable: true,
1253
+ get: function() {
1254
+ return readyMessageSchema;
1255
+ }
1256
+ });
1257
+ Object.defineProperty(exports, "renumber", {
1258
+ enumerable: true,
1259
+ get: function() {
1260
+ return renumber;
1261
+ }
1262
+ });
1263
+ Object.defineProperty(exports, "requestCameraMessageSchema", {
1264
+ enumerable: true,
1265
+ get: function() {
1266
+ return requestCameraMessageSchema;
1267
+ }
1268
+ });
1269
+ Object.defineProperty(exports, "requestSessionTokenMessageSchema", {
1270
+ enumerable: true,
1271
+ get: function() {
1272
+ return requestSessionTokenMessageSchema;
1273
+ }
1274
+ });
1275
+ Object.defineProperty(exports, "requireWritableScope", {
1276
+ enumerable: true,
1277
+ get: function() {
1278
+ return requireWritableScope;
1279
+ }
1280
+ });
1281
+ Object.defineProperty(exports, "resolveActivity", {
1282
+ enumerable: true,
1283
+ get: function() {
1284
+ return resolveActivity;
1285
+ }
1286
+ });
1287
+ Object.defineProperty(exports, "restActivitySlugSchema", {
1288
+ enumerable: true,
1289
+ get: function() {
1290
+ return restActivitySlugSchema;
1291
+ }
1292
+ });
1293
+ Object.defineProperty(exports, "routeLineOf", {
1294
+ enumerable: true,
1295
+ get: function() {
1296
+ return routeLineOf;
1297
+ }
1298
+ });
1299
+ Object.defineProperty(exports, "segmentEditInitialState", {
1300
+ enumerable: true,
1301
+ get: function() {
1302
+ return segmentEditInitialState;
1303
+ }
1304
+ });
1305
+ Object.defineProperty(exports, "segmentEditModeSchema", {
1306
+ enumerable: true,
1307
+ get: function() {
1308
+ return segmentEditModeSchema;
1309
+ }
1310
+ });
1311
+ Object.defineProperty(exports, "segmentEditSessionMark", {
1312
+ enumerable: true,
1313
+ get: function() {
1314
+ return segmentEditSessionMark;
1315
+ }
1316
+ });
1317
+ Object.defineProperty(exports, "segmentInsertAnchorSchema", {
1318
+ enumerable: true,
1319
+ get: function() {
1320
+ return segmentInsertAnchorSchema;
1321
+ }
1322
+ });
1323
+ Object.defineProperty(exports, "setSessionTokenMessageSchema", {
1324
+ enumerable: true,
1325
+ get: function() {
1326
+ return setSessionTokenMessageSchema;
1327
+ }
1328
+ });
1329
+ Object.defineProperty(exports, "shareLinkTargetSchema", {
1330
+ enumerable: true,
1331
+ get: function() {
1332
+ return shareLinkTargetSchema;
1333
+ }
1334
+ });
1335
+ Object.defineProperty(exports, "shareLinkToolContracts", {
1336
+ enumerable: true,
1337
+ get: function() {
1338
+ return shareLinkToolContracts;
1339
+ }
1340
+ });
1341
+ Object.defineProperty(exports, "substituteLiveSegment", {
1342
+ enumerable: true,
1343
+ get: function() {
1344
+ return substituteLiveSegment;
1345
+ }
1346
+ });
1347
+ Object.defineProperty(exports, "surfaceTypeSchema", {
1348
+ enumerable: true,
1349
+ get: function() {
1350
+ return surfaceTypeSchema;
1351
+ }
1352
+ });
1353
+ Object.defineProperty(exports, "switchOverridesSchema", {
1354
+ enumerable: true,
1355
+ get: function() {
1356
+ return switchOverridesSchema;
1357
+ }
1358
+ });
1359
+ Object.defineProperty(exports, "synthesizeDraftSegment", {
1360
+ enumerable: true,
1361
+ get: function() {
1362
+ return synthesizeDraftSegment;
1363
+ }
1364
+ });
1365
+ Object.defineProperty(exports, "toDataActivity", {
1366
+ enumerable: true,
1367
+ get: function() {
1368
+ return toDataActivity;
1369
+ }
1370
+ });
1371
+ Object.defineProperty(exports, "toolNoDataSchema", {
1372
+ enumerable: true,
1373
+ get: function() {
1374
+ return toolNoDataSchema;
1375
+ }
1376
+ });
1377
+ Object.defineProperty(exports, "trailDifficultyTypeSchema", {
1378
+ enumerable: true,
1379
+ get: function() {
1380
+ return trailDifficultyTypeSchema;
1381
+ }
1382
+ });
1383
+ Object.defineProperty(exports, "wayTypeSchema", {
1384
+ enumerable: true,
1385
+ get: function() {
1386
+ return wayTypeSchema;
1387
+ }
1388
+ });
1389
+ Object.defineProperty(exports, "zoneDescriptionSchema", {
1390
+ enumerable: true,
1391
+ get: function() {
1392
+ return zoneDescriptionSchema;
1393
+ }
1394
+ });
1395
+ Object.defineProperty(exports, "zoneNameSchema", {
1396
+ enumerable: true,
1397
+ get: function() {
1398
+ return zoneNameSchema;
1399
+ }
1400
+ });
1401
+
1402
+ //# sourceMappingURL=chunk-C2rr9Q0V.cjs.map