@telepath-computer/television 1.5.10 → 1.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/THIRD-PARTY-NOTICES.txt +701 -0
- package/dist/cli.cjs +9035 -596
- package/dist/onboarding/tv-guide/welcome.html +14 -4
- package/dist/skills/television/SKILL.md +39 -33
- package/dist/skills/television/resources.md +4 -4
- package/dist/skills/television/templates.md +77 -0
- package/dist/skills/television/theming.md +31 -17
- package/dist/templates/calendar/README.md +17 -0
- package/dist/{skills/tv-tasks → templates/calendar}/THIRD-PARTY-NOTICES.txt +22 -22
- package/dist/templates/calendar/calendar-attendees.js +131 -0
- package/dist/templates/calendar/calendar-event.js +22 -0
- package/dist/templates/calendar/calendar-motion.js +273 -0
- package/dist/templates/calendar/calendar-page.js +403 -0
- package/dist/templates/calendar/calendar-time-axis.js +32 -0
- package/dist/templates/calendar/calendar-week.js +711 -0
- package/dist/templates/calendar/data.json +3 -0
- package/dist/templates/calendar/icon.svg +1 -0
- package/dist/templates/calendar/index.html +27 -0
- package/dist/templates/calendar/manifest.json +148 -0
- package/dist/templates/calendar/styles.css +771 -0
- package/dist/templates/checklist/README.md +45 -0
- package/dist/templates/checklist/THIRD-PARTY-NOTICES.txt +29 -0
- package/dist/templates/checklist/data.json +1 -0
- package/dist/templates/checklist/icon.svg +8 -0
- package/dist/templates/checklist/icons.css +61 -0
- package/dist/templates/checklist/index.html +47 -0
- package/dist/templates/checklist/manifest.json +49 -0
- package/dist/templates/checklist/model.d.ts +30 -0
- package/dist/templates/checklist/model.js +60 -0
- package/dist/templates/checklist/page.js +425 -0
- package/dist/templates/checklist/styles.css +206 -0
- package/dist/templates/document/README.md +55 -0
- package/dist/templates/document/THIRD-PARTY-NOTICES.txt +1080 -0
- package/dist/templates/document/data.json +3 -0
- package/dist/templates/document/editor.css +1 -0
- package/dist/templates/document/editor.js +37 -0
- package/dist/templates/document/icon.svg +6 -0
- package/dist/templates/document/index.html +29 -0
- package/dist/templates/document/manifest.json +22 -0
- package/dist/templates/document/page.js +190 -0
- package/dist/templates/document/styles.css +76 -0
- package/dist/templates/map/README.md +85 -0
- package/dist/templates/map/THIRD-PARTY-NOTICES.txt +84 -0
- package/dist/templates/map/data.json +1 -0
- package/dist/templates/map/icon.svg +8 -0
- package/dist/templates/map/icons.svg +43 -0
- package/dist/templates/map/index.html +95 -0
- package/dist/templates/map/manifest.json +227 -0
- package/dist/templates/map/map-model.js +18 -0
- package/dist/templates/map/map.css +202 -0
- package/dist/templates/map/map.js +728 -0
- package/dist/templates/map/vendor/LICENSE +26 -0
- package/dist/templates/map/vendor/README.md +11 -0
- package/dist/templates/map/vendor/leaflet.css +661 -0
- package/dist/templates/map/vendor/leaflet.js +6 -0
- package/dist/templates/map/vendor/lucide/LICENSE +43 -0
- package/dist/templates/map/vendor/lucide/README.md +46 -0
- package/dist/templates/map/vendor/lucide/icons.js +832 -0
- package/dist/templates/map/vendor/lucide/svg/airport.svg +15 -0
- package/dist/templates/map/vendor/lucide/svg/bar.svg +17 -0
- package/dist/templates/map/vendor/lucide/svg/beach.svg +17 -0
- package/dist/templates/map/vendor/lucide/svg/bridge.svg +20 -0
- package/dist/templates/map/vendor/lucide/svg/bus.svg +21 -0
- package/dist/templates/map/vendor/lucide/svg/church.svg +19 -0
- package/dist/templates/map/vendor/lucide/svg/coffee.svg +18 -0
- package/dist/templates/map/vendor/lucide/svg/ferry.svg +19 -0
- package/dist/templates/map/vendor/lucide/svg/flag.svg +15 -0
- package/dist/templates/map/vendor/lucide/svg/heart.svg +15 -0
- package/dist/templates/map/vendor/lucide/svg/home.svg +16 -0
- package/dist/templates/map/vendor/lucide/svg/hospital.svg +19 -0
- package/dist/templates/map/vendor/lucide/svg/hotel.svg +24 -0
- package/dist/templates/map/vendor/lucide/svg/info.svg +17 -0
- package/dist/templates/map/vendor/lucide/svg/landmark.svg +20 -0
- package/dist/templates/map/vendor/lucide/svg/mountain.svg +15 -0
- package/dist/templates/map/vendor/lucide/svg/museum.svg +20 -0
- package/dist/templates/map/vendor/lucide/svg/music.svg +17 -0
- package/dist/templates/map/vendor/lucide/svg/park.svg +18 -0
- package/dist/templates/map/vendor/lucide/svg/parking.svg +16 -0
- package/dist/templates/map/vendor/lucide/svg/pin.svg +16 -0
- package/dist/templates/map/vendor/lucide/svg/restaurant.svg +17 -0
- package/dist/templates/map/vendor/lucide/svg/school.svg +20 -0
- package/dist/templates/map/vendor/lucide/svg/shop.svg +17 -0
- package/dist/templates/map/vendor/lucide/svg/sports.svg +19 -0
- package/dist/templates/map/vendor/lucide/svg/star.svg +15 -0
- package/dist/templates/map/vendor/lucide/svg/theatre.svg +23 -0
- package/dist/templates/map/vendor/lucide/svg/train.svg +20 -0
- package/dist/templates/map/vendor/lucide/svg/viewpoint.svg +20 -0
- package/dist/templates/map/vendor/lucide/svg/work.svg +18 -0
- package/dist/templates/sticky-note/Caveat-Medium.woff2 +0 -0
- package/dist/templates/sticky-note/README.md +47 -0
- package/dist/templates/sticky-note/THIRD-PARTY-NOTICES.txt +127 -0
- package/dist/templates/sticky-note/data.json +1 -0
- package/dist/templates/sticky-note/icon.svg +16 -0
- package/dist/templates/sticky-note/icons.css +61 -0
- package/dist/templates/sticky-note/index.html +31 -0
- package/dist/templates/sticky-note/manifest.json +27 -0
- package/dist/templates/sticky-note/model.d.ts +33 -0
- package/dist/templates/sticky-note/model.js +152 -0
- package/dist/templates/sticky-note/page.js +84 -0
- package/dist/templates/sticky-note/styles.css +140 -0
- package/dist/templates/table/README.md +107 -0
- package/dist/templates/table/data.json +4 -0
- package/dist/templates/table/icon.svg +6 -0
- package/dist/templates/table/index.html +15 -0
- package/dist/templates/table/manifest.json +70 -0
- package/dist/templates/table/model.d.ts +164 -0
- package/dist/templates/table/model.js +395 -0
- package/dist/templates/table/page.js +1045 -0
- package/dist/templates/table/selection-model.d.ts +67 -0
- package/dist/templates/table/selection-model.js +163 -0
- package/dist/templates/table/styles.css +522 -0
- package/dist/views/markdown/THIRD-PARTY-NOTICES.txt +408 -0
- package/dist/views/markdown/index.html +21 -21
- package/dist/web/assets/main-CRSNodQt.js +864 -0
- package/dist/web/assets/main-DnvQkpg4.css +1 -0
- package/dist/web/index.html +2 -2
- package/package.json +1 -1
- package/dist/skills/tv-calendar/SKILL.md +0 -100
- package/dist/skills/tv-calendar/calendar.css +0 -1
- package/dist/skills/tv-calendar/calendar.js +0 -400
- package/dist/skills/tv-table/SKILL.md +0 -95
- package/dist/skills/tv-tasks/SKILL.md +0 -269
- package/dist/skills/tv-tasks/task.css +0 -180
- package/dist/skills/tv-tasks/task.js +0 -304
- package/dist/web/assets/calendar-DToAnkzj.png +0 -0
- package/dist/web/assets/main-CekDfJPz.js +0 -848
- package/dist/web/assets/main-CunC2_Nx.css +0 -1
- package/dist/web/assets/markdown-DdDrJuVK.png +0 -0
- package/dist/web/assets/table-oeG9uAN1.png +0 -0
- package/dist/web/assets/tasks-D4xqXFPl.png +0 -0
|
@@ -0,0 +1,728 @@
|
|
|
1
|
+
// Store snapshots supply places; the page owns the camera, open panel, and
|
|
2
|
+
// selected key. The list remains mounted while details replace it visually.
|
|
3
|
+
import { getStore, onConnectionStatusChanged, onValue, ref } from '/sdk/v1/resources.js';
|
|
4
|
+
import { icons } from './vendor/lucide/icons.js';
|
|
5
|
+
import { categoryColors, httpsURL, photoURL } from './map-model.js';
|
|
6
|
+
|
|
7
|
+
const L = window.L;
|
|
8
|
+
const byId = (id) => document.getElementById(id);
|
|
9
|
+
const app = document.querySelector('.app');
|
|
10
|
+
const reducedMotion = matchMedia('(prefers-reduced-motion: reduce)');
|
|
11
|
+
const narrow = matchMedia('(max-width: 640px)');
|
|
12
|
+
const svgNamespace = 'http://www.w3.org/2000/svg';
|
|
13
|
+
const stableKey = /^[A-Za-z][A-Za-z0-9_-]*$/;
|
|
14
|
+
const indexKey = /^(?:0|[1-9][0-9]*)$/;
|
|
15
|
+
const maxMapZoom = 19;
|
|
16
|
+
const pinSize = L.point(38, 48);
|
|
17
|
+
const pinAnchor = L.point(19, 46);
|
|
18
|
+
const map = L.map('map', {
|
|
19
|
+
zoomControl: false, worldCopyJump: true, inertia: !reducedMotion.matches,
|
|
20
|
+
zoomAnimation: !reducedMotion.matches, fadeAnimation: !reducedMotion.matches,
|
|
21
|
+
}).setView([20, 0], 2);
|
|
22
|
+
const service = 'https://server.arcgisonline.com/ArcGIS/rest/services/';
|
|
23
|
+
const standard = L.tileLayer(`${service}World_Street_Map/MapServer/tile/{z}/{y}/{x}`, { maxZoom: maxMapZoom, className: 'street-tiles', attribution: 'Tiles © Esri' });
|
|
24
|
+
const imagery = L.tileLayer(`${service}World_Imagery/MapServer/tile/{z}/{y}/{x}`, { maxZoom: maxMapZoom, attribution: 'Imagery © Esri, Maxar, Earthstar Geographics, GIS User Community' });
|
|
25
|
+
const labels = L.tileLayer(`${service}Reference/World_Boundaries_and_Places/MapServer/tile/{z}/{y}/{x}`, { maxZoom: maxMapZoom, attribution: 'Labels © Esri' });
|
|
26
|
+
let places = [], markers = [], rows = [], selectedKey = null;
|
|
27
|
+
let visibleIndices = [];
|
|
28
|
+
let selectionOrigin = 'list', selectionOriginKey = null, listScrollTop = 0, sidebarOpen = true;
|
|
29
|
+
let locationSignature = '', storedBasemap, storedSidebar, basemap = 'standard', mapTitle = '';
|
|
30
|
+
let sheetState = 'half', sheetHeight = 0, sheetPointer = null, sheetWheel = null;
|
|
31
|
+
let sheetWheelTimer, suppressSheetClickUntil = 0;
|
|
32
|
+
|
|
33
|
+
// Match the JSON store: numeric index keys first, then other keys by UTF-16.
|
|
34
|
+
function compareStoreKeys(left, right) {
|
|
35
|
+
const leftIndex = indexKey.test(left);
|
|
36
|
+
const rightIndex = indexKey.test(right);
|
|
37
|
+
if (leftIndex !== rightIndex) return leftIndex ? -1 : 1;
|
|
38
|
+
if (leftIndex && left.length !== right.length) return left.length - right.length;
|
|
39
|
+
return left < right ? -1 : left > right ? 1 : 0;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function element(tag, className, text) {
|
|
43
|
+
const node = document.createElement(tag);
|
|
44
|
+
if (className) node.className = className;
|
|
45
|
+
if (text !== undefined) node.textContent = text;
|
|
46
|
+
return node;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function svgNode(tag, attributes) {
|
|
50
|
+
const node = document.createElementNS(svgNamespace, tag);
|
|
51
|
+
for (const [name, value] of Object.entries(attributes)) node.setAttribute(name, value);
|
|
52
|
+
return node;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function placeGlyph(name) {
|
|
56
|
+
const icon = typeof name === 'string' && Object.hasOwn(icons, name) ? name : 'pin';
|
|
57
|
+
const svg = svgNode('svg', { viewBox: '0 0 24 24', class: 'glyph pin-glyph', 'aria-hidden': 'true', 'data-icon': icon });
|
|
58
|
+
for (const [tag, attributes] of icons[icon]) svg.append(svgNode(tag, attributes));
|
|
59
|
+
return svg;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function categoryGlyph(place) {
|
|
63
|
+
const glyph = placeGlyph(place.icon);
|
|
64
|
+
glyph.classList.add('category-glyph');
|
|
65
|
+
return glyph;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// Resolve category defaults once per snapshot, independently of place order.
|
|
69
|
+
// Only automatic categories consume palette slots; explicit colours stay fixed.
|
|
70
|
+
function readCategories(value) {
|
|
71
|
+
const categories = new Map();
|
|
72
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) return categories;
|
|
73
|
+
let automaticColor = 0;
|
|
74
|
+
for (const key of Object.keys(value).sort(compareStoreKeys)) {
|
|
75
|
+
const category = value[key];
|
|
76
|
+
if (!stableKey.test(key) || !category || typeof category.name !== 'string' || !category.name) continue;
|
|
77
|
+
categories.set(key, {
|
|
78
|
+
name: category.name,
|
|
79
|
+
icon: typeof category.icon === 'string' && Object.hasOwn(icons, category.icon) ? category.icon : 'pin',
|
|
80
|
+
color: categoryColors.includes(category.color) ? category.color : categoryColors[automaticColor++ % categoryColors.length],
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
return categories;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function thumbnail(place) {
|
|
87
|
+
const url = photoURL(place.photo);
|
|
88
|
+
if (!url) return null;
|
|
89
|
+
const frame = element('span', 'thumbnail');
|
|
90
|
+
frame.append(placeGlyph(place.icon));
|
|
91
|
+
const image = element('img');
|
|
92
|
+
image.src = url;
|
|
93
|
+
image.alt = '';
|
|
94
|
+
image.loading = 'lazy';
|
|
95
|
+
image.addEventListener('error', () => image.remove(), { once: true });
|
|
96
|
+
frame.append(image);
|
|
97
|
+
return frame;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function setBasemap(next) {
|
|
101
|
+
basemap = next;
|
|
102
|
+
const visible = next === 'standard' ? [standard] : next === 'satellite' ? [imagery] : [imagery, labels];
|
|
103
|
+
[standard, imagery, labels].forEach((layer) => {
|
|
104
|
+
if (!visible.includes(layer)) map.removeLayer(layer);
|
|
105
|
+
else if (!map.hasLayer(layer)) layer.addTo(map);
|
|
106
|
+
});
|
|
107
|
+
byId('layer-label').textContent = next[0].toUpperCase() + next.slice(1);
|
|
108
|
+
document.querySelectorAll('[data-basemap]').forEach((button) => button.setAttribute('aria-pressed', String(button.dataset.basemap === next)));
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// The map stays behind the translucent panel. Its camera uses the remaining
|
|
112
|
+
// visible area, rather than centring places underneath the panel or sheet.
|
|
113
|
+
function cameraOffset() {
|
|
114
|
+
const panel = byId('sidebar');
|
|
115
|
+
if (panel.hidden) return L.point(0, 0);
|
|
116
|
+
const open = panel.dataset.open === 'true';
|
|
117
|
+
if (narrow.matches) return L.point(0, -sheetHeight / 2);
|
|
118
|
+
return open ? L.point((panel.offsetWidth + 32) / 2, 0) : L.point(0, 0);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function sidebarHeaderHeight() {
|
|
122
|
+
return document.querySelector(selectedKey === null ? '.sidebar-header' : '.detail-bar').offsetHeight + 1;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function measureSidebarHeader() {
|
|
126
|
+
app.style.setProperty('--sidebar-header-height', `${sidebarHeaderHeight()}px`);
|
|
127
|
+
if (!narrow.matches) return;
|
|
128
|
+
const heights = sheetHeights();
|
|
129
|
+
app.style.setProperty('--sheet-half-height', `${heights.half}px`);
|
|
130
|
+
if (!sheetPointer?.dragging && !sheetWheel) setSheetHeight(heights[sheetState]);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// The live height is shared by the sheet, map credit, and camera padding.
|
|
134
|
+
// Below half height the panel translates, keeping its whole header visible.
|
|
135
|
+
function sheetHeights() {
|
|
136
|
+
const collapsed = sidebarHeaderHeight();
|
|
137
|
+
const expanded = Math.max(collapsed, app.clientHeight - 96);
|
|
138
|
+
return { collapsed, half: Math.max(collapsed, Math.min(app.clientHeight * .48, 430, expanded)), expanded };
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function setSheetHeight(height) {
|
|
142
|
+
sheetHeight = height;
|
|
143
|
+
app.style.setProperty('--sheet-height', `${height}px`);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function settleSheet(velocity = 0, direction = 0, previousOffset = cameraOffset()) {
|
|
147
|
+
const heights = Object.entries(sheetHeights());
|
|
148
|
+
let nearest = heights.reduce((best, entry) => Math.abs(entry[1] - sheetHeight) < Math.abs(best[1] - sheetHeight) ? entry : best);
|
|
149
|
+
if (velocity < -1.5) nearest = heights[0];
|
|
150
|
+
else if (direction || Math.abs(velocity) > .45) {
|
|
151
|
+
const upward = (direction || velocity) > 0;
|
|
152
|
+
nearest = (upward ? heights.find(([, height]) => height > sheetHeight + 1) : heights.findLast(([, height]) => height < sheetHeight - 1)) || nearest;
|
|
153
|
+
}
|
|
154
|
+
sheetState = nearest[0];
|
|
155
|
+
sidebarOpen = sheetState !== 'collapsed';
|
|
156
|
+
delete app.dataset.sheetDragging;
|
|
157
|
+
syncSidebar();
|
|
158
|
+
if (!sidebarOpen && byId('sidebar-surface').contains(document.activeElement)) byId('sidebar-toggle').focus({ preventScroll: true });
|
|
159
|
+
if (!previousOffset.equals(cameraOffset())) {
|
|
160
|
+
if (selectedKey === null) fit();
|
|
161
|
+
else reframe(previousOffset);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// Own vertical touch movement throughout a gesture so the same swipe can
|
|
166
|
+
// cross the boundary between sheet movement and list scrolling in either direction.
|
|
167
|
+
function moveSheet(delta, scroll) {
|
|
168
|
+
const { collapsed, expanded } = sheetHeights();
|
|
169
|
+
if (scroll && delta < 0) {
|
|
170
|
+
const consumed = Math.min(scroll.scrollTop, -delta);
|
|
171
|
+
scroll.scrollTop -= consumed;
|
|
172
|
+
delta += consumed;
|
|
173
|
+
}
|
|
174
|
+
const previous = sheetHeight;
|
|
175
|
+
setSheetHeight(Math.max(collapsed, Math.min(expanded, sheetHeight + delta)));
|
|
176
|
+
const movement = sheetHeight - previous;
|
|
177
|
+
if (scroll && delta > 0) scroll.scrollTop += delta - movement;
|
|
178
|
+
return movement;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
function finishSheetPointer(event) {
|
|
182
|
+
if (event.type === 'lostpointercapture' && event.target !== byId('sidebar')) return;
|
|
183
|
+
if (!sheetPointer || event.pointerId !== sheetPointer.id) return;
|
|
184
|
+
const pointer = sheetPointer;
|
|
185
|
+
sheetPointer = null;
|
|
186
|
+
if (byId('sidebar').hasPointerCapture(pointer.id)) byId('sidebar').releasePointerCapture(pointer.id);
|
|
187
|
+
if (!pointer.dragging) {
|
|
188
|
+
if (pointer.interruptedWheel !== undefined) settleSheet(0, pointer.interruptedWheel, pointer.offset);
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
suppressSheetClickUntil = performance.now() + 400;
|
|
192
|
+
const velocity = event.type === 'pointerup' && event.timeStamp - pointer.time < 100 ? pointer.velocity : 0;
|
|
193
|
+
settleSheet(velocity, 0, pointer.offset);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
function cancelSheetInput() {
|
|
197
|
+
const pointer = sheetPointer;
|
|
198
|
+
sheetPointer = null;
|
|
199
|
+
sheetWheel = null;
|
|
200
|
+
clearTimeout(sheetWheelTimer);
|
|
201
|
+
if (pointer?.dragging) suppressSheetClickUntil = performance.now() + 400;
|
|
202
|
+
if (pointer && byId('sidebar').hasPointerCapture(pointer.id)) byId('sidebar').releasePointerCapture(pointer.id);
|
|
203
|
+
delete app.dataset.sheetDragging;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
function syncSidebar() {
|
|
207
|
+
const hasPlaces = places.length > 0;
|
|
208
|
+
const open = hasPlaces && sidebarOpen;
|
|
209
|
+
if (!sidebarOpen) sheetState = 'collapsed';
|
|
210
|
+
else if (sheetState === 'collapsed') sheetState = 'half';
|
|
211
|
+
byId('sidebar').hidden = !hasPlaces;
|
|
212
|
+
byId('sidebar').dataset.open = String(open);
|
|
213
|
+
// The tab remains interactive while the panel is closed. On narrow screens,
|
|
214
|
+
// the sheet's header stays visible; only its scrolling content is unavailable.
|
|
215
|
+
byId('sidebar-surface').inert = !open && !narrow.matches;
|
|
216
|
+
byId('sidebar-surface').setAttribute('aria-hidden', String(!open && !narrow.matches));
|
|
217
|
+
for (const id of ['list-scroll', 'detail-scroll']) {
|
|
218
|
+
byId(id).inert = !open;
|
|
219
|
+
byId(id).setAttribute('aria-hidden', String(!open));
|
|
220
|
+
}
|
|
221
|
+
app.dataset.sidebarOpen = String(open);
|
|
222
|
+
app.dataset.hasPlaces = String(hasPlaces);
|
|
223
|
+
byId('sidebar-toggle').setAttribute('aria-expanded', String(open));
|
|
224
|
+
byId('sidebar-toggle').setAttribute('aria-label', open ? 'Hide sidebar' : 'Show sidebar');
|
|
225
|
+
byId('sidebar-toggle').title = open ? 'Hide sidebar' : 'Show sidebar';
|
|
226
|
+
byId('list-view').hidden = selectedKey !== null;
|
|
227
|
+
byId('detail').hidden = selectedKey === null;
|
|
228
|
+
byId('map-title').hidden = !mapTitle || open || (hasPlaces && narrow.matches);
|
|
229
|
+
byId('empty-title').textContent = mapTitle;
|
|
230
|
+
measureSidebarHeader();
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
function reframe(previousOffset, animate = true) {
|
|
234
|
+
const delta = previousOffset.subtract(cameraOffset());
|
|
235
|
+
if (delta.x || delta.y) {
|
|
236
|
+
map.stop();
|
|
237
|
+
map.panBy(delta, { animate: animate && !reducedMotion.matches, duration: .32 });
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
function fit(animate = true) {
|
|
242
|
+
if (!places.length) return;
|
|
243
|
+
const panel = byId('sidebar');
|
|
244
|
+
const open = sidebarOpen && !panel.hidden;
|
|
245
|
+
const left = open && !narrow.matches ? panel.offsetWidth + 60 : 50;
|
|
246
|
+
const uncovered = map.getSize().y - sheetHeight;
|
|
247
|
+
// Expanded leaves little map space: retain room for pin heads while reducing
|
|
248
|
+
// the usual outer padding, rather than fitting beneath the sheet.
|
|
249
|
+
const top = narrow.matches ? Math.min(100, Math.max(50, uncovered - 100)) : 100;
|
|
250
|
+
const bottom = narrow.matches ? sheetHeight + Math.min(open ? 75 : 51, Math.max(6, uncovered - 150)) : 65;
|
|
251
|
+
map.stop();
|
|
252
|
+
map.fitBounds(L.latLngBounds(places.map((place) => [place.lat, place.lng])), {
|
|
253
|
+
paddingTopLeft: [left, top], paddingBottomRight: [50, bottom], maxZoom: 16,
|
|
254
|
+
animate: animate && !reducedMotion.matches, duration: .5,
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
function updateSelection() {
|
|
259
|
+
places.forEach((place, index) => {
|
|
260
|
+
const selected = place.key === selectedKey;
|
|
261
|
+
rows[index].setAttribute('aria-pressed', String(selected));
|
|
262
|
+
markers[index].getElement().setAttribute('aria-pressed', String(selected));
|
|
263
|
+
markers[index].setZIndexOffset(selected ? 1000 : 0);
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
// Keep the query in the mounted field. Store snapshots rebuild rows and pins,
|
|
268
|
+
// but filtering changes only their visibility, never the map camera or store.
|
|
269
|
+
function applyFilter() {
|
|
270
|
+
const input = byId('place-filter');
|
|
271
|
+
const query = input.value.trim().toLowerCase();
|
|
272
|
+
visibleIndices = [];
|
|
273
|
+
hoverPlace(-1, false);
|
|
274
|
+
places.forEach((place, index) => {
|
|
275
|
+
const matches = !query || [place.title, place.categoryName, place.description]
|
|
276
|
+
.some(value => typeof value === 'string' && value.toLowerCase().includes(query));
|
|
277
|
+
rows[index].parentElement.hidden = !matches;
|
|
278
|
+
markers[index].getElement().hidden = !matches;
|
|
279
|
+
if (matches) visibleIndices.push(index);
|
|
280
|
+
});
|
|
281
|
+
byId('filter-clear').hidden = !input.value;
|
|
282
|
+
byId('no-matches').hidden = !places.length || visibleIndices.length > 0;
|
|
283
|
+
byId('place-count').textContent = query ? `${visibleIndices.length} of ${places.length}` : `${places.length} ${places.length === 1 ? 'place' : 'places'}`;
|
|
284
|
+
spreadMarkers();
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
function updateFilter() {
|
|
288
|
+
applyFilter();
|
|
289
|
+
byId('list-scroll').scrollTop = 0;
|
|
290
|
+
listScrollTop = 0;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
function clearFilter() {
|
|
294
|
+
byId('place-filter').value = '';
|
|
295
|
+
updateFilter();
|
|
296
|
+
byId('place-filter').focus({ preventScroll: true });
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
function adjacentVisibleIndex(index, direction) {
|
|
300
|
+
const position = visibleIndices.indexOf(index);
|
|
301
|
+
if (position === -1) return direction > 0 ? visibleIndices[0] : visibleIndices.at(-1);
|
|
302
|
+
return visibleIndices[(position + direction + visibleIndices.length) % visibleIndices.length];
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
function renderDetail(place) {
|
|
306
|
+
byId('detail-title').textContent = place.title;
|
|
307
|
+
const categoryLine = byId('detail-category');
|
|
308
|
+
categoryLine.dataset.color = place.color;
|
|
309
|
+
categoryLine.replaceChildren(categoryGlyph(place), element('span', '', place.categoryName));
|
|
310
|
+
categoryLine.hidden = !place.categoryName;
|
|
311
|
+
byId('detail-description').textContent = typeof place.description === 'string' ? place.description : '';
|
|
312
|
+
byId('detail-description').hidden = !byId('detail-description').textContent;
|
|
313
|
+
const photoContainer = byId('detail-photo');
|
|
314
|
+
photoContainer.replaceChildren();
|
|
315
|
+
const url = photoURL(place.photo);
|
|
316
|
+
photoContainer.hidden = !url;
|
|
317
|
+
if (url) {
|
|
318
|
+
const image = element('img');
|
|
319
|
+
image.src = url;
|
|
320
|
+
image.alt = place.title;
|
|
321
|
+
image.addEventListener('error', () => { if (image.parentElement === photoContainer) photoContainer.hidden = true; }, { once: true });
|
|
322
|
+
photoContainer.append(image);
|
|
323
|
+
}
|
|
324
|
+
const fields = byId('detail-fields');
|
|
325
|
+
fields.replaceChildren();
|
|
326
|
+
if (place.fields && typeof place.fields === 'object' && !Array.isArray(place.fields)) {
|
|
327
|
+
for (const [label, value] of Object.entries(place.fields)) {
|
|
328
|
+
const text = value == null ? '—' : typeof value === 'object' ? JSON.stringify(value) : String(value);
|
|
329
|
+
const field = element('div', text.length > 45 ? 'field long-value' : 'field');
|
|
330
|
+
field.append(element('dt', '', label), element('dd', '', text || '—'));
|
|
331
|
+
fields.append(field);
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
fields.hidden = !fields.children.length;
|
|
335
|
+
const credit = byId('detail-credit');
|
|
336
|
+
credit.replaceChildren();
|
|
337
|
+
if (typeof place.credit?.text === 'string' && place.credit.text) {
|
|
338
|
+
const text = `Photo: ${place.credit.text}`;
|
|
339
|
+
const source = httpsURL(place.credit.url);
|
|
340
|
+
if (source) {
|
|
341
|
+
const link = element('a', '', text);
|
|
342
|
+
link.href = source;
|
|
343
|
+
link.target = '_blank';
|
|
344
|
+
link.rel = 'noopener noreferrer';
|
|
345
|
+
credit.append(link);
|
|
346
|
+
} else credit.textContent = text;
|
|
347
|
+
}
|
|
348
|
+
credit.hidden = !credit.textContent;
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
function selectPlace(index, origin = 'list') {
|
|
352
|
+
const place = places[index];
|
|
353
|
+
if (!place) return;
|
|
354
|
+
if (selectedKey === null) {
|
|
355
|
+
listScrollTop = byId('list-scroll').scrollTop;
|
|
356
|
+
selectionOrigin = origin;
|
|
357
|
+
selectionOriginKey = place.key;
|
|
358
|
+
}
|
|
359
|
+
selectedKey = place.key;
|
|
360
|
+
sidebarOpen = true;
|
|
361
|
+
hoverPlace(-1, false);
|
|
362
|
+
renderDetail(place);
|
|
363
|
+
syncSidebar();
|
|
364
|
+
updateSelection();
|
|
365
|
+
byId('detail-scroll').scrollTop = 0;
|
|
366
|
+
byId('close-detail').focus({ preventScroll: true });
|
|
367
|
+
byId('selection-status').textContent = `${place.title} selected. Press Escape to return to places.`;
|
|
368
|
+
map.stop();
|
|
369
|
+
const zoom = Math.max(map.getZoom(), 15);
|
|
370
|
+
// Account for the height of the balloon: its geographic anchor is its tip.
|
|
371
|
+
const offset = cameraOffset().add([0, 20]);
|
|
372
|
+
const center = map.unproject(map.project([place.lat, place.lng], zoom).subtract(offset), zoom);
|
|
373
|
+
if (reducedMotion.matches) map.setView(center, zoom, { animate: false });
|
|
374
|
+
else map.flyTo(center, zoom, { duration: .8 });
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
function closeDetail() {
|
|
378
|
+
const index = places.findIndex((place) => place.key === selectionOriginKey);
|
|
379
|
+
selectedKey = null;
|
|
380
|
+
syncSidebar();
|
|
381
|
+
updateSelection();
|
|
382
|
+
byId('list-scroll').scrollTop = listScrollTop;
|
|
383
|
+
const target = visibleIndices.includes(index)
|
|
384
|
+
? selectionOrigin === 'marker' || !sidebarOpen ? markers[index].getElement() : rows[index]
|
|
385
|
+
: sidebarOpen ? byId('place-filter') : byId('map');
|
|
386
|
+
(target || byId('map')).focus({ preventScroll: true });
|
|
387
|
+
byId('selection-status').textContent = 'Place list.';
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
// At zoom 19, only coordinates whose 38×48px pin hit boxes still overlap count
|
|
391
|
+
// as the same place. Fan their icons without changing stored or Leaflet points.
|
|
392
|
+
function spreadMarkers() {
|
|
393
|
+
const pending = markers
|
|
394
|
+
.filter(marker => !marker.getElement().hidden)
|
|
395
|
+
.map(marker => ({ marker, projected: map.project(marker.getLatLng(), maxMapZoom) }));
|
|
396
|
+
const groups = [];
|
|
397
|
+
while (pending.length) {
|
|
398
|
+
const group = [pending.shift()];
|
|
399
|
+
for (let candidate = pending.length - 1; candidate >= 0; candidate -= 1) {
|
|
400
|
+
const overlapsGroup = group.every(({ projected }) => {
|
|
401
|
+
const delta = pending[candidate].projected.subtract(projected);
|
|
402
|
+
return Math.abs(delta.x) < pinSize.x && Math.abs(delta.y) < pinSize.y;
|
|
403
|
+
});
|
|
404
|
+
if (overlapsGroup) group.push(pending.splice(candidate, 1)[0]);
|
|
405
|
+
}
|
|
406
|
+
groups.push(group);
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
const size = map.getSize();
|
|
410
|
+
const uncovered = narrow.matches && !byId('sidebar').hidden ? size.y - sheetHeight : null;
|
|
411
|
+
groups.forEach((group) => {
|
|
412
|
+
const anchors = group.map(({ marker }) => map.latLngToContainerPoint(marker.getLatLng()));
|
|
413
|
+
const center = anchors.reduce((sum, point) => sum.add(point), L.point(0, 0)).divideBy(group.length);
|
|
414
|
+
const radius = group.length > 1 ? Math.max(20, 16 / Math.sin(Math.PI / group.length)) : 0;
|
|
415
|
+
const top = group.some(({ marker }) => marker.getElement().getAttribute('aria-pressed') === 'true') ? 64 : 48;
|
|
416
|
+
// Above a narrow sheet, keep the compact fan sideways so no pin is pushed
|
|
417
|
+
// under the sheet. Offscreen groups keep the usual circular fan.
|
|
418
|
+
const sideways = uncovered !== null && center.x >= 24 && center.x <= size.x - 24 && center.y >= top && center.y <= uncovered - 2;
|
|
419
|
+
group.forEach(({ marker }, index) => {
|
|
420
|
+
const anchor = anchors[index];
|
|
421
|
+
let point = anchor;
|
|
422
|
+
if (group.length > 1) {
|
|
423
|
+
const offset = sideways
|
|
424
|
+
? L.point((index - (group.length - 1) / 2) * 32, 0)
|
|
425
|
+
: L.point(Math.cos(-Math.PI / 2 + index * 2 * Math.PI / group.length) * radius, Math.sin(-Math.PI / 2 + index * 2 * Math.PI / group.length) * radius);
|
|
426
|
+
point = center.add(offset);
|
|
427
|
+
}
|
|
428
|
+
const delta = point.subtract(anchor);
|
|
429
|
+
const node = marker.getElement();
|
|
430
|
+
node.style.marginLeft = `${delta.x - pinAnchor.x}px`;
|
|
431
|
+
node.style.marginTop = `${delta.y - pinAnchor.y}px`;
|
|
432
|
+
const tooltip = marker.getTooltip();
|
|
433
|
+
tooltip.options.offset = L.point(delta.x, delta.y - 52);
|
|
434
|
+
if (marker.isTooltipOpen()) tooltip.update();
|
|
435
|
+
});
|
|
436
|
+
});
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
function hoverPlace(index, hovered, fromPin = false) {
|
|
440
|
+
rows.forEach((row, rowIndex) => {
|
|
441
|
+
const active = hovered && rowIndex === index;
|
|
442
|
+
row.classList.toggle('is-hovered', active);
|
|
443
|
+
markers[rowIndex].getElement().classList.toggle('is-hovered', active);
|
|
444
|
+
markers[rowIndex].setZIndexOffset(active ? 2000 : places[rowIndex].key === selectedKey ? 1000 : 0);
|
|
445
|
+
if (active && fromPin) markers[rowIndex].openTooltip();
|
|
446
|
+
else markers[rowIndex].closeTooltip();
|
|
447
|
+
});
|
|
448
|
+
if (hovered && fromPin && sidebarOpen && selectedKey === null) rows[index].scrollIntoView({ block: 'nearest', behavior: reducedMotion.matches ? 'instant' : 'smooth' });
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
function render(value) {
|
|
452
|
+
const previousOffset = sheetPointer?.offset || sheetWheel?.offset || cameraOffset();
|
|
453
|
+
cancelSheetInput();
|
|
454
|
+
const data = value && typeof value === 'object' && !Array.isArray(value) ? value : {};
|
|
455
|
+
const wasSidebarOpen = sidebarOpen;
|
|
456
|
+
const active = document.activeElement;
|
|
457
|
+
const focusedKey = active?.dataset.key;
|
|
458
|
+
const focusedMarker = active?.classList.contains('map-pin');
|
|
459
|
+
const detailCreditFocused = byId('detail-credit').contains(active);
|
|
460
|
+
const detailHadFocus = byId('detail').contains(active);
|
|
461
|
+
const detailScrollTop = byId('detail-scroll').scrollTop;
|
|
462
|
+
if (selectedKey === null) listScrollTop = byId('list-scroll').scrollTop;
|
|
463
|
+
delete app.dataset.unreadable;
|
|
464
|
+
byId('error').hidden = true;
|
|
465
|
+
mapTitle = typeof data.title === 'string' ? data.title : '';
|
|
466
|
+
byId('title').textContent = mapTitle || 'Places';
|
|
467
|
+
document.title = mapTitle || 'Map';
|
|
468
|
+
byId('subtitle').textContent = typeof data.subtitle === 'string' ? data.subtitle : '';
|
|
469
|
+
byId('subtitle').hidden = !byId('subtitle').textContent;
|
|
470
|
+
const categories = readCategories(data.categories);
|
|
471
|
+
places = Object.entries(data.places && typeof data.places === 'object' && !Array.isArray(data.places) ? data.places : {})
|
|
472
|
+
.filter(([, place]) => place && Number.isFinite(place.lat) && Number.isFinite(place.lng) && Math.abs(place.lat) <= 90 && Math.abs(place.lng) <= 180)
|
|
473
|
+
.map(([key, place]) => {
|
|
474
|
+
const category = categories.get(place.category);
|
|
475
|
+
const icon = category && typeof place.icon === 'string' && Object.hasOwn(icons, place.icon) ? place.icon : category?.icon || 'pin';
|
|
476
|
+
return { ...place, key, title: typeof place.title === 'string' && place.title ? place.title : 'Untitled place', categoryName: category?.name || '', icon, color: category?.color || 'default' };
|
|
477
|
+
})
|
|
478
|
+
.sort((a, b) => (Number.isFinite(a.order) ? a.order : Infinity) - (Number.isFinite(b.order) ? b.order : Infinity) || compareStoreKeys(a.key, b.key));
|
|
479
|
+
markers.forEach((marker) => marker.remove());
|
|
480
|
+
markers = [];
|
|
481
|
+
rows = [];
|
|
482
|
+
byId('place-list').replaceChildren();
|
|
483
|
+
places.forEach((place, index) => {
|
|
484
|
+
const face = element('span', 'pin-face');
|
|
485
|
+
const shape = svgNode('svg', { viewBox: '0 0 44 56', class: 'pin-shape', 'aria-hidden': 'true' });
|
|
486
|
+
shape.append(svgNode('path', { d: 'M22 2C11.5 2 3 10.4 3 21c0 11 13.1 26.4 17.3 31a2.3 2.3 0 0 0 3.4 0C27.9 47.4 41 32 41 21 41 10.4 32.5 2 22 2Z' }));
|
|
487
|
+
face.append(shape);
|
|
488
|
+
if (data.numbered === true) face.append(element('span', 'pin-number', index + 1));
|
|
489
|
+
else face.append(placeGlyph(place.icon));
|
|
490
|
+
const marker = L.marker([place.lat, place.lng], { icon: L.divIcon({ className: 'map-pin', html: face, iconSize: pinSize, iconAnchor: pinAnchor }), keyboard: true }).addTo(map);
|
|
491
|
+
marker.bindTooltip(element('span', '', place.title), { direction: 'top', offset: [0, -52], opacity: 1 });
|
|
492
|
+
const pin = marker.getElement();
|
|
493
|
+
pin.dataset.key = place.key;
|
|
494
|
+
pin.dataset.color = place.color;
|
|
495
|
+
pin.setAttribute('aria-label', place.title);
|
|
496
|
+
pin.setAttribute('aria-pressed', 'false');
|
|
497
|
+
pin.addEventListener('keydown', (event) => {
|
|
498
|
+
if (event.key === ' ' || event.key === 'Enter') {
|
|
499
|
+
event.preventDefault();
|
|
500
|
+
event.stopPropagation();
|
|
501
|
+
selectPlace(index, 'marker');
|
|
502
|
+
}
|
|
503
|
+
});
|
|
504
|
+
marker.on('click', () => selectPlace(index, 'marker'));
|
|
505
|
+
marker.on('mouseover', () => hoverPlace(index, true, true));
|
|
506
|
+
marker.on('mouseout', () => hoverPlace(index, false));
|
|
507
|
+
markers.push(marker);
|
|
508
|
+
const row = element('li', 'place-row');
|
|
509
|
+
const button = element('button', 'place-button');
|
|
510
|
+
button.type = 'button';
|
|
511
|
+
button.dataset.key = place.key;
|
|
512
|
+
button.dataset.color = place.color;
|
|
513
|
+
button.setAttribute('aria-label', place.title);
|
|
514
|
+
button.setAttribute('aria-pressed', 'false');
|
|
515
|
+
const photo = thumbnail(place);
|
|
516
|
+
if (photo) button.append(photo);
|
|
517
|
+
const copy = element('span', 'row-copy');
|
|
518
|
+
const heading = element('span', 'row-title');
|
|
519
|
+
if (data.numbered === true) heading.append(element('span', 'list-badge', `${index + 1}.`));
|
|
520
|
+
heading.append(element('span', '', place.title));
|
|
521
|
+
copy.append(heading);
|
|
522
|
+
if (place.categoryName) {
|
|
523
|
+
const category = element('span', 'row-category category-pill');
|
|
524
|
+
category.append(categoryGlyph(place), element('span', '', place.categoryName));
|
|
525
|
+
copy.append(category);
|
|
526
|
+
}
|
|
527
|
+
if (typeof place.description === 'string' && place.description) copy.append(element('span', 'row-description', place.description));
|
|
528
|
+
button.append(copy);
|
|
529
|
+
button.addEventListener('click', () => selectPlace(index));
|
|
530
|
+
button.addEventListener('mouseenter', () => hoverPlace(index, true));
|
|
531
|
+
button.addEventListener('mouseleave', () => hoverPlace(index, false));
|
|
532
|
+
button.addEventListener('keydown', (event) => {
|
|
533
|
+
if (!['ArrowUp', 'ArrowDown', 'Home', 'End'].includes(event.key)) return;
|
|
534
|
+
event.preventDefault();
|
|
535
|
+
const next = event.key === 'Home' ? visibleIndices[0] : event.key === 'End' ? visibleIndices.at(-1) : adjacentVisibleIndex(index, event.key === 'ArrowDown' ? 1 : -1);
|
|
536
|
+
rows[next]?.focus();
|
|
537
|
+
hoverPlace(next, true);
|
|
538
|
+
});
|
|
539
|
+
row.append(button);
|
|
540
|
+
rows.push(button);
|
|
541
|
+
byId('place-list').append(row);
|
|
542
|
+
});
|
|
543
|
+
applyFilter();
|
|
544
|
+
const desiredSidebar = ['open', 'closed'].includes(data.sidebar) ? data.sidebar : undefined;
|
|
545
|
+
if (desiredSidebar !== storedSidebar) { storedSidebar = desiredSidebar; sidebarOpen = desiredSidebar !== 'closed'; }
|
|
546
|
+
const selected = places.find((place) => place.key === selectedKey);
|
|
547
|
+
if (selected) renderDetail(selected);
|
|
548
|
+
else selectedKey = null;
|
|
549
|
+
syncSidebar();
|
|
550
|
+
updateSelection();
|
|
551
|
+
const restoredIndex = places.findIndex((place) => place.key === focusedKey);
|
|
552
|
+
if (visibleIndices.includes(restoredIndex) && (focusedMarker || (sidebarOpen && selectedKey === null))) (focusedMarker ? markers[restoredIndex].getElement() : rows[restoredIndex]).focus({ preventScroll: true });
|
|
553
|
+
else if (restoredIndex !== -1 && sidebarOpen && selectedKey === null) byId('place-filter').focus({ preventScroll: true });
|
|
554
|
+
else if (focusedKey || (detailHadFocus && (!selected || !sidebarOpen))) byId('map').focus({ preventScroll: true });
|
|
555
|
+
if (detailCreditFocused && selected && sidebarOpen) (byId('detail-credit').querySelector('a') || byId('close-detail')).focus({ preventScroll: true });
|
|
556
|
+
byId('list-scroll').scrollTop = listScrollTop;
|
|
557
|
+
byId('detail-scroll').scrollTop = detailScrollTop;
|
|
558
|
+
byId('empty').hidden = places.length > 0;
|
|
559
|
+
const desiredBasemap = ['standard', 'satellite', 'hybrid'].includes(data.basemap) ? data.basemap : undefined;
|
|
560
|
+
if (desiredBasemap !== storedBasemap) { storedBasemap = desiredBasemap; basemap = desiredBasemap || 'standard'; }
|
|
561
|
+
setBasemap(basemap);
|
|
562
|
+
const signature = JSON.stringify(places.map((place) => [place.key, place.lat, place.lng]).sort((a, b) => compareStoreKeys(a[0], b[0])));
|
|
563
|
+
if (signature !== locationSignature) { locationSignature = signature; fit(false); }
|
|
564
|
+
else if (!wasSidebarOpen && sidebarOpen && selectedKey === null) fit();
|
|
565
|
+
else reframe(previousOffset);
|
|
566
|
+
spreadMarkers();
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
function closeLayers(restoreFocus = false) {
|
|
570
|
+
byId('layers-menu').hidden = true;
|
|
571
|
+
byId('layers-toggle').setAttribute('aria-expanded', 'false');
|
|
572
|
+
if (restoreFocus) byId('layers-toggle').focus();
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
byId('sidebar').addEventListener('pointerdown', (event) => {
|
|
576
|
+
suppressSheetClickUntil = 0;
|
|
577
|
+
if (!narrow.matches || !event.isPrimary || event.button !== 0) return;
|
|
578
|
+
const scroll = event.target.closest('.sidebar-scroll');
|
|
579
|
+
if (scroll ? event.pointerType === 'mouse' : !event.target.closest('.sidebar-header, .detail-bar, #sidebar-toggle')) return;
|
|
580
|
+
if (!scroll && event.target.closest('input, select, textarea, a, button:not(#sidebar-toggle)')) return;
|
|
581
|
+
const offset = sheetWheel?.offset || cameraOffset();
|
|
582
|
+
const interruptedWheel = sheetWheel?.direction;
|
|
583
|
+
cancelSheetInput();
|
|
584
|
+
sheetPointer = {
|
|
585
|
+
id: event.pointerId, scroll, offset, interruptedWheel, startX: event.clientX, startY: event.clientY,
|
|
586
|
+
y: event.clientY, time: event.timeStamp, velocity: 0, dragging: false,
|
|
587
|
+
height: app.getBoundingClientRect().bottom - byId('sidebar').getBoundingClientRect().top,
|
|
588
|
+
};
|
|
589
|
+
});
|
|
590
|
+
document.addEventListener('pointermove', (event) => {
|
|
591
|
+
const pointer = sheetPointer;
|
|
592
|
+
if (!pointer || event.pointerId !== pointer.id) return;
|
|
593
|
+
if (!pointer.dragging) {
|
|
594
|
+
const distance = Math.abs(event.clientY - pointer.startY);
|
|
595
|
+
if (distance < 6) return;
|
|
596
|
+
if (Math.abs(event.clientX - pointer.startX) > distance) { finishSheetPointer(event); return; }
|
|
597
|
+
pointer.dragging = true;
|
|
598
|
+
app.dataset.sheetDragging = 'true';
|
|
599
|
+
setSheetHeight(pointer.height);
|
|
600
|
+
byId('sidebar').setPointerCapture(event.pointerId);
|
|
601
|
+
}
|
|
602
|
+
event.preventDefault();
|
|
603
|
+
const movement = moveSheet(pointer.y - event.clientY, pointer.scroll);
|
|
604
|
+
pointer.velocity = movement / Math.max(1, event.timeStamp - pointer.time);
|
|
605
|
+
pointer.y = event.clientY;
|
|
606
|
+
pointer.time = event.timeStamp;
|
|
607
|
+
});
|
|
608
|
+
for (const type of ['pointerup', 'pointercancel']) document.addEventListener(type, finishSheetPointer, true);
|
|
609
|
+
byId('sidebar').addEventListener('lostpointercapture', finishSheetPointer);
|
|
610
|
+
byId('sidebar').addEventListener('click', (event) => {
|
|
611
|
+
if (event.detail && performance.now() < suppressSheetClickUntil) {
|
|
612
|
+
event.preventDefault();
|
|
613
|
+
event.stopImmediatePropagation();
|
|
614
|
+
}
|
|
615
|
+
}, true);
|
|
616
|
+
byId('sidebar').addEventListener('wheel', (event) => {
|
|
617
|
+
const scroll = event.target.closest('.sidebar-scroll');
|
|
618
|
+
if (!narrow.matches || !scroll || sheetPointer || event.ctrlKey || Math.abs(event.deltaX) >= Math.abs(event.deltaY)) return;
|
|
619
|
+
event.preventDefault();
|
|
620
|
+
if (!sheetWheel) {
|
|
621
|
+
const height = app.getBoundingClientRect().bottom - byId('sidebar').getBoundingClientRect().top;
|
|
622
|
+
sheetWheel = { direction: 0, offset: cameraOffset() };
|
|
623
|
+
app.dataset.sheetDragging = 'true';
|
|
624
|
+
setSheetHeight(height);
|
|
625
|
+
}
|
|
626
|
+
const delta = event.deltaY * (event.deltaMode === 1 ? 16 : event.deltaMode === 2 ? scroll.clientHeight : 1);
|
|
627
|
+
const movement = moveSheet(delta, scroll);
|
|
628
|
+
if (movement) sheetWheel.direction = Math.sign(movement);
|
|
629
|
+
clearTimeout(sheetWheelTimer);
|
|
630
|
+
sheetWheelTimer = setTimeout(() => {
|
|
631
|
+
const { direction, offset } = sheetWheel;
|
|
632
|
+
sheetWheel = null;
|
|
633
|
+
if (direction) settleSheet(0, direction, offset);
|
|
634
|
+
else delete app.dataset.sheetDragging;
|
|
635
|
+
}, 120);
|
|
636
|
+
}, { passive: false });
|
|
637
|
+
|
|
638
|
+
byId('sidebar-toggle').addEventListener('click', () => {
|
|
639
|
+
const previousOffset = sheetPointer?.offset || sheetWheel?.offset || cameraOffset();
|
|
640
|
+
cancelSheetInput();
|
|
641
|
+
sidebarOpen = !sidebarOpen;
|
|
642
|
+
hoverPlace(-1, false);
|
|
643
|
+
syncSidebar();
|
|
644
|
+
byId('sidebar-toggle').focus({ preventScroll: true });
|
|
645
|
+
if (sidebarOpen && selectedKey === null) fit();
|
|
646
|
+
else reframe(previousOffset);
|
|
647
|
+
});
|
|
648
|
+
byId('zoom-in').addEventListener('click', () => map.zoomIn(1, { animate: !reducedMotion.matches }));
|
|
649
|
+
byId('zoom-out').addEventListener('click', () => map.zoomOut(1, { animate: !reducedMotion.matches }));
|
|
650
|
+
byId('place-filter').addEventListener('input', updateFilter);
|
|
651
|
+
byId('place-filter').addEventListener('keydown', event => {
|
|
652
|
+
if (!['ArrowDown', 'ArrowUp'].includes(event.key) || event.isComposing) return;
|
|
653
|
+
event.preventDefault();
|
|
654
|
+
const index = event.key === 'ArrowDown' ? visibleIndices[0] : visibleIndices.at(-1);
|
|
655
|
+
rows[index]?.focus();
|
|
656
|
+
hoverPlace(index, index !== undefined);
|
|
657
|
+
});
|
|
658
|
+
byId('filter-clear').addEventListener('click', clearFilter);
|
|
659
|
+
byId('close-detail').addEventListener('click', closeDetail);
|
|
660
|
+
byId('detail').addEventListener('keydown', (event) => {
|
|
661
|
+
if (!['ArrowUp', 'ArrowDown'].includes(event.key) || event.altKey || event.ctrlKey || event.metaKey) return;
|
|
662
|
+
event.preventDefault();
|
|
663
|
+
const index = places.findIndex((place) => place.key === selectedKey);
|
|
664
|
+
selectPlace(adjacentVisibleIndex(index, event.key === 'ArrowDown' ? 1 : -1), selectionOrigin);
|
|
665
|
+
});
|
|
666
|
+
byId('layers-toggle').addEventListener('click', () => {
|
|
667
|
+
const open = byId('layers-menu').hidden;
|
|
668
|
+
byId('layers-menu').hidden = !open;
|
|
669
|
+
byId('layers-toggle').setAttribute('aria-expanded', String(open));
|
|
670
|
+
if (open) byId('layers-menu').querySelector('[aria-pressed="true"]').focus();
|
|
671
|
+
});
|
|
672
|
+
const layerButtons = [...document.querySelectorAll('[data-basemap]')];
|
|
673
|
+
layerButtons.forEach((button, index) => {
|
|
674
|
+
button.addEventListener('click', () => { setBasemap(button.dataset.basemap); closeLayers(true); });
|
|
675
|
+
button.addEventListener('keydown', (event) => {
|
|
676
|
+
if (event.key !== 'ArrowUp' && event.key !== 'ArrowDown') return;
|
|
677
|
+
event.preventDefault();
|
|
678
|
+
layerButtons[(index + (event.key === 'ArrowDown' ? 1 : -1) + layerButtons.length) % layerButtons.length].focus();
|
|
679
|
+
});
|
|
680
|
+
});
|
|
681
|
+
document.addEventListener('pointerdown', (event) => { if (!event.target.closest('.map-toolbar')) closeLayers(); });
|
|
682
|
+
document.addEventListener('keydown', (event) => {
|
|
683
|
+
if (event.altKey || event.ctrlKey || event.metaKey || event.isComposing) return;
|
|
684
|
+
if (event.key === 'Escape') {
|
|
685
|
+
if (event.target === byId('place-filter') && event.target.value) { event.preventDefault(); clearFilter(); }
|
|
686
|
+
else if (!byId('layers-menu').hidden) { event.preventDefault(); closeLayers(true); }
|
|
687
|
+
else if (selectedKey !== null) { event.preventDefault(); closeDetail(); }
|
|
688
|
+
return;
|
|
689
|
+
}
|
|
690
|
+
if (event.target.closest('input, textarea, select, [contenteditable="true"]')) return;
|
|
691
|
+
if (event.key.toLowerCase() === 'f') { event.preventDefault(); fit(); }
|
|
692
|
+
});
|
|
693
|
+
map.on('zoomend moveend', spreadMarkers);
|
|
694
|
+
new ResizeObserver(() => { cancelSheetInput(); measureSidebarHeader(); map.invalidateSize({ pan: false }); fit(false); spreadMarkers(); }).observe(byId('map'));
|
|
695
|
+
const headerObserver = new ResizeObserver(measureSidebarHeader);
|
|
696
|
+
document.querySelectorAll('.sidebar-header, .detail-bar').forEach(header => headerObserver.observe(header));
|
|
697
|
+
narrow.addEventListener('change', () => { cancelSheetInput(); syncSidebar(); });
|
|
698
|
+
reducedMotion.addEventListener('change', () => { map.stop(); map.options.inertia = !reducedMotion.matches; });
|
|
699
|
+
|
|
700
|
+
function showUnavailable() {
|
|
701
|
+
app.dataset.unreadable = 'true';
|
|
702
|
+
byId('error').hidden = false;
|
|
703
|
+
}
|
|
704
|
+
|
|
705
|
+
setBasemap('standard');
|
|
706
|
+
// A listener that ends on access loss leaves the last map in place. Other
|
|
707
|
+
// terminal errors show the unreadable state. A later connection starts a new
|
|
708
|
+
// listener and can recover without the page writing to the store.
|
|
709
|
+
let listening = false;
|
|
710
|
+
function listen() {
|
|
711
|
+
listening = true;
|
|
712
|
+
onValue(ref(getStore()), snapshot => {
|
|
713
|
+
const value = snapshot.val();
|
|
714
|
+
if (value !== null && value !== undefined && (typeof value !== 'object' || Array.isArray(value))) {
|
|
715
|
+
showUnavailable();
|
|
716
|
+
return;
|
|
717
|
+
}
|
|
718
|
+
render(value);
|
|
719
|
+
}, error => {
|
|
720
|
+
listening = false;
|
|
721
|
+
if (error.code === 'no-store') return;
|
|
722
|
+
showUnavailable();
|
|
723
|
+
});
|
|
724
|
+
}
|
|
725
|
+
listen();
|
|
726
|
+
onConnectionStatusChanged(status => {
|
|
727
|
+
if (status === 'connected' && !listening) listen();
|
|
728
|
+
});
|