@mountaya/studio 0.0.0-stage → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +69 -0
- package/LICENCE.fr.txt +280 -0
- package/LICENSE.txt +262 -0
- package/README.md +917 -2
- package/dist/agent/index.cjs +2600 -0
- package/dist/agent/index.cjs.map +1 -0
- package/dist/agent/index.d.cts +1237 -0
- package/dist/agent/index.d.ts +1237 -0
- package/dist/agent/index.js +2581 -0
- package/dist/agent/index.js.map +1 -0
- package/dist/chunk-3Oi_Zrtm.js +9 -0
- package/dist/chunk-3Oi_Zrtm.js.map +1 -0
- package/dist/chunk-B18OPIu_.js +6 -0
- package/dist/chunk-B18OPIu_.js.map +1 -0
- package/dist/chunk-B5Uz3Qct.cjs +15 -0
- package/dist/chunk-B5Uz3Qct.cjs.map +1 -0
- package/dist/chunk-BBEJwkd3.d.cts +839 -0
- package/dist/chunk-BIEc_SkR.cjs +29 -0
- package/dist/chunk-BIEc_SkR.cjs.map +1 -0
- package/dist/chunk-BKMFOe-N.js +171 -0
- package/dist/chunk-BKMFOe-N.js.map +1 -0
- package/dist/chunk-BP4uy7E1.d.ts +11583 -0
- package/dist/chunk-BSHTsFiB.js +1403 -0
- package/dist/chunk-BSHTsFiB.js.map +1 -0
- package/dist/chunk-BTUUABGI.js +17 -0
- package/dist/chunk-BTUUABGI.js.map +1 -0
- package/dist/chunk-BaPiaz5X.cjs +115 -0
- package/dist/chunk-BaPiaz5X.cjs.map +1 -0
- package/dist/chunk-BeCVpkYr.cjs +542 -0
- package/dist/chunk-BeCVpkYr.cjs.map +1 -0
- package/dist/chunk-BgngsvK8.cjs +6202 -0
- package/dist/chunk-BgngsvK8.cjs.map +1 -0
- package/dist/chunk-BhInd7CJ.d.cts +253 -0
- package/dist/chunk-Bn6ZbxkS.cjs +27 -0
- package/dist/chunk-By9ZnkVI.js +60 -0
- package/dist/chunk-By9ZnkVI.js.map +1 -0
- package/dist/chunk-BzqPhxsz.cjs +367 -0
- package/dist/chunk-BzqPhxsz.cjs.map +1 -0
- package/dist/chunk-C2mMX81q.d.ts +443 -0
- package/dist/chunk-C2rr9Q0V.cjs +1402 -0
- package/dist/chunk-C2rr9Q0V.cjs.map +1 -0
- package/dist/chunk-CDJCbwIQ.d.cts +78 -0
- package/dist/chunk-CLGvBOVH.d.cts +1654 -0
- package/dist/chunk-COdw1dc6.d.ts +525 -0
- package/dist/chunk-CQCJnT2i.d.ts +511 -0
- package/dist/chunk-CSyHY67q.cjs +353 -0
- package/dist/chunk-CSyHY67q.cjs.map +1 -0
- package/dist/chunk-CiK1Iqrv.js +950 -0
- package/dist/chunk-CiK1Iqrv.js.map +1 -0
- package/dist/chunk-CmJBgSwZ.cjs +24 -0
- package/dist/chunk-CmJBgSwZ.cjs.map +1 -0
- package/dist/chunk-CnrsRK2u.cjs +83 -0
- package/dist/chunk-CnrsRK2u.cjs.map +1 -0
- package/dist/chunk-Co782_9r.js +326 -0
- package/dist/chunk-Co782_9r.js.map +1 -0
- package/dist/chunk-Csr3KDpZ.cjs +32 -0
- package/dist/chunk-Csr3KDpZ.cjs.map +1 -0
- package/dist/chunk-CwkmccXv.js +89 -0
- package/dist/chunk-CwkmccXv.js.map +1 -0
- package/dist/chunk-D0Q4iL9B.cjs +255 -0
- package/dist/chunk-D0Q4iL9B.cjs.map +1 -0
- package/dist/chunk-DFwiSzUS.cjs +72 -0
- package/dist/chunk-DFwiSzUS.cjs.map +1 -0
- package/dist/chunk-DIFayl2P.d.cts +443 -0
- package/dist/chunk-DIGF58ux.d.cts +525 -0
- package/dist/chunk-DKuuuld5.js +101 -0
- package/dist/chunk-DKuuuld5.js.map +1 -0
- package/dist/chunk-DMePkFEo.js +5054 -0
- package/dist/chunk-DMePkFEo.js.map +1 -0
- package/dist/chunk-DO5SIBgu.js +305 -0
- package/dist/chunk-DO5SIBgu.js.map +1 -0
- package/dist/chunk-DOQ_7eE5.d.ts +6662 -0
- package/dist/chunk-DThaaNeb.d.cts +15 -0
- package/dist/chunk-DThaaNeb.d.ts +15 -0
- package/dist/chunk-DUQzjUJy.d.ts +78 -0
- package/dist/chunk-DX37IPhV.cjs +1903 -0
- package/dist/chunk-DX37IPhV.cjs.map +1 -0
- package/dist/chunk-Damps5Tk.cjs +155 -0
- package/dist/chunk-Damps5Tk.cjs.map +1 -0
- package/dist/chunk-DbK5PhpJ.d.ts +1654 -0
- package/dist/chunk-De0vAASv.d.ts +253 -0
- package/dist/chunk-DhSZ7YZt.d.cts +6662 -0
- package/dist/chunk-DjEvqvPA.cjs +43 -0
- package/dist/chunk-DjEvqvPA.cjs.map +1 -0
- package/dist/chunk-DkwDzwvu.d.cts +121 -0
- package/dist/chunk-DkwDzwvu.d.ts +121 -0
- package/dist/chunk-Dmszv9If.js +71 -0
- package/dist/chunk-Dmszv9If.js.map +1 -0
- package/dist/chunk-Dp_ftNWY.d.cts +511 -0
- package/dist/chunk-DsHQySz0.js +31 -0
- package/dist/chunk-DsHQySz0.js.map +1 -0
- package/dist/chunk-DwoUyHHh.js +281 -0
- package/dist/chunk-DwoUyHHh.js.map +1 -0
- package/dist/chunk-IaIDQflj.d.cts +2315 -0
- package/dist/chunk-IaIDQflj.d.ts +2315 -0
- package/dist/chunk-cVXLsZfL.d.ts +839 -0
- package/dist/chunk-mIaCX9EJ.d.cts +11583 -0
- package/dist/chunk-nJQxbOwQ.cjs +8962 -0
- package/dist/chunk-nJQxbOwQ.cjs.map +1 -0
- package/dist/chunk-o9jaxhCO.js +8852 -0
- package/dist/chunk-o9jaxhCO.js.map +1 -0
- package/dist/chunk-p-Tt_Lwz.js +14 -0
- package/dist/chunk-p-Tt_Lwz.js.map +1 -0
- package/dist/engines/index.cjs +2091 -0
- package/dist/engines/index.cjs.map +1 -0
- package/dist/engines/index.d.cts +2176 -0
- package/dist/engines/index.d.ts +2176 -0
- package/dist/engines/index.js +2075 -0
- package/dist/engines/index.js.map +1 -0
- package/dist/handlers/index.cjs +53 -0
- package/dist/handlers/index.cjs.map +1 -0
- package/dist/handlers/index.d.cts +403 -0
- package/dist/handlers/index.d.ts +403 -0
- package/dist/handlers/index.js +33 -0
- package/dist/handlers/index.js.map +1 -0
- package/dist/index.cjs +3511 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +8 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +3033 -0
- package/dist/index.js.map +1 -0
- package/dist/plugins/index.cjs +510 -0
- package/dist/plugins/index.cjs.map +1 -0
- package/dist/plugins/index.d.cts +296 -0
- package/dist/plugins/index.d.ts +296 -0
- package/dist/plugins/index.js +489 -0
- package/dist/plugins/index.js.map +1 -0
- package/dist/seams/index.cjs +89 -0
- package/dist/seams/index.cjs.map +1 -0
- package/dist/seams/index.d.cts +452 -0
- package/dist/seams/index.d.ts +452 -0
- package/dist/seams/index.js +49 -0
- package/dist/seams/index.js.map +1 -0
- package/dist/strings/fr/index.cjs +2135 -0
- package/dist/strings/fr/index.cjs.map +1 -0
- package/dist/strings/fr/index.d.cts +17 -0
- package/dist/strings/fr/index.d.ts +17 -0
- package/dist/strings/fr/index.js +2130 -0
- package/dist/strings/fr/index.js.map +1 -0
- package/dist/strings/index.cjs +2384 -0
- package/dist/strings/index.cjs.map +1 -0
- package/dist/strings/index.d.cts +3 -0
- package/dist/strings/index.d.ts +3 -0
- package/dist/strings/index.js +2353 -0
- package/dist/strings/index.js.map +1 -0
- package/dist/testing/index.cjs +230 -0
- package/dist/testing/index.cjs.map +1 -0
- package/dist/testing/index.d.cts +246 -0
- package/dist/testing/index.d.ts +246 -0
- package/dist/testing/index.js +219 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/time/index.cjs +28 -0
- package/dist/time/index.cjs.map +1 -0
- package/dist/time/index.d.cts +41 -0
- package/dist/time/index.d.ts +41 -0
- package/dist/time/index.js +23 -0
- package/dist/time/index.js.map +1 -0
- package/package.json +224 -4
- package/src/agent/engines/agentThreads.ts +1601 -0
- package/src/agent/engines/directorChat.ts +500 -0
- package/src/agent/index.ts +67 -0
- package/src/agent/rules/agentEditLock.ts +115 -0
- package/src/agent/rules/agentErrorCopy.ts +44 -0
- package/src/agent/rules/copilotOrganization.ts +36 -0
- package/src/agent/rules/playbook.gen.ts +444 -0
- package/src/agent/rules/router.ts +518 -0
- package/src/agent/rules/stateDelta.ts +29 -0
- package/src/agent/rules/studioRouter.ts +123 -0
- package/src/agent/rules/surfaces.gen.ts +633 -0
- package/src/agent/rules/threadsUrl.ts +48 -0
- package/src/agent/rules/transcriptObserver.ts +90 -0
- package/src/agent/stores/agentThreads.ts +451 -0
- package/src/bus/contracts/noData.ts +18 -0
- package/src/bus/contracts/shared.ts +172 -0
- package/src/bus/contracts/studioTools.ts +224 -0
- package/src/bus/rules/bus.ts +857 -0
- package/src/bus/rules/confirmation.ts +22 -0
- package/src/bus/rules/defineRegistry.ts +24 -0
- package/src/bus/rules/errors.ts +401 -0
- package/src/bus/rules/handlerErrors.ts +103 -0
- package/src/bus/rules/handlerRegistry.ts +627 -0
- package/src/bus/rules/inputSchema.ts +232 -0
- package/src/bus/rules/invalidInput.ts +441 -0
- package/src/bus/rules/lateBoundTools.ts +100 -0
- package/src/bus/rules/studioRegistry.ts +324 -0
- package/src/bus/rules/studioToolBus.ts +73 -0
- package/src/bus/rules/types.ts +804 -0
- package/src/chrome/contracts/alert.ts +42 -0
- package/src/chrome/contracts/itinerary.ts +26 -0
- package/src/chrome/contracts/map.ts +23 -0
- package/src/chrome/contracts/overlay.ts +46 -0
- package/src/chrome/contracts/panel.ts +29 -0
- package/src/chrome/contracts/question.ts +52 -0
- package/src/chrome/contracts/selection.ts +26 -0
- package/src/chrome/contracts/sidenav.ts +23 -0
- package/src/chrome/contracts/snapshot.ts +319 -0
- package/src/chrome/contracts/state.ts +22 -0
- package/src/chrome/contracts/tabs.ts +56 -0
- package/src/chrome/handlers/alert.ts +91 -0
- package/src/chrome/handlers/introspection.ts +180 -0
- package/src/chrome/handlers/panels.ts +42 -0
- package/src/chrome/handlers/question.ts +24 -0
- package/src/chrome/handlers/sidenav.ts +116 -0
- package/src/chrome/handlers/snapshot.ts +451 -0
- package/src/chrome/handlers/stateDelta.ts +125 -0
- package/src/chrome/handlers/tabs.ts +143 -0
- package/src/chrome/handlers/timestamp.ts +19 -0
- package/src/chrome/rules/agentSelectors.ts +210 -0
- package/src/chrome/rules/mapAlert.ts +13 -0
- package/src/chrome/rules/question.ts +25 -0
- package/src/chrome/rules/tabs.ts +13 -0
- package/src/chrome/stores/activeDraftSession.ts +134 -0
- package/src/chrome/stores/chrome.ts +527 -0
- package/src/chrome/stores/uiStore.ts +575 -0
- package/src/collab/contracts/collab.ts +261 -0
- package/src/collab/handlers/collab.ts +468 -0
- package/src/collab/rules/toolNames.ts +33 -0
- package/src/collab/stores/collab.ts +899 -0
- package/src/collections/contracts/collection.ts +182 -0
- package/src/collections/handlers/collectionAttach.ts +141 -0
- package/src/collections/handlers/collections.ts +499 -0
- package/src/collections/handlers/heldCollection.ts +42 -0
- package/src/collections/handlers/restCollections.ts +386 -0
- package/src/collections/rules/collections.ts +138 -0
- package/src/collections/rules/entityCollections.ts +53 -0
- package/src/collections/stores/collections.ts +133 -0
- package/src/data/contracts/data.ts +233 -0
- package/src/data/contracts/itinerary.ts +71 -0
- package/src/data/handlers/activityResolve.ts +76 -0
- package/src/data/handlers/data.ts +200 -0
- package/src/data/handlers/graphql.ts +26 -0
- package/src/data/handlers/mutationSink.ts +1577 -0
- package/src/data/handlers/profile.ts +83 -0
- package/src/data/handlers/writeThrough.ts +417 -0
- package/src/data/rules/cache.ts +181 -0
- package/src/data/rules/dataTypes.ts +40 -0
- package/src/data/rules/keys.ts +106 -0
- package/src/data/rules/persistence.ts +1058 -0
- package/src/data/rules/requestBody.ts +43 -0
- package/src/data/rules/restErrors.ts +354 -0
- package/src/data/rules/sessionSurface.ts +156 -0
- package/src/data/rules/toolResultData.ts +73 -0
- package/src/data/rules/uuid.ts +24 -0
- package/src/edit/contracts/edit.ts +37 -0
- package/src/edit/contracts/itinerary.ts +57 -0
- package/src/edit/handlers/draftCommit.ts +257 -0
- package/src/edit/handlers/editDiscard.ts +34 -0
- package/src/edit/handlers/editLock.ts +949 -0
- package/src/edit/handlers/editor.ts +203 -0
- package/src/edit/handlers/formUnsaved.ts +24 -0
- package/src/edit/rules/draftMetadata.ts +117 -0
- package/src/edit/rules/editKeyboard.ts +222 -0
- package/src/edit/rules/editShortcuts.ts +102 -0
- package/src/edit/rules/editTooltip.ts +174 -0
- package/src/edit/rules/editorTaken.ts +49 -0
- package/src/edit/rules/history.ts +26 -0
- package/src/edit/rules/unsavedWork.ts +60 -0
- package/src/edit/stores/editorReservation.ts +70 -0
- package/src/edit/stores/formsUnsaved.ts +54 -0
- package/src/embed/contracts/embed.ts +48 -0
- package/src/embed/engines/embedFraming.ts +1329 -0
- package/src/embed/engines/embedReady.ts +353 -0
- package/src/embed/engines/framingPageSession.ts +169 -0
- package/src/embed/handlers/embed.ts +130 -0
- package/src/embed/rules/allowedDomains.ts +71 -0
- package/src/embed/rules/bridgeMessages.ts +224 -0
- package/src/embed/rules/defaults.ts +173 -0
- package/src/embed/rules/displaySeed.ts +115 -0
- package/src/embed/rules/embedAllowlist.ts +146 -0
- package/src/embed/rules/embedConstraints.ts +215 -0
- package/src/embed/rules/embedElements.ts +277 -0
- package/src/embed/rules/embedSectionFields.ts +126 -0
- package/src/embed/rules/embedSecurity.ts +116 -0
- package/src/embed/rules/fieldDependencies.ts +89 -0
- package/src/embed/rules/fieldOptions.ts +138 -0
- package/src/embed/rules/layerOptions.ts +161 -0
- package/src/embed/rules/readyProtocol.ts +66 -0
- package/src/embed/rules/safetyRules.ts +215 -0
- package/src/embed/rules/snippet.ts +531 -0
- package/src/embed/rules/tableCode.ts +270 -0
- package/src/embed/stores/embed.ts +60 -0
- package/src/embed/stores/embedContent.ts +77 -0
- package/src/engines/index.ts +81 -0
- package/src/handlers/index.ts +66 -0
- package/src/index.ts +1065 -0
- package/src/itinerary/contracts/itinerary.ts +705 -0
- package/src/itinerary/engines/itineraryPace.ts +612 -0
- package/src/itinerary/engines/profileMarker.ts +238 -0
- package/src/itinerary/handlers/importStaging.ts +352 -0
- package/src/itinerary/handlers/itinerary.ts +572 -0
- package/src/itinerary/handlers/itineraryDuplicate.ts +177 -0
- package/src/itinerary/handlers/itineraryExport.ts +117 -0
- package/src/itinerary/handlers/itineraryImport.ts +783 -0
- package/src/itinerary/handlers/itineraryPublish.ts +118 -0
- package/src/itinerary/handlers/itinerarySelection.ts +354 -0
- package/src/itinerary/handlers/itinerarySuggest.ts +1186 -0
- package/src/itinerary/handlers/itineraryUnpublish.ts +101 -0
- package/src/itinerary/handlers/publicationScope.ts +118 -0
- package/src/itinerary/handlers/restItineraries.ts +752 -0
- package/src/itinerary/handlers/restItineraryExport.ts +70 -0
- package/src/itinerary/handlers/restItineraryImport.ts +311 -0
- package/src/itinerary/handlers/restItineraryPace.ts +87 -0
- package/src/itinerary/handlers/restItineraryRecord.ts +36 -0
- package/src/itinerary/handlers/suggestParams.ts +379 -0
- package/src/itinerary/handlers/suggestStaging.ts +363 -0
- package/src/itinerary/handlers/surfaceOpen.ts +389 -0
- package/src/itinerary/rules/activity.ts +139 -0
- package/src/itinerary/rules/analysis.ts +42 -0
- package/src/itinerary/rules/ceiling.ts +49 -0
- package/src/itinerary/rules/createFlow.ts +107 -0
- package/src/itinerary/rules/densify.ts +440 -0
- package/src/itinerary/rules/draftSurface.ts +219 -0
- package/src/itinerary/rules/editorView.ts +83 -0
- package/src/itinerary/rules/export.ts +159 -0
- package/src/itinerary/rules/friendlyName.ts +77 -0
- package/src/itinerary/rules/import.ts +1050 -0
- package/src/itinerary/rules/importFiles.ts +140 -0
- package/src/itinerary/rules/importTotals.ts +77 -0
- package/src/itinerary/rules/liveSegment.ts +712 -0
- package/src/itinerary/rules/lngLat.ts +17 -0
- package/src/itinerary/rules/mapSync.ts +100 -0
- package/src/itinerary/rules/previewRender.ts +416 -0
- package/src/itinerary/rules/profileReadout.ts +216 -0
- package/src/itinerary/rules/routing.ts +707 -0
- package/src/itinerary/rules/suggest.ts +522 -0
- package/src/itinerary/rules/suggestionPreview.ts +119 -0
- package/src/itinerary/rules/view.ts +61 -0
- package/src/itinerary/stores/importSession.ts +319 -0
- package/src/itinerary/stores/itinerary.ts +331 -0
- package/src/itinerary/stores/itineraryDuplicate.ts +76 -0
- package/src/itinerary/stores/sessionIdentity.ts +43 -0
- package/src/itinerary/stores/suggestSession.ts +418 -0
- package/src/layers/contracts/itinerary.ts +46 -0
- package/src/layers/contracts/overlay.ts +132 -0
- package/src/layers/handlers/enrichment.ts +36 -0
- package/src/layers/handlers/overlay.ts +406 -0
- package/src/layers/handlers/restLayers.ts +94 -0
- package/src/layers/handlers/tiles.ts +25 -0
- package/src/layers/rules/layers.ts +212 -0
- package/src/layers/rules/overlayInstant.ts +12 -0
- package/src/layers/rules/reachabilityIcon.ts +18 -0
- package/src/layers/rules/readout.ts +102 -0
- package/src/layers/stores/layers.ts +262 -0
- package/src/map/contracts/contextmenu.ts +33 -0
- package/src/map/contracts/geolocate.ts +37 -0
- package/src/map/contracts/map.ts +146 -0
- package/src/map/contracts/streetview.ts +53 -0
- package/src/map/contracts/terrain.ts +152 -0
- package/src/map/handlers/contextMenu.ts +135 -0
- package/src/map/handlers/geolocate.ts +52 -0
- package/src/map/handlers/map.ts +391 -0
- package/src/map/handlers/streetview.ts +94 -0
- package/src/map/handlers/terrain.ts +663 -0
- package/src/map/rules/baseTerrain.ts +75 -0
- package/src/map/rules/clickTargets.ts +464 -0
- package/src/map/rules/constraints.ts +32 -0
- package/src/map/rules/contextMenuReadout.ts +67 -0
- package/src/map/rules/coordinates.ts +71 -0
- package/src/map/rules/itineraryFit.ts +8 -0
- package/src/map/rules/mapEvents.ts +64 -0
- package/src/map/rules/mapProjection.ts +476 -0
- package/src/map/rules/terrainReading.ts +62 -0
- package/src/plugins/contracts/ids.ts +66 -0
- package/src/plugins/contracts/plugin.ts +202 -0
- package/src/plugins/contracts/slots.ts +137 -0
- package/src/plugins/engines/studioPlugin.ts +1365 -0
- package/src/plugins/index.ts +111 -0
- package/src/plugins/rules/contributions.ts +152 -0
- package/src/plugins/rules/errors.ts +60 -0
- package/src/plugins/rules/ids.ts +42 -0
- package/src/plugins/rules/validation.ts +249 -0
- package/src/rules/listeners.ts +57 -0
- package/src/rules/origin.ts +13 -0
- package/src/rules/storeWrite.ts +37 -0
- package/src/rules/types.ts +136 -0
- package/src/seams/index.ts +79 -0
- package/src/seams/rules/clock.ts +28 -0
- package/src/seams/rules/formatters.ts +211 -0
- package/src/seams/rules/ids.ts +102 -0
- package/src/seams/rules/links.ts +66 -0
- package/src/seams/rules/navigation.ts +222 -0
- package/src/seams/rules/notify.ts +49 -0
- package/src/seams/rules/persistenceDrawer.ts +220 -0
- package/src/seams/rules/saveFile.ts +101 -0
- package/src/seams/rules/seams.ts +156 -0
- package/src/seams/rules/storage.ts +116 -0
- package/src/search/contracts/overlay.ts +74 -0
- package/src/search/contracts/search.ts +197 -0
- package/src/search/handlers/pois.ts +57 -0
- package/src/search/handlers/search.ts +280 -0
- package/src/search/rules/params.ts +925 -0
- package/src/search/rules/poiGroups.ts +138 -0
- package/src/search/rules/searchFetch.ts +139 -0
- package/src/search/rules/timeWindow.ts +30 -0
- package/src/search/stores/search.ts +51 -0
- package/src/segments/contracts/itinerary.ts +433 -0
- package/src/segments/contracts/segment.ts +35 -0
- package/src/segments/engines/segmentDraft.ts +926 -0
- package/src/segments/handlers/chainGuards.ts +67 -0
- package/src/segments/handlers/directions.ts +44 -0
- package/src/segments/handlers/itineraryEcho.ts +45 -0
- package/src/segments/handlers/roadAccessDialog.ts +34 -0
- package/src/segments/handlers/segment.ts +111 -0
- package/src/segments/handlers/segmentEdit.ts +1341 -0
- package/src/segments/handlers/segmentGroups.ts +347 -0
- package/src/segments/handlers/segmentStructure.ts +1144 -0
- package/src/segments/rules/chain.ts +196 -0
- package/src/segments/rules/chainModel.ts +217 -0
- package/src/segments/rules/colors.ts +11 -0
- package/src/segments/rules/commit.ts +76 -0
- package/src/segments/rules/draft.ts +90 -0
- package/src/segments/rules/draftDisposition.ts +43 -0
- package/src/segments/rules/draftSegmentEdit.ts +129 -0
- package/src/segments/rules/engine.ts +222 -0
- package/src/segments/rules/groupSave.ts +234 -0
- package/src/segments/rules/hazardPrompt.ts +60 -0
- package/src/segments/rules/itineraryEcho.ts +40 -0
- package/src/segments/rules/liveSegmentProjection.ts +55 -0
- package/src/segments/rules/merge.ts +51 -0
- package/src/segments/rules/metrics.ts +456 -0
- package/src/segments/rules/naming.ts +168 -0
- package/src/segments/rules/segmentArming.ts +144 -0
- package/src/segments/rules/splitPick.ts +84 -0
- package/src/segments/rules/viaSimplify.ts +230 -0
- package/src/segments/stores/directions.ts +77 -0
- package/src/segments/stores/roadAccessDialog.ts +58 -0
- package/src/segments/stores/segmentEdit.ts +922 -0
- package/src/segments/stores/segmentGroupEdit.ts +84 -0
- package/src/segments/stores/segmentSplit.ts +77 -0
- package/src/share/contracts/share.ts +39 -0
- package/src/share/contracts/shareLink.ts +63 -0
- package/src/share/engines/shareLink.ts +1053 -0
- package/src/share/handlers/share.ts +47 -0
- package/src/share/handlers/shareLink.ts +231 -0
- package/src/share/handlers/shareScope.ts +54 -0
- package/src/share/rules/link.ts +89 -0
- package/src/share/rules/shareLink.ts +218 -0
- package/src/share/rules/targets.ts +92 -0
- package/src/share/rules/viewConfig.ts +95 -0
- package/src/share/stores/share.ts +58 -0
- package/src/strings/fr/index.ts +18 -0
- package/src/strings/fr/rules/fr.ts +2368 -0
- package/src/strings/index.ts +98 -0
- package/src/strings/rules/confirmCopy.ts +156 -0
- package/src/strings/rules/draftToolNames.ts +94 -0
- package/src/strings/rules/en.ts +2519 -0
- package/src/strings/rules/failureAlert.ts +115 -0
- package/src/strings/rules/formError.ts +400 -0
- package/src/strings/rules/maneuvers.ts +107 -0
- package/src/strings/rules/outputOptions.ts +126 -0
- package/src/strings/rules/publicationState.ts +100 -0
- package/src/strings/rules/routeHazardCopy.ts +62 -0
- package/src/strings/rules/searchLabels.ts +50 -0
- package/src/strings/rules/segmentChainVerbs.ts +62 -0
- package/src/strings/rules/studioCopy.ts +130 -0
- package/src/strings/rules/unitOptions.ts +119 -0
- package/src/testing/checkedBus.ts +226 -0
- package/src/testing/index.ts +30 -0
- package/src/testing/plugins.ts +106 -0
- package/src/testing/studio.ts +267 -0
- package/src/testing/urlSeam.ts +153 -0
- package/src/time/index.ts +12 -0
- package/src/time/rules/sun.ts +78 -0
- package/src/video/contracts/cameraSchemas.ts +266 -0
- package/src/video/contracts/profileSchemas.ts +37 -0
- package/src/video/contracts/video.ts +601 -0
- package/src/video/handlers/video.ts +1638 -0
- package/src/video/handlers/videoDirector.ts +114 -0
- package/src/video/rules/previewRefresh.ts +76 -0
- package/src/video/rules/profileSource.ts +51 -0
- package/src/video/rules/routeSpans.ts +79 -0
- package/src/video/rules/shotDefaults.ts +28 -0
- package/src/video/rules/stepOrder.ts +17 -0
- package/src/video/rules/videoSnapshot.ts +136 -0
- package/src/video/stores/directorThreads.ts +167 -0
- package/src/video/stores/videoExport.ts +290 -0
- package/src/viewer/contracts/preferences.ts +40 -0
- package/src/viewer/handlers/preferences.ts +91 -0
- package/src/viewer/rules/capabilities.ts +42 -0
- package/src/viewer/rules/config.ts +266 -0
- package/src/viewer/rules/context.ts +375 -0
- package/src/viewer/rules/ownership.ts +134 -0
- package/src/viewer/rules/platformViewer.ts +199 -0
- package/src/viewer/rules/scope.ts +197 -0
- package/src/viewer/rules/url.ts +145 -0
- package/src/viewer/rules/viewer.ts +307 -0
- package/src/viewer/rules/viewerSeam.ts +49 -0
- package/src/viewer/rules/viewerUnits.ts +34 -0
- package/src/waypoints/contracts/itinerary.ts +417 -0
- package/src/waypoints/handlers/poiWaypointStyle.ts +32 -0
- package/src/waypoints/handlers/waypointDetailsDialog.ts +38 -0
- package/src/waypoints/handlers/waypointEdit.ts +1073 -0
- package/src/waypoints/rules/amenities.ts +30 -0
- package/src/waypoints/rules/defaults.ts +31 -0
- package/src/waypoints/rules/details.ts +213 -0
- package/src/waypoints/rules/detailsDraft.ts +312 -0
- package/src/waypoints/rules/detailsPreview.ts +76 -0
- package/src/waypoints/rules/detailsSave.ts +356 -0
- package/src/waypoints/rules/draftDirty.ts +45 -0
- package/src/waypoints/rules/icons.ts +32 -0
- package/src/waypoints/rules/liveWaypoint.ts +63 -0
- package/src/waypoints/rules/naming.ts +185 -0
- package/src/waypoints/rules/sections.ts +77 -0
- package/src/waypoints/rules/waypointDraft.ts +62 -0
- package/src/waypoints/stores/waypointDetails.ts +62 -0
- package/src/waypoints/stores/waypointEdit.ts +566 -0
- package/src/zones/contracts/collection.ts +37 -0
- package/src/zones/contracts/zone.ts +528 -0
- package/src/zones/engines/zoneForm.ts +1773 -0
- package/src/zones/handlers/restZones.ts +287 -0
- package/src/zones/handlers/zonePublish.ts +206 -0
- package/src/zones/handlers/zoneUnpublish.ts +56 -0
- package/src/zones/handlers/zones.ts +2254 -0
- package/src/zones/rules/geometry.ts +946 -0
- package/src/zones/rules/zoneDefaults.ts +34 -0
- package/src/zones/rules/zoneDraft.ts +54 -0
- package/src/zones/rules/zoneForm.ts +563 -0
- package/src/zones/rules/zoneMetadata.ts +29 -0
- package/src/zones/rules/zoneSource.ts +87 -0
- package/src/zones/rules/zoneSourceRefusal.ts +104 -0
- package/src/zones/stores/zoneEdit.ts +998 -0
|
@@ -0,0 +1,707 @@
|
|
|
1
|
+
import type { Position } from "geojson";
|
|
2
|
+
import * as z from "zod";
|
|
3
|
+
|
|
4
|
+
import type { Mountaya } from "@mountaya/client";
|
|
5
|
+
import { type RoadAccessKind, roadAccessKindOf } from "@mountaya/elements/data";
|
|
6
|
+
import { wrapLongitudePastRange } from "@mountaya/elements/geo";
|
|
7
|
+
import {
|
|
8
|
+
SEGMENT_ROUTE_REFUSED,
|
|
9
|
+
type SegmentAnalyzeFn,
|
|
10
|
+
type SegmentRoute,
|
|
11
|
+
type SegmentRouteAnalysis,
|
|
12
|
+
type SegmentRouteElevation,
|
|
13
|
+
type SegmentRouteFn,
|
|
14
|
+
} from "@mountaya/elements/seams";
|
|
15
|
+
|
|
16
|
+
import type { GeometryAnalysis, RouteAdvisories } from "../../data/rules/dataTypes.js";
|
|
17
|
+
import { toDataActivity } from "./activity.js";
|
|
18
|
+
import { densifyFreehandLine, lineLengthMeters } from "./densify.js";
|
|
19
|
+
import {
|
|
20
|
+
graphqlAnalysisToEntries,
|
|
21
|
+
graphqlElevationToSummary,
|
|
22
|
+
graphqlRoadAccessToInfo,
|
|
23
|
+
graphqlRouteToLiveRoute,
|
|
24
|
+
routeLineOf,
|
|
25
|
+
} from "./liveSegment.js";
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Routing a segment being edited, over the Data API.
|
|
29
|
+
*
|
|
30
|
+
* {@link SegmentRouteFn} and {@link SegmentAnalyzeFn} are sockets an engine is handed at
|
|
31
|
+
* `beginSegmentEdit`, so an engine routes without knowing what routes. These are the default
|
|
32
|
+
* implementations: they take a `Mountaya` and answer in the shape the engine and the elevation
|
|
33
|
+
* panel both read.
|
|
34
|
+
*
|
|
35
|
+
* They are the default rather than the implementation. A host with its own router supplies its
|
|
36
|
+
* own function against the same contract and never imports this file, which is the entire
|
|
37
|
+
* reason the socket is a parameter rather than a dependency.
|
|
38
|
+
*
|
|
39
|
+
* What does NOT live here is the prompt. `confirmHazards` is injected because a dialog belongs
|
|
40
|
+
* to whoever renders one, and a package that opened one would be deciding a host's interaction
|
|
41
|
+
* design. The memo behind it DOES live here, because it is correctness rather than
|
|
42
|
+
* presentation: without it a route the user already accepted is put to them again on the next
|
|
43
|
+
* drag of a later via.
|
|
44
|
+
*/
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* routeAdvisorySchema is the closed vocabulary of route advisories worth stopping a user for
|
|
48
|
+
* before a placement is adopted, most severe first. Zod-first because the value crosses the
|
|
49
|
+
* routing socket: this module raises it, and whoever prompts resolves it to copy.
|
|
50
|
+
*
|
|
51
|
+
* It names each of the Data API's two hazards the way a reader is told about it. A restricted
|
|
52
|
+
* way is told by the kind of restriction it carries, so the prompt can say who the way is for:
|
|
53
|
+
* the kinds of `ROAD_ACCESS_KINDS` from `@mountaya/elements/data`, the table the tiles stripe
|
|
54
|
+
* the same stretches by. A tollway is one kind of its own. A test pins the two hazards of the
|
|
55
|
+
* wire, and that table, to these members, so a hazard added to the wire or a kind added to the
|
|
56
|
+
* table fails there rather than going unraised.
|
|
57
|
+
*
|
|
58
|
+
* - "forbidden", "private", "permit", "service", "local-access", "restricted": the route
|
|
59
|
+
* crosses a way whose access is restricted, in the kind its access values are grouped into.
|
|
60
|
+
* A permissive, agricultural or forestry way is none of these: the owner tolerates passage on
|
|
61
|
+
* the first, the other two are ordinary terrain on foot, and counting them would prompt on a
|
|
62
|
+
* large share of ordinary hikes.
|
|
63
|
+
* - "tollway": the route crosses a way that charges a toll for this activity's mode of travel.
|
|
64
|
+
*/
|
|
65
|
+
export const routeAdvisorySchema = z.enum([
|
|
66
|
+
// ROAD_ACCESS_KINDS, in its order, spelled out so the contract's walk reads the members.
|
|
67
|
+
"forbidden",
|
|
68
|
+
"private",
|
|
69
|
+
"permit",
|
|
70
|
+
"service",
|
|
71
|
+
"local-access",
|
|
72
|
+
"restricted",
|
|
73
|
+
"tollway",
|
|
74
|
+
]);
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* RouteAdvisory is a single advisory a computed route carries, derived from
|
|
78
|
+
* {@link routeAdvisorySchema}.
|
|
79
|
+
*/
|
|
80
|
+
export type RouteAdvisory = z.infer<typeof routeAdvisorySchema>;
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* RouteHazardMemo is where an edit session remembers which hazard OCCURRENCES the user has
|
|
84
|
+
* already accepted. It is a seam rather than a closure variable, so the answers outlive the
|
|
85
|
+
* routing function.
|
|
86
|
+
*
|
|
87
|
+
* A `Set<string>` of via-set keys living inside {@link buildRouteFn} would be wrong twice over:
|
|
88
|
+
* at the wrong GRANULARITY, since a via-set key changes on any mutation at all, so a point
|
|
89
|
+
* deletion, a pinned-boundary correction and an undo would each ask again; and at the wrong
|
|
90
|
+
* LIFETIME, since `buildRouteFn` is rebuilt every time the segment editor is armed
|
|
91
|
+
* (`SegmentDraftEngine` arms it through `buildSegmentEditOptions`), so a memo inside it would
|
|
92
|
+
* lose every answer at each re-arm.
|
|
93
|
+
*
|
|
94
|
+
* Keying by hazard KIND would overshoot. `advisories.restrictedAccess` is one boolean for the
|
|
95
|
+
* whole route, so the first restricted way the user accepted would silence the question for
|
|
96
|
+
* every later one, and a segment routed through a second unrelated private road would be
|
|
97
|
+
* adopted with no prompt at all. A decision is made about one restricted WAY, so what is
|
|
98
|
+
* remembered is WHERE each hazard is: opaque keys built by `routeHazardOccurrences` from the
|
|
99
|
+
* per-stretch advisory lists, which a holder stores and compares and does not otherwise read.
|
|
100
|
+
*
|
|
101
|
+
* Supplied by whoever owns the session. Absent, the fallback is a memo local to the built
|
|
102
|
+
* function, right for a test or a headless route, which have no session to hang one on.
|
|
103
|
+
*/
|
|
104
|
+
export interface RouteHazardMemo {
|
|
105
|
+
/** Records hazard occurrence keys as accepted for the rest of the session. */
|
|
106
|
+
accept: (keys: readonly string[]) => void;
|
|
107
|
+
/** The occurrence keys already accepted, so a repeat is not put to the user again. */
|
|
108
|
+
accepted: () => readonly string[];
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* RouteHazardOccurrence is ONE hazard the user can be asked about: its kind, and the keys
|
|
113
|
+
* naming where on the ground it is.
|
|
114
|
+
*
|
|
115
|
+
* `keys` is a list rather than one key because a stretch spans many coordinates and a re-route
|
|
116
|
+
* over the same way may enter and leave it at different points: sharing ANY key with an
|
|
117
|
+
* accepted occurrence is what identifies it as the same way.
|
|
118
|
+
*
|
|
119
|
+
* Module-local on purpose: the seam above is keyed by opaque string, so nothing outside this
|
|
120
|
+
* file needs the shape.
|
|
121
|
+
*/
|
|
122
|
+
interface RouteHazardOccurrence {
|
|
123
|
+
readonly keys: readonly string[];
|
|
124
|
+
readonly kind: RouteAdvisory;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* RouteFnOptions tunes the SegmentRouteFn {@link buildRouteFn} builds. Every field is optional
|
|
129
|
+
* so a caller with no prompt surface (a test, a headless route) gets a route adopted with no
|
|
130
|
+
* question asked.
|
|
131
|
+
*/
|
|
132
|
+
interface RouteFnOptions {
|
|
133
|
+
/**
|
|
134
|
+
* confirmHazards is asked to approve a computed route carrying at least one
|
|
135
|
+
* hazard NOT YET ACCEPTED in this session, resolving true to adopt it and false to undo the
|
|
136
|
+
* placement that produced it. Absent, a hazardous route is adopted silently: a
|
|
137
|
+
* package cannot prompt on its own, so the gate exists only where a host supplies one.
|
|
138
|
+
*
|
|
139
|
+
* It is handed only the NEW kinds, not every kind the route carries, so the sentence a host
|
|
140
|
+
* builds names what is actually being asked about.
|
|
141
|
+
*
|
|
142
|
+
* One prompt is open at a time. A route that answers while the reader is still being asked
|
|
143
|
+
* waits for that answer and reads what it accepted, so two routes over one restricted way ask
|
|
144
|
+
* once. A route is asked about whichever call brought it: an engine may keep the route of a
|
|
145
|
+
* call it made before its newest request, so no call is taken for one nobody waits on, but
|
|
146
|
+
* the one whose signal has aborted, which is asked nothing.
|
|
147
|
+
*/
|
|
148
|
+
confirmHazards?: ((hazards: RouteAdvisory[]) => Promise<boolean>) | undefined;
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* hazardMemo is the session's record of accepted hazard occurrences: see
|
|
152
|
+
* {@link RouteHazardMemo}. Absent, the built function keeps its own, which lasts exactly as
|
|
153
|
+
* long as it does.
|
|
154
|
+
*/
|
|
155
|
+
hazardMemo?: RouteHazardMemo | undefined;
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* seedVias are the vias the edit session opened with. Whatever hazards the OPENING shape
|
|
159
|
+
* turns out to carry are pre-accepted when it is first routed: a saved segment that already
|
|
160
|
+
* crosses a restricted way is the state the user arrived in, not a placement they are
|
|
161
|
+
* making, so opening it must not prompt.
|
|
162
|
+
*
|
|
163
|
+
* The hazards cannot be listed up front (they are only known once the shape has been routed),
|
|
164
|
+
* so this stays a via set, compared against the first route's own vias.
|
|
165
|
+
*
|
|
166
|
+
* The opening shape's request is never aborted: the first placement drops it, and its answer
|
|
167
|
+
* is the one place the opening hazards are read.
|
|
168
|
+
*/
|
|
169
|
+
seedVias?: Position[] | undefined;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* localHazardMemo is the fallback {@link RouteHazardMemo}: one that lives and dies with the
|
|
174
|
+
* routing function it was built for. It is the right answer for a caller with no session (a
|
|
175
|
+
* test, a headless route) and the wrong one for an editor, which is why the editor supplies
|
|
176
|
+
* its own.
|
|
177
|
+
*/
|
|
178
|
+
const localHazardMemo = (): RouteHazardMemo => {
|
|
179
|
+
const accepted = new Set<string>();
|
|
180
|
+
|
|
181
|
+
return {
|
|
182
|
+
accept: (keys) => {
|
|
183
|
+
for (const key of keys) {
|
|
184
|
+
accepted.add(key);
|
|
185
|
+
}
|
|
186
|
+
},
|
|
187
|
+
accepted: () => [...accepted],
|
|
188
|
+
};
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* RoutedAnswer is one route as the router answered it: the live route an engine renders, and the
|
|
193
|
+
* hazards it crosses.
|
|
194
|
+
*/
|
|
195
|
+
interface RoutedAnswer {
|
|
196
|
+
readonly occurrences: readonly RouteHazardOccurrence[];
|
|
197
|
+
readonly route: SegmentRoute;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* routedAnswer reads the route the router answers for `vias`, with the hazards it crosses, or
|
|
202
|
+
* null when the router finds none. An unknown slug throws inside the query, as a fault of the
|
|
203
|
+
* transport does.
|
|
204
|
+
*
|
|
205
|
+
* The vias are asked about within the range the wire writes a longitude in
|
|
206
|
+
* ({@link positionWithinRange}): a via placed on a world copy names the same ground.
|
|
207
|
+
*
|
|
208
|
+
* @param signal - Aborts the request, which then rejects with the abort's reason. Left out, the
|
|
209
|
+
* request runs to its answer.
|
|
210
|
+
*/
|
|
211
|
+
const routedAnswer = async (
|
|
212
|
+
graphql: Mountaya,
|
|
213
|
+
activitySlug: string,
|
|
214
|
+
vias: Position[],
|
|
215
|
+
signal?: AbortSignal,
|
|
216
|
+
): Promise<RoutedAnswer | null> => {
|
|
217
|
+
const result = await graphql.data.directions(
|
|
218
|
+
{
|
|
219
|
+
activity: toDataActivity(activitySlug),
|
|
220
|
+
waypoints: vias.map(positionWithinRange),
|
|
221
|
+
},
|
|
222
|
+
{ signal },
|
|
223
|
+
);
|
|
224
|
+
|
|
225
|
+
const found = result.routes[0];
|
|
226
|
+
if (!found) {
|
|
227
|
+
return null;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
// The geometry scalar is a GeoJSON geometry and a routed result is a line, read as one by
|
|
231
|
+
// routeLineOf; graphqlRouteToLiveRoute then projects the metrics and the optional elevation and
|
|
232
|
+
// analysis blocks onto the platform-neutral live-route shape the engine renders.
|
|
233
|
+
const line = routeLineOf(found.geometry);
|
|
234
|
+
|
|
235
|
+
return {
|
|
236
|
+
occurrences: routeHazardOccurrences(found.analysis.advisories, line.coordinates),
|
|
237
|
+
route: graphqlRouteToLiveRoute({
|
|
238
|
+
analysis: found.analysis,
|
|
239
|
+
distance: found.distance,
|
|
240
|
+
duration: found.duration,
|
|
241
|
+
elevation: found.elevation,
|
|
242
|
+
geometry: line,
|
|
243
|
+
}),
|
|
244
|
+
};
|
|
245
|
+
};
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* HazardGate answers whether a routed placement is adopted, given the hazards it crosses: true
|
|
249
|
+
* when it crosses nothing new or the reader says yes, false when the reader declines.
|
|
250
|
+
*/
|
|
251
|
+
type HazardGate = (
|
|
252
|
+
occurrences: readonly RouteHazardOccurrence[],
|
|
253
|
+
signal: AbortSignal | undefined,
|
|
254
|
+
) => Promise<boolean>;
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* hazardGate builds the gate one routing function puts its placements through.
|
|
258
|
+
*
|
|
259
|
+
* One prompt is open at a time. A route that answers while the reader is still being asked waits
|
|
260
|
+
* for that answer and reads what it accepted, so two routes over one restricted way ask once.
|
|
261
|
+
*
|
|
262
|
+
* A route is asked about whichever call brought it. An engine shares a call still in flight with
|
|
263
|
+
* an identical request it makes later and keeps that call's route, so a call another one followed
|
|
264
|
+
* is not a call nobody waits on, and a gate that skipped it would adopt a restricted way the
|
|
265
|
+
* reader was never shown.
|
|
266
|
+
*
|
|
267
|
+
* A call nobody waits on is the one whose signal has aborted: the engine dropped it for a request
|
|
268
|
+
* of other vias, or the edit ended. Its route is a line the reader no longer sees, so the gate
|
|
269
|
+
* asks nothing about it and rejects with the abort's reason, which the engine reads as its own
|
|
270
|
+
* drop. The signal is read as the gate is entered and again once it has waited on an open prompt.
|
|
271
|
+
*
|
|
272
|
+
* With no `confirmHazards` every route is adopted and nothing is recorded.
|
|
273
|
+
*/
|
|
274
|
+
const hazardGate = (
|
|
275
|
+
memo: RouteHazardMemo,
|
|
276
|
+
confirmHazards: RouteFnOptions["confirmHazards"],
|
|
277
|
+
): HazardGate => {
|
|
278
|
+
// The prompt that is open, settled whichever way it ends.
|
|
279
|
+
let openPrompt: Promise<void> | null = null;
|
|
280
|
+
|
|
281
|
+
return async (occurrences, signal) => {
|
|
282
|
+
signal?.throwIfAborted();
|
|
283
|
+
while (openPrompt !== null) {
|
|
284
|
+
await openPrompt;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
// Dropped while it waited: nothing is asked about a line the reader no longer sees.
|
|
288
|
+
signal?.throwIfAborted();
|
|
289
|
+
|
|
290
|
+
// Only what is NEWLY crossed. A route that crosses the same restricted way the user
|
|
291
|
+
// already said yes to is not a new question, and asking it again on every later point,
|
|
292
|
+
// and on every deletion, pinned-boundary correction and undo, none of which is even a
|
|
293
|
+
// placement, would make the prompt read as a malfunction. A route that reaches a
|
|
294
|
+
// DIFFERENT restricted way is a new question, and not asking it would let a segment
|
|
295
|
+
// cross a private road the user was never shown.
|
|
296
|
+
const accepted = new Set(memo.accepted());
|
|
297
|
+
const unaccepted = occurrences.filter(
|
|
298
|
+
(occurrence) => !occurrence.keys.some((key) => accepted.has(key)),
|
|
299
|
+
);
|
|
300
|
+
if (unaccepted.length === 0 || !confirmHazards) {
|
|
301
|
+
return true;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
// The prompt names KINDS, not occurrences: the sentence a host builds says "this route
|
|
305
|
+
// goes through a restricted way", and two restricted ways in one round-trip are one
|
|
306
|
+
// sentence. Deduplicated and ordered by routeAdvisorySchema so the wording does not
|
|
307
|
+
// reshuffle between two routes carrying the same pair.
|
|
308
|
+
const kinds = routeAdvisorySchema.options.filter((kind) =>
|
|
309
|
+
unaccepted.some((occurrence) => occurrence.kind === kind),
|
|
310
|
+
);
|
|
311
|
+
|
|
312
|
+
// The answer is recorded before the prompt is released, so a route that waited on it reads
|
|
313
|
+
// what it accepted.
|
|
314
|
+
let answered: () => void = () => undefined;
|
|
315
|
+
openPrompt = new Promise<void>((resolve) => {
|
|
316
|
+
answered = resolve;
|
|
317
|
+
});
|
|
318
|
+
|
|
319
|
+
try {
|
|
320
|
+
const approved = await confirmHazards(kinds);
|
|
321
|
+
|
|
322
|
+
// A refusal records nothing: the user declined, so placing a via across the same way
|
|
323
|
+
// again asks again rather than having their refusal reinterpreted as consent.
|
|
324
|
+
if (approved) {
|
|
325
|
+
memo.accept(unaccepted.flatMap((occurrence) => occurrence.keys));
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
return approved;
|
|
329
|
+
} finally {
|
|
330
|
+
openPrompt = null;
|
|
331
|
+
answered();
|
|
332
|
+
}
|
|
333
|
+
};
|
|
334
|
+
};
|
|
335
|
+
|
|
336
|
+
/**
|
|
337
|
+
* buildRouteFn builds the SegmentRouteFn the directions edit engine routes through, injected at
|
|
338
|
+
* `beginSegmentEdit` so an engine computes a route without holding a client of its own: it sees
|
|
339
|
+
* this closure and nothing else. It maps the REST activity slug to the Data-API enum and runs the
|
|
340
|
+
* directions query, returning the routed line and metrics, the elevation summary, and the
|
|
341
|
+
* surface, way-type and slope analysis when the router computed them, or null when the router
|
|
342
|
+
* finds no route. The engine is responsible for the via-count floor; an unknown slug throws inside
|
|
343
|
+
* the query (toDataActivity validates it), which the engine absorbs into a cleared route. The
|
|
344
|
+
* geometry scalar is a GeoJSON geometry read as the one line a route is ({@link routeLineOf}),
|
|
345
|
+
* then the shared graphqlRouteToLiveRoute normalizes the analysis to the snake_case indices and
|
|
346
|
+
* REST enum strings the persisted segment carries. `SegmentRoute` IS that live-route shape under
|
|
347
|
+
* the editor's name, so the suggest start-from and the segment editor route through one converter
|
|
348
|
+
* and one type.
|
|
349
|
+
*
|
|
350
|
+
* The function built takes the request's signal as its third argument
|
|
351
|
+
* (`SegmentRouteOptions`). It hands the signal to its request, the opening shape's excepted
|
|
352
|
+
* (see `seedVias`), and reads it once the route has answered, before it asks about a hazard: a
|
|
353
|
+
* request the engine dropped rejects with the abort's reason and raises no prompt. Called with
|
|
354
|
+
* no signal, it is never told that a request was dropped, and asks about every route.
|
|
355
|
+
*/
|
|
356
|
+
export const buildRouteFn = (graphql: Mountaya, options: RouteFnOptions = {}): SegmentRouteFn =>
|
|
357
|
+
(() => {
|
|
358
|
+
// The session's record of which hazard OCCURRENCES have already been accepted, so one
|
|
359
|
+
// restricted way is put to the user once per edit rather than once per placement, and a
|
|
360
|
+
// SECOND restricted way is still put to them. See RouteHazardMemo for why this is a seam
|
|
361
|
+
// and why it is keyed by occurrence rather than by kind.
|
|
362
|
+
const memo = options.hazardMemo ?? localHazardMemo();
|
|
363
|
+
const adopts = hazardGate(memo, options.confirmHazards);
|
|
364
|
+
|
|
365
|
+
// The opening shape's own hazards are pre-accepted, but they are not known until it has
|
|
366
|
+
// been routed, so the seed is matched by via set on the first route that comes back and
|
|
367
|
+
// whatever IT carries is recorded. Consumed after that first match, so a later placement
|
|
368
|
+
// that happens to land back on the seeded shape is treated as a placement.
|
|
369
|
+
let seedKey =
|
|
370
|
+
options.seedVias && options.seedVias.length > 0 ? viaSetKey(options.seedVias) : null;
|
|
371
|
+
|
|
372
|
+
// The opening shape's route while it is out, settled whichever way it ends. A placement
|
|
373
|
+
// routed meanwhile may answer first, and what the reader arrived on is not known until
|
|
374
|
+
// this has: such a placement waits for it before it reads what is accepted.
|
|
375
|
+
let openingRoute: Promise<void> | null = null;
|
|
376
|
+
|
|
377
|
+
return async (activitySlug, vias, request) => {
|
|
378
|
+
const opening = seedKey !== null && openingRoute === null && seedKey === viaSetKey(vias);
|
|
379
|
+
let openingAnswered: () => void = () => undefined;
|
|
380
|
+
if (opening) {
|
|
381
|
+
openingRoute = new Promise<void>((resolve) => {
|
|
382
|
+
openingAnswered = resolve;
|
|
383
|
+
});
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
let answer: RoutedAnswer | null;
|
|
387
|
+
try {
|
|
388
|
+
// The opening shape's request runs to its answer whatever becomes of its signal: the
|
|
389
|
+
// first placement drops it, and what the reader arrived on is learned from it alone.
|
|
390
|
+
answer = await routedAnswer(
|
|
391
|
+
graphql,
|
|
392
|
+
activitySlug,
|
|
393
|
+
vias,
|
|
394
|
+
opening ? undefined : request?.signal,
|
|
395
|
+
);
|
|
396
|
+
|
|
397
|
+
// Opening a saved segment that already crosses a restricted way is the state the user
|
|
398
|
+
// arrived in, not a placement they are making, so its hazards are adopted silently. A
|
|
399
|
+
// request that failed or found no route leaves the seed to be matched again.
|
|
400
|
+
if (answer && opening) {
|
|
401
|
+
seedKey = null;
|
|
402
|
+
memo.accept(answer.occurrences.flatMap((occurrence) => occurrence.keys));
|
|
403
|
+
}
|
|
404
|
+
} finally {
|
|
405
|
+
if (opening) {
|
|
406
|
+
openingRoute = null;
|
|
407
|
+
openingAnswered();
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
if (!answer) {
|
|
412
|
+
return null;
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
if (opening) {
|
|
416
|
+
return answer.route;
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
if (openingRoute !== null) {
|
|
420
|
+
await openingRoute;
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
return (await adopts(answer.occurrences, request?.signal))
|
|
424
|
+
? answer.route
|
|
425
|
+
: SEGMENT_ROUTE_REFUSED;
|
|
426
|
+
};
|
|
427
|
+
})();
|
|
428
|
+
|
|
429
|
+
/**
|
|
430
|
+
* viaSetKey serializes a via array into a stable memo key. Rounding to 6 decimal
|
|
431
|
+
* places (~11 cm) absorbs the float noise a round-trip through the SDK and the
|
|
432
|
+
* wire introduces, so the set restored by a revert keys identically to the set
|
|
433
|
+
* that was accepted, where an exact-equality key would miss and re-prompt. Each via is keyed
|
|
434
|
+
* within the wire's range of longitudes, so a shape stated on a world copy keys as the ground it
|
|
435
|
+
* names.
|
|
436
|
+
*/
|
|
437
|
+
const viaSetKey = (vias: Position[]): string =>
|
|
438
|
+
vias
|
|
439
|
+
.map(positionWithinRange)
|
|
440
|
+
.map((via) => `${via[0]?.toFixed(6)},${via[1]?.toFixed(6)}`)
|
|
441
|
+
.join(";");
|
|
442
|
+
|
|
443
|
+
/**
|
|
444
|
+
* positionWithinRange answers a position with its longitude within [-180, 180], the range the
|
|
445
|
+
* wire writes one in, and everything after the longitude as it came.
|
|
446
|
+
*
|
|
447
|
+
* A line drawn on a copy of the world a map repeats east or west carries longitudes a whole
|
|
448
|
+
* number of turns away from the ground they name. The Data API reads a longitude as written, so
|
|
449
|
+
* a via and a drawn vertex are brought back by whole turns before they are sent
|
|
450
|
+
* (`wrapLongitudePastRange`, which keeps a longitude already in range to the digit).
|
|
451
|
+
*/
|
|
452
|
+
const positionWithinRange = (position: Position): Position => {
|
|
453
|
+
const [longitude, ...rest] = position;
|
|
454
|
+
|
|
455
|
+
return longitude === undefined ? [] : [wrapLongitudePastRange(longitude), ...rest];
|
|
456
|
+
};
|
|
457
|
+
|
|
458
|
+
/**
|
|
459
|
+
* HAZARD_CELL_DECIMALS is the grid a hazard stretch's coordinates are rounded onto to identify
|
|
460
|
+
* WHICH way it is: three decimal places, a cell of roughly 110m north-south and 70-80m
|
|
461
|
+
* east-west at Alpine latitudes.
|
|
462
|
+
*
|
|
463
|
+
* The number is the whole of the identity, so it is chosen against both ways of being wrong.
|
|
464
|
+
* Too fine and the same way re-entered from a different via reads as a new one, which is the
|
|
465
|
+
* re-prompting malfunction this memo exists to stop. Too coarse and a genuinely different
|
|
466
|
+
* restricted way a few hundred meters away reads as the one already accepted, which is the
|
|
467
|
+
* missed prompt.
|
|
468
|
+
*
|
|
469
|
+
* Three decimals is comfortably on the safe side of both: a re-route over the same way returns
|
|
470
|
+
* the SAME OSM node coordinates (the router is deterministic and the way geometry is fixed), so
|
|
471
|
+
* matching there does not depend on the tolerance at all. It only has to survive the router
|
|
472
|
+
* entering the stretch at a different point, which sharing any one cell of a multi-coordinate
|
|
473
|
+
* stretch does. And two distinct ways closer together than one cell are, for the purpose of
|
|
474
|
+
* "did I already agree to walk through here", the same place.
|
|
475
|
+
*/
|
|
476
|
+
const HAZARD_CELL_DECIMALS = 3;
|
|
477
|
+
|
|
478
|
+
/**
|
|
479
|
+
* hazardCellKeys turns one advisory stretch into the keys naming where it is: one per
|
|
480
|
+
* coordinate in the stretch, rounded onto the {@link HAZARD_CELL_DECIMALS} grid and prefixed
|
|
481
|
+
* with the hazard kind, so a tollway and a restricted way sharing a cell stay two decisions.
|
|
482
|
+
*
|
|
483
|
+
* The indices are inclusive on both ends and come off the wire, so they are clamped rather than
|
|
484
|
+
* trusted: a stretch naming a coordinate the geometry does not have would otherwise put
|
|
485
|
+
* `undefined` in a key and make two unrelated stretches match.
|
|
486
|
+
*/
|
|
487
|
+
const hazardCellKeys = (
|
|
488
|
+
kind: RouteAdvisory,
|
|
489
|
+
coordinates: Position[],
|
|
490
|
+
fromIndex: number,
|
|
491
|
+
toIndex: number,
|
|
492
|
+
): string[] => {
|
|
493
|
+
const first = Math.max(0, Math.min(fromIndex, toIndex));
|
|
494
|
+
const last = Math.min(coordinates.length - 1, Math.max(fromIndex, toIndex));
|
|
495
|
+
|
|
496
|
+
const keys: string[] = [];
|
|
497
|
+
for (let index = first; index <= last; index += 1) {
|
|
498
|
+
const [lng, lat] = coordinates[index] ?? [];
|
|
499
|
+
if (lng === undefined || lat === undefined) {
|
|
500
|
+
continue;
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
keys.push(`${kind}@${lng.toFixed(HAZARD_CELL_DECIMALS)},${lat.toFixed(HAZARD_CELL_DECIMALS)}`);
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
return keys;
|
|
507
|
+
};
|
|
508
|
+
|
|
509
|
+
/**
|
|
510
|
+
* anywhereKey is the key a hazard gets when the route carries the FLAG but no stretches to
|
|
511
|
+
* place it with, which the wire documents as a real case: "a flag can be true while its info
|
|
512
|
+
* list is empty on a routing graph that raises the warning without carrying the per-stretch
|
|
513
|
+
* data".
|
|
514
|
+
*
|
|
515
|
+
* It restores the kind-wide behaviour for exactly that graph: one prompt per kind per edit,
|
|
516
|
+
* because there is nothing to tell two occurrences apart with. That is a deliberate floor
|
|
517
|
+
* rather than a fix: a graph that cannot say WHERE a hazard is cannot support asking about a
|
|
518
|
+
* second one, and asking again with the same sentence and no new information would read as the
|
|
519
|
+
* malfunction this memo exists to stop.
|
|
520
|
+
*/
|
|
521
|
+
const anywhereKey = (kind: RouteAdvisory): string => `${kind}@*`;
|
|
522
|
+
|
|
523
|
+
/**
|
|
524
|
+
* UNPLACED_ACCESS_KIND is the kind a restricted-access flag is told as when no stretch says which
|
|
525
|
+
* restriction it is: the least specific one, which promises nothing about who the way is for.
|
|
526
|
+
*/
|
|
527
|
+
const UNPLACED_ACCESS_KIND: RoadAccessKind = "restricted";
|
|
528
|
+
|
|
529
|
+
/**
|
|
530
|
+
* routeHazardOccurrences names every hazard on a computed route that is worth stopping a user
|
|
531
|
+
* for, as a separately-answerable occurrence carrying the keys that identify WHERE it is.
|
|
532
|
+
*
|
|
533
|
+
* The BOOLEAN decides whether a kind is present at all, not the stretch list: the router raises
|
|
534
|
+
* the flags from data it computes on every request, while the stretches only exist on a graph
|
|
535
|
+
* carrying the backing encoded values. So a raised flag always yields at least one occurrence,
|
|
536
|
+
* and the stretches, when there are any, are what split it into the separate decisions.
|
|
537
|
+
*
|
|
538
|
+
* A restricted stretch is told as the kind `roadAccessKindOf` groups its values into, the kind
|
|
539
|
+
* the tiles stripe it as, and a stretch whose values name no kind is dropped on the way through.
|
|
540
|
+
* PERMISSIVE, AGRICULTURAL and FORESTRY name none: they appear in `roadAccessInfo` because the
|
|
541
|
+
* list is informational, but the owner TOLERATES passage on the first and the other two are
|
|
542
|
+
* ordinary terrain on foot, and none raises the flag. Counting them would raise an occurrence
|
|
543
|
+
* for a stretch the flag never named, and on a route whose only access info is one of them, it
|
|
544
|
+
* would invent a hazard out of a route that has none. Each kind is placed by its own stretches,
|
|
545
|
+
* as one kind of hazard is, and a raised flag whose stretches name no kind at all is told as
|
|
546
|
+
* `restricted`, anywhere on the route.
|
|
547
|
+
*/
|
|
548
|
+
const routeHazardOccurrences = (
|
|
549
|
+
advisories: RouteAdvisories,
|
|
550
|
+
coordinates: Position[],
|
|
551
|
+
): RouteHazardOccurrence[] => {
|
|
552
|
+
const occurrences: RouteHazardOccurrence[] = [];
|
|
553
|
+
|
|
554
|
+
if (advisories.restrictedAccess) {
|
|
555
|
+
const stretchesByKind = new Map<RoadAccessKind, (readonly [number, number])[]>();
|
|
556
|
+
for (const info of advisories.roadAccessInfo) {
|
|
557
|
+
const kind = roadAccessKindOf(info.values);
|
|
558
|
+
if (kind !== null) {
|
|
559
|
+
const stretches = stretchesByKind.get(kind) ?? [];
|
|
560
|
+
stretches.push([info.fromIndex, info.toIndex]);
|
|
561
|
+
stretchesByKind.set(kind, stretches);
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
// The flag stands whatever the stretches say, so a flag no stretch names a kind for is told
|
|
566
|
+
// as the least specific kind, with nothing to place it by.
|
|
567
|
+
if (stretchesByKind.size === 0) {
|
|
568
|
+
stretchesByKind.set(UNPLACED_ACCESS_KIND, []);
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
for (const [kind, stretches] of stretchesByKind) {
|
|
572
|
+
occurrences.push(...placedOccurrences(kind, coordinates, stretches));
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
if (advisories.tollway) {
|
|
577
|
+
const stretches = advisories.tollwayInfo.filter((info) => info.value === "TOLLWAY");
|
|
578
|
+
|
|
579
|
+
occurrences.push(
|
|
580
|
+
...placedOccurrences(
|
|
581
|
+
"tollway",
|
|
582
|
+
coordinates,
|
|
583
|
+
stretches.map((info) => [info.fromIndex, info.toIndex] as const),
|
|
584
|
+
),
|
|
585
|
+
);
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
return occurrences;
|
|
589
|
+
};
|
|
590
|
+
|
|
591
|
+
/**
|
|
592
|
+
* placedOccurrences projects one kind's qualifying stretches into occurrences, falling back to
|
|
593
|
+
* a single {@link anywhereKey} one when there is nothing to place it with.
|
|
594
|
+
*
|
|
595
|
+
* A stretch whose indices fall outside the geometry yields no keys and is dropped; a kind whose
|
|
596
|
+
* every stretch drops out is unplaceable and takes the fallback, so a hazard the flag raised is
|
|
597
|
+
* never silently lost on the way to the prompt.
|
|
598
|
+
*/
|
|
599
|
+
const placedOccurrences = (
|
|
600
|
+
kind: RouteAdvisory,
|
|
601
|
+
coordinates: Position[],
|
|
602
|
+
stretches: readonly (readonly [number, number])[],
|
|
603
|
+
): RouteHazardOccurrence[] => {
|
|
604
|
+
const placed = stretches
|
|
605
|
+
.map((stretch) => hazardCellKeys(kind, coordinates, stretch[0], stretch[1]))
|
|
606
|
+
.filter((keys) => keys.length > 0)
|
|
607
|
+
.map((keys) => ({ keys, kind }));
|
|
608
|
+
|
|
609
|
+
return placed.length > 0 ? placed : [{ keys: [anywhereKey(kind)], kind }];
|
|
610
|
+
};
|
|
611
|
+
|
|
612
|
+
/**
|
|
613
|
+
* buildAnalyzeFn builds the SegmentAnalyzeFn the freehand-linestring edit engine resolves its
|
|
614
|
+
* live elevation profile through, injected at `beginSegmentEdit` so an engine computes the
|
|
615
|
+
* profile without holding a client of its own. It is the linestring twin of buildRouteFn: where
|
|
616
|
+
* the directions fn snaps vias to a routed line, this analyzes the DRAWN line.
|
|
617
|
+
*
|
|
618
|
+
* It first densifies the drawn line to a fixed ground spacing so the profile follows the terrain
|
|
619
|
+
* between the sparse drawn vias rather than interpolating flat across a long edge. It is the
|
|
620
|
+
* densification the segment-save path applies, budget included ({@link densifyFreehandLine}):
|
|
621
|
+
* the sample budget of the line's length, shortened where the line and the vertices kept beside
|
|
622
|
+
* it would pass the position ceiling a segment write takes, so a long line drawn with a few
|
|
623
|
+
* thousand vertices is sampled as coarsely live as once saved, and the live and persisted
|
|
624
|
+
* profiles match. The densified line is within the wire's range of longitudes, a line drawn on a
|
|
625
|
+
* world copy included, and it is what the query and the answer's geometry carry.
|
|
626
|
+
*
|
|
627
|
+
* It maps the REST activity slug to the Data-API enum, runs the analyzeGeometry query for the
|
|
628
|
+
* DENSIFIED coordinates, and builds a SegmentRoute whose geometry is that densified line zipped
|
|
629
|
+
* with the per-coordinate `elevations` (each [lng, lat] gains its altitude → a 3D LineString),
|
|
630
|
+
* whose distance is the densified line's great-circle length (equal to the drawn line's by
|
|
631
|
+
* construction, since densifying rides the same arc), whose duration is the one the query
|
|
632
|
+
* integrated over the ground it just read (freehand is UNROUTED, not untimed: the same
|
|
633
|
+
* travel-time model a directions segment's duration comes from, so a drawn line and the segment
|
|
634
|
+
* it becomes agree), and whose elevation + surface/way-type/slope analysis and restricted
|
|
635
|
+
* stretches are normalized exactly as buildRouteFn does, so the live preview projects onto the
|
|
636
|
+
* panel's ItinerarySegment-shaped model without a second translation. A freehand line is never
|
|
637
|
+
* put to the hazard prompt: it follows no way the router chose, so its stretches are shown and
|
|
638
|
+
* never asked about.
|
|
639
|
+
*
|
|
640
|
+
* It resolves to null below the two-point floor (a single point cannot describe a line) and
|
|
641
|
+
* absorbs a thrown query (an unknown slug, a transport error, a partial response) into null,
|
|
642
|
+
* the same NoRoute-style absorption buildRouteFn does, so the engine renders a cleared profile
|
|
643
|
+
* rather than surfacing the error.
|
|
644
|
+
*/
|
|
645
|
+
export const buildAnalyzeFn =
|
|
646
|
+
(graphql: Mountaya): SegmentAnalyzeFn =>
|
|
647
|
+
async (activitySlug, line) => {
|
|
648
|
+
if (line.length < 2) {
|
|
649
|
+
return null;
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
// Densify the drawn line to a fixed ground spacing BEFORE analyzing so the
|
|
653
|
+
// profile samples the terrain every ~50m rather than interpolating flat across
|
|
654
|
+
// a long hand-drawn edge. The saved line is densified the same way and within the
|
|
655
|
+
// same budget, so the live preview and the persisted profile sample matching points.
|
|
656
|
+
const densified = densifyFreehandLine(line);
|
|
657
|
+
|
|
658
|
+
// The operation answers with a RESULT that carries the analysis AND the duration the
|
|
659
|
+
// travel-time model integrated over it, not with the analysis alone. Both are unwrapped
|
|
660
|
+
// here rather than threaded through, because everything below reads one or the other and
|
|
661
|
+
// a wrapper at each site would say nothing about the operation's shape.
|
|
662
|
+
let result: GeometryAnalysis;
|
|
663
|
+
let duration: number;
|
|
664
|
+
try {
|
|
665
|
+
const answer = await graphql.data.analyzeGeometry({
|
|
666
|
+
activity: toDataActivity(activitySlug),
|
|
667
|
+
coordinates: densified.map((coordinate) => [...coordinate]),
|
|
668
|
+
});
|
|
669
|
+
result = answer.analysis;
|
|
670
|
+
duration = answer.duration;
|
|
671
|
+
} catch {
|
|
672
|
+
return null;
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
// Zip each densified coordinate with its matching altitude; the server returns
|
|
676
|
+
// one elevation per input coordinate in order, so a present entry lifts the
|
|
677
|
+
// [lng, lat] to a 3D [lng, lat, ele]. A missing entry (a length mismatch on a
|
|
678
|
+
// partial response) leaves the pair 2D rather than forcing a zero altitude.
|
|
679
|
+
const coordinates3d: Position[] = densified.map((coordinate, index) => {
|
|
680
|
+
const altitude = result.elevations[index];
|
|
681
|
+
return altitude === undefined
|
|
682
|
+
? [coordinate[0] ?? 0, coordinate[1] ?? 0]
|
|
683
|
+
: [coordinate[0] ?? 0, coordinate[1] ?? 0, altitude];
|
|
684
|
+
});
|
|
685
|
+
|
|
686
|
+
// The analyzed line is the densified drawn geometry (not a routed line), so the
|
|
687
|
+
// shared converters project only the elevation summary + analysis blocks onto
|
|
688
|
+
// the segment shape: the geometry is the 3D-zipped densified line and the
|
|
689
|
+
// distance is that line's own great-circle length, equal to the drawn line's since
|
|
690
|
+
// densifying inserts points along the same arc. Freehand carries no ROUTED distance,
|
|
691
|
+
// and the distance above is why it needs none; the duration is the query's own, over
|
|
692
|
+
// the ground it just analyzed rather than over a snapped line.
|
|
693
|
+
const elevation: SegmentRouteElevation = graphqlElevationToSummary(result.elevation);
|
|
694
|
+
const analysis: SegmentRouteAnalysis = graphqlAnalysisToEntries(result);
|
|
695
|
+
|
|
696
|
+
const segmentRoute: SegmentRoute = {
|
|
697
|
+
analysis,
|
|
698
|
+
distance: lineLengthMeters(densified),
|
|
699
|
+
duration,
|
|
700
|
+
elevation,
|
|
701
|
+
geometry: { coordinates: coordinates3d, type: "LineString" },
|
|
702
|
+
// The stretches index the densified line the query read, which is the geometry above.
|
|
703
|
+
roadAccessInfo: graphqlRoadAccessToInfo(result.advisories),
|
|
704
|
+
};
|
|
705
|
+
|
|
706
|
+
return segmentRoute;
|
|
707
|
+
};
|