UNPKG

g2o-gradient

Version:

g2o LinearGradient and RadialGradient

3 lines (2 loc) 5 kB
System.register(["g2o","g2o-reactive"],(function(t){"use strict";var e,s,i,r,n,o;return{setters:[function(t){e=t.ElementBase,s=t.variable,i=t.vector_from_like,r=t.G20},function(t){n=t.state,o=t.effect}],execute:function(){let h=0;const a="g2o-gradient-",p=function(){return h++};class c extends e{#t=n(0);#e=n(1);#s=n("#fff");#i=s(this);change$=this.#i.asObservable();constructor(t,e,s){super(a+p()),this.offset="number"==typeof t?t:c.Index<=0?0:1,this.opacity="number"==typeof s?s:1,this.color="string"==typeof e?e:c.Index<=0?"#fff":"#000",c.Index=(c.Index+1)%2}static Index=0;get color(){return this.#s.get()}set color(t){this.#s.set(t),this.parent&&this.parent instanceof u&&(this.parent._flagStops=!0),this.#i.set(this)}get offset(){return this.#t.get()}set offset(t){this.#t.set(t),this.parent&&this.parent instanceof u&&(this.parent._flagStops=!0),this.#i.set(this)}get opacity(){return this.#e.get()}set opacity(t){this.#e.set(t),this.parent&&this.parent instanceof u&&(this.parent._flagStops=!0),this.#i.set(this)}}t("Stop",c);class u extends e{#r=0;_flagStops=!1;#n=n("pad");#o=n("userSpaceOnUse");#h=n([]);_change=s(this);change$=this._change.asObservable();constructor(t=[],e={}){var s;super("string"==typeof(s=e).id?s.id:`${a}${p()}`),"string"==typeof e.spreadMethod&&(this.spreadMethod=e.spreadMethod),"string"==typeof e.units&&(this.units=e.units),this.#h=n(function(t){const e=[],s=t.length;for(let i=0;i<s;i++){const s=t[i];if(s instanceof c)e.push(s);else{if(!Array.isArray(s))throw new Error;e.push(new c(s[0],s[1],s[2]))}}return e}(t))}dispose(){super.dispose()}serialize(){return`url(#${this.id})`}render(t,e){this.zzz.disposables.push(o((()=>{for(;t.getLastChild(this.zzz.viewee);)t.removeChild(this.zzz.viewee,t.getLastChild(this.zzz.viewee));const e=this.stops,s=e.length;for(let i=0;i<s;i++){const s=e[i];{const e={id:s.id},i=t.createSVGElement("stop",e);s.zzz.viewee=i,t.appendChild(this.zzz.viewee,i),s.zzz.disposables.push(o((()=>{t.setAttribute(i,"offset",100*s.offset+"%")}))),s.zzz.disposables.push(o((()=>{t.setAttribute(i,"stop-color",s.color)}))),s.zzz.disposables.push(o((()=>{t.setAttribute(i,"stop-opacity",`${s.opacity}`)})))}}})))}incrementUse(t,e){this.#r++,1===this.#r&&this.render(t,e)}decrementUse(t,e){this.#r--,0===this.#r&&(t.removeChild(e,t.downcast(this.zzz.viewee)),this.zzz.viewee=null)}update(){return this._flagStops&&this._change.set(this),this}flagReset(t=!1){return this._flagStops=t,this}get spreadMethod(){return this.#n.get()}set spreadMethod(t){this.#n.set(t)}get stops(){return this.#h.get()}set stops(t){this.#h.set(t)}get units(){return this.#o.get()}set units(t){this.#o.set(t)}}t("Gradient",u);t("LinearGradient",class extends u{#a;#p;constructor(t,e,s,r={}){super(s,r),this.#a=i(t),this.#p=i(e)}render(t,e){if(this.zzz.viewee);else{const s={};s.id=this.id;const i=t.createSVGElement("linearGradient",s);this.zzz.viewee=i,null===t.getParentNode(i)&&t.appendChild(e,i),this.zzz.disposables.push(o((()=>{const e={};e.x1=`${this.point1.x}`,e.y1=`${this.point1.y}`,t.setAttributes(i,e)}))),this.zzz.disposables.push(o((()=>{const e={};e.x2=`${this.point2.x}`,e.y2=`${this.point2.y}`,t.setAttributes(i,e)}))),this.zzz.disposables.push(o((()=>{const e={};e.gradientUnits=this.units,t.setAttributes(i,e)}))),this.zzz.disposables.push(o((()=>{const e={};e.spreadMethod=this.spreadMethod,t.setAttributes(i,e)}))),super.render(t,e)}return this.flagReset()}update(){return this._flagStops&&this._change.set(this),this}flagReset(t=!1){return super.flagReset(t),this}get point1(){return this.#a}set point1(t){t instanceof r&&this.#a.copyVector(t)}get point2(){return this.#p}set point2(t){t instanceof r&&this.#p.copyVector(t)}});t("RadialGradient",class extends u{#c;#u=n(1);#d;constructor(t,e=[],s={}){super(e,s),this.#c=i(t),"number"==typeof s.radius&&this.#u.set(s.radius),this.#d=this.center.clone(),"number"==typeof s.fx&&(this.focal.x=s.fx),"number"==typeof s.fy&&(this.focal.y=s.fy)}render(t,e){if(this.zzz.viewee);else{const s={};s.id=this.id;const i=t.createSVGElement("radialGradient",s);this.zzz.viewee=i,t.appendChild(e,i),super.render(t,e),this.zzz.disposables.push(o((()=>{const e={};e.cx=`${this.center.x}`,e.cy=`${this.center.y}`,t.setAttributes(i,e)}))),this.zzz.disposables.push(o((()=>{const e={};e.fx=`${this.focal.x}`,e.fy=`${this.focal.y}`,t.setAttributes(i,e)}))),this.zzz.disposables.push(o((()=>{const e={};e.gradientUnits=this.units,t.setAttributes(i,e)}))),this.zzz.disposables.push(o((()=>{const e={};e.r=`${this.radius}`,t.setAttributes(i,e)}))),this.zzz.disposables.push(o((()=>{const e={};e.spreadMethod=this.spreadMethod,t.setAttributes(i,e)})))}return this.flagReset()}update(){return this._flagStops&&this._change.set(this),this}flagReset(t=!1){return super.flagReset(t),this}get center(){return this.#c}set center(t){this.#c.copyVector(t)}get focal(){return this.#d}set focal(t){this.#d.copyVector(t)}get radius(){return this.#u.get()}set radius(t){this.#u.set(t)}})}}})); //# sourceMappingURL=index.min.js.map