This commit is contained in:
Akko
2025-08-04 18:57:35 +02:00
parent 8cf6e78a79
commit 9495868c2e
5030 changed files with 518594 additions and 17609 deletions

View File

@@ -0,0 +1,274 @@
import { Container } from '../../../../scene/container/Container';
import { EventEmitter } from '../../../../utils/utils';
import { SystemRunner } from './SystemRunner';
import type { ColorSource } from '../../../../color/Color';
import type { ICanvas } from '../../../../environment/canvas/ICanvas';
import type { Matrix } from '../../../../maths/matrix/Matrix';
import type { Rectangle } from '../../../../maths/shapes/Rectangle';
import type { TypeOrBool } from '../../../../scene/container/destroyTypes';
import type { CLEAR_OR_BOOL } from '../../gl/const';
import type { BackgroundSystem } from '../background/BackgroundSystem';
import type { GenerateTextureOptions, GenerateTextureSystem } from '../extract/GenerateTextureSystem';
import type { PipeConstructor } from '../instructions/RenderPipe';
import type { RenderSurface } from '../renderTarget/RenderTargetSystem';
import type { Texture } from '../texture/Texture';
import type { ViewSystem, ViewSystemDestroyOptions } from '../view/ViewSystem';
import type { SharedRendererOptions } from './SharedSystems';
import type { SystemConstructor } from './System';
export interface RendererConfig {
type: number;
name: string;
runners?: string[];
systems: {
name: string;
value: SystemConstructor;
}[];
renderPipes: {
name: string;
value: PipeConstructor;
}[];
renderPipeAdaptors: {
name: string;
value: any;
}[];
}
/**
* The options for rendering a view.
* @memberof rendering
*/
export interface RenderOptions extends ClearOptions {
/** The container to render. */
container: Container;
/** the transform to apply to the container. */
transform?: Matrix;
}
/**
* The options for clearing the render target.
* @memberof rendering
*/
export interface ClearOptions {
/**
* The render target to render. if this target is a canvas and you are using the WebGL renderer,
* please ensure you have set `multiView` to `true` on renderer.
*/
target?: RenderSurface;
/** The color to clear with. */
clearColor?: ColorSource;
/** The clear mode to use. */
clear?: CLEAR_OR_BOOL;
}
export type RendererDestroyOptions = TypeOrBool<ViewSystemDestroyOptions>;
declare const defaultRunners: readonly ["init", "destroy", "contextChange", "resolutionChange", "reset", "renderEnd", "renderStart", "render", "update", "postrender", "prerender"];
type DefaultRunners = typeof defaultRunners[number];
type Runners = {
[key in DefaultRunners]: SystemRunner;
} & {
[K: ({} & string) | ({} & symbol)]: SystemRunner;
};
/**
* The base class for a PixiJS Renderer. It contains the shared logic for all renderers.
*
* You should not use this class directly, but instead use {@linkrendering.WebGLRenderer}
* or {@link rendering.WebGPURenderer}.
* Alternatively, you can also use {@link rendering.autoDetectRenderer} if you want us to
* determine the best renderer for you.
*
* The renderer is composed of systems that manage specific tasks. The following systems are added by default
* whenever you create a renderer:
*
*
* | Generic Systems | Systems that manage functionality that all renderer types share |
* | ------------------------------------ | ----------------------------------------------------------------------------- |
* | {@link rendering.ViewSystem} | This manages the main view of the renderer usually a Canvas |
* | {@link rendering.BackgroundSystem} | This manages the main views background color and alpha |
* | {@link events.EventSystem} | This manages UI events. |
* | {@link accessibility.AccessibilitySystem} | This manages accessibility features. Requires `import 'pixi.js/accessibility'`|
*
* | Core Systems | Provide an optimised, easy to use API to work with WebGL/WebGPU |
* | ------------------------------------ | ----------------------------------------------------------------------------- |
* | {@link rendering.RenderGroupSystem} | This manages the what what we are rendering to (eg - canvas or texture) |
* | {@link rendering.GlobalUniformSystem} | This manages shaders, programs that run on the GPU to calculate 'em pixels. |
* | {@link rendering.TextureGCSystem} | This will automatically remove textures from the GPU if they are not used. |
*
* | PixiJS High-Level Systems | Set of specific systems designed to work with PixiJS objects |
* | ------------------------------------ | ----------------------------------------------------------------------------- |
* | {@link rendering.HelloSystem} | Says hello, buy printing out the pixi version into the console log (along with the renderer type) |
* | {@link rendering.GenerateTextureSystem} | This adds the ability to generate textures from any Container |
* | {@link rendering.FilterSystem} | This manages the filtering pipeline for post-processing effects. |
* | {@link rendering.PrepareSystem} | This manages uploading assets to the GPU. Requires `import 'pixi.js/prepare'`|
* | {@link rendering.ExtractSystem} | This extracts image data from display objects. |
*
* The breadth of the API surface provided by the renderer is contained within these systems.
* @abstract
* @memberof rendering
* @property {rendering.HelloSystem} hello - HelloSystem instance.
* @property {rendering.RenderGroupSystem} renderGroup - RenderGroupSystem instance.
* @property {rendering.TextureGCSystem} textureGC - TextureGCSystem instance.
* @property {rendering.FilterSystem} filter - FilterSystem instance.
* @property {rendering.GlobalUniformSystem} globalUniforms - GlobalUniformSystem instance.
* @property {rendering.TextureSystem} texture - TextureSystem instance.
* @property {rendering.EventSystem} events - EventSystem instance.
* @property {rendering.ExtractSystem} extract - ExtractSystem instance. Requires `import 'pixi.js/extract'`.
* @property {rendering.PrepareSystem} prepare - PrepareSystem instance. Requires `import 'pixi.js/prepare'`.
* @property {rendering.AccessibilitySystem} accessibility - AccessibilitySystem instance. Requires `import 'pixi.js/accessibility'`.
*/
export declare class AbstractRenderer<PIPES, OPTIONS extends SharedRendererOptions, CANVAS extends ICanvas = HTMLCanvasElement> extends EventEmitter<{
resize: [screenWidth: number, screenHeight: number, resolution: number];
}> {
/** The default options for the renderer. */
static defaultOptions: {
/**
* Default resolution / device pixel ratio of the renderer.
* @default 1
*/
resolution: number;
/**
* Should the `failIfMajorPerformanceCaveat` flag be enabled as a context option used in the `isWebGLSupported`
* function. If set to true, a WebGL renderer can fail to be created if the browser thinks there could be
* performance issues when using WebGL.
*
* In PixiJS v6 this has changed from true to false by default, to allow WebGL to work in as many
* scenarios as possible. However, some users may have a poor experience, for example, if a user has a gpu or
* driver version blacklisted by the
* browser.
*
* If your application requires high performance rendering, you may wish to set this to false.
* We recommend one of two options if you decide to set this flag to false:
*
* 1: Use the Canvas renderer as a fallback in case high performance WebGL is
* not supported.
*
* 2: Call `isWebGLSupported` (which if found in the utils package) in your code before attempting to create a
* PixiJS renderer, and show an error message to the user if the function returns false, explaining that their
* device & browser combination does not support high performance WebGL.
* This is a much better strategy than trying to create a PixiJS renderer and finding it then fails.
* @default false
*/
failIfMajorPerformanceCaveat: boolean;
/**
* Should round pixels be forced when rendering?
* @default false
*/
roundPixels: boolean;
};
readonly type: number;
/** The name of the renderer. */
readonly name: string;
_roundPixels: 0 | 1;
readonly runners: Runners;
readonly renderPipes: PIPES;
/** The view system manages the main canvas that is attached to the DOM */
view: ViewSystem;
/** The background system manages the background color and alpha of the main view. */
background: BackgroundSystem;
/** System that manages the generation of textures from the renderer */
textureGenerator: GenerateTextureSystem;
protected _initOptions: OPTIONS;
protected config: RendererConfig;
private _systemsHash;
private _lastObjectRendered;
/**
* Set up a system with a collection of SystemClasses and runners.
* Systems are attached dynamically to this class when added.
* @param config - the config for the system manager
*/
constructor(config: RendererConfig);
/**
* Initialize the renderer.
* @param options - The options to use to create the renderer.
*/
init(options?: Partial<OPTIONS>): Promise<void>;
/**
* Renders the object to its view.
* @param options - The options to render with.
* @param options.container - The container to render.
* @param [options.target] - The target to render to.
*/
render(options: RenderOptions | Container): void;
/** @deprecated since 8.0.0 */
render(container: Container, options: {
renderTexture: any;
}): void;
/**
* Resizes the WebGL view to the specified width and height.
* @param desiredScreenWidth - The desired width of the screen.
* @param desiredScreenHeight - The desired height of the screen.
* @param resolution - The resolution / device pixel ratio of the renderer.
*/
resize(desiredScreenWidth: number, desiredScreenHeight: number, resolution?: number): void;
clear(options?: ClearOptions): void;
/** The resolution / device pixel ratio of the renderer. */
get resolution(): number;
set resolution(value: number);
/**
* Same as view.width, actual number of pixels in the canvas by horizontal.
* @member {number}
* @readonly
* @default 800
*/
get width(): number;
/**
* Same as view.height, actual number of pixels in the canvas by vertical.
* @default 600
*/
get height(): number;
/**
* The canvas element that everything is drawn to.
* @type {environment.ICanvas}
*/
get canvas(): CANVAS;
/**
* the last object rendered by the renderer. Useful for other plugins like interaction managers
* @readonly
*/
get lastObjectRendered(): Container;
/**
* Flag if we are rendering to the screen vs renderTexture
* @readonly
* @default true
*/
get renderingToScreen(): boolean;
/**
* Measurements of the screen. (0, 0, screenWidth, screenHeight).
*
* Its safe to use as filterArea or hitArea for the whole stage.
*/
get screen(): Rectangle;
/**
* Create a bunch of runners based of a collection of ids
* @param runnerIds - the runner ids to add
*/
private _addRunners;
private _addSystems;
/**
* Add a new system to the renderer.
* @param ClassRef - Class reference
* @param name - Property name for system, if not specified
* will use a static `name` property on the class itself. This
* name will be assigned as s property on the Renderer so make
* sure it doesn't collide with properties on Renderer.
* @returns Return instance of renderer
*/
private _addSystem;
private _addPipes;
destroy(options?: RendererDestroyOptions): void;
/**
* Generate a texture from a container.
* @param options - options or container target to use when generating the texture
* @returns a texture
*/
generateTexture(options: GenerateTextureOptions | Container): Texture;
/**
* Whether the renderer will round coordinates to whole pixels when rendering.
* Can be overridden on a per scene item basis.
*/
get roundPixels(): boolean;
/**
* Overridable function by `pixi.js/unsafe-eval` to silence
* throwing an error if platform doesn't support unsafe-evals.
* @private
* @ignore
*/
_unsafeEvalCheck(): void;
}
export {};

