pixi-solid 0.0.1 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. package/dist/index.js +8 -7
  2. package/dist/pixi-application.js +86 -0
  3. package/dist/pixi-application.js.map +1 -0
  4. package/dist/pixi-canvas.js +79 -0
  5. package/dist/pixi-canvas.js.map +1 -0
  6. package/dist/pixi-components.js +197 -0
  7. package/dist/pixi-components.js.map +1 -0
  8. package/dist/pixi-events.js +40 -38
  9. package/dist/pixi-events.js.map +1 -1
  10. package/dist/pixi-stage.js +31 -0
  11. package/dist/pixi-stage.js.map +1 -0
  12. package/dist/renderer.js +59 -0
  13. package/dist/renderer.js.map +1 -0
  14. package/dist/universal.js +204 -0
  15. package/dist/universal.js.map +1 -0
  16. package/dist/use-ticker.js +44 -0
  17. package/dist/use-ticker.js.map +1 -0
  18. package/package.json +3 -2
  19. package/dist/examples/AnimatedSprite.example.jsx +0 -17
  20. package/dist/examples/AnimatedSprite.example.jsx.map +0 -1
  21. package/dist/examples/BitmapText.example.jsx +0 -8
  22. package/dist/examples/BitmapText.example.jsx.map +0 -1
  23. package/dist/examples/Container.example.jsx +0 -8
  24. package/dist/examples/Container.example.jsx.map +0 -1
  25. package/dist/examples/Graphics.example.jsx +0 -7
  26. package/dist/examples/Graphics.example.jsx.map +0 -1
  27. package/dist/examples/HTMLText.example.jsx +0 -5
  28. package/dist/examples/HTMLText.example.jsx.map +0 -1
  29. package/dist/examples/MeshPlane.example.jsx +0 -6
  30. package/dist/examples/MeshPlane.example.jsx.map +0 -1
  31. package/dist/examples/MeshRope.example.jsx +0 -10
  32. package/dist/examples/MeshRope.example.jsx.map +0 -1
  33. package/dist/examples/MeshSimple.example.jsx +0 -9
  34. package/dist/examples/MeshSimple.example.jsx.map +0 -1
  35. package/dist/examples/NineSliceSprite.example.jsx +0 -7
  36. package/dist/examples/NineSliceSprite.example.jsx.map +0 -1
  37. package/dist/examples/ParticleContainer.example.jsx +0 -30
  38. package/dist/examples/ParticleContainer.example.jsx.map +0 -1
  39. package/dist/examples/PerspectiveMesh.example.jsx +0 -6
  40. package/dist/examples/PerspectiveMesh.example.jsx.map +0 -1
  41. package/dist/examples/PixiApplication.example.jsx +0 -12
  42. package/dist/examples/PixiApplication.example.jsx.map +0 -1
  43. package/dist/examples/PixiCanvas.example.jsx +0 -12
  44. package/dist/examples/PixiCanvas.example.jsx.map +0 -1
  45. package/dist/examples/PixiStage.example.jsx +0 -12
  46. package/dist/examples/PixiStage.example.jsx.map +0 -1
  47. package/dist/examples/RenderContainer.example.jsx +0 -8
  48. package/dist/examples/RenderContainer.example.jsx.map +0 -1
  49. package/dist/examples/RenderLayer.example.jsx +0 -10
  50. package/dist/examples/RenderLayer.example.jsx.map +0 -1
  51. package/dist/examples/Sprite.example.jsx +0 -6
  52. package/dist/examples/Sprite.example.jsx.map +0 -1
  53. package/dist/examples/Text.example.jsx +0 -9
  54. package/dist/examples/Text.example.jsx.map +0 -1
  55. package/dist/examples/TilingSprite.example.jsx +0 -6
  56. package/dist/examples/TilingSprite.example.jsx.map +0 -1
  57. package/dist/examples/useTick.example.jsx +0 -12
  58. package/dist/examples/useTick.example.jsx.map +0 -1
  59. package/dist/examples/useTicker.example.jsx +0 -8
  60. package/dist/examples/useTicker.example.jsx.map +0 -1
  61. package/dist/index.js.map +0 -1
  62. package/dist/pixi-application.jsx +0 -86
  63. package/dist/pixi-application.jsx.map +0 -1
  64. package/dist/pixi-canvas.jsx +0 -65
  65. package/dist/pixi-canvas.jsx.map +0 -1
  66. package/dist/pixi-components.jsx +0 -214
  67. package/dist/pixi-components.jsx.map +0 -1
  68. package/dist/pixi-stage.jsx +0 -30
  69. package/dist/pixi-stage.jsx.map +0 -1
  70. package/dist/renderer.jsx +0 -74
  71. package/dist/renderer.jsx.map +0 -1
  72. package/dist/use-ticker.jsx +0 -39
  73. package/dist/use-ticker.jsx.map +0 -1
