{"version":3,"file":"TextMixin.mjs","sources":["../../../src/core/mixins/TextMixin.ts"],"sourcesContent":["import { AbstractText, extensions, Point, type TextString } from 'pixi.js';\nimport { type ComputedLayout } from '../types';\nimport { calculateObjectFit } from './utils/calculateObjectFit';\nimport { calculatePositionSpecifier } from './utils/calculatePositionSpecifier';\n\nconst tempScale = new Point(0, 0);\nconst mixin: Partial<AbstractText> = {\n    /**\n     * Computes the layout data for the text element\n     * @param computedLayout - The computed layout from Yoga\n     * @returns The layout data for the text element\n     */\n    computeLayoutData(computedLayout: ComputedLayout) {\n        const style = this._style!;\n\n        tempScale.copyFrom(this.scale);\n        this.scale = 1;\n\n        if (style.wordWrap) {\n            // we want to scale down the text first then wrap it\n            style.wordWrapWidth = computedLayout.width;\n        }\n\n        let bounds = this.getLocalBounds();\n\n        const objectFit = this.layout!.style.objectFit || 'scale-down';\n        const { offsetScaleX, offsetScaleY } = calculateObjectFit(objectFit, computedLayout, bounds);\n\n        if (style.wordWrap) {\n            // we now need to recalculate the wordWrapWidth based on the new scale\n            style.wordWrapWidth = computedLayout.width / Math.min(1, Math.max(offsetScaleX, offsetScaleY));\n        }\n\n        // recalculate the bounds after the wordWrapWidth has been set\n        bounds = this.getLocalBounds();\n\n        // scale the current bounds by the offset scale\n        const scaledBounds = {\n            width: bounds.width * offsetScaleX,\n            height: bounds.height * offsetScaleY,\n        };\n        let { x: offsetX, y: offsetY } = calculatePositionSpecifier(\n            this.layout!.style.objectPosition,\n            computedLayout,\n            scaledBounds,\n        );\n\n        // offset the anchor point\n        offsetX += bounds.width * offsetScaleX * this.anchor._x;\n        offsetY += bounds.height * offsetScaleY * this.anchor._y;\n\n        const applySizeDirectly = this.layout!.style.applySizeDirectly;\n\n        // If applySizeDirectly is true, set the this's width and height directly\n        if (applySizeDirectly === true) {\n            this.width = bounds.width * offsetScaleX;\n            this.height = bounds.height * offsetScaleY;\n        }\n\n        // Reset the scale to the original value\n        this.scale.copyFrom(tempScale);\n\n        return {\n            x: computedLayout.left,\n            y: computedLayout.top,\n            offsetX,\n            offsetY,\n            scaleX: offsetScaleX,\n            scaleY: offsetScaleY,\n        };\n    },\n} as AbstractText;\n\nextensions.mixin(AbstractText, mixin);\n\nconst text = Object.getOwnPropertyDescriptor(AbstractText.prototype, 'text')!;\n\n// eslint-disable-next-line accessor-pairs\nObject.defineProperty(AbstractText.prototype, 'text', {\n    ...text,\n    set(textString: TextString) {\n        const currentText = text.get!.call(this);\n\n        text.set!.call(this, textString);\n\n        if (currentText === textString) return;\n        this.layout?.forceUpdate();\n    },\n});\n"],"names":[],"mappings":";;;AAKA,MAAM,YAAY,IAAI,MAAM,GAAG,CAAC;AAChC,MAAM,QAA+B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMjC,kBAAkB,gBAAgC;AAC9C,UAAM,QAAQ,KAAK;AAET,cAAA,SAAS,KAAK,KAAK;AAC7B,SAAK,QAAQ;AAEb,QAAI,MAAM,UAAU;AAEhB,YAAM,gBAAgB,eAAe;AAAA,IAAA;AAGrC,QAAA,SAAS,KAAK,eAAe;AAEjC,UAAM,YAAY,KAAK,OAAQ,MAAM,aAAa;AAClD,UAAM,EAAE,cAAc,iBAAiB,mBAAmB,WAAW,gBAAgB,MAAM;AAE3F,QAAI,MAAM,UAAU;AAEV,YAAA,gBAAgB,eAAe,QAAQ,KAAK,IAAI,GAAG,KAAK,IAAI,cAAc,YAAY,CAAC;AAAA,IAAA;AAIjG,aAAS,KAAK,eAAe;AAG7B,UAAM,eAAe;AAAA,MACjB,OAAO,OAAO,QAAQ;AAAA,MACtB,QAAQ,OAAO,SAAS;AAAA,IAC5B;AACA,QAAI,EAAE,GAAG,SAAS,GAAG,QAAY,IAAA;AAAA,MAC7B,KAAK,OAAQ,MAAM;AAAA,MACnB;AAAA,MACA;AAAA,IACJ;AAGA,eAAW,OAAO,QAAQ,eAAe,KAAK,OAAO;AACrD,eAAW,OAAO,SAAS,eAAe,KAAK,OAAO;AAEhD,UAAA,oBAAoB,KAAK,OA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