pixi-solid 0.1.21 → 0.1.22

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 CHANGED
@@ -1,10 +1,10 @@
1
1
  import { getPixiApp } from "./pixi-application/get-pixi-app.js";
2
2
  import { getTicker } from "./pixi-application/get-ticker.js";
3
3
  import { PixiApplicationProvider, TickerProvider } from "./pixi-application/pixi-application-provider.js";
4
- import { usePixiScreen } from "./use-pixi-screen/use-pixi-screen.js";
5
4
  import { onResize } from "./on-resize.js";
6
5
  import { onTick } from "./on-tick.js";
7
6
  import { createAsyncDelay, delay } from "./delay.js";
8
7
  import { AnimatedSprite, BitmapText, Container, Graphics, HTMLText, MeshPlane, MeshRope, NineSliceSprite, ParticleContainer, PerspectiveMesh, RenderContainer, RenderLayer, Sprite, Text, TilingSprite } from "./components/components.js";
9
8
  import { PixiCanvas } from "./pixi-canvas.js";
9
+ import { usePixiScreen } from "./use-pixi-screen/use-pixi-screen.js";
10
10
  export { AnimatedSprite, BitmapText, Container, Graphics, HTMLText, MeshPlane, MeshRope, NineSliceSprite, ParticleContainer, PerspectiveMesh, PixiApplicationProvider, PixiCanvas, RenderContainer, RenderLayer, Sprite, Text, TickerProvider, TilingSprite, createAsyncDelay, delay, getPixiApp, getTicker, onResize, onTick, usePixiScreen };
package/dist/on-resize.js CHANGED
@@ -1,6 +1,5 @@
1
1
  import { getPixiApp } from "./pixi-application/get-pixi-app.js";
2
- import { usePixiScreen } from "./use-pixi-screen/use-pixi-screen.js";
3
- import { createEffect, on } from "solid-js";
2
+ import { onCleanup } from "solid-js";
4
3
  //#region src/on-resize.ts
5
4
  /**
6
5
  *
@@ -20,20 +19,16 @@ var onResize = (resizeCallback) => {
20
19
  } catch {
21
20
  throw new Error("onResize must be used within a PixiApplicationProvider or a PixiCanvas");
22
21
  }
23
- const screen = usePixiScreen();
24
- /**
25
- * We derive from the reactive screen store so this hook always fires after `usePixiScreen()` has
26
- * been updated.
27
- * This avoids a race condition and guarantees consistent values when both are used together.
28
- */
29
- createEffect(on(() => [
30
- screen.width,
31
- screen.height,
32
- screen.x,
33
- screen.y
34
- ], () => {
35
- resizeCallback(pixiApp.renderer.screen);
36
- }, { defer: false }));
22
+ resizeCallback(pixiApp.renderer.screen);
23
+ const handleResize = () => {
24
+ queueMicrotask(() => {
25
+ resizeCallback(pixiApp.renderer.screen);
26
+ });
27
+ };
28
+ pixiApp.renderer.addListener("resize", handleResize);
29
+ onCleanup(() => {
30
+ pixiApp.renderer.removeListener("resize", handleResize);
31
+ });
37
32
  };
38
33
  //#endregion
39
34
  export { onResize };
