/**
 * @license MIT
 * Copyright (c) 2025 matraic
 * See LICENSE file in the project root for full license text.
 */
import{LitElement as t,html as e,unsafeCSS as i,css as o,nothing as s}from"lit";import{Selected as r,Disabled as a,AttachInternals as n,Role as l,DesignToken as c,getTextContent as h,guid as d,HtmlFor as p,scrollIntoViewIfNeeded as m,IntersectionController as u,ScrollController as f,MutationController as g,debounce as v,hasAssignedNodes as y}from"@m3e/core";import{SelectionManager as b}from"@m3e/core/a11y";function $(t,e,i,o){var s,r=arguments.length,a=r<3?e:null===o?o=Object.getOwnPropertyDescriptor(e,i):o;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(t,e,i,o);else for(var n=t.length-1;n>=0;n--)(s=t[n])&&(a=(r<3?s(a):r>3?s(e,i,a):s(e,i))||a);return r>3&&a&&Object.defineProperty(e,i,a),a}function w(t,e,i,o){if("a"===i&&!o)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!o:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===i?o:"a"===i?o.call(t):o?o.value:e.get(t)}function _(t,e,i,o,s){if("m"===o)throw new TypeError("Private method is not writable");if("a"===o&&!s)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof e?t!==e||!s:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===o?s.call(t,i):s?s.value=i:e.set(t,i),i}"function"==typeof SuppressedError&&SuppressedError;
/**
 * @license
 * Copyright 2017 Google LLC
 * SPDX-License-Identifier: BSD-3-Clause
 */
