import * as PIXI from 'pixi.js'; import * as React from 'react'; // Reconciler API interface Reconciler { updateContainerAtExpirationTime( element: any, container: any, parentComponent: React.Component | null | undefined, expirationTime: any, callback: () => void | null | undefined ): any; createContainer(containerInfo: any, isConcurrent: boolean, hydrate: boolean): any; updateContainer( element: any, container: any, parentComponent: React.Component | null | undefined, callback: () => void | null | undefined ): any; flushRoot(root: any, expirationTime: any): void; requestWork(root: any, expirationTime: any): void; computeUniqueAsyncExpiration(): any; batchedUpdates(fn: () => A): A; unbatchedUpdates(fn: () => A): A; deferredUpdates(fn: () => A): A; syncUpdates(fn: () => A): A; interactiveUpdates(fn: () => A): A; flushInteractiveUpdates(): void; flushControlled(fn: () => any): void; flushSync(fn: () => A): A; getPublicRootInstance(container: any): React.Component | PublicInstance | null; findHostInstance(component: object): PublicInstance | null; findHostInstanceWithNoPortals(component: any): PublicInstance | null; injectIntoDevTools(devToolsConfig: any): boolean; } interface ReconcilerConfig { getRootHostContext(rootContainerInstance: any): any; getChildHostContext(): any; getChildHostContextForEventComponent(parentHostContext: any): any; getPublicInstance(getPublicInstance: any): any; prepareForCommit(): void; resetAfterCommit(): void; createInstance(...args: any[]): any; hideInstance(ins: any): void; unhideInstance(ins: any, props: any): void; appendInitialChild(...args: any[]): any; finalizeInitialChildren(doFinalize: boolean): boolean; prepareUpdate(...args: any): any; shouldSetTextContent(type: any, props: any): boolean; shouldDeprioritizeSubtree(type: any, props: any):boolean; createTextInstance(): void; mountEventComponent(): void; updateEventComponent(): void; handleEventTarget(): void; scheduleTimeout(...args: any[]): any; cancelTimeout(...args: any[]): any; appendChild(...args: any[]): any; appendChildToContainer(...args: any[]): any; removeChild(...args: any[]): any; removeChildFromContainer(...args: any[]): any; insertBefore(...args: any[]): any; insertInContainerBefore(...args: any[]): any; commitUpdate(...args: any[]): any; commitMount(...args: any[]): any; commitTextUpdate(...args: any[]): any; resetTextContent(...args: any[]): any; } export type InteractionEventTypes = | 'click' | 'mousedown' | 'mousemove' | 'mouseout' | 'mouseover' | 'mouseup' | 'mouseupoutside' | 'tap' | 'touchstart' | 'touchmove' | 'touchend' | 'touchendoutside' | 'pointercancel' | 'pointerout' | 'pointerover' | 'pointertap' | 'pointerdown' | 'pointerup' | 'pointerupoutside' | 'pointermove' | 'rightclick' | 'rightdown' | 'rightup' | 'rightupoutside' | 'touchcancel' | 'touchendoutside' | 'touchmove' | 'touchstart'; export type InteractionEvents = { [P in InteractionEventTypes]?: ( event: PIXI.InteractionEvent ) => void; }; // private declare namespace _ReactPixi { type FunctionTypes = { [P in keyof T]: ((...args: any) => any) extends T[P] ? P : never; }[keyof T]; type IfEquals = (() => T extends X ? 1 : 2) extends (() => T extends Y ? 1 : 2) ? A : B; type ReadonlyKeys = { [P in keyof T]-?: IfEquals<{ [Q in P]: T[P] }, { -readonly [Q in P]: T[P] }, never, P> }[keyof T]; type ApplicationOptions = ConstructorParameters[0]; type PointLike = | PIXI.Point | PIXI.ObservablePoint | [number, number] | [number] | number | { x: number, y: number }; type ImageSource = string | HTMLImageElement; type VideoSource = string | HTMLVideoElement; type AnySource = number | ImageSource | VideoSource | HTMLCanvasElement | PIXI.Texture; type WithPointLike = { [P in T]: PointLike }; interface WithSource { /** * Directly apply an image * * @example * * image="./image.png" */ image?: ImageSource; /** * Directly apply a video * * @example * * video="./video.mp4" */ video?: VideoSource; /** * Directly apply a source. * Can be an image, video, canvas, frame id or even a texture * * @example * * source="./image.jpg" * source="./video.mp4" * source={document.querySelector('img')} * source={document.querySelector('video')} * source={document.querySelector('canvas')} */ source?: AnySource; } type P = 'position' | 'scale' | 'pivot' | 'anchor' | 'skew'; type Container = Partial< Omit | keyof U> & WithPointLike

