import{parseFragment as t,registerTemplate as s,freezeTemplate as e,registerDecorators as o,registerComponent as i}from"@kdcloudjs/kwc";import n from"./shadowBaseClassPrivate.js";import{f as r}from"../focus-93ksTIEs.js";import"./utilsPrivate.js";import"../client-Ddi3i8XR.js";import"../ssr-C2pjZzfv.js";import"../observable-tloG64m6.js";import"../empty_html-CjXB8rB4.js";import"../i18n-B98kiI7M.js";import"../normalize-C0Pp7GJL.js";import"./iso8601Utils.js";import"../colorValid-qIPgkqGp.js";import"./tooltipLibrary.js";import"./positionLibrary.js";import"./primitiveBubble.js";import"../kddsCommon-CucK_w70.js";import"../classSet-DY6Qvt6E.js";import"./ariaObserver.js";var a=[function(t,s,e){var o=t?"["+t+"]":"";return"div[data-start]"+o+",\rdiv[data-end]"+o+" {position: fixed;top: 1rem;left: 1rem;}"}];const d=t`<div${"a0:tabindex"} data-start${3}></div>`,u=t`<div${"a0:tabindex"} data-end${3}></div>`,c=[];function l(t,s,e,o){const{ti:i,b:n,sp:r,st:a,s:l}=t,{_m0:m,_m1:p,_m2:_,_m3:h,_m4:f}=o;return[a(d,1,[r(0,{on:p||(o._m1={focus:n(s._focusLastElement)}),attrs:{tabindex:i(s._bookendTabIndex)}},null)]),l("",{key:2,on:_||(o._m2={focusin:n(s._handleFocusIn),focusout:n(s._handleFocusOut)})},c,e),a(u,4,[r(0,{on:f||(o._m4={focus:n(s._focusFirstElement)}),attrs:{tabindex:i(s._bookendTabIndex)}},null)])]}var m=s(l);l.slots=[""],l.stylesheets=[],l.stylesheetToken="kwc-4840k3f1rh1",l.legacyStylesheetToken="D:\\new_workspace\\workspace\\kingdee-base-components\\src\\modules\\kd\\focusTrap-undefined_focusTrap",a&&l.stylesheets.push.apply(l.stylesheets,a),e(l);class p extends n{constructor(...t){super(...t),this._startNode=void 0,this._endNode=void 0,this._focused=!1,this._initialized=!1,this._pendingFocusOut=!1}renderedCallback(){this._initialized||(this._initialized=!0,this._startNode=this.template.querySelector("[data-start]"),this._endNode=this.template.querySelector("[data-end]"))}focus(){this._focused||this._focusFirstElement()}get _bookendTabIndex(){return this._focused?"0":"-1"}_handleFocusIn(){this._pendingFocusOut&&(this._pendingFocusOut=!1),this._focused=!0}_handleFocusOut(){this._pendingFocusOut=!0,requestAnimationFrame(()=>{this._pendingFocusOut&&(this._focused=!1)})}_moveFocusTo(t){const s=this._getFocusableElements();if(s.length>0){let e;"last"===t?e=s[s.length-1]:"first"===t&&(e=s[0]),e.focus()}}_focusFirstElement(){this._moveFocusTo("first")}_focusLastElement(){this._moveFocusTo("last")}_getFocusableElements(){return r(this.template.querySelector("slot"))}}o(p,{publicMethods:["focus"],fields:["_startNode","_endNode","_focused","_initialized","_pendingFocusOut"]});const _=i(p,{tmpl:m,sel:"D:\\new_workspace\\workspace\\kingdee-base-components\\src\\modules\\kd\\focusTrap-",apiVersion:63});export{_ as default};