const E=t=>(e,i)=>{void 0!==i?i.addInitializer(()=>{customElements.define(t,e)}):customElements.define(t,e)},S=globalThis,P=S.ShadowRoot&&(void 0===S.ShadyCSS||S.ShadyCSS.nativeShadow)&&"adoptedStyleSheets"in Document.prototype&&"replace"in CSSStyleSheet.prototype,k=Symbol(),U=new WeakMap;
/**
 * @license
 * Copyright 2019 Google LLC
 * SPDX-License-Identifier: BSD-3-Clause
 */let O=class{constructor(t,e,i){if(this._$cssResult$=!0,i!==k)throw Error("CSSResult is not constructable. Use `unsafeCSS` or `css` instead.");this.cssText=t,this.t=e}get styleSheet(){let t=this.o;const e=this.t;if(P&&void 0===t){const i=void 0!==e&&1===e.length;i&&(t=U.get(e)),void 0===t&&((this.o=t=new CSSStyleSheet).replaceSync(this.cssText),i&&U.set(e,t))}return t}toString(){return this.cssText}};const A=(t,e)=>{if(P)t.adoptedStyleSheets=e.map(t=>t instanceof CSSStyleSheet?t:t.styleSheet);else for(const i of e){const e=document.createElement("style"),o=S.litNonce;void 0!==o&&e.setAttribute("nonce",o),e.textContent=i.cssText,t.appendChild(e)}},C=P?t=>t:t=>t instanceof CSSStyleSheet?(t=>{let e="";for(const i of t.cssRules)e+=i.cssText;return(t=>new O("string"==typeof t?t:t+"",void 0,k))(e)})(t):t,{is:x,defineProperty:z,getOwnPropertyDescriptor:M,getOwnPropertyNames:I,getOwnPropertySymbols:T,getPrototypeOf:R}=Object,j=globalThis,L=j.trustedTypes,D=L?L.emptyScript:"",W=j.reactiveElementPolyfillSupport,q=(t,e)=>t,N={toAttribute(t,e){switch(e){case Boolean:t=t?D:null;break;case Object:case Array:t=null==t?t:JSON.stringify(t)}return t},fromAttribute(t,e){let i=t;switch(e){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}},H=(t,e)=>!x(t,e),V={attribute:!0,type:String,converter:N,reflect:!1,useDefault:!1,hasChanged:H};
/**
 * @license
 * Copyright 2017 Google LLC
 * SPDX-License-Identifier: BSD-3-Clause
 */Symbol.metadata??=Symbol("metadata"),j.litPropertyMetadata??=new WeakMap;class B 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,e=V){if(e.state&&(e.attribute=!1),this._$Ei(),this.prototype.hasOwnProperty(t)&&((e=Object.create(e)).wrapped=!0),this.elementProperties.set(t,e),!e.noAccessor){const i=Symbol(),o=this.getPropertyDescriptor(t,i,e);void 0!==o&&z(this.prototype,t,o)}}static getPropertyDescriptor(t,e,i){const{get:o,set:s}=M(this.prototype,t)??{get(){return this[e]},set(t){this[e]=t}};return{get:o,set(e){const r=o?.call(this);s?.call(this,e),this.requestUpdate(t,r,i)},configurable:!0,enumerable:!0}}static getPropertyOptions(t){return this.elementProperties.get(t)??V}static _$Ei(){if(this.hasOwnProperty(q("elementProperties")))return;const t=R(this);t.finalize(),void 0!==t.l&&(this.l=[...t.l]),this.elementProperties=new Map(t.elementProperties)}static finalize(){if(this.hasOwnProperty(q("finalized")))return;if(this.finalized=!0,this._$Ei(),this.hasOwnProperty(q("properties"))){const t=this.properties,e=[...I(t),...T(t)];for(const i of e)this.createProperty(i,t[i])}const t=this[Symbol.metadata];if(null!==t){const e=litPropertyMetadata.get(t);if(void 0!==e)for(const[t,i]of e)this.elementProperties.set(t,i)}this._$Eh=new Map;for(const[t,e]of this.elementProperties){const i=this._$Eu(t,e);void 0!==i&&this._$Eh.set(i,t)}this.elementStyles=this.finalizeStyles(this.styles)}static finalizeStyles(t){const e=[];if(Array.isArray(t)){const i=new Set(t.flat(1/0).reverse());for(const t of i)e.unshift(C(t))}else void 0!==t&&e.push(C(t));return e}static _$Eu(t,e){const i=e.attribute;return!1===i?void 0:"string"==typeof i?i:"string"==typeof t?t.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(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,e=this.constructor.elementProperties;for(const i of e.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 A(t,this.constructor.elementStyles),t}connectedCallback(){this.renderRoot??=this.createRenderRoot(),this.enableUpdating(!0),this._$EO?.forEach(t=>t.hostConnected?.())}enableUpdating(t){}disconnectedCallback(){this._$EO?.forEach(t=>t.hostDisconnected?.())}attributeChangedCallback(t,e,i){this._$AK(t,i)}_$ET(t,e){const i=this.constructor.elementProperties.get(t),o=this.constructor._$Eu(t,i);if(void 0!==o&&!0===i.reflect){const s=(void 0!==i.converter?.toAttribute?i.converter:N).toAttribute(e,i.type);this._$Em=t,null==s?this.removeAttribute(o):this.setAttribute(o,s),this._$Em=null}}_$AK(t,e){const i=this.constructor,o=i._$Eh.get(t);if(void 0!==o&&this._$Em!==o){const t=i.getPropertyOptions(o),s="function"==typeof t.converter?{fromAttribute:t.converter}:void 0!==t.converter?.fromAttribute?t.converter:N;this._$Em=o;const r=s.fromAttribute(e,t.type);this[o]=r??this._$Ej?.get(o)??r,this._$Em=null}}requestUpdate(t,e,i){if(void 0!==t){const o=this.constructor,s=this[t];if(i??=o.getPropertyOptions(t),!((i.hasChanged??H)(s,e)||i.useDefault&&i.reflect&&s===this._$Ej?.get(t)&&!this.hasAttribute(o._$Eu(t,i))))return;this.C(t,e,i)}!1===this.isUpdatePending&&(this._$ES=this._$EP())}C(t,e,{useDefault:i,reflect:o,wrapped:s},r){i&&!(this._$Ej??=new Map).has(t)&&(this._$Ej.set(t,r??e??this[t]),!0!==s||void 0!==r)||(this._$AL.has(t)||(this.hasUpdated||i||(e=void 0),this._$AL.set(t,e)),!0===o&&this._$Em!==t&&(this._$Eq??=new Set).add(t))}async _$EP(){this.isUpdatePending=!0;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,e]of this._$Ep)this[t]=e;this._$Ep=void 0}const t=this.constructor.elementProperties;if(t.size>0)for(const[e,i]of t){const{wrapped:t}=i,o=this[e];!0!==t||this._$AL.has(e)||void 0===o||this.C(e,void 0,i,o)}}let t=!1;const e=this._$AL;try{t=this.shouldUpdate(e),t?(this.willUpdate(e),this._$EO?.forEach(t=>t.hostUpdate?.()),this.update(e)):this._$EM()}catch(e){throw t=!1,this._$EM(),e}t&&this._$AE(e)}willUpdate(t){}_$AE(t){this._$EO?.forEach(t=>t.hostUpdated?.()),this.hasUpdated||(this.hasUpdated=!0,this.firstUpdated(t)),this.updated(t)}_$EM(){this._$AL=new Map,this.isUpdatePending=!1}get updateComplete(){return this.getUpdateComplete()}getUpdateComplete(){return this._$ES}shouldUpdate(t){return!0}update(t){this._$Eq&&=this._$Eq.forEach(t=>this._$ET(t,this[t])),this._$EM()}updated(t){}firstUpdated(t){}}B.elementStyles=[],B.shadowRootOptions={mode:"open"},B[q("elementProperties")]=new Map,B[q("finalized")]=new Map,W?.({ReactiveElement:B}),(j.reactiveElementVersions??=[]).push("2.1.1");
