pixi-solid 0.0.18 → 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/dist/index.js +1 -1
- package/dist/{use-resize.js → on-resize.js} +1 -1
- package/dist/on-resize.js.map +1 -0
- package/dist/pixi-application.js +2 -2
- package/dist/pixi-application.js.map +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/pixi-application.d.ts +4 -4
- package/package.json +1 -1
- package/dist/use-resize.js.map +0 -1
- /package/dist/types/{use-resize.d.ts → on-resize.d.ts} +0 -0
package/dist/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
import { onResize } from "./on-resize.js";
|
|
1
2
|
import { PixiApplication, TickerProvider, delay, getPixiApp, getTicker, onTick } from "./pixi-application.js";
|
|
2
3
|
import { PixiCanvas } from "./pixi-canvas.js";
|
|
3
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 { onResize } from "./use-resize.js";
|
|
7
7
|
export {
|
|
8
8
|
AnimatedSprite,
|
|
9
9
|
BitmapText,
|
|
@@ -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,8 +1,8 @@
|
|
|
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();
|
|
5
|
+
const TickerContext = createContext(Ticker.shared);
|
|
6
6
|
const getPixiApp = () => {
|
|
7
7
|
const app = useContext(PixiAppContext);
|
|
8
8
|
if (!app) {
|
|
@@ -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,MAA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MAAMO,YAAYA,MAAc;AACrC,QAAMZ,SAASnB,WAAWL,aAAa;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/types/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export { onResize } from "./on-resize";
|
|
1
2
|
export type { PixiApplicationProps } from "./pixi-application";
|
|
2
3
|
export { delay, getPixiApp, getTicker, onTick, PixiApplication, TickerProvider, } from "./pixi-application";
|
|
3
4
|
export { PixiCanvas } from "./pixi-canvas";
|
|
@@ -7,4 +8,3 @@ 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 { onResize } from "./use-resize";
|
|
@@ -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.
|
|
@@ -66,9 +66,9 @@ export declare const getTicker: () => Ticker;
|
|
|
66
66
|
*/
|
|
67
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.
|
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 { 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;"}
|
|
File without changes
|