// All material copyright Esri, All Rights Reserved, unless otherwise specified. // See https://js.arcgis.com/4.30/esri/copyright.txt for details. //>>built define("../../chunks/tslib.es6 ../../intl ../../core/Accessor ../../core/arrayUtils ../../core/domUtils ../../core/Evented ../../core/handleUtils ../../core/reactiveUtils ../../core/accessorSupport/decorators/property ../../core/accessorSupport/decorators/cast ../../core/has ../../core/accessorSupport/decorators/subclass ../../support/themeUtils ./Component ../../widgets/support/widgetUtils ../../intl/locale".split(" "),function(h,g,v,w,n,x,y,k,l,z,F,A,B,p,C,t){function m(a){return 0===a?"0":`${a}px`} function q(a){const b="object"===typeof a&&null!==a&&Object.getPrototypeOf(a);return null!==b&&b!==Object.prototype||!("component"in a||"index"in a||"position"in a)?null:a}function r(a,{top:b,bottom:c,left:d,right:e}){a.style.top=b;a.style.bottom=c;a.style.left=d;a.style.right=e}const D={left:0,top:0,bottom:0,right:0},u={bottom:30,top:15,right:15,left:15};g=class extends x.EventedAccessor{constructor(a){super(a);this._cornerNameToContainerLookup={};this._positionNameToContainerLookup={};this._components= [];this._componentMap=new Map;this._removeWidgetHandleKey=Symbol("componentOnRemoveSymbol");this._locale=t.getLocale();this.view=null;this._applyViewPadding=()=>{const b=this.container;b&&r(b,this._toPixelPosition(this._getViewPadding()))};this._applyUIPadding=()=>{const b=this._innerContainer;b&&r(b,this._toPixelPosition(this.padding))};this._initContainers()}initialize(){this.addHandles([k.watch(()=>[this.view?.padding,this.container],this._applyViewPadding,k.initial),k.watch(()=>this.padding,this._applyUIPadding, k.initial),k.watch(()=>[this.container,this._locale],([a,b])=>{a&&a.setAttribute("lang",b)},k.initial),t.onLocaleChange(a=>{this._locale=a})])}destroy(){this.container=null;for(const a of this._components)a.destroy();this._components.length=0;this._componentMap.clear()}set container(a){const b=this._get("container");a!==b&&(a&&(a.classList.add("esri-ui"),B.setCalciteThemeClass(a),this._attachContainers(a)),b&&(b.classList.remove("esri-ui"),r(b,{top:"",bottom:"",left:"",right:""}),n.empty(b)),this._set("container", a))}get height(){const a=this.view?.height??0;if(0===a)return a;const b=this._getViewPadding(),{top:c,bottom:d}=b;return Math.max(a-c-d,0)}get padding(){return this._get("padding")}set padding(a){this._overrideIfSome("padding",a)}castPadding(a){return"number"===typeof a?{bottom:a,top:a,right:a,left:a}:{...u,...a}}get width(){const a=this.view?.width??0;if(0===a)return a;const b=this._getViewPadding(),{left:c,right:d}=b;return Math.max(a-c-d,0)}add(a,b){let c,d,e;if(Array.isArray(a))a.forEach(E=>this.add(E, b));else{var f=q(a);f&&({index:c,position:b,component:a,key:d}=f);b&&"object"===typeof b&&({index:c,key:d,position:b,internal:e}=b);!a||b&&!this._isValidPosition(b)||this._add(a,b,c,d,e)}}remove(a,b){if(a){if(Array.isArray(a))return a.map(d=>this.remove(d,b));if((a=this._find(a))&&(!this._componentMap.has(a)||this._componentMap.get(a)?.key===b)){var c=this._components.indexOf(a);a.node.parentNode?.removeChild(a.node);this._componentMap.delete(a);a.widget?.removeHandlesReference(this._removeWidgetHandleKey); return this._components.splice(c,1)[0]}}}empty(a,b={removeInternal:!1}){if(Array.isArray(a))for(const c of a)this.empty(c,b);else{a=Array.prototype.slice.call(this._positionNameToContainerLookup[a??"manual"].children).map(c=>this._findByNode(c)).filter(c=>null==c?!1:!(this._componentMap.get(c)?.internal??!1)||b.removeInternal);for(const c of a)this.remove(c)}}move(a,b){Array.isArray(a)&&a.forEach(e=>this.move(e,b));if(a){var c=q(a)||q(b);if(c){var d=c.index;b=c.position;a=c.component||a}(!b||this._isValidPosition(b))&& (a=this.remove(a))&&this.add(a,{position:b,index:d})}}find(a){return a?(a=this._findById(a))&&(a.widget||a.node):null}getComponents(a,b={includeInternal:!1}){return a?Array.isArray(a)?a.flatMap(c=>this._getComponentsAtPosition(c,b)):this._getComponentsAtPosition(a,b):this._components.filter(c=>b.includeInternal||!(this._componentMap.get(c)?.internal??!1)).map(({widget:c,node:d})=>c??d)}getPosition(a){for(const b in this._positionNameToContainerLookup)if(this._positionNameToContainerLookup[b].contains(a))return b; return null}_add(a,b,c,d,e){a instanceof p||(a=new p({node:a}));const {widget:f}=a;null!=f&&f instanceof v&&f.addHandles(y.makeHandle(()=>{queueMicrotask(()=>this.remove(a))}),this._removeWidgetHandleKey);this._place({component:a,position:b,index:c});this._components.push(a);this._componentMap.set(a,{key:d,internal:e})}_find(a){return a?a instanceof p?this._findByComponent(a):"string"===typeof a?this._findById(a):this._findByNode(a.domNode||a):null}_getViewPadding(){return this.view?.padding??D}_attachContainers(a){a.appendChild(this._innerContainer); a.appendChild(this._manualContainer)}_initContainers(){var a=document.createElement("div");a.classList.add("esri-ui-inner-container","esri-ui-corner-container");const b=document.createElement("div");b.classList.add("esri-ui-inner-container","esri-ui-manual-container");const c=document.createElement("div");c.classList.add("esri-ui-top-left","esri-ui-corner");a.appendChild(c);const d=document.createElement("div");d.classList.add("esri-ui-top-right","esri-ui-corner");a.appendChild(d);const e=document.createElement("div"); e.classList.add("esri-ui-bottom-left","esri-ui-corner");a.appendChild(e);const f=document.createElement("div");f.classList.add("esri-ui-bottom-right","esri-ui-corner");a.appendChild(f);this._innerContainer=a;this._manualContainer=b;a=C.isRTL();this._cornerNameToContainerLookup={"top-left":c,"top-right":d,"bottom-left":e,"bottom-right":f,"top-leading":a?d:c,"top-trailing":a?c:d,"bottom-leading":a?f:e,"bottom-trailing":a?e:f};this._positionNameToContainerLookup={manual:b,...this._cornerNameToContainerLookup}}_isValidPosition(a){return!!this._positionNameToContainerLookup[a]}_place(a){var b= a.position??"manual";const {component:c,index:d}=a;a=this._positionNameToContainerLookup[b];b=null!=d&&-1=b.length?a.appendChild(c.node):n.insertBefore(c.node,b[d])):a.appendChild(c.node)}_toPixelPosition(a){return{top:m(a.top), left:m(a.left),right:m(a.right),bottom:m(a.bottom)}}_findByComponent(a){return this._components.find(b=>b===a)??null}_findById(a){return this._components.find(({id:b})=>b===a)??null}_findByNode(a){return this._components.find(({node:b})=>b===a)??null}_getComponentsAtPosition(a,b){return Array.prototype.slice.call(this._positionNameToContainerLookup[a].children).map(c=>this._findByNode(c)).filter(w.isSome).filter(c=>b.includeInternal||!(this._componentMap.get(c)?.internal??!1)).map(({widget:c,node:d})=> c??d)}};h.__decorate([l.property()],g.prototype,"_locale",void 0);h.__decorate([l.property()],g.prototype,"container",null);h.__decorate([l.property()],g.prototype,"height",null);h.__decorate([l.property({value:u})],g.prototype,"padding",null);h.__decorate([z.cast("padding")],g.prototype,"castPadding",null);h.__decorate([l.property()],g.prototype,"view",void 0);h.__decorate([l.property()],g.prototype,"width",null);return g=h.__decorate([A.subclass("esri.views.ui.UI")],g)});