@mattilsynet/design 2.3.7 → 3.0.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/mtds/analytics/analytics.js +16 -14
- package/mtds/analytics/analytics.js.map +1 -1
- package/mtds/app/app-observer.js +26 -26
- package/mtds/app/app-observer.js.map +1 -1
- package/mtds/atlas/atlas-element.js +3 -3
- package/mtds/atlas/atlas-element.js.map +1 -1
- package/mtds/atlas/atlas-marker.js +2 -2
- package/mtds/atlas/atlas-marker.js.map +1 -1
- package/mtds/atlas.iife.js +4 -4
- package/mtds/breadcrumbs/breadcrumbs.d.ts +9 -8
- package/mtds/breadcrumbs/breadcrumbs.js +8 -10
- package/mtds/breadcrumbs/breadcrumbs.js.map +1 -1
- package/mtds/chart/chart-element.js +41 -37
- package/mtds/chart/chart-element.js.map +1 -1
- package/mtds/chart/chart.js +45 -11
- package/mtds/chart/chart.js.map +1 -1
- package/mtds/deprecations.js +135 -0
- package/mtds/deprecations.js.map +1 -0
- package/mtds/details/details.js +18 -11
- package/mtds/details/details.js.map +1 -1
- package/mtds/errorsummary/errorsummary.d.ts +4 -2
- package/mtds/errorsummary/errorsummary.js +14 -18
- package/mtds/errorsummary/errorsummary.js.map +1 -1
- package/mtds/field/field.d.ts +34 -12
- package/mtds/field/field.js +167 -137
- package/mtds/field/field.js.map +1 -1
- package/mtds/field/field.stories.d.ts +10 -10
- package/mtds/fieldset/fieldset.js +2 -1
- package/mtds/fieldset/fieldset.js.map +1 -1
- package/mtds/icons/cosmetics.svg +1 -1
- package/mtds/icons/megaphone.svg +3 -0
- package/mtds/illustrations/car-logo.svg +1 -0
- package/mtds/illustrations/car.svg +1 -0
- package/mtds/illustrations/cheese.svg +1 -0
- package/mtds/illustrations/cloud-1.svg +1 -0
- package/mtds/illustrations/cloud-2.svg +1 -0
- package/mtds/illustrations/cloud-sun.svg +1 -0
- package/mtds/illustrations/cloud-sunshine.svg +1 -0
- package/mtds/illustrations/egg-boat.svg +1 -0
- package/mtds/illustrations/egg-half.svg +1 -0
- package/mtds/illustrations/foodtruck-logo.svg +1 -0
- package/mtds/illustrations/foodtruck.svg +1 -0
- package/mtds/illustrations/house.svg +1 -0
- package/mtds/illustrations/index.json +104 -11
- package/mtds/illustrations/paragraph.svg +1 -0
- package/mtds/illustrations/person-child-puppy.svg +1 -0
- package/mtds/illustrations/person-family-house.svg +1 -0
- package/mtds/illustrations/person-family.svg +1 -0
- package/mtds/illustrations/person-paragraph.svg +1 -0
- package/mtds/illustrations/plane-solo.svg +1 -0
- package/mtds/illustrations/sunshine.svg +1 -0
- package/mtds/illustrations/tractor.svg +1 -0
- package/mtds/illustrations/wind.svg +1 -0
- package/mtds/index.d.ts +4 -3
- package/mtds/index.iife.js +24 -22
- package/mtds/index.js +23 -37
- package/mtds/index.js.map +1 -1
- package/mtds/input/input.js +30 -24
- package/mtds/input/input.js.map +1 -1
- package/mtds/logo/logo-observer.js +11 -11
- package/mtds/logo/logo-observer.js.map +1 -1
- package/mtds/package.json.js +1 -1
- package/mtds/pagination/pagination.d.ts +19 -2
- package/mtds/pagination/pagination.js +19 -21
- package/mtds/pagination/pagination.js.map +1 -1
- package/mtds/popover/popover.d.ts +4 -0
- package/mtds/popover/popover.js +7 -6
- package/mtds/popover/popover.js.map +1 -1
- package/mtds/react-types.d.ts +1 -2
- package/mtds/styles.css +1 -1
- package/mtds/styles.json +44 -43
- package/mtds/styles.module.css.js +43 -43
- package/mtds/table/table-observer.d.ts +1 -1
- package/mtds/table/table-observer.js +17 -41
- package/mtds/table/table-observer.js.map +1 -1
- package/mtds/tabs/tabs.d.ts +10 -9
- package/mtds/tabs/tabs.js +8 -8
- package/mtds/tabs/tabs.js.map +1 -1
- package/mtds/toast/toast-observer.js +7 -7
- package/mtds/toast/toast-observer.js.map +1 -1
- package/mtds/togglegroup/togglegroup.d.ts +6 -2
- package/mtds/togglegroup/togglegroup.js +20 -19
- package/mtds/togglegroup/togglegroup.js.map +1 -1
- package/mtds/tooltip/tooltip-element.js +7 -0
- package/mtds/tooltip/tooltip-element.js.map +1 -0
- package/mtds/utils.d.ts +13 -32
- package/mtds/utils.js +47 -98
- package/mtds/utils.js.map +1 -1
- package/mtds/validation/validation-observer.js +34 -29
- package/mtds/validation/validation-observer.js.map +1 -1
- package/mtds/validation/validation.js +6 -5
- package/mtds/validation/validation.js.map +1 -1
- package/package.json +15 -14
- package/mtds/breadcrumbs/breadcrumbs-observer.js +0 -12
- package/mtds/breadcrumbs/breadcrumbs-observer.js.map +0 -1
- package/mtds/dialog/dialog-observer.js +0 -65
- package/mtds/dialog/dialog-observer.js.map +0 -1
- package/mtds/errorsummary/errorsummary-observer.d.ts +0 -1
- package/mtds/errorsummary/errorsummary-observer.js +0 -11
- package/mtds/errorsummary/errorsummary-observer.js.map +0 -1
- package/mtds/field/field-observer.d.ts +0 -1
- package/mtds/field/field-observer.js +0 -67
- package/mtds/field/field-observer.js.map +0 -1
- package/mtds/fieldset/fieldset-observer.d.ts +0 -1
- package/mtds/fieldset/fieldset-observer.js +0 -20
- package/mtds/fieldset/fieldset-observer.js.map +0 -1
- package/mtds/pagination/pagination-helper.d.ts +0 -13
- package/mtds/pagination/pagination-helper.js +0 -16
- package/mtds/pagination/pagination-helper.js.map +0 -1
- package/mtds/popover/popover-observer.d.ts +0 -1
- package/mtds/popover/popover-observer.js +0 -46
- package/mtds/popover/popover-observer.js.map +0 -1
- package/mtds/togglegroup/togglegroup-observer.d.ts +0 -1
- package/mtds/togglegroup/togglegroup-observer.js +0 -13
- package/mtds/togglegroup/togglegroup-observer.js.map +0 -1
- package/mtds/tooltip/tooltip-observer.d.ts +0 -1
- package/mtds/tooltip/tooltip-observer.js +0 -43
- package/mtds/tooltip/tooltip-observer.js.map +0 -1
- /package/mtds/{breadcrumbs/breadcrumbs-observer.d.ts → deprecations.d.ts} +0 -0
- /package/mtds/{dialog/dialog-observer.d.ts → tooltip/tooltip-element.d.ts} +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import d from "../styles.module.css.js";
|
|
2
|
-
import {
|
|
3
|
-
const S = `[data-command="toggle-app-expanded"],.${d.app.split(" ")[0]} > [command="show-modal"]`, k = `.${d.breadcrumbs.split(" ")[0]}`, T = `.${d.card.split(" ")[0]}`, u = `.${d.chip.split(" ")[0]}`, v = `.${d.helptext.split(" ")[0]}`, C = `.${d.pagination.split(" ")[0]}`, x = 'summary,u-summary,a,button,[role="tab"],[role="button"]',
|
|
2
|
+
import { onHotReload as w, isBrowser as g, tag as b, on as y, QUICK_EVENT as _, attr as s } from "../utils.js";
|
|
3
|
+
const S = `[data-command="toggle-app-expanded"],.${d.app.split(" ")[0]} > [command="show-modal"]`, k = `.${d.breadcrumbs.split(" ")[0]}`, T = `.${d.card.split(" ")[0]}`, u = `.${d.chip.split(" ")[0]}`, v = `.${d.helptext.split(" ")[0]}`, C = `.${d.pagination.split(" ")[0]}`, x = 'summary,u-summary,a,button,[role="tab"],[role="button"]', p = "mattilsynet.matomo.cloud", $ = ["setCustomUrl", "setDocumentTitle", "setReferrerUrl"], i = "mtds-analytics-banner", q = "https://www.mattilsynet.no/om-mattilsynet/personvernerklaering/informasjonskapsler";
|
|
4
4
|
function A(o, a = {}) {
|
|
5
5
|
if (g()) {
|
|
6
6
|
if (window._paq || (window._paq = [], window._paq.push(["HeatmapSessionRecording::disable"]), window._paq.push(["enableLinkTracking"]), window._paq.push(["setTrackerUrl", `https://${p}/matomo.php`])), window._mtm || (window._mtm = window._mtm || [], window._mtm.push({ "mtm.startTime": Date.now(), event: "mtm.Start" })), o === "init") {
|
|
@@ -11,7 +11,7 @@ function A(o, a = {}) {
|
|
|
11
11
|
};
|
|
12
12
|
const { consent: e, enabled: t, matomoId: n, matomoTagManagerId: r } = window._mtdsTracking;
|
|
13
13
|
if (n && window._paq.push(["setSiteId", n]), t) {
|
|
14
|
-
e !== "custom" &&
|
|
14
|
+
e !== "custom" && E();
|
|
15
15
|
const l = r ? `https://cdn.matomo.cloud/${p}/container_${r}.js` : `https://cdn.matomo.cloud/${p}/matomo.js`;
|
|
16
16
|
document.querySelector(`script[src="${l}"]`) || document.head.append(b("script", { async: "", src: l }));
|
|
17
17
|
}
|
|
@@ -39,12 +39,12 @@ function A(o, a = {}) {
|
|
|
39
39
|
window._paq.push(["trackSiteSearch", e, t, n]);
|
|
40
40
|
} else if (o === "matomo") {
|
|
41
41
|
const e = a;
|
|
42
|
-
|
|
42
|
+
$.includes(e?.[0]) && typeof e[1] != "string" && (e[1] = `${e[1] ?? ""}`), window._paq.push(e);
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
|
-
function
|
|
47
|
+
function E() {
|
|
48
48
|
if (document.getElementById(i) || window.localStorage.getItem(i)) return;
|
|
49
49
|
document.body.insertAdjacentHTML(
|
|
50
50
|
"afterbegin",
|
|
@@ -63,14 +63,14 @@ function I() {
|
|
|
63
63
|
const a = document.getElementById(i), e = () => window.localStorage.setItem(i, "seen");
|
|
64
64
|
a.addEventListener("close", e, { once: !0 }), a.show();
|
|
65
65
|
}
|
|
66
|
-
function
|
|
67
|
-
window._mtdsTracking?.enabled && setTimeout(
|
|
66
|
+
function I(o) {
|
|
67
|
+
window._mtdsTracking?.enabled && setTimeout(M, 0, o);
|
|
68
68
|
}
|
|
69
|
-
function
|
|
69
|
+
function M({ type: o, target: a }) {
|
|
70
70
|
const e = o === "click" ? a?.closest?.(x) : a;
|
|
71
71
|
if (!(e instanceof Element) || e.closest('[data-analytics="ignore"]'))
|
|
72
72
|
return;
|
|
73
|
-
let t = "click", n = "Button", r = f(e) ||
|
|
73
|
+
let t = "click", n = "Button", r = f(e) || R(e) || s(e, "data-tooltip") || "";
|
|
74
74
|
if (o === "submit")
|
|
75
75
|
n = "Form", t = "submit", r = r || document.title;
|
|
76
76
|
else if (o === "toggle") {
|
|
@@ -82,18 +82,18 @@ function B({ type: o, target: a }) {
|
|
|
82
82
|
} else if (s(e, "role") === "tab")
|
|
83
83
|
n = "Tab", t = "navigate";
|
|
84
84
|
else if (s(e, "popovertarget")) {
|
|
85
|
-
if (!
|
|
85
|
+
if (!B(e)?.matches(":popover-open")) return;
|
|
86
86
|
n = e.closest(v) ? "HelpText" : "Popover", t = "open";
|
|
87
87
|
} else if (e.nodeName.endsWith("SUMMARY")) {
|
|
88
88
|
if (!e.parentElement.open) return;
|
|
89
89
|
n = "Details", t = "open";
|
|
90
90
|
} else if (e.matches(S)) {
|
|
91
|
-
const l =
|
|
91
|
+
const l = L(e, "--mtds-tooltip-position") === "none";
|
|
92
92
|
n = "Sidebar", t = l ? "expand" : "minimize", r = l && s(e, "data-tooltip") || m(e);
|
|
93
93
|
} else if (e.closest(k))
|
|
94
94
|
n = "Breadcrumbs", t = "navigate";
|
|
95
95
|
else if (e.closest(C))
|
|
96
|
-
n = "
|
|
96
|
+
n = "Pagination", t = "navigate";
|
|
97
97
|
else if (e.closest(T))
|
|
98
98
|
n = "Card", t = e instanceof HTMLAnchorElement ? "navigate" : "click";
|
|
99
99
|
else if (e.closest(u))
|
|
@@ -112,11 +112,13 @@ function B({ type: o, target: a }) {
|
|
|
112
112
|
name: s(e, "data-analytics-name") ?? r
|
|
113
113
|
});
|
|
114
114
|
}
|
|
115
|
-
const m = (o) => o?.textContent?.trim() || "", f = (o) => o && s(o, "aria-label") || "",
|
|
115
|
+
const m = (o) => o?.textContent?.trim() || "", f = (o) => o && s(o, "aria-label") || "", B = (o) => document.getElementById(s(o, "popovertarget") || ""), L = (o, a) => window.getComputedStyle(o).getPropertyValue(a)?.trim(), R = (o) => {
|
|
116
116
|
const a = m(o), e = m(o.querySelector("h1,h2,h3,h4,h5,h6"));
|
|
117
117
|
return a.startsWith(e) && e || a.slice(0, 100).trim();
|
|
118
118
|
};
|
|
119
|
-
w(() => [
|
|
119
|
+
w("analytics", () => [
|
|
120
|
+
y(document, "click toggle submit change", I, _)
|
|
121
|
+
]);
|
|
120
122
|
export {
|
|
121
123
|
A as analytics
|
|
122
124
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"analytics.js","sources":["../../designsystem/analytics/analytics.ts"],"sourcesContent":["import styles from \"../styles.module.css\";\nimport { attr, isBrowser, on, onLoaded, QUICK_EVENT, tag } from \"../utils\";\n\n/*\n * IMPORTANT: [data-command=\"toggle-app-expanded\"] is deprecated but kept for backward compatibility.\n * Please use [command=\"show-modal\"] instead.\n */\nconst CSS_APP_TOGGLE = `[data-command=\"toggle-app-expanded\"],.${styles.app.split(\" \")[0]} > [command=\"show-modal\"]`;\nconst CSS_BREADCRUMBS = `.${styles.breadcrumbs.split(\" \")[0]}`;\nconst CSS_CARD = `.${styles.card.split(\" \")[0]}`;\nconst CSS_CHIP = `.${styles.chip.split(\" \")[0]}`;\nconst CSS_HELPTEXT = `.${styles.helptext.split(\" \")[0]}`;\nconst CSS_PAGINATION = `.${styles.pagination.split(\" \")[0]}`;\nconst CLICKS = `summary,u-summary,a,button,[role=\"tab\"],[role=\"button\"]`;\nconst EVENTS = \"click,toggle,submit,change\";\nconst MATOMO = \"mattilsynet.matomo.cloud\";\nconst MATOMO_STRINGS = [\"setCustomUrl\", \"setDocumentTitle\", \"setReferrerUrl\"];\nconst BANNER = \"mtds-analytics-banner\"; // Dialog to show Matomo script loading\nconst BANNER_URL =\n\t\"https://www.mattilsynet.no/om-mattilsynet/personvernerklaering/informasjonskapsler\";\n\ntype Matomo = (\n\t| string\n\t| number\n\t| boolean\n\t| Document\n\t| Element\n\t| ((this: Record<string, <T>() => T>) => void)\n)[];\ndeclare global {\n\tinterface Window {\n\t\t_paq?: Matomo[];\n\t\t_mtm?: Record<string, string | number>[];\n\t\t_mtdsTracking?: AnalyticsActions[\"init\"];\n\t\t_mtdsUntrack?: () => void;\n\t}\n}\n\nexport type AnalyticsActions = {\n\tinit: {\n\t\tenabled?: boolean | \"debug\";\n\t\tconsent?: \"custom\" | true;\n\t} & (\n\t\t| {\n\t\t\t\tmatomoId: number | string;\n\t\t\t\tmatomoTagManagerId?: never;\n\t\t }\n\t\t| {\n\t\t\t\tmatomoId?: number | string;\n\t\t\t\tmatomoTagManagerId: string;\n\t\t }\n\t);\n\tpageview: {\n\t\turl?: string;\n\t\ttitle?: string;\n\t};\n\tevent: {\n\t\tcategory: string;\n\t\taction: string;\n\t\tname?: string;\n\t\tvalue?: number;\n\t};\n\tsearch: {\n\t\tquery: string;\n\t\tcategory?: string;\n\t\tresults?: number;\n\t};\n\tmatomo: Matomo;\n};\n\nexport function analytics<Action extends keyof AnalyticsActions>(\n\taction: Action,\n\targs = {} as AnalyticsActions[Action],\n) {\n\tif (!isBrowser()) return;\n\tif (!window._paq) {\n\t\twindow._paq = [];\n\t\twindow._paq.push([\"HeatmapSessionRecording::disable\"]); // Disable heatmaps by default as this require cookies\n\t\twindow._paq.push([\"enableLinkTracking\"]);\n\t\twindow._paq.push([\"setTrackerUrl\", `https://${MATOMO}/matomo.php`]);\n\t}\n\tif (!window._mtm) {\n\t\twindow._mtm = window._mtm || []; // Prepare Matomo Tag Manager\n\t\twindow._mtm.push({ \"mtm.startTime\": Date.now(), event: \"mtm.Start\" });\n\t}\n\n\tif (action === \"init\") {\n\t\twindow._mtdsTracking = {\n\t\t\tenabled: window.location.hostname !== \"localhost\",\n\t\t\t...window._mtdsTracking,\n\t\t\t...args,\n\t\t} as AnalyticsActions[\"init\"];\n\t\tconst { consent, enabled, matomoId, matomoTagManagerId } =\n\t\t\twindow._mtdsTracking;\n\n\t\tif (matomoId) window._paq.push([\"setSiteId\", matomoId]);\n\t\tif (enabled) {\n\t\t\tif (consent !== \"custom\") renderBanner();\n\t\t\tconst src = matomoTagManagerId\n\t\t\t\t? `https://cdn.matomo.cloud/${MATOMO}/container_${matomoTagManagerId}.js`\n\t\t\t\t: `https://cdn.matomo.cloud/${MATOMO}/matomo.js`;\n\n\t\t\tdocument.querySelector(`script[src=\"${src}\"]`) ||\n\t\t\t\tdocument.head.append(tag(\"script\", { async: \"\", src }));\n\t\t}\n\t}\n\n\tif (window._mtdsTracking?.enabled === false) return;\n\tif (window._mtdsTracking?.enabled === \"debug\")\n\t\treturn console.info(`analytics ${action}:`, args);\n\n\tif (action === \"pageview\") {\n\t\tconst { url, title } = args as AnalyticsActions[\"pageview\"];\n\t\twindow._paq.push([\"setCustomUrl\", url || location.href]);\n\t\twindow._paq.push([\"setDocumentTitle\", title || document.title]);\n\t\twindow._paq.push([\"trackPageView\"]);\n\t} else if (action === \"event\") {\n\t\tconst { category, action, name, value } = args as AnalyticsActions[\"event\"];\n\t\tconst event = [\"trackEvent\", category, action, name, value];\n\n\t\t// We do not want to track events with hash in URL as this causes hard-to-read data,\n\t\t// so temporarily remove the hash part, and add it back after the event is pushed\n\t\tlet url = location.href;\n\t\twindow._paq.push([\n\t\t\tfunction () {\n\t\t\t\turl = this.getCurrentUrl<string>();\n\t\t\t},\n\t\t]);\n\t\twindow._paq.push([\"setCustomUrl\", url.split(\"#\")[0]]); // Skip hash part of URL\n\t\twindow._paq.push(event.filter((v) => v !== undefined)); // Push event\n\t\twindow._paq.push([\"setCustomUrl\", url]); // Reverrt to original URL with hash\n\t} else if (action === \"search\") {\n\t\tconst {\n\t\t\tquery,\n\t\t\tcategory = false,\n\t\t\tresults = false,\n\t\t} = args as AnalyticsActions[\"search\"];\n\t\twindow._paq.push([\"trackSiteSearch\", query, category, results]);\n\t} else if (action === \"matomo\") {\n\t\tconst props = args as AnalyticsActions[\"matomo\"];\n\t\tconst needStr = MATOMO_STRINGS.includes(props?.[0] as string);\n\t\tif (needStr && typeof props[1] !== \"string\") props[1] = `${props[1] ?? \"\"}`; // Matomo dies if not string\n\t\twindow._paq.push(props);\n\t}\n}\n\nfunction renderBanner() {\n\tconst hasSeenBanner =\n\t\tdocument.getElementById(BANNER) || window.localStorage.getItem(BANNER);\n\n\tif (hasSeenBanner) return;\n\n\tdocument.body.insertAdjacentHTML(\n\t\t\"afterbegin\",\n\t\t`<dialog id=\"${BANNER}\" data-analytics=\"ignore\"><style>\n\t\t\t\t#${BANNER}[open] { box-sizing: border-box; display: flex; align-items: center; background: #116e6b; border-radius: .5em; border: 0; box-shadow: 0 .25em .5em rgba(0,0,0,.3); color: #fff; font-size: .875em; inset: auto auto 1em 1em; max-width: calc(100vw - 2em); outline: 0; padding: .5em; position: fixed; z-index: 99999 }\n\t\t\t\t#${BANNER} button { all: unset; box-sizing: border-box; cursor: pointer; display: flex; width: 1.5em; height: 1.5em; font: 300 1.5em/1.35 sans-serif; border-radius: .25em; place-content: center; transition: .2s; transition-property: background, scale }\n\t\t\t\t#${BANNER} button:focus-visible { outline: 2px solid }\n\t\t\t\t#${BANNER} button:hover { background: #0a4e4f }\n\t\t\t\t#${BANNER} button:active { background: #054449; scale: .9 }\n\t\t\t\t#${BANNER} p { margin: 0 .25em }\n\t\t\t</style>\n\t\t\t<p>Vi bruker <a href=\"${BANNER_URL}\" target=\"_blank\">informasjonskapsler</a> for å forbedre brukeropplevelsen.</p>\n\t\t\t<form method=\"dialog\" data-analytics=\"ignore\"><button type=\"submit\" aria-label=\"OK\">×</button></form>\n\t\t</dialog>`,\n\t);\n\tconst banner = document.getElementById(BANNER) as HTMLDialogElement;\n\tconst onClose = () => window.localStorage.setItem(BANNER, \"seen\");\n\tbanner.addEventListener(\"close\", onClose, { once: true });\n\tbanner.show();\n}\n\nfunction handleAnalyticsTrack(event: Event) {\n\tif (window._mtdsTracking?.enabled) setTimeout(processTrack, 0, event); // Let other events process first\n}\n\nfunction processTrack({ type, target }: Event) {\n\tconst el = type === \"click\" ? (target as Element)?.closest?.(CLICKS) : target;\n\tif (!(el instanceof Element) || el.closest('[data-analytics=\"ignore\"]'))\n\t\treturn;\n\n\tlet action = \"click\";\n\tlet category = \"Button\";\n\tlet name = label(el) || heading(el) || attr(el, \"data-tooltip\") || \"\";\n\n\tif (type === \"submit\") {\n\t\tcategory = \"Form\";\n\t\taction = \"submit\";\n\t\tname = name || document.title;\n\t} else if (type === \"toggle\") {\n\t\tif (!el.matches(\"dialog:modal\")) return; // Skip non-modal dialogs\n\t\tcategory = \"Dialog\";\n\t\taction = \"open\";\n\t} else if (type === \"change\") {\n\t\tconst type = attr(el, \"type\");\n\t\tconst group =\n\t\t\ttype === \"checkbox\" || type === \"radio\" ? el.closest(\"fieldset\") : null;\n\n\t\tcategory = el.closest(CSS_CHIP) ? \"Chip\" : \"Form\";\n\t\taction = \"change\";\n\t\tname =\n\t\t\tlabel(group || el) ||\n\t\t\ttext(group?.querySelector(\"legend\")) ||\n\t\t\ttext((el as HTMLInputElement)?.labels?.[0]);\n\t} else if (attr(el, \"role\") === \"tab\") {\n\t\tcategory = \"Tab\";\n\t\taction = \"navigate\";\n\t} else if (attr(el, \"popovertarget\")) {\n\t\tif (!popover(el)?.matches(\":popover-open\")) return; // Skip if not open\n\t\tcategory = el.closest(CSS_HELPTEXT) ? \"HelpText\" : \"Popover\";\n\t\taction = \"open\";\n\t} else if (el.nodeName.endsWith(\"SUMMARY\")) {\n\t\tif (!(el.parentElement as HTMLDetailsElement).open) return; // Skip if not open\n\t\tcategory = \"Details\";\n\t\taction = \"open\";\n\t} else if (el.matches(CSS_APP_TOGGLE)) {\n\t\tconst open = style(el, \"--mtds-tooltip-position\") === \"none\";\n\t\tcategory = \"Sidebar\";\n\t\taction = open ? \"expand\" : \"minimize\";\n\t\tname = (open && attr(el, \"data-tooltip\")) || text(el);\n\t} else if (el.closest(CSS_BREADCRUMBS)) {\n\t\tcategory = \"Breadcrumbs\";\n\t\taction = \"navigate\";\n\t} else if (el.closest(CSS_PAGINATION)) {\n\t\tcategory = \"Pagintation\";\n\t\taction = \"navigate\";\n\t} else if (el.closest(CSS_CARD)) {\n\t\tcategory = \"Card\";\n\t\taction = el instanceof HTMLAnchorElement ? \"navigate\" : \"click\";\n\t} else if (el.closest(CSS_CHIP)) {\n\t\tcategory = \"Chip\";\n\t\taction = el.hasAttribute(\"data-removable\") ? \"remove\" : \"click\";\n\t} else if (el.closest(\"th[aria-sort]\")) {\n\t\tcategory = \"Table\";\n\t\taction = \"sort\";\n\t} else if (el instanceof HTMLAnchorElement) {\n\t\tcategory = \"Link\";\n\t\taction = el.protocol === \"mailto:\" ? \"email\" : \"navigate\";\n\t\tif (el.hasAttribute(\"download\")) action = \"download\";\n\t\telse if (el.hash && el.href.startsWith(location.href.split(\"#\")[0]))\n\t\t\taction = \"anchor\"; // Only track as anchor if same page\n\t} else if (el.hasAttribute(\"aria-expanded\")) {\n\t\tif (attr(el, \"aria-expanded\") !== \"true\") return; // Skip if not open\n\t\tcategory = \"Expand\";\n\t\taction = \"open\";\n\t} else if (el.nodeName.startsWith(\"MTDS-ATLAS-\")) {\n\t\tcategory = \"Map Marker\";\n\t\taction = \"open\";\n\t}\n\n\t// Respect attributes and send\n\tanalytics(\"event\", {\n\t\tcategory: attr(el, \"data-analytics-category\") ?? category,\n\t\taction: attr(el, \"data-analytics-action\") ?? action,\n\t\tname: attr(el, \"data-analytics-name\") ?? name,\n\t});\n}\n\n// Utilities\nconst text = (el?: Element | null) => el?.textContent?.trim() || \"\";\nconst label = (el?: Element | null) => (el && attr(el, \"aria-label\")) || \"\";\nconst popover = (el: Element) =>\n\tdocument.getElementById(attr(el, \"popovertarget\") || \"\");\nconst style = (el: Element, key: string) =>\n\twindow.getComputedStyle(el).getPropertyValue(key)?.trim();\nconst heading = (el: Element) => {\n\tconst body = text(el);\n\tconst head = text(el.querySelector(\"h1,h2,h3,h4,h5,h6\")); // Note: head might be empty string ''\n\treturn (body.startsWith(head) && head) || body.slice(0, 100).trim(); // Limit to 100 characters\n};\n\nonLoaded(() => [on(document, EVENTS, handleAnalyticsTrack, QUICK_EVENT)]);\n"],"names":["CSS_APP_TOGGLE","styles","CSS_BREADCRUMBS","CSS_CARD","CSS_CHIP","CSS_HELPTEXT","CSS_PAGINATION","CLICKS","EVENTS","MATOMO","MATOMO_STRINGS","BANNER","BANNER_URL","analytics","action","args","isBrowser","consent","enabled","matomoId","matomoTagManagerId","renderBanner","src","tag","url","title","category","name","value","event","v","query","results","props","banner","onClose","handleAnalyticsTrack","processTrack","type","target","el","label","heading","attr","group","text","popover","open","style","key","body","head","onLoaded","on","QUICK_EVENT"],"mappings":";;AAOA,MAAMA,IAAiB,yCAAyCC,EAAO,IAAI,MAAM,GAAG,EAAE,CAAC,CAAC,6BAClFC,IAAkB,IAAID,EAAO,YAAY,MAAM,GAAG,EAAE,CAAC,CAAC,IACtDE,IAAW,IAAIF,EAAO,KAAK,MAAM,GAAG,EAAE,CAAC,CAAC,IACxCG,IAAW,IAAIH,EAAO,KAAK,MAAM,GAAG,EAAE,CAAC,CAAC,IACxCI,IAAe,IAAIJ,EAAO,SAAS,MAAM,GAAG,EAAE,CAAC,CAAC,IAChDK,IAAiB,IAAIL,EAAO,WAAW,MAAM,GAAG,EAAE,CAAC,CAAC,IACpDM,IAAS,2DACTC,IAAS,8BACTC,IAAS,4BACTC,IAAiB,CAAC,gBAAgB,oBAAoB,gBAAgB,GACtEC,IAAS,yBACTC,IACL;AAmDM,SAASC,EACfC,GACAC,IAAO,IACN;AACD,MAAKC,KAYL;AAAA,QAXK,OAAO,SACX,OAAO,OAAO,CAAA,GACd,OAAO,KAAK,KAAK,CAAC,kCAAkC,CAAC,GACrD,OAAO,KAAK,KAAK,CAAC,oBAAoB,CAAC,GACvC,OAAO,KAAK,KAAK,CAAC,iBAAiB,WAAWP,CAAM,aAAa,CAAC,IAE9D,OAAO,SACX,OAAO,OAAO,OAAO,QAAQ,CAAA,GAC7B,OAAO,KAAK,KAAK,EAAE,iBAAiB,KAAK,IAAA,GAAO,OAAO,aAAa,IAGjEK,MAAW,QAAQ;AACtB,aAAO,gBAAgB;AAAA,QACtB,SAAS,OAAO,SAAS,aAAa;AAAA,QACtC,GAAG,OAAO;AAAA,QACV,GAAGC;AAAA,MAAA;AAEJ,YAAM,EAAE,SAAAE,GAAS,SAAAC,GAAS,UAAAC,GAAU,oBAAAC,EAAA,IACnC,OAAO;AAGR,UADID,KAAU,OAAO,KAAK,KAAK,CAAC,aAAaA,CAAQ,CAAC,GAClDD,GAAS;A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AKA,KAASD,EAAK,MAAM,GAAG,GAAG,EAAE,KAAA;AAC9D;AAEAE,EAAS,MAAM,CAACC,EAAG,UAAU7C,GAAQ4B,GAAsBkB,CAAW,CAAC,CAAC;"}
|
|
1
|
+
{"version":3,"file":"analytics.js","sources":["../../designsystem/analytics/analytics.ts"],"sourcesContent":["import styles from \"../styles.module.css\";\nimport { attr, isBrowser, on, onHotReload, QUICK_EVENT, tag } from \"../utils\";\n\n/*\n * IMPORTANT: [data-command=\"toggle-app-expanded\"] is deprecated but kept for backward compatibility.\n * Please use [command=\"show-modal\"] instead.\n */\nconst CSS_APP_TOGGLE = `[data-command=\"toggle-app-expanded\"],.${styles.app.split(\" \")[0]} > [command=\"show-modal\"]`;\nconst CSS_BREADCRUMBS = `.${styles.breadcrumbs.split(\" \")[0]}`;\nconst CSS_CARD = `.${styles.card.split(\" \")[0]}`;\nconst CSS_CHIP = `.${styles.chip.split(\" \")[0]}`;\nconst CSS_HELPTEXT = `.${styles.helptext.split(\" \")[0]}`;\nconst CSS_PAGINATION = `.${styles.pagination.split(\" \")[0]}`;\nconst CLICKS = `summary,u-summary,a,button,[role=\"tab\"],[role=\"button\"]`;\nconst MATOMO = \"mattilsynet.matomo.cloud\";\nconst MATOMO_STRINGS = [\"setCustomUrl\", \"setDocumentTitle\", \"setReferrerUrl\"];\nconst BANNER = \"mtds-analytics-banner\"; // Dialog to show Matomo script loading\nconst BANNER_URL =\n\t\"https://www.mattilsynet.no/om-mattilsynet/personvernerklaering/informasjonskapsler\";\n\ntype Matomo = (\n\t| string\n\t| number\n\t| boolean\n\t| Document\n\t| Element\n\t| ((this: Record<string, <T>() => T>) => void)\n)[];\ndeclare global {\n\tinterface Window {\n\t\t_paq?: Matomo[];\n\t\t_mtm?: Record<string, string | number>[];\n\t\t_mtdsTracking?: AnalyticsActions[\"init\"];\n\t\t_mtdsUntrack?: () => void;\n\t}\n}\n\nexport type AnalyticsActions = {\n\tinit: {\n\t\tenabled?: boolean | \"debug\";\n\t\tconsent?: \"custom\" | true;\n\t} & (\n\t\t| {\n\t\t\t\tmatomoId: number | string;\n\t\t\t\tmatomoTagManagerId?: never;\n\t\t }\n\t\t| {\n\t\t\t\tmatomoId?: number | string;\n\t\t\t\tmatomoTagManagerId: string;\n\t\t }\n\t);\n\tpageview: {\n\t\turl?: string;\n\t\ttitle?: string;\n\t};\n\tevent: {\n\t\tcategory: string;\n\t\taction: string;\n\t\tname?: string;\n\t\tvalue?: number;\n\t};\n\tsearch: {\n\t\tquery: string;\n\t\tcategory?: string;\n\t\tresults?: number;\n\t};\n\tmatomo: Matomo;\n};\n\nexport function analytics<Action extends keyof AnalyticsActions>(\n\taction: Action,\n\targs = {} as AnalyticsActions[Action],\n) {\n\tif (!isBrowser()) return;\n\tif (!window._paq) {\n\t\twindow._paq = [];\n\t\twindow._paq.push([\"HeatmapSessionRecording::disable\"]); // Disable heatmaps by default as this require cookies\n\t\twindow._paq.push([\"enableLinkTracking\"]);\n\t\twindow._paq.push([\"setTrackerUrl\", `https://${MATOMO}/matomo.php`]);\n\t}\n\tif (!window._mtm) {\n\t\twindow._mtm = window._mtm || []; // Prepare Matomo Tag Manager\n\t\twindow._mtm.push({ \"mtm.startTime\": Date.now(), event: \"mtm.Start\" });\n\t}\n\n\tif (action === \"init\") {\n\t\twindow._mtdsTracking = {\n\t\t\tenabled: window.location.hostname !== \"localhost\",\n\t\t\t...window._mtdsTracking,\n\t\t\t...args,\n\t\t} as AnalyticsActions[\"init\"];\n\t\tconst { consent, enabled, matomoId, matomoTagManagerId } =\n\t\t\twindow._mtdsTracking;\n\n\t\tif (matomoId) window._paq.push([\"setSiteId\", matomoId]);\n\t\tif (enabled) {\n\t\t\tif (consent !== \"custom\") renderBanner();\n\t\t\tconst src = matomoTagManagerId\n\t\t\t\t? `https://cdn.matomo.cloud/${MATOMO}/container_${matomoTagManagerId}.js`\n\t\t\t\t: `https://cdn.matomo.cloud/${MATOMO}/matomo.js`;\n\n\t\t\tdocument.querySelector(`script[src=\"${src}\"]`) ||\n\t\t\t\tdocument.head.append(tag(\"script\", { async: \"\", src }));\n\t\t}\n\t}\n\n\tif (window._mtdsTracking?.enabled === false) return;\n\tif (window._mtdsTracking?.enabled === \"debug\")\n\t\treturn console.info(`analytics ${action}:`, args);\n\n\tif (action === \"pageview\") {\n\t\tconst { url, title } = args as AnalyticsActions[\"pageview\"];\n\t\twindow._paq.push([\"setCustomUrl\", url || location.href]);\n\t\twindow._paq.push([\"setDocumentTitle\", title || document.title]);\n\t\twindow._paq.push([\"trackPageView\"]);\n\t} else if (action === \"event\") {\n\t\tconst { category, action, name, value } = args as AnalyticsActions[\"event\"];\n\t\tconst event = [\"trackEvent\", category, action, name, value];\n\n\t\t// We do not want to track events with hash in URL as this causes hard-to-read data,\n\t\t// so temporarily remove the hash part, and add it back after the event is pushed\n\t\tlet url = location.href;\n\t\twindow._paq.push([\n\t\t\tfunction () {\n\t\t\t\turl = this.getCurrentUrl<string>();\n\t\t\t},\n\t\t]);\n\t\twindow._paq.push([\"setCustomUrl\", url.split(\"#\")[0]]); // Skip hash part of URL\n\t\twindow._paq.push(event.filter((v) => v !== undefined)); // Push event\n\t\twindow._paq.push([\"setCustomUrl\", url]); // Reverrt to original URL with hash\n\t} else if (action === \"search\") {\n\t\tconst {\n\t\t\tquery,\n\t\t\tcategory = false,\n\t\t\tresults = false,\n\t\t} = args as AnalyticsActions[\"search\"];\n\t\twindow._paq.push([\"trackSiteSearch\", query, category, results]);\n\t} else if (action === \"matomo\") {\n\t\tconst props = args as AnalyticsActions[\"matomo\"];\n\t\tconst needStr = MATOMO_STRINGS.includes(props?.[0] as string);\n\t\tif (needStr && typeof props[1] !== \"string\") props[1] = `${props[1] ?? \"\"}`; // Matomo dies if not string\n\t\twindow._paq.push(props);\n\t}\n}\n\nfunction renderBanner() {\n\tconst hasSeenBanner =\n\t\tdocument.getElementById(BANNER) || window.localStorage.getItem(BANNER);\n\n\tif (hasSeenBanner) return;\n\n\tdocument.body.insertAdjacentHTML(\n\t\t\"afterbegin\",\n\t\t`<dialog id=\"${BANNER}\" data-analytics=\"ignore\"><style>\n\t\t\t\t#${BANNER}[open] { box-sizing: border-box; display: flex; align-items: center; background: #116e6b; border-radius: .5em; border: 0; box-shadow: 0 .25em .5em rgba(0,0,0,.3); color: #fff; font-size: .875em; inset: auto auto 1em 1em; max-width: calc(100vw - 2em); outline: 0; padding: .5em; position: fixed; z-index: 99999 }\n\t\t\t\t#${BANNER} button { all: unset; box-sizing: border-box; cursor: pointer; display: flex; width: 1.5em; height: 1.5em; font: 300 1.5em/1.35 sans-serif; border-radius: .25em; place-content: center; transition: .2s; transition-property: background, scale }\n\t\t\t\t#${BANNER} button:focus-visible { outline: 2px solid }\n\t\t\t\t#${BANNER} button:hover { background: #0a4e4f }\n\t\t\t\t#${BANNER} button:active { background: #054449; scale: .9 }\n\t\t\t\t#${BANNER} p { margin: 0 .25em }\n\t\t\t</style>\n\t\t\t<p>Vi bruker <a href=\"${BANNER_URL}\" target=\"_blank\">informasjonskapsler</a> for å forbedre brukeropplevelsen.</p>\n\t\t\t<form method=\"dialog\" data-analytics=\"ignore\"><button type=\"submit\" aria-label=\"OK\">×</button></form>\n\t\t</dialog>`,\n\t);\n\tconst banner = document.getElementById(BANNER) as HTMLDialogElement;\n\tconst onClose = () => window.localStorage.setItem(BANNER, \"seen\");\n\tbanner.addEventListener(\"close\", onClose, { once: true });\n\tbanner.show();\n}\n\nfunction handleAnalyticsTrack(event: Event) {\n\tif (window._mtdsTracking?.enabled) setTimeout(processTrack, 0, event); // Let other events process first\n}\n\nfunction processTrack({ type, target }: Event) {\n\tconst el = type === \"click\" ? (target as Element)?.closest?.(CLICKS) : target;\n\tif (!(el instanceof Element) || el.closest('[data-analytics=\"ignore\"]'))\n\t\treturn;\n\n\tlet action = \"click\";\n\tlet category = \"Button\";\n\tlet name = label(el) || heading(el) || attr(el, \"data-tooltip\") || \"\";\n\n\tif (type === \"submit\") {\n\t\tcategory = \"Form\";\n\t\taction = \"submit\";\n\t\tname = name || document.title;\n\t} else if (type === \"toggle\") {\n\t\tif (!el.matches(\"dialog:modal\")) return; // Skip non-modal dialogs\n\t\tcategory = \"Dialog\";\n\t\taction = \"open\";\n\t} else if (type === \"change\") {\n\t\tconst type = attr(el, \"type\");\n\t\tconst group =\n\t\t\ttype === \"checkbox\" || type === \"radio\" ? el.closest(\"fieldset\") : null;\n\n\t\tcategory = el.closest(CSS_CHIP) ? \"Chip\" : \"Form\";\n\t\taction = \"change\";\n\t\tname =\n\t\t\tlabel(group || el) ||\n\t\t\ttext(group?.querySelector(\"legend\")) ||\n\t\t\ttext((el as HTMLInputElement)?.labels?.[0]);\n\t} else if (attr(el, \"role\") === \"tab\") {\n\t\tcategory = \"Tab\";\n\t\taction = \"navigate\";\n\t} else if (attr(el, \"popovertarget\")) {\n\t\tif (!popover(el)?.matches(\":popover-open\")) return; // Skip if not open\n\t\tcategory = el.closest(CSS_HELPTEXT) ? \"HelpText\" : \"Popover\";\n\t\taction = \"open\";\n\t} else if (el.nodeName.endsWith(\"SUMMARY\")) {\n\t\tif (!(el.parentElement as HTMLDetailsElement).open) return; // Skip if not open\n\t\tcategory = \"Details\";\n\t\taction = \"open\";\n\t} else if (el.matches(CSS_APP_TOGGLE)) {\n\t\tconst open = style(el, \"--mtds-tooltip-position\") === \"none\";\n\t\tcategory = \"Sidebar\";\n\t\taction = open ? \"expand\" : \"minimize\";\n\t\tname = (open && attr(el, \"data-tooltip\")) || text(el);\n\t} else if (el.closest(CSS_BREADCRUMBS)) {\n\t\tcategory = \"Breadcrumbs\";\n\t\taction = \"navigate\";\n\t} else if (el.closest(CSS_PAGINATION)) {\n\t\tcategory = \"Pagination\";\n\t\taction = \"navigate\";\n\t} else if (el.closest(CSS_CARD)) {\n\t\tcategory = \"Card\";\n\t\taction = el instanceof HTMLAnchorElement ? \"navigate\" : \"click\";\n\t} else if (el.closest(CSS_CHIP)) {\n\t\tcategory = \"Chip\";\n\t\taction = el.hasAttribute(\"data-removable\") ? \"remove\" : \"click\";\n\t} else if (el.closest(\"th[aria-sort]\")) {\n\t\tcategory = \"Table\";\n\t\taction = \"sort\";\n\t} else if (el instanceof HTMLAnchorElement) {\n\t\tcategory = \"Link\";\n\t\taction = el.protocol === \"mailto:\" ? \"email\" : \"navigate\";\n\t\tif (el.hasAttribute(\"download\")) action = \"download\";\n\t\telse if (el.hash && el.href.startsWith(location.href.split(\"#\")[0]))\n\t\t\taction = \"anchor\"; // Only track as anchor if same page\n\t} else if (el.hasAttribute(\"aria-expanded\")) {\n\t\tif (attr(el, \"aria-expanded\") !== \"true\") return; // Skip if not open\n\t\tcategory = \"Expand\";\n\t\taction = \"open\";\n\t} else if (el.nodeName.startsWith(\"MTDS-ATLAS-\")) {\n\t\tcategory = \"Map Marker\";\n\t\taction = \"open\";\n\t}\n\n\t// Respect attributes and send\n\tanalytics(\"event\", {\n\t\tcategory: attr(el, \"data-analytics-category\") ?? category,\n\t\taction: attr(el, \"data-analytics-action\") ?? action,\n\t\tname: attr(el, \"data-analytics-name\") ?? name,\n\t});\n}\n\n// Utilities\nconst text = (el?: Element | null) => el?.textContent?.trim() || \"\";\nconst label = (el?: Element | null) => (el && attr(el, \"aria-label\")) || \"\";\nconst popover = (el: Element) =>\n\tdocument.getElementById(attr(el, \"popovertarget\") || \"\");\nconst style = (el: Element, key: string) =>\n\twindow.getComputedStyle(el).getPropertyValue(key)?.trim();\nconst heading = (el: Element) => {\n\tconst body = text(el);\n\tconst head = text(el.querySelector(\"h1,h2,h3,h4,h5,h6\")); // Note: head might be empty string ''\n\treturn (body.startsWith(head) && head) || body.slice(0, 100).trim(); // Limit to 100 characters\n};\n\nonHotReload(\"analytics\", () => [\n\ton(document, \"click toggle submit change\", handleAnalyticsTrack, QUICK_EVENT),\n]);\n"],"names":["CSS_APP_TOGGLE","styles","CSS_BREADCRUMBS","CSS_CARD","CSS_CHIP","CSS_HELPTEXT","CSS_PAGINATION","CLICKS","MATOMO","MATOMO_STRINGS","BANNER","BANNER_URL","analytics","action","args","isBrowser","consent","enabled","matomoId","matomoTagManagerId","renderBanner","src","tag","url","title","category","name","value","event","v","query","results","props","banner","onClose","handleAnalyticsTrack","processTrack","type","target","el","label","heading","attr","group","text","popover","open","style","key","body","head","onHotReload","on","QUICK_EVENT"],"mappings":";;AAOA,MAAMA,IAAiB,yCAAyCC,EAAO,IAAI,MAAM,GAAG,EAAE,CAAC,CAAC,6BAClFC,IAAkB,IAAID,EAAO,YAAY,MAAM,GAAG,EAAE,CAAC,CAAC,IACtDE,IAAW,IAAIF,EAAO,KAAK,MAAM,GAAG,EAAE,CAAC,CAAC,IACxCG,IAAW,IAAIH,EAAO,KAAK,MAAM,GAAG,EAAE,CAAC,CAAC,IACxCI,IAAe,IAAIJ,EAAO,SAAS,MAAM,GAAG,EAAE,CAAC,CAAC,IAChDK,IAAiB,IAAIL,EAAO,WAAW,MAAM,GAAG,EAAE,CAAC,CAAC,IACpDM,IAAS,2DACTC,IAAS,4BACTC,IAAiB,CAAC,gBAAgB,oBAAoB,gBAAgB,GACtEC,IAAS,yBACTC,IACL;AAmDM,SAASC,EACfC,GACAC,IAAO,IACN;AACD,MAAKC,KAYL;AAAA,QAXK,OAAO,SACX,OAAO,OAAO,CAAA,GACd,OAAO,KAAK,KAAK,CAAC,kCAAkC,CAAC,GACrD,OAAO,KAAK,KAAK,CAAC,oBAAoB,CAAC,GACvC,OAAO,KAAK,KAAK,CAAC,iBAAiB,WAAWP,CAAM,aAAa,CAAC,IAE9D,OAAO,SACX,OAAO,OAAO,OAAO,QAAQ,CAAA,GAC7B,OAAO,KAAK,KAAK,EAAE,iBAAiB,KAAK,IAAA,GAAO,OAAO,aAAa,IAGjEK,MAAW,QAAQ;AACtB,aAAO,gBAAgB;AAAA,QACtB,SAAS,OAAO,SAAS,aAAa;AAAA,QACtC,GAAG,OAAO;AAAA,QACV,GAAGC;AAAA,MAAA;AAEJ,YAAM,EAAE,SAAAE,GAAS,SAAAC,GAAS,UAAAC,GAAU,oBAAAC,EAA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AKL,CAAE,GACdW,IAAON,EAAKL,EAAG,cAAc,mBAAmB,CAAC;AACvD,SAAQU,EAAK,WAAWC,CAAI,KAAKA,KAASD,EAAK,MAAM,GAAG,GAAG,EAAE,KAAA;AAC9D;AAEAE,EAAY,aAAa,MAAM;AAAA,EAC9BC,EAAG,UAAU,8BAA8BjB,GAAsBkB,CAAW;AAC7E,CAAC;"}
|
package/mtds/app/app-observer.js
CHANGED
|
@@ -1,40 +1,40 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
1
|
+
import P from "../styles.module.css.js";
|
|
2
|
+
import { getByCSSModule as _, onHotReload as h, on as r, QUICK_EVENT as m, debounce as E } from "../utils.js";
|
|
3
3
|
import "./app-toggle2.js";
|
|
4
|
-
const y =
|
|
5
|
-
document.startViewTransition ? document.startViewTransition(
|
|
6
|
-
},
|
|
4
|
+
const y = P.app.split(" ")[0], I = `[data-command="toggle-app-expanded"],.${y} > [command="show-modal"]`, u = `.${y} > dialog,.${y} dialog ~ main`, S = _("sticky"), w = (t) => {
|
|
5
|
+
document.startViewTransition ? document.startViewTransition(t) : t();
|
|
6
|
+
}, x = (t) => (
|
|
7
7
|
// @ts-expect-error window.mtdsAppToggle comes from app-toggle.js
|
|
8
|
-
|
|
8
|
+
w(() => window.mtdsToggleAppExpanded?.(t))
|
|
9
9
|
);
|
|
10
|
-
function
|
|
11
|
-
const { target: o, defaultPrevented:
|
|
12
|
-
if (
|
|
13
|
-
return
|
|
14
|
-
if (
|
|
10
|
+
function H(t) {
|
|
11
|
+
const { target: o, defaultPrevented: l } = t, f = o?.closest?.("a");
|
|
12
|
+
if (f?.closest("dialog") && f?.closest(u))
|
|
13
|
+
return C();
|
|
14
|
+
if (l || !(o instanceof HTMLButtonElement) || !o.matches(I))
|
|
15
15
|
return;
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
const
|
|
19
|
-
|
|
16
|
+
const T = getComputedStyle(o).position === "sticky";
|
|
17
|
+
t.preventDefault(), T ? x() : w(() => {
|
|
18
|
+
const g = document.querySelector(u);
|
|
19
|
+
g?.setAttribute("closedby", "any"), g?.showModal();
|
|
20
20
|
});
|
|
21
21
|
}
|
|
22
|
-
function
|
|
23
|
-
document.querySelector(
|
|
22
|
+
function C() {
|
|
23
|
+
document.querySelector(u)?.close();
|
|
24
24
|
}
|
|
25
|
-
let p = 0, n,
|
|
26
|
-
function
|
|
25
|
+
let p = 0, n, e = 0, c = 0, i = 0, d = !1, a = 0, s = 0;
|
|
26
|
+
function k() {
|
|
27
27
|
if (!S?.length) return;
|
|
28
|
-
const
|
|
29
|
-
s = o,
|
|
28
|
+
const t = S[0], o = window.scrollY, l = o < s;
|
|
29
|
+
s = o, l !== n && (p = (t.parentElement?.getBoundingClientRect().top || 0) + s, n = l, c = t.offsetHeight, i = t.getBoundingClientRect().top + s, d = t.offsetHeight <= window.innerHeight, a = window.innerHeight), !(e === -1 && d) && (e !== -1 && (d || n && s <= i) ? (t.style.setProperty("--pos", "sticky"), t.style.setProperty("--top", "0px"), e = -1) : e === -1 && !n ? (t.style.setProperty("--pos", "relative"), t.style.setProperty("--top", `${Math.max(0, s - p)}px`), e = 0) : e !== 1 && !n && s + a >= i + c ? (t.style.setProperty("--pos", "sticky"), t.style.setProperty("--top", `${a - c}px`), e = 1) : e === 1 && n && (t.style.setProperty("--pos", "relative"), t.style.setProperty("--top", `${i - p}px`), e = 0));
|
|
30
30
|
}
|
|
31
|
-
|
|
32
|
-
r(document, "click",
|
|
31
|
+
h("app", () => [
|
|
32
|
+
r(document, "click", H, !0),
|
|
33
33
|
// Use capture to run before other click handlers
|
|
34
|
-
r(window, "resize",
|
|
35
|
-
r(window, "scroll",
|
|
34
|
+
r(window, "resize", E(C, 100), m),
|
|
35
|
+
r(window, "scroll", k, m)
|
|
36
36
|
]);
|
|
37
37
|
export {
|
|
38
|
-
|
|
38
|
+
x as toggleAppExpanded
|
|
39
39
|
};
|
|
40
40
|
//# sourceMappingURL=app-observer.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app-observer.js","sources":["../../designsystem/app/app-observer.ts"],"sourcesContent":["import styles from \"../styles.module.css\";\nimport {
|
|
1
|
+
{"version":3,"file":"app-observer.js","sources":["../../designsystem/app/app-observer.ts"],"sourcesContent":["import styles from \"../styles.module.css\";\nimport {\n\tdebounce,\n\tgetByCSSModule,\n\ton,\n\tonHotReload,\n\tQUICK_EVENT,\n} from \"../utils\";\nimport \"./app-toggle\";\n\nconst CSS_APP = styles.app.split(\" \")[0];\nconst CSS_TOGGLE = `[data-command=\"toggle-app-expanded\"],.${CSS_APP} > [command=\"show-modal\"]`;\nconst CSS_SIDEBAR = `.${CSS_APP} > dialog,.${CSS_APP} dialog ~ main`;\nconst STICKIES = getByCSSModule(\"sticky\");\n\nconst useTransition = (callback: () => void) => {\n\tif (!document.startViewTransition) callback();\n\telse document.startViewTransition(callback);\n};\n\nexport const toggleAppExpanded = (force?: boolean) =>\n\t// @ts-expect-error window.mtdsAppToggle comes from app-toggle.js\n\tuseTransition(() => window.mtdsToggleAppExpanded?.(force));\n\nfunction handleAppToggleClick(event: Event) {\n\tconst { target: el, defaultPrevented: stop } = event;\n\tconst link = (el as Element)?.closest?.(\"a\");\n\tif (link?.closest(\"dialog\") && link?.closest(CSS_SIDEBAR))\n\t\treturn closeSidebar(); // Close sidebar if link is clicked inside sidebar\n\n\tif (stop || !(el instanceof HTMLButtonElement) || !el.matches(CSS_TOGGLE))\n\t\treturn;\n\tconst isDesktop = getComputedStyle(el).position === \"sticky\";\n\tevent.preventDefault(); // Prevent default Invoker Command action so we can animate\n\n\tif (isDesktop) toggleAppExpanded();\n\telse\n\t\tuseTransition(() => {\n\t\t\tconst sidebar = document.querySelector<HTMLDialogElement>(CSS_SIDEBAR);\n\t\t\tsidebar?.setAttribute(\"closedby\", \"any\"); // Allow closing by clicking outside\n\t\t\tsidebar?.showModal();\n\t\t});\n}\n\nfunction closeSidebar() {\n\tdocument.querySelector<HTMLDialogElement>(CSS_SIDEBAR)?.close();\n}\n\n// Scroll state\nlet MIN_Y = 0; // Offset to avoid scroll jump when sticky is set to relative\nlet SCROLL_UP: boolean;\nlet STICK = 0; // -1 = stick top, 0 = relative, 1 = stick bottom\nlet STICK_H = 0;\nlet STICK_Y = 0;\nlet STUCK = false; // Used to figure if nav is larger than viewport\nlet WIN_H = 0;\nlet WIN_Y = 0;\n\nfunction handleAppScroll() {\n\tif (!STICKIES?.length) return;\n\tconst el = STICKIES[0] as HTMLElement;\n\tconst NEXT_Y = window.scrollY;\n\tconst NEXT_UP = NEXT_Y < WIN_Y;\n\tWIN_Y = NEXT_Y;\n\n\t// Only calculate if scroll direction has changed\n\tif (NEXT_UP !== SCROLL_UP) {\n\t\tMIN_Y = (el.parentElement?.getBoundingClientRect().top || 0) + WIN_Y;\n\t\tSCROLL_UP = NEXT_UP;\n\t\tSTICK_H = el.offsetHeight;\n\t\tSTICK_Y = el.getBoundingClientRect().top + WIN_Y;\n\t\tSTUCK = el.offsetHeight <= window.innerHeight;\n\t\tWIN_H = window.innerHeight;\n\t}\n\n\tif (STICK === -1 && STUCK) return; // Allways sticky when sidebar is smaller than viewport\n\tif (STICK !== -1 && (STUCK || (SCROLL_UP && WIN_Y <= STICK_Y))) {\n\t\tel.style.setProperty(\"--pos\", \"sticky\");\n\t\tel.style.setProperty(\"--top\", \"0px\");\n\t\tSTICK = -1; // Not sticking to top and sidebar is smaller than viewport or scrolling up\n\t} else if (STICK === -1 && !SCROLL_UP) {\n\t\tel.style.setProperty(\"--pos\", \"relative\");\n\t\tel.style.setProperty(\"--top\", `${Math.max(0, WIN_Y - MIN_Y)}px`);\n\t\tSTICK = 0; // Sticking to top and scrolling down\n\t} else if (STICK !== 1 && !SCROLL_UP && WIN_Y + WIN_H >= STICK_Y + STICK_H) {\n\t\tel.style.setProperty(\"--pos\", \"sticky\");\n\t\tel.style.setProperty(\"--top\", `${WIN_H - STICK_H}px`);\n\t\tSTICK = 1; // Not sticking to bottom and scrolling down\n\t} else if (STICK === 1 && SCROLL_UP) {\n\t\tel.style.setProperty(\"--pos\", \"relative\");\n\t\tel.style.setProperty(\"--top\", `${STICK_Y - MIN_Y}px`);\n\t\tSTICK = 0; // Sticking to bottom and scrolling up\n\t}\n}\n\nonHotReload(\"app\", () => [\n\ton(document, \"click\", handleAppToggleClick, true), // Use capture to run before other click handlers\n\ton(window, \"resize\", debounce(closeSidebar, 100), QUICK_EVENT),\n\ton(window, \"scroll\", handleAppScroll, QUICK_EVENT),\n]);\n"],"names":["CSS_APP","styles","CSS_TOGGLE","CSS_SIDEBAR","STICKIES","getByCSSModule","useTransition","callback","toggleAppExpanded","force","handleAppToggleClick","event","el","stop","link","closeSidebar","isDesktop","sidebar","MIN_Y","SCROLL_UP","STICK","STICK_H","STICK_Y","STUCK","WIN_H","WIN_Y","handleAppScroll","NEXT_Y","NEXT_UP","onHotReload","on","debounce","QUICK_EVENT"],"mappings":";;;AAUA,MAAMA,IAAUC,EAAO,IAAI,MAAM,GAAG,EAAE,CAAC,GACjCC,IAAa,yCAAyCF,CAAO,6BAC7DG,IAAc,IAAIH,CAAO,cAAcA,CAAO,kBAC9CI,IAAWC,EAAe,QAAQ,GAElCC,IAAgB,CAACC,MAAyB;AAC/C,EAAK,SAAS,sBACT,SAAS,oBAAoBA,CAAQ,IADPA,EAAA;AAEpC,GAEaC,IAAoB,CAACC;AAAA;AAAA,EAEjCH,EAAc,MAAM,OAAO,wBAAwBG,CAAK,CAAC;AAAA;AAE1D,SAASC,EAAqBC,GAAc;AAC3C,QAAM,EAAE,QAAQC,GAAI,kBAAkBC,MAASF,GACzCG,IAAQF,GAAgB,UAAU,GAAG;AAC3C,MAAIE,GAAM,QAAQ,QAAQ,KAAKA,GAAM,QAAQX,CAAW;AACvD,WAAOY,EAAA;AAER,MAAIF,KAAQ,EAAED,aAAc,sBAAsB,CAACA,EAAG,QAAQV,CAAU;AACvE;AACD,QAAMc,IAAY,iBAAiBJ,CAAE,EAAE,aAAa;AACpD,EAAAD,EAAM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MAAM,YAAY,SAAS,GAAGU,IAAUJ,CAAK,IAAI,GACpDE,IAAQ;AAEV;AAEAS,EAAY,OAAO,MAAM;AAAA,EACxBC,EAAG,UAAU,SAASpB,GAAsB,EAAI;AAAA;AAAA,EAChDoB,EAAG,QAAQ,UAAUC,EAAShB,GAAc,GAAG,GAAGiB,CAAW;AAAA,EAC7DF,EAAG,QAAQ,UAAUJ,GAAiBM,CAAW;AAClD,CAAC;"}
|
|
@@ -24,7 +24,7 @@ class m extends C {
|
|
|
24
24
|
"style",
|
|
25
25
|
null,
|
|
26
26
|
`@layer leaflet{${f}}
|
|
27
|
-
@layer mt.
|
|
27
|
+
@layer mt.v3-0-0design{${b}`
|
|
28
28
|
),
|
|
29
29
|
r("figure")
|
|
30
30
|
);
|
|
@@ -42,7 +42,7 @@ class m extends C {
|
|
|
42
42
|
layers: [e],
|
|
43
43
|
zoomControl: !1,
|
|
44
44
|
zoomSnap: 0.2
|
|
45
|
-
}), v(this, "pointerup
|
|
45
|
+
}), v(this, "pointerup click", this.#t), this.map.addControl(new i.Control.Attribution({ prefix: "" })), this.map.addControl(new i.Control.Zoom({ position: "bottomright" })), this.map.on("popupopen popupclose", this.#e, this), this.cluster = new i.MarkerClusterGroup({
|
|
46
46
|
zoomToBoundsOnClick: !0,
|
|
47
47
|
showCoverageOnHover: !1,
|
|
48
48
|
disableClusteringAtZoom: o === "false" ? 1 : Number(o) || d + 1,
|
|
@@ -71,7 +71,7 @@ class m extends C {
|
|
|
71
71
|
return this.map?.pointerEventToLatLng({ clientX: t, clientY: o });
|
|
72
72
|
}
|
|
73
73
|
disconnectedCallback() {
|
|
74
|
-
w(this, "pointerup
|
|
74
|
+
w(this, "pointerup click", this.#t), this.map?.remove(), this.map = this.cluster = void 0;
|
|
75
75
|
}
|
|
76
76
|
async getCollections() {
|
|
77
77
|
return window._matgeoCollections || Promise.resolve({});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"atlas-element.js","sources":["../../designsystem/atlas/atlas-element.ts"],"sourcesContent":["import L from \"leaflet\";\nimport LeafletCSS from \"leaflet/dist/leaflet.css?raw\";\nimport type {} from \"leaflet.markercluster\"; // Extend L namespace\nimport \"./cluster.js\";\nimport {\n\tattr,\n\tdefineElement,\n\tisBrowser,\n\tMTDSElement,\n\toff,\n\ton,\n\ttag,\n} from \"../utils\";\nimport css from \"./atlas.css?raw\";\nexport { L };\nexport { MTDSAtlasMarkerElement } from \"./atlas-marker\";\nexport { MTDSAtlasMatgeoElement } from \"./atlas-matgeo\";\nexport { MTDSAtlasWMSElement } from \"./atlas-wms\";\n\n// TODO: Add minimum zoom level for adding markers (minimum 17 som standard?)\n// TODO: Add search helper (https://ws.geonorge.no/adresser/v1/openapi.json + https://ws.geonorge.no/adresser/v1/#/default/get_sok)\n// TODO: matgeo-autoload popover info\n\ntype Link = { href: string; rel: string; type: string; title: string };\ntype BBox = [number, number, number, number];\nexport type MTDSAtlasCollections = Record<string, MTDSAtlasCollection>;\nexport type MTDSAtlasCollection = {\n\tcrs: string[];\n\tdescription: string;\n\textent: { spatial: { bbox: BBox[] } };\n\tgeometry: string;\n\tid: string;\n\titemType: string;\n\tlinks: Link[];\n\ttitle: string;\n};\n\ndeclare global {\n\tinterface HTMLElementTagNameMap {\n\t\t\"mtds-atlas\": MTDSAtlasElement;\n\t}\n\n\tinterface Window {\n\t\t_matgeoCollections?: Promise<MTDSAtlasCollections>;\n\t}\n}\n\nlet SKIP_CLICK: number | NodeJS.Timeout = 0;\nconst KARTVERKET_MAX_ZOOM = 18; // Kartverket does not support more than zoom level 18\nconst KARTVERKET_TILES_URL =\n\t\"https://cache.kartverket.no/v1/wmts/1.0.0/topo/default/webmercator/{z}/{y}/{x}.png\";\nexport const MATGEO_URL =\n\t\"https://matgeoservice-256616427209.europe-north1.run.app/ogc/features/collections\";\nconst BOUNDS_NORWAY: L.LatLngBoundsLiteral = [\n\t[57.5, 4.73],\n\t[71.5, 31.44],\n];\n\nif (isBrowser() && !window._matgeoCollections)\n\twindow._matgeoCollections = fetch(MATGEO_URL)\n\t\t.then((res) => res.json())\n\t\t.then((d) => d.collections.map((c: MTDSAtlasCollection) => [c.id, c]))\n\t\t.then(Object.fromEntries);\n\nexport class MTDSAtlasElement extends MTDSElement {\n\tcluster?: L.MarkerClusterGroup;\n\tmap?: L.Map;\n\n\tstatic get observedAttributes() {\n\t\treturn [\"data-view\", \"data-scrollzoom\"]; // Using ES2015 syntax for backwards compatibility\n\t}\n\tconstructor() {\n\t\tsuper();\n\t\tthis.attachShadow({ mode: \"open\" }).append(\n\t\t\ttag(\n\t\t\t\t\"style\",\n\t\t\t\tnull,\n\t\t\t\t`@layer leaflet{${LeafletCSS}}\\n@layer mt.design{${css}`,\n\t\t\t),\n\t\t\ttag(\"figure\"),\n\t\t);\n\t}\n\tconnectedCallback() {\n\t\tconst container = this.shadowRoot?.lastElementChild as HTMLElement;\n\t\tconst cluster = attr(this, \"data-cluster\") ?? \"false\";\n\t\tconst tiles = new L.TileLayer(KARTVERKET_TILES_URL, {\n\t\t\tattribution: \"© Kartverket\",\n\t\t\tclassName: \"leaflet-kartverket-tiles\",\n\t\t\tmaxZoom: KARTVERKET_MAX_ZOOM,\n\t\t});\n\n\t\tthis.map = new L.Map(container, {\n\t\t\tattributionControl: false,\n\t\t\tfadeAnimation: false, // Prevent popup fades\n\t\t\tlayers: [tiles],\n\t\t\tzoomControl: false,\n\t\t\tzoomSnap: 0.2,\n\t\t});\n\n\t\ton(this, \"pointerup,click\", this.#skipClick); // Prevent clicks from bubbling up unless sent from Leaflet\n\t\tthis.map.addControl(new L.Control.Attribution({ prefix: \"\" }));\n\t\tthis.map.addControl(new L.Control.Zoom({ position: \"bottomright\" }));\n\t\tthis.map.on(\"popupopen popupclose\", this.#handlePopup, this);\n\t\tthis.cluster = new L.MarkerClusterGroup({\n\t\t\tzoomToBoundsOnClick: true,\n\t\t\tshowCoverageOnHover: false,\n\t\t\tdisableClusteringAtZoom:\n\t\t\t\tcluster === \"false\" ? 1 : Number(cluster) || KARTVERKET_MAX_ZOOM + 1,\n\t\t\ticonCreateFunction: (cluster: L.MarkerCluster) =>\n\t\t\t\tnew L.DivIcon({\n\t\t\t\t\thtml: `${cluster.getChildCount()}`,\n\t\t\t\t\tclassName: \"leaflet-cluster-icon\",\n\t\t\t\t\ticonSize: [30, 30],\n\t\t\t\t}),\n\t\t}).addTo(this.map);\n\n\t\t// Initial setup attributes\n\t\tfor (const name of MTDSAtlasElement.observedAttributes)\n\t\t\tthis.attributeChangedCallback(name, null, attr(this, name));\n\t}\n\tattributeChangedCallback(name: string, _prev?: null, next?: string | null) {\n\t\tif (name === \"data-view\") this.setView(next || \"\");\n\t\tif (name === \"data-scrollzoom\")\n\t\t\tthis.map?.scrollWheelZoom[next === \"false\" ? \"disable\" : \"enable\"]();\n\t}\n\tsetView(view: string | number[], opts?: L.FitBoundsOptions) {\n\t\tconst p = `${view}`.split(\",\").map(parseFloat).filter(Number.isFinite);\n\t\tconst b = this.cluster?.getBounds();\n\n\t\tif (p.length === 3) return this.map?.setView([p[0], p[1]], p[2], opts);\n\t\tif (view !== \"fit\") return this.map?.fitBounds(BOUNDS_NORWAY, opts);\n\t\tif (b?.isValid()) return this.map?.fitBounds(b.pad(0.1), opts);\n\t\tthis.cluster?.once(\"layeradd\", () => {\n\t\t\tsetTimeout(() => this.setView(\"fit\"), 50); // Add all markers before fitting\n\t\t});\n\t}\n\tlatLngFromPoint(x: number, y: number) {\n\t\t// @ts-expect-error -- Missing from Leaflet@2.0.0-alpha.1 types\n\t\treturn this.map?.pointerEventToLatLng({ clientX: x, clientY: y });\n\t}\n\tdisconnectedCallback() {\n\t\toff(this, \"pointerup,click\", this.#skipClick);\n\t\tthis.map?.remove();\n\t\tthis.map = this.cluster = undefined;\n\t}\n\tasync getCollections() {\n\t\treturn (\n\t\t\twindow._matgeoCollections || Promise.resolve({} as MTDSAtlasCollections)\n\t\t);\n\t}\n\t#handlePopup({ type, popup }: { type: string; popup: L.Popup }) {\n\t\tconst open = type === \"popupopen\";\n\t\tconst cont = popup.getElement()?.querySelector(\".leaflet-popup-content\");\n\t\tconst slot = cont?.querySelector<HTMLSlotElement>(\":scope > slot\");\n\t\tconst id = cont?.textContent?.match(/^#(\\S+)/)?.[1] || \"\";\n\t\tconst el = document.getElementById(slot?.name || id); // If content of popup is #id, replace with <slot>\n\n\t\tif (!el) return open && id && popup.close(); // Close popup if target element not found\n\t\tL.Util.setOptions(popup, { maxWidth: this.offsetWidth - 40 });\n\t\tattr(el, \"data-popover\", open ? attr(el, \"popover\") : null); // Store previous popover mode\n\t\tattr(el, \"popover\", open ? null : attr(el, \"data-popover\")); // But temporarily remove it so popover renders\n\t\tattr(el, \"slot\", open ? el.id : null); // Render popover in slot\n\t\tif (open) popup.setContent(tag(\"slot\", { name: el.id }));\n\t}\n\t#skipClick(event: Partial<MouseEvent>) {\n\t\tif (event.type === \"click\") SKIP_CLICK && event.stopPropagation?.();\n\t\telse if (document.body.classList.contains(\"leaflet-dragging\"))\n\t\t\tSKIP_CLICK = setTimeout(() => {\n\t\t\t\tSKIP_CLICK = 0;\n\t\t\t}, 50); // Was dragging, so skip succeeding click\n\t}\n}\n\ndefineElement(\"mtds-atlas\", MTDSAtlasElement);\n\nif (isBrowser())\n\tL.Marker.prototype.options.icon = new L.DivIcon({\n\t\thtml: '<div class=\"leaflet-marker-generated-slot\"><div class=\"leaflet-marker-generated-icon\"></div></div>',\n\t\ticonSize: [0, 0],\n\t});\n"],"names":["SKIP_CLICK","KARTVERKET_MAX_ZOOM","KARTVERKET_TILES_URL","MATGEO_URL","BOUNDS_NORWAY","isBrowser","res","d","c","MTDSAtlasElement","MTDSElement","tag","LeafletCSS","css","container","cluster","attr","tiles","L","on","#skipClick","#handlePopup","name","_prev","next","view","opts","p","b","x","y","off","type","popup","open","cont","slot","id","el","event","defineElement"],"mappings":";;;;;;;;AA+CA,IAAIA,IAAsC;AAC1C,MAAMC,IAAsB,IACtBC,IACL,sFACYC,IACZ,qFACKC,IAA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AEAwC,EAAc,cAAc/B,CAAgB;AAExCJ,EAAA,MACHa,EAAE,OAAO,UAAU,QAAQ,OAAO,IAAIA,EAAE,QAAQ;AAAA,EAC/C,MAAM;AAAA,EACN,UAAU,CAAC,GAAG,CAAC;AAAA,CACf;"}
|
|
1
|
+
{"version":3,"file":"atlas-element.js","sources":["../../designsystem/atlas/atlas-element.ts"],"sourcesContent":["import L from \"leaflet\";\nimport LeafletCSS from \"leaflet/dist/leaflet.css?raw\";\nimport type {} from \"leaflet.markercluster\"; // Extend L namespace\nimport \"./cluster.js\";\nimport {\n\tattr,\n\tdefineElement,\n\tisBrowser,\n\tMTDSElement,\n\toff,\n\ton,\n\ttag,\n} from \"../utils\";\nimport css from \"./atlas.css?raw\";\nexport { L };\nexport { MTDSAtlasMarkerElement } from \"./atlas-marker\";\nexport { MTDSAtlasMatgeoElement } from \"./atlas-matgeo\";\nexport { MTDSAtlasWMSElement } from \"./atlas-wms\";\n\n// TODO: Add minimum zoom level for adding markers (minimum 17 som standard?)\n// TODO: Add search helper (https://ws.geonorge.no/adresser/v1/openapi.json + https://ws.geonorge.no/adresser/v1/#/default/get_sok)\n// TODO: matgeo-autoload popover info\n\ntype Link = { href: string; rel: string; type: string; title: string };\ntype BBox = [number, number, number, number];\nexport type MTDSAtlasCollections = Record<string, MTDSAtlasCollection>;\nexport type MTDSAtlasCollection = {\n\tcrs: string[];\n\tdescription: string;\n\textent: { spatial: { bbox: BBox[] } };\n\tgeometry: string;\n\tid: string;\n\titemType: string;\n\tlinks: Link[];\n\ttitle: string;\n};\n\ndeclare global {\n\tinterface HTMLElementTagNameMap {\n\t\t\"mtds-atlas\": MTDSAtlasElement;\n\t}\n\n\tinterface Window {\n\t\t_matgeoCollections?: Promise<MTDSAtlasCollections>;\n\t}\n}\n\nlet SKIP_CLICK: number | NodeJS.Timeout = 0;\nconst KARTVERKET_MAX_ZOOM = 18; // Kartverket does not support more than zoom level 18\nconst KARTVERKET_TILES_URL =\n\t\"https://cache.kartverket.no/v1/wmts/1.0.0/topo/default/webmercator/{z}/{y}/{x}.png\";\nexport const MATGEO_URL =\n\t\"https://matgeoservice-256616427209.europe-north1.run.app/ogc/features/collections\";\nconst BOUNDS_NORWAY: L.LatLngBoundsLiteral = [\n\t[57.5, 4.73],\n\t[71.5, 31.44],\n];\n\nif (isBrowser() && !window._matgeoCollections)\n\twindow._matgeoCollections = fetch(MATGEO_URL)\n\t\t.then((res) => res.json())\n\t\t.then((d) => d.collections.map((c: MTDSAtlasCollection) => [c.id, c]))\n\t\t.then(Object.fromEntries);\n\nexport class MTDSAtlasElement extends MTDSElement {\n\tcluster?: L.MarkerClusterGroup;\n\tmap?: L.Map;\n\n\tstatic get observedAttributes() {\n\t\treturn [\"data-view\", \"data-scrollzoom\"]; // Using ES2015 syntax for backwards compatibility\n\t}\n\tconstructor() {\n\t\tsuper();\n\t\tthis.attachShadow({ mode: \"open\" }).append(\n\t\t\ttag(\n\t\t\t\t\"style\",\n\t\t\t\tnull,\n\t\t\t\t`@layer leaflet{${LeafletCSS}}\\n@layer mt.design{${css}`,\n\t\t\t),\n\t\t\ttag(\"figure\"),\n\t\t);\n\t}\n\tconnectedCallback() {\n\t\tconst container = this.shadowRoot?.lastElementChild as HTMLElement;\n\t\tconst cluster = attr(this, \"data-cluster\") ?? \"false\";\n\t\tconst tiles = new L.TileLayer(KARTVERKET_TILES_URL, {\n\t\t\tattribution: \"© Kartverket\",\n\t\t\tclassName: \"leaflet-kartverket-tiles\",\n\t\t\tmaxZoom: KARTVERKET_MAX_ZOOM,\n\t\t});\n\n\t\tthis.map = new L.Map(container, {\n\t\t\tattributionControl: false,\n\t\t\tfadeAnimation: false, // Prevent popup fades\n\t\t\tlayers: [tiles],\n\t\t\tzoomControl: false,\n\t\t\tzoomSnap: 0.2,\n\t\t});\n\n\t\ton(this, \"pointerup click\", this.#skipClick); // Prevent clicks from bubbling up unless sent from Leaflet\n\t\tthis.map.addControl(new L.Control.Attribution({ prefix: \"\" }));\n\t\tthis.map.addControl(new L.Control.Zoom({ position: \"bottomright\" }));\n\t\tthis.map.on(\"popupopen popupclose\", this.#handlePopup, this);\n\t\tthis.cluster = new L.MarkerClusterGroup({\n\t\t\tzoomToBoundsOnClick: true,\n\t\t\tshowCoverageOnHover: false,\n\t\t\tdisableClusteringAtZoom:\n\t\t\t\tcluster === \"false\" ? 1 : Number(cluster) || KARTVERKET_MAX_ZOOM + 1,\n\t\t\ticonCreateFunction: (cluster: L.MarkerCluster) =>\n\t\t\t\tnew L.DivIcon({\n\t\t\t\t\thtml: `${cluster.getChildCount()}`,\n\t\t\t\t\tclassName: \"leaflet-cluster-icon\",\n\t\t\t\t\ticonSize: [30, 30],\n\t\t\t\t}),\n\t\t}).addTo(this.map);\n\n\t\t// Initial setup attributes\n\t\tfor (const name of MTDSAtlasElement.observedAttributes)\n\t\t\tthis.attributeChangedCallback(name, null, attr(this, name));\n\t}\n\tattributeChangedCallback(name: string, _prev?: null, next?: string | null) {\n\t\tif (name === \"data-view\") this.setView(next || \"\");\n\t\tif (name === \"data-scrollzoom\")\n\t\t\tthis.map?.scrollWheelZoom[next === \"false\" ? \"disable\" : \"enable\"]();\n\t}\n\tsetView(view: string | number[], opts?: L.FitBoundsOptions) {\n\t\tconst p = `${view}`.split(\",\").map(parseFloat).filter(Number.isFinite);\n\t\tconst b = this.cluster?.getBounds();\n\n\t\tif (p.length === 3) return this.map?.setView([p[0], p[1]], p[2], opts);\n\t\tif (view !== \"fit\") return this.map?.fitBounds(BOUNDS_NORWAY, opts);\n\t\tif (b?.isValid()) return this.map?.fitBounds(b.pad(0.1), opts);\n\t\tthis.cluster?.once(\"layeradd\", () => {\n\t\t\tsetTimeout(() => this.setView(\"fit\"), 50); // Add all markers before fitting\n\t\t});\n\t}\n\tlatLngFromPoint(x: number, y: number) {\n\t\t// @ts-expect-error -- Missing from Leaflet@2.0.0-alpha.1 types\n\t\treturn this.map?.pointerEventToLatLng({ clientX: x, clientY: y });\n\t}\n\tdisconnectedCallback() {\n\t\toff(this, \"pointerup click\", this.#skipClick);\n\t\tthis.map?.remove();\n\t\tthis.map = this.cluster = undefined;\n\t}\n\tasync getCollections() {\n\t\treturn (\n\t\t\twindow._matgeoCollections || Promise.resolve({} as MTDSAtlasCollections)\n\t\t);\n\t}\n\t#handlePopup({ type, popup }: { type: string; popup: L.Popup }) {\n\t\tconst open = type === \"popupopen\";\n\t\tconst cont = popup.getElement()?.querySelector(\".leaflet-popup-content\");\n\t\tconst slot = cont?.querySelector<HTMLSlotElement>(\":scope > slot\");\n\t\tconst id = cont?.textContent?.match(/^#(\\S+)/)?.[1] || \"\";\n\t\tconst el = document.getElementById(slot?.name || id); // If content of popup is #id, replace with <slot>\n\n\t\tif (!el) return open && id && popup.close(); // Close popup if target element not found\n\t\tL.Util.setOptions(popup, { maxWidth: this.offsetWidth - 40 });\n\t\tattr(el, \"data-popover\", open ? attr(el, \"popover\") : null); // Store previous popover mode\n\t\tattr(el, \"popover\", open ? null : attr(el, \"data-popover\")); // But temporarily remove it so popover renders\n\t\tattr(el, \"slot\", open ? el.id : null); // Render popover in slot\n\t\tif (open) popup.setContent(tag(\"slot\", { name: el.id }));\n\t}\n\t#skipClick(event: Partial<MouseEvent>) {\n\t\tif (event.type === \"click\") SKIP_CLICK && event.stopPropagation?.();\n\t\telse if (document.body.classList.contains(\"leaflet-dragging\"))\n\t\t\tSKIP_CLICK = setTimeout(() => {\n\t\t\t\tSKIP_CLICK = 0;\n\t\t\t}, 50); // Was dragging, so skip succeeding click\n\t}\n}\n\ndefineElement(\"mtds-atlas\", MTDSAtlasElement);\n\nif (isBrowser())\n\tL.Marker.prototype.options.icon = new L.DivIcon({\n\t\thtml: '<div class=\"leaflet-marker-generated-slot\"><div class=\"leaflet-marker-generated-icon\"></div></div>',\n\t\ticonSize: [0, 0],\n\t});\n"],"names":["SKIP_CLICK","KARTVERKET_MAX_ZOOM","KARTVERKET_TILES_URL","MATGEO_URL","BOUNDS_NORWAY","isBrowser","res","d","c","MTDSAtlasElement","MTDSElement","tag","LeafletCSS","css","container","cluster","attr","tiles","L","on","#skipClick","#handlePopup","name","_prev","next","view","opts","p","b","x","y","off","type","popup","open","cont","slot","id","el","event","defineElement"],"mappings":";;;;;;;;AA+CA,IAAIA,IAAsC;AAC1C,MAAMC,IAAsB,IACtBC,IACL,sFACYC,IACZ,qFACKC,IAAuC;AAAA,EAC5C,CAAC,MAAM,IAAI;AAAA,EACX,CAAC,MAAM,KAAK;AACb;AAEIC,EAAA,KAAe,CAAC,OAAO,uBAC1B,OAAO,qBAAqB,MAAMF,CAAU,EAC1C,KAAK,CAACG,MAAQA,EAAI,MAAM,EACxB,KAAK,CAACC,MAAMA,EAAE,YAAY,IAAI,CAACC,MAA2B,CAACA,EAAE,IAAIA,CAAC,CAAC,CAAC,EACpE,KAAK,OAAO,WAAW;AAEnB,MAAMC,UAAyBC,EAAY;AAAA,EACjD;AAAA,EACA;AAAA,EAEA,WAAW,qBAAqB;AAC/B,WAAO,CAAC,aAAa,iBAAiB;AAAA,EACvC;AAAA,EACA,cAAc;AACb,UAAA,GACA,KAAK,aAAa,EAAE,MAAM,OAAA,CAAQ,EAAE;AAAA,MACnCC;AAAA,QACC;AAAA,QACA;AAAA,QACA,kBAAkBC,CAAU;AAAA,yBAA0BC,CAAA;AAAA,MAAA;AAAA,MAEvDF,EAAI,QAAQ;AAAA,IAAA;AAAA,EAEd;AAAA,EACA,oBAAoB;AACnB,UAAMG,IAAY,KAAK,YAAY,kBAC7BC,IAAUC,EAAK,MAAM,cAAc,KAAK,SACxCC,IAAQ,IAAIC,EAAE,UAAUhB,GAAsB;AAAA,MACnD,aAAa;AAAA,MACb,WAAW;AAAA,MACX,SAASD;AAAA,IAAA,CACT;AAED,SAAK,MAAM,IAAIiB,EAAE,IAAIJ,GAAW;AAAA,MAC/B,oBAAoB;AAAA,MACpB,eAAe;AAAA;AAAA,MACf,QAAQ,CAACG,CAAK;AAAA,MACd,aAAa;AAAA,MACb,UAAU;AAAA,IAAA,CACV,GA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EACxD;AAAA,EACAlB,GAAWmB,GAA4B;AACtC,IAAIA,EAAM,SAAS,UAASvC,KAAcuC,EAAM,kBAAA,IACvC,SAAS,KAAK,UAAU,SAAS,kBAAkB,MAC3DvC,IAAa,WAAW,MAAM;AAC7B,MAAAA,IAAa;AAAA,IACd,GAAG,EAAE;AAAA,EACP;AACD;AAEAwC,EAAc,cAAc/B,CAAgB;AAExCJ,EAAA,MACHa,EAAE,OAAO,UAAU,QAAQ,OAAO,IAAIA,EAAE,QAAQ;AAAA,EAC/C,MAAM;AAAA,EACN,UAAU,CAAC,GAAG,CAAC;AAAA,CACf;"}
|
|
@@ -14,7 +14,7 @@ class k extends o {
|
|
|
14
14
|
draggable: this.draggable,
|
|
15
15
|
keyboard: !1,
|
|
16
16
|
icon: e
|
|
17
|
-
}), this.marker.bindPopup(() => `#${s(this, "popovertarget")}`), this.marker.on("dragend", this.#e), h(this, "click
|
|
17
|
+
}), this.marker.bindPopup(() => `#${s(this, "popovertarget")}`), this.marker.on("dragend", this.#e), h(this, "click keydown", this), s(this, "slot", `${l}`), s(this, "role", "button"), s(this, "tabindex", "0"), this.attributeChangedCallback("hidden");
|
|
18
18
|
});
|
|
19
19
|
}
|
|
20
20
|
attributeChangedCallback(t) {
|
|
@@ -26,7 +26,7 @@ class k extends o {
|
|
|
26
26
|
t === "draggable" && e?.dragging?.[this.draggable ? "enable" : "disable"](), t === "hidden" && e && a && a[this.hidden ? "removeLayer" : "addLayer"](e);
|
|
27
27
|
}
|
|
28
28
|
disconnectedCallback() {
|
|
29
|
-
c(this, "click
|
|
29
|
+
c(this, "click keydown", this), this.marker?.unbindPopup().off("dragend", this.#e).remove(), this.marker = this.atlas = void 0;
|
|
30
30
|
}
|
|
31
31
|
handleEvent(t) {
|
|
32
32
|
if (t.type === "click") return this.marker?.fire("click");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"atlas-marker.js","sources":["../../designsystem/atlas/atlas-marker.ts"],"sourcesContent":["import L from \"leaflet\";\nimport { attr, defineElement, MTDSElement, off, on, tag } from \"../utils\";\nimport type { MTDSAtlasElement } from \"./atlas-element\";\n\ndeclare global {\n\tinterface HTMLElementTagNameMap {\n\t\t\"mtds-atlas-marker\": MTDSAtlasMarkerElement;\n\t}\n}\n\nlet SLOT = 0;\nexport class MTDSAtlasMarkerElement extends MTDSElement {\n\tatlas?: MTDSAtlasElement;\n\tmarker?: L.Marker;\n\n\tstatic get observedAttributes() {\n\t\treturn [\"hidden\", \"draggable\", \"data-latlng\", \"popovertarget\"]; // Using ES2015 syntax for backwards compatibility\n\t}\n\tconnectedCallback() {\n\t\tqueueMicrotask(() => {\n\t\t\tconst html = tag(\"slot\", { name: `${++SLOT}` });\n\t\t\tconst icon = new L.DivIcon({ html, iconSize: [0, 0] });\n\t\t\tthis.atlas = this.closest<MTDSAtlasElement>(\"mtds-atlas\") || undefined;\n\t\t\tthis.marker = new L.Marker(this.#parseLatLng(), {\n\t\t\t\tdraggable: this.draggable,\n\t\t\t\tkeyboard: false,\n\t\t\t\ticon,\n\t\t\t});\n\t\t\tthis.marker.bindPopup(() => `#${attr(this, \"popovertarget\")}`);\n\t\t\tthis.marker.on(\"dragend\", this.#handleDragEnd);\n\n\t\t\ton(this, \"click
|
|
1
|
+
{"version":3,"file":"atlas-marker.js","sources":["../../designsystem/atlas/atlas-marker.ts"],"sourcesContent":["import L from \"leaflet\";\nimport { attr, defineElement, MTDSElement, off, on, tag } from \"../utils\";\nimport type { MTDSAtlasElement } from \"./atlas-element\";\n\ndeclare global {\n\tinterface HTMLElementTagNameMap {\n\t\t\"mtds-atlas-marker\": MTDSAtlasMarkerElement;\n\t}\n}\n\nlet SLOT = 0;\nexport class MTDSAtlasMarkerElement extends MTDSElement {\n\tatlas?: MTDSAtlasElement;\n\tmarker?: L.Marker;\n\n\tstatic get observedAttributes() {\n\t\treturn [\"hidden\", \"draggable\", \"data-latlng\", \"popovertarget\"]; // Using ES2015 syntax for backwards compatibility\n\t}\n\tconnectedCallback() {\n\t\tqueueMicrotask(() => {\n\t\t\tconst html = tag(\"slot\", { name: `${++SLOT}` });\n\t\t\tconst icon = new L.DivIcon({ html, iconSize: [0, 0] });\n\t\t\tthis.atlas = this.closest<MTDSAtlasElement>(\"mtds-atlas\") || undefined;\n\t\t\tthis.marker = new L.Marker(this.#parseLatLng(), {\n\t\t\t\tdraggable: this.draggable,\n\t\t\t\tkeyboard: false,\n\t\t\t\ticon,\n\t\t\t});\n\t\t\tthis.marker.bindPopup(() => `#${attr(this, \"popovertarget\")}`);\n\t\t\tthis.marker.on(\"dragend\", this.#handleDragEnd);\n\n\t\t\ton(this, \"click keydown\", this); // Listen for clicks to toggle popup\n\t\t\tattr(this, \"slot\", `${SLOT}`); // Link slot to marker icon\n\t\t\tattr(this, \"role\", \"button\");\n\t\t\tattr(this, \"tabindex\", \"0\");\n\t\t\tthis.attributeChangedCallback(\"hidden\"); // Maybe add to map\n\t\t}); // Let the atlas parent initialize first\n\t}\n\tattributeChangedCallback(name: string) {\n\t\tconst mark = this.marker;\n\t\tconst cluster = this.atlas?.cluster;\n\t\tif (name === \"popovertarget\") mark?.getPopup()?.update();\n\t\tif (name === \"data-latlng\") {\n\t\t\tconst latlng = this.#parseLatLng();\n\t\t\tmark?.getLatLng().equals(latlng) || mark?.setLatLng(latlng);\n\t\t}\n\t\tif (name === \"draggable\")\n\t\t\tmark?.dragging?.[this.draggable ? \"enable\" : \"disable\"]();\n\t\tif (name === \"hidden\" && mark && cluster)\n\t\t\tcluster[this.hidden ? \"removeLayer\" : \"addLayer\"](mark);\n\t}\n\tdisconnectedCallback() {\n\t\toff(this, \"click keydown\", this);\n\t\tthis.marker?.unbindPopup().off(\"dragend\", this.#handleDragEnd).remove();\n\t\tthis.marker = this.atlas = undefined;\n\t}\n\thandleEvent(event: KeyboardEvent) {\n\t\tif (event.type === \"click\") return this.marker?.fire(\"click\"); //this.atlas?.togglePopup(this.marker, this);\n\t\tif (event.key === \" \") event.preventDefault(); // Prevent page scroll on space key\n\t\tif (event.key === \" \" || event.key === \"Enter\") this.click(); // Forward keyvoard to click for accessibility\n\t}\n\tget latlng() {\n\t\treturn attr(this, \"data-latlng\") || \"\";\n\t}\n\tset latlng(latlng: string) {\n\t\tattr(this, \"data-latlng\", latlng);\n\t}\n\t#parseLatLng() {\n\t\treturn this.latlng?.split(\",\").map(parseFloat) as L.LatLngTuple;\n\t}\n\t#handleDragEnd(detail: L.LeafletEvent) {\n\t\tconst slot = detail.target._icon\n\t\t\t?.firstElementChild as HTMLSlotElement | null;\n\t\tconst self =\n\t\t\tslot?.assignedElements?.()?.[0] as MTDSAtlasMarkerElement | null;\n\t\tconst { lat, lng } = detail.target.getLatLng(); // Using L.Marker.getLatLng() to get position also when in spiderified cluster\n\t\tif (self) self.latlng = `${lat},${lng}`;\n\t\tself?.dispatchEvent(new CustomEvent(\"dragend\", { detail, bubbles: true }));\n\t}\n}\n\ndefineElement(\"mtds-atlas-marker\", MTDSAtlasMarkerElement);\n"],"names":["SLOT","MTDSAtlasMarkerElement","MTDSElement","html","tag","icon","L","#parseLatLng","attr","#handleDragEnd","on","name","mark","cluster","latlng","off","event","detail","self","lat","lng","defineElement"],"mappings":";;AAUA,IAAIA,IAAO;AACJ,MAAMC,UAA+BC,EAAY;AAAA,EACvD;AAAA,EACA;AAAA,EAEA,WAAW,qBAAqB;AAC/B,WAAO,CAAC,UAAU,aAAa,eAAe,eAAe;AAAA,EAC9D;AAAA,EACA,oBAAoB;AACnB,mBAAe,MAAM;AACpB,YAAMC,IAAOC,EAAI,QAAQ,EAAE,MAAM,GAAG,EAAEJ,CAAI,IAAI,GACxCK,IAAO,IAAIC,EAAE,QAAQ,EAAE,MAAAH,GAAM,UAAU,CAAC,GAAG,CAAC,GAAG;AACrD,WAAK,QAAQ,KAAK,QAA0B,YAAY,KAAK,QAC7D,KAAK,SAAS,IAAIG,EAAE,OAAO,KAAKC,MAAgB;AAAA,QAC/C,WAAW,KAAK;AAAA,QAChB,UAAU;AAAA,QACV,M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