@mattilsynet/design 0.2.19 → 0.2.21

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/styles.json CHANGED
@@ -1,33 +1,32 @@
1
1
  {
2
- "validation": "_validation_1rgmg_1 _ds-validation-message_1w6ss_1",
3
- "tag": "_tag_1rgmg_1 _ds-tag_1w6ss_1",
4
- "tabs": "_tabs_1rgmg_1 _ds-tabs_1w6ss_1",
5
- "table": "_table_1rgmg_1 _ds-table_1w6ss_1",
6
- "scrollShadow": "_scrollShadow_1rgmg_1",
7
- "skeleton": "_skeleton_1rgmg_1 _ds-skeleton_1w6ss_1",
8
- "popover": "_popover_1rgmg_1",
9
- "pagination": "_pagination_1rgmg_1 _ds-pagination_1w6ss_1",
10
- "modal": "_modal_1rgmg_1 _ds-modal_1w6ss_1",
11
- "logo": "_logo_1rgmg_1 _ds-focus_1w6ss_1",
12
- "link": "_link_1rgmg_1",
13
- "grid": "_grid_1rgmg_1",
14
- "flex": "_flex_1rgmg_1",
15
- "input": "_input_1rgmg_1 _ds-input_1w6ss_1",
16
- "fieldset": "_fieldset_1rgmg_1 _ds-fieldset_1w6ss_1",
17
- "field": "_field_1rgmg_1 _ds-field_1w6ss_1",
18
- "affixes": "_affixes_1rgmg_1 _ds-field-affixes_1w6ss_1",
19
- "count": "_count_1rgmg_1",
20
- "errorsummary": "_errorsummary_1rgmg_1 _ds-error-summary_1w6ss_1",
21
- "details": "_details_1rgmg_1 _ds-details_1w6ss_1",
22
- "chip": "_chip_1rgmg_1 _ds-chip_1w6ss_1",
23
- "card": "_card_1rgmg_1",
24
- "info": "_info_1rgmg_1",
25
- "button": "_button_1rgmg_1 _ds-button_1w6ss_1",
26
- "breadcrumbs": "_breadcrumbs_1rgmg_1 _ds-breadcrumbs_1w6ss_1",
27
- "badge": "_badge_1rgmg_1",
28
- "avatar": "_avatar_1rgmg_1 _ds-avatar_1w6ss_1",
29
- "alert": "_alert_1rgmg_1 _ds-alert_1w6ss_1",
30
- "heading": "_heading_1rgmg_1 _ds-heading_1w6ss_1",
31
- "body": "_body_1rgmg_116",
32
- "tooltip": "_tooltip_1rgmg_131"
2
+ "tooltip": "_tooltip_ipkht_1",
3
+ "alert": "_alert_ipkht_1 _ds-alert_1w6ss_1",
4
+ "avatar": "_avatar_ipkht_1 _ds-avatar_1w6ss_1",
5
+ "badge": "_badge_ipkht_1",
6
+ "breadcrumbs": "_breadcrumbs_ipkht_1 _ds-breadcrumbs_1w6ss_1",
7
+ "button": "_button_ipkht_1 _ds-button_1w6ss_1",
8
+ "card": "_card_ipkht_1",
9
+ "chip": "_chip_ipkht_1 _ds-chip_1w6ss_1",
10
+ "details": "_details_ipkht_1 _ds-details_1w6ss_1",
11
+ "errorsummary": "_errorsummary_ipkht_1 _ds-error-summary_1w6ss_1",
12
+ "field": "_field_ipkht_1 _ds-field_1w6ss_1",
13
+ "affixes": "_affixes_ipkht_1 _ds-field-affixes_1w6ss_1",
14
+ "count": "_count_ipkht_1",
15
+ "fieldset": "_fieldset_ipkht_1 _ds-fieldset_1w6ss_1",
16
+ "heading": "_heading_ipkht_1 _ds-heading_1w6ss_1",
17
+ "input": "_input_ipkht_1 _ds-input_1w6ss_1",
18
+ "grid": "_grid_ipkht_1",
19
+ "flex": "_flex_ipkht_1",
20
+ "link": "_link_ipkht_1",
21
+ "logo": "_logo_ipkht_1 _ds-focus_1w6ss_1",
22
+ "modal": "_modal_ipkht_1 _ds-modal_1w6ss_1",
23
+ "pagination": "_pagination_ipkht_1 _ds-pagination_1w6ss_1",
24
+ "popover": "_popover_ipkht_1",
25
+ "skeleton": "_skeleton_ipkht_1 _ds-skeleton_1w6ss_1",
26
+ "table": "_table_ipkht_1 _ds-table_1w6ss_1",
27
+ "scrollShadow": "_scrollShadow_ipkht_1",
28
+ "tabs": "_tabs_ipkht_1 _ds-tabs_1w6ss_1",
29
+ "tag": "_tag_ipkht_1 _ds-tag_1w6ss_1",
30
+ "validation": "_validation_ipkht_1 _ds-validation-message_1w6ss_1",
31
+ "body": "_body_ipkht_115"
33
32
  }
