UNPKG

artistic-engine

Version:

General purpose html5 canvas rendering game engine

1 lines 8.82 kB
var t={539:(t,e,i)=>{i.d(e,{Z:()=>n});var s=i(391);class r{constructor(){this.children=[],this.parent=null}get Root(){let t=this;for(;null!=t.Parent;)t=t.Parent;return t}get Parent(){return this.parent}get Children(){return this.children.slice()}attachChildren(t,e=1/0){let i=-1;if(Array.isArray(t)){const s=Math.max(0,Math.min(e,this.children.length));for(let e=0;e<t.length;e++)i=this.attachChildren(t[e],s+e)}else{for(let e=this;null!=e;e=e.parent)if(e===t)throw new Error("Loop of parent-child relationships detected.");null!=t.parent&&(t.parent.detachChildren(t),t.onDetach(t.parent)),this.children.push(t),t.parent=this,i=this.setChildIndex(t,e),t.onAttach(this)}return i}detachChildren(t){if(Array.isArray(t))for(const e of t)this.detachChildren(e);else{const e=this.children.indexOf(t);e>-1&&(this.children.splice(e,1),t.parent=null)}}getChildIndex(t){return this.children.indexOf(t)}setChildIndex(t,e){const i=this.getChildIndex(t);if(-1===i)throw new Error("I AM NOT YOUR FATHER");this.children.splice(i,1);const s=Math.max(0,Math.min(e,this.children.length));return this.children.splice(s,0,t),s}setParent(t=null){null==t?this.parent?.detachChildren(this):t.attachChildren(this)}onAttach(t){}onDetach(t){}}class n extends r{constructor(t){super(),this.dimension=new s.Z,this.position=new s.Z,t&&(this.dimension.X=t.W??0,this.dimension.Y=t.H??0,this.position.X=t.X??0,this.position.Y=t.Y??0)}get Position(){return this.position}get X(){return this.position.X}get Y(){return this.position.Y}get Dimension(){return this.dimension}get W(){return this.dimension.X}get H(){return this.dimension.Y}get Width(){return this.dimension.X}get Height(){return this.dimension.Y}get AbsoluteX(){return(this.parent?.AbsoluteX??0)+this.position.X}get AbsoluteY(){return(this.parent?.AbsoluteY??0)+this.position.Y}set Position(t){this.position=t}set X(t){this.position.X=t}set Y(t){this.position.Y=t}set Dimension(t){this.dimension=t}set W(t){this.dimension.X=t}set H(t){this.dimension.Y=t}set Width(t){this.dimension.X=t}set Height(t){this.dimension.Y=t}setPosition(t,e){this.X=t,this.Y=e}setSize(t,e){this.W=t,this.H=e}}},789:(t,e,i)=>{i.d(e,{Z:()=>r});var s=i(283);class r extends s.Z{onDrawShape(t){t.beginPath(),t.moveTo(0,0),t.lineTo(0,this.Height),t.lineTo(this.Width,this.Height),t.lineTo(this.Width,0),t.closePath()}onFillShape(t){t.fillStyle=this.fillStyle,t.fill()}}},283:(t,e,i)=>{i.d(e,{Z:()=>r});var s=i(727);class r extends s.Z{constructor(){super(...arguments),this.fillStyle="#000"}get FillStyle(){return this.fillStyle}set FillStyle(t){this.fillStyle=t}onDraw(t,e){this.onDrawShape(t,e),this.onFillShape(t,e)}}},727:(t,e,i)=>{i.d(e,{Z:()=>n});var s=i(539),r=i(333);class n extends s.Z{constructor(){super(...arguments),this.contextMutator=!1,this.opacity=1,this.draw=(t,e)=>{t.translate(this.X,this.Y);const i=this.needsTransform,s=this.hasRegion,r=this.hasOpacity;if(this.contextMutator||(this.contextMutator=i||s||r),this.contextMutator){if(t.save(),i&&t.transform(this.transform.m11,this.transform.m21,this.transform.m12,this.transform.m22,this.transform.ox,this.transform.oy),s){this.beforeClip(t,e);const i=this.region();t.clip(i)}r&&(t.globalAlpha=this.opacity)}this.onDraw(t,e),this.contextMutator&&(t.restore(),this.afterRestore(t,e));for(const i of this.Children)i instanceof n&&i.draw(t,e);this.afterChildren(t,e),t.translate(-this.X,-this.Y)}}get Transform(){return this.transform||(this.transform=new r.Z),this.transform}get Region(){return this.region}get Opacity(){return this.opacity}get needsTransform(){return null!=this.transform&&!this.transform.isIdentity}get hasRegion(){return null!=this.region}get hasOpacity(){return 1!==this.opacity}set Transform(t){this.transform=t}set Region(t){this.region=t}set Opacity(t){this.opacity=Math.max(0,Math.min(t,1))}beforeClip(t,e){}afterRestore(t,e){}afterChildren(t,e){}}},866:(t,e,i)=>{i.d(e,{Z:()=>r});var s=i(727);class r extends s.Z{constructor(){super(...arguments),this.text="",this.property={direction:"inherit",fill:"#000",font:"",fontKerning:"auto",textAlign:"start",textBaseLine:"top",lineSpacing:0}}get Text(){return"string"==typeof this.text?this.text:this.text()}get Property(){return this.property}set Text(t){this.text=t}set Property(t){this.property=t}onDraw(t,e){t.direction=this.property.direction,t.fillStyle=this.property.fill,t.font=this.property.font,t.fontKerning=this.property.fontKerning,t.textAlign=this.property.textAlign,t.textBaseline=this.property.textBaseLine;const i=this.Text.split("\n");for(let e=0;e<i.length;e++)t.fillText(i[e],0,e*this.property.lineSpacing)}}},333:(t,e,i)=>{i.d(e,{Z:()=>r});var s=i(391);class r{constructor(t=1,e=0,i=0,s=1,r=0,n=0){this.values=[t,e,i,s,r,n]}get m11(){return this.values[0]}get m21(){return this.values[1]}get m12(){return this.values[2]}get m22(){return this.values[3]}get ox(){return this.values[4]}get oy(){return this.values[5]}get Determinant(){return this.m11*this.m22-this.m12*this.m21}get isInvertible(){return 0!==this.Determinant}get isIdentity(){return 1===this.m11&&1===this.m22&&0===this.m12&&0===this.m21&&0===this.ox&&0===this.oy}set m11(t){this.values[0]=t}set m21(t){this.values[1]=t}set m12(t){this.values[2]=t}set m22(t){this.values[3]=t}set ox(t){this.values[4]=t}set oy(t){this.values[5]=t}static fromDOM(t){return new this(t.a,t.b,t.c,t.d,t.e,t.f)}translate(t,e){return this.linear(1,0,0,1,t,e)}scale(t,e){return void 0===e?this.scale(t,t):this.linear(t,0,0,e,0,0)}linear(t,e,i,s,r,n){return this.values=[t*this.m11+i*this.m21,e*this.m11+s*this.m21,t*this.m12+i*this.m22,e*this.m12+s*this.m22,this.m11*r+this.m12*n+this.ox,this.m21*r+this.m22*n+this.oy],this}rotate(t){const e=Math.sin(t),i=Math.cos(t);return this.linear(i,e,-e,i,0,0)}apply(t,e){let i;if(t instanceof s.Z)i=t,e=t.Y,t=t.X,i.X=this.m11*t+this.m12*e+this.ox,i.Y=this.m21*t+this.m22*e+this.oy;else{if(void 0===e)throw new Error("Transform#apply method requires two number parameters or one Vector2D.");i=new s.Z(this.m11*t+this.m12*e+this.ox,this.m21*t+this.m22*e+this.oy)}return i}multiply(t){return this.linear(...t.values)}invert(){const t=this.Determinant;if(0===t)throw new Error("This transform is not invertible");const e=this.m22/t,i=-1*this.m12/t,s=(this.m12*this.oy-this.m22*this.ox)/t,r=-1*this.m21/t,n=this.m11/t,h=-1*(this.m11*this.oy-this.m21*this.ox)/t;return this.m11=e,this.m12=i,this.ox=s,this.m21=r,this.m22=n,this.oy=h,this}skew(t=0,e=0){return this.linear(1,t,e,1,0,0),this}reset(){return this.m11=1,this.m22=1,this.m12=0,this.m21=0,this.ox=0,this.oy=0,this}copy(){return new r(...this.values)}copyTo(t){t.m11=this.m11,t.m21=this.m21,t.m12=this.m12,t.m22=this.m22,t.ox=this.ox,t.oy=this.oy}toDOM(){return new DOMMatrix([this.m11,this.m21,this.m12,this.m22,this.ox,this.oy])}}},70:(t,e,i)=>{i.d(e,{Z:()=>s});class s{constructor(...t){this.values=[...t],this.size=t.length}get Size(){return this.size}copy(t,e=!1){if(this.size>t.size&&!e)throw new Error(`Copying vector of size ${this.size} to ${t.size} will cause data loss.\nInclude force option if intended.`);return t.overwrite(this.values),t}isequal(t,e){if(this.size!==t.size)return!1;const i=this.values.slice(),s=t.values.slice();return i.every(((t,i)=>null==e?t==s[i]:t.toFixed(e)==s[i].toFixed(e)))}shift(t=1){t%=this.size;const e=this.values.slice(0,-t);return e.unshift(...this.values.slice(-t)),this.values=e,this}overwrite(t){let e=0;this.values=this.values.map((function(){return t[e++]||0}))}}},391:(t,e,i)=>{i.d(e,{Z:()=>r});var s=i(70);class r extends s.Z{constructor(t=0,e=0){super(t,e)}get X(){return this.values[0]}get Y(){return this.values[1]}set X(t){this.values[0]=t}set Y(t){this.values[1]=t}}}},e={};function i(s){var r=e[s];if(void 0!==r)return r.exports;var n=e[s]={exports:{}};return t[s](n,n.exports,i),n.exports}i.d=(t,e)=>{for(var s in e)i.o(e,s)&&!i.o(t,s)&&Object.defineProperty(t,s,{enumerable:!0,get:e[s]})},i.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e);var s={};(()=>{i.d(s,{qu:()=>l,Pj:()=>n,Ae:()=>r.Z,xs:()=>a,bn:()=>e.Z,jy:()=>t.Z,VW:()=>o.Z,WL:()=>h});var t=i(727),e=i(283),r=i(789);class n extends e.Z{onDrawShape(t){t.beginPath();const e=this.Width/2,i=this.Height/2;t.ellipse(e,i,e,i,0,0,n.PI2),t.closePath()}onFillShape(t){t.fillStyle=this.fillStyle,t.fill()}}n.PI2=2*Math.PI;class h extends t.Z{constructor(t){null!=t?.texture?(void 0===t.W&&(t.W=t.texture.width),void 0===t.H&&(t.H=t.texture.height),super(t),this.texture=t.texture):super()}onDraw(t,e){this.texture&&t.drawImage(this.texture,0,0,this.Width,this.Height)}}var o=i(866);class a extends t.Z{onDraw(t,e){}onAttachEngine(t,e){}onDetachEngine(t,e){}}class l extends a{onDraw(t,e){}onAttachEngine(t,e){}onDetachEngine(t,e){}}})();var r=s.qu,n=s.Pj,h=s.Ae,o=s.xs,a=s.bn,l=s.jy,u=s.VW,c=s.WL;export{r as BlankScene,n as Ellipse,h as Rectangle,o as Scene,a as Shape,l as Sprite,u as TextSprite,c as TextureSprite};