@@ -1 +1 @@
1
- {"version":3,"file":"on-resize.js","names":[],"sources":["../src/on-resize.ts"],"sourcesContent":["import type * as Pixi from \"pixi.js\";\nimport { createEffect, on } from \"solid-js\";\n\nimport { getPixiApp } from \"./pixi-application\";\nimport { usePixiScreen } from \"./use-pixi-screen\";\n\n/**\n *\n * A SolidJS hook that runs a callback function whenever the PixiJS renderer is resized.\n * The callback is automatically removed when the component or hook's owning computation is cleaned up.\n *\n * This hook must be called from a component that is a descendant of `PixiCanvas` or `PixiApplicationProvider`.\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 * We listen for the renderer's \"resize\" event so this hook will work correctly whether the window is resized or just the DOM element the PixiCanvas is inside of changes size.\n */\nexport const onResize = (resizeCallback: (screen: Pixi.Rectangle) => void): void => {\n let pixiApp: Pixi.Application;\n\n try {\n pixiApp = getPixiApp();\n } catch {\n throw new Error(\"onResize must be used within a PixiApplicationProvider or a PixiCanvas\");\n }\n\n const screen = usePixiScreen();\n\n /**\n * We derive from the reactive screen store so this hook always fires after `usePixiScreen()` has\n * been updated.\n * This avoids a race condition and guarantees consistent values when both are used together.\n */\n createEffect(\n on(\n () => [screen.width, screen.height, screen.x, screen.y],\n () => {\n resizeCallback(pixiApp.renderer.screen);\n },\n { defer: false },\n ),\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;AAiBA,IAAa,YAAY,mBAA2D;CAClF,IAAI;AAEJ,KAAI;AACF,YAAU,YAAY;SAChB;AACN,QAAM,IAAI,MAAM,yEAAyE;;CAG3F,MAAM,SAAS,eAAe;;;;;;AAO9B,cACE,SACQ;EAAC,OAAO;EAAO,OAAO;EAAQ,OAAO;EAAG,OAAO;EAAE,QACjD;AACJ,iBAAe,QAAQ,SAAS,OAAO;IAEzC,EAAE,OAAO,OAAO,CACjB,CACF"}
1
+ {"version":3,"file":"on-resize.js","names":[],"sources":["../src/on-resize.ts"],"sourcesContent":["import type * as Pixi from \"pixi.js\";\nimport { onCleanup } from \"solid-js\";\n\nimport { getPixiApp } from \"./pixi-application\";\n\n/**\n *\n * A SolidJS hook that runs a callback function whenever the PixiJS renderer is resized.\n * The callback is automatically removed when the component or hook's owning computation is cleaned up.\n *\n * This hook must be called from a component that is a descendant of `PixiCanvas` or `PixiApplicationProvider`.\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 * We listen for the renderer's \"resize\" event so this hook will work correctly whether the window is resized or just the DOM element the PixiCanvas is inside of changes size.\n */\nexport const onResize = (resizeCallback: (screen: Pixi.Rectangle) => void): void => {\n let pixiApp: Pixi.Application;\n\n try {\n pixiApp = getPixiApp();\n } catch {\n throw new Error(\"onResize must be used within a PixiApplicationProvider or a PixiCanvas\");\n }\n\n // Ensure initial callback happens during setup.\n resizeCallback(pixiApp.renderer.screen);\n\n const handleResize = () => {\n // Keep onResize event-driven (fires for every renderer resize event), but schedule the\n // callback after the current emit cycle so usePixiScreen listeners have already synchronized\n // their reactive values. This avoids stale reads when both hooks are used together.\n queueMicrotask(() => {\n resizeCallback(pixiApp.renderer.screen);\n });\n };\n\n pixiApp.renderer.addListener(\"resize\", handleResize);\n\n onCleanup(() => {\n pixiApp.renderer.removeListener(\"resize\", handleResize);\n });\n};\n"],"mappings":";;;;;;;;;;;;;;AAgBA,IAAa,YAAY,mBAA2D;CAClF,IAAI;AAEJ,KAAI;AACF,YAAU,YAAY;SAChB;AACN,QAAM,IAAI,MAAM,yEAAyE;;AAI3F,gBAAe,QAAQ,SAAS,OAAO;CAEvC,MAAM,qBAAqB;AAIzB,uBAAqB;AACnB,kBAAe,QAAQ,SAAS,OAAO;IACvC;;AAGJ,SAAQ,SAAS,YAAY,UAAU,aAAa;AAEpD,iBAAgB;AACd,UAAQ,SAAS,eAAe,UAAU,aAAa;GACvD"}
@@ -1,9 +1,3 @@
1
- import type { JSX } from "solid-js";
2
- export declare const withTestRoot: <T>(setup: () => T) => {
3
- value: T;
4
- dispose: () => void;
5
- };
6
- /**
7
- * Calls pixi solid components in a pure Solid root without mounting to the Canvas.
8
- */
9
- export declare const mountHeadless: (component: () => JSX.Element) => (() => void);
1
+ export { mountHeadless, withTestRoot } from "./test-root";
2
+ export { createMockApp, createMockRenderer, TestPixiProvider } from "./pixi-renderer-mock";
3
+ export type { MockRenderer } from "./pixi-renderer-mock";
@@ -0,0 +1,24 @@
1
+ import type * as Pixi from "pixi.js";
2
+ import type { JSX, ParentProps } from "solid-js";
3
+ export type MockRenderer = {
4
+ screen: {
5
+ width: number;
6
+ height: number;
7
+ x: number;
8
+ y: number;
9
+ };
10
+ addListener: (event: string, listener: () => void) => void;
11
+ removeListener: (event: string, listener: () => void) => void;
12
+ emitResize: (nextScreen?: Partial<{
13
+ width: number;
14
+ height: number;
15
+ x: number;
16
+ y: number;
17
+ }>) => void;
18
+ };
19
+ export declare const createMockRenderer: () => MockRenderer;
20
+ export declare const createMockApp: (renderer: MockRenderer) => Pixi.Application;
21
+ export declare const TestPixiProvider: (props: ParentProps<{
22
+ app: Pixi.Application;
23
+ renderer: MockRenderer;
24
+ }>) => JSX.Element;
@@ -0,0 +1,9 @@
1
+ import type { JSX } from "solid-js";
2
+ export declare const withTestRoot: <T>(setup: () => T) => {
3
+ value: T;
4
+ dispose: () => void;
5
+ };
6
+ /**
7
+ * Calls pixi solid components in a pure Solid root without mounting to the Canvas.
8
+ */
9
+ export declare const mountHeadless: (component: () => JSX.Element) => (() => void);
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pixi-solid",
3
- "version": "0.1.21",
3
+ "version": "0.1.22",
4
4
  "private": false,
5
5
  "description": "A library to write PixiJS applications with SolidJS",
6
6
  "homepage": "https://lukecarlthompson.github.io/pixi-solid/",