import{DirHelper as t}from"./vaadin-dir-helper.js";const e=[];let i;new MutationObserver((function(){const t=getDocumentDir();e.forEach((e=>{alignDirs(e,t)}))})).observe(document.documentElement,{attributes:!0,attributeFilter:["dir"]});const alignDirs=function(t,e){e?t.setAttribute("dir",e):t.removeAttribute("dir")},getDocumentDir=function(){return document.documentElement.getAttribute("dir")};export const DirMixin=r=>class VaadinDirMixin extends r{static get properties(){return{dir:{type:String,readOnly:!0}}}static finalize(){super.finalize(),i||(i=t.detectScrollType())}connectedCallback(){super.connectedCallback(),this.hasAttribute("dir")||(this.__subscribe(),alignDirs(this,getDocumentDir()))}attributeChangedCallback(t,i,r){if(super.attributeChangedCallback(t,i,r),"dir"!==t)return;const s=r===getDocumentDir()&&-1===e.indexOf(this),n=!r&&i&&-1===e.indexOf(this),c=r!==getDocumentDir()&&i===getDocumentDir();s||n?(this.__subscribe(),alignDirs(this,getDocumentDir())):c&&this.__subscribe(!1)}disconnectedCallback(){super.disconnectedCallback(),this.__subscribe(!1),this.removeAttribute("dir")}__subscribe(t=!0){t?-1===e.indexOf(this)&&e.push(this):e.indexOf(this)>-1&&e.splice(e.indexOf(this),1)}__getNormalizedScrollLeft(e){return t.getNormalizedScrollLeft(i,this.getAttribute("dir")||"ltr",e)}__setNormalizedScrollLeft(e,r){return t.setNormalizedScrollLeft(i,this.getAttribute("dir")||"ltr",e,r)}};