"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[4461],{94461:(e,t,r)=>{r.d(t,{exportDocsToDocx:()=>S});var n=r(72050),a=r(30640),o=r(79535);function i(e){return!!e&&"object"==typeof e&&!Array.isArray(e)}async function l(e){if(!e)return null;if(e.startsWith("data:"))return e;try{var t;let r=await fetch(e,{credentials:"include"});if(!r.ok)return null;return t=await r.blob(),new Promise((e,r)=>{let n=new FileReader;n.onload=()=>e(String(n.result)),n.onerror=r,n.readAsDataURL(t)})}catch{return null}}function s(e){let t=[];e.bold&&t.push({type:"bold"}),e.italic&&t.push({type:"italic"}),e.underline&&t.push({type:"underline"});let r={};return e.fontFamily&&(r.fontFamily=e.fontFamily),null!=e.fontSizePx&&(r.fontSize=`${e.fontSizePx}px`),e.color&&(r.color=e.color),Object.keys(r).length>0&&t.push({type:"textStyle",attrs:r}),t}function c(e,t){if("text"===e.type){let r=Array.isArray(e.marks)?e.marks:[];return{...e,marks:[...r,...t]}}return Array.isArray(e.content)?{...e,content:e.content.map(e=>c(e,t))}:e}function p(e){return Array.isArray(e.content)?e.content:[]}async function d(e,t){let r=(0,o.Oy)(e);if("image"!==r.graphicType||!r.src)return"shape"===r.graphicType||r.graphicType,null;let n=await l(r.src);if(!n)return null;let a={src:n,alt:r.alt||r.altTitle||"",width:r.width,height:r.height};return("absolute"===r.placement||"fixed-on-page"===r.positionMode)&&(a.placement="absolute",a.x=r.pageX||r.x,a.y=r.pageY||r.y,a.wrap=r.wrap,a.floatSide=r.floatSide,a.rotationDeg=r.rotationDeg),{type:"image",attrs:a}}async function m(e){let t=[],r=0,n=async e=>{let a=e.type;if("docsGraphic"===a||"docsInlineGraphic"===a){let n=i(e.attrs)?e.attrs:{},s=(0,o.Oy)(n);if(("absolute"===s.placement||"fixed-on-page"===s.positionMode||"behind"===s.wrap||"in-front"===s.wrap)&&s.src){let e=await l(s.src);return t.push({nodeIndex:r,attrs:e?{...s,src:e}:s}),r+=1,null}let c=await d(n,"docsInlineGraphic"===a);return r+=1,c}if("image"===a){let t=i(e.attrs)?{...e.attrs}:{};if("string"==typeof t.src){let e=await l(t.src);e&&(t.src=e)}return r+=1,{...e,attrs:t}}if(Array.isArray(e.content)){let t=[];for(let r of e.content){let e=await n(r);e&&t.push(e)}return{...e,content:t}}return r+=1,e};return{content:await n(e)??{type:"doc",content:[]},anchoredGraphics:t}}async function w(e,t){var r;let o,l,d=(o=e=>{if("docsPageFlowSpacer"===e.type)return null;if(!Array.isArray(e.content))return e;let t=e.content.map(e=>o(e)).filter(e=>null!=e);return{...e,content:t}})(e)??{type:"doc",content:[]};return r=d,d=d=(l=e=>{let r=e.type,a=i(e.attrs)?{...e.attrs}:void 0;if(("paragraph"===r||"heading"===r)&&a){let r="string"==typeof a.styleId?a.styleId:null;if(r){let o=(0,n.v9)(t,r);if(o){if("heading"===o.blockType&&o.level)return l({type:"heading",attrs:{level:o.level,textAlign:o.textAlign??a.textAlign},content:p(e).map(e=>c(e,s(o)))});let t={...a};delete t.styleId,o.textAlign&&(t.textAlign=o.textAlign);let r={...e,attrs:t,content:p(e).map(e=>c(e,s(o)))};return Array.isArray(r.content)&&(r={...r,content:r.content.map(e=>l(e))}),r}}}return Array.isArray(e.content)?{...e,content:e.content.map(e=>l(e))}:e})(r),m(d=(0,a.G)(d))}let f=1440/25.4;function h(e){return Math.round(e*f)}async function u(e,t){var n,a;let o,i,l,s,c,p,d,m,w,f,u,{unzipSync:g,zipSync:y}=await r.e(6951).then(r.bind(r,86951)),x={...g(new Uint8Array(e))},b="word/document.xml",$=(n=x[b])?new TextDecoder().decode(n):"";return $?(x[b]=(o=h(t.widthMm),i=h(t.heightMm),l="landscape"===t.orientation||t.widthMm>t.heightMm?' w:orient="landscape"':"",s=h(t.marginsMm.top),c=h(t.marginsMm.right),p=h(t.marginsMm.bottom),d=h(t.marginsMm.left),m=h(t.headerMarginMm??t.marginsMm.top),w=h(t.footerMarginMm??t.marginsMm.bottom),f=``,u=``,a=/]*>[\s\S]*?<\/w:sectPr>/i.test($)?$.replace(/]*>[\s\S]*?<\/w:sectPr>/i,e=>{let t=e.replace(/]*\/?>/gi,"").replace(/]*\/?>/gi,"");return t.replace("",`${f}${u}`)}):/]*\/>/i.test($)?$.replace(/]*\/>/i,`${f}${u}`):$.replace(/<\/w:body>/i,`${f}${u}`),new TextEncoder().encode(a)),y(x)):new Uint8Array(e)}function g(e){return e?new TextDecoder().decode(e):""}function y(e){return new TextEncoder().encode(e)}async function x(e){try{let{generateDOCX:t}=await Promise.all([r.e(2184),r.e(1062),r.e(8112)]).then(r.bind(r,6304)),n=(0,a.G)(e),o=await t(n,{outputType:"uint8array"}),{unzipSync:i}=await r.e(6951).then(r.bind(r,86951)),l=i(o),s=g(l["word/document.xml"]).match(/([\s\S]*?)<\/w:body>/i);if(s?.[1])return s[1].replace(//gi,"").replace(/]*\/>/gi,"")}catch{}let t=[],n=e=>{if(e&&"object"==typeof e){if("paragraph"===e.type||"heading"===e.type){let r=[],n=e=>{e&&"object"==typeof e&&("text"===e.type&&"string"==typeof e.text&&r.push(e.text.replace(/&/g,"&").replace(//g,">").replace(/"/g,""")),Array.isArray(e.content)&&e.content.forEach(n))};Array.isArray(e.content)&&e.content.forEach(n),t.push(`${r.join("")}`)}Array.isArray(e.content)&&e.content.forEach(n)}};return n(e),t.join("")}async function b(e,t,r){var n;let a;if(!e?.content)return null;let o=await x(e.content);if(r?.enabled&&r.placement===("hdr"===t?"header":"footer")){let e="center"===r.align?"center":"right"===r.align?"right":"left";o+=`1`}return o.trim()?(n=o,a="hdr"===t?"header":"footer",` ${n}`):null}function $(e,t,r,n){if(e.includes(`Id="${t}"`))return e;let a=``;return e.replace("",`${a}`)}function P(e,t,r){if(e.includes(`PartName="/${t}"`))return e;let n=``;return e.replace("",`${n}`)}async function A(e,t){var n;let a,o,{unzipSync:i,zipSync:l}=await r.e(6951).then(r.bind(r,86951)),s={...i(e)},c=await b(t.header,"hdr",t.pageNumbers),p=await b(t.footer,"ftr",t.pageNumbers),d=t.headerFooterDifferentFirstPage?await b(t.headerFirstPage,"hdr",t.pageNumbers):null,m=t.headerFooterDifferentFirstPage?await b(t.footerFirstPage,"ftr",t.pageNumbers):null;if(!c&&!p&&!d&&!m)return e;let w=g(s["word/_rels/document.xml.rels"])||'',f=g(s["[Content_Types].xml"])||'',h={};c&&(s["word/header1.xml"]=y(c),w=$(w,"rIdHeader1","http://schemas.openxmlformats.org/officeDocument/2006/relationships/header","header1.xml"),f=P(f,"word/header1.xml","application/vnd.openxmlformats-officedocument.wordprocessingml.header+xml"),h.header="rIdHeader1"),p&&(s["word/footer1.xml"]=y(p),w=$(w,"rIdFooter1","http://schemas.openxmlformats.org/officeDocument/2006/relationships/footer","footer1.xml"),f=P(f,"word/footer1.xml","application/vnd.openxmlformats-officedocument.wordprocessingml.footer+xml"),h.footer="rIdFooter1"),d&&(s["word/header2.xml"]=y(d),w=$(w,"rIdHeader2","http://schemas.openxmlformats.org/officeDocument/2006/relationships/header","header2.xml"),f=P(f,"word/header2.xml","application/vnd.openxmlformats-officedocument.wordprocessingml.header+xml"),h.headerFirst="rIdHeader2"),m&&(s["word/footer2.xml"]=y(m),w=$(w,"rIdFooter2","http://schemas.openxmlformats.org/officeDocument/2006/relationships/footer","footer2.xml"),f=P(f,"word/footer2.xml","application/vnd.openxmlformats-officedocument.wordprocessingml.footer+xml"),h.footerFirst="rIdFooter2"),s["word/_rels/document.xml.rels"]=y(w),s["[Content_Types].xml"]=y(f);let u=g(s["word/document.xml"]);return s["word/document.xml"]=y((n=!!t.headerFooterDifferentFirstPage,a=[],h.header&&a.push(``),h.footer&&a.push(``),n&&h.headerFirst&&a.push(``),n&&h.footerFirst&&a.push(``),n&&a.push(""),o=a.join(""),/]*>[\s\S]*?<\/w:sectPr>/i.test(u)?u.replace(/]*>([\s\S]*?)<\/w:sectPr>/i,(e,t)=>`${t.replace(/]*\/?>/gi,"").replace(/]*\/?>/gi,"").replace(/]*\/?>/gi,"")}${o}`):u.replace(/<\/w:body>/i,`${o}`))),l(s)}function v(e){return Math.round(9525*e)}function F(e){return e?new TextDecoder().decode(e):""}function T(e){return new TextEncoder().encode(e)}async function M(e,t){if(0===t.length)return e;let{unzipSync:n,zipSync:a}=await r.e(6951).then(r.bind(r,86951)),o={...n(e)},i=F(o["word/_rels/document.xml.rels"])||'',l=F(o["word/document.xml"]);if(!l)return e;let s=[];for(let{attrs:e}of t){if(!e.src)continue;let t=e.src.startsWith("data:")?function(e){let t=e.match(/^data:[^;]+;base64,(.+)$/);if(!t?.[1])return null;let r=atob(t[1]),n=new Uint8Array(r.length);for(let e=0;e/^word\/media\/image\d+\./i.test(e)).map(e=>Number.parseInt(e.match(/image(\d+)/i)?.[1]??"0",10)),r=t.length>0?Math.max(...t)+1:1;return`image${r}.png`}(o);o[`word/media/${r}`]=t;let n=function(e){let t=[...e.matchAll(/Id="rId(\d+)"/gi)].map(e=>Number.parseInt(e[1]??"0",10)),r=t.length>0?Math.max(...t):0;return`rId${r+1}`}(i);i=i.replace("",``),s.push(function(e,t,r){let n=v(t.width),a=v(t.height),o=v(t.pageX||t.x),i=v(t.pageY||t.y),l=6e4*t.rotationDeg,s="behind"===t.wrap?' behindDoc="1"':"",c=function(e){switch(e){case"tight":return"wrapTight";case"through":return"wrapThrough";case"top-bottom":return"wrapTopAndBottom";case"behind":case"in-front":return"wrapNone";default:return"wrapSquare"}}(t.wrap);return` ${o} ${i} `}(n,e,r))}return 0===s.length?e:(o["word/_rels/document.xml.rels"]=T(i),l=l.replace(/<\/w:body>/i,`${s.join("")}`),o["word/document.xml"]=T(l),a(o))}async function S(e){let{content:t,anchoredGraphics:n}=await w(e.body,e.paragraphStyles),{generateDOCX:a}=await Promise.all([r.e(2184),r.e(1062),r.e(8112)]).then(r.bind(r,6304)),o=await a(t,{outputType:"uint8array",title:e.title});return e.pageSetup&&(o=await u(o,e.pageSetup),o=await A(o,e.pageSetup)),n.length>0&&(o=await M(o,n)),new Blob([o],{type:"application/vnd.openxmlformats-officedocument.wordprocessingml.document"})}}}]);