"use strict";var B=Object.create;var C=Object.defineProperty;var L=Object.getOwnPropertyDescriptor;var D=Object.getOwnPropertyNames;var P=Object.getPrototypeOf,S=Object.prototype.hasOwnProperty;var I=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of D(t))!S.call(e,i)&&i!==n&&C(e,i,{get:()=>t[i],enumerable:!(r=L(t,i))||r.enumerable});return e};var T=(e,t,n)=>(n=e!=null?B(P(e)):{},I(t||!e||!e.__esModule?C(n,"default",{value:e,enumerable:!0}):n,e));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const h=require("@blocknote/core"),o=require("docx");async function k(e){if(typeof window<"u"){const t=await createImageBitmap(e),{width:n,height:r}=t;return t.close(),{width:n,height:r}}else{const t=(await import("image-meta")).imageMeta,n=new Uint8Array(await e.arrayBuffer()),r=t(n);if(!r.width||!r.height)throw new Error("Image dimensions not found");return{width:r.width,height:r.height}}}const F=(e,t)=>{const r=new Array(e.headerRows??0).fill(!0),i=new Array(e.headerCols??0).fill(!0);return new o.Table({layout:"autofit",columnWidths:e.columnWidths.map(a=>(a??120)*.75*20),rows:e.rows.map((a,s)=>{const u=r[s];return new o.TableRow({tableHeader:u,children:a.cells.map((p,y)=>{var b;const x=(b=e.columnWidths)==null?void 0:b[y],l=h.mapTableCell(p),v=i[y];return new o.TableCell({width:x?{size:x*.75*20,type:"dxa"}:void 0,columnSpan:l.props.colspan,rowSpan:l.props.rowspan,shading:l.props.backgroundColor==="default"||!l.props.backgroundColor?void 0:{type:o.ShadingType.SOLID,color:(()=>{var f;const d=(f=t.options.colors[l.props.backgroundColor])==null?void 0:f.background;if(d)return d.slice(1)})()},children:[new o.Paragraph({children:t.transformInlineContent(l.content),alignment:!l.props.textAlignment||l.props.textAlignment==="left"?void 0:l.props.textAlignment==="center"?"center":l.props.textAlignment==="right"?"right":l.props.textAlignment==="justify"?"distribute":(()=>{throw new h.UnreachableCaseError(l.props.textAlignment)})(),run:{bold:u||v,color:l.props.textColor==="default"||!l.props.textColor?void 0:(()=>{var f;const d=(f=t.options.colors[l.props.textColor])==null?void 0:f.text;if(d)return d.slice(1)})()}})]})})})})})};function c(e,t){return{shading:e.backgroundColor==="default"||!e.backgroundColor?void 0:{type:o.ShadingType.CLEAR,fill:(()=>{var r;const n=(r=t[e.backgroundColor])==null?void 0:r.background;if(n)return n.slice(1)})()},run:e.textColor==="default"||!e.textColor?void 0:{color:(()=>{var r;const n=(r=t[e.textColor])==null?void 0:r.text;if(n)return n.slice(1)})()},alignment:!e.textAlignment||e.textAlignment==="left"?void 0:e.textAlignment==="center"?"center":e.textAlignment==="right"?"right":e.textAlignment==="justify"?"distribute":(()=>{throw new h.UnreachableCaseError(e.textAlignment)})()}}const O={paragraph:(e,t)=>new o.Paragraph({...c(e.props,t.options.colors),children:t.transformInlineContent(e.content)}),toggleListItem:(e,t)=>new o.Paragraph({...c(e.props,t.options.colors),children:[new o.TextRun({children:["> "]}),...t.transformInlineContent(e.content)]}),numberedListItem:(e,t,n)=>new o.Paragraph({...c(e.props,t.options.colors),children:t.transformInlineContent(e.content),numbering:{reference:"blocknote-numbered-list",level:n}}),bulletListItem:(e,t,n)=>new o.Paragraph({...c(e.props,t.options.colors),children:t.transformInlineContent(e.content),numbering:{reference:"blocknote-bullet-list",level:n}}),checkListItem:(e,t)=>new o.Paragraph({...c(e.props,t.options.colors),children:[new o.CheckBox({checked:e.props.checked}),new o.TextRun({children:[" "]}),...t.transformInlineContent(e.content)]}),heading:(e,t)=>new o.Paragraph({...c(e.props,t.options.colors),children:t.transformInlineContent(e.content),heading:`Heading${e.props.level}`}),quote:(e,t)=>new o.Paragraph({style:"BlockQuote",...c(e.props,t.options.colors),children:t.transformInlineContent(e.content)}),audio:(e,t)=>[w(e.props,"Open audio",t),...g(e.props,t)],video:(e,t)=>[w(e.props,"Open video",t),...g(e.props,t)],file:(e,t)=>[w(e.props,"Open file",t),...g(e.props,t)],codeBlock:e=>{var n;const t=((n=e.content[0])==null?void 0:n.text)||"";return new o.Paragraph({style:"SourceCode",children:[...t.split(`
`).map((r,i)=>new o.TextRun({text:r,break:i>0?1:0}))]})},pageBreak:()=>new o.Paragraph({children:[new o.PageBreak]}),divider:()=>new o.Paragraph({border:{top:{color:"auto",space:1,style:"single",size:1}}}),column:(e,t,n,r,i)=>new o.TableCell({width:{size:`${e.props.width*100}%`,type:"pct"},children:(i||[]).flatMap(a=>Array.isArray(a)?a:[a])}),columnList:(e,t,n,r,i)=>new o.Table({layout:"autofit",borders:{bottom:{style:"nil"},top:{style:"nil"},left:{style:"nil"},right:{style:"nil"},insideHorizontal:{style:"nil"},insideVertical:{style:"nil"}},rows:[new o.TableRow({children:i.map((a,s,u)=>{var p;return new o.TableCell({width:{size:`${parseFloat(`${((p=a.options.width)==null?void 0:p.size)||"100%"}`)/(u.length*100)*100}%`,type:"pct"},children:a.options.children})})})]}),image:async(e,t)=>{const n=await t.resolveFile(e.props.url),{width:r,height:i}=await k(n);return[new o.Paragraph({...c(e.props,t.options.colors),children:[new o.ImageRun({data:await n.arrayBuffer(),type:"gif",altText:e.props.caption?{description:e.props.caption,name:e.props.caption,title:e.props.caption}:void 0,transformation:{width:e.props.previewWidth||r,height:(e.props.previewWidth||r)/r*i}})]}),...g(e.props,t)]},table:(e,t)=>F(e.content,t)};function w(e,t,n){return new o.Paragraph({...c(e,n.options.colors),children:[new o.ExternalHyperlink({children:[new o.TextRun({text:e.name||t,style:"Hyperlink"})],link:e.url})]})}function g(e,t){return e.caption?[new o.Paragraph({...c(e,t.options.colors),children:[new o.TextRun({text:e.caption})],style:"Caption"})]:[]}const R={link:(e,t)=>new o.ExternalHyperlink({children:e.content.map(n=>t.transformStyledText(n,!0)),link:e.href}),text:(e,t)=>t.transformStyledText(e)},E={bold:e=>e?{bold:e}:{},italic:e=>e?{italics:e}:{},underline:e=>e?{underline:{type:"single"}}:{},strike:e=>e?{strike:e}:{},backgroundColor:(e,t)=>{var r;if(!e)return{};const n=(r=t.options.colors[e])==null?void 0:r.background;return n?{shading:{type:o.ShadingType.CLEAR,fill:n.slice(1)}}:{}},textColor:(e,t)=>{var r;if(!e)return{};const n=(r=t.options.colors[e])==null?void 0:r.text;return n?{color:n.slice(1)}:{}},code:e=>e?{style:"VerbatimChar"}:{}},_={blockMapping:O,inlineContentMapping:R,styleMapping:E};async function M(e){return"https://corsproxy.api.blocknotejs.org/corsproxy/?url="+encodeURIComponent(e)}async function A(e){{const t=e.default;return await(await fetch(t)).arrayBuffer()}}const m=16*.75*1.5*20;class U extends h.Exporter{constructor(t,n,r){const a={...{colors:h.COLORS_DEFAULT,resolveFileUrl:M},...r};super(t,n,a),this.schema=t,this.mappings=n}transformStyledText(t,n){const r=this.mapStyles(t.styles),i=Object.assign({},...r);return new o.TextRun({...i,style:n?"Hyperlink":i.style,text:t.text})}async transformBlocks(t,n=0){const r=[];for(const i of t){let a=await this.transformBlocks(i.children,n+1);["columnList","column"].includes(i.type)||(a=a.map((u,p)=>(u instanceof o.Paragraph&&!u.properties.numberingReferences.length&&u.addRunToFront(new o.TextRun({children:[new o.Tab]})),u)));const s=await this.mapBlock(i,n,0,a);["columnList","column"].includes(i.type)?r.push(s):Array.isArray(s)?r.push(...s,...a):r.push(s,...a)}return r}async getFonts(){let t=await A(await Promise.resolve().then(()=>require("./Inter_18pt-Regular-CCMUw8TC.cjs"))),n=await A(await Promise.resolve().then(()=>require("./GeistMono-Regular--NrcstcO.cjs")));if(t instanceof ArrayBuffer||n instanceof ArrayBuffer){const r=(await Promise.resolve().then(()=>require("./index-B-FmPo2r.cjs")).then(i=>i.index)).Buffer;t instanceof ArrayBuffer&&(t=r.from(t)),n instanceof ArrayBuffer&&(n=r.from(n))}return[{name:"Inter",data:t},{name:"GeistMono",data:n}]}async createDefaultDocumentOptions(t){let n=(await Promise.resolve().then(()=>require("./styles-BRTtNJM0.cjs"))).default;const r=t&&t.trim()||"en-US";n=n.replace(/(<w:lang\b[^>]*\bw:val=")([^"]+)("[^>]*\/>)/g,`$1${r}$3`);const i=["•"];return{numbering:{config:[{reference:"blocknote-numbered-list",levels:Array.from({length:9},(a,s)=>({start:1,level:s,format:o.LevelFormat.DECIMAL,text:`%${s+1}.`,alignment:o.AlignmentType.LEFT,style:{paragraph:{indent:{left:m*(s+1),hanging:m}}}}))},{reference:"blocknote-bullet-list",levels:Array.from({length:9},(a,s)=>({start:1,level:s,format:o.LevelFormat.BULLET,text:i[s%i.length],alignment:o.AlignmentType.LEFT,style:{paragraph:{indent:{left:m*(s+1),hanging:m}}}}))}]},fonts:await this.getFonts(),defaultTabStop:200,externalStyles:n}}async toBlob(t,n={sectionOptions:{},documentOptions:{}}){const r=await this.toDocxJsDocument(t,n),i=globalThis.Buffer;try{return globalThis.Buffer||(globalThis.Buffer=(await import("buffer")).default.Buffer),o.Packer.toBlob(r)}finally{globalThis.Buffer=i}}async toDocxJsDocument(t,n={sectionOptions:{},documentOptions:{}}){return new o.Document({...await this.createDefaultDocumentOptions(n.locale),...n.documentOptions,sections:[{children:await this.transformBlocks(t),...n.sectionOptions}]})}}exports.DOCXExporter=U;exports.docxDefaultSchemaMappings=_;
//# sourceMappingURL=blocknote-xl-docx-exporter.cjs.map
