UNPKG

casparcg-state

Version:

Node.js Javascript/Typescript library for keeping and resolving a given state of CasparCG into commands for casparcg-connection.

155 lines 5.7 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Transition = exports.TransitionObject = void 0; const enums_1 = require("casparcg-connection/dist/enums"); const _ = require("underscore"); const util_1 = require("./util"); class TransitionObject { /** */ constructor(value, options) { this._transition = true; if (!_.isUndefined(value)) { this._value = value; } if (options) { if (options.inTransition) this.inTransition = options.inTransition; if (options.changeTransition) this.changeTransition = options.changeTransition; if (options.outTransition) this.outTransition = options.outTransition; } } /** */ valueOf() { return this._value ?? 'Transition Object'; } /** */ toString() { if (this._value) return this._value.toString(); return ''; } } exports.TransitionObject = TransitionObject; class Transition { constructor(typeOrTransition, durationOrMaskFile, easingOrDelay, directionOrOverlayFile, audioFadeStart, audioFadeDuration) { this.type = enums_1.TransitionType.Mix; this.duration = 0; this.easing = enums_1.TransitionTween.LINEAR; this.direction = enums_1.Direction.Right; this.maskFile = ''; this.delay = 0; this.overlayFile = ''; this.audioFadeStart = 0; this.audioFadeDuration = 0; this.customOptions = undefined; let type; if (_.isObject(typeOrTransition)) { const t = typeOrTransition; type = t.type; const isSting = (type + '').match(/sting/i); durationOrMaskFile = isSting ? t.maskFile : t.duration; easingOrDelay = isSting ? t.delay : t.easing; directionOrOverlayFile = isSting ? t.overlayFile : t.direction; audioFadeStart = isSting ? t.audioFadeStart : undefined; audioFadeDuration = isSting ? t.audioFadeDuration : undefined; this.customOptions = t.customOptions; } else { type = typeOrTransition; } // @todo: for all: string literal if (type) { this.type = type; } if ((this.type + '').match(/sting/i)) { if (durationOrMaskFile) { this.maskFile = durationOrMaskFile; } if (easingOrDelay) { this.delay = easingOrDelay; } if (directionOrOverlayFile) { this.overlayFile = directionOrOverlayFile; } if (audioFadeStart) { this.audioFadeStart = audioFadeStart; } if (audioFadeDuration) { this.audioFadeDuration = audioFadeDuration; } } else { if (durationOrMaskFile) { this.duration = durationOrMaskFile; } if (easingOrDelay) { this.easing = easingOrDelay; } if (directionOrOverlayFile) { this.direction = directionOrOverlayFile; } } } getOptions(fps) { if ((this.type + '').match(/sting/i)) { const stingProperties = { maskFile: this.maskFile, }; if (this.delay) stingProperties.delay = this.time2Frames(this.delay, fps); if (this.audioFadeStart) { stingProperties.audioFadeStart = this.time2Frames(this.audioFadeStart, fps); } if (this.audioFadeDuration) { stingProperties.audioFadeDuration = this.time2Frames(this.audioFadeDuration, fps); } return { transition: { transitionType: enums_1.TransitionType.Sting, duration: 0, stingProperties, }, }; } else { const o = { transitionType: this.type, duration: this.time2Frames(this.duration || 0, fps), tween: this.easing, direction: this.direction, }; // if (this.customOptions) o['customOptions'] = this.customOptions return { transition: o }; } } getString(fps) { if ((this.type + '').match(/sting/i)) { if (this.audioFadeStart || this.audioFadeDuration) { let str = 'STING ('; if (this.maskFile) str += `MASK="${this.maskFile}" `; if (this.overlayFile) str += `OVERLAY="${this.overlayFile}" `; if (this.delay) str += `TRIGGER_POINT="${this.time2Frames(this.delay, fps)}" `; if (this.audioFadeStart) str += `AUDIO_FADE_START="${this.time2Frames(this.audioFadeStart, fps)}" `; if (this.audioFadeDuration) str += `AUDIO_FADE_DURATION="${this.time2Frames(this.audioFadeDuration, fps)}" `; str = str.substr(0, str.length - 1) + ')'; return str; } return ['STING', this.maskFile, this.time2Frames(this.delay || 0, fps), this.overlayFile].join(' '); } else { return [this.type, this.time2Frames(this.duration || 0, fps), this.easing, this.direction].join(' '); } } time2Frames(time, fps) { return (0, util_1.time2Frames)(time, fps); } } exports.Transition = Transition; //# sourceMappingURL=transitionObject.js.map