> & U & InteractionEvents & { ref?: React.Ref }; type IContainer = Container; type ISprite = Container; type IText = Container; type IGraphics = Container { * g.beginFill(0xff0000); * g.drawRect(0,0,100,100); * g.endFill(); * }} */ draw?(graphics: PIXI.Graphics): void; }>; type IBitmapText = Container< PIXI.BitmapText, { /** * Set the style object * * @example * * style={{ font: '50px Desyrel' }} */ style?: ConstructorParameters[1]; } >; type INineSlicePlane = Container; type IParticleContainer = Container< PIXI.ParticleContainer, { maxSize?: ConstructorParameters[0]; properties?: ConstructorParameters[1]; batchSize?: ConstructorParameters[2]; autoResize?: ConstructorParameters[3]; } >; type ITilingSprite = Container< PIXI.TilingSprite, WithSource & { tileScale?: PointLike; tilePosition: PointLike; } >; type ISimpleRope = Container; type ISimpleMesh = Container< PIXI.SimpleMesh, WithSource & { uvs?: ConstructorParameters[2]; indices?: ConstructorParameters[3]; } >; type IAnimatedSprite = Container< PIXI.AnimatedSprite, WithSource & { isPlaying: boolean; images?: string[]; initialFrame?: number; } >; type IStage = React.CanvasHTMLAttributes & { /** * Width of the Stage and canvas */ width?: number; /** * Height of the Stage and canvas */ height?: number; /** * Enable the {@see PIXI.Application} ticker? [default=true]. * Automatically renders the stage on request animation frame. */ raf?: boolean; /** * Render the PIXI stage on React component changes. * You'll need to set raf={false}. */ renderOnComponentChange?: boolean; /** * The PIXI application options. * * @see PIXI.ApplicationOptions * @example * * options={{ antialias: true, roundPixels: true }} */ options?: ApplicationOptions; /** * Callback when the component is successfully mounted * * @param {PIXI.Application} app */ onMount?(app: PIXI.Application): void; /** * Callback when the component is successfully unmounted * * @param {PIXI.Application} app */ onUnmount?(app: PIXI.Application): void; }; interface ICustomComponent< P extends { [key: string]: any }, PixiInstance extends PIXI.DisplayObject > { /** * Create the PIXI instance * The component is created during React reconciliation. * * @param props passed down props * @returns {PIXI.DisplayObject} */ create(props: P): PixiInstance; /** * Instance mounted * This is called during React reconciliation. * * @param {PIXI.DisplayObject} instance * @param {PIXI.Container} parent */ didMount?(instance: PixiInstance, parent: PIXI.Container): void; /** * Instance will unmount * This is called during React reconciliation. * * @param {PIXI.DisplayObject} instance * @param {PIXI.Container} parent */ willUnmount?(instance: PixiInstance, parent: PIXI.Container): void; /** * Apply props for this custom component. * This is called during React reconciliation. * * @param {PIXI.DisplayObject} instance * @param oldProps * @param newProps */ applyProps?( instance: PixiInstance, oldProps: Readonly

, newProps: Readonly

): void; /** * Reconcile config */ config?: { /** * Destroy instance on unmount? * @default true */ destroy?: boolean; /** * Destroy child instances? * @default true */ destroyChildren?: boolean }; } } // components export const Text: React.FC<_ReactPixi.IText>; export const Sprite: React.FC<_ReactPixi.ISprite>; export const Container: React.FC<_ReactPixi.IContainer>; export const Graphics: React.FC<_ReactPixi.IGraphics>; export const BitmapText: React.FC<_ReactPixi.IBitmapText>; export const NineSlicePlane: React.FC<_ReactPixi.INineSlicePlane>; export const ParticleContainer: React.FC<_ReactPixi.IParticleContainer>; export const TilingSprite: React.FC<_ReactPixi.ITilingSprite>; export const SimpleRope: React.FC<_ReactPixi.ISimpleRope>; export const SimpleMesh: React.FC<_ReactPixi.ISimpleMesh>; export const AnimatedSprite: React.FC<_ReactPixi.IAnimatedSprite>; // renderer export const render: ( element: React.ReactElement | React.ReactElement[] | React.Factory, container: PIXI.Container, callback?: (...args: any) => void ) => any; // unmount component export const unmountComponentAtNode: (container: PIXI.Container) => void; // context export const AppContext: React.Context; export const AppProvider: React.ComponentType>; export const AppConsumer: React.ComponentType>; // fiber export const PixiFiber: ( eventsMap?: { [P in keyof ReconcilerConfig]: (...args: any) => void } ) => Reconciler; // stage export class Stage extends React.Component<_ReactPixi.IStage> {} /** * Create a Custom PIXI Component * * @example * * type RectangleProps = { x: number, y: number, color: number }; * * const Rectangle = PixiComponent('Rectangle', { * create() { * return new PIXI.Graphics(); * } * applyProps(ins: PIXI.Graphics, oldProps: RectangleProps, newProps: RectangleProps) { * ins.clear(); * ins.beginFill(newProps.color); * ins.drawRect(newProps.x, newProps.y, 100, 100); * ins.endFill(); * } * }); */ export const PixiComponent: ( componentName: string, lifecycle: _ReactPixi.ICustomComponent ) => React.FC }>; /** * Tap into the {PIXI.Application} ticker raf. * * @example * * const MyComponent = () => { * const [x, setX] = useState(0); * useTick(() => setX(x + 1)); * * return * } */ export const useTick: ( tick: (this: PIXI.Ticker, delta: number, ticker: PIXI.Ticker) => void, enabled?: boolean ) => void; /** * Get the {} {PIXI.Application} instance. * * @example * * const MyComponent = () => { * const app = useApp(); // app = PIXI.Application * * return * } * */ export const useApp: () => PIXI.Application; /** * Higher Order Component to attach the {PIXI.Application} to `app` prop. * * @example * * interface Props { * app: PIXI.Application * } * * export default withPixiApp( * ({ app }) => ( * // * ) * ); */ export const withPixiApp:

( WrappedComponent: React.ComponentType

) => React.ComponentClass>; /** * Apply default props. Useful in Custom Components. * * @example * * const Rectangle = PixiComponent('Rectangle', { * create() { * return new PIXI.Graphics(); * }, * applyProps(instance, oldProps, newProps) { * applyDefaultProps(instance, oldProps, newProps); * } * }); */ export const applyDefaultProps:

( instance: PIXI.DisplayObject, oldProps: P, newProps: P ) => void; /** * Create a filter wrapper to easily facilitate filter arguments as props * in a declarative way. * * @example * * render() { * return ( * * * * * * ) * } */ export const withFilters: < Component extends React.ComponentType< _ReactPixi.Container >, Filters extends { [filterKey: string]: any } >( WrapperComponent: Component, filters: Filters ) => React.ComponentType< React.ComponentProps & Partial< { [P in keyof Filters]: Partial & { construct: ConstructorParameters }> } > > /** * Get the component instance ref * * @example * * const App = () => { * const containerRef = React.useRef>(null); * * return * }; */ export type PixiRef> = Extract< React.ComponentProps['ref'], React.RefObject > extends React.Ref ? R : never;