Compare commits

..

53 Commits
5.4.1 ... 5.5.0

Author SHA1 Message Date
d6f363b275 Version bump 2021-01-31 04:54:26 +00:00
118ea57412 Merge pull request #749 from dolanmiu/dependabot/npm_and_yarn/types/webpack-4.41.26
build(deps-dev): bump @types/webpack from 4.41.25 to 4.41.26
2021-01-28 10:18:02 +00:00
7c8be4c8a7 Merge pull request #757 from arran4/jszip-supports-more-datatypes
Added more data types for JSZip to consider using
2021-01-28 10:17:48 +00:00
fa9021596f Merge pull request #759 from dolanmiu/dependabot/npm_and_yarn/sinon-9.2.4
build(deps-dev): bump sinon from 9.2.2 to 9.2.4
2021-01-28 10:15:40 +00:00
3ccf4bdfe3 Ran npm run style.fix added "line_ending" configuration to .editorconfig to match the results 2021-01-26 15:09:12 +11:00
f2480673ec build(deps-dev): bump sinon from 9.2.2 to 9.2.4
Bumps [sinon](https://github.com/sinonjs/sinon) from 9.2.2 to 9.2.4.
- [Release notes](https://github.com/sinonjs/sinon/releases)
- [Changelog](https://github.com/sinonjs/sinon/blob/master/CHANGELOG.md)
- [Commits](https://github.com/sinonjs/sinon/compare/v9.2.2...v9.2.4)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2021-01-25 08:20:27 +00:00
e93b8032d8 Buffer is required as it was originally there too 2021-01-22 16:48:41 +11:00
5de2d8c7fb Minor change 2021-01-22 16:45:39 +11:00
e355fd3d2e build(deps-dev): bump @types/webpack from 4.41.25 to 4.41.26
Bumps [@types/webpack](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/webpack) from 4.41.25 to 4.41.26.
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/webpack)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2021-01-12 08:20:34 +00:00
d41ef99c85 Merge pull request #739 from dolanmiu/feat/convenience-functions
Add zIndex property to floating
2020-12-25 02:26:04 +00:00
5ec18d6e01 Add tests and simplify 2020-12-25 02:15:40 +00:00
b4cd3a319c Add documentation 2020-12-25 00:30:58 +00:00
d894bfa167 Add test 2020-12-25 00:29:27 +00:00
d74db948ba Add zIndex property to floating 2020-12-25 00:07:57 +00:00
3ef26c747b Merge pull request #736 from dolanmiu/feat/convenience-functions
Use LevelFormat string enum rather than strings
2020-12-24 17:45:09 +00:00
38c8220e9e Use LevelFormat string enum rather than strings 2020-12-24 04:26:45 +00:00
86f8259b33 Merge pull request #735 from dolanmiu/feat/convenience-functions
Add Convenience functions
2020-12-24 03:44:54 +00:00
502db14bba Add Convenience functions 2020-12-24 03:37:43 +00:00
ef12ada5d7 Add parent to numbered list 2020-12-24 01:50:05 +00:00
977b2b302d Merge pull request #734 from dolanmiu/feat/strong-style
Add declarative break()
2020-12-24 00:21:07 +00:00
17d02a3d1c Fix demos 2020-12-24 00:00:24 +00:00
6100ff4c4e Add declarative break() 2020-12-23 23:31:28 +00:00
8bb73fb25e Merge pull request #729 from dolanmiu/feat/strong-style
Adding TableBorders.NONE convenience object
2020-12-23 00:28:34 +00:00
d6cce4ae15 Adding TableBorders.NONE convenience object 2020-12-22 23:42:02 +00:00
058304d16b Merge pull request #728 from dolanmiu/feat/strong-style
Add strong default style
2020-12-22 22:17:24 +00:00
345d34a2e1 Merge pull request #720 from dolanmiu/dependabot/npm_and_yarn/sinon-9.2.2
build(deps-dev): bump sinon from 9.2.1 to 9.2.2
2020-12-22 21:11:07 +00:00
3839a49d47 Merge pull request #726 from dolanmiu/dependabot/npm_and_yarn/prompt-1.1.0
build(deps-dev): bump prompt from 1.0.0 to 1.1.0
2020-12-22 21:10:57 +00:00
0afe0929a3 Add strong default style 2020-12-22 21:08:10 +00:00
a14a1fbd10 Update character style demo 2020-12-22 20:56:06 +00:00
52f0a6958a build(deps-dev): bump prompt from 1.0.0 to 1.1.0
Bumps [prompt](https://github.com/flatiron/prompt) from 1.0.0 to 1.1.0.
- [Release notes](https://github.com/flatiron/prompt/releases)
- [Changelog](https://github.com/flatiron/prompt/blob/master/CHANGELOG.md)
- [Commits](https://github.com/flatiron/prompt/commits)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-12-22 08:14:29 +00:00
8bdde98db1 build(deps-dev): bump sinon from 9.2.1 to 9.2.2
Bumps [sinon](https://github.com/sinonjs/sinon) from 9.2.1 to 9.2.2.
- [Release notes](https://github.com/sinonjs/sinon/releases)
- [Changelog](https://github.com/sinonjs/sinon/blob/master/CHANGELOG.md)
- [Commits](https://github.com/sinonjs/sinon/commits/v9.2.2)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-12-15 08:16:05 +00:00
19fc900045 Merge pull request #708 from dolanmiu/dependabot/npm_and_yarn/ts-node-9.1.1
build(deps-dev): bump ts-node from 9.1.0 to 9.1.1
2020-12-15 02:01:08 +00:00
6bdd9b882a Merge pull request #711 from dolanmiu/dependabot/npm_and_yarn/types/mocha-8.2.0
build(deps-dev): bump @types/mocha from 8.0.4 to 8.2.0
2020-12-15 02:00:53 +00:00
0d97d428fa Merge pull request #715 from dolanmiu/dependabot/npm_and_yarn/types/request-promise-4.1.47
build(deps-dev): bump @types/request-promise from 4.1.46 to 4.1.47
2020-12-15 02:00:08 +00:00
a0b42d7bdb Merge pull request #717 from dolanmiu/dependabot/npm_and_yarn/ini-1.3.8
build(deps): bump ini from 1.3.5 to 1.3.8
2020-12-15 01:59:54 +00:00
69ba312a96 build(deps): bump ini from 1.3.5 to 1.3.8
Bumps [ini](https://github.com/isaacs/ini) from 1.3.5 to 1.3.8.
- [Release notes](https://github.com/isaacs/ini/releases)
- [Commits](https://github.com/isaacs/ini/compare/v1.3.5...v1.3.8)

Signed-off-by: dependabot[bot] <support@github.com>
2020-12-11 22:47:35 +00:00
a0c13214e6 build(deps-dev): bump @types/request-promise from 4.1.46 to 4.1.47
Bumps [@types/request-promise](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/request-promise) from 4.1.46 to 4.1.47.
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/request-promise)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-12-11 08:22:49 +00:00
4c8829df28 build(deps-dev): bump @types/mocha from 8.0.4 to 8.2.0
Bumps [@types/mocha](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/mocha) from 8.0.4 to 8.2.0.
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/mocha)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-12-09 08:04:12 +00:00
3ee3e95410 build(deps-dev): bump ts-node from 9.1.0 to 9.1.1
Bumps [ts-node](https://github.com/TypeStrong/ts-node) from 9.1.0 to 9.1.1.
- [Release notes](https://github.com/TypeStrong/ts-node/releases)
- [Commits](https://github.com/TypeStrong/ts-node/compare/v9.1.0...v9.1.1)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-12-08 08:49:26 +00:00
806deeaf78 Merge pull request #705 from dolanmiu/dependabot/npm_and_yarn/ts-node-9.1.0
build(deps-dev): bump ts-node from 9.0.0 to 9.1.0
2020-12-04 16:52:27 +00:00
feb121707d build(deps-dev): bump ts-node from 9.0.0 to 9.1.0
Bumps [ts-node](https://github.com/TypeStrong/ts-node) from 9.0.0 to 9.1.0.
- [Release notes](https://github.com/TypeStrong/ts-node/releases)
- [Commits](https://github.com/TypeStrong/ts-node/compare/v9.0.0...v9.1.0)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-12-03 08:01:46 +00:00
31c7f034ec Merge pull request #697 from devoidfury/master
Add defaultStyles option to overwrite the core default styles
2020-11-30 23:58:42 +00:00
30ab92652c move file options.defaultStyles to options.styles.default 2020-11-30 10:25:58 -06:00
0407548113 Merge pull request #702 from dolanmiu/dependabot/npm_and_yarn/prettier-2.2.1
build(deps-dev): bump prettier from 2.2.0 to 2.2.1
2020-11-30 14:48:17 +00:00
277845626c build(deps-dev): bump prettier from 2.2.0 to 2.2.1
Bumps [prettier](https://github.com/prettier/prettier) from 2.2.0 to 2.2.1.
- [Release notes](https://github.com/prettier/prettier/releases)
- [Changelog](https://github.com/prettier/prettier/blob/master/CHANGELOG.md)
- [Commits](https://github.com/prettier/prettier/compare/2.2.0...2.2.1)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-11-30 08:29:40 +00:00
b2af8b970e Merge pull request #693 from dolanmiu/dependabot/npm_and_yarn/prettier-2.2.0
build(deps-dev): bump prettier from 2.1.2 to 2.2.0
2020-11-29 20:16:38 +00:00
542866e18b Merge pull request #699 from dolanmiu/dependabot/npm_and_yarn/highlight.js-9.18.5
build(deps): [security] bump highlight.js from 9.18.1 to 9.18.5
2020-11-29 20:16:26 +00:00
f54192809f build(deps): [security] bump highlight.js from 9.18.1 to 9.18.5
Bumps [highlight.js](https://github.com/highlightjs/highlight.js) from 9.18.1 to 9.18.5. **This update includes a security fix.**
- [Release notes](https://github.com/highlightjs/highlight.js/releases)
- [Changelog](https://github.com/highlightjs/highlight.js/blob/9.18.5/CHANGES.md)
- [Commits](https://github.com/highlightjs/highlight.js/compare/9.18.1...9.18.5)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-11-24 23:10:41 +00:00
f3ba62fd88 bugfix path 2020-11-24 13:36:43 -06:00
8d4a07302b Add defaultStyles option to overwrite the core default styles (Heading 1-6, document, hyperlinks, etc) 2020-11-24 13:30:26 -06:00
d504231124 build(deps-dev): bump prettier from 2.1.2 to 2.2.0
Bumps [prettier](https://github.com/prettier/prettier) from 2.1.2 to 2.2.0.
- [Release notes](https://github.com/prettier/prettier/releases)
- [Changelog](https://github.com/prettier/prettier/blob/master/CHANGELOG.md)
- [Commits](https://github.com/prettier/prettier/compare/2.1.2...2.2.0)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-11-20 11:14:03 +00:00
173b1e118c Merge pull request #690 from dolanmiu/dependabot/npm_and_yarn/docsify-cli-4.4.2
build(deps-dev): bump docsify-cli from 4.4.1 to 4.4.2
2020-11-17 11:50:18 +00:00
ffba276f0d build(deps-dev): bump docsify-cli from 4.4.1 to 4.4.2
Bumps [docsify-cli](https://github.com/docsifyjs/docsify-cli) from 4.4.1 to 4.4.2.
- [Release notes](https://github.com/docsifyjs/docsify-cli/releases)
- [Changelog](https://github.com/docsifyjs/docsify-cli/blob/master/CHANGELOG.md)
- [Commits](https://github.com/docsifyjs/docsify-cli/compare/v4.4.1...v4.4.2)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-11-17 11:13:13 +00:00
43 changed files with 1395 additions and 498 deletions

View File

@ -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

View File

@ -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,
}),
],
});
}

View File

@ -3,6 +3,7 @@
import * as fs from "fs";
import {
AlignmentType,
convertInchesToTwip,
Document,
Footer,
HeadingLevel,
@ -18,13 +19,8 @@ import {
const doc = new Document({
styles: {
paragraphStyles: [
{
id: "Heading1",
name: "Heading 1",
basedOn: "Normal",
next: "Normal",
quickFormat: true,
default: {
heading1: {
run: {
font: "Calibri",
size: 52,
@ -40,12 +36,7 @@ const doc = new Document({
spacing: { line: 340 },
},
},
{
id: "Heading2",
name: "Heading 2",
basedOn: "Normal",
next: "Normal",
quickFormat: true,
heading2: {
run: {
font: "Calibri",
size: 26,
@ -55,12 +46,7 @@ const doc = new Document({
spacing: { line: 340 },
},
},
{
id: "Heading3",
name: "Heading 3",
basedOn: "Normal",
next: "Normal",
quickFormat: true,
heading3: {
run: {
font: "Calibri",
size: 26,
@ -70,12 +56,7 @@ const doc = new Document({
spacing: { line: 276 },
},
},
{
id: "Heading4",
name: "Heading 4",
basedOn: "Normal",
next: "Normal",
quickFormat: true,
heading4: {
run: {
font: "Calibri",
size: 26,
@ -85,6 +66,8 @@ const doc = new Document({
alignment: AlignmentType.JUSTIFIED,
},
},
},
paragraphStyles: [
{
id: "normalPara",
name: "Normal Para",
@ -128,7 +111,7 @@ const doc = new Document({
},
paragraph: {
spacing: { line: 276 },
indent: { left: 720 },
indent: { left: convertInchesToTwip(0.5) },
},
},
{
@ -139,12 +122,6 @@ const doc = new Document({
spacing: { line: 276, before: 20 * 72 * 0.1, after: 20 * 72 * 0.05 },
},
},
{
id: "ListParagraph",
name: "List Paragraph",
basedOn: "Normal",
quickFormat: true,
},
],
},
});

View File

@ -1,20 +1,25 @@
// 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",
title: "Sample Document",
description: "A brief example of using docx",
styles: {
paragraphStyles: [
{
id: "Heading1",
name: "Heading 1",
basedOn: "Normal",
next: "Normal",
quickFormat: true,
default: {
heading1: {
run: {
size: 28,
bold: true,
@ -27,12 +32,7 @@ const doc = new Document({
},
},
},
{
id: "Heading2",
name: "Heading 2",
basedOn: "Normal",
next: "Normal",
quickFormat: true,
heading2: {
run: {
size: 26,
bold: true,
@ -48,6 +48,13 @@ const doc = new Document({
},
},
},
listParagraph: {
run: {
color: "#FF0000",
},
},
},
paragraphStyles: [
{
id: "aside",
name: "Aside",
@ -59,7 +66,7 @@ const doc = new Document({
},
paragraph: {
indent: {
left: 720,
left: convertInchesToTwip(0.5),
},
spacing: {
line: 276,
@ -75,12 +82,6 @@ const doc = new Document({
spacing: { line: 276, before: 20 * 72 * 0.1, after: 20 * 72 * 0.05 },
},
},
{
id: "ListParagraph",
name: "List Paragraph",
basedOn: "Normal",
quickFormat: true,
},
],
},
numbering: {
@ -90,7 +91,7 @@ const doc = new Document({
levels: [
{
level: 0,
format: "lowerLetter",
format: LevelFormat.LOWER_LETTER,
text: "%1)",
alignment: AlignmentType.LEFT,
},
@ -170,6 +171,17 @@ 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, 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,

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, 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,
},
}),
],
});

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, 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: {

View File

@ -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: {

View File

@ -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);

View File

@ -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,

View File

@ -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.",
}),
],
}),
],
});

View File

@ -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,

View 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);
});

View File

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

View 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
```

View File

@ -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:

View File

@ -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,
});
```

679
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -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": {

View 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);
});
});
});

View 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);
};

View File

@ -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),
},

View File

@ -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,

View File

@ -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,
});
});
});
});

View File

@ -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 = {
export class Anchor extends XmlComponent {
constructor(mediaData: IMediaData, dimensions: IMediaDataDimensions, drawingOptions: IDrawingOptions) {
super("wp:anchor");
const floating: 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.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,
}),
);

View File

@ -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;
}

View File

@ -106,7 +106,7 @@ export class File {
this.styles = stylesFactory.newInstance(options.externalStyles);
} else if (options.styles) {
const stylesFactory = new DefaultStylesFactory();
const defaultStyles = stylesFactory.newInstance();
const defaultStyles = stylesFactory.newInstance(options.styles.default);
this.styles = new Styles({
...defaultStyles,
...options.styles,

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 { 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: {

View File

@ -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;

View File

@ -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) },
},
},
},

View File

@ -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()", () => {

View File

@ -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 {
if (options.break) {
for (let i = 0; i < options.break; i++) {
this.root.splice(1, 0, new Break());
return this;
}
}
}
}

View File

@ -1,7 +1,7 @@
import { DocumentAttributes } from "../document/document-attributes";
import { IStylesOptions } from "./styles";
import { DocumentDefaults } from "./defaults";
import { DocumentDefaults, IDocumentDefaultsOptions } from "./defaults";
import {
FootnoteReferenceStyle,
FootnoteText,
@ -13,12 +13,32 @@ import {
Heading5Style,
Heading6Style,
HyperlinkStyle,
IBaseCharacterStyleOptions,
IBaseParagraphStyleOptions,
ListParagraph,
StrongStyle,
TitleStyle,
} from "./style";
export interface IDefaultStylesOptions {
readonly document?: IDocumentDefaultsOptions;
readonly title?: IBaseParagraphStyleOptions;
readonly heading1?: IBaseParagraphStyleOptions;
readonly heading2?: IBaseParagraphStyleOptions;
readonly heading3?: IBaseParagraphStyleOptions;
readonly heading4?: IBaseParagraphStyleOptions;
readonly heading5?: IBaseParagraphStyleOptions;
readonly heading6?: IBaseParagraphStyleOptions;
readonly strong?: IBaseParagraphStyleOptions;
readonly listParagraph?: IBaseParagraphStyleOptions;
readonly hyperlink?: IBaseCharacterStyleOptions;
readonly footnoteReference?: IBaseCharacterStyleOptions;
readonly footnoteText?: IBaseParagraphStyleOptions;
readonly footnoteTextChar?: IBaseCharacterStyleOptions;
}
export class DefaultStylesFactory {
public newInstance(): IStylesOptions {
public newInstance(options: IDefaultStylesOptions = {}): IStylesOptions {
const documentAttributes = new DocumentAttributes({
mc: "http://schemas.openxmlformats.org/markup-compatibility/2006",
r: "http://schemas.openxmlformats.org/officeDocument/2006/relationships",
@ -30,51 +50,64 @@ export class DefaultStylesFactory {
return {
initialStyles: documentAttributes,
importedStyles: [
new DocumentDefaults(),
new DocumentDefaults(options.document),
new TitleStyle({
run: {
size: 56,
},
...options.title,
}),
new Heading1Style({
run: {
color: "2E74B5",
size: 32,
},
...options.heading1,
}),
new Heading2Style({
run: {
color: "2E74B5",
size: 26,
},
...options.heading2,
}),
new Heading3Style({
run: {
color: "1F4D78",
size: 24,
},
...options.heading3,
}),
new Heading4Style({
run: {
color: "2E74B5",
italics: true,
},
...options.heading4,
}),
new Heading5Style({
run: {
color: "2E74B5",
},
...options.heading5,
}),
new Heading6Style({
run: {
color: "1F4D78",
},
...options.heading6,
}),
new ListParagraph({}),
new HyperlinkStyle({}),
new FootnoteReferenceStyle({}),
new FootnoteText({}),
new FootnoteTextChar({}),
new StrongStyle({
run: {
bold: true,
},
...options.strong,
}),
new ListParagraph(options.listParagraph || {}),
new HyperlinkStyle(options.hyperlink || {}),
new FootnoteReferenceStyle(options.footnoteReference || {}),
new FootnoteText(options.footnoteText || {}),
new FootnoteTextChar(options.footnoteTextChar || {}),
],
};
}

View File

@ -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);

View File

@ -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({

View File

@ -1,11 +1,12 @@
import { IDefaultStylesOptions } from "file/styles/factory";
import { BaseXmlComponent, ImportedXmlComponent, XmlComponent } from "file/xml-components";
import { StyleForCharacter, StyleForParagraph } from "./style";
import { ICharacterStyleOptions } from "./style/character-style";
import { IParagraphStyleOptions } from "./style/paragraph-style";
export * from "./border";
export interface IStylesOptions {
readonly default?: IDefaultStylesOptions;
readonly initialStyles?: BaseXmlComponent;
readonly paragraphStyles?: IParagraphStyleOptions[];
readonly characterStyles?: ICharacterStyleOptions[];

View File

@ -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",
},
},
},
],
});
});
});
});
});

View File

@ -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");

View File

@ -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": [

View File

@ -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 {
if (options.break) {
for (let i = 0; i < options.break; i++) {
this.root.splice(1, 0, new Break());
}
}
}
}

View File

@ -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");

View File

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