@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,531 @@
1
+ import { originBase } from "../../rules/origin.js";
2
+ import type { EmbeddedStudioDefaultProps } from "../../rules/types.js";
3
+ import {
4
+ type EmbedConfig,
5
+ embedSearchSchema,
6
+ resolveEmbedConfig,
7
+ } from "../../search/rules/params.js";
8
+ import { REQUEST_SESSION_TOKEN_MESSAGE, SET_SESSION_TOKEN_MESSAGE } from "./bridgeMessages.js";
9
+ import { ALLOWLIST_WILDCARD, allowlistUnrestricted } from "./safetyRules.js";
10
+
11
+ /**
12
+ * EmbedConfigFieldKey is the subset of EmbedConfig keys the embed wizard exposes
13
+ * as configuration: the keys EMBED_CONFIG_FIELDS pairs with a URL param. It
14
+ * deliberately excludes the content selectors (the itinerary/collection/zone ids,
15
+ * the activity, the overlay, the time offset) and the non-configurable `embedded`
16
+ * flag. So a descriptor can only ever name a field the snippet builder is allowed
17
+ * to override.
18
+ */
19
+ export type EmbedConfigFieldKey =
20
+ | "preferredLanguage"
21
+ | "preferredTheme"
22
+ | "preferredUnitLength"
23
+ | "preferredUnitPace"
24
+ | "preferredUnitSlope"
25
+ | "preferredUnitTemperature"
26
+ | "segmentsColor"
27
+ | "terrain"
28
+ | "terrainVariant"
29
+ | "withAccessRestrictions"
30
+ | "withDirectionsControl"
31
+ | "withDownloadControl"
32
+ | "withNavigationControl"
33
+ | "withOverlays"
34
+ | "withOverlaysControl"
35
+ | "withPreferencesControl"
36
+ | "withProfileAnalysis"
37
+ | "withProfileCharacteristics"
38
+ | "withProfileElevation"
39
+ | "withProfilePaceControl"
40
+ | "withStreetviewControl"
41
+ | "withTerrains";
42
+
43
+ /**
44
+ * EmbedConfigFieldKind tags how a descriptor's value serializes into the URL: a
45
+ * `boolean` flag becomes `"true"`/`"false"`, an `enum` or `string` becomes its
46
+ * own text, and a `stringArray` emits one repeated param per element. The kind
47
+ * also tells the diff how to compare a value against the organization default (a scalar
48
+ * compare for the first three, an order-insensitive contents compare for the
49
+ * array).
50
+ */
51
+ export type EmbedConfigFieldKind = "boolean" | "enum" | "string" | "stringArray";
52
+
53
+ /**
54
+ * EmbedConfigField pairs one configurable EmbedConfig field with the snake_case
55
+ * search-param name the embed page reads and the kind that drives both its
56
+ * serialization and its default-diff. The `key` is constrained to
57
+ * EmbedConfigFieldKey, so a descriptor cannot reference a content selector or a
58
+ * non-EmbedConfig field. The list of these (EMBED_CONFIG_FIELDS) is the shared
59
+ * source of truth the URL serializer and the wizard's form controls both drive
60
+ * from.
61
+ */
62
+ export interface EmbedConfigField {
63
+ /** key is the EmbedConfig field this descriptor configures. */
64
+ key: EmbedConfigFieldKey;
65
+ /** kind tags how the value serializes and how it is diffed against the default. */
66
+ kind: EmbedConfigFieldKind;
67
+ /**
68
+ * param is the snake_case search-param name the embed reads for this field, which is also the
69
+ * field's key in the organization's default props.
70
+ */
71
+ param: keyof EmbeddedStudioDefaultProps;
72
+ }
73
+
74
+ /**
75
+ * EMBED_CONFIG_FIELDS is the ordered descriptor list pairing each configurable
76
+ * EmbedConfig field with its embed search-param name and kind. It is the shared
77
+ * vocabulary the snippet serializer (buildEmbedSearch) and the wizard form
78
+ * controls both drive from, so the params a snippet can override and the controls
79
+ * the form renders never drift. The order is grouped by configuration section
80
+ * (Appearance, Map controls, Profile, Layers) and, within each section,
81
+ * follows the order the controls render on screen (the top-right control stack for
82
+ * Map controls, the elevation panel top-to-bottom for Profile), so a section's rail
83
+ * order, the serialized search, and the rendered surface all read the same. The
84
+ * content selectors and the always-on `embedded` flag are intentionally absent: a
85
+ * snippet authors the display config, not the content selection (that comes from the
86
+ * itinerary the wizard opened for) and not the always-on flag.
87
+ */
88
+ export const EMBED_CONFIG_FIELDS: readonly EmbedConfigField[] = [
89
+ // Appearance.
90
+ { key: "preferredLanguage", kind: "enum", param: "preferred_language" },
91
+ { key: "preferredTheme", kind: "enum", param: "preferred_theme" },
92
+ { key: "preferredUnitLength", kind: "enum", param: "preferred_unit_length" },
93
+ { key: "preferredUnitPace", kind: "enum", param: "preferred_unit_pace" },
94
+ { key: "preferredUnitSlope", kind: "enum", param: "preferred_unit_slope" },
95
+ { key: "preferredUnitTemperature", kind: "enum", param: "preferred_unit_temperature" },
96
+ { key: "terrain", kind: "string", param: "terrain" },
97
+ { key: "terrainVariant", kind: "enum", param: "terrain_variant" },
98
+ { key: "segmentsColor", kind: "string", param: "segments_color" },
99
+ // Map controls, in the top-right stack's render order: zoom, preferences, download,
100
+ // directions, Street View (the overlay time slider is in the Layers section below).
101
+ { key: "withNavigationControl", kind: "boolean", param: "with_navigation_control" },
102
+ { key: "withPreferencesControl", kind: "boolean", param: "with_preferences_control" },
103
+ { key: "withDownloadControl", kind: "boolean", param: "with_download_control" },
104
+ { key: "withDirectionsControl", kind: "boolean", param: "with_directions_control" },
105
+ { key: "withStreetviewControl", kind: "boolean", param: "with_streetview_control" },
106
+ // Profile panel, in the elevation panel's render order: characteristics, elevation,
107
+ // analysis.
108
+ { key: "withProfileCharacteristics", kind: "boolean", param: "with_profile_characteristics" },
109
+ { key: "withProfileElevation", kind: "boolean", param: "with_profile_elevation" },
110
+ { key: "withProfilePaceControl", kind: "boolean", param: "with_profile_pace_control" },
111
+ { key: "withProfileAnalysis", kind: "boolean", param: "with_profile_analysis" },
112
+ // Layers: the layers-button toggle that governs the panel, then the terrain and
113
+ // overlay allowlists it offers, then the restricted stretches the routes are drawn with.
114
+ { key: "withOverlaysControl", kind: "boolean", param: "with_overlays_control" },
115
+ { key: "withTerrains", kind: "stringArray", param: "with_terrains" },
116
+ { key: "withOverlays", kind: "stringArray", param: "with_overlays" },
117
+ { key: "withAccessRestrictions", kind: "boolean", param: "with_access_restrictions" },
118
+ ] as const;
119
+
120
+ /**
121
+ * emptyEmbedSearch is the parsed empty search every embed field falls through,
122
+ * so resolveEmbedDefaults resolves each field to the organization default rather than a URL
123
+ * override. It is the merged embed schema applied to an empty object: every field
124
+ * is optional there, so the parse yields all-undefined and the resolver takes the
125
+ * default_props branch for every field. Parsed once and frozen because it is a
126
+ * constant input, never mutated.
127
+ */
128
+ const emptyEmbedSearch = embedSearchSchema.parse({});
129
+
130
+ /**
131
+ * resolveEmbedDefaults resolves the organization's default_props into the fully-resolved
132
+ * EmbedConfig the wizard form initializes to and the Reset action returns to. It
133
+ * folds an empty search over the default_props, so every field falls to the organization
134
+ * default (or the hardcoded fallback when the organization leaves it unset): the same
135
+ * precedence the live embed page applies, minus any URL override. It is the
136
+ * baseline buildEmbedSearch diffs against: a configured value equal to this
137
+ * default emits no param.
138
+ *
139
+ * @param defaultProps The organization's typed defaults, as `normalizeDefaultProps` answers
140
+ * them.
141
+ */
142
+ export const resolveEmbedDefaults = (defaultProps: EmbeddedStudioDefaultProps): EmbedConfig =>
143
+ resolveEmbedConfig(emptyEmbedSearch, defaultProps);
144
+
145
+ /**
146
+ * arraysDifferByContents reports whether two string arrays differ by their
147
+ * contents, ignoring order: the diff a stringArray descriptor uses so a
148
+ * reordered-but-equal overlay/terrain list is not treated as an override. Compares
149
+ * by length and a sorted element-wise walk, so `["a","b"]` and `["b","a"]` are
150
+ * equal while `["a"]` and `["a","b"]` differ.
151
+ */
152
+ export const arraysDifferByContents = (a: readonly string[], b: readonly string[]): boolean => {
153
+ if (a.length !== b.length) {
154
+ return true;
155
+ }
156
+
157
+ const sortedA = [...a].sort();
158
+ const sortedB = [...b].sort();
159
+
160
+ return sortedA.some((value, index) => value !== sortedB[index]);
161
+ };
162
+
163
+ /**
164
+ * allowlistEntries emits the pairs one display allowlist contributes, against the default it
165
+ * overrides. Every list field of an embed's config is one (`with_terrains`, `with_overlays`).
166
+ *
167
+ * - A list that offers the whole catalog (empty, or holding the wildcard) emits the wildcard
168
+ * alone, and nothing when the default offers the whole catalog too. The wildcard is how a URL
169
+ * states a list that restricts nothing: a repeated param has one pair per entry, and an empty
170
+ * list has none. Left out, an empty list would resolve to the organization's own list, and
171
+ * the embed would restrict to it while the form shows every layer.
172
+ * - A list that names slugs emits one pair per slug, and nothing when the default names the
173
+ * same slugs in any order.
174
+ */
175
+ const allowlistEntries = (
176
+ param: string,
177
+ value: readonly string[],
178
+ fallback: readonly string[],
179
+ ): Array<[string, string]> => {
180
+ if (allowlistUnrestricted(value)) {
181
+ return allowlistUnrestricted(fallback) ? [] : [[param, ALLOWLIST_WILDCARD]];
182
+ }
183
+
184
+ return arraysDifferByContents(value, fallback) ? value.map((slug) => [param, slug]) : [];
185
+ };
186
+
187
+ /**
188
+ * fieldEntries emits the ordered [param, value] pairs a single descriptor
189
+ * contributes when its configured value differs from the resolved default, or an
190
+ * empty array when it matches (a value equal to the default is never emitted: a
191
+ * param exists solely to override the organization default). A boolean serializes to
192
+ * "true"/"false"; an enum/string serializes to its own text; a list is a display
193
+ * allowlist, emitted as {@link allowlistEntries} states.
194
+ *
195
+ * The value decides how it serializes, read off the config itself, so no member is taken for
196
+ * another type on a descriptor's word. `snippet.test.ts` holds each descriptor's kind to the
197
+ * type of the value it configures.
198
+ */
199
+ const fieldEntries = (
200
+ field: EmbedConfigField,
201
+ config: EmbedConfig,
202
+ defaults: EmbedConfig,
203
+ ): Array<[string, string]> => {
204
+ const value = config[field.key];
205
+ const fallback = defaults[field.key];
206
+
207
+ if (Array.isArray(value)) {
208
+ return allowlistEntries(field.param, value, Array.isArray(fallback) ? fallback : []);
209
+ }
210
+
211
+ if (value === fallback) {
212
+ return [];
213
+ }
214
+
215
+ return [[field.param, typeof value === "boolean" ? (value ? "true" : "false") : value]];
216
+ };
217
+
218
+ /**
219
+ * BuildEmbedSearchInput is the input to buildEmbedSearch: the publishable key the
220
+ * snippet always carries, the content selection (a collection, an itinerary, or
221
+ * both), the optional session token (present only for an organization that sets
222
+ * require_session_token), the live config the wizard authored, and the organization's
223
+ * resolved defaults to diff against. At least one of collectionId / itineraryId names what
224
+ * the embed renders; a caller with neither builds a snippet with no content, which the embed
225
+ * page answers with its own empty state.
226
+ */
227
+ export interface BuildEmbedSearchInput {
228
+ /**
229
+ * collectionId is the collection the embed renders. Alone it selects the whole
230
+ * collection; alongside an itinerary it frames the collection on that one.
231
+ * Omitted from the search when absent.
232
+ */
233
+ collectionId?: string | undefined;
234
+ /** config is the live embed configuration the wizard authored. */
235
+ config: EmbedConfig;
236
+ /** defaults is the organization's resolved defaults the config is diffed against. */
237
+ defaults: EmbedConfig;
238
+ /**
239
+ * itineraryId is the itinerary the embed renders, alone or as the frame inside a
240
+ * collection. Omitted from the search when the embed targets a whole collection.
241
+ */
242
+ itineraryId?: string | undefined;
243
+ /** publishableKey names the organization the embed is served for. */
244
+ publishableKey: string;
245
+ /**
246
+ * sessionToken is the optional embed session token for an organization that sets
247
+ * require_session_token; omitted from the search when absent.
248
+ */
249
+ sessionToken?: string | undefined;
250
+ }
251
+
252
+ /**
253
+ * buildEmbedSearch builds the ordered embed search-param pairs the snippet's iframe
254
+ * src carries. The order is deterministic for testability: the publishable key
255
+ * first, then the itinerary id when present, then the collection id when present,
256
+ * then the session token when present, then, for each descriptor in EMBED_CONFIG_FIELDS in
257
+ * list order, a param ONLY when the configured value differs from the resolved
258
+ * default. A value equal to the organization default is never emitted, so the snippet stays
259
+ * minimal and a publisher's URL carries only the overrides they actually changed.
260
+ * Booleans serialize to "true"/"false"; an allowlist emits one repeated entry per slug
261
+ * and differs by contents (order-insensitive), and one that offers the whole catalog
262
+ * emits the wildcard `*`, which the embed reads as no restriction.
263
+ *
264
+ * @param input The key, the content, the session token, the config and the defaults it is
265
+ * diffed against.
266
+ * @returns The `[param, value]` pairs, not a string, so the caller renders them through
267
+ * URLSearchParams (see {@link buildEmbedSrc}).
268
+ */
269
+ export const buildEmbedSearch = (input: BuildEmbedSearchInput): Array<[string, string]> => {
270
+ const entries: Array<[string, string]> = [["publishable_key", input.publishableKey]];
271
+
272
+ // Either content selector may stand alone. An itinerary alone embeds that itinerary; a
273
+ // collection alone embeds the whole folder; together they embed the collection
274
+ // framed on the one itinerary.
275
+ if (input.itineraryId) {
276
+ entries.push(["itinerary_id", input.itineraryId]);
277
+ }
278
+
279
+ if (input.collectionId) {
280
+ entries.push(["collection_id", input.collectionId]);
281
+ }
282
+
283
+ if (input.sessionToken) {
284
+ entries.push(["session_token", input.sessionToken]);
285
+ }
286
+
287
+ for (const field of EMBED_CONFIG_FIELDS) {
288
+ entries.push(...fieldEntries(field, input.config, input.defaults));
289
+ }
290
+
291
+ return entries;
292
+ };
293
+
294
+ /**
295
+ * buildEmbedSrc renders the ordered search pairs into the embed iframe's src: the
296
+ * `${origin}/studio/embed` path with the params serialized through URLSearchParams (which
297
+ * percent-encodes each value), plus an optional URL `hash` fragment appended verbatim (the
298
+ * `#view=…` anchor {@link buildEmbedViewHash} writes).
299
+ *
300
+ * @param origin The app origin the embed is served from, a scheme and a host with no path. A
301
+ * trailing `/` is read as none. The caller supplies it, so the builder reads no environment.
302
+ * @param search The ordered pairs {@link buildEmbedSearch} answers.
303
+ * @param hash The fragment to append, `#` included.
304
+ * @default hash ""
305
+ */
306
+ export const buildEmbedSrc = (
307
+ origin: string,
308
+ search: Array<[string, string]>,
309
+ hash = "",
310
+ ): string => {
311
+ const params = new URLSearchParams(search);
312
+
313
+ return `${originBase(origin)}/studio/embed?${params.toString()}${hash}`;
314
+ };
315
+
316
+ /**
317
+ * EmbedViewAnchor is the captured per-embed default camera buildEmbedViewHash encodes
318
+ * (each channel null when the publisher left it unset). It mirrors the wizard's
319
+ * DefaultView shape structurally, so this module imports no type of the wizard's.
320
+ */
321
+ export interface EmbedViewAnchor {
322
+ bearing: number | null;
323
+ center: [number, number] | null;
324
+ pitch: number | null;
325
+ zoom: number | null;
326
+ }
327
+
328
+ /**
329
+ * buildEmbedViewHash encodes the captured default view as MapLibre's `#view` URL hash,
330
+ * `#view=<zoom>/<lat>/<lng>/<bearing>/<pitch>`: the exact anchor a `hash: "view"` map
331
+ * reads on load to open framed there. The publisher captures it from the live preview,
332
+ * and it rides the copyable snippet as this hash (NOT search params), so the embedded
333
+ * map frames itself purely off the URL fragment. center + zoom are the essential anchor;
334
+ * with either unset there is nothing to frame, so the hash is empty (the embed opens at
335
+ * its plain fit-to-itinerary). A null bearing/pitch encodes as 0 (north-up / flat). Pure
336
+ * string output (no DOM, no environment), so it stays a testable leaf.
337
+ *
338
+ * @param view The captured camera, each channel null when the publisher left it unset.
339
+ * @returns The fragment, `#` included, or the empty string when the view frames nothing.
340
+ *
341
+ * @example
342
+ * ```ts
343
+ * const hash = buildEmbedViewHash({ bearing: 45, center: [6.86, 45.83], pitch: 30, zoom: 11 });
344
+ * // hash is "#view=11.00/45.830000/6.860000/45/30"
345
+ * ```
346
+ */
347
+ export const buildEmbedViewHash = (view: EmbedViewAnchor): string => {
348
+ if (view.center === null || view.zoom === null) {
349
+ return "";
350
+ }
351
+
352
+ const [lng, lat] = view.center;
353
+ const bearing = Math.round(view.bearing ?? 0);
354
+ const pitch = Math.round(view.pitch ?? 0);
355
+
356
+ return `#view=${view.zoom.toFixed(2)}/${lat.toFixed(6)}/${lng.toFixed(6)}/${bearing}/${pitch}`;
357
+ };
358
+
359
+ /**
360
+ * EMBED_IFRAME_RADIUS_PX is the corner radius, in px, shared by the copy-paste snippet
361
+ * (buildEmbedIframe) and the wizard's in-app preview box, so the preview frames the embed
362
+ * exactly as the published iframe renders it. It is a concrete px length, NOT a Mantine
363
+ * radius token: the snippet runs on the publisher's own page where no Mantine CSS variables
364
+ * resolve, so the value must be self-contained. 8px is the studio's `md` radius, so the
365
+ * embed reads as a finished card on the host page.
366
+ */
367
+ export const EMBED_IFRAME_RADIUS_PX = 8;
368
+
369
+ /**
370
+ * BuildEmbedIframeInput is the input to buildEmbedIframe: the iframe src and the
371
+ * width/height the publisher chose for the embed.
372
+ */
373
+ export interface BuildEmbedIframeInput {
374
+ /** height is the iframe height (a CSS length, e.g. "480" or "480px"). */
375
+ height: string;
376
+ /** src is the embed iframe src built by buildEmbedSrc. */
377
+ src: string;
378
+ /** title is the iframe's accessible title. */
379
+ title: string;
380
+ /** width is the iframe width (a CSS length, e.g. "100%" or "640"). */
381
+ width: string;
382
+ }
383
+
384
+ /**
385
+ * escapeHtmlAttribute rewrites a string for safe interpolation into a double-quoted HTML
386
+ * attribute value. The ampersand is replaced first so the entities the later passes introduce
387
+ * are not themselves re-escaped, then the angle brackets and the double quote. The apostrophe
388
+ * is left as-is, since a double-quoted attribute does not require escaping it, so a common name
389
+ * like `Tour de l'Île` stays readable.
390
+ */
391
+ const escapeHtmlAttribute = (value: string): string =>
392
+ value.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
393
+
394
+ /**
395
+ * buildEmbedIframe renders the copy-paste `<iframe>` HTML a publisher pastes into their site:
396
+ * the src, the chosen width and height, a zero border with rounded corners (8px, the studio's
397
+ * `md` radius, so the embed reads as a finished card on the host page), lazy loading, and an
398
+ * accessible title. Every interpolated value is HTML-escaped, so a title, a width or a height a
399
+ * publisher types cannot break out of its attribute, and the `&` between the src's params is
400
+ * written `&amp;`, which a browser reads back as `&`.
401
+ *
402
+ * It carries no `allow="fullscreen"`: the embedded studio offers no fullscreen affordance, so
403
+ * the permission would be dead. It carries `referrerpolicy="strict-origin-when-cross-origin"`:
404
+ * the hosted embed serves only a frame request that names its page in `Referer`, since that
405
+ * origin is what its allowed-domains check reads, and the attribute sends the page's origin (and
406
+ * never its path) even from a page whose own `Referrer-Policy` is `no-referrer`, which would
407
+ * otherwise leave the embed blank. It is indented for readability because it is copy-paste
408
+ * output a human reads.
409
+ *
410
+ * @example
411
+ * ```ts
412
+ * const html = buildEmbedIframe({
413
+ * height: "480",
414
+ * src: "https://mountaya.com/studio/embed?publishable_key=pk_example&itinerary_id=itin-1",
415
+ * title: "Tour du Mont Blanc",
416
+ * width: "100%",
417
+ * });
418
+ * ```
419
+ */
420
+ export const buildEmbedIframe = (input: BuildEmbedIframeInput): string =>
421
+ [
422
+ "<iframe",
423
+ ` src="${escapeHtmlAttribute(input.src)}"`,
424
+ ` width="${escapeHtmlAttribute(input.width)}"`,
425
+ ` height="${escapeHtmlAttribute(input.height)}"`,
426
+ ` title="${escapeHtmlAttribute(input.title)}"`,
427
+ ` style="border:0;border-radius:${EMBED_IFRAME_RADIUS_PX}px"`,
428
+ ' loading="lazy"',
429
+ ' referrerpolicy="strict-origin-when-cross-origin"',
430
+ "></iframe>",
431
+ ].join("\n");
432
+
433
+ /**
434
+ * EMBED_SESSION_ENDPOINT is the path the session script asks by default: the endpoint of the
435
+ * integrator's own server that mints the hosted embed's session token. A publisher whose endpoint
436
+ * lives elsewhere edits the one line of the script that states it.
437
+ *
438
+ * It is the embed's own path, and not the `/api/mountaya-session` of the SDK's examples, which
439
+ * mints an Embedded Studio's token: a `studio-embedded` session naming the signed-in member, for
440
+ * the studio's key. The embed's endpoint calls `POST /v1/sessions` with the embed's own
441
+ * publishable key and nothing else, so its token names no surface (the API reads `api`) and no
442
+ * user, and reads what the key alone reaches: what the organization publishes.
443
+ */
444
+ export const EMBED_SESSION_ENDPOINT = "/api/mountaya-embed-session";
445
+
446
+ /** BuildEmbedSessionScriptInput is the input to buildEmbedSessionScript. */
447
+ export interface BuildEmbedSessionScriptInput {
448
+ /**
449
+ * appOrigin is the origin the embed is served from, a scheme and a host with no path, as
450
+ * {@link buildEmbedSrc} takes it. The script answers only a frame of that origin, and posts the
451
+ * token to that origin alone.
452
+ */
453
+ appOrigin: string;
454
+ /**
455
+ * endpoint is the path or URL of the integrator's endpoint that mints a session token.
456
+ *
457
+ * @default EMBED_SESSION_ENDPOINT
458
+ */
459
+ endpoint?: string | undefined;
460
+ }
461
+
462
+ /**
463
+ * scriptString renders a value as a JavaScript string literal that cannot close the `<script>`
464
+ * holding it: JSON's own quoting, with every `<` written `\u003c`.
465
+ */
466
+ const scriptString = (value: string): string => JSON.stringify(value).replace(/</g, "\\u003c");
467
+
468
+ /**
469
+ * buildEmbedSessionScript renders the `<script>` an organization that sets
470
+ * `require_session_token` pastes beside the snippet's iframe. A session token lives minutes and
471
+ * only the integrator's server can mint one, so the hosted embed asks the page that frames it
472
+ * for a token, when it loads with none and a minute before the one it holds expires, with a
473
+ * `mountaya:requestSessionToken` message. The script answers each one: it fetches the endpoint,
474
+ * which calls `POST /v1/sessions` with the secret key, and posts the session's `token` and
475
+ * `expires_at` back to the frame that asked as a `mountaya:setSessionToken`. The endpoint may pass
476
+ * the API's answer through as it came, `{ data: { token, expires_at } }`, or answer the session
477
+ * unwrapped, `{ token, expires_at }`: the script reads either.
478
+ *
479
+ * It hears only a frame of the embed's origin, and posts the token to that origin alone, so no
480
+ * other frame on the page is handed one. One copy serves every embed on a page: a second copy
481
+ * pasted beside another iframe attaches nothing. An endpoint that fails, or that answers no token
482
+ * in either shape, is reported on the page's console with nothing posted, and the embed asks
483
+ * again a minute later. So is a session that names a user (`user_id` a string): that is a
484
+ * member's token, minted for an Embedded Studio, which would read the member's drafts in a page
485
+ * any visitor loads, and no embed is handed one. The values it states are JavaScript string
486
+ * literals that cannot close the script. Indented for readability, as the iframe is.
487
+ *
488
+ * @example
489
+ * ```ts
490
+ * const html = buildEmbedSessionScript({ appOrigin: "https://mountaya.com" });
491
+ * ```
492
+ */
493
+ export const buildEmbedSessionScript = (input: BuildEmbedSessionScriptInput): string =>
494
+ [
495
+ "<script>",
496
+ " // Answers each Mountaya embed's request for a session token from your endpoint, which",
497
+ " // calls POST /v1/sessions with your secret key and answers its body, or the session in it.",
498
+ " (function () {",
499
+ ` var origin = ${scriptString(originBase(input.appOrigin))};`,
500
+ ` var endpoint = ${scriptString(input.endpoint ?? EMBED_SESSION_ENDPOINT)};`,
501
+ " if (window.mountayaEmbedSession) return;",
502
+ " window.mountayaEmbedSession = true;",
503
+ ' window.addEventListener("message", function (event) {',
504
+ " if (event.origin !== origin || !event.data) return;",
505
+ ` if (event.data.type !== ${scriptString(REQUEST_SESSION_TOKEN_MESSAGE)}) return;`,
506
+ " var frame = event.source;",
507
+ ' fetch(endpoint, { credentials: "same-origin" })',
508
+ " .then(function (response) {",
509
+ ' if (!response.ok) throw new Error("Session endpoint answered " + response.status);',
510
+ " return response.json();",
511
+ " })",
512
+ " .then(function (body) {",
513
+ " var session = body && body.data ? body.data : body;",
514
+ ' if (!session || typeof session.token !== "string") {',
515
+ ' throw new Error("Session endpoint answered no token");',
516
+ " }",
517
+ ' if (typeof session.user_id === "string") {',
518
+ ' throw new Error("Session endpoint answered a token naming a user: mint without user_id");',
519
+ " }",
520
+ " frame.postMessage(",
521
+ ` { type: ${scriptString(SET_SESSION_TOKEN_MESSAGE)}, token: session.token, expiresAt: session.expires_at },`,
522
+ " origin",
523
+ " );",
524
+ " })",
525
+ " .catch(function (error) {",
526
+ " console.error(error);",
527
+ " });",
528
+ " });",
529
+ " })();",
530
+ "</script>",
531
+ ].join("\n");