/*
* XmlDigitalTeaching v0.0.1
* Copyright ©Wed Dec 10 2025 14:35:07 GMT+0800 (中国标准时间) smile
* Released under the ISC License.
*/
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//

// import "../block.scss"
var script = {
  name: 'xmlHtmlRender',
  components: {},
  props: {
    //模式：preview 预览 (默认)，editor 编辑
    mode: {
      type: String,
      default: function () {
        return 'preview';
      }
    },
    //属性中传递过来的块儿数据
    pBlockData: {},
    //块儿数据名
    blockDataName: String,
    //页面类型，取值h5、pc、pad
    pageType: {
      type: String,
      default: 'h5'
    },
    //当前所处组的规则
    currentRule: {
      type: Object,
      default: function () {
        return {};
      }
    },
    ruleIndex: Number,
    extendParams: {
      type: Object,
      default: function () {
        return {};
      }
    },
    resourceBasisPath: {
      type: String,
      default: ''
    },
    isCopyUrl: {
      // 是否显示复制链接
      type: Boolean,
      default: false
    },
    isReader: {
      // 是否阅读器
      type: Boolean,
      default: false
    }
  },
  watch: {
    pBlockData: {
      handler(newValue) {
        // console.log('XmlHtml组件(ruleIndex:' + this.ruleIndex + ')，watch触发，变量pBlockData：', newValue)
        this.$nextTick(() => {
          this.blockData = Object.assign({}, this.blockData, newValue);
          if (this.blockData.htmlType === 'code') {
            this.addIframe();
          }
          // ios扫描二维码微信端不支持srcdoc，改为获取dom写入
          // 清除计时器
          // if (this.timer) {
          //   clearTimeout(this.timer)
          //   this.timer = null
          // }

          // this.timer = setTimeout(() => {
          //   if (this.blockData.htmlType === 'code') {
          //     var iframe = this.$refs.iframe
          //     iframe.contentWindow.document.write(this.pBlockData.code) // 动态写入返回页面到iframe
          //     iframe.contentWindow.document.close()

          //   }
          // }, 500)

          // console.log(this.blockData.code);
          // iframe.contentWindow.document.write(this.blockData.code) // 动态写入返回页面到iframe
          // iframe.contentWindow.document.close()
        });
      },
      deep: true,
      immediate: true
    }
  },
  data() {
    return {
      blockId: 'blockId' + Math.random(),
      //当前块儿数据，一般用不到，因为一般的块儿中不会在块儿内更改数据
      blockData: {},
      timer: null,
      fileBaseUrl: '',
      showDialog: false,
      height: '500px',
      noshow: false,
      retryCount: 10,
      //属性组件名
      propertyComponentsName: 'xml-html-property',
      src: 'data:image/png;base64,[encoded data, 23320 characters]'
      // ebookSetList:[]
    };
  },
  mounted() {
    // console.log('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa');

    // ios扫描二维码微信端不支持srcdoc，改为获取dom写入
    // var iframe = this.$refs.iframe
    // // console.log(this.blockData.code);
    // iframe.contentWindow.document.write(this.pBlockData.code) // 动态写入返回页面到iframe
    // iframe.contentWindow.document.close()

    this.height = window.innerHeight - 100 + 'px';
    // if (this.blockData.htmlType === 'code') {
    this.addIframe();
    // }
  },
  methods: {
    addIframe() {
      this.retryCount--;
      // console.log('addIframe', this.blockData, this.pBlockData,this.retryCount)
      if (this.pBlockData.htmlType == 'code' && this.pBlockData.code) {
        console.log('访问网址', this.pBlockData);
        let data = JSON.parse(JSON.stringify(this.blockData));
        var iframe = this.$refs.iframe;
        iframe.contentWindow.document.open();
        iframe.contentWindow.document.write(data.code); // 动态写入返回页面到iframe
        iframe.contentWindow.document.close();
      } else if (this.retryCount > 0) {
        setTimeout(() => {
          this.addIframe();
        }, 500);
      }
    },
    catchtouchmove() {},
    // 此方法必须要，用户注册块儿点击事件
    blockClick() {
      this.$emit('blockclick', {
        blockData: this.blockData,
        dataName: this.blockDataName,
        propertyComponentsName: this.propertyComponentsName,
        blockId: this.blockId,
        ruleIndex: this.ruleIndex
      });
    },
    goRead(info) {
      // console.log('🚀 ~ goRead ~ info:', info,this.mode,this.pageType)

      if (this.mode === 'preview' || this.mode == 'reader') {
        let url = '';
        if (info.htmlType == 'url') {
          url = info.link;
        } else {
          url = info.file.indexOf('./') !== -1 ? this.resourceBasisPath + info.file.split('./')[1] : info.file;
        }
        if (!this.isReader) {
          window.open(url);
        } else {
          this.$emit('openHtml', {
            previewUrl: url,
            title: info.materialName
          });
        }
      }
    },
    handleClose() {
      console.log('aaaaaaaaaaaaaaaaaaaa');
      this.showDialog = false;
    },
    open(info) {
      let url = '';
      if (info.htmlType == 'url') {
        url = info.link;
      } else {
        url = info.file.indexOf('./') !== -1 ? this.resourceBasisPath + info.file.split('./')[1] : info.file;
      }
      this.fileBaseUrl = url;
      this.showDialog = true;
    },
    toggleFullscreen() {
      const iframe = this.$el.querySelector('iframe');
      if (!iframe) return;
      if (!document.fullscreenElement) {
        if (iframe.requestFullscreen) {
          iframe.requestFullscreen();
        } else if (iframe.webkitRequestFullscreen) {
          iframe.webkitRequestFullscreen();
        } else if (iframe.msRequestFullscreen) {
          iframe.msRequestFullscreen();
        }
      } else {
        if (document.exitFullscreen) {
          document.exitFullscreen();
        } else if (document.webkitExitFullscreen) {
          document.webkitExitFullscreen();
        } else if (document.msExitFullscreen) {
          document.msExitFullscreen();
        }
      }
    },
    iframeLoaded() {
      this.addIframe();
    }
  },
  created() {
    // this.blockData = Object.assign( this.blockData,this.pBlockData)
  }
};

