@m3e/switch 1.0.0-rc.1

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.
Files changed (45) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +174 -0
  3. package/cem.config.mjs +16 -0
  4. package/demo/index.html +65 -0
  5. package/dist/css-custom-data.json +352 -0
  6. package/dist/custom-elements.json +633 -0
  7. package/dist/html-custom-data.json +38 -0
  8. package/dist/index.js +774 -0
  9. package/dist/index.js.map +1 -0
  10. package/dist/index.min.js +399 -0
  11. package/dist/index.min.js.map +1 -0
  12. package/dist/src/SwitchElement.d.ts +147 -0
  13. package/dist/src/SwitchElement.d.ts.map +1 -0
  14. package/dist/src/SwitchIcons.d.ts +3 -0
  15. package/dist/src/SwitchIcons.d.ts.map +1 -0
  16. package/dist/src/index.d.ts +3 -0
  17. package/dist/src/index.d.ts.map +1 -0
  18. package/dist/src/styles/SwitchHandleStyle.d.ts +6 -0
  19. package/dist/src/styles/SwitchHandleStyle.d.ts.map +1 -0
  20. package/dist/src/styles/SwitchIconStyle.d.ts +6 -0
  21. package/dist/src/styles/SwitchIconStyle.d.ts.map +1 -0
  22. package/dist/src/styles/SwitchStateLayerStyle.d.ts +6 -0
  23. package/dist/src/styles/SwitchStateLayerStyle.d.ts.map +1 -0
  24. package/dist/src/styles/SwitchStyle.d.ts +6 -0
  25. package/dist/src/styles/SwitchStyle.d.ts.map +1 -0
  26. package/dist/src/styles/SwitchToken.d.ts +76 -0
  27. package/dist/src/styles/SwitchToken.d.ts.map +1 -0
  28. package/dist/src/styles/SwitchTrackStyle.d.ts +6 -0
  29. package/dist/src/styles/SwitchTrackStyle.d.ts.map +1 -0
  30. package/dist/src/styles/index.d.ts +6 -0
  31. package/dist/src/styles/index.d.ts.map +1 -0
  32. package/eslint.config.mjs +13 -0
  33. package/package.json +48 -0
  34. package/rollup.config.js +32 -0
  35. package/src/SwitchElement.ts +268 -0
  36. package/src/SwitchIcons.ts +2 -0
  37. package/src/index.ts +2 -0
  38. package/src/styles/SwitchHandleStyle.ts +140 -0
  39. package/src/styles/SwitchIconStyle.ts +89 -0
  40. package/src/styles/SwitchStateLayerStyle.ts +43 -0
  41. package/src/styles/SwitchStyle.ts +30 -0
  42. package/src/styles/SwitchToken.ts +145 -0
  43. package/src/styles/SwitchTrackStyle.ts +104 -0
  44. package/src/styles/index.ts +5 -0
  45. package/tsconfig.json +9 -0
