"use strict";var A=Object.create;var x=Object.defineProperty;var B=Object.getOwnPropertyDescriptor;var D=Object.getOwnPropertyNames;var v=Object.getPrototypeOf,S=Object.prototype.hasOwnProperty;var O=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of D(t))!S.call(e,i)&&i!==n&&x(e,i,{get:()=>t[i],enumerable:!(r=B(t,i))||r.enumerable});return e};var b=(e,t,n)=>(n=e!=null?A(v(e)):{},O(t||!e||!e.__esModule?x(n,"default",{value:e,enumerable:!0}):n,e));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const p=require("@blocknote/core"),o=require("docx");async function I(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 P=(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(s=>(s??120)*.75*20),rows:e.rows.map((s,u)=>{const c=r[u];return new o.TableRow({tableHeader:c,children:s.cells.map((g,m)=>{var y;const w=(y=e.columnWidths)==null?void 0:y[m],a=p.mapTableCell(g),T=i[m];return new o.TableCell({width:w?{size:`${w*.75}pt`,type:"dxa"}:void 0,columnSpan:a.props.colspan,rowSpan:a.props.rowspan,shading:a.props.backgroundColor==="default"||!a.props.backgroundColor?void 0:{type:o.ShadingType.SOLID,color:t.options.colors[a.props.backgroundColor].background.slice(1)},children:[new o.Paragraph({children:t.transformInlineContent(a.content),alignment:!a.props.textAlignment||a.props.textAlignment==="left"?void 0:a.props.textAlignment==="center"?"center":a.props.textAlignment==="right"?"right":a.props.textAlignment==="justify"?"distribute":(()=>{throw new p.UnreachableCaseError(a.props.textAlignment)})(),run:{bold:c||T,color:a.props.textColor==="default"||!a.props.textColor?void 0:t.options.colors[a.props.textColor].text.slice(1)}})]})})})})})};function l(e,t){return{shading:e.backgroundColor==="default"||!e.backgroundColor?void 0:{type:o.ShadingType.SOLID,color:t[e.backgroundColor].background.slice(1)},run:e.textColor==="default"||!e.textColor?void 0:{color:t[e.textColor].text.slice(1)},alignment:!e.textAlignment||e.textAlignment==="left"?void 0:e.textAlignment==="center"?"center":e.textAlignment==="right"?"right":e.textAlignment==="justify"?"distribute":(()=>{throw new p.UnreachableCaseError(e.textAlignment)})()}}const k={paragraph:(e,t)=>new o.Paragraph({...l(e.props,t.options.colors),children:t.transformInlineContent(e.content),style:"Normal",run:{font:"Inter"}}),numberedListItem:(e,t,n)=>new o.Paragraph({...l(e.props,t.options.colors),children:t.transformInlineContent(e.content),numbering:{reference:"blocknote-numbered-list",level:n}}),bulletListItem:(e,t,n)=>new o.Paragraph({...l(e.props,t.options.colors),children:t.transformInlineContent(e.content),numbering:{reference:"blocknote-bullet-list",level:n}}),checkListItem:(e,t)=>new o.Paragraph({...l(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({...l(e.props,t.options.colors),children:t.transformInlineContent(e.content),heading:`Heading${e.props.level}`}),quote:(e,t)=>new o.Paragraph({shading:{color:"#7D797A"},border:{left:{color:"#7D797A",space:100,style:"single",size:8}},...l(e.props,t.options.colors),children:t.transformInlineContent(e.content)}),audio:(e,t)=>[h(e.props,"Open audio",t),...f(e.props,t)],video:(e,t)=>[h(e.props,"Open video",t),...f(e.props,t)],file:(e,t)=>[h(e.props,"Open file",t),...f(e.props,t)],codeBlock:e=>{var n;const t=((n=e.content[0])==null?void 0:n.text)||"";return new o.Paragraph({style:"Codeblock",shading:{type:o.ShadingType.SOLID,fill:"161616",color:"161616"},children:[...t.split(`
`).map((r,i)=>new o.TextRun({text:r,break:i>0?1:0}))]})},pageBreak:()=>new o.Paragraph({children:[new o.PageBreak]}),image:async(e,t)=>{const n=await t.resolveFile(e.props.url),{width:r,height:i}=await I(n);return[new o.Paragraph({...l(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}})]}),...f(e.props,t)]},table:(e,t)=>P(e.content,t)};function h(e,t,n){return new o.Paragraph({...l(e,n.options.colors),children:[new o.ExternalHyperlink({children:[new o.TextRun({text:e.name||t,style:"Hyperlink"})],link:e.url})]})}function f(e,t){return e.caption?[new o.Paragraph({...l(e,t.options.colors),children:[new o.TextRun({text:e.caption})],style:"Caption"})]:[]}const F={link:(e,t)=>new o.ExternalHyperlink({children:e.content.map(n=>t.transformStyledText(n,!0)),link:e.href}),text:(e,t)=>t.transformStyledText(e)},R={bold:e=>e?{bold:e}:{},italic:e=>e?{italics:e}:{},underline:e=>e?{underline:{type:"single"}}:{},strike:e=>e?{strike:e}:{},backgroundColor:(e,t)=>e?{shading:{fill:t.options.colors[e].background.slice(1)}}:{},textColor:(e,t)=>e?{color:t.options.colors[e].text.slice(1)}:{},code:e=>e?{font:"GeistMono"}:{}},L={blockMapping:k,inlineContentMapping:F,styleMapping:R};async function M(e){return"https://corsproxy.api.blocknotejs.org/corsproxy/?url="+encodeURIComponent(e)}async function C(e){{const t=e.default;return await(await fetch(t)).arrayBuffer()}}const d=16*.75*1.5*20;class E extends p.Exporter{constructor(t,n,r){const s={...{colors:p.COLORS_DEFAULT,resolveFileUrl:M},...r};super(t,n,s),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":void 0,text:t.text})}async transformBlocks(t,n=0){const r=[];for(const i of t){let s=await this.transformBlocks(i.children,n+1);s=s.map((c,g)=>(c instanceof o.Paragraph&&!c.properties.numberingReferences.length&&c.addRunToFront(new o.TextRun({children:[new o.Tab]})),c));const u=await this.mapBlock(i,n,0);Array.isArray(u)?r.push(...u,...s):r.push(u,...s)}return r}async getFonts(){let t=await C(await Promise.resolve().then(()=>require("./Inter_18pt-Regular-CCMUw8TC.cjs"))),n=await C(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(){const t=(await Promise.resolve().then(()=>require("./styles-C7c5RlKz.cjs"))).default,n=["•"];return{numbering:{config:[{reference:"blocknote-numbered-list",levels:Array.from({length:9},(r,i)=>({start:1,level:i,format:o.LevelFormat.DECIMAL,text:`%${i+1}.`,alignment:o.AlignmentType.LEFT,style:{paragraph:{indent:{left:d*(i+1),hanging:d}}}}))},{reference:"blocknote-bullet-list",levels:Array.from({length:9},(r,i)=>({start:1,level:i,format:o.LevelFormat.BULLET,text:n[i%n.length],alignment:o.AlignmentType.LEFT,style:{paragraph:{indent:{left:d*(i+1),hanging:d}}}}))}]},fonts:await this.getFonts(),defaultTabStop:200,externalStyles:t}}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:{}}){const r=new o.Document({...await this.createDefaultDocumentOptions(),...n.documentOptions,sections:[{children:await this.transformBlocks(t),...n.sectionOptions}]});return r.Document.Relationships.createRelationship(r.Document.Relationships.RelationshipCount+1,"http://schemas.openxmlformats.org/officeDocument/2006/relationships/fontTable","fontTable.xml"),r}}exports.DOCXExporter=E;exports.docxDefaultSchemaMappings=L;
//# sourceMappingURL=blocknote-xl-docx-exporter.cjs.map
