1"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[4797],{14797:(t,e,i)=>{function r(t="/wasm/"){let e=t.endsWith("/")?t:`${t}/`;return{sofficeJs:`${e}soffice.js`,sofficeWasm:`${e}soffice.wasm`,sofficeData:`${e}soffice.data`,sofficeWorkerJs:`${e}soffice.worker.js`}}i.d(e,{WorkerBrowserConverter:()=>y});var o=(t=>(t.UNKNOWN="UNKNOWN",t.INVALID_INPUT="INVALID_INPUT",t.UNSUPPORTED_FORMAT="UNSUPPORTED_FORMAT",t.CORRUPTED_DOCUMENT="CORRUPTED_DOCUMENT",t.PASSWORD_REQUIRED="PASSWORD_REQUIRED",t.WASM_NOT_INITIALIZED="WASM_NOT_INITIALIZED",t.CONVERSION_FAILED="CONVERSION_FAILED",t.LOAD_FAILED="LOAD_FAILED",t))(o||{}),s=class extends Error{code;details;constructor(t,e,i){super(e),this.name="ConversionError",this.code=t,this.details=i}},n={pdf:"writer_pdf_Export",docx:"MS Word 2007 XML",doc:"MS Word 97",odt:"writer8",rtf:"Rich Text Format",txt:"Text",html:"HTML (StarWriter)",xlsx:"Calc MS Excel 2007 XML",xls:"MS Excel 97",ods:"calc8",csv:"Text - txt - csv (StarCalc)",pptx:"Impress MS PowerPoint 2007 XML",ppt:"MS PowerPoint 97",odp:"impress8",png:"writer_png_Export",jpg:"writer_jpg_Export",svg:"writer_svg_Export"},l={pdf:"application/pdf",docx:"application/vnd.openxmlformats-officedocument.wordprocessingml.document",doc:"application/msword",odt:"application/vnd.oasis.opendocument.text",rtf:"application/rtf",txt:"text/plain",html:"text/html",xlsx:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",xls:"application/vnd.ms-excel",ods:"application/vnd.oasis.opendocument.spreadsheet",csv:"text/csv",pptx:"application/vnd.openxmlformats-officedocument.presentationml.presentation",ppt:"application/vnd.ms-powerpoint",odp:"application/vnd.oasis.opendocument.presentation",png:"image/png",jpg:"image/jpeg",svg:"image/svg+xml"},a={pdf:"pdf",docx:"docx",doc:"doc",odt:"odt",rtf:"rtf",txt:"txt",html:"html",xlsx:"xlsx",xls:"xls",ods:"ods",csv:"csv",pptx:"pptx",ppt:"ppt",odp:"odp",png:"png",jpg:"jpg",svg:"svg"},h={pdf:"",csv:"44,34,76,1,,0,false,true,false,false,false,-1",txt:"UTF8"},d=class extends null{cachedParagraphs=null;getDocumentType(){return"writer"}getStructure(t){try{let e=this.getParagraphsInternal(),i=t?.maxResponseChars??this.options.maxResponseChars,r=e.map((t,e)=>({index:e,preview:t.slice(0,100)+(t.length>100?"...":""),style:"Normal",charCount:t.length})),o=this.truncateArray(r,i,t=>JSON.stringify(t)),s={type:"writer",paragraphs:o.items,pageCount:this.lok.documentGetParts(this.docPtr),wordCount:e.join(" ").split(/\s+/).filter(t=>t.length>0).length};return o.truncated?this.createResultWithTruncation(s,{original:o.original,returned:o.returned,message:`Showing ${o.returned} of ${o.original} paragraphs. Use getParagraphs(start, count) to paginate.`}):this.createResult(s)}catch(t){return this.createErrorResult(`Failed to get structure: ${String(t)}`)}}getParagraph(t){try{let e=this.getParagraphsInternal();if(t<0||t>=e.length)return this.createErrorResult(`Paragraph index ${t} out of range (0-${e.length-1})`,"Use getStructure() to see available paragraphs");let i=e[t];return this.createResult({index:t,text:i,style:"Normal",charCount:i.length})}catch(t){return this.createErrorResult(`Failed to get paragraph: ${String(t)}`)}}getParagraphs(t,e){try{let i=this.getParagraphsInternal();if(t<0||t>=i.length)return this.createErrorResult(`Start index ${t} out of range`,`Valid range: 0-${i.length-1}`);let r=Math.min(t+e,i.length),o=i.slice(t,r).map((e,i)=>({index:t+i,text:e,style:"Normal",charCount:e.length}));return this.createResult(o)}catch(t){return this.createErrorResult(`Failed to get paragraphs: ${String(t)}`)}}insertParagraph(t,e){try{let i=this.getParagraphsInternal(),r=e?.afterIndex!==void 0?e.afterIndex+1:i.length;r>0&&r<=i.length&&this.lok.postUnoCommand(this.docPtr,".uno:GoToEndOfDoc"),this.lok.postUnoCommand(this.docPtr,".uno:InsertPara");let o=JSON.stringify({Text:{type:"string",value:t}});if(this.lok.postUnoCommand(this.docPtr,".uno:InsertText",o),e?.style&&"Normal"!==e.style){let t={"Heading 1":"Heading 1","Heading 2":"Heading 2","Heading 3":"Heading 3",List:"List"}[e.style];if(t){let e=JSON.stringify({Template:{type:"string",value:t},Family:{type:"short",value:2}});this.lok.postUnoCommand(this.docPtr,".uno:StyleApply",e)}}return this.cachedParagraphs=null,{success:!0,verified:this.getParagraphsInternal().length>i.length,data:{index:r}}}catch(t){return this.createErrorResult(`Failed to insert paragraph: ${String(t)}`)}}replaceParagraph(t,e){try{let i=this.getParagraphsInternal();if(t<0||t>=i.length)return this.createErrorResult(`Paragraph index ${t} out of range`,`Valid range: 0-${i.length-1}`);let r=i[t],o=JSON.stringify({"SearchItem.SearchString":{type:"string",value:r},"SearchItem.ReplaceString":{type:"string",value:e},"SearchItem.Command":{type:"long",value:2}});return this.lok.postUnoCommand(this.docPtr,".uno:ExecuteSearch",o),this.cachedParagraphs=null,this.createResult({oldText:r})}catch(t){return this.createErrorResult(`Failed to replace paragraph: ${String(t)}`)}}deleteParagraph(t){try{let e=this.getParagraphsInternal();if(t<0||t>=e.length)return this.createErrorResult(`Paragraph index ${t} out of range`,`Valid range: 0-${e.length-1}`);let i=e[t],r=this.replaceParagraph(t,"");return r.success?this.createResult({deletedText:i}):this.createErrorResult(r.error||"Failed to delete")}catch(t){return this.createErrorResult(`Failed to delete paragraph: ${String(t)}`)}}insertText(t,e){try{let e=JSON.stringify({Text:{type:"string",value:t}});return this.lok.postUnoCommand(this.docPtr,".uno:InsertText",e),this.cachedParagraphs=null,this.createResult(void 0)}catch(t){return this.createErrorResult(`Failed to insert text: ${String(t)}`)}}deleteText(t,e){try{let t=this.lok.getTextSelection(this.docPtr,"text/plain");return this.lok.postUnoCommand(this.docPtr,".uno:Delete"),this.cachedParagraphs=null,this.createResult({deleted:t||""})}catch(t){return this.createErrorResult(`Failed to delete text: ${String(t)}`)}}replaceText(t,e,i){try{let r=i?.all?3:2,o=JSON.stringify({"SearchItem.SearchString":{type:"string",value:t},"SearchItem.ReplaceString":{type:"string",value:e},"SearchItem.Command":{type:"long",value:r}});return this.lok.postUnoCommand(this.docPtr,".uno:ExecuteSearch",o),this.cachedParagraphs=null,this.createResult({replacements:-1})}catch(t){return this.createErrorResult(`Failed to replace text: ${String(t)}`)}}formatText(t,e){try{if(void 0!==e.bold&&this.lok.postUnoCommand(this.docPtr,".uno:Bold"),void 0!==e.italic&&this.lok.postUnoCommand(this.docPtr,".uno:Italic"),void 0!==e.underline&&this.lok.postUnoCommand(this.docPtr,".uno:Underline"),void 0!==e.fontSize){let t=JSON.stringify({FontHeight:{type:"float",value:e.fontSize}});this.lok.postUnoCommand(this.docPtr,".uno:FontHeight",t)}if(void 0!==e.fontName){let t=JSON.stringify({CharFontName:{type:"string",value:e.fontName}});this.lok.postUnoCommand(this.docPtr,".uno:CharFontName",t)}return this.createResult(void 0)}catch(t){return this.createErrorResult(`Failed to format text: ${String(t)}`)}}getFormat(t){try{this.lok.clearCallbackQueue(),this.lok.postUnoCommand(this.docPtr,".uno:CharRightSel"),this.lok.flushCallbacks(this.docPtr),this.lok.postUnoCommand(this.docPtr,".uno:CharLeft"),this.lok.flushCallbacks(this.docPtr);let t=this.lok.pollStateChanges(),e={},i=t.get(".uno:Bold");void 0!==i&&(e.bold="true"===i);let r=t.get(".uno:Italic");void 0!==r&&(e.italic="true"===r);let o=t.get(".uno:Underline");void 0!==o&&(e.underline="true"===o);let s=t.get(".uno:FontHeight");if(void 0!==s){let t=parseFloat(s);isNaN(t)||(e.fontSize=t)}let n=t.get(".uno:CharFontName");return void 0!==n&&n.length>0&&(e.fontName=n),this.createResult(e)}catch(t){return this.createErrorResult(`Failed to get format: ${String(t)}`)}}getSelectionFormat(){try{let t=this.lok.pollStateChanges();if(0===t.size){this.lok.clearCallbackQueue(),this.lok.postUnoCommand(this.docPtr,".uno:SelectWord"),this.lok.flushCallbacks(this.docPtr);let t=this.lok.pollStateChanges();return this.createResult(t)}return this.createResult(t)}catch(t){return this.createErrorResult(`Failed to get selection format: ${String(t)}`)}}getParagraphsInternal(){if(this.cachedParagraphs)return this.cachedParagraphs;let t=this.lok.getAllText(this.docPtr);return t?(this.cachedParagraphs=t.split(/\n\n|\r\n\r\n/).map(t=>t.trim()).filter(t=>t.length>0),this.cachedParagraphs):[]}},u=class extends null{getDocumentType(){return"calc"}getStructure(t){try{let t=this.lok.documentGetParts(this.docPtr),e=[];for(let i=0;i<t;i++){let t=this.lok.getPartName(this.docPtr,i)||`Sheet${i+1}`,r=this.lok.getDataArea(this.docPtr,i);e.push({index:i,name:t,usedRange:r.col>0&&r.row>
10?`A1:${this.rowColToA1(r.row-1,r.col-1)}`:"A1",rowCount:r.row,colCount:r.col})}return this.createResult({type:"calc",sheets:e})}catch(t){return this.createErrorResult(`Failed to get structure: ${String(t)}`)}}getSheetNames(){try{let t=this.lok.documentGetParts(this.docPtr),e=[];for(let i=0;i<t;i++){let t=this.lok.getPartName(this.docPtr,i)||`Sheet${i+1}`;e.push(t)}return this.createResult(e)}catch(t){return this.createErrorResult(`Failed to get sheet names: ${String(t)}`)}}getCell(t,e){try{this.selectSheet(e);let{row:i,col:r}=this.normalizeCellRef(t),o=this.rowColToA1(i,r);this.goToCell(o);let s=this.getCellValueInternal(),n=this.getCellFormulaInternal();return this.createResult({address:o,value:s,formula:n||void 0})}catch(t){return this.createErrorResult(`Failed to get cell: ${String(t)}`)}}getCells(t,e,i){try{this.selectSheet(e);let{startRow:r,startCol:o,endRow:s,endCol:n}=this.normalizeRangeRef(t),l=i?.maxResponseChars??this.options.maxResponseChars,a=[],h=0,d=!1;for(let t=r;t<=s&&!d;t++){let e=[];for(let i=o;i<=n&&!d;i++){let r=this.rowColToA1(t,i);this.goToCell(r);let o=this.getCellValueInternal(),s={address:r,value:o},n=JSON.stringify(s);if(h+n.length>l){d=!0;break}h+=n.length,e.push(s)}e.length>0&&a.push(e)}return d?this.createResultWithTruncation(a,{original:(s-r+1)*(n-o+1),returned:a.reduce((t,e)=>t+e.length,0),message:"Range truncated due to size. Use smaller ranges to paginate."}):this.createResult(a)}catch(t){return this.createErrorResult(`Failed to get cells: ${String(t)}`)}}setCellValue(t,e,i){try{this.selectSheet(i);let{row:r,col:o}=this.normalizeCellRef(t),s=this.rowColToA1(r,o);this.goToCell(s);let n=this.getCellValueInternal(),l="number"==typeof e?e.toString():e,a=JSON.stringify({StringName:{type:"string",value:l}});this.lok.postUnoCommand(this.docPtr,".uno:EnterString",a);let h=this.getCellValueInternal(),d="number"==typeof e?e.toString():e;return{success:!0,verified:h===d||h===e,data:{oldValue:n,newValue:h}}}catch(t){return this.createErrorResult(`Failed to set cell value: ${String(t)}`)}}setCellFormula(t,e,i){try{this.selectSheet(i);let{row:r,col:o}=this.normalizeCellRef(t),s=this.rowColToA1(r,o);this.goToCell(s);let n=JSON.stringify({StringName:{type:"string",value:e}});this.lok.postUnoCommand(this.docPtr,".uno:EnterString",n);let l=this.getCellValueInternal();return this.createResult({calculatedValue:l})}catch(t){return this.createErrorResult(`Failed to set formula: ${String(t)}`)}}setCells(t,e,i){try{this.selectSheet(i);let{startRow:r,startCol:o}=this.normalizeRangeRef(t),s=0;for(let t=0;t<e.length;t++){let i=e[t];if(i)for(let e=0;e<i.length;e++){let n=i[e];if(null==n)continue;let l=this.rowColToA1(r+t,o+e);this.goToCell(l);let a="number"==typeof n?n.toString():String(n),h=JSON.stringify({StringName:{type:"string",value:a}});this.lok.postUnoCommand(this.docPtr,".uno:EnterString",h),s++}}return this.createResult({cellsUpdated:s})}catch(t){return this.createErrorResult(`Failed to set cells: ${String(t)}`)}}clearCell(t,e){try{this.selectSheet(e);let{row:i,col:r}=this.normalizeCellRef(t),o=this.rowColToA1(i,r);this.goToCell(o);let s=this.getCellValueInternal();return this.lok.postUnoCommand(this.docPtr,".uno:ClearContents"),this.createResult({oldValue:s})}catch(t){return this.createErrorResult(`Failed to clear cell: ${String(t)}`)}}clearRange(t,e){try{this.selectSheet(e);let i=this.normalizeRangeToString(t);this.goToCell(i),this.lok.postUnoCommand(this.docPtr,".uno:ClearContents");let{startRow:r,startCol:o,endRow:s,endCol:n}=this.normalizeRangeRef(t);return this.createResult({cellsCleared:(s-r+1)*(n-o+1)})}catch(t){return this.createErrorResult(`Failed to clear range: ${String(t)}`)}}insertRow(t,e){try{return this.selectSheet(e),this.goToCell(this.rowColToA1(t+1,0)),this.lok.postUnoCommand(this.docPtr,".uno:InsertRows"),this.createResult(void 0)}catch(t){return this.createErrorResult(`Failed to insert row: ${String(t)}`)}}insertColumn(t,e){try{this.selectSheet(e);let i="string"==typeof t?this.a1ToRowCol(t+"1").col+1:t+1;return this.goToCell(this.rowColToA1(0,i)),this.lok.postUnoCommand(this.docPtr,".uno:InsertColumns"),this.createResult(void 0)}catch(t){return this.createErrorResult(`Failed to insert column: ${String(t)}`)}}deleteRow(t,e){try{return this.selectSheet(e),this.goToCell(this.rowColToA1(t,0)),this.lok.postUnoCommand(this.docPtr,".uno:DeleteRows"),this.createResult(void 0)}catch(t){return this.createErrorResult(`Failed to delete row: ${String(t)}`)}}deleteColumn(t,e){try{this.selectSheet(e);let i="string"==typeof t?this.a1ToRowCol(t+"1").col:t;return this.goToCell(this.rowColToA1(0,i)),this.lok.postUnoCommand(this.docPtr,".uno:DeleteColumns"),this.createResult(void 0)}catch(t){return this.createErrorResult(`Failed to delete column: ${String(t)}`)}}formatCells(t,e,i){try{this.selectSheet(i);let r=this.normalizeRangeToString(t);if(this.goToCell(r),void 0!==e.bold&&this.lok.postUnoCommand(this.docPtr,".uno:Bold"),void 0!==e.numberFormat){let t=JSON.stringify({NumberFormatValue:{type:"string",value:e.numberFormat}});this.lok.postUnoCommand(this.docPtr,".uno:NumberFormatValue",t)}
1if(void 0!==e.backgroundColor){let t=JSON.stringify({BackgroundColor:{type:"long",value:this.hexToNumber(e.backgroundColor)}});this.lok.postUnoCommand(this.docPtr,".uno:BackgroundColor",t)}return this.createResult(void 0)}catch(t){return this.createErrorResult(`Failed to format cells: ${String(t)}`)}}addSheet(t){try{let e=JSON.stringify({Name:{type:"string",value:t}});this.lok.postUnoCommand(this.docPtr,".uno:Insert",e);let i=this.lok.documentGetParts(this.docPtr);return this.createResult({index:i-1})}catch(t){return this.createErrorResult(`Failed to add sheet: ${String(t)}`)}}renameSheet(t,e){try{this.selectSheet(t);let i=JSON.stringify({Name:{type:"string",value:e}});return this.lok.postUnoCommand(this.docPtr,".uno:RenameTable",i),this.createResult(void 0)}catch(t){return this.createErrorResult(`Failed to rename sheet: ${String(t)}`)}}deleteSheet(t){try{return this.selectSheet(t),this.lok.postUnoCommand(this.docPtr,".uno:Remove"),this.createResult(void 0)}catch(t){return this.createErrorResult(`Failed to delete sheet: ${String(t)}`)}}selectSheet(t){if(void 0===t)return;let e="number"==typeof t?t:this.getSheetIndexByName(t);e>=0&&this.lok.documentSetPart(this.docPtr,e)}getSheetIndexByName(t){let e=this.lok.documentGetParts(this.docPtr);for(let i=0;i<e;i++)if(this.lok.getPartName(this.docPtr,i)===t)return i;return -1}goToCell(t){let e=JSON.stringify({ToPoint:{type:"string",value:t}});this.lok.postUnoCommand(this.docPtr,".uno:GoToCell",e)}getCellValueInternal(){let t=this.lok.getTextSelection(this.docPtr,"text/plain");if(!t)return null;let e=parseFloat(t);return isNaN(e)||t.trim()!==e.toString()?"true"===t.toLowerCase()||"false"!==t.toLowerCase()&&t:e}getCellFormulaInternal(){let t=this.lok.getCommandValues(this.docPtr,".uno:GetFormulaBarText");if(!t)return null;try{return JSON.parse(t).value??null}catch{return null}}normalizeRangeRef(t){if("string"==typeof t){let e=t.split(":"),i=this.a1ToRowCol(e[0]),r=e[1]?this.a1ToRowCol(e[1]):i;return{startRow:i.row,startCol:i.col,endRow:r.row,endCol:r.col}}let e=this.normalizeCellRef(t.start),i=this.normalizeCellRef(t.end);return{startRow:e.row,startCol:e.col,endRow:i.row,endCol:i.col}}normalizeRangeToString(t){if("string"==typeof t)return t;let e=this.normalizeCellRef(t.start),i=this.normalizeCellRef(t.end);return`${this.rowColToA1(e.row,e.col)}:${this.rowColToA1(i.row,i.col)}`}hexToNumber(t){return parseInt(t.replace("#",""),16)}},c=class extends null{getDocumentType(){return"impress"}getStructure(t){try{let t=this.lok.documentGetParts(this.docPtr),e=[];for(let i=0;i<t;i++){let t=this.getSlideInfoInternal(i);e.push(t)}return this.createResult({type:"impress",slides:e,slideCount:t})}catch(t){return this.createErrorResult(`Failed to get structure: ${String(t)}`)}}getSlide(t){try{let e=this.lok.documentGetParts(this.docPtr);if(t<0||t>=e)return this.createErrorResult(`Invalid slide index: ${t}. Valid range: 0-${e-1}`,"Use getStructure() to see available slides");this.lok.documentSetPart(this.docPtr,t);let i=this.lok.getAllText(this.docPtr)||"",r=this.parseTextFrames(i),o={index:t,title:r.find(t=>"title"===t.type)?.text,textFrames:r,hasNotes:!1};return this.createResult(o)}catch(t){return this.createErrorResult(`Failed to get slide: ${String(t)}`)}}getSlideCount(){try{let t=this.lok.documentGetParts(this.docPtr);return this.createResult(t)}catch(t){return this.createErrorResult(`Failed to get slide count: ${String(t)}`)}}addSlide(t){try{let e=this.lok.documentGetParts(this.docPtr);t?.afterSlide!==void 0?this.lok.documentSetPart(this.docPtr,t.afterSlide):this.lok.documentSetPart(this.docPtr,e-1),this.lok.postUnoCommand(this.docPtr,".uno:InsertPage"),t?.layout&&this.applySlideLayout(t.layout);let i=t?.afterSlide!==void 0?t.afterSlide+1:e;return{success:!0,verified:this.lok.documentGetParts(this.docPtr)>e,data:{index:i}}}catch(t){return this.createErrorResult(`Failed to add slide: ${String(t)}`)}}deleteSlide(t){try{let e=this.lok.documentGetParts(this.docPtr);return e<=1?this.createErrorResult("Cannot delete the last slide","A presentation must have at least one slide"):t<0||t>=e?this.createErrorResult(`Invalid slide index: ${t}`,`Valid range: 0-${e-1}`):(this.lok.documentSetPart(this.docPtr,t),this.lok.postUnoCommand(this.docPtr,".uno:DeletePage"),this.createResult(void 0))}catch(t){return this.createErrorResult(`Failed to delete slide: ${String(t)}`)}}duplicateSlide(t){try{let e=this.lok.documentGetParts(this.docPtr);return t<0||t>=e?this.createErrorResult(`Invalid slide index: ${t}`,`Valid range: 0-${e-1}`):(this.lok.documentSetPart(this.docPtr,t),this.lok.postUnoCommand(this.docPtr,".uno:Dupl
1icatePage"),this.createResult({newIndex:t+1}))}catch(t){return this.createErrorResult(`Failed to duplicate slide: ${String(t)}`)}}moveSlide(t,e){try{let i=this.lok.documentGetParts(this.docPtr);if(t<0||t>=i||e<0||e>=i)return this.createErrorResult(`Invalid slide indices. Valid range: 0-${i-1}`,"Check slide indices are within bounds");if(t===e)return this.createErrorResult("Source and destination are the same","Provide different indices to move");this.lok.documentSetPart(this.docPtr,t);let r=JSON.stringify({Position:{type:"long",value:e}});return this.lok.postUnoCommand(this.docPtr,".uno:MovePageFirst",r),this.createResult(void 0)}catch(t){return this.createErrorResult(`Failed to move slide: ${String(t)}`)}}setSlideTitle(t,e){try{let i=this.lok.documentGetParts(this.docPtr);if(t<0||t>=i)return this.createErrorResult(`Invalid slide index: ${t}`);this.lok.documentSetPart(this.docPtr,t);let r=this.lok.getAllText(this.docPtr)||"",o=this.parseTextFrames(r).find(t=>"title"===t.type)?.text;this.lok.postUnoCommand(this.docPtr,".uno:SelectAll");let s=JSON.stringify({Text:{type:"string",value:e}});return this.lok.postUnoCommand(this.docPtr,".uno:InsertText",s),this.createResult({oldTitle:o})}catch(t){return this.createErrorResult(`Failed to set slide title: ${String(t)}`)}}setSlideBody(t,e){try{let i=this.lok.documentGetParts(this.docPtr);if(t<0||t>=i)return this.createErrorResult(`Invalid slide index: ${t}`);this.lok.documentSetPart(this.docPtr,t);let r=this.lok.getAllText(this.docPtr)||"",o=this.parseTextFrames(r).find(t=>"body"===t.type)?.text;this.lok.postUnoCommand(this.docPtr,".uno:NextObject");let s=JSON.stringify({Text:{type:"string",value:e}});return this.lok.postUnoCommand(this.docPtr,".uno:InsertText",s),this.createResult({oldBody:o})}catch(t){return this.createErrorResult(`Failed to set slide body: ${String(t)}`)}}setSlideNotes(t,e){try{let i=this.lok.documentGetParts(this.docPtr);if(t<0||t>=i)return this.createErrorResult(`Invalid slide index: ${t}`);this.lok.documentSetPart(this.docPtr,t),this.lok.postUnoCommand(this.docPtr,".uno:NotesMode");let r=JSON.stringify({Text:{type:"string",value:e}});return this.lok.postUnoCommand(this.docPtr,".uno:InsertText",r),this.lok.postUnoCommand(this.docPtr,".uno:NormalViewMode"),this.createResult(void 0)}catch(t){return this.createErrorResult(`Failed to set slide notes: ${String(t)}`)}}setSlideLayout(t,e){try{let i=this.lok.documentGetParts(this.docPtr);return t<0||t>=i?this.createErrorResult(`Invalid slide index: ${t}`):(this.lok.documentSetPart(this.docPtr,t),this.applySlideLayout(e),this.createResult(void 0))}catch(t){return this.createErrorResult(`Failed to set slide layout: ${String(t)}`)}}getSlideInfoInternal(t){this.lok.documentSetPart(this.docPtr,t);let e=this.lok.getAllText(this.docPtr)||"",i=this.parseTextFrames(e),r=i.find(t=>"title"===t.type);return{index:t,title:r?.text,layout:this.detectLayout(i),textFrameCount:i.length}}parseTextFrames(t){let e=t.split(/\n\n+/).filter(t=>t.trim()),i=[];return e.forEach((t,e)=>{i.push({index:e,type:0===e?"title":1===e?"body":"other",text:t.trim(),bounds:{x:0,y:0,width:0,height:0}})}),i}detectLayout(t){return 0===t.length?"blank":1===t.length&&t[0]?.type==="title"?"title":t.length>=2?"titleContent":"blank"}applySlideLayout(t){let e=JSON.stringify({WhatLayout:{type:"long",value:{blank:0,title:1,titleContent:2,twoColumn:3}[t]??0}});this.lok.postUnoCommand(this.docPtr,".uno:AssignLayout",e)}},m=class extends null{isImportedPdf=!1;getDocumentType(){return"draw"}setImportedPdf(t){this.isImportedPdf=t}getStructure(t){try{let t=this.lok.documentGetParts(this.docPtr),e=[];for(let i=0;i<t;i++){let t=this.getPageInfoInternal(i);e.push(t)}let i={type:"draw",pages:e,pageCount:t,isImportedPdf:this.isImportedPdf};return this.createResult(i)}catch(t){return this.createErrorResult(`Failed to get structure: ${String(t)}`)}}getPage(t){try{let e=this.lok.documentGetParts(this.docPtr);if(t<0||t>=e)return this.createErrorResult(`Invalid page index: ${t}. Valid range: 0-${e-1}`,"Use getStructure() to see available pages");this.lok.documentSetPart(this.docPtr,t);let i=this.lok.documentGetDocumentSize(this.docPtr),r=this.getShapesOnPage(),o={index:t,shapes:r,size:{width:i.width,height:i.height}};return this.createResult(o)}catch(t){return this.createErrorResult(`Failed to get page: ${String(t)}`)}}getPageCount(){try{let t=this.lok.documentGetParts(this.docPtr);return this.createResult(t)}catch(t){return this.createErrorResult(`Failed to get page count: ${String(t)}`)}}addPage(t){try{let e=this.lok.documentGetParts(this.docPtr);t?.afterPage!==void 0?this.lok.documentSetPart(this.docPtr,t.afterPage):this.lok.documentSetPart(this.docPtr,e-1),this.lok.postUnoCommand(this.docPtr,".uno:InsertPage");let i=t?.afterPage!==void 0?t.afterPage+1:e;return this.createResult({index:i})}catch(t){return this.createErrorResult(`Failed to add page: ${String(t)}`)}}deletePage(t){try{let e=this.lok.documentGetParts(this.docPtr);return e<=1?this.createErrorResult("Cannot delete the last page","A drawing document must have at least one page"):t<0||t>=e?this.createErrorResult(`Invalid page index: ${t}`,`Valid range: 0-${e-1}`):(this.lok.documentSetPart(this.docPtr,t),this.lok.postUnoCommand(this.docPtr,".uno:DeletePage"),this.createResult(void 0))}catch(t){return this.createErrorResult(`Failed to delete page: ${String(t)}`)}}duplicatePage(t){try{let e=this.lok.documentGetParts(this.docPtr);return t<0||t>=e?this.createErrorResult(`Invalid page index: ${t}`,`Valid range: 0-${e-1}`):(this.lok.documentSetPart(this.docPtr,t),this.lok.postUnoCommand(this.docPtr,".uno:Dupl
1icatePage"),this.createResult({newIndex:t+1}))}catch(t){return this.createErrorResult(`Failed to duplicate page: ${String(t)}`)}}addShape(t,e,i,r){try{let o=this.lok.documentGetParts(this.docPtr);if(t<0||t>=o)return this.createErrorResult(`Invalid page index: ${t}`);this.lok.documentSetPart(this.docPtr,t);let s=this.getShapeCommand(e),n=JSON.stringify({X:{type:"long",value:i.x},Y:{type:"long",value:i.y},Width:{type:"long",value:i.width},Height:{type:"long",value:i.height}});if(this.lok.postUnoCommand(this.docPtr,s,n),r?.text){let t=JSON.stringify({Text:{type:"string",value:r.text}});this.lok.postUnoCommand(this.docPtr,".uno:InsertText",t)}if(r?.fillColor){let t=JSON.stringify({FillColor:{type:"long",value:this.hexToNumber(r.fillColor)}});this.lok.postUnoCommand(this.docPtr,".uno:FillColor",t)}if(r?.lineColor){let t=JSON.stringify({LineColor:{type:"long",value:this.hexToNumber(r.lineColor)}});this.lok.postUnoCommand(this.docPtr,".uno:XLineColor",t)}return this.createResult({shapeIndex:0})}catch(t){return this.createErrorResult(`Failed to add shape: ${String(t)}`)}}addLine(t,e,i,r){try{let o=this.lok.documentGetParts(this.docPtr);if(t<0||t>=o)return this.createErrorResult(`Invalid page index: ${t}`);this.lok.documentSetPart(this.docPtr,t);let s=JSON.stringify({StartX:{type:"long",value:e.x},StartY:{type:"long",value:e.y},EndX:{type:"long",value:i.x},EndY:{type:"long",value:i.y}});if(this.lok.postUnoCommand(this.docPtr,".uno:Line",s),r?.lineColor){let t=JSON.stringify({LineColor:{type:"long",value:this.hexToNumber(r.lineColor)}});this.lok.postUnoCommand(this.docPtr,".uno:XLineColor",t)}if(r?.lineWidth){let t=JSON.stringify({LineWidth:{type:"long",value:r.lineWidth}});this.lok.postUnoCommand(this.docPtr,".uno:LineWidth",t)}return this.createResult({shapeIndex:0})}catch(t){return this.createErrorResult(`Failed to add line: ${String(t)}`)}}deleteShape(t,e){try{return this.lok.documentSetPart(this.docPtr,t),this.selectShape(e),this.lok.postUnoCommand(this.docPtr,".uno:Delete"),this.createResult(void 0)}catch(t){return this.createErrorResult(`Failed to delete shape: ${String(t)}`)}}setShapeText(t,e,i){try{this.lok.documentSetPart(this.docPtr,t),this.selectShape(e),this.lok.postUnoCommand(this.docPtr,".uno:EnterGroup"),this.lok.postUnoCommand(this.docPtr,".uno:SelectAll");let r=JSON.stringify({Text:{type:"string",value:i}});return this.lok.postUnoCommand(this.docPtr,".uno:InsertText",r),this.lok.postUnoCommand(this.docPtr,".uno:LeaveGroup"),this.createResult(void 0)}catch(t){return this.createErrorResult(`Failed to set shape text: ${String(t)}`)}}moveShape(t,e,i){try{this.lok.documentSetPart(this.docPtr,t),this.selectShape(e);let r=JSON.stringify({X:{type:"long",value:i.x},Y:{type:"long",value:i.y}});return this.lok.postUnoCommand(this.docPtr,".uno:SetObjectPosition",r),this.createResult(void 0)}catch(t){return this.createErrorResult(`Failed to move shape: ${String(t)}`)}}resizeShape(t,e,i){try{this.lok.documentSetPart(this.docPtr,t),this.selectShape(e);let r=JSON.stringify({Width:{type:"long",value:i.width},Height:{type:"long",value:i.height}});return this.lok.postUnoCommand(this.docPtr,".uno:Size",r),this.createResult(void 0)}catch(t){return this.createErrorResult(`Failed to resize shape: ${String(t)}`)}}getPageInfoInternal(t){this.lok.documentSetPart(this.docPtr,t);let e=this.lok.documentGetDocumentSize(this.docPtr);return{index:t,shapeCount:this.getShapesOnPage().length,size:{width:e.width,height:e.height}}}getShapesOnPage(){let t=this.lok.getAllText(this.docPtr)||"";return t.trim()?[{index:0,type:"text",text:t,bounds:{x:0,y:0,width:0,height:0}}]:[]}selectShape(t){let e=JSON.stringify({Index:{type:"long",value:t}});this.lok.postUnoCommand(this.docPtr,".uno:SelectObject",e)}getShapeCommand(t){return({rectangle:".uno:Rect",ellipse:".uno:Ellipse",line:".uno:Line",text:".uno:Text",image:".uno:InsertGraphic",group:".uno:FormatGroup",other:".uno:Rect"})[t]}hexToNumber(t){return parseInt(t.replace("#",""),16)}},g={destroy:4,documentLoad:8,getError:12,documentLoadWithOptions:16},p={destroy:4,saveAs:8},f=new TextEncoder,S=new TextDecoder,P=class{module;lokPtr=0;verbose;useShims;constructor(t,e=!1){this.module=t,this.verbose=e,this.useShims="function"==typeof this.module._lok_documentLoad,this.useShims?this.log("Using direct LOK shim exports"):this.log("Using vtable traversal (shims not available)")}log(...t){this.verbose&&console.log("[LOK]",...t)}get HEAPU8(){return this.module.HEAPU8}get HEAPU32(){return this.module.HEAPU32}get HEAP32(){return this.module.HEAP32}allocString(t){let e=f.encode(t+"\0"),i=this.module._malloc(e.length);return this.HEAPU8.set(e,i),i}readString(t){if(0===t)return null;let e=this.HEAPU8,i=t;
1for(;0!==e[i];)i++;let r=e.slice(t,i);return S.decode(r)}readPtr(t){return this.HEAPU32[t>>2]||0}getFunc(t){return this.module.wasmTable.get(t)}initialize(t="/instdir/program"){this.log("Initializing with path:",t);let e=this.allocString(t);try{let t=this.module._libreofficekit_hook;if("function"!=typeof t)throw Error("libreofficekit_hook export not found on module");if(this.lokPtr=t(e),0===this.lokPtr)throw Error("Failed to initialize LibreOfficeKit");this.log("LOK initialized, ptr:",this.lokPtr)}finally{this.module._free(e)}}getError(){if(0===this.lokPtr)return null;if(this.useShims&&this.module._lok_getError){let t=this.module._lok_getError(this.lokPtr);return this.readString(t)}let t=this.readPtr(this.lokPtr),e=this.readPtr(t+g.getError);if(0===e)return null;let i=this.getFunc(e)(this.lokPtr);return this.readString(i)}getVersionInfo(){return"LibreOffice WASM"}toFileUrl(t){return t.startsWith("file://")?t:"file://"+(t.startsWith("/")?t:"/"+t)}documentLoad(t){if(0===this.lokPtr)throw Error("LOK not initialized");let e=this.toFileUrl(t);this.log("Loading document:",t,"->",e);let i=this.allocString(e);try{let t=Date.now(),e;if(this.useShims&&this.module._lok_documentLoad)e=this.module._lok_documentLoad(this.lokPtr,i);else{let t=this.readPtr(this.lokPtr),r=this.readPtr(t+g.documentLoad);e=this.getFunc(r)(this.lokPtr,i)}if(this.log("Document loaded in",Date.now()-t,"ms, ptr:",e),0===e){let t=this.getError();throw Error(`Failed to load document: ${t||"unknown error"}`)}return e}finally{this.module._free(i)}}documentLoadWithOptions(t,e){if(0===this.lokPtr)throw Error("LOK not initialized");let i=this.toFileUrl(t);this.log("Loading document with options:",t,"->",i,e);let r=this.allocString(i),o=this.allocString(e);try{let e;if(this.useShims&&this.module._lok_documentLoadWithOptions)e=this.module._lok_documentLoadWithOptions(this.lokPtr,r,o);else{let i=this.readPtr(this.lokPtr),s=this.readPtr(i+g.documentLoadWithOptions);if(0===s)return this.documentLoad(t);e=this.getFunc(s)(this.lokPtr,r,o)}if(0===e){let t=this.getError();throw Error(`Failed to load document: ${t||"unknown error"}`)}return this.log("Document loaded, ptr:",e),e}finally{this.module._free(r),this.module._free(o)}}documentSaveAs(t,e,i,r=""){if(0===t)throw Error("Invalid document pointer");let o=this.toFileUrl(e);this.log("Saving document to:",e,"->",o,"format:",i);let s=this.allocString(o),n=this.allocString(i),l=this.allocString(r);try{let e;if(this.useShims&&this.module._lok_documentSaveAs)e=this.module._lok_documentSaveAs(t,s,n,l);else{let i=this.readPtr(t),r=this.readPtr(i+p.saveAs);e=this.getFunc(r)(t,s,n,l)}if(this.log("Save result:",e),0===e)throw Error("Failed to save document")}finally{this.module._free(s),this.module._free(n),this.module._free(l)}}documentDestroy(t){if(0===t)return;if(this.useShims&&this.module._lok_documentDestroy){this.module._lok_documentDestroy(t),this.log("Document destroyed (via shim)");return}let e=this.readPtr(t),i=this.readPtr(e+p.destroy);0!==i&&(this.getFunc(i)(t),this.log("Document destroyed (via vtable)"))}destroy(){if(0!==this.lokPtr){try{if(this.useShims&&this.module._lok_destroy)this.module._lok_destroy(this.lokPtr),this.log("LOK destroyed (via shim)");else{let t=this.readPtr(this.lokPtr),e=this.readPtr(t+g.destroy);0!==e&&(this.getFunc(e)(this.lokPtr),this.log("LOK destroyed (via vtable)"))}}catch(t){this.log("LOK destroy error (ignored):",t)}this.lokPtr=0}}isInitialized(){return 0!==this.lokPtr}isUsingShims(){return this.useShims}documentGetParts(t){if(0===t)throw Error("Invalid document pointer");return this.useShims&&this.module._lok_documentGetParts?this.module._lok_documentGetParts(t):(this.log("documentGetParts: shim not available"),0)}documentGetPart(t){if(0===t)throw Error("Invalid document pointer");return this.useShims&&this.module._lok_documentGetPart?this.module._lok_documentGetPart(t):(this.log("documentGetPart: shim not available"),0)}documentSetPart(t,e){if(0===t)throw Error("Invalid document pointer");if(this.useShims&&this.module._lok_documentSetPart){this.module._lok_documentSetPart(t,e);return}this.log("documentSetPart: shim not available")}documentGetDocumentType(t){if(0===t)throw Error("Invalid document pointer");return this.useShims&&this.module._lok_documentGetDocumentType?this.module._lok_documentGetDocumentType(t):(this.log("documentGetDocumentType: shim not available"),0)}documentGetDocumentSize(t){if(this.log(`documentGetDocumentSize called with docPtr: ${t}`),0===t)throw Error("Invalid document pointer");if(this.useShims&&this.module._lok_documentGetDocumentSize){let e=this.module._malloc(8);try{this.module._lok_documentGetDocumentSize(t,e,e+4);let i=this.HEAP32[e>>2]??0,r=this.HEAP32[e+4>>2]??0;return this.log(`documentGetDocumentSize: ${i}x${r} twips`),{width:i,height:r}}finally{this.module._free(e)}}return this.log("documentGetDocumentSize: shim not available"),{width:0,height:0}}documentInitializeForRendering(t,e=""){if(0===t)throw Error("Invalid document pointer");if(this.useShims&&this.module._lok_documentInitializeForRendering){let i=this.allocString(e);try{this.module._lok_documentInitializeForRendering(t,i)}finally{this.module._free(i)}return}this.log("documentInitializeForRendering: shim not available")}documentPaintTile(t,e,i,r,o,s,n){if(0===t)throw Error("Invalid document pointer");if(this.useShims&&this.module._lok_documentPaintTile){let l=e*i*4,a=this.module._malloc(l);if(0===a)throw Error(`Failed to allocate ${l} bytes for tile buffer`);try{this.module._lok_documentPaintTile(t,a,e,i,r,o,s,n);let h=new Uint8Array(l);return h.set(this.HEAPU8.subarray(a,a+l)),h}finally{this.module._free(a)}}return this.log("documentPaintTile: shim not available"),new Uint8Array(0)}documentGetTileMode(t){if(0===t)throw Error("Invalid document pointer");return this.useShims&&this.module._lok_documentGetTileMode?this.module._lok_documentGetTileMode(t):(this.log("documentGetTileMode: shim not available"),0)}renderPage(t,e,i,r=0,o=!1){this.documentInitializeForRendering(t);let s=this.documentGetDocumentType(t);if(2===s||3===s){console.log(`[LOK] Setting part to ${e} for presentation/drawing`),this.documentSetPart(t,e);let i=this.documentGetPart(t);console.log(`[LOK] Current part after setPart: ${i}`),o||(this.setEditMode(t,0),console.log("[LOK] Set edit mode to 0 (view mode) for presentation rendering"))}let n=this.documentGetDocumentSize(t);if(this.log("Document size (twips):",n),0===n.width||0===n.height)throw Error("Failed to get document size");let l=0,a=0,h=n.width,d=n.height;if(0===s||1===s){let i=this.getPartPageRectangles(t);if(i){let t=this.parsePageRectangles(i)[e];t&&(l=t.x,a=t.y,h=t.width,d=t.height,this.log(`Page ${e}
1 rectangle:`,t))}}let u=d/h,c=r>0?r:Math.round(i*u);console.log(`[LOK] Calling paintTile: ${i}x${c} from tile pos (${l}, ${a}) size (${h}x${d})`);let m=this.documentPaintTile(t,i,c,l,a,h,d);return console.log(`[LOK] paintTile returned ${m.length} bytes`),{data:m,width:i,height:c}}renderPageFullQuality(t,e,i=150,r,o=!1){this.documentInitializeForRendering(t);let s=this.documentGetDocumentType(t);(2===s||3===s)&&(this.log(`Setting part to ${e} for presentation/drawing`),this.documentSetPart(t,e),o||(this.setEditMode(t,0),this.log("Set edit mode to 0 (view mode) for presentation rendering")));let n=this.documentGetDocumentSize(t);if(this.log("Document size (twips):",n),0===n.width||0===n.height)throw Error("Failed to get document size");let l=0,a=0,h=n.width,d=n.height;if(0===s||1===s){let i=this.getPartPageRectangles(t);if(i){let t=this.parsePageRectangles(i)[e];t&&(l=t.x,a=t.y,h=t.width,d=t.height,this.log(`Page ${e} rectangle:`,t))}}let u=Math.round(h*i/1440),c=Math.round(d*i/1440),m=i;if(r&&(u>r||c>r)){let t=r/Math.max(u,c);u=Math.round(u*t),c=Math.round(c*t),m=Math.round(i*t),this.log(`Capped dimensions to ${u}x${c} (effective DPI: ${m})`)}console.log(`[LOK] renderPageFullQuality: ${u}x${c} at ${m} DPI from tile (${l}, ${a}) size (${h}x${d}) twips`);let g=this.documentPaintTile(t,u,c,l,a,h,d);return console.log(`[LOK] renderPageFullQuality returned ${g.length} bytes`),{data:g,width:u,height:c,dpi:m}}getTextSelection(t,e="text/plain;charset=utf-8"){if(0===t)throw Error("Invalid document pointer");if(this.useShims&&this.module._lok_documentGetTextSelection){let i=this.allocString(e),r=this.module._malloc(4);try{let e=this.module._lok_documentGetTextSelection(t,i,r);if(0===e)return null;let o=this.readString(e);return this.module._free(e),o}finally{this.module._free(i),this.module._free(r)}}return this.log("getTextSelection: shim not available"),null}setTextSelection(t,e,i,r){if(0===t)throw Error("Invalid document pointer");if(this.useShims&&this.module._lok_documentSetTextSelection){this.module._lok_documentSetTextSelection(t,e,i,r);return}this.log("setTextSelection: shim not available")}getSelectionType(t){if(0===t)throw Error("Invalid document pointer");return this.useShims&&this.module._lok_documentGetSelectionType?this.module._lok_documentGetSelectionType(t):(this.log("getSelectionType: shim not available"),0)}resetSelection(t){if(0===t)throw Error("Invalid document pointer");if(this.useShims&&this.module._lok_documentResetSelection){this.module._lok_documentResetSelection(t);return}this.log("resetSelection: shim not available")}postMouseEvent(t,e,i,r,o=1,s=1,n=0){if(0===t)throw Error("Invalid document pointer");if(this.useShims&&this.module._lok_documentPostMouseEvent){this.module._lok_documentPostMouseEvent(t,e,i,r,o,s,n);return}this.log("postMouseEvent: shim not available")}postKeyEvent(t,e,i,r){if(0===t)throw Error("Invalid document pointer");if(this.useShims&&this.module._lok_documentPostKeyEvent){this.module._lok_documentPostKeyEvent(t,e,i,r);return}this.log("postKeyEvent: shim not available")}postUnoCommand(t,e,i="{}",r=!1){if(0===t)throw Error("Invalid document pointer");if(this.useShims&&this.module._lok_documentPostUnoCommand){let o=this.allocString(e),s=this.allocString(i);try{this.module._lok_documentPostUnoCommand(t,o,s,+!!r)}finally{this.module._free(o),this.module._free(s)}return}this.log("postUnoCommand: shim not available")}getCommandValues(t,e){if(0===t)throw Error("Invalid document pointer");if(this.useShims&&this.module._lok_documentGetCommandValues){let i=this.allocString(e);try{let e=this.module._lok_documentGetCommandValues(t,i);if(0===e)return null;let r=this.readString(e);return this.module._free(e),r}finally{this.module._free(i)}}return this.log("getCommandValues: shim not available"),null}getPartPageRectangles(t){if(this.log(`getPartPageRectangles called with docPtr: ${t}`),0===t)throw Error("Invalid document pointer");if(this.useShims&&this.module._lok_documentGetPartPageRectangles){this.log("getPartPageRectangles: using shim");let e=this.module._lok_documentGetPartPageRectangles(t);if(this.log(`getPartPageRectangles: resultPtr=${e}`),0===e)return null;let i=this.readString(e);return this.log(`getPartPageRectangles: result="${i?.slice(0,100)}..."`),this.module._free(e),i}return this.log("getPartPageRectangles: shim not available"),null}getPartInfo(t,e){if(0===t)throw Error("Invalid document pointer");if(this.useShims&&this.module._lok_documentGetPartInfo){let i=this.module._lok_documentGetPartInfo(t,e);if(0===i)return null;let r=this.readString(i);return this.module._free(i),r}return this.log("getPartInfo: shim not available"),null}getPartName(t,e){if(0===t)throw Error("Invalid document pointer");if(this.useShims&&this.module._lok_documentGetPartName){let i=this.module._lok_documentGetPartName(t,e);if(0===i)return null;let r=this.readString(i);return this.module._free(i),r}return this.log("getPartName: shim not available"),null}paste(t,e,i){if(0===t)throw Error("Invalid document pointer");if(this.useShims&&this.module._lok_documentPaste){let r=this.allocString(e),o,s;if("string"==typeof i){let t=new TextEncoder().encode(i);s=t.length,o=this.module._malloc(s),this.HEAPU8.set(t,o)}else s=i.length,o=this.module._malloc(s),this.HEAPU8.set(i,o);try{return 0!==this.module._lok_documentPaste(t,r,o,s)}finally{this.module._free(r),this.module._free(o)}}return this.log("paste: shim not available"),!1}setClientZoom(t,e,i,r,o){if(0===t)throw Error("Invalid document pointer");if(this.useShims&&this.module._lok_documentSetClientZoom){this.module._lok_documentSetClientZoom(t,e,i,r,o);return}this.log("setClientZoom: shim not available")}
1setClientVisibleArea(t,e,i,r,o){if(0===t)throw Error("Invalid document pointer");if(this.useShims&&this.module._lok_documentSetClientVisibleArea){this.module._lok_documentSetClientVisibleArea(t,e,i,r,o);return}this.log("setClientVisibleArea: shim not available")}getA11yFocusedParagraph(t){if(0===t)throw Error("Invalid document pointer");if(this.useShims&&this.module._lok_documentGetA11yFocusedParagraph){let e=this.module._lok_documentGetA11yFocusedParagraph(t);if(0===e)return null;let i=this.readString(e);return this.module._free(e),i}return this.log("getA11yFocusedParagraph: shim not available"),null}getA11yCaretPosition(t){if(0===t)throw Error("Invalid document pointer");return this.useShims&&this.module._lok_documentGetA11yCaretPosition?this.module._lok_documentGetA11yCaretPosition(t):(this.log("getA11yCaretPosition: shim not available"),-1)}setAccessibilityState(t,e,i){if(0===t)throw Error("Invalid document pointer");if(this.useShims&&this.module._lok_documentSetAccessibilityState){this.module._lok_documentSetAccessibilityState(t,e,+!!i);return}this.log("setAccessibilityState: shim not available")}getDataArea(t,e){if(0===t)throw Error("Invalid document pointer");if(this.useShims&&this.module._lok_documentGetDataArea){let i=this.module._malloc(8),r=this.module._malloc(8);try{this.module._lok_documentGetDataArea(t,e,i,r);let o=this.HEAP32[i>>2]??0,s=this.HEAP32[r>>2]??0;return{col:o,row:s}}finally{this.module._free(i),this.module._free(r)}}return this.log("getDataArea: shim not available"),{col:0,row:0}}getEditMode(t){if(0===t)throw Error("Invalid document pointer");return this.useShims&&this.module._lok_documentGetEditMode?this.module._lok_documentGetEditMode(t):(this.log("getEditMode: shim not available"),0)}setEditMode(t,e){if(0===t)throw Error("Invalid document pointer");if(this.useShims&&this.module._lok_documentSetEditMode){this.log(`setEditMode: setting mode to ${e}`),this.module._lok_documentSetEditMode(t,e);return}this.log("setEditMode: shim not available")}createView(t){if(0===t)throw Error("Invalid document pointer");if(this.useShims&&this.module._lok_documentCreateView){let e=this.module._lok_documentCreateView(t);return this.log(`createView: created view ${e}`),e}return this.log("createView: shim not available"),-1}createViewWithOptions(t,e){if(0===t)throw Error("Invalid document pointer");if(this.useShims&&this.module._lok_documentCreateViewWithOptions){let i=this.allocString(e);try{let e=this.module._lok_documentCreateViewWithOptions(t,i);return this.log(`createViewWithOptions: created view ${e}`),e}finally{this.module._free(i)}}return this.log("createViewWithOptions: shim not available"),-1}destroyView(t,e){if(0===t)throw Error("Invalid document pointer");if(this.useShims&&this.module._lok_documentDestroyView){this.log(`destroyView: destroying view ${e}`),this.module._lok_documentDestroyView(t,e);return}this.log("destroyView: shim not available")}setView(t,e){if(0===t)throw Error("Invalid document pointer");if(this.useShims&&this.module._lok_documentSetView){this.log(`setView: setting active view to ${e}`),this.module._lok_documentSetView(t,e);return}this.log("setView: shim not available")}getView(t){if(0===t)throw Error("Invalid document pointer");return this.useShims&&this.module._lok_documentGetView?this.module._lok_documentGetView(t):(this.log("getView: shim not available"),-1)}getViewsCount(t){if(0===t)throw Error("Invalid document pointer");return this.useShims&&this.module._lok_documentGetViewsCount?this.module._lok_documentGetViewsCount(t):(this.log("getViewsCount: shim not available"),0)}enableSyncEvents(){this.useShims&&this.module._lok_enableSyncEvents?(this.module._lok_enableSyncEvents(),this.log("enableSyncEvents: Unipoll mode enabled")):this.log("enableSyncEvents: shim not available")}disableSyncEvents(){this.useShims&&this.module._lok_disableSyncEvents?(this.module._lok_disableSyncEvents(),this.log("disableSyncEvents: Unipoll mode disabled")):this.log("disableSyncEvents: shim not available")}registerCallback(t){if(0===t)throw Error("Invalid document pointer");this.useShims&&this.module._lok_documentRegisterCallback?(this.module._lok_documentRegisterCallback(t),this.log("registerCallback: callback registered")):this.log("registerCallback: shim not available")}unregisterCallback(t){if(0===t)throw Error("Invalid document pointer");this.useShims&&this.module._lok_documentUnregisterCallback?(this.module._lok_documentUnregisterCallback(t),this.log("unregisterCallback: callback unregistered")):this.log("unregisterCallback: shim not available")}hasCallbackEvents(){return!!this.useShims&&!!this.module._lok_hasCallbackEvents&&0!==this.module._lok_hasCallbackEvents()}getCallbackEventCount(){return this.useShims&&this.module._lok_getCallbackEventCount?this.module._lok_getCallbackEventCount():0}pollCallback(){if(!this.useShims||!this.module._lok_pollCallback)return null;let t=this.module._malloc(4096),e=this.module._malloc(4);try{let i=this.module._lok_pollCallback(t,4096,e);if(-1===i)return null;let r=this.module.HEAP32[e>>2]??0,o="";if(r>0){let e=Math.min(r,4095),i=this.module.HEAPU8.slice(t,t+e);o=S.decode(i)}return{type:i,typeName:({0:"INVALIDATE_TILES",1:"INVALIDATE_VISIBLE_CURSOR",2:"TEXT_SELECTION",3:"TEXT_SELECTION_START",4:"TEXT_SELECTION_END",5:"CURSOR_VISIBLE",6:"GRAPHIC_SELECTION",7:"HYPERLINK_CLICKED",8:"STATE_CHANGED",9:"STATUS_INDICATOR_START",10:"STATUS_INDICATOR_SET_VALUE",11:"STATUS_INDICATOR_FINISH",12:"SEARCH_NOT_FOUND",13:"DOCUMENT_SIZE_CHANGED",14:"SET_PART",15:"SEARCH_RESULT_SELECTION",16:"UNO_COMMAND_RESULT",17:"CELL_CURSOR",18:"MOUSE_POINTER",19:"CELL_FORMULA",20:"DOCUMENT_PASSWORD",21:"DOCUMENT_PASSWORD_TO_MODIFY",22:"CONTEXT_MENU",23:"INVALIDATE_VIEW_CURSOR",24:"TEXT_VIEW_SELECTION",25:"CELL_VIEW_CURSOR",26:"GRAPHIC_VIEW_SELECTION",27:"VIEW_CURSOR_VISIBLE",28:"VIEW_LOCK",29:"REDLINE_TABLE_SIZE_CHANGED",30:"REDLINE_TABLE_ENTRY_MODIFIED",31:"COMMENT",32:"INVALIDATE_HEADER",33:"CELL_ADDRESS"})[i]||`UNKNOWN(${i})`,payload:o}}finally{this.module._free(t),this.module._free(e)}}pollAllCallbacks(){let t=[],e=this.pollCallback();for(;null!==e;)t.push(e),e=this.pollCallback();return t}clearCallbackQueue(){this.useShims&&this.module._lok_clearCallbackQueue&&(this.module._lok_clearCallbackQueue(),this.log("clearCallbackQueue: queue cleared"))}flushCallbacks(t){if(0===t)throw Error("Invalid document pointer");let e=!!this.module._lok_flushCallbacks;this.log(`flushCallbacks: useShims=${this.useShims}, _lok_flushCallbacks exists=${e}`),this.useShims&&this.module._lok_flushCallbacks?(this.module._lok_flushCallbacks(t),this.log("flushCallbacks: callbacks flushed")):this.log("flushCallbacks: shim not available")}pollStateChanges(){let t=new Map;for(let e of this.pollAllCallbacks())if(8===e.type){let i=e.payload.indexOf("=");if(-1!==i){let r=e.payload.substring(0,i),o=e.payload.substring(i+1);t.set(r,o)}else t.set(e.payload,"")}return t}clickAndGetText(t,e,i){return this.postMouseEvent(t,0,e,i,1,1,0),this.postMouseEvent(t,1,e,i,1,1,0),this.getTextSelection(t,"text/plain;charset=utf-8")}
1doubleClickAndGetWord(t,e,i){return this.postMouseEvent(t,0,e,i,2,1,0),this.postMouseEvent(t,1,e,i,2,1,0),this.getTextSelection(t,"text/plain;charset=utf-8")}selectAll(t){this.postUnoCommand(t,".uno:SelectAll")}getAllText(t){this.log(`getAllText called with docPtr: ${t}`),this.selectAll(t);let e=this.getTextSelection(t,"text/plain;charset=utf-8");return this.log(`getAllText: text="${e?.slice(0,100)}..."`),this.resetSelection(t),e}parsePageRectangles(t){return t?t.split(";").filter(t=>t.trim()).map(t=>{let e=t.split(",").map(Number);return{x:e[0]??0,y:e[1]??0,width:e[2]??0,height:e[3]??0}}):[]}},y=class{worker=null;initialized=!1;initializing=!1;messageId=0;pendingRequests=new Map;options;constructor(t={}){let e=r();this.options={verbose:!1,browserWorkerJs:"/dist/browser.worker.global.js",...e,...t}}async initialize(){if(!this.initialized){if(this.initializing){for(;this.initializing;)await new Promise(t=>setTimeout(t,100));return}this.initializing=!0,this.emitProgress("loading",0,"Starting worker...");try{this.worker=new Worker(this.options.browserWorkerJs),this.worker.onmessage=t=>this.handleWorkerMessage(t),this.worker.onerror=t=>{console.error("[WorkerConverter] Worker error:",t),this.options.onError?.(new s("WASM_NOT_INITIALIZED",t.message))},await new Promise((t,e)=>{let i=setTimeout(()=>e(Error("Worker load timeout")),1e4),r=e=>{"loaded"===e.data.type&&(clearTimeout(i),this.worker?.removeEventListener("message",r),t())};this.worker.addEventListener("message",r)}),await this.sendMessage("init",{sofficeJs:this.options.sofficeJs,sofficeWasm:this.options.sofficeWasm,sofficeData:this.options.sofficeData,sofficeWorkerJs:this.options.sofficeWorkerJs,enableProgressTracking:this.options.enableProgressTracking,verbose:this.options.verbose}),this.initialized=!0,this.emitProgress("complete",100,"Ready"),this.options.onReady?.()}catch(e){let t=e instanceof s?e:new s("WASM_NOT_INITIALIZED",String(e));throw this.options.onError?.(t),t}finally{this.initializing=!1}}}handleWorkerMessage(t){let e=t.data;if("progress"===e.type){let t=e.progress;t&&this.emitProgress("converting",t.percent,t.message);return}let i=this.pendingRequests.get(e.id);i&&(this.pendingRequests.delete(e.id),"error"===e.type?i.reject(new s("CONVERSION_FAILED",e.error??"Unknown error")):"result"===e.type?i.resolve(e.data):"ready"===e.type?i.resolve(void 0):"pageCount"===e.type?i.resolve(e.pageCount):"previews"===e.type?i.resolve(e.previews):"singlePagePreview"===e.type||"fullQualityPagePreview"===e.type?i.resolve(e.preview):"documentInfo"===e.type?i.resolve(e.documentInfo):"lokInfo"===e.type?i.resolve(e.lokInfo):"editResult"===e.type?i.resolve(e.editResult):"pageRectangles"===e.type?i.resolve(e.pageRectangles):"testLokOperations"===e.type?i.resolve(e.testLokOperationsResult):"editorSession"===e.type?i.resolve(e.editorSession):"editorOperationResult"===e.type?i.resolve(e.editorOperationResult):"documentClosed"===e.type&&i.resolve(e.data))}sendMessage(t,e={}){return new Promise((i,r)=>{if(!this.worker){r(Error("Worker not initialized"));return}let o=++this.messageId;if(this.pendingRequests.set(o,{resolve:i,reject:r}),e.inputData instanceof Uint8Array){let i=new Uint8Array(e.inputData.length);i.set(e.inputData);let r={type:t,id:o,...e,inputData:i};this.worker.postMessage(r,[i.buffer])}else{let i={type:t,id:o,...e};this.worker.postMessage(i)}})}async convert(t,e,i="document"){if(!this.initialized||!this.worker)throw new s("WASM_NOT_INITIALIZED","Not initialized");let r=Date.now(),o=t instanceof Uint8Array?t:new Uint8Array(t);if(0===o.length)throw new s("INVALID_INPUT","Empty document");let a=this.getExt(i)||e.inputFormat||"docx",h=e.outputFormat;if(!n[h])throw new s("UNSUPPORTED_FORMAT",`Unsupported: ${h}`);let d="";if("pdf"===h&&e.pdf){let t=[];e.pdf.pdfaLevel&&t.push(`SelectPdfVersion=${{"PDF/A-1b":1,"PDF/A-2b":2,"PDF/A-3b":3}[e.pdf.pdfaLevel]||0}`),void 0!==e.pdf.quality&&t.push(`Quality=${e.pdf.quality}`),d=t.join(",")}let u=await this.sendMessage("convert",{inputData:o,inputExt:a,outputFormat:h,filterOptions:d,password:e.password}),c=i.includes(".")?i.substring(0,i.lastIndexOf(".")):i,m=u.length>=2&&80===u[0]&&75===u[1],g=["png","jpg","jpeg","svg"].includes(h.toLowerCase());return m&&g?{data:u,mimeType:"application/zip",filename:`${c}_pages.zip`,duration:Date.now()-r}:{data:u,mimeType:l[h],filename:`${c}.${h}`,duration:Date.now()-r}}async convertFile(t,e){let i=await t.arrayBuffer();return this.convert(new Uint8Array(i),e,t.name)}async convertFromUrl(t,e){let i=await fetch(t);if(!i.ok)throw Error(`Fetch failed: ${i.statusText}`);let r=await i.arrayBuffer(),o=t.split("/").pop()||"document";return this.convert(new Uint8Array(r),e,o)}download(t,e){let i=new Blob([new Uint8Array(t.data).buffer],{type:t.mimeType}),r=URL.createObjectURL(i),o=document.createElement("a");o.href=r,o.download=e||t.filename,o.click(),setTimeout(()=>URL.revokeObjectURL(r),1e3)}createBlobUrl(t){let e=new Blob([new Uint8Array(t.data).buffer],{type:t.mimeType});return URL.createObjectURL(e)}preview(t){return window.open(this.createBlobUrl(t),"_blank")}async getPageCount(t,e){if(!this.initialized||!this.worker)throw new s("WASM_NOT_INITIALIZED","Not initialized");let i=t instanceof Uint8Array?t:new Uint8Array(t),r=e.inputFormat||"docx";return await this.sendMessage("getPageCount",{inputData:i,inputExt:r})}
1async renderPreviews(t,e,i=256){if(!this.initialized||!this.worker)throw new s("WASM_NOT_INITIALIZED","Not initialized");let r=t instanceof Uint8Array?t:new Uint8Array(t),o=e.inputFormat||"docx";return await this.sendMessage("renderPreviews",{inputData:r,inputExt:o,maxWidth:i})}async renderSinglePage(t,e,i,r=256){if(!this.initialized||!this.worker)throw new s("WASM_NOT_INITIALIZED","Not initialized");let o=t instanceof Uint8Array?t:new Uint8Array(t),n=e.inputFormat||"docx";return await this.sendMessage("renderSinglePage",{inputData:o,inputExt:n,pageIndex:i,maxWidth:r})}async renderPageViaConvert(t,e,i,r=256){if(!this.initialized||!this.worker)throw new s("WASM_NOT_INITIALIZED","Not initialized");let o=t instanceof Uint8Array?t:new Uint8Array(t),n=e.inputFormat||"pdf";return await this.sendMessage("renderPageViaConvert",{inputData:o,inputExt:n,pageIndex:i,maxWidth:r})}async getDocumentInfo(t,e){if(!this.initialized||!this.worker)throw new s("WASM_NOT_INITIALIZED","Not initialized");let i=t instanceof Uint8Array?t:new Uint8Array(t),r=e.inputFormat||"docx";return await this.sendMessage("getDocumentInfo",{inputData:i,inputExt:r})}async getLokInfo(t,e){if(!this.initialized||!this.worker)throw new s("WASM_NOT_INITIALIZED","Not initialized");let i=t instanceof Uint8Array?t:new Uint8Array(t),r=e.inputFormat||"docx";return await this.sendMessage("getLokInfo",{inputData:i,inputExt:r})}async renderPageRectangles(t,e,i=256){if(!this.initialized||!this.worker)throw new s("WASM_NOT_INITIALIZED","Not initialized");let r=t instanceof Uint8Array?t:new Uint8Array(t),o=e.inputFormat||"docx";return await this.sendMessage("renderPageRectangles",{inputData:r,inputExt:o,maxWidth:i})}async editText(t,e,i){if(!this.initialized||!this.worker)throw new s("WASM_NOT_INITIALIZED","Not initialized");let r=t instanceof Uint8Array?t:new Uint8Array(t),o=e.inputFormat||"docx";return await this.sendMessage("editText",{inputData:r,inputExt:o,findText:i.findText,replaceText:i.replaceText,insertText:i.insertText})}async testLokOperations(t,e){if(!this.initialized||!this.worker)throw new s("WASM_NOT_INITIALIZED","Not initialized");let i=t instanceof Uint8Array?t:new Uint8Array(t),r=e.inputFormat||"docx";return await this.sendMessage("testLokOperations",{inputData:i,inputExt:r})}async openDocument(t,e){if(!this.initialized||!this.worker)throw new s("WASM_NOT_INITIALIZED","Not initialized");let i=t instanceof Uint8Array?t:new Uint8Array(t),r=e.inputFormat||"docx",o=await this.sendMessage("openDocument",{inputData:i,inputExt:r});return new _(this,o.sessionId,o.documentType,o.pageCount)}async _sendEditorOperation(t,e,i=[]){return await this.sendMessage("editorOperation",{sessionId:t,editorMethod:e,editorArgs:i})}async _closeDocument(t){return await this.sendMessage("closeDocument",{sessionId:t})}async renderPage(t,e,i,r,o){return this.renderSinglePage(t,e,i,r)}async renderPagePreviews(t,e,i){let r=i?.width??256;return this.renderPreviews(t,e,r)}async renderPageFullQuality(t,e,i,r){if(!this.initialized||!this.worker)throw new s("WASM_NOT_INITIALIZED","Not initialized");let o=t instanceof Uint8Array?t:new Uint8Array(t),n=e.inputFormat||"docx";return await this.sendMessage("renderPageFullQuality",{inputData:o,inputExt:n,pageIndex:i,dpi:r?.dpi??150,maxDimension:r?.maxDimension,editMode:r?.editMode??!1})}async editorOperation(t,e,i){return await this._sendEditorOperation(t,e,i??[])}async closeDocument(t){return this._closeDocument(t)}async destroy(){if(this.worker){try{await this.sendMessage("destroy")}catch{}this.worker.terminate(),this.worker=null}this.initialized=!1,this.pendingRequests.clear()}isReady(){return this.initialized&&null!==this.worker}static getSupportedOutputFormats(){return Object.keys(n)}getExt(t){let e=t.split(".");return e.length>1&&e.pop()?.toLowerCase()||null}emitProgress(t,e,i){this.options.onProgress?.({phase:t,percent:e,message:i})}},_=class{converter;_sessionId;_documentType;_pageCount;_closed=!1;constructor(t,e,i,r){this.converter=t,this._sessionId=e,this._documentType=i,this._pageCount=r}get sessionId(){return this._sessionId}get documentType(){return this._documentType}get pageCount(){return this._pageCount}get isOpen(){return!this._closed}async getStructure(){return this.assertOpen(),this.converter._sendEditorOperation(this._sessionId,"getStructure")}
1async undo(){return this.assertOpen(),this.converter._sendEditorOperation(this._sessionId,"undo")}async redo(){return this.assertOpen(),this.converter._sendEditorOperation(this._sessionId,"redo")}async find(t,e){return this.assertOpen(),this.converter._sendEditorOperation(this._sessionId,"find",[t,e])}async findAndReplaceAll(t,e,i){return this.assertOpen(),this.converter._sendEditorOperation(this._sessionId,"findAndReplaceAll",[t,e,i])}async getSelection(){return this.assertOpen(),this.converter._sendEditorOperation(this._sessionId,"getSelection")}async clearSelection(){return this.assertOpen(),this.converter._sendEditorOperation(this._sessionId,"clearSelection")}async getStateChanges(){return this.assertOpen(),this.converter._sendEditorOperation(this._sessionId,"getStateChanges")}async flushAndPollState(){return this.assertOpen(),this.converter._sendEditorOperation(this._sessionId,"flushAndPollState")}async getFormat(){return this.assertOpen(),this.converter._sendEditorOperation(this._sessionId,"getFormat")}async getSelectionFormat(){return this.assertOpen(),this.converter._sendEditorOperation(this._sessionId,"getSelectionFormat")}async getParagraph(t){return this.assertOpen(),this.converter._sendEditorOperation(this._sessionId,"getParagraph",[t])}async getParagraphs(t,e){return this.assertOpen(),this.converter._sendEditorOperation(this._sessionId,"getParagraphs",[t,e])}async insertParagraph(t,e){return this.assertOpen(),this.converter._sendEditorOperation(this._sessionId,"insertParagraph",[t,e])}async replaceParagraph(t,e){return this.assertOpen(),this.converter._sendEditorOperation(this._sessionId,"replaceParagraph",[t,e])}async deleteParagraph(t){return this.assertOpen(),this.converter._sendEditorOperation(this._sessionId,"deleteParagraph",[t])}async formatText(t,e){return this.assertOpen(),this.converter._sendEditorOperation(this._sessionId,"formatText",[t,e])}async replaceText(t,e,i){return this.assertOpen(),this.converter._sendEditorOperation(this._sessionId,"replaceText",[t,e,i])}async close(){return this.assertOpen(),this._closed=!0,this.converter._closeDocument(this._sessionId)}assertOpen(){if(this._closed)throw Error("Document session is closed")}}}}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.