@m3e/segmented-button 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/dist/index.js ADDED
@@ -0,0 +1,642 @@
1
+ /**
2
+ * @license MIT
3
+ * Copyright (c) 2025 matraic
4
+ * See LICENSE file in the project root for full license text.
5
+ */
6
+ import { LitElement, html, unsafeCSS, css } from 'lit';
7
+ import { Dirty, Touched, Checked, Disabled, AttachInternals, Role, DesignToken, hasAssignedNodes, Labelled, FormAssociated, formValue } from '@m3e/core';
8
+ import { selectionManager, SelectionManager } from '@m3e/core/a11y';
9
+
10
+ /******************************************************************************
11
+ Copyright (c) Microsoft Corporation.
12
+
13
+ Permission to use, copy, modify, and/or distribute this software for any
14
+ purpose with or without fee is hereby granted.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
17
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
18
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
19
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
20
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
21
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
22
+ PERFORMANCE OF THIS SOFTWARE.
23
+ ***************************************************************************** */
24
+ /* global Reflect, Promise, SuppressedError, Symbol, Iterator */
25
+
26
+
27
+ function __decorate(decorators, target, key, desc) {
28
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
29
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
30
+ 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;
31
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
32
+ }
33
+
34
+ function __classPrivateFieldGet(receiver, state, kind, f) {
35
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
36
+ 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");
37
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
38
+ }
39
+
40
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
41
+ var e = new Error(message);
42
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
43
+ };
44
+
45
+ /**
46
+ * @license
47
+ * Copyright 2017 Google LLC
48
+ * SPDX-License-Identifier: BSD-3-Clause
49
+ */
50
+ const t$1=t=>(e,o)=>{ void 0!==o?o.addInitializer((()=>{customElements.define(t,e);})):customElements.define(t,e);};
51
+
52
+ /**
53
+ * @license
54
+ * Copyright 2019 Google LLC
55
+ * SPDX-License-Identifier: BSD-3-Clause
56
+ */
57
+ 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;
58
+
59
+ /**
60
+ * @license
61
+ * Copyright 2017 Google LLC
62
+ * SPDX-License-Identifier: BSD-3-Clause
63
+ */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");
64
+
65
+ /**
66
+ * @license
67
+ * Copyright 2017 Google LLC
68
+ * SPDX-License-Identifier: BSD-3-Clause
69
+ */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)}
70
+
71
+ /**
72
+ * @license
73
+ * Copyright 2017 Google LLC
74
+ * SPDX-License-Identifier: BSD-3-Clause
75
+ */
76
+ const e$1=(e,t,c)=>(c.configurable=true,c.enumerable=true,Reflect.decorate&&"object"!=typeof t&&Object.defineProperty(e,t,c),c);
77
+
78
+ /**
79
+ * @license
80
+ * Copyright 2017 Google LLC
81
+ * SPDX-License-Identifier: BSD-3-Clause
82
+ */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)}})}}
83
+
84
+ var _M3eButtonSegmentElement_instances, _M3eButtonSegmentElement_clickHandler, _M3eButtonSegmentElement_handleIconSlotChange, _M3eButtonSegmentElement_handleClick;
85
+ var M3eButtonSegmentElement_1;
86
+ /**
87
+ * @summary
88
+ * A option that can be selected within a segmented button.
89
+ *
90
+ * @description
91
+ * The `m3e-button-segment` component represents a single selectable option within a segmented button group.
92
+ * It behaves like a toggle-able button, supporting icon and label content, selection state, and accessibility
93
+ * roles. Segments are visually unified but independently interactive, adapting shape, color, and ripple feedback
94
+ * based on their position and state.
95
+ *
96
+ * @example
97
+ * The following example illustrates a single-select segmented button with four segments.
98
+ * ```html
99
+ * <m3e-segmented-button>
100
+ * <m3e-button-segment checked>8 oz</m3e-button-segment>
101
+ * <m3e-button-segment>12 oz</m3e-button-segment>
102
+ * <m3e-button-segment>16 oz</m3e-button-segment>
103
+ * <m3e-button-segment>20 oz</m3e-button-segment>
104
+ * </m3e-segmented-button>
105
+ * ```
106
+ * @example
107
+ * The next example illustrates a multiselect segmented button designated using the `multi` attribute.
108
+ * ```html
109
+ * <m3e-segmented-button multi>
110
+ * <m3e-button-segment checked>$</m3e-button-segment>
111
+ * <m3e-button-segment checked>$$</m3e-button-segment>
112
+ * <m3e-button-segment>$$$</m3e-button-segment>
113
+ * <m3e-button-segment>$$$$</m3e-button-segment>
114
+ * </m3e-segmented-button>
115
+ * ```
116
+ *
117
+ * @tag m3e-button-segment
118
+ *
119
+ * @slot - Renders the label of the option.
120
+ * @slot icon - Renders an icon before the option's label.
121
+ *
122
+ * @attr checked - Whether the element is checked.
123
+ * @attr disabled - Whether the element is disabled.
124
+ * @attr value - A string representing the value of the segment.
125
+ *
126
+ * @fires input - Emitted when the checked state changes.
127
+ * @fires change - Emitted when the checked state changes.
128
+ *
129
+ * @cssprop --m3e-segmented-button-height - Total height of the segmented button.
130
+ * @cssprop --m3e-segmented-button-outline-thickness - Thickness of the button’s border.
131
+ * @cssprop --m3e-segmented-button-outline-color - Color of the button’s border.
132
+ * @cssprop --m3e-segmented-button-padding-start - Padding on the leading edge of the button content.
133
+ * @cssprop --m3e-segmented-button-padding-end - Padding on the trailing edge of the button content.
134
+ * @cssprop --m3e-segmented-button-spacing - Horizontal gap between icon and label.
135
+ * @cssprop --m3e-segmented-button-font-size - Font size of the label text.
136
+ * @cssprop --m3e-segmented-button-font-weight - Font weight of the label text.
137
+ * @cssprop --m3e-segmented-button-line-height - Line height of the label text.
138
+ * @cssprop --m3e-segmented-button-tracking - Letter spacing of the label text.
139
+ * @cssprop --m3e-segmented-button-with-icon-padding-start - Leading padding when an icon is present.
140
+ * @cssprop --m3e-segmented-button-selected-container-color - Background color of a selected segment.
141
+ * @cssprop --m3e-segmented-button-selected-container-hover-color - Hover state-layer color for selected segments.
142
+ * @cssprop --m3e-segmented-button-selected-container-focus-color - Focus state-layer color for selected segments.
143
+ * @cssprop --m3e-segmented-button-selected-ripple-color - Ripple color for selected segments.
144
+ * @cssprop --m3e-segmented-button-selected-label-text-color - Label text color for selected segments.
145
+ * @cssprop --m3e-segmented-button-selected-icon-color - Icon color for selected segments.
146
+ * @cssprop --m3e-segmented-button-unselected-container-hover-color - Hover state-layer color for unselected segments.
147
+ * @cssprop --m3e-segmented-button-unselected-container-focus-color - Focus state-layer color for unselected segments.
148
+ * @cssprop --m3e-segmented-button-unselected-ripple-color - Ripple color for unselected segments.
149
+ * @cssprop --m3e-segmented-button-unselected-label-text-color - Label text color for unselected segments.
150
+ * @cssprop --m3e-segmented-button-unselected-icon-color - Icon color for unselected segments.
151
+ * @cssprop --m3e-segmented-button-icon-size - Font size of the icon.
152
+ * @cssprop --m3e-segmented-button-disabled-outline-color - Base color for disabled segment borders.
153
+ * @cssprop --m3e-segmented-button-disabled-outline-opacity - Opacity applied to disabled segment borders.
154
+ * @cssprop --m3e-segmented-button-disabled-label-text-color - Base color for disabled label text.
155
+ * @cssprop --m3e-segmented-button-disabled-label-text-opacity - Opacity applied to disabled label text.
156
+ * @cssprop --m3e-segmented-button-disabled-icon-color - Base color for disabled icons.
157
+ * @cssprop --m3e-segmented-button-disabled-icon-opacity - Opacity applied to disabled icons.
158
+ */
159
+ let M3eButtonSegmentElement = M3eButtonSegmentElement_1 = class M3eButtonSegmentElement extends Dirty(Touched(Checked(Disabled(AttachInternals(Role(LitElement, "radio"), true))))) {
160
+ constructor() {
161
+ super(...arguments);
162
+ _M3eButtonSegmentElement_instances.add(this);
163
+ /** @private */ _M3eButtonSegmentElement_clickHandler.set(this, (e) => __classPrivateFieldGet(this, _M3eButtonSegmentElement_instances, "m", _M3eButtonSegmentElement_handleClick).call(this, e));
164
+ /**
165
+ * A string representing the value of the segment.
166
+ * @default "on"
167
+ */
168
+ this.value = "on";
169
+ }
170
+ /** @inheritdoc */
171
+ connectedCallback() {
172
+ super.connectedCallback();
173
+ this.addEventListener("click", __classPrivateFieldGet(this, _M3eButtonSegmentElement_clickHandler, "f"));
174
+ }
175
+ /** @inheritdoc */
176
+ disconnectedCallback() {
177
+ super.disconnectedCallback();
178
+ this.removeEventListener("click", __classPrivateFieldGet(this, _M3eButtonSegmentElement_clickHandler, "f"));
179
+ }
180
+ /** @inheritdoc */
181
+ firstUpdated(_changedProperties) {
182
+ super.firstUpdated(_changedProperties);
183
+ [this._focusRing, this._stateLayer, this._ripple].forEach((x) => x?.attach(this));
184
+ }
185
+ /** @inheritdoc */
186
+ update(changedProperties) {
187
+ const segmentedButton = this.closest("m3e-segmented-button");
188
+ if (segmentedButton) {
189
+ this.role = segmentedButton.multi ? "button" : "radio";
190
+ }
191
+ super.update(changedProperties);
192
+ if (changedProperties.has("checked")) {
193
+ segmentedButton?.[selectionManager].notifySelectionChange(this);
194
+ }
195
+ if (changedProperties.has("disabled")) {
196
+ if (this.disabled) {
197
+ if (this.nextElementSibling instanceof M3eButtonSegmentElement_1) {
198
+ if (!this.nextElementSibling.disabled) {
199
+ this.style.setProperty("--_segmented-button-disabled-outline-color", `var(--m3e-segmented-button-outline-color, ${DesignToken.color.outline})`);
200
+ }
201
+ else {
202
+ this.style.removeProperty("--_segmented-button-disabled-outline-color");
203
+ }
204
+ }
205
+ }
206
+ else {
207
+ this.style.removeProperty("--_segmented-button-disabled-outline-color");
208
+ if (this.previousElementSibling instanceof M3eButtonSegmentElement_1) {
209
+ if (this.previousElementSibling.disabled) {
210
+ this.previousElementSibling.style.setProperty("--_segmented-button-disabled-outline-color", `var(--m3e-segmented-button-outline-color, ${DesignToken.color.outline})`);
211
+ }
212
+ else {
213
+ this.previousElementSibling.style.removeProperty("--_segmented-button-disabled-outline-color");
214
+ }
215
+ }
216
+ }
217
+ }
218
+ }
219
+ /** @inheritdoc */
220
+ render() {
221
+ return html `<div class="base">
222
+ <m3e-state-layer class="state-layer" ?disabled="${this.disabled}"></m3e-state-layer>
223
+ <m3e-focus-ring class="focus-ring" ?disabled="${this.disabled}"></m3e-focus-ring>
224
+ <m3e-ripple class="ripple" ?disabled="${this.disabled}"></m3e-ripple>
225
+ <div class="touch" aria-hidden="true"></div>
226
+ <div class="wrapper">
227
+ <div class="icon" aria-hidden="true">
228
+ <svg class="check" viewBox="0 -960 960 960">
229
+ <path fill="currentColor" d="M382-240 154-468l57-57 171 171 367-367 57 57-424 424Z" />
230
+ </svg>
231
+ <slot name="icon" @slotchange="${__classPrivateFieldGet(this, _M3eButtonSegmentElement_instances, "m", _M3eButtonSegmentElement_handleIconSlotChange)}"></slot>
232
+ </div>
233
+ <div class="label">
234
+ <slot></slot>
235
+ </div>
236
+ </div>
237
+ </div>`;
238
+ }
239
+ };
240
+ _M3eButtonSegmentElement_clickHandler = new WeakMap();
241
+ _M3eButtonSegmentElement_instances = new WeakSet();
242
+ _M3eButtonSegmentElement_handleIconSlotChange = function _M3eButtonSegmentElement_handleIconSlotChange(e) {
243
+ this.classList.toggle("-with-icon", hasAssignedNodes(e.target));
244
+ };
245
+ _M3eButtonSegmentElement_handleClick = function _M3eButtonSegmentElement_handleClick(e) {
246
+ if (e.defaultPrevented)
247
+ return;
248
+ const segmentedButton = this.closest("m3e-segmented-button");
249
+ if (segmentedButton && (segmentedButton.multi || !this.checked)) {
250
+ const checked = this.checked;
251
+ this.checked = !this.checked;
252
+ if (this.dispatchEvent(new Event("input", { bubbles: true, composed: true, cancelable: true }))) {
253
+ this.closest("m3e-segmented-button")?.[selectionManager].notifySelectionChange(this);
254
+ this.dispatchEvent(new Event("change", { bubbles: true }));
255
+ }
256
+ else {
257
+ this.checked = checked;
258
+ }
259
+ }
260
+ };
261
+ /** The styles of the element. */
262
+ M3eButtonSegmentElement.styles = css `
263
+ :host {
264
+ display: inline-block;
265
+ position: relative;
266
+ vertical-align: middle;
267
+ outline: none;
268
+ user-select: none;
269
+ flex: 1 1 auto;
270
+ min-width: 0;
271
+ }
272
+ .base {
273
+ display: inline-flex;
274
+ vertical-align: middle;
275
+ align-items: center;
276
+ width: 100%;
277
+ height: calc(var(--m3e-segmented-button-height, 2.5rem) + ${DesignToken.density.calc(-3)});
278
+ box-sizing: border-box;
279
+ border-width: var(--m3e-segmented-button-outline-thickness, 1px);
280
+ border-color: var(--m3e-segmented-button-outline-color, ${DesignToken.color.outline});
281
+ border-style: solid;
282
+ border-radius: inherit;
283
+ border-left-style: var(--_segmented-button-left-border, solid);
284
+ transition: ${unsafeCSS(`background-color ${DesignToken.motion.duration.short4} ${DesignToken.motion.easing.standard}`)};
285
+ }
286
+ .touch {
287
+ position: absolute;
288
+ height: 3rem;
289
+ left: 0;
290
+ right: 0;
291
+ }
292
+ .wrapper {
293
+ width: 100%;
294
+ overflow: hidden;
295
+ display: inline-flex;
296
+ align-items: center;
297
+ padding-inline-start: var(--m3e-segmented-button-padding-start, 1rem);
298
+ padding-inline-end: var(--m3e-segmented-button-padding-end, 1rem);
299
+ column-gap: var(--m3e-segmented-button-spacing, 0.5rem);
300
+ }
301
+ .label {
302
+ font-size: var(--m3e-segmented-button-font-size, ${DesignToken.typescale.standard.label.large.fontSize});
303
+ font-weight: var(--m3e-segmented-button-font-weight, ${DesignToken.typescale.standard.label.large.fontWeight});
304
+ line-height: var(--m3e-segmented-button-line-height, ${DesignToken.typescale.standard.label.large.lineHeight});
305
+ letter-spacing: var(--m3e-segmented-button-tracking, ${DesignToken.typescale.standard.label.large.tracking});
306
+ justify-self: center;
307
+ flex: 1 1 auto;
308
+ white-space: nowrap;
309
+ overflow: hidden;
310
+ text-overflow: ellipsis;
311
+ transition: ${unsafeCSS(`color ${DesignToken.motion.duration.short4} ${DesignToken.motion.easing.standard}`)};
312
+ }
313
+ .icon {
314
+ display: flex;
315
+ align-items: center;
316
+ justify-content: center;
317
+ transition: ${unsafeCSS(`color ${DesignToken.motion.duration.short4} ${DesignToken.motion.easing.standard}`)};
318
+ }
319
+ :host(:not(:disabled)) {
320
+ cursor: pointer;
321
+ }
322
+ :host([checked]:not(.-hide-selection)) .wrapper,
323
+ :host(.-with-icon) .wrapper {
324
+ padding-inline-start: var(--m3e-segmented-button-with-icon-padding-start, 0.75rem);
325
+ }
326
+ :host(:not(:disabled)[checked]) .base {
327
+ background-color: var(--m3e-segmented-button-selected-container-color, ${DesignToken.color.secondaryContainer});
328
+ --m3e-state-layer-hover-color: var(
329
+ --m3e-segmented-button-selected-container-hover-color,
330
+ ${DesignToken.color.onSecondaryContainer}
331
+ );
332
+ --m3e-state-layer-focus-color: var(
333
+ --m3e-segmented-button-selected-container-focus-color,
334
+ ${DesignToken.color.onSecondaryContainer}
335
+ );
336
+ --m3e-ripple-color: var(--m3e-segmented-button-selected-ripple-color, ${DesignToken.color.onSecondaryContainer});
337
+ }
338
+ :host(:not(:disabled)[checked]) .label {
339
+ color: var(--m3e-segmented-button-selected-label-text-color, ${DesignToken.color.onSecondaryContainer});
340
+ }
341
+ :host(:not(:disabled)[checked]) .icon {
342
+ color: var(--m3e-segmented-button-selected-icon-color, ${DesignToken.color.onSecondaryContainer});
343
+ }
344
+ :host(:not(:disabled):not([checked])) .base {
345
+ --m3e-state-layer-hover-color: var(
346
+ --m3e-segmented-button-unselected-container-hover-color,
347
+ ${DesignToken.color.onSurface}
348
+ );
349
+ --m3e-state-layer-focus-color: var(
350
+ --m3e-segmented-button-unselected-container-focus-color,
351
+ ${DesignToken.color.onSurface}
352
+ );
353
+ --m3e-ripple-color: var(--m3e-segmented-button-unselected-ripple-color, ${DesignToken.color.onSurface});
354
+ }
355
+ :host(:not(:disabled):not([checked])) .label {
356
+ color: var(--m3e-segmented-button-unselected-label-text-color, ${DesignToken.color.onSurface});
357
+ }
358
+ :host(:not(:disabled):not([checked])) .icon {
359
+ color: var(--m3e-segmented-button-unselected-icon-color, ${DesignToken.color.onSurface});
360
+ }
361
+ :host(:not(.-with-icon)) .icon {
362
+ margin-inline-start: calc(0px - var(--m3e-segmented-button-spacing, 0.5rem));
363
+ transition: margin-inline-start ${DesignToken.motion.spring.fastEffects};
364
+ }
365
+ .check,
366
+ ::slotted([slot="icon"]) {
367
+ width: 1em;
368
+ font-size: var(--m3e-segmented-button-icon-size, 1.125rem) !important;
369
+ }
370
+ :host(:not([checked])) .check,
371
+ :host(.-hide-selection) .check,
372
+ :host(.-hide-selection:not(.-with-icon)) .icon {
373
+ display: none;
374
+ }
375
+ :host([checked]) .icon {
376
+ margin-inline-start: 0;
377
+ }
378
+ :host([checked]:not(.-hide-selection)) ::slotted([slot="icon"]) {
379
+ display: none !important;
380
+ }
381
+ :host(:disabled) .base {
382
+ border-color: color-mix(
383
+ in srgb,
384
+ var(--m3e-segmented-button-disabled-outline-color, ${DesignToken.color.onSurface})
385
+ var(--m3e-segmented-button-disabled-outline-opacity, 12%),
386
+ transparent
387
+ );
388
+ border-right-color: var(
389
+ --_segmented-button-disabled-outline-color,
390
+ color-mix(
391
+ in srgb,
392
+ var(--m3e-segmented-button-disabled-outline-color, ${DesignToken.color.onSurface})
393
+ var(--m3e-segmented-button-disabled-outline-opacity, 12%),
394
+ transparent
395
+ )
396
+ );
397
+ }
398
+ :host(:disabled) .label {
399
+ color: color-mix(
400
+ in srgb,
401
+ var(--m3e-segmented-button-disabled-label-text-color, ${DesignToken.color.onSurface})
402
+ var(--m3e-segmented-button-disabled-label-text-opacity, 38%),
403
+ transparent
404
+ );
405
+ }
406
+ :host(:disabled) .icon {
407
+ color: color-mix(
408
+ in srgb,
409
+ var(--m3e-segmented-button-disabled-icon-color, ${DesignToken.color.onSurface})
410
+ var(--m3e-segmented-button-disabled-icon-opacity, 38%),
411
+ transparent
412
+ );
413
+ }
414
+ @media (prefers-reduced-motion) {
415
+ .base,
416
+ .icon,
417
+ .label {
418
+ transition: none;
419
+ }
420
+ }
421
+ @media (forced-colors: active) {
422
+ .base,
423
+ .icon,
424
+ .label {
425
+ transition: none !important;
426
+ }
427
+
428
+ :host(:disabled) .label,
429
+ :host(:disabled) .icon {
430
+ color: GrayText;
431
+ }
432
+ :host(:not([selected]):not(:disabled)) .label,
433
+ :host(:not([selected]):not(:disabled)) .icon {
434
+ color: ButtonText;
435
+ }
436
+ :host(:not(:disabled)[checked]) .base {
437
+ background-color: ButtonText;
438
+ }
439
+ :host(:not(:disabled)[checked]) .label,
440
+ :host(:not(:disabled)[checked]) .icon {
441
+ forced-color-adjust: none;
442
+ color: ButtonFace;
443
+ }
444
+ :host {
445
+ --m3e-segmented-button-outline-color: ButtonText;
446
+ }
447
+ }
448
+ `;
449
+ __decorate([
450
+ e(".focus-ring")
451
+ ], M3eButtonSegmentElement.prototype, "_focusRing", void 0);
452
+ __decorate([
453
+ e(".state-layer")
454
+ ], M3eButtonSegmentElement.prototype, "_stateLayer", void 0);
455
+ __decorate([
456
+ e(".ripple")
457
+ ], M3eButtonSegmentElement.prototype, "_ripple", void 0);
458
+ __decorate([
459
+ n()
460
+ ], M3eButtonSegmentElement.prototype, "value", void 0);
461
+ M3eButtonSegmentElement = M3eButtonSegmentElement_1 = __decorate([
462
+ t$1("m3e-button-segment")
463
+ ], M3eButtonSegmentElement);
464
+
465
+ var _M3eSegmentedButtonElement_instances, _M3eSegmentedButtonElement_handleSlotChange, _M3eSegmentedButtonElement_handleKeyDown, _M3eSegmentedButtonElement_handleChange, _a;
466
+ /**
467
+ * @summary
468
+ * A button that allows a user to select from a limited set of options.
469
+ *
470
+ * @description
471
+ * The `m3e-segmented-button` component allows users to select one or more options from a horizontal group.
472
+ * Each segment behaves like a toggle-able button, supporting icon and label content, selection state, and
473
+ * accessibility roles. Built with Material Design 3 principles, it adapts shape, color, and ripple feedback
474
+ * based on interaction state and input modality. Segments are visually unified but independently interactive.
475
+ *
476
+ * @example
477
+ * The following example illustrates a single-select segmented button with four segments.
478
+ * ```html
479
+ * <m3e-segmented-button>
480
+ * <m3e-button-segment checked>8 oz</m3e-button-segment>
481
+ * <m3e-button-segment>12 oz</m3e-button-segment>
482
+ * <m3e-button-segment>16 oz</m3e-button-segment>
483
+ * <m3e-button-segment>20 oz</m3e-button-segment>
484
+ * </m3e-segmented-button>
485
+ * ```
486
+ * @example
487
+ * The next example illustrates a multiselect segmented button designated using the `multi` attribute.
488
+ * ```html
489
+ * <m3e-segmented-button multi>
490
+ * <m3e-button-segment checked>$</m3e-button-segment>
491
+ * <m3e-button-segment checked>$$</m3e-button-segment>
492
+ * <m3e-button-segment>$$$</m3e-button-segment>
493
+ * <m3e-button-segment>$$$$</m3e-button-segment>
494
+ * </m3e-segmented-button>
495
+ * ```
496
+ *
497
+ * @tag m3e-segmented-button
498
+ *
499
+ * @slot - Renders the segments of the button.
500
+ *
501
+ * @attr disabled - Whether the element is disabled.
502
+ * @attr hide-selection-indicator - Whether to hide the selection indicator.
503
+ * @attr multi - Whether multiple options can be selected.
504
+ * @attr name - The name that identifies the element when submitting the associated form.
505
+ *
506
+ * @fires input - Emitted when the checked state of a segment changes.
507
+ * @fires change - Emitted when the checked state of a segment changes.
508
+ *
509
+ * @cssprop --m3e-segmented-button-start-shape - Border radius for the first segment in a segmented button.
510
+ * @cssprop --m3e-segmented-button-end-shape - Border radius for the last segment in a segmented button.
511
+ */
512
+ let M3eSegmentedButtonElement = class M3eSegmentedButtonElement extends Labelled(Dirty(Touched(FormAssociated(Disabled(AttachInternals(Role(LitElement, "radiogroup"))))))) {
513
+ constructor() {
514
+ super(...arguments);
515
+ _M3eSegmentedButtonElement_instances.add(this);
516
+ /** @internal */
517
+ this[_a] = new SelectionManager()
518
+ .withWrap()
519
+ .onActiveItemChange(() => this[selectionManager].activeItem?.click());
520
+ /**
521
+ * Whether multiple options can be selected.
522
+ * @default false
523
+ */
524
+ this.multi = false;
525
+ /**
526
+ * Whether to hide the selection indicator.
527
+ * @default false
528
+ */
529
+ this.hideSelectionIndicator = false;
530
+ }
531
+ /** The segments of the button. */
532
+ get segments() {
533
+ return this[selectionManager]?.items ?? [];
534
+ }
535
+ /** The selected segment(s) of the button. */
536
+ get selected() {
537
+ return this[selectionManager]?.selectedItems ?? [];
538
+ }
539
+ /** The selected value(s) of the button. */
540
+ get value() {
541
+ const values = this.selected.map((x) => x.value);
542
+ switch (values.length) {
543
+ case 0:
544
+ return null;
545
+ case 1:
546
+ return values[0];
547
+ default:
548
+ return values;
549
+ }
550
+ }
551
+ /** @inheritdoc @internal */
552
+ get [(_M3eSegmentedButtonElement_instances = new WeakSet(), _a = selectionManager, formValue)]() {
553
+ const values = this.value;
554
+ if (Array.isArray(values)) {
555
+ const data = new FormData();
556
+ for (const value of values) {
557
+ data.append(this.name, value);
558
+ }
559
+ return data;
560
+ }
561
+ return values;
562
+ }
563
+ /** @inheritdoc */
564
+ connectedCallback() {
565
+ super.connectedCallback();
566
+ this[selectionManager].multi = this.multi;
567
+ this[selectionManager].disableRovingTabIndex(this.multi);
568
+ }
569
+ /** @inheritdoc */
570
+ update(changedProperties) {
571
+ super.update(changedProperties);
572
+ if (changedProperties.has("disabled") && (changedProperties.get("disabled") !== undefined || this.disabled)) {
573
+ this[selectionManager].disabled = this.disabled;
574
+ }
575
+ if (changedProperties.has("multi")) {
576
+ this.role = this.multi ? "group" : "radiogroup";
577
+ this[selectionManager].multi = this.multi;
578
+ this[selectionManager].disableRovingTabIndex(this.multi);
579
+ }
580
+ if (changedProperties.has("hideSelectionIndicator")) {
581
+ this.segments.forEach((x) => x.classList.toggle("-hide-selection", this.hideSelectionIndicator));
582
+ }
583
+ }
584
+ /** @inheritdoc */
585
+ render() {
586
+ return html `<slot
587
+ @slotchange="${__classPrivateFieldGet(this, _M3eSegmentedButtonElement_instances, "m", _M3eSegmentedButtonElement_handleSlotChange)}"
588
+ @keydown="${__classPrivateFieldGet(this, _M3eSegmentedButtonElement_instances, "m", _M3eSegmentedButtonElement_handleKeyDown)}"
589
+ @change="${__classPrivateFieldGet(this, _M3eSegmentedButtonElement_instances, "m", _M3eSegmentedButtonElement_handleChange)}"
590
+ ></slot>`;
591
+ }
592
+ };
593
+ _M3eSegmentedButtonElement_handleSlotChange = function _M3eSegmentedButtonElement_handleSlotChange() {
594
+ const { added } = this[selectionManager].setItems([...this.querySelectorAll("m3e-button-segment")]);
595
+ added.forEach((x) => x.classList.toggle("-hide-selection", this.hideSelectionIndicator));
596
+ };
597
+ _M3eSegmentedButtonElement_handleKeyDown = function _M3eSegmentedButtonElement_handleKeyDown(e) {
598
+ if (!this.multi) {
599
+ this[selectionManager].onKeyDown(e);
600
+ }
601
+ };
602
+ _M3eSegmentedButtonElement_handleChange = function _M3eSegmentedButtonElement_handleChange(e) {
603
+ e.stopPropagation();
604
+ this.dispatchEvent(new Event("change", { bubbles: true }));
605
+ };
606
+ /** The styles of the element. */
607
+ M3eSegmentedButtonElement.styles = css `
608
+ :host {
609
+ display: inline-flex;
610
+ vertical-align: middle;
611
+ align-items: center;
612
+ }
613
+ ::slotted(:first-child) {
614
+ border-radius: var(
615
+ --m3e-segmented-button-start-shape,
616
+ ${DesignToken.shape.corner.full} ${DesignToken.shape.corner.none} ${DesignToken.shape.corner.none}
617
+ ${DesignToken.shape.corner.full}
618
+ );
619
+ }
620
+ ::slotted(:last-child) {
621
+ border-radius: var(
622
+ --m3e-segmented-button-end-shape,
623
+ ${DesignToken.shape.corner.none} ${DesignToken.shape.corner.full} ${DesignToken.shape.corner.full}
624
+ ${DesignToken.shape.corner.none}
625
+ );
626
+ }
627
+ ::slotted(:not(:first-child)) {
628
+ --_segmented-button-left-border: none;
629
+ }
630
+ `;
631
+ __decorate([
632
+ n({ type: Boolean })
633
+ ], M3eSegmentedButtonElement.prototype, "multi", void 0);
634
+ __decorate([
635
+ n({ attribute: "hide-selection-indicator", type: Boolean })
636
+ ], M3eSegmentedButtonElement.prototype, "hideSelectionIndicator", void 0);
637
+ M3eSegmentedButtonElement = __decorate([
638
+ t$1("m3e-segmented-button")
639
+ ], M3eSegmentedButtonElement);
640
+
641
+ export { M3eButtonSegmentElement, M3eSegmentedButtonElement };
642
+ //# sourceMappingURL=index.js.map