@uvalib/web-components 1.2.0 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +105 -0
- package/README.md +849 -47
- package/dist/analytics.d.ts +10 -0
- package/dist/analytics.js +9 -0
- package/dist/analytics.js.map +1 -0
- package/dist/base/UvalibElement.js +8 -5
- package/dist/base/UvalibElement.js.map +1 -1
- package/dist/base/analytics-state.d.ts +7 -0
- package/dist/base/analytics-state.js.map +1 -1
- package/dist/base/light-dom-styles.d.ts +13 -0
- package/dist/base/light-dom-styles.js +26 -0
- package/dist/base/light-dom-styles.js.map +1 -1
- package/dist/base/search-tracker.d.ts +57 -0
- package/dist/base/search-tracker.js +51 -0
- package/dist/base/search-tracker.js.map +1 -0
- package/dist/base.css +286 -14
- package/dist/base.d.ts +2 -0
- package/dist/base.js +1 -0
- package/dist/base.js.map +1 -1
- package/dist/components/site-analytics/SiteAnalytics.d.ts +20 -1
- package/dist/components/site-analytics/SiteAnalytics.js +93 -12
- package/dist/components/site-analytics/SiteAnalytics.js.map +1 -1
- package/dist/components/site-page/SitePage.d.ts +23 -0
- package/dist/components/site-page/SitePage.js +77 -0
- package/dist/components/site-page/SitePage.js.map +1 -1
- package/dist/components/uvalib-back-to-top/UvalibBackToTop.d.ts +58 -0
- package/dist/components/uvalib-back-to-top/UvalibBackToTop.js +250 -0
- package/dist/components/uvalib-back-to-top/UvalibBackToTop.js.map +1 -0
- package/dist/components/uvalib-back-to-top/uvalib-back-to-top.d.ts +1 -0
- package/dist/components/uvalib-back-to-top/uvalib-back-to-top.js +4 -0
- package/dist/components/uvalib-back-to-top/uvalib-back-to-top.js.map +1 -0
- package/dist/components/uvalib-breadcrumbs/UvalibBreadcrumbs.d.ts +14 -0
- package/dist/components/uvalib-breadcrumbs/UvalibBreadcrumbs.js +56 -4
- package/dist/components/uvalib-breadcrumbs/UvalibBreadcrumbs.js.map +1 -1
- package/dist/components/uvalib-chip-group/UvalibChipGroup.d.ts +25 -3
- package/dist/components/uvalib-chip-group/UvalibChipGroup.js +80 -10
- package/dist/components/uvalib-chip-group/UvalibChipGroup.js.map +1 -1
- package/dist/components/uvalib-combobox/UvalibCombobox.d.ts +212 -0
- package/dist/components/uvalib-combobox/UvalibCombobox.js +1088 -0
- package/dist/components/uvalib-combobox/UvalibCombobox.js.map +1 -0
- package/dist/components/uvalib-combobox/uvalib-combobox.d.ts +1 -0
- package/dist/components/uvalib-combobox/uvalib-combobox.js +4 -0
- package/dist/components/uvalib-combobox/uvalib-combobox.js.map +1 -0
- package/dist/components/uvalib-contents/UvalibContents.d.ts +53 -0
- package/dist/components/uvalib-contents/UvalibContents.js +202 -3
- package/dist/components/uvalib-contents/UvalibContents.js.map +1 -1
- package/dist/components/uvalib-date-histogram/UvalibDateHistogram.d.ts +56 -17
- package/dist/components/uvalib-date-histogram/UvalibDateHistogram.js +285 -81
- package/dist/components/uvalib-date-histogram/UvalibDateHistogram.js.map +1 -1
- package/dist/components/uvalib-date-range/UvalibDateRange.d.ts +6 -0
- package/dist/components/uvalib-date-range/UvalibDateRange.js +23 -0
- package/dist/components/uvalib-date-range/UvalibDateRange.js.map +1 -1
- package/dist/components/uvalib-filter-drawer/UvalibFilterDrawer.d.ts +113 -0
- package/dist/components/uvalib-filter-drawer/UvalibFilterDrawer.js +589 -0
- package/dist/components/uvalib-filter-drawer/UvalibFilterDrawer.js.map +1 -0
- package/dist/components/uvalib-filter-drawer/uvalib-filter-drawer.d.ts +1 -0
- package/dist/components/uvalib-filter-drawer/uvalib-filter-drawer.js +4 -0
- package/dist/components/uvalib-filter-drawer/uvalib-filter-drawer.js.map +1 -0
- package/dist/components/uvalib-image-regions/UvalibImageRegions.d.ts +138 -0
- package/dist/components/uvalib-image-regions/UvalibImageRegions.js +689 -0
- package/dist/components/uvalib-image-regions/UvalibImageRegions.js.map +1 -0
- package/dist/components/uvalib-image-regions/regions.d.ts +57 -0
- package/dist/components/uvalib-image-regions/regions.js +117 -0
- package/dist/components/uvalib-image-regions/regions.js.map +1 -0
- package/dist/components/uvalib-image-regions/uvalib-image-regions.d.ts +1 -0
- package/dist/components/uvalib-image-regions/uvalib-image-regions.js +4 -0
- package/dist/components/uvalib-image-regions/uvalib-image-regions.js.map +1 -0
- package/dist/components/uvalib-lightbox/UvalibLightbox.d.ts +79 -0
- package/dist/components/uvalib-lightbox/UvalibLightbox.js +295 -16
- package/dist/components/uvalib-lightbox/UvalibLightbox.js.map +1 -1
- package/dist/components/uvalib-map/UvalibMap.d.ts +251 -0
- package/dist/components/uvalib-map/UvalibMap.js +1395 -0
- package/dist/components/uvalib-map/UvalibMap.js.map +1 -0
- package/dist/components/uvalib-map/uvalib-map.d.ts +1 -0
- package/dist/components/uvalib-map/uvalib-map.js +4 -0
- package/dist/components/uvalib-map/uvalib-map.js.map +1 -0
- package/dist/components/uvalib-metadata/UvalibMetadata.d.ts +39 -2
- package/dist/components/uvalib-metadata/UvalibMetadata.js +214 -8
- package/dist/components/uvalib-metadata/UvalibMetadata.js.map +1 -1
- package/dist/components/uvalib-pager/UvalibPager.d.ts +22 -3
- package/dist/components/uvalib-pager/UvalibPager.js +42 -4
- package/dist/components/uvalib-pager/UvalibPager.js.map +1 -1
- package/dist/custom-elements.json +9641 -3131
- package/dist/index.d.ts +8 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -1
- package/dist/pagefind.css +4 -0
- package/dist/styles/base.js +119 -0
- package/dist/styles/base.js.map +1 -1
- package/dist/styles/color-scheme.js +5 -0
- package/dist/styles/color-scheme.js.map +1 -1
- package/dist/styles/controls.js +6 -0
- package/dist/styles/controls.js.map +1 -1
- package/dist/styles/hidden.d.ts +2 -0
- package/dist/styles/hidden.js +51 -0
- package/dist/styles/hidden.js.map +1 -0
- package/dist/styles/message.d.ts +1 -0
- package/dist/styles/message.js +82 -0
- package/dist/styles/message.js.map +1 -0
- package/dist/styles/pagefind.js +4 -0
- package/dist/styles/pagefind.js.map +1 -1
- package/dist/styles/result-list.d.ts +1 -0
- package/dist/styles/result-list.js +111 -0
- package/dist/styles/result-list.js.map +1 -0
- package/dist/styles/results.js +0 -15
- package/dist/styles/results.js.map +1 -1
- package/dist/testing/index.d.ts +110 -0
- package/dist/testing/index.js +100 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/testing/lighthouse-rules.d.ts +10 -0
- package/dist/testing/lighthouse-rules.js +44 -0
- package/dist/testing/lighthouse-rules.js.map +1 -0
- package/dist/tokens.css +5 -0
- package/dist-cdn/analytics.js +32 -0
- package/dist-cdn/analytics.js.map +1 -0
- package/dist-cdn/base.css +286 -14
- package/dist-cdn/bento-box.js +3 -3
- package/dist-cdn/chunks/{SiteAnalytics-Cm-FyhYS.js → SiteAnalytics-B9gu5aGO.js} +59 -30
- package/dist-cdn/chunks/SiteAnalytics-B9gu5aGO.js.map +1 -0
- package/dist-cdn/chunks/{UvalibElement-BnI-eRRR.js → UvalibElement-pGONDAwB.js} +108 -101
- package/dist-cdn/chunks/UvalibElement-pGONDAwB.js.map +1 -0
- package/dist-cdn/chunks/{accessible-GqhVn5_H.js → accessible-DJv7YOtS.js} +2 -2
- package/dist-cdn/chunks/{accessible-GqhVn5_H.js.map → accessible-DJv7YOtS.js.map} +1 -1
- package/dist-cdn/chunks/analytics-state-Ce8DKe4F.js.map +1 -1
- package/dist-cdn/chunks/{base-p5pk0vb2.js → base-BI8h0Gf3.js} +121 -2
- package/dist-cdn/chunks/base-BI8h0Gf3.js.map +1 -0
- package/dist-cdn/chunks/{library-weekly-hours-COE7Vv6V.js → library-weekly-hours-CrV3TlP5.js} +3 -3
- package/dist-cdn/chunks/{library-weekly-hours-COE7Vv6V.js.map → library-weekly-hours-CrV3TlP5.js.map} +1 -1
- package/dist-cdn/chunks/regions-B8ExwUGP.js +86 -0
- package/dist-cdn/chunks/regions-B8ExwUGP.js.map +1 -0
- package/dist-cdn/chunks/{repeat-CIFUYkyh.js → repeat-m5Zd_QeP.js} +2 -2
- package/dist-cdn/chunks/{repeat-CIFUYkyh.js.map → repeat-m5Zd_QeP.js.map} +1 -1
- package/dist-cdn/chunks/{site-header-BlOYvQg1.js → site-header-DYRMpdBj.js} +9 -4
- package/dist-cdn/chunks/{site-header-BlOYvQg1.js.map → site-header-DYRMpdBj.js.map} +1 -1
- package/dist-cdn/chunks/{site-main-nav-AaxZ9rQf.js → site-main-nav-DURrQMal.js} +3 -3
- package/dist-cdn/chunks/{site-main-nav-AaxZ9rQf.js.map → site-main-nav-DURrQMal.js.map} +1 -1
- package/dist-cdn/chunks/{static-html-1mTAG6nS.js → static-html-C1rhtCHu.js} +2 -2
- package/dist-cdn/chunks/{static-html-1mTAG6nS.js.map → static-html-C1rhtCHu.js.map} +1 -1
- package/dist-cdn/custom-elements.json +9641 -3131
- package/dist-cdn/events-section.js +3 -3
- package/dist-cdn/library-hours-setup.js +2 -2
- package/dist-cdn/library-weekly-hours.js +1 -1
- package/dist-cdn/manifest.json +10 -2
- package/dist-cdn/pagefind.css +4 -0
- package/dist-cdn/site-alerts.js +4 -4
- package/dist-cdn/site-analytics.js +2 -2
- package/dist-cdn/site-footer.js +2 -2
- package/dist-cdn/site-header.js +1 -1
- package/dist-cdn/site-hours-section.js +4 -4
- package/dist-cdn/site-main-nav.js +1 -1
- package/dist-cdn/site-page.js +56 -11
- package/dist-cdn/site-page.js.map +1 -1
- package/dist-cdn/site-style.js +2 -2
- package/dist-cdn/skills/uvalib-web-components/SKILL.md +98 -13
- package/dist-cdn/skills/uvalib-web-components/reference/accessibility-testing.md +34 -2
- package/dist-cdn/skills/uvalib-web-components/reference/components.md +302 -14
- package/dist-cdn/skills/uvalib-web-components/reference/snippets.md +1 -1
- package/dist-cdn/tokens.css +5 -0
- package/dist-cdn/uvalib-analytics.js +2 -2
- package/dist-cdn/uvalib-back-to-top.js +156 -0
- package/dist-cdn/uvalib-back-to-top.js.map +1 -0
- package/dist-cdn/uvalib-breadcrumbs.js +31 -11
- package/dist-cdn/uvalib-breadcrumbs.js.map +1 -1
- package/dist-cdn/uvalib-card-grid.js +1 -1
- package/dist-cdn/uvalib-card.js +3 -3
- package/dist-cdn/uvalib-chip-group.js +53 -14
- package/dist-cdn/uvalib-chip-group.js.map +1 -1
- package/dist-cdn/uvalib-combobox.js +667 -0
- package/dist-cdn/uvalib-combobox.js.map +1 -0
- package/dist-cdn/uvalib-contents.js +100 -22
- package/dist-cdn/uvalib-contents.js.map +1 -1
- package/dist-cdn/uvalib-date-histogram.js +237 -127
- package/dist-cdn/uvalib-date-histogram.js.map +1 -1
- package/dist-cdn/uvalib-date-range.js +14 -2
- package/dist-cdn/uvalib-date-range.js.map +1 -1
- package/dist-cdn/uvalib-filter-drawer.js +355 -0
- package/dist-cdn/uvalib-filter-drawer.js.map +1 -0
- package/dist-cdn/uvalib-filter.js +3 -3
- package/dist-cdn/uvalib-image-regions.js +460 -0
- package/dist-cdn/uvalib-image-regions.js.map +1 -0
- package/dist-cdn/uvalib-lightbox.js +214 -59
- package/dist-cdn/uvalib-lightbox.js.map +1 -1
- package/dist-cdn/uvalib-map.js +667 -0
- package/dist-cdn/uvalib-map.js.map +1 -0
- package/dist-cdn/uvalib-metadata.js +150 -24
- package/dist-cdn/uvalib-metadata.js.map +1 -1
- package/dist-cdn/uvalib-pager.js +29 -17
- package/dist-cdn/uvalib-pager.js.map +1 -1
- package/dist-cdn/uvalib-photo-grid.js +2 -2
- package/dist-cdn/uvalib-results-count.js +2 -2
- package/dist-cdn/uvalib-tabs.js +2 -2
- package/dist-cdn/uvalib-tag-list.js +2 -2
- package/package.json +43 -1
- package/skills/uvalib-web-components/SKILL.md +98 -13
- package/skills/uvalib-web-components/reference/accessibility-testing.md +34 -2
- package/skills/uvalib-web-components/reference/components.md +302 -14
- package/skills/uvalib-web-components/reference/snippets.md +1 -1
- package/dist-cdn/chunks/SiteAnalytics-Cm-FyhYS.js.map +0 -1
- package/dist-cdn/chunks/UvalibElement-BnI-eRRR.js.map +0 -1
- package/dist-cdn/chunks/base-p5pk0vb2.js.map +0 -1
|
@@ -0,0 +1,1395 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import { html, nothing, unsafeCSS } from 'lit';
|
|
8
|
+
import { property, state } from 'lit/decorators.js';
|
|
9
|
+
import { trackEvent } from '../../base/analytics.js';
|
|
10
|
+
import { installLightDomStyles } from '../../base/light-dom-styles.js';
|
|
11
|
+
import { normalize, safeHref, SourceChildren } from '../../base/source-children.js';
|
|
12
|
+
import { UvalibElement } from '../../base/UvalibElement.js';
|
|
13
|
+
import { accessible } from '../../styles/accessible.js';
|
|
14
|
+
const countOf = (p) => p && Number.isFinite(p.count) && p.count > 0 ? p.count : 0;
|
|
15
|
+
/** The analytics category. */
|
|
16
|
+
const TAG = 'uvalib-map';
|
|
17
|
+
/** OpenStreetMap's standard tiles: fine for low traffic only (see the README). */
|
|
18
|
+
export const OSM_TILE_URL = 'https://tile.openstreetmap.org/{z}/{x}/{y}.png';
|
|
19
|
+
export const OSM_ATTRIBUTION = '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors';
|
|
20
|
+
/** Where the map opens with no places and no `center`: the Lawn. */
|
|
21
|
+
const GROUNDS = [38.0336, -78.5048];
|
|
22
|
+
/** Marker dot diameters (px): the smallest and largest count. Every target is at least 44px. */
|
|
23
|
+
const MIN_DOT = 24;
|
|
24
|
+
const MAX_DOT = 56;
|
|
25
|
+
const HIT = 44;
|
|
26
|
+
/**
|
|
27
|
+
* Space kept between two visible markers' hit areas: closer ones are grouped. Every target is
|
|
28
|
+
* at least 44px, so WCAG 2.5.8 only needs them not to overlap; a few pixels keep them visibly
|
|
29
|
+
* apart without grouping places that are merely close.
|
|
30
|
+
*/
|
|
31
|
+
const GROUP_GAP = 4;
|
|
32
|
+
/** Space between the places of an open ring (and the group), generous since they are close by design. */
|
|
33
|
+
const GAP = 24;
|
|
34
|
+
/** A group's dot: big enough for the number of places in it, and never larger than this. */
|
|
35
|
+
const MIN_GROUP_DOT = 32;
|
|
36
|
+
const MAX_GROUP_DOT = 64;
|
|
37
|
+
const MAP_HEIGHT = 'var(--uvalib-map-height, min(24rem, 75vw))';
|
|
38
|
+
/** Shown above the map, and kept in step with base.css's pre-upgrade placeholder. */
|
|
39
|
+
export const MAP_INSTRUCTIONS = 'Tab or arrow keys move between places; Enter opens one. With the map focused, arrow keys pan and + and − zoom.';
|
|
40
|
+
let instanceCounter = 0;
|
|
41
|
+
const fmt = (n) => n.toLocaleString('en-US');
|
|
42
|
+
/** "photos" for most counts, "photo" for one. */
|
|
43
|
+
const noun = (unit, n) => (n === 1 && /s$/.test(unit) ? unit.slice(0, -1) : unit);
|
|
44
|
+
const validPlace = (p) => Number.isFinite(p.lat) &&
|
|
45
|
+
Number.isFinite(p.lng) &&
|
|
46
|
+
Math.abs(p.lat) <= 90 &&
|
|
47
|
+
Math.abs(p.lng) <= 180;
|
|
48
|
+
/** Parse `"lat, lng"`; null unless both are numbers in range. */
|
|
49
|
+
function parseCenter(s) {
|
|
50
|
+
const m = /^\s*(-?\d+(?:\.\d+)?)\s*,\s*(-?\d+(?:\.\d+)?)\s*$/.exec(s);
|
|
51
|
+
if (!m)
|
|
52
|
+
return null;
|
|
53
|
+
const [lat, lng] = [Number(m[1]), Number(m[2])];
|
|
54
|
+
return Math.abs(lat) <= 90 && Math.abs(lng) <= 180 ? [lat, lng] : null;
|
|
55
|
+
}
|
|
56
|
+
/** Whether the page shows the opt-in dark mode (`data-uva-color-scheme` on the root element). */
|
|
57
|
+
function pageIsDark(doc) {
|
|
58
|
+
const attr = doc.documentElement.getAttribute('data-uva-color-scheme');
|
|
59
|
+
if (attr === null)
|
|
60
|
+
return false;
|
|
61
|
+
try {
|
|
62
|
+
if (!doc.defaultView?.CSS?.supports?.('color', 'light-dark(#000, #fff)'))
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
catch {
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
if (attr === 'dark')
|
|
69
|
+
return true;
|
|
70
|
+
if (attr === 'light')
|
|
71
|
+
return false;
|
|
72
|
+
return !!doc.defaultView?.matchMedia?.('(prefers-color-scheme: dark)').matches;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Leaflet's own layout rules that the map needs (panes, tiles, controls, the tooltip), so
|
|
76
|
+
* Leaflet's leaflet.css is optional and the map works inside the shadow root. Kept with
|
|
77
|
+
* `no-style`, with the map's height, the 44px marker and zoom targets, the hidden marker
|
|
78
|
+
* names and skip link, and forced-colors borders. `host` is `:host` or the tag. Sizes that
|
|
79
|
+
* leaflet.css also sets are `!important`, so a page that loads it (light DOM) keeps them.
|
|
80
|
+
*/
|
|
81
|
+
const structuralRules = (host) => `
|
|
82
|
+
${host} { display: block; position: relative; max-width: 100%; min-width: 0; box-sizing: border-box; }
|
|
83
|
+
${host}[hidden], ${host} [hidden] { display: none !important; }
|
|
84
|
+
${host} .visually-hidden {
|
|
85
|
+
position: absolute !important; width: 1px !important; height: 1px !important; margin: -1px; padding: 0;
|
|
86
|
+
overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
|
|
87
|
+
}
|
|
88
|
+
${host} .skip-link { position: absolute; inset-inline-start: 0; inset-block-start: 0; z-index: 1100; transform: translateY(-120%); }
|
|
89
|
+
${host} .skip-link:focus-visible { transform: translateY(0); }
|
|
90
|
+
${host} .map { position: relative; block-size: ${MAP_HEIGHT}; min-block-size: 12rem; box-sizing: border-box; }
|
|
91
|
+
${host} .leaflet-pane, ${host} .leaflet-tile, ${host} .leaflet-marker-icon, ${host} .leaflet-marker-shadow,
|
|
92
|
+
${host} .leaflet-tile-container, ${host} .leaflet-pane > svg, ${host} .leaflet-pane > canvas,
|
|
93
|
+
${host} .leaflet-zoom-box, ${host} .leaflet-image-layer, ${host} .leaflet-layer {
|
|
94
|
+
position: absolute; left: 0; top: 0;
|
|
95
|
+
}
|
|
96
|
+
${host} .leaflet-container { overflow: hidden; -webkit-tap-highlight-color: transparent; }
|
|
97
|
+
${host} .leaflet-tile, ${host} .leaflet-marker-icon { user-select: none; -webkit-user-drag: none; }
|
|
98
|
+
${host} .leaflet-marker-icon { display: block; }
|
|
99
|
+
${host} .leaflet-container .leaflet-tile-pane img, ${host} .leaflet-container .leaflet-tile {
|
|
100
|
+
max-width: none !important; max-height: none !important; width: auto; padding: 0;
|
|
101
|
+
}
|
|
102
|
+
${host} .leaflet-container.leaflet-touch-zoom { touch-action: pan-x pan-y; }
|
|
103
|
+
${host} .leaflet-container.leaflet-touch-drag { touch-action: pinch-zoom; }
|
|
104
|
+
${host} .leaflet-container.leaflet-touch-drag.leaflet-touch-zoom { touch-action: none; }
|
|
105
|
+
${host} .leaflet-tile { filter: inherit; visibility: hidden; }
|
|
106
|
+
${host} .leaflet-tile-loaded { visibility: inherit; }
|
|
107
|
+
${host} .leaflet-zoom-box { width: 0; height: 0; box-sizing: border-box; z-index: 800; }
|
|
108
|
+
${host} .leaflet-pane { z-index: 400; }
|
|
109
|
+
${host} .leaflet-tile-pane { z-index: 200; }
|
|
110
|
+
${host} .leaflet-overlay-pane { z-index: 400; }
|
|
111
|
+
${host} .leaflet-shadow-pane { z-index: 500; }
|
|
112
|
+
${host} .leaflet-marker-pane { z-index: 600; }
|
|
113
|
+
${host} .leaflet-tooltip-pane { z-index: 650; }
|
|
114
|
+
${host} .leaflet-popup-pane { z-index: 700; }
|
|
115
|
+
${host} .leaflet-control { position: relative; z-index: 800; pointer-events: auto; float: left; clear: both; }
|
|
116
|
+
${host} .leaflet-top, ${host} .leaflet-bottom { position: absolute; z-index: 1000; pointer-events: none; }
|
|
117
|
+
${host} .leaflet-top { top: 0; }
|
|
118
|
+
${host} .leaflet-right { right: 0; }
|
|
119
|
+
${host} .leaflet-bottom { bottom: 0; }
|
|
120
|
+
${host} .leaflet-left { left: 0; }
|
|
121
|
+
${host} .leaflet-right .leaflet-control { float: right; }
|
|
122
|
+
${host} .leaflet-top .leaflet-control { margin-top: 10px; }
|
|
123
|
+
${host} .leaflet-bottom .leaflet-control { margin-bottom: 10px; }
|
|
124
|
+
${host} .leaflet-left .leaflet-control { margin-left: 10px; }
|
|
125
|
+
${host} .leaflet-right .leaflet-control { margin-right: 10px; }
|
|
126
|
+
${host} .leaflet-control-attribution { margin: 0 !important; }
|
|
127
|
+
${host} .leaflet-zoom-animated { transform-origin: 0 0; }
|
|
128
|
+
${host} .leaflet-zoom-anim .leaflet-zoom-animated { transition: transform 0.25s cubic-bezier(0, 0, 0.25, 1); }
|
|
129
|
+
${host} .leaflet-zoom-anim .leaflet-tile, ${host} .leaflet-pan-anim .leaflet-tile { transition: none; }
|
|
130
|
+
${host} .leaflet-zoom-anim .leaflet-zoom-hide { visibility: hidden; }
|
|
131
|
+
${host} .leaflet-interactive { cursor: pointer; }
|
|
132
|
+
${host} .leaflet-grab { cursor: grab; }
|
|
133
|
+
${host} .leaflet-dragging .leaflet-grab, ${host} .leaflet-dragging .leaflet-grab .leaflet-interactive { cursor: grabbing; }
|
|
134
|
+
${host} .leaflet-marker-icon, ${host} .leaflet-tile-container { pointer-events: none; }
|
|
135
|
+
${host} .leaflet-marker-icon.leaflet-interactive { pointer-events: auto; }
|
|
136
|
+
${host} .leaflet-tooltip { position: absolute; pointer-events: none; white-space: nowrap; user-select: none; }
|
|
137
|
+
${host} .uvalib-map-marker .marker {
|
|
138
|
+
box-sizing: border-box; display: flex; align-items: center; justify-content: center;
|
|
139
|
+
inline-size: 100%; block-size: 100%; margin: 0; padding: 0; border: 0; background: none;
|
|
140
|
+
cursor: pointer; font: inherit; color: inherit;
|
|
141
|
+
}
|
|
142
|
+
${host} .uvalib-map-marker .dot { box-sizing: border-box; display: block; flex: none; inline-size: var(--d); block-size: var(--d); border-radius: 50%; }
|
|
143
|
+
${host} .uvalib-map-marker.is-group .dot { display: flex; align-items: center; justify-content: center; font-weight: 700; line-height: 1; }
|
|
144
|
+
${host} .leaflet-bar a {
|
|
145
|
+
box-sizing: border-box; display: flex !important; align-items: center; justify-content: center;
|
|
146
|
+
inline-size: 44px !important; block-size: 44px !important; line-height: 1 !important;
|
|
147
|
+
}
|
|
148
|
+
@media (prefers-reduced-motion: reduce) {
|
|
149
|
+
${host} .leaflet-zoom-anim .leaflet-zoom-animated { transition: none; }
|
|
150
|
+
}
|
|
151
|
+
@media (forced-colors: active) {
|
|
152
|
+
${host} .uvalib-map-marker .dot {
|
|
153
|
+
forced-color-adjust: none; background: Canvas !important; color: CanvasText !important; border: 3px solid CanvasText !important; box-shadow: none !important;
|
|
154
|
+
}
|
|
155
|
+
${host} .uvalib-map-marker.is-group .dot { border-style: double !important; border-width: 6px !important; }
|
|
156
|
+
${host} .uvalib-map-marker.is-active .dot { outline: 3px solid Highlight; outline-offset: 3px; }
|
|
157
|
+
${host} .uvalib-map-marker .marker:focus-visible .dot { outline: 3px solid Highlight; outline-offset: 6px; }
|
|
158
|
+
${host} .map, ${host} .map .leaflet-bar, ${host} .map .leaflet-bar a, ${host} .map .leaflet-tooltip,
|
|
159
|
+
${host} .map .leaflet-control-attribution, ${host} .place {
|
|
160
|
+
border: 1px solid CanvasText !important;
|
|
161
|
+
}
|
|
162
|
+
${host} .place.is-active { outline: 3px solid Highlight; outline-offset: 1px; }
|
|
163
|
+
${host} :is(.map, .leaflet-bar a, a, .skip-link):focus-visible { outline: 3px solid Highlight; outline-offset: 2px; }
|
|
164
|
+
}
|
|
165
|
+
`;
|
|
166
|
+
const shadowStructure = unsafeCSS(structuralRules(':host'));
|
|
167
|
+
/**
|
|
168
|
+
* A map of places with a linked list of the same places: buildings, rooms or outdoor spaces,
|
|
169
|
+
* each a marker sized by a count, with a link to the place's page. It wraps
|
|
170
|
+
* [Leaflet](https://leafletjs.com) 1.9, which the page provides (the library never bundles
|
|
171
|
+
* it): set the `leaflet` property to the Leaflet module (`import * as L from 'leaflet'`), or
|
|
172
|
+
* load leaflet.js so that `window.L` exists. Without Leaflet only the list is shown, with
|
|
173
|
+
* one console warning. Leaflet's leaflet.css is optional: the element carries the layout
|
|
174
|
+
* rules it needs, in shadow DOM and light DOM alike.
|
|
175
|
+
*
|
|
176
|
+
* Places come from `items` (`{ id?, name, lat, lng, count?, href?, description? }`) or from
|
|
177
|
+
* a child `<ul>`/`<ol>` of `<li><a href data-lat data-lng data-count>Name</a></li>`, which is
|
|
178
|
+
* the list before the script runs (and without it). The list always stays, under the map:
|
|
179
|
+
* it is the text equivalent.
|
|
180
|
+
*
|
|
181
|
+
* Each marker is a real link (a button when the place has no `href`) named like "The
|
|
182
|
+
* Rotunda, 2,702 photos" (`count-label` is the noun), sized by the square root of its count
|
|
183
|
+
* (a 24 to 56px dot in a hit area of at least 44px). Tab or the arrow keys move between
|
|
184
|
+
* markers, Enter follows the link (or chooses the place), and Escape hides the tooltip.
|
|
185
|
+
* Hovering or focusing a marker shows a tooltip with its name and count and highlights its
|
|
186
|
+
* list entry; hovering or focusing a list entry highlights its marker (a ring and a larger
|
|
187
|
+
* dot, not colour alone) and brings it into view.
|
|
188
|
+
*
|
|
189
|
+
* Markers whose 44px targets would overlap at the current zoom are drawn as one group
|
|
190
|
+
* marker (regrouped after every zoom and resize): a button
|
|
191
|
+
* showing how many places it holds, sized by their summed count and named like "The Rotunda
|
|
192
|
+
* and 2 more places, 3,610 photos" (the largest place's name; `place-label` is the noun).
|
|
193
|
+
* Choosing it zooms in until its places part; when they cannot (one point, or the
|
|
194
|
+
* maximum zoom) it spreads them in a ring around it instead, with focus on the first;
|
|
195
|
+
* Escape or a zoom closes the ring and focus returns to the group. The arrow keys move
|
|
196
|
+
* between the markers shown (a group is one); a place in the list that is in a group
|
|
197
|
+
* highlights the group, whose tooltip names the place.
|
|
198
|
+
*
|
|
199
|
+
* The map is a region named by `label`, after a "Skip map, go to the list" link and a line
|
|
200
|
+
* of key instructions. It opens on the bounds of the places, or on `center` and `zoom`. The
|
|
201
|
+
* zoom buttons are 44px with a visible focus ring; the attribution stays. Tiles come from
|
|
202
|
+
* `tile-url` (OpenStreetMap by default: low-traffic use only) with `attribution`. In the
|
|
203
|
+
* page's dark mode the tiles are inverted with a CSS filter (`--uvalib-map-dark-filter`)
|
|
204
|
+
* unless `dark-tile-url` gives dark tiles; markers and controls are never filtered. With
|
|
205
|
+
* `prefers-reduced-motion` nothing animates.
|
|
206
|
+
*
|
|
207
|
+
* @tagname uvalib-map
|
|
208
|
+
* @slot - A `<ul>` or `<ol>` of places: each `<li>` holds an `<a href>` (or the `<li>` itself) with `data-lat`, `data-lng` and optionally `data-count`, `data-id` and `data-description`. Used when `items` is empty; without JavaScript it is the list.
|
|
209
|
+
* @fires select - A place's marker was chosen (click, Enter or Space); never a group's. `detail` is `{ item }`. Cancelable: for a place with `href`, `preventDefault()` keeps the page from following the link. Bubbles and is composed.
|
|
210
|
+
* @fires uvalib-analytics-event - For `<site-analytics>`: `['uvalib-map', 'select', '<label>', <position from 1>]` when a place's marker is chosen, `['uvalib-map', 'expand', '<label>', <places in it>]` when a group is chosen (it zooms in or opens its ring), and `['uvalib-map', 'zoom', '<label>', <zoom level>]` 1 s after the last zoom-button press. Never a place's name, coordinates or URL. Bubbles and is composed.
|
|
211
|
+
* @csspart map - The map region (the Leaflet container).
|
|
212
|
+
* @csspart instructions - The line of key instructions above the map.
|
|
213
|
+
* @csspart list - The list of places.
|
|
214
|
+
* @csspart place - Each list entry.
|
|
215
|
+
* @cssprop [--uvalib-map-height=min(24rem, 75vw)] - Height of the map.
|
|
216
|
+
* @cssprop [--uvalib-map-dark-filter=invert(1) hue-rotate(180deg) brightness(0.95) contrast(0.9)] - The filter on the tiles in dark mode, when there is no `dark-tile-url`.
|
|
217
|
+
* @cssprop [--uva-brand-blue=#232d4b] - Marker fill.
|
|
218
|
+
* @cssprop [--uva-brand-orange=#e57200] - Focus ring when `--uva-color-focus` is unset.
|
|
219
|
+
* @cssprop [--uva-font-family=inherit] - Font family.
|
|
220
|
+
* @cssprop --uva-color-accent-bg - Dark-mode role token: marker fill (else `--uva-brand-blue`).
|
|
221
|
+
* @cssprop --uva-color-on-accent - Dark-mode role token: marker border (else #fff).
|
|
222
|
+
* @cssprop --uva-color-text - Dark-mode role token: text and the highlight ring (else #2b2b2b).
|
|
223
|
+
* @cssprop --uva-color-text-muted - Dark-mode role token: instructions and descriptions (else #4b5563).
|
|
224
|
+
* @cssprop --uva-color-link - Dark-mode role token: links (else `--uva-brand-blue`).
|
|
225
|
+
* @cssprop --uva-color-surface - Dark-mode role token: attribution background and the highlight ring's gap (else #fff).
|
|
226
|
+
* @cssprop --uva-color-surface-raised - Dark-mode role token: zoom buttons, tooltip and list entries (else #fff).
|
|
227
|
+
* @cssprop --uva-color-surface-hover - Dark-mode role token: hovered zoom button (else #dadada).
|
|
228
|
+
* @cssprop --uva-color-track - Dark-mode role token: the map before tiles load, and count badges (else #e5e7eb).
|
|
229
|
+
* @cssprop --uva-color-control-border - Dark-mode role token: borders (else #808080).
|
|
230
|
+
* @cssprop --uva-color-focus - Dark-mode role token: focus ring (else `--uva-brand-orange`).
|
|
231
|
+
* @cssprop --uva-color-shadow - Dark-mode role token: control and tooltip shadow.
|
|
232
|
+
*/
|
|
233
|
+
export class UvalibMap extends UvalibElement {
|
|
234
|
+
static { this.styles = [
|
|
235
|
+
accessible,
|
|
236
|
+
shadowStructure,
|
|
237
|
+
unsafeCSS(`
|
|
238
|
+
:host { font-family: var(--uva-font-family, inherit); color: var(--uva-color-text, #2b2b2b); }
|
|
239
|
+
.instructions {
|
|
240
|
+
margin: 0 0 0.5rem;
|
|
241
|
+
font-size: 0.875rem;
|
|
242
|
+
line-height: 1.5;
|
|
243
|
+
color: var(--uva-color-text-muted, #4b5563);
|
|
244
|
+
}
|
|
245
|
+
.map {
|
|
246
|
+
border: 1px solid var(--uva-color-control-border, #808080);
|
|
247
|
+
border-radius: 4px;
|
|
248
|
+
background: var(--uva-color-track, #e5e7eb) !important;
|
|
249
|
+
font-family: inherit !important;
|
|
250
|
+
font-size: 1rem !important;
|
|
251
|
+
line-height: 1.5 !important;
|
|
252
|
+
}
|
|
253
|
+
.map:focus-visible {
|
|
254
|
+
outline: 3px solid var(--uva-color-focus, var(--uva-brand-orange, #e57200));
|
|
255
|
+
outline-offset: 2px;
|
|
256
|
+
}
|
|
257
|
+
.dark-tiles .leaflet-tile-pane {
|
|
258
|
+
filter: var(--uvalib-map-dark-filter, invert(1) hue-rotate(180deg) brightness(0.95) contrast(0.9));
|
|
259
|
+
}
|
|
260
|
+
.uvalib-map-marker .dot {
|
|
261
|
+
background: var(--uva-color-accent-bg, var(--uva-brand-blue, #232d4b));
|
|
262
|
+
border: 2px solid var(--uva-color-on-accent, #fff);
|
|
263
|
+
box-shadow: 0 0 0 1px var(--uva-color-accent-bg, var(--uva-brand-blue, #232d4b));
|
|
264
|
+
transition: transform 0.15s ease, box-shadow 0.15s ease;
|
|
265
|
+
}
|
|
266
|
+
/* A group: its number of places, and a second ring (not colour alone). */
|
|
267
|
+
.uvalib-map-marker.is-group .dot {
|
|
268
|
+
color: var(--uva-color-on-accent, #fff);
|
|
269
|
+
font-family: var(--uva-font-family, system-ui, sans-serif);
|
|
270
|
+
font-size: 0.875rem;
|
|
271
|
+
box-shadow:
|
|
272
|
+
0 0 0 1px var(--uva-color-accent-bg, var(--uva-brand-blue, #232d4b)),
|
|
273
|
+
0 0 0 3px var(--uva-color-on-accent, #fff),
|
|
274
|
+
0 0 0 5px var(--uva-color-accent-bg, var(--uva-brand-blue, #232d4b));
|
|
275
|
+
}
|
|
276
|
+
.uvalib-map-marker.is-active .dot {
|
|
277
|
+
transform: scale(1.25);
|
|
278
|
+
box-shadow:
|
|
279
|
+
0 0 0 3px var(--uva-color-surface, #fff),
|
|
280
|
+
0 0 0 6px var(--uva-color-text, #2b2b2b);
|
|
281
|
+
}
|
|
282
|
+
.uvalib-map-marker .marker:focus-visible { outline: none; }
|
|
283
|
+
.uvalib-map-marker .marker:focus-visible .dot {
|
|
284
|
+
outline: 3px solid var(--uva-color-focus, var(--uva-brand-orange, #e57200));
|
|
285
|
+
outline-offset: 6px;
|
|
286
|
+
}
|
|
287
|
+
.leaflet-bar {
|
|
288
|
+
border: 1px solid var(--uva-color-control-border, #808080) !important;
|
|
289
|
+
border-radius: 4px !important;
|
|
290
|
+
background: var(--uva-color-surface-raised, #fff) !important;
|
|
291
|
+
box-shadow: 0 1px 4px var(--uva-color-shadow, rgba(0, 0, 0, 0.2)) !important;
|
|
292
|
+
}
|
|
293
|
+
.leaflet-bar a {
|
|
294
|
+
border: 0 !important;
|
|
295
|
+
border-radius: 0 !important;
|
|
296
|
+
background: var(--uva-color-surface-raised, #fff) !important;
|
|
297
|
+
color: var(--uva-color-text, #2b2b2b) !important;
|
|
298
|
+
font: 600 1.5rem/1 var(--uva-font-family, system-ui, sans-serif) !important;
|
|
299
|
+
text-decoration: none !important;
|
|
300
|
+
}
|
|
301
|
+
.leaflet-bar a:first-child { border-radius: 3px 3px 0 0 !important; }
|
|
302
|
+
.leaflet-bar a:last-child { border-radius: 0 0 3px 3px !important; }
|
|
303
|
+
.leaflet-bar a + a { border-block-start: 1px solid var(--uva-color-control-border, #808080) !important; }
|
|
304
|
+
.leaflet-bar a:hover { background: var(--uva-color-surface-hover, #dadada) !important; }
|
|
305
|
+
.leaflet-bar a.leaflet-disabled {
|
|
306
|
+
background: var(--uva-color-track, #e5e7eb) !important;
|
|
307
|
+
color: var(--uva-color-text-muted, #4b5563) !important;
|
|
308
|
+
cursor: not-allowed;
|
|
309
|
+
}
|
|
310
|
+
.leaflet-bar a:focus-visible { position: relative; z-index: 1; }
|
|
311
|
+
.leaflet-control-attribution {
|
|
312
|
+
padding: 0.125rem 0.375rem !important;
|
|
313
|
+
background: var(--uva-color-surface, #fff) !important;
|
|
314
|
+
color: var(--uva-color-text, #2b2b2b) !important;
|
|
315
|
+
font-size: 0.8125rem !important;
|
|
316
|
+
line-height: 1.5 !important;
|
|
317
|
+
}
|
|
318
|
+
.leaflet-control-attribution a {
|
|
319
|
+
color: var(--uva-color-link, var(--uva-brand-blue, #232d4b)) !important;
|
|
320
|
+
text-decoration: underline !important;
|
|
321
|
+
}
|
|
322
|
+
.leaflet-tooltip {
|
|
323
|
+
padding: 0.25rem 0.5rem !important;
|
|
324
|
+
border: 1px solid var(--uva-color-control-border, #808080) !important;
|
|
325
|
+
border-radius: 4px !important;
|
|
326
|
+
background: var(--uva-color-surface-raised, #fff) !important;
|
|
327
|
+
color: var(--uva-color-text, #2b2b2b) !important;
|
|
328
|
+
box-shadow: 0 1px 4px var(--uva-color-shadow, rgba(0, 0, 0, 0.2)) !important;
|
|
329
|
+
font-size: 0.875rem !important;
|
|
330
|
+
line-height: 1.4 !important;
|
|
331
|
+
}
|
|
332
|
+
.leaflet-tooltip::before { display: none !important; }
|
|
333
|
+
.tip-name { display: block; font-weight: 600; }
|
|
334
|
+
.tip-note { display: block; }
|
|
335
|
+
.places {
|
|
336
|
+
display: grid;
|
|
337
|
+
grid-template-columns: repeat(auto-fill, minmax(min(100%, 15rem), 1fr));
|
|
338
|
+
gap: 0.5rem;
|
|
339
|
+
margin: 1rem 0 0;
|
|
340
|
+
padding: 0;
|
|
341
|
+
list-style: none;
|
|
342
|
+
}
|
|
343
|
+
.places:focus { outline: none; }
|
|
344
|
+
.places:focus-visible {
|
|
345
|
+
outline: 3px solid var(--uva-color-focus, var(--uva-brand-orange, #e57200));
|
|
346
|
+
outline-offset: 2px;
|
|
347
|
+
}
|
|
348
|
+
.place {
|
|
349
|
+
display: flex;
|
|
350
|
+
flex-wrap: wrap;
|
|
351
|
+
align-items: baseline;
|
|
352
|
+
gap: 0.25rem 0.5rem;
|
|
353
|
+
padding: 0.5rem 0.75rem;
|
|
354
|
+
border: 1px solid var(--uva-color-control-border, #808080);
|
|
355
|
+
border-radius: 4px;
|
|
356
|
+
background: var(--uva-color-surface-raised, #fff);
|
|
357
|
+
color: var(--uva-color-text, #2b2b2b);
|
|
358
|
+
}
|
|
359
|
+
.place.is-active {
|
|
360
|
+
outline: 3px solid var(--uva-color-text, #2b2b2b);
|
|
361
|
+
outline-offset: 1px;
|
|
362
|
+
}
|
|
363
|
+
.place a, .place .name {
|
|
364
|
+
display: inline-block;
|
|
365
|
+
min-block-size: 24px;
|
|
366
|
+
font-weight: 600;
|
|
367
|
+
line-height: 1.5;
|
|
368
|
+
}
|
|
369
|
+
.place a { color: var(--uva-color-link, var(--uva-brand-blue, #232d4b)); text-decoration: underline; }
|
|
370
|
+
.count {
|
|
371
|
+
padding: 0 0.5rem;
|
|
372
|
+
border: 1px solid var(--uva-color-control-border, #808080);
|
|
373
|
+
border-radius: 999px;
|
|
374
|
+
background: var(--uva-color-track, #e5e7eb);
|
|
375
|
+
color: var(--uva-color-text, #2b2b2b);
|
|
376
|
+
font-size: 0.875rem;
|
|
377
|
+
white-space: nowrap;
|
|
378
|
+
}
|
|
379
|
+
.description {
|
|
380
|
+
flex-basis: 100%;
|
|
381
|
+
font-size: 0.875rem;
|
|
382
|
+
color: var(--uva-color-text-muted, #4b5563);
|
|
383
|
+
}
|
|
384
|
+
@media (prefers-reduced-motion: reduce) {
|
|
385
|
+
.uvalib-map-marker .dot { transition: none; }
|
|
386
|
+
}
|
|
387
|
+
`),
|
|
388
|
+
]; }
|
|
389
|
+
constructor() {
|
|
390
|
+
super();
|
|
391
|
+
/** The places. When non-empty, wins over the child list. Set a new array to update. */
|
|
392
|
+
this.items = [];
|
|
393
|
+
/** The map's name (required): the region's label, the list's label and the analytics name. */
|
|
394
|
+
this.label = '';
|
|
395
|
+
/** The noun after each count, plural ("photos"); a count of one drops a trailing s. */
|
|
396
|
+
this.countLabel = 'items';
|
|
397
|
+
/**
|
|
398
|
+
* The noun for places in a group's name, plural: "The Rotunda and 2 more places" (one
|
|
399
|
+
* drops a trailing s: "and 1 more place"). For example "rooms".
|
|
400
|
+
*/
|
|
401
|
+
this.placeLabel = 'places';
|
|
402
|
+
/** The tile URL template (`{z}/{x}/{y}`, optionally `{s}` and `{r}`). */
|
|
403
|
+
this.tileUrl = OSM_TILE_URL;
|
|
404
|
+
/** Tiles for the page's dark mode. Without it, dark mode filters the light tiles instead. */
|
|
405
|
+
this.darkTileUrl = '';
|
|
406
|
+
/** The tiles' attribution, as HTML. Required by most tile sources; always shown. */
|
|
407
|
+
this.attribution = OSM_ATTRIBUTION;
|
|
408
|
+
/** Where the map opens, `"lat,lng"`. Without it the map fits every place. */
|
|
409
|
+
this.center = '';
|
|
410
|
+
this.sourceItems = [];
|
|
411
|
+
this.hasLeaflet = false;
|
|
412
|
+
/** The highlighted target: "3" a place, "g:1,3" a group, "" none. */
|
|
413
|
+
this.active = '';
|
|
414
|
+
this.dark = false;
|
|
415
|
+
this.uid = `uvalib-map-${++instanceCounter}`;
|
|
416
|
+
this.sourceKey = '[]';
|
|
417
|
+
this.markers = [];
|
|
418
|
+
this.dots = [];
|
|
419
|
+
this.maxCount = 0;
|
|
420
|
+
/** The groups drawn at the current zoom, by key. */
|
|
421
|
+
this.groups = new Map();
|
|
422
|
+
/** A grouped place's index → its group's key. */
|
|
423
|
+
this.groupOf = new Map();
|
|
424
|
+
/** The key of the group whose places are spread in a ring, or "". */
|
|
425
|
+
this.ring = '';
|
|
426
|
+
/** The visible markers' controls, in keyboard (and document) order. */
|
|
427
|
+
this.order = [];
|
|
428
|
+
this.drawn = [];
|
|
429
|
+
this.reduceMotion = false;
|
|
430
|
+
/** The visitor moved the map: a resize no longer refits it. */
|
|
431
|
+
this.userMoved = false;
|
|
432
|
+
this.fitting = false;
|
|
433
|
+
this.hoverKey = '';
|
|
434
|
+
this.focusKey = '';
|
|
435
|
+
this.dismissed = false;
|
|
436
|
+
this.warnedLabel = false;
|
|
437
|
+
this.warnedLeaflet = false;
|
|
438
|
+
this.onPageLoad = () => this.requestUpdate();
|
|
439
|
+
this.readScheme = () => {
|
|
440
|
+
this.dark = pageIsDark(this.ownerDocument);
|
|
441
|
+
};
|
|
442
|
+
this.onMapClick = (e) => {
|
|
443
|
+
const t = e.target;
|
|
444
|
+
if (t.closest?.('.leaflet-control-zoom a')) {
|
|
445
|
+
this.queueZoomReport();
|
|
446
|
+
return;
|
|
447
|
+
}
|
|
448
|
+
const key = this.targetOf(e);
|
|
449
|
+
if (!key)
|
|
450
|
+
return;
|
|
451
|
+
// The end of a drag that started on a marker is not a choice (a key press always is).
|
|
452
|
+
const drag = this.map?.dragging;
|
|
453
|
+
if (e.detail !== 0 && drag?.moved?.()) {
|
|
454
|
+
e.preventDefault();
|
|
455
|
+
return;
|
|
456
|
+
}
|
|
457
|
+
if (key.startsWith('g:')) {
|
|
458
|
+
this.expand(key.slice(2));
|
|
459
|
+
return;
|
|
460
|
+
}
|
|
461
|
+
const i = Number(key);
|
|
462
|
+
const p = this.places[i];
|
|
463
|
+
if (!p)
|
|
464
|
+
return;
|
|
465
|
+
trackEvent(this, [TAG, 'select', this.label, i + 1]);
|
|
466
|
+
const go = this.dispatchEvent(new CustomEvent('select', {
|
|
467
|
+
detail: { item: p },
|
|
468
|
+
bubbles: true,
|
|
469
|
+
composed: true,
|
|
470
|
+
cancelable: true,
|
|
471
|
+
}));
|
|
472
|
+
if (!go)
|
|
473
|
+
e.preventDefault();
|
|
474
|
+
};
|
|
475
|
+
this.onMapKeydown = (e) => {
|
|
476
|
+
const t = e.target;
|
|
477
|
+
// Leaflet's zoom buttons are links with role="button": Space presses them too.
|
|
478
|
+
if (e.key === ' ' && t.closest?.('.leaflet-control-zoom a')) {
|
|
479
|
+
e.preventDefault();
|
|
480
|
+
t.closest('a').click();
|
|
481
|
+
return;
|
|
482
|
+
}
|
|
483
|
+
const ctl = t.closest?.('.marker');
|
|
484
|
+
if (!ctl)
|
|
485
|
+
return;
|
|
486
|
+
// Escape in a ring (on its places or its group) closes it; focus goes to the group.
|
|
487
|
+
if (e.key === 'Escape' && this.ring) {
|
|
488
|
+
const key = this.keyOf(ctl);
|
|
489
|
+
const g = this.groups.get(this.ring);
|
|
490
|
+
if (g && (key === `g:${g.key}` || g.members.includes(Number(key)))) {
|
|
491
|
+
e.preventDefault();
|
|
492
|
+
e.stopPropagation();
|
|
493
|
+
this.unring();
|
|
494
|
+
this.regroup();
|
|
495
|
+
return;
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
const order = this.order;
|
|
499
|
+
const at = order.indexOf(ctl);
|
|
500
|
+
let next;
|
|
501
|
+
if (e.key === 'ArrowRight' || e.key === 'ArrowDown')
|
|
502
|
+
next = order[at + 1];
|
|
503
|
+
else if (e.key === 'ArrowLeft' || e.key === 'ArrowUp')
|
|
504
|
+
next = at > 0 ? order[at - 1] : undefined;
|
|
505
|
+
else if (e.key === 'Home')
|
|
506
|
+
next = order[0];
|
|
507
|
+
else if (e.key === 'End')
|
|
508
|
+
next = order[order.length - 1];
|
|
509
|
+
else if (e.key === ' ' && t.localName === 'a') {
|
|
510
|
+
// A link marker is a control here: Space chooses it, like Enter.
|
|
511
|
+
e.preventDefault();
|
|
512
|
+
t.click();
|
|
513
|
+
return;
|
|
514
|
+
}
|
|
515
|
+
else
|
|
516
|
+
return;
|
|
517
|
+
e.preventDefault();
|
|
518
|
+
e.stopPropagation();
|
|
519
|
+
if (next) {
|
|
520
|
+
this.reveal(this.keyOf(next));
|
|
521
|
+
next.focus();
|
|
522
|
+
}
|
|
523
|
+
};
|
|
524
|
+
this.onMapFocusIn = (e) => {
|
|
525
|
+
const key = this.targetOf(e);
|
|
526
|
+
if (!key)
|
|
527
|
+
return;
|
|
528
|
+
this.focusKey = key;
|
|
529
|
+
this.dismissed = false;
|
|
530
|
+
this.reveal(key);
|
|
531
|
+
this.syncActive();
|
|
532
|
+
};
|
|
533
|
+
this.onMapFocusOut = (e) => {
|
|
534
|
+
if (!this.targetOf(e))
|
|
535
|
+
return;
|
|
536
|
+
const to = e.relatedTarget;
|
|
537
|
+
if (to?.closest?.('.marker'))
|
|
538
|
+
return; // the next marker's focusin sets it
|
|
539
|
+
this.focusKey = '';
|
|
540
|
+
this.syncActive();
|
|
541
|
+
};
|
|
542
|
+
this.onMapLeave = () => {
|
|
543
|
+
this.hoverKey = '';
|
|
544
|
+
this.syncActive();
|
|
545
|
+
};
|
|
546
|
+
/** The skip link: focus the list (a fragment link cannot reach into a shadow root). */
|
|
547
|
+
this.skipToList = (e) => {
|
|
548
|
+
e.preventDefault();
|
|
549
|
+
this.renderRoot.querySelector(`#${this.uid}-list`)?.focus();
|
|
550
|
+
};
|
|
551
|
+
new SourceChildren(this, () => this.lightDom, (nodes) => this.readList(nodes));
|
|
552
|
+
this.addEventListener('keydown', (e) => {
|
|
553
|
+
if (e.key === 'Escape' && this.active) {
|
|
554
|
+
this.dismissed = true;
|
|
555
|
+
this.syncActive();
|
|
556
|
+
}
|
|
557
|
+
});
|
|
558
|
+
}
|
|
559
|
+
createRenderRoot() {
|
|
560
|
+
const root = super.createRenderRoot();
|
|
561
|
+
if (root instanceof ShadowRoot && this.noStyle) {
|
|
562
|
+
const sheet = shadowStructure.styleSheet;
|
|
563
|
+
if (sheet)
|
|
564
|
+
root.adoptedStyleSheets = [sheet];
|
|
565
|
+
}
|
|
566
|
+
return root;
|
|
567
|
+
}
|
|
568
|
+
connectedCallback() {
|
|
569
|
+
super.connectedCallback();
|
|
570
|
+
if (this.lightDom && this.noStyle) {
|
|
571
|
+
const node = this.getRootNode();
|
|
572
|
+
installLightDomStyles(`${this.localName}::structure`, unsafeCSS(structuralRules(this.localName)), {
|
|
573
|
+
root: node instanceof ShadowRoot || node instanceof Document ? node : undefined,
|
|
574
|
+
scope: false,
|
|
575
|
+
});
|
|
576
|
+
}
|
|
577
|
+
const doc = this.ownerDocument;
|
|
578
|
+
this.schemeObserver = new MutationObserver(() => this.readScheme());
|
|
579
|
+
this.schemeObserver.observe(doc.documentElement, {
|
|
580
|
+
attributes: true,
|
|
581
|
+
attributeFilter: ['data-uva-color-scheme'],
|
|
582
|
+
});
|
|
583
|
+
this.darkQuery = doc.defaultView?.matchMedia?.('(prefers-color-scheme: dark)');
|
|
584
|
+
this.darkQuery?.addEventListener('change', this.readScheme);
|
|
585
|
+
this.readScheme();
|
|
586
|
+
// leaflet.js loaded with async (or after this script): look again once the page has loaded.
|
|
587
|
+
if (doc.readyState !== 'complete')
|
|
588
|
+
doc.defaultView?.addEventListener('load', this.onPageLoad, { once: true });
|
|
589
|
+
if (this.hasUpdated)
|
|
590
|
+
this.requestUpdate();
|
|
591
|
+
}
|
|
592
|
+
disconnectedCallback() {
|
|
593
|
+
super.disconnectedCallback();
|
|
594
|
+
this.ownerDocument.defaultView?.removeEventListener('load', this.onPageLoad);
|
|
595
|
+
this.schemeObserver?.disconnect();
|
|
596
|
+
this.darkQuery?.removeEventListener('change', this.readScheme);
|
|
597
|
+
this.teardown();
|
|
598
|
+
}
|
|
599
|
+
/** The places shown: `items`, else the child list. */
|
|
600
|
+
get places() {
|
|
601
|
+
return this.items?.length ? this.items : this.sourceItems;
|
|
602
|
+
}
|
|
603
|
+
/** The child list's places, compared with the last read so only a real change re-renders. */
|
|
604
|
+
readList(nodes) {
|
|
605
|
+
const list = nodes.find((n) => n instanceof Element && (n.localName === 'ul' || n.localName === 'ol'));
|
|
606
|
+
const out = [];
|
|
607
|
+
for (const li of list ? [...list.children] : []) {
|
|
608
|
+
if (li.localName !== 'li')
|
|
609
|
+
continue;
|
|
610
|
+
const src = (li.matches('[data-lat]') ? li : li.querySelector('[data-lat]'));
|
|
611
|
+
if (!src)
|
|
612
|
+
continue;
|
|
613
|
+
const a = li.querySelector('a[href]');
|
|
614
|
+
const d = src.dataset;
|
|
615
|
+
const item = {
|
|
616
|
+
name: normalize((a ?? src).textContent),
|
|
617
|
+
lat: Number(d.lat),
|
|
618
|
+
lng: Number(d.lng),
|
|
619
|
+
};
|
|
620
|
+
const id = d.id ?? (li.id || undefined);
|
|
621
|
+
if (id)
|
|
622
|
+
item.id = id;
|
|
623
|
+
if (d.count !== undefined && d.count.trim() !== '' && Number.isFinite(Number(d.count)))
|
|
624
|
+
item.count = Number(d.count);
|
|
625
|
+
const href = a?.getAttribute('href');
|
|
626
|
+
if (href)
|
|
627
|
+
item.href = href;
|
|
628
|
+
const description = d.description ?? li.dataset.description;
|
|
629
|
+
if (description)
|
|
630
|
+
item.description = normalize(description);
|
|
631
|
+
out.push(item);
|
|
632
|
+
}
|
|
633
|
+
const key = JSON.stringify(out);
|
|
634
|
+
if (key === this.sourceKey)
|
|
635
|
+
return;
|
|
636
|
+
this.sourceKey = key;
|
|
637
|
+
this.sourceItems = out;
|
|
638
|
+
}
|
|
639
|
+
/** The page's Leaflet: the `leaflet` property (a module namespace or its default), or `window.L`. */
|
|
640
|
+
findLeaflet() {
|
|
641
|
+
const isL = (x) => !!x &&
|
|
642
|
+
typeof x.map === 'function' &&
|
|
643
|
+
typeof x.divIcon === 'function' &&
|
|
644
|
+
typeof x.tileLayer === 'function';
|
|
645
|
+
const own = this.leaflet;
|
|
646
|
+
const win = this.ownerDocument.defaultView;
|
|
647
|
+
for (const x of [own, own?.default, win?.L])
|
|
648
|
+
if (isL(x))
|
|
649
|
+
return x;
|
|
650
|
+
return undefined;
|
|
651
|
+
}
|
|
652
|
+
willUpdate(changed) {
|
|
653
|
+
const L = this.findLeaflet();
|
|
654
|
+
if (L !== this.L) {
|
|
655
|
+
if (this.map)
|
|
656
|
+
this.teardown();
|
|
657
|
+
this.L = L;
|
|
658
|
+
}
|
|
659
|
+
this.hasLeaflet = !!L;
|
|
660
|
+
if (changed.has('label') && !this.label.trim() && !this.warnedLabel) {
|
|
661
|
+
this.warnedLabel = true;
|
|
662
|
+
console.warn(`<${TAG}>: label is required; it names the map region and the list.`);
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
updated(changed) {
|
|
666
|
+
super.updated(changed);
|
|
667
|
+
if (!this.L) {
|
|
668
|
+
// A page script may set `leaflet` just after this renders: warn only if it is still
|
|
669
|
+
// missing a second after the page has loaded.
|
|
670
|
+
if (!this.warnedLeaflet && this.ownerDocument.readyState === 'complete') {
|
|
671
|
+
this.warnedLeaflet = true;
|
|
672
|
+
setTimeout(() => {
|
|
673
|
+
if (this.isConnected && !this.findLeaflet())
|
|
674
|
+
console.warn(`<${TAG}>: Leaflet was not found (set the leaflet property, or load leaflet.js for window.L); showing the list only.`);
|
|
675
|
+
}, 1000);
|
|
676
|
+
}
|
|
677
|
+
return;
|
|
678
|
+
}
|
|
679
|
+
const created = this.setUpMap();
|
|
680
|
+
const map = this.map;
|
|
681
|
+
if (!map)
|
|
682
|
+
return;
|
|
683
|
+
if (!created &&
|
|
684
|
+
(changed.has('tileUrl') ||
|
|
685
|
+
changed.has('darkTileUrl') ||
|
|
686
|
+
changed.has('attribution') ||
|
|
687
|
+
changed.has('dark')))
|
|
688
|
+
this.drawTiles();
|
|
689
|
+
if (created ||
|
|
690
|
+
this.places !== this.drawn ||
|
|
691
|
+
changed.has('countLabel') ||
|
|
692
|
+
changed.has('placeLabel')) {
|
|
693
|
+
this.drawMarkers();
|
|
694
|
+
if (created || !this.userMoved)
|
|
695
|
+
this.fit();
|
|
696
|
+
this.regroup();
|
|
697
|
+
}
|
|
698
|
+
else if (changed.has('center') || changed.has('zoom')) {
|
|
699
|
+
this.fit();
|
|
700
|
+
}
|
|
701
|
+
if (changed.has('active'))
|
|
702
|
+
this.showActive();
|
|
703
|
+
}
|
|
704
|
+
get container() {
|
|
705
|
+
return this.renderRoot.querySelector(`#${this.uid}-map`);
|
|
706
|
+
}
|
|
707
|
+
/** Create the Leaflet map once its container is rendered. True when it was created now. */
|
|
708
|
+
setUpMap() {
|
|
709
|
+
const L = this.L;
|
|
710
|
+
const el = this.container;
|
|
711
|
+
if (!L || !el || this.map)
|
|
712
|
+
return false;
|
|
713
|
+
const win = this.ownerDocument.defaultView;
|
|
714
|
+
this.reduceMotion = !!win?.matchMedia?.('(prefers-reduced-motion: reduce)').matches;
|
|
715
|
+
const still = !this.reduceMotion;
|
|
716
|
+
const map = L.map(el, {
|
|
717
|
+
zoomControl: false,
|
|
718
|
+
attributionControl: false,
|
|
719
|
+
scrollWheelZoom: false,
|
|
720
|
+
zoomAnimation: still,
|
|
721
|
+
fadeAnimation: still,
|
|
722
|
+
markerZoomAnimation: still,
|
|
723
|
+
inertia: still,
|
|
724
|
+
keyboard: true,
|
|
725
|
+
// Half steps, so the opening view fits the places as closely as it can.
|
|
726
|
+
zoomSnap: 0.5,
|
|
727
|
+
});
|
|
728
|
+
this.map = map;
|
|
729
|
+
L.control.zoom({ position: 'topleft' }).addTo(map);
|
|
730
|
+
L.control
|
|
731
|
+
.attribution({
|
|
732
|
+
position: 'bottomright',
|
|
733
|
+
prefix: '<a href="https://leafletjs.com">Leaflet</a>',
|
|
734
|
+
})
|
|
735
|
+
.addTo(map);
|
|
736
|
+
this.tooltip = L.tooltip({
|
|
737
|
+
direction: 'top',
|
|
738
|
+
opacity: 1,
|
|
739
|
+
className: 'uvalib-map-tooltip',
|
|
740
|
+
});
|
|
741
|
+
map.on('movestart', () => {
|
|
742
|
+
if (!this.fitting)
|
|
743
|
+
this.userMoved = true;
|
|
744
|
+
});
|
|
745
|
+
// Any zoom closes a ring; every zoom regroups.
|
|
746
|
+
map.on('zoomstart', () => {
|
|
747
|
+
if (!this.ring)
|
|
748
|
+
return;
|
|
749
|
+
this.unring();
|
|
750
|
+
this.regroup();
|
|
751
|
+
});
|
|
752
|
+
map.on('zoomend', () => this.regroup());
|
|
753
|
+
this.drawTiles();
|
|
754
|
+
this.ro = new ResizeObserver(() => {
|
|
755
|
+
if (!this.map)
|
|
756
|
+
return;
|
|
757
|
+
this.map.invalidateSize({ animate: false });
|
|
758
|
+
if (!this.userMoved)
|
|
759
|
+
this.fit();
|
|
760
|
+
this.regroup();
|
|
761
|
+
});
|
|
762
|
+
this.ro.observe(el);
|
|
763
|
+
return true;
|
|
764
|
+
}
|
|
765
|
+
teardown() {
|
|
766
|
+
clearTimeout(this.zoomTimer);
|
|
767
|
+
this.ro?.disconnect();
|
|
768
|
+
this.ro = undefined;
|
|
769
|
+
this.map?.remove();
|
|
770
|
+
this.map = undefined;
|
|
771
|
+
this.tiles = undefined;
|
|
772
|
+
this.tooltip = undefined;
|
|
773
|
+
this.markers = [];
|
|
774
|
+
this.groups.clear();
|
|
775
|
+
this.groupOf.clear();
|
|
776
|
+
this.ring = '';
|
|
777
|
+
this.order = [];
|
|
778
|
+
this.activeIcon = undefined;
|
|
779
|
+
this.drawn = [];
|
|
780
|
+
this.userMoved = false;
|
|
781
|
+
}
|
|
782
|
+
/** The tile layer for the current scheme: dark tiles when given, else the filtered light ones. */
|
|
783
|
+
drawTiles() {
|
|
784
|
+
const { L, map } = this;
|
|
785
|
+
if (!L || !map)
|
|
786
|
+
return;
|
|
787
|
+
const url = this.dark && this.darkTileUrl ? this.darkTileUrl : this.tileUrl || OSM_TILE_URL;
|
|
788
|
+
this.tiles?.remove();
|
|
789
|
+
this.tiles = L.tileLayer(url, { attribution: this.attribution, maxZoom: 19 }).addTo(map);
|
|
790
|
+
}
|
|
791
|
+
/** Marker dot diameter: the square root of the count, between MIN_DOT and MAX_DOT. */
|
|
792
|
+
dotSize(count, max) {
|
|
793
|
+
if (!(max > 0) || count === undefined || !(count > 0))
|
|
794
|
+
return MIN_DOT;
|
|
795
|
+
return Math.round(MIN_DOT + (MAX_DOT - MIN_DOT) * Math.sqrt(count / max));
|
|
796
|
+
}
|
|
797
|
+
/** "The Rotunda, 2,702 photos", or the name alone without a count. */
|
|
798
|
+
placeName(p) {
|
|
799
|
+
return p.count === undefined ? p.name : `${p.name}, ${this.countText(p.count)}`;
|
|
800
|
+
}
|
|
801
|
+
countText(n) {
|
|
802
|
+
return `${fmt(n)} ${noun(this.countLabel || 'items', n)}`;
|
|
803
|
+
}
|
|
804
|
+
href(p) {
|
|
805
|
+
return p.href && safeHref(p.href, this.ownerDocument.baseURI) ? p.href : null;
|
|
806
|
+
}
|
|
807
|
+
/** A group's dot: by the square root of its summed count, between MIN_GROUP_DOT and MAX_GROUP_DOT. */
|
|
808
|
+
groupDot(sum) {
|
|
809
|
+
const max = this.maxCount;
|
|
810
|
+
if (!(max > 0) || !(sum > 0))
|
|
811
|
+
return MIN_GROUP_DOT;
|
|
812
|
+
const d = Math.round(MIN_DOT + (MAX_DOT - MIN_DOT) * Math.sqrt(sum / max));
|
|
813
|
+
return Math.min(MAX_GROUP_DOT, Math.max(MIN_GROUP_DOT, d));
|
|
814
|
+
}
|
|
815
|
+
/** "The Rotunda and 2 more places": the largest place's name and how many more. */
|
|
816
|
+
groupName(members) {
|
|
817
|
+
const n = members.length - 1;
|
|
818
|
+
return `${this.places[members[0]].name} and ${fmt(n)} more ${noun(this.placeLabel || 'places', n)}`;
|
|
819
|
+
}
|
|
820
|
+
/** A marker's hit area (px): its dot, at least 44px; a group's dot for several places. */
|
|
821
|
+
hitOf(members) {
|
|
822
|
+
if (members.length === 1)
|
|
823
|
+
return Math.max(HIT, this.dots[members[0]] ?? MIN_DOT);
|
|
824
|
+
return Math.max(HIT, this.groupDot(members.reduce((s, i) => s + countOf(this.places[i]), 0)));
|
|
825
|
+
}
|
|
826
|
+
makeMarker(ll, ctl, d, className) {
|
|
827
|
+
const L = this.L;
|
|
828
|
+
const hit = Math.max(HIT, d);
|
|
829
|
+
return L.marker(ll, {
|
|
830
|
+
icon: L.divIcon({
|
|
831
|
+
className,
|
|
832
|
+
html: ctl,
|
|
833
|
+
iconSize: [hit, hit],
|
|
834
|
+
iconAnchor: [hit / 2, hit / 2],
|
|
835
|
+
}),
|
|
836
|
+
keyboard: false,
|
|
837
|
+
// Smaller dots above larger ones.
|
|
838
|
+
zIndexOffset: (MAX_DOT - d) * 10,
|
|
839
|
+
});
|
|
840
|
+
}
|
|
841
|
+
/** The control inside a marker: its dot (with `text`, for a group) and its hidden name. */
|
|
842
|
+
makeControl(tag, d, label, text = '') {
|
|
843
|
+
const doc = this.ownerDocument;
|
|
844
|
+
const ctl = doc.createElement(tag);
|
|
845
|
+
if (ctl instanceof HTMLButtonElement)
|
|
846
|
+
ctl.type = 'button';
|
|
847
|
+
ctl.className = 'marker';
|
|
848
|
+
ctl.style.setProperty('--d', `${d}px`);
|
|
849
|
+
const dot = doc.createElement('span');
|
|
850
|
+
dot.className = 'dot';
|
|
851
|
+
dot.setAttribute('aria-hidden', 'true');
|
|
852
|
+
dot.textContent = text;
|
|
853
|
+
const name = doc.createElement('span');
|
|
854
|
+
name.className = 'visually-hidden';
|
|
855
|
+
name.textContent = label;
|
|
856
|
+
ctl.append(dot, name);
|
|
857
|
+
return ctl;
|
|
858
|
+
}
|
|
859
|
+
/** One marker per place, not yet on the map: `regroup()` adds the ones not in a group. */
|
|
860
|
+
drawMarkers() {
|
|
861
|
+
const { L, map } = this;
|
|
862
|
+
if (!L || !map)
|
|
863
|
+
return;
|
|
864
|
+
for (const m of this.markers)
|
|
865
|
+
m?.remove();
|
|
866
|
+
for (const g of this.groups.values())
|
|
867
|
+
g.marker.remove();
|
|
868
|
+
this.groups.clear();
|
|
869
|
+
this.groupOf.clear();
|
|
870
|
+
this.ring = '';
|
|
871
|
+
this.order = [];
|
|
872
|
+
this.activeIcon = undefined;
|
|
873
|
+
const places = this.places;
|
|
874
|
+
this.drawn = places;
|
|
875
|
+
this.maxCount = Math.max(0, ...places.map(countOf));
|
|
876
|
+
this.dots = places.map((p) => this.dotSize(p.count, this.maxCount));
|
|
877
|
+
this.markers = places.map((p, i) => {
|
|
878
|
+
if (!validPlace(p))
|
|
879
|
+
return undefined;
|
|
880
|
+
const d = this.dots[i];
|
|
881
|
+
const href = this.href(p);
|
|
882
|
+
const ctl = this.makeControl(href ? 'a' : 'button', d, this.placeName(p));
|
|
883
|
+
if (ctl instanceof HTMLAnchorElement)
|
|
884
|
+
ctl.href = href;
|
|
885
|
+
ctl.dataset.index = String(i);
|
|
886
|
+
const marker = this.makeMarker([p.lat, p.lng], ctl, d, 'uvalib-map-marker');
|
|
887
|
+
marker.on('mouseover', () => this.hover(String(i)));
|
|
888
|
+
return marker;
|
|
889
|
+
});
|
|
890
|
+
this.hoverKey = '';
|
|
891
|
+
this.focusKey = '';
|
|
892
|
+
if (this.active)
|
|
893
|
+
this.active = '';
|
|
894
|
+
}
|
|
895
|
+
/**
|
|
896
|
+
* Greedy screen-space grouping at `zoom`: largest count first, each place takes every
|
|
897
|
+
* later one whose hit area (plus GROUP_GAP) would overlap its own; then groups whose larger
|
|
898
|
+
* markers now overlap merge, until none do. Each group's largest place comes first.
|
|
899
|
+
*/
|
|
900
|
+
cluster(idx, zoom) {
|
|
901
|
+
const map = this.map;
|
|
902
|
+
const places = this.places;
|
|
903
|
+
const byCount = (a, b) => countOf(places[b]) - countOf(places[a]) || a - b;
|
|
904
|
+
const pt = new Map(idx.map((i) => [i, map.project([places[i].lat, places[i].lng], zoom)]));
|
|
905
|
+
const clash = (a, b) => {
|
|
906
|
+
const p = pt.get(a[0]);
|
|
907
|
+
const q = pt.get(b[0]);
|
|
908
|
+
const t = (this.hitOf(a) + this.hitOf(b)) / 2 + GROUP_GAP;
|
|
909
|
+
return Math.abs(p.x - q.x) < t && Math.abs(p.y - q.y) < t;
|
|
910
|
+
};
|
|
911
|
+
const sorted = [...idx].sort(byCount);
|
|
912
|
+
const out = [];
|
|
913
|
+
const taken = new Set();
|
|
914
|
+
for (const i of sorted) {
|
|
915
|
+
if (taken.has(i))
|
|
916
|
+
continue;
|
|
917
|
+
const c = [i];
|
|
918
|
+
taken.add(i);
|
|
919
|
+
for (const j of sorted)
|
|
920
|
+
if (!taken.has(j) && clash([i], [j])) {
|
|
921
|
+
c.push(j);
|
|
922
|
+
taken.add(j);
|
|
923
|
+
}
|
|
924
|
+
out.push(c);
|
|
925
|
+
}
|
|
926
|
+
for (let merged = true; merged;) {
|
|
927
|
+
merged = false;
|
|
928
|
+
for (let a = 0; a < out.length && !merged; a++)
|
|
929
|
+
for (let b = a + 1; b < out.length && !merged; b++)
|
|
930
|
+
if (clash(out[a], out[b])) {
|
|
931
|
+
out[a] = [...out[a], ...out[b]].sort(byCount);
|
|
932
|
+
out.splice(b, 1);
|
|
933
|
+
merged = true;
|
|
934
|
+
}
|
|
935
|
+
}
|
|
936
|
+
return out;
|
|
937
|
+
}
|
|
938
|
+
makeGroup(key, members) {
|
|
939
|
+
const p = this.places;
|
|
940
|
+
const lead = p[members[0]];
|
|
941
|
+
const sum = members.reduce((s, i) => s + countOf(p[i]), 0);
|
|
942
|
+
const counted = members.some((i) => Number.isFinite(p[i].count));
|
|
943
|
+
const d = this.groupDot(sum);
|
|
944
|
+
const name = this.groupName(members);
|
|
945
|
+
const ctl = this.makeControl('button', d, counted ? `${name}, ${this.countText(sum)}` : name, String(members.length));
|
|
946
|
+
ctl.dataset.group = key;
|
|
947
|
+
const marker = this.makeMarker([lead.lat, lead.lng], ctl, d, 'uvalib-map-marker is-group');
|
|
948
|
+
marker.on('mouseover', () => this.hover(`g:${key}`));
|
|
949
|
+
return { key, members, marker, ctl, d, sum, counted };
|
|
950
|
+
}
|
|
951
|
+
/** The marker control that has focus, if any. */
|
|
952
|
+
focusedControl() {
|
|
953
|
+
const r = this.renderRoot;
|
|
954
|
+
const a = r instanceof ShadowRoot ? r.activeElement : this.ownerDocument.activeElement;
|
|
955
|
+
const ctl = a?.closest?.('.marker');
|
|
956
|
+
return ctl && this.container?.contains(ctl) ? ctl : null;
|
|
957
|
+
}
|
|
958
|
+
/**
|
|
959
|
+
* Group the markers whose hit areas would overlap at the current zoom, show one marker
|
|
960
|
+
* per group (and the ring's places, when one is open), keep the markers' document order
|
|
961
|
+
* the keyboard order, and give focus back if its marker went.
|
|
962
|
+
*/
|
|
963
|
+
regroup() {
|
|
964
|
+
const { map } = this;
|
|
965
|
+
if (!map || !map._loaded)
|
|
966
|
+
return;
|
|
967
|
+
const had = this.focusedControl();
|
|
968
|
+
const hadKey = had ? this.keyOf(had) : '';
|
|
969
|
+
const lead = hadKey.startsWith('g:')
|
|
970
|
+
? (this.groups.get(hadKey.slice(2))?.members[0] ?? -1)
|
|
971
|
+
: hadKey
|
|
972
|
+
? Number(hadKey)
|
|
973
|
+
: -1;
|
|
974
|
+
const idx = this.markers.flatMap((m, i) => (m ? [i] : []));
|
|
975
|
+
const groups = new Map();
|
|
976
|
+
this.groupOf.clear();
|
|
977
|
+
for (const c of this.cluster(idx, map.getZoom())) {
|
|
978
|
+
if (c.length < 2)
|
|
979
|
+
continue;
|
|
980
|
+
const key = [...c].sort((a, b) => a - b).join(',');
|
|
981
|
+
groups.set(key, this.groups.get(key) ?? this.makeGroup(key, c));
|
|
982
|
+
for (const i of c)
|
|
983
|
+
this.groupOf.set(i, key);
|
|
984
|
+
}
|
|
985
|
+
for (const [key, g] of this.groups)
|
|
986
|
+
if (!groups.has(key))
|
|
987
|
+
g.marker.remove();
|
|
988
|
+
if (this.ring && !groups.has(this.ring))
|
|
989
|
+
this.unring();
|
|
990
|
+
this.groups = groups;
|
|
991
|
+
// The visible markers, by the first place in each; a ring's places follow its group.
|
|
992
|
+
const spots = [];
|
|
993
|
+
const shown = new Set();
|
|
994
|
+
for (const i of idx)
|
|
995
|
+
if (!this.groupOf.has(i)) {
|
|
996
|
+
shown.add(i);
|
|
997
|
+
spots.push({ first: i, list: [this.spot(i)] });
|
|
998
|
+
}
|
|
999
|
+
for (const g of groups.values()) {
|
|
1000
|
+
const list = [{ marker: g.marker, ctl: g.ctl }];
|
|
1001
|
+
if (this.ring === g.key)
|
|
1002
|
+
for (const i of g.members) {
|
|
1003
|
+
shown.add(i);
|
|
1004
|
+
list.push(this.spot(i));
|
|
1005
|
+
}
|
|
1006
|
+
spots.push({ first: Number(g.key.split(',')[0]), list });
|
|
1007
|
+
}
|
|
1008
|
+
spots.sort((a, b) => a.first - b.first);
|
|
1009
|
+
const added = new Set();
|
|
1010
|
+
for (const i of idx) {
|
|
1011
|
+
const m = this.markers[i];
|
|
1012
|
+
if (shown.has(i) && !map.hasLayer(m)) {
|
|
1013
|
+
m.addTo(map);
|
|
1014
|
+
added.add(m.getElement());
|
|
1015
|
+
}
|
|
1016
|
+
else if (!shown.has(i) && map.hasLayer(m))
|
|
1017
|
+
m.remove();
|
|
1018
|
+
}
|
|
1019
|
+
for (const g of groups.values())
|
|
1020
|
+
if (!map.hasLayer(g.marker)) {
|
|
1021
|
+
g.marker.addTo(map);
|
|
1022
|
+
added.add(g.marker.getElement());
|
|
1023
|
+
}
|
|
1024
|
+
const flat = spots.flatMap((s) => s.list);
|
|
1025
|
+
// Move only the markers just added, so a focused one is never moved.
|
|
1026
|
+
const els = flat.map((s) => s.marker.getElement());
|
|
1027
|
+
for (let k = els.length - 2; k >= 0; k--)
|
|
1028
|
+
if (added.has(els[k]))
|
|
1029
|
+
els[k + 1].before(els[k]);
|
|
1030
|
+
this.order = flat.map((s) => s.ctl);
|
|
1031
|
+
for (const g of groups.values())
|
|
1032
|
+
if (this.ring === g.key)
|
|
1033
|
+
g.ctl.setAttribute('aria-expanded', 'true');
|
|
1034
|
+
else
|
|
1035
|
+
g.ctl.removeAttribute('aria-expanded');
|
|
1036
|
+
if (had && !had.isConnected && lead >= 0) {
|
|
1037
|
+
const to = shown.has(lead)
|
|
1038
|
+
? this.spot(lead).ctl
|
|
1039
|
+
: groups.get(this.groupOf.get(lead) ?? '')?.ctl;
|
|
1040
|
+
to?.focus({ preventScroll: true });
|
|
1041
|
+
}
|
|
1042
|
+
// A group hovered or focused that is gone highlights nothing.
|
|
1043
|
+
const gone = (k) => k.startsWith('g:') && !groups.has(k.slice(2));
|
|
1044
|
+
if (gone(this.hoverKey))
|
|
1045
|
+
this.hoverKey = '';
|
|
1046
|
+
if (gone(this.focusKey))
|
|
1047
|
+
this.focusKey = '';
|
|
1048
|
+
this.syncActive();
|
|
1049
|
+
this.showActive();
|
|
1050
|
+
}
|
|
1051
|
+
spot(i) {
|
|
1052
|
+
const marker = this.markers[i];
|
|
1053
|
+
const html = marker.options.icon.options.html;
|
|
1054
|
+
return { marker, ctl: html };
|
|
1055
|
+
}
|
|
1056
|
+
/** The first zoom (in zoomSnap steps, up to the maximum) at which a group's places part. */
|
|
1057
|
+
splitZoom(members) {
|
|
1058
|
+
const map = this.map;
|
|
1059
|
+
const step = map.options.zoomSnap || 1;
|
|
1060
|
+
const max = map.getMaxZoom();
|
|
1061
|
+
for (let z = map.getZoom() + step; z <= max + 1e-9; z += step)
|
|
1062
|
+
if (this.cluster(members, z).length > 1)
|
|
1063
|
+
return z;
|
|
1064
|
+
return undefined;
|
|
1065
|
+
}
|
|
1066
|
+
/** A group chosen: zoom in until its places part, or (when they cannot) spread them in a ring. */
|
|
1067
|
+
expand(key) {
|
|
1068
|
+
const { L, map } = this;
|
|
1069
|
+
const g = this.groups.get(key);
|
|
1070
|
+
if (!L || !map || !g)
|
|
1071
|
+
return;
|
|
1072
|
+
if (this.ring === key) {
|
|
1073
|
+
this.unring();
|
|
1074
|
+
this.regroup();
|
|
1075
|
+
return;
|
|
1076
|
+
}
|
|
1077
|
+
trackEvent(this, [TAG, 'expand', this.label, g.members.length]);
|
|
1078
|
+
const z = this.splitZoom(g.members);
|
|
1079
|
+
if (z === undefined) {
|
|
1080
|
+
this.spread(g);
|
|
1081
|
+
return;
|
|
1082
|
+
}
|
|
1083
|
+
const bounds = L.latLngBounds(g.members.map((i) => [this.places[i].lat, this.places[i].lng]));
|
|
1084
|
+
map.setView(bounds.getCenter(), z, { animate: !this.reduceMotion });
|
|
1085
|
+
}
|
|
1086
|
+
/**
|
|
1087
|
+
* Spread a group's places in a ring around it, far enough apart that each 44px target
|
|
1088
|
+
* keeps 24px from its neighbours and from the group's own marker; focus the first.
|
|
1089
|
+
*/
|
|
1090
|
+
spread(g) {
|
|
1091
|
+
const map = this.map;
|
|
1092
|
+
if (this.ring)
|
|
1093
|
+
this.unring();
|
|
1094
|
+
const z = map.getZoom();
|
|
1095
|
+
const c = map.project(g.marker.getLatLng(), z);
|
|
1096
|
+
const h = Math.max(...g.members.map((i) => Math.max(HIT, this.dots[i] ?? MIN_DOT)));
|
|
1097
|
+
const n = g.members.length;
|
|
1098
|
+
// Square hit areas: centres √2 × (size + gap) apart are clear in every direction.
|
|
1099
|
+
const r = Math.ceil(Math.max(((h + GAP) * Math.SQRT2) / (2 * Math.sin(Math.PI / n)), ((Math.max(HIT, g.d) + h) / 2 + GAP) * Math.SQRT2));
|
|
1100
|
+
g.members.forEach((i, k) => {
|
|
1101
|
+
const a = -Math.PI / 2 + (2 * Math.PI * k) / n;
|
|
1102
|
+
this.markers[i].setLatLng(map.unproject(c.add([r * Math.cos(a), r * Math.sin(a)]), z));
|
|
1103
|
+
});
|
|
1104
|
+
this.ring = g.key;
|
|
1105
|
+
this.regroup();
|
|
1106
|
+
const size = map.getSize();
|
|
1107
|
+
const pad = r + h / 2 + 8;
|
|
1108
|
+
const at = map.latLngToContainerPoint(g.marker.getLatLng());
|
|
1109
|
+
if (at.x < pad || at.y < pad || at.x > size.x - pad || at.y > size.y - pad)
|
|
1110
|
+
map.panTo(g.marker.getLatLng(), { animate: !this.reduceMotion });
|
|
1111
|
+
this.spot(g.members[0]).ctl.focus();
|
|
1112
|
+
}
|
|
1113
|
+
/** Put a ring's places back on their own point (the next regroup hides them). */
|
|
1114
|
+
unring() {
|
|
1115
|
+
const g = this.groups.get(this.ring);
|
|
1116
|
+
for (const i of g?.members ?? []) {
|
|
1117
|
+
const p = this.places[i];
|
|
1118
|
+
if (p)
|
|
1119
|
+
this.markers[i]?.setLatLng([p.lat, p.lng]);
|
|
1120
|
+
}
|
|
1121
|
+
this.ring = '';
|
|
1122
|
+
}
|
|
1123
|
+
/** Open on `center`/`zoom`, else on the places' bounds, else on Grounds. */
|
|
1124
|
+
fit() {
|
|
1125
|
+
const { L, map } = this;
|
|
1126
|
+
if (!L || !map)
|
|
1127
|
+
return;
|
|
1128
|
+
const pts = this.places.filter(validPlace).map((p) => L.latLng(p.lat, p.lng));
|
|
1129
|
+
const center = parseCenter(this.center);
|
|
1130
|
+
const zoom = Number.isFinite(this.zoom) ? this.zoom : undefined;
|
|
1131
|
+
this.fitting = true;
|
|
1132
|
+
try {
|
|
1133
|
+
if (center)
|
|
1134
|
+
map.setView(center, zoom ?? 16, { animate: false });
|
|
1135
|
+
else if (pts.length === 1)
|
|
1136
|
+
map.setView(pts[0], zoom ?? 16, { animate: false });
|
|
1137
|
+
else if (pts.length && zoom !== undefined)
|
|
1138
|
+
map.setView(L.latLngBounds(pts).getCenter(), zoom, { animate: false });
|
|
1139
|
+
else if (pts.length) {
|
|
1140
|
+
// As close as the largest marker allows; again clear of the zoom buttons (top
|
|
1141
|
+
// left) and the attribution (bottom right) if a marker would sit under them.
|
|
1142
|
+
const bounds = L.latLngBounds(pts);
|
|
1143
|
+
const edge = MAX_DOT / 2 + 4;
|
|
1144
|
+
map.fitBounds(bounds, { padding: [edge, edge], maxZoom: 17, animate: false });
|
|
1145
|
+
if (this.underControls(pts))
|
|
1146
|
+
map.fitBounds(bounds, {
|
|
1147
|
+
paddingTopLeft: [80, 40],
|
|
1148
|
+
paddingBottomRight: [40, 40],
|
|
1149
|
+
maxZoom: 17,
|
|
1150
|
+
animate: false,
|
|
1151
|
+
});
|
|
1152
|
+
}
|
|
1153
|
+
else
|
|
1154
|
+
map.setView(GROUNDS, 15, { animate: false });
|
|
1155
|
+
}
|
|
1156
|
+
finally {
|
|
1157
|
+
this.fitting = false;
|
|
1158
|
+
}
|
|
1159
|
+
}
|
|
1160
|
+
/** Whether any of `pts` is under (or within 12px of) the zoom buttons or the attribution. */
|
|
1161
|
+
underControls(pts) {
|
|
1162
|
+
const map = this.map;
|
|
1163
|
+
const box = map.getContainer().getBoundingClientRect();
|
|
1164
|
+
const rects = [
|
|
1165
|
+
...map.getContainer().querySelectorAll('.leaflet-control-zoom, .leaflet-control-attribution'),
|
|
1166
|
+
].map((c) => c.getBoundingClientRect());
|
|
1167
|
+
return pts.some((ll) => {
|
|
1168
|
+
const p = map.latLngToContainerPoint(ll);
|
|
1169
|
+
const [x, y] = [p.x + box.left, p.y + box.top];
|
|
1170
|
+
return rects.some((r) => r.width > 0 &&
|
|
1171
|
+
x >= r.left - 12 &&
|
|
1172
|
+
x <= r.right + 12 &&
|
|
1173
|
+
y >= r.top - 12 &&
|
|
1174
|
+
y <= r.bottom + 12);
|
|
1175
|
+
});
|
|
1176
|
+
}
|
|
1177
|
+
/** The marker on the map for a target ("3" a place, "g:1,3" a group): a place's own, or its group's. */
|
|
1178
|
+
markerFor(key) {
|
|
1179
|
+
if (key.startsWith('g:')) {
|
|
1180
|
+
const g = this.groups.get(key.slice(2));
|
|
1181
|
+
return g && { marker: g.marker, group: g };
|
|
1182
|
+
}
|
|
1183
|
+
const i = Number(key);
|
|
1184
|
+
const m = this.markers[i];
|
|
1185
|
+
if (!m || !this.map)
|
|
1186
|
+
return undefined;
|
|
1187
|
+
if (this.map.hasLayer(m))
|
|
1188
|
+
return { marker: m };
|
|
1189
|
+
const g = this.groups.get(this.groupOf.get(i) ?? '');
|
|
1190
|
+
return g && { marker: g.marker, group: g };
|
|
1191
|
+
}
|
|
1192
|
+
hover(key) {
|
|
1193
|
+
this.hoverKey = key;
|
|
1194
|
+
this.dismissed = false;
|
|
1195
|
+
this.syncActive();
|
|
1196
|
+
}
|
|
1197
|
+
/** The highlighted target: the one hovered, else the one focused (none after Escape). */
|
|
1198
|
+
syncActive() {
|
|
1199
|
+
this.active = this.dismissed ? '' : this.hoverKey || this.focusKey;
|
|
1200
|
+
}
|
|
1201
|
+
/**
|
|
1202
|
+
* Highlight the active target's marker (a place inside a group highlights the group) and
|
|
1203
|
+
* show its tooltip: the name and count, and for a place in a group, how many share it.
|
|
1204
|
+
*/
|
|
1205
|
+
showActive() {
|
|
1206
|
+
const { map, tooltip } = this;
|
|
1207
|
+
if (!map || !tooltip)
|
|
1208
|
+
return;
|
|
1209
|
+
const prev = this.activeIcon;
|
|
1210
|
+
if (prev) {
|
|
1211
|
+
prev.marker.getElement()?.classList.remove('is-active');
|
|
1212
|
+
prev.marker.setZIndexOffset(prev.z);
|
|
1213
|
+
this.activeIcon = undefined;
|
|
1214
|
+
}
|
|
1215
|
+
const key = this.active;
|
|
1216
|
+
const spot = key ? this.markerFor(key) : undefined;
|
|
1217
|
+
const el = spot?.marker.getElement();
|
|
1218
|
+
if (!spot || !el) {
|
|
1219
|
+
tooltip.remove();
|
|
1220
|
+
return;
|
|
1221
|
+
}
|
|
1222
|
+
const g = spot.group;
|
|
1223
|
+
const own = spot.marker === this.markers[Number(key)];
|
|
1224
|
+
const d = own ? (this.dots[Number(key)] ?? MIN_DOT) : (g?.d ?? MIN_DOT);
|
|
1225
|
+
el.classList.add('is-active');
|
|
1226
|
+
this.activeIcon = { marker: spot.marker, z: (MAX_DOT - d) * 10 };
|
|
1227
|
+
spot.marker.setZIndexOffset(10000);
|
|
1228
|
+
const doc = this.ownerDocument;
|
|
1229
|
+
const content = doc.createElement('span');
|
|
1230
|
+
const name = doc.createElement('span');
|
|
1231
|
+
name.className = 'tip-name';
|
|
1232
|
+
content.append(name);
|
|
1233
|
+
if (key.startsWith('g:') && g) {
|
|
1234
|
+
name.textContent = this.groupName(g.members);
|
|
1235
|
+
if (g.counted)
|
|
1236
|
+
content.append(this.countText(g.sum));
|
|
1237
|
+
}
|
|
1238
|
+
else {
|
|
1239
|
+
const p = this.places[Number(key)];
|
|
1240
|
+
name.textContent = p.name;
|
|
1241
|
+
if (p.count !== undefined)
|
|
1242
|
+
content.append(this.countText(p.count));
|
|
1243
|
+
if (g) {
|
|
1244
|
+
const note = doc.createElement('span');
|
|
1245
|
+
note.className = 'tip-note';
|
|
1246
|
+
note.textContent = `One of ${fmt(g.members.length)} ${this.placeLabel || 'places'} here`;
|
|
1247
|
+
content.append(note);
|
|
1248
|
+
}
|
|
1249
|
+
}
|
|
1250
|
+
const size = Math.max(HIT, d);
|
|
1251
|
+
tooltip.options.offset = [0, -Math.round(size * 0.6)];
|
|
1252
|
+
tooltip.setLatLng(spot.marker.getLatLng()).setContent(content);
|
|
1253
|
+
if (!map.hasLayer(tooltip))
|
|
1254
|
+
tooltip.addTo(map);
|
|
1255
|
+
else
|
|
1256
|
+
tooltip.update();
|
|
1257
|
+
}
|
|
1258
|
+
/** Bring a target's marker into view (on focus), without animation under reduced motion. */
|
|
1259
|
+
reveal(key) {
|
|
1260
|
+
const { map } = this;
|
|
1261
|
+
const spot = this.markerFor(key);
|
|
1262
|
+
if (!map || !spot)
|
|
1263
|
+
return;
|
|
1264
|
+
const ll = spot.marker.getLatLng();
|
|
1265
|
+
if (!map.getBounds().pad(-0.15).contains(ll))
|
|
1266
|
+
map.panTo(ll, { animate: !this.reduceMotion });
|
|
1267
|
+
}
|
|
1268
|
+
/** "3" for a place's marker, "g:1,3" for a group's. */
|
|
1269
|
+
keyOf(ctl) {
|
|
1270
|
+
return ctl.dataset.group !== undefined ? `g:${ctl.dataset.group}` : (ctl.dataset.index ?? '');
|
|
1271
|
+
}
|
|
1272
|
+
targetOf(e) {
|
|
1273
|
+
const ctl = e.target?.closest?.('.marker');
|
|
1274
|
+
return ctl ? this.keyOf(ctl) : '';
|
|
1275
|
+
}
|
|
1276
|
+
/** Report the zoom level 1 s after the last zoom-button press. */
|
|
1277
|
+
queueZoomReport() {
|
|
1278
|
+
clearTimeout(this.zoomTimer);
|
|
1279
|
+
this.zoomTimer = setTimeout(() => {
|
|
1280
|
+
if (this.map)
|
|
1281
|
+
trackEvent(this, [TAG, 'zoom', this.label, this.map.getZoom()]);
|
|
1282
|
+
}, 1000);
|
|
1283
|
+
}
|
|
1284
|
+
onPlaceEnter(i) {
|
|
1285
|
+
this.hover(String(i));
|
|
1286
|
+
}
|
|
1287
|
+
onPlaceLeave() {
|
|
1288
|
+
this.hoverKey = '';
|
|
1289
|
+
this.syncActive();
|
|
1290
|
+
}
|
|
1291
|
+
onPlaceFocusIn(i) {
|
|
1292
|
+
this.focusKey = String(i);
|
|
1293
|
+
this.dismissed = false;
|
|
1294
|
+
this.reveal(String(i));
|
|
1295
|
+
this.syncActive();
|
|
1296
|
+
}
|
|
1297
|
+
onPlaceFocusOut(e) {
|
|
1298
|
+
const to = e.relatedTarget;
|
|
1299
|
+
if (to?.closest?.('.place'))
|
|
1300
|
+
return;
|
|
1301
|
+
this.focusKey = '';
|
|
1302
|
+
this.syncActive();
|
|
1303
|
+
}
|
|
1304
|
+
render() {
|
|
1305
|
+
const places = this.places;
|
|
1306
|
+
const label = this.label.trim() || 'Places';
|
|
1307
|
+
// A list entry is highlighted with its place, or with its group.
|
|
1308
|
+
const a = this.active;
|
|
1309
|
+
const lit = new Set(a.startsWith('g:') ? a.slice(2).split(',').map(Number) : a ? [Number(a)] : []);
|
|
1310
|
+
const listId = `${this.uid}-list`;
|
|
1311
|
+
const map = this.hasLeaflet
|
|
1312
|
+
? html `<a class="skip-link" href="#${listId}" @click=${this.skipToList}
|
|
1313
|
+
>Skip map, go to the list</a
|
|
1314
|
+
>
|
|
1315
|
+
<p class="instructions" part="instructions">${MAP_INSTRUCTIONS}</p>
|
|
1316
|
+
<div class=${this.dark && !this.darkTileUrl ? 'frame dark-tiles' : 'frame'}>
|
|
1317
|
+
<div
|
|
1318
|
+
id="${this.uid}-map"
|
|
1319
|
+
class="map"
|
|
1320
|
+
part="map"
|
|
1321
|
+
role="region"
|
|
1322
|
+
aria-label=${`${label}, map`}
|
|
1323
|
+
@click=${{ handleEvent: this.onMapClick, capture: true }}
|
|
1324
|
+
@keydown=${this.onMapKeydown}
|
|
1325
|
+
@focusin=${this.onMapFocusIn}
|
|
1326
|
+
@focusout=${this.onMapFocusOut}
|
|
1327
|
+
@mouseleave=${this.onMapLeave}
|
|
1328
|
+
></div>
|
|
1329
|
+
</div>`
|
|
1330
|
+
: nothing;
|
|
1331
|
+
return html `${map}
|
|
1332
|
+
<ul class="places" part="list" id=${listId} tabindex="-1" aria-label=${`${label}, list`}>
|
|
1333
|
+
${places.map((p, i) => {
|
|
1334
|
+
const href = this.href(p);
|
|
1335
|
+
return html `<li
|
|
1336
|
+
class=${lit.has(i) ? 'place is-active' : 'place'}
|
|
1337
|
+
part="place"
|
|
1338
|
+
@mouseenter=${() => this.onPlaceEnter(i)}
|
|
1339
|
+
@mouseleave=${() => this.onPlaceLeave()}
|
|
1340
|
+
@focusin=${() => this.onPlaceFocusIn(i)}
|
|
1341
|
+
@focusout=${(e) => this.onPlaceFocusOut(e)}
|
|
1342
|
+
>
|
|
1343
|
+
${href ? html `<a href=${href}>${p.name}</a>` : html `<span class="name">${p.name}</span>`}
|
|
1344
|
+
${p.count !== undefined && Number.isFinite(p.count)
|
|
1345
|
+
? html `<span class="count">${this.countText(p.count)}</span>`
|
|
1346
|
+
: nothing}
|
|
1347
|
+
${p.description ? html `<span class="description">${p.description}</span>` : nothing}
|
|
1348
|
+
</li>`;
|
|
1349
|
+
})}
|
|
1350
|
+
</ul>`;
|
|
1351
|
+
}
|
|
1352
|
+
}
|
|
1353
|
+
__decorate([
|
|
1354
|
+
property({ type: Array })
|
|
1355
|
+
], UvalibMap.prototype, "items", void 0);
|
|
1356
|
+
__decorate([
|
|
1357
|
+
property({ type: String })
|
|
1358
|
+
], UvalibMap.prototype, "label", void 0);
|
|
1359
|
+
__decorate([
|
|
1360
|
+
property({ type: String, attribute: 'count-label' })
|
|
1361
|
+
], UvalibMap.prototype, "countLabel", void 0);
|
|
1362
|
+
__decorate([
|
|
1363
|
+
property({ type: String, attribute: 'place-label' })
|
|
1364
|
+
], UvalibMap.prototype, "placeLabel", void 0);
|
|
1365
|
+
__decorate([
|
|
1366
|
+
property({ type: String, attribute: 'tile-url' })
|
|
1367
|
+
], UvalibMap.prototype, "tileUrl", void 0);
|
|
1368
|
+
__decorate([
|
|
1369
|
+
property({ type: String, attribute: 'dark-tile-url' })
|
|
1370
|
+
], UvalibMap.prototype, "darkTileUrl", void 0);
|
|
1371
|
+
__decorate([
|
|
1372
|
+
property({ type: String })
|
|
1373
|
+
], UvalibMap.prototype, "attribution", void 0);
|
|
1374
|
+
__decorate([
|
|
1375
|
+
property({ type: String })
|
|
1376
|
+
], UvalibMap.prototype, "center", void 0);
|
|
1377
|
+
__decorate([
|
|
1378
|
+
property({ type: Number })
|
|
1379
|
+
], UvalibMap.prototype, "zoom", void 0);
|
|
1380
|
+
__decorate([
|
|
1381
|
+
property({ attribute: false })
|
|
1382
|
+
], UvalibMap.prototype, "leaflet", void 0);
|
|
1383
|
+
__decorate([
|
|
1384
|
+
state()
|
|
1385
|
+
], UvalibMap.prototype, "sourceItems", void 0);
|
|
1386
|
+
__decorate([
|
|
1387
|
+
state()
|
|
1388
|
+
], UvalibMap.prototype, "hasLeaflet", void 0);
|
|
1389
|
+
__decorate([
|
|
1390
|
+
state()
|
|
1391
|
+
], UvalibMap.prototype, "active", void 0);
|
|
1392
|
+
__decorate([
|
|
1393
|
+
state()
|
|
1394
|
+
], UvalibMap.prototype, "dark", void 0);
|
|
1395
|
+
//# sourceMappingURL=UvalibMap.js.map
|