Compare commits

..

1 Commits

Author SHA1 Message Date
5e87e4fb0b Add run properties to paragraph 2020-12-19 20:06:23 +00:00
43 changed files with 244 additions and 981 deletions

View File

@ -7,7 +7,6 @@ indent_style = space
indent_size = 4
insert_final_newline = true
trim_trailing_whitespace = true
end_of_line = lf
[*.md]
max_line_length = off

View File

@ -204,10 +204,7 @@ class DocumentCreator {
alignment: AlignmentType.CENTER,
children: [
new TextRun(`Mobile: ${phoneNumber} | LinkedIn: ${profileUrl} | Email: ${email}`),
new TextRun({
text: "Address: 58 Elm Avenue, Kent ME4 6ER, UK",
break: 1,
}),
new TextRun("Address: 58 Elm Avenue, Kent ME4 6ER, UK").break(),
],
});
}

View File

@ -3,7 +3,6 @@
import * as fs from "fs";
import {
AlignmentType,
convertInchesToTwip,
Document,
Footer,
HeadingLevel,
@ -111,7 +110,7 @@ const doc = new Document({
},
paragraph: {
spacing: { line: 276 },
indent: { left: convertInchesToTwip(0.5) },
indent: { left: 720 },
},
},
{

View File

@ -1,17 +1,7 @@
// 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,
convertInchesToTwip,
Document,
HeadingLevel,
LevelFormat,
Packer,
Paragraph,
TextRun,
UnderlineType,
} from "../build";
import { AlignmentType, Document, HeadingLevel, Packer, Paragraph, TextRun, UnderlineType } from "../build";
const doc = new Document({
creator: "Clippy",
@ -50,9 +40,9 @@ const doc = new Document({
},
listParagraph: {
run: {
color: "#FF0000",
},
},
color: '#FF0000'
}
}
},
paragraphStyles: [
{
@ -66,7 +56,7 @@ const doc = new Document({
},
paragraph: {
indent: {
left: convertInchesToTwip(0.5),
left: 720,
},
spacing: {
line: 276,
@ -91,7 +81,7 @@ const doc = new Document({
levels: [
{
level: 0,
format: LevelFormat.LOWER_LETTER,
format: "lowerLetter",
text: "%1)",
alignment: AlignmentType.LEFT,
},
@ -171,17 +161,6 @@ doc.addSection({
}),
],
}),
new Paragraph({
style: "Strong",
children: [
new TextRun({
text: "Strong Style",
}),
new TextRun({
text: " - Very strong.",
}),
],
}),
],
});

View File

@ -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, convertInchesToTwip, HeadingLevel, Packer, Paragraph, UnderlineType } from "../build";
import { Document, HeadingLevel, Packer, Paragraph, UnderlineType } from "../build";
const doc = new Document({
styles: {
@ -17,7 +17,7 @@ const doc = new Document({
},
paragraph: {
indent: {
left: convertInchesToTwip(0.5),
left: 720,
},
spacing: {
line: 276,

View File

@ -1,7 +1,7 @@
// Numbered lists
// Import from 'docx' rather than '../build' if you install from npm
import * as fs from "fs";
import { AlignmentType, convertInchesToTwip, Document, LevelFormat, Packer, Paragraph } from "../build";
import { AlignmentType, Document, Packer, Paragraph } from "../build";
const doc = new Document({
numbering: {
@ -10,12 +10,12 @@ const doc = new Document({
levels: [
{
level: 0,
format: LevelFormat.UPPER_ROMAN,
format: "upperRoman",
text: "%1",
alignment: AlignmentType.START,
style: {
paragraph: {
indent: { left: convertInchesToTwip(0.5), hanging: convertInchesToTwip(0.18) },
indent: { left: 720, hanging: 260 },
},
},
},
@ -26,34 +26,18 @@ const doc = new Document({
levels: [
{
level: 0,
format: LevelFormat.DECIMAL,
format: "decimal",
text: "%1",
alignment: AlignmentType.START,
style: {
paragraph: {
indent: { left: convertInchesToTwip(0.5), hanging: convertInchesToTwip(0.18) },
indent: { left: 720, hanging: 260 },
},
},
},
],
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",
},
],
},
});
@ -125,139 +109,6 @@ 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,
},
}),
],
});

View File

@ -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, convertInchesToTwip, Document, LevelFormat, Packer, Paragraph } from "../build";
import { AlignmentType, Document, Packer, Paragraph } from "../build";
const doc = new Document({
numbering: {
@ -11,40 +11,40 @@ const doc = new Document({
levels: [
{
level: 0,
format: LevelFormat.UPPER_ROMAN,
format: "upperRoman",
text: "%1",
alignment: AlignmentType.START,
style: {
paragraph: {
indent: { left: convertInchesToTwip(0.5), hanging: convertInchesToTwip(0.18) },
indent: { left: 720, hanging: 260 },
},
},
},
{
level: 1,
format: LevelFormat.DECIMAL,
format: "decimal",
text: "%2.",
alignment: AlignmentType.START,
style: {
paragraph: {
indent: { left: convertInchesToTwip(1), hanging: convertInchesToTwip(0.68) },
indent: { left: 1440, hanging: 980 },
},
},
},
{
level: 2,
format: LevelFormat.LOWER_LETTER,
format: "lowerLetter",
text: "%3)",
alignment: AlignmentType.START,
style: {
paragraph: {
indent: { left: convertInchesToTwip(1.5), hanging: convertInchesToTwip(1.18) },
indent: { left: 2160, hanging: 1700 },
},
},
},
{
level: 3,
format: LevelFormat.UPPER_LETTER,
format: "upperLetter",
text: "%4)",
alignment: AlignmentType.START,
style: {

View File

@ -2,20 +2,7 @@
// 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,
convertInchesToTwip,
Document,
HeadingLevel,
Packer,
Paragraph,
ShadingType,
Table,
TableCell,
TableRow,
WidthType,
} from "../build";
import { AlignmentType, BorderStyle, Document, HeadingLevel, Packer, Paragraph, ShadingType, Table, TableCell, TableRow, WidthType } from "../build";
const doc = new Document();
@ -50,10 +37,10 @@ const table2 = new Table({
new TableCell({
children: [new Paragraph("World")],
margins: {
top: convertInchesToTwip(0.69),
bottom: convertInchesToTwip(0.69),
left: convertInchesToTwip(0.69),
right: convertInchesToTwip(0.69),
top: 1000,
bottom: 1000,
left: 1000,
right: 1000,
},
columnSpan: 3,
}),
@ -77,7 +64,7 @@ const table2 = new Table({
size: 100,
type: WidthType.AUTO,
},
columnWidths: [convertInchesToTwip(0.69), convertInchesToTwip(0.69), convertInchesToTwip(0.69)],
columnWidths: [1000, 1000, 1000],
});
const table3 = new Table({
@ -132,14 +119,14 @@ const table3 = new Table({
}),
],
width: {
size: convertInchesToTwip(4.86),
size: 7000,
type: WidthType.DXA,
},
margins: {
top: convertInchesToTwip(0.27),
bottom: convertInchesToTwip(0.27),
right: convertInchesToTwip(0.27),
left: convertInchesToTwip(0.27),
top: 400,
bottom: 400,
right: 400,
left: 400,
},
});
@ -368,7 +355,9 @@ const table8 = new Table({
],
}),
new TableRow({
children: [new TableCell({ children: [new Paragraph("4,1")] })],
children: [
new TableCell({ children: [new Paragraph("4,1")] }),
],
}),
],
width: {

View File

@ -1,19 +1,7 @@
// Add custom borders and no-borders to the table itself
// Add custom borders to the table itself
// Import from 'docx' rather than '../build' if you install from npm
import * as fs from "fs";
import {
BorderStyle,
Document,
HeadingLevel,
Packer,
Paragraph,
Table,
TableBorders,
TableCell,
TableRow,
TextDirection,
VerticalAlign,
} from "../build";
import { BorderStyle, Document, Packer, Paragraph, Table, TableCell, TableRow } from "../build";
const doc = new Document();
@ -22,28 +10,6 @@ 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({
@ -64,103 +30,7 @@ const table = new 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] });
doc.addSection({ children: [table] });
Packer.toBuffer(doc).then((buffer) => {
fs.writeFileSync("My Document.docx", buffer);

View File

@ -22,7 +22,6 @@ 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,
},
@ -34,7 +33,6 @@ 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,

View File

@ -15,14 +15,6 @@ const doc = new Document({
italics: true,
},
},
{
id: "strong",
name: "Strong",
basedOn: "Normal",
run: {
bold: true,
},
},
],
},
});
@ -37,18 +29,6 @@ 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.",
}),
],
}),
],
});

