pixi-solid 0.1.19 → 0.1.21

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 CHANGED
@@ -14,11 +14,7 @@ A custom renderer for [PixiJS](https://pixijs.com/) that lets you build your sce
14
14
  - 💫 Useful helper utilities included.
15
15
  - 🤩 Full Typescript support for type safety and auto completion.
16
16
 
17
- Take a look at the [docs site 🧑‍💻](https://lukecarlthompson.github.io/pixi-solid/) for more information.
18
-
19
- ---
20
-
21
- ### Install
17
+ ## Install
22
18
 
23
19
  ```bash
24
20
  npm i pixi-solid pixi.js solid-js
@@ -28,33 +24,60 @@ Peer dependencies of
28
24
 
29
25
  ```json
30
26
  {
31
- "pixi.js": "^8.14.3",
32
- "solid-js": "^1.9.10"
27
+ "pixi.js": ">=8.14.3 <9",
28
+ "solid-js": ">=1.9.10 <2"
33
29
  }
34
30
  ```
35
31
 
36
- ---
32
+ ## Basic usage
33
+
34
+ ```tsx
35
+ import { PixiCanvas, Sprite } from "pixi-solid";
36
+ import { createSignal } from "solid-js";
37
+ import { Texture } from "pixi.js";
38
+
39
+ export const DemoApp = () => {
40
+ const [scale, setScale] = createSignal(10);
41
+
42
+ const handleSpriteTap = () => {
43
+ setScale((currentScale) => currentScale + 1);
44
+ };
45
+
46
+ return (
47
+ <PixiCanvas style={{ width: "100%", height: "100vh" }}>
48
+ <Sprite
49
+ texture={Texture.WHITE}
50
+ scale={scale()}
51
+ onpointertap={handleSpriteTap}
52
+ tint="#ff0000"
53
+ />
54
+ </PixiCanvas>
55
+ );
56
+ };
57
+ ```
58
+
59
+ ## Documentation and examples
60
+
61
+ Check out the [documentation site 🧑‍💻](https://lukecarlthompson.github.io/pixi-solid/) for more comprehensive information and live examples.
37
62
 
38
- ### Why combine SolidJS with PixiJS?
63
+ ## Why combine SolidJS with PixiJS?
39
64
 
40
- - **Declarative PixiJS scene graph**: Using SolidJS's JSX templating means we get declarative control over the scene graph. No longer necessary to imperatively add and remove children.
65
+ - **Declarative PixiJS scene graph**: Using SolidJS's JSX templating means we get declarative control over the scene graph. For improved separation of concerns, simpler views and more scalable projects.
41
66
 
42
- - **Lifecycle hooks in our PixiJS components**: SolidJS rendering PixiJS components means we can take advantage of the built in lifecycle methods in SolidJS `onMount` and `onCleanup` as well as few extra custom hooks so we can automatically subscribe and unsubscribe from the ticker.
67
+ - **SolidJS hooks in our PixiJS components**: SolidJS rendering PixiJS components means we can take advantage of the built in lifecycle methods in SolidJS `onMount`, `onCleanup` as well as extra custom hooks for responsive behaviour and ticker subscriptions.
43
68
 
44
- - **Shared State and Reactivity**: Pixi Solid leverages SolidJS's reactivity system to automatically update PixiJS components when SolidJS signals or stores change. So your HTML and PixiJS graphics can stay in sync effortlessly.
69
+ - **Shared State and Reactivity**: HTML and PixiJS graphics can stay in sync effortlessly because they can subscribe to the same state.
45
70
 
46
- - **Combine the best of both worlds**: Pixi Solid makes it easy to use HTML elements alongside a PixiJS canvas, allowing you to create rich user interfaces that combine the strengths of both technologies.
71
+ - **Combine the best of both worlds**: Pixi Solid makes it easy to use HTML elements alongside or on top of a PixiJS canvas, allowing you to create rich user interfaces that combine the strengths of both technologies.
47
72
 
48
73
  - **Composability**: Pixi Solid components can be easily composed together to create complex scenes and animations out of reusable components.
49
74
 
50
75
  - **SolidJS is a thin wrapper**: While Pixi Solid provides a nice abstraction over PixiJS it provides access to all the properties and events of PixiJS objects.
51
76
 
52
- - **SolidJS is really fast**: SolidJs is on of the fastest front-end frameworks out there so the overhead is very minimal.
77
+ - **SolidJS is really fast**: SolidJS is one of the fastest front-end frameworks out there so the overhead is very minimal.
53
78
 
54
79
  - **SolidJS is fully featured**: It has stores, signals, suspense, error boundaries, resource fetching and more. It's a great feature set for simple or complex applications and you won't have to reach for other libraries to manage templating or state.
55
80
 
56
- ---
57
-
58
81
  ## Contributing
59
82
 
60
83
  Contributions are welcome! This project is still in its early stages, so feel free to open an issue to report a bug, suggest a feature, or submit a pull request.
@@ -1 +1 @@
1
- {"version":3,"file":"component-factories.js","names":[],"sources":["../../src/components/component-factories.ts"],"sourcesContent":["import type * as Pixi from \"pixi.js\";\nimport type { JSX, Ref } from \"solid-js\";\nimport { createRenderEffect, on, splitProps, onCleanup } from \"solid-js\";\n\nimport { getTicker } from \"../pixi-application\";\n\nimport { bindInitialisationProps, bindRuntimeProps } from \"./bind-props\";\nimport type { PixiSolidEventHandlerMap } from \"./bind-props/event-names\";\nimport { PIXI_SOLID_EVENT_HANDLER_NAMES } from \"./bind-props/event-names\";\nimport type {\n CommonPointAxisPropName,\n AnchorPointAxisPropName,\n TilingPointAxisPropName,\n} from \"./bind-props/point-property-names\";\nimport {\n COMMON_POINT_PROP_AXIS_NAMES,\n ANCHOR_POINT_PROP_AXIS_NAMES,\n TILING_POINT_PROP_AXIS_NAMES,\n} from \"./bind-props/point-property-names\";\n\n/**\n * Common point axis properties available on all Container-based components\n */\nexport type CommonPointAxisProps = Partial<Record<CommonPointAxisPropName, number>>;\n\n/**\n * Anchor point axis properties available on Sprite-like components\n */\nexport type AnchorPointAxisProps = Partial<Record<AnchorPointAxisPropName, number>>;\n\n/**\n * Tiling point axis properties available on TilingSprite\n */\nexport type TilingPointAxisProps = Partial<Record<TilingPointAxisPropName, number>>;\n\n/**\n * This is a utility type useful for extending the props of custom components to allow props to be passed through to the underlying Pixi instance.\n *\n * If you don't require them all it's recommended to narrow the type by using Pick or Omit the props to only allow the ones you need.\n *\n * @example PixiComponentProps<Pixi.SpriteOptions>.\n */\nexport type PixiComponentProps<\n ComponentOptions extends Pixi.ContainerOptions = Pixi.ContainerOptions,\n> = PixiSolidEventHandlerMap & CommonPointAxisProps & Omit<ComponentOptions, \"children\">;\n\n/**\n * Prop definition for basic Container components (position, scale, pivot, skew only)\n */\nexport type ContainerProps<Component> = PixiSolidEventHandlerMap &\n CommonPointAxisProps &\n Record<string, unknown> & {\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/**\n * Prop definition for Sprite-like components (includes anchor properties)\n */\nexport type SpriteProps<Component> = PixiSolidEventHandlerMap &\n CommonPointAxisProps &\n AnchorPointAxisProps & {\n ref?: Ref<Component>;\n as?: Component;\n };\n\nexport type AnimatedSpriteProps<Component> = SpriteProps<Component> &\n Pick<Pixi.AnimatedSpriteOptions, \"autoUpdate\">;\n\ntype AnimatedSpriteLike = Pixi.Container & {\n autoUpdate: boolean;\n update: (ticker: Pixi.Ticker) => void;\n};\n\n/**\n * Prop definition for TilingSprite (includes anchor and tiling properties)\n */\nexport type TilingSpriteProps<Component> = PixiSolidEventHandlerMap &\n CommonPointAxisProps &\n AnchorPointAxisProps &\n TilingPointAxisProps & {\n ref?: Ref<Component>;\n as?: Component;\n };\n\n/**\n * Prop definition for filter components\n */\nexport type FilterProps<Component> = {\n ref?: Ref<Component>;\n as?: Component;\n};\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// Combined keys for splitting props\nconst CONTAINER_RUNTIME_KEYS = [\n ...SOLID_PROP_KEYS,\n ...PIXI_SOLID_EVENT_HANDLER_NAMES,\n ...COMMON_POINT_PROP_AXIS_NAMES,\n] as const;\n\n// Sprite components don't accept \"children\" since they can't have children\nconst SPRITE_RUNTIME_KEYS = [\n \"ref\",\n \"as\",\n ...PIXI_SOLID_EVENT_HANDLER_NAMES,\n ...COMMON_POINT_PROP_AXIS_NAMES,\n ...ANCHOR_POINT_PROP_AXIS_NAMES,\n] as const;\n\nconst TILING_SPRITE_RUNTIME_KEYS = [\n \"ref\",\n \"as\",\n ...PIXI_SOLID_EVENT_HANDLER_NAMES,\n ...COMMON_POINT_PROP_AXIS_NAMES,\n ...ANCHOR_POINT_PROP_AXIS_NAMES,\n ...TILING_POINT_PROP_AXIS_NAMES,\n] as const;\n\nexport const createContainerComponent = <\n InstanceType extends Pixi.Container,\n OptionsType extends object,\n>(\n PixiClass: new (props: OptionsType) => InstanceType,\n): ((\n props: Omit<OptionsType, \"children\"> & ContainerProps<InstanceType>,\n) => InstanceType & JSX.Element) => {\n return (props): InstanceType & JSX.Element => {\n const [runtimeProps, initialisationProps] = splitProps(props, CONTAINER_RUNTIME_KEYS);\n\n const instance = props.as || new PixiClass(initialisationProps as any);\n\n bindInitialisationProps(instance, initialisationProps);\n bindRuntimeProps(instance, runtimeProps);\n\n onCleanup(() => {\n if (\"attach\" in instance) {\n // Means it's a render layer so we don't want to destroy children as they are managed elsewhere in the tree.\n instance.destroy({ children: false });\n } else {\n instance.destroy({ children: true });\n }\n });\n\n return instance as InstanceType & JSX.Element;\n };\n};\n\nexport const createLeafComponent = <\n InstanceType extends Pixi.Container,\n OptionsType extends object,\n>(\n PixiClass: new (props: OptionsType) => InstanceType,\n) => {\n return (\n props: Omit<OptionsType, \"children\"> & LeafProps<InstanceType>,\n ): InstanceType & JSX.Element => {\n return createContainerComponent<InstanceType, OptionsType>(PixiClass)(props);\n };\n};\n\nexport const createSpriteComponent = <\n InstanceType extends Pixi.Container,\n OptionsType extends object,\n>(\n PixiClass: new (props: OptionsType) => InstanceType,\n) => {\n return (\n props: Omit<OptionsType, \"children\"> & SpriteProps<InstanceType>,\n ): InstanceType & JSX.Element => {\n const [runtimeProps, initialisationProps] = splitProps(props, SPRITE_RUNTIME_KEYS);\n\n const instance = props.as || new PixiClass(initialisationProps as any);\n\n bindInitialisationProps(instance, initialisationProps);\n bindRuntimeProps(instance, runtimeProps);\n\n onCleanup(() => {\n instance.destroy({ children: true });\n });\n\n return instance as InstanceType & JSX.Element;\n };\n};\n\nexport const createAnimatedSpriteComponent = <\n InstanceType extends AnimatedSpriteLike,\n OptionsType extends object,\n>(\n PixiClass: new (props: OptionsType) => InstanceType,\n) => {\n return (\n props: Omit<OptionsType, \"children\"> & AnimatedSpriteProps<InstanceType>,\n ): InstanceType & JSX.Element => {\n // Specifically separate `autoUpdate` as we handle it manually below.\n const [runtimeProps, update, initialisationProps] = splitProps(props, SPRITE_RUNTIME_KEYS, [\n \"autoUpdate\",\n ]);\n\n const instance = props.as || new PixiClass(initialisationProps as any);\n\n // Set this to false to override Pixi's default shared ticker behaviour.\n instance.autoUpdate = false;\n\n createRenderEffect(\n on(\n () => update.autoUpdate,\n (autoUpdate) => {\n const updateInstance = (ticker: Pixi.Ticker) => {\n instance.update(ticker);\n };\n\n if (autoUpdate !== false) {\n const ticker = getTicker();\n ticker.add(updateInstance);\n onCleanup(() => {\n ticker.remove(updateInstance);\n });\n }\n },\n ),\n );\n\n bindInitialisationProps(instance, initialisationProps);\n bindRuntimeProps(instance, runtimeProps);\n\n onCleanup(() => {\n instance.destroy({ children: true });\n });\n\n return instance as InstanceType & JSX.Element;\n };\n};\n\nexport const createTilingSpriteComponent = <\n InstanceType extends Pixi.Container,\n OptionsType extends object,\n>(\n PixiClass: new (props: OptionsType) => InstanceType,\n) => {\n return (\n props: Omit<OptionsType, \"children\"> & TilingSpriteProps<InstanceType>,\n ): InstanceType & JSX.Element => {\n const [runtimeProps, initialisationProps] = splitProps(props, TILING_SPRITE_RUNTIME_KEYS);\n\n const instance = props.as || new PixiClass(initialisationProps as any);\n\n bindInitialisationProps(instance, initialisationProps);\n bindRuntimeProps(instance, runtimeProps);\n\n onCleanup(() => {\n instance.destroy({ children: true });\n });\n\n return instance as InstanceType & JSX.Element;\n };\n};\n\nexport const createFilterComponent = <InstanceType extends Pixi.Filter, OptionsType extends object>(\n PixiClass: new (props: OptionsType) => InstanceType,\n) => {\n return (props: OptionsType & FilterProps<InstanceType>): InstanceType & JSX.Element => {\n const [runtimeProps, initialisationProps] = splitProps(props, [\"ref\", \"as\"]);\n\n const instance = props.as || new PixiClass(initialisationProps as any);\n\n for (const key in initialisationProps) {\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 throw new Error(`Cannot set children on non-container instance.`);\n } else {\n createRenderEffect(\n on(\n () => props[key as keyof typeof initialisationProps],\n () => {\n (instance as any)[key] = initialisationProps[key];\n },\n { defer: true },\n ),\n );\n }\n }\n\n for (const key in runtimeProps) {\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 }\n }\n\n onCleanup(() => {\n instance.destroy();\n });\n\n return instance as InstanceType & JSX.Element;\n };\n};\n"],"mappings":";;;;;AAuGA,IAAM,yBAAyB;CAC7B,GAAG;EAJ2B;EAAO;EAAM;EAIxC;CACH,GAAG;CACH,GAAG;CACJ;AAGD,IAAM,sBAAsB;CAC1B;CACA;CACA,GAAG;CACH,GAAG;CACH,GAAG;CACJ;AAED,IAAM,6BAA6B;CACjC;CACA;CACA,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACJ;AAED,IAAa,4BAIX,cAGkC;AAClC,SAAQ,UAAsC;EAC5C,MAAM,CAAC,cAAc,uBAAuB,WAAW,OAAO,uBAAuB;EAErF,MAAM,WAAW,MAAM,MAAM,IAAI,UAAU,oBAA2B;AAEtE,0BAAwB,UAAU,oBAAoB;AACtD,mBAAiB,UAAU,aAAa;AAExC,kBAAgB;AACd,OAAI,YAAY,SAEd,UAAS,QAAQ,EAAE,UAAU,OAAO,CAAC;OAErC,UAAS,QAAQ,EAAE,UAAU,MAAM,CAAC;IAEtC;AAEF,SAAO;;;AAIX,IAAa,uBAIX,cACG;AACH,SACE,UAC+B;AAC/B,SAAO,yBAAoD,UAAU,CAAC,MAAM;;;AAIhF,IAAa,yBAIX,cACG;AACH,SACE,UAC+B;EAC/B,MAAM,CAAC,cAAc,uBAAuB,WAAW,OAAO,oBAAoB;EAElF,MAAM,WAAW,MAAM,MAAM,IAAI,UAAU,oBAA2B;AAEtE,0BAAwB,UAAU,oBAAoB;AACtD,mBAAiB,UAAU,aAAa;AAExC,kBAAgB;AACd,YAAS,QAAQ,EAAE,UAAU,MAAM,CAAC;IACpC;AAEF,SAAO;;;AAIX,IAAa,iCAIX,cACG;AACH,SACE,UAC+B;EAE/B,MAAM,CAAC,cAAc,QAAQ,uBAAuB,WAAW,OAAO,qBAAqB,CACzF,aACD,CAAC;EAEF,MAAM,WAAW,MAAM,MAAM,IAAI,UAAU,oBAA2B;AAGtE,WAAS,aAAa;AAEtB,qBACE,SACQ,OAAO,aACZ,eAAe;GACd,MAAM,kBAAkB,WAAwB;AAC9C,aAAS,OAAO,OAAO;;AAGzB,OAAI,eAAe,OAAO;IACxB,MAAM,SAAS,WAAW;AAC1B,WAAO,IAAI,eAAe;AAC1B,oBAAgB;AACd,YAAO,OAAO,eAAe;MAC7B;;IAGP,CACF;AAED,0BAAwB,UAAU,oBAAoB;AACtD,mBAAiB,UAAU,aAAa;AAExC,kBAAgB;AACd,YAAS,QAAQ,EAAE,UAAU,MAAM,CAAC;IACpC;AAEF,SAAO;;;AAIX,IAAa,+BAIX,cACG;AACH,SACE,UAC+B;EAC/B,MAAM,CAAC,cAAc,uBAAuB,WAAW,OAAO,2BAA2B;EAEzF,MAAM,WAAW,MAAM,MAAM,IAAI,UAAU,oBAA2B;AAEtE,0BAAwB,UAAU,oBAAoB;AACtD,mBAAiB,UAAU,aAAa;AAExC,kBAAgB;AACd,YAAS,QAAQ,EAAE,UAAU,MAAM,CAAC;IACpC;AAEF,SAAO"}
1
+ {"version":3,"file":"component-factories.js","names":[],"sources":["../../src/components/component-factories.ts"],"sourcesContent":["import type * as Pixi from \"pixi.js\";\nimport type { JSX, Ref } from \"solid-js\";\nimport { createRenderEffect, on, splitProps, onCleanup } from \"solid-js\";\n\nimport { getTicker } from \"../pixi-application\";\n\nimport { bindInitialisationProps, bindRuntimeProps } from \"./bind-props\";\nimport type { PixiSolidEventHandlerMap } from \"./bind-props/event-names\";\nimport { PIXI_SOLID_EVENT_HANDLER_NAMES } from \"./bind-props/event-names\";\nimport type {\n CommonPointAxisPropName,\n AnchorPointAxisPropName,\n TilingPointAxisPropName,\n} from \"./bind-props/point-property-names\";\nimport {\n COMMON_POINT_PROP_AXIS_NAMES,\n ANCHOR_POINT_PROP_AXIS_NAMES,\n TILING_POINT_PROP_AXIS_NAMES,\n} from \"./bind-props/point-property-names\";\n\n/**\n * Common point axis properties available on all Container-based components\n */\nexport type CommonPointAxisProps = Partial<Record<CommonPointAxisPropName, number>>;\n\n/**\n * Anchor point axis properties available on Sprite-like components\n */\nexport type AnchorPointAxisProps = Partial<Record<AnchorPointAxisPropName, number>>;\n\n/**\n * Tiling point axis properties available on TilingSprite\n */\nexport type TilingPointAxisProps = Partial<Record<TilingPointAxisPropName, number>>;\n\n/**\n * This is a utility type useful for extending the props of custom components to allow props to be passed through to the underlying Pixi instance.\n *\n * If you don't require them all it's recommended to narrow the type by using Pick or Omit the props to only allow the ones you need.\n *\n * @example PixiComponentProps<Pixi.SpriteOptions>.\n */\nexport type PixiComponentProps<\n ComponentOptions extends Pixi.ContainerOptions = Pixi.ContainerOptions,\n> = PixiSolidEventHandlerMap & CommonPointAxisProps & Omit<ComponentOptions, \"children\">;\n\ntype RefAsProps<Component> = {\n ref?: Ref<Component>;\n as?: Component;\n};\n\ntype PixiComponent<Props, Instance> = (props: Props) => Instance & JSX.Element;\n\n/**\n * Prop definition for basic Container components (position, scale, pivot, skew only)\n */\nexport type ContainerProps<Component> = PixiSolidEventHandlerMap &\n CommonPointAxisProps &\n RefAsProps<Component> & {\n children?: JSX.Element;\n };\n\n/**\n * Prop definition for components that cannot have children\n */\nexport type LeafProps<Component> = PixiSolidEventHandlerMap &\n CommonPointAxisProps &\n RefAsProps<Component>;\n\n/**\n * Prop definition for Sprite-like components (includes anchor properties)\n */\nexport type SpriteProps<Component> = PixiSolidEventHandlerMap &\n CommonPointAxisProps &\n AnchorPointAxisProps &\n RefAsProps<Component>;\n\nexport type AnimatedSpriteProps<Component> = SpriteProps<Component> &\n Pick<Pixi.AnimatedSpriteOptions, \"autoUpdate\">;\n\ntype AnimatedSpriteLike = Pixi.Container & {\n autoUpdate: boolean;\n update: (ticker: Pixi.Ticker) => void;\n};\n\n/**\n * Prop definition for TilingSprite (includes anchor and tiling properties)\n */\nexport type TilingSpriteProps<Component> = PixiSolidEventHandlerMap &\n CommonPointAxisProps &\n AnchorPointAxisProps &\n TilingPointAxisProps &\n RefAsProps<Component>;\n\n/**\n * Prop definition for filter components\n */\nexport type FilterProps<Component> = RefAsProps<Component>;\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// Combined keys for splitting props\nconst CONTAINER_RUNTIME_KEYS = [\n ...SOLID_PROP_KEYS,\n ...PIXI_SOLID_EVENT_HANDLER_NAMES,\n ...COMMON_POINT_PROP_AXIS_NAMES,\n] as const;\n\n// Sprite components don't accept \"children\" since they can't have children\nconst SPRITE_RUNTIME_KEYS = [\n \"ref\",\n \"as\",\n ...PIXI_SOLID_EVENT_HANDLER_NAMES,\n ...COMMON_POINT_PROP_AXIS_NAMES,\n ...ANCHOR_POINT_PROP_AXIS_NAMES,\n] as const;\n\nconst TILING_SPRITE_RUNTIME_KEYS = [\n \"ref\",\n \"as\",\n ...PIXI_SOLID_EVENT_HANDLER_NAMES,\n ...COMMON_POINT_PROP_AXIS_NAMES,\n ...ANCHOR_POINT_PROP_AXIS_NAMES,\n ...TILING_POINT_PROP_AXIS_NAMES,\n] as const;\n\nexport const createContainerComponent = <\n InstanceType extends Pixi.Container,\n OptionsType extends object,\n>(\n PixiClass: new (props: OptionsType) => InstanceType,\n): PixiComponent<Omit<OptionsType, \"children\"> & ContainerProps<InstanceType>, InstanceType> => {\n return (props): InstanceType & JSX.Element => {\n const [runtimeProps, initialisationProps] = splitProps(props, CONTAINER_RUNTIME_KEYS);\n\n const instance = props.as || new PixiClass(initialisationProps as any);\n\n bindInitialisationProps(instance, initialisationProps);\n bindRuntimeProps(instance, runtimeProps);\n\n onCleanup(() => {\n if (\"attach\" in instance) {\n // Means it's a render layer so we don't want to destroy children as they are managed elsewhere in the tree.\n instance.destroy({ children: false });\n } else {\n instance.destroy({ children: true });\n }\n });\n\n return instance as InstanceType & JSX.Element;\n };\n};\n\nexport const createLeafComponent = <\n InstanceType extends Pixi.Container,\n OptionsType extends object,\n>(\n PixiClass: new (props: OptionsType) => InstanceType,\n): PixiComponent<Omit<OptionsType, \"children\"> & LeafProps<InstanceType>, InstanceType> => {\n return (\n props: Omit<OptionsType, \"children\"> & LeafProps<InstanceType>,\n ): InstanceType & JSX.Element => {\n return createContainerComponent<InstanceType, OptionsType>(PixiClass)(props);\n };\n};\n\nexport const createSpriteComponent = <\n InstanceType extends Pixi.Container,\n OptionsType extends object,\n>(\n PixiClass: new (props: OptionsType) => InstanceType,\n): PixiComponent<Omit<OptionsType, \"children\"> & SpriteProps<InstanceType>, InstanceType> => {\n return (\n props: Omit<OptionsType, \"children\"> & SpriteProps<InstanceType>,\n ): InstanceType & JSX.Element => {\n const [runtimeProps, initialisationProps] = splitProps(props, SPRITE_RUNTIME_KEYS);\n\n const instance = props.as || new PixiClass(initialisationProps as any);\n\n bindInitialisationProps(instance, initialisationProps);\n bindRuntimeProps(instance, runtimeProps);\n\n onCleanup(() => {\n instance.destroy({ children: true });\n });\n\n return instance as InstanceType & JSX.Element;\n };\n};\n\nexport const createAnimatedSpriteComponent = <\n InstanceType extends AnimatedSpriteLike,\n OptionsType extends object,\n>(\n PixiClass: new (props: OptionsType) => InstanceType,\n): PixiComponent<\n Omit<OptionsType, \"children\"> & AnimatedSpriteProps<InstanceType>,\n InstanceType\n> => {\n return (\n props: Omit<OptionsType, \"children\"> & AnimatedSpriteProps<InstanceType>,\n ): InstanceType & JSX.Element => {\n // Specifically separate `autoUpdate` as we handle it manually below.\n const [runtimeProps, update, initialisationProps] = splitProps(props, SPRITE_RUNTIME_KEYS, [\n \"autoUpdate\",\n ]);\n\n const instance = props.as || new PixiClass(initialisationProps as any);\n\n // Set this to false to override Pixi's default shared ticker behaviour.\n instance.autoUpdate = false;\n\n createRenderEffect(\n on(\n () => update.autoUpdate,\n (autoUpdate) => {\n const updateInstance = (ticker: Pixi.Ticker) => {\n instance.update(ticker);\n };\n\n if (autoUpdate !== false) {\n const ticker = getTicker();\n ticker.add(updateInstance);\n onCleanup(() => {\n ticker.remove(updateInstance);\n });\n }\n },\n ),\n );\n\n bindInitialisationProps(instance, initialisationProps);\n bindRuntimeProps(instance, runtimeProps);\n\n onCleanup(() => {\n instance.destroy({ children: true });\n });\n\n return instance as InstanceType & JSX.Element;\n };\n};\n\nexport const createTilingSpriteComponent = <\n InstanceType extends Pixi.Container,\n OptionsType extends object,\n>(\n PixiClass: new (props: OptionsType) => InstanceType,\n): PixiComponent<Omit<OptionsType, \"children\"> & TilingSpriteProps<InstanceType>, InstanceType> => {\n return (\n props: Omit<OptionsType, \"children\"> & TilingSpriteProps<InstanceType>,\n ): InstanceType & JSX.Element => {\n const [runtimeProps, initialisationProps] = splitProps(props, TILING_SPRITE_RUNTIME_KEYS);\n\n const instance = props.as || new PixiClass(initialisationProps as any);\n\n bindInitialisationProps(instance, initialisationProps);\n bindRuntimeProps(instance, runtimeProps);\n\n onCleanup(() => {\n instance.destroy({ children: true });\n });\n\n return instance as InstanceType & JSX.Element;\n };\n};\n\nexport const createFilterComponent = <InstanceType extends Pixi.Filter, OptionsType extends object>(\n PixiClass: new (props: OptionsType) => InstanceType,\n): PixiComponent<OptionsType & FilterProps<InstanceType>, InstanceType> => {\n return (props: OptionsType & FilterProps<InstanceType>): InstanceType & JSX.Element => {\n const [runtimeProps, initialisationProps] = splitProps(props, [\"ref\", \"as\"]);\n\n const instance = props.as || new PixiClass(initialisationProps as any);\n\n for (const key in initialisationProps) {\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 throw new Error(`Cannot set children on non-container instance.`);\n } else {\n createRenderEffect(\n on(\n () => props[key as keyof typeof initialisationProps],\n () => {\n (instance as any)[key] = initialisationProps[key];\n },\n { defer: true },\n ),\n );\n }\n }\n\n for (const key in runtimeProps) {\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 }\n }\n\n onCleanup(() => {\n instance.destroy();\n });\n\n return instance as InstanceType & JSX.Element;\n };\n};\n"],"mappings":";;;;;AAuGA,IAAM,yBAAyB;CAC7B,GAAG;EAJ2B;EAAO;EAAM;EAIxC;CACH,GAAG;CACH,GAAG;CACJ;AAGD,IAAM,sBAAsB;CAC1B;CACA;CACA,GAAG;CACH,GAAG;CACH,GAAG;CACJ;AAED,IAAM,6BAA6B;CACjC;CACA;CACA,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACJ;AAED,IAAa,4BAIX,cAC8F;AAC9F,SAAQ,UAAsC;EAC5C,MAAM,CAAC,cAAc,uBAAuB,WAAW,OAAO,uBAAuB;EAErF,MAAM,WAAW,MAAM,MAAM,IAAI,UAAU,oBAA2B;AAEtE,0BAAwB,UAAU,oBAAoB;AACtD,mBAAiB,UAAU,aAAa;AAExC,kBAAgB;AACd,OAAI,YAAY,SAEd,UAAS,QAAQ,EAAE,UAAU,OAAO,CAAC;OAErC,UAAS,QAAQ,EAAE,UAAU,MAAM,CAAC;IAEtC;AAEF,SAAO;;;AAIX,IAAa,uBAIX,cACyF;AACzF,SACE,UAC+B;AAC/B,SAAO,yBAAoD,UAAU,CAAC,MAAM;;;AAIhF,IAAa,yBAIX,cAC2F;AAC3F,SACE,UAC+B;EAC/B,MAAM,CAAC,cAAc,uBAAuB,WAAW,OAAO,oBAAoB;EAElF,MAAM,WAAW,MAAM,MAAM,IAAI,UAAU,oBAA2B;AAEtE,0BAAwB,UAAU,oBAAoB;AACtD,mBAAiB,UAAU,aAAa;AAExC,kBAAgB;AACd,YAAS,QAAQ,EAAE,UAAU,MAAM,CAAC;IACpC;AAEF,SAAO;;;AAIX,IAAa,iCAIX,cAIG;AACH,SACE,UAC+B;EAE/B,MAAM,CAAC,cAAc,QAAQ,uBAAuB,WAAW,OAAO,qBAAqB,CACzF,aACD,CAAC;EAEF,MAAM,WAAW,MAAM,MAAM,IAAI,UAAU,oBAA2B;AAGtE,WAAS,aAAa;AAEtB,qBACE,SACQ,OAAO,aACZ,eAAe;GACd,MAAM,kBAAkB,WAAwB;AAC9C,aAAS,OAAO,OAAO;;AAGzB,OAAI,eAAe,OAAO;IACxB,MAAM,SAAS,WAAW;AAC1B,WAAO,IAAI,eAAe;AAC1B,oBAAgB;AACd,YAAO,OAAO,eAAe;MAC7B;;IAGP,CACF;AAED,0BAAwB,UAAU,oBAAoB;AACtD,mBAAiB,UAAU,aAAa;AAExC,kBAAgB;AACd,YAAS,QAAQ,EAAE,UAAU,MAAM,CAAC;IACpC;AAEF,SAAO;;;AAIX,IAAa,+BAIX,cACiG;AACjG,SACE,UAC+B;EAC/B,MAAM,CAAC,cAAc,uBAAuB,WAAW,OAAO,2BAA2B;EAEzF,MAAM,WAAW,MAAM,MAAM,IAAI,UAAU,oBAA2B;AAEtE,0BAAwB,UAAU,oBAAoB;AACtD,mBAAiB,UAAU,aAAa;AAExC,kBAAgB;AACd,YAAS,QAAQ,EAAE,UAAU,MAAM,CAAC;IACpC;AAEF,SAAO"}
@@ -22,25 +22,25 @@ export type TilingPointAxisProps = Partial<Record<TilingPointAxisPropName, numbe
22
22
  * @example PixiComponentProps<Pixi.SpriteOptions>.
23
23
  */
24
24
  export type PixiComponentProps<ComponentOptions extends Pixi.ContainerOptions = Pixi.ContainerOptions> = PixiSolidEventHandlerMap & CommonPointAxisProps & Omit<ComponentOptions, "children">;
25
+ type RefAsProps<Component> = {
26
+ ref?: Ref<Component>;
27
+ as?: Component;
28
+ };
29
+ type PixiComponent<Props, Instance> = (props: Props) => Instance & JSX.Element;
25
30
  /**
26
31
  * Prop definition for basic Container components (position, scale, pivot, skew only)
27
32
  */
28
- export type ContainerProps<Component> = PixiSolidEventHandlerMap & CommonPointAxisProps & Record<string, unknown> & {
29
- ref?: Ref<Component>;
30
- as?: Component;
33
+ export type ContainerProps<Component> = PixiSolidEventHandlerMap & CommonPointAxisProps & RefAsProps<Component> & {
31
34
  children?: JSX.Element;
32
35
  };
33
36
  /**
34
37
  * Prop definition for components that cannot have children
35
38
  */
36
- export type LeafProps<Component> = Omit<ContainerProps<Component>, "children">;
39
+ export type LeafProps<Component> = PixiSolidEventHandlerMap & CommonPointAxisProps & RefAsProps<Component>;
37
40
  /**
38
41
  * Prop definition for Sprite-like components (includes anchor properties)
39
42
  */
40
- export type SpriteProps<Component> = PixiSolidEventHandlerMap & CommonPointAxisProps & AnchorPointAxisProps & {
41
- ref?: Ref<Component>;
42
- as?: Component;
43
- };
43
+ export type SpriteProps<Component> = PixiSolidEventHandlerMap & CommonPointAxisProps & AnchorPointAxisProps & RefAsProps<Component>;
44
44
  export type AnimatedSpriteProps<Component> = SpriteProps<Component> & Pick<Pixi.AnimatedSpriteOptions, "autoUpdate">;
45
45
  type AnimatedSpriteLike = Pixi.Container & {
46
46
  autoUpdate: boolean;
@@ -49,22 +49,16 @@ type AnimatedSpriteLike = Pixi.Container & {
49
49
  /**
50
50
  * Prop definition for TilingSprite (includes anchor and tiling properties)
51
51
  */
52
- export type TilingSpriteProps<Component> = PixiSolidEventHandlerMap & CommonPointAxisProps & AnchorPointAxisProps & TilingPointAxisProps & {
53
- ref?: Ref<Component>;
54
- as?: Component;
55
- };
52
+ export type TilingSpriteProps<Component> = PixiSolidEventHandlerMap & CommonPointAxisProps & AnchorPointAxisProps & TilingPointAxisProps & RefAsProps<Component>;
56
53
  /**
57
54
  * Prop definition for filter components
58
55
  */
59
- export type FilterProps<Component> = {
60
- ref?: Ref<Component>;
61
- as?: Component;
62
- };
56
+ export type FilterProps<Component> = RefAsProps<Component>;
63
57
  export declare const SOLID_PROP_KEYS: readonly ["ref", "as", "children"];
64
- export declare const createContainerComponent: <InstanceType extends Pixi.Container, OptionsType extends object>(PixiClass: new (props: OptionsType) => InstanceType) => ((props: Omit<OptionsType, "children"> & ContainerProps<InstanceType>) => InstanceType & JSX.Element);
65
- export declare const createLeafComponent: <InstanceType extends Pixi.Container, OptionsType extends object>(PixiClass: new (props: OptionsType) => InstanceType) => (props: Omit<OptionsType, "children"> & LeafProps<InstanceType>) => InstanceType & JSX.Element;
66
- export declare const createSpriteComponent: <InstanceType extends Pixi.Container, OptionsType extends object>(PixiClass: new (props: OptionsType) => InstanceType) => (props: Omit<OptionsType, "children"> & SpriteProps<InstanceType>) => InstanceType & JSX.Element;
67
- export declare const createAnimatedSpriteComponent: <InstanceType extends AnimatedSpriteLike, OptionsType extends object>(PixiClass: new (props: OptionsType) => InstanceType) => (props: Omit<OptionsType, "children"> & AnimatedSpriteProps<InstanceType>) => InstanceType & JSX.Element;
68
- export declare const createTilingSpriteComponent: <InstanceType extends Pixi.Container, OptionsType extends object>(PixiClass: new (props: OptionsType) => InstanceType) => (props: Omit<OptionsType, "children"> & TilingSpriteProps<InstanceType>) => InstanceType & JSX.Element;
69
- export declare const createFilterComponent: <InstanceType extends Pixi.Filter, OptionsType extends object>(PixiClass: new (props: OptionsType) => InstanceType) => (props: OptionsType & FilterProps<InstanceType>) => InstanceType & JSX.Element;
58
+ export declare const createContainerComponent: <InstanceType extends Pixi.Container, OptionsType extends object>(PixiClass: new (props: OptionsType) => InstanceType) => PixiComponent<Omit<OptionsType, "children"> & ContainerProps<InstanceType>, InstanceType>;
59
+ export declare const createLeafComponent: <InstanceType extends Pixi.Container, OptionsType extends object>(PixiClass: new (props: OptionsType) => InstanceType) => PixiComponent<Omit<OptionsType, "children"> & LeafProps<InstanceType>, InstanceType>;
60
+ export declare const createSpriteComponent: <InstanceType extends Pixi.Container, OptionsType extends object>(PixiClass: new (props: OptionsType) => InstanceType) => PixiComponent<Omit<OptionsType, "children"> & SpriteProps<InstanceType>, InstanceType>;
61
+ export declare const createAnimatedSpriteComponent: <InstanceType extends AnimatedSpriteLike, OptionsType extends object>(PixiClass: new (props: OptionsType) => InstanceType) => PixiComponent<Omit<OptionsType, "children"> & AnimatedSpriteProps<InstanceType>, InstanceType>;
62
+ export declare const createTilingSpriteComponent: <InstanceType extends Pixi.Container, OptionsType extends object>(PixiClass: new (props: OptionsType) => InstanceType) => PixiComponent<Omit<OptionsType, "children"> & TilingSpriteProps<InstanceType>, InstanceType>;
63
+ export declare const createFilterComponent: <InstanceType extends Pixi.Filter, OptionsType extends object>(PixiClass: new (props: OptionsType) => InstanceType) => PixiComponent<OptionsType & FilterProps<InstanceType>, InstanceType>;
70
64
  export {};
@@ -16,16 +16,20 @@ export declare const BitmapText: (props: Omit<Pixi.TextOptions<Pixi.TextStyle, P
16
16
  /**
17
17
  * A SolidJS component that renders a `PIXI.Container`.
18
18
  */
19
- export declare const Container: (props: Omit<Pixi.ContainerOptions<Pixi.ContainerChild>, "children"> & import("./bind-props").PixiSolidEventHandlerMap & Partial<Record<"positionX" | "positionY" | "scaleX" | "scaleY" | "pivotX" | "pivotY" | "skewX" | "skewY", number>> & Record<string, unknown> & {
19
+ export declare const Container: (props: Omit<Pixi.ContainerOptions<Pixi.ContainerChild>, "children"> & import("./bind-props").PixiSolidEventHandlerMap & Partial<Record<"positionX" | "positionY" | "scaleX" | "scaleY" | "pivotX" | "pivotY" | "skewX" | "skewY", number>> & {
20
20
  ref?: import("solid-js").Ref<Pixi.Container<Pixi.ContainerChild>> | undefined;
21
21
  as?: Pixi.Container<Pixi.ContainerChild> | undefined;
22
+ } & {
22
23
  children?: import("solid-js").JSX.Element;
23
24
  }) => Pixi.Container<Pixi.ContainerChild> & import("solid-js").JSX.Element;
24
25
  /**
25
26
  * A SolidJS component that renders a `PIXI.Graphics`.
26
27
  * Use a ref to access the underlying graphics instance and draw with it.
27
28
  */
28
- export declare const Graphics: (props: Omit<Pixi.GraphicsOptions, "children"> & import("./component-factories").LeafProps<Pixi.Graphics>) => Pixi.Graphics & import("solid-js").JSX.Element;
29
+ export declare const Graphics: (props: Omit<Pixi.GraphicsOptions, "children"> & import("./bind-props").PixiSolidEventHandlerMap & Partial<Record<"positionX" | "positionY" | "scaleX" | "scaleY" | "pivotX" | "pivotY" | "skewX" | "skewY", number>> & {
30
+ ref?: import("solid-js").Ref<Pixi.Graphics> | undefined;
31
+ as?: Pixi.Graphics | undefined;
32
+ }) => Pixi.Graphics & import("solid-js").JSX.Element;
29
33
  /**
30
34
  * A SolidJS component that renders a `PIXI.HTMLText`.
31
35
  */
@@ -59,7 +63,10 @@ export declare const NineSliceSprite: (props: Omit<Pixi.NineSliceSpriteOptions,
59
63
  *
60
64
  * Particles should be added and removed from this component imperatively. Please see the docs for a reference example.
61
65
  */
62
- export declare const ParticleContainer: (props: Omit<Pixi.ParticleContainerOptions<Pixi.IParticle>, "children"> & import("./component-factories").LeafProps<Pixi.ParticleContainer<Pixi.IParticle>>) => Pixi.ParticleContainer<Pixi.IParticle> & import("solid-js").JSX.Element;
66
+ export declare const ParticleContainer: (props: Omit<Pixi.ParticleContainerOptions<Pixi.IParticle>, "children"> & import("./bind-props").PixiSolidEventHandlerMap & Partial<Record<"positionX" | "positionY" | "scaleX" | "scaleY" | "pivotX" | "pivotY" | "skewX" | "skewY", number>> & {
67
+ ref?: import("solid-js").Ref<Pixi.ParticleContainer<Pixi.IParticle>> | undefined;
68
+ as?: Pixi.ParticleContainer<Pixi.IParticle> | undefined;
69
+ }) => Pixi.ParticleContainer<Pixi.IParticle> & import("solid-js").JSX.Element;
63
70
  /**
64
71
  * A SolidJS component that renders a `PIXI.PerspectiveMesh`.
65
72
  */
@@ -70,17 +77,19 @@ export declare const PerspectiveMesh: (props: Omit<Pixi.PerspectivePlaneOptions,
70
77
  /**
71
78
  * A SolidJS component that renders a `PIXI.RenderContainer`.
72
79
  */
73
- export declare const RenderContainer: (props: Omit<Pixi.RenderContainerOptions, "children"> & import("./bind-props").PixiSolidEventHandlerMap & Partial<Record<"positionX" | "positionY" | "scaleX" | "scaleY" | "pivotX" | "pivotY" | "skewX" | "skewY", number>> & Record<string, unknown> & {
80
+ export declare const RenderContainer: (props: Omit<Pixi.RenderContainerOptions, "children"> & import("./bind-props").PixiSolidEventHandlerMap & Partial<Record<"positionX" | "positionY" | "scaleX" | "scaleY" | "pivotX" | "pivotY" | "skewX" | "skewY", number>> & {
74
81
  ref?: import("solid-js").Ref<Pixi.RenderContainer> | undefined;
75
82
  as?: Pixi.RenderContainer | undefined;
83
+ } & {
76
84
  children?: import("solid-js").JSX.Element;
77
85
  }) => Pixi.RenderContainer & import("solid-js").JSX.Element;
78
86
  /**
79
87
  * A SolidJS component that renders a `PIXI.RenderLayer`.
80
88
  */
81
- export declare const RenderLayer: (props: Omit<Pixi.RenderLayerOptions, "children"> & import("./bind-props").PixiSolidEventHandlerMap & Partial<Record<"positionX" | "positionY" | "scaleX" | "scaleY" | "pivotX" | "pivotY" | "skewX" | "skewY", number>> & Record<string, unknown> & {
89
+ export declare const RenderLayer: (props: Omit<Pixi.RenderLayerOptions, "children"> & import("./bind-props").PixiSolidEventHandlerMap & Partial<Record<"positionX" | "positionY" | "scaleX" | "scaleY" | "pivotX" | "pivotY" | "skewX" | "skewY", number>> & {
82
90
  ref?: import("solid-js").Ref<Pixi.RenderLayer> | undefined;
83
91
  as?: Pixi.RenderLayer | undefined;
92
+ } & {
84
93
  children?: import("solid-js").JSX.Element;
85
94
  }) => Pixi.RenderLayer & import("solid-js").JSX.Element;
86
95
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pixi-solid",
3
- "version": "0.1.19",
3
+ "version": "0.1.21",
4
4
  "private": false,
5
5
  "description": "A library to write PixiJS applications with SolidJS",
6
6
  "homepage": "https://lukecarlthompson.github.io/pixi-solid/",