mirror of
https://github.com/gpxstudio/gpx.studio.git
synced 2026-11-30 09:34:29 +00:00
Compare commits
10
Commits
fbfdc1933c
...
tauri
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8d878fb0e1 | ||
|
|
972510bfbc | ||
|
|
46563ef283 | ||
|
|
c778766293 | ||
|
|
fbd8775528 | ||
|
|
b3fe640575 | ||
|
|
c3ace59527 | ||
|
|
50348e7c5c | ||
|
|
c3ce577e6d | ||
|
|
957f0c35ec |
No files matched your search
@@ -0,0 +1,67 @@
|
|||||||
|
name: Deploy to Cloudflare Pages
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: 'dev'
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
concurrency:
|
||||||
|
group: cloudflare-${{ github.ref }}
|
||||||
|
cancel-in-progress: true
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
deploy:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
deployments: write
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v5
|
||||||
|
|
||||||
|
- name: Install Node.js
|
||||||
|
uses: actions/setup-node@v6
|
||||||
|
with:
|
||||||
|
node-version: 24
|
||||||
|
cache: npm
|
||||||
|
cache-dependency-path: website/package-lock.json
|
||||||
|
|
||||||
|
- name: Install Rust
|
||||||
|
uses: dtolnay/rust-toolchain@stable
|
||||||
|
with:
|
||||||
|
targets: wasm32-unknown-unknown
|
||||||
|
|
||||||
|
- name: Install wasm-pack
|
||||||
|
uses: taiki-e/install-action@v2
|
||||||
|
with:
|
||||||
|
tool: wasm-pack
|
||||||
|
|
||||||
|
- name: Test gpx-rs
|
||||||
|
run: cargo test
|
||||||
|
|
||||||
|
- name: Build wasm
|
||||||
|
run: wasm-pack build --target bundler
|
||||||
|
working-directory: wasm
|
||||||
|
|
||||||
|
- name: Install dependencies for website
|
||||||
|
run: npm install --prefix website
|
||||||
|
|
||||||
|
- name: Test website
|
||||||
|
run: npm test --prefix website
|
||||||
|
|
||||||
|
- name: Create env file
|
||||||
|
run: echo PUBLIC_MAPTILER_KEY=${{ secrets.PUBLIC_MAPTILER_KEY }} >> website/.env
|
||||||
|
|
||||||
|
- name: Build website
|
||||||
|
env:
|
||||||
|
BASE_PATH: ''
|
||||||
|
run: npm run build --prefix website
|
||||||
|
|
||||||
|
- name: Deploy to Cloudflare Pages
|
||||||
|
uses: cloudflare/wrangler-action@v3
|
||||||
|
with:
|
||||||
|
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
|
||||||
|
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
|
||||||
|
command: pages deploy website/build --project-name=${{ vars.CLOUDFLARE_PROJECT_NAME || 'gpxstudio' }} --branch=${{ github.ref_name }}
|
||||||
|
gitHubToken: ${{ secrets.GITHUB_TOKEN }}
|
||||||
Generated
+6
-2
@@ -20,7 +20,7 @@
|
|||||||
"mapillary-js": "^4.1.2",
|
"mapillary-js": "^4.1.2",
|
||||||
"maplibre-gl": "^6.15.0",
|
"maplibre-gl": "^6.15.0",
|
||||||
"sanitize-html": "^2.17.0",
|
"sanitize-html": "^2.17.0",
|
||||||
"sortablejs": "^1.15.6"
|
"sortablejs": "^1.15.7"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@fontsource-variable/inter": "^5.2.8",
|
"@fontsource-variable/inter": "^5.2.8",
|
||||||
@@ -39,7 +39,7 @@
|
|||||||
"@types/mapbox__tilebelt": "^1.0.4",
|
"@types/mapbox__tilebelt": "^1.0.4",
|
||||||
"@types/node": "^22.15.30",
|
"@types/node": "^22.15.30",
|
||||||
"@types/sanitize-html": "^2.16.0",
|
"@types/sanitize-html": "^2.16.0",
|
||||||
"@types/sortablejs": "^1.15.8",
|
"@types/sortablejs": "^1.15.9",
|
||||||
"@typescript-eslint/eslint-plugin": "^8.33.1",
|
"@typescript-eslint/eslint-plugin": "^8.33.1",
|
||||||
"@typescript-eslint/parser": "^8.33.1",
|
"@typescript-eslint/parser": "^8.33.1",
|
||||||
"bits-ui": "^2.17.2",
|
"bits-ui": "^2.17.2",
|
||||||
@@ -2762,6 +2762,8 @@
|
|||||||
},
|
},
|
||||||
"node_modules/@types/sortablejs": {
|
"node_modules/@types/sortablejs": {
|
||||||
"version": "1.15.9",
|
"version": "1.15.9",
|
||||||
|
"resolved": "https://registry.npmjs.org/@types/sortablejs/-/sortablejs-1.15.9.tgz",
|
||||||
|
"integrity": "sha512-7HP+rZGE2p886PKV9c9OJzLBI6BBJu1O7lJGYnPyG3fS4/duUCcngkNCjsLwIMV+WMqANe3tt4irrXHSIe68OQ==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
},
|
},
|
||||||
@@ -5599,6 +5601,8 @@
|
|||||||
},
|
},
|
||||||
"node_modules/sortablejs": {
|
"node_modules/sortablejs": {
|
||||||
"version": "1.15.7",
|
"version": "1.15.7",
|
||||||
|
"resolved": "https://registry.npmjs.org/sortablejs/-/sortablejs-1.15.7.tgz",
|
||||||
|
"integrity": "sha512-Kk8wLQPlS+yi1ZEf48a4+fzHa4yxjC30M/Sr2AnQu+f/MPwvvX9XjZ6OWejiz8crBsLwSq8GHqaxaET7u6ux0A==",
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
},
|
},
|
||||||
"node_modules/source-map-js": {
|
"node_modules/source-map-js": {
|
||||||
|
|||||||
@@ -33,7 +33,7 @@
|
|||||||
"@types/mapbox__tilebelt": "^1.0.4",
|
"@types/mapbox__tilebelt": "^1.0.4",
|
||||||
"@types/node": "^22.15.30",
|
"@types/node": "^22.15.30",
|
||||||
"@types/sanitize-html": "^2.16.0",
|
"@types/sanitize-html": "^2.16.0",
|
||||||
"@types/sortablejs": "^1.15.8",
|
"@types/sortablejs": "^1.15.9",
|
||||||
"@typescript-eslint/eslint-plugin": "^8.33.1",
|
"@typescript-eslint/eslint-plugin": "^8.33.1",
|
||||||
"@typescript-eslint/parser": "^8.33.1",
|
"@typescript-eslint/parser": "^8.33.1",
|
||||||
"bits-ui": "^2.17.2",
|
"bits-ui": "^2.17.2",
|
||||||
@@ -80,6 +80,6 @@
|
|||||||
"mapillary-js": "^4.1.2",
|
"mapillary-js": "^4.1.2",
|
||||||
"maplibre-gl": "^6.15.0",
|
"maplibre-gl": "^6.15.0",
|
||||||
"sanitize-html": "^2.17.0",
|
"sanitize-html": "^2.17.0",
|
||||||
"sortablejs": "^1.15.6"
|
"sortablejs": "^1.15.7"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Vendored
+5
@@ -8,6 +8,11 @@ declare global {
|
|||||||
// interface PageState {}
|
// interface PageState {}
|
||||||
// interface Platform {}
|
// interface Platform {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface Window {
|
||||||
|
/** The map, for extensions (set once it has loaded). */
|
||||||
|
_map?: import('maplibre-gl').Map;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export {};
|
export {};
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import { base } from '$app/paths';
|
import { asset, resolve as resolvePath } from '$app/paths';
|
||||||
import { languages } from '$lib/i18n/languages';
|
import { languages } from '$lib/i18n/languages';
|
||||||
import { getURLForLanguage } from '$lib/utils';
|
import { getURLForLanguage } from '$lib/utils';
|
||||||
|
|
||||||
@@ -37,16 +37,16 @@ export async function handle({ event, resolve }) {
|
|||||||
<meta property="og:description" content="${description}" />
|
<meta property="og:description" content="${description}" />
|
||||||
<meta name="twitter:title" content="gpx.studio — ${title}" />
|
<meta name="twitter:title" content="gpx.studio — ${title}" />
|
||||||
<meta name="twitter:description" content="${description}" />
|
<meta name="twitter:description" content="${description}" />
|
||||||
<meta property="og:image" content="https://gpx.studio${base}/og_logo.png" />
|
<meta property="og:image" content="https://gpx.studio${asset('/og_logo.png')}" />
|
||||||
<meta property="og:url" content="https://gpx.studio/" />
|
<meta property="og:url" content="https://gpx.studio/" />
|
||||||
<meta property="og:type" content="website" />
|
<meta property="og:type" content="website" />
|
||||||
<meta property="og:site_name" content="gpx.studio" />
|
<meta property="og:site_name" content="gpx.studio" />
|
||||||
<meta name="twitter:card" content="summary_large_image" />
|
<meta name="twitter:card" content="summary_large_image" />
|
||||||
<meta name="twitter:image" content="https://gpx.studio${base}/og_logo.png" />
|
<meta name="twitter:image" content="https://gpx.studio${asset('/og_logo.png')}" />
|
||||||
<meta name="twitter:url" content="https://gpx.studio/" />
|
<meta name="twitter:url" content="https://gpx.studio/" />
|
||||||
<meta name="twitter:site" content="@gpxstudio" />
|
<meta name="twitter:site" content="@gpxstudio" />
|
||||||
<meta name="twitter:creator" content="@gpxstudio" />
|
<meta name="twitter:creator" content="@gpxstudio" />
|
||||||
<link rel="alternate" hreflang="x-default" href="https://gpx.studio${getURLForLanguage('en', path)}" />`;
|
<link rel="alternate" hreflang="x-default" href="https://gpx.studio${resolvePath(getURLForLanguage('en', path))}" />`;
|
||||||
|
|
||||||
// the manifests are made for the website, not for the desktop app (`npm run build:desktop`)
|
// the manifests are made for the website, not for the desktop app (`npm run build:desktop`)
|
||||||
if (process.env.BUILD_TARGET !== 'desktop') {
|
if (process.env.BUILD_TARGET !== 'desktop') {
|
||||||
@@ -56,7 +56,7 @@ export async function handle({ event, resolve }) {
|
|||||||
|
|
||||||
if (page !== '404') {
|
if (page !== '404') {
|
||||||
for (let lang of Object.keys(languages)) {
|
for (let lang of Object.keys(languages)) {
|
||||||
headTag += ` <link rel="alternate" hreflang="${lang}" href="https://gpx.studio${getURLForLanguage(lang, path)}" />
|
headTag += ` <link rel="alternate" hreflang="${lang}" href="https://gpx.studio${resolvePath(getURLForLanguage(lang, path))}" />
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,7 +60,7 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<svelte:head>
|
<svelte:head>
|
||||||
<link rel="preconnect" href="https://21XLD94PE3-dsn.algolia.net" crossorigin />
|
<link rel="preconnect" href="https://21XLD94PE3-dsn.algolia.net" crossorigin="anonymous" />
|
||||||
</svelte:head>
|
</svelte:head>
|
||||||
|
|
||||||
<div id="docsearch" class={props.class ?? ''}></div>
|
<div id="docsearch" class={props.class ?? ''}></div>
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import { resolve } from '$app/paths';
|
||||||
import { Button } from '$lib/components/ui/button';
|
import { Button } from '$lib/components/ui/button';
|
||||||
import LanguageSelect from '$lib/components/LanguageSelect.svelte';
|
import LanguageSelect from '$lib/components/LanguageSelect.svelte';
|
||||||
import ModeSwitch from '$lib/components/ModeSwitch.svelte';
|
import ModeSwitch from '$lib/components/ModeSwitch.svelte';
|
||||||
@@ -31,7 +32,7 @@
|
|||||||
<Button
|
<Button
|
||||||
variant="link"
|
variant="link"
|
||||||
class="h-6 px-0 has-[>svg]:px-0 text-muted-foreground"
|
class="h-6 px-0 has-[>svg]:px-0 text-muted-foreground"
|
||||||
href={getURLForLanguage(i18n.lang, '/')}
|
href={resolve(getURLForLanguage(i18n.lang, '/'))}
|
||||||
>
|
>
|
||||||
<House size="16" />
|
<House size="16" />
|
||||||
{i18n._('homepage.home')}
|
{i18n._('homepage.home')}
|
||||||
@@ -40,7 +41,7 @@
|
|||||||
data-sveltekit-reload
|
data-sveltekit-reload
|
||||||
variant="link"
|
variant="link"
|
||||||
class="h-6 px-0 has-[>svg]:px-0 text-muted-foreground"
|
class="h-6 px-0 has-[>svg]:px-0 text-muted-foreground"
|
||||||
href={getURLForLanguage(i18n.lang, '/app')}
|
href={resolve(getURLForLanguage(i18n.lang, '/app'))}
|
||||||
>
|
>
|
||||||
<Map size="16" />
|
<Map size="16" />
|
||||||
{i18n._('homepage.app')}
|
{i18n._('homepage.app')}
|
||||||
@@ -48,7 +49,7 @@
|
|||||||
<Button
|
<Button
|
||||||
variant="link"
|
variant="link"
|
||||||
class="h-6 px-0 has-[>svg]:px-0 text-muted-foreground"
|
class="h-6 px-0 has-[>svg]:px-0 text-muted-foreground"
|
||||||
href={getURLForLanguage(i18n.lang, '/help')}
|
href={resolve(getURLForLanguage(i18n.lang, '/help'))}
|
||||||
>
|
>
|
||||||
<BookOpenText size="16" />
|
<BookOpenText size="16" />
|
||||||
{i18n._('menu.help')}
|
{i18n._('menu.help')}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
import { CircleQuestionMark } from '@lucide/svelte';
|
import { CircleQuestionMark } from '@lucide/svelte';
|
||||||
import { i18n } from '$lib/i18n/i18n.svelte';
|
import { i18n } from '$lib/i18n/i18n.svelte';
|
||||||
import type { Snippet } from 'svelte';
|
import type { Snippet } from 'svelte';
|
||||||
|
import { resolve } from '$app/paths';
|
||||||
|
|
||||||
let {
|
let {
|
||||||
link,
|
link,
|
||||||
@@ -19,7 +20,7 @@
|
|||||||
<div>
|
<div>
|
||||||
{@render children()}
|
{@render children()}
|
||||||
{#if link}
|
{#if link}
|
||||||
<a href={link} target="_blank" class="text-[13px] text-link hover:underline">
|
<a href={resolve(link)} target="_blank" class="text-[13px] text-link hover:underline">
|
||||||
{i18n._('menu.more')}
|
{i18n._('menu.more')}
|
||||||
</a>
|
</a>
|
||||||
{/if}
|
{/if}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import { resolve } from '$app/paths';
|
||||||
import { page } from '$app/state';
|
import { page } from '$app/state';
|
||||||
import * as Select from '$lib/components/ui/select';
|
import * as Select from '$lib/components/ui/select';
|
||||||
import { languages } from '$lib/i18n/languages';
|
import { languages } from '$lib/i18n/languages';
|
||||||
@@ -15,13 +16,13 @@
|
|||||||
</span>
|
</span>
|
||||||
</Select.Trigger>
|
</Select.Trigger>
|
||||||
<Select.Content>
|
<Select.Content>
|
||||||
{#each Object.entries(languages) as [lang, label]}
|
{#each Object.entries(languages) as [lang, label] (lang)}
|
||||||
{#if page.url.pathname.includes('404')}
|
{#if page.url.pathname.includes('404')}
|
||||||
<a href={getURLForLanguage(lang, '/')}>
|
<a href={resolve(getURLForLanguage(lang, '/'))}>
|
||||||
<Select.Item value={lang}>{label}</Select.Item>
|
<Select.Item value={lang}>{label}</Select.Item>
|
||||||
</a>
|
</a>
|
||||||
{:else}
|
{:else}
|
||||||
<a href={getURLForLanguage(lang, page.url.pathname)}>
|
<a href={resolve(getURLForLanguage(lang, page.url.pathname))}>
|
||||||
<Select.Item value={lang}>{label}</Select.Item>
|
<Select.Item value={lang}>{label}</Select.Item>
|
||||||
</a>
|
</a>
|
||||||
{/if}
|
{/if}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { mode } from 'mode-watcher';
|
import { mode } from 'mode-watcher';
|
||||||
import { base } from '$app/paths';
|
import { asset } from '$app/paths';
|
||||||
|
|
||||||
let {
|
let {
|
||||||
iconOnly = false,
|
iconOnly = false,
|
||||||
@@ -9,13 +9,13 @@
|
|||||||
}: {
|
}: {
|
||||||
iconOnly?: boolean;
|
iconOnly?: boolean;
|
||||||
company?: 'gpx.studio' | 'github' | 'crowdin' | 'facebook' | 'reddit';
|
company?: 'gpx.studio' | 'github' | 'crowdin' | 'facebook' | 'reddit';
|
||||||
[key: string]: any;
|
[key: string]: unknown;
|
||||||
} = $props();
|
} = $props();
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#if company === 'gpx.studio'}
|
{#if company === 'gpx.studio'}
|
||||||
<img
|
<img
|
||||||
src="{base}/{iconOnly ? 'icon' : 'logo'}{mode.current === 'dark' ? '-dark' : ''}.svg"
|
src={asset(`/${iconOnly ? 'icon' : 'logo'}${mode.current === 'dark' ? '-dark' : ''}.svg`)}
|
||||||
alt="Logo of gpx.studio."
|
alt="Logo of gpx.studio."
|
||||||
{...others}
|
{...others}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import { resolve } from '$app/paths';
|
||||||
import * as Menubar from '$lib/components/ui/menubar/index.js';
|
import * as Menubar from '$lib/components/ui/menubar/index.js';
|
||||||
import { Button } from '$lib/components/ui/button';
|
import { Button } from '$lib/components/ui/button';
|
||||||
import Logo from '$lib/components/Logo.svelte';
|
import Logo from '$lib/components/Logo.svelte';
|
||||||
@@ -148,7 +149,7 @@
|
|||||||
<div
|
<div
|
||||||
class="w-fit flex flex-row items-center justify-center p-1 bg-background rounded-b-md md:rounded-md pointer-events-auto shadow-md"
|
class="w-fit flex flex-row items-center justify-center p-1 bg-background rounded-b-md md:rounded-md pointer-events-auto shadow-md"
|
||||||
>
|
>
|
||||||
<a href={getURLForLanguage(i18n.lang, '/')} target="_blank" class="shrink-0">
|
<a href={resolve(getURLForLanguage(i18n.lang, '/'))} target="_blank" class="shrink-0">
|
||||||
<Logo class="h-5 mt-0.5 mx-2 md:hidden" iconOnly={true} width="16" />
|
<Logo class="h-5 mt-0.5 mx-2 md:hidden" iconOnly={true} width="16" />
|
||||||
<Logo class="h-5 mt-0.5 mx-2 hidden md:block" width="96" />
|
<Logo class="h-5 mt-0.5 mx-2 hidden md:block" width="96" />
|
||||||
</a>
|
</a>
|
||||||
@@ -526,8 +527,8 @@
|
|||||||
</Menubar.SubTrigger>
|
</Menubar.SubTrigger>
|
||||||
<Menubar.SubContent>
|
<Menubar.SubContent>
|
||||||
<Menubar.RadioGroup value={i18n.lang}>
|
<Menubar.RadioGroup value={i18n.lang}>
|
||||||
{#each Object.entries(languages) as [lang, label]}
|
{#each Object.entries(languages) as [lang, label] (lang)}
|
||||||
<a href={getURLForLanguage(lang, '/app')}>
|
<a href={resolve(getURLForLanguage(lang, '/app'))}>
|
||||||
<Menubar.RadioItem value={lang}>{label}</Menubar.RadioItem>
|
<Menubar.RadioItem value={lang}>{label}</Menubar.RadioItem>
|
||||||
</a>
|
</a>
|
||||||
{/each}
|
{/each}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import { resolve } from '$app/paths';
|
||||||
import Logo from '$lib/components/Logo.svelte';
|
import Logo from '$lib/components/Logo.svelte';
|
||||||
import { Button } from '$lib/components/ui/button';
|
import { Button } from '$lib/components/ui/button';
|
||||||
import { BookOpenText, House, Map } from '@lucide/svelte';
|
import { BookOpenText, House, Map } from '@lucide/svelte';
|
||||||
@@ -9,7 +10,7 @@
|
|||||||
<nav class="sticky top-0 w-full px-12 py-2 bg-background z-50 flex flex-col items-center border-b">
|
<nav class="sticky top-0 w-full px-12 py-2 bg-background z-50 flex flex-col items-center border-b">
|
||||||
<div class="w-full max-w-5xl flex flex-row items-center gap-4 sm:gap-8">
|
<div class="w-full max-w-5xl flex flex-row items-center gap-4 sm:gap-8">
|
||||||
<a
|
<a
|
||||||
href={getURLForLanguage(i18n.lang, '/')}
|
href={resolve(getURLForLanguage(i18n.lang, '/'))}
|
||||||
class="shrink-0 translate-y-0.25 justify-self-start"
|
class="shrink-0 translate-y-0.25 justify-self-start"
|
||||||
>
|
>
|
||||||
<Logo class="h-8 xs:hidden" iconOnly={true} width="26" />
|
<Logo class="h-8 xs:hidden" iconOnly={true} width="26" />
|
||||||
@@ -18,7 +19,7 @@
|
|||||||
<Button
|
<Button
|
||||||
variant="link"
|
variant="link"
|
||||||
class="text-base px-0 has-[>svg]:px-0 ml-auto"
|
class="text-base px-0 has-[>svg]:px-0 ml-auto"
|
||||||
href={getURLForLanguage(i18n.lang, '/')}
|
href={resolve(getURLForLanguage(i18n.lang, '/'))}
|
||||||
>
|
>
|
||||||
<House size="18" />
|
<House size="18" />
|
||||||
{i18n._('homepage.home')}
|
{i18n._('homepage.home')}
|
||||||
@@ -27,7 +28,7 @@
|
|||||||
data-sveltekit-reload
|
data-sveltekit-reload
|
||||||
variant="link"
|
variant="link"
|
||||||
class="text-base px-0 has-[>svg]:px-0"
|
class="text-base px-0 has-[>svg]:px-0"
|
||||||
href={getURLForLanguage(i18n.lang, '/app')}
|
href={resolve(getURLForLanguage(i18n.lang, '/app'))}
|
||||||
>
|
>
|
||||||
<Map size="18" />
|
<Map size="18" />
|
||||||
{i18n._('homepage.app')}
|
{i18n._('homepage.app')}
|
||||||
@@ -35,7 +36,7 @@
|
|||||||
<Button
|
<Button
|
||||||
variant="link"
|
variant="link"
|
||||||
class="text-base px-0 has-[>svg]:px-0"
|
class="text-base px-0 has-[>svg]:px-0"
|
||||||
href={getURLForLanguage(i18n.lang, '/help')}
|
href={resolve(getURLForLanguage(i18n.lang, '/help'))}
|
||||||
>
|
>
|
||||||
<BookOpenText size="18" />
|
<BookOpenText size="18" />
|
||||||
{i18n._('menu.help')}
|
{i18n._('menu.help')}
|
||||||
|
|||||||
@@ -346,7 +346,8 @@ export class ElevationProfile {
|
|||||||
grid: {
|
grid: {
|
||||||
display: false,
|
display: false,
|
||||||
},
|
},
|
||||||
reverse: () => id === 'speed' && get(velocityUnits) === 'pace',
|
// the pace axis is reversed: set with the data, which the units change
|
||||||
|
reverse: false,
|
||||||
display: false,
|
display: false,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
@@ -562,6 +563,8 @@ export class ElevationProfile {
|
|||||||
global.totalDistance,
|
global.totalDistance,
|
||||||
units.distance
|
units.distance
|
||||||
);
|
);
|
||||||
|
// a faster pace is a lower value, it goes up like a higher speed
|
||||||
|
this._chart.options.scales!.yspeed!.reverse = units.velocity === 'pace';
|
||||||
|
|
||||||
this.setVisibility();
|
this.setVisibility();
|
||||||
this.setFill();
|
this.setFill();
|
||||||
|
|||||||
@@ -25,9 +25,10 @@
|
|||||||
import { PUBLIC_MAPTILER_KEY } from '$env/static/public';
|
import { PUBLIC_MAPTILER_KEY } from '$env/static/public';
|
||||||
import Embedding from './Embedding.svelte';
|
import Embedding from './Embedding.svelte';
|
||||||
import { onDestroy } from 'svelte';
|
import { onDestroy } from 'svelte';
|
||||||
import { base } from '$app/paths';
|
import { resolve } from '$app/paths';
|
||||||
import { map } from '$lib/components/map/map';
|
import { map } from '$lib/components/map/map';
|
||||||
import { mode } from 'mode-watcher';
|
import { mode } from 'mode-watcher';
|
||||||
|
import { getURLForLanguage } from '$lib/utils';
|
||||||
|
|
||||||
let options = $state(
|
let options = $state(
|
||||||
getMergedEmbeddingOptions(
|
getMergedEmbeddingOptions(
|
||||||
@@ -114,7 +115,7 @@
|
|||||||
{i18n._(`layers.label.${options.basemap}`)}
|
{i18n._(`layers.label.${options.basemap}`)}
|
||||||
</Select.Trigger>
|
</Select.Trigger>
|
||||||
<Select.Content class="max-h-60 overflow-y-scroll">
|
<Select.Content class="max-h-60 overflow-y-scroll">
|
||||||
{#each allowedEmbeddingBasemaps as basemap}
|
{#each allowedEmbeddingBasemaps as basemap (basemap)}
|
||||||
<Select.Item value={basemap}
|
<Select.Item value={basemap}
|
||||||
>{i18n._(`layers.label.${basemap}`)}</Select.Item
|
>{i18n._(`layers.label.${basemap}`)}</Select.Item
|
||||||
>
|
>
|
||||||
@@ -321,7 +322,7 @@
|
|||||||
<pre
|
<pre
|
||||||
class="bg-primary text-primary-foreground p-3 rounded-md whitespace-normal break-all">
|
class="bg-primary text-primary-foreground p-3 rounded-md whitespace-normal break-all">
|
||||||
<code class="language-html">
|
<code class="language-html">
|
||||||
{`<iframe src="https://gpx.studio${base}/embed?options=${encodeURIComponent(JSON.stringify(getCleanedEmbeddingOptions(iframeOptions)))}${hash}" width="100%" height="600px" frameborder="0" style="outline: none;"/>`}
|
{`<iframe src="https://gpx.studio${resolve(getURLForLanguage(i18n.lang, '/embed'))}?options=${encodeURIComponent(JSON.stringify(getCleanedEmbeddingOptions(iframeOptions)))}${hash}" width="100%" height="600px" frameborder="0" style="outline: none;"/>`}
|
||||||
</code>
|
</code>
|
||||||
</pre>
|
</pre>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import { resolve } from '$app/paths';
|
||||||
import { Button } from '$lib/components/ui/button';
|
import { Button } from '$lib/components/ui/button';
|
||||||
import Logo from '$lib/components/Logo.svelte';
|
import Logo from '$lib/components/Logo.svelte';
|
||||||
import { getURLForLanguage } from '$lib/utils';
|
import { getURLForLanguage } from '$lib/utils';
|
||||||
@@ -16,7 +17,7 @@
|
|||||||
<Button
|
<Button
|
||||||
variant="ghost"
|
variant="ghost"
|
||||||
class="absolute top-0 flex-wrap h-fit bg-background font-semibold rounded-md py-1 px-2 gap-1.5 xs:text-base mt-2.5 ml-2.5 mr-12"
|
class="absolute top-0 flex-wrap h-fit bg-background font-semibold rounded-md py-1 px-2 gap-1.5 xs:text-base mt-2.5 ml-2.5 mr-12"
|
||||||
href="{getURLForLanguage(i18n.lang, '/app')}?{files.length > 0
|
href="{resolve(getURLForLanguage(i18n.lang, '/app'))}?{files.length > 0
|
||||||
? `files=${encodeURIComponent(JSON.stringify(files))}`
|
? `files=${encodeURIComponent(JSON.stringify(files))}`
|
||||||
: ''}{files.length > 0 && ids.length > 0 ? '&' : ''}{ids.length > 0
|
: ''}{files.length > 0 && ids.length > 0 ? '&' : ''}{ids.length > 0
|
||||||
? `ids=${encodeURIComponent(JSON.stringify(ids))}`
|
? `ids=${encodeURIComponent(JSON.stringify(ids))}`
|
||||||
|
|||||||
@@ -43,7 +43,7 @@
|
|||||||
</AlertDialog.Description>
|
</AlertDialog.Description>
|
||||||
</AlertDialog.Header>
|
</AlertDialog.Header>
|
||||||
<ul class="list-disc pl-6 text-sm max-h-40 overflow-y-auto">
|
<ul class="list-disc pl-6 text-sm max-h-40 overflow-y-auto">
|
||||||
{#each prompt.names as name}
|
{#each prompt.names as name, i (i)}
|
||||||
<li>{name}</li>
|
<li>{name}</li>
|
||||||
{/each}
|
{/each}
|
||||||
</ul>
|
</ul>
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { isMac } from '$lib/utils';
|
import { isMac } from '$lib/utils';
|
||||||
import Sortable, { type Direction } from 'sortablejs/Sortable';
|
import Sortable from './sortable';
|
||||||
|
import type { Direction } from 'sortablejs';
|
||||||
import { get, writable } from 'svelte/store';
|
import { get, writable } from 'svelte/store';
|
||||||
import { tick } from 'svelte';
|
import { tick } from 'svelte';
|
||||||
import { engine, type MoveTarget, type Selection } from '$lib/engine';
|
import { engine, type MoveTarget, type Selection } from '$lib/engine';
|
||||||
@@ -78,9 +79,13 @@ export class SortableFileList {
|
|||||||
setTimeout(() => this.updateToSelection(e), 50),
|
setTimeout(() => this.updateToSelection(e), 50),
|
||||||
onDeselect: (e: Sortable.SortableEvent) =>
|
onDeselect: (e: Sortable.SortableEvent) =>
|
||||||
setTimeout(() => this.updateToSelection(e), 50),
|
setTimeout(() => this.updateToSelection(e), 50),
|
||||||
onStart: (e: Sortable.SortableEvent) => {
|
onChoose: () => {
|
||||||
// all the nodes, not only the elements: the comments are the anchors of the Svelte blocks
|
// all the nodes, not only the elements: the comments are the anchors of the Svelte
|
||||||
|
// blocks. Taken before the drag starts, when MultiDrag removes the other selected
|
||||||
|
// elements from the list.
|
||||||
this._snapshot = Array.from(container.childNodes);
|
this._snapshot = Array.from(container.childNodes);
|
||||||
|
},
|
||||||
|
onStart: (e: Sortable.SortableEvent) => {
|
||||||
dragging.set(sortableLevel);
|
dragging.set(sortableLevel);
|
||||||
// the files that are dragged (or whose elements are) are open for good
|
// the files that are dragged (or whose elements are) are open for good
|
||||||
engine.keepPreview(this.draggedFiles(e));
|
engine.keepPreview(this.draggedFiles(e));
|
||||||
@@ -258,7 +263,7 @@ export class SortableFileList {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
updateToSelection(e: Sortable.SortableEvent) {
|
updateToSelection(e: Sortable.SortableEvent & { originalEvent?: MouseEvent }) {
|
||||||
if (!this._sortable) return;
|
if (!this._sortable) return;
|
||||||
if (this._updatingSelection || this._applying) return;
|
if (this._updatingSelection || this._applying) return;
|
||||||
this._updatingSelection = true;
|
this._updatingSelection = true;
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
import Sortable, { MultiDrag } from 'sortablejs';
|
||||||
|
|
||||||
|
// The ESM build leaves out the MultiDrag plugin. Mounting it twice throws, so it is done here
|
||||||
|
// rather than in a module that hot reloading runs again.
|
||||||
|
Sortable.mount(new MultiDrag());
|
||||||
|
|
||||||
|
export default Sortable;
|
||||||
@@ -48,7 +48,7 @@
|
|||||||
<Card.Title class="text-md">
|
<Card.Title class="text-md">
|
||||||
{@const link = waypoint.item.links?.[0]}
|
{@const link = waypoint.item.links?.[0]}
|
||||||
{#if link?.href}
|
{#if link?.href}
|
||||||
<a href={link.href} target="_blank">
|
<a href={link.href} target="_blank" rel="external">
|
||||||
{waypoint.item.name ?? link.href}
|
{waypoint.item.name ?? link.href}
|
||||||
<ExternalLink size="12" class="inline-block mb-1.5" />
|
<ExternalLink size="12" class="inline-block mb-1.5" />
|
||||||
</a>
|
</a>
|
||||||
|
|||||||
@@ -66,9 +66,9 @@ export class GPXLayer {
|
|||||||
unsubscribe: (() => void)[] = [];
|
unsubscribe: (() => void)[] = [];
|
||||||
|
|
||||||
updateBinded: () => void = this.update.bind(this);
|
updateBinded: () => void = this.update.bind(this);
|
||||||
layerOnMouseEnterBinded: (e: any) => void = this.layerOnMouseEnter.bind(this);
|
layerOnMouseEnterBinded: (e: MapLayerMouseEvent) => void = this.layerOnMouseEnter.bind(this);
|
||||||
layerOnMouseLeaveBinded: () => void = this.layerOnMouseLeave.bind(this);
|
layerOnMouseLeaveBinded: () => void = this.layerOnMouseLeave.bind(this);
|
||||||
layerOnMouseMoveBinded: (e: any) => void = this.layerOnMouseMove.bind(this);
|
layerOnMouseMoveBinded: (e: MapLayerMouseEvent) => void = this.layerOnMouseMove.bind(this);
|
||||||
layerOnClickBinded: (e: MapLayerMouseEvent) => void = this.layerOnClick.bind(this);
|
layerOnClickBinded: (e: MapLayerMouseEvent) => void = this.layerOnClick.bind(this);
|
||||||
layerOnContextMenuBinded: (e: MapLayerMouseEvent) => void = this.layerOnContextMenu.bind(this);
|
layerOnContextMenuBinded: (e: MapLayerMouseEvent) => void = this.layerOnContextMenu.bind(this);
|
||||||
waypointLayerOnMouseEnterBinded: (e: MapLayerMouseEvent) => void =
|
waypointLayerOnMouseEnterBinded: (e: MapLayerMouseEvent) => void =
|
||||||
@@ -386,10 +386,10 @@ export class GPXLayer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
layerOnMouseEnter(e: any) {
|
layerOnMouseEnter(e: MapLayerMouseEvent) {
|
||||||
if (
|
if (
|
||||||
get(currentTool) === Tool.SCISSORS &&
|
get(currentTool) === Tool.SCISSORS &&
|
||||||
isCovered(this.selectionState, this.segmentNode(e.features[0].properties))
|
isCovered(this.selectionState, this.segmentNode(e.features![0].properties))
|
||||||
) {
|
) {
|
||||||
mapCursor.notify(MapCursorState.SCISSORS, true);
|
mapCursor.notify(MapCursorState.SCISSORS, true);
|
||||||
} else {
|
} else {
|
||||||
@@ -402,9 +402,9 @@ export class GPXLayer {
|
|||||||
mapCursor.notify(MapCursorState.LAYER_HOVER, false);
|
mapCursor.notify(MapCursorState.LAYER_HOVER, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
async layerOnMouseMove(e: any) {
|
async layerOnMouseMove(e: MapLayerMouseEvent) {
|
||||||
if (e.originalEvent.shiftKey) {
|
if (e.originalEvent.shiftKey) {
|
||||||
const { segmentId } = e.features[0].properties;
|
const { segmentId } = e.features![0].properties;
|
||||||
const lngLat = { lng: e.lngLat.lng, lat: e.lngLat.lat };
|
const lngLat = { lng: e.lngLat.lng, lat: e.lngLat.lat };
|
||||||
const index = closestPointIndex(await engine.segmentCoordinates(segmentId), lngLat);
|
const index = closestPointIndex(await engine.segmentCoordinates(segmentId), lngLat);
|
||||||
const trackpoint =
|
const trackpoint =
|
||||||
@@ -469,7 +469,7 @@ export class GPXLayer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
layerOnContextMenu(e: any) {
|
layerOnContextMenu(e: MapLayerMouseEvent) {
|
||||||
if (e.originalEvent.ctrlKey) {
|
if (e.originalEvent.ctrlKey) {
|
||||||
this.layerOnClick(e);
|
this.layerOnClick(e);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
Layers2,
|
Layers2,
|
||||||
} from '@lucide/svelte';
|
} from '@lucide/svelte';
|
||||||
import { i18n } from '$lib/i18n/i18n.svelte';
|
import { i18n } from '$lib/i18n/i18n.svelte';
|
||||||
import { defaultBasemap, type CustomLayer } from '$lib/data/layers';
|
import { defaultBasemap, layerGroup, type CustomLayer } from '$lib/data/layers';
|
||||||
import { onMount } from 'svelte';
|
import { onMount } from 'svelte';
|
||||||
import { remove } from './utils';
|
import { remove } from './utils';
|
||||||
import { settings } from '$lib/state/settings';
|
import { settings } from '$lib/state/settings';
|
||||||
@@ -128,8 +128,9 @@
|
|||||||
],
|
],
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
addLayer(layerId);
|
|
||||||
$customLayers[layerId] = layer;
|
$customLayers[layerId] = layer;
|
||||||
|
addLayer(layerId);
|
||||||
selectedLayerId = undefined;
|
selectedLayerId = undefined;
|
||||||
setDataFromSelectedLayer();
|
setDataFromSelectedLayer();
|
||||||
}
|
}
|
||||||
@@ -182,7 +183,7 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function tryDeleteLayer(node: any, id: string): any {
|
function tryDeleteLayer<T>(node: Record<string, T>, id: string): Record<string, T> {
|
||||||
if (Object.hasOwn(node, id)) {
|
if (Object.hasOwn(node, id)) {
|
||||||
delete node[id];
|
delete node[id];
|
||||||
}
|
}
|
||||||
@@ -255,13 +256,12 @@
|
|||||||
onfinalize={(e) => {
|
onfinalize={(e) => {
|
||||||
customBasemapItems = e.detail.items;
|
customBasemapItems = e.detail.items;
|
||||||
$customBasemapOrder = customBasemapItems.map((item) => item.id);
|
$customBasemapOrder = customBasemapItems.map((item) => item.id);
|
||||||
$selectedBasemapTree.basemaps['custom'] = customBasemapItems.reduce(
|
selectedBasemapTree.update(($tree) => {
|
||||||
(acc, item) => {
|
layerGroup($tree.basemaps)['custom'] = Object.fromEntries(
|
||||||
acc[item.id] = true;
|
customBasemapItems.map((item) => [item.id, true])
|
||||||
return acc;
|
);
|
||||||
},
|
return $tree;
|
||||||
{}
|
});
|
||||||
);
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{#each customBasemapItems as item (item.id)}
|
{#each customBasemapItems as item (item.id)}
|
||||||
@@ -315,13 +315,12 @@
|
|||||||
onfinalize={(e) => {
|
onfinalize={(e) => {
|
||||||
customOverlayItems = e.detail.items;
|
customOverlayItems = e.detail.items;
|
||||||
$customOverlayOrder = customOverlayItems.map((item) => item.id);
|
$customOverlayOrder = customOverlayItems.map((item) => item.id);
|
||||||
$selectedOverlayTree.overlays['custom'] = customOverlayItems.reduce(
|
selectedOverlayTree.update(($tree) => {
|
||||||
(acc, item) => {
|
layerGroup($tree.overlays)['custom'] = Object.fromEntries(
|
||||||
acc[item.id] = true;
|
customOverlayItems.map((item) => [item.id, true])
|
||||||
return acc;
|
);
|
||||||
},
|
return $tree;
|
||||||
{}
|
});
|
||||||
);
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{#each customOverlayItems as item (item.id)}
|
{#each customOverlayItems as item (item.id)}
|
||||||
@@ -365,7 +364,7 @@
|
|||||||
<Label for="name">{i18n._('menu.metadata.name')}</Label>
|
<Label for="name">{i18n._('menu.metadata.name')}</Label>
|
||||||
<Input bind:value={name} id="name" class="h-8" />
|
<Input bind:value={name} id="name" class="h-8" />
|
||||||
<Label for="url">{i18n._('layers.custom_layers.urls')}</Label>
|
<Label for="url">{i18n._('layers.custom_layers.urls')}</Label>
|
||||||
{#each tileUrls as _, i}
|
{#each tileUrls as _, i (i)}
|
||||||
<div class="flex flex-row gap-2">
|
<div class="flex flex-row gap-2">
|
||||||
<Input
|
<Input
|
||||||
bind:value={tileUrls[i]}
|
bind:value={tileUrls[i]}
|
||||||
|
|||||||
@@ -178,7 +178,7 @@
|
|||||||
{/if}
|
{/if}
|
||||||
</Select.Trigger>
|
</Select.Trigger>
|
||||||
<Select.Content class="h-fit max-h-[40dvh] overflow-y-auto">
|
<Select.Content class="h-fit max-h-[40dvh] overflow-y-auto">
|
||||||
{#each Object.keys(overlays) as id}
|
{#each Object.keys(overlays) as id (id)}
|
||||||
{#if isSelected($selectedOverlayTree, id)}
|
{#if isSelected($selectedOverlayTree, id)}
|
||||||
<Select.Item value={id}>
|
<Select.Item value={id}>
|
||||||
{#if $isLayerFromExtension(id)}
|
{#if $isLayerFromExtension(id)}
|
||||||
@@ -189,7 +189,7 @@
|
|||||||
</Select.Item>
|
</Select.Item>
|
||||||
{/if}
|
{/if}
|
||||||
{/each}
|
{/each}
|
||||||
{#each Object.entries($customLayers) as [id, layer]}
|
{#each Object.entries($customLayers) as [id, layer] (id)}
|
||||||
{#if layer.layerType === 'overlay'}
|
{#if layer.layerType === 'overlay'}
|
||||||
<Select.Item value={id}>{layer.name}</Select.Item>
|
<Select.Item value={id}>{layer.name}</Select.Item>
|
||||||
{/if}
|
{/if}
|
||||||
@@ -247,7 +247,7 @@
|
|||||||
{i18n._(`layers.label.${$terrainSource}`)}
|
{i18n._(`layers.label.${$terrainSource}`)}
|
||||||
</Select.Trigger>
|
</Select.Trigger>
|
||||||
<Select.Content class="h-fit max-h-[40dvh] overflow-y-auto">
|
<Select.Content class="h-fit max-h-[40dvh] overflow-y-auto">
|
||||||
{#each Object.keys(terrainSources) as id}
|
{#each Object.keys(terrainSources) as id (id)}
|
||||||
<Select.Item value={id}>
|
<Select.Item value={id}>
|
||||||
{i18n._(`layers.label.${id}`)}
|
{i18n._(`layers.label.${id}`)}
|
||||||
</Select.Item>
|
</Select.Item>
|
||||||
|
|||||||
@@ -22,7 +22,7 @@
|
|||||||
selected?: string;
|
selected?: string;
|
||||||
onselect?: (value: string) => void;
|
onselect?: (value: string) => void;
|
||||||
multiple: boolean;
|
multiple: boolean;
|
||||||
checked: LayerTreeType;
|
checked?: LayerTreeType;
|
||||||
} = $props();
|
} = $props();
|
||||||
|
|
||||||
const { customLayers } = settings;
|
const { customLayers } = settings;
|
||||||
@@ -44,7 +44,7 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="flex flex-col gap-[3px]">
|
<div class="flex flex-col gap-[3px]">
|
||||||
{#each Object.keys(node) as id}
|
{#each Object.keys(node) as id (id)}
|
||||||
{#if typeof node[id] == 'boolean'}
|
{#if typeof node[id] == 'boolean'}
|
||||||
{#if node[id]}
|
{#if node[id]}
|
||||||
<div class="flex flex-row items-center gap-2 first:mt-0.5 h-4">
|
<div class="flex flex-row items-center gap-2 first:mt-0.5 h-4">
|
||||||
@@ -53,7 +53,9 @@
|
|||||||
id="{name}-{id}"
|
id="{name}-{id}"
|
||||||
{name}
|
{name}
|
||||||
value={id}
|
value={id}
|
||||||
bind:checked={checked[id]}
|
bind:checked={
|
||||||
|
() => checked[id] === true, (value) => (checked[id] = value)
|
||||||
|
}
|
||||||
class="scale-90"
|
class="scale-90"
|
||||||
aria-label={i18n._(`layers.label.${id}`)}
|
aria-label={i18n._(`layers.label.${id}`)}
|
||||||
/>
|
/>
|
||||||
@@ -90,12 +92,18 @@
|
|||||||
{#snippet content()}
|
{#snippet content()}
|
||||||
<div class="ml-2">
|
<div class="ml-2">
|
||||||
<Self
|
<Self
|
||||||
node={node[id]}
|
node={node[id] as LayerTreeType}
|
||||||
{name}
|
{name}
|
||||||
{selected}
|
{selected}
|
||||||
{onselect}
|
{onselect}
|
||||||
{multiple}
|
{multiple}
|
||||||
bind:checked={checked[id]}
|
bind:checked={
|
||||||
|
() => {
|
||||||
|
const group = checked[id];
|
||||||
|
return typeof group === 'object' ? group : undefined;
|
||||||
|
},
|
||||||
|
(value) => (checked[id] = value ?? {})
|
||||||
|
}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
{/snippet}
|
{/snippet}
|
||||||
|
|||||||
@@ -79,11 +79,16 @@
|
|||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
<div class="grid grid-cols-[auto_auto] gap-x-3">
|
<div class="grid grid-cols-[auto_auto] gap-x-3">
|
||||||
{#each Object.entries(tags) as [key, value]}
|
{#each Object.entries(tags) as [key, value] (key)}
|
||||||
{#if key !== 'name' && !key.includes('image')}
|
{#if key !== 'name' && !key.includes('image')}
|
||||||
<span class="font-mono">{key}</span>
|
<span class="font-mono">{key}</span>
|
||||||
{#if key === 'website' || key.startsWith('website:') || key.endsWith(':website') || key === 'contact:facebook' || key === 'contact:instagram' || key === 'contact:twitter'}
|
{#if key === 'website' || key.startsWith('website:') || key.endsWith(':website') || key === 'contact:facebook' || key === 'contact:instagram' || key === 'contact:twitter'}
|
||||||
<a href={value} target="_blank" class="text-link underline">{value}</a>
|
<a
|
||||||
|
href={value}
|
||||||
|
target="_blank"
|
||||||
|
rel="external"
|
||||||
|
class="text-link underline">{value}</a
|
||||||
|
>
|
||||||
{:else if key === 'wikipedia' || key.startsWith('wikipedia:') || key.endsWith(':wikipedia')}
|
{:else if key === 'wikipedia' || key.startsWith('wikipedia:') || key.endsWith(':wikipedia')}
|
||||||
<a
|
<a
|
||||||
href="https://wikipedia.org/wiki/{value}"
|
href="https://wikipedia.org/wiki/{value}"
|
||||||
|
|||||||
@@ -9,6 +9,15 @@ import { ExtensionAPI, type CustomOverlay } from './extension-api';
|
|||||||
import { isSelected } from './utils';
|
import { isSelected } from './utils';
|
||||||
|
|
||||||
const original = { set: engine.setSetting, delete: engine.deleteSetting };
|
const original = { set: engine.setSetting, delete: engine.deleteSetting };
|
||||||
|
|
||||||
|
/** The raster source that an overlay added by an extension uses. */
|
||||||
|
function rasterSource(id: string) {
|
||||||
|
const style = overlays[id];
|
||||||
|
assert.ok(typeof style === 'object');
|
||||||
|
const source = style.sources[id];
|
||||||
|
assert.ok(source?.type === 'raster');
|
||||||
|
return source;
|
||||||
|
}
|
||||||
const overlayTreeBefore = JSON.stringify(overlayTree);
|
const overlayTreeBefore = JSON.stringify(overlayTree);
|
||||||
const overlayIdsBefore = Object.keys(overlays).sort();
|
const overlayIdsBefore = Object.keys(overlays).sort();
|
||||||
|
|
||||||
@@ -45,10 +54,7 @@ describe('ExtensionAPI', () => {
|
|||||||
it('adds an overlay as a layer, in the tree of its extension', () => {
|
it('adds an overlay as a layer, in the tree of its extension', () => {
|
||||||
api.addOrUpdateOverlay(overlay('one'));
|
api.addOrUpdateOverlay(overlay('one'));
|
||||||
|
|
||||||
const layer = overlays['extension-one'];
|
const source = rasterSource('extension-one');
|
||||||
assert.ok(layer && typeof layer === 'object');
|
|
||||||
const source = (layer as any).sources['extension-one'];
|
|
||||||
assert.equal(source.type, 'raster');
|
|
||||||
assert.deepEqual(source.tiles, ['https://tiles.example.com/one/{z}/{x}/{y}.png']);
|
assert.deepEqual(source.tiles, ['https://tiles.example.com/one/{z}/{x}/{y}.png']);
|
||||||
assert.equal(source.tileSize, 256);
|
assert.equal(source.tileSize, 256);
|
||||||
assert.equal(source.maxzoom, 22);
|
assert.equal(source.maxzoom, 22);
|
||||||
@@ -69,7 +75,7 @@ describe('ExtensionAPI', () => {
|
|||||||
tileUrls: ['https://tiles.example.com/512/{z}/{x}/{y}.png'],
|
tileUrls: ['https://tiles.example.com/512/{z}/{x}/{y}.png'],
|
||||||
maxZoom: 15,
|
maxZoom: 15,
|
||||||
});
|
});
|
||||||
const source = (overlays['extension-big'] as any).sources['extension-big'];
|
const source = rasterSource('extension-big');
|
||||||
assert.equal(source.tileSize, 512);
|
assert.equal(source.tileSize, 512);
|
||||||
assert.equal(source.maxzoom, 15);
|
assert.equal(source.maxzoom, 15);
|
||||||
});
|
});
|
||||||
@@ -100,9 +106,7 @@ describe('ExtensionAPI', () => {
|
|||||||
tileUrls: ['https://other/{z}'],
|
tileUrls: ['https://other/{z}'],
|
||||||
});
|
});
|
||||||
assert.equal(get(api.getLayerName)('extension-one'), 'Renamed');
|
assert.equal(get(api.getLayerName)('extension-one'), 'Renamed');
|
||||||
assert.deepEqual((overlays['extension-one'] as any).sources['extension-one'].tiles, [
|
assert.deepEqual(rasterSource('extension-one').tiles, ['https://other/{z}']);
|
||||||
'https://other/{z}',
|
|
||||||
]);
|
|
||||||
assert.equal(isSelected(get(settings.currentOverlays)!, 'extension-one'), true);
|
assert.equal(isSelected(get(settings.currentOverlays)!, 'extension-one'), true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { settings } from '$lib/state/settings';
|
import { settings } from '$lib/state/settings';
|
||||||
import { derived, get, writable, type Writable } from 'svelte/store';
|
import { derived, get, writable, type Writable } from 'svelte/store';
|
||||||
import { isSelected, remove, removeAll } from './utils';
|
import { isSelected, remove, removeAll } from './utils';
|
||||||
import { overlays, overlayTree, type LayerTreeType } from '$lib/data/layers';
|
import { layerGroup, overlays, overlayTree, type LayerTreeType } from '$lib/data/layers';
|
||||||
import { browser } from '$app/environment';
|
import { browser } from '$app/environment';
|
||||||
import { map } from '$lib/components/map/map';
|
import { map } from '$lib/components/map/map';
|
||||||
|
|
||||||
@@ -84,11 +84,12 @@ export class ExtensionAPI {
|
|||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!Object.hasOwn(overlayTree.overlays as LayerTreeType, overlay.extensionName)) {
|
const extensions = layerGroup(overlayTree.overlays);
|
||||||
overlayTree.overlays[overlay.extensionName] = {};
|
if (!Object.hasOwn(extensions, overlay.extensionName)) {
|
||||||
|
extensions[overlay.extensionName] = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
overlayTree.overlays[overlay.extensionName][overlay.id] = true;
|
layerGroup(extensions[overlay.extensionName])[overlay.id] = true;
|
||||||
|
|
||||||
selectedOverlayTree.update((selected) => {
|
selectedOverlayTree.update((selected) => {
|
||||||
if (!Object.hasOwn(selected.overlays, overlay.extensionName)) {
|
if (!Object.hasOwn(selected.overlays, overlay.extensionName)) {
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import { get, writable } from 'svelte/store';
|
|||||||
import { overpassQueryData } from '$lib/data/layers';
|
import { overpassQueryData } from '$lib/data/layers';
|
||||||
import { MapPopup } from '$lib/components/map/map-popup';
|
import { MapPopup } from '$lib/components/map/map-popup';
|
||||||
import { settings } from '$lib/state/settings';
|
import { settings } from '$lib/state/settings';
|
||||||
import type { GeoJSONSource, Map as MapLibreMap } from 'maplibre-gl';
|
import type { GeoJSONSource, MapLayerMouseEvent, Map as MapLibreMap } from 'maplibre-gl';
|
||||||
import { ANCHOR_LAYER_KEY } from '$lib/components/map/style';
|
import { ANCHOR_LAYER_KEY } from '$lib/components/map/style';
|
||||||
import type { MapLayerEventManager } from '$lib/components/map/map-layer-event-manager';
|
import type { MapLayerEventManager } from '$lib/components/map/map-layer-event-manager';
|
||||||
import { loadSVGIcon } from '$lib/utils';
|
import { loadSVGIcon } from '$lib/utils';
|
||||||
@@ -140,12 +140,12 @@ export class OverpassLayer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onHover(e: any) {
|
onHover(e: MapLayerMouseEvent) {
|
||||||
this.popup.setItem({
|
this.popup.setItem({
|
||||||
kind: 'overpass',
|
kind: 'overpass',
|
||||||
item: {
|
item: {
|
||||||
...e.features[0].properties,
|
...e.features![0].properties,
|
||||||
sym: overpassQueryData[e.features[0].properties.query].symbol ?? '',
|
sym: overpassQueryData[e.features![0].properties.query].symbol ?? '',
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -85,15 +85,23 @@ export class MapLibreGLMap {
|
|||||||
try {
|
try {
|
||||||
const request = `https://nominatim.openstreetmap.org/search?format=json&q=${config.query}&limit=5&accept-language=${language}`;
|
const request = `https://nominatim.openstreetmap.org/search?format=json&q=${config.query}&limit=5&accept-language=${language}`;
|
||||||
const response = await fetch(request);
|
const response = await fetch(request);
|
||||||
const geojson = await response.json();
|
const places: {
|
||||||
results.features = geojson.map((result: any) => {
|
lat: string;
|
||||||
|
lon: string;
|
||||||
|
type: string;
|
||||||
|
display_name: string;
|
||||||
|
}[] = await response.json();
|
||||||
|
results.features = places.map((result) => {
|
||||||
return {
|
return {
|
||||||
type: 'Feature',
|
type: 'Feature',
|
||||||
geometry: {
|
geometry: {
|
||||||
type: 'Point',
|
type: 'Point',
|
||||||
coordinates: [result.lon, result.lat],
|
coordinates: [Number(result.lon), Number(result.lat)],
|
||||||
},
|
},
|
||||||
|
properties: {},
|
||||||
|
text: result.display_name,
|
||||||
place_name: result.display_name,
|
place_name: result.display_name,
|
||||||
|
place_type: [result.type],
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
} catch {}
|
} catch {}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import {
|
|||||||
type MapLayerMouseEvent,
|
type MapLayerMouseEvent,
|
||||||
type VectorSourceSpecification,
|
type VectorSourceSpecification,
|
||||||
} from 'maplibre-gl';
|
} from 'maplibre-gl';
|
||||||
import { Viewer, type ViewerBearingEvent } from 'mapillary-js/dist/mapillary.module';
|
import { Viewer, type ViewerBearingEvent } from 'mapillary-js';
|
||||||
import 'mapillary-js/dist/mapillary.css';
|
import 'mapillary-js/dist/mapillary.css';
|
||||||
import { mapCursor, MapCursorState } from '$lib/state/map-cursor';
|
import { mapCursor, MapCursorState } from '$lib/state/map-cursor';
|
||||||
import { ANCHOR_LAYER_KEY } from '$lib/components/map/style';
|
import { ANCHOR_LAYER_KEY } from '$lib/components/map/style';
|
||||||
|
|||||||
@@ -125,7 +125,7 @@ export class StyleManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e.message);
|
console.error(e instanceof Error ? e.message : e);
|
||||||
}
|
}
|
||||||
this.merge(style, basemapStyle);
|
this.merge(style, basemapStyle);
|
||||||
style.sky ??= sky;
|
style.sky ??= sky;
|
||||||
@@ -196,7 +196,7 @@ export class StyleManager {
|
|||||||
}
|
}
|
||||||
this._pastOverlays.add(overlay);
|
this._pastOverlays.add(overlay);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e.message);
|
console.error(e instanceof Error ? e.message : e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
import { getURLForLanguage } from '$lib/utils';
|
import { getURLForLanguage } from '$lib/utils';
|
||||||
import { Trash2 } from '@lucide/svelte';
|
import { Trash2 } from '@lucide/svelte';
|
||||||
import { map } from '$lib/components/map/map';
|
import { map } from '$lib/components/map/map';
|
||||||
import type { GeoJSONSource, LngLat } from 'maplibre-gl';
|
import type { GeoJSONSource, LngLat, MapMouseEvent, MapTouchEvent } from 'maplibre-gl';
|
||||||
import { engine } from '$lib/engine';
|
import { engine } from '$lib/engine';
|
||||||
import { mapCursor, MapCursorState } from '$lib/state/map-cursor';
|
import { mapCursor, MapCursorState } from '$lib/state/map-cursor';
|
||||||
import { ANCHOR_LAYER_KEY } from '$lib/components/map/style';
|
import { ANCHOR_LAYER_KEY } from '$lib/components/map/style';
|
||||||
@@ -81,12 +81,12 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
let mousedown = false;
|
let mousedown = false;
|
||||||
function onMouseDown(e: any) {
|
function onMouseDown(e: MapMouseEvent | MapTouchEvent) {
|
||||||
mousedown = true;
|
mousedown = true;
|
||||||
rectangleCoordinates = [e.lngLat, e.lngLat];
|
rectangleCoordinates = [e.lngLat, e.lngLat];
|
||||||
}
|
}
|
||||||
|
|
||||||
function onMouseMove(e: any) {
|
function onMouseMove(e: MapMouseEvent | MapTouchEvent) {
|
||||||
if (mousedown) {
|
if (mousedown) {
|
||||||
rectangleCoordinates[1] = e.lngLat;
|
rectangleCoordinates[1] = e.lngLat;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import type { Popup } from 'maplibre-gl';
|
import type { MapMouseEvent, Popup } from 'maplibre-gl';
|
||||||
import * as Select from '$lib/components/ui/select';
|
import * as Select from '$lib/components/ui/select';
|
||||||
import { Switch } from '$lib/components/ui/switch';
|
import { Switch } from '$lib/components/ui/switch';
|
||||||
import { Label } from '$lib/components/ui/label/index.js';
|
import { Label } from '$lib/components/ui/label/index.js';
|
||||||
@@ -58,7 +58,7 @@
|
|||||||
// the tool works on files, routes, tracks and segments, not on waypoints
|
// the tool works on files, routes, tracks and segments, not on waypoints
|
||||||
let validSelection = $derived(coversSegments($selection));
|
let validSelection = $derived(coversSegments($selection));
|
||||||
|
|
||||||
function createFileWithPoint(e: any) {
|
function createFileWithPoint(e: MapMouseEvent) {
|
||||||
if ($selection.type === 'empty') {
|
if ($selection.type === 'empty') {
|
||||||
// the engine selects the new file, which starts with the trackpoint: one undo step
|
// the engine selects the new file, which starts with the trackpoint: one undo step
|
||||||
engine.newFile(newFileName(), { lng: e.lngLat.lng, lat: e.lngLat.lat });
|
engine.newFile(newFileName(), { lng: e.lngLat.lng, lat: e.lngLat.lat });
|
||||||
@@ -130,7 +130,7 @@
|
|||||||
{i18n._(`toolbar.routing.activities.${$routingProfile}`)}
|
{i18n._(`toolbar.routing.activities.${$routingProfile}`)}
|
||||||
</Select.Trigger>
|
</Select.Trigger>
|
||||||
<Select.Content>
|
<Select.Content>
|
||||||
{#each Object.keys(routingProfiles) as profile}
|
{#each Object.keys(routingProfiles) as profile (profile)}
|
||||||
<Select.Item value={profile}
|
<Select.Item value={profile}
|
||||||
>{i18n._(
|
>{i18n._(
|
||||||
`toolbar.routing.activities.${profile}`
|
`toolbar.routing.activities.${profile}`
|
||||||
|
|||||||
@@ -556,8 +556,9 @@ export class RoutingControls {
|
|||||||
let response;
|
let response;
|
||||||
try {
|
try {
|
||||||
response = await route(targets);
|
response = await route(targets);
|
||||||
} catch (e: any) {
|
} catch (e) {
|
||||||
toast.error(i18n._(e.message, e.message));
|
const message = e instanceof Error ? e.message : String(e);
|
||||||
|
toast.error(i18n._(message, message));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -802,7 +803,7 @@ export class RoutingControls {
|
|||||||
this.moveAnchorFeature(this.anchorWithId(this.anchors.length)!, position);
|
this.moveAnchorFeature(this.anchorWithId(this.anchors.length)!, position);
|
||||||
}
|
}
|
||||||
|
|
||||||
temporaryAnchorCloseToOtherAnchor(e: any) {
|
temporaryAnchorCloseToOtherAnchor(e: MapMouseEvent) {
|
||||||
const map_ = get(map);
|
const map_ = get(map);
|
||||||
if (!map_) {
|
if (!map_) {
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -131,7 +131,7 @@
|
|||||||
{i18n._('gpx.' + $splitAs)}
|
{i18n._('gpx.' + $splitAs)}
|
||||||
</Select.Trigger>
|
</Select.Trigger>
|
||||||
<Select.Content>
|
<Select.Content>
|
||||||
{#each splitTypes as splitType}
|
{#each splitTypes as splitType (splitType)}
|
||||||
<Select.Item value={splitType}>{i18n._('gpx.' + splitType)}</Select.Item>
|
<Select.Item value={splitType}>{i18n._('gpx.' + splitType)}</Select.Item>
|
||||||
{/each}
|
{/each}
|
||||||
</Select.Content>
|
</Select.Content>
|
||||||
|
|||||||
@@ -29,9 +29,9 @@ export class SplitControls {
|
|||||||
selection: Selection = { type: 'empty' };
|
selection: Selection = { type: 'empty' };
|
||||||
statistics: SelectionStatistics | undefined = undefined;
|
statistics: SelectionStatistics | undefined = undefined;
|
||||||
|
|
||||||
layerOnMouseEnterBinded: (e: any) => void = this.layerOnMouseEnter.bind(this);
|
layerOnMouseEnterBinded: () => void = this.layerOnMouseEnter.bind(this);
|
||||||
layerOnMouseLeaveBinded: () => void = this.layerOnMouseLeave.bind(this);
|
layerOnMouseLeaveBinded: () => void = this.layerOnMouseLeave.bind(this);
|
||||||
layerOnClickBinded: (e: any) => void = this.layerOnClick.bind(this);
|
layerOnClickBinded: (e: MapLayerMouseEvent) => void = this.layerOnClick.bind(this);
|
||||||
|
|
||||||
constructor(map: Map, layerEventManager: MapLayerEventManager) {
|
constructor(map: Map, layerEventManager: MapLayerEventManager) {
|
||||||
this.map = map;
|
this.map = map;
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
import { selectedWaypoint } from './waypoint';
|
import { selectedWaypoint } from './waypoint';
|
||||||
import { map } from '$lib/components/map/map';
|
import { map } from '$lib/components/map/map';
|
||||||
import { mapCursor, MapCursorState } from '$lib/state/map-cursor';
|
import { mapCursor, MapCursorState } from '$lib/state/map-cursor';
|
||||||
import { Marker } from 'maplibre-gl';
|
import { Marker, type MapMouseEvent } from 'maplibre-gl';
|
||||||
import { getSvgForSymbol } from '$lib/components/map/gpx-layer/gpx-layer';
|
import { getSvgForSymbol } from '$lib/components/map/gpx-layer/gpx-layer';
|
||||||
|
|
||||||
let props: {
|
let props: {
|
||||||
@@ -108,7 +108,7 @@
|
|||||||
reset();
|
reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
function setCoordinates(e: any) {
|
function setCoordinates(e: MapMouseEvent) {
|
||||||
if (
|
if (
|
||||||
$map?.queryRenderedFeatures(e.point, {
|
$map?.queryRenderedFeatures(e.point, {
|
||||||
layers: $map.getLayersOrder().filter((layerId) => layerId.endsWith('-waypoints')),
|
layers: $map.getLayersOrder().filter((layerId) => layerId.endsWith('-waypoints')),
|
||||||
@@ -117,8 +117,8 @@
|
|||||||
// Clicked on a waypoint, ignoring
|
// Clicked on a waypoint, ignoring
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
latitude = e.lngLat.lat.toFixed(6);
|
latitude = parseFloat(e.lngLat.lat.toFixed(6));
|
||||||
longitude = e.lngLat.lng.toFixed(6);
|
longitude = parseFloat(e.lngLat.lng.toFixed(6));
|
||||||
}
|
}
|
||||||
|
|
||||||
$effect(() => {
|
$effect(() => {
|
||||||
@@ -212,7 +212,7 @@
|
|||||||
</span>
|
</span>
|
||||||
</Select.Trigger>
|
</Select.Trigger>
|
||||||
<Select.Content class="max-h-60">
|
<Select.Content class="max-h-60">
|
||||||
{#each sortedSymbols as [key, symbol]}
|
{#each sortedSymbols as [key, symbol] (key)}
|
||||||
<Select.Item value={symbol.value}>
|
<Select.Item value={symbol.value}>
|
||||||
<span>
|
<span>
|
||||||
{#if symbol.icon}
|
{#if symbol.icon}
|
||||||
|
|||||||
@@ -56,6 +56,8 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#if href}
|
{#if href}
|
||||||
|
<!-- the href comes resolved (or external) from the users of the button -->
|
||||||
|
<!-- eslint-disable svelte/no-navigation-without-resolve -->
|
||||||
<a
|
<a
|
||||||
bind:this={ref}
|
bind:this={ref}
|
||||||
data-slot="button"
|
data-slot="button"
|
||||||
@@ -68,6 +70,7 @@
|
|||||||
>
|
>
|
||||||
{@render children?.()}
|
{@render children?.()}
|
||||||
</a>
|
</a>
|
||||||
|
<!-- eslint-enable svelte/no-navigation-without-resolve -->
|
||||||
{:else}
|
{:else}
|
||||||
<button
|
<button
|
||||||
bind:this={ref}
|
bind:this={ref}
|
||||||
|
|||||||
@@ -794,6 +794,14 @@ export const defaultOpacities: { [key: string]: number } = {
|
|||||||
|
|
||||||
export type LayerTreeType = { [key: string]: LayerTreeType | boolean };
|
export type LayerTreeType = { [key: string]: LayerTreeType | boolean };
|
||||||
|
|
||||||
|
/** A node of a layer tree that is a group of layers, not a layer (which is selected or not). */
|
||||||
|
export function layerGroup(node: LayerTreeType | boolean | undefined): LayerTreeType {
|
||||||
|
if (typeof node !== 'object') {
|
||||||
|
throw new Error('Not a group of layers');
|
||||||
|
}
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
|
||||||
// Hierarchy containing all basemaps
|
// Hierarchy containing all basemaps
|
||||||
export const basemapTree: LayerTreeType = {
|
export const basemapTree: LayerTreeType = {
|
||||||
basemaps: {
|
basemaps: {
|
||||||
@@ -1170,6 +1178,25 @@ export type CustomLayer = {
|
|||||||
value: string | StyleSpecification;
|
value: string | StyleSpecification;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** Whether a saved value is a custom layer, with all that the layers have had from the start. */
|
||||||
|
export function isCustomLayer(value: unknown): value is CustomLayer {
|
||||||
|
if (typeof value !== 'object' || value === null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
const layer: Partial<Record<keyof CustomLayer, unknown>> = value;
|
||||||
|
return (
|
||||||
|
typeof layer.id === 'string' &&
|
||||||
|
typeof layer.name === 'string' &&
|
||||||
|
Array.isArray(layer.tileUrls) &&
|
||||||
|
layer.tileUrls.every((url) => typeof url === 'string') &&
|
||||||
|
typeof layer.maxZoom === 'number' &&
|
||||||
|
(layer.layerType === 'basemap' || layer.layerType === 'overlay') &&
|
||||||
|
(layer.resourceType === 'raster' || layer.resourceType === 'vector') &&
|
||||||
|
(typeof layer.value === 'string' ||
|
||||||
|
(typeof layer.value === 'object' && layer.value !== null))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
type OverpassQueryData = {
|
type OverpassQueryData = {
|
||||||
icon: {
|
icon: {
|
||||||
svg: string;
|
svg: string;
|
||||||
|
|||||||
@@ -143,19 +143,25 @@ describe('errors', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('selection', () => {
|
describe('selection', () => {
|
||||||
|
/** The selected files, when files are selected. */
|
||||||
|
const selectedFiles = () => {
|
||||||
|
const selection = get(engine.selection);
|
||||||
|
return selection.type === 'file' ? selection.fileIds : [];
|
||||||
|
};
|
||||||
|
|
||||||
it('adds and toggles files', async () => {
|
it('adds and toggles files', async () => {
|
||||||
await load('simple', 'with_tracks', 'with_waypoint');
|
await load('simple', 'with_tracks', 'with_waypoint');
|
||||||
const [a, b, c] = get(engine.order);
|
const [a, b, c] = get(engine.order);
|
||||||
await engine.select([a]);
|
await engine.select([a]);
|
||||||
await engine.select([b], 'add');
|
await engine.select([b], 'add');
|
||||||
assert.deepEqual(new Set((get(engine.selection) as any).fileIds), new Set([a, b]));
|
assert.deepEqual(new Set(selectedFiles()), new Set([a, b]));
|
||||||
await engine.select([a], 'toggle');
|
await engine.select([a], 'toggle');
|
||||||
assert.deepEqual((get(engine.selection) as any).fileIds, [b]);
|
assert.deepEqual(selectedFiles(), [b]);
|
||||||
await engine.select([]);
|
await engine.select([]);
|
||||||
assert.deepEqual(get(engine.selection), { type: 'empty' });
|
assert.deepEqual(get(engine.selection), { type: 'empty' });
|
||||||
|
|
||||||
assert.equal(await engine.selectAll(), true);
|
assert.equal(await engine.selectAll(), true);
|
||||||
assert.deepEqual(new Set((get(engine.selection) as any).fileIds), new Set([a, b, c]));
|
assert.deepEqual(new Set(selectedFiles()), new Set([a, b, c]));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('selects tracks and segments of a file', async () => {
|
it('selects tracks and segments of a file', async () => {
|
||||||
|
|||||||
@@ -19,18 +19,23 @@ function sources(dir: string): string[] {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function has(dictionary: any, key: string): boolean {
|
/** The value at a key (`a.b.c`) of a dictionary, `undefined` if there is none. */
|
||||||
let value = dictionary;
|
function valueAt(dictionary: object, key: string): unknown {
|
||||||
|
let value: unknown = dictionary;
|
||||||
for (const part of key.split('.')) {
|
for (const part of key.split('.')) {
|
||||||
if (value === null || typeof value !== 'object' || !(part in value)) {
|
if (value === null || typeof value !== 'object' || !(part in value)) {
|
||||||
return false;
|
return undefined;
|
||||||
}
|
}
|
||||||
value = value[part];
|
value = (value as Record<string, unknown>)[part];
|
||||||
}
|
}
|
||||||
return typeof value === 'string';
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
function keysOf(dictionary: any, prefix = ''): string[] {
|
function has(dictionary: object, key: string): boolean {
|
||||||
|
return typeof valueAt(dictionary, key) === 'string';
|
||||||
|
}
|
||||||
|
|
||||||
|
function keysOf(dictionary: object, prefix = ''): string[] {
|
||||||
return Object.entries(dictionary).flatMap(([key, value]) =>
|
return Object.entries(dictionary).flatMap(([key, value]) =>
|
||||||
typeof value === 'object' && value !== null
|
typeof value === 'object' && value !== null
|
||||||
? keysOf(value, `${prefix}${key}.`)
|
? keysOf(value, `${prefix}${key}.`)
|
||||||
@@ -60,7 +65,7 @@ describe('translations', () => {
|
|||||||
|
|
||||||
it('have no empty text in english', () => {
|
it('have no empty text in english', () => {
|
||||||
const empty = keysOf(english).filter((key) => {
|
const empty = keysOf(english).filter((key) => {
|
||||||
const value = key.split('.').reduce((v: any, part) => v[part], english);
|
const value = valueAt(english, key);
|
||||||
return typeof value === 'string' && value.trim() === '';
|
return typeof value === 'string' && value.trim() === '';
|
||||||
});
|
});
|
||||||
assert.deepEqual(empty, []);
|
assert.deepEqual(empty, []);
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import { languages } from '$lib/i18n/languages';
|
import { languages } from '$lib/i18n/languages';
|
||||||
|
|
||||||
function localizeManifest(manifestTemplateData: any, language: string) {
|
function localizeManifest(manifestTemplateData: Record<string, unknown>, language: string) {
|
||||||
const localizedManifestFile = `static/${language}.manifest.webmanifest`;
|
const localizedManifestFile = `static/${language}.manifest.webmanifest`;
|
||||||
const localizedStringsFile = `src/locales/${language}.json`;
|
const localizedStringsFile = `src/locales/${language}.json`;
|
||||||
const localizedStrings = JSON.parse(fs.readFileSync(localizedStringsFile, 'utf8'));
|
const localizedStrings = JSON.parse(fs.readFileSync(localizedStringsFile, 'utf8'));
|
||||||
|
|||||||
@@ -1,13 +1,17 @@
|
|||||||
import assert from 'node:assert/strict';
|
import assert from 'node:assert/strict';
|
||||||
import { afterEach, beforeEach, describe, it } from 'node:test';
|
import { afterEach, beforeEach, describe, it } from 'node:test';
|
||||||
import { get } from 'svelte/store';
|
import { get } from 'svelte/store';
|
||||||
import type { LayerTreeType } from '$lib/data/layers';
|
import { isCustomLayer, type LayerTreeType } from '$lib/data/layers';
|
||||||
import {
|
import {
|
||||||
filterLayerTree,
|
filterLayerTree,
|
||||||
getArrayValidator,
|
getArrayValidator,
|
||||||
getLayerTreeValidator,
|
getLayerTreeValidator,
|
||||||
getLayerValidator,
|
getLayerValidator,
|
||||||
|
getListValidator,
|
||||||
|
getRecordValidator,
|
||||||
getValueValidator,
|
getValueValidator,
|
||||||
|
isNumber,
|
||||||
|
isString,
|
||||||
Setting,
|
Setting,
|
||||||
SettingInitOnFirstRead,
|
SettingInitOnFirstRead,
|
||||||
storedValue,
|
storedValue,
|
||||||
@@ -48,7 +52,9 @@ describe('validators', () => {
|
|||||||
const validate = getValueValidator(['metric', 'imperial'], 'metric');
|
const validate = getValueValidator(['metric', 'imperial'], 'metric');
|
||||||
assert.equal(validate('imperial'), 'imperial');
|
assert.equal(validate('imperial'), 'imperial');
|
||||||
assert.equal(validate('nautical'), 'metric');
|
assert.equal(validate('nautical'), 'metric');
|
||||||
assert.equal(validate(undefined as any), 'metric');
|
assert.equal(validate(undefined), 'metric');
|
||||||
|
assert.equal(validate(null), 'metric');
|
||||||
|
assert.equal(validate(3), 'metric');
|
||||||
const optional = getValueValidator<string | undefined>(['slope', undefined], undefined);
|
const optional = getValueValidator<string | undefined>(['slope', undefined], undefined);
|
||||||
assert.equal(optional('slope'), 'slope');
|
assert.equal(optional('slope'), 'slope');
|
||||||
assert.equal(optional('other'), undefined);
|
assert.equal(optional('other'), undefined);
|
||||||
@@ -60,6 +66,48 @@ describe('validators', () => {
|
|||||||
assert.deepEqual(validate([]), []);
|
assert.deepEqual(validate([]), []);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('keeps nothing of a saved value that is not a list', () => {
|
||||||
|
const validate = getArrayValidator(['hr', 'cad', 'power']);
|
||||||
|
for (const saved of [null, 'hr', 3, { 0: 'hr' }]) {
|
||||||
|
assert.deepEqual(validate(saved), []);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
it('keeps the items of a list that are what it holds', () => {
|
||||||
|
const validate = getListValidator(isString);
|
||||||
|
assert.deepEqual(validate(['a', 3, null, 'b']), ['a', 'b']);
|
||||||
|
assert.deepEqual(validate('a'), []);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('keeps the entries of a record that are what it holds, else takes the fallback', () => {
|
||||||
|
const fallback = { a: 0.5 };
|
||||||
|
const validate = getRecordValidator(isNumber, fallback);
|
||||||
|
assert.deepEqual(validate({ a: 0.4, b: 'x', c: 1 }), { a: 0.4, c: 1 });
|
||||||
|
for (const saved of [null, 3, ['a'], 'a']) {
|
||||||
|
assert.equal(validate(saved), fallback);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
it('recognizes a custom layer', () => {
|
||||||
|
const layer = {
|
||||||
|
id: 'custom-0',
|
||||||
|
name: 'Layer',
|
||||||
|
tileUrls: ['https://tiles/{z}/{x}/{y}.png'],
|
||||||
|
maxZoom: 20,
|
||||||
|
layerType: 'basemap',
|
||||||
|
resourceType: 'raster',
|
||||||
|
value: { version: 8, sources: {}, layers: [] },
|
||||||
|
};
|
||||||
|
assert.ok(isCustomLayer(layer));
|
||||||
|
assert.ok(isCustomLayer({ ...layer, resourceType: 'vector', value: 'https://style.json' }));
|
||||||
|
assert.ok(!isCustomLayer({ ...layer, layerType: 'other' }));
|
||||||
|
assert.ok(!isCustomLayer({ ...layer, tileUrls: [3] }));
|
||||||
|
assert.ok(!isCustomLayer({ ...layer, value: null }));
|
||||||
|
const { name: _name, ...nameless } = layer;
|
||||||
|
assert.ok(!isCustomLayer(nameless));
|
||||||
|
assert.ok(!isCustomLayer(null));
|
||||||
|
});
|
||||||
|
|
||||||
it('accepts the known layers, and the custom and extension ones', () => {
|
it('accepts the known layers, and the custom and extension ones', () => {
|
||||||
const validate = getLayerValidator({ libertyTopo: 'url', osm: 'url' }, 'libertyTopo');
|
const validate = getLayerValidator({ libertyTopo: 'url', osm: 'url' }, 'libertyTopo');
|
||||||
assert.equal(validate('osm'), 'osm');
|
assert.equal(validate('osm'), 'osm');
|
||||||
@@ -67,6 +115,9 @@ describe('validators', () => {
|
|||||||
assert.equal(validate('extension-some-id'), 'extension-some-id');
|
assert.equal(validate('extension-some-id'), 'extension-some-id');
|
||||||
assert.equal(validate('gone'), 'libertyTopo');
|
assert.equal(validate('gone'), 'libertyTopo');
|
||||||
assert.equal(validate('toString'), 'libertyTopo');
|
assert.equal(validate('toString'), 'libertyTopo');
|
||||||
|
for (const saved of [null, 3, ['osm'], { id: 'osm' }]) {
|
||||||
|
assert.equal(validate(saved), 'libertyTopo');
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -116,12 +167,33 @@ describe('layer trees', () => {
|
|||||||
a: false,
|
a: false,
|
||||||
b: false,
|
b: false,
|
||||||
});
|
});
|
||||||
|
// a branch saved for a layer, and values that are not choices
|
||||||
|
assert.deepEqual(filterLayerTree({ world: { a: { x: true }, b: 'yes' } }, allowed).world, {
|
||||||
|
a: true,
|
||||||
|
b: false,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('takes the defaults when what was saved is not a tree', () => {
|
||||||
|
for (const saved of [null, true, 'world', 3, ['world']]) {
|
||||||
|
assert.deepEqual(filterLayerTree(saved, allowed), allowed);
|
||||||
|
}
|
||||||
|
assert.deepEqual(
|
||||||
|
filterLayerTree({ world: null, old: null, other: [true] }, allowed),
|
||||||
|
allowed
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('does not share its branches with the allowed tree', () => {
|
||||||
|
const filtered = filterLayerTree({}, allowed);
|
||||||
|
(filtered.world as LayerTreeType).a = false;
|
||||||
|
assert.equal((allowed.world as LayerTreeType).a, true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Setting', () => {
|
describe('Setting', () => {
|
||||||
it('has its initial value until it is connected', () => {
|
it('has its initial value until it is connected', () => {
|
||||||
const setting = new Setting('key', 'initial');
|
const setting = new Setting('key', 'initial', getValueValidator(['initial'], 'initial'));
|
||||||
assert.equal(get(setting), 'initial');
|
assert.equal(get(setting), 'initial');
|
||||||
setting.connect({});
|
setting.connect({});
|
||||||
assert.equal(get(setting), 'initial');
|
assert.equal(get(setting), 'initial');
|
||||||
@@ -145,6 +217,19 @@ describe('Setting', () => {
|
|||||||
assert.deepEqual(saved, {});
|
assert.deepEqual(saved, {});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('takes a saved boolean or number of the type of its initial value', () => {
|
||||||
|
const flag = new Setting('flag', false);
|
||||||
|
flag.connect({ flag: 'true' });
|
||||||
|
assert.equal(get(flag), true);
|
||||||
|
flag.connect({ flag: '"yes"' });
|
||||||
|
assert.equal(get(flag), false);
|
||||||
|
const size = new SettingInitOnFirstRead('size', 170);
|
||||||
|
size.connect({ size: '240' });
|
||||||
|
assert.equal(get(size), 240);
|
||||||
|
size.connect({ size: 'null' });
|
||||||
|
assert.equal(get(size), 170);
|
||||||
|
});
|
||||||
|
|
||||||
it('saves what it is set to, when it changes', () => {
|
it('saves what it is set to, when it changes', () => {
|
||||||
const setting = new Setting('key', 1);
|
const setting = new Setting('key', 1);
|
||||||
setting.set(2);
|
setting.set(2);
|
||||||
@@ -160,13 +245,17 @@ describe('Setting', () => {
|
|||||||
|
|
||||||
it('always saves objects, which may have been changed in place', () => {
|
it('always saves objects, which may have been changed in place', () => {
|
||||||
const value = { a: 1 };
|
const value = { a: 1 };
|
||||||
const setting = new Setting('key', value);
|
const setting = new Setting('key', value, getRecordValidator(isNumber, value));
|
||||||
setting.set(value);
|
setting.set(value);
|
||||||
assert.deepEqual(saved, { key: '{"a":1}' });
|
assert.deepEqual(saved, { key: '{"a":1}' });
|
||||||
});
|
});
|
||||||
|
|
||||||
it('forgets what it saved when it has no value', () => {
|
it('forgets what it saved when it has no value', () => {
|
||||||
const setting = new Setting<string | undefined>('key', 'x');
|
const setting = new Setting<string | undefined>(
|
||||||
|
'key',
|
||||||
|
'x',
|
||||||
|
getValueValidator<string | undefined>(['x', undefined], undefined)
|
||||||
|
);
|
||||||
setting.set(undefined);
|
setting.set(undefined);
|
||||||
assert.equal(get(setting), undefined);
|
assert.equal(get(setting), undefined);
|
||||||
assert.ok('key' in saved);
|
assert.ok('key' in saved);
|
||||||
@@ -187,7 +276,11 @@ describe('Setting', () => {
|
|||||||
|
|
||||||
describe('SettingInitOnFirstRead', () => {
|
describe('SettingInitOnFirstRead', () => {
|
||||||
it('has no value until it is connected', () => {
|
it('has no value until it is connected', () => {
|
||||||
const setting = new SettingInitOnFirstRead('key', { a: true });
|
const setting = new SettingInitOnFirstRead(
|
||||||
|
'key',
|
||||||
|
{ a: true },
|
||||||
|
getLayerTreeValidator({ a: true })
|
||||||
|
);
|
||||||
assert.equal(get(setting), undefined);
|
assert.equal(get(setting), undefined);
|
||||||
setting.connect({});
|
setting.connect({});
|
||||||
assert.deepEqual(get(setting), { a: true });
|
assert.deepEqual(get(setting), { a: true });
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ export function useSettingsStorage(newStorage: SettingsStorage | undefined) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Reads the saved value of a setting, `undefined` if there is none or if it cannot be read. */
|
/** Reads the saved value of a setting, `undefined` if there is none or if it cannot be read. */
|
||||||
export function storedValue(stored: StoredSettings, key: string): { value: any } | undefined {
|
export function storedValue(stored: StoredSettings, key: string): { value: unknown } | undefined {
|
||||||
if (!Object.hasOwn(stored, key)) {
|
if (!Object.hasOwn(stored, key)) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
@@ -41,6 +41,26 @@ function save(key: string, value: unknown) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Makes a saved value one that the setting can hold: what was saved can be anything (an old
|
||||||
|
* format, a value that is not allowed anymore), the validator checks it.
|
||||||
|
*/
|
||||||
|
export type Validator<V> = (value: unknown) => V;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The validator of a setting: a boolean or a number can do without one, its saved value is then
|
||||||
|
* checked against the type of its initial value. The other settings say what they can hold: a
|
||||||
|
* string is often one of a few, an object has a shape.
|
||||||
|
*/
|
||||||
|
type ValidatorArgument<V> = [V] extends [boolean] | [number]
|
||||||
|
? [validator?: Validator<V>]
|
||||||
|
: [validator: Validator<V>];
|
||||||
|
|
||||||
|
/** Keeps a saved value that has the type of the initial one (a boolean or a number). */
|
||||||
|
function sameTypeAs<V>(initial: V): Validator<V> {
|
||||||
|
return (value) => (typeof value === typeof initial ? (value as V) : initial);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A setting: a store whose value is kept when it changes. `S` is what the store holds, which is
|
* A setting: a store whose value is kept when it changes. `S` is what the store holds, which is
|
||||||
* `V` or, for a setting that has no value until it is read, `V | undefined`.
|
* `V` or, for a setting that has no value until it is read, `V | undefined`.
|
||||||
@@ -48,9 +68,9 @@ function save(key: string, value: unknown) {
|
|||||||
abstract class SettingBase<V, S extends V | undefined> {
|
abstract class SettingBase<V, S extends V | undefined> {
|
||||||
protected _key: string;
|
protected _key: string;
|
||||||
protected _value: Writable<S>;
|
protected _value: Writable<S>;
|
||||||
protected _validator?: (value: V) => V;
|
protected _validator: Validator<V>;
|
||||||
|
|
||||||
protected constructor(key: string, initial: S, validator?: (value: V) => V) {
|
protected constructor(key: string, initial: S, validator: Validator<V>) {
|
||||||
this._key = key;
|
this._key = key;
|
||||||
this._value = writable(initial);
|
this._value = writable(initial);
|
||||||
this._validator = validator;
|
this._validator = validator;
|
||||||
@@ -59,7 +79,7 @@ abstract class SettingBase<V, S extends V | undefined> {
|
|||||||
/** The saved value, validated, `undefined` if there is none. */
|
/** The saved value, validated, `undefined` if there is none. */
|
||||||
protected saved(stored: StoredSettings): { value: V } | undefined {
|
protected saved(stored: StoredSettings): { value: V } | undefined {
|
||||||
const saved = storedValue(stored, this._key);
|
const saved = storedValue(stored, this._key);
|
||||||
return saved && { value: this._validator ? this._validator(saved.value) : saved.value };
|
return saved && { value: this._validator(saved.value) };
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Takes the saved value, if there is one. */
|
/** Takes the saved value, if there is one. */
|
||||||
@@ -83,8 +103,8 @@ abstract class SettingBase<V, S extends V | undefined> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class Setting<V> extends SettingBase<V, V> {
|
export class Setting<V> extends SettingBase<V, V> {
|
||||||
constructor(key: string, initial: V, validator?: (value: V) => V) {
|
constructor(key: string, initial: V, ...[validator]: ValidatorArgument<V>) {
|
||||||
super(key, initial, validator);
|
super(key, initial, validator ?? sameTypeAs(initial));
|
||||||
}
|
}
|
||||||
|
|
||||||
connect(stored: StoredSettings) {
|
connect(stored: StoredSettings) {
|
||||||
@@ -99,8 +119,8 @@ export class Setting<V> extends SettingBase<V, V> {
|
|||||||
export class SettingInitOnFirstRead<V> extends SettingBase<V, V | undefined> {
|
export class SettingInitOnFirstRead<V> extends SettingBase<V, V | undefined> {
|
||||||
private _initial: V;
|
private _initial: V;
|
||||||
|
|
||||||
constructor(key: string, initial: V, validator?: (value: V) => V) {
|
constructor(key: string, initial: V, ...[validator]: ValidatorArgument<V>) {
|
||||||
super(key, undefined, validator);
|
super(key, undefined, validator ?? sameTypeAs(initial));
|
||||||
this._initial = initial;
|
this._initial = initial;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -114,53 +134,90 @@ export class SettingInitOnFirstRead<V> extends SettingBase<V, V | undefined> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getValueValidator<V>(allowed: V[], fallback: V) {
|
/** Whether a value is one of the allowed ones. */
|
||||||
const dict = new Set<V>(allowed);
|
function oneOf<V>(allowed: V[]) {
|
||||||
return (value: V) => (dict.has(value) ? value : fallback);
|
const dict = new Set<unknown>(allowed);
|
||||||
|
return (value: unknown): value is V => dict.has(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getArrayValidator<V>(allowed: V[]) {
|
export function getValueValidator<V>(allowed: V[], fallback: V): Validator<V> {
|
||||||
const dict = new Set<V>(allowed);
|
const isAllowed = oneOf(allowed);
|
||||||
return (value: V[]) => value.filter((v) => dict.has(v));
|
return (value) => (isAllowed(value) ? value : fallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getLayerValidator(allowed: Record<string, any>, fallback: string) {
|
export function isString(value: unknown): value is string {
|
||||||
return (layer: string) =>
|
return typeof value === 'string';
|
||||||
Object.hasOwn(allowed, layer) ||
|
}
|
||||||
layer.startsWith('custom-') ||
|
|
||||||
layer.startsWith('extension-')
|
export function isNumber(value: unknown): value is number {
|
||||||
|
return typeof value === 'number';
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Keeps the items of a saved list that are what it holds, in their order; nothing if it is not a list. */
|
||||||
|
export function getListValidator<V>(isItem: (value: unknown) => value is V): Validator<V[]> {
|
||||||
|
return (value) => (Array.isArray(value) ? value.filter(isItem) : []);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Keeps the allowed values of a list, in their order; nothing if what was saved is not a list. */
|
||||||
|
export function getArrayValidator<V>(allowed: V[]): Validator<V[]> {
|
||||||
|
return getListValidator(oneOf(allowed));
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Keeps the entries of a saved record that are what it holds; `fallback` if it is not a record. */
|
||||||
|
export function getRecordValidator<V>(
|
||||||
|
isEntry: (value: unknown) => value is V,
|
||||||
|
fallback: Record<string, V>
|
||||||
|
): Validator<Record<string, V>> {
|
||||||
|
return (value) =>
|
||||||
|
isRecord(value)
|
||||||
|
? Object.fromEntries(
|
||||||
|
Object.entries(value).filter((entry): entry is [string, V] => isEntry(entry[1]))
|
||||||
|
)
|
||||||
|
: fallback;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getLayerValidator(
|
||||||
|
allowed: Record<string, unknown>,
|
||||||
|
fallback: string
|
||||||
|
): Validator<string> {
|
||||||
|
return (layer) =>
|
||||||
|
typeof layer === 'string' &&
|
||||||
|
(Object.hasOwn(allowed, layer) ||
|
||||||
|
layer.startsWith('custom-') ||
|
||||||
|
layer.startsWith('extension-'))
|
||||||
? layer
|
? layer
|
||||||
: fallback;
|
: fallback;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function filterLayerTree(
|
/** Whether a value is a record, which can hold the layers of a tree: an object, not null or a list. */
|
||||||
t: LayerTreeType,
|
function isRecord(value: unknown): value is Record<string, unknown> {
|
||||||
allowed: LayerTreeType | undefined
|
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
||||||
): LayerTreeType {
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The saved tree `t`, with the layers of `allowed`: the choices saved for them are kept, the new
|
||||||
|
* ones have their default, and of the others only the custom and extension layers are kept.
|
||||||
|
*/
|
||||||
|
export function filterLayerTree(t: unknown, allowed: LayerTreeType | undefined): LayerTreeType {
|
||||||
|
const tree = isRecord(t) ? t : {};
|
||||||
const filtered: LayerTreeType = {};
|
const filtered: LayerTreeType = {};
|
||||||
if (allowed) {
|
if (allowed) {
|
||||||
Object.entries(allowed).forEach(([key, value]) => {
|
Object.entries(allowed).forEach(([key, value]) => {
|
||||||
if (Object.hasOwn(t, key)) {
|
const saved = Object.hasOwn(tree, key) ? tree[key] : undefined;
|
||||||
if (typeof value === 'boolean') {
|
if (typeof value === 'boolean') {
|
||||||
filtered[key] = t[key];
|
filtered[key] = typeof saved === 'boolean' ? saved : value;
|
||||||
} else if (typeof value === 'object') {
|
|
||||||
filtered[key] = filterLayerTree(
|
|
||||||
typeof t[key] === 'object' ? t[key] : {},
|
|
||||||
value
|
|
||||||
);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
filtered[key] = value;
|
filtered[key] = filterLayerTree(saved, value);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
Object.entries(t).forEach(([key, value]) => {
|
Object.entries(tree).forEach(([key, value]) => {
|
||||||
if (!Object.hasOwn(filtered, key)) {
|
if (!Object.hasOwn(filtered, key)) {
|
||||||
if (typeof value === 'boolean') {
|
if (typeof value === 'boolean') {
|
||||||
if (key.startsWith('custom-') || key.startsWith('extension-')) {
|
if (key.startsWith('custom-') || key.startsWith('extension-')) {
|
||||||
filtered[key] = value;
|
filtered[key] = value;
|
||||||
}
|
}
|
||||||
} else if (typeof value === 'object') {
|
} else if (isRecord(value)) {
|
||||||
filtered[key] = filterLayerTree(value, undefined);
|
filtered[key] = filterLayerTree(value, undefined);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -168,6 +225,6 @@ export function filterLayerTree(
|
|||||||
return filtered;
|
return filtered;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getLayerTreeValidator(allowed: LayerTreeType) {
|
export function getLayerTreeValidator(allowed: LayerTreeType): Validator<LayerTreeType> {
|
||||||
return (value: LayerTreeType) => filterLayerTree(value, allowed);
|
return (value) => filterLayerTree(value, allowed);
|
||||||
}
|
}
|
||||||
@@ -8,8 +8,8 @@ import {
|
|||||||
defaultOverpassQueries,
|
defaultOverpassQueries,
|
||||||
defaultOverpassTree,
|
defaultOverpassTree,
|
||||||
defaultTerrainSource,
|
defaultTerrainSource,
|
||||||
|
isCustomLayer,
|
||||||
overpassTree,
|
overpassTree,
|
||||||
type CustomLayer,
|
|
||||||
} from '$lib/data/layers';
|
} from '$lib/data/layers';
|
||||||
import { browser } from '$app/environment';
|
import { browser } from '$app/environment';
|
||||||
import type { DistanceUnits, TemperatureUnits, VelocityUnits } from '$lib/units/conversions';
|
import type { DistanceUnits, TemperatureUnits, VelocityUnits } from '$lib/units/conversions';
|
||||||
@@ -19,7 +19,11 @@ import {
|
|||||||
getArrayValidator,
|
getArrayValidator,
|
||||||
getLayerTreeValidator,
|
getLayerTreeValidator,
|
||||||
getLayerValidator,
|
getLayerValidator,
|
||||||
|
getListValidator,
|
||||||
|
getRecordValidator,
|
||||||
getValueValidator,
|
getValueValidator,
|
||||||
|
isNumber,
|
||||||
|
isString,
|
||||||
Setting,
|
Setting,
|
||||||
SettingInitOnFirstRead,
|
SettingInitOnFirstRead,
|
||||||
useSettingsStorage,
|
useSettingsStorage,
|
||||||
@@ -136,10 +140,14 @@ export const settings = {
|
|||||||
defaultOverpassTree,
|
defaultOverpassTree,
|
||||||
getLayerTreeValidator(overpassTree)
|
getLayerTreeValidator(overpassTree)
|
||||||
),
|
),
|
||||||
opacities: new Setting('opacities', defaultOpacities),
|
opacities: new Setting(
|
||||||
customLayers: new Setting<Record<string, CustomLayer>>('customLayers', {}),
|
'opacities',
|
||||||
customBasemapOrder: new Setting<string[]>('customBasemapOrder', []),
|
defaultOpacities,
|
||||||
customOverlayOrder: new Setting<string[]>('customOverlayOrder', []),
|
getRecordValidator(isNumber, defaultOpacities)
|
||||||
|
),
|
||||||
|
customLayers: new Setting('customLayers', {}, getRecordValidator(isCustomLayer, {})),
|
||||||
|
customBasemapOrder: new Setting('customBasemapOrder', [], getListValidator(isString)),
|
||||||
|
customOverlayOrder: new Setting('customOverlayOrder', [], getListValidator(isString)),
|
||||||
terrainSource: new Setting<TerrainSource>(
|
terrainSource: new Setting<TerrainSource>(
|
||||||
'terrainSource',
|
'terrainSource',
|
||||||
defaultTerrainSource,
|
defaultTerrainSource,
|
||||||
@@ -165,16 +173,14 @@ export const settings = {
|
|||||||
),
|
),
|
||||||
/** Takes the saved values (see `Engine.openStorage`). */
|
/** Takes the saved values (see `Engine.openStorage`). */
|
||||||
connect(stored: StoredSettings) {
|
connect(stored: StoredSettings) {
|
||||||
for (const key in settings) {
|
for (const setting of Object.values(settings)) {
|
||||||
const setting = (settings as any)[key];
|
|
||||||
if (setting instanceof Setting || setting instanceof SettingInitOnFirstRead) {
|
if (setting instanceof Setting || setting instanceof SettingInitOnFirstRead) {
|
||||||
setting.connect(stored);
|
setting.connect(stored);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
initialize() {
|
initialize() {
|
||||||
for (const key in settings) {
|
for (const setting of Object.values(settings)) {
|
||||||
const setting = (settings as any)[key];
|
|
||||||
if (setting instanceof SettingInitOnFirstRead) {
|
if (setting instanceof SettingInitOnFirstRead) {
|
||||||
setting.initialize();
|
setting.initialize();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { clsx, type ClassValue } from 'clsx';
|
import { clsx, type ClassValue } from 'clsx';
|
||||||
import { twMerge } from 'tailwind-merge';
|
import { twMerge } from 'tailwind-merge';
|
||||||
import { base } from '$app/paths';
|
import { resolve } from '$app/paths';
|
||||||
import { languages } from '$lib/i18n/languages';
|
import { languages } from '$lib/i18n/languages';
|
||||||
import type { Coordinates } from '$lib/geo/coordinates';
|
import type { Coordinates } from '$lib/geo/coordinates';
|
||||||
import { LngLatBounds, type Map as MapLibreMap } from 'maplibre-gl';
|
import { LngLatBounds, type Map as MapLibreMap } from 'maplibre-gl';
|
||||||
@@ -130,8 +130,16 @@ export function isSafari() {
|
|||||||
return /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
|
return /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The path of a page in another language, without the base path (pass it to `resolve`). `path` is
|
||||||
|
* the path of the page, with or without the base path.
|
||||||
|
*/
|
||||||
export function getURLForLanguage(lang: string, path: string): string {
|
export function getURLForLanguage(lang: string, path: string): string {
|
||||||
let newPath = path.replace(base, '');
|
const base = resolve('/').slice(0, -1);
|
||||||
|
let newPath =
|
||||||
|
base && (path === base || path.startsWith(`${base}/`))
|
||||||
|
? path.slice(base.length) || '/'
|
||||||
|
: path;
|
||||||
|
|
||||||
let languageInPath = newPath.split('/')[1];
|
let languageInPath = newPath.split('/')[1];
|
||||||
if (!Object.hasOwn(languages, languageInPath)) {
|
if (!Object.hasOwn(languages, languageInPath)) {
|
||||||
@@ -144,17 +152,16 @@ export function getURLForLanguage(lang: string, path: string): string {
|
|||||||
|
|
||||||
if (languageInPath === 'en') {
|
if (languageInPath === 'en') {
|
||||||
if (lang === 'en') {
|
if (lang === 'en') {
|
||||||
return `${base}${newPath}`;
|
return newPath;
|
||||||
} else {
|
} else {
|
||||||
return `${base}/${lang}${newPath}`;
|
return `/${lang}${newPath}`;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (lang === 'en') {
|
if (lang === 'en') {
|
||||||
newPath = newPath.replace(`/${languageInPath}`, '');
|
newPath = newPath.replace(`/${languageInPath}`, '');
|
||||||
return newPath === '' ? `${base}/` : `${base}${newPath}`;
|
return newPath === '' ? '/' : newPath;
|
||||||
} else {
|
} else {
|
||||||
newPath = newPath.replace(`/${languageInPath}`, `/${lang}`);
|
return newPath.replace(`/${languageInPath}`, `/${lang}`);
|
||||||
return `${base}${newPath}`;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -7,7 +7,7 @@
|
|||||||
import Footer from '$lib/components/Footer.svelte';
|
import Footer from '$lib/components/Footer.svelte';
|
||||||
import { onMount, type Snippet } from 'svelte';
|
import { onMount, type Snippet } from 'svelte';
|
||||||
import { convertOldEmbeddingOptions } from '$lib/components/embedding/embedding';
|
import { convertOldEmbeddingOptions } from '$lib/components/embedding/embedding';
|
||||||
import { base } from '$app/paths';
|
import { resolve } from '$app/paths';
|
||||||
import { languages } from '$lib/i18n/languages';
|
import { languages } from '$lib/i18n/languages';
|
||||||
import { browser } from '$app/environment';
|
import { browser } from '$app/environment';
|
||||||
import { goto } from '$app/navigation';
|
import { goto } from '$app/navigation';
|
||||||
@@ -31,7 +31,7 @@
|
|||||||
let folders = page.url.pathname.split('/');
|
let folders = page.url.pathname.split('/');
|
||||||
let locale =
|
let locale =
|
||||||
folders.indexOf('l') >= 0 ? (folders[folders.indexOf('l') + 1] ?? 'en') : 'en';
|
folders.indexOf('l') >= 0 ? (folders[folders.indexOf('l') + 1] ?? 'en') : 'en';
|
||||||
window.location.href = `${getURLForLanguage(locale, '/embed')}?options=${encodeURIComponent(JSON.stringify(convertOldEmbeddingOptions(page.url.searchParams)))}`;
|
window.location.href = `${resolve(getURLForLanguage(locale, '/embed'))}?options=${encodeURIComponent(JSON.stringify(convertOldEmbeddingOptions(page.url.searchParams)))}`;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -43,7 +43,7 @@
|
|||||||
if (Object.hasOwn(languages, lang)) {
|
if (Object.hasOwn(languages, lang)) {
|
||||||
i18n.lang = lang;
|
i18n.lang = lang;
|
||||||
} else if (browser) {
|
} else if (browser) {
|
||||||
goto(`${base}/404`);
|
goto(resolve('/404'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (i18n.lang !== 'en') {
|
} else if (i18n.lang !== 'en') {
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import { resolve } from '$app/paths';
|
||||||
import { Button } from '$lib/components/ui/button';
|
import { Button } from '$lib/components/ui/button';
|
||||||
import Logo from '$lib/components/Logo.svelte';
|
import Logo from '$lib/components/Logo.svelte';
|
||||||
import { getURLForLanguage } from '$lib/utils';
|
import { getURLForLanguage } from '$lib/utils';
|
||||||
@@ -12,7 +13,7 @@
|
|||||||
<Logo class="h-40 my-3 animate-spin" style="animation-duration: 20000ms" iconOnly={true} />
|
<Logo class="h-40 my-3 animate-spin" style="animation-duration: 20000ms" iconOnly={true} />
|
||||||
<div class="w-full flex flex-row flex-wrap gap-3 justify-center">
|
<div class="w-full flex flex-row flex-wrap gap-3 justify-center">
|
||||||
<Button
|
<Button
|
||||||
href={getURLForLanguage(i18n.lang, '/')}
|
href={resolve(getURLForLanguage(i18n.lang, '/'))}
|
||||||
class="text-base w-1/4 min-w-fit rounded-full"
|
class="text-base w-1/4 min-w-fit rounded-full"
|
||||||
>
|
>
|
||||||
<House size="18" />
|
<House size="18" />
|
||||||
@@ -20,14 +21,14 @@
|
|||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
data-sveltekit-reload
|
data-sveltekit-reload
|
||||||
href={getURLForLanguage(i18n.lang, '/app')}
|
href={resolve(getURLForLanguage(i18n.lang, '/app'))}
|
||||||
class="text-base w-1/4 min-w-fit rounded-full"
|
class="text-base w-1/4 min-w-fit rounded-full"
|
||||||
>
|
>
|
||||||
<Map size="18" />
|
<Map size="18" />
|
||||||
{i18n._('homepage.app')}
|
{i18n._('homepage.app')}
|
||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
href={getURLForLanguage(i18n.lang, '/help')}
|
href={resolve(getURLForLanguage(i18n.lang, '/help'))}
|
||||||
class="text-base w-1/4 min-w-fit rounded-full"
|
class="text-base w-1/4 min-w-fit rounded-full"
|
||||||
>
|
>
|
||||||
<BookOpenText size="18" />
|
<BookOpenText size="18" />
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import { resolve } from '$app/paths';
|
||||||
import { Button } from '$lib/components/ui/button';
|
import { Button } from '$lib/components/ui/button';
|
||||||
import ElevationProfile from '$lib/components/elevation-profile/ElevationProfile.svelte';
|
import ElevationProfile from '$lib/components/elevation-profile/ElevationProfile.svelte';
|
||||||
import GPXStatistics from '$lib/components/GPXStatistics.svelte';
|
import GPXStatistics from '$lib/components/GPXStatistics.svelte';
|
||||||
@@ -58,7 +59,7 @@
|
|||||||
<div class="w-full flex flex-row xs:justify-center gap-3">
|
<div class="w-full flex flex-row xs:justify-center gap-3">
|
||||||
<Button
|
<Button
|
||||||
data-sveltekit-reload
|
data-sveltekit-reload
|
||||||
href={getURLForLanguage(i18n.lang, '/app')}
|
href={resolve(getURLForLanguage(i18n.lang, '/app'))}
|
||||||
class="w-1/3 min-w-fit"
|
class="w-1/3 min-w-fit"
|
||||||
>
|
>
|
||||||
<Map size="18" />
|
<Map size="18" />
|
||||||
@@ -66,7 +67,7 @@
|
|||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
variant="secondary"
|
variant="secondary"
|
||||||
href={getURLForLanguage(i18n.lang, '/help')}
|
href={resolve(getURLForLanguage(i18n.lang, '/help'))}
|
||||||
class="w-1/3 min-w-fit"
|
class="w-1/3 min-w-fit"
|
||||||
>
|
>
|
||||||
<BookOpenText size="18" />
|
<BookOpenText size="18" />
|
||||||
@@ -74,7 +75,10 @@
|
|||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<a href={getURLForLanguage(i18n.lang, '/app')} aria-label="Link to the web app.">
|
<a
|
||||||
|
href={resolve(getURLForLanguage(i18n.lang, '/app'))}
|
||||||
|
aria-label="Link to the web app."
|
||||||
|
>
|
||||||
<enhanced:img
|
<enhanced:img
|
||||||
src="/src/lib/assets/img/docs/getting-started/interface.webp"
|
src="/src/lib/assets/img/docs/getting-started/interface.webp"
|
||||||
alt="The gpx.studio interface."
|
alt="The gpx.studio interface."
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import { resolve } from '$app/paths';
|
||||||
import GPXLayers from '$lib/components/map/gpx-layer/GPXLayers.svelte';
|
import GPXLayers from '$lib/components/map/gpx-layer/GPXLayers.svelte';
|
||||||
import ElevationProfile from '$lib/components/elevation-profile/ElevationProfile.svelte';
|
import ElevationProfile from '$lib/components/elevation-profile/ElevationProfile.svelte';
|
||||||
import FileList from '$lib/components/file-list/FileList.svelte';
|
import FileList from '$lib/components/file-list/FileList.svelte';
|
||||||
@@ -79,7 +80,9 @@
|
|||||||
const saved = get(settings.language);
|
const saved = get(settings.language);
|
||||||
if (saved !== undefined && saved !== language) {
|
if (saved !== undefined && saved !== language) {
|
||||||
await goto(
|
await goto(
|
||||||
`${getURLForLanguage(saved, page.url.pathname)}${page.url.search}${page.url.hash}`,
|
resolve(
|
||||||
|
`${getURLForLanguage(saved, page.url.pathname)}${page.url.search}${page.url.hash}`
|
||||||
|
),
|
||||||
{ replaceState: true }
|
{ replaceState: true }
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import { resolve } from '$app/paths';
|
||||||
import { Button } from '$lib/components/ui/button';
|
import { Button } from '$lib/components/ui/button';
|
||||||
import AlgoliaDocSearch from '$lib/components/AlgoliaDocSearch.svelte';
|
import AlgoliaDocSearch from '$lib/components/AlgoliaDocSearch.svelte';
|
||||||
import { getURLForLanguage } from '$lib/utils';
|
import { getURLForLanguage } from '$lib/utils';
|
||||||
@@ -24,10 +25,10 @@
|
|||||||
<div class="mb-2">
|
<div class="mb-2">
|
||||||
<AlgoliaDocSearch />
|
<AlgoliaDocSearch />
|
||||||
</div>
|
</div>
|
||||||
{#each Object.keys(guides) as guide}
|
{#each Object.keys(guides) as guide (guide)}
|
||||||
<Button
|
<Button
|
||||||
variant="link"
|
variant="link"
|
||||||
href={getURLForLanguage(i18n.lang, `/help/${guide}`)}
|
href={resolve(getURLForLanguage(i18n.lang, `/help/${guide}`))}
|
||||||
class="min-h-5 h-fit p-0 w-fit border-none text-muted-foreground hover:text-foreground hover:no-underline font-normal hover:font-semibold items-start whitespace-normal {page
|
class="min-h-5 h-fit p-0 w-fit border-none text-muted-foreground hover:text-foreground hover:no-underline font-normal hover:font-semibold items-start whitespace-normal {page
|
||||||
.params.guide === guide
|
.params.guide === guide
|
||||||
? 'font-semibold text-foreground'
|
? 'font-semibold text-foreground'
|
||||||
@@ -35,10 +36,10 @@
|
|||||||
>
|
>
|
||||||
{data.guideTitles[guide]}
|
{data.guideTitles[guide]}
|
||||||
</Button>
|
</Button>
|
||||||
{#each guides[guide] as subGuide}
|
{#each guides[guide] as subGuide (subGuide)}
|
||||||
<Button
|
<Button
|
||||||
variant="link"
|
variant="link"
|
||||||
href={getURLForLanguage(i18n.lang, `/help/${guide}/${subGuide}`)}
|
href={resolve(getURLForLanguage(i18n.lang, `/help/${guide}/${subGuide}`))}
|
||||||
class="min-h-5 h-fit p-0 w-fit border-none text-muted-foreground hover:text-foreground hover:no-underline font-normal hover:font-semibold items-start whitespace-normal ml-3 {page
|
class="min-h-5 h-fit p-0 w-fit border-none text-muted-foreground hover:text-foreground hover:no-underline font-normal hover:font-semibold items-start whitespace-normal ml-3 {page
|
||||||
.params.guide ===
|
.params.guide ===
|
||||||
guide + '/' + subGuide
|
guide + '/' + subGuide
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import { resolve } from '$app/paths';
|
||||||
import { Button } from '$lib/components/ui/button';
|
import { Button } from '$lib/components/ui/button';
|
||||||
import { getURLForLanguage } from '$lib/utils';
|
import { getURLForLanguage } from '$lib/utils';
|
||||||
import { i18n } from '$lib/i18n/i18n.svelte';
|
import { i18n } from '$lib/i18n/i18n.svelte';
|
||||||
@@ -14,10 +15,10 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="grid grid-cols-1 sm:grid-cols-2 gap-3">
|
<div class="grid grid-cols-1 sm:grid-cols-2 gap-3">
|
||||||
{#each Object.keys(guides) as guide}
|
{#each Object.keys(guides) as guide (guide)}
|
||||||
<Button
|
<Button
|
||||||
variant="outline"
|
variant="outline"
|
||||||
href={getURLForLanguage(i18n.lang, `/help/${guide}`)}
|
href={resolve(getURLForLanguage(i18n.lang, `/help/${guide}`))}
|
||||||
class="min-h-36 h-full pt-6 pb-3 px-0"
|
class="min-h-36 h-full pt-6 pb-3 px-0"
|
||||||
>
|
>
|
||||||
<div class="flex flex-col w-full">
|
<div class="flex flex-col w-full">
|
||||||
@@ -28,10 +29,12 @@
|
|||||||
{data.guideTitles[guide]}
|
{data.guideTitles[guide]}
|
||||||
</div>
|
</div>
|
||||||
<div class="flex flex-row justify-center flex-wrap gap-x-6 px-6">
|
<div class="flex flex-row justify-center flex-wrap gap-x-6 px-6">
|
||||||
{#each guides[guide] as subGuide}
|
{#each guides[guide] as subGuide (subGuide)}
|
||||||
<Button
|
<Button
|
||||||
variant="link"
|
variant="link"
|
||||||
href={getURLForLanguage(i18n.lang, `/help/${guide}/${subGuide}`)}
|
href={resolve(
|
||||||
|
getURLForLanguage(i18n.lang, `/help/${guide}/${subGuide}`)
|
||||||
|
)}
|
||||||
class="min-h-8 h-fit min-w-24 px-0 py-1 text-muted-foreground text-base text-center whitespace-normal"
|
class="min-h-8 h-fit min-w-24 px-0 py-1 text-muted-foreground text-base text-center whitespace-normal"
|
||||||
>
|
>
|
||||||
{#if typeof guideIcons[subGuide] === 'string'}
|
{#if typeof guideIcons[subGuide] === 'string'}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import { resolve } from '$app/paths';
|
||||||
import { page } from '$app/state';
|
import { page } from '$app/state';
|
||||||
import { getNextGuide, getPreviousGuide } from '$lib/components/docs/docs';
|
import { getNextGuide, getPreviousGuide } from '$lib/components/docs/docs';
|
||||||
import DocsContainer from '$lib/components/docs/DocsContainer.svelte';
|
import DocsContainer from '$lib/components/docs/DocsContainer.svelte';
|
||||||
@@ -6,11 +7,15 @@
|
|||||||
import { getURLForLanguage } from '$lib/utils';
|
import { getURLForLanguage } from '$lib/utils';
|
||||||
import { ChevronLeft, ChevronRight, PenLine, CornerDownRight } from '@lucide/svelte';
|
import { ChevronLeft, ChevronRight, PenLine, CornerDownRight } from '@lucide/svelte';
|
||||||
import { i18n } from '$lib/i18n/i18n.svelte';
|
import { i18n } from '$lib/i18n/i18n.svelte';
|
||||||
|
import type { Component } from 'svelte';
|
||||||
|
|
||||||
let { data }: { data: { guideModule: any; guideTitles: Record<string, string> } } = $props();
|
let {
|
||||||
|
data,
|
||||||
|
}: { data: { guideModule: { default: Component }; guideTitles: Record<string, string> } } =
|
||||||
|
$props();
|
||||||
|
|
||||||
let previousGuide = $derived(getPreviousGuide(page.params.guide));
|
let previousGuide = $derived(getPreviousGuide(page.params.guide ?? ''));
|
||||||
let nextGuide = $derived(getNextGuide(page.params.guide));
|
let nextGuide = $derived(getNextGuide(page.params.guide ?? ''));
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="markdown flex flex-col gap-3">
|
<div class="markdown flex flex-col gap-3">
|
||||||
@@ -22,7 +27,7 @@
|
|||||||
<Button
|
<Button
|
||||||
variant="outline"
|
variant="outline"
|
||||||
class="mr-auto"
|
class="mr-auto"
|
||||||
href={getURLForLanguage(i18n.lang, `/help/${previousGuide}`)}
|
href={resolve(getURLForLanguage(i18n.lang, `/help/${previousGuide}`))}
|
||||||
>
|
>
|
||||||
<ChevronLeft size="14" class="mt-0.5" />
|
<ChevronLeft size="14" class="mt-0.5" />
|
||||||
{data.guideTitles[previousGuide]}
|
{data.guideTitles[previousGuide]}
|
||||||
@@ -32,7 +37,7 @@
|
|||||||
<Button
|
<Button
|
||||||
variant="outline"
|
variant="outline"
|
||||||
class="ml-auto"
|
class="ml-auto"
|
||||||
href={getURLForLanguage(i18n.lang, `/help/${nextGuide}`)}
|
href={resolve(getURLForLanguage(i18n.lang, `/help/${nextGuide}`))}
|
||||||
>
|
>
|
||||||
{data.guideTitles[nextGuide]}
|
{data.guideTitles[nextGuide]}
|
||||||
<ChevronRight size="14" class="mt-0.5" />
|
<ChevronRight size="14" class="mt-0.5" />
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
export const base = '';
|
|
||||||
export const assets = '';
|
|
||||||
export function resolve(path: string) {
|
export function resolve(path: string) {
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
export function asset(file: string) {
|
||||||
|
return file;
|
||||||
|
}
|
||||||
@@ -47,4 +47,8 @@ export default defineConfig({
|
|||||||
wasm(),
|
wasm(),
|
||||||
sveltekit(),
|
sveltekit(),
|
||||||
],
|
],
|
||||||
|
ssr: {
|
||||||
|
// their main entry is UMD, which has no named exports in Node: bundle their ESM build instead
|
||||||
|
noExternal: ['mapillary-js', 'sortablejs'],
|
||||||
|
},
|
||||||
});
|
});
|
||||||
Reference in new issue
Block a user