View File

@@ -0,0 +1,301 @@
'use strict';
var Color = require('../../../../color/Color.js');
var autoDetectEnvironment = require('../../../../environment/autoDetectEnvironment.js');
var Container = require('../../../../scene/container/Container.js');
var unsafeEvalSupported = require('../../../../utils/browser/unsafeEvalSupported.js');
var deprecation = require('../../../../utils/logging/deprecation.js');
require('../../../../utils/utils.js');
var _const = require('../../gl/const.js');
var SystemRunner = require('./SystemRunner.js');
var EventEmitter = require('eventemitter3');
"use strict";
const defaultRunners = [
"init",
"destroy",
"contextChange",
"resolutionChange",
"reset",
"renderEnd",
"renderStart",
"render",
"update",
"postrender",
"prerender"
];
const _AbstractRenderer = class _AbstractRenderer extends EventEmitter {
/**
* Set up a system with a collection of SystemClasses and runners.
* Systems are attached dynamically to this class when added.
* @param config - the config for the system manager
*/
constructor(config) {
super();
this.runners = /* @__PURE__ */ Object.create(null);
this.renderPipes = /* @__PURE__ */ Object.create(null);
this._initOptions = {};
this._systemsHash = /* @__PURE__ */ Object.create(null);
this.type = config.type;
this.name = config.name;
this.config = config;
const combinedRunners = [...defaultRunners, ...this.config.runners ?? []];
this._addRunners(...combinedRunners);
this._unsafeEvalCheck();
}
/**
* Initialize the renderer.
* @param options - The options to use to create the renderer.
*/
async init(options = {}) {
const skip = options.skipExtensionImports === true ? true : options.manageImports === false;
await autoDetectEnvironment.loadEnvironmentExtensions(skip);
this._addSystems(this.config.systems);
this._addPipes(this.config.renderPipes, this.config.renderPipeAdaptors);
for (const systemName in this._systemsHash) {
const system = this._systemsHash[systemName];
const defaultSystemOptions = system.constructor.defaultOptions;
options = { ...defaultSystemOptions, ...options };
}
options = { ..._AbstractRenderer.defaultOptions, ...options };
this._roundPixels = options.roundPixels ? 1 : 0;
for (let i = 0; i < this.runners.init.items.length; i++) {
await this.runners.init.items[i].init(options);
}
this._initOptions = options;
}
render(args, deprecated) {
let options = args;
if (options instanceof Container.Container) {
options = { container: options };
if (deprecated) {
deprecation.deprecation(deprecation.v8_0_0, "passing a second argument is deprecated, please use render options instead");
options.target = deprecated.renderTexture;
}
}
options.target || (options.target = this.view.renderTarget);
if (options.target === this.view.renderTarget) {
this._lastObjectRendered = options.container;
options.clearColor = this.background.colorRgba;
}
if (options.clearColor) {
const isRGBAArray = Array.isArray(options.clearColor) && options.clearColor.length === 4;
options.clearColor = isRGBAArray ? options.clearColor : Color.Color.shared.setValue(options.clearColor).toArray();
}
if (!options.transform) {
options.container.updateLocalTransform();
options.transform = options.container.localTransform;
}
this.runners.prerender.emit(options);
this.runners.renderStart.emit(options);
this.runners.render.emit(options);
this.runners.renderEnd.emit(options);
this.runners.postrender.emit(options);
}
/**
* Resizes the WebGL view to the specified width and height.
* @param desiredScreenWidth - The desired width of the screen.
* @param desiredScreenHeight - The desired height of the screen.
* @param resolution - The resolution / device pixel ratio of the renderer.
*/
resize(desiredScreenWidth, desiredScreenHeight, resolution) {
const previousResolution = this.view.resolution;
this.view.resize(desiredScreenWidth, desiredScreenHeight, resolution);
this.emit("resize", this.view.screen.width, this.view.screen.height, this.view.resolution);
if (resolution !== void 0 && resolution !== previousResolution) {
this.runners.resolutionChange.emit(resolution);
}
}
clear(options = {}) {
const renderer = this;
options.target || (options.target = renderer.renderTarget.renderTarget);
options.clearColor || (options.clearColor = this.background.colorRgba);
options.clear ?? (options.clear = _const.CLEAR.ALL);
const { clear, clearColor, target } = options;
Color.Color.shared.setValue(clearColor ?? this.background.colorRgba);
renderer.renderTarget.clear(target, clear, Color.Color.shared.toArray());
}
/** The resolution / device pixel ratio of the renderer. */
get resolution() {
return this.view.resolution;
}
set resolution(value) {
this.view.resolution = value;
this.runners.resolutionChange.emit(value);
}
/**
* Same as view.width, actual number of pixels in the canvas by horizontal.
* @member {number}
* @readonly
* @default 800
*/
get width() {
return this.view.texture.frame.width;
}
/**
* Same as view.height, actual number of pixels in the canvas by vertical.
* @default 600
*/
get height() {
return this.view.texture.frame.height;
}
// NOTE: this was `view` in v7
/**
* The canvas element that everything is drawn to.
* @type {environment.ICanvas}
*/
get canvas() {
return this.view.canvas;
}
/**
* the last object rendered by the renderer. Useful for other plugins like interaction managers
* @readonly
*/
get lastObjectRendered() {
return this._lastObjectRendered;
}
/**
* Flag if we are rendering to the screen vs renderTexture
* @readonly
* @default true
*/
get renderingToScreen() {
const renderer = this;
return renderer.renderTarget.renderingToScreen;
}
/**
* Measurements of the screen. (0, 0, screenWidth, screenHeight).
*
* Its safe to use as filterArea or hitArea for the whole stage.
*/
get screen() {
return this.view.screen;
}
/**
* Create a bunch of runners based of a collection of ids
* @param runnerIds - the runner ids to add
*/
_addRunners(...runnerIds) {
runnerIds.forEach((runnerId) => {
this.runners[runnerId] = new SystemRunner.SystemRunner(runnerId);
});
}
_addSystems(systems) {
let i;
for (i in systems) {
const val = systems[i];
this._addSystem(val.value, val.name);
}
}
/**
* Add a new system to the renderer.
* @param ClassRef - Class reference
* @param name - Property name for system, if not specified
* will use a static `name` property on the class itself. This
* name will be assigned as s property on the Renderer so make
* sure it doesn't collide with properties on Renderer.
* @returns Return instance of renderer
*/
_addSystem(ClassRef, name) {
const system = new ClassRef(this);
if (this[name]) {
throw new Error(`Whoops! The name "${name}" is already in use`);
}
this[name] = system;
this._systemsHash[name] = system;
for (const i in this.runners) {
this.runners[i].add(system);
}
return this;
}
_addPipes(pipes, pipeAdaptors) {
const adaptors = pipeAdaptors.reduce((acc, adaptor) => {
acc[adaptor.name] = adaptor.value;
return acc;
}, {});
pipes.forEach((pipe) => {
const PipeClass = pipe.value;
const name = pipe.name;
const Adaptor = adaptors[name];
this.renderPipes[name] = new PipeClass(
this,
Adaptor ? new Adaptor() : null
);
});
}
destroy(options = false) {
this.runners.destroy.items.reverse();
this.runners.destroy.emit(options);
Object.values(this.runners).forEach((runner) => {
runner.destroy();
});
this._systemsHash = null;
this.renderPipes = null;
}
/**
* Generate a texture from a container.
* @param options - options or container target to use when generating the texture
* @returns a texture
*/
generateTexture(options) {
return this.textureGenerator.generateTexture(options);
}
/**
* Whether the renderer will round coordinates to whole pixels when rendering.
* Can be overridden on a per scene item basis.
*/
get roundPixels() {
return !!this._roundPixels;
}
/**
* Overridable function by `pixi.js/unsafe-eval` to silence
* throwing an error if platform doesn't support unsafe-evals.
* @private
* @ignore
*/
_unsafeEvalCheck() {
if (!unsafeEvalSupported.unsafeEvalSupported()) {
throw new Error("Current environment does not allow unsafe-eval, please use pixi.js/unsafe-eval module to enable support.");
}
}
};
/** The default options for the renderer. */
_AbstractRenderer.defaultOptions = {
/**
* Default resolution / device pixel ratio of the renderer.
* @default 1
*/
resolution: 1,
/**
* Should the `failIfMajorPerformanceCaveat` flag be enabled as a context option used in the `isWebGLSupported`
* function. If set to true, a WebGL renderer can fail to be created if the browser thinks there could be
* performance issues when using WebGL.
*
* In PixiJS v6 this has changed from true to false by default, to allow WebGL to work in as many
* scenarios as possible. However, some users may have a poor experience, for example, if a user has a gpu or
* driver version blacklisted by the
* browser.
*
* If your application requires high performance rendering, you may wish to set this to false.
* We recommend one of two options if you decide to set this flag to false:
*
* 1: Use the Canvas renderer as a fallback in case high performance WebGL is
* not supported.
*
* 2: Call `isWebGLSupported` (which if found in the utils package) in your code before attempting to create a
* PixiJS renderer, and show an error message to the user if the function returns false, explaining that their
* device & browser combination does not support high performance WebGL.
* This is a much better strategy than trying to create a PixiJS renderer and finding it then fails.
* @default false
*/
failIfMajorPerformanceCaveat: false,
/**
* Should round pixels be forced when rendering?
* @default false
*/
roundPixels: false
};
let AbstractRenderer = _AbstractRenderer;
exports.AbstractRenderer = AbstractRenderer;
//# sourceMappingURL=AbstractRenderer.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,299 @@
import { Color } from '../../../../color/Color.mjs';
import { loadEnvironmentExtensions } from '../../../../environment/autoDetectEnvironment.mjs';
import { Container } from '../../../../scene/container/Container.mjs';
import { unsafeEvalSupported } from '../../../../utils/browser/unsafeEvalSupported.mjs';
import { deprecation, v8_0_0 } from '../../../../utils/logging/deprecation.mjs';
import '../../../../utils/utils.mjs';
import { CLEAR } from '../../gl/const.mjs';
import { SystemRunner } from './SystemRunner.mjs';
import EventEmitter from 'eventemitter3';
"use strict";
const defaultRunners = [
"init",
"destroy",
"contextChange",
"resolutionChange",
"reset",
"renderEnd",
"renderStart",
"render",
"update",
"postrender",
"prerender"
];
const _AbstractRenderer = class _AbstractRenderer extends EventEmitter {
/**
* Set up a system with a collection of SystemClasses and runners.
* Systems are attached dynamically to this class when added.
* @param config - the config for the system manager
*/
constructor(config) {
super();
this.runners = /* @__PURE__ */ Object.create(null);
this.renderPipes = /* @__PURE__ */ Object.create(null);
this._initOptions = {};
this._systemsHash = /* @__PURE__ */ Object.create(null);
this.type = config.type;
this.name = config.name;
this.config = config;
const combinedRunners = [...defaultRunners, ...this.config.runners ?? []];
this._addRunners(...combinedRunners);
this._unsafeEvalCheck();
}
/**
* Initialize the renderer.
* @param options - The options to use to create the renderer.
*/
async init(options = {}) {
const skip = options.skipExtensionImports === true ? true : options.manageImports === false;
await loadEnvironmentExtensions(skip);
this._addSystems(this.config.systems);
this._addPipes(this.config.renderPipes, this.config.renderPipeAdaptors);
for (const systemName in this._systemsHash) {
const system = this._systemsHash[systemName];
const defaultSystemOptions = system.constructor.defaultOptions;
options = { ...defaultSystemOptions, ...options };
}
options = { ..._AbstractRenderer.defaultOptions, ...options };
this._roundPixels = options.roundPixels ? 1 : 0;
for (let i = 0; i < this.runners.init.items.length; i++) {
await this.runners.init.items[i].init(options);
}
this._initOptions = options;
}
render(args, deprecated) {
let options = args;
if (options instanceof Container) {
options = { container: options };
if (deprecated) {
deprecation(v8_0_0, "passing a second argument is deprecated, please use render options instead");
options.target = deprecated.renderTexture;
}
}
options.target || (options.target = this.view.renderTarget);
if (options.target === this.view.renderTarget) {
this._lastObjectRendered = options.container;
options.clearColor = this.background.colorRgba;
}
if (options.clearColor) {
const isRGBAArray = Array.isArray(options.clearColor) && options.clearColor.length === 4;
options.clearColor = isRGBAArray ? options.clearColor : Color.shared.setValue(options.clearColor).toArray();
}
if (!options.transform) {
options.container.updateLocalTransform();
options.transform = options.container.localTransform;
}
this.runners.prerender.emit(options);
this.runners.renderStart.emit(options);
this.runners.render.emit(options);
this.runners.renderEnd.emit(options);
this.runners.postrender.emit(options);
}
/**
* Resizes the WebGL view to the specified width and height.
* @param desiredScreenWidth - The desired width of the screen.
* @param desiredScreenHeight - The desired height of the screen.
* @param resolution - The resolution / device pixel ratio of the renderer.
*/
resize(desiredScreenWidth, desiredScreenHeight, resolution) {
const previousResolution = this.view.resolution;
this.view.resize(desiredScreenWidth, desiredScreenHeight, resolution);
this.emit("resize", this.view.screen.width, this.view.screen.height, this.view.resolution);
if (resolution !== void 0 && resolution !== previousResolution) {
this.runners.resolutionChange.emit(resolution);
}
}
clear(options = {}) {
const renderer = this;
options.target || (options.target = renderer.renderTarget.renderTarget);
options.clearColor || (options.clearColor = this.background.colorRgba);
options.clear ?? (options.clear = CLEAR.ALL);
const { clear, clearColor, target } = options;
Color.shared.setValue(clearColor ?? this.background.colorRgba);
renderer.renderTarget.clear(target, clear, Color.shared.toArray());
}
/** The resolution / device pixel ratio of the renderer. */
get resolution() {
return this.view.resolution;
}
set resolution(value) {
this.view.resolution = value;
this.runners.resolutionChange.emit(value);
}
/**
* Same as view.width, actual number of pixels in the canvas by horizontal.
* @member {number}
* @readonly
* @default 800
*/
get width() {
return this.view.texture.frame.width;
}
/**
* Same as view.height, actual number of pixels in the canvas by vertical.
* @default 600
*/
get height() {
return this.view.texture.frame.height;
}
// NOTE: this was `view` in v7
/**
* The canvas element that everything is drawn to.
* @type {environment.ICanvas}
*/
get canvas() {
return this.view.canvas;
}
/**
* the last object rendered by the renderer. Useful for other plugins like interaction managers
* @readonly
*/
get lastObjectRendered() {
return this._lastObjectRendered;
}
/**
* Flag if we are rendering to the screen vs renderTexture
* @readonly
* @default true
*/
get renderingToScreen() {
const renderer = this;
return renderer.renderTarget.renderingToScreen;
}
/**
* Measurements of the screen. (0, 0, screenWidth, screenHeight).
*
* Its safe to use as filterArea or hitArea for the whole stage.
*/
get screen() {
return this.view.screen;
}
/**
* Create a bunch of runners based of a collection of ids
* @param runnerIds - the runner ids to add
*/
_addRunners(...runnerIds) {
runnerIds.forEach((runnerId) => {
this.runners[runnerId] = new SystemRunner(runnerId);
});
}
_addSystems(systems) {
let i;
for (i in systems) {
const val = systems[i];
this._addSystem(val.value, val.name);
}
}
/**
* Add a new system to the renderer.
* @param ClassRef - Class reference
* @param name - Property name for system, if not specified
* will use a static `name` property on the class itself. This
* name will be assigned as s property on the Renderer so make
* sure it doesn't collide with properties on Renderer.
* @returns Return instance of renderer
*/
_addSystem(ClassRef, name) {
const system = new ClassRef(this);
if (this[name]) {
throw new Error(`Whoops! The name "${name}" is already in use`);
}
this[name] = system;
this._systemsHash[name] = system;
for (const i in this.runners) {
this.runners[i].add(system);
}
return this;
}
_addPipes(pipes, pipeAdaptors) {
const adaptors = pipeAdaptors.reduce((acc, adaptor) => {
acc[adaptor.name] = adaptor.value;
return acc;
}, {});
pipes.forEach((pipe) => {
const PipeClass = pipe.value;
const name = pipe.name;
const Adaptor = adaptors[name];
this.renderPipes[name] = new PipeClass(
this,
Adaptor ? new Adaptor() : null
);
});
}
destroy(options = false) {
this.runners.destroy.items.reverse();
this.runners.destroy.emit(options);
Object.values(this.runners).forEach((runner) => {
runner.destroy();
});
this._systemsHash = null;
this.renderPipes = null;
}
/**
* Generate a texture from a container.
* @param options - options or container target to use when generating the texture
* @returns a texture
*/
generateTexture(options) {
return this.textureGenerator.generateTexture(options);
}
/**
* Whether the renderer will round coordinates to whole pixels when rendering.
* Can be overridden on a per scene item basis.
*/
get roundPixels() {
return !!this._roundPixels;
}
/**
* Overridable function by `pixi.js/unsafe-eval` to silence
* throwing an error if platform doesn't support unsafe-evals.
* @private
* @ignore
*/
_unsafeEvalCheck() {
if (!unsafeEvalSupported()) {
throw new Error("Current environment does not allow unsafe-eval, please use pixi.js/unsafe-eval module to enable support.");
}
}
};
/** The default options for the renderer. */
_AbstractRenderer.defaultOptions = {
/**
* Default resolution / device pixel ratio of the renderer.
* @default 1
*/
resolution: 1,
/**
* Should the `failIfMajorPerformanceCaveat` flag be enabled as a context option used in the `isWebGLSupported`
* function. If set to true, a WebGL renderer can fail to be created if the browser thinks there could be
* performance issues when using WebGL.
*
* In PixiJS v6 this has changed from true to false by default, to allow WebGL to work in as many
* scenarios as possible. However, some users may have a poor experience, for example, if a user has a gpu or
* driver version blacklisted by the
* browser.
*
* If your application requires high performance rendering, you may wish to set this to false.
* We recommend one of two options if you decide to set this flag to false:
*
* 1: Use the Canvas renderer as a fallback in case high performance WebGL is
* not supported.
*
* 2: Call `isWebGLSupported` (which if found in the utils package) in your code before attempting to create a
* PixiJS renderer, and show an error message to the user if the function returns false, explaining that their
* device & browser combination does not support high performance WebGL.
* This is a much better strategy than trying to create a PixiJS renderer and finding it then fails.
* @default false
*/
failIfMajorPerformanceCaveat: false,
/**
* Should round pixels be forced when rendering?
* @default false
*/
roundPixels: false
};
let AbstractRenderer = _AbstractRenderer;
export { AbstractRenderer };
//# sourceMappingURL=AbstractRenderer.mjs.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,62 @@
import { CustomRenderPipe } from '../../../../scene/container/CustomRenderPipe';
import { RenderGroupPipe } from '../../../../scene/container/RenderGroupPipe';
import { RenderGroupSystem } from '../../../../scene/container/RenderGroupSystem';
import { SpritePipe } from '../../../../scene/sprite/SpritePipe';
import { RendererInitHook } from '../../../../utils/global/globalHooks';
import { BatcherPipe } from '../../../batcher/shared/BatcherPipe';
import { AlphaMaskPipe } from '../../../mask/alpha/AlphaMaskPipe';
import { ColorMaskPipe } from '../../../mask/color/ColorMaskPipe';
import { StencilMaskPipe } from '../../../mask/stencil/StencilMaskPipe';
import { BackgroundSystem } from '../background/BackgroundSystem';
import { BlendModePipe } from '../blendModes/BlendModePipe';
import { ExtractSystem } from '../extract/ExtractSystem';
import { GenerateTextureSystem } from '../extract/GenerateTextureSystem';
import { GlobalUniformSystem } from '../renderTarget/GlobalUniformSystem';
import { SchedulerSystem } from '../SchedulerSystem';
import { HelloSystem } from '../startup/HelloSystem';
import { RenderableGCSystem } from '../texture/RenderableGCSystem';
import { TextureGCSystem } from '../texture/TextureGCSystem';
import { ViewSystem } from '../view/ViewSystem';
import type { ExtractRendererOptions } from './utils/typeUtils';
export declare const SharedSystems: (typeof BackgroundSystem | typeof GenerateTextureSystem | typeof GlobalUniformSystem | typeof HelloSystem | typeof ViewSystem | typeof RenderGroupSystem | typeof TextureGCSystem | typeof ExtractSystem | typeof RendererInitHook | typeof RenderableGCSystem | typeof SchedulerSystem)[];
export declare const SharedRenderPipes: (typeof BlendModePipe | typeof BatcherPipe | typeof SpritePipe | typeof RenderGroupPipe | typeof AlphaMaskPipe | typeof StencilMaskPipe | typeof ColorMaskPipe | typeof CustomRenderPipe)[];
/**
* Options for the shared systems of a renderer.
* @memberof rendering
*/
export interface SharedRendererOptions extends ExtractRendererOptions<typeof SharedSystems>, PixiMixins.RendererOptions {
/**
* Whether to stop PixiJS from dynamically importing default extensions for the renderer.
* It is false by default, and means PixiJS will load all the default extensions, based
* on the environment e.g browser/webworker.
* If you set this to true, then you will need to manually import the systems and extensions you need.
*
* e.g.
* ```js
* import 'accessibility';
* import 'app';
* import 'events';
* import 'spritesheet';
* import 'graphics';
* import 'mesh';
* import 'text';
* import 'text-bitmap';
* import 'text-html';
* import { autoDetectRenderer } from 'pixi.js';
*
* const renderer = await autoDetectRenderer({
* width: 800,
* height: 600,
* skipExtensionImports: true,
* });
* ```
* @default false
*/
skipExtensionImports?: boolean;
/**
* @default true
* @deprecated since 8.1.6
* @see `skipExtensionImports`
*/
manageImports?: boolean;
}

