12345 |
- /*
- All material copyright ESRI, All Rights Reserved, unless otherwise specified.
- See https://js.arcgis.com/4.24/esri/copyright.txt for details.
- */
- import{_ as e}from"../chunks/tslib.es6.js";import{reparent as t,byId as s,empty as i}from"../core/domUtils.js";import{watch as o,initial as r}from"../core/reactiveUtils.js";import{addFrameTask as n}from"../core/scheduling.js";import{property as h}from"../core/accessorSupport/decorators/property.js";import"../core/arrayUtils.js";import"../core/has.js";import"../core/accessorSupport/ensureType.js";import{subclass as a}from"../core/accessorSupport/decorators/subclass.js";import d from"./overlay/ViewOverlay.js";import u from"../widgets/Popup.js";const l=[0,0];function p(e){const t=(e.ownerDocument||window.document).defaultView,s=e.getBoundingClientRect();return l[0]=s.left+t.pageXOffset,l[1]=s.top+t.pageYOffset,l}function c(e){e&&(i(e),e.parentNode&&e.parentNode.removeChild(e))}function m(e){const t=document.createElement("div");return e.appendChild(t),t}const f=16,y=750,v=512,_=2,g=i=>{let l=class extends i{constructor(...e){super(...e),this._freqInfo={freq:f,time:y},this._overlayRenderTaskHandle=null,this.height=0,this.position=null,this.resizing=!1,this.root=null,this.surface=null,this.suspended=!0,this.ui=null,this.userContent=null,this.width=0,this.widthBreakpoint=null,this.handles.add([o((()=>this.cursor),(e=>{const{surface:t}=this;t&&t.setAttribute("data-cursor",e)})),o((()=>this.interacting),(e=>{const{surface:t}=this;t&&t.setAttribute("data-interacting",e.toString())}))])}initialize(){this.handles.add(o((()=>this.ui),((e,t)=>this._handleUIChange(e,t)))),this._wireUI(this.ui),this.handles.add([this.on("focus",(()=>this.notifyChange("focused"))),this.on("blur",(()=>this.notifyChange("focused")))])}destroy(){this.destroyed||(this.ui&&(this.ui.destroy(),this.ui=null),this.popup&&!this.popup.destroyed&&this.popup.destroy(),this.container=null)}set container(e){const s=this._get("container");if(s===e)return;const i="dom-size";if(this.handles.remove(i),this._stopMeasuring(),s&&(s.classList.remove("esri-view"),this._overlayRenderTaskHandle&&(this._overlayRenderTaskHandle.remove(),this._overlayRenderTaskHandle=null),this.overlay.destroy(),this._set("overlay",null),c(this.root),this._set("root",null),t(this.userContent,s),c(this.userContent),this._set("userContent",null)),e){e.classList.add("esri-view");const s=document.createElement("div");s.className="esri-view-user-storage",t(e,s),e.appendChild(s),this._set("userContent",s);const h=document.createElement("div");h.className="esri-view-root",e.insertBefore(h,e.firstChild),this._set("root",h);const a=document.createElement("div");a.className="esri-view-surface",a.setAttribute("role","application"),a.tabIndex=0,h.appendChild(a),this._set("surface",a);const u=new d;h.appendChild(u.surface),this._set("overlay",u),o((()=>u.needsRender),(e=>{e&&!this._overlayRenderTaskHandle?this._overlayRenderTaskHandle=n({render:()=>{this.overlay.render()}}):this._overlayRenderTaskHandle&&(this._overlayRenderTaskHandle.remove(),this._overlayRenderTaskHandle=null)})),this.forceDOMReadyCycle(),this.handles.add(o((()=>this.size),(e=>{const[t,s]=e,i="esri-view-surface--inset-outline";t>=document.body.clientWidth||s>=document.body.clientHeight?a.classList.add(i):a.classList.remove(i)}),r),i),this._set("container",e),this._startMeasuring()}else this._set("width",0),this._set("height",0),this._set("position",null),this._set("suspended",!0),this._set("surface",null),this._set("container",null)}get focused(){const e=document.activeElement===this.surface;return document.hasFocus()&&e}get popup(){return this._get("popup")||new u({view:this})}set popup(e){const t=this._get("popup");t&&t!==e&&t.destroy(),this._set("popup",e)}get size(){return[this.width,this.height]}blur(){this.surface&&this.surface.blur()}focus(){this.surface&&this.surface.focus()}pageToContainer(e,t,s){const i=this.position;return e-=i[0],t-=i[1],s?(s[0]=e,s[1]=t):s=[e,t],s}containerToPage(e,t,s){const i=this.position;return e+=i[0],t+=i[1],s?(s[0]=e,s[1]=t):s=[e,t],s}_handleUIChange(e,t){t&&(this.handles.remove("ui"),t.destroy()),e&&this._wireUI(e),this._set("ui",e)}_wireUI(e){this.handles.remove("ui"),e&&(e.view=this,this.handles.add([o((()=>this.root),(t=>{e.container=t?m(t):null}),r),o((()=>this.popup),((t,s)=>{const i="popup",o="manual";s&&e.remove(s,i),t&&(t.view=e.view,e.add(t,{key:i,position:o}))}),r)],"ui"))}_stopMeasuring(){this.handles.remove("measuring"),this._get("resizing")&&this._set("resizing",!1)}_startMeasuring(){const e=this._freqInfo;e.freq=f,e.time=y,this.handles.add([(()=>{const t=()=>{e.freq=f,e.time=y};return window.addEventListener("resize",t),{remove(){window.removeEventListener("resize",t)}}})(),n({prepare:e=>{const t=this._measure(),s=this._freqInfo;if(s.time+=e.deltaTime,t&&(s.freq=f,this._get("resizing")||this._set("resizing",!0)),s.time<s.freq)return;s.time=0;const i=this._position();s.freq=i||t?f:Math.min(y,s.freq*_),!t&&s.freq>=v&&this._get("resizing")&&this._set("resizing",!1)}})],"measuring"),this._measure(),this._position()}_measure(){const e=this.container,t=e?e.clientWidth:0,s=e?e.clientHeight:0;if(0===t||0===s)return this.suspended||this._set("suspended",!0),!1;const i=this.width,o=this.height;return t===i&&s===o?(this.suspended&&this._set("suspended",!1),!1):(this._set("width",t),this._set("height",s),this.suspended&&this._set("suspended",!1),this.emit("resize",{oldWidth:i,oldHeight:o,width:t,height:s}),!0)}_position(){const e=this.container,t=this.position,s=p(e);return(!t||s[0]!==t[0]||s[1]!==t[1])&&(this._set("position",[s[0],s[1]]),!0)}forceDOMReadyCycle(){}};return e([h({value:null,cast:e=>s(e)})],l.prototype,"container",null),e([h({readOnly:!0})],l.prototype,"focused",null),e([h({readOnly:!0})],l.prototype,"height",void 0),e([h({type:u})],l.prototype,"popup",null),e([h({type:d})],l.prototype,"overlay",void 0),e([h({readOnly:!0})],l.prototype,"position",void 0),e([h({readOnly:!0})],l.prototype,"resizing",void 0),e([h({readOnly:!0})],l.prototype,"root",void 0),e([h({value:null,readOnly:!0})],l.prototype,"size",null),e([h({readOnly:!0})],l.prototype,"surface",void 0),e([h({readOnly:!0})],l.prototype,"suspended",void 0),e([h()],l.prototype,"ui",void 0),e([h({readOnly:!0})],l.prototype,"userContent",void 0),e([h({readOnly:!0})],l.prototype,"width",void 0),e([h()],l.prototype,"widthBreakpoint",void 0),l=e([a("esri.views.DOMContainer")],l),l};function w(e){return e&&"focus"in e}export{g as DOMContainer,w as isDOMContainer};
|