@mattilsynet/design 2.2.7 → 2.2.9

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.js CHANGED
@@ -1,12 +1,13 @@
1
1
  import { jsx as c } from "react/jsx-runtime";
2
- import m from "clsx";
3
- import { forwardRef as n } from "react";
4
- import f from "../styles.module.css.js";
5
- const g = n(function({ as: o, className: t, ...r }, a) {
6
- const s = o || (r.href ? "a" : "div");
7
- return /* @__PURE__ */ c(s, { className: m(f.card, t), ref: a, ...r });
8
- }), l = n(function({ as: o, className: t, ...r }, a) {
9
- return /* @__PURE__ */ c(o || "div", { className: m(f.group, t), ref: a, ...r });
2
+ import s from "clsx";
3
+ import { forwardRef as f } from "react";
4
+ import i from "../styles.module.css.js";
5
+ const g = f(function({ as: t, className: n, ...o }, a) {
6
+ const r = t || (o.href ? "a" : "div");
7
+ return /* @__PURE__ */ c(r, { className: s(i.card, n), ref: a, ...o });
8
+ }), l = f(function({ as: t, className: n, ...o }, a) {
9
+ const r = t || "div";
10
+ return r === "button" && !o.type && Object.assign(o, { type: "button" }), /* @__PURE__ */ c(r, { className: s(i.group, n), ref: a, ...o });
10
11
  });
11
12
  export {
12
13
  g as Card,
@@ -1 +1 @@
1
- {"version":3,"file":"card.js","sources":["../../designsystem/card/card.tsx"],"sourcesContent":["import clsx from \"clsx\";\nimport { forwardRef, type JSX } from \"react\";\nimport type {\n\tPolymorphicComponentPropWithRef,\n\tPolymorphicRef,\n\tSizes,\n} from \"../react-types\";\nimport styles from \"../styles.module.css\";\n\ntype CardBaseProps<Href> = {\n\t\"data-pad\"?: Sizes;\n\thref?: Href;\n};\n\nexport type CardProps<\n\tHref,\n\tAs extends React.ElementType = Href extends string ? \"a\" : \"div\",\n> = PolymorphicComponentPropWithRef<As, CardBaseProps<Href>>;\n\ntype CardComponent = <\n\tHref,\n\tAs extends React.ElementType = Href extends string ? \"a\" : \"div\",\n>(\n\tprops: CardProps<Href, As>,\n) => JSX.Element;\n\nexport const Card: CardComponent = forwardRef<null>(function Card<\n\tHref,\n\tAs extends React.ElementType = Href extends string ? \"a\" : \"div\",\n>({ as, className, ...rest }: CardProps<Href, As>, ref?: PolymorphicRef<As>) {\n\tconst Tag = as || (rest.href ? \"a\" : \"div\");\n\n\treturn <Tag className={clsx(styles.card, className)} ref={ref} {...rest} />;\n}) as CardComponent; // Needed to tell Typescript this does not return ReactNode but acutally JSX.Element\n\nexport type GroupProps<As extends React.ElementType = \"div\"> =\n\tPolymorphicComponentPropWithRef<As, { \"data-pad\"?: Sizes }>;\n\ntype GroupComponent = <As extends React.ElementType = \"div\">(\n\tprops: GroupProps<As>,\n) => JSX.Element;\n\nexport const Group: GroupComponent = forwardRef<null>(function Group<\n\tAs extends React.ElementType = \"div\",\n>({ as, className, ...rest }: GroupProps<As>, ref?: PolymorphicRef<As>) {\n\tconst Tag = as || \"div\";\n\n\treturn <Tag className={clsx(styles.group, className)} ref={ref} {...rest} />;\n}) as GroupComponent; // Needed to tell Typescript this does not return ReactNode but acutally JSX.Element\n"],"names":["Card","forwardRef","as","className","rest","ref","Tag","jsx","clsx","styles","Group"],"mappings":";;;;AA0BO,MAAMA,IAAsBC,EAAiB,SAGlD,EAAE,IAAAC,GAAI,WAAAC,GAAW,GAAGC,EAAA,GAA6BC,GAA0B;AAC5E,QAAMC,IAAMJ,MAAOE,EAAK,OAAO,MAAM;AAErC,SAAO,gBAAAG,EAACD,GAAA,EAAI,WAAWE,EAAKC,EAAO,MAAMN,CAAS,GAAG,KAAAE,GAAW,GAAGD,EAAA,CAAM;AAC1E,CAAC,GASYM,IAAwBT,EAAiB,SAEpD,EAAE,IAAAC,GAAI,WAAAC,GAAW,GAAGC,EAAA,GAAwBC,GAA0B;AAGvE,SAAO,gBAAAE,EAFKL,KAAM,OAEV,EAAI,WAAWM,EAAKC,EAAO,OAAON,CAAS,GAAG,KAAAE,GAAW,GAAGD,EAAA,CAAM;AAC3E,CAAC;"}
1
+ {"version":3,"file":"card.js","sources":["../../designsystem/card/card.tsx"],"sourcesContent":["import clsx from \"clsx\";\nimport { forwardRef, type JSX } from \"react\";\nimport type {\n\tPolymorphicComponentPropWithRef,\n\tPolymorphicRef,\n\tSizes,\n} from \"../react-types\";\nimport styles from \"../styles.module.css\";\n\ntype CardBaseProps<Href> = {\n\t\"data-pad\"?: Sizes;\n\thref?: Href;\n};\n\nexport type CardProps<\n\tHref,\n\tAs extends React.ElementType = Href extends string ? \"a\" : \"div\",\n> = PolymorphicComponentPropWithRef<As, CardBaseProps<Href>>;\n\ntype CardComponent = <\n\tHref,\n\tAs extends React.ElementType = Href extends string ? \"a\" : \"div\",\n>(\n\tprops: CardProps<Href, As>,\n) => JSX.Element;\n\nexport const Card: CardComponent = forwardRef<null>(function Card<\n\tHref,\n\tAs extends React.ElementType = Href extends string ? \"a\" : \"div\",\n>({ as, className, ...rest }: CardProps<Href, As>, ref?: PolymorphicRef<As>) {\n\tconst Tag = as || (rest.href ? \"a\" : \"div\");\n\n\treturn <Tag className={clsx(styles.card, className)} ref={ref} {...rest} />;\n}) as CardComponent; // Needed to tell Typescript this does not return ReactNode but acutally JSX.Element\n\nexport type GroupProps<As extends React.ElementType = \"div\"> =\n\tPolymorphicComponentPropWithRef<As, { \"data-pad\"?: Sizes }>;\n\ntype GroupComponent = <As extends React.ElementType = \"div\">(\n\tprops: GroupProps<As>,\n) => JSX.Element;\n\nexport const Group: GroupComponent = forwardRef<null>(function Group<\n\tAs extends React.ElementType = \"div\",\n>({ as, className, ...rest }: GroupProps<As>, ref?: PolymorphicRef<As>) {\n\tconst Tag = as || \"div\";\n\tif (Tag === \"button\" && !rest.type) Object.assign(rest, { type: \"button\" }); // Default type for button to avoid accidental submits\n\treturn <Tag className={clsx(styles.group, className)} ref={ref} {...rest} />;\n}) as GroupComponent; // Needed to tell Typescript this does not return ReactNode but acutally JSX.Element\n"],"names":["Card","forwardRef","as","className","rest","ref","Tag","jsx","clsx","styles","Group"],"mappings":";;;;AA0BO,MAAMA,IAAsBC,EAAiB,SAGlD,EAAE,IAAAC,GAAI,WAAAC,GAAW,GAAGC,EAAA,GAA6BC,GAA0B;AAC5E,QAAMC,IAAMJ,MAAOE,EAAK,OAAO,MAAM;AAErC,SAAO,gBAAAG,EAACD,GAAA,EAAI,WAAWE,EAAKC,EAAO,MAAMN,CAAS,GAAG,KAAAE,GAAW,GAAGD,EAAA,CAAM;AAC1E,CAAC,GASYM,IAAwBT,EAAiB,SAEpD,EAAE,IAAAC,GAAI,WAAAC,GAAW,GAAGC,EAAA,GAAwBC,GAA0B;AACvE,QAAMC,IAAMJ,KAAM;AAClB,SAAII,MAAQ,YAAY,CAACF,EAAK,QAAM,OAAO,OAAOA,GAAM,EAAE,MAAM,SAAA,CAAU,GACnE,gBAAAG,EAACD,GAAA,EAAI,WAAWE,EAAKC,EAAO,OAAON,CAAS,GAAG,KAAAE,GAAW,GAAGD,EAAA,CAAM;AAC3E,CAAC;"}
@@ -1,12 +1,12 @@
1
1
  import g from "../styles.module.css.js";
2
- import { IS_BROWSER as b, tag as c, MTDSElement as E, on as C, off as k, attr as d } from "../utils.js";
3
- import T from "./chart.css.js";
4
- import { toAxis as w } from "./chart-axis.js";
2
+ import { IS_BROWSER as f, tag as d, MTDSElement as E, on as C, off as k, attr as p } from "../utils.js";
3
+ import w from "./chart.css.js";
4
+ import { toAxis as T } from "./chart-axis.js";
5
5
  import { toBars as S } from "./chart-bars.js";
6
6
  import { toLines as _ } from "./chart-lines.js";
7
- import { toPies as O } from "./chart-pies.js";
8
- const h = "click,keydown,mousemove,mouseout", p = "mtds-chart-tooltip", a = b ? document.getElementById(p) || c("div", { class: g._tooltip, id: p, hidden: "" }) : null;
9
- class $ extends E {
7
+ import { toPies as $ } from "./chart-pies.js";
8
+ const h = "click,keydown,mousemove,mouseout", u = "mtds-chart-tooltip", r = f ? document.getElementById(u) || d("div", { class: g._tooltip, id: u, hidden: "" }) : null;
9
+ class O extends E {
10
10
  _observer;
11
11
  // Using underscore instead of # for backwards compatibility
12
12
  static get observedAttributes() {
@@ -27,16 +27,16 @@ class $ extends E {
27
27
  }), this.attributeChangedCallback(), C(this, h, this);
28
28
  }
29
29
  disconnectedCallback() {
30
- a && (a.hidden = !0), k(this, h, this), this._observer?.disconnect(), this._observer = void 0;
30
+ r && (r.hidden = !0), k(this, h, this), this._observer?.disconnect(), this._observer = void 0;
31
31
  }
32
32
  attributeChangedCallback() {
33
- Array.from(this.shadowRoot?.children || []).map((l) => l.remove());
34
- const e = x(this.querySelector("table")), [t, s] = (d(this, "data-variant") || "bar").split("-"), r = c("style", {}, T), n = c("div", { class: "legends" });
35
- e.slice(1).forEach(([{ value: l, style: v }]) => {
36
- n.appendChild(c("div", { class: "legend", style: v }, l));
33
+ Array.from(this.shadowRoot?.children || []).map((m) => m.remove());
34
+ const e = x(this.querySelector("table")), [t, s] = (p(this, "data-variant") || "bar").split("-"), a = d("style", {}, w), i = d("div", { class: "legends" });
35
+ e.slice(1).forEach(([{ value: m, style: v }]) => {
36
+ i.appendChild(d("div", { class: "legend", style: v }, m));
37
37
  });
38
- const { axis: f, groups: m, total: y } = w(e, { type: s });
39
- (t === "bar" || t === "column") && m.append(...S(e)), (t === "line" || t === "area") && m.append(_(e, { total: y, variant: t })), (t === "doughnut" || t === "pie") && this.shadowRoot?.append(O(e, { variant: t })), this.shadowRoot?.append(r, f, n);
38
+ const { axis: c, groups: l, total: y } = T(e, { type: s });
39
+ (t === "bar" || t === "column") && l.append(...S(e)), (t === "line" || t === "area") && l.append(_(e, { total: y, variant: t })), (t === "doughnut" || t === "pie") && this.shadowRoot?.append($(e, { variant: t })), this.shadowRoot?.append(a, c, i);
40
40
  }
41
41
  handleEvent(e) {
42
42
  e.type === "click" || e.type === "keydown" ? A(e, this) : P(e);
@@ -44,30 +44,33 @@ class $ extends E {
44
44
  }
45
45
  function A(o, e) {
46
46
  if (o instanceof KeyboardEvent && o.key !== "Enter") return;
47
- const t = o.composedPath()[0], s = e.querySelector("table"), [r, n] = t instanceof Element && d(t, "data-event")?.split("-").map(Number) || [];
48
- s?.rows[r]?.cells[n]?.querySelector("a,button")?.click?.();
47
+ const t = o.composedPath()[0], s = e.querySelector("table"), [a, i] = t instanceof Element && p(t, "data-event")?.split("-").map(Number) || [];
48
+ s?.rows[a]?.cells[i]?.querySelector("a,button")?.click?.();
49
49
  }
50
- let u = "";
50
+ let b = "";
51
51
  function P(o) {
52
- if (!a) return;
53
- a?.isConnected || document.body.append(a);
52
+ if (!r) return;
53
+ r?.isConnected || document.body.append(r);
54
54
  const e = o.composedPath()[0], t = e instanceof Element && e.getAttribute("aria-label") || "";
55
- t && (a.style.transform = `translate(${o.pageX}px, ${o.pageY}px)`), t !== u && (t && (a.textContent = t), u = t, a.hidden = !t);
55
+ t && (r.style.transform = `translate(${o.pageX}px, ${o.pageY}px)`), t !== b && (t && (r.textContent = t), b = t, r.hidden = !t);
56
56
  }
57
- const i = (o) => o?.textContent?.trim() || "", x = (o) => Array.from(
57
+ const n = (o) => o?.textContent?.trim() || "", x = (o) => Array.from(
58
58
  o?.rows || [],
59
- (e, t) => Array.from(e.cells, (s, r) => ({
60
- number: r && t && Number.parseFloat(i(s)) || 0,
61
- // First row and column is not a number
62
- event: s.querySelector("a,button") && `${t}-${r}`,
63
- // Reference to proxy events
64
- style: `--color: var(--mtdsc-chart-color-${t}, var(--mtdsc-chart-color-base))`,
65
- value: i(s),
66
- tooltip: d(s, "data-tooltip") || `${i(e.cells[0])}: ${i(s)} (${i(o?.rows[0].cells[r])})`
67
- }))
59
+ (e, t) => Array.from(e.cells, (s, a) => {
60
+ const i = n(e.cells[0]), c = n(o?.rows[0].cells[a]), l = `${i}: ${n(s)}${c ? ` (${c})` : ""}`;
61
+ return {
62
+ number: a && t && Number.parseFloat(n(s)) || 0,
63
+ // First row and column is not a number
64
+ event: s.querySelector("a,button") && `${t}-${a}`,
65
+ // Reference to proxy events
66
+ style: `--color: var(--mtdsc-chart-color-${t}, var(--mtdsc-chart-color-base))`,
67
+ value: n(s),
68
+ tooltip: p(s, "data-tooltip") || l
69
+ };
70
+ })
68
71
  );
69
- b && !window.customElements.get("mtds-chart") && window.customElements.define("mtds-chart", $);
72
+ f && !window.customElements.get("mtds-chart") && window.customElements.define("mtds-chart", O);
70
73
  export {
71
- $ as MTDSChartElement
74
+ O as MTDSChartElement
72
75
  };
73
76
  //# sourceMappingURL=chart-element.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"chart-element.js","sources":["../../designsystem/chart/chart-element.ts"],"sourcesContent":["import styles from \"../styles.module.css\";\nimport { attr, IS_BROWSER, MTDSElement, off, on, tag } from \"../utils\";\nimport css from \"./chart.css?raw\";\nimport { toAxis } from \"./chart-axis\";\nimport { toBars } from \"./chart-bars\";\nimport { toLines } from \"./chart-lines\";\nimport { toPies } from \"./chart-pies\";\n\nexport type ChartData = ReturnType<typeof toData>;\n\nconst EVENTS = \"click,keydown,mousemove,mouseout\";\nconst TOOLTIP_ID = \"mtds-chart-tooltip\";\nconst TOOLTIP = IS_BROWSER\n\t? document.getElementById(TOOLTIP_ID) ||\n\t\ttag(\"div\", { class: styles._tooltip, id: TOOLTIP_ID, hidden: \"\" })\n\t: null;\n\nexport class MTDSChartElement extends MTDSElement {\n\t_observer?: MutationObserver; // Using underscore instead of # for backwards compatibility\n\n\tstatic get observedAttributes() {\n\t\treturn [\"data-variant\"]; // Using ES2015 syntax for backwards compatibility\n\t}\n\tconstructor() {\n\t\tsuper();\n\t\tthis.attachShadow({ mode: \"open\" });\n\t}\n\tconnectedCallback() {\n\t\tthis._observer = new MutationObserver(\n\t\t\tthis.attributeChangedCallback.bind(this),\n\t\t);\n\t\tthis._observer.observe(this, {\n\t\t\tattributeFilter: [\"data-tooltip\"],\n\t\t\tattributes: true,\n\t\t\tcharacterData: true,\n\t\t\tchildList: true,\n\t\t\tsubtree: true,\n\t\t});\n\t\tthis.attributeChangedCallback(); // Initial setup\n\t\ton(this, EVENTS, this);\n\t}\n\tdisconnectedCallback() {\n\t\tif (TOOLTIP) TOOLTIP.hidden = true;\n\t\toff(this, EVENTS, this);\n\t\tthis._observer?.disconnect();\n\t\tthis._observer = undefined;\n\t}\n\tattributeChangedCallback() {\n\t\tArray.from(this.shadowRoot?.children || []).map((el) => el.remove()); // Clear shadowRoot\n\n\t\tconst data = toData(this.querySelector(\"table\"));\n\t\tconst [variant, type] = (attr(this, \"data-variant\") || \"bar\").split(\"-\");\n\t\tconst style = tag(\"style\", {}, css);\n\t\tconst legend = tag(\"div\", { class: \"legends\" });\n\t\tdata.slice(1).forEach(([{ value, style }]) => {\n\t\t\tlegend.appendChild(tag(\"div\", { class: \"legend\", style }, value));\n\t\t});\n\n\t\tconst { axis, groups, total } = toAxis(data, { type });\n\t\tif (variant === \"bar\" || variant === \"column\")\n\t\t\tgroups.append(...toBars(data));\n\t\tif (variant === \"line\" || variant === \"area\")\n\t\t\tgroups.append(toLines(data, { total, variant, type }));\n\t\tif (variant === \"doughnut\" || variant === \"pie\")\n\t\t\tthis.shadowRoot?.append(toPies(data, { variant }));\n\n\t\tthis.shadowRoot?.append(style, axis, legend);\n\t}\n\thandleEvent(e: Event) {\n\t\tif (e.type === \"click\" || e.type === \"keydown\") onClick(e, this);\n\t\telse onMoveTooltip(e as MouseEvent);\n\t}\n}\n\nfunction onClick(event: Event, self: MTDSChartElement) {\n\tif (event instanceof KeyboardEvent && event.key !== \"Enter\") return; // Only handle enter key\n\tconst el = event.composedPath()[0];\n\tconst table = self.querySelector(\"table\");\n\tconst [tr, td] =\n\t\t(el instanceof Element && attr(el, \"data-event\")?.split(\"-\").map(Number)) ||\n\t\t[];\n\n\ttable?.rows[tr]?.cells[td]?.querySelector<HTMLElement>(\"a,button\")?.click?.();\n}\n\nlet TOOLTIP_TEXT = \"\";\nfunction onMoveTooltip(event: MouseEvent) {\n\tif (!TOOLTIP) return;\n\tif (!TOOLTIP?.isConnected) document.body.append(TOOLTIP); // Ensure connected\n\n\tconst el = event.composedPath()[0];\n\tconst tip = (el instanceof Element && el.getAttribute(\"aria-label\")) || \"\";\n\n\tif (tip)\n\t\tTOOLTIP.style.transform = `translate(${event.pageX}px, ${event.pageY}px)`;\n\tif (tip !== TOOLTIP_TEXT) {\n\t\tif (tip) TOOLTIP.textContent = tip;\n\t\tTOOLTIP_TEXT = tip;\n\t\tTOOLTIP.hidden = !tip;\n\t}\n}\n\nconst text = (el?: Element | null) => el?.textContent?.trim() || \"\"; // Helper to get trimmed text\nconst toData = (table?: HTMLTableElement | null) =>\n\tArray.from(table?.rows || [], (row, rowIndex) =>\n\t\tArray.from(row.cells, (cell, cellIndex) => ({\n\t\t\tnumber: (cellIndex && rowIndex && Number.parseFloat(text(cell))) || 0, // First row and column is not a number\n\t\t\tevent: cell.querySelector(\"a,button\") && `${rowIndex}-${cellIndex}`, // Reference to proxy events\n\t\t\tstyle: `--color: var(--mtdsc-chart-color-${rowIndex}, var(--mtdsc-chart-color-base))`,\n\t\t\tvalue: text(cell),\n\t\t\ttooltip:\n\t\t\t\tattr(cell, \"data-tooltip\") ||\n\t\t\t\t`${text(row.cells[0])}: ${text(cell)} (${text(table?.rows[0].cells[cellIndex])})`,\n\t\t})),\n\t);\n\nif (IS_BROWSER && !window.customElements.get(\"mtds-chart\"))\n\twindow.customElements.define(\"mtds-chart\", MTDSChartElement);\n"],"names":["EVENTS","TOOLTIP_ID","TOOLTIP","IS_BROWSER","tag","styles","MTDSChartElement","MTDSElement","on","off","el","data","toData","variant","type","attr","style","css","legend","value","axis","groups","total","toAxis","toBars","toLines","toPies","onClick","event","self","table","tr","td","TOOLTIP_TEXT","onMoveTooltip","tip","text","row","rowIndex","cell","cellIndex"],"mappings":";;;;;;;AAUA,MAAMA,IAAS,oCACTC,IAAa,sBACbC,IAAUC,IACb,SAAS,eAAeF,CAAU,KACnCG,EAAI,OAAO,EAAE,OAAOC,EAAO,UAAU,IAAIJ,GAAY,QAAQ,GAAA,CAAI,IAChE;AAEI,MAAMK,UAAyBC,EAAY;AAAA,EACjD;AAAA;AAAA,EAEA,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AI,aAAa,UAAU,IAC3DE,IAAS,CAACkB,MACf,MAAM;AAAA,EAAKA,GAAO,QAAQ,CAAA;AAAA,EAAI,CAACO,GAAKC,MACnC,MAAM,KAAKD,EAAI,OAAO,CAACE,GAAMC,OAAe;AAAA,IAC3C,QAASA,KAAaF,KAAY,OAAO,WAAWF,EAAKG,CAAI,CAAC,KAAM;AAAA;AAAA,IACpE,OAAOA,EAAK,cAAc,UAAU,KAAK,GAAGD,CAAQ,IAAIE,CAAS;AAAA;AAAA,IACjE,OAAO,oCAAoCF,CAAQ;AAAA,IACnD,OAAOF,EAAKG,CAAI;AAAA,IAChB,SACCxB,EAAKwB,GAAM,cAAc,KACzB,GAAGH,EAAKC,EAAI,MAAM,CAAC,CAAC,CAAC,KAAKD,EAAKG,CAAI,CAAC,KAAKH,EAAKN,GAAO,KAAK,CAAC,EAAE,MAAMU,CAAS,CAAC,CAAC;AAAA,EAAA,EAC9E;AACH;AAEGrC,KAAc,CAAC,OAAO,eAAe,IAAI,YAAY,KACxD,OAAO,eAAe,OAAO,cAAcG,CAAgB;"}
1
+ {"version":3,"file":"chart-element.js","sources":["../../designsystem/chart/chart-element.ts"],"sourcesContent":["import styles from \"../styles.module.css\";\nimport { attr, IS_BROWSER, MTDSElement, off, on, tag } from \"../utils\";\nimport css from \"./chart.css?raw\";\nimport { toAxis } from \"./chart-axis\";\nimport { toBars } from \"./chart-bars\";\nimport { toLines } from \"./chart-lines\";\nimport { toPies } from \"./chart-pies\";\n\nexport type ChartData = ReturnType<typeof toData>;\n\nconst EVENTS = \"click,keydown,mousemove,mouseout\";\nconst TOOLTIP_ID = \"mtds-chart-tooltip\";\nconst TOOLTIP = IS_BROWSER\n\t? document.getElementById(TOOLTIP_ID) ||\n\t\ttag(\"div\", { class: styles._tooltip, id: TOOLTIP_ID, hidden: \"\" })\n\t: null;\n\nexport class MTDSChartElement extends MTDSElement {\n\t_observer?: MutationObserver; // Using underscore instead of # for backwards compatibility\n\n\tstatic get observedAttributes() {\n\t\treturn [\"data-variant\"]; // Using ES2015 syntax for backwards compatibility\n\t}\n\tconstructor() {\n\t\tsuper();\n\t\tthis.attachShadow({ mode: \"open\" });\n\t}\n\tconnectedCallback() {\n\t\tthis._observer = new MutationObserver(\n\t\t\tthis.attributeChangedCallback.bind(this),\n\t\t);\n\t\tthis._observer.observe(this, {\n\t\t\tattributeFilter: [\"data-tooltip\"],\n\t\t\tattributes: true,\n\t\t\tcharacterData: true,\n\t\t\tchildList: true,\n\t\t\tsubtree: true,\n\t\t});\n\t\tthis.attributeChangedCallback(); // Initial setup\n\t\ton(this, EVENTS, this);\n\t}\n\tdisconnectedCallback() {\n\t\tif (TOOLTIP) TOOLTIP.hidden = true;\n\t\toff(this, EVENTS, this);\n\t\tthis._observer?.disconnect();\n\t\tthis._observer = undefined;\n\t}\n\tattributeChangedCallback() {\n\t\tArray.from(this.shadowRoot?.children || []).map((el) => el.remove()); // Clear shadowRoot\n\n\t\tconst data = toData(this.querySelector(\"table\"));\n\t\tconst [variant, type] = (attr(this, \"data-variant\") || \"bar\").split(\"-\");\n\t\tconst style = tag(\"style\", {}, css);\n\t\tconst legend = tag(\"div\", { class: \"legends\" });\n\t\tdata.slice(1).forEach(([{ value, style }]) => {\n\t\t\tlegend.appendChild(tag(\"div\", { class: \"legend\", style }, value));\n\t\t});\n\n\t\tconst { axis, groups, total } = toAxis(data, { type });\n\t\tif (variant === \"bar\" || variant === \"column\")\n\t\t\tgroups.append(...toBars(data));\n\t\tif (variant === \"line\" || variant === \"area\")\n\t\t\tgroups.append(toLines(data, { total, variant, type }));\n\t\tif (variant === \"doughnut\" || variant === \"pie\")\n\t\t\tthis.shadowRoot?.append(toPies(data, { variant }));\n\n\t\tthis.shadowRoot?.append(style, axis, legend);\n\t}\n\thandleEvent(e: Event) {\n\t\tif (e.type === \"click\" || e.type === \"keydown\") onClick(e, this);\n\t\telse onMoveTooltip(e as MouseEvent);\n\t}\n}\n\nfunction onClick(event: Event, self: MTDSChartElement) {\n\tif (event instanceof KeyboardEvent && event.key !== \"Enter\") return; // Only handle enter key\n\tconst el = event.composedPath()[0];\n\tconst table = self.querySelector(\"table\");\n\tconst [tr, td] =\n\t\t(el instanceof Element && attr(el, \"data-event\")?.split(\"-\").map(Number)) ||\n\t\t[];\n\n\ttable?.rows[tr]?.cells[td]?.querySelector<HTMLElement>(\"a,button\")?.click?.();\n}\n\nlet TOOLTIP_TEXT = \"\";\nfunction onMoveTooltip(event: MouseEvent) {\n\tif (!TOOLTIP) return;\n\tif (!TOOLTIP?.isConnected) document.body.append(TOOLTIP); // Ensure connected\n\n\tconst el = event.composedPath()[0];\n\tconst tip = (el instanceof Element && el.getAttribute(\"aria-label\")) || \"\";\n\n\tif (tip)\n\t\tTOOLTIP.style.transform = `translate(${event.pageX}px, ${event.pageY}px)`;\n\tif (tip !== TOOLTIP_TEXT) {\n\t\tif (tip) TOOLTIP.textContent = tip;\n\t\tTOOLTIP_TEXT = tip;\n\t\tTOOLTIP.hidden = !tip;\n\t}\n}\n\nconst text = (el?: Element | null) => el?.textContent?.trim() || \"\"; // Helper to get trimmed text\nconst toData = (table?: HTMLTableElement | null) =>\n\tArray.from(table?.rows || [], (row, rowIndex) =>\n\t\tArray.from(row.cells, (cell, cellIndex) => {\n\t\t\tconst rowHeading = text(row.cells[0]);\n\t\t\tconst colHeading = text(table?.rows[0].cells[cellIndex]);\n\t\t\tconst tooltip = `${rowHeading}: ${text(cell)}${colHeading ? ` (${colHeading})` : \"\"}`;\n\n\t\t\treturn {\n\t\t\t\tnumber: (cellIndex && rowIndex && Number.parseFloat(text(cell))) || 0, // First row and column is not a number\n\t\t\t\tevent: cell.querySelector(\"a,button\") && `${rowIndex}-${cellIndex}`, // Reference to proxy events\n\t\t\t\tstyle: `--color: var(--mtdsc-chart-color-${rowIndex}, var(--mtdsc-chart-color-base))`,\n\t\t\t\tvalue: text(cell),\n\t\t\t\ttooltip: attr(cell, \"data-tooltip\") || tooltip,\n\t\t\t};\n\t\t}),\n\t);\n\nif (IS_BROWSER && !window.customElements.get(\"mtds-chart\"))\n\twindow.customElements.define(\"mtds-chart\", MTDSChartElement);\n"],"names":["EVENTS","TOOLTIP_ID","TOOLTIP","IS_BROWSER","tag","styles","MTDSChartElement","MTDSElement","on","off","el","data","toData","variant","type","attr","style","css","legend","value","axis","groups","total","toAxis","toBars","toLines","toPies","onClick","event","self","table","tr","td","TOOLTIP_TEXT","onMoveTooltip","tip","text","row","rowIndex","cell","cellIndex","rowHeading","colHeading","tooltip"],"mappings":";;;;;;;AAUA,MAAMA,IAAS,oCACTC,IAAa,sBACbC,IAAUC,IACb,SAAS,eAAeF,CAAU,KACnCG,EAAI,OAAO,EAAE,OAAOC,EAAO,UAAU,IAAIJ,GAAY,QAAQ,GAAA,CAAI,IAChE;AAEI,MAAMK,UAAyBC,EAAY;AAAA,EACjD;AAAA;AAAA,EAEA,WAAW,qBAAqB;AAC/B,WAAO,CAAC,cAAc;AAAA,EACvB;AAAA,EACA,cAAc;AACb,UAAA,GACA,KAAK,aAAa,EAAE,MAAM,OAAA,CAAQ;AAAA,EACnC;AAAA,EACA,oBAAoB;AACnB,SAAK,YAAY,IAAI;AAAA,MACpB,KAAK,yBAAyB,KAAK,IAAI;AAAA,IAAA,GAExC,KAAK,UAAU,QAAQ,MAAM;AAAA,MAC5B,iBAAiB,CAAC,cAAc;AAAA,MAChC,YAAY;AAAA,MACZ,eAAe;AAAA,MACf,WAAW;AAAA,MACX,SAAS;AAAA,IAAA,CACT,GACD,KAAK,yBAAA,GACLC,EAAG,MAAMR,GAAQ,IAAI;AAAA,EACtB;AAAA,EACA,uBAAuB;AACtB,IAAIE,QAAiB,SAAS,KAC9BO,EAAI,MAAMT,GAAQ,IAAI,GACtB,KAAK,WAAW,WAAA,GAChB,KAAK,YAAY;AAAA,EAClB;AAAA,EACA,2BAA2B;AAC1B,UAAM,KAAK,KAAK,YAAY,YAAY,CAAA,CAAE,EAAE,IAAI,CAACU,MAAOA,EAAG,OAAA,CAAQ;AAEnE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,CAAC,OAAO,eAAe,IAAI,YAAY,KACxD,OAAO,eAAe,OAAO,cAAcG,CAAgB;"}
@@ -1,17 +1,18 @@
1
1
  import { attr as n } from "../utils.js";
2
- function A(h, { variant: f }) {
2
+ function E(h, { variant: f }) {
3
3
  const s = document.createElementNS("http://www.w3.org/2000/svg", "svg");
4
4
  n(s, "class", "pie"), n(s, "viewBox", "0 0 100 100");
5
- let c = 0;
6
- const t = 50, e = f === "doughnut" ? 25 : 0, l = h.slice(1).reduce((a, [, r]) => a + r.number, 0);
7
- return h.slice(1).forEach(([, { tooltip: a, number: r, event: v, style: x }]) => {
8
- const o = document.createElementNS("http://www.w3.org/2000/svg", "path"), d = c / l;
9
- c += r;
10
- const p = c / l, u = p - d > 0.5 ? 1 : 0, w = 2 * Math.PI * (d - 0.25), g = 2 * Math.PI * (p - 0.25), i = Math.cos(w), $ = Math.sin(w), m = Math.cos(g), M = Math.sin(g), b = `M ${t + e * i} ${t + e * $} L ${t + t * i} ${t + t * $} A ${t} ${t} 0 ${u} 1 ${t + t * m} ${t + t * M} L ${t + e * m} ${t + e * M} A ${e} ${e} 0 ${u} 0 ${t + e * i} ${t + e * $}`;
11
- n(o, "aria-label", a), n(o, "data-event", v), n(o, "style", x), n(o, "d", b), n(o, "role", "img"), n(o, "tabindex", "0"), s.appendChild(o);
5
+ let a = 0;
6
+ const t = 50, e = f === "doughnut" ? 25 : 0, l = h.slice(1).reduce((r, [, c]) => r + c.number, 0);
7
+ return h.slice(1).forEach(([, { tooltip: r, number: c, event: v, style: x }]) => {
8
+ if (!c) return;
9
+ const o = document.createElementNS("http://www.w3.org/2000/svg", "path"), d = a / l;
10
+ a += c;
11
+ const p = Math.min(a / l, 0.99999), u = p - d > 0.5 ? 1 : 0, w = 2 * Math.PI * (d - 0.25), g = 2 * Math.PI * (p - 0.25), i = Math.cos(w), $ = Math.sin(w), m = Math.cos(g), M = Math.sin(g), y = `M ${t + e * i} ${t + e * $} L ${t + t * i} ${t + t * $} A ${t} ${t} 0 ${u} 1 ${t + t * m} ${t + t * M} L ${t + e * m} ${t + e * M} A ${e} ${e} 0 ${u} 0 ${t + e * i} ${t + e * $}`;
12
+ n(o, "aria-label", r), n(o, "data-event", v), n(o, "style", x), n(o, "d", y), n(o, "role", "img"), n(o, "tabindex", "0"), s.appendChild(o);
12
13
  }), s;
13
14
  }
14
15
  export {
15
- A as toPies
16
+ E as toPies
16
17
  };
17
18
  //# sourceMappingURL=chart-pies.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"chart-pies.js","sources":["../../designsystem/chart/chart-pies.ts"],"sourcesContent":["import { attr } from \"../utils\";\nimport type { ChartData } from \"./chart-element\";\n\nexport function toPies(data: ChartData, { variant }: { variant: string }) {\n\tconst pie = document.createElementNS(\"http://www.w3.org/2000/svg\", \"svg\");\n\tattr(pie, \"class\", \"pie\");\n\tattr(pie, \"viewBox\", \"0 0 100 100\");\n\n\tlet offset = 0;\n\tconst radius = 50;\n\tconst inner = variant === \"doughnut\" ? 25 : 0;\n\tconst total = data.slice(1).reduce((tot, [, td]) => tot + td.number, 0);\n\n\tdata.slice(1).forEach(([, { tooltip, number, event, style }]) => {\n\t\tconst path = document.createElementNS(\"http://www.w3.org/2000/svg\", \"path\");\n\t\tconst start = offset / total;\n\t\toffset += number;\n\t\tconst end = offset / total;\n\t\tconst largeArc = end - start > 0.5 ? 1 : 0;\n\t\tconst a0 = 2 * Math.PI * (start - 0.25);\n\t\tconst a1 = 2 * Math.PI * (end - 0.25);\n\t\tconst x0 = Math.cos(a0);\n\t\tconst y0 = Math.sin(a0);\n\t\tconst x1 = Math.cos(a1);\n\t\tconst y1 = Math.sin(a1);\n\t\tconst d = `M ${radius + inner * x0} ${radius + inner * y0} L ${radius + radius * x0} ${radius + radius * y0} A ${radius} ${radius} 0 ${largeArc} 1 ${radius + radius * x1} ${radius + radius * y1} L ${radius + inner * x1} ${radius + inner * y1} A ${inner} ${inner} 0 ${largeArc} 0 ${radius + inner * x0} ${radius + inner * y0}`;\n\n\t\tattr(path, \"aria-label\", tooltip);\n\t\tattr(path, \"data-event\", event);\n\t\tattr(path, \"style\", style);\n\t\tattr(path, \"d\", d);\n\t\tattr(path, \"role\", \"img\");\n\t\tattr(path, \"tabindex\", \"0\");\n\t\tpie.appendChild(path);\n\t});\n\treturn pie;\n}\n"],"names":["toPies","data","variant","pie","attr","offset","radius","inner","total","tot","td","tooltip","number","event","style","path","start","end","largeArc","a0","a1","x0","y0","x1","y1","d"],"mappings":";AAGO,SAASA,EAAOC,GAAiB,EAAE,SAAAC,KAAgC;AACzE,QAAMC,IAAM,SAAS,gBAAgB,8BAA8B,KAAK;AACxE,EAAAC,EAAKD,GAAK,SAAS,KAAK,GACxBC,EAAKD,GAAK,WAAW,aAAa;AAElC,MAAIE,IAAS;AACb,QAAMC,IAAS,IACTC,IAAQL,MAAY,aAAa,KAAK,GACtCM,IAAQP,EAAK,MAAM,CAAC,EAAE,OAAO,CAACQ,GAAK,CAAA,EAAGC,CAAE,MAAMD,IAAMC,EAAG,QAAQ,CAAC;AAEtE,SAAAT,EAAK,MAAM,CAAC,EAAE,QAAQ,CAAC,GAAG,EAAE,SAAAU,GAAS,QAAAC,GAAQ,OAAAC,GAAO,OAAAC,EAAA,CAAO,MAAM;AAChE,UAAMC,IAAO,SAAS,gBAAgB,8BAA8B,MAAM,GACpEC,IAAQX,IAASG;AACvB,IAAAH,KAAUO;AACV,UAAMK,IAAMZ,IAASG,GACfU,IAAWD,IAAMD,IAAQ,MAAM,IAAI,GACnCG,IAAK,IAAI,KAAK,MAAMH,IAAQ,OAC5BI,IAAK,IAAI,KAAK,MAAMH,IAAM,OAC1BI,IAAK,KAAK,IAAIF,CAAE,GAChBG,IAAK,KAAK,IAAIH,CAAE,GAChBI,IAAK,KAAK,IAAIH,CAAE,GAChBI,IAAK,KAAK,IAAIJ,CAAE,GAChBK,IAAI,KAAKnB,IAASC,IAAQc,CAAE,IAAIf,IAASC,IAAQe,CAAE,MAAMhB,IAASA,IAASe,CAAE,IAAIf,IAASA,IAASgB,CAAE,MAAMhB,CAAM,IAAIA,CAAM,MAAMY,CAAQ,MAAMZ,IAASA,IAASiB,CAAE,IAAIjB,IAASA,IAASkB,CAAE,MAAMlB,IAASC,IAAQgB,CAAE,IAAIjB,IAASC,IAAQiB,CAAE,MAAMjB,CAAK,IAAIA,CAAK,MAAMW,CAAQ,MAAMZ,IAASC,IAAQc,CAAE,IAAIf,IAASC,IAAQe,CAAE;AAEnU,IAAAlB,EAAKW,GAAM,cAAcJ,CAAO,GAChCP,EAAKW,GAAM,cAAcF,CAAK,GAC9BT,EAAKW,GAAM,SAASD,CAAK,GACzBV,EAAKW,GAAM,KAAKU,CAAC,GACjBrB,EAAKW,GAAM,QAAQ,KAAK,GACxBX,EAAKW,GAAM,YAAY,GAAG,GAC1BZ,EAAI,YAAYY,CAAI;AAAA,EACrB,CAAC,GACMZ;AACR;"}
1
+ {"version":3,"file":"chart-pies.js","sources":["../../designsystem/chart/chart-pies.ts"],"sourcesContent":["import { attr } from \"../utils\";\nimport type { ChartData } from \"./chart-element\";\n\nexport function toPies(data: ChartData, { variant }: { variant: string }) {\n\tconst pie = document.createElementNS(\"http://www.w3.org/2000/svg\", \"svg\");\n\tattr(pie, \"class\", \"pie\");\n\tattr(pie, \"viewBox\", \"0 0 100 100\");\n\n\tlet offset = 0;\n\tconst radius = 50;\n\tconst inner = variant === \"doughnut\" ? 25 : 0;\n\tconst total = data.slice(1).reduce((tot, [, td]) => tot + td.number, 0);\n\n\tdata.slice(1).forEach(([, { tooltip, number, event, style }]) => {\n\t\tif (!number) return; // Skip empty\n\t\tconst path = document.createElementNS(\"http://www.w3.org/2000/svg\", \"path\");\n\t\tconst start = offset / total;\n\t\toffset += number;\n\t\tconst end = Math.min(offset / total, 0.99999); // Ensure full circle works\n\t\tconst largeArc = end - start > 0.5 ? 1 : 0;\n\t\tconst a0 = 2 * Math.PI * (start - 0.25);\n\t\tconst a1 = 2 * Math.PI * (end - 0.25);\n\t\tconst x0 = Math.cos(a0);\n\t\tconst y0 = Math.sin(a0);\n\t\tconst x1 = Math.cos(a1);\n\t\tconst y1 = Math.sin(a1);\n\t\tconst d = `M ${radius + inner * x0} ${radius + inner * y0} L ${radius + radius * x0} ${radius + radius * y0} A ${radius} ${radius} 0 ${largeArc} 1 ${radius + radius * x1} ${radius + radius * y1} L ${radius + inner * x1} ${radius + inner * y1} A ${inner} ${inner} 0 ${largeArc} 0 ${radius + inner * x0} ${radius + inner * y0}`;\n\n\t\tattr(path, \"aria-label\", tooltip);\n\t\tattr(path, \"data-event\", event);\n\t\tattr(path, \"style\", style);\n\t\tattr(path, \"d\", d);\n\t\tattr(path, \"role\", \"img\");\n\t\tattr(path, \"tabindex\", \"0\");\n\t\tpie.appendChild(path);\n\t});\n\treturn pie;\n}\n"],"names":["toPies","data","variant","pie","attr","offset","radius","inner","total","tot","td","tooltip","number","event","style","path","start","end","largeArc","a0","a1","x0","y0","x1","y1","d"],"mappings":";AAGO,SAASA,EAAOC,GAAiB,EAAE,SAAAC,KAAgC;AACzE,QAAMC,IAAM,SAAS,gBAAgB,8BAA8B,KAAK;AACxE,EAAAC,EAAKD,GAAK,SAAS,KAAK,GACxBC,EAAKD,GAAK,WAAW,aAAa;AAElC,MAAIE,IAAS;AACb,QAAMC,IAAS,IACTC,IAAQL,MAAY,aAAa,KAAK,GACtCM,IAAQP,EAAK,MAAM,CAAC,EAAE,OAAO,CAACQ,GAAK,CAAA,EAAGC,CAAE,MAAMD,IAAMC,EAAG,QAAQ,CAAC;AAEtE,SAAAT,EAAK,MAAM,CAAC,EAAE,QAAQ,CAAC,GAAG,EAAE,SAAAU,GAAS,QAAAC,GAAQ,OAAAC,GAAO,OAAAC,EAAA,CAAO,MAAM;AAChE,QAAI,CAACF,EAAQ;AACb,UAAMG,IAAO,SAAS,gBAAgB,8BAA8B,MAAM,GACpEC,IAAQX,IAASG;AACvB,IAAAH,KAAUO;AACV,UAAMK,IAAM,KAAK,IAAIZ,IAASG,GAAO,OAAO,GACtCU,IAAWD,IAAMD,IAAQ,MAAM,IAAI,GACnCG,IAAK,IAAI,KAAK,MAAMH,IAAQ,OAC5BI,IAAK,IAAI,KAAK,MAAMH,IAAM,OAC1BI,IAAK,KAAK,IAAIF,CAAE,GAChBG,IAAK,KAAK,IAAIH,CAAE,GAChBI,IAAK,KAAK,IAAIH,CAAE,GAChBI,IAAK,KAAK,IAAIJ,CAAE,GAChBK,IAAI,KAAKnB,IAASC,IAAQc,CAAE,IAAIf,IAASC,IAAQe,CAAE,MAAMhB,IAASA,IAASe,CAAE,IAAIf,IAASA,IAASgB,CAAE,MAAMhB,CAAM,IAAIA,CAAM,MAAMY,CAAQ,MAAMZ,IAASA,IAASiB,CAAE,IAAIjB,IAASA,IAASkB,CAAE,MAAMlB,IAASC,IAAQgB,CAAE,IAAIjB,IAASC,IAAQiB,CAAE,MAAMjB,CAAK,IAAIA,CAAK,MAAMW,CAAQ,MAAMZ,IAASC,IAAQc,CAAE,IAAIf,IAASC,IAAQe,CAAE;AAEnU,IAAAlB,EAAKW,GAAM,cAAcJ,CAAO,GAChCP,EAAKW,GAAM,cAAcF,CAAK,GAC9BT,EAAKW,GAAM,SAASD,CAAK,GACzBV,EAAKW,GAAM,KAAKU,CAAC,GACjBrB,EAAKW,GAAM,QAAQ,KAAK,GACxBX,EAAKW,GAAM,YAAY,GAAG,GAC1BZ,EAAI,YAAYY,CAAI;AAAA,EACrB,CAAC,GACMZ;AACR;"}
@@ -1,11 +1,16 @@
1
- import { jsx as r } from "react/jsx-runtime";
2
- import { forwardRef as h } from "react";
1
+ import { jsx as r, jsxs as l } from "react/jsx-runtime";
2
+ import { forwardRef as p } from "react";
3
3
  import { toCustomElementProps as d } from "../utils.js";
4
4
  import "./chart-element.js";
5
- const C = h(function({ data: t, children: o, ...m }, e) {
6
- return /* @__PURE__ */ r("mtds-chart", { ref: e, ...d(m), children: t ? /* @__PURE__ */ r("table", { children: t.map((i, n) => /* @__PURE__ */ r("tr", { children: i.map((p, c) => /* @__PURE__ */ r("td", { children: p }, `${c + 1}`)) }, `${n + 1}`)) }) : o });
5
+ const x = p(function({ data: h, children: c, ...m }, n) {
6
+ return /* @__PURE__ */ r("mtds-chart", { ref: n, ...d(m), children: h ? /* @__PURE__ */ l("table", { children: [
7
+ /* @__PURE__ */ r("thead", { children: h.slice(0, 1).map((i, o) => /* @__PURE__ */ r("tr", { children: i.map((t, e) => /* @__PURE__ */ r("th", { children: t }, `${e}-${t}`)) }, `${o + 1}`)) }),
8
+ /* @__PURE__ */ r("tbody", { children: h.slice(1).map((i, o) => /* @__PURE__ */ r("tr", { children: i.map(
9
+ (t, e) => e ? /* @__PURE__ */ r("th", { children: t }, "th") : /* @__PURE__ */ r("td", { children: t }, `${e}-${t}`)
10
+ ) }, `${o + 1}`)) })
11
+ ] }) : c });
7
12
  });
8
13
  export {
9
- C as Chart
14
+ x as Chart
10
15
  };
11
16
  //# sourceMappingURL=chart.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"chart.js","sources":["../../designsystem/chart/chart.tsx"],"sourcesContent":["import type * as ReactTypes from \"react\";\nimport { forwardRef } from \"react\";\nimport { toCustomElementProps } from \"../utils\";\nimport \"./chart-element\";\n\ndeclare global {\n\tnamespace React.JSX {\n\t\tinterface IntrinsicElements {\n\t\t\t\"mtds-chart\": ReactTypes.JSX.IntrinsicElements[\"div\"] & {\n\t\t\t\tclass?: string;\n\t\t\t};\n\t\t}\n\t}\n}\n\nexport type ChartProps = React.ComponentPropsWithoutRef<\"div\"> & {\n\tdata?: (number | string)[][];\n\t\"data-variant\"?:\n\t\t| \"area\"\n\t\t| \"bar\"\n\t\t| \"bar-stacked\"\n\t\t| \"column\"\n\t\t| \"column-stacked\"\n\t\t| \"doughnut\"\n\t\t| \"line\"\n\t\t| \"pie\";\n};\n\nexport const Chart = forwardRef<HTMLDivElement, ChartProps>(function Chart(\n\t{ data, children, ...rest },\n\tref,\n) {\n\treturn (\n\t\t<mtds-chart ref={ref} {...toCustomElementProps(rest)}>\n\t\t\t{data ? (\n\t\t\t\t<table>\n\t\t\t\t\t{data.map((row, rowIndex) => (\n\t\t\t\t\t\t<tr key={`${rowIndex + 1}`}>\n\t\t\t\t\t\t\t{row.map((cell, cellIndex) => (\n\t\t\t\t\t\t\t\t<td key={`${cellIndex + 1}`}>{cell}</td>\n\t\t\t\t\t\t\t))}\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t))}\n\t\t\t\t</table>\n\t\t\t) : (\n\t\t\t\tchildren\n\t\t\t)}\n\t\t</mtds-chart>\n\t);\n});\n"],"names":["Chart","forwardRef","data","children","rest","ref","toCustomElementProps","jsx","row","rowIndex","cell","cellIndex"],"mappings":";;;;AA4BO,MAAMA,IAAQC,EAAuC,SAC3D,EAAE,MAAAC,GAAM,UAAAC,GAAU,GAAGC,EAAA,GACrBC,GACC;AACD,2BACE,cAAA,EAAW,KAAAA,GAAW,GAAGC,EAAqBF,CAAI,GACjD,UAAAF,IACA,gBAAAK,EAAC,SAAA,EACC,YAAK,IAAI,CAACC,GAAKC,MACf,gBAAAF,EAAC,QACC,UAAAC,EAAI,IAAI,CAACE,GAAMC,MACf,gBAAAJ,EAAC,MAAA,EAA6B,UAAAG,KAArB,GAAGC,IAAY,CAAC,EAAU,CACnC,KAHO,GAAGF,IAAW,CAAC,EAIxB,CACA,EAAA,CACF,IAEAN,GAEF;AAEF,CAAC;"}
1
+ {"version":3,"file":"chart.js","sources":["../../designsystem/chart/chart.tsx"],"sourcesContent":["import type * as ReactTypes from \"react\";\nimport { forwardRef } from \"react\";\nimport { toCustomElementProps } from \"../utils\";\nimport \"./chart-element\";\n\ndeclare global {\n\tnamespace React.JSX {\n\t\tinterface IntrinsicElements {\n\t\t\t\"mtds-chart\": ReactTypes.JSX.IntrinsicElements[\"div\"] & {\n\t\t\t\tclass?: string;\n\t\t\t};\n\t\t}\n\t}\n}\n\nexport type ChartProps = React.ComponentPropsWithoutRef<\"div\"> & {\n\tdata?: (number | string)[][];\n\t\"data-variant\"?:\n\t\t| \"area\"\n\t\t| \"bar\"\n\t\t| \"bar-stacked\"\n\t\t| \"column\"\n\t\t| \"column-stacked\"\n\t\t| \"doughnut\"\n\t\t| \"line\"\n\t\t| \"pie\";\n};\n\nexport const Chart = forwardRef<HTMLDivElement, ChartProps>(function Chart(\n\t{ data, children, ...rest },\n\tref,\n) {\n\treturn (\n\t\t<mtds-chart ref={ref} {...toCustomElementProps(rest)}>\n\t\t\t{data ? (\n\t\t\t\t<table>\n\t\t\t\t\t<thead>\n\t\t\t\t\t\t{data.slice(0, 1).map((tr, row) => (\n\t\t\t\t\t\t\t<tr key={`${row + 1}`}>\n\t\t\t\t\t\t\t\t{tr.map((td, i) => (\n\t\t\t\t\t\t\t\t\t<th key={`${i}-${td}`}>{td}</th>\n\t\t\t\t\t\t\t\t))}\n\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t))}\n\t\t\t\t\t</thead>\n\t\t\t\t\t<tbody>\n\t\t\t\t\t\t{data.slice(1).map((tr, row) => (\n\t\t\t\t\t\t\t<tr key={`${row + 1}`}>\n\t\t\t\t\t\t\t\t{tr.map((td, i) =>\n\t\t\t\t\t\t\t\t\ti ? <th key=\"th\">{td}</th> : <td key={`${i}-${td}`}>{td}</td>,\n\t\t\t\t\t\t\t\t)}\n\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t))}\n\t\t\t\t\t</tbody>\n\t\t\t\t</table>\n\t\t\t) : (\n\t\t\t\tchildren\n\t\t\t)}\n\t\t</mtds-chart>\n\t);\n});\n"],"names":["Chart","forwardRef","data","children","rest","ref","jsx","toCustomElementProps","jsxs","tr","row","td","i"],"mappings":";;;;AA4BO,MAAMA,IAAQC,EAAuC,SAC3D,EAAE,MAAAC,GAAM,UAAAC,GAAU,GAAGC,EAAA,GACrBC,GACC;AACD,SACC,gBAAAC,EAAC,gBAAW,KAAAD,GAAW,GAAGE,EAAqBH,CAAI,GACjD,UAAAF,IACA,gBAAAM,EAAC,SAAA,EACA,UAAA;AAAA,IAAA,gBAAAF,EAAC,SAAA,EACC,UAAAJ,EAAK,MAAM,GAAG,CAAC,EAAE,IAAI,CAACO,GAAIC,MAC1B,gBAAAJ,EAAC,MAAA,EACC,UAAAG,EAAG,IAAI,CAACE,GAAIC,MACZ,gBAAAN,EAAC,MAAA,EAAuB,UAAAK,KAAf,GAAGC,CAAC,IAAID,CAAE,EAAQ,CAC3B,EAAA,GAHO,GAAGD,IAAM,CAAC,EAInB,CACA,GACF;AAAA,IACA,gBAAAJ,EAAC,SAAA,EACC,UAAAJ,EAAK,MAAM,CAAC,EAAE,IAAI,CAACO,GAAIC,MACvB,gBAAAJ,EAAC,MAAA,EACC,UAAAG,EAAG;AAAA,MAAI,CAACE,GAAIC,MACZA,IAAI,gBAAAN,EAAC,QAAa,UAAAK,EAAA,GAAN,IAAS,IAAQ,gBAAAL,EAAC,QAAuB,UAAAK,EAAA,GAAf,GAAGC,CAAC,IAAID,CAAE,EAAQ;AAAA,IAAA,KAFjD,GAAGD,IAAM,CAAC,EAInB,CACA,EAAA,CACF;AAAA,EAAA,EAAA,CACD,IAEAP,GAEF;AAEF,CAAC;"}
@@ -1,24 +1,25 @@
1
- import d from "../styles.module.css.js";
2
- import { IS_BROWSER as m, onLoaded as r, on as u, QUICK_EVENT as f, createOptimizedMutationObserver as g, attr as e } from "../utils.js";
3
- const p = d.dialog.split(" ")[0], h = m ? document.getElementsByClassName(
4
- p
5
- ) : [], b = () => {
6
- for (const t of h)
7
- t.isConnected && t.showModal && t.close && (t.matches('[open]:not([data-modal="false"]):not(:modal)') ? (e(t, "open", null), t.showModal()) : t.matches(":modal:not([open])") && (e(t, "open", ""), t.close()));
8
- }, C = ({
9
- clientX: t,
10
- clientY: n,
11
- target: o
1
+ import m from "../styles.module.css.js";
2
+ import { IS_BROWSER as f, onLoaded as u, on as g, QUICK_EVENT as p, createOptimizedMutationObserver as h, attr as e } from "../utils.js";
3
+ const b = m.dialog.split(" ")[0], c = f ? document.getElementsByClassName(
4
+ b
5
+ ) : [], C = () => {
6
+ for (const o of c)
7
+ o.isConnected && o.showModal && o.close && (o.matches('[open]:not([data-modal="false"]):not(:modal)') ? (e(o, "open", null), o.showModal()) : o.matches(":modal:not([open])") && (e(o, "open", ""), o.close()));
8
+ }, I = ({
9
+ clientX: o,
10
+ clientY: s,
11
+ target: n
12
12
  }) => {
13
- if (o instanceof HTMLDialogElement && e(o, "data-closedby") === "any") {
14
- const { top: l, right: c, bottom: i, left: a } = o.getBoundingClientRect();
15
- if (!(l <= n && n <= i && a <= t && t <= c)) return o.close();
16
- }
17
- const s = o?.closest?.("dialog");
18
- s && o?.closest?.('[data-command="close"]') && s.close();
13
+ for (const t of c)
14
+ if (t.open && e(t, "data-closedby") === "any") {
15
+ const { top: i, right: a, bottom: d, left: r } = t.getBoundingClientRect();
16
+ if (!(i <= s && s <= d && r <= o && o <= a)) return t.close();
17
+ }
18
+ const l = n?.closest?.("dialog");
19
+ l && n?.closest?.('[data-command="close"]') && l.close();
19
20
  };
20
- r(() => {
21
- u(document, "click", C, f), g(b).observe(
21
+ u(() => {
22
+ g(document, "click", I, p), h(C).observe(
22
23
  document.documentElement,
23
24
  {
24
25
  attributeFilter: ["open"],
@@ -1 +1 @@
1
- {"version":3,"file":"dialog-observer.js","sources":["../../designsystem/dialog/dialog-observer.ts"],"sourcesContent":["import styles from \"../styles.module.css\";\nimport {\n\tattr,\n\tcreateOptimizedMutationObserver,\n\tIS_BROWSER,\n\ton,\n\tonLoaded,\n\tQUICK_EVENT,\n} from \"../utils\";\n\nconst CSS_DIALOG = styles.dialog.split(\" \")[0];\nconst DIALOGS = IS_BROWSER\n\t? (document.getElementsByClassName(\n\t\t\tCSS_DIALOG,\n\t\t) as HTMLCollectionOf<HTMLDialogElement>)\n\t: [];\n\nconst handleModal = () => {\n\tfor (const dialog of DIALOGS)\n\t\tif (dialog.isConnected && dialog.showModal && dialog.close) {\n\t\t\tif (dialog.matches('[open]:not([data-modal=\"false\"]):not(:modal)')) {\n\t\t\t\tattr(dialog, \"open\", null); // Using attribute instead of .close to avoid `close` event\n\t\t\t\tdialog.showModal();\n\t\t\t} else if (dialog.matches(\":modal:not([open])\")) {\n\t\t\t\tattr(dialog, \"open\", \"\"); // Set as open\n\t\t\t\tdialog.close(); // So we correclty can call .close, removing <dialog> from #top-layer\n\t\t\t}\n\t\t}\n};\n\nconst handleDialogClick = ({\n\tclientX: x,\n\tclientY: y,\n\ttarget: el,\n}: MouseEvent) => {\n\tif (el instanceof HTMLDialogElement && attr(el, \"data-closedby\") === \"any\") {\n\t\tconst { top, right, bottom, left } = el.getBoundingClientRect();\n\t\tconst isInside = top <= y && y <= bottom && left <= x && x <= right;\n\t\tif (!isInside) return el.close();\n\t}\n\tconst dialog = (el as Element)?.closest?.(\"dialog\");\n\tconst close = dialog && (el as Element)?.closest?.('[data-command=\"close\"]');\n\tif (close) dialog.close();\n};\n\nonLoaded(() => {\n\ton(document, \"click\", handleDialogClick as EventListener, QUICK_EVENT);\n\tcreateOptimizedMutationObserver(handleModal).observe(\n\t\tdocument.documentElement,\n\t\t{\n\t\t\tattributeFilter: [\"open\"],\n\t\t\tattributes: true,\n\t\t\tchildList: true,\n\t\t\tsubtree: true,\n\t\t},\n\t);\n});\n"],"names":["CSS_DIALOG","styles","DIALOGS","IS_BROWSER","handleModal","dialog","attr","handleDialogClick","x","y","el","top","right","bottom","left","onLoaded","on","QUICK_EVENT","createOptimizedMutationObserver"],"mappings":";;AAUA,MAAMA,IAAaC,EAAO,OAAO,MAAM,GAAG,EAAE,CAAC,GACvCC,IAAUC,IACZ,SAAS;AAAA,EACVH;AACD,IACC,CAAA,GAEGI,IAAc,MAAM;AACzB,aAAWC,KAAUH;AACpB,IAAIG,EAAO,eAAeA,EAAO,aAAaA,EAAO,UAChDA,EAAO,QAAQ,8CAA8C,KAChEC,EAAKD,GAAQ,QAAQ,IAAI,GACzBA,EAAO,UAAA,KACGA,EAAO,QAAQ,oBAAoB,MAC7CC,EAAKD,GAAQ,QAAQ,EAAE,GACvBA,EAAO,MAAA;AAGX,GAEME,IAAoB,CAAC;AAAA,EAC1B,SAASC;AAAA,EACT,SAASC;AAAA,EACT,QAAQC;AACT,MAAkB;AACjB,MAAIA,aAAc,qBAAqBJ,EAAKI,GAAI,eAAe,MAAM,OAAO;AAC3E,UAAM,EAAE,KAAAC,GAAK,OAAAC,GAAO,QAAAC,GAAQ,MAAAC,EAAA,IAASJ,EAAG,sBAAA;AAExC,QAAI,EADaC,KAAOF,KAAKA,KAAKI,KAAUC,KAAQN,KAAKA,KAAKI,GAC/C,QAAOF,EAAG,MAAA;AAAA,EAC1B;AACA,QAAML,IAAUK,GAAgB,UAAU,QAAQ;AAElD,EADcL,KAAWK,GAAgB,UAAU,wBAAwB,OACzD,MAAA;AACnB;AAEAK,EAAS,MAAM;AACd,EAAAC,EAAG,UAAU,SAAST,GAAoCU,CAAW,GACrEC,EAAgCd,CAAW,EAAE;AAAA,IAC5C,SAAS;AAAA,IACT;AAAA,MACC,iBAAiB,CAAC,MAAM;AAAA,MACxB,YAAY;AAAA,MACZ,WAAW;AAAA,MACX,SAAS;AAAA,IAAA;AAAA,EACV;AAEF,CAAC;"}
1
+ {"version":3,"file":"dialog-observer.js","sources":["../../designsystem/dialog/dialog-observer.ts"],"sourcesContent":["import styles from \"../styles.module.css\";\nimport {\n\tattr,\n\tcreateOptimizedMutationObserver,\n\tIS_BROWSER,\n\ton,\n\tonLoaded,\n\tQUICK_EVENT,\n} from \"../utils\";\n\nconst CSS_DIALOG = styles.dialog.split(\" \")[0];\nconst DIALOGS = IS_BROWSER\n\t? (document.getElementsByClassName(\n\t\t\tCSS_DIALOG,\n\t\t) as HTMLCollectionOf<HTMLDialogElement>)\n\t: [];\n\nconst handleModal = () => {\n\tfor (const dialog of DIALOGS)\n\t\tif (dialog.isConnected && dialog.showModal && dialog.close) {\n\t\t\tif (dialog.matches('[open]:not([data-modal=\"false\"]):not(:modal)')) {\n\t\t\t\tattr(dialog, \"open\", null); // Using attribute instead of .close to avoid `close` event\n\t\t\t\tdialog.showModal();\n\t\t\t} else if (dialog.matches(\":modal:not([open])\")) {\n\t\t\t\tattr(dialog, \"open\", \"\"); // Set as open\n\t\t\t\tdialog.close(); // So we correclty can call .close, removing <dialog> from #top-layer\n\t\t\t}\n\t\t}\n};\n\nconst handleDialogClick = ({\n\tclientX: x,\n\tclientY: y,\n\ttarget: el,\n}: MouseEvent) => {\n\tfor (const dialog of DIALOGS)\n\t\tif (dialog.open && attr(dialog, \"data-closedby\") === \"any\") {\n\t\t\tconst { top, right, bottom, left } = dialog.getBoundingClientRect();\n\t\t\tconst isInside = top <= y && y <= bottom && left <= x && x <= right;\n\t\t\tif (!isInside) return dialog.close();\n\t\t}\n\tconst dialog = (el as Element)?.closest?.(\"dialog\");\n\tconst close = dialog && (el as Element)?.closest?.('[data-command=\"close\"]');\n\tif (close) dialog.close();\n};\n\nonLoaded(() => {\n\ton(document, \"click\", handleDialogClick as EventListener, QUICK_EVENT);\n\tcreateOptimizedMutationObserver(handleModal).observe(\n\t\tdocument.documentElement,\n\t\t{\n\t\t\tattributeFilter: [\"open\"],\n\t\t\tattributes: true,\n\t\t\tchildList: true,\n\t\t\tsubtree: true,\n\t\t},\n\t);\n});\n"],"names":["CSS_DIALOG","styles","DIALOGS","IS_BROWSER","handleModal","dialog","attr","handleDialogClick","x","y","el","top","right","bottom","left","onLoaded","on","QUICK_EVENT","createOptimizedMutationObserver"],"mappings":";;AAUA,MAAMA,IAAaC,EAAO,OAAO,MAAM,GAAG,EAAE,CAAC,GACvCC,IAAUC,IACZ,SAAS;AAAA,EACVH;AACD,IACC,CAAA,GAEGI,IAAc,MAAM;AACzB,aAAWC,KAAUH;AACpB,IAAIG,EAAO,eAAeA,EAAO,aAAaA,EAAO,UAChDA,EAAO,QAAQ,8CAA8C,KAChEC,EAAKD,GAAQ,QAAQ,IAAI,GACzBA,EAAO,UAAA,KACGA,EAAO,QAAQ,oBAAoB,MAC7CC,EAAKD,GAAQ,QAAQ,EAAE,GACvBA,EAAO,MAAA;AAGX,GAEME,IAAoB,CAAC;AAAA,EAC1B,SAASC;AAAA,EACT,SAASC;AAAA,EACT,QAAQC;AACT,MAAkB;AACjB,aAAWL,KAAUH;AACpB,QAAIG,EAAO,QAAQC,EAAKD,GAAQ,eAAe,MAAM,OAAO;AAC3D,YAAM,EAAE,KAAAM,GAAK,OAAAC,GAAO,QAAAC,GAAQ,MAAAC,EAAA,IAAST,EAAO,sBAAA;AAE5C,UAAI,EADaM,KAAOF,KAAKA,KAAKI,KAAUC,KAAQN,KAAKA,KAAKI,GAC/C,QAAOP,EAAO,MAAA;AAAA,IAC9B;AACD,QAAMA,IAAUK,GAAgB,UAAU,QAAQ;AAElD,EADcL,KAAWK,GAAgB,UAAU,wBAAwB,OACzD,MAAA;AACnB;AAEAK,EAAS,MAAM;AACd,EAAAC,EAAG,UAAU,SAAST,GAAoCU,CAAW,GACrEC,EAAgCd,CAAW,EAAE;AAAA,IAC5C,SAAS;AAAA,IACT;AAAA,MACC,iBAAiB,CAAC,MAAM;AAAA,MACxB,YAAY;AAAA,MACZ,WAAW;AAAA,MACX,SAAS;AAAA,IAAA;AAAA,EACV;AAEF,CAAC;"}
@@ -8,5 +8,7 @@ export declare const Default: Story;
8
8
  export declare const React: Story;
9
9
  export declare const WithClose: Story;
10
10
  export declare const WithBackdropClose: Story;
11
+ export declare const WithStickyFooter: Story;
11
12
  export declare const WithoutBackdrop: Story;
12
- export declare const AsDrawer: Story;
13
+ export declare const VariantDrawer: Story;
14
+ export declare const VariantDrawerWithoutBackdrop: Story;
@@ -1,23 +1,22 @@
1
- import { flip as C, shift as E, size as I } from "@floating-ui/dom";
2
- import { UHTMLComboboxElement as M } from "@u-elements/u-combobox";
3
- import { UHTMLDataListElement as A } from "@u-elements/u-datalist";
1
+ import { UHTMLComboboxElement as E } from "@u-elements/u-combobox";
2
+ import { UHTMLDataListElement as S } from "@u-elements/u-datalist";
4
3
  import h from "../styles.module.css.js";
5
- import { onLoaded as H, onMutation as $, on as m, QUICK_EVENT as b, isInputLike as v, attr as a, useId as u, anchorPosition as g } from "../utils.js";
6
- const p = h.field.split(" ")[0], x = h.validation.split(" "), w = x[0], l = (t, o) => t.getPropertyValue(`--mtds-text-${o}`)?.slice(1, -1) || "";
7
- function y(t, o) {
8
- for (const n of t)
9
- if (n.isConnected) {
10
- const i = [], s = [], f = [];
4
+ import { onLoaded as I, onMutation as M, on as m, QUICK_EVENT as b, isInputLike as v, attr as a, useId as u, anchorPosition as g } from "../utils.js";
5
+ const p = h.field.split(" ")[0], x = h.validation.split(" "), A = x[0], l = (t, e) => t.getPropertyValue(`--mtds-text-${e}`)?.slice(1, -1) || "";
6
+ function y(t, e) {
7
+ for (const i of t)
8
+ if (i.isConnected) {
9
+ const n = [], s = [], f = [];
11
10
  let c = null, r = null, d = !0;
12
- for (const e of n.getElementsByTagName("*"))
13
- e instanceof HTMLLabelElement ? i.push(e) : e instanceof M ? c = e : v(e) && !e.hidden ? r = e : e.hasAttribute("data-description") ? s.push(e) : e.classList.contains(w) ? (d = a(e, "data-color") === "success" || !e.clientHeight, f.push(e), s.unshift(e)) : e instanceof HTMLParagraphElement && (s.some((T) => T.contains(e)) || s.push(e));
11
+ for (const o of i.getElementsByTagName("*"))
12
+ o instanceof HTMLLabelElement ? n.push(o) : o instanceof E ? c = o : v(o) && !o.hidden ? r = o : o.hasAttribute("data-description") ? s.push(o) : o.classList.contains(A) ? (d = a(o, "data-color") === "success" || !o.clientHeight, f.push(o), s.unshift(o)) : o instanceof HTMLParagraphElement && (s.some((C) => C.contains(o)) || s.push(o));
14
13
  if (r) {
15
- for (const e of i) e.htmlFor = u(r);
16
- if (o && a(n, "data-validation") === "form") {
14
+ for (const o of n) o.htmlFor = u(r);
15
+ if (e && a(i, "data-validation") === "form") {
17
16
  d = r.matches(":valid");
18
- for (const e of f) a(e, "hidden", d ? "" : null);
17
+ for (const o of f) a(o, "hidden", d ? "" : null);
19
18
  }
20
- N(c), S(r), L(r), a(r, "aria-describedby", s.map(u).join(" ") || null), a(r, "aria-invalid", `${!d}`);
19
+ H(c), T(r), L(r), a(r, "aria-describedby", s.map(u).join(" ") || null), a(r, "aria-invalid", `${!d}`);
21
20
  }
22
21
  }
23
22
  }
@@ -27,56 +26,48 @@ function L(t) {
27
26
  `${t.scrollHeight}px`
28
27
  ));
29
28
  }
30
- function N(t) {
31
- const { control: o, list: n } = t || {};
32
- if (t && n && !t.hasAttribute("data-sr-added")) {
33
- const i = window.getComputedStyle(t);
34
- a(t, "data-sr-added", l(i, "combobox-added")), a(t, "data-sr-empty", l(i, "combobox-empty")), a(t, "data-sr-found", l(i, "combobox-found")), a(t, "data-sr-invalid", l(i, "combobox-invalid")), a(t, "data-sr-of", l(i, "combobox-of")), a(t, "data-sr-remove", l(i, "combobox-remove")), a(t, "data-sr-removed", l(i, "combobox-removed")), a(n, "data-sr-plural", l(i, "datalist-plural")), a(n, "data-sr-singular", l(i, "datalist-singular"));
29
+ function H(t) {
30
+ const { control: e, list: i } = t || {};
31
+ if (t && i && !t.hasAttribute("data-sr-added")) {
32
+ const n = window.getComputedStyle(t);
33
+ a(t, "data-sr-added", l(n, "combobox-added")), a(t, "data-sr-empty", l(n, "combobox-empty")), a(t, "data-sr-found", l(n, "combobox-found")), a(t, "data-sr-invalid", l(n, "combobox-invalid")), a(t, "data-sr-of", l(n, "combobox-of")), a(t, "data-sr-remove", l(n, "combobox-remove")), a(t, "data-sr-removed", l(n, "combobox-removed")), a(i, "data-sr-plural", l(n, "datalist-plural")), a(i, "data-sr-singular", l(n, "datalist-singular"));
35
34
  }
36
- n && o && !n.hasAttribute("popover") && (a(n, "popover", "manual"), a(o, "popovertarget", u(n)));
35
+ i && e && !i.hasAttribute("popover") && (a(i, "popover", "manual"), a(e, "popovertarget", u(i)));
37
36
  }
38
- function S(t) {
39
- const o = t?.nextElementSibling, n = o && a(o, "data-count");
40
- if (o && n) {
41
- const i = Number(n) - t.value.length, s = i < 0, f = a(o, "aria-live") === "polite", c = window.getComputedStyle(o || t), r = l(c, "count-over"), d = l(c, "count-under");
37
+ function T(t) {
38
+ const e = t?.nextElementSibling, i = e && a(e, "data-count");
39
+ if (e && i) {
40
+ const n = Number(i) - t.value.length, s = n < 0, f = a(e, "aria-live") === "polite", c = window.getComputedStyle(e || t), r = l(c, "count-over"), d = l(c, "count-under");
42
41
  if (f !== s) {
43
- a(o, "aria-live", s ? "polite" : "off");
44
- for (const e of x) o.classList.toggle(e, s);
42
+ a(e, "aria-live", s ? "polite" : "off");
43
+ for (const o of x) e.classList.toggle(o, s);
45
44
  }
46
- o.textContent = (s ? r : d).replace(
45
+ e.textContent = (s ? r : d).replace(
47
46
  "%d",
48
- `${Math.abs(i)}`
47
+ `${Math.abs(n)}`
49
48
  );
50
49
  }
51
50
  }
52
- function F(t) {
53
- if (t.target instanceof A) {
54
- const o = t.target, i = o.getRootNode()?.querySelector(
55
- `[popovertarget="${o.id}"]`
51
+ function $({ target: t, newState: e }) {
52
+ if (t instanceof S) {
53
+ const n = t.getRootNode()?.querySelector(
54
+ `[popovertarget="${t.id}"]`
56
55
  );
57
- t.newState === "closed" ? g(o, !1) : i && g(o, i, {
58
- placement: a(o, "data-position") ?? "bottom",
59
- middleware: [
60
- C(),
61
- E(),
62
- I({
63
- padding: 10,
64
- apply({ availableHeight: s }) {
65
- o.style.width = `${i.offsetWidth}px`, o.style.maxHeight = `${Math.max(50, s)}px`;
66
- }
67
- })
68
- ]
56
+ e === "closed" ? g(t, !1) : n && g(t, n, {
57
+ contain({ availableHeight: s }) {
58
+ t.style.width = `${n.clientWidth}px`, t.style.maxHeight = `${Math.max(50, s)}px`;
59
+ }
69
60
  });
70
61
  }
71
62
  }
72
- function D(t) {
73
- v(t.target) && (S(t.target), L(t.target));
63
+ function N(t) {
64
+ v(t.target) && (T(t.target), L(t.target));
74
65
  }
75
- function P(t) {
76
- const o = t.target?.closest?.(`.${p}`);
77
- t.type === "invalid" && o && t.preventDefault(), y(document.getElementsByClassName(p), !0);
66
+ function F(t) {
67
+ const e = t.target?.closest?.(`.${p}`);
68
+ t.type === "invalid" && e && t.preventDefault(), y(document.getElementsByClassName(p), !0);
78
69
  }
79
- H(() => {
80
- $(document.documentElement, p, y), m(document, "input", D, b), m(document, "invalid,submit", P, !0), m(document, "toggle", F, b);
70
+ I(() => {
71
+ M(document.documentElement, p, y), m(document, "input", N, b), m(document, "invalid,submit", F, !0), m(document, "toggle", $, b);
81
72
  });
82
73
  //# sourceMappingURL=field-observer.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"field-observer.js","sources":["../../designsystem/field/field-observer.ts"],"sourcesContent":["import { flip, type Placement, shift, size } from \"@floating-ui/dom\";\nimport { UHTMLComboboxElement } from \"@u-elements/u-combobox\";\nimport { UHTMLDataListElement } from \"@u-elements/u-datalist\";\nimport styles from \"../styles.module.css\";\nimport {\n\tanchorPosition,\n\tattr,\n\tisInputLike,\n\ton,\n\tonLoaded,\n\tonMutation,\n\tQUICK_EVENT,\n\tuseId,\n} from \"../utils\";\n\nconst CSS_FIELD = styles.field.split(\" \")[0];\nconst CSS_VALIDATIONS = styles.validation.split(\" \");\nconst CSS_VALIDATION = CSS_VALIDATIONS[0];\n\nconst getText = (style: CSSStyleDeclaration, key: string) =>\n\tstyle.getPropertyValue(`--mtds-text-${key}`)?.slice(1, -1) || \"\"; // slice to trim quotes\n\nfunction handleFieldMutation(\n\tfields: HTMLCollectionOf<Element>,\n\tvalidate?: boolean,\n) {\n\tfor (const field of fields)\n\t\tif (field.isConnected) {\n\t\t\tconst labels: HTMLLabelElement[] = [];\n\t\t\tconst descs: Element[] = [];\n\t\t\tconst valids: Element[] = [];\n\t\t\tlet combobox: UHTMLComboboxElement | null = null;\n\t\t\tlet input: HTMLInputElement | null = null;\n\t\t\tlet valid = true;\n\n\t\t\tfor (const el of field.getElementsByTagName(\"*\")) {\n\t\t\t\tif (el instanceof HTMLLabelElement) labels.push(el);\n\t\t\t\telse if (el instanceof UHTMLComboboxElement) combobox = el;\n\t\t\t\telse if (isInputLike(el) && !el.hidden) input = el;\n\t\t\t\telse if (el.hasAttribute(\"data-description\")) descs.push(el);\n\t\t\t\telse if (el.classList.contains(CSS_VALIDATION)) {\n\t\t\t\t\tvalid = attr(el, \"data-color\") === \"success\" || !el.clientHeight; // Only set invalid if Validation is visible\n\t\t\t\t\tvalids.push(el);\n\t\t\t\t\tdescs.unshift(el);\n\t\t\t\t} else if (el instanceof HTMLParagraphElement)\n\t\t\t\t\tdescs.some((desc) => desc.contains(el)) || descs.push(el); // Only add if not already inside description\n\t\t\t}\n\n\t\t\tif (input) {\n\t\t\t\tfor (const label of labels) label.htmlFor = useId(input);\n\t\t\t\tif (validate && attr(field, \"data-validation\") === \"form\") {\n\t\t\t\t\tvalid = input.matches(\":valid\");\n\t\t\t\t\tfor (const el of valids) attr(el, \"hidden\", valid ? \"\" : null);\n\t\t\t\t}\n\t\t\t\trenderCombobox(combobox);\n\t\t\t\trenderCounter(input);\n\t\t\t\trenderTextareaSize(input);\n\t\t\t\tattr(input, \"aria-describedby\", descs.map(useId).join(\" \") || null); // Remove if empty\n\t\t\t\tattr(input, \"aria-invalid\", `${!valid}`);\n\t\t\t}\n\t\t}\n}\n\n// iOS does not support field-sizing: content, so we need to manually resize\nfunction renderTextareaSize(textarea: Element) {\n\tif (textarea instanceof HTMLTextAreaElement) {\n\t\ttextarea.style.setProperty(\"--mtds-textarea-height\", \"auto\");\n\t\ttextarea.style.setProperty(\n\t\t\t\"--mtds-textarea-height\",\n\t\t\t`${textarea.scrollHeight}px`,\n\t\t);\n\t}\n}\n\n// Setup translations from CSS custom properties\nfunction renderCombobox(el: UHTMLComboboxElement | null) {\n\tconst { control, list } = el || {};\n\n\tif (el && list && !el.hasAttribute(\"data-sr-added\")) {\n\t\tconst style = window.getComputedStyle(el);\n\t\tattr(el, \"data-sr-added\", getText(style, \"combobox-added\"));\n\t\tattr(el, \"data-sr-empty\", getText(style, \"combobox-empty\"));\n\t\tattr(el, \"data-sr-found\", getText(style, \"combobox-found\"));\n\t\tattr(el, \"data-sr-invalid\", getText(style, \"combobox-invalid\"));\n\t\tattr(el, \"data-sr-of\", getText(style, \"combobox-of\"));\n\t\tattr(el, \"data-sr-remove\", getText(style, \"combobox-remove\"));\n\t\tattr(el, \"data-sr-removed\", getText(style, \"combobox-removed\"));\n\t\tattr(list, \"data-sr-plural\", getText(style, \"datalist-plural\"));\n\t\tattr(list, \"data-sr-singular\", getText(style, \"datalist-singular\"));\n\t}\n\tif (list && control && !list.hasAttribute(\"popover\")) {\n\t\tattr(list, \"popover\", \"manual\");\n\t\tattr(control, \"popovertarget\", useId(list));\n\t}\n}\n\nfunction renderCounter(input: HTMLInputElement) {\n\tconst el = input?.nextElementSibling;\n\tconst limit = el && attr(el, \"data-count\");\n\n\tif (el && limit) {\n\t\tconst remainder = Number(limit) - input.value.length;\n\t\tconst nextInvalid = remainder < 0;\n\t\tconst prevInvalid = attr(el, \"aria-live\") === \"polite\";\n\t\tconst style = window.getComputedStyle(el || input);\n\t\tconst over = getText(style, \"count-over\");\n\t\tconst under = getText(style, \"count-under\");\n\n\t\tif (prevInvalid !== nextInvalid) {\n\t\t\tattr(el, \"aria-live\", nextInvalid ? \"polite\" : \"off\");\n\t\t\tfor (const css of CSS_VALIDATIONS) el.classList.toggle(css, nextInvalid);\n\t\t}\n\t\tel.textContent = (nextInvalid ? over : under).replace(\n\t\t\t\"%d\",\n\t\t\t`${Math.abs(remainder)}`,\n\t\t);\n\t}\n}\n\nfunction handleFieldToggle(event: Event & { newState?: string }) {\n\tif (event.target instanceof UHTMLDataListElement) {\n\t\tconst list = event.target;\n\t\tconst root = list.getRootNode() as ShadowRoot | null;\n\t\tconst anchor = root?.querySelector<HTMLElement>(\n\t\t\t`[popovertarget=\"${list.id}\"]`,\n\t\t);\n\n\t\tif (event.newState === \"closed\") anchorPosition(list, false);\n\t\telse if (anchor)\n\t\t\tanchorPosition(list, anchor, {\n\t\t\t\tplacement: (attr(list, \"data-position\") ?? \"bottom\") as Placement,\n\t\t\t\tmiddleware: [\n\t\t\t\t\tflip(),\n\t\t\t\t\tshift(),\n\t\t\t\t\tsize({\n\t\t\t\t\t\tpadding: 10,\n\t\t\t\t\t\tapply({ availableHeight }) {\n\t\t\t\t\t\t\tlist.style.width = `${anchor.offsetWidth}px`;\n\t\t\t\t\t\t\tlist.style.maxHeight = `${Math.max(50, availableHeight)}px`;\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// Update when typing\nfunction handleFieldInput(event: Event) {\n\tif (isInputLike(event.target)) {\n\t\trenderCounter(event.target);\n\t\trenderTextareaSize(event.target);\n\t}\n}\n\nfunction handleFieldValdiation(event: Event) {\n\tconst field = (event.target as Element)?.closest?.(`.${CSS_FIELD}`);\n\tif (event.type === \"invalid\" && field) event.preventDefault(); // Prevent browsers from showing default validation bubbles\n\thandleFieldMutation(document.getElementsByClassName(CSS_FIELD), true); // Update state\n}\n\nonLoaded(() => {\n\tonMutation(document.documentElement, CSS_FIELD, handleFieldMutation);\n\ton(document, \"input\", handleFieldInput, QUICK_EVENT);\n\ton(document, \"invalid,submit\", handleFieldValdiation, true); // Use capture as invalid and submit does not bubble\n\ton(document, \"toggle\", handleFieldToggle, QUICK_EVENT); // Use capture since toggle does not bubble\n});\n"],"names":["CSS_FIELD","styles","CSS_VALIDATIONS","CSS_VALIDATION","getText","style","key","handleFieldMutation","fields","validate","field","labels","descs","valids","combobox","input","valid","el","UHTMLComboboxElement","isInputLike","attr","desc","label","useId","renderCombobox","renderCounter","renderTextareaSize","textarea","control","list","limit","remainder","nextInvalid","prevInvalid","over","under","css","handleFieldToggle","event","UHTMLDataListElement","anchor","anchorPosition","flip","shift","size","availableHeight","handleFieldInput","handleFieldValdiation","onLoaded","onMutation","on","QUICK_EVENT"],"mappings":";;;;;AAeA,MAAMA,IAAYC,EAAO,MAAM,MAAM,GAAG,EAAE,CAAC,GACrCC,IAAkBD,EAAO,WAAW,MAAM,GAAG,GAC7CE,IAAiBD,EAAg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,EAAM,MAAM;AAEjC;AAEA,SAASS,EAAsBT,GAAc;AAC5C,QAAM5B,IAAS4B,EAAM,QAAoB,UAAU,IAAItC,CAAS,EAAE;AAClE,EAAIsC,EAAM,SAAS,aAAa5B,OAAa,eAAA,GAC7CH,EAAoB,SAAS,uBAAuBP,CAAS,GAAG,EAAI;AACrE;AAEAgD,EAAS,MAAM;AACd,EAAAC,EAAW,SAAS,iBAAiBjD,GAAWO,CAAmB,GACnE2C,EAAG,UAAU,SAASJ,GAAkBK,CAAW,GACnDD,EAAG,UAAU,kBAAkBH,GAAuB,EAAI,GAC1DG,EAAG,UAAU,UAAUb,GAAmBc,CAAW;AACtD,CAAC;"}
1
+ {"version":3,"file":"field-observer.js","sources":["../../designsystem/field/field-observer.ts"],"sourcesContent":["import { UHTMLComboboxElement } from \"@u-elements/u-combobox\";\nimport { UHTMLDataListElement } from \"@u-elements/u-datalist\";\nimport styles from \"../styles.module.css\";\nimport {\n\tanchorPosition,\n\tattr,\n\tisInputLike,\n\ton,\n\tonLoaded,\n\tonMutation,\n\tQUICK_EVENT,\n\tuseId,\n} from \"../utils\";\n\nconst CSS_FIELD = styles.field.split(\" \")[0];\nconst CSS_VALIDATIONS = styles.validation.split(\" \");\nconst CSS_VALIDATION = CSS_VALIDATIONS[0];\n\nconst getText = (style: CSSStyleDeclaration, key: string) =>\n\tstyle.getPropertyValue(`--mtds-text-${key}`)?.slice(1, -1) || \"\"; // slice to trim quotes\n\nfunction handleFieldMutation(\n\tfields: HTMLCollectionOf<Element>,\n\tvalidate?: boolean,\n) {\n\tfor (const field of fields)\n\t\tif (field.isConnected) {\n\t\t\tconst labels: HTMLLabelElement[] = [];\n\t\t\tconst descs: Element[] = [];\n\t\t\tconst valids: Element[] = [];\n\t\t\tlet combobox: UHTMLComboboxElement | null = null;\n\t\t\tlet input: HTMLInputElement | null = null;\n\t\t\tlet valid = true;\n\n\t\t\tfor (const el of field.getElementsByTagName(\"*\")) {\n\t\t\t\tif (el instanceof HTMLLabelElement) labels.push(el);\n\t\t\t\telse if (el instanceof UHTMLComboboxElement) combobox = el;\n\t\t\t\telse if (isInputLike(el) && !el.hidden) input = el;\n\t\t\t\telse if (el.hasAttribute(\"data-description\")) descs.push(el);\n\t\t\t\telse if (el.classList.contains(CSS_VALIDATION)) {\n\t\t\t\t\tvalid = attr(el, \"data-color\") === \"success\" || !el.clientHeight; // Only set invalid if Validation is visible\n\t\t\t\t\tvalids.push(el);\n\t\t\t\t\tdescs.unshift(el);\n\t\t\t\t} else if (el instanceof HTMLParagraphElement)\n\t\t\t\t\tdescs.some((desc) => desc.contains(el)) || descs.push(el); // Only add if not already inside description\n\t\t\t}\n\n\t\t\tif (input) {\n\t\t\t\tfor (const label of labels) label.htmlFor = useId(input);\n\t\t\t\tif (validate && attr(field, \"data-validation\") === \"form\") {\n\t\t\t\t\tvalid = input.matches(\":valid\");\n\t\t\t\t\tfor (const el of valids) attr(el, \"hidden\", valid ? \"\" : null);\n\t\t\t\t}\n\t\t\t\trenderCombobox(combobox);\n\t\t\t\trenderCounter(input);\n\t\t\t\trenderTextareaSize(input);\n\t\t\t\tattr(input, \"aria-describedby\", descs.map(useId).join(\" \") || null); // Remove if empty\n\t\t\t\tattr(input, \"aria-invalid\", `${!valid}`);\n\t\t\t}\n\t\t}\n}\n\n// iOS does not support field-sizing: content, so we need to manually resize\nfunction renderTextareaSize(textarea: Element) {\n\tif (textarea instanceof HTMLTextAreaElement) {\n\t\ttextarea.style.setProperty(\"--mtds-textarea-height\", \"auto\");\n\t\ttextarea.style.setProperty(\n\t\t\t\"--mtds-textarea-height\",\n\t\t\t`${textarea.scrollHeight}px`,\n\t\t);\n\t}\n}\n\n// Setup translations from CSS custom properties\nfunction renderCombobox(el: UHTMLComboboxElement | null) {\n\tconst { control, list } = el || {};\n\n\tif (el && list && !el.hasAttribute(\"data-sr-added\")) {\n\t\tconst style = window.getComputedStyle(el);\n\t\tattr(el, \"data-sr-added\", getText(style, \"combobox-added\"));\n\t\tattr(el, \"data-sr-empty\", getText(style, \"combobox-empty\"));\n\t\tattr(el, \"data-sr-found\", getText(style, \"combobox-found\"));\n\t\tattr(el, \"data-sr-invalid\", getText(style, \"combobox-invalid\"));\n\t\tattr(el, \"data-sr-of\", getText(style, \"combobox-of\"));\n\t\tattr(el, \"data-sr-remove\", getText(style, \"combobox-remove\"));\n\t\tattr(el, \"data-sr-removed\", getText(style, \"combobox-removed\"));\n\t\tattr(list, \"data-sr-plural\", getText(style, \"datalist-plural\"));\n\t\tattr(list, \"data-sr-singular\", getText(style, \"datalist-singular\"));\n\t}\n\tif (list && control && !list.hasAttribute(\"popover\")) {\n\t\tattr(list, \"popover\", \"manual\");\n\t\tattr(control, \"popovertarget\", useId(list));\n\t}\n}\n\nfunction renderCounter(input: HTMLInputElement) {\n\tconst el = input?.nextElementSibling;\n\tconst limit = el && attr(el, \"data-count\");\n\n\tif (el && limit) {\n\t\tconst remainder = Number(limit) - input.value.length;\n\t\tconst nextInvalid = remainder < 0;\n\t\tconst prevInvalid = attr(el, \"aria-live\") === \"polite\";\n\t\tconst style = window.getComputedStyle(el || input);\n\t\tconst over = getText(style, \"count-over\");\n\t\tconst under = getText(style, \"count-under\");\n\n\t\tif (prevInvalid !== nextInvalid) {\n\t\t\tattr(el, \"aria-live\", nextInvalid ? \"polite\" : \"off\");\n\t\t\tfor (const css of CSS_VALIDATIONS) el.classList.toggle(css, nextInvalid);\n\t\t}\n\t\tel.textContent = (nextInvalid ? over : under).replace(\n\t\t\t\"%d\",\n\t\t\t`${Math.abs(remainder)}`,\n\t\t);\n\t}\n}\n\nfunction handleFieldToggle({ target: el, newState }: Partial<ToggleEvent>) {\n\tif (el instanceof UHTMLDataListElement) {\n\t\tconst root = el.getRootNode() as ShadowRoot | null;\n\t\tconst anchor = root?.querySelector<HTMLElement>(\n\t\t\t`[popovertarget=\"${el.id}\"]`,\n\t\t);\n\n\t\tif (newState === \"closed\") anchorPosition(el, false);\n\t\telse if (anchor)\n\t\t\tanchorPosition(el, anchor, {\n\t\t\t\tcontain({ availableHeight }) {\n\t\t\t\t\tel.style.width = `${anchor.clientWidth}px`;\n\t\t\t\t\tel.style.maxHeight = `${Math.max(50, availableHeight)}px`;\n\t\t\t\t},\n\t\t\t});\n\t}\n}\n// Update when typing\nfunction handleFieldInput(event: Event) {\n\tif (isInputLike(event.target)) {\n\t\trenderCounter(event.target);\n\t\trenderTextareaSize(event.target);\n\t}\n}\n\nfunction handleFieldValdiation(event: Event) {\n\tconst field = (event.target as Element)?.closest?.(`.${CSS_FIELD}`);\n\tif (event.type === \"invalid\" && field) event.preventDefault(); // Prevent browsers from showing default validation bubbles\n\thandleFieldMutation(document.getElementsByClassName(CSS_FIELD), true); // Update state\n}\n\nonLoaded(() => {\n\tonMutation(document.documentElement, CSS_FIELD, handleFieldMutation);\n\ton(document, \"input\", handleFieldInput, QUICK_EVENT);\n\ton(document, \"invalid,submit\", handleFieldValdiation, true); // Use capture as invalid and submit does not bubble\n\ton(document, \"toggle\", handleFieldToggle, QUICK_EVENT); // Use capture since toggle does not bubble\n});\n"],"names":["CSS_FIELD","styles","CSS_VALIDATIONS","CSS_VALIDATION","getText","style","key","handleFieldMutation","fields","validate","field","labels","descs","valids","combobox","input","valid","el","UHTMLComboboxElement","isInputLike","attr","desc","label","useId","renderCombobox","renderCounter","renderTextareaSize","textarea","control","list","limit","remainder","nextInvalid","prevInvalid","over","under","css","handleFieldToggle","newState","UHTMLDataListElement","anchor","anchorPosition","availableHeight","handleFieldInput","event","handleFieldValdiation","onLoaded","onMutation","on","QUICK_EVENT"],"mappings":";;;;AAcA,MAAMA,IAAYC,EAAO,MAAM,MAAM,GAAG,EAAE,CAAC,GACrCC,IAAkBD,EAAO,WAAW,MAAM,GAAG,GAC7CE,IAAiBD,EAAgB,CAAC,GAElCE,IAAU,CAACC,GAA4BC,MAC5CD,EAAM,iBAAiB,eAAeC,CAAG,EAAE,GAAG,MAAM,GAAG,EAAE,KAAK;AAE/D,SAASC,EACRC,GACAC,GACC;A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,UAAU,SAASL,GAAkBM,CAAW,GACnDD,EAAG,UAAU,kBAAkBH,GAAuB,EAAI,GAC1DG,EAAG,UAAU,UAAUX,GAAmBY,CAAW;AACtD,CAAC;"}
package/mtds/index.d.ts CHANGED
@@ -28,7 +28,6 @@ grid: string;
28
28
  flex: string;
29
29
  link: string;
30
30
  logo: string;
31
- map: string;
32
31
  pagination: string;
33
32
  popover: string;
34
33
  progress: string;