View File

@@ -0,0 +1,50 @@
'use strict';
var CustomRenderPipe = require('../../../../scene/container/CustomRenderPipe.js');
var RenderGroupPipe = require('../../../../scene/container/RenderGroupPipe.js');
var RenderGroupSystem = require('../../../../scene/container/RenderGroupSystem.js');
var SpritePipe = require('../../../../scene/sprite/SpritePipe.js');
var globalHooks = require('../../../../utils/global/globalHooks.js');
var BatcherPipe = require('../../../batcher/shared/BatcherPipe.js');
var AlphaMaskPipe = require('../../../mask/alpha/AlphaMaskPipe.js');
var ColorMaskPipe = require('../../../mask/color/ColorMaskPipe.js');
var StencilMaskPipe = require('../../../mask/stencil/StencilMaskPipe.js');
var BackgroundSystem = require('../background/BackgroundSystem.js');
var BlendModePipe = require('../blendModes/BlendModePipe.js');
var ExtractSystem = require('../extract/ExtractSystem.js');
var GenerateTextureSystem = require('../extract/GenerateTextureSystem.js');
var GlobalUniformSystem = require('../renderTarget/GlobalUniformSystem.js');
var SchedulerSystem = require('../SchedulerSystem.js');
var HelloSystem = require('../startup/HelloSystem.js');
var RenderableGCSystem = require('../texture/RenderableGCSystem.js');
var TextureGCSystem = require('../texture/TextureGCSystem.js');
var ViewSystem = require('../view/ViewSystem.js');
"use strict";
const SharedSystems = [
BackgroundSystem.BackgroundSystem,
GlobalUniformSystem.GlobalUniformSystem,
HelloSystem.HelloSystem,
ViewSystem.ViewSystem,
RenderGroupSystem.RenderGroupSystem,
TextureGCSystem.TextureGCSystem,
GenerateTextureSystem.GenerateTextureSystem,
ExtractSystem.ExtractSystem,
globalHooks.RendererInitHook,
RenderableGCSystem.RenderableGCSystem,
SchedulerSystem.SchedulerSystem
];
const SharedRenderPipes = [
BlendModePipe.BlendModePipe,
BatcherPipe.BatcherPipe,
SpritePipe.SpritePipe,
RenderGroupPipe.RenderGroupPipe,
AlphaMaskPipe.AlphaMaskPipe,
StencilMaskPipe.StencilMaskPipe,
ColorMaskPipe.ColorMaskPipe,
CustomRenderPipe.CustomRenderPipe
];
exports.SharedRenderPipes = SharedRenderPipes;
exports.SharedSystems = SharedSystems;
//# sourceMappingURL=SharedSystems.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"SharedSystems.js","sources":["../../../../../src/rendering/renderers/shared/system/SharedSystems.ts"],"sourcesContent":["import { CustomRenderPipe } from '../../../../scene/container/CustomRenderPipe';\nimport { RenderGroupPipe } from '../../../../scene/container/RenderGroupPipe';\nimport { RenderGroupSystem } from '../../../../scene/container/RenderGroupSystem';\nimport { SpritePipe } from '../../../../scene/sprite/SpritePipe';\nimport { RendererInitHook } from '../../../../utils/global/globalHooks';\nimport { BatcherPipe } from '../../../batcher/shared/BatcherPipe';\nimport { AlphaMaskPipe } from '../../../mask/alpha/AlphaMaskPipe';\nimport { ColorMaskPipe } from '../../../mask/color/ColorMaskPipe';\nimport { StencilMaskPipe } from '../../../mask/stencil/StencilMaskPipe';\nimport { BackgroundSystem } from '../background/BackgroundSystem';\nimport { BlendModePipe } from '../blendModes/BlendModePipe';\nimport { ExtractSystem } from '../extract/ExtractSystem';\nimport { GenerateTextureSystem } from '../extract/GenerateTextureSystem';\nimport { GlobalUniformSystem } from '../renderTarget/GlobalUniformSystem';\nimport { SchedulerSystem } from '../SchedulerSystem';\nimport { HelloSystem } from '../startup/HelloSystem';\nimport { RenderableGCSystem } from '../texture/RenderableGCSystem';\nimport { TextureGCSystem } from '../texture/TextureGCSystem';\nimport { ViewSystem } from '../view/ViewSystem';\n\nimport type { ExtractRendererOptions } from './utils/typeUtils';\n\nexport const SharedSystems = [\n BackgroundSystem,\n GlobalUniformSystem,\n HelloSystem,\n ViewSystem,\n RenderGroupSystem,\n TextureGCSystem,\n GenerateTextureSystem,\n ExtractSystem,\n RendererInitHook,\n RenderableGCSystem,\n SchedulerSystem,\n];\n\nexport const SharedRenderPipes = [\n BlendModePipe,\n BatcherPipe,\n SpritePipe,\n RenderGroupPipe,\n AlphaMaskPipe,\n StencilMaskPipe,\n ColorMaskPipe,\n CustomRenderPipe\n];\n\n/**\n * Options for the shared systems of a renderer.\n * @memberof rendering\n */\nexport interface SharedRendererOptions extends ExtractRendererOptions<typeof SharedSystems>, PixiMixins.RendererOptions\n{\n /**\n * Whether to stop PixiJS from dynamically importing default extensions for the renderer.\n * It is false by default, and means PixiJS will load all the default extensions, based\n * on the environment e.g browser/webworker.\n * If you set this to true, then you will need to manually import the systems and extensions you need.\n *\n * e.g.\n * ```js\n * import 'accessibility';\n * import 'app';\n * import 'events';\n * import 'spritesheet';\n * import 'graphics';\n * import 'mesh';\n * import 'text';\n * import 'text-bitmap';\n * import 'text-html';\n * import { autoDetectRenderer } from 'pixi.js';\n *\n * const renderer = await autoDetectRenderer({\n * width: 800,\n * height: 600,\n * skipExtensionImports: true,\n * });\n * ```\n * @default false\n */\n skipExtensionImports?: boolean;\n /**\n * @default true\n * @deprecated since 8.1.6\n * @see `skipExtensionImports`\n */\n manageImports?: boolean;\n}\n"],"names":["BackgroundSystem","GlobalUniformSystem","HelloSystem","ViewSystem","RenderGroupSystem","TextureGCSystem","GenerateTextureSystem","ExtractSystem","RendererInitHook","RenderableGCSystem","SchedulerSystem","BlendModePipe","BatcherPipe","SpritePipe","RenderGroupPipe","AlphaMaskPipe","StencilMaskPipe","ColorMaskPipe","CustomRenderPipe"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAsBO,MAAM,aAAgB,GAAA;AAAA,EACzBA,iCAAA;AAAA,EACAC,uCAAA;AAAA,EACAC,uBAAA;AAAA,EACAC,qBAAA;AAAA,EACAC,mCAAA;AAAA,EACAC,+BAAA;AAAA,EACAC,2CAAA;AAAA,EACAC,2BAAA;AAAA,EACAC,4BAAA;AAAA,EACAC,qCAAA;AAAA,EACAC,+BAAA;AACJ,EAAA;AAEO,MAAM,iBAAoB,GAAA;AAAA,EAC7BC,2BAAA;AAAA,EACAC,uBAAA;AAAA,EACAC,qBAAA;AAAA,EACAC,+BAAA;AAAA,EACAC,2BAAA;AAAA,EACAC,+BAAA;AAAA,EACAC,2BAAA;AAAA,EACAC,iCAAA;AACJ;;;;;"}

