import{ESGlobalBridgeStore as e}from"../../es-global-bridge/es-global-bridge.js";import{FileSystemBroker as t,FileSystemBrokerSingleton as o}from"../file-system-broker.js";class DOCXFileSystemBroker extends t{static get tag(){return"docx-file-system-broker"}constructor(){super(),this.libPath=new URL("./docx-file-system-broker.js",import.meta.url).href+"/../",this.libPath+="mammoth/",e.load("mammoth",this.libPath+"mammoth.browser.min.js").then((()=>{globalThis.mammoth&&(this.docx=globalThis.mammoth,this.dispatchEvent(new CustomEvent("docx-reader-ready",{bubbles:!0,composed:!0,cancelable:!1,detail:this})))}))}__toHTML(e,t){globalThis.dispatchEvent(new CustomEvent("docx-file-system-data",{composed:!1,bubbles:!1,cancelable:!0,detail:{name:t,value:e.value}}))}HTMLToDOCX(e,t,o=!0){const l=`<html xmlns:o='urn:schemas-microsoft-com:office:office' xmlns:w='urn:schemas-microsoft-com:office:word' xmlns='http://www.w3.org/TR/REC-html40'>\n      <head>\n        <meta charset='utf-8'>\n        <title>${t}</title>\n      </head>\n      <body>\n      ${e}\n      </body>\n    </html>`;if(o){let e=globalThis.document.createElement("a");globalThis.document.body.appendChild(e),e.href="data:application/vnd.ms-word;charset=utf-8,"+encodeURIComponent(l),e.download=`${t}.docx`,e.click(),globalThis.document.body.removeChild(e)}return l}fileToHTML(e,t="filepicked"){var o=new FileReader;o.onload=async e=>{await this.docx.convertToHtml({arrayBuffer:e.target.result}).then((e=>this.__toHTML(e,t))).done()},o.readAsBinaryString(e)}}customElements.define(DOCXFileSystemBroker.tag,DOCXFileSystemBroker),globalThis.DOCXFileSystemBroker=globalThis.DOCXFileSystemBroker||{},globalThis.DOCXFileSystemBroker.requestAvailability=()=>(globalThis.DOCXFileSystemBroker.instance||(globalThis.DOCXFileSystemBroker.instance=globalThis.document.createElement("docx-file-system-broker"),globalThis.document.body.appendChild(globalThis.DOCXFileSystemBroker.instance)),globalThis.DOCXFileSystemBroker.instance);const l=globalThis.DOCXFileSystemBroker.requestAvailability();export{l as DOCXFileSystemBrokerSingleton,DOCXFileSystemBroker,t as FileSystemBroker,o as FileSystemBrokerSingleton};