@justeattakeaway/pie-switch 0.29.11 → 0.30.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/dist/index.js CHANGED
@@ -1,18 +1,12 @@
1
- import { LitElement as Fe, html as A, nothing as C, unsafeCSS as Ae } from "lit";
2
- import { query as le, property as E } from "lit/decorators.js";
3
- import { FormControlMixin as Ie, RtlMixin as Se, wrapNativeEvent as Ve, validPropertyValues as Te, defineCustomElement as Le } from "@justeattakeaway/pie-webc-core";
1
+ import { LitElement as xe, nothing as L, html as N, unsafeCSS as Fe } from "lit";
2
+ import { property as E, query as le } from "lit/decorators.js";
3
+ import { classMap as Se } from "lit/directives/class-map.js";
4
+ import { ifDefined as Ie } from "lit/directives/if-defined.js";
5
+ import { FormControlMixin as Ve, RtlMixin as Te, wrapNativeEvent as Le, validPropertyValues as Ne, defineCustomElement as Pe } from "@justeattakeaway/pie-webc-core";
4
6
  import "@justeattakeaway/pie-icons-webc/dist/IconCheck.js";
5
- const Ne = `*,*:after,*:before{box-sizing:inherit}*,*:before,*:after{cursor:inherit}.c-switch-wrapper{display:inline-flex;align-items:center;gap:var(--dt-spacing-b);font-family:var(--dt-font-body-l-family);cursor:pointer}.c-switch-wrapper[disabled]{cursor:not-allowed}.c-switch{--switch-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(--switch-bg-color)}@media (prefers-reduced-motion: no-preference){.c-switch{transition:background-color .15s cubic-bezier(.4,0,.9,1) 0s}}.c-switch:hover{background-color:hsl(var(--dt-color-interactive-form-h),var(--dt-color-interactive-form-s),calc(var(--dt-color-interactive-form-l) - var(--dt-color-hover-01)))}.c-switch:focus,.c-switch:focus-within{box-shadow:0 0 0 2px var(--dt-color-focus-inner),0 0 0 4px var(--dt-color-focus-outer);outline:none}.c-switch:active{background-color:hsl(var(--dt-color-interactive-form-h),var(--dt-color-interactive-form-s),calc(var(--dt-color-interactive-form-l) - var(--dt-color-active-01)))}.c-switch[checked]{background-color:var(--switch-bg-color--checked)}@media (prefers-reduced-motion: no-preference){.c-switch[checked]{transition:background-color .15s cubic-bezier(.4,0,.9,1) 0s}}.c-switch[checked]:hover{background-color:hsl(var(--dt-color-interactive-brand-h),var(--dt-color-interactive-brand-s),calc(var(--dt-color-interactive-brand-l) - var(--dt-color-hover-01)))}.c-switch[checked]:focus,.c-switch[checked]:focus-within{background-color:var(--switch-bg-color--checked)}.c-switch[checked]:active{background-color:hsl(var(--dt-color-interactive-brand-h),var(--dt-color-interactive-brand-s),calc(var(--dt-color-interactive-brand-l) - var(--dt-color-active-01)))}[disabled] .c-switch{background-color:var(--switch-bg-color--disabled);pointer-events:none}.c-switch-input{position:absolute;width:1px;height:1px;margin:-1px;padding:0;overflow:hidden;clip:rect(0,0,0,0);border:0;left:50%;transform:translate(-50%) translateY(-50%);bottom:0}.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)}@media (prefers-reduced-motion: no-preference){.c-switch-control{transition:transform .15s cubic-bezier(.4,0,.9,1) 0s}}.c-switch-input:checked+.c-switch-control{transform:translate(var(--switch-translation))}@media (prefers-reduced-motion: no-preference){.c-switch-input:checked+.c-switch-control{transition:transform .15s cubic-bezier(.4,0,.9,1) 0s}}.c-switch-input:checked+.c-switch-control .c-pieIcon--check{color:var(--switch-bg-color--checked)}@media (prefers-reduced-motion: no-preference){.c-switch-input:checked+.c-switch-control .c-pieIcon--check{transition:color .15s cubic-bezier(.4,0,.9,1) 0s}}.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)}@media (prefers-reduced-motion: no-preference){.c-switch-input:disabled~.c-switch-control .c-pieIcon--check{transition:color .15s cubic-bezier(.4,0,.9,1) 0s}}.c-switch-description{position:absolute;display:block;height:1px;width:1px;overflow:hidden;padding:1px;white-space:nowrap}.c-switch-wrapper[data-is-rtl] .c-switch-control{position:absolute;left:initial;right:2px}.c-switch-wrapper[data-is-rtl] .c-switch-input:checked+.c-switch-control{transform:translate(calc(-1 * var(--switch-translation)))}@media (prefers-reduced-motion: no-preference){.c-switch-wrapper[data-is-rtl] .c-switch-input:checked+.c-switch-control{transition:transform .15s cubic-bezier(.4,0,.9,1) 0s}}
6
- `, Pe = ["leading", "trailing"], ze = "change", x = {
7
- checked: !1,
8
- required: !1,
9
- disabled: !1,
10
- value: "on",
11
- labelPlacement: "leading"
12
- };
13
7
  (function() {
14
- (function(g) {
15
- const n = /* @__PURE__ */ new WeakMap(), l = /* @__PURE__ */ new WeakMap(), h = /* @__PURE__ */ new WeakMap(), c = /* @__PURE__ */ new WeakMap(), w = /* @__PURE__ */ new WeakMap(), k = /* @__PURE__ */ new WeakMap(), M = /* @__PURE__ */ new WeakMap(), y = /* @__PURE__ */ new WeakMap(), z = /* @__PURE__ */ new WeakMap(), I = /* @__PURE__ */ new WeakMap(), q = /* @__PURE__ */ new WeakMap(), B = /* @__PURE__ */ new WeakMap(), U = /* @__PURE__ */ new WeakMap(), j = /* @__PURE__ */ new WeakMap(), S = /* @__PURE__ */ new WeakMap(), V = {
8
+ (function(v) {
9
+ const o = /* @__PURE__ */ new WeakMap(), c = /* @__PURE__ */ new WeakMap(), h = /* @__PURE__ */ new WeakMap(), l = /* @__PURE__ */ new WeakMap(), g = /* @__PURE__ */ new WeakMap(), k = /* @__PURE__ */ new WeakMap(), P = /* @__PURE__ */ new WeakMap(), y = /* @__PURE__ */ new WeakMap(), z = /* @__PURE__ */ new WeakMap(), A = /* @__PURE__ */ new WeakMap(), q = /* @__PURE__ */ new WeakMap(), B = /* @__PURE__ */ new WeakMap(), U = /* @__PURE__ */ new WeakMap(), j = /* @__PURE__ */ new WeakMap(), x = /* @__PURE__ */ new WeakMap(), F = {
16
10
  ariaAtomic: "aria-atomic",
17
11
  ariaAutoComplete: "aria-autocomplete",
18
12
  ariaBusy: "aria-busy",
@@ -56,72 +50,72 @@ const Ne = `*,*:after,*:before{box-sizing:inherit}*,*:before,*:after{cursor:inhe
56
50
  ariaValueText: "aria-valuetext",
57
51
  role: "role"
58
52
  }, de = (t, e) => {
59
- for (let i in V) {
53
+ for (let i in F) {
60
54
  e[i] = null;
61
55
  let a = null;
62
- const r = V[i];
56
+ const r = F[i];
63
57
  Object.defineProperty(e, i, {
64
58
  get() {
65
59
  return a;
66
60
  },
67
- set(o) {
68
- a = o, t.isConnected ? t.setAttribute(r, o) : I.set(t, e);
61
+ set(s) {
62
+ a = s, t.isConnected ? t.setAttribute(r, s) : A.set(t, e);
69
63
  }
70
64
  });
71
65
  }
72
66
  };
73
67
  function K(t) {
74
- const e = c.get(t), { form: i } = e;
68
+ const e = l.get(t), { form: i } = e;
75
69
  Z(t, i, e), X(t, e.labels);
76
70
  }
77
71
  const G = (t, e = !1) => {
78
72
  const i = document.createTreeWalker(t, NodeFilter.SHOW_ELEMENT, {
79
- acceptNode(o) {
80
- return c.has(o) ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP;
73
+ acceptNode(s) {
74
+ return l.has(s) ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP;
81
75
  }
82
76
  });
83
77
  let a = i.nextNode();
84
78
  const r = !e || t.disabled;
85
79
  for (; a; )
86
80
  a.formDisabledCallback && r && $(a, t.disabled), a = i.nextNode();
87
- }, Y = { attributes: !0, attributeFilter: ["disabled", "name"] }, T = P() ? new MutationObserver((t) => {
81
+ }, Y = { attributes: !0, attributeFilter: ["disabled", "name"] }, S = T() ? new MutationObserver((t) => {
88
82
  for (const e of t) {
89
83
  const i = e.target;
90
84
  if (e.attributeName === "disabled" && (i.constructor.formAssociated ? $(i, i.hasAttribute("disabled")) : i.localName === "fieldset" && G(i)), e.attributeName === "name" && i.constructor.formAssociated) {
91
- const a = c.get(i), r = z.get(i);
85
+ const a = l.get(i), r = z.get(i);
92
86
  a.setFormValue(r);
93
87
  }
94
88
  }
95
89
  }) : {};
96
90
  function O(t) {
97
91
  t.forEach((e) => {
98
- const { addedNodes: i, removedNodes: a } = e, r = Array.from(i), o = Array.from(a);
99
- r.forEach((s) => {
92
+ const { addedNodes: i, removedNodes: a } = e, r = Array.from(i), s = Array.from(a);
93
+ r.forEach((n) => {
100
94
  var u;
101
- if (c.has(s) && s.constructor.formAssociated && K(s), I.has(s)) {
102
- const d = I.get(s);
103
- Object.keys(V).filter((f) => d[f] !== null).forEach((f) => {
104
- s.setAttribute(V[f], d[f]);
105
- }), I.delete(s);
95
+ if (l.has(n) && n.constructor.formAssociated && K(n), A.has(n)) {
96
+ const d = A.get(n);
97
+ Object.keys(F).filter((f) => d[f] !== null).forEach((f) => {
98
+ n.setAttribute(F[f], d[f]);
99
+ }), A.delete(n);
106
100
  }
107
- if (S.has(s)) {
108
- const d = S.get(s);
109
- s.setAttribute("internals-valid", d.validity.valid.toString()), s.setAttribute("internals-invalid", (!d.validity.valid).toString()), s.setAttribute("aria-invalid", (!d.validity.valid).toString()), S.delete(s);
101
+ if (x.has(n)) {
102
+ const d = x.get(n);
103
+ n.setAttribute("internals-valid", d.validity.valid.toString()), n.setAttribute("internals-invalid", (!d.validity.valid).toString()), n.setAttribute("aria-invalid", (!d.validity.valid).toString()), x.delete(n);
110
104
  }
111
- if (s.localName === "form") {
112
- const d = y.get(s), v = document.createTreeWalker(s, NodeFilter.SHOW_ELEMENT, {
105
+ if (n.localName === "form") {
106
+ const d = y.get(n), b = document.createTreeWalker(n, NodeFilter.SHOW_ELEMENT, {
113
107
  acceptNode(W) {
114
- return c.has(W) && W.constructor.formAssociated && !(d && d.has(W)) ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP;
108
+ return l.has(W) && W.constructor.formAssociated && !(d && d.has(W)) ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP;
115
109
  }
116
110
  });
117
- let f = v.nextNode();
111
+ let f = b.nextNode();
118
112
  for (; f; )
119
- K(f), f = v.nextNode();
113
+ K(f), f = b.nextNode();
120
114
  }
121
- s.localName === "fieldset" && ((u = T.observe) === null || u === void 0 || u.call(T, s, Y), G(s, !0));
122
- }), o.forEach((s) => {
123
- const u = c.get(s);
124
- u && h.get(u) && J(u), M.has(s) && M.get(s).disconnect();
115
+ n.localName === "fieldset" && ((u = S.observe) === null || u === void 0 || u.call(S, n, Y), G(n, !0));
116
+ }), s.forEach((n) => {
117
+ const u = l.get(n);
118
+ u && h.get(u) && J(u), P.has(n) && P.get(n).disconnect();
125
119
  });
126
120
  });
127
121
  }
@@ -130,7 +124,7 @@ const Ne = `*,*:after,*:before{box-sizing:inherit}*,*:before,*:after{cursor:inhe
130
124
  const { removedNodes: i } = e;
131
125
  i.forEach((a) => {
132
126
  const r = U.get(e.target);
133
- c.has(a) && te(a), r.disconnect();
127
+ l.has(a) && te(a), r.disconnect();
134
128
  });
135
129
  });
136
130
  }
@@ -139,7 +133,7 @@ const Ne = `*,*:after,*:before{box-sizing:inherit}*,*:before,*:after{cursor:inhe
139
133
  const a = new MutationObserver(he);
140
134
  !((e = window == null ? void 0 : window.ShadyDOM) === null || e === void 0) && e.inUse && t.mode && t.host && (t = t.host), (i = a.observe) === null || i === void 0 || i.call(a, t, { childList: !0 }), U.set(t, a);
141
135
  };
142
- P() && new MutationObserver(O);
136
+ T() && new MutationObserver(O);
143
137
  const _ = {
144
138
  childList: !0,
145
139
  subtree: !0
@@ -154,20 +148,20 @@ const Ne = `*,*:after,*:before{box-sizing:inherit}*,*:before,*:after{cursor:inhe
154
148
  return i.type = "hidden", i.name = t.getAttribute("name"), t.after(i), h.get(e).push(i), i;
155
149
  }, pe = (t, e) => {
156
150
  var i;
157
- h.set(e, []), (i = T.observe) === null || i === void 0 || i.call(T, t, Y);
151
+ h.set(e, []), (i = S.observe) === null || i === void 0 || i.call(S, t, Y);
158
152
  }, X = (t, e) => {
159
153
  if (e.length) {
160
154
  Array.from(e).forEach((a) => a.addEventListener("click", t.click.bind(t)));
161
155
  let i = e[0].id;
162
156
  e[0].id || (i = `${e[0].htmlFor}_Label`, e[0].id = i), t.setAttribute("aria-labelledby", i);
163
157
  }
164
- }, L = (t) => {
165
- const e = Array.from(t.elements).filter((o) => !o.tagName.includes("-") && o.validity).map((o) => o.validity.valid), i = y.get(t) || [], a = Array.from(i).filter((o) => o.isConnected).map((o) => c.get(o).validity.valid), r = [...e, ...a].includes(!1);
158
+ }, I = (t) => {
159
+ const e = Array.from(t.elements).filter((s) => !s.tagName.includes("-") && s.validity).map((s) => s.validity.valid), i = y.get(t) || [], a = Array.from(i).filter((s) => s.isConnected).map((s) => l.get(s).validity.valid), r = [...e, ...a].includes(!1);
166
160
  t.toggleAttribute("internals-invalid", r), t.toggleAttribute("internals-valid", !r);
167
161
  }, fe = (t) => {
168
- L(N(t.target));
162
+ I(V(t.target));
169
163
  }, me = (t) => {
170
- L(N(t.target));
164
+ I(V(t.target));
171
165
  }, we = (t) => {
172
166
  const e = ["button[type=submit]", "input[type=submit]", "button:not([type])"].map((i) => `${i}:not([disabled])`).map((i) => `${i}:not([form])${t.id ? `,${i}[form='${t.id}']` : ""}`).join(",");
173
167
  t.addEventListener("click", (i) => {
@@ -175,7 +169,7 @@ const Ne = `*,*:after,*:before{box-sizing:inherit}*,*:before,*:after{cursor:inhe
175
169
  const r = y.get(t);
176
170
  if (t.noValidate)
177
171
  return;
178
- r.size && Array.from(r).reverse().map((u) => c.get(u).reportValidity()).includes(!1) && i.preventDefault();
172
+ r.size && Array.from(r).reverse().map((u) => l.get(u).reportValidity()).includes(!1) && i.preventDefault();
179
173
  }
180
174
  });
181
175
  }, be = (t) => {
@@ -194,26 +188,26 @@ const Ne = `*,*:after,*:before{box-sizing:inherit}*,*:before,*:after{cursor:inhe
194
188
  }
195
189
  k.set(e, { ref: t, internals: i }), t.constructor.formAssociated && t.formAssociatedCallback && setTimeout(() => {
196
190
  t.formAssociatedCallback.apply(t, [e]);
197
- }, 0), L(e);
191
+ }, 0), I(e);
198
192
  }
199
- }, N = (t) => {
193
+ }, V = (t) => {
200
194
  let e = t.parentNode;
201
- return e && e.tagName !== "FORM" && (e = N(e)), e;
202
- }, b = (t, e, i = DOMException) => {
195
+ return e && e.tagName !== "FORM" && (e = V(e)), e;
196
+ }, w = (t, e, i = DOMException) => {
203
197
  if (!t.constructor.formAssociated)
204
198
  throw new i(e);
205
199
  }, ee = (t, e, i) => {
206
200
  const a = y.get(t);
207
201
  return a && a.size && a.forEach((r) => {
208
- c.get(r)[i]() || (e = !1);
202
+ l.get(r)[i]() || (e = !1);
209
203
  }), e;
210
204
  }, te = (t) => {
211
205
  if (t.constructor.formAssociated) {
212
- const e = c.get(t), { labels: i, form: a } = e;
206
+ const e = l.get(t), { labels: i, form: a } = e;
213
207
  X(t, i), Z(t, a, e);
214
208
  }
215
209
  };
216
- function P() {
210
+ function T() {
217
211
  return typeof MutationObserver < "u";
218
212
  }
219
213
  class ve {
@@ -221,7 +215,7 @@ const Ne = `*,*:after,*:before{box-sizing:inherit}*,*:before,*:after{cursor:inhe
221
215
  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);
222
216
  }
223
217
  }
224
- const ge = (t) => (t.badInput = !1, t.customError = !1, t.patternMismatch = !1, t.rangeOverflow = !1, t.rangeUnderflow = !1, t.stepMismatch = !1, t.tooLong = !1, t.tooShort = !1, t.typeMismatch = !1, t.valid = !0, t.valueMissing = !1, t), ye = (t, e, i) => (t.valid = Ee(e), Object.keys(e).forEach((a) => t[a] = e[a]), i && L(i), t), Ee = (t) => {
218
+ const ge = (t) => (t.badInput = !1, t.customError = !1, t.patternMismatch = !1, t.rangeOverflow = !1, t.rangeUnderflow = !1, t.stepMismatch = !1, t.tooLong = !1, t.tooShort = !1, t.typeMismatch = !1, t.valid = !0, t.valueMissing = !1, t), ye = (t, e, i) => (t.valid = Ee(e), Object.keys(e).forEach((a) => t[a] = e[a]), i && I(i), t), Ee = (t) => {
225
219
  let e = !0;
226
220
  for (let i in t)
227
221
  i !== "valid" && t[i] !== !1 && (e = !1);
@@ -275,10 +269,10 @@ const Ne = `*,*:after,*:before{box-sizing:inherit}*,*:before,*:after{cursor:inhe
275
269
  throw new TypeError("Cannot write private member to an object whose class did not declare it");
276
270
  return a === "a" ? r.call(t, i) : r ? r.value = i : e.set(t, i), i;
277
271
  }
278
- var F;
272
+ var C;
279
273
  class Me {
280
274
  constructor(e) {
281
- F.set(this, void 0), ke(this, F, e, "f");
275
+ C.set(this, void 0), ke(this, C, e, "f");
282
276
  for (let i = 0; i < e.length; i++) {
283
277
  let a = e[i];
284
278
  this[i] = a, a.hasAttribute("name") && (this[a.getAttribute("name")] = a);
@@ -286,10 +280,10 @@ const Ne = `*,*:after,*:before{box-sizing:inherit}*,*:before,*:after{cursor:inhe
286
280
  Object.freeze(this);
287
281
  }
288
282
  get length() {
289
- return ae(this, F, "f").length;
283
+ return ae(this, C, "f").length;
290
284
  }
291
- [(F = /* @__PURE__ */ new WeakMap(), Symbol.iterator)]() {
292
- return ae(this, F, "f")[Symbol.iterator]();
285
+ [(C = /* @__PURE__ */ new WeakMap(), Symbol.iterator)]() {
286
+ return ae(this, C, "f")[Symbol.iterator]();
293
287
  }
294
288
  item(e) {
295
289
  return this[e] == null ? null : this[e];
@@ -303,21 +297,21 @@ const Ne = `*,*:after,*:before{box-sizing:inherit}*,*:before,*:after{cursor:inhe
303
297
  HTMLFormElement.prototype.checkValidity = i;
304
298
  const e = HTMLFormElement.prototype.reportValidity;
305
299
  HTMLFormElement.prototype.reportValidity = a;
306
- function i(...o) {
307
- let s = t.apply(this, o);
308
- return ee(this, s, "checkValidity");
300
+ function i(...s) {
301
+ let n = t.apply(this, s);
302
+ return ee(this, n, "checkValidity");
309
303
  }
310
- function a(...o) {
311
- let s = e.apply(this, o);
312
- return ee(this, s, "reportValidity");
304
+ function a(...s) {
305
+ let n = e.apply(this, s);
306
+ return ee(this, n, "reportValidity");
313
307
  }
314
308
  const { get: r } = Object.getOwnPropertyDescriptor(HTMLFormElement.prototype, "elements");
315
309
  Object.defineProperty(HTMLFormElement.prototype, "elements", {
316
- get(...o) {
317
- const s = r.call(this, ...o), u = Array.from(y.get(this) || []);
310
+ get(...s) {
311
+ const n = r.call(this, ...s), u = Array.from(y.get(this) || []);
318
312
  if (u.length === 0)
319
- return s;
320
- const d = Array.from(s).concat(u).sort((v, f) => v.compareDocumentPosition ? v.compareDocumentPosition(f) & 2 ? 1 : -1 : 0);
313
+ return n;
314
+ const d = Array.from(n).concat(u).sort((b, f) => b.compareDocumentPosition ? b.compareDocumentPosition(f) & 2 ? 1 : -1 : 0);
321
315
  return new Me(d);
322
316
  }
323
317
  });
@@ -330,13 +324,13 @@ const Ne = `*,*:after,*:before{box-sizing:inherit}*,*:before,*:after{cursor:inhe
330
324
  if (!e || !e.tagName || e.tagName.indexOf("-") === -1)
331
325
  throw new TypeError("Illegal constructor");
332
326
  const i = e.getRootNode(), a = new ve();
333
- this.states = new D(e), n.set(this, e), l.set(this, a), c.set(e, this), de(e, this), pe(e, this), Object.seal(this), i instanceof DocumentFragment && ue(i);
327
+ this.states = new D(e), o.set(this, e), c.set(this, a), l.set(e, this), de(e, this), pe(e, this), Object.seal(this), i instanceof DocumentFragment && ue(i);
334
328
  }
335
329
  checkValidity() {
336
- const e = n.get(this);
337
- if (b(e, "Failed to execute 'checkValidity' on 'ElementInternals': The target element is not a form-associated custom element."), !this.willValidate)
330
+ const e = o.get(this);
331
+ if (w(e, "Failed to execute 'checkValidity' on 'ElementInternals': The target element is not a form-associated custom element."), !this.willValidate)
338
332
  return !0;
339
- const i = l.get(this);
333
+ const i = c.get(this);
340
334
  if (!i.valid) {
341
335
  const a = new Event("invalid", {
342
336
  bubbles: !1,
@@ -348,20 +342,20 @@ const Ne = `*,*:after,*:before{box-sizing:inherit}*,*:before,*:after{cursor:inhe
348
342
  return i.valid;
349
343
  }
350
344
  get form() {
351
- const e = n.get(this);
352
- b(e, "Failed to read the 'form' property from 'ElementInternals': The target element is not a form-associated custom element.");
345
+ const e = o.get(this);
346
+ w(e, "Failed to read the 'form' property from 'ElementInternals': The target element is not a form-associated custom element.");
353
347
  let i;
354
- return e.constructor.formAssociated === !0 && (i = N(e)), i;
348
+ return e.constructor.formAssociated === !0 && (i = V(e)), i;
355
349
  }
356
350
  get labels() {
357
- const e = n.get(this);
358
- b(e, "Failed to read the 'labels' property from 'ElementInternals': The target element is not a form-associated custom element.");
351
+ const e = o.get(this);
352
+ w(e, "Failed to read the 'labels' property from 'ElementInternals': The target element is not a form-associated custom element.");
359
353
  const i = e.getAttribute("id"), a = e.getRootNode();
360
354
  return a && i ? a.querySelectorAll(`[for="${i}"]`) : [];
361
355
  }
362
356
  reportValidity() {
363
- const e = n.get(this);
364
- if (b(e, "Failed to execute 'reportValidity' on 'ElementInternals': The target element is not a form-associated custom element."), !this.willValidate)
357
+ const e = o.get(this);
358
+ if (w(e, "Failed to execute 'reportValidity' on 'ElementInternals': The target element is not a form-associated custom element."), !this.willValidate)
365
359
  return !0;
366
360
  const i = this.checkValidity(), a = B.get(this);
367
361
  if (a && !e.constructor.formAssociated)
@@ -369,8 +363,8 @@ const Ne = `*,*:after,*:before{box-sizing:inherit}*,*:before,*:after{cursor:inhe
369
363
  return !i && a && (e.focus(), a.focus()), i;
370
364
  }
371
365
  setFormValue(e) {
372
- const i = n.get(this);
373
- if (b(i, "Failed to execute 'setFormValue' on 'ElementInternals': The target element is not a form-associated custom element."), J(this), e != null && !(e instanceof FormData)) {
366
+ const i = o.get(this);
367
+ if (w(i, "Failed to execute 'setFormValue' on 'ElementInternals': The target element is not a form-associated custom element."), J(this), e != null && !(e instanceof FormData)) {
374
368
  if (i.getAttribute("name")) {
375
369
  const a = Q(i, this);
376
370
  a.value = e;
@@ -378,46 +372,46 @@ const Ne = `*,*:after,*:before{box-sizing:inherit}*,*:before,*:after{cursor:inhe
378
372
  } else
379
373
  e != null && e instanceof FormData && Array.from(e).reverse().forEach(([a, r]) => {
380
374
  if (typeof r == "string") {
381
- const o = Q(i, this);
382
- o.name = a, o.value = r;
375
+ const s = Q(i, this);
376
+ s.name = a, s.value = r;
383
377
  }
384
378
  });
385
379
  z.set(i, e);
386
380
  }
387
381
  setValidity(e, i, a) {
388
- const r = n.get(this);
389
- if (b(r, "Failed to execute 'setValidity' on 'ElementInternals': The target element is not a form-associated custom element."), !e)
382
+ const r = o.get(this);
383
+ if (w(r, "Failed to execute 'setValidity' on 'ElementInternals': The target element is not a form-associated custom element."), !e)
390
384
  throw new TypeError("Failed to execute 'setValidity' on 'ElementInternals': 1 argument required, but only 0 present.");
391
385
  B.set(this, a);
392
- const o = l.get(this), s = {};
393
- for (const v in e)
394
- s[v] = e[v];
395
- Object.keys(s).length === 0 && ge(o);
396
- const u = Object.assign(Object.assign({}, o), s);
386
+ const s = c.get(this), n = {};
387
+ for (const b in e)
388
+ n[b] = e[b];
389
+ Object.keys(n).length === 0 && ge(s);
390
+ const u = Object.assign(Object.assign({}, s), n);
397
391
  delete u.valid;
398
- const { valid: d } = ye(o, u, this.form);
392
+ const { valid: d } = ye(s, u, this.form);
399
393
  if (!d && !i)
400
394
  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.");
401
- w.set(this, d ? "" : i), r.isConnected ? (r.toggleAttribute("internals-invalid", !d), r.toggleAttribute("internals-valid", d), r.setAttribute("aria-invalid", `${!d}`)) : S.set(r, this);
395
+ g.set(this, d ? "" : i), r.isConnected ? (r.toggleAttribute("internals-invalid", !d), r.toggleAttribute("internals-valid", d), r.setAttribute("aria-invalid", `${!d}`)) : x.set(r, this);
402
396
  }
403
397
  get shadowRoot() {
404
- const e = n.get(this), i = q.get(e);
398
+ const e = o.get(this), i = q.get(e);
405
399
  return i || null;
406
400
  }
407
401
  get validationMessage() {
408
- const e = n.get(this);
409
- return b(e, "Failed to read the 'validationMessage' property from 'ElementInternals': The target element is not a form-associated custom element."), w.get(this);
402
+ const e = o.get(this);
403
+ return w(e, "Failed to read the 'validationMessage' property from 'ElementInternals': The target element is not a form-associated custom element."), g.get(this);
410
404
  }
411
405
  get validity() {
412
- const e = n.get(this);
413
- return b(e, "Failed to read the 'validity' property from 'ElementInternals': The target element is not a form-associated custom element."), l.get(this);
406
+ const e = o.get(this);
407
+ return w(e, "Failed to read the 'validity' property from 'ElementInternals': The target element is not a form-associated custom element."), c.get(this);
414
408
  }
415
409
  get willValidate() {
416
- const e = n.get(this);
417
- return b(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"));
410
+ const e = o.get(this);
411
+ return w(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"));
418
412
  }
419
413
  }
420
- function xe() {
414
+ function Ae() {
421
415
  if (typeof window > "u" || !window.ElementInternals || !HTMLElement.prototype.attachInternals)
422
416
  return !1;
423
417
  class t extends HTMLElement {
@@ -454,9 +448,9 @@ const Ne = `*,*:after,*:before{box-sizing:inherit}*,*:before,*:after{cursor:inhe
454
448
  const e = CustomElementRegistry.prototype.define;
455
449
  CustomElementRegistry.prototype.define = function(i, a, r) {
456
450
  if (a.formAssociated) {
457
- const o = a.prototype.connectedCallback;
451
+ const s = a.prototype.connectedCallback;
458
452
  a.prototype.connectedCallback = function() {
459
- j.has(this) || (j.set(this, !0), this.hasAttribute("disabled") && $(this, !0)), o != null && o.apply(this), te(this);
453
+ j.has(this) || (j.set(this, !0), this.hasAttribute("disabled") && $(this, !0)), s != null && s.apply(this), te(this);
460
454
  };
461
455
  }
462
456
  e.call(this, i, a, r);
@@ -468,45 +462,53 @@ const Ne = `*,*:after,*:before{box-sizing:inherit}*,*:before,*:after{cursor:inhe
468
462
  throw new Error("Failed to execute 'attachInternals' on 'HTMLElement': Unable to attach ElementInternals to non-custom elements.");
469
463
  } else
470
464
  return {};
471
- if (c.has(this))
465
+ if (l.has(this))
472
466
  throw new DOMException("DOMException: Failed to execute 'attachInternals' on 'HTMLElement': ElementInternals for the specified element was already attached.");
473
467
  return new re(this);
474
468
  }), typeof Element < "u") {
475
469
  let e = function(...a) {
476
470
  const r = i.apply(this, a);
477
- if (q.set(this, r), P()) {
478
- const o = new MutationObserver(O);
479
- window.ShadyDOM ? o.observe(this, _) : o.observe(r, _), M.set(this, o);
471
+ if (q.set(this, r), T()) {
472
+ const s = new MutationObserver(O);
473
+ window.ShadyDOM ? s.observe(this, _) : s.observe(r, _), P.set(this, s);
480
474
  }
481
475
  return r;
482
476
  };
483
477
  const i = Element.prototype.attachShadow;
484
478
  Element.prototype.attachShadow = e;
485
479
  }
486
- P() && typeof document < "u" && new MutationObserver(O).observe(document.documentElement, _), typeof HTMLFormElement < "u" && Ce(), (t || typeof window < "u" && !window.CustomStateSet) && H();
480
+ T() && typeof document < "u" && new MutationObserver(O).observe(document.documentElement, _), typeof HTMLFormElement < "u" && Ce(), (t || typeof window < "u" && !window.CustomStateSet) && H();
487
481
  }
488
482
  }
489
- return !!customElements.polyfillWrapFlushCallback || (xe() ? typeof window < "u" && !window.CustomStateSet && H(HTMLElement.prototype.attachInternals) : ne(!1)), g.forceCustomStateSetPolyfill = H, g.forceElementInternalsPolyfill = ne, Object.defineProperty(g, "__esModule", { value: !0 }), g;
483
+ return !!customElements.polyfillWrapFlushCallback || (Ae() ? typeof window < "u" && !window.CustomStateSet && H(HTMLElement.prototype.attachInternals) : ne(!1)), v.forceCustomStateSetPolyfill = H, v.forceElementInternalsPolyfill = ne, Object.defineProperty(v, "__esModule", { value: !0 }), v;
490
484
  })({});
491
485
  })();
492
- var Oe = Object.defineProperty, _e = Object.getOwnPropertyDescriptor, m = (g, n, l, h) => {
493
- for (var c = h > 1 ? void 0 : h ? _e(n, l) : n, w = g.length - 1, k; w >= 0; w--)
494
- (k = g[w]) && (c = (h ? k(n, l, c) : k(c)) || c);
495
- return h && c && Oe(n, l, c), c;
486
+ const Oe = `*,*:after,*:before{box-sizing:inherit}*,*:before,*:after{cursor:inherit}.c-switch-wrapper{display:inline-flex;align-items:center;gap:var(--dt-spacing-b);font-family:var(--dt-font-body-l-family);cursor:pointer}.c-switch-wrapper[disabled]{cursor:not-allowed}.c-switch{--switch-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(--switch-bg-color)}@media (prefers-reduced-motion: no-preference){.c-switch{transition:background-color .15s cubic-bezier(.4,0,.9,1) 0s}}.c-switch:hover{background-color:hsl(var(--dt-color-interactive-form-h),var(--dt-color-interactive-form-s),calc(var(--dt-color-interactive-form-l) - var(--dt-color-hover-01)))}.c-switch:focus,.c-switch:focus-within{box-shadow:0 0 0 2px var(--dt-color-focus-inner),0 0 0 4px var(--dt-color-focus-outer);outline:none}.c-switch:active{background-color:hsl(var(--dt-color-interactive-form-h),var(--dt-color-interactive-form-s),calc(var(--dt-color-interactive-form-l) - var(--dt-color-active-01)))}.c-switch[checked]{background-color:var(--switch-bg-color--checked)}@media (prefers-reduced-motion: no-preference){.c-switch[checked]{transition:background-color .15s cubic-bezier(.4,0,.9,1) 0s}}.c-switch[checked]:hover{background-color:hsl(var(--dt-color-interactive-brand-h),var(--dt-color-interactive-brand-s),calc(var(--dt-color-interactive-brand-l) - var(--dt-color-hover-01)))}.c-switch[checked]:focus,.c-switch[checked]:focus-within{background-color:var(--switch-bg-color--checked)}.c-switch[checked]:active{background-color:hsl(var(--dt-color-interactive-brand-h),var(--dt-color-interactive-brand-s),calc(var(--dt-color-interactive-brand-l) - var(--dt-color-active-01)))}[disabled] .c-switch{background-color:var(--switch-bg-color--disabled);pointer-events:none}.c-switch-input{position:absolute;width:1px;height:1px;margin:-1px;padding:0;overflow:hidden;clip:rect(0,0,0,0);border:0;left:50%;transform:translate(-50%) translateY(-50%);bottom:0}.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)}@media (prefers-reduced-motion: no-preference){.c-switch-control{transition:transform .15s cubic-bezier(.4,0,.9,1) 0s}}.c-switch-wrapper--rtl .c-switch-control{position:absolute;left:initial;right:2px}.c-switch-input:checked+.c-switch-control{transform:translate(var(--switch-translation))}@media (prefers-reduced-motion: no-preference){.c-switch-input:checked+.c-switch-control{transition:transform .15s cubic-bezier(.4,0,.9,1) 0s}}.c-switch-input:checked+.c-switch-control .c-pieIcon--check{color:var(--switch-bg-color--checked)}@media (prefers-reduced-motion: no-preference){.c-switch-input:checked+.c-switch-control .c-pieIcon--check{transition:color .15s cubic-bezier(.4,0,.9,1) 0s}}.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)}@media (prefers-reduced-motion: no-preference){.c-switch-input:disabled~.c-switch-control .c-pieIcon--check{transition:color .15s cubic-bezier(.4,0,.9,1) 0s}}.c-switch-description{position:absolute;display:block;height:1px;width:1px;overflow:hidden;padding:1px;white-space:nowrap}.c-switch-wrapper--rtl .c-switch-input:checked+.c-switch-control{transform:translate(calc(-1 * var(--switch-translation)))}@media (prefers-reduced-motion: no-preference){.c-switch-wrapper--rtl .c-switch-input:checked+.c-switch-control{transition:transform .15s cubic-bezier(.4,0,.9,1) 0s}}
487
+ `, _e = ["leading", "trailing"], je = "change", M = {
488
+ checked: !1,
489
+ disabled: !1,
490
+ labelPlacement: "leading",
491
+ required: !1,
492
+ value: "on"
493
+ };
494
+ var $e = Object.defineProperty, Re = Object.getOwnPropertyDescriptor, m = (v, o, c, h) => {
495
+ for (var l = h > 1 ? void 0 : h ? Re(o, c) : o, g = v.length - 1, k; g >= 0; g--)
496
+ (k = v[g]) && (l = (h ? k(o, c, l) : k(l)) || l);
497
+ return h && l && $e(o, c, l), l;
496
498
  };
497
499
  const ce = "pie-switch";
498
- class p extends Ie(Se(Fe)) {
500
+ class p extends Ve(Te(xe)) {
499
501
  constructor() {
500
- super(...arguments), this.labelPlacement = x.labelPlacement, this.checked = x.checked, this.required = x.required, this.value = x.value, this.disabled = x.disabled;
502
+ super(...arguments), this.labelPlacement = M.labelPlacement, this.checked = M.checked, this.required = M.required, this.value = M.value, this.disabled = M.disabled;
501
503
  }
502
- firstUpdated(n) {
503
- var l;
504
- super.firstUpdated(n), this.handleFormAssociation(), (l = this.input) == null || l.addEventListener("invalid", (h) => {
505
- this.dispatchEvent(new Event("invalid", h));
504
+ firstUpdated() {
505
+ var o;
506
+ this.handleFormAssociation(), (o = this.input) == null || o.addEventListener("invalid", (c) => {
507
+ this.dispatchEvent(new Event("invalid", c));
506
508
  });
507
509
  }
508
- updated(n) {
509
- super.updated(n), this.handleFormAssociation();
510
+ updated() {
511
+ this.handleFormAssociation();
510
512
  }
511
513
  /**
512
514
  * Ensures that the form value and validation state are in sync with the component.
@@ -518,10 +520,10 @@ class p extends Ie(Se(Fe)) {
518
520
  * The handleChange function updates the checkbox state and emits an event for consumers.
519
521
  * @param {Event} event - This should be the change event that was listened for on an input element with `type="checkbox"`.
520
522
  */
521
- handleChange(n) {
522
- const { checked: l } = n == null ? void 0 : n.currentTarget;
523
- this.checked = l;
524
- const h = Ve(n);
523
+ handleChange(o) {
524
+ const { checked: c } = o == null ? void 0 : o.currentTarget;
525
+ this.checked = c;
526
+ const h = Le(o);
525
527
  this.dispatchEvent(h), this.handleFormAssociation();
526
528
  }
527
529
  /**
@@ -544,9 +546,9 @@ class p extends Ie(Se(Fe)) {
544
546
  * Allows a consumer to set a custom validation message on the switch. An empty string counts as valid.
545
547
  * https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/setCustomValidity
546
548
  */
547
- setCustomValidity(n) {
548
- var l;
549
- (l = this.input) == null || l.setCustomValidity(n), this._internals.setValidity(this.validity, this.validationMessage, this.input);
549
+ setCustomValidity(o) {
550
+ var c;
551
+ (c = this.input) == null || c.setCustomValidity(o), this._internals.setValidity(this.validity, this.validationMessage, this.input);
550
552
  }
551
553
  /**
552
554
  * (Read-only) returns a ValidityState with the validity states that this element is in.
@@ -564,68 +566,75 @@ class p extends Ie(Se(Fe)) {
564
566
  return this.input.validationMessage;
565
567
  }
566
568
  /**
567
- * Renders the label for a switch if provided.
568
- * if invalid value is passed, nothing gets rendered
569
+ * If a label is provided, renders it if `labelPlacement` matches the given position.
570
+ * If no label is provided, or `labelPlacement` does not match the given position, nothing is rendered.
569
571
  *
570
572
  * @private
571
573
  */
572
- renderSwitchLabel() {
573
- const { label: n, labelPlacement: l } = this;
574
- return n ? A`
575
- <span data-test-id="switch-label-${l}">
576
- ${n}
577
- </span>` : A``;
574
+ renderSwitchLabel(o) {
575
+ const { label: c, labelPlacement: h } = this;
576
+ return !c || h !== o ? L : N`
577
+ <span data-test-id="switch-label-${h}">
578
+ ${c}
579
+ </span>`;
580
+ }
581
+ renderAriaDescription() {
582
+ var o;
583
+ return (o = this.aria) != null && o.describedBy ? N`
584
+ <div
585
+ id="switch-description"
586
+ data-test-id="switch-description"
587
+ class="c-switch-description">
588
+ ${this.aria.describedBy}
589
+ </div>` : L;
578
590
  }
579
591
  render() {
580
592
  const {
581
- labelPlacement: n,
582
- aria: l,
583
- checked: h,
584
- required: c,
585
- disabled: w,
586
- isRTL: k
587
- } = this, M = "switch-description";
588
- return A`
593
+ aria: o,
594
+ checked: c,
595
+ disabled: h,
596
+ isRTL: l,
597
+ required: g
598
+ } = this;
599
+ return N`
589
600
  <label
590
- class="c-switch-wrapper"
591
- ?data-is-rtl=${k}
592
- ?disabled=${w}>
593
- ${n === "leading" ? this.renderSwitchLabel() : C}
601
+ class="${Se({
602
+ "c-switch-wrapper": !0,
603
+ "c-switch-wrapper--rtl": l
604
+ })}"
605
+ ?disabled=${h}>
606
+ ${this.renderSwitchLabel("leading")}
594
607
  <div
595
608
  data-test-id="switch-component"
596
609
  class="c-switch"
597
- ?checked=${h}>
610
+ ?checked=${c}>
598
611
  <input
599
612
  data-test-id="switch-input"
600
613
  role="switch"
601
614
  type="checkbox"
602
615
  class="c-switch-input"
603
- .required=${c}
604
- .checked="${h}"
605
- .disabled="${w}"
616
+ .required=${g}
617
+ .checked="${c}"
618
+ .disabled="${h}"
606
619
  @change="${this.handleChange}"
607
- aria-label="${(l == null ? void 0 : l.label) || C}"
608
- aria-describedby="${l != null && l.describedBy ? M : C}">
620
+ aria-label="${Ie(o == null ? void 0 : o.label)}"
621
+ aria-describedby="${o != null && o.describedBy ? "switch-description" : L}">
609
622
  <div class="c-switch-control">
610
- ${h ? A`<icon-check></icon-check>` : C}
623
+ ${c ? N`<icon-check></icon-check>` : L}
611
624
  </div>
612
625
  </div>
613
- ${n === "trailing" ? this.renderSwitchLabel() : C}
614
- ${l != null && l.describedBy ? A`<div id="${M}" data-test-id="${M}" class="c-switch-description">${l == null ? void 0 : l.describedBy}</div>` : C}
615
- </label>
616
- `;
626
+ ${this.renderSwitchLabel("trailing")}
627
+ ${this.renderAriaDescription()}
628
+ </label>`;
617
629
  }
618
630
  }
619
- p.styles = Ae(Ne);
620
- m([
621
- le('input[type="checkbox"]')
622
- ], p.prototype, "input", 2);
631
+ p.styles = Fe(Oe);
623
632
  m([
624
633
  E({ type: String })
625
634
  ], p.prototype, "label", 2);
626
635
  m([
627
636
  E({ type: String }),
628
- Te(ce, Pe, x.labelPlacement)
637
+ Ne(ce, _e, M.labelPlacement)
629
638
  ], p.prototype, "labelPlacement", 2);
630
639
  m([
631
640
  E({ type: Object })
@@ -645,13 +654,16 @@ m([
645
654
  m([
646
655
  E({ type: Boolean, reflect: !0 })
647
656
  ], p.prototype, "disabled", 2);
657
+ m([
658
+ le('input[type="checkbox"]')
659
+ ], p.prototype, "input", 2);
648
660
  m([
649
661
  le("label")
650
662
  ], p.prototype, "focusTarget", 2);
651
- Le(ce, p);
663
+ Pe(ce, p);
652
664
  export {
653
- ze as ON_SWITCH_CHANGED_EVENT,
665
+ je as ON_SWITCH_CHANGED_EVENT,
654
666
  p as PieSwitch,
655
- x as defaultProps,
656
- Pe as labelPlacements
667
+ M as defaultProps,
668
+ _e as labelPlacements
657
669
  };