@mountaya/studio 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (524) hide show
  1. package/CHANGELOG.md +39 -0
  2. package/LICENCE.fr.txt +280 -0
  3. package/LICENSE.txt +262 -0
  4. package/README.md +917 -2
  5. package/dist/agent/index.cjs +2854 -0
  6. package/dist/agent/index.cjs.map +1 -0
  7. package/dist/agent/index.d.cts +1257 -0
  8. package/dist/agent/index.d.ts +1257 -0
  9. package/dist/agent/index.js +2818 -0
  10. package/dist/agent/index.js.map +1 -0
  11. package/dist/bus-BwiNiXdH.d.ts +514 -0
  12. package/dist/bus-DzmhPwdK.d.cts +514 -0
  13. package/dist/chainModel-B23pEP_1.d.cts +127 -0
  14. package/dist/chainModel-B23pEP_1.d.ts +127 -0
  15. package/dist/chunk-2HFY7ETU.js +5721 -0
  16. package/dist/chunk-2HFY7ETU.js.map +1 -0
  17. package/dist/chunk-355TOXSB.js +72 -0
  18. package/dist/chunk-355TOXSB.js.map +1 -0
  19. package/dist/chunk-4ZCUZVSV.js +10275 -0
  20. package/dist/chunk-4ZCUZVSV.js.map +1 -0
  21. package/dist/chunk-6HEKY3NF.js +95 -0
  22. package/dist/chunk-6HEKY3NF.js.map +1 -0
  23. package/dist/chunk-7GFLGGBX.cjs +8 -0
  24. package/dist/chunk-7GFLGGBX.cjs.map +1 -0
  25. package/dist/chunk-7NBRCENN.cjs +19 -0
  26. package/dist/chunk-7NBRCENN.cjs.map +1 -0
  27. package/dist/chunk-AF5GCXE3.js +8 -0
  28. package/dist/chunk-AF5GCXE3.js.map +1 -0
  29. package/dist/chunk-CJDIFRGZ.cjs +2005 -0
  30. package/dist/chunk-CJDIFRGZ.cjs.map +1 -0
  31. package/dist/chunk-CNPZY7N3.js +349 -0
  32. package/dist/chunk-CNPZY7N3.js.map +1 -0
  33. package/dist/chunk-DZJHTWSF.cjs +45 -0
  34. package/dist/chunk-DZJHTWSF.cjs.map +1 -0
  35. package/dist/chunk-EABIHHWA.js +42 -0
  36. package/dist/chunk-EABIHHWA.js.map +1 -0
  37. package/dist/chunk-EKZWV6RS.cjs +415 -0
  38. package/dist/chunk-EKZWV6RS.cjs.map +1 -0
  39. package/dist/chunk-EOKRXXAC.cjs +24 -0
  40. package/dist/chunk-EOKRXXAC.cjs.map +1 -0
  41. package/dist/chunk-F73W2ZTJ.js +1126 -0
  42. package/dist/chunk-F73W2ZTJ.js.map +1 -0
  43. package/dist/chunk-H4DVOZ5O.js +1897 -0
  44. package/dist/chunk-H4DVOZ5O.js.map +1 -0
  45. package/dist/chunk-HI52PBFT.cjs +10314 -0
  46. package/dist/chunk-HI52PBFT.cjs.map +1 -0
  47. package/dist/chunk-IDBXFBLG.cjs +1225 -0
  48. package/dist/chunk-IDBXFBLG.cjs.map +1 -0
  49. package/dist/chunk-LBWTJZUJ.js +297 -0
  50. package/dist/chunk-LBWTJZUJ.js.map +1 -0
  51. package/dist/chunk-NCLA6DKD.cjs +310 -0
  52. package/dist/chunk-NCLA6DKD.cjs.map +1 -0
  53. package/dist/chunk-O4MC5DPD.js +19 -0
  54. package/dist/chunk-O4MC5DPD.js.map +1 -0
  55. package/dist/chunk-OP37FKW6.cjs +98 -0
  56. package/dist/chunk-OP37FKW6.cjs.map +1 -0
  57. package/dist/chunk-OQSYFH3Z.cjs +5945 -0
  58. package/dist/chunk-OQSYFH3Z.cjs.map +1 -0
  59. package/dist/chunk-PACIO4NS.cjs +26 -0
  60. package/dist/chunk-PACIO4NS.cjs.map +1 -0
  61. package/dist/chunk-PSZ2R3TC.cjs +75 -0
  62. package/dist/chunk-PSZ2R3TC.cjs.map +1 -0
  63. package/dist/chunk-QFO5CZG2.cjs +136 -0
  64. package/dist/chunk-QFO5CZG2.cjs.map +1 -0
  65. package/dist/chunk-QL63MUEW.cjs +140 -0
  66. package/dist/chunk-QL63MUEW.cjs.map +1 -0
  67. package/dist/chunk-RFUPPVZO.js +17 -0
  68. package/dist/chunk-RFUPPVZO.js.map +1 -0
  69. package/dist/chunk-RPG2LWMP.js +23 -0
  70. package/dist/chunk-RPG2LWMP.js.map +1 -0
  71. package/dist/chunk-TIBXK6B7.cjs +12 -0
  72. package/dist/chunk-TIBXK6B7.cjs.map +1 -0
  73. package/dist/chunk-UU65VNEV.js +381 -0
  74. package/dist/chunk-UU65VNEV.js.map +1 -0
  75. package/dist/chunk-VGX6TR2I.js +209 -0
  76. package/dist/chunk-VGX6TR2I.js.map +1 -0
  77. package/dist/chunk-WUTDDBVP.js +130 -0
  78. package/dist/chunk-WUTDDBVP.js.map +1 -0
  79. package/dist/chunk-WVQQLKCI.cjs +224 -0
  80. package/dist/chunk-WVQQLKCI.cjs.map +1 -0
  81. package/dist/chunk-WZYXG3SE.js +111 -0
  82. package/dist/chunk-WZYXG3SE.js.map +1 -0
  83. package/dist/chunk-XDI2X3KE.js +6 -0
  84. package/dist/chunk-XDI2X3KE.js.map +1 -0
  85. package/dist/chunk-XKHLRIC7.cjs +381 -0
  86. package/dist/chunk-XKHLRIC7.cjs.map +1 -0
  87. package/dist/context-DNtd2WUv.d.cts +11666 -0
  88. package/dist/context-DgB72Bur.d.ts +11666 -0
  89. package/dist/directorThreads-CqmvsV8b.d.cts +80 -0
  90. package/dist/directorThreads-CqmvsV8b.d.ts +80 -0
  91. package/dist/en-Bu4Ti9Ev.d.cts +2315 -0
  92. package/dist/en-Bu4Ti9Ev.d.ts +2315 -0
  93. package/dist/engines/index.cjs +3446 -0
  94. package/dist/engines/index.cjs.map +1 -0
  95. package/dist/engines/index.d.cts +2216 -0
  96. package/dist/engines/index.d.ts +2216 -0
  97. package/dist/engines/index.js +3416 -0
  98. package/dist/engines/index.js.map +1 -0
  99. package/dist/handlers/index.cjs +99 -0
  100. package/dist/handlers/index.cjs.map +1 -0
  101. package/dist/handlers/index.d.cts +445 -0
  102. package/dist/handlers/index.d.ts +445 -0
  103. package/dist/handlers/index.js +42 -0
  104. package/dist/handlers/index.js.map +1 -0
  105. package/dist/index.cjs +4562 -0
  106. package/dist/index.cjs.map +1 -0
  107. package/dist/index.d.cts +7297 -0
  108. package/dist/index.d.ts +7297 -0
  109. package/dist/index.js +3223 -0
  110. package/dist/index.js.map +1 -0
  111. package/dist/plugins/index.cjs +977 -0
  112. package/dist/plugins/index.cjs.map +1 -0
  113. package/dist/plugins/index.d.cts +313 -0
  114. package/dist/plugins/index.d.ts +313 -0
  115. package/dist/plugins/index.js +933 -0
  116. package/dist/plugins/index.js.map +1 -0
  117. package/dist/saveFile-j-1kkApx.d.cts +123 -0
  118. package/dist/saveFile-j-1kkApx.d.ts +123 -0
  119. package/dist/seams/index.cjs +152 -0
  120. package/dist/seams/index.cjs.map +1 -0
  121. package/dist/seams/index.d.cts +485 -0
  122. package/dist/seams/index.d.ts +485 -0
  123. package/dist/seams/index.js +79 -0
  124. package/dist/seams/index.js.map +1 -0
  125. package/dist/shareLink-B6hlt942.d.ts +144 -0
  126. package/dist/shareLink-C7rIMb7x.d.ts +527 -0
  127. package/dist/shareLink-CnTxxXjp.d.cts +144 -0
  128. package/dist/shareLink-DyZVYH2V.d.cts +527 -0
  129. package/dist/strings/fr/index.cjs +2121 -0
  130. package/dist/strings/fr/index.cjs.map +1 -0
  131. package/dist/strings/fr/index.d.cts +19 -0
  132. package/dist/strings/fr/index.d.ts +19 -0
  133. package/dist/strings/fr/index.js +2119 -0
  134. package/dist/strings/fr/index.js.map +1 -0
  135. package/dist/strings/index.cjs +2678 -0
  136. package/dist/strings/index.cjs.map +1 -0
  137. package/dist/strings/index.d.cts +731 -0
  138. package/dist/strings/index.d.ts +731 -0
  139. package/dist/strings/index.js +2644 -0
  140. package/dist/strings/index.js.map +1 -0
  141. package/dist/studioPlugin-C3C7VjMy.d.ts +847 -0
  142. package/dist/studioPlugin-Cf3OBNUv.d.cts +847 -0
  143. package/dist/tabs-B2nRO4p_.d.cts +15 -0
  144. package/dist/tabs-B2nRO4p_.d.ts +15 -0
  145. package/dist/testing/index.cjs +292 -0
  146. package/dist/testing/index.cjs.map +1 -0
  147. package/dist/testing/index.d.cts +306 -0
  148. package/dist/testing/index.d.ts +306 -0
  149. package/dist/testing/index.js +284 -0
  150. package/dist/testing/index.js.map +1 -0
  151. package/dist/time/index.cjs +28 -0
  152. package/dist/time/index.cjs.map +1 -0
  153. package/dist/time/index.d.cts +43 -0
  154. package/dist/time/index.d.ts +43 -0
  155. package/dist/time/index.js +26 -0
  156. package/dist/time/index.js.map +1 -0
  157. package/dist/types-BzJRV6UI.d.cts +845 -0
  158. package/dist/types-BzJRV6UI.d.ts +845 -0
  159. package/dist/zoneForm-CdYNtnnA.d.cts +320 -0
  160. package/dist/zoneForm-mG85yt5e.d.ts +320 -0
  161. package/package.json +225 -4
  162. package/src/agent/engines/agentThreads.ts +1601 -0
  163. package/src/agent/engines/directorChat.ts +500 -0
  164. package/src/agent/index.ts +67 -0
  165. package/src/agent/rules/agentEditLock.ts +115 -0
  166. package/src/agent/rules/agentErrorCopy.ts +44 -0
  167. package/src/agent/rules/copilotOrganization.ts +36 -0
  168. package/src/agent/rules/playbook.gen.ts +444 -0
  169. package/src/agent/rules/router.ts +518 -0
  170. package/src/agent/rules/stateDelta.ts +28 -0
  171. package/src/agent/rules/studioRouter.ts +123 -0
  172. package/src/agent/rules/surfaces.gen.ts +633 -0
  173. package/src/agent/rules/threadsUrl.ts +48 -0
  174. package/src/agent/rules/transcriptObserver.ts +90 -0
  175. package/src/agent/stores/agentThreads.ts +454 -0
  176. package/src/bus/contracts/noData.ts +18 -0
  177. package/src/bus/contracts/shared.ts +172 -0
  178. package/src/bus/contracts/studioTools.ts +224 -0
  179. package/src/bus/rules/bus.ts +858 -0
  180. package/src/bus/rules/confirmation.ts +22 -0
  181. package/src/bus/rules/defineRegistry.ts +26 -0
  182. package/src/bus/rules/errors.ts +401 -0
  183. package/src/bus/rules/handlerErrors.ts +103 -0
  184. package/src/bus/rules/handlerRegistry.ts +627 -0
  185. package/src/bus/rules/inputSchema.ts +232 -0
  186. package/src/bus/rules/invalidInput.ts +441 -0
  187. package/src/bus/rules/lateBoundTools.ts +100 -0
  188. package/src/bus/rules/studioRegistry.ts +324 -0
  189. package/src/bus/rules/studioToolBus.ts +73 -0
  190. package/src/bus/rules/types.ts +805 -0
  191. package/src/chrome/contracts/alert.ts +42 -0
  192. package/src/chrome/contracts/itinerary.ts +26 -0
  193. package/src/chrome/contracts/map.ts +23 -0
  194. package/src/chrome/contracts/overlay.ts +46 -0
  195. package/src/chrome/contracts/panel.ts +29 -0
  196. package/src/chrome/contracts/question.ts +52 -0
  197. package/src/chrome/contracts/selection.ts +26 -0
  198. package/src/chrome/contracts/sidenav.ts +23 -0
  199. package/src/chrome/contracts/snapshot.ts +319 -0
  200. package/src/chrome/contracts/state.ts +22 -0
  201. package/src/chrome/contracts/tabs.ts +56 -0
  202. package/src/chrome/handlers/alert.ts +91 -0
  203. package/src/chrome/handlers/introspection.ts +180 -0
  204. package/src/chrome/handlers/panels.ts +42 -0
  205. package/src/chrome/handlers/question.ts +24 -0
  206. package/src/chrome/handlers/sidenav.ts +116 -0
  207. package/src/chrome/handlers/snapshot.ts +451 -0
  208. package/src/chrome/handlers/stateDelta.ts +125 -0
  209. package/src/chrome/handlers/tabs.ts +143 -0
  210. package/src/chrome/handlers/timestamp.ts +19 -0
  211. package/src/chrome/rules/agentSelectors.ts +210 -0
  212. package/src/chrome/rules/mapAlert.ts +13 -0
  213. package/src/chrome/rules/question.ts +25 -0
  214. package/src/chrome/rules/tabs.ts +13 -0
  215. package/src/chrome/stores/activeDraftSession.ts +134 -0
  216. package/src/chrome/stores/chrome.ts +527 -0
  217. package/src/chrome/stores/uiStore.ts +573 -0
  218. package/src/collab/contracts/collab.ts +261 -0
  219. package/src/collab/handlers/collab.ts +468 -0
  220. package/src/collab/rules/toolNames.ts +33 -0
  221. package/src/collab/stores/collab.ts +899 -0
  222. package/src/collections/contracts/collection.ts +182 -0
  223. package/src/collections/handlers/collectionAttach.ts +141 -0
  224. package/src/collections/handlers/collections.ts +499 -0
  225. package/src/collections/handlers/heldCollection.ts +42 -0
  226. package/src/collections/handlers/restCollections.ts +386 -0
  227. package/src/collections/rules/collections.ts +138 -0
  228. package/src/collections/rules/entityCollections.ts +53 -0
  229. package/src/collections/stores/collections.ts +133 -0
  230. package/src/data/contracts/data.ts +233 -0
  231. package/src/data/contracts/itinerary.ts +71 -0
  232. package/src/data/handlers/activityResolve.ts +76 -0
  233. package/src/data/handlers/data.ts +200 -0
  234. package/src/data/handlers/graphql.ts +26 -0
  235. package/src/data/handlers/mutationSink.ts +1577 -0
  236. package/src/data/handlers/profile.ts +83 -0
  237. package/src/data/handlers/writeThrough.ts +417 -0
  238. package/src/data/rules/cache.ts +181 -0
  239. package/src/data/rules/dataTypes.ts +40 -0
  240. package/src/data/rules/keys.ts +106 -0
  241. package/src/data/rules/persistence.ts +1058 -0
  242. package/src/data/rules/requestBody.ts +43 -0
  243. package/src/data/rules/restErrors.ts +354 -0
  244. package/src/data/rules/sessionSurface.ts +156 -0
  245. package/src/data/rules/toolResultData.ts +73 -0
  246. package/src/data/rules/uuid.ts +24 -0
  247. package/src/edit/contracts/edit.ts +37 -0
  248. package/src/edit/contracts/itinerary.ts +57 -0
  249. package/src/edit/handlers/draftCommit.ts +257 -0
  250. package/src/edit/handlers/editDiscard.ts +34 -0
  251. package/src/edit/handlers/editLock.ts +949 -0
  252. package/src/edit/handlers/editor.ts +203 -0
  253. package/src/edit/handlers/formUnsaved.ts +24 -0
  254. package/src/edit/rules/draftMetadata.ts +117 -0
  255. package/src/edit/rules/editKeyboard.ts +222 -0
  256. package/src/edit/rules/editShortcuts.ts +102 -0
  257. package/src/edit/rules/editTooltip.ts +174 -0
  258. package/src/edit/rules/editorTaken.ts +49 -0
  259. package/src/edit/rules/history.ts +26 -0
  260. package/src/edit/rules/unsavedWork.ts +60 -0
  261. package/src/edit/stores/editorReservation.ts +70 -0
  262. package/src/edit/stores/formsUnsaved.ts +54 -0
  263. package/src/embed/contracts/embed.ts +48 -0
  264. package/src/embed/engines/embedFraming.ts +1329 -0
  265. package/src/embed/engines/embedReady.ts +353 -0
  266. package/src/embed/engines/framingPageSession.ts +169 -0
  267. package/src/embed/handlers/embed.ts +130 -0
  268. package/src/embed/rules/allowedDomains.ts +71 -0
  269. package/src/embed/rules/bridgeMessages.ts +224 -0
  270. package/src/embed/rules/defaults.ts +173 -0
  271. package/src/embed/rules/displaySeed.ts +115 -0
  272. package/src/embed/rules/embedAllowlist.ts +146 -0
  273. package/src/embed/rules/embedConstraints.ts +215 -0
  274. package/src/embed/rules/embedElements.ts +277 -0
  275. package/src/embed/rules/embedSectionFields.ts +126 -0
  276. package/src/embed/rules/embedSecurity.ts +116 -0
  277. package/src/embed/rules/fieldDependencies.ts +87 -0
  278. package/src/embed/rules/fieldOptions.ts +138 -0
  279. package/src/embed/rules/layerOptions.ts +161 -0
  280. package/src/embed/rules/readyProtocol.ts +66 -0
  281. package/src/embed/rules/safetyRules.ts +213 -0
  282. package/src/embed/rules/snippet.ts +531 -0
  283. package/src/embed/rules/tableCode.ts +269 -0
  284. package/src/embed/stores/embed.ts +60 -0
  285. package/src/embed/stores/embedContent.ts +77 -0
  286. package/src/engines/index.ts +81 -0
  287. package/src/handlers/index.ts +66 -0
  288. package/src/index.ts +1086 -0
  289. package/src/itinerary/contracts/itinerary.ts +705 -0
  290. package/src/itinerary/engines/itineraryPace.ts +612 -0
  291. package/src/itinerary/engines/profileMarker.ts +238 -0
  292. package/src/itinerary/handlers/importStaging.ts +352 -0
  293. package/src/itinerary/handlers/itinerary.ts +572 -0
  294. package/src/itinerary/handlers/itineraryDuplicate.ts +177 -0
  295. package/src/itinerary/handlers/itineraryExport.ts +117 -0
  296. package/src/itinerary/handlers/itineraryImport.ts +783 -0
  297. package/src/itinerary/handlers/itineraryPublish.ts +118 -0
  298. package/src/itinerary/handlers/itinerarySelection.ts +354 -0
  299. package/src/itinerary/handlers/itinerarySuggest.ts +1186 -0
  300. package/src/itinerary/handlers/itineraryUnpublish.ts +101 -0
  301. package/src/itinerary/handlers/publicationScope.ts +118 -0
  302. package/src/itinerary/handlers/restItineraries.ts +752 -0
  303. package/src/itinerary/handlers/restItineraryExport.ts +70 -0
  304. package/src/itinerary/handlers/restItineraryImport.ts +311 -0
  305. package/src/itinerary/handlers/restItineraryPace.ts +87 -0
  306. package/src/itinerary/handlers/restItineraryRecord.ts +36 -0
  307. package/src/itinerary/handlers/suggestParams.ts +379 -0
  308. package/src/itinerary/handlers/suggestStaging.ts +363 -0
  309. package/src/itinerary/handlers/surfaceOpen.ts +389 -0
  310. package/src/itinerary/rules/activity.ts +139 -0
  311. package/src/itinerary/rules/analysis.ts +42 -0
  312. package/src/itinerary/rules/ceiling.ts +49 -0
  313. package/src/itinerary/rules/createFlow.ts +107 -0
  314. package/src/itinerary/rules/densify.ts +440 -0
  315. package/src/itinerary/rules/draftSurface.ts +219 -0
  316. package/src/itinerary/rules/editorView.ts +83 -0
  317. package/src/itinerary/rules/export.ts +159 -0
  318. package/src/itinerary/rules/friendlyName.ts +77 -0
  319. package/src/itinerary/rules/import.ts +1052 -0
  320. package/src/itinerary/rules/importFiles.ts +140 -0
  321. package/src/itinerary/rules/importTotals.ts +77 -0
  322. package/src/itinerary/rules/liveSegment.ts +712 -0
  323. package/src/itinerary/rules/lngLat.ts +17 -0
  324. package/src/itinerary/rules/mapSync.ts +100 -0
  325. package/src/itinerary/rules/previewRender.ts +416 -0
  326. package/src/itinerary/rules/profileReadout.ts +216 -0
  327. package/src/itinerary/rules/routing.ts +707 -0
  328. package/src/itinerary/rules/suggest.ts +522 -0
  329. package/src/itinerary/rules/suggestionPreview.ts +119 -0
  330. package/src/itinerary/rules/view.ts +61 -0
  331. package/src/itinerary/stores/importSession.ts +319 -0
  332. package/src/itinerary/stores/itinerary.ts +331 -0
  333. package/src/itinerary/stores/itineraryDuplicate.ts +76 -0
  334. package/src/itinerary/stores/sessionIdentity.ts +43 -0
  335. package/src/itinerary/stores/suggestSession.ts +418 -0
  336. package/src/layers/contracts/itinerary.ts +46 -0
  337. package/src/layers/contracts/overlay.ts +132 -0
  338. package/src/layers/handlers/enrichment.ts +36 -0
  339. package/src/layers/handlers/overlay.ts +406 -0
  340. package/src/layers/handlers/restLayers.ts +94 -0
  341. package/src/layers/handlers/tiles.ts +25 -0
  342. package/src/layers/rules/layers.ts +212 -0
  343. package/src/layers/rules/overlayInstant.ts +12 -0
  344. package/src/layers/rules/reachabilityIcon.ts +18 -0
  345. package/src/layers/rules/readout.ts +102 -0
  346. package/src/layers/stores/layers.ts +262 -0
  347. package/src/map/contracts/contextmenu.ts +33 -0
  348. package/src/map/contracts/geolocate.ts +37 -0
  349. package/src/map/contracts/map.ts +146 -0
  350. package/src/map/contracts/streetview.ts +53 -0
  351. package/src/map/contracts/terrain.ts +152 -0
  352. package/src/map/handlers/contextMenu.ts +135 -0
  353. package/src/map/handlers/geolocate.ts +52 -0
  354. package/src/map/handlers/map.ts +391 -0
  355. package/src/map/handlers/streetview.ts +94 -0
  356. package/src/map/handlers/terrain.ts +663 -0
  357. package/src/map/rules/baseTerrain.ts +75 -0
  358. package/src/map/rules/clickTargets.ts +464 -0
  359. package/src/map/rules/constraints.ts +32 -0
  360. package/src/map/rules/contextMenuReadout.ts +67 -0
  361. package/src/map/rules/coordinates.ts +71 -0
  362. package/src/map/rules/itineraryFit.ts +8 -0
  363. package/src/map/rules/mapEvents.ts +64 -0
  364. package/src/map/rules/mapProjection.ts +476 -0
  365. package/src/map/rules/terrainReading.ts +62 -0
  366. package/src/plugins/contracts/ids.ts +66 -0
  367. package/src/plugins/contracts/plugin.ts +200 -0
  368. package/src/plugins/contracts/slots.ts +137 -0
  369. package/src/plugins/engines/studioPlugin.ts +1365 -0
  370. package/src/plugins/index.ts +111 -0
  371. package/src/plugins/rules/contributions.ts +152 -0
  372. package/src/plugins/rules/errors.ts +60 -0
  373. package/src/plugins/rules/ids.ts +42 -0
  374. package/src/plugins/rules/validation.ts +249 -0
  375. package/src/rules/listeners.ts +57 -0
  376. package/src/rules/origin.ts +13 -0
  377. package/src/rules/storeWrite.ts +37 -0
  378. package/src/rules/types.ts +136 -0
  379. package/src/seams/index.ts +79 -0
  380. package/src/seams/rules/clock.ts +28 -0
  381. package/src/seams/rules/formatters.ts +209 -0
  382. package/src/seams/rules/ids.ts +102 -0
  383. package/src/seams/rules/links.ts +66 -0
  384. package/src/seams/rules/navigation.ts +222 -0
  385. package/src/seams/rules/notify.ts +49 -0
  386. package/src/seams/rules/persistenceDrawer.ts +220 -0
  387. package/src/seams/rules/saveFile.ts +101 -0
  388. package/src/seams/rules/seams.ts +156 -0
  389. package/src/seams/rules/storage.ts +116 -0
  390. package/src/search/contracts/overlay.ts +74 -0
  391. package/src/search/contracts/search.ts +197 -0
  392. package/src/search/handlers/pois.ts +57 -0
  393. package/src/search/handlers/search.ts +280 -0
  394. package/src/search/rules/params.ts +925 -0
  395. package/src/search/rules/poiGroups.ts +138 -0
  396. package/src/search/rules/searchFetch.ts +139 -0
  397. package/src/search/rules/timeWindow.ts +30 -0
  398. package/src/search/stores/search.ts +51 -0
  399. package/src/segments/contracts/itinerary.ts +433 -0
  400. package/src/segments/contracts/segment.ts +35 -0
  401. package/src/segments/engines/segmentDraft.ts +926 -0
  402. package/src/segments/handlers/chainGuards.ts +67 -0
  403. package/src/segments/handlers/directions.ts +44 -0
  404. package/src/segments/handlers/itineraryEcho.ts +45 -0
  405. package/src/segments/handlers/roadAccessDialog.ts +34 -0
  406. package/src/segments/handlers/segment.ts +111 -0
  407. package/src/segments/handlers/segmentEdit.ts +1341 -0
  408. package/src/segments/handlers/segmentGroups.ts +347 -0
  409. package/src/segments/handlers/segmentStructure.ts +1144 -0
  410. package/src/segments/rules/chain.ts +196 -0
  411. package/src/segments/rules/chainModel.ts +217 -0
  412. package/src/segments/rules/colors.ts +11 -0
  413. package/src/segments/rules/commit.ts +76 -0
  414. package/src/segments/rules/draft.ts +90 -0
  415. package/src/segments/rules/draftDisposition.ts +43 -0
  416. package/src/segments/rules/draftSegmentEdit.ts +129 -0
  417. package/src/segments/rules/engine.ts +222 -0
  418. package/src/segments/rules/groupSave.ts +234 -0
  419. package/src/segments/rules/hazardPrompt.ts +60 -0
  420. package/src/segments/rules/itineraryEcho.ts +40 -0
  421. package/src/segments/rules/liveSegmentProjection.ts +55 -0
  422. package/src/segments/rules/merge.ts +51 -0
  423. package/src/segments/rules/metrics.ts +456 -0
  424. package/src/segments/rules/naming.ts +168 -0
  425. package/src/segments/rules/segmentArming.ts +144 -0
  426. package/src/segments/rules/splitPick.ts +84 -0
  427. package/src/segments/rules/viaSimplify.ts +230 -0
  428. package/src/segments/stores/directions.ts +77 -0
  429. package/src/segments/stores/roadAccessDialog.ts +58 -0
  430. package/src/segments/stores/segmentEdit.ts +922 -0
  431. package/src/segments/stores/segmentGroupEdit.ts +84 -0
  432. package/src/segments/stores/segmentSplit.ts +77 -0
  433. package/src/share/contracts/share.ts +39 -0
  434. package/src/share/contracts/shareLink.ts +63 -0
  435. package/src/share/engines/shareLink.ts +1053 -0
  436. package/src/share/handlers/share.ts +47 -0
  437. package/src/share/handlers/shareLink.ts +231 -0
  438. package/src/share/handlers/shareScope.ts +54 -0
  439. package/src/share/rules/link.ts +89 -0
  440. package/src/share/rules/shareLink.ts +218 -0
  441. package/src/share/rules/targets.ts +92 -0
  442. package/src/share/rules/viewConfig.ts +95 -0
  443. package/src/share/stores/share.ts +58 -0
  444. package/src/strings/fr/index.ts +18 -0
  445. package/src/strings/fr/rules/fr.ts +2368 -0
  446. package/src/strings/index.ts +98 -0
  447. package/src/strings/rules/confirmCopy.ts +156 -0
  448. package/src/strings/rules/draftToolNames.ts +94 -0
  449. package/src/strings/rules/en.ts +2519 -0
  450. package/src/strings/rules/failureAlert.ts +115 -0
  451. package/src/strings/rules/formError.ts +400 -0
  452. package/src/strings/rules/maneuvers.ts +107 -0
  453. package/src/strings/rules/outputOptions.ts +126 -0
  454. package/src/strings/rules/publicationState.ts +100 -0
  455. package/src/strings/rules/routeHazardCopy.ts +62 -0
  456. package/src/strings/rules/searchLabels.ts +50 -0
  457. package/src/strings/rules/segmentChainVerbs.ts +62 -0
  458. package/src/strings/rules/studioCopy.ts +130 -0
  459. package/src/strings/rules/unitOptions.ts +119 -0
  460. package/src/testing/checkedBus.ts +226 -0
  461. package/src/testing/index.ts +34 -0
  462. package/src/testing/plugins.ts +106 -0
  463. package/src/testing/studio.ts +267 -0
  464. package/src/testing/urlSeam.ts +153 -0
  465. package/src/time/index.ts +12 -0
  466. package/src/time/rules/sun.ts +78 -0
  467. package/src/video/contracts/cameraSchemas.ts +266 -0
  468. package/src/video/contracts/profileSchemas.ts +37 -0
  469. package/src/video/contracts/video.ts +601 -0
  470. package/src/video/handlers/video.ts +1638 -0
  471. package/src/video/handlers/videoDirector.ts +114 -0
  472. package/src/video/rules/previewRefresh.ts +76 -0
  473. package/src/video/rules/profileSource.ts +51 -0
  474. package/src/video/rules/routeSpans.ts +79 -0
  475. package/src/video/rules/shotDefaults.ts +28 -0
  476. package/src/video/rules/stepOrder.ts +17 -0
  477. package/src/video/rules/videoSnapshot.ts +136 -0
  478. package/src/video/stores/directorThreads.ts +167 -0
  479. package/src/video/stores/videoExport.ts +290 -0
  480. package/src/viewer/contracts/preferences.ts +40 -0
  481. package/src/viewer/handlers/preferences.ts +91 -0
  482. package/src/viewer/rules/capabilities.ts +42 -0
  483. package/src/viewer/rules/config.ts +266 -0
  484. package/src/viewer/rules/context.ts +375 -0
  485. package/src/viewer/rules/ownership.ts +134 -0
  486. package/src/viewer/rules/platformViewer.ts +198 -0
  487. package/src/viewer/rules/scope.ts +197 -0
  488. package/src/viewer/rules/url.ts +145 -0
  489. package/src/viewer/rules/viewer.ts +307 -0
  490. package/src/viewer/rules/viewerSeam.ts +49 -0
  491. package/src/viewer/rules/viewerUnits.ts +34 -0
  492. package/src/waypoints/contracts/itinerary.ts +417 -0
  493. package/src/waypoints/handlers/poiWaypointStyle.ts +32 -0
  494. package/src/waypoints/handlers/waypointDetailsDialog.ts +38 -0
  495. package/src/waypoints/handlers/waypointEdit.ts +1073 -0
  496. package/src/waypoints/rules/amenities.ts +30 -0
  497. package/src/waypoints/rules/defaults.ts +31 -0
  498. package/src/waypoints/rules/details.ts +213 -0
  499. package/src/waypoints/rules/detailsDraft.ts +312 -0
  500. package/src/waypoints/rules/detailsPreview.ts +76 -0
  501. package/src/waypoints/rules/detailsSave.ts +356 -0
  502. package/src/waypoints/rules/draftDirty.ts +45 -0
  503. package/src/waypoints/rules/icons.ts +32 -0
  504. package/src/waypoints/rules/liveWaypoint.ts +63 -0
  505. package/src/waypoints/rules/naming.ts +185 -0
  506. package/src/waypoints/rules/sections.ts +77 -0
  507. package/src/waypoints/rules/waypointDraft.ts +62 -0
  508. package/src/waypoints/stores/waypointDetails.ts +62 -0
  509. package/src/waypoints/stores/waypointEdit.ts +566 -0
  510. package/src/zones/contracts/collection.ts +37 -0
  511. package/src/zones/contracts/zone.ts +528 -0
  512. package/src/zones/engines/zoneForm.ts +1773 -0
  513. package/src/zones/handlers/restZones.ts +287 -0
  514. package/src/zones/handlers/zonePublish.ts +206 -0
  515. package/src/zones/handlers/zoneUnpublish.ts +56 -0
  516. package/src/zones/handlers/zones.ts +2254 -0
  517. package/src/zones/rules/geometry.ts +946 -0
  518. package/src/zones/rules/zoneDefaults.ts +34 -0
  519. package/src/zones/rules/zoneDraft.ts +54 -0
  520. package/src/zones/rules/zoneForm.ts +563 -0
  521. package/src/zones/rules/zoneMetadata.ts +29 -0
  522. package/src/zones/rules/zoneSource.ts +87 -0
  523. package/src/zones/rules/zoneSourceRefusal.ts +104 -0
  524. package/src/zones/stores/zoneEdit.ts +998 -0