package/dist/index.js CHANGED
@@ -1,7 +1,8 @@
1
- export { PixiApplication, usePixiApp } from "./pixi-application";
2
- export { PixiCanvas } from "./pixi-canvas";
3
- export { AnimatedSprite, BitmapText, Container, Graphics, HTMLText, MeshPlane, MeshRope, MeshSimple, NineSliceSprite, ParticleContainer, PerspectiveMesh, RenderContainer, RenderLayer, Sprite, Text, TilingSprite, } from "./pixi-components";
4
- export { PIXI_EVENT_NAMES } from "./pixi-events";
5
- export { PixiStage } from "./pixi-stage";
6
- export { useTick, useTicker } from "./use-ticker";
7
- //# sourceMappingURL=index.js.map
1
+ import { PixiApplication, usePixiApp } from "./pixi-application.js";
2
+ import { PixiCanvas } from "./pixi-canvas.js";
3
+ import { PIXI_EVENT_NAMES } from "./pixi-events.js";
4
+ import { AnimatedSprite, BitmapText, Container, Graphics, HTMLText, MeshPlane, MeshRope, MeshSimple, NineSliceSprite, ParticleContainer, PerspectiveMesh, RenderContainer, RenderLayer, Sprite, Text, TilingSprite } from "./pixi-components.js";
5
+ import { PixiStage } from "./pixi-stage.js";
6
+ import { useTick, useTicker } from "./use-ticker.js";
7
+
8
+ export { AnimatedSprite, BitmapText, Container, Graphics, HTMLText, MeshPlane, MeshRope, MeshSimple, NineSliceSprite, PIXI_EVENT_NAMES, ParticleContainer, PerspectiveMesh, PixiApplication, PixiCanvas, PixiStage, RenderContainer, RenderLayer, Sprite, Text, TilingSprite, usePixiApp, useTick, useTicker };
@@ -0,0 +1,86 @@
1
+ import { createComponent } from "solid-js/web";
2
+ import { Application } from "pixi.js";
3
+ import { Show, createContext, createEffect, createResource, onCleanup, splitProps, useContext } from "solid-js";
4
+
5
+ //#region src/pixi-application.tsx
6
+ var PixiAppContext = createContext();
7
+ /**
8
+ * A custom SolidJS hook to access the root PIXI.Application instance.
9
+ * This hook must be called from a component that is a descendant of `PixiApplication`.
10
+ *
11
+ * @returns The PIXI.Application instance provided by the `PixiApplication` component.
12
+ * @throws Will throw an error if used outside of a `PixiApplication` context provider.
13
+ * @example
14
+ * ```tsx
15
+ * const MyComponent = () => {
16
+ * const app = usePixiApp();
17
+ *
18
+ * createEffect(() => {
19
+ * console.log('App resolution:', app.renderer.resolution);
20
+ * });
21
+ *
22
+ * return <Sprite texture={Texture.WHITE} />;
23
+ * };
24
+ * ```
25
+ */
26
+ const usePixiApp = () => {
27
+ const app = useContext(PixiAppContext);
28
+ if (!app) throw new Error("usePixiApp must be used within a PixiApplication");
29
+ return app;
30
+ };
31
+ /**
32
+ * A SolidJS component that creates and manages a PIXI.Application instance.
33
+ * It provides the application instance through context to be used by child components
34
+ * and custom hooks like `usePixiApp`, `useTick`, and `useTicker`.
35
+ *
36
+ * This component should only be used once in your application.
37
+ *
38
+ * @param props The properties to configure the Pixi.js Application.
39
+ *
40
+ * **Example**
41
+ * {@includeCode ./examples/PixiApplication.example.tsx}
42
+ */
43
+ const PixiApplication = (props) => {
44
+ const [_solidProps, initialisationProps] = splitProps(props, ["ref", "children"]);
45
+ const [appResource] = createResource(async () => {
46
+ if (globalThis.__PIXI_DEVTOOLS__) throw new Error("Only one PixiApplication can be active at a time. Multiple instances detected.");
47
+ const app = new Application();
48
+ await app.init({
49
+ autoDensity: true,
50
+ resolution: Math.min(window.devicePixelRatio, 2),
51
+ sharedTicker: true,
52
+ ...initialisationProps
53
+ });
54
+ return app;
55
+ });
56
+ createEffect(() => {
57
+ const app = appResource();
58
+ if (app) {
59
+ if (props.ref) props.ref(app.stage);
60
+ app.ticker.autoStart = false;
61
+ app.ticker.start();
62
+ globalThis.__PIXI_DEVTOOLS__ = { app };
63
+ onCleanup(() => {
64
+ app.destroy(true, { children: true });
65
+ globalThis.__PIXI_DEVTOOLS__ = void 0;
66
+ });
67
+ }
68
+ });
69
+ return createComponent(Show, {
70
+ get when() {
71
+ return appResource();
72
+ },
73
+ children: (app) => createComponent(PixiAppContext.Provider, {
74
+ get value() {
75
+ return app();
76
+ },
77
+ get children() {
78
+ return props.children;
79
+ }
80
+ })
81
+ });
82
+ };
83
+
84
+ //#endregion
85
+ export { PixiApplication, usePixiApp };
86
+ //# sourceMappingURL=pixi-application.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pixi-application.js","names":["ApplicationOptions","Container","Application","JSX","Ref","createContext","createEffect","createResource","onCleanup","Show","splitProps","useContext","PixiAppContext","usePixiApp","app","Error","PixiApplicationProps","Partial","Omit","ref","children","Element","PixiApplication","props","_solidProps","initialisationProps","appResource","globalThis","__PIXI_DEVTOOLS__","init","autoDensity","resolution","Math","min","window","devicePixelRatio","sharedTicker","arg","stage","ticker","autoStart","start","destroy","undefined","_$createComponent","when","Provider","value"],"sources":["../src/pixi-application.tsx"],"sourcesContent":["import type { ApplicationOptions, Container } from \"pixi.js\";\nimport { Application } from \"pixi.js\";\nimport type { JSX, Ref } from \"solid-js\";\nimport {\n createContext,\n createEffect,\n createResource,\n onCleanup,\n Show,\n splitProps,\n useContext,\n} from \"solid-js\";\n\nconst PixiAppContext = createContext<Application>();\n\n/**\n * A custom SolidJS hook to access the root PIXI.Application instance.\n * This hook must be called from a component that is a descendant of `PixiApplication`.\n *\n * @returns The PIXI.Application instance provided by the `PixiApplication` component.\n * @throws Will throw an error if used outside of a `PixiApplication` context provider.\n * @example\n * ```tsx\n * const MyComponent = () => {\n * const app = usePixiApp();\n *\n * createEffect(() => {\n * console.log('App resolution:', app.renderer.resolution);\n * });\n *\n * return <Sprite texture={Texture.WHITE} />;\n * };\n * ```\n */\nexport const usePixiApp = () => {\n const app = useContext(PixiAppContext);\n if (!app) {\n throw new Error(\"usePixiApp must be used within a PixiApplication\");\n }\n return app;\n};\n\n/**\n * Props for the `PixiApplication` component. It extends the PIXI.ApplicationOptions\n * to allow passing configuration directly to the Pixi.js Application constructor,\n * but omits properties that are handled by the component itself.\n */\nexport type PixiApplicationProps = Partial<\n Omit<ApplicationOptions, \"children\" | \"resizeTo\" | \"view\">\n> & {\n ref?: Ref<Container>;\n children?: JSX.Element;\n};\n\n/**\n * A SolidJS component that creates and manages a PIXI.Application instance.\n * It provides the application instance through context to be used by child components\n * and custom hooks like `usePixiApp`, `useTick`, and `useTicker`.\n *\n * This component should only be used once in your application.\n *\n * @param props The properties to configure the Pixi.js Application.\n * \n * **Example**\n * {@includeCode ./examples/PixiApplication.example.tsx}\n */\nexport const PixiApplication = (props: PixiApplicationProps) => {\n const [_solidProps, initialisationProps] = splitProps(props, [\"ref\", \"children\"]);\n\n // TODO: Reinitialise the pixi app if any of the initialisationProps change that we can't set at runtime\n\n const [appResource] = createResource(async () => {\n // Enforce singleton pattern: Check if an app already exists\n // @ts-expect-error\n if (globalThis.__PIXI_DEVTOOLS__) {\n throw new Error(\n \"Only one PixiApplication can be active at a time. Multiple instances detected.\",\n );\n }\n\n const app = new Application();\n await app.init({\n autoDensity: true,\n resolution: Math.min(window.devicePixelRatio, 2),\n sharedTicker: true,\n ...initialisationProps,\n });\n\n return app;\n });\n\n createEffect(() => {\n const app = appResource();\n if (app) {\n if (props.ref) {\n // Solid converts the ref prop to a callback function\n (props.ref as unknown as (arg: any) => void)(app.stage);\n }\n\n // TODO: Go through the other props that can be set at runtime and apply them here\n // e.g. backgroundColor => app.renderer.backgroundColor, etc.\n\n app.ticker.autoStart = false;\n app.ticker.start();\n\n // @ts-expect-error\n globalThis.__PIXI_DEVTOOLS__ = {\n app,\n };\n\n onCleanup(() => {\n app.destroy(true, { children: true });\n // @ts-expect-error\n globalThis.__PIXI_DEVTOOLS__ = undefined;\n });\n }\n });\n\n return (\n <Show when={appResource()}>\n {(app) => <PixiAppContext.Provider value={app()}>{props.children}</PixiAppContext.Provider>}\n </Show>\n );\n};\n"],"mappings":";;;;;AAaA,IAAMY,iBAAiBP,eAA4B;;;;;;;;;;;;;;;;;;;;AAqBnD,MAAaQ,mBAAmB;CAC9B,MAAMC,MAAMH,WAAWC,eAAe;AACtC,KAAI,CAACE,IACH,OAAM,IAAIC,MAAM,mDAAmD;AAErE,QAAOD;;;;;;;;;;;;;;AA2BT,MAAaQ,mBAAmBC,UAAgC;CAC9D,MAAM,CAACC,aAAaC,uBAAuBf,WAAWa,OAAO,CAAC,OAAO,WAAW,CAAC;CAIjF,MAAM,CAACG,eAAenB,eAAe,YAAY;AAG/C,MAAIoB,WAAWC,kBACb,OAAM,IAAIb,MACR,iFACD;EAGH,MAAMD,MAAM,IAAIZ,aAAa;AAC7B,QAAMY,IAAIe,KAAK;GACbC,aAAa;GACbC,YAAYC,KAAKC,IAAIC,OAAOC,kBAAkB,EAAE;GAChDC,cAAc;GACd,GAAGX;GACJ,CAAC;AAEF,SAAOX;GACP;AAEFR,oBAAmB;EACjB,MAAMQ,MAAMY,aAAa;AACzB,MAAIZ,KAAK;AACP,OAAIS,MAAMJ,IAEPI,OAAMJ,IAAsCL,IAAIwB,MAAM;AAMzDxB,OAAIyB,OAAOC,YAAY;AACvB1B,OAAIyB,OAAOE,OAAO;AAGlBd,cAAWC,oBAAoB,EAC7Bd,KACD;AAEDN,mBAAgB;AACdM,QAAI4B,QAAQ,MAAM,EAAEtB,UAAU,MAAM,CAAC;AAErCO,eAAWC,oBAAoBe;KAC/B;;GAEJ;AAEF,QAAAC,gBACGnC,MAAI;EAAA,IAACoC,OAAI;AAAA,UAAEnB,aAAa;;EAAAN,WACrBN,QAAG8B,gBAAMhC,eAAekC,UAAQ;GAAA,IAACC,QAAK;AAAA,WAAEjC,KAAK;;GAAA,IAAAM,WAAA;AAAA,WAAGG,MAAMH;;GAAQ,CAAA;EAA2B,CAAA"}
@@ -0,0 +1,79 @@
1
+ import { usePixiApp } from "./pixi-application.js";
2
+ import { classList, effect, insert, style, template, use } from "solid-js/web";
3
+ import { createRenderEffect, onCleanup, onMount } from "solid-js";
4
+
5
+ //#region src/pixi-canvas.tsx
6
+ var _tmpl$ = /* @__PURE__ */ template(`<div>`);
7
+ /**
8
+ * PixiCanvas
9
+ *
10
+ * A small wrapper that mounts the PIXI application's canvas element into the DOM
11
+ * and automatically resizes it.
12
+ *
13
+ * - Requires a surrounding `PixiApplication` (accessed via `usePixiApp`).
14
+ * - Requires a `PixiStage` component as a child.
15
+ *
16
+ * Props:
17
+ * @param props.children - JSX content to render inside the canvas wrapper. Use
18
+ * `PixiStage` as the only child.
19
+ *
20
+ * **Example**
21
+ * {@includeCode ./examples/PixiCanvas.example.tsx}
22
+ *
23
+ */
24
+ const PixiCanvas = (props) => {
25
+ let canvasWrapElement;
26
+ const pixiApp = usePixiApp();
27
+ pixiApp.canvas.style.display = "block";
28
+ pixiApp.canvas.style.position = "absolute";
29
+ pixiApp.canvas.style.top = "0";
30
+ pixiApp.canvas.style.left = "0";
31
+ pixiApp.canvas.style.width = "100%";
32
+ pixiApp.canvas.style.height = "100%";
33
+ createRenderEffect(() => {
34
+ if (props.children === void 0) throw new Error("PixiCanvas requires the `PixiStage` component to render.");
35
+ });
36
+ let previousResizeTo;
37
+ let resizeObserver;
38
+ onMount(() => {
39
+ if (!canvasWrapElement) return;
40
+ previousResizeTo = pixiApp.resizeTo;
41
+ pixiApp.resizeTo = canvasWrapElement;
42
+ pixiApp.queueResize();
43
+ resizeObserver = new ResizeObserver(() => {
44
+ pixiApp.queueResize();
45
+ });
46
+ resizeObserver.observe(canvasWrapElement);
47
+ });
48
+ onCleanup(() => {
49
+ if (!canvasWrapElement) return;
50
+ pixiApp.resizeTo = previousResizeTo;
51
+ resizeObserver?.disconnect();
52
+ resizeObserver = void 0;
53
+ });
54
+ return (() => {
55
+ var _el$ = _tmpl$();
56
+ var _ref$ = canvasWrapElement;
57
+ typeof _ref$ === "function" ? use(_ref$, _el$) : canvasWrapElement = _el$;
58
+ insert(_el$, () => pixiApp.canvas);
59
+ effect((_p$) => {
60
+ var _v$ = {
61
+ position: "relative",
62
+ flex: 1,
63
+ display: "block",
64
+ ...typeof props.style === "object" ? props.style : {}
65
+ }, _v$2 = { [props.className || ""]: props.className !== void 0 };
66
+ _p$.e = style(_el$, _v$, _p$.e);
67
+ _p$.t = classList(_el$, _v$2, _p$.t);
68
+ return _p$;
69
+ }, {
70
+ e: void 0,
71
+ t: void 0
72
+ });
73
+ return _el$;
74
+ })();
75
+ };
76
+
77
+ //#endregion
78
+ export { PixiCanvas };
79
+ //# sourceMappingURL=pixi-canvas.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pixi-canvas.js","names":["JSX","createRenderEffect","onCleanup","onMount","usePixiApp","PixiCanvas","props","children","Element","style","CSSProperties","className","canvasWrapElement","HTMLDivElement","pixiApp","canvas","display","position","top","left","width","height","undefined","Error","previousResizeTo","resizeTo","resizeObserver","ResizeObserver","queueResize","observe","disconnect","_el$","_tmpl$","_ref$","_$use","_$insert","_$effect","_p$","_v$","flex","_v$2","e","_$style","t","_$classList"],"sources":["../src/pixi-canvas.tsx"],"sourcesContent":["import type { JSX } from \"solid-js\";\nimport { createRenderEffect, onCleanup, onMount } from \"solid-js\";\nimport { usePixiApp } from \"./pixi-application\";\n\n/**\n * PixiCanvas\n *\n * A small wrapper that mounts the PIXI application's canvas element into the DOM\n * and automatically resizes it.\n *\n * - Requires a surrounding `PixiApplication` (accessed via `usePixiApp`).\n * - Requires a `PixiStage` component as a child.\n *\n * Props:\n * @param props.children - JSX content to render inside the canvas wrapper. Use\n * `PixiStage` as the only child.\n *\n * **Example**\n * {@includeCode ./examples/PixiCanvas.example.tsx}\n *\n */\n\nexport const PixiCanvas = (props: {\n children: JSX.Element;\n style?: JSX.CSSProperties | undefined;\n className?: string;\n}): JSX.Element => {\n let canvasWrapElement: HTMLDivElement | undefined;\n\n const pixiApp = usePixiApp();\n pixiApp.canvas.style.display = \"block\";\n pixiApp.canvas.style.position = \"absolute\";\n pixiApp.canvas.style.top = \"0\";\n pixiApp.canvas.style.left = \"0\";\n pixiApp.canvas.style.width = \"100%\";\n pixiApp.canvas.style.height = \"100%\";\n\n createRenderEffect(() => {\n if (props.children === undefined) {\n throw new Error(\"PixiCanvas requires the `PixiStage` component to render.\");\n }\n });\n\n let previousResizeTo: typeof pixiApp.resizeTo;\n let resizeObserver: ResizeObserver | undefined;\n\n onMount(() => {\n if (!canvasWrapElement) return;\n previousResizeTo = pixiApp.resizeTo;\n pixiApp.resizeTo = canvasWrapElement;\n pixiApp.queueResize();\n resizeObserver = new ResizeObserver(() => {\n pixiApp.queueResize();\n });\n resizeObserver.observe(canvasWrapElement);\n });\n\n onCleanup(() => {\n if (!canvasWrapElement) return;\n pixiApp.resizeTo = previousResizeTo;\n resizeObserver?.disconnect();\n resizeObserver = undefined;\n });\n\n return (\n <div\n ref={canvasWrapElement}\n style={{\n ...{\n position: \"relative\",\n flex: 1,\n display: \"block\",\n },\n ...(typeof props.style === \"object\" ? props.style : {}),\n }}\n classList={{ [props.className || \"\"]: props.className !== undefined }}\n >\n {pixiApp.canvas}\n </div>\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAsBA,MAAaK,cAAcC,UAIR;CACjB,IAAIM;CAEJ,MAAME,UAAUV,YAAY;AAC5BU,SAAQC,OAAON,MAAMO,UAAU;AAC/BF,SAAQC,OAAON,MAAMQ,WAAW;AAChCH,SAAQC,OAAON,MAAMS,MAAM;AAC3BJ,SAAQC,OAAON,MAAMU,OAAO;AAC5BL,SAAQC,OAAON,MAAMW,QAAQ;AAC7BN,SAAQC,OAAON,MAAMY,SAAS;AAE9BpB,0BAAyB;AACvB,MAAIK,MAAMC,aAAae,OACrB,OAAM,IAAIC,MAAM,2DAA2D;GAE7E;CAEF,IAAIC;CACJ,IAAIE;AAEJvB,eAAc;AACZ,MAAI,CAACS,kBAAmB;AACxBY,qBAAmBV,QAAQW;AAC3BX,UAAQW,WAAWb;AACnBE,UAAQc,aAAa;AACrBF,mBAAiB,IAAIC,qBAAqB;AACxCb,WAAQc,aAAa;IACrB;AACFF,iBAAeG,QAAQjB,kBAAkB;GACzC;AAEFV,iBAAgB;AACd,MAAI,CAACU,kBAAmB;AACxBE,UAAQW,WAAWD;AACnBE,kBAAgBI,YAAY;AAC5BJ,mBAAiBJ;GACjB;AAEF,eAAA;EAAA,IAAAS,OAAAC,QAAA;EAAA,IAAAC,QAESrB;AAAiB,SAAAqB,UAAA,aAAAC,IAAAD,OAAAF,KAAA,GAAjBnB,oBAAiBmB;AAAAI,SAAAJ,YAWrBjB,QAAQC,OAAM;AAAAqB,UAAAC,QAAA;GAAA,IAAAC,MAVR;IAEHrB,UAAU;IACVsB,MAAM;IACNvB,SAAS;IAEX,GAAI,OAAOV,MAAMG,UAAU,WAAWH,MAAMG,QAAQ,EAAE;IACvD,EAAA+B,OACU,GAAGlC,MAAMK,aAAa,KAAKL,MAAMK,cAAcW,QAAW;AAAAe,OAAAI,IAAAC,MAAAX,MAAAO,KAAAD,IAAAI,EAAA;AAAAJ,OAAAM,IAAAC,UAAAb,MAAAS,MAAAH,IAAAM,EAAA;AAAA,UAAAN;KAAA;GAAAI,GAAAnB;GAAAqB,GAAArB;GAAA,CAAA;AAAA,SAAAS;KAAA"}
@@ -0,0 +1,197 @@
1
+ import { PIXI_EVENT_HANDLER_NAMES } from "./pixi-events.js";
2
+ import { insert, setProp } from "./renderer.js";
3
+ import { AnimatedSprite, BitmapText, Container, Graphics, HTMLText, MeshPlane, MeshRope, MeshSimple, NineSliceSprite, ParticleContainer, PerspectiveMesh, RenderContainer, RenderLayer, Sprite, Text, TilingSprite } from "pixi.js";
4
+ import { createRenderEffect, splitProps } from "solid-js";
5
+
6
+ //#region src/pixi-components.tsx
7
+ const SOLID_PROP_KEYS = [
8
+ "ref",
9
+ "as",
10
+ "children"
11
+ ];
12
+ /**
13
+ * Apply's the props to a Pixi instance with subsriptions to maintain reactivity.
14
+ *
15
+ * @param instance The Pixi instance we want to apply props to.
16
+ * @param props The props object.
17
+ */
18
+ const applyProps = (instance, props) => {
19
+ for (const key in props) {
20
+ if (key === "as") continue;
21
+ if (key === "ref") createRenderEffect(() => {
22
+ props[key](instance);
23
+ });
24
+ else if (key === "children") {
25
+ if (!("addChild" in instance)) throw new Error(`Cannot set children on non-container instance.`);
26
+ createRenderEffect(() => {
27
+ insert(instance, () => props.children);
28
+ });
29
+ } else createRenderEffect(() => {
30
+ setProp(instance, key, props[key]);
31
+ });
32
+ }
33
+ };
34
+ var createContainerComponent = (PixiClass) => {
35
+ return (props) => {
36
+ const [runtimeProps, initialisationProps] = splitProps(props, [...SOLID_PROP_KEYS, ...PIXI_EVENT_HANDLER_NAMES]);
37
+ const instance = props.as || new PixiClass(initialisationProps);
38
+ applyProps(instance, initialisationProps);
39
+ applyProps(instance, runtimeProps);
40
+ return instance;
41
+ };
42
+ };
43
+ var createLeafComponent = (PixiClass) => {
44
+ return (props) => {
45
+ return createContainerComponent(PixiClass)(props);
46
+ };
47
+ };
48
+ /**
49
+ * A SolidJS component that renders a PIXI.AnimatedSprite.
50
+ *
51
+ * **Example**
52
+ * {@includeCode ./examples/AnimatedSprite.example.tsx}
53
+ *
54
+ * {@link PixiAnimatedSprite}
55
+ *
56
+ */
57
+ const AnimatedSprite$1 = createLeafComponent(AnimatedSprite);
58
+ /**
59
+ * A SolidJS component that renders a PIXI.BitmapText.
60
+ *
61
+ * **Example**
62
+ * {@includeCode ./examples/BitmapText.example.tsx}
63
+ *
64
+ * {@link PixiBitmapText}
65
+ *
66
+ */
67
+ const BitmapText$1 = createLeafComponent(BitmapText);
68
+ /**
69
+ * A SolidJS component that renders a PIXI.Container.
70
+ *
71
+ * **Example**
72
+ * {@includeCode ./examples/Container.example.tsx}
73
+ *
74
+ */
75
+ const Container$1 = createContainerComponent(Container);
76
+ /**
77
+ * A SolidJS component that renders a PIXI.Graphics.
78
+ * Use a ref to access the underlying graphics instance and draw with it.
79
+ *
80
+ * **Example**
81
+ * {@includeCode ./examples/Graphics.example.tsx}
82
+ *
83
+ * {@link PixiGraphics}
84
+ */
85
+ const Graphics$1 = createLeafComponent(Graphics);
86
+ /**
87
+ * A SolidJS component that renders a PIXI.HTMLText.
88
+ *
89
+ * **Example**
90
+ * {@includeCode ./examples/HTMLText.example.tsx}
91
+ *
92
+ * {@link PixiHTMLText}
93
+ */
94
+ const HTMLText$1 = createLeafComponent(HTMLText);
95
+ /**
96
+ * A SolidJS component that renders a PIXI.MeshPlane.
97
+ *
98
+ * **Example**
99
+ * {@includeCode ./examples/MeshPlane.example.tsx}
100
+ *
101
+ * {@link PixiMeshPlane}
102
+ */
103
+ const MeshPlane$1 = createLeafComponent(MeshPlane);
104
+ /**
105
+ * A SolidJS component that renders a PIXI.MeshRope.
106
+ *
107
+ * **Example**
108
+ * {@includeCode ./examples/MeshRope.example.tsx}
109
+ *
110
+ * {@link PixiMeshRope}
111
+ */
112
+ const MeshRope$1 = createLeafComponent(MeshRope);
113
+ /**
114
+ * A SolidJS component that renders a PIXI.MeshSimple.
115
+ *
116
+ * **Example**
117
+ * {@includeCode ./examples/MeshSimple.example.tsx}
118
+ *
119
+ * {@link PixiMeshSimple}
120
+ */
121
+ const MeshSimple$1 = createLeafComponent(MeshSimple);
122
+ /**
123
+ * A SolidJS component that renders a PIXI.NineSliceSprite.
124
+ *
125
+ * **Example**
126
+ * {@includeCode ./examples/NineSliceSprite.example.tsx}
127
+ *
128
+ * {@link PixiNineSliceSprite}
129
+ */
130
+ const NineSliceSprite$1 = createLeafComponent(NineSliceSprite);
131
+ /**
132
+ * A SolidJS component that renders a PIXI.ParticleContainer.
133
+ *
134
+ * **Example**
135
+ * {@includeCode ./examples/ParticleContainer.example.tsx}
136
+ *
137
+ * {@link PixiParticleContainer}
138
+ */
139
+ const ParticleContainer$1 = createLeafComponent(ParticleContainer);
140
+ /**
141
+ * A SolidJS component that renders a PIXI.PerspectiveMesh.
142
+ *
143
+ * **Example**
144
+ * {@includeCode ./examples/PerspectiveMesh.example.tsx}
145
+ *
146
+ * {@link PixiPerspectiveMesh}
147
+ */
148
+ const PerspectiveMesh$1 = createLeafComponent(PerspectiveMesh);
149
+ /**
150
+ * A SolidJS component that renders a PIXI.RenderContainer.
151
+ *
152
+ * **Example**
153
+ * {@includeCode ./examples/RenderContainer.example.tsx}
154
+ *
155
+ * {@link PixiRenderContainer}
156
+ */
157
+ const RenderContainer$1 = createContainerComponent(RenderContainer);
158
+ /**
159
+ * A SolidJS component that renders a PIXI.RenderLayer.
160
+ *
161
+ * **Example**
162
+ * {@includeCode ./examples/RenderLayer.example.tsx}
163
+ *
164
+ * {@link PixiRenderLayer}
165
+ */
166
+ const RenderLayer$1 = createContainerComponent(RenderLayer);
167
+ /**
168
+ * A SolidJS component that renders a PIXI.Sprite.
169
+ *
170
+ * **Example**
171
+ * {@includeCode ./examples/Sprite.example.tsx}
172
+ *
173
+ * {@link PixiSprite}
174
+ */
175
+ const Sprite$1 = createLeafComponent(Sprite);
176
+ /**
177
+ * A SolidJS component that renders a PIXI.Text.
178
+ *
179
+ * **Example**
180
+ * {@includeCode ./examples/Text.example.tsx}
181
+ *
182
+ * {@link PixiText}
183
+ */
184
+ const Text$1 = createLeafComponent(Text);
185
+ /**
186
+ * A SolidJS component that renders a PIXI.TilingSprite.
187
+ *
188
+ * **Example**
189
+ * {@includeCode ./examples/TilingSprite.example.tsx}
190
+ *
191
+ * {@link PixiTilingSprite}
192
+ */
193
+ const TilingSprite$1 = createLeafComponent(TilingSprite);
194
+
195
+ //#endregion
196
+ export { AnimatedSprite$1 as AnimatedSprite, BitmapText$1 as BitmapText, Container$1 as Container, Graphics$1 as Graphics, HTMLText$1 as HTMLText, MeshPlane$1 as MeshPlane, MeshRope$1 as MeshRope, MeshSimple$1 as MeshSimple, NineSliceSprite$1 as NineSliceSprite, ParticleContainer$1 as ParticleContainer, PerspectiveMesh$1 as PerspectiveMesh, RenderContainer$1 as RenderContainer, RenderLayer$1 as RenderLayer, Sprite$1 as Sprite, Text$1 as Text, TilingSprite$1 as TilingSprite, applyProps };
197
+ //# sourceMappingURL=pixi-components.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pixi-components.js","names":["Pixi","AnimatedSprite","PixiAnimatedSprite","BitmapText","PixiBitmapText","Container","PixiContainer","Graphics","PixiGraphics","HTMLText","PixiHTMLText","MeshPlane","PixiMeshPlane","MeshRope","PixiMeshRope","MeshSimple","PixiMeshSimple","NineSliceSprite","PixiNineSliceSprite","ParticleContainer","PixiParticleContainer","PerspectiveMesh","PixiPerspectiveMesh","RenderContainer","PixiRenderContainer","RenderLayer","PixiRenderLayer","Sprite","PixiSprite","Text","PixiText","TilingSprite","PixiTilingSprite","JSX","Ref","createRenderEffect","splitProps","PixiEventHandlerMap","PIXI_EVENT_HANDLER_NAMES","insert","setProp","ContainerProps","ref","Component","as","children","Element","LeafProps","Omit","SOLID_PROP_KEYS","const","applyProps","InstanceType","instance","props","OptionsType","key","arg","Error","createContainerComponent","PixiClass","runtimeProps","initialisationProps","createLeafComponent","AnimatedSpriteOptions","TextOptions","ContainerOptions","GraphicsOptions","HTMLTextOptions","MeshPlaneOptions","MeshRopeOptions","SimpleMeshOptions","NineSliceSpriteOptions","ParticleContainerOptions","PerspectivePlaneOptions","RenderContainerOptions","RenderLayerOptions","SpriteOptions","CanvasTextOptions","TilingSpriteOptions"],"sources":["../src/pixi-components.tsx"],"sourcesContent":["import type * as Pixi from \"pixi.js\";\nimport {\n AnimatedSprite as PixiAnimatedSprite,\n BitmapText as PixiBitmapText,\n Container as PixiContainer,\n Graphics as PixiGraphics,\n HTMLText as PixiHTMLText,\n MeshPlane as PixiMeshPlane,\n MeshRope as PixiMeshRope,\n MeshSimple as PixiMeshSimple,\n NineSliceSprite as PixiNineSliceSprite,\n ParticleContainer as PixiParticleContainer,\n PerspectiveMesh as PixiPerspectiveMesh,\n RenderContainer as PixiRenderContainer,\n RenderLayer as PixiRenderLayer,\n Sprite as PixiSprite,\n Text as PixiText,\n TilingSprite as PixiTilingSprite,\n} from \"pixi.js\";\nimport type { JSX, Ref } from \"solid-js\";\nimport { createRenderEffect, splitProps } from \"solid-js\";\nimport type { PixiEventHandlerMap } from \"./pixi-events\";\n\nimport { PIXI_EVENT_HANDLER_NAMES } from \"./pixi-events\";\nimport { insert, setProp } from \"./renderer\";\n\n/**\n * Prop definition for components that CAN have children\n */\nexport type ContainerProps<Component> = PixiEventHandlerMap & {\n ref?: Ref<Component>;\n as?: Component;\n children?: JSX.Element;\n};\n\n/**\n * Prop definition for components that CANNOT have children\n */\nexport type LeafProps<Component> = Omit<ContainerProps<Component>, \"children\">;\n\n// Keys that are specific to Solid components and not Pixi props\nexport const SOLID_PROP_KEYS = [\"ref\", \"as\", \"children\"] as const;\n\n/**\n * Apply's the props to a Pixi instance with subsriptions to maintain reactivity.\n * \n * @param instance The Pixi instance we want to apply props to.\n * @param props The props object.\n */\nexport const applyProps = <\n InstanceType extends PixiContainer,\n OptionsType extends ContainerProps<InstanceType>,\n>(\n instance: InstanceType,\n props: OptionsType,\n) => {\n for (const key in props) {\n if (key === \"as\") continue;\n\n if (key === \"ref\") {\n createRenderEffect(() => {\n // Solid converts the ref prop to a callback function\n (props[key] as unknown as (arg: any) => void)(instance);\n });\n } else if (key === \"children\") {\n if (!(\"addChild\" in instance)) {\n throw new Error(`Cannot set children on non-container instance.`);\n }\n createRenderEffect(() => {\n insert(instance, () => props.children);\n });\n } else {\n createRenderEffect(() => {\n setProp(instance, key, props[key as keyof typeof props]);\n });\n }\n }\n};\n\nconst createContainerComponent = <InstanceType extends PixiContainer, OptionsType extends object>(\n PixiClass: new (props: OptionsType) => InstanceType,\n) => {\n return (props: Omit<OptionsType, \"children\"> & ContainerProps<InstanceType>): JSX.Element => {\n const [runtimeProps, initialisationProps] = splitProps(props, [\n ...SOLID_PROP_KEYS,\n ...PIXI_EVENT_HANDLER_NAMES,\n ]);\n\n const instance = props.as || new PixiClass(initialisationProps as any);\n\n applyProps(instance, initialisationProps);\n applyProps(instance, runtimeProps);\n\n return instance as unknown as JSX.Element;\n };\n};\n\nconst createLeafComponent = <InstanceType extends PixiContainer, OptionsType extends object>(\n PixiClass: new (props: OptionsType) => InstanceType,\n) => {\n return (props: Omit<OptionsType, \"children\"> & LeafProps<InstanceType>): JSX.Element => {\n return createContainerComponent<PixiContainer, OptionsType>(PixiClass)(props as any);\n };\n};\n\n/**\n * A SolidJS component that renders a PIXI.AnimatedSprite.\n *\n * **Example**\n * {@includeCode ./examples/AnimatedSprite.example.tsx}\n * \n * {@link PixiAnimatedSprite}\n *\n */\nexport const AnimatedSprite = createLeafComponent<PixiAnimatedSprite, Pixi.AnimatedSpriteOptions>(\n PixiAnimatedSprite,\n);\n/**\n * A SolidJS component that renders a PIXI.BitmapText.\n *\n * **Example**\n * {@includeCode ./examples/BitmapText.example.tsx}\n * \n * {@link PixiBitmapText}\n *\n */\nexport const BitmapText = createLeafComponent<PixiBitmapText, Pixi.TextOptions>(PixiBitmapText);\n/**\n * A SolidJS component that renders a PIXI.Container.\n *\n * **Example**\n * {@includeCode ./examples/Container.example.tsx}\n *\n */\nexport const Container = createContainerComponent<PixiContainer, Pixi.ContainerOptions>(\n PixiContainer,\n);\n/**\n * A SolidJS component that renders a PIXI.Graphics.\n * Use a ref to access the underlying graphics instance and draw with it.\n *\n * **Example**\n * {@includeCode ./examples/Graphics.example.tsx}\n *\n * {@link PixiGraphics}\n */\nexport const Graphics = createLeafComponent<PixiGraphics, Pixi.GraphicsOptions>(PixiGraphics);\n/**\n * A SolidJS component that renders a PIXI.HTMLText.\n *\n * **Example**\n * {@includeCode ./examples/HTMLText.example.tsx}\n *\n * {@link PixiHTMLText}\n */\nexport const HTMLText = createLeafComponent<PixiHTMLText, Pixi.HTMLTextOptions>(PixiHTMLText);\n\n/**\n * A SolidJS component that renders a PIXI.MeshPlane.\n *\n * **Example**\n * {@includeCode ./examples/MeshPlane.example.tsx}\n *\n * {@link PixiMeshPlane}\n */\nexport const MeshPlane = createLeafComponent<PixiMeshPlane, Pixi.MeshPlaneOptions>(PixiMeshPlane);\n\n/**\n * A SolidJS component that renders a PIXI.MeshRope.\n *\n * **Example**\n * {@includeCode ./examples/MeshRope.example.tsx}\n *\n * {@link PixiMeshRope}\n */\nexport const MeshRope = createLeafComponent<PixiMeshRope, Pixi.MeshRopeOptions>(PixiMeshRope);\n\n/**\n * A SolidJS component that renders a PIXI.MeshSimple.\n *\n * **Example**\n * {@includeCode ./examples/MeshSimple.example.tsx}\n *\n * {@link PixiMeshSimple}\n */\nexport const MeshSimple = createLeafComponent<PixiMeshSimple, Pixi.SimpleMeshOptions>(\n PixiMeshSimple,\n);\n\n/**\n * A SolidJS component that renders a PIXI.NineSliceSprite.\n *\n * **Example**\n * {@includeCode ./examples/NineSliceSprite.example.tsx}\n *\n * {@link PixiNineSliceSprite}\n */\nexport const NineSliceSprite = createLeafComponent<\n PixiNineSliceSprite,\n Pixi.NineSliceSpriteOptions\n>(PixiNineSliceSprite);\n\n/**\n * A SolidJS component that renders a PIXI.ParticleContainer.\n *\n * **Example**\n * {@includeCode ./examples/ParticleContainer.example.tsx}\n *\n * {@link PixiParticleContainer}\n */\nexport const ParticleContainer = createLeafComponent<\n PixiParticleContainer,\n Pixi.ParticleContainerOptions\n>(PixiParticleContainer);\n\n/**\n * A SolidJS component that renders a PIXI.PerspectiveMesh.\n *\n * **Example**\n * {@includeCode ./examples/PerspectiveMesh.example.tsx}\n *\n * {@link PixiPerspectiveMesh}\n */\nexport const PerspectiveMesh = createLeafComponent<\n PixiPerspectiveMesh,\n Pixi.PerspectivePlaneOptions\n>(PixiPerspectiveMesh);\n\n/**\n * A SolidJS component that renders a PIXI.RenderContainer.\n *\n * **Example**\n * {@includeCode ./examples/RenderContainer.example.tsx}\n *\n * {@link PixiRenderContainer}\n */\nexport const RenderContainer = createContainerComponent<\n PixiRenderContainer,\n Pixi.RenderContainerOptions\n>(PixiRenderContainer);\n\n/**\n * A SolidJS component that renders a PIXI.RenderLayer.\n *\n * **Example**\n * {@includeCode ./examples/RenderLayer.example.tsx}\n *\n * {@link PixiRenderLayer}\n */\nexport const RenderLayer = createContainerComponent<PixiRenderLayer, Pixi.RenderLayerOptions>(\n PixiRenderLayer,\n);\n\n/**\n * A SolidJS component that renders a PIXI.Sprite.\n *\n * **Example**\n * {@includeCode ./examples/Sprite.example.tsx}\n *\n * {@link PixiSprite}\n */\nexport const Sprite = createLeafComponent<PixiSprite, Pixi.SpriteOptions>(PixiSprite);\n/**\n * A SolidJS component that renders a PIXI.Text.\n *\n * **Example**\n * {@includeCode ./examples/Text.example.tsx}\n *\n * {@link PixiText}\n */\nexport const Text = createLeafComponent<PixiText, Pixi.CanvasTextOptions>(PixiText);\n\n/**\n * A SolidJS component that renders a PIXI.TilingSprite.\n *\n * **Example**\n * {@includeCode ./examples/TilingSprite.example.tsx}\n *\n * {@link PixiTilingSprite}\n */\nexport const TilingSprite = createLeafComponent<PixiTilingSprite, Pixi.TilingSpriteOptions>(\n PixiTilingSprite,\n);\n\n// export const MeshGeometry = createLeafComponent<PixiMeshGeometry, Pixi.MeshGeometryOptions>(PixiMeshGeometry);\n// export const NineSliceGeometry = createLeafComponent<PixiNineSliceGeometry, Pixi.NineSliceGeometryOptions>(\n// PixiNineSliceGeometry\n// );\n\n// export const Particle = createLeafComponent<PixiParticle, Pixi.ParticleOptions>(PixiParticle);\n// export const PerspectivePlaneGeometry = createLeafComponent<\n// PixiPerspectivePlaneGeometry,\n// Pixi.PerspectivePlaneGeometryOptions\n// >(PixiPerspectivePlaneGeometry);\n// export const PlaneGeometry = createLeafComponent<PixiPlaneGeometry, Pixi.PlaneGeometryOptions>(PixiPlaneGeometry);\n// export const RopeGeometry = createLeafComponent<PixiRopeGeometry, Pixi.RopeGeometryOptions>(PixiRopeGeometry);\n\n// TODO: Don't need a component for the Culler. It needs to interact with the stage directly.\n// export const Culler = createLeafComponent<PixiCuller, Pixi.Culler>(PixiCuller);\n"],"mappings":";;;;;;AAyCA,MAAaiD,kBAAkB;CAAC;CAAO;CAAM;CAAW;;;;;;;AAQxD,MAAaE,cAIXE,UACAC,UACG;AACH,MAAK,MAAME,OAAOF,OAAO;AACvB,MAAIE,QAAQ,KAAM;AAElB,MAAIA,QAAQ,MACVrB,0BAAyB;AAEtBmB,SAAME,KAAuCH,SAAS;IACvD;WACOG,QAAQ,YAAY;AAC7B,OAAI,EAAE,cAAcH,UAClB,OAAM,IAAIK,MAAM,iDAAiD;AAEnEvB,4BAAyB;AACvBI,WAAOc,gBAAgBC,MAAMT,SAAS;KACtC;QAEFV,0BAAyB;AACvBK,WAAQa,UAAUG,KAAKF,MAAME,KAA2B;IACxD;;;AAKR,IAAMG,4BACJC,cACG;AACH,SAAQN,UAAqF;EAC3F,MAAM,CAACO,cAAcC,uBAAuB1B,WAAWkB,OAAO,CAC5D,GAAGL,iBACH,GAAGX,yBACJ,CAAC;EAEF,MAAMe,WAAWC,MAAMV,MAAM,IAAIgB,UAAUE,oBAA2B;AAEtEX,aAAWE,UAAUS,oBAAoB;AACzCX,aAAWE,UAAUQ,aAAa;AAElC,SAAOR;;;AAIX,IAAMU,uBACJH,cACG;AACH,SAAQN,UAAgF;AACtF,SAAOK,yBAAqDC,UAAU,CAACN,MAAa;;;;;;;;;;;;AAaxF,MAAarD,mBAAiB8D,oBAC5B7D,eACD;;;;;;;;;;AAUD,MAAaC,eAAa4D,oBAAsD3D,WAAe;;;;;;;;AAQ/F,MAAaC,cAAYsD,yBACvBrD,UACD;;;;;;;;;;AAUD,MAAaC,aAAWwD,oBAAwDvD,SAAa;;;;;;;;;AAS7F,MAAaC,aAAWsD,oBAAwDrD,SAAa;;;;;;;;;AAU7F,MAAaC,cAAYoD,oBAA0DnD,UAAc;;;;;;;;;AAUjG,MAAaC,aAAWkD,oBAAwDjD,SAAa;;;;;;;;;AAU7F,MAAaC,eAAagD,oBACxB/C,WACD;;;;;;;;;AAUD,MAAaC,oBAAkB8C,oBAG7B7C,gBAAoB;;;;;;;;;AAUtB,MAAaC,sBAAoB4C,oBAG/B3C,kBAAsB;;;;;;;;;AAUxB,MAAaC,oBAAkB0C,oBAG7BzC,gBAAoB;;;;;;;;;AAUtB,MAAaC,oBAAkBoC,yBAG7BnC,gBAAoB;;;;;;;;;AAUtB,MAAaC,gBAAckC,yBACzBjC,YACD;;;;;;;;;AAUD,MAAaC,WAASoC,oBAAoDnC,OAAW;;;;;;;;;AASrF,MAAaC,SAAOkC,oBAAsDjC,KAAS;;;;;;;;;AAUnF,MAAaC,iBAAegC,oBAC1B/B,aACD"}
@@ -1,40 +1,42 @@
1
- export const PIXI_EVENT_NAMES = [
2
- "click",
3
- "mousedown",
4
- "mouseenter",
5
- "mouseleave",
6
- "mousemove",
7
- "mouseout",
8
- "mouseover",
9
- "mouseup",
10
- "mouseupoutside",
11
- "pointercancel",
12
- "pointerdown",
13
- "pointerenter",
14
- "pointerleave",
15
- "pointermove",
16
- "pointerout",
17
- "pointerover",
18
- "pointertap",
19
- "pointerup",
20
- "pointerupoutside",
21
- "rightclick",
22
- "rightdown",
23
- "rightup",
24
- "rightupoutside",
25
- "tap",
26
- "touchcancel",
27
- "touchend",
28
- "touchendoutside",
29
- "touchmove",
30
- "touchstart",
31
- "wheel",
32
- "globalmousemove",
33
- "globalpointermove",
34
- "globaltouchmove",
1
+ //#region src/pixi-events.ts
2
+ const PIXI_EVENT_NAMES = [
3
+ "click",
4
+ "mousedown",
5
+ "mouseenter",
6
+ "mouseleave",
7
+ "mousemove",
8
+ "mouseout",
9
+ "mouseover",
10
+ "mouseup",
11
+ "mouseupoutside",
12
+ "pointercancel",
13
+ "pointerdown",
14
+ "pointerenter",
15
+ "pointerleave",
16
+ "pointermove",
17
+ "pointerout",
18
+ "pointerover",
19
+ "pointertap",
20
+ "pointerup",
21
+ "pointerupoutside",
22
+ "rightclick",
23
+ "rightdown",
24
+ "rightup",
25
+ "rightupoutside",
26
+ "tap",
27
+ "touchcancel",
28
+ "touchend",
29
+ "touchendoutside",
30
+ "touchmove",
31
+ "touchstart",
32
+ "wheel",
33
+ "globalmousemove",
34
+ "globalpointermove",
35
+ "globaltouchmove"
35
36
  ];
36
- export const PIXI_EVENT_HANDLER_NAMES = PIXI_EVENT_NAMES.map((eventName) => `on${eventName}`);
37
- export const PIXI_EVENT_HANDLER_NAME_SET = new Set(PIXI_EVENT_HANDLER_NAMES);
38
- const allEventsAreHandled = true;
39
- void allEventsAreHandled;
37
+ const PIXI_EVENT_HANDLER_NAMES = PIXI_EVENT_NAMES.map((eventName) => `on${eventName}`);
38
+ const PIXI_EVENT_HANDLER_NAME_SET = new Set(PIXI_EVENT_HANDLER_NAMES);
39
+
40
+ //#endregion
41
+ export { PIXI_EVENT_HANDLER_NAMES, PIXI_EVENT_HANDLER_NAME_SET, PIXI_EVENT_NAMES };
40
42
  //# sourceMappingURL=pixi-events.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"pixi-events.js","sourceRoot":"","sources":["../src/pixi-events.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,gBAAgB,GAAmC;IAC9D,OAAO;IACP,WAAW;IACX,YAAY;IACZ,YAAY;IACZ,WAAW;IACX,UAAU;IACV,WAAW;IACX,SAAS;IACT,gBAAgB;IAChB,eAAe;IACf,aAAa;IACb,cAAc;IACd,cAAc;IACd,aAAa;IACb,YAAY;IACZ,aAAa;IACb,YAAY;IACZ,WAAW;IACX,kBAAkB;IAClB,YAAY;IACZ,WAAW;IACX,SAAS;IACT,gBAAgB;IAChB,KAAK;IACL,aAAa;IACb,UAAU;IACV,iBAAiB;IACjB,WAAW;IACX,YAAY;IACZ,OAAO;IACP,iBAAiB;IACjB,mBAAmB;IACnB,iBAAiB;CACT,CAAC;AAEX,MAAM,CAAC,MAAM,wBAAwB,GAAG,gBAAgB,CAAC,GAAG,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,KAAK,SAAS,EAAW,CAAC,CAAC;AAMvG,MAAM,CAAC,MAAM,2BAA2B,GAA6D,IAAI,GAAG,CAC1G,wBAAwB,CACzB,CAAC;AAQF,MAAM,mBAAmB,GAAwB,IAAI,CAAC;AACtD,KAAK,mBAAmB,CAAC"}
1
+ {"version":3,"file":"pixi-events.js","names":["PIXI_EVENT_NAMES: (keyof AllFederatedEventMap)[]","PIXI_EVENT_HANDLER_NAME_SET: Readonly<Set<(typeof PIXI_EVENT_HANDLER_NAMES)[number]>>","allEventsAreHandled: AllEventsAreHandled"],"sources":["../src/pixi-events.ts"],"sourcesContent":["import type { AllFederatedEventMap } from \"pixi.js\";\n\nexport const PIXI_EVENT_NAMES: (keyof AllFederatedEventMap)[] = [\n \"click\",\n \"mousedown\",\n \"mouseenter\",\n \"mouseleave\",\n \"mousemove\",\n \"mouseout\",\n \"mouseover\",\n \"mouseup\",\n \"mouseupoutside\",\n \"pointercancel\",\n \"pointerdown\",\n \"pointerenter\",\n \"pointerleave\",\n \"pointermove\",\n \"pointerout\",\n \"pointerover\",\n \"pointertap\",\n \"pointerup\",\n \"pointerupoutside\",\n \"rightclick\",\n \"rightdown\",\n \"rightup\",\n \"rightupoutside\",\n \"tap\",\n \"touchcancel\",\n \"touchend\",\n \"touchendoutside\",\n \"touchmove\",\n \"touchstart\",\n \"wheel\",\n \"globalmousemove\",\n \"globalpointermove\",\n \"globaltouchmove\",\n] as const;\n\nexport const PIXI_EVENT_HANDLER_NAMES = PIXI_EVENT_NAMES.map((eventName) => `on${eventName}` as const);\n\nexport type PixiEventHandlerMap = {\n [K in (typeof PIXI_EVENT_NAMES)[number] as `on${K}`]?: (event: AllFederatedEventMap[K]) => void;\n};\n\nexport const PIXI_EVENT_HANDLER_NAME_SET: Readonly<Set<(typeof PIXI_EVENT_HANDLER_NAMES)[number]>> = new Set(\n PIXI_EVENT_HANDLER_NAMES\n);\n\n/**\n * This is a type-safe check that ensures `PIXI_EVENT_NAMES` includes every key from Pixi's `AllFederatedEventMap` type.\n * It will cause a build error if any event names are missing.\n */\ntype MissingKeys = Exclude<keyof AllFederatedEventMap, (typeof PIXI_EVENT_NAMES)[number]>;\ntype AllEventsAreHandled = MissingKeys extends never ? true : `Error: Missing event keys: ${MissingKeys}`;\nconst allEventsAreHandled: AllEventsAreHandled = true;\nvoid allEventsAreHandled;\n"],"mappings":";AAEA,MAAaA,mBAAmD;CAC9D;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD;AAED,MAAa,2BAA2B,iBAAiB,KAAK,cAAc,KAAK,YAAqB;AAMtG,MAAaC,8BAAwF,IAAI,IACvG,yBACD"}
@@ -0,0 +1,31 @@
1
+ import { usePixiApp } from "./pixi-application.js";
2
+ import { applyProps } from "./pixi-components.js";
3
+ import { memo } from "solid-js/web";
4
+
5
+ //#region src/pixi-stage.tsx
6
+ /**
7
+ * PixiStage
8
+ *
9
+ * The root container for rendering Pixi display objects. This component
10
+ * uses the application stage (`pixiApp.stage`) as the mount point and
11
+ * applies props and event handlers to it.
12
+ *
13
+ * Props:
14
+ * - `ref` (optional): receives the stage container reference.
15
+ * - Event handler props (e.g. `onpointerdown`) are forwarded to the stage.
16
+ * - Any other container options supported by Pixi may be passed.
17
+ *
18
+ * Children passed to `PixiStage` are inserted into the application stage.
19
+ *
20
+ * **Example**
21
+ * {@includeCode ./examples/PixiStage.example.tsx}
22
+ */
23
+ const PixiStage = (props) => {
24
+ const pixiApp = usePixiApp();
25
+ applyProps(pixiApp.stage, props);
26
+ return memo(() => pixiApp.stage);
27
+ };
28
+
29
+ //#endregion
30
+ export { PixiStage };
31
+ //# sourceMappingURL=pixi-stage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pixi-stage.js","names":["Container","ContainerOptions","JSX","Ref","usePixiApp","applyProps","PixiEventHandlerMap","PixiStageProps","Omit","ref","children","Element","PixiStage","props","pixiApp","stage","_$memo"],"sources":["../src/pixi-stage.tsx"],"sourcesContent":["import type { Container, ContainerOptions } from \"pixi.js\";\nimport type { JSX, Ref } from \"solid-js\";\nimport { usePixiApp } from \"./pixi-application\";\nimport { applyProps } from \"./pixi-components\";\nimport type { PixiEventHandlerMap } from \"./pixi-events\";\n\nexport type PixiStageProps = PixiEventHandlerMap &\n Omit<ContainerOptions, \"children\"> & {\n ref?: Ref<Container>;\n children?: JSX.Element;\n };\n\n/**\n * PixiStage\n *\n * The root container for rendering Pixi display objects. This component\n * uses the application stage (`pixiApp.stage`) as the mount point and\n * applies props and event handlers to it.\n *\n * Props:\n * - `ref` (optional): receives the stage container reference.\n * - Event handler props (e.g. `onpointerdown`) are forwarded to the stage.\n * - Any other container options supported by Pixi may be passed.\n *\n * Children passed to `PixiStage` are inserted into the application stage.\n *\n * **Example**\n * {@includeCode ./examples/PixiStage.example.tsx}\n */\nexport const PixiStage = (props: PixiStageProps): JSX.Element => {\n const pixiApp = usePixiApp();\n\n applyProps(pixiApp.stage, props);\n\n return <>{pixiApp.stage}</>;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AA6BA,MAAaY,aAAaC,UAAuC;CAC/D,MAAMC,UAAUV,YAAY;AAE5BC,YAAWS,QAAQC,OAAOF,MAAM;AAEhC,QAAAG,WAAUF,QAAQC,MAAK"}
@@ -0,0 +1,59 @@
1
+ import { PIXI_EVENT_HANDLER_NAME_SET } from "./pixi-events.js";
2
+ import { createRenderer } from "./universal.js";
3
+ import { Text } from "pixi.js";
4
+
5
+ //#region src/renderer.tsx
6
+ const { effect, memo, createComponent, createElement, createTextNode, insertNode, insert, setProp, mergeProps, use, render, spread } = createRenderer({
7
+ createElement(name) {
8
+ throw new Error(`Cannot create element "${name}". Please import components directly from 'pixi-solid' and use them with a capital letter.`);
9
+ },
10
+ createTextNode(value) {
11
+ return new Text({ text: value });
12
+ },
13
+ replaceText(textNode, value) {
14
+ textNode.text = value;
15
+ },
16
+ setProperty(node, name, value, prev) {
17
+ if (PIXI_EVENT_HANDLER_NAME_SET.has(name)) {
18
+ const eventName = name.slice(2);
19
+ if (prev) node.removeEventListener(eventName, prev);
20
+ node.addEventListener(eventName, value);
21
+ return;
22
+ }
23
+ if (name in node) {
24
+ node[name] = value;
25
+ return;
26
+ }
27
+ },
28
+ insertNode(parent, node, anchor) {
29
+ if ("attach" in parent && typeof parent.attach === "function") {
30
+ parent.attach(node);
31
+ return;
32
+ }
33
+ if (!("addChildAt" in parent) || !("addChild" in parent) || typeof parent.addChild !== "function") throw new Error("Parent does not support children.");
34
+ if (anchor) parent.addChildAt(node, parent.children.indexOf(anchor));
35
+ else parent.addChild(node);
36
+ },
37
+ isTextNode(node) {
38
+ return node instanceof Text;
39
+ },
40
+ removeNode(_, node) {
41
+ node.removeFromParent();
42
+ node.destroy({ children: true });
43
+ },
44
+ getParentNode(node) {
45
+ return node?.parent ?? void 0;
46
+ },
47
+ getFirstChild(node) {
48
+ return node.children?.[0];
49
+ },
50
+ getNextSibling(node) {
51
+ if (!node.parent) return void 0;
52
+ const index = node.parent.children.indexOf(node);
53
+ return index > -1 ? node.parent.children[index + 1] : void 0;
54
+ }
55
+ });
56
+
57
+ //#endregion
58
+ export { insert, setProp };
59
+ //# sourceMappingURL=renderer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"renderer.js","names":["Container","PixiContainer","Text","PixiText","createRenderer","PIXI_EVENT_NAMES","PixiEventHandlerMap","PIXI_EVENT_HANDLER_NAME_SET","effect","memo","createComponent","createElement","createTextNode","insertNode","insert","setProp","mergeProps","use","render","spread","name","Error","value","text","replaceText","textNode","setProperty","node","prev","has","eventName","slice","removeEventListener","addEventListener","parent","anchor","attach","addChild","addChildAt","children","indexOf","isTextNode","removeNode","_","removeFromParent","destroy","getParentNode","undefined","getFirstChild","getNextSibling","index"],"sources":["../src/renderer.tsx"],"sourcesContent":["import type { Container as PixiContainer } from \"pixi.js\";\nimport { Text as PixiText } from \"pixi.js\";\nimport { createRenderer } from \"solid-js/universal\";\nimport type { PIXI_EVENT_NAMES, PixiEventHandlerMap } from \"./pixi-events\";\nimport { PIXI_EVENT_HANDLER_NAME_SET } from \"./pixi-events\";\n\nexport const {\n effect,\n memo,\n createComponent,\n createElement,\n createTextNode,\n insertNode,\n insert,\n setProp,\n mergeProps,\n use,\n render,\n spread,\n} = createRenderer<PixiContainer>({\n createElement(name: string) {\n // This function is for lowercase string tags like `<container />`.\n // To support tree-shaking, we require users to import components\n // directly and use them with an uppercase name like `<Container />`,\n // which does not call this function.\n throw new Error(\n `Cannot create element \"${name}\". Please import components directly from 'pixi-solid' and use them with a capital letter.`,\n );\n },\n createTextNode(value) {\n return new PixiText({ text: value });\n },\n replaceText(textNode: PixiText, value) {\n textNode.text = value;\n },\n setProperty(node, name, value, prev) {\n // Check for event listeners and handle them appropriately.\n if (PIXI_EVENT_HANDLER_NAME_SET.has(name as keyof PixiEventHandlerMap)) {\n // Remove the 'on' prefix to get the actual event name.\n const eventName = name.slice(2) as (typeof PIXI_EVENT_NAMES)[number];\n\n if (prev) {\n node.removeEventListener(eventName, prev as any);\n }\n node.addEventListener(eventName, value as any);\n return;\n }\n\n if (name in node) {\n (node as any)[name] = value;\n return;\n }\n },\n insertNode(parent, node, anchor) {\n // RenderLayer uses `attach` instead of `addChild`.\n if (\"attach\" in parent && typeof parent.attach === \"function\") {\n parent.attach(node);\n // Note: `attach` does not support anchoring, so we ignore the anchor.\n return;\n }\n\n if (\n !(\"addChildAt\" in parent) ||\n !(\"addChild\" in parent) ||\n typeof parent.addChild !== \"function\"\n ) {\n throw new Error(\"Parent does not support children.\");\n }\n\n if (anchor) {\n parent.addChildAt(node, parent.children.indexOf(anchor));\n } else {\n parent.addChild(node);\n }\n },\n isTextNode(node) {\n return node instanceof PixiText;\n },\n removeNode(_, node) {\n node.removeFromParent();\n node.destroy({ children: true });\n },\n getParentNode(node) {\n return node?.parent ?? undefined;\n },\n getFirstChild(node) {\n return node.children?.[0];\n },\n getNextSibling(node) {\n if (!node.parent) return undefined;\n const index = node.parent.children.indexOf(node);\n // Return the next child if it exists, otherwise undefined.\n return index > -1 ? node.parent.children[index + 1] : undefined;\n },\n});\n"],"mappings":";;;;;AAMA,MAAa,EACXQ,QACAC,MACAC,iBACAC,eACAC,gBACAC,YACAC,QACAC,SACAC,YACAC,KACAC,QACAC,WACEf,eAA8B;CAChCO,cAAcS,MAAc;AAK1B,QAAM,IAAIC,MACR,0BAA0BD,KAAI,4FAC/B;;CAEHR,eAAeU,OAAO;AACpB,SAAO,IAAInB,KAAS,EAAEoB,MAAMD,OAAO,CAAC;;CAEtCE,YAAYC,UAAoBH,OAAO;AACrCG,WAASF,OAAOD;;CAElBI,YAAYC,MAAMP,MAAME,OAAOM,MAAM;AAEnC,MAAIrB,4BAA4BsB,IAAIT,KAAkC,EAAE;GAEtE,MAAMU,YAAYV,KAAKW,MAAM,EAAE;AAE/B,OAAIH,KACFD,MAAKK,oBAAoBF,WAAWF,KAAY;AAElDD,QAAKM,iBAAiBH,WAAWR,MAAa;AAC9C;;AAGF,MAAIF,QAAQO,MAAM;AACfA,QAAaP,QAAQE;AACtB;;;CAGJT,WAAWqB,QAAQP,MAAMQ,QAAQ;AAE/B,MAAI,YAAYD,UAAU,OAAOA,OAAOE,WAAW,YAAY;AAC7DF,UAAOE,OAAOT,KAAK;AAEnB;;AAGF,MACE,EAAE,gBAAgBO,WAClB,EAAE,cAAcA,WAChB,OAAOA,OAAOG,aAAa,WAE3B,OAAM,IAAIhB,MAAM,oCAAoC;AAGtD,MAAIc,OACFD,QAAOI,WAAWX,MAAMO,OAAOK,SAASC,QAAQL,OAAO,CAAC;MAExDD,QAAOG,SAASV,KAAK;;CAGzBc,WAAWd,MAAM;AACf,SAAOA,gBAAgBxB;;CAEzBuC,WAAWC,GAAGhB,MAAM;AAClBA,OAAKiB,kBAAkB;AACvBjB,OAAKkB,QAAQ,EAAEN,UAAU,MAAM,CAAC;;CAElCO,cAAcnB,MAAM;AAClB,SAAOA,MAAMO,UAAUa;;CAEzBC,cAAcrB,MAAM;AAClB,SAAOA,KAAKY,WAAW;;CAEzBU,eAAetB,MAAM;AACnB,MAAI,CAACA,KAAKO,OAAQ,QAAOa;EACzB,MAAMG,QAAQvB,KAAKO,OAAOK,SAASC,QAAQb,KAAK;AAEhD,SAAOuB,QAAQ,KAAKvB,KAAKO,OAAOK,SAASW,QAAQ,KAAKH;;CAEzD,CAAC"}