phaser-jsx
Version:
Use JSX in Phaser.
3 lines (2 loc) • 11.5 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}var r=t.GameObjects.Arc,o=t.GameObjects.BitmapText,a=t.GameObjects.Blitter,i=t.GameObjects.Bob,l=t.GameObjects.Container,c=t.GameObjects.Curve,u=t.GameObjects.DOMElement,s=t.GameObjects.DisplayList,p=t.GameObjects.DynamicBitmapText,d=t.GameObjects.Ellipse,m=t.GameObjects.Extern,v=t.GameObjects.GameObject,f=t.GameObjects.GameObjectCreator,y=t.GameObjects.GameObjectFactory,b=t.GameObjects.Graphics,O=t.GameObjects.Grid,j=t.GameObjects.Group,G=t.GameObjects.Image,g=t.GameObjects.IsoBox,h=t.GameObjects.IsoTriangle,x=t.GameObjects.Layer,P=t.GameObjects.Light,S=t.GameObjects.LightsManager,w=t.GameObjects.LightsPlugin,T=t.GameObjects.Line,L=t.GameObjects.Mesh,D=t.GameObjects.NineSlice,E=t.GameObjects.Particles.ParticleEmitter,B=t.GameObjects.PathFollower,I=t.GameObjects.Plane,M=t.GameObjects.PointLight,C=t.GameObjects.Polygon,R=t.GameObjects.Rectangle,A=t.GameObjects.RenderTexture,U=t.GameObjects.Rope,F=t.GameObjects.Shader,N=t.GameObjects.Shape,k=t.GameObjects.Sprite,X=t.GameObjects.Star,V=t.GameObjects.Text,Z=t.GameObjects.TextStyle,_=t.GameObjects.TileSprite,J=t.GameObjects.Triangle,W=t.GameObjects.UpdateList,Y=t.GameObjects.Video,q=t.GameObjects.Zone,z=Object.freeze({__proto__:null,Arc:r,BitmapText:o,Blitter:a,Bob:i,Container:l,Curve:c,DOMElement:u,DisplayList:s,DynamicBitmapText:p,Ellipse:d,Extern:m,GameObject:v,GameObjectCreator:f,GameObjectFactory:y,Graphics:b,Grid:O,Group:j,Image:G,IsoBox:g,IsoTriangle:h,Layer:x,Light:P,LightsManager:S,LightsPlugin:w,Line:T,Mesh:L,NineSlice:D,ParticleEmitter:E,PathFollower:B,Plane:I,PointLight:M,Polygon:C,Rectangle:R,RenderTexture:A,Rope:U,Shader:F,Shape:N,Sprite:k,Star:X,Text:V,TextStyle:Z,TileSprite:_,Triangle:J,UpdateList:W,Video:Y,Zone:q});function K(e,t){for(var n=[],r=2;r<arguments.length;r++)n[r-2]=arguments[r];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;var H=["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(function(e,t){return e[t]=1,e},{}),Q=["input"];function $(e,t,n){var r=function(r){if(Q.includes(r))return"continue";var o=t[r];if(o&&"data"===r)return e.setData(o),"continue";if(H[r]&&"function"==typeof o){e.setInteractive(t.input);var a=r.slice(2).toLowerCase();if(["pointerdown","pointerdownoutside","pointermove","pointerout","pointerover","pointerup","pointerupoutside","pointerwheel"].includes(a)){e.on(a,function(t){for(var n=[],r=1;r<arguments.length;r++)n[r-1]=arguments[r];o.apply(void 0,function(e,t,n){if(n||2===arguments.length)for(var r,o=0,a=t.length;o<a;o++)!r&&o in t||(r||(r=Array.prototype.slice.call(t,0,o)),r[o]=t[o]);return e.concat(r||Array.prototype.slice.call(t))}([t,e],n,!1))},n)}else e.on(a,o,n);return"continue"}return"style"===r&&o&&"object"==typeof o?(function(e,t){var n,r,o=e;null===(n=o.setStyle)||void 0===n||n.call(o,t);var a=t.padding;void 0!==a&&(null===(r=o.setPadding)||void 0===r||r.call(o,a))}(e,o),"continue"):r in e?(e[r]=o,"continue"):void 0};for(var o in t)r(o);"number"!=typeof t.originX&&"number"!=typeof t.originY||"function"!=typeof e.setOrigin||e.setOrigin(t.originX,t.originY)}function ee(e,t){"function"==typeof t?t(e):t&&"object"==typeof t&&(t.current=e)}function te(e,r,o,a){var i,l,c;switch(!0){case void 0===e:case null===e:return r&&re(r),null;case Array.isArray(e):return ne(e,null!==(i=null==r?void 0:r.children)&&void 0!==i?i:null,o,a);case(null==e?void 0:e.type)===n:var u=null===(l=e.props)||void 0===l?void 0:l.children;return ne(u?ie(u):[],null!==(c=null==r?void 0:r.children)&&void 0!==c?c:null,o,a);case!function(e){var 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: ".concat(String(e))),!1;case"function"!=typeof e.type:return console.warn("Invalid JSX type. Expected a class or function but got: ".concat("symbol"==typeof e.type?"Symbol":e.type)),!1;default:return!0}}(e):return r&&re(r),null;case"function"==typeof(null==e?void 0:e.type)&&!ae(e.type):return te(e.type(e.props),r,o,a);case ae(null==e?void 0:e.type):default:return function(e,n,r,o){var a,i,l,c,u=e.props,s=u.children,p=u.ref,d=function(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(e);o<r.length;o++)t.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(e,r[o])&&(n[r[o]]=e[r[o]])}return n}(u,["children","ref"]);if(n)(function(e,t,n,r){for(var o in t)if(H[o]&&"function"==typeof t[o]){var a=o.slice(2).toLowerCase();e.off(a)}$(e,n,r)})(c=n.gameObject,n.props,d,r),ee(c,p);else{var m=function(e,n){var r=e.props,o=r.props,a=r.color,i=r.frame,l=r.points,c=r.shader,u=r.style,s=r.texture;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==a?void 0:a.r,null==a?void 0:a.g,null==a?void 0:a.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.Plane:return new e.type(n,null==o?void 0:o.x,null==o?void 0:o.y,s,i,null==o?void 0:o.width,null==o?void 0:o.height,null==o?void 0:o.isTiled);case e.type===t.GameObjects.PointLight:return new e.type(n,null==o?void 0:o.x,null==o?void 0:o.y,a);case e.type===t.GameObjects.Rectangle: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,l);case e.type===t.GameObjects.Shader:return new e.type(n,c);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,u);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,r);"function"==typeof(null==o?void 0:o.add)?o.add(m):r.add.existing(m),$(m,d,r),ee(m,p),c=m}var v={gameObject:c,props:d,children:[]};if(e.type===t.GameObjects.Container||e.type===t.GameObjects.Layer){for(var f=s?ie(s):[],y=null!==(a=null==n?void 0:n.children)&&void 0!==a?a:null,b=null!==(i=null==y?void 0:y.length)&&void 0!==i?i:0,O=0;O<f.length;O++){var j=null!==(l=null==y?void 0:y[O])&&void 0!==l?l:null,G=te(f[O],j,r,c);v.children.push(G),j&&!G&&re(j)}for(O=f.length;O<b;O++){(j=y[O])&&re(j)}}return v}(e,r,o,a)}}function ne(e,t,n,r){for(var o,a,i={gameObject:null,props:{},children:[]},l=null!==(o=null==t?void 0:t.length)&&void 0!==o?o:0,c=0;c<e.length;c++){var u=null!==(a=null==t?void 0:t[c])&&void 0!==a?a:null,s=te(e[c],u,n,r);i.children.push(s),u&&!s&&re(u)}for(c=e.length;c<l;c++){(u=t[c])&&re(u)}return i}function re(e){var t;(null===(t=e.gameObject)||void 0===t?void 0:t.active)&&e.gameObject.destroy();for(var n=0,r=e.children;n<r.length;n++){var o=r[n];o&&re(o)}}var oe=Object.keys(z).map(function(e){return z[e]});function ae(e){return oe.some(function(t){return t===e})}function ie(e){return Array.isArray(e)?e:[e]}var le,ce=null;function ue(){return null!=ce||(ce=se()),ce}function se(e,t,n,r){void 0===e&&(e=null),void 0===t&&(t=null),void 0===n&&(n=null),void 0===r&&(r=null);var o=new Map,a=new Map,i=[],l=0,c=0,u=null,s=!1,p=!1;function d(){if(s)p=!0;else{s=!0,p=!1;try{for(var e=0,t=i;e<t.length;e++){var n=t[e],r=n.key,o=n.callback,l=n.deps,u=a.get(r);if(!u||void 0===l||!pe(u.deps,l)){"function"==typeof(null==u?void 0:u.cleanup)&&u.cleanup();var m=o();a.set(r,{deps:l,cleanup:m})}}i.length=0,c=0}finally{s=!1,p&&i.length>0&&setTimeout(d)}}}return{state:o,effects:a,pendingEffects:i,scene:t,componentFn:n,componentProps:r,gameObjectTree:u,getNextStateIndex:function(){return l++},resetStateIndex:function(){l=0},getNextEffectIndex:function(){return c++},resetEffectIndex:function(){c=0},flushEffects:d,rerender:function(){if(l=0,c=0,n&&r&&t){var o=n(r);u=te(o,u,t)}else e&&t&&(u=te(e,u,t));setTimeout(d)}}}function pe(e,t){if(void 0===e||void 0===t)return!1;if(e.length!==t.length)return!1;for(var n=0;n<t.length;n++)if(!Object.is(e[n],t[n]))return!1;return!0}e.Arc=r,e.BitmapText=o,e.Blitter=a,e.Bob=i,e.Container=l,e.Curve=c,e.DOMElement=u,e.DisplayList=s,e.DynamicBitmapText=p,e.Ellipse=d,e.Extern=m,e.Fragment=n,e.GameObject=v,e.GameObjectCreator=f,e.GameObjectFactory=y,e.Graphics=b,e.Grid=O,e.Group=j,e.Image=G,e.IsoBox=g,e.IsoTriangle=h,e.Layer=x,e.Light=P,e.LightsManager=S,e.LightsPlugin=w,e.Line=T,e.Mesh=L,e.NineSlice=D,e.ParticleEmitter=E,e.PathFollower=B,e.Plane=I,e.PointLight=M,e.Polygon=C,e.Rectangle=R,e.RenderTexture=A,e.Rope=U,e.Shader=F,e.Shape=N,e.Sprite=k,e.Star=X,e.Text=V,e.TextStyle=Z,e.TileSprite=_,e.Triangle=J,e.UpdateList=W,e.Video=Y,e.Zone=q,e.createElement=K,e.createRef=function(){return{current:null}},e.jsx=K,e.render=function(e,t){var n;!function(e){le=e}(t);var r=null,o=null;"function"==typeof(null==e?void 0:e.type)&&(null===(n=e.type.prototype)||void 0===n?void 0:n.constructor)!==e.type&&(r=e.type,o=e.props);var a=se(e,t,r,o);!function(e){ce=e}(a),a.rerender()},e.useEffect=function(e,t){var n=ue(),r=n.getNextEffectIndex();n.pendingEffects.push({key:r,callback:e,deps:t})},e.useRef=function(e){return void 0===e&&(e=null),{current:e}},e.useScene=function(){return le},e.useState=function(e){var t=ue(),n=t.getNextStateIndex();t.state.has(n)||t.state.set(n,e);var r=t.state.get(n);return[r,function(e){var o="function"==typeof e?e(r):e;t.state.set(n,o),t.rerender()}]}});
//# sourceMappingURL=phaser-jsx.min.js.map