@mattilsynet/design 0.0.7 → 0.0.8
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/field/field.d.ts +2 -1
- package/mtds/field/field.js +38 -25
- package/mtds/field/field.js.map +1 -1
- package/mtds/index.d.ts +1 -0
- package/mtds/index.js +5 -3
- package/mtds/styles.css +997 -82
- package/mtds/styles.json +275 -105
- package/mtds/styles.module.css.js +286 -114
- package/mtds/styles.module.css.js.map +1 -1
- package/package.json +1 -3
package/mtds/field/field.d.ts
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export
|
|
1
|
+
export declare function observe(el: Element): void;
|
|
2
|
+
export declare function unobserve(el: Element): void;
|
package/mtds/field/field.js
CHANGED
|
@@ -1,31 +1,44 @@
|
|
|
1
|
-
import
|
|
2
|
-
const
|
|
3
|
-
let
|
|
4
|
-
function
|
|
5
|
-
return
|
|
1
|
+
import u from "../styles.module.css.js";
|
|
2
|
+
const f = `:${Date.now().toString(36)}${Math.random().toString(36).slice(2, 5)}`, d = u.field.split(" ")[0], b = u.validation.split(" ")[0], a = /* @__PURE__ */ new WeakMap();
|
|
3
|
+
let m = 0;
|
|
4
|
+
function r(t) {
|
|
5
|
+
return t.id || (t.id = `${f}${++m}`), t.id;
|
|
6
6
|
}
|
|
7
|
-
function
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
}),
|
|
11
|
-
|
|
7
|
+
function v(t) {
|
|
8
|
+
const e = [], i = new MutationObserver((n) => {
|
|
9
|
+
e[0] || requestAnimationFrame(o), e.push(...n);
|
|
10
|
+
}), o = () => {
|
|
11
|
+
t(e, i), e.length = 0;
|
|
12
12
|
};
|
|
13
|
-
return
|
|
13
|
+
return i;
|
|
14
14
|
}
|
|
15
|
-
function
|
|
16
|
-
for (const
|
|
17
|
-
const
|
|
18
|
-
let
|
|
19
|
-
for (const
|
|
20
|
-
|
|
21
|
-
if (
|
|
22
|
-
|
|
15
|
+
function l(t) {
|
|
16
|
+
for (const e of t) {
|
|
17
|
+
const i = [], o = [];
|
|
18
|
+
let n = null, c = !0;
|
|
19
|
+
for (const s of e.getElementsByTagName("*"))
|
|
20
|
+
s instanceof HTMLLabelElement ? i.push(s) : "validity" in s && !(s instanceof HTMLButtonElement) ? n = s : s.classList.contains(b) ? (c = s.getAttribute("data-color") === "success", o.unshift(r(s))) : s instanceof HTMLParagraphElement && o.push(r(s));
|
|
21
|
+
if (n) for (const s of i) s.htmlFor = r(n);
|
|
22
|
+
n == null || n.setAttribute("aria-describedby", o.join(" ")), n == null || n.setAttribute("aria-invalid", `${!c}`);
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
25
|
+
typeof window < "u" && h(document.body);
|
|
26
|
+
function h(t) {
|
|
27
|
+
if (a.has(t)) return;
|
|
28
|
+
const e = t.getElementsByClassName(d), i = v(() => l(e));
|
|
29
|
+
i.observe(t, {
|
|
30
|
+
attributeFilter: ["class"],
|
|
31
|
+
attributes: !0,
|
|
32
|
+
childList: !0,
|
|
33
|
+
subtree: !0
|
|
34
|
+
}), l(e), a.set(t, i);
|
|
35
|
+
}
|
|
36
|
+
function g(t) {
|
|
37
|
+
var e;
|
|
38
|
+
(e = a.get(t)) == null || e.disconnect();
|
|
39
|
+
}
|
|
40
|
+
export {
|
|
41
|
+
h as observe,
|
|
42
|
+
g as unobserve
|
|
43
|
+
};
|
|
31
44
|
//# sourceMappingURL=field.js.map
|
package/mtds/field/field.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"field.js","sources":["../../designsystem/field/field.ts"],"sourcesContent":["import styles from '../styles.module.css';\n\nconst
|
|
1
|
+
{"version":3,"file":"field.js","sources":["../../designsystem/field/field.ts"],"sourcesContent":["import styles from '../styles.module.css';\n\nconst UUID = `:${Date.now().toString(36)}${Math.random().toString(36).slice(2, 5)}`;\nconst CSS_FIELD = styles.field.split(' ')[0];\nconst CSS_VALIDATION = styles.validation.split(' ')[0];\nconst OBSERVERS = new WeakMap();\n\nlet id = 0;\nfunction useId (el: Element) {\n if (!el.id) el.id = `${UUID}${++id}`;\n\treturn el.id;\n};\n\n// Speed up MutationObserver by debouncing and only running when page is visible\nfunction createOptimizedMutationObserver(callback: MutationCallback) {\n const queue: MutationRecord[] = [];\n const observer = new MutationObserver((mutations) => {\n if (!queue[0]) requestAnimationFrame(process);\n queue.push(...mutations);\n });\n\n const process = () => {\n callback(queue, observer);\n queue.length = 0; // Reset queue\n };\n\n return observer;\n}\n\n\nfunction process(fields: HTMLCollectionOf<Element>) {\n for(const field of fields) {\n const labels: HTMLLabelElement[] = [];\n const descs: string[] = [];\n let input: Element | null = null;\n let valid = true;\n\n for (const el of field.getElementsByTagName('*')) {\n if (el instanceof HTMLLabelElement) labels.push(el);\n else if ('validity' in el && !(el instanceof HTMLButtonElement)) input = el;\n else if (el.classList.contains(CSS_VALIDATION)) { // Must be before validation since it can also be a <p>\n valid = el.getAttribute('data-color') === 'success';\n descs.unshift(useId(el));\n } else if (el instanceof HTMLParagraphElement) descs.push(useId(el));\n }\n\n if (input) for (const label of labels) label.htmlFor = useId(input);\n input?.setAttribute('aria-describedby', descs.join(' '));\n input?.setAttribute('aria-invalid', `${!valid}`);\n }\n}\n\n// Automatically observe <body> if in browser\nif (typeof window !== 'undefined') observe(document.body);\n\nexport function observe (el: Element) {\n if (OBSERVERS.has(el)) return;\n const fields = el.getElementsByClassName(CSS_FIELD); // Reutrns a live HTMLCollection\n const observer = createOptimizedMutationObserver(() => process(fields));\n observer.observe(el, {\n attributeFilter: ['class'],\n attributes: true,\n childList: true,\n subtree: true\n });\n\n process(fields); // Initial run\n OBSERVERS.set(el, observer);\n}\n\nexport function unobserve (el: Element) {\n OBSERVERS.get(el)?.disconnect();\n}\n"],"names":["UUID","CSS_FIELD","styles","CSS_VALIDATION","OBSERVERS","id","useId","el","createOptimizedMutationObserver","callback","queue","observer","mutations","process","fields","field","labels","descs","input","valid","label","observe","unobserve","_a"],"mappings":";AAEA,MAAMA,IAAO,IAAI,KAAK,MAAM,SAAS,EAAE,CAAC,GAAG,KAAK,OAAA,EAAS,SAAS,EAAE,EAAE,MAAM,GAAG,CAAC,CAAC,IAC3EC,IAAYC,EAAO,MAAM,MAAM,GAAG,EAAE,CAAC,GACrCC,IAAiBD,EAAO,WAAW,MAAM,GAAG,EAAE,CAAC,GAC/CE,wBAAgB,QAAQ;AAE9B,IAAIC,IAAK;AACT,SAASC,EAAOC,GAAa;AACvB,SAACA,EAAG,OAAIA,EAAG,KAAK,GAAGP,CAAI,GAAG,EAAEK,CAAE,KAC5BE,EAAG;AACX;AAGA,SAASC,EAAgCC,GAA4B;AACnE,QAAMC,IAA0B,CAAC,GAC3BC,IAAW,IAAI,iBAAiB,CAACC,MAAc;AACnD,IAAKF,EAAM,CAAC,2BAAyBG,CAAO,GACtCH,EAAA,KAAK,GAAGE,CAAS;AAAA,EAAA,CACxB,GAEKC,IAAU,MAAM;AACpB,IAAAJ,EAASC,GAAOC,CAAQ,GACxBD,EAAM,SAAS;AAAA,EACjB;AAEO,SAAAC;AACT;AAGA,SAASE,EAAQC,GAAmC;AAClD,aAAUC,KAASD,GAAQ;AACzB,UAAME,IAA6B,CAAC,GAC9BC,IAAkB,CAAC;AACzB,QAAIC,IAAwB,MACxBC,IAAQ;AAEZ,eAAWZ,KAAMQ,EAAM,qBAAqB,GAAG;AAC7C,MAAIR,aAAc,mBAAyBS,EAAA,KAAKT,CAAE,IACzC,cAAcA,KAAM,EAAEA,aAAc,qBAA4BW,IAAAX,IAChEA,EAAG,UAAU,SAASJ,CAAc,KACnCgB,IAAAZ,EAAG,aAAa,YAAY,MAAM,WACpCU,EAAA,QAAQX,EAAMC,CAAE,CAAC,KACdA,aAAc,0BAA4B,KAAKD,EAAMC,CAAE,CAAC;AAGrE,QAAIW,EAAkB,YAAAE,KAASJ,EAAc,CAAAI,EAAA,UAAUd,EAAMY,CAAK;AAClE,IAAAA,KAAA,QAAAA,EAAO,aAAa,oBAAoBD,EAAM,KAAK,GAAG,IACtDC,KAAA,QAAAA,EAAO,aAAa,gBAAgB,GAAG,CAACC,CAAK;AAAA,EAAE;AAEnD;AAGI,OAAO,SAAW,OAAaE,EAAQ,SAAS,IAAI;AAEjD,SAASA,EAASd,GAAa;AAChC,MAAAH,EAAU,IAAIG,CAAE,EAAG;AACjB,QAAAO,IAASP,EAAG,uBAAuBN,CAAS,GAC5CU,IAAWH,EAAgC,MAAMK,EAAQC,CAAM,CAAC;AACtE,EAAAH,EAAS,QAAQJ,GAAI;AAAA,IACnB,iBAAiB,CAAC,OAAO;AAAA,IACzB,YAAY;AAAA,IACZ,WAAW;AAAA,IACX,SAAS;AAAA,EAAA,CACV,GAEDM,EAAQC,CAAM,GACJV,EAAA,IAAIG,GAAII,CAAQ;AAC5B;AAEO,SAASW,EAAWf,GAAa;;AAC5B,GAAAgB,IAAAnB,EAAA,IAAIG,CAAE,MAAN,QAAAgB,EAAS;AACrB;"}
|
package/mtds/index.d.ts
CHANGED
package/mtds/index.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import * as
|
|
2
|
-
import "./field/field.js";
|
|
1
|
+
import * as e from "./styles.module.css.js";
|
|
2
|
+
import { observe as r, unobserve as t } from "./field/field.js";
|
|
3
3
|
export {
|
|
4
|
-
|
|
4
|
+
r as observe,
|
|
5
|
+
e as styles,
|
|
6
|
+
t as unobserve
|
|
5
7
|
};
|
|
6
8
|
//# sourceMappingURL=index.js.map
|