pixi-solid 0.1.15 → 0.1.17
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/components/component-factories.js +37 -11
- package/dist/components/component-factories.js.map +1 -1
- package/dist/components/components.js +3 -3
- package/dist/components/components.js.map +1 -1
- package/dist/on-resize.js +12 -9
- package/dist/on-resize.js.map +1 -1
- package/dist/pixi-application/pixi-application-provider.js.map +1 -1
- package/dist/types/components/component-factories.d.ts +8 -1
- package/dist/types/components/component-factories.test.d.ts +1 -0
- package/dist/types/components/components.d.ts +11 -4
- package/dist/types/components/index.d.ts +2 -2
- package/dist/types/index.d.ts +1 -1
- package/package.json +1 -1
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { splitProps, onCleanup } from "solid-js";
|
|
1
|
+
import { splitProps, createRenderEffect, on, onCleanup } from "solid-js";
|
|
2
2
|
import { PIXI_SOLID_EVENT_HANDLER_NAMES } from "./bind-props/event-names.js";
|
|
3
3
|
import { COMMON_POINT_PROP_AXIS_NAMES, ANCHOR_POINT_PROP_AXIS_NAMES, TILING_POINT_PROP_AXIS_NAMES } from "./bind-props/point-property-names.js";
|
|
4
|
+
import { getTicker } from "../pixi-application/get-ticker.js";
|
|
4
5
|
import { bindInitialisationProps, bindRuntimeProps } from "./bind-props/bind-props.js";
|
|
5
6
|
const SOLID_PROP_KEYS = ["ref", "as", "children"];
|
|
6
7
|
const CONTAINER_RUNTIME_KEYS = [
|
|
@@ -51,11 +52,39 @@ const createSpriteComponent = (PixiClass) => {
|
|
|
51
52
|
bindInitialisationProps(instance, initialisationProps);
|
|
52
53
|
bindRuntimeProps(instance, runtimeProps);
|
|
53
54
|
onCleanup(() => {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
55
|
+
instance.destroy({ children: true });
|
|
56
|
+
});
|
|
57
|
+
return instance;
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
const createAnimatedSpriteComponent = (PixiClass) => {
|
|
61
|
+
return (props) => {
|
|
62
|
+
const [runtimeProps, update, initialisationProps] = splitProps(props, SPRITE_RUNTIME_KEYS, [
|
|
63
|
+
"autoUpdate"
|
|
64
|
+
]);
|
|
65
|
+
const instance = props.as || new PixiClass(initialisationProps);
|
|
66
|
+
instance.autoUpdate = false;
|
|
67
|
+
createRenderEffect(
|
|
68
|
+
on(
|
|
69
|
+
() => update.autoUpdate,
|
|
70
|
+
(autoUpdate) => {
|
|
71
|
+
const updateInstance = (ticker) => {
|
|
72
|
+
instance.update(ticker);
|
|
73
|
+
};
|
|
74
|
+
if (autoUpdate !== false) {
|
|
75
|
+
const ticker = getTicker();
|
|
76
|
+
ticker.add(updateInstance);
|
|
77
|
+
onCleanup(() => {
|
|
78
|
+
ticker.remove(updateInstance);
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
)
|
|
83
|
+
);
|
|
84
|
+
bindInitialisationProps(instance, initialisationProps);
|
|
85
|
+
bindRuntimeProps(instance, runtimeProps);
|
|
86
|
+
onCleanup(() => {
|
|
87
|
+
instance.destroy({ children: true });
|
|
59
88
|
});
|
|
60
89
|
return instance;
|
|
61
90
|
};
|
|
@@ -67,17 +96,14 @@ const createTilingSpriteComponent = (PixiClass) => {
|
|
|
67
96
|
bindInitialisationProps(instance, initialisationProps);
|
|
68
97
|
bindRuntimeProps(instance, runtimeProps);
|
|
69
98
|
onCleanup(() => {
|
|
70
|
-
|
|
71
|
-
instance.destroy({ children: false });
|
|
72
|
-
} else {
|
|
73
|
-
instance.destroy({ children: true });
|
|
74
|
-
}
|
|
99
|
+
instance.destroy({ children: true });
|
|
75
100
|
});
|
|
76
101
|
return instance;
|
|
77
102
|
};
|
|
78
103
|
};
|
|
79
104
|
export {
|
|
80
105
|
SOLID_PROP_KEYS,
|
|
106
|
+
createAnimatedSpriteComponent,
|
|
81
107
|
createContainerComponent,
|
|
82
108
|
createLeafComponent,
|
|
83
109
|
createSpriteComponent,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"component-factories.js","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 { bindInitialisationProps, bindRuntimeProps } from \"./bind-props\";\nimport type { PixiEventHandlerMap } 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> = PixiEventHandlerMap & CommonPointAxisProps & Omit<ComponentOptions, \"children\">;\n\n/**\n * Prop definition for basic Container components (position, scale, pivot, skew only)\n */\nexport type ContainerProps<Component> = PixiEventHandlerMap &\n CommonPointAxisProps & {\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> = PixiEventHandlerMap &\n CommonPointAxisProps &\n AnchorPointAxisProps & {\n ref?: Ref<Component>;\n as?: Component;\n };\n\n/**\n * Prop definition for TilingSprite (includes anchor and tiling properties)\n */\nexport type TilingSpriteProps<Component> = PixiEventHandlerMap &\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 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 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 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 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 return instance as InstanceType & JSX.Element;\n };\n};\n"],"names":[],"mappings":";;;;AAyFO,MAAM,kBAAkB,CAAC,OAAO,MAAM,UAAU;AAGvD,MAAM,yBAAyB;AAAA,EAC7B,GAAG;AAAA,EACH,GAAG;AAAA,EACH,GAAG;AACL;AAGA,MAAM,sBAAsB;AAAA,EAC1B;AAAA,EACA;AAAA,EACA,GAAG;AAAA,EACH,GAAG;AAAA,EACH,GAAG;AACL;AAEA,MAAM,6BAA6B;AAAA,EACjC;AAAA,EACA;AAAA,EACA,GAAG;AAAA,EACH,GAAG;AAAA,EACH,GAAG;AAAA,EACH,GAAG;AACL;AAEO,MAAM,2BAA2B,CAItC,cAGkC;AAClC,SAAO,CAAC,UAAsC;AAC5C,UAAM,CAAC,cAAc,mBAAmB,IAAI,WAAW,OAAO,sBAAsB;AAEpF,UAAM,WAAW,MAAM,MAAM,IAAI,UAAU,mBAA0B;AAErE,4BAAwB,UAAU,mBAAmB;AACrD,qBAAiB,UAAU,YAAY;AAEvC,cAAU,MAAM;AACd,UAAI,YAAY,UAAU;AAExB,iBAAS,QAAQ,EAAE,UAAU,MAAA,CAAO;AAAA,MACtC,OAAO;AACL,iBAAS,QAAQ,EAAE,UAAU,KAAA,CAAM;AAAA,MACrC;AAAA,IACF,CAAC;AAED,WAAO;AAAA,EACT;AACF;AAEO,MAAM,sBAAsB,CAIjC,cACG;AACH,SAAO,CACL,UAC+B;AAC/B,WAAO,yBAAoD,SAAS,EAAE,KAAK;AAAA,EAC7E;AACF;AAEO,MAAM,wBAAwB,CAInC,cACG;AACH,SAAO,CACL,UAC+B;AAC/B,UAAM,CAAC,cAAc,mBAAmB,IAAI,WAAW,OAAO,mBAAmB;AAEjF,UAAM,WAAW,MAAM,MAAM,IAAI,UAAU,mBAA0B;AAErE,4BAAwB,UAAU,mBAAmB;AACrD,qBAAiB,UAAU,YAAY;AAEvC,cAAU,MAAM;AACd,UAAI,YAAY,UAAU;AAExB,iBAAS,QAAQ,EAAE,UAAU,MAAA,CAAO;AAAA,MACtC,OAAO;AACL,iBAAS,QAAQ,EAAE,UAAU,KAAA,CAAM;AAAA,MACrC;AAAA,IACF,CAAC;AAED,WAAO;AAAA,EACT;AACF;AAEO,MAAM,8BAA8B,CAIzC,cACG;AACH,SAAO,CACL,UAC+B;AAC/B,UAAM,CAAC,cAAc,mBAAmB,IAAI,WAAW,OAAO,0BAA0B;AAExF,UAAM,WAAW,MAAM,MAAM,IAAI,UAAU,mBAA0B;AAErE,4BAAwB,UAAU,mBAAmB;AACrD,qBAAiB,UAAU,YAAY;AAEvC,cAAU,MAAM;AACd,UAAI,YAAY,UAAU;AAExB,iBAAS,QAAQ,EAAE,UAAU,MAAA,CAAO;AAAA,MACtC,OAAO;AACL,iBAAS,QAAQ,EAAE,UAAU,KAAA,CAAM;AAAA,MACrC;AAAA,IACF,CAAC;AAED,WAAO;AAAA,EACT;AACF;"}
|
|
1
|
+
{"version":3,"file":"component-factories.js","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 { PixiEventHandlerMap } 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> = PixiEventHandlerMap & CommonPointAxisProps & Omit<ComponentOptions, \"children\">;\n\n/**\n * Prop definition for basic Container components (position, scale, pivot, skew only)\n */\nexport type ContainerProps<Component> = PixiEventHandlerMap &\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> = PixiEventHandlerMap &\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> = PixiEventHandlerMap &\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"],"names":[],"mappings":";;;;;AAoGO,MAAM,kBAAkB,CAAC,OAAO,MAAM,UAAU;AAGvD,MAAM,yBAAyB;AAAA,EAC7B,GAAG;AAAA,EACH,GAAG;AAAA,EACH,GAAG;AACL;AAGA,MAAM,sBAAsB;AAAA,EAC1B;AAAA,EACA;AAAA,EACA,GAAG;AAAA,EACH,GAAG;AAAA,EACH,GAAG;AACL;AAEA,MAAM,6BAA6B;AAAA,EACjC;AAAA,EACA;AAAA,EACA,GAAG;AAAA,EACH,GAAG;AAAA,EACH,GAAG;AAAA,EACH,GAAG;AACL;AAEO,MAAM,2BAA2B,CAItC,cAGkC;AAClC,SAAO,CAAC,UAAsC;AAC5C,UAAM,CAAC,cAAc,mBAAmB,IAAI,WAAW,OAAO,sBAAsB;AAEpF,UAAM,WAAW,MAAM,MAAM,IAAI,UAAU,mBAA0B;AAErE,4BAAwB,UAAU,mBAAmB;AACrD,qBAAiB,UAAU,YAAY;AAEvC,cAAU,MAAM;AACd,UAAI,YAAY,UAAU;AAExB,iBAAS,QAAQ,EAAE,UAAU,MAAA,CAAO;AAAA,MACtC,OAAO;AACL,iBAAS,QAAQ,EAAE,UAAU,KAAA,CAAM;AAAA,MACrC;AAAA,IACF,CAAC;AAED,WAAO;AAAA,EACT;AACF;AAEO,MAAM,sBAAsB,CAIjC,cACG;AACH,SAAO,CACL,UAC+B;AAC/B,WAAO,yBAAoD,SAAS,EAAE,KAAK;AAAA,EAC7E;AACF;AAEO,MAAM,wBAAwB,CAInC,cACG;AACH,SAAO,CACL,UAC+B;AAC/B,UAAM,CAAC,cAAc,mBAAmB,IAAI,WAAW,OAAO,mBAAmB;AAEjF,UAAM,WAAW,MAAM,MAAM,IAAI,UAAU,mBAA0B;AAErE,4BAAwB,UAAU,mBAAmB;AACrD,qBAAiB,UAAU,YAAY;AAEvC,cAAU,MAAM;AACd,eAAS,QAAQ,EAAE,UAAU,KAAA,CAAM;AAAA,IACrC,CAAC;AAED,WAAO;AAAA,EACT;AACF;AAEO,MAAM,gCAAgC,CAI3C,cACG;AACH,SAAO,CACL,UAC+B;AAE/B,UAAM,CAAC,cAAc,QAAQ,mBAAmB,IAAI,WAAW,OAAO,qBAAqB;AAAA,MACzF;AAAA,IAAA,CACD;AAED,UAAM,WAAW,MAAM,MAAM,IAAI,UAAU,mBAA0B;AAGrE,aAAS,aAAa;AAEtB;AAAA,MACE;AAAA,QACE,MAAM,OAAO;AAAA,QACb,CAAC,eAAe;AACd,gBAAM,iBAAiB,CAAC,WAAwB;AAC9C,qBAAS,OAAO,MAAM;AAAA,UACxB;AAEA,cAAI,eAAe,OAAO;AACxB,kBAAM,SAAS,UAAA;AACf,mBAAO,IAAI,cAAc;AACzB,sBAAU,MAAM;AACd,qBAAO,OAAO,cAAc;AAAA,YAC9B,CAAC;AAAA,UACH;AAAA,QACF;AAAA,MAAA;AAAA,IACF;AAGF,4BAAwB,UAAU,mBAAmB;AACrD,qBAAiB,UAAU,YAAY;AAEvC,cAAU,MAAM;AACd,eAAS,QAAQ,EAAE,UAAU,KAAA,CAAM;AAAA,IACrC,CAAC;AAED,WAAO;AAAA,EACT;AACF;AAEO,MAAM,8BAA8B,CAIzC,cACG;AACH,SAAO,CACL,UAC+B;AAC/B,UAAM,CAAC,cAAc,mBAAmB,IAAI,WAAW,OAAO,0BAA0B;AAExF,UAAM,WAAW,MAAM,MAAM,IAAI,UAAU,mBAA0B;AAErE,4BAAwB,UAAU,mBAAmB;AACrD,qBAAiB,UAAU,YAAY;AAEvC,cAAU,MAAM;AACd,eAAS,QAAQ,EAAE,UAAU,KAAA,CAAM;AAAA,IACrC,CAAC;AAED,WAAO;AAAA,EACT;AACF;"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { createSpriteComponent, createContainerComponent, createLeafComponent, createTilingSpriteComponent } from "./component-factories.js";
|
|
3
|
-
const AnimatedSprite =
|
|
1
|
+
import { HTMLText as HTMLText$1, MeshPlane as MeshPlane$1, MeshRope as MeshRope$1, NineSliceSprite as NineSliceSprite$1, ParticleContainer as ParticleContainer$1, PerspectiveMesh as PerspectiveMesh$1, RenderContainer as RenderContainer$1, RenderLayer as RenderLayer$1, Sprite as Sprite$1, Text as Text$1, AnimatedSprite as AnimatedSprite$1, BitmapText as BitmapText$1, Container as Container$1, Graphics as Graphics$1, TilingSprite as TilingSprite$1 } from "pixi.js";
|
|
2
|
+
import { createAnimatedSpriteComponent, createSpriteComponent, createContainerComponent, createLeafComponent, createTilingSpriteComponent } from "./component-factories.js";
|
|
3
|
+
const AnimatedSprite = createAnimatedSpriteComponent(AnimatedSprite$1);
|
|
4
4
|
const BitmapText = createSpriteComponent(BitmapText$1);
|
|
5
5
|
const Container = createContainerComponent(Container$1);
|
|
6
6
|
const Graphics = createLeafComponent(Graphics$1);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"components.js","sources":["../../src/components/components.tsx"],"sourcesContent":["import type * as Pixi from \"pixi.js\";\nimport {\n AnimatedSprite as PixiAnimatedSprite,\n BitmapText as PixiBitmapText,\n Container as PixiContainer,\n Graphics as PixiGraphics,\n HTMLText as PixiHTMLText,\n MeshPlane as PixiMeshPlane,\n MeshRope as PixiMeshRope,\n NineSliceSprite as PixiNineSliceSprite,\n ParticleContainer as PixiParticleContainer,\n PerspectiveMesh as PixiPerspectiveMesh,\n RenderContainer as PixiRenderContainer,\n RenderLayer as PixiRenderLayer,\n Sprite as PixiSprite,\n Text as PixiText,\n TilingSprite as PixiTilingSprite,\n} from \"pixi.js\";\n\nimport {\n createContainerComponent,\n createLeafComponent,\n createSpriteComponent,\n createTilingSpriteComponent,\n} from \"./component-factories\";\n\n/**\n * A SolidJS component that renders a `PIXI.AnimatedSprite`.\n */\nexport const AnimatedSprite =
|
|
1
|
+
{"version":3,"file":"components.js","sources":["../../src/components/components.tsx"],"sourcesContent":["import type * as Pixi from \"pixi.js\";\nimport {\n AnimatedSprite as PixiAnimatedSprite,\n BitmapText as PixiBitmapText,\n Container as PixiContainer,\n Graphics as PixiGraphics,\n HTMLText as PixiHTMLText,\n MeshPlane as PixiMeshPlane,\n MeshRope as PixiMeshRope,\n NineSliceSprite as PixiNineSliceSprite,\n ParticleContainer as PixiParticleContainer,\n PerspectiveMesh as PixiPerspectiveMesh,\n RenderContainer as PixiRenderContainer,\n RenderLayer as PixiRenderLayer,\n Sprite as PixiSprite,\n Text as PixiText,\n TilingSprite as PixiTilingSprite,\n} from \"pixi.js\";\n\nimport {\n createAnimatedSpriteComponent,\n createContainerComponent,\n createLeafComponent,\n createSpriteComponent,\n createTilingSpriteComponent,\n} from \"./component-factories\";\n\n/**\n * A SolidJS component that renders a `PIXI.AnimatedSprite`.\n */\nexport const AnimatedSprite = createAnimatedSpriteComponent<\n PixiAnimatedSprite,\n Pixi.AnimatedSpriteOptions\n>(PixiAnimatedSprite);\n/**\n * A SolidJS component that renders a `PIXI.BitmapText`.\n */\nexport const BitmapText = createSpriteComponent<PixiBitmapText, Pixi.TextOptions>(PixiBitmapText);\n/**\n * A SolidJS component that renders a `PIXI.Container`.\n */\nexport const Container = createContainerComponent<PixiContainer, Pixi.ContainerOptions>(\n PixiContainer,\n);\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 = createSpriteComponent<PixiHTMLText, Pixi.HTMLTextOptions>(PixiHTMLText);\n\n/**\n * A SolidJS component that renders a `PIXI.MeshPlane`.\n */\nexport const MeshPlane = createSpriteComponent<PixiMeshPlane, Pixi.MeshPlaneOptions>(PixiMeshPlane);\n\n/**\n * A SolidJS component that renders a `PIXI.MeshRope`.\n */\nexport const MeshRope = createSpriteComponent<PixiMeshRope, Pixi.MeshRopeOptions>(PixiMeshRope);\n\n/**\n * A SolidJS component that renders a `PIXI.NineSliceSprite`.\n */\nexport const NineSliceSprite = createSpriteComponent<\n PixiNineSliceSprite,\n Pixi.NineSliceSpriteOptions\n>(PixiNineSliceSprite);\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<\n PixiParticleContainer,\n Pixi.ParticleContainerOptions\n>(PixiParticleContainer);\n\n/**\n * A SolidJS component that renders a `PIXI.PerspectiveMesh`.\n */\nexport const PerspectiveMesh = createSpriteComponent<\n PixiPerspectiveMesh,\n Pixi.PerspectivePlaneOptions\n>(PixiPerspectiveMesh);\n\n/**\n * A SolidJS component that renders a `PIXI.RenderContainer`.\n */\nexport const RenderContainer = createContainerComponent<\n PixiRenderContainer,\n Pixi.RenderContainerOptions\n>(PixiRenderContainer);\n\n/**\n * A SolidJS component that renders a `PIXI.RenderLayer`.\n */\nexport const RenderLayer = createContainerComponent<PixiRenderLayer, Pixi.RenderLayerOptions>(\n PixiRenderLayer,\n);\n\n/**\n * A SolidJS component that renders a `PIXI.Sprite`.\n */\nexport const Sprite = createSpriteComponent<PixiSprite, Pixi.SpriteOptions>(PixiSprite);\n/**\n * A SolidJS component that renders a `PIXI.Text`.\n */\nexport const Text = createSpriteComponent<PixiText, Pixi.CanvasTextOptions>(PixiText);\n\n/**\n * A SolidJS component that renders a `PIXI.TilingSprite`.\n */\nexport const TilingSprite = createTilingSpriteComponent<PixiTilingSprite, Pixi.TilingSpriteOptions>(\n PixiTilingSprite,\n);\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\n// TODO: Should we export the built in filters as component?\n/**\n * AlphaFilter\tApplies uniform transparency\n * BlurFilter\tGaussian blur\n * ColorMatrixFilter\tColor transformations via a 5x4 matrix\n * DisplacementFilter\tDistorts using a displacement map texture\n * NoiseFilter\tAdds random noise for a grainy look\n * */\n"],"names":["AnimatedSprite","createAnimatedSpriteComponent","PixiAnimatedSprite","BitmapText","createSpriteComponent","PixiBitmapText","Container","createContainerComponent","PixiContainer","Graphics","createLeafComponent","PixiGraphics","HTMLText","PixiHTMLText","MeshPlane","PixiMeshPlane","MeshRope","PixiMeshRope","NineSliceSprite","PixiNineSliceSprite","ParticleContainer","PixiParticleContainer","PerspectiveMesh","PixiPerspectiveMesh","RenderContainer","PixiRenderContainer","RenderLayer","PixiRenderLayer","Sprite","PixiSprite","Text","PixiText","TilingSprite","createTilingSpriteComponent","PixiTilingSprite"],"mappings":";;AA8BO,MAAMA,iBAAiBC,8BAG5BC,gBAAkB;AAIb,MAAMC,aAAaC,sBAAwDC,YAAc;AAIzF,MAAMC,YAAYC,yBACvBC,WACF;AAKO,MAAMC,WAAWC,oBAAwDC,UAAY;AAIrF,MAAMC,WAAWR,sBAA0DS,UAAY;AAKvF,MAAMC,YAAYV,sBAA4DW,WAAa;AAK3F,MAAMC,WAAWZ,sBAA0Da,UAAY;AAKvF,MAAMC,kBAAkBd,sBAG7Be,iBAAmB;AAOd,MAAMC,oBAAoBV,oBAG/BW,mBAAqB;AAKhB,MAAMC,kBAAkBlB,sBAG7BmB,iBAAmB;AAKd,MAAMC,kBAAkBjB,yBAG7BkB,iBAAmB;AAKd,MAAMC,cAAcnB,yBACzBoB,aACF;AAKO,MAAMC,SAASxB,sBAAsDyB,QAAU;AAI/E,MAAMC,OAAO1B,sBAAwD2B,MAAQ;AAK7E,MAAMC,eAAeC,4BAC1BC,cACF;"}
|
package/dist/on-resize.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createEffect, on } from "solid-js";
|
|
2
2
|
import { getPixiApp } from "./pixi-application/get-pixi-app.js";
|
|
3
|
+
import { usePixiScreen } from "./use-pixi-screen/use-pixi-screen.js";
|
|
3
4
|
const onResize = (resizeCallback) => {
|
|
4
5
|
let pixiApp;
|
|
5
6
|
try {
|
|
@@ -7,14 +8,16 @@ const onResize = (resizeCallback) => {
|
|
|
7
8
|
} catch {
|
|
8
9
|
throw new Error("onResize must be used within a PixiApplicationProvider or a PixiCanvas");
|
|
9
10
|
}
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
11
|
+
const screen = usePixiScreen();
|
|
12
|
+
createEffect(
|
|
13
|
+
on(
|
|
14
|
+
() => [screen.width, screen.height, screen.x, screen.y],
|
|
15
|
+
() => {
|
|
16
|
+
resizeCallback(pixiApp.renderer.screen);
|
|
17
|
+
},
|
|
18
|
+
{ defer: false }
|
|
19
|
+
)
|
|
20
|
+
);
|
|
18
21
|
};
|
|
19
22
|
export {
|
|
20
23
|
onResize
|
package/dist/on-resize.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"on-resize.js","sources":["../src/on-resize.ts"],"sourcesContent":["import type * as Pixi from \"pixi.js\";\nimport {
|
|
1
|
+
{"version":3,"file":"on-resize.js","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"],"names":[],"mappings":";;;AAiBO,MAAM,WAAW,CAAC,mBAA2D;AAClF,MAAI;AAEJ,MAAI;AACF,cAAU,WAAA;AAAA,EACZ,QAAQ;AACN,UAAM,IAAI,MAAM,wEAAwE;AAAA,EAC1F;AAEA,QAAM,SAAS,cAAA;AAOf;AAAA,IACE;AAAA,MACE,MAAM,CAAC,OAAO,OAAO,OAAO,QAAQ,OAAO,GAAG,OAAO,CAAC;AAAA,MACtD,MAAM;AACJ,uBAAe,QAAQ,SAAS,MAAM;AAAA,MACxC;AAAA,MACA,EAAE,OAAO,MAAA;AAAA,IAAM;AAAA,EACjB;AAEJ;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pixi-application-provider.js","sources":["../../src/pixi-application/pixi-application-provider.tsx"],"sourcesContent":["import type * as Pixi from \"pixi.js\";\nimport type { JSX, ParentProps } from \"solid-js\";\nimport { createResource, onCleanup, Show, splitProps, useContext } from \"solid-js\";\n\nimport { createPixiScreenStore } from \"../use-pixi-screen/pixi-screen-store\";\n\nimport { PixiAppContext, TickerContext } from \"./context\";\nimport { createPixiApplication } from \"./pixi-application\";\n\n/**\n * Props for the `PixiApplication` component. It extends the PIXI.ApplicationOptions\n * minus the `children` and `resizeTo` properties, which are handled by pixi-solid internally.\n * There is also an optional `existingApp` property to pass in an already created Pixi.Application instance, which will be used instead of creating a new one.\n */\nexport type PixiApplicationProps = Partial<\n Omit<Pixi.ApplicationOptions, \"children\" | \"resizeTo\">\n> & {\n children?: JSX.Element;\n existingApp?: Pixi.Application;\n};\n\n/**\n * A SolidJS component that creates a Pixi.Application instance and works as a context provider.\n * It provides the application instance through context to be used by child components\n * and custom hooks like `getPixiApp`, `onTick`, `getTicker` and `usePixiScreen`.\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 PixiApplicationProvider = (props: PixiApplicationProps): JSX.Element => {\n let externallyProvidedApp: Pixi.Application | undefined = props.existingApp;\n\n const [appResource] = createResource(async () => {\n if (externallyProvidedApp) {\n return externallyProvidedApp;\n }\n\n const existingContext = useContext(PixiAppContext);\n if (existingContext?.app) {\n externallyProvidedApp = existingContext.app;\n return existingContext.app;\n }\n\n const [, initialisationProps] = splitProps(props, [\"children\", \"existingApp\"]);\n return await createPixiApplication(initialisationProps);\n });\n\n onCleanup(() => {\n // Only
|
|
1
|
+
{"version":3,"file":"pixi-application-provider.js","sources":["../../src/pixi-application/pixi-application-provider.tsx"],"sourcesContent":["import type * as Pixi from \"pixi.js\";\nimport type { JSX, ParentProps } from \"solid-js\";\nimport { createResource, onCleanup, Show, splitProps, useContext } from \"solid-js\";\n\nimport { createPixiScreenStore } from \"../use-pixi-screen/pixi-screen-store\";\n\nimport { PixiAppContext, TickerContext } from \"./context\";\nimport { createPixiApplication } from \"./pixi-application\";\n\n/**\n * Props for the `PixiApplication` component. It extends the PIXI.ApplicationOptions\n * minus the `children` and `resizeTo` properties, which are handled by pixi-solid internally.\n * There is also an optional `existingApp` property to pass in an already created Pixi.Application instance, which will be used instead of creating a new one.\n */\nexport type PixiApplicationProps = Partial<\n Omit<Pixi.ApplicationOptions, \"children\" | \"resizeTo\">\n> & {\n children?: JSX.Element;\n existingApp?: Pixi.Application;\n};\n\n/**\n * A SolidJS component that creates a Pixi.Application instance and works as a context provider.\n * It provides the application instance through context to be used by child components\n * and custom hooks like `getPixiApp`, `onTick`, `getTicker` and `usePixiScreen`.\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 PixiApplicationProvider = (props: PixiApplicationProps): JSX.Element => {\n let externallyProvidedApp: Pixi.Application | undefined = props.existingApp;\n\n const [appResource] = createResource(async () => {\n if (externallyProvidedApp) {\n return externallyProvidedApp;\n }\n\n const existingContext = useContext(PixiAppContext);\n if (existingContext?.app) {\n externallyProvidedApp = existingContext.app;\n return existingContext.app;\n }\n\n const [, initialisationProps] = splitProps(props, [\"children\", \"existingApp\"]);\n return await createPixiApplication(initialisationProps);\n });\n\n onCleanup(() => {\n // Only destroy the app if it was created here.\n if (externallyProvidedApp) return;\n appResource()?.destroy(true, { children: true });\n });\n\n return (\n <Show when={appResource()}>\n {(app) => {\n const pixiScreenStore = createPixiScreenStore(app().renderer);\n const contextValue = {\n app: app(),\n pixiScreenStore,\n };\n\n return (\n <PixiAppContext.Provider value={contextValue}>\n <TickerContext.Provider value={app().ticker}>{props.children}</TickerContext.Provider>\n </PixiAppContext.Provider>\n );\n }}\n </Show>\n );\n};\n\nexport type TickerProviderProps = ParentProps<{ ticker: Pixi.Ticker }>;\n\n/**\n * This is only required if you want a ticker without the Pixi Application.\n * For applications that want to use multiple tickers or for testing a store that relies on the ticker related utilities.\n * It provides context for the `onTick`, `delay`, `createAsyncDelay` and `getTicker` utilities.\n *\n * The ticker instance you want to use needs to be passed in as a prop so it can be manually controlled from the outside for testing.\n */\nexport const TickerProvider = (props: TickerProviderProps): JSX.Element => {\n return <TickerContext.Provider value={props.ticker}>{props.children}</TickerContext.Provider>;\n};\n"],"names":["PixiApplicationProvider","props","externallyProvidedApp","existingApp","appResource","createResource","existingContext","useContext","PixiAppContext","app","initialisationProps","splitProps","createPixiApplication","onCleanup","destroy","children","_$createComponent","Show","when","pixiScreenStore","createPixiScreenStore","renderer","contextValue","Provider","value","TickerContext","ticker","TickerProvider"],"mappings":";;;;;AA+BO,MAAMA,0BAA0BA,CAACC,UAA6C;AACnF,MAAIC,wBAAsDD,MAAME;AAEhE,QAAM,CAACC,WAAW,IAAIC,eAAe,YAAY;AAC/C,QAAIH,uBAAuB;AACzB,aAAOA;AAAAA,IACT;AAEA,UAAMI,kBAAkBC,WAAWC,cAAc;AACjD,QAAIF,iBAAiBG,KAAK;AACxBP,8BAAwBI,gBAAgBG;AACxC,aAAOH,gBAAgBG;AAAAA,IACzB;AAEA,UAAM,CAAA,EAAGC,mBAAmB,IAAIC,WAAWV,OAAO,CAAC,YAAY,aAAa,CAAC;AAC7E,WAAO,MAAMW,sBAAsBF,mBAAmB;AAAA,EACxD,CAAC;AAEDG,YAAU,MAAM;AAEd,QAAIX,sBAAuB;AAC3BE,gBAAAA,GAAeU,QAAQ,MAAM;AAAA,MAAEC,UAAU;AAAA,IAAA,CAAM;AAAA,EACjD,CAAC;AAED,SAAAC,gBACGC,MAAI;AAAA,IAAA,IAACC,OAAI;AAAA,aAAEd,YAAAA;AAAAA,IAAa;AAAA,IAAAW,UACrBN,CAAAA,QAAQ;AACR,YAAMU,kBAAkBC,sBAAsBX,IAAAA,EAAMY,QAAQ;AAC5D,YAAMC,eAAe;AAAA,QACnBb,KAAKA,IAAAA;AAAAA,QACLU;AAAAA,MAAAA;AAGF,aAAAH,gBACGR,eAAee,UAAQ;AAAA,QAACC,OAAOF;AAAAA,QAAY,IAAAP,WAAA;AAAA,iBAAAC,gBACzCS,cAAcF,UAAQ;AAAA,YAAA,IAACC,QAAK;AAAA,qBAAEf,MAAMiB;AAAAA,YAAM;AAAA,YAAA,IAAAX,WAAA;AAAA,qBAAGd,MAAMc;AAAAA,YAAQ;AAAA,UAAA,CAAA;AAAA,QAAA;AAAA,MAAA,CAAA;AAAA,IAGlE;AAAA,EAAA,CAAC;AAGP;AAWO,MAAMY,iBAAiBA,CAAC1B,UAA4C;AACzE,SAAAe,gBAAQS,cAAcF,UAAQ;AAAA,IAAA,IAACC,QAAK;AAAA,aAAEvB,MAAMyB;AAAAA,IAAM;AAAA,IAAA,IAAAX,WAAA;AAAA,aAAGd,MAAMc;AAAAA,IAAQ;AAAA,EAAA,CAAA;AACrE;"}
|
|
@@ -25,7 +25,7 @@ export type PixiComponentProps<ComponentOptions extends Pixi.ContainerOptions =
|
|
|
25
25
|
/**
|
|
26
26
|
* Prop definition for basic Container components (position, scale, pivot, skew only)
|
|
27
27
|
*/
|
|
28
|
-
export type ContainerProps<Component> = PixiEventHandlerMap & CommonPointAxisProps & {
|
|
28
|
+
export type ContainerProps<Component> = PixiEventHandlerMap & CommonPointAxisProps & Record<string, unknown> & {
|
|
29
29
|
ref?: Ref<Component>;
|
|
30
30
|
as?: Component;
|
|
31
31
|
children?: JSX.Element;
|
|
@@ -41,6 +41,11 @@ export type SpriteProps<Component> = PixiEventHandlerMap & CommonPointAxisProps
|
|
|
41
41
|
ref?: Ref<Component>;
|
|
42
42
|
as?: Component;
|
|
43
43
|
};
|
|
44
|
+
export type AnimatedSpriteProps<Component> = SpriteProps<Component> & Pick<Pixi.AnimatedSpriteOptions, "autoUpdate">;
|
|
45
|
+
type AnimatedSpriteLike = Pixi.Container & {
|
|
46
|
+
autoUpdate: boolean;
|
|
47
|
+
update: (ticker: Pixi.Ticker) => void;
|
|
48
|
+
};
|
|
44
49
|
/**
|
|
45
50
|
* Prop definition for TilingSprite (includes anchor and tiling properties)
|
|
46
51
|
*/
|
|
@@ -59,5 +64,7 @@ export declare const SOLID_PROP_KEYS: readonly ["ref", "as", "children"];
|
|
|
59
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);
|
|
60
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;
|
|
61
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;
|
|
62
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;
|
|
63
69
|
export declare const createFilterComponent: <InstanceType extends Pixi.Filter, OptionsType extends object>(PixiClass: new (props: OptionsType) => InstanceType) => (props: OptionsType & FilterProps<InstanceType>) => InstanceType & JSX.Element;
|
|
70
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -5,7 +5,7 @@ import type * as Pixi from "pixi.js";
|
|
|
5
5
|
export declare const AnimatedSprite: (props: Omit<Pixi.AnimatedSpriteOptions, "children"> & import("./bind-props").PixiEventHandlerMap & Partial<Record<"positionX" | "positionY" | "scaleX" | "scaleY" | "pivotX" | "pivotY" | "skewX" | "skewY", number>> & Partial<Record<"anchorX" | "anchorY", number>> & {
|
|
6
6
|
ref?: import("solid-js").Ref<Pixi.AnimatedSprite> | undefined;
|
|
7
7
|
as?: Pixi.AnimatedSprite | undefined;
|
|
8
|
-
}) => Pixi.AnimatedSprite & import("solid-js").JSX.Element;
|
|
8
|
+
} & Pick<Pixi.AnimatedSpriteOptions, "autoUpdate">) => Pixi.AnimatedSprite & import("solid-js").JSX.Element;
|
|
9
9
|
/**
|
|
10
10
|
* A SolidJS component that renders a `PIXI.BitmapText`.
|
|
11
11
|
*/
|
|
@@ -16,7 +16,7 @@ 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").PixiEventHandlerMap & Partial<Record<"positionX" | "positionY" | "scaleX" | "scaleY" | "pivotX" | "pivotY" | "skewX" | "skewY", number>> & {
|
|
19
|
+
export declare const Container: (props: Omit<Pixi.ContainerOptions<Pixi.ContainerChild>, "children"> & import("./bind-props").PixiEventHandlerMap & Partial<Record<"positionX" | "positionY" | "scaleX" | "scaleY" | "pivotX" | "pivotY" | "skewX" | "skewY", number>> & Record<string, unknown> & {
|
|
20
20
|
ref?: import("solid-js").Ref<Pixi.Container<Pixi.ContainerChild>> | undefined;
|
|
21
21
|
as?: Pixi.Container<Pixi.ContainerChild> | undefined;
|
|
22
22
|
children?: import("solid-js").JSX.Element;
|
|
@@ -70,7 +70,7 @@ export declare const PerspectiveMesh: (props: Omit<Pixi.PerspectivePlaneOptions,
|
|
|
70
70
|
/**
|
|
71
71
|
* A SolidJS component that renders a `PIXI.RenderContainer`.
|
|
72
72
|
*/
|
|
73
|
-
export declare const RenderContainer: (props: Omit<Pixi.RenderContainerOptions, "children"> & import("./bind-props").PixiEventHandlerMap & Partial<Record<"positionX" | "positionY" | "scaleX" | "scaleY" | "pivotX" | "pivotY" | "skewX" | "skewY", number>> & {
|
|
73
|
+
export declare const RenderContainer: (props: Omit<Pixi.RenderContainerOptions, "children"> & import("./bind-props").PixiEventHandlerMap & Partial<Record<"positionX" | "positionY" | "scaleX" | "scaleY" | "pivotX" | "pivotY" | "skewX" | "skewY", number>> & Record<string, unknown> & {
|
|
74
74
|
ref?: import("solid-js").Ref<Pixi.RenderContainer> | undefined;
|
|
75
75
|
as?: Pixi.RenderContainer | undefined;
|
|
76
76
|
children?: import("solid-js").JSX.Element;
|
|
@@ -78,7 +78,7 @@ export declare const RenderContainer: (props: Omit<Pixi.RenderContainerOptions,
|
|
|
78
78
|
/**
|
|
79
79
|
* A SolidJS component that renders a `PIXI.RenderLayer`.
|
|
80
80
|
*/
|
|
81
|
-
export declare const RenderLayer: (props: Omit<Pixi.RenderLayerOptions, "children"> & import("./bind-props").PixiEventHandlerMap & Partial<Record<"positionX" | "positionY" | "scaleX" | "scaleY" | "pivotX" | "pivotY" | "skewX" | "skewY", number>> & {
|
|
81
|
+
export declare const RenderLayer: (props: Omit<Pixi.RenderLayerOptions, "children"> & import("./bind-props").PixiEventHandlerMap & Partial<Record<"positionX" | "positionY" | "scaleX" | "scaleY" | "pivotX" | "pivotY" | "skewX" | "skewY", number>> & Record<string, unknown> & {
|
|
82
82
|
ref?: import("solid-js").Ref<Pixi.RenderLayer> | undefined;
|
|
83
83
|
as?: Pixi.RenderLayer | undefined;
|
|
84
84
|
children?: import("solid-js").JSX.Element;
|
|
@@ -104,3 +104,10 @@ export declare const TilingSprite: (props: Omit<Pixi.TilingSpriteOptions, "child
|
|
|
104
104
|
ref?: import("solid-js").Ref<Pixi.TilingSprite> | undefined;
|
|
105
105
|
as?: Pixi.TilingSprite | undefined;
|
|
106
106
|
}) => Pixi.TilingSprite & import("solid-js").JSX.Element;
|
|
107
|
+
/**
|
|
108
|
+
* AlphaFilter Applies uniform transparency
|
|
109
|
+
* BlurFilter Gaussian blur
|
|
110
|
+
* ColorMatrixFilter Color transformations via a 5x4 matrix
|
|
111
|
+
* DisplacementFilter Distorts using a displacement map texture
|
|
112
|
+
* NoiseFilter Adds random noise for a grainy look
|
|
113
|
+
* */
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { AnimatedSprite, BitmapText, Container, Graphics, HTMLText, MeshPlane, MeshRope, NineSliceSprite, ParticleContainer, PerspectiveMesh, Sprite, Text, RenderContainer, RenderLayer, TilingSprite, } from "./components";
|
|
2
2
|
export { PIXI_EVENT_NAMES, PIXI_SOLID_EVENT_HANDLER_NAMES, bindRuntimeProps, bindInitialisationProps, } from "./bind-props";
|
|
3
3
|
export type { PixiEventHandlerMap, PointAxisPropName, CommonPointAxisPropName, AnchorPointAxisPropName, TilingPointAxisPropName, } from "./bind-props";
|
|
4
|
-
export type { ContainerProps, LeafProps, SpriteProps, TilingSpriteProps, PixiComponentProps, CommonPointAxisProps, AnchorPointAxisProps, TilingPointAxisProps, } from "./component-factories";
|
|
5
|
-
export { createContainerComponent, createLeafComponent, createSpriteComponent, createTilingSpriteComponent, createFilterComponent, } from "./component-factories";
|
|
4
|
+
export type { AnimatedSpriteProps, ContainerProps, LeafProps, SpriteProps, TilingSpriteProps, PixiComponentProps, CommonPointAxisProps, AnchorPointAxisProps, TilingPointAxisProps, } from "./component-factories";
|
|
5
|
+
export { createAnimatedSpriteComponent, createContainerComponent, createLeafComponent, createSpriteComponent, createTilingSpriteComponent, createFilterComponent, } from "./component-factories";
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type { ContainerProps, LeafProps, SpriteProps, TilingSpriteProps, PixiComponentProps, CommonPointAxisProps, AnchorPointAxisProps, TilingPointAxisProps, PixiEventHandlerMap, PointAxisPropName, CommonPointAxisPropName, AnchorPointAxisPropName, TilingPointAxisPropName, } from "./components";
|
|
1
|
+
export type { AnimatedSpriteProps, ContainerProps, LeafProps, SpriteProps, TilingSpriteProps, PixiComponentProps, CommonPointAxisProps, AnchorPointAxisProps, TilingPointAxisProps, PixiEventHandlerMap, PointAxisPropName, CommonPointAxisPropName, AnchorPointAxisPropName, TilingPointAxisPropName, } from "./components";
|
|
2
2
|
export { PIXI_EVENT_NAMES, PIXI_SOLID_EVENT_HANDLER_NAMES } from "./components";
|
|
3
3
|
export { onResize } from "./on-resize";
|
|
4
4
|
export { onTick } from "./on-tick";
|