@oslokommune/punkt-elements
Version:
Komponentbiblioteket til Punkt, et designsystem laget av Oslo Origo
644 lines (643 loc) • 29.2 kB
JavaScript
import { i as e, r as t, s as n } from "./element-cZ85T_aa.js";
import { t as r } from "./element-with-slot-4J2o3SeU.js";
import { n as i } from "./utils-BOOZ0ppt.js";
import { t as a } from "./booleanish-CRaKZ75t.js";
import { t as o } from "./input-wrapper-DwSsP39J.js";
//#region ../../node_modules/element-internals-polyfill/dist/index.js
(function(e) {
let t = /* @__PURE__ */ new WeakMap(), n = /* @__PURE__ */ new WeakMap(), r = /* @__PURE__ */ new WeakMap(), i = /* @__PURE__ */ new WeakMap(), a = /* @__PURE__ */ new WeakMap(), o = /* @__PURE__ */ new WeakMap(), s = /* @__PURE__ */ new WeakMap(), c = /* @__PURE__ */ new WeakMap(), l = /* @__PURE__ */ new WeakMap(), u = /* @__PURE__ */ new WeakMap(), d = /* @__PURE__ */ new WeakMap(), f = /* @__PURE__ */ new WeakMap(), p = /* @__PURE__ */ new WeakMap(), m = /* @__PURE__ */ new WeakMap(), h = /* @__PURE__ */ new WeakMap(), g = {
ariaAtomic: "aria-atomic",
ariaAutoComplete: "aria-autocomplete",
ariaBusy: "aria-busy",
ariaChecked: "aria-checked",
ariaColCount: "aria-colcount",
ariaColIndex: "aria-colindex",
ariaColIndexText: "aria-colindextext",
ariaColSpan: "aria-colspan",
ariaCurrent: "aria-current",
ariaDescription: "aria-description",
ariaDisabled: "aria-disabled",
ariaExpanded: "aria-expanded",
ariaHasPopup: "aria-haspopup",
ariaHidden: "aria-hidden",
ariaInvalid: "aria-invalid",
ariaKeyShortcuts: "aria-keyshortcuts",
ariaLabel: "aria-label",
ariaLevel: "aria-level",
ariaLive: "aria-live",
ariaModal: "aria-modal",
ariaMultiLine: "aria-multiline",
ariaMultiSelectable: "aria-multiselectable",
ariaOrientation: "aria-orientation",
ariaPlaceholder: "aria-placeholder",
ariaPosInSet: "aria-posinset",
ariaPressed: "aria-pressed",
ariaReadOnly: "aria-readonly",
ariaRelevant: "aria-relevant",
ariaRequired: "aria-required",
ariaRoleDescription: "aria-roledescription",
ariaRowCount: "aria-rowcount",
ariaRowIndex: "aria-rowindex",
ariaRowIndexText: "aria-rowindextext",
ariaRowSpan: "aria-rowspan",
ariaSelected: "aria-selected",
ariaSetSize: "aria-setsize",
ariaSort: "aria-sort",
ariaValueMax: "aria-valuemax",
ariaValueMin: "aria-valuemin",
ariaValueNow: "aria-valuenow",
ariaValueText: "aria-valuetext",
role: "role"
}, _ = (e, t) => {
for (let n in g) {
t[n] = null;
let r = null, i = g[n];
Object.defineProperty(t, n, {
get() {
return r;
},
set(n) {
r = n, e.isConnected ? T(e, i, n) : u.set(e, t);
}
});
}
};
function v(e) {
let t = i.get(e), { form: n } = t;
P(e, n, t), A(e, t.labels);
}
let y = (e, t = !1) => {
let n = document.createTreeWalker(e, NodeFilter.SHOW_ELEMENT, { acceptNode(e) {
return i.has(e) ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP;
} }), r = n.nextNode(), a = !t || e.disabled;
for (; r;) r.formDisabledCallback && a && E(r, e.disabled), r = n.nextNode();
}, b = {
attributes: !0,
attributeFilter: ["disabled", "name"]
}, x = z() ? new MutationObserver((e) => {
for (let t of e) {
let e = t.target;
if (t.attributeName === "disabled" && (e.constructor.formAssociated ? E(e, e.hasAttribute("disabled")) : e.localName === "fieldset" && y(e)), t.attributeName === "name" && e.constructor.formAssociated) {
let t = i.get(e), n = l.get(e);
t.setFormValue(n);
}
}
}) : {};
function S(e) {
e.forEach((e) => {
let { addedNodes: t, removedNodes: n } = e, a = Array.from(t), o = Array.from(n);
a.forEach((e) => {
var t;
if (i.has(e) && e.constructor.formAssociated && v(e), u.has(e)) {
let t = u.get(e);
Object.keys(g).filter((e) => t[e] !== null).forEach((n) => {
T(e, g[n], t[n]);
}), u.delete(e);
}
if (h.has(e)) {
let t = h.get(e);
T(e, "internals-valid", t.validity.valid.toString()), T(e, "internals-invalid", (!t.validity.valid).toString()), T(e, "aria-invalid", (!t.validity.valid).toString()), h.delete(e);
}
if (e.localName === "form") {
let t = c.get(e), n = document.createTreeWalker(e, NodeFilter.SHOW_ELEMENT, { acceptNode(e) {
return i.has(e) && e.constructor.formAssociated && !(t && t.has(e)) ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP;
} }), r = n.nextNode();
for (; r;) v(r), r = n.nextNode();
}
e.localName === "fieldset" && ((t = x.observe) == null || t.call(x, e, b), y(e, !0));
}), o.forEach((e) => {
let t = i.get(e);
t && r.get(t) && D(t), s.has(e) && s.get(e).disconnect();
});
});
}
function C(e) {
e.forEach((e) => {
let { removedNodes: t } = e;
t.forEach((t) => {
let n = p.get(e.target);
i.has(t) && R(t), n.disconnect();
});
});
}
let ee = (e) => {
var t;
let n = new MutationObserver(C);
(window == null ? void 0 : window.ShadyDOM)?.inUse && e.mode && e.host && (e = e.host), (t = n.observe) == null || t.call(n, e, { childList: !0 }), p.set(e, n);
};
z() && new MutationObserver(S);
let w = {
childList: !0,
subtree: !0
}, T = (e, t, n) => {
e.getAttribute(t) !== n && e.setAttribute(t, n);
}, E = (e, t) => {
e.toggleAttribute("internals-disabled", t), t ? T(e, "aria-disabled", "true") : e.removeAttribute("aria-disabled"), e.formDisabledCallback && e.formDisabledCallback.apply(e, [t]);
}, D = (e) => {
r.get(e).forEach((e) => {
e.remove();
}), r.set(e, []);
}, O = (e, t) => {
let n = document.createElement("input");
return n.type = "hidden", n.name = e.getAttribute("name"), e.after(n), r.get(t).push(n), n;
}, k = (e, t) => {
var n;
r.set(t, []), (n = x.observe) == null || n.call(x, e, b);
}, A = (e, t) => {
if (t.length) {
Array.from(t).forEach((t) => t.addEventListener("click", e.click.bind(e)));
let n = t[0].id;
t[0].id || (n = `${t[0].htmlFor}_Label`, t[0].id = n), T(e, "aria-labelledby", n);
}
}, j = (e) => {
let t = Array.from(e.elements).filter((e) => !e.tagName.includes("-") && e.validity).map((e) => e.validity.valid), n = c.get(e) || [], r = Array.from(n).filter((e) => e.isConnected).map((e) => i.get(e).validity.valid), a = [...t, ...r].includes(!1);
e.toggleAttribute("internals-invalid", a), e.toggleAttribute("internals-valid", !a);
}, M = (e) => {
j(F(e.target));
}, N = (e) => {
j(F(e.target));
}, te = (e) => {
let t = [
"button[type=submit]",
"input[type=submit]",
"button:not([type])"
].map((e) => `${e}:not([disabled])`).map((t) => `${t}:not([form])${e.id ? `,${t}[form='${e.id}']` : ""}`).join(",");
e.addEventListener("click", (n) => {
if (n.target.closest(t)) {
let t = c.get(e);
if (e.noValidate) return;
t.size && Array.from(t).reverse().map((e) => i.get(e).reportValidity()).includes(!1) && n.preventDefault();
}
});
}, ne = (e) => {
let t = c.get(e.target);
t && t.size && t.forEach((e) => {
e.constructor.formAssociated && e.formResetCallback && e.formResetCallback.apply(e);
});
}, P = (e, t, n) => {
if (t) {
let r = c.get(t);
if (r) r.add(e);
else {
let n = /* @__PURE__ */ new Set();
n.add(e), c.set(t, n), te(t), t.addEventListener("reset", ne), t.addEventListener("input", M), t.addEventListener("change", N);
}
o.set(t, {
ref: e,
internals: n
}), e.constructor.formAssociated && e.formAssociatedCallback && setTimeout(() => {
e.formAssociatedCallback.apply(e, [t]);
}, 0), j(t);
}
}, F = (e) => {
let t = e.parentNode;
return t && t.tagName !== "FORM" && (t = F(t)), t;
}, I = (e, t, n = DOMException) => {
if (!e.constructor.formAssociated) throw new n(t);
}, L = (e, t, n) => {
let r = c.get(e);
return r && r.size && r.forEach((e) => {
i.get(e)[n]() || (t = !1);
}), t;
}, R = (e) => {
if (e.constructor.formAssociated) {
let t = i.get(e), { labels: n, form: r } = t;
A(e, n), P(e, r, t);
}
};
function z() {
return typeof MutationObserver < "u";
}
class B {
constructor() {
this.badInput = !1, this.customError = !1, this.patternMismatch = !1, this.rangeOverflow = !1, this.rangeUnderflow = !1, this.stepMismatch = !1, this.tooLong = !1, this.tooShort = !1, this.typeMismatch = !1, this.valid = !0, this.valueMissing = !1, Object.seal(this);
}
}
let re = (e) => (e.badInput = !1, e.customError = !1, e.patternMismatch = !1, e.rangeOverflow = !1, e.rangeUnderflow = !1, e.stepMismatch = !1, e.tooLong = !1, e.tooShort = !1, e.typeMismatch = !1, e.valid = !0, e.valueMissing = !1, e), ie = (e, t, n) => (e.valid = V(t), Object.keys(t).forEach((n) => e[n] = t[n]), n && j(n), e), V = (e) => {
let t = !0;
for (let n in e) n !== "valid" && e[n] !== !1 && (t = !1);
return t;
}, H = /* @__PURE__ */ new WeakMap();
function U(e, t) {
e.toggleAttribute(t, !0), e.part && e.part.add(t);
}
class W extends Set {
static get isPolyfilled() {
return !0;
}
constructor(e) {
if (super(), !e || !e.tagName || e.tagName.indexOf("-") === -1) throw TypeError("Illegal constructor");
H.set(this, e);
}
add(e) {
if (!/^--/.test(e) || typeof e != "string") throw new DOMException(`Failed to execute 'add' on 'CustomStateSet': The specified value ${e} must start with '--'.`);
let t = super.add(e), n = H.get(this), r = `state${e}`;
return n.isConnected ? U(n, r) : setTimeout(() => {
U(n, r);
}), t;
}
clear() {
for (let [e] of this.entries()) this.delete(e);
super.clear();
}
delete(e) {
let t = super.delete(e), n = H.get(this);
return n.isConnected ? (n.toggleAttribute(`state${e}`, !1), n.part && n.part.remove(`state${e}`)) : setTimeout(() => {
n.toggleAttribute(`state${e}`, !1), n.part && n.part.remove(`state${e}`);
}), t;
}
}
function G(e, t, n, r) {
if (n === "a" && !r) throw TypeError("Private accessor was defined without a getter");
if (typeof t == "function" ? e !== t || !r : !t.has(e)) throw TypeError("Cannot read private member from an object whose class did not declare it");
return n === "m" ? r : n === "a" ? r.call(e) : r ? r.value : t.get(e);
}
function K(e, t, n, r, i) {
if (r === "m") throw TypeError("Private method is not writable");
if (r === "a" && !i) throw TypeError("Private accessor was defined without a setter");
if (typeof t == "function" ? e !== t || !i : !t.has(e)) throw TypeError("Cannot write private member to an object whose class did not declare it");
return r === "a" ? i.call(e, n) : i ? i.value = n : t.set(e, n), n;
}
var q;
class J {
constructor(e) {
q.set(this, void 0), K(this, q, e, "f");
for (let t = 0; t < e.length; t++) {
let n = e[t];
this[t] = n, n.hasAttribute("name") && (this[n.getAttribute("name")] = n);
}
Object.freeze(this);
}
get length() {
return G(this, q, "f").length;
}
[(q = /* @__PURE__ */ new WeakMap(), Symbol.iterator)]() {
return G(this, q, "f")[Symbol.iterator]();
}
item(e) {
return this[e] == null ? null : this[e];
}
namedItem(e) {
return this[e] == null ? null : this[e];
}
}
function ae() {
let e = HTMLFormElement.prototype.checkValidity;
HTMLFormElement.prototype.checkValidity = n;
let t = HTMLFormElement.prototype.reportValidity;
HTMLFormElement.prototype.reportValidity = r;
function n(...t) {
let n = e.apply(this, t);
return L(this, n, "checkValidity");
}
function r(...e) {
let n = t.apply(this, e);
return L(this, n, "reportValidity");
}
let { get: i } = Object.getOwnPropertyDescriptor(HTMLFormElement.prototype, "elements");
Object.defineProperty(HTMLFormElement.prototype, "elements", { get(...e) {
let t = i.call(this, ...e), n = Array.from(c.get(this) || []);
return n.length === 0 ? t : new J(Array.from(t).concat(n).sort((e, t) => e.compareDocumentPosition ? e.compareDocumentPosition(t) & 2 ? 1 : -1 : 0));
} });
}
class Y {
static get isPolyfilled() {
return !0;
}
constructor(e) {
if (!e || !e.tagName || e.tagName.indexOf("-") === -1) throw TypeError("Illegal constructor");
let r = e.getRootNode(), a = new B();
this.states = new W(e), t.set(this, e), n.set(this, a), i.set(e, this), _(e, this), k(e, this), Object.seal(this), r instanceof DocumentFragment && ee(r);
}
checkValidity() {
let e = t.get(this);
if (I(e, "Failed to execute 'checkValidity' on 'ElementInternals': The target element is not a form-associated custom element."), !this.willValidate) return !0;
let r = n.get(this);
if (!r.valid) {
let t = new Event("invalid", {
bubbles: !1,
cancelable: !0,
composed: !1
});
e.dispatchEvent(t);
}
return r.valid;
}
get form() {
let e = t.get(this);
I(e, "Failed to read the 'form' property from 'ElementInternals': The target element is not a form-associated custom element.");
let n;
return e.constructor.formAssociated === !0 && (n = F(e)), n;
}
get labels() {
let e = t.get(this);
I(e, "Failed to read the 'labels' property from 'ElementInternals': The target element is not a form-associated custom element.");
let n = e.getAttribute("id"), r = e.getRootNode();
return r && n ? r.querySelectorAll(`[for="${n}"]`) : [];
}
reportValidity() {
let e = t.get(this);
if (I(e, "Failed to execute 'reportValidity' on 'ElementInternals': The target element is not a form-associated custom element."), !this.willValidate) return !0;
let n = this.checkValidity(), r = f.get(this);
if (r && !e.constructor.formAssociated) throw new DOMException("Failed to execute 'reportValidity' on 'ElementInternals': The target element is not a form-associated custom element.");
return !n && r && (e.focus(), r.focus()), n;
}
setFormValue(e) {
let n = t.get(this);
if (I(n, "Failed to execute 'setFormValue' on 'ElementInternals': The target element is not a form-associated custom element."), D(this), e != null && !(e instanceof FormData)) {
if (n.getAttribute("name")) {
let t = O(n, this);
t.value = e;
}
} else e != null && e instanceof FormData && Array.from(e).reverse().forEach(([e, t]) => {
if (typeof t == "string") {
let r = O(n, this);
r.name = e, r.value = t;
}
});
l.set(n, e);
}
setValidity(e, r, i) {
let o = t.get(this);
if (I(o, "Failed to execute 'setValidity' on 'ElementInternals': The target element is not a form-associated custom element."), !e) throw TypeError("Failed to execute 'setValidity' on 'ElementInternals': 1 argument required, but only 0 present.");
f.set(this, i);
let s = n.get(this), c = {};
for (let t in e) c[t] = e[t];
Object.keys(c).length === 0 && re(s);
let l = Object.assign(Object.assign({}, s), c);
delete l.valid;
let { valid: u } = ie(s, l, this.form);
if (!u && !r) throw new DOMException("Failed to execute 'setValidity' on 'ElementInternals': The second argument should not be empty if one or more flags in the first argument are true.");
a.set(this, u ? "" : r), o.isConnected ? (o.toggleAttribute("internals-invalid", !u), o.toggleAttribute("internals-valid", u), T(o, "aria-invalid", `${!u}`)) : h.set(o, this);
}
get shadowRoot() {
let e = t.get(this);
return d.get(e) || null;
}
get validationMessage() {
return I(t.get(this), "Failed to read the 'validationMessage' property from 'ElementInternals': The target element is not a form-associated custom element."), a.get(this);
}
get validity() {
return I(t.get(this), "Failed to read the 'validity' property from 'ElementInternals': The target element is not a form-associated custom element."), n.get(this);
}
get willValidate() {
let e = t.get(this);
return I(e, "Failed to read the 'willValidate' property from 'ElementInternals': The target element is not a form-associated custom element."), !(e.disabled || e.hasAttribute("disabled") || e.hasAttribute("readonly"));
}
}
function oe() {
if (typeof window > "u" || !window.ElementInternals || !HTMLElement.prototype.attachInternals) return !1;
class e extends HTMLElement {
constructor() {
super(), this.internals = this.attachInternals();
}
}
let t = `element-internals-feature-detection-${Math.random().toString(36).replace(/[^a-z]+/g, "")}`;
customElements.define(t, e);
let n = new e();
return [
"shadowRoot",
"form",
"willValidate",
"validity",
"validationMessage",
"labels",
"setFormValue",
"setValidity",
"checkValidity",
"reportValidity"
].every((e) => e in n.internals);
}
let X = !1, Z = !1;
function Q(e) {
Z || (Z = !0, window.CustomStateSet = W, e && (HTMLElement.prototype.attachInternals = function(...t) {
let n = e.call(this, t);
return n.states = new W(this), n;
}));
}
function $(e = !0) {
if (!X) {
if (X = !0, typeof window < "u" && (window.ElementInternals = Y), typeof CustomElementRegistry < "u") {
let e = CustomElementRegistry.prototype.define;
CustomElementRegistry.prototype.define = function(t, n, r) {
if (n.formAssociated) {
let e = n.prototype.connectedCallback;
n.prototype.connectedCallback = function() {
m.has(this) || (m.set(this, !0), this.hasAttribute("disabled") && E(this, !0)), e?.apply(this), R(this);
};
}
e.call(this, t, n, r);
};
}
if (typeof HTMLElement < "u" && (HTMLElement.prototype.attachInternals = function() {
if (!this.tagName) return {};
if (this.tagName.indexOf("-") === -1) throw Error("Failed to execute 'attachInternals' on 'HTMLElement': Unable to attach ElementInternals to non-custom elements.");
if (i.has(this)) throw new DOMException("DOMException: Failed to execute 'attachInternals' on 'HTMLElement': ElementInternals for the specified element was already attached.");
return new Y(this);
}), typeof Element < "u") {
function e(...e) {
let n = t.apply(this, e);
if (d.set(this, n), z()) {
let e = new MutationObserver(S);
window.ShadyDOM ? e.observe(this, w) : e.observe(n, w), s.set(this, e);
}
return n;
}
let t = Element.prototype.attachShadow;
Element.prototype.attachShadow = e;
}
z() && typeof document < "u" && new MutationObserver(S).observe(document.documentElement, w), typeof HTMLFormElement < "u" && ae(), (e || typeof window < "u" && !window.CustomStateSet) && Q();
}
}
return customElements.polyfillWrapFlushCallback || (oe() ? typeof window < "u" && !window.CustomStateSet && Q(HTMLElement.prototype.attachInternals) : $(!1)), e.forceCustomStateSetPolyfill = Q, e.forceElementInternalsPolyfill = $, Object.defineProperty(e, "__esModule", { value: !0 }), e;
})({});
//#endregion
//#region src/base-elements/input-element.ts
var s = "on", c = "--checked", l = ",", u = class extends r {
static get formAssociated() {
return !0;
}
constructor() {
super(), this.defaultValue = null, this.disabled = !1, this.readonly = !1, this.required = !1, this.max = null, this.maxlength = null, this.min = null, this.minlength = null, this.step = null, this.ariaDescribedBy = null, this.ariaLabelledby = null, this.name = "", this.pattern = null, this.placeholder = null, this.id = i(), this.counter = !1, this.hasError = !1, this.inline = !1, this.hasFieldset = !1, this.optionalTag = !1, this.requiredTag = !1, this.skipForwardTestid = !1, this.useWrapper = !0, this.fullwidth = !1, this.counterMaxLength = 0, this.errorMessage = "", this.helptext = "", this.helptextDropdown = "", this.helptextDropdownButton = o.props.helptextDropdownButton.default, this.label = null, this.optionalText = e.forms.labels.optional, this.requiredText = e.forms.labels.required, this.tagText = null, this.dataTestid = "", this.touched = !1, this.internals = this.attachInternals();
}
manageValidity(t) {
if (!t) {
console.warn("manageValidity called without valid input element");
return;
}
this.required && !this.value ? this.internals.setValidity({ valueMissing: !0 }, e.forms.messages.required, t) : t.validity?.typeMismatch || t.validity?.badInput ? this.internals.setValidity({ typeMismatch: !0 }, e.forms.messages.invalid, t) : t.validity?.patternMismatch ? this.internals.setValidity({ patternMismatch: !0 }, e.forms.messages.invalidPattern, t) : t.validity?.tooShort || this.minlength && this.minlength > 0 && this.value.length < this.minlength ? this.internals.setValidity({ tooShort: !0 }, e.forms.messages.tooShort, t) : t.validity?.tooLong || this.maxlength && this.maxlength > 0 && this.value.length > this.maxlength ? this.internals.setValidity({ tooLong: !0 }, e.forms.messages.tooLong, t) : t.validity?.rangeUnderflow ? this.internals.setValidity({ rangeUnderflow: !0 }, this.min ? e.forms.messages.rangeUnderflowMin.replace("{min}", this.min?.toString()) : e.forms.messages.rangeUnderflow, t) : t.validity?.stepMismatch ? this.internals.setValidity({ stepMismatch: !0 }, e.forms.messages.invalid, t) : t.validity?.rangeOverflow ? this.internals.setValidity({ rangeOverflow: !0 }, this.max ? e.forms.messages.rangeOverflowMax.replace("{max}", this.max?.toString()) : e.forms.messages.rangeOverflow, t) : t.validity?.customError ? this.internals.setValidity({ customError: !0 }, t.validationMessage, t) : this.internals.setValidity({});
}
setFormValue(e) {
if (this.internals) if (Array.isArray(e)) {
let t = new FormData();
e.forEach((e) => {
t.append(this.name, e);
}), this.internals.setFormValue(t);
} else this.internals.setFormValue(e);
}
coordinateRadioGroup() {
if (!this.form || !this.name || this.type !== "radio") return;
let e = `pkt-radiobutton[name="${this.name}"], input[type=radio][name="${this.name}"]`;
this.form.querySelectorAll(e).forEach((e) => {
if (e !== this && e.getAttribute("name") === this.name && e.getAttribute("value") !== this.value) {
let t = e;
t.checked && (t.checked = !1, t.internals && (t.internals.setFormValue(null), t.internals.states?.delete(c)));
}
});
}
valueChecked(e) {
if (!this.touched) return;
let t = this.internals.form || this.closest("form"), n = t ? new FormData(t) : null;
if (this.type === "radio" && this.coordinateRadioGroup(), typeof e == "string" ? (this.checked = e === "true", this.internals.ariaChecked = String(e === "true")) : typeof e == "boolean" && (this.checked = e, this.internals.ariaChecked = String(e)), this.checked) {
let e = (typeof this.value == "string" ? this.value : "") || s;
this.internals.setFormValue(e), n && n.append(this.name, e), this.internals.states.add(c);
} else this.internals.setFormValue(null), n && n.delete(this.name), this.internals.states.delete(c);
this.dispatchChangeEvents(this.checked), this.internals.reportValidity();
}
valueChanged(e, t) {
(t !== this.value || t !== this._value) && (typeof e == "string" ? ((this.multiple || this.range) && e.includes(l) && (e = e.split(l)), this.value = e, this._value = Array.isArray(e) ? e : [e]) : Array.isArray(e) ? (this.value = this.multiple || this.range ? e : e[0], this._value = e) : (this.value = "", this._value = []), (!this.value || this.value.length === 0) && t && t.length !== 0 ? this.clearInputValue() : this.value && this.value.toString() !== t?.toString() && this.onChange(this.value));
}
dispatchChangeEvents(e) {
this.dispatchEvent(new Event("change", {
bubbles: !0,
composed: !0
})), this.dispatchEvent(new CustomEvent("value-change", {
detail: e,
bubbles: !0,
composed: !0
}));
}
clearInputValue() {
let e = this.multiple || this.range ? [] : "";
this.value = e, this.setFormValue(e), this.dispatchChangeEvents(e);
}
onFocus() {
this.dispatchEvent(new FocusEvent("focus", {
bubbles: !0,
composed: !0
}));
}
onBlur() {
this.dispatchEvent(new FocusEvent("blur", {
bubbles: !0,
composed: !0
}));
}
onInput() {
this.dispatchEvent(new InputEvent("input", {
bubbles: !0,
composed: !0
}));
}
normalizeValue(e) {
return (this.range || this.multiple) && typeof e == "string" && e.includes(l) ? e.split(l) : !this.multiple && !this.range && Array.isArray(e) ? e[0] || "" : e;
}
validate() {
this.inputRef?.value && this.manageValidity(this.inputRef.value), this.inputRefTo?.value && this.manageValidity(this.inputRefTo.value);
}
onChange(e) {
if (!this.touched) {
this.touched = !0, e && this.setFormValue(e), this.validate();
return;
}
if (typeof e != "string" && !Array.isArray(e)) return;
let t = this.normalizeValue(e);
this.setFormValue(t), this.validate(), this.dispatchChangeEvents(t);
}
formResetCallback() {
if (this.touched = !1, this._options && this._options.length && this._options.forEach((e) => {
"selected" in e && (e.selected = !1);
}), this.checked !== void 0) this.checked = !1, this.internals.ariaChecked = "false", this.internals.setFormValue(""), this.inputRef?.value && "checked" in this.inputRef.value && (this.inputRef.value.checked = !1), this.valueChecked(this.checked);
else {
this.internals.setFormValue("");
let e = this.defaultValue || (this.multiple || this.range ? [] : "");
this.value = e, this._value = Array.isArray(e) ? e : [e], this.valueChanged(this.value, null);
}
this.internals.ariaInvalid = "false";
}
updated(e) {
super.updated(e), e.has("dataTestid") && this.dataTestid && this.inputRef.value && (this.skipForwardTestid ? this.hasAttribute("data-testid") || this.setAttribute("data-testid", this.dataTestid) : (this.inputRef.value.dataset.testid = this.dataTestid, this.removeAttribute("data-testid")));
}
firstUpdated(e) {
if (super.firstUpdated(e), this.form ||= this.internals.form || this.closest("form"), this.value && this.defaultValue === null && (this.defaultValue = this.value), this.defaultValue !== null && !this.value && this.valueChanged(this.defaultValue, null), this.defaultChecked && (this.internals.ariaChecked = "true", this.checked = !0), this.required && (this.internals.ariaRequired = "true"), this.disabled && (this.internals.ariaDisabled = "true"), this.id && !this.name && (this.name = this.id), this.checked !== void 0) {
let e = this.checked === "" || this.checked === "true" || this.checked === !0;
this.internals.ariaChecked = String(e);
let t = e ? (typeof this.value == "string" ? this.value : "") || s : null;
this.internals.setFormValue(t);
} else this.setFormValue(this.value);
this.inputRef && this.inputRef.value && (this.inputRef.value.setAttribute("form", ""), this.manageValidity(this.inputRef.value)), this.inputRefTo && this.inputRefTo.value && (this.inputRefTo.value.setAttribute("form", ""), this.manageValidity(this.inputRefTo.value));
}
};
t([n({
type: Boolean,
reflect: !0
})], u.prototype, "checked", void 0), t([n({ type: Boolean })], u.prototype, "defaultChecked", void 0), t([n({ type: Boolean })], u.prototype, "multiple", void 0), t([n({ type: Boolean })], u.prototype, "range", void 0), t([n({
type: String,
reflect: !0
})], u.prototype, "type", void 0), t([n()], u.prototype, "defaultValue", void 0), t([n({
type: Boolean,
reflect: !0
})], u.prototype, "disabled", void 0), t([n({
type: Boolean,
reflect: !0
})], u.prototype, "readonly", void 0), t([n({
type: Boolean,
reflect: !0
})], u.prototype, "required", void 0), t([n({
reflect: !0,
converter: {
fromAttribute: (e) => e,
toAttribute: (e) => e?.toString() ?? null
}
})], u.prototype, "max", void 0), t([n({
type: Number,
reflect: !0
})], u.prototype, "maxlength", void 0), t([n({
reflect: !0,
converter: {
fromAttribute: (e) => e,
toAttribute: (e) => e?.toString() ?? null
}
})], u.prototype, "min", void 0), t([n({
type: Number,
reflect: !0
})], u.prototype, "minlength", void 0), t([n({
type: Number,
reflect: !0
})], u.prototype, "step", void 0), t([n({ type: String })], u.prototype, "ariaDescribedBy", void 0), t([n({ type: String })], u.prototype, "ariaLabelledby", void 0), t([n({
type: String,
reflect: !0
})], u.prototype, "name", void 0), t([n({
type: String,
reflect: !0
})], u.prototype, "pattern", void 0), t([n({
type: String,
reflect: !0
})], u.prototype, "placeholder", void 0), t([n({
type: String,
reflect: !0
})], u.prototype, "id", void 0), t([n({ type: Boolean })], u.prototype, "counter", void 0), t([n({ type: Boolean })], u.prototype, "hasError", void 0), t([n({ type: Boolean })], u.prototype, "inline", void 0), t([n({ type: Boolean })], u.prototype, "hasFieldset", void 0), t([n({ type: Boolean })], u.prototype, "optionalTag", void 0), t([n({ type: Boolean })], u.prototype, "requiredTag", void 0), t([n({ type: Boolean })], u.prototype, "skipForwardTestid", void 0), t([n({
type: Boolean,
reflect: !0,
converter: a
})], u.prototype, "useWrapper", void 0), t([n({
type: Boolean,
reflect: !0
})], u.prototype, "fullwidth", void 0), t([n({ type: Number })], u.prototype, "counterMaxLength", void 0), t([n({ type: String })], u.prototype, "errorMessage", void 0), t([n({ type: String })], u.prototype, "helptext", void 0), t([n({ type: String })], u.prototype, "helptextDropdown", void 0), t([n({
type: String,
reflect: !1
})], u.prototype, "helptextDropdownButton", void 0), t([n({ type: String })], u.prototype, "label", void 0), t([n({
type: String,
reflect: !1
})], u.prototype, "optionalText", void 0), t([n({
type: String,
reflect: !1
})], u.prototype, "requiredText", void 0), t([n({
type: String,
reflect: !1
})], u.prototype, "tagText", void 0), t([n({
type: String,
attribute: "data-testid"
})], u.prototype, "dataTestid", void 0);
//#endregion
export { u as t };