import{a as y,b as v}from"./chunk-PI6A7EIZ.js";import{d as b}from"./chunk-FSRPMVAS.js";var i=b(y(),1),l=b(v(),1);function m(e,r,t={}){return k(e,r,t).buffer}function k(e,r,t={}){let{nullGetter:n="keep",linebreaks:a=!0,delimiters:s}=t,o=[],h=[],d=[];try{let f=new i.default(e),g=new l.default(f,{paragraphLoop:!0,linebreaks:a,nullGetter:u=>{let c=u.value||"";if(n==="error")throw new Error(`Undefined variable: ${c}`);return n==="empty"?(d.push(c),""):(d.push(c),`{${c}}`)},delimiters:s?{start:s.start||"{",end:s.end||"}"}:void 0});return Object.keys(r).forEach(u=>{r[u]!==void 0&&r[u]!==null&&h.push(u)}),g.setData(r),g.render(),{buffer:g.getZip().generate({type:"arraybuffer",compression:"DEFLATE",compressionOptions:{level:6}}),replacedVariables:h,unreplacedVariables:d,warnings:o}}catch(f){throw p(f)}}function E(e,r,t={}){let n=m(e,r,t);return new Blob([n],{type:"application/vnd.openxmlformats-officedocument.wordprocessingml.document"})}function U(e,r,t="document",n={}){let a=E(e,r,n);T(a,`${t}.docx`)}function D(e){try{let r=new i.default(e),t=new l.default(r,{paragraphLoop:!0,linebreaks:!0}).getFullText();return w(t)}catch(r){throw p(r)}}function j(e){let r=[],t=[];try{let n=new i.default(e),a=new l.default(n,{paragraphLoop:!0,linebreaks:!0}).getFullText();t=w(a);let s=L(a);for(let o of s)r.push({message:`Unclosed tag: ${o}`,variable:o,type:"parse"});return{valid:r.length===0,errors:r,tags:t}}catch(n){return r.push(p(n)),{valid:!1,errors:r,tags:t}}}function F(e,r){return e.filter(t=>!(t in r)||r[t]===void 0||r[t]===null)}function O(e,r){try{let t=new i.default(e),n=new l.default(t,{paragraphLoop:!0,linebreaks:!0,nullGetter:a=>`[${a.value||""}]`});return n.setData(r),n.render(),n.getFullText()}catch(t){throw p(t)}}function w(e){let r=[],t=/\{([^{}]+)\}/g,n;for(;(n=t.exec(e))!==null;){let a=n[1].trim();a&&!r.includes(a)&&r.push(a)}return r.sort()}function L(e){let r=[],t=0,n="";for(let a of e)a==="{"?(t++,n=""):a==="}"?(t--,t<0&&(t=0)):t>0&&(n+=a);return t>0&&n.trim()&&r.push(n.trim()),r}function x(e){return"properties"in e&&typeof e.properties=="object"}function p(e){if(e instanceof Error){if(x(e)&&e.properties?.errors){let r=e.properties.errors[0];return{message:r?.message||"Template processing error",variable:r?.properties?.tag,type:"render",originalError:e}}if(e.message.includes("undefined")){let r=e.message.match(/undefined (?:variable|tag):\s*(\S+)/i);return{message:e.message,variable:r?r[1]:void 0,type:"undefined",originalError:e}}return e.message.includes("parse")||e.message.includes("unclosed")||e.message.includes("syntax")?{message:e.message,type:"parse",originalError:e}:{message:e.message,type:"unknown",originalError:e}}return{message:String(e),type:"unknown"}}function T(e,r){let t=URL.createObjectURL(e),n=document.createElement("a");n.href=t,n.download=r,document.body.appendChild(n),n.click(),document.body.removeChild(n),URL.revokeObjectURL(t)}function R(e,r,t={}){let{linebreaks:n=!0,delimiters:a}=t;try{let s=new i.default(e),o=new l.default(s,{paragraphLoop:!0,linebreaks:n,delimiters:a?{start:a.start||"{",end:a.end||"}"}:void 0});return o.setData(r),o.render(),o.getZip().generate({type:"arraybuffer",compression:"DEFLATE"})}catch(s){throw p(s)}}function $(e={}){return(r,t)=>m(r,t,e)}var G=m;export{m as a,k as b,E as c,U as d,D as e,j as f,F as g,O as h,R as i,$ as j,G as k};