/**
 * @license
 * Copyright 2017 Google LLC
 * SPDX-License-Identifier: BSD-3-Clause
 */
const J={attribute:!0,type:String,converter:N,reflect:!1,hasChanged:H},K=(t=J,e,i)=>{const{kind:o,metadata:s}=i;let r=globalThis.litPropertyMetadata.get(s);if(void 0===r&&globalThis.litPropertyMetadata.set(s,r=new Map),"setter"===o&&((t=Object.create(t)).wrapped=!0),r.set(i.name,t),"accessor"===o){const{name:o}=i;return{set(i){const s=e.get.call(this);e.set.call(this,i),this.requestUpdate(o,s,t)},init(e){return void 0!==e&&this.C(o,void 0,t,e),e}}}if("setter"===o){const{name:o}=i;return function(i){const s=this[o];e.call(this,i),this.requestUpdate(o,s,t)}}throw Error("Unsupported decorator location: "+o)};function F(t){return(e,i)=>"object"==typeof i?K(t,e,i):((t,e,i)=>{const o=e.hasOwnProperty(i);return e.constructor.createProperty(i,t),o?Object.getOwnPropertyDescriptor(e,i):void 0})(t,e,i)}
/**
 * @license
 * Copyright 2017 Google LLC
 * SPDX-License-Identifier: BSD-3-Clause
 */function Y(t){return F({...t,state:!0,attribute:!1})}
/**
 * @license
 * Copyright 2017 Google LLC
 * SPDX-License-Identifier: BSD-3-Clause
 */
/**
 * @license
 * Copyright 2017 Google LLC
 * SPDX-License-Identifier: BSD-3-Clause
 */
