@blocknote/xl-docx-exporter 0.35.0 → 0.36.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +218 -205
- package/dist/blocknote-xl-docx-exporter.cjs +2 -2
- package/dist/blocknote-xl-docx-exporter.cjs.map +1 -1
- package/dist/blocknote-xl-docx-exporter.js +77 -71
- package/dist/blocknote-xl-docx-exporter.js.map +1 -1
- package/dist/webpack-stats.json +1 -1
- package/package.json +4 -4
- package/src/docx/__snapshots__/basic/styles.xml +1 -1
- package/src/docx/__snapshots__/withMultiColumn/styles.xml +1 -1
- package/src/docx/docxExporter.test.ts +7 -1
- package/src/docx/docxExporter.ts +24 -3
- package/types/src/docx/docxExporter.d.ts +11 -1
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
"use strict";var A=Object.create;var x=Object.defineProperty;var B=Object.getOwnPropertyDescriptor;var
|
|
2
|
-
`).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,u
|
|
1
|
+
"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(`
|
|
2
|
+
`).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;
|
|
3
3
|
//# sourceMappingURL=blocknote-xl-docx-exporter.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"blocknote-xl-docx-exporter.cjs","sources":["../../../shared/util/imageUtil.ts","../src/docx/util/Table.tsx","../src/docx/defaultSchema/blocks.ts","../src/docx/defaultSchema/inlinecontent.ts","../src/docx/defaultSchema/styles.ts","../src/docx/defaultSchema/index.ts","../../../shared/api/corsProxy.ts","../../../shared/util/fileUtil.ts","../src/docx/docxExporter.ts"],"sourcesContent":["export async function getImageDimensions(blob: Blob) {\n if (typeof window !== \"undefined\" && import.meta.env.NODE_ENV !== \"test\") {\n const bmp = await createImageBitmap(blob);\n const { width, height } = bmp;\n bmp.close(); // free memory\n return { width, height };\n } else {\n // node or vitest\n const imageMetaFunc = (await import(\"image-meta\")).imageMeta;\n const bytes = new Uint8Array(await blob.arrayBuffer());\n const meta = imageMetaFunc(bytes);\n if (!meta.width || !meta.height) {\n throw new Error(\"Image dimensions not found\");\n }\n return { width: meta.width, height: meta.height };\n }\n}\n","import {\n Exporter,\n InlineContentSchema,\n mapTableCell,\n TableContent,\n UnreachableCaseError,\n} from \"@blocknote/core\";\nimport {\n Table as DocxTable,\n Paragraph,\n ParagraphChild,\n ShadingType,\n TableCell,\n TableRow,\n} from \"docx\";\n\nexport const Table = (\n data: TableContent<InlineContentSchema>,\n t: Exporter<any, any, any, any, ParagraphChild, any, any>,\n) => {\n const DEFAULT_COLUMN_WIDTH = 120;\n\n // If headerRows is 1, then the first row is a header row\n const headerRows = new Array(data.headerRows ?? 0).fill(true);\n // If headerCols is 1, then the first column is a header column\n const headerCols = new Array(data.headerCols ?? 0).fill(true);\n\n return new DocxTable({\n layout: \"autofit\",\n columnWidths: data.columnWidths.map(\n (w) =>\n (w ?? DEFAULT_COLUMN_WIDTH) * /* to points */ 0.75 * /* to twips */ 20,\n ),\n rows: data.rows.map((row, rowIndex) => {\n const isHeaderRow = headerRows[rowIndex];\n return new TableRow({\n tableHeader: isHeaderRow,\n children: row.cells.map((c, colIndex) => {\n const width = data.columnWidths?.[colIndex];\n const cell = mapTableCell(c);\n const isHeaderColumn = headerCols[colIndex];\n\n return new TableCell({\n width: width\n ? {\n size: `${width * 0.75}pt`,\n type: \"dxa\",\n }\n : undefined,\n columnSpan: cell.props.colspan,\n rowSpan: cell.props.rowspan,\n shading:\n cell.props.backgroundColor === \"default\" ||\n !cell.props.backgroundColor\n ? undefined\n : {\n type: ShadingType.SOLID,\n color:\n t.options.colors[\n cell.props\n .backgroundColor as keyof typeof t.options.colors\n ].background.slice(1),\n },\n children: [\n new Paragraph({\n children: t.transformInlineContent(cell.content),\n\n alignment:\n !cell.props.textAlignment ||\n cell.props.textAlignment === \"left\"\n ? undefined\n : cell.props.textAlignment === \"center\"\n ? \"center\"\n : cell.props.textAlignment === \"right\"\n ? \"right\"\n : cell.props.textAlignment === \"justify\"\n ? \"distribute\"\n : (() => {\n throw new UnreachableCaseError(\n cell.props.textAlignment,\n );\n })(),\n run: {\n // TODO add support for table headers exporting, bolding seems to not be working at the moment\n bold: isHeaderRow || isHeaderColumn,\n // TODO table paragraph color seems to not be working at the moment\n // Probably because the runs are setting their own color\n color:\n cell.props.textColor === \"default\" || !cell.props.textColor\n ? undefined\n : t.options.colors[\n cell.props.textColor as keyof typeof t.options.colors\n ].text.slice(1),\n },\n }),\n ],\n });\n }),\n });\n }),\n });\n};\n","import {\n BlockMapping,\n COLORS_DEFAULT,\n DefaultBlockSchema,\n DefaultProps,\n pageBreakSchema,\n StyledText,\n UnreachableCaseError,\n} from \"@blocknote/core\";\nimport { getImageDimensions } from \"@shared/util/imageUtil.js\";\nimport {\n CheckBox,\n Table as DocxTable,\n ExternalHyperlink,\n ImageRun,\n IParagraphOptions,\n PageBreak,\n Paragraph,\n ParagraphChild,\n ShadingType,\n TableCell,\n TableRow,\n TextRun,\n} from \"docx\";\nimport { Table } from \"../util/Table.js\";\nimport { multiColumnSchema } from \"@blocknote/xl-multi-column\";\n\nfunction blockPropsToStyles(\n props: Partial<DefaultProps>,\n colors: typeof COLORS_DEFAULT,\n): IParagraphOptions {\n return {\n shading:\n props.backgroundColor === \"default\" || !props.backgroundColor\n ? undefined\n : {\n type: ShadingType.SOLID,\n color:\n colors[\n props.backgroundColor as keyof typeof colors\n ].background.slice(1),\n },\n run:\n props.textColor === \"default\" || !props.textColor\n ? undefined\n : {\n color: colors[props.textColor as keyof typeof colors].text.slice(1),\n },\n alignment:\n !props.textAlignment || props.textAlignment === \"left\"\n ? undefined\n : props.textAlignment === \"center\"\n ? \"center\"\n : props.textAlignment === \"right\"\n ? \"right\"\n : props.textAlignment === \"justify\"\n ? \"distribute\"\n : (() => {\n throw new UnreachableCaseError(props.textAlignment);\n })(),\n };\n}\nexport const docxBlockMappingForDefaultSchema: BlockMapping<\n DefaultBlockSchema &\n typeof pageBreakSchema.blockSchema &\n typeof multiColumnSchema.blockSchema,\n any,\n any,\n | Promise<Paragraph[] | Paragraph | DocxTable>\n | Paragraph[]\n | Paragraph\n | DocxTable,\n ParagraphChild\n> = {\n paragraph: (block, exporter) => {\n return new Paragraph({\n ...blockPropsToStyles(block.props, exporter.options.colors),\n children: exporter.transformInlineContent(block.content),\n style: \"Normal\",\n run: {\n font: \"Inter\",\n },\n });\n },\n toggleListItem: (block, exporter) => {\n return new Paragraph({\n ...blockPropsToStyles(block.props, exporter.options.colors),\n children: [\n new TextRun({\n children: [\"> \"],\n }),\n ...exporter.transformInlineContent(block.content),\n ],\n });\n },\n numberedListItem: (block, exporter, nestingLevel) => {\n return new Paragraph({\n ...blockPropsToStyles(block.props, exporter.options.colors),\n children: exporter.transformInlineContent(block.content),\n numbering: {\n reference: \"blocknote-numbered-list\",\n level: nestingLevel,\n },\n });\n },\n bulletListItem: (block, exporter, nestingLevel) => {\n return new Paragraph({\n ...blockPropsToStyles(block.props, exporter.options.colors),\n children: exporter.transformInlineContent(block.content),\n numbering: {\n reference: \"blocknote-bullet-list\",\n level: nestingLevel,\n },\n });\n },\n checkListItem: (block, exporter) => {\n return new Paragraph({\n ...blockPropsToStyles(block.props, exporter.options.colors),\n children: [\n new CheckBox({ checked: block.props.checked }),\n new TextRun({\n children: [\" \"],\n }),\n ...exporter.transformInlineContent(block.content),\n ],\n });\n },\n heading: (block, exporter) => {\n return new Paragraph({\n ...blockPropsToStyles(block.props, exporter.options.colors),\n children: exporter.transformInlineContent(block.content),\n heading: `Heading${block.props.level}`,\n });\n },\n quote: (block, exporter) => {\n return new Paragraph({\n shading: {\n color: \"#7D797A\",\n },\n border: {\n left: {\n color: \"#7D797A\",\n space: 100,\n style: \"single\",\n size: 8,\n },\n },\n ...blockPropsToStyles(block.props, exporter.options.colors),\n children: exporter.transformInlineContent(block.content),\n });\n },\n audio: (block, exporter) => {\n return [\n file(block.props, \"Open audio\", exporter),\n ...caption(block.props, exporter),\n ];\n },\n video: (block, exporter) => {\n return [\n file(block.props, \"Open video\", exporter),\n ...caption(block.props, exporter),\n ];\n },\n file: (block, exporter) => {\n return [\n file(block.props, \"Open file\", exporter),\n ...caption(block.props, exporter),\n ];\n },\n codeBlock: (block) => {\n const textContent = (block.content as StyledText<any>[])[0]?.text || \"\";\n\n return new Paragraph({\n style: \"Codeblock\",\n shading: {\n type: ShadingType.SOLID,\n fill: \"161616\",\n color: \"161616\",\n },\n children: [\n ...textContent.split(\"\\n\").map((line, index) => {\n return new TextRun({\n text: line,\n break: index > 0 ? 1 : 0,\n });\n }),\n ],\n });\n },\n pageBreak: () => {\n return new Paragraph({\n children: [new PageBreak()],\n });\n },\n column: (block, _exporter, _nestingLevel, _numberedListIndex, children) => {\n return new TableCell({\n width: {\n size: `${block.props.width * 100}%`,\n type: \"pct\",\n },\n children: (children || []).flatMap((child) => {\n if (Array.isArray(child)) {\n return child;\n }\n\n return [child];\n }),\n }) as any;\n },\n columnList: (\n _block,\n _exporter,\n _nestingLevel,\n _numberedListIndex,\n children,\n ) => {\n return new DocxTable({\n layout: \"autofit\",\n borders: {\n bottom: { style: \"nil\" },\n top: { style: \"nil\" },\n left: { style: \"nil\" },\n right: { style: \"nil\" },\n insideHorizontal: { style: \"nil\" },\n insideVertical: { style: \"nil\" },\n },\n rows: [\n new TableRow({\n children: (children as unknown as TableCell[]).map(\n (cell, _index, children) => {\n return new TableCell({\n width: {\n size: `${(parseFloat(`${cell.options.width?.size || \"100%\"}`) / (children.length * 100)) * 100}%`,\n type: \"pct\",\n },\n children: cell.options.children,\n });\n },\n ),\n }),\n ],\n });\n },\n image: async (block, exporter) => {\n const blob = await exporter.resolveFile(block.props.url);\n const { width, height } = await getImageDimensions(blob);\n\n return [\n new Paragraph({\n ...blockPropsToStyles(block.props, exporter.options.colors),\n children: [\n new ImageRun({\n data: await blob.arrayBuffer(),\n // it would be nicer to set the actual data type here, but then we'd need to use a mime type / image type\n // detector. atm passing gif does not seem to be causing issues as the \"type\" is mainly used by docxjs internally\n // (i.e.: to make sure it's not svg)\n type: \"gif\",\n altText: block.props.caption\n ? {\n description: block.props.caption,\n name: block.props.caption,\n title: block.props.caption,\n }\n : undefined,\n transformation: {\n width: block.props.previewWidth || width,\n height: ((block.props.previewWidth || width) / width) * height,\n },\n }),\n ],\n }),\n ...caption(block.props, exporter),\n ];\n },\n table: (block, exporter) => {\n return Table(block.content, exporter);\n },\n};\n\nfunction file(\n props: Partial<DefaultProps & { name: string; url: string }>,\n defaultText: string,\n exporter: any,\n) {\n return new Paragraph({\n ...blockPropsToStyles(props, exporter.options.colors),\n children: [\n new ExternalHyperlink({\n children: [\n new TextRun({\n text: props.name || defaultText,\n style: \"Hyperlink\",\n }),\n ],\n link: props.url!,\n }),\n ],\n });\n}\n\nfunction caption(\n props: Partial<DefaultProps & { caption: string }>,\n exporter: any,\n) {\n if (!props.caption) {\n return [];\n }\n return [\n new Paragraph({\n ...blockPropsToStyles(props, exporter.options.colors),\n children: [\n new TextRun({\n text: props.caption,\n }),\n ],\n style: \"Caption\",\n }),\n ];\n}\n","import {\n DefaultInlineContentSchema,\n DefaultStyleSchema,\n InlineContentMapping,\n} from \"@blocknote/core\";\nimport { ExternalHyperlink, ParagraphChild, TextRun } from \"docx\";\nimport type { DOCXExporter } from \"../docxExporter.js\";\n\nexport const docxInlineContentMappingForDefaultSchema: InlineContentMapping<\n DefaultInlineContentSchema,\n DefaultStyleSchema,\n ParagraphChild,\n TextRun\n> = {\n link: (ic, exporter) => {\n return new ExternalHyperlink({\n children: ic.content.map((content) => {\n return (exporter as DOCXExporter<any, any, any>).transformStyledText(\n content,\n true,\n );\n }),\n link: ic.href,\n });\n },\n text: (ic, t) => {\n return t.transformStyledText(ic);\n },\n};\n","import { DefaultStyleSchema, StyleMapping } from \"@blocknote/core\";\nimport { IRunPropertiesOptions } from \"docx\";\n\nexport const docxStyleMappingForDefaultSchema: StyleMapping<\n DefaultStyleSchema,\n IRunPropertiesOptions\n> = {\n bold: (val) => {\n if (!val) {\n return {};\n }\n return {\n bold: val,\n };\n },\n italic: (val) => {\n if (!val) {\n return {};\n }\n return {\n italics: val,\n };\n },\n underline: (val) => {\n if (!val) {\n return {};\n }\n return {\n underline: {\n type: \"single\",\n },\n };\n },\n strike: (val) => {\n if (!val) {\n return {};\n }\n return {\n strike: val,\n };\n },\n backgroundColor: (val, exporter) => {\n if (!val) {\n return {};\n }\n return {\n shading: {\n fill: exporter.options.colors[\n val as keyof typeof exporter.options.colors\n ].background.slice(1),\n },\n };\n },\n textColor: (val, exporter) => {\n if (!val) {\n return {};\n }\n return {\n color:\n exporter.options.colors[\n val as keyof typeof exporter.options.colors\n ].text.slice(1),\n };\n },\n code: (val) => {\n if (!val) {\n return {};\n }\n return {\n font: \"GeistMono\",\n };\n },\n};\n","import { docxBlockMappingForDefaultSchema } from \"./blocks.js\";\nimport { docxInlineContentMappingForDefaultSchema } from \"./inlinecontent.js\";\nimport { docxStyleMappingForDefaultSchema } from \"./styles.js\";\n\nexport const docxDefaultSchemaMappings = {\n blockMapping: docxBlockMappingForDefaultSchema,\n inlineContentMapping: docxInlineContentMappingForDefaultSchema,\n styleMapping: docxStyleMappingForDefaultSchema,\n};\n","export async function corsProxyResolveFileUrl(url: string) {\n return (\n \"https://corsproxy.api.blocknotejs.org/corsproxy/?url=\" +\n encodeURIComponent(url)\n );\n}\n","/**\n *\n * Helper functions so that we can import files both on vitest, browser and node\n * TODO: should find a way to test automatically in all environments\n */\n\nexport async function loadFileDataUrl(\n requireUrl: { default: string },\n mimeType: string,\n) {\n if (import.meta.env.NODE_ENV === \"test\") {\n const buffer = await loadFileBuffer(requireUrl);\n const fileBase64 = buffer.toString(\"base64\");\n\n const dataUrl = `data:${mimeType};base64,${fileBase64}`;\n return dataUrl;\n } else {\n // in browser, this is already a data url\n return requireUrl.default as string;\n }\n}\n\nexport async function loadFontDataUrl(requireUrl: { default: string }) {\n return loadFileDataUrl(requireUrl, \"font/ttf\");\n}\n\nexport async function loadFileBuffer(requireUrl: {\n default: string;\n}): Promise<Buffer | ArrayBuffer> {\n if (import.meta.env.NODE_ENV === \"test\") {\n // in vitest, this is the url we need to load with readfilesync\n // eslint-disable-next-line\n const fs = require(\"fs\");\n let url = requireUrl.default;\n\n if (url.startsWith(\"/@fs/\")) {\n url = url.substring(\"/@fs\".length);\n }\n const buffer = fs.readFileSync(url);\n return buffer;\n } else {\n // in browser, this is already a data url\n const dataUrl = requireUrl.default as string;\n // convert to buffer on browser\n const response = await fetch(dataUrl);\n const arrayBuffer = await response.arrayBuffer();\n return arrayBuffer;\n }\n}\n\n/**\n * usage:\n * \n * await loadFontDataUrl(\n await import(\"../fonts/inter/Inter_18pt-Italic.ttf\")\n );\n */\n","import {\n Block,\n BlockNoteSchema,\n BlockSchema,\n COLORS_DEFAULT,\n InlineContentSchema,\n StyleSchema,\n StyledText,\n} from \"@blocknote/core\";\nimport {\n AlignmentType,\n Document,\n IRunPropertiesOptions,\n ISectionOptions,\n LevelFormat,\n Packer,\n Paragraph,\n ParagraphChild,\n Tab,\n Table,\n TextRun,\n} from \"docx\";\n\nimport { Exporter, ExporterOptions } from \"@blocknote/core\";\nimport { corsProxyResolveFileUrl } from \"@shared/api/corsProxy.js\";\nimport { loadFileBuffer } from \"@shared/util/fileUtil.js\";\n\n// get constructor arg type from Document\ntype DocumentOptions = Partial<ConstructorParameters<typeof Document>[0]>;\n\nconst DEFAULT_TAB_STOP =\n /* default font size */ 16 *\n /* 1 pixel is 0.75 points */ 0.75 *\n /* 1.5em*/ 1.5 *\n /* 1 point is 20 twips */ 20;\n\n/**\n * Exports a BlockNote document to a .docx file using the docxjs library.\n */\nexport class DOCXExporter<\n B extends BlockSchema,\n S extends StyleSchema,\n I extends InlineContentSchema,\n> extends Exporter<\n B,\n I,\n S,\n Promise<Paragraph[] | Paragraph | Table> | Paragraph[] | Paragraph | Table,\n ParagraphChild,\n IRunPropertiesOptions,\n TextRun\n> {\n public constructor(\n /**\n * The schema of your editor. The mappings are automatically typed checked against this schema.\n */\n protected readonly schema: BlockNoteSchema<B, I, S>,\n /**\n * The mappings that map the BlockNote schema to the docxjs content.\n * Pass {@link docxDefaultSchemaMappings} for the default schema.\n */\n protected readonly mappings: Exporter<\n NoInfer<B>,\n NoInfer<I>,\n NoInfer<S>,\n | Promise<Paragraph[] | Paragraph | Table>\n | Paragraph[]\n | Paragraph\n | Table,\n ParagraphChild,\n IRunPropertiesOptions,\n TextRun\n >[\"mappings\"],\n options?: Partial<ExporterOptions>,\n ) {\n const defaults = {\n colors: COLORS_DEFAULT,\n resolveFileUrl: corsProxyResolveFileUrl,\n } satisfies Partial<ExporterOptions>;\n\n const newOptions = {\n ...defaults,\n ...options,\n };\n super(schema, mappings, newOptions);\n }\n\n /**\n * Mostly for internal use, you probably want to use `toBlob` or `toDocxJsDocument` instead.\n */\n public transformStyledText(styledText: StyledText<S>, hyperlink?: boolean) {\n const stylesArray = this.mapStyles(styledText.styles);\n\n const styles: IRunPropertiesOptions = Object.assign(\n {} as IRunPropertiesOptions,\n ...stylesArray,\n );\n\n return new TextRun({\n ...styles,\n style: hyperlink ? \"Hyperlink\" : undefined,\n text: styledText.text,\n });\n }\n\n /**\n * Mostly for internal use, you probably want to use `toBlob` or `toDocxJsDocument` instead.\n */\n public async transformBlocks(\n blocks: Block<B, I, S>[],\n nestingLevel = 0,\n ): Promise<Array<Paragraph | Table>> {\n const ret: Array<Paragraph | Table> = [];\n\n for (const b of blocks) {\n let children = await this.transformBlocks(b.children, nestingLevel + 1);\n\n if (![\"columnList\", \"column\"].includes(b.type)) {\n children = children.map((c, _i) => {\n // NOTE: nested tables not supported (we can't insert the new Tab before a table)\n if (\n c instanceof Paragraph &&\n !(c as any).properties.numberingReferences.length\n ) {\n c.addRunToFront(\n new TextRun({\n children: [new Tab()],\n }),\n );\n }\n return c;\n });\n }\n\n const self = await this.mapBlock(\n b as any,\n nestingLevel,\n 0 /*unused*/,\n children,\n ); // TODO: any\n if ([\"columnList\", \"column\"].includes(b.type)) {\n ret.push(self as Table);\n } else if (Array.isArray(self)) {\n ret.push(...self, ...children);\n } else {\n ret.push(self, ...children);\n }\n }\n return ret;\n }\n\n protected async getFonts(): Promise<DocumentOptions[\"fonts\"]> {\n // Unfortunately, loading the variable font doesn't work\n // \"./src/fonts/Inter-VariableFont_opsz,wght.ttf\",\n\n let interFont = await loadFileBuffer(\n await import(\"@shared/assets/fonts/inter/Inter_18pt-Regular.ttf\"),\n );\n let geistMonoFont = await loadFileBuffer(\n await import(\"@shared/assets/fonts/GeistMono-Regular.ttf\"),\n );\n\n if (\n interFont instanceof ArrayBuffer ||\n geistMonoFont instanceof ArrayBuffer\n ) {\n // conversion with Polyfill needed because docxjs requires Buffer\n // NOTE: the buffer/ import is intentional and as documented in\n // the `buffer` package usage instructions\n // https://github.com/feross/buffer?tab=readme-ov-file#usage\n const Buffer = (await import(\"buffer/\")).Buffer;\n\n if (interFont instanceof ArrayBuffer) {\n interFont = Buffer.from(interFont) as unknown as Buffer;\n }\n if (geistMonoFont instanceof ArrayBuffer) {\n geistMonoFont = Buffer.from(geistMonoFont) as unknown as Buffer;\n }\n }\n\n return [\n { name: \"Inter\", data: interFont },\n {\n name: \"GeistMono\",\n data: geistMonoFont,\n },\n ];\n }\n\n protected async createDefaultDocumentOptions(): Promise<DocumentOptions> {\n const externalStyles = (await import(\"./template/word/styles.xml?raw\"))\n .default;\n\n const bullets = [\"•\"]; //, \"◦\", \"▪\"]; (these don't look great, just use solid bullet for now)\n return {\n numbering: {\n config: [\n {\n reference: \"blocknote-numbered-list\",\n levels: Array.from({ length: 9 }, (_, i) => ({\n start: 1,\n level: i,\n format: LevelFormat.DECIMAL,\n text: `%${i + 1}.`,\n alignment: AlignmentType.LEFT,\n style: {\n paragraph: {\n indent: {\n left: DEFAULT_TAB_STOP * (i + 1),\n hanging: DEFAULT_TAB_STOP,\n },\n },\n },\n })),\n },\n {\n reference: \"blocknote-bullet-list\",\n levels: Array.from({ length: 9 }, (_, i) => ({\n start: 1,\n level: i,\n format: LevelFormat.BULLET,\n text: bullets[i % bullets.length],\n alignment: AlignmentType.LEFT,\n style: {\n paragraph: {\n indent: {\n left: DEFAULT_TAB_STOP * (i + 1),\n hanging: DEFAULT_TAB_STOP,\n },\n },\n },\n })),\n },\n ],\n },\n fonts: await this.getFonts(),\n defaultTabStop: 200,\n externalStyles,\n };\n }\n\n /**\n * Convert a document (array of Blocks to a Blob representing a .docx file)\n */\n public async toBlob(\n blocks: Block<B, I, S>[],\n options: {\n sectionOptions: Omit<ISectionOptions, \"children\">;\n documentOptions: DocumentOptions;\n } = {\n sectionOptions: {},\n documentOptions: {},\n },\n ) {\n const doc = await this.toDocxJsDocument(blocks, options);\n type GlobalThis = typeof globalThis & { Buffer?: any };\n const prevBuffer = (globalThis as GlobalThis).Buffer;\n try {\n if (!(globalThis as GlobalThis).Buffer) {\n // load Buffer polyfill because docxjs requires this\n (globalThis as GlobalThis).Buffer = (\n await import(\"buffer\")\n ).default.Buffer;\n }\n return Packer.toBlob(doc);\n } finally {\n (globalThis as GlobalThis).Buffer = prevBuffer;\n }\n }\n\n /**\n * Convert a document (array of Blocks to a docxjs Document)\n */\n public async toDocxJsDocument(\n blocks: Block<B, I, S>[],\n options: {\n sectionOptions: Omit<ISectionOptions, \"children\">;\n documentOptions: DocumentOptions;\n } = {\n sectionOptions: {},\n documentOptions: {},\n },\n ) {\n const doc = new Document({\n ...(await this.createDefaultDocumentOptions()),\n ...options.documentOptions,\n sections: [\n {\n children: await this.transformBlocks(blocks),\n ...options.sectionOptions,\n },\n ],\n });\n\n return doc;\n }\n}\n"],"names":["getImageDimensions","blob","bmp","width","height","imageMetaFunc","bytes","meta","Table","data","headerRows","headerCols","DocxTable","w","row","rowIndex","isHeaderRow","TableRow","c","colIndex","_a","cell","mapTableCell","isHeaderColumn","TableCell","ShadingType","Paragraph","UnreachableCaseError","blockPropsToStyles","props","colors","docxBlockMappingForDefaultSchema","block","exporter","TextRun","nestingLevel","CheckBox","file","caption","textContent","line","index","PageBreak","_exporter","_nestingLevel","_numberedListIndex","children","child","_block","_index","ImageRun","defaultText","ExternalHyperlink","docxInlineContentMappingForDefaultSchema","ic","content","docxStyleMappingForDefaultSchema","val","docxDefaultSchemaMappings","corsProxyResolveFileUrl","url","loadFileBuffer","requireUrl","dataUrl","DEFAULT_TAB_STOP","DOCXExporter","Exporter","schema","mappings","options","newOptions","COLORS_DEFAULT","styledText","hyperlink","stylesArray","styles","blocks","ret","b","_i","Tab","self","interFont","geistMonoFont","Buffer","n","externalStyles","bullets","_","LevelFormat","AlignmentType","doc","prevBuffer","Packer","Document"],"mappings":"glBAAA,eAAsBA,EAAmBC,EAAY,CACnD,GAAI,OAAO,OAAW,IAAoD,CAClE,MAAAC,EAAM,MAAM,kBAAkBD,CAAI,EAClC,CAAE,MAAAE,EAAO,OAAAC,CAAA,EAAWF,EAC1B,OAAAA,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AA,QACpB,KAAM,IAAI,EAAI,CAAC,IACf,UAAWC,EAAc,cAAA,KACzB,MAAO,CACL,UAAW,CACT,OAAQ,CACN,KAAM1B,GAAoB,EAAI,GAC9B,QAASA,CAAA,CACX,CACF,CACF,EACA,CACJ,EACA,CACE,UAAW,wBACX,OAAQ,MAAM,KAAK,CAAE,OAAQ,GAAK,CAACwB,EAAG,KAAO,CAC3C,MAAO,EACP,MAAO,EACP,OAAQC,EAAY,YAAA,OACpB,KAAMF,EAAQ,EAAIA,EAAQ,MAAM,EAChC,UAAWG,EAAc,cAAA,KACzB,MAAO,CACL,UAAW,CACT,OAAQ,CACN,KAAM1B,GAAoB,EAAI,GAC9B,QAASA,CAAA,CACX,CACF,CACF,EACA,CAAA,CACJ,CAEJ,EACA,MAAO,MAAM,KAAK,SAAS,EAC3B,eAAgB,IAChB,eAAAsB,CACF,CAAA,CAMF,MAAa,OACXV,EACAP,EAGI,CACF,eAAgB,CAAC,EACjB,gBAAiB,CAAA,CAAC,EAEpB,CACA,MAAMsB,EAAM,MAAM,KAAK,iBAAiBf,EAAQP,CAAO,EAEjDuB,EAAc,WAA0B,OAC1C,GAAA,CACE,OAAE,WAA0B,SAE7B,WAA0B,QACzB,KAAM,QAAO,QAAQ,GACrB,QAAQ,QAELC,EAAA,OAAO,OAAOF,CAAG,CAAA,QACxB,CACC,WAA0B,OAASC,CAAA,CACtC,CAMF,MAAa,iBACXhB,EACAP,EAGI,CACF,eAAgB,CAAC,EACjB,gBAAiB,CAAA,CAAC,EAEpB,CAYO,OAXK,IAAIyB,WAAS,CACvB,GAAI,MAAM,KAAK,6BAA6B,EAC5C,GAAGzB,EAAQ,gBACX,SAAU,CACR,CACE,SAAU,MAAM,KAAK,gBAAgBO,CAAM,EAC3C,GAAGP,EAAQ,cAAA,CACb,CACF,CACD,CAEM,CAEX"}
|
|
1
|
+
{"version":3,"file":"blocknote-xl-docx-exporter.cjs","sources":["../../../shared/util/imageUtil.ts","../src/docx/util/Table.tsx","../src/docx/defaultSchema/blocks.ts","../src/docx/defaultSchema/inlinecontent.ts","../src/docx/defaultSchema/styles.ts","../src/docx/defaultSchema/index.ts","../../../shared/api/corsProxy.ts","../../../shared/util/fileUtil.ts","../src/docx/docxExporter.ts"],"sourcesContent":["export async function getImageDimensions(blob: Blob) {\n if (typeof window !== \"undefined\" && import.meta.env.NODE_ENV !== \"test\") {\n const bmp = await createImageBitmap(blob);\n const { width, height } = bmp;\n bmp.close(); // free memory\n return { width, height };\n } else {\n // node or vitest\n const imageMetaFunc = (await import(\"image-meta\")).imageMeta;\n const bytes = new Uint8Array(await blob.arrayBuffer());\n const meta = imageMetaFunc(bytes);\n if (!meta.width || !meta.height) {\n throw new Error(\"Image dimensions not found\");\n }\n return { width: meta.width, height: meta.height };\n }\n}\n","import {\n Exporter,\n InlineContentSchema,\n mapTableCell,\n TableContent,\n UnreachableCaseError,\n} from \"@blocknote/core\";\nimport {\n Table as DocxTable,\n Paragraph,\n ParagraphChild,\n ShadingType,\n TableCell,\n TableRow,\n} from \"docx\";\n\nexport const Table = (\n data: TableContent<InlineContentSchema>,\n t: Exporter<any, any, any, any, ParagraphChild, any, any>,\n) => {\n const DEFAULT_COLUMN_WIDTH = 120;\n\n // If headerRows is 1, then the first row is a header row\n const headerRows = new Array(data.headerRows ?? 0).fill(true);\n // If headerCols is 1, then the first column is a header column\n const headerCols = new Array(data.headerCols ?? 0).fill(true);\n\n return new DocxTable({\n layout: \"autofit\",\n columnWidths: data.columnWidths.map(\n (w) =>\n (w ?? DEFAULT_COLUMN_WIDTH) * /* to points */ 0.75 * /* to twips */ 20,\n ),\n rows: data.rows.map((row, rowIndex) => {\n const isHeaderRow = headerRows[rowIndex];\n return new TableRow({\n tableHeader: isHeaderRow,\n children: row.cells.map((c, colIndex) => {\n const width = data.columnWidths?.[colIndex];\n const cell = mapTableCell(c);\n const isHeaderColumn = headerCols[colIndex];\n\n return new TableCell({\n width: width\n ? {\n size: `${width * 0.75}pt`,\n type: \"dxa\",\n }\n : undefined,\n columnSpan: cell.props.colspan,\n rowSpan: cell.props.rowspan,\n shading:\n cell.props.backgroundColor === \"default\" ||\n !cell.props.backgroundColor\n ? undefined\n : {\n type: ShadingType.SOLID,\n color:\n t.options.colors[\n cell.props\n .backgroundColor as keyof typeof t.options.colors\n ].background.slice(1),\n },\n children: [\n new Paragraph({\n children: t.transformInlineContent(cell.content),\n\n alignment:\n !cell.props.textAlignment ||\n cell.props.textAlignment === \"left\"\n ? undefined\n : cell.props.textAlignment === \"center\"\n ? \"center\"\n : cell.props.textAlignment === \"right\"\n ? \"right\"\n : cell.props.textAlignment === \"justify\"\n ? \"distribute\"\n : (() => {\n throw new UnreachableCaseError(\n cell.props.textAlignment,\n );\n })(),\n run: {\n // TODO add support for table headers exporting, bolding seems to not be working at the moment\n bold: isHeaderRow || isHeaderColumn,\n // TODO table paragraph color seems to not be working at the moment\n // Probably because the runs are setting their own color\n color:\n cell.props.textColor === \"default\" || !cell.props.textColor\n ? undefined\n : t.options.colors[\n cell.props.textColor as keyof typeof t.options.colors\n ].text.slice(1),\n },\n }),\n ],\n });\n }),\n });\n }),\n });\n};\n","import {\n BlockMapping,\n COLORS_DEFAULT,\n DefaultBlockSchema,\n DefaultProps,\n pageBreakSchema,\n StyledText,\n UnreachableCaseError,\n} from \"@blocknote/core\";\nimport { getImageDimensions } from \"@shared/util/imageUtil.js\";\nimport {\n CheckBox,\n Table as DocxTable,\n ExternalHyperlink,\n ImageRun,\n IParagraphOptions,\n PageBreak,\n Paragraph,\n ParagraphChild,\n ShadingType,\n TableCell,\n TableRow,\n TextRun,\n} from \"docx\";\nimport { Table } from \"../util/Table.js\";\nimport { multiColumnSchema } from \"@blocknote/xl-multi-column\";\n\nfunction blockPropsToStyles(\n props: Partial<DefaultProps>,\n colors: typeof COLORS_DEFAULT,\n): IParagraphOptions {\n return {\n shading:\n props.backgroundColor === \"default\" || !props.backgroundColor\n ? undefined\n : {\n type: ShadingType.SOLID,\n color:\n colors[\n props.backgroundColor as keyof typeof colors\n ].background.slice(1),\n },\n run:\n props.textColor === \"default\" || !props.textColor\n ? undefined\n : {\n color: colors[props.textColor as keyof typeof colors].text.slice(1),\n },\n alignment:\n !props.textAlignment || props.textAlignment === \"left\"\n ? undefined\n : props.textAlignment === \"center\"\n ? \"center\"\n : props.textAlignment === \"right\"\n ? \"right\"\n : props.textAlignment === \"justify\"\n ? \"distribute\"\n : (() => {\n throw new UnreachableCaseError(props.textAlignment);\n })(),\n };\n}\nexport const docxBlockMappingForDefaultSchema: BlockMapping<\n DefaultBlockSchema &\n typeof pageBreakSchema.blockSchema &\n typeof multiColumnSchema.blockSchema,\n any,\n any,\n | Promise<Paragraph[] | Paragraph | DocxTable>\n | Paragraph[]\n | Paragraph\n | DocxTable,\n ParagraphChild\n> = {\n paragraph: (block, exporter) => {\n return new Paragraph({\n ...blockPropsToStyles(block.props, exporter.options.colors),\n children: exporter.transformInlineContent(block.content),\n style: \"Normal\",\n run: {\n font: \"Inter\",\n },\n });\n },\n toggleListItem: (block, exporter) => {\n return new Paragraph({\n ...blockPropsToStyles(block.props, exporter.options.colors),\n children: [\n new TextRun({\n children: [\"> \"],\n }),\n ...exporter.transformInlineContent(block.content),\n ],\n });\n },\n numberedListItem: (block, exporter, nestingLevel) => {\n return new Paragraph({\n ...blockPropsToStyles(block.props, exporter.options.colors),\n children: exporter.transformInlineContent(block.content),\n numbering: {\n reference: \"blocknote-numbered-list\",\n level: nestingLevel,\n },\n });\n },\n bulletListItem: (block, exporter, nestingLevel) => {\n return new Paragraph({\n ...blockPropsToStyles(block.props, exporter.options.colors),\n children: exporter.transformInlineContent(block.content),\n numbering: {\n reference: \"blocknote-bullet-list\",\n level: nestingLevel,\n },\n });\n },\n checkListItem: (block, exporter) => {\n return new Paragraph({\n ...blockPropsToStyles(block.props, exporter.options.colors),\n children: [\n new CheckBox({ checked: block.props.checked }),\n new TextRun({\n children: [\" \"],\n }),\n ...exporter.transformInlineContent(block.content),\n ],\n });\n },\n heading: (block, exporter) => {\n return new Paragraph({\n ...blockPropsToStyles(block.props, exporter.options.colors),\n children: exporter.transformInlineContent(block.content),\n heading: `Heading${block.props.level}`,\n });\n },\n quote: (block, exporter) => {\n return new Paragraph({\n shading: {\n color: \"#7D797A\",\n },\n border: {\n left: {\n color: \"#7D797A\",\n space: 100,\n style: \"single\",\n size: 8,\n },\n },\n ...blockPropsToStyles(block.props, exporter.options.colors),\n children: exporter.transformInlineContent(block.content),\n });\n },\n audio: (block, exporter) => {\n return [\n file(block.props, \"Open audio\", exporter),\n ...caption(block.props, exporter),\n ];\n },\n video: (block, exporter) => {\n return [\n file(block.props, \"Open video\", exporter),\n ...caption(block.props, exporter),\n ];\n },\n file: (block, exporter) => {\n return [\n file(block.props, \"Open file\", exporter),\n ...caption(block.props, exporter),\n ];\n },\n codeBlock: (block) => {\n const textContent = (block.content as StyledText<any>[])[0]?.text || \"\";\n\n return new Paragraph({\n style: \"Codeblock\",\n shading: {\n type: ShadingType.SOLID,\n fill: \"161616\",\n color: \"161616\",\n },\n children: [\n ...textContent.split(\"\\n\").map((line, index) => {\n return new TextRun({\n text: line,\n break: index > 0 ? 1 : 0,\n });\n }),\n ],\n });\n },\n pageBreak: () => {\n return new Paragraph({\n children: [new PageBreak()],\n });\n },\n column: (block, _exporter, _nestingLevel, _numberedListIndex, children) => {\n return new TableCell({\n width: {\n size: `${block.props.width * 100}%`,\n type: \"pct\",\n },\n children: (children || []).flatMap((child) => {\n if (Array.isArray(child)) {\n return child;\n }\n\n return [child];\n }),\n }) as any;\n },\n columnList: (\n _block,\n _exporter,\n _nestingLevel,\n _numberedListIndex,\n children,\n ) => {\n return new DocxTable({\n layout: \"autofit\",\n borders: {\n bottom: { style: \"nil\" },\n top: { style: \"nil\" },\n left: { style: \"nil\" },\n right: { style: \"nil\" },\n insideHorizontal: { style: \"nil\" },\n insideVertical: { style: \"nil\" },\n },\n rows: [\n new TableRow({\n children: (children as unknown as TableCell[]).map(\n (cell, _index, children) => {\n return new TableCell({\n width: {\n size: `${(parseFloat(`${cell.options.width?.size || \"100%\"}`) / (children.length * 100)) * 100}%`,\n type: \"pct\",\n },\n children: cell.options.children,\n });\n },\n ),\n }),\n ],\n });\n },\n image: async (block, exporter) => {\n const blob = await exporter.resolveFile(block.props.url);\n const { width, height } = await getImageDimensions(blob);\n\n return [\n new Paragraph({\n ...blockPropsToStyles(block.props, exporter.options.colors),\n children: [\n new ImageRun({\n data: await blob.arrayBuffer(),\n // it would be nicer to set the actual data type here, but then we'd need to use a mime type / image type\n // detector. atm passing gif does not seem to be causing issues as the \"type\" is mainly used by docxjs internally\n // (i.e.: to make sure it's not svg)\n type: \"gif\",\n altText: block.props.caption\n ? {\n description: block.props.caption,\n name: block.props.caption,\n title: block.props.caption,\n }\n : undefined,\n transformation: {\n width: block.props.previewWidth || width,\n height: ((block.props.previewWidth || width) / width) * height,\n },\n }),\n ],\n }),\n ...caption(block.props, exporter),\n ];\n },\n table: (block, exporter) => {\n return Table(block.content, exporter);\n },\n};\n\nfunction file(\n props: Partial<DefaultProps & { name: string; url: string }>,\n defaultText: string,\n exporter: any,\n) {\n return new Paragraph({\n ...blockPropsToStyles(props, exporter.options.colors),\n children: [\n new ExternalHyperlink({\n children: [\n new TextRun({\n text: props.name || defaultText,\n style: \"Hyperlink\",\n }),\n ],\n link: props.url!,\n }),\n ],\n });\n}\n\nfunction caption(\n props: Partial<DefaultProps & { caption: string }>,\n exporter: any,\n) {\n if (!props.caption) {\n return [];\n }\n return [\n new Paragraph({\n ...blockPropsToStyles(props, exporter.options.colors),\n children: [\n new TextRun({\n text: props.caption,\n }),\n ],\n style: \"Caption\",\n }),\n ];\n}\n","import {\n DefaultInlineContentSchema,\n DefaultStyleSchema,\n InlineContentMapping,\n} from \"@blocknote/core\";\nimport { ExternalHyperlink, ParagraphChild, TextRun } from \"docx\";\nimport type { DOCXExporter } from \"../docxExporter.js\";\n\nexport const docxInlineContentMappingForDefaultSchema: InlineContentMapping<\n DefaultInlineContentSchema,\n DefaultStyleSchema,\n ParagraphChild,\n TextRun\n> = {\n link: (ic, exporter) => {\n return new ExternalHyperlink({\n children: ic.content.map((content) => {\n return (exporter as DOCXExporter<any, any, any>).transformStyledText(\n content,\n true,\n );\n }),\n link: ic.href,\n });\n },\n text: (ic, t) => {\n return t.transformStyledText(ic);\n },\n};\n","import { DefaultStyleSchema, StyleMapping } from \"@blocknote/core\";\nimport { IRunPropertiesOptions } from \"docx\";\n\nexport const docxStyleMappingForDefaultSchema: StyleMapping<\n DefaultStyleSchema,\n IRunPropertiesOptions\n> = {\n bold: (val) => {\n if (!val) {\n return {};\n }\n return {\n bold: val,\n };\n },\n italic: (val) => {\n if (!val) {\n return {};\n }\n return {\n italics: val,\n };\n },\n underline: (val) => {\n if (!val) {\n return {};\n }\n return {\n underline: {\n type: \"single\",\n },\n };\n },\n strike: (val) => {\n if (!val) {\n return {};\n }\n return {\n strike: val,\n };\n },\n backgroundColor: (val, exporter) => {\n if (!val) {\n return {};\n }\n return {\n shading: {\n fill: exporter.options.colors[\n val as keyof typeof exporter.options.colors\n ].background.slice(1),\n },\n };\n },\n textColor: (val, exporter) => {\n if (!val) {\n return {};\n }\n return {\n color:\n exporter.options.colors[\n val as keyof typeof exporter.options.colors\n ].text.slice(1),\n };\n },\n code: (val) => {\n if (!val) {\n return {};\n }\n return {\n font: \"GeistMono\",\n };\n },\n};\n","import { docxBlockMappingForDefaultSchema } from \"./blocks.js\";\nimport { docxInlineContentMappingForDefaultSchema } from \"./inlinecontent.js\";\nimport { docxStyleMappingForDefaultSchema } from \"./styles.js\";\n\nexport const docxDefaultSchemaMappings = {\n blockMapping: docxBlockMappingForDefaultSchema,\n inlineContentMapping: docxInlineContentMappingForDefaultSchema,\n styleMapping: docxStyleMappingForDefaultSchema,\n};\n","export async function corsProxyResolveFileUrl(url: string) {\n return (\n \"https://corsproxy.api.blocknotejs.org/corsproxy/?url=\" +\n encodeURIComponent(url)\n );\n}\n","/**\n *\n * Helper functions so that we can import files both on vitest, browser and node\n * TODO: should find a way to test automatically in all environments\n */\n\nexport async function loadFileDataUrl(\n requireUrl: { default: string },\n mimeType: string,\n) {\n if (import.meta.env.NODE_ENV === \"test\") {\n const buffer = await loadFileBuffer(requireUrl);\n const fileBase64 = buffer.toString(\"base64\");\n\n const dataUrl = `data:${mimeType};base64,${fileBase64}`;\n return dataUrl;\n } else {\n // in browser, this is already a data url\n return requireUrl.default as string;\n }\n}\n\nexport async function loadFontDataUrl(requireUrl: { default: string }) {\n return loadFileDataUrl(requireUrl, \"font/ttf\");\n}\n\nexport async function loadFileBuffer(requireUrl: {\n default: string;\n}): Promise<Buffer | ArrayBuffer> {\n if (import.meta.env.NODE_ENV === \"test\") {\n // in vitest, this is the url we need to load with readfilesync\n // eslint-disable-next-line\n const fs = require(\"fs\");\n let url = requireUrl.default;\n\n if (url.startsWith(\"/@fs/\")) {\n url = url.substring(\"/@fs\".length);\n }\n // On Windows, vite/vitest may yield paths like \"/C:/...\" after removing /@fs\n // Node on Windows treats paths starting with \"/\" as relative to current drive,\n // which would produce \"C:\\C:\\...\". Strip leading slash when followed by a drive letter.\n if (/^\\/[A-Za-z]:/.test(url)) {\n url = url.slice(1);\n }\n const buffer = fs.readFileSync(url);\n return buffer;\n } else {\n // in browser, this is already a data url\n const dataUrl = requireUrl.default as string;\n // convert to buffer on browser\n const response = await fetch(dataUrl);\n const arrayBuffer = await response.arrayBuffer();\n return arrayBuffer;\n }\n}\n\n/**\n * usage:\n * \n * await loadFontDataUrl(\n await import(\"../fonts/inter/Inter_18pt-Italic.ttf\")\n );\n */\n","import {\n Block,\n BlockNoteSchema,\n BlockSchema,\n COLORS_DEFAULT,\n InlineContentSchema,\n StyleSchema,\n StyledText,\n} from \"@blocknote/core\";\nimport {\n AlignmentType,\n Document,\n IRunPropertiesOptions,\n ISectionOptions,\n LevelFormat,\n Packer,\n Paragraph,\n ParagraphChild,\n Tab,\n Table,\n TextRun,\n} from \"docx\";\n\nimport { Exporter, ExporterOptions } from \"@blocknote/core\";\nimport { corsProxyResolveFileUrl } from \"@shared/api/corsProxy.js\";\nimport { loadFileBuffer } from \"@shared/util/fileUtil.js\";\n\n// get constructor arg type from Document\ntype DocumentOptions = Partial<ConstructorParameters<typeof Document>[0]>;\n\nconst DEFAULT_TAB_STOP =\n /* default font size */ 16 *\n /* 1 pixel is 0.75 points */ 0.75 *\n /* 1.5em*/ 1.5 *\n /* 1 point is 20 twips */ 20;\n\n/**\n * Exports a BlockNote document to a .docx file using the docxjs library.\n */\nexport class DOCXExporter<\n B extends BlockSchema,\n S extends StyleSchema,\n I extends InlineContentSchema,\n> extends Exporter<\n B,\n I,\n S,\n Promise<Paragraph[] | Paragraph | Table> | Paragraph[] | Paragraph | Table,\n ParagraphChild,\n IRunPropertiesOptions,\n TextRun\n> {\n public constructor(\n /**\n * The schema of your editor. The mappings are automatically typed checked against this schema.\n */\n protected readonly schema: BlockNoteSchema<B, I, S>,\n /**\n * The mappings that map the BlockNote schema to the docxjs content.\n * Pass {@link docxDefaultSchemaMappings} for the default schema.\n */\n protected readonly mappings: Exporter<\n NoInfer<B>,\n NoInfer<I>,\n NoInfer<S>,\n | Promise<Paragraph[] | Paragraph | Table>\n | Paragraph[]\n | Paragraph\n | Table,\n ParagraphChild,\n IRunPropertiesOptions,\n TextRun\n >[\"mappings\"],\n options?: Partial<ExporterOptions>,\n ) {\n const defaults = {\n colors: COLORS_DEFAULT,\n resolveFileUrl: corsProxyResolveFileUrl,\n } satisfies Partial<ExporterOptions>;\n\n const newOptions = {\n ...defaults,\n ...options,\n };\n super(schema, mappings, newOptions);\n }\n\n /**\n * Mostly for internal use, you probably want to use `toBlob` or `toDocxJsDocument` instead.\n */\n public transformStyledText(styledText: StyledText<S>, hyperlink?: boolean) {\n const stylesArray = this.mapStyles(styledText.styles);\n\n const styles: IRunPropertiesOptions = Object.assign(\n {} as IRunPropertiesOptions,\n ...stylesArray,\n );\n\n return new TextRun({\n ...styles,\n style: hyperlink ? \"Hyperlink\" : undefined,\n text: styledText.text,\n });\n }\n\n /**\n * Mostly for internal use, you probably want to use `toBlob` or `toDocxJsDocument` instead.\n */\n public async transformBlocks(\n blocks: Block<B, I, S>[],\n nestingLevel = 0,\n ): Promise<Array<Paragraph | Table>> {\n const ret: Array<Paragraph | Table> = [];\n\n for (const b of blocks) {\n let children = await this.transformBlocks(b.children, nestingLevel + 1);\n\n if (![\"columnList\", \"column\"].includes(b.type)) {\n children = children.map((c, _i) => {\n // NOTE: nested tables not supported (we can't insert the new Tab before a table)\n if (\n c instanceof Paragraph &&\n !(c as any).properties.numberingReferences.length\n ) {\n c.addRunToFront(\n new TextRun({\n children: [new Tab()],\n }),\n );\n }\n return c;\n });\n }\n\n const self = await this.mapBlock(\n b as any,\n nestingLevel,\n 0 /*unused*/,\n children,\n ); // TODO: any\n if ([\"columnList\", \"column\"].includes(b.type)) {\n ret.push(self as Table);\n } else if (Array.isArray(self)) {\n ret.push(...self, ...children);\n } else {\n ret.push(self, ...children);\n }\n }\n return ret;\n }\n\n protected async getFonts(): Promise<DocumentOptions[\"fonts\"]> {\n // Unfortunately, loading the variable font doesn't work\n // \"./src/fonts/Inter-VariableFont_opsz,wght.ttf\",\n\n let interFont = await loadFileBuffer(\n await import(\"@shared/assets/fonts/inter/Inter_18pt-Regular.ttf\"),\n );\n let geistMonoFont = await loadFileBuffer(\n await import(\"@shared/assets/fonts/GeistMono-Regular.ttf\"),\n );\n\n if (\n interFont instanceof ArrayBuffer ||\n geistMonoFont instanceof ArrayBuffer\n ) {\n // conversion with Polyfill needed because docxjs requires Buffer\n // NOTE: the buffer/ import is intentional and as documented in\n // the `buffer` package usage instructions\n // https://github.com/feross/buffer?tab=readme-ov-file#usage\n const Buffer = (await import(\"buffer/\")).Buffer;\n\n if (interFont instanceof ArrayBuffer) {\n interFont = Buffer.from(interFont) as unknown as Buffer;\n }\n if (geistMonoFont instanceof ArrayBuffer) {\n geistMonoFont = Buffer.from(geistMonoFont) as unknown as Buffer;\n }\n }\n\n return [\n { name: \"Inter\", data: interFont },\n {\n name: \"GeistMono\",\n data: geistMonoFont,\n },\n ];\n }\n\n protected async createDefaultDocumentOptions(\n locale?: string,\n ): Promise<DocumentOptions> {\n let externalStyles = (await import(\"./template/word/styles.xml?raw\"))\n .default;\n\n // Replace the default language in styles.xml with the provided locale.\n // If not provided, default to en-US.\n const resolvedLocale = (locale && locale.trim()) || \"en-US\";\n\n externalStyles = externalStyles.replace(\n /(<w:lang\\b[^>]*\\bw:val=\")([^\"]+)(\"[^>]*\\/>)/g,\n `$1${resolvedLocale}$3`,\n );\n\n const bullets = [\"•\"]; //, \"◦\", \"▪\"]; (these don't look great, just use solid bullet for now)\n return {\n numbering: {\n config: [\n {\n reference: \"blocknote-numbered-list\",\n levels: Array.from({ length: 9 }, (_, i) => ({\n start: 1,\n level: i,\n format: LevelFormat.DECIMAL,\n text: `%${i + 1}.`,\n alignment: AlignmentType.LEFT,\n style: {\n paragraph: {\n indent: {\n left: DEFAULT_TAB_STOP * (i + 1),\n hanging: DEFAULT_TAB_STOP,\n },\n },\n },\n })),\n },\n {\n reference: \"blocknote-bullet-list\",\n levels: Array.from({ length: 9 }, (_, i) => ({\n start: 1,\n level: i,\n format: LevelFormat.BULLET,\n text: bullets[i % bullets.length],\n alignment: AlignmentType.LEFT,\n style: {\n paragraph: {\n indent: {\n left: DEFAULT_TAB_STOP * (i + 1),\n hanging: DEFAULT_TAB_STOP,\n },\n },\n },\n })),\n },\n ],\n },\n fonts: await this.getFonts(),\n defaultTabStop: 200,\n externalStyles,\n };\n }\n\n /**\n * Convert a document (array of Blocks to a Blob representing a .docx file)\n */\n public async toBlob(\n blocks: Block<B, I, S>[],\n options: {\n sectionOptions: Omit<ISectionOptions, \"children\">;\n documentOptions: DocumentOptions;\n /**\n * The document locale in OOXML format (e.g. en-US, fr-FR, de-DE).\n * If omitted, defaults to en-US.\n */\n locale?: string;\n } = {\n sectionOptions: {},\n documentOptions: {},\n },\n ) {\n const doc = await this.toDocxJsDocument(blocks, options);\n type GlobalThis = typeof globalThis & { Buffer?: any };\n const prevBuffer = (globalThis as GlobalThis).Buffer;\n try {\n if (!(globalThis as GlobalThis).Buffer) {\n // load Buffer polyfill because docxjs requires this\n (globalThis as GlobalThis).Buffer = (\n await import(\"buffer\")\n ).default.Buffer;\n }\n return Packer.toBlob(doc);\n } finally {\n (globalThis as GlobalThis).Buffer = prevBuffer;\n }\n }\n\n /**\n * Convert a document (array of Blocks to a docxjs Document)\n */\n public async toDocxJsDocument(\n blocks: Block<B, I, S>[],\n options: {\n sectionOptions: Omit<ISectionOptions, \"children\">;\n documentOptions: DocumentOptions;\n /**\n * The document locale in OOXML format (e.g. en-US, fr-FR, de-DE).\n * If omitted, defaults to en-US.\n */\n locale?: string;\n } = {\n sectionOptions: {},\n documentOptions: {},\n },\n ) {\n const doc = new Document({\n ...(await this.createDefaultDocumentOptions(options.locale)),\n ...options.documentOptions,\n sections: [\n {\n children: await this.transformBlocks(blocks),\n ...options.sectionOptions,\n },\n ],\n });\n\n return doc;\n }\n}\n"],"names":["getImageDimensions","blob","bmp","width","height","imageMetaFunc","bytes","meta","Table","data","headerRows","headerCols","DocxTable","w","row","rowIndex","isHeaderRow","TableRow","c","colIndex","_a","cell","mapTableCell","isHeaderColumn","TableCell","ShadingType","Paragraph","UnreachableCaseError","blockPropsToStyles","props","colors","docxBlockMappingForDefaultSchema","block","exporter","TextRun","nestingLevel","CheckBox","file","caption","textContent","line","index","PageBreak","_exporter","_nestingLevel","_numberedListIndex","children","child","_block","_index","ImageRun","defaultText","ExternalHyperlink","docxInlineContentMappingForDefaultSchema","ic","content","docxStyleMappingForDefaultSchema","val","docxDefaultSchemaMappings","corsProxyResolveFileUrl","url","loadFileBuffer","requireUrl","dataUrl","DEFAULT_TAB_STOP","DOCXExporter","Exporter","schema","mappings","options","newOptions","COLORS_DEFAULT","styledText","hyperlink","stylesArray","styles","blocks","ret","b","_i","Tab","self","interFont","geistMonoFont","Buffer","n","locale","externalStyles","resolvedLocale","bullets","_","i","LevelFormat","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,EAQI,CACF,eAAgB,CAAC,EACjB,gBAAiB,CAAA,CAAC,EAEpB,CAYO,OAXK,IAAI4B,WAAS,CACvB,GAAI,MAAM,KAAK,6BAA6B5B,EAAQ,MAAM,EAC1D,GAAGA,EAAQ,gBACX,SAAU,CACR,CACE,SAAU,MAAM,KAAK,gBAAgBO,CAAM,EAC3C,GAAGP,EAAQ,cAAA,CACb,CACF,CACD,CAEM,CAEX"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { mapTableCell as
|
|
2
|
-
import { Table as D, TableRow as I, TableCell as g, Paragraph as
|
|
1
|
+
import { mapTableCell as O, UnreachableCaseError as T, Exporter as k, COLORS_DEFAULT as F } from "@blocknote/core";
|
|
2
|
+
import { Table as D, TableRow as I, TableCell as g, Paragraph as a, ShadingType as w, ImageRun as S, PageBreak as _, TextRun as p, CheckBox as M, ExternalHyperlink as L, Tab as U, AlignmentType as C, LevelFormat as A, Packer as E, Document as R } from "docx";
|
|
3
3
|
async function H(e) {
|
|
4
4
|
if (typeof window < "u") {
|
|
5
5
|
const t = await createImageBitmap(e), { width: n, height: r } = t;
|
|
@@ -11,7 +11,7 @@ async function H(e) {
|
|
|
11
11
|
return { width: r.width, height: r.height };
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
|
-
const
|
|
14
|
+
const $ = (e, t) => {
|
|
15
15
|
const r = new Array(e.headerRows ?? 0).fill(!0), o = new Array(e.headerCols ?? 0).fill(!0);
|
|
16
16
|
return new D({
|
|
17
17
|
layout: "autofit",
|
|
@@ -20,38 +20,38 @@ const W = (e, t) => {
|
|
|
20
20
|
0.75 * /* to twips */
|
|
21
21
|
20
|
|
22
22
|
),
|
|
23
|
-
rows: e.rows.map((i,
|
|
24
|
-
const
|
|
23
|
+
rows: e.rows.map((i, s) => {
|
|
24
|
+
const u = r[s];
|
|
25
25
|
return new I({
|
|
26
|
-
tableHeader:
|
|
26
|
+
tableHeader: u,
|
|
27
27
|
children: i.cells.map((d, y) => {
|
|
28
28
|
var b;
|
|
29
|
-
const x = (b = e.columnWidths) == null ? void 0 : b[y],
|
|
29
|
+
const x = (b = e.columnWidths) == null ? void 0 : b[y], l = O(d), v = o[y];
|
|
30
30
|
return new g({
|
|
31
31
|
width: x ? {
|
|
32
32
|
size: `${x * 0.75}pt`,
|
|
33
33
|
type: "dxa"
|
|
34
34
|
} : void 0,
|
|
35
|
-
columnSpan:
|
|
36
|
-
rowSpan:
|
|
37
|
-
shading:
|
|
35
|
+
columnSpan: l.props.colspan,
|
|
36
|
+
rowSpan: l.props.rowspan,
|
|
37
|
+
shading: l.props.backgroundColor === "default" || !l.props.backgroundColor ? void 0 : {
|
|
38
38
|
type: w.SOLID,
|
|
39
|
-
color: t.options.colors[
|
|
39
|
+
color: t.options.colors[l.props.backgroundColor].background.slice(1)
|
|
40
40
|
},
|
|
41
41
|
children: [
|
|
42
|
-
new
|
|
43
|
-
children: t.transformInlineContent(
|
|
44
|
-
alignment: !
|
|
42
|
+
new a({
|
|
43
|
+
children: t.transformInlineContent(l.content),
|
|
44
|
+
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" : (() => {
|
|
45
45
|
throw new T(
|
|
46
|
-
|
|
46
|
+
l.props.textAlignment
|
|
47
47
|
);
|
|
48
48
|
})(),
|
|
49
49
|
run: {
|
|
50
50
|
// TODO add support for table headers exporting, bolding seems to not be working at the moment
|
|
51
|
-
bold:
|
|
51
|
+
bold: u || v,
|
|
52
52
|
// TODO table paragraph color seems to not be working at the moment
|
|
53
53
|
// Probably because the runs are setting their own color
|
|
54
|
-
color:
|
|
54
|
+
color: l.props.textColor === "default" || !l.props.textColor ? void 0 : t.options.colors[l.props.textColor].text.slice(1)
|
|
55
55
|
}
|
|
56
56
|
})
|
|
57
57
|
]
|
|
@@ -61,7 +61,7 @@ const W = (e, t) => {
|
|
|
61
61
|
})
|
|
62
62
|
});
|
|
63
63
|
};
|
|
64
|
-
function
|
|
64
|
+
function c(e, t) {
|
|
65
65
|
return {
|
|
66
66
|
shading: e.backgroundColor === "default" || !e.backgroundColor ? void 0 : {
|
|
67
67
|
type: w.SOLID,
|
|
@@ -75,17 +75,17 @@ function a(e, t) {
|
|
|
75
75
|
})()
|
|
76
76
|
};
|
|
77
77
|
}
|
|
78
|
-
const
|
|
79
|
-
paragraph: (e, t) => new
|
|
80
|
-
...
|
|
78
|
+
const W = {
|
|
79
|
+
paragraph: (e, t) => new a({
|
|
80
|
+
...c(e.props, t.options.colors),
|
|
81
81
|
children: t.transformInlineContent(e.content),
|
|
82
82
|
style: "Normal",
|
|
83
83
|
run: {
|
|
84
84
|
font: "Inter"
|
|
85
85
|
}
|
|
86
86
|
}),
|
|
87
|
-
toggleListItem: (e, t) => new
|
|
88
|
-
...
|
|
87
|
+
toggleListItem: (e, t) => new a({
|
|
88
|
+
...c(e.props, t.options.colors),
|
|
89
89
|
children: [
|
|
90
90
|
new p({
|
|
91
91
|
children: ["> "]
|
|
@@ -93,24 +93,24 @@ const $ = {
|
|
|
93
93
|
...t.transformInlineContent(e.content)
|
|
94
94
|
]
|
|
95
95
|
}),
|
|
96
|
-
numberedListItem: (e, t, n) => new
|
|
97
|
-
...
|
|
96
|
+
numberedListItem: (e, t, n) => new a({
|
|
97
|
+
...c(e.props, t.options.colors),
|
|
98
98
|
children: t.transformInlineContent(e.content),
|
|
99
99
|
numbering: {
|
|
100
100
|
reference: "blocknote-numbered-list",
|
|
101
101
|
level: n
|
|
102
102
|
}
|
|
103
103
|
}),
|
|
104
|
-
bulletListItem: (e, t, n) => new
|
|
105
|
-
...
|
|
104
|
+
bulletListItem: (e, t, n) => new a({
|
|
105
|
+
...c(e.props, t.options.colors),
|
|
106
106
|
children: t.transformInlineContent(e.content),
|
|
107
107
|
numbering: {
|
|
108
108
|
reference: "blocknote-bullet-list",
|
|
109
109
|
level: n
|
|
110
110
|
}
|
|
111
111
|
}),
|
|
112
|
-
checkListItem: (e, t) => new
|
|
113
|
-
...
|
|
112
|
+
checkListItem: (e, t) => new a({
|
|
113
|
+
...c(e.props, t.options.colors),
|
|
114
114
|
children: [
|
|
115
115
|
new M({ checked: e.props.checked }),
|
|
116
116
|
new p({
|
|
@@ -119,12 +119,12 @@ const $ = {
|
|
|
119
119
|
...t.transformInlineContent(e.content)
|
|
120
120
|
]
|
|
121
121
|
}),
|
|
122
|
-
heading: (e, t) => new
|
|
123
|
-
...
|
|
122
|
+
heading: (e, t) => new a({
|
|
123
|
+
...c(e.props, t.options.colors),
|
|
124
124
|
children: t.transformInlineContent(e.content),
|
|
125
125
|
heading: `Heading${e.props.level}`
|
|
126
126
|
}),
|
|
127
|
-
quote: (e, t) => new
|
|
127
|
+
quote: (e, t) => new a({
|
|
128
128
|
shading: {
|
|
129
129
|
color: "#7D797A"
|
|
130
130
|
},
|
|
@@ -136,25 +136,25 @@ const $ = {
|
|
|
136
136
|
size: 8
|
|
137
137
|
}
|
|
138
138
|
},
|
|
139
|
-
...
|
|
139
|
+
...c(e.props, t.options.colors),
|
|
140
140
|
children: t.transformInlineContent(e.content)
|
|
141
141
|
}),
|
|
142
142
|
audio: (e, t) => [
|
|
143
|
-
|
|
143
|
+
h(e.props, "Open audio", t),
|
|
144
144
|
...f(e.props, t)
|
|
145
145
|
],
|
|
146
146
|
video: (e, t) => [
|
|
147
|
-
|
|
147
|
+
h(e.props, "Open video", t),
|
|
148
148
|
...f(e.props, t)
|
|
149
149
|
],
|
|
150
150
|
file: (e, t) => [
|
|
151
|
-
|
|
151
|
+
h(e.props, "Open file", t),
|
|
152
152
|
...f(e.props, t)
|
|
153
153
|
],
|
|
154
154
|
codeBlock: (e) => {
|
|
155
155
|
var n;
|
|
156
156
|
const t = ((n = e.content[0]) == null ? void 0 : n.text) || "";
|
|
157
|
-
return new
|
|
157
|
+
return new a({
|
|
158
158
|
style: "Codeblock",
|
|
159
159
|
shading: {
|
|
160
160
|
type: w.SOLID,
|
|
@@ -170,7 +170,7 @@ const $ = {
|
|
|
170
170
|
]
|
|
171
171
|
});
|
|
172
172
|
},
|
|
173
|
-
pageBreak: () => new
|
|
173
|
+
pageBreak: () => new a({
|
|
174
174
|
children: [new _()]
|
|
175
175
|
}),
|
|
176
176
|
column: (e, t, n, r, o) => new g({
|
|
@@ -193,11 +193,11 @@ const $ = {
|
|
|
193
193
|
rows: [
|
|
194
194
|
new I({
|
|
195
195
|
children: o.map(
|
|
196
|
-
(i,
|
|
196
|
+
(i, s, u) => {
|
|
197
197
|
var d;
|
|
198
198
|
return new g({
|
|
199
199
|
width: {
|
|
200
|
-
size: `${parseFloat(`${((d = i.options.width) == null ? void 0 : d.size) || "100%"}`) / (
|
|
200
|
+
size: `${parseFloat(`${((d = i.options.width) == null ? void 0 : d.size) || "100%"}`) / (u.length * 100) * 100}%`,
|
|
201
201
|
type: "pct"
|
|
202
202
|
},
|
|
203
203
|
children: i.options.children
|
|
@@ -210,8 +210,8 @@ const $ = {
|
|
|
210
210
|
image: async (e, t) => {
|
|
211
211
|
const n = await t.resolveFile(e.props.url), { width: r, height: o } = await H(n);
|
|
212
212
|
return [
|
|
213
|
-
new
|
|
214
|
-
...
|
|
213
|
+
new a({
|
|
214
|
+
...c(e.props, t.options.colors),
|
|
215
215
|
children: [
|
|
216
216
|
new S({
|
|
217
217
|
data: await n.arrayBuffer(),
|
|
@@ -234,11 +234,11 @@ const $ = {
|
|
|
234
234
|
...f(e.props, t)
|
|
235
235
|
];
|
|
236
236
|
},
|
|
237
|
-
table: (e, t) =>
|
|
237
|
+
table: (e, t) => $(e.content, t)
|
|
238
238
|
};
|
|
239
|
-
function
|
|
240
|
-
return new
|
|
241
|
-
...
|
|
239
|
+
function h(e, t, n) {
|
|
240
|
+
return new a({
|
|
241
|
+
...c(e, n.options.colors),
|
|
242
242
|
children: [
|
|
243
243
|
new L({
|
|
244
244
|
children: [
|
|
@@ -254,8 +254,8 @@ function m(e, t, n) {
|
|
|
254
254
|
}
|
|
255
255
|
function f(e, t) {
|
|
256
256
|
return e.caption ? [
|
|
257
|
-
new
|
|
258
|
-
...
|
|
257
|
+
new a({
|
|
258
|
+
...c(e, t.options.colors),
|
|
259
259
|
children: [
|
|
260
260
|
new p({
|
|
261
261
|
text: e.caption
|
|
@@ -301,7 +301,7 @@ const z = {
|
|
|
301
301
|
font: "GeistMono"
|
|
302
302
|
} : {}
|
|
303
303
|
}, J = {
|
|
304
|
-
blockMapping:
|
|
304
|
+
blockMapping: W,
|
|
305
305
|
inlineContentMapping: z,
|
|
306
306
|
styleMapping: P
|
|
307
307
|
};
|
|
@@ -314,14 +314,14 @@ async function B(e) {
|
|
|
314
314
|
return await (await fetch(t)).arrayBuffer();
|
|
315
315
|
}
|
|
316
316
|
}
|
|
317
|
-
const
|
|
317
|
+
const m = (
|
|
318
318
|
/* default font size */
|
|
319
319
|
16 * /* 1 pixel is 0.75 points */
|
|
320
320
|
0.75 * /* 1.5em*/
|
|
321
321
|
1.5 * /* 1 point is 20 twips */
|
|
322
322
|
20
|
|
323
323
|
);
|
|
324
|
-
class q extends
|
|
324
|
+
class q extends k {
|
|
325
325
|
constructor(t, n, r) {
|
|
326
326
|
const i = {
|
|
327
327
|
...{
|
|
@@ -353,18 +353,18 @@ class q extends v {
|
|
|
353
353
|
const r = [];
|
|
354
354
|
for (const o of t) {
|
|
355
355
|
let i = await this.transformBlocks(o.children, n + 1);
|
|
356
|
-
["columnList", "column"].includes(o.type) || (i = i.map((
|
|
356
|
+
["columnList", "column"].includes(o.type) || (i = i.map((u, d) => (u instanceof a && !u.properties.numberingReferences.length && u.addRunToFront(
|
|
357
357
|
new p({
|
|
358
|
-
children: [new
|
|
358
|
+
children: [new U()]
|
|
359
359
|
})
|
|
360
|
-
),
|
|
361
|
-
const
|
|
360
|
+
), u)));
|
|
361
|
+
const s = await this.mapBlock(
|
|
362
362
|
o,
|
|
363
363
|
n,
|
|
364
364
|
0,
|
|
365
365
|
i
|
|
366
366
|
);
|
|
367
|
-
["columnList", "column"].includes(o.type) ? r.push(
|
|
367
|
+
["columnList", "column"].includes(o.type) ? r.push(s) : Array.isArray(s) ? r.push(...s, ...i) : r.push(s, ...i);
|
|
368
368
|
}
|
|
369
369
|
return r;
|
|
370
370
|
}
|
|
@@ -386,24 +386,30 @@ class q extends v {
|
|
|
386
386
|
}
|
|
387
387
|
];
|
|
388
388
|
}
|
|
389
|
-
async createDefaultDocumentOptions() {
|
|
390
|
-
|
|
389
|
+
async createDefaultDocumentOptions(t) {
|
|
390
|
+
let n = (await import("./styles-CujW8HHo.js")).default;
|
|
391
|
+
const r = t && t.trim() || "en-US";
|
|
392
|
+
n = n.replace(
|
|
393
|
+
/(<w:lang\b[^>]*\bw:val=")([^"]+)("[^>]*\/>)/g,
|
|
394
|
+
`$1${r}$3`
|
|
395
|
+
);
|
|
396
|
+
const o = ["•"];
|
|
391
397
|
return {
|
|
392
398
|
numbering: {
|
|
393
399
|
config: [
|
|
394
400
|
{
|
|
395
401
|
reference: "blocknote-numbered-list",
|
|
396
|
-
levels: Array.from({ length: 9 }, (
|
|
402
|
+
levels: Array.from({ length: 9 }, (i, s) => ({
|
|
397
403
|
start: 1,
|
|
398
|
-
level:
|
|
404
|
+
level: s,
|
|
399
405
|
format: A.DECIMAL,
|
|
400
|
-
text: `%${
|
|
406
|
+
text: `%${s + 1}.`,
|
|
401
407
|
alignment: C.LEFT,
|
|
402
408
|
style: {
|
|
403
409
|
paragraph: {
|
|
404
410
|
indent: {
|
|
405
|
-
left:
|
|
406
|
-
hanging:
|
|
411
|
+
left: m * (s + 1),
|
|
412
|
+
hanging: m
|
|
407
413
|
}
|
|
408
414
|
}
|
|
409
415
|
}
|
|
@@ -411,17 +417,17 @@ class q extends v {
|
|
|
411
417
|
},
|
|
412
418
|
{
|
|
413
419
|
reference: "blocknote-bullet-list",
|
|
414
|
-
levels: Array.from({ length: 9 }, (
|
|
420
|
+
levels: Array.from({ length: 9 }, (i, s) => ({
|
|
415
421
|
start: 1,
|
|
416
|
-
level:
|
|
422
|
+
level: s,
|
|
417
423
|
format: A.BULLET,
|
|
418
|
-
text:
|
|
424
|
+
text: o[s % o.length],
|
|
419
425
|
alignment: C.LEFT,
|
|
420
426
|
style: {
|
|
421
427
|
paragraph: {
|
|
422
428
|
indent: {
|
|
423
|
-
left:
|
|
424
|
-
hanging:
|
|
429
|
+
left: m * (s + 1),
|
|
430
|
+
hanging: m
|
|
425
431
|
}
|
|
426
432
|
}
|
|
427
433
|
}
|
|
@@ -431,7 +437,7 @@ class q extends v {
|
|
|
431
437
|
},
|
|
432
438
|
fonts: await this.getFonts(),
|
|
433
439
|
defaultTabStop: 200,
|
|
434
|
-
externalStyles:
|
|
440
|
+
externalStyles: n
|
|
435
441
|
};
|
|
436
442
|
}
|
|
437
443
|
/**
|
|
@@ -443,7 +449,7 @@ class q extends v {
|
|
|
443
449
|
}) {
|
|
444
450
|
const r = await this.toDocxJsDocument(t, n), o = globalThis.Buffer;
|
|
445
451
|
try {
|
|
446
|
-
return globalThis.Buffer || (globalThis.Buffer = (await import("buffer")).default.Buffer),
|
|
452
|
+
return globalThis.Buffer || (globalThis.Buffer = (await import("buffer")).default.Buffer), E.toBlob(r);
|
|
447
453
|
} finally {
|
|
448
454
|
globalThis.Buffer = o;
|
|
449
455
|
}
|
|
@@ -456,7 +462,7 @@ class q extends v {
|
|
|
456
462
|
documentOptions: {}
|
|
457
463
|
}) {
|
|
458
464
|
return new R({
|
|
459
|
-
...await this.createDefaultDocumentOptions(),
|
|
465
|
+
...await this.createDefaultDocumentOptions(n.locale),
|
|
460
466
|
...n.documentOptions,
|
|
461
467
|
sections: [
|
|
462
468
|
{
|