var __$_require_static_images_leaflet_resource_enter_html_cover_png__ = "data:image/png;base64,[encoded data, 4484 characters]";

function normalizeComponent(template, style, script, scopeId, isFunctionalTemplate, moduleIdentifier /* server only */, shadowMode, createInjector, createInjectorSSR, createInjectorShadow) {
  if (typeof shadowMode !== 'boolean') {
    createInjectorSSR = createInjector;
    createInjector = shadowMode;
    shadowMode = false;
  }
  // Vue.extend constructor export interop.
  const options = typeof script === 'function' ? script.options : script;
  // render functions
  if (template && template.render) {
    options.render = template.render;
    options.staticRenderFns = template.staticRenderFns;
    options._compiled = true;
    // functional template
    if (isFunctionalTemplate) {
      options.functional = true;
    }
  }
  // scopedId
  if (scopeId) {
    options._scopeId = scopeId;
  }
  let hook;
  if (moduleIdentifier) {
    // server build
    hook = function (context) {
      // 2.3 injection
      context = context ||
      // cached call
      this.$vnode && this.$vnode.ssrContext ||
      // stateful
      this.parent && this.parent.$vnode && this.parent.$vnode.ssrContext; // functional
      // 2.2 with runInNewContext: true
      if (!context && typeof __VUE_SSR_CONTEXT__ !== 'undefined') {
        context = __VUE_SSR_CONTEXT__;
      }
      // inject component styles
      if (style) {
        style.call(this, createInjectorSSR(context));
      }
      // register component module identifier for async chunk inference
      if (context && context._registeredComponents) {
        context._registeredComponents.add(moduleIdentifier);
      }
    };
    // used by ssr in case component is cached and beforeCreate
    // never gets called
    options._ssrRegister = hook;
  } else if (style) {
    hook = shadowMode ? function (context) {
      style.call(this, createInjectorShadow(context, this.$root.$options.shadowRoot));
    } : function (context) {
      style.call(this, createInjector(context));
    };
  }
  if (hook) {
    if (options.functional) {
      // register for functional component in vue file
      const originalRender = options.render;
      options.render = function renderWithStyleInjection(h, context) {
        hook.call(context);
        return originalRender(h, context);
      };
    } else {
      // inject component registration as beforeCreate hook
      const existing = options.beforeCreate;
      options.beforeCreate = existing ? [].concat(existing, hook) : [hook];
    }
  }
  return script;
}

