index.d.ts 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522
  1. import type { BaseTexture } from '@pixi/core';
  2. import { default as earcut_2 } from 'earcut';
  3. import EventEmitter from 'eventemitter3';
  4. import { isMobile } from '@pixi/settings';
  5. import type { ITypedArray } from '@pixi/core';
  6. import type { Program } from '@pixi/core';
  7. import type { Texture } from '@pixi/core';
  8. export declare type ArrayFixed<T, L extends number> = [T, ...Array<T>] & {
  9. length: L;
  10. };
  11. /**
  12. * @todo Describe property usage
  13. * @static
  14. * @name BaseTextureCache
  15. * @memberof PIXI.utils
  16. * @type {object}
  17. */
  18. export declare const BaseTextureCache: {
  19. [key: string]: BaseTexture;
  20. };
  21. /**
  22. * Creates a Canvas element of the given size to be used as a target for rendering to.
  23. * @class
  24. * @memberof PIXI.utils
  25. */
  26. export declare class CanvasRenderTarget {
  27. /** The Canvas object that belongs to this CanvasRenderTarget. */
  28. canvas: HTMLCanvasElement;
  29. /** A CanvasRenderingContext2D object representing a two-dimensional rendering context. */
  30. context: CanvasRenderingContext2D;
  31. /**
  32. * The resolution / device pixel ratio of the canvas
  33. * @default 1
  34. */
  35. resolution: number;
  36. /**
  37. * @param width - the width for the newly created canvas
  38. * @param height - the height for the newly created canvas
  39. * @param {number} [resolution=PIXI.settings.RESOLUTION] - The resolution / device pixel ratio of the canvas
  40. */
  41. constructor(width: number, height: number, resolution?: number);
  42. /**
  43. * Clears the canvas that was created by the CanvasRenderTarget class.
  44. * @private
  45. */
  46. clear(): void;
  47. /**
  48. * Resizes the canvas to the specified width and height.
  49. * @param desiredWidth - the desired width of the canvas
  50. * @param desiredHeight - the desired height of the canvas
  51. */
  52. resize(desiredWidth: number, desiredHeight: number): void;
  53. /** Destroys this canvas. */
  54. destroy(): void;
  55. /**
  56. * The width of the canvas buffer in pixels.
  57. * @member {number}
  58. */
  59. get width(): number;
  60. set width(val: number);
  61. /**
  62. * The height of the canvas buffer in pixels.
  63. * @member {number}
  64. */
  65. get height(): number;
  66. set height(val: number);
  67. }
  68. /**
  69. * Removes all textures from cache, but does not destroy them
  70. * @memberof PIXI.utils
  71. * @function clearTextureCache
  72. */
  73. export declare function clearTextureCache(): void;
  74. /**
  75. * changes blendMode according to texture format
  76. * @memberof PIXI.utils
  77. * @function correctBlendMode
  78. * @param {number} blendMode - supposed blend mode
  79. * @param {boolean} premultiplied - whether source is premultiplied
  80. * @returns {number} true blend mode for this texture
  81. */
  82. export declare function correctBlendMode(blendMode: number, premultiplied: boolean): number;
  83. /**
  84. * Generic Mask Stack data structure
  85. * @memberof PIXI.utils
  86. * @function createIndicesForQuads
  87. * @param {number} size - Number of quads
  88. * @param {Uint16Array|Uint32Array} [outBuffer] - Buffer for output, length has to be `6 * size`
  89. * @returns {Uint16Array|Uint32Array} - Resulting index buffer
  90. */
  91. export declare function createIndicesForQuads(size: number, outBuffer?: Uint16Array | Uint32Array): Uint16Array | Uint32Array;
  92. /**
  93. * Regexp for data URI.
  94. * Based on: {@link https://github.com/ragingwind/data-uri-regex}
  95. * @static
  96. * @constant {RegExp|string} DATA_URI
  97. * @memberof PIXI
  98. * @example data:image/png;base64
  99. */
  100. export declare const DATA_URI: RegExp;
  101. /**
  102. * @memberof PIXI.utils
  103. * @interface DecomposedDataUri
  104. */
  105. /**
  106. * type, eg. `image`
  107. * @memberof PIXI.utils.DecomposedDataUri#
  108. * @member {string} mediaType
  109. */
  110. /**
  111. * Sub type, eg. `png`
  112. * @memberof PIXI.utils.DecomposedDataUri#
  113. * @member {string} subType
  114. */
  115. /**
  116. * @memberof PIXI.utils.DecomposedDataUri#
  117. * @member {string} charset
  118. */
  119. /**
  120. * Data encoding, eg. `base64`
  121. * @memberof PIXI.utils.DecomposedDataUri#
  122. * @member {string} encoding
  123. */
  124. /**
  125. * The actual data
  126. * @memberof PIXI.utils.DecomposedDataUri#
  127. * @member {string} data
  128. */
  129. /**
  130. * Split a data URI into components. Returns undefined if
  131. * parameter `dataUri` is not a valid data URI.
  132. * @memberof PIXI.utils
  133. * @function decomposeDataUri
  134. * @param {string} dataUri - the data URI to check
  135. * @returns {PIXI.utils.DecomposedDataUri|undefined} The decomposed data uri or undefined
  136. */
  137. export declare function decomposeDataUri(dataUri: string): DecomposedDataUri;
  138. export declare interface DecomposedDataUri {
  139. mediaType: string;
  140. subType: string;
  141. charset: string;
  142. encoding: string;
  143. data: string;
  144. }
  145. /**
  146. * Helper for warning developers about deprecated features & settings.
  147. * A stack track for warnings is given; useful for tracking-down where
  148. * deprecated methods/properties/classes are being used within the code.
  149. * @memberof PIXI.utils
  150. * @function deprecation
  151. * @param {string} version - The version where the feature became deprecated
  152. * @param {string} message - Message should include what is deprecated, where, and the new solution
  153. * @param {number} [ignoreDepth=3] - The number of steps to ignore at the top of the error stack
  154. * this is mostly to ignore internal deprecation calls.
  155. */
  156. export declare function deprecation(version: string, message: string, ignoreDepth?: number): void;
  157. /**
  158. * Destroys all texture in the cache
  159. * @memberof PIXI.utils
  160. * @function destroyTextureCache
  161. */
  162. export declare function destroyTextureCache(): void;
  163. /**
  164. * Sets the `crossOrigin` property for this resource based on if the url
  165. * for this resource is cross-origin. If crossOrigin was manually set, this
  166. * function does nothing.
  167. * Nipped from the resource loader!
  168. * @ignore
  169. * @param {string} url - The url to test.
  170. * @param {object} [loc=window.location] - The location object to test against.
  171. * @returns {string} The crossOrigin value to use (or empty string for none).
  172. */
  173. export declare function determineCrossOrigin(url: string, loc?: Location): string;
  174. export declare type Dict<T> = {
  175. [key: string]: T;
  176. };
  177. export { earcut_2 as earcut }
  178. export { EventEmitter }
  179. declare type FormatFunction = {
  180. (URL: URL, options?: URLFormatOptions): string;
  181. (urlObject: UrlObject | string): string;
  182. };
  183. export declare function getBufferType(array: ITypedArray): 'Float32Array' | 'Uint32Array' | 'Int32Array' | 'Uint16Array' | 'Uint8Array' | null;
  184. /**
  185. * get the resolution / device pixel ratio of an asset by looking for the prefix
  186. * used by spritesheets and image urls
  187. * @memberof PIXI.utils
  188. * @function getResolutionOfUrl
  189. * @param {string} url - the image path
  190. * @param {number} [defaultValue=1] - the defaultValue if no filename prefix is set.
  191. * @returns {number} resolution / device pixel ratio of an asset
  192. */
  193. export declare function getResolutionOfUrl(url: string, defaultValue?: number): number;
  194. /**
  195. * Converts a hexadecimal color number to an [R, G, B] array of normalized floats (numbers from 0.0 to 1.0).
  196. * @example
  197. * PIXI.utils.hex2rgb(0xffffff); // returns [1, 1, 1]
  198. * @memberof PIXI.utils
  199. * @function hex2rgb
  200. * @param {number} hex - The hexadecimal number to convert
  201. * @param {number[]} [out=[]] - If supplied, this array will be used rather than returning a new one
  202. * @returns {number[]} An array representing the [R, G, B] of the color where all values are floats.
  203. */
  204. export declare function hex2rgb(hex: number, out?: Array<number> | Float32Array): Array<number> | Float32Array;
  205. /**
  206. * Converts a hexadecimal color number to a string.
  207. * @example
  208. * PIXI.utils.hex2string(0xffffff); // returns "#ffffff"
  209. * @memberof PIXI.utils
  210. * @function hex2string
  211. * @param {number} hex - Number in hex (e.g., `0xffffff`)
  212. * @returns {string} The string color (e.g., `"#ffffff"`).
  213. */
  214. export declare function hex2string(hex: number): string;
  215. export declare function interleaveTypedArrays(arrays: PackedArray[], sizes: number[]): Float32Array;
  216. export { isMobile }
  217. /**
  218. * Checks if a number is a power of two.
  219. * @function isPow2
  220. * @memberof PIXI.utils
  221. * @param {number} v - input value
  222. * @returns {boolean} `true` if value is power of two
  223. */
  224. export declare function isPow2(v: number): boolean;
  225. /**
  226. * Helper for checking for WebGL support.
  227. * @memberof PIXI.utils
  228. * @function isWebGLSupported
  229. * @returns {boolean} Is WebGL supported.
  230. */
  231. export declare function isWebGLSupported(): boolean;
  232. /**
  233. * Computes ceil of log base 2
  234. * @function log2
  235. * @memberof PIXI.utils
  236. * @param {number} v - input value
  237. * @returns {number} logarithm base 2
  238. */
  239. export declare function log2(v: number): number;
  240. /**
  241. * Rounds to next power of two.
  242. * @function nextPow2
  243. * @memberof PIXI.utils
  244. * @param {number} v - input value
  245. * @returns {number} - next rounded power of two
  246. */
  247. export declare function nextPow2(v: number): number;
  248. declare type PackedArray = Float32Array | Uint32Array | Int32Array | Uint8Array;
  249. /**
  250. * This file contains redeclared types for Node `url` and `querystring` modules. These modules
  251. * don't provide their own typings but instead are a part of the full Node typings. The purpose of
  252. * this file is to redeclare the required types to avoid having the whole Node types as a
  253. * dependency.
  254. */
  255. declare interface ParsedUrlQuery {
  256. [key: string]: string | string[];
  257. }
  258. declare interface ParsedUrlQueryInput {
  259. [key: string]: unknown;
  260. }
  261. declare type ParseFunction = {
  262. (urlStr: string): UrlWithStringQuery;
  263. (urlStr: string, parseQueryString: false | undefined, slashesDenoteHost?: boolean): UrlWithStringQuery;
  264. (urlStr: string, parseQueryString: true, slashesDenoteHost?: boolean): UrlWithParsedQuery;
  265. (urlStr: string, parseQueryString: boolean, slashesDenoteHost?: boolean): Url;
  266. };
  267. export declare interface Path {
  268. toPosix: (path: string) => string;
  269. toAbsolute: (url: string, baseUrl?: string, rootUrl?: string) => string;
  270. isUrl: (path: string) => boolean;
  271. isDataUrl: (path: string) => boolean;
  272. hasProtocol: (path: string) => boolean;
  273. getProtocol: (path: string) => string;
  274. normalize: (path: string) => string;
  275. join: (...paths: string[]) => string;
  276. isAbsolute: (path: string) => boolean;
  277. dirname: (path: string) => string;
  278. rootname: (path: string) => string;
  279. basename: (path: string, ext?: string) => string;
  280. extname: (path: string) => string;
  281. parse: (path: string) => {
  282. root?: string;
  283. dir?: string;
  284. base?: string;
  285. ext?: string;
  286. name?: string;
  287. };
  288. sep: string;
  289. delimiter: string;
  290. }
  291. export declare const path: Path;
  292. /**
  293. * maps premultiply flag and blendMode to adjusted blendMode
  294. * @memberof PIXI.utils
  295. * @constant premultiplyBlendMode
  296. * @type {Array<number[]>}
  297. */
  298. export declare const premultiplyBlendMode: number[][];
  299. /**
  300. * combines rgb and alpha to out array
  301. * @memberof PIXI.utils
  302. * @function premultiplyRgba
  303. * @param {Float32Array|number[]} rgb - input rgb
  304. * @param {number} alpha - alpha param
  305. * @param {Float32Array} [out] - output
  306. * @param {boolean} [premultiply=true] - do premultiply it
  307. * @returns {Float32Array} vec4 rgba
  308. */
  309. export declare function premultiplyRgba(rgb: Float32Array | number[], alpha: number, out?: Float32Array, premultiply?: boolean): Float32Array;
  310. /**
  311. * premultiplies tint
  312. * @memberof PIXI.utils
  313. * @function premultiplyTint
  314. * @param {number} tint - integer RGB
  315. * @param {number} alpha - floating point alpha (0.0-1.0)
  316. * @returns {number} tint multiplied by alpha
  317. */
  318. export declare function premultiplyTint(tint: number, alpha: number): number;
  319. /**
  320. * converts integer tint and float alpha to vec4 form, premultiplies by default
  321. * @memberof PIXI.utils
  322. * @function premultiplyTintToRgba
  323. * @param {number} tint - input tint
  324. * @param {number} alpha - alpha param
  325. * @param {Float32Array} [out] - output
  326. * @param {boolean} [premultiply=true] - do premultiply it
  327. * @returns {Float32Array} vec4 rgba
  328. */
  329. export declare function premultiplyTintToRgba(tint: number, alpha: number, out: Float32Array, premultiply?: boolean): Float32Array;
  330. /**
  331. * @todo Describe property usage
  332. * @static
  333. * @name ProgramCache
  334. * @memberof PIXI.utils
  335. * @type {object}
  336. */
  337. export declare const ProgramCache: {
  338. [key: string]: Program;
  339. };
  340. /**
  341. * Remove items from a javascript array without generating garbage
  342. * @function removeItems
  343. * @memberof PIXI.utils
  344. * @param {Array<any>} arr - Array to remove elements from
  345. * @param {number} startIdx - starting index
  346. * @param {number} removeCount - how many to remove
  347. */
  348. export declare function removeItems(arr: any[], startIdx: number, removeCount: number): void;
  349. declare type ResolveFunction = {
  350. (from: string, to: string): string;
  351. };
  352. /**
  353. * Converts a color as an [R, G, B] array of normalized floats to a hexadecimal number.
  354. * @example
  355. * PIXI.utils.rgb2hex([1, 1, 1]); // returns 0xffffff, which is 16777215 as an integer
  356. * @memberof PIXI.utils
  357. * @function rgb2hex
  358. * @param {number[]} rgb - Array of numbers where all values are normalized floats from 0.0 to 1.0.
  359. * @returns {number} Number in hexadecimal.
  360. */
  361. export declare function rgb2hex(rgb: number[] | Float32Array): number;
  362. /**
  363. * Logs out the version and renderer information for this running instance of PIXI.
  364. * If you don't want to see this message you can run `PIXI.utils.skipHello()` before
  365. * creating your renderer. Keep in mind that doing that will forever make you a jerk face.
  366. * @static
  367. * @function sayHello
  368. * @memberof PIXI.utils
  369. * @param {string} type - The string renderer type to log.
  370. */
  371. export declare function sayHello(type: string): void;
  372. /**
  373. * Returns sign of number
  374. * @memberof PIXI.utils
  375. * @function sign
  376. * @param {number} n - the number to check the sign of
  377. * @returns {number} 0 if `n` is 0, -1 if `n` is negative, 1 if `n` is positive
  378. */
  379. export declare function sign(n: number): -1 | 0 | 1;
  380. /**
  381. * Skips the hello message of renderers that are created after this is run.
  382. * @function skipHello
  383. * @memberof PIXI.utils
  384. */
  385. export declare function skipHello(): void;
  386. /**
  387. * Converts a string to a hexadecimal color number.
  388. * It can handle:
  389. * hex strings starting with #: "#ffffff"
  390. * hex strings starting with 0x: "0xffffff"
  391. * hex strings without prefix: "ffffff"
  392. * css colors: "black"
  393. * @example
  394. * PIXI.utils.string2hex("#ffffff"); // returns 0xffffff, which is 16777215 as an integer
  395. * @memberof PIXI.utils
  396. * @function string2hex
  397. * @param {string} string - The string color (e.g., `"#ffffff"`)
  398. * @returns {number} Number in hexadecimal.
  399. */
  400. export declare function string2hex(string: string): number;
  401. /**
  402. * @todo Describe property usage
  403. * @static
  404. * @name TextureCache
  405. * @memberof PIXI.utils
  406. * @type {object}
  407. */
  408. export declare const TextureCache: {
  409. [key: string]: Texture;
  410. };
  411. /**
  412. * Trim transparent borders from a canvas
  413. * @memberof PIXI.utils
  414. * @function trimCanvas
  415. * @param {HTMLCanvasElement} canvas - the canvas to trim
  416. * @returns {object} Trim data
  417. */
  418. export declare function trimCanvas(canvas: HTMLCanvasElement): {
  419. width: number;
  420. height: number;
  421. data?: ImageData;
  422. };
  423. /**
  424. * Gets the next unique identifier
  425. * @memberof PIXI.utils
  426. * @function uid
  427. * @returns {number} The next unique identifier to use.
  428. */
  429. export declare function uid(): number;
  430. declare interface Url extends UrlObjectCommon {
  431. port?: string;
  432. query?: string | null | ParsedUrlQuery;
  433. }
  434. export declare const url: {
  435. parse: ParseFunction;
  436. format: FormatFunction;
  437. resolve: ResolveFunction;
  438. };
  439. declare interface URLFormatOptions {
  440. auth?: boolean;
  441. fragment?: boolean;
  442. search?: boolean;
  443. unicode?: boolean;
  444. }
  445. declare interface UrlObject extends UrlObjectCommon {
  446. port?: string | number;
  447. query?: string | null | ParsedUrlQueryInput;
  448. }
  449. declare interface UrlObjectCommon {
  450. auth?: string;
  451. hash?: string;
  452. host?: string;
  453. hostname?: string;
  454. href?: string;
  455. path?: string;
  456. pathname?: string;
  457. protocol?: string;
  458. search?: string;
  459. slashes?: boolean;
  460. }
  461. declare interface UrlWithParsedQuery extends Url {
  462. query: ParsedUrlQuery;
  463. }
  464. declare interface UrlWithStringQuery extends Url {
  465. query: string | null;
  466. }
  467. export { }