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