@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
package/dist/index.js
ADDED
|
@@ -0,0 +1,3033 @@
|
|
|
1
|
+
import { $ as shareLinkTargetSchema, B as SET_SESSION_TOKEN_MESSAGE, F as CAMERA_MESSAGE, G as readyErrorSchema, I as READY_MESSAGE, J as requestSessionTokenMessageSchema, K as readyMessageSchema, L as REQUEST_CAMERA_MESSAGE, O as substituteLiveSegment, Q as buildShareSrc, R as REQUEST_SESSION_TOKEN_MESSAGE, U as inboundBridgeMessageSchema, V as cameraMessageSchema, W as mapBoundsSchema, X as switchOverridesSchema, Y as setSessionTokenMessageSchema, Z as buildShareSearch, _t as resolveActivity, a as zoneDescriptionSchema, at as displayNameSchema, ct as draftNameInput, d as segmentEditModeSchema, dt as fitDisplayName, et as originBase, g as draftPositionCount, gt as renumber, i as requireWritableScope, it as descriptionSchema, lt as draftOrganizationInput, m as synthesizeDraftSegment, n as defaultStudioScope, nt as DISPLAY_NAME_MAX_LENGTH, o as zoneNameSchema, ot as draftActivityInput, p as segmentInsertAnchorSchema, q as requestCameraMessageSchema, r as isPublishableScope, rt as DISPLAY_NAME_MIN_LENGTH, st as draftCollectionsInput, t as activeStudioScope, tt as DESCRIPTION_MAX_LENGTH, ut as draftPrivateInput, xt as toolNoDataSchema, z as SET_ITINERARY_MESSAGE } from "./chunk-CiK1Iqrv.js";
|
|
2
|
+
import { $ as segmentSpanSchema, $n as zoneSensorGeometry, $t as exportExtension, A as waypointPropertyValueMatchesFormat, An as urlBoolean, Ar as selectCollabLockHolderIds, B as cameraFpsSchema, Bn as zoneEditBeginSchema, Bt as selectedCandidate, Cn as studioMapStateSearchSchema, Cr as collabPresencePeerSchema, Ct as draftToView, D as isWaypointPropertyKey, Dn as unitPaceSchema, E as isWaypointPhone, En as unitLengthSchema, Er as collabResourceSchema, Fn as timeSliderWindow, Ft as SUGGESTION_TARGET_COUNT, G as cameraPlanSchema, Gn as destinationPoint, Gt as defaultSegmentGroupName, H as cameraOutputBaseSchema, Hn as zoneEditLevelSchema, Ht as suggestionCandidateToView, I as videoExportProfileSchema, In as hexColorSchema, J as cameraShotSchema, Jn as zoneCircleGeometry, Jt as renumberDefaultSegments, K as cameraResolutionSchema, Kt as defaultSegmentName, L as videoExportSchema, M as waypointPropertyFormatSchema, Mn as TIME_OFFSET_MIN_MINUTES, Mr as selectCollabPeers, Nn as TIME_WINDOW_FUTURE_HOURS, O as isWaypointWebUrl, On as unitSlopeSchema, Or as peerSegmentDraftsOf, P as defaultVideoExportProfile, Pn as TIME_WINDOW_PAST_HOURS, Pt as SUGGESTION_MAX_KEPT, Q as routeGeometrySchema, Qn as zoneSectorParamsSchema, Qt as buildExportFilename, R as videoExportStatusSchema, S as waypointEditModeSchema, Sn as shareSearchSchema, Sr as collabPeerColorIndex, T as isWaypointEmail, Tn as themeSchema, Tr as collabResourceKindSchema, Tt as importReasonSentence, U as cameraOutputFormatSchema, Un as zoneEditModeSchema, Ut as userWaypointIconSchema, V as cameraModeSchema, Vt as suggestRouteTypeSchema, W as cameraOutputSchema, Wn as zonePreviewQueryKey, Wt as waypointIconSchema, X as profileSourceSchema, Xn as zoneReachPole, Xt as EXPORT_FORMATS, Y as profileDesignSchema, Yn as zoneCircleParamsSchema, Yt as splitSegmentNames, Z as qualitySchema, Zn as zoneSectorGeometry, Zt as EXPORT_VARIANTS, _n as embedThemeSchema, _t as POI_GROUP_IDS, a as studioEntitlementSchema, an as editingCollectionSchema, ar as mapAlertSchema, at as segmentSplitPickSchema, bn as resolveEmbedConfig, br as collabLockKindSchema, bt as DUPLICATE_WAYPOINT_IDS_MAX, cn as overlaySampleResultSchema, cr as streetviewPositionSchema, d as segmentLengthMeters, dn as DEFAULT_TERRAIN, dr as studioModalSchema, en as exportFileStem, er as zoneSensorParamsSchema, et as videoPresetSchema, f as agentHandoffTarget, fn as MAP_STATE_SEARCH_KEYS, fr as studioPanelSchema, g as itineraryWaypointsToolContracts, gn as embedSearchSchema, gr as COLLAB_PEER_COLORS, gt as POI_GROUP_COUNT, h as studioToolContracts, hn as embedConfigSearchSchema, hr as poiInfoSchema, ht as POI_GROUPS, j as waypointAmenitySchema, jn as TIME_OFFSET_MAX_MINUTES, jr as selectCollabPeerDrafts, k as waypointDetailLimits, kn as unitTemperatureSchema, kr as selectCollabLockHolder, kt as importWarningSentence, l as pointAtFraction, lr as studioAlertCodeSchema, lt as segmentGroupEditTargetSchema, m as selectSuggestionSession, mn as embedConfigSchema, mr as overlayFeatureSchema, mt as DEFAULT_ENABLED_POI_GROUP_IDS, n as createStaticViewer, nr as contextMenuSchema, nt as routeProfilePointSchema, o as SPLIT_MIN_END_DISTANCE_METERS, on as exportTargetSchema, or as profileSheetSnapSchema, ot as selectSegmentSplitPick, p as selectActiveEditEngine, pn as embedAuthSearchSchema, pr as featureHitSchema, pt as poiGroupIdSchema, q as cameraShotBaseSchema, qn as wrapZoneGeometryPastRange, qt as isDefaultSegmentName, rn as collectionsTargetSchema, rr as contextMenuZoneSchema, s as SPLIT_PICK_TOLERANCE_PX, sr as selectAgentEntityLocked, t as createMemoryViewer, tn as exportFormatVariants, tt as climbCategorySchema, u as projectOnSegment, un as AGENT_PANEL_SEARCH_KEYS, ur as studioContentSchema, ut as selectSegmentGroupEdit, v as synthesizeDraftWaypoint, vn as languageSchema, vr as collabLockEntrySchema, vt as poiGroupSchema, w as waypointPoiSeedSchema, wn as terrainVariantSchema, wr as collabResourceKey, x as waypointEditIntentSchema, xn as segmentsColorSchema, xr as collabPeerColor, xt as chosenCandidate, y as waypointDraftSchema, yn as mapStateShape, yr as collabLockKey, yt as DUPLICATE_SEGMENT_IDS_MAX, z as cameraBearingModeSchema, zn as zoneCreateMethodSchema } from "./chunk-DMePkFEo.js";
|
|
3
|
+
import { $ as classicOverlays, A as embedUiBaseline, At as describeInvalidInput, B as selectSelectedSuggestionCandidate, Ct as registerStudioTools, D as rethrowSegmentWriteError, Dt as toolCapabilitySchema, E as reconcileMadeWrite, Et as confirmationToneSchema, F as selectEditDirtyTick, G as selectZoneCreateSetup, H as selectVideoExportPlan, I as selectImportSession, J as selectShare, K as selectZoneEditDirty, L as selectProfilePaceKmh, M as selectActiveDraftSession, N as selectAgentHandoffArmed, O as declaredBody, Ot as toolConfirmationSchema, P as selectBaseMapLocked, Q as POIS_OVERLAY_SLUG, R as selectProfileSheetSnap, St as selectEmbed, Tt as ToolBus, U as selectVideoExportRoute, V as selectVideoExport, W as selectVideoExportStatus, X as selectDirections, Y as directionsTargetSchema, Z as HILLSHADE_OVERLAY_SLUG, _ as withSegmentAnalysis, a as exceedsMergeViaCeiling, at as findHillshadeOverlay, bt as showingDraftSurface, c as toggleableSegmentIds, ct as allowlistUnrestricted, d as isZoneWorkUnsaved, et as collectAttributions, f as selectUnsavedWork, g as withItineraryAnalysis, h as fetchItineraryRecord, i as splitPickVerdict, it as filterTerrains, j as selectActiveDraft, k as createUiStore, kt as toolErrorCodeSchema, l as hasUuidShape, lt as clampConfigToSafetyRules, m as selectEditorTakenBy, n as resolveViewerUnits, nt as filterEnrichmentOverlays, o as contiguousRunBounds, ot as allowlistForMode, q as selectWaypointDetails, rt as filterOverlayCategories, s as isContiguousRun, st as allowlistMode, t as makeWaypointId, tt as enrichmentOverlays, u as lngLatOf, ut as isFieldRestricted, v as SegmentDeleteNotEdgeError, wt as studioRegistry, xt as selectEmbedContent, y as createdIdOf, z as selectSegmentViaPrompt } from "./chunk-BSHTsFiB.js";
|
|
4
|
+
import { r as isConfirmationWithheld } from "./chunk-p-Tt_Lwz.js";
|
|
5
|
+
import { a as failureFromThrown, i as codeForThrown, l as restStatusCodes } from "./chunk-DKuuuld5.js";
|
|
6
|
+
import { n as memoryPersistenceDrawer, t as localPersistenceDrawer } from "./chunk-By9ZnkVI.js";
|
|
7
|
+
import { r as studioSeamAbsences } from "./chunk-BKMFOe-N.js";
|
|
8
|
+
import { a as profileMarkerIcon, c as resolveFramedError, i as profileCursorReadout, l as embedConstraintsFor, n as routeHazardConfirmation, o as EMBED_COVER_MAX_MS, r as draftChangeDisposition, s as buildReadyPayload, t as buildSegmentEditOptions } from "./chunk-DO5SIBgu.js";
|
|
9
|
+
import { F as DEFAULT_ZONE_LEVEL, I as DEFAULT_ZONE_MODE, M as zoneSaveRequest, P as DEFAULT_ZONE_CREATE_METHOD, T as isZoneMetadataDirty, _ as seedFromPersistedSegment, c as canEditOwnedResource, d as availableEnginesForActivity, f as clampSeedPoint, g as seedFromCoordinates, h as firstActivityId, i as shareLinkScope, j as zoneAutoName, m as defaultSpeedForActivity, n as isShareLinkDisableSettled, o as ITINERARY_FIT_MAX_ZOOM, p as defaultEngineForActivity, r as shareLinkActions, s as canEditItinerary, t as isRetryableShareLinkFailure, u as activityForId, v as simplifyToVias, x as ZONE_PREVIEW_DEBOUNCE_MS } from "./chunk-Co782_9r.js";
|
|
10
|
+
import { i as videoSnapshotSchema, n as selectDirecting, r as buildVideoSnapshot, t as createVideoDirectorStore } from "./chunk-CwkmccXv.js";
|
|
11
|
+
import { t as layerToolContext } from "./chunk-3Oi_Zrtm.js";
|
|
12
|
+
import * as z$1 from "zod";
|
|
13
|
+
import { DIRECTIONS_VIA_COUNTER_THRESHOLD, DIRECTIONS_VIA_MAX, SEGMENT_MIN_VIAS, boundsTuple, buildGeometryCollection, extractLines, extractPoint, extractVias, pointTuple, segmentLineCoordinates } from "@mountaya/elements/geo";
|
|
14
|
+
import { ROAD_ACCESS_KINDS, SEGMENT_GROUP_MIN_MEMBERS, segmentsForSelection } from "@mountaya/elements/data";
|
|
15
|
+
import { SECONDS_PER_MINUTE, convertDataSize, convertDuration, convertSpeed } from "@mountaya/elements/units";
|
|
16
|
+
import { MountayaElementsError, MountayaElementsNotFoundError } from "@mountaya/elements/errors";
|
|
17
|
+
import { ITINERARY_ENDPOINT_ICONS, ITINERARY_LINE_SOURCE_LAYER, ITINERARY_POINT_SOURCE_LAYER, ITINERARY_RESTRICTION_SOURCE_LAYER, findOverlay, overlayInstant, roadAccessIconLayerIdOf, timestampedSources, zoneLevelColors } from "@mountaya/elements/layers";
|
|
18
|
+
import { DEFAULT_SEGMENT_COLOR, pickLivelyColor } from "@mountaya/elements/style";
|
|
19
|
+
import { DEFAULT_WAYPOINT_COLOR, DEFAULT_WAYPOINT_ICON } from "@mountaya/elements/icons";
|
|
20
|
+
import { DEFAULT_SEGMENT_TABLE_COLUMNS, DEFAULT_WAYPOINT_TABLE_COLUMNS, buildElevationPoints, buildInfoBands, durationForSpeed, formatDistance, formatHumidity, formatSnowDepth, formatSnowfall, formatSpeed, formatTemperature, resolveSpeedKmh } from "@mountaya/elements/profile";
|
|
21
|
+
import { representativeStillFraction } from "@mountaya/elements/camera";
|
|
22
|
+
import { MAP_LANGUAGES, languageEndonym } from "@mountaya/elements/i18n";
|
|
23
|
+
import { peerDraftInitials } from "@mountaya/elements/collab";
|
|
24
|
+
const defineRegistry = (registry) => registry;
|
|
25
|
+
const lateBoundTool = (read) => ({
|
|
26
|
+
get agentHidden() {
|
|
27
|
+
return read().agentHidden;
|
|
28
|
+
},
|
|
29
|
+
get capability() {
|
|
30
|
+
return read().capability;
|
|
31
|
+
},
|
|
32
|
+
get confirmation() {
|
|
33
|
+
return read().confirmation;
|
|
34
|
+
},
|
|
35
|
+
get confirmationValues() {
|
|
36
|
+
return read().confirmationValues;
|
|
37
|
+
},
|
|
38
|
+
get description() {
|
|
39
|
+
return read().description;
|
|
40
|
+
},
|
|
41
|
+
get handler() {
|
|
42
|
+
return read().handler;
|
|
43
|
+
},
|
|
44
|
+
get input() {
|
|
45
|
+
return read().input;
|
|
46
|
+
},
|
|
47
|
+
get name() {
|
|
48
|
+
return read().name;
|
|
49
|
+
},
|
|
50
|
+
get output() {
|
|
51
|
+
return read().output;
|
|
52
|
+
},
|
|
53
|
+
get precondition() {
|
|
54
|
+
return read().precondition;
|
|
55
|
+
},
|
|
56
|
+
get requiresConfirmation() {
|
|
57
|
+
return read().requiresConfirmation;
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
const lateBoundTools = (names, tools) => {
|
|
61
|
+
const bound = {};
|
|
62
|
+
for (const name of names) {
|
|
63
|
+
const record = tools();
|
|
64
|
+
const initial = Object.hasOwn(record, name) ? record[name] : void 0;
|
|
65
|
+
if (initial === void 0) continue;
|
|
66
|
+
let held = initial;
|
|
67
|
+
bound[name] = lateBoundTool(() => {
|
|
68
|
+
const current = tools();
|
|
69
|
+
held = (Object.hasOwn(current, name) ? current[name] : void 0) ?? held;
|
|
70
|
+
return held;
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
return bound;
|
|
74
|
+
};
|
|
75
|
+
const studioCollabTools = {
|
|
76
|
+
changeApply: "studio.collab.change.apply",
|
|
77
|
+
listApply: "studio.collab.list.apply",
|
|
78
|
+
lockClear: "studio.collab.lock.clear",
|
|
79
|
+
lockSet: "studio.collab.lock.set",
|
|
80
|
+
lockSnapshot: "studio.collab.lock.snapshot",
|
|
81
|
+
peerDraftClear: "studio.collab.peerDraft.clear",
|
|
82
|
+
peerDraftSet: "studio.collab.peerDraft.set",
|
|
83
|
+
peerSelectionSet: "studio.collab.peerSelection.set",
|
|
84
|
+
presenceClear: "studio.collab.presence.clear",
|
|
85
|
+
presenceSet: "studio.collab.presence.set",
|
|
86
|
+
presenceSnapshot: "studio.collab.presence.snapshot"
|
|
87
|
+
};
|
|
88
|
+
const collectionContentRoles = /* @__PURE__ */ new Set([
|
|
89
|
+
"owner",
|
|
90
|
+
"admin",
|
|
91
|
+
"contributor"
|
|
92
|
+
]);
|
|
93
|
+
const collectionMetadataRoles = /* @__PURE__ */ new Set(["owner", "admin"]);
|
|
94
|
+
const canEditCollection = (role) => collectionContentRoles.has(role);
|
|
95
|
+
const canEditCollectionMetadata = (role, isAuthor) => collectionMetadataRoles.has(role) || isAuthor && collectionContentRoles.has(role);
|
|
96
|
+
const canDeleteCollection = canEditCollectionMetadata;
|
|
97
|
+
const collectionFormSchema = z$1.object({
|
|
98
|
+
description: descriptionSchema,
|
|
99
|
+
isPrivate: z$1.boolean(),
|
|
100
|
+
name: displayNameSchema
|
|
101
|
+
});
|
|
102
|
+
const collectionCreateScope = (organizationId, isPersonalScope) => isPersonalScope(organizationId) ? void 0 : organizationId ?? void 0;
|
|
103
|
+
const projectEntityCollections = (collections, holding) => {
|
|
104
|
+
const held = new Set(holding.map(({ id }) => id));
|
|
105
|
+
const rows = /* @__PURE__ */ new Map();
|
|
106
|
+
for (const collection of [...collections, ...holding]) if (!rows.has(collection.id)) rows.set(collection.id, {
|
|
107
|
+
has: held.has(collection.id),
|
|
108
|
+
id: collection.id,
|
|
109
|
+
name: collection.name,
|
|
110
|
+
role: collection.role
|
|
111
|
+
});
|
|
112
|
+
return [...rows.values()];
|
|
113
|
+
};
|
|
114
|
+
const KEY_PREFIX_LENGTH = 7;
|
|
115
|
+
const truncateKey = (key) => key.length <= 12 ? key : `${key.slice(0, KEY_PREFIX_LENGTH)}…${key.slice(-4)}`;
|
|
116
|
+
const itineraryUpdateFields = {
|
|
117
|
+
description: true,
|
|
118
|
+
is_private: true,
|
|
119
|
+
name: true
|
|
120
|
+
};
|
|
121
|
+
const itineraryCreateFields = {
|
|
122
|
+
activity_id: true,
|
|
123
|
+
description: true,
|
|
124
|
+
is_private: true,
|
|
125
|
+
name: true,
|
|
126
|
+
organization_id: true
|
|
127
|
+
};
|
|
128
|
+
const segmentCreateFields = {
|
|
129
|
+
before_segment_id: true,
|
|
130
|
+
color: true,
|
|
131
|
+
description: true,
|
|
132
|
+
geojson: true,
|
|
133
|
+
mode: true,
|
|
134
|
+
name: true,
|
|
135
|
+
speed: true,
|
|
136
|
+
start_at: true
|
|
137
|
+
};
|
|
138
|
+
const segmentUpdateFields = {
|
|
139
|
+
color: true,
|
|
140
|
+
description: true,
|
|
141
|
+
geojson: true,
|
|
142
|
+
name: true,
|
|
143
|
+
speed: true,
|
|
144
|
+
start_at: true
|
|
145
|
+
};
|
|
146
|
+
const segmentSplitFields = {
|
|
147
|
+
first_name: true,
|
|
148
|
+
fraction: true,
|
|
149
|
+
second_name: true
|
|
150
|
+
};
|
|
151
|
+
const segmentConvertFields = { mode: true };
|
|
152
|
+
const segmentGroupCreateFields = {
|
|
153
|
+
color: true,
|
|
154
|
+
name: true,
|
|
155
|
+
segment_ids: true,
|
|
156
|
+
speed: true
|
|
157
|
+
};
|
|
158
|
+
const segmentGroupUpdateFields = {
|
|
159
|
+
color: true,
|
|
160
|
+
name: true,
|
|
161
|
+
segment_ids: true,
|
|
162
|
+
speed: true
|
|
163
|
+
};
|
|
164
|
+
const itineraryDuplicateFields = {
|
|
165
|
+
name: true,
|
|
166
|
+
organization_id: true,
|
|
167
|
+
segment_ids: true,
|
|
168
|
+
waypoint_ids: true
|
|
169
|
+
};
|
|
170
|
+
const waypointCreateFields = {
|
|
171
|
+
amenities: true,
|
|
172
|
+
color: true,
|
|
173
|
+
contact: true,
|
|
174
|
+
description: true,
|
|
175
|
+
geojson: true,
|
|
176
|
+
icon: true,
|
|
177
|
+
media: true,
|
|
178
|
+
mode: true,
|
|
179
|
+
name: true,
|
|
180
|
+
position: true,
|
|
181
|
+
properties: true,
|
|
182
|
+
timing: true
|
|
183
|
+
};
|
|
184
|
+
const waypointUpdateFields = {
|
|
185
|
+
amenities: true,
|
|
186
|
+
color: true,
|
|
187
|
+
contact: true,
|
|
188
|
+
description: true,
|
|
189
|
+
geojson: true,
|
|
190
|
+
icon: true,
|
|
191
|
+
media: true,
|
|
192
|
+
name: true,
|
|
193
|
+
position: true,
|
|
194
|
+
properties: true,
|
|
195
|
+
timing: true
|
|
196
|
+
};
|
|
197
|
+
const partOf = (parts, id, operation) => {
|
|
198
|
+
const part = parts.find((candidate) => candidate.id === id);
|
|
199
|
+
if (part === void 0) throw new MountayaElementsError(`${operation}: the write landed, and the itinerary it answered holds no part ${String(id)}. Read the itinerary again to see it.`);
|
|
200
|
+
return part;
|
|
201
|
+
};
|
|
202
|
+
const updateItinerary = async (client, itineraryId, params) => {
|
|
203
|
+
const body = await client.studio.itineraries.patchItinerary({
|
|
204
|
+
body: declaredBody(params, itineraryUpdateFields),
|
|
205
|
+
itinerary_id: itineraryId
|
|
206
|
+
});
|
|
207
|
+
return withItineraryAnalysis(body.data);
|
|
208
|
+
};
|
|
209
|
+
const updateSegment = async (client, itineraryId, segmentId, params) => {
|
|
210
|
+
try {
|
|
211
|
+
const body = await client.studio.itineraries.patchItinerarySegment({
|
|
212
|
+
body: declaredBody(params, segmentUpdateFields),
|
|
213
|
+
itinerary_id: itineraryId,
|
|
214
|
+
segment_id: segmentId
|
|
215
|
+
});
|
|
216
|
+
return withSegmentAnalysis(partOf(body.data.segments, segmentId, "update segment"));
|
|
217
|
+
} catch (error) {
|
|
218
|
+
return rethrowSegmentWriteError(error);
|
|
219
|
+
}
|
|
220
|
+
};
|
|
221
|
+
const deleteItinerary = async (client, itineraryId) => {
|
|
222
|
+
await client.studio.itineraries.deleteItinerary({ itinerary_id: itineraryId });
|
|
223
|
+
};
|
|
224
|
+
const readMadeItinerary = async (client, location) => {
|
|
225
|
+
const itineraryId = createdIdOf({ location });
|
|
226
|
+
if (itineraryId === void 0) return null;
|
|
227
|
+
try {
|
|
228
|
+
return await fetchItineraryRecord(client, itineraryId);
|
|
229
|
+
} catch {
|
|
230
|
+
return null;
|
|
231
|
+
}
|
|
232
|
+
};
|
|
233
|
+
const createItinerary = async (client, params) => reconcileMadeWrite(async () => {
|
|
234
|
+
const body = await client.studio.itineraries.postItinerary({ body: declaredBody(params, itineraryCreateFields) });
|
|
235
|
+
return withItineraryAnalysis(body.data);
|
|
236
|
+
}, (answer) => readMadeItinerary(client, answer.location));
|
|
237
|
+
const createSegment = async (client, itineraryId, params) => {
|
|
238
|
+
try {
|
|
239
|
+
const body = await client.studio.itineraries.postItinerarySegment({
|
|
240
|
+
body: declaredBody(params, segmentCreateFields),
|
|
241
|
+
itinerary_id: itineraryId
|
|
242
|
+
});
|
|
243
|
+
return withSegmentAnalysis(partOf(body.data.segments, body.extensions.metadata.created.id, "create segment"));
|
|
244
|
+
} catch (error) {
|
|
245
|
+
return rethrowSegmentWriteError(error);
|
|
246
|
+
}
|
|
247
|
+
};
|
|
248
|
+
const deleteSegment = async (client, itineraryId, segmentId) => {
|
|
249
|
+
try {
|
|
250
|
+
await client.studio.itineraries.deleteItinerarySegment({
|
|
251
|
+
itinerary_id: itineraryId,
|
|
252
|
+
segment_id: segmentId
|
|
253
|
+
});
|
|
254
|
+
} catch (error) {
|
|
255
|
+
return rethrowSegmentWriteError(error, "delete");
|
|
256
|
+
}
|
|
257
|
+
};
|
|
258
|
+
const mergeSegment = async (client, itineraryId, segmentId) => {
|
|
259
|
+
try {
|
|
260
|
+
const body = await client.studio.itineraries.postItinerarySegmentMerge({
|
|
261
|
+
itinerary_id: itineraryId,
|
|
262
|
+
segment_id: segmentId
|
|
263
|
+
});
|
|
264
|
+
return withItineraryAnalysis(body.data);
|
|
265
|
+
} catch (error) {
|
|
266
|
+
return rethrowSegmentWriteError(error);
|
|
267
|
+
}
|
|
268
|
+
};
|
|
269
|
+
const splitSegment = async (client, itineraryId, segmentId, params) => {
|
|
270
|
+
try {
|
|
271
|
+
const body = await client.studio.itineraries.postItinerarySegmentSplit({
|
|
272
|
+
body: declaredBody(params, segmentSplitFields),
|
|
273
|
+
itinerary_id: itineraryId,
|
|
274
|
+
segment_id: segmentId
|
|
275
|
+
});
|
|
276
|
+
return withItineraryAnalysis(body.data);
|
|
277
|
+
} catch (error) {
|
|
278
|
+
return rethrowSegmentWriteError(error);
|
|
279
|
+
}
|
|
280
|
+
};
|
|
281
|
+
const convertSegment = async (client, itineraryId, segmentId, params) => {
|
|
282
|
+
try {
|
|
283
|
+
const body = await client.studio.itineraries.postItinerarySegmentConvert({
|
|
284
|
+
body: declaredBody(params, segmentConvertFields),
|
|
285
|
+
itinerary_id: itineraryId,
|
|
286
|
+
segment_id: segmentId
|
|
287
|
+
});
|
|
288
|
+
return withItineraryAnalysis(body.data);
|
|
289
|
+
} catch (error) {
|
|
290
|
+
return rethrowSegmentWriteError(error);
|
|
291
|
+
}
|
|
292
|
+
};
|
|
293
|
+
const createSegmentGroup = async (client, itineraryId, params) => {
|
|
294
|
+
try {
|
|
295
|
+
const body = await client.studio.itineraries.postItinerarySegmentGroup({
|
|
296
|
+
body: declaredBody(params, segmentGroupCreateFields),
|
|
297
|
+
itinerary_id: itineraryId
|
|
298
|
+
});
|
|
299
|
+
return withItineraryAnalysis(body.data);
|
|
300
|
+
} catch (error) {
|
|
301
|
+
return rethrowSegmentWriteError(error);
|
|
302
|
+
}
|
|
303
|
+
};
|
|
304
|
+
const updateSegmentGroup = async (client, itineraryId, groupId, params) => {
|
|
305
|
+
try {
|
|
306
|
+
const body = await client.studio.itineraries.patchItinerarySegmentGroup({
|
|
307
|
+
body: declaredBody(params, segmentGroupUpdateFields),
|
|
308
|
+
group_id: groupId,
|
|
309
|
+
itinerary_id: itineraryId
|
|
310
|
+
});
|
|
311
|
+
return withItineraryAnalysis(body.data);
|
|
312
|
+
} catch (error) {
|
|
313
|
+
return rethrowSegmentWriteError(error);
|
|
314
|
+
}
|
|
315
|
+
};
|
|
316
|
+
const deleteSegmentGroup = async (client, itineraryId, groupId) => {
|
|
317
|
+
try {
|
|
318
|
+
const body = await client.studio.itineraries.deleteItinerarySegmentGroup({
|
|
319
|
+
group_id: groupId,
|
|
320
|
+
itinerary_id: itineraryId
|
|
321
|
+
});
|
|
322
|
+
return withItineraryAnalysis(body.data);
|
|
323
|
+
} catch (error) {
|
|
324
|
+
return rethrowSegmentWriteError(error);
|
|
325
|
+
}
|
|
326
|
+
};
|
|
327
|
+
const duplicateItinerary = async (client, itineraryId, params) => reconcileMadeWrite(async () => {
|
|
328
|
+
const body = await client.studio.itineraries.postItineraryDuplicate({
|
|
329
|
+
body: declaredBody(params, itineraryDuplicateFields),
|
|
330
|
+
itinerary_id: itineraryId
|
|
331
|
+
});
|
|
332
|
+
return withItineraryAnalysis(body.data);
|
|
333
|
+
}, (answer) => readMadeItinerary(client, answer.location));
|
|
334
|
+
const publishItinerary = async (client, itineraryId) => reconcileMadeWrite(async () => {
|
|
335
|
+
try {
|
|
336
|
+
const body = await client.studio.itineraries.postItineraryPublication({ itinerary_id: itineraryId });
|
|
337
|
+
return withItineraryAnalysis(body.data);
|
|
338
|
+
} catch (error) {
|
|
339
|
+
return rethrowSegmentWriteError(error);
|
|
340
|
+
}
|
|
341
|
+
}, () => fetchItineraryRecord(client, itineraryId));
|
|
342
|
+
const unpublishItinerary = async (client, itineraryId) => reconcileMadeWrite(async () => {
|
|
343
|
+
const body = await client.studio.itineraries.deleteItineraryPublication({ itinerary_id: itineraryId });
|
|
344
|
+
return withItineraryAnalysis(body.data);
|
|
345
|
+
}, () => fetchItineraryRecord(client, itineraryId));
|
|
346
|
+
const createWaypoint = async (client, itineraryId, params) => {
|
|
347
|
+
const body = await client.studio.itineraries.postItineraryWaypoint({
|
|
348
|
+
body: declaredBody(params, waypointCreateFields),
|
|
349
|
+
itinerary_id: itineraryId
|
|
350
|
+
});
|
|
351
|
+
return partOf(body.data.waypoints, body.extensions.metadata.created.id, "create waypoint");
|
|
352
|
+
};
|
|
353
|
+
const updateWaypoint = async (client, itineraryId, waypointId, params) => {
|
|
354
|
+
const body = await client.studio.itineraries.patchItineraryWaypoint({
|
|
355
|
+
body: declaredBody(params, waypointUpdateFields),
|
|
356
|
+
itinerary_id: itineraryId,
|
|
357
|
+
waypoint_id: waypointId
|
|
358
|
+
});
|
|
359
|
+
return partOf(body.data.waypoints, waypointId, "update waypoint");
|
|
360
|
+
};
|
|
361
|
+
const deleteWaypoint = async (client, itineraryId, waypointId) => {
|
|
362
|
+
await client.studio.itineraries.deleteItineraryWaypoint({
|
|
363
|
+
itinerary_id: itineraryId,
|
|
364
|
+
waypoint_id: waypointId
|
|
365
|
+
});
|
|
366
|
+
};
|
|
367
|
+
const shareLinkSchema = z$1.object({
|
|
368
|
+
created_at: z$1.date(),
|
|
369
|
+
share_token: z$1.string().min(1)
|
|
370
|
+
});
|
|
371
|
+
const shareLinkResponseSchema = z$1.object({ data: shareLinkSchema });
|
|
372
|
+
const shareLinkReadSchema = z$1.object({ data: shareLinkSchema.nullable() });
|
|
373
|
+
const mintItineraryShareLink = async (client, itineraryId) => {
|
|
374
|
+
const envelope = await client.studio.itineraries.postItineraryShareLink({ itinerary_id: itineraryId });
|
|
375
|
+
return shareLinkResponseSchema.parse(envelope).data;
|
|
376
|
+
};
|
|
377
|
+
const rotateItineraryShareLink = async (client, itineraryId) => {
|
|
378
|
+
const envelope = await client.studio.itineraries.postItineraryShareLinkRotate({ itinerary_id: itineraryId });
|
|
379
|
+
return shareLinkResponseSchema.parse(envelope).data;
|
|
380
|
+
};
|
|
381
|
+
const disableItineraryShareLink = async (client, itineraryId) => {
|
|
382
|
+
await client.studio.itineraries.deleteItineraryShareLink({ itinerary_id: itineraryId });
|
|
383
|
+
};
|
|
384
|
+
const fetchItineraryShareLink = async (client, itineraryId) => {
|
|
385
|
+
const envelope = await client.studio.itineraries.getItineraryShareLink({ itinerary_id: itineraryId });
|
|
386
|
+
return shareLinkReadSchema.parse(envelope).data;
|
|
387
|
+
};
|
|
388
|
+
const restStudioPersistence = (client) => ({
|
|
389
|
+
tiled: true,
|
|
390
|
+
convertSegment: (itineraryId, segmentId, params) => convertSegment(client, itineraryId, segmentId, params),
|
|
391
|
+
createItinerary: (params) => createItinerary(client, params),
|
|
392
|
+
createSegment: (itineraryId, params) => createSegment(client, itineraryId, params),
|
|
393
|
+
createSegmentGroup: (itineraryId, params) => createSegmentGroup(client, itineraryId, params),
|
|
394
|
+
createWaypoint: (itineraryId, params) => createWaypoint(client, itineraryId, params),
|
|
395
|
+
deleteItinerary: (itineraryId) => deleteItinerary(client, itineraryId),
|
|
396
|
+
deleteSegment: (itineraryId, segmentId) => deleteSegment(client, itineraryId, segmentId),
|
|
397
|
+
deleteSegmentGroup: (itineraryId, groupId) => deleteSegmentGroup(client, itineraryId, groupId),
|
|
398
|
+
deleteWaypoint: (itineraryId, waypointId) => deleteWaypoint(client, itineraryId, waypointId),
|
|
399
|
+
disableItineraryShareLink: (itineraryId) => disableItineraryShareLink(client, itineraryId),
|
|
400
|
+
duplicateItinerary: (itineraryId, params) => duplicateItinerary(client, itineraryId, params),
|
|
401
|
+
fetchItineraryRecord: (itineraryId, surface) => fetchItineraryRecord(client, itineraryId, surface),
|
|
402
|
+
fetchItineraryShareLink: (itineraryId) => fetchItineraryShareLink(client, itineraryId),
|
|
403
|
+
mergeSegment: (itineraryId, segmentId) => mergeSegment(client, itineraryId, segmentId),
|
|
404
|
+
mintItineraryShareLink: (itineraryId) => mintItineraryShareLink(client, itineraryId),
|
|
405
|
+
publishItinerary: (itineraryId) => publishItinerary(client, itineraryId),
|
|
406
|
+
rotateItineraryShareLink: (itineraryId) => rotateItineraryShareLink(client, itineraryId),
|
|
407
|
+
splitSegment: (itineraryId, segmentId, params) => splitSegment(client, itineraryId, segmentId, params),
|
|
408
|
+
unpublishItinerary: (itineraryId) => unpublishItinerary(client, itineraryId),
|
|
409
|
+
updateItinerary: (itineraryId, params) => updateItinerary(client, itineraryId, params),
|
|
410
|
+
updateSegment: (itineraryId, segmentId, params) => updateSegment(client, itineraryId, segmentId, params),
|
|
411
|
+
updateSegmentGroup: (itineraryId, groupId, params) => updateSegmentGroup(client, itineraryId, groupId, params),
|
|
412
|
+
updateWaypoint: (itineraryId, waypointId, params) => updateWaypoint(client, itineraryId, waypointId, params)
|
|
413
|
+
});
|
|
414
|
+
const PERSISTENCE_REFUSED_NAME = "StudioPersistenceRefusedError";
|
|
415
|
+
var StudioPersistenceRefusedError = class extends MountayaElementsError {
|
|
416
|
+
name = PERSISTENCE_REFUSED_NAME;
|
|
417
|
+
};
|
|
418
|
+
const refusedError = (verb) => new StudioPersistenceRefusedError(`${verb} is not available in a local studio session`);
|
|
419
|
+
const DEFAULT_NAMESPACE = "studio";
|
|
420
|
+
const instantOf = (clock) => {
|
|
421
|
+
const reading = clock.now();
|
|
422
|
+
const instant = new Date(reading);
|
|
423
|
+
if (Number.isNaN(instant.getTime())) throw new MountayaElementsError(`local studio session: the clock seam reads no instant (${String(reading)}), so the write has no time to carry. Hand the session a clock whose now() answers epoch milliseconds.`);
|
|
424
|
+
return instant;
|
|
425
|
+
};
|
|
426
|
+
const withLocalMetrics = (segment) => {
|
|
427
|
+
let ascent = 0;
|
|
428
|
+
let descent = 0;
|
|
429
|
+
let lowest = Number.POSITIVE_INFINITY;
|
|
430
|
+
let highest = Number.NEGATIVE_INFINITY;
|
|
431
|
+
let readings = 0;
|
|
432
|
+
let distance = null;
|
|
433
|
+
for (const line of extractLines(segment.geojson)) {
|
|
434
|
+
if (line.coordinates.length > 1) distance = (distance ?? 0) + segmentLengthMeters(line);
|
|
435
|
+
let previous = null;
|
|
436
|
+
for (const position of line.coordinates) {
|
|
437
|
+
const elevation = position[2];
|
|
438
|
+
if (typeof elevation !== "number") continue;
|
|
439
|
+
if (previous !== null) {
|
|
440
|
+
const step = elevation - previous;
|
|
441
|
+
if (step > 0) ascent += step;
|
|
442
|
+
else descent -= step;
|
|
443
|
+
}
|
|
444
|
+
lowest = Math.min(lowest, elevation);
|
|
445
|
+
highest = Math.max(highest, elevation);
|
|
446
|
+
previous = elevation;
|
|
447
|
+
readings += 1;
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
const has3d = readings > 1;
|
|
451
|
+
return withSegmentAnalysis({
|
|
452
|
+
...segment,
|
|
453
|
+
altitude_max: has3d ? highest : null,
|
|
454
|
+
altitude_min: has3d ? lowest : null,
|
|
455
|
+
ascent: has3d ? ascent : null,
|
|
456
|
+
descent: has3d ? descent : null,
|
|
457
|
+
distance
|
|
458
|
+
});
|
|
459
|
+
};
|
|
460
|
+
const routedGeometry = async (geojson, mode, activityId, route) => {
|
|
461
|
+
if (!route || mode !== "directions" || !geojson) return geojson;
|
|
462
|
+
if (extractLines(geojson).length > 0) return geojson;
|
|
463
|
+
const vias = extractVias(geojson);
|
|
464
|
+
if (vias.length < 2) return geojson;
|
|
465
|
+
try {
|
|
466
|
+
const line = await route({
|
|
467
|
+
activityId,
|
|
468
|
+
vias: vias.map((via) => [...via])
|
|
469
|
+
});
|
|
470
|
+
return line ? buildGeometryCollection([line, {
|
|
471
|
+
coordinates: vias,
|
|
472
|
+
type: "MultiPoint"
|
|
473
|
+
}]) : geojson;
|
|
474
|
+
} catch {
|
|
475
|
+
return geojson;
|
|
476
|
+
}
|
|
477
|
+
};
|
|
478
|
+
const sum = (values) => {
|
|
479
|
+
const present = values.filter((value) => value !== null);
|
|
480
|
+
return present.length ? present.reduce((total, value) => total + value, 0) : null;
|
|
481
|
+
};
|
|
482
|
+
const withRollUp = (itinerary) => {
|
|
483
|
+
const segments = itinerary.segments.map((segment, index) => ({
|
|
484
|
+
...segment,
|
|
485
|
+
position: index
|
|
486
|
+
}));
|
|
487
|
+
return withItineraryAnalysis({
|
|
488
|
+
...itinerary,
|
|
489
|
+
ascent: sum(segments.map((segment) => segment.ascent)),
|
|
490
|
+
count: {
|
|
491
|
+
...itinerary.count,
|
|
492
|
+
groups: itinerary.groups.length,
|
|
493
|
+
segments: segments.length,
|
|
494
|
+
waypoints: itinerary.waypoints.length
|
|
495
|
+
},
|
|
496
|
+
distance: sum(segments.map((segment) => segment.distance)),
|
|
497
|
+
segments
|
|
498
|
+
});
|
|
499
|
+
};
|
|
500
|
+
const clearedText = (sent, held) => {
|
|
501
|
+
if (sent === void 0) return held;
|
|
502
|
+
return sent === null || sent.trim() === "" ? null : sent;
|
|
503
|
+
};
|
|
504
|
+
const segmentOf = (record, segmentId) => {
|
|
505
|
+
const segment = record.segments.find((candidate) => candidate.id === segmentId);
|
|
506
|
+
if (!segment) throw new MountayaElementsNotFoundError(`local studio session holds no segment ${segmentId}`);
|
|
507
|
+
return segment;
|
|
508
|
+
};
|
|
509
|
+
const waypointOf = (record, waypointId) => {
|
|
510
|
+
const waypoint = record.waypoints.find((candidate) => candidate.id === waypointId);
|
|
511
|
+
if (!waypoint) throw new MountayaElementsNotFoundError(`local studio session holds no waypoint ${waypointId}`);
|
|
512
|
+
return waypoint;
|
|
513
|
+
};
|
|
514
|
+
const activityDefaultSpeed = (read, activityId) => {
|
|
515
|
+
if (!read) return null;
|
|
516
|
+
try {
|
|
517
|
+
const speed = read(activityId);
|
|
518
|
+
return typeof speed === "number" && Number.isFinite(speed) && speed > 0 ? speed : null;
|
|
519
|
+
} catch {
|
|
520
|
+
return null;
|
|
521
|
+
}
|
|
522
|
+
};
|
|
523
|
+
const rescaledDuration = (segment, speed, activityDefault) => {
|
|
524
|
+
const held = resolveSpeedKmh(segment.speed, activityDefault);
|
|
525
|
+
const next = resolveSpeedKmh(speed, activityDefault);
|
|
526
|
+
if (held === null || next === null) return segment.duration;
|
|
527
|
+
return durationForSpeed({
|
|
528
|
+
baseDurationSeconds: segment.duration,
|
|
529
|
+
baseSpeedKmh: held,
|
|
530
|
+
distanceMeters: segment.distance,
|
|
531
|
+
targetSpeedKmh: next
|
|
532
|
+
}) ?? segment.duration;
|
|
533
|
+
};
|
|
534
|
+
const updatedSegment = (segment, params, geojson, activityDefault) => {
|
|
535
|
+
const next = {
|
|
536
|
+
...segment,
|
|
537
|
+
color: params.color === void 0 ? segment.color : params.color,
|
|
538
|
+
description: clearedText(params.description, segment.description),
|
|
539
|
+
duration: params.speed === void 0 ? segment.duration : rescaledDuration(segment, params.speed, activityDefault),
|
|
540
|
+
geojson: geojson ?? segment.geojson,
|
|
541
|
+
name: params.name ?? segment.name,
|
|
542
|
+
revision: segment.revision + 1,
|
|
543
|
+
speed: params.speed === void 0 ? segment.speed : params.speed,
|
|
544
|
+
start_at: params.start_at === void 0 ? segment.start_at : params.start_at
|
|
545
|
+
};
|
|
546
|
+
return geojson ? withLocalMetrics(next) : next;
|
|
547
|
+
};
|
|
548
|
+
const updatedWaypoint = (waypoint, params) => ({
|
|
549
|
+
...waypoint,
|
|
550
|
+
amenities: params.amenities === void 0 ? waypoint.amenities : params.amenities ?? [],
|
|
551
|
+
color: params.color === void 0 ? waypoint.color : params.color,
|
|
552
|
+
contact: params.contact === void 0 ? waypoint.contact : params.contact,
|
|
553
|
+
description: clearedText(params.description, waypoint.description),
|
|
554
|
+
geojson: params.geojson ?? waypoint.geojson,
|
|
555
|
+
icon: params.icon ?? waypoint.icon,
|
|
556
|
+
media: params.media === void 0 ? waypoint.media : params.media,
|
|
557
|
+
name: params.name === void 0 ? waypoint.name : params.name,
|
|
558
|
+
position: params.position ?? waypoint.position,
|
|
559
|
+
properties: params.properties === void 0 ? waypoint.properties : params.properties,
|
|
560
|
+
revision: waypoint.revision + 1,
|
|
561
|
+
timing: params.timing === void 0 ? waypoint.timing : params.timing
|
|
562
|
+
});
|
|
563
|
+
const sameRecord = (kept, written) => kept === written || kept !== void 0 && JSON.stringify(kept) === JSON.stringify(written);
|
|
564
|
+
const createLocalRecords = (drawer, clock, seed) => {
|
|
565
|
+
let seeded = null;
|
|
566
|
+
let unkept = null;
|
|
567
|
+
const seedRecords = () => {
|
|
568
|
+
seeded ??= Object.fromEntries(seed.map((itinerary) => [itinerary.id, withRollUp(itinerary)]));
|
|
569
|
+
return seeded;
|
|
570
|
+
};
|
|
571
|
+
const written = () => unkept ?? drawer.read() ?? {};
|
|
572
|
+
const recordIn = (document, itineraryId) => {
|
|
573
|
+
const record = document[itineraryId] ?? seedRecords()[itineraryId];
|
|
574
|
+
if (!record) throw new MountayaElementsNotFoundError(`local studio session holds no itinerary ${itineraryId}`);
|
|
575
|
+
return record;
|
|
576
|
+
};
|
|
577
|
+
return {
|
|
578
|
+
commit: (itineraryId, change) => {
|
|
579
|
+
const held = written();
|
|
580
|
+
const current = recordIn(held, itineraryId);
|
|
581
|
+
const stamp = instantOf(clock);
|
|
582
|
+
const next = withRollUp({
|
|
583
|
+
...change(current, stamp),
|
|
584
|
+
updated_at: stamp
|
|
585
|
+
});
|
|
586
|
+
const document = {
|
|
587
|
+
...held,
|
|
588
|
+
[next.id]: next
|
|
589
|
+
};
|
|
590
|
+
drawer.write(document);
|
|
591
|
+
unkept = sameRecord(drawer.read()?.[next.id], next) ? null : document;
|
|
592
|
+
return next;
|
|
593
|
+
},
|
|
594
|
+
recordOf: (itineraryId) => recordIn(written(), itineraryId)
|
|
595
|
+
};
|
|
596
|
+
};
|
|
597
|
+
const createLocalPersistence = (drawer, options) => {
|
|
598
|
+
const { clock = studioSeamAbsences.clock, ids = studioSeamAbsences.ids } = options;
|
|
599
|
+
const { defaultSpeed, route, seed = [] } = options;
|
|
600
|
+
const records = createLocalRecords(drawer, clock, seed);
|
|
601
|
+
const refuse = (verb) => Promise.reject(refusedError(verb));
|
|
602
|
+
return {
|
|
603
|
+
tiled: false,
|
|
604
|
+
convertSegment: () => refuse("Changing a segment's authoring mode"),
|
|
605
|
+
createItinerary: () => refuse("Creating an itinerary"),
|
|
606
|
+
createSegment: async (itineraryId, params) => {
|
|
607
|
+
const { activity_id: activityId } = records.recordOf(itineraryId);
|
|
608
|
+
const geojson = await routedGeometry(params.geojson, params.mode, activityId, route);
|
|
609
|
+
const id = localId(ids);
|
|
610
|
+
const saved = records.commit(itineraryId, (current, stamp) => {
|
|
611
|
+
const segment = withLocalMetrics({
|
|
612
|
+
...blankSegment(current, stamp, id),
|
|
613
|
+
color: params.color ?? null,
|
|
614
|
+
description: params.description ?? null,
|
|
615
|
+
geojson: geojson ?? null,
|
|
616
|
+
mode: params.mode,
|
|
617
|
+
name: params.name,
|
|
618
|
+
speed: params.speed ?? null,
|
|
619
|
+
start_at: params.start_at ?? null
|
|
620
|
+
});
|
|
621
|
+
const before = params.before_segment_id;
|
|
622
|
+
const at = before === void 0 ? current.segments.length : current.segments.indexOf(segmentOf(current, before));
|
|
623
|
+
return {
|
|
624
|
+
...current,
|
|
625
|
+
segments: [
|
|
626
|
+
...current.segments.slice(0, at),
|
|
627
|
+
segment,
|
|
628
|
+
...current.segments.slice(at)
|
|
629
|
+
]
|
|
630
|
+
};
|
|
631
|
+
});
|
|
632
|
+
return segmentOf(saved, id);
|
|
633
|
+
},
|
|
634
|
+
createSegmentGroup: () => refuse("Creating a segment group"),
|
|
635
|
+
createWaypoint: async (itineraryId, params) => {
|
|
636
|
+
const id = localId(ids);
|
|
637
|
+
const saved = records.commit(itineraryId, (current, stamp) => ({
|
|
638
|
+
...current,
|
|
639
|
+
waypoints: [...current.waypoints, {
|
|
640
|
+
...blankWaypoint(current, stamp, id),
|
|
641
|
+
amenities: params.amenities ?? [],
|
|
642
|
+
color: params.color ?? null,
|
|
643
|
+
contact: params.contact ?? null,
|
|
644
|
+
description: params.description ?? null,
|
|
645
|
+
geojson: params.geojson ?? null,
|
|
646
|
+
icon: params.icon ?? null,
|
|
647
|
+
media: params.media ?? null,
|
|
648
|
+
mode: params.mode,
|
|
649
|
+
name: params.name ?? null,
|
|
650
|
+
position: params.position,
|
|
651
|
+
properties: params.properties ?? null,
|
|
652
|
+
timing: params.timing ?? null
|
|
653
|
+
}]
|
|
654
|
+
}));
|
|
655
|
+
return waypointOf(saved, id);
|
|
656
|
+
},
|
|
657
|
+
deleteItinerary: () => refuse("Deleting an itinerary"),
|
|
658
|
+
deleteSegment: async (itineraryId, segmentId) => {
|
|
659
|
+
records.commit(itineraryId, (current) => {
|
|
660
|
+
const index = current.segments.indexOf(segmentOf(current, segmentId));
|
|
661
|
+
if (index > 0 && index < current.segments.length - 1) throw new SegmentDeleteNotEdgeError(`local studio session: segment ${segmentId} is neither the first nor the last of the chain, and a chain shrinks from its ends only`);
|
|
662
|
+
return {
|
|
663
|
+
...current,
|
|
664
|
+
segments: current.segments.filter((segment) => segment.id !== segmentId)
|
|
665
|
+
};
|
|
666
|
+
});
|
|
667
|
+
},
|
|
668
|
+
deleteSegmentGroup: () => refuse("Deleting a segment group"),
|
|
669
|
+
deleteWaypoint: async (itineraryId, waypointId) => {
|
|
670
|
+
records.commit(itineraryId, (current) => {
|
|
671
|
+
const removed = waypointOf(current, waypointId);
|
|
672
|
+
return {
|
|
673
|
+
...current,
|
|
674
|
+
waypoints: current.waypoints.filter((waypoint) => waypoint !== removed)
|
|
675
|
+
};
|
|
676
|
+
});
|
|
677
|
+
},
|
|
678
|
+
disableItineraryShareLink: () => refuse("Disabling a share link"),
|
|
679
|
+
duplicateItinerary: () => refuse("Duplicating an itinerary"),
|
|
680
|
+
fetchItineraryRecord: async (itineraryId) => records.recordOf(itineraryId),
|
|
681
|
+
fetchItineraryShareLink: () => refuse("Reading a share link"),
|
|
682
|
+
mergeSegment: () => refuse("Merging two segments"),
|
|
683
|
+
mintItineraryShareLink: () => refuse("Minting a share link"),
|
|
684
|
+
publishItinerary: () => refuse("Publishing an itinerary"),
|
|
685
|
+
rotateItineraryShareLink: () => refuse("Rotating a share link"),
|
|
686
|
+
splitSegment: () => refuse("Splitting a segment"),
|
|
687
|
+
unpublishItinerary: () => refuse("Unpublishing an itinerary"),
|
|
688
|
+
updateItinerary: async (itineraryId, params) => records.commit(itineraryId, (current) => ({
|
|
689
|
+
...current,
|
|
690
|
+
description: clearedText(params.description, current.description),
|
|
691
|
+
is_private: params.is_private ?? current.is_private,
|
|
692
|
+
name: params.name ?? current.name,
|
|
693
|
+
revision: current.revision + 1
|
|
694
|
+
})),
|
|
695
|
+
updateSegment: async (itineraryId, segmentId, params) => {
|
|
696
|
+
const record = records.recordOf(itineraryId);
|
|
697
|
+
const { mode } = segmentOf(record, segmentId);
|
|
698
|
+
const geojson = await routedGeometry(params.geojson, mode, record.activity_id, route);
|
|
699
|
+
const activityDefault = params.speed === void 0 ? null : activityDefaultSpeed(defaultSpeed, record.activity_id);
|
|
700
|
+
const saved = records.commit(itineraryId, (current) => {
|
|
701
|
+
const held = segmentOf(current, segmentId);
|
|
702
|
+
return {
|
|
703
|
+
...current,
|
|
704
|
+
segments: current.segments.map((segment) => segment === held ? updatedSegment(segment, params, geojson, activityDefault) : segment)
|
|
705
|
+
};
|
|
706
|
+
});
|
|
707
|
+
return segmentOf(saved, segmentId);
|
|
708
|
+
},
|
|
709
|
+
updateSegmentGroup: () => refuse("Updating a segment group"),
|
|
710
|
+
updateWaypoint: async (itineraryId, waypointId, params) => {
|
|
711
|
+
const saved = records.commit(itineraryId, (current) => {
|
|
712
|
+
const held = waypointOf(current, waypointId);
|
|
713
|
+
return {
|
|
714
|
+
...current,
|
|
715
|
+
waypoints: current.waypoints.map((waypoint) => waypoint === held ? updatedWaypoint(waypoint, params) : waypoint)
|
|
716
|
+
};
|
|
717
|
+
});
|
|
718
|
+
return waypointOf(saved, waypointId);
|
|
719
|
+
}
|
|
720
|
+
};
|
|
721
|
+
};
|
|
722
|
+
const localStudioPersistence = (options = {}) => createLocalPersistence(localPersistenceDrawer(options.namespace ?? DEFAULT_NAMESPACE), options);
|
|
723
|
+
const memoryStudioPersistence = (options = {}) => createLocalPersistence(memoryPersistenceDrawer(), options);
|
|
724
|
+
const blankSegment = (record, stamp, id) => ({
|
|
725
|
+
altitude_max: null,
|
|
726
|
+
altitude_min: null,
|
|
727
|
+
ascent: null,
|
|
728
|
+
color: null,
|
|
729
|
+
created_at: stamp,
|
|
730
|
+
created_by: record.created_by,
|
|
731
|
+
descent: null,
|
|
732
|
+
description: null,
|
|
733
|
+
distance: null,
|
|
734
|
+
duration: null,
|
|
735
|
+
geojson: null,
|
|
736
|
+
gradient_max: null,
|
|
737
|
+
gradient_min: null,
|
|
738
|
+
group_id: null,
|
|
739
|
+
id,
|
|
740
|
+
itinerary_id: record.id,
|
|
741
|
+
mode: "linestring",
|
|
742
|
+
name: "",
|
|
743
|
+
position: 0,
|
|
744
|
+
revision: 1,
|
|
745
|
+
road_access_info: null,
|
|
746
|
+
slope_info: [],
|
|
747
|
+
speed: null,
|
|
748
|
+
speed_info: null,
|
|
749
|
+
start_at: null,
|
|
750
|
+
steps: [],
|
|
751
|
+
surface_info: [],
|
|
752
|
+
trail_difficulty_info: [],
|
|
753
|
+
way_type_info: []
|
|
754
|
+
});
|
|
755
|
+
const blankWaypoint = (record, stamp, id) => ({
|
|
756
|
+
amenities: [],
|
|
757
|
+
color: null,
|
|
758
|
+
contact: null,
|
|
759
|
+
created_at: stamp,
|
|
760
|
+
created_by: record.created_by,
|
|
761
|
+
description: null,
|
|
762
|
+
geojson: null,
|
|
763
|
+
icon: null,
|
|
764
|
+
id,
|
|
765
|
+
itinerary_id: record.id,
|
|
766
|
+
media: null,
|
|
767
|
+
mode: "point",
|
|
768
|
+
name: null,
|
|
769
|
+
position: 0,
|
|
770
|
+
properties: null,
|
|
771
|
+
revision: 1,
|
|
772
|
+
timing: null
|
|
773
|
+
});
|
|
774
|
+
const localId = (ids) => `local-${ids.next()}`;
|
|
775
|
+
const SESSION_TOKEN_PREFIX = "sess_";
|
|
776
|
+
const DEFAULT_SURFACE = "api";
|
|
777
|
+
const STUDIO_SURFACE = "studio-embedded";
|
|
778
|
+
const BASE64URL_ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
|
|
779
|
+
const base64UrlBytes = (text) => {
|
|
780
|
+
if (text.length % 4 === 1) return;
|
|
781
|
+
const bytes = [];
|
|
782
|
+
let buffer = 0;
|
|
783
|
+
let bits = 0;
|
|
784
|
+
for (const character of text) {
|
|
785
|
+
const value = BASE64URL_ALPHABET.indexOf(character);
|
|
786
|
+
if (value === -1) return;
|
|
787
|
+
buffer = buffer << 6 | value;
|
|
788
|
+
bits += 6;
|
|
789
|
+
if (bits >= 8) {
|
|
790
|
+
bits -= 8;
|
|
791
|
+
bytes.push(buffer >> bits & 255);
|
|
792
|
+
buffer &= (1 << bits) - 1;
|
|
793
|
+
}
|
|
794
|
+
}
|
|
795
|
+
return Uint8Array.from(bytes);
|
|
796
|
+
};
|
|
797
|
+
const payloadOf = (token) => {
|
|
798
|
+
if (!token.startsWith(SESSION_TOKEN_PREFIX)) return;
|
|
799
|
+
const body = token.slice(5);
|
|
800
|
+
const dot = body.indexOf(".");
|
|
801
|
+
if (dot <= 0 || dot === body.length - 1) return;
|
|
802
|
+
const bytes = base64UrlBytes(body.slice(0, dot));
|
|
803
|
+
if (bytes === void 0) return;
|
|
804
|
+
let parsed;
|
|
805
|
+
try {
|
|
806
|
+
parsed = JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(bytes));
|
|
807
|
+
} catch {
|
|
808
|
+
return;
|
|
809
|
+
}
|
|
810
|
+
return typeof parsed === "object" && parsed !== null && !Array.isArray(parsed) ? parsed : void 0;
|
|
811
|
+
};
|
|
812
|
+
const sessionTokenSurface = (token) => {
|
|
813
|
+
const payload = payloadOf(token);
|
|
814
|
+
if (payload === void 0) return;
|
|
815
|
+
if (!("surface" in payload) || payload.surface === void 0) return DEFAULT_SURFACE;
|
|
816
|
+
return typeof payload.surface === "string" ? payload.surface : void 0;
|
|
817
|
+
};
|
|
818
|
+
const isStudioSessionToken = (token) => sessionTokenSurface(token) === STUDIO_SURFACE;
|
|
819
|
+
const latinLetter = /^[a-z]$/i;
|
|
820
|
+
const LAST_ASCII_CODE_POINT = 127;
|
|
821
|
+
const isCharacterOutsideAscii = (key) => {
|
|
822
|
+
const [first, ...rest] = key;
|
|
823
|
+
return first !== void 0 && rest.length === 0 && (first.codePointAt(0) ?? 0) > LAST_ASCII_CODE_POINT;
|
|
824
|
+
};
|
|
825
|
+
const physicalLetter = /^Key([A-Z])$/;
|
|
826
|
+
const chordLetter = (stroke) => {
|
|
827
|
+
if (latinLetter.test(stroke.key)) return stroke.key.toLowerCase();
|
|
828
|
+
if (stroke.code === void 0 || !isCharacterOutsideAscii(stroke.key)) return null;
|
|
829
|
+
return physicalLetter.exec(stroke.code)?.[1]?.toLowerCase() ?? null;
|
|
830
|
+
};
|
|
831
|
+
const editToolPrefixes = {
|
|
832
|
+
segment: "studio.itinerary.segment.",
|
|
833
|
+
waypoint: "studio.itinerary.waypoint.",
|
|
834
|
+
zone: "studio.zone."
|
|
835
|
+
};
|
|
836
|
+
const editToolVerbs = {
|
|
837
|
+
cancel: "editCancel",
|
|
838
|
+
commit: "editCommit",
|
|
839
|
+
redo: "editRedo",
|
|
840
|
+
undo: "editUndo"
|
|
841
|
+
};
|
|
842
|
+
const editToolName = (family, intent) => `${editToolPrefixes[family]}${editToolVerbs[intent]}`;
|
|
843
|
+
const editHijacksNativeShortcut = (stroke) => {
|
|
844
|
+
if (stroke.key === "Enter") return true;
|
|
845
|
+
const letter = chordLetter(stroke);
|
|
846
|
+
return stroke.meta && (letter === "z" || letter === "y" || letter === "s");
|
|
847
|
+
};
|
|
848
|
+
const editKeyIntent = (stroke, options = {}) => {
|
|
849
|
+
const { escapeCancels = true } = options;
|
|
850
|
+
const letter = chordLetter(stroke);
|
|
851
|
+
if (stroke.key === "Enter" || stroke.meta && letter === "s") return "commit";
|
|
852
|
+
if (escapeCancels && stroke.key === "Escape") return "cancel";
|
|
853
|
+
if (stroke.meta && letter === "z") return stroke.shift ? "redo" : "undo";
|
|
854
|
+
if (stroke.meta && letter === "y") return "redo";
|
|
855
|
+
return null;
|
|
856
|
+
};
|
|
857
|
+
const editShortcuts = (input) => {
|
|
858
|
+
const modifier = input.apple ? "command" : "control";
|
|
859
|
+
const shortcuts = [];
|
|
860
|
+
if (input.canUndo) shortcuts.push({
|
|
861
|
+
action: "undo",
|
|
862
|
+
keys: [modifier, "z"]
|
|
863
|
+
});
|
|
864
|
+
if (input.canRedo) shortcuts.push({
|
|
865
|
+
action: "redo",
|
|
866
|
+
keys: input.apple ? [
|
|
867
|
+
"shift",
|
|
868
|
+
"command",
|
|
869
|
+
"z"
|
|
870
|
+
] : ["control", "y"]
|
|
871
|
+
});
|
|
872
|
+
if (input.escape !== null) shortcuts.push({
|
|
873
|
+
action: input.escape,
|
|
874
|
+
keys: ["escape"]
|
|
875
|
+
});
|
|
876
|
+
if (input.canCommit) shortcuts.push({
|
|
877
|
+
action: "commit",
|
|
878
|
+
keys: ["enter"]
|
|
879
|
+
});
|
|
880
|
+
return shortcuts;
|
|
881
|
+
};
|
|
882
|
+
const zoneEditTooltipText = (texts, hasShape) => {
|
|
883
|
+
if (hasShape) return texts.reshape;
|
|
884
|
+
return texts.draw;
|
|
885
|
+
};
|
|
886
|
+
const segmentEditTooltipContent = (texts, viaCount, mode) => {
|
|
887
|
+
if (mode === "directions" && viaCount >= DIRECTIONS_VIA_MAX) return {
|
|
888
|
+
hint: null,
|
|
889
|
+
primary: texts.viaCapReached,
|
|
890
|
+
tone: "limit"
|
|
891
|
+
};
|
|
892
|
+
if (mode === "directions" && viaCount >= DIRECTIONS_VIA_COUNTER_THRESHOLD) return {
|
|
893
|
+
hint: null,
|
|
894
|
+
primary: texts.viaCapCounter(viaCount),
|
|
895
|
+
tone: "warning"
|
|
896
|
+
};
|
|
897
|
+
return {
|
|
898
|
+
hint: texts.finishHint,
|
|
899
|
+
primary: viaCount >= SEGMENT_MIN_VIAS ? texts.reshape : texts.addPoint,
|
|
900
|
+
tone: "info"
|
|
901
|
+
};
|
|
902
|
+
};
|
|
903
|
+
const waypointEditTooltipText = (texts, mode, hasDraft, poiUnderCursor) => {
|
|
904
|
+
if (mode === "point") return hasDraft ? texts.clickToMove : texts.clickToDrop;
|
|
905
|
+
return poiUnderCursor ? texts.clickToCapture : texts.clickAPoi;
|
|
906
|
+
};
|
|
907
|
+
const leadingWww = /^www\./;
|
|
908
|
+
const loopbackIpv4 = /^127(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}$/;
|
|
909
|
+
const ipv6Text = /^[0-9a-f:.]+$/;
|
|
910
|
+
const loopbackIpv6 = /^\[(?:::1|::ffff:7f[0-9a-f]{2}:[0-9a-f]{1,4})\]$/;
|
|
911
|
+
const isLoopbackHost = (host) => {
|
|
912
|
+
if (host === "localhost" || host.endsWith(".localhost") || loopbackIpv4.test(host)) return true;
|
|
913
|
+
if (!host.includes(":") || !ipv6Text.test(host)) return false;
|
|
914
|
+
try {
|
|
915
|
+
return loopbackIpv6.test(new URL(`http://[${host}]`).hostname);
|
|
916
|
+
} catch {
|
|
917
|
+
return false;
|
|
918
|
+
}
|
|
919
|
+
};
|
|
920
|
+
const isLoopbackDomain = (entry) => {
|
|
921
|
+
const text = entry.toLowerCase().replace(leadingWww, "");
|
|
922
|
+
if (text.startsWith("[")) {
|
|
923
|
+
const close = text.indexOf("]");
|
|
924
|
+
const rest = close === -1 ? "" : text.slice(close + 1);
|
|
925
|
+
return close !== -1 && (rest === "" || rest.startsWith(":")) && isLoopbackHost(text.slice(1, close));
|
|
926
|
+
}
|
|
927
|
+
const colons = text.split(":").length - 1;
|
|
928
|
+
return isLoopbackHost(colons === 1 ? text.slice(0, text.indexOf(":")) : text);
|
|
929
|
+
};
|
|
930
|
+
const EMBED_CONFIG_FIELDS = [
|
|
931
|
+
{
|
|
932
|
+
key: "preferredLanguage",
|
|
933
|
+
kind: "enum",
|
|
934
|
+
param: "preferred_language"
|
|
935
|
+
},
|
|
936
|
+
{
|
|
937
|
+
key: "preferredTheme",
|
|
938
|
+
kind: "enum",
|
|
939
|
+
param: "preferred_theme"
|
|
940
|
+
},
|
|
941
|
+
{
|
|
942
|
+
key: "preferredUnitLength",
|
|
943
|
+
kind: "enum",
|
|
944
|
+
param: "preferred_unit_length"
|
|
945
|
+
},
|
|
946
|
+
{
|
|
947
|
+
key: "preferredUnitPace",
|
|
948
|
+
kind: "enum",
|
|
949
|
+
param: "preferred_unit_pace"
|
|
950
|
+
},
|
|
951
|
+
{
|
|
952
|
+
key: "preferredUnitSlope",
|
|
953
|
+
kind: "enum",
|
|
954
|
+
param: "preferred_unit_slope"
|
|
955
|
+
},
|
|
956
|
+
{
|
|
957
|
+
key: "preferredUnitTemperature",
|
|
958
|
+
kind: "enum",
|
|
959
|
+
param: "preferred_unit_temperature"
|
|
960
|
+
},
|
|
961
|
+
{
|
|
962
|
+
key: "terrain",
|
|
963
|
+
kind: "string",
|
|
964
|
+
param: "terrain"
|
|
965
|
+
},
|
|
966
|
+
{
|
|
967
|
+
key: "terrainVariant",
|
|
968
|
+
kind: "enum",
|
|
969
|
+
param: "terrain_variant"
|
|
970
|
+
},
|
|
971
|
+
{
|
|
972
|
+
key: "segmentsColor",
|
|
973
|
+
kind: "string",
|
|
974
|
+
param: "segments_color"
|
|
975
|
+
},
|
|
976
|
+
{
|
|
977
|
+
key: "withNavigationControl",
|
|
978
|
+
kind: "boolean",
|
|
979
|
+
param: "with_navigation_control"
|
|
980
|
+
},
|
|
981
|
+
{
|
|
982
|
+
key: "withPreferencesControl",
|
|
983
|
+
kind: "boolean",
|
|
984
|
+
param: "with_preferences_control"
|
|
985
|
+
},
|
|
986
|
+
{
|
|
987
|
+
key: "withDownloadControl",
|
|
988
|
+
kind: "boolean",
|
|
989
|
+
param: "with_download_control"
|
|
990
|
+
},
|
|
991
|
+
{
|
|
992
|
+
key: "withDirectionsControl",
|
|
993
|
+
kind: "boolean",
|
|
994
|
+
param: "with_directions_control"
|
|
995
|
+
},
|
|
996
|
+
{
|
|
997
|
+
key: "withStreetviewControl",
|
|
998
|
+
kind: "boolean",
|
|
999
|
+
param: "with_streetview_control"
|
|
1000
|
+
},
|
|
1001
|
+
{
|
|
1002
|
+
key: "withProfileCharacteristics",
|
|
1003
|
+
kind: "boolean",
|
|
1004
|
+
param: "with_profile_characteristics"
|
|
1005
|
+
},
|
|
1006
|
+
{
|
|
1007
|
+
key: "withProfileElevation",
|
|
1008
|
+
kind: "boolean",
|
|
1009
|
+
param: "with_profile_elevation"
|
|
1010
|
+
},
|
|
1011
|
+
{
|
|
1012
|
+
key: "withProfilePaceControl",
|
|
1013
|
+
kind: "boolean",
|
|
1014
|
+
param: "with_profile_pace_control"
|
|
1015
|
+
},
|
|
1016
|
+
{
|
|
1017
|
+
key: "withProfileAnalysis",
|
|
1018
|
+
kind: "boolean",
|
|
1019
|
+
param: "with_profile_analysis"
|
|
1020
|
+
},
|
|
1021
|
+
{
|
|
1022
|
+
key: "withOverlaysControl",
|
|
1023
|
+
kind: "boolean",
|
|
1024
|
+
param: "with_overlays_control"
|
|
1025
|
+
},
|
|
1026
|
+
{
|
|
1027
|
+
key: "withTerrains",
|
|
1028
|
+
kind: "stringArray",
|
|
1029
|
+
param: "with_terrains"
|
|
1030
|
+
},
|
|
1031
|
+
{
|
|
1032
|
+
key: "withOverlays",
|
|
1033
|
+
kind: "stringArray",
|
|
1034
|
+
param: "with_overlays"
|
|
1035
|
+
},
|
|
1036
|
+
{
|
|
1037
|
+
key: "withAccessRestrictions",
|
|
1038
|
+
kind: "boolean",
|
|
1039
|
+
param: "with_access_restrictions"
|
|
1040
|
+
}
|
|
1041
|
+
];
|
|
1042
|
+
const emptyEmbedSearch = embedSearchSchema.parse({});
|
|
1043
|
+
const resolveEmbedDefaults = (defaultProps) => resolveEmbedConfig(emptyEmbedSearch, defaultProps);
|
|
1044
|
+
const arraysDifferByContents = (a, b) => {
|
|
1045
|
+
if (a.length !== b.length) return true;
|
|
1046
|
+
const sortedA = [...a].sort();
|
|
1047
|
+
const sortedB = [...b].sort();
|
|
1048
|
+
return sortedA.some((value, index) => value !== sortedB[index]);
|
|
1049
|
+
};
|
|
1050
|
+
const allowlistEntries = (param, value, fallback) => {
|
|
1051
|
+
if (allowlistUnrestricted(value)) return allowlistUnrestricted(fallback) ? [] : [[param, "*"]];
|
|
1052
|
+
return arraysDifferByContents(value, fallback) ? value.map((slug) => [param, slug]) : [];
|
|
1053
|
+
};
|
|
1054
|
+
const fieldEntries = (field, config, defaults) => {
|
|
1055
|
+
const value = config[field.key];
|
|
1056
|
+
const fallback = defaults[field.key];
|
|
1057
|
+
if (Array.isArray(value)) return allowlistEntries(field.param, value, Array.isArray(fallback) ? fallback : []);
|
|
1058
|
+
if (value === fallback) return [];
|
|
1059
|
+
return [[field.param, typeof value === "boolean" ? value ? "true" : "false" : value]];
|
|
1060
|
+
};
|
|
1061
|
+
const buildEmbedSearch = (input) => {
|
|
1062
|
+
const entries = [["publishable_key", input.publishableKey]];
|
|
1063
|
+
if (input.itineraryId) entries.push(["itinerary_id", input.itineraryId]);
|
|
1064
|
+
if (input.collectionId) entries.push(["collection_id", input.collectionId]);
|
|
1065
|
+
if (input.sessionToken) entries.push(["session_token", input.sessionToken]);
|
|
1066
|
+
for (const field of EMBED_CONFIG_FIELDS) entries.push(...fieldEntries(field, input.config, input.defaults));
|
|
1067
|
+
return entries;
|
|
1068
|
+
};
|
|
1069
|
+
const buildEmbedSrc = (origin, search, hash = "") => {
|
|
1070
|
+
const params = new URLSearchParams(search);
|
|
1071
|
+
return `${originBase(origin)}/studio/embed?${params.toString()}${hash}`;
|
|
1072
|
+
};
|
|
1073
|
+
const buildEmbedViewHash = (view) => {
|
|
1074
|
+
if (view.center === null || view.zoom === null) return "";
|
|
1075
|
+
const [lng, lat] = view.center;
|
|
1076
|
+
const bearing = Math.round(view.bearing ?? 0);
|
|
1077
|
+
const pitch = Math.round(view.pitch ?? 0);
|
|
1078
|
+
return `#view=${view.zoom.toFixed(2)}/${lat.toFixed(6)}/${lng.toFixed(6)}/${bearing}/${pitch}`;
|
|
1079
|
+
};
|
|
1080
|
+
const EMBED_IFRAME_RADIUS_PX = 8;
|
|
1081
|
+
const escapeHtmlAttribute = (value) => value.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
1082
|
+
const buildEmbedIframe = (input) => [
|
|
1083
|
+
"<iframe",
|
|
1084
|
+
` src="${escapeHtmlAttribute(input.src)}"`,
|
|
1085
|
+
` width="${escapeHtmlAttribute(input.width)}"`,
|
|
1086
|
+
` height="${escapeHtmlAttribute(input.height)}"`,
|
|
1087
|
+
` title="${escapeHtmlAttribute(input.title)}"`,
|
|
1088
|
+
` style="border:0;border-radius:8px"`,
|
|
1089
|
+
" loading=\"lazy\"",
|
|
1090
|
+
" referrerpolicy=\"strict-origin-when-cross-origin\"",
|
|
1091
|
+
"></iframe>"
|
|
1092
|
+
].join("\n");
|
|
1093
|
+
const EMBED_SESSION_ENDPOINT = "/api/mountaya-embed-session";
|
|
1094
|
+
const scriptString = (value) => JSON.stringify(value).replace(/</g, "\\u003c");
|
|
1095
|
+
const buildEmbedSessionScript = (input) => [
|
|
1096
|
+
"<script>",
|
|
1097
|
+
" // Answers each Mountaya embed's request for a session token from your endpoint, which",
|
|
1098
|
+
" // calls POST /v1/sessions with your secret key and answers its body, or the session in it.",
|
|
1099
|
+
" (function () {",
|
|
1100
|
+
` var origin = ${scriptString(originBase(input.appOrigin))};`,
|
|
1101
|
+
` var endpoint = ${scriptString(input.endpoint ?? "/api/mountaya-embed-session")};`,
|
|
1102
|
+
" if (window.mountayaEmbedSession) return;",
|
|
1103
|
+
" window.mountayaEmbedSession = true;",
|
|
1104
|
+
" window.addEventListener(\"message\", function (event) {",
|
|
1105
|
+
" if (event.origin !== origin || !event.data) return;",
|
|
1106
|
+
` if (event.data.type !== ${scriptString(REQUEST_SESSION_TOKEN_MESSAGE)}) return;`,
|
|
1107
|
+
" var frame = event.source;",
|
|
1108
|
+
" fetch(endpoint, { credentials: \"same-origin\" })",
|
|
1109
|
+
" .then(function (response) {",
|
|
1110
|
+
" if (!response.ok) throw new Error(\"Session endpoint answered \" + response.status);",
|
|
1111
|
+
" return response.json();",
|
|
1112
|
+
" })",
|
|
1113
|
+
" .then(function (body) {",
|
|
1114
|
+
" var session = body && body.data ? body.data : body;",
|
|
1115
|
+
" if (!session || typeof session.token !== \"string\") {",
|
|
1116
|
+
" throw new Error(\"Session endpoint answered no token\");",
|
|
1117
|
+
" }",
|
|
1118
|
+
" if (typeof session.user_id === \"string\") {",
|
|
1119
|
+
" throw new Error(\"Session endpoint answered a token naming a user: mint without user_id\");",
|
|
1120
|
+
" }",
|
|
1121
|
+
" frame.postMessage(",
|
|
1122
|
+
` { type: ${scriptString(SET_SESSION_TOKEN_MESSAGE)}, token: session.token, expiresAt: session.expires_at },`,
|
|
1123
|
+
" origin",
|
|
1124
|
+
" );",
|
|
1125
|
+
" })",
|
|
1126
|
+
" .catch(function (error) {",
|
|
1127
|
+
" console.error(error);",
|
|
1128
|
+
" });",
|
|
1129
|
+
" });",
|
|
1130
|
+
" })();",
|
|
1131
|
+
"<\/script>"
|
|
1132
|
+
].join("\n");
|
|
1133
|
+
const embedFallbackProps = {
|
|
1134
|
+
preferred_language: "en",
|
|
1135
|
+
preferred_theme: "light",
|
|
1136
|
+
preferred_unit_length: "metric",
|
|
1137
|
+
preferred_unit_pace: "per-time",
|
|
1138
|
+
preferred_unit_slope: "degrees",
|
|
1139
|
+
preferred_unit_temperature: "celsius",
|
|
1140
|
+
segments_color: "",
|
|
1141
|
+
terrain: DEFAULT_TERRAIN,
|
|
1142
|
+
terrain_variant: "light",
|
|
1143
|
+
with_access_restrictions: true,
|
|
1144
|
+
with_collection_itineraries: true,
|
|
1145
|
+
with_collection_zones: true,
|
|
1146
|
+
with_directions_control: false,
|
|
1147
|
+
with_download_control: false,
|
|
1148
|
+
with_navigation_control: true,
|
|
1149
|
+
with_overlays: [],
|
|
1150
|
+
with_overlays_control: false,
|
|
1151
|
+
with_preferences_control: true,
|
|
1152
|
+
with_profile_analysis: false,
|
|
1153
|
+
with_profile_characteristics: true,
|
|
1154
|
+
with_profile_elevation: true,
|
|
1155
|
+
with_profile_pace_control: true,
|
|
1156
|
+
with_streetview_control: false,
|
|
1157
|
+
with_terrains: []
|
|
1158
|
+
};
|
|
1159
|
+
const normalizeDefaultProps = (props) => {
|
|
1160
|
+
if (!props) return embedFallbackProps;
|
|
1161
|
+
const language = languageSchema.safeParse(props.preferred_language);
|
|
1162
|
+
const theme = themeSchema.safeParse(props.preferred_theme);
|
|
1163
|
+
const unitLength = unitLengthSchema.safeParse(props.preferred_unit_length);
|
|
1164
|
+
const unitPace = unitPaceSchema.safeParse(props.preferred_unit_pace);
|
|
1165
|
+
const unitSlope = unitSlopeSchema.safeParse(props.preferred_unit_slope);
|
|
1166
|
+
const unitTemperature = unitTemperatureSchema.safeParse(props.preferred_unit_temperature);
|
|
1167
|
+
const terrainVariant = terrainVariantSchema.safeParse(props.terrain_variant);
|
|
1168
|
+
return {
|
|
1169
|
+
preferred_language: language.success ? language.data : embedFallbackProps.preferred_language,
|
|
1170
|
+
preferred_theme: theme.success ? theme.data : embedFallbackProps.preferred_theme,
|
|
1171
|
+
preferred_unit_length: unitLength.success ? unitLength.data : embedFallbackProps.preferred_unit_length,
|
|
1172
|
+
preferred_unit_pace: unitPace.success ? unitPace.data : embedFallbackProps.preferred_unit_pace,
|
|
1173
|
+
preferred_unit_slope: unitSlope.success ? unitSlope.data : embedFallbackProps.preferred_unit_slope,
|
|
1174
|
+
preferred_unit_temperature: unitTemperature.success ? unitTemperature.data : embedFallbackProps.preferred_unit_temperature,
|
|
1175
|
+
segments_color: props.segments_color ?? embedFallbackProps.segments_color,
|
|
1176
|
+
terrain: props.terrain || embedFallbackProps.terrain,
|
|
1177
|
+
terrain_variant: terrainVariant.success ? terrainVariant.data : embedFallbackProps.terrain_variant,
|
|
1178
|
+
with_access_restrictions: props.with_access_restrictions,
|
|
1179
|
+
with_collection_itineraries: props.with_collection_itineraries,
|
|
1180
|
+
with_collection_zones: props.with_collection_zones,
|
|
1181
|
+
with_directions_control: props.with_directions_control,
|
|
1182
|
+
with_download_control: props.with_download_control,
|
|
1183
|
+
with_navigation_control: props.with_navigation_control,
|
|
1184
|
+
with_overlays: props.with_overlays,
|
|
1185
|
+
with_overlays_control: props.with_overlays_control,
|
|
1186
|
+
with_preferences_control: props.with_preferences_control,
|
|
1187
|
+
with_profile_analysis: props.with_profile_analysis,
|
|
1188
|
+
with_profile_characteristics: props.with_profile_characteristics,
|
|
1189
|
+
with_profile_elevation: props.with_profile_elevation,
|
|
1190
|
+
with_profile_pace_control: props.with_profile_pace_control,
|
|
1191
|
+
with_streetview_control: props.with_streetview_control,
|
|
1192
|
+
with_terrains: props.with_terrains
|
|
1193
|
+
};
|
|
1194
|
+
};
|
|
1195
|
+
const resolveOrgEmbedDefaults = (props) => resolveEmbedDefaults(normalizeDefaultProps(props));
|
|
1196
|
+
const displaySeedDispatches = (previous, next) => {
|
|
1197
|
+
const dispatches = [];
|
|
1198
|
+
if (previous === null || previous.terrain !== next.terrain || previous.terrainVariant !== next.terrainVariant) dispatches.push({
|
|
1199
|
+
input: {
|
|
1200
|
+
terrain: next.terrain,
|
|
1201
|
+
variant: next.terrainVariant
|
|
1202
|
+
},
|
|
1203
|
+
name: "studio.terrain.set"
|
|
1204
|
+
});
|
|
1205
|
+
if (previous === null || previous.overlay !== next.overlay) dispatches.push({
|
|
1206
|
+
input: { overlay: next.overlay },
|
|
1207
|
+
name: "studio.overlay.set"
|
|
1208
|
+
});
|
|
1209
|
+
const previousEnrichments = previous?.enrichments ?? [];
|
|
1210
|
+
for (const slug of next.enrichments) if (!previousEnrichments.includes(slug)) dispatches.push({
|
|
1211
|
+
input: {
|
|
1212
|
+
enabled: true,
|
|
1213
|
+
overlay: slug
|
|
1214
|
+
},
|
|
1215
|
+
name: "studio.overlay.enrichment.set"
|
|
1216
|
+
});
|
|
1217
|
+
for (const slug of previousEnrichments) if (!next.enrichments.includes(slug)) dispatches.push({
|
|
1218
|
+
input: {
|
|
1219
|
+
enabled: false,
|
|
1220
|
+
overlay: slug
|
|
1221
|
+
},
|
|
1222
|
+
name: "studio.overlay.enrichment.set"
|
|
1223
|
+
});
|
|
1224
|
+
return dispatches;
|
|
1225
|
+
};
|
|
1226
|
+
const capPermits = (cap, slug) => {
|
|
1227
|
+
if (cap === void 0) return true;
|
|
1228
|
+
const mode = allowlistMode(cap, "cap");
|
|
1229
|
+
return mode === "all" || mode === "specific" && cap.includes(slug);
|
|
1230
|
+
};
|
|
1231
|
+
const clampConfigToAllowlists = (config, cap) => {
|
|
1232
|
+
const displayUnrestricted = allowlistUnrestricted(config.withOverlays);
|
|
1233
|
+
const permits = (slug) => capPermits(cap, slug) && (displayUnrestricted || config.withOverlays.includes(slug));
|
|
1234
|
+
let next = config;
|
|
1235
|
+
if (next.overlay !== null && !permits(next.overlay)) next = {
|
|
1236
|
+
...next,
|
|
1237
|
+
overlay: null
|
|
1238
|
+
};
|
|
1239
|
+
if (next.enrichments.length > 0) {
|
|
1240
|
+
const allowedEnrichments = next.enrichments.filter(permits);
|
|
1241
|
+
if (allowedEnrichments.length !== next.enrichments.length) next = {
|
|
1242
|
+
...next,
|
|
1243
|
+
enrichments: allowedEnrichments
|
|
1244
|
+
};
|
|
1245
|
+
}
|
|
1246
|
+
if ((cap === void 0 ? "all" : allowlistMode(cap, "cap")) !== "all") {
|
|
1247
|
+
const offered = displayUnrestricted ? cap ?? [] : config.withOverlays.filter((slug) => capPermits(cap, slug));
|
|
1248
|
+
if (offered.length > 0 && (displayUnrestricted || offered.length !== config.withOverlays.length)) next = {
|
|
1249
|
+
...next,
|
|
1250
|
+
withOverlays: [...offered]
|
|
1251
|
+
};
|
|
1252
|
+
}
|
|
1253
|
+
if (!allowlistUnrestricted(next.withTerrains) && !next.withTerrains.includes(next.terrain)) {
|
|
1254
|
+
const fallbackTerrain = next.withTerrains[0];
|
|
1255
|
+
if (fallbackTerrain !== void 0) next = {
|
|
1256
|
+
...next,
|
|
1257
|
+
terrain: fallbackTerrain
|
|
1258
|
+
};
|
|
1259
|
+
}
|
|
1260
|
+
return next;
|
|
1261
|
+
};
|
|
1262
|
+
const overlaysOffered = (withOverlays, cap) => {
|
|
1263
|
+
const capMode = cap === void 0 ? "all" : allowlistMode(cap, "cap");
|
|
1264
|
+
if (capMode !== "specific") return capMode === "all";
|
|
1265
|
+
return allowlistUnrestricted(withOverlays) || withOverlays.some((slug) => capPermits(cap, slug));
|
|
1266
|
+
};
|
|
1267
|
+
const layersControlOffered = (config, cap) => overlaysOffered(config.withOverlays, cap) || !allowlistUnrestricted(config.withTerrains);
|
|
1268
|
+
const EMBED_SECTION_ORDER = [
|
|
1269
|
+
"appearance",
|
|
1270
|
+
"controls",
|
|
1271
|
+
"profile",
|
|
1272
|
+
"layers"
|
|
1273
|
+
];
|
|
1274
|
+
const embedSectionFieldKeys = {
|
|
1275
|
+
appearance: /* @__PURE__ */ new Set([
|
|
1276
|
+
"preferredLanguage",
|
|
1277
|
+
"preferredTheme",
|
|
1278
|
+
"preferredUnitLength",
|
|
1279
|
+
"preferredUnitPace",
|
|
1280
|
+
"preferredUnitSlope",
|
|
1281
|
+
"preferredUnitTemperature",
|
|
1282
|
+
"terrain",
|
|
1283
|
+
"terrainVariant",
|
|
1284
|
+
"segmentsColor"
|
|
1285
|
+
]),
|
|
1286
|
+
collection: /* @__PURE__ */ new Set(),
|
|
1287
|
+
controls: /* @__PURE__ */ new Set([
|
|
1288
|
+
"withNavigationControl",
|
|
1289
|
+
"withPreferencesControl",
|
|
1290
|
+
"withDownloadControl",
|
|
1291
|
+
"withDirectionsControl",
|
|
1292
|
+
"withStreetviewControl"
|
|
1293
|
+
]),
|
|
1294
|
+
layers: /* @__PURE__ */ new Set([
|
|
1295
|
+
"withOverlaysControl",
|
|
1296
|
+
"withTerrains",
|
|
1297
|
+
"withOverlays",
|
|
1298
|
+
"withAccessRestrictions"
|
|
1299
|
+
]),
|
|
1300
|
+
profile: /* @__PURE__ */ new Set([
|
|
1301
|
+
"withProfileCharacteristics",
|
|
1302
|
+
"withProfileElevation",
|
|
1303
|
+
"withProfilePaceControl",
|
|
1304
|
+
"withProfileAnalysis"
|
|
1305
|
+
])
|
|
1306
|
+
};
|
|
1307
|
+
const sectionFields = (section) => EMBED_CONFIG_FIELDS.filter((field) => embedSectionFieldKeys[section].has(field.key));
|
|
1308
|
+
const orgOnlySectionProps = { collection: ["with_collection_itineraries", "with_collection_zones"] };
|
|
1309
|
+
const sectionDefaultPropsFields = (section) => [...sectionFields(section).map((field) => field.param), ...orgOnlySectionProps[section] ?? []];
|
|
1310
|
+
const EMBED_ELEMENTS = [
|
|
1311
|
+
"map",
|
|
1312
|
+
"segment-table",
|
|
1313
|
+
"waypoint-table"
|
|
1314
|
+
];
|
|
1315
|
+
const isEmbedTableElement = (element) => element !== "map";
|
|
1316
|
+
const isPerEmbedSection = (section) => section !== "collection";
|
|
1317
|
+
const embedElementSections = (element, withGeneral) => {
|
|
1318
|
+
const own = isEmbedTableElement(element) ? ["columns", "appearance"] : ["defaultView", ...EMBED_SECTION_ORDER.filter(isPerEmbedSection)];
|
|
1319
|
+
return [
|
|
1320
|
+
...withGeneral ? ["general"] : [],
|
|
1321
|
+
...own,
|
|
1322
|
+
"code"
|
|
1323
|
+
];
|
|
1324
|
+
};
|
|
1325
|
+
const tableFieldKeys = /* @__PURE__ */ new Set(["preferredLanguage", "preferredUnitLength"]);
|
|
1326
|
+
const embedElementSupportsField = (element, key) => !isEmbedTableElement(element) || tableFieldKeys.has(key);
|
|
1327
|
+
const embedElementSectionFields = (element, section) => sectionFields(section).filter((field) => embedElementSupportsField(element, field.key));
|
|
1328
|
+
const embedSectionChanges = (element, section, config, defaults) => embedElementSectionFields(element, section).filter((field) => {
|
|
1329
|
+
const value = config[field.key];
|
|
1330
|
+
const fallback = defaults[field.key];
|
|
1331
|
+
return Array.isArray(value) && Array.isArray(fallback) ? arraysDifferByContents(value, fallback) : value !== fallback;
|
|
1332
|
+
}).length;
|
|
1333
|
+
const EMBED_SEGMENT_TABLE_COLUMNS = [
|
|
1334
|
+
"segment",
|
|
1335
|
+
"profile",
|
|
1336
|
+
"distance",
|
|
1337
|
+
"elevation",
|
|
1338
|
+
"altitude",
|
|
1339
|
+
"duration",
|
|
1340
|
+
"difficulty"
|
|
1341
|
+
];
|
|
1342
|
+
const EMBED_WAYPOINT_TABLE_COLUMNS = [
|
|
1343
|
+
"waypoint",
|
|
1344
|
+
"profile",
|
|
1345
|
+
"distance",
|
|
1346
|
+
"elevation",
|
|
1347
|
+
"altitude",
|
|
1348
|
+
"amenities",
|
|
1349
|
+
"cutoff",
|
|
1350
|
+
"properties"
|
|
1351
|
+
];
|
|
1352
|
+
const defaultEmbedTableOptions = {
|
|
1353
|
+
segmentColumns: DEFAULT_SEGMENT_TABLE_COLUMNS,
|
|
1354
|
+
serviceFilter: false,
|
|
1355
|
+
waypointColumns: DEFAULT_WAYPOINT_TABLE_COLUMNS
|
|
1356
|
+
};
|
|
1357
|
+
const toggleEmbedTableColumn = (all, columns, column, shown) => all.filter((candidate, index) => candidate === column ? shown || index === 0 : columns.includes(candidate));
|
|
1358
|
+
const embedTableColumns = (element, options) => element === "segment-table" ? options.segmentColumns : options.waypointColumns;
|
|
1359
|
+
const embedTableChanges = (element, options) => {
|
|
1360
|
+
const columns = embedTableColumns(element, options);
|
|
1361
|
+
const defaults = element === "segment-table" ? DEFAULT_SEGMENT_TABLE_COLUMNS : DEFAULT_WAYPOINT_TABLE_COLUMNS;
|
|
1362
|
+
return columns.filter((column) => !defaults.includes(column)).length + defaults.filter((column) => !columns.includes(column)).length + (element === "waypoint-table" && options.serviceFilter ? 1 : 0);
|
|
1363
|
+
};
|
|
1364
|
+
const embedFieldDependencies = {
|
|
1365
|
+
withProfileAnalysis: ["withProfileElevation"],
|
|
1366
|
+
withProfilePaceControl: ["withProfileElevation", "withProfileCharacteristics"]
|
|
1367
|
+
};
|
|
1368
|
+
const isDependentFieldKey = (key) => Object.hasOwn(embedFieldDependencies, key);
|
|
1369
|
+
const fieldDependenciesUnmet = (key, config) => {
|
|
1370
|
+
if (!isDependentFieldKey(key)) return [];
|
|
1371
|
+
return embedFieldDependencies[key].filter((field) => config[field] === false);
|
|
1372
|
+
};
|
|
1373
|
+
const clampConfigToFieldDependencies = (config) => {
|
|
1374
|
+
let next = config;
|
|
1375
|
+
for (const key of Object.keys(embedFieldDependencies).filter(isDependentFieldKey)) if (next[key] && fieldDependenciesUnmet(key, next).length > 0) next = {
|
|
1376
|
+
...next,
|
|
1377
|
+
[key]: false
|
|
1378
|
+
};
|
|
1379
|
+
return next;
|
|
1380
|
+
};
|
|
1381
|
+
const clampEmbedConfigToSecurity = (config, safetyRules) => clampConfigToFieldDependencies(clampConfigToAllowlists(clampConfigToSafetyRules(config, safetyRules), safetyRules?.with_overlays));
|
|
1382
|
+
const applyEmbedOverrides = (config, content) => {
|
|
1383
|
+
const { itineraryId, overrides } = content;
|
|
1384
|
+
const next = {
|
|
1385
|
+
...config,
|
|
1386
|
+
itineraryId
|
|
1387
|
+
};
|
|
1388
|
+
if (overrides.terrain !== void 0) next.terrain = overrides.terrain;
|
|
1389
|
+
if (Array.isArray(overrides.withOverlays)) next.withOverlays = overrides.withOverlays;
|
|
1390
|
+
if (Array.isArray(overrides.withTerrains)) next.withTerrains = overrides.withTerrains;
|
|
1391
|
+
if (overrides.withAccessRestrictions !== void 0) next.withAccessRestrictions = overrides.withAccessRestrictions;
|
|
1392
|
+
if (overrides.withDirectionsControl !== void 0) next.withDirectionsControl = overrides.withDirectionsControl;
|
|
1393
|
+
if (overrides.withDownloadControl !== void 0) next.withDownloadControl = overrides.withDownloadControl;
|
|
1394
|
+
if (overrides.withNavigationControl !== void 0) next.withNavigationControl = overrides.withNavigationControl;
|
|
1395
|
+
if (overrides.withOverlaysControl !== void 0) next.withOverlaysControl = overrides.withOverlaysControl;
|
|
1396
|
+
if (overrides.withPreferencesControl !== void 0) next.withPreferencesControl = overrides.withPreferencesControl;
|
|
1397
|
+
if (overrides.withProfileAnalysis !== void 0) next.withProfileAnalysis = overrides.withProfileAnalysis;
|
|
1398
|
+
if (overrides.withProfileCharacteristics !== void 0) next.withProfileCharacteristics = overrides.withProfileCharacteristics;
|
|
1399
|
+
if (overrides.withProfileElevation !== void 0) next.withProfileElevation = overrides.withProfileElevation;
|
|
1400
|
+
if (overrides.withProfilePaceControl !== void 0) next.withProfilePaceControl = overrides.withProfilePaceControl;
|
|
1401
|
+
if (overrides.withStreetviewControl !== void 0) next.withStreetviewControl = overrides.withStreetviewControl;
|
|
1402
|
+
return next;
|
|
1403
|
+
};
|
|
1404
|
+
const languageOptions = () => MAP_LANGUAGES.map((value) => ({
|
|
1405
|
+
label: languageEndonym[value],
|
|
1406
|
+
value
|
|
1407
|
+
}));
|
|
1408
|
+
const themeOptions = (words) => [{
|
|
1409
|
+
label: words.embed.options.theme.light,
|
|
1410
|
+
value: "light"
|
|
1411
|
+
}, {
|
|
1412
|
+
label: words.embed.options.theme.dark,
|
|
1413
|
+
value: "dark"
|
|
1414
|
+
}];
|
|
1415
|
+
const unitLengthOptions = (words) => [{
|
|
1416
|
+
label: words.preferences.units.metric.name,
|
|
1417
|
+
value: "metric"
|
|
1418
|
+
}, {
|
|
1419
|
+
label: words.preferences.units.imperial.name,
|
|
1420
|
+
value: "imperial"
|
|
1421
|
+
}];
|
|
1422
|
+
const unitPaceOptions = (words) => [{
|
|
1423
|
+
label: words.preferences.units.perTime.name,
|
|
1424
|
+
value: "per-time"
|
|
1425
|
+
}, {
|
|
1426
|
+
label: words.preferences.units.perDistance.name,
|
|
1427
|
+
value: "per-distance"
|
|
1428
|
+
}];
|
|
1429
|
+
const unitSlopeOptions = (words) => [{
|
|
1430
|
+
label: words.preferences.units.degrees.name,
|
|
1431
|
+
value: "degrees"
|
|
1432
|
+
}, {
|
|
1433
|
+
label: words.preferences.units.percentage.name,
|
|
1434
|
+
value: "percentage"
|
|
1435
|
+
}];
|
|
1436
|
+
const unitTemperatureOptions = (words) => [{
|
|
1437
|
+
label: words.preferences.units.celsius.name,
|
|
1438
|
+
value: "celsius"
|
|
1439
|
+
}, {
|
|
1440
|
+
label: words.preferences.units.fahrenheit.name,
|
|
1441
|
+
value: "fahrenheit"
|
|
1442
|
+
}];
|
|
1443
|
+
const terrainVariantOptions = (words) => [{
|
|
1444
|
+
label: words.embed.options.terrainVariant.light,
|
|
1445
|
+
value: "light"
|
|
1446
|
+
}, {
|
|
1447
|
+
label: words.embed.options.terrainVariant.dark,
|
|
1448
|
+
value: "dark"
|
|
1449
|
+
}];
|
|
1450
|
+
const enumFieldOptions = (key, words) => {
|
|
1451
|
+
switch (key) {
|
|
1452
|
+
case "preferredLanguage": return languageOptions();
|
|
1453
|
+
case "preferredTheme": return themeOptions(words);
|
|
1454
|
+
case "preferredUnitLength": return unitLengthOptions(words);
|
|
1455
|
+
case "preferredUnitPace": return unitPaceOptions(words);
|
|
1456
|
+
case "preferredUnitSlope": return unitSlopeOptions(words);
|
|
1457
|
+
case "preferredUnitTemperature": return unitTemperatureOptions(words);
|
|
1458
|
+
case "terrainVariant": return terrainVariantOptions(words);
|
|
1459
|
+
default: return [];
|
|
1460
|
+
}
|
|
1461
|
+
};
|
|
1462
|
+
const isLayerSlug = (slug) => slug.length > 0 && slug !== "*";
|
|
1463
|
+
const missingOptions = (selected, known) => [...new Set(selected)].filter((slug) => isLayerSlug(slug) && !known.has(slug)).map((slug) => ({
|
|
1464
|
+
label: slug,
|
|
1465
|
+
value: slug
|
|
1466
|
+
}));
|
|
1467
|
+
const withSelectedTerrains = (terrains, selected) => {
|
|
1468
|
+
const extra = missingOptions(selected, new Set(terrains.map((option) => option.value)));
|
|
1469
|
+
return extra.length === 0 ? terrains : [...terrains, ...extra];
|
|
1470
|
+
};
|
|
1471
|
+
const cappedOverlayGroups = (groups, allowed) => {
|
|
1472
|
+
if (allowed === void 0 || allowed.includes("*")) return groups;
|
|
1473
|
+
const permitted = new Set(allowed);
|
|
1474
|
+
return groups.map((group) => ({
|
|
1475
|
+
group: group.group,
|
|
1476
|
+
items: group.items.filter((item) => permitted.has(item.value))
|
|
1477
|
+
})).filter((group) => group.items.length > 0);
|
|
1478
|
+
};
|
|
1479
|
+
const withSelectedOverlays = (groups, selected, otherLabel) => {
|
|
1480
|
+
const extra = missingOptions(selected, new Set(groups.flatMap((group) => group.items.map((item) => item.value))));
|
|
1481
|
+
return extra.length === 0 ? groups : [...groups, {
|
|
1482
|
+
group: otherLabel,
|
|
1483
|
+
items: extra
|
|
1484
|
+
}];
|
|
1485
|
+
};
|
|
1486
|
+
const embedLayerOptions = (catalog, config, allowedOverlays, otherLabel) => ({
|
|
1487
|
+
overlayGroups: withSelectedOverlays(cappedOverlayGroups(catalog.overlayGroups, allowedOverlays), config.withOverlays, otherLabel),
|
|
1488
|
+
terrains: withSelectedTerrains(catalog.terrains, [config.terrain, ...config.withTerrains])
|
|
1489
|
+
});
|
|
1490
|
+
const EMBED_TABLE_INSTALL_COMMAND = "npm install @mountaya/elements-react @mountaya/elements @mountaya/client";
|
|
1491
|
+
const tableComponents = {
|
|
1492
|
+
"segment-table": {
|
|
1493
|
+
element: "ItinerarySegmentTable",
|
|
1494
|
+
wrapper: "SegmentTable"
|
|
1495
|
+
},
|
|
1496
|
+
"waypoint-table": {
|
|
1497
|
+
element: "ItineraryWaypointTable",
|
|
1498
|
+
wrapper: "WaypointTable"
|
|
1499
|
+
}
|
|
1500
|
+
};
|
|
1501
|
+
const defaultColumns = {
|
|
1502
|
+
"segment-table": DEFAULT_SEGMENT_TABLE_COLUMNS,
|
|
1503
|
+
"waypoint-table": DEFAULT_WAYPOINT_TABLE_COLUMNS
|
|
1504
|
+
};
|
|
1505
|
+
const instantColumns = /* @__PURE__ */ new Set(["cutoff", "properties"]);
|
|
1506
|
+
const codeString = (value) => JSON.stringify(value).replace(/</g, "\\u003c");
|
|
1507
|
+
const plainAttribute = /^[\w-]*$/;
|
|
1508
|
+
const attribute = (name, value) => plainAttribute.test(value) ? `${name}="${value}"` : `${name}={${codeString(value)}}`;
|
|
1509
|
+
const sameOrder = (a, b) => a.length === b.length && a.every((value, index) => value === b[index]);
|
|
1510
|
+
const sessionLines = (endpoint) => [
|
|
1511
|
+
"// Your organization requires a session token. This asks your own endpoint for one, which",
|
|
1512
|
+
"// calls POST /v1/sessions with your secret key and answers its body, or the session in it.",
|
|
1513
|
+
"const session = new SessionTokenEngine({",
|
|
1514
|
+
" mint: async () => {",
|
|
1515
|
+
` const response = await fetch(${codeString(endpoint)}, { credentials: "same-origin" });`,
|
|
1516
|
+
" if (!response.ok) {",
|
|
1517
|
+
" throw new Error(\"Session endpoint answered \" + response.status);",
|
|
1518
|
+
" }",
|
|
1519
|
+
" const body = await response.json();",
|
|
1520
|
+
"",
|
|
1521
|
+
" return body.data ?? body;",
|
|
1522
|
+
" },",
|
|
1523
|
+
"});",
|
|
1524
|
+
"// The engine mints again before each token expires, for as long as something subscribes.",
|
|
1525
|
+
"session.subscribe(() => undefined);",
|
|
1526
|
+
""
|
|
1527
|
+
];
|
|
1528
|
+
const buildEmbedTableCode = (input) => {
|
|
1529
|
+
const { element, wrapper } = tableComponents[input.element];
|
|
1530
|
+
const requireSessionToken = input.requireSessionToken === true;
|
|
1531
|
+
const filtered = input.element === "waypoint-table" && input.serviceFilter === true;
|
|
1532
|
+
const statesColumns = !sameOrder(input.columns, defaultColumns[input.element]);
|
|
1533
|
+
const formatsInstants = input.element === "waypoint-table" && input.columns.some((column) => instantColumns.has(column));
|
|
1534
|
+
const french = input.language === "fr";
|
|
1535
|
+
const imperial = input.length === "imperial";
|
|
1536
|
+
const imports = [
|
|
1537
|
+
...filtered ? ["import { useState } from \"react\";", ""] : [],
|
|
1538
|
+
`import { Mountaya${requireSessionToken ? ", SessionTokenEngine" : ""} } from "@mountaya/client/browser";`,
|
|
1539
|
+
...formatsInstants ? ["import { formatDate } from \"@mountaya/elements/i18n\";"] : [],
|
|
1540
|
+
...french ? ["import { frElementsStrings } from \"@mountaya/elements/i18n/fr\";"] : [],
|
|
1541
|
+
...imperial ? ["import { defaultUnits, type UnitFormatOptions } from \"@mountaya/elements/profile\";"] : [],
|
|
1542
|
+
`import { ${element} } from "@mountaya/elements-react/elements";`,
|
|
1543
|
+
"import { MountayaElementsProvider } from \"@mountaya/elements-react/headless\";"
|
|
1544
|
+
];
|
|
1545
|
+
const credential = requireSessionToken ? `{ publishableKey: ${codeString(input.publishableKey)}, sessionToken: session }` : `{ publishableKey: ${codeString(input.publishableKey)} }`;
|
|
1546
|
+
const units = imperial ? [`const units: UnitFormatOptions = { ...defaultUnits, ${input.language === "en" ? "" : `language: ${codeString(input.language)}, `}length: "imperial" };`, ""] : [];
|
|
1547
|
+
const formatter = formatsInstants ? [
|
|
1548
|
+
"// A cut-off is written in the visitor's own time zone, as the elements write their own",
|
|
1549
|
+
"// dates: state `timeZone` to write it in your event's instead.",
|
|
1550
|
+
"const formatCutoffAt = (instant: Date): string =>",
|
|
1551
|
+
` formatDate(${codeString(input.language)}, instant, { dateStyle: "medium", timeStyle: "short" }) ?? "";`,
|
|
1552
|
+
""
|
|
1553
|
+
] : [];
|
|
1554
|
+
const provider = french ? [
|
|
1555
|
+
"<MountayaElementsProvider",
|
|
1556
|
+
" client={client}",
|
|
1557
|
+
" language=\"fr\"",
|
|
1558
|
+
" translations={{ fr: frElementsStrings }}",
|
|
1559
|
+
">"
|
|
1560
|
+
] : input.language === "en" ? ["<MountayaElementsProvider client={client}>"] : [`<MountayaElementsProvider client={client} ${attribute("language", input.language)}>`];
|
|
1561
|
+
const props = [
|
|
1562
|
+
...statesColumns ? [`columns={[${input.columns.map(codeString).join(", ")}]}`] : [],
|
|
1563
|
+
...filtered ? ["filter={filter}"] : [],
|
|
1564
|
+
...formatsInstants ? ["formatCutoffAt={formatCutoffAt}"] : [],
|
|
1565
|
+
attribute("itineraryId", input.itineraryId),
|
|
1566
|
+
...filtered ? ["onFilterChange={setFilter}"] : [],
|
|
1567
|
+
"surface=\"published\"",
|
|
1568
|
+
...imperial ? ["units={units}"] : []
|
|
1569
|
+
];
|
|
1570
|
+
const tree = [
|
|
1571
|
+
...provider,
|
|
1572
|
+
...props.length <= 2 ? [` <${element} ${props.join(" ")} />`] : [
|
|
1573
|
+
` <${element}`,
|
|
1574
|
+
...props.map((prop) => ` ${prop}`),
|
|
1575
|
+
" />"
|
|
1576
|
+
],
|
|
1577
|
+
"</MountayaElementsProvider>"
|
|
1578
|
+
];
|
|
1579
|
+
const component = filtered ? [
|
|
1580
|
+
`export const ${wrapper} = () => {`,
|
|
1581
|
+
" // Controlled, so the chosen services can live in a URL. Several at once keep the",
|
|
1582
|
+
" // waypoints that offer all of them.",
|
|
1583
|
+
" const [filter, setFilter] = useState<readonly string[]>([]);",
|
|
1584
|
+
"",
|
|
1585
|
+
" return (",
|
|
1586
|
+
...tree.map((line) => ` ${line}`),
|
|
1587
|
+
" );",
|
|
1588
|
+
"};"
|
|
1589
|
+
] : [
|
|
1590
|
+
`export const ${wrapper} = () => (`,
|
|
1591
|
+
...tree.map((line) => ` ${line}`),
|
|
1592
|
+
");"
|
|
1593
|
+
];
|
|
1594
|
+
return [
|
|
1595
|
+
"import \"@mountaya/elements-react/styles.css\";",
|
|
1596
|
+
"",
|
|
1597
|
+
...imports,
|
|
1598
|
+
"",
|
|
1599
|
+
...requireSessionToken ? sessionLines(input.sessionEndpoint ?? "/api/mountaya-embed-session") : [],
|
|
1600
|
+
"const client = new Mountaya({",
|
|
1601
|
+
` credential: ${credential},`,
|
|
1602
|
+
"});",
|
|
1603
|
+
"",
|
|
1604
|
+
...units,
|
|
1605
|
+
...formatter,
|
|
1606
|
+
...component
|
|
1607
|
+
].join("\n");
|
|
1608
|
+
};
|
|
1609
|
+
const itineraryCeiling = (limit, count) => {
|
|
1610
|
+
if (limit === null || !Number.isFinite(limit) || limit < 0) return {
|
|
1611
|
+
full: false,
|
|
1612
|
+
limit: null
|
|
1613
|
+
};
|
|
1614
|
+
return {
|
|
1615
|
+
full: count >= limit,
|
|
1616
|
+
limit
|
|
1617
|
+
};
|
|
1618
|
+
};
|
|
1619
|
+
const firstSegmentEditInput = (activity, segmentId, random) => ({
|
|
1620
|
+
activitySlug: activity?.slug ?? void 0,
|
|
1621
|
+
color: pickLivelyColor(null, void 0, random),
|
|
1622
|
+
mode: defaultEngineForActivity(activity?.capabilities),
|
|
1623
|
+
name: defaultSegmentName(0),
|
|
1624
|
+
segmentId
|
|
1625
|
+
});
|
|
1626
|
+
const createFormChanged = (state) => state.name.trim() !== state.seededName.trim() || state.activityId !== null && state.activityId !== state.defaultActivityId || state.organizationId !== null && state.organizationId !== state.defaultOrganizationId || state.collectionIds.length > 0;
|
|
1627
|
+
const persistedItineraryView = (itinerary) => ({
|
|
1628
|
+
mode: "persisted",
|
|
1629
|
+
source: {
|
|
1630
|
+
activity_id: itinerary.activity_id,
|
|
1631
|
+
id: itinerary.id,
|
|
1632
|
+
segments: itinerary.segments,
|
|
1633
|
+
waypoints: itinerary.waypoints
|
|
1634
|
+
}
|
|
1635
|
+
});
|
|
1636
|
+
const emptyEditorView = Object.freeze({
|
|
1637
|
+
mode: "persisted",
|
|
1638
|
+
source: Object.freeze({
|
|
1639
|
+
activity_id: null,
|
|
1640
|
+
id: null,
|
|
1641
|
+
segments: [],
|
|
1642
|
+
waypoints: []
|
|
1643
|
+
})
|
|
1644
|
+
});
|
|
1645
|
+
const editorItineraryView = (sources) => {
|
|
1646
|
+
const { draft, itinerary, selectedCandidate, suggestSurfaceShows } = sources;
|
|
1647
|
+
if (draft !== null) return {
|
|
1648
|
+
mode: "preview",
|
|
1649
|
+
source: draftToView(draft)
|
|
1650
|
+
};
|
|
1651
|
+
if (selectedCandidate !== null && suggestSurfaceShows) return {
|
|
1652
|
+
mode: "preview",
|
|
1653
|
+
source: suggestionCandidateToView(selectedCandidate)
|
|
1654
|
+
};
|
|
1655
|
+
return itinerary === null ? emptyEditorView : persistedItineraryView(itinerary);
|
|
1656
|
+
};
|
|
1657
|
+
const pick = (items, random) => {
|
|
1658
|
+
const index = Math.floor(random() * items.length);
|
|
1659
|
+
return items[Number.isFinite(index) ? Math.min(Math.max(index, 0), items.length - 1) : 0] ?? "";
|
|
1660
|
+
};
|
|
1661
|
+
const generateFriendlyName = (copy, random) => {
|
|
1662
|
+
const adjective = pick(copy.nameAdjectives, random);
|
|
1663
|
+
const noun = pick(copy.nameNouns, random);
|
|
1664
|
+
if (adjective === "" || noun === "") return `${adjective}${noun}`;
|
|
1665
|
+
return copy.friendlyName(adjective, noun);
|
|
1666
|
+
};
|
|
1667
|
+
const IMPORT_FILE_MAX_SIZE = convertDataSize(20, "megabyte", "byte");
|
|
1668
|
+
const IMPORT_FILE_FORMATS = [
|
|
1669
|
+
{
|
|
1670
|
+
extension: ".gpx",
|
|
1671
|
+
mimeTypes: ["application/gpx+xml"],
|
|
1672
|
+
provider: "gpx"
|
|
1673
|
+
},
|
|
1674
|
+
{
|
|
1675
|
+
extension: ".geojson",
|
|
1676
|
+
mimeTypes: ["application/geo+json", "application/json"],
|
|
1677
|
+
provider: "geojson"
|
|
1678
|
+
},
|
|
1679
|
+
{
|
|
1680
|
+
extension: ".kml",
|
|
1681
|
+
mimeTypes: ["application/vnd.google-earth.kml+xml", "text/xml"],
|
|
1682
|
+
provider: "kml"
|
|
1683
|
+
},
|
|
1684
|
+
{
|
|
1685
|
+
extension: ".kmz",
|
|
1686
|
+
mimeTypes: [
|
|
1687
|
+
"application/vnd.google-earth.kmz",
|
|
1688
|
+
"application/zip",
|
|
1689
|
+
"application/x-zip-compressed"
|
|
1690
|
+
],
|
|
1691
|
+
provider: "kmz"
|
|
1692
|
+
},
|
|
1693
|
+
{
|
|
1694
|
+
extension: ".fit",
|
|
1695
|
+
mimeTypes: ["application/vnd.ant.fit", "application/octet-stream"],
|
|
1696
|
+
provider: "fit"
|
|
1697
|
+
},
|
|
1698
|
+
{
|
|
1699
|
+
extension: ".tcx",
|
|
1700
|
+
mimeTypes: ["application/vnd.garmin.tcx+xml", "application/xml"],
|
|
1701
|
+
provider: "tcx"
|
|
1702
|
+
}
|
|
1703
|
+
];
|
|
1704
|
+
IMPORT_FILE_FORMATS.map((format) => format.extension);
|
|
1705
|
+
const importDropzoneAccept = IMPORT_FILE_FORMATS.reduce((accept, format) => {
|
|
1706
|
+
for (const mimeType of format.mimeTypes) accept[mimeType] = [...accept[mimeType] ?? [], format.extension];
|
|
1707
|
+
return accept;
|
|
1708
|
+
}, {});
|
|
1709
|
+
const fileProviderByExtension = new Map(IMPORT_FILE_FORMATS.map((format) => [format.extension, format.provider]));
|
|
1710
|
+
const detectFileProvider = (fileName) => {
|
|
1711
|
+
const lowered = fileName.toLowerCase();
|
|
1712
|
+
for (const [extension, provider] of fileProviderByExtension) if (lowered.endsWith(extension)) return provider;
|
|
1713
|
+
return null;
|
|
1714
|
+
};
|
|
1715
|
+
const EMPTY_SEGMENTS = Object.freeze([]);
|
|
1716
|
+
const importSegmentCounts = (segments) => {
|
|
1717
|
+
let routable = 0;
|
|
1718
|
+
let snapped = 0;
|
|
1719
|
+
for (const segment of segments) {
|
|
1720
|
+
if (segment.directions === null) continue;
|
|
1721
|
+
routable += 1;
|
|
1722
|
+
if (segment.mode === "directions") snapped += 1;
|
|
1723
|
+
}
|
|
1724
|
+
return {
|
|
1725
|
+
exact: segments.length - snapped,
|
|
1726
|
+
routable,
|
|
1727
|
+
snapped,
|
|
1728
|
+
total: segments.length,
|
|
1729
|
+
unroutable: segments.length - routable
|
|
1730
|
+
};
|
|
1731
|
+
};
|
|
1732
|
+
const itinerarySpriteIcons = (itinerary) => {
|
|
1733
|
+
const [startIcon, endIcon] = ITINERARY_ENDPOINT_ICONS;
|
|
1734
|
+
const icons = [];
|
|
1735
|
+
for (const waypoint of itinerary.waypoints ?? []) if (waypoint.icon && waypoint.color) icons.push({
|
|
1736
|
+
color: waypoint.color,
|
|
1737
|
+
icon: waypoint.icon
|
|
1738
|
+
});
|
|
1739
|
+
for (const segment of itinerary.segments ?? []) if (segment.color) icons.push({
|
|
1740
|
+
color: segment.color,
|
|
1741
|
+
icon: startIcon
|
|
1742
|
+
}, {
|
|
1743
|
+
color: segment.color,
|
|
1744
|
+
icon: endIcon
|
|
1745
|
+
});
|
|
1746
|
+
return icons;
|
|
1747
|
+
};
|
|
1748
|
+
const itineraryEmphasisFor = (selection, itinerary) => {
|
|
1749
|
+
if (selection !== null) return {
|
|
1750
|
+
id: selection.id,
|
|
1751
|
+
mode: selection.kind
|
|
1752
|
+
};
|
|
1753
|
+
return itinerary === null ? { mode: "none" } : {
|
|
1754
|
+
id: itinerary.id,
|
|
1755
|
+
mode: "itinerary"
|
|
1756
|
+
};
|
|
1757
|
+
};
|
|
1758
|
+
const chosenAndOther = (segment) => {
|
|
1759
|
+
const chosen = chosenCandidate(segment);
|
|
1760
|
+
const other = chosen === segment.linestring ? segment.directions : segment.linestring;
|
|
1761
|
+
return {
|
|
1762
|
+
chosen: chosen.geojson,
|
|
1763
|
+
other: other?.geojson ?? null
|
|
1764
|
+
};
|
|
1765
|
+
};
|
|
1766
|
+
const [DRAFT_START_ICON, DRAFT_END_ICON] = ITINERARY_ENDPOINT_ICONS;
|
|
1767
|
+
const endpointMarkers = (draft, active) => chainEndpointMarkers(draft.segments.map((segment) => ({
|
|
1768
|
+
color: segment.color,
|
|
1769
|
+
geometry: chosenAndOther(segment).chosen,
|
|
1770
|
+
id: segment.id
|
|
1771
|
+
})), active);
|
|
1772
|
+
const chainEndpointMarkers = (chain, active) => {
|
|
1773
|
+
const first = chain[0];
|
|
1774
|
+
const last = chain[chain.length - 1];
|
|
1775
|
+
if (!first || !last) return [];
|
|
1776
|
+
const markers = [];
|
|
1777
|
+
if (first.id !== active.segmentId) {
|
|
1778
|
+
const head = lngLatOf(extractLines(first.geometry)[0]?.coordinates[0]);
|
|
1779
|
+
if (head) markers.push({
|
|
1780
|
+
color: first.color,
|
|
1781
|
+
icon: DRAFT_START_ICON,
|
|
1782
|
+
lngLat: head
|
|
1783
|
+
});
|
|
1784
|
+
}
|
|
1785
|
+
if (last.id !== active.segmentId) {
|
|
1786
|
+
const tail = lngLatOf(extractLines(last.geometry).at(-1)?.coordinates.at(-1));
|
|
1787
|
+
if (tail) markers.push({
|
|
1788
|
+
color: last.color,
|
|
1789
|
+
icon: DRAFT_END_ICON,
|
|
1790
|
+
lngLat: tail
|
|
1791
|
+
});
|
|
1792
|
+
}
|
|
1793
|
+
return markers;
|
|
1794
|
+
};
|
|
1795
|
+
const draftToPreviewRender = (glyphs, draft, active) => {
|
|
1796
|
+
const lines = [];
|
|
1797
|
+
for (const segment of draft.segments) {
|
|
1798
|
+
if (segment.id === active.segmentId) continue;
|
|
1799
|
+
const { chosen, other } = chosenAndOther(segment);
|
|
1800
|
+
for (const line of extractLines(chosen)) lines.push({
|
|
1801
|
+
color: segment.color,
|
|
1802
|
+
coordinates: line.coordinates,
|
|
1803
|
+
dashed: false
|
|
1804
|
+
});
|
|
1805
|
+
if (other) for (const line of extractLines(other)) lines.push({
|
|
1806
|
+
color: segment.color,
|
|
1807
|
+
coordinates: line.coordinates,
|
|
1808
|
+
dashed: true
|
|
1809
|
+
});
|
|
1810
|
+
}
|
|
1811
|
+
const waypoints = [];
|
|
1812
|
+
for (const waypoint of draft.waypoints) {
|
|
1813
|
+
if (waypoint.id === active.waypointId) continue;
|
|
1814
|
+
const lngLat = lngLatOf(extractPoint(waypoint.geojson)?.coordinates);
|
|
1815
|
+
if (!lngLat) continue;
|
|
1816
|
+
waypoints.push({
|
|
1817
|
+
color: DEFAULT_WAYPOINT_COLOR,
|
|
1818
|
+
icon: waypoint.icon ?? glyphs.WAYPOINT_FALLBACK_ICON,
|
|
1819
|
+
lngLat
|
|
1820
|
+
});
|
|
1821
|
+
}
|
|
1822
|
+
waypoints.push(...endpointMarkers(draft, active));
|
|
1823
|
+
return {
|
|
1824
|
+
lines,
|
|
1825
|
+
waypoints
|
|
1826
|
+
};
|
|
1827
|
+
};
|
|
1828
|
+
const itineraryToPreviewRender = (glyphs, itinerary, active) => {
|
|
1829
|
+
const chain = (itinerary.segments ?? []).map((segment) => ({
|
|
1830
|
+
color: segment.color ?? DEFAULT_SEGMENT_COLOR,
|
|
1831
|
+
geometry: segment.geojson,
|
|
1832
|
+
id: segment.id
|
|
1833
|
+
}));
|
|
1834
|
+
const lines = [];
|
|
1835
|
+
for (const segment of chain) {
|
|
1836
|
+
if (segment.id === active.segmentId) continue;
|
|
1837
|
+
for (const line of extractLines(segment.geometry)) lines.push({
|
|
1838
|
+
color: segment.color,
|
|
1839
|
+
coordinates: line.coordinates,
|
|
1840
|
+
dashed: false
|
|
1841
|
+
});
|
|
1842
|
+
}
|
|
1843
|
+
const waypoints = [];
|
|
1844
|
+
for (const waypoint of itinerary.waypoints ?? []) {
|
|
1845
|
+
if (waypoint.id === active.waypointId) continue;
|
|
1846
|
+
const lngLat = lngLatOf(extractPoint(waypoint.geojson)?.coordinates);
|
|
1847
|
+
if (!lngLat) continue;
|
|
1848
|
+
waypoints.push({
|
|
1849
|
+
color: waypoint.color ?? DEFAULT_WAYPOINT_COLOR,
|
|
1850
|
+
icon: waypoint.icon ?? glyphs.WAYPOINT_FALLBACK_ICON,
|
|
1851
|
+
lngLat
|
|
1852
|
+
});
|
|
1853
|
+
}
|
|
1854
|
+
waypoints.push(...chainEndpointMarkers(chain, active));
|
|
1855
|
+
return {
|
|
1856
|
+
lines,
|
|
1857
|
+
waypoints
|
|
1858
|
+
};
|
|
1859
|
+
};
|
|
1860
|
+
const itineraryExclusions = (itinerary) => ({
|
|
1861
|
+
segmentIds: (itinerary.segments ?? []).map((segment) => segment.id),
|
|
1862
|
+
waypointIds: (itinerary.waypoints ?? []).map((waypoint) => waypoint.id)
|
|
1863
|
+
});
|
|
1864
|
+
const draftGeometries = (draft) => {
|
|
1865
|
+
const geometries = [];
|
|
1866
|
+
for (const segment of draft.segments) geometries.push(chosenAndOther(segment).chosen);
|
|
1867
|
+
for (const waypoint of draft.waypoints) geometries.push(waypoint.geojson);
|
|
1868
|
+
return geometries;
|
|
1869
|
+
};
|
|
1870
|
+
const zoneBandsToPreviewRender = (glyphs, preview) => {
|
|
1871
|
+
const color = zoneLevelColors[preview.level];
|
|
1872
|
+
const lines = [];
|
|
1873
|
+
for (const band of preview.bands) for (const ring of band.geometry.coordinates) lines.push({
|
|
1874
|
+
color,
|
|
1875
|
+
coordinates: ring,
|
|
1876
|
+
dashed: false
|
|
1877
|
+
});
|
|
1878
|
+
return {
|
|
1879
|
+
lines,
|
|
1880
|
+
waypoints: preview.origin ? [{
|
|
1881
|
+
color,
|
|
1882
|
+
icon: glyphs.activityMarkerIcon(preview.activity) ?? glyphs.WAYPOINT_FALLBACK_ICON,
|
|
1883
|
+
lngLat: preview.origin
|
|
1884
|
+
}] : []
|
|
1885
|
+
};
|
|
1886
|
+
};
|
|
1887
|
+
const REACHABILITY_GLYPH = "reachability";
|
|
1888
|
+
const MIN_VALUE_KEY = "minValue";
|
|
1889
|
+
const MAX_VALUE_KEY = "maxValue";
|
|
1890
|
+
const overlayReadouts = {
|
|
1891
|
+
humidity: {
|
|
1892
|
+
format: formatHumidity,
|
|
1893
|
+
glyph: "datum-humidity"
|
|
1894
|
+
},
|
|
1895
|
+
snowdepth: {
|
|
1896
|
+
format: formatSnowDepth,
|
|
1897
|
+
glyph: "datum-snow-depth"
|
|
1898
|
+
},
|
|
1899
|
+
"snowfall-daily": {
|
|
1900
|
+
format: formatSnowfall,
|
|
1901
|
+
glyph: "datum-snowfall"
|
|
1902
|
+
},
|
|
1903
|
+
"snowfall-hourly": {
|
|
1904
|
+
format: formatSnowfall,
|
|
1905
|
+
glyph: "datum-snowfall"
|
|
1906
|
+
},
|
|
1907
|
+
"temperature-actual": {
|
|
1908
|
+
format: formatTemperature,
|
|
1909
|
+
glyph: "datum-temperature"
|
|
1910
|
+
},
|
|
1911
|
+
"temperature-perceived": {
|
|
1912
|
+
format: formatTemperature,
|
|
1913
|
+
glyph: "datum-temperature"
|
|
1914
|
+
},
|
|
1915
|
+
"temperature-soil": {
|
|
1916
|
+
format: formatTemperature,
|
|
1917
|
+
glyph: "datum-temperature"
|
|
1918
|
+
},
|
|
1919
|
+
visibility: {
|
|
1920
|
+
format: formatDistance,
|
|
1921
|
+
glyph: "datum-visibility"
|
|
1922
|
+
},
|
|
1923
|
+
wind: {
|
|
1924
|
+
format: (value, options) => formatSpeed(value, {
|
|
1925
|
+
...options,
|
|
1926
|
+
pace: "per-time"
|
|
1927
|
+
}),
|
|
1928
|
+
glyph: "datum-wind"
|
|
1929
|
+
}
|
|
1930
|
+
};
|
|
1931
|
+
const overlayReadoutFor = (slug) => slug && Object.hasOwn(overlayReadouts, slug) ? overlayReadouts[slug] ?? null : null;
|
|
1932
|
+
const extractOverlayBand = (features) => {
|
|
1933
|
+
for (const feature of features) {
|
|
1934
|
+
const min = feature[MIN_VALUE_KEY];
|
|
1935
|
+
const max = feature[MAX_VALUE_KEY];
|
|
1936
|
+
const hasMin = typeof min === "number" && Number.isFinite(min);
|
|
1937
|
+
const hasMax = typeof max === "number" && Number.isFinite(max);
|
|
1938
|
+
if (hasMin || hasMax) return {
|
|
1939
|
+
max: hasMax ? max : null,
|
|
1940
|
+
min: hasMin ? min : null
|
|
1941
|
+
};
|
|
1942
|
+
}
|
|
1943
|
+
return null;
|
|
1944
|
+
};
|
|
1945
|
+
const resolveBaseTerrain = (terrains, slug, variant, demUrl) => {
|
|
1946
|
+
const terrain = terrains.find((candidate) => candidate.slug === slug) ?? terrains[0];
|
|
1947
|
+
if (!terrain) return null;
|
|
1948
|
+
const tint = terrain.variants[variant] ?? terrain.variants.light ?? terrain.variants.dark;
|
|
1949
|
+
if (!tint) return null;
|
|
1950
|
+
const config = { styleUrl: tint.style.url };
|
|
1951
|
+
if (demUrl) config.demUrl = demUrl;
|
|
1952
|
+
return config;
|
|
1953
|
+
};
|
|
1954
|
+
const attributeOf = (hit, name) => {
|
|
1955
|
+
const value = hit.properties[name];
|
|
1956
|
+
return typeof value === "string" && value !== "" ? value : null;
|
|
1957
|
+
};
|
|
1958
|
+
const itineraryTileFeature = (hit) => {
|
|
1959
|
+
const waypointId = attributeOf(hit, "waypoint_id");
|
|
1960
|
+
if (waypointId !== null) return {
|
|
1961
|
+
id: waypointId,
|
|
1962
|
+
kind: "waypoint"
|
|
1963
|
+
};
|
|
1964
|
+
const segmentId = attributeOf(hit, "segment_id");
|
|
1965
|
+
return segmentId === null ? null : {
|
|
1966
|
+
id: segmentId,
|
|
1967
|
+
kind: "segment"
|
|
1968
|
+
};
|
|
1969
|
+
};
|
|
1970
|
+
const drawnByItinerary = (hit) => attributeOf(hit, "itinerary_id") !== null || itineraryTileFeature(hit) !== null;
|
|
1971
|
+
const itineraryLayerIdsOf = (sources) => {
|
|
1972
|
+
const lines = [];
|
|
1973
|
+
const points = [];
|
|
1974
|
+
const icons = [];
|
|
1975
|
+
for (const source of sources) {
|
|
1976
|
+
for (const layer of source.layers) if (layer.source_layer === ITINERARY_LINE_SOURCE_LAYER) lines.push(layer.id);
|
|
1977
|
+
else if (layer.source_layer === ITINERARY_POINT_SOURCE_LAYER) points.push(layer.id);
|
|
1978
|
+
const icon = roadAccessIconLayerIdOf(source);
|
|
1979
|
+
if (icon !== null) icons.push(icon);
|
|
1980
|
+
}
|
|
1981
|
+
return [
|
|
1982
|
+
...lines,
|
|
1983
|
+
...points,
|
|
1984
|
+
...icons
|
|
1985
|
+
];
|
|
1986
|
+
};
|
|
1987
|
+
const roadAccessStretchOf = (hit) => {
|
|
1988
|
+
if (hit.sourceLayer !== ITINERARY_RESTRICTION_SOURCE_LAYER) return null;
|
|
1989
|
+
const segmentId = attributeOf(hit, "segment_id");
|
|
1990
|
+
const itineraryId = attributeOf(hit, "itinerary_id");
|
|
1991
|
+
if (segmentId === null || itineraryId === null) return null;
|
|
1992
|
+
const stated = hit.properties.kind;
|
|
1993
|
+
return {
|
|
1994
|
+
itineraryId,
|
|
1995
|
+
kind: ROAD_ACCESS_KINDS.find((known) => known === stated) ?? "restricted",
|
|
1996
|
+
segmentId
|
|
1997
|
+
};
|
|
1998
|
+
};
|
|
1999
|
+
const itineraryClickTarget = (kind, hit, state, readOnly) => {
|
|
2000
|
+
const itinerary = state.activeItinerary;
|
|
2001
|
+
const feature = itineraryTileFeature(hit);
|
|
2002
|
+
const ofTheOpenItinerary = itinerary !== null && hit.properties.itinerary_id === itinerary.id;
|
|
2003
|
+
if (kind !== "itinerary" && !readOnly && !ofTheOpenItinerary) return null;
|
|
2004
|
+
if (kind === "roadAccess") {
|
|
2005
|
+
const stretch = roadAccessStretchOf(hit);
|
|
2006
|
+
return stretch === null ? null : {
|
|
2007
|
+
kind,
|
|
2008
|
+
stretch
|
|
2009
|
+
};
|
|
2010
|
+
}
|
|
2011
|
+
if (kind === "segment") {
|
|
2012
|
+
if (feature?.kind !== "segment") return null;
|
|
2013
|
+
const segmentId = feature.id;
|
|
2014
|
+
return {
|
|
2015
|
+
edit: !readOnly && itinerary !== null && itinerary.segments.some((segment) => segment.id === segmentId) && hit.sourceLayer !== ITINERARY_RESTRICTION_SOURCE_LAYER && showingDraftSurface(state) === null && !state.agentDriving && state.segmentSplitPick === null && state.collabByResource[collabResourceKey({
|
|
2016
|
+
id: itinerary.id,
|
|
2017
|
+
kind: "itineraries"
|
|
2018
|
+
})]?.locks[collabLockKey("segment", segmentId)] === void 0,
|
|
2019
|
+
kind,
|
|
2020
|
+
segmentId
|
|
2021
|
+
};
|
|
2022
|
+
}
|
|
2023
|
+
if (kind === "waypoint") return feature?.kind === "waypoint" ? {
|
|
2024
|
+
details: ofTheOpenItinerary,
|
|
2025
|
+
kind,
|
|
2026
|
+
waypointId: feature.id
|
|
2027
|
+
} : null;
|
|
2028
|
+
const itineraryId = hit.properties.itinerary_id;
|
|
2029
|
+
if (readOnly || typeof itineraryId !== "string" || itineraryId.length === 0) return null;
|
|
2030
|
+
return itinerary?.id === itineraryId ? null : {
|
|
2031
|
+
itineraryId,
|
|
2032
|
+
kind
|
|
2033
|
+
};
|
|
2034
|
+
};
|
|
2035
|
+
const zoneClickTarget = (hit, activeZone, userId, writableOrganizationIds) => {
|
|
2036
|
+
const zoneId = hit.properties.id ?? hit.id;
|
|
2037
|
+
if (typeof zoneId !== "string" || !hasUuidShape(zoneId)) return null;
|
|
2038
|
+
if (activeZone?.id === zoneId) {
|
|
2039
|
+
const geometry = activeZone.geojson.geometry;
|
|
2040
|
+
if (!canEditOwnedResource({
|
|
2041
|
+
createdById: activeZone.created_by.id,
|
|
2042
|
+
organizationId: activeZone.organization_id
|
|
2043
|
+
}, userId, writableOrganizationIds) || geometry.type !== "Polygon" || activeZone.source) return null;
|
|
2044
|
+
return {
|
|
2045
|
+
input: {
|
|
2046
|
+
intent: "edit",
|
|
2047
|
+
level: activeZone.level,
|
|
2048
|
+
mode: activeZone.mode,
|
|
2049
|
+
seedGeometry: geometry,
|
|
2050
|
+
zoneId
|
|
2051
|
+
},
|
|
2052
|
+
kind: "reshape"
|
|
2053
|
+
};
|
|
2054
|
+
}
|
|
2055
|
+
const createdBy = hit.properties.created_by;
|
|
2056
|
+
const organizationId = hit.properties.organization_id;
|
|
2057
|
+
return {
|
|
2058
|
+
kind: canEditOwnedResource({
|
|
2059
|
+
createdById: typeof createdBy === "string" ? createdBy : null,
|
|
2060
|
+
organizationId: typeof organizationId === "string" ? organizationId : null
|
|
2061
|
+
}, userId, writableOrganizationIds) ? "edit" : "view",
|
|
2062
|
+
zoneId
|
|
2063
|
+
};
|
|
2064
|
+
};
|
|
2065
|
+
const mapInteractionScope = (state) => {
|
|
2066
|
+
if (state.segmentEditSession !== null || state.waypointEditSession !== null || state.zoneEditSession !== null) return "locked";
|
|
2067
|
+
if (state.activeZone !== null) return "zone";
|
|
2068
|
+
return state.activeItinerary === null ? "free" : "itinerary";
|
|
2069
|
+
};
|
|
2070
|
+
const READOUT_KEYS = [
|
|
2071
|
+
"elevation",
|
|
2072
|
+
"slope",
|
|
2073
|
+
"aspect",
|
|
2074
|
+
"steepness_class"
|
|
2075
|
+
];
|
|
2076
|
+
const contextMenuReadout = (features) => {
|
|
2077
|
+
const rows = [];
|
|
2078
|
+
for (const key of READOUT_KEYS) {
|
|
2079
|
+
const value = features.find((feature) => feature[key] != null)?.[key];
|
|
2080
|
+
if (value != null) rows.push({
|
|
2081
|
+
key,
|
|
2082
|
+
value
|
|
2083
|
+
});
|
|
2084
|
+
}
|
|
2085
|
+
return rows;
|
|
2086
|
+
};
|
|
2087
|
+
const SUGGESTION_PREVIEW_COLOR = "#228be6";
|
|
2088
|
+
const SUGGESTION_START_ICON = ITINERARY_ENDPOINT_ICONS[0];
|
|
2089
|
+
const SUGGESTION_END_ICON = ITINERARY_ENDPOINT_ICONS[1];
|
|
2090
|
+
const suggestionPreviewRender = (inputs) => {
|
|
2091
|
+
const { candidates, end, routeType, selectedSeed, start } = inputs;
|
|
2092
|
+
const candidate = selectedSeed === null ? null : candidates.find((entry) => entry.seed === selectedSeed) ?? null;
|
|
2093
|
+
const lines = candidate ? extractLines(candidate.geometry).map((line) => ({
|
|
2094
|
+
color: candidate.color,
|
|
2095
|
+
coordinates: line.coordinates,
|
|
2096
|
+
dashed: false
|
|
2097
|
+
})) : [];
|
|
2098
|
+
const waypoints = [];
|
|
2099
|
+
if (start) waypoints.push({
|
|
2100
|
+
color: SUGGESTION_PREVIEW_COLOR,
|
|
2101
|
+
icon: SUGGESTION_START_ICON,
|
|
2102
|
+
lngLat: start
|
|
2103
|
+
});
|
|
2104
|
+
if (routeType === "point_to_point" && end) waypoints.push({
|
|
2105
|
+
color: SUGGESTION_PREVIEW_COLOR,
|
|
2106
|
+
icon: SUGGESTION_END_ICON,
|
|
2107
|
+
lngLat: end
|
|
2108
|
+
});
|
|
2109
|
+
return {
|
|
2110
|
+
lines,
|
|
2111
|
+
waypoints
|
|
2112
|
+
};
|
|
2113
|
+
};
|
|
2114
|
+
const previewProjection = (glyphs, input) => {
|
|
2115
|
+
const { activeItinerary, draft, suggestion, tiled, zonePreview } = input;
|
|
2116
|
+
const editing = {
|
|
2117
|
+
segmentId: input.editSegmentId,
|
|
2118
|
+
waypointId: input.editWaypointId
|
|
2119
|
+
};
|
|
2120
|
+
if (zonePreview && zonePreview.bands.length > 0) return {
|
|
2121
|
+
draft: null,
|
|
2122
|
+
exclusions: null,
|
|
2123
|
+
render: zoneBandsToPreviewRender(glyphs, zonePreview)
|
|
2124
|
+
};
|
|
2125
|
+
if (draft && (draft.segments.length > 0 || draft.waypoints.length > 0)) return {
|
|
2126
|
+
draft,
|
|
2127
|
+
exclusions: null,
|
|
2128
|
+
render: draftToPreviewRender(glyphs, draft, editing)
|
|
2129
|
+
};
|
|
2130
|
+
if (suggestion) {
|
|
2131
|
+
const render = suggestionPreviewRender(suggestion);
|
|
2132
|
+
if (render.lines.length > 0 || render.waypoints.length > 0) return {
|
|
2133
|
+
draft: null,
|
|
2134
|
+
exclusions: null,
|
|
2135
|
+
render
|
|
2136
|
+
};
|
|
2137
|
+
}
|
|
2138
|
+
if (!tiled && activeItinerary) return {
|
|
2139
|
+
draft: null,
|
|
2140
|
+
exclusions: itineraryExclusions(activeItinerary),
|
|
2141
|
+
render: itineraryToPreviewRender(glyphs, activeItinerary, editing)
|
|
2142
|
+
};
|
|
2143
|
+
return {
|
|
2144
|
+
draft: null,
|
|
2145
|
+
exclusions: null,
|
|
2146
|
+
render: null
|
|
2147
|
+
};
|
|
2148
|
+
};
|
|
2149
|
+
const peerDraftGhosts = (input) => {
|
|
2150
|
+
const present = new Set(input.presentPeerIds);
|
|
2151
|
+
const ghosts = [];
|
|
2152
|
+
for (const [key, draft] of Object.entries(input.drafts)) {
|
|
2153
|
+
if (!present.has(draft.userId)) continue;
|
|
2154
|
+
const color = collabPeerColor(draft.userId);
|
|
2155
|
+
const label = input.resolveName?.(draft.userId) ?? peerDraftInitials(draft.userId);
|
|
2156
|
+
if (draft.kind === "segment") {
|
|
2157
|
+
if (draft.segment.id === input.localSegmentEditId) continue;
|
|
2158
|
+
const line = extractLines(draft.segment.geojson).find((candidate) => candidate.coordinates.length >= 2);
|
|
2159
|
+
if (!line) continue;
|
|
2160
|
+
ghosts.push({
|
|
2161
|
+
color,
|
|
2162
|
+
entity: {
|
|
2163
|
+
id: draft.segment.id,
|
|
2164
|
+
kind: "segment"
|
|
2165
|
+
},
|
|
2166
|
+
geometry: line,
|
|
2167
|
+
key,
|
|
2168
|
+
label
|
|
2169
|
+
});
|
|
2170
|
+
continue;
|
|
2171
|
+
}
|
|
2172
|
+
const zoneId = key.slice(key.indexOf("/") + 1);
|
|
2173
|
+
if (zoneId === input.localZoneEditId) continue;
|
|
2174
|
+
ghosts.push({
|
|
2175
|
+
color,
|
|
2176
|
+
entity: {
|
|
2177
|
+
id: zoneId,
|
|
2178
|
+
kind: "zone"
|
|
2179
|
+
},
|
|
2180
|
+
geometry: draft.zone,
|
|
2181
|
+
key,
|
|
2182
|
+
label
|
|
2183
|
+
});
|
|
2184
|
+
}
|
|
2185
|
+
return ghosts;
|
|
2186
|
+
};
|
|
2187
|
+
const permittedEnrichmentOverlays = (layers, activeEnrichments, overlaysEntitled, poisEntitled) => [...new Set(activeEnrichments)].flatMap((slug) => {
|
|
2188
|
+
if (!(slug === POIS_OVERLAY_SLUG ? poisEntitled : overlaysEntitled)) return [];
|
|
2189
|
+
const overlay = findOverlay({ overlays: layers.overlays ?? [] }, slug);
|
|
2190
|
+
return overlay === null ? [] : [overlay];
|
|
2191
|
+
});
|
|
2192
|
+
const permittedClassicOverlay = (layers, activeOverlay, overlaysEntitled) => overlaysEntitled && activeOverlay !== null ? findOverlay({ overlays: layers.overlays ?? [] }, activeOverlay) : null;
|
|
2193
|
+
const poiGroupByLayerKey = new Map(POI_GROUPS.flatMap((group) => group.layerKeys.map((key) => [key, group.id])));
|
|
2194
|
+
const poiLayerVisibility = (layers, activePoiGroups) => {
|
|
2195
|
+
const overlay = findOverlay({ overlays: layers.overlays ?? [] }, POIS_OVERLAY_SLUG);
|
|
2196
|
+
if (!overlay) return [];
|
|
2197
|
+
const active = new Set(activePoiGroups);
|
|
2198
|
+
return overlay.sources.flatMap((source) => source.layers.map((layer) => {
|
|
2199
|
+
const group = poiGroupByLayerKey.get(layer.key);
|
|
2200
|
+
return {
|
|
2201
|
+
layerId: layer.id,
|
|
2202
|
+
visible: group === void 0 || active.has(group)
|
|
2203
|
+
};
|
|
2204
|
+
}));
|
|
2205
|
+
};
|
|
2206
|
+
const ZONE_TIME_REFERENCE_INTERVAL_MS = /*#__PURE__*/ convertDuration(1, "minute", "millisecond");
|
|
2207
|
+
const zoneTimeReferenceSeconds = (overlayTimestamp, nowMs) => {
|
|
2208
|
+
const pinnedMs = overlayTimestamp ? new Date(overlayTimestamp).getTime() : NaN;
|
|
2209
|
+
if (!Number.isNaN(pinnedMs)) return Math.floor(convertDuration(pinnedMs, "millisecond", "second"));
|
|
2210
|
+
const intervalStartMs = Math.floor(nowMs / ZONE_TIME_REFERENCE_INTERVAL_MS) * ZONE_TIME_REFERENCE_INTERVAL_MS;
|
|
2211
|
+
return convertDuration(intervalStartMs, "millisecond", "second");
|
|
2212
|
+
};
|
|
2213
|
+
const activeSegmentLines = (itinerary) => (itinerary?.segments ?? []).flatMap((segment) => extractLines(segment.geojson).map((line) => line.coordinates));
|
|
2214
|
+
const resolveDemUrl = (layers, demUrl) => demUrl || layers?.elevation?.url || void 0;
|
|
2215
|
+
const SEARCH_REFUSED_NAME = "SearchRefusedError";
|
|
2216
|
+
var SearchRefusedError = class extends MountayaElementsError {
|
|
2217
|
+
name = SEARCH_REFUSED_NAME;
|
|
2218
|
+
code;
|
|
2219
|
+
detail;
|
|
2220
|
+
constructor(refusal) {
|
|
2221
|
+
super(refusal.error);
|
|
2222
|
+
this.code = refusal.code;
|
|
2223
|
+
this.detail = refusal.detail;
|
|
2224
|
+
}
|
|
2225
|
+
};
|
|
2226
|
+
const targetFlags = {
|
|
2227
|
+
collections: true,
|
|
2228
|
+
itineraries: true,
|
|
2229
|
+
places: true,
|
|
2230
|
+
pois: true,
|
|
2231
|
+
ways: true,
|
|
2232
|
+
zones: true
|
|
2233
|
+
};
|
|
2234
|
+
const isTargetName = (name) => Object.hasOwn(targetFlags, name);
|
|
2235
|
+
const enabledTarget = (targets) => Object.keys(targetFlags).find((name) => isTargetName(name) && targets[name] === true);
|
|
2236
|
+
const createSearchFetch = (dispatch) => async (input) => {
|
|
2237
|
+
const target = enabledTarget(input.targets);
|
|
2238
|
+
if (target === void 0) throw new MountayaElementsError("no search target requested");
|
|
2239
|
+
const result = await dispatch("studio.search.run", {
|
|
2240
|
+
bbox: boundsTuple(input.bbox),
|
|
2241
|
+
focus: pointTuple(input.focus),
|
|
2242
|
+
language: input.language ?? void 0,
|
|
2243
|
+
limit: input.limit ?? void 0,
|
|
2244
|
+
query: input.query,
|
|
2245
|
+
target
|
|
2246
|
+
});
|
|
2247
|
+
if (!result.ok) throw new SearchRefusedError(result);
|
|
2248
|
+
return result.data;
|
|
2249
|
+
};
|
|
2250
|
+
const buildSegmentChainMerges = (segments, lockedSegmentIds = /* @__PURE__ */ new Set()) => {
|
|
2251
|
+
const byAbsorber = /* @__PURE__ */ new Map();
|
|
2252
|
+
const byFolded = /* @__PURE__ */ new Map();
|
|
2253
|
+
for (let index = 1; index < segments.length; index += 1) {
|
|
2254
|
+
const previous = segments[index - 1];
|
|
2255
|
+
const segment = segments[index];
|
|
2256
|
+
if (!previous || !segment) continue;
|
|
2257
|
+
let disabledReason = null;
|
|
2258
|
+
if (previous.mode !== segment.mode) disabledReason = "engine";
|
|
2259
|
+
else if (previous.group_id !== segment.group_id) disabledReason = "group";
|
|
2260
|
+
else if (exceedsMergeViaCeiling(previous, segment)) disabledReason = "waypointsMax";
|
|
2261
|
+
else if (lockedSegmentIds.has(previous.id) || lockedSegmentIds.has(segment.id)) disabledReason = "locked";
|
|
2262
|
+
const merge = {
|
|
2263
|
+
disabledReason,
|
|
2264
|
+
intoSegmentId: segment.id,
|
|
2265
|
+
segmentId: previous.id
|
|
2266
|
+
};
|
|
2267
|
+
byFolded.set(previous.id, merge);
|
|
2268
|
+
byAbsorber.set(segment.id, merge);
|
|
2269
|
+
}
|
|
2270
|
+
return {
|
|
2271
|
+
byAbsorber,
|
|
2272
|
+
byFolded
|
|
2273
|
+
};
|
|
2274
|
+
};
|
|
2275
|
+
const segmentChainEnds = (segments) => ({
|
|
2276
|
+
committedIds: new Set(segments.map((segment) => segment.id)),
|
|
2277
|
+
firstCommittedId: segments[0]?.id ?? null,
|
|
2278
|
+
lastCommittedId: segments.at(-1)?.id ?? null
|
|
2279
|
+
});
|
|
2280
|
+
const buildSegmentGroupRuns = (segments, groups) => {
|
|
2281
|
+
const byId = new Map(groups.map((group) => [group.id, group]));
|
|
2282
|
+
const memberCounts = /* @__PURE__ */ new Map();
|
|
2283
|
+
for (const segment of segments) if (segment.group_id !== null) memberCounts.set(segment.group_id, (memberCounts.get(segment.group_id) ?? 0) + 1);
|
|
2284
|
+
const groupOf = (segment) => segment.group_id === null ? null : byId.get(segment.group_id) ?? null;
|
|
2285
|
+
const runs = /* @__PURE__ */ new Map();
|
|
2286
|
+
segments.forEach((segment, index) => {
|
|
2287
|
+
const group = groupOf(segment);
|
|
2288
|
+
const previous = segments[index - 1];
|
|
2289
|
+
const next = segments[index + 1];
|
|
2290
|
+
runs.set(segment.id, {
|
|
2291
|
+
group,
|
|
2292
|
+
hasFreeNeighbour: previous !== void 0 && groupOf(previous) === null || next !== void 0 && groupOf(next) === null,
|
|
2293
|
+
isFirst: group === null ? false : previous?.group_id !== group.id,
|
|
2294
|
+
isLast: group === null ? false : next?.group_id !== group.id,
|
|
2295
|
+
memberCount: group === null ? 0 : memberCounts.get(group.id) ?? 0
|
|
2296
|
+
});
|
|
2297
|
+
});
|
|
2298
|
+
return runs;
|
|
2299
|
+
};
|
|
2300
|
+
const segmentGroupDissolvesOnLeave = (memberCount) => memberCount - 1 < SEGMENT_GROUP_MIN_MEMBERS;
|
|
2301
|
+
const buildSegmentEditCommitInput = ({ coordinates, draftColor, draftName, itineraryId, mode, segmentId }) => {
|
|
2302
|
+
if (draftName !== null) return mode === "directions" ? {
|
|
2303
|
+
color: draftColor ?? void 0,
|
|
2304
|
+
itineraryId,
|
|
2305
|
+
mode: "directions",
|
|
2306
|
+
name: draftName,
|
|
2307
|
+
vias: coordinates
|
|
2308
|
+
} : {
|
|
2309
|
+
color: draftColor ?? void 0,
|
|
2310
|
+
itineraryId,
|
|
2311
|
+
line: coordinates,
|
|
2312
|
+
mode: "linestring",
|
|
2313
|
+
name: draftName
|
|
2314
|
+
};
|
|
2315
|
+
return mode === "directions" ? {
|
|
2316
|
+
itineraryId,
|
|
2317
|
+
mode: "directions",
|
|
2318
|
+
segmentId,
|
|
2319
|
+
vias: coordinates
|
|
2320
|
+
} : {
|
|
2321
|
+
itineraryId,
|
|
2322
|
+
line: coordinates,
|
|
2323
|
+
mode: "linestring",
|
|
2324
|
+
segmentId
|
|
2325
|
+
};
|
|
2326
|
+
};
|
|
2327
|
+
const draftSeed = (segment) => {
|
|
2328
|
+
if (segment.mode === "directions") {
|
|
2329
|
+
if (!segment.directions) return null;
|
|
2330
|
+
const vias = extractVias(segment.directions.geojson);
|
|
2331
|
+
const rawSeed = vias.length > 0 ? vias : simplifyToVias(segmentLineCoordinates(segment.directions.geojson), DIRECTIONS_VIA_MAX);
|
|
2332
|
+
return rawSeed.length > 0 ? seedFromCoordinates(rawSeed) : null;
|
|
2333
|
+
}
|
|
2334
|
+
const line = segmentLineCoordinates(segment.linestring.geojson);
|
|
2335
|
+
return line.length > 0 ? seedFromCoordinates(line) : null;
|
|
2336
|
+
};
|
|
2337
|
+
const beginDraftSegmentEdit = (dispatch, segment, anchor, activitySlug) => {
|
|
2338
|
+
const mode = segment.mode;
|
|
2339
|
+
const seed = draftSeed(segment);
|
|
2340
|
+
if (!seed) return Promise.resolve(null);
|
|
2341
|
+
const previousPin = anchor.previousEnd ? clampSeedPoint(anchor.previousEnd) : null;
|
|
2342
|
+
const pinnedStart = anchor.isFirst ? void 0 : previousPin ?? seed.pinnedStart;
|
|
2343
|
+
return dispatch("studio.itinerary.segment.editBegin", {
|
|
2344
|
+
activitySlug: activitySlug ?? void 0,
|
|
2345
|
+
color: hexColorSchema.safeParse(segment.color).success ? segment.color : DEFAULT_SEGMENT_COLOR,
|
|
2346
|
+
mode,
|
|
2347
|
+
pinnedStart,
|
|
2348
|
+
seedVias: seed.seedVias,
|
|
2349
|
+
segmentId: segment.id
|
|
2350
|
+
});
|
|
2351
|
+
};
|
|
2352
|
+
const heldRun = (segments, groupId) => segments.filter((segment) => segment.group_id === groupId).map((segment) => segment.id);
|
|
2353
|
+
const segmentGroupForm = (group, segments) => ({
|
|
2354
|
+
color: group.color,
|
|
2355
|
+
name: group.name,
|
|
2356
|
+
opened: {
|
|
2357
|
+
color: group.color,
|
|
2358
|
+
groupId: group.id,
|
|
2359
|
+
name: group.name,
|
|
2360
|
+
speed: group.speed
|
|
2361
|
+
},
|
|
2362
|
+
segmentIds: heldRun(segments, group.id),
|
|
2363
|
+
speed: group.speed
|
|
2364
|
+
});
|
|
2365
|
+
const formRefusal$1 = (form) => {
|
|
2366
|
+
if (form.segmentIds.length < SEGMENT_GROUP_MIN_MEMBERS) return "minMembers";
|
|
2367
|
+
return displayNameSchema.safeParse(form.name).success ? null : "nameError";
|
|
2368
|
+
};
|
|
2369
|
+
const sameRun = (left, right) => left.length === right.length && left.every((id, index) => id === right[index]);
|
|
2370
|
+
const segmentGroupSavePlan = (itineraryId, segments, form) => {
|
|
2371
|
+
const name = form.name.trim();
|
|
2372
|
+
const refusal = formRefusal$1(form);
|
|
2373
|
+
const { opened } = form;
|
|
2374
|
+
if (opened === null) {
|
|
2375
|
+
const create = {
|
|
2376
|
+
input: {
|
|
2377
|
+
color: form.color,
|
|
2378
|
+
itineraryId,
|
|
2379
|
+
name,
|
|
2380
|
+
segmentIds: [...form.segmentIds],
|
|
2381
|
+
speed: form.speed
|
|
2382
|
+
},
|
|
2383
|
+
name: "studio.itinerary.group.create"
|
|
2384
|
+
};
|
|
2385
|
+
return {
|
|
2386
|
+
changed: true,
|
|
2387
|
+
refusal,
|
|
2388
|
+
steps: refusal === null ? [create] : []
|
|
2389
|
+
};
|
|
2390
|
+
}
|
|
2391
|
+
const subject = {
|
|
2392
|
+
groupId: opened.groupId,
|
|
2393
|
+
itineraryId
|
|
2394
|
+
};
|
|
2395
|
+
const runMoved = !sameRun(heldRun(segments, opened.groupId), form.segmentIds);
|
|
2396
|
+
const display = {
|
|
2397
|
+
...form.color === opened.color ? {} : { color: form.color },
|
|
2398
|
+
...name === opened.name.trim() ? {} : { name },
|
|
2399
|
+
...form.speed === opened.speed ? {} : { speed: form.speed }
|
|
2400
|
+
};
|
|
2401
|
+
const displayMoved = Object.keys(display).length > 0;
|
|
2402
|
+
const changed = runMoved || displayMoved;
|
|
2403
|
+
if (refusal !== null) return {
|
|
2404
|
+
changed,
|
|
2405
|
+
refusal,
|
|
2406
|
+
steps: []
|
|
2407
|
+
};
|
|
2408
|
+
const steps = [];
|
|
2409
|
+
if (runMoved) steps.push({
|
|
2410
|
+
input: {
|
|
2411
|
+
...subject,
|
|
2412
|
+
segmentIds: [...form.segmentIds]
|
|
2413
|
+
},
|
|
2414
|
+
name: "studio.itinerary.group.setRange"
|
|
2415
|
+
});
|
|
2416
|
+
if (displayMoved) steps.push({
|
|
2417
|
+
input: {
|
|
2418
|
+
...display,
|
|
2419
|
+
...subject
|
|
2420
|
+
},
|
|
2421
|
+
name: "studio.itinerary.group.update"
|
|
2422
|
+
});
|
|
2423
|
+
return {
|
|
2424
|
+
changed,
|
|
2425
|
+
refusal,
|
|
2426
|
+
steps
|
|
2427
|
+
};
|
|
2428
|
+
};
|
|
2429
|
+
const buildShareText = (name, meta) => meta ? `${name} · ${meta}` : name;
|
|
2430
|
+
const SOCIAL_SHARE_TARGETS = [
|
|
2431
|
+
{
|
|
2432
|
+
buildHref: (url, text) => `https://wa.me/?text=${encodeURIComponent(`${text} ${url}`)}`,
|
|
2433
|
+
id: "whatsapp"
|
|
2434
|
+
},
|
|
2435
|
+
{
|
|
2436
|
+
buildHref: (url, text) => `https://twitter.com/intent/tweet?text=${encodeURIComponent(text)}&url=${encodeURIComponent(url)}`,
|
|
2437
|
+
id: "x"
|
|
2438
|
+
},
|
|
2439
|
+
{
|
|
2440
|
+
buildHref: (url, text) => `https://t.me/share/url?url=${encodeURIComponent(url)}&text=${encodeURIComponent(text)}`,
|
|
2441
|
+
id: "telegram"
|
|
2442
|
+
},
|
|
2443
|
+
{
|
|
2444
|
+
buildHref: (url) => `https://www.facebook.com/sharer/sharer.php?u=${encodeURIComponent(url)}`,
|
|
2445
|
+
id: "facebook"
|
|
2446
|
+
},
|
|
2447
|
+
{
|
|
2448
|
+
buildHref: (url, text) => `https://www.reddit.com/submit?url=${encodeURIComponent(url)}&title=${encodeURIComponent(text)}`,
|
|
2449
|
+
id: "reddit"
|
|
2450
|
+
},
|
|
2451
|
+
{
|
|
2452
|
+
buildHref: (url) => `https://www.linkedin.com/sharing/share-offsite/?url=${encodeURIComponent(url)}`,
|
|
2453
|
+
id: "linkedin"
|
|
2454
|
+
},
|
|
2455
|
+
{
|
|
2456
|
+
buildHref: (url, text) => `mailto:?subject=${encodeURIComponent(text)}&body=${encodeURIComponent(url)}`,
|
|
2457
|
+
id: "email"
|
|
2458
|
+
}
|
|
2459
|
+
];
|
|
2460
|
+
const fallbackLanguage = resolveOrgEmbedDefaults(void 0).preferredLanguage;
|
|
2461
|
+
const buildShareViewConfig = (target, language) => {
|
|
2462
|
+
const known = languageSchema.safeParse(language);
|
|
2463
|
+
return {
|
|
2464
|
+
activity: null,
|
|
2465
|
+
collectionId: target.kind === "collection" ? target.id : null,
|
|
2466
|
+
embedded: true,
|
|
2467
|
+
enrichments: [],
|
|
2468
|
+
itineraryId: target.kind === "itinerary" ? target.id : null,
|
|
2469
|
+
overlay: null,
|
|
2470
|
+
preferredLanguage: known.success ? known.data : fallbackLanguage,
|
|
2471
|
+
preferredTheme: "light",
|
|
2472
|
+
preferredUnitLength: "metric",
|
|
2473
|
+
preferredUnitPace: "per-time",
|
|
2474
|
+
preferredUnitSlope: "degrees",
|
|
2475
|
+
preferredUnitTemperature: "celsius",
|
|
2476
|
+
segmentsColor: "",
|
|
2477
|
+
terrain: DEFAULT_TERRAIN,
|
|
2478
|
+
terrainVariant: "light",
|
|
2479
|
+
withAccessRestrictions: true,
|
|
2480
|
+
withCollectionItineraries: null,
|
|
2481
|
+
withCollectionZones: null,
|
|
2482
|
+
withDirectionsControl: false,
|
|
2483
|
+
withDownloadControl: true,
|
|
2484
|
+
withNavigationControl: true,
|
|
2485
|
+
withOverlays: [],
|
|
2486
|
+
withOverlaysControl: true,
|
|
2487
|
+
withPreferencesControl: true,
|
|
2488
|
+
withProfileAnalysis: true,
|
|
2489
|
+
withProfileCharacteristics: true,
|
|
2490
|
+
withProfileElevation: true,
|
|
2491
|
+
withProfilePaceControl: true,
|
|
2492
|
+
withStreetviewControl: false,
|
|
2493
|
+
withTerrains: []
|
|
2494
|
+
};
|
|
2495
|
+
};
|
|
2496
|
+
const previewRefreshDisposition = (status, plan) => {
|
|
2497
|
+
if (status === null || status.kind === "recording") return { kind: "keep" };
|
|
2498
|
+
if (status.kind === "previewing") return { kind: "restart" };
|
|
2499
|
+
return {
|
|
2500
|
+
fraction: representativeStillFraction(plan),
|
|
2501
|
+
kind: "park"
|
|
2502
|
+
};
|
|
2503
|
+
};
|
|
2504
|
+
const videoRouteSpans = (itinerary, segmentId) => {
|
|
2505
|
+
const segments = segmentsForSelection(itinerary, segmentId);
|
|
2506
|
+
const stretches = new Map(buildInfoBands(segments, (segment) => [{
|
|
2507
|
+
from_index: 0,
|
|
2508
|
+
to_index: Number.MAX_SAFE_INTEGER,
|
|
2509
|
+
value: segment
|
|
2510
|
+
}]).map((band) => [band.value, band]));
|
|
2511
|
+
const spans = [];
|
|
2512
|
+
let startKm = 0;
|
|
2513
|
+
for (const segment of segments) {
|
|
2514
|
+
const endKm = stretches.get(segment)?.endKm ?? startKm;
|
|
2515
|
+
spans.push({
|
|
2516
|
+
endKm,
|
|
2517
|
+
name: segment.name,
|
|
2518
|
+
speed: segment.speed === null ? null : convertSpeed(segment.speed, "kilometer-per-hour", "meter-per-second"),
|
|
2519
|
+
startKm
|
|
2520
|
+
});
|
|
2521
|
+
startKm = endKm;
|
|
2522
|
+
}
|
|
2523
|
+
return spans;
|
|
2524
|
+
};
|
|
2525
|
+
const videoProfileSource = (itinerary, segmentId) => {
|
|
2526
|
+
const segments = segmentsForSelection(itinerary, segmentId);
|
|
2527
|
+
return {
|
|
2528
|
+
elevationPoints: buildElevationPoints(segments),
|
|
2529
|
+
segmentSpans: videoRouteSpans(itinerary, segmentId),
|
|
2530
|
+
slopeBands: buildInfoBands(segments, (segment) => segment.slope_info),
|
|
2531
|
+
surfaceBands: buildInfoBands(segments, (segment) => segment.surface_info),
|
|
2532
|
+
waytypeBands: buildInfoBands(segments, (segment) => segment.way_type_info)
|
|
2533
|
+
};
|
|
2534
|
+
};
|
|
2535
|
+
const DEFAULT_SHOT_PITCH_DEG = 60;
|
|
2536
|
+
const DEFAULT_SHOT_ZOOM = 13;
|
|
2537
|
+
const DEFAULT_HOLD_MS = 2e3;
|
|
2538
|
+
const PREVIEW_PLAN_REFRESH_DEBOUNCE_MS = 250;
|
|
2539
|
+
const VIDEO_STEP_ORDER = [
|
|
2540
|
+
"format",
|
|
2541
|
+
"camera",
|
|
2542
|
+
"profile",
|
|
2543
|
+
"review"
|
|
2544
|
+
];
|
|
2545
|
+
const studioCapabilitySchema = z$1.enum([
|
|
2546
|
+
"authenticated",
|
|
2547
|
+
"editor",
|
|
2548
|
+
"embedding",
|
|
2549
|
+
"share"
|
|
2550
|
+
]);
|
|
2551
|
+
const studioConfigSchema = z$1.object({
|
|
2552
|
+
terrain: z$1.string(),
|
|
2553
|
+
terrainVariant: terrainVariantSchema,
|
|
2554
|
+
withDirectionsControl: z$1.boolean(),
|
|
2555
|
+
withDownloadControl: z$1.boolean(),
|
|
2556
|
+
withLayersControl: z$1.boolean(),
|
|
2557
|
+
withNavigationControl: z$1.boolean(),
|
|
2558
|
+
withOverlays: z$1.array(z$1.string()),
|
|
2559
|
+
withOverlaysControl: z$1.boolean(),
|
|
2560
|
+
withPreferencesControl: z$1.boolean(),
|
|
2561
|
+
withStreetviewControl: z$1.boolean(),
|
|
2562
|
+
withTerrains: z$1.array(z$1.string())
|
|
2563
|
+
});
|
|
2564
|
+
const defaultStudioConfig = studioConfigSchema.parse({
|
|
2565
|
+
terrain: DEFAULT_TERRAIN,
|
|
2566
|
+
terrainVariant: "light",
|
|
2567
|
+
withDirectionsControl: true,
|
|
2568
|
+
withDownloadControl: true,
|
|
2569
|
+
withLayersControl: true,
|
|
2570
|
+
withNavigationControl: true,
|
|
2571
|
+
withOverlays: [],
|
|
2572
|
+
withOverlaysControl: true,
|
|
2573
|
+
withPreferencesControl: true,
|
|
2574
|
+
withStreetviewControl: true,
|
|
2575
|
+
withTerrains: []
|
|
2576
|
+
});
|
|
2577
|
+
const embedBaseline = resolveOrgEmbedDefaults(void 0);
|
|
2578
|
+
const memberOr = (schema, value, fallback) => {
|
|
2579
|
+
const parsed = schema.safeParse(value);
|
|
2580
|
+
return parsed.success ? parsed.data : fallback;
|
|
2581
|
+
};
|
|
2582
|
+
const listOr = (schema, value, fallback) => {
|
|
2583
|
+
const parsed = schema.safeParse(value);
|
|
2584
|
+
return parsed.success ? parsed.data : [...fallback];
|
|
2585
|
+
};
|
|
2586
|
+
const embedConfigToStudioConfig = (embedConfig, cap) => {
|
|
2587
|
+
const { shape } = studioConfigSchema;
|
|
2588
|
+
const withOverlays = listOr(shape.withOverlays, embedConfig.withOverlays, embedBaseline.withOverlays);
|
|
2589
|
+
const withTerrains = listOr(shape.withTerrains, embedConfig.withTerrains, embedBaseline.withTerrains);
|
|
2590
|
+
return {
|
|
2591
|
+
terrain: memberOr(shape.terrain, embedConfig.terrain, embedBaseline.terrain),
|
|
2592
|
+
terrainVariant: memberOr(shape.terrainVariant, embedConfig.terrainVariant, embedBaseline.terrainVariant),
|
|
2593
|
+
withDirectionsControl: memberOr(shape.withDirectionsControl, embedConfig.withDirectionsControl, embedBaseline.withDirectionsControl),
|
|
2594
|
+
withDownloadControl: memberOr(shape.withDownloadControl, embedConfig.withDownloadControl, embedBaseline.withDownloadControl),
|
|
2595
|
+
withLayersControl: layersControlOffered({
|
|
2596
|
+
withOverlays,
|
|
2597
|
+
withTerrains
|
|
2598
|
+
}, cap),
|
|
2599
|
+
withNavigationControl: memberOr(shape.withNavigationControl, embedConfig.withNavigationControl, embedBaseline.withNavigationControl),
|
|
2600
|
+
withOverlays,
|
|
2601
|
+
withOverlaysControl: memberOr(shape.withOverlaysControl, embedConfig.withOverlaysControl, embedBaseline.withOverlaysControl),
|
|
2602
|
+
withPreferencesControl: memberOr(shape.withPreferencesControl, embedConfig.withPreferencesControl, embedBaseline.withPreferencesControl),
|
|
2603
|
+
withStreetviewControl: memberOr(shape.withStreetviewControl, embedConfig.withStreetviewControl, embedBaseline.withStreetviewControl),
|
|
2604
|
+
withTerrains
|
|
2605
|
+
};
|
|
2606
|
+
};
|
|
2607
|
+
const clampStudioConfigToSafetyRules = (config, safetyRules) => {
|
|
2608
|
+
if (safetyRules === void 0) return config;
|
|
2609
|
+
let next = config;
|
|
2610
|
+
if (next.withOverlaysControl && safetyRules.with_overlays_control === false) next = {
|
|
2611
|
+
...next,
|
|
2612
|
+
withOverlaysControl: false
|
|
2613
|
+
};
|
|
2614
|
+
const cap = safetyRules.with_overlays;
|
|
2615
|
+
if (cap === void 0) return next;
|
|
2616
|
+
if (allowlistMode(cap, "cap") === "specific") {
|
|
2617
|
+
const unrestricted = allowlistUnrestricted(next.withOverlays);
|
|
2618
|
+
const offered = unrestricted ? [...cap] : next.withOverlays.filter((slug) => cap.includes(slug));
|
|
2619
|
+
if (offered.length > 0 && (unrestricted || offered.length !== next.withOverlays.length)) next = {
|
|
2620
|
+
...next,
|
|
2621
|
+
withOverlays: offered
|
|
2622
|
+
};
|
|
2623
|
+
}
|
|
2624
|
+
if (next.withLayersControl && !layersControlOffered(next, cap)) next = {
|
|
2625
|
+
...next,
|
|
2626
|
+
withLayersControl: false
|
|
2627
|
+
};
|
|
2628
|
+
return next;
|
|
2629
|
+
};
|
|
2630
|
+
const createPlatformViewer = ({ isPersonalScope = defaultStudioScope.isPersonalScope, memberships, personalSpace, scope, viewer }) => {
|
|
2631
|
+
const scopeOf = (organizationId) => organizationId === void 0 || organizationId === "" || isPersonalScope(organizationId) ? null : organizationId;
|
|
2632
|
+
const answerFor = (organizationId) => organizationId === null ? personalSpace?.read() : memberships.read()?.find((membership) => membership.organization_id === organizationId);
|
|
2633
|
+
return {
|
|
2634
|
+
getItineraryLimit: (organizationId) => answerFor(scopeOf(organizationId))?.itinerary_limit ?? null,
|
|
2635
|
+
getPreferences: () => viewer.getPreferences(),
|
|
2636
|
+
getUserId: () => viewer.getUserId(),
|
|
2637
|
+
hasEntitlement: (entitlement) => answerFor(scopeOf(scope.read()))?.studio_entitlements.includes(entitlement) ?? false,
|
|
2638
|
+
setPreferences: (partial) => viewer.setPreferences(partial),
|
|
2639
|
+
subscribe: (onChange) => {
|
|
2640
|
+
let inView = scopeOf(scope.read());
|
|
2641
|
+
const releases = [
|
|
2642
|
+
viewer.subscribe(onChange),
|
|
2643
|
+
memberships.subscribe(onChange),
|
|
2644
|
+
personalSpace?.subscribe(onChange),
|
|
2645
|
+
scope.subscribe(() => {
|
|
2646
|
+
const next = scopeOf(scope.read());
|
|
2647
|
+
if (next !== inView) {
|
|
2648
|
+
inView = next;
|
|
2649
|
+
onChange();
|
|
2650
|
+
}
|
|
2651
|
+
})
|
|
2652
|
+
];
|
|
2653
|
+
return () => {
|
|
2654
|
+
for (const release of releases) release?.();
|
|
2655
|
+
};
|
|
2656
|
+
}
|
|
2657
|
+
};
|
|
2658
|
+
};
|
|
2659
|
+
const nothingMirrored = {};
|
|
2660
|
+
const releaseNothing = () => {};
|
|
2661
|
+
const inertStudioUrlSeam = {
|
|
2662
|
+
read: () => nothingMirrored,
|
|
2663
|
+
readOnce: () => nothingMirrored,
|
|
2664
|
+
subscribe: () => releaseNothing,
|
|
2665
|
+
write: () => {}
|
|
2666
|
+
};
|
|
2667
|
+
const sameViewerValues = (a, b) => {
|
|
2668
|
+
for (const key of /* @__PURE__ */ new Set([...Object.keys(a), ...Object.keys(b)])) if (Reflect.get(a, key) !== Reflect.get(b, key)) return false;
|
|
2669
|
+
return true;
|
|
2670
|
+
};
|
|
2671
|
+
const inertViewer = /*#__PURE__*/ createStaticViewer();
|
|
2672
|
+
const mintRowId = (ids = studioSeamAbsences.ids) => ids.next();
|
|
2673
|
+
const shownMinutes = (seconds) => seconds == null ? null : Math.round(seconds / SECONDS_PER_MINUTE);
|
|
2674
|
+
const storedSeconds = (minutes) => minutes === null ? null : Math.round(minutes) * SECONDS_PER_MINUTE;
|
|
2675
|
+
const stopSeconds = (draft) => {
|
|
2676
|
+
const stored = draft.storedStopSeconds;
|
|
2677
|
+
return stored !== void 0 && shownMinutes(stored) === draft.stopMinutes ? stored : storedSeconds(draft.stopMinutes);
|
|
2678
|
+
};
|
|
2679
|
+
const cutoffInstant = (cutoffAt) => {
|
|
2680
|
+
if (cutoffAt === null) return null;
|
|
2681
|
+
if (Number.isNaN(cutoffAt.getTime())) throw new MountayaElementsError("patch waypoint details: the cut-off is no valid date. Set it to a date and a time, or clear it.");
|
|
2682
|
+
return cutoffAt.toISOString();
|
|
2683
|
+
};
|
|
2684
|
+
const text = (value) => value ?? "";
|
|
2685
|
+
const orNull$1 = (value) => {
|
|
2686
|
+
const trimmed = value.trim();
|
|
2687
|
+
return trimmed === "" ? null : trimmed;
|
|
2688
|
+
};
|
|
2689
|
+
const draftFromWaypoint = (waypoint) => ({
|
|
2690
|
+
...waypoint.timing?.stop_duration == null ? {} : { storedStopSeconds: waypoint.timing.stop_duration },
|
|
2691
|
+
address: text(waypoint.contact?.address),
|
|
2692
|
+
amenities: [...waypoint.amenities ?? []],
|
|
2693
|
+
bookingUrl: text(waypoint.contact?.booking_url),
|
|
2694
|
+
cutoffAt: waypoint.timing?.cutoff_at ?? null,
|
|
2695
|
+
email: text(waypoint.contact?.email),
|
|
2696
|
+
links: (waypoint.media?.links ?? []).map((link) => ({
|
|
2697
|
+
label: link.label,
|
|
2698
|
+
rowId: mintRowId(),
|
|
2699
|
+
url: link.url
|
|
2700
|
+
})),
|
|
2701
|
+
openingHours: text(waypoint.contact?.opening_hours),
|
|
2702
|
+
phone: text(waypoint.contact?.phone),
|
|
2703
|
+
photos: (waypoint.media?.photos ?? []).map((photo) => ({
|
|
2704
|
+
caption: text(photo.caption),
|
|
2705
|
+
rowId: mintRowId(),
|
|
2706
|
+
url: photo.url
|
|
2707
|
+
})),
|
|
2708
|
+
properties: (waypoint.properties ?? []).map((property) => ({
|
|
2709
|
+
format: property.format ?? "text",
|
|
2710
|
+
key: property.key,
|
|
2711
|
+
label: property.label,
|
|
2712
|
+
rowId: mintRowId(),
|
|
2713
|
+
value: property.value
|
|
2714
|
+
})),
|
|
2715
|
+
stopMinutes: shownMinutes(waypoint.timing?.stop_duration),
|
|
2716
|
+
website: text(waypoint.contact?.website)
|
|
2717
|
+
});
|
|
2718
|
+
const patchFromDraft = (draft) => {
|
|
2719
|
+
const timing = {
|
|
2720
|
+
cutoff_at: cutoffInstant(draft.cutoffAt),
|
|
2721
|
+
stop_duration: stopSeconds(draft)
|
|
2722
|
+
};
|
|
2723
|
+
const contact = {
|
|
2724
|
+
address: orNull$1(draft.address),
|
|
2725
|
+
booking_url: orNull$1(draft.bookingUrl),
|
|
2726
|
+
email: orNull$1(draft.email),
|
|
2727
|
+
opening_hours: orNull$1(draft.openingHours),
|
|
2728
|
+
phone: orNull$1(draft.phone),
|
|
2729
|
+
website: orNull$1(draft.website)
|
|
2730
|
+
};
|
|
2731
|
+
const photos = draft.photos.filter((photo) => photo.url.trim() !== "").map((photo) => ({
|
|
2732
|
+
caption: orNull$1(photo.caption),
|
|
2733
|
+
url: photo.url.trim()
|
|
2734
|
+
}));
|
|
2735
|
+
const links = draft.links.filter((link) => link.label.trim() !== "" && link.url.trim() !== "").map((link) => ({
|
|
2736
|
+
label: link.label.trim(),
|
|
2737
|
+
url: link.url.trim()
|
|
2738
|
+
}));
|
|
2739
|
+
const properties = draft.properties.filter((property) => property.key.trim() !== "" && property.label.trim() !== "").map((property) => ({
|
|
2740
|
+
format: property.format,
|
|
2741
|
+
key: property.key.trim(),
|
|
2742
|
+
label: property.label.trim(),
|
|
2743
|
+
value: property.value.trim()
|
|
2744
|
+
}));
|
|
2745
|
+
const media = {
|
|
2746
|
+
links,
|
|
2747
|
+
photos
|
|
2748
|
+
};
|
|
2749
|
+
return {
|
|
2750
|
+
amenities: draft.amenities,
|
|
2751
|
+
contact: Object.values(contact).every((value) => value === null) ? null : contact,
|
|
2752
|
+
media: links.length === 0 && photos.length === 0 ? null : media,
|
|
2753
|
+
properties: properties.length === 0 ? null : properties,
|
|
2754
|
+
timing: Object.values(timing).every((value) => value === null) ? null : timing
|
|
2755
|
+
};
|
|
2756
|
+
};
|
|
2757
|
+
const nextPropertyKey = (properties) => {
|
|
2758
|
+
const taken = new Set(properties.map((property) => property.key));
|
|
2759
|
+
let index = properties.length + 1;
|
|
2760
|
+
while (taken.has(`field-${index}`)) index += 1;
|
|
2761
|
+
return `field-${index}`;
|
|
2762
|
+
};
|
|
2763
|
+
const previewWaypoint = (waypoint, fields) => {
|
|
2764
|
+
const patch = patchFromDraft(fields.draft);
|
|
2765
|
+
const description = fields.description.trim();
|
|
2766
|
+
const name = fields.name.trim();
|
|
2767
|
+
return {
|
|
2768
|
+
...waypoint,
|
|
2769
|
+
amenities: patch.amenities ?? [],
|
|
2770
|
+
color: fields.color,
|
|
2771
|
+
contact: patch.contact ?? null,
|
|
2772
|
+
description: description === "" ? null : description,
|
|
2773
|
+
icon: fields.icon,
|
|
2774
|
+
media: patch.media ?? null,
|
|
2775
|
+
name: name === "" ? null : name,
|
|
2776
|
+
properties: patch.properties ?? null,
|
|
2777
|
+
timing: patch.timing == null ? null : {
|
|
2778
|
+
...patch.timing,
|
|
2779
|
+
cutoff_at: fields.draft.cutoffAt
|
|
2780
|
+
}
|
|
2781
|
+
};
|
|
2782
|
+
};
|
|
2783
|
+
const waypointDetailsForm = (waypoint) => {
|
|
2784
|
+
const fields = {
|
|
2785
|
+
color: waypoint.color ?? DEFAULT_WAYPOINT_COLOR,
|
|
2786
|
+
description: waypoint.description ?? "",
|
|
2787
|
+
details: draftFromWaypoint(waypoint),
|
|
2788
|
+
icon: waypoint.icon,
|
|
2789
|
+
name: waypoint.name ?? ""
|
|
2790
|
+
};
|
|
2791
|
+
return {
|
|
2792
|
+
...fields,
|
|
2793
|
+
opened: fields
|
|
2794
|
+
};
|
|
2795
|
+
};
|
|
2796
|
+
const filledAndRefused = (value, accepts) => value.trim() !== "" && !accepts(value.trim());
|
|
2797
|
+
const detailsRefusal = (details) => {
|
|
2798
|
+
if (filledAndRefused(details.phone, isWaypointPhone)) return "phoneInvalid";
|
|
2799
|
+
if (filledAndRefused(details.email, isWaypointEmail)) return "emailInvalid";
|
|
2800
|
+
if ([
|
|
2801
|
+
details.website,
|
|
2802
|
+
details.bookingUrl,
|
|
2803
|
+
...details.photos.map((photo) => photo.url),
|
|
2804
|
+
...details.links.map((link) => link.url)
|
|
2805
|
+
].some((address) => filledAndRefused(address, isWaypointWebUrl))) return "urlInvalid";
|
|
2806
|
+
if (details.properties.some((property) => filledAndRefused(property.key, isWaypointPropertyKey))) return "keyInvalid";
|
|
2807
|
+
return details.properties.some((property) => !waypointPropertyValueMatchesFormat(property.value, property.format)) ? "valueFormatInvalid" : null;
|
|
2808
|
+
};
|
|
2809
|
+
const formRefusal = (form) => {
|
|
2810
|
+
const name = form.name.trim();
|
|
2811
|
+
if (name !== "" && !displayNameSchema.safeParse(name).success) return "nameInvalid";
|
|
2812
|
+
if (!descriptionSchema.safeParse(form.description).success) return "descriptionInvalid";
|
|
2813
|
+
return detailsRefusal(form.details);
|
|
2814
|
+
};
|
|
2815
|
+
const DETAILS_MEMBERS = [
|
|
2816
|
+
"amenities",
|
|
2817
|
+
"contact",
|
|
2818
|
+
"media",
|
|
2819
|
+
"properties",
|
|
2820
|
+
"timing"
|
|
2821
|
+
];
|
|
2822
|
+
const openedPatches = /* @__PURE__ */ new WeakMap();
|
|
2823
|
+
const openedPatch = (draft) => {
|
|
2824
|
+
const held = openedPatches.get(draft);
|
|
2825
|
+
if (held !== void 0) return held;
|
|
2826
|
+
const patch = patchFromDraft(draft);
|
|
2827
|
+
openedPatches.set(draft, patch);
|
|
2828
|
+
return patch;
|
|
2829
|
+
};
|
|
2830
|
+
const orNull = (value) => {
|
|
2831
|
+
const trimmed = value.trim();
|
|
2832
|
+
return trimmed === "" ? null : trimmed;
|
|
2833
|
+
};
|
|
2834
|
+
const waypointSavePlan = (itineraryId, waypoint, form) => {
|
|
2835
|
+
const subject = {
|
|
2836
|
+
itineraryId,
|
|
2837
|
+
waypointId: waypoint.id
|
|
2838
|
+
};
|
|
2839
|
+
const { opened } = form;
|
|
2840
|
+
const name = form.name.trim();
|
|
2841
|
+
const openedName = opened.name.trim();
|
|
2842
|
+
const nameMoved = name === "" ? waypoint.mode === "point" && openedName !== "" : name !== openedName;
|
|
2843
|
+
const icon = userWaypointIconSchema.safeParse(form.icon);
|
|
2844
|
+
const iconMoved = icon.success && icon.data !== opened.icon;
|
|
2845
|
+
const colorMoved = form.color !== opened.color;
|
|
2846
|
+
const descriptionMoved = form.description.trim() !== opened.description.trim();
|
|
2847
|
+
const patch = patchFromDraft(form.details);
|
|
2848
|
+
const baseline = openedPatch(opened.details);
|
|
2849
|
+
const movedDetails = DETAILS_MEMBERS.filter((member) => JSON.stringify(patch[member]) !== JSON.stringify(baseline[member]));
|
|
2850
|
+
const detailsMoved = descriptionMoved || movedDetails.length > 0;
|
|
2851
|
+
const changed = nameMoved || iconMoved || colorMoved || detailsMoved;
|
|
2852
|
+
const refusal = formRefusal(form);
|
|
2853
|
+
if (refusal !== null) return {
|
|
2854
|
+
changed,
|
|
2855
|
+
refusal,
|
|
2856
|
+
steps: []
|
|
2857
|
+
};
|
|
2858
|
+
const details = detailsMoved ? {
|
|
2859
|
+
input: {
|
|
2860
|
+
...movedDetails.includes("amenities") ? { amenities: patch.amenities } : {},
|
|
2861
|
+
...movedDetails.includes("contact") ? { contact: patch.contact } : {},
|
|
2862
|
+
...movedDetails.includes("media") ? { media: patch.media } : {},
|
|
2863
|
+
...movedDetails.includes("properties") ? { properties: patch.properties } : {},
|
|
2864
|
+
...movedDetails.includes("timing") ? { timing: patch.timing } : {},
|
|
2865
|
+
...subject,
|
|
2866
|
+
...descriptionMoved ? { description: orNull(form.description) } : {}
|
|
2867
|
+
},
|
|
2868
|
+
name: "studio.itinerary.waypoint.setDetails"
|
|
2869
|
+
} : null;
|
|
2870
|
+
const accepted = details === null || itineraryWaypointsToolContracts["studio.itinerary.waypoint.setDetails"].input.safeParse(details.input).success;
|
|
2871
|
+
if (details !== null && !accepted) return {
|
|
2872
|
+
changed,
|
|
2873
|
+
refusal,
|
|
2874
|
+
steps: [details]
|
|
2875
|
+
};
|
|
2876
|
+
const steps = [];
|
|
2877
|
+
if (nameMoved) steps.push({
|
|
2878
|
+
input: {
|
|
2879
|
+
...subject,
|
|
2880
|
+
name: name === "" ? null : name
|
|
2881
|
+
},
|
|
2882
|
+
name: "studio.itinerary.waypoint.rename"
|
|
2883
|
+
});
|
|
2884
|
+
if (iconMoved) steps.push({
|
|
2885
|
+
input: {
|
|
2886
|
+
...subject,
|
|
2887
|
+
icon: icon.data
|
|
2888
|
+
},
|
|
2889
|
+
name: "studio.itinerary.waypoint.setIcon"
|
|
2890
|
+
});
|
|
2891
|
+
if (colorMoved) steps.push({
|
|
2892
|
+
input: {
|
|
2893
|
+
...subject,
|
|
2894
|
+
color: form.color
|
|
2895
|
+
},
|
|
2896
|
+
name: "studio.itinerary.waypoint.recolor"
|
|
2897
|
+
});
|
|
2898
|
+
if (details !== null) steps.push(details);
|
|
2899
|
+
return {
|
|
2900
|
+
changed,
|
|
2901
|
+
refusal,
|
|
2902
|
+
steps
|
|
2903
|
+
};
|
|
2904
|
+
};
|
|
2905
|
+
const substituteLiveWaypoint = (waypoints, session, itineraryId) => {
|
|
2906
|
+
if (session === null) return waypoints;
|
|
2907
|
+
const { draft, waypointId } = session;
|
|
2908
|
+
const name = draft.name === "" ? null : draft.name;
|
|
2909
|
+
const index = waypoints.findIndex((waypoint) => waypoint.id === waypointId);
|
|
2910
|
+
const saved = waypoints[index];
|
|
2911
|
+
if (saved === void 0) return session.intent === "create" ? [...waypoints, synthesizeDraftWaypoint({
|
|
2912
|
+
draft: {
|
|
2913
|
+
color: draft.color,
|
|
2914
|
+
icon: draft.icon,
|
|
2915
|
+
lngLat: draft.lngLat,
|
|
2916
|
+
name
|
|
2917
|
+
},
|
|
2918
|
+
itineraryId,
|
|
2919
|
+
waypointId
|
|
2920
|
+
})] : waypoints;
|
|
2921
|
+
const savedPoint = saved.geojson?.type === "Point" ? saved.geojson.coordinates : null;
|
|
2922
|
+
const moved = draft.lngLat !== null && (savedPoint === null || savedPoint[0] !== draft.lngLat[0] || savedPoint[1] !== draft.lngLat[1]);
|
|
2923
|
+
const live = {
|
|
2924
|
+
...saved,
|
|
2925
|
+
color: draft.color,
|
|
2926
|
+
geojson: moved && draft.lngLat !== null ? {
|
|
2927
|
+
coordinates: [draft.lngLat[0], draft.lngLat[1]],
|
|
2928
|
+
type: "Point"
|
|
2929
|
+
} : saved.geojson,
|
|
2930
|
+
icon: draft.icon,
|
|
2931
|
+
name
|
|
2932
|
+
};
|
|
2933
|
+
return waypoints.map((waypoint, at) => at === index ? live : waypoint);
|
|
2934
|
+
};
|
|
2935
|
+
const defaultWaypointName = (label, occurrence) => `${label} #${occurrence}`;
|
|
2936
|
+
const iconOf = (icon) => icon ?? DEFAULT_WAYPOINT_ICON;
|
|
2937
|
+
const waypointIconOccurrence = (waypoints, index) => {
|
|
2938
|
+
const entry = waypoints[index];
|
|
2939
|
+
if (entry === void 0) return 0;
|
|
2940
|
+
const target = iconOf(entry.icon);
|
|
2941
|
+
let occurrence = 0;
|
|
2942
|
+
for (let position = 0; position <= index; position += 1) {
|
|
2943
|
+
const candidate = waypoints[position];
|
|
2944
|
+
if (candidate !== void 0 && iconOf(candidate.icon) === target) occurrence += 1;
|
|
2945
|
+
}
|
|
2946
|
+
return occurrence;
|
|
2947
|
+
};
|
|
2948
|
+
const waypointIconLabel = (icon, names) => names[iconOf(icon)];
|
|
2949
|
+
const waypointDefaultName = (waypoints, index, names, icon = waypoints[index]?.icon) => {
|
|
2950
|
+
if (icon === waypoints[index]?.icon) return defaultWaypointName(waypointIconLabel(icon, names), waypointIconOccurrence(waypoints, index));
|
|
2951
|
+
const target = iconOf(icon);
|
|
2952
|
+
const before = waypoints.slice(0, Math.max(0, index)).filter((waypoint) => iconOf(waypoint.icon) === target).length;
|
|
2953
|
+
return defaultWaypointName(waypointIconLabel(icon, names), before + 1);
|
|
2954
|
+
};
|
|
2955
|
+
const waypointDefaultNames = (waypoints, names) => {
|
|
2956
|
+
const counts = /* @__PURE__ */ new Map();
|
|
2957
|
+
return waypoints.map((waypoint) => {
|
|
2958
|
+
const icon = iconOf(waypoint.icon);
|
|
2959
|
+
const occurrence = (counts.get(icon) ?? 0) + 1;
|
|
2960
|
+
counts.set(icon, occurrence);
|
|
2961
|
+
return defaultWaypointName(waypointIconLabel(icon, names), occurrence);
|
|
2962
|
+
});
|
|
2963
|
+
};
|
|
2964
|
+
const nextWaypointDefaultName = (saved, icon, names) => defaultWaypointName(waypointIconLabel(icon, names), saved.filter((waypoint) => iconOf(waypoint.icon) === iconOf(icon)).length + 1);
|
|
2965
|
+
const resolveWaypointName = (name, defaultName) => name !== null && name !== "" ? name : defaultName;
|
|
2966
|
+
const WAYPOINT_SECTIONS = [
|
|
2967
|
+
{
|
|
2968
|
+
glyph: "appearance",
|
|
2969
|
+
id: "appearance"
|
|
2970
|
+
},
|
|
2971
|
+
{
|
|
2972
|
+
glyph: "amenities",
|
|
2973
|
+
id: "amenities"
|
|
2974
|
+
},
|
|
2975
|
+
{
|
|
2976
|
+
glyph: "timing",
|
|
2977
|
+
id: "timing"
|
|
2978
|
+
},
|
|
2979
|
+
{
|
|
2980
|
+
glyph: "contact",
|
|
2981
|
+
id: "contact"
|
|
2982
|
+
},
|
|
2983
|
+
{
|
|
2984
|
+
glyph: "media",
|
|
2985
|
+
id: "media"
|
|
2986
|
+
},
|
|
2987
|
+
{
|
|
2988
|
+
glyph: "properties",
|
|
2989
|
+
id: "properties"
|
|
2990
|
+
}
|
|
2991
|
+
];
|
|
2992
|
+
const waypointSectionLabel = (words, id) => {
|
|
2993
|
+
const copy = words.waypointDetails;
|
|
2994
|
+
switch (id) {
|
|
2995
|
+
case "amenities": return copy.amenitiesSection;
|
|
2996
|
+
case "appearance": return copy.appearanceSection;
|
|
2997
|
+
case "contact": return copy.contactSection;
|
|
2998
|
+
case "media": return copy.mediaSection;
|
|
2999
|
+
case "properties": return copy.propertiesSection;
|
|
3000
|
+
case "timing": return copy.timingSection;
|
|
3001
|
+
}
|
|
3002
|
+
};
|
|
3003
|
+
const recordWaypointDraftChange = (bus, context, change) => {
|
|
3004
|
+
const state = context.ui.getState();
|
|
3005
|
+
const waypointId = state.waypointEditSession?.waypointId;
|
|
3006
|
+
if (waypointId === void 0) return "drop";
|
|
3007
|
+
const disposition = draftChangeDisposition({
|
|
3008
|
+
agentDriving: state.agentDriving,
|
|
3009
|
+
programmatic: false
|
|
3010
|
+
});
|
|
3011
|
+
if (disposition !== "record") return disposition;
|
|
3012
|
+
Promise.resolve(bus.dispatch(context, "studio.itinerary.waypoint.editSetPosition", {
|
|
3013
|
+
lngLat: change.lngLat,
|
|
3014
|
+
poiSeed: change.poiSeed,
|
|
3015
|
+
waypointId
|
|
3016
|
+
})).then(void 0, () => {});
|
|
3017
|
+
return disposition;
|
|
3018
|
+
};
|
|
3019
|
+
const recordZoneDraftChange = (ui, draft) => {
|
|
3020
|
+
const state = ui.getState();
|
|
3021
|
+
const disposition = draftChangeDisposition({
|
|
3022
|
+
agentDriving: state.agentDriving,
|
|
3023
|
+
programmatic: draft.programmatic
|
|
3024
|
+
});
|
|
3025
|
+
if (disposition !== "record") return disposition;
|
|
3026
|
+
const geometry = wrapZoneGeometryPastRange(draft.geometry);
|
|
3027
|
+
if (draft.phase === "live") state.setZoneEditLiveDraft(geometry);
|
|
3028
|
+
else state.pushZoneDraft(geometry);
|
|
3029
|
+
return disposition;
|
|
3030
|
+
};
|
|
3031
|
+
export { AGENT_PANEL_SEARCH_KEYS, CAMERA_MESSAGE, COLLAB_PEER_COLORS, DEFAULT_ENABLED_POI_GROUP_IDS, DEFAULT_HOLD_MS, DEFAULT_SHOT_PITCH_DEG, DEFAULT_SHOT_ZOOM, DEFAULT_TERRAIN, DEFAULT_ZONE_CREATE_METHOD, DEFAULT_ZONE_LEVEL, DEFAULT_ZONE_MODE, DESCRIPTION_MAX_LENGTH, DISPLAY_NAME_MAX_LENGTH, DISPLAY_NAME_MIN_LENGTH, DUPLICATE_SEGMENT_IDS_MAX, DUPLICATE_WAYPOINT_IDS_MAX, EMBED_CONFIG_FIELDS, EMBED_COVER_MAX_MS, EMBED_ELEMENTS, EMBED_IFRAME_RADIUS_PX, EMBED_SECTION_ORDER, EMBED_SEGMENT_TABLE_COLUMNS, EMBED_SESSION_ENDPOINT, EMBED_TABLE_INSTALL_COMMAND, EMBED_WAYPOINT_TABLE_COLUMNS, EMPTY_SEGMENTS, EXPORT_FORMATS, EXPORT_VARIANTS, HILLSHADE_OVERLAY_SLUG, IMPORT_FILE_FORMATS, IMPORT_FILE_MAX_SIZE, ITINERARY_FIT_MAX_ZOOM, MAP_STATE_SEARCH_KEYS, POIS_OVERLAY_SLUG, POI_GROUPS, POI_GROUP_COUNT, POI_GROUP_IDS, PREVIEW_PLAN_REFRESH_DEBOUNCE_MS, REACHABILITY_GLYPH, READY_MESSAGE, REQUEST_CAMERA_MESSAGE, REQUEST_SESSION_TOKEN_MESSAGE, SET_ITINERARY_MESSAGE, SET_SESSION_TOKEN_MESSAGE, SOCIAL_SHARE_TARGETS, SPLIT_MIN_END_DISTANCE_METERS, SPLIT_PICK_TOLERANCE_PX, SUGGESTION_MAX_KEPT, SUGGESTION_TARGET_COUNT, StudioPersistenceRefusedError, TIME_OFFSET_MAX_MINUTES, TIME_OFFSET_MIN_MINUTES, TIME_WINDOW_FUTURE_HOURS, TIME_WINDOW_PAST_HOURS, ToolBus, VIDEO_STEP_ORDER, WAYPOINT_SECTIONS, ZONE_PREVIEW_DEBOUNCE_MS, ZONE_TIME_REFERENCE_INTERVAL_MS, activeSegmentLines, activeStudioScope, activityForId, agentHandoffTarget, allowlistForMode, allowlistMode, allowlistUnrestricted, applyEmbedOverrides, availableEnginesForActivity, beginDraftSegmentEdit, buildEmbedIframe, buildEmbedSearch, buildEmbedSessionScript, buildEmbedSrc, buildEmbedTableCode, buildEmbedViewHash, buildExportFilename, buildReadyPayload, buildSegmentChainMerges, buildSegmentEditCommitInput, buildSegmentEditOptions, buildSegmentGroupRuns, buildShareSearch, buildShareSrc, buildShareText, buildShareViewConfig, buildVideoSnapshot, cameraBearingModeSchema, cameraFpsSchema, cameraMessageSchema, cameraModeSchema, cameraOutputBaseSchema, cameraOutputFormatSchema, cameraOutputSchema, cameraPlanSchema, cameraResolutionSchema, cameraShotBaseSchema, cameraShotSchema, canDeleteCollection, canEditCollection, canEditCollectionMetadata, canEditItinerary, canEditOwnedResource, clampConfigToAllowlists, clampConfigToFieldDependencies, clampConfigToSafetyRules, clampEmbedConfigToSecurity, clampSeedPoint, clampStudioConfigToSafetyRules, classicOverlays, climbCategorySchema, codeForThrown, collabLockEntrySchema, collabLockKey, collabLockKindSchema, collabPeerColor, collabPeerColorIndex, collabPresencePeerSchema, collabResourceKey, collabResourceKindSchema, collabResourceSchema, collectAttributions, collectionCreateScope, collectionFormSchema, collectionsTargetSchema, confirmationToneSchema, contextMenuReadout, contextMenuSchema, contextMenuZoneSchema, contiguousRunBounds, createFormChanged, createMemoryViewer, createPlatformViewer, createSearchFetch, createStaticViewer, createUiStore, createVideoDirectorStore, defaultEmbedTableOptions, defaultEngineForActivity, defaultSegmentGroupName, defaultSegmentName, defaultSpeedForActivity, defaultStudioConfig, defaultStudioScope, defaultVideoExportProfile, defaultWaypointName, defineRegistry, describeInvalidInput, descriptionSchema, destinationPoint, detectFileProvider, directionsTargetSchema, displayNameSchema, displaySeedDispatches, draftActivityInput, draftChangeDisposition, draftCollectionsInput, draftFromWaypoint, draftGeometries, draftNameInput, draftOrganizationInput, draftPositionCount, draftPrivateInput, drawnByItinerary, editHijacksNativeShortcut, editKeyIntent, editShortcuts, editToolName, editingCollectionSchema, editorItineraryView, embedAuthSearchSchema, embedConfigSchema, embedConfigSearchSchema, embedConfigToStudioConfig, embedConstraintsFor, embedElementSectionFields, embedElementSections, embedElementSupportsField, embedFieldDependencies, embedLayerOptions, embedSearchSchema, embedSectionChanges, embedSectionFieldKeys, embedTableChanges, embedTableColumns, embedThemeSchema, embedUiBaseline, enrichmentOverlays, enumFieldOptions, exceedsMergeViaCeiling, exportExtension, exportFileStem, exportFormatVariants, exportTargetSchema, extractOverlayBand, failureFromThrown, featureHitSchema, fieldDependenciesUnmet, filterEnrichmentOverlays, filterOverlayCategories, filterTerrains, findHillshadeOverlay, firstActivityId, firstSegmentEditInput, fitDisplayName, generateFriendlyName, hexColorSchema, importDropzoneAccept, importReasonSentence, importSegmentCounts, importWarningSentence, inboundBridgeMessageSchema, inertStudioUrlSeam, inertViewer, isConfirmationWithheld, isContiguousRun, isDefaultSegmentName, isEmbedTableElement, isFieldRestricted, isLoopbackDomain, isPublishableScope, isRetryableShareLinkFailure, isShareLinkDisableSettled, isStudioSessionToken, isWaypointEmail, isWaypointPhone, isWaypointPropertyKey, isWaypointWebUrl, isZoneMetadataDirty, isZoneWorkUnsaved, itineraryCeiling, itineraryClickTarget, itineraryEmphasisFor, itineraryLayerIdsOf, itinerarySpriteIcons, itineraryTileFeature, languageSchema, lateBoundTools, layerToolContext, layersControlOffered, localStudioPersistence, makeWaypointId, mapAlertSchema, mapBoundsSchema, mapInteractionScope, mapStateShape, memoryStudioPersistence, mintRowId, nextPropertyKey, nextWaypointDefaultName, normalizeDefaultProps, overlayFeatureSchema, overlayInstant, overlayReadoutFor, overlaySampleResultSchema, overlaysOffered, patchFromDraft, peerDraftGhosts, peerSegmentDraftsOf, permittedClassicOverlay, permittedEnrichmentOverlays, persistedItineraryView, poiGroupIdSchema, poiGroupSchema, poiInfoSchema, poiLayerVisibility, pointAtFraction, previewProjection, previewRefreshDisposition, previewWaypoint, profileCursorReadout, profileDesignSchema, profileMarkerIcon, profileSheetSnapSchema, profileSourceSchema, projectEntityCollections, projectOnSegment, qualitySchema, readyErrorSchema, readyMessageSchema, recordWaypointDraftChange, recordZoneDraftChange, registerStudioTools, renumber, renumberDefaultSegments, requestCameraMessageSchema, requestSessionTokenMessageSchema, requireWritableScope, resolveActivity, resolveBaseTerrain, resolveDemUrl, resolveEmbedConfig, resolveEmbedDefaults, resolveFramedError, resolveOrgEmbedDefaults, resolveViewerUnits, resolveWaypointName, restStatusCodes, restStudioPersistence, routeGeometrySchema, routeHazardConfirmation, routeProfilePointSchema, sameViewerValues, sectionDefaultPropsFields, sectionFields, seedFromCoordinates, seedFromPersistedSegment, segmentChainEnds, segmentEditModeSchema, segmentEditTooltipContent, segmentGroupDissolvesOnLeave, segmentGroupEditTargetSchema, segmentGroupForm, segmentGroupSavePlan, segmentInsertAnchorSchema, segmentLengthMeters, segmentSpanSchema, segmentSplitPickSchema, segmentsColorSchema, selectActiveDraft, selectActiveDraftSession, selectActiveEditEngine, selectAgentEntityLocked, selectAgentHandoffArmed, selectBaseMapLocked, selectCollabLockHolder, selectCollabLockHolderIds, selectCollabPeerDrafts, selectCollabPeers, selectDirecting, selectDirections, selectEditDirtyTick, selectEditorTakenBy, selectEmbed, selectEmbedContent, selectImportSession, selectProfilePaceKmh, selectProfileSheetSnap, selectSegmentGroupEdit, selectSegmentSplitPick, selectSegmentViaPrompt, selectSelectedSuggestionCandidate, selectShare, selectSuggestionSession, selectUnsavedWork, selectVideoExport, selectVideoExportPlan, selectVideoExportRoute, selectVideoExportStatus, selectWaypointDetails, selectZoneCreateSetup, selectZoneEditDirty, selectedCandidate, sessionTokenSurface, setSessionTokenMessageSchema, shareLinkActions, shareLinkScope, shareLinkTargetSchema, shareSearchSchema, simplifyToVias, splitPickVerdict, splitSegmentNames, streetviewPositionSchema, studioAlertCodeSchema, studioCapabilitySchema, studioCollabTools, studioConfigSchema, studioContentSchema, studioEntitlementSchema, studioMapStateSearchSchema, studioModalSchema, studioPanelSchema, studioRegistry, studioToolContracts, substituteLiveSegment, substituteLiveWaypoint, suggestRouteTypeSchema, switchOverridesSchema, synthesizeDraftSegment, synthesizeDraftWaypoint, terrainVariantOptions, terrainVariantSchema, themeSchema, timeSliderWindow, timestampedSources, toggleEmbedTableColumn, toggleableSegmentIds, toolCapabilitySchema, toolConfirmationSchema, toolErrorCodeSchema, toolNoDataSchema, truncateKey, unitLengthSchema, unitPaceSchema, unitSlopeSchema, unitTemperatureSchema, urlBoolean, userWaypointIconSchema, videoExportProfileSchema, videoExportSchema, videoExportStatusSchema, videoPresetSchema, videoProfileSource, videoRouteSpans, videoSnapshotSchema, waypointAmenitySchema, waypointDefaultName, waypointDefaultNames, waypointDetailLimits, waypointDetailsForm, waypointDraftSchema, waypointEditIntentSchema, waypointEditModeSchema, waypointEditTooltipText, waypointIconLabel, waypointIconOccurrence, waypointIconSchema, waypointPoiSeedSchema, waypointPropertyFormatSchema, waypointPropertyValueMatchesFormat, waypointSavePlan, waypointSectionLabel, withItineraryAnalysis, wrapZoneGeometryPastRange, zoneAutoName, zoneCircleGeometry, zoneCircleParamsSchema, zoneClickTarget, zoneCreateMethodSchema, zoneDescriptionSchema, zoneEditBeginSchema, zoneEditLevelSchema, zoneEditModeSchema, zoneEditTooltipText, zoneNameSchema, zonePreviewQueryKey, zoneReachPole, zoneSaveRequest, zoneSectorGeometry, zoneSectorParamsSchema, zoneSensorGeometry, zoneSensorParamsSchema, zoneTimeReferenceSeconds };
|
|
3032
|
+
|
|
3033
|
+
//# sourceMappingURL=index.js.map
|