UNPKG

phaser-jsx

Version:
3 lines (2 loc) 12 kB
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("phaser")):"function"==typeof define&&define.amd?define(["exports","phaser"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).PhaserJSX={},e.Phaser)}(this,function(e,t){"use strict";function n(e){return e.children}const o=t.GameObjects.Arc,l=t.GameObjects.BitmapText,i=t.GameObjects.Blitter,r=t.GameObjects.Bob,a=t.GameObjects.Container,c=t.GameObjects.Curve,s=t.GameObjects.DOMElement,u=t.GameObjects.DisplayList,p=t.GameObjects.DynamicBitmapText,d=t.GameObjects.Ellipse,m=t.GameObjects.Extern,b=t.GameObjects.GameObject,f=t.GameObjects.GameObjectCreator,y=t.GameObjects.GameObjectFactory,O=t.GameObjects.Graphics,j=t.GameObjects.Grid,G=t.GameObjects.Group,v=t.GameObjects.Image,g=t.GameObjects.IsoBox,h=t.GameObjects.IsoTriangle,x=t.GameObjects.Layer,S=t.GameObjects.Light,D=t.GameObjects.LightsManager,P=t.GameObjects.LightsPlugin,w=t.GameObjects.Line,C=t.GameObjects.Mesh2D,L=t.GameObjects.NineSlice,T=t.GameObjects.Particles.ParticleEmitter,E=t.GameObjects.PathFollower,N=t.GameObjects.PointLight,B=t.GameObjects.Polygon,I=t.GameObjects.Rectangle,M=t.GameObjects.RenderTexture,R=t.GameObjects.Rope,F=t.GameObjects.Shader,A=t.GameObjects.Gradient,U=t.GameObjects.Noise,k=t.GameObjects.NoiseCell2D,V=t.GameObjects.NoiseCell3D,X=t.GameObjects.NoiseCell4D,Z=t.GameObjects.NoiseSimplex2D,_=t.GameObjects.NoiseSimplex3D,J=t.GameObjects.Shape,W=t.GameObjects.SpriteGPULayer,Y=t.GameObjects.Stamp,$=t.GameObjects.Stencil,q=t.GameObjects.StencilReference,z=t.GameObjects.CaptureFrame,K=t.GameObjects.CustomContext,H=t.GameObjects.Sprite,Q=t.GameObjects.Star,ee=t.GameObjects.Text,te=t.GameObjects.TextStyle,ne=t.GameObjects.TileSprite,oe=t.GameObjects.Triangle,le=t.GameObjects.UpdateList,ie=t.GameObjects.Video,re=t.GameObjects.Zone;var ae=Object.freeze({__proto__:null,Arc:o,BitmapText:l,Blitter:i,Bob:r,CaptureFrame:z,Container:a,Curve:c,CustomContext:K,DOMElement:s,DisplayList:u,DynamicBitmapText:p,Ellipse:d,Extern:m,GameObject:b,GameObjectCreator:f,GameObjectFactory:y,Gradient:A,Graphics:O,Grid:j,Group:G,Image:v,IsoBox:g,IsoTriangle:h,Layer:x,Light:S,LightsManager:D,LightsPlugin:P,Line:w,Mesh2D:C,NineSlice:L,Noise:U,NoiseCell2D:k,NoiseCell3D:V,NoiseCell4D:X,NoiseSimplex2D:Z,NoiseSimplex3D:_,ParticleEmitter:T,PathFollower:E,PointLight:N,Polygon:B,Rectangle:I,RenderTexture:M,Rope:R,Shader:F,Shape:J,Sprite:H,SpriteGPULayer:W,Stamp:Y,Star:Q,Stencil:$,StencilReference:q,Text:ee,TextStyle:te,TileSprite:ne,Triangle:oe,UpdateList:le,Video:ie,Zone:re});function ce(e,t,...n){return null!=t||(t={}),n.length&&(t.children=n),t.children&&!Array.isArray(t.children)&&(t.children=[t.children]),{type:e,props:t,key:null}}"function"==typeof SuppressedError&&SuppressedError;const se=["onBoot","onDestroy","onDragEnd","onDragEnter","onDrag","onDragLeave","onDragOver","onDragStart","onDrop","onGameObjectDown","onGameObjectDragEnd","onGameObjectDragEnter","onGameObjectDrag","onGameObjectDragLeave","onGameObjectDragOver","onGameObjectDragStart","onGameObjectDrop","onGameObjectMove","onGameObjectOut","onGameObjectOver","onGameObjectPointerDown","onGameObjectPointerMove","onGameObjectPointerOut","onGameObjectPointerOver","onGameObjectPointerUp","onGameObjectPointerWheel","onGameObjectUp","onGameObjectWheel","onGameOut","onGameOver","onManagerBoot","onManagerProcess","onManagerUpdate","onPointerLockChange","onPointerDown","onPointerDownOutside","onPointerMove","onPointerOut","onPointerOver","onPointerUp","onPointerUpOutside","onPointerWheel","onPreUpdate","onShutdown","onStart","onUpdate"].reduce((e,t)=>(e[t]=1,e),{}),ue=["input"];function pe(e,t,n){for(const o in t){if(ue.includes(o))continue;const l=t[o];if(l&&"data"===o)e.setData(l);else{if(se[o]&&"function"==typeof l){e.setInteractive(t.input);const i=o.slice(2).toLowerCase();if(["pointerdown","pointerdownoutside","pointermove","pointerout","pointerover","pointerup","pointerupoutside","pointerwheel"].includes(i)){const t=(t,...n)=>{l(t,e,...n)};e.on(i,t,n)}else e.on(i,l,n);continue}if("style"===o&&l&&"object"==typeof l)de(e,l);else{if(("fillColor"===o||"fillAlpha"===o)&&"function"==typeof e.setFillStyle){const n=e,i="fillColor"===o?l:t.fillColor,r="fillAlpha"===o?l:t.fillAlpha;n.setFillStyle(i,r);continue}o in e&&(e[o]=l)}}}"number"!=typeof t.originX&&"number"!=typeof t.originY||"function"!=typeof e.setOrigin||e.setOrigin(t.originX,t.originY)}function de(e,t){var n,o;const l=e;null===(n=l.setStyle)||void 0===n||n.call(l,t);const i=t.padding;void 0!==i&&(null===(o=l.setPadding)||void 0===o||o.call(l,i))}function me(e,t){"function"==typeof t?t(e):t&&"object"==typeof t&&(t.current=e)}function be(e,o,l,i){var r,a,c;switch(!0){case void 0===e:case null===e:return o&&ye(o),null;case Array.isArray(e):return fe(e,null!==(r=null==o?void 0:o.children)&&void 0!==r?r:null,l,i);case(null==e?void 0:e.type)===n:{const t=null===(a=e.props)||void 0===a?void 0:a.children;return fe(t?Ge(t):[],null!==(c=null==o?void 0:o.children)&&void 0!==c?c:null,l,i)}case!function(e){const t=typeof e;switch(!0){case null===e:case void 0===e:case"boolean"===t:case"number"===t:case"string"===t:return!1;case"object"!==t:return console.warn(`Invalid JSX element. Expected an object but got: ${String(e)}`),!1;case"function"!=typeof e.type:return console.warn(`Invalid JSX type. Expected a class or function but got: ${"symbol"==typeof e.type?"Symbol":e.type}`),!1;default:return!0}}(e):return o&&ye(o),null;case"function"==typeof(null==e?void 0:e.type)&&!je(e.type):return be(e.type(e.props),o,l,i);case je(null==e?void 0:e.type):default:return function(e,n,o,l){var i,r,a;const c=e.props,{children:s,ref:u}=c,p=function(e,t){var n={};for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&t.indexOf(o)<0&&(n[o]=e[o]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var l=0;for(o=Object.getOwnPropertySymbols(e);l<o.length;l++)t.indexOf(o[l])<0&&Object.prototype.propertyIsEnumerable.call(e,o[l])&&(n[o[l]]=e[o[l]])}return n}(c,["children","ref"]);let d;if(n)d=n.gameObject,function(e,t,n,o){for(const n in t)if(se[n]&&"function"==typeof t[n]){const t=n.slice(2).toLowerCase();e.off(t)}pe(e,n,o)}(d,n.props,p,o),me(d,u);else{const n=function(e,n){const{props:o,color:l,frame:i,points:r,shader:a,style:c,texture:s}=e.props;switch(!0){case e.type===t.GameObjects.BitmapText:case e.type===t.GameObjects.DynamicBitmapText:return new e.type(n,null==o?void 0:o.x,null==o?void 0:o.y,null==o?void 0:o.font);case e.type===t.GameObjects.Bob:return new e.type(n,null==o?void 0:o.x,null==o?void 0:o.y,i,null==o?void 0:o.visible);case e.type===t.GameObjects.Container:case e.type===t.GameObjects.Layer:return new e.type(n);case e.type===t.GameObjects.GameObject:return new e.type(n,null==o?void 0:o.type);case e.type===t.GameObjects.Image:case e.type===t.GameObjects.Sprite:case e.type===t.GameObjects.NineSlice:return new e.type(n,null==o?void 0:o.x,null==o?void 0:o.y,s,i);case e.type===t.GameObjects.Light:return new e.type(n,null==o?void 0:o.x,null==o?void 0:o.y,null==o?void 0:o.radius,null==l?void 0:l.r,null==l?void 0:l.g,null==l?void 0:l.b,null==o?void 0:o.intensity);case e.type===t.GameObjects.PathFollower:return new e.type(n,null==o?void 0:o.path,null==o?void 0:o.x,null==o?void 0:o.y,s,i);case e.type===t.GameObjects.Mesh2D:return new e.type(n,null==o?void 0:o.x,null==o?void 0:o.y,s,null==o?void 0:o.vertices,null==o?void 0:o.indices,null==o?void 0:o.flipV);case e.type===t.GameObjects.PointLight:return new e.type(n,null==o?void 0:o.x,null==o?void 0:o.y,l);case e.type===t.GameObjects.Rectangle:return new e.type(n,null==o?void 0:o.x,null==o?void 0:o.y,null==o?void 0:o.width,null==o?void 0:o.height,null==o?void 0:o.fillColor,null==o?void 0:o.fillAlpha);case e.type===t.GameObjects.Zone:return new e.type(n,null==o?void 0:o.x,null==o?void 0:o.y);case e.type===t.GameObjects.Rope:return new e.type(n,null==o?void 0:o.x,null==o?void 0:o.y,s,i,r);case e.type===t.GameObjects.Shader:return new e.type(n,a);case e.type===t.GameObjects.Text:return new e.type(n,null==o?void 0:o.x,null==o?void 0:o.y,null==o?void 0:o.text,c);case e.type===t.GameObjects.TileSprite:return new e.type(n,null==o?void 0:o.x,null==o?void 0:o.y,null==o?void 0:o.width,null==o?void 0:o.height,s,i);case e.type===t.GameObjects.Video:return new e.type(n,null==o?void 0:o.x,null==o?void 0:o.y,null==o?void 0:o.cacheKey);default:return new e.type(n)}}(e,o);"function"==typeof(null==l?void 0:l.add)?l.add(n):o.add.existing(n),pe(n,p,o),me(n,u),d=n}const m={gameObject:d,props:p,children:[]};if(e.type===t.GameObjects.Container||e.type===t.GameObjects.Layer){const e=s?Ge(s):[],t=null!==(i=null==n?void 0:n.children)&&void 0!==i?i:null,l=null!==(r=null==t?void 0:t.length)&&void 0!==r?r:0;for(let n=0;n<e.length;n++){const l=null!==(a=null==t?void 0:t[n])&&void 0!==a?a:null,i=be(e[n],l,o,d);m.children.push(i),l&&!i&&ye(l)}for(let n=e.length;n<l;n++){const e=t[n];e&&ye(e)}}return m}(e,o,l,i)}}function fe(e,t,n,o){var l,i;const r={gameObject:null,props:{},children:[]},a=null!==(l=null==t?void 0:t.length)&&void 0!==l?l:0;for(let l=0;l<e.length;l++){const a=null!==(i=null==t?void 0:t[l])&&void 0!==i?i:null,c=be(e[l],a,n,o);r.children.push(c),a&&!c&&ye(a)}for(let n=e.length;n<a;n++){const e=t[n];e&&ye(e)}return r}function ye(e){var t;(null===(t=e.gameObject)||void 0===t?void 0:t.active)&&e.gameObject.destroy();for(const t of e.children)t&&ye(t)}const Oe=Object.keys(ae).map(e=>ae[e]);function je(e){return Oe.some(t=>t===e)}function Ge(e){return Array.isArray(e)?e:[e]}let ve,ge=null;function he(){return null!=ge||(ge=Se()),ge}function xe(e){ge=e}function Se(e=null,t=null,n=null,o=null){const l=new Map,i=new Map,r=[];let a=0,c=0,s=null,u=!1,p=!1;function d(){if(u)p=!0;else{u=!0,p=!1;try{for(const{key:e,callback:t,deps:n}of r){const o=i.get(e);if(!o||void 0===n||!De(o.deps,n)){"function"==typeof(null==o?void 0:o.cleanup)&&o.cleanup();const l=t();i.set(e,{deps:n,cleanup:l})}}r.length=0,c=0}finally{u=!1,p&&r.length>0&&setTimeout(d)}}}const m={state:l,effects:i,pendingEffects:r,scene:t,componentFn:n,componentProps:o,gameObjectTree:s,getNextStateIndex:()=>a++,resetStateIndex:()=>{a=0},getNextEffectIndex:()=>c++,resetEffectIndex:()=>{c=0},flushEffects:d,rerender:()=>{if(xe(m),a=0,c=0,n&&o&&t){const e=n(o);s=be(e,s,t)}else e&&t&&(s=be(e,s,t));setTimeout(d)}};return m}function De(e,t){if(void 0===e||void 0===t)return!1;if(e.length!==t.length)return!1;for(let n=0;n<t.length;n++)if(!Object.is(e[n],t[n]))return!1;return!0}e.Arc=o,e.BitmapText=l,e.Blitter=i,e.Bob=r,e.CaptureFrame=z,e.Container=a,e.Curve=c,e.CustomContext=K,e.DOMElement=s,e.DisplayList=u,e.DynamicBitmapText=p,e.Ellipse=d,e.Extern=m,e.Fragment=n,e.GameObject=b,e.GameObjectCreator=f,e.GameObjectFactory=y,e.Gradient=A,e.Graphics=O,e.Grid=j,e.Group=G,e.Image=v,e.IsoBox=g,e.IsoTriangle=h,e.Layer=x,e.Light=S,e.LightsManager=D,e.LightsPlugin=P,e.Line=w,e.Mesh2D=C,e.NineSlice=L,e.Noise=U,e.NoiseCell2D=k,e.NoiseCell3D=V,e.NoiseCell4D=X,e.NoiseSimplex2D=Z,e.NoiseSimplex3D=_,e.ParticleEmitter=T,e.PathFollower=E,e.PointLight=N,e.Polygon=B,e.Rectangle=I,e.RenderTexture=M,e.Rope=R,e.Shader=F,e.Shape=J,e.Sprite=H,e.SpriteGPULayer=W,e.Stamp=Y,e.Star=Q,e.Stencil=$,e.StencilReference=q,e.Text=ee,e.TextStyle=te,e.TileSprite=ne,e.Triangle=oe,e.UpdateList=le,e.Video=ie,e.Zone=re,e.createElement=ce,e.createRef=function(){return{current:null}},e.jsx=ce,e.render=function(e,t){var n;!function(e){ve=e}(t);let o=null,l=null;"function"==typeof(null==e?void 0:e.type)&&(null===(n=e.type.prototype)||void 0===n?void 0:n.constructor)!==e.type&&(o=e.type,l=e.props);const i=Se(e,t,o,l);xe(i),i.rerender()},e.useEffect=function(e,t){const n=he(),o=n.getNextEffectIndex();n.pendingEffects.push({key:o,callback:e,deps:t})},e.useRef=function(e=null){return{current:e}},e.useScene=function(){return ve},e.useState=function(e){const t=he(),n=t.getNextStateIndex();t.state.has(n)||t.state.set(n,e);const o=t.state.get(n);return[o,function(e){const l="function"==typeof e?e(o):e;t.state.set(n,l),t.rerender()}]}}); //# sourceMappingURL=phaser-jsx.min.js.map