UNPKG

@arcgis/map-components

Version:
3 lines (2 loc) • 12.7 kB
/* COPYRIGHT Esri - https://js.arcgis.com/5.1/LICENSE.txt */ import{E as L,F as R,P as y,R as k,h as x}from"./ID7AT6M5.js";import{O as b,R as V,d as $,f as C,o as G,q as D,u as w}from"./XDQDTW2I.js";import{a as B}from"./XENQYCEN.js";import{P as E,g as m,o as M}from"./ZJXSHJF2.js";var c=class extends R{_beforeChanged(){super._beforeChanged(),(this.isDirty("cornerRadiusTL")||this.isDirty("cornerRadiusTR")||this.isDirty("cornerRadiusBR")||this.isDirty("cornerRadiusBL"))&&(this._clear=!0)}_draw(){let e=this.width(),t=this.height(),s=e/Math.abs(e),r=t/Math.abs(t),i=0,a=0,l=this.get("strokeWidth",0);this.get("containStroke",!1)&&(e-=s*l,t-=r*l,i+=s*l/2,a+=r*l/2);let n=e,h=t;if(m(n)&&m(h)){let o=Math.min(n,h)/2,u=w(this.get("cornerRadiusTL",8),o),d=w(this.get("cornerRadiusTR",8),o),g=w(this.get("cornerRadiusBR",8),o),f=w(this.get("cornerRadiusBL",8),o),_=Math.min(Math.abs(n/2),Math.abs(h/2));u=x(u,0,_),d=x(d,0,_),g=x(g,0,_),f=x(f,0,_);let p=this._display;p.moveTo(i+u*s,a),p.lineTo(i+n-d*s,a),d>0&&p.arcTo(i+n,a,i+n,a+d*r,d),p.lineTo(i+n,a+h-g*r),g>0&&p.arcTo(i+n,a+h,i+n-g*s,a+h,g),p.lineTo(i+f*s,a+h),f>0&&p.arcTo(i,a+h,i,a+h-f*r,f),p.lineTo(i,a+u*r),u>0&&p.arcTo(i,a,i+u*s,a,u),p.closePath()}}};c.className="RoundedRectangle";c.classNames=R.classNames.concat([c.className]);var v=class extends y{_afterNew(){this._settings.themeTags=b(this._settings.themeTags,["button"]),super._afterNew(),this._settings.background||this.set("background",c.new(this._root,{themeTags:b(this._settings.themeTags,["background"])})),this.setPrivate("trustBounds",!0)}_prepareChildren(){if(super._prepareChildren(),this.isDirty("icon")){let e=this._prevSettings.icon,t=this.get("icon");t!==e&&(this._disposeProperty("icon"),e&&e.dispose(),t&&this.children.push(t),this._prevSettings.icon=t)}if(this.isDirty("label")){let e=this._prevSettings.label,t=this.get("label");t!==e&&(this._disposeProperty("label"),e&&e.dispose(),t&&this.children.push(t),this._prevSettings.label=t)}}};v.className="Button";v.classNames=y.classNames.concat([v.className]);var T=class extends k{_afterNew(){super._afterNew();let e=this.children.push(y.new(this._root,{html:'<textarea class="am5-editable-label"></textarea>',isMeasured:!1}));e.hide(),this.setPrivate("input",e);let t=this.get("background");t?t.set("themeTags",["editablelabel","background"]):t=this.set("background",c.new(this._root,{themeTags:["editablelabel","background"]}))}_beforeChanged(){if(super._beforeChanged(),this.isDirty("editOn")){this._editOnEvents&&this._editOnEvents.dispose();let e=this.get("editOn","click");e!="none"&&(this._editOnEvents=new E([this.getPrivate("input").events.on(e,t=>{}),this.events.on(e,t=>{this.set("active",!0)})]))}}_prepareChildren(){super._prepareChildren(),this._maybeInitTextarea()}_updateChildren(){if(super._updateChildren(),this.isDirty("active")){let e=this.get("active",!1);e?this._startEditing():this._stopEditing();let t=this.get("background");t&&t.set("active",e)}this._syncText(),this._syncStyle()}_maybeInitTextarea(){if(!this._isInited()){let e=this.getPrivate("input");if(e&&e.getPrivate("htmlElement")){let s=e.getPrivate("htmlElement").querySelector(".am5-editable-label");s&&(this.setPrivate("textarea",s),s.addEventListener("input",r=>{this.get("multiLine")===!1&&(s.value=s.value.replace(/\n/g," ")),this.set("text",s.value),this._syncStyle()}),s.addEventListener("blur",r=>this.set("active",!1)),C("keyboardevents")&&this._disposers.push($(document,"keydown",r=>{D(r)=="Escape"&&this.set("active",!1)})),this._disposers.push($(document,"keydown",r=>{D(r)=="Enter"&&this.get("multiLine")===!1&&(r.preventDefault(),this.set("active",!1))})),this.events.dispatch("inited",{type:"inited",target:this}))}}}_isInited(){return!!this.getPrivate("textarea")}_startEditing(){if(!this._isInited()){this.events.once("inited",()=>{this._startEditing()});return}this._text.set("opacity",0);let e=this.getPrivate("input"),t=this.getPrivate("textarea");t&&(this.get("text","")==""&&this.set("text"," "),e.show(0),this.setTimeout(()=>{this._syncStyle(),t.focus()},100))}_stopEditing(){if(!this._isInited()){this.events.once("inited",()=>{this._stopEditing()});return}let e=this.getPrivate("input"),t=this.getPrivate("textarea");t&&(this.set("text",t.value),e.hide(0),this._text.set("opacity",1))}_syncStyle(){let e=this.getPrivate("input"),t=this.getPrivate("textarea"),s=e.getPrivate("htmlElement");if(t&&s){let r=window.getComputedStyle(t);M(r,d=>{t.style[d]="initial"}),t.style.color=this.get("fill",V(0)).toCSS(this.get("fillOpacity",1)),t.style.backgroundColor="rgba(0, 0, 0, 0)",t.style.border="none",t.style.outline="none",t.style.padding="0",t.wrap="off",t.style.resize="none",t.style.overflow="hidden";let i=this.get("maxWidth",0)-this.get("paddingLeft",0)-this.get("paddingRight",0);i>0?t.style.maxWidth=i+"px":t.style.minWidth="",t.style.height="auto",t.style.minHeight=t.scrollHeight+"px",this.get("width")&&(t.style.width=this.width()-this.get("paddingLeft",0)-this.get("paddingRight",0)+"px",t.style.minWidth="");let a=this.get("lineHeight");a?a instanceof B?t.style.lineHeight=a.value+"":m(a)&&(t.style.lineHeight=a+""):t.style.lineHeight="1.2";let l=this.get("fontFamily");l||(l=getComputedStyle(s,"font-family").getPropertyValue("font-family")),t.style.fontFamily=l;let n=this.get("fontSize");n?m(n)?n=n+"px":n=n:n=getComputedStyle(s,"font-size").getPropertyValue("font-size"),t.style.fontSize=n;let h=this.get("fontWeight");h?h=h:h=getComputedStyle(s,"font-weight").getPropertyValue("font-weight"),t.style.fontWeight=h;let o=this.get("fontStyle");o?o=o:o=getComputedStyle(s,"font-style").getPropertyValue("font-style"),t.style.fontStyle=o,this.get("oversizedBehavior")=="wrap"?t.style.whiteSpace="pre-wrap":t.style.whiteSpace="nowrap",this._root.events.on("frameended",()=>{t.style.minWidth==""&&(t.style.minWidth=t.scrollWidth+20+"px");let d=this.get("textAlign","start");d=="center"?(t.style.textAlign="center",!s.style.transform.match(/translateX/)&&!this.get("width")&&(s.style.transform+=" translateX(-50%)")):d=="end"?(t.style.textAlign="right",!s.style.transform.match(/translateX/)&&!this.get("width")&&(s.style.transform+=" translateX(-100%)")):t.style.textAlign=d})}}_syncText(){let e=this.getPrivate("textarea"),t=this.get("text","");t==" "&&(t=""),e&&(e.value=t)}};T.className="EditableLabel";T.classNames=k.classNames.concat([T.className]);var N=class extends y{constructor(){super(...arguments),this.thumb=this._makeThumb(),this.startGrip=this._makeButton(),this.endGrip=this._makeButton(),this._thumbBusy=!1,this._startDown=!1,this._endDown=!1,this._thumbDown=!1}_addOrientationClass(){this._settings.themeTags=b(this._settings.themeTags,["scrollbar",this._settings.orientation]),this._settings.background||(this._settings.background=c.new(this._root,{themeTags:b(this._settings.themeTags,["main","background"])}))}_makeButton(){return this.children.push(v.new(this._root,{themeTags:["resize","button",this.get("orientation")],icon:L.new(this._root,{themeTags:["icon"]})}))}_makeThumb(){return this.children.push(c.new(this._root,{themeTags:["thumb",this.get("orientation")]}))}_handleAnimation(e){e&&this._disposers.push(e.events.on("stopped",()=>{this.setPrivateRaw("isBusy",!1),this._thumbBusy=!1}))}_afterNew(){this._addOrientationClass(),super._afterNew();let e=this.startGrip,t=this.endGrip,s=this.thumb,r=this.get("background");r&&this._disposers.push(r.events.on("click",i=>{this.setPrivateRaw("isBusy",!0);let a=this._display.toLocal(i.point),l=this.width(),n=this.height(),h=this.get("orientation"),o;h=="vertical"?o=(a.y-s.height()/2)/n:o=(a.x-s.width()/2)/l;let u,d;h=="vertical"?(u=o*n,d="y"):(u=o*l,d="x");let g=this.get("animationDuration",0);g>0?(this._thumbBusy=!0,this._handleAnimation(this.thumb.animate({key:d,to:u,duration:g,easing:this.get("animationEasing")}))):(this.thumb.set(d,u),this._root.events.once("frameended",()=>{this.setPrivateRaw("isBusy",!1)}))})),this._disposers.push(s.events.on("dblclick",i=>{if(!G(i.originalEvent,this))return;let a=this.get("animationDuration",0),l=this.get("animationEasing");this.animate({key:"start",to:0,duration:a,easing:l}),this.animate({key:"end",to:1,duration:a,easing:l})})),this._disposers.push(e.events.on("pointerdown",()=>{this.setPrivateRaw("isBusy",!0),this._startDown=!0,this._gripDown="start"})),this._disposers.push(t.events.on("pointerdown",()=>{this.setPrivateRaw("isBusy",!0),this._endDown=!0,this._gripDown="end"})),this._disposers.push(s.events.on("pointerdown",()=>{this.setPrivateRaw("isBusy",!0),this._thumbDown=!0,this._gripDown=void 0})),this._disposers.push(e.events.on("globalpointerup",()=>{this._startDown&&(this.setPrivateRaw("isBusy",!1),this._released()),this._startDown=!1})),this._disposers.push(t.events.on("globalpointerup",()=>{this._endDown&&(this.setPrivateRaw("isBusy",!1),this._released()),this._endDown=!1})),this._disposers.push(s.events.on("globalpointerup",()=>{this._thumbDown&&(this.setPrivateRaw("isBusy",!1),this._released()),this._thumbDown=!1})),this._disposers.push(e.on("x",()=>{this._updateThumb()})),this._disposers.push(t.on("x",()=>{this._updateThumb()})),this._disposers.push(e.on("y",()=>{this._updateThumb()})),this._disposers.push(t.on("y",()=>{this._updateThumb()})),this._disposers.push(s.events.on("positionchanged",()=>{this._updateGripsByThumb()})),this.get("orientation")=="vertical"?(e.set("x",0),t.set("x",0),this._disposers.push(s.adapters.add("y",i=>Math.max(Math.min(Number(i),this.height()-s.height()),0))),this._disposers.push(s.adapters.add("x",i=>this.width()/2)),this._disposers.push(e.adapters.add("x",i=>this.width()/2)),this._disposers.push(t.adapters.add("x",i=>this.width()/2)),this._disposers.push(e.adapters.add("y",i=>Math.max(Math.min(Number(i),this.height()),0))),this._disposers.push(t.adapters.add("y",i=>Math.max(Math.min(Number(i),this.height()),0)))):(e.set("y",0),t.set("y",0),this._disposers.push(s.adapters.add("x",i=>Math.max(Math.min(Number(i),this.width()-s.width()),0))),this._disposers.push(s.adapters.add("y",i=>this.height()/2)),this._disposers.push(e.adapters.add("y",i=>this.height()/2)),this._disposers.push(t.adapters.add("y",i=>this.height()/2)),this._disposers.push(e.adapters.add("x",i=>Math.max(Math.min(Number(i),this.width()),0))),this._disposers.push(t.adapters.add("x",i=>Math.max(Math.min(Number(i),this.width()),0))))}_updateChildren(){super._updateChildren(),(this.isDirty("end")||this.isDirty("start")||this._sizeDirty)&&this.updateGrips()}_changed(){if(super._changed(),this.isDirty("start")||this.isDirty("end")){let e="rangechanged";this.events.isEnabled(e)&&this.events.dispatch(e,{type:e,target:this,start:this.get("start",0),end:this.get("end",1),grip:this._gripDown})}}_released(){let e="released";this.events.isEnabled(e)&&this.events.dispatch(e,{type:e,target:this})}updateGrips(){let e=this.startGrip,t=this.endGrip,s=this.get("orientation"),r=this.height(),i=this.width();s=="vertical"?(e.set("y",r*this.get("start",0)),t.set("y",r*this.get("end",1))):(e.set("x",i*this.get("start",0)),t.set("x",i*this.get("end",1)));let a=this.getPrivate("positionTextFunction"),l=Math.round(this.get("start",0)*100),n=Math.round(this.get("end",0)*100),h,o;a?(h=a.call(this,this.get("start",0)),o=a.call(this,this.get("end",0))):(h=l+"%",o=n+"%"),e.set("ariaLabel",this._t("From %1",void 0,h)),e.set("ariaValueNow",""+l),e.set("ariaValueText",l+"%"),e.set("ariaValueMin","0"),e.set("ariaValueMax","100"),t.set("ariaLabel",this._t("To %1",void 0,o)),t.set("ariaValueNow",""+n),t.set("ariaValueText",n+"%"),t.set("ariaValueMin","0"),t.set("ariaValueMax","100")}_updateThumb(){let e=this.thumb,t=this.startGrip,s=this.endGrip,r=this.height(),i=this.width(),a=t.x(),l=s.x(),n=t.y(),h=s.y(),o=0,u=1;this.get("orientation")=="vertical"?m(n)&&m(h)&&(!this._thumbBusy&&!e.isDragging()&&(e.set("height",h-n),e.set("y",n)),o=n/r,u=h/r):m(a)&&m(l)&&(!this._thumbBusy&&!e.isDragging()&&(e.set("width",l-a),e.set("x",a)),o=a/i,u=l/i),this.getPrivate("isBusy")&&(this.get("start")!=o||this.get("end")!=u)&&(this.set("start",o),this.set("end",u));let d=this.getPrivate("positionTextFunction"),g=Math.round(this.get("start",0)*100),f=Math.round(this.get("end",0)*100),_,p;d?(_=d.call(this,this.get("start",0)),p=d.call(this,this.get("end",0))):(_=g+"%",p=f+"%"),e.set("ariaLabel",this._t("From %1 to %2",void 0,_,p)),e.set("ariaValueNow",""+g),e.set("ariaValueText",g+"%")}_updateGripsByThumb(){let e=this.thumb,t=this.startGrip,s=this.endGrip;if(this.get("orientation")=="vertical"){let r=e.height();t.set("y",e.y()),s.set("y",e.y()+r)}else{let r=e.width();t.set("x",e.x()),s.set("x",e.x()+r)}}};N.className="Scrollbar";N.classNames=y.classNames.concat([N.className]);export{c as a,v as b,T as c,N as d};