View File

@ -80,7 +80,6 @@ doc.addSection({
children: [
new TextRun("This is a demo "),
new DeletedTextRun({
break: 1,
text: "in order",
color: "red",
bold: true,
@ -96,7 +95,7 @@ doc.addSection({
id: 2,
author: "Firstname Lastname",
date: "2020-10-06T09:00:00Z",
}),
}).break(),
new InsertedTextRun({
text: "to show how to ",
bold: false,

View File

@ -1,88 +0,0 @@
// 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);
});

View File

@ -0,0 +1,31 @@
// Add Run styles across the whole Paragraph
// Import from 'docx' rather than '../build' if you install from npm
import * as fs from "fs";
import { Document, Packer, Paragraph, TextRun } from "../build";
const doc = new Document();
doc.addSection({
children: [
new Paragraph({
runStyle: {
size: 100,
},
children: [
new TextRun("Hello World"),
new TextRun({
text: "Foo Bar",
bold: true,
}),
new TextRun({
text: "\tGithub is the best",
bold: true,
}),
],
}),
],
});
Packer.toBuffer(doc).then((buffer) => {
fs.writeFileSync("My Document.docx", buffer);
});

View File

@ -28,8 +28,5 @@
* Exporting
* [Packers](usage/packers.md)
* Utility
* [Convenience functions](usage/convenience-functions.md)
* [Contribution Guidelines](contribution-guidelines.md)

View File

@ -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 be
level: 0, // How deep you want the bullet to me
},
});
```

View File

@ -1,22 +0,0 @@
# 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
```

