pixi-solid 0.0.10 → 0.0.12

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,9 +1,35 @@
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 { useResize } from "./use-resize.js";
7
- import { useTick, useTicker } from "./use-ticker.js";
8
-
9
- export { AnimatedSprite, BitmapText, Container, Graphics, HTMLText, MeshPlane, MeshRope, MeshSimple, NineSliceSprite, PIXI_EVENT_NAMES, ParticleContainer, PerspectiveMesh, PixiApplication, PixiCanvas, PixiStage, RenderContainer, RenderLayer, Sprite, Text, TilingSprite, usePixiApp, useResize, useTick, useTicker };
1
+ import { PixiApplication as r, usePixiApp as t } from "./pixi-application.js";
2
+ import { PixiCanvas as o } from "./pixi-canvas.js";
3
+ import { AnimatedSprite as x, BitmapText as a, Container as s, Graphics as m, HTMLText as S, MeshPlane as P, MeshRope as T, MeshSimple as c, NineSliceSprite as f, ParticleContainer as E, PerspectiveMesh as M, RenderContainer as l, RenderLayer as A, Sprite as N, Text as _, TilingSprite as h } from "./pixi-components.js";
4
+ import { PIXI_EVENT_NAMES as R, PIXI_SOLID_EVENT_HANDLER_NAMES as u } from "./pixi-events.js";
5
+ import { PixiStage as L } from "./pixi-stage.js";
6
+ import { useResize as g } from "./use-resize.js";
7
+ import { useTick as v, useTicker as D } from "./use-ticker.js";
8
+ export {
9
+ x as AnimatedSprite,
10
+ a as BitmapText,
11
+ s as Container,
12
+ m as Graphics,
13
+ S as HTMLText,
14
+ P as MeshPlane,
15
+ T as MeshRope,
16
+ c as MeshSimple,
17
+ f as NineSliceSprite,
18
+ R as PIXI_EVENT_NAMES,
19
+ u as PIXI_SOLID_EVENT_HANDLER_NAMES,
20
+ E as ParticleContainer,
21
+ M as PerspectiveMesh,
22
+ r as PixiApplication,
23
+ o as PixiCanvas,
24
+ L as PixiStage,
25
+ l as RenderContainer,
26
+ A as RenderLayer,
27
+ N as Sprite,
28
+ _ as Text,
29
+ h as TilingSprite,
30
+ t as usePixiApp,
31
+ g as useResize,
32
+ v as useTick,
33
+ D as useTicker
34
+ };
35
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;"}
@@ -1,70 +1,44 @@
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
- */
14
- const usePixiApp = () => {
15
- const app = useContext(PixiAppContext);
16
- if (!app) throw new Error("usePixiApp must be used within a PixiApplication");
17
- return app;
1
+ import { createComponent as i } from "solid-js/web";
2
+ import { Application as c } from "pixi.js";
3
+ import { createContext as a, useContext as s, splitProps as p, createResource as u, createEffect as l, onCleanup as d, Show as f } from "solid-js";
4
+ const n = a(), w = () => {
5
+ const t = s(n);
6
+ if (!t)
7
+ throw new Error("usePixiApp must be used within a PixiApplication");
8
+ return t;
9
+ }, A = (t) => {
10
+ const [h, o] = p(t, ["ref", "children"]), [r] = u(async () => {
11
+ const e = new c();
12
+ return await e.init({
13
+ autoDensity: !0,
14
+ resolution: Math.min(window.devicePixelRatio, 2),
15
+ sharedTicker: !0,
16
+ ...o
17
+ }), e;
18
+ });
19
+ return l(() => {
20
+ const e = r();
21
+ e && (t.ref && t.ref(e), e.ticker.autoStart = !1, e.ticker.start(), d(() => {
22
+ e.destroy(!0, {
23
+ children: !0
24
+ });
25
+ }));
26
+ }), i(f, {
27
+ get when() {
28
+ return r();
29
+ },
30
+ children: (e) => i(n.Provider, {
31
+ get value() {
32
+ return e();
33
+ },
34
+ get children() {
35
+ return t.children;
36
+ }
37
+ })
38
+ });
18
39
  };
19
- /**
20
- * A SolidJS component that creates and manages a PIXI.Application instance.
21
- * It provides the application instance through context to be used by child components
22
- * and custom hooks like `usePixiApp`, `useTick`, and `useTicker`.
23
- *
24
- * This component should only be used once in your application.
25
- *
26
- * @param props The properties to configure the Pixi.js Application.
27
- *
28
- */
29
- const PixiApplication = (props) => {
30
- const [_solidProps, initialisationProps] = splitProps(props, ["ref", "children"]);
31
- const [appResource] = createResource(async () => {
32
- const app = new Application();
33
- await app.init({
34
- autoDensity: true,
35
- resolution: Math.min(window.devicePixelRatio, 2),
36
- sharedTicker: true,
37
- ...initialisationProps
38
- });
39
- return app;
40
- });
41
- createEffect(() => {
42
- const app = appResource();
43
- if (app) {
44
- if (props.ref) props.ref(app);
45
- app.ticker.autoStart = false;
46
- app.ticker.start();
47
- globalThis.__PIXI_DEVTOOLS__ = { app };
48
- onCleanup(() => {
49
- app.destroy(true, { children: true });
50
- });
51
- }
52
- });
53
- return createComponent(Show, {
54
- get when() {
55
- return appResource();
56
- },
57
- children: (app) => createComponent(PixiAppContext.Provider, {
58
- get value() {
59
- return app();
60
- },
61
- get children() {
62
- return props.children;
63
- }
64
- })
65
- });
40
+ export {
41
+ A as PixiApplication,
42
+ w as usePixiApp
66
43
  };
67
-
68
- //#endregion
69
- export { PixiApplication, usePixiApp };
70
- //# sourceMappingURL=pixi-application.js.map
44
+ //# sourceMappingURL=pixi-application.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"pixi-application.js","names":["ApplicationOptions","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","init","autoDensity","resolution","Math","min","window","devicePixelRatio","sharedTicker","arg","ticker","autoStart","start","globalThis","__PIXI_DEVTOOLS__","destroy","_$createComponent","when","Provider","value"],"sources":["../src/pixi-application.tsx"],"sourcesContent":["import type { ApplicationOptions } from \"pixi.js\";\nimport { Application } from \"pixi.js\";\nimport type { JSX, Ref } from \"solid-js\";\nimport { createContext, createEffect, createResource, onCleanup, Show, splitProps, useContext } 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 */\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<Omit<ApplicationOptions, \"children\" | \"resizeTo\" | \"view\">> & {\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 `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 */\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 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 // @ts-expect-error\n globalThis.__PIXI_DEVTOOLS__ = {\n app,\n };\n\n onCleanup(() => {\n app.destroy(true, { children: true });\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":";;;;;AAKA,IAAMW,iBAAiBP,eAA4B;;;;;;;;AASnD,MAAaQ,mBAAmB;CAC9B,MAAMC,MAAMH,WAAWC,eAAe;AACtC,KAAI,CAACE,IACH,OAAM,IAAIC,MAAM,mDAAmD;AAErE,QAAOD;;;;;;;;;;;;AAuBT,MAAaQ,mBAAmBC,UAAgC;CAC9D,MAAM,CAACC,aAAaC,uBAAuBf,WAAWa,OAAO,CAAC,OAAO,WAAW,CAAC;CAIjF,MAAM,CAACG,eAAenB,eAAe,YAAY;EAC/C,MAAMO,MAAM,IAAIZ,aAAa;AAC7B,QAAMY,IAAIa,KAAK;GACbC,aAAa;GACbC,YAAYC,KAAKC,IAAIC,OAAOC,kBAAkB,EAAE;GAChDC,cAAc;GACd,GAAGT;GACJ,CAAC;AAEF,SAAOX;GACP;AAEFR,oBAAmB;EACjB,MAAMQ,MAAMY,aAAa;AACzB,MAAIZ,KAAK;AACP,OAAIS,MAAMJ,IAEPI,OAAMJ,IAAsCL,IAAI;AAMnDA,OAAIsB,OAAOC,YAAY;AACvBvB,OAAIsB,OAAOE,OAAO;AAGlBC,cAAWC,oBAAoB,EAC7B1B,KACD;AAEDN,mBAAgB;AACdM,QAAI2B,QAAQ,MAAM,EAAErB,UAAU,MAAM,CAAC;KACrC;;GAEJ;AAEF,QAAAsB,gBACGjC,MAAI;EAAA,IAACkC,OAAI;AAAA,UAAEjB,aAAa;;EAAAN,WACrBN,QAAG4B,gBAAM9B,eAAegC,UAAQ;GAAA,IAACC,QAAK;AAAA,WAAE/B,KAAK;;GAAA,IAAAM,WAAA;AAAA,WAAGG,MAAMH;;GAAQ,CAAA;EAA2B,CAAA"}
1
+ {"version":3,"file":"pixi-application.js","sources":["../src/pixi-application.tsx"],"sourcesContent":["import type { ApplicationOptions } from \"pixi.js\";\nimport { Application } from \"pixi.js\";\nimport type { JSX, Ref } from \"solid-js\";\nimport { createContext, createEffect, createResource, onCleanup, Show, splitProps, useContext } 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 */\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<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 `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 */\nexport const PixiApplication = (props: PixiApplicationProps) => {\n const [_solidProps, 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) => <PixiAppContext.Provider value={app()}>{props.children}</PixiAppContext.Provider>}\n </Show>\n );\n};\n"],"names":["PixiAppContext","createContext","usePixiApp","app","useContext","Error","PixiApplication","props","_solidProps","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"],"mappings":";;;AAKA,MAAMA,IAAiBC,EAAAA,GASVC,IAAaA,MAAM;AAC9B,QAAMC,IAAMC,EAAWJ,CAAc;AACrC,MAAI,CAACG;AACH,UAAM,IAAIE,MAAM,kDAAkD;AAEpE,SAAOF;AACT,GAsBaG,IAAkBA,CAACC,MAAgC;AAC9D,QAAM,CAACC,GAAaC,CAAmB,IAAIC,EAAWH,GAAO,CAAC,OAAO,UAAU,CAAC,GAI1E,CAACI,CAAW,IAAIC,EAAe,YAAY;AAC/C,UAAMT,IAAM,IAAIU,EAAAA;AAChB,iBAAMV,EAAIW,KAAK;AAAA,MACbC,aAAa;AAAA,MACbC,YAAYC,KAAKC,IAAIC,OAAOC,kBAAkB,CAAC;AAAA,MAC/CC,cAAc;AAAA,MACd,GAAGZ;AAAAA,IAAAA,CACJ,GAEMN;AAAAA,EACT,CAAC;AAEDmB,SAAAA,EAAa,MAAM;AACjB,UAAMnB,IAAMQ,EAAAA;AACZ,IAAIR,MACEI,EAAMgB,OAEPhB,EAAMgB,IAAsCpB,CAAG,GAMlDA,EAAIqB,OAAOC,YAAY,IACvBtB,EAAIqB,OAAOE,MAAAA,GAEXC,EAAU,MAAM;AACdxB,MAAAA,EAAIyB,QAAQ,IAAM;AAAA,QAAEC,UAAU;AAAA,MAAA,CAAM;AAAA,IACtC,CAAC;AAAA,EAEL,CAAC,GAEDC,EACGC,GAAI;AAAA,IAAA,IAACC,OAAI;AAAA,aAAErB,EAAAA;AAAAA,IAAa;AAAA,IAAAkB,UACrB1B,CAAAA,MAAG2B,EAAM9B,EAAeiC,UAAQ;AAAA,MAAA,IAACC,QAAK;AAAA,eAAE/B,EAAAA;AAAAA,MAAK;AAAA,MAAA,IAAA0B,WAAA;AAAA,eAAGtB,EAAMsB;AAAAA,MAAQ;AAAA,IAAA,CAAA;AAAA,EAAA,CAA2B;AAGjG;"}
@@ -1,64 +1,35 @@
1
- import { usePixiApp } from "./pixi-application.js";
2
- import { className, 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` component.
14
- * - Requires a `PixiStage` component as a child.
15
- *
16
- * Props:
17
- * @param props.children - JSX content to render inside the canvas wrapper. Use `PixiStage` as the only child.
18
- */
19
- const PixiCanvas = (props) => {
20
- let canvasWrapElement;
21
- const pixiApp = usePixiApp();
22
- pixiApp.canvas.style.display = "block";
23
- createRenderEffect(() => {
24
- if (props.children === void 0) throw new Error("PixiCanvas requires the `PixiStage` component to render.");
25
- });
26
- let previousResizeTo;
27
- let resizeObserver;
28
- onMount(() => {
29
- if (!canvasWrapElement) return;
30
- previousResizeTo = pixiApp.resizeTo;
31
- pixiApp.resizeTo = canvasWrapElement;
32
- pixiApp.queueResize();
33
- resizeObserver = new ResizeObserver(() => {
34
- pixiApp.queueResize();
35
- });
36
- resizeObserver.observe(canvasWrapElement);
37
- });
38
- onCleanup(() => {
39
- if (!canvasWrapElement) return;
40
- pixiApp.resizeTo = previousResizeTo;
41
- resizeObserver?.disconnect();
42
- resizeObserver = void 0;
43
- });
44
- return (() => {
45
- var _el$ = _tmpl$();
46
- var _ref$ = canvasWrapElement;
47
- typeof _ref$ === "function" ? use(_ref$, _el$) : canvasWrapElement = _el$;
48
- insert(_el$, () => pixiApp.canvas);
49
- effect((_p$) => {
50
- var _v$ = { ...typeof props.style === "object" ? props.style : {} }, _v$2 = props.className;
51
- _p$.e = style(_el$, _v$, _p$.e);
52
- _v$2 !== _p$.t && className(_el$, _p$.t = _v$2);
53
- return _p$;
54
- }, {
55
- e: void 0,
56
- t: void 0
57
- });
58
- return _el$;
59
- })();
1
+ import { template as l, insert as u, effect as f, style as m, className as d, use as p } from "solid-js/web";
2
+ import { createRenderEffect as z, onMount as y, onCleanup as x } from "solid-js";
3
+ import { usePixiApp as b } from "./pixi-application.js";
4
+ var R = /* @__PURE__ */ l("<div>");
5
+ const q = (o) => {
6
+ let r;
7
+ const e = b();
8
+ e.canvas.style.display = "block", z(() => {
9
+ if (o.children === void 0)
10
+ throw new Error("PixiCanvas requires the `PixiStage` component to render.");
11
+ });
12
+ let n, s;
13
+ return y(() => {
14
+ r && (n = e.resizeTo, e.resizeTo = r, e.queueResize(), s = new ResizeObserver(() => {
15
+ e.queueResize();
16
+ }), s.observe(r));
17
+ }), x(() => {
18
+ r && (e.resizeTo = n, s?.disconnect(), s = void 0);
19
+ }), (() => {
20
+ var t = R(), a = r;
21
+ return typeof a == "function" ? p(a, t) : r = t, u(t, () => e.canvas), f((i) => {
22
+ var c = {
23
+ ...typeof o.style == "object" ? o.style : {}
24
+ }, v = o.className;
25
+ return i.e = m(t, c, i.e), v !== i.t && d(t, i.t = v), i;
26
+ }, {
27
+ e: void 0,
28
+ t: void 0
29
+ }), t;
30
+ })();
60
31
  };
61
-
62
- //#endregion
63
- export { PixiCanvas };
64
- //# sourceMappingURL=pixi-canvas.js.map
32
+ export {
33
+ q as PixiCanvas
34
+ };
35
+ //# sourceMappingURL=pixi-canvas.js.map
@@ -1 +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","undefined","Error","previousResizeTo","resizeTo","resizeObserver","ResizeObserver","queueResize","observe","disconnect","_el$","_tmpl$","_ref$","_$use","_$insert","_$effect","_p$","_v$","_v$2","e","_$style","t","_$className"],"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` 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 = usePixiApp();\n pixiApp.canvas.style.display = \"block\";\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 ...(typeof props.style === \"object\" ? props.style : {}),\n }}\n class={props.className}\n >\n {pixiApp.canvas}\n </div>\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAiBA,MAAaK,cAAcC,UAIR;CACjB,IAAIM;CAEJ,MAAME,UAAUV,YAAY;AAC5BU,SAAQC,OAAON,MAAMO,UAAU;AAE/Bf,0BAAyB;AACvB,MAAIK,MAAMC,aAAaU,OACrB,OAAM,IAAIC,MAAM,2DAA2D;GAE7E;CAEF,IAAIC;CACJ,IAAIE;AAEJlB,eAAc;AACZ,MAAI,CAACS,kBAAmB;AACxBO,qBAAmBL,QAAQM;AAC3BN,UAAQM,WAAWR;AACnBE,UAAQS,aAAa;AACrBF,mBAAiB,IAAIC,qBAAqB;AACxCR,WAAQS,aAAa;IACrB;AACFF,iBAAeG,QAAQZ,kBAAkB;GACzC;AAEFV,iBAAgB;AACd,MAAI,CAACU,kBAAmB;AACxBE,UAAQM,WAAWD;AACnBE,kBAAgBI,YAAY;AAC5BJ,mBAAiBJ;GACjB;AAEF,eAAA;EAAA,IAAAS,OAAAC,QAAA;EAAA,IAAAC,QAEShB;AAAiB,SAAAgB,UAAA,aAAAC,IAAAD,OAAAF,KAAA,GAAjBd,oBAAiBc;AAAAI,SAAAJ,YAMrBZ,QAAQC,OAAM;AAAAgB,UAAAC,QAAA;GAAA,IAAAC,MALR,EACL,GAAI,OAAO3B,MAAMG,UAAU,WAAWH,MAAMG,QAAQ,EAAE,EACvD,EAAAyB,OACM5B,MAAMK;AAASqB,OAAAG,IAAAC,MAAAV,MAAAO,KAAAD,IAAAG,EAAA;AAAAD,YAAAF,IAAAK,KAAAC,UAAAZ,MAAAM,IAAAK,IAAAH,KAAA;AAAA,UAAAF;KAAA;GAAAG,GAAAlB;GAAAoB,GAAApB;GAAA,CAAA;AAAA,SAAAS;KAAA"}
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 { 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` 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 = usePixiApp();\n pixiApp.canvas.style.display = \"block\";\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 ...(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","usePixiApp","canvas","style","display","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,IAAaA,CAACC,MAIR;AACjB,MAAIC;AAEJ,QAAMC,IAAUC,EAAAA;AAChBD,EAAAA,EAAQE,OAAOC,MAAMC,UAAU,SAE/BC,EAAmB,MAAM;AACvB,QAAIP,EAAMQ,aAAaC;AACrB,YAAM,IAAIC,MAAM,0DAA0D;AAAA,EAE9E,CAAC;AAED,MAAIC,GACAC;AAEJC,SAAAA,EAAQ,MAAM;AACZ,IAAKZ,MACLU,IAAmBT,EAAQY,UAC3BZ,EAAQY,WAAWb,GACnBC,EAAQa,YAAAA,GACRH,IAAiB,IAAII,eAAe,MAAM;AACxCd,MAAAA,EAAQa,YAAAA;AAAAA,IACV,CAAC,GACDH,EAAeK,QAAQhB,CAAiB;AAAA,EAC1C,CAAC,GAEDiB,EAAU,MAAM;AACd,IAAKjB,MACLC,EAAQY,WAAWH,GACnBC,GAAgBO,WAAAA,GAChBP,IAAiBH;AAAAA,EACnB,CAAC,IAED,MAAA;AAAA,QAAAW,IAAAC,EAAAA,GAAAC,IAESrB;AAAiB,kBAAAqB,KAAA,aAAAC,EAAAD,GAAAF,CAAA,IAAjBnB,IAAiBmB,GAAAI,EAAAJ,GAAA,MAMrBlB,EAAQE,MAAM,GAAAqB,EAAAC,CAAAA,MAAA;AAAA,UAAAC,IALR;AAAA,QACL,GAAI,OAAO3B,EAAMK,SAAU,WAAWL,EAAMK,QAAQ,CAAA;AAAA,MAAC,GACtDuB,IACM5B,EAAM6B;AAASH,aAAAA,EAAAI,IAAAC,EAAAX,GAAAO,GAAAD,EAAAI,CAAA,GAAAF,MAAAF,EAAAM,KAAAC,EAAAb,GAAAM,EAAAM,IAAAJ,CAAA,GAAAF;AAAAA,IAAA,GAAA;AAAA,MAAAI,GAAArB;AAAAA,MAAAuB,GAAAvB;AAAAA,IAAAA,CAAA,GAAAW;AAAAA,EAAA,GAAA;AAK5B;"}
@@ -1,118 +1,49 @@
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
- }
1
+ import { RenderContainer as l, RenderLayer as S, AnimatedSprite as h, BitmapText as m, Container as P, Graphics as d, HTMLText as M, MeshPlane as T, MeshRope as $, MeshSimple as f, NineSliceSprite as C, ParticleContainer as R, PerspectiveMesh as x, Sprite as L, Text as u, TilingSprite as E } from "pixi.js";
2
+ import { splitProps as N, createRenderEffect as s, on as _ } from "solid-js";
3
+ import { PIXI_SOLID_EVENT_HANDLER_NAMES as y } from "./pixi-events.js";
4
+ import { insert as A, setProp as c } from "./renderer.js";
5
+ const H = ["ref", "as", "children"], p = (i, n, r) => {
6
+ for (const t in n)
7
+ if (t !== "as")
8
+ if (t === "ref")
9
+ s(() => {
10
+ n[t](i);
11
+ });
12
+ else if (t === "children") {
13
+ if (!("addChild" in i))
14
+ throw new Error("Cannot set children on non-container instance.");
15
+ s(() => {
16
+ A(i, () => n.children);
17
+ });
18
+ } else r ? s(_(() => n[t], () => {
19
+ c(i, t, n[t]);
20
+ }, {
21
+ defer: r
22
+ })) : s(() => {
23
+ c(i, t, n[t]);
24
+ });
25
+ }, o = (i) => (n) => {
26
+ const [r, t] = N(n, [...H, ...y]), a = n.as || new i(t);
27
+ return p(a, t, !0), p(a, r), a;
28
+ }, e = (i) => (n) => o(i)(n), B = e(h), D = e(m), G = o(P), O = e(d), k = e(M), K = e(T), V = e($), X = e(f), Y = e(C), b = e(R), j = e(x), q = o(l), z = o(S), F = e(L), J = e(u), Q = e(E);
29
+ export {
30
+ B as AnimatedSprite,
31
+ D as BitmapText,
32
+ G as Container,
33
+ O as Graphics,
34
+ k as HTMLText,
35
+ K as MeshPlane,
36
+ V as MeshRope,
37
+ X as MeshSimple,
38
+ Y as NineSliceSprite,
39
+ b as ParticleContainer,
40
+ j as PerspectiveMesh,
41
+ q as RenderContainer,
42
+ z as RenderLayer,
43
+ H as SOLID_PROP_KEYS,
44
+ F as Sprite,
45
+ J as Text,
46
+ Q as TilingSprite,
47
+ p as applyProps
33
48
  };
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
- const AnimatedSprite$1 = createLeafComponent(AnimatedSprite);
52
- /**
53
- * A SolidJS component that renders a `PIXI.BitmapText`.
54
- */
55
- const BitmapText$1 = createLeafComponent(BitmapText);
56
- /**
57
- * A SolidJS component that renders a `PIXI.Container`.
58
- */
59
- const Container$1 = createContainerComponent(Container);
60
- /**
61
- * A SolidJS component that renders a `PIXI.Graphics`.
62
- * Use a ref to access the underlying graphics instance and draw with it.
63
- */
64
- const Graphics$1 = createLeafComponent(Graphics);
65
- /**
66
- * A SolidJS component that renders a `PIXI.HTMLText`.
67
- */
68
- const HTMLText$1 = createLeafComponent(HTMLText);
69
- /**
70
- * A SolidJS component that renders a `PIXI.MeshPlane`.
71
- */
72
- const MeshPlane$1 = createLeafComponent(MeshPlane);
73
- /**
74
- * A SolidJS component that renders a `PIXI.MeshRope`.
75
- */
76
- const MeshRope$1 = createLeafComponent(MeshRope);
77
- /**
78
- * A SolidJS component that renders a `PIXI.MeshSimple`.
79
- */
80
- const MeshSimple$1 = createLeafComponent(MeshSimple);
81
- /**
82
- * A SolidJS component that renders a `PIXI.NineSliceSprite`.
83
- */
84
- const NineSliceSprite$1 = createLeafComponent(NineSliceSprite);
85
- /**
86
- * A SolidJS component that renders a `PIXI.ParticleContainer`.
87
- *
88
- * Particles should be added and removed from this component imperatively. Please see the docs for a reference example.
89
- */
90
- const ParticleContainer$1 = createLeafComponent(ParticleContainer);
91
- /**
92
- * A SolidJS component that renders a `PIXI.PerspectiveMesh`.
93
- */
94
- const PerspectiveMesh$1 = createLeafComponent(PerspectiveMesh);
95
- /**
96
- * A SolidJS component that renders a `PIXI.RenderContainer`.
97
- */
98
- const RenderContainer$1 = createContainerComponent(RenderContainer);
99
- /**
100
- * A SolidJS component that renders a `PIXI.RenderLayer`.
101
- */
102
- const RenderLayer$1 = createContainerComponent(RenderLayer);
103
- /**
104
- * A SolidJS component that renders a `PIXI.Sprite`.
105
- */
106
- const Sprite$1 = createLeafComponent(Sprite);
107
- /**
108
- * A SolidJS component that renders a `PIXI.Text`.
109
- */
110
- const Text$1 = createLeafComponent(Text);
111
- /**
112
- * A SolidJS component that renders a `PIXI.TilingSprite`.
113
- */
114
- const TilingSprite$1 = createLeafComponent(TilingSprite);
115
-
116
- //#endregion
117
- 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 };
118
- //# sourceMappingURL=pixi-components.js.map
49
+ //# sourceMappingURL=pixi-components.js.map
@@ -1 +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","ConstructorParameters","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 = <InstanceType extends PixiContainer, OptionsType extends ContainerProps<InstanceType>>(\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, [...SOLID_PROP_KEYS, ...PIXI_EVENT_HANDLER_NAMES]);\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 */\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// 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,cACXE,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,CAAC,GAAGL,iBAAiB,GAAGX,yBAAyB,CAAC;EAEhH,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;;;;;;AAOxF,MAAarD,mBAAiB8D,oBAAoE7D,eAAmB;;;;AAIrH,MAAaC,eAAa4D,oBACxB3D,WACD;;;;AAID,MAAaC,cAAYsD,yBAA+DrD,UAAc;;;;;AAKtG,MAAaC,aAAWwD,oBAAwDvD,SAAa;;;;AAI7F,MAAaC,aAAWsD,oBAAwDrD,SAAa;;;;AAK7F,MAAaC,cAAYoD,oBAA0DnD,UAAc;;;;AAKjG,MAAaC,aAAWkD,oBAAwDjD,SAAa;;;;AAK7F,MAAaC,eAAagD,oBAA4D/C,WAAe;;;;AAKrG,MAAaC,oBAAkB8C,oBAC7B7C,gBACD;;;;;;AAOD,MAAaC,sBAAoB4C,oBAC/B3C,kBACD;;;;AAKD,MAAaC,oBAAkB0C,oBAC7BzC,gBACD;;;;AAKD,MAAaC,oBAAkBoC,yBAC7BnC,gBACD;;;;AAKD,MAAaC,gBAAckC,yBAAmEjC,YAAgB;;;;AAK9G,MAAaC,WAASoC,oBAAoDnC,OAAW;;;;AAIrF,MAAaC,SAAOkC,oBAAsDjC,KAAS;;;;AAKnF,MAAaC,iBAAegC,oBAAgE/B,aAAiB"}
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>): 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 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 */\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,IAAkB,CAAC,OAAO,MAAM,UAAU,GAW1CC,IAAa,CACxBC,GACAC,GACAC,MACG;AACH,aAAWC,KAAOF;AAChB,QAAIE,MAAQ;AAEZ,UAAIA,MAAQ;AACVC,QAAAA,EAAmB,MAAM;AAEtBH,UAAAA,EAAME,CAAG,EAAoCH,CAAQ;AAAA,QACxD,CAAC;AAAA,eACQG,MAAQ,YAAY;AAC7B,YAAI,EAAE,cAAcH;AAClB,gBAAM,IAAIK,MAAM,gDAAgD;AAElED,QAAAA,EAAmB,MAAM;AACvBE,UAAAA,EAAON,GAAU,MAAMC,EAAMM,QAAQ;AAAA,QACvC,CAAC;AAAA,MACH,OAAWL,IACTE,EACEI,EACE,MAAMP,EAAME,CAAyB,GACrC,MAAM;AACJM,QAAAA,EAAQT,GAAUG,GAAKF,EAAME,CAAyB,CAAC;AAAA,MACzD,GACA;AAAA,QAAED,OAAAA;AAAAA,MAAAA,CACJ,CACF,IAEAE,EAAmB,MAAM;AACvBK,QAAAA,EAAQT,GAAUG,GAAKF,EAAME,CAAyB,CAAC;AAAA,MACzD,CAAC;AAGP,GAEMO,IAA2B,CAC/BC,MAEO,CAACV,MAAqF;AAC3F,QAAM,CAACW,GAAcC,CAAmB,IAAIC,EAAWb,GAAO,CAC5D,GAAGH,GACH,GAAGiB,CAA8B,CAClC,GAEKf,IAAWC,EAAMe,MAAM,IAAIL,EAAUE,CAA0B;AAErEd,SAAAA,EAAWC,GAAUa,GAAqB,EAAI,GAC9Cd,EAAWC,GAAUY,CAAY,GAE1BZ;AACT,GAGIiB,IAAsB,CAC1BN,MAEO,CAACV,MACCS,EAAqDC,CAAS,EAAEV,CAAY,GAO1EiB,IAAiBD,EAAoEE,CAAkB,GAIvGC,IAAaH,EACxBI,CACF,GAIaC,IAAYZ,EAA+Da,CAAa,GAKxFC,IAAWP,EAAwDQ,CAAY,GAI/EC,IAAWT,EAAwDU,CAAY,GAK/EC,IAAYX,EAA0DY,CAAa,GAKnFC,IAAWb,EAAwDc,CAAY,GAK/EC,IAAaf,EAA4DgB,CAAc,GAKvFC,IAAkBjB,EAC7BkB,CACF,GAOaC,IAAoBnB,EAC/BoB,CACF,GAKaC,IAAkBrB,EAC7BsB,CACF,GAKaC,IAAkB9B,EAC7B+B,CACF,GAKaC,IAAchC,EAAmEiC,CAAe,GAKhGC,IAAS3B,EAAoD4B,CAAU,GAIvEC,IAAO7B,EAAsD8B,CAAQ,GAKrEC,IAAe/B,EAAgEgC,CAAgB;"}