UNPKG

@g20/graphics

Version:
3 lines (2 loc) 5.12 kB
import{is_color as t,Path as s,dispose as i,Anchor as e,G20 as o}from"@g20/core";import{signal as r,effect as n}from"@g20/reactive";function a(s,i){return t(s)?s:i}function u(t,s){return"number"==typeof t?t:s}function l(t,s){return"number"==typeof t?t:3/s.sx}const h=Math.cos,d=Math.sin;class c extends s{#t=[];#s=r(1);#i=r(0);#e=r(6);constructor(t,s={}){if(super(t,[],!0,!1,!0,function(t,s){const i={id:t.id,attitude:t.attitude,opacity:t.opacity,position:t.position,visibility:t.visibility,fillColor:a(t.fillColor,s.defaults.polygon.fillColor),fillOpacity:u(t.fillOpacity,s.defaults.polygon.fillOpacity),strokeColor:a(t.strokeColor,s.defaults.polygon.strokeColor),strokeOpacity:u(t.strokeOpacity,s.defaults.polygon.strokeOpacity),strokeWidth:l(t.strokeWidth,s)};return i}(s,t)),"number"==typeof s.radius&&(this.radius=s.radius),"number"==typeof s.sides){const t=3,i=24;this.sides=Math.min(Math.max(s.sides,t),i)}"number"==typeof s.twist&&(this.twist=s.twist),this.#t.push(n((()=>{this.update()}))),this.flagReset(!0)}dispose(){i(this.#t),super.dispose()}update(){return function(t,s,i,r){const n=s+1;r.length>n&&r.splice(n,r.length-n);for(;r.length<n;)r.push(new e(o.vector(0,0)));for(let e=0;e<n;e++){const o=2*Math.PI*e/s+i,n=t*h(o),a=t*d(o),u=r.getAt(e);u.origin.set(n,a),u.command=0===e?"M":"L"}}(this.radius,this.sides,this.twist,this.vertices),super.update(),this}flagReset(t=!1){return super.flagReset(t),this}get radius(){return this.#s.get()}set radius(t){this.#s.set(t)}get sides(){return this.#e.get()}set sides(t){this.#e.set(t)}get twist(){return this.#i.get()}set twist(t){this.#i.set(t)}}class p extends s{#t=[];#o=r(Math.SQRT2);#r=r(Math.SQRT2);#s=r(.2);constructor(t,s={}){void 0===s.radius&&"number"==typeof s.width&&"number"==typeof s.height&&(s.radius=Math.floor(Math.min(s.width,s.height)/12));const i=[];for(let t=0;t<10;t++){const s=o.vector(0,0),r=0===t?"M":"C";i.push(new e(s,r))}super(t,i,!0,!1,!0,function(t,s){const i={id:t.id,attitude:t.attitude,opacity:t.opacity,position:t.position,visibility:t.visibility,fillColor:a(t.fillColor,s.defaults.polygon.fillColor),fillOpacity:u(t.fillOpacity,s.defaults.polygon.fillOpacity),strokeColor:a(t.strokeColor,s.defaults.polygon.strokeColor),strokeOpacity:u(t.strokeOpacity,s.defaults.polygon.strokeOpacity),strokeWidth:l(t.strokeWidth,s)};return i}(s,t)),"number"==typeof s.width&&(this.width=s.width),"number"==typeof s.height&&(this.height=s.height),"number"==typeof s.radius&&(this.radius=s.radius),this.#t.push(n((()=>{this.update()})))}dispose(){i(this.#t),super.dispose()}update(){return function(t,s,i,e){const o=i,r=i;let n;const a=t/2,u=s/2;n=e.getAt(0),n.x=-(a-o),n.y=-u,n=e.getAt(1),n.x=a-o,n.y=-u,n.controls.a.clear(),n.controls.b.x=o,n.controls.b.y=0,n=e.getAt(2),n.x=a,n.y=-(u-r),n.controls.b.clear(),n.controls.a.clear(),n=e.getAt(3),n.x=a,n.y=u-r,n.controls.a.clear(),n.controls.b.x=0,n.controls.b.y=r,n=e.getAt(4),n.x=a-o,n.y=u,n.controls.b.clear(),n.controls.a.clear(),n=e.getAt(5),n.x=-(a-o),n.y=u,n.controls.a.clear(),n.controls.b.x=-o,n.controls.b.y=0,n=e.getAt(6),n.x=-a,n.y=u-r,n.controls.a.clear(),n.controls.b.clear(),n=e.getAt(7),n.x=-a,n.y=-(u-r),n.controls.a.clear(),n.controls.b.x=0,n.controls.b.y=-r,n=e.getAt(8),n.x=-(a-o),n.y=-u,n.controls.a.clear(),n.controls.b.clear(),n=e.getAt(9),n.copy(e.getAt(8))}(this.width,this.height,this.radius,this.vertices),super.update(),this}get width(){return this.#o.get()}set width(t){this.#o.set(t)}get height(){return this.#r.get()}set height(t){this.#r.set(t)}get radius(){return this.#s.get()}set radius(t){this.#s.set(t)}}const y=Math.cos,g=Math.sin;class f extends s{#t=[];#n=r(.5);#a=r(1);#u=r(8);#i=r(0);constructor(t,s={}){super(t,[],!0,!1,!0,function(t,s){const i={id:t.id,attitude:t.attitude,opacity:t.opacity,position:t.position,visibility:t.visibility,fillColor:a(t.fillColor,s.defaults.polygon.fillColor),fillOpacity:u(t.fillOpacity,s.defaults.polygon.fillOpacity),strokeColor:a(t.strokeColor,s.defaults.polygon.strokeColor),strokeOpacity:u(t.strokeOpacity,s.defaults.polygon.strokeOpacity),strokeWidth:l(t.strokeWidth,s)};return i}(s,t)),"number"==typeof s.innerRadius&&(this.innerRadius=s.innerRadius),"number"==typeof s.outerRadius&&(this.outerRadius=s.outerRadius),"number"==typeof s.points&&(this.points=s.points),"number"==typeof s.twist&&(this.twist=s.twist),this.#t.push(n((()=>{this.update()})))}dispose(){i(this.#t),super.dispose()}update(){return function(t,s,i,r,n){const a=2*t,u=a+1;n.length>u&&n.splice(u,n.length-u);for(;n.length<u;)n.push(new e(o.vector(0,0)));for(let t=0;t<u;t++){const e=2*Math.PI*t/a+r,o=t%2==0?i:s,u=o*y(e),l=o*g(e),h=n.getAt(t);h.origin.set(u,l),h.command=0===t?"M":"L"}}(this.points,this.innerRadius,this.outerRadius,this.twist,this.vertices),super.update(),this}get innerRadius(){return this.#n.get()}set innerRadius(t){this.#n.set(t)}get outerRadius(){return this.#a.get()}set outerRadius(t){this.#a.set(t)}get points(){return this.#u.get()}set points(t){this.#u.set(t)}get twist(){return this.#i.get()}set twist(t){this.#i.set(t)}}export{c as RegularPolygon,p as RoundedRectangle,f as Star}; //# sourceMappingURL=index.min.js.map