phaser-jsx
Version:
Use JSX in Phaser.
3 lines (2 loc) • 12.4 kB
JavaScript
!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,i=t.GameObjects.BitmapText,l=t.GameObjects.Blitter,r=t.GameObjects.Bob,c=t.GameObjects.Container,a=t.GameObjects.Curve,s=t.GameObjects.DOMElement,u=t.GameObjects.DisplayList,p=t.GameObjects.DynamicBitmapText,d=t.GameObjects.Ellipse,m=t.GameObjects.Extern,f=t.GameObjects.GameObject,b=t.GameObjects.GameObjectCreator,O=t.GameObjects.GameObjectFactory,y=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,ie=t.GameObjects.UpdateList,le=t.GameObjects.Video,re=t.GameObjects.Zone;var ce=Object.freeze({__proto__:null,Arc:o,BitmapText:i,Blitter:l,Bob:r,CaptureFrame:z,Container:c,Curve:a,CustomContext:K,DOMElement:s,DisplayList:u,DynamicBitmapText:p,Ellipse:d,Extern:m,GameObject:f,GameObjectCreator:b,GameObjectFactory:O,Gradient:A,Graphics:y,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:ie,Video:le,Zone:re});function ae(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),{});function ue(e){return Object.prototype.hasOwnProperty.call(se,e)}const pe=["input"];function de(e,t,n){for(const o in t){if(pe.includes(o))continue;const i=t[o];if(i&&"data"===o)e.setData(i);else{if(ue(o)&&"function"==typeof i){e.setInteractive(t.input);const l=o.slice(2).toLowerCase();if(["pointerdown","pointerdownoutside","pointermove","pointerout","pointerover","pointerup","pointerupoutside","pointerwheel"].includes(l)){const t=i,o=(n,...o)=>{t(n,e,...o)};e.on(l,o,n)}else e.on(l,i,n);continue}if("style"===o&&i&&"object"==typeof i)me(e,i);else{if(("fillColor"===o||"fillAlpha"===o)&&"function"==typeof e.setFillStyle){const n=e,l="fillColor"===o?i:t.fillColor,r="fillAlpha"===o?i:t.fillAlpha;n.setFillStyle(l,r);continue}o in e&&(e[o]=i)}}}"number"!=typeof t.originX&&"number"!=typeof t.originY||"function"!=typeof e.setOrigin||e.setOrigin(t.originX,t.originY)}function me(e,t){var n,o;const i=e;null===(n=i.setStyle)||void 0===n||n.call(i,t);const l=t.padding;void 0!==l&&(null===(o=i.setPadding)||void 0===o||o.call(i,l))}function fe(e,t){"function"==typeof t?t(e):t&&"object"==typeof t&&(t.current=e)}function be(e,o,i,l){var r,c,a;if(null==e)return Oe(o);if(Array.isArray(e))return ye(e,null!==(r=null==o?void 0:o.children)&&void 0!==r?r:null,i,l);if(e.type===n){const t=e.props.children;return ye(t?ve(t):[],null!==(c=null==o?void 0:o.children)&&void 0!==c?c:null,i,l)}if(!function(e){if(null==e)return!1;const t=typeof e;if("boolean"===t||"number"===t||"string"===t)return!1;if("object"!==t)return console.warn(`Invalid JSX element. Expected an object but got: ${String(e)}`),!1;const n=e.type;return"function"==typeof n||(console.warn(`Invalid JSX type. Expected a class or function but got: ${String(n)}`),!1)}(e))return Oe(o);if("function"==typeof e.type&&(a=e.type,!Ge.some(e=>e===a))){return be((0,e.type)(e.props),o,i,l)}return function(e,n,o,i){var l,r,c;const a=e.props,{children:s,ref:u}=a,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 i=0;for(o=Object.getOwnPropertySymbols(e);i<o.length;i++)t.indexOf(o[i])<0&&Object.prototype.propertyIsEnumerable.call(e,o[i])&&(n[o[i]]=e[o[i]])}return n}(a,["children","ref"]);let d;if(n)d=n.gameObject,d&&(!function(e,t,n,o){for(const n in t)if(ue(n)&&"function"==typeof t[n]){const t=n.slice(2).toLowerCase();e.off(t)}de(e,n,o)}(d,n.props,p,o),fe(d,u));else{const n=function(e,n){const{props:o,color:i,frame:l,points:r,shader:c,style:a,texture:s}=e.props;switch(!0){case e.type===t.GameObjects.BitmapText:case e.type===t.GameObjects.DynamicBitmapText:{const t=[n,null==o?void 0:o.x,null==o?void 0:o.y,null==o?void 0:o.font];return new e.type(...t)}case e.type===t.GameObjects.Bob:{const i=new t.GameObjects.Blitter(n);n.add.existing(i);const r=[i,null==o?void 0:o.x,null==o?void 0:o.y,l,null==o?void 0:o.visible];return new e.type(...r)}case e.type===t.GameObjects.Container:case e.type===t.GameObjects.Layer:{const t=[n];return new e.type(...t)}case e.type===t.GameObjects.GameObject:{const t=[n,null==o?void 0:o.type];return new e.type(...t)}case e.type===t.GameObjects.Image:case e.type===t.GameObjects.Sprite:case e.type===t.GameObjects.NineSlice:{const t=[n,null==o?void 0:o.x,null==o?void 0:o.y,s,l];return new e.type(...t)}case e.type===t.GameObjects.Light:{const t=[null==o?void 0:o.x,null==o?void 0:o.y,null==o?void 0:o.radius,null==i?void 0:i.r,null==i?void 0:i.g,null==i?void 0:i.b,null==o?void 0:o.intensity];return new e.type(...t)}case e.type===t.GameObjects.PathFollower:{const t=[n,null==o?void 0:o.path,null==o?void 0:o.x,null==o?void 0:o.y,s,l];return new e.type(...t)}case e.type===t.GameObjects.Mesh2D:{const t=[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];return new e.type(...t)}case e.type===t.GameObjects.PointLight:{const l=[n,null==o?void 0:o.x,null==o?void 0:o.y,i?t.Display.Color.GetColor(i.r,i.g,i.b):void 0,null==o?void 0:o.radius,null==o?void 0:o.intensity];return new e.type(...l)}case e.type===t.GameObjects.Rectangle:{const t=[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];return new e.type(...t)}case e.type===t.GameObjects.Zone:{const t=[n,null==o?void 0:o.x,null==o?void 0:o.y];return new e.type(...t)}case e.type===t.GameObjects.Rope:{const t=[n,null==o?void 0:o.x,null==o?void 0:o.y,s,l,r];return new e.type(...t)}case e.type===t.GameObjects.Shader:{const t=[n,c];return new e.type(...t)}case e.type===t.GameObjects.Text:{const t=[n,null==o?void 0:o.x,null==o?void 0:o.y,null==o?void 0:o.text,a];return new e.type(...t)}case e.type===t.GameObjects.TileSprite:{const t=[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,l];return new e.type(...t)}case e.type===t.GameObjects.Video:{const t=[n,null==o?void 0:o.x,null==o?void 0:o.y,null==o?void 0:o.cacheKey];return new e.type(...t)}default:return new e.type(n)}}(e,o);"function"==typeof(null==i?void 0:i.add)?i.add(n):o.add.existing(n),de(n,p,o),fe(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?ve(s):[],t=null!==(l=null==n?void 0:n.children)&&void 0!==l?l:null,i=null!==(r=null==t?void 0:t.length)&&void 0!==r?r:0;for(let n=0;n<e.length;n++){const i=null!==(c=null==t?void 0:t[n])&&void 0!==c?c:null,l=be(e[n],i,o,d);m.children.push(l),i&&!l&&je(i)}for(let n=e.length;n<i;n++){const e=null==t?void 0:t[n];e&&je(e)}}return m}(e,o,i,l)}function Oe(e){return e&&je(e),null}function ye(e,t,n,o){var i,l;const r={gameObject:null,props:{},children:[]},c=null!==(i=null==t?void 0:t.length)&&void 0!==i?i:0;for(let i=0;i<e.length;i++){const c=null!==(l=null==t?void 0:t[i])&&void 0!==l?l:null,a=be(e[i],c,n,o);r.children.push(a),c&&!a&&je(c)}for(let n=e.length;n<c;n++){const e=null==t?void 0:t[n];e&&je(e)}return r}function je(e){var t;(null===(t=e.gameObject)||void 0===t?void 0:t.active)&&e.gameObject.destroy();for(const t of e.children)t&&je(t)}const Ge=Object.keys(ce).map(e=>ce[e]);function ve(e){return Array.isArray(e)?e:[e]}let ge,he=null;function xe(){return null!=he||(he=De()),he}function Se(e){he=e}function De(e=null,t=null,n=null,o=null){const i=new Map,l=new Map,r=[];let c=0,a=0,s=null,u=!1,p=!1;function d(){p=!1}function m(){if(u)p=!0;else{u=!0,d();try{for(const{key:e,callback:t,deps:n}of r){const o=l.get(e);if(!o||void 0===n||!Pe(o.deps,n)){"function"==typeof(null==o?void 0:o.cleanup)&&o.cleanup();const i=t();l.set(e,{deps:n,cleanup:i})}}r.length=0,a=0}finally{u=!1,p&&r.length>0&&(d(),setTimeout(m))}}}const f={state:i,effects:l,pendingEffects:r,scene:t,componentFn:n,componentProps:o,gameObjectTree:s,getNextStateIndex:()=>c++,resetStateIndex:()=>{c=0},getNextEffectIndex:()=>a++,resetEffectIndex:()=>{a=0},flushEffects:m,rerender:()=>{if(Se(f),c=0,a=0,n&&o&&t){const e=n(o);s=be(e,s,t)}else e&&t&&(s=be(e,s,t));setTimeout(m)}};return f}function Pe(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=i,e.Blitter=l,e.Bob=r,e.CaptureFrame=z,e.Container=c,e.Curve=a,e.CustomContext=K,e.DOMElement=s,e.DisplayList=u,e.DynamicBitmapText=p,e.Ellipse=d,e.Extern=m,e.Fragment=n,e.GameObject=f,e.GameObjectCreator=b,e.GameObjectFactory=O,e.Gradient=A,e.Graphics=y,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=ie,e.Video=le,e.Zone=re,e.createElement=ae,e.createRef=function(){return{current:null}},e.jsx=ae,e.render=function(e,t){!function(e){ge=e}(t);const n=e.type;let o=null,i=null;if("function"==typeof n){const{prototype:t}=n;(null==t?void 0:t.constructor)!==n&&(o=n,i=e.props)}const l=De(e,t,o,i);Se(l),l.rerender()},e.useEffect=function(e,t){const n=xe(),o=n.getNextEffectIndex();n.pendingEffects.push({key:o,callback:e,deps:t})},e.useRef=function(e=null){return{current:e}},e.useScene=function(){return ge},e.useState=function(e){const t=xe(),n=t.getNextStateIndex();t.state.has(n)||t.state.set(n,e);const o=t.state.get(n);return[o,function(e){const i="function"==typeof e?e(o):e;t.state.set(n,i),t.rerender()}]}});
//# sourceMappingURL=phaser-jsx.min.js.map