View File

@@ -0,0 +1,47 @@
import { CustomRenderPipe } from '../../../../scene/container/CustomRenderPipe.mjs';
import { RenderGroupPipe } from '../../../../scene/container/RenderGroupPipe.mjs';
import { RenderGroupSystem } from '../../../../scene/container/RenderGroupSystem.mjs';
import { SpritePipe } from '../../../../scene/sprite/SpritePipe.mjs';
import { RendererInitHook } from '../../../../utils/global/globalHooks.mjs';
import { BatcherPipe } from '../../../batcher/shared/BatcherPipe.mjs';
import { AlphaMaskPipe } from '../../../mask/alpha/AlphaMaskPipe.mjs';
import { ColorMaskPipe } from '../../../mask/color/ColorMaskPipe.mjs';
import { StencilMaskPipe } from '../../../mask/stencil/StencilMaskPipe.mjs';
import { BackgroundSystem } from '../background/BackgroundSystem.mjs';
import { BlendModePipe } from '../blendModes/BlendModePipe.mjs';
import { ExtractSystem } from '../extract/ExtractSystem.mjs';
import { GenerateTextureSystem } from '../extract/GenerateTextureSystem.mjs';
import { GlobalUniformSystem } from '../renderTarget/GlobalUniformSystem.mjs';
import { SchedulerSystem } from '../SchedulerSystem.mjs';
import { HelloSystem } from '../startup/HelloSystem.mjs';
import { RenderableGCSystem } from '../texture/RenderableGCSystem.mjs';
import { TextureGCSystem } from '../texture/TextureGCSystem.mjs';
import { ViewSystem } from '../view/ViewSystem.mjs';
"use strict";
const SharedSystems = [
BackgroundSystem,
GlobalUniformSystem,
HelloSystem,
ViewSystem,
RenderGroupSystem,
TextureGCSystem,
GenerateTextureSystem,
ExtractSystem,
RendererInitHook,
RenderableGCSystem,
SchedulerSystem
];
const SharedRenderPipes = [
BlendModePipe,
BatcherPipe,
SpritePipe,
RenderGroupPipe,
AlphaMaskPipe,
StencilMaskPipe,
ColorMaskPipe,
CustomRenderPipe
];
export { SharedRenderPipes, SharedSystems };
//# sourceMappingURL=SharedSystems.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"SharedSystems.mjs","sources":["../../../../../src/rendering/renderers/shared/system/SharedSystems.ts"],"sourcesContent":["import { CustomRenderPipe } from '../../../../scene/container/CustomRenderPipe';\nimport { RenderGroupPipe } from '../../../../scene/container/RenderGroupPipe';\nimport { RenderGroupSystem } from '../../../../scene/container/RenderGroupSystem';\nimport { SpritePipe } from '../../../../scene/sprite/SpritePipe';\nimport { RendererInitHook } from '../../../../utils/global/globalHooks';\nimport { BatcherPipe } from '../../../batcher/shared/BatcherPipe';\nimport { AlphaMaskPipe } from '../../../mask/alpha/AlphaMaskPipe';\nimport { ColorMaskPipe } from '../../../mask/color/ColorMaskPipe';\nimport { StencilMaskPipe } from '../../../mask/stencil/StencilMaskPipe';\nimport { BackgroundSystem } from '../background/BackgroundSystem';\nimport { BlendModePipe } from '../blendModes/BlendModePipe';\nimport { ExtractSystem } from '../extract/ExtractSystem';\nimport { GenerateTextureSystem } from '../extract/GenerateTextureSystem';\nimport { GlobalUniformSystem } from '../renderTarget/GlobalUniformSystem';\nimport { SchedulerSystem } from '../SchedulerSystem';\nimport { HelloSystem } from '../startup/HelloSystem';\nimport { RenderableGCSystem } from '../texture/RenderableGCSystem';\nimport { TextureGCSystem } from '../texture/TextureGCSystem';\nimport { ViewSystem } from '../view/ViewSystem';\n\nimport type { ExtractRendererOptions } from './utils/typeUtils';\n\nexport const SharedSystems = [\n BackgroundSystem,\n GlobalUniformSystem,\n HelloSystem,\n ViewSystem,\n RenderGroupSystem,\n TextureGCSystem,\n GenerateTextureSystem,\n ExtractSystem,\n RendererInitHook,\n RenderableGCSystem,\n SchedulerSystem,\n];\n\nexport const SharedRenderPipes = [\n BlendModePipe,\n BatcherPipe,\n SpritePipe,\n RenderGroupPipe,\n AlphaMaskPipe,\n StencilMaskPipe,\n ColorMaskPipe,\n CustomRenderPipe\n];\n\n/**\n * Options for the shared systems of a renderer.\n * @memberof rendering\n */\nexport interface SharedRendererOptions extends ExtractRendererOptions<typeof SharedSystems>, PixiMixins.RendererOptions\n{\n /**\n * Whether to stop PixiJS from dynamically importing default extensions for the renderer.\n * It is false by default, and means PixiJS will load all the default extensions, based\n * on the environment e.g browser/webworker.\n * If you set this to true, then you will need to manually import the systems and extensions you need.\n *\n * e.g.\n * ```js\n * import 'accessibility';\n * import 'app';\n * import 'events';\n * import 'spritesheet';\n * import 'graphics';\n * import 'mesh';\n * import 'text';\n * import 'text-bitmap';\n * import 'text-html';\n * import { autoDetectRenderer } from 'pixi.js';\n *\n * const renderer = await autoDetectRenderer({\n * width: 800,\n * height: 600,\n * skipExtensionImports: true,\n * });\n * ```\n * @default false\n */\n skipExtensionImports?: boolean;\n /**\n * @default true\n * @deprecated since 8.1.6\n * @see `skipExtensionImports`\n */\n manageImports?: boolean;\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AAsBO,MAAM,aAAgB,GAAA;AAAA,EACzB,gBAAA;AAAA,EACA,mBAAA;AAAA,EACA,WAAA;AAAA,EACA,UAAA;AAAA,EACA,iBAAA;AAAA,EACA,eAAA;AAAA,EACA,qBAAA;AAAA,EACA,aAAA;AAAA,EACA,gBAAA;AAAA,EACA,kBAAA;AAAA,EACA,eAAA;AACJ,EAAA;AAEO,MAAM,iBAAoB,GAAA;AAAA,EAC7B,aAAA;AAAA,EACA,WAAA;AAAA,EACA,UAAA;AAAA,EACA,eAAA;AAAA,EACA,aAAA;AAAA,EACA,eAAA;AAAA,EACA,aAAA;AAAA,EACA,gBAAA;AACJ;;;;"}

