{"version":3,"file":"Slot.mjs","sources":["../../src/core/Slot.ts"],"sourcesContent":["import { Color, ISlot } from '@pixi-spine/base';\n\nimport { Attachment, VertexAttachment } from './attachments/Attachment';\nimport type { Bone } from './Bone';\nimport type { SlotData } from './SlotData';\nimport type { Skeleton } from './Skeleton';\n\n/** Stores a slot's current pose. Slots organize attachments for {@link Skeleton#drawOrder} purposes and provide a place to store\n * state for an attachment. State cannot be stored in an attachment itself because attachments are stateless and may be shared\n * across multiple skeletons.\n * @public\n * */\nexport class Slot implements ISlot {\n    // this is canon\n    blendMode: number;\n    /** The slot's setup pose data. */\n    data: SlotData;\n\n    /** The bone this slot belongs to. */\n    bone: Bone;\n\n    /** The color used to tint the slot's attachment. If {@link #getDarkColor()} is set, this is used as the light color for two\n     * color tinting. */\n    color: Color;\n\n    /** The dark color used to tint the slot's attachment for two color tinting, or null if two color tinting is not used. The dark\n     * color's alpha is not used. */\n    darkColor: Color | null = null;\n\n    attachment: Attachment | null = null;\n\n    attachmentState = 0;\n\n    /** The index of the texture region to display when the slot's attachment has a {@link Sequence}. -1 represents the\n     * {@link Sequence#getSetupIndex()}. */\n    sequenceIndex = -1;\n\n    /** Values to deform the slot's attachment. For an unweighted mesh, the entries are local positions for each vertex. For a\n     * weighted mesh, the entries are an offset for each vertex which will be added to the mesh's local vertex positions.\n     *\n     * See {@link VertexAttachment#computeWorldVertices()} and {@link DeformTimeline}. */\n    deform = new Array<number>();\n\n    constructor(data: SlotData, bone: Bone) {\n        if (!data) throw new Error('data cannot be null.');\n        if (!bone) throw new Error('bone cannot be null.');\n        this.data = data;\n        this.bone = bone;\n        this.color = new Color();\n        this.darkColor = !data.darkColor ? null : new Color();\n        this.setToSetupPose();\n\n        this.blendMode = this.data.blendMode;\n    }\n\n    /** The skeleton this slot belongs to. */\n    getSkeleton(): Skeleton {\n        return this.bone.skeleton;\n    }\n\n    /** The current attachment for the slot, or null if the slot has no attachment. */\n    getAttachment(): Attachment | null {\n        return this.attachment;\n    }\n\n    /** Sets the slot's attachment and, if the attachment changed, resets {@link #sequenceIndex} and clears the {@link #deform}.\n     * The deform is not cleared if the old attachment has the same {@link VertexAttachment#getTimelineAttachment()} as the\n     * specified attachment. */\n    setAttachment(attachment: Attachment | null) {\n        if (this.attachment == attachment) return;\n        if (\n            !(attachment instanceof VertexAttachment) ||\n            !(this.attachment instanceof VertexAttachment) ||\n            (<VertexAttachment>attachment).timelineAttachment != (<VertexAttachment>this.attachment).timelineAttachment\n        ) {\n            this.deform.length = 0;\n        }\n        this.attachment = attachment;\n        this.sequenceIndex = -1;\n    }\n\n    /** Sets this slot to the setup pose. */\n    setToSetupPose() {\n        this.color.setFromColor(this.data.color);\n        if (this.darkColor) this.darkColor.setFromColor(this.data.darkColor);\n        if (!this.data.attachmentName) this.attachment = null;\n        else {\n            this.attachment = null;\n            this.setAttachment(this.bone.skeleton.getAttachment(this.data.index, this.data.attachmentName));\n        }\n    }\n}\n"],"names":[],"mappings":";;;AAYO,MAAM,IAAsB,CAAA;AAAA,EA+B/B,WAAA,CAAY,MAAgB,IAAY,EAAA;AAhBxC;AAAA;AAAA,IAA0B,IAAA,CAAA,SAAA,GAAA,IAAA,CAAA;AAE1B,IAAgC,IAAA,CAAA,UAAA,GAAA,IAAA,CAAA;AAEhC,IAAkB,IAAA,CAAA,eAAA,GAAA,CAAA,CAAA;AAIlB;AAAA;AAAA,IAAgB,IAAA,CAAA,aAAA,GAAA,CAAA,CAAA,CAAA;AAMhB;AAAA;AAAA;AAAA;AAAA,IAAA,IAAA,CAAA,MAAA,GAAS,IAAI,KAAc,EAAA,CAAA;AAGvB,IAAA,IAAI,CAAC,IAAA;AAAM,MAAM,MAAA,IAAI,MAAM,sBAAsB,CAAA,CAAA;AACjD,IAAA,IAAI,CAAC,IAAA;AAAM,MAAM,MAAA,IAAI,MAAM,sBAAsB,CAAA,CAAA;AACjD,IAAA,IAAA,CAAK,IAAO,GAAA,IAAA,CAAA;AACZ,IAAA,IAAA,CAAK,IAAO,GAAA,I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