Migration to new Rust-based engine (#401)

* wasm first steps

* parsing start

* parsing continued

* progress

* progress

* progress

* progress

* progress

* progress

* progress

* progress

* fixes

* reorganize

* change type

* fix

* progress

* refactoring

* progress

* progress

* progress

* keep style info

* progress

* progress

* remove (copy) in name

* progress

* merge methods into 1

* splice

* progress

* progress

* progress

* cleaning

* progress

* progress

* progress

* visibility

* progress

* progress

* progress

* progress

* progress

* fixes

* progress

* fix markers

* fix

* progress

* progress

* progress

* progress

* progress

* progress

* small fix

* use engine info

* fix popups

* small fix

* progress

* progress

* progress

* clean tool

* handle self closing elements

* reduce data exchanges across boundary

* copy on wasm side to avoid any data corruption

* speed fix

* routing

* refactoring

* reverse

* reverse

* crop

* split

* merge

* progress

* time tool

* fix bounds for waypoints

* reduce

* fix reactivity

* handle corrupt time data

* export

* progress

* remove gpx js package

* remove todo

* update readme

* cleaning

* progress

* fix link fields

* remove unused fields

* refactoring and tests

* import and export of routes, ref #192

* per-chunk categories storage

* cross-tab sync

* outdated state

* refactoring

* reorder methods

* refactoring

* fix

* improve flow

* renaming

* progress

* progress

* fix

* progress

* per file history

* keep original flag

* use history variant

* fix

* progress

* file explorer

* progress

* fix

* sticky folders

* improved sticky folders

* fix sortable

* fix sortable

* fix

* fix tab size

* no file delete on desktop

* fix routing on other file

* fix sorting

* remember language

* open links in browser

* commit missing changes

* avoid selecting on resize

* clarify filename

* explorer actions

* fix folder styling

* drop anywhere in folder

* cleaning

* fixes

* remove focus-ring

* full screen

* small fix

* consistent highlight color

* improved preview

* performance improvements

* sparser data transfers

* sparser data transfers

* show popup once data is loaded

* fix routing control size

* fix

* sparse desktop build

* remove custom ign styles

* use new endpoint for openhikingmap

* strip native menu

* reorder context menu items

* route full support

* route - track conversion

* create route file action

* route export, filter out anchors at high zoom level

* clarify name handling

* move hide & center to view

* routes continued

* update docs

* fix power format, closes #378

* lint fixes

* fix display of additional data with gaps, closes #361

* fix linting issues

* fix import modules

* fix multidrag

* change base to resolve

* fix type errors

* fix layer typings

* fix last type error

* each keys

* improve typings

* deploy to cloudflare

---------

Co-authored-by: vcoppe <vcoppe@hexaly.com>
This commit is contained in:
vcoppeandvcoppe authored and GitHub committed 2026-10-31 18:08:22 +01:00
1 parent 6a0d434371
commit 8fe7d8d64d
484 files changed
+53949 -41152

No files matched your search

@@ -17,113 +17,140 @@
Maximize,
Scissors,
FileStack,
FileX,
Route,
ArrowRightLeft,
} from '@lucide/svelte';
import {
ListFileItem,
ListLevel,
ListTrackItem,
ListWaypointItem,
type ListItem,
} from './file-list';
import { getContext } from 'svelte';
import { GPXTreeElement, Track, type AnyGPXTreeElement, Waypoint, GPXFile } from 'gpx';
import { i18n } from '$lib/i18n.svelte';
import { getContext, untrack } from 'svelte';
import { i18n } from '$lib/i18n/i18n.svelte';
import MetadataDialog from '$lib/components/file-list/metadata/MetadataDialog.svelte';
import { editMetadata } from '$lib/components/file-list/metadata/utils.svelte';
import StyleDialog from '$lib/components/file-list/style/StyleDialog.svelte';
import { editStyle } from '$lib/components/file-list/style/utils.svelte';
import { getSymbolKey, symbols } from '$lib/assets/symbols';
import { selection, copied, cut } from '$lib/logic/selection';
import { fileActions, pasteSelection } from '$lib/logic/file-actions';
import { allHidden } from '$lib/logic/hidden';
import { boundsManager } from '$lib/logic/bounds';
import { gpxColors, gpxLayers } from '$lib/components/map/gpx-layer/gpx-layers';
import { fileStateCollection } from '$lib/logic/file-state';
import { getSymbolKey, symbols } from '$lib/data/symbols';
import { engine, type FileState } from '$lib/engine';
import { allHidden, selectedFilesConversion } from '$lib/engine/selection-stores';
import { normalizeColor } from '$lib/engine/file-colors';
import { isHidden } from '$lib/engine/file-visibility';
import {
elementId,
isInClipboard,
isSelected,
pathInfo,
selectedElementIds,
selectedFileIds,
selectionSize,
type FileTreeNode,
} from '$lib/engine/selection-helpers';
import { boundsManager } from '$lib/state/bounds';
import { closeFiles } from '$lib/actions/file-actions';
import { waypointPopup } from '$lib/components/map/gpx-layer/gpx-layer-popup';
import { allowedPastes } from './sortable-file-list';
let {
fileState,
node,
item,
label,
}: {
node: GPXTreeElement<AnyGPXTreeElement> | Waypoint[] | Waypoint;
item: ListItem;
fileState: FileState;
node: FileTreeNode;
label: string | undefined;
} = $props();
const { selection, clipboard, canPaste, workspace } = engine;
let orientation = getContext<'vertical' | 'horizontal'>('orientation');
let embedding = getContext<boolean>('embedding');
let singleSelection = $derived($selection.size === 1);
let level = $derived(node.type);
let singleSelection = $derived(selectionSize($selection) === 1);
// a route or a track: it has a name, a description and a style, like a file
let isPath = $derived(node.type === 'route' || node.type === 'track');
let nodeColors: string[] = $derived.by(() => {
let colors: string[] = [];
if (node) {
if (node instanceof GPXFile) {
let defaultColor = $gpxColors.get(item.getFileId());
let style = node.getStyle(defaultColor);
colors = style.color;
} else if (node instanceof Track) {
let style = node.getStyle();
if (
style &&
style['gpx_style:color'] &&
!colors.includes(style['gpx_style:color'])
) {
colors.push(style['gpx_style:color']);
}
if (colors.length === 0) {
let defaultColor = $gpxColors.get(item.getFileId());
if (defaultColor) {
colors.push(defaultColor);
}
}
}
const { routes, tracks } = fileState.structure;
if (node.type === 'file') {
// the colors defined by the routes and tracks, or else the one of the file
const colors = [
...new Set(
[...routes, ...tracks].flatMap((path) =>
path.color !== undefined ? [normalizeColor(path.color)] : []
)
),
];
return colors.length > 0 ? colors : [fileState.color];
} else if (isPath) {
const color = pathInfo(fileState.structure, node)?.color;
return [color !== undefined ? normalizeColor(color) : fileState.color];
}
return colors;
return [];
});
let symbolKey = $derived(node instanceof Waypoint ? getSymbolKey(node.sym) : undefined);
let openEditMetadata: boolean = $derived(
editMetadata.current && singleSelection && $selection.has(item)
let symbolKey = $derived(
node.type === 'waypoint'
? getSymbolKey(fileState.structure.waypoints.find((w) => w.id === node.waypointId)?.sym)
: undefined
);
let selected = $derived(isSelected($selection, node));
let openEditMetadata: boolean = $derived(editMetadata.current && singleSelection && selected);
let openEditStyle: boolean = $derived(
editStyle.current &&
$selection.has(item) &&
$selection.getSelected().findIndex((i) => i.getFullId() === item.getFullId()) === 0
selected &&
selectedElementIds($selection)[0]?.ids[0] === elementId(node)
);
$effect(() => {
// the file is open for good once its info or its appearance is (the desktop app)
if (openEditMetadata || openEditStyle) {
untrack(() => engine.keepPreview([node.fileId]));
}
});
let hidden = $derived(
item.level === ListLevel.WAYPOINTS ? node._data.hiddenWpt : node._data.hidden
// the desktop app: the files are linked to the file system, they are closed rather than deleted
let desktop = $derived($workspace !== undefined);
// the file is not the one on the disk (the desktop app)
let unsaved = $derived(node.type === 'file' && $workspace?.files[node.fileId]?.dirty === true);
// the file is open as a preview, which the next one replaces (the desktop app)
let preview = $derived(
node.type === 'file' && $workspace?.files[node.fileId]?.preview === true
);
let hidden = $derived(isHidden(fileState, elementId(node)));
// cut elements are greyed until they are pasted
let isCut = $derived($clipboard?.cut === true && isInClipboard($clipboard, node));
</script>
<!-- svelte-ignore a11y_click_events_have_key_events -->
<!-- svelte-ignore a11y_no_static_element_interactions -->
<ContextMenu.Root
onOpenChange={(open) => {
if (open) {
if (!$selection.has(item)) {
selection.selectItem(item);
// the file is open for good once its menu is (the desktop app)
engine.keepPreview([node.fileId]);
if (!selected) {
engine.selectNode(node);
}
}
}}
>
<ContextMenu.Trigger class="grow truncate">
<!-- A tab of the horizontal list is as wide as its content, said explicitly: a width that is a
percentage of a parent that is as wide as its content is not updated by WebKit when the
content changes (the indicators come and go) -->
<!-- it only catches right-clicks: no focus ring when it has the focus (WebKit gives it on a
click), the selection shows where the arrow keys are -->
<ContextMenu.Trigger class="outline-none {orientation === 'vertical' ? 'grow truncate' : ''}">
<Button
variant="ghost"
class="relative w-full p-0 overflow-hidden border-none focus-visible:ring-0 focus-visible:ring-offset-0 flex flex-row {orientation ===
class="relative p-0 overflow-hidden border-none focus-visible:ring-0 focus-visible:ring-offset-0 flex flex-row {orientation ===
'vertical'
? 'h-7'
: 'h-9 px-1.5'} pointer-events-auto"
? 'w-full h-7'
: 'w-max h-9 px-1.5'} pointer-events-auto"
>
{#if item instanceof ListFileItem || item instanceof ListTrackItem}
<MetadataDialog bind:open={openEditMetadata} {node} {item} />
<StyleDialog bind:open={openEditStyle} {item} />
{#if node.type === 'file' || isPath}
<MetadataDialog bind:open={openEditMetadata} {fileState} {node} />
<StyleDialog bind:open={openEditStyle} {fileState} {node} />
{/if}
{#if item.level === ListLevel.FILE || item.level === ListLevel.TRACK}
{#if level === 'file' || isPath}
<div
class="absolute {orientation === 'vertical'
? 'top-0 bottom-0 right-0 w-1'
@@ -139,9 +166,9 @@
></div>
{/if}
<span
class="grow text-left truncate ml-1 flex flex-row items-center {hidden
? 'text-muted-foreground'
: ''} {$cut && $copied?.some((i) => i.getFullId() === item.getFullId())
class="grow text-left ml-1 flex flex-row items-center {orientation === 'vertical'
? 'truncate'
: 'whitespace-nowrap'} {hidden ? 'text-muted-foreground' : ''} {isCut
? 'text-muted-foreground'
: ''}"
oncontextmenu={(e) => {
@@ -154,37 +181,32 @@
// Add to selection instead of opening context menu
e.preventDefault();
e.stopPropagation();
$selection.toggle(item);
$selection = $selection;
engine.selectNode(node, 'toggle');
}
}}
onmouseenter={() => {
if (item instanceof ListWaypointItem) {
let layer = gpxLayers.getLayer(item.getFileId());
let file = fileStateCollection.getFile(item.getFileId());
if (layer && file) {
let waypoint = file.wpt[item.getWaypointIndex()];
if (waypoint && !waypoint._data.hidden) {
waypointPopup?.setItem({
item: waypoint,
fileId: item.getFileId(),
});
}
onmouseenter={async () => {
if (node.type === 'waypoint' && !isHidden(fileState, node.waypointId)) {
const waypoint = await engine.waypoint(node.fileId, node.waypointId);
if (waypoint) {
waypointPopup?.setItem({
item: waypoint,
kind: 'waypoint',
fileId: node.fileId,
});
}
}
}}
onmouseleave={() => {
if (item instanceof ListWaypointItem) {
let layer = gpxLayers.getLayer(item.getFileId());
if (layer) {
waypointPopup?.setItem(null);
}
if (node.type === 'waypoint') {
waypointPopup?.setItem(null);
}
}}
>
{#if item.level === ListLevel.SEGMENT}
{#if level === 'route'}
<Route size="16" class="mx-1 shrink-0" />
{:else if level === 'segment'}
<Waypoints size="16" class="mx-1 shrink-0" />
{:else if item.level === ListLevel.WAYPOINT}
{:else if level === 'waypoint'}
{#if symbolKey && symbols[symbolKey].icon}
{@const SymbolIcon = symbols[symbolKey].icon}
<SymbolIcon size="16" class="mx-1 shrink-0" />
@@ -192,26 +214,38 @@
<MapPin size="16" class="mx-1 shrink-0" />
{/if}
{/if}
<!-- a tab of the horizontal list is as wide as its content: the name is not cut -->
<span
class="grow select-none truncate {orientation === 'vertical'
? 'last:mr-2'
: ''}"
class:italic={preview}
class="grow select-none {orientation === 'vertical'
? 'truncate last:mr-2'
: 'shrink-0'}"
>
{label}
</span>
{#if hidden}
<EyeOff
size="10"
class="shrink-0 size-3.5 ml-1 {orientation === 'vertical'
{#if unsaved || hidden}
<span
class="flex flex-row items-center gap-1 shrink-0 pl-1 {orientation ===
'vertical'
? 'mr-3'
: 'mt-0.5'}"
/>
: ''}"
>
{#if unsaved}
<span class="size-1.5 rounded-full bg-foreground"></span>
{/if}
{#if hidden}
<EyeOff
size="10"
class="size-3.5 {orientation === 'vertical' ? '' : 'mt-0.5'}"
/>
{/if}
</span>
{/if}
</span>
</Button>
</ContextMenu.Trigger>
<ContextMenu.Content>
{#if item instanceof ListFileItem || item instanceof ListTrackItem}
{#if node.type === 'file' || isPath}
<ContextMenu.Item
disabled={!singleSelection}
onclick={() => (editMetadata.current = true)}
@@ -224,16 +258,53 @@
<PaintBucket size="16" />
{i18n._('menu.style.button')}
</ContextMenu.Item>
<ContextMenu.Separator />
{/if}
<ContextMenu.Item
onclick={() => {
if ($allHidden) {
fileActions.setHiddenToSelection(false);
} else {
fileActions.setHiddenToSelection(true);
}
}}
>
{#if orientation === 'vertical'}
{#if node.type === 'file'}
<ContextMenu.Item disabled={!singleSelection} onclick={() => engine.newTrack()}>
<Plus size="16" />
{i18n._('menu.new_track')}
</ContextMenu.Item>
<ContextMenu.Item disabled={!singleSelection} onclick={() => engine.newRoute()}>
<Plus size="16" />
{i18n._('menu.new_route')}
</ContextMenu.Item>
{:else if node.type === 'track'}
<ContextMenu.Item
disabled={!singleSelection}
onclick={() => engine.newTrackSegment()}
>
<Plus size="16" />
{i18n._('menu.new_segment')}
</ContextMenu.Item>
{/if}
{#if isPath || node.type === 'segment'}
<ContextMenu.Item onclick={() => engine.convert()}>
<ArrowRightLeft size="16" />
{i18n._(
node.type === 'route' ? 'menu.convert_to_track' : 'menu.convert_to_route'
)}
</ContextMenu.Item>
<ContextMenu.Separator />
{/if}
{/if}
{#if node.type === 'file'}
{#if $selectedFilesConversion}
<ContextMenu.Item onclick={() => engine.convert()}>
<ArrowRightLeft size="16" />
{i18n._(
$selectedFilesConversion === 'route'
? 'menu.convert_to_routes'
: 'menu.convert_to_tracks'
)}
</ContextMenu.Item>
{/if}
{#if orientation === 'vertical' || $selectedFilesConversion}
<ContextMenu.Separator />
{/if}
{/if}
<ContextMenu.Item onclick={() => engine.setSelectionHidden(!$allHidden)}>
{#if $allHidden}
<Eye size="16" />
{i18n._('menu.unhide')}
@@ -243,74 +314,55 @@
{/if}
<Shortcut key="H" ctrl={true} />
</ContextMenu.Item>
<ContextMenu.Separator />
{#if orientation === 'vertical'}
{#if item instanceof ListFileItem}
<ContextMenu.Item
disabled={!singleSelection}
onclick={() => fileActions.addNewTrack(item.getFileId())}
>
<Plus size="16" />
{i18n._('menu.new_track')}
</ContextMenu.Item>
<ContextMenu.Separator />
{:else if item instanceof ListTrackItem}
<ContextMenu.Item
disabled={!singleSelection}
onclick={() =>
fileActions.addNewSegment(item.getFileId(), item.getTrackIndex())}
>
<Plus size="16" />
{i18n._('menu.new_segment')}
</ContextMenu.Item>
<ContextMenu.Separator />
{/if}
{/if}
{#if item.level !== ListLevel.WAYPOINTS}
<ContextMenu.Item onclick={() => selection.selectAll()}>
<FileStack size="16" />
{i18n._('menu.select_all')}
<Shortcut key="A" ctrl={true} />
</ContextMenu.Item>
{/if}
<ContextMenu.Item onclick={() => boundsManager.centerMapOnSelection()}>
<Maximize size="16" />
{i18n._('menu.center')}
<Shortcut key="⏎" ctrl={true} />
</ContextMenu.Item>
{#if level !== 'waypoints'}
<ContextMenu.Separator />
<ContextMenu.Item onclick={() => engine.selectAll()}>
<FileStack size="16" />
{i18n._('menu.select_all')}
<Shortcut key="A" ctrl={true} />
</ContextMenu.Item>
{/if}
<ContextMenu.Separator />
<ContextMenu.Item onclick={fileActions.duplicateSelection}>
<ContextMenu.Item onclick={() => engine.duplicate()}>
<Copy size="16" />
{i18n._('menu.duplicate')}
<Shortcut key="D" ctrl={true} />
</ContextMenu.Item>
{#if orientation === 'vertical'}
<ContextMenu.Item onclick={() => selection.copySelection()}>
<ContextMenu.Item onclick={() => engine.copy()}>
<ClipboardCopy size="16" />
{i18n._('menu.copy')}
<Shortcut key="C" ctrl={true} />
</ContextMenu.Item>
<ContextMenu.Item onclick={() => selection.cutSelection()}>
<ContextMenu.Item onclick={() => engine.cut()}>
<Scissors size="16" />
{i18n._('menu.cut')}
<Shortcut key="X" ctrl={true} />
</ContextMenu.Item>
<ContextMenu.Item
disabled={$copied === undefined ||
$copied.length === 0 ||
!allowedPastes[$copied[0].level].includes(item.level)}
onclick={pasteSelection}
>
<ContextMenu.Item disabled={!$canPaste} onclick={() => engine.paste()}>
<ClipboardPaste size="16" />
{i18n._('menu.paste')}
<Shortcut key="V" ctrl={true} />
</ContextMenu.Item>
{/if}
<ContextMenu.Separator />
<ContextMenu.Item onclick={fileActions.deleteSelection}>
<Trash2 size="16" />
{i18n._('menu.delete')}
<Shortcut key="⌫" ctrl={true} />
</ContextMenu.Item>
{#if desktop && node.type === 'file'}
<ContextMenu.Item onclick={() => closeFiles(selectedFileIds($selection))}>
<FileX size="16" />
{i18n._('menu.close')}
<Shortcut key="W" ctrl={true} />
</ContextMenu.Item>
{:else}
<ContextMenu.Item onclick={() => engine.delete()}>
<Trash2 size="16" />
{i18n._('menu.delete')}
<Shortcut key="⌫" ctrl={true} />
</ContextMenu.Item>
{/if}
</ContextMenu.Content>
</ContextMenu.Root>