View File

@@ -0,0 +1,10 @@
import type { Renderer } from '../../types';
import type { RendererDestroyOptions } from './AbstractRenderer';
export interface System<INIT_OPTIONS = null, DESTROY_OPTIONS = RendererDestroyOptions> {
init?: (options: INIT_OPTIONS) => void;
/** Generic destroy methods to be overridden by the subclass */
destroy?: (options?: DESTROY_OPTIONS) => void;
}
export interface SystemConstructor {
new (renderer: Renderer): System;
}

View File

@@ -0,0 +1,4 @@
'use strict';
"use strict";
//# sourceMappingURL=System.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"System.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;"}

View File

@@ -0,0 +1,2 @@
"use strict";
//# sourceMappingURL=System.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"System.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":""}

View File

@@ -0,0 +1,98 @@
/**
* SystemRunner is used internally by the renderers as an efficient way for systems to
* be notified about what the renderer is up to during the rendering phase.
*
* ```
* import { SystemRunner } from 'pixi.js';
*
* const myObject = {
* loaded: new SystemRunner('loaded')
* }
*
* const listener = {
* loaded: function(){
* // thin
* }
* }
*
* myObject.loaded.add(listener);
*
* myObject.loaded.emit();
* ```
*
* Or for handling calling the same function on many items
* ```
* import { SystemRunner } from 'pixi.js';
*
* const myGame = {
* update: new SystemRunner('update')
* }
*
* const gameObject = {
* update: function(time){
* // update my gamey state
* }
* }
*
* myGame.update.add(gameObject);
*
* myGame.update.emit(time);
* ```
* @memberof rendering
*/
export declare class SystemRunner {
items: any[];
private _name;
/**
* @param name - The function name that will be executed on the listeners added to this Runner.
*/
constructor(name: string);
/**
* Dispatch/Broadcast Runner to all listeners added to the queue.
* @param {...any} params - (optional) parameters to pass to each listener
*/
emit(a0?: unknown, a1?: unknown, a2?: unknown, a3?: unknown, a4?: unknown, a5?: unknown, a6?: unknown, a7?: unknown): this;
/**
* Add a listener to the Runner
*
* Runners do not need to have scope or functions passed to them.
* All that is required is to pass the listening object and ensure that it has contains a function that has the same name
* as the name provided to the Runner when it was created.
*
* Eg A listener passed to this Runner will require a 'complete' function.
*
* ```
* import { Runner } from 'pixi.js';
*
* const complete = new Runner('complete');
* ```
*
* The scope used will be the object itself.
* @param {any} item - The object that will be listening.
*/
add(item: unknown): this;
/**
* Remove a single listener from the dispatch queue.
* @param {any} item - The listener that you would like to remove.
*/
remove(item: unknown): this;
/**
* Check to see if the listener is already in the Runner
* @param {any} item - The listener that you would like to check.
*/
contains(item: unknown): boolean;
/** Remove all listeners from the Runner */
removeAll(): this;
/** Remove all references, don't use after this. */
destroy(): void;
/**
* `true` if there are no this Runner contains no listeners
* @readonly
*/
get empty(): boolean;
/**
* The name of the runner.
* @readonly
*/
get name(): string;
}