@@ -0,0 +1,1329 @@
1
+ import {
2
+ type ItineraryWithDetails,
3
+ segmentGeometries,
4
+ segmentsForSelection,
5
+ } from "@mountaya/elements/data";
6
+ import { boundsOf } from "@mountaya/elements/geo";
7
+ import type {
8
+ BoundingBox,
9
+ FitBoundsPadding,
10
+ MapClient,
11
+ MapConstraints,
12
+ } from "@mountaya/elements/map-client";
13
+ import { type EmbedProfileSections, embedFitPadding } from "@mountaya/elements/profile";
14
+
15
+ import { ITINERARY_FIT_MAX_ZOOM } from "../../map/rules/itineraryFit.js";
16
+ import { notifyListeners, surfaceFault } from "../../rules/listeners.js";
17
+ import {
18
+ type EmbedCanvasSize,
19
+ type EmbedConstraintsInput,
20
+ type EmbedZoomRange,
21
+ embedConstraintsFor,
22
+ measuredCanvas,
23
+ } from "../rules/embedConstraints.js";
24
+
25
+ /**
26
+ * EmbedFramingCollection is a collection an embed frames: its id, and the extent of the
27
+ * itineraries its tiles draw, as the collection's specification states it (`bbox`).
28
+ */
29
+ export interface EmbedFramingCollection {
30
+ /**
31
+ * The extent, `[west, south, east, north]`: the box the collection's specification answers for
32
+ * the credential and the surface its tiles are asked with.
33
+ */
34
+ readonly bounds: BoundingBox;
35
+ /** The collection's id, which tells one collection's framing from the next one's. */
36
+ readonly id: string;
37
+ }
38
+
39
+ /**
40
+ * EmbedFramingConfig is what an embed's initial framing runs against, all of it replaceable
41
+ * mid-life through {@link EmbedFramingEngine.configure}.
42
+ */
43
+ export interface EmbedFramingConfig {
44
+ /**
45
+ * The size of the map's canvas, or null while it is unmeasured: the size a fit frames. It
46
+ * sizes the pan lock from the view the embed opens on (see `embedConstraintsFor`). A change
47
+ * while a fit is on its way frames again with it, except a change to a canvas that measures
48
+ * nothing (null, or no area): there is nothing to frame on one, so the fit on its way stands,
49
+ * and a canvas that comes back at the size it had asks nothing new. Another input that changes
50
+ * while the canvas measures nothing is a question of its own: under no size at all it is
51
+ * framed as it stands, and under a canvas with no area no fit starts for it, so the canvas that
52
+ * comes back is the one framed. The fit on its way then settles nothing if it lands first: it
53
+ * framed the inputs as they were. A change that can start no fit (after the settle, under a
54
+ * publisher's own view, or while the next itinerary loads) moves no camera: the pan lock alone
55
+ * is widened for a canvas that outgrew it, and it is never tightened for one that shrank.
56
+ *
57
+ * An embed that opens on a canvas with no area, a frame the page has laid out and not shown,
58
+ * starts no fit and settles nothing: a renderer gives such a container a canvas of its own
59
+ * default size, and a fit would frame that. The organization's zoom range applies at once, and
60
+ * the itinerary is framed in the first canvas with an area. Null is another statement: a host
61
+ * that measures no canvas at all is framed at once, as it stands.
62
+ *
63
+ * WHEN a host hands a size over decides what the renderer makes of it, and the two uses want
64
+ * opposite orders. A fit frames the canvas the renderer holds, so a size that frames again is
65
+ * handed over once the renderer has resized: earlier, the fit frames the canvas as it was. The
66
+ * renderer enforces the lock as IT resizes, so a size that widens a lock is handed over before
67
+ * the renderer has resized: later, the lock is widened under a camera the renderer has
68
+ * already zoomed in. One size cannot arrive at both moments. A host that learns a size ahead
69
+ * of the renderer states it as {@link EmbedFramingConfig.lockCanvasSize}, and states it here
70
+ * once the renderer has resized to it.
71
+ */
72
+ readonly canvasSize: EmbedCanvasSize | null;
73
+ /**
74
+ * The map client the embed frames and locks, or null while there is no map, in which case
75
+ * nothing is framed.
76
+ *
77
+ * Required even so, because an engine without a client is silent: a key the caller has to write
78
+ * makes forgetting it a compile error rather than an embed that never frames. Compared by
79
+ * identity: a replaced client is framed and locked afresh.
80
+ */
81
+ readonly client: MapClient | null;
82
+ /**
83
+ * The collection the embed frames while no itinerary is active or expected, or null when there
84
+ * is none to frame: no collection is configured, its specification has not answered, or it
85
+ * answered no extent (a `bbox` that is null or absent, since its tiles draw no itinerary). An
86
+ * itinerary wins over it: while one is active or expected, the collection is not framed.
87
+ *
88
+ * It is framed as an itinerary is, through `fitCollection`, with the same padding and the same
89
+ * zoom ceiling, and once: a collection that stays the one stated is not framed again after its
90
+ * view settled, whatever extent a later answer states. A content switch to another collection,
91
+ * or back to the same one after an itinerary, is framed in its turn. Compared by value: the id
92
+ * and the four edges.
93
+ *
94
+ * Read only with `fitCollection` stated: a configuration that states none frames no collection.
95
+ *
96
+ * @default No collection: the embed frames an itinerary, or the base map alone.
97
+ */
98
+ readonly collection?: EmbedFramingCollection | null | undefined;
99
+ /**
100
+ * The id of the itinerary the embed is configured with, or null for an embed of the base map
101
+ * alone. A change of it while no itinerary is active is a content switch owed one settle,
102
+ * whatever `expectsItinerary` says: the base map's, on its next paint, when no itinerary is
103
+ * expected, and otherwise the settle the expectation ends on, the itinerary's framing or the
104
+ * base map's. So a host that already holds the failure of the itinerary it switches to, and
105
+ * never expects one, still hears how the switch ended. A change made while the base map's
106
+ * settle is on its way shares that settle. While an itinerary is active the switch is read off
107
+ * `itinerary`, and a change here settles nothing by itself.
108
+ *
109
+ * The id's change and `expectsItinerary` each signal a switch, and they are one settle only
110
+ * when one configure brings both. An expectation that rises in a later configure, once the
111
+ * base map has started to settle for the id's change, is a wait of its own and is owed its own
112
+ * settle: a host whose data layer shows the failure it holds and then fetches again hears a
113
+ * report for each, the first of them possibly while the itinerary is expected. Such a host
114
+ * raises `expectsItinerary` in the configure that brings the id.
115
+ *
116
+ * @default No id is stated: a content switch is read off `itinerary` and `expectsItinerary`
117
+ * alone, so one that changes neither settles nothing.
118
+ */
119
+ readonly configuredItineraryId?: string | null | undefined;
120
+ /**
121
+ * Whether a collection will frame this embed: one is configured and its specification has not
122
+ * answered yet. While it holds and nothing is framed, the settle waits for the collection as it
123
+ * waits for an expected itinerary (see `expectsItinerary`), except on the cold load of a map a
124
+ * publisher's own view frames. An expectation that ends with no collection to frame (the read
125
+ * failed, or it answered no extent) settles the base map again, so a host hears how it ended.
126
+ *
127
+ * Read only with `fitCollection` stated.
128
+ *
129
+ * @default false
130
+ */
131
+ readonly expectsCollection?: boolean | undefined;
132
+ /**
133
+ * Whether an itinerary will frame this embed: one is configured and its detail has not failed to
134
+ * load. While it holds and no itinerary is active, the settle waits for one, except on the cold
135
+ * load of a map a publisher's own view frames; otherwise the view settles on the map's next
136
+ * paint. An expectation that ends with no itinerary (its detail failed to load) settles the base
137
+ * map again, so a host hears how the switch ended.
138
+ *
139
+ * A flag the host states rather than one read off the active itinerary, so the moment between
140
+ * the itinerary's detail arriving and the store activating it never settles an off-route view.
141
+ */
142
+ readonly expectsItinerary: boolean;
143
+ /**
144
+ * Frames the whole active itinerary with `padding`, at once rather than animated, so the first
145
+ * painted frame is already the route. It goes through the bus in a studio
146
+ * (`studio.map.fitBoundsToSegment` with a null segment), the one camera mutation surface, and
147
+ * resolves once the camera has moved. Read when a framing starts.
148
+ */
149
+ readonly fit: (padding: FitBoundsPadding) => Promise<void>;
150
+ /**
151
+ * Frames `bounds`, the collection's extent, with `padding` and no closer than `maxZoom`, at once
152
+ * rather than animated: the collection's twin of `fit`, under the zoom ceiling an itinerary's
153
+ * fit holds. It goes through the bus in a studio (`studio.map.fitBounds` with `animate: false`),
154
+ * and resolves once the camera has moved. Read when a framing of the collection starts.
155
+ *
156
+ * @default No collection is framed: `collection` and `expectsCollection` are read as absent.
157
+ */
158
+ readonly fitCollection?:
159
+ | ((bounds: BoundingBox, padding: FitBoundsPadding, maxZoom: number) => Promise<void>)
160
+ | undefined;
161
+ /** The itinerary the store has active, or null while none is. */
162
+ readonly itinerary: ItineraryWithDetails | null;
163
+ /**
164
+ * The size the page has laid the canvas out at, or null while it is unmeasured, for a host
165
+ * that learns it before the renderer has resized to it. The pan lock is widened from it and no
166
+ * fit ever frames it: the lock covers the wider and the taller of this size and `canvasSize`,
167
+ * so the renderer resizes inside a lock already sized for the canvas it grows to.
168
+ *
169
+ * While it measures a canvas `canvasSize` does not state, a resize is under way: the renderer
170
+ * has yet to resize, and `canvasSize` has yet to follow. A fit asked for then would frame the
171
+ * canvas as it was, so none starts, and one already on its way settles nothing when it
172
+ * paints. The framing runs once the two sizes agree, on the canvas the renderer holds by then,
173
+ * so the view settles on the fit of the last canvas. A host that states this size therefore
174
+ * states the same one as `canvasSize` once the renderer has resized, or a fitted itinerary
175
+ * never settles: the organization's zoom range and the lock of the last framing are all that
176
+ * stand on the map meanwhile. Under a publisher's own view no fit reads the canvas, and nothing
177
+ * waits.
178
+ *
179
+ * @default The size `canvasSize` states: the pan lock is widened when `canvasSize` changes,
180
+ * and no resize is ever under way.
181
+ */
182
+ readonly lockCanvasSize?: EmbedCanvasSize | null | undefined;
183
+ /**
184
+ * The docked elevation profile's measured height, in CSS pixels, or null before it is measured
185
+ * or when no profile is docked. It sizes the fit's bottom inset (`embedFitPadding`), and a change
186
+ * before the framing has settled frames again with it.
187
+ */
188
+ readonly measuredPanelHeight: number | null;
189
+ /**
190
+ * Receives each settle of the initial view, framed on the `[west, south, east, north]` extent
191
+ * of the itinerary or the collection that frames it, or null when neither does. An embed lifts
192
+ * its loading cover and posts its ready event from it (see `EmbedReadyEngine`). Read when a
193
+ * framing settles. One that throws stops nothing: the settle stands, and its fault reaches the
194
+ * program as an uncaught error on a microtask.
195
+ */
196
+ readonly onFramed?: ((bounds: BoundingBox | null) => void) | undefined;
197
+ /** The profile sections the embed docks, which size the fit's bottom inset. */
198
+ readonly sections: EmbedProfileSections;
199
+ /**
200
+ * The organization's zoom range. One that changes, or first arrives, is applied at once,
201
+ * whatever stands on the map: with the next framing, or over the framing that stands, at the
202
+ * floor that framing lowered and with no fit. One that leaves is released the same way: a
203
+ * configuration that states no range over a map this engine wrote one to hands the map a null
204
+ * for each end, which gives it back its own window.
205
+ */
206
+ readonly zoomRange: EmbedZoomRange;
207
+ }
208
+
209
+ /**
210
+ * EmbedFramingSnapshot is what an {@link EmbedFramingEngine} answers: whether the initial view of
211
+ * what the embed frames (the active itinerary, the collection, or the base map alone) has
212
+ * settled, and on what.
213
+ *
214
+ * It names what it answers for, so a reader holding a snapshot never takes one content's framing
215
+ * for the next one's: after a content switch it reads unframed, under the new id, until the new
216
+ * framing settles. Both ids are null for the base map alone.
217
+ */
218
+ export interface EmbedFramingSnapshot {
219
+ /**
220
+ * The extent the view was framed on, the itinerary's or the collection's, or null while
221
+ * unframed or with none to frame.
222
+ */
223
+ readonly bounds: BoundingBox | null;
224
+ /** The collection the answer is for: the one framed while no itinerary is, or null. */
225
+ readonly collectionId: string | null;
226
+ /**
227
+ * Whether the initial view has painted: after the framing fit or, with no fit to wait for, on
228
+ * the map's next paint.
229
+ */
230
+ readonly framed: boolean;
231
+ /** The itinerary the answer is for: the active one, or null while none is. */
232
+ readonly itineraryId: string | null;
233
+ }
234
+
235
+ /**
236
+ * ContentKey names what one framing answers for: the active itinerary, or the collection framed
237
+ * while no itinerary is active or expected. Both null is the base map alone.
238
+ */
239
+ interface ContentKey {
240
+ readonly collectionId: string | null;
241
+ readonly itineraryId: string | null;
242
+ }
243
+
244
+ /** baseMapContent is the key of the base map alone: no itinerary and no collection frames it. */
245
+ const baseMapContent: ContentKey = { collectionId: null, itineraryId: null };
246
+
247
+ /** sameContent reports whether two keys name the same content. */
248
+ const sameContent = (a: ContentKey, b: ContentKey): boolean =>
249
+ a.collectionId === b.collectionId && a.itineraryId === b.itineraryId;
250
+
251
+ /** isBaseMap reports whether a key names the base map alone. */
252
+ const isBaseMap = (content: ContentKey): boolean => sameContent(content, baseMapContent);
253
+
254
+ /**
255
+ * collectionOf reads the collection a configuration frames when no itinerary does, or null: a
256
+ * collection is read only with the fit that frames it.
257
+ */
258
+ const collectionOf = (config: EmbedFramingConfig): EmbedFramingCollection | null =>
259
+ config.fitCollection === undefined ? null : (config.collection ?? null);
260
+
261
+ /**
262
+ * expectsCollectionOf reports whether a configuration waits for a collection: one is expected,
263
+ * and read with the fit that frames it.
264
+ */
265
+ const expectsCollectionOf = (config: EmbedFramingConfig): boolean =>
266
+ config.fitCollection !== undefined && config.expectsCollection === true;
267
+
268
+ /** expectsContent reports whether a configuration waits for an itinerary or a collection. */
269
+ const expectsContent = (config: EmbedFramingConfig): boolean =>
270
+ config.expectsItinerary || expectsCollectionOf(config);
271
+
272
+ /**
273
+ * contentOf reads what a configuration frames: the active itinerary, else the collection while no
274
+ * itinerary is expected, else the base map alone. An itinerary expected and still loading wins
275
+ * over the collection, so nothing is framed while it loads.
276
+ */
277
+ const contentOf = (config: EmbedFramingConfig): ContentKey => {
278
+ if (config.itinerary !== null) {
279
+ return { collectionId: null, itineraryId: config.itinerary.id };
280
+ }
281
+
282
+ const collection = collectionOf(config);
283
+
284
+ return collection === null || config.expectsItinerary
285
+ ? baseMapContent
286
+ : { collectionId: collection.id, itineraryId: null };
287
+ };
288
+
289
+ /**
290
+ * FramingQuestion is every input one framing is decided from. A change to any of them before the
291
+ * framing settles frames again; the callbacks are read when they are used and are not part of it.
292
+ */
293
+ interface FramingQuestion {
294
+ readonly canvasHeight: number | null;
295
+ readonly canvasWidth: number | null;
296
+ readonly client: MapClient;
297
+ readonly collectionBounds: BoundingBox | null;
298
+ readonly collectionId: string | null;
299
+ readonly expectsCollection: boolean;
300
+ readonly expectsItinerary: boolean;
301
+ readonly itinerary: ItineraryWithDetails | null;
302
+ readonly lockHeight: number | null;
303
+ readonly lockWidth: number | null;
304
+ readonly measuredPanelHeight: number | null;
305
+ readonly showAnalysis: boolean;
306
+ readonly showCharacteristics: boolean;
307
+ readonly showElevation: boolean;
308
+ readonly zoomMax: number | undefined;
309
+ readonly zoomMin: number | undefined;
310
+ }
311
+
312
+ /**
313
+ * lockSizeOf reads the size a configuration widens its pan lock from: its `lockCanvasSize`, or
314
+ * its `canvasSize` when it states none.
315
+ */
316
+ const lockSizeOf = (config: EmbedFramingConfig): EmbedCanvasSize | null =>
317
+ config.lockCanvasSize === undefined ? config.canvasSize : config.lockCanvasSize;
318
+
319
+ /** questionOf reads the framing question a configuration asks, on the client it names. */
320
+ const questionOf = (config: EmbedFramingConfig, client: MapClient): FramingQuestion => ({
321
+ canvasHeight: config.canvasSize?.height ?? null,
322
+ canvasWidth: config.canvasSize?.width ?? null,
323
+ client,
324
+ collectionBounds: collectionOf(config)?.bounds ?? null,
325
+ collectionId: collectionOf(config)?.id ?? null,
326
+ expectsCollection: expectsCollectionOf(config),
327
+ expectsItinerary: config.expectsItinerary,
328
+ itinerary: config.itinerary,
329
+ lockHeight: lockSizeOf(config)?.height ?? null,
330
+ lockWidth: lockSizeOf(config)?.width ?? null,
331
+ measuredPanelHeight: config.measuredPanelHeight,
332
+ showAnalysis: config.sections.showAnalysis,
333
+ showCharacteristics: config.sections.showCharacteristics,
334
+ showElevation: config.sections.showElevation,
335
+ zoomMax: config.zoomRange.zoomMax,
336
+ zoomMin: config.zoomRange.zoomMin,
337
+ });
338
+
339
+ /**
340
+ * sameQuestion reports whether two framings would be decided from the same inputs. The numbers are
341
+ * compared with `Object.is`: a size that is not a number equals itself, where `===` would read it
342
+ * as a change on every configure and fit again each time. A collection is compared by its id and
343
+ * its four edges, so a host that states the same one afresh on every render frames it once.
344
+ */
345
+ const sameQuestion = (a: FramingQuestion, b: FramingQuestion): boolean =>
346
+ a.client === b.client &&
347
+ a.itinerary === b.itinerary &&
348
+ a.expectsItinerary === b.expectsItinerary &&
349
+ a.collectionId === b.collectionId &&
350
+ sameLock(a.collectionBounds, b.collectionBounds) &&
351
+ a.expectsCollection === b.expectsCollection &&
352
+ Object.is(a.measuredPanelHeight, b.measuredPanelHeight) &&
353
+ Object.is(a.canvasWidth, b.canvasWidth) &&
354
+ Object.is(a.canvasHeight, b.canvasHeight) &&
355
+ Object.is(a.lockWidth, b.lockWidth) &&
356
+ Object.is(a.lockHeight, b.lockHeight) &&
357
+ a.showAnalysis === b.showAnalysis &&
358
+ a.showCharacteristics === b.showCharacteristics &&
359
+ a.showElevation === b.showElevation &&
360
+ Object.is(a.zoomMax, b.zoomMax) &&
361
+ Object.is(a.zoomMin, b.zoomMin);
362
+
363
+ /** sameSize reports whether two canvas sizes are one size, or both unmeasured. */
364
+ const sameSize = (a: EmbedCanvasSize | null, b: EmbedCanvasSize | null): boolean =>
365
+ a === null || b === null ? a === b : Object.is(a.width, b.width) && Object.is(a.height, b.height);
366
+
367
+ /**
368
+ * largestOf is the canvas as wide as the wider and as tall as the taller of two sizes, or null
369
+ * when neither measures anything. A size that measures nothing counts for nothing.
370
+ */
371
+ const largestOf = (
372
+ a: EmbedCanvasSize | null,
373
+ b: EmbedCanvasSize | null,
374
+ ): EmbedCanvasSize | null => {
375
+ const first = measuredCanvas(a);
376
+ const second = measuredCanvas(b);
377
+
378
+ if (first === null || second === null) {
379
+ return first ?? second;
380
+ }
381
+
382
+ return {
383
+ height: Math.max(first.height, second.height),
384
+ width: Math.max(first.width, second.width),
385
+ };
386
+ };
387
+
388
+ /**
389
+ * laidOutAtNoArea reports whether a size states a canvas the page has laid out and given no
390
+ * area: a width and a height that are numbers, one of them zero or less. Not for no size at
391
+ * all, and not for a size that is not a number, each of which is no measurement of a layout.
392
+ */
393
+ const laidOutAtNoArea = (size: EmbedCanvasSize | null): boolean =>
394
+ size !== null &&
395
+ Number.isFinite(size.width) &&
396
+ Number.isFinite(size.height) &&
397
+ (size.width <= 0 || size.height <= 0);
398
+
399
+ /** isEmpty reports whether a set of constraints decides nothing, so applying it would be a no-op. */
400
+ const isEmpty = (constraints: MapConstraints): boolean =>
401
+ constraints.maxBounds === undefined &&
402
+ constraints.maxZoom === undefined &&
403
+ constraints.minZoom === undefined;
404
+
405
+ /** sameLock reports whether two pan locks are one box, or both the release of one. */
406
+ const sameLock = (a: BoundingBox | null | undefined, b: BoundingBox | null | undefined): boolean =>
407
+ a === null || a === undefined || b === null || b === undefined
408
+ ? a === b
409
+ : a.every((edge, index) => Object.is(edge, b[index]));
410
+
411
+ /**
412
+ * standsAs reports whether every constraint `decided` states already stands on the map as
413
+ * `applied` left it. A member `decided` leaves out asks for nothing, so it is the same as any.
414
+ */
415
+ const standsAs = (decided: MapConstraints, applied: MapConstraints): boolean =>
416
+ (decided.maxBounds === undefined || sameLock(decided.maxBounds, applied.maxBounds)) &&
417
+ (decided.maxZoom === undefined || Object.is(decided.maxZoom, applied.maxZoom)) &&
418
+ (decided.minZoom === undefined || Object.is(decided.minZoom, applied.minZoom));
419
+
420
+ /** sameRange reports whether two zoom ranges state the same ends. */
421
+ const sameRange = (a: EmbedZoomRange, b: EmbedZoomRange): boolean =>
422
+ Object.is(a.zoomMax, b.zoomMax) && Object.is(a.zoomMin, b.zoomMin);
423
+
424
+ /**
425
+ * A settle on its way: the content it answers for (both ids null for the base map alone) and the
426
+ * bounds it reports. Compared by identity, so a settle that was replaced or dropped reports
427
+ * nothing: a settle for an itinerary cleared before it painted is dropped.
428
+ */
429
+ interface Pending extends ContentKey {
430
+ readonly bounds: BoundingBox | null;
431
+ }
432
+
433
+ /**
434
+ * The constraints standing on a client from the last itinerary or collection framed on it: the
435
+ * content they were decided for, and what they were decided from. Kept so a canvas that outgrows
436
+ * its lock is locked again from the same camera, and so an itinerary still loading leaves them in
437
+ * place.
438
+ */
439
+ interface Standing {
440
+ readonly content: ContentKey;
441
+ readonly input: EmbedConstraintsInput;
442
+ }
443
+
444
+ /**
445
+ * EmbedFramingEngine is the machine behind an embed's initial framing: it frames the active
446
+ * itinerary, or the collection an embed of one is configured with, locks the camera to it, and
447
+ * reports when the initial view has painted, so the embed's loading cover never shows a visitor
448
+ * the map's default, off-route centre.
449
+ *
450
+ * A collection is framed as an itinerary is. While no itinerary is active or expected, the
451
+ * collection's extent (`collection`, the `bbox` its specification answers) is what the embed
452
+ * frames: fitted through `fitCollection` with the same padding and under the same zoom ceiling,
453
+ * locked to, deferred to a publisher's own view, and reported on its extent, once per
454
+ * collection. While its specification has not answered (`expectsCollection`) the settle waits for
455
+ * it, and an answer with no extent leaves the base map alone, which settles as it does with
456
+ * nothing to frame. What follows says "itinerary" for either, a content switch included, except
457
+ * where `configuredItineraryId` and a failed detail are concerned, which are the itinerary's own.
458
+ *
459
+ * What it does, in the order a cold load meets it:
460
+ *
461
+ * - **Constraints.** As soon as a client is set, the organization's zoom range is applied; once
462
+ * the itinerary is active, the pan lock too, both decided by `embedConstraintsFor` and handed to
463
+ * `client.setConstraints` in one call. Constraints that already stand on the map as decided
464
+ * are not written again, so a step that decides nothing new costs the renderer nothing.
465
+ * - **Framing.** The whole itinerary is framed through `fit`, with the profile-aware padding
466
+ * `embedFitPadding` sizes to the docked profile, unless the map was built with a publisher's own
467
+ * `#view` (`client.hadInitialViewHash()`), which the embed defers to. The camera the fit lands on
468
+ * (`client.cameraForBounds` under the same ceiling, `ITINERARY_FIT_MAX_ZOOM`) lowers the zoom
469
+ * floor for a short viewport and sizes the pan lock. Under a publisher's own view the lock is
470
+ * sized from the camera the map shows (`client.getViewport()`) and the itinerary together, so it
471
+ * never zooms that view in.
472
+ * - **The settle.** The view has settled on the first render after the fit
473
+ * (`client.waitForRender()`), not merely once the fit is dispatched, so the cover lifts on the
474
+ * painted framing. With nothing to fit (an embed of the base map alone, an itinerary that failed
475
+ * to load, a publisher's own view) it settles on the map's next render instead. Each settle is
476
+ * reported once, through `onFramed` and the snapshot.
477
+ *
478
+ * The framing is the INITIAL view only. Before it settles, a change to what it is decided from (a
479
+ * measured profile height, a measured canvas, the itinerary's detail arriving again) frames again
480
+ * and the earlier fit's settle is dropped, so the cover lifts on the final framing. After it
481
+ * settles, nothing reframes that itinerary while it stays active, so a visitor's own pan, tilt or
482
+ * zoom is never pulled back to the route.
483
+ *
484
+ * The pan lock grows with the canvas for as long as it stands. A canvas that grows after the
485
+ * settle, at any moment under a publisher's own view, or while the next itinerary loads under
486
+ * the lock of the outgoing one, shows more ground at the same camera, so the lock alone is
487
+ * applied again, sized from the same camera on the larger canvas: no fit, no report, and the
488
+ * zoom range is left as the framing set it. It never shrinks back: a lock tightened ahead of the
489
+ * renderer's own resize would be narrower than the canvas the renderer still holds, and zoom the
490
+ * camera in. See {@link EmbedFramingConfig.canvasSize} for when a host hands the size over.
491
+ *
492
+ * That is a choice, and it has two costs. A reader of a frame that left full screen keeps the
493
+ * full screen's lock, so they can pan and zoom out as far as it allowed: tightening it would
494
+ * take a second step once the renderer has resized, and a lock looser than the canvas harms
495
+ * nothing. And under a publisher's own view, a host that measures its canvas after the first
496
+ * step gets the bare route's lock until the size arrives, which can zoom that view in for a
497
+ * moment: such a host states the size with the client, as `MountayaStudioViewer` does.
498
+ *
499
+ * The zoom range follows the configuration for as long as a framing stands. One that changes, or
500
+ * first arrives, after the settle is applied over the standing framing, decided by
501
+ * `embedConstraintsFor` from that framing's own inputs: the ceiling as stated and the floor no
502
+ * higher than the zoom the fit landed on. No fit runs and nothing is reported, so a visitor's
503
+ * camera is moved only when the new floor is above it, and then only up to that floor, which is
504
+ * where the embed would have opened under the same range. The same holds while the next
505
+ * itinerary loads under the outgoing framing.
506
+ *
507
+ * A host that learns of a resize before the renderer states two sizes: `lockCanvasSize`, the
508
+ * canvas the page has laid out, and `canvasSize`, the one the renderer holds. While the first
509
+ * measures a canvas the second does not state, the renderer has yet to resize, and the two uses
510
+ * of a size part ways. The lock is widened for the size ahead at once, whatever stands on the
511
+ * map, the lock of a fit still on its way included, so the renderer never resizes under a lock
512
+ * narrower than its canvas. A fit waits: none starts, and one that paints meanwhile settles
513
+ * nothing, since it framed a canvas that is gone. The zoom range does not wait with it: on a
514
+ * client nothing was framed on it applies at once, as it does while an itinerary loads. The
515
+ * framing runs in full once the two sizes agree, so a burst of resizes ends on one fit, of the
516
+ * last canvas, and that fit is the settle reported. A view no fit moves waits for nothing.
517
+ *
518
+ * A content switch starts over, whichever way the view settles: another active itinerary, or the
519
+ * same one activated again after it was cleared, is framed, locked and reported in its turn. A
520
+ * settle on its way for an itinerary that is switched away from, or cleared, before it painted is
521
+ * dropped, so a report never names an itinerary that is no longer active, and so is the base
522
+ * map's for an itinerary activated before it painted: a switch is one report, whichever drawing
523
+ * lands first. A replaced client starts over too, subscribed to or not. The snapshot is the
524
+ * record: it reads unframed from the switch until that settle.
525
+ *
526
+ * What stands between two itineraries depends on whether another one is expected:
527
+ *
528
+ * - **One is.** The constraints of the last framing stay until the next framing replaces them,
529
+ * and the pan lock among them still follows the canvas. Putting the organization's zoom floor
530
+ * back under a view framed below it would make the renderer zoom the camera in for the length
531
+ * of a load, and under a publisher's own view no fit follows the load to put right a camera
532
+ * zoomed in by a lock the canvas outgrew.
533
+ * - **None is.** The embed is the base map alone: the pan lock is released (a null `maxBounds`,
534
+ * as it is for a next itinerary with no extent to lock to), the organization's zoom range
535
+ * applies as it is, and the view settles again, to be reported.
536
+ * That holds for an itinerary that was cleared and for one that never came: a base-map embed
537
+ * switched to an itinerary whose detail fails to load settles on the base map once more, which
538
+ * is the settle a host hears `"not_found"` from. A switch to an itinerary whose failure the
539
+ * host already holds changes neither `itinerary` nor `expectsItinerary`, so it is read off
540
+ * `configuredItineraryId`: a change of it with no itinerary active and none expected settles
541
+ * the base map once more. The id's change and an expectation each signal a switch, and they
542
+ * are one settle only when one configure brings both (see
543
+ * {@link EmbedFramingConfig.configuredItineraryId}).
544
+ *
545
+ * Under a publisher's own view no fit will move the camera, so the cold load does not wait for the
546
+ * itinerary: the first settle on a client is the map's next render, whatever is active then. While
547
+ * the itinerary's detail is still loading that is the base map, reported with null bounds, and
548
+ * the itinerary settles in its turn, on its own extent, once it is active; an itinerary active
549
+ * before that first render lands takes its place, so the two are reported as one settle. After
550
+ * that first settle a content switch waits for its itinerary, as a fitted one does, so the
551
+ * switch is reported on its itinerary and not on the base map first.
552
+ *
553
+ * It reads the itinerary and the collection it is handed and never writes a store: the camera
554
+ * moves through `fit` and `fitCollection` and the constraints through the client, so the tool bus
555
+ * stays the one mutation surface.
556
+ *
557
+ * It holds no timer and takes no `Clock`: it waits on the map's own paint, never on time.
558
+ *
559
+ * A host's `onFramed` that throws, and a listener that throws, stop neither the engine nor the
560
+ * listeners after it: the settle is the engine's to complete, and a throw left to travel would
561
+ * surface as an unhandled rejection from the paint the settle waited on, or as a `configure`
562
+ * that failed. The fault leaves through `surfaceFault` and `notifyListeners`: an uncaught error
563
+ * on a microtask, for the program that handed the callback over.
564
+ *
565
+ * The lifecycle is the listeners. Constructing one touches no client; the first subscriber frames
566
+ * the current configuration; the last unsubscribe parks: a settle that arrives while parked is
567
+ * dropped, with or without a fit, and the next subscriber settles again what it left unsettled.
568
+ * React's StrictMode mounts, unmounts and mounts again before a fit can settle, which parks and
569
+ * resumes and leaves one fit in flight and one settle. `dispose()` is the latch, for an owner that
570
+ * is not a component.
571
+ *
572
+ * @example
573
+ * ```ts
574
+ * declare const client: MapClient;
575
+ * declare const ready: EmbedReadyEngine;
576
+ *
577
+ * const framing = new EmbedFramingEngine({
578
+ * canvasSize: { height: 480, width: 800 },
579
+ * client,
580
+ * expectsItinerary: true,
581
+ * fit: (padding) =>
582
+ * bus
583
+ * .dispatch(ctx, "studio.map.fitBoundsToSegment", { animate: false, padding, segmentId: null })
584
+ * .then(() => undefined),
585
+ * itinerary: store.getState().activeItinerary,
586
+ * measuredPanelHeight: null,
587
+ * onFramed: (bounds) => ready.settle(bounds),
588
+ * sections: { showAnalysis: true, showCharacteristics: true, showElevation: true },
589
+ * zoomRange: { zoomMax: 14, zoomMin: 9 },
590
+ * });
591
+ * const release = framing.subscribe(() => undefined);
592
+ * ```
593
+ */
594
+ export class EmbedFramingEngine {
595
+ private config: EmbedFramingConfig;
596
+
597
+ private snapshot: EmbedFramingSnapshot;
598
+ private readonly listeners = new Set<() => void>();
599
+
600
+ /** The client the framing below was made on; a replaced one starts from nothing. */
601
+ private framingClient: MapClient | null = null;
602
+ /** The question the last framing step answered, or null when the next step must run in full. */
603
+ private asked: FramingQuestion | null = null;
604
+ /** The fit waiting for its paint, or null. */
605
+ private pendingFit: Pending | null = null;
606
+ /** The settle with no fit waiting for its paint, or null. */
607
+ private pendingReveal: Pending | null = null;
608
+ /**
609
+ * Whether a settle has been reported on {@link framingClient}. Until one has, a publisher's own
610
+ * view settles without waiting for its itinerary, which is what lifts a cold load's cover.
611
+ */
612
+ private reported = false;
613
+ /**
614
+ * The constraints the last itinerary or collection framed on {@link framingClient} left
615
+ * standing, or null.
616
+ */
617
+ private standing: Standing | null = null;
618
+ /**
619
+ * Every constraint written to {@link framingClient}, each member as it was written last. A
620
+ * member never written is absent, so the first write of anything is news.
621
+ */
622
+ private applied: MapConstraints = {};
623
+ /**
624
+ * Whether a pan lock stands on {@link framingClient}. The next constraints that decide no lock
625
+ * (the base map alone, an itinerary with no extent) release it.
626
+ */
627
+ private locked = false;
628
+ /**
629
+ * Whether a content switch made with nothing framed is still unanswered: an itinerary or a
630
+ * collection is, or was, expected, or the configured id changed, and since then nothing was
631
+ * framed and the base map alone was not set to settle again. A switch that ends with nothing to
632
+ * frame settles the base map again. Answered when that settle starts, not when it paints, so an
633
+ * expectation that rises after it is a wait of its own, owed its own settle.
634
+ */
635
+ private awaited: boolean;
636
+ /** The configured itinerary's id as last stated, or undefined when it was left out. */
637
+ private configuredId: string | null | undefined;
638
+
639
+ /** Whether nobody is watching. A parked engine frames nothing and reports nothing. */
640
+ private parked = true;
641
+ private disposed = false;
642
+
643
+ /**
644
+ * Constructing one holds the configuration and does nothing else: no client is read, framed or
645
+ * constrained. A React binding constructs during a render React is free to throw away, and a
646
+ * constructor with a side effect would leave the discarded copy framing.
647
+ */
648
+ constructor(config: EmbedFramingConfig) {
649
+ this.config = config;
650
+ const content = contentOf(config);
651
+ this.awaited = isBaseMap(content) && expectsContent(config);
652
+ this.configuredId = config.configuredItineraryId;
653
+ this.snapshot = { bounds: null, framed: false, ...content };
654
+ }
655
+
656
+ /** getSnapshot returns the current answer, by reference and stable between changes. */
657
+ getSnapshot(): EmbedFramingSnapshot {
658
+ return this.snapshot;
659
+ }
660
+
661
+ /**
662
+ * subscribe registers a listener for every change of the snapshot, and returns its own
663
+ * unsubscribe, which is idempotent.
664
+ *
665
+ * The first listener resumes the engine and the last one leaving parks it, which is the whole
666
+ * lifecycle a component can express correctly: React tears an effect down and sets it up again
667
+ * with the same object under StrictMode, so a latch here would leave a live surface bound to a
668
+ * dead engine.
669
+ */
670
+ subscribe(listener: () => void): () => void {
671
+ if (this.disposed) {
672
+ return () => undefined;
673
+ }
674
+
675
+ const subscription = (): void => listener();
676
+ this.listeners.add(subscription);
677
+
678
+ if (this.parked) {
679
+ this.parked = false;
680
+ this.step();
681
+ }
682
+
683
+ return () => {
684
+ if (!this.listeners.delete(subscription) || this.listeners.size > 0 || this.parked) {
685
+ return;
686
+ }
687
+
688
+ this.parked = true;
689
+ };
690
+ }
691
+
692
+ /**
693
+ * configure replaces the configuration, and frames again only when what a framing is decided
694
+ * from changed.
695
+ *
696
+ * A binding calls it after every render, so it compares the inputs a framing reads (the client
697
+ * and the itinerary by identity, the rest by value) and does nothing more when they are
698
+ * unchanged: `fit`, `fitCollection` and `onFramed` are read when they are used, so a fresh
699
+ * closure per render costs nothing. Parked or not, the snapshot answers for the new content,
700
+ * and for a replaced client, before this returns: unframed, under the active id, until its
701
+ * framing settles. Only the framing waits for a subscriber.
702
+ */
703
+ configure(config: EmbedFramingConfig): void {
704
+ if (this.disposed) {
705
+ return;
706
+ }
707
+
708
+ this.config = config;
709
+ if (config.client !== this.framingClient) {
710
+ // A framing made on another client is no answer for this one, subscribed to or not.
711
+ this.restart(config.client);
712
+ }
713
+
714
+ const content = contentOf(config);
715
+ if (!sameContent(content, this.snapshot)) {
716
+ // Another content's settle is no answer for this one, so the next step runs in full even
717
+ // when its question reads as one already asked (a switch away and back while parked).
718
+ this.asked = null;
719
+ this.publish({ bounds: null, framed: false, ...content });
720
+ }
721
+
722
+ // An id stated for the first time, or left out, is no switch: there is no earlier id to
723
+ // tell it from.
724
+ const configuredId = config.configuredItineraryId;
725
+ const switched =
726
+ configuredId !== undefined &&
727
+ this.configuredId !== undefined &&
728
+ configuredId !== this.configuredId;
729
+ this.configuredId = configuredId;
730
+
731
+ if (isBaseMap(content) && !this.awaited && (expectsContent(config) || switched)) {
732
+ // Noted here, parked or not, and the next step runs in full: an expectation that comes and
733
+ // goes while nobody watches leaves the question it found, and is still owed its settle. So
734
+ // is a switch to an itinerary whose failure the host already holds, which changes no
735
+ // question at all.
736
+ this.awaited = true;
737
+ this.asked = null;
738
+ }
739
+
740
+ this.step();
741
+ }
742
+
743
+ /**
744
+ * dispose parks the engine and drops every listener, for good: a settle still on its way reports
745
+ * nothing.
746
+ *
747
+ * Idempotent, and every call after it is a no-op rather than an error: an owner torn down
748
+ * mid-load should not have to guard the calls it already queued.
749
+ */
750
+ dispose(): void {
751
+ if (this.disposed) {
752
+ return;
753
+ }
754
+
755
+ this.disposed = true;
756
+ this.parked = true;
757
+ this.pendingFit = null;
758
+ this.pendingReveal = null;
759
+ this.listeners.clear();
760
+ }
761
+
762
+ /**
763
+ * step brings the framing in line with the configuration. It runs in full only when the question
764
+ * changed since the last step, when the active itinerary did, or when work the last one started
765
+ * was dropped while parked.
766
+ */
767
+ private step(): void {
768
+ if (this.parked || this.disposed) {
769
+ return;
770
+ }
771
+
772
+ const { client } = this.config;
773
+ if (client !== this.framingClient) {
774
+ this.restart(client);
775
+ }
776
+
777
+ if (client === null) {
778
+ return;
779
+ }
780
+
781
+ const question = questionOf(this.config, client);
782
+ if (
783
+ this.asked !== null &&
784
+ (sameQuestion(this.asked, question) || sameQuestion(this.asked, this.whileFitting(question)))
785
+ ) {
786
+ return;
787
+ }
788
+
789
+ // The configuration's own question is the one recorded and framed, never the one
790
+ // `whileFitting` answers: a framing decided for a canvas with no area is recorded as asked for
791
+ // no canvas, so the canvas that comes back is a question nobody answered.
792
+ this.asked = question;
793
+ this.frame(client, question);
794
+ }
795
+
796
+ /**
797
+ * whileFitting answers `question` as the fit on its way was asked it, when the canvas has since
798
+ * gone to nothing: neither size the configuration states measures anything (see
799
+ * `measuredCanvas`). A canvas with no area has nothing to frame, so it asks nothing new, the fit
800
+ * on its way stands, and a canvas that comes back at the size that fit was asked for is the
801
+ * question already answered. With no fit on its way, or while either size still measures
802
+ * something, the question is the configuration's own.
803
+ *
804
+ * It is read to compare and never to record: another input that changes while the canvas
805
+ * measures nothing is a question of its own, recorded with the sizes the configuration states.
806
+ * It starts no fit while the page has laid the canvas out at no area (see {@link unlaid}), so
807
+ * the canvas that comes back is the one framed for it.
808
+ */
809
+ private whileFitting(question: FramingQuestion): FramingQuestion {
810
+ const asked = this.asked;
811
+
812
+ if (
813
+ asked === null ||
814
+ this.pendingFit === null ||
815
+ largestOf(this.config.canvasSize, lockSizeOf(this.config)) !== null
816
+ ) {
817
+ return question;
818
+ }
819
+
820
+ return {
821
+ ...question,
822
+ canvasHeight: asked.canvasHeight,
823
+ canvasWidth: asked.canvasWidth,
824
+ lockHeight: asked.lockHeight,
825
+ lockWidth: asked.lockWidth,
826
+ };
827
+ }
828
+
829
+ /**
830
+ * restart forgets every framing made on the previous client, so a replaced client (or the map
831
+ * arriving) frames and locks from nothing. A settle still on its way for the previous client is
832
+ * dropped.
833
+ */
834
+ private restart(client: MapClient | null): void {
835
+ this.framingClient = client;
836
+ this.asked = null;
837
+ this.pendingFit = null;
838
+ this.pendingReveal = null;
839
+ this.reported = false;
840
+ this.standing = null;
841
+ this.locked = false;
842
+ this.applied = {};
843
+
844
+ const content = contentOf(this.config);
845
+ if (this.snapshot.framed || !sameContent(this.snapshot, content)) {
846
+ this.publish({ bounds: null, framed: false, ...content });
847
+ }
848
+ }
849
+
850
+ /** frame runs one framing step for `question` on `client`. */
851
+ private frame(client: MapClient, question: FramingQuestion): void {
852
+ const { itinerary, zoomRange } = this.config;
853
+ // Read off the client rather than the live address bar, so a view the map wrote into the hash
854
+ // itself (or a remount left there) never stops a preview from framing.
855
+ const deferred = client.hadInitialViewHash();
856
+ const content = contentOf(this.config);
857
+ const collection = collectionOf(this.config);
858
+
859
+ if (isBaseMap(content)) {
860
+ // A settle on its way for an itinerary or a collection answers nothing once neither is
861
+ // framed, so it is dropped. The base map's own settle stays.
862
+ this.pendingFit = null;
863
+ if (this.pendingReveal !== null && !isBaseMap(this.pendingReveal)) {
864
+ this.pendingReveal = null;
865
+ }
866
+
867
+ if (expectsContent(this.config)) {
868
+ this.awaitContent(client, deferred);
869
+ } else {
870
+ this.showBaseMap(client);
871
+ }
872
+
873
+ return;
874
+ }
875
+
876
+ // What the embed waited for is here, which answers the wait.
877
+ this.awaited = false;
878
+ // The base map's settle on its way answers for a view the reader has left: the content's own
879
+ // framing is the one settle of the switch, whichever drawing lands first.
880
+ if (this.pendingReveal !== null && isBaseMap(this.pendingReveal)) {
881
+ this.pendingReveal = null;
882
+ }
883
+
884
+ // Settled, or settling on a publisher's own view: a re-render, the store activating the
885
+ // itinerary again under the same id, a collection's extent answered again, or a profile
886
+ // height measured late must neither reframe (which would pull a visitor's own camera back to
887
+ // the route) nor tighten the zoom floor the framing lowered. The zoom range follows the
888
+ // configuration and the pan lock the canvas.
889
+ if (
890
+ this.settledFor(content) ||
891
+ (this.pendingReveal !== null && sameContent(this.pendingReveal, content))
892
+ ) {
893
+ this.rangeAgain(client, content);
894
+ this.lockAgain(client, content);
895
+
896
+ return;
897
+ }
898
+
899
+ if (!deferred && (this.unlaid() || this.resizing())) {
900
+ this.awaitResize(client);
901
+
902
+ return;
903
+ }
904
+
905
+ // What the content spans: the itinerary's geometry, or the box the collection's
906
+ // specification states for the itineraries its tiles draw.
907
+ const bounds =
908
+ itinerary === null
909
+ ? (collection?.bounds ?? null)
910
+ : boundsOf(segmentGeometries(segmentsForSelection(itinerary, null)));
911
+ const padding = embedFitPadding(
912
+ {
913
+ showAnalysis: question.showAnalysis,
914
+ showCharacteristics: question.showCharacteristics,
915
+ showElevation: question.showElevation,
916
+ },
917
+ question.measuredPanelHeight,
918
+ );
919
+ const framing =
920
+ !deferred && bounds !== null
921
+ ? client.cameraForBounds(bounds, padding, ITINERARY_FIT_MAX_ZOOM)
922
+ : null;
923
+ const input: EmbedConstraintsInput = {
924
+ bounds,
925
+ // The larger of the two sizes: under a publisher's own view the lock is sized for a canvas
926
+ // the page has laid out and the renderer has yet to resize to. Under a fit the two agree.
927
+ canvasSize: largestOf(this.config.canvasSize, lockSizeOf(this.config)),
928
+ framing,
929
+ padding,
930
+ // Read before the lock is applied: the camera no fit will move, which the lock must hold.
931
+ view: deferred ? client.getViewport() : null,
932
+ zoomRange,
933
+ };
934
+
935
+ this.standing = { content, input };
936
+ this.constrain(client, embedConstraintsFor(input));
937
+
938
+ if (deferred) {
939
+ // A publisher's own view frames the camera: no fit runs against it, and the content
940
+ // settles on the map's next render.
941
+ this.revealWithoutFit(client, bounds, content);
942
+
943
+ return;
944
+ }
945
+
946
+ // Replaces a fit already on its way, whose settle is then dropped, even one asked for these
947
+ // very inputs: an itinerary cleared and activated again had its own settle dropped at the
948
+ // clear, so only a fit asked for since then reports it.
949
+ const pending: Pending = { bounds, ...content };
950
+ this.pendingFit = pending;
951
+ // The collection's fit frames its box under the ceiling the camera above was computed with,
952
+ // so the fit lands where the lock and the lowered floor expect it. The itinerary's fit holds
953
+ // that ceiling by default.
954
+ const fitting =
955
+ itinerary === null && collection !== null && this.config.fitCollection !== undefined
956
+ ? this.config.fitCollection(collection.bounds, padding, ITINERARY_FIT_MAX_ZOOM)
957
+ : this.config.fit(padding);
958
+ fitting
959
+ .then(() => client.waitForRender())
960
+ .then(
961
+ () => {
962
+ if (this.pendingFit !== pending) {
963
+ return;
964
+ }
965
+
966
+ this.pendingFit = null;
967
+ if (this.parked || this.disposed) {
968
+ // Dropped while parked: the next subscriber frames it again.
969
+ this.asked = null;
970
+
971
+ return;
972
+ }
973
+
974
+ if (this.resizing()) {
975
+ // The fit framed a canvas the renderer is resizing away from, so its paint is no
976
+ // view to settle on. The two sizes agreeing is a question not asked yet, so the
977
+ // step that finds them so runs in full and fits again.
978
+ return;
979
+ }
980
+
981
+ if (this.asked !== question && this.unlaid()) {
982
+ // An input changed while the canvas had no area, and no fit started for it: this
983
+ // one framed the inputs as they were. Its paint is no view to settle on, and the
984
+ // question is left open, so the canvas that comes back is framed as they stand.
985
+ this.asked = null;
986
+
987
+ return;
988
+ }
989
+
990
+ this.settle(pending);
991
+ },
992
+ () => {
993
+ // A fit that failed settles nothing, and the embed's deadline lifts the cover. Asking
994
+ // again waits for the question to change, so a failing fit is never retried in a loop.
995
+ if (this.pendingFit === pending) {
996
+ this.pendingFit = null;
997
+ }
998
+ },
999
+ );
1000
+ }
1001
+
1002
+ /**
1003
+ * resizing reports whether the page has laid the canvas out at a size the renderer has yet to
1004
+ * resize to: `lockCanvasSize` measures a canvas `canvasSize` does not state. Never with no
1005
+ * `lockCanvasSize`, and never while it measures nothing.
1006
+ */
1007
+ private resizing(): boolean {
1008
+ const ahead = measuredCanvas(lockSizeOf(this.config));
1009
+
1010
+ return ahead !== null && !sameSize(ahead, measuredCanvas(this.config.canvasSize));
1011
+ }
1012
+
1013
+ /**
1014
+ * unlaid reports whether the page has laid the canvas out at no area: no size the
1015
+ * configuration states measures anything, and one of them, `canvasSize` or `lockCanvasSize`,
1016
+ * states a layout with no area (see {@link laidOutAtNoArea}). An embed mounted in a frame
1017
+ * nobody is shown yet reads so. Never for a host that states no size at all, or one that is
1018
+ * not a number: neither is a layout, and the embed is framed as it stands.
1019
+ *
1020
+ * A renderer gives a container with no area a canvas of its own default size, so a fit asked
1021
+ * for now would frame a canvas nobody sees, and its settle would report a view the reader is
1022
+ * never shown.
1023
+ */
1024
+ private unlaid(): boolean {
1025
+ const { canvasSize } = this.config;
1026
+ const lockSize = lockSizeOf(this.config);
1027
+
1028
+ return (
1029
+ largestOf(canvasSize, lockSize) === null &&
1030
+ (laidOutAtNoArea(canvasSize) || laidOutAtNoArea(lockSize))
1031
+ );
1032
+ }
1033
+
1034
+ /**
1035
+ * awaitResize runs the framing step for an itinerary a fit frames while there is no canvas to
1036
+ * frame yet: the page has laid it out at no area (see {@link unlaid}), or the renderer has yet
1037
+ * to resize to it (see {@link resizing}). It starts no fit, since one asked for now would
1038
+ * frame the canvas as it was, and it leaves a fit already on its way in flight. The step that
1039
+ * finds a canvas with an area, at a size the two agree on, frames in full, and the fit it
1040
+ * starts replaces that one.
1041
+ *
1042
+ * What stands on the client meanwhile is what {@link awaitContent} leaves there. The pan lock
1043
+ * of the last framing, this itinerary's or the outgoing one's, is widened for the size ahead
1044
+ * (see {@link lockAgain}), so the renderer resizes inside it. On a client nothing was framed
1045
+ * on, the organization's zoom range applies at once: it reads no canvas, so it has nothing to
1046
+ * wait for, and a host whose two sizes never agree is not left with a map no range holds.
1047
+ */
1048
+ private awaitResize(client: MapClient): void {
1049
+ if (this.standing === null) {
1050
+ this.constrain(client, this.zoomRangeAlone());
1051
+ } else {
1052
+ this.rangeAgain(client, this.standing.content);
1053
+ this.lockAgain(client, this.standing.content);
1054
+ }
1055
+ }
1056
+
1057
+ /**
1058
+ * awaitContent runs the framing step for an itinerary or a collection that is expected and not
1059
+ * framed yet: the itinerary's detail is loading, a content switch cleared the outgoing one
1060
+ * first, or the collection's specification has not answered.
1061
+ *
1062
+ * The constraints of the last itinerary or collection framed on this client stay until the next
1063
+ * framing replaces them, the zoom floor that framing lowered included; the pan lock among them
1064
+ * still follows a canvas that outgrows it (see {@link lockAgain}). On a client nothing was
1065
+ * framed on, the organization's zoom range applies at once.
1066
+ */
1067
+ private awaitContent(client: MapClient, deferred: boolean): void {
1068
+ if (this.standing === null) {
1069
+ // The zoom range alone, which reads neither the canvas nor a padding.
1070
+ this.constrain(client, this.zoomRangeAlone());
1071
+ } else {
1072
+ // Over the outgoing framing, so the zoom floor it lowered stays: a range that changed is
1073
+ // decided from that framing's own inputs. Under a publisher's own view no fit follows the
1074
+ // load: a camera the renderer zoomed in to keep a grown canvas inside the outgoing lock
1075
+ // would stay zoomed in for good.
1076
+ this.rangeAgain(client, this.standing.content);
1077
+ this.lockAgain(client, this.standing.content);
1078
+ }
1079
+
1080
+ // Only a publisher's own view settles without its content, and only for the first settle on
1081
+ // this client: after it, a content switch waits for its content, as a fitted one does.
1082
+ if (deferred && !this.reported) {
1083
+ this.revealWithoutFit(client, null, baseMapContent);
1084
+ }
1085
+ }
1086
+
1087
+ /**
1088
+ * showBaseMap runs the framing step for the base map alone: no itinerary or collection is
1089
+ * framed and none is expected. The organization's zoom range applies as it is, the pan lock an
1090
+ * itinerary or a collection left standing is released (see {@link constrain}), and the view
1091
+ * settles on the map's next render.
1092
+ */
1093
+ private showBaseMap(client: MapClient): void {
1094
+ this.standing = null;
1095
+ this.constrain(client, this.zoomRangeAlone());
1096
+
1097
+ if (this.awaited) {
1098
+ // What the embed waited for never came, so the base map's earlier settle is no answer for
1099
+ // how the switch ended: it settles again, and is reported again.
1100
+ this.awaited = false;
1101
+ if (this.snapshot.framed) {
1102
+ this.publish({ bounds: null, framed: false, ...baseMapContent });
1103
+ }
1104
+ }
1105
+
1106
+ this.revealWithoutFit(client, null, baseMapContent);
1107
+ }
1108
+
1109
+ /** zoomRangeAlone decides the constraints with no itinerary to lock to: the zoom range alone. */
1110
+ private zoomRangeAlone(): MapConstraints {
1111
+ return embedConstraintsFor({
1112
+ bounds: null,
1113
+ canvasSize: null,
1114
+ framing: null,
1115
+ padding: 0,
1116
+ zoomRange: this.config.zoomRange,
1117
+ });
1118
+ }
1119
+
1120
+ /**
1121
+ * rangeAgain applies the configuration's zoom range over the framing of `content` when it is not
1122
+ * the range that framing was decided from: the same route, camera, canvas and padding, under
1123
+ * the range as it is stated now. The zoom range alone, so the pan lock stays as it is and no
1124
+ * camera is moved by a fit.
1125
+ *
1126
+ * The floor is the one a framing under this range would have set, lowered to the zoom the fit
1127
+ * landed on, so a range that arrives late leaves the embed where it would have opened. A range
1128
+ * that does not state both ends decides no clamp, so the one on the map is released
1129
+ * (see {@link rangeRelease}).
1130
+ */
1131
+ private rangeAgain(client: MapClient, content: ContentKey): void {
1132
+ const standing = this.standing;
1133
+ const { zoomRange } = this.config;
1134
+
1135
+ if (
1136
+ standing === null ||
1137
+ !sameContent(standing.content, content) ||
1138
+ sameRange(standing.input.zoomRange, zoomRange)
1139
+ ) {
1140
+ return;
1141
+ }
1142
+
1143
+ const input: EmbedConstraintsInput = { ...standing.input, zoomRange };
1144
+ this.standing = { content, input };
1145
+
1146
+ const { maxZoom, minZoom } = embedConstraintsFor(input);
1147
+ this.apply(
1148
+ client,
1149
+ maxZoom !== undefined && minZoom !== undefined ? { maxZoom, minZoom } : this.rangeRelease(),
1150
+ );
1151
+ }
1152
+
1153
+ /**
1154
+ * rangeRelease is the constraints that release the zoom range this engine wrote to the client:
1155
+ * a null for each end, which hands the map back its own window. Nothing while no range of the
1156
+ * engine's stands there, so a map no range was written to is told nothing.
1157
+ */
1158
+ private rangeRelease(): MapConstraints {
1159
+ const { maxZoom, minZoom } = this.applied;
1160
+
1161
+ return typeof maxZoom === "number" || typeof minZoom === "number"
1162
+ ? { maxZoom: null, minZoom: null }
1163
+ : {};
1164
+ }
1165
+
1166
+ /**
1167
+ * lockAgain widens the pan lock of the framing of `content` when the canvas has outgrown the one
1168
+ * it was sized for: the same route, camera and padding, on a canvas as wide as the widest and as
1169
+ * tall as the tallest it has been handed since the framing, as `canvasSize` or as
1170
+ * `lockCanvasSize`. The lock alone, so the zoom range stays as the framing set it, and no
1171
+ * camera is moved.
1172
+ *
1173
+ * The lock only grows. The renderer keeps its canvas inside the lock at the size the canvas has
1174
+ * when the lock is applied, and a new size is handed over before the renderer resizes: a lock
1175
+ * sized for a smaller canvas would be narrower than the one the renderer still holds. A canvas
1176
+ * that reads unmeasured changes nothing either.
1177
+ */
1178
+ private lockAgain(client: MapClient, content: ContentKey): void {
1179
+ const standing = this.standing;
1180
+
1181
+ if (
1182
+ standing === null ||
1183
+ !sameContent(standing.content, content) ||
1184
+ standing.input.bounds === null
1185
+ ) {
1186
+ return;
1187
+ }
1188
+
1189
+ const sizedFor = measuredCanvas(standing.input.canvasSize);
1190
+ const largest = largestOf(sizedFor, largestOf(this.config.canvasSize, lockSizeOf(this.config)));
1191
+ if (largest === null || sameSize(sizedFor, largest)) {
1192
+ return;
1193
+ }
1194
+
1195
+ const input: EmbedConstraintsInput = { ...standing.input, canvasSize: largest };
1196
+ this.standing = { content, input };
1197
+
1198
+ const { maxBounds } = embedConstraintsFor(input);
1199
+ if (maxBounds !== undefined) {
1200
+ this.apply(client, { maxBounds });
1201
+ }
1202
+ }
1203
+
1204
+ /**
1205
+ * constrain applies one framing step's constraints, in one call, and only when they decide
1206
+ * something.
1207
+ *
1208
+ * Constraints that decide no pan lock release the one standing, with a null `maxBounds`: there
1209
+ * is no route left to hold the camera to, whether the embed is the base map alone or its next
1210
+ * itinerary has no extent. Constraints that decide no zoom range release the one standing the
1211
+ * same way (see {@link rangeRelease}): the configuration states none any more.
1212
+ */
1213
+ private constrain(client: MapClient, decided: MapConstraints): void {
1214
+ const ranged = decided.maxZoom === undefined ? { ...decided, ...this.rangeRelease() } : decided;
1215
+ const constraints =
1216
+ ranged.maxBounds === undefined && this.locked ? { ...ranged, maxBounds: null } : ranged;
1217
+
1218
+ this.apply(client, constraints);
1219
+ if (constraints.maxBounds !== undefined) {
1220
+ this.locked = constraints.maxBounds !== null;
1221
+ }
1222
+ }
1223
+
1224
+ /**
1225
+ * apply writes `constraints` to the client, unless they decide nothing or every member they
1226
+ * state already stands there as stated. A resize under the zoom range alone, and a framing
1227
+ * asked again for the inputs it had, decide what the map already holds, and writing it again
1228
+ * would have the renderer enforce an unchanged range and lock once more.
1229
+ *
1230
+ * The set is written whole when any member is news, so a caller's one call stays one call.
1231
+ */
1232
+ private apply(client: MapClient, constraints: MapConstraints): void {
1233
+ if (isEmpty(constraints) || standsAs(constraints, this.applied)) {
1234
+ return;
1235
+ }
1236
+
1237
+ client.setConstraints(constraints);
1238
+ this.applied = { ...this.applied, ...constraints };
1239
+ }
1240
+
1241
+ /**
1242
+ * revealWithoutFit settles the view on the map's next render, for a view no fit will move: an
1243
+ * embed of the base map alone, an itinerary that failed to load, or a publisher's own view.
1244
+ *
1245
+ * Once for what it answers, `content`: a view already settled for it, or settling, is left
1246
+ * alone. A settle on its way for anything else is replaced, since both would wait on the same
1247
+ * render and only the active one is worth reporting.
1248
+ */
1249
+ private revealWithoutFit(
1250
+ client: MapClient,
1251
+ bounds: BoundingBox | null,
1252
+ content: ContentKey,
1253
+ ): void {
1254
+ if (
1255
+ this.settledFor(content) ||
1256
+ (this.pendingReveal !== null && sameContent(this.pendingReveal, content))
1257
+ ) {
1258
+ return;
1259
+ }
1260
+
1261
+ const pending: Pending = { bounds, ...content };
1262
+ this.pendingReveal = pending;
1263
+ client.waitForRender().then(
1264
+ () => {
1265
+ if (this.pendingReveal !== pending) {
1266
+ return;
1267
+ }
1268
+
1269
+ this.pendingReveal = null;
1270
+ if (this.parked || this.disposed) {
1271
+ // Dropped while parked: the next subscriber settles it again.
1272
+ this.asked = null;
1273
+
1274
+ return;
1275
+ }
1276
+
1277
+ this.settle(pending);
1278
+ },
1279
+ () => {
1280
+ if (this.pendingReveal === pending) {
1281
+ this.pendingReveal = null;
1282
+ }
1283
+ },
1284
+ );
1285
+ }
1286
+
1287
+ /**
1288
+ * settledFor reports whether the initial view of `content` has settled on the current client.
1289
+ * The snapshot is the one record of it: it answers for the active content and reads unframed
1290
+ * from a content switch, or a replaced client, until that settle.
1291
+ */
1292
+ private settledFor(content: ContentKey): boolean {
1293
+ return this.snapshot.framed && sameContent(this.snapshot, content);
1294
+ }
1295
+
1296
+ /**
1297
+ * settle reports one settle: through the snapshot, then to `onFramed`. A settle on its way for
1298
+ * anything but the active content is dropped before it lands (see {@link frame}), so the
1299
+ * snapshot is written only for the content it answers for, and never goes back to a content
1300
+ * the reader has left.
1301
+ */
1302
+ private settle(pending: Pending): void {
1303
+ this.reported = true;
1304
+ if (sameContent(pending, contentOf(this.config))) {
1305
+ this.publish({
1306
+ bounds: pending.bounds,
1307
+ collectionId: pending.collectionId,
1308
+ framed: true,
1309
+ itineraryId: pending.itineraryId,
1310
+ });
1311
+ }
1312
+
1313
+ try {
1314
+ this.config.onFramed?.(pending.bounds);
1315
+ } catch (fault) {
1316
+ // The settle is complete by now: the snapshot answers and every listener has heard. This
1317
+ // runs at the end of the promise the paint resolved, so a throw left to travel would be an
1318
+ // unhandled rejection in whatever surface holds the engine, with no caller placed to catch
1319
+ // it. The host's own program hears of its defect.
1320
+ surfaceFault(fault);
1321
+ }
1322
+ }
1323
+
1324
+ /** publish shows `snapshot` and tells every listener. */
1325
+ private publish(snapshot: EmbedFramingSnapshot): void {
1326
+ this.snapshot = snapshot;
1327
+ notifyListeners(this.listeners);
1328
+ }
1329
+ }