@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,712 @@
|
|
|
1
|
+
import type { Geometry, GeometryCollection, LineString } from "geojson";
|
|
2
|
+
import * as z from "zod";
|
|
3
|
+
|
|
4
|
+
import type { DataSchema, RestSchema } from "@mountaya/client";
|
|
5
|
+
import type { ItinerarySegment } from "@mountaya/elements/data";
|
|
6
|
+
import { extractLines, segmentLineCoordinates } from "@mountaya/elements/geo";
|
|
7
|
+
import type { IndexedInfo } from "@mountaya/elements/profile";
|
|
8
|
+
|
|
9
|
+
import type {
|
|
10
|
+
SurfaceType as DataSurfaceType,
|
|
11
|
+
TrailDifficultyType as DataTrailDifficultyType,
|
|
12
|
+
WayType as DataWayType,
|
|
13
|
+
ElevationSummary,
|
|
14
|
+
GeometryAnalysis,
|
|
15
|
+
RouteAdvisories,
|
|
16
|
+
SlopeInfo,
|
|
17
|
+
SpeedInfo,
|
|
18
|
+
SurfaceInfo,
|
|
19
|
+
TrailDifficultyInfo,
|
|
20
|
+
WayTypeInfo,
|
|
21
|
+
} from "../../data/rules/dataTypes.js";
|
|
22
|
+
import type { SurfaceType, TrailDifficultyType, WayType } from "../../rules/types.js";
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* LiveSegmentRouteElevation is the per-route elevation summary the live preview carries: the
|
|
26
|
+
* altitude range along the route (meters above sea level), the total elevation gain/loss
|
|
27
|
+
* (meters), and the steepest ascending/descending gradients (degrees). It mirrors
|
|
28
|
+
* `SegmentRouteElevation` of `@mountaya/elements/seams`.
|
|
29
|
+
*/
|
|
30
|
+
export interface LiveSegmentRouteElevation {
|
|
31
|
+
altitudeMax: number;
|
|
32
|
+
altitudeMin: number;
|
|
33
|
+
ascent: number;
|
|
34
|
+
descent: number;
|
|
35
|
+
gradientMax: number;
|
|
36
|
+
gradientMin: number;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* LiveSegmentRouteAnalysis is the surface/way-type/slope/trail-difficulty/speed
|
|
41
|
+
* analysis the live preview carries. Each list classifies a coordinate-index
|
|
42
|
+
* window within the route's geometry; absent when the router did not compute the
|
|
43
|
+
* analysis. The entry shape matches the persisted ItinerarySegment analysis
|
|
44
|
+
* arrays exactly (snake_case indices, REST-vocabulary value) so the projector
|
|
45
|
+
* copies them straight onto the segment without a second translation.
|
|
46
|
+
*
|
|
47
|
+
* `speedInfo` is the resolved travel speed (km/h) over each stretch: what the
|
|
48
|
+
* segment travels at there, not the flat pace it was asked for. Carrying it live is
|
|
49
|
+
* what lets a drag band the speed cell immediately rather than only after the commit's
|
|
50
|
+
* refetch; it is a plain number like `slopeInfo`, so it needs no vocabulary mapping.
|
|
51
|
+
*
|
|
52
|
+
* Every member of this interface must appear in {@link liveSegmentRouteAnalysisSchema}
|
|
53
|
+
* and in `graphqlAnalysisToEntries`, and `liveSegment.test.ts` pins the set against the
|
|
54
|
+
* wire `GeometryAnalysis` so a band added upstream cannot go unprojected.
|
|
55
|
+
*/
|
|
56
|
+
export interface LiveSegmentRouteAnalysis {
|
|
57
|
+
slopeInfo: IndexedInfo<number>[];
|
|
58
|
+
speedInfo: IndexedInfo<number>[];
|
|
59
|
+
surfaceInfo: IndexedInfo<SurfaceType>[];
|
|
60
|
+
trailDifficultyInfo: IndexedInfo<TrailDifficultyType>[];
|
|
61
|
+
wayTypeInfo: IndexedInfo<WayType>[];
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* surfaceTypes is every surface a persisted segment names the contract declares, each keyed by
|
|
66
|
+
* itself.
|
|
67
|
+
*
|
|
68
|
+
* The `satisfies` clause ties it to the generated `RestSchema.SurfaceType` in both directions: a
|
|
69
|
+
* member the contract adds leaves a missing key, and a key the contract does not declare is an
|
|
70
|
+
* excess property of the literal, so `tsc` fails either way.
|
|
71
|
+
*/
|
|
72
|
+
const surfaceTypes = {
|
|
73
|
+
unknown: "unknown",
|
|
74
|
+
paved: "paved",
|
|
75
|
+
unpaved: "unpaved",
|
|
76
|
+
asphalt: "asphalt",
|
|
77
|
+
concrete: "concrete",
|
|
78
|
+
cobblestone: "cobblestone",
|
|
79
|
+
metal: "metal",
|
|
80
|
+
wood: "wood",
|
|
81
|
+
"compacted-gravel": "compacted-gravel",
|
|
82
|
+
"fine-gravel": "fine-gravel",
|
|
83
|
+
gravel: "gravel",
|
|
84
|
+
dirt: "dirt",
|
|
85
|
+
ground: "ground",
|
|
86
|
+
ice: "ice",
|
|
87
|
+
"paving-stones": "paving-stones",
|
|
88
|
+
sand: "sand",
|
|
89
|
+
woodchips: "woodchips",
|
|
90
|
+
grass: "grass",
|
|
91
|
+
"grass-paver": "grass-paver",
|
|
92
|
+
} as const satisfies { [K in RestSchema.SurfaceType]: K };
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* surfaceTypeSchema is the surface-classification vocabulary an analysis band carries: the
|
|
96
|
+
* REST surface_info enum (lower-case, hyphenated) the persisted ItinerarySegment uses, which
|
|
97
|
+
* the wire conversion already normalized the UPPER_CASE Data-API value to. Pinned to the wire
|
|
98
|
+
* SurfaceType via `satisfies` so the accepted set cannot drift from the persisted enum the panel
|
|
99
|
+
* renders.
|
|
100
|
+
*/
|
|
101
|
+
export const surfaceTypeSchema = z.enum(surfaceTypes);
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* wayTypes is every way type a persisted segment names the contract declares, each keyed by itself.
|
|
105
|
+
*
|
|
106
|
+
* The `satisfies` clause ties it to the generated `RestSchema.WayType` in both directions: a
|
|
107
|
+
* member the contract adds leaves a missing key, and a key the contract does not declare is an
|
|
108
|
+
* excess property of the literal, so `tsc` fails either way.
|
|
109
|
+
*/
|
|
110
|
+
const wayTypes = {
|
|
111
|
+
unknown: "unknown",
|
|
112
|
+
"state-road": "state-road",
|
|
113
|
+
road: "road",
|
|
114
|
+
street: "street",
|
|
115
|
+
path: "path",
|
|
116
|
+
track: "track",
|
|
117
|
+
cycleway: "cycleway",
|
|
118
|
+
footway: "footway",
|
|
119
|
+
steps: "steps",
|
|
120
|
+
ferry: "ferry",
|
|
121
|
+
construction: "construction",
|
|
122
|
+
} as const satisfies { [K in RestSchema.WayType]: K };
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* wayTypeSchema is the way-type-classification vocabulary an analysis band carries: the REST
|
|
126
|
+
* way_type_info enum the persisted segment uses, normalized from the Data-API value by the wire
|
|
127
|
+
* conversion. Pinned to the wire WayType via `satisfies` so the two cannot drift.
|
|
128
|
+
*/
|
|
129
|
+
export const wayTypeSchema = z.enum(wayTypes);
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* trailDifficultyTypes is every trail difficulty a persisted segment names the contract declares,
|
|
133
|
+
* each keyed by itself.
|
|
134
|
+
*
|
|
135
|
+
* The `satisfies` clause ties it to the generated `RestSchema.TrailDifficultyType` in both
|
|
136
|
+
* directions: a member the contract adds leaves a missing key, and a key the contract does not
|
|
137
|
+
* declare is an excess property of the literal, so `tsc` fails either way.
|
|
138
|
+
*/
|
|
139
|
+
const trailDifficultyTypes = {
|
|
140
|
+
unknown: "unknown",
|
|
141
|
+
hiking: "hiking",
|
|
142
|
+
"mountain-hiking": "mountain-hiking",
|
|
143
|
+
"demanding-mountain-hiking": "demanding-mountain-hiking",
|
|
144
|
+
"alpine-hiking": "alpine-hiking",
|
|
145
|
+
"demanding-alpine-hiking": "demanding-alpine-hiking",
|
|
146
|
+
"difficult-alpine-hiking": "difficult-alpine-hiking",
|
|
147
|
+
"mtb-0": "mtb-0",
|
|
148
|
+
"mtb-1": "mtb-1",
|
|
149
|
+
"mtb-2": "mtb-2",
|
|
150
|
+
"mtb-3": "mtb-3",
|
|
151
|
+
"mtb-4": "mtb-4",
|
|
152
|
+
"mtb-5": "mtb-5",
|
|
153
|
+
"mtb-6": "mtb-6",
|
|
154
|
+
} as const satisfies { [K in RestSchema.TrailDifficultyType]: K };
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* trailDifficultyTypeSchema is the trail-difficulty vocabulary an analysis band carries: the
|
|
158
|
+
* REST trail_difficulty_info enum the persisted segment uses, normalized from the Data-API value
|
|
159
|
+
* by the wire conversion. It holds both grading scales: a walking activity is graded on the SAC
|
|
160
|
+
* hiking scale and a cycling one on the mountain-biking scale, and the value names which, so a
|
|
161
|
+
* reader never needs the activity. Pinned to the wire TrailDifficultyType via `satisfies` so the
|
|
162
|
+
* two cannot drift.
|
|
163
|
+
*/
|
|
164
|
+
export const trailDifficultyTypeSchema = z.enum(trailDifficultyTypes);
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* indexedInfoSchema builds the coordinate-index-ranged analysis-entry schema for
|
|
168
|
+
* a given value type: the inclusive [from_index, to_index] window into the
|
|
169
|
+
* route's coordinates and the classified value. It mirrors the IndexedInfo shape
|
|
170
|
+
* the elevation panel reads, parameterized by the per-kind value schema so one
|
|
171
|
+
* builder serves the surface/way-type (enum) and slope (number) arrays.
|
|
172
|
+
*
|
|
173
|
+
* Published because the same window is parsed at two boundaries (a routed result
|
|
174
|
+
* on its way into a live segment, and an import preview on its way into a draft),
|
|
175
|
+
* and both classify against the enums beside it. A second builder would agree with
|
|
176
|
+
* this one until one of them learned that an index is an integer.
|
|
177
|
+
*/
|
|
178
|
+
export const indexedInfoSchema = <T extends z.ZodTypeAny>(value: T) =>
|
|
179
|
+
z.object({
|
|
180
|
+
from_index: z.number().int(),
|
|
181
|
+
to_index: z.number().int(),
|
|
182
|
+
value,
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* liveSegmentRouteAnalysisSchema validates the surface/way-type/slope/
|
|
187
|
+
* trail-difficulty analysis a routed result carries once it is converted to the
|
|
188
|
+
* snake_case indices + REST vocabulary the persisted segment uses. It is the
|
|
189
|
+
* wire→session boundary validator the import + suggest drafts share, pinned to
|
|
190
|
+
* LiveSegmentRouteAnalysis via `satisfies` so the validated shape and the
|
|
191
|
+
* projected shape cannot drift.
|
|
192
|
+
*/
|
|
193
|
+
export const liveSegmentRouteAnalysisSchema = z.object({
|
|
194
|
+
slopeInfo: z.array(indexedInfoSchema(z.number())),
|
|
195
|
+
speedInfo: z.array(indexedInfoSchema(z.number())),
|
|
196
|
+
surfaceInfo: z.array(indexedInfoSchema(surfaceTypeSchema)),
|
|
197
|
+
trailDifficultyInfo: z.array(indexedInfoSchema(trailDifficultyTypeSchema)),
|
|
198
|
+
wayTypeInfo: z.array(indexedInfoSchema(wayTypeSchema)),
|
|
199
|
+
}) satisfies z.ZodType<LiveSegmentRouteAnalysis>;
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* liveSegmentRouteElevationSchema validates the per-route elevation summary a
|
|
203
|
+
* routed result carries: the altitude range, total gain/loss, and the steepest
|
|
204
|
+
* ascending/descending gradients. Pinned to LiveSegmentRouteElevation via
|
|
205
|
+
* `satisfies` so the validated shape matches the projected one.
|
|
206
|
+
*/
|
|
207
|
+
export const liveSegmentRouteElevationSchema = z.object({
|
|
208
|
+
altitudeMax: z.number(),
|
|
209
|
+
altitudeMin: z.number(),
|
|
210
|
+
ascent: z.number(),
|
|
211
|
+
descent: z.number(),
|
|
212
|
+
gradientMax: z.number(),
|
|
213
|
+
gradientMin: z.number(),
|
|
214
|
+
}) satisfies z.ZodType<LiveSegmentRouteElevation>;
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* LiveSegmentRoute is the renderer-free shape buildLiveSegment projects onto a segment: the 3D
|
|
218
|
+
* routed line (lng/lat/elevation), the route distance and duration (meters/seconds), and, when
|
|
219
|
+
* the router computed them, the elevation summary, the surface/way-type/slope analysis and the
|
|
220
|
+
* restricted stretches the line follows. It mirrors `SegmentRoute` of `@mountaya/elements/seams`:
|
|
221
|
+
* the directions engine emits a SegmentRoute, and the hook hands it through here as a
|
|
222
|
+
* LiveSegmentRoute to project onto the panel's ItinerarySegment.
|
|
223
|
+
*/
|
|
224
|
+
export interface LiveSegmentRoute {
|
|
225
|
+
analysis?: LiveSegmentRouteAnalysis | undefined;
|
|
226
|
+
distance: number;
|
|
227
|
+
duration: number;
|
|
228
|
+
elevation?: LiveSegmentRouteElevation | undefined;
|
|
229
|
+
geometry: LineString;
|
|
230
|
+
/**
|
|
231
|
+
* The stretches of the line that follow a way restricting who may pass, in the shape a
|
|
232
|
+
* segment's `road_access_info` takes: an inclusive window into the line's coordinates and the
|
|
233
|
+
* access values tagged on it, in the REST spelling. Undefined when the router reports none.
|
|
234
|
+
*/
|
|
235
|
+
roadAccessInfo?: readonly RestSchema.RoadAccessInfo[] | undefined;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* GraphqlRouteShape is the slice of a Data-API routed result the live-route
|
|
240
|
+
* projector reads: the routed line geometry, the distance/duration metrics, and
|
|
241
|
+
* the optional elevation summary + surface/way-type/slope analysis blocks. Both
|
|
242
|
+
* the directions and the suggestions queries return this shape (DirectionsRoute
|
|
243
|
+
* and SuggestionRoute share it), so the projector takes the structural subset
|
|
244
|
+
* rather than either named wire type: the geometry is the GeoJSON scalar a
|
|
245
|
+
* routed result carries, narrowed to a LineString at the single boundary the
|
|
246
|
+
* caller crosses.
|
|
247
|
+
*/
|
|
248
|
+
export interface GraphqlRouteShape {
|
|
249
|
+
analysis?: GeometryAnalysis | undefined;
|
|
250
|
+
distance: number;
|
|
251
|
+
duration: number;
|
|
252
|
+
elevation?: ElevationSummary | undefined;
|
|
253
|
+
geometry: LineString;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* dataSurfaceTypes is every surface the Data API names the contract declares, each keyed by itself.
|
|
258
|
+
*
|
|
259
|
+
* The `satisfies` clause ties it to the generated `DataSchema.SurfaceType` in both directions: a
|
|
260
|
+
* member the contract adds leaves a missing key, and a key the contract does not declare is an
|
|
261
|
+
* excess property of the literal, so `tsc` fails either way.
|
|
262
|
+
*/
|
|
263
|
+
const dataSurfaceTypes = {
|
|
264
|
+
ASPHALT: "ASPHALT",
|
|
265
|
+
COBBLESTONE: "COBBLESTONE",
|
|
266
|
+
COMPACTED_GRAVEL: "COMPACTED_GRAVEL",
|
|
267
|
+
CONCRETE: "CONCRETE",
|
|
268
|
+
DIRT: "DIRT",
|
|
269
|
+
FINE_GRAVEL: "FINE_GRAVEL",
|
|
270
|
+
GRASS: "GRASS",
|
|
271
|
+
GRASS_PAVER: "GRASS_PAVER",
|
|
272
|
+
GRAVEL: "GRAVEL",
|
|
273
|
+
GROUND: "GROUND",
|
|
274
|
+
ICE: "ICE",
|
|
275
|
+
METAL: "METAL",
|
|
276
|
+
PAVED: "PAVED",
|
|
277
|
+
PAVING_STONES: "PAVING_STONES",
|
|
278
|
+
SAND: "SAND",
|
|
279
|
+
UNKNOWN: "UNKNOWN",
|
|
280
|
+
UNPAVED: "UNPAVED",
|
|
281
|
+
WOOD: "WOOD",
|
|
282
|
+
WOODCHIPS: "WOODCHIPS",
|
|
283
|
+
} as const satisfies { [K in DataSchema.SurfaceType]: K };
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* dataSurfaceTypeSchema is the Data-API surface vocabulary (SCREAMING_SNAKE) an analysis band
|
|
287
|
+
* carries before the projection normalizes it: the same classifications as surfaceTypeSchema, in
|
|
288
|
+
* the wire form the GraphQL enum marshals. Pinned to the wire DataSurfaceType via `satisfies` so
|
|
289
|
+
* the accepted set cannot drift from the Data-API enum the converter maps from.
|
|
290
|
+
*/
|
|
291
|
+
export const dataSurfaceTypeSchema = z.enum(dataSurfaceTypes);
|
|
292
|
+
|
|
293
|
+
/**
|
|
294
|
+
* dataWayTypes is every way type the Data API names the contract declares, each keyed by itself.
|
|
295
|
+
*
|
|
296
|
+
* The `satisfies` clause ties it to the generated `DataSchema.WayType` in both directions: a
|
|
297
|
+
* member the contract adds leaves a missing key, and a key the contract does not declare is an
|
|
298
|
+
* excess property of the literal, so `tsc` fails either way.
|
|
299
|
+
*/
|
|
300
|
+
const dataWayTypes = {
|
|
301
|
+
CONSTRUCTION: "CONSTRUCTION",
|
|
302
|
+
CYCLEWAY: "CYCLEWAY",
|
|
303
|
+
FERRY: "FERRY",
|
|
304
|
+
FOOTWAY: "FOOTWAY",
|
|
305
|
+
PATH: "PATH",
|
|
306
|
+
ROAD: "ROAD",
|
|
307
|
+
STATE_ROAD: "STATE_ROAD",
|
|
308
|
+
STEPS: "STEPS",
|
|
309
|
+
STREET: "STREET",
|
|
310
|
+
TRACK: "TRACK",
|
|
311
|
+
UNKNOWN: "UNKNOWN",
|
|
312
|
+
} as const satisfies { [K in DataSchema.WayType]: K };
|
|
313
|
+
|
|
314
|
+
/**
|
|
315
|
+
* dataWayTypeSchema is the Data-API way-type vocabulary (SCREAMING_SNAKE) an
|
|
316
|
+
* analysis band carries before the projection normalizes it. Pinned to the wire
|
|
317
|
+
* DataWayType via `satisfies` so the two cannot drift.
|
|
318
|
+
*/
|
|
319
|
+
export const dataWayTypeSchema = z.enum(dataWayTypes);
|
|
320
|
+
|
|
321
|
+
/**
|
|
322
|
+
* dataTrailDifficultyTypes is every trail difficulty the Data API names the contract declares, each
|
|
323
|
+
* keyed by itself.
|
|
324
|
+
*
|
|
325
|
+
* The `satisfies` clause ties it to the generated `DataSchema.TrailDifficultyType` in both
|
|
326
|
+
* directions: a member the contract adds leaves a missing key, and a key the contract does not
|
|
327
|
+
* declare is an excess property of the literal, so `tsc` fails either way.
|
|
328
|
+
*/
|
|
329
|
+
const dataTrailDifficultyTypes = {
|
|
330
|
+
ALPINE_HIKING: "ALPINE_HIKING",
|
|
331
|
+
DEMANDING_ALPINE_HIKING: "DEMANDING_ALPINE_HIKING",
|
|
332
|
+
DEMANDING_MOUNTAIN_HIKING: "DEMANDING_MOUNTAIN_HIKING",
|
|
333
|
+
DIFFICULT_ALPINE_HIKING: "DIFFICULT_ALPINE_HIKING",
|
|
334
|
+
HIKING: "HIKING",
|
|
335
|
+
MOUNTAIN_HIKING: "MOUNTAIN_HIKING",
|
|
336
|
+
MTB_0: "MTB_0",
|
|
337
|
+
MTB_1: "MTB_1",
|
|
338
|
+
MTB_2: "MTB_2",
|
|
339
|
+
MTB_3: "MTB_3",
|
|
340
|
+
MTB_4: "MTB_4",
|
|
341
|
+
MTB_5: "MTB_5",
|
|
342
|
+
MTB_6: "MTB_6",
|
|
343
|
+
UNKNOWN: "UNKNOWN",
|
|
344
|
+
} as const satisfies { [K in DataSchema.TrailDifficultyType]: K };
|
|
345
|
+
|
|
346
|
+
/**
|
|
347
|
+
* dataTrailDifficultyTypeSchema is the Data-API trail-difficulty vocabulary
|
|
348
|
+
* (SCREAMING_SNAKE) an analysis band carries before the projection normalizes
|
|
349
|
+
* it. Pinned to the wire DataTrailDifficultyType via `satisfies` so the two
|
|
350
|
+
* cannot drift.
|
|
351
|
+
*/
|
|
352
|
+
export const dataTrailDifficultyTypeSchema = z.enum(dataTrailDifficultyTypes);
|
|
353
|
+
|
|
354
|
+
/**
|
|
355
|
+
* dataToRestSurface maps each Data-API surface value to the REST surface_info
|
|
356
|
+
* value the persisted segment carries (SCREAMING_SNAKE → lower-case-hyphen). It is
|
|
357
|
+
* an exhaustive Record keyed on the generated DataSurfaceType and valued in the
|
|
358
|
+
* generated SurfaceType, so a member added or dropped on either side fails the type
|
|
359
|
+
* check; a test asserts the runtime bijection over the full generated unions.
|
|
360
|
+
*/
|
|
361
|
+
const dataToRestSurface: Record<DataSurfaceType, SurfaceType> = {
|
|
362
|
+
ASPHALT: "asphalt",
|
|
363
|
+
COBBLESTONE: "cobblestone",
|
|
364
|
+
COMPACTED_GRAVEL: "compacted-gravel",
|
|
365
|
+
CONCRETE: "concrete",
|
|
366
|
+
DIRT: "dirt",
|
|
367
|
+
FINE_GRAVEL: "fine-gravel",
|
|
368
|
+
GRASS: "grass",
|
|
369
|
+
GRASS_PAVER: "grass-paver",
|
|
370
|
+
GRAVEL: "gravel",
|
|
371
|
+
GROUND: "ground",
|
|
372
|
+
ICE: "ice",
|
|
373
|
+
METAL: "metal",
|
|
374
|
+
PAVED: "paved",
|
|
375
|
+
PAVING_STONES: "paving-stones",
|
|
376
|
+
SAND: "sand",
|
|
377
|
+
UNKNOWN: "unknown",
|
|
378
|
+
UNPAVED: "unpaved",
|
|
379
|
+
WOOD: "wood",
|
|
380
|
+
WOODCHIPS: "woodchips",
|
|
381
|
+
};
|
|
382
|
+
|
|
383
|
+
/**
|
|
384
|
+
* dataToRestWaytype maps each Data-API way-type value to the REST way_type_info
|
|
385
|
+
* value the persisted segment carries. Exhaustive Record keyed on the generated
|
|
386
|
+
* DataWayType and valued in the generated WayType, so a drift on either side
|
|
387
|
+
* fails the type check; a test asserts the runtime bijection.
|
|
388
|
+
*/
|
|
389
|
+
const dataToRestWaytype: Record<DataWayType, WayType> = {
|
|
390
|
+
CONSTRUCTION: "construction",
|
|
391
|
+
CYCLEWAY: "cycleway",
|
|
392
|
+
FERRY: "ferry",
|
|
393
|
+
FOOTWAY: "footway",
|
|
394
|
+
PATH: "path",
|
|
395
|
+
ROAD: "road",
|
|
396
|
+
STATE_ROAD: "state-road",
|
|
397
|
+
STEPS: "steps",
|
|
398
|
+
STREET: "street",
|
|
399
|
+
TRACK: "track",
|
|
400
|
+
UNKNOWN: "unknown",
|
|
401
|
+
};
|
|
402
|
+
|
|
403
|
+
/**
|
|
404
|
+
* dataToRestTrailDifficulty maps each Data-API trail-difficulty value to the
|
|
405
|
+
* REST trail_difficulty_info value the persisted segment carries. Both grading scales
|
|
406
|
+
* live in the one map because they share one field; they overlap only on
|
|
407
|
+
* UNKNOWN, so a value still names the scale it was graded on. Exhaustive Record
|
|
408
|
+
* keyed on the generated DataTrailDifficultyType and valued in the generated
|
|
409
|
+
* TrailDifficultyType, so a drift on either side fails the type check; a test
|
|
410
|
+
* asserts the runtime bijection.
|
|
411
|
+
*/
|
|
412
|
+
const dataToRestTrailDifficulty: Record<DataTrailDifficultyType, TrailDifficultyType> = {
|
|
413
|
+
ALPINE_HIKING: "alpine-hiking",
|
|
414
|
+
DEMANDING_ALPINE_HIKING: "demanding-alpine-hiking",
|
|
415
|
+
DEMANDING_MOUNTAIN_HIKING: "demanding-mountain-hiking",
|
|
416
|
+
DIFFICULT_ALPINE_HIKING: "difficult-alpine-hiking",
|
|
417
|
+
HIKING: "hiking",
|
|
418
|
+
MOUNTAIN_HIKING: "mountain-hiking",
|
|
419
|
+
MTB_0: "mtb-0",
|
|
420
|
+
MTB_1: "mtb-1",
|
|
421
|
+
MTB_2: "mtb-2",
|
|
422
|
+
MTB_3: "mtb-3",
|
|
423
|
+
MTB_4: "mtb-4",
|
|
424
|
+
MTB_5: "mtb-5",
|
|
425
|
+
MTB_6: "mtb-6",
|
|
426
|
+
UNKNOWN: "unknown",
|
|
427
|
+
};
|
|
428
|
+
|
|
429
|
+
/**
|
|
430
|
+
* toRestSurface maps a Data-API surface value to the REST surface_info value the
|
|
431
|
+
* persisted segment carries, so the routed analysis reads identically to the panel's
|
|
432
|
+
* stored render path. The input is the generated Data-API enum, so the lookup is
|
|
433
|
+
* total and needs no cast.
|
|
434
|
+
*/
|
|
435
|
+
export const toRestSurface = (value: DataSurfaceType): SurfaceType => dataToRestSurface[value];
|
|
436
|
+
|
|
437
|
+
/**
|
|
438
|
+
* toRestWayType maps a Data-API way-type value to the REST way_type_info value the
|
|
439
|
+
* persisted segment carries. Total over the generated enum, so no cast.
|
|
440
|
+
*/
|
|
441
|
+
export const toRestWayType = (value: DataWayType): WayType => dataToRestWaytype[value];
|
|
442
|
+
|
|
443
|
+
/**
|
|
444
|
+
* toRestTrailDifficulty maps a Data-API trail-difficulty value to the REST
|
|
445
|
+
* trail_difficulty_info value the persisted segment carries. Total over the generated
|
|
446
|
+
* enum, so no cast.
|
|
447
|
+
*/
|
|
448
|
+
export const toRestTrailDifficulty = (value: DataTrailDifficultyType): TrailDifficultyType =>
|
|
449
|
+
dataToRestTrailDifficulty[value];
|
|
450
|
+
|
|
451
|
+
/**
|
|
452
|
+
* dataToRestRoadAccess maps each Data-API access restriction to the REST `road_access_info`
|
|
453
|
+
* value a persisted segment carries (SCREAMING → lower case). An exhaustive Record keyed on the
|
|
454
|
+
* generated Data-API enum and valued in the generated REST one, so a member added or dropped on
|
|
455
|
+
* either side fails the type check.
|
|
456
|
+
*/
|
|
457
|
+
const dataToRestRoadAccess: Record<
|
|
458
|
+
DataSchema.RoadAccessRestrictionType,
|
|
459
|
+
RestSchema.RoadAccessRestrictionType
|
|
460
|
+
> = {
|
|
461
|
+
AGRICULTURAL: "agricultural",
|
|
462
|
+
CUSTOMERS: "customers",
|
|
463
|
+
DELIVERY: "delivery",
|
|
464
|
+
DESTINATION: "destination",
|
|
465
|
+
FORESTRY: "forestry",
|
|
466
|
+
NO: "no",
|
|
467
|
+
PERMISSIVE: "permissive",
|
|
468
|
+
PERMIT: "permit",
|
|
469
|
+
PRIVATE: "private",
|
|
470
|
+
RESTRICTED: "restricted",
|
|
471
|
+
SERVICE: "service",
|
|
472
|
+
UNKNOWN: "unknown",
|
|
473
|
+
};
|
|
474
|
+
|
|
475
|
+
/**
|
|
476
|
+
* graphqlRoadAccessToInfo projects the stretches a Data-API advisory block reports over a
|
|
477
|
+
* restricted way onto the `road_access_info` shape a persisted segment carries: snake_case
|
|
478
|
+
* indexes, and every access value in the REST spelling. Every stretch is carried, the permissive,
|
|
479
|
+
* agricultural and forestry ones included, as the persisted segment carries them: what a stretch
|
|
480
|
+
* is shown as is decided where it is shown, by `roadAccessKindOf` of `@mountaya/elements/data`.
|
|
481
|
+
*
|
|
482
|
+
* @param advisories - The advisory block of a routed or analysed line.
|
|
483
|
+
* @returns The stretches, in the order the block lists them.
|
|
484
|
+
*/
|
|
485
|
+
export const graphqlRoadAccessToInfo = (advisories: RouteAdvisories): RestSchema.RoadAccessInfo[] =>
|
|
486
|
+
advisories.roadAccessInfo.map((info) => ({
|
|
487
|
+
from_index: info.fromIndex,
|
|
488
|
+
to_index: info.toIndex,
|
|
489
|
+
values: info.values.map((value) => dataToRestRoadAccess[value]),
|
|
490
|
+
}));
|
|
491
|
+
|
|
492
|
+
/**
|
|
493
|
+
* toAnalysisEntries maps a list of Data-API indexed-info entries into the
|
|
494
|
+
* coordinate-index-ranged shape the segment analysis arrays carry: snake_case
|
|
495
|
+
* indices and a (string-)enum value normalized to the REST vocabulary. The
|
|
496
|
+
* generic `convert` callback narrows the value type per analysis kind so a slope
|
|
497
|
+
* entry stays a number while surface/way-type entries land in their REST enum.
|
|
498
|
+
*/
|
|
499
|
+
const toAnalysisEntries = <
|
|
500
|
+
Source extends { fromIndex: number; toIndex: number; value: unknown },
|
|
501
|
+
Target,
|
|
502
|
+
>(
|
|
503
|
+
entries: Source[],
|
|
504
|
+
convert: (value: Source["value"]) => Target,
|
|
505
|
+
): IndexedInfo<Target>[] =>
|
|
506
|
+
entries.map((entry) => ({
|
|
507
|
+
from_index: entry.fromIndex,
|
|
508
|
+
to_index: entry.toIndex,
|
|
509
|
+
value: convert(entry.value),
|
|
510
|
+
}));
|
|
511
|
+
|
|
512
|
+
/**
|
|
513
|
+
* graphqlElevationToSummary projects a Data-API elevation summary onto the renderer-free
|
|
514
|
+
* LiveSegmentRouteElevation the projector overlays, flattening the altitude/gradient ranges into
|
|
515
|
+
* the flat min/max fields the persisted segment carries.
|
|
516
|
+
*/
|
|
517
|
+
export const graphqlElevationToSummary = (
|
|
518
|
+
elevation: ElevationSummary,
|
|
519
|
+
): LiveSegmentRouteElevation => ({
|
|
520
|
+
altitudeMax: elevation.altitude.max,
|
|
521
|
+
altitudeMin: elevation.altitude.min,
|
|
522
|
+
ascent: elevation.ascent,
|
|
523
|
+
descent: elevation.descent,
|
|
524
|
+
gradientMax: elevation.gradient.max,
|
|
525
|
+
gradientMin: elevation.gradient.min,
|
|
526
|
+
});
|
|
527
|
+
|
|
528
|
+
/**
|
|
529
|
+
* graphqlAnalysisToEntries projects a Data-API analysis block onto the
|
|
530
|
+
* LiveSegmentRouteAnalysis the projector overlays: it renames each entry's
|
|
531
|
+
* indices to the snake_case the persisted arrays use and normalizes the
|
|
532
|
+
* surface/way-type/trail-difficulty values to the REST vocabulary, leaving the
|
|
533
|
+
* slope angle and the resolved speed the raw numbers they already are. It is the
|
|
534
|
+
* single converter both the directions/suggestions route path and the freehand-line analysis
|
|
535
|
+
* path reuse, so the routed analysis always reads identically to the panel's stored render
|
|
536
|
+
* path.
|
|
537
|
+
*/
|
|
538
|
+
export const graphqlAnalysisToEntries = (analysis: GeometryAnalysis): LiveSegmentRouteAnalysis => ({
|
|
539
|
+
slopeInfo: toAnalysisEntries<SlopeInfo, number>(analysis.slopeInfo, (value) => value),
|
|
540
|
+
speedInfo: toAnalysisEntries<SpeedInfo, number>(analysis.speedInfo, (value) => value),
|
|
541
|
+
surfaceInfo: toAnalysisEntries<SurfaceInfo, SurfaceType>(analysis.surfaceInfo, toRestSurface),
|
|
542
|
+
trailDifficultyInfo: toAnalysisEntries<TrailDifficultyInfo, TrailDifficultyType>(
|
|
543
|
+
analysis.trailDifficultyInfo,
|
|
544
|
+
toRestTrailDifficulty,
|
|
545
|
+
),
|
|
546
|
+
wayTypeInfo: toAnalysisEntries<WayTypeInfo, WayType>(analysis.wayTypeInfo, toRestWayType),
|
|
547
|
+
});
|
|
548
|
+
|
|
549
|
+
/**
|
|
550
|
+
* routeLineOf reads the geometry a Data API route answers as the one line it is.
|
|
551
|
+
*
|
|
552
|
+
* The wire types a route's geometry as any GeoJSON geometry. A route is a `LineString`, which is
|
|
553
|
+
* handed back as it is. Any other geometry has the lines {@link extractLines} finds laid end to
|
|
554
|
+
* end, as every reader of a segment's geometry walks them, and one that holds no line reads as a
|
|
555
|
+
* line with no coordinates.
|
|
556
|
+
*
|
|
557
|
+
* @param geometry - The route's geometry, as the Data API answers it.
|
|
558
|
+
* @returns The route's line.
|
|
559
|
+
*/
|
|
560
|
+
export const routeLineOf = (geometry: Geometry): LineString => {
|
|
561
|
+
const lines = extractLines(geometry);
|
|
562
|
+
const [only] = lines;
|
|
563
|
+
if (lines.length === 1 && only !== undefined) {
|
|
564
|
+
return only;
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
return { coordinates: segmentLineCoordinates(geometry), type: "LineString" };
|
|
568
|
+
};
|
|
569
|
+
|
|
570
|
+
/**
|
|
571
|
+
* graphqlRouteToLiveRoute projects a Data-API routed result (a directions or a suggestion route)
|
|
572
|
+
* into the renderer-free LiveSegmentRoute buildLiveSegment overlays.
|
|
573
|
+
*
|
|
574
|
+
* It carries the routed line + metrics and, when the router computed them, the elevation
|
|
575
|
+
* summary and the surface/way-type/slope/trail-difficulty analysis, normalized to the snake_case
|
|
576
|
+
* indices + REST-vocabulary values the persisted segment carries so the projection lands without
|
|
577
|
+
* a second translation. The elevation/analysis blocks stay optional: a 2D-only response leaves
|
|
578
|
+
* them undefined, which buildLiveSegment renders as the base segment's own values. The restricted
|
|
579
|
+
* stretches ride the analysis block's advisories, so a route with no analysis carries none. It is
|
|
580
|
+
* the shared wire→live-route conversion the segment editor's directions routing and the suggest
|
|
581
|
+
* start-from both reuse, so the two cannot drift.
|
|
582
|
+
*/
|
|
583
|
+
export const graphqlRouteToLiveRoute = (itinerary: GraphqlRouteShape): LiveSegmentRoute => ({
|
|
584
|
+
analysis: itinerary.analysis ? graphqlAnalysisToEntries(itinerary.analysis) : undefined,
|
|
585
|
+
distance: itinerary.distance,
|
|
586
|
+
duration: itinerary.duration,
|
|
587
|
+
elevation: itinerary.elevation ? graphqlElevationToSummary(itinerary.elevation) : undefined,
|
|
588
|
+
geometry: itinerary.geometry,
|
|
589
|
+
roadAccessInfo: itinerary.analysis
|
|
590
|
+
? graphqlRoadAccessToInfo(itinerary.analysis.advisories)
|
|
591
|
+
: undefined,
|
|
592
|
+
});
|
|
593
|
+
|
|
594
|
+
/**
|
|
595
|
+
* overlayRouteAnalysis overlays a route's elevation summary + surface/way-type/
|
|
596
|
+
* slope/trail-difficulty/speed analysis and its restricted stretches onto a base segment, the
|
|
597
|
+
* field-by-field projection buildLiveSegment and the suggestion-candidate view share. A missing
|
|
598
|
+
* elevation block keeps the base values (the persisted summary survives a 2D-only routed
|
|
599
|
+
* response); a missing analysis block keeps the base analysis bands. Missing stretches read as
|
|
600
|
+
* not analysed (`road_access_info: null`): a stretch is a window of indexes into one line, so the
|
|
601
|
+
* base's own would point into a geometry the route has replaced. It does NOT
|
|
602
|
+
* touch the geometry or the distance/duration metrics: those vary by caller (a
|
|
603
|
+
* live edit overlays the routed line, the candidate view keeps the candidate
|
|
604
|
+
* geometry), so each caller spreads the result and sets them itself.
|
|
605
|
+
*/
|
|
606
|
+
export const overlayRouteAnalysis = (
|
|
607
|
+
base: ItinerarySegment,
|
|
608
|
+
itinerary: {
|
|
609
|
+
analysis?: LiveSegmentRouteAnalysis | undefined;
|
|
610
|
+
elevation?: LiveSegmentRouteElevation | undefined;
|
|
611
|
+
roadAccessInfo?: readonly RestSchema.RoadAccessInfo[] | undefined;
|
|
612
|
+
},
|
|
613
|
+
): ItinerarySegment => ({
|
|
614
|
+
...base,
|
|
615
|
+
altitude_max: itinerary.elevation?.altitudeMax ?? base.altitude_max,
|
|
616
|
+
altitude_min: itinerary.elevation?.altitudeMin ?? base.altitude_min,
|
|
617
|
+
ascent: itinerary.elevation?.ascent ?? base.ascent,
|
|
618
|
+
descent: itinerary.elevation?.descent ?? base.descent,
|
|
619
|
+
gradient_max: itinerary.elevation?.gradientMax ?? base.gradient_max,
|
|
620
|
+
gradient_min: itinerary.elevation?.gradientMin ?? base.gradient_min,
|
|
621
|
+
road_access_info: itinerary.roadAccessInfo ? [...itinerary.roadAccessInfo] : null,
|
|
622
|
+
slope_info: itinerary.analysis?.slopeInfo ?? base.slope_info,
|
|
623
|
+
speed_info: itinerary.analysis?.speedInfo ?? base.speed_info,
|
|
624
|
+
surface_info: itinerary.analysis?.surfaceInfo ?? base.surface_info,
|
|
625
|
+
trail_difficulty_info: itinerary.analysis?.trailDifficultyInfo ?? base.trail_difficulty_info,
|
|
626
|
+
way_type_info: itinerary.analysis?.wayTypeInfo ?? base.way_type_info,
|
|
627
|
+
});
|
|
628
|
+
|
|
629
|
+
/**
|
|
630
|
+
* buildLiveSegment projects a freshly-routed response onto the ItinerarySegment shape the
|
|
631
|
+
* elevation panel renders.
|
|
632
|
+
*
|
|
633
|
+
* It keeps the segment's identity (id, name, color, mode) and overlays the routed metrics
|
|
634
|
+
* (distance, ascent/descent, altitude extremes, gradient extremes), the analysis bands
|
|
635
|
+
* (surface/way-type/slope), and the routed geometry, wrapped in a collection of that one line.
|
|
636
|
+
* That is no shape the API answers, which never sends a collection of one member, and nothing
|
|
637
|
+
* sends it: the panel's geometry helpers flatten a collection and a bare geometry alike. A
|
|
638
|
+
* missing elevation block keeps the base values (the persisted summary survives a 2D-only routed
|
|
639
|
+
* response); a missing analysis block keeps the base analysis bands.
|
|
640
|
+
*
|
|
641
|
+
* The result is a live preview, not a persist source: the authoritative commit-time analysis
|
|
642
|
+
* still rides the whole-itinerary refetch on commit, so this projection only lives on
|
|
643
|
+
* `editSession.liveSegment` while the edit is open.
|
|
644
|
+
*/
|
|
645
|
+
export const buildLiveSegment = (
|
|
646
|
+
base: ItinerarySegment,
|
|
647
|
+
itinerary: LiveSegmentRoute,
|
|
648
|
+
): ItinerarySegment => {
|
|
649
|
+
const geojson: GeometryCollection = {
|
|
650
|
+
geometries: [itinerary.geometry],
|
|
651
|
+
type: "GeometryCollection",
|
|
652
|
+
};
|
|
653
|
+
|
|
654
|
+
// Overlay the analysis + elevation through the shared field projection, then
|
|
655
|
+
// set the geometry + the routed distance/duration on top: the live edit
|
|
656
|
+
// replaces the segment's line with the freshly-routed one.
|
|
657
|
+
return {
|
|
658
|
+
...overlayRouteAnalysis(base, itinerary),
|
|
659
|
+
distance: itinerary.distance,
|
|
660
|
+
duration: itinerary.duration,
|
|
661
|
+
geojson,
|
|
662
|
+
};
|
|
663
|
+
};
|
|
664
|
+
|
|
665
|
+
/**
|
|
666
|
+
* substituteLiveSegment overlays the in-flight live segment onto a persisted segment chain so
|
|
667
|
+
* every consumer (the segment list rows, the header totals, the elevation chart) reads the same
|
|
668
|
+
* live-edit metrics from one shape.
|
|
669
|
+
*
|
|
670
|
+
* It returns `segments` unchanged when `live` is null (no edit open). Otherwise it replaces the
|
|
671
|
+
* entry whose id matches `live` (an edit of an existing segment, whose distance/ascent then
|
|
672
|
+
* track the latest routed response), or places `live` among the persisted entries when no entry
|
|
673
|
+
* matches, which is the create case where no persisted entry exists yet. The result is a live
|
|
674
|
+
* preview, not a persist source: the authoritative metrics still ride the whole-itinerary
|
|
675
|
+
* refetch on commit, so the substitution only lives while the edit session carries a
|
|
676
|
+
* liveSegment.
|
|
677
|
+
*
|
|
678
|
+
* `insertAnchor` is where an unmatched live segment lands: the id of the segment
|
|
679
|
+
* it will follow once committed, or null for a head insert. It is what makes a
|
|
680
|
+
* segment being INSERTED render in the gap it is destined for rather than at the
|
|
681
|
+
* tail: the draft carries a client-minted id that matches nothing in the chain,
|
|
682
|
+
* so without the anchor the only honest answer is "somewhere", and the row would
|
|
683
|
+
* jump position on save. Omit it (undefined) for an append, which is the tail by
|
|
684
|
+
* definition; an anchor naming a segment that is not in the chain falls back to
|
|
685
|
+
* the tail rather than guessing.
|
|
686
|
+
*/
|
|
687
|
+
export const substituteLiveSegment = (
|
|
688
|
+
segments: ItinerarySegment[],
|
|
689
|
+
live: ItinerarySegment | null,
|
|
690
|
+
insertAnchor?: string | null,
|
|
691
|
+
): ItinerarySegment[] => {
|
|
692
|
+
if (!live) {
|
|
693
|
+
return segments;
|
|
694
|
+
}
|
|
695
|
+
|
|
696
|
+
if (segments.some((segment) => segment.id === live.id)) {
|
|
697
|
+
return segments.map((segment) => (segment.id === live.id ? live : segment));
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
if (insertAnchor === undefined) {
|
|
701
|
+
return [...segments, live];
|
|
702
|
+
}
|
|
703
|
+
|
|
704
|
+
// A null anchor is the head insert: nothing precedes the new segment, so it
|
|
705
|
+
// opens the chain.
|
|
706
|
+
const anchorIndex = insertAnchor === null ? -1 : segments.findIndex((s) => s.id === insertAnchor);
|
|
707
|
+
if (insertAnchor !== null && anchorIndex === -1) {
|
|
708
|
+
return [...segments, live];
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
return [...segments.slice(0, anchorIndex + 1), live, ...segments.slice(anchorIndex + 1)];
|
|
712
|
+
};
|