Compare commits
31 Commits
feat/parag
...
5.5.0
Author | SHA1 | Date | |
---|---|---|---|
d6f363b275 | |||
118ea57412 | |||
7c8be4c8a7 | |||
fa9021596f | |||
3ccf4bdfe3 | |||
f2480673ec | |||
e93b8032d8 | |||
5de2d8c7fb | |||
e355fd3d2e | |||
d41ef99c85 | |||
5ec18d6e01 | |||
b4cd3a319c | |||
d894bfa167 | |||
d74db948ba | |||
3ef26c747b | |||
38c8220e9e | |||
86f8259b33 | |||
502db14bba | |||
ef12ada5d7 | |||
977b2b302d | |||
17d02a3d1c | |||
6100ff4c4e | |||
8bb73fb25e | |||
d6cce4ae15 | |||
058304d16b | |||
345d34a2e1 | |||
3839a49d47 | |||
0afe0929a3 | |||
a14a1fbd10 | |||
52f0a6958a | |||
8bdde98db1 |
@ -7,6 +7,7 @@ indent_style = space
|
||||
indent_size = 4
|
||||
insert_final_newline = true
|
||||
trim_trailing_whitespace = true
|
||||
end_of_line = lf
|
||||
|
||||
[*.md]
|
||||
max_line_length = off
|
||||
|
@ -204,7 +204,10 @@ class DocumentCreator {
|
||||
alignment: AlignmentType.CENTER,
|
||||
children: [
|
||||
new TextRun(`Mobile: ${phoneNumber} | LinkedIn: ${profileUrl} | Email: ${email}`),
|
||||
new TextRun("Address: 58 Elm Avenue, Kent ME4 6ER, UK").break(),
|
||||
new TextRun({
|
||||
text: "Address: 58 Elm Avenue, Kent ME4 6ER, UK",
|
||||
break: 1,
|
||||
}),
|
||||
],
|
||||
});
|
||||
}
|
||||
|
@ -3,6 +3,7 @@
|
||||
import * as fs from "fs";
|
||||
import {
|
||||
AlignmentType,
|
||||
convertInchesToTwip,
|
||||
Document,
|
||||
Footer,
|
||||
HeadingLevel,
|
||||
@ -110,7 +111,7 @@ const doc = new Document({
|
||||
},
|
||||
paragraph: {
|
||||
spacing: { line: 276 },
|
||||
indent: { left: 720 },
|
||||
indent: { left: convertInchesToTwip(0.5) },
|
||||
},
|
||||
},
|
||||
{
|
||||
|
@ -1,7 +1,17 @@
|
||||
// Example on how to customise the look at feel using Styles
|
||||
// Import from 'docx' rather than '../build' if you install from npm
|
||||
import * as fs from "fs";
|
||||
import { AlignmentType, Document, HeadingLevel, Packer, Paragraph, TextRun, UnderlineType } from "../build";
|
||||
import {
|
||||
AlignmentType,
|
||||
convertInchesToTwip,
|
||||
Document,
|
||||
HeadingLevel,
|
||||
LevelFormat,
|
||||
Packer,
|
||||
Paragraph,
|
||||
TextRun,
|
||||
UnderlineType,
|
||||
} from "../build";
|
||||
|
||||
const doc = new Document({
|
||||
creator: "Clippy",
|
||||
@ -40,9 +50,9 @@ const doc = new Document({
|
||||
},
|
||||
listParagraph: {
|
||||
run: {
|
||||
color: '#FF0000'
|
||||
}
|
||||
}
|
||||
color: "#FF0000",
|
||||
},
|
||||
},
|
||||
},
|
||||
paragraphStyles: [
|
||||
{
|
||||
@ -56,7 +66,7 @@ const doc = new Document({
|
||||
},
|
||||
paragraph: {
|
||||
indent: {
|
||||
left: 720,
|
||||
left: convertInchesToTwip(0.5),
|
||||
},
|
||||
spacing: {
|
||||
line: 276,
|
||||
@ -81,7 +91,7 @@ const doc = new Document({
|
||||
levels: [
|
||||
{
|
||||
level: 0,
|
||||
format: "lowerLetter",
|
||||
format: LevelFormat.LOWER_LETTER,
|
||||
text: "%1)",
|
||||
alignment: AlignmentType.LEFT,
|
||||
},
|
||||
@ -161,6 +171,17 @@ doc.addSection({
|
||||
}),
|
||||
],
|
||||
}),
|
||||
new Paragraph({
|
||||
style: "Strong",
|
||||
children: [
|
||||
new TextRun({
|
||||
text: "Strong Style",
|
||||
}),
|
||||
new TextRun({
|
||||
text: " - Very strong.",
|
||||
}),
|
||||
],
|
||||
}),
|
||||
],
|
||||
});
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
// Custom styles using JavaScript configuration
|
||||
// Import from 'docx' rather than '../build' if you install from npm
|
||||
import * as fs from "fs";
|
||||
import { Document, HeadingLevel, Packer, Paragraph, UnderlineType } from "../build";
|
||||
import { Document, convertInchesToTwip, HeadingLevel, Packer, Paragraph, UnderlineType } from "../build";
|
||||
|
||||
const doc = new Document({
|
||||
styles: {
|
||||
@ -17,7 +17,7 @@ const doc = new Document({
|
||||
},
|
||||
paragraph: {
|
||||
indent: {
|
||||
left: 720,
|
||||
left: convertInchesToTwip(0.5),
|
||||
},
|
||||
spacing: {
|
||||
line: 276,
|
||||
|
@ -1,7 +1,7 @@
|
||||
// Numbered lists
|
||||
// Import from 'docx' rather than '../build' if you install from npm
|
||||
import * as fs from "fs";
|
||||
import { AlignmentType, Document, Packer, Paragraph } from "../build";
|
||||
import { AlignmentType, convertInchesToTwip, Document, LevelFormat, Packer, Paragraph } from "../build";
|
||||
|
||||
const doc = new Document({
|
||||
numbering: {
|
||||
@ -10,12 +10,12 @@ const doc = new Document({
|
||||
levels: [
|
||||
{
|
||||
level: 0,
|
||||
format: "upperRoman",
|
||||
format: LevelFormat.UPPER_ROMAN,
|
||||
text: "%1",
|
||||
alignment: AlignmentType.START,
|
||||
style: {
|
||||
paragraph: {
|
||||
indent: { left: 720, hanging: 260 },
|
||||
indent: { left: convertInchesToTwip(0.5), hanging: convertInchesToTwip(0.18) },
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -26,18 +26,34 @@ const doc = new Document({
|
||||
levels: [
|
||||
{
|
||||
level: 0,
|
||||
format: "decimal",
|
||||
format: LevelFormat.DECIMAL,
|
||||
text: "%1",
|
||||
alignment: AlignmentType.START,
|
||||
style: {
|
||||
paragraph: {
|
||||
indent: { left: 720, hanging: 260 },
|
||||
indent: { left: convertInchesToTwip(0.5), hanging: convertInchesToTwip(0.18) },
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
reference: "my-number-numbering-reference",
|
||||
},
|
||||
{
|
||||
levels: [
|
||||
{
|
||||
level: 0,
|
||||
format: LevelFormat.DECIMAL_ZERO,
|
||||
text: "[%1]",
|
||||
alignment: AlignmentType.START,
|
||||
style: {
|
||||
paragraph: {
|
||||
indent: { left: convertInchesToTwip(0.5), hanging: convertInchesToTwip(0.18) },
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
reference: "padded-numbering-reference",
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
@ -109,6 +125,139 @@ doc.addSection({
|
||||
level: 0,
|
||||
},
|
||||
}),
|
||||
new Paragraph({
|
||||
text: "test",
|
||||
numbering: {
|
||||
reference: "padded-numbering-reference",
|
||||
level: 0,
|
||||
},
|
||||
}),
|
||||
new Paragraph({
|
||||
text: "test",
|
||||
numbering: {
|
||||
reference: "padded-numbering-reference",
|
||||
level: 0,
|
||||
},
|
||||
}),
|
||||
new Paragraph({
|
||||
text: "test",
|
||||
numbering: {
|
||||
reference: "padded-numbering-reference",
|
||||
level: 0,
|
||||
},
|
||||
}),
|
||||
new Paragraph({
|
||||
text: "test",
|
||||
numbering: {
|
||||
reference: "padded-numbering-reference",
|
||||
level: 0,
|
||||
},
|
||||
}),
|
||||
new Paragraph({
|
||||
text: "test",
|
||||
numbering: {
|
||||
reference: "padded-numbering-reference",
|
||||
level: 0,
|
||||
},
|
||||
}),
|
||||
new Paragraph({
|
||||
text: "test",
|
||||
numbering: {
|
||||
reference: "padded-numbering-reference",
|
||||
level: 0,
|
||||
},
|
||||
}),
|
||||
new Paragraph({
|
||||
text: "test",
|
||||
numbering: {
|
||||
reference: "padded-numbering-reference",
|
||||
level: 0,
|
||||
},
|
||||
}),
|
||||
new Paragraph({
|
||||
text: "test",
|
||||
numbering: {
|
||||
reference: "padded-numbering-reference",
|
||||
level: 0,
|
||||
},
|
||||
}),
|
||||
new Paragraph({
|
||||
text: "test",
|
||||
numbering: {
|
||||
reference: "padded-numbering-reference",
|
||||
level: 0,
|
||||
},
|
||||
}),
|
||||
new Paragraph({
|
||||
text: "test",
|
||||
numbering: {
|
||||
reference: "padded-numbering-reference",
|
||||
level: 0,
|
||||
},
|
||||
}),
|
||||
new Paragraph({
|
||||
text: "test",
|
||||
numbering: {
|
||||
reference: "padded-numbering-reference",
|
||||
level: 0,
|
||||
},
|
||||
}),
|
||||
new Paragraph({
|
||||
text: "test",
|
||||
numbering: {
|
||||
reference: "padded-numbering-reference",
|
||||
level: 0,
|
||||
},
|
||||
}),
|
||||
new Paragraph({
|
||||
text: "test",
|
||||
numbering: {
|
||||
reference: "padded-numbering-reference",
|
||||
level: 0,
|
||||
},
|
||||
}),
|
||||
new Paragraph({
|
||||
text: "test",
|
||||
numbering: {
|
||||
reference: "padded-numbering-reference",
|
||||
level: 0,
|
||||
},
|
||||
}),
|
||||
new Paragraph({
|
||||
text: "test",
|
||||
numbering: {
|
||||
reference: "padded-numbering-reference",
|
||||
level: 0,
|
||||
},
|
||||
}),
|
||||
new Paragraph({
|
||||
text: "test",
|
||||
numbering: {
|
||||
reference: "padded-numbering-reference",
|
||||
level: 0,
|
||||
},
|
||||
}),
|
||||
new Paragraph({
|
||||
text: "test",
|
||||
numbering: {
|
||||
reference: "padded-numbering-reference",
|
||||
level: 0,
|
||||
},
|
||||
}),
|
||||
new Paragraph({
|
||||
text: "test",
|
||||
numbering: {
|
||||
reference: "padded-numbering-reference",
|
||||
level: 0,
|
||||
},
|
||||
}),
|
||||
new Paragraph({
|
||||
text: "test",
|
||||
numbering: {
|
||||
reference: "padded-numbering-reference",
|
||||
level: 0,
|
||||
},
|
||||
}),
|
||||
],
|
||||
});
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
// Numbering and bullet points example
|
||||
// Import from 'docx' rather than '../build' if you install from npm
|
||||
import * as fs from "fs";
|
||||
import { AlignmentType, Document, Packer, Paragraph } from "../build";
|
||||
import { AlignmentType, convertInchesToTwip, Document, LevelFormat, Packer, Paragraph } from "../build";
|
||||
|
||||
const doc = new Document({
|
||||
numbering: {
|
||||
@ -11,40 +11,40 @@ const doc = new Document({
|
||||
levels: [
|
||||
{
|
||||
level: 0,
|
||||
format: "upperRoman",
|
||||
format: LevelFormat.UPPER_ROMAN,
|
||||
text: "%1",
|
||||
alignment: AlignmentType.START,
|
||||
style: {
|
||||
paragraph: {
|
||||
indent: { left: 720, hanging: 260 },
|
||||
indent: { left: convertInchesToTwip(0.5), hanging: convertInchesToTwip(0.18) },
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
level: 1,
|
||||
format: "decimal",
|
||||
format: LevelFormat.DECIMAL,
|
||||
text: "%2.",
|
||||
alignment: AlignmentType.START,
|
||||
style: {
|
||||
paragraph: {
|
||||
indent: { left: 1440, hanging: 980 },
|
||||
indent: { left: convertInchesToTwip(1), hanging: convertInchesToTwip(0.68) },
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
level: 2,
|
||||
format: "lowerLetter",
|
||||
format: LevelFormat.LOWER_LETTER,
|
||||
text: "%3)",
|
||||
alignment: AlignmentType.START,
|
||||
style: {
|
||||
paragraph: {
|
||||
indent: { left: 2160, hanging: 1700 },
|
||||
indent: { left: convertInchesToTwip(1.5), hanging: convertInchesToTwip(1.18) },
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
level: 3,
|
||||
format: "upperLetter",
|
||||
format: LevelFormat.UPPER_LETTER,
|
||||
text: "%4)",
|
||||
alignment: AlignmentType.START,
|
||||
style: {
|
||||
|
@ -2,7 +2,20 @@
|
||||
// Also includes an example on how to center tables
|
||||
// Import from 'docx' rather than '../build' if you install from npm
|
||||
import * as fs from "fs";
|
||||
import { AlignmentType, BorderStyle, Document, HeadingLevel, Packer, Paragraph, ShadingType, Table, TableCell, TableRow, WidthType } from "../build";
|
||||
import {
|
||||
AlignmentType,
|
||||
BorderStyle,
|
||||
convertInchesToTwip,
|
||||
Document,
|
||||
HeadingLevel,
|
||||
Packer,
|
||||
Paragraph,
|
||||
ShadingType,
|
||||
Table,
|
||||
TableCell,
|
||||
TableRow,
|
||||
WidthType,
|
||||
} from "../build";
|
||||
|
||||
const doc = new Document();
|
||||
|
||||
@ -37,10 +50,10 @@ const table2 = new Table({
|
||||
new TableCell({
|
||||
children: [new Paragraph("World")],
|
||||
margins: {
|
||||
top: 1000,
|
||||
bottom: 1000,
|
||||
left: 1000,
|
||||
right: 1000,
|
||||
top: convertInchesToTwip(0.69),
|
||||
bottom: convertInchesToTwip(0.69),
|
||||
left: convertInchesToTwip(0.69),
|
||||
right: convertInchesToTwip(0.69),
|
||||
},
|
||||
columnSpan: 3,
|
||||
}),
|
||||
@ -64,7 +77,7 @@ const table2 = new Table({
|
||||
size: 100,
|
||||
type: WidthType.AUTO,
|
||||
},
|
||||
columnWidths: [1000, 1000, 1000],
|
||||
columnWidths: [convertInchesToTwip(0.69), convertInchesToTwip(0.69), convertInchesToTwip(0.69)],
|
||||
});
|
||||
|
||||
const table3 = new Table({
|
||||
@ -119,14 +132,14 @@ const table3 = new Table({
|
||||
}),
|
||||
],
|
||||
width: {
|
||||
size: 7000,
|
||||
size: convertInchesToTwip(4.86),
|
||||
type: WidthType.DXA,
|
||||
},
|
||||
margins: {
|
||||
top: 400,
|
||||
bottom: 400,
|
||||
right: 400,
|
||||
left: 400,
|
||||
top: convertInchesToTwip(0.27),
|
||||
bottom: convertInchesToTwip(0.27),
|
||||
right: convertInchesToTwip(0.27),
|
||||
left: convertInchesToTwip(0.27),
|
||||
},
|
||||
});
|
||||
|
||||
@ -355,9 +368,7 @@ const table8 = new Table({
|
||||
],
|
||||
}),
|
||||
new TableRow({
|
||||
children: [
|
||||
new TableCell({ children: [new Paragraph("4,1")] }),
|
||||
],
|
||||
children: [new TableCell({ children: [new Paragraph("4,1")] })],
|
||||
}),
|
||||
],
|
||||
width: {
|
||||
|
@ -1,7 +1,19 @@
|
||||
// Add custom borders to the table itself
|
||||
// Add custom borders and no-borders to the table itself
|
||||
// Import from 'docx' rather than '../build' if you install from npm
|
||||
import * as fs from "fs";
|
||||
import { BorderStyle, Document, Packer, Paragraph, Table, TableCell, TableRow } from "../build";
|
||||
import {
|
||||
BorderStyle,
|
||||
Document,
|
||||
HeadingLevel,
|
||||
Packer,
|
||||
Paragraph,
|
||||
Table,
|
||||
TableBorders,
|
||||
TableCell,
|
||||
TableRow,
|
||||
TextDirection,
|
||||
VerticalAlign,
|
||||
} from "../build";
|
||||
|
||||
const doc = new Document();
|
||||
|
||||
@ -10,6 +22,28 @@ const table = new Table({
|
||||
new TableRow({
|
||||
children: [
|
||||
new TableCell({
|
||||
borders: {
|
||||
top: {
|
||||
style: BorderStyle.DASH_SMALL_GAP,
|
||||
size: 1,
|
||||
color: "red",
|
||||
},
|
||||
bottom: {
|
||||
style: BorderStyle.DASH_SMALL_GAP,
|
||||
size: 1,
|
||||
color: "red",
|
||||
},
|
||||
left: {
|
||||
style: BorderStyle.DASH_SMALL_GAP,
|
||||
size: 1,
|
||||
color: "red",
|
||||
},
|
||||
right: {
|
||||
style: BorderStyle.DASH_SMALL_GAP,
|
||||
size: 1,
|
||||
color: "red",
|
||||
},
|
||||
},
|
||||
children: [new Paragraph("Hello")],
|
||||
}),
|
||||
new TableCell({
|
||||
@ -30,7 +64,103 @@ const table = new Table({
|
||||
],
|
||||
});
|
||||
|
||||
doc.addSection({ children: [table] });
|
||||
// Using the no-border convenience object. It is the same as writing this manually:
|
||||
// const borders = {
|
||||
// top: {
|
||||
// style: BorderStyle.NONE,
|
||||
// size: 0,
|
||||
// color: "auto",
|
||||
// },
|
||||
// bottom: {
|
||||
// style: BorderStyle.NONE,
|
||||
// size: 0,
|
||||
// color: "auto",
|
||||
// },
|
||||
// left: {
|
||||
// style: BorderStyle.NONE,
|
||||
// size: 0,
|
||||
// color: "auto",
|
||||
// },
|
||||
// right: {
|
||||
// style: BorderStyle.NONE,
|
||||
// size: 0,
|
||||
// color: "auto",
|
||||
// },
|
||||
// insideHorizontal: {
|
||||
// style: BorderStyle.NONE,
|
||||
// size: 0,
|
||||
// color: "auto",
|
||||
// },
|
||||
// insideVertical: {
|
||||
// style: BorderStyle.NONE,
|
||||
// size: 0,
|
||||
// color: "auto",
|
||||
// },
|
||||
// };
|
||||
const noBorderTable = new Table({
|
||||
borders: TableBorders.NONE,
|
||||
rows: [
|
||||
new TableRow({
|
||||
children: [
|
||||
new TableCell({
|
||||
children: [new Paragraph({}), new Paragraph({})],
|
||||
verticalAlign: VerticalAlign.CENTER,
|
||||
}),
|
||||
new TableCell({
|
||||
children: [new Paragraph({}), new Paragraph({})],
|
||||
verticalAlign: VerticalAlign.CENTER,
|
||||
}),
|
||||
new TableCell({
|
||||
children: [new Paragraph({ text: "bottom to top" }), new Paragraph({})],
|
||||
textDirection: TextDirection.BOTTOM_TO_TOP_LEFT_TO_RIGHT,
|
||||
}),
|
||||
new TableCell({
|
||||
children: [new Paragraph({ text: "top to bottom" }), new Paragraph({})],
|
||||
textDirection: TextDirection.TOP_TO_BOTTOM_RIGHT_TO_LEFT,
|
||||
}),
|
||||
],
|
||||
}),
|
||||
new TableRow({
|
||||
children: [
|
||||
new TableCell({
|
||||
children: [
|
||||
new Paragraph({
|
||||
text:
|
||||
"Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah",
|
||||
heading: HeadingLevel.HEADING_1,
|
||||
}),
|
||||
],
|
||||
}),
|
||||
new TableCell({
|
||||
children: [
|
||||
new Paragraph({
|
||||
text: "This text should be in the middle of the cell",
|
||||
}),
|
||||
],
|
||||
verticalAlign: VerticalAlign.CENTER,
|
||||
}),
|
||||
new TableCell({
|
||||
children: [
|
||||
new Paragraph({
|
||||
text: "Text above should be vertical from bottom to top",
|
||||
}),
|
||||
],
|
||||
verticalAlign: VerticalAlign.CENTER,
|
||||
}),
|
||||
new TableCell({
|
||||
children: [
|
||||
new Paragraph({
|
||||
text: "Text above should be vertical from top to bottom",
|
||||
}),
|
||||
],
|
||||
verticalAlign: VerticalAlign.CENTER,
|
||||
}),
|
||||
],
|
||||
}),
|
||||
],
|
||||
});
|
||||
|
||||
doc.addSection({ children: [table, new Paragraph("Hello"), noBorderTable] });
|
||||
|
||||
Packer.toBuffer(doc).then((buffer) => {
|
||||
fs.writeFileSync("My Document.docx", buffer);
|
||||
|
@ -22,6 +22,7 @@ const image4 = Media.addImage(doc, fs.readFileSync("./demo/images/parrots.bmp"))
|
||||
const image5 = Media.addImage(doc, fs.readFileSync("./demo/images/pizza.gif"));
|
||||
const image6 = Media.addImage(doc, fs.readFileSync("./demo/images/pizza.gif"), 200, 200, {
|
||||
floating: {
|
||||
zIndex: 10,
|
||||
horizontalPosition: {
|
||||
offset: 1014400,
|
||||
},
|
||||
@ -33,6 +34,7 @@ const image6 = Media.addImage(doc, fs.readFileSync("./demo/images/pizza.gif"), 2
|
||||
|
||||
const image7 = Media.addImage(doc, fs.readFileSync("./demo/images/cat.jpg"), 200, 200, {
|
||||
floating: {
|
||||
zIndex: 5,
|
||||
horizontalPosition: {
|
||||
relative: HorizontalPositionRelativeFrom.PAGE,
|
||||
align: HorizontalPositionAlign.RIGHT,
|
||||
|
@ -15,6 +15,14 @@ const doc = new Document({
|
||||
italics: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
id: "strong",
|
||||
name: "Strong",
|
||||
basedOn: "Normal",
|
||||
run: {
|
||||
bold: true,
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
@ -29,6 +37,18 @@ doc.addSection({
|
||||
}),
|
||||
],
|
||||
}),
|
||||
new Paragraph({
|
||||
children: [
|
||||
new TextRun({
|
||||
text: "First Word",
|
||||
style: "strong",
|
||||
}),
|
||||
new TextRun({
|
||||
text:
|
||||
" - Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.",
|
||||
}),
|
||||
],
|
||||
}),
|
||||
],
|
||||
});
|
||||
|
||||
|
@ -80,6 +80,7 @@ doc.addSection({
|
||||
children: [
|
||||
new TextRun("This is a demo "),
|
||||
new DeletedTextRun({
|
||||
break: 1,
|
||||
text: "in order",
|
||||
color: "red",
|
||||
bold: true,
|
||||
@ -95,7 +96,7 @@ doc.addSection({
|
||||
id: 2,
|
||||
author: "Firstname Lastname",
|
||||
date: "2020-10-06T09:00:00Z",
|
||||
}).break(),
|
||||
}),
|
||||
new InsertedTextRun({
|
||||
text: "to show how to ",
|
||||
bold: false,
|
||||
|
88
demo/57-add-parent-numbered-lists.ts
Normal file
88
demo/57-add-parent-numbered-lists.ts
Normal file
@ -0,0 +1,88 @@
|
||||
// Numbered lists - Add parent number in sub number
|
||||
// Import from 'docx' rather than '../build' if you install from npm
|
||||
import * as fs from "fs";
|
||||
import { AlignmentType, convertInchesToTwip, Document, HeadingLevel, LevelFormat, Packer, Paragraph } from "../build";
|
||||
|
||||
const doc = new Document({
|
||||
numbering: {
|
||||
config: [
|
||||
{
|
||||
levels: [
|
||||
{
|
||||
level: 0,
|
||||
format: LevelFormat.DECIMAL,
|
||||
text: "%1",
|
||||
alignment: AlignmentType.START,
|
||||
style: {
|
||||
paragraph: {
|
||||
indent: { left: convertInchesToTwip(0.5), hanging: 260 },
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
level: 1,
|
||||
format: LevelFormat.DECIMAL,
|
||||
text: "%1.%2",
|
||||
alignment: AlignmentType.START,
|
||||
style: {
|
||||
paragraph: {
|
||||
indent: { left: 1.25 * convertInchesToTwip(0.5), hanging: 1.25 * 260 },
|
||||
},
|
||||
run: {
|
||||
bold: true,
|
||||
size: 18,
|
||||
font: "Times New Roman",
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
reference: "my-number-numbering-reference",
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
|
||||
doc.addSection({
|
||||
children: [
|
||||
new Paragraph({
|
||||
text: "How to make cake",
|
||||
heading: HeadingLevel.HEADING_1,
|
||||
}),
|
||||
new Paragraph({
|
||||
text: "Step 1 - Add sugar",
|
||||
numbering: {
|
||||
reference: "my-number-numbering-reference",
|
||||
level: 0,
|
||||
},
|
||||
}),
|
||||
new Paragraph({
|
||||
text: "Step 2 - Add wheat",
|
||||
numbering: {
|
||||
reference: "my-number-numbering-reference",
|
||||
level: 0,
|
||||
},
|
||||
}),
|
||||
new Paragraph({
|
||||
text: "Step 2a - Stir the wheat in a circle",
|
||||
numbering: {
|
||||
reference: "my-number-numbering-reference",
|
||||
level: 1,
|
||||
},
|
||||
}),
|
||||
new Paragraph({
|
||||
text: "Step 3 - Put in oven",
|
||||
numbering: {
|
||||
reference: "my-number-numbering-reference",
|
||||
level: 0,
|
||||
},
|
||||
}),
|
||||
new Paragraph({
|
||||
text: "How to make cake",
|
||||
heading: HeadingLevel.HEADING_1,
|
||||
}),
|
||||
],
|
||||
});
|
||||
|
||||
Packer.toBuffer(doc).then((buffer) => {
|
||||
fs.writeFileSync("My Document.docx", buffer);
|
||||
});
|
@ -28,5 +28,8 @@
|
||||
* Exporting
|
||||
|
||||
* [Packers](usage/packers.md)
|
||||
* Utility
|
||||
|
||||
* [Convenience functions](usage/convenience-functions.md)
|
||||
|
||||
* [Contribution Guidelines](contribution-guidelines.md)
|
||||
|
@ -9,7 +9,7 @@ const text = new TextRun("Bullet points");
|
||||
const paragraph = new Paragraph({
|
||||
text: "Bullet points",
|
||||
bullet: {
|
||||
level: 0, // How deep you want the bullet to me
|
||||
level: 0, //How deep you want the bullet to be
|
||||
},
|
||||
});
|
||||
```
|
||||
|
22
docs/usage/convenience-functions.md
Normal file
22
docs/usage/convenience-functions.md
Normal file
@ -0,0 +1,22 @@
|
||||
# Convenience functions
|
||||
|
||||
OOXML and this library mainly uses a unit called twentieths of a point or `twip` for short. a twip is a typographical measurement, defined as 1/20 of a typographical point. One twip is 1/1440 inch, or 17.64 μm. This unit is not intuitive for many users, so some functions were created to help
|
||||
|
||||
More info here: https://en.wikipedia.org/wiki/Twip
|
||||
|
||||
## Convert Inches to Twip
|
||||
|
||||
```ts
|
||||
import { convertInchesToTwip } from "docx";
|
||||
|
||||
const twip = convertInchesToTwip(1); // returns 1440
|
||||
const twip = convertInchesToTwip(0.5); // returns 720
|
||||
```
|
||||
|
||||
## Convert Millimeters to Twip
|
||||
|
||||
```ts
|
||||
import { convertMillimetersToTwip } from "docx";
|
||||
|
||||
const twip = convertMillimetersToTwip(50); // returns 2834
|
||||
```
|
@ -125,6 +125,7 @@ Full options you can pass into `floating` are:
|
||||
| lockAnchor | `boolean` | Optional |
|
||||
| behindDocument | `boolean` | Optional |
|
||||
| layoutInCell | `boolean` | Optional |
|
||||
| zIndex | `number` | Optional |
|
||||
|
||||
`HorizontalPositionOptions` are:
|
||||
|
||||
|
@ -158,6 +158,15 @@ Sometimes you would want to put text underneath another line of text but inside
|
||||
```ts
|
||||
const text = new TextRun({
|
||||
text: "break",
|
||||
break: true,
|
||||
break: 1,
|
||||
});
|
||||
```
|
||||
|
||||
Adding two breaks:
|
||||
|
||||
```ts
|
||||
const text = new TextRun({
|
||||
text: "break",
|
||||
break: 2,
|
||||
});
|
||||
```
|
||||
|
83
package-lock.json
generated
83
package-lock.json
generated
@ -462,9 +462,9 @@
|
||||
"dev": true
|
||||
},
|
||||
"@sinonjs/commons": {
|
||||
"version": "1.8.1",
|
||||
"resolved": "https://registry.npmjs.org/@sinonjs/commons/-/commons-1.8.1.tgz",
|
||||
"integrity": "sha512-892K+kWUUi3cl+LlqEWIDrhvLgdL79tECi8JZUyq6IviKy/DNhuzCRlbHUjxK89f4ypPMMaFnFuR9Ie6DoIMsw==",
|
||||
"version": "1.8.2",
|
||||
"resolved": "https://registry.npmjs.org/@sinonjs/commons/-/commons-1.8.2.tgz",
|
||||
"integrity": "sha512-sruwd86RJHdsVf/AtBoijDmUqJp3B6hF/DGC23C+JaegnDHaZyewCjoVGTdg3J0uz3Zs7NnIT05OBOmML72lQw==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"type-detect": "4.0.8"
|
||||
@ -487,20 +487,10 @@
|
||||
"@sinonjs/commons": "^1.7.0"
|
||||
}
|
||||
},
|
||||
"@sinonjs/formatio": {
|
||||
"version": "5.0.1",
|
||||
"resolved": "https://registry.npmjs.org/@sinonjs/formatio/-/formatio-5.0.1.tgz",
|
||||
"integrity": "sha512-KaiQ5pBf1MpS09MuA0kp6KBQt2JUOQycqVG1NZXvzeaXe5LGFqAKueIS0bw4w0P9r7KuBSVdUk5QjXsUdu2CxQ==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@sinonjs/commons": "^1",
|
||||
"@sinonjs/samsam": "^5.0.2"
|
||||
}
|
||||
},
|
||||
"@sinonjs/samsam": {
|
||||
"version": "5.2.0",
|
||||
"resolved": "https://registry.npmjs.org/@sinonjs/samsam/-/samsam-5.2.0.tgz",
|
||||
"integrity": "sha512-CaIcyX5cDsjcW/ab7HposFWzV1kC++4HNsfnEdFJa7cP1QIuILAKV+BgfeqRXhcnSAc76r/Rh/O5C+300BwUIw==",
|
||||
"version": "5.3.1",
|
||||
"resolved": "https://registry.npmjs.org/@sinonjs/samsam/-/samsam-5.3.1.tgz",
|
||||
"integrity": "sha512-1Hc0b1TtyfBu8ixF/tpfSHTVWKwCBLY4QJbkgnE7HcwyvT2xArDxb4K7dMgqRm3szI+LJbzmW/s4xxEhv6hwDg==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@sinonjs/commons": "^1.6.0",
|
||||
@ -670,9 +660,9 @@
|
||||
}
|
||||
},
|
||||
"@types/webpack": {
|
||||
"version": "4.41.25",
|
||||
"resolved": "https://registry.npmjs.org/@types/webpack/-/webpack-4.41.25.tgz",
|
||||
"integrity": "sha512-cr6kZ+4m9lp86ytQc1jPOJXgINQyz3kLLunZ57jznW+WIAL0JqZbGubQk4GlD42MuQL5JGOABrxdpqqWeovlVQ==",
|
||||
"version": "4.41.26",
|
||||
"resolved": "https://registry.npmjs.org/@types/webpack/-/webpack-4.41.26.tgz",
|
||||
"integrity": "sha512-7ZyTfxjCRwexh+EJFwRUM+CDB2XvgHl4vfuqf1ZKrgGvcS5BrNvPQqJh3tsZ0P6h6Aa1qClVHaJZszLPzpqHeA==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@types/anymatch": "*",
|
||||
@ -684,9 +674,9 @@
|
||||
}
|
||||
},
|
||||
"@types/webpack-sources": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/@types/webpack-sources/-/webpack-sources-2.0.0.tgz",
|
||||
"integrity": "sha512-a5kPx98CNFRKQ+wqawroFunvFqv7GHm/3KOI52NY9xWADgc8smu4R6prt4EU/M4QfVjvgBkMqU4fBhw3QfMVkg==",
|
||||
"version": "2.1.0",
|
||||
"resolved": "https://registry.npmjs.org/@types/webpack-sources/-/webpack-sources-2.1.0.tgz",
|
||||
"integrity": "sha512-LXn/oYIpBeucgP1EIJbKQ2/4ZmpvRl+dlrFdX7+94SKRUV3Evy3FsfMZY318vGhkWUS5MPhtOM3w1/hCOAOXcg==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@types/node": "*",
|
||||
@ -1932,9 +1922,9 @@
|
||||
"dev": true
|
||||
},
|
||||
"colors": {
|
||||
"version": "1.3.3",
|
||||
"resolved": "https://registry.npmjs.org/colors/-/colors-1.3.3.tgz",
|
||||
"integrity": "sha512-mmGt/1pZqYRjMxB1axhTo16/snVZ5krrKkcmMeVKxzECMMXoCgnvTPp10QgHfcbQZw8Dq2jMNG6je4JlWU0gWg==",
|
||||
"version": "1.4.0",
|
||||
"resolved": "https://registry.npmjs.org/colors/-/colors-1.4.0.tgz",
|
||||
"integrity": "sha512-a+UqTh4kgZg/SlGvfbzDHpgRu7AAQOmmqRHJnxhRZICKFUT91brVhNNt58CMWU9PsBbv3PDCZUHbVxuDiH2mtA==",
|
||||
"dev": true
|
||||
},
|
||||
"combined-stream": {
|
||||
@ -5598,9 +5588,9 @@
|
||||
"dev": true
|
||||
},
|
||||
"mute-stream": {
|
||||
"version": "0.0.7",
|
||||
"resolved": "https://registry.npmjs.org/mute-stream/-/mute-stream-0.0.7.tgz",
|
||||
"integrity": "sha1-MHXOk7whuPq0PhvE2n6BFe0ee6s=",
|
||||
"version": "0.0.8",
|
||||
"resolved": "https://registry.npmjs.org/mute-stream/-/mute-stream-0.0.8.tgz",
|
||||
"integrity": "sha512-nnbWWOkoWyUsTjKrhgD0dcz22mdkSnpYqbEjIm2nhwhuxlSkpywJmBo8h0ZqJdkp73mb90SssHkN4rsRaBAfAA==",
|
||||
"dev": true
|
||||
},
|
||||
"nan": {
|
||||
@ -6501,12 +6491,6 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"pkginfo": {
|
||||
"version": "0.4.1",
|
||||
"resolved": "https://registry.npmjs.org/pkginfo/-/pkginfo-0.4.1.tgz",
|
||||
"integrity": "sha1-tUGO8EOd5UJfxJlQQtztFPsqhP8=",
|
||||
"dev": true
|
||||
},
|
||||
"posix-character-classes": {
|
||||
"version": "0.1.1",
|
||||
"resolved": "https://registry.npmjs.org/posix-character-classes/-/posix-character-classes-0.1.1.tgz",
|
||||
@ -6578,17 +6562,16 @@
|
||||
"dev": true
|
||||
},
|
||||
"prompt": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/prompt/-/prompt-1.0.0.tgz",
|
||||
"integrity": "sha1-jlcSPDlquYiJf7Mn/Trtw+c15P4=",
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/prompt/-/prompt-1.1.0.tgz",
|
||||
"integrity": "sha512-ec1vUPXCplDBDUVD8uPa3XGA+OzLrO40Vxv3F1uxoiZGkZhdctlK2JotcHq5X6ExjocDOGwGdCSXloGNyU5L1Q==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"colors": "^1.1.2",
|
||||
"pkginfo": "0.x.x",
|
||||
"read": "1.0.x",
|
||||
"revalidator": "0.1.x",
|
||||
"utile": "0.3.x",
|
||||
"winston": "2.1.x"
|
||||
"winston": "2.x"
|
||||
}
|
||||
},
|
||||
"prr": {
|
||||
@ -7365,15 +7348,14 @@
|
||||
"dev": true
|
||||
},
|
||||
"sinon": {
|
||||
"version": "9.2.1",
|
||||
"resolved": "https://registry.npmjs.org/sinon/-/sinon-9.2.1.tgz",
|
||||
"integrity": "sha512-naPfsamB5KEE1aiioaoqJ6MEhdUs/2vtI5w1hPAXX/UwvoPjXcwh1m5HiKx0HGgKR8lQSoFIgY5jM6KK8VrS9w==",
|
||||
"version": "9.2.4",
|
||||
"resolved": "https://registry.npmjs.org/sinon/-/sinon-9.2.4.tgz",
|
||||
"integrity": "sha512-zljcULZQsJxVra28qIAL6ow1Z9tpattkCTEJR4RBP3TGc00FcttsP5pK284Nas5WjMZU5Yzy3kAIp3B3KRf5Yg==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@sinonjs/commons": "^1.8.1",
|
||||
"@sinonjs/fake-timers": "^6.0.1",
|
||||
"@sinonjs/formatio": "^5.0.1",
|
||||
"@sinonjs/samsam": "^5.2.0",
|
||||
"@sinonjs/samsam": "^5.3.1",
|
||||
"diff": "^4.0.2",
|
||||
"nise": "^4.0.4",
|
||||
"supports-color": "^7.1.0"
|
||||
@ -8986,9 +8968,9 @@
|
||||
"dev": true
|
||||
},
|
||||
"winston": {
|
||||
"version": "2.1.1",
|
||||
"resolved": "https://registry.npmjs.org/winston/-/winston-2.1.1.tgz",
|
||||
"integrity": "sha1-PJNJ0ZYgf9G9/51LxD73JRDjoS4=",
|
||||
"version": "2.4.5",
|
||||
"resolved": "https://registry.npmjs.org/winston/-/winston-2.4.5.tgz",
|
||||
"integrity": "sha512-TWoamHt5yYvsMarGlGEQE59SbJHqGsZV8/lwC+iCcGeAe0vUaOh+Lv6SYM17ouzC/a/LB1/hz/7sxFBtlu1l4A==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"async": "~1.0.0",
|
||||
@ -8996,7 +8978,6 @@
|
||||
"cycle": "1.0.x",
|
||||
"eyes": "0.1.x",
|
||||
"isstream": "0.1.x",
|
||||
"pkginfo": "0.3.x",
|
||||
"stack-trace": "0.0.x"
|
||||
},
|
||||
"dependencies": {
|
||||
@ -9011,12 +8992,6 @@
|
||||
"resolved": "https://registry.npmjs.org/colors/-/colors-1.0.3.tgz",
|
||||
"integrity": "sha1-BDP0TYCWgP3rYO0mDxsMJi6CpAs=",
|
||||
"dev": true
|
||||
},
|
||||
"pkginfo": {
|
||||
"version": "0.3.1",
|
||||
"resolved": "https://registry.npmjs.org/pkginfo/-/pkginfo-0.3.1.tgz",
|
||||
"integrity": "sha1-Wyn2qB9wcXFC4J52W76rl7T4HiE=",
|
||||
"dev": true
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "docx",
|
||||
"version": "5.4.1",
|
||||
"version": "5.5.0",
|
||||
"description": "Easily generate .docx files with JS/TS with a nice declarative API. Works for Node and on the Browser.",
|
||||
"main": "build/index.js",
|
||||
"scripts": {
|
||||
|
18
src/convenience-functions.spec.ts
Normal file
18
src/convenience-functions.spec.ts
Normal file
@ -0,0 +1,18 @@
|
||||
import { expect } from "chai";
|
||||
import { convertInchesToTwip, convertMillimetersToTwip } from "./convenience-functions";
|
||||
|
||||
describe("Utility", () => {
|
||||
describe("#convertMillimetersToTwip", () => {
|
||||
it("should call the underlying header's addChildElement for Paragraph", () => {
|
||||
expect(convertMillimetersToTwip(1000)).to.equal(56692);
|
||||
});
|
||||
});
|
||||
|
||||
describe("#convertInchesToTwip", () => {
|
||||
it("should call the underlying header's addChildElement", () => {
|
||||
expect(convertInchesToTwip(1)).to.equal(1440);
|
||||
expect(convertInchesToTwip(0.5)).to.equal(720);
|
||||
expect(convertInchesToTwip(0.25)).to.equal(360);
|
||||
});
|
||||
});
|
||||
});
|
8
src/convenience-functions.ts
Normal file
8
src/convenience-functions.ts
Normal file
@ -0,0 +1,8 @@
|
||||
// Twip - twentieths of a point
|
||||
export const convertMillimetersToTwip = (millimeters: number): number => {
|
||||
return Math.floor((millimeters / 25.4) * 72 * 20);
|
||||
};
|
||||
|
||||
export const convertInchesToTwip = (inches: number): number => {
|
||||
return Math.floor(inches * 72 * 20);
|
||||
};
|
@ -1,5 +1,6 @@
|
||||
import { expect } from "chai";
|
||||
|
||||
import { convertInchesToTwip } from "convenience-functions";
|
||||
import { Formatter } from "export/formatter";
|
||||
import { FooterWrapper } from "file/footer-wrapper";
|
||||
import { HeaderWrapper } from "file/header-wrapper";
|
||||
@ -18,10 +19,10 @@ describe("SectionProperties", () => {
|
||||
const properties = new SectionProperties({
|
||||
width: 11906,
|
||||
height: 16838,
|
||||
top: 1440,
|
||||
right: 1440,
|
||||
bottom: 1440,
|
||||
left: 1440,
|
||||
top: convertInchesToTwip(1),
|
||||
right: convertInchesToTwip(1),
|
||||
bottom: convertInchesToTwip(1),
|
||||
left: convertInchesToTwip(1),
|
||||
header: 708,
|
||||
footer: 708,
|
||||
gutter: 0,
|
||||
@ -30,7 +31,7 @@ describe("SectionProperties", () => {
|
||||
space: 708,
|
||||
count: 1,
|
||||
},
|
||||
linePitch: 360,
|
||||
linePitch: convertInchesToTwip(0.25),
|
||||
headers: {
|
||||
default: new HeaderWrapper(media, 100),
|
||||
},
|
||||
|
@ -1,4 +1,5 @@
|
||||
// http://officeopenxml.com/WPsection.php
|
||||
import { convertInchesToTwip } from "convenience-functions";
|
||||
import { FooterWrapper } from "file/footer-wrapper";
|
||||
import { HeaderWrapper } from "file/header-wrapper";
|
||||
import { XmlComponent } from "file/xml-components";
|
||||
@ -64,10 +65,10 @@ export class SectionProperties extends XmlComponent {
|
||||
const {
|
||||
width = 11906,
|
||||
height = 16838,
|
||||
top = 1440,
|
||||
right = 1440,
|
||||
bottom = 1440,
|
||||
left = 1440,
|
||||
top = convertInchesToTwip(1),
|
||||
right = convertInchesToTwip(1),
|
||||
bottom = convertInchesToTwip(1),
|
||||
left = convertInchesToTwip(1),
|
||||
header = 708,
|
||||
footer = 708,
|
||||
gutter = 0,
|
||||
|
@ -218,5 +218,150 @@ describe("Anchor", () => {
|
||||
const textWrap = newJson.root[6];
|
||||
assert.equal(textWrap.rootKey, "wp:wrapTopAndBottom");
|
||||
});
|
||||
|
||||
it("should create a Drawing with a margin", () => {
|
||||
anchor = createAnchor({
|
||||
floating: {
|
||||
verticalPosition: {
|
||||
offset: 0,
|
||||
},
|
||||
horizontalPosition: {
|
||||
offset: 0,
|
||||
},
|
||||
margins: {
|
||||
top: 10,
|
||||
left: 10,
|
||||
bottom: 10,
|
||||
right: 10,
|
||||
},
|
||||
},
|
||||
});
|
||||
const newJson = Utility.jsonify(anchor);
|
||||
const anchorAttributes = newJson.root[0].root;
|
||||
assert.include(anchorAttributes, {
|
||||
distT: 10,
|
||||
distB: 10,
|
||||
distL: 10,
|
||||
distR: 10,
|
||||
});
|
||||
});
|
||||
|
||||
it("should create a Drawing with a default margin", () => {
|
||||
anchor = createAnchor({
|
||||
floating: {
|
||||
verticalPosition: {
|
||||
offset: 0,
|
||||
},
|
||||
horizontalPosition: {
|
||||
offset: 0,
|
||||
},
|
||||
margins: {},
|
||||
},
|
||||
});
|
||||
const newJson = Utility.jsonify(anchor);
|
||||
const anchorAttributes = newJson.root[0].root;
|
||||
assert.include(anchorAttributes, {
|
||||
distT: 0,
|
||||
distB: 0,
|
||||
distL: 0,
|
||||
distR: 0,
|
||||
});
|
||||
});
|
||||
|
||||
it("should create a Drawing with allowOverlap being false", () => {
|
||||
anchor = createAnchor({
|
||||
floating: {
|
||||
verticalPosition: {
|
||||
offset: 0,
|
||||
},
|
||||
horizontalPosition: {
|
||||
offset: 0,
|
||||
},
|
||||
allowOverlap: false,
|
||||
},
|
||||
});
|
||||
const newJson = Utility.jsonify(anchor);
|
||||
const anchorAttributes = newJson.root[0].root;
|
||||
assert.include(anchorAttributes, {
|
||||
allowOverlap: "0",
|
||||
});
|
||||
});
|
||||
|
||||
it("should create a Drawing with behindDocument being true", () => {
|
||||
anchor = createAnchor({
|
||||
floating: {
|
||||
verticalPosition: {
|
||||
offset: 0,
|
||||
},
|
||||
horizontalPosition: {
|
||||
offset: 0,
|
||||
},
|
||||
behindDocument: true,
|
||||
},
|
||||
});
|
||||
const newJson = Utility.jsonify(anchor);
|
||||
const anchorAttributes = newJson.root[0].root;
|
||||
assert.include(anchorAttributes, {
|
||||
behindDoc: "1",
|
||||
});
|
||||
});
|
||||
|
||||
it("should create a Drawing with locked being true", () => {
|
||||
anchor = createAnchor({
|
||||
floating: {
|
||||
verticalPosition: {
|
||||
offset: 0,
|
||||
},
|
||||
horizontalPosition: {
|
||||
offset: 0,
|
||||
},
|
||||
lockAnchor: true,
|
||||
},
|
||||
});
|
||||
const newJson = Utility.jsonify(anchor);
|
||||
const anchorAttributes = newJson.root[0].root;
|
||||
assert.include(anchorAttributes, {
|
||||
locked: "1",
|
||||
});
|
||||
});
|
||||
|
||||
it("should create a Drawing with locked being false", () => {
|
||||
anchor = createAnchor({
|
||||
floating: {
|
||||
verticalPosition: {
|
||||
offset: 0,
|
||||
},
|
||||
horizontalPosition: {
|
||||
offset: 0,
|
||||
},
|
||||
layoutInCell: false,
|
||||
},
|
||||
});
|
||||
const newJson = Utility.jsonify(anchor);
|
||||
const anchorAttributes = newJson.root[0].root;
|
||||
assert.include(anchorAttributes, {
|
||||
layoutInCell: "0",
|
||||
});
|
||||
});
|
||||
|
||||
it("should create a Drawing with a certain z-index", () => {
|
||||
anchor = createAnchor({
|
||||
floating: {
|
||||
verticalPosition: {
|
||||
offset: 0,
|
||||
},
|
||||
horizontalPosition: {
|
||||
offset: 0,
|
||||
},
|
||||
zIndex: 120,
|
||||
},
|
||||
});
|
||||
const newJson = Utility.jsonify(anchor);
|
||||
const anchorAttributes = newJson.root[0].root;
|
||||
|
||||
assert.include(anchorAttributes, {
|
||||
relativeHeight: 120,
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -11,42 +11,32 @@ import { Extent } from "./../extent/extent";
|
||||
import { GraphicFrameProperties } from "./../graphic-frame/graphic-frame-properties";
|
||||
import { AnchorAttributes } from "./anchor-attributes";
|
||||
|
||||
const defaultOptions: IFloating = {
|
||||
allowOverlap: true,
|
||||
behindDocument: false,
|
||||
lockAnchor: false,
|
||||
layoutInCell: true,
|
||||
verticalPosition: {},
|
||||
horizontalPosition: {},
|
||||
};
|
||||
|
||||
export class Anchor extends XmlComponent {
|
||||
constructor(mediaData: IMediaData, dimensions: IMediaDataDimensions, drawingOptions: IDrawingOptions) {
|
||||
super("wp:anchor");
|
||||
|
||||
const floating = {
|
||||
margins: {
|
||||
top: 0,
|
||||
bottom: 0,
|
||||
left: 0,
|
||||
right: 0,
|
||||
},
|
||||
...defaultOptions,
|
||||
const floating: IFloating = {
|
||||
allowOverlap: true,
|
||||
behindDocument: false,
|
||||
lockAnchor: false,
|
||||
layoutInCell: true,
|
||||
verticalPosition: {},
|
||||
horizontalPosition: {},
|
||||
...drawingOptions.floating,
|
||||
};
|
||||
|
||||
this.root.push(
|
||||
new AnchorAttributes({
|
||||
distT: floating.margins.top || 0,
|
||||
distB: floating.margins.bottom || 0,
|
||||
distL: floating.margins.left || 0,
|
||||
distR: floating.margins.right || 0,
|
||||
distT: floating.margins ? floating.margins.top || 0 : 0,
|
||||
distB: floating.margins ? floating.margins.bottom || 0 : 0,
|
||||
distL: floating.margins ? floating.margins.left || 0 : 0,
|
||||
distR: floating.margins ? floating.margins.right || 0 : 0,
|
||||
simplePos: "0", // note: word doesn't fully support - so we use 0
|
||||
allowOverlap: floating.allowOverlap === true ? "1" : "0",
|
||||
behindDoc: floating.behindDocument === true ? "1" : "0",
|
||||
locked: floating.lockAnchor === true ? "1" : "0",
|
||||
layoutInCell: floating.layoutInCell === true ? "1" : "0",
|
||||
relativeHeight: dimensions.emus.y,
|
||||
relativeHeight: floating.zIndex ? floating.zIndex : dimensions.emus.y,
|
||||
}),
|
||||
);
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
// http://officeopenxml.com/drwPicFloating-position.php
|
||||
// http://officeopenxml.com/drwPicFloating.php
|
||||
import { ITextWrapping } from "../text-wrap";
|
||||
|
||||
export enum HorizontalPositionRelativeFrom {
|
||||
@ -67,4 +68,5 @@ export interface IFloating {
|
||||
readonly layoutInCell?: boolean;
|
||||
readonly margins?: IMargins;
|
||||
readonly wrap?: ITextWrapping;
|
||||
readonly zIndex?: number;
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ import { AlignmentType, EmphasisMarkType, TabStopPosition } from "../paragraph";
|
||||
import { UnderlineType } from "../paragraph/run/underline";
|
||||
import { ShadingType } from "../table";
|
||||
import { AbstractNumbering } from "./abstract-numbering";
|
||||
import { LevelSuffix } from "./level";
|
||||
import { LevelFormat, LevelSuffix } from "./level";
|
||||
|
||||
describe("AbstractNumbering", () => {
|
||||
it("stores its ID at its .id property", () => {
|
||||
@ -20,7 +20,7 @@ describe("AbstractNumbering", () => {
|
||||
const abstractNumbering = new AbstractNumbering(1, [
|
||||
{
|
||||
level: 3,
|
||||
format: "lowerLetter",
|
||||
format: LevelFormat.LOWER_LETTER,
|
||||
text: "%1)",
|
||||
alignment: AlignmentType.END,
|
||||
},
|
||||
@ -29,7 +29,7 @@ describe("AbstractNumbering", () => {
|
||||
expect(tree["w:abstractNum"][2]["w:lvl"]).to.include({ _attr: { "w:ilvl": 3, "w15:tentative": 1 } });
|
||||
expect(tree["w:abstractNum"][2]["w:lvl"]).to.include({ "w:start": { _attr: { "w:val": 1 } } });
|
||||
expect(tree["w:abstractNum"][2]["w:lvl"]).to.include({ "w:lvlJc": { _attr: { "w:val": "end" } } });
|
||||
expect(tree["w:abstractNum"][2]["w:lvl"]).to.include({ "w:numFmt": { _attr: { "w:val": "lowerLetter" } } });
|
||||
expect(tree["w:abstractNum"][2]["w:lvl"]).to.include({ "w:numFmt": { _attr: { "w:val": LevelFormat.LOWER_LETTER } } });
|
||||
expect(tree["w:abstractNum"][2]["w:lvl"]).to.include({ "w:lvlText": { _attr: { "w:val": "%1)" } } });
|
||||
});
|
||||
|
||||
@ -37,7 +37,7 @@ describe("AbstractNumbering", () => {
|
||||
const abstractNumbering = new AbstractNumbering(1, [
|
||||
{
|
||||
level: 3,
|
||||
format: "lowerLetter",
|
||||
format: LevelFormat.LOWER_LETTER,
|
||||
text: "%1)",
|
||||
},
|
||||
]);
|
||||
@ -45,7 +45,7 @@ describe("AbstractNumbering", () => {
|
||||
expect(tree["w:abstractNum"][2]["w:lvl"]).to.include({ _attr: { "w:ilvl": 3, "w15:tentative": 1 } });
|
||||
expect(tree["w:abstractNum"][2]["w:lvl"]).to.include({ "w:start": { _attr: { "w:val": 1 } } });
|
||||
expect(tree["w:abstractNum"][2]["w:lvl"]).to.include({ "w:lvlJc": { _attr: { "w:val": "start" } } });
|
||||
expect(tree["w:abstractNum"][2]["w:lvl"]).to.include({ "w:numFmt": { _attr: { "w:val": "lowerLetter" } } });
|
||||
expect(tree["w:abstractNum"][2]["w:lvl"]).to.include({ "w:numFmt": { _attr: { "w:val": LevelFormat.LOWER_LETTER } } });
|
||||
expect(tree["w:abstractNum"][2]["w:lvl"]).to.include({ "w:lvlText": { _attr: { "w:val": "%1)" } } });
|
||||
});
|
||||
|
||||
@ -53,7 +53,7 @@ describe("AbstractNumbering", () => {
|
||||
const abstractNumbering = new AbstractNumbering(1, [
|
||||
{
|
||||
level: 3,
|
||||
format: "lowerLetter",
|
||||
format: LevelFormat.LOWER_LETTER,
|
||||
text: "%1)",
|
||||
alignment: AlignmentType.END,
|
||||
suffix: LevelSuffix.SPACE,
|
||||
@ -68,7 +68,7 @@ describe("AbstractNumbering", () => {
|
||||
const abstractNumbering = new AbstractNumbering(1, [
|
||||
{
|
||||
level: 0,
|
||||
format: "lowerRoman",
|
||||
format: LevelFormat.LOWER_ROMAN,
|
||||
text: "%0.",
|
||||
style: {
|
||||
paragraph: {
|
||||
@ -87,7 +87,7 @@ describe("AbstractNumbering", () => {
|
||||
const abstractNumbering = new AbstractNumbering(1, [
|
||||
{
|
||||
level: 0,
|
||||
format: "lowerRoman",
|
||||
format: LevelFormat.LOWER_ROMAN,
|
||||
text: "%0.",
|
||||
style: {
|
||||
paragraph: {
|
||||
@ -106,7 +106,7 @@ describe("AbstractNumbering", () => {
|
||||
const abstractNumbering = new AbstractNumbering(1, [
|
||||
{
|
||||
level: 0,
|
||||
format: "lowerRoman",
|
||||
format: LevelFormat.LOWER_ROMAN,
|
||||
text: "%0.",
|
||||
style: {
|
||||
paragraph: {
|
||||
@ -125,7 +125,7 @@ describe("AbstractNumbering", () => {
|
||||
const abstractNumbering = new AbstractNumbering(1, [
|
||||
{
|
||||
level: 0,
|
||||
format: "lowerRoman",
|
||||
format: LevelFormat.LOWER_ROMAN,
|
||||
text: "%0.",
|
||||
style: {
|
||||
paragraph: {
|
||||
@ -144,7 +144,7 @@ describe("AbstractNumbering", () => {
|
||||
const abstractNumbering = new AbstractNumbering(1, [
|
||||
{
|
||||
level: 0,
|
||||
format: "lowerRoman",
|
||||
format: LevelFormat.LOWER_ROMAN,
|
||||
text: "%0.",
|
||||
style: {
|
||||
paragraph: {
|
||||
@ -163,7 +163,7 @@ describe("AbstractNumbering", () => {
|
||||
const abstractNumbering = new AbstractNumbering(1, [
|
||||
{
|
||||
level: 0,
|
||||
format: "lowerRoman",
|
||||
format: LevelFormat.LOWER_ROMAN,
|
||||
text: "%0.",
|
||||
style: {
|
||||
paragraph: {
|
||||
@ -182,7 +182,7 @@ describe("AbstractNumbering", () => {
|
||||
const abstractNumbering = new AbstractNumbering(1, [
|
||||
{
|
||||
level: 0,
|
||||
format: "lowerRoman",
|
||||
format: LevelFormat.LOWER_ROMAN,
|
||||
text: "%0.",
|
||||
style: {
|
||||
paragraph: {
|
||||
@ -216,7 +216,7 @@ describe("AbstractNumbering", () => {
|
||||
const abstractNumbering = new AbstractNumbering(1, [
|
||||
{
|
||||
level: 0,
|
||||
format: "lowerRoman",
|
||||
format: LevelFormat.LOWER_ROMAN,
|
||||
text: "%0.",
|
||||
style: {
|
||||
paragraph: {
|
||||
@ -239,7 +239,7 @@ describe("AbstractNumbering", () => {
|
||||
const abstractNumbering = new AbstractNumbering(1, [
|
||||
{
|
||||
level: 0,
|
||||
format: "lowerRoman",
|
||||
format: LevelFormat.LOWER_ROMAN,
|
||||
text: "%0.",
|
||||
style: {
|
||||
paragraph: {
|
||||
@ -262,7 +262,7 @@ describe("AbstractNumbering", () => {
|
||||
const abstractNumbering = new AbstractNumbering(1, [
|
||||
{
|
||||
level: 0,
|
||||
format: "lowerRoman",
|
||||
format: LevelFormat.LOWER_ROMAN,
|
||||
text: "%0.",
|
||||
style: {
|
||||
paragraph: {
|
||||
@ -281,7 +281,7 @@ describe("AbstractNumbering", () => {
|
||||
const abstractNumbering = new AbstractNumbering(1, [
|
||||
{
|
||||
level: 0,
|
||||
format: "lowerRoman",
|
||||
format: LevelFormat.LOWER_ROMAN,
|
||||
text: "%0.",
|
||||
style: {
|
||||
paragraph: {
|
||||
@ -324,7 +324,7 @@ describe("AbstractNumbering", () => {
|
||||
const abstractNumbering = new AbstractNumbering(1, [
|
||||
{
|
||||
level: 0,
|
||||
format: "lowerRoman",
|
||||
format: LevelFormat.LOWER_ROMAN,
|
||||
text: "%0.",
|
||||
style: {
|
||||
run: { size, sizeComplexScript },
|
||||
@ -340,7 +340,7 @@ describe("AbstractNumbering", () => {
|
||||
const abstractNumbering = new AbstractNumbering(1, [
|
||||
{
|
||||
level: 0,
|
||||
format: "lowerRoman",
|
||||
format: LevelFormat.LOWER_ROMAN,
|
||||
text: "%0.",
|
||||
style: {
|
||||
run: {
|
||||
@ -359,7 +359,7 @@ describe("AbstractNumbering", () => {
|
||||
const abstractNumbering = new AbstractNumbering(1, [
|
||||
{
|
||||
level: 0,
|
||||
format: "lowerRoman",
|
||||
format: LevelFormat.LOWER_ROMAN,
|
||||
text: "%0.",
|
||||
style: {
|
||||
run: {
|
||||
@ -378,7 +378,7 @@ describe("AbstractNumbering", () => {
|
||||
const abstractNumbering = new AbstractNumbering(1, [
|
||||
{
|
||||
level: 0,
|
||||
format: "lowerRoman",
|
||||
format: LevelFormat.LOWER_ROMAN,
|
||||
text: "%0.",
|
||||
style: {
|
||||
run: {
|
||||
@ -398,7 +398,7 @@ describe("AbstractNumbering", () => {
|
||||
const abstractNumbering = new AbstractNumbering(1, [
|
||||
{
|
||||
level: 0,
|
||||
format: "lowerRoman",
|
||||
format: LevelFormat.LOWER_ROMAN,
|
||||
text: "%0.",
|
||||
style: {
|
||||
run: {
|
||||
@ -417,7 +417,7 @@ describe("AbstractNumbering", () => {
|
||||
const abstractNumbering = new AbstractNumbering(1, [
|
||||
{
|
||||
level: 0,
|
||||
format: "lowerRoman",
|
||||
format: LevelFormat.LOWER_ROMAN,
|
||||
text: "%0.",
|
||||
style: {
|
||||
run: {
|
||||
@ -436,7 +436,7 @@ describe("AbstractNumbering", () => {
|
||||
const abstractNumbering = new AbstractNumbering(1, [
|
||||
{
|
||||
level: 0,
|
||||
format: "lowerRoman",
|
||||
format: LevelFormat.LOWER_ROMAN,
|
||||
text: "%0.",
|
||||
style: {
|
||||
run: {
|
||||
@ -455,7 +455,7 @@ describe("AbstractNumbering", () => {
|
||||
const abstractNumbering = new AbstractNumbering(1, [
|
||||
{
|
||||
level: 0,
|
||||
format: "lowerRoman",
|
||||
format: LevelFormat.LOWER_ROMAN,
|
||||
text: "%0.",
|
||||
style: {
|
||||
run: {
|
||||
@ -485,7 +485,7 @@ describe("AbstractNumbering", () => {
|
||||
const abstractNumbering = new AbstractNumbering(1, [
|
||||
{
|
||||
level: 0,
|
||||
format: "lowerRoman",
|
||||
format: LevelFormat.LOWER_ROMAN,
|
||||
text: "%0.",
|
||||
style: {
|
||||
run: {
|
||||
@ -533,7 +533,7 @@ describe("AbstractNumbering", () => {
|
||||
const abstractNumbering = new AbstractNumbering(1, [
|
||||
{
|
||||
level: 0,
|
||||
format: "lowerRoman",
|
||||
format: LevelFormat.LOWER_ROMAN,
|
||||
text: "%0.",
|
||||
style: {
|
||||
run: { bold, boldComplexScript },
|
||||
@ -566,7 +566,7 @@ describe("AbstractNumbering", () => {
|
||||
const abstractNumbering = new AbstractNumbering(1, [
|
||||
{
|
||||
level: 0,
|
||||
format: "lowerRoman",
|
||||
format: LevelFormat.LOWER_ROMAN,
|
||||
text: "%0.",
|
||||
style: {
|
||||
run: { italics, italicsComplexScript },
|
||||
@ -604,7 +604,7 @@ describe("AbstractNumbering", () => {
|
||||
const abstractNumbering = new AbstractNumbering(1, [
|
||||
{
|
||||
level: 0,
|
||||
format: "lowerRoman",
|
||||
format: LevelFormat.LOWER_ROMAN,
|
||||
text: "%0.",
|
||||
style: {
|
||||
run: { highlight, highlightComplexScript },
|
||||
@ -682,7 +682,7 @@ describe("AbstractNumbering", () => {
|
||||
const abstractNumbering = new AbstractNumbering(1, [
|
||||
{
|
||||
level: 0,
|
||||
format: "lowerRoman",
|
||||
format: LevelFormat.LOWER_ROMAN,
|
||||
text: "%0.",
|
||||
style: {
|
||||
run: { shadow, shading, shadingComplexScript },
|
||||
@ -699,7 +699,7 @@ describe("AbstractNumbering", () => {
|
||||
const abstractNumbering = new AbstractNumbering(1, [
|
||||
{
|
||||
level: 0,
|
||||
format: "lowerRoman",
|
||||
format: LevelFormat.LOWER_ROMAN,
|
||||
text: "%0.",
|
||||
style: {
|
||||
run: {
|
||||
@ -718,7 +718,7 @@ describe("AbstractNumbering", () => {
|
||||
const abstractNumbering = new AbstractNumbering(1, [
|
||||
{
|
||||
level: 0,
|
||||
format: "lowerRoman",
|
||||
format: LevelFormat.LOWER_ROMAN,
|
||||
text: "%0.",
|
||||
style: {
|
||||
run: {
|
||||
@ -739,7 +739,7 @@ describe("AbstractNumbering", () => {
|
||||
const abstractNumbering = new AbstractNumbering(1, [
|
||||
{
|
||||
level: 0,
|
||||
format: "lowerRoman",
|
||||
format: LevelFormat.LOWER_ROMAN,
|
||||
text: "%0.",
|
||||
style: {
|
||||
run: {
|
||||
@ -763,7 +763,7 @@ describe("AbstractNumbering", () => {
|
||||
const abstractNumbering = new AbstractNumbering(1, [
|
||||
{
|
||||
level: 0,
|
||||
format: "lowerRoman",
|
||||
format: LevelFormat.LOWER_ROMAN,
|
||||
text: "%0.",
|
||||
style: {
|
||||
run: {
|
||||
@ -782,7 +782,7 @@ describe("AbstractNumbering", () => {
|
||||
const abstractNumbering = new AbstractNumbering(1, [
|
||||
{
|
||||
level: 0,
|
||||
format: "lowerRoman",
|
||||
format: LevelFormat.LOWER_ROMAN,
|
||||
text: "%0.",
|
||||
style: {
|
||||
run: {
|
||||
@ -804,7 +804,7 @@ describe("AbstractNumbering", () => {
|
||||
const abstractNumbering = new AbstractNumbering(1, [
|
||||
{
|
||||
level: 0,
|
||||
format: "lowerRoman",
|
||||
format: LevelFormat.LOWER_ROMAN,
|
||||
text: "%0.",
|
||||
style: {
|
||||
run: {
|
||||
|
@ -1,8 +1,26 @@
|
||||
// http://officeopenxml.com/WPnumbering-numFmt.php
|
||||
import { Attributes, XmlAttributeComponent, XmlComponent } from "file/xml-components";
|
||||
import { AlignmentType } from "../paragraph/formatting";
|
||||
import { IParagraphStylePropertiesOptions, ParagraphProperties } from "../paragraph/properties";
|
||||
import { IRunStylePropertiesOptions, RunProperties } from "../paragraph/run/properties";
|
||||
|
||||
export enum LevelFormat {
|
||||
BULLET = "bullet",
|
||||
CARDINAL_TEXT = "cardinalText",
|
||||
CHICAGO = "chicago",
|
||||
DECIMAL = "decimal",
|
||||
DECIMAL_ENCLOSED_CIRCLE = "decimalEnclosedCircle",
|
||||
DECIMAL_ENCLOSED_FULLSTOP = "decimalEnclosedFullstop",
|
||||
DECIMAL_ENCLOSED_PARENTHESES = "decimalEnclosedParen",
|
||||
DECIMAL_ZERO = "decimalZero",
|
||||
LOWER_LETTER = "lowerLetter",
|
||||
LOWER_ROMAN = "lowerRoman",
|
||||
NONE = "none",
|
||||
ORDINAL_TEXT = "ordinalText",
|
||||
UPPER_LETTER = "upperLetter",
|
||||
UPPER_ROMAN = "upperRoman",
|
||||
}
|
||||
|
||||
interface ILevelAttributesProperties {
|
||||
readonly ilvl?: number;
|
||||
readonly tentative?: number;
|
||||
@ -67,7 +85,7 @@ export enum LevelSuffix {
|
||||
|
||||
export interface ILevelsOptions {
|
||||
readonly level: number;
|
||||
readonly format?: string;
|
||||
readonly format?: LevelFormat;
|
||||
readonly text?: string;
|
||||
readonly alignment?: AlignmentType;
|
||||
readonly start?: number;
|
||||
|
@ -1,10 +1,11 @@
|
||||
// http://officeopenxml.com/WPnumbering.php
|
||||
import { convertInchesToTwip } from "convenience-functions";
|
||||
import { AlignmentType } from "file/paragraph";
|
||||
import { IXmlableObject, XmlComponent } from "file/xml-components";
|
||||
|
||||
import { DocumentAttributes } from "../document/document-attributes";
|
||||
import { AbstractNumbering } from "./abstract-numbering";
|
||||
import { ILevelsOptions } from "./level";
|
||||
import { ILevelsOptions, LevelFormat } from "./level";
|
||||
import { ConcreteNumbering } from "./num";
|
||||
|
||||
export interface INumberingOptions {
|
||||
@ -50,100 +51,100 @@ export class Numbering extends XmlComponent {
|
||||
const abstractNumbering = this.createAbstractNumbering([
|
||||
{
|
||||
level: 0,
|
||||
format: "bullet",
|
||||
format: LevelFormat.BULLET,
|
||||
text: "\u25CF",
|
||||
alignment: AlignmentType.LEFT,
|
||||
style: {
|
||||
paragraph: {
|
||||
indent: { left: 720, hanging: 360 },
|
||||
indent: { left: convertInchesToTwip(0.5), hanging: convertInchesToTwip(0.25) },
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
level: 1,
|
||||
format: "bullet",
|
||||
format: LevelFormat.BULLET,
|
||||
text: "\u25CB",
|
||||
alignment: AlignmentType.LEFT,
|
||||
style: {
|
||||
paragraph: {
|
||||
indent: { left: 1440, hanging: 360 },
|
||||
indent: { left: convertInchesToTwip(1), hanging: convertInchesToTwip(0.25) },
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
level: 2,
|
||||
format: "bullet",
|
||||
format: LevelFormat.BULLET,
|
||||
text: "\u25A0",
|
||||
alignment: AlignmentType.LEFT,
|
||||
style: {
|
||||
paragraph: {
|
||||
indent: { left: 2160, hanging: 360 },
|
||||
indent: { left: 2160, hanging: convertInchesToTwip(0.25) },
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
level: 3,
|
||||
format: "bullet",
|
||||
format: LevelFormat.BULLET,
|
||||
text: "\u25CF",
|
||||
alignment: AlignmentType.LEFT,
|
||||
style: {
|
||||
paragraph: {
|
||||
indent: { left: 2880, hanging: 360 },
|
||||
indent: { left: 2880, hanging: convertInchesToTwip(0.25) },
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
level: 4,
|
||||
format: "bullet",
|
||||
format: LevelFormat.BULLET,
|
||||
text: "\u25CB",
|
||||
alignment: AlignmentType.LEFT,
|
||||
style: {
|
||||
paragraph: {
|
||||
indent: { left: 3600, hanging: 360 },
|
||||
indent: { left: 3600, hanging: convertInchesToTwip(0.25) },
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
level: 5,
|
||||
format: "bullet",
|
||||
format: LevelFormat.BULLET,
|
||||
text: "\u25A0",
|
||||
alignment: AlignmentType.LEFT,
|
||||
style: {
|
||||
paragraph: {
|
||||
indent: { left: 4320, hanging: 360 },
|
||||
indent: { left: 4320, hanging: convertInchesToTwip(0.25) },
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
level: 6,
|
||||
format: "bullet",
|
||||
format: LevelFormat.BULLET,
|
||||
text: "\u25CF",
|
||||
alignment: AlignmentType.LEFT,
|
||||
style: {
|
||||
paragraph: {
|
||||
indent: { left: 5040, hanging: 360 },
|
||||
indent: { left: 5040, hanging: convertInchesToTwip(0.25) },
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
level: 7,
|
||||
format: "bullet",
|
||||
format: LevelFormat.BULLET,
|
||||
text: "\u25CF",
|
||||
alignment: AlignmentType.LEFT,
|
||||
style: {
|
||||
paragraph: {
|
||||
indent: { left: 5760, hanging: 360 },
|
||||
indent: { left: 5760, hanging: convertInchesToTwip(0.25) },
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
level: 8,
|
||||
format: "bullet",
|
||||
format: LevelFormat.BULLET,
|
||||
text: "\u25CF",
|
||||
alignment: AlignmentType.LEFT,
|
||||
style: {
|
||||
paragraph: {
|
||||
indent: { left: 6480, hanging: 360 },
|
||||
indent: { left: 6480, hanging: convertInchesToTwip(0.25) },
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -239,13 +239,29 @@ describe("Run", () => {
|
||||
|
||||
describe("#break()", () => {
|
||||
it("it should add break to the run", () => {
|
||||
const run = new Run({});
|
||||
run.break();
|
||||
const run = new Run({
|
||||
break: 1,
|
||||
});
|
||||
const tree = new Formatter().format(run);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:r": [{ "w:br": {} }],
|
||||
});
|
||||
});
|
||||
|
||||
it("it should add two breaks to the run", () => {
|
||||
const run = new Run({
|
||||
break: 2,
|
||||
});
|
||||
const tree = new Formatter().format(run);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:r": [
|
||||
{ "w:br": {} },
|
||||
{
|
||||
"w:br": {},
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("#font()", () => {
|
||||
|
@ -11,6 +11,7 @@ import { Text } from "./run-components/text";
|
||||
|
||||
export interface IRunOptions extends IRunPropertiesOptions {
|
||||
readonly children?: (Begin | FieldInstruction | Separate | End | PageNumber | FootnoteReferenceRun | string)[];
|
||||
readonly break?: number;
|
||||
readonly text?: string;
|
||||
}
|
||||
|
||||
@ -62,10 +63,11 @@ export class Run extends XmlComponent {
|
||||
} else if (options.text) {
|
||||
this.root.push(new Text(options.text));
|
||||
}
|
||||
}
|
||||
|
||||
public break(): Run {
|
||||
this.root.splice(1, 0, new Break());
|
||||
return this;
|
||||
if (options.break) {
|
||||
for (let i = 0; i < options.break; i++) {
|
||||
this.root.splice(1, 0, new Break());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -16,6 +16,7 @@ import {
|
||||
IBaseCharacterStyleOptions,
|
||||
IBaseParagraphStyleOptions,
|
||||
ListParagraph,
|
||||
StrongStyle,
|
||||
TitleStyle,
|
||||
} from "./style";
|
||||
|
||||
@ -28,6 +29,7 @@ export interface IDefaultStylesOptions {
|
||||
readonly heading4?: IBaseParagraphStyleOptions;
|
||||
readonly heading5?: IBaseParagraphStyleOptions;
|
||||
readonly heading6?: IBaseParagraphStyleOptions;
|
||||
readonly strong?: IBaseParagraphStyleOptions;
|
||||
readonly listParagraph?: IBaseParagraphStyleOptions;
|
||||
readonly hyperlink?: IBaseCharacterStyleOptions;
|
||||
readonly footnoteReference?: IBaseCharacterStyleOptions;
|
||||
@ -95,6 +97,12 @@ export class DefaultStylesFactory {
|
||||
},
|
||||
...options.heading6,
|
||||
}),
|
||||
new StrongStyle({
|
||||
run: {
|
||||
bold: true,
|
||||
},
|
||||
...options.strong,
|
||||
}),
|
||||
new ListParagraph(options.listParagraph || {}),
|
||||
new HyperlinkStyle(options.hyperlink || {}),
|
||||
new FootnoteReferenceStyle(options.footnoteReference || {}),
|
||||
|
@ -120,6 +120,20 @@ describe("Default Styles", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("StrongStyle#constructor", () => {
|
||||
const style = new defaultStyles.StrongStyle({});
|
||||
const tree = new Formatter().format(style);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:style": [
|
||||
{ _attr: { "w:type": "paragraph", "w:styleId": "Strong" } },
|
||||
{ "w:name": { _attr: { "w:val": "Strong" } } },
|
||||
{ "w:basedOn": { _attr: { "w:val": "Normal" } } },
|
||||
{ "w:next": { _attr: { "w:val": "Normal" } } },
|
||||
{ "w:qFormat": EMPTY_OBJECT },
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
it("ListParagraph#constructor", () => {
|
||||
const style = new defaultStyles.ListParagraph({});
|
||||
const tree = new Formatter().format(style);
|
||||
|
@ -84,6 +84,16 @@ export class Heading6Style extends HeadingStyle {
|
||||
}
|
||||
}
|
||||
|
||||
export class StrongStyle extends HeadingStyle {
|
||||
constructor(options: IBaseParagraphStyleOptions) {
|
||||
super({
|
||||
...options,
|
||||
id: "Strong",
|
||||
name: "Strong",
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export class ListParagraph extends StyleForParagraph {
|
||||
constructor(options: IBaseParagraphStyleOptions) {
|
||||
super({
|
||||
|
@ -546,5 +546,77 @@ describe("TableBorders", () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("TableBorders.NONE convenience object", () => {
|
||||
it("should add no borders", () => {
|
||||
const tableBorders = new TableBorders(TableBorders.NONE);
|
||||
const tree = new Formatter().format(tableBorders);
|
||||
|
||||
expect(tree).to.deep.equal({
|
||||
"w:tblBorders": [
|
||||
{
|
||||
"w:top": {
|
||||
_attr: {
|
||||
"w:color": "auto",
|
||||
"w:space": 0,
|
||||
"w:sz": 0,
|
||||
"w:val": "none",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
"w:left": {
|
||||
_attr: {
|
||||
"w:color": "auto",
|
||||
"w:space": 0,
|
||||
"w:sz": 0,
|
||||
"w:val": "none",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
"w:bottom": {
|
||||
_attr: {
|
||||
"w:color": "auto",
|
||||
"w:space": 0,
|
||||
"w:sz": 0,
|
||||
"w:val": "none",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
"w:right": {
|
||||
_attr: {
|
||||
"w:color": "auto",
|
||||
"w:space": 0,
|
||||
"w:sz": 0,
|
||||
"w:val": "none",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
"w:insideH": {
|
||||
_attr: {
|
||||
"w:color": "auto",
|
||||
"w:space": 0,
|
||||
"w:sz": 0,
|
||||
"w:val": "none",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
"w:insideV": {
|
||||
_attr: {
|
||||
"w:color": "auto",
|
||||
"w:space": 0,
|
||||
"w:sz": 0,
|
||||
"w:val": "none",
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -36,6 +36,39 @@ export interface ITableBordersOptions {
|
||||
}
|
||||
|
||||
export class TableBorders extends XmlComponent {
|
||||
public static readonly NONE = {
|
||||
top: {
|
||||
style: BorderStyle.NONE,
|
||||
size: 0,
|
||||
color: "auto",
|
||||
},
|
||||
bottom: {
|
||||
style: BorderStyle.NONE,
|
||||
size: 0,
|
||||
color: "auto",
|
||||
},
|
||||
left: {
|
||||
style: BorderStyle.NONE,
|
||||
size: 0,
|
||||
color: "auto",
|
||||
},
|
||||
right: {
|
||||
style: BorderStyle.NONE,
|
||||
size: 0,
|
||||
color: "auto",
|
||||
},
|
||||
insideHorizontal: {
|
||||
style: BorderStyle.NONE,
|
||||
size: 0,
|
||||
color: "auto",
|
||||
},
|
||||
insideVertical: {
|
||||
style: BorderStyle.NONE,
|
||||
size: 0,
|
||||
color: "auto",
|
||||
},
|
||||
};
|
||||
|
||||
constructor(options: ITableBordersOptions) {
|
||||
super("w:tblBorders");
|
||||
|
||||
|
@ -89,11 +89,12 @@ describe("DeletedTextRun", () => {
|
||||
describe("#break()", () => {
|
||||
it("should add a break", () => {
|
||||
const deletedTextRun = new DeletedTextRun({
|
||||
break: 1,
|
||||
children: ["some text"],
|
||||
id: 0,
|
||||
date: "123",
|
||||
author: "Author",
|
||||
}).break();
|
||||
});
|
||||
const tree = new Formatter().format(deletedTextRun);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:del": [
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { XmlComponent } from "file/xml-components";
|
||||
|
||||
import { FootnoteReferenceRun, IRunOptions, IRunPropertiesOptions, RunProperties } from "../../index";
|
||||
import { IRunOptions, RunProperties } from "../../index";
|
||||
import { Break } from "../../paragraph/run/break";
|
||||
import { Begin, End, Separate } from "../../paragraph/run/field";
|
||||
import { PageNumber } from "../../paragraph/run/run";
|
||||
@ -8,10 +8,7 @@ import { ChangeAttributes, IChangedAttributesProperties } from "../track-revisio
|
||||
import { DeletedNumberOfPages, DeletedNumberOfPagesSection, DeletedPage } from "./deleted-page-number";
|
||||
import { DeletedText } from "./deleted-text";
|
||||
|
||||
interface IDeletedRunOptions extends IRunPropertiesOptions, IChangedAttributesProperties {
|
||||
readonly children?: (Begin | Separate | End | PageNumber | FootnoteReferenceRun | string)[];
|
||||
readonly text?: string;
|
||||
}
|
||||
interface IDeletedRunOptions extends IRunOptions, IChangedAttributesProperties {}
|
||||
|
||||
export class DeletedTextRun extends XmlComponent {
|
||||
protected readonly deletedTextRunWrapper: DeletedTextRunWrapper;
|
||||
@ -25,14 +22,9 @@ export class DeletedTextRun extends XmlComponent {
|
||||
date: options.date,
|
||||
}),
|
||||
);
|
||||
this.deletedTextRunWrapper = new DeletedTextRunWrapper(options as IRunOptions);
|
||||
this.deletedTextRunWrapper = new DeletedTextRunWrapper(options);
|
||||
this.addChildElement(this.deletedTextRunWrapper);
|
||||
}
|
||||
|
||||
public break(): DeletedTextRun {
|
||||
this.deletedTextRunWrapper.break();
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
class DeletedTextRunWrapper extends XmlComponent {
|
||||
@ -74,9 +66,11 @@ class DeletedTextRunWrapper extends XmlComponent {
|
||||
} else if (options.text) {
|
||||
this.root.push(new DeletedText(options.text));
|
||||
}
|
||||
}
|
||||
|
||||
public break(): void {
|
||||
this.root.splice(1, 0, new Break());
|
||||
if (options.break) {
|
||||
for (let i = 0; i < options.break; i++) {
|
||||
this.root.splice(1, 0, new Break());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -46,7 +46,9 @@ export interface IDocumentTemplate {
|
||||
}
|
||||
|
||||
export class ImportDotx {
|
||||
public async extract(data: Buffer): Promise<IDocumentTemplate> {
|
||||
public async extract(
|
||||
data: Buffer | string | number[] | Uint8Array | ArrayBuffer | Blob | NodeJS.ReadableStream,
|
||||
): Promise<IDocumentTemplate> {
|
||||
const zipContent = await JSZip.loadAsync(data);
|
||||
|
||||
const documentContent = await zipContent.files["word/document.xml"].async("text");
|
||||
|
@ -4,3 +4,4 @@ export { File as Document } from "./file";
|
||||
export * from "./file";
|
||||
export * from "./export";
|
||||
export * from "./import-dotx";
|
||||
export * from "./convenience-functions";
|
||||
|
Reference in New Issue
Block a user