@mattilsynet/design 1.1.0 → 1.1.2
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/card/card.d.ts +1 -6
- package/mtds/card/card.js +11 -22
- package/mtds/card/card.js.map +1 -1
- package/mtds/details/details.js +9 -9
- package/mtds/details/details.js.map +1 -1
- package/mtds/dialog/dialog-observer.js +12 -17
- package/mtds/dialog/dialog-observer.js.map +1 -1
- package/mtds/field/field-observer.js +20 -19
- package/mtds/field/field-observer.js.map +1 -1
- package/mtds/field/field.js +56 -55
- package/mtds/field/field.js.map +1 -1
- package/mtds/fieldset/fieldset-observer.js +16 -15
- package/mtds/fieldset/fieldset-observer.js.map +1 -1
- package/mtds/index.iife.js +5 -5
- package/mtds/layout/app-observer.js +23 -25
- package/mtds/layout/app-observer.js.map +1 -1
- package/mtds/layout/layout.stories.d.ts +1 -0
- package/mtds/logo/logo-observer.js +8 -10
- package/mtds/logo/logo-observer.js.map +1 -1
- package/mtds/popover/popover-observer.js +15 -15
- package/mtds/popover/popover-observer.js.map +1 -1
- package/mtds/progress/progress.js +8 -15
- package/mtds/progress/progress.js.map +1 -1
- package/mtds/styles.css +1 -1
- package/mtds/styles.json +35 -35
- package/mtds/styles.module.css.js +25 -25
- package/mtds/table/table-observer.js +1 -3
- package/mtds/table/table-observer.js.map +1 -1
- package/mtds/tabs/tabs.js +20 -18
- package/mtds/tabs/tabs.js.map +1 -1
- package/mtds/tooltip/tooltip-observer.js +24 -24
- package/mtds/tooltip/tooltip-observer.js.map +1 -1
- package/mtds/utils.d.ts +16 -8
- package/mtds/utils.js +50 -66
- package/mtds/utils.js.map +1 -1
- package/package.json +1 -2
- package/mtds/index.iife.js.map +0 -1
package/mtds/styles.json
CHANGED
|
@@ -1,37 +1,37 @@
|
|
|
1
1
|
{
|
|
2
|
-
"alert": "
|
|
3
|
-
"avatar": "
|
|
4
|
-
"badge": "
|
|
5
|
-
"breadcrumbs": "
|
|
6
|
-
"button": "
|
|
7
|
-
"card": "
|
|
8
|
-
"info": "
|
|
9
|
-
"group": "
|
|
10
|
-
"chip": "
|
|
11
|
-
"details": "
|
|
12
|
-
"dialog": "
|
|
13
|
-
"divider": "
|
|
14
|
-
"errorsummary": "
|
|
15
|
-
"field": "
|
|
16
|
-
"affixes": "
|
|
17
|
-
"fieldset": "
|
|
18
|
-
"heading": "
|
|
19
|
-
"helptext": "
|
|
20
|
-
"input": "
|
|
21
|
-
"app": "
|
|
22
|
-
"grid": "
|
|
23
|
-
"flex": "
|
|
24
|
-
"prose": "
|
|
25
|
-
"link": "
|
|
26
|
-
"logo": "
|
|
27
|
-
"pagination": "
|
|
28
|
-
"popover": "
|
|
29
|
-
"progress": "
|
|
30
|
-
"skeleton": "
|
|
31
|
-
"spinner": "
|
|
32
|
-
"table": "
|
|
33
|
-
"tabs": "
|
|
34
|
-
"tag": "
|
|
35
|
-
"validation": "
|
|
36
|
-
"body": "
|
|
2
|
+
"alert": "_alert_mc7vk_1 _ds-alert_oaddr_1",
|
|
3
|
+
"avatar": "_avatar_mc7vk_1 _ds-avatar_oaddr_1",
|
|
4
|
+
"badge": "_badge_mc7vk_1",
|
|
5
|
+
"breadcrumbs": "_breadcrumbs_mc7vk_1 _ds-breadcrumbs_oaddr_1",
|
|
6
|
+
"button": "_button_mc7vk_1 _ds-button_oaddr_1",
|
|
7
|
+
"card": "_card_mc7vk_1",
|
|
8
|
+
"info": "_info_mc7vk_1",
|
|
9
|
+
"group": "_group_mc7vk_1",
|
|
10
|
+
"chip": "_chip_mc7vk_1 _ds-chip_oaddr_1",
|
|
11
|
+
"details": "_details_mc7vk_1 _ds-details_oaddr_1",
|
|
12
|
+
"dialog": "_dialog_mc7vk_1 _ds-dialog_oaddr_1",
|
|
13
|
+
"divider": "_divider_mc7vk_1",
|
|
14
|
+
"errorsummary": "_errorsummary_mc7vk_1 _ds-error-summary_oaddr_1",
|
|
15
|
+
"field": "_field_mc7vk_1 _ds-field_oaddr_1",
|
|
16
|
+
"affixes": "_affixes_mc7vk_1 _ds-field-affixes_oaddr_1",
|
|
17
|
+
"fieldset": "_fieldset_mc7vk_1 _ds-fieldset_oaddr_1",
|
|
18
|
+
"heading": "_heading_mc7vk_1 _ds-heading_oaddr_1",
|
|
19
|
+
"helptext": "_helptext_mc7vk_1 _ds-focus_oaddr_1",
|
|
20
|
+
"input": "_input_mc7vk_1 _ds-input_oaddr_1",
|
|
21
|
+
"app": "_app_mc7vk_1",
|
|
22
|
+
"grid": "_grid_mc7vk_1",
|
|
23
|
+
"flex": "_flex_mc7vk_1",
|
|
24
|
+
"prose": "_prose_mc7vk_1",
|
|
25
|
+
"link": "_link_mc7vk_1",
|
|
26
|
+
"logo": "_logo_mc7vk_1",
|
|
27
|
+
"pagination": "_pagination_mc7vk_1 _ds-pagination_oaddr_1",
|
|
28
|
+
"popover": "_popover_mc7vk_1",
|
|
29
|
+
"progress": "_progress_mc7vk_1",
|
|
30
|
+
"skeleton": "_skeleton_mc7vk_1 _ds-skeleton_oaddr_1",
|
|
31
|
+
"spinner": "_spinner_mc7vk_1",
|
|
32
|
+
"table": "_table_mc7vk_1 _ds-table_oaddr_1",
|
|
33
|
+
"tabs": "_tabs_mc7vk_1 _ds-tabs_oaddr_1",
|
|
34
|
+
"tag": "_tag_mc7vk_1 _ds-tag_oaddr_1",
|
|
35
|
+
"validation": "_validation_mc7vk_1 _ds-validation-message_oaddr_1",
|
|
36
|
+
"body": "_body_mc7vk_144"
|
|
37
37
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const _ = "
|
|
1
|
+
const _ = "_alert_mc7vk_1 _ds-alert_oaddr_1", o = "_avatar_mc7vk_1 _ds-avatar_oaddr_1", t = "_badge_mc7vk_1", s = "_breadcrumbs_mc7vk_1 _ds-breadcrumbs_oaddr_1", d = "_button_mc7vk_1 _ds-button_oaddr_1", a = "_card_mc7vk_1", e = "_info_mc7vk_1", r = "_group_mc7vk_1", c = "_chip_mc7vk_1 _ds-chip_oaddr_1", n = "_details_mc7vk_1 _ds-details_oaddr_1", i = "_dialog_mc7vk_1 _ds-dialog_oaddr_1", m = "_divider_mc7vk_1", l = "_errorsummary_mc7vk_1 _ds-error-summary_oaddr_1", v = "__errorsummary_mc7vk_1", k = "_field_mc7vk_1 _ds-field_oaddr_1", p = "_affixes_mc7vk_1 _ds-field-affixes_oaddr_1", g = "_fieldset_mc7vk_1 _ds-fieldset_oaddr_1", b = "_heading_mc7vk_1 _ds-heading_oaddr_1", f = "_helptext_mc7vk_1 _ds-focus_oaddr_1", u = "_input_mc7vk_1 _ds-input_oaddr_1", h = "_app_mc7vk_1", x = "_grid_mc7vk_1", y = "_flex_mc7vk_1", w = "_prose_mc7vk_1", S = "_link_mc7vk_1", j = "_logo_mc7vk_1", q = "_pagination_mc7vk_1 _ds-pagination_oaddr_1", z = "_popover_mc7vk_1", A = "_progress_mc7vk_1", B = "__indeterminate_mc7vk_1", C = "_skeleton_mc7vk_1 _ds-skeleton_oaddr_1", D = "__skeleton_mc7vk_1", E = "_spinner_mc7vk_1", F = "_table_mc7vk_1 _ds-table_oaddr_1", G = "__scrollShadow_mc7vk_1", H = "_tabs_mc7vk_1 _ds-tabs_oaddr_1", I = "_tag_mc7vk_1 _ds-tag_oaddr_1", J = "__tooltip_mc7vk_1", K = "_validation_mc7vk_1 _ds-validation-message_oaddr_1", L = "_body_mc7vk_144", M = {
|
|
2
2
|
alert: _,
|
|
3
3
|
avatar: o,
|
|
4
4
|
badge: t,
|
|
@@ -10,18 +10,18 @@ const _ = "_alert_1c79o_1 _ds-alert_oaddr_1", o = "_avatar_1c79o_1 _ds-avatar_oa
|
|
|
10
10
|
chip: c,
|
|
11
11
|
details: n,
|
|
12
12
|
dialog: i,
|
|
13
|
-
divider:
|
|
14
|
-
errorsummary:
|
|
15
|
-
_errorsummary:
|
|
16
|
-
field:
|
|
17
|
-
affixes:
|
|
18
|
-
fieldset:
|
|
19
|
-
heading:
|
|
20
|
-
helptext:
|
|
21
|
-
input:
|
|
22
|
-
app:
|
|
23
|
-
grid:
|
|
24
|
-
flex:
|
|
13
|
+
divider: m,
|
|
14
|
+
errorsummary: l,
|
|
15
|
+
_errorsummary: v,
|
|
16
|
+
field: k,
|
|
17
|
+
affixes: p,
|
|
18
|
+
fieldset: g,
|
|
19
|
+
heading: b,
|
|
20
|
+
helptext: f,
|
|
21
|
+
input: u,
|
|
22
|
+
app: h,
|
|
23
|
+
grid: x,
|
|
24
|
+
flex: y,
|
|
25
25
|
prose: w,
|
|
26
26
|
link: S,
|
|
27
27
|
logo: j,
|
|
@@ -41,14 +41,14 @@ const _ = "_alert_1c79o_1 _ds-alert_oaddr_1", o = "_avatar_1c79o_1 _ds-avatar_oa
|
|
|
41
41
|
body: L
|
|
42
42
|
};
|
|
43
43
|
export {
|
|
44
|
-
|
|
44
|
+
v as _errorsummary,
|
|
45
45
|
B as _indeterminate,
|
|
46
46
|
G as _scrollShadow,
|
|
47
47
|
D as _skeleton,
|
|
48
48
|
J as _tooltip,
|
|
49
|
-
|
|
49
|
+
p as affixes,
|
|
50
50
|
_ as alert,
|
|
51
|
-
|
|
51
|
+
h as app,
|
|
52
52
|
o as avatar,
|
|
53
53
|
t as badge,
|
|
54
54
|
L as body,
|
|
@@ -59,17 +59,17 @@ export {
|
|
|
59
59
|
M as default,
|
|
60
60
|
n as details,
|
|
61
61
|
i as dialog,
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
62
|
+
m as divider,
|
|
63
|
+
l as errorsummary,
|
|
64
|
+
k as field,
|
|
65
|
+
g as fieldset,
|
|
66
|
+
y as flex,
|
|
67
|
+
x as grid,
|
|
68
68
|
r as group,
|
|
69
|
-
|
|
70
|
-
|
|
69
|
+
b as heading,
|
|
70
|
+
f as helptext,
|
|
71
71
|
e as info,
|
|
72
|
-
|
|
72
|
+
u as input,
|
|
73
73
|
S as link,
|
|
74
74
|
j as logo,
|
|
75
75
|
q as pagination,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"table-observer.js","sources":["../../designsystem/table/table-observer.ts"],"sourcesContent":["import styles from \"../styles.module.css\";\nimport { attr, onLoaded, onMutation } from \"../utils\";\n\nconst CSS_TABLE = styles.table.split(\" \")[0];\n\nfunction handleMutation(tables: HTMLCollectionOf<HTMLTableElement>) {\n\tfor (const table of tables) {\n\t\tconst ths: string[] = []; // Add data-th=\"\" to each cell to support data-mobile designs\n\n\t\tattr(table, \"role\", \"table\"); // Add helping role=\"\" to ensure screen readers understand the table regardless of CSS display\n\t\tif (table.caption) attr(table.caption, \"role\", \"caption\");\n\t\tfor (const group of [table.tHead, table.tFoot, ...table.tBodies])\n\t\t\tif (group) {\n\t\t\t\tattr(group, \"role\", \"rowgroup\");\n\t\t\t\tconst isTbody = group.nodeName === \"TBODY\";\n\n\t\t\t\tfor (const row of group.rows) {\n\t\t\t\t\tattr(row, \"role\", \"row\");\n\t\t\t\t\tfor (const cell of row.cells) {\n\t\t\t\t\t\tif (isTbody) attr(cell, \"data-th\", ths[cell.cellIndex] || \":empty\");\n\t\t\t\t\t\telse ths.push(cell.innerText.trim()); // Using innerText to only include visible text\n\t\t\t\t\t\tif (cell.nodeName === \"TD\") attr(cell, \"role\", \"cell\");\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\tattr(cell, \"role\", isTbody ? \"rowheader\" : \"columnheader\");\n\t\t\t\t\t\t\tattr(cell, \"scope\", isTbody ? \"row\" : \"col\");\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t}\n}\n\nonLoaded(() =>
|
|
1
|
+
{"version":3,"file":"table-observer.js","sources":["../../designsystem/table/table-observer.ts"],"sourcesContent":["import styles from \"../styles.module.css\";\nimport { attr, onLoaded, onMutation } from \"../utils\";\n\nconst CSS_TABLE = styles.table.split(\" \")[0];\n\nfunction handleMutation(tables: HTMLCollectionOf<HTMLTableElement>) {\n\tfor (const table of tables) {\n\t\tconst ths: string[] = []; // Add data-th=\"\" to each cell to support data-mobile designs\n\n\t\tattr(table, \"role\", \"table\"); // Add helping role=\"\" to ensure screen readers understand the table regardless of CSS display\n\t\tif (table.caption) attr(table.caption, \"role\", \"caption\");\n\t\tfor (const group of [table.tHead, table.tFoot, ...table.tBodies])\n\t\t\tif (group) {\n\t\t\t\tattr(group, \"role\", \"rowgroup\");\n\t\t\t\tconst isTbody = group.nodeName === \"TBODY\";\n\n\t\t\t\tfor (const row of group.rows) {\n\t\t\t\t\tattr(row, \"role\", \"row\");\n\t\t\t\t\tfor (const cell of row.cells) {\n\t\t\t\t\t\tif (isTbody) attr(cell, \"data-th\", ths[cell.cellIndex] || \":empty\");\n\t\t\t\t\t\telse ths.push(cell.innerText.trim()); // Using innerText to only include visible text\n\t\t\t\t\t\tif (cell.nodeName === \"TD\") attr(cell, \"role\", \"cell\");\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\tattr(cell, \"role\", isTbody ? \"rowheader\" : \"columnheader\");\n\t\t\t\t\t\t\tattr(cell, \"scope\", isTbody ? \"row\" : \"col\");\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t}\n}\n\nonLoaded(() => onMutation(document.documentElement, CSS_TABLE, handleMutation));\n"],"names":["CSS_TABLE","styles","handleMutation","tables","table","ths","attr","group","isTbody","row","cell","onLoaded","onMutation"],"mappings":";;AAGA,MAAMA,IAAYC,EAAO,MAAM,MAAM,GAAG,EAAE,CAAC;AAE3C,SAASC,EAAeC,GAA4C;AACnE,aAAWC,KAASD,GAAQ;AAC3B,UAAME,IAAgB,CAAC;AAElB,IAAAC,EAAAF,GAAO,QAAQ,OAAO,GACvBA,EAAM,WAASE,EAAKF,EAAM,SAAS,QAAQ,SAAS;AAC7C,eAAAG,KAAS,CAACH,EAAM,OAAOA,EAAM,OAAO,GAAGA,EAAM,OAAO;AAC9D,UAAIG,GAAO;AACL,QAAAD,EAAAC,GAAO,QAAQ,UAAU;AACxB,cAAAC,IAAUD,EAAM,aAAa;AAExB,mBAAAE,KAAOF,EAAM,MAAM;AACxB,UAAAD,EAAAG,GAAK,QAAQ,KAAK;AACZ,qBAAAC,KAAQD,EAAI;AAClB,YAAAD,MAAcE,GAAM,WAAWL,EAAIK,EAAK,SAAS,KAAK,QAAQ,IACzDL,EAAA,KAAKK,EAAK,UAAU,MAAM,GAC/BA,EAAK,aAAa,OAAWJ,EAAAI,GAAM,QAAQ,MAAM,KAEpDJ,EAAKI,GAAM,QAAQF,IAAU,cAAc,cAAc,GACzDF,EAAKI,GAAM,SAASF,IAAU,QAAQ,KAAK;AAAA,QAE7C;AAAA,MACD;AAAA,EACD;AAEH;AAEAG,EAAS,MAAMC,EAAW,SAAS,iBAAiBZ,GAAWE,CAAc,CAAC;"}
|
package/mtds/tabs/tabs.js
CHANGED
|
@@ -1,27 +1,29 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
function({ className: s, ...t }, a) {
|
|
9
|
-
return /* @__PURE__ */ n("u-tablist", { class: s, ref: a, ...t });
|
|
1
|
+
import { jsx as a } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef as n } from "react";
|
|
3
|
+
import b from "../styles.module.css.js";
|
|
4
|
+
import { toCustomElementProps as o } from "../utils.js";
|
|
5
|
+
const e = n(
|
|
6
|
+
function(t, s) {
|
|
7
|
+
return /* @__PURE__ */ a("u-tabs", { ref: s, ...o(t, b.tabs) });
|
|
10
8
|
}
|
|
11
|
-
),
|
|
12
|
-
function(
|
|
13
|
-
return /* @__PURE__ */
|
|
9
|
+
), i = n(
|
|
10
|
+
function(t, s) {
|
|
11
|
+
return /* @__PURE__ */ a("u-tablist", { ref: s, ...o(t) });
|
|
14
12
|
}
|
|
15
|
-
),
|
|
16
|
-
function(
|
|
17
|
-
return /* @__PURE__ */
|
|
13
|
+
), u = n(
|
|
14
|
+
function(t, s) {
|
|
15
|
+
return /* @__PURE__ */ a("u-tabpanel", { ref: s, ...o(t) });
|
|
18
16
|
}
|
|
19
|
-
),
|
|
20
|
-
|
|
17
|
+
), T = n(
|
|
18
|
+
function(t, s) {
|
|
19
|
+
return /* @__PURE__ */ a("u-tab", { ref: s, ...o(t) });
|
|
20
|
+
}
|
|
21
|
+
), l = Object.assign(e, {
|
|
22
|
+
List: i,
|
|
21
23
|
Panel: u,
|
|
22
24
|
Tab: T
|
|
23
25
|
});
|
|
24
26
|
export {
|
|
25
|
-
|
|
27
|
+
l as Tabs
|
|
26
28
|
};
|
|
27
29
|
//# sourceMappingURL=tabs.js.map
|
package/mtds/tabs/tabs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tabs.js","sources":["../../designsystem/tabs/tabs.tsx"],"sourcesContent":["import type * as UTabs from \"@u-elements/u-tabs\";\nimport
|
|
1
|
+
{"version":3,"file":"tabs.js","sources":["../../designsystem/tabs/tabs.tsx"],"sourcesContent":["import type * as UTabs from \"@u-elements/u-tabs\";\nimport { forwardRef } from \"react\";\nimport styles from \"../styles.module.css\";\nimport { toCustomElementProps } from \"../utils\";\n\nexport type TabsProps = UTabs.ReactUtabs;\nconst TabsComp = forwardRef<UTabs.UHTMLTabsElement, TabsProps>(\n\tfunction Tabs(props, ref) {\n\t\treturn <u-tabs ref={ref} {...toCustomElementProps(props, styles.tabs)} />;\n\t},\n);\n\nexport type TabsListProps = UTabs.ReactUtablist;\nconst TabsList = forwardRef<UTabs.UHTMLTabListElement, TabsListProps>(\n\tfunction TabsList(props, ref) {\n\t\treturn <u-tablist ref={ref} {...toCustomElementProps(props)} />;\n\t},\n);\n\nexport type TabsPanelProps = UTabs.ReactUtabpanel;\nconst TabsPanel = forwardRef<UTabs.UHTMLTabPanelElement, TabsPanelProps>(\n\tfunction TabsPanel(props, ref) {\n\t\treturn <u-tabpanel ref={ref} {...toCustomElementProps(props)} />;\n\t},\n);\n\nexport type TabsTabProps = UTabs.ReactUtab;\nconst TabsTab = forwardRef<UTabs.UHTMLTabElement, TabsTabProps>(\n\tfunction TabsTab(props, ref) {\n\t\treturn <u-tab ref={ref} {...toCustomElementProps(props)} />;\n\t},\n);\n\nexport const Tabs = Object.assign(TabsComp, {\n\tList: TabsList,\n\tPanel: TabsPanel,\n\tTab: TabsTab,\n});\n"],"names":["TabsComp","forwardRef","props","ref","jsx","toCustomElementProps","styles","TabsList","TabsPanel","TabsTab","Tabs"],"mappings":";;;;AAMA,MAAMA,IAAWC;AAAA,EAChB,SAAcC,GAAOC,GAAK;AAClB,WAAA,gBAAAC,EAAC,YAAO,KAAAD,GAAW,GAAGE,EAAqBH,GAAOI,EAAO,IAAI,GAAG;AAAA,EAAA;AAEzE,GAGMC,IAAWN;AAAA,EAChB,SAAkBC,GAAOC,GAAK;AAC7B,6BAAQ,aAAU,EAAA,KAAAA,GAAW,GAAGE,EAAqBH,CAAK,GAAG;AAAA,EAAA;AAE/D,GAGMM,IAAYP;AAAA,EACjB,SAAmBC,GAAOC,GAAK;AAC9B,6BAAQ,cAAW,EAAA,KAAAA,GAAW,GAAGE,EAAqBH,CAAK,GAAG;AAAA,EAAA;AAEhE,GAGMO,IAAUR;AAAA,EACf,SAAiBC,GAAOC,GAAK;AAC5B,6BAAQ,SAAM,EAAA,KAAAA,GAAW,GAAGE,EAAqBH,CAAK,GAAG;AAAA,EAAA;AAE3D,GAEaQ,IAAO,OAAO,OAAOV,GAAU;AAAA,EAC3C,MAAMO;AAAA,EACN,OAAOC;AAAA,EACP,KAAKC;AACN,CAAC;"}
|
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { onLoaded as
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
className: y._tooltip,
|
|
7
|
-
id: m,
|
|
1
|
+
import L from "../styles.module.css.js";
|
|
2
|
+
import { IS_BROWSER as _, onLoaded as v, on as a, QUICK_EVENT as u, attr as s, anchorPosition as E } from "../utils.js";
|
|
3
|
+
const b = "aria-describedby", f = "Escape", d = "aria-labelledby", A = "--mtds-tooltip-position", T = 300, o = _ ? Object.assign(document.createElement("div"), {
|
|
4
|
+
className: L._tooltip,
|
|
5
|
+
id: "mtds-tooltip",
|
|
8
6
|
popover: "manual"
|
|
9
|
-
});
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
7
|
+
}) : null;
|
|
8
|
+
let e = null, S = Number.NEGATIVE_INFINITY, w = 0;
|
|
9
|
+
function c({ target: n, type: t, key: i }) {
|
|
10
|
+
if (t === "keydown" && i !== f) return;
|
|
11
|
+
const l = S + T - Date.now();
|
|
12
|
+
clearTimeout(w), w = setTimeout(
|
|
13
|
+
D,
|
|
15
14
|
Math.max(l, 0),
|
|
16
|
-
|
|
15
|
+
i === f ? null : n
|
|
17
16
|
);
|
|
18
17
|
}
|
|
19
|
-
function
|
|
20
|
-
var
|
|
21
|
-
if (
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
o == null
|
|
18
|
+
function D(n) {
|
|
19
|
+
var m, r, p;
|
|
20
|
+
if (S = Date.now(), !o || n === o) return;
|
|
21
|
+
o != null && o.isConnected || document.body.append(o);
|
|
22
|
+
let t = ((m = n == null ? void 0 : n.closest) == null ? void 0 : m.call(n, "[data-tooltip]")) || null;
|
|
23
|
+
if (t === e) return;
|
|
24
|
+
const i = t && s(t, "data-tooltip") || "", l = t && s(t, "data-tooltip-position") || ((r = window.getComputedStyle(t || document.body).getPropertyValue(A)) == null ? void 0 : r.trim()) || "top";
|
|
25
|
+
(!i || i === "false" || i === "true" || l === "none") && (t = null), t && (o.textContent = i);
|
|
26
|
+
const y = e && s(e, d) === (o == null ? void 0 : o.id), C = ((p = t instanceof HTMLElement ? t.innerText : t == null ? void 0 : t.textContent) == null ? void 0 : p.trim()) || (t == null ? void 0 : t.hasAttribute(d)) || (t == null ? void 0 : t.hasAttribute("aria-label"));
|
|
27
|
+
e == null || e.removeAttribute(y ? d : b), E(o, !1), e = t, e && s(e, C ? b : d, o == null ? void 0 : o.id), o.togglePopover(!!t), E(o, t || !1, l);
|
|
28
28
|
}
|
|
29
|
-
|
|
29
|
+
v(() => {
|
|
30
30
|
a(document, "blur,focus,mouseout,mouseover", c, u), a(window, "keydown", c, u), a(window, "blur", c, u);
|
|
31
31
|
});
|
|
32
32
|
//# sourceMappingURL=tooltip-observer.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tooltip-observer.js","sources":["../../designsystem/tooltip/tooltip-observer.ts"],"sourcesContent":["import styles from \"../styles.module.css\";\nimport {
|
|
1
|
+
{"version":3,"file":"tooltip-observer.js","sources":["../../designsystem/tooltip/tooltip-observer.ts"],"sourcesContent":["import styles from \"../styles.module.css\";\nimport {\n\tIS_BROWSER,\n\tQUICK_EVENT,\n\tanchorPosition,\n\tattr,\n\ton,\n\tonLoaded,\n} from \"../utils\";\n\nconst DESCRIBEDBY = \"aria-describedby\";\nconst ESC = \"Escape\";\nconst LABELLEDBY = \"aria-labelledby\";\nconst POSITION_CSS_PROPERTY = \"--mtds-tooltip-position\";\nconst THROTTLE_DELAY = 300;\nconst TOOLTIP = IS_BROWSER\n\t? Object.assign(document.createElement(\"div\"), {\n\t\t\tclassName: styles._tooltip,\n\t\t\tid: \"mtds-tooltip\",\n\t\t\tpopover: \"manual\",\n\t\t})\n\t: null; // Create a dummy element to avoid null checks\n\nlet ANCHOR: Element | null = null;\nlet LAST_CALL = Number.NEGATIVE_INFINITY;\nlet THROTTLE: number | ReturnType<typeof setTimeout> = 0;\n\nfunction handleMove({ target, type, key }: Event & { key?: string }) {\n\tif (type === \"keydown\" && key !== ESC) return; // Allow ESC dismiss to follow https://www.w3.org/WAI/ARIA/apg/patterns/tooltip/\n\tconst wait = LAST_CALL + THROTTLE_DELAY - Date.now();\n\tclearTimeout(THROTTLE);\n\tTHROTTLE = setTimeout(\n\t\thandleMoveThrottled,\n\t\tMath.max(wait, 0),\n\t\tkey === ESC ? null : target,\n\t);\n}\n\n// Using a throttled function to avoid performance issues\nfunction handleMoveThrottled(target: Element | null) {\n\tLAST_CALL = Date.now();\n\n\t// Build and append tooltip if not existing\n\tif (!TOOLTIP || target === TOOLTIP) return; // Allow tooltip to be hovered, following https://www.w3.org/TR/WCAG21/#content-on-hover-or-focus\n\tif (!TOOLTIP?.isConnected) document.body.append(TOOLTIP); // Ensure connected\n\tlet anchor = target?.closest?.<Element>(\"[data-tooltip]\") || null;\n\n\t// No need to update\n\tif (anchor === ANCHOR) return;\n\n\tconst content = (anchor && attr(anchor, \"data-tooltip\")) || \"\";\n\tconst position =\n\t\t(anchor && attr(anchor, \"data-tooltip-position\")) ||\n\t\twindow\n\t\t\t.getComputedStyle(anchor || document.body)\n\t\t\t.getPropertyValue(POSITION_CSS_PROPERTY)\n\t\t\t?.trim() ||\n\t\t\"top\";\n\n\tconst isHidden =\n\t\t!content ||\n\t\tcontent === \"false\" ||\n\t\tcontent === \"true\" ||\n\t\tposition === \"none\";\n\n\tif (isHidden) anchor = null; // Do not show tooltip if boolish value\n\tif (anchor) TOOLTIP.textContent = content; // Only update content if new anchor\n\n\tconst hadLabel = ANCHOR && attr(ANCHOR, LABELLEDBY) === TOOLTIP?.id;\n\tconst hasLabel =\n\t\t(anchor instanceof HTMLElement\n\t\t\t? anchor.innerText\n\t\t\t: anchor?.textContent\n\t\t)?.trim() ||\n\t\tanchor?.hasAttribute(LABELLEDBY) ||\n\t\tanchor?.hasAttribute(\"aria-label\");\n\n\tANCHOR?.removeAttribute(hadLabel ? LABELLEDBY : DESCRIBEDBY); // Unlink previous anchor\n\tanchorPosition(TOOLTIP, false); // Reset anchor position\n\n\tANCHOR = anchor; // Store new anchor - might be null if no new anchor\n\tif (ANCHOR) attr(ANCHOR, hasLabel ? DESCRIBEDBY : LABELLEDBY, TOOLTIP?.id); // Use tooltip as description if allready has label\n\tTOOLTIP.togglePopover(!!anchor);\n\tanchorPosition(TOOLTIP, anchor || false, position);\n}\n\nonLoaded(() => {\n\ton(document, \"blur,focus,mouseout,mouseover\", handleMove, QUICK_EVENT);\n\ton(window, \"keydown\", handleMove, QUICK_EVENT);\n\ton(window, \"blur\", handleMove, QUICK_EVENT);\n});\n"],"names":["DESCRIBEDBY","ESC","LABELLEDBY","POSITION_CSS_PROPERTY","THROTTLE_DELAY","TOOLTIP","IS_BROWSER","styles","ANCHOR","LAST_CALL","THROTTLE","handleMove","target","type","key","wait","handleMoveThrottled","anchor","_a","content","attr","position","_b","hadLabel","hasLabel","_c","anchorPosition","onLoaded","on","QUICK_EVENT"],"mappings":";;AAUA,MAAMA,IAAc,oBACdC,IAAM,UACNC,IAAa,mBACbC,IAAwB,2BACxBC,IAAiB,KACjBC,IAAUC,IACb,OAAO,OAAO,SAAS,cAAc,KAAK,GAAG;AAAA,EAC7C,WAAWC,EAAO;AAAA,EAClB,IAAI;AAAA,EACJ,SAAS;AACV,CAAC,IACA;AAEH,IAAIC,IAAyB,MACzBC,IAAY,OAAO,mBACnBC,IAAmD;AAEvD,SAASC,EAAW,EAAE,QAAAC,GAAQ,MAAAC,GAAM,KAAAC,KAAiC;AAChE,MAAAD,MAAS,aAAaC,MAAQb,EAAK;AACvC,QAAMc,IAAON,IAAYL,IAAiB,KAAK,IAAI;AACnD,eAAaM,CAAQ,GACVA,IAAA;AAAA,IACVM;AAAA,IACA,KAAK,IAAID,GAAM,CAAC;AAAA,IAChBD,MAAQb,IAAM,OAAOW;AAAA,EACtB;AACD;AAGA,SAASI,EAAoBJ,GAAwB;;AAIhD,MAHJH,IAAY,KAAK,IAAI,GAGjB,CAACJ,KAAWO,MAAWP,EAAS;AACpC,EAAKA,KAAA,QAAAA,EAAS,eAAsB,SAAA,KAAK,OAAOA,CAAO;AACvD,MAAIY,MAASC,IAAAN,KAAA,gBAAAA,EAAQ,YAAR,gBAAAM,EAAA,KAAAN,GAA2B,sBAAqB;AAG7D,MAAIK,MAAWT,EAAQ;AAEvB,QAAMW,IAAWF,KAAUG,EAAKH,GAAQ,cAAc,KAAM,IACtDI,IACJJ,KAAUG,EAAKH,GAAQ,uBAAuB,OAC/CK,IAAA,OACE,iBAAiBL,KAAU,SAAS,IAAI,EACxC,iBAAiBd,CAAqB,MAFxC,gBAAAmB,EAGG,WACH;AAQD,GALC,CAACH,KACDA,MAAY,WACZA,MAAY,UACZE,MAAa,YAESJ,IAAA,OACnBA,QAAgB,cAAcE;AAElC,QAAMI,IAAWf,KAAUY,EAAKZ,GAAQN,CAAU,OAAMG,KAAA,gBAAAA,EAAS,KAC3DmB,MACJC,IAAAR,aAAkB,cAChBA,EAAO,YACPA,KAAA,gBAAAA,EAAQ,gBAFV,gBAAAQ,EAGE,YACHR,KAAA,gBAAAA,EAAQ,aAAaf,QACrBe,KAAA,gBAAAA,EAAQ,aAAa;AAEd,EAAAT,KAAA,QAAAA,EAAA,gBAAgBe,IAAWrB,IAAaF,IAChD0B,EAAerB,GAAS,EAAK,GAEpBG,IAAAS,GACLT,KAAaY,EAAAZ,GAAQgB,IAAWxB,IAAcE,GAAYG,KAAA,gBAAAA,EAAS,EAAE,GACjEA,EAAA,cAAc,CAAC,CAACY,CAAM,GACfS,EAAArB,GAASY,KAAU,IAAOI,CAAQ;AAClD;AAEAM,EAAS,MAAM;AACX,EAAAC,EAAA,UAAU,iCAAiCjB,GAAYkB,CAAW,GAClED,EAAA,QAAQ,WAAWjB,GAAYkB,CAAW,GAC1CD,EAAA,QAAQ,QAAQjB,GAAYkB,CAAW;AAC3C,CAAC;"}
|
package/mtds/utils.d.ts
CHANGED
|
@@ -34,18 +34,26 @@ export declare function anchorPosition(target: HTMLElement, anchor: Element | fa
|
|
|
34
34
|
* @return new MutaionObserver
|
|
35
35
|
*/
|
|
36
36
|
export declare function createOptimizedMutationObserver(callback: MutationCallback): MutationObserver;
|
|
37
|
-
|
|
38
|
-
* onMutation
|
|
39
|
-
* @description Utility to quickly observe mutations on a specific class name
|
|
40
|
-
* @param element The Element to use as EventTarget
|
|
41
|
-
* @param className The class name to observe
|
|
42
|
-
* @param callback The callback to run when mutations are detected or false to stop observing
|
|
43
|
-
*/
|
|
44
|
-
export declare const onMutation: <T extends Element>(element: Element, className: string, callback: ((collection: HTMLCollectionOf<T>) => void) | false) => void;
|
|
37
|
+
export declare const onMutation: <T extends Element>(el: Element, className: string, callback: (elems: HTMLCollectionOf<T>) => void) => void;
|
|
45
38
|
/**
|
|
46
39
|
* onLoaded
|
|
47
40
|
* @description Runs a callback when window is loaded in browser
|
|
48
41
|
* @param callback The callback to run when the page is ready
|
|
49
42
|
*/
|
|
50
43
|
export declare const onLoaded: (callback: () => void) => void;
|
|
44
|
+
/**
|
|
45
|
+
* isInputLike
|
|
46
|
+
* @description Check if element is an input like element
|
|
47
|
+
* @param el The element to check
|
|
48
|
+
* @returns True if the element is an input like element
|
|
49
|
+
*/
|
|
51
50
|
export declare const isInputLike: (el: unknown) => el is HTMLInputElement;
|
|
51
|
+
/**
|
|
52
|
+
* toCustomElementProps
|
|
53
|
+
* @description Utility to quickly convert props to custom element attributes
|
|
54
|
+
* @param props The props to convert
|
|
55
|
+
* @returns The converted props
|
|
56
|
+
*/
|
|
57
|
+
export declare const toCustomElementProps: ({ className, hidden, open, ...rest }: Record<string, unknown>, klass?: string) => {
|
|
58
|
+
[x: string]: unknown;
|
|
59
|
+
};
|
package/mtds/utils.js
CHANGED
|
@@ -1,95 +1,79 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { clsx as v } from "./external/clsx/dist/clsx.js";
|
|
2
|
+
const C = { capture: !0, passive: !0 }, w = typeof window < "u" && typeof document < "u";
|
|
3
|
+
function D(t, e, n) {
|
|
3
4
|
return n === void 0 ? t.getAttribute(e) ?? null : (n === null ? t.removeAttribute(e) : t.getAttribute(e) !== n && t.setAttribute(e, n), null);
|
|
4
5
|
}
|
|
5
6
|
let O = 0;
|
|
6
|
-
const
|
|
7
|
-
function
|
|
8
|
-
return t.id || (t.id = `${
|
|
7
|
+
const P = `${Date.now().toString(36)}${Math.random().toString(36).slice(2, 5)}`;
|
|
8
|
+
function L(t) {
|
|
9
|
+
return t.id || (t.id = `${P}${++O}`), t.id;
|
|
9
10
|
}
|
|
10
|
-
const
|
|
11
|
+
const _ = (t, e, n) => {
|
|
11
12
|
for (const i of n[0].split(","))
|
|
12
13
|
n[0] = i, e[`${t}EventListener`](...n);
|
|
13
|
-
},
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
() => {
|
|
19
|
-
for (const [t, e] of p) e();
|
|
20
|
-
},
|
|
21
|
-
U
|
|
22
|
-
);
|
|
23
|
-
const u = { top: 0, right: 1, bottom: 2, left: 3 };
|
|
14
|
+
}, M = (t, ...e) => _("add", t, e), c = w ? document.createElement("div") : null, l = /* @__PURE__ */ new Map(), B = () => {
|
|
15
|
+
for (const [t, e] of l) e();
|
|
16
|
+
};
|
|
17
|
+
c && (c.style.cssText = "position:absolute;padding:1px;top:0;left:0px", M(window, "load,resize,scroll", B, C));
|
|
18
|
+
const a = { top: 0, right: 1, bottom: 2, left: 3 };
|
|
24
19
|
function F(t, e, n) {
|
|
25
|
-
var
|
|
20
|
+
var m;
|
|
26
21
|
if (e === !1 || !e.isConnected || !t.isConnected)
|
|
27
|
-
return
|
|
28
|
-
if (
|
|
29
|
-
const
|
|
30
|
-
return (
|
|
22
|
+
return l.delete(t);
|
|
23
|
+
if (c != null && c.isConnected || document.body.append(c || ""), !l.has(t)) {
|
|
24
|
+
const U = a[n] ?? a.bottom;
|
|
25
|
+
return (m = l.set(t, () => F(t, e, U)).get(
|
|
31
26
|
t
|
|
32
|
-
)) == null ? void 0 :
|
|
27
|
+
)) == null ? void 0 : m();
|
|
33
28
|
}
|
|
34
|
-
const i = e instanceof HTMLElement, { offsetWidth: o, offsetHeight:
|
|
35
|
-
Math.max(10,
|
|
29
|
+
const i = e instanceof HTMLElement, { offsetWidth: o, offsetHeight: d } = t, s = i ? e.offsetWidth : e.clientWidth, r = i ? e.offsetHeight : e.clientHeight, { width: T, height: g, left: b, top: y } = e.getBoundingClientRect(), f = Math.round(b - (s - T) / 2), u = Math.round(y - (r - g) / 2), x = f - o > 0, A = s + s + o < window.innerWidth, H = u - d > 0, E = u + r + d < window.innerHeight, S = n === a.bottom && A || !x, W = n === a.bottom && E || !H, $ = Math.min(
|
|
30
|
+
Math.max(10, f - (o - s) / 2),
|
|
36
31
|
window.innerWidth - o - 10
|
|
37
|
-
),
|
|
38
|
-
Math.max(10,
|
|
39
|
-
window.innerHeight -
|
|
40
|
-
),
|
|
41
|
-
t.style.left = `${Math.round(
|
|
32
|
+
), I = Math.min(
|
|
33
|
+
Math.max(10, u - (d - r) / 2),
|
|
34
|
+
window.innerHeight - d - 10
|
|
35
|
+
), h = n === a.top || n === a.bottom;
|
|
36
|
+
t.style.left = `${Math.round(h ? $ : S ? f + s : f - o)}px`, t.style.top = `${Math.round(h ? W ? u + r : u - d : I)}px`, c == null || c.style.setProperty(
|
|
42
37
|
"translate",
|
|
43
|
-
`${Math.round(window.scrollX +
|
|
38
|
+
`${Math.round(window.scrollX + f + s + o + 30)}px ${Math.round(window.scrollY + u + r + d + 30)}px`
|
|
44
39
|
);
|
|
45
40
|
}
|
|
46
|
-
function
|
|
41
|
+
function k(t) {
|
|
47
42
|
let e = 0;
|
|
48
43
|
const n = () => setTimeout(i, 200), i = () => {
|
|
49
|
-
t([], o), e = 0;
|
|
44
|
+
t([], o), o.takeRecords(), e = 0;
|
|
50
45
|
}, o = new MutationObserver(() => {
|
|
51
46
|
e || (e = requestAnimationFrame(n));
|
|
52
47
|
});
|
|
53
48
|
return o;
|
|
54
49
|
}
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}, P = (t, e, n) => {
|
|
65
|
-
const i = t.getElementsByClassName(
|
|
66
|
-
e
|
|
67
|
-
);
|
|
68
|
-
let o = a.get(t);
|
|
69
|
-
o || (o = {
|
|
70
|
-
collections: /* @__PURE__ */ new Map(),
|
|
71
|
-
observer: _(
|
|
72
|
-
() => q(t)
|
|
73
|
-
)
|
|
74
|
-
}, o.observer.observe(t, {
|
|
75
|
-
childList: !0,
|
|
76
|
-
subtree: !0,
|
|
50
|
+
const p = /* @__PURE__ */ new WeakMap(), N = (t, e, n) => {
|
|
51
|
+
const i = t.getElementsByClassName(e), o = p.get(t) || [];
|
|
52
|
+
o.length || (p.set(t, o), k((d, s) => {
|
|
53
|
+
if (t.isConnected && (o != null && o.length))
|
|
54
|
+
for (const r of o) r();
|
|
55
|
+
else
|
|
56
|
+
s == null || s.disconnect(), p.delete(t);
|
|
57
|
+
}).observe(t, {
|
|
58
|
+
attributeFilter: ["class"],
|
|
77
59
|
attributes: !0,
|
|
78
|
-
|
|
79
|
-
|
|
60
|
+
childList: !0,
|
|
61
|
+
subtree: !0
|
|
62
|
+
})), o.push(() => n(i));
|
|
80
63
|
}, R = (t) => {
|
|
81
|
-
|
|
82
|
-
}, X = (t) => t instanceof HTMLElement && "validity" in t && !(t instanceof HTMLButtonElement);
|
|
64
|
+
w && (document.readyState === "complete" ? window.requestAnimationFrame(t) : M(window, "load", t));
|
|
65
|
+
}, X = (t) => t instanceof HTMLElement && "validity" in t && !(t instanceof HTMLButtonElement), Y = ({ className: t, hidden: e, open: n, ...i }, o) => (i.class = v(o, t || "") || void 0, e && (i.hidden = !0), n && (i.open = !0), i);
|
|
83
66
|
export {
|
|
84
|
-
|
|
85
|
-
|
|
67
|
+
w as IS_BROWSER,
|
|
68
|
+
C as QUICK_EVENT,
|
|
86
69
|
F as anchorPosition,
|
|
87
|
-
|
|
88
|
-
|
|
70
|
+
D as attr,
|
|
71
|
+
k as createOptimizedMutationObserver,
|
|
89
72
|
X as isInputLike,
|
|
90
|
-
|
|
73
|
+
M as on,
|
|
91
74
|
R as onLoaded,
|
|
92
|
-
|
|
93
|
-
|
|
75
|
+
N as onMutation,
|
|
76
|
+
Y as toCustomElementProps,
|
|
77
|
+
L as useId
|
|
94
78
|
};
|
|
95
79
|
//# 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 QUICK_EVENT = { capture: true, passive: true };\nexport const IS_BROWSER =\n\ttypeof window !== \"undefined\" && typeof document !== \"undefined\";\n\n// TODO: Documentation for prettyNumber\nlet INTL_NUM: Intl.NumberFormat | undefined;\nexport function prettyNumber(number: number | string) {\n\tif (!INTL_NUM)\n\t\tINTL_NUM = new Intl.NumberFormat(\n\t\t\t(IS_BROWSER && attr(document.documentElement, \"lang\")) || \"no\",\n\t\t);\n\treturn INTL_NUM.format(Number(number));\n}\n\nexport function debounce<T extends unknown[]>(\n\tcallback: (...args: T) => void,\n\tdelay: number,\n) {\n\tlet timer: ReturnType<typeof setTimeout>;\n\n\treturn (...args: T) => {\n\t\tclearTimeout(timer);\n\t\ttimer = setTimeout(() => callback(...args), delay);\n\t};\n}\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\tif (!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/**\n * Scroller targes helping anchorPosition\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)\n\tattr(SCROLLER, \"style\", \"position:absolute;padding:1px;top:0;left:0px\");\n\nif (IS_BROWSER) {\n\ton(\n\t\twindow,\n\t\t\"load,resize,scroll\",\n\t\t() => {\n\t\t\tfor (const [_, update] of TARGETS) update();\n\t\t},\n\t\tQUICK_EVENT,\n\t);\n}\n\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(\n\ttarget: HTMLElement,\n\tanchor: Element | false,\n\tposition?: string | number,\n) {\n\tif (anchor === false || !anchor.isConnected || !target.isConnected)\n\t\treturn TARGETS.delete(target); // Stop watching 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\t// Setup new target or update position\n\t\tconst place =\n\t\t\tPOSITION[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(\n\t\t\ttarget,\n\t\t)?.(); // Start watching if not already watching\n\t}\n\n\tconst isHTMLAnchor = anchor instanceof HTMLElement; // SVG or XML elements does not have offsetWidth or offsetHeight\n\tconst { offsetWidth: targetW, offsetHeight: targetH } = target;\n\tconst anchorW = isHTMLAnchor ? anchor.offsetWidth : anchor.clientWidth;\n\tconst anchorH = isHTMLAnchor ? anchor.offsetHeight : anchor.clientHeight;\n\tconst { width, height, left, top } = anchor.getBoundingClientRect();\n\tconst anchorX = Math.round(left - (anchorW - width) / 2); // Correct for CSS transform scale\n\tconst 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 =\n\t\t(position === POSITION.bottom && hasSpaceRight) || !hasSpaceLeft; // Always position right when no hasSpaceLeft, as no OS scrolls further up than 0\n\tconst positionUnder =\n\t\t(position === POSITION.bottom && hasSpaceUnder) || !hasSpaceOver; // Always position under when no hasSpaceOver, as no OS scrolls further up than 0\n\tconst centerX = Math.min(\n\t\tMath.max(10, anchorX - (targetW - anchorW) / 2),\n\t\twindow.innerWidth - targetW - 10,\n\t);\n\tconst centerY = Math.min(\n\t\tMath.max(10, anchorY - (targetH - anchorH) / 2),\n\t\twindow.innerHeight - targetH - 10,\n\t);\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\ttarget.style.top = `${Math.round(isVertical ? (positionUnder ? anchorY + anchorH : anchorY - targetH) : centerY)}px`;\n\tSCROLLER?.style.setProperty(\n\t\t\"translate\",\n\t\t`${Math.round(window.scrollX + anchorX + anchorW + targetW + 30)} ${Math.round(window.scrollY + anchorY + anchorH + targetH + 30)}px`,\n\t);\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\tlet 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\tconst observer = new MutationObserver(() => {\n\t\tif (!queue) queue = requestAnimationFrame(onFrame);\n\t});\n\n\treturn observer;\n}\n\ntype Mutator = {\n\tobserver: MutationObserver;\n\tcollections: Map<string, () => void>;\n};\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 {\n\t\tfor (const [, callback] of mutator.collections) callback();\n\t\tmutator.observer.takeRecords(); // Clear records to avoid running callback multiple times\n\t}\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 = <T extends Element>(\n\telement: Element,\n\tclassName: string,\n\tcallback: ((collection: HTMLCollectionOf<T>) => void) | false,\n) => {\n\tconst collection = element.getElementsByClassName(\n\t\tclassName,\n\t) as HTMLCollectionOf<T>;\n\tlet mutator = MUTATORS.get(element);\n\n\tif (!mutator) {\n\t\tmutator = {\n\t\t\tcollections: new Map(),\n\t\t\tobserver: createOptimizedMutationObserver(() =>\n\t\t\t\tMUTATORS_CALLBACK(element),\n\t\t\t),\n\t\t};\n\t\tmutator.observer.observe(element, {\n\t\t\tchildList: true,\n\t\t\tsubtree: true,\n\t\t\tattributes: true,\n\t\t\tattributeFilter: [\"class\"],\n\t\t});\n\t\tMUTATORS.set(element, mutator);\n\t}\n\tif (callback) mutator.collections.set(className, () => callback(collection));\n\telse mutator.collections.delete(className);\n\tif (!mutator.collections.size) {\n\t\tmutator.observer.disconnect(); // Remove mutation observer if no more callbacks\n\t\tMUTATORS.delete(element);\n\t}\n};\n\n/**\n * onLoaded\n * @description Runs a callback when window is loaded in browser\n * @param callback The callback to run when the page is ready\n */\nexport const onLoaded = (callback: () => void) => {\n\tif (!IS_BROWSER) return;\n\tif (document.readyState === \"complete\")\n\t\twindow.requestAnimationFrame(callback); // Ensure we run after all other load events\n\telse on(window, \"load\", callback);\n};\n\nexport const isInputLike = (el: unknown): el is HTMLInputElement =>\n\tel instanceof HTMLElement &&\n\t\"validity\" in el &&\n\t!(el instanceof HTMLButtonElement);\n"],"names":["QUICK_EVENT","IS_BROWSER","attr","el","name","value","id","UUID","useId","events","action","element","rest","type","on","TARGETS","SCROLLER","_","update","POSITION","anchorPosition","target","anchor","position","_a","place","isHTMLAnchor","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","onLoaded","isInputLike"],"mappings":"AAAO,MAAMA,IAAc,EAAE,SAAS,IAAM,SAAS,GAAK,GAC7CC,IACZ,OAAO,SAAW,OAAe,OAAO,WAAa;AA+BtC,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,GAAG,KAAK,SAAS,SAAS,EAAE,EAAE,MAAM,GAAG,CAAC,CAAC;AACzE,SAASC,E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zB,GAOa+C,IAAW,CAACX,MAAyB;AACjD,EAAK9C,MACD,SAAS,eAAe,aAC3B,OAAO,sBAAsB8C,CAAQ,IACjCjC,EAAG,QAAQ,QAAQiC,CAAQ;AACjC,GAEaY,IAAc,CAACxD,MAC3BA,aAAc,eACd,cAAcA,KACd,EAAEA,aAAc;"}
|
|
1
|
+
{"version":3,"file":"utils.js","sources":["../designsystem/utils.ts"],"sourcesContent":["import { clsx } from \"clsx\";\n\nexport const QUICK_EVENT = { capture: true, passive: true };\nexport const IS_BROWSER =\n\ttypeof window !== \"undefined\" && typeof document !== \"undefined\";\n\n// TODO: Documentation for prettyNumber\nlet INTL_NUM: Intl.NumberFormat | undefined;\nexport function prettyNumber(number: number | string) {\n\tif (!INTL_NUM)\n\t\tINTL_NUM = new Intl.NumberFormat(\n\t\t\t(IS_BROWSER && attr(document.documentElement, \"lang\")) || \"no\",\n\t\t);\n\treturn INTL_NUM.format(Number(number));\n}\n\nexport function debounce<T extends unknown[]>(\n\tcallback: (...args: T) => void,\n\tdelay: number,\n) {\n\tlet timer: ReturnType<typeof setTimeout>;\n\n\treturn (...args: T) => {\n\t\tclearTimeout(timer);\n\t\ttimer = setTimeout(() => callback(...args), delay);\n\t};\n}\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\tif (!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/**\n * Scroller targes helping anchorPosition\n */\nconst SCROLLER = IS_BROWSER ? document.createElement(\"div\") : null; // Used to ensure we have scrollability under\nconst TARGETS = new Map<Element, () => void>(); // Store current open poppers and their update functions\nconst TARGETS_UPDATE = () => {\n\tfor (const [_, update] of TARGETS) update();\n};\n\nif (SCROLLER) {\n\tSCROLLER.style.cssText = \"position:absolute;padding:1px;top:0;left:0px\";\n\ton(window, \"load,resize,scroll\", TARGETS_UPDATE, QUICK_EVENT);\n}\n\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(\n\ttarget: HTMLElement,\n\tanchor: Element | false,\n\tposition?: string | number,\n) {\n\tif (anchor === false || !anchor.isConnected || !target.isConnected)\n\t\treturn TARGETS.delete(target); // Stop watching if anchor is removed from DOM\n\tif (!SCROLLER?.isConnected) document.body.append(SCROLLER || \"\"); // Ensure we have the scroller\n\tif (!TARGETS.has(target)) {\n\t\t// Setup new target or update position\n\t\tconst place =\n\t\t\tPOSITION[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(\n\t\t\ttarget,\n\t\t)?.(); // Start watching if not already watching\n\t}\n\n\tconst isHTMLAnchor = anchor instanceof HTMLElement; // SVG or XML elements does not have offsetWidth or offsetHeight\n\tconst { offsetWidth: targetW, offsetHeight: targetH } = target;\n\tconst anchorW = isHTMLAnchor ? anchor.offsetWidth : anchor.clientWidth;\n\tconst anchorH = isHTMLAnchor ? anchor.offsetHeight : anchor.clientHeight;\n\tconst { width, height, left, top } = anchor.getBoundingClientRect();\n\tconst anchorX = Math.round(left - (anchorW - width) / 2); // Correct for CSS transform scale\n\tconst 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 =\n\t\t(position === POSITION.bottom && hasSpaceRight) || !hasSpaceLeft; // Always position right when no hasSpaceLeft, as no OS scrolls further up than 0\n\tconst positionUnder =\n\t\t(position === POSITION.bottom && hasSpaceUnder) || !hasSpaceOver; // Always position under when no hasSpaceOver, as no OS scrolls further up than 0\n\tconst centerX = Math.min(\n\t\tMath.max(10, anchorX - (targetW - anchorW) / 2),\n\t\twindow.innerWidth - targetW - 10,\n\t);\n\tconst centerY = Math.min(\n\t\tMath.max(10, anchorY - (targetH - anchorH) / 2),\n\t\twindow.innerHeight - targetH - 10,\n\t);\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\ttarget.style.top = `${Math.round(isVertical ? (positionUnder ? anchorY + anchorH : anchorY - targetH) : centerY)}px`;\n\tSCROLLER?.style.setProperty(\n\t\t\"translate\",\n\t\t`${Math.round(window.scrollX + anchorX + anchorW + targetW + 30)}px ${Math.round(window.scrollY + anchorY + anchorH + targetH + 30)}px`,\n\t);\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\tlet 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\tobserver.takeRecords(); // Clear records to avoid running callback multiple times\n\t\tqueue = 0;\n\t};\n\tconst observer = new MutationObserver(() => {\n\t\tif (!queue) queue = requestAnimationFrame(onFrame);\n\t});\n\n\treturn observer;\n}\n\n/**\n * onMutation\n * @description Utility to quickly observe mutations on a specific class name\n * @param el 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\n */\nconst MUTATORS = new WeakMap<Element, Array<() => void>>();\nexport const onMutation = <T extends Element>(\n\tel: Element,\n\tclassName: string,\n\tcallback: (elems: HTMLCollectionOf<T>) => void,\n) => {\n\tconst elems = el.getElementsByClassName(className);\n\tconst mutator = MUTATORS.get(el) || [];\n\n\tif (!mutator.length) {\n\t\tMUTATORS.set(el, mutator);\n\t\tcreateOptimizedMutationObserver((_, observer) => {\n\t\t\tif (el.isConnected && mutator?.length) {\n\t\t\t\tfor (const callback of mutator) callback();\n\t\t\t} else {\n\t\t\t\tobserver?.disconnect();\n\t\t\t\tMUTATORS.delete(el);\n\t\t\t}\n\t\t}).observe(el, {\n\t\t\tattributeFilter: [\"class\"],\n\t\t\tattributes: true,\n\t\t\tchildList: true,\n\t\t\tsubtree: true,\n\t\t});\n\t}\n\tmutator.push(() => callback(elems as HTMLCollectionOf<T>));\n};\n\n/**\n * onLoaded\n * @description Runs a callback when window is loaded in browser\n * @param callback The callback to run when the page is ready\n */\nexport const onLoaded = (callback: () => void) => {\n\tif (!IS_BROWSER) return;\n\tif (document.readyState === \"complete\")\n\t\twindow.requestAnimationFrame(callback); // Ensure we run after all other load events\n\telse on(window, \"load\", callback);\n};\n\n/**\n * isInputLike\n * @description Check if element is an input like element\n * @param el The element to check\n * @returns True if the element is an input like element\n */\nexport const isInputLike = (el: unknown): el is HTMLInputElement =>\n\tel instanceof HTMLElement &&\n\t\"validity\" in el &&\n\t!(el instanceof HTMLButtonElement);\n\n/**\n * toCustomElementProps\n * @description Utility to quickly convert props to custom element attributes\n * @param props The props to convert\n * @returns The converted props\n */\nexport const toCustomElementProps = (\n\t{ className, hidden, open, ...rest }: Record<string, unknown>,\n\tklass?: string,\n) => {\n\trest.class = clsx(klass, className || \"\") || undefined; // Use class instead of className\n\tif (hidden) rest.hidden = true; // Ensure boolean prop behaviour\n\tif (open) rest.open = true; // Ensure boolean prop behaviour\n\treturn rest;\n};\n"],"names":["QUICK_EVENT","IS_BROWSER","attr","el","name","value","id","UUID","useId","events","action","element","rest","type","on","SCROLLER","TARGETS","TARGETS_UPDATE","_","update","POSITION","anchorPosition","target","anchor","position","place","_a","isHTMLAnchor","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","onMutation","className","elems","mutator","onLoaded","isInputLike","toCustomElementProps","hidden","open","klass","clsx"],"mappings":";AAEO,MAAMA,IAAc,EAAE,SAAS,IAAM,SAAS,GAAK,GAC7CC,IACZ,OAAO,SAAW,OAAe,OAAO,WAAa;AA+BtC,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,GAAG,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