@mattilsynet/design 0.2.16 → 0.2.18

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,33 @@
1
1
  {
2
- "validation": "_validation_cpy8b_1 _ds-validation-message_1w6ss_1",
3
- "tag": "_tag_cpy8b_1 _ds-tag_1w6ss_1",
4
- "tabs": "_tabs_cpy8b_1 _ds-tabs_1w6ss_1",
5
- "table": "_table_cpy8b_1 _ds-table_1w6ss_1",
6
- "scrollShadow": "_scrollShadow_cpy8b_1",
7
- "skeleton": "_skeleton_cpy8b_1 _ds-skeleton_1w6ss_1",
8
- "popover": "_popover_cpy8b_1",
9
- "pagination": "_pagination_cpy8b_1 _ds-pagination_1w6ss_1",
10
- "modal": "_modal_cpy8b_1 _ds-modal_1w6ss_1",
11
- "logo": "_logo_cpy8b_1 _ds-focus_1w6ss_1",
12
- "link": "_link_cpy8b_1",
13
- "grid": "_grid_cpy8b_1",
14
- "flex": "_flex_cpy8b_1",
15
- "input": "_input_cpy8b_1 _ds-input_1w6ss_1",
16
- "fieldset": "_fieldset_cpy8b_1 _ds-fieldset_1w6ss_1",
17
- "field": "_field_cpy8b_1 _ds-field_1w6ss_1",
18
- "affixes": "_affixes_cpy8b_1 _ds-field-affixes_1w6ss_1",
19
- "count": "_count_cpy8b_1",
20
- "errorsummary": "_errorsummary_cpy8b_1 _ds-error-summary_1w6ss_1",
21
- "details": "_details_cpy8b_1 _ds-details_1w6ss_1",
22
- "chip": "_chip_cpy8b_1 _ds-chip_1w6ss_1",
23
- "card": "_card_cpy8b_1",
24
- "info": "_info_cpy8b_1",
25
- "button": "_button_cpy8b_1 _ds-button_1w6ss_1",
26
- "breadcrumbs": "_breadcrumbs_cpy8b_1 _ds-breadcrumbs_1w6ss_1",
27
- "badge": "_badge_cpy8b_1",
28
- "avatar": "_avatar_cpy8b_1 _ds-avatar_1w6ss_1",
29
- "alert": "_alert_cpy8b_1 _ds-alert_1w6ss_1",
30
- "heading": "_heading_cpy8b_1 _ds-heading_1w6ss_1",
31
- "body": "_body_cpy8b_113",
32
- "tooltip": "_tooltip_cpy8b_128"
2
+ "validation": "_validation_14niv_1 _ds-validation-message_1w6ss_1",
3
+ "tag": "_tag_14niv_1 _ds-tag_1w6ss_1",
4
+ "tabs": "_tabs_14niv_1 _ds-tabs_1w6ss_1",
5
+ "table": "_table_14niv_1 _ds-table_1w6ss_1",
6
+ "scrollShadow": "_scrollShadow_14niv_1",
7
+ "skeleton": "_skeleton_14niv_1 _ds-skeleton_1w6ss_1",
8
+ "popover": "_popover_14niv_1",
9
+ "pagination": "_pagination_14niv_1 _ds-pagination_1w6ss_1",
10
+ "modal": "_modal_14niv_1 _ds-modal_1w6ss_1",
11
+ "logo": "_logo_14niv_1 _ds-focus_1w6ss_1",
12
+ "link": "_link_14niv_1",
13
+ "grid": "_grid_14niv_1",
14
+ "flex": "_flex_14niv_1",
15
+ "input": "_input_14niv_1 _ds-input_1w6ss_1",
16
+ "fieldset": "_fieldset_14niv_1 _ds-fieldset_1w6ss_1",
17
+ "field": "_field_14niv_1 _ds-field_1w6ss_1",
18
+ "affixes": "_affixes_14niv_1 _ds-field-affixes_1w6ss_1",
19
+ "count": "_count_14niv_1",
20
+ "errorsummary": "_errorsummary_14niv_1 _ds-error-summary_1w6ss_1",
21
+ "details": "_details_14niv_1 _ds-details_1w6ss_1",
22
+ "chip": "_chip_14niv_1 _ds-chip_1w6ss_1",
23
+ "card": "_card_14niv_1",
24
+ "info": "_info_14niv_1",
25
+ "button": "_button_14niv_1 _ds-button_1w6ss_1",
26
+ "breadcrumbs": "_breadcrumbs_14niv_1 _ds-breadcrumbs_1w6ss_1",
27
+ "badge": "_badge_14niv_1",
28
+ "avatar": "_avatar_14niv_1 _ds-avatar_1w6ss_1",
29
+ "alert": "_alert_14niv_1 _ds-alert_1w6ss_1",
30
+ "heading": "_heading_14niv_1 _ds-heading_1w6ss_1",
31
+ "body": "_body_14niv_114",
32
+ "tooltip": "_tooltip_14niv_129"
33
33
  }
