@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.
- package/LICENSE +22 -0
- package/README.md +174 -0
- package/cem.config.mjs +16 -0
- package/demo/index.html +65 -0
- package/dist/css-custom-data.json +352 -0
- package/dist/custom-elements.json +633 -0
- package/dist/html-custom-data.json +38 -0
- package/dist/index.js +774 -0
- package/dist/index.js.map +1 -0
- package/dist/index.min.js +399 -0
- package/dist/index.min.js.map +1 -0
- package/dist/src/SwitchElement.d.ts +147 -0
- package/dist/src/SwitchElement.d.ts.map +1 -0
- package/dist/src/SwitchIcons.d.ts +3 -0
- package/dist/src/SwitchIcons.d.ts.map +1 -0
- package/dist/src/index.d.ts +3 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/styles/SwitchHandleStyle.d.ts +6 -0
- package/dist/src/styles/SwitchHandleStyle.d.ts.map +1 -0
- package/dist/src/styles/SwitchIconStyle.d.ts +6 -0
- package/dist/src/styles/SwitchIconStyle.d.ts.map +1 -0
- package/dist/src/styles/SwitchStateLayerStyle.d.ts +6 -0
- package/dist/src/styles/SwitchStateLayerStyle.d.ts.map +1 -0
- package/dist/src/styles/SwitchStyle.d.ts +6 -0
- package/dist/src/styles/SwitchStyle.d.ts.map +1 -0
- package/dist/src/styles/SwitchToken.d.ts +76 -0
- package/dist/src/styles/SwitchToken.d.ts.map +1 -0
- package/dist/src/styles/SwitchTrackStyle.d.ts +6 -0
- package/dist/src/styles/SwitchTrackStyle.d.ts.map +1 -0
- package/dist/src/styles/index.d.ts +6 -0
- package/dist/src/styles/index.d.ts.map +1 -0
- package/eslint.config.mjs +13 -0
- package/package.json +48 -0
- package/rollup.config.js +32 -0
- package/src/SwitchElement.ts +268 -0
- package/src/SwitchIcons.ts +2 -0
- package/src/index.ts +2 -0
- package/src/styles/SwitchHandleStyle.ts +140 -0
- package/src/styles/SwitchIconStyle.ts +89 -0
- package/src/styles/SwitchStateLayerStyle.ts +43 -0
- package/src/styles/SwitchStyle.ts +30 -0
- package/src/styles/SwitchToken.ts +145 -0
- package/src/styles/SwitchTrackStyle.ts +104 -0
- package/src/styles/index.ts +5 -0
- package/tsconfig.json +9 -0
|
@@ -0,0 +1,399 @@
|
|
|
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 as e,css as t,LitElement as o,html as r}from"lit";import{DesignToken as s,Labelled as c,Dirty as a,Touched as i,ConstraintValidation as n,Checked as d,FormAssociated as h,KeyboardClick as l,Focusable as u,Disabled as p,AttachInternals as f,Role as k,HoverController as m,PressedController as b,formValue as $}from"@m3e/core";function v(e,t,o,r){var s,c=arguments.length,a=c<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,o):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,o,r);else for(var i=e.length-1;i>=0;i--)(s=e[i])&&(a=(c<3?s(a):c>3?s(t,o,a):s(t,o))||a);return c>3&&a&&Object.defineProperty(t,o,a),a}function y(e,t,o,r){if("a"===o&&!r)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!r:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===o?r:"a"===o?r.call(e):r?r.value:t.get(e)}"function"==typeof SuppressedError&&SuppressedError;
|
|
7
|
+
/**
|
|
8
|
+
* @license
|
|
9
|
+
* Copyright 2017 Google LLC
|
|
10
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
11
|
+
*/
|
|
12
|
+
const w=globalThis,g=w.ShadowRoot&&(void 0===w.ShadyCSS||w.ShadyCSS.nativeShadow)&&"adoptedStyleSheets"in Document.prototype&&"replace"in CSSStyleSheet.prototype,E=Symbol(),_=new WeakMap;
|
|
13
|
+
/**
|
|
14
|
+
* @license
|
|
15
|
+
* Copyright 2019 Google LLC
|
|
16
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
17
|
+
*/let S=class{constructor(e,t,o){if(this._$cssResult$=!0,o!==E)throw Error("CSSResult is not constructable. Use `unsafeCSS` or `css` instead.");this.cssText=e,this.t=t}get styleSheet(){let e=this.o;const t=this.t;if(g&&void 0===e){const o=void 0!==t&&1===t.length;o&&(e=_.get(t)),void 0===e&&((this.o=e=new CSSStyleSheet).replaceSync(this.cssText),o&&_.set(t,e))}return e}toString(){return this.cssText}};const C=(e,t)=>{if(g)e.adoptedStyleSheets=t.map(e=>e instanceof CSSStyleSheet?e:e.styleSheet);else for(const o of t){const t=document.createElement("style"),r=w.litNonce;void 0!==r&&t.setAttribute("nonce",r),t.textContent=o.cssText,e.appendChild(t)}},P=g?e=>e:e=>e instanceof CSSStyleSheet?(e=>{let t="";for(const o of e.cssRules)t+=o.cssText;return(e=>new S("string"==typeof e?e:e+"",void 0,E))(t)})(e):e,{is:x,defineProperty:U,getOwnPropertyDescriptor:O,getOwnPropertyNames:A,getOwnPropertySymbols:M,getPrototypeOf:R}=Object,T=globalThis,j=T.trustedTypes,L=j?j.emptyScript:"",z=T.reactiveElementPolyfillSupport,H=(e,t)=>e,D={toAttribute(e,t){switch(t){case Boolean:e=e?L:null;break;case Object:case Array:e=null==e?e:JSON.stringify(e)}return e},fromAttribute(e,t){let o=e;switch(t){case Boolean:o=null!==e;break;case Number:o=null===e?null:Number(e);break;case Object:case Array:try{o=JSON.parse(e)}catch(e){o=null}}return o}},q=(e,t)=>!x(e,t),B={attribute:!0,type:String,converter:D,reflect:!1,useDefault:!1,hasChanged:q};
|
|
18
|
+
/**
|
|
19
|
+
* @license
|
|
20
|
+
* Copyright 2017 Google LLC
|
|
21
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
22
|
+
*/Symbol.metadata??=Symbol("metadata"),T.litPropertyMetadata??=new WeakMap;class N extends HTMLElement{static addInitializer(e){this._$Ei(),(this.l??=[]).push(e)}static get observedAttributes(){return this.finalize(),this._$Eh&&[...this._$Eh.keys()]}static createProperty(e,t=B){if(t.state&&(t.attribute=!1),this._$Ei(),this.prototype.hasOwnProperty(e)&&((t=Object.create(t)).wrapped=!0),this.elementProperties.set(e,t),!t.noAccessor){const o=Symbol(),r=this.getPropertyDescriptor(e,o,t);void 0!==r&&U(this.prototype,e,r)}}static getPropertyDescriptor(e,t,o){const{get:r,set:s}=O(this.prototype,e)??{get(){return this[t]},set(e){this[t]=e}};return{get:r,set(t){const c=r?.call(this);s?.call(this,t),this.requestUpdate(e,c,o)},configurable:!0,enumerable:!0}}static getPropertyOptions(e){return this.elementProperties.get(e)??B}static _$Ei(){if(this.hasOwnProperty(H("elementProperties")))return;const e=R(this);e.finalize(),void 0!==e.l&&(this.l=[...e.l]),this.elementProperties=new Map(e.elementProperties)}static finalize(){if(this.hasOwnProperty(H("finalized")))return;if(this.finalized=!0,this._$Ei(),this.hasOwnProperty(H("properties"))){const e=this.properties,t=[...A(e),...M(e)];for(const o of t)this.createProperty(o,e[o])}const e=this[Symbol.metadata];if(null!==e){const t=litPropertyMetadata.get(e);if(void 0!==t)for(const[e,o]of t)this.elementProperties.set(e,o)}this._$Eh=new Map;for(const[e,t]of this.elementProperties){const o=this._$Eu(e,t);void 0!==o&&this._$Eh.set(o,e)}this.elementStyles=this.finalizeStyles(this.styles)}static finalizeStyles(e){const t=[];if(Array.isArray(e)){const o=new Set(e.flat(1/0).reverse());for(const e of o)t.unshift(P(e))}else void 0!==e&&t.push(P(e));return t}static _$Eu(e,t){const o=t.attribute;return!1===o?void 0:"string"==typeof o?o:"string"==typeof e?e.toLowerCase():void 0}constructor(){super(),this._$Ep=void 0,this.isUpdatePending=!1,this.hasUpdated=!1,this._$Em=null,this._$Ev()}_$Ev(){this._$ES=new Promise(e=>this.enableUpdating=e),this._$AL=new Map,this._$E_(),this.requestUpdate(),this.constructor.l?.forEach(e=>e(this))}addController(e){(this._$EO??=new Set).add(e),void 0!==this.renderRoot&&this.isConnected&&e.hostConnected?.()}removeController(e){this._$EO?.delete(e)}_$E_(){const e=new Map,t=this.constructor.elementProperties;for(const o of t.keys())this.hasOwnProperty(o)&&(e.set(o,this[o]),delete this[o]);e.size>0&&(this._$Ep=e)}createRenderRoot(){const e=this.shadowRoot??this.attachShadow(this.constructor.shadowRootOptions);return C(e,this.constructor.elementStyles),e}connectedCallback(){this.renderRoot??=this.createRenderRoot(),this.enableUpdating(!0),this._$EO?.forEach(e=>e.hostConnected?.())}enableUpdating(e){}disconnectedCallback(){this._$EO?.forEach(e=>e.hostDisconnected?.())}attributeChangedCallback(e,t,o){this._$AK(e,o)}_$ET(e,t){const o=this.constructor.elementProperties.get(e),r=this.constructor._$Eu(e,o);if(void 0!==r&&!0===o.reflect){const s=(void 0!==o.converter?.toAttribute?o.converter:D).toAttribute(t,o.type);this._$Em=e,null==s?this.removeAttribute(r):this.setAttribute(r,s),this._$Em=null}}_$AK(e,t){const o=this.constructor,r=o._$Eh.get(e);if(void 0!==r&&this._$Em!==r){const e=o.getPropertyOptions(r),s="function"==typeof e.converter?{fromAttribute:e.converter}:void 0!==e.converter?.fromAttribute?e.converter:D;this._$Em=r;const c=s.fromAttribute(t,e.type);this[r]=c??this._$Ej?.get(r)??c,this._$Em=null}}requestUpdate(e,t,o){if(void 0!==e){const r=this.constructor,s=this[e];if(o??=r.getPropertyOptions(e),!((o.hasChanged??q)(s,t)||o.useDefault&&o.reflect&&s===this._$Ej?.get(e)&&!this.hasAttribute(r._$Eu(e,o))))return;this.C(e,t,o)}!1===this.isUpdatePending&&(this._$ES=this._$EP())}C(e,t,{useDefault:o,reflect:r,wrapped:s},c){o&&!(this._$Ej??=new Map).has(e)&&(this._$Ej.set(e,c??t??this[e]),!0!==s||void 0!==c)||(this._$AL.has(e)||(this.hasUpdated||o||(t=void 0),this._$AL.set(e,t)),!0===r&&this._$Em!==e&&(this._$Eq??=new Set).add(e))}async _$EP(){this.isUpdatePending=!0;try{await this._$ES}catch(e){Promise.reject(e)}const e=this.scheduleUpdate();return null!=e&&await e,!this.isUpdatePending}scheduleUpdate(){return this.performUpdate()}performUpdate(){if(!this.isUpdatePending)return;if(!this.hasUpdated){if(this.renderRoot??=this.createRenderRoot(),this._$Ep){for(const[e,t]of this._$Ep)this[e]=t;this._$Ep=void 0}const e=this.constructor.elementProperties;if(e.size>0)for(const[t,o]of e){const{wrapped:e}=o,r=this[t];!0!==e||this._$AL.has(t)||void 0===r||this.C(t,void 0,o,r)}}let e=!1;const t=this._$AL;try{e=this.shouldUpdate(t),e?(this.willUpdate(t),this._$EO?.forEach(e=>e.hostUpdate?.()),this.update(t)):this._$EM()}catch(t){throw e=!1,this._$EM(),t}e&&this._$AE(t)}willUpdate(e){}_$AE(e){this._$EO?.forEach(e=>e.hostUpdated?.()),this.hasUpdated||(this.hasUpdated=!0,this.firstUpdated(e)),this.updated(e)}_$EM(){this._$AL=new Map,this.isUpdatePending=!1}get updateComplete(){return this.getUpdateComplete()}getUpdateComplete(){return this._$ES}shouldUpdate(e){return!0}update(e){this._$Eq&&=this._$Eq.forEach(e=>this._$ET(e,this[e])),this._$EM()}updated(e){}firstUpdated(e){}}N.elementStyles=[],N.shadowRootOptions={mode:"open"},N[H("elementProperties")]=new Map,N[H("finalized")]=new Map,z?.({ReactiveElement:N}),(T.reactiveElementVersions??=[]).push("2.1.1");
|
|
23
|
+
/**
|
|
24
|
+
* @license
|
|
25
|
+
* Copyright 2017 Google LLC
|
|
26
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
27
|
+
*/
|
|
28
|
+
const W={attribute:!0,type:String,converter:D,reflect:!1,hasChanged:q},G=(e=W,t,o)=>{const{kind:r,metadata:s}=o;let c=globalThis.litPropertyMetadata.get(s);if(void 0===c&&globalThis.litPropertyMetadata.set(s,c=new Map),"setter"===r&&((e=Object.create(e)).wrapped=!0),c.set(o.name,e),"accessor"===r){const{name:r}=o;return{set(o){const s=t.get.call(this);t.set.call(this,o),this.requestUpdate(r,s,e)},init(t){return void 0!==t&&this.C(r,void 0,e,t),t}}}if("setter"===r){const{name:r}=o;return function(o){const s=this[r];t.call(this,o),this.requestUpdate(r,s,e)}}throw Error("Unsupported decorator location: "+r)};function V(e){return(t,o)=>"object"==typeof o?G(e,t,o):((e,t,o)=>{const r=t.hasOwnProperty(o);return t.constructor.createProperty(o,e),r?Object.getOwnPropertyDescriptor(t,o):void 0})(e,t,o)}
|
|
29
|
+
/**
|
|
30
|
+
* @license
|
|
31
|
+
* Copyright 2017 Google LLC
|
|
32
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
33
|
+
*/
|
|
34
|
+
/**
|
|
35
|
+
* @license
|
|
36
|
+
* Copyright 2017 Google LLC
|
|
37
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
38
|
+
*/
|
|
39
|
+
function X(e,t){return(t,o,r)=>((e,t,o)=>(o.configurable=!0,o.enumerable=!0,Reflect.decorate&&"object"!=typeof t&&Object.defineProperty(e,t,o),o))(t,o,{get(){return(t=>t.renderRoot?.querySelector(e)??null)(this)}})}const K=e(`var(--m3e-switch-selected-icon-color, ${s.color.onPrimaryContainer})`),I=e("var(--m3e-switch-selected-icon-size, 1rem)"),J=e(`var(--m3e-switch-unselected-icon-color, ${s.color.surfaceContainerHighest})`),Z=e("var(--m3e-switch-unselected-icon-size, 1rem)"),F=e("var(--m3e-switch-track-height, 2rem)"),Q=e("var(--m3e-switch-track-width, 3.25rem)"),Y=e(`var(--m3e-switch-track-outline-color, ${s.color.outline})`),ee=e("var(--m3e-switch-track-outline-width, 0.125rem)"),te=e(`var(--m3e-switch-track-shape, ${s.shape.corner.full})`),oe=e(`var(--m3e-switch-selected-track-color, ${s.color.primary})`),re=e(`var(--m3e-switch-unselected-track-color, ${s.color.surfaceContainerHighest})`),se=e("var(--m3e-switch-unselected-handle-height, 1rem)"),ce=e("var(--m3e-switch-unselected-handle-width, 1rem)"),ae=e("var(--m3e-switch-with-icon-handle-height, 1.5rem)"),ie=e("var(--m3e-switch-with-icon-handle-width, 1.5rem)"),ne=e("var(--m3e-switch-selected-handle-height, 1.5rem)"),de=e("var(--m3e-switch-selected-handle-width, 1.5rem)"),he=e("var(--m3e-switch-pressed-handle-height, 1.75rem)"),le=e("var(--m3e-switch-pressed-handle-width, 1.75rem)"),ue=e(`var(--m3e-switch-handle-shape, ${s.shape.corner.full})`),pe=e(`var(--m3e-switch-selected-handle-color, ${s.color.onPrimary})`),fe=e(`var(--m3e-switch-unselected-handle-color, ${s.color.outline})`),ke=e("var(--m3e-switch-state-layer-size, 2.5rem)"),me=e(`var(--m3e-switch-state-layer-shape, ${s.shape.corner.full})`),be=e(`var(--m3e-switch-disabled-selected-icon-color, ${s.color.onSurface})`),$e=e("var(--m3e-switch-disabled-selected-icon-opacity, 38%)"),ve=e(`var(--m3e-switch-disabled-unselected-icon-color, ${s.color.surfaceContainerHighest})`),ye=e("var(--m3e-switch-disabled-unselected-icon-opacity, 38%)"),we=e("var(--m3e-switch-disabled-track-opacity, 12%)"),ge=e(`var(--m3e-switch-disabled-selected-track-color, ${s.color.onSurface})`),Ee=e(`var(--m3e-switch-disabled-unselected-track-color, ${s.color.surfaceContainerHighest})`),_e=e(`var(--m3e-switch-disabled-unselected-track-outline-color, ${s.color.onSurface})`),Se=e("var(--m3e-switch-disabled-unselected-handle-opacity, 38%)"),Ce=e("var(--m3e-switch-disabled-selected-handle-opacity, 100%)"),Pe=e(`var(--m3e-switch-disabled-selected-handle-color, ${s.color.surface})`),xe=e(`var(--m3e-switch-disabled-unselected-handle-color, ${s.color.onSurface})`),Ue=e(`var(--m3e-switch-selected-hover-icon-color, ${s.color.onPrimaryContainer})`),Oe=e(`var(--m3e-switch-unselected-hover-icon-color, ${s.color.surfaceContainerHighest})`),Ae=e(`var(--m3e-switch-selected-hover-track-color, ${s.color.primary})`),Me=e(`var(--m3e-switch-selected-hover-state-layer-color, ${s.color.primary})`),Re=e("var(--m3e-switch-selected-hover-state-layer-opacity, 8%)"),Te=e(`var(--m3e-switch-unselected-hover-track-color, ${s.color.surfaceContainerHighest})`),je=e(`var(--m3e-switch-unselected-hover-track-outline-color, ${s.color.outline})`),Le=e(`var(--m3e-switch-unselected-hover-state-layer-color, ${s.color.onSurface})`),ze=e("var(--m3e-switch-unselected-hover-state-layer-opacity, 8%)"),He=e(`var(--m3e-switch-selected-hover-handle-color, ${s.color.surfaceContainerHighest})`),De=e(`var(--m3e-switch-unselected-hover-handle-color, ${s.color.onSurfaceVariant})`),qe=e(`var(--m3e-switch-selected-focus-icon-color, ${s.color.onPrimaryContainer})`),Be=e(`var(--m3e-switch-unselected-focus-icon-color, ${s.color.surfaceContainerHighest})`),Ne=e(`var(--m3e-switch-selected-focus-track-color, ${s.color.primary})`),We=e(`var(--m3e-switch-selected-focus-state-layer-color, ${s.color.primary})`),Ge=e("var(--m3e-switch-selected-focus-state-layer-opacity, 10%)"),Ve=e(`var(--m3e-switch-unselected-focus-track-color, ${s.color.surfaceContainerHighest})`),Xe=e(`var(--m3e-switch-unselected-focus-track-outline-color, ${s.color.outline})`),Ke=e(`var(--m3e-switch-unselected-focus-state-layer-color, ${s.color.onSurface})`),Ie=e("var(--m3e-switch-unselected-focus-state-layer-opacity, 10%)"),Je=e(`var(--m3e-switch-selected-focus-handle-color, ${s.color.primaryContainer})`),Ze=e(`var(--m3e-switch-unselected-focus-handle-color, ${s.color.onSurfaceVariant})`),Fe=e(`var(--m3e-switch-selected-pressed-icon-color, ${s.color.onPrimaryContainer})`),Qe=e(`var(--m3e-switch-unselected-pressed-icon-color, ${s.color.surfaceContainerHighest})`),Ye=e(`var(--m3e-switch-selected-pressed-track-color, ${s.color.primary})`),et=(e(`var(--m3e-switch-selected-pressed-state-layer-color, ${s.color.primary})`),e("var(--m3e-switch-selected-pressed-state-layer-opacity, 10%)"),e(`var(--m3e-switch-unselected-pressed-track-color, ${s.color.surfaceContainerHighest})`)),tt=e(`var(--m3e-switch-unselected-pressed-track-outline-color, ${s.color.outline})`),ot=(e(`var(--m3e-switch-unselected-pressed-state-layer-color, ${s.color.onSurface})`),e("var(--m3e-switch-unselected-pressed-state-layer-opacity, 10%)"),e(`var(--m3e-switch-selected-pressed-handle-color, ${s.color.primaryContainer})`)),rt=e(`var(--m3e-switch-unselected-pressed-handle-color, ${s.color.onSurfaceVariant})`),st=t`
|
|
40
|
+
.handle {
|
|
41
|
+
position: relative;
|
|
42
|
+
display: flex;
|
|
43
|
+
align-items: center;
|
|
44
|
+
justify-content: center;
|
|
45
|
+
pointer-events: none;
|
|
46
|
+
transform-origin: center center;
|
|
47
|
+
border-radius: ${ue};
|
|
48
|
+
transition: ${e(`background-color ${s.motion.duration.short4} ${s.motion.easing.standard},\n transform var(--_switch-handle-effect),\n width ${s.motion.spring.fastEffects},\n height ${s.motion.spring.fastEffects}`)};
|
|
49
|
+
}
|
|
50
|
+
.track:not(.pressed) .handle {
|
|
51
|
+
--_switch-handle-effect: ${s.motion.spring.fastSpatial};
|
|
52
|
+
}
|
|
53
|
+
.track.pressed .handle {
|
|
54
|
+
--_switch-handle-effect: ${s.motion.spring.fastEffects};
|
|
55
|
+
}
|
|
56
|
+
:host(:not([aria-disabled="true"]):not([checked])[icons="both"]) .track:not(.pressed) .handle {
|
|
57
|
+
width: ${ie};
|
|
58
|
+
height: ${ae};
|
|
59
|
+
}
|
|
60
|
+
:host(:not([checked]):not([icons="both"])) .track:not(.pressed) .handle,
|
|
61
|
+
:host([aria-disabled="true"]:not([checked])) .handle {
|
|
62
|
+
width: ${ce};
|
|
63
|
+
height: ${se};
|
|
64
|
+
}
|
|
65
|
+
:host([checked]) .track:not(.pressed) .handle {
|
|
66
|
+
width: ${de};
|
|
67
|
+
height: ${ne};
|
|
68
|
+
}
|
|
69
|
+
.track.pressed .handle {
|
|
70
|
+
width: ${le};
|
|
71
|
+
height: ${he};
|
|
72
|
+
}
|
|
73
|
+
:host(:not([aria-disabled="true"]):not([checked]):not(:focus):not(:hover)) .track:not(.pressed) .handle {
|
|
74
|
+
background-color: ${fe};
|
|
75
|
+
}
|
|
76
|
+
:host(:not([aria-disabled="true"]):not([checked]):not(:focus):hover) .track:not(.pressed) .handle {
|
|
77
|
+
background-color: ${De};
|
|
78
|
+
}
|
|
79
|
+
:host(:not([aria-disabled="true"]):not([checked]):focus) .track:not(.pressed) .handle {
|
|
80
|
+
background-color: ${Ze};
|
|
81
|
+
}
|
|
82
|
+
:host(:not([aria-disabled="true"]):not([checked])) .track.pressed .handle {
|
|
83
|
+
background-color: ${rt};
|
|
84
|
+
}
|
|
85
|
+
:host(:not([aria-disabled="true"])[checked]:not(:focus):not(:hover)) .track:not(.pressed) .handle {
|
|
86
|
+
background-color: ${pe};
|
|
87
|
+
}
|
|
88
|
+
:host(:not([aria-disabled="true"])[checked]:not(:focus):hover) .track:not(.pressed) .handle {
|
|
89
|
+
background-color: ${He};
|
|
90
|
+
}
|
|
91
|
+
:host(:not([aria-disabled="true"])[checked]:focus) .track:not(.pressed) .handle {
|
|
92
|
+
background-color: ${Je};
|
|
93
|
+
}
|
|
94
|
+
:host(:not([aria-disabled="true"])[checked]) .track.pressed .handle {
|
|
95
|
+
background-color: ${ot};
|
|
96
|
+
}
|
|
97
|
+
:host([aria-disabled="true"]:not([checked])) .handle {
|
|
98
|
+
background-color: color-mix(
|
|
99
|
+
in srgb,
|
|
100
|
+
${xe} ${Se},
|
|
101
|
+
transparent
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
:host([aria-disabled="true"][checked]) .handle {
|
|
105
|
+
background-color: color-mix(
|
|
106
|
+
in srgb,
|
|
107
|
+
${Pe} ${Ce},
|
|
108
|
+
transparent
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
:host([checked]) .track:not(.pressed) .handle {
|
|
112
|
+
transform: translateX(
|
|
113
|
+
calc(${Q} - ${de} - ${ee})
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
:host([checked]) .track.pressed .handle {
|
|
117
|
+
transform: translateX(
|
|
118
|
+
calc(${Q} - ${le} - ${ee})
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
:host(:not([checked]):not([icons="both"])) .track:not(.pressed) .handle,
|
|
122
|
+
:host([aria-disabled="true"]:not([checked])) .handle {
|
|
123
|
+
transform: translateX(
|
|
124
|
+
calc(
|
|
125
|
+
${ee} + calc(${le} - ${ie})
|
|
126
|
+
)
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
:host(:not([aria-disabled="true"]):not([checked])[icons="both"]) .track:not(.pressed) .handle {
|
|
130
|
+
transform: translateX(${ee});
|
|
131
|
+
}
|
|
132
|
+
@media (forced-colors: active) {
|
|
133
|
+
.handle {
|
|
134
|
+
transition: ${e(`transform var(--_switch-handle-effect),\n width ${s.motion.spring.fastEffects},\n height ${s.motion.spring.fastEffects}`)};
|
|
135
|
+
}
|
|
136
|
+
:host(:not([aria-disabled="true"]):not([checked]):not(:focus):not(:hover)) .track:not(.pressed) .handle,
|
|
137
|
+
:host(:not([aria-disabled="true"]):not([checked]):not(:focus):hover) .track:not(.pressed) .handle,
|
|
138
|
+
:host(:not([aria-disabled="true"]):not([checked]):focus) .track:not(.pressed) .handle,
|
|
139
|
+
:host(:not([aria-disabled="true"]):not([checked])) .track.pressed .handle {
|
|
140
|
+
background-color: ButtonText;
|
|
141
|
+
}
|
|
142
|
+
:host([aria-disabled="true"]:not([checked])) .handle {
|
|
143
|
+
background-color: GrayText;
|
|
144
|
+
}
|
|
145
|
+
:host(:not([aria-disabled="true"])[checked]:not(:focus):not(:hover)) .track:not(.pressed) .handle,
|
|
146
|
+
:host(:not([aria-disabled="true"])[checked]:not(:focus):hover) .track:not(.pressed) .handle,
|
|
147
|
+
:host(:not([aria-disabled="true"])[checked]:focus) .track:not(.pressed) .handle,
|
|
148
|
+
:host(:not([aria-disabled="true"])[checked]) .track.pressed .handle {
|
|
149
|
+
background-color: Canvas;
|
|
150
|
+
}
|
|
151
|
+
:host([aria-disabled="true"][checked]) .handle {
|
|
152
|
+
background-color: Canvas;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
@media (prefers-reduced-motion) {
|
|
156
|
+
.handle {
|
|
157
|
+
transition: none;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
`,ct=t`
|
|
161
|
+
:host([icons="none"]) .icon,
|
|
162
|
+
:host([icons="selected"]:not([checked])) .icon,
|
|
163
|
+
:host([aria-disabled="true"]:not([checked])) .icon {
|
|
164
|
+
display: none;
|
|
165
|
+
}
|
|
166
|
+
.icon {
|
|
167
|
+
width: 1em;
|
|
168
|
+
transition: ${e(`color ${s.motion.duration.short4} ${s.motion.easing.standard}`)};
|
|
169
|
+
}
|
|
170
|
+
:host(:not([checked])) .icon {
|
|
171
|
+
font-size: ${Z};
|
|
172
|
+
}
|
|
173
|
+
:host([checked]) .icon {
|
|
174
|
+
font-size: ${I};
|
|
175
|
+
}
|
|
176
|
+
:host(:not([aria-disabled="true"]):not([checked]):not(:focus):not(:hover)) .track:not(.pressed) .icon {
|
|
177
|
+
color: ${J};
|
|
178
|
+
}
|
|
179
|
+
:host(:not([aria-disabled="true"]):not([checked]):not(:focus):hover) .track:not(.pressed) .icon {
|
|
180
|
+
color: ${Oe};
|
|
181
|
+
}
|
|
182
|
+
:host(:not([aria-disabled="true"]):not([checked]):focus) .track:not(.pressed) .icon {
|
|
183
|
+
color: ${Be};
|
|
184
|
+
}
|
|
185
|
+
:host(:not([aria-disabled="true"]):not([checked])) .track.pressed .icon {
|
|
186
|
+
color: ${Qe};
|
|
187
|
+
}
|
|
188
|
+
:host(:not([aria-disabled="true"])[checked]:not(:focus):not(:hover)) .track:not(.pressed) .icon {
|
|
189
|
+
color: ${K};
|
|
190
|
+
}
|
|
191
|
+
:host(:not([aria-disabled="true"])[checked]:not(:focus):hover) .track:not(.pressed) .icon {
|
|
192
|
+
color: ${Ue};
|
|
193
|
+
}
|
|
194
|
+
:host(:not([aria-disabled="true"])[checked]:focus) .track:not(.pressed) .icon {
|
|
195
|
+
color: ${qe};
|
|
196
|
+
}
|
|
197
|
+
:host(:not([aria-disabled="true"])[checked]) .track.pressed .icon {
|
|
198
|
+
color: ${Fe};
|
|
199
|
+
}
|
|
200
|
+
:host([aria-disabled="true"]:not([checked])) .icon {
|
|
201
|
+
color: color-mix(
|
|
202
|
+
in srgb,
|
|
203
|
+
${ve} ${ye},
|
|
204
|
+
transparent
|
|
205
|
+
);
|
|
206
|
+
}
|
|
207
|
+
:host([aria-disabled="true"][checked]) .icon {
|
|
208
|
+
color: color-mix(
|
|
209
|
+
in srgb,
|
|
210
|
+
${be} ${$e},
|
|
211
|
+
transparent
|
|
212
|
+
);
|
|
213
|
+
}
|
|
214
|
+
@media (forced-colors: active) {
|
|
215
|
+
:host(:not([aria-disabled="true"]):not([checked]):not(:focus):not(:hover)) .track:not(.pressed) .icon,
|
|
216
|
+
:host(:not([aria-disabled="true"]):not([checked]):not(:focus):hover) .track:not(.pressed) .icon,
|
|
217
|
+
:host(:not([aria-disabled="true"]):not([checked]):focus) .track:not(.pressed) .icon,
|
|
218
|
+
:host(:not([aria-disabled="true"]):not([checked])) .track.pressed .icon {
|
|
219
|
+
color: Canvas;
|
|
220
|
+
}
|
|
221
|
+
:host(:not([aria-disabled="true"])[checked]:not(:focus):not(:hover)) .track:not(.pressed) .icon,
|
|
222
|
+
:host(:not([aria-disabled="true"])[checked]:not(:focus):hover) .track:not(.pressed) .icon,
|
|
223
|
+
:host(:not([aria-disabled="true"])[checked]:focus) .track:not(.pressed) .icon,
|
|
224
|
+
:host(:not([aria-disabled="true"])[checked]) .track.pressed .icon {
|
|
225
|
+
color: CanvasText;
|
|
226
|
+
}
|
|
227
|
+
:host([aria-disabled="true"]:not([checked])) .icon {
|
|
228
|
+
color: Canvas;
|
|
229
|
+
}
|
|
230
|
+
:host([aria-disabled="true"][checked]) .icon {
|
|
231
|
+
color: GrayText;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
@media (prefers-reduced-motion) {
|
|
235
|
+
.icon {
|
|
236
|
+
transition: none;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
`,at=t`
|
|
240
|
+
.state-layer {
|
|
241
|
+
width: ${ke};
|
|
242
|
+
height: ${ke};
|
|
243
|
+
border-radius: ${me};
|
|
244
|
+
}
|
|
245
|
+
:host(:not([checked])[icons="both"]) .track:not(.pressed) .state-layer {
|
|
246
|
+
left: calc(0px - calc(calc(${ke} - ${ie}) / 2));
|
|
247
|
+
top: calc(0px - calc(calc(${ke} - ${ae}) / 2));
|
|
248
|
+
}
|
|
249
|
+
:host(:not([checked]):not([icons="both"])) .track:not(.pressed) .state-layer {
|
|
250
|
+
left: calc(0px - calc(calc(${ke} - ${ce}) / 2));
|
|
251
|
+
top: calc(0px - calc(calc(${ke} - ${se}) / 2));
|
|
252
|
+
}
|
|
253
|
+
:host([checked]) .track:not(.pressed) .state-layer {
|
|
254
|
+
left: calc(0px - calc(calc(${ke} - ${de}) / 2));
|
|
255
|
+
top: calc(0px - calc(calc(${ke} - ${ne}) / 2));
|
|
256
|
+
}
|
|
257
|
+
.track.pressed .state-layer {
|
|
258
|
+
left: calc(0px - calc(calc(${ke} - ${le}) / 2));
|
|
259
|
+
top: calc(0px - calc(calc(${ke} - ${le}) / 2));
|
|
260
|
+
}
|
|
261
|
+
:host(:not([checked])) .state-layer {
|
|
262
|
+
--m3e-state-layer-hover-color: ${Le};
|
|
263
|
+
--m3e-state-layer-hover-opacity: ${ze};
|
|
264
|
+
--m3e-state-layer-focus-color: ${Ke};
|
|
265
|
+
--m3e-state-layer-focus-opacity: ${Ie};
|
|
266
|
+
}
|
|
267
|
+
:host([checked]) .state-layer {
|
|
268
|
+
--m3e-state-layer-hover-color: ${Me};
|
|
269
|
+
--m3e-state-layer-hover-opacity: ${Re};
|
|
270
|
+
--m3e-state-layer-focus-color: ${We};
|
|
271
|
+
--m3e-state-layer-focus-opacity: ${Ge};
|
|
272
|
+
}
|
|
273
|
+
`,it=t`
|
|
274
|
+
:host {
|
|
275
|
+
display: inline-block;
|
|
276
|
+
position: relative;
|
|
277
|
+
outline: none;
|
|
278
|
+
height: fit-content;
|
|
279
|
+
width: fit-content;
|
|
280
|
+
}
|
|
281
|
+
.focus-ring {
|
|
282
|
+
border-radius: ${te};
|
|
283
|
+
}
|
|
284
|
+
.touch {
|
|
285
|
+
position: absolute;
|
|
286
|
+
height: 3rem;
|
|
287
|
+
left: 0;
|
|
288
|
+
right: 0;
|
|
289
|
+
}
|
|
290
|
+
.base {
|
|
291
|
+
display: flex;
|
|
292
|
+
align-items: center;
|
|
293
|
+
justify-content: center;
|
|
294
|
+
}
|
|
295
|
+
`,nt=t`
|
|
296
|
+
.track {
|
|
297
|
+
display: flex;
|
|
298
|
+
align-items: center;
|
|
299
|
+
position: relative;
|
|
300
|
+
box-sizing: border-box;
|
|
301
|
+
border-radius: ${te};
|
|
302
|
+
width: ${Q};
|
|
303
|
+
height: ${F};
|
|
304
|
+
transition: ${e(`background-color ${s.motion.duration.short4} ${s.motion.easing.standard}`)};
|
|
305
|
+
}
|
|
306
|
+
:host(:not([checked])) .track {
|
|
307
|
+
border-width: ${ee};
|
|
308
|
+
border-style: solid;
|
|
309
|
+
}
|
|
310
|
+
:host(:not([aria-disabled="true"]):not([checked]):not(:focus):not(:hover)) .track:not(.pressed) {
|
|
311
|
+
border-color: ${Y};
|
|
312
|
+
background-color: ${re};
|
|
313
|
+
}
|
|
314
|
+
:host(:not([aria-disabled="true"]):not([checked]):not(:focus):hover) .track:not(.pressed) {
|
|
315
|
+
border-color: ${je};
|
|
316
|
+
background-color: ${Te};
|
|
317
|
+
}
|
|
318
|
+
:host(:not([aria-disabled="true"]):not([checked]):focus) .track:not(.pressed) {
|
|
319
|
+
border-color: ${Xe};
|
|
320
|
+
background-color: ${Ve};
|
|
321
|
+
}
|
|
322
|
+
:host(:not([aria-disabled="true"]):not([checked])) .track.pressed {
|
|
323
|
+
border-color: ${tt};
|
|
324
|
+
background-color: ${et};
|
|
325
|
+
}
|
|
326
|
+
:host([aria-disabled="true"]:not([checked])) .track {
|
|
327
|
+
border-color: color-mix(
|
|
328
|
+
in srgb,
|
|
329
|
+
${_e} ${we},
|
|
330
|
+
transparent
|
|
331
|
+
);
|
|
332
|
+
background-color: color-mix(
|
|
333
|
+
in srgb,
|
|
334
|
+
${Ee} ${we},
|
|
335
|
+
transparent
|
|
336
|
+
);
|
|
337
|
+
}
|
|
338
|
+
:host(:not([aria-disabled="true"])[checked]:not(:focus):not(:hover)) .track:not(.pressed) {
|
|
339
|
+
background-color: ${oe};
|
|
340
|
+
}
|
|
341
|
+
:host(:not([aria-disabled="true"])[checked]:not(:focus):hover) .track:not(.pressed) {
|
|
342
|
+
background-color: ${Ae};
|
|
343
|
+
}
|
|
344
|
+
:host(:not([aria-disabled="true"])[checked]:focus) .track:not(.pressed) {
|
|
345
|
+
background-color: ${Ne};
|
|
346
|
+
}
|
|
347
|
+
:host(:not([aria-disabled="true"])[checked]) .track.pressed {
|
|
348
|
+
background-color: ${Ye};
|
|
349
|
+
}
|
|
350
|
+
:host([aria-disabled="true"][checked]) .track {
|
|
351
|
+
background-color: color-mix(
|
|
352
|
+
in srgb,
|
|
353
|
+
${ge} ${we},
|
|
354
|
+
transparent
|
|
355
|
+
);
|
|
356
|
+
}
|
|
357
|
+
@media (forced-colors: active) {
|
|
358
|
+
.track {
|
|
359
|
+
transition: none;
|
|
360
|
+
}
|
|
361
|
+
:host(:not([aria-disabled="true"]):not([checked]):not(:focus):not(:hover)) .track:not(.pressed),
|
|
362
|
+
:host(:not([aria-disabled="true"]):not([checked]):not(:focus):hover) .track:not(.pressed),
|
|
363
|
+
:host(:not([aria-disabled="true"]):not([checked]):focus) .track:not(.pressed),
|
|
364
|
+
:host(:not([aria-disabled="true"]):not([checked])) .track.pressed {
|
|
365
|
+
border-color: ButtonText;
|
|
366
|
+
background-color: Canvas;
|
|
367
|
+
}
|
|
368
|
+
:host([aria-disabled="true"]:not([checked])) .track {
|
|
369
|
+
border-color: GrayText;
|
|
370
|
+
background-color: Canvas;
|
|
371
|
+
}
|
|
372
|
+
:host(:not([aria-disabled="true"])[checked]:not(:focus):not(:hover)) .track:not(.pressed),
|
|
373
|
+
:host(:not([aria-disabled="true"])[checked]:not(:focus):hover) .track:not(.pressed),
|
|
374
|
+
:host(:not([aria-disabled="true"])[checked]:focus) .track:not(.pressed),
|
|
375
|
+
:host(:not([aria-disabled="true"])[checked]) .track.pressed {
|
|
376
|
+
background-color: ButtonText;
|
|
377
|
+
}
|
|
378
|
+
:host([aria-disabled="true"][checked]) .track {
|
|
379
|
+
background-color: GrayText;
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
@media (prefers-reduced-motion) {
|
|
383
|
+
.track {
|
|
384
|
+
transition: none;
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
`;var dt,ht,lt,ut,pt,ft;let kt=class extends(c(a(i(n(d(h(l(u(p(f(k(o,"switch")))))))))))){constructor(){super(),dt.add(this),ht.set(this,e=>y(this,dt,"m",ft).call(this,e)),lt.set(this,new m(this,{target:null,callback:e=>{this.disabled||(e?this._stateLayer?.show("hover"):this._stateLayer?.hide("hover"))}})),ut.set(this,new b(this,{target:null,callback:e=>this._track?.classList.toggle("pressed",e&&!this.disabled)})),this.icons="none",this.value="on",new b(this,{isPressedKey:e=>" "===e||"Enter"===e,callback:e=>this._track?.classList.toggle("pressed",e&&!this.disabled)})}get[(ht=new WeakMap,lt=new WeakMap,ut=new WeakMap,dt=new WeakSet,$)](){return this.checked?this.value:null}connectedCallback(){super.connectedCallback(),this.addEventListener("click",y(this,ht,"f"));for(const e of this.labels)y(this,lt,"f").observe(e),y(this,ut,"f").observe(e)}disconnectedCallback(){super.disconnectedCallback(),this.removeEventListener("click",y(this,ht,"f"));for(const e of this.labels)y(this,lt,"f").unobserve(e),y(this,ut,"f").unobserve(e)}firstUpdated(e){super.firstUpdated(e),[this._focusRing,this._stateLayer].forEach(e=>e?.attach(this))}render(){return r`<m3e-focus-ring class="focus-ring"></m3e-focus-ring>
|
|
388
|
+
<div class="track" aria-hidden="true">
|
|
389
|
+
<div class="touch" aria-hidden="true"></div>
|
|
390
|
+
<div class="handle">
|
|
391
|
+
<m3e-state-layer class="state-layer" ?disabled="${this.disabled}"></m3e-state-layer>
|
|
392
|
+
<div class="base">${y(this,dt,"m",pt).call(this)}</div>
|
|
393
|
+
</div>
|
|
394
|
+
</div>`}};pt=function(){return this.checked?r`<svg class="icon" viewBox="0 0 24 24" aria-hidden="true">
|
|
395
|
+
<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>
|
|
396
|
+
</svg>`:r`<svg class="icon" viewBox="0 -960 960 960" fill="currentColor">
|
|
397
|
+
<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" />
|
|
398
|
+
</svg>`},ft=function(e){e.defaultPrevented||(this.checked=!this.checked,this.dispatchEvent(new Event("input",{bubbles:!0,composed:!0,cancelable:!0}))?this.dispatchEvent(new Event("change",{bubbles:!0})):this.checked=!this.checked)},kt.styles=[it,at,nt,st,ct],v([X(".track")],kt.prototype,"_track",void 0),v([X(".focus-ring")],kt.prototype,"_focusRing",void 0),v([X(".state-layer")],kt.prototype,"_stateLayer",void 0),v([V({reflect:!0})],kt.prototype,"icons",void 0),v([V()],kt.prototype,"value",void 0),kt=v([(e=>(t,o)=>{void 0!==o?o.addInitializer(()=>{customElements.define(e,t)}):customElements.define(e,t)})("m3e-switch")],kt);export{kt as M3eSwitchElement};
|
|
399
|
+
//# sourceMappingURL=index.min.js.map
|