View File

@ -125,7 +125,6 @@ Full options you can pass into `floating` are:
| lockAnchor | `boolean` | Optional |
| behindDocument | `boolean` | Optional |
| layoutInCell | `boolean` | Optional |
| zIndex | `number` | Optional |
`HorizontalPositionOptions` are:

View File

@ -158,15 +158,6 @@ Sometimes you would want to put text underneath another line of text but inside
```ts
const text = new TextRun({
text: "break",
break: 1,
});
```
Adding two breaks:
```ts
const text = new TextRun({
text: "break",
break: 2,
break: true,
});
```

83
package-lock.json generated
View File

@ -462,9 +462,9 @@
"dev": true
},
"@sinonjs/commons": {
"version": "1.8.2",
"resolved": "https://registry.npmjs.org/@sinonjs/commons/-/commons-1.8.2.tgz",
"integrity": "sha512-sruwd86RJHdsVf/AtBoijDmUqJp3B6hF/DGC23C+JaegnDHaZyewCjoVGTdg3J0uz3Zs7NnIT05OBOmML72lQw==",
"version": "1.8.1",
"resolved": "https://registry.npmjs.org/@sinonjs/commons/-/commons-1.8.1.tgz",
"integrity": "sha512-892K+kWUUi3cl+LlqEWIDrhvLgdL79tECi8JZUyq6IviKy/DNhuzCRlbHUjxK89f4ypPMMaFnFuR9Ie6DoIMsw==",
"dev": true,
"requires": {
"type-detect": "4.0.8"
@ -487,10 +487,20 @@
"@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.3.1",
"resolved": "https://registry.npmjs.org/@sinonjs/samsam/-/samsam-5.3.1.tgz",
"integrity": "sha512-1Hc0b1TtyfBu8ixF/tpfSHTVWKwCBLY4QJbkgnE7HcwyvT2xArDxb4K7dMgqRm3szI+LJbzmW/s4xxEhv6hwDg==",
"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==",
"dev": true,
"requires": {
"@sinonjs/commons": "^1.6.0",
@ -660,9 +670,9 @@
}
},
"@types/webpack": {
"version": "4.41.26",
"resolved": "https://registry.npmjs.org/@types/webpack/-/webpack-4.41.26.tgz",
"integrity": "sha512-7ZyTfxjCRwexh+EJFwRUM+CDB2XvgHl4vfuqf1ZKrgGvcS5BrNvPQqJh3tsZ0P6h6Aa1qClVHaJZszLPzpqHeA==",
"version": "4.41.25",
"resolved": "https://registry.npmjs.org/@types/webpack/-/webpack-4.41.25.tgz",
"integrity": "sha512-cr6kZ+4m9lp86ytQc1jPOJXgINQyz3kLLunZ57jznW+WIAL0JqZbGubQk4GlD42MuQL5JGOABrxdpqqWeovlVQ==",
"dev": true,
"requires": {
"@types/anymatch": "*",
@ -674,9 +684,9 @@
}
},
"@types/webpack-sources": {
"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==",
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/@types/webpack-sources/-/webpack-sources-2.0.0.tgz",
"integrity": "sha512-a5kPx98CNFRKQ+wqawroFunvFqv7GHm/3KOI52NY9xWADgc8smu4R6prt4EU/M4QfVjvgBkMqU4fBhw3QfMVkg==",
"dev": true,
"requires": {
"@types/node": "*",
@ -1922,9 +1932,9 @@
"dev": true
},
"colors": {
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/colors/-/colors-1.4.0.tgz",
"integrity": "sha512-a+UqTh4kgZg/SlGvfbzDHpgRu7AAQOmmqRHJnxhRZICKFUT91brVhNNt58CMWU9PsBbv3PDCZUHbVxuDiH2mtA==",
"version": "1.3.3",
"resolved": "https://registry.npmjs.org/colors/-/colors-1.3.3.tgz",
"integrity": "sha512-mmGt/1pZqYRjMxB1axhTo16/snVZ5krrKkcmMeVKxzECMMXoCgnvTPp10QgHfcbQZw8Dq2jMNG6je4JlWU0gWg==",
"dev": true
},
"combined-stream": {
@ -5588,9 +5598,9 @@
"dev": true
},
"mute-stream": {
"version": "0.0.8",
"resolved": "https://registry.npmjs.org/mute-stream/-/mute-stream-0.0.8.tgz",
"integrity": "sha512-nnbWWOkoWyUsTjKrhgD0dcz22mdkSnpYqbEjIm2nhwhuxlSkpywJmBo8h0ZqJdkp73mb90SssHkN4rsRaBAfAA==",
"version": "0.0.7",
"resolved": "https://registry.npmjs.org/mute-stream/-/mute-stream-0.0.7.tgz",
"integrity": "sha1-MHXOk7whuPq0PhvE2n6BFe0ee6s=",
"dev": true
},
"nan": {
@ -6491,6 +6501,12 @@
}
}
},
"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",
@ -6562,16 +6578,17 @@
"dev": true
},
"prompt": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/prompt/-/prompt-1.1.0.tgz",
"integrity": "sha512-ec1vUPXCplDBDUVD8uPa3XGA+OzLrO40Vxv3F1uxoiZGkZhdctlK2JotcHq5X6ExjocDOGwGdCSXloGNyU5L1Q==",
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/prompt/-/prompt-1.0.0.tgz",
"integrity": "sha1-jlcSPDlquYiJf7Mn/Trtw+c15P4=",
"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.x"
"winston": "2.1.x"
}
},
"prr": {
@ -7348,14 +7365,15 @@
"dev": true
},
"sinon": {
"version": "9.2.4",
"resolved": "https://registry.npmjs.org/sinon/-/sinon-9.2.4.tgz",
"integrity": "sha512-zljcULZQsJxVra28qIAL6ow1Z9tpattkCTEJR4RBP3TGc00FcttsP5pK284Nas5WjMZU5Yzy3kAIp3B3KRf5Yg==",
"version": "9.2.1",
"resolved": "https://registry.npmjs.org/sinon/-/sinon-9.2.1.tgz",
"integrity": "sha512-naPfsamB5KEE1aiioaoqJ6MEhdUs/2vtI5w1hPAXX/UwvoPjXcwh1m5HiKx0HGgKR8lQSoFIgY5jM6KK8VrS9w==",
"dev": true,
"requires": {
"@sinonjs/commons": "^1.8.1",
"@sinonjs/fake-timers": "^6.0.1",
"@sinonjs/samsam": "^5.3.1",
"@sinonjs/formatio": "^5.0.1",
"@sinonjs/samsam": "^5.2.0",
"diff": "^4.0.2",
"nise": "^4.0.4",
"supports-color": "^7.1.0"
@ -8968,9 +8986,9 @@
"dev": true
},
"winston": {
"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==",
"version": "2.1.1",
"resolved": "https://registry.npmjs.org/winston/-/winston-2.1.1.tgz",
"integrity": "sha1-PJNJ0ZYgf9G9/51LxD73JRDjoS4=",
"dev": true,
"requires": {
"async": "~1.0.0",
@ -8978,6 +8996,7 @@
"cycle": "1.0.x",
"eyes": "0.1.x",
"isstream": "0.1.x",
"pkginfo": "0.3.x",
"stack-trace": "0.0.x"
},
"dependencies": {
@ -8992,6 +9011,12 @@
"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
}
}
},

