@sdxc/ui 2026.11.18 → 2026.11.26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +133 -1
- package/dist/app/index.d.ts +1 -0
- package/dist/app/index.js +1 -0
- package/dist/app/mixins/command-palette.js +10 -2
- package/dist/app/mixins/log-viewer.js +17 -14
- package/dist/app/mixins/route-dialog.d.ts +17 -0
- package/dist/app/mixins/route-dialog.js +53 -0
- package/dist/app/optimistic-toggle.js +6 -0
- package/dist/app/route-dialog.d.ts +38 -0
- package/dist/app/route-dialog.js +49 -0
- package/dist/audio/equalizer.d.ts +24 -0
- package/dist/audio/equalizer.js +57 -0
- package/dist/audio/index.d.ts +16 -0
- package/dist/audio/index.js +16 -0
- package/dist/audio/media-tile.d.ts +38 -0
- package/dist/audio/media-tile.js +98 -0
- package/dist/audio/player-bar.d.ts +108 -0
- package/dist/audio/player-bar.js +338 -0
- package/dist/audio/queue-list.d.ts +56 -0
- package/dist/audio/queue-list.js +102 -0
- package/dist/audio/track-list.d.ts +91 -0
- package/dist/audio/track-list.js +226 -0
- package/dist/audio/utils/media-session.d.ts +44 -0
- package/dist/audio/utils/media-session.js +87 -0
- package/dist/audio/utils/play-queue.d.ts +98 -0
- package/dist/audio/utils/play-queue.js +149 -0
- package/dist/audio/utils/track-time.d.ts +28 -0
- package/dist/audio/utils/track-time.js +36 -0
- package/dist/chat/composer-format.d.ts +35 -0
- package/dist/chat/composer-format.js +84 -0
- package/dist/chat/index.d.ts +6 -0
- package/dist/chat/index.js +6 -0
- package/dist/chat/mention-menu.d.ts +43 -0
- package/dist/chat/mention-menu.js +70 -0
- package/dist/chat/message-group.d.ts +92 -0
- package/dist/chat/message-group.js +222 -0
- package/dist/chat/mixins/composer-format.d.ts +28 -0
- package/dist/chat/mixins/composer-format.js +80 -0
- package/dist/chat/mixins/composer-send.d.ts +2 -2
- package/dist/chat/mixins/composer-send.js +4 -2
- package/dist/chat/mixins/mention-menu.d.ts +41 -0
- package/dist/chat/mixins/mention-menu.js +213 -0
- package/dist/chat/mixins/reaction-sync.d.ts +47 -0
- package/dist/chat/mixins/reaction-sync.js +172 -0
- package/dist/chat/reaction-bar.d.ts +70 -0
- package/dist/chat/reaction-bar.js +108 -0
- package/dist/chat/typing-indicator.d.ts +42 -0
- package/dist/chat/typing-indicator.js +68 -0
- package/dist/chat/utils/composer-text.d.ts +38 -0
- package/dist/chat/utils/composer-text.js +86 -0
- package/dist/chat/utils/markdown-format.d.ts +30 -0
- package/dist/chat/utils/markdown-format.js +158 -0
- package/dist/chat/utils/mention-query.d.ts +55 -0
- package/dist/chat/utils/mention-query.js +60 -0
- package/dist/commerce/cart-drawer.d.ts +69 -0
- package/dist/commerce/cart-drawer.js +163 -0
- package/dist/commerce/cart-line.d.ts +32 -0
- package/dist/commerce/cart-line.js +43 -0
- package/dist/commerce/checkout-layout.d.ts +32 -0
- package/dist/commerce/checkout-layout.js +51 -0
- package/dist/commerce/facet-filters.d.ts +121 -0
- package/dist/commerce/facet-filters.js +318 -0
- package/dist/commerce/fulfilment-note.d.ts +28 -0
- package/dist/commerce/fulfilment-note.js +26 -0
- package/dist/commerce/index.d.ts +27 -0
- package/dist/commerce/index.js +27 -0
- package/dist/commerce/item-options-dialog.d.ts +67 -0
- package/dist/commerce/item-options-dialog.js +150 -0
- package/dist/commerce/menu-item-card.d.ts +37 -0
- package/dist/commerce/menu-item-card.js +96 -0
- package/dist/commerce/option-group.d.ts +62 -0
- package/dist/commerce/option-group.js +121 -0
- package/dist/commerce/order-summary.d.ts +42 -0
- package/dist/commerce/order-summary.js +76 -0
- package/dist/commerce/order-tracker.d.ts +80 -0
- package/dist/commerce/order-tracker.js +178 -0
- package/dist/commerce/price.d.ts +52 -0
- package/dist/commerce/price.js +108 -0
- package/dist/commerce/product-card.d.ts +53 -0
- package/dist/commerce/product-card.js +127 -0
- package/dist/commerce/product-gallery.d.ts +70 -0
- package/dist/commerce/product-gallery.js +186 -0
- package/dist/commerce/promo-code.d.ts +56 -0
- package/dist/commerce/promo-code.js +101 -0
- package/dist/commerce/quantity-stepper.d.ts +42 -0
- package/dist/commerce/quantity-stepper.js +53 -0
- package/dist/commerce/question-list.d.ts +53 -0
- package/dist/commerce/question-list.js +92 -0
- package/dist/commerce/shipping-estimate.d.ts +53 -0
- package/dist/commerce/shipping-estimate.js +39 -0
- package/dist/commerce/sort-select.d.ts +38 -0
- package/dist/commerce/sort-select.js +38 -0
- package/dist/commerce/variant-picker.d.ts +75 -0
- package/dist/commerce/variant-picker.js +135 -0
- package/dist/components/amount.d.ts +46 -0
- package/dist/components/amount.js +34 -0
- package/dist/components/autocomplete.d.ts +82 -0
- package/dist/components/autocomplete.js +114 -0
- package/dist/components/carousel.d.ts +31 -1
- package/dist/components/carousel.js +66 -3
- package/dist/components/index.d.ts +11 -0
- package/dist/components/index.js +11 -0
- package/dist/components/letterbox.d.ts +47 -0
- package/dist/components/letterbox.js +56 -0
- package/dist/components/lightbox.d.ts +88 -0
- package/dist/components/lightbox.js +224 -0
- package/dist/components/media-grid.d.ts +53 -0
- package/dist/components/media-grid.js +89 -0
- package/dist/components/range-months.d.ts +100 -0
- package/dist/components/range-months.js +274 -0
- package/dist/components/rating-input.d.ts +33 -0
- package/dist/components/rating-input.js +63 -0
- package/dist/components/rating.d.ts +38 -0
- package/dist/components/rating.js +66 -0
- package/dist/components/review-card.d.ts +39 -0
- package/dist/components/review-card.js +59 -0
- package/dist/components/section-bar.d.ts +57 -0
- package/dist/components/section-bar.js +140 -0
- package/dist/components/slider.js +7 -0
- package/dist/components/step-indicator.d.ts +46 -0
- package/dist/components/step-indicator.js +96 -0
- package/dist/finance/index.d.ts +10 -0
- package/dist/finance/index.js +10 -0
- package/dist/finance/ledger.d.ts +60 -0
- package/dist/finance/ledger.js +93 -0
- package/dist/finance/payment-card.d.ts +49 -0
- package/dist/finance/payment-card.js +115 -0
- package/dist/map/engine.d.ts +49 -0
- package/dist/map/engine.js +591 -0
- package/dist/map/index.d.ts +12 -0
- package/dist/map/index.js +12 -0
- package/dist/map/map-canvas.d.ts +101 -0
- package/dist/map/map-canvas.js +275 -0
- package/dist/map/map.d.ts +217 -0
- package/dist/map/map.js +598 -0
- package/dist/map/mixins/map-link.d.ts +30 -0
- package/dist/map/mixins/map-link.js +116 -0
- package/dist/map/utils/basemap.d.ts +88 -0
- package/dist/map/utils/basemap.js +84 -0
- package/dist/map/utils/cluster.d.ts +43 -0
- package/dist/map/utils/cluster.js +80 -0
- package/dist/map/utils/mercator.d.ts +66 -0
- package/dist/map/utils/mercator.js +92 -0
- package/dist/map/utils/stage.d.ts +24 -0
- package/dist/map/utils/stage.js +49 -0
- package/dist/mixins/autocomplete.d.ts +28 -0
- package/dist/mixins/autocomplete.js +283 -0
- package/dist/mixins/carousel-controls.d.ts +14 -3
- package/dist/mixins/carousel-controls.js +89 -30
- package/dist/mixins/index.d.ts +2 -0
- package/dist/mixins/index.js +2 -0
- package/dist/mixins/lightbox-controls.d.ts +34 -0
- package/dist/mixins/lightbox-controls.js +176 -0
- package/dist/schedule/agenda.d.ts +63 -0
- package/dist/schedule/agenda.js +221 -0
- package/dist/schedule/day-strip.d.ts +50 -0
- package/dist/schedule/day-strip.js +136 -0
- package/dist/schedule/free-busy.d.ts +96 -0
- package/dist/schedule/free-busy.js +285 -0
- package/dist/schedule/index.d.ts +15 -0
- package/dist/schedule/index.js +15 -0
- package/dist/schedule/mixins/day-strip-scroll.d.ts +16 -0
- package/dist/schedule/mixins/day-strip-scroll.js +40 -0
- package/dist/schedule/mixins/time-grid-drag.d.ts +24 -0
- package/dist/schedule/mixins/time-grid-drag.js +532 -0
- package/dist/schedule/month-view.d.ts +68 -0
- package/dist/schedule/month-view.js +301 -0
- package/dist/schedule/time-grid.d.ts +168 -0
- package/dist/schedule/time-grid.js +417 -0
- package/dist/schedule/utils/time-grid-layout.d.ts +50 -0
- package/dist/schedule/utils/time-grid-layout.js +93 -0
- package/dist/schedule/year-view.d.ts +46 -0
- package/dist/schedule/year-view.js +142 -0
- package/dist/styles/index.d.ts +1 -0
- package/dist/styles/index.js +1 -0
- package/dist/styles/typewriter-text.d.ts +20 -0
- package/dist/styles/typewriter-text.js +23 -0
- package/dist/test/map.d.ts +18 -0
- package/dist/test/map.js +96 -0
- package/dist/test/reels.d.ts +30 -0
- package/dist/test/reels.js +41 -0
- package/dist/test/stories.d.ts +31 -0
- package/dist/test/stories.js +66 -0
- package/dist/travel/boarding-pass.d.ts +107 -0
- package/dist/travel/boarding-pass.js +293 -0
- package/dist/travel/car-offer.d.ts +70 -0
- package/dist/travel/car-offer.js +127 -0
- package/dist/travel/fare-calendar.d.ts +85 -0
- package/dist/travel/fare-calendar.js +233 -0
- package/dist/travel/fare-options.d.ts +84 -0
- package/dist/travel/fare-options.js +142 -0
- package/dist/travel/flight-itinerary.d.ts +84 -0
- package/dist/travel/flight-itinerary.js +112 -0
- package/dist/travel/flight-option.d.ts +58 -0
- package/dist/travel/flight-option.js +111 -0
- package/dist/travel/flight-segment.d.ts +105 -0
- package/dist/travel/flight-segment.js +174 -0
- package/dist/travel/index.d.ts +20 -0
- package/dist/travel/index.js +20 -0
- package/dist/travel/package-savings.d.ts +74 -0
- package/dist/travel/package-savings.js +128 -0
- package/dist/travel/price-breakdown.d.ts +66 -0
- package/dist/travel/price-breakdown.js +102 -0
- package/dist/travel/rating-breakdown.d.ts +81 -0
- package/dist/travel/rating-breakdown.js +132 -0
- package/dist/travel/seat-map.d.ts +108 -0
- package/dist/travel/seat-map.js +371 -0
- package/dist/travel/trip-timeline.d.ts +84 -0
- package/dist/travel/trip-timeline.js +212 -0
- package/dist/utils/gamepad-presses.d.ts +21 -0
- package/dist/utils/gamepad-presses.js +28 -0
- package/dist/utils/index.d.ts +5 -0
- package/dist/utils/index.js +5 -0
- package/dist/utils/move-focus.d.ts +20 -0
- package/dist/utils/move-focus.js +28 -0
- package/dist/utils/range-months.d.ts +54 -0
- package/dist/utils/range-months.js +98 -0
- package/dist/utils/swipe-direction.d.ts +23 -0
- package/dist/utils/swipe-direction.js +27 -0
- package/dist/utils/typewriter.d.ts +49 -0
- package/dist/utils/typewriter.js +171 -0
- package/dist/video/index.d.ts +6 -2
- package/dist/video/index.js +6 -2
- package/dist/video/mixins/reel-feed-sync.d.ts +41 -0
- package/dist/video/mixins/reel-feed-sync.js +430 -0
- package/dist/video/mixins/story-viewer-sync.d.ts +31 -0
- package/dist/video/mixins/story-viewer-sync.js +391 -0
- package/dist/video/reel-feed.d.ts +95 -0
- package/dist/video/reel-feed.js +124 -0
- package/dist/video/story-ring.d.ts +32 -0
- package/dist/video/story-ring.js +42 -0
- package/dist/video/story-viewer.d.ts +85 -0
- package/dist/video/story-viewer.js +250 -0
- package/package.json +21 -2
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Links every element that shares one `data-map-key` across a page, so pointing at or focusing a
|
|
3
|
+
* listing row lights up its pin on a map and the reverse. Without script nothing is lit and
|
|
4
|
+
* each row and pin still works as its own link or button.
|
|
5
|
+
*
|
|
6
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
|
+
* @copyright Sergio Xalambrí 2026
|
|
8
|
+
*/
|
|
9
|
+
import { createElement, createMixin, on } from "remix/component";
|
|
10
|
+
/** Attribute naming the record a row or pin stands for. */
|
|
11
|
+
export const MAP_KEY_ATTRIBUTE = "data-map-key";
|
|
12
|
+
/** Attribute present on every element of the record under the pointer or focus. */
|
|
13
|
+
export const MAP_HIGHLIGHTED_ATTRIBUTE = "data-highlighted";
|
|
14
|
+
/**
|
|
15
|
+
* Sets or clears {@link MAP_HIGHLIGHTED_ATTRIBUTE} on every element in `host`'s document that
|
|
16
|
+
* carries `key`, the host included.
|
|
17
|
+
*
|
|
18
|
+
* @param host Element the pointer or focus moved on.
|
|
19
|
+
* @param key Record key every linked element carries.
|
|
20
|
+
* @param lit Whether the record is lit.
|
|
21
|
+
*/
|
|
22
|
+
function setLinked(host, key, lit) {
|
|
23
|
+
let linked = host.ownerDocument.querySelectorAll(`[${MAP_KEY_ATTRIBUTE}="${CSS.escape(key)}"]`);
|
|
24
|
+
for (let element of [host, ...linked]) {
|
|
25
|
+
if (lit)
|
|
26
|
+
element.setAttribute(MAP_HIGHLIGHTED_ATTRIBUTE, "");
|
|
27
|
+
else
|
|
28
|
+
element.removeAttribute(MAP_HIGHLIGHTED_ATTRIBUTE);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Lights every element sharing `key` while the host is pointed at or holds focus, and keeps
|
|
33
|
+
* them lit until both the pointer and the focus have left it. The host gets `data-map-key`
|
|
34
|
+
* too, so a row and a pin each carrying `mapLink` light one another.
|
|
35
|
+
*
|
|
36
|
+
* @param key Record key, such as a listing id.
|
|
37
|
+
* @example <li mix={mapLink(stay.id)}><a href={stay.url}>{stay.name}</a></li>
|
|
38
|
+
* @example <MapCanvas.Pin x={120} y={80} label="$182" mapKey={stay.id} />
|
|
39
|
+
*/
|
|
40
|
+
export const mapLink = createMixin((handle) => {
|
|
41
|
+
return (key) => createElement(handle.element, {
|
|
42
|
+
[MAP_KEY_ATTRIBUTE]: key,
|
|
43
|
+
mix: [
|
|
44
|
+
on("pointerenter", (event) => {
|
|
45
|
+
setLinked(event.currentTarget, key, true);
|
|
46
|
+
}),
|
|
47
|
+
on("pointerleave", (event) => {
|
|
48
|
+
let host = event.currentTarget;
|
|
49
|
+
if (host.matches(":focus-within"))
|
|
50
|
+
return;
|
|
51
|
+
setLinked(host, key, false);
|
|
52
|
+
}),
|
|
53
|
+
on("focusin", (event) => {
|
|
54
|
+
setLinked(event.currentTarget, key, true);
|
|
55
|
+
}),
|
|
56
|
+
on("focusout", (event) => {
|
|
57
|
+
let host = event.currentTarget;
|
|
58
|
+
let next = event.relatedTarget;
|
|
59
|
+
if (next instanceof Node && host.contains(next))
|
|
60
|
+
return;
|
|
61
|
+
if (host.matches(":hover"))
|
|
62
|
+
return;
|
|
63
|
+
setLinked(host, key, false);
|
|
64
|
+
}),
|
|
65
|
+
],
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
/** The element with a `data-map-key` an event happened in, if any. */
|
|
69
|
+
function keyedAncestor(target) {
|
|
70
|
+
return target instanceof Element ? target.closest(`[${MAP_KEY_ATTRIBUTE}]`) : null;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Links every `data-map-key` row and pin in the host's document at once, by listening on the
|
|
74
|
+
* document, so markup rendered on the server lights up without each row being an island. The
|
|
75
|
+
* listeners go when the host leaves the page.
|
|
76
|
+
*
|
|
77
|
+
* @example <span hidden mix={mapLinks()} />
|
|
78
|
+
*/
|
|
79
|
+
export const mapLinks = createMixin((handle) => {
|
|
80
|
+
let controller;
|
|
81
|
+
handle.addEventListener("insert", (event) => {
|
|
82
|
+
controller?.abort();
|
|
83
|
+
controller = new AbortController();
|
|
84
|
+
let document = event.node.ownerDocument;
|
|
85
|
+
let options = { signal: controller.signal };
|
|
86
|
+
/** Lights the record under a pointer or focus move, and unlights the one it left. */
|
|
87
|
+
function move(from, to) {
|
|
88
|
+
let left = keyedAncestor(from);
|
|
89
|
+
let entered = keyedAncestor(to);
|
|
90
|
+
if (left === entered)
|
|
91
|
+
return;
|
|
92
|
+
let leftKey = left?.getAttribute(MAP_KEY_ATTRIBUTE);
|
|
93
|
+
let enteredKey = entered?.getAttribute(MAP_KEY_ATTRIBUTE);
|
|
94
|
+
if (left !== null && leftKey !== null && leftKey !== undefined && leftKey !== enteredKey) {
|
|
95
|
+
setLinked(left, leftKey, false);
|
|
96
|
+
}
|
|
97
|
+
if (entered !== null && enteredKey !== null && enteredKey !== undefined) {
|
|
98
|
+
setLinked(entered, enteredKey, true);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
document.addEventListener("pointerover", (event) => move(event.relatedTarget, event.target), options);
|
|
102
|
+
document.addEventListener("pointerout", (event) => {
|
|
103
|
+
if (event.relatedTarget === null)
|
|
104
|
+
move(event.target, null);
|
|
105
|
+
}, options);
|
|
106
|
+
document.addEventListener("focusin", (event) => move(event.relatedTarget, event.target), options);
|
|
107
|
+
document.addEventListener("focusout", (event) => {
|
|
108
|
+
if (event.relatedTarget === null)
|
|
109
|
+
move(event.target, null);
|
|
110
|
+
}, options);
|
|
111
|
+
});
|
|
112
|
+
handle.addEventListener("remove", () => {
|
|
113
|
+
controller?.abort();
|
|
114
|
+
controller = undefined;
|
|
115
|
+
});
|
|
116
|
+
});
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The vector basemap a caller draws a map with: GeoJSON features sorted into land, water, parks,
|
|
3
|
+
* roads and place names, turned into SVG path data for the server render and painted from the
|
|
4
|
+
* same `--ui-map-*` color properties in the browser, so both look alike in light and dark.
|
|
5
|
+
*
|
|
6
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
|
+
* @copyright Sergio Xalambrí 2026
|
|
8
|
+
*/
|
|
9
|
+
import type { Pixel } from "./mercator.js";
|
|
10
|
+
/** A GeoJSON position: longitude, latitude and an optional altitude that maps ignore. */
|
|
11
|
+
export type Position = number[];
|
|
12
|
+
/** The GeoJSON geometries a basemap draws; points become place names. */
|
|
13
|
+
export type MapGeometry = {
|
|
14
|
+
type: "Point";
|
|
15
|
+
coordinates: Position;
|
|
16
|
+
} | {
|
|
17
|
+
type: "LineString";
|
|
18
|
+
coordinates: Position[];
|
|
19
|
+
} | {
|
|
20
|
+
type: "MultiLineString";
|
|
21
|
+
coordinates: Position[][];
|
|
22
|
+
} | {
|
|
23
|
+
type: "Polygon";
|
|
24
|
+
coordinates: Position[][];
|
|
25
|
+
} | {
|
|
26
|
+
type: "MultiPolygon";
|
|
27
|
+
coordinates: Position[][][];
|
|
28
|
+
};
|
|
29
|
+
/** What a feature is, which decides its color and drawing order. */
|
|
30
|
+
export type FeatureKind = "land" | "water" | "park" | "road" | "place";
|
|
31
|
+
/** Properties a basemap reads from each feature. */
|
|
32
|
+
export type MapFeatureProperties = {
|
|
33
|
+
/** Polygons default to `land`, lines to `road`, points to `place`. */
|
|
34
|
+
kind?: FeatureKind;
|
|
35
|
+
/** A place's name, written as a label at its point. */
|
|
36
|
+
name?: string;
|
|
37
|
+
/** Draws a road wider. */
|
|
38
|
+
major?: boolean;
|
|
39
|
+
};
|
|
40
|
+
/** One GeoJSON feature of a basemap. */
|
|
41
|
+
export type MapFeature = {
|
|
42
|
+
type: "Feature";
|
|
43
|
+
geometry: MapGeometry;
|
|
44
|
+
properties?: MapFeatureProperties | null;
|
|
45
|
+
};
|
|
46
|
+
/** The GeoJSON document a vector basemap is drawn from. */
|
|
47
|
+
export type MapFeatureCollection = {
|
|
48
|
+
type: "FeatureCollection";
|
|
49
|
+
features: MapFeature[];
|
|
50
|
+
};
|
|
51
|
+
/** The order kinds are drawn in, bottom first, so roads cross parks and water covers land. */
|
|
52
|
+
export declare const KIND_ORDER: Exclude<FeatureKind, "place">[];
|
|
53
|
+
/**
|
|
54
|
+
* The color each part of a basemap paints with: a `--ui-map-*` property a page may set, falling
|
|
55
|
+
* back to a mix of the theme's page and text colors, so a basemap follows light and dark.
|
|
56
|
+
*/
|
|
57
|
+
export declare const BASEMAP_PAINT: {
|
|
58
|
+
land: string;
|
|
59
|
+
water: string;
|
|
60
|
+
park: string;
|
|
61
|
+
road: string;
|
|
62
|
+
label: string;
|
|
63
|
+
};
|
|
64
|
+
/** Stroke widths in pixels for minor and major roads, the same on the server and in the browser. */
|
|
65
|
+
export declare const ROAD_WIDTH: {
|
|
66
|
+
minor: number;
|
|
67
|
+
major: number;
|
|
68
|
+
};
|
|
69
|
+
/** The kind a feature draws as, reading its geometry when it names none. */
|
|
70
|
+
export declare function featureKind(feature: MapFeature): FeatureKind;
|
|
71
|
+
/**
|
|
72
|
+
* SVG path data through `points`, each projected to pixels; `close` ends it with `Z` for a ring.
|
|
73
|
+
*
|
|
74
|
+
* @example linePath([[0, 0], [1, 1]], ([x, y]) => [x * 10, y * 10]); // "M0 0L10 10"
|
|
75
|
+
*/
|
|
76
|
+
export declare function linePath(points: Position[], project: (point: Position) => Pixel, close?: boolean): string;
|
|
77
|
+
/**
|
|
78
|
+
* SVG path data for a line or area geometry, with every ring of a polygon closed, so holes
|
|
79
|
+
* cut through under the `evenodd` fill rule. A point has no path and comes back empty.
|
|
80
|
+
*/
|
|
81
|
+
export declare function geometryPath(geometry: MapGeometry, project: (point: Position) => Pixel): string;
|
|
82
|
+
/** A place name to write over the basemap, read from a point feature. */
|
|
83
|
+
export interface PlaceLabel {
|
|
84
|
+
name: string;
|
|
85
|
+
at: Position;
|
|
86
|
+
}
|
|
87
|
+
/** The named point features of a basemap, the labels it writes over its shapes. */
|
|
88
|
+
export declare function placeLabels(data: MapFeatureCollection | undefined): PlaceLabel[];
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The vector basemap a caller draws a map with: GeoJSON features sorted into land, water, parks,
|
|
3
|
+
* roads and place names, turned into SVG path data for the server render and painted from the
|
|
4
|
+
* same `--ui-map-*` color properties in the browser, so both look alike in light and dark.
|
|
5
|
+
*
|
|
6
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
|
+
* @copyright Sergio Xalambrí 2026
|
|
8
|
+
*/
|
|
9
|
+
/** The order kinds are drawn in, bottom first, so roads cross parks and water covers land. */
|
|
10
|
+
export const KIND_ORDER = ["land", "park", "water", "road"];
|
|
11
|
+
/**
|
|
12
|
+
* The color each part of a basemap paints with: a `--ui-map-*` property a page may set, falling
|
|
13
|
+
* back to a mix of the theme's page and text colors, so a basemap follows light and dark.
|
|
14
|
+
*/
|
|
15
|
+
export const BASEMAP_PAINT = {
|
|
16
|
+
land: "var(--ui-map-land, color-mix(in oklab, var(--ui-bg, Canvas), var(--ui-fg, CanvasText) 3%))",
|
|
17
|
+
water: "var(--ui-map-water, color-mix(in oklab, var(--ui-bg, Canvas), oklch(0.66 0.11 235) 30%))",
|
|
18
|
+
park: "var(--ui-map-park, color-mix(in oklab, var(--ui-bg, Canvas), oklch(0.7 0.13 150) 24%))",
|
|
19
|
+
road: "var(--ui-map-road, var(--ui-surface-raised, Canvas))",
|
|
20
|
+
label: "var(--ui-map-label, var(--ui-neutral-fg-muted, GrayText))",
|
|
21
|
+
};
|
|
22
|
+
/** Stroke widths in pixels for minor and major roads, the same on the server and in the browser. */
|
|
23
|
+
export const ROAD_WIDTH = { minor: 3, major: 6 };
|
|
24
|
+
/** The kind a feature draws as, reading its geometry when it names none. */
|
|
25
|
+
export function featureKind(feature) {
|
|
26
|
+
let kind = feature.properties?.kind;
|
|
27
|
+
if (kind !== undefined)
|
|
28
|
+
return kind;
|
|
29
|
+
let type = feature.geometry.type;
|
|
30
|
+
if (type === "Point")
|
|
31
|
+
return "place";
|
|
32
|
+
if (type === "LineString" || type === "MultiLineString")
|
|
33
|
+
return "road";
|
|
34
|
+
return "land";
|
|
35
|
+
}
|
|
36
|
+
/** Writes a number with at most one decimal, which is finer than a screen pixel needs. */
|
|
37
|
+
function short(value) {
|
|
38
|
+
return String(Math.round(value * 10) / 10);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* SVG path data through `points`, each projected to pixels; `close` ends it with `Z` for a ring.
|
|
42
|
+
*
|
|
43
|
+
* @example linePath([[0, 0], [1, 1]], ([x, y]) => [x * 10, y * 10]); // "M0 0L10 10"
|
|
44
|
+
*/
|
|
45
|
+
export function linePath(points, project, close = false) {
|
|
46
|
+
let d = points
|
|
47
|
+
.map((point, index) => {
|
|
48
|
+
let [x, y] = project(point);
|
|
49
|
+
return `${index === 0 ? "M" : "L"}${short(x)} ${short(y)}`;
|
|
50
|
+
})
|
|
51
|
+
.join("");
|
|
52
|
+
return close && d !== "" ? `${d}Z` : d;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* SVG path data for a line or area geometry, with every ring of a polygon closed, so holes
|
|
56
|
+
* cut through under the `evenodd` fill rule. A point has no path and comes back empty.
|
|
57
|
+
*/
|
|
58
|
+
export function geometryPath(geometry, project) {
|
|
59
|
+
switch (geometry.type) {
|
|
60
|
+
case "LineString":
|
|
61
|
+
return linePath(geometry.coordinates, project);
|
|
62
|
+
case "MultiLineString":
|
|
63
|
+
return geometry.coordinates.map((line) => linePath(line, project)).join("");
|
|
64
|
+
case "Polygon":
|
|
65
|
+
return geometry.coordinates.map((ring) => linePath(ring, project, true)).join("");
|
|
66
|
+
case "MultiPolygon":
|
|
67
|
+
return geometry.coordinates
|
|
68
|
+
.flatMap((polygon) => polygon.map((ring) => linePath(ring, project, true)))
|
|
69
|
+
.join("");
|
|
70
|
+
default:
|
|
71
|
+
return "";
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
/** The named point features of a basemap, the labels it writes over its shapes. */
|
|
75
|
+
export function placeLabels(data) {
|
|
76
|
+
let labels = [];
|
|
77
|
+
for (let feature of data?.features ?? []) {
|
|
78
|
+
let name = feature.properties?.name;
|
|
79
|
+
if (feature.geometry.type !== "Point" || featureKind(feature) !== "place" || !name)
|
|
80
|
+
continue;
|
|
81
|
+
labels.push({ name, at: feature.geometry.coordinates });
|
|
82
|
+
}
|
|
83
|
+
return labels;
|
|
84
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Screen-space clustering for map markers: points closer than a radius in pixels at the current
|
|
3
|
+
* zoom gather into one group. The server render and the browser island run the same function,
|
|
4
|
+
* so a page renders the same bubbles before and after the island takes over.
|
|
5
|
+
*
|
|
6
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
|
+
* @copyright Sergio Xalambrí 2026
|
|
8
|
+
*/
|
|
9
|
+
import type { Pixel } from "./mercator.js";
|
|
10
|
+
/** One point to cluster, in pixels at the current zoom. */
|
|
11
|
+
export interface ClusterPoint {
|
|
12
|
+
x: number;
|
|
13
|
+
y: number;
|
|
14
|
+
/** Keeps the point on its own, such as the selected marker. */
|
|
15
|
+
alone?: boolean;
|
|
16
|
+
}
|
|
17
|
+
/** One group of points: the indexes of its members in input order and their mean position. */
|
|
18
|
+
export interface Cluster {
|
|
19
|
+
members: number[];
|
|
20
|
+
x: number;
|
|
21
|
+
y: number;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Groups points greedily in input order: each point not yet taken seeds a group and gathers
|
|
25
|
+
* every free point within `radius` pixels of it. A grid of `radius`-wide cells keeps each
|
|
26
|
+
* lookup to its nine neighbouring cells. Groups of one come back too, so every input appears
|
|
27
|
+
* exactly once.
|
|
28
|
+
*
|
|
29
|
+
* @param points Positions in pixels at the zoom being drawn.
|
|
30
|
+
* @param radius Distance in pixels under which two points share a bubble.
|
|
31
|
+
* @returns The groups in the order their seeds appear.
|
|
32
|
+
* @example clusterPoints([{ x: 0, y: 0 }, { x: 10, y: 0 }, { x: 200, y: 0 }], 40).map((c) => c.members); // [[0, 1], [2]]
|
|
33
|
+
*/
|
|
34
|
+
export declare function clusterPoints(points: ClusterPoint[], radius: number): Cluster[];
|
|
35
|
+
/** The middle of a set of pixels, used to place a bubble or aim a zoom at its members. */
|
|
36
|
+
export declare function centroid(pixels: Pixel[]): Pixel;
|
|
37
|
+
/**
|
|
38
|
+
* Fills a label template's `{count}` placeholder, the one way bubbles name how many markers
|
|
39
|
+
* they hold.
|
|
40
|
+
*
|
|
41
|
+
* @example clusterLabel("{count} stays", 3); // "3 stays"
|
|
42
|
+
*/
|
|
43
|
+
export declare function clusterLabel(template: string, count: number): string;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Screen-space clustering for map markers: points closer than a radius in pixels at the current
|
|
3
|
+
* zoom gather into one group. The server render and the browser island run the same function,
|
|
4
|
+
* so a page renders the same bubbles before and after the island takes over.
|
|
5
|
+
*
|
|
6
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
|
+
* @copyright Sergio Xalambrí 2026
|
|
8
|
+
*/
|
|
9
|
+
/** The grid cell a pixel falls in for cells `size` pixels wide. */
|
|
10
|
+
function cellOf(x, y, size) {
|
|
11
|
+
return `${Math.floor(x / size)}:${Math.floor(y / size)}`;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Groups points greedily in input order: each point not yet taken seeds a group and gathers
|
|
15
|
+
* every free point within `radius` pixels of it. A grid of `radius`-wide cells keeps each
|
|
16
|
+
* lookup to its nine neighbouring cells. Groups of one come back too, so every input appears
|
|
17
|
+
* exactly once.
|
|
18
|
+
*
|
|
19
|
+
* @param points Positions in pixels at the zoom being drawn.
|
|
20
|
+
* @param radius Distance in pixels under which two points share a bubble.
|
|
21
|
+
* @returns The groups in the order their seeds appear.
|
|
22
|
+
* @example clusterPoints([{ x: 0, y: 0 }, { x: 10, y: 0 }, { x: 200, y: 0 }], 40).map((c) => c.members); // [[0, 1], [2]]
|
|
23
|
+
*/
|
|
24
|
+
export function clusterPoints(points, radius) {
|
|
25
|
+
let size = Math.max(radius, 1);
|
|
26
|
+
let grid = {};
|
|
27
|
+
points.forEach((point, index) => {
|
|
28
|
+
if (point.alone)
|
|
29
|
+
return;
|
|
30
|
+
let cell = cellOf(point.x, point.y, size);
|
|
31
|
+
(grid[cell] ??= []).push(index);
|
|
32
|
+
});
|
|
33
|
+
let taken = new Set();
|
|
34
|
+
let clusters = [];
|
|
35
|
+
points.forEach((seed, index) => {
|
|
36
|
+
if (taken.has(index))
|
|
37
|
+
return;
|
|
38
|
+
taken.add(index);
|
|
39
|
+
let members = [index];
|
|
40
|
+
if (!seed.alone) {
|
|
41
|
+
let column = Math.floor(seed.x / size);
|
|
42
|
+
let row = Math.floor(seed.y / size);
|
|
43
|
+
for (let dx = -1; dx <= 1; dx++) {
|
|
44
|
+
for (let dy = -1; dy <= 1; dy++) {
|
|
45
|
+
for (let other of grid[`${column + dx}:${row + dy}`] ?? []) {
|
|
46
|
+
if (taken.has(other))
|
|
47
|
+
continue;
|
|
48
|
+
let candidate = points[other];
|
|
49
|
+
if (Math.hypot(candidate.x - seed.x, candidate.y - seed.y) > radius)
|
|
50
|
+
continue;
|
|
51
|
+
taken.add(other);
|
|
52
|
+
members.push(other);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
members.sort((a, b) => a - b);
|
|
58
|
+
let x = members.reduce((sum, member) => sum + points[member].x, 0) / members.length;
|
|
59
|
+
let y = members.reduce((sum, member) => sum + points[member].y, 0) / members.length;
|
|
60
|
+
clusters.push({ members, x, y });
|
|
61
|
+
});
|
|
62
|
+
return clusters;
|
|
63
|
+
}
|
|
64
|
+
/** The middle of a set of pixels, used to place a bubble or aim a zoom at its members. */
|
|
65
|
+
export function centroid(pixels) {
|
|
66
|
+
if (pixels.length === 0)
|
|
67
|
+
return [0, 0];
|
|
68
|
+
let x = pixels.reduce((sum, [px]) => sum + px, 0) / pixels.length;
|
|
69
|
+
let y = pixels.reduce((sum, [, py]) => sum + py, 0) / pixels.length;
|
|
70
|
+
return [x, y];
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Fills a label template's `{count}` placeholder, the one way bubbles name how many markers
|
|
74
|
+
* they hold.
|
|
75
|
+
*
|
|
76
|
+
* @example clusterLabel("{count} stays", 3); // "3 stays"
|
|
77
|
+
*/
|
|
78
|
+
export function clusterLabel(template, count) {
|
|
79
|
+
return template.replaceAll("{count}", String(count));
|
|
80
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Web Mercator arithmetic for a map view: longitude and latitude to pixels at a zoom, pixels
|
|
3
|
+
* back to longitude and latitude, and the bounds a stage of a given size shows. The server
|
|
4
|
+
* render and the browser island share it, so both place every marker on the same pixel.
|
|
5
|
+
*
|
|
6
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
|
+
* @copyright Sergio Xalambrí 2026
|
|
8
|
+
*/
|
|
9
|
+
/** Width in pixels of the whole world at zoom 0, matching vector-tile renderers' 512px tiles. */
|
|
10
|
+
export declare const TILE_SIZE = 512;
|
|
11
|
+
/** The furthest latitude Web Mercator draws, north and south, where the square world ends. */
|
|
12
|
+
export declare const MAX_LATITUDE = 85.0511287798;
|
|
13
|
+
/** A point on Earth as `[longitude, latitude]` in degrees, the GeoJSON order. */
|
|
14
|
+
export type LngLat = [longitude: number, latitude: number];
|
|
15
|
+
/** A point in pixels, `[x, y]`, with `y` growing downwards. */
|
|
16
|
+
export type Pixel = [x: number, y: number];
|
|
17
|
+
/** The bounds a view shows as `[west, south, east, north]` in degrees. */
|
|
18
|
+
export type Bounds = [west: number, south: number, east: number, north: number];
|
|
19
|
+
/** Where a map looks: the point at the middle of the stage and how far in it is zoomed. */
|
|
20
|
+
export interface View {
|
|
21
|
+
center: LngLat;
|
|
22
|
+
/** Zoom level; each step doubles the scale, and fractions are allowed. */
|
|
23
|
+
zoom: number;
|
|
24
|
+
}
|
|
25
|
+
/** The world's width in pixels at `zoom`. */
|
|
26
|
+
export declare function worldSize(zoom: number): number;
|
|
27
|
+
/**
|
|
28
|
+
* Projects a point to world pixels at `zoom`, measured from the world's top-left corner.
|
|
29
|
+
* Latitudes past {@link MAX_LATITUDE} pin to the edge, so every input lands on the map.
|
|
30
|
+
*
|
|
31
|
+
* @example worldPixel([0, 0], 0); // [256, 256]
|
|
32
|
+
*/
|
|
33
|
+
export declare function worldPixel([longitude, latitude]: LngLat, zoom: number): Pixel;
|
|
34
|
+
/**
|
|
35
|
+
* Reads world pixels at `zoom` back to a point; the inverse of {@link worldPixel}.
|
|
36
|
+
*
|
|
37
|
+
* @example worldLngLat([256, 256], 0); // [0, 0]
|
|
38
|
+
*/
|
|
39
|
+
export declare function worldLngLat([x, y]: Pixel, zoom: number): LngLat;
|
|
40
|
+
/**
|
|
41
|
+
* Pixels from the middle of a stage showing `view` to `point`, which is how every marker,
|
|
42
|
+
* label and route places itself: `left: calc(50% + x px)`, at any stage size.
|
|
43
|
+
*
|
|
44
|
+
* @example offsetFrom({ center: [0, 0], zoom: 1 }, [90, 0]); // [256, 0]
|
|
45
|
+
*/
|
|
46
|
+
export declare function offsetFrom(view: View, point: LngLat): Pixel;
|
|
47
|
+
/** The point `offset` pixels away from the middle of a stage showing `view`. */
|
|
48
|
+
export declare function lngLatAt(view: View, [dx, dy]: Pixel): LngLat;
|
|
49
|
+
/**
|
|
50
|
+
* The bounds a stage of `size` pixels shows when it looks at `view`.
|
|
51
|
+
*
|
|
52
|
+
* @example viewBounds({ center: [0, 0], zoom: 1 }, [512, 512]); // [-90, -66.51…, 90, 66.51…]
|
|
53
|
+
*/
|
|
54
|
+
export declare function viewBounds(view: View, [width, height]: Pixel): Bounds;
|
|
55
|
+
/** Rounds `value` to `digits` decimals and drops a negative zero, for form fields and URLs. */
|
|
56
|
+
export declare function roundTo(value: number, digits: number): number;
|
|
57
|
+
/**
|
|
58
|
+
* Writes bounds the way a search form submits them: `west,south,east,north`, five decimals.
|
|
59
|
+
*
|
|
60
|
+
* @example formatBounds([-9.2, 38.7, -9.1, 38.8]); // "-9.2,38.7,-9.1,38.8"
|
|
61
|
+
*/
|
|
62
|
+
export declare function formatBounds(bounds: Bounds): string;
|
|
63
|
+
/** Writes a point as `longitude,latitude` with five decimals. */
|
|
64
|
+
export declare function formatLngLat([longitude, latitude]: LngLat): string;
|
|
65
|
+
/** Keeps `zoom` inside `[min, max]`, reading anything that is not a number as `min`. */
|
|
66
|
+
export declare function clampZoom(zoom: number, min: number, max: number): number;
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Web Mercator arithmetic for a map view: longitude and latitude to pixels at a zoom, pixels
|
|
3
|
+
* back to longitude and latitude, and the bounds a stage of a given size shows. The server
|
|
4
|
+
* render and the browser island share it, so both place every marker on the same pixel.
|
|
5
|
+
*
|
|
6
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
|
+
* @copyright Sergio Xalambrí 2026
|
|
8
|
+
*/
|
|
9
|
+
/** Width in pixels of the whole world at zoom 0, matching vector-tile renderers' 512px tiles. */
|
|
10
|
+
export const TILE_SIZE = 512;
|
|
11
|
+
/** The furthest latitude Web Mercator draws, north and south, where the square world ends. */
|
|
12
|
+
export const MAX_LATITUDE = 85.0511287798;
|
|
13
|
+
/** The world's width in pixels at `zoom`. */
|
|
14
|
+
export function worldSize(zoom) {
|
|
15
|
+
return TILE_SIZE * 2 ** zoom;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Projects a point to world pixels at `zoom`, measured from the world's top-left corner.
|
|
19
|
+
* Latitudes past {@link MAX_LATITUDE} pin to the edge, so every input lands on the map.
|
|
20
|
+
*
|
|
21
|
+
* @example worldPixel([0, 0], 0); // [256, 256]
|
|
22
|
+
*/
|
|
23
|
+
export function worldPixel([longitude, latitude], zoom) {
|
|
24
|
+
let size = worldSize(zoom);
|
|
25
|
+
let clamped = Math.max(-MAX_LATITUDE, Math.min(MAX_LATITUDE, latitude));
|
|
26
|
+
let sine = Math.sin((clamped * Math.PI) / 180);
|
|
27
|
+
let x = ((longitude + 180) / 360) * size;
|
|
28
|
+
let y = (0.5 - Math.log((1 + sine) / (1 - sine)) / (4 * Math.PI)) * size;
|
|
29
|
+
return [x, y];
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Reads world pixels at `zoom` back to a point; the inverse of {@link worldPixel}.
|
|
33
|
+
*
|
|
34
|
+
* @example worldLngLat([256, 256], 0); // [0, 0]
|
|
35
|
+
*/
|
|
36
|
+
export function worldLngLat([x, y], zoom) {
|
|
37
|
+
let size = worldSize(zoom);
|
|
38
|
+
let longitude = (x / size) * 360 - 180;
|
|
39
|
+
let n = Math.PI - (2 * Math.PI * y) / size;
|
|
40
|
+
let latitude = (180 / Math.PI) * Math.atan(Math.sinh(n));
|
|
41
|
+
return [longitude, latitude];
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Pixels from the middle of a stage showing `view` to `point`, which is how every marker,
|
|
45
|
+
* label and route places itself: `left: calc(50% + x px)`, at any stage size.
|
|
46
|
+
*
|
|
47
|
+
* @example offsetFrom({ center: [0, 0], zoom: 1 }, [90, 0]); // [256, 0]
|
|
48
|
+
*/
|
|
49
|
+
export function offsetFrom(view, point) {
|
|
50
|
+
let [cx, cy] = worldPixel(view.center, view.zoom);
|
|
51
|
+
let [x, y] = worldPixel(point, view.zoom);
|
|
52
|
+
return [x - cx, y - cy];
|
|
53
|
+
}
|
|
54
|
+
/** The point `offset` pixels away from the middle of a stage showing `view`. */
|
|
55
|
+
export function lngLatAt(view, [dx, dy]) {
|
|
56
|
+
let [cx, cy] = worldPixel(view.center, view.zoom);
|
|
57
|
+
return worldLngLat([cx + dx, cy + dy], view.zoom);
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* The bounds a stage of `size` pixels shows when it looks at `view`.
|
|
61
|
+
*
|
|
62
|
+
* @example viewBounds({ center: [0, 0], zoom: 1 }, [512, 512]); // [-90, -66.51…, 90, 66.51…]
|
|
63
|
+
*/
|
|
64
|
+
export function viewBounds(view, [width, height]) {
|
|
65
|
+
let [west, north] = lngLatAt(view, [-width / 2, -height / 2]);
|
|
66
|
+
let [east, south] = lngLatAt(view, [width / 2, height / 2]);
|
|
67
|
+
return [west, south, east, north];
|
|
68
|
+
}
|
|
69
|
+
/** Rounds `value` to `digits` decimals and drops a negative zero, for form fields and URLs. */
|
|
70
|
+
export function roundTo(value, digits) {
|
|
71
|
+
let factor = 10 ** digits;
|
|
72
|
+
let rounded = Math.round(value * factor) / factor;
|
|
73
|
+
return rounded === 0 ? 0 : rounded;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Writes bounds the way a search form submits them: `west,south,east,north`, five decimals.
|
|
77
|
+
*
|
|
78
|
+
* @example formatBounds([-9.2, 38.7, -9.1, 38.8]); // "-9.2,38.7,-9.1,38.8"
|
|
79
|
+
*/
|
|
80
|
+
export function formatBounds(bounds) {
|
|
81
|
+
return bounds.map((value) => roundTo(value, 5)).join(",");
|
|
82
|
+
}
|
|
83
|
+
/** Writes a point as `longitude,latitude` with five decimals. */
|
|
84
|
+
export function formatLngLat([longitude, latitude]) {
|
|
85
|
+
return `${roundTo(longitude, 5)},${roundTo(latitude, 5)}`;
|
|
86
|
+
}
|
|
87
|
+
/** Keeps `zoom` inside `[min, max]`, reading anything that is not a number as `min`. */
|
|
88
|
+
export function clampZoom(zoom, min, max) {
|
|
89
|
+
if (!Number.isFinite(zoom))
|
|
90
|
+
return min;
|
|
91
|
+
return Math.min(max, Math.max(min, zoom));
|
|
92
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How a map's parts sit on its stage: every marker, label and route is measured in pixels from
|
|
3
|
+
* the stage's middle, so one placement holds at any stage size, and the island moves a part by
|
|
4
|
+
* rewriting the same two properties the server wrote.
|
|
5
|
+
*
|
|
6
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
|
+
* @copyright Sergio Xalambrí 2026
|
|
8
|
+
*/
|
|
9
|
+
import type { LngLat, Pixel } from "./mercator.js";
|
|
10
|
+
/**
|
|
11
|
+
* The `left` and `top` that put a part `offset` pixels from the stage's middle.
|
|
12
|
+
*
|
|
13
|
+
* @example offsetStyle([12, -4]); // { left: "calc(50% + 12px)", top: "calc(50% + -4px)" }
|
|
14
|
+
*/
|
|
15
|
+
export declare function offsetStyle([x, y]: Pixel): {
|
|
16
|
+
left: string;
|
|
17
|
+
top: string;
|
|
18
|
+
};
|
|
19
|
+
/** A CSS dashed ident from an id that may hold characters an ident cannot, for anchor names. */
|
|
20
|
+
export declare function anchorFor(id: string): string;
|
|
21
|
+
/** SVG path data for a route, each point projected to pixels from the stage's middle. */
|
|
22
|
+
export declare function routePathData(path: LngLat[], project: (point: LngLat) => Pixel): string;
|
|
23
|
+
/** Reads a route's points back from its `data-path` attribute, skipping anything malformed. */
|
|
24
|
+
export declare function readPath(value: string | null): LngLat[];
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How a map's parts sit on its stage: every marker, label and route is measured in pixels from
|
|
3
|
+
* the stage's middle, so one placement holds at any stage size, and the island moves a part by
|
|
4
|
+
* rewriting the same two properties the server wrote.
|
|
5
|
+
*
|
|
6
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
|
+
* @copyright Sergio Xalambrí 2026
|
|
8
|
+
*/
|
|
9
|
+
import { linePath } from "./basemap.js";
|
|
10
|
+
/** Writes a pixel length with at most one decimal. */
|
|
11
|
+
function px(value) {
|
|
12
|
+
return `${Math.round(value * 10) / 10}px`;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* The `left` and `top` that put a part `offset` pixels from the stage's middle.
|
|
16
|
+
*
|
|
17
|
+
* @example offsetStyle([12, -4]); // { left: "calc(50% + 12px)", top: "calc(50% + -4px)" }
|
|
18
|
+
*/
|
|
19
|
+
export function offsetStyle([x, y]) {
|
|
20
|
+
return { left: `calc(50% + ${px(x)})`, top: `calc(50% + ${px(y)})` };
|
|
21
|
+
}
|
|
22
|
+
/** A CSS dashed ident from an id that may hold characters an ident cannot, for anchor names. */
|
|
23
|
+
export function anchorFor(id) {
|
|
24
|
+
return `--ui-map-${id.replace(/[^\w-]/g, "-")}`;
|
|
25
|
+
}
|
|
26
|
+
/** SVG path data for a route, each point projected to pixels from the stage's middle. */
|
|
27
|
+
export function routePathData(path, project) {
|
|
28
|
+
return linePath(path, (point) => project([point[0] ?? 0, point[1] ?? 0]));
|
|
29
|
+
}
|
|
30
|
+
/** Reads a route's points back from its `data-path` attribute, skipping anything malformed. */
|
|
31
|
+
export function readPath(value) {
|
|
32
|
+
if (value === null)
|
|
33
|
+
return [];
|
|
34
|
+
let parsed;
|
|
35
|
+
try {
|
|
36
|
+
parsed = JSON.parse(value);
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
return [];
|
|
40
|
+
}
|
|
41
|
+
if (!Array.isArray(parsed))
|
|
42
|
+
return [];
|
|
43
|
+
return parsed.flatMap((point) => {
|
|
44
|
+
if (!Array.isArray(point))
|
|
45
|
+
return [];
|
|
46
|
+
let [lng, lat] = point;
|
|
47
|
+
return typeof lng === "number" && typeof lat === "number" ? [[lng, lat]] : [];
|
|
48
|
+
});
|
|
49
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Turns a server-rendered `Autocomplete` into an ARIA combobox: the native `<datalist>` gives
|
|
3
|
+
* way to a styled listbox that filters as the reader types, walks with the arrows and picks on
|
|
4
|
+
* Enter or a press. Without script the field keeps its datalist and submits the typed text.
|
|
5
|
+
*
|
|
6
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
|
+
* @copyright Sergio Xalambrí 2026
|
|
8
|
+
*/
|
|
9
|
+
/** Name of the bubbling event a pick dispatches on the field, carrying {@link AutocompleteSelectDetail}. */
|
|
10
|
+
export declare const AUTOCOMPLETE_SELECT_EVENT = "autocomplete-select";
|
|
11
|
+
/** The option a pick chose, as the `detail` of {@link AUTOCOMPLETE_SELECT_EVENT}. */
|
|
12
|
+
export interface AutocompleteSelectDetail {
|
|
13
|
+
value: string;
|
|
14
|
+
label: string;
|
|
15
|
+
}
|
|
16
|
+
declare global {
|
|
17
|
+
interface HTMLElementEventMap {
|
|
18
|
+
[AUTOCOMPLETE_SELECT_EVENT]: CustomEvent<AutocompleteSelectDetail>;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Enhances the `[data-slot="autocomplete"]` around the host into a combobox over its styled
|
|
23
|
+
* list, and undoes nothing on removal beyond dropping its listeners. Mount it on a hidden
|
|
24
|
+
* element inside the autocomplete, which is how the island that carries it renders.
|
|
25
|
+
*
|
|
26
|
+
* @example <span hidden mix={autocomplete()} />
|
|
27
|
+
*/
|
|
28
|
+
export declare const autocomplete: import("remix/component").MixinFactory<HTMLElement, [], import("remix/component").ElementProps>;
|