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