UNPKG

pixi.js

Version:

<p align="center"> <a href="https://pixijs.com" target="_blank" rel="noopener noreferrer"> <img height="150" src="https://files.pixijs.download/branding/pixijs-logo-transparent-dark.svg?v=1" alt="PixiJS logo"> </a> </p> <br/> <p align="center">

90 lines (87 loc) 2.38 kB
import { Matrix } from '../../../../maths/matrix/Matrix.mjs'; import { uid } from '../../../../utils/data/uid.mjs'; "use strict"; const repetitionMap = { repeat: { addressModeU: "repeat", addressModeV: "repeat" }, "repeat-x": { addressModeU: "repeat", addressModeV: "clamp-to-edge" }, "repeat-y": { addressModeU: "clamp-to-edge", addressModeV: "repeat" }, "no-repeat": { addressModeU: "clamp-to-edge", addressModeV: "clamp-to-edge" } }; class FillPattern { constructor(texture, repetition) { /** * unique id for this fill pattern * @internal */ this.uid = uid("fillPattern"); /** * Internal tick counter to track changes in the pattern. * This is used to invalidate the pattern when the texture or transform changes. * @internal */ this._tick = 0; /** The transform matrix applied to the pattern */ this.transform = new Matrix(); this.texture = texture; this.transform.scale( 1 / texture.frame.width, 1 / texture.frame.height ); if (repetition) { texture.source.style.addressModeU = repetitionMap[repetition].addressModeU; texture.source.style.addressModeV = repetitionMap[repetition].addressModeV; } } /** * Sets the transform for the pattern * @param transform - The transform matrix to apply to the pattern. * If not provided, the pattern will use the default transform. */ setTransform(transform) { const texture = this.texture; this.transform.copyFrom(transform); this.transform.invert(); this.transform.scale( 1 / texture.frame.width, 1 / texture.frame.height ); this._tick++; } /** Internal texture used to render the gradient */ get texture() { return this._texture; } set texture(value) { if (this._texture === value) return; this._texture = value; this._tick++; } /** * Returns a unique key for this instance. * This key is used for caching. * @returns {string} Unique key for the instance */ get styleKey() { return `fill-pattern-${this.uid}-${this._tick}`; } /** Destroys the fill pattern, releasing resources. This will also destroy the internal texture. */ destroy() { this.texture.destroy(true); this.texture = null; } } export { FillPattern }; //# sourceMappingURL=FillPattern.mjs.map