pixi-solid 0.0.16 → 0.0.19
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.
- package/README.md +5 -5
- package/dist/index.js +8 -9
- package/dist/{use-resize.js → on-resize.js} +5 -5
- package/dist/on-resize.js.map +1 -0
- package/dist/pixi-application.js +14 -14
- package/dist/pixi-application.js.map +1 -1
- package/dist/pixi-canvas.js +2 -2
- package/dist/pixi-canvas.js.map +1 -1
- package/dist/pixi-components.js +1 -3
- package/dist/pixi-components.js.map +1 -1
- package/dist/pixi-stage.js +2 -2
- package/dist/pixi-stage.js.map +1 -1
- package/dist/types/index.d.ts +3 -3
- package/dist/types/{use-resize.d.ts → on-resize.d.ts} +1 -1
- package/dist/types/pixi-application.d.ts +12 -12
- package/dist/types/pixi-components.d.ts +1 -5
- package/package.json +1 -1
- package/dist/use-resize.js.map +0 -1
package/README.md
CHANGED
|
@@ -17,7 +17,7 @@ By using `pixi-solid`, you can write your PixiJS applications declaratively usin
|
|
|
17
17
|
It is intended to provide nice abstractions for encapsulating useful functionality and state management to represent the core logic of your application.
|
|
18
18
|
|
|
19
19
|
In some cases when creating high performance applications like games which may have lots of fast changing state and logic every frame it may be beneficial to escape from SolidJS and use Pixi imperatively.
|
|
20
|
-
In these cases you may want to create an imperative component and update it every frame with the `
|
|
20
|
+
In these cases you may want to create an imperative component and update it every frame with the `onTick` method and then wrap it inside a `<Container />` component as an easy way of packaging it.
|
|
21
21
|
|
|
22
22
|
## Getting Started
|
|
23
23
|
|
|
@@ -41,7 +41,7 @@ Here's a simple example to get you started. This will render a "Hello World" tex
|
|
|
41
41
|
|
|
42
42
|
```jsx
|
|
43
43
|
import { render } from "solid-js/web";
|
|
44
|
-
import { PixiApplication, PixiStage,
|
|
44
|
+
import { PixiApplication, PixiStage, getPixiApp } from "pixi-solid";
|
|
45
45
|
import { Text, FederatedPointerEvent } from "pixi.js";
|
|
46
46
|
import { createSignal, onMount } from "solid-js";
|
|
47
47
|
|
|
@@ -93,15 +93,15 @@ This component creates a `div` and mounts the PixiJS canvas into it. It automati
|
|
|
93
93
|
|
|
94
94
|
This component gives us a reference to the Pixi stage which is the top level container of your scene. It is useful for listening to global events.
|
|
95
95
|
|
|
96
|
-
### `
|
|
96
|
+
### `getPixiApp()`
|
|
97
97
|
|
|
98
98
|
A hook to get access to the PixiJS `Application` instance.
|
|
99
99
|
|
|
100
|
-
### `
|
|
100
|
+
### `getTicker()`
|
|
101
101
|
|
|
102
102
|
A hook to get access to the Pixi ticker instance.
|
|
103
103
|
|
|
104
|
-
### `
|
|
104
|
+
### `onTick()`
|
|
105
105
|
|
|
106
106
|
A hook to auto subscribe and unsubscribe to the ticker in sync with the components lifecycle.
|
|
107
107
|
Any function passed in here will be called every frame whilst the component is mounted.
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { onResize } from "./on-resize.js";
|
|
2
|
+
import { PixiApplication, TickerProvider, delay, getPixiApp, getTicker, onTick } from "./pixi-application.js";
|
|
2
3
|
import { PixiCanvas } from "./pixi-canvas.js";
|
|
3
|
-
import { AnimatedSprite, BitmapText, Container, Graphics, HTMLText, MeshPlane, MeshRope,
|
|
4
|
+
import { AnimatedSprite, BitmapText, Container, Graphics, HTMLText, MeshPlane, MeshRope, NineSliceSprite, ParticleContainer, PerspectiveMesh, RenderContainer, RenderLayer, Sprite, Text, TilingSprite } from "./pixi-components.js";
|
|
4
5
|
import { PIXI_EVENT_NAMES, PIXI_SOLID_EVENT_HANDLER_NAMES } from "./pixi-events.js";
|
|
5
6
|
import { PixiStage } from "./pixi-stage.js";
|
|
6
|
-
import { useResize } from "./use-resize.js";
|
|
7
7
|
export {
|
|
8
8
|
AnimatedSprite,
|
|
9
9
|
BitmapText,
|
|
@@ -12,7 +12,6 @@ export {
|
|
|
12
12
|
HTMLText,
|
|
13
13
|
MeshPlane,
|
|
14
14
|
MeshRope,
|
|
15
|
-
MeshSimple,
|
|
16
15
|
NineSliceSprite,
|
|
17
16
|
PIXI_EVENT_NAMES,
|
|
18
17
|
PIXI_SOLID_EVENT_HANDLER_NAMES,
|
|
@@ -27,10 +26,10 @@ export {
|
|
|
27
26
|
Text,
|
|
28
27
|
TickerProvider,
|
|
29
28
|
TilingSprite,
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
29
|
+
delay,
|
|
30
|
+
getPixiApp,
|
|
31
|
+
getTicker,
|
|
32
|
+
onResize,
|
|
33
|
+
onTick
|
|
35
34
|
};
|
|
36
35
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { onCleanup } from "solid-js";
|
|
2
|
-
import {
|
|
3
|
-
const
|
|
4
|
-
const app =
|
|
2
|
+
import { getPixiApp } from "./pixi-application.js";
|
|
3
|
+
const onResize = (resizeCallback) => {
|
|
4
|
+
const app = getPixiApp();
|
|
5
5
|
const handleResize = () => {
|
|
6
6
|
resizeCallback(app.renderer.screen);
|
|
7
7
|
};
|
|
@@ -12,6 +12,6 @@ const useResize = (resizeCallback) => {
|
|
|
12
12
|
});
|
|
13
13
|
};
|
|
14
14
|
export {
|
|
15
|
-
|
|
15
|
+
onResize
|
|
16
16
|
};
|
|
17
|
-
//# sourceMappingURL=
|
|
17
|
+
//# sourceMappingURL=on-resize.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"on-resize.js","sources":["../src/on-resize.ts"],"sourcesContent":["import type * as Pixi from \"pixi.js\";\nimport { onCleanup } from \"solid-js\";\nimport { getPixiApp } from \"./pixi-application\";\n\n/**\n * A SolidJS hook that runs a callback function whenever the PixiJS renderer is resized.\n *\n * @param resizeCallback A callback function that receives the updated screen dimensions as a `Pixi.Rectangle` object. This function will be called immediately upon hook initialization and then on every subsequent resize event.\n *\n * Because we listen for the renderer's \"resize\" event, this hook will work correctly whether the window is resized or just the DOM element the PixiCanvas is inside changes size.\n */\nexport const onResize = (resizeCallback: (screen: Pixi.Rectangle) => void): void => {\n const app = getPixiApp();\n\n const handleResize = () => {\n resizeCallback(app.renderer.screen);\n };\n\n handleResize();\n\n app.renderer.addListener(\"resize\", handleResize);\n\n onCleanup(() => {\n app.renderer.removeListener(\"resize\", handleResize);\n });\n};\n"],"names":[],"mappings":";;AAWO,MAAM,WAAW,CAAC,mBAA2D;AAClF,QAAM,MAAM,WAAA;AAEZ,QAAM,eAAe,MAAM;AACzB,mBAAe,IAAI,SAAS,MAAM;AAAA,EACpC;AAEA,eAAA;AAEA,MAAI,SAAS,YAAY,UAAU,YAAY;AAE/C,YAAU,MAAM;AACd,QAAI,SAAS,eAAe,UAAU,YAAY;AAAA,EACpD,CAAC;AACH;"}
|
package/dist/pixi-application.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { createComponent } from "solid-js/web";
|
|
2
|
-
import { Application } from "pixi.js";
|
|
2
|
+
import { Ticker, Application } from "pixi.js";
|
|
3
3
|
import { createContext, useContext, splitProps, createResource, createEffect, onCleanup, Show } from "solid-js";
|
|
4
4
|
const PixiAppContext = createContext();
|
|
5
|
-
const TickerContext = createContext();
|
|
6
|
-
const
|
|
5
|
+
const TickerContext = createContext(Ticker.shared);
|
|
6
|
+
const getPixiApp = () => {
|
|
7
7
|
const app = useContext(PixiAppContext);
|
|
8
8
|
if (!app) {
|
|
9
|
-
throw new Error("
|
|
9
|
+
throw new Error("getPixiApp must be used within a PixiApplication");
|
|
10
10
|
}
|
|
11
11
|
return app;
|
|
12
12
|
};
|
|
@@ -68,27 +68,27 @@ const TickerProvider = (props) => {
|
|
|
68
68
|
}
|
|
69
69
|
});
|
|
70
70
|
};
|
|
71
|
-
const
|
|
71
|
+
const getTicker = () => {
|
|
72
72
|
const ticker = useContext(TickerContext);
|
|
73
73
|
if (!ticker) {
|
|
74
|
-
throw new Error("
|
|
74
|
+
throw new Error("getTicker must be used within a PixiApplication or a TickerProvider");
|
|
75
75
|
}
|
|
76
76
|
return ticker;
|
|
77
77
|
};
|
|
78
|
-
const
|
|
78
|
+
const onTick = (tickerCallback) => {
|
|
79
79
|
const ticker = useContext(TickerContext);
|
|
80
80
|
if (!ticker) {
|
|
81
|
-
throw new Error("
|
|
81
|
+
throw new Error("onTick must be used within a PixiApplication or a TickerProvider");
|
|
82
82
|
}
|
|
83
83
|
ticker.add(tickerCallback);
|
|
84
84
|
onCleanup(() => {
|
|
85
85
|
ticker.remove(tickerCallback);
|
|
86
86
|
});
|
|
87
87
|
};
|
|
88
|
-
const
|
|
88
|
+
const delay = async (delayMs, callback) => {
|
|
89
89
|
const ticker = useContext(TickerContext);
|
|
90
90
|
if (!ticker) {
|
|
91
|
-
throw new Error("
|
|
91
|
+
throw new Error("delay must be used within a PixiApplication or a TickerProvider");
|
|
92
92
|
}
|
|
93
93
|
let timeDelayed = 0;
|
|
94
94
|
let resolvePromise;
|
|
@@ -108,9 +108,9 @@ const useDelay = async (delayMs, callback) => {
|
|
|
108
108
|
export {
|
|
109
109
|
PixiApplication,
|
|
110
110
|
TickerProvider,
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
111
|
+
delay,
|
|
112
|
+
getPixiApp,
|
|
113
|
+
getTicker,
|
|
114
|
+
onTick
|
|
115
115
|
};
|
|
116
116
|
//# sourceMappingURL=pixi-application.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pixi-application.js","sources":["../src/pixi-application.tsx"],"sourcesContent":["import type { ApplicationOptions,
|
|
1
|
+
{"version":3,"file":"pixi-application.js","sources":["../src/pixi-application.tsx"],"sourcesContent":["import type { ApplicationOptions, TickerCallback } from \"pixi.js\";\nimport { Application, Ticker } from \"pixi.js\";\nimport type { JSX, ParentProps, Ref } from \"solid-js\";\nimport { createContext, createEffect, createResource, onCleanup, Show, splitProps, useContext } from \"solid-js\";\n\nconst PixiAppContext = createContext<Application>();\nconst TickerContext = createContext<Ticker>(Ticker.shared);\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 */\nexport const getPixiApp = () => {\n const app = useContext(PixiAppContext);\n if (!app) {\n throw new Error(\"getPixiApp 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<Omit<ApplicationOptions, \"children\" | \"resizeTo\">> & {\n ref?: Ref<Application>;\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 `getPixiApp`, `onTick`, and `getTicker`.\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 */\nexport const PixiApplication = (props: PixiApplicationProps) => {\n const [, initialisationProps] = splitProps(props, [\"ref\", \"children\"]);\n\n // TODO: Split props into initialisation props and runtime props\n\n const [appResource] = createResource(async () => {\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);\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 onCleanup(() => {\n app.destroy(true, { children: true });\n });\n }\n });\n\n return (\n <Show when={appResource()}>\n {(app) => (\n <PixiAppContext.Provider value={app()}>\n <TickerContext.Provider value={app().ticker}>{props.children}</TickerContext.Provider>\n </PixiAppContext.Provider>\n )}\n </Show>\n );\n};\n\nexport type TickerProviderProps = ParentProps<{ ticker: Ticker }>;\n\n/**\n * This is only required if you want a ticker without the Application.\n * It provides context for the `onTick` and `getTicker` hooks so we can run tests that use them without having to instantate a Pixi Application.\n *\n * You need to pass in the ticker instance you want to use so it can be manually controled form the outside for testing.\n */\nexport const TickerProvider = (props: TickerProviderProps) => {\n return <TickerContext.Provider value={props.ticker}>{props.children}</TickerContext.Provider>;\n};\n\n/**\n * getTicker\n *\n * A custom SolidJS hook that provides access to the PIXI.Application's shared Ticker instance.\n * This hook must be called from a component that is a descendant of `PixiApplication`.\n * Or a descendant of `TickerProvider` if being used for testing without an application.\n *\n * @returns The PIXI.Ticker instance from the application context.\n * @throws Will throw an error if used outside of a `PixiApplication` or `TickerProvider` context.\n */\nexport const getTicker = (): Ticker => {\n const ticker = useContext(TickerContext);\n if (!ticker) {\n throw new Error(\"getTicker must be used within a PixiApplication or a TickerProvider\");\n }\n return ticker;\n};\n\n/**\n * onTick\n *\n * A custom SolidJS hook that registers a callback function to be executed on every frame\n * of the PIXI.Application's ticker. The callback is automatically removed when the\n * component or hook's owning computation is cleaned up.\n *\n * This hook must be called from a component that is a descendant of `PixiApplication`.\n * Or a descendant of `TickerProvider` if being used for testing without an application.\n *\n * @param tickerCallback - The function to call on each ticker update. It receives\n * the `PIXI.Ticker` instance as its argument.\n *\n */\nexport const onTick = (tickerCallback: TickerCallback<Ticker>): void => {\n const ticker = useContext(TickerContext);\n\n if (!ticker) {\n throw new Error(\"onTick must be used within a PixiApplication or a TickerProvider\");\n }\n\n ticker.add(tickerCallback);\n onCleanup(() => {\n ticker.remove(tickerCallback);\n });\n};\n\n/**\n * Delay until a given number of milliseconds has passed on the shared ticker.\n *\n * It is guaranteed to be in sync with the shared ticker and uses accumulated deltaMs not an external time measurement.\n *\n * Simply await for it to resolve if in an async context or pass in a callback function.\n * It's not recommended to use both techniques at once.\n *\n * @param delayMs - Number of milliseconds to wait (measured in the ticker's time units).\n *\n * @param callback - Optional callback function that will fire when the delayMs time has passed.\n *\n * @returns A Promise that resolves once the ticker's time has advanced by `delayMs`.\n *\n * @throws {Error} If called outside of a `PixiApplication` or `TickerProvider` context.\n *\n * @note It will not resolve or fire the callback if the ticker is paused or stopped.\n *\n */\nexport const delay = async (delayMs: number, callback?: () => void): Promise<void> => {\n const ticker = useContext(TickerContext);\n\n if (!ticker) {\n throw new Error(\"delay must be used within a PixiApplication or a TickerProvider\");\n }\n\n let timeDelayed = 0;\n\n let resolvePromise: (value: void | PromiseLike<void>) => void;\n\n const promise = new Promise<void>((resolve) => {\n resolvePromise = resolve;\n });\n\n const internalCallback = () => {\n timeDelayed += ticker.deltaMS;\n if (timeDelayed < delayMs) return;\n callback?.();\n resolvePromise();\n };\n\n ticker.add(internalCallback);\n\n await promise;\n\n ticker.remove(internalCallback);\n};\n"],"names":["PixiAppContext","createContext","TickerContext","Ticker","shared","getPixiApp","app","useContext","Error","PixiApplication","props","initialisationProps","splitProps","appResource","createResource","Application","init","autoDensity","resolution","Math","min","window","devicePixelRatio","sharedTicker","createEffect","ref","ticker","autoStart","start","onCleanup","destroy","children","_$createComponent","Show","when","Provider","value","TickerProvider","getTicker","onTick","tickerCallback","add","remove","delay","delayMs","callback","timeDelayed","resolvePromise","promise","Promise","resolve","internalCallback","deltaMS"],"mappings":";;;AAKA,MAAMA,iBAAiBC,cAAAA;AACvB,MAAMC,gBAAgBD,cAAsBE,OAAOC,MAAM;AASlD,MAAMC,aAAaA,MAAM;AAC9B,QAAMC,MAAMC,WAAWP,cAAc;AACrC,MAAI,CAACM,KAAK;AACR,UAAM,IAAIE,MAAM,kDAAkD;AAAA,EACpE;AACA,SAAOF;AACT;AAsBO,MAAMG,kBAAkBA,CAACC,UAAgC;AAC9D,QAAM,CAAA,EAAGC,mBAAmB,IAAIC,WAAWF,OAAO,CAAC,OAAO,UAAU,CAAC;AAIrE,QAAM,CAACG,WAAW,IAAIC,eAAe,YAAY;AAC/C,UAAMR,MAAM,IAAIS,YAAAA;AAChB,UAAMT,IAAIU,KAAK;AAAA,MACb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a;AACvC,MAAI,CAACwB,QAAQ;AACX,UAAM,IAAIlB,MAAM,qEAAqE;AAAA,EACvF;AACA,SAAOkB;AACT;AAgBO,MAAMa,SAASA,CAACC,mBAAiD;AACtE,QAAMd,SAASnB,WAAWL,aAAa;AAEvC,MAAI,CAACwB,QAAQ;AACX,UAAM,IAAIlB,MAAM,kEAAkE;AAAA,EACpF;AAEAkB,SAAOe,IAAID,cAAc;AACzBX,YAAU,MAAM;AACdH,WAAOgB,OAAOF,cAAc;AAAA,EAC9B,CAAC;AACH;AAqBO,MAAMG,QAAQ,OAAOC,SAAiBC,aAAyC;AACpF,QAAMnB,SAASnB,WAAWL,aAAa;AAEvC,MAAI,CAACwB,QAAQ;AACX,UAAM,IAAIlB,MAAM,iEAAiE;AAAA,EACnF;AAEA,MAAIsC,cAAc;AAElB,MAAIC;AAEJ,QAAMC,UAAU,IAAIC,QAAeC,CAAAA,YAAY;AAC7CH,qBAAiBG;AAAAA,EACnB,CAAC;AAED,QAAMC,mBAAmBA,MAAM;AAC7BL,mBAAepB,OAAO0B;AACtB,QAAIN,cAAcF,QAAS;AAC3BC,eAAAA;AACAE,mBAAAA;AAAAA,EACF;AAEArB,SAAOe,IAAIU,gBAAgB;AAE3B,QAAMH;AAENtB,SAAOgB,OAAOS,gBAAgB;AAChC;"}
|
package/dist/pixi-canvas.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { template, insert, effect, style, className, use } from "solid-js/web";
|
|
2
2
|
import { createRenderEffect, onMount, onCleanup } from "solid-js";
|
|
3
|
-
import {
|
|
3
|
+
import { getPixiApp } from "./pixi-application.js";
|
|
4
4
|
var _tmpl$ = /* @__PURE__ */ template(`<div style=position:relative>`);
|
|
5
5
|
const PixiCanvas = (props) => {
|
|
6
6
|
let canvasWrapElement;
|
|
7
|
-
const pixiApp =
|
|
7
|
+
const pixiApp = getPixiApp();
|
|
8
8
|
pixiApp.canvas.style.display = "block";
|
|
9
9
|
pixiApp.canvas.style.position = "absolute";
|
|
10
10
|
pixiApp.canvas.style.top = "0";
|
package/dist/pixi-canvas.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pixi-canvas.js","sources":["../src/pixi-canvas.tsx"],"sourcesContent":["import type { JSX } from \"solid-js\";\nimport { createRenderEffect, onCleanup, onMount } from \"solid-js\";\nimport {
|
|
1
|
+
{"version":3,"file":"pixi-canvas.js","sources":["../src/pixi-canvas.tsx"],"sourcesContent":["import type { JSX } from \"solid-js\";\nimport { createRenderEffect, onCleanup, onMount } from \"solid-js\";\nimport { getPixiApp } 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` component.\n * - Requires a `PixiStage` component as a child.\n *\n * Props:\n * @param props.children - JSX content to render inside the canvas wrapper. Use `PixiStage` as the only child.\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 = getPixiApp();\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 position: \"relative\",\n ...(typeof props.style === \"object\" ? props.style : {}),\n }}\n class={props.className}\n >\n {pixiApp.canvas}\n </div>\n );\n};\n"],"names":["PixiCanvas","props","canvasWrapElement","pixiApp","getPixiApp","canvas","style","display","position","top","left","width","height","createRenderEffect","children","undefined","Error","previousResizeTo","resizeObserver","onMount","resizeTo","queueResize","ResizeObserver","observe","onCleanup","disconnect","_el$","_tmpl$","_ref$","_$use","_$insert","_$effect","_p$","_v$","_v$2","className","e","_$style","t","_$className"],"mappings":";;;;AAiBO,MAAMA,aAAaA,CAACC,UAIR;AACjB,MAAIC;AAEJ,QAAMC,UAAUC,WAAAA;AAChBD,UAAQE,OAAOC,MAAMC,UAAU;AAC/BJ,UAAQE,OAAOC,MAAME,WAAW;AAChCL,UAAQE,OAAOC,MAAMG,MAAM;AAC3BN,UAAQE,OAAOC,MAAMI,OAAO;AAC5BP,UAAQE,OAAOC,MAAMK,QAAQ;AAC7BR,UAAQE,OAAOC,MAAMM,SAAS;AAE9BC,qBAAmB,MAAM;AACvB,QAAIZ,MAAMa,aAAaC,QAAW;AAChC,YAAM,IAAIC,MAAM,0DAA0D;AAAA,IAC5E;AAAA,EACF,CAAC;AAED,MAAIC;AACJ,MAAIC;AAEJC,UAAQ,MAAM;AACZ,QAAI,CAACjB,kBAAmB;AACxBe,uBAAmBd,QAAQiB;AAC3BjB,YAAQiB,WAAWlB;AACnBC,YAAQkB,YAAAA;AACRH,qBAAiB,IAAII,eAAe,MAAM;AACxCnB,cAAQkB,YAAAA;AAAAA,IACV,CAAC;AACDH,mBAAeK,QAAQrB,iBAAiB;AAAA,EAC1C,CAAC;AAEDsB,YAAU,MAAM;AACd,QAAI,CAACtB,kBAAmB;AACxBC,YAAQiB,WAAWH;AACnBC,oBAAgBO,WAAAA;AAChBP,qBAAiBH;AAAAA,EACnB,CAAC;AAED,UAAA,MAAA;AAAA,QAAAW,OAAAC,OAAAA;AAAA,QAAAC,QAES1B;AAAiB,WAAA0B,UAAA,aAAAC,IAAAD,OAAAF,IAAA,IAAjBxB,oBAAiBwB;AAAAI,WAAAJ,MAAA,MAOrBvB,QAAQE,MAAM;AAAA0B,WAAAC,CAAAA,QAAA;AAAA,UAAAC,MANR;AAAA,QAEL,GAAI,OAAOhC,MAAMK,UAAU,WAAWL,MAAMK,QAAQ,CAAA;AAAA,MAAC,GACtD4B,OACMjC,MAAMkC;AAASH,UAAAI,IAAAC,MAAAX,MAAAO,KAAAD,IAAAI,CAAA;AAAAF,eAAAF,IAAAM,KAAAC,UAAAb,MAAAM,IAAAM,IAAAJ,IAAA;AAAA,aAAAF;AAAAA,IAAA,GAAA;AAAA,MAAAI,GAAArB;AAAAA,MAAAuB,GAAAvB;AAAAA,IAAAA,CAAA;AAAA,WAAAW;AAAAA,EAAA,GAAA;AAK5B;"}
|
package/dist/pixi-components.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { RenderContainer as RenderContainer$1, RenderLayer as RenderLayer$1, AnimatedSprite as AnimatedSprite$1, BitmapText as BitmapText$1, Container as Container$1, Graphics as Graphics$1, HTMLText as HTMLText$1, MeshPlane as MeshPlane$1, MeshRope as MeshRope$1,
|
|
1
|
+
import { RenderContainer as RenderContainer$1, RenderLayer as RenderLayer$1, AnimatedSprite as AnimatedSprite$1, BitmapText as BitmapText$1, Container as Container$1, Graphics as Graphics$1, HTMLText as HTMLText$1, MeshPlane as MeshPlane$1, MeshRope as MeshRope$1, NineSliceSprite as NineSliceSprite$1, ParticleContainer as ParticleContainer$1, PerspectiveMesh as PerspectiveMesh$1, Sprite as Sprite$1, Text as Text$1, TilingSprite as TilingSprite$1 } from "pixi.js";
|
|
2
2
|
import { splitProps, createRenderEffect, on } from "solid-js";
|
|
3
3
|
import { PIXI_SOLID_EVENT_HANDLER_NAMES } from "./pixi-events.js";
|
|
4
4
|
import { insert, setProp } from "./renderer.js";
|
|
@@ -51,7 +51,6 @@ const Graphics = createLeafComponent(Graphics$1);
|
|
|
51
51
|
const HTMLText = createLeafComponent(HTMLText$1);
|
|
52
52
|
const MeshPlane = createLeafComponent(MeshPlane$1);
|
|
53
53
|
const MeshRope = createLeafComponent(MeshRope$1);
|
|
54
|
-
const MeshSimple = createLeafComponent(MeshSimple$1);
|
|
55
54
|
const NineSliceSprite = createLeafComponent(NineSliceSprite$1);
|
|
56
55
|
const ParticleContainer = createLeafComponent(ParticleContainer$1);
|
|
57
56
|
const PerspectiveMesh = createLeafComponent(PerspectiveMesh$1);
|
|
@@ -68,7 +67,6 @@ export {
|
|
|
68
67
|
HTMLText,
|
|
69
68
|
MeshPlane,
|
|
70
69
|
MeshRope,
|
|
71
|
-
MeshSimple,
|
|
72
70
|
NineSliceSprite,
|
|
73
71
|
ParticleContainer,
|
|
74
72
|
PerspectiveMesh,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pixi-components.js","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, on, splitProps } from \"solid-js\";\nimport type { PixiEventHandlerMap } from \"./pixi-events\";\n\nimport { PIXI_SOLID_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 * @param defer Defers the createRenderEffect so the props aren't set on the first run.\n * This is useful because setting initialisation props can have unintended side effects.\n * Notibly in AnimatedSprite, if we set the textures roperty after instantiation it will stop the instance from playing.\n */\nexport const applyProps = <InstanceType extends PixiContainer, OptionsType extends ContainerProps<InstanceType>>(\n instance: InstanceType,\n props: OptionsType,\n defer?: boolean\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 if (defer) {\n createRenderEffect(\n on(\n () => props[key as keyof typeof props],\n () => {\n setProp(instance, key, props[key as keyof typeof props]);\n },\n { defer }\n )\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>): InstanceType & JSX.Element => {\n const [runtimeProps, initialisationProps] = splitProps(props, [\n ...SOLID_PROP_KEYS,\n ...PIXI_SOLID_EVENT_HANDLER_NAMES,\n ]);\n\n const instance = props.as || new PixiClass(initialisationProps as any);\n\n applyProps(instance, initialisationProps, true);\n applyProps(instance, runtimeProps);\n\n return instance as InstanceType & 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>): InstanceType & JSX.Element => {\n return createContainerComponent<InstanceType, OptionsType>(PixiClass)(props);\n };\n};\n\n/**\n * A SolidJS component that renders a `PIXI.AnimatedSprite`.\n */\nexport const AnimatedSprite = createLeafComponent<PixiAnimatedSprite, Pixi.AnimatedSpriteOptions>(PixiAnimatedSprite);\n/**\n * A SolidJS component that renders a `PIXI.BitmapText`.\n */\nexport const BitmapText = createLeafComponent<PixiBitmapText, ConstructorParameters<typeof PixiBitmapText>>(\n PixiBitmapText\n);\n/**\n * A SolidJS component that renders a `PIXI.Container`.\n */\nexport const Container = createContainerComponent<PixiContainer, Pixi.ContainerOptions>(PixiContainer);\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 */\nexport const Graphics = createLeafComponent<PixiGraphics, Pixi.GraphicsOptions>(PixiGraphics);\n/**\n * A SolidJS component that renders a `PIXI.HTMLText`.\n */\nexport const HTMLText = createLeafComponent<PixiHTMLText, Pixi.HTMLTextOptions>(PixiHTMLText);\n\n/**\n * A SolidJS component that renders a `PIXI.MeshPlane`.\n */\nexport const MeshPlane = createLeafComponent<PixiMeshPlane, Pixi.MeshPlaneOptions>(PixiMeshPlane);\n\n/**\n * A SolidJS component that renders a `PIXI.MeshRope`.\n */\nexport const MeshRope = createLeafComponent<PixiMeshRope, Pixi.MeshRopeOptions>(PixiMeshRope);\n\n/**\n * A SolidJS component that renders a `PIXI.MeshSimple`.\n */\nexport const MeshSimple = createLeafComponent<PixiMeshSimple, Pixi.SimpleMeshOptions>(PixiMeshSimple);\n\n/**\n * A SolidJS component that renders a `PIXI.NineSliceSprite`.\n */\nexport const NineSliceSprite = createLeafComponent<PixiNineSliceSprite, Pixi.NineSliceSpriteOptions>(\n PixiNineSliceSprite\n);\n\n/**\n * A SolidJS component that renders a `PIXI.ParticleContainer`.\n *\n * Particles should be added and removed from this component imperatively. Please see the docs for a reference example.\n */\nexport const ParticleContainer = createLeafComponent<PixiParticleContainer, Pixi.ParticleContainerOptions>(\n PixiParticleContainer\n);\n\n/**\n * A SolidJS component that renders a `PIXI.PerspectiveMesh`.\n */\nexport const PerspectiveMesh = createLeafComponent<PixiPerspectiveMesh, Pixi.PerspectivePlaneOptions>(\n PixiPerspectiveMesh\n);\n\n/**\n * A SolidJS component that renders a `PIXI.RenderContainer`.\n */\nexport const RenderContainer = createContainerComponent<PixiRenderContainer, Pixi.RenderContainerOptions>(\n PixiRenderContainer\n);\n\n/**\n * A SolidJS component that renders a `PIXI.RenderLayer`.\n */\nexport const RenderLayer = createContainerComponent<PixiRenderLayer, Pixi.RenderLayerOptions>(PixiRenderLayer);\n\n/**\n * A SolidJS component that renders a `PIXI.Sprite`.\n */\nexport const Sprite = createLeafComponent<PixiSprite, Pixi.SpriteOptions>(PixiSprite);\n/**\n * A SolidJS component that renders a `PIXI.Text`.\n */\nexport const Text = createLeafComponent<PixiText, Pixi.CanvasTextOptions>(PixiText);\n\n/**\n * A SolidJS component that renders a `PIXI.TilingSprite`.\n */\nexport const TilingSprite = createLeafComponent<PixiTilingSprite, Pixi.TilingSpriteOptions>(PixiTilingSprite);\n\n// export const MeshGeometry = createLeafComponent<PixiMeshGeometry, Pixi.MeshGeometryOptions>(PixiMeshGeometry);\n\n// export const NineSliceGeometry = createLeafComponent<PixiNineSliceGeometry, Pixi.NineSliceGeometryOptions>(\n// PixiNineSliceGeometry\n// );\n\n// export const Particle = createLeafComponent<PixiParticle, Pixi.ParticleOptions>(PixiParticle);\n\n// export const PerspectivePlaneGeometry = createLeafComponent<\n// PixiPerspectivePlaneGeometry,\n// Pixi.PerspectivePlaneGeometryOptions\n// >(PixiPerspectivePlaneGeometry);\n\n// export const PlaneGeometry = createLeafComponent<PixiPlaneGeometry, Pixi.PlaneGeometryOptions>(PixiPlaneGeometry);\n\n// export const RopeGeometry = createLeafComponent<PixiRopeGeometry, Pixi.RopeGeometryOptions>(PixiRopeGeometry);\n\n// TODO: Do we need a component for the Culler. It needs to interact with the stage directly.\n// export const Culler = createLeafComponent<PixiCuller, Pixi.Culler>(PixiCuller);\n"],"names":["SOLID_PROP_KEYS","applyProps","instance","props","defer","key","createRenderEffect","Error","insert","children","on","setProp","createContainerComponent","PixiClass","runtimeProps","initialisationProps","splitProps","PIXI_SOLID_EVENT_HANDLER_NAMES","as","createLeafComponent","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"],"mappings":";;;;AAyCO,MAAMA,kBAAkB,CAAC,OAAO,MAAM,UAAU;AAWhD,MAAMC,aAAa,CACxBC,UACAC,OACAC,UACG;AACH,aAAWC,OAAOF,OAAO;AACvB,QAAIE,QAAQ,KAAM;AAElB,QAAIA,QAAQ,OAAO;AACjBC,yBAAmB,MAAM;AAEtBH,cAAME,GAAG,EAAoCH,QAAQ;AAAA,MACxD,CAAC;AAAA,IACH,WAAWG,QAAQ,YAAY;AAC7B,UAAI,EAAE,cAAcH,WAAW;AAC7B,cAAM,IAAIK,MAAM,gDAAgD;AAAA,MAClE;AACAD,yBAAmB,MAAM;AACvBE,eAAON,UAAU,MAAMC,MAAMM,QAAQ;AAAA,MACvC,CAAC;AAAA,IACH,WAAWL,OAAO;AAChBE,yBACEI,GACE,MAAMP,MAAME,GAAyB,GACrC,MAAM;AACJM,gBAAQT,UAAUG,KAAKF,MAA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,eAAe/B,oBAAgEgC,cAAgB;"}
|
|
1
|
+
{"version":3,"file":"pixi-components.js","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 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, on, splitProps } from \"solid-js\";\nimport type { PixiEventHandlerMap } from \"./pixi-events\";\n\nimport { PIXI_SOLID_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 * @param defer Defers the createRenderEffect so the props aren't set on the first run.\n * This is useful because setting initialisation props can have unintended side effects.\n * Notibly in AnimatedSprite, if we set the textures roperty after instantiation it will stop the instance from playing.\n */\nexport const applyProps = <InstanceType extends PixiContainer, OptionsType extends ContainerProps<InstanceType>>(\n instance: InstanceType,\n props: OptionsType,\n defer?: boolean\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 if (defer) {\n createRenderEffect(\n on(\n () => props[key as keyof typeof props],\n () => {\n setProp(instance, key, props[key as keyof typeof props]);\n },\n { defer }\n )\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>): InstanceType & JSX.Element => {\n const [runtimeProps, initialisationProps] = splitProps(props, [\n ...SOLID_PROP_KEYS,\n ...PIXI_SOLID_EVENT_HANDLER_NAMES,\n ]);\n\n const instance = props.as || new PixiClass(initialisationProps as any);\n\n applyProps(instance, initialisationProps, true);\n applyProps(instance, runtimeProps);\n\n return instance as InstanceType & 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>): InstanceType & JSX.Element => {\n return createContainerComponent<InstanceType, OptionsType>(PixiClass)(props);\n };\n};\n\n/**\n * A SolidJS component that renders a `PIXI.AnimatedSprite`.\n */\nexport const AnimatedSprite = createLeafComponent<PixiAnimatedSprite, Pixi.AnimatedSpriteOptions>(PixiAnimatedSprite);\n/**\n * A SolidJS component that renders a `PIXI.BitmapText`.\n */\nexport const BitmapText = createLeafComponent<PixiBitmapText, Pixi.TextOptions>(PixiBitmapText);\n/**\n * A SolidJS component that renders a `PIXI.Container`.\n */\nexport const Container = createContainerComponent<PixiContainer, Pixi.ContainerOptions>(PixiContainer);\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 */\nexport const Graphics = createLeafComponent<PixiGraphics, Pixi.GraphicsOptions>(PixiGraphics);\n/**\n * A SolidJS component that renders a `PIXI.HTMLText`.\n */\nexport const HTMLText = createLeafComponent<PixiHTMLText, Pixi.HTMLTextOptions>(PixiHTMLText);\n\n/**\n * A SolidJS component that renders a `PIXI.MeshPlane`.\n */\nexport const MeshPlane = createLeafComponent<PixiMeshPlane, Pixi.MeshPlaneOptions>(PixiMeshPlane);\n\n/**\n * A SolidJS component that renders a `PIXI.MeshRope`.\n */\nexport const MeshRope = createLeafComponent<PixiMeshRope, Pixi.MeshRopeOptions>(PixiMeshRope);\n\n/**\n * A SolidJS component that renders a `PIXI.NineSliceSprite`.\n */\nexport const NineSliceSprite = createLeafComponent<PixiNineSliceSprite, Pixi.NineSliceSpriteOptions>(\n PixiNineSliceSprite\n);\n\n/**\n * A SolidJS component that renders a `PIXI.ParticleContainer`.\n *\n * Particles should be added and removed from this component imperatively. Please see the docs for a reference example.\n */\nexport const ParticleContainer = createLeafComponent<PixiParticleContainer, Pixi.ParticleContainerOptions>(\n PixiParticleContainer\n);\n\n/**\n * A SolidJS component that renders a `PIXI.PerspectiveMesh`.\n */\nexport const PerspectiveMesh = createLeafComponent<PixiPerspectiveMesh, Pixi.PerspectivePlaneOptions>(\n PixiPerspectiveMesh\n);\n\n/**\n * A SolidJS component that renders a `PIXI.RenderContainer`.\n */\nexport const RenderContainer = createContainerComponent<PixiRenderContainer, Pixi.RenderContainerOptions>(\n PixiRenderContainer\n);\n\n/**\n * A SolidJS component that renders a `PIXI.RenderLayer`.\n */\nexport const RenderLayer = createContainerComponent<PixiRenderLayer, Pixi.RenderLayerOptions>(PixiRenderLayer);\n\n/**\n * A SolidJS component that renders a `PIXI.Sprite`.\n */\nexport const Sprite = createLeafComponent<PixiSprite, Pixi.SpriteOptions>(PixiSprite);\n/**\n * A SolidJS component that renders a `PIXI.Text`.\n */\nexport const Text = createLeafComponent<PixiText, Pixi.CanvasTextOptions>(PixiText);\n\n/**\n * A SolidJS component that renders a `PIXI.TilingSprite`.\n */\nexport const TilingSprite = createLeafComponent<PixiTilingSprite, Pixi.TilingSpriteOptions>(PixiTilingSprite);\n\n// export const MeshGeometry = createLeafComponent<PixiMeshGeometry, Pixi.MeshGeometryOptions>(PixiMeshGeometry);\n\n// export const NineSliceGeometry = createLeafComponent<PixiNineSliceGeometry, Pixi.NineSliceGeometryOptions>(\n// PixiNineSliceGeometry\n// );\n\n// export const Particle = createLeafComponent<PixiParticle, Pixi.ParticleOptions>(PixiParticle);\n\n// export const PerspectivePlaneGeometry = createLeafComponent<\n// PixiPerspectivePlaneGeometry,\n// Pixi.PerspectivePlaneGeometryOptions\n// >(PixiPerspectivePlaneGeometry);\n\n// export const PlaneGeometry = createLeafComponent<PixiPlaneGeometry, Pixi.PlaneGeometryOptions>(PixiPlaneGeometry);\n\n// export const RopeGeometry = createLeafComponent<PixiRopeGeometry, Pixi.RopeGeometryOptions>(PixiRopeGeometry);\n\n// TODO: Do we need a component for the Culler. It needs to interact with the stage directly.\n// export const Culler = createLeafComponent<PixiCuller, Pixi.Culler>(PixiCuller);\n"],"names":["SOLID_PROP_KEYS","applyProps","instance","props","defer","key","createRenderEffect","Error","insert","children","on","setProp","createContainerComponent","PixiClass","runtimeProps","initialisationProps","splitProps","PIXI_SOLID_EVENT_HANDLER_NAMES","as","createLeafComponent","AnimatedSprite","PixiAnimatedSprite","BitmapText","PixiBitmapText","Container","PixiContainer","Graphics","PixiGraphics","HTMLText","PixiHTMLText","MeshPlane","PixiMeshPlane","MeshRope","PixiMeshRope","NineSliceSprite","PixiNineSliceSprite","ParticleContainer","PixiParticleContainer","PerspectiveMesh","PixiPerspectiveMesh","RenderContainer","PixiRenderContainer","RenderLayer","PixiRenderLayer","Sprite","PixiSprite","Text","PixiText","TilingSprite","PixiTilingSprite"],"mappings":";;;;AAwCO,MAAMA,kBAAkB,CAAC,O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,MAAMC,YAAYZ,yBAA+Da,WAAa;AAK9F,MAAMC,WAAWP,oBAAwDQ,UAAY;AAIrF,MAAMC,WAAWT,oBAAwDU,UAAY;AAKrF,MAAMC,YAAYX,oBAA0DY,WAAa;AAKzF,MAAMC,WAAWb,oBAAwDc,UAAY;AAKrF,MAAMC,kBAAkBf,oBAC7BgB,iBACF;AAOO,MAAMC,oBAAoBjB,oBAC/BkB,mBACF;AAKO,MAAMC,kBAAkBnB,oBAC7BoB,iBACF;AAKO,MAAMC,kBAAkB5B,yBAC7B6B,iBACF;AAKO,MAAMC,cAAc9B,yBAAmE+B,aAAe;AAKtG,MAAMC,SAASzB,oBAAoD0B,QAAU;AAI7E,MAAMC,OAAO3B,oBAAsD4B,MAAQ;AAK3E,MAAMC,eAAe7B,oBAAgE8B,cAAgB;"}
|
package/dist/pixi-stage.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { memo } from "solid-js/web";
|
|
2
|
-
import {
|
|
2
|
+
import { getPixiApp } from "./pixi-application.js";
|
|
3
3
|
import { applyProps } from "./pixi-components.js";
|
|
4
4
|
const PixiStage = (props) => {
|
|
5
|
-
const pixiApp =
|
|
5
|
+
const pixiApp = getPixiApp();
|
|
6
6
|
applyProps(pixiApp.stage, props);
|
|
7
7
|
return memo(() => pixiApp.stage);
|
|
8
8
|
};
|
package/dist/pixi-stage.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pixi-stage.js","sources":["../src/pixi-stage.tsx"],"sourcesContent":["import type { Container, ContainerOptions } from \"pixi.js\";\nimport type { JSX, Ref } from \"solid-js\";\nimport {
|
|
1
|
+
{"version":3,"file":"pixi-stage.js","sources":["../src/pixi-stage.tsx"],"sourcesContent":["import type { Container, ContainerOptions } from \"pixi.js\";\nimport type { JSX, Ref } from \"solid-js\";\nimport { getPixiApp } 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 */\nexport const PixiStage = (props: PixiStageProps): JSX.Element => {\n const pixiApp = getPixiApp();\n\n applyProps(pixiApp.stage, props);\n\n return <>{pixiApp.stage}</>;\n};\n"],"names":["PixiStage","props","pixiApp","getPixiApp","applyProps","stage","_$memo"],"mappings":";;;AA0BO,MAAMA,YAAYA,CAACC,UAAuC;AAC/D,QAAMC,UAAUC,WAAAA;AAEhBC,aAAWF,QAAQG,OAAOJ,KAAK;AAE/B,SAAAK,KAAA,MAAUJ,QAAQG,KAAK;AACzB;"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
+
export { onResize } from "./on-resize";
|
|
1
2
|
export type { PixiApplicationProps } from "./pixi-application";
|
|
2
|
-
export {
|
|
3
|
+
export { delay, getPixiApp, getTicker, onTick, PixiApplication, TickerProvider, } from "./pixi-application";
|
|
3
4
|
export { PixiCanvas } from "./pixi-canvas";
|
|
4
5
|
export type { ContainerProps, LeafProps } from "./pixi-components";
|
|
5
|
-
export { AnimatedSprite, BitmapText, Container, Graphics, HTMLText, MeshPlane, MeshRope,
|
|
6
|
+
export { AnimatedSprite, BitmapText, Container, Graphics, HTMLText, MeshPlane, MeshRope, NineSliceSprite, ParticleContainer, PerspectiveMesh, RenderContainer, RenderLayer, Sprite, Text, TilingSprite, } from "./pixi-components";
|
|
6
7
|
export type { PixiEventHandlerMap } from "./pixi-events";
|
|
7
8
|
export { PIXI_EVENT_NAMES, PIXI_SOLID_EVENT_HANDLER_NAMES } from "./pixi-events";
|
|
8
9
|
export type { PixiStageProps } from "./pixi-stage";
|
|
9
10
|
export { PixiStage } from "./pixi-stage";
|
|
10
|
-
export { useResize } from "./use-resize";
|
|
@@ -6,4 +6,4 @@ import type * as Pixi from "pixi.js";
|
|
|
6
6
|
*
|
|
7
7
|
* Because we listen for the renderer's "resize" event, this hook will work correctly whether the window is resized or just the DOM element the PixiCanvas is inside changes size.
|
|
8
8
|
*/
|
|
9
|
-
export declare const
|
|
9
|
+
export declare const onResize: (resizeCallback: (screen: Pixi.Rectangle) => void) => void;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { ApplicationOptions,
|
|
2
|
-
import { Application } from "pixi.js";
|
|
1
|
+
import type { ApplicationOptions, TickerCallback } from "pixi.js";
|
|
2
|
+
import { Application, Ticker } from "pixi.js";
|
|
3
3
|
import type { JSX, ParentProps, Ref } from "solid-js";
|
|
4
4
|
/**
|
|
5
5
|
* A custom SolidJS hook to access the root PIXI.Application instance.
|
|
@@ -8,7 +8,7 @@ import type { JSX, ParentProps, Ref } from "solid-js";
|
|
|
8
8
|
* @returns The PIXI.Application instance provided by the `PixiApplication` component.
|
|
9
9
|
* @throws Will throw an error if used outside of a `PixiApplication` context provider.
|
|
10
10
|
*/
|
|
11
|
-
export declare const
|
|
11
|
+
export declare const getPixiApp: () => Application<import("pixi.js").Renderer>;
|
|
12
12
|
/**
|
|
13
13
|
* Props for the `PixiApplication` component. It extends the PIXI.ApplicationOptions
|
|
14
14
|
* to allow passing configuration directly to the Pixi.js Application constructor,
|
|
@@ -21,7 +21,7 @@ export type PixiApplicationProps = Partial<Omit<ApplicationOptions, "children" |
|
|
|
21
21
|
/**
|
|
22
22
|
* A SolidJS component that creates and manages a PIXI.Application instance.
|
|
23
23
|
* It provides the application instance through context to be used by child components
|
|
24
|
-
* and custom hooks like `
|
|
24
|
+
* and custom hooks like `getPixiApp`, `onTick`, and `getTicker`.
|
|
25
25
|
*
|
|
26
26
|
* This component should only be used once in your application.
|
|
27
27
|
*
|
|
@@ -34,13 +34,13 @@ export type TickerProviderProps = ParentProps<{
|
|
|
34
34
|
}>;
|
|
35
35
|
/**
|
|
36
36
|
* This is only required if you want a ticker without the Application.
|
|
37
|
-
* It provides context for the `
|
|
37
|
+
* It provides context for the `onTick` and `getTicker` hooks so we can run tests that use them without having to instantate a Pixi Application.
|
|
38
38
|
*
|
|
39
39
|
* You need to pass in the ticker instance you want to use so it can be manually controled form the outside for testing.
|
|
40
40
|
*/
|
|
41
41
|
export declare const TickerProvider: (props: TickerProviderProps) => JSX.Element;
|
|
42
42
|
/**
|
|
43
|
-
*
|
|
43
|
+
* getTicker
|
|
44
44
|
*
|
|
45
45
|
* A custom SolidJS hook that provides access to the PIXI.Application's shared Ticker instance.
|
|
46
46
|
* This hook must be called from a component that is a descendant of `PixiApplication`.
|
|
@@ -49,9 +49,9 @@ export declare const TickerProvider: (props: TickerProviderProps) => JSX.Element
|
|
|
49
49
|
* @returns The PIXI.Ticker instance from the application context.
|
|
50
50
|
* @throws Will throw an error if used outside of a `PixiApplication` or `TickerProvider` context.
|
|
51
51
|
*/
|
|
52
|
-
export declare const
|
|
52
|
+
export declare const getTicker: () => Ticker;
|
|
53
53
|
/**
|
|
54
|
-
*
|
|
54
|
+
* onTick
|
|
55
55
|
*
|
|
56
56
|
* A custom SolidJS hook that registers a callback function to be executed on every frame
|
|
57
57
|
* of the PIXI.Application's ticker. The callback is automatically removed when the
|
|
@@ -64,11 +64,11 @@ export declare const useTicker: () => Ticker;
|
|
|
64
64
|
* the `PIXI.Ticker` instance as its argument.
|
|
65
65
|
*
|
|
66
66
|
*/
|
|
67
|
-
export declare const
|
|
67
|
+
export declare const onTick: (tickerCallback: TickerCallback<Ticker>) => void;
|
|
68
68
|
/**
|
|
69
|
-
* Delay until a given number of milliseconds has passed on the
|
|
69
|
+
* Delay until a given number of milliseconds has passed on the shared ticker.
|
|
70
70
|
*
|
|
71
|
-
* It is guaranteed to be in sync with the ticker and uses accumulated deltaMs not an external time measurement.
|
|
71
|
+
* It is guaranteed to be in sync with the shared ticker and uses accumulated deltaMs not an external time measurement.
|
|
72
72
|
*
|
|
73
73
|
* Simply await for it to resolve if in an async context or pass in a callback function.
|
|
74
74
|
* It's not recommended to use both techniques at once.
|
|
@@ -84,4 +84,4 @@ export declare const useTick: (tickerCallback: TickerCallback<Ticker>) => void;
|
|
|
84
84
|
* @note It will not resolve or fire the callback if the ticker is paused or stopped.
|
|
85
85
|
*
|
|
86
86
|
*/
|
|
87
|
-
export declare const
|
|
87
|
+
export declare const delay: (delayMs: number, callback?: () => void) => Promise<void>;
|
|
@@ -32,7 +32,7 @@ export declare const AnimatedSprite: (props: Omit<Pixi.AnimatedSpriteOptions, "c
|
|
|
32
32
|
/**
|
|
33
33
|
* A SolidJS component that renders a `PIXI.BitmapText`.
|
|
34
34
|
*/
|
|
35
|
-
export declare const BitmapText: (props: Omit<
|
|
35
|
+
export declare const BitmapText: (props: Omit<Pixi.TextOptions<Pixi.TextStyle, Pixi.TextStyleOptions>, "children"> & LeafProps<Pixi.BitmapText>) => Pixi.BitmapText & JSX.Element;
|
|
36
36
|
/**
|
|
37
37
|
* A SolidJS component that renders a `PIXI.Container`.
|
|
38
38
|
*/
|
|
@@ -58,10 +58,6 @@ export declare const MeshPlane: (props: Omit<Pixi.MeshPlaneOptions, "children">
|
|
|
58
58
|
* A SolidJS component that renders a `PIXI.MeshRope`.
|
|
59
59
|
*/
|
|
60
60
|
export declare const MeshRope: (props: Omit<Pixi.MeshRopeOptions, "children"> & LeafProps<Pixi.MeshRope>) => Pixi.MeshRope & JSX.Element;
|
|
61
|
-
/**
|
|
62
|
-
* A SolidJS component that renders a `PIXI.MeshSimple`.
|
|
63
|
-
*/
|
|
64
|
-
export declare const MeshSimple: (props: Omit<Pixi.SimpleMeshOptions, "children"> & LeafProps<Pixi.MeshSimple>) => Pixi.MeshSimple & JSX.Element;
|
|
65
61
|
/**
|
|
66
62
|
* A SolidJS component that renders a `PIXI.NineSliceSprite`.
|
|
67
63
|
*/
|
package/package.json
CHANGED
package/dist/use-resize.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"use-resize.js","sources":["../src/use-resize.ts"],"sourcesContent":["import type * as Pixi from \"pixi.js\";\nimport { onCleanup } from \"solid-js\";\nimport { usePixiApp } from \"./pixi-application\";\n\n/**\n * A SolidJS hook that runs a callback function whenever the PixiJS renderer is resized.\n *\n * @param resizeCallback A callback function that receives the updated screen dimensions as a `Pixi.Rectangle` object. This function will be called immediately upon hook initialization and then on every subsequent resize event.\n *\n * Because we listen for the renderer's \"resize\" event, this hook will work correctly whether the window is resized or just the DOM element the PixiCanvas is inside changes size.\n */\nexport const useResize = (resizeCallback: (screen: Pixi.Rectangle) => void): void => {\n const app = usePixiApp();\n\n const handleResize = () => {\n resizeCallback(app.renderer.screen);\n };\n\n handleResize();\n\n app.renderer.addListener(\"resize\", handleResize);\n\n onCleanup(() => {\n app.renderer.removeListener(\"resize\", handleResize);\n });\n};\n"],"names":[],"mappings":";;AAWO,MAAM,YAAY,CAAC,mBAA2D;AACnF,QAAM,MAAM,WAAA;AAEZ,QAAM,eAAe,MAAM;AACzB,mBAAe,IAAI,SAAS,MAAM;AAAA,EACpC;AAEA,eAAA;AAEA,MAAI,SAAS,YAAY,UAAU,YAAY;AAE/C,YAAU,MAAM;AACd,QAAI,SAAS,eAAe,UAAU,YAAY;AAAA,EACpD,CAAC;AACH;"}
|