@@ -1,68 +1,66 @@
1
- const _ = "_validation_1rgmg_1 _ds-validation-message_1w6ss_1", s = "_tag_1rgmg_1 _ds-tag_1w6ss_1", t = "_tabs_1rgmg_1 _ds-tabs_1w6ss_1", o = "_table_1rgmg_1 _ds-table_1w6ss_1", g = "_scrollShadow_1rgmg_1", a = "_skeleton_1rgmg_1 _ds-skeleton_1w6ss_1", r = "_popover_1rgmg_1", n = "_pagination_1rgmg_1 _ds-pagination_1w6ss_1", d = "_modal_1rgmg_1 _ds-modal_1w6ss_1", e = "_logo_1rgmg_1 _ds-focus_1w6ss_1", i = "_link_1rgmg_1", l = "_grid_1rgmg_1", c = "_flex_1rgmg_1", m = "_input_1rgmg_1 _ds-input_1w6ss_1", b = "_fieldset_1rgmg_1 _ds-fieldset_1w6ss_1", f = "_field_1rgmg_1 _ds-field_1w6ss_1", w = "_affixes_1rgmg_1 _ds-field-affixes_1w6ss_1", p = "_count_1rgmg_1", u = "_errorsummary_1rgmg_1 _ds-error-summary_1w6ss_1", h = "_details_1rgmg_1 _ds-details_1w6ss_1", v = "_chip_1rgmg_1 _ds-chip_1w6ss_1", x = "_card_1rgmg_1", y = "_info_1rgmg_1", k = "_button_1rgmg_1 _ds-button_1w6ss_1", S = "_breadcrumbs_1rgmg_1 _ds-breadcrumbs_1w6ss_1", j = "_badge_1rgmg_1", q = "_avatar_1rgmg_1 _ds-avatar_1w6ss_1", z = "_alert_1rgmg_1 _ds-alert_1w6ss_1", A = "_heading_1rgmg_1 _ds-heading_1w6ss_1", B = "_body_1rgmg_116", C = "_tooltip_1rgmg_131", D = {
2
- validation: _,
3
- tag: s,
4
- tabs: t,
5
- table: o,
6
- scrollShadow: g,
7
- skeleton: a,
8
- popover: r,
9
- pagination: n,
10
- modal: d,
11
- logo: e,
12
- link: i,
13
- grid: l,
14
- flex: c,
15
- input: m,
16
- fieldset: b,
17
- field: f,
18
- affixes: w,
19
- count: p,
20
- errorsummary: u,
21
- details: h,
22
- chip: v,
23
- card: x,
24
- info: y,
25
- button: k,
26
- breadcrumbs: S,
27
- badge: j,
28
- avatar: q,
29
- alert: z,
30
- heading: A,
31
- body: B,
32
- tooltip: C
1
+ const _ = "_alert_ipkht_1 _ds-alert_1w6ss_1", s = "_avatar_ipkht_1 _ds-avatar_1w6ss_1", t = "_badge_ipkht_1", o = "_breadcrumbs_ipkht_1 _ds-breadcrumbs_1w6ss_1", i = "_button_ipkht_1 _ds-button_1w6ss_1", a = "_card_ipkht_1", d = "_chip_ipkht_1 _ds-chip_1w6ss_1", n = "_details_ipkht_1 _ds-details_1w6ss_1", e = "_errorsummary_ipkht_1 _ds-error-summary_1w6ss_1", l = "_field_ipkht_1 _ds-field_1w6ss_1", p = "_affixes_ipkht_1 _ds-field-affixes_1w6ss_1", c = "_count_ipkht_1", r = "_fieldset_ipkht_1 _ds-fieldset_1w6ss_1", h = "_heading_ipkht_1 _ds-heading_1w6ss_1", k = "_input_ipkht_1 _ds-input_1w6ss_1", b = "_grid_ipkht_1", w = "_flex_ipkht_1", f = "_link_ipkht_1", g = "_logo_ipkht_1 _ds-focus_1w6ss_1", u = "_modal_ipkht_1 _ds-modal_1w6ss_1", m = "_pagination_ipkht_1 _ds-pagination_1w6ss_1", v = "_popover_ipkht_1", x = "_skeleton_ipkht_1 _ds-skeleton_1w6ss_1", y = "_table_ipkht_1 _ds-table_1w6ss_1", S = "_scrollShadow_ipkht_1", j = "_tabs_ipkht_1 _ds-tabs_1w6ss_1", q = "_tag_ipkht_1 _ds-tag_1w6ss_1", z = "_tooltip_ipkht_1", A = "_validation_ipkht_1 _ds-validation-message_1w6ss_1", B = "_body_ipkht_115", C = {
2
+ alert: _,
3
+ avatar: s,
4
+ badge: t,
5
+ breadcrumbs: o,
6
+ button: i,
7
+ card: a,
8
+ chip: d,
9
+ details: n,
10
+ errorsummary: e,
11
+ field: l,
12
+ affixes: p,
13
+ count: c,
14
+ fieldset: r,
15
+ heading: h,
16
+ input: k,
17
+ grid: b,
18
+ flex: w,
19
+ link: f,
20
+ logo: g,
21
+ modal: u,
22
+ pagination: m,
23
+ popover: v,
24
+ skeleton: x,
25
+ table: y,
26
+ scrollShadow: S,
27
+ tabs: j,
28
+ tag: q,
29
+ tooltip: z,
30
+ validation: A,
31
+ body: B
33
32
  };
34
33
  export {
35
- w as affixes,
36
- z as alert,
37
- q as avatar,
38
- j as badge,
34
+ p as affixes,
35
+ _ as alert,
36
+ s as avatar,
37
+ t as badge,
39
38
  B as body,
40
- S as breadcrumbs,
41
- k as button,
42
- x as card,
43
- v as chip,
44
- p as count,
45
- D as default,
46
- h as details,
47
- u as errorsummary,
48
- f as field,
49
- b as fieldset,
50
- c as flex,
51
- l as grid,
52
- A as heading,
53
- y as info,
54
- m as input,
55
- i as link,
56
- e as logo,
57
- d as modal,
58
- n as pagination,
59
- r as popover,
60
- g as scrollShadow,
61
- a as skeleton,
62
- o as table,
63
- t as tabs,
64
- s as tag,
65
- C as tooltip,
66
- _ as validation
39
+ o as breadcrumbs,
40
+ i as button,
41
+ a as card,
42
+ d as chip,
43
+ c as count,
44
+ C as default,
45
+ n as details,
46
+ e as errorsummary,
47
+ l as field,
48
+ r as fieldset,
49
+ w as flex,
50
+ b as grid,
51
+ h as heading,
52
+ k as input,
53
+ f as link,
54
+ g as logo,
55
+ u as modal,
56
+ m as pagination,
57
+ v as popover,
58
+ S as scrollShadow,
59
+ x as skeleton,
60
+ y as table,
61
+ j as tabs,
62
+ q as tag,
63
+ z as tooltip,
64
+ A as validation
67
65
  };
68
66
  //# sourceMappingURL=styles.module.css.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"styles.module.css.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"styles.module.css.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,18 @@
1
+ import { IS_BROWSER as I, attr as L, on as m, QUICK_EVENT as a, anchorPosition as p } from "../utils.js";
2
+ import f from "./tooltip.module.css.js";
3
+ const T = "aria-describedby", n = "aria-labelledby", A = "--mtds-tooltip-position", y = 100, s = "mtds-tooltip";
4
+ let o = null, c = Number.NEGATIVE_INFINITY, b = 0, e = null;
5
+ function r({ target: i }) {
6
+ const t = c + y - Date.now();
7
+ clearTimeout(b), b = setTimeout(P, Math.max(t, 0), i);
8
+ }
9
+ function P(i) {
10
+ var d;
11
+ if (c = Date.now(), !e || i === e) return;
12
+ let t = ((d = i == null ? void 0 : i.closest) == null ? void 0 : d.call(i, "[data-tooltip]")) || null;
13
+ if (t === o) return;
14
+ const l = (t == null ? void 0 : t.getAttribute("data-tooltip")) || "", u = (t == null ? void 0 : t.getAttribute("data-tooltip-position")) || window.getComputedStyle(t || document.body).getPropertyValue(A) || "top", E = !!(t != null && t.innerText.trim()) || (t == null ? void 0 : t.hasAttribute(n)) || (t == null ? void 0 : t.hasAttribute("aria-label"));
15
+ (!l || l === "false" || l === "true" || u === "none") && (t = null), t && (e.textContent = l), o == null || o.removeAttribute(o.getAttribute(n) === s ? n : T), p(e, !1), o = t, o == null || o.setAttribute(E ? T : n, s), e.togglePopover(!!t), p(e, t, u);
16
+ }
17
+ I && !document.getElementById(s) && (e = document.body.appendChild(document.createElement("div")), e.classList.add(...f.tooltip.split(" ")), e.id = s, L(e, "popover", "manual"), m(document, "blur,focus,mouseout,mouseover", r, a), m(window, "blur", r, a));
18
+ //# sourceMappingURL=tooltip.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tooltip.js","sources":["../../designsystem/tooltip/tooltip.ts"],"sourcesContent":["import { IS_BROWSER, QUICK_EVENT, anchorPosition, attr, on } from \"../utils\";\nimport styles from './tooltip.module.css';\n\nconst DESCRIBEDBY = 'aria-describedby';\nconst LABELLEDBY = 'aria-labelledby';\nconst POSITION_CSS_PROPERTY = '--mtds-tooltip-position';\nconst THROTTLE_DELAY = 100;\nconst TOOLTIP_ID = 'mtds-tooltip';\n\nlet ANCHOR: HTMLElement | null = null;\nlet LAST_CALL = Number.NEGATIVE_INFINITY;\nlet THROTTLE: number | ReturnType<typeof setTimeout> = 0;\nlet TOOLTIP: HTMLElement | null = null;\n\nfunction handleMove({ target }: Event) {\n const wait = LAST_CALL + THROTTLE_DELAY - Date.now();\n clearTimeout(THROTTLE);\n THROTTLE = setTimeout(handleMoveThrottled, Math.max(wait, 0), target);\n}\n\n// Using a throttled function to avoid performance issues\nfunction handleMoveThrottled(target: Element | null) {\n LAST_CALL = Date.now();\n\n if (!TOOLTIP || target === TOOLTIP) return; // Allow tooltip to be hovered, following https://www.w3.org/TR/WCAG21/#content-on-hover-or-focus\n let anchor = target?.closest?.<HTMLElement>('[data-tooltip]') || null;\n \n // No need to update\n if (anchor === ANCHOR) return;\n\n const content = anchor?.getAttribute('data-tooltip') || '';\n const position = anchor?.getAttribute('data-tooltip-position') || window.getComputedStyle(anchor || document.body).getPropertyValue(POSITION_CSS_PROPERTY) || 'top';\n const hasLabel = Boolean(anchor?.innerText.trim()) || anchor?.hasAttribute(LABELLEDBY) || anchor?.hasAttribute('aria-label');\n\n if (!content || content === 'false' || content === 'true' || position === 'none') anchor = null; // Do not show tooltip if boolish value\n if (anchor) TOOLTIP.textContent = content; // Only update content if new anchor\n\n ANCHOR?.removeAttribute(ANCHOR.getAttribute(LABELLEDBY) === TOOLTIP_ID ? LABELLEDBY : DESCRIBEDBY); // Unlink previous anchor\n anchorPosition(TOOLTIP, false); // Reset anchor position\n\n ANCHOR = anchor; // Store new anchor - might be null if no new anchor\n ANCHOR?.setAttribute(hasLabel ? DESCRIBEDBY : LABELLEDBY, TOOLTIP_ID); // Use tooltip as description if allready has label\n TOOLTIP.togglePopover(!!anchor);\n anchorPosition(TOOLTIP, anchor, position);\n}\n\n// Initialize if in browser and not already initialized\nif (IS_BROWSER && !document.getElementById(TOOLTIP_ID)) {\n TOOLTIP = document.body.appendChild(document.createElement('div'));\n TOOLTIP.classList.add(...styles.tooltip.split(' '));\n TOOLTIP.id = TOOLTIP_ID;\n attr(TOOLTIP, 'popover', 'manual');\n on(document, 'blur,focus,mouseout,mouseover', handleMove, QUICK_EVENT);\n on(window, 'blur', handleMove, QUICK_EVENT);\n}"],"names":["DESCRIBEDBY","LABELLEDBY","POSITION_CSS_PROPERTY","THROTTLE_DELAY","TOOLTIP_ID","ANCHOR","LAST_CALL","THROTTLE","TOOLTIP","handleMove","target","wait","handleMoveThrottled","anchor","_a","content","position","hasLabel","anchorPosition","IS_BROWSER","styles","attr","on","QUICK_EVENT"],"mappings":";;AAGA,MAAMA,IAAc,oBACdC,IAAa,mBACbC,IAAwB,2BACxBC,IAAiB,KACjBC,IAAa;AAEnB,IAAIC,IAA6B,MAC7BC,IAAY,OAAO,mBACnBC,IAAmD,GACnDC,IAA8B;AAElC,SAASC,EAAW,EAAE,QAAAC,KAAiB;AACrC,QAAMC,IAAOL,IAAYH,IAAiB,KAAK,IAAI;AACnD,eAAaI,CAAQ,GACrBA,IAAW,WAAWK,GAAqB,KAAK,IAAID,GAAM,CAAC,GAAGD,CAAM;AACtE;AAGA,SAASE,EAAoBF,GAAwB;;AAG/C,MAFJJ,IAAY,KAAK,IAAI,GAEjB,CAACE,KAAWE,MAAWF,EAAS;AACpC,MAAIK,MAASC,IAAAJ,KAAA,gBAAAA,EAAQ,YAAR,gBAAAI,EAAA,KAAAJ,GAA+B,sBAAqB;AAGjE,MAAIG,MAAWR,EAAQ;AAEvB,QAAMU,KAAUF,KAAA,gBAAAA,EAAQ,aAAa,oBAAmB,IAClDG,KAAWH,KAAA,gBAAAA,EAAQ,aAAa,6BAA4B,OAAO,iBAAiBA,KAAU,SAAS,IAAI,EAAE,iBAAiBX,CAAqB,KAAK,OACxJe,IAAW,GAAQJ,KAAA,QAAAA,EAAQ,UAAU,YAAWA,KAAA,gBAAAA,EAAQ,aAAaZ,QAAeY,KAAA,gBAAAA,EAAQ,aAAa;AAE3G,GAAA,CAACE,KAAWA,MAAY,WAAWA,MAAY,UAAUC,MAAa,YAAiBH,IAAA,OACvFA,QAAgB,cAAcE,IAElCV,KAAA,QAAAA,EAAQ,gBAAgBA,EAAO,aAAaJ,CAAU,MAAMG,IAAaH,IAAaD,IACtFkB,EAAeV,GAAS,EAAK,GAEpBH,IAAAQ,GACTR,KAAA,QAAAA,EAAQ,aAAaY,IAAWjB,IAAcC,GAAYG,IAClDI,EAAA,cAAc,CAAC,CAACK,CAAM,GACfK,EAAAV,GAASK,GAAQG,CAAQ;AAC1C;AAGIG,KAAc,CAAC,SAAS,eAAef,CAAU,MACnDI,IAAU,SAAS,KAAK,YAAY,SAAS,cAAc,KAAK,CAAC,GACjEA,EAAQ,UAAU,IAAI,GAAGY,EAAO,QAAQ,MAAM,GAAG,CAAC,GAClDZ,EAAQ,KAAKJ,GACRiB,EAAAb,GAAS,WAAW,QAAQ,GAC9Bc,EAAA,UAAU,iCAAiCb,GAAYc,CAAW,GAClED,EAAA,QAAQ,QAAQb,GAAYc,CAAW;"}
@@ -0,0 +1,8 @@
1
+ const t = "_tooltip_1pse6_5", o = {
2
+ tooltip: t
3
+ };
4
+ export {
5
+ o as default,
6
+ t as tooltip
7
+ };
8
+ //# sourceMappingURL=tooltip.module.css.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tooltip.module.css.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;"}
package/mtds/utils.js CHANGED
@@ -1,62 +1,61 @@
1
1
  const w = typeof window < "u" && typeof document < "u", U = { capture: !0, passive: !0 };
2
- function E(t, e, n) {
3
- return n === void 0 ? t.getAttribute(e) ?? null : (n === null ? t.removeAttribute(e) : t.getAttribute(e) !== n && t.setAttribute(e, n), null);
2
+ function C(t, e, o) {
3
+ return o === void 0 ? t.getAttribute(e) ?? null : (o === null ? t.removeAttribute(e) : t.getAttribute(e) !== o && t.setAttribute(e, o), null);
4
4
  }
5
- let B = 0;
6
- const I = `${Date.now().toString(36)}${Math.random().toString(36).slice(2, 5)}`;
7
- function R(t) {
8
- return t.id || (t.id = `${I}${++B}`), t.id;
5
+ let E = 0;
6
+ const O = `${Date.now().toString(36)}${Math.random().toString(36).slice(2, 5)}`;
7
+ function X(t) {
8
+ return t.id || (t.id = `${O}${++E}`), t.id;
9
9
  }
10
- const b = (t, e, n) => {
11
- for (const i of n[0].split(","))
12
- n[0] = i, e[`${t}EventListener`](...n);
13
- }, O = (t, ...e) => b("add", t, e), X = (t, ...e) => b("remove", t, e), l = /* @__PURE__ */ new Map(), s = w ? document.createElement("div") : null;
14
- s && E(s, "style", "position:absolute;padding:1px;top:0;left:0px");
15
- w && O(window, "load,resize,scroll", () => {
16
- for (const [t, e] of l) e();
10
+ const b = (t, e, o) => {
11
+ for (const i of o[0].split(","))
12
+ o[0] = i, e[`${t}EventListener`](...o);
13
+ }, B = (t, ...e) => b("add", t, e), Y = (t, ...e) => b("remove", t, e), a = /* @__PURE__ */ new Map(), s = w ? document.createElement("div") : null;
14
+ s && C(s, "style", "position:absolute;padding:1px;top:0;left:0px");
15
+ w && B(window, "load,resize,scroll", () => {
16
+ for (const [t, e] of a) e();
17
17
  }, U);
18
- const c = { top: 0, right: 1, bottom: 2, left: 3, none: 4 };
19
- function _(t, e, n) {
18
+ const d = { top: 0, right: 1, bottom: 2, left: 3 };
19
+ function _(t, e, o) {
20
20
  var p;
21
- if (!e || !e.isConnected || !t.isConnected) return l.delete(t);
22
- if (s != null && s.isConnected || document.body.append(s || ""), !l.has(t)) {
23
- const C = c[n] ?? c.bottom;
24
- return (p = l.set(t, () => _(t, e, C)).get(t)) == null ? void 0 : p();
21
+ if (!e || !e.isConnected || !t.isConnected) return a.delete(t);
22
+ if (s != null && s.isConnected || document.body.append(s || ""), !a.has(t)) {
23
+ const I = d[o] ?? d.bottom;
24
+ return (p = a.set(t, () => _(t, e, I)).get(t)) == null ? void 0 : p();
25
25
  }
26
- if (n === c.none) return t.style.setProperty("left", "-100vw");
27
- const { offsetWidth: i, offsetHeight: o } = t, { offsetWidth: r, offsetHeight: u } = e, { width: M, height: m, left: v, top: y } = e.getBoundingClientRect(), f = Math.round(v - (r - M) / 2), d = Math.round(y - (u - m) / 2), g = f - i > 0, A = r + r + i < window.innerWidth, T = d - o > 0, H = d + u + o < window.innerHeight, $ = n === c.bottom && A || !g, x = n === c.bottom && H || !T, S = Math.min(Math.max(10, f - (i - r) / 2), window.innerWidth - i - 10), W = Math.min(Math.max(10, d - (o - u) / 2), window.innerHeight - o - 10), h = n === c.top || n === c.bottom;
28
- t.style.left = `${Math.round(h ? S : $ ? f + r : f - i)}px`, t.style.top = `${Math.round(h ? x ? d + u : d - o : W)}px`, s == null || s.style.setProperty("translate", `${Math.round(window.scrollX + f + r + i + 30)} ${Math.round(window.scrollY + d + u + o + 30)}px`);
26
+ const { offsetWidth: i, offsetHeight: n } = t, { offsetWidth: c, offsetHeight: u } = e, { width: M, height: m, left: g, top: v } = e.getBoundingClientRect(), f = Math.round(g - (c - M) / 2), r = Math.round(v - (u - m) / 2), T = f - i > 0, y = c + c + i < window.innerWidth, A = r - n > 0, S = r + u + n < window.innerHeight, $ = o === d.bottom && y || !T, x = o === d.bottom && S || !A, H = Math.min(Math.max(10, f - (i - c) / 2), window.innerWidth - i - 10), W = Math.min(Math.max(10, r - (n - u) / 2), window.innerHeight - n - 10), h = o === d.top || o === d.bottom;
27
+ t.style.left = `${Math.round(h ? H : $ ? f + c : f - i)}px`, t.style.top = `${Math.round(h ? x ? r + u : r - n : W)}px`, s == null || s.style.setProperty("translate", `${Math.round(window.scrollX + f + c + i + 30)} ${Math.round(window.scrollY + r + u + n + 30)}px`);
29
28
  }
30
29
  function F(t) {
31
30
  let e = 0;
32
- const n = () => setTimeout(i, 200), i = () => {
33
- t([], o), e = 0;
34
- }, o = new MutationObserver(() => {
35
- e || (e = requestAnimationFrame(n));
31
+ const o = () => setTimeout(i, 200), i = () => {
32
+ t([], n), e = 0;
33
+ }, n = new MutationObserver(() => {
34
+ e || (e = requestAnimationFrame(o));
36
35
  });
37
- return o;
36
+ return n;
38
37
  }
39
- const a = /* @__PURE__ */ new WeakMap(), P = (t) => {
40
- var n;
41
- const e = a.get(t);
38
+ const l = /* @__PURE__ */ new WeakMap(), P = (t) => {
39
+ var o;
40
+ const e = l.get(t);
42
41
  if (!e || !t.isConnected)
43
- (n = e == null ? void 0 : e.observer) == null || n.disconnect(), a.delete(t);
42
+ (o = e == null ? void 0 : e.observer) == null || o.disconnect(), l.delete(t);
44
43
  else for (const [, i] of e.collections) i();
45
- }, Y = (t, e, n) => {
44
+ }, k = (t, e, o) => {
46
45
  const i = t.getElementsByClassName(e);
47
- let o = a.get(t);
48
- o || (o = { collections: /* @__PURE__ */ new Map(), observer: F(() => P(t)) }, o.observer.observe(t, { childList: !0, subtree: !0, attributes: !0, attributeFilter: ["class"] }), a.set(t, o)), n ? o.collections.set(e, () => n(i)) : o.collections.delete(e);
49
- }, k = (t) => t instanceof HTMLElement && "validity" in t && !(t instanceof HTMLButtonElement);
46
+ let n = l.get(t);
47
+ n || (n = { collections: /* @__PURE__ */ new Map(), observer: F(() => P(t)) }, n.observer.observe(t, { childList: !0, subtree: !0, attributes: !0, attributeFilter: ["class"] }), l.set(t, n)), o ? n.collections.set(e, () => o(i)) : n.collections.delete(e);
48
+ }, q = (t) => t instanceof HTMLElement && "validity" in t && !(t instanceof HTMLButtonElement);
50
49
  export {
51
50
  w as IS_BROWSER,
52
51
  U as QUICK_EVENT,
53
52
  _ as anchorPosition,
54
- E as attr,
53
+ C as attr,
55
54
  F as createOptimizedMutationObserver,
56
- k as isInputLike,
57
- X as off,
58
- O as on,
59
- Y as onMutation,
60
- R as useId
55
+ q as isInputLike,
56
+ Y as off,
57
+ B as on,
58
+ k as onMutation,
59
+ X as useId
61
60
  };
62
61
  //# sourceMappingURL=utils.js.map
package/mtds/utils.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sources":["../designsystem/utils.ts"],"sourcesContent":["export const IS_BROWSER = typeof window !== 'undefined' && typeof document !== 'undefined';\nexport const QUICK_EVENT = { capture: true, passive: true };\n\n/**\n * attr\n * @description Utility to quickly get, set and remove attributes\n * @param el The Element to use as EventTarget\n * @param name The attribute name to get, set or remove, or a object to set multiple attributes\n * @param value A valid attribute value or null to remove attribute\n */\nexport function attr(\n\tel: Element,\n\tname: string,\n\tvalue?: string | null,\n): string | null {\n\tif (value === undefined) return el.getAttribute(name) ?? null; // Fallback to null only if el is undefined\n\tif (value === null) el.removeAttribute(name);\n\telse if (el.getAttribute(name) !== value) el.setAttribute(name, value);\n\treturn null;\n}\n\n/**\n * useId\n * @return A generated unique ID\n */\nlet id = 0;\nconst UUID = `${Date.now().toString(36)}${Math.random().toString(36).slice(2, 5)}`;\nexport function useId (el: Element) {\n if (!el.id) el.id = `${UUID}${++id}`;\n\treturn el.id;\n};\n\n// Internal helper for on / off\nconst events = (\n\taction: \"add\" | \"remove\",\n\telement: Node | Window,\n\trest: Parameters<typeof Element.prototype.addEventListener>,\n): void => {\n\tfor (const type of rest[0].split(\",\")) {\n\t\trest[0] = type;\n\t\telement[`${action}EventListener`](...rest);\n\t}\n};\n\n/**\n * on\n * @param element The Element to use as EventTarget\n * @param types A comma separated string of event types\n * @param listener An event listener function or listener object\n */\nexport const on = (\n\telement: Node | Window,\n\t...rest: Parameters<typeof Element.prototype.addEventListener>\n): void => events(\"add\", element, rest);\n\n/**\n * off\n * @param element The Element to use as EventTarget\n * @param types A comma separated string of event types\n * @param listener An event listener function or listener object\n */\nexport const off = (\n\telement: Node | Window,\n\t...rest: Parameters<typeof Element.prototype.removeEventListener>\n): void => events(\"remove\", element, rest);\n\n\nconst TARGETS = new Map<Element, () => void>(); // Store current open poppers and their update functions\nconst SCROLLER = IS_BROWSER ? document.createElement('div') : null // Used to ensure we have scrollability under\nif (SCROLLER) attr(SCROLLER, 'style', 'position:absolute;padding:1px;top:0;left:0px');\n\nif (IS_BROWSER){\n\ton(window, 'load,resize,scroll', () => {\n\t\tfor (const [_, update] of TARGETS) update();\n\t}, QUICK_EVENT);}\n\t\n/**\n * anchorPosition\n * @param target The Element to position\n * @param anchor The Element to use as anchor\n */\ntype AnchorKeys = keyof typeof ANCHOR;\nconst ANCHOR = { top: 0, right: 1, bottom: 2, left: 3, none: 4 }; // Speed up by using a const map\n\nexport function anchorPosition (target: HTMLElement, anchor: HTMLElement | null | false, position?: string | number) {\n\tif (!anchor || !anchor.isConnected || !target.isConnected) return TARGETS.delete(target); // Stop watchning if anchor is removed from DOM\n\tif (!SCROLLER?.isConnected) document.body.append(SCROLLER || ''); // Ensure we have t´he scroller\n\tif (!TARGETS.has(target)) { // Setup new target or update position\n\t\tconst place = ANCHOR[position as keyof typeof ANCHOR] ?? ANCHOR.bottom; // Use CSS property to store position for more flexibility\n\t\treturn TARGETS.set(target, () => anchorPosition(target, anchor, place)).get(target)?.(); // Start watching if not already watching\n\t}\n\tif (position === ANCHOR.none) return target.style.setProperty('left', '-100vw'); // Hide target if anchor is set to none\n\n const { offsetWidth: targetW, offsetHeight: targetH } = target;\n const { offsetWidth: anchorW, offsetHeight: anchorH } = anchor;\n const { width, height, left, top } = anchor.getBoundingClientRect();\n\tconst anchorX = Math.round(left - (anchorW - width) / 2); // Correct for CSS transform scale\n const anchorY = Math.round(top - (anchorH - height) / 2); // Correct for CSS transform scale\n\n\tconst hasSpaceLeft = anchorX - targetW > 0\n\tconst hasSpaceRight = anchorW + anchorW + targetW < window.innerWidth;\n\tconst hasSpaceOver = anchorY - targetH > 0\n\tconst hasSpaceUnder = anchorY + anchorH + targetH < window.innerHeight;\n\tconst positionRight = (position === ANCHOR.bottom && hasSpaceRight) || !hasSpaceLeft // Always position right when no hasSpaceLeft, as no OS scrolls further up than 0\n\tconst positionUnder = (position === ANCHOR.bottom && hasSpaceUnder) || !hasSpaceOver // Always position under when no hasSpaceOver, as no OS scrolls further up than 0\n\tconst centerX = Math.min(Math.max(10, anchorX - (targetW - anchorW) / 2), window.innerWidth - targetW - 10);\n\tconst centerY = Math.min(Math.max(10, anchorY - (targetH - anchorH) / 2), window.innerHeight - targetH - 10);\n\tconst isVertical = position === ANCHOR.top || position === ANCHOR.bottom;\n\n\ttarget.style.left = `${Math.round(isVertical ? centerX : (positionRight ? anchorX + anchorW : anchorX - targetW))}px`\n target.style.top = `${Math.round(isVertical ? (positionUnder ? anchorY + anchorH : anchorY - targetH) : centerY)}px`\n SCROLLER?.style.setProperty('translate', `${Math.round(window.scrollX + anchorX + anchorW + targetW + 30)} ${Math.round(window.scrollY + anchorY + anchorH + targetH + 30)}px`);\n}\n\n/**\n * Speed up MutationObserver by debouncing and only running when page is visible\n * @return new MutaionObserver\n */\nexport function createOptimizedMutationObserver(callback: MutationCallback) {\n let queue = 0;\n\n\tconst onFrame = () => setTimeout(onTimer, 200); // Use both requestAnimationFrame and setTimeout to debounce and only run when visible\n\tconst onTimer = () => {\n\t\tcallback([], observer);\n\t\tqueue = 0;\n\t};\n const observer = new MutationObserver(() => {\n if (!queue) queue = requestAnimationFrame(onFrame);\n });\n\n return observer;\n}\n\ntype Mutator = { observer: MutationObserver, collections: Map<string, () => void> };\nconst MUTATORS = new WeakMap<Element, Mutator>();\nconst MUTATORS_CALLBACK = (element: Element) => {\n\tconst mutator = MUTATORS.get(element);\n\n\tif (!mutator || !element.isConnected) {\n\t\tmutator?.observer?.disconnect();\n\t\tMUTATORS.delete(element);\n\t} else for(const [, callback] of mutator.collections) callback();\n};\n\n/**\n * onMutation\n * @description Utility to quickly observe mutations on a specific class name\n * @param element The Element to use as EventTarget\n * @param className The class name to observe\n * @param callback The callback to run when mutations are detected or false to stop observing\n */\nexport const onMutation = (\n\telement: Element,\n\tclassName: string,\n\tcallback: ((collection: HTMLCollection) => void) | false\n) => {\n\tconst collection = element.getElementsByClassName(className);\n\tlet mutator = MUTATORS.get(element);\n\n\tif (!mutator) {\n\t\tmutator = { collections: new Map(), observer: createOptimizedMutationObserver(() => MUTATORS_CALLBACK(element)) };\n\t\tmutator.observer.observe(element, { childList: true, subtree: true, attributes: true, attributeFilter: ['class'] });\n\t\tMUTATORS.set(element, mutator);\n\t}\n\tif (callback) mutator.collections.set(className, () => callback(collection));\n\telse mutator.collections.delete(className);\n}\n\nexport const isInputLike = (el: unknown): el is HTMLInputElement =>\n\tel instanceof HTMLElement && 'validity' in el && !(el instanceof HTMLButtonElement);\n\n// Make React support popover=\"\"target attribute\n// https://github.com/facebook/react/issues/27479\ntype Popover = \"\" | \"auto\" | \"manual\" | undefined;\ndeclare global {\n\tnamespace React.JSX {\n\t\tinterface IntrinsicAttributes {\n\t\t\tpopovertargetaction?: string;\n\t\t\tpopovertarget?: string;\n\t\t\tpopover?: Popover;\n\t\t}\n\t}\n\tnamespace React {\n\t\tinterface HTMLAttributes<T> {\n\t\t\tpopovertargetaction?: string;\n\t\t\tpopovertarget?: string;\n\t\t\tpopover?: Popover;\n\t\t}\n\t}\n}"],"names":["IS_BROWSER","QUICK_EVENT","attr","el","name","value","id","UUID","useId","events","action","element","rest","type","on","off","TARGETS","SCROLLER","_","update","ANCHOR","anchorPosition","target","anchor","position","_a","place","targetW","targetH","anchorW","anchorH","width","height","left","top","anchorX","anchorY","hasSpaceLeft","hasSpaceRight","hasSpaceOver","hasSpaceUnder","positionRight","positionUnder","centerX","centerY","isVertical","createOptimizedMutationObserver","callback","queue","onFrame","onTimer","observer","MUTATORS","MUTATORS_CALLBACK","mutator","onMutation","className","collection","isInputLike"],"mappings":"AAAO,MAAMA,IAAa,OAAO,SAAW,OAAe,OAAO,WAAa,KAClEC,IAAc,EAAE,SAAS,IAAM,SAAS,GAAK;AAS1C,SAAAC,EACfC,GACAC,GACAC,GACgB;AAChB,SAAIA,MAAU,SAAkBF,EAAG,aAAaC,CAAI,KAAK,QACrDC,MAAU,OAASF,EAAA,gBAAgBC,CAAI,IAClCD,EAAG,aAAaC,CAAI,MAAMC,KAAUF,EAAA,aAAaC,GAAMC,CAAK,GAC9D;AACR;AAMA,IAAIC,IAAK;AAC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EAAEA,aAAc;"}
1
+ {"version":3,"file":"utils.js","sources":["../designsystem/utils.ts"],"sourcesContent":["export const IS_BROWSER = typeof window !== 'undefined' && typeof document !== 'undefined';\nexport const QUICK_EVENT = { capture: true, passive: true };\n\n/**\n * attr\n * @description Utility to quickly get, set and remove attributes\n * @param el The Element to use as EventTarget\n * @param name The attribute name to get, set or remove, or a object to set multiple attributes\n * @param value A valid attribute value or null to remove attribute\n */\nexport function attr(\n\tel: Element,\n\tname: string,\n\tvalue?: string | null,\n): string | null {\n\tif (value === undefined) return el.getAttribute(name) ?? null; // Fallback to null only if el is undefined\n\tif (value === null) el.removeAttribute(name);\n\telse if (el.getAttribute(name) !== value) el.setAttribute(name, value);\n\treturn null;\n}\n\n/**\n * useId\n * @return A generated unique ID\n */\nlet id = 0;\nconst UUID = `${Date.now().toString(36)}${Math.random().toString(36).slice(2, 5)}`;\nexport function useId (el: Element) {\n if (!el.id) el.id = `${UUID}${++id}`;\n\treturn el.id;\n};\n\n// Internal helper for on / off\nconst events = (\n\taction: \"add\" | \"remove\",\n\telement: Node | Window,\n\trest: Parameters<typeof Element.prototype.addEventListener>,\n): void => {\n\tfor (const type of rest[0].split(\",\")) {\n\t\trest[0] = type;\n\t\telement[`${action}EventListener`](...rest);\n\t}\n};\n\n/**\n * on\n * @param element The Element to use as EventTarget\n * @param types A comma separated string of event types\n * @param listener An event listener function or listener object\n */\nexport const on = (\n\telement: Node | Window,\n\t...rest: Parameters<typeof Element.prototype.addEventListener>\n): void => events(\"add\", element, rest);\n\n/**\n * off\n * @param element The Element to use as EventTarget\n * @param types A comma separated string of event types\n * @param listener An event listener function or listener object\n */\nexport const off = (\n\telement: Node | Window,\n\t...rest: Parameters<typeof Element.prototype.removeEventListener>\n): void => events(\"remove\", element, rest);\n\n\nconst TARGETS = new Map<Element, () => void>(); // Store current open poppers and their update functions\nconst SCROLLER = IS_BROWSER ? document.createElement('div') : null // Used to ensure we have scrollability under\nif (SCROLLER) attr(SCROLLER, 'style', 'position:absolute;padding:1px;top:0;left:0px');\n\nif (IS_BROWSER){\n\ton(window, 'load,resize,scroll', () => {\n\t\tfor (const [_, update] of TARGETS) update();\n\t}, QUICK_EVENT);}\n\t\n/**\n * anchorPosition\n * @param target The Element to position\n * @param anchor The Element to use as anchor\n */\nconst POSITION = { top: 0, right: 1, bottom: 2, left: 3 }; // Speed up by using a const map\n\nexport function anchorPosition (target: HTMLElement, anchor: HTMLElement | null | false, position?: string | number) {\n\tif (!anchor || !anchor.isConnected || !target.isConnected) return TARGETS.delete(target); // Stop watchning if anchor is removed from DOM\n\tif (!SCROLLER?.isConnected) document.body.append(SCROLLER || ''); // Ensure we have t´he scroller\n\tif (!TARGETS.has(target)) { // Setup new target or update position\n\t\tconst place = POSITION[position as keyof typeof POSITION] ?? POSITION.bottom; // Use CSS property to store position for more flexibility\n\t\treturn TARGETS.set(target, () => anchorPosition(target, anchor, place)).get(target)?.(); // Start watching if not already watching\n\t}\n\n const { offsetWidth: targetW, offsetHeight: targetH } = target;\n const { offsetWidth: anchorW, offsetHeight: anchorH } = anchor;\n const { width, height, left, top } = anchor.getBoundingClientRect();\n\tconst anchorX = Math.round(left - (anchorW - width) / 2); // Correct for CSS transform scale\n const anchorY = Math.round(top - (anchorH - height) / 2); // Correct for CSS transform scale\n\n\tconst hasSpaceLeft = anchorX - targetW > 0\n\tconst hasSpaceRight = anchorW + anchorW + targetW < window.innerWidth;\n\tconst hasSpaceOver = anchorY - targetH > 0\n\tconst hasSpaceUnder = anchorY + anchorH + targetH < window.innerHeight;\n\tconst positionRight = (position === POSITION.bottom && hasSpaceRight) || !hasSpaceLeft // Always position right when no hasSpaceLeft, as no OS scrolls further up than 0\n\tconst positionUnder = (position === POSITION.bottom && hasSpaceUnder) || !hasSpaceOver // Always position under when no hasSpaceOver, as no OS scrolls further up than 0\n\tconst centerX = Math.min(Math.max(10, anchorX - (targetW - anchorW) / 2), window.innerWidth - targetW - 10);\n\tconst centerY = Math.min(Math.max(10, anchorY - (targetH - anchorH) / 2), window.innerHeight - targetH - 10);\n\tconst isVertical = position === POSITION.top || position === POSITION.bottom;\n\n\ttarget.style.left = `${Math.round(isVertical ? centerX : (positionRight ? anchorX + anchorW : anchorX - targetW))}px`\n target.style.top = `${Math.round(isVertical ? (positionUnder ? anchorY + anchorH : anchorY - targetH) : centerY)}px`\n SCROLLER?.style.setProperty('translate', `${Math.round(window.scrollX + anchorX + anchorW + targetW + 30)} ${Math.round(window.scrollY + anchorY + anchorH + targetH + 30)}px`);\n}\n\n/**\n * Speed up MutationObserver by debouncing and only running when page is visible\n * @return new MutaionObserver\n */\nexport function createOptimizedMutationObserver(callback: MutationCallback) {\n let queue = 0;\n\n\tconst onFrame = () => setTimeout(onTimer, 200); // Use both requestAnimationFrame and setTimeout to debounce and only run when visible\n\tconst onTimer = () => {\n\t\tcallback([], observer);\n\t\tqueue = 0;\n\t};\n const observer = new MutationObserver(() => {\n if (!queue) queue = requestAnimationFrame(onFrame);\n });\n\n return observer;\n}\n\ntype Mutator = { observer: MutationObserver, collections: Map<string, () => void> };\nconst MUTATORS = new WeakMap<Element, Mutator>();\nconst MUTATORS_CALLBACK = (element: Element) => {\n\tconst mutator = MUTATORS.get(element);\n\n\tif (!mutator || !element.isConnected) {\n\t\tmutator?.observer?.disconnect();\n\t\tMUTATORS.delete(element);\n\t} else for(const [, callback] of mutator.collections) callback();\n};\n\n/**\n * onMutation\n * @description Utility to quickly observe mutations on a specific class name\n * @param element The Element to use as EventTarget\n * @param className The class name to observe\n * @param callback The callback to run when mutations are detected or false to stop observing\n */\nexport const onMutation = (\n\telement: Element,\n\tclassName: string,\n\tcallback: ((collection: HTMLCollection) => void) | false\n) => {\n\tconst collection = element.getElementsByClassName(className);\n\tlet mutator = MUTATORS.get(element);\n\n\tif (!mutator) {\n\t\tmutator = { collections: new Map(), observer: createOptimizedMutationObserver(() => MUTATORS_CALLBACK(element)) };\n\t\tmutator.observer.observe(element, { childList: true, subtree: true, attributes: true, attributeFilter: ['class'] });\n\t\tMUTATORS.set(element, mutator);\n\t}\n\tif (callback) mutator.collections.set(className, () => callback(collection));\n\telse mutator.collections.delete(className);\n}\n\nexport const isInputLike = (el: unknown): el is HTMLInputElement =>\n\tel instanceof HTMLElement && 'validity' in el && !(el instanceof HTMLButtonElement);\n\n// Make React support popover=\"\"target attribute\n// https://github.com/facebook/react/issues/27479\ntype Popover = \"\" | \"auto\" | \"manual\" | undefined;\ndeclare global {\n\tnamespace React.JSX {\n\t\tinterface IntrinsicAttributes {\n\t\t\tpopovertargetaction?: string;\n\t\t\tpopovertarget?: string;\n\t\t\tpopover?: Popover;\n\t\t}\n\t}\n\tnamespace React {\n\t\tinterface HTMLAttributes<T> {\n\t\t\tpopovertargetaction?: string;\n\t\t\tpopovertarget?: string;\n\t\t\tpopover?: Popover;\n\t\t}\n\t}\n}"],"names":["IS_BROWSER","QUICK_EVENT","attr","el","name","value","id","UUID","useId","events","action","element","rest","type","on","off","TARGETS","SCROLLER","_","update","POSITION","anchorPosition","target","anchor","position","_a","place","targetW","targetH","anchorW","anchorH","width","height","left","top","anchorX","anchorY","hasSpaceLeft","hasSpaceRight","hasSpaceOver","hasSpaceUnder","positionRight","positionUnder","centerX","centerY","isVertical","createOptimizedMutationObserver","callback","queue","onFrame","onTimer","observer","MUTATORS","MUTATORS_CALLBACK","mutator","onMutation","className","collection","isInputLike"],"mappings":"AAAO,MAAMA,IAAa,OAAO,SAAW,OAAe,OAAO,WAAa,KAClEC,IAAc,EAAE,SAAS,IAAM,SAAS,GAAK;AAS1C,SAAAC,EACfC,GACAC,GACAC,GACgB;AAChB,SAAIA,MAAU,SAAkBF,EAAG,aAAaC,CAAI,KAAK,QACrDC,MAAU,OAASF,EAAA,gBAAgBC,CAAI,IAClCD,EAAG,aAAaC,CAAI,MAAMC,KAAUF,EAAA,aAAaC,GAAMC,CAAK,GAC9D;AACR;AAMA,IAAIC,IAAK;AACT,MAAMC,IAAO,GAAG,KAAK,IAAM,EAAA,SAAS,EAAE,CAAC,G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/index.js",
6
6
  "types": "./mtds/index.d.ts",
package/mtds/tooltip.js DELETED
@@ -1,18 +0,0 @@
1
- import T from "./styles.module.css.js";
2
- import { IS_BROWSER as b, attr as c, on as d, QUICK_EVENT as u, useId as f, anchorPosition as s } from "./utils.js";
3
- const E = "--mtds-tooltip-position", I = 100;
4
- let l = null, m = Number.NEGATIVE_INFINITY, a = 0, e = null;
5
- b && (e = document.body.appendChild(document.createElement("div")), e.classList.add(...T.tooltip.split(" ")), c(e, "popover", "manual"), d(document, "blur,focus,mouseout,mouseover", p, u), d(window, "blur", p, u));
6
- function p({ target: o }) {
7
- const t = m + I - Date.now();
8
- clearTimeout(a), a = setTimeout(L, Math.max(t, 0), o);
9
- }
10
- function L(o) {
11
- var n;
12
- if (m = Date.now(), !e || o === e) return;
13
- let t = ((n = o == null ? void 0 : o.closest) == null ? void 0 : n.call(o, "[data-tooltip],[data-expanded]")) || null;
14
- if (t === l) return;
15
- const i = (t == null ? void 0 : t.getAttribute("data-tooltip")) || (t == null ? void 0 : t.getAttribute("data-expanded")) || e.textContent || "", r = (t == null ? void 0 : t.getAttribute("data-tooltip-position")) || window.getComputedStyle(t || document.body).getPropertyValue(E) || "top";
16
- (!i || i === "false" || i === "true") && (t = null), l == null || l.removeAttribute("aria-labelledby"), l = t, l == null || l.setAttribute("aria-labelledby", f(e)), e.togglePopover(!!t), e.replaceChildren(i), s(e, !1), s(e, t, r);
17
- }
18
- //# sourceMappingURL=tooltip.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"tooltip.js","sources":["../designsystem/tooltip.ts"],"sourcesContent":["import styles from './styles.module.css';\nimport { IS_BROWSER, QUICK_EVENT, anchorPosition, attr, on, useId } from \"./utils\";\n\nconst POSITION_CSS_PROPERTY = '--mtds-tooltip-position';\nconst THROTTLE_DELAY = 100;\nlet ANCHOR: Element | null = null;\nlet LAST_CALL = Number.NEGATIVE_INFINITY;\nlet THROTTLE: number | ReturnType<typeof setTimeout> = 0;\nlet TOOLTIP: HTMLElement | null = null;\n\nif (IS_BROWSER) {\n TOOLTIP = document.body.appendChild(document.createElement('div'));\n TOOLTIP.classList.add(...styles.tooltip.split(' '));\n attr(TOOLTIP, 'popover', 'manual');\n on(document, 'blur,focus,mouseout,mouseover', handleMove, QUICK_EVENT);\n on(window, 'blur', handleMove, QUICK_EVENT);\n}\n\nfunction handleMove({ target }: Event) {\n const wait = LAST_CALL + THROTTLE_DELAY - Date.now();\n clearTimeout(THROTTLE);\n THROTTLE = setTimeout(handleMoveThrottled, Math.max(wait, 0), target);\n}\n\n// Using a throttled function to avoid performance issues\nfunction handleMoveThrottled(target: Element | null) {\n LAST_CALL = Date.now();\n\n if (!TOOLTIP || target === TOOLTIP) return; // Allow tooltip to be hovered, following https://www.w3.org/TR/WCAG21/#content-on-hover-or-focus\n let anchor = target?.closest?.<HTMLElement>('[data-tooltip],[data-expanded]') || null;\n \n // No need to update\n if (anchor === ANCHOR) return;\n\n // Do not show tooltip if boolish value\n const content = anchor?.getAttribute('data-tooltip') || anchor?.getAttribute('data-expanded') || TOOLTIP.textContent || '';\n const position = anchor?.getAttribute('data-tooltip-position') || window.getComputedStyle(anchor || document.body).getPropertyValue(POSITION_CSS_PROPERTY) || 'top';\n if (!content || content === 'false' || content === 'true') anchor = null;\n \n ANCHOR?.removeAttribute('aria-labelledby'); // Unbind previous anchor\n ANCHOR = anchor; // Store new anchor - might be null if no new anchor\n\n ANCHOR?.setAttribute('aria-labelledby', useId(TOOLTIP));\n TOOLTIP.togglePopover(!!anchor);\n TOOLTIP.replaceChildren(content);\n anchorPosition(TOOLTIP, false); // Reset anchor position\n anchorPosition(TOOLTIP, anchor, position);\n}"],"names":["POSITION_CSS_PROPERTY","THROTTLE_DELAY","ANCHOR","LAST_CALL","THROTTLE","TOOLTIP","IS_BROWSER","styles","attr","on","handleMove","QUICK_EVENT","target","wait","handleMoveThrottled","anchor","_a","content","position","useId","anchorPosition"],"mappings":";;AAGA,MAAMA,IAAwB,2BACxBC,IAAiB;AAC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