View File

@@ -0,0 +1,96 @@
'use strict';
"use strict";
class SystemRunner {
/**
* @param name - The function name that will be executed on the listeners added to this Runner.
*/
constructor(name) {
this.items = [];
this._name = name;
}
/* eslint-disable jsdoc/require-param, jsdoc/check-param-names */
/**
* Dispatch/Broadcast Runner to all listeners added to the queue.
* @param {...any} params - (optional) parameters to pass to each listener
*/
/* eslint-enable jsdoc/require-param, jsdoc/check-param-names */
emit(a0, a1, a2, a3, a4, a5, a6, a7) {
const { name, items } = this;
for (let i = 0, len = items.length; i < len; i++) {
items[i][name](a0, a1, a2, a3, a4, a5, a6, a7);
}
return this;
}
/**
* Add a listener to the Runner
*
* Runners do not need to have scope or functions passed to them.
* All that is required is to pass the listening object and ensure that it has contains a function that has the same name
* as the name provided to the Runner when it was created.
*
* Eg A listener passed to this Runner will require a 'complete' function.
*
* ```
* import { Runner } from 'pixi.js';
*
* const complete = new Runner('complete');
* ```
*
* The scope used will be the object itself.
* @param {any} item - The object that will be listening.
*/
add(item) {
if (item[this._name]) {
this.remove(item);
this.items.push(item);
}
return this;
}
/**
* Remove a single listener from the dispatch queue.
* @param {any} item - The listener that you would like to remove.
*/
remove(item) {
const index = this.items.indexOf(item);
if (index !== -1) {
this.items.splice(index, 1);
}
return this;
}
/**
* Check to see if the listener is already in the Runner
* @param {any} item - The listener that you would like to check.
*/
contains(item) {
return this.items.indexOf(item) !== -1;
}
/** Remove all listeners from the Runner */
removeAll() {
this.items.length = 0;
return this;
}
/** Remove all references, don't use after this. */
destroy() {
this.removeAll();
this.items = null;
this._name = null;
}
/**
* `true` if there are no this Runner contains no listeners
* @readonly
*/
get empty() {
return this.items.length === 0;
}
/**
* The name of the runner.
* @readonly
*/
get name() {
return this._name;
}
}
exports.SystemRunner = SystemRunner;
//# sourceMappingURL=SystemRunner.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,94 @@
"use strict";
class SystemRunner {
/**
* @param name - The function name that will be executed on the listeners added to this Runner.
*/
constructor(name) {
this.items = [];
this._name = name;
}
/* eslint-disable jsdoc/require-param, jsdoc/check-param-names */
/**
* Dispatch/Broadcast Runner to all listeners added to the queue.
* @param {...any} params - (optional) parameters to pass to each listener
*/
/* eslint-enable jsdoc/require-param, jsdoc/check-param-names */
emit(a0, a1, a2, a3, a4, a5, a6, a7) {
const { name, items } = this;
for (let i = 0, len = items.length; i < len; i++) {
items[i][name](a0, a1, a2, a3, a4, a5, a6, a7);
}
return this;
}
/**
* Add a listener to the Runner
*
* Runners do not need to have scope or functions passed to them.
* All that is required is to pass the listening object and ensure that it has contains a function that has the same name
* as the name provided to the Runner when it was created.
*
* Eg A listener passed to this Runner will require a 'complete' function.
*
* ```
* import { Runner } from 'pixi.js';
*
* const complete = new Runner('complete');
* ```
*
* The scope used will be the object itself.
* @param {any} item - The object that will be listening.
*/
add(item) {
if (item[this._name]) {
this.remove(item);
this.items.push(item);
}
return this;
}
/**
* Remove a single listener from the dispatch queue.
* @param {any} item - The listener that you would like to remove.
*/
remove(item) {
const index = this.items.indexOf(item);
if (index !== -1) {
this.items.splice(index, 1);
}
return this;
}
/**
* Check to see if the listener is already in the Runner
* @param {any} item - The listener that you would like to check.
*/
contains(item) {
return this.items.indexOf(item) !== -1;
}
/** Remove all listeners from the Runner */
removeAll() {
this.items.length = 0;
return this;
}
/** Remove all references, don't use after this. */
destroy() {
this.removeAll();
this.items = null;
this._name = null;
}
/**
* `true` if there are no this Runner contains no listeners
* @readonly
*/
get empty() {
return this.items.length === 0;
}
/**
* The name of the runner.
* @readonly
*/
get name() {
return this._name;
}
}
export { SystemRunner };
//# sourceMappingURL=SystemRunner.mjs.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,66 @@
/**
* TS for extracting the system as a record based on a list of systems
* @example
*
* type Systems = [
* { extension: { name: 'foo' }, defaultOptions: { foo: 1 } },
* { extension: { name: 'bar' }, defaultOptions: { bar: 2 } },
* { extension: { name: 'baz' }, defaultOptions: { baz: 3 } },
* ];
*
* type SystemTypes = ExtractSystemTypes<Systems>;
*
* SystemTypes = {
* foo: { extension: { name: 'foo' }, defaultOptions: { foo: 1 } },
* bar: { extension: { name: 'bar' }, defaultOptions: { bar: 2 } },
* baz: { extension: { name: 'baz' }, defaultOptions: { baz: 3 } },
* }
*/
interface System {
extension: {
name: string;
};
defaultOptions?: any;
new (...args: any): any;
}
type SystemsWithExtensionList = System[];
type InstanceType<T extends new (...args: any) => any> = T extends new (...args: any) => infer R ? R : any;
type NameType<T extends SystemsWithExtensionList> = T[number]['extension']['name'];
export type ExtractSystemTypes<T extends SystemsWithExtensionList> = {
[K in NameType<T>]: InstanceType<Extract<T[number], {
extension: {
name: K;
};
}>>;
};
/**
* TS for extracting the init options based on a list of systems
* @example
*
* const list = [
* { extension: { name: 'foo' }, defaultOptions: { foo: 1 } },
* { extension: { name: 'bar' }, defaultOptions: { bar: 2 } },
* { extension: { name: 'baz' }, defaultOptions: { baz: 3 } },
* ]
*
* type Options = ExtractRendererOptions<typeof list> // { foo: 1 } & { bar: 2 } & { baz: 3 }
*/
type NotUnknown<T> = T extends unknown ? keyof T extends never ? never : T : T;
type KnownProperties<T> = {
[K in keyof T as NotUnknown<T[K]> extends never ? never : K]: T[K];
};
type FlattenOptions<T> = T extends {
[K: string]: infer U;
} ? U : never;
type OptionsUnion<T extends SystemsWithExtensionList> = FlattenOptions<SeparateOptions<T>>;
type DefaultOptionsTypes<T extends SystemsWithExtensionList> = {
[K in NameType<T>]: Extract<T[number], {
extension: {
name: K;
};
}>['defaultOptions'];
};
type SeparateOptions<T extends SystemsWithExtensionList> = KnownProperties<DefaultOptionsTypes<T>>;
type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends ((k: infer I) => void) ? I : never;
export type ExtractRendererOptions<T extends SystemsWithExtensionList> = UnionToIntersection<OptionsUnion<T>>;
export {};

View File

@@ -0,0 +1,4 @@
'use strict';
"use strict";
//# sourceMappingURL=typeUtils.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"typeUtils.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;"}

View File

@@ -0,0 +1,2 @@
"use strict";
//# sourceMappingURL=typeUtils.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"typeUtils.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":""}