function G(t,e){return(e,i,o)=>((t,e,i)=>(i.configurable=!0,i.enumerable=!0,Reflect.decorate&&"object"!=typeof e&&Object.defineProperty(t,e,i),i))(e,i,{get(){return(e=>e.renderRoot?.querySelector(t)??null)(this)}})}let Q=class extends(r(a(n(l(t,"link"))))){update(t){super.update(t),t.has("selected")&&(this.ariaSelected=null,this.ariaCurrent=this.selected?"true":null),t.has("node")&&(this.node?this._base?.style.setProperty("--_level",""+(this.node.level-1)):this._base?.style.removeProperty("--_level"))}firstUpdated(t){super.firstUpdated(t),this._stateLayer?.attach(this)}render(){return e`<m3e-state-layer class="state-layer"></m3e-state-layer><div class="base"><slot></slot></div>`}};var X,Z,tt,et,it,ot,st,rt,at,nt,lt,ct,ht;Q.styles=o`:host { display: inline-block; position: relative; user-select: none; outline: none; border-radius: var(--m3e-toc-item-shape, ${c.shape.corner.largeIncreased}); padding-block: var(--m3e-toc-item-padding-block, 0.5rem); -webkit-tap-highlight-color: rgba(0, 0, 0, 0); } :host(:not(:disabled)) { cursor: pointer; } .base { padding-inline-start: calc( var(--m3e-toc-item-padding, 1rem) + calc(var(--m3e-toc-item-inset, 0.75rem) * var(--_level, 0)) ); padding-inline-end: var(--m3e-toc-item-padding, 1rem); transition: ${i(`color var(--m3e-toc-active-indicator-animation-duration, ${c.motion.duration.long1}) ${c.motion.easing.standard}`)}; } :host(:not([selected])) { font-size: var(--m3e-toc-item-font-size, ${c.typescale.standard.body.large.fontSize}); font-weight: var(--m3e-toc-item-font-weight, ${c.typescale.standard.body.large.fontWeight}); line-height: var(--m3e-toc-item-line-height, ${c.typescale.standard.body.large.lineHeight}); letter-spacing: var(--m3e-toc-item-tracking, ${c.typescale.standard.body.large.tracking}); color: var(--m3e-toc-item-color, ${c.color.onSurfaceVariant}); } :host([selected]) { font-size: var(--m3e-toc-item-selected-font-size, ${c.typescale.emphasized.body.large.fontSize}); font-weight: var(--m3e-toc-item-selected-font-weight, ${c.typescale.emphasized.body.large.fontWeight}); line-height: var(--m3e-toc-item-selected-line-height, ${c.typescale.emphasized.body.large.lineHeight}); letter-spacing: var(--m3e-toc-item-selected-tracking, ${c.typescale.emphasized.body.large.tracking}); color: var(--m3e-toc-item-selected-color, ${c.color.onSecondaryContainer}); } .base { justify-content: unset; } .state-layer { --m3e-state-layer-focus-opacity: 0; } @media (prefers-reduced-motion) { .base { transition: none; } }`,$([G(".base")],Q.prototype,"_base",void 0),$([G(".state-layer")],Q.prototype,"_stateLayer",void 0),$([Y()],Q.prototype,"node",void 0),Q=$([E("m3e-toc-item")],Q);class dt{static generate(t,e=6){let i=6;const o=new Array;t.querySelectorAll("h1:not([m3e-toc-ignore]),h2:not([m3e-toc-ignore]),h3:not([m3e-toc-ignore]),h4:not([m3e-toc-ignore]),h5:not([m3e-toc-ignore]),h6:not([m3e-toc-ignore]),m3e-heading[level]:not([m3e-toc-ignore])").forEach(t=>{const e=w(X,X,"m",Z).call(X,t);i=Math.min(e,i),o.push({id:t.id||d(),element:t,level:e,label:h(t,!0),nodes:new Array})});for(let t=i+e-1;t>i;t--)for(let e=0;e<o.length;e++){const i=o[e];if(i.level===t)for(let s=e;s>=0;s--){const e=o[s];if(e.level<t){e.nodes.push(i);break}}}return o.forEach(t=>t.level-=i-1),o.filter(t=>1===t.level)}}X=dt,Z=function(t){return t.tagName.startsWith("H")?parseInt(t.tagName.substring(1)):parseInt(t.getAttribute("level")??"0")};let pt=class extends(p(n(l(t,"navigation")))){constructor(){super(...arguments),tt.add(this),this._toc=[],et.set(this,!1),it.set(this,(new b).withHomeAndEnd().withVerticalOrientation().disableRovingTabIndex().onSelectedItemsChange(()=>{if(this._activeIndicator){const t=w(this,it,"f").selectedItems[0];t?(m(t,this,{block:"nearest",behavior:"smooth"}),this._activeIndicator.style.top=`${t.offsetTop}px`,this._activeIndicator.style.height=`${t.clientHeight}px`,this._activeIndicator.style.visibility=0==t.clientHeight?"hidden":"",this.classList.contains("-no-animate")&&setTimeout(()=>this.classList.toggle("-no-animate",!1),40)):(this.classList.toggle("-no-animate",!0),this._activeIndicator.style.top="0px",this._activeIndicator.style.height="0px",this._activeIndicator.style.visibility="hidden")}})),ot.set(this,new u(this,{target:null,callback:t=>{if(!this.control||w(this,et,"f"))return;const e=this.control.scrollTop;let i=null,o=Number.POSITIVE_INFINITY;if(t.filter(t=>t.isIntersecting).map(t=>t.target).forEach(t=>{const s=t.offsetTop,r=Math.abs(s-e);r<o&&(o=r,i=t)}),i){const t=w(this,it,"f").items.find(t=>t.node?.element===i);t&&w(this,it,"f").select(t)}}})),st.set(this,new f(this,{target:null,callback:()=>_(this,et,!1,"f"),debounce:!0})),rt.set(this,new g(this,{target:null,config:{childList:!0,subtree:!0},callback:()=>this._updateToc()})),this.maxDepth=2}attach(t){super.attach(t),w(this,rt,"f").observe(t),w(this,st,"f").observe(t),w(this,tt,"m",ht).call(this)}detach(){this.control&&(w(this,rt,"f").unobserve(this.control),w(this,st,"f").unobserve(this.control)),super.detach(),w(this,tt,"m",ht).call(this)}update(t){super.update(t),t.has("maxDepth")&&w(this,tt,"m",ht).call(this)}updated(t){if(super.updated(t),t.has("_toc")){const{added:t,removed:e}=w(this,it,"f").setItems([...this.shadowRoot?.querySelectorAll("m3e-toc-item")??[]]);w(this,it,"f").activeItem||(this.classList.toggle("-no-animate",!0),w(this,it,"f").updateActiveItem(t.find(t=>!t.disabled)));for(const e of t)e.node&&w(this,ot,"f").observe(e.node.element);for(const t of e)t.node&&w(this,ot,"f").unobserve(t.node.element)}}render(){return e`<div class="header"><div class="overline"><slot name="overline" @slotchange="${w(this,tt,"m",nt)}"></slot></div><div class="title"><slot name="title" @slotchange="${w(this,tt,"m",lt)}"></slot></div></div><slot></slot><ul class="list">${this._toc.map(t=>w(this,tt,"m",at).call(this,t))}</ul><div class="active-indicator" aria-hidden="true"></div>`}_updateToc(){w(this,tt,"m",ht).call(this)}};et=new WeakMap,it=new WeakMap,ot=new WeakMap,st=new WeakMap,rt=new WeakMap,tt=new WeakSet,at=function t(i){return e`<li><m3e-toc-item tabindex="-1" .node="${i}" @click="${w(this,tt,"m",ct)}">${i.label}</m3e-toc-item>${0==i.nodes.length?s:e`<ul>${i.nodes.map(e=>w(this,tt,"m",t).call(this,e))}</ul>`}</li>`},nt=function(t){this.classList.toggle("-with-overline",y(t.target))},lt=function(t){this.classList.toggle("-with-title",y(t.target))},ct=function(t){t.target instanceof Q&&!t.target.disabled&&t.target.node?.element&&(_(this,et,!0,"f"),t.target.node.element.scrollIntoView({block:"start",behavior:"smooth"}),w(this,it,"f").updateActiveItem(t.target),w(this,it,"f").select(t.target))},ht=function(){this._toc=this.control?dt.generate(this.control,Math.max(1,Math.min(this.maxDepth,6))):[],this.requestUpdate()},pt.styles=o`:host { display: inline-block; position: relative; overflow-y: auto; scrollbar-width: ${c.scrollbar.thinWidth}; scrollbar-color: ${c.scrollbar.color}; width: var(--m3e-toc-width, 9.75rem); } ul { list-style: none; padding-inline-start: unset; margin-block-start: unset; margin-block-end: unset; } ul, li { display: flex; flex-direction: column; align-items: stretch; } m3e-toc-item { flex: none; } .active-indicator { position: absolute; pointer-events: none; box-sizing: border-box; left: 0; right: 0; border-radius: var(--m3e-toc-item-shape, ${c.shape.corner.largeIncreased}); border: 1px solid var(--m3e-toc-active-indicator-color, ${c.color.outline}); transition: ${i(`visibility var(--m3e-toc-active-indicator-animation-duration, ${c.motion.duration.long1})\n          ${c.motion.easing.standard},\n        height var(--m3e-toc-active-indicator-animation-duration, ${c.motion.duration.long1})\n          ${c.motion.easing.standard},\n        top var(--m3e-toc-active-indicator-animation-duration, ${c.motion.duration.long1})\n          ${c.motion.easing.standard}`)}; } .header { display: flex; flex-direction: column; align-items: stretch; padding-inline-start: var(--m3e-toc-item-padding, 1rem); padding-block-end: var(--m3e-toc-header-space, 0.5rem); row-gap: var(--m3e-toc-header-space, 0.5rem); } .overline { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; } .title { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; line-clamp: 2; } :host(:not(.-with-overline)) .overline, :host(:not(.-with-title)) .title, :host(:not(.-with-overline):not(.-with-title)) .header { display: none; } ::slotted([slot="overline"]) { font-size: var(--m3e-toc-overline-font-size, ${c.typescale.standard.label.small.fontSize}); font-weight: var(--m3e-toc-overline-font-weight, ${c.typescale.standard.label.small.fontWeight}); line-height: var(--m3e-toc-overline-line-height, ${c.typescale.standard.label.small.lineHeight}); letter-spacing: var(--m3e-toc-overline-tracking, ${c.typescale.standard.label.small.tracking}); color: var(--m3e-toc-overline-color, ${c.color.onSurfaceVariant}); } ::slotted([slot="title"]) { font-size: var(--m3e-toc-title-font-size, ${c.typescale.standard.headline.small.fontSize}); font-weight: var(--m3e-toc-title-font-weight, ${c.typescale.standard.headline.small.fontWeight}); line-height: var(--m3e-toc-title-line-height, ${c.typescale.standard.headline.small.lineHeight}); letter-spacing: var(--m3e-toc-title-tracking, ${c.typescale.standard.headline.small.tracking}); color: var(--m3e-toc-title-color, ${c.color.onSurface}); } :host(.-no-animate) .active-indicator { transition: none; } @media (prefers-reduced-motion) { .active-indicator { transition: none; } }`,$([Y()],pt.prototype,"_toc",void 0),$([G(".active-indicator")],pt.prototype,"_activeIndicator",void 0),$([F({attribute:"max-depth",type:Number})],pt.prototype,"maxDepth",void 0),$([v(40)],pt.prototype,"_updateToc",null),pt=$([E("m3e-toc")],pt);export{pt as M3eTocElement,Q as M3eTocItemElement,dt as TocGenerator};
//# sourceMappingURL=index.min.js.map
