@justeattakeaway/pie-switch 2.5.5 → 2.6.0
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/custom-elements.json +8 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +423 -364
- package/dist/react.d.ts +1 -0
- package/package.json +5 -5
- package/src/index.ts +12 -2
- package/src/switch.scss +21 -0
package/custom-elements.json
CHANGED
|
@@ -142,6 +142,14 @@
|
|
|
142
142
|
"attribute": "disabled",
|
|
143
143
|
"reflects": true
|
|
144
144
|
},
|
|
145
|
+
{
|
|
146
|
+
"kind": "field",
|
|
147
|
+
"name": "_contextAria",
|
|
148
|
+
"type": {
|
|
149
|
+
"text": "ContextualAria | undefined"
|
|
150
|
+
},
|
|
151
|
+
"privacy": "private"
|
|
152
|
+
},
|
|
145
153
|
{
|
|
146
154
|
"kind": "field",
|
|
147
155
|
"name": "input",
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,23 +1,76 @@
|
|
|
1
|
-
import { LitElement as
|
|
2
|
-
import { unsafeStatic as
|
|
3
|
-
import { property as
|
|
4
|
-
import { classMap as
|
|
5
|
-
import { ifDefined as
|
|
6
|
-
import { live as
|
|
7
|
-
import { AssociatedLabelMixin as
|
|
1
|
+
import { LitElement as _t, nothing as O, html as U, unsafeCSS as Nt } from "lit";
|
|
2
|
+
import { unsafeStatic as Pt, html as Ot } from "lit/static-html.js";
|
|
3
|
+
import { property as E, state as bt, query as K } from "lit/decorators.js";
|
|
4
|
+
import { classMap as ht } from "lit/directives/class-map.js";
|
|
5
|
+
import { ifDefined as ut } from "lit/directives/if-defined.js";
|
|
6
|
+
import { live as $t } from "lit/directives/live.js";
|
|
7
|
+
import { AssociatedLabelMixin as Dt, FormControlMixin as Rt, DelegatesFocusMixin as Ht, wrapNativeEvent as Wt, validPropertyValues as zt, safeCustomElement as qt, ariaContext as Bt } from "@justeattakeaway/pie-webc-core";
|
|
8
8
|
import "@justeattakeaway/pie-icons-webc/dist/IconCheck.js";
|
|
9
|
-
const
|
|
9
|
+
const $ = class $ extends _t {
|
|
10
10
|
willUpdate() {
|
|
11
|
-
this.getAttribute("v") || this.setAttribute("v",
|
|
11
|
+
this.getAttribute("v") || this.setAttribute("v", $.v);
|
|
12
12
|
}
|
|
13
13
|
};
|
|
14
|
-
|
|
15
|
-
let
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
14
|
+
$.v = "2.6.0";
|
|
15
|
+
let j = $;
|
|
16
|
+
/**
|
|
17
|
+
* @license
|
|
18
|
+
* Copyright 2021 Google LLC
|
|
19
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
20
|
+
*/
|
|
21
|
+
let Ut = class extends Event {
|
|
22
|
+
constructor(c, d, h, l) {
|
|
23
|
+
super("context-request", { bubbles: !0, composed: !0 }), this.context = c, this.contextTarget = d, this.callback = h, this.subscribe = l ?? !1;
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* @license
|
|
28
|
+
* Copyright 2021 Google LLC
|
|
29
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
30
|
+
*/
|
|
31
|
+
class pt {
|
|
32
|
+
constructor(c, d, h, l) {
|
|
33
|
+
if (this.subscribe = !1, this.provided = !1, this.value = void 0, this.t = (p, v) => {
|
|
34
|
+
this.unsubscribe && (this.unsubscribe !== v && (this.provided = !1, this.unsubscribe()), this.subscribe || this.unsubscribe()), this.value = p, this.host.requestUpdate(), this.provided && !this.subscribe || (this.provided = !0, this.callback && this.callback(p, v)), this.unsubscribe = v;
|
|
35
|
+
}, this.host = c, d.context !== void 0) {
|
|
36
|
+
const p = d;
|
|
37
|
+
this.context = p.context, this.callback = p.callback, this.subscribe = p.subscribe ?? !1;
|
|
38
|
+
} else this.context = d, this.callback = h, this.subscribe = l ?? !1;
|
|
39
|
+
this.host.addController(this);
|
|
40
|
+
}
|
|
41
|
+
hostConnected() {
|
|
42
|
+
this.dispatchRequest();
|
|
43
|
+
}
|
|
44
|
+
hostDisconnected() {
|
|
45
|
+
this.unsubscribe && (this.unsubscribe(), this.unsubscribe = void 0);
|
|
46
|
+
}
|
|
47
|
+
dispatchRequest() {
|
|
48
|
+
this.host.dispatchEvent(new Ut(this.context, this.host, this.t, this.subscribe));
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* @license
|
|
53
|
+
* Copyright 2022 Google LLC
|
|
54
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
55
|
+
*/
|
|
56
|
+
function jt({ context: s, subscribe: c }) {
|
|
57
|
+
return (d, h) => {
|
|
58
|
+
typeof h == "object" ? h.addInitializer((function() {
|
|
59
|
+
new pt(this, { context: s, callback: (l) => {
|
|
60
|
+
d.set.call(this, l);
|
|
61
|
+
}, subscribe: c });
|
|
62
|
+
})) : d.constructor.addInitializer(((l) => {
|
|
63
|
+
new pt(l, { context: s, callback: (p) => {
|
|
64
|
+
l[h] = p;
|
|
65
|
+
}, subscribe: c });
|
|
66
|
+
}));
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
var mt = {}, ft;
|
|
70
|
+
function Kt() {
|
|
71
|
+
return ft || (ft = 1, (function() {
|
|
72
|
+
(function(s) {
|
|
73
|
+
const c = /* @__PURE__ */ new WeakMap(), d = /* @__PURE__ */ new WeakMap(), h = /* @__PURE__ */ new WeakMap(), l = /* @__PURE__ */ new WeakMap(), p = /* @__PURE__ */ new WeakMap(), v = /* @__PURE__ */ new WeakMap(), C = /* @__PURE__ */ new WeakMap(), w = /* @__PURE__ */ new WeakMap(), S = /* @__PURE__ */ new WeakMap(), x = /* @__PURE__ */ new WeakMap(), A = /* @__PURE__ */ new WeakMap(), F = /* @__PURE__ */ new WeakMap(), G = /* @__PURE__ */ new WeakMap(), J = /* @__PURE__ */ new WeakMap(), V = /* @__PURE__ */ new WeakMap(), T = {
|
|
21
74
|
ariaAtomic: "aria-atomic",
|
|
22
75
|
ariaAutoComplete: "aria-autocomplete",
|
|
23
76
|
ariaBusy: "aria-busy",
|
|
@@ -60,278 +113,278 @@ function Be() {
|
|
|
60
113
|
ariaValueNow: "aria-valuenow",
|
|
61
114
|
ariaValueText: "aria-valuetext",
|
|
62
115
|
role: "role"
|
|
63
|
-
},
|
|
64
|
-
for (let i in
|
|
65
|
-
|
|
116
|
+
}, vt = (e, t) => {
|
|
117
|
+
for (let i in T) {
|
|
118
|
+
t[i] = null;
|
|
66
119
|
let a = null;
|
|
67
|
-
const r =
|
|
68
|
-
Object.defineProperty(
|
|
120
|
+
const r = T[i];
|
|
121
|
+
Object.defineProperty(t, i, {
|
|
69
122
|
get() {
|
|
70
123
|
return a;
|
|
71
124
|
},
|
|
72
125
|
set(o) {
|
|
73
|
-
a = o,
|
|
126
|
+
a = o, e.isConnected ? e.setAttribute(r, o) : x.set(e, t);
|
|
74
127
|
}
|
|
75
128
|
});
|
|
76
129
|
}
|
|
77
130
|
};
|
|
78
|
-
function Q(
|
|
79
|
-
const
|
|
80
|
-
|
|
131
|
+
function Q(e) {
|
|
132
|
+
const t = l.get(e), { form: i } = t;
|
|
133
|
+
it(e, i, t), et(e, t.labels);
|
|
81
134
|
}
|
|
82
|
-
const X = (
|
|
83
|
-
const i = document.createTreeWalker(
|
|
135
|
+
const X = (e, t = !1) => {
|
|
136
|
+
const i = document.createTreeWalker(e, NodeFilter.SHOW_ELEMENT, {
|
|
84
137
|
acceptNode(o) {
|
|
85
|
-
return
|
|
138
|
+
return l.has(o) ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP;
|
|
86
139
|
}
|
|
87
140
|
});
|
|
88
141
|
let a = i.nextNode();
|
|
89
|
-
const r = !
|
|
142
|
+
const r = !t || e.disabled;
|
|
90
143
|
for (; a; )
|
|
91
|
-
a.formDisabledCallback && r &&
|
|
92
|
-
}, Y = { attributes: !0, attributeFilter: ["disabled", "name"] },
|
|
93
|
-
for (const
|
|
94
|
-
const i =
|
|
95
|
-
if (
|
|
96
|
-
const a =
|
|
144
|
+
a.formDisabledCallback && r && H(a, e.disabled), a = i.nextNode();
|
|
145
|
+
}, Y = { attributes: !0, attributeFilter: ["disabled", "name"] }, L = P() ? new MutationObserver((e) => {
|
|
146
|
+
for (const t of e) {
|
|
147
|
+
const i = t.target;
|
|
148
|
+
if (t.attributeName === "disabled" && (i.constructor.formAssociated ? H(i, i.hasAttribute("disabled")) : i.localName === "fieldset" && X(i)), t.attributeName === "name" && i.constructor.formAssociated) {
|
|
149
|
+
const a = l.get(i), r = S.get(i);
|
|
97
150
|
a.setFormValue(r);
|
|
98
151
|
}
|
|
99
152
|
}
|
|
100
153
|
}) : {};
|
|
101
|
-
function
|
|
102
|
-
|
|
103
|
-
const { addedNodes: i, removedNodes: a } =
|
|
104
|
-
r.forEach((
|
|
105
|
-
var
|
|
106
|
-
if (
|
|
107
|
-
const
|
|
108
|
-
Object.keys(
|
|
109
|
-
|
|
110
|
-
}),
|
|
154
|
+
function D(e) {
|
|
155
|
+
e.forEach((t) => {
|
|
156
|
+
const { addedNodes: i, removedNodes: a } = t, r = Array.from(i), o = Array.from(a);
|
|
157
|
+
r.forEach((n) => {
|
|
158
|
+
var f;
|
|
159
|
+
if (l.has(n) && n.constructor.formAssociated && Q(n), x.has(n)) {
|
|
160
|
+
const u = x.get(n);
|
|
161
|
+
Object.keys(T).filter((g) => u[g] !== null).forEach((g) => {
|
|
162
|
+
n.setAttribute(T[g], u[g]);
|
|
163
|
+
}), x.delete(n);
|
|
111
164
|
}
|
|
112
|
-
if (
|
|
113
|
-
const
|
|
114
|
-
|
|
165
|
+
if (V.has(n)) {
|
|
166
|
+
const u = V.get(n);
|
|
167
|
+
n.setAttribute("internals-valid", u.validity.valid.toString()), n.setAttribute("internals-invalid", (!u.validity.valid).toString()), n.setAttribute("aria-invalid", (!u.validity.valid).toString()), V.delete(n);
|
|
115
168
|
}
|
|
116
|
-
if (
|
|
117
|
-
const
|
|
118
|
-
acceptNode(
|
|
119
|
-
return
|
|
169
|
+
if (n.localName === "form") {
|
|
170
|
+
const u = w.get(n), k = document.createTreeWalker(n, NodeFilter.SHOW_ELEMENT, {
|
|
171
|
+
acceptNode(B) {
|
|
172
|
+
return l.has(B) && B.constructor.formAssociated && !(u && u.has(B)) ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP;
|
|
120
173
|
}
|
|
121
174
|
});
|
|
122
|
-
let
|
|
123
|
-
for (;
|
|
124
|
-
Q(
|
|
175
|
+
let g = k.nextNode();
|
|
176
|
+
for (; g; )
|
|
177
|
+
Q(g), g = k.nextNode();
|
|
125
178
|
}
|
|
126
|
-
|
|
127
|
-
}), o.forEach((
|
|
128
|
-
const
|
|
129
|
-
|
|
179
|
+
n.localName === "fieldset" && ((f = L.observe) === null || f === void 0 || f.call(L, n, Y), X(n, !0));
|
|
180
|
+
}), o.forEach((n) => {
|
|
181
|
+
const f = l.get(n);
|
|
182
|
+
f && h.get(f) && Z(f), C.has(n) && C.get(n).disconnect();
|
|
130
183
|
});
|
|
131
184
|
});
|
|
132
185
|
}
|
|
133
|
-
function
|
|
134
|
-
|
|
135
|
-
const { removedNodes: i } =
|
|
186
|
+
function wt(e) {
|
|
187
|
+
e.forEach((t) => {
|
|
188
|
+
const { removedNodes: i } = t;
|
|
136
189
|
i.forEach((a) => {
|
|
137
|
-
const r = G.get(
|
|
138
|
-
|
|
190
|
+
const r = G.get(t.target);
|
|
191
|
+
l.has(a) && rt(a), r.disconnect();
|
|
139
192
|
});
|
|
140
193
|
});
|
|
141
194
|
}
|
|
142
|
-
const
|
|
143
|
-
var
|
|
144
|
-
const a = new MutationObserver(
|
|
145
|
-
!((
|
|
195
|
+
const gt = (e) => {
|
|
196
|
+
var t, i;
|
|
197
|
+
const a = new MutationObserver(wt);
|
|
198
|
+
!((t = window == null ? void 0 : window.ShadyDOM) === null || t === void 0) && t.inUse && e.mode && e.host && (e = e.host), (i = a.observe) === null || i === void 0 || i.call(a, e, { childList: !0 }), G.set(e, a);
|
|
146
199
|
};
|
|
147
|
-
|
|
148
|
-
const
|
|
200
|
+
P() && new MutationObserver(D);
|
|
201
|
+
const R = {
|
|
149
202
|
childList: !0,
|
|
150
203
|
subtree: !0
|
|
151
|
-
},
|
|
152
|
-
|
|
153
|
-
}, Z = (
|
|
154
|
-
|
|
204
|
+
}, H = (e, t) => {
|
|
205
|
+
e.toggleAttribute("internals-disabled", t), t ? e.setAttribute("aria-disabled", "true") : e.removeAttribute("aria-disabled"), e.formDisabledCallback && e.formDisabledCallback.apply(e, [t]);
|
|
206
|
+
}, Z = (e) => {
|
|
207
|
+
h.get(e).forEach((i) => {
|
|
155
208
|
i.remove();
|
|
156
|
-
}),
|
|
157
|
-
},
|
|
209
|
+
}), h.set(e, []);
|
|
210
|
+
}, tt = (e, t) => {
|
|
158
211
|
const i = document.createElement("input");
|
|
159
|
-
return i.type = "hidden", i.name =
|
|
160
|
-
},
|
|
212
|
+
return i.type = "hidden", i.name = e.getAttribute("name"), e.after(i), h.get(t).push(i), i;
|
|
213
|
+
}, yt = (e, t) => {
|
|
161
214
|
var i;
|
|
162
|
-
|
|
163
|
-
},
|
|
164
|
-
if (
|
|
165
|
-
Array.from(
|
|
166
|
-
let i =
|
|
167
|
-
|
|
168
|
-
}
|
|
169
|
-
},
|
|
170
|
-
const
|
|
171
|
-
|
|
172
|
-
},
|
|
173
|
-
|
|
174
|
-
},
|
|
175
|
-
|
|
176
|
-
},
|
|
177
|
-
const
|
|
178
|
-
|
|
179
|
-
if (i.target.closest(
|
|
180
|
-
const r =
|
|
181
|
-
if (
|
|
215
|
+
h.set(t, []), (i = L.observe) === null || i === void 0 || i.call(L, e, Y);
|
|
216
|
+
}, et = (e, t) => {
|
|
217
|
+
if (t.length) {
|
|
218
|
+
Array.from(t).forEach((a) => a.addEventListener("click", e.click.bind(e)));
|
|
219
|
+
let i = t[0].id;
|
|
220
|
+
t[0].id || (i = `${t[0].htmlFor}_Label`, t[0].id = i), e.setAttribute("aria-labelledby", i);
|
|
221
|
+
}
|
|
222
|
+
}, _ = (e) => {
|
|
223
|
+
const t = Array.from(e.elements).filter((o) => !o.tagName.includes("-") && o.validity).map((o) => o.validity.valid), i = w.get(e) || [], a = Array.from(i).filter((o) => o.isConnected).map((o) => l.get(o).validity.valid), r = [...t, ...a].includes(!1);
|
|
224
|
+
e.toggleAttribute("internals-invalid", r), e.toggleAttribute("internals-valid", !r);
|
|
225
|
+
}, kt = (e) => {
|
|
226
|
+
_(N(e.target));
|
|
227
|
+
}, Et = (e) => {
|
|
228
|
+
_(N(e.target));
|
|
229
|
+
}, xt = (e) => {
|
|
230
|
+
const t = ["button[type=submit]", "input[type=submit]", "button:not([type])"].map((i) => `${i}:not([disabled])`).map((i) => `${i}:not([form])${e.id ? `,${i}[form='${e.id}']` : ""}`).join(",");
|
|
231
|
+
e.addEventListener("click", (i) => {
|
|
232
|
+
if (i.target.closest(t)) {
|
|
233
|
+
const r = w.get(e);
|
|
234
|
+
if (e.noValidate)
|
|
182
235
|
return;
|
|
183
|
-
r.size && Array.from(r).reverse().map((
|
|
236
|
+
r.size && Array.from(r).reverse().map((f) => l.get(f).reportValidity()).includes(!1) && i.preventDefault();
|
|
184
237
|
}
|
|
185
238
|
});
|
|
186
|
-
},
|
|
187
|
-
const
|
|
188
|
-
|
|
239
|
+
}, Mt = (e) => {
|
|
240
|
+
const t = w.get(e.target);
|
|
241
|
+
t && t.size && t.forEach((i) => {
|
|
189
242
|
i.constructor.formAssociated && i.formResetCallback && i.formResetCallback.apply(i);
|
|
190
243
|
});
|
|
191
|
-
},
|
|
192
|
-
if (
|
|
193
|
-
const a =
|
|
244
|
+
}, it = (e, t, i) => {
|
|
245
|
+
if (t) {
|
|
246
|
+
const a = w.get(t);
|
|
194
247
|
if (a)
|
|
195
|
-
a.add(
|
|
248
|
+
a.add(e);
|
|
196
249
|
else {
|
|
197
250
|
const r = /* @__PURE__ */ new Set();
|
|
198
|
-
r.add(
|
|
251
|
+
r.add(e), w.set(t, r), xt(t), t.addEventListener("reset", Mt), t.addEventListener("input", kt), t.addEventListener("change", Et);
|
|
199
252
|
}
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
}, 0),
|
|
203
|
-
}
|
|
204
|
-
},
|
|
205
|
-
let
|
|
206
|
-
return
|
|
207
|
-
},
|
|
208
|
-
if (!
|
|
209
|
-
throw new i(
|
|
210
|
-
},
|
|
211
|
-
const a =
|
|
253
|
+
v.set(t, { ref: e, internals: i }), e.constructor.formAssociated && e.formAssociatedCallback && setTimeout(() => {
|
|
254
|
+
e.formAssociatedCallback.apply(e, [t]);
|
|
255
|
+
}, 0), _(t);
|
|
256
|
+
}
|
|
257
|
+
}, N = (e) => {
|
|
258
|
+
let t = e.parentNode;
|
|
259
|
+
return t && t.tagName !== "FORM" && (t = N(t)), t;
|
|
260
|
+
}, y = (e, t, i = DOMException) => {
|
|
261
|
+
if (!e.constructor.formAssociated)
|
|
262
|
+
throw new i(t);
|
|
263
|
+
}, at = (e, t, i) => {
|
|
264
|
+
const a = w.get(e);
|
|
212
265
|
return a && a.size && a.forEach((r) => {
|
|
213
|
-
|
|
214
|
-
}),
|
|
215
|
-
},
|
|
216
|
-
if (
|
|
217
|
-
const
|
|
218
|
-
|
|
266
|
+
l.get(r)[i]() || (t = !1);
|
|
267
|
+
}), t;
|
|
268
|
+
}, rt = (e) => {
|
|
269
|
+
if (e.constructor.formAssociated) {
|
|
270
|
+
const t = l.get(e), { labels: i, form: a } = t;
|
|
271
|
+
et(e, i), it(e, a, t);
|
|
219
272
|
}
|
|
220
273
|
};
|
|
221
|
-
function
|
|
274
|
+
function P() {
|
|
222
275
|
return typeof MutationObserver < "u";
|
|
223
276
|
}
|
|
224
|
-
class
|
|
277
|
+
class Ct {
|
|
225
278
|
constructor() {
|
|
226
279
|
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);
|
|
227
280
|
}
|
|
228
281
|
}
|
|
229
|
-
const
|
|
230
|
-
let
|
|
231
|
-
for (let i in
|
|
232
|
-
i !== "valid" &&
|
|
233
|
-
return
|
|
234
|
-
},
|
|
235
|
-
function
|
|
236
|
-
|
|
282
|
+
const At = (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), Ft = (e, t, i) => (e.valid = It(t), Object.keys(t).forEach((a) => e[a] = t[a]), i && _(i), e), It = (e) => {
|
|
283
|
+
let t = !0;
|
|
284
|
+
for (let i in e)
|
|
285
|
+
i !== "valid" && e[i] !== !1 && (t = !1);
|
|
286
|
+
return t;
|
|
287
|
+
}, W = /* @__PURE__ */ new WeakMap();
|
|
288
|
+
function st(e, t) {
|
|
289
|
+
e.toggleAttribute(t, !0), e.part && e.part.add(t);
|
|
237
290
|
}
|
|
238
|
-
class
|
|
291
|
+
class z extends Set {
|
|
239
292
|
static get isPolyfilled() {
|
|
240
293
|
return !0;
|
|
241
294
|
}
|
|
242
|
-
constructor(
|
|
243
|
-
if (super(), !
|
|
295
|
+
constructor(t) {
|
|
296
|
+
if (super(), !t || !t.tagName || t.tagName.indexOf("-") === -1)
|
|
244
297
|
throw new TypeError("Illegal constructor");
|
|
245
|
-
|
|
246
|
-
}
|
|
247
|
-
add(
|
|
248
|
-
if (!/^--/.test(
|
|
249
|
-
throw new DOMException(`Failed to execute 'add' on 'CustomStateSet': The specified value ${
|
|
250
|
-
const i = super.add(
|
|
251
|
-
return a.isConnected ?
|
|
252
|
-
|
|
298
|
+
W.set(this, t);
|
|
299
|
+
}
|
|
300
|
+
add(t) {
|
|
301
|
+
if (!/^--/.test(t) || typeof t != "string")
|
|
302
|
+
throw new DOMException(`Failed to execute 'add' on 'CustomStateSet': The specified value ${t} must start with '--'.`);
|
|
303
|
+
const i = super.add(t), a = W.get(this), r = `state${t}`;
|
|
304
|
+
return a.isConnected ? st(a, r) : setTimeout(() => {
|
|
305
|
+
st(a, r);
|
|
253
306
|
}), i;
|
|
254
307
|
}
|
|
255
308
|
clear() {
|
|
256
|
-
for (let [
|
|
257
|
-
this.delete(
|
|
309
|
+
for (let [t] of this.entries())
|
|
310
|
+
this.delete(t);
|
|
258
311
|
super.clear();
|
|
259
312
|
}
|
|
260
|
-
delete(
|
|
261
|
-
const i = super.delete(
|
|
262
|
-
return a.isConnected ? (a.toggleAttribute(`state${
|
|
263
|
-
a.toggleAttribute(`state${
|
|
313
|
+
delete(t) {
|
|
314
|
+
const i = super.delete(t), a = W.get(this);
|
|
315
|
+
return a.isConnected ? (a.toggleAttribute(`state${t}`, !1), a.part && a.part.remove(`state${t}`)) : setTimeout(() => {
|
|
316
|
+
a.toggleAttribute(`state${t}`, !1), a.part && a.part.remove(`state${t}`);
|
|
264
317
|
}), i;
|
|
265
318
|
}
|
|
266
319
|
}
|
|
267
|
-
function
|
|
268
|
-
if (typeof
|
|
269
|
-
return i === "m" ? a : i === "a" ? a.call(
|
|
320
|
+
function ot(e, t, i, a) {
|
|
321
|
+
if (typeof t == "function" ? e !== t || !a : !t.has(e)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
322
|
+
return i === "m" ? a : i === "a" ? a.call(e) : a ? a.value : t.get(e);
|
|
270
323
|
}
|
|
271
|
-
function
|
|
272
|
-
if (typeof
|
|
273
|
-
return
|
|
324
|
+
function St(e, t, i, a, r) {
|
|
325
|
+
if (typeof t == "function" ? e !== t || !0 : !t.has(e)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
326
|
+
return t.set(e, i), i;
|
|
274
327
|
}
|
|
275
|
-
var
|
|
276
|
-
class
|
|
277
|
-
constructor(
|
|
278
|
-
|
|
279
|
-
for (let i = 0; i <
|
|
280
|
-
let a =
|
|
328
|
+
var I;
|
|
329
|
+
class Vt {
|
|
330
|
+
constructor(t) {
|
|
331
|
+
I.set(this, void 0), St(this, I, t);
|
|
332
|
+
for (let i = 0; i < t.length; i++) {
|
|
333
|
+
let a = t[i];
|
|
281
334
|
this[i] = a, a.hasAttribute("name") && (this[a.getAttribute("name")] = a);
|
|
282
335
|
}
|
|
283
336
|
Object.freeze(this);
|
|
284
337
|
}
|
|
285
338
|
get length() {
|
|
286
|
-
return
|
|
339
|
+
return ot(this, I, "f").length;
|
|
287
340
|
}
|
|
288
|
-
[(
|
|
289
|
-
return
|
|
341
|
+
[(I = /* @__PURE__ */ new WeakMap(), Symbol.iterator)]() {
|
|
342
|
+
return ot(this, I, "f")[Symbol.iterator]();
|
|
290
343
|
}
|
|
291
|
-
item(
|
|
292
|
-
return this[
|
|
344
|
+
item(t) {
|
|
345
|
+
return this[t] == null ? null : this[t];
|
|
293
346
|
}
|
|
294
|
-
namedItem(
|
|
295
|
-
return this[
|
|
347
|
+
namedItem(t) {
|
|
348
|
+
return this[t] == null ? null : this[t];
|
|
296
349
|
}
|
|
297
350
|
}
|
|
298
|
-
function
|
|
299
|
-
const
|
|
351
|
+
function Tt() {
|
|
352
|
+
const e = HTMLFormElement.prototype.checkValidity;
|
|
300
353
|
HTMLFormElement.prototype.checkValidity = i;
|
|
301
|
-
const
|
|
354
|
+
const t = HTMLFormElement.prototype.reportValidity;
|
|
302
355
|
HTMLFormElement.prototype.reportValidity = a;
|
|
303
356
|
function i(...o) {
|
|
304
|
-
let
|
|
305
|
-
return
|
|
357
|
+
let n = e.apply(this, o);
|
|
358
|
+
return at(this, n, "checkValidity");
|
|
306
359
|
}
|
|
307
360
|
function a(...o) {
|
|
308
|
-
let
|
|
309
|
-
return
|
|
361
|
+
let n = t.apply(this, o);
|
|
362
|
+
return at(this, n, "reportValidity");
|
|
310
363
|
}
|
|
311
364
|
const { get: r } = Object.getOwnPropertyDescriptor(HTMLFormElement.prototype, "elements");
|
|
312
365
|
Object.defineProperty(HTMLFormElement.prototype, "elements", {
|
|
313
366
|
get(...o) {
|
|
314
|
-
const
|
|
315
|
-
if (
|
|
316
|
-
return
|
|
317
|
-
const
|
|
318
|
-
return new
|
|
367
|
+
const n = r.call(this, ...o), f = Array.from(w.get(this) || []);
|
|
368
|
+
if (f.length === 0)
|
|
369
|
+
return n;
|
|
370
|
+
const u = Array.from(n).concat(f).sort((k, g) => k.compareDocumentPosition ? k.compareDocumentPosition(g) & 2 ? 1 : -1 : 0);
|
|
371
|
+
return new Vt(u);
|
|
319
372
|
}
|
|
320
373
|
});
|
|
321
374
|
}
|
|
322
|
-
class
|
|
375
|
+
class nt {
|
|
323
376
|
static get isPolyfilled() {
|
|
324
377
|
return !0;
|
|
325
378
|
}
|
|
326
|
-
constructor(
|
|
327
|
-
if (!
|
|
379
|
+
constructor(t) {
|
|
380
|
+
if (!t || !t.tagName || t.tagName.indexOf("-") === -1)
|
|
328
381
|
throw new TypeError("Illegal constructor");
|
|
329
|
-
const i =
|
|
330
|
-
this.states = new
|
|
382
|
+
const i = t.getRootNode(), a = new Ct();
|
|
383
|
+
this.states = new z(t), c.set(this, t), d.set(this, a), l.set(t, this), vt(t, this), yt(t, this), Object.seal(this), i instanceof DocumentFragment && gt(i);
|
|
331
384
|
}
|
|
332
385
|
checkValidity() {
|
|
333
|
-
const
|
|
334
|
-
if (
|
|
386
|
+
const t = c.get(this);
|
|
387
|
+
if (y(t, "Failed to execute 'checkValidity' on 'ElementInternals': The target element is not a form-associated custom element."), !this.willValidate)
|
|
335
388
|
return !0;
|
|
336
389
|
const i = d.get(this);
|
|
337
390
|
if (!i.valid) {
|
|
@@ -340,90 +393,90 @@ function Be() {
|
|
|
340
393
|
cancelable: !0,
|
|
341
394
|
composed: !1
|
|
342
395
|
});
|
|
343
|
-
|
|
396
|
+
t.dispatchEvent(a);
|
|
344
397
|
}
|
|
345
398
|
return i.valid;
|
|
346
399
|
}
|
|
347
400
|
get form() {
|
|
348
|
-
const
|
|
349
|
-
|
|
401
|
+
const t = c.get(this);
|
|
402
|
+
y(t, "Failed to read the 'form' property from 'ElementInternals': The target element is not a form-associated custom element.");
|
|
350
403
|
let i;
|
|
351
|
-
return
|
|
404
|
+
return t.constructor.formAssociated === !0 && (i = N(t)), i;
|
|
352
405
|
}
|
|
353
406
|
get labels() {
|
|
354
|
-
const
|
|
355
|
-
|
|
356
|
-
const i =
|
|
407
|
+
const t = c.get(this);
|
|
408
|
+
y(t, "Failed to read the 'labels' property from 'ElementInternals': The target element is not a form-associated custom element.");
|
|
409
|
+
const i = t.getAttribute("id"), a = t.getRootNode();
|
|
357
410
|
return a && i ? a.querySelectorAll(`[for="${i}"]`) : [];
|
|
358
411
|
}
|
|
359
412
|
reportValidity() {
|
|
360
|
-
const
|
|
361
|
-
if (
|
|
413
|
+
const t = c.get(this);
|
|
414
|
+
if (y(t, "Failed to execute 'reportValidity' on 'ElementInternals': The target element is not a form-associated custom element."), !this.willValidate)
|
|
362
415
|
return !0;
|
|
363
|
-
const i = this.checkValidity(), a =
|
|
364
|
-
if (a && !
|
|
416
|
+
const i = this.checkValidity(), a = F.get(this);
|
|
417
|
+
if (a && !t.constructor.formAssociated)
|
|
365
418
|
throw new DOMException("Failed to execute 'reportValidity' on 'ElementInternals': The target element is not a form-associated custom element.");
|
|
366
|
-
return !i && a && (
|
|
419
|
+
return !i && a && (t.focus(), a.focus()), i;
|
|
367
420
|
}
|
|
368
|
-
setFormValue(
|
|
369
|
-
const i =
|
|
370
|
-
if (
|
|
421
|
+
setFormValue(t) {
|
|
422
|
+
const i = c.get(this);
|
|
423
|
+
if (y(i, "Failed to execute 'setFormValue' on 'ElementInternals': The target element is not a form-associated custom element."), Z(this), t != null && !(t instanceof FormData)) {
|
|
371
424
|
if (i.getAttribute("name")) {
|
|
372
|
-
const a =
|
|
373
|
-
a.value =
|
|
425
|
+
const a = tt(i, this);
|
|
426
|
+
a.value = t;
|
|
374
427
|
}
|
|
375
|
-
} else
|
|
428
|
+
} else t != null && t instanceof FormData && Array.from(t).reverse().forEach(([a, r]) => {
|
|
376
429
|
if (typeof r == "string") {
|
|
377
|
-
const o =
|
|
430
|
+
const o = tt(i, this);
|
|
378
431
|
o.name = a, o.value = r;
|
|
379
432
|
}
|
|
380
433
|
});
|
|
381
|
-
|
|
434
|
+
S.set(i, t);
|
|
382
435
|
}
|
|
383
|
-
setValidity(
|
|
384
|
-
const r =
|
|
385
|
-
if (
|
|
436
|
+
setValidity(t, i, a) {
|
|
437
|
+
const r = c.get(this);
|
|
438
|
+
if (y(r, "Failed to execute 'setValidity' on 'ElementInternals': The target element is not a form-associated custom element."), !t)
|
|
386
439
|
throw new TypeError("Failed to execute 'setValidity' on 'ElementInternals': 1 argument required, but only 0 present.");
|
|
387
|
-
|
|
388
|
-
const o = d.get(this),
|
|
389
|
-
for (const
|
|
390
|
-
|
|
391
|
-
Object.keys(
|
|
392
|
-
const
|
|
393
|
-
delete
|
|
394
|
-
const { valid:
|
|
395
|
-
if (!
|
|
440
|
+
F.set(this, a);
|
|
441
|
+
const o = d.get(this), n = {};
|
|
442
|
+
for (const k in t)
|
|
443
|
+
n[k] = t[k];
|
|
444
|
+
Object.keys(n).length === 0 && At(o);
|
|
445
|
+
const f = Object.assign(Object.assign({}, o), n);
|
|
446
|
+
delete f.valid;
|
|
447
|
+
const { valid: u } = Ft(o, f, this.form);
|
|
448
|
+
if (!u && !i)
|
|
396
449
|
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.");
|
|
397
|
-
|
|
450
|
+
p.set(this, u ? "" : i), r.isConnected ? (r.toggleAttribute("internals-invalid", !u), r.toggleAttribute("internals-valid", u), r.setAttribute("aria-invalid", `${!u}`)) : V.set(r, this);
|
|
398
451
|
}
|
|
399
452
|
get shadowRoot() {
|
|
400
|
-
const
|
|
453
|
+
const t = c.get(this), i = A.get(t);
|
|
401
454
|
return i || null;
|
|
402
455
|
}
|
|
403
456
|
get validationMessage() {
|
|
404
|
-
const
|
|
405
|
-
return
|
|
457
|
+
const t = c.get(this);
|
|
458
|
+
return y(t, "Failed to read the 'validationMessage' property from 'ElementInternals': The target element is not a form-associated custom element."), p.get(this);
|
|
406
459
|
}
|
|
407
460
|
get validity() {
|
|
408
|
-
const
|
|
409
|
-
return
|
|
461
|
+
const t = c.get(this);
|
|
462
|
+
return y(t, "Failed to read the 'validity' property from 'ElementInternals': The target element is not a form-associated custom element."), d.get(this);
|
|
410
463
|
}
|
|
411
464
|
get willValidate() {
|
|
412
|
-
const
|
|
413
|
-
return
|
|
465
|
+
const t = c.get(this);
|
|
466
|
+
return y(t, "Failed to read the 'willValidate' property from 'ElementInternals': The target element is not a form-associated custom element."), !(t.disabled || t.hasAttribute("disabled") || t.hasAttribute("readonly"));
|
|
414
467
|
}
|
|
415
468
|
}
|
|
416
|
-
function
|
|
469
|
+
function Lt() {
|
|
417
470
|
if (typeof window > "u" || !window.ElementInternals || !HTMLElement.prototype.attachInternals)
|
|
418
471
|
return !1;
|
|
419
|
-
class
|
|
472
|
+
class e extends HTMLElement {
|
|
420
473
|
constructor() {
|
|
421
474
|
super(), this.internals = this.attachInternals();
|
|
422
475
|
}
|
|
423
476
|
}
|
|
424
|
-
const
|
|
425
|
-
customElements.define(
|
|
426
|
-
const i = new
|
|
477
|
+
const t = `element-internals-feature-detection-${Math.random().toString(36).replace(/[^a-z]+/g, "")}`;
|
|
478
|
+
customElements.define(t, e);
|
|
479
|
+
const i = new e();
|
|
427
480
|
return [
|
|
428
481
|
"shadowRoot",
|
|
429
482
|
"form",
|
|
@@ -437,25 +490,25 @@ function Be() {
|
|
|
437
490
|
"reportValidity"
|
|
438
491
|
].every((a) => a in i.internals);
|
|
439
492
|
}
|
|
440
|
-
let
|
|
441
|
-
function
|
|
442
|
-
|
|
443
|
-
const i =
|
|
444
|
-
return i.states = new
|
|
493
|
+
let ct = !1, lt = !1;
|
|
494
|
+
function q(e) {
|
|
495
|
+
lt || (lt = !0, window.CustomStateSet = z, e && (HTMLElement.prototype.attachInternals = function(...t) {
|
|
496
|
+
const i = e.call(this, t);
|
|
497
|
+
return i.states = new z(this), i;
|
|
445
498
|
}));
|
|
446
499
|
}
|
|
447
|
-
function
|
|
448
|
-
if (!
|
|
449
|
-
if (
|
|
450
|
-
const
|
|
500
|
+
function dt(e = !0) {
|
|
501
|
+
if (!ct) {
|
|
502
|
+
if (ct = !0, typeof window < "u" && (window.ElementInternals = nt), typeof CustomElementRegistry < "u") {
|
|
503
|
+
const t = CustomElementRegistry.prototype.define;
|
|
451
504
|
CustomElementRegistry.prototype.define = function(i, a, r) {
|
|
452
505
|
if (a.formAssociated) {
|
|
453
506
|
const o = a.prototype.connectedCallback;
|
|
454
507
|
a.prototype.connectedCallback = function() {
|
|
455
|
-
J.has(this) || (J.set(this, !0), this.hasAttribute("disabled") &&
|
|
508
|
+
J.has(this) || (J.set(this, !0), this.hasAttribute("disabled") && H(this, !0)), o != null && o.apply(this), rt(this);
|
|
456
509
|
};
|
|
457
510
|
}
|
|
458
|
-
|
|
511
|
+
t.call(this, i, a, r);
|
|
459
512
|
};
|
|
460
513
|
}
|
|
461
514
|
if (typeof HTMLElement < "u" && (HTMLElement.prototype.attachInternals = function() {
|
|
@@ -463,30 +516,30 @@ function Be() {
|
|
|
463
516
|
if (this.tagName.indexOf("-") === -1)
|
|
464
517
|
throw new Error("Failed to execute 'attachInternals' on 'HTMLElement': Unable to attach ElementInternals to non-custom elements.");
|
|
465
518
|
} else return {};
|
|
466
|
-
if (
|
|
519
|
+
if (l.has(this))
|
|
467
520
|
throw new DOMException("DOMException: Failed to execute 'attachInternals' on 'HTMLElement': ElementInternals for the specified element was already attached.");
|
|
468
|
-
return new
|
|
521
|
+
return new nt(this);
|
|
469
522
|
}), typeof Element < "u") {
|
|
470
|
-
let
|
|
523
|
+
let t = function(...a) {
|
|
471
524
|
const r = i.apply(this, a);
|
|
472
|
-
if (
|
|
473
|
-
const o = new MutationObserver(
|
|
474
|
-
window.ShadyDOM ? o.observe(this,
|
|
525
|
+
if (A.set(this, r), P()) {
|
|
526
|
+
const o = new MutationObserver(D);
|
|
527
|
+
window.ShadyDOM ? o.observe(this, R) : o.observe(r, R), C.set(this, o);
|
|
475
528
|
}
|
|
476
529
|
return r;
|
|
477
530
|
};
|
|
478
531
|
const i = Element.prototype.attachShadow;
|
|
479
|
-
Element.prototype.attachShadow =
|
|
532
|
+
Element.prototype.attachShadow = t;
|
|
480
533
|
}
|
|
481
|
-
|
|
534
|
+
P() && typeof document < "u" && new MutationObserver(D).observe(document.documentElement, R), typeof HTMLFormElement < "u" && Tt(), (e || typeof window < "u" && !window.CustomStateSet) && q();
|
|
482
535
|
}
|
|
483
536
|
}
|
|
484
|
-
return !!customElements.polyfillWrapFlushCallback || (
|
|
537
|
+
return !!customElements.polyfillWrapFlushCallback || (Lt() ? typeof window < "u" && !window.CustomStateSet && q(HTMLElement.prototype.attachInternals) : dt(!1)), s.forceCustomStateSetPolyfill = q, s.forceElementInternalsPolyfill = dt, Object.defineProperty(s, "__esModule", { value: !0 }), s;
|
|
485
538
|
})({});
|
|
486
|
-
})()),
|
|
539
|
+
})()), mt;
|
|
487
540
|
}
|
|
488
|
-
|
|
489
|
-
const
|
|
541
|
+
Kt();
|
|
542
|
+
const Gt = "*,*:after,*:before{box-sizing:inherit}:host{display:block}*,*:before,*:after{cursor:inherit}.c-switch-wrapper{display:inline-flex;align-items:center;gap:var(--dt-spacing-b);vertical-align:top;font-family:var(--dt-font-body-l-family);cursor:pointer}.c-switch-wrapper[disabled]{cursor:not-allowed}.c-switch{--int-states-mixin-bg-color: var(--dt-color-interactive-form);--switch-bg-color--checked: var(--dt-color-interactive-brand);--switch-bg-color--disabled: var(--dt-color-disabled-01);--switch-width: 48px;--switch-height: 24px;--switch-control-size: 20px;--switch-padding: 2px;--switch-radius: var(--dt-radius-rounded-e);--switch-translation: calc(var(--switch-width) - var(--switch-control-size) - 2 * var(--switch-padding));position:relative;display:flex;width:var(--switch-width);height:var(--switch-height);flex-shrink:0;padding:var(--switch-padding);border-radius:var(--switch-radius);background-color:var(--int-states-mixin-bg-color)}@media(hover:hover){.c-switch:hover:not(:disabled,.is-disabled,.is-dismissible){--hover-modifier: calc(-1 * var(--dt-color-hover-01));--int-states-mixin-bg-color: hsl(var(--dt-color-interactive-form-h), var(--dt-color-interactive-form-s), calc(var(--dt-color-interactive-form-l) + var(--hover-modifier)))}}.c-switch:active:not(:disabled,.is-disabled,.is-dismissible),.c-switch.is-loading:not(:disabled,.is-disabled){--active-modifier: calc(-1 * var(--dt-color-active-01));--int-states-mixin-bg-color: hsl(var(--dt-color-interactive-form-h), var(--dt-color-interactive-form-s), calc(var(--dt-color-interactive-form-l) + var(--active-modifier)))}@supports (background-color: color-mix(in srgb,black,white)){@media(hover:hover){.c-switch:hover:not(:disabled,.is-disabled,.is-dismissible){--int-states-mixin-bg-color: color-mix(in srgb, var(--dt-color-hover-01-bg) var(--dt-color-hover-01), var(--dt-color-interactive-form))}}.c-switch:active:not(:disabled,.is-disabled,.is-dismissible),.c-switch.is-loading:not(:disabled,.is-disabled){--int-states-mixin-bg-color: color-mix(in srgb, var(--dt-color-active-01-bg) var(--dt-color-active-01), var(--dt-color-interactive-form))}}.c-switch[checked]{--int-states-mixin-bg-color: var(--dt-color-interactive-brand)}@media(hover:hover){.c-switch[checked]:hover:not(:disabled,.is-disabled,.is-dismissible){--hover-modifier: calc(-1 * var(--dt-color-hover-01));--int-states-mixin-bg-color: hsl(var(--dt-color-interactive-brand-h), var(--dt-color-interactive-brand-s), calc(var(--dt-color-interactive-brand-l) + var(--hover-modifier)))}}.c-switch[checked]:active:not(:disabled,.is-disabled,.is-dismissible),.c-switch[checked].is-loading:not(:disabled,.is-disabled){--active-modifier: calc(-1 * var(--dt-color-active-01));--int-states-mixin-bg-color: hsl(var(--dt-color-interactive-brand-h), var(--dt-color-interactive-brand-s), calc(var(--dt-color-interactive-brand-l) + var(--active-modifier)))}@supports (background-color: color-mix(in srgb,black,white)){@media(hover:hover){.c-switch[checked]:hover:not(:disabled,.is-disabled,.is-dismissible){--int-states-mixin-bg-color: color-mix(in srgb, var(--dt-color-hover-01-bg) var(--dt-color-hover-01), var(--dt-color-interactive-brand))}}.c-switch[checked]:active:not(:disabled,.is-disabled,.is-dismissible),.c-switch[checked].is-loading:not(:disabled,.is-disabled){--int-states-mixin-bg-color: color-mix(in srgb, var(--dt-color-active-01-bg) var(--dt-color-active-01), var(--dt-color-interactive-brand))}}[disabled] .c-switch{--int-states-mixin-bg-color: var(--switch-bg-color--disabled);pointer-events:none}.c-switch:has(.c-switch-input:focus-visible){box-shadow:0 0 0 2px var(--dt-color-focus-inner),0 0 0 4px var(--dt-color-focus-outer);outline:none}.c-switch--in-interactive-container{background-image:linear-gradient(var(--interactive-container-tint, transparent) 0 0)}.c-switch--in-interactive-container:hover:not(:disabled),.c-switch--in-interactive-container:active:not(:disabled){--int-states-mixin-bg-color: var(--dt-color-interactive-form)}.c-switch--in-interactive-container[checked]:hover:not(:disabled),.c-switch--in-interactive-container[checked]:active:not(:disabled){--int-states-mixin-bg-color: var(--dt-color-interactive-brand)}.c-switch-input{position:absolute;display:block;height:1px;width:1px;border:0;padding:0;margin:-1px;overflow:hidden;white-space:nowrap;clip:rect(0,0,0,0);clip-path:inset(50%)}.c-switch-input *{overflow:hidden}.c-switch-input:disabled{background-color:transparent}.c-switch-control{position:absolute;left:2px;width:var(--switch-control-size);height:var(--switch-control-size);border-radius:var(--switch-radius);background-color:var(--dt-color-interactive-light);padding:var(--switch-padding)}.c-switch-wrapper:dir(rtl) .c-switch-control{position:absolute;left:initial;right:2px}.c-switch-control .c-pieIcon--check{vertical-align:top}.c-switch[checked] .c-switch-control{transform:translate(var(--switch-translation))}.c-switch[checked] .c-switch-control .c-pieIcon--check{color:var(--dt-color-interactive-brand)}.c-switch-input:disabled~.c-switch-control{color:var(--switch-bg-color--disabled)}.c-switch-input:disabled~.c-switch-control .c-pieIcon--check{color:var(--switch-bg-color--disabled)}.c-switch-label{color:var(--dt-color-content-default-solid)}.c-switch-description{position:absolute;display:block;height:1px;width:1px;border:0;padding:0;margin:-1px;overflow:hidden;white-space:nowrap;clip:rect(0,0,0,0);clip-path:inset(50%)}.c-switch-description *{overflow:hidden}.c-switch-wrapper--label-leading{flex-direction:row-reverse}.c-switch-wrapper--label-trailing{flex-direction:row}@media(prefers-reduced-motion:no-preference){.c-switch-wrapper--allow-animation .c-switch{transition:background-color .15s cubic-bezier(.4,0,.9,1) 0s}}@media(prefers-reduced-motion:no-preference){.c-switch-wrapper--allow-animation .c-switch[checked]{transition:background-color .15s cubic-bezier(.4,0,.9,1) 0s}}@media(prefers-reduced-motion:no-preference){.c-switch-wrapper--allow-animation .c-switch-control{transition:transform .15s cubic-bezier(.4,0,.9,1) 0s}}@media(prefers-reduced-motion:no-preference){.c-switch[checked] .c-switch-wrapper--allow-animation .c-switch-control{transition:transform .15s cubic-bezier(.4,0,.9,1) 0s}}@media(prefers-reduced-motion:no-preference){.c-switch[checked] .c-switch-wrapper--allow-animation .c-switch-control .c-pieIcon--check{transition:color .15s cubic-bezier(.4,0,.9,1) 0s}}@media(prefers-reduced-motion:no-preference){.c-switch-input:disabled~.c-switch-wrapper--allow-animation .c-switch-control .c-pieIcon--check{transition:color .15s cubic-bezier(.4,0,.9,1) 0s}}.c-switch-wrapper:dir(rtl) .c-switch[checked] .c-switch-control{transform:translate(calc(-1 * var(--switch-translation)))}", Jt = ["leading", "trailing"], le = "change", M = {
|
|
490
543
|
checked: !1,
|
|
491
544
|
defaultChecked: !1,
|
|
492
545
|
disabled: !1,
|
|
@@ -494,37 +547,37 @@ const qe = "*,*:after,*:before{box-sizing:inherit}:host{display:block}*,*:before
|
|
|
494
547
|
required: !1,
|
|
495
548
|
value: "on"
|
|
496
549
|
};
|
|
497
|
-
var
|
|
498
|
-
for (var
|
|
499
|
-
(
|
|
500
|
-
return
|
|
550
|
+
var Qt = Object.defineProperty, Xt = Object.getOwnPropertyDescriptor, b = (s, c, d, h) => {
|
|
551
|
+
for (var l = h > 1 ? void 0 : h ? Xt(c, d) : c, p = s.length - 1, v; p >= 0; p--)
|
|
552
|
+
(v = s[p]) && (l = (h ? v(c, d, l) : v(l)) || l);
|
|
553
|
+
return h && l && Qt(c, d, l), l;
|
|
501
554
|
};
|
|
502
|
-
const
|
|
503
|
-
let
|
|
555
|
+
const Yt = "pie-switch";
|
|
556
|
+
let m = class extends Dt(Rt(Ht(j))) {
|
|
504
557
|
constructor() {
|
|
505
|
-
super(...arguments), this.labelPlacement =
|
|
558
|
+
super(...arguments), this.labelPlacement = M.labelPlacement, this.checked = M.checked, this.defaultChecked = M.defaultChecked, this.required = M.required, this.value = M.value, this.disabled = M.disabled, this._isAnimationAllowed = !1;
|
|
506
559
|
}
|
|
507
|
-
firstUpdated(
|
|
508
|
-
super.firstUpdated(
|
|
509
|
-
const { signal:
|
|
560
|
+
firstUpdated(s) {
|
|
561
|
+
super.firstUpdated(s);
|
|
562
|
+
const { signal: c } = this._abortController;
|
|
510
563
|
this.handleFormAssociation(), this.input.addEventListener("invalid", (d) => {
|
|
511
564
|
this.dispatchEvent(new Event("invalid", d));
|
|
512
|
-
}, { signal:
|
|
565
|
+
}, { signal: c });
|
|
513
566
|
}
|
|
514
567
|
connectedCallback() {
|
|
515
568
|
super.connectedCallback(), this._abortController = new AbortController();
|
|
516
|
-
const { signal:
|
|
517
|
-
this.addEventListener("click", (
|
|
518
|
-
const [d] =
|
|
569
|
+
const { signal: s } = this._abortController;
|
|
570
|
+
this.addEventListener("click", (c) => {
|
|
571
|
+
const [d] = c.composedPath();
|
|
519
572
|
if (this.disabled || d === this.input)
|
|
520
573
|
return;
|
|
521
|
-
const
|
|
522
|
-
(d === this ||
|
|
523
|
-
}, { signal:
|
|
574
|
+
const h = !this.label && c.composedPath().includes(this.switchBody);
|
|
575
|
+
(d === this || h) && this.input.click();
|
|
576
|
+
}, { signal: s });
|
|
524
577
|
}
|
|
525
578
|
disconnectedCallback() {
|
|
526
|
-
var
|
|
527
|
-
super.disconnectedCallback(), (
|
|
579
|
+
var s;
|
|
580
|
+
super.disconnectedCallback(), (s = this._abortController) == null || s.abort();
|
|
528
581
|
}
|
|
529
582
|
updated() {
|
|
530
583
|
this.handleFormAssociation();
|
|
@@ -539,10 +592,10 @@ let p = class extends $e(De(Re(q))) {
|
|
|
539
592
|
* The handleChange function updates the checkbox state and emits an event for consumers.
|
|
540
593
|
* @param {Event} event - This should be the change event that was listened for on an input element with `type="checkbox"`.
|
|
541
594
|
*/
|
|
542
|
-
handleChange(
|
|
543
|
-
const { checked:
|
|
544
|
-
this.checked =
|
|
545
|
-
const d =
|
|
595
|
+
handleChange(s) {
|
|
596
|
+
const { checked: c } = s == null ? void 0 : s.currentTarget;
|
|
597
|
+
this.checked = c;
|
|
598
|
+
const d = Wt(s);
|
|
546
599
|
this._isAnimationAllowed || (this._isAnimationAllowed = !0), this.dispatchEvent(d), this.handleFormAssociation();
|
|
547
600
|
}
|
|
548
601
|
/**
|
|
@@ -565,8 +618,8 @@ let p = class extends $e(De(Re(q))) {
|
|
|
565
618
|
* Allows a consumer to set a custom validation message on the switch. An empty string counts as valid.
|
|
566
619
|
* https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/setCustomValidity
|
|
567
620
|
*/
|
|
568
|
-
setCustomValidity(
|
|
569
|
-
this.input.setCustomValidity(
|
|
621
|
+
setCustomValidity(s) {
|
|
622
|
+
this.input.setCustomValidity(s), this._internals.setValidity(this.validity, this.validationMessage, this.input);
|
|
570
623
|
}
|
|
571
624
|
/**
|
|
572
625
|
* Called when the containing form is reset.
|
|
@@ -576,8 +629,8 @@ let p = class extends $e(De(Re(q))) {
|
|
|
576
629
|
if (this.checked === this.defaultChecked)
|
|
577
630
|
return;
|
|
578
631
|
this.checked = this.defaultChecked;
|
|
579
|
-
const
|
|
580
|
-
this.dispatchEvent(
|
|
632
|
+
const s = new Event("change", { bubbles: !0, composed: !0 });
|
|
633
|
+
this.dispatchEvent(s), this.handleFormAssociation();
|
|
581
634
|
}
|
|
582
635
|
/**
|
|
583
636
|
* (Read-only) returns a ValidityState with the validity states that this element is in.
|
|
@@ -595,116 +648,122 @@ let p = class extends $e(De(Re(q))) {
|
|
|
595
648
|
return this.input.validationMessage;
|
|
596
649
|
}
|
|
597
650
|
renderAriaDescription() {
|
|
598
|
-
var
|
|
599
|
-
return (
|
|
651
|
+
var s;
|
|
652
|
+
return (s = this.aria) != null && s.describedBy ? U`
|
|
600
653
|
<div
|
|
601
654
|
aria-hidden="true"
|
|
602
655
|
id="switch-description"
|
|
603
656
|
data-test-id="switch-description"
|
|
604
657
|
class="c-switch-description">
|
|
605
658
|
${this.aria.describedBy}
|
|
606
|
-
</div>` :
|
|
659
|
+
</div>` : O;
|
|
607
660
|
}
|
|
608
661
|
renderSwitchLabel() {
|
|
609
|
-
const { label:
|
|
610
|
-
return
|
|
662
|
+
const { label: s, labelPlacement: c } = this;
|
|
663
|
+
return s ? U`
|
|
611
664
|
<span
|
|
612
665
|
aria-hidden="true"
|
|
613
|
-
data-test-id="switch-label-${
|
|
666
|
+
data-test-id="switch-label-${c}"
|
|
614
667
|
class="c-switch-label">
|
|
615
|
-
${
|
|
616
|
-
</span>` :
|
|
668
|
+
${s}
|
|
669
|
+
</span>` : O;
|
|
617
670
|
}
|
|
618
671
|
render() {
|
|
672
|
+
var A, F;
|
|
619
673
|
const {
|
|
620
|
-
label:
|
|
621
|
-
labelPlacement:
|
|
674
|
+
label: s,
|
|
675
|
+
labelPlacement: c,
|
|
622
676
|
aria: d,
|
|
623
|
-
checked:
|
|
624
|
-
disabled:
|
|
625
|
-
required:
|
|
626
|
-
_isAnimationAllowed:
|
|
677
|
+
checked: h,
|
|
678
|
+
disabled: l,
|
|
679
|
+
required: p,
|
|
680
|
+
_isAnimationAllowed: v,
|
|
627
681
|
associatedLabelText: C
|
|
628
|
-
} = this,
|
|
682
|
+
} = this, w = (d == null ? void 0 : d.label) || s || ((A = this._contextAria) == null ? void 0 : A.label) || C, S = {
|
|
629
683
|
"c-switch-wrapper": !0,
|
|
630
|
-
"c-switch-wrapper--allow-animation":
|
|
631
|
-
[`c-switch-wrapper--label-${
|
|
632
|
-
},
|
|
633
|
-
return
|
|
634
|
-
<${
|
|
635
|
-
class="${
|
|
636
|
-
?disabled=${
|
|
684
|
+
"c-switch-wrapper--allow-animation": v,
|
|
685
|
+
[`c-switch-wrapper--label-${c}`]: !0
|
|
686
|
+
}, x = Pt(s ? "label" : "div");
|
|
687
|
+
return Ot`
|
|
688
|
+
<${x}
|
|
689
|
+
class="${ht(S)}"
|
|
690
|
+
?disabled=${l}>
|
|
637
691
|
<div
|
|
638
692
|
data-test-id="switch-component"
|
|
639
|
-
class="c-switch"
|
|
640
|
-
?checked=${
|
|
693
|
+
class="${ht({ "c-switch": !0, "c-switch--in-interactive-container": !!this._contextAria })}"
|
|
694
|
+
?checked=${h}>
|
|
641
695
|
<input
|
|
642
696
|
data-test-id="switch-input"
|
|
643
697
|
role="switch"
|
|
644
698
|
type="checkbox"
|
|
645
699
|
class="c-switch-input"
|
|
646
|
-
?required=${
|
|
647
|
-
.checked="${
|
|
648
|
-
?disabled="${
|
|
700
|
+
?required=${p}
|
|
701
|
+
.checked="${$t(h)}"
|
|
702
|
+
?disabled="${l}"
|
|
649
703
|
@change="${this.handleChange}"
|
|
650
|
-
aria-label="${
|
|
651
|
-
aria-
|
|
704
|
+
aria-label="${ut(w)}"
|
|
705
|
+
aria-description="${ut((F = this._contextAria) == null ? void 0 : F.description)}"
|
|
706
|
+
aria-describedby="${d != null && d.describedBy ? "switch-description" : O}">
|
|
652
707
|
<div class="c-switch-control">
|
|
653
|
-
${
|
|
708
|
+
${h ? U`<icon-check></icon-check>` : O}
|
|
654
709
|
</div>
|
|
655
710
|
</div>
|
|
656
711
|
${this.renderSwitchLabel()}
|
|
657
712
|
${this.renderAriaDescription()}
|
|
658
|
-
</${
|
|
713
|
+
</${x}>`;
|
|
659
714
|
}
|
|
660
715
|
};
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
],
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
],
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
],
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
],
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
],
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
],
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
],
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
],
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
],
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
716
|
+
m.styles = Nt(Gt);
|
|
717
|
+
b([
|
|
718
|
+
E({ type: String })
|
|
719
|
+
], m.prototype, "label", 2);
|
|
720
|
+
b([
|
|
721
|
+
E({ type: String }),
|
|
722
|
+
zt(Yt, Jt, M.labelPlacement)
|
|
723
|
+
], m.prototype, "labelPlacement", 2);
|
|
724
|
+
b([
|
|
725
|
+
E({ type: Object })
|
|
726
|
+
], m.prototype, "aria", 2);
|
|
727
|
+
b([
|
|
728
|
+
E({ type: Boolean, reflect: !0 })
|
|
729
|
+
], m.prototype, "checked", 2);
|
|
730
|
+
b([
|
|
731
|
+
E({ type: Boolean, reflect: !0 })
|
|
732
|
+
], m.prototype, "defaultChecked", 2);
|
|
733
|
+
b([
|
|
734
|
+
E({ type: Boolean, reflect: !0 })
|
|
735
|
+
], m.prototype, "required", 2);
|
|
736
|
+
b([
|
|
737
|
+
E({ type: String })
|
|
738
|
+
], m.prototype, "value", 2);
|
|
739
|
+
b([
|
|
740
|
+
E({ type: String, reflect: !0 })
|
|
741
|
+
], m.prototype, "name", 2);
|
|
742
|
+
b([
|
|
743
|
+
E({ type: Boolean, reflect: !0 })
|
|
744
|
+
], m.prototype, "disabled", 2);
|
|
745
|
+
b([
|
|
746
|
+
jt({ context: Bt, subscribe: !0 }),
|
|
747
|
+
bt()
|
|
748
|
+
], m.prototype, "_contextAria", 2);
|
|
749
|
+
b([
|
|
750
|
+
K('input[type="checkbox"]')
|
|
751
|
+
], m.prototype, "input", 2);
|
|
752
|
+
b([
|
|
753
|
+
K(".c-switch")
|
|
754
|
+
], m.prototype, "switchBody", 2);
|
|
755
|
+
b([
|
|
756
|
+
K('label, input[type="checkbox"]')
|
|
757
|
+
], m.prototype, "focusTarget", 2);
|
|
758
|
+
b([
|
|
759
|
+
bt()
|
|
760
|
+
], m.prototype, "_isAnimationAllowed", 2);
|
|
761
|
+
m = b([
|
|
762
|
+
qt("pie-switch")
|
|
763
|
+
], m);
|
|
705
764
|
export {
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
765
|
+
le as ON_SWITCH_CHANGED_EVENT,
|
|
766
|
+
m as PieSwitch,
|
|
767
|
+
M as defaultProps,
|
|
768
|
+
Jt as labelPlacements
|
|
710
769
|
};
|
package/dist/react.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@justeattakeaway/pie-switch",
|
|
3
3
|
"description": "PIE Design System Switch built using Web Components",
|
|
4
|
-
"version": "2.
|
|
4
|
+
"version": "2.6.0",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "https://github.com/justeattakeaway/pie",
|
|
@@ -44,13 +44,13 @@
|
|
|
44
44
|
"license": "Apache-2.0",
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@justeattakeaway/pie-components-config": "0.21.3",
|
|
47
|
-
"@justeattakeaway/pie-css": "1.3.
|
|
48
|
-
"@justeattakeaway/pie-monorepo-utils": "0.9.
|
|
47
|
+
"@justeattakeaway/pie-css": "1.3.2",
|
|
48
|
+
"@justeattakeaway/pie-monorepo-utils": "0.9.8",
|
|
49
49
|
"@justeattakeaway/pie-wrapper-react": "0.14.5"
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
|
-
"@justeattakeaway/pie-icons-webc": "1.27.
|
|
53
|
-
"@justeattakeaway/pie-webc-core": "16.
|
|
52
|
+
"@justeattakeaway/pie-icons-webc": "1.27.1",
|
|
53
|
+
"@justeattakeaway/pie-webc-core": "16.1.0",
|
|
54
54
|
"element-internals-polyfill": "1.3.11"
|
|
55
55
|
},
|
|
56
56
|
"customElements": "custom-elements.json",
|
package/src/index.ts
CHANGED
|
@@ -7,6 +7,7 @@ import { property, query, state } from 'lit/decorators.js';
|
|
|
7
7
|
import { classMap } from 'lit/directives/class-map.js';
|
|
8
8
|
import { ifDefined } from 'lit/directives/if-defined.js';
|
|
9
9
|
import { live } from 'lit/directives/live.js';
|
|
10
|
+
import { consume } from '@lit/context';
|
|
10
11
|
import 'element-internals-polyfill';
|
|
11
12
|
|
|
12
13
|
import {
|
|
@@ -16,7 +17,9 @@ import {
|
|
|
16
17
|
AssociatedLabelMixin,
|
|
17
18
|
wrapNativeEvent,
|
|
18
19
|
safeCustomElement,
|
|
20
|
+
ariaContext,
|
|
19
21
|
type PIEInputElement,
|
|
22
|
+
type ContextualAria,
|
|
20
23
|
} from '@justeattakeaway/pie-webc-core';
|
|
21
24
|
import '@justeattakeaway/pie-icons-webc/dist/IconCheck.js';
|
|
22
25
|
|
|
@@ -62,6 +65,12 @@ export class PieSwitch extends AssociatedLabelMixin(FormControlMixin(DelegatesFo
|
|
|
62
65
|
@property({ type: Boolean, reflect: true })
|
|
63
66
|
public disabled = defaultProps.disabled;
|
|
64
67
|
|
|
68
|
+
// Optional ARIA supplied by an ancestor (for example a `pie-list-item`), folded into the
|
|
69
|
+
// input's ARIA below as a fallback behind the switch's own label. Undefined when standalone.
|
|
70
|
+
@consume({ context: ariaContext, subscribe: true })
|
|
71
|
+
@state()
|
|
72
|
+
private _contextAria?: ContextualAria;
|
|
73
|
+
|
|
65
74
|
@query('input[type="checkbox"]')
|
|
66
75
|
private input!: HTMLInputElement;
|
|
67
76
|
|
|
@@ -266,7 +275,7 @@ export class PieSwitch extends AssociatedLabelMixin(FormControlMixin(DelegatesFo
|
|
|
266
275
|
associatedLabelText,
|
|
267
276
|
} = this;
|
|
268
277
|
|
|
269
|
-
const ariaLabel = aria?.label || label || associatedLabelText;
|
|
278
|
+
const ariaLabel = aria?.label || label || this._contextAria?.label || associatedLabelText;
|
|
270
279
|
|
|
271
280
|
const classes = {
|
|
272
281
|
'c-switch-wrapper': true,
|
|
@@ -282,7 +291,7 @@ export class PieSwitch extends AssociatedLabelMixin(FormControlMixin(DelegatesFo
|
|
|
282
291
|
?disabled=${disabled}>
|
|
283
292
|
<div
|
|
284
293
|
data-test-id="switch-component"
|
|
285
|
-
class="c-switch"
|
|
294
|
+
class="${classMap({ 'c-switch': true, 'c-switch--in-interactive-container': Boolean(this._contextAria) })}"
|
|
286
295
|
?checked=${checked}>
|
|
287
296
|
<input
|
|
288
297
|
data-test-id="switch-input"
|
|
@@ -294,6 +303,7 @@ export class PieSwitch extends AssociatedLabelMixin(FormControlMixin(DelegatesFo
|
|
|
294
303
|
?disabled="${disabled}"
|
|
295
304
|
@change="${this.handleChange}"
|
|
296
305
|
aria-label="${ifDefined(ariaLabel)}"
|
|
306
|
+
aria-description="${ifDefined(this._contextAria?.description)}"
|
|
297
307
|
aria-describedby="${aria?.describedBy ? 'switch-description' : nothing}">
|
|
298
308
|
<div class="c-switch-control">
|
|
299
309
|
${checked ? html`<icon-check></icon-check>` : nothing}
|
package/src/switch.scss
CHANGED
|
@@ -68,6 +68,27 @@
|
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
+
// Inside an interactive container (such as a `pie-list-item`) the whole container is the click
|
|
72
|
+
// target, so the track should tint with the container rather than only on a direct hover of the
|
|
73
|
+
// switch. The container exposes its current hover/active tint as `--interactive-container-tint` (an
|
|
74
|
+
// inherited custom property that flows through the slot into this shadow tree); we layer it over
|
|
75
|
+
// the track. We also opt the switch out of its own hover/active tint here, so hovering the switch
|
|
76
|
+
// directly (which also hovers the container) does not tint twice. The class is added by the
|
|
77
|
+
// component when it consumes an ancestor's ARIA context.
|
|
78
|
+
.c-switch--in-interactive-container {
|
|
79
|
+
background-image: linear-gradient(var(--interactive-container-tint, transparent) 0 0);
|
|
80
|
+
|
|
81
|
+
&:hover:not(:disabled),
|
|
82
|
+
&:active:not(:disabled) {
|
|
83
|
+
--int-states-mixin-bg-color: var(--dt-color-interactive-form);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
&[checked]:hover:not(:disabled),
|
|
87
|
+
&[checked]:active:not(:disabled) {
|
|
88
|
+
--int-states-mixin-bg-color: var(--dt-color-interactive-brand);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
71
92
|
.c-switch-input {
|
|
72
93
|
@include p.visually-hidden;
|
|
73
94
|
|