"use strict";
const common_vendor = require("../../../../../common/vendor.js");
const block0 = {};
const aliyunVideo = () => "../aliyun-video/aliyun-video.js";
const wxChannelVideo = () => "../channel-video/channel-video.js";
const node = () => Promise.resolve().then(() => RDovd29yay9aaGlZaS91bmktYXBwL3VuaS1hcHAtZGVtby91bmlfbW9kdWxlcy9tcC1odG1sL2NvbXBvbmVudHMvbXAtaHRtbC9ub2RlL25vZGUudnVl);
const _sfc_main = {
  name: "node",
  options: {
    virtualHost: true
  },
  data() {
    return {
      ctrl: {},
      nodes: [],
      isiOS: common_vendor.index.getDeviceInfo().system.includes("iOS")
    };
  },
  props: {
    name: String,
    attrs: {
      type: Object,
      default() {
        return {};
      }
    },
    childs: Array,
    opts: Array,
    token: String
  },
  watch: {
    childs: {
      handler(nodes) {
        while (this.nodes.length > nodes.length) {
          nodes.push({});
        }
        this.nodes = nodes;
      },
      immediate: true
    }
  },
  components: {
    aliyunVideo,
    wxChannelVideo,
    node
  },
  mounted() {
    this.$nextTick(() => {
      for (this.root = this.$parent; this.root.$options.name !== "mp-html"; this.root = this.root.$parent)
        ;
    });
  },
  beforeDestroy() {
  },
  methods: {
    toJSON() {
      return this;
    },
    /**
     * @description 播放视频事件
     * @param {Event} e
     */
    play(e) {
      const i = e.currentTarget.dataset.i;
      const node2 = this.childs[i];
      this.root.$emit("play", {
        source: node2.name,
        attrs: {
          ...node2.attrs,
          src: node2.src[this.ctrl[i] || 0]
        }
      });
      if (this.root.pauseVideo) {
        let flag = false;
        const id = e.target.id;
        for (let i2 = this.root._videos.length; i2--; ) {
          if (this.root._videos[i2].id === id) {
            flag = true;
          } else {
            this.root._videos[i2].pause();
          }
        }
        if (!flag) {
          const ctx = common_vendor.index.createVideoContext(
            id,
            this
          );
          ctx.id = id;
          if (this.root.playbackRate) {
            ctx.playbackRate(this.root.playbackRate);
          }
          this.root._videos.push(ctx);
        }
      }
    },
    /**
     * @description 图片点击事件
     * @param {Event} e
     */
    imgTap(e) {
      const node2 = this.childs[e.currentTarget.dataset.i];
      if (node2.a) {
        this.linkTap(node2.a);
        return;
      }
      if (node2.attrs.ignore)
        return;
      this.root.$emit("imgtap", node2.attrs);
      if (this.root.previewImg) {
        common_vendor.index.previewImage({
          showmenu: this.root.showImgMenu,
          current: parseInt(node2.attrs.i),
          urls: this.root.imgList
        });
      }
    },
    /**
     * @description 图片长按
     */
    imgLongTap(e) {
    },
    /**
     * @description 图片加载完成事件
     * @param {Event} e
     */
    imgLoad(e) {
      const i = e.currentTarget.dataset.i;
      if (!this.childs[i].w) {
        this.$set(this.ctrl, i, e.detail.width);
      } else if (this.opts[1] && !this.ctrl[i] || this.ctrl[i] === -1) {
        this.$set(this.ctrl, i, 1);
      }
      this.checkReady();
    },
    /**
     * @description 检查是否所有图片加载完毕
     */
    checkReady() {
      if (this.root && !this.root.lazyLoad) {
        this.root._unloadimgs -= 1;
        if (!this.root._unloadimgs) {
          setTimeout(() => {
            this.root.getRect().then((rect) => {
              this.root.$emit("ready", rect);
            }).catch(() => {
              this.root.$emit("ready", {});
            });
          }, 350);
        }
      }
    },
    /**
     * @description 链接点击事件
     * @param {Event} e
     */
    linkTap(e) {
      const node2 = e.currentTarget ? this.childs[e.currentTarget.dataset.i] : {};
      const attrs = node2.attrs || e;
      const href = attrs.href;
      this.root.$emit("linktap", Object.assign({
        innerText: this.root.getText(node2.children || [])
        // 链接内的文本内容
      }, attrs));
      if (href) {
        if (href[0] === "#") {
          this.root.navigateTo(href.substring(1)).catch(() => {
          });
        } else if (href.split("?")[0].includes("://")) {
          if (this.root.copyLink) {
            common_vendor.index.setClipboardData({
              data: href,
              success: () => common_vendor.index.showToast({
                title: "链接已复制"
              })
            });
          }
        } else {
          common_vendor.index.navigateTo({
            url: href,
            fail() {
              common_vendor.index.switchTab({
                url: href,
                fail() {
                }
              });
            }
          });
        }
      }
    },
    /**
     * @description 错误事件
     * @param {Event} e
     */
    mediaError(e) {
      const i = e.currentTarget.dataset.i;
      const node2 = this.childs[i];
      if (node2.name === "video" || node2.name === "audio") {
        let index = (this.ctrl[i] || 0) + 1;
        if (index > node2.src.length) {
          index = 0;
        }
        if (index < node2.src.length) {
          this.$set(this.ctrl, i, index);
          return;
        }
      } else if (node2.name === "img") {
        if (this.opts[2]) {
          this.$set(this.ctrl, i, -1);
        }
        this.checkReady();
      }
      if (this.root) {
        this.root.$emit("error", {
          source: node2.name,
          attrs: node2.attrs,
          errMsg: e.detail.errMsg
        });
      }
    },
    urlWithToken(url) {
      if (this.root) {
        const hasParams = url.includes("?");
        return `${url}${this.root.token ? `${hasParams ? "&" : "?"}token=${this.root.token}` : ""}`;
      } else {
        return url;
      }
    }
  }
};
if (!Array) {
  const _component_node = common_vendor.resolveComponent("node");
  const _component_wx_channel_video = common_vendor.resolveComponent("wx-channel-video");
  const _component_aliyun_video = common_vendor.resolveComponent("aliyun-video");
  (_component_node + _component_wx_channel_video + _component_aliyun_video)();
}
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  return {
    a: common_vendor.f($data.nodes, (n, i, i0) => {
      return common_vendor.e({
        a: n.name === "img" && !n.t && ($props.opts[1] && !$data.ctrl[i] || $data.ctrl[i] < 0)
      }, n.name === "img" && !n.t && ($props.opts[1] && !$data.ctrl[i] || $data.ctrl[i] < 0) ? {
        b: common_vendor.s(n.attrs.style),
        c: $data.ctrl[i] < 0 ? $props.opts[2] : $props.opts[1]
      } : {}, {
        d: n.name === "img" && n.t
      }, n.name === "img" && n.t ? {
        e: common_vendor.s("display:" + n.t),
        f: [{
          attrs: {
            style: n.attrs.style || "",
            src: n.attrs.src
          },
          name: "img"
        }],
        g: i,
        h: common_vendor.o((...args) => $options.imgTap && $options.imgTap(...args), i)
      } : n.name === "img" ? {
        j: n.attrs.id,
        k: common_vendor.n("_img " + n.attrs.class),
        l: common_vendor.s(($data.ctrl[i] === -1 ? "display:none;" : "") + "width:" + ($data.ctrl[i] || 1) + "px;height:1px;" + n.attrs.style),
        m: n.attrs.src,
        n: !n.h ? "widthFix" : !n.w ? "heightFix" : n.m || "scaleToFill",
        o: $props.opts[0],
        p: n.webp,
        q: $props.opts[3] && !n.attrs.ignore,
        r: !$props.opts[3] || n.attrs.ignore,
        s: i,
        t: common_vendor.o((...args) => $options.imgLoad && $options.imgLoad(...args), i),
        v: common_vendor.o((...args) => $options.mediaError && $options.mediaError(...args), i),
        w: common_vendor.o((...args) => $options.imgTap && $options.imgTap(...args), i),
        x: common_vendor.o((...args) => $options.imgLongTap && $options.imgLongTap(...args), i)
      } : n.text ? {
        z: common_vendor.t(n.text),
        A: $props.opts[4] == "force" && $data.isiOS
      } : n.name === "br" ? {
        C: common_vendor.t("\n")
      } : n.name === "a" ? {
        E: "2fe0f0de-0-" + i0,
        F: common_vendor.p({
          name: "span",
          childs: n.children,
          opts: $props.opts
        }),
        G: n.attrs.id,
        H: common_vendor.n((n.attrs.href ? "_a " : "") + n.attrs.class),
        I: common_vendor.s("display:inline;" + n.attrs.style),
        J: i,
        K: common_vendor.o((...args) => $options.linkTap && $options.linkTap(...args), i)
      } : n.name === "video" ? {
        M: n.attrs.id,
        N: common_vendor.n(n.attrs.class),
        O: common_vendor.s(n.attrs.style),
        P: n.attrs.autoplay,
        Q: n.attrs.controls,
        R: n.attrs.loop,
        S: n.attrs.muted,
        T: n.attrs["object-fit"],
        U: n.attrs.poster,
        V: $options.urlWithToken(n.src[$data.ctrl[i] || 0]),
        W: i,
        X: common_vendor.o((...args) => $options.play && $options.play(...args), i),
        Y: common_vendor.o((...args) => $options.mediaError && $options.mediaError(...args), i)
      } : n.name === "channel-video" ? {
        aa: "2fe0f0de-1-" + i0,
        ab: common_vendor.p({
          ["feed-id"]: n.attrs["data-feed-id"],
          ["finder-user-name"]: n.attrs["data-finder-user-name"],
          src: n.attrs["data-url"]
        })
      } : n.name === "aliyun-video" ? {
        ad: common_vendor.n(n.attrs.class),
        ae: common_vendor.s(n.attrs.style),
        af: i,
        ag: common_vendor.o($options.play, i),
        ah: common_vendor.o($options.mediaError, i),
        ai: "2fe0f0de-2-" + i0,
        aj: common_vendor.p({
          ["video-id"]: n.attrs["data-id"],
          autoplay: n.attrs.autoplay,
          controls: n.attrs.controls,
          loop: n.attrs.loop,
          muted: n.attrs.muted,
          ["object-fit"]: n.attrs["object-fit"],
          poster: n.attrs.poster
        })
      } : n.name === "audio" ? {
        al: n.attrs.id,
        am: common_vendor.n(n.attrs.class),
        an: common_vendor.s(n.attrs.style),
        ao: n.attrs.author,
        ap: n.attrs.controls,
        aq: n.attrs.loop,
        ar: n.attrs.name,
        as: n.attrs.poster,
        at: $options.urlWithToken(n.src[$data.ctrl[i] || 0]),
        av: i,
        aw: common_vendor.o((...args) => $options.play && $options.play(...args), i),
        ax: common_vendor.o((...args) => $options.mediaError && $options.mediaError(...args), i)
      } : n.name === "table" && n.c || n.name === "li" ? common_vendor.e({
        az: n.name === "li"
      }, n.name === "li" ? {
        aA: "2fe0f0de-3-" + i0,
        aB: common_vendor.p({
          childs: n.children,
          opts: $props.opts
        })
      } : {
        aC: common_vendor.f(n.children, (tbody, x, i1) => {
          return common_vendor.e({
            a: tbody.name === "td" || tbody.name === "th"
          }, tbody.name === "td" || tbody.name === "th" ? {
            b: "2fe0f0de-4-" + i0 + "-" + i1,
            c: common_vendor.p({
              childs: tbody.children,
              opts: $props.opts
            })
          } : {
            d: common_vendor.f(tbody.children, (tr, y, i2) => {
              return common_vendor.e({
                a: tr.name === "td" || tr.name === "th"
              }, tr.name === "td" || tr.name === "th" ? {
                b: "2fe0f0de-5-" + i0 + "-" + i1 + "-" + i2,
                c: common_vendor.p({
                  childs: tr.children,
                  opts: $props.opts
                }),
                d: common_vendor.n("_" + tr.name + " " + tr.attrs.class),
                e: common_vendor.s(tr.attrs.style)
              } : {
                f: common_vendor.f(tr.children, (td, z, i3) => {
                  return {
                    a: "2fe0f0de-6-" + i0 + "-" + i1 + "-" + i2 + "-" + i3,
                    b: common_vendor.p({
                      childs: td.children,
                      opts: $props.opts
                    }),
                    c: z,
                    d: common_vendor.n("_" + td.name + " " + td.attrs.class),
                    e: common_vendor.s(td.attrs.style)
                  };
                }),
                g: common_vendor.n("_" + tr.name + " " + tr.attrs.class),
                h: common_vendor.s(tr.attrs.style)
              }, {
                i: y
              });
            })
          }, {
            e: x,
            f: common_vendor.n("_" + tbody.name + " " + tbody.attrs.class),
            g: common_vendor.s(tbody.attrs.style)
          });
        })
      }, {
        aD: n.attrs.id,
        aE: common_vendor.n("_" + n.name + " " + n.attrs.class),
        aF: common_vendor.s(n.attrs.style)
      }) : n.name == "aliyun-video" ? {
        aH: common_vendor.n(n.attrs.class),
        aI: common_vendor.s(n.attrs.style),
        aJ: i,
        aK: "2fe0f0de-7-" + i0,
        aL: common_vendor.p({
          ["video-id"]: n.attrs["data-id"],
          mode: $props.opts[5],
          src: n.attrs.src,
          title: n.attrs.title,
          desc: n.attrs.desc,
          url: n.attrs.url,
          color: n.attrs.color,
          bgcolor: n.attrs.bgcolor,
          border: n.attrs.border,
          name: n.attrs.name
        })
      } : n.name == "channel-video" ? {} : !n.c ? {
        aO: n.attrs.id,
        aP: common_vendor.s("display:inline;" + n.f),
        aQ: $props.opts[4],
        aR: $props.opts[4],
        aS: [n]
      } : n.c === 2 ? {
        aU: common_vendor.f(n.children, (n2, j, i1) => {
          return {
            a: j,
            b: common_vendor.s(n2.f),
            c: "2fe0f0de-8-" + i0 + "-" + i1,
            d: common_vendor.p({
              name: n2.name,
              attrs: n2.attrs,
              childs: n2.children,
              opts: $props.opts
            })
          };
        }),
        aV: n.attrs.id,
        aW: common_vendor.n("_block _" + n.name + " " + n.attrs.class),
        aX: common_vendor.s(n.f + ";" + n.attrs.style)
      } : {
        aY: common_vendor.s(n.f),
        aZ: "2fe0f0de-9-" + i0,
        ba: common_vendor.p({
          name: n.name,
          attrs: n.attrs,
          childs: n.children,
          opts: $props.opts
        })
      }, {
        i: n.name === "img",
        y: n.text,
        B: n.name === "br",
        D: n.name === "a",
        L: n.name === "video",
        Z: n.name === "channel-video",
        ac: n.name === "aliyun-video",
        ak: n.name === "audio",
        ay: n.name === "table" && n.c || n.name === "li",
        aG: n.name == "aliyun-video",
        aM: n.name == "channel-video",
        aN: !n.c,
        aT: n.c === 2,
        bb: i
      });
    }),
    b: $props.attrs.id,
    c: common_vendor.n("_block _" + $props.name + " " + $props.attrs.class),
    d: common_vendor.s($props.attrs.style)
  };
}
if (typeof block0 === "function")
  block0(_sfc_main);
const Component = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render]]);
wx.createComponent(Component);
const RDovd29yay9aaGlZaS91bmktYXBwL3VuaS1hcHAtZGVtby91bmlfbW9kdWxlcy9tcC1odG1sL2NvbXBvbmVudHMvbXAtaHRtbC9ub2RlL25vZGUudnVl = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
  __proto__: null
}, Symbol.toStringTag, { value: "Module" }));
//# sourceMappingURL=../../../../../../.sourcemap/mp-weixin/uni_modules/mp-html/components/mp-html/node/node.js.map
