'use strict';

var elements_TransitionElement = require('../elements/TransitionElement.cjs');
var utils_transitionRenderer = require('../utils/transition-renderer.cjs');

/**
 * 转场效果类 - 使用 gl-transitions
 */
/**
 * 转场效果类
 */
class Transition {
  constructor(config = {}) {
    this.track = config.track;
    this.name = config.name || config.type || 'fade'; // gl-transitions 名称
    this.duration = config.duration || 0.5; // 转场时长（秒）
    this.startTime = config.startTime; // 转场开始时间
    this.fromScene = config.fromScene;
    this.toScene = config.toScene;
    this.fromSceneIndex = config.fromSceneIndex;
    this.toSceneIndex = config.toSceneIndex;
    this.easing = config.easing || 'easeInOutQuad';
    this.params = config.params; // gl-transitions 参数
    // 如果this.name是'random'，则随机选择一个过渡效果
    if (this.name === 'random') {
      const randomIndex = Math.floor(Math.random() * utils_transitionRenderer.AllTransitions.length);
      this.name = utils_transitionRenderer.AllTransitions[randomIndex];
    }
  }

  /**
   * 应用转场效果 - 创建 TransitionElement 并返回
   * @param {VideoMaker} fromSceneComposition - 源场景合成
   * @param {VideoMaker} toSceneComposition - 目标场景合成
   * @param {number} transitionStartTime - 转场开始时间
   * @param {number} width - 宽度
   * @param {number} height - 高度
   * @returns {TransitionElement} 转场元素
   */
  createTransitionElement(fromSceneComposition, toSceneComposition, transitionStartTime, width, height) {
    // 创建转场元素
    const transitionElement = new elements_TransitionElement.TransitionElement({
      x: width / 2,
      y: height / 2,
      width: width,
      height: height,
      anchor: [0.5, 0.5],
      fromComposition: fromSceneComposition,
      toComposition: toSceneComposition,
      transitionConfig: {
        name: this.name,
        duration: this.duration,
        easing: this.easing,
        params: this.params,
      },
      startTime: transitionStartTime,
      duration: this.duration,
    });

    return transitionElement;
  }
}

exports.Transition = Transition;
//# sourceMappingURL=Transition.cjs.map
