@uvalib/web-components 1.2.0 → 1.3.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 +87 -0
- package/README.md +808 -46
- 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 +130 -0
- package/dist/components/uvalib-image-regions/UvalibImageRegions.js +658 -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 +40 -0
- package/dist/components/uvalib-lightbox/UvalibLightbox.js +144 -16
- package/dist/components/uvalib-lightbox/UvalibLightbox.js.map +1 -1
- package/dist/components/uvalib-map/UvalibMap.d.ts +182 -0
- package/dist/components/uvalib-map/UvalibMap.js +1001 -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 +9253 -3253
- 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 +9253 -3253
- 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 +300 -13
- 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 +447 -0
- package/dist-cdn/uvalib-image-regions.js.map +1 -0
- package/dist-cdn/uvalib-lightbox.js +144 -55
- package/dist-cdn/uvalib-lightbox.js.map +1 -1
- package/dist-cdn/uvalib-map.js +471 -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 +300 -13
- 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,1001 @@
|
|
|
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
|
+
/** The analytics category. */
|
|
15
|
+
const TAG = 'uvalib-map';
|
|
16
|
+
/** OpenStreetMap's standard tiles: fine for low traffic only (see the README). */
|
|
17
|
+
export const OSM_TILE_URL = 'https://tile.openstreetmap.org/{z}/{x}/{y}.png';
|
|
18
|
+
export const OSM_ATTRIBUTION = '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors';
|
|
19
|
+
/** Where the map opens with no places and no `center`: the Lawn. */
|
|
20
|
+
const GROUNDS = [38.0336, -78.5048];
|
|
21
|
+
/** Marker dot diameters (px): the smallest and largest count. Every target is at least 44px. */
|
|
22
|
+
const MIN_DOT = 24;
|
|
23
|
+
const MAX_DOT = 56;
|
|
24
|
+
const HIT = 44;
|
|
25
|
+
const MAP_HEIGHT = 'var(--uvalib-map-height, min(24rem, 75vw))';
|
|
26
|
+
/** Shown above the map, and kept in step with base.css's pre-upgrade placeholder. */
|
|
27
|
+
export const MAP_INSTRUCTIONS = 'Tab or arrow keys move between places; Enter opens one. With the map focused, arrow keys pan and + and − zoom.';
|
|
28
|
+
let instanceCounter = 0;
|
|
29
|
+
const fmt = (n) => n.toLocaleString('en-US');
|
|
30
|
+
/** "photos" for most counts, "photo" for one. */
|
|
31
|
+
const noun = (unit, n) => (n === 1 && /s$/.test(unit) ? unit.slice(0, -1) : unit);
|
|
32
|
+
const validPlace = (p) => Number.isFinite(p.lat) &&
|
|
33
|
+
Number.isFinite(p.lng) &&
|
|
34
|
+
Math.abs(p.lat) <= 90 &&
|
|
35
|
+
Math.abs(p.lng) <= 180;
|
|
36
|
+
/** Parse `"lat, lng"`; null unless both are numbers in range. */
|
|
37
|
+
function parseCenter(s) {
|
|
38
|
+
const m = /^\s*(-?\d+(?:\.\d+)?)\s*,\s*(-?\d+(?:\.\d+)?)\s*$/.exec(s);
|
|
39
|
+
if (!m)
|
|
40
|
+
return null;
|
|
41
|
+
const [lat, lng] = [Number(m[1]), Number(m[2])];
|
|
42
|
+
return Math.abs(lat) <= 90 && Math.abs(lng) <= 180 ? [lat, lng] : null;
|
|
43
|
+
}
|
|
44
|
+
/** Whether the page shows the opt-in dark mode (`data-uva-color-scheme` on the root element). */
|
|
45
|
+
function pageIsDark(doc) {
|
|
46
|
+
const attr = doc.documentElement.getAttribute('data-uva-color-scheme');
|
|
47
|
+
if (attr === null)
|
|
48
|
+
return false;
|
|
49
|
+
try {
|
|
50
|
+
if (!doc.defaultView?.CSS?.supports?.('color', 'light-dark(#000, #fff)'))
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
catch {
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
if (attr === 'dark')
|
|
57
|
+
return true;
|
|
58
|
+
if (attr === 'light')
|
|
59
|
+
return false;
|
|
60
|
+
return !!doc.defaultView?.matchMedia?.('(prefers-color-scheme: dark)').matches;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Leaflet's own layout rules that the map needs (panes, tiles, controls, the tooltip), so
|
|
64
|
+
* Leaflet's leaflet.css is optional and the map works inside the shadow root. Kept with
|
|
65
|
+
* `no-style`, with the map's height, the 44px marker and zoom targets, the hidden marker
|
|
66
|
+
* names and skip link, and forced-colors borders. `host` is `:host` or the tag. Sizes that
|
|
67
|
+
* leaflet.css also sets are `!important`, so a page that loads it (light DOM) keeps them.
|
|
68
|
+
*/
|
|
69
|
+
const structuralRules = (host) => `
|
|
70
|
+
${host} { display: block; position: relative; max-width: 100%; min-width: 0; box-sizing: border-box; }
|
|
71
|
+
${host}[hidden], ${host} [hidden] { display: none !important; }
|
|
72
|
+
${host} .visually-hidden {
|
|
73
|
+
position: absolute !important; width: 1px !important; height: 1px !important; margin: -1px; padding: 0;
|
|
74
|
+
overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
|
|
75
|
+
}
|
|
76
|
+
${host} .skip-link { position: absolute; inset-inline-start: 0; inset-block-start: 0; z-index: 1100; transform: translateY(-120%); }
|
|
77
|
+
${host} .skip-link:focus-visible { transform: translateY(0); }
|
|
78
|
+
${host} .map { position: relative; block-size: ${MAP_HEIGHT}; min-block-size: 12rem; box-sizing: border-box; }
|
|
79
|
+
${host} .leaflet-pane, ${host} .leaflet-tile, ${host} .leaflet-marker-icon, ${host} .leaflet-marker-shadow,
|
|
80
|
+
${host} .leaflet-tile-container, ${host} .leaflet-pane > svg, ${host} .leaflet-pane > canvas,
|
|
81
|
+
${host} .leaflet-zoom-box, ${host} .leaflet-image-layer, ${host} .leaflet-layer {
|
|
82
|
+
position: absolute; left: 0; top: 0;
|
|
83
|
+
}
|
|
84
|
+
${host} .leaflet-container { overflow: hidden; -webkit-tap-highlight-color: transparent; }
|
|
85
|
+
${host} .leaflet-tile, ${host} .leaflet-marker-icon { user-select: none; -webkit-user-drag: none; }
|
|
86
|
+
${host} .leaflet-marker-icon { display: block; }
|
|
87
|
+
${host} .leaflet-container .leaflet-tile-pane img, ${host} .leaflet-container .leaflet-tile {
|
|
88
|
+
max-width: none !important; max-height: none !important; width: auto; padding: 0;
|
|
89
|
+
}
|
|
90
|
+
${host} .leaflet-container.leaflet-touch-zoom { touch-action: pan-x pan-y; }
|
|
91
|
+
${host} .leaflet-container.leaflet-touch-drag { touch-action: pinch-zoom; }
|
|
92
|
+
${host} .leaflet-container.leaflet-touch-drag.leaflet-touch-zoom { touch-action: none; }
|
|
93
|
+
${host} .leaflet-tile { filter: inherit; visibility: hidden; }
|
|
94
|
+
${host} .leaflet-tile-loaded { visibility: inherit; }
|
|
95
|
+
${host} .leaflet-zoom-box { width: 0; height: 0; box-sizing: border-box; z-index: 800; }
|
|
96
|
+
${host} .leaflet-pane { z-index: 400; }
|
|
97
|
+
${host} .leaflet-tile-pane { z-index: 200; }
|
|
98
|
+
${host} .leaflet-overlay-pane { z-index: 400; }
|
|
99
|
+
${host} .leaflet-shadow-pane { z-index: 500; }
|
|
100
|
+
${host} .leaflet-marker-pane { z-index: 600; }
|
|
101
|
+
${host} .leaflet-tooltip-pane { z-index: 650; }
|
|
102
|
+
${host} .leaflet-popup-pane { z-index: 700; }
|
|
103
|
+
${host} .leaflet-control { position: relative; z-index: 800; pointer-events: auto; float: left; clear: both; }
|
|
104
|
+
${host} .leaflet-top, ${host} .leaflet-bottom { position: absolute; z-index: 1000; pointer-events: none; }
|
|
105
|
+
${host} .leaflet-top { top: 0; }
|
|
106
|
+
${host} .leaflet-right { right: 0; }
|
|
107
|
+
${host} .leaflet-bottom { bottom: 0; }
|
|
108
|
+
${host} .leaflet-left { left: 0; }
|
|
109
|
+
${host} .leaflet-right .leaflet-control { float: right; }
|
|
110
|
+
${host} .leaflet-top .leaflet-control { margin-top: 10px; }
|
|
111
|
+
${host} .leaflet-bottom .leaflet-control { margin-bottom: 10px; }
|
|
112
|
+
${host} .leaflet-left .leaflet-control { margin-left: 10px; }
|
|
113
|
+
${host} .leaflet-right .leaflet-control { margin-right: 10px; }
|
|
114
|
+
${host} .leaflet-control-attribution { margin: 0 !important; }
|
|
115
|
+
${host} .leaflet-zoom-animated { transform-origin: 0 0; }
|
|
116
|
+
${host} .leaflet-zoom-anim .leaflet-zoom-animated { transition: transform 0.25s cubic-bezier(0, 0, 0.25, 1); }
|
|
117
|
+
${host} .leaflet-zoom-anim .leaflet-tile, ${host} .leaflet-pan-anim .leaflet-tile { transition: none; }
|
|
118
|
+
${host} .leaflet-zoom-anim .leaflet-zoom-hide { visibility: hidden; }
|
|
119
|
+
${host} .leaflet-interactive { cursor: pointer; }
|
|
120
|
+
${host} .leaflet-grab { cursor: grab; }
|
|
121
|
+
${host} .leaflet-dragging .leaflet-grab, ${host} .leaflet-dragging .leaflet-grab .leaflet-interactive { cursor: grabbing; }
|
|
122
|
+
${host} .leaflet-marker-icon, ${host} .leaflet-tile-container { pointer-events: none; }
|
|
123
|
+
${host} .leaflet-marker-icon.leaflet-interactive { pointer-events: auto; }
|
|
124
|
+
${host} .leaflet-tooltip { position: absolute; pointer-events: none; white-space: nowrap; user-select: none; }
|
|
125
|
+
${host} .uvalib-map-marker .marker {
|
|
126
|
+
box-sizing: border-box; display: flex; align-items: center; justify-content: center;
|
|
127
|
+
inline-size: 100%; block-size: 100%; margin: 0; padding: 0; border: 0; background: none;
|
|
128
|
+
cursor: pointer; font: inherit; color: inherit;
|
|
129
|
+
}
|
|
130
|
+
${host} .uvalib-map-marker .dot { box-sizing: border-box; display: block; flex: none; inline-size: var(--d); block-size: var(--d); border-radius: 50%; }
|
|
131
|
+
${host} .leaflet-bar a {
|
|
132
|
+
box-sizing: border-box; display: flex !important; align-items: center; justify-content: center;
|
|
133
|
+
inline-size: 44px !important; block-size: 44px !important; line-height: 1 !important;
|
|
134
|
+
}
|
|
135
|
+
@media (prefers-reduced-motion: reduce) {
|
|
136
|
+
${host} .leaflet-zoom-anim .leaflet-zoom-animated { transition: none; }
|
|
137
|
+
}
|
|
138
|
+
@media (forced-colors: active) {
|
|
139
|
+
${host} .uvalib-map-marker .dot {
|
|
140
|
+
forced-color-adjust: none; background: Canvas !important; border: 3px solid CanvasText !important; box-shadow: none !important;
|
|
141
|
+
}
|
|
142
|
+
${host} .uvalib-map-marker.is-active .dot { outline: 3px solid Highlight; outline-offset: 3px; }
|
|
143
|
+
${host} .uvalib-map-marker .marker:focus-visible .dot { outline: 3px solid Highlight; outline-offset: 6px; }
|
|
144
|
+
${host} .map, ${host} .map .leaflet-bar, ${host} .map .leaflet-bar a, ${host} .map .leaflet-tooltip,
|
|
145
|
+
${host} .map .leaflet-control-attribution, ${host} .place {
|
|
146
|
+
border: 1px solid CanvasText !important;
|
|
147
|
+
}
|
|
148
|
+
${host} .place.is-active { outline: 3px solid Highlight; outline-offset: 1px; }
|
|
149
|
+
${host} :is(.map, .leaflet-bar a, a, .skip-link):focus-visible { outline: 3px solid Highlight; outline-offset: 2px; }
|
|
150
|
+
}
|
|
151
|
+
`;
|
|
152
|
+
const shadowStructure = unsafeCSS(structuralRules(':host'));
|
|
153
|
+
/**
|
|
154
|
+
* A map of places with a linked list of the same places: buildings, rooms or outdoor spaces,
|
|
155
|
+
* each a marker sized by a count, with a link to the place's page. It wraps
|
|
156
|
+
* [Leaflet](https://leafletjs.com) 1.9, which the page provides (the library never bundles
|
|
157
|
+
* it): set the `leaflet` property to the Leaflet module (`import * as L from 'leaflet'`), or
|
|
158
|
+
* load leaflet.js so that `window.L` exists. Without Leaflet only the list is shown, with
|
|
159
|
+
* one console warning. Leaflet's leaflet.css is optional: the element carries the layout
|
|
160
|
+
* rules it needs, in shadow DOM and light DOM alike.
|
|
161
|
+
*
|
|
162
|
+
* Places come from `items` (`{ id?, name, lat, lng, count?, href?, description? }`) or from
|
|
163
|
+
* a child `<ul>`/`<ol>` of `<li><a href data-lat data-lng data-count>Name</a></li>`, which is
|
|
164
|
+
* the list before the script runs (and without it). The list always stays, under the map:
|
|
165
|
+
* it is the text equivalent.
|
|
166
|
+
*
|
|
167
|
+
* Each marker is a real link (a button when the place has no `href`) named like "The
|
|
168
|
+
* Rotunda, 2,702 photos" (`count-label` is the noun), sized by the square root of its count
|
|
169
|
+
* (a 24 to 56px dot in a hit area of at least 44px). Tab or the arrow keys move between
|
|
170
|
+
* markers, Enter follows the link (or chooses the place), and Escape hides the tooltip.
|
|
171
|
+
* Hovering or focusing a marker shows a tooltip with its name and count and highlights its
|
|
172
|
+
* list entry; hovering or focusing a list entry highlights its marker (a ring and a larger
|
|
173
|
+
* dot, not colour alone) and brings it into view.
|
|
174
|
+
*
|
|
175
|
+
* The map is a region named by `label`, after a "Skip map, go to the list" link and a line
|
|
176
|
+
* of key instructions. It opens on the bounds of the places, or on `center` and `zoom`. The
|
|
177
|
+
* zoom buttons are 44px with a visible focus ring; the attribution stays. Tiles come from
|
|
178
|
+
* `tile-url` (OpenStreetMap by default: low-traffic use only) with `attribution`. In the
|
|
179
|
+
* page's dark mode the tiles are inverted with a CSS filter (`--uvalib-map-dark-filter`)
|
|
180
|
+
* unless `dark-tile-url` gives dark tiles; markers and controls are never filtered. With
|
|
181
|
+
* `prefers-reduced-motion` nothing animates.
|
|
182
|
+
*
|
|
183
|
+
* @tagname uvalib-map
|
|
184
|
+
* @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.
|
|
185
|
+
* @fires select - A marker was chosen (click, Enter or Space). `detail` is `{ item }`. Cancelable: for a place with `href`, `preventDefault()` keeps the page from following the link. Bubbles and is composed.
|
|
186
|
+
* @fires uvalib-analytics-event - For `<site-analytics>`: `['uvalib-map', 'select', '<label>', <position from 1>]` when a marker is chosen, 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.
|
|
187
|
+
* @csspart map - The map region (the Leaflet container).
|
|
188
|
+
* @csspart instructions - The line of key instructions above the map.
|
|
189
|
+
* @csspart list - The list of places.
|
|
190
|
+
* @csspart place - Each list entry.
|
|
191
|
+
* @cssprop [--uvalib-map-height=min(24rem, 75vw)] - Height of the map.
|
|
192
|
+
* @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`.
|
|
193
|
+
* @cssprop [--uva-brand-blue=#232d4b] - Marker fill.
|
|
194
|
+
* @cssprop [--uva-brand-orange=#e57200] - Focus ring when `--uva-color-focus` is unset.
|
|
195
|
+
* @cssprop [--uva-font-family=inherit] - Font family.
|
|
196
|
+
* @cssprop --uva-color-accent-bg - Dark-mode role token: marker fill (else `--uva-brand-blue`).
|
|
197
|
+
* @cssprop --uva-color-on-accent - Dark-mode role token: marker border (else #fff).
|
|
198
|
+
* @cssprop --uva-color-text - Dark-mode role token: text and the highlight ring (else #2b2b2b).
|
|
199
|
+
* @cssprop --uva-color-text-muted - Dark-mode role token: instructions and descriptions (else #4b5563).
|
|
200
|
+
* @cssprop --uva-color-link - Dark-mode role token: links (else `--uva-brand-blue`).
|
|
201
|
+
* @cssprop --uva-color-surface - Dark-mode role token: attribution background and the highlight ring's gap (else #fff).
|
|
202
|
+
* @cssprop --uva-color-surface-raised - Dark-mode role token: zoom buttons, tooltip and list entries (else #fff).
|
|
203
|
+
* @cssprop --uva-color-surface-hover - Dark-mode role token: hovered zoom button (else #dadada).
|
|
204
|
+
* @cssprop --uva-color-track - Dark-mode role token: the map before tiles load, and count badges (else #e5e7eb).
|
|
205
|
+
* @cssprop --uva-color-control-border - Dark-mode role token: borders (else #808080).
|
|
206
|
+
* @cssprop --uva-color-focus - Dark-mode role token: focus ring (else `--uva-brand-orange`).
|
|
207
|
+
* @cssprop --uva-color-shadow - Dark-mode role token: control and tooltip shadow.
|
|
208
|
+
*/
|
|
209
|
+
export class UvalibMap extends UvalibElement {
|
|
210
|
+
static { this.styles = [
|
|
211
|
+
accessible,
|
|
212
|
+
shadowStructure,
|
|
213
|
+
unsafeCSS(`
|
|
214
|
+
:host { font-family: var(--uva-font-family, inherit); color: var(--uva-color-text, #2b2b2b); }
|
|
215
|
+
.instructions {
|
|
216
|
+
margin: 0 0 0.5rem;
|
|
217
|
+
font-size: 0.875rem;
|
|
218
|
+
line-height: 1.5;
|
|
219
|
+
color: var(--uva-color-text-muted, #4b5563);
|
|
220
|
+
}
|
|
221
|
+
.map {
|
|
222
|
+
border: 1px solid var(--uva-color-control-border, #808080);
|
|
223
|
+
border-radius: 4px;
|
|
224
|
+
background: var(--uva-color-track, #e5e7eb) !important;
|
|
225
|
+
font-family: inherit !important;
|
|
226
|
+
font-size: 1rem !important;
|
|
227
|
+
line-height: 1.5 !important;
|
|
228
|
+
}
|
|
229
|
+
.map:focus-visible {
|
|
230
|
+
outline: 3px solid var(--uva-color-focus, var(--uva-brand-orange, #e57200));
|
|
231
|
+
outline-offset: 2px;
|
|
232
|
+
}
|
|
233
|
+
.dark-tiles .leaflet-tile-pane {
|
|
234
|
+
filter: var(--uvalib-map-dark-filter, invert(1) hue-rotate(180deg) brightness(0.95) contrast(0.9));
|
|
235
|
+
}
|
|
236
|
+
.uvalib-map-marker .dot {
|
|
237
|
+
background: var(--uva-color-accent-bg, var(--uva-brand-blue, #232d4b));
|
|
238
|
+
border: 2px solid var(--uva-color-on-accent, #fff);
|
|
239
|
+
box-shadow: 0 0 0 1px var(--uva-color-accent-bg, var(--uva-brand-blue, #232d4b));
|
|
240
|
+
transition: transform 0.15s ease, box-shadow 0.15s ease;
|
|
241
|
+
}
|
|
242
|
+
.uvalib-map-marker.is-active .dot {
|
|
243
|
+
transform: scale(1.25);
|
|
244
|
+
box-shadow:
|
|
245
|
+
0 0 0 3px var(--uva-color-surface, #fff),
|
|
246
|
+
0 0 0 6px var(--uva-color-text, #2b2b2b);
|
|
247
|
+
}
|
|
248
|
+
.uvalib-map-marker .marker:focus-visible { outline: none; }
|
|
249
|
+
.uvalib-map-marker .marker:focus-visible .dot {
|
|
250
|
+
outline: 3px solid var(--uva-color-focus, var(--uva-brand-orange, #e57200));
|
|
251
|
+
outline-offset: 6px;
|
|
252
|
+
}
|
|
253
|
+
.leaflet-bar {
|
|
254
|
+
border: 1px solid var(--uva-color-control-border, #808080) !important;
|
|
255
|
+
border-radius: 4px !important;
|
|
256
|
+
background: var(--uva-color-surface-raised, #fff) !important;
|
|
257
|
+
box-shadow: 0 1px 4px var(--uva-color-shadow, rgba(0, 0, 0, 0.2)) !important;
|
|
258
|
+
}
|
|
259
|
+
.leaflet-bar a {
|
|
260
|
+
border: 0 !important;
|
|
261
|
+
border-radius: 0 !important;
|
|
262
|
+
background: var(--uva-color-surface-raised, #fff) !important;
|
|
263
|
+
color: var(--uva-color-text, #2b2b2b) !important;
|
|
264
|
+
font: 600 1.5rem/1 var(--uva-font-family, system-ui, sans-serif) !important;
|
|
265
|
+
text-decoration: none !important;
|
|
266
|
+
}
|
|
267
|
+
.leaflet-bar a:first-child { border-radius: 3px 3px 0 0 !important; }
|
|
268
|
+
.leaflet-bar a:last-child { border-radius: 0 0 3px 3px !important; }
|
|
269
|
+
.leaflet-bar a + a { border-block-start: 1px solid var(--uva-color-control-border, #808080) !important; }
|
|
270
|
+
.leaflet-bar a:hover { background: var(--uva-color-surface-hover, #dadada) !important; }
|
|
271
|
+
.leaflet-bar a.leaflet-disabled {
|
|
272
|
+
background: var(--uva-color-track, #e5e7eb) !important;
|
|
273
|
+
color: var(--uva-color-text-muted, #4b5563) !important;
|
|
274
|
+
cursor: not-allowed;
|
|
275
|
+
}
|
|
276
|
+
.leaflet-bar a:focus-visible { position: relative; z-index: 1; }
|
|
277
|
+
.leaflet-control-attribution {
|
|
278
|
+
padding: 0.125rem 0.375rem !important;
|
|
279
|
+
background: var(--uva-color-surface, #fff) !important;
|
|
280
|
+
color: var(--uva-color-text, #2b2b2b) !important;
|
|
281
|
+
font-size: 0.8125rem !important;
|
|
282
|
+
line-height: 1.5 !important;
|
|
283
|
+
}
|
|
284
|
+
.leaflet-control-attribution a {
|
|
285
|
+
color: var(--uva-color-link, var(--uva-brand-blue, #232d4b)) !important;
|
|
286
|
+
text-decoration: underline !important;
|
|
287
|
+
}
|
|
288
|
+
.leaflet-tooltip {
|
|
289
|
+
padding: 0.25rem 0.5rem !important;
|
|
290
|
+
border: 1px solid var(--uva-color-control-border, #808080) !important;
|
|
291
|
+
border-radius: 4px !important;
|
|
292
|
+
background: var(--uva-color-surface-raised, #fff) !important;
|
|
293
|
+
color: var(--uva-color-text, #2b2b2b) !important;
|
|
294
|
+
box-shadow: 0 1px 4px var(--uva-color-shadow, rgba(0, 0, 0, 0.2)) !important;
|
|
295
|
+
font-size: 0.875rem !important;
|
|
296
|
+
line-height: 1.4 !important;
|
|
297
|
+
}
|
|
298
|
+
.leaflet-tooltip::before { display: none !important; }
|
|
299
|
+
.tip-name { display: block; font-weight: 600; }
|
|
300
|
+
.places {
|
|
301
|
+
display: grid;
|
|
302
|
+
grid-template-columns: repeat(auto-fill, minmax(min(100%, 15rem), 1fr));
|
|
303
|
+
gap: 0.5rem;
|
|
304
|
+
margin: 1rem 0 0;
|
|
305
|
+
padding: 0;
|
|
306
|
+
list-style: none;
|
|
307
|
+
}
|
|
308
|
+
.places:focus { outline: none; }
|
|
309
|
+
.places:focus-visible {
|
|
310
|
+
outline: 3px solid var(--uva-color-focus, var(--uva-brand-orange, #e57200));
|
|
311
|
+
outline-offset: 2px;
|
|
312
|
+
}
|
|
313
|
+
.place {
|
|
314
|
+
display: flex;
|
|
315
|
+
flex-wrap: wrap;
|
|
316
|
+
align-items: baseline;
|
|
317
|
+
gap: 0.25rem 0.5rem;
|
|
318
|
+
padding: 0.5rem 0.75rem;
|
|
319
|
+
border: 1px solid var(--uva-color-control-border, #808080);
|
|
320
|
+
border-radius: 4px;
|
|
321
|
+
background: var(--uva-color-surface-raised, #fff);
|
|
322
|
+
color: var(--uva-color-text, #2b2b2b);
|
|
323
|
+
}
|
|
324
|
+
.place.is-active {
|
|
325
|
+
outline: 3px solid var(--uva-color-text, #2b2b2b);
|
|
326
|
+
outline-offset: 1px;
|
|
327
|
+
}
|
|
328
|
+
.place a, .place .name {
|
|
329
|
+
display: inline-block;
|
|
330
|
+
min-block-size: 24px;
|
|
331
|
+
font-weight: 600;
|
|
332
|
+
line-height: 1.5;
|
|
333
|
+
}
|
|
334
|
+
.place a { color: var(--uva-color-link, var(--uva-brand-blue, #232d4b)); text-decoration: underline; }
|
|
335
|
+
.count {
|
|
336
|
+
padding: 0 0.5rem;
|
|
337
|
+
border: 1px solid var(--uva-color-control-border, #808080);
|
|
338
|
+
border-radius: 999px;
|
|
339
|
+
background: var(--uva-color-track, #e5e7eb);
|
|
340
|
+
color: var(--uva-color-text, #2b2b2b);
|
|
341
|
+
font-size: 0.875rem;
|
|
342
|
+
white-space: nowrap;
|
|
343
|
+
}
|
|
344
|
+
.description {
|
|
345
|
+
flex-basis: 100%;
|
|
346
|
+
font-size: 0.875rem;
|
|
347
|
+
color: var(--uva-color-text-muted, #4b5563);
|
|
348
|
+
}
|
|
349
|
+
@media (prefers-reduced-motion: reduce) {
|
|
350
|
+
.uvalib-map-marker .dot { transition: none; }
|
|
351
|
+
}
|
|
352
|
+
`),
|
|
353
|
+
]; }
|
|
354
|
+
constructor() {
|
|
355
|
+
super();
|
|
356
|
+
/** The places. When non-empty, wins over the child list. Set a new array to update. */
|
|
357
|
+
this.items = [];
|
|
358
|
+
/** The map's name (required): the region's label, the list's label and the analytics name. */
|
|
359
|
+
this.label = '';
|
|
360
|
+
/** The noun after each count, plural ("photos"); a count of one drops a trailing s. */
|
|
361
|
+
this.countLabel = 'items';
|
|
362
|
+
/** The tile URL template (`{z}/{x}/{y}`, optionally `{s}` and `{r}`). */
|
|
363
|
+
this.tileUrl = OSM_TILE_URL;
|
|
364
|
+
/** Tiles for the page's dark mode. Without it, dark mode filters the light tiles instead. */
|
|
365
|
+
this.darkTileUrl = '';
|
|
366
|
+
/** The tiles' attribution, as HTML. Required by most tile sources; always shown. */
|
|
367
|
+
this.attribution = OSM_ATTRIBUTION;
|
|
368
|
+
/** Where the map opens, `"lat,lng"`. Without it the map fits every place. */
|
|
369
|
+
this.center = '';
|
|
370
|
+
this.sourceItems = [];
|
|
371
|
+
this.hasLeaflet = false;
|
|
372
|
+
this.active = -1;
|
|
373
|
+
this.dark = false;
|
|
374
|
+
this.uid = `uvalib-map-${++instanceCounter}`;
|
|
375
|
+
this.sourceKey = '[]';
|
|
376
|
+
this.markers = [];
|
|
377
|
+
this.drawn = [];
|
|
378
|
+
this.reduceMotion = false;
|
|
379
|
+
/** The visitor moved the map: a resize no longer refits it. */
|
|
380
|
+
this.userMoved = false;
|
|
381
|
+
this.fitting = false;
|
|
382
|
+
this.hoverIndex = -1;
|
|
383
|
+
this.focusIndex = -1;
|
|
384
|
+
this.dismissed = false;
|
|
385
|
+
this.warnedLabel = false;
|
|
386
|
+
this.warnedLeaflet = false;
|
|
387
|
+
this.onPageLoad = () => this.requestUpdate();
|
|
388
|
+
this.readScheme = () => {
|
|
389
|
+
this.dark = pageIsDark(this.ownerDocument);
|
|
390
|
+
};
|
|
391
|
+
this.onMapClick = (e) => {
|
|
392
|
+
const t = e.target;
|
|
393
|
+
if (t.closest?.('.leaflet-control-zoom a')) {
|
|
394
|
+
this.queueZoomReport();
|
|
395
|
+
return;
|
|
396
|
+
}
|
|
397
|
+
const i = this.indexOf(e);
|
|
398
|
+
const p = this.places[i];
|
|
399
|
+
if (i < 0 || !p)
|
|
400
|
+
return;
|
|
401
|
+
// The end of a drag that started on a marker is not a choice (a key press always is).
|
|
402
|
+
const drag = this.map?.dragging;
|
|
403
|
+
if (e.detail !== 0 && drag?.moved?.()) {
|
|
404
|
+
e.preventDefault();
|
|
405
|
+
return;
|
|
406
|
+
}
|
|
407
|
+
trackEvent(this, [TAG, 'select', this.label, i + 1]);
|
|
408
|
+
const go = this.dispatchEvent(new CustomEvent('select', {
|
|
409
|
+
detail: { item: p },
|
|
410
|
+
bubbles: true,
|
|
411
|
+
composed: true,
|
|
412
|
+
cancelable: true,
|
|
413
|
+
}));
|
|
414
|
+
if (!go)
|
|
415
|
+
e.preventDefault();
|
|
416
|
+
};
|
|
417
|
+
this.onMapKeydown = (e) => {
|
|
418
|
+
const t = e.target;
|
|
419
|
+
// Leaflet's zoom buttons are links with role="button": Space presses them too.
|
|
420
|
+
if (e.key === ' ' && t.closest?.('.leaflet-control-zoom a')) {
|
|
421
|
+
e.preventDefault();
|
|
422
|
+
t.closest('a').click();
|
|
423
|
+
return;
|
|
424
|
+
}
|
|
425
|
+
const i = this.indexOf(e);
|
|
426
|
+
if (i < 0)
|
|
427
|
+
return;
|
|
428
|
+
const order = this.markers.flatMap((m, j) => (m ? [j] : []));
|
|
429
|
+
const at = order.indexOf(i);
|
|
430
|
+
let next = -1;
|
|
431
|
+
if (e.key === 'ArrowRight' || e.key === 'ArrowDown')
|
|
432
|
+
next = order[at + 1] ?? -1;
|
|
433
|
+
else if (e.key === 'ArrowLeft' || e.key === 'ArrowUp')
|
|
434
|
+
next = order[at - 1] ?? -1;
|
|
435
|
+
else if (e.key === 'Home')
|
|
436
|
+
next = order[0] ?? -1;
|
|
437
|
+
else if (e.key === 'End')
|
|
438
|
+
next = order[order.length - 1] ?? -1;
|
|
439
|
+
else if (e.key === ' ' && t.localName === 'a') {
|
|
440
|
+
// A link marker is a control here: Space chooses it, like Enter.
|
|
441
|
+
e.preventDefault();
|
|
442
|
+
t.click();
|
|
443
|
+
return;
|
|
444
|
+
}
|
|
445
|
+
else
|
|
446
|
+
return;
|
|
447
|
+
e.preventDefault();
|
|
448
|
+
e.stopPropagation();
|
|
449
|
+
if (next >= 0) {
|
|
450
|
+
this.reveal(next);
|
|
451
|
+
this.markerEl(next)?.querySelector('.marker')?.focus();
|
|
452
|
+
}
|
|
453
|
+
};
|
|
454
|
+
this.onMapFocusIn = (e) => {
|
|
455
|
+
const i = this.indexOf(e);
|
|
456
|
+
if (i < 0)
|
|
457
|
+
return;
|
|
458
|
+
this.focusIndex = i;
|
|
459
|
+
this.dismissed = false;
|
|
460
|
+
this.reveal(i);
|
|
461
|
+
this.syncActive();
|
|
462
|
+
};
|
|
463
|
+
this.onMapFocusOut = (e) => {
|
|
464
|
+
if (this.indexOf(e) < 0)
|
|
465
|
+
return;
|
|
466
|
+
const to = e.relatedTarget;
|
|
467
|
+
if (to?.closest?.('.marker'))
|
|
468
|
+
return; // the next marker's focusin sets it
|
|
469
|
+
this.focusIndex = -1;
|
|
470
|
+
this.syncActive();
|
|
471
|
+
};
|
|
472
|
+
this.onMapLeave = () => {
|
|
473
|
+
this.hoverIndex = -1;
|
|
474
|
+
this.syncActive();
|
|
475
|
+
};
|
|
476
|
+
/** The skip link: focus the list (a fragment link cannot reach into a shadow root). */
|
|
477
|
+
this.skipToList = (e) => {
|
|
478
|
+
e.preventDefault();
|
|
479
|
+
this.renderRoot.querySelector(`#${this.uid}-list`)?.focus();
|
|
480
|
+
};
|
|
481
|
+
new SourceChildren(this, () => this.lightDom, (nodes) => this.readList(nodes));
|
|
482
|
+
this.addEventListener('keydown', (e) => {
|
|
483
|
+
if (e.key === 'Escape' && this.active >= 0) {
|
|
484
|
+
this.dismissed = true;
|
|
485
|
+
this.syncActive();
|
|
486
|
+
}
|
|
487
|
+
});
|
|
488
|
+
}
|
|
489
|
+
createRenderRoot() {
|
|
490
|
+
const root = super.createRenderRoot();
|
|
491
|
+
if (root instanceof ShadowRoot && this.noStyle) {
|
|
492
|
+
const sheet = shadowStructure.styleSheet;
|
|
493
|
+
if (sheet)
|
|
494
|
+
root.adoptedStyleSheets = [sheet];
|
|
495
|
+
}
|
|
496
|
+
return root;
|
|
497
|
+
}
|
|
498
|
+
connectedCallback() {
|
|
499
|
+
super.connectedCallback();
|
|
500
|
+
if (this.lightDom && this.noStyle) {
|
|
501
|
+
const node = this.getRootNode();
|
|
502
|
+
installLightDomStyles(`${this.localName}::structure`, unsafeCSS(structuralRules(this.localName)), {
|
|
503
|
+
root: node instanceof ShadowRoot || node instanceof Document ? node : undefined,
|
|
504
|
+
scope: false,
|
|
505
|
+
});
|
|
506
|
+
}
|
|
507
|
+
const doc = this.ownerDocument;
|
|
508
|
+
this.schemeObserver = new MutationObserver(() => this.readScheme());
|
|
509
|
+
this.schemeObserver.observe(doc.documentElement, {
|
|
510
|
+
attributes: true,
|
|
511
|
+
attributeFilter: ['data-uva-color-scheme'],
|
|
512
|
+
});
|
|
513
|
+
this.darkQuery = doc.defaultView?.matchMedia?.('(prefers-color-scheme: dark)');
|
|
514
|
+
this.darkQuery?.addEventListener('change', this.readScheme);
|
|
515
|
+
this.readScheme();
|
|
516
|
+
// leaflet.js loaded with async (or after this script): look again once the page has loaded.
|
|
517
|
+
if (doc.readyState !== 'complete')
|
|
518
|
+
doc.defaultView?.addEventListener('load', this.onPageLoad, { once: true });
|
|
519
|
+
if (this.hasUpdated)
|
|
520
|
+
this.requestUpdate();
|
|
521
|
+
}
|
|
522
|
+
disconnectedCallback() {
|
|
523
|
+
super.disconnectedCallback();
|
|
524
|
+
this.ownerDocument.defaultView?.removeEventListener('load', this.onPageLoad);
|
|
525
|
+
this.schemeObserver?.disconnect();
|
|
526
|
+
this.darkQuery?.removeEventListener('change', this.readScheme);
|
|
527
|
+
this.teardown();
|
|
528
|
+
}
|
|
529
|
+
/** The places shown: `items`, else the child list. */
|
|
530
|
+
get places() {
|
|
531
|
+
return this.items?.length ? this.items : this.sourceItems;
|
|
532
|
+
}
|
|
533
|
+
/** The child list's places, compared with the last read so only a real change re-renders. */
|
|
534
|
+
readList(nodes) {
|
|
535
|
+
const list = nodes.find((n) => n instanceof Element && (n.localName === 'ul' || n.localName === 'ol'));
|
|
536
|
+
const out = [];
|
|
537
|
+
for (const li of list ? [...list.children] : []) {
|
|
538
|
+
if (li.localName !== 'li')
|
|
539
|
+
continue;
|
|
540
|
+
const src = (li.matches('[data-lat]') ? li : li.querySelector('[data-lat]'));
|
|
541
|
+
if (!src)
|
|
542
|
+
continue;
|
|
543
|
+
const a = li.querySelector('a[href]');
|
|
544
|
+
const d = src.dataset;
|
|
545
|
+
const item = {
|
|
546
|
+
name: normalize((a ?? src).textContent),
|
|
547
|
+
lat: Number(d.lat),
|
|
548
|
+
lng: Number(d.lng),
|
|
549
|
+
};
|
|
550
|
+
const id = d.id ?? (li.id || undefined);
|
|
551
|
+
if (id)
|
|
552
|
+
item.id = id;
|
|
553
|
+
if (d.count !== undefined && d.count.trim() !== '' && Number.isFinite(Number(d.count)))
|
|
554
|
+
item.count = Number(d.count);
|
|
555
|
+
const href = a?.getAttribute('href');
|
|
556
|
+
if (href)
|
|
557
|
+
item.href = href;
|
|
558
|
+
const description = d.description ?? li.dataset.description;
|
|
559
|
+
if (description)
|
|
560
|
+
item.description = normalize(description);
|
|
561
|
+
out.push(item);
|
|
562
|
+
}
|
|
563
|
+
const key = JSON.stringify(out);
|
|
564
|
+
if (key === this.sourceKey)
|
|
565
|
+
return;
|
|
566
|
+
this.sourceKey = key;
|
|
567
|
+
this.sourceItems = out;
|
|
568
|
+
}
|
|
569
|
+
/** The page's Leaflet: the `leaflet` property (a module namespace or its default), or `window.L`. */
|
|
570
|
+
findLeaflet() {
|
|
571
|
+
const isL = (x) => !!x &&
|
|
572
|
+
typeof x.map === 'function' &&
|
|
573
|
+
typeof x.divIcon === 'function' &&
|
|
574
|
+
typeof x.tileLayer === 'function';
|
|
575
|
+
const own = this.leaflet;
|
|
576
|
+
const win = this.ownerDocument.defaultView;
|
|
577
|
+
for (const x of [own, own?.default, win?.L])
|
|
578
|
+
if (isL(x))
|
|
579
|
+
return x;
|
|
580
|
+
return undefined;
|
|
581
|
+
}
|
|
582
|
+
willUpdate(changed) {
|
|
583
|
+
const L = this.findLeaflet();
|
|
584
|
+
if (L !== this.L) {
|
|
585
|
+
if (this.map)
|
|
586
|
+
this.teardown();
|
|
587
|
+
this.L = L;
|
|
588
|
+
}
|
|
589
|
+
this.hasLeaflet = !!L;
|
|
590
|
+
if (changed.has('label') && !this.label.trim() && !this.warnedLabel) {
|
|
591
|
+
this.warnedLabel = true;
|
|
592
|
+
console.warn(`<${TAG}>: label is required; it names the map region and the list.`);
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
updated(changed) {
|
|
596
|
+
super.updated(changed);
|
|
597
|
+
if (!this.L) {
|
|
598
|
+
// A page script may set `leaflet` just after this renders: warn only if it is still
|
|
599
|
+
// missing a second after the page has loaded.
|
|
600
|
+
if (!this.warnedLeaflet && this.ownerDocument.readyState === 'complete') {
|
|
601
|
+
this.warnedLeaflet = true;
|
|
602
|
+
setTimeout(() => {
|
|
603
|
+
if (this.isConnected && !this.findLeaflet())
|
|
604
|
+
console.warn(`<${TAG}>: Leaflet was not found (set the leaflet property, or load leaflet.js for window.L); showing the list only.`);
|
|
605
|
+
}, 1000);
|
|
606
|
+
}
|
|
607
|
+
return;
|
|
608
|
+
}
|
|
609
|
+
const created = this.setUpMap();
|
|
610
|
+
const map = this.map;
|
|
611
|
+
if (!map)
|
|
612
|
+
return;
|
|
613
|
+
if (!created &&
|
|
614
|
+
(changed.has('tileUrl') ||
|
|
615
|
+
changed.has('darkTileUrl') ||
|
|
616
|
+
changed.has('attribution') ||
|
|
617
|
+
changed.has('dark')))
|
|
618
|
+
this.drawTiles();
|
|
619
|
+
if (created || this.places !== this.drawn || changed.has('countLabel')) {
|
|
620
|
+
this.drawMarkers();
|
|
621
|
+
if (created || !this.userMoved)
|
|
622
|
+
this.fit();
|
|
623
|
+
}
|
|
624
|
+
else if (changed.has('center') || changed.has('zoom')) {
|
|
625
|
+
this.fit();
|
|
626
|
+
}
|
|
627
|
+
if (changed.has('active'))
|
|
628
|
+
this.showActive(changed.get('active'));
|
|
629
|
+
}
|
|
630
|
+
get container() {
|
|
631
|
+
return this.renderRoot.querySelector(`#${this.uid}-map`);
|
|
632
|
+
}
|
|
633
|
+
/** Create the Leaflet map once its container is rendered. True when it was created now. */
|
|
634
|
+
setUpMap() {
|
|
635
|
+
const L = this.L;
|
|
636
|
+
const el = this.container;
|
|
637
|
+
if (!L || !el || this.map)
|
|
638
|
+
return false;
|
|
639
|
+
const win = this.ownerDocument.defaultView;
|
|
640
|
+
this.reduceMotion = !!win?.matchMedia?.('(prefers-reduced-motion: reduce)').matches;
|
|
641
|
+
const still = !this.reduceMotion;
|
|
642
|
+
const map = L.map(el, {
|
|
643
|
+
zoomControl: false,
|
|
644
|
+
attributionControl: false,
|
|
645
|
+
scrollWheelZoom: false,
|
|
646
|
+
zoomAnimation: still,
|
|
647
|
+
fadeAnimation: still,
|
|
648
|
+
markerZoomAnimation: still,
|
|
649
|
+
inertia: still,
|
|
650
|
+
keyboard: true,
|
|
651
|
+
// Half steps, so the opening view fits the places as closely as it can.
|
|
652
|
+
zoomSnap: 0.5,
|
|
653
|
+
});
|
|
654
|
+
this.map = map;
|
|
655
|
+
L.control.zoom({ position: 'topleft' }).addTo(map);
|
|
656
|
+
L.control
|
|
657
|
+
.attribution({
|
|
658
|
+
position: 'bottomright',
|
|
659
|
+
prefix: '<a href="https://leafletjs.com">Leaflet</a>',
|
|
660
|
+
})
|
|
661
|
+
.addTo(map);
|
|
662
|
+
this.tooltip = L.tooltip({
|
|
663
|
+
direction: 'top',
|
|
664
|
+
opacity: 1,
|
|
665
|
+
className: 'uvalib-map-tooltip',
|
|
666
|
+
});
|
|
667
|
+
map.on('movestart', () => {
|
|
668
|
+
if (!this.fitting)
|
|
669
|
+
this.userMoved = true;
|
|
670
|
+
});
|
|
671
|
+
this.drawTiles();
|
|
672
|
+
this.ro = new ResizeObserver(() => {
|
|
673
|
+
if (!this.map)
|
|
674
|
+
return;
|
|
675
|
+
this.map.invalidateSize({ animate: false });
|
|
676
|
+
if (!this.userMoved)
|
|
677
|
+
this.fit();
|
|
678
|
+
});
|
|
679
|
+
this.ro.observe(el);
|
|
680
|
+
return true;
|
|
681
|
+
}
|
|
682
|
+
teardown() {
|
|
683
|
+
clearTimeout(this.zoomTimer);
|
|
684
|
+
this.ro?.disconnect();
|
|
685
|
+
this.ro = undefined;
|
|
686
|
+
this.map?.remove();
|
|
687
|
+
this.map = undefined;
|
|
688
|
+
this.tiles = undefined;
|
|
689
|
+
this.tooltip = undefined;
|
|
690
|
+
this.markers = [];
|
|
691
|
+
this.drawn = [];
|
|
692
|
+
this.userMoved = false;
|
|
693
|
+
}
|
|
694
|
+
/** The tile layer for the current scheme: dark tiles when given, else the filtered light ones. */
|
|
695
|
+
drawTiles() {
|
|
696
|
+
const { L, map } = this;
|
|
697
|
+
if (!L || !map)
|
|
698
|
+
return;
|
|
699
|
+
const url = this.dark && this.darkTileUrl ? this.darkTileUrl : this.tileUrl || OSM_TILE_URL;
|
|
700
|
+
this.tiles?.remove();
|
|
701
|
+
this.tiles = L.tileLayer(url, { attribution: this.attribution, maxZoom: 19 }).addTo(map);
|
|
702
|
+
}
|
|
703
|
+
/** Marker dot diameter: the square root of the count, between MIN_DOT and MAX_DOT. */
|
|
704
|
+
dotSize(count, max) {
|
|
705
|
+
if (!(max > 0) || count === undefined || !(count > 0))
|
|
706
|
+
return MIN_DOT;
|
|
707
|
+
return Math.round(MIN_DOT + (MAX_DOT - MIN_DOT) * Math.sqrt(count / max));
|
|
708
|
+
}
|
|
709
|
+
/** "The Rotunda, 2,702 photos", or the name alone without a count. */
|
|
710
|
+
placeName(p) {
|
|
711
|
+
return p.count === undefined ? p.name : `${p.name}, ${this.countText(p.count)}`;
|
|
712
|
+
}
|
|
713
|
+
countText(n) {
|
|
714
|
+
return `${fmt(n)} ${noun(this.countLabel || 'items', n)}`;
|
|
715
|
+
}
|
|
716
|
+
href(p) {
|
|
717
|
+
return p.href && safeHref(p.href, this.ownerDocument.baseURI) ? p.href : null;
|
|
718
|
+
}
|
|
719
|
+
drawMarkers() {
|
|
720
|
+
const { L, map } = this;
|
|
721
|
+
if (!L || !map)
|
|
722
|
+
return;
|
|
723
|
+
for (const m of this.markers)
|
|
724
|
+
m?.remove();
|
|
725
|
+
const places = this.places;
|
|
726
|
+
this.drawn = places;
|
|
727
|
+
const max = Math.max(0, ...places.map((p) => (Number.isFinite(p.count) ? p.count : 0)));
|
|
728
|
+
const doc = this.ownerDocument;
|
|
729
|
+
this.markers = places.map((p, i) => {
|
|
730
|
+
if (!validPlace(p))
|
|
731
|
+
return undefined;
|
|
732
|
+
const d = this.dotSize(p.count, max);
|
|
733
|
+
const hit = Math.max(HIT, d);
|
|
734
|
+
const href = this.href(p);
|
|
735
|
+
const ctl = doc.createElement(href ? 'a' : 'button');
|
|
736
|
+
if (ctl instanceof HTMLAnchorElement)
|
|
737
|
+
ctl.href = href;
|
|
738
|
+
else
|
|
739
|
+
ctl.type = 'button';
|
|
740
|
+
ctl.className = 'marker';
|
|
741
|
+
ctl.dataset.index = String(i);
|
|
742
|
+
ctl.style.setProperty('--d', `${d}px`);
|
|
743
|
+
const dot = doc.createElement('span');
|
|
744
|
+
dot.className = 'dot';
|
|
745
|
+
dot.setAttribute('aria-hidden', 'true');
|
|
746
|
+
const name = doc.createElement('span');
|
|
747
|
+
name.className = 'visually-hidden';
|
|
748
|
+
name.textContent = this.placeName(p);
|
|
749
|
+
ctl.append(dot, name);
|
|
750
|
+
const marker = L.marker([p.lat, p.lng], {
|
|
751
|
+
icon: L.divIcon({
|
|
752
|
+
className: 'uvalib-map-marker',
|
|
753
|
+
html: ctl,
|
|
754
|
+
iconSize: [hit, hit],
|
|
755
|
+
iconAnchor: [hit / 2, hit / 2],
|
|
756
|
+
}),
|
|
757
|
+
keyboard: false,
|
|
758
|
+
// Smaller dots above larger ones, so every one stays reachable by pointer.
|
|
759
|
+
zIndexOffset: (MAX_DOT - d) * 10,
|
|
760
|
+
});
|
|
761
|
+
marker.on('mouseover', () => this.hover(i));
|
|
762
|
+
return marker.addTo(map);
|
|
763
|
+
});
|
|
764
|
+
this.hoverIndex = -1;
|
|
765
|
+
this.focusIndex = -1;
|
|
766
|
+
if (this.active !== -1)
|
|
767
|
+
this.active = -1;
|
|
768
|
+
}
|
|
769
|
+
/** Open on `center`/`zoom`, else on the places' bounds, else on Grounds. */
|
|
770
|
+
fit() {
|
|
771
|
+
const { L, map } = this;
|
|
772
|
+
if (!L || !map)
|
|
773
|
+
return;
|
|
774
|
+
const pts = this.places.filter(validPlace).map((p) => L.latLng(p.lat, p.lng));
|
|
775
|
+
const center = parseCenter(this.center);
|
|
776
|
+
const zoom = Number.isFinite(this.zoom) ? this.zoom : undefined;
|
|
777
|
+
this.fitting = true;
|
|
778
|
+
try {
|
|
779
|
+
if (center)
|
|
780
|
+
map.setView(center, zoom ?? 16, { animate: false });
|
|
781
|
+
else if (pts.length === 1)
|
|
782
|
+
map.setView(pts[0], zoom ?? 16, { animate: false });
|
|
783
|
+
else if (pts.length && zoom !== undefined)
|
|
784
|
+
map.setView(L.latLngBounds(pts).getCenter(), zoom, { animate: false });
|
|
785
|
+
else if (pts.length) {
|
|
786
|
+
// As close as the largest marker allows; again clear of the zoom buttons (top
|
|
787
|
+
// left) and the attribution (bottom right) if a marker would sit under them.
|
|
788
|
+
const bounds = L.latLngBounds(pts);
|
|
789
|
+
const edge = MAX_DOT / 2 + 4;
|
|
790
|
+
map.fitBounds(bounds, { padding: [edge, edge], maxZoom: 17, animate: false });
|
|
791
|
+
if (this.underControls(pts))
|
|
792
|
+
map.fitBounds(bounds, {
|
|
793
|
+
paddingTopLeft: [80, 40],
|
|
794
|
+
paddingBottomRight: [40, 40],
|
|
795
|
+
maxZoom: 17,
|
|
796
|
+
animate: false,
|
|
797
|
+
});
|
|
798
|
+
}
|
|
799
|
+
else
|
|
800
|
+
map.setView(GROUNDS, 15, { animate: false });
|
|
801
|
+
}
|
|
802
|
+
finally {
|
|
803
|
+
this.fitting = false;
|
|
804
|
+
}
|
|
805
|
+
}
|
|
806
|
+
/** Whether any of `pts` is under (or within 12px of) the zoom buttons or the attribution. */
|
|
807
|
+
underControls(pts) {
|
|
808
|
+
const map = this.map;
|
|
809
|
+
const box = map.getContainer().getBoundingClientRect();
|
|
810
|
+
const rects = [
|
|
811
|
+
...map.getContainer().querySelectorAll('.leaflet-control-zoom, .leaflet-control-attribution'),
|
|
812
|
+
].map((c) => c.getBoundingClientRect());
|
|
813
|
+
return pts.some((ll) => {
|
|
814
|
+
const p = map.latLngToContainerPoint(ll);
|
|
815
|
+
const [x, y] = [p.x + box.left, p.y + box.top];
|
|
816
|
+
return rects.some((r) => r.width > 0 &&
|
|
817
|
+
x >= r.left - 12 &&
|
|
818
|
+
x <= r.right + 12 &&
|
|
819
|
+
y >= r.top - 12 &&
|
|
820
|
+
y <= r.bottom + 12);
|
|
821
|
+
});
|
|
822
|
+
}
|
|
823
|
+
markerEl(i) {
|
|
824
|
+
return this.markers[i]?.getElement();
|
|
825
|
+
}
|
|
826
|
+
hover(i) {
|
|
827
|
+
this.hoverIndex = i;
|
|
828
|
+
this.dismissed = false;
|
|
829
|
+
this.syncActive();
|
|
830
|
+
}
|
|
831
|
+
/** The highlighted place: the one hovered, else the one focused (none after Escape). */
|
|
832
|
+
syncActive() {
|
|
833
|
+
this.active = this.dismissed ? -1 : this.hoverIndex >= 0 ? this.hoverIndex : this.focusIndex;
|
|
834
|
+
}
|
|
835
|
+
/** Highlight the active place's marker and show its tooltip (after a render). */
|
|
836
|
+
showActive(prev) {
|
|
837
|
+
const { map, tooltip } = this;
|
|
838
|
+
if (!map || !tooltip)
|
|
839
|
+
return;
|
|
840
|
+
if (prev !== undefined && prev >= 0) {
|
|
841
|
+
this.markerEl(prev)?.classList.remove('is-active');
|
|
842
|
+
const d = this.markerDot(prev);
|
|
843
|
+
this.markers[prev]?.setZIndexOffset((MAX_DOT - d) * 10);
|
|
844
|
+
}
|
|
845
|
+
const i = this.active;
|
|
846
|
+
const marker = this.markers[i];
|
|
847
|
+
const p = this.places[i];
|
|
848
|
+
if (i < 0 || !marker || !p) {
|
|
849
|
+
tooltip.remove();
|
|
850
|
+
return;
|
|
851
|
+
}
|
|
852
|
+
this.markerEl(i)?.classList.add('is-active');
|
|
853
|
+
marker.setZIndexOffset(10000);
|
|
854
|
+
const content = this.ownerDocument.createElement('span');
|
|
855
|
+
const name = this.ownerDocument.createElement('span');
|
|
856
|
+
name.className = 'tip-name';
|
|
857
|
+
name.textContent = p.name;
|
|
858
|
+
content.append(name);
|
|
859
|
+
if (p.count !== undefined)
|
|
860
|
+
content.append(this.countText(p.count));
|
|
861
|
+
const size = Math.max(HIT, this.markerDot(i));
|
|
862
|
+
tooltip.options.offset = [0, -Math.round(size * 0.6)];
|
|
863
|
+
tooltip.setLatLng(marker.getLatLng()).setContent(content);
|
|
864
|
+
if (!map.hasLayer(tooltip))
|
|
865
|
+
tooltip.addTo(map);
|
|
866
|
+
else
|
|
867
|
+
tooltip.update();
|
|
868
|
+
}
|
|
869
|
+
markerDot(i) {
|
|
870
|
+
const d = parseFloat(this.markerEl(i)?.querySelector('.marker')?.style.getPropertyValue('--d') ?? '');
|
|
871
|
+
return Number.isFinite(d) ? d : MIN_DOT;
|
|
872
|
+
}
|
|
873
|
+
/** Bring a place into view (on focus), without animation under reduced motion. */
|
|
874
|
+
reveal(i) {
|
|
875
|
+
const { map } = this;
|
|
876
|
+
const marker = this.markers[i];
|
|
877
|
+
if (!map || !marker)
|
|
878
|
+
return;
|
|
879
|
+
const ll = marker.getLatLng();
|
|
880
|
+
if (!map.getBounds().pad(-0.15).contains(ll))
|
|
881
|
+
map.panTo(ll, { animate: !this.reduceMotion });
|
|
882
|
+
}
|
|
883
|
+
indexOf(e) {
|
|
884
|
+
const t = e.target;
|
|
885
|
+
const ctl = t?.closest?.('.marker');
|
|
886
|
+
return ctl ? Number(ctl.dataset.index) : -1;
|
|
887
|
+
}
|
|
888
|
+
/** Report the zoom level 1 s after the last zoom-button press. */
|
|
889
|
+
queueZoomReport() {
|
|
890
|
+
clearTimeout(this.zoomTimer);
|
|
891
|
+
this.zoomTimer = setTimeout(() => {
|
|
892
|
+
if (this.map)
|
|
893
|
+
trackEvent(this, [TAG, 'zoom', this.label, this.map.getZoom()]);
|
|
894
|
+
}, 1000);
|
|
895
|
+
}
|
|
896
|
+
onPlaceEnter(i) {
|
|
897
|
+
this.hover(i);
|
|
898
|
+
}
|
|
899
|
+
onPlaceLeave() {
|
|
900
|
+
this.hoverIndex = -1;
|
|
901
|
+
this.syncActive();
|
|
902
|
+
}
|
|
903
|
+
onPlaceFocusIn(i) {
|
|
904
|
+
this.focusIndex = i;
|
|
905
|
+
this.dismissed = false;
|
|
906
|
+
this.reveal(i);
|
|
907
|
+
this.syncActive();
|
|
908
|
+
}
|
|
909
|
+
onPlaceFocusOut(e) {
|
|
910
|
+
const to = e.relatedTarget;
|
|
911
|
+
if (to?.closest?.('.place'))
|
|
912
|
+
return;
|
|
913
|
+
this.focusIndex = -1;
|
|
914
|
+
this.syncActive();
|
|
915
|
+
}
|
|
916
|
+
render() {
|
|
917
|
+
const places = this.places;
|
|
918
|
+
const label = this.label.trim() || 'Places';
|
|
919
|
+
const listId = `${this.uid}-list`;
|
|
920
|
+
const map = this.hasLeaflet
|
|
921
|
+
? html `<a class="skip-link" href="#${listId}" @click=${this.skipToList}
|
|
922
|
+
>Skip map, go to the list</a
|
|
923
|
+
>
|
|
924
|
+
<p class="instructions" part="instructions">${MAP_INSTRUCTIONS}</p>
|
|
925
|
+
<div class=${this.dark && !this.darkTileUrl ? 'frame dark-tiles' : 'frame'}>
|
|
926
|
+
<div
|
|
927
|
+
id="${this.uid}-map"
|
|
928
|
+
class="map"
|
|
929
|
+
part="map"
|
|
930
|
+
role="region"
|
|
931
|
+
aria-label=${`${label}, map`}
|
|
932
|
+
@click=${{ handleEvent: this.onMapClick, capture: true }}
|
|
933
|
+
@keydown=${this.onMapKeydown}
|
|
934
|
+
@focusin=${this.onMapFocusIn}
|
|
935
|
+
@focusout=${this.onMapFocusOut}
|
|
936
|
+
@mouseleave=${this.onMapLeave}
|
|
937
|
+
></div>
|
|
938
|
+
</div>`
|
|
939
|
+
: nothing;
|
|
940
|
+
return html `${map}
|
|
941
|
+
<ul class="places" part="list" id=${listId} tabindex="-1" aria-label=${`${label}, list`}>
|
|
942
|
+
${places.map((p, i) => {
|
|
943
|
+
const href = this.href(p);
|
|
944
|
+
return html `<li
|
|
945
|
+
class=${i === this.active ? 'place is-active' : 'place'}
|
|
946
|
+
part="place"
|
|
947
|
+
@mouseenter=${() => this.onPlaceEnter(i)}
|
|
948
|
+
@mouseleave=${() => this.onPlaceLeave()}
|
|
949
|
+
@focusin=${() => this.onPlaceFocusIn(i)}
|
|
950
|
+
@focusout=${(e) => this.onPlaceFocusOut(e)}
|
|
951
|
+
>
|
|
952
|
+
${href ? html `<a href=${href}>${p.name}</a>` : html `<span class="name">${p.name}</span>`}
|
|
953
|
+
${p.count !== undefined && Number.isFinite(p.count)
|
|
954
|
+
? html `<span class="count">${this.countText(p.count)}</span>`
|
|
955
|
+
: nothing}
|
|
956
|
+
${p.description ? html `<span class="description">${p.description}</span>` : nothing}
|
|
957
|
+
</li>`;
|
|
958
|
+
})}
|
|
959
|
+
</ul>`;
|
|
960
|
+
}
|
|
961
|
+
}
|
|
962
|
+
__decorate([
|
|
963
|
+
property({ type: Array })
|
|
964
|
+
], UvalibMap.prototype, "items", void 0);
|
|
965
|
+
__decorate([
|
|
966
|
+
property({ type: String })
|
|
967
|
+
], UvalibMap.prototype, "label", void 0);
|
|
968
|
+
__decorate([
|
|
969
|
+
property({ type: String, attribute: 'count-label' })
|
|
970
|
+
], UvalibMap.prototype, "countLabel", void 0);
|
|
971
|
+
__decorate([
|
|
972
|
+
property({ type: String, attribute: 'tile-url' })
|
|
973
|
+
], UvalibMap.prototype, "tileUrl", void 0);
|
|
974
|
+
__decorate([
|
|
975
|
+
property({ type: String, attribute: 'dark-tile-url' })
|
|
976
|
+
], UvalibMap.prototype, "darkTileUrl", void 0);
|
|
977
|
+
__decorate([
|
|
978
|
+
property({ type: String })
|
|
979
|
+
], UvalibMap.prototype, "attribution", void 0);
|
|
980
|
+
__decorate([
|
|
981
|
+
property({ type: String })
|
|
982
|
+
], UvalibMap.prototype, "center", void 0);
|
|
983
|
+
__decorate([
|
|
984
|
+
property({ type: Number })
|
|
985
|
+
], UvalibMap.prototype, "zoom", void 0);
|
|
986
|
+
__decorate([
|
|
987
|
+
property({ attribute: false })
|
|
988
|
+
], UvalibMap.prototype, "leaflet", void 0);
|
|
989
|
+
__decorate([
|
|
990
|
+
state()
|
|
991
|
+
], UvalibMap.prototype, "sourceItems", void 0);
|
|
992
|
+
__decorate([
|
|
993
|
+
state()
|
|
994
|
+
], UvalibMap.prototype, "hasLeaflet", void 0);
|
|
995
|
+
__decorate([
|
|
996
|
+
state()
|
|
997
|
+
], UvalibMap.prototype, "active", void 0);
|
|
998
|
+
__decorate([
|
|
999
|
+
state()
|
|
1000
|
+
], UvalibMap.prototype, "dark", void 0);
|
|
1001
|
+
//# sourceMappingURL=UvalibMap.js.map
|