import { u as utils, A as AudioModel } from "./install-editor.js";
import { l as lodash } from "./index.js";
import { P as Promise$1 } from "./base-element.js";
import "vue";
import "./watermark.js";
import "./v4.js";
import "./defaults.js";
import "./index15.js";
import "./asyncToGenerator.js";
import "./pixel-helper.js";
import "./index16.js";
import "./uniq.js";
import "./video.js";
import "./get-lines.js";
import "./gif-apng.worker.js";
import "./vue-slider-component.umd.min.js";
var methods = {
  addAudio(url, options) {
    const data = lodash.exports.assign({
      type: "audio",
      volume: 1,
      width: 0,
      height: 0,
      top: -10,
      left: -10,
      url
    }, options);
    return this.addElement(data);
  },
  seekAudio(element, time) {
    if (element && element.type === "audio") {
      element.$currentTime = time;
    }
  },
  async playAudio(element, time) {
    if (!element || element.type !== "audio")
      return;
    await this.$nextTick();
    time && this.seekAudio(element, time);
    this.$set(element, "$playing", true);
  },
  pauseAudio(element, time) {
    if (!element || element.type !== "audio")
      return;
    this.$set(element, "$playing", false);
    time && this.seekAudio(element, time);
  },
  stopAudio(element) {
    this.pauseAudio(element, 0);
  }
};
var template = `<audio
    ref='audio'
    crossorigin
    :src="originUrl || null"
    style="width: 0; height: 0; opacity: 0; display: none;"
/>
`;
var AudioElement = {
  name: "audio-element",
  template,
  props: ["global", "model", "options", "editor"],
  data() {
    return {
      audio: null
    };
  },
  computed: {
    originUrl() {
      const { model, options } = this;
      return utils.getComputedUrl(model.url, options.fitCrossOrigin);
    }
  },
  watch: {
    "model.$currentTime"(time) {
      if (this.audio) {
        this.audio.currentTime = (time || 0) / 1e3;
      }
    },
    "model.volume"(volume) {
      if (this.audio) {
        this.audio.volume = volume;
      }
    },
    "model.$playing"(playing) {
      if (!this.audio)
        return;
      if (playing) {
        this.audio.volume = this.model.volume;
        this.audio.play();
      } else {
        this.audio.pause();
      }
    }
  },
  methods: {
    checkLoad() {
      const { model, originUrl } = this;
      model.$loaded = false;
      return Promise$1.try(() => {
        return utils.loadAudio(originUrl, this.options.fitCrossOrigin);
      }).then(() => {
        model.$loaded = true;
        this.$events.$emit("element.loaded", model);
      }).catch((ex) => {
        model.$loaded = true;
        this.$events.$emit("element.loadError", ex, model);
      });
    }
  },
  mounted() {
    this.audio = this.$refs.audio;
    this.$nextTick(this.checkLoad);
  }
};
var index = {
  model: AudioModel,
  methods,
  layoutComponent: AudioElement
};
export { index as default };
