ReactMaterial3/dist/item-DvSwYnPq.js

42 lines
7.1 KiB
JavaScript

"use strict";const u=require("./class-map-DV5418hw.js"),L=require("./animation-A38fZ1oY.js");/**
* @license
* Copyright 2017 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*/let S;function z(i){return(e,t)=>L.e(e,t,{get(){return(this.renderRoot??S??(S=document.createDocumentFragment())).querySelectorAll(i)}})}/**
* @license
* Copyright 2023 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/function w(i,e=c){const t=y(i,e);return t&&(t.tabIndex=0,t.focus()),t}function A(i,e=c){const t=N(i,e);return t&&(t.tabIndex=0,t.focus()),t}function P(i,e=c){const t=v(i,e);return t&&(t.item.tabIndex=-1),t}function v(i,e=c){for(let t=0;t<i.length;t++){const s=i[t];if(s.tabIndex===0&&e(s))return{item:s,index:t}}return null}function y(i,e=c){for(const t of i)if(e(t))return t;return null}function N(i,e=c){for(let t=i.length-1;t>=0;t--){const s=i[t];if(e(s))return s}return null}function _(i,e,t=c,s=!0){for(let n=1;n<i.length;n++){const a=(n+e)%i.length;if(a<e&&!s)return null;const d=i[a];if(t(d))return d}return i[e]?i[e]:null}function k(i,e,t=c,s=!0){for(let n=1;n<i.length;n++){const a=(e-n+i.length)%i.length;if(a>e&&!s)return null;const d=i[a];if(t(d))return d}return i[e]?i[e]:null}function I(i,e,t=c,s=!0){if(e){const n=_(i,e.index,t,s);return n&&(n.tabIndex=0,n.focus()),n}else return w(i,t)}function x(i,e,t=c,s=!0){if(e){const n=k(i,e.index,t,s);return n&&(n.tabIndex=0,n.focus()),n}else return A(i,t)}function q(){return new Event("deactivate-items",{bubbles:!0,composed:!0})}function K(){return new Event("request-activation",{bubbles:!0,composed:!0})}function c(i){return!i.disabled}/**
* @license
* Copyright 2023 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/const f={ArrowDown:"ArrowDown",ArrowLeft:"ArrowLeft",ArrowUp:"ArrowUp",ArrowRight:"ArrowRight",Home:"Home",End:"End"};class ${constructor(e){this.handleKeydown=r=>{const o=r.key;if(r.defaultPrevented||!this.isNavigableKey(o))return;const m=this.items;if(!m.length)return;const l=v(m,this.isActivatable);r.preventDefault();const g=this.isRtl(),C=g?f.ArrowRight:f.ArrowLeft,T=g?f.ArrowLeft:f.ArrowRight;let h=null;switch(o){case f.ArrowDown:case T:h=I(m,l,this.isActivatable,this.wrapNavigation());break;case f.ArrowUp:case C:h=x(m,l,this.isActivatable,this.wrapNavigation());break;case f.Home:h=w(m,this.isActivatable);break;case f.End:h=A(m,this.isActivatable);break}h&&l&&l.item!==h&&(l.item.tabIndex=-1)},this.onDeactivateItems=()=>{const r=this.items;for(const o of r)this.deactivateItem(o)},this.onRequestActivation=r=>{this.onDeactivateItems();const o=r.target;this.activateItem(o),o.focus()},this.onSlotchange=()=>{const r=this.items;let o=!1;for(const l of r){if(!l.disabled&&l.tabIndex>-1&&!o){o=!0,l.tabIndex=0;continue}l.tabIndex=-1}if(o)return;const m=y(r,this.isActivatable);m&&(m.tabIndex=0)};const{isItem:t,getPossibleItems:s,isRtl:n,deactivateItem:a,activateItem:d,isNavigableKey:R,isActivatable:E,wrapNavigation:D}=e;this.isItem=t,this.getPossibleItems=s,this.isRtl=n,this.deactivateItem=a,this.activateItem=d,this.isNavigableKey=R,this.isActivatable=E,this.wrapNavigation=D??(()=>!0)}get items(){const e=this.getPossibleItems(),t=[];for(const s of e){if(this.isItem(s)){t.push(s);continue}const a=s.item;a&&this.isItem(a)&&t.push(a)}return t}activateNextItem(){const e=this.items,t=v(e,this.isActivatable);return t&&(t.item.tabIndex=-1),I(e,t,this.isActivatable,this.wrapNavigation())}activatePreviousItem(){const e=this.items,t=v(e,this.isActivatable);return t&&(t.item.tabIndex=-1),x(e,t,this.isActivatable,this.wrapNavigation())}}/**
* @license
* Copyright 2023 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/class p extends u.r{constructor(){super(...arguments),this.multiline=!1}render(){return u.x`
<slot name="container"></slot>
<slot class="non-text" name="start"></slot>
<div class="text">
<slot name="overline" @slotchange=${this.handleTextSlotChange}></slot>
<slot
class="default-slot"
@slotchange=${this.handleTextSlotChange}></slot>
<slot name="headline" @slotchange=${this.handleTextSlotChange}></slot>
<slot
name="supporting-text"
@slotchange=${this.handleTextSlotChange}></slot>
</div>
<slot class="non-text" name="trailing-supporting-text"></slot>
<slot class="non-text" name="end"></slot>
`}handleTextSlotChange(){let e=!1,t=0;for(const s of this.textSlots)if(M(s)&&(t+=1),t>1){e=!0;break}this.multiline=e}}u.__decorate([u.n({type:Boolean,reflect:!0})],p.prototype,"multiline",void 0);u.__decorate([z(".text slot")],p.prototype,"textSlots",void 0);function M(i){var e;for(const t of i.assignedNodes({flatten:!0})){const s=t.nodeType===Node.ELEMENT_NODE,n=t.nodeType===Node.TEXT_NODE&&((e=t.textContent)==null?void 0:e.match(/\S/));if(s||n)return!0}return!1}/**
* @license
* Copyright 2024 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/const F=u.i$1`:host{color:var(--md-sys-color-on-surface, #1d1b20);font-family:var(--md-sys-typescale-body-large-font, var(--md-ref-typeface-plain, Roboto));font-size:var(--md-sys-typescale-body-large-size, 1rem);font-weight:var(--md-sys-typescale-body-large-weight, var(--md-ref-typeface-weight-regular, 400));line-height:var(--md-sys-typescale-body-large-line-height, 1.5rem);align-items:center;box-sizing:border-box;display:flex;gap:16px;min-height:56px;overflow:hidden;padding:12px 16px;position:relative;text-overflow:ellipsis}:host([multiline]){min-height:72px}[name=overline]{color:var(--md-sys-color-on-surface-variant, #49454f);font-family:var(--md-sys-typescale-label-small-font, var(--md-ref-typeface-plain, Roboto));font-size:var(--md-sys-typescale-label-small-size, 0.6875rem);font-weight:var(--md-sys-typescale-label-small-weight, var(--md-ref-typeface-weight-medium, 500));line-height:var(--md-sys-typescale-label-small-line-height, 1rem)}[name=supporting-text]{color:var(--md-sys-color-on-surface-variant, #49454f);font-family:var(--md-sys-typescale-body-medium-font, var(--md-ref-typeface-plain, Roboto));font-size:var(--md-sys-typescale-body-medium-size, 0.875rem);font-weight:var(--md-sys-typescale-body-medium-weight, var(--md-ref-typeface-weight-regular, 400));line-height:var(--md-sys-typescale-body-medium-line-height, 1.25rem)}[name=trailing-supporting-text]{color:var(--md-sys-color-on-surface-variant, #49454f);font-family:var(--md-sys-typescale-label-small-font, var(--md-ref-typeface-plain, Roboto));font-size:var(--md-sys-typescale-label-small-size, 0.6875rem);font-weight:var(--md-sys-typescale-label-small-weight, var(--md-ref-typeface-weight-medium, 500));line-height:var(--md-sys-typescale-label-small-line-height, 1rem)}[name=container]::slotted(*){inset:0;position:absolute}.default-slot{display:inline}.default-slot,.text ::slotted(*){overflow:hidden;text-overflow:ellipsis}.text{display:flex;flex:1;flex-direction:column;overflow:hidden}
`;/**
* @license
* Copyright 2023 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/let b=class extends p{};b.styles=[F];b=u.__decorate([u.t$1("md-item")],b);exports.ListController=$;exports.NavigableKeys=f;exports.createDeactivateItemsEvent=q;exports.createRequestActivationEvent=K;exports.deactivateActiveItem=P;exports.getActiveItem=v;exports.getFirstActivatableItem=y;exports.getLastActivatableItem=N;