@@ -1,27 +1,27 @@
1
- const _ = "_validation_cpy8b_1 _ds-validation-message_1w6ss_1", s = "_tag_cpy8b_1 _ds-tag_1w6ss_1", t = "_tabs_cpy8b_1 _ds-tabs_1w6ss_1", o = "_table_cpy8b_1 _ds-table_1w6ss_1", c = "_scrollShadow_cpy8b_1", a = "_skeleton_cpy8b_1 _ds-skeleton_1w6ss_1", n = "_popover_cpy8b_1", d = "_pagination_cpy8b_1 _ds-pagination_1w6ss_1", e = "_modal_cpy8b_1 _ds-modal_1w6ss_1", b = "_logo_cpy8b_1 _ds-focus_1w6ss_1", i = "_link_cpy8b_1", l = "_grid_cpy8b_1", p = "_flex_cpy8b_1", r = "_input_cpy8b_1 _ds-input_1w6ss_1", y = "_fieldset_cpy8b_1 _ds-fieldset_1w6ss_1", f = "_field_cpy8b_1 _ds-field_1w6ss_1", w = "_affixes_cpy8b_1 _ds-field-affixes_1w6ss_1", g = "_count_cpy8b_1", u = "_errorsummary_cpy8b_1 _ds-error-summary_1w6ss_1", m = "_details_cpy8b_1 _ds-details_1w6ss_1", h = "_chip_cpy8b_1 _ds-chip_1w6ss_1", v = "_card_cpy8b_1", x = "_info_cpy8b_1", k = "_button_cpy8b_1 _ds-button_1w6ss_1", S = "_breadcrumbs_cpy8b_1 _ds-breadcrumbs_1w6ss_1", j = "_badge_cpy8b_1", q = "_avatar_cpy8b_1 _ds-avatar_1w6ss_1", z = "_alert_cpy8b_1 _ds-alert_1w6ss_1", A = "_heading_cpy8b_1 _ds-heading_1w6ss_1", B = "_body_cpy8b_113", C = "_tooltip_cpy8b_128", D = {
1
+ const _ = "_validation_14niv_1 _ds-validation-message_1w6ss_1", s = "_tag_14niv_1 _ds-tag_1w6ss_1", n = "_tabs_14niv_1 _ds-tabs_1w6ss_1", t = "_table_14niv_1 _ds-table_1w6ss_1", o = "_scrollShadow_14niv_1", i = "_skeleton_14niv_1 _ds-skeleton_1w6ss_1", a = "_popover_14niv_1", d = "_pagination_14niv_1 _ds-pagination_1w6ss_1", e = "_modal_14niv_1 _ds-modal_1w6ss_1", l = "_logo_14niv_1 _ds-focus_1w6ss_1", c = "_link_14niv_1", r = "_grid_14niv_1", v = "_flex_14niv_1", b = "_input_14niv_1 _ds-input_1w6ss_1", f = "_fieldset_14niv_1 _ds-fieldset_1w6ss_1", w = "_field_14niv_1 _ds-field_1w6ss_1", g = "_affixes_14niv_1 _ds-field-affixes_1w6ss_1", p = "_count_14niv_1", u = "_errorsummary_14niv_1 _ds-error-summary_1w6ss_1", m = "_details_14niv_1 _ds-details_1w6ss_1", h = "_chip_14niv_1 _ds-chip_1w6ss_1", x = "_card_14niv_1", y = "_info_14niv_1", k = "_button_14niv_1 _ds-button_1w6ss_1", S = "_breadcrumbs_14niv_1 _ds-breadcrumbs_1w6ss_1", j = "_badge_14niv_1", q = "_avatar_14niv_1 _ds-avatar_1w6ss_1", z = "_alert_14niv_1 _ds-alert_1w6ss_1", A = "_heading_14niv_1 _ds-heading_1w6ss_1", B = "_body_14niv_114", C = "_tooltip_14niv_129", D = {
2
2
  validation: _,
3
3
  tag: s,
4
- tabs: t,
5
- table: o,
6
- scrollShadow: c,
7
- skeleton: a,
8
- popover: n,
4
+ tabs: n,
5
+ table: t,
6
+ scrollShadow: o,
7
+ skeleton: i,
8
+ popover: a,
9
9
  pagination: d,
10
10
  modal: e,
11
- logo: b,
12
- link: i,
13
- grid: l,
14
- flex: p,
15
- input: r,
16
- fieldset: y,
17
- field: f,
18
- affixes: w,
19
- count: g,
11
+ logo: l,
12
+ link: c,
13
+ grid: r,
14
+ flex: v,
15
+ input: b,
16
+ fieldset: f,
17
+ field: w,
18
+ affixes: g,
19
+ count: p,
20
20
  errorsummary: u,
21
21
  details: m,
22
22
  chip: h,
23
- card: v,
24
- info: x,
23
+ card: x,
24
+ info: y,
25
25
  button: k,
26
26
  breadcrumbs: S,
27
27
  badge: j,
@@ -32,35 +32,35 @@ const _ = "_validation_cpy8b_1 _ds-validation-message_1w6ss_1", s = "_tag_cpy8b_
32
32
  tooltip: C
33
33
  };
34
34
  export {
35
- w as affixes,
35
+ g as affixes,
36
36
  z as alert,
37
37
  q as avatar,
38
38
  j as badge,
39
39
  B as body,
40
40
  S as breadcrumbs,
41
41
  k as button,
42
- v as card,
42
+ x as card,
43
43
  h as chip,
44
- g as count,
44
+ p as count,
45
45
  D as default,
46
46
  m as details,
47
47
  u as errorsummary,
48
- f as field,
49
- y as fieldset,
50
- p as flex,
51
- l as grid,
48
+ w as field,
49
+ f as fieldset,
50
+ v as flex,
51
+ r as grid,
52
52
  A as heading,
53
- x as info,
54
- r as input,
55
- i as link,
56
- b as logo,
53
+ y as info,
54
+ b as input,
55
+ c as link,
56
+ l as logo,
57
57
  e as modal,
58
58
  d as pagination,
59
- n as popover,
60
- c as scrollShadow,
61
- a as skeleton,
62
- o as table,
63
- t as tabs,
59
+ a as popover,
60
+ o as scrollShadow,
61
+ i as skeleton,
62
+ t as table,
63
+ n as tabs,
64
64
  s as tag,
65
65
  C as tooltip,
66
66
  _ as validation
package/mtds/tooltip.js CHANGED
@@ -1,14 +1,18 @@
1
- import d from "./styles.module.css.js";
2
- import { IS_BROWSER as u, attr as c, on as m, QUICK_EVENT as p, anchorPosition as t } from "./utils.js";
3
- let n = null, s = 0, o = null;
4
- u && (o = document.body.appendChild(document.createElement("div")), o.classList.add(...d.tooltip.split(" ")), c(o, "popover", "manual"), m(document, "mousemove", f, p));
5
- function f({ target: e }) {
6
- clearTimeout(s), s = setTimeout(a, 20, e);
1
+ import m from "./styles.module.css.js";
2
+ import { IS_BROWSER as p, attr as r, on as u, QUICK_EVENT as d, useId as b, anchorPosition as f } from "./utils.js";
3
+ let e = null, l = null, a = 0, T = Number.NEGATIVE_INFINITY;
4
+ const c = 100;
5
+ p && (e = document.body.appendChild(document.createElement("div")), e.classList.add(...m.tooltip.split(" ")), r(e, "popover", "manual"), u(document, "blur,focus,mouseout,mouseover", s, d), u(window, "blur", s, d));
6
+ function s({ target: o }) {
7
+ const t = T + c - Date.now();
8
+ clearTimeout(a), a = setTimeout(E, Math.max(t, 0), o);
7
9
  }
8
- function a(e) {
9
- var i;
10
- if (!o || e === o) return;
11
- const l = (i = e == null ? void 0 : e.closest) == null ? void 0 : i.call(e, "[data-tooltip]");
12
- !l && n ? (t(o, !1), o == null || o.hidePopover(), n = null) : l && l !== n && (n = l, o.textContent = l.getAttribute("data-tooltip") || "", o.showPopover(), t(o, !1), t(o, l, "top"));
10
+ function E(o) {
11
+ var n;
12
+ if (T = 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")) || "";
16
+ (!i || i === "false" || i === "true") && (t = null), l == null || l.removeAttribute("aria-labelledby"), l = t, l == null || l.setAttribute("aria-labelledby", b(e)), e.togglePopover(!!t), f(e, t, (t == null ? void 0 : t.getAttribute("data-tooltip-position")) || "top"), t && (e.textContent = i);
13
17
  }
14
18
  //# sourceMappingURL=tooltip.js.map
@@ -1 +1 @@
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 } from \"./utils\";\n\nlet ANCHOR: Element | null = null;\nlet DEBOUNCE: 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, 'mousemove', handleMove, QUICK_EVENT);\n}\n\nfunction handleMove({ target }: Event) {\n clearTimeout(DEBOUNCE);\n DEBOUNCE = setTimeout(handleMoveDebounced, 20, target);\n}\n\nfunction handleMoveDebounced(target: Element | null) {\n if (!TOOLTIP || target === TOOLTIP) return; // Allow tooltip to be hovered, following https://www.w3.org/TR/WCAG21/#content-on-hover-or-focus\n const anchor = target?.closest?.<HTMLElement>('[data-tooltip]');\n \n if (!anchor && ANCHOR) {\n anchorPosition(TOOLTIP, false);\n TOOLTIP?.hidePopover();\n ANCHOR = null;\n } else if (anchor && anchor !== ANCHOR) {\n ANCHOR = anchor;\n TOOLTIP.textContent = anchor.getAttribute('data-tooltip') || '';\n TOOLTIP.showPopover();\n anchorPosition(TOOLTIP, false); // Reset position\n anchorPosition(TOOLTIP, anchor, 'top');\n }\n}"],"names":["ANCHOR","DEBOUNCE","TOOLTIP","IS_BROWSER","styles","attr","on","handleMove","QUICK_EVENT","target","handleMoveDebounced","anchor","_a","anchorPosition"],"mappings":";;AAGA,IAAIA,IAAyB,MACzBC,IAAmD,GACnDC,IAA8B;AAE9BC,MACFD,IAAU,SAAS,KAAK,YAAY,SAAS,cAAc,KAAK,CAAC,GACjEA,EAAQ,UAAU,IAAI,GAAGE,EAAO,QAAQ,MAAM,GAAG,CAAC,GAC7CC,EAAAH,GAAS,WAAW,QAAQ,GAC9BI,EAAA,UAAU,aAAaC,GAAYC,CAAW;AAGnD,SAASD,EAAW,EAAE,QAAAE,KAAiB;AACrC,eAAaR,CAAQ,GACVA,IAAA,WAAWS,GAAqB,IAAID,CAAM;AACvD;AAEA,SAASC,EAAoBD,GAAwB;;AAC/C,MAAA,CAACP,KAAWO,MAAWP,EAAS;AAC9B,QAAAS,KAASC,IAAAH,KAAA,gBAAAA,EAAQ,YAAR,gBAAAG,EAAA,KAAAH,GAA+B;AAE1C,EAAA,CAACE,KAAUX,KACba,EAAeX,GAAS,EAAK,GAC7BA,KAAA,QAAAA,EAAS,eACAF,IAAA,QACAW,KAAUA,MAAWX,MACrBA,IAAAW,GACTT,EAAQ,cAAcS,EAAO,aAAa,cAAc,KAAK,IAC7DT,EAAQ,YAAY,GACpBW,EAAeX,GAAS,EAAK,GACdW,EAAAX,GAASS,GAAQ,KAAK;AAEzC;"}
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\nlet TOOLTIP: HTMLElement | null = null;\nlet ANCHOR: Element | null = null;\nlet THROTTLE: number | ReturnType<typeof setTimeout> = 0;\nlet THROTTLE_LAST_CALL = Number.NEGATIVE_INFINITY;\nconst THROTTLE_DELAY = 100;\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 = THROTTLE_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 THROTTLE_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') || '';\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 // anchorPosition(TOOLTIP, false); // Reset anchor position\n anchorPosition(TOOLTIP, anchor, anchor?.getAttribute('data-tooltip-position') || 'top');\n if (anchor) TOOLTIP.textContent = content;\n}"],"names":["TOOLTIP","ANCHOR","THROTTLE","THROTTLE_LAST_CALL","THROTTLE_DELAY","IS_BROWSER","styles","attr","on","handleMove","QUICK_EVENT","target","wait","handleMoveThrottled","anchor","_a","content","useId","anchorPosition"],"mappings":";;AAGA,IAAIA,IAA8B,MAC9BC,IAAyB,MACzBC,IAAmD,GACnDC,IAAqB,OAAO;AAChC,MAAMC,IAAiB;AAEnBC,MACFL,IAAU,SAAS,KAAK,YAAY,SAAS,cAAc,KAAK,CAAC,GACjEA,EAAQ,UAAU,IAAI,GAAGM,EAAO,QAAQ,MAAM,GAAG,CAAC,GAC7CC,EAAAP,GAAS,WAAW,QAAQ,GAC9BQ,EAAA,UAAU,iCAAiCC,GAAYC,CAAW,GAClEF,EAAA,QAAQ,QAAQC,GAAYC,CAAW;AAG5C,SAASD,EAAW,EAAE,QAAAE,KAAiB;AACrC,QAAMC,IAAOT,IAAqBC,IAAiB,KAAK,IAAI;AAC5D,eAAaF,CAAQ,GACrBA,IAAW,WAAWW,GAAqB,KAAK,IAAID,GAAM,CAAC,GAAGD,CAAM;AACtE;AAGA,SAASE,EAAoBF,GAAwB;;AAG/C,MAFJR,IAAqB,KAAK,IAAI,GAE1B,CAACH,KAAWW,MAAWX,EAAS;AACpC,MAAIc,MAASC,IAAAJ,KAAA,gBAAAA,EAAQ,YAAR,gBAAAI,EAAA,KAAAJ,GAA+B,sCAAqC;AAGjF,MAAIG,MAAWb,EAAQ;AAGjB,QAAAe,KAAUF,KAAA,gBAAAA,EAAQ,aAAa,qBAAmBA,KAAA,gBAAAA,EAAQ,aAAa,qBAAoB;AACjG,GAAI,CAACE,KAAWA,MAAY,WAAWA,MAAY,YAAiBF,IAAA,OAEpEb,KAAA,QAAAA,EAAQ,gBAAgB,oBACfA,IAAAa,GAETb,KAAA,QAAAA,EAAQ,aAAa,mBAAmBgB,EAAMjB,CAAO,IAC7CA,EAAA,cAAc,CAAC,CAACc,CAAM,GAE9BI,EAAelB,GAASc,IAAQA,KAAA,gBAAAA,EAAQ,aAAa,6BAA4B,KAAK,GAClFA,QAAgB,cAAcE;AACpC;"}
package/mtds/utils.js CHANGED
@@ -1,33 +1,33 @@
1
- const w = typeof window < "u" && typeof document < "u", W = { capture: !0, passive: !0 };
2
- function C(t, e, n) {
1
+ const w = typeof window < "u" && typeof document < "u", U = { capture: !0, passive: !0 };
2
+ function E(t, e, n) {
3
3
  return n === void 0 ? t.getAttribute(e) ?? null : (n === null ? t.removeAttribute(e) : t.getAttribute(e) !== n && t.setAttribute(e, n), null);
4
4
  }
5
- let U = 0;
6
- const E = `${Date.now().toString(36)}${Math.random().toString(36).slice(2, 5)}`;
7
- function F(t) {
8
- return t.id || (t.id = `${E}${++U}`), t.id;
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;
9
9
  }
10
10
  const b = (t, e, n) => {
11
11
  for (const i of n[0].split(","))
12
12
  n[0] = i, e[`${t}EventListener`](...n);
13
- }, B = (t, ...e) => b("add", t, e), P = (t, ...e) => b("remove", t, e), l = /* @__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", () => {
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
16
  for (const [t, e] of l) e();
17
- }, W);
17
+ }, U);
18
18
  const c = { top: 0, right: 1, bottom: 2, left: 3, none: 4 };
19
- function I(t, e, n) {
20
- var h;
21
- if (e === !1 || !(e != null && e.isConnected) || !(t != null && t.isConnected)) return l.delete(t);
22
- if (s != null && s.isConnected || document.body.append(s || ""), !l.has(t)) {
23
- const S = c[n] ?? c.bottom;
24
- return (h = l.set(t, () => I(t, e, S)).get(t)) == null ? void 0 : h();
19
+ function _(t, e, n) {
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) || c[n] === void 0) {
23
+ const C = c[n] ?? c.bottom;
24
+ return (p = l.set(t, () => _(t, e, C)).get(t)) == null ? void 0 : p();
25
25
  }
26
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), A = f - i > 0, T = r + r + i < window.innerWidth, H = d - o > 0, $ = d + u + o < window.innerHeight, g = n === c.bottom && T || !A, x = n === c.bottom && $ || !H, p = n === c.top || n === c.bottom;
28
- t.style.left = `${Math.round(p ? Math.min(Math.max(10, f - (i - r) / 2), window.innerWidth - i - 10) : g ? f + r : f - i)}px`, t.style.top = `${Math.round(p ? x ? d + u : d - o : Math.min(Math.max(10, d - (o - u) / 2), window.innerHeight - o - 10))}px`, s == null || s.style.setProperty("translate", `${Math.round(window.scrollX + f + r + i + 30)} ${Math.round(window.scrollY + d + u + o + 30)}px`);
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`);
29
29
  }
30
- function O(t) {
30
+ function F(t) {
31
31
  let e = 0;
32
32
  const n = () => setTimeout(i, 200), i = () => {
33
33
  t([], o), e = 0;
@@ -36,27 +36,27 @@ function O(t) {
36
36
  });
37
37
  return o;
38
38
  }
39
- const a = /* @__PURE__ */ new WeakMap(), _ = (t) => {
39
+ const a = /* @__PURE__ */ new WeakMap(), P = (t) => {
40
40
  var n;
41
41
  const e = a.get(t);
42
42
  if (!e || !t.isConnected)
43
43
  (n = e == null ? void 0 : e.observer) == null || n.disconnect(), a.delete(t);
44
44
  else for (const [, i] of e.collections) i();
45
- }, R = (t, e, n) => {
45
+ }, Y = (t, e, n) => {
46
46
  const i = t.getElementsByClassName(e);
47
47
  let o = a.get(t);
48
- o || (o = { collections: /* @__PURE__ */ new Map(), observer: O(() => _(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);
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
49
  }, k = (t) => t instanceof HTMLElement && "validity" in t && !(t instanceof HTMLButtonElement);
50
50
  export {
51
51
  w as IS_BROWSER,
52
- W as QUICK_EVENT,
53
- I as anchorPosition,
54
- C as attr,
55
- O as createOptimizedMutationObserver,
52
+ U as QUICK_EVENT,
53
+ _ as anchorPosition,
54
+ E as attr,
55
+ F as createOptimizedMutationObserver,
56
56
  k as isInputLike,
57
- P as off,
58
- B as on,
59
- R as onMutation,
60
- F as useId
57
+ X as off,
58
+ O as on,
59
+ Y as onMutation,
60
+ R as useId
61
61
  };
62
62
  //# 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 */\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 === false || !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)) {\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 under when no hasSpaceOver, as no OS can scroll further up than 0\n\tconst positionUnder = (position === ANCHOR.bottom && hasSpaceUnder) || !hasSpaceOver // Always position under when no hasSpaceOver, as no OS can scroll further up than 0\n\tconst isVertical = position === ANCHOR.top || position === ANCHOR.bottom;\n\n\ttarget.style.left = `${Math.round(isVertical ? Math.min(Math.max(10, anchorX - (targetW - anchorW) / 2), window.innerWidth - targetW - 10) : (positionRight ? anchorX + anchorW : anchorX - targetW))}px`\n target.style.top = `${Math.round(isVertical ? (positionUnder ? anchorY + anchorH : anchorY - targetH) : Math.min(Math.max(10, anchorY - (targetH - anchorH) / 2), window.innerHeight - targetH - 10))}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","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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AcA,KAAM,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 */\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) || ANCHOR[position as AnchorKeys] === undefined) { // 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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,MAAMT,EAASU,CAAU,CAAC,IACtEH,EAAQ,YAAY,OAAOE,CAAS;AAC1C,GAEaE,IAAc,CAACvD,MAC3BA,aAAc,eAAe,cAAcA,KAAM,EAAEA,aAAc;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mattilsynet/design",
3
- "version": "0.2.16",
3
+ "version": "0.2.18",
4
4
  "type": "module",
5
5
  "main": "./mtds/index.js",
6
6
  "types": "./mtds/index.d.ts",
@@ -35,16 +35,16 @@
35
35
  "devDependencies": {
36
36
  "@biomejs/biome": "^1.9.4",
37
37
  "@phosphor-icons/react": "^2.1.7",
38
- "@storybook/addon-essentials": "^8.5.2",
39
- "@storybook/addon-mdx-gfm": "^8.5.2",
40
- "@storybook/addon-storysource": "^8.5.2",
41
- "@storybook/blocks": "^8.5.2",
42
- "@storybook/manager-api": "^8.5.2",
43
- "@storybook/react": "^8.5.2",
44
- "@storybook/react-vite": "^8.5.2",
45
- "@storybook/theming": "^8.5.2",
38
+ "@storybook/addon-essentials": "^8.5.3",
39
+ "@storybook/addon-mdx-gfm": "^8.5.3",
40
+ "@storybook/addon-storysource": "^8.5.3",
41
+ "@storybook/blocks": "^8.5.3",
42
+ "@storybook/manager-api": "^8.5.3",
43
+ "@storybook/react": "^8.5.3",
44
+ "@storybook/react-vite": "^8.5.3",
45
+ "@storybook/theming": "^8.5.3",
46
46
  "@tanstack/react-table": "^8.20.6",
47
- "@types/node": "^22.12.0",
47
+ "@types/node": "^22.13.0",
48
48
  "@types/react": "^19.0.8",
49
49
  "@types/react-dom": "^19.0.3",
50
50
  "@u-elements/u-datalist": "0.1.2",