EffectView.js 3.7 KB

12345
  1. /*
  2. All material copyright ESRI, All Rights Reserved, unless otherwise specified.
  3. See https://js.arcgis.com/4.24/esri/copyright.txt for details.
  4. */
  5. import{_ as t}from"../../chunks/tslib.es6.js";import e from"../../core/Accessor.js";import s from"../../core/has.js";import{clone as r}from"../../core/lang.js";import i from"../../core/Logger.js";import{property as n}from"../../core/accessorSupport/decorators/property.js";import"../../core/accessorSupport/ensureType.js";import{subclass as c}from"../../core/accessorSupport/decorators/subclass.js";import{parse as o}from"./parser.js";import{canInterpolateEffects as f,normalizeEffects as l}from"./utils.js";const a=-1;let h=class extends e{constructor(t){super(t),this._from=null,this._to=null,this._final=null,this._current=[],this._time=0,this.duration=s("mapview-transitions-duration"),this.effects=[]}set effect(t){if(this._get("effect")!==(t=t||"")){this._set("effect",t);try{this._transitionTo(u(t))}catch(e){this._transitionTo([]),i.getLogger(this.declaredClass).warn("Invalid Effect",{effect:t,error:e})}}}get hasEffects(){return this.transitioning||!!this.effects.length}set scale(t){this._updateForScale(t)}get transitioning(){return null!==this._to}canTransitionTo(t){try{return this.scale>0&&_(this._current,u(t),this.scale)}catch{return!1}}transitionStep(t,e){this._applyTimeTransition(t),this._updateForScale(e)}end(){this._applyTimeTransition(this.duration)}_transitionTo(t){this.scale>0&&_(this._current,t,this.scale)?(this._final=t,this._to=r(t),p(this._current,this._to,this.scale),this._from=r(this._current),this._time=0):(this._from=this._to=this._final=null,this._current=t),this._set("effects",this._current[0]?r(this._current[0].effects):[])}_applyTimeTransition(t){if(!(this._to&&this._from&&this._current&&this._final))return;this._time+=t;const e=Math.min(1,this._time/this.duration);for(let s=0;s<this._current.length;s++){const t=this._current[s],r=this._from[s],i=this._to[s];t.scale=m(r.scale,i.scale,e);for(let s=0;s<t.effects.length;s++){const n=t.effects[s],c=r.effects[s],o=i.effects[s];n.interpolate(c,o,e)}}1===e&&(this._current=this._final,this._set("effects",this._current[0]?r(this._current[0].effects):[]),this._from=this._to=this._final=null)}_updateForScale(t){if(this._set("scale",t),0===this._current.length)return;const e=this._current,s=this._current.length-1;let r,i,n=1;if(1===e.length||t>=e[0].scale)i=r=e[0].effects;else if(t<=e[s].scale)i=r=e[s].effects;else for(let c=0;c<s;c++){const s=e[c],o=e[c+1];if(s.scale>=t&&o.scale<=t){n=(t-s.scale)/(o.scale-s.scale),r=s.effects,i=o.effects;break}}for(let c=0;c<this.effects.length;c++){this.effects[c].interpolate(r[c],i[c],n)}}};function u(t){const e=o(t)||[];return g(e)?[{scale:a,effects:e}]:e}function _(t,e,s){if(!t[0]?.effects||!e[0]?.effects)return!0;return!((t[0]?.scale===a||e[0]?.scale===a)&&(t.length>1||e.length>1)&&s<=0)&&f(t[0].effects,e[0].effects)}function p(t,e,s){const r=t.length>e.length?t:e,i=t.length>e.length?e:t,n=i[i.length-1],c=n?.scale??s,o=n?.effects??[];for(let f=i.length;f<r.length;f++)i.push({scale:c,effects:[...o]});for(let f=0;f<r.length;f++)i[f].scale=i[f].scale===a?s:i[f].scale,r[f].scale=r[f].scale===a?s:r[f].scale,l(i[f].effects,r[f].effects)}function m(t,e,s){return t+(e-t)*s}function g(t){const e=t[0];return!!e&&"type"in e}t([n()],h.prototype,"_to",void 0),t([n()],h.prototype,"duration",void 0),t([n({value:""})],h.prototype,"effect",null),t([n({readOnly:!0})],h.prototype,"effects",void 0),t([n({readOnly:!0})],h.prototype,"hasEffects",null),t([n({value:0})],h.prototype,"scale",null),t([n({readOnly:!0})],h.prototype,"transitioning",null),h=t([c("esri.layers.effects.EffectView")],h);export{h as EffectView,_ as canInterpolateEffectStops,u as convertEffectToStops,p as normalizeEffectStops};