diff --git a/types/pixi.js/index.d.ts b/types/pixi.js/index.d.ts index 88ed75eced..bcf403d475 100644 --- a/types/pixi.js/index.d.ts +++ b/types/pixi.js/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for Pixi.js 4.4 +// Type definitions for Pixi.js 4.5 // Project: https://github.com/pixijs/pixi.js/tree/dev // Definitions by: clark-stevenson // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped @@ -20,8 +20,10 @@ declare namespace PIXI { const GC_MODES: typeof CONST.GC_MODES; const SHAPES: typeof CONST.SHAPES; const TEXT_GRADIENT: typeof CONST.TEXT_GRADIENT; + const UPDATE_PRIORITY: typeof CONST.UPDATE_PRIORITY; - function autoDetectRenderer(width: number, height: number, options?: PIXI.IRendererOptions, noWebGL?: boolean): PIXI.WebGLRenderer | PIXI.CanvasRenderer; + function autoDetectRenderer(width: number, height: number, options?: PIXI.RendererOptions, forceCanvas?: boolean): PIXI.WebGLRenderer | PIXI.CanvasRenderer; + function autoDetectRenderer(options?: PIXI.RendererOptions): PIXI.WebGLRenderer | PIXI.CanvasRenderer; const loader: PIXI.loaders.Loader; ////////////////////////////////////////////////////////////////////////////// @@ -46,6 +48,9 @@ declare namespace PIXI { clearBeforeRender: boolean, preserveDrawingBuffer: boolean, roundPixels: boolean + width: number, + height: number, + legacy: boolean, }; let TRANSFORM_MODE: number; let GC_MODE: number; @@ -53,6 +58,8 @@ declare namespace PIXI { let GC_MAX_CHECK_COUNT: number; let WRAP_MODE: number; let SCALE_MODE: number; + let PRECISION_VERTEX: string; + let PRECISION_FRAGMENT: string; let PRECISION: string; let UPLOADS_PER_FRAME: number; let CAN_UPLOAD_SAME_BUFFER: boolean; @@ -66,20 +73,19 @@ declare namespace PIXI { // accessibility class AccessibilityManager { constructor(renderer: CanvasRenderer | WebGLRenderer); - + activate(): void; + deactivate(): void; protected div: HTMLElement; protected pool: HTMLElement[]; protected renderId: number; debug: boolean; renderer: SystemRenderer; - protected children: IAccessibleTarget[]; + protected children: AccessibleTarget[]; protected isActive: boolean; - protected activate(): void; - protected deactivate(): void; protected updateAccessibleObjects(displayObject: DisplayObject): void; protected update(): void; - protected capHitArea(hitArea: IHitArea): void; + protected capHitArea(hitArea: HitArea): void; protected addChild(displayObject: DisplayObject): void; protected _onClick(e: interaction.InteractionEvent): void; protected _onFocus(e: interaction.InteractionEvent): void; @@ -89,7 +95,7 @@ declare namespace PIXI { destroy(): void; } - interface IAccessibleTarget { + interface AccessibleTarget { accessible: boolean; accessibleTitle: string | null; accessibleHint: string | null; @@ -132,6 +138,9 @@ declare namespace PIXI { SATURATION: number; COLOR: number; LUMINOSITY: number; + NORMAL_NPM: number; + ADD_NPM: number; + SCREEN_NPM: number; }; const DRAW_MODES: { POINTS: number; @@ -179,11 +188,18 @@ declare namespace PIXI { LINEAR_VERTICAL: number; LINEAR_HORIZONTAL: number; }; + const UPDATE_PRIORITY: { + INTERACTION: number; + HIGH: number; + NORMAL: number; + LOW: number; + UTILITY: number; + }; } // display - interface IApplicationOptions extends IRendererOptions { + interface ApplicationOptions extends RendererOptions { view?: HTMLCanvasElement; transparent?: boolean; autoResize?: boolean; @@ -195,10 +211,16 @@ declare namespace PIXI { context?: WebGLRenderingContext; preserveDrawingBuffer?: boolean; legacy?: boolean; + width?: number; + height?: number; + forceCanvas?: boolean; + sharedTicker?: boolean; + sharedLoader?: boolean; } class Application { - constructor(width?: number, height?: number, options?: IApplicationOptions, noWebGL?: boolean, useSharedTicker?: boolean); + constructor(options?: ApplicationOptions) + constructor(width?: number, height?: number, options?: ApplicationOptions, noWebGL?: boolean, sharedTicker?: boolean, sharedLoader?: boolean); private _ticker: ticker.Ticker; @@ -214,7 +236,7 @@ declare namespace PIXI { readonly view: HTMLCanvasElement; } - interface IDestroyOptions { + interface DestroyOptions { children?: boolean; texture?: boolean; baseTexture?: boolean; @@ -266,17 +288,18 @@ declare namespace PIXI { protected _renderWebGL(renderer: WebGLRenderer): void; protected _renderCanvas(renderer: CanvasRenderer): void; renderCanvas(renderer: CanvasRenderer): void; - destroy(options?: IDestroyOptions | boolean): void; + destroy(options?: DestroyOptions | boolean): void; - once(event: "added", fn: (displayObject: DisplayObject) => void, context?: any): this; - once(event: "removed", fn: (DisplayObject: DisplayObject) => void, context?: any): this; + once(event: "added" | "removed", fn: (displayObject: DisplayObject) => void, context?: any): this; + //tslint:disable-next-line:ban-types forbidden-types once(event: string, fn: Function, context?: any): this; - on(event: "added", fn: (displayObject: DisplayObject) => void, context?: any): this; - on(event: "removed", fn: (DisplayObject: DisplayObject) => void, context?: any): this; + on(event: "added" | "removed", fn: (displayObject: DisplayObject) => void, context?: any): this; + //tslint:disable-next-line:ban-types forbidden-types on(event: string, fn: Function, context?: any): this; - off(event: string, fn: Function, context?: any): this; + //tslint:disable-next-line:ban-types forbidden-types + off(event: "added" | "removed" | string, fn?: Function, context?: any): this; } - class DisplayObject extends utils.EventEmitter implements interaction.InteractiveTarget, accessibility.IAccessibleTarget { + class DisplayObject extends utils.EventEmitter implements interaction.InteractiveTarget, accessibility.AccessibleTarget { // begin extras.cacheAsBitmap protected _cacheAsBitmap: boolean; protected _cacheData: boolean; @@ -288,7 +311,7 @@ declare namespace PIXI { protected _calculateCachedBounds(): Rectangle; protected _getCachedLocalBounds(): Rectangle; protected _destroyCachedDisplayObject(): void; - protected _cacheAsBitmapDestroy(): void; + protected _cacheAsBitmapDestroy(options: boolean | any): void; // end extras.cacheAsBitmap // begin extras.getChildByName @@ -332,14 +355,15 @@ declare namespace PIXI { protected _boundsRect: Rectangle; protected _localBoundsRect: Rectangle; protected _mask: PIXI.Graphics | PIXI.Sprite; + protected readonly _destroyed: boolean; x: number; y: number; worldTransform: Matrix; localTransform: Matrix; - position: Point; - scale: Point; - pivot: Point; - skew: Point; + position: Point | ObservablePoint; + scale: Point | ObservablePoint; + pivot: Point | ObservablePoint; + skew: ObservablePoint; rotation: number; worldVisible: boolean; mask: PIXI.Graphics | PIXI.Sprite; @@ -350,55 +374,27 @@ declare namespace PIXI { protected _recursivePostUpdateTransform(): void; getBounds(skipUpdate?: boolean, rect?: Rectangle): Rectangle; getLocalBounds(rect?: Rectangle): Rectangle; - toGlobal(position: Point, point?: Point, skipUpdate?: boolean): Point; - toLocal(position: Point, from?: DisplayObject, point?: Point, skipUpdate?: boolean): Point; + //creates and returns a new point + toGlobal(position: PointLike): Point; + //modifies the x and y of the passed point and returns it + toGlobal(position: PointLike, point?: T, skipUpdate?: boolean): T; + //creates and returns a new point + toLocal(position: PointLike, from?: DisplayObject): Point; + //modifies the x and y of the passed point and returns it + toLocal(position: PointLike, from?: DisplayObject, point?: T, skipUpdate?: boolean): T; renderWebGL(renderer: WebGLRenderer): void; renderCanvas(renderer: CanvasRenderer): void; setParent(container: Container): Container; setTransform(x?: number, y?: number, scaleX?: number, scaleY?: number, rotation?: number, skewX?: number, skewY?: number, pivotX?: number, pivotY?: number): DisplayObject; destroy(): void; - on(event: string, fn: Function, context?: any): this; - once(event: string, fn: Function, context?: any): this; - off(event: string, fn: Function, context?: any): this; - - /* - on(event: 'click', fn: (event: interaction.InteractionEvent) => void, context?: any): this; - on(event: 'mousedown', fn: (event: interaction.InteractionEvent) => void, context?: any): this; - on(event: 'mouseout', fn: (event: interaction.InteractionEvent) => void, context?: any): this; - on(event: 'mouseover', fn: (event: interaction.InteractionEvent) => void, context?: any): this; - on(event: 'mouseup', fn: (event: interaction.InteractionEvent) => void, context?: any): this; - on(event: 'mouseclick', fn: (event: interaction.InteractionEvent) => void, context?: any): this; - on(event: 'mouseupoutside', fn: (event: interaction.InteractionEvent) => void, context?: any): this; - on(event: 'rightclick', fn: (event: interaction.InteractionEvent) => void, context?: any): this; - on(event: 'rightdown', fn: (event: interaction.InteractionEvent) => void, context?: any): this; - on(event: 'rightup', fn: (event: interaction.InteractionEvent) => void, context?: any): this; - on(event: 'rightupoutside', fn: (event: interaction.InteractionEvent) => void, context?: any): this; - on(event: 'tap', fn: (event: interaction.InteractionEvent) => void, context?: any): this; - on(event: 'touchend', fn: (event: interaction.InteractionEvent) => void, context?: any): this; - on(event: 'touchendoutside', fn: (event: interaction.InteractionEvent) => void, context?: any): this; - on(event: 'touchmove', fn: (event: interaction.InteractionEvent) => void, context?: any): this; - on(event: 'touchstart', fn: (event: interaction.InteractionEvent) => void, context?: any): this; - - once(event: 'click', fn: (event: interaction.InteractionEvent) => void, context?: any): this; - once(event: 'mousedown', fn: (event: interaction.InteractionEvent) => void, context?: any): this; - once(event: 'mouseout', fn: (event: interaction.InteractionEvent) => void, context?: any): this; - once(event: 'mouseover', fn: (event: interaction.InteractionEvent) => void, context?: any): this; - once(event: 'mouseup', fn: (event: interaction.InteractionEvent) => void, context?: any): this; - once(event: 'mouseclick', fn: (event: interaction.InteractionEvent) => void, context?: any): this; - once(event: 'mouseupoutside', fn: (event: interaction.InteractionEvent) => void, context?: any): this; - once(event: 'rightclick', fn: (event: interaction.InteractionEvent) => void, context?: any): this; - once(event: 'rightdown', fn: (event: interaction.InteractionEvent) => void, context?: any): this; - once(event: 'rightup', fn: (event: interaction.InteractionEvent) => void, context?: any): this; - once(event: 'rightupoutside', fn: (event: interaction.InteractionEvent) => void, context?: any): this; - once(event: 'tap', fn: (event: interaction.InteractionEvent) => void, context?: any): this; - once(event: 'touchend', fn: (event: interaction.InteractionEvent) => void, context?: any): this; - once(event: 'touchendoutside', fn: (event: interaction.InteractionEvent) => void, context?: any): this; - once(event: 'touchmove', fn: (event: interaction.InteractionEvent) => void, context?: any): this; - once(event: 'touchstart', fn: (event: interaction.InteractionEvent) => void, context?: any): this; - */ + on(event: interaction.InteractionEventTypes, fn: (event: interaction.InteractionEvent) => void, context?: any): this; + once(event: interaction.InteractionEventTypes, fn: (event: interaction.InteractionEvent) => void, context?: any): this; + removeListener(event: interaction.InteractionEventTypes, fn?: (event: interaction.InteractionEvent) => void, context?: any): this; + removeAllListeners(event: interaction.InteractionEventTypes): this; + off(event: interaction.InteractionEventTypes, fn?: (event: interaction.InteractionEvent) => void, context?: any): this; + addListener(event: interaction.InteractionEventTypes, fn: (event: interaction.InteractionEvent) => void, context?: any): this; } - class TransformBase { static IDENTITY: TransformBase; @@ -429,7 +425,6 @@ declare namespace PIXI { updateLocalTransform(): void; updateTransform(parentTransform: TransformBase): void; setFromMatrix(matrix: Matrix): void; - rotation: number; } class Transform extends TransformBase { @@ -453,9 +448,7 @@ declare namespace PIXI { rotation: number; } - // graphics - class GraphicsData { constructor( lineWidth: number, @@ -465,8 +458,7 @@ declare namespace PIXI { fillAlpha: number, fill: boolean, nativeLines: boolean, - shape: IShape | Circle | Rectangle | RoundedRectangle | Ellipse | Polygon); - + shape: Circle | Rectangle | Ellipse | Polygon | RoundedRectangle | any); lineWidth: number; nativeLines: boolean; lineColor: number; @@ -476,12 +468,12 @@ declare namespace PIXI { fillAlpha: number; protected _fillTint: number; fill: boolean; - protected holes: IShape[]; - shape: IShape | Circle | Rectangle | RoundedRectangle | Ellipse | Polygon; + protected holes: Circle[] | Rectangle[] | Ellipse[] | Polygon[] | RoundedRectangle[] | any[]; + shape: Circle | Rectangle | Ellipse | Polygon | RoundedRectangle | any; type?: number; clone(): GraphicsData; - addHole(shape: IShape | Circle | Rectangle | RoundedRectangle | Ellipse | Polygon): void; - destroy(options?: IDestroyOptions | boolean): void; + addHole(shape: Circle | Rectangle | Ellipse | Polygon | RoundedRectangle | any): void; + destroy(options?: DestroyOptions | boolean): void; } class Graphics extends Container { constructor(nativeLines?: boolean); @@ -499,7 +491,7 @@ declare namespace PIXI { isMask: boolean; boundsPadding: number; protected _localBounds: Bounds; - dirty: boolean; + dirty: number; fastRectDirty: number; clearDirty: number; boundsDirty: number; @@ -531,11 +523,11 @@ declare namespace PIXI { protected _renderSpriteRect(renderer: PIXI.SystemRenderer): void; containsPoint(point: Point): boolean; updateLocalBounds(): void; - drawShape(shape: IShape | Circle | Rectangle | Ellipse | Polygon | RoundedRectangle): GraphicsData; + drawShape(shape: Circle | Rectangle | Ellipse | Polygon | RoundedRectangle | any): GraphicsData; generateCanvasTexture(scaleMode?: number, resolution?: number): Texture; protected closePath(): Graphics; protected addHole(): Graphics; - destroy(options?: IDestroyOptions | boolean): void; + destroy(options?: DestroyOptions | boolean): void; } class CanvasGraphicsRenderer { constructor(renderer: SystemRenderer); @@ -556,10 +548,10 @@ declare namespace PIXI { destroy(): void; render(graphics: Graphics): void; protected updateGraphics(graphics: PIXI.Graphics): void; - getWebGLData(webGL: WebGLRenderingContext, type: number): WebGLGraphicsData; + getWebGLData(webGL: WebGLRenderingContext, type: number, nativeLines: number): WebGLGraphicsData; } class WebGLGraphicsData { - constructor(gl: WebGLRenderingContext, shader: glCore.GLShader, attribsState: glCore.IAttribState); + constructor(gl: WebGLRenderingContext, shader: glCore.GLShader, attribsState: glCore.AttribState); gl: WebGLRenderingContext; color: number[]; @@ -572,6 +564,7 @@ declare namespace PIXI { glIndices: number[]; shader: glCore.GLShader; vao: glCore.VertexArrayObject; + nativeLines: boolean; reset(): void; upload(): void; @@ -592,7 +585,6 @@ declare namespace PIXI { const NE: number; const MIRROR_HORIZONTAL: number; const MIRROR_VERTICAL: number; - function uX(ind: number): number; function uY(ind: number): number; function vX(ind: number): number; @@ -635,32 +627,24 @@ declare namespace PIXI { static IDENTITY: Matrix; static TEMP_MATRIX: Matrix; } - class ObservablePoint { - constructor(cb: Function, scope?: any, x?: number, y?: number); - + class PointLike { x: number; y: number; + + set(x?: number, y?: number): void; + copy(point: PointLike): void; + } + class ObservablePoint extends PointLike { + constructor(cb: () => any, scope?: any, x?: number, y?: number); cb: () => any; scope: any; - - set(x?: number, y?: number): void; - copy(point: Point | ObservablePoint): void; } - class Point { + class Point extends PointLike { constructor(x?: number, y?: number); - - x: number; - y: number; - clone(): Point; - copy(p: Point): void; - equals(p: Point): boolean; - set(x?: number, y?: number): void; + equals(p: PointLike): boolean; } - - interface IShape { - } - interface IHitArea extends IShape { + interface HitArea { contains(x: number, y: number): boolean; } class Circle { @@ -690,7 +674,10 @@ declare namespace PIXI { } class Polygon { constructor(points: Point[] | number[]); + // Note - Rest Params cannot be combined with | + //tslint:disable-next-line:unified-signatures constructor(...points: Point[]); + //tslint:disable-next-line:unified-signatures constructor(...points: number[]); closed: boolean; @@ -736,10 +723,8 @@ declare namespace PIXI { clone(): RoundedRectangle; contains(x: number, y: number): boolean; } - // renderers - - interface IRendererOptions { + interface RendererOptions { view?: HTMLCanvasElement; transparent?: boolean; autoResize?: boolean; @@ -749,11 +734,16 @@ declare namespace PIXI { backgroundColor?: number; roundPixels?: boolean; context?: WebGLRenderingContext; + width?: number; + height?: number; + forceCanvas?: boolean; } class SystemRenderer extends utils.EventEmitter { - constructor(system: string, screenWidth?: number, screenHeight?: number, options?: IRendererOptions); + constructor(system: string, options?: RendererOptions); + constructor(system: string, screenWidth?: number, screenHeight?: number, options?: RendererOptions); type: number; + options: RendererOptions; screen: Rectangle; readonly width: number; readonly height: number; @@ -770,7 +760,6 @@ declare namespace PIXI { protected _backgroundColorString: string; protected _tempDisplayObjectParent: Container; protected _lastObjectRendered: DisplayObject; - backgroundColor: number; resize(screenWidth: number, screenHeight: number): void; generateTexture(displayObject: DisplayObject, scaleMode?: number, resolution?: number): RenderTexture; @@ -779,7 +768,8 @@ declare namespace PIXI { } class CanvasRenderer extends SystemRenderer { // plugintarget mixin start - static __plugins: Object; + static __plugins: any; + //tslint:disable-next-line:ban-types forbidden-types static registerPlugin(pluginName: string, ctor: Function): void; plugins: any; initPlugins(): void; @@ -789,7 +779,8 @@ declare namespace PIXI { // from InteractionManager interaction?: interaction.InteractionManager; - constructor(screenWidth?: number, screenHeight?: number, options?: IRendererOptions); + constructor(options?: RendererOptions); + constructor(screenWidth?: number, screenHeight?: number, options?: RendererOptions); rootContext: CanvasRenderingContext2D; rootResolution?: number; @@ -805,13 +796,12 @@ declare namespace PIXI { destroy(removeView?: boolean): void; clear(clearColor?: string): void; - on(event: "prerender", fn: () => void, context?: any): this; - on(event: "postrender", fn: () => void, context?: any): this; - on(event: string, fn: Function, context?: any): this; - once(event: "prerender", fn: () => void, context?: any): this; - once(event: "postrender", fn: () => void, context?: any): this; - once(event: string, fn: Function, context?: any): this; - off(event: string, fn: Function, context?: any): this; + on(event: "prerender" | "postrender", fn: () => void, context?: any): this; + once(event: "prerender" | "postrender", fn: () => void, context?: any): this; + removeListener(event: "prerender" | "postrender", fn?: () => void, context?: any): this; + removeAllListeners(event: "prerender" | "postrender"): this; + off(event: "prerender" | "postrender", fn?: () => void, context?: any): this; + addListener(event: "prerender" | "postrender", fn: () => void, context?: any): this; } class CanvasMaskManager { constructor(renderer: CanvasRenderer); @@ -835,16 +825,25 @@ declare namespace PIXI { resize(width: number, height: number): void; destroy(): void; } - - interface IWebGLRendererOptions extends IRendererOptions { + interface WebGLRendererOptions { + view?: HTMLCanvasElement; + transparent?: boolean; + autoResize?: boolean; + antialias?: boolean; forceFXAA?: boolean; + resolution?: number; + clearBeforeRender?: boolean; + backgroundColor?: number; preserveDrawingBuffer?: boolean; + roundPixels?: boolean; legacy?: boolean; + width?: number; + height?: number; } - class WebGLRenderer extends SystemRenderer { // plugintarget mixin start - static __plugins: Object; + static __plugins: any; + //tslint:disable-next-line:ban-types forbidden-types static registerPlugin(pluginName: string, ctor: Function): void; plugins: any; initPlugins(): void; @@ -854,7 +853,8 @@ declare namespace PIXI { // from InteractionManager interaction: interaction.InteractionManager; - constructor(screenWidth?: number, screenHeight?: number, options?: IWebGLRendererOptions); + constructor(options?: WebGLRendererOptions); + constructor(screenWidth?: number, screenHeight?: number, options?: WebGLRendererOptions); protected _contextOptions: { alpha: boolean; @@ -875,6 +875,7 @@ declare namespace PIXI { boundTextures: Texture[]; filterManager: FilterManager; textureManager?: TextureManager; + textureGC?: TextureGarbageCollector; extract: extract.WebGLExtract; protected drawModes: any; protected _activeShader: Shader; @@ -900,15 +901,17 @@ declare namespace PIXI { handleContextRestored: () => void; destroy(removeView?: boolean): void; + on(event: "prerender" | "postrender", fn: () => void, context?: any): this; on(event: "context", fn: (gl: WebGLRenderingContext) => void, context?: any): this; - on(event: "prerender", fn: () => void, context?: any): this; - on(event: "postrender", fn: () => void, context?: any): this; - on(event: string, fn: Function, context?: any): this; + once(event: "prerender" | "postrender", fn: () => void, context?: any): this; once(event: "context", fn: (gl: WebGLRenderingContext) => void, context?: any): this; - once(event: "prerender", fn: () => void, context?: any): this; - once(event: "postrender", fn: () => void, context?: any): this; - once(event: string, fn: Function, context?: any): this; - off(event: string, fn: Function, context?: any): this; + removeListener(event: "prerender" | "postrender", fn?: () => void, context?: any): this; + removeListener(event: "context", fn?: (gl: WebGLRenderingContext) => void, context?: any): this; + removeAllListeners(event: "prerender" | "postrender" | "context"): this; + off(event: "prerender" | "postrender", fn?: () => void, context?: any): this; + off(event: "context", fn?: (gl: WebGLRenderingContext) => void, context?: any): this; + addListener(event: "prerender" | "postrender", fn: () => void, context?: any): this; + addListener(event: "context", fn: (gl: WebGLRenderingContext) => void, context?: any): this; } class WebGLState { constructor(gl: WebGLRenderingContext); @@ -919,7 +922,7 @@ declare namespace PIXI { stack: number[]; gl: WebGLRenderingContext; maxAttribs: number; - attribState: glCore.IAttribState; + attribState: glCore.AttribState; nativeVaoExtension: any; push(): void; @@ -938,7 +941,7 @@ declare namespace PIXI { renderer: WebGLRenderer; gl: WebGLRenderingContext; - protected _managedTextures: WebGLTexture[]; + protected _managedTextures: Texture[]; bindTexture(): void; getTexture(): WebGLTexture; @@ -985,6 +988,11 @@ declare namespace PIXI { upload(): Quad; destroy(): void; } + interface FilterDataStackItem { + renderTarget: RenderTarget; + filter: any[]; + bounds: Rectangle; + } class RenderTarget { constructor(gl: WebGLRenderingContext, width: number, height: number, scaleMode: number, resolution: number, root?: boolean); @@ -1004,11 +1012,7 @@ declare namespace PIXI { stencilMaskStack: Graphics[]; filterData: { index: number, - stack: Array<{ - renderTarget: RenderTarget, - filter: any[]; - bounds: Rectangle - }> + stack: FilterDataStackItem[]; }; scaleMode: number; root: boolean; @@ -1029,19 +1033,19 @@ declare namespace PIXI { setBlendMode(blendMode: number): boolean; } + interface FilterManagerStackItem { + renderTarget: RenderTarget; + sourceFrame: Rectangle; + destinationFrame: Rectangle; + filters: Filter[]; + target: any; + resolution: number; + } class FilterManager extends WebGLManager { constructor(renderer: WebGLRenderer); - gl: WebGLRenderingContext; quad: Quad; - stack: Array<{ - renderTarget: RenderTarget; - sourceFrame: Rectangle; - destinationFrame: Rectangle; - filters: Filter[]; - target: any; - resolution: number; - }>; + stack: FilterManagerStackItem[]; stackIndex: number; shaderCache: any; filterData: any; @@ -1098,7 +1102,7 @@ declare namespace PIXI { onContextChange(): void; destroy(): void; } - interface IUniformData { + interface UniformData { type: string; value: any; @@ -1106,19 +1110,20 @@ declare namespace PIXI { name?: string; } class Filter { - constructor(vertexSrc?: string, fragmentSrc?: string, uniforms?: { [name: string]: IUniformData }); + constructor(vertexSrc?: string, fragmentSrc?: string, uniforms?: { [name: string]: UniformData }); vertextSrc?: string; fragmentSrc: string; blendMode: number; - protected uniformData: { [name: string]: IUniformData }; + protected uniformData: { [name: string]: UniformData }; uniforms: { [name: string]: any } | any; glShaders: any; glShaderKey?: number; padding: number; resolution: number; enabled: boolean; - apply(filterManager: FilterManager, input: RenderTarget, output: RenderTarget, clear?: boolean): void; + autoFit: boolean; + apply(filterManager: FilterManager, input: RenderTarget, output: RenderTarget, clear?: boolean, currentState?: any): void; static defaultVertexSrc: string; static defaultFragmentSrc: string; @@ -1167,7 +1172,7 @@ declare namespace PIXI { protected _renderCanvas(renderer: CanvasRenderer): void; getLocalBounds(): Rectangle; containsPoint(point: Point): boolean; - destroy(options?: IDestroyOptions | boolean): void; + destroy(options?: DestroyOptions | boolean): void; static from(source: number | string | BaseTexture | HTMLImageElement | HTMLCanvasElement | HTMLVideoElement): Sprite; static fromFrame(frameId: string): Sprite; @@ -1222,7 +1227,7 @@ declare namespace PIXI { let cacheStepsPerColorChannel: number; let convertTintToImage: boolean; let canUseMultiply: boolean; - let tintMethod: Function; + let tintMethod: number; } // text @@ -1318,12 +1323,35 @@ declare namespace PIXI { wordWrap: boolean; protected _wordWrapWidth: number; wordWrapWidth: number; + toFontString(): string; } + class TextMetrics { + protected _canvas: HTMLCanvasElement; + protected _context: CanvasRenderingContext2D; + protected _fonts: FontMetrics; + text: string; + style: TextStyle; + width: number; + height: number; + lines: number[]; + lineWidgets: number[]; + lineHeight: number; + maxLineWidth: number; + fontProperties: any; + + constructor(text: string, style: TextStyle, width: number, height: number, lines: number[], lineWidths: number[], lineHeight: number, maxLineWidth: number, fontProperties: any); + + static measureText(text: string, style: TextStyle, wordWrap?: boolean, canvas?: HTMLCanvasElement): TextMetrics; + static wordWrap(text: string, style: TextStyle, canvas?: HTMLCanvasElement): string; + static measureFont(font: string): FontMetrics; + } + interface FontMetrics { + ascent: number; + descent: number; + fontSize: number; + } class Text extends Sprite { - static getFontStyle(style: TextStyleOptions): string; - static calculateFontProperties(style: string): any; - constructor(text?: string, style?: TextStyleOptions, canvas?: HTMLCanvasElement); canvas: HTMLCanvasElement; @@ -1331,14 +1359,11 @@ declare namespace PIXI { resolution: number; protected _text: string; protected _style: TextStyle; + //tslint:disable-next-line:ban-types forbidden-types protected _styleListener: Function; protected _font: string; protected localStyleID: number; - static fontPropertiesCache: any; - static fontPropertiesCanvas: HTMLCanvasElement; - static fontPropertiesContext: CanvasRenderingContext2D; - width: number; height: number; style: TextStyle; @@ -1349,17 +1374,14 @@ declare namespace PIXI { protected updateTexture(): void; renderWebGL(renderer: WebGLRenderer): void; protected _renderCanvas(renderer: CanvasRenderer): void; - protected wordWrap(text: string): string; getLocalBounds(rect?: Rectangle): Rectangle; protected _calculateBounds(): void; protected _onStyleChange: () => void; protected _generateFillStyle(style: TextStyle, lines: string[]): string | number | CanvasGradient; - destroy(options?: IDestroyOptions | boolean): void; + destroy(options?: DestroyOptions | boolean): void; dirty: boolean; } - // textures - class BaseRenderTexture extends BaseTexture { constructor(width?: number, height?: number, scaleMode?: number, resolution?: number); @@ -1377,11 +1399,12 @@ declare namespace PIXI { resize(width: number, height: number): void; destroy(): void; - once(event: "update", fn: (baseRenderTexture: BaseRenderTexture) => void, context?: any): this; - once(event: string, fn: Function, context?: any): this; on(event: "update", fn: (baseRenderTexture: BaseRenderTexture) => void, context?: any): this; - on(event: string, fn: Function, context?: any): this; - off(event: string, fn: Function, context?: any): this; + once(event: "update", fn: (baseRenderTexture: BaseRenderTexture) => void, context?: any): this; + removeListener(event: "update", fn?: (baseRenderTexture: BaseRenderTexture) => void, context?: any): this; + removeAllListeners(event: "update"): this; + off(event: "update", fn?: (baseRenderTexture: BaseRenderTexture) => void, context?: any): this; + addListener(event: "update", fn: (baseRenderTexture: BaseRenderTexture) => void, context?: any): this; } class BaseTexture extends utils.EventEmitter { static from(source: string | HTMLImageElement | HTMLCanvasElement, scaleMode?: number, sourceScale?: number): BaseTexture; @@ -1411,6 +1434,9 @@ declare namespace PIXI { protected _glTextures: any; protected _enabled: number; protected _id?: number; + protected _virtualBoundId: number; + protected readonly _destroyed: boolean; + textureCacheIds: string[]; update(): void; protected _updateDimensions(): void; @@ -1426,19 +1452,16 @@ declare namespace PIXI { updateSourceImage(newSrc: string): void; static fromImage(imageUrl: string, crossorigin?: boolean, scaleMode?: number, sourceScale?: number): BaseTexture; - static fromCanvas(canvas: HTMLCanvasElement, scaleMode?: number): BaseTexture; + static fromCanvas(canvas: HTMLCanvasElement, scaleMode?: number, origin?: string): BaseTexture; + static addToCache(baseTexture: BaseTexture, id: string): void; + static removeFromCache(baseTexture: string | BaseTexture): BaseTexture; - on(event: "update", fn: (baseTexture: BaseTexture) => void, context?: any): this; - on(event: "loaded", fn: (baseTexture: BaseTexture) => void, context?: any): this; - on(event: "error", fn: (baseTexture: BaseTexture) => void, context?: any): this; - on(event: "dispose", fn: (baseTexture: BaseTexture) => void, context?: any): this; - on(event: string, fn: Function, context?: any): this; - once(event: "update", fn: (baseTexture: BaseTexture) => void, context?: any): this; - once(event: "loaded", fn: (baseTexture: BaseTexture) => void, context?: any): this; - once(event: "error", fn: (baseTexture: BaseTexture) => void, context?: any): this; - once(event: "dispose", fn: (baseTexture: BaseTexture) => void, context?: any): this; - once(event: string, fn: Function, context?: any): this; - off(event: string, fn: Function, context?: any): this; + on(event: "update" | "loaded" | "error" | "dispose", fn: (baseTexture: BaseTexture) => void, context?: any): this; + once(event: "update" | "loaded" | "error" | "dispose", fn: (baseTexture: BaseTexture) => void, context?: any): this; + removeListener(event: "update" | "loaded" | "error" | "dispose", fn?: (baseTexture: BaseTexture) => void, context?: any): this; + removeAllListeners(event: "update" | "loaded" | "error" | "dispose"): this; + off(event: "update" | "loaded" | "error" | "dispose", fn?: (baseTexture: BaseTexture) => void, context?: any): this; + addListener(event: "update" | "loaded" | "error" | "dispose", fn: (baseTexture: BaseTexture) => void, context?: any): this; } class RenderTexture extends Texture { constructor(baseRenderTexture: BaseRenderTexture, frame?: Rectangle); @@ -1451,8 +1474,6 @@ declare namespace PIXI { static create(width?: number, height?: number, scaleMode?: number, resolution?: number): RenderTexture; } class Texture extends utils.EventEmitter { - static from(source: number | string | HTMLImageElement | HTMLCanvasElement | HTMLVideoElement | BaseTexture): Texture; - constructor(baseTexture: BaseTexture, frame?: Rectangle, orig?: Rectangle, trim?: Rectangle, rotate?: number); noFrame: boolean; @@ -1465,6 +1486,7 @@ declare namespace PIXI { orig: Rectangle; protected _updateID: number; transform: any; + textureCacheIds: string[]; update(): void; protected onBaseTextureLoaded(baseTexture: BaseTexture): void; @@ -1475,12 +1497,17 @@ declare namespace PIXI { static fromImage(imageUrl: string, crossOrigin?: boolean, scaleMode?: number, sourceScale?: number): Texture; static fromFrame(frameId: string): Texture; - static fromCanvas(canvas: HTMLCanvasElement, scaleMode?: number): Texture; + static fromCanvas(canvas: HTMLCanvasElement, scaleMode?: number, origin?: string): Texture; static fromVideo(video: HTMLVideoElement | string, scaleMode?: number): Texture; static fromVideoUrl(videoUrl: string, scaleMode?: number): Texture; + static from(source: number | string | HTMLImageElement | HTMLCanvasElement | HTMLVideoElement | BaseTexture): Texture; static fromLoader(source: HTMLImageElement | HTMLCanvasElement, imageUrl: string, name?: string): Texture; + static addToCache(texture: Texture, id: string): void; + static removeFromCache(texture: string | Texture): Texture; + + // depreciation static addTextureToCache(texture: Texture, id: string): void; - static removeTextureFromCache(id: string): Texture | undefined; + static removeTextureFromCache(id: string): Texture; frame: Rectangle; protected _rotate: boolean | 0; @@ -1489,12 +1516,14 @@ declare namespace PIXI { height: number; static EMPTY: Texture; + static WHITE: Texture; on(event: "update", fn: (texture: Texture) => void, context?: any): this; - on(event: string, fn: Function, context?: any): this; once(event: "update", fn: (texture: Texture) => void, context?: any): this; - once(event: string, fn: Function, context?: any): this; - off(event: string, fn: Function, context?: any): this; + removeListener(event: "update", fn?: (texture: Texture) => void, context?: any): this; + removeAllListeners(event: "update"): this; + off(event: "update", fn?: (texture: Texture) => void, context?: any): this; + addListener(event: "update", fn: (texture: Texture) => void, context?: any): this; } class TextureUvs { x0: number; @@ -1560,16 +1589,26 @@ declare namespace PIXI { namespace ticker { const shared: Ticker; + class TickerListener { + constructor(fn: (deltaTime: number) => void, context?: any, priority?: number, once?: boolean); + fn: (deltaTime: number) => void; + context: any; + priority: number; + once: boolean; + next: TickerListener; + previous: TickerListener; + protected _destroyed: boolean; + match(fn: (deltaTime: number) => void, context?: any): boolean; + emit(deltaTime: number): TickerListener; + connect(previous: TickerListener): void; + destroy(hard?: boolean): void; + } class Ticker { - protected _tick(time: number): void; - protected _emitter: utils.EventEmitter; + protected _tick: (time: number) => void; + protected _head: TickerListener; protected _requestId: number | null; protected _maxElapsedMS: number; - protected _requestIfNeeded(): void; - protected _cancelIfNeeded(): void; - protected _startIfPossible(): void; - autoStart: boolean; deltaTime: number; elapsedMS: number; @@ -1577,15 +1616,22 @@ declare namespace PIXI { speed: number; started: boolean; - FPS: number; + protected _requestIfNeeded(): void; + protected _cancelIfNeeded(): void; + protected _startIfPossible(): void; + + add(fn: (deltaTime: number) => void, context?: any, priority?: number): Ticker; + addOnce(fn: (deltaTime: number) => void, context?: any, priority?: number): Ticker; + //tslint:disable-next-line:ban-types forbidden-types + remove(fn: Function, context?: any, priority?: number): Ticker; + protected _addListener(listener: TickerListener): Ticker; + readonly FPS: number; minFPS: number; - add(fn: (deltaTime: number) => void, context?: any): Ticker; - addOnce(fn: (deltaTime: number) => void, context?: any): Ticker; - remove(fn: (deltaTime: number) => void, context?: any): Ticker; start(): void; stop(): void; - update(): void; + destroy(): void; + update(currentTime?: number): void; } } @@ -1629,7 +1675,7 @@ declare namespace PIXI { ////////////////////////////////////////////////////////////////////////////// namespace extras { - interface IBitmapTextStyle { + interface BitmapTextStyle { font?: string | { name?: string; size?: number; @@ -1640,7 +1686,7 @@ declare namespace PIXI { class BitmapText extends Container { static registerFont(xml: XMLDocument, texture: Texture): any; - constructor(text: string, style?: IBitmapTextStyle); + constructor(text: string, style?: BitmapTextStyle); protected _textWidth: number; protected _textHeight: number; @@ -1656,7 +1702,9 @@ declare namespace PIXI { size?: number; }; protected _text: string; + protected _maxWidth: number; maxWidth: number; + protected _maxLineHeight: number; maxLineHeight: number; protected _anchor: ObservablePoint; dirty: boolean; @@ -1672,17 +1720,22 @@ declare namespace PIXI { static fonts: any; } + interface AnimatedSpriteTextureTimeObject { + texture: Texture; + time?: number; + } class AnimatedSprite extends Sprite { - constructor(textures: Texture[] | Array<{ texture: Texture, time?: number }>, autoUpdate?: boolean); + constructor(textures: Texture[] | AnimatedSpriteTextureTimeObject[], autoUpdate?: boolean); protected _autoUpdate: boolean; protected _textures: Texture[]; protected _durations: number[]; - textures: Texture[] | Array<{ texture: Texture, time?: number }>; + textures: Texture[] | AnimatedSpriteTextureTimeObject[]; animationSpeed: number; loop: boolean; onComplete: () => void; onFrameChange: (currentFrame: number) => void; + onLoop: () => void; protected _currentTime: number; playing: boolean; totalFrames: number; @@ -1692,7 +1745,7 @@ declare namespace PIXI { gotoAndStop(frameNumber: number): void; gotoAndPlay(frameNumber: number): void; protected update(deltaTime: number): void; - destroy(): void; + destroy(options?: DestroyOptions | boolean): void; static fromFrames(frame: string[]): AnimatedSprite; static fromImages(images: string[]): AnimatedSprite; @@ -1711,7 +1764,7 @@ declare namespace PIXI { texture: Texture; - update(forceUpdate?: boolean): void; + update(forceUpdate?: boolean): boolean; } class TilingSprite extends Sprite { constructor(texture: Texture, width?: number, height?: number); @@ -1727,13 +1780,14 @@ declare namespace PIXI { tileScale: Point | ObservablePoint; tilePosition: Point | ObservablePoint; + multiplyUvs(uvs: Float32Array, out: Float32Array): Float32Array; protected _onTextureUpdate(): void; protected _renderWebGL(renderer: WebGLRenderer): void; protected _renderCanvas(renderer: CanvasRenderer): void; protected _calculateBounds(): void; getLocalBounds(rect?: Rectangle): Rectangle; containsPoint(point: Point): boolean; - destroy(): void; + destroy(options?: DestroyOptions | boolean): void; static from(source: number | string | BaseTexture | HTMLCanvasElement | HTMLVideoElement, width?: number, height?: number): TilingSprite; static fromFrame(frameId: string, width?: number, height?: number): TilingSprite; @@ -1802,6 +1856,7 @@ declare namespace PIXI { protected _colorMatrix(matrix: number[]): void; matrix: number[]; + alpha: number; brightness(b: number, multiply?: boolean): void; greyscale(scale: number, multiply?: boolean): void; @@ -1837,7 +1892,9 @@ declare namespace PIXI { // pixi-filters.d.ts todo // https://github.com/pixijs/pixi-filters/ class NoiseFilter extends Filter { + constructor(noise?: number, seed?: number); noise: number; + seed: number; } } @@ -1876,11 +1933,33 @@ declare namespace PIXI { class InteractionData { global: Point; target: DisplayObject; - originalEvent: Event; - identifier?: number; - + originalEvent: MouseEvent | TouchEvent | PointerEvent; + identifier: number; + isPrimary: boolean; + button: number; + buttons: number; + width: number; + height: number; + tiltX: number; + tiltY: number; + pointerType: string; + pressure: number; + rotationAngle: number; + twist: number; + tangentialPressure: number; + readonly pointerID: number; + protected _copyEvent(event: Touch | MouseEvent | PointerEvent): void; + protected _reset(): void; getLocalPosition(displayObject: DisplayObject, point?: Point, globalPos?: Point): Point; } + type InteractionPointerEvents = "pointerdown" | "pointercancel" | "pointerup" | + "pointertap" | "pointerupoutside" | "pointermove" | "pointerover" | "pointerout"; + type InteractionTouchEvents = "touchstart" | "touchcancel" | "touchend" | + "touchendoutside" | "touchmove" | "tap"; + type InteractionMouseEvents = "rightdown" | "mousedown" | "rightup" | "mouseup" | + "rightclick" | "click" | "rightupoutside" | "mouseupoutside" | "mousemove" | + "mouseover" | "mouseout" | "mouseover"; + type InteractionEventTypes = InteractionPointerEvents | InteractionTouchEvents | InteractionMouseEvents; interface InteractionManagerOptions { autoPreventDefault?: boolean; interactionFrequency?: number; @@ -1920,6 +1999,7 @@ declare namespace PIXI { cursor: string; protected _tempPoint: Point; resolution: number; + hitTest(globalPoint: Point, root?: Container): DisplayObject; protected setTargetElement(element: HTMLCanvasElement, resolution?: number): void; protected addEvents(): void; protected removeEvents(): void; @@ -1927,15 +2007,22 @@ declare namespace PIXI { setCursorMode(mode: string): void; protected dispatchEvent(displayObject: Container | Sprite | extras.TilingSprite, eventString: string, eventData: any): void; mapPositionToPoint(point: Point, x: number, y: number): void; + //tslint:disable-next-line:ban-types forbidden-types protected processInteractive( interactionEvent: InteractionEvent, displayObject: PIXI.Container | PIXI.Sprite | PIXI.extras.TilingSprite, func?: Function, hitTest?: boolean, - interactive?: boolean): boolean; - protected onPointerComplete(originalEvent: PointerEvent, cancelled: boolean, func: Function): void; + interactive?: boolean + ): boolean; + //tslint:disable-next-line:ban-types forbidden-types + protected onPointerComplete( + originalEvent: PointerEvent, + cancelled: boolean, + func: Function + ): void; protected getInteractionDataForPointerId(pointerId: number): InteractionData; - protected releaseInteractionDataForPointerId(pointerId: number): void; + protected releaseInteractionDataForPointerId(event: PointerEvent): void; protected configureInteractionEventForDOMEvent(interactionEvent: InteractionEvent, pointerEvent: PointerEvent, interactionData: InteractionData): InteractionEvent; protected normalizeToPointerData(event: TouchEvent | MouseEvent | PointerEvent): PointerEvent[]; destroy(): void; @@ -1955,8 +2042,10 @@ declare namespace PIXI { // 2.0.6 class MiniSignalBinding { + //tslint:disable-next-line:ban-types forbidden-types constructor(fn: Function, once?: boolean, thisArg?: any); + //tslint:disable-next-line:ban-types forbidden-types protected _fn: Function; protected _once: boolean; protected _thisArg: any; @@ -1978,14 +2067,16 @@ declare namespace PIXI { has(node: MiniSignalBinding): boolean; dispatch(): boolean; + //tslint:disable-next-line:ban-types forbidden-types add(fn: Function, thisArg?: any): any; + //tslint:disable-next-line:ban-types forbidden-types once(fn: Function, thisArg?: any): any; detach(node: MiniSignalBinding): MiniSignal; detachAll(): MiniSignal; } namespace loaders { - interface ILoaderOptions { + interface LoaderOptions { crossOrigin?: boolean | string; loadType?: number; xhrType?: string; @@ -1993,7 +2084,7 @@ declare namespace PIXI { loadElement?: HTMLImageElement | HTMLAudioElement | HTMLVideoElement; skipSource?: boolean; } - interface IResourceDictionary { + interface ResourceDictionary { [index: string]: PIXI.loaders.Resource; } @@ -2001,6 +2092,7 @@ declare namespace PIXI { // However, for depreciation reasons, it remains. class Loader extends utils.EventEmitter { // pixi overrides here + //tslint:disable-next-line:ban-types forbidden-types static addPixiMiddleware(fn: Function): void; // below this line is the original non-pixi loader @@ -2016,13 +2108,16 @@ declare namespace PIXI { loading: boolean; defaultQueryString: string; + //tslint:disable-next-line:ban-types forbidden-types protected _beforeMiddleware: Function[]; + //tslint:disable-next-line:ban-types forbidden-types protected _afterMiddleware: Function[]; protected _resourcesParsing: Resource[]; + //tslint:disable-next-line:ban-types forbidden-types protected _boundLoadResource: (r: Resource, d: Function) => void; protected _queue: any; - resources: IResourceDictionary; + resources: ResourceDictionary; onProgress: MiniSignal; onError: MiniSignal; @@ -2031,44 +2126,49 @@ declare namespace PIXI { onComplete: MiniSignal; add(...params: any[]): this; - add(name: string, url: string, options?: ILoaderOptions, cb?: Function): this; - add(url: string, options?: ILoaderOptions, cb?: Function): this; - add(obj: any | any[], options?: ILoaderOptions, cb?: Function): this; + //tslint:disable-next-line:ban-types forbidden-types + add(name: string, url: string, options?: LoaderOptions, cb?: Function): this; + //tslint:disable-next-line:ban-types forbidden-types + add(obj: string | any | any[], options?: LoaderOptions, cb?: Function): this; + //tslint:disable-next-line:ban-types forbidden-types pre(fn: Function): this; + //tslint:disable-next-line:ban-types forbidden-types use(fn: Function): this; reset(): this; + //tslint:disable-next-line:ban-types forbidden-types load(cb?: Function): this; protected _prepareUrl(url: string): string; + //tslint:disable-next-line:ban-types forbidden-types protected _loadResource(resource: Resource, dequeue: Function): void; protected _onComplete(): void; protected _onLoad(resource: Resource): void; + destroy(): void; + // depreciation on(event: "complete", fn: (loader: loaders.Loader, object: any) => void, context?: any): this; on(event: "error", fn: (error: Error, loader: loaders.Loader, resource: Resource) => void, context?: any): this; - on(event: "load", fn: (loader: loaders.Loader, resource: Resource) => void, context?: any): this; - on(event: "progress", fn: (loader: loaders.Loader, resource: Resource) => void, context?: any): this; + on(event: "load" | "progress", fn: (loader: loaders.Loader, resource: Resource) => void, context?: any): this; on(event: "start", fn: (loader: loaders.Loader) => void, context?: any): this; - on(event: string, fn: Function, context?: any): this; once(event: "complete", fn: (loader: loaders.Loader, object: any) => void, context?: any): this; once(event: "error", fn: (error: Error, loader: loaders.Loader, resource: Resource) => void, context?: any): this; - once(event: "load", fn: (loader: loaders.Loader, resource: Resource) => void, context?: any): this; - once(event: "progress", fn: (loader: loaders.Loader, resource: Resource) => void, context?: any): this; + once(event: "load" | "progress", fn: (loader: loaders.Loader, resource: Resource) => void, context?: any): this; once(event: "start", fn: (loader: loaders.Loader) => void, context?: any): this; - once(event: string, fn: Function, context?: any): this; + //tslint:disable-next-line:ban-types forbidden-types + off(event: "complete" | "error" | "load" | "progress" | "start" | string, fn?: Function, context?: any): this; } - interface ITextureDictionary { + interface TextureDictionary { [index: string]: PIXI.Texture; } class Resource { static setExtensionLoadType(extname: string, loadType: number): void; static setExtensionXhrType(extname: string, xhrType: string): void; - constructor(name: string, url: string | string[], options?: ILoaderOptions); + constructor(name: string, url: string | string[], options?: LoaderOptions); protected _flags: number; @@ -2086,14 +2186,23 @@ declare namespace PIXI { type: number; progressChunk: number; + //tslint:disable-next-line:ban-types forbidden-types protected _dequeue: Function; + //tslint:disable-next-line:ban-types forbidden-types protected _onLoadBinding: Function; + //tslint:disable-next-line:ban-types forbidden-types protected _boundComplete: Function; + //tslint:disable-next-line:ban-types forbidden-types protected _boundOnError: Function; + //tslint:disable-next-line:ban-types forbidden-types protected _boundOnProgress: Function; + //tslint:disable-next-line:ban-types forbidden-types protected _boundXhrOnError: Function; + //tslint:disable-next-line:ban-types forbidden-types protected _boundXhrOnAbort: Function; + //tslint:disable-next-line:ban-types forbidden-types protected _boundXhrOnLoad: Function; + //tslint:disable-next-line:ban-types forbidden-types protected _boundXdrOnTimeout: Function; onStart: MiniSignal; @@ -2106,6 +2215,7 @@ declare namespace PIXI { isLoading: boolean; complete(): void; abort(message?: string): void; + //tslint:disable-next-line:ban-types forbidden-types load(cb?: Function): void; protected _hasFlag(flag: number): boolean; @@ -2165,7 +2275,7 @@ declare namespace PIXI { texture: Texture; spineAtlas: any; spineData: any; - textures?: ITextureDictionary; + textures?: TextureDictionary; } } @@ -2192,6 +2302,11 @@ declare namespace PIXI { texture: Texture; tintRgb: Float32Array; protected _glDatas: { [n: number]: any; }; + protected _uvTransform: extras.TextureTransform; + uploadUvTransform: boolean; + multiplyUvs(): void; + refresh(forceUpdate?: boolean): void; + protected _refresh(): void; protected _renderWebGL(renderer: WebGLRenderer): void; protected _renderCanvas(renderer: CanvasRenderer): void; protected _onTextureUpdate(): void; @@ -2262,6 +2377,7 @@ declare namespace PIXI { updateHorizontalVertices(): void; updateVerticalVertices(): void; protected drawSegment(context: CanvasRenderingContext2D | WebGLRenderingContext, textureSource: any, w: number, h: number, x1: number, y1: number, x2: number, y2: number): void; + protected _refresh(): void; } class Rope extends Mesh { @@ -2269,20 +2385,17 @@ declare namespace PIXI { points: Point[]; colors: number[]; - protected _ready: boolean; - refresh(): void; + autoUpdate: boolean; + protected _refresh(): void; - protected _onTextureUpdate(): void; - updateTransform(): void; + refreshVertices(): void; } } - ////////////////////////////////////////////////////////////////////////////// /////////////////////////////PARTICLES//////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////// - namespace particles { - interface IParticleContainerProperties { + interface ParticleContainerProperties { scale?: boolean; position?: boolean; rotation?: boolean; @@ -2290,8 +2403,10 @@ declare namespace PIXI { alpha?: boolean; } class ParticleContainer extends Container { - constructor(size?: number, properties?: IParticleContainerProperties, batchSize?: number); - + constructor(size?: number, properties?: ParticleContainerProperties, batchSize?: number); + protected _tint: number; + protected tintRgb: number | any[]; + tint: number; protected _properties: boolean[]; protected _maxSize: number; protected _batchSize: number; @@ -2302,10 +2417,10 @@ declare namespace PIXI { roundPixels: boolean; baseTexture: BaseTexture; - setProperties(properties: IParticleContainerProperties): void; + setProperties(properties: ParticleContainerProperties): void; protected onChildrenChange: (smallestChildIndex?: number) => void; - destroy(options?: IDestroyOptions | boolean): void; + destroy(options?: DestroyOptions | boolean): void; } class ParticleBuffer { constructor(gl: WebGLRenderingContext, properties: any, dynamicPropertyFlags: any[], size: number); @@ -2325,7 +2440,7 @@ declare namespace PIXI { destroy(): void; } - interface IParticleRendererProperty { + interface ParticleRendererProperty { attribute: number; size: number; uploadFunction(children: PIXI.DisplayObject[], startIndex: number, amount: number, array: number[], stride: number, offset: number): void; @@ -2336,7 +2451,7 @@ declare namespace PIXI { shader: glCore.GLShader; indexBuffer: WebGLBuffer; - properties: IParticleRendererProperty[]; + properties: ParticleRendererProperty[]; protected tempMatrix: Matrix; start(): void; @@ -2350,13 +2465,10 @@ declare namespace PIXI { indices: Uint16Array; } - interface IParticleShader extends glCore.GLShader { } } - ////////////////////////////////////////////////////////////////////////////// ////////////////////////////PREPARE/////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////// - namespace prepare { type AddHook = (item: any, queue: any[]) => boolean; type UploadHook = (prepare: UploadHookSource, item: any) => boolean; @@ -2369,14 +2481,20 @@ declare namespace PIXI { protected queue: any[]; protected addHooks: AddHook[]; protected uploadHooks: Array>; + //tslint:disable-next-line:ban-types forbidden-types protected completes: Function[]; protected ticking: boolean; protected delayedTick: () => void; + //tslint:disable-next-line:ban-types forbidden-types upload(item: Function | DisplayObject | Container | BaseTexture | Texture | Graphics | Text | any, done?: () => void): void; protected tick(): void; protected prepareItems(): void; - register(addHook?: AddHook, uploadHook?: UploadHook): this; + registerFindHook(addHook: AddHook): this; + registerUploadHook(uploadHook: UploadHook): this; + protected findMultipleBaseTextures(item: PIXI.DisplayObject, queue: any[]): boolean; + protected findBaseTexture(item: PIXI.DisplayObject, queue: any[]): boolean; + protected findTexture(item: PIXI.DisplayObject, queue: any[]): boolean; add(item: PIXI.DisplayObject | PIXI.Container | PIXI.BaseTexture | PIXI.Texture | PIXI.Graphics | PIXI.Text | any): this; destroy(): void; } @@ -2410,7 +2528,7 @@ declare namespace PIXI { // sharedArrayBuffer as a type is not available yet. // need to fully define what an `Attrib` is. namespace glCore { - interface IContextOptions { + interface ContextOptions { /** * Boolean that indicates if the canvas contains an alpha buffer. */ @@ -2440,8 +2558,8 @@ declare namespace PIXI { */ failIfMajorPerformanceCaveat?: boolean; } - function createContext(view: HTMLCanvasElement, options?: IContextOptions): WebGLRenderingContext; - function setVertexAttribArrays(gl: WebGLRenderingContext, attribs: IAttrib[], state?: WebGLState): WebGLRenderingContext | undefined; + function createContext(view: HTMLCanvasElement, options?: ContextOptions): WebGLRenderingContext; + function setVertexAttribArrays(gl: WebGLRenderingContext, attribs: Attrib[], state?: WebGLState): WebGLRenderingContext | undefined; class GLBuffer { constructor(gl: WebGLRenderingContext, type: number, data: ArrayBuffer | ArrayBufferView | any, drawType: number); @@ -2483,7 +2601,7 @@ declare namespace PIXI { static createFloat32(gl: WebGLRenderingContext, width: number, height: number, data: ArrayBuffer | ArrayBufferView | any): GLFramebuffer; } class GLShader { - constructor(gl: WebGLRenderingContext, vertexSrc: string | string[], fragmentSrc: string | string[], precision: string, attributeLocations: { [key: string]: number }); + constructor(gl: WebGLRenderingContext, vertexSrc: string | string[], fragmentSrc: string | string[], precision?: string, attributeLocations?: { [key: string]: number }); gl: WebGLRenderingContext; program?: WebGLProgram | null; @@ -2507,7 +2625,7 @@ declare namespace PIXI { type: number; upload(source: HTMLImageElement | ImageData | HTMLVideoElement | HTMLCanvasElement): void; - uploadData(data: number, width: number, height: number): void; + uploadData(data: ArrayBuffer | ArrayBufferView, width: number, height: number): void; bind(location?: number): void; unbind(): void; minFilter(linear: boolean): void; @@ -2523,9 +2641,9 @@ declare namespace PIXI { static fromSource(gl: WebGLRenderingContext, source: HTMLImageElement | ImageData | HTMLVideoElement | HTMLCanvasElement, premultipleAlpha?: boolean): GLTexture; static fromData(gl: WebGLRenderingContext, data: number[], width: number, height: number): GLTexture; } - interface IAttrib { + interface Attrib { attribute: { - location: boolean; + location: number; size: number; }; normalized: boolean; @@ -2533,7 +2651,7 @@ declare namespace PIXI { start: number; buffer: ArrayBuffer; } - interface IWebGLRenderingContextAttribute { + interface WebGLRenderingContextAttribute { buffer: WebGLBuffer; attribute: any; type: number; @@ -2541,28 +2659,27 @@ declare namespace PIXI { stride: number; start: number; } - interface IAttribState { - tempAttribState: IAttrib[]; - attribState: IAttrib[]; + interface AttribState { + tempAttribState: Attrib[]; + attribState: Attrib[]; } - class VertexArrayObject { static FORCE_NATIVE: boolean; constructor(gl: WebGLRenderingContext, state: WebGLState); protected nativeVaoExtension: any; - protected nativeState: IAttribState; + protected nativeState: AttribState; protected nativeVao: VertexArrayObject; gl: WebGLRenderingContext; - attributes: IAttrib[]; + attributes: Attrib[]; indexBuffer: GLBuffer; dirty: boolean; bind(): VertexArrayObject; unbind(): VertexArrayObject; activate(): VertexArrayObject; - addAttribute(buffer: GLBuffer, attribute: IAttrib, type: number, normalized: boolean, stride: number, start: number): VertexArrayObject; + addAttribute(buffer: GLBuffer, attribute: Attrib, type: number, normalized: boolean, stride: number, start: number): VertexArrayObject; addIndex(buffer: GLBuffer, options?: any): VertexArrayObject; clear(): VertexArrayObject; draw(type: number, size: number, start: number): VertexArrayObject; @@ -2574,7 +2691,7 @@ declare namespace PIXI { ///////////////////////////////UTILS////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////// - interface IDecomposedDataUri { + interface DecomposedDataUri { mediaType: string; subType: string; encoding: string; @@ -2585,11 +2702,11 @@ declare namespace PIXI { function uid(): number; function hex2rgb(hex: number, out?: number[]): number[]; function hex2string(hex: number): string; - function rgb2hex(rgb: Number[]): number; + function rgb2hex(rgb: number[]): number; function canUseNewCanvasBlendModes(): boolean; function getResolutionOfUrl(url: string, defaultValue?: number): number; function getSvgSize(svgString: string): any; - function decomposeDataUri(dataUri: string): IDecomposedDataUri | void; + function decomposeDataUri(dataUri: string): DecomposedDataUri | void; function getUrlFileExtension(url: string): string | void; function sayHello(type: string): void; function skipHello(): void; @@ -2635,22 +2752,107 @@ declare namespace PIXI { const phone: boolean; const tablet: boolean; } - // https://github.com/primus/eventemitter3 class EventEmitter { - listeners(event: string, exists?: boolean): Function[]; - emit(event: string, ...args: any[]): boolean; - on(event: string, fn: Function, context?: any): this; - once(event: string, fn: Function, context?: any): this; - removeListener(event: string, fn: Function, context?: any, once?: boolean): this; - removeAllListeners(event?: string): this; - eventNames(): string[]; - - off(event: string, fn: Function, context?: any, once?: boolean): this; - addListener(event: string, fn: Function, context?: any): this; + static prefixed: string | boolean; + static EventEmitter: { + new (): EventEmitter; + prefixed: string | boolean; + }; + /** + * Minimal EventEmitter interface that is molded against the Node.js + * EventEmitter interface. + * + * @constructor + * @api public + */ + constructor(); + /** + * Return an array listing the events for which the emitter has registered listeners. + * + * @returns {(string | symbol)[]} + */ + eventNames(): Array<(string | symbol)>; + /** + * Return the listeners registered for a given event. + * + * @param {(string | symbol)} event The event name. + * @returns {Function[]} + */ + //tslint:disable-next-line:ban-types forbidden-types + listeners(event: string | symbol): Function[]; + /** + * Check if there listeners for a given event. + * If `exists` argument is not `true` lists listeners. + * + * @param {(string | symbol)} event The event name. + * @param {boolean} exists Only check if there are listeners. + * @returns {boolean} + */ + listeners(event: string | symbol, exists: boolean): boolean; + /** + * Calls each of the listeners registered for a given event. + * + * @param {(string | symbol)} event The event name. + * @param {...*} args Arguments that are passed to registered listeners + * @returns {boolean} `true` if the event had listeners, else `false`. + */ + emit(event: string | symbol, ...args: any[]): boolean; + /** + * Add a listener for a given event. + * + * @param {(string | symbol)} event The event name. + * @param {Function} fn The listener function. + * @param {*} [context=this] The context to invoke the listener with. + * @returns {EventEmitter} `this`. + */ + //tslint:disable-next-line:ban-types forbidden-types + on(event: string | symbol, fn: Function, context?: any): this; + /** + * Add a one-time listener for a given event. + * + * @param {(string | symbol)} event The event name. + * @param {Function} fn The listener function. + * @param {*} [context=this] The context to invoke the listener with. + * @returns {EventEmitter} `this`. + */ + //tslint:disable-next-line:ban-types forbidden-types + once(event: string | symbol, fn: Function, context?: any): this; + /** + * Remove the listeners of a given event. + * + * @param {(string | symbol)} event The event name. + * @param {Function} fn Only remove the listeners that match this function. + * @param {*} context Only remove the listeners that have this context. + * @param {boolean} once Only remove one-time listeners. + * @returns {EventEmitter} `this`. + */ + //tslint:disable-next-line:ban-types forbidden-types + removeListener(event: string | symbol, fn?: Function, context?: any, once?: boolean): this; + /** + * Remove all listeners, or those of the specified event. + * + * @param {(string | symbol)} event The event name. + * @returns {EventEmitter} `this`. + */ + removeAllListeners(event?: string | symbol): this; + /** + * Alias method for `removeListener` + */ + //tslint:disable-next-line:ban-types forbidden-types + off(event: string | symbol, fn?: Function, context?: any, once?: boolean): this; + /** + * Alias method for `on` + */ + //tslint:disable-next-line:ban-types forbidden-types + addListener(event: string | symbol, fn: Function, context?: any): this; + /** + * This function doesn't apply anymore. + * @deprecated + */ + setMaxListeners(): this; } } - ////////////////////////////////////////////////////////////////////////////// /////////////////////////////depreciation///////////////////////////////////// ////////////////////////////////////////////////////////////////////////////// @@ -2748,6 +2950,16 @@ declare namespace PIXI { */ type TilingSprite = extras.TilingSprite; + /** + * @class + * @private + * @name BaseTextureCache + * @memberof PIXI + * @see PIXI.utils.BaseTextureCache + * @deprecated since version 3.0.0 + */ + type BaseTextureCache = any; + /** * @class * @private @@ -2857,6 +3069,15 @@ declare namespace PIXI { * @deprecated since version 4.2.0 */ type DEFAULT_RENDER_OPTIONS = number; + + /** + * @static + * @name PRECISION + * @memberof PIXI.settings + * @see PIXI.PRECISION + * @deprecated since version 4.4.0 + */ + type PRECISION = string; } namespace extras { @@ -2869,12 +3090,23 @@ declare namespace PIXI { */ type MovieClip = extras.AnimatedSprite; } + namespace settings { + /** + * @static + * @name PRECISION + * @memberof PIXI.settings + * @see PIXI.PRECISION + * @deprecated since version 4.4.0 + */ + type PRECISION = number; + } } declare namespace pixi { const gl: typeof PIXI.glCore; } +//tslint:disable-next-line:no-single-declare-module declare module "pixi.js" { export = PIXI; } diff --git a/types/pixi.js/pixi.js-tests.ts b/types/pixi.js/pixi.js-tests.ts index f73dfd7021..d14d3e0e71 100644 --- a/types/pixi.js/pixi.js-tests.ts +++ b/types/pixi.js/pixi.js-tests.ts @@ -24,7 +24,7 @@ function basics() { private renderer: PIXI.WebGLRenderer; constructor() { // Renderer should allow options from both WebGLRenderer and underlying SystemRenderer - this.renderer = new PIXI.WebGLRenderer(0, 0, { backgroundColor : 0x272d37, forceFXAA: true }); + this.renderer = new PIXI.WebGLRenderer(0, 0, { backgroundColor: 0x272d37, forceFXAA: true }); } } @@ -1507,7 +1507,8 @@ function filters() { maggot.position.y = Math.random() * bounds.height; maggot.scale.set(1 + Math.random() * 0.3); - maggot.original = maggot.scale.clone(); + //tslint:disable-next-line:whitespace + maggot.original = (maggot.scale).clone(); this.maggots.push(maggot); }