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">

1 lines 5.46 kB
{"version":3,"file":"FillPattern.mjs","sources":["../../../../../src/scene/graphics/shared/fill/FillPattern.ts"],"sourcesContent":["import { Matrix } from '../../../../maths/matrix/Matrix';\nimport { uid } from '../../../../utils/data/uid';\n\nimport type { WRAP_MODE } from '../../../../rendering/renderers/shared/texture/const';\nimport type { Texture } from '../../../../rendering/renderers/shared/texture/Texture';\n\n/**\n * Defines the repetition modes for fill patterns.\n *\n * - `repeat`: The pattern repeats in both directions.\n * - `repeat-x`: The pattern repeats horizontally only.\n * - `repeat-y`: The pattern repeats vertically only.\n * - `no-repeat`: The pattern does not repeat.\n * @category scene\n * @standard\n */\nexport type PatternRepetition = 'repeat' | 'repeat-x' | 'repeat-y' | 'no-repeat';\n\nconst repetitionMap = {\n repeat: {\n addressModeU: 'repeat',\n addressModeV: 'repeat',\n },\n 'repeat-x': {\n addressModeU: 'repeat',\n addressModeV: 'clamp-to-edge',\n },\n 'repeat-y': {\n addressModeU: 'clamp-to-edge',\n addressModeV: 'repeat',\n },\n 'no-repeat': {\n addressModeU: 'clamp-to-edge',\n addressModeV: 'clamp-to-edge',\n },\n};\n\n/**\n * A class that represents a fill pattern for use in Text and Graphics fills.\n * It allows for textures to be used as patterns, with optional repetition modes.\n * @category scene\n * @standard\n * @example\n * const txt = await Assets.load('https://pixijs.com/assets/bg_scene_rotate.jpg');\n * const pat = new FillPattern(txt, 'repeat');\n *\n * const textPattern = new Text({\n * text: 'PixiJS',\n * style: {\n * fontSize: 36,\n * fill: 0xffffff,\n * stroke: { fill: pat, width: 10 },\n * },\n * });\n *\n * textPattern.y = (textGradient.height);\n */\nexport class FillPattern implements CanvasPattern\n{\n /**\n * unique id for this fill pattern\n * @internal\n */\n public readonly uid: number = uid('fillPattern');\n /** Internal texture used to render the gradient */\n public texture: Texture;\n /** The transform matrix applied to the pattern */\n public transform = new Matrix();\n\n private _styleKey: string | null = null;\n\n constructor(texture: Texture, repetition?: PatternRepetition)\n {\n this.texture = texture;\n\n this.transform.scale(\n 1 / texture.frame.width,\n 1 / texture.frame.height\n );\n\n if (repetition)\n {\n texture.source.style.addressModeU = repetitionMap[repetition].addressModeU as WRAP_MODE;\n texture.source.style.addressModeV = repetitionMap[repetition].addressModeV as WRAP_MODE;\n }\n }\n\n /**\n * Sets the transform for the pattern\n * @param transform - The transform matrix to apply to the pattern.\n * If not provided, the pattern will use the default transform.\n */\n public setTransform(transform?: Matrix): void\n {\n const texture = this.texture;\n\n this.transform.copyFrom(transform);\n this.transform.invert();\n // transform.scale\n this.transform.scale(\n 1 / texture.frame.width,\n 1 / texture.frame.height\n );\n\n this._styleKey = null;\n }\n\n /**\n * Gets a unique key representing the current state of the pattern.\n * Used internally for caching.\n * @returns Unique string key\n */\n public get styleKey(): string\n {\n if (this._styleKey) return this._styleKey;\n\n this._styleKey = `fill-pattern-${this.uid}-${this.texture.uid}-${this.transform.toArray().join('-')}`;\n\n return this._styleKey;\n }\n}\n"],"names":[],"mappings":";;;;AAkBA,MAAM,aAAgB,GAAA;AAAA,EAClB,MAAQ,EAAA;AAAA,IACJ,YAAc,EAAA,QAAA;AAAA,IACd,YAAc,EAAA,QAAA;AAAA,GAClB;AAAA,EACA,UAAY,EAAA;AAAA,IACR,YAAc,EAAA,QAAA;AAAA,IACd,YAAc,EAAA,eAAA;AAAA,GAClB;AAAA,EACA,UAAY,EAAA;AAAA,IACR,YAAc,EAAA,eAAA;AAAA,IACd,YAAc,EAAA,QAAA;AAAA,GAClB;AAAA,EACA,WAAa,EAAA;AAAA,IACT,YAAc,EAAA,eAAA;AAAA,IACd,YAAc,EAAA,eAAA;AAAA,GAClB;AACJ,CAAA,CAAA;AAsBO,MAAM,WACb,CAAA;AAAA,EAaI,WAAA,CAAY,SAAkB,UAC9B,E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