/* script */
const __vue_script__ = script;
var __vue_render__ = function () {
  var _vm = this;
  var _h = _vm.$createElement;
  var _c = _vm._self._c || _h;
  return _c(
    "div",
    {
      staticClass: "xml-group-item xml-single-html-group-render",
      class: "xml-ebook-container-" + _vm.pageType,
      attrs: { id: _vm.blockId },
      on: { click: _vm.blockClick },
    },
    [
      _vm.noshow
        ? _c(
            "div",
            {
              staticClass: "xml-full-screen",
              staticStyle: { display: "none" },
              on: {
                click: function ($event) {
                  return _vm.open(_vm.blockData)
                },
              },
            },
            [
              _c("i", {
                staticClass: "el-icon-full-screen",
                attrs: { title: "全屏" },
              }),
            ]
          )
        : _vm._e(),
      _vm._v(" "),
      _vm.mode === "editor"
        ? _c("div", {
            staticClass: "xml-html-mask",
            attrs: { catchtouchmove: "catchtouchmove" },
          })
        : _vm._e(),
      _vm._v(" "),
      _vm.blockData.htmlType === "url"
        ? _c("div", { staticStyle: { width: "100%", overflow: "auto" } }, [
            _vm.isCopyUrl
              ? _c(
                  "div",
                  {
                    staticClass: "web-file-box",
                    on: {
                      click: function ($event) {
                        return _vm.$emit("copyHtmlUrl", _vm.blockData)
                      },
                    },
                  },
                  [
                    _c("div", { staticClass: "file-cover" }, [
                      _c("img", {
                        attrs: {
                          src: _vm.blockData.fileCover
                            ? _vm.blockData.fileCover.indexOf("http") !== -1
                              ? _vm.blockData.fileCover
                              : _vm.resourceBasisPath
                              ? _vm.resourceBasisPath +
                                _vm.blockData.fileCover.split("./")[1]
                              : _vm.blockData.file
                            : __$_require_static_images_leaflet_resource_enter_html_cover_png__,
                        },
                      }),
                    ]),
                    _vm._v(" "),
                    _c("div", { staticClass: "file-title" }, [
                      _vm._v(
                        "\n        " +
                          _vm._s(
                            _vm.blockData.fileNames
                              ? _vm.blockData.fileNames
                              : "--"
                          ) +
                          "\n      "
                      ),
                    ]),
                  ]
                )
              : !_vm.isCopyUrl && _vm.blockData.styleModel == "A"
              ? _c(
                  "div",
                  {
                    staticClass: "web-file-box",
                    on: {
                      click: function ($event) {
                        return _vm.goRead(_vm.blockData)
                      },
                    },
                  },
                  [
                    _c("div", { staticClass: "file-cover" }, [
                      _c("img", {
                        attrs: {
                          src: _vm.blockData.fileCover
                            ? _vm.blockData.fileCover.indexOf("http") !== -1
                              ? _vm.blockData.fileCover
                              : _vm.resourceBasisPath
                              ? _vm.resourceBasisPath +
                                _vm.blockData.fileCover.split("./")[1]
                              : _vm.blockData.file
                            : __$_require_static_images_leaflet_resource_enter_html_cover_png__,
                        },
                      }),
                    ]),
                    _vm._v(" "),
                    _c("div", { staticClass: "file-title" }, [
                      _vm._v(
                        "\n        " +
                          _vm._s(
                            _vm.blockData.fileNames
                              ? _vm.blockData.fileNames
                              : "--"
                          ) +
                          "\n      "
                      ),
                    ]),
                  ]
                )
              : _c("iframe", {
                  style: {
                    width: "100%",
                    border: "none",
                    height: _vm.blockData.htmlHeight + "px",
                    "padding-top": Number(_vm.blockData.htmlTopMargin) + "px",
                    "padding-bottom": _vm.blockData.htmlBottomMargin + "px",
                  },
                  attrs: { src: _vm.blockData.link, loading: "lazy" },
                }),
            _vm._v(" "),
            _c(
              "div",
              {
                staticClass: "fullscreen-btn",
                on: { click: _vm.toggleFullscreen },
              },
              [_c("i", { staticClass: "el-icon-full-screen" })]
            ),
          ])
        : _vm._e(),
      _vm._v(" "),
      _c(
        "div",
        {
          directives: [
            {
              name: "show",
              rawName: "v-show",
              value: _vm.blockData.htmlType === "code",
              expression: "blockData.htmlType === 'code'",
            },
          ],
        },
        [
          _c("iframe", {
            ref: "iframe",
            style: {
              width: "100%",
              height: _vm.blockData.htmlHeight + "px",
              border: "none",
              "padding-top": Number(_vm.blockData.htmlTopMargin) + "px",
              "padding-bottom": _vm.blockData.htmlBottomMargin + "px",
            },
            attrs: { loading: "lazy" },
            on: { load: _vm.iframeLoaded },
          }),
        ]
      ),
      _vm._v(" "),
      _vm.blockData.htmlType === "file"
        ? _c("div", [
            _vm.blockData.styleModel == "A"
              ? _c(
                  "div",
                  {
                    staticClass: "web-file-box",
                    on: {
                      click: function ($event) {
                        return _vm.goRead(_vm.blockData)
                      },
                    },
                  },
                  [
                    _c("div", { staticClass: "file-cover" }, [
                      _c("img", {
                        attrs: {
                          src: _vm.blockData.fileCover
                            ? _vm.blockData.fileCover.indexOf("http") !== -1
                              ? _vm.blockData.fileCover
                              : _vm.resourceBasisPath
                              ? _vm.resourceBasisPath +
                                _vm.blockData.fileCover.split("./")[1]
                              : _vm.blockData.file
                            : __$_require_static_images_leaflet_resource_enter_html_cover_png__,
                        },
                      }),
                    ]),
                    _vm._v(" "),
                    _c("div", { staticClass: "file-title" }, [
                      _vm._v(
                        "\n        " +
                          _vm._s(
                            _vm.blockData.fileNames
                              ? _vm.blockData.fileNames
                              : "--"
                          ) +
                          "\n      "
                      ),
                    ]),
                  ]
                )
              : _c("div", [
                  _c("iframe", {
                    style: {
                      width: "100%",
                      height: _vm.blockData.htmlHeight + "px",
                      border: "none",
                      "padding-top": Number(_vm.blockData.htmlTopMargin) + "px",
                      "padding-bottom": _vm.blockData.htmlBottomMargin + "px",
                    },
                    attrs: {
                      src: _vm.blockData.file
                        ? _vm.blockData.file.indexOf("http") !== -1
                          ? _vm.blockData.file
                          : _vm.resourceBasisPath
                          ? _vm.resourceBasisPath +
                            _vm.blockData.file.split("./")[1]
                          : _vm.blockData.file
                        : "",
                      loading: "lazy",
                    },
                  }),
                ]),
          ])
        : _vm._e(),
      _vm._v(" "),
      _c(
        "el-dialog",
        {
          attrs: { visible: _vm.showDialog, fullscreen: true },
          on: {
            "update:visible": function ($event) {
              _vm.showDialog = $event;
            },
          },
        },
        [
          _c("iframe", {
            ref: "xmlIframe",
            attrs: {
              width: "100%",
              height: _vm.height,
              frameborder: "0",
              src: _vm.fileBaseUrl,
            },
          }),
        ]
      ),
    ],
    1
  )
};
var __vue_staticRenderFns__ = [];
__vue_render__._withStripped = true;

  /* style */
  const __vue_inject_styles__ = undefined;
  /* scoped */
  const __vue_scope_id__ = undefined;
  /* module identifier */
  const __vue_module_identifier__ = undefined;
  /* functional template */
  const __vue_is_functional_template__ = false;
  /* style inject */
  
  /* style inject SSR */
  
  /* style inject shadow dom */
  

  
  const __vue_component__ = /*#__PURE__*/normalizeComponent(
    { render: __vue_render__, staticRenderFns: __vue_staticRenderFns__ },
    __vue_inject_styles__,
    __vue_script__,
    __vue_scope_id__,
    __vue_is_functional_template__,
    __vue_module_identifier__,
    false,
    undefined,
    undefined,
    undefined
  );

let componentNamespace = 'xml';
// 组件前缀命名只能更新一次，防止重复执行修改组件注册出错
let isUpdated = false;
function createNamespace(name, {
  prefix,
  isUnPrefix
}) {
  let useNamespace;
  if (!isUpdated) {
    isUpdated = true;
    useNamespace = prefix || componentNamespace; // 更改前缀
  }
  if (prefix) {
    if (name.indexOf(componentNamespace) === 0) {
      return name.replace(componentNamespace, prefix);
    }
    return useNamespace.charAt(0).toUpperCase() + useNamespace.substr(1) + name;
  }
  if (name.indexOf(componentNamespace) === 0 || name.indexOf(componentNamespace.charAt(0).toUpperCase()) === 0) {
    return name.charAt(0).toUpperCase() + name.substr(1);
  }
  return isUnPrefix ? name.charAt(0).toLowerCase() + name.substr(1) : componentNamespace + name.charAt(0).toUpperCase() + name.substr(1);
}

__vue_component__.install = (Vue, options = {}) => {
  Vue.component(createNamespace('html-render', {
    prefix: options.prefix
  }), __vue_component__);
};

export { __vue_component__ as default };
