@mattilsynet/design 2.2.24 → 2.2.25
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/alert/alert.js +9 -8
- package/mtds/alert/alert.js.map +1 -1
- package/mtds/analytics/analytics.d.ts +1 -1
- package/mtds/analytics/analytics.js +163 -101
- package/mtds/analytics/analytics.js.map +1 -1
- package/mtds/app/app-observer.js +73 -27
- package/mtds/app/app-observer.js.map +1 -1
- package/mtds/app/app-toggle.js +2 -24
- package/mtds/app/app-toggle.js.map +1 -1
- package/mtds/app/app-toggle2.js +16 -10
- package/mtds/app/app-toggle2.js.map +1 -1
- package/mtds/app/app.d.ts +5 -5
- package/mtds/app/app.js +36 -32
- package/mtds/app/app.js.map +1 -1
- package/mtds/atlas/atlas-element.d.ts +8 -14
- package/mtds/atlas/atlas-element.js +90 -76
- package/mtds/atlas/atlas-element.js.map +1 -1
- package/mtds/atlas/atlas-marker.d.ts +20 -0
- package/mtds/atlas/atlas-marker.js +69 -0
- package/mtds/atlas/atlas-marker.js.map +1 -0
- package/mtds/atlas/atlas-matgeo.d.ts +29 -0
- package/mtds/atlas/atlas-matgeo.js +71 -0
- package/mtds/atlas/atlas-matgeo.js.map +1 -0
- package/mtds/atlas/atlas.css.js +76 -96
- package/mtds/atlas/atlas.css.js.map +1 -1
- package/mtds/atlas/atlas.d.ts +42 -0
- package/mtds/atlas/atlas.js +33 -0
- package/mtds/atlas/atlas.js.map +1 -0
- package/mtds/atlas/atlas.stories.d.ts +5 -1
- package/mtds/atlas/cluster.js +1576 -697
- package/mtds/atlas/cluster.js.map +1 -1
- package/mtds/atlas.iife.js +80 -100
- package/mtds/atlas.js +8 -4
- package/mtds/atlas.js.map +1 -1
- package/mtds/avatar/avatar.js +8 -8
- package/mtds/avatar/avatar.js.map +1 -1
- package/mtds/badge/badge.d.ts +2 -2
- package/mtds/badge/badge.js +7 -7
- package/mtds/badge/badge.js.map +1 -1
- package/mtds/breadcrumbs/breadcrumbs-observer.js +10 -9
- package/mtds/breadcrumbs/breadcrumbs-observer.js.map +1 -1
- package/mtds/breadcrumbs/breadcrumbs.js +14 -13
- package/mtds/breadcrumbs/breadcrumbs.js.map +1 -1
- package/mtds/button/button.js +16 -14
- package/mtds/button/button.js.map +1 -1
- package/mtds/card/card.js +14 -12
- package/mtds/card/card.js.map +1 -1
- package/mtds/chart/chart-axis.js +27 -15
- package/mtds/chart/chart-axis.js.map +1 -1
- package/mtds/chart/chart-bars.js +15 -13
- package/mtds/chart/chart-bars.js.map +1 -1
- package/mtds/chart/chart-element.d.ts +5 -0
- package/mtds/chart/chart-element.js +83 -48
- package/mtds/chart/chart-element.js.map +1 -1
- package/mtds/chart/chart-lines.js +54 -32
- package/mtds/chart/chart-lines.js.map +1 -1
- package/mtds/chart/chart-pies.js +34 -14
- package/mtds/chart/chart-pies.js.map +1 -1
- package/mtds/chart/chart.css.js +2 -2
- package/mtds/chart/chart.css.js.map +1 -1
- package/mtds/chart/chart.d.ts +3 -4
- package/mtds/chart/chart.js +12 -12
- package/mtds/chart/chart.js.map +1 -1
- package/mtds/chip/chip.js +8 -8
- package/mtds/chip/chip.js.map +1 -1
- package/mtds/details/details.d.ts +3 -3
- package/mtds/details/details.js +14 -12
- package/mtds/details/details.js.map +1 -1
- package/mtds/dialog/dialog-observer.js +35 -22
- package/mtds/dialog/dialog-observer.js.map +1 -1
- package/mtds/dialog/dialog.d.ts +2 -2
- package/mtds/dialog/dialog.js +12 -12
- package/mtds/dialog/dialog.js.map +1 -1
- package/mtds/divider/divider.d.ts +2 -2
- package/mtds/divider/divider.js +10 -10
- package/mtds/divider/divider.js.map +1 -1
- package/mtds/errorsummary/errorsummary-observer.js +11 -8
- package/mtds/errorsummary/errorsummary-observer.js.map +1 -1
- package/mtds/errorsummary/errorsummary.d.ts +1 -1
- package/mtds/errorsummary/errorsummary.js +11 -11
- package/mtds/errorsummary/errorsummary.js.map +1 -1
- package/mtds/external/leaflet/dist/leaflet-src.js +6006 -3098
- package/mtds/external/leaflet/dist/leaflet-src.js.map +1 -1
- package/mtds/external/leaflet/dist/leaflet.css.js +2 -2
- package/mtds/external/leaflet/dist/leaflet.css.js.map +1 -1
- package/mtds/field/field-observer.js +114 -62
- package/mtds/field/field-observer.js.map +1 -1
- package/mtds/field/field.d.ts +6 -6
- package/mtds/field/field.js +166 -133
- package/mtds/field/field.js.map +1 -1
- package/mtds/field/field.stories.d.ts +2 -0
- package/mtds/fieldset/fieldset-observer.js +24 -14
- package/mtds/fieldset/fieldset-observer.js.map +1 -1
- package/mtds/fieldset/fieldset.d.ts +1 -1
- package/mtds/fieldset/fieldset.js +11 -11
- package/mtds/fieldset/fieldset.js.map +1 -1
- package/mtds/fileupload/fileupload.js +9 -8
- package/mtds/fileupload/fileupload.js.map +1 -1
- package/mtds/helptext/helptext.d.ts +1 -1
- package/mtds/helptext/helptext.js +15 -15
- package/mtds/helptext/helptext.js.map +1 -1
- package/mtds/index.iife.js +9 -9
- package/mtds/index.js +26 -24
- package/mtds/input/input.d.ts +3 -3
- package/mtds/input/input.js +22 -20
- package/mtds/input/input.js.map +1 -1
- package/mtds/law/law-helper.d.ts +6 -2
- package/mtds/law/law-helper.js +145 -63
- package/mtds/law/law-helper.js.map +1 -1
- package/mtds/law/law.d.ts +6 -2
- package/mtds/law/law.js +6 -6
- package/mtds/law/law.js.map +1 -1
- package/mtds/law/law.stories.d.ts +1 -0
- package/mtds/layout/layout.js +13 -10
- package/mtds/layout/layout.js.map +1 -1
- package/mtds/link/link.js +8 -7
- package/mtds/link/link.js.map +1 -1
- package/mtds/logo/logo-observer.js +18 -12
- package/mtds/logo/logo-observer.js.map +1 -1
- package/mtds/logo/logo.js +8 -8
- package/mtds/logo/logo.js.map +1 -1
- package/mtds/package.json.js +2 -2
- package/mtds/pagination/pagination-helper.js +17 -11
- package/mtds/pagination/pagination-helper.js.map +1 -1
- package/mtds/pagination/pagination.d.ts +1 -1
- package/mtds/pagination/pagination.js +30 -30
- package/mtds/pagination/pagination.js.map +1 -1
- package/mtds/popover/popover-observer.js +37 -28
- package/mtds/popover/popover-observer.js.map +1 -1
- package/mtds/popover/popover.js +13 -11
- package/mtds/popover/popover.js.map +1 -1
- package/mtds/progress/progress.d.ts +1 -1
- package/mtds/progress/progress.js +8 -8
- package/mtds/progress/progress.js.map +1 -1
- package/mtds/react-atlas.d.ts +1 -0
- package/mtds/react-atlas.js +13 -0
- package/mtds/react-atlas.js.map +1 -0
- package/mtds/react-types.d.ts +3 -0
- package/mtds/react.js +79 -79
- package/mtds/skeleton/skeleton.js +8 -8
- package/mtds/skeleton/skeleton.js.map +1 -1
- package/mtds/spinner/spinner.d.ts +2 -2
- package/mtds/spinner/spinner.js +8 -8
- package/mtds/spinner/spinner.js.map +1 -1
- package/mtds/steps/steps.d.ts +2 -2
- package/mtds/steps/steps.js +7 -7
- package/mtds/steps/steps.js.map +1 -1
- package/mtds/styles.css +4586 -1
- package/mtds/styles.module.css.js +167 -112
- package/mtds/styles.module.css.js.map +1 -1
- package/mtds/table/table-observer.js +22 -19
- package/mtds/table/table-observer.js.map +1 -1
- package/mtds/table/table.d.ts +4 -4
- package/mtds/table/table.js +18 -16
- package/mtds/table/table.js.map +1 -1
- package/mtds/tabs/tabs.d.ts +4 -4
- package/mtds/tabs/tabs.js +25 -21
- package/mtds/tabs/tabs.js.map +1 -1
- package/mtds/tag/tag.js +8 -8
- package/mtds/tag/tag.js.map +1 -1
- package/mtds/tailwind.css +24 -6
- package/mtds/toast/toast-helper.js +35 -20
- package/mtds/toast/toast-helper.js.map +1 -1
- package/mtds/toast/toast-observer.js +30 -15
- package/mtds/toast/toast-observer.js.map +1 -1
- package/mtds/toast/toast.js +45 -37
- package/mtds/toast/toast.js.map +1 -1
- package/mtds/togglegroup/togglegroup-observer.js +15 -10
- package/mtds/togglegroup/togglegroup-observer.js.map +1 -1
- package/mtds/togglegroup/togglegroup.d.ts +3 -3
- package/mtds/togglegroup/togglegroup.js +20 -18
- package/mtds/togglegroup/togglegroup.js.map +1 -1
- package/mtds/tooltip/tooltip-observer.js +48 -32
- package/mtds/tooltip/tooltip-observer.js.map +1 -1
- package/mtds/typography/typography.js +28 -19
- package/mtds/typography/typography.js.map +1 -1
- package/mtds/utils.d.ts +12 -3
- package/mtds/utils.js +133 -81
- package/mtds/utils.js.map +1 -1
- package/mtds/validation/validation.d.ts +1 -1
- package/mtds/validation/validation.js +12 -12
- package/mtds/validation/validation.js.map +1 -1
- package/package.json +14 -10
package/mtds/alert/alert.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import { jsx
|
|
2
|
-
import
|
|
3
|
-
import { forwardRef
|
|
4
|
-
import
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import clsx from "clsx";
|
|
3
|
+
import { forwardRef } from "react";
|
|
4
|
+
import styles from "../styles.module.css.js";
|
|
5
|
+
const Alert = forwardRef(function Alert2({ as, className, ...rest }, ref) {
|
|
6
|
+
const Tag = as || "output";
|
|
7
|
+
if (!rest.role && Tag !== "output") Object.assign(rest, { role: "alert" });
|
|
8
|
+
return /* @__PURE__ */ jsx(Tag, { className: clsx(styles.alert, className), ref, ...rest });
|
|
8
9
|
});
|
|
9
10
|
export {
|
|
10
|
-
|
|
11
|
+
Alert
|
|
11
12
|
};
|
|
12
13
|
//# sourceMappingURL=alert.js.map
|
package/mtds/alert/alert.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"alert.js","sources":["../../designsystem/alert/alert.tsx"],"sourcesContent":["import clsx from \"clsx\";\nimport { forwardRef, type JSX } from \"react\";\nimport type {\n\tPolymorphicComponentPropWithRef,\n\tPolymorphicRef,\n} from \"../react-types\";\nimport styles from \"../styles.module.css\";\n\nexport type AlertProps<As extends React.ElementType = \"output\"> =\n\tPolymorphicComponentPropWithRef<\n\t\tAs,\n\t\t{ \"data-color\"?: \"info\" | \"success\" | \"warning\" | \"danger\" | \"neutral\" }\n\t>;\n\ntype AlertComponent = <As extends React.ElementType = \"output\">(\n\tprops: AlertProps<As>,\n) => JSX.Element;\n\nexport const Alert: AlertComponent = forwardRef<null>(function Alert<\n\tAs extends React.ElementType = \"output\",\n>({ as, className, ...rest }: AlertProps<As>, ref?: PolymorphicRef<As>) {\n\tconst Tag = as || \"output\";\n\n\tif (!rest.role && Tag !== \"output\") Object.assign(rest, { role: \"alert\" }); // Ensure role is set to 'alert' if not <output>\n\n\treturn <Tag className={clsx(styles.alert, className)} ref={ref} {...rest} />;\n}) as AlertComponent; // Needed to tell Typescript this does not return ReactNode but acutally JSX.Element\n"],"names":["Alert"
|
|
1
|
+
{"version":3,"file":"alert.js","sources":["../../designsystem/alert/alert.tsx"],"sourcesContent":["import clsx from \"clsx\";\nimport { forwardRef, type JSX } from \"react\";\nimport type {\n\tPolymorphicComponentPropWithRef,\n\tPolymorphicRef,\n} from \"../react-types\";\nimport styles from \"../styles.module.css\";\n\nexport type AlertProps<As extends React.ElementType = \"output\"> =\n\tPolymorphicComponentPropWithRef<\n\t\tAs,\n\t\t{ \"data-color\"?: \"info\" | \"success\" | \"warning\" | \"danger\" | \"neutral\" }\n\t>;\n\ntype AlertComponent = <As extends React.ElementType = \"output\">(\n\tprops: AlertProps<As>,\n) => JSX.Element;\n\nexport const Alert: AlertComponent = forwardRef<null>(function Alert<\n\tAs extends React.ElementType = \"output\",\n>({ as, className, ...rest }: AlertProps<As>, ref?: PolymorphicRef<As>) {\n\tconst Tag = as || \"output\";\n\n\tif (!rest.role && Tag !== \"output\") Object.assign(rest, { role: \"alert\" }); // Ensure role is set to 'alert' if not <output>\n\n\treturn <Tag className={clsx(styles.alert, className)} ref={ref} {...rest} />;\n}) as AlertComponent; // Needed to tell Typescript this does not return ReactNode but acutally JSX.Element\n"],"names":["Alert"],"mappings":";;;;AAkBO,MAAM,QAAwB,WAAiB,SAASA,OAE7D,EAAE,IAAI,WAAW,GAAG,KAAA,GAAwB,KAA0B;AACvE,QAAM,MAAM,MAAM;AAElB,MAAI,CAAC,KAAK,QAAQ,QAAQ,SAAU,QAAO,OAAO,MAAM,EAAE,MAAM,QAAA,CAAS;AAEzE,SAAO,oBAAC,KAAA,EAAI,WAAW,KAAK,OAAO,OAAO,SAAS,GAAG,KAAW,GAAG,KAAA,CAAM;AAC3E,CAAC;"}
|
|
@@ -1,120 +1,182 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { onLoaded
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
results: n = !1
|
|
38
|
-
} = a;
|
|
39
|
-
window._paq.push(["trackSiteSearch", e, o, n]);
|
|
40
|
-
} else t === "matomo" && window._paq.push(a);
|
|
1
|
+
import styles from "../styles.module.css.js";
|
|
2
|
+
import { onLoaded, isBrowser, tag, on, QUICK_EVENT, attr } from "../utils.js";
|
|
3
|
+
const CSS_BREADCRUMBS = `.${styles.breadcrumbs.split(" ")[0]}`;
|
|
4
|
+
const CSS_CARD = `.${styles.card.split(" ")[0]}`;
|
|
5
|
+
const CSS_CHIP = `.${styles.chip.split(" ")[0]}`;
|
|
6
|
+
const CSS_HELPTEXT = `.${styles.helptext.split(" ")[0]}`;
|
|
7
|
+
const CSS_PAGINATION = `.${styles.pagination.split(" ")[0]}`;
|
|
8
|
+
const CLICKS = `summary,u-summary,a,button,[role="tab"],[role="button"]`;
|
|
9
|
+
const EVENTS = "click,toggle,submit,change";
|
|
10
|
+
const MATOMO = "mattilsynet.matomo.cloud";
|
|
11
|
+
const BANNER = "mtds-analytics-banner";
|
|
12
|
+
const BANNER_URL = "https://www.mattilsynet.no/om-mattilsynet/personvernerklaering/informasjonskapsler";
|
|
13
|
+
function analytics(action, args = {}) {
|
|
14
|
+
if (!isBrowser()) return;
|
|
15
|
+
if (!window._paq) {
|
|
16
|
+
window._paq = [];
|
|
17
|
+
window._paq.push(["HeatmapSessionRecording::disable"]);
|
|
18
|
+
window._paq.push(["enableLinkTracking"]);
|
|
19
|
+
window._paq.push(["setTrackerUrl", `https://${MATOMO}/matomo.php`]);
|
|
20
|
+
}
|
|
21
|
+
if (!window._mtm) {
|
|
22
|
+
window._mtm = window._mtm || [];
|
|
23
|
+
window._mtm.push({ "mtm.startTime": Date.now(), event: "mtm.Start" });
|
|
24
|
+
}
|
|
25
|
+
if (action === "init") {
|
|
26
|
+
window._mtdsTracking = {
|
|
27
|
+
enabled: window.location.hostname !== "localhost",
|
|
28
|
+
...window._mtdsTracking,
|
|
29
|
+
...args
|
|
30
|
+
};
|
|
31
|
+
const { consent, enabled, matomoId, matomoTagManagerId } = window._mtdsTracking;
|
|
32
|
+
if (matomoId) window._paq.push(["setSiteId", matomoId]);
|
|
33
|
+
if (enabled) {
|
|
34
|
+
if (consent !== "custom") renderBanner();
|
|
35
|
+
const src = matomoTagManagerId ? `https://cdn.matomo.cloud/${MATOMO}/container_${matomoTagManagerId}.js` : `https://cdn.matomo.cloud/${MATOMO}/matomo.js`;
|
|
36
|
+
document.querySelector(`script[src="${src}"]`) || document.head.append(tag("script", { async: "", src }));
|
|
41
37
|
}
|
|
42
38
|
}
|
|
39
|
+
if (window._mtdsTracking?.enabled === false) return;
|
|
40
|
+
if (window._mtdsTracking?.enabled === "debug")
|
|
41
|
+
return console.info(`analytics ${action}:`, args);
|
|
42
|
+
if (action === "pageview") {
|
|
43
|
+
const { url, title } = args;
|
|
44
|
+
window._paq.push(["setCustomUrl", url || location.href]);
|
|
45
|
+
window._paq.push(["setDocumentTitle", title || document.title]);
|
|
46
|
+
window._paq.push(["trackPageView"]);
|
|
47
|
+
} else if (action === "event") {
|
|
48
|
+
const { category, action: action2, name, value } = args;
|
|
49
|
+
const event = ["trackEvent", category, action2, name, value];
|
|
50
|
+
let url = location.href;
|
|
51
|
+
window._paq.push([
|
|
52
|
+
function() {
|
|
53
|
+
url = this.getCurrentUrl();
|
|
54
|
+
}
|
|
55
|
+
]);
|
|
56
|
+
window._paq.push(["setCustomUrl", url.split("#")[0]]);
|
|
57
|
+
window._paq.push(event.filter((v) => v !== void 0));
|
|
58
|
+
window._paq.push(["setCustomUrl", url]);
|
|
59
|
+
} else if (action === "search") {
|
|
60
|
+
const {
|
|
61
|
+
query,
|
|
62
|
+
category = false,
|
|
63
|
+
results = false
|
|
64
|
+
} = args;
|
|
65
|
+
window._paq.push(["trackSiteSearch", query, category, results]);
|
|
66
|
+
} else if (action === "matomo") {
|
|
67
|
+
const props = args;
|
|
68
|
+
if (props?.[0] === "setReferrerUrl" && !props[1]) props[1] = "";
|
|
69
|
+
window._paq.push(props);
|
|
70
|
+
}
|
|
43
71
|
}
|
|
44
|
-
function
|
|
45
|
-
|
|
72
|
+
function renderBanner() {
|
|
73
|
+
const hasSeenBanner = document.getElementById(BANNER) || window.localStorage.getItem(BANNER);
|
|
74
|
+
if (hasSeenBanner) return;
|
|
46
75
|
document.body.insertAdjacentHTML(
|
|
47
76
|
"afterbegin",
|
|
48
|
-
`<dialog id="${
|
|
49
|
-
#${
|
|
50
|
-
#${
|
|
51
|
-
#${
|
|
52
|
-
#${
|
|
53
|
-
#${
|
|
54
|
-
#${
|
|
77
|
+
`<dialog id="${BANNER}" data-analytics="ignore"><style>
|
|
78
|
+
#${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 }
|
|
79
|
+
#${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 }
|
|
80
|
+
#${BANNER} button:focus-visible { outline: 2px solid }
|
|
81
|
+
#${BANNER} button:hover { background: #0a4e4f }
|
|
82
|
+
#${BANNER} button:active { background: #054449; scale: .9 }
|
|
83
|
+
#${BANNER} p { margin: 0 .25em }
|
|
55
84
|
</style>
|
|
56
|
-
<p>Vi bruker <a href="${
|
|
85
|
+
<p>Vi bruker <a href="${BANNER_URL}" target="_blank">informasjonskapsler</a> for å forbedre brukeropplevelsen.</p>
|
|
57
86
|
<form method="dialog" data-analytics="ignore"><button type="submit" aria-label="OK">×</button></form>
|
|
58
87
|
</dialog>`
|
|
59
88
|
);
|
|
60
|
-
const
|
|
61
|
-
|
|
89
|
+
const banner = document.getElementById(BANNER);
|
|
90
|
+
const onClose = () => window.localStorage.setItem(BANNER, "seen");
|
|
91
|
+
banner.addEventListener("close", onClose, { once: true });
|
|
92
|
+
banner.show();
|
|
62
93
|
}
|
|
63
|
-
function
|
|
64
|
-
window._mtdsTracking?.enabled
|
|
94
|
+
function handleAnalyticsTrack(event) {
|
|
95
|
+
if (window._mtdsTracking?.enabled) setTimeout(processTrack, 0, event);
|
|
65
96
|
}
|
|
66
|
-
function
|
|
67
|
-
const
|
|
68
|
-
if (!(
|
|
97
|
+
function processTrack({ type, target }) {
|
|
98
|
+
const el = type === "click" ? target?.closest?.(CLICKS) : target;
|
|
99
|
+
if (!(el instanceof Element) || el.closest('[data-analytics="ignore"]'))
|
|
69
100
|
return;
|
|
70
|
-
let
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
else if (
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
} else if (
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
} else if (
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
else if (
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
else if (
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
101
|
+
let action = "click";
|
|
102
|
+
let category = "Button";
|
|
103
|
+
let name = label(el) || heading(el) || attr(el, "data-tooltip") || "";
|
|
104
|
+
if (type === "submit") {
|
|
105
|
+
category = "Form";
|
|
106
|
+
action = "submit";
|
|
107
|
+
name = name || document.title;
|
|
108
|
+
} else if (type === "toggle") {
|
|
109
|
+
if (!el.matches("dialog:modal")) return;
|
|
110
|
+
category = "Dialog";
|
|
111
|
+
action = "open";
|
|
112
|
+
} else if (type === "change") {
|
|
113
|
+
const type2 = attr(el, "type");
|
|
114
|
+
const group = type2 === "checkbox" || type2 === "radio" ? el.closest("fieldset") : null;
|
|
115
|
+
category = el.closest(CSS_CHIP) ? "Chip" : "Form";
|
|
116
|
+
action = "change";
|
|
117
|
+
name = label(group || el) || text(group?.querySelector("legend")) || text(el?.labels?.[0]);
|
|
118
|
+
} else if (attr(el, "role") === "tab") {
|
|
119
|
+
category = "Tab";
|
|
120
|
+
action = "navigate";
|
|
121
|
+
} else if (attr(el, "popovertarget")) {
|
|
122
|
+
if (!popover(el)?.matches(":popover-open")) return;
|
|
123
|
+
category = el.closest(CSS_HELPTEXT) ? "HelpText" : "Popover";
|
|
124
|
+
action = "open";
|
|
125
|
+
} else if (el.nodeName.endsWith("SUMMARY")) {
|
|
126
|
+
if (!el.parentElement.open) return;
|
|
127
|
+
category = "Details";
|
|
128
|
+
action = "open";
|
|
129
|
+
} else if (attr(el, "data-command") === "toggle-app-expanded") {
|
|
130
|
+
const open = style(el, "--mtds-tooltip-position") === "none";
|
|
131
|
+
category = "Sidebar";
|
|
132
|
+
action = open ? "expand" : "minimize";
|
|
133
|
+
name = open && attr(el, "data-tooltip") || text(el);
|
|
134
|
+
} else if (el.closest(CSS_BREADCRUMBS)) {
|
|
135
|
+
category = "Breadcrumbs";
|
|
136
|
+
action = "navigate";
|
|
137
|
+
} else if (el.closest(CSS_PAGINATION)) {
|
|
138
|
+
category = "Pagintation";
|
|
139
|
+
action = "navigate";
|
|
140
|
+
} else if (el.closest(CSS_CARD)) {
|
|
141
|
+
category = "Card";
|
|
142
|
+
action = el instanceof HTMLAnchorElement ? "navigate" : "click";
|
|
143
|
+
} else if (el.closest(CSS_CHIP)) {
|
|
144
|
+
category = "Chip";
|
|
145
|
+
action = el.hasAttribute("data-removable") ? "remove" : "click";
|
|
146
|
+
} else if (el.closest("th[aria-sort]")) {
|
|
147
|
+
category = "Table";
|
|
148
|
+
action = "sort";
|
|
149
|
+
} else if (el instanceof HTMLAnchorElement) {
|
|
150
|
+
category = "Link";
|
|
151
|
+
action = el.protocol === "mailto:" ? "email" : "navigate";
|
|
152
|
+
if (el.hasAttribute("download")) action = "download";
|
|
153
|
+
else if (el.hash && el.href.startsWith(location.href.split("#")[0]))
|
|
154
|
+
action = "anchor";
|
|
155
|
+
} else if (el.hasAttribute("aria-expanded")) {
|
|
156
|
+
if (attr(el, "aria-expanded") !== "true") return;
|
|
157
|
+
category = "Expand";
|
|
158
|
+
action = "open";
|
|
159
|
+
} else if (el.nodeName.startsWith("MTDS-ATLAS-")) {
|
|
160
|
+
category = "Map Marker";
|
|
161
|
+
action = "open";
|
|
105
162
|
}
|
|
106
|
-
|
|
107
|
-
category:
|
|
108
|
-
action:
|
|
109
|
-
name:
|
|
163
|
+
analytics("event", {
|
|
164
|
+
category: attr(el, "data-analytics-category") ?? category,
|
|
165
|
+
action: attr(el, "data-analytics-action") ?? action,
|
|
166
|
+
name: attr(el, "data-analytics-name") ?? name
|
|
110
167
|
});
|
|
111
168
|
}
|
|
112
|
-
const
|
|
113
|
-
|
|
114
|
-
|
|
169
|
+
const text = (el) => el?.textContent?.trim() || "";
|
|
170
|
+
const label = (el) => el && attr(el, "aria-label") || "";
|
|
171
|
+
const popover = (el) => document.getElementById(attr(el, "popovertarget") || "");
|
|
172
|
+
const style = (el, key) => window.getComputedStyle(el).getPropertyValue(key)?.trim();
|
|
173
|
+
const heading = (el) => {
|
|
174
|
+
const body = text(el);
|
|
175
|
+
const head = text(el.querySelector("h1,h2,h3,h4,h5,h6"));
|
|
176
|
+
return body.startsWith(head) && head || body.slice(0, 100).trim();
|
|
115
177
|
};
|
|
116
|
-
|
|
178
|
+
onLoaded(() => [on(document, EVENTS, handleAnalyticsTrack, QUICK_EVENT)]);
|
|
117
179
|
export {
|
|
118
|
-
|
|
180
|
+
analytics
|
|
119
181
|
};
|
|
120
182
|
//# sourceMappingURL=analytics.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"analytics.js","sources":["../../designsystem/analytics/analytics.ts"],"sourcesContent":["import styles from \"../styles.module.css\";\nimport { attr, IS_BROWSER, on, onLoaded, QUICK_EVENT, tag } from \"../utils\";\n\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 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?: never;\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 (!IS_BROWSER) 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\twindow._paq.push(args as AnalyticsActions[\"matomo\"]);\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 (attr(el, \"data-command\") === \"toggle-app-expanded\") {\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}\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_BREADCRUMBS","styles","CSS_CARD","CSS_CHIP","CSS_HELPTEXT","CSS_PAGINATION","CLICKS","EVENTS","MATOMO","BANNER","BANNER_URL","analytics","action","args","IS_BROWSER","consent","enabled","matomoId","matomoTagManagerId","renderBanner","src","tag","url","title","category","name","value","event","v","query","results","banner","onClose","handleAnalyticsTrack","processTrack","type","target","el","label","heading","attr","group","text","popover","open","style","key","body","head","onLoaded","on","QUICK_EVENT"],"mappings":";;AAGA,MAAMA,IAAkB,IAAIC,EAAO,YAAY,MAAM,GAAG,EAAE,CAAC,CAAC,IACtDC,IAAW,IAAID,EAAO,KAAK,MAAM,GAAG,EAAE,CAAC,CAAC,IACxCE,IAAW,IAAIF,EAAO,KAAK,MAAM,GAAG,EAAE,CAAC,CAAC,IACxCG,IAAe,IAAIH,EAAO,SAAS,MAAM,GAAG,EAAE,CAAC,CAAC,IAChDI,IAAiB,IAAIJ,EAAO,WAAW,MAAM,GAAG,EAAE,CAAC,CAAC,IACpDK,IAAS,2DACTC,IAAS,8BACTC,IAAS,4BACTC,IAAS,yBACTC,IACL;AAmDM,SAASC,EACfC,GACAC,IAAO,IACN;AACD,MAAKC,GAYL;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,WAAWN,CAAM,aAAa,CAAC,IAE9D,OAAO,SACX,OAAO,OAAO,OAAO,QAAQ,CAAA,GAC7B,OAAO,KAAK,KAAK,EAAE,iBAAiB,KAAK,IAAA,GAAO,OAAO,aAAa,IAGjEI,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;AACZ,QAAID,M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AAAb,IAAW,SACXZ,IAAS;AAAA,WACCyB,aAAc;AACxB,IAAAb,IAAW,QACXZ,IAASyB,EAAG,aAAa,YAAY,UAAU,YAC3CA,EAAG,aAAa,UAAU,IAAGzB,IAAS,aACjCyB,EAAG,QAAQA,EAAG,KAAK,WAAW,SAAS,KAAK,MAAM,GAAG,EAAE,CAAC,CAAC,MACjEzB,IAAS;AAAA,WACAyB,EAAG,aAAa,eAAe,GAAG;AAC5C,QAAIG,EAAKH,GAAI,eAAe,MAAM,OAAQ;AAC1C,IAAAb,IAAW,UACXZ,IAAS;AAAA,EACV;AAGA,EAAAD,EAAU,SAAS;AAAA,IAClB,UAAU6B,EAAKH,GAAI,yBAAyB,KAAKb;AAAA,IACjD,QAAQgB,EAAKH,GAAI,uBAAuB,KAAKzB;AAAA,IAC7C,MAAM4B,EAAKH,GAAI,qBAAqB,KAAKZ;AAAA,EAAA,CACzC;AACF;AAGA,MAAMiB,IAAO,CAACL,MAAwBA,GAAI,aAAa,UAAU,IAC3DC,IAAQ,CAACD,MAAyBA,KAAMG,EAAKH,GAAI,YAAY,KAAM,IACnEM,IAAU,CAACN,MAChB,SAAS,eAAeG,EAAKH,GAAI,eAAe,KAAK,EAAE,GAClDQ,IAAQ,CAACR,GAAaS,MAC3B,OAAO,iBAAiBT,CAAE,EAAE,iBAAiBS,CAAG,GAAG,KAAA,GAC9CP,IAAU,CAACF,MAAgB;AAChC,QAAMU,IAAOL,EAAKL,CAAE,GACdW,IAAON,EAAKL,EAAG,cAAc,mBAAmB,CAAC;AACvD,SAAQU,EAAK,WAAWC,CAAI,KAAKA,KAASD,EAAK,MAAM,GAAG,GAAG,EAAE,KAAA;AAC9D;AAEAE,EAAS,MAAM,CAACC,EAAG,UAAU3C,GAAQ0B,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, onLoaded, QUICK_EVENT, tag } from \"../utils\";\n\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 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\tif (props?.[0] === \"setReferrerUrl\" && !props[1]) props[1] = \"\"; // Matomo dies if referrer is undefined\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 (attr(el, \"data-command\") === \"toggle-app-expanded\") {\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":["action","type"],"mappings":";;AAGA,MAAM,kBAAkB,IAAI,OAAO,YAAY,MAAM,GAAG,EAAE,CAAC,CAAC;AAC5D,MAAM,WAAW,IAAI,OAAO,KAAK,MAAM,GAAG,EAAE,CAAC,CAAC;AAC9C,MAAM,WAAW,IAAI,OAAO,KAAK,MAAM,GAAG,EAAE,CAAC,CAAC;AAC9C,MAAM,eAAe,IAAI,OAAO,SAAS,MAAM,GAAG,EAAE,CAAC,CAAC;AACtD,MAAM,iBAAiB,IAAI,OAAO,WAAW,MAAM,GAAG,EAAE,CAAC,CAAC;AAC1D,MAAM,SAAS;AACf,MAAM,SAAS;AACf,MAAM,SAAS;AACf,MAAM,SAAS;AACf,MAAM,aACL;AAmDM,SAAS,UACf,QACA,OAAO,IACN;AACD,MAAI,CAAC,YAAa;AAClB,MAAI,CAAC,OAAO,MAAM;AACjB,WAAO,OAAO,CAAA;AACd,WAAO,KAAK,KAAK,CAAC,kCAAkC,CAAC;AACrD,WAAO,KAAK,KAAK,CAAC,oBAAoB,CAAC;A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AAG,GAAG,KAAA;AACpD,MAAM,UAAU,CAAC,OAAgB;AAChC,QAAM,OAAO,KAAK,EAAE;AACpB,QAAM,OAAO,KAAK,GAAG,cAAc,mBAAmB,CAAC;AACvD,SAAQ,KAAK,WAAW,IAAI,KAAK,QAAS,KAAK,MAAM,GAAG,GAAG,EAAE,KAAA;AAC9D;AAEA,SAAS,MAAM,CAAC,GAAG,UAAU,QAAQ,sBAAsB,WAAW,CAAC,CAAC;"}
|
package/mtds/app/app-observer.js
CHANGED
|
@@ -1,38 +1,84 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
1
|
+
import styles from "../styles.module.css.js";
|
|
2
|
+
import { isBrowser, onLoaded, on, QUICK_EVENT, debounce } from "../utils.js";
|
|
3
3
|
import "./app-toggle2.js";
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
const CSS_APP = styles.app.split(" ")[0];
|
|
5
|
+
const CSS_STICKY = styles.sticky.split(" ")[0];
|
|
6
|
+
const CSS_TOGGLE = '[data-command="toggle-app-expanded"]';
|
|
7
|
+
const CSS_SIDEBAR = `.${CSS_APP} > dialog,.${CSS_APP} dialog ~ main`;
|
|
8
|
+
const STICKIES = isBrowser() ? document.getElementsByClassName(CSS_STICKY) : [];
|
|
9
|
+
const useTransition = (callback) => {
|
|
10
|
+
if (!document.startViewTransition) callback();
|
|
11
|
+
else document.startViewTransition(callback);
|
|
12
|
+
};
|
|
13
|
+
const toggleAppExpanded = (force) => (
|
|
7
14
|
// @ts-expect-error window.mtdsAppToggle comes from app-toggle.js
|
|
8
|
-
|
|
15
|
+
useTransition(() => window.mtdsToggleAppExpanded?.(force))
|
|
9
16
|
);
|
|
10
|
-
function
|
|
11
|
-
const
|
|
12
|
-
if (
|
|
13
|
-
return
|
|
14
|
-
if (
|
|
17
|
+
function handleAppToggleClick({ target: el, defaultPrevented: stop }) {
|
|
18
|
+
const link = el?.closest?.("a");
|
|
19
|
+
if (link?.closest("dialog") && link?.closest(CSS_SIDEBAR))
|
|
20
|
+
return closeSidebar();
|
|
21
|
+
if (stop || !(el instanceof HTMLButtonElement) || !el.matches(CSS_TOGGLE))
|
|
15
22
|
return;
|
|
16
|
-
getComputedStyle(
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
23
|
+
const isDesktop = getComputedStyle(el).position === "sticky";
|
|
24
|
+
if (isDesktop) toggleAppExpanded();
|
|
25
|
+
else
|
|
26
|
+
useTransition(() => {
|
|
27
|
+
const sidebar = document.querySelector(CSS_SIDEBAR);
|
|
28
|
+
sidebar?.setAttribute("data-closedby", "any");
|
|
29
|
+
sidebar?.showModal();
|
|
30
|
+
});
|
|
20
31
|
}
|
|
21
|
-
function
|
|
22
|
-
document.querySelector(
|
|
32
|
+
function closeSidebar() {
|
|
33
|
+
document.querySelector(CSS_SIDEBAR)?.close();
|
|
23
34
|
}
|
|
24
|
-
let
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
35
|
+
let MIN_Y = 0;
|
|
36
|
+
let SCROLL_UP;
|
|
37
|
+
let STICK = 0;
|
|
38
|
+
let STICK_H = 0;
|
|
39
|
+
let STICK_Y = 0;
|
|
40
|
+
let STUCK = false;
|
|
41
|
+
let WIN_H = 0;
|
|
42
|
+
let WIN_Y = 0;
|
|
43
|
+
function handleAppScroll() {
|
|
44
|
+
if (!STICKIES?.length) return;
|
|
45
|
+
const el = STICKIES[0];
|
|
46
|
+
const NEXT_Y = window.scrollY;
|
|
47
|
+
const NEXT_UP = NEXT_Y < WIN_Y;
|
|
48
|
+
WIN_Y = NEXT_Y;
|
|
49
|
+
if (NEXT_UP !== SCROLL_UP) {
|
|
50
|
+
MIN_Y = (el.parentElement?.getBoundingClientRect().top || 0) + WIN_Y;
|
|
51
|
+
SCROLL_UP = NEXT_UP;
|
|
52
|
+
STICK_H = el.offsetHeight;
|
|
53
|
+
STICK_Y = el.getBoundingClientRect().top + WIN_Y;
|
|
54
|
+
STUCK = el.offsetHeight <= window.innerHeight;
|
|
55
|
+
WIN_H = window.innerHeight;
|
|
56
|
+
}
|
|
57
|
+
if (STICK === -1 && STUCK) return;
|
|
58
|
+
if (STICK !== -1 && (STUCK || SCROLL_UP && WIN_Y <= STICK_Y)) {
|
|
59
|
+
el.style.setProperty("--pos", "sticky");
|
|
60
|
+
el.style.setProperty("--top", "0px");
|
|
61
|
+
STICK = -1;
|
|
62
|
+
} else if (STICK === -1 && !SCROLL_UP) {
|
|
63
|
+
el.style.setProperty("--pos", "relative");
|
|
64
|
+
el.style.setProperty("--top", `${Math.max(0, WIN_Y - MIN_Y)}px`);
|
|
65
|
+
STICK = 0;
|
|
66
|
+
} else if (STICK !== 1 && !SCROLL_UP && WIN_Y + WIN_H >= STICK_Y + STICK_H) {
|
|
67
|
+
el.style.setProperty("--pos", "sticky");
|
|
68
|
+
el.style.setProperty("--top", `${WIN_H - STICK_H}px`);
|
|
69
|
+
STICK = 1;
|
|
70
|
+
} else if (STICK === 1 && SCROLL_UP) {
|
|
71
|
+
el.style.setProperty("--pos", "relative");
|
|
72
|
+
el.style.setProperty("--top", `${STICK_Y - MIN_Y}px`);
|
|
73
|
+
STICK = 0;
|
|
74
|
+
}
|
|
29
75
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
76
|
+
onLoaded(() => [
|
|
77
|
+
on(document, "click", handleAppToggleClick, QUICK_EVENT),
|
|
78
|
+
on(window, "resize", debounce(closeSidebar, 100), QUICK_EVENT),
|
|
79
|
+
on(window, "scroll", handleAppScroll, QUICK_EVENT)
|
|
34
80
|
]);
|
|
35
81
|
export {
|
|
36
|
-
|
|
82
|
+
toggleAppExpanded
|
|
37
83
|
};
|
|
38
84
|
//# 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 { debounce,
|
|
1
|
+
{"version":3,"file":"app-observer.js","sources":["../../designsystem/app/app-observer.ts"],"sourcesContent":["import styles from \"../styles.module.css\";\nimport { debounce, isBrowser, on, onLoaded, QUICK_EVENT } from \"../utils\";\nimport \"./app-toggle\";\n\nconst CSS_APP = styles.app.split(\" \")[0];\nconst CSS_STICKY = styles.sticky.split(\" \")[0];\nconst CSS_TOGGLE = '[data-command=\"toggle-app-expanded\"]';\nconst CSS_SIDEBAR = `.${CSS_APP} > dialog,.${CSS_APP} dialog ~ main`;\nconst STICKIES = isBrowser() ? document.getElementsByClassName(CSS_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({ 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\n\tif (isDesktop) toggleAppExpanded();\n\telse\n\t\tuseTransition(() => {\n\t\t\tconst sidebar = document.querySelector<HTMLDialogElement>(CSS_SIDEBAR);\n\t\t\tsidebar?.setAttribute(\"data-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\nonLoaded(() => [\n\ton(document, \"click\", handleA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-1,27 +1,5 @@
|
|
|
1
|
-
const
|
|
2
|
-
typeof window !== "undefined" &&
|
|
3
|
-
window.CSSStyleSheet &&
|
|
4
|
-
document.adoptedStyleSheets
|
|
5
|
-
)
|
|
6
|
-
(() => {
|
|
7
|
-
const key = "--mtds-app-expanded";
|
|
8
|
-
const sheet = new CSSStyleSheet();
|
|
9
|
-
const prev = () => !window.localStorage.getItem(key)?.includes("false");
|
|
10
|
-
|
|
11
|
-
document.adoptedStyleSheets.push(sheet);
|
|
12
|
-
window.mtdsToggleAppExpanded = (force) => {
|
|
13
|
-
try {
|
|
14
|
-
const next = force ?? !prev();
|
|
15
|
-
sheet.replaceSync?.(\`:root { \${key}: var(\${key}--\${next})}\`);
|
|
16
|
-
window.localStorage.setItem(key, next);
|
|
17
|
-
} catch (_err) {} // localStorage is full or replaceSync is not supported
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
// Set and store initial state
|
|
21
|
-
window.mtdsToggleAppExpanded(prev());
|
|
22
|
-
})();
|
|
23
|
-
`;
|
|
1
|
+
const script = 'if (\n typeof window !== "undefined" &&\n window.CSSStyleSheet &&\n document.adoptedStyleSheets\n)\n (() => {\n const key = "--mtds-app-expanded";\n const sheet = new CSSStyleSheet();\n const prev = () => !window.localStorage.getItem(key)?.includes("false");\n\n document.adoptedStyleSheets.push(sheet);\n window.mtdsToggleAppExpanded = (force) => {\n try {\n const next = force ?? !prev();\n sheet.replaceSync?.(`:root { ${key}: var(${key}--${next})}`);\n window.localStorage.setItem(key, next);\n } catch (_err) {} // localStorage is full or replaceSync is not supported\n };\n\n // Set and store initial state\n window.mtdsToggleAppExpanded(prev());\n })();\n';
|
|
24
2
|
export {
|
|
25
|
-
|
|
3
|
+
script as default
|
|
26
4
|
};
|
|
27
5
|
//# sourceMappingURL=app-toggle.js.map
|