package/dist/index.js ADDED
@@ -0,0 +1,774 @@
1
+ /**
2
+ * @license MIT
3
+ * Copyright (c) 2025 matraic
4
+ * See LICENSE file in the project root for full license text.
5
+ */
6
+ import { unsafeCSS, css, LitElement, html } from 'lit';
7
+ import { DesignToken, Labelled, Dirty, Touched, ConstraintValidation, Checked, FormAssociated, KeyboardClick, Focusable, Disabled, AttachInternals, Role, HoverController, PressedController, formValue } from '@m3e/core';
8
+
9
+ /******************************************************************************
10
+ Copyright (c) Microsoft Corporation.
11
+
12
+ Permission to use, copy, modify, and/or distribute this software for any
13
+ purpose with or without fee is hereby granted.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
16
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
17
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
18
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
19
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
20
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
21
+ PERFORMANCE OF THIS SOFTWARE.
22
+ ***************************************************************************** */
23
+ /* global Reflect, Promise, SuppressedError, Symbol, Iterator */
24
+
25
+
26
+ function __decorate(decorators, target, key, desc) {
27
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
28
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
29
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
30
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
31
+ }
32
+
33
+ function __classPrivateFieldGet(receiver, state, kind, f) {
34
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
35
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
36
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
37
+ }
38
+
39
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
40
+ var e = new Error(message);
41
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
42
+ };
43
+
44
+ /**
45
+ * @license
46
+ * Copyright 2017 Google LLC
47
+ * SPDX-License-Identifier: BSD-3-Clause
48
+ */
49
+ const t$1=t=>(e,o)=>{ void 0!==o?o.addInitializer((()=>{customElements.define(t,e);})):customElements.define(t,e);};
50
+
51
+ /**
52
+ * @license
53
+ * Copyright 2019 Google LLC
54
+ * SPDX-License-Identifier: BSD-3-Clause
55
+ */
56
+ const t=globalThis,e$3=t.ShadowRoot&&(void 0===t.ShadyCSS||t.ShadyCSS.nativeShadow)&&"adoptedStyleSheets"in Document.prototype&&"replace"in CSSStyleSheet.prototype,s=Symbol(),o$2=new WeakMap;let n$2 = class n{constructor(t,e,o){if(this._$cssResult$=true,o!==s)throw Error("CSSResult is not constructable. Use `unsafeCSS` or `css` instead.");this.cssText=t,this.t=e;}get styleSheet(){let t=this.o;const s=this.t;if(e$3&&void 0===t){const e=void 0!==s&&1===s.length;e&&(t=o$2.get(s)),void 0===t&&((this.o=t=new CSSStyleSheet).replaceSync(this.cssText),e&&o$2.set(s,t));}return t}toString(){return this.cssText}};const r$2=t=>new n$2("string"==typeof t?t:t+"",void 0,s),S=(s,o)=>{if(e$3)s.adoptedStyleSheets=o.map((t=>t instanceof CSSStyleSheet?t:t.styleSheet));else for(const e of o){const o=document.createElement("style"),n=t.litNonce;void 0!==n&&o.setAttribute("nonce",n),o.textContent=e.cssText,s.appendChild(o);}},c$1=e$3?t=>t:t=>t instanceof CSSStyleSheet?(t=>{let e="";for(const s of t.cssRules)e+=s.cssText;return r$2(e)})(t):t;
57
+
58
+ /**
59
+ * @license
60
+ * Copyright 2017 Google LLC
61
+ * SPDX-License-Identifier: BSD-3-Clause
62
+ */const{is:i,defineProperty:e$2,getOwnPropertyDescriptor:h,getOwnPropertyNames:r$1,getOwnPropertySymbols:o$1,getPrototypeOf:n$1}=Object,a=globalThis,c=a.trustedTypes,l=c?c.emptyScript:"",p=a.reactiveElementPolyfillSupport,d=(t,s)=>t,u={toAttribute(t,s){switch(s){case Boolean:t=t?l:null;break;case Object:case Array:t=null==t?t:JSON.stringify(t);}return t},fromAttribute(t,s){let i=t;switch(s){case Boolean:i=null!==t;break;case Number:i=null===t?null:Number(t);break;case Object:case Array:try{i=JSON.parse(t);}catch(t){i=null;}}return i}},f=(t,s)=>!i(t,s),b={attribute:true,type:String,converter:u,reflect:false,useDefault:false,hasChanged:f};Symbol.metadata??=Symbol("metadata"),a.litPropertyMetadata??=new WeakMap;class y extends HTMLElement{static addInitializer(t){this._$Ei(),(this.l??=[]).push(t);}static get observedAttributes(){return this.finalize(),this._$Eh&&[...this._$Eh.keys()]}static createProperty(t,s=b){if(s.state&&(s.attribute=false),this._$Ei(),this.prototype.hasOwnProperty(t)&&((s=Object.create(s)).wrapped=true),this.elementProperties.set(t,s),!s.noAccessor){const i=Symbol(),h=this.getPropertyDescriptor(t,i,s);void 0!==h&&e$2(this.prototype,t,h);}}static getPropertyDescriptor(t,s,i){const{get:e,set:r}=h(this.prototype,t)??{get(){return this[s]},set(t){this[s]=t;}};return {get:e,set(s){const h=e?.call(this);r?.call(this,s),this.requestUpdate(t,h,i);},configurable:true,enumerable:true}}static getPropertyOptions(t){return this.elementProperties.get(t)??b}static _$Ei(){if(this.hasOwnProperty(d("elementProperties")))return;const t=n$1(this);t.finalize(),void 0!==t.l&&(this.l=[...t.l]),this.elementProperties=new Map(t.elementProperties);}static finalize(){if(this.hasOwnProperty(d("finalized")))return;if(this.finalized=true,this._$Ei(),this.hasOwnProperty(d("properties"))){const t=this.properties,s=[...r$1(t),...o$1(t)];for(const i of s)this.createProperty(i,t[i]);}const t=this[Symbol.metadata];if(null!==t){const s=litPropertyMetadata.get(t);if(void 0!==s)for(const[t,i]of s)this.elementProperties.set(t,i);}this._$Eh=new Map;for(const[t,s]of this.elementProperties){const i=this._$Eu(t,s);void 0!==i&&this._$Eh.set(i,t);}this.elementStyles=this.finalizeStyles(this.styles);}static finalizeStyles(s){const i=[];if(Array.isArray(s)){const e=new Set(s.flat(1/0).reverse());for(const s of e)i.unshift(c$1(s));}else void 0!==s&&i.push(c$1(s));return i}static _$Eu(t,s){const i=s.attribute;return false===i?void 0:"string"==typeof i?i:"string"==typeof t?t.toLowerCase():void 0}constructor(){super(),this._$Ep=void 0,this.isUpdatePending=false,this.hasUpdated=false,this._$Em=null,this._$Ev();}_$Ev(){this._$ES=new Promise((t=>this.enableUpdating=t)),this._$AL=new Map,this._$E_(),this.requestUpdate(),this.constructor.l?.forEach((t=>t(this)));}addController(t){(this._$EO??=new Set).add(t),void 0!==this.renderRoot&&this.isConnected&&t.hostConnected?.();}removeController(t){this._$EO?.delete(t);}_$E_(){const t=new Map,s=this.constructor.elementProperties;for(const i of s.keys())this.hasOwnProperty(i)&&(t.set(i,this[i]),delete this[i]);t.size>0&&(this._$Ep=t);}createRenderRoot(){const t=this.shadowRoot??this.attachShadow(this.constructor.shadowRootOptions);return S(t,this.constructor.elementStyles),t}connectedCallback(){this.renderRoot??=this.createRenderRoot(),this.enableUpdating(true),this._$EO?.forEach((t=>t.hostConnected?.()));}enableUpdating(t){}disconnectedCallback(){this._$EO?.forEach((t=>t.hostDisconnected?.()));}attributeChangedCallback(t,s,i){this._$AK(t,i);}_$ET(t,s){const i=this.constructor.elementProperties.get(t),e=this.constructor._$Eu(t,i);if(void 0!==e&&true===i.reflect){const h=(void 0!==i.converter?.toAttribute?i.converter:u).toAttribute(s,i.type);this._$Em=t,null==h?this.removeAttribute(e):this.setAttribute(e,h),this._$Em=null;}}_$AK(t,s){const i=this.constructor,e=i._$Eh.get(t);if(void 0!==e&&this._$Em!==e){const t=i.getPropertyOptions(e),h="function"==typeof t.converter?{fromAttribute:t.converter}:void 0!==t.converter?.fromAttribute?t.converter:u;this._$Em=e;const r=h.fromAttribute(s,t.type);this[e]=r??this._$Ej?.get(e)??r,this._$Em=null;}}requestUpdate(t,s,i){if(void 0!==t){const e=this.constructor,h=this[t];if(i??=e.getPropertyOptions(t),!((i.hasChanged??f)(h,s)||i.useDefault&&i.reflect&&h===this._$Ej?.get(t)&&!this.hasAttribute(e._$Eu(t,i))))return;this.C(t,s,i);} false===this.isUpdatePending&&(this._$ES=this._$EP());}C(t,s,{useDefault:i,reflect:e,wrapped:h},r){i&&!(this._$Ej??=new Map).has(t)&&(this._$Ej.set(t,r??s??this[t]),true!==h||void 0!==r)||(this._$AL.has(t)||(this.hasUpdated||i||(s=void 0),this._$AL.set(t,s)),true===e&&this._$Em!==t&&(this._$Eq??=new Set).add(t));}async _$EP(){this.isUpdatePending=true;try{await this._$ES;}catch(t){Promise.reject(t);}const t=this.scheduleUpdate();return null!=t&&await t,!this.isUpdatePending}scheduleUpdate(){return this.performUpdate()}performUpdate(){if(!this.isUpdatePending)return;if(!this.hasUpdated){if(this.renderRoot??=this.createRenderRoot(),this._$Ep){for(const[t,s]of this._$Ep)this[t]=s;this._$Ep=void 0;}const t=this.constructor.elementProperties;if(t.size>0)for(const[s,i]of t){const{wrapped:t}=i,e=this[s];true!==t||this._$AL.has(s)||void 0===e||this.C(s,void 0,i,e);}}let t=false;const s=this._$AL;try{t=this.shouldUpdate(s),t?(this.willUpdate(s),this._$EO?.forEach((t=>t.hostUpdate?.())),this.update(s)):this._$EM();}catch(s){throw t=false,this._$EM(),s}t&&this._$AE(s);}willUpdate(t){}_$AE(t){this._$EO?.forEach((t=>t.hostUpdated?.())),this.hasUpdated||(this.hasUpdated=true,this.firstUpdated(t)),this.updated(t);}_$EM(){this._$AL=new Map,this.isUpdatePending=false;}get updateComplete(){return this.getUpdateComplete()}getUpdateComplete(){return this._$ES}shouldUpdate(t){return true}update(t){this._$Eq&&=this._$Eq.forEach((t=>this._$ET(t,this[t]))),this._$EM();}updated(t){}firstUpdated(t){}}y.elementStyles=[],y.shadowRootOptions={mode:"open"},y[d("elementProperties")]=new Map,y[d("finalized")]=new Map,p?.({ReactiveElement:y}),(a.reactiveElementVersions??=[]).push("2.1.1");
63
+
64
+ /**
65
+ * @license
66
+ * Copyright 2017 Google LLC
67
+ * SPDX-License-Identifier: BSD-3-Clause
68
+ */const o={attribute:true,type:String,converter:u,reflect:false,hasChanged:f},r=(t=o,e,r)=>{const{kind:n,metadata:i}=r;let s=globalThis.litPropertyMetadata.get(i);if(void 0===s&&globalThis.litPropertyMetadata.set(i,s=new Map),"setter"===n&&((t=Object.create(t)).wrapped=true),s.set(r.name,t),"accessor"===n){const{name:o}=r;return {set(r){const n=e.get.call(this);e.set.call(this,r),this.requestUpdate(o,n,t);},init(e){return void 0!==e&&this.C(o,void 0,t,e),e}}}if("setter"===n){const{name:o}=r;return function(r){const n=this[o];e.call(this,r),this.requestUpdate(o,n,t);}}throw Error("Unsupported decorator location: "+n)};function n(t){return (e,o)=>"object"==typeof o?r(t,e,o):((t,e,o)=>{const r=e.hasOwnProperty(o);return e.constructor.createProperty(o,t),r?Object.getOwnPropertyDescriptor(e,o):void 0})(t,e,o)}
69
+
70
+ /**
71
+ * @license
72
+ * Copyright 2017 Google LLC
73
+ * SPDX-License-Identifier: BSD-3-Clause
74
+ */
75
+ const e$1=(e,t,c)=>(c.configurable=true,c.enumerable=true,Reflect.decorate&&"object"!=typeof t&&Object.defineProperty(e,t,c),c);
76
+
77
+ /**
78
+ * @license
79
+ * Copyright 2017 Google LLC
80
+ * SPDX-License-Identifier: BSD-3-Clause
81
+ */function e(e,r){return (n,s,i)=>{const o=t=>t.renderRoot?.querySelector(e)??null;return e$1(n,s,{get(){return o(this)}})}}
82
+
83
+ /**
84
+ * Component design tokens that control `M3eSwitchElement`.
85
+ * @internal
86
+ */
87
+ const SwitchToken = {
88
+ selectedIconColor: unsafeCSS(`var(--m3e-switch-selected-icon-color, ${DesignToken.color.onPrimaryContainer})`),
89
+ selectedIconSize: unsafeCSS("var(--m3e-switch-selected-icon-size, 1rem)"),
90
+ unselectedIconColor: unsafeCSS(`var(--m3e-switch-unselected-icon-color, ${DesignToken.color.surfaceContainerHighest})`),
91
+ unselectedIconSize: unsafeCSS("var(--m3e-switch-unselected-icon-size, 1rem)"),
92
+ trackHeight: unsafeCSS("var(--m3e-switch-track-height, 2rem)"),
93
+ trackWidth: unsafeCSS("var(--m3e-switch-track-width, 3.25rem)"),
94
+ trackOutlineColor: unsafeCSS(`var(--m3e-switch-track-outline-color, ${DesignToken.color.outline})`),
95
+ trackOutlineWidth: unsafeCSS("var(--m3e-switch-track-outline-width, 0.125rem)"),
96
+ trackShape: unsafeCSS(`var(--m3e-switch-track-shape, ${DesignToken.shape.corner.full})`),
97
+ selectedTrackColor: unsafeCSS(`var(--m3e-switch-selected-track-color, ${DesignToken.color.primary})`),
98
+ unselectedTrackColor: unsafeCSS(`var(--m3e-switch-unselected-track-color, ${DesignToken.color.surfaceContainerHighest})`),
99
+ unselectedHandleHeight: unsafeCSS("var(--m3e-switch-unselected-handle-height, 1rem)"),
100
+ unselectedHandleWidth: unsafeCSS("var(--m3e-switch-unselected-handle-width, 1rem)"),
101
+ withIconHandleHeight: unsafeCSS("var(--m3e-switch-with-icon-handle-height, 1.5rem)"),
102
+ withIconHandleWidth: unsafeCSS("var(--m3e-switch-with-icon-handle-width, 1.5rem)"),
103
+ selectedHandleHeight: unsafeCSS("var(--m3e-switch-selected-handle-height, 1.5rem)"),
104
+ selectedHandleWidth: unsafeCSS("var(--m3e-switch-selected-handle-width, 1.5rem)"),
105
+ pressedHandleHeight: unsafeCSS("var(--m3e-switch-pressed-handle-height, 1.75rem)"),
106
+ pressedHandleWidth: unsafeCSS("var(--m3e-switch-pressed-handle-width, 1.75rem)"),
107
+ handleShape: unsafeCSS(`var(--m3e-switch-handle-shape, ${DesignToken.shape.corner.full})`),
108
+ selectedHandleColor: unsafeCSS(`var(--m3e-switch-selected-handle-color, ${DesignToken.color.onPrimary})`),
109
+ unselectedHandleColor: unsafeCSS(`var(--m3e-switch-unselected-handle-color, ${DesignToken.color.outline})`),
110
+ stateLayerSize: unsafeCSS("var(--m3e-switch-state-layer-size, 2.5rem)"),
111
+ stateLayerShape: unsafeCSS(`var(--m3e-switch-state-layer-shape, ${DesignToken.shape.corner.full})`),
112
+ disabledSelectedIconColor: unsafeCSS(`var(--m3e-switch-disabled-selected-icon-color, ${DesignToken.color.onSurface})`),
113
+ disabledSelectedIconOpacity: unsafeCSS("var(--m3e-switch-disabled-selected-icon-opacity, 38%)"),
114
+ disabledUnselectedIconColor: unsafeCSS(`var(--m3e-switch-disabled-unselected-icon-color, ${DesignToken.color.surfaceContainerHighest})`),
115
+ disabledUnselectedIconOpacity: unsafeCSS("var(--m3e-switch-disabled-unselected-icon-opacity, 38%)"),
116
+ disabledTrackOpacity: unsafeCSS("var(--m3e-switch-disabled-track-opacity, 12%)"),
117
+ disabledSelectedTrackColor: unsafeCSS(`var(--m3e-switch-disabled-selected-track-color, ${DesignToken.color.onSurface})`),
118
+ disabledUnselectedTrackColor: unsafeCSS(`var(--m3e-switch-disabled-unselected-track-color, ${DesignToken.color.surfaceContainerHighest})`),
119
+ disabledUnselectedTrackOutlineColor: unsafeCSS(`var(--m3e-switch-disabled-unselected-track-outline-color, ${DesignToken.color.onSurface})`),
120
+ disabledUnselectedHandleOpacity: unsafeCSS("var(--m3e-switch-disabled-unselected-handle-opacity, 38%)"),
121
+ disabledSelectedHandleOpacity: unsafeCSS("var(--m3e-switch-disabled-selected-handle-opacity, 100%)"),
122
+ disabledSelectedHandleColor: unsafeCSS(`var(--m3e-switch-disabled-selected-handle-color, ${DesignToken.color.surface})`),
123
+ disabledUnselectedHandleColor: unsafeCSS(`var(--m3e-switch-disabled-unselected-handle-color, ${DesignToken.color.onSurface})`),
124
+ selectedHoverIconColor: unsafeCSS(`var(--m3e-switch-selected-hover-icon-color, ${DesignToken.color.onPrimaryContainer})`),
125
+ unselectedHoverIconColor: unsafeCSS(`var(--m3e-switch-unselected-hover-icon-color, ${DesignToken.color.surfaceContainerHighest})`),
126
+ selectedHoverTrackColor: unsafeCSS(`var(--m3e-switch-selected-hover-track-color, ${DesignToken.color.primary})`),
127
+ selectedHoverStateLayerColor: unsafeCSS(`var(--m3e-switch-selected-hover-state-layer-color, ${DesignToken.color.primary})`),
128
+ selectedHoverStateLayerOpacity: unsafeCSS("var(--m3e-switch-selected-hover-state-layer-opacity, 8%)"),
129
+ unselectedHoverTrackColor: unsafeCSS(`var(--m3e-switch-unselected-hover-track-color, ${DesignToken.color.surfaceContainerHighest})`),
130
+ unselectedHoverTrackOutlineColor: unsafeCSS(`var(--m3e-switch-unselected-hover-track-outline-color, ${DesignToken.color.outline})`),
131
+ unselectedHoverStateLayerColor: unsafeCSS(`var(--m3e-switch-unselected-hover-state-layer-color, ${DesignToken.color.onSurface})`),
132
+ unselectedHoverStateLayerOpacity: unsafeCSS("var(--m3e-switch-unselected-hover-state-layer-opacity, 8%)"),
133
+ selectedHoverHandleColor: unsafeCSS(`var(--m3e-switch-selected-hover-handle-color, ${DesignToken.color.surfaceContainerHighest})`),
134
+ unselectedHoverHandleColor: unsafeCSS(`var(--m3e-switch-unselected-hover-handle-color, ${DesignToken.color.onSurfaceVariant})`),
135
+ selectedFocusIconColor: unsafeCSS(`var(--m3e-switch-selected-focus-icon-color, ${DesignToken.color.onPrimaryContainer})`),
136
+ unselectedFocusIconColor: unsafeCSS(`var(--m3e-switch-unselected-focus-icon-color, ${DesignToken.color.surfaceContainerHighest})`),
137
+ selectedFocusTrackColor: unsafeCSS(`var(--m3e-switch-selected-focus-track-color, ${DesignToken.color.primary})`),
138
+ selectedFocusStateLayerColor: unsafeCSS(`var(--m3e-switch-selected-focus-state-layer-color, ${DesignToken.color.primary})`),
139
+ selectedFocusStateLayerOpacity: unsafeCSS("var(--m3e-switch-selected-focus-state-layer-opacity, 10%)"),
140
+ unselectedFocusTrackColor: unsafeCSS(`var(--m3e-switch-unselected-focus-track-color, ${DesignToken.color.surfaceContainerHighest})`),
141
+ unselectedFocusTrackOutlineColor: unsafeCSS(`var(--m3e-switch-unselected-focus-track-outline-color, ${DesignToken.color.outline})`),
142
+ unselectedFocusStateLayerColor: unsafeCSS(`var(--m3e-switch-unselected-focus-state-layer-color, ${DesignToken.color.onSurface})`),
143
+ unselectedFocusStateLayerOpacity: unsafeCSS("var(--m3e-switch-unselected-focus-state-layer-opacity, 10%)"),
144
+ selectedFocusHandleColor: unsafeCSS(`var(--m3e-switch-selected-focus-handle-color, ${DesignToken.color.primaryContainer})`),
145
+ unselectedFocusHandleColor: unsafeCSS(`var(--m3e-switch-unselected-focus-handle-color, ${DesignToken.color.onSurfaceVariant})`),
146
+ selectedPressedIconColor: unsafeCSS(`var(--m3e-switch-selected-pressed-icon-color, ${DesignToken.color.onPrimaryContainer})`),
147
+ unselectedPressedIconColor: unsafeCSS(`var(--m3e-switch-unselected-pressed-icon-color, ${DesignToken.color.surfaceContainerHighest})`),
148
+ selectedPressedTrackColor: unsafeCSS(`var(--m3e-switch-selected-pressed-track-color, ${DesignToken.color.primary})`),
149
+ selectedPressedStateLayerColor: unsafeCSS(`var(--m3e-switch-selected-pressed-state-layer-color, ${DesignToken.color.primary})`),
150
+ selectedPressedStateLayerOpacity: unsafeCSS("var(--m3e-switch-selected-pressed-state-layer-opacity, 10%)"),
151
+ unselectedPressedTrackColor: unsafeCSS(`var(--m3e-switch-unselected-pressed-track-color, ${DesignToken.color.surfaceContainerHighest})`),
152
+ unselectedPressedTrackOutlineColor: unsafeCSS(`var(--m3e-switch-unselected-pressed-track-outline-color, ${DesignToken.color.outline})`),
153
+ unselectedPressedStateLayerColor: unsafeCSS(`var(--m3e-switch-unselected-pressed-state-layer-color, ${DesignToken.color.onSurface})`),
154
+ unselectedPressedStateLayerOpacity: unsafeCSS("var(--m3e-switch-unselected-pressed-state-layer-opacity, 10%)"),
155
+ selectedPressedHandleColor: unsafeCSS(`var(--m3e-switch-selected-pressed-handle-color, ${DesignToken.color.primaryContainer})`),
156
+ unselectedPressedHandleColor: unsafeCSS(`var(--m3e-switch-unselected-pressed-handle-color, ${DesignToken.color.onSurfaceVariant})`),
157
+ };
158
+
159
+ /**
160
+ * Handle styles for `M3eSwitchElement`.
161
+ * @internal
162
+ */
163
+ const SwitchHandleStyle = css `
164
+ .handle {
165
+ position: relative;
166
+ display: flex;
167
+ align-items: center;
168
+ justify-content: center;
169
+ pointer-events: none;
170
+ transform-origin: center center;
171
+ border-radius: ${SwitchToken.handleShape};
172
+ transition: ${unsafeCSS(`background-color ${DesignToken.motion.duration.short4} ${DesignToken.motion.easing.standard},
173
+ transform var(--_switch-handle-effect),
174
+ width ${DesignToken.motion.spring.fastEffects},
175
+ height ${DesignToken.motion.spring.fastEffects}`)};
176
+ }
177
+ .track:not(.pressed) .handle {
178
+ --_switch-handle-effect: ${DesignToken.motion.spring.fastSpatial};
179
+ }
180
+ .track.pressed .handle {
181
+ --_switch-handle-effect: ${DesignToken.motion.spring.fastEffects};
182
+ }
183
+ :host(:not([aria-disabled="true"]):not([checked])[icons="both"]) .track:not(.pressed) .handle {
184
+ width: ${SwitchToken.withIconHandleWidth};
185
+ height: ${SwitchToken.withIconHandleHeight};
186
+ }
187
+ :host(:not([checked]):not([icons="both"])) .track:not(.pressed) .handle,
188
+ :host([aria-disabled="true"]:not([checked])) .handle {
189
+ width: ${SwitchToken.unselectedHandleWidth};
190
+ height: ${SwitchToken.unselectedHandleHeight};
191
+ }
192
+ :host([checked]) .track:not(.pressed) .handle {
193
+ width: ${SwitchToken.selectedHandleWidth};
194
+ height: ${SwitchToken.selectedHandleHeight};
195
+ }
196
+ .track.pressed .handle {
197
+ width: ${SwitchToken.pressedHandleWidth};
198
+ height: ${SwitchToken.pressedHandleHeight};
199
+ }
200
+ :host(:not([aria-disabled="true"]):not([checked]):not(:focus):not(:hover)) .track:not(.pressed) .handle {
201
+ background-color: ${SwitchToken.unselectedHandleColor};
202
+ }
203
+ :host(:not([aria-disabled="true"]):not([checked]):not(:focus):hover) .track:not(.pressed) .handle {
204
+ background-color: ${SwitchToken.unselectedHoverHandleColor};
205
+ }
206
+ :host(:not([aria-disabled="true"]):not([checked]):focus) .track:not(.pressed) .handle {
207
+ background-color: ${SwitchToken.unselectedFocusHandleColor};
208
+ }
209
+ :host(:not([aria-disabled="true"]):not([checked])) .track.pressed .handle {
210
+ background-color: ${SwitchToken.unselectedPressedHandleColor};
211
+ }
212
+ :host(:not([aria-disabled="true"])[checked]:not(:focus):not(:hover)) .track:not(.pressed) .handle {
213
+ background-color: ${SwitchToken.selectedHandleColor};
214
+ }
215
+ :host(:not([aria-disabled="true"])[checked]:not(:focus):hover) .track:not(.pressed) .handle {
216
+ background-color: ${SwitchToken.selectedHoverHandleColor};
217
+ }
218
+ :host(:not([aria-disabled="true"])[checked]:focus) .track:not(.pressed) .handle {
219
+ background-color: ${SwitchToken.selectedFocusHandleColor};
220
+ }
221
+ :host(:not([aria-disabled="true"])[checked]) .track.pressed .handle {
222
+ background-color: ${SwitchToken.selectedPressedHandleColor};
223
+ }
224
+ :host([aria-disabled="true"]:not([checked])) .handle {
225
+ background-color: color-mix(
226
+ in srgb,
227
+ ${SwitchToken.disabledUnselectedHandleColor} ${SwitchToken.disabledUnselectedHandleOpacity},
228
+ transparent
229
+ );
230
+ }
231
+ :host([aria-disabled="true"][checked]) .handle {
232
+ background-color: color-mix(
233
+ in srgb,
234
+ ${SwitchToken.disabledSelectedHandleColor} ${SwitchToken.disabledSelectedHandleOpacity},
235
+ transparent
236
+ );
237
+ }
238
+ :host([checked]) .track:not(.pressed) .handle {
239
+ transform: translateX(
240
+ calc(${SwitchToken.trackWidth} - ${SwitchToken.selectedHandleWidth} - ${SwitchToken.trackOutlineWidth})
241
+ );
242
+ }
243
+ :host([checked]) .track.pressed .handle {
244
+ transform: translateX(
245
+ calc(${SwitchToken.trackWidth} - ${SwitchToken.pressedHandleWidth} - ${SwitchToken.trackOutlineWidth})
246
+ );
247
+ }
248
+ :host(:not([checked]):not([icons="both"])) .track:not(.pressed) .handle,
249
+ :host([aria-disabled="true"]:not([checked])) .handle {
250
+ transform: translateX(
251
+ calc(
252
+ ${SwitchToken.trackOutlineWidth} + calc(${SwitchToken.pressedHandleWidth} - ${SwitchToken.withIconHandleWidth})
253
+ )
254
+ );
255
+ }
256
+ :host(:not([aria-disabled="true"]):not([checked])[icons="both"]) .track:not(.pressed) .handle {
257
+ transform: translateX(${SwitchToken.trackOutlineWidth});
258
+ }
259
+ @media (forced-colors: active) {
260
+ .handle {
261
+ transition: ${unsafeCSS(`transform var(--_switch-handle-effect),
262
+ width ${DesignToken.motion.spring.fastEffects},
263
+ height ${DesignToken.motion.spring.fastEffects}`)};
264
+ }
265
+ :host(:not([aria-disabled="true"]):not([checked]):not(:focus):not(:hover)) .track:not(.pressed) .handle,
266
+ :host(:not([aria-disabled="true"]):not([checked]):not(:focus):hover) .track:not(.pressed) .handle,
267
+ :host(:not([aria-disabled="true"]):not([checked]):focus) .track:not(.pressed) .handle,
268
+ :host(:not([aria-disabled="true"]):not([checked])) .track.pressed .handle {
269
+ background-color: ButtonText;
270
+ }
271
+ :host([aria-disabled="true"]:not([checked])) .handle {
272
+ background-color: GrayText;
273
+ }
274
+ :host(:not([aria-disabled="true"])[checked]:not(:focus):not(:hover)) .track:not(.pressed) .handle,
275
+ :host(:not([aria-disabled="true"])[checked]:not(:focus):hover) .track:not(.pressed) .handle,
276
+ :host(:not([aria-disabled="true"])[checked]:focus) .track:not(.pressed) .handle,
277
+ :host(:not([aria-disabled="true"])[checked]) .track.pressed .handle {
278
+ background-color: Canvas;
279
+ }
280
+ :host([aria-disabled="true"][checked]) .handle {
281
+ background-color: Canvas;
282
+ }
283
+ }
284
+ @media (prefers-reduced-motion) {
285
+ .handle {
286
+ transition: none;
287
+ }
288
+ }
289
+ `;
290
+
291
+ /**
292
+ * Icon styles for `M3eSwitchElement`.
293
+ * @internal
294
+ */
295
+ const SwitchIconStyle = css `
296
+ :host([icons="none"]) .icon,
297
+ :host([icons="selected"]:not([checked])) .icon,
298
+ :host([aria-disabled="true"]:not([checked])) .icon {
299
+ display: none;
300
+ }
301
+ .icon {
302
+ width: 1em;
303
+ transition: ${unsafeCSS(`color ${DesignToken.motion.duration.short4} ${DesignToken.motion.easing.standard}`)};
304
+ }
305
+ :host(:not([checked])) .icon {
306
+ font-size: ${SwitchToken.unselectedIconSize};
307
+ }
308
+ :host([checked]) .icon {
309
+ font-size: ${SwitchToken.selectedIconSize};
310
+ }
311
+ :host(:not([aria-disabled="true"]):not([checked]):not(:focus):not(:hover)) .track:not(.pressed) .icon {
312
+ color: ${SwitchToken.unselectedIconColor};
313
+ }
314
+ :host(:not([aria-disabled="true"]):not([checked]):not(:focus):hover) .track:not(.pressed) .icon {
315
+ color: ${SwitchToken.unselectedHoverIconColor};
316
+ }
317
+ :host(:not([aria-disabled="true"]):not([checked]):focus) .track:not(.pressed) .icon {
318
+ color: ${SwitchToken.unselectedFocusIconColor};
319
+ }
320
+ :host(:not([aria-disabled="true"]):not([checked])) .track.pressed .icon {
321
+ color: ${SwitchToken.unselectedPressedIconColor};
322
+ }
323
+ :host(:not([aria-disabled="true"])[checked]:not(:focus):not(:hover)) .track:not(.pressed) .icon {
324
+ color: ${SwitchToken.selectedIconColor};
325
+ }
326
+ :host(:not([aria-disabled="true"])[checked]:not(:focus):hover) .track:not(.pressed) .icon {
327
+ color: ${SwitchToken.selectedHoverIconColor};
328
+ }
329
+ :host(:not([aria-disabled="true"])[checked]:focus) .track:not(.pressed) .icon {
330
+ color: ${SwitchToken.selectedFocusIconColor};
331
+ }
332
+ :host(:not([aria-disabled="true"])[checked]) .track.pressed .icon {
333
+ color: ${SwitchToken.selectedPressedIconColor};
334
+ }
335
+ :host([aria-disabled="true"]:not([checked])) .icon {
336
+ color: color-mix(
337
+ in srgb,
338
+ ${SwitchToken.disabledUnselectedIconColor} ${SwitchToken.disabledUnselectedIconOpacity},
339
+ transparent
340
+ );
341
+ }
342
+ :host([aria-disabled="true"][checked]) .icon {
343
+ color: color-mix(
344
+ in srgb,
345
+ ${SwitchToken.disabledSelectedIconColor} ${SwitchToken.disabledSelectedIconOpacity},
346
+ transparent
347
+ );
348
+ }
349
+ @media (forced-colors: active) {
350
+ :host(:not([aria-disabled="true"]):not([checked]):not(:focus):not(:hover)) .track:not(.pressed) .icon,
351
+ :host(:not([aria-disabled="true"]):not([checked]):not(:focus):hover) .track:not(.pressed) .icon,
352
+ :host(:not([aria-disabled="true"]):not([checked]):focus) .track:not(.pressed) .icon,
353
+ :host(:not([aria-disabled="true"]):not([checked])) .track.pressed .icon {
354
+ color: Canvas;
355
+ }
356
+ :host(:not([aria-disabled="true"])[checked]:not(:focus):not(:hover)) .track:not(.pressed) .icon,
357
+ :host(:not([aria-disabled="true"])[checked]:not(:focus):hover) .track:not(.pressed) .icon,
358
+ :host(:not([aria-disabled="true"])[checked]:focus) .track:not(.pressed) .icon,
359
+ :host(:not([aria-disabled="true"])[checked]) .track.pressed .icon {
360
+ color: CanvasText;
361
+ }
362
+ :host([aria-disabled="true"]:not([checked])) .icon {
363
+ color: Canvas;
364
+ }
365
+ :host([aria-disabled="true"][checked]) .icon {
366
+ color: GrayText;
367
+ }
368
+ }
369
+ @media (prefers-reduced-motion) {
370
+ .icon {
371
+ transition: none;
372
+ }
373
+ }
374
+ `;
375
+
376
+ /**
377
+ * State layer styles for `M3eSwitchElement`.
378
+ * @internal
379
+ */
380
+ const SwitchStateLayerStyle = css `
381
+ .state-layer {
382
+ width: ${SwitchToken.stateLayerSize};
383
+ height: ${SwitchToken.stateLayerSize};
384
+ border-radius: ${SwitchToken.stateLayerShape};
385
+ }
386
+ :host(:not([checked])[icons="both"]) .track:not(.pressed) .state-layer {
387
+ left: calc(0px - calc(calc(${SwitchToken.stateLayerSize} - ${SwitchToken.withIconHandleWidth}) / 2));
388
+ top: calc(0px - calc(calc(${SwitchToken.stateLayerSize} - ${SwitchToken.withIconHandleHeight}) / 2));
389
+ }
390
+ :host(:not([checked]):not([icons="both"])) .track:not(.pressed) .state-layer {
391
+ left: calc(0px - calc(calc(${SwitchToken.stateLayerSize} - ${SwitchToken.unselectedHandleWidth}) / 2));
392
+ top: calc(0px - calc(calc(${SwitchToken.stateLayerSize} - ${SwitchToken.unselectedHandleHeight}) / 2));
393
+ }
394
+ :host([checked]) .track:not(.pressed) .state-layer {
395
+ left: calc(0px - calc(calc(${SwitchToken.stateLayerSize} - ${SwitchToken.selectedHandleWidth}) / 2));
396
+ top: calc(0px - calc(calc(${SwitchToken.stateLayerSize} - ${SwitchToken.selectedHandleHeight}) / 2));
397
+ }
398
+ .track.pressed .state-layer {
399
+ left: calc(0px - calc(calc(${SwitchToken.stateLayerSize} - ${SwitchToken.pressedHandleWidth}) / 2));
400
+ top: calc(0px - calc(calc(${SwitchToken.stateLayerSize} - ${SwitchToken.pressedHandleWidth}) / 2));
401
+ }
402
+ :host(:not([checked])) .state-layer {
403
+ --m3e-state-layer-hover-color: ${SwitchToken.unselectedHoverStateLayerColor};
404
+ --m3e-state-layer-hover-opacity: ${SwitchToken.unselectedHoverStateLayerOpacity};
405
+ --m3e-state-layer-focus-color: ${SwitchToken.unselectedFocusStateLayerColor};
406
+ --m3e-state-layer-focus-opacity: ${SwitchToken.unselectedFocusStateLayerOpacity};
407
+ }
408
+ :host([checked]) .state-layer {
409
+ --m3e-state-layer-hover-color: ${SwitchToken.selectedHoverStateLayerColor};
410
+ --m3e-state-layer-hover-opacity: ${SwitchToken.selectedHoverStateLayerOpacity};
411
+ --m3e-state-layer-focus-color: ${SwitchToken.selectedFocusStateLayerColor};
412
+ --m3e-state-layer-focus-opacity: ${SwitchToken.selectedFocusStateLayerOpacity};
413
+ }
414
+ `;
415
+
416
+ /**
417
+ * Baseline styles for `M3eSwitchElement`.
418
+ * @internal
419
+ */
420
+ const SwitchStyle = css `
421
+ :host {
422
+ display: inline-block;
423
+ position: relative;
424
+ outline: none;
425
+ height: fit-content;
426
+ width: fit-content;
427
+ }
428
+ .focus-ring {
429
+ border-radius: ${SwitchToken.trackShape};
430
+ }
431
+ .touch {
432
+ position: absolute;
433
+ height: 3rem;
434
+ left: 0;
435
+ right: 0;
436
+ }
437
+ .base {
438
+ display: flex;
439
+ align-items: center;
440
+ justify-content: center;
441
+ }
442
+ `;
443
+
444
+ /**
445
+ * Track styles for `M3eSwitchElement`.
446
+ * @internal
447
+ */
448
+ const SwitchTrackStyle = css `
449
+ .track {
450
+ display: flex;
451
+ align-items: center;
452
+ position: relative;
453
+ box-sizing: border-box;
454
+ border-radius: ${SwitchToken.trackShape};
455
+ width: ${SwitchToken.trackWidth};
456
+ height: ${SwitchToken.trackHeight};
457
+ transition: ${unsafeCSS(`background-color ${DesignToken.motion.duration.short4} ${DesignToken.motion.easing.standard}`)};
458
+ }
459
+ :host(:not([checked])) .track {
460
+ border-width: ${SwitchToken.trackOutlineWidth};
461
+ border-style: solid;
462
+ }
463
+ :host(:not([aria-disabled="true"]):not([checked]):not(:focus):not(:hover)) .track:not(.pressed) {
464
+ border-color: ${SwitchToken.trackOutlineColor};
465
+ background-color: ${SwitchToken.unselectedTrackColor};
466
+ }
467
+ :host(:not([aria-disabled="true"]):not([checked]):not(:focus):hover) .track:not(.pressed) {
468
+ border-color: ${SwitchToken.unselectedHoverTrackOutlineColor};
469
+ background-color: ${SwitchToken.unselectedHoverTrackColor};
470
+ }
471
+ :host(:not([aria-disabled="true"]):not([checked]):focus) .track:not(.pressed) {
472
+ border-color: ${SwitchToken.unselectedFocusTrackOutlineColor};
473
+ background-color: ${SwitchToken.unselectedFocusTrackColor};
474
+ }
475
+ :host(:not([aria-disabled="true"]):not([checked])) .track.pressed {
476
+ border-color: ${SwitchToken.unselectedPressedTrackOutlineColor};
477
+ background-color: ${SwitchToken.unselectedPressedTrackColor};
478
+ }
479
+ :host([aria-disabled="true"]:not([checked])) .track {
480
+ border-color: color-mix(
481
+ in srgb,
482
+ ${SwitchToken.disabledUnselectedTrackOutlineColor} ${SwitchToken.disabledTrackOpacity},
483
+ transparent
484
+ );
485
+ background-color: color-mix(
486
+ in srgb,
487
+ ${SwitchToken.disabledUnselectedTrackColor} ${SwitchToken.disabledTrackOpacity},
488
+ transparent
489
+ );
490
+ }
491
+ :host(:not([aria-disabled="true"])[checked]:not(:focus):not(:hover)) .track:not(.pressed) {
492
+ background-color: ${SwitchToken.selectedTrackColor};
493
+ }
494
+ :host(:not([aria-disabled="true"])[checked]:not(:focus):hover) .track:not(.pressed) {
495
+ background-color: ${SwitchToken.selectedHoverTrackColor};
496
+ }
497
+ :host(:not([aria-disabled="true"])[checked]:focus) .track:not(.pressed) {
498
+ background-color: ${SwitchToken.selectedFocusTrackColor};
499
+ }
500
+ :host(:not([aria-disabled="true"])[checked]) .track.pressed {
501
+ background-color: ${SwitchToken.selectedPressedTrackColor};
502
+ }
503
+ :host([aria-disabled="true"][checked]) .track {
504
+ background-color: color-mix(
505
+ in srgb,
506
+ ${SwitchToken.disabledSelectedTrackColor} ${SwitchToken.disabledTrackOpacity},
507
+ transparent
508
+ );
509
+ }
510
+ @media (forced-colors: active) {
511
+ .track {
512
+ transition: none;
513
+ }
514
+ :host(:not([aria-disabled="true"]):not([checked]):not(:focus):not(:hover)) .track:not(.pressed),
515
+ :host(:not([aria-disabled="true"]):not([checked]):not(:focus):hover) .track:not(.pressed),
516
+ :host(:not([aria-disabled="true"]):not([checked]):focus) .track:not(.pressed),
517
+ :host(:not([aria-disabled="true"]):not([checked])) .track.pressed {
518
+ border-color: ButtonText;
519
+ background-color: Canvas;
520
+ }
521
+ :host([aria-disabled="true"]:not([checked])) .track {
522
+ border-color: GrayText;
523
+ background-color: Canvas;
524
+ }
525
+ :host(:not([aria-disabled="true"])[checked]:not(:focus):not(:hover)) .track:not(.pressed),
526
+ :host(:not([aria-disabled="true"])[checked]:not(:focus):hover) .track:not(.pressed),
527
+ :host(:not([aria-disabled="true"])[checked]:focus) .track:not(.pressed),
528
+ :host(:not([aria-disabled="true"])[checked]) .track.pressed {
529
+ background-color: ButtonText;
530
+ }
531
+ :host([aria-disabled="true"][checked]) .track {
532
+ background-color: GrayText;
533
+ }
534
+ }
535
+ @media (prefers-reduced-motion) {
536
+ .track {
537
+ transition: none;
538
+ }
539
+ }
540
+ `;
541
+
542
+ var _M3eSwitchElement_instances, _M3eSwitchElement_clickHandler, _M3eSwitchElement_hoverController, _M3eSwitchElement_pressedController, _M3eSwitchElement_renderIcon, _M3eSwitchElement_handleClick;
543
+ /**
544
+ * @summary
545
+ * An on/off control that can be toggled by clicking.
546
+ *
547
+ * @description
548
+ * The `m3e-switch` component is a semantic, accessible toggle control that reflects a binary state.
549
+ * Designed according to Material Design 3 guidelines, it supports shape transitions, and adaptive color
550
+ * theming across selected, unselected, and disabled states. The component responds to user interaction
551
+ * with smooth motion and expressive feedback. It supports optional icons (`none`, `selected`, or `both`)
552
+ * and integrates with form-associated behavior, emitting `input` and `change` events when toggled.
553
+ *
554
+ * @example
555
+ * The following example illustrates a switch wrapped by a `label`.
556
+ *
557
+ * ```html
558
+ * <label>Switch label&nbsp;<m3e-switch></m3e-switch></label>
559
+ * ```
560
+ *
561
+ * @example
562
+ * By default, icons are not presented. Use the `icons` attribute to control which icons to show. The next
563
+ * example illustrates showing both the unselected and selected icons.
564
+ *
565
+ * ```html
566
+ * <label>Switch label&nbsp;<m3e-switch icons="both"></m3e-switch></label>
567
+ * ```
568
+ *
569
+ * @tag m3e-switch
570
+ *
571
+ * @attr checked - Whether the element is checked.
572
+ * @attr disabled - Whether the element is disabled.
573
+ * @attr icons - The icons to present.
574
+ * @attr name - The name that identifies the element when submitting the associated form.
575
+ * @attr value - A string representing the value of the switch.
576
+ *
577
+ * @fires input - Emitted when the checked state changes.
578
+ * @fires change - Emitted when the checked state changes.
579
+ *
580
+ * @cssprop --m3e-switch-selected-icon-color - Color of the icon when the switch is selected.
581
+ * @cssprop --m3e-switch-selected-icon-size - Size of the icon in the selected state.
582
+ * @cssprop --m3e-switch-unselected-icon-color - Color of the icon when the switch is unselected.
583
+ * @cssprop --m3e-switch-unselected-icon-size - Size of the icon in the unselected state.
584
+ * @cssprop --m3e-switch-track-height - Height of the switch track.
585
+ * @cssprop --m3e-switch-track-width - Width of the switch track.
586
+ * @cssprop --m3e-switch-track-outline-color - Color of the track’s outline.
587
+ * @cssprop --m3e-switch-track-outline-width - Thickness of the track’s outline.
588
+ * @cssprop --m3e-switch-track-shape - Corner shape of the track.
589
+ * @cssprop --m3e-switch-selected-track-color - Track color when selected.
590
+ * @cssprop --m3e-switch-unselected-track-color - Track color when unselected.
591
+ * @cssprop --m3e-switch-unselected-handle-height - Height of the handle when unselected.
592
+ * @cssprop --m3e-switch-unselected-handle-width - Width of the handle when unselected.
593
+ * @cssprop --m3e-switch-with-icon-handle-height - Height of the handle when icons are present.
594
+ * @cssprop --m3e-switch-with-icon-handle-width - Width of the handle when icons are present.
595
+ * @cssprop --m3e-switch-selected-handle-height - Height of the handle when selected.
596
+ * @cssprop --m3e-switch-selected-handle-width - Width of the handle when selected.
597
+ * @cssprop --m3e-switch-pressed-handle-height - Height of the handle during press.
598
+ * @cssprop --m3e-switch-pressed-handle-width - Width of the handle during press.
599
+ * @cssprop --m3e-switch-handle-shape - Corner shape of the handle.
600
+ * @cssprop --m3e-switch-selected-handle-color - Handle color when selected.
601
+ * @cssprop --m3e-switch-unselected-handle-color - Handle color when unselected.
602
+ * @cssprop --m3e-switch-state-layer-size - Diameter of the state layer overlay.
603
+ * @cssprop --m3e-switch-state-layer-shape - Corner shape of the state layer.
604
+ * @cssprop --m3e-switch-disabled-selected-icon-color - Icon color when selected and disabled.
605
+ * @cssprop --m3e-switch-disabled-selected-icon-opacity - Icon opacity when selected and disabled.
606
+ * @cssprop --m3e-switch-disabled-unselected-icon-color - Icon color when unselected and disabled.
607
+ * @cssprop --m3e-switch-disabled-unselected-icon-opacity - Icon opacity when unselected and disabled.
608
+ * @cssprop --m3e-switch-disabled-track-opacity - Track opacity when disabled.
609
+ * @cssprop --m3e-switch-disabled-selected-track-color - Track color when selected and disabled.
610
+ * @cssprop --m3e-switch-disabled-unselected-track-color - Track color when unselected and disabled.
611
+ * @cssprop --m3e-switch-disabled-unselected-track-outline-color - Outline color when unselected and disabled.
612
+ * @cssprop --m3e-switch-disabled-unselected-handle-opacity - Handle opacity when unselected and disabled.
613
+ * @cssprop --m3e-switch-disabled-selected-handle-opacity - Handle opacity when selected and disabled.
614
+ * @cssprop --m3e-switch-disabled-selected-handle-color - Handle color when selected and disabled.
615
+ * @cssprop --m3e-switch-disabled-unselected-handle-color - Handle color when unselected and disabled.
616
+ * @cssprop --m3e-switch-selected-hover-icon-color - Icon color when selected and hovered.
617
+ * @cssprop --m3e-switch-unselected-hover-icon-color - Icon color when unselected and hovered.
618
+ * @cssprop --m3e-switch-selected-hover-track-color - Track color when selected and hovered.
619
+ * @cssprop --m3e-switch-selected-hover-state-layer-color - State layer color when selected and hovered.
620
+ * @cssprop --m3e-switch-selected-hover-state-layer-opacity - State layer opacity when selected and hovered.
621
+ * @cssprop --m3e-switch-unselected-hover-track-color - Track color when unselected and hovered.
622
+ * @cssprop --m3e-switch-unselected-hover-track-outline-color - Outline color when unselected and hovered.
623
+ * @cssprop --m3e-switch-unselected-hover-state-layer-color - State layer color when unselected and hovered.
624
+ * @cssprop --m3e-switch-unselected-hover-state-layer-opacity - State layer opacity when unselected and hovered.
625
+ * @cssprop --m3e-switch-selected-hover-handle-color - Handle color when selected and hovered.
626
+ * @cssprop --m3e-switch-unselected-hover-handle-color - Handle color when unselected and hovered.
627
+ * @cssprop --m3e-switch-selected-focus-icon-color - Icon color when selected and focused.
628
+ * @cssprop --m3e-switch-unselected-focus-icon-color - Icon color when unselected and focused.
629
+ * @cssprop --m3e-switch-selected-focus-track-color - Track color when selected and focused.
630
+ * @cssprop --m3e-switch-selected-focus-state-layer-color - State layer color when selected and focused.
631
+ * @cssprop --m3e-switch-selected-focus-state-layer-opacity - State layer opacity when selected and focused.
632
+ * @cssprop --m3e-switch-unselected-focus-track-color - Track color when unselected and focused.
633
+ * @cssprop --m3e-switch-unselected-focus-track-outline-color - Outline color when unselected and focused.
634
+ * @cssprop --m3e-switch-unselected-focus-state-layer-color - State layer color when unselected and focused.
635
+ * @cssprop --m3e-switch-unselected-focus-state-layer-opacity - State layer opacity when unselected and focused.
636
+ * @cssprop --m3e-switch-selected-focus-handle-color - Handle color when selected and focused.
637
+ * @cssprop --m3e-switch-unselected-focus-handle-color - Handle color when unselected and focused.
638
+ * @cssprop --m3e-switch-selected-pressed-icon-color - Icon color when selected and pressed.
639
+ * @cssprop --m3e-switch-unselected-pressed-icon-color - Icon color when unselected and pressed.
640
+ * @cssprop --m3e-switch-selected-pressed-track-color - Track color when selected and pressed.
641
+ * @cssprop --m3e-switch-selected-pressed-state-layer-color - State layer color when selected and pressed.
642
+ * @cssprop --m3e-switch-selected-pressed-state-layer-opacity - State layer opacity when selected and pressed.
643
+ * @cssprop --m3e-switch-unselected-pressed-track-color - Track color when unselected and pressed.
644
+ * @cssprop --m3e-switch-unselected-pressed-track-outline-color - Outline color when unselected and pressed.
645
+ * @cssprop --m3e-switch-unselected-pressed-state-layer-color - State layer color when unselected and pressed.
646
+ * @cssprop --m3e-switch-unselected-pressed-state-layer-opacity - State layer opacity when unselected and pressed.
647
+ * @cssprop --m3e-switch-selected-pressed-handle-color - Handle color when selected and pressed.
648
+ * @cssprop --m3e-switch-unselected-pressed-handle-color - Handle color when unselected and pressed.
649
+ */
650
+ let M3eSwitchElement = class M3eSwitchElement extends Labelled(Dirty(Touched(ConstraintValidation(Checked(FormAssociated(KeyboardClick(Focusable(Disabled(AttachInternals(Role(LitElement, "switch"))))))))))) {
651
+ constructor() {
652
+ super();
653
+ _M3eSwitchElement_instances.add(this);
654
+ /** @private */ _M3eSwitchElement_clickHandler.set(this, (e) => __classPrivateFieldGet(this, _M3eSwitchElement_instances, "m", _M3eSwitchElement_handleClick).call(this, e));
655
+ /** @private */ _M3eSwitchElement_hoverController.set(this, new HoverController(this, {
656
+ target: null,
657
+ callback: (hovering) => {
658
+ if (this.disabled)
659
+ return;
660
+ if (hovering) {
661
+ this._stateLayer?.show("hover");
662
+ }
663
+ else {
664
+ this._stateLayer?.hide("hover");
665
+ }
666
+ },
667
+ }));
668
+ /** @private */ _M3eSwitchElement_pressedController.set(this, new PressedController(this, {
669
+ target: null,
670
+ callback: (pressed) => this._track?.classList.toggle("pressed", pressed && !this.disabled),
671
+ }));
672
+ /**
673
+ * The icons to present.
674
+ * @default "none"
675
+ */
676
+ this.icons = "none";
677
+ /**
678
+ * A string representing the value of the switch.
679
+ * @default "on"
680
+ */
681
+ this.value = "on";
682
+ new PressedController(this, {
683
+ isPressedKey: (key) => key === " " || key === "Enter",
684
+ callback: (pressed) => this._track?.classList.toggle("pressed", pressed && !this.disabled),
685
+ });
686
+ }
687
+ /** @inheritdoc @private */
688
+ get [(_M3eSwitchElement_clickHandler = new WeakMap(), _M3eSwitchElement_hoverController = new WeakMap(), _M3eSwitchElement_pressedController = new WeakMap(), _M3eSwitchElement_instances = new WeakSet(), formValue)]() {
689
+ return !this.checked ? null : this.value;
690
+ }
691
+ /** @inheritdoc */
692
+ connectedCallback() {
693
+ super.connectedCallback();
694
+ this.addEventListener("click", __classPrivateFieldGet(this, _M3eSwitchElement_clickHandler, "f"));
695
+ for (const label of this.labels) {
696
+ __classPrivateFieldGet(this, _M3eSwitchElement_hoverController, "f").observe(label);
697
+ __classPrivateFieldGet(this, _M3eSwitchElement_pressedController, "f").observe(label);
698
+ }
699
+ }
700
+ /** @inheritdoc */
701
+ disconnectedCallback() {
702
+ super.disconnectedCallback();
703
+ this.removeEventListener("click", __classPrivateFieldGet(this, _M3eSwitchElement_clickHandler, "f"));
704
+ for (const label of this.labels) {
705
+ __classPrivateFieldGet(this, _M3eSwitchElement_hoverController, "f").unobserve(label);
706
+ __classPrivateFieldGet(this, _M3eSwitchElement_pressedController, "f").unobserve(label);
707
+ }
708
+ }
709
+ /** @inheritdoc */
710
+ firstUpdated(_changedProperties) {
711
+ super.firstUpdated(_changedProperties);
712
+ [this._focusRing, this._stateLayer].forEach((x) => x?.attach(this));
713
+ }
714
+ /** @inheritdoc */
715
+ render() {
716
+ return html `<m3e-focus-ring class="focus-ring"></m3e-focus-ring>
717
+ <div class="track" aria-hidden="true">
718
+ <div class="touch" aria-hidden="true"></div>
719
+ <div class="handle">
720
+ <m3e-state-layer class="state-layer" ?disabled="${this.disabled}"></m3e-state-layer>
721
+ <div class="base">${__classPrivateFieldGet(this, _M3eSwitchElement_instances, "m", _M3eSwitchElement_renderIcon).call(this)}</div>
722
+ </div>
723
+ </div>`;
724
+ }
725
+ };
726
+ _M3eSwitchElement_renderIcon = function _M3eSwitchElement_renderIcon() {
727
+ return this.checked
728
+ ? html `<svg class="icon" viewBox="0 0 24 24" aria-hidden="true">
729
+ <path fill="currentColor" d="M19.69,5.23L8.96,15.96l-4.23-4.23L2.96,13.5l6,6L21.46,7L19.69,5.23z"></path>
730
+ </svg>`
731
+ : html `<svg class="icon" viewBox="0 -960 960 960" fill="currentColor">
732
+ <path d="m256-200-56-56 224-224-224-224 56-56 224 224 224-224 56 56-224 224 224 224-56 56-224-224-224 224Z" />
733
+ </svg>`;
734
+ };
735
+ _M3eSwitchElement_handleClick = function _M3eSwitchElement_handleClick(e) {
736
+ if (e.defaultPrevented)
737
+ return;
738
+ this.checked = !this.checked;
739
+ if (this.dispatchEvent(new Event("input", { bubbles: true, composed: true, cancelable: true }))) {
740
+ this.dispatchEvent(new Event("change", { bubbles: true }));
741
+ }
742
+ else {
743
+ this.checked = !this.checked;
744
+ }
745
+ };
746
+ /** The styles of the element. */
747
+ M3eSwitchElement.styles = [
748
+ SwitchStyle,
749
+ SwitchStateLayerStyle,
750
+ SwitchTrackStyle,
751
+ SwitchHandleStyle,
752
+ SwitchIconStyle,
753
+ ];
754
+ __decorate([
755
+ e(".track")
756
+ ], M3eSwitchElement.prototype, "_track", void 0);
757
+ __decorate([
758
+ e(".focus-ring")
759
+ ], M3eSwitchElement.prototype, "_focusRing", void 0);
760
+ __decorate([
761
+ e(".state-layer")
762
+ ], M3eSwitchElement.prototype, "_stateLayer", void 0);
763
+ __decorate([
764
+ n({ reflect: true })
765
+ ], M3eSwitchElement.prototype, "icons", void 0);
766
+ __decorate([
767
+ n()
768
+ ], M3eSwitchElement.prototype, "value", void 0);
769
+ M3eSwitchElement = __decorate([
770
+ t$1("m3e-switch")
771
+ ], M3eSwitchElement);
772
+
773
+ export { M3eSwitchElement };
774
+ //# sourceMappingURL=index.js.map