View File

@ -1,6 +1,6 @@
{
"name": "docx",
"version": "5.5.0",
"version": "5.4.1",
"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": {

View File

@ -1,18 +0,0 @@
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);
});
});
});

View File

@ -1,8 +0,0 @@
// 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);
};

View File

@ -1,6 +1,5 @@
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";
@ -19,10 +18,10 @@ describe("SectionProperties", () => {
const properties = new SectionProperties({
width: 11906,
height: 16838,
top: convertInchesToTwip(1),
right: convertInchesToTwip(1),
bottom: convertInchesToTwip(1),
left: convertInchesToTwip(1),
top: 1440,
right: 1440,
bottom: 1440,
left: 1440,
header: 708,
footer: 708,
gutter: 0,
@ -31,7 +30,7 @@ describe("SectionProperties", () => {
space: 708,
count: 1,
},
linePitch: convertInchesToTwip(0.25),
linePitch: 360,
headers: {
default: new HeaderWrapper(media, 100),
},

View File

@ -1,5 +1,4 @@
// 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";
@ -65,10 +64,10 @@ export class SectionProperties extends XmlComponent {
const {
width = 11906,
height = 16838,
top = convertInchesToTwip(1),
right = convertInchesToTwip(1),
bottom = convertInchesToTwip(1),
left = convertInchesToTwip(1),
top = 1440,
right = 1440,
bottom = 1440,
left = 1440,
header = 708,
footer = 708,
gutter = 0,

View File

@ -218,150 +218,5 @@ 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,
});
});
});
});

View File

@ -11,32 +11,42 @@ import { Extent } from "./../extent/extent";
import { GraphicFrameProperties } from "./../graphic-frame/graphic-frame-properties";
import { AnchorAttributes } from "./anchor-attributes";
export class Anchor extends XmlComponent {
constructor(mediaData: IMediaData, dimensions: IMediaDataDimensions, drawingOptions: IDrawingOptions) {
super("wp:anchor");
const floating: IFloating = {
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,
...drawingOptions.floating,
};
this.root.push(
new AnchorAttributes({
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,
distT: floating.margins.top || 0,
distB: floating.margins.bottom || 0,
distL: floating.margins.left || 0,
distR: floating.margins.right || 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: floating.zIndex ? floating.zIndex : dimensions.emus.y,
relativeHeight: dimensions.emus.y,
}),
);

View File

@ -1,5 +1,4 @@
// http://officeopenxml.com/drwPicFloating-position.php
// http://officeopenxml.com/drwPicFloating.php
import { ITextWrapping } from "../text-wrap";
export enum HorizontalPositionRelativeFrom {
@ -68,5 +67,4 @@ export interface IFloating {
readonly layoutInCell?: boolean;
readonly margins?: IMargins;
readonly wrap?: ITextWrapping;
readonly zIndex?: number;
}

View File

@ -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 { LevelFormat, LevelSuffix } from "./level";
import { 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: LevelFormat.LOWER_LETTER,
format: "lowerLetter",
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": LevelFormat.LOWER_LETTER } } });
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:lvlText": { _attr: { "w:val": "%1)" } } });
});
@ -37,7 +37,7 @@ describe("AbstractNumbering", () => {
const abstractNumbering = new AbstractNumbering(1, [
{
level: 3,
format: LevelFormat.LOWER_LETTER,
format: "lowerLetter",
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": LevelFormat.LOWER_LETTER } } });
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:lvlText": { _attr: { "w:val": "%1)" } } });
});
@ -53,7 +53,7 @@ describe("AbstractNumbering", () => {
const abstractNumbering = new AbstractNumbering(1, [
{
level: 3,
format: LevelFormat.LOWER_LETTER,
format: "lowerLetter",
text: "%1)",
alignment: AlignmentType.END,
suffix: LevelSuffix.SPACE,
@ -68,7 +68,7 @@ describe("AbstractNumbering", () => {
const abstractNumbering = new AbstractNumbering(1, [
{
level: 0,
format: LevelFormat.LOWER_ROMAN,
format: "lowerRoman",
text: "%0.",
style: {
paragraph: {
@ -87,7 +87,7 @@ describe("AbstractNumbering", () => {
const abstractNumbering = new AbstractNumbering(1, [
{
level: 0,
format: LevelFormat.LOWER_ROMAN,
format: "lowerRoman",
text: "%0.",
style: {
paragraph: {
@ -106,7 +106,7 @@ describe("AbstractNumbering", () => {
const abstractNumbering = new AbstractNumbering(1, [
{
level: 0,
format: LevelFormat.LOWER_ROMAN,
format: "lowerRoman",
text: "%0.",
style: {
paragraph: {
@ -125,7 +125,7 @@ describe("AbstractNumbering", () => {
const abstractNumbering = new AbstractNumbering(1, [
{
level: 0,
format: LevelFormat.LOWER_ROMAN,
format: "lowerRoman",
text: "%0.",
style: {
paragraph: {
@ -144,7 +144,7 @@ describe("AbstractNumbering", () => {
const abstractNumbering = new AbstractNumbering(1, [
{
level: 0,
format: LevelFormat.LOWER_ROMAN,
format: "lowerRoman",
text: "%0.",
style: {
paragraph: {
@ -163,7 +163,7 @@ describe("AbstractNumbering", () => {
const abstractNumbering = new AbstractNumbering(1, [
{
level: 0,
format: LevelFormat.LOWER_ROMAN,
format: "lowerRoman",
text: "%0.",
style: {
paragraph: {
@ -182,7 +182,7 @@ describe("AbstractNumbering", () => {
const abstractNumbering = new AbstractNumbering(1, [
{
level: 0,
format: LevelFormat.LOWER_ROMAN,
format: "lowerRoman",
text: "%0.",
style: {
paragraph: {
@ -216,7 +216,7 @@ describe("AbstractNumbering", () => {
const abstractNumbering = new AbstractNumbering(1, [
{
level: 0,
format: LevelFormat.LOWER_ROMAN,
format: "lowerRoman",
text: "%0.",
style: {
paragraph: {
@ -239,7 +239,7 @@ describe("AbstractNumbering", () => {
const abstractNumbering = new AbstractNumbering(1, [
{
level: 0,
format: LevelFormat.LOWER_ROMAN,
format: "lowerRoman",
text: "%0.",
style: {
paragraph: {
@ -262,7 +262,7 @@ describe("AbstractNumbering", () => {
const abstractNumbering = new AbstractNumbering(1, [
{
level: 0,
format: LevelFormat.LOWER_ROMAN,
format: "lowerRoman",
text: "%0.",
style: {
paragraph: {
@ -281,7 +281,7 @@ describe("AbstractNumbering", () => {
const abstractNumbering = new AbstractNumbering(1, [
{
level: 0,
format: LevelFormat.LOWER_ROMAN,
format: "lowerRoman",
text: "%0.",
style: {
paragraph: {
@ -324,7 +324,7 @@ describe("AbstractNumbering", () => {
const abstractNumbering = new AbstractNumbering(1, [
{
level: 0,
format: LevelFormat.LOWER_ROMAN,
format: "lowerRoman",
text: "%0.",
style: {
run: { size, sizeComplexScript },
@ -340,7 +340,7 @@ describe("AbstractNumbering", () => {
const abstractNumbering = new AbstractNumbering(1, [
{
level: 0,
format: LevelFormat.LOWER_ROMAN,
format: "lowerRoman",
text: "%0.",
style: {
run: {
@ -359,7 +359,7 @@ describe("AbstractNumbering", () => {
const abstractNumbering = new AbstractNumbering(1, [
{
level: 0,
format: LevelFormat.LOWER_ROMAN,
format: "lowerRoman",
text: "%0.",
style: {
run: {
@ -378,7 +378,7 @@ describe("AbstractNumbering", () => {
const abstractNumbering = new AbstractNumbering(1, [
{
level: 0,
format: LevelFormat.LOWER_ROMAN,
format: "lowerRoman",
text: "%0.",
style: {
run: {
@ -398,7 +398,7 @@ describe("AbstractNumbering", () => {
const abstractNumbering = new AbstractNumbering(1, [
{
level: 0,
format: LevelFormat.LOWER_ROMAN,
format: "lowerRoman",
text: "%0.",
style: {
run: {
@ -417,7 +417,7 @@ describe("AbstractNumbering", () => {
const abstractNumbering = new AbstractNumbering(1, [
{
level: 0,
format: LevelFormat.LOWER_ROMAN,
format: "lowerRoman",
text: "%0.",
style: {
run: {
@ -436,7 +436,7 @@ describe("AbstractNumbering", () => {
const abstractNumbering = new AbstractNumbering(1, [
{
level: 0,
format: LevelFormat.LOWER_ROMAN,
format: "lowerRoman",
text: "%0.",
style: {
run: {
@ -455,7 +455,7 @@ describe("AbstractNumbering", () => {
const abstractNumbering = new AbstractNumbering(1, [
{
level: 0,
format: LevelFormat.LOWER_ROMAN,
format: "lowerRoman",
text: "%0.",
style: {
run: {
@ -485,7 +485,7 @@ describe("AbstractNumbering", () => {
const abstractNumbering = new AbstractNumbering(1, [
{
level: 0,
format: LevelFormat.LOWER_ROMAN,
format: "lowerRoman",
text: "%0.",
style: {
run: {
@ -533,7 +533,7 @@ describe("AbstractNumbering", () => {
const abstractNumbering = new AbstractNumbering(1, [
{
level: 0,
format: LevelFormat.LOWER_ROMAN,
format: "lowerRoman",
text: "%0.",
style: {
run: { bold, boldComplexScript },
@ -566,7 +566,7 @@ describe("AbstractNumbering", () => {
const abstractNumbering = new AbstractNumbering(1, [
{
level: 0,
format: LevelFormat.LOWER_ROMAN,
format: "lowerRoman",
text: "%0.",
style: {
run: { italics, italicsComplexScript },
@ -604,7 +604,7 @@ describe("AbstractNumbering", () => {
const abstractNumbering = new AbstractNumbering(1, [
{
level: 0,
format: LevelFormat.LOWER_ROMAN,
format: "lowerRoman",
text: "%0.",
style: {
run: { highlight, highlightComplexScript },
@ -682,7 +682,7 @@ describe("AbstractNumbering", () => {
const abstractNumbering = new AbstractNumbering(1, [
{
level: 0,
format: LevelFormat.LOWER_ROMAN,
format: "lowerRoman",
text: "%0.",
style: {
run: { shadow, shading, shadingComplexScript },
@ -699,7 +699,7 @@ describe("AbstractNumbering", () => {
const abstractNumbering = new AbstractNumbering(1, [
{
level: 0,
format: LevelFormat.LOWER_ROMAN,
format: "lowerRoman",
text: "%0.",
style: {
run: {
@ -718,7 +718,7 @@ describe("AbstractNumbering", () => {
const abstractNumbering = new AbstractNumbering(1, [
{
level: 0,
format: LevelFormat.LOWER_ROMAN,
format: "lowerRoman",
text: "%0.",
style: {
run: {
@ -739,7 +739,7 @@ describe("AbstractNumbering", () => {
const abstractNumbering = new AbstractNumbering(1, [
{
level: 0,
format: LevelFormat.LOWER_ROMAN,
format: "lowerRoman",
text: "%0.",
style: {
run: {
@ -763,7 +763,7 @@ describe("AbstractNumbering", () => {
const abstractNumbering = new AbstractNumbering(1, [
{
level: 0,
format: LevelFormat.LOWER_ROMAN,
format: "lowerRoman",
text: "%0.",
style: {
run: {
@ -782,7 +782,7 @@ describe("AbstractNumbering", () => {
const abstractNumbering = new AbstractNumbering(1, [
{
level: 0,
format: LevelFormat.LOWER_ROMAN,
format: "lowerRoman",
text: "%0.",
style: {
run: {
@ -804,7 +804,7 @@ describe("AbstractNumbering", () => {
const abstractNumbering = new AbstractNumbering(1, [
{
level: 0,
format: LevelFormat.LOWER_ROMAN,
format: "lowerRoman",
text: "%0.",
style: {
run: {

View File

@ -1,26 +1,8 @@
// 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;
@ -85,7 +67,7 @@ export enum LevelSuffix {
export interface ILevelsOptions {
readonly level: number;
readonly format?: LevelFormat;
readonly format?: string;
readonly text?: string;
readonly alignment?: AlignmentType;
readonly start?: number;

View File

@ -1,11 +1,10 @@
// 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, LevelFormat } from "./level";
import { ILevelsOptions } from "./level";
import { ConcreteNumbering } from "./num";
export interface INumberingOptions {
@ -51,100 +50,100 @@ export class Numbering extends XmlComponent {
const abstractNumbering = this.createAbstractNumbering([
{
level: 0,
format: LevelFormat.BULLET,
format: "bullet",
text: "\u25CF",
alignment: AlignmentType.LEFT,
style: {
paragraph: {
indent: { left: convertInchesToTwip(0.5), hanging: convertInchesToTwip(0.25) },
indent: { left: 720, hanging: 360 },
},
},
},
{
level: 1,
format: LevelFormat.BULLET,
format: "bullet",
text: "\u25CB",
alignment: AlignmentType.LEFT,
style: {
paragraph: {
indent: { left: convertInchesToTwip(1), hanging: convertInchesToTwip(0.25) },
indent: { left: 1440, hanging: 360 },
},
},
},
{
level: 2,
format: LevelFormat.BULLET,
format: "bullet",
text: "\u25A0",
alignment: AlignmentType.LEFT,
style: {
paragraph: {
indent: { left: 2160, hanging: convertInchesToTwip(0.25) },
indent: { left: 2160, hanging: 360 },
},
},
},
{
level: 3,
format: LevelFormat.BULLET,
format: "bullet",
text: "\u25CF",
alignment: AlignmentType.LEFT,
style: {
paragraph: {
indent: { left: 2880, hanging: convertInchesToTwip(0.25) },
indent: { left: 2880, hanging: 360 },
},
},
},
{
level: 4,
format: LevelFormat.BULLET,
format: "bullet",
text: "\u25CB",
alignment: AlignmentType.LEFT,
style: {
paragraph: {
indent: { left: 3600, hanging: convertInchesToTwip(0.25) },
indent: { left: 3600, hanging: 360 },
},
},
},
{
level: 5,
format: LevelFormat.BULLET,
format: "bullet",
text: "\u25A0",
alignment: AlignmentType.LEFT,
style: {
paragraph: {
indent: { left: 4320, hanging: convertInchesToTwip(0.25) },
indent: { left: 4320, hanging: 360 },
},
},
},
{
level: 6,
format: LevelFormat.BULLET,
format: "bullet",
text: "\u25CF",
alignment: AlignmentType.LEFT,
style: {
paragraph: {
indent: { left: 5040, hanging: convertInchesToTwip(0.25) },
indent: { left: 5040, hanging: 360 },
},
},
},
{
level: 7,
format: LevelFormat.BULLET,
format: "bullet",
text: "\u25CF",
alignment: AlignmentType.LEFT,
style: {
paragraph: {
indent: { left: 5760, hanging: convertInchesToTwip(0.25) },
indent: { left: 5760, hanging: 360 },
},
},
},
{
level: 8,
format: LevelFormat.BULLET,
format: "bullet",
text: "\u25CF",
alignment: AlignmentType.LEFT,
style: {
paragraph: {
indent: { left: 6480, hanging: convertInchesToTwip(0.25) },
indent: { left: 6480, hanging: 360 },
},
},
},

View File

@ -12,6 +12,7 @@ import { HeadingLevel, Style } from "./formatting/style";
import { LeaderType, TabStop, TabStopPosition, TabStopType } from "./formatting/tab-stop";
import { NumberProperties } from "./formatting/unordered-list";
import { OutlineLevel } from "./links";
import { IRunPropertiesOptions, RunProperties } from "./run";
import { Shading } from "./run/formatting";
export interface IParagraphStylePropertiesOptions {
@ -51,6 +52,7 @@ export interface IParagraphPropertiesOptions extends IParagraphStylePropertiesOp
readonly fill: string;
readonly color: string;
};
readonly runStyle?: IRunPropertiesOptions;
}
export class ParagraphProperties extends IgnoreIfEmptyXmlComponent {
@ -142,6 +144,10 @@ export class ParagraphProperties extends IgnoreIfEmptyXmlComponent {
if (options.shading) {
this.push(new Shading(options.shading.type, options.shading.fill, options.shading.color));
}
if (options.runStyle) {
this.push(new RunProperties(options.runStyle));
}
}
public push(item: XmlComponent): void {

View File

@ -239,29 +239,13 @@ describe("Run", () => {
describe("#break()", () => {
it("it should add break to the run", () => {
const run = new Run({
break: 1,
});
const run = new Run({});
run.break();
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()", () => {

View File

@ -11,7 +11,6 @@ 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;
}
@ -63,11 +62,10 @@ export class Run extends XmlComponent {
} else if (options.text) {
this.root.push(new Text(options.text));
}
}
if (options.break) {
for (let i = 0; i < options.break; i++) {
public break(): Run {
this.root.splice(1, 0, new Break());
}
}
return this;
}
}

View File

@ -16,7 +16,6 @@ import {
IBaseCharacterStyleOptions,
IBaseParagraphStyleOptions,
ListParagraph,
StrongStyle,
TitleStyle,
} from "./style";
@ -29,7 +28,6 @@ export interface IDefaultStylesOptions {
readonly heading4?: IBaseParagraphStyleOptions;
readonly heading5?: IBaseParagraphStyleOptions;
readonly heading6?: IBaseParagraphStyleOptions;
readonly strong?: IBaseParagraphStyleOptions;
readonly listParagraph?: IBaseParagraphStyleOptions;
readonly hyperlink?: IBaseCharacterStyleOptions;
readonly footnoteReference?: IBaseCharacterStyleOptions;
@ -97,12 +95,6 @@ export class DefaultStylesFactory {
},
...options.heading6,
}),
new StrongStyle({
run: {
bold: true,
},
...options.strong,
}),
new ListParagraph(options.listParagraph || {}),
new HyperlinkStyle(options.hyperlink || {}),
new FootnoteReferenceStyle(options.footnoteReference || {}),

View File

@ -120,20 +120,6 @@ 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);

View File

@ -84,16 +84,6 @@ 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({

View File

@ -546,77 +546,5 @@ 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",
},
},
},
],
});
});
});
});
});

View File

@ -36,39 +36,6 @@ 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");

View File

@ -89,12 +89,11 @@ 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": [

View File

@ -1,6 +1,6 @@
import { XmlComponent } from "file/xml-components";
import { IRunOptions, RunProperties } from "../../index";
import { FootnoteReferenceRun, IRunOptions, IRunPropertiesOptions, RunProperties } from "../../index";
import { Break } from "../../paragraph/run/break";
import { Begin, End, Separate } from "../../paragraph/run/field";
import { PageNumber } from "../../paragraph/run/run";
@ -8,7 +8,10 @@ import { ChangeAttributes, IChangedAttributesProperties } from "../track-revisio
import { DeletedNumberOfPages, DeletedNumberOfPagesSection, DeletedPage } from "./deleted-page-number";
import { DeletedText } from "./deleted-text";
interface IDeletedRunOptions extends IRunOptions, IChangedAttributesProperties {}
interface IDeletedRunOptions extends IRunPropertiesOptions, IChangedAttributesProperties {
readonly children?: (Begin | Separate | End | PageNumber | FootnoteReferenceRun | string)[];
readonly text?: string;
}
export class DeletedTextRun extends XmlComponent {
protected readonly deletedTextRunWrapper: DeletedTextRunWrapper;
@ -22,9 +25,14 @@ export class DeletedTextRun extends XmlComponent {
date: options.date,
}),
);
this.deletedTextRunWrapper = new DeletedTextRunWrapper(options);
this.deletedTextRunWrapper = new DeletedTextRunWrapper(options as IRunOptions);
this.addChildElement(this.deletedTextRunWrapper);
}
public break(): DeletedTextRun {
this.deletedTextRunWrapper.break();
return this;
}
}
class DeletedTextRunWrapper extends XmlComponent {
@ -66,11 +74,9 @@ class DeletedTextRunWrapper extends XmlComponent {
} else if (options.text) {
this.root.push(new DeletedText(options.text));
}
}
if (options.break) {
for (let i = 0; i < options.break; i++) {
public break(): void {
this.root.splice(1, 0, new Break());
}
}
}
}

View File

@ -46,9 +46,7 @@ export interface IDocumentTemplate {
}
export class ImportDotx {
public async extract(
data: Buffer | string | number[] | Uint8Array | ArrayBuffer | Blob | NodeJS.ReadableStream,
): Promise<IDocumentTemplate> {
public async extract(data: Buffer): Promise<IDocumentTemplate> {
const zipContent = await JSZip.loadAsync(data);
const documentContent = await zipContent.files["word/document.xml"].async("text");

View File

@ -4,4 +4,3 @@ export { File as Document } from "./file";
export * from "./file";
export * from "./export";
export * from "./import-dotx";
export * from "./convenience-functions";