{"version":3,"file":"SoundSprite.mjs","sources":["../src/SoundSprite.ts"],"sourcesContent":["import { IMediaInstance } from './interfaces';\nimport { CompleteCallback, Sound } from './Sound';\n\n/** Data for adding new sound sprites. */\ninterface SoundSpriteData\n{\n    /** The start time in seconds. */\n    start: number;\n    /** The end time in seconds. */\n    end: number;\n    /** The optional speed, if not speed, uses the default speed of the parent. */\n    speed?: number;\n}\n\n// Collection of sound sprites\ntype SoundSprites = Record<string, SoundSprite>;\n\n/**\n * Object that represents a single Sound's sprite. To add sound sprites\n * use the {@link Sound#addSprites} method.\n * @example\n * import { sound } from '@pixi/sound';\n * sound.add('alias', {\n *   url: 'path/to/file.ogg',\n *   sprites: {\n *     blast: { start: 0, end: 0.2 },\n *     boom: { start: 0.3, end: 0.5 },\n *   },\n *   loaded() {\n *     sound.play('alias', 'blast');\n *   }\n * );\n *\n */\nclass SoundSprite\n{\n    /**\n     * The reference sound\n     * @readonly\n     */\n    public parent: Sound;\n\n    /**\n     * The starting location in seconds.\n     * @readonly\n     */\n    public start: number;\n\n    /**\n     * The ending location in seconds\n     * @readonly\n     */\n    public end: number;\n\n    /**\n     * The speed override where 1 is 100% speed playback.\n     * @readonly\n     */\n    public speed: number;\n\n    /**\n     * The duration of the sound in seconds.\n     * @readonly\n     */\n    public duration: number;\n\n    /**\n     * Whether to loop the sound sprite.\n     * @readonly\n     */\n    public loop: boolean;\n\n    /**\n     * @param parent - The parent sound\n     * @param options - Data associated with object.\n     */\n    constructor(parent: Sound, options: SoundSpriteData)\n    {\n        this.parent = parent;\n        Object.assign(this, options);\n        this.duration = this.end - this.start;\n\n        // eslint-disable-next-line no-console\n        console.assert(this.duration > 0, 'End time must be after start time');\n    }\n\n    /**\n     * Play the sound sprite.\n     * @param {Function} [complete] - Function call when complete\n     * @return Sound instance being played.\n     */\n    public play(complete?: CompleteCallback): IMediaInstance | Promise<IMediaInstance>\n    {\n        return this.parent.play({\n            complete,\n            speed: this.speed || this.parent.speed,\n            end: this.end,\n            start: this.start,\n            loop: this.loop\n        });\n    }\n\n    /** Destroy and don't use after this */\n    public destroy(): void\n    {\n        this.parent = null;\n    }\n}\n\nexport type { SoundSpriteData, SoundSprites };\nexport { SoundSprite };\n"],"names":[],"mappings":"AAkCA,MAAM,WACN,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAyCI,WAAA,CAAY,QAAe,OAC3B,EAAA;AACI,IAAA,IAAA,CAAK,MAAS,GAAA,MAAA,CAAA;AACd,IAAO,MAAA,CAAA,MAAA,CAAO,MAAM,OAAO,CAAA,CAAA;AAC3B,IAAK,IAAA,CAAA,QAAA,GAAW,IAAK,CAAA,GAAA,GAAM,IAAK,CAAA,KAAA,CAAA;AAGhC,IAAA,OAAA,CAAQ,MAAO,CAAA,IAAA,CAAK,QAAW,GAAA,CAAA,EAAG,mCAAmC,CAAA,CAAA;AAAA,GACzE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOO,KAAK,QACZ,EAAA;AACI,IAAO,OAAA,IAAA,CAAK,OAAO,IAAK,CAAA;AAAA,MACpB,QAAA;AAAA,MACA,KAAO,EAAA,IAAA,CAAK,KAAS,IAAA,IAAA,CAAK,MAAO,CAAA,KAAA;AAAA,MACjC,KAAK,IAAK,CAAA,GAAA;AAAA,MACV,OAAO,IAAK,CAAA,KAAA;AAAA,MACZ,MAAM,IAAK,CAAA,IAAA;AAAA,KACd,CAAA,CAAA;AAAA,GACL;AAAA;AAAA,EAGO,OACP,GAAA;AACI,IAAA,IAAA,CAAK,MAAS,GAAA,IAAA,CAAA;AAAA